blob: 68e92be1ef5b24fa5167d9b94601033e36ffdf10 [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 Smart13815c82008-01-11 01:52:48 -0500345 if (!phba->cfg_enable_hba_reset)
346 return -EIO;
347
James Smart46fa3112007-04-25 09:51:45 -0400348 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400349
350 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400351 return status;
James Smart40496f02006-07-06 15:50:22 -0400352
353 init_completion(&online_compl);
354 lpfc_workq_post_event(phba, &status, &online_compl,
355 LPFC_EVT_ONLINE);
356 wait_for_completion(&online_compl);
357
358 if (status != 0)
359 return -EIO;
360
361 return 0;
362}
363
364static ssize_t
365lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
366{
James Smart2e0fef82007-06-17 19:56:36 -0500367 struct Scsi_Host *shost = class_to_shost(cdev);
368 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
369 struct lpfc_hba *phba = vport->phba;
370
James Smart40496f02006-07-06 15:50:22 -0400371 int status = -EINVAL;
372
373 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
374 status = lpfc_selective_reset(phba);
375
376 if (status == 0)
377 return strlen(buf);
378 else
379 return status;
380}
381
dea31012005-04-17 16:05:31 -0500382static ssize_t
383lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
384{
James Smart2e0fef82007-06-17 19:56:36 -0500385 struct Scsi_Host *shost = class_to_shost(cdev);
386 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
387 struct lpfc_hba *phba = vport->phba;
388
dea31012005-04-17 16:05:31 -0500389 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
390}
391
392static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500393lpfc_board_mode_show(struct class_device *cdev, char *buf)
394{
James Smart2e0fef82007-06-17 19:56:36 -0500395 struct Scsi_Host *shost = class_to_shost(cdev);
396 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
397 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500398 char * state;
399
James Smart2e0fef82007-06-17 19:56:36 -0500400 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500401 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500402 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500403 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500404 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500405 state = "offline";
406 else
407 state = "online";
408
409 return snprintf(buf, PAGE_SIZE, "%s\n", state);
410}
411
412static ssize_t
413lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
414{
James Smart2e0fef82007-06-17 19:56:36 -0500415 struct Scsi_Host *shost = class_to_shost(cdev);
416 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
417 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500418 struct completion online_compl;
419 int status=0;
420
James Smart13815c82008-01-11 01:52:48 -0500421 if (!phba->cfg_enable_hba_reset)
422 return -EACCES;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500423 init_completion(&online_compl);
424
James Smart46fa3112007-04-25 09:51:45 -0400425 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500426 lpfc_workq_post_event(phba, &status, &online_compl,
427 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400428 wait_for_completion(&online_compl);
429 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
430 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500431 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400432 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
433 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
434 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500435 else
436 return -EINVAL;
437
Jamie Wellnitz41415862006-02-28 19:25:27 -0500438 if (!status)
439 return strlen(buf);
440 else
441 return -EIO;
442}
443
James Smart311464e2007-08-02 11:10:37 -0400444static int
James Smart858c9f62007-06-17 19:56:39 -0500445lpfc_get_hba_info(struct lpfc_hba *phba,
446 uint32_t *mxri, uint32_t *axri,
447 uint32_t *mrpi, uint32_t *arpi,
448 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500449{
450 struct lpfc_sli *psli = &phba->sli;
451 LPFC_MBOXQ_t *pmboxq;
452 MAILBOX_t *pmb;
453 int rc = 0;
454
455 /*
456 * prevent udev from issuing mailbox commands until the port is
457 * configured.
458 */
459 if (phba->link_state < LPFC_LINK_DOWN ||
460 !phba->mbox_mem_pool ||
461 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
462 return 0;
463
464 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
465 return 0;
466
467 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
468 if (!pmboxq)
469 return 0;
470 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
471
472 pmb = &pmboxq->mb;
473 pmb->mbxCommand = MBX_READ_CONFIG;
474 pmb->mbxOwner = OWN_HOST;
475 pmboxq->context1 = NULL;
476
477 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
478 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
479 rc = MBX_NOT_FINISHED;
480 else
481 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
482
483 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500484 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500485 mempool_free(pmboxq, phba->mbox_mem_pool);
486 return 0;
487 }
488
489 if (mrpi)
490 *mrpi = pmb->un.varRdConfig.max_rpi;
491 if (arpi)
492 *arpi = pmb->un.varRdConfig.avail_rpi;
493 if (mxri)
494 *mxri = pmb->un.varRdConfig.max_xri;
495 if (axri)
496 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500497 if (mvpi)
498 *mvpi = pmb->un.varRdConfig.max_vpi;
499 if (avpi)
500 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500501
502 mempool_free(pmboxq, phba->mbox_mem_pool);
503 return 1;
504}
505
506static ssize_t
507lpfc_max_rpi_show(struct class_device *cdev, char *buf)
508{
509 struct Scsi_Host *shost = class_to_shost(cdev);
510 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
511 struct lpfc_hba *phba = vport->phba;
512 uint32_t cnt;
513
James Smart858c9f62007-06-17 19:56:39 -0500514 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500515 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
516 return snprintf(buf, PAGE_SIZE, "Unknown\n");
517}
518
519static ssize_t
520lpfc_used_rpi_show(struct class_device *cdev, char *buf)
521{
522 struct Scsi_Host *shost = class_to_shost(cdev);
523 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
524 struct lpfc_hba *phba = vport->phba;
525 uint32_t cnt, acnt;
526
James Smart858c9f62007-06-17 19:56:39 -0500527 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500528 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
529 return snprintf(buf, PAGE_SIZE, "Unknown\n");
530}
531
532static ssize_t
533lpfc_max_xri_show(struct class_device *cdev, char *buf)
534{
535 struct Scsi_Host *shost = class_to_shost(cdev);
536 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
537 struct lpfc_hba *phba = vport->phba;
538 uint32_t cnt;
539
James Smart858c9f62007-06-17 19:56:39 -0500540 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500541 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
542 return snprintf(buf, PAGE_SIZE, "Unknown\n");
543}
544
545static ssize_t
546lpfc_used_xri_show(struct class_device *cdev, char *buf)
547{
548 struct Scsi_Host *shost = class_to_shost(cdev);
549 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
550 struct lpfc_hba *phba = vport->phba;
551 uint32_t cnt, acnt;
552
James Smart858c9f62007-06-17 19:56:39 -0500553 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
554 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
555 return snprintf(buf, PAGE_SIZE, "Unknown\n");
556}
557
558static ssize_t
559lpfc_max_vpi_show(struct class_device *cdev, char *buf)
560{
561 struct Scsi_Host *shost = class_to_shost(cdev);
562 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
563 struct lpfc_hba *phba = vport->phba;
564 uint32_t cnt;
565
566 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
567 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
568 return snprintf(buf, PAGE_SIZE, "Unknown\n");
569}
570
571static ssize_t
572lpfc_used_vpi_show(struct class_device *cdev, char *buf)
573{
574 struct Scsi_Host *shost = class_to_shost(cdev);
575 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
576 struct lpfc_hba *phba = vport->phba;
577 uint32_t cnt, acnt;
578
579 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500580 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
581 return snprintf(buf, PAGE_SIZE, "Unknown\n");
582}
583
584static ssize_t
585lpfc_npiv_info_show(struct class_device *cdev, char *buf)
586{
587 struct Scsi_Host *shost = class_to_shost(cdev);
588 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
589 struct lpfc_hba *phba = vport->phba;
590
591 if (!(phba->max_vpi))
592 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
593 if (vport->port_type == LPFC_PHYSICAL_PORT)
594 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
595 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
596}
597
Jamie Wellnitz41415862006-02-28 19:25:27 -0500598static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500599lpfc_poll_show(struct class_device *cdev, char *buf)
600{
James Smart2e0fef82007-06-17 19:56:36 -0500601 struct Scsi_Host *shost = class_to_shost(cdev);
602 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
603 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500604
605 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
606}
607
608static ssize_t
609lpfc_poll_store(struct class_device *cdev, const char *buf,
610 size_t count)
611{
James Smart2e0fef82007-06-17 19:56:36 -0500612 struct Scsi_Host *shost = class_to_shost(cdev);
613 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
614 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500615 uint32_t creg_val;
616 uint32_t old_val;
617 int val=0;
618
619 if (!isdigit(buf[0]))
620 return -EINVAL;
621
622 if (sscanf(buf, "%i", &val) != 1)
623 return -EINVAL;
624
625 if ((val & 0x3) != val)
626 return -EINVAL;
627
James Smart2e0fef82007-06-17 19:56:36 -0500628 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500629
630 old_val = phba->cfg_poll;
631
632 if (val & ENABLE_FCP_RING_POLLING) {
633 if ((val & DISABLE_FCP_RING_INT) &&
634 !(old_val & DISABLE_FCP_RING_INT)) {
635 creg_val = readl(phba->HCregaddr);
636 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
637 writel(creg_val, phba->HCregaddr);
638 readl(phba->HCregaddr); /* flush */
639
640 lpfc_poll_start_timer(phba);
641 }
642 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500643 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500644 return -EINVAL;
645 }
646
647 if (!(val & DISABLE_FCP_RING_INT) &&
648 (old_val & DISABLE_FCP_RING_INT))
649 {
James Smart2e0fef82007-06-17 19:56:36 -0500650 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500651 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500652 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500653 creg_val = readl(phba->HCregaddr);
654 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
655 writel(creg_val, phba->HCregaddr);
656 readl(phba->HCregaddr); /* flush */
657 }
658
659 phba->cfg_poll = val;
660
James Smart2e0fef82007-06-17 19:56:36 -0500661 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500662
663 return strlen(buf);
664}
dea31012005-04-17 16:05:31 -0500665
666#define lpfc_param_show(attr) \
667static ssize_t \
668lpfc_##attr##_show(struct class_device *cdev, char *buf) \
669{ \
James Smart2e0fef82007-06-17 19:56:36 -0500670 struct Scsi_Host *shost = class_to_shost(cdev);\
671 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
672 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500673 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400674 val = phba->cfg_##attr;\
675 return snprintf(buf, PAGE_SIZE, "%d\n",\
676 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500677}
678
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400679#define lpfc_param_hex_show(attr) \
680static ssize_t \
681lpfc_##attr##_show(struct class_device *cdev, char *buf) \
682{ \
James Smart2e0fef82007-06-17 19:56:36 -0500683 struct Scsi_Host *shost = class_to_shost(cdev);\
684 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
685 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400686 int val = 0;\
687 val = phba->cfg_##attr;\
688 return snprintf(buf, PAGE_SIZE, "%#x\n",\
689 phba->cfg_##attr);\
690}
691
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400692#define lpfc_param_init(attr, default, minval, maxval) \
693static int \
694lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
695{ \
696 if (val >= minval && val <= maxval) {\
697 phba->cfg_##attr = val;\
698 return 0;\
699 }\
700 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400701 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
702 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400703 phba->cfg_##attr = default;\
704 return -EINVAL;\
705}
706
707#define lpfc_param_set(attr, default, minval, maxval) \
708static int \
709lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
710{ \
711 if (val >= minval && val <= maxval) {\
712 phba->cfg_##attr = val;\
713 return 0;\
714 }\
715 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400716 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
717 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400718 return -EINVAL;\
719}
720
721#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500722static ssize_t \
723lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
724{ \
James Smart2e0fef82007-06-17 19:56:36 -0500725 struct Scsi_Host *shost = class_to_shost(cdev);\
726 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
727 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400728 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400729 if (!isdigit(buf[0]))\
730 return -EINVAL;\
731 if (sscanf(buf, "%i", &val) != 1)\
732 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400733 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400734 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400735 else \
736 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500737}
738
James Smart3de2a652007-08-02 11:09:59 -0400739#define lpfc_vport_param_show(attr) \
740static ssize_t \
741lpfc_##attr##_show(struct class_device *cdev, char *buf) \
742{ \
743 struct Scsi_Host *shost = class_to_shost(cdev);\
744 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
745 int val = 0;\
746 val = vport->cfg_##attr;\
747 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
748}
749
750#define lpfc_vport_param_hex_show(attr) \
751static ssize_t \
752lpfc_##attr##_show(struct class_device *cdev, char *buf) \
753{ \
754 struct Scsi_Host *shost = class_to_shost(cdev);\
755 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
756 int val = 0;\
757 val = vport->cfg_##attr;\
758 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
759}
760
761#define lpfc_vport_param_init(attr, default, minval, maxval) \
762static int \
763lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
764{ \
765 if (val >= minval && val <= maxval) {\
766 vport->cfg_##attr = val;\
767 return 0;\
768 }\
James Smarte8b62012007-08-02 11:10:09 -0400769 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
770 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
771 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400772 vport->cfg_##attr = default;\
773 return -EINVAL;\
774}
775
776#define lpfc_vport_param_set(attr, default, minval, maxval) \
777static int \
778lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
779{ \
780 if (val >= minval && val <= maxval) {\
781 vport->cfg_##attr = val;\
782 return 0;\
783 }\
James Smarte8b62012007-08-02 11:10:09 -0400784 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
785 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
786 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400787 return -EINVAL;\
788}
789
790#define lpfc_vport_param_store(attr) \
791static ssize_t \
792lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
793{ \
794 struct Scsi_Host *shost = class_to_shost(cdev);\
795 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
796 int val=0;\
797 if (!isdigit(buf[0]))\
798 return -EINVAL;\
799 if (sscanf(buf, "%i", &val) != 1)\
800 return -EINVAL;\
801 if (lpfc_##attr##_set(vport, val) == 0) \
802 return strlen(buf);\
803 else \
804 return -EINVAL;\
805}
806
807
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400808#define LPFC_ATTR(name, defval, minval, maxval, desc) \
809static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500810module_param(lpfc_##name, int, 0);\
811MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400812lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500813
814#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
815static int lpfc_##name = defval;\
816module_param(lpfc_##name, int, 0);\
817MODULE_PARM_DESC(lpfc_##name, desc);\
818lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400819lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500820static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
821
822#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
823static int lpfc_##name = defval;\
824module_param(lpfc_##name, int, 0);\
825MODULE_PARM_DESC(lpfc_##name, desc);\
826lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400827lpfc_param_init(name, defval, minval, maxval)\
828lpfc_param_set(name, defval, minval, maxval)\
829lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500830static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
831 lpfc_##name##_show, lpfc_##name##_store)
832
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400833#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
834static int lpfc_##name = defval;\
835module_param(lpfc_##name, int, 0);\
836MODULE_PARM_DESC(lpfc_##name, desc);\
837lpfc_param_hex_show(name)\
838lpfc_param_init(name, defval, minval, maxval)\
839static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
840
841#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
842static int lpfc_##name = defval;\
843module_param(lpfc_##name, int, 0);\
844MODULE_PARM_DESC(lpfc_##name, desc);\
845lpfc_param_hex_show(name)\
846lpfc_param_init(name, defval, minval, maxval)\
847lpfc_param_set(name, defval, minval, maxval)\
848lpfc_param_store(name)\
849static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
850 lpfc_##name##_show, lpfc_##name##_store)
851
James Smart3de2a652007-08-02 11:09:59 -0400852#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
853static int lpfc_##name = defval;\
854module_param(lpfc_##name, int, 0);\
855MODULE_PARM_DESC(lpfc_##name, desc);\
856lpfc_vport_param_init(name, defval, minval, maxval)
857
858#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
859static int lpfc_##name = defval;\
860module_param(lpfc_##name, int, 0);\
861MODULE_PARM_DESC(lpfc_##name, desc);\
862lpfc_vport_param_show(name)\
863lpfc_vport_param_init(name, defval, minval, maxval)\
864static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
865
866#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
867static int lpfc_##name = defval;\
868module_param(lpfc_##name, int, 0);\
869MODULE_PARM_DESC(lpfc_##name, desc);\
870lpfc_vport_param_show(name)\
871lpfc_vport_param_init(name, defval, minval, maxval)\
872lpfc_vport_param_set(name, defval, minval, maxval)\
873lpfc_vport_param_store(name)\
874static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
875 lpfc_##name##_show, lpfc_##name##_store)
876
877#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
878static int lpfc_##name = defval;\
879module_param(lpfc_##name, int, 0);\
880MODULE_PARM_DESC(lpfc_##name, desc);\
881lpfc_vport_param_hex_show(name)\
882lpfc_vport_param_init(name, defval, minval, maxval)\
883static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
884
885#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
886static int lpfc_##name = defval;\
887module_param(lpfc_##name, int, 0);\
888MODULE_PARM_DESC(lpfc_##name, desc);\
889lpfc_vport_param_hex_show(name)\
890lpfc_vport_param_init(name, defval, minval, maxval)\
891lpfc_vport_param_set(name, defval, minval, maxval)\
892lpfc_vport_param_store(name)\
893static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
894 lpfc_##name##_show, lpfc_##name##_store)
895
dea31012005-04-17 16:05:31 -0500896static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
897static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
898static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
899static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
900static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500901static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500902static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
903static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
904static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
905static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
906 lpfc_option_rom_version_show, NULL);
907static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
908 lpfc_num_discovered_ports_show, NULL);
909static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
910static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
911 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500912static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
913 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400914static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500915static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
916static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
917static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
918static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
919static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
920static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
921static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
James Smart57127f12007-10-27 13:37:05 -0400922static CLASS_DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show,
923 NULL);
dea31012005-04-17 16:05:31 -0500924
James Smartc3f28af2006-08-18 17:47:18 -0400925
James Smarta12e07b2006-12-02 13:35:30 -0500926static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400927
928static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500929lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400930 size_t count)
931{
James Smart2e0fef82007-06-17 19:56:36 -0500932 struct Scsi_Host *shost = class_to_shost(cdev);
933 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
934 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400935 unsigned int cnt = count;
936
937 /*
938 * We're doing a simple sanity check for soft_wwpn setting.
939 * We require that the user write a specific key to enable
940 * the soft_wwpn attribute to be settable. Once the attribute
941 * is written, the enable key resets. If further updates are
942 * desired, the key must be written again to re-enable the
943 * attribute.
944 *
945 * The "key" is not secret - it is a hardcoded string shown
946 * here. The intent is to protect against the random user or
947 * application that is just writing attributes.
948 */
949
950 /* count may include a LF at end of string */
951 if (buf[cnt-1] == '\n')
952 cnt--;
953
James Smarta12e07b2006-12-02 13:35:30 -0500954 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
955 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400956 return -EINVAL;
957
James Smarta12e07b2006-12-02 13:35:30 -0500958 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400959 return count;
960}
James Smarta12e07b2006-12-02 13:35:30 -0500961static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
962 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400963
964static ssize_t
965lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
966{
James Smart2e0fef82007-06-17 19:56:36 -0500967 struct Scsi_Host *shost = class_to_shost(cdev);
968 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
969 struct lpfc_hba *phba = vport->phba;
970
Randy Dunlapafc071e2006-10-23 21:47:13 -0700971 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
972 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400973}
974
975
976static ssize_t
977lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
978{
James Smart2e0fef82007-06-17 19:56:36 -0500979 struct Scsi_Host *shost = class_to_shost(cdev);
980 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
981 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400982 struct completion online_compl;
983 int stat1=0, stat2=0;
984 unsigned int i, j, cnt=count;
985 u8 wwpn[8];
986
James Smart13815c82008-01-11 01:52:48 -0500987 if (!phba->cfg_enable_hba_reset)
988 return -EACCES;
James Smart7af67052007-10-27 13:38:11 -0400989 spin_lock_irq(&phba->hbalock);
990 if (phba->over_temp_state == HBA_OVER_TEMP) {
991 spin_unlock_irq(&phba->hbalock);
992 return -EPERM;
993 }
994 spin_unlock_irq(&phba->hbalock);
James Smartc3f28af2006-08-18 17:47:18 -0400995 /* count may include a LF at end of string */
996 if (buf[cnt-1] == '\n')
997 cnt--;
998
James Smarta12e07b2006-12-02 13:35:30 -0500999 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -04001000 ((cnt == 17) && (*buf++ != 'x')) ||
1001 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1002 return -EINVAL;
1003
James Smarta12e07b2006-12-02 13:35:30 -05001004 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -04001005
1006 memset(wwpn, 0, sizeof(wwpn));
1007
1008 /* Validate and store the new name */
1009 for (i=0, j=0; i < 16; i++) {
1010 if ((*buf >= 'a') && (*buf <= 'f'))
1011 j = ((j << 4) | ((*buf++ -'a') + 10));
1012 else if ((*buf >= 'A') && (*buf <= 'F'))
1013 j = ((j << 4) | ((*buf++ -'A') + 10));
1014 else if ((*buf >= '0') && (*buf <= '9'))
1015 j = ((j << 4) | (*buf++ -'0'));
1016 else
1017 return -EINVAL;
1018 if (i % 2) {
1019 wwpn[i/2] = j & 0xff;
1020 j = 0;
1021 }
1022 }
1023 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001024 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001025 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001026 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001027
1028 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1029 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1030
James Smart46fa3112007-04-25 09:51:45 -04001031 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001032 if (stat1)
1033 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001034 "0463 lpfc_soft_wwpn attribute set failed to "
1035 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001036 init_completion(&online_compl);
1037 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1038 wait_for_completion(&online_compl);
1039 if (stat2)
1040 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001041 "0464 lpfc_soft_wwpn attribute set failed to "
1042 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001043 return (stat1 || stat2) ? -EIO : count;
1044}
1045static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1046 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1047
James Smarta12e07b2006-12-02 13:35:30 -05001048static ssize_t
1049lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1050{
James Smart51ef4c22007-08-02 11:10:31 -04001051 struct Scsi_Host *shost = class_to_shost(cdev);
1052 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001053 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1054 (unsigned long long)phba->cfg_soft_wwnn);
1055}
1056
1057
1058static ssize_t
1059lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1060{
James Smart51ef4c22007-08-02 11:10:31 -04001061 struct Scsi_Host *shost = class_to_shost(cdev);
1062 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001063 unsigned int i, j, cnt=count;
1064 u8 wwnn[8];
1065
1066 /* count may include a LF at end of string */
1067 if (buf[cnt-1] == '\n')
1068 cnt--;
1069
1070 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1071 ((cnt == 17) && (*buf++ != 'x')) ||
1072 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1073 return -EINVAL;
1074
1075 /*
1076 * Allow wwnn to be set many times, as long as the enable is set.
1077 * However, once the wwpn is set, everything locks.
1078 */
1079
1080 memset(wwnn, 0, sizeof(wwnn));
1081
1082 /* Validate and store the new name */
1083 for (i=0, j=0; i < 16; i++) {
1084 if ((*buf >= 'a') && (*buf <= 'f'))
1085 j = ((j << 4) | ((*buf++ -'a') + 10));
1086 else if ((*buf >= 'A') && (*buf <= 'F'))
1087 j = ((j << 4) | ((*buf++ -'A') + 10));
1088 else if ((*buf >= '0') && (*buf <= '9'))
1089 j = ((j << 4) | (*buf++ -'0'));
1090 else
1091 return -EINVAL;
1092 if (i % 2) {
1093 wwnn[i/2] = j & 0xff;
1094 j = 0;
1095 }
1096 }
1097 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1098
1099 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1100 "lpfc%d: soft_wwnn set. Value will take effect upon "
1101 "setting of the soft_wwpn\n", phba->brd_no);
1102
1103 return count;
1104}
1105static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1106 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1107
James Smartc3f28af2006-08-18 17:47:18 -04001108
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001109static int lpfc_poll = 0;
1110module_param(lpfc_poll, int, 0);
1111MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1112 " 0 - none,"
1113 " 1 - poll with interrupts enabled"
1114 " 3 - poll and disable FCP ring interrupts");
1115
1116static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1117 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001118
James Smart92d7f7b2007-06-17 19:56:38 -05001119int lpfc_sli_mode = 0;
1120module_param(lpfc_sli_mode, int, 0);
1121MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1122 " 0 - auto (SLI-3 if supported),"
1123 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1124 " 3 - select SLI-3");
1125
James Smart7ee5d432007-10-27 13:37:17 -04001126int lpfc_enable_npiv = 0;
1127module_param(lpfc_enable_npiv, int, 0);
1128MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
1129lpfc_param_show(enable_npiv);
1130lpfc_param_init(enable_npiv, 0, 0, 1);
1131static CLASS_DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
1132 lpfc_enable_npiv_show, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05001133
dea31012005-04-17 16:05:31 -05001134/*
James Smartc01f3202006-08-18 17:47:08 -04001135# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1136# until the timer expires. Value range is [0,255]. Default value is 30.
1137*/
1138static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1139static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1140module_param(lpfc_nodev_tmo, int, 0);
1141MODULE_PARM_DESC(lpfc_nodev_tmo,
1142 "Seconds driver will hold I/O waiting "
1143 "for a device to come back");
1144static ssize_t
1145lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1146{
James Smart2e0fef82007-06-17 19:56:36 -05001147 struct Scsi_Host *shost = class_to_shost(cdev);
1148 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001149 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001150 val = vport->cfg_devloss_tmo;
1151 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001152}
1153
1154static int
James Smart3de2a652007-08-02 11:09:59 -04001155lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001156{
James Smart3de2a652007-08-02 11:09:59 -04001157 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1158 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1159 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001160 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1161 "0402 Ignoring nodev_tmo module "
1162 "parameter because devloss_tmo is "
1163 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001164 return 0;
1165 }
1166
1167 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001168 vport->cfg_nodev_tmo = val;
1169 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001170 return 0;
1171 }
James Smarte8b62012007-08-02 11:10:09 -04001172 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1173 "0400 lpfc_nodev_tmo attribute cannot be set to"
1174 " %d, allowed range is [%d, %d]\n",
1175 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001176 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001177 return -EINVAL;
1178}
1179
James Smart7054a602007-04-25 09:52:34 -04001180static void
James Smart3de2a652007-08-02 11:09:59 -04001181lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001182{
James Smart858c9f62007-06-17 19:56:39 -05001183 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001184 struct lpfc_nodelist *ndlp;
1185
James Smart51ef4c22007-08-02 11:10:31 -04001186 shost = lpfc_shost_from_vport(vport);
1187 spin_lock_irq(shost->host_lock);
1188 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1189 if (ndlp->rport)
1190 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1191 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001192}
1193
James Smartc01f3202006-08-18 17:47:08 -04001194static int
James Smart3de2a652007-08-02 11:09:59 -04001195lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001196{
James Smart3de2a652007-08-02 11:09:59 -04001197 if (vport->dev_loss_tmo_changed ||
1198 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001199 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1200 "0401 Ignoring change to nodev_tmo "
1201 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001202 return 0;
1203 }
James Smartc01f3202006-08-18 17:47:08 -04001204 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001205 vport->cfg_nodev_tmo = val;
1206 vport->cfg_devloss_tmo = val;
1207 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001208 return 0;
1209 }
James Smarte8b62012007-08-02 11:10:09 -04001210 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1211 "0403 lpfc_nodev_tmo attribute cannot be set to"
1212 "%d, allowed range is [%d, %d]\n",
1213 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001214 return -EINVAL;
1215}
1216
James Smart3de2a652007-08-02 11:09:59 -04001217lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001218
1219static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1220 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1221
1222/*
1223# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1224# disappear until the timer expires. Value range is [0,255]. Default
1225# value is 30.
1226*/
1227module_param(lpfc_devloss_tmo, int, 0);
1228MODULE_PARM_DESC(lpfc_devloss_tmo,
1229 "Seconds driver will hold I/O waiting "
1230 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001231lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1232 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1233lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001234static int
James Smart3de2a652007-08-02 11:09:59 -04001235lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001236{
1237 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001238 vport->cfg_nodev_tmo = val;
1239 vport->cfg_devloss_tmo = val;
1240 vport->dev_loss_tmo_changed = 1;
1241 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001242 return 0;
1243 }
1244
James Smarte8b62012007-08-02 11:10:09 -04001245 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1246 "0404 lpfc_devloss_tmo attribute cannot be set to"
1247 " %d, allowed range is [%d, %d]\n",
1248 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001249 return -EINVAL;
1250}
1251
James Smart3de2a652007-08-02 11:09:59 -04001252lpfc_vport_param_store(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001253static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1254 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1255
1256/*
dea31012005-04-17 16:05:31 -05001257# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1258# deluged with LOTS of information.
1259# You can set a bit mask to record specific types of verbose messages:
1260#
1261# LOG_ELS 0x1 ELS events
1262# LOG_DISCOVERY 0x2 Link discovery events
1263# LOG_MBOX 0x4 Mailbox events
1264# LOG_INIT 0x8 Initialization events
1265# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001266# LOG_FCP 0x40 FCP traffic history
1267# LOG_NODE 0x80 Node table events
1268# LOG_MISC 0x400 Miscellaneous events
1269# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001270# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001271# LOG_LIBDFC 0x2000 LIBDFC events
1272# LOG_ALL_MSG 0xffff LOG all messages
1273*/
James Smarte8b62012007-08-02 11:10:09 -04001274LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1275 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001276
1277/*
James Smart7ee5d432007-10-27 13:37:17 -04001278# lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
1279# objects that have been registered with the nameserver after login.
1280*/
1281LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
1282 "Deregister nameserver objects before LOGO");
1283
1284/*
dea31012005-04-17 16:05:31 -05001285# lun_queue_depth: This parameter is used to limit the number of outstanding
1286# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1287*/
James Smart3de2a652007-08-02 11:09:59 -04001288LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1289 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001290
1291/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001292# hba_queue_depth: This parameter is used to limit the number of outstanding
1293# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1294# value is greater than the maximum number of exchanges supported by the HBA,
1295# then maximum number of exchanges supported by the HBA is used to determine
1296# the hba_queue_depth.
1297*/
1298LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1299 "Max number of FCP commands we can queue to a lpfc HBA");
1300
1301/*
James Smart92d7f7b2007-06-17 19:56:38 -05001302# peer_port_login: This parameter allows/prevents logins
1303# between peer ports hosted on the same physical port.
1304# When this parameter is set 0 peer ports of same physical port
1305# are not allowed to login to each other.
1306# When this parameter is set 1 peer ports of same physical port
1307# are allowed to login to each other.
1308# Default value of this parameter is 0.
1309*/
James Smart3de2a652007-08-02 11:09:59 -04001310LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1311 "Allow peer ports on the same physical port to login to each "
1312 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001313
1314/*
James Smart3de2a652007-08-02 11:09:59 -04001315# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001316# between Virtual Ports and remote initiators.
1317# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1318# other initiators and will attempt to PLOGI all remote ports.
1319# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1320# remote ports and will not attempt to PLOGI to other initiators.
1321# This parameter does not restrict to the physical port.
1322# This parameter does not restrict logins to Fabric resident remote ports.
1323# Default value of this parameter is 1.
1324*/
James Smart3de2a652007-08-02 11:09:59 -04001325static int lpfc_restrict_login = 1;
1326module_param(lpfc_restrict_login, int, 0);
1327MODULE_PARM_DESC(lpfc_restrict_login,
1328 "Restrict virtual ports login to remote initiators.");
1329lpfc_vport_param_show(restrict_login);
1330
1331static int
1332lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1333{
1334 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001335 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1336 "0449 lpfc_restrict_login attribute cannot "
1337 "be set to %d, allowed range is [0, 1]\n",
1338 val);
James Smart3de2a652007-08-02 11:09:59 -04001339 vport->cfg_restrict_login = 1;
1340 return -EINVAL;
1341 }
1342 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1343 vport->cfg_restrict_login = 0;
1344 return 0;
1345 }
1346 vport->cfg_restrict_login = val;
1347 return 0;
1348}
1349
1350static int
1351lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1352{
1353 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001354 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1355 "0450 lpfc_restrict_login attribute cannot "
1356 "be set to %d, allowed range is [0, 1]\n",
1357 val);
James Smart3de2a652007-08-02 11:09:59 -04001358 vport->cfg_restrict_login = 1;
1359 return -EINVAL;
1360 }
1361 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001362 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1363 "0468 lpfc_restrict_login must be 0 for "
1364 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001365 vport->cfg_restrict_login = 0;
1366 return 0;
1367 }
1368 vport->cfg_restrict_login = val;
1369 return 0;
1370}
1371lpfc_vport_param_store(restrict_login);
1372static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1373 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001374
1375/*
dea31012005-04-17 16:05:31 -05001376# Some disk devices have a "select ID" or "select Target" capability.
1377# From a protocol standpoint "select ID" usually means select the
1378# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1379# annex" which contains a table that maps a "select ID" (a number
1380# between 0 and 7F) to an ALPA. By default, for compatibility with
1381# older drivers, the lpfc driver scans this table from low ALPA to high
1382# ALPA.
1383#
1384# Turning on the scan-down variable (on = 1, off = 0) will
1385# cause the lpfc driver to use an inverted table, effectively
1386# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1387#
1388# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1389# and will not work across a fabric. Also this parameter will take
1390# effect only in the case when ALPA map is not available.)
1391*/
James Smart3de2a652007-08-02 11:09:59 -04001392LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1393 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001394
1395/*
dea31012005-04-17 16:05:31 -05001396# lpfc_topology: link topology for init link
1397# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001398# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001399# 0x02 = attempt point-to-point mode only
1400# 0x04 = attempt loop mode only
1401# 0x06 = attempt point-to-point mode then loop
1402# Set point-to-point mode if you want to run as an N_Port.
1403# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1404# Default value is 0.
1405*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001406LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -05001407
1408/*
1409# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1410# connection.
1411# 0 = auto select (default)
1412# 1 = 1 Gigabaud
1413# 2 = 2 Gigabaud
1414# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001415# 8 = 8 Gigabaud
1416# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001417*/
James Smartb87eab32007-04-25 09:53:28 -04001418LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -05001419
1420/*
1421# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1422# Value range is [2,3]. Default value is 3.
1423*/
James Smart3de2a652007-08-02 11:09:59 -04001424LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1425 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001426
1427/*
1428# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1429# is [0,1]. Default value is 0.
1430*/
James Smart3de2a652007-08-02 11:09:59 -04001431LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1432 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001433
1434/*
1435# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1436# range is [0,1]. Default value is 0.
1437*/
1438LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1439
1440/*
1441# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1442# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001443# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001444# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1445# cr_delay is set to 0.
1446*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001447LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001448 "interrupt response is generated");
1449
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001450LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001451 "interrupt response is generated");
1452
1453/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001454# lpfc_multi_ring_support: Determines how many rings to spread available
1455# cmd/rsp IOCB entries across.
1456# Value range is [1,2]. Default value is 1.
1457*/
1458LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1459 "SLI rings to spread IOCB entries across");
1460
1461/*
James Smarta4bc3372006-12-02 13:34:16 -05001462# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1463# identifies what rctl value to configure the additional ring for.
1464# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1465*/
1466LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1467 255, "Identifies RCTL for additional ring configuration");
1468
1469/*
1470# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1471# identifies what type value to configure the additional ring for.
1472# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1473*/
1474LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1475 255, "Identifies TYPE for additional ring configuration");
1476
1477/*
dea31012005-04-17 16:05:31 -05001478# lpfc_fdmi_on: controls FDMI support.
1479# 0 = no FDMI support
1480# 1 = support FDMI without attribute of hostname
1481# 2 = support FDMI with attribute of hostname
1482# Value range [0,2]. Default value is 0.
1483*/
James Smart3de2a652007-08-02 11:09:59 -04001484LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001485
1486/*
1487# Specifies the maximum number of ELS cmds we can have outstanding (for
1488# discovery). Value range is [1,64]. Default value = 32.
1489*/
James Smart3de2a652007-08-02 11:09:59 -04001490LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001491 "during discovery");
1492
1493/*
James Smart65a29c12006-07-06 15:50:50 -04001494# lpfc_max_luns: maximum allowed LUN.
1495# Value range is [0,65535]. Default value is 255.
1496# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001497*/
James Smart3de2a652007-08-02 11:09:59 -04001498LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001499
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001500/*
1501# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1502# Value range is [1,255], default value is 10.
1503*/
1504LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1505 "Milliseconds driver will wait between polling FCP ring");
1506
James Smart4ff43242006-12-02 13:34:56 -05001507/*
1508# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1509# support this feature
1510# 0 = MSI disabled (default)
1511# 1 = MSI enabled
1512# Value range is [0,1]. Default value is 0.
1513*/
1514LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1515
James Smart13815c82008-01-11 01:52:48 -05001516/*
1517# lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
1518# 0 = HBA resets disabled
1519# 1 = HBA resets enabled (default)
1520# Value range is [0,1]. Default value is 1.
1521*/
1522LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
James Smartc3f28af2006-08-18 17:47:18 -04001523
James Smart13815c82008-01-11 01:52:48 -05001524/*
1525# lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
1526# 0 = HBA Heartbeat disabled
1527# 1 = HBA Heartbeat enabled (default)
1528# Value range is [0,1]. Default value is 1.
1529*/
1530LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
James Smart92d7f7b2007-06-17 19:56:38 -05001531
James Smart2e0fef82007-06-17 19:56:36 -05001532struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001533 &class_device_attr_info,
1534 &class_device_attr_serialnum,
1535 &class_device_attr_modeldesc,
1536 &class_device_attr_modelname,
1537 &class_device_attr_programtype,
1538 &class_device_attr_portnum,
1539 &class_device_attr_fwrev,
1540 &class_device_attr_hdw,
1541 &class_device_attr_option_rom_version,
1542 &class_device_attr_state,
1543 &class_device_attr_num_discovered_ports,
1544 &class_device_attr_lpfc_drvr_version,
James Smart57127f12007-10-27 13:37:05 -04001545 &class_device_attr_lpfc_temp_sensor,
dea31012005-04-17 16:05:31 -05001546 &class_device_attr_lpfc_log_verbose,
1547 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001548 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001549 &class_device_attr_lpfc_peer_port_login,
dea31012005-04-17 16:05:31 -05001550 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001551 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001552 &class_device_attr_lpfc_fcp_class,
1553 &class_device_attr_lpfc_use_adisc,
1554 &class_device_attr_lpfc_ack0,
1555 &class_device_attr_lpfc_topology,
1556 &class_device_attr_lpfc_scan_down,
1557 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001558 &class_device_attr_lpfc_cr_delay,
1559 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001560 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001561 &class_device_attr_lpfc_multi_ring_rctl,
1562 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001563 &class_device_attr_lpfc_fdmi_on,
1564 &class_device_attr_lpfc_max_luns,
James Smart78b2d852007-08-02 11:10:21 -04001565 &class_device_attr_lpfc_enable_npiv,
dea31012005-04-17 16:05:31 -05001566 &class_device_attr_nport_evt_cnt,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001567 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001568 &class_device_attr_max_vpi,
1569 &class_device_attr_used_vpi,
1570 &class_device_attr_max_rpi,
1571 &class_device_attr_used_rpi,
1572 &class_device_attr_max_xri,
1573 &class_device_attr_used_xri,
1574 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001575 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001576 &class_device_attr_lpfc_poll,
1577 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001578 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001579 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001580 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001581 &class_device_attr_lpfc_soft_wwn_enable,
James Smart13815c82008-01-11 01:52:48 -05001582 &class_device_attr_lpfc_enable_hba_reset,
1583 &class_device_attr_lpfc_enable_hba_heartbeat,
dea31012005-04-17 16:05:31 -05001584 NULL,
1585};
1586
James Smart3de2a652007-08-02 11:09:59 -04001587struct class_device_attribute *lpfc_vport_attrs[] = {
1588 &class_device_attr_info,
1589 &class_device_attr_state,
1590 &class_device_attr_num_discovered_ports,
1591 &class_device_attr_lpfc_drvr_version,
1592
1593 &class_device_attr_lpfc_log_verbose,
1594 &class_device_attr_lpfc_lun_queue_depth,
1595 &class_device_attr_lpfc_nodev_tmo,
1596 &class_device_attr_lpfc_devloss_tmo,
1597 &class_device_attr_lpfc_hba_queue_depth,
1598 &class_device_attr_lpfc_peer_port_login,
1599 &class_device_attr_lpfc_restrict_login,
1600 &class_device_attr_lpfc_fcp_class,
1601 &class_device_attr_lpfc_use_adisc,
1602 &class_device_attr_lpfc_fdmi_on,
1603 &class_device_attr_lpfc_max_luns,
1604 &class_device_attr_nport_evt_cnt,
James Smart3de2a652007-08-02 11:09:59 -04001605 &class_device_attr_npiv_info,
James Smart7ee5d432007-10-27 13:37:17 -04001606 &class_device_attr_lpfc_enable_da_id,
James Smart3de2a652007-08-02 11:09:59 -04001607 NULL,
1608};
1609
dea31012005-04-17 16:05:31 -05001610static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001611sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1612 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001613{
1614 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001615 struct class_device *cdev = container_of(kobj, struct class_device,
1616 kobj);
1617 struct Scsi_Host *shost = class_to_shost(cdev);
1618 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1619 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001620
1621 if ((off + count) > FF_REG_AREA_SIZE)
1622 return -ERANGE;
1623
1624 if (count == 0) return 0;
1625
1626 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1627 return -EINVAL;
1628
James Smart2e0fef82007-06-17 19:56:36 -05001629 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001630 return -EPERM;
1631 }
1632
James Smart2e0fef82007-06-17 19:56:36 -05001633 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001634 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1635 writel(*((uint32_t *)(buf + buf_off)),
1636 phba->ctrl_regs_memmap_p + off + buf_off);
1637
James Smart2e0fef82007-06-17 19:56:36 -05001638 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001639
1640 return count;
1641}
1642
1643static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001644sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1645 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001646{
1647 size_t buf_off;
1648 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001649 struct class_device *cdev = container_of(kobj, struct class_device,
1650 kobj);
1651 struct Scsi_Host *shost = class_to_shost(cdev);
1652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1653 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001654
1655 if (off > FF_REG_AREA_SIZE)
1656 return -ERANGE;
1657
1658 if ((off + count) > FF_REG_AREA_SIZE)
1659 count = FF_REG_AREA_SIZE - off;
1660
1661 if (count == 0) return 0;
1662
1663 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1664 return -EINVAL;
1665
James Smart2e0fef82007-06-17 19:56:36 -05001666 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001667
1668 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1669 tmp_ptr = (uint32_t *)(buf + buf_off);
1670 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1671 }
1672
James Smart2e0fef82007-06-17 19:56:36 -05001673 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001674
1675 return count;
1676}
1677
1678static struct bin_attribute sysfs_ctlreg_attr = {
1679 .attr = {
1680 .name = "ctlreg",
1681 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001682 },
1683 .size = 256,
1684 .read = sysfs_ctlreg_read,
1685 .write = sysfs_ctlreg_write,
1686};
1687
1688
1689static void
James Smart2e0fef82007-06-17 19:56:36 -05001690sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001691{
1692 phba->sysfs_mbox.state = SMBOX_IDLE;
1693 phba->sysfs_mbox.offset = 0;
1694
1695 if (phba->sysfs_mbox.mbox) {
1696 mempool_free(phba->sysfs_mbox.mbox,
1697 phba->mbox_mem_pool);
1698 phba->sysfs_mbox.mbox = NULL;
1699 }
1700}
1701
1702static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001703sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1704 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001705{
James Smart2e0fef82007-06-17 19:56:36 -05001706 struct class_device *cdev = container_of(kobj, struct class_device,
1707 kobj);
1708 struct Scsi_Host *shost = class_to_shost(cdev);
1709 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1710 struct lpfc_hba *phba = vport->phba;
1711 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001712
1713 if ((count + off) > MAILBOX_CMD_SIZE)
1714 return -ERANGE;
1715
1716 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1717 return -EINVAL;
1718
1719 if (count == 0)
1720 return 0;
1721
1722 if (off == 0) {
1723 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1724 if (!mbox)
1725 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001726 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001727 }
1728
James Smart2e0fef82007-06-17 19:56:36 -05001729 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001730
1731 if (off == 0) {
1732 if (phba->sysfs_mbox.mbox)
1733 mempool_free(mbox, phba->mbox_mem_pool);
1734 else
1735 phba->sysfs_mbox.mbox = mbox;
1736 phba->sysfs_mbox.state = SMBOX_WRITING;
1737 } else {
1738 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1739 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001740 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001741 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001742 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001743 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001744 }
1745 }
1746
1747 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1748 buf, count);
1749
1750 phba->sysfs_mbox.offset = off + count;
1751
James Smart2e0fef82007-06-17 19:56:36 -05001752 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001753
1754 return count;
1755}
1756
1757static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001758sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1759 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001760{
James Smart2e0fef82007-06-17 19:56:36 -05001761 struct class_device *cdev = container_of(kobj, struct class_device,
1762 kobj);
1763 struct Scsi_Host *shost = class_to_shost(cdev);
1764 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1765 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001766 int rc;
1767
James Smart1dcb58e2007-04-25 09:51:30 -04001768 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001769 return -ERANGE;
1770
James Smart1dcb58e2007-04-25 09:51:30 -04001771 if ((count + off) > MAILBOX_CMD_SIZE)
1772 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001773
1774 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1775 return -EINVAL;
1776
1777 if (off && count == 0)
1778 return 0;
1779
James Smart2e0fef82007-06-17 19:56:36 -05001780 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001781
James Smart7af67052007-10-27 13:38:11 -04001782 if (phba->over_temp_state == HBA_OVER_TEMP) {
1783 sysfs_mbox_idle(phba);
1784 spin_unlock_irq(&phba->hbalock);
1785 return -EPERM;
1786 }
1787
dea31012005-04-17 16:05:31 -05001788 if (off == 0 &&
1789 phba->sysfs_mbox.state == SMBOX_WRITING &&
1790 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1791
1792 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1793 /* Offline only */
dea31012005-04-17 16:05:31 -05001794 case MBX_INIT_LINK:
1795 case MBX_DOWN_LINK:
1796 case MBX_CONFIG_LINK:
1797 case MBX_CONFIG_RING:
1798 case MBX_RESET_RING:
1799 case MBX_UNREG_LOGIN:
1800 case MBX_CLEAR_LA:
1801 case MBX_DUMP_CONTEXT:
1802 case MBX_RUN_DIAGS:
1803 case MBX_RESTART:
1804 case MBX_FLASH_WR_ULA:
1805 case MBX_SET_MASK:
1806 case MBX_SET_SLIM:
1807 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001808 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001809 printk(KERN_WARNING "mbox_read:Command 0x%x "
1810 "is illegal in on-line state\n",
1811 phba->sysfs_mbox.mbox->mb.mbxCommand);
1812 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001813 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001814 return -EPERM;
1815 }
James Smarta8adb832007-10-27 13:37:53 -04001816 case MBX_WRITE_NV:
1817 case MBX_WRITE_VPARMS:
dea31012005-04-17 16:05:31 -05001818 case MBX_LOAD_SM:
1819 case MBX_READ_NV:
1820 case MBX_READ_CONFIG:
1821 case MBX_READ_RCONFIG:
1822 case MBX_READ_STATUS:
1823 case MBX_READ_XRI:
1824 case MBX_READ_REV:
1825 case MBX_READ_LNK_STAT:
1826 case MBX_DUMP_MEMORY:
1827 case MBX_DOWN_LOAD:
1828 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001829 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001830 case MBX_LOAD_AREA:
1831 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001832 case MBX_BEACON:
1833 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001834 break;
1835 case MBX_READ_SPARM64:
1836 case MBX_READ_LA:
1837 case MBX_READ_LA64:
1838 case MBX_REG_LOGIN:
1839 case MBX_REG_LOGIN64:
1840 case MBX_CONFIG_PORT:
1841 case MBX_RUN_BIU_DIAG:
1842 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1843 phba->sysfs_mbox.mbox->mb.mbxCommand);
1844 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001845 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001846 return -EPERM;
1847 default:
1848 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1849 phba->sysfs_mbox.mbox->mb.mbxCommand);
1850 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001851 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001852 return -EPERM;
1853 }
1854
James Smart92d7f7b2007-06-17 19:56:38 -05001855 phba->sysfs_mbox.mbox->vport = vport;
1856
James Smart2e0fef82007-06-17 19:56:36 -05001857 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001858 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001859 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001860 return -EAGAIN;
1861 }
1862
James Smart2e0fef82007-06-17 19:56:36 -05001863 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001864 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1865
James Smart2e0fef82007-06-17 19:56:36 -05001866 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001867 rc = lpfc_sli_issue_mbox (phba,
1868 phba->sysfs_mbox.mbox,
1869 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001870 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001871
1872 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001873 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001874 rc = lpfc_sli_issue_mbox_wait (phba,
1875 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001876 lpfc_mbox_tmo_val(phba,
1877 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001878 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001879 }
1880
1881 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001882 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04001883 phba->sysfs_mbox.mbox = NULL;
1884 }
dea31012005-04-17 16:05:31 -05001885 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001886 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001887 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001888 }
1889 phba->sysfs_mbox.state = SMBOX_READING;
1890 }
1891 else if (phba->sysfs_mbox.offset != off ||
1892 phba->sysfs_mbox.state != SMBOX_READING) {
1893 printk(KERN_WARNING "mbox_read: Bad State\n");
1894 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001895 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001896 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001897 }
1898
1899 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1900
1901 phba->sysfs_mbox.offset = off + count;
1902
James Smart1dcb58e2007-04-25 09:51:30 -04001903 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001904 sysfs_mbox_idle(phba);
1905
James Smart2e0fef82007-06-17 19:56:36 -05001906 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001907
1908 return count;
1909}
1910
1911static struct bin_attribute sysfs_mbox_attr = {
1912 .attr = {
1913 .name = "mbox",
1914 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001915 },
James Smart1dcb58e2007-04-25 09:51:30 -04001916 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001917 .read = sysfs_mbox_read,
1918 .write = sysfs_mbox_write,
1919};
1920
1921int
James Smart2e0fef82007-06-17 19:56:36 -05001922lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001923{
James Smart2e0fef82007-06-17 19:56:36 -05001924 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001925 int error;
1926
James Smart2e0fef82007-06-17 19:56:36 -05001927 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001928 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001929 if (error)
1930 goto out;
1931
James Smart2e0fef82007-06-17 19:56:36 -05001932 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001933 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05001934 if (error)
1935 goto out_remove_ctlreg_attr;
1936
1937 return 0;
1938out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05001939 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001940out:
1941 return error;
1942}
1943
1944void
James Smart2e0fef82007-06-17 19:56:36 -05001945lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001946{
James Smart2e0fef82007-06-17 19:56:36 -05001947 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001948
James Smart2e0fef82007-06-17 19:56:36 -05001949 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1950 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001951}
1952
1953
1954/*
1955 * Dynamic FC Host Attributes Support
1956 */
1957
1958static void
1959lpfc_get_host_port_id(struct Scsi_Host *shost)
1960{
James Smart2e0fef82007-06-17 19:56:36 -05001961 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1962
dea31012005-04-17 16:05:31 -05001963 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05001964 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001965}
1966
1967static void
1968lpfc_get_host_port_type(struct Scsi_Host *shost)
1969{
James Smart2e0fef82007-06-17 19:56:36 -05001970 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1971 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001972
1973 spin_lock_irq(shost->host_lock);
1974
James Smart92d7f7b2007-06-17 19:56:38 -05001975 if (vport->port_type == LPFC_NPIV_PORT) {
1976 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1977 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001978 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05001979 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05001980 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1981 else
1982 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1983 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001984 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05001985 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1986 else
1987 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1988 }
1989 } else
1990 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1991
1992 spin_unlock_irq(shost->host_lock);
1993}
1994
1995static void
1996lpfc_get_host_port_state(struct Scsi_Host *shost)
1997{
James Smart2e0fef82007-06-17 19:56:36 -05001998 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1999 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002000
2001 spin_lock_irq(shost->host_lock);
2002
James Smart2e0fef82007-06-17 19:56:36 -05002003 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05002004 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2005 else {
James Smart2e0fef82007-06-17 19:56:36 -05002006 switch (phba->link_state) {
2007 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05002008 case LPFC_LINK_DOWN:
2009 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2010 break;
2011 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05002012 case LPFC_CLEAR_LA:
2013 case LPFC_HBA_READY:
2014 /* Links up, beyond this port_type reports state */
2015 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2016 break;
2017 case LPFC_HBA_ERROR:
2018 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
2019 break;
2020 default:
2021 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2022 break;
2023 }
2024 }
2025
2026 spin_unlock_irq(shost->host_lock);
2027}
2028
2029static void
2030lpfc_get_host_speed(struct Scsi_Host *shost)
2031{
James Smart2e0fef82007-06-17 19:56:36 -05002032 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2033 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002034
2035 spin_lock_irq(shost->host_lock);
2036
James Smart2e0fef82007-06-17 19:56:36 -05002037 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05002038 switch(phba->fc_linkspeed) {
2039 case LA_1GHZ_LINK:
2040 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2041 break;
2042 case LA_2GHZ_LINK:
2043 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2044 break;
2045 case LA_4GHZ_LINK:
2046 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2047 break;
James Smartb87eab32007-04-25 09:53:28 -04002048 case LA_8GHZ_LINK:
2049 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2050 break;
dea31012005-04-17 16:05:31 -05002051 default:
2052 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2053 break;
2054 }
2055 }
2056
2057 spin_unlock_irq(shost->host_lock);
2058}
2059
2060static void
2061lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2062{
James Smart2e0fef82007-06-17 19:56:36 -05002063 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2064 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002065 u64 node_name;
dea31012005-04-17 16:05:31 -05002066
2067 spin_lock_irq(shost->host_lock);
2068
James Smart2e0fef82007-06-17 19:56:36 -05002069 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002070 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002071 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002072 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002073 else
2074 /* fabric is local port if there is no F/FL_Port */
James Smart2e0fef82007-06-17 19:56:36 -05002075 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05002076
2077 spin_unlock_irq(shost->host_lock);
2078
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002079 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002080}
2081
dea31012005-04-17 16:05:31 -05002082static struct fc_host_statistics *
2083lpfc_get_stats(struct Scsi_Host *shost)
2084{
James Smart2e0fef82007-06-17 19:56:36 -05002085 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2086 struct lpfc_hba *phba = vport->phba;
2087 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002088 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002089 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002090 LPFC_MBOXQ_t *pmboxq;
2091 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002092 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002093 int rc = 0;
dea31012005-04-17 16:05:31 -05002094
James Smart92d7f7b2007-06-17 19:56:38 -05002095 /*
2096 * prevent udev from issuing mailbox commands until the port is
2097 * configured.
2098 */
James Smart2e0fef82007-06-17 19:56:36 -05002099 if (phba->link_state < LPFC_LINK_DOWN ||
2100 !phba->mbox_mem_pool ||
2101 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002102 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002103
2104 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002105 return NULL;
2106
dea31012005-04-17 16:05:31 -05002107 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2108 if (!pmboxq)
2109 return NULL;
2110 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2111
2112 pmb = &pmboxq->mb;
2113 pmb->mbxCommand = MBX_READ_STATUS;
2114 pmb->mbxOwner = OWN_HOST;
2115 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002116 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002117
James Smart2e0fef82007-06-17 19:56:36 -05002118 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002119 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002120 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002121 else
dea31012005-04-17 16:05:31 -05002122 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2123
2124 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002125 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002126 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002127 return NULL;
2128 }
2129
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002130 memset(hs, 0, sizeof (struct fc_host_statistics));
2131
dea31012005-04-17 16:05:31 -05002132 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2133 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2134 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2135 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2136
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002137 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002138 pmb->mbxCommand = MBX_READ_LNK_STAT;
2139 pmb->mbxOwner = OWN_HOST;
2140 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002141 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002142
James Smart2e0fef82007-06-17 19:56:36 -05002143 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002144 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002145 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002146 else
dea31012005-04-17 16:05:31 -05002147 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2148
2149 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002150 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002151 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002152 return NULL;
2153 }
2154
2155 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2156 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2157 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2158 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2159 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2160 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2161 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2162
James Smart64ba8812006-08-02 15:24:34 -04002163 hs->link_failure_count -= lso->link_failure_count;
2164 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2165 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2166 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2167 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2168 hs->invalid_crc_count -= lso->invalid_crc_count;
2169 hs->error_frames -= lso->error_frames;
2170
dea31012005-04-17 16:05:31 -05002171 if (phba->fc_topology == TOPOLOGY_LOOP) {
2172 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002173 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002174 hs->nos_count = -1;
2175 } else {
2176 hs->lip_count = -1;
2177 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002178 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002179 }
2180
2181 hs->dumped_frames = -1;
2182
James Smart64ba8812006-08-02 15:24:34 -04002183 seconds = get_seconds();
2184 if (seconds < psli->stats_start)
2185 hs->seconds_since_last_reset = seconds +
2186 ((unsigned long)-1 - psli->stats_start);
2187 else
2188 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002189
James Smart1dcb58e2007-04-25 09:51:30 -04002190 mempool_free(pmboxq, phba->mbox_mem_pool);
2191
dea31012005-04-17 16:05:31 -05002192 return hs;
2193}
2194
James Smart64ba8812006-08-02 15:24:34 -04002195static void
2196lpfc_reset_stats(struct Scsi_Host *shost)
2197{
James Smart2e0fef82007-06-17 19:56:36 -05002198 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2199 struct lpfc_hba *phba = vport->phba;
2200 struct lpfc_sli *psli = &phba->sli;
2201 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002202 LPFC_MBOXQ_t *pmboxq;
2203 MAILBOX_t *pmb;
2204 int rc = 0;
2205
James Smart2e0fef82007-06-17 19:56:36 -05002206 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002207 return;
2208
James Smart64ba8812006-08-02 15:24:34 -04002209 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2210 if (!pmboxq)
2211 return;
2212 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2213
2214 pmb = &pmboxq->mb;
2215 pmb->mbxCommand = MBX_READ_STATUS;
2216 pmb->mbxOwner = OWN_HOST;
2217 pmb->un.varWords[0] = 0x1; /* reset request */
2218 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002219 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002220
James Smart2e0fef82007-06-17 19:56:36 -05002221 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002222 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2223 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2224 else
2225 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2226
2227 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002228 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002229 mempool_free(pmboxq, phba->mbox_mem_pool);
2230 return;
2231 }
2232
2233 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2234 pmb->mbxCommand = MBX_READ_LNK_STAT;
2235 pmb->mbxOwner = OWN_HOST;
2236 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002237 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002238
James Smart2e0fef82007-06-17 19:56:36 -05002239 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002240 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2241 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2242 else
2243 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2244
2245 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002246 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002247 mempool_free( pmboxq, phba->mbox_mem_pool);
2248 return;
2249 }
2250
2251 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2252 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2253 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2254 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2255 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2256 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2257 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2258 lso->link_events = (phba->fc_eventTag >> 1);
2259
2260 psli->stats_start = get_seconds();
2261
James Smart1dcb58e2007-04-25 09:51:30 -04002262 mempool_free(pmboxq, phba->mbox_mem_pool);
2263
James Smart64ba8812006-08-02 15:24:34 -04002264 return;
2265}
dea31012005-04-17 16:05:31 -05002266
2267/*
2268 * The LPFC driver treats linkdown handling as target loss events so there
2269 * are no sysfs handlers for link_down_tmo.
2270 */
James Smart685f0bf2007-04-25 09:53:08 -04002271
2272static struct lpfc_nodelist *
2273lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002274{
James Smart2e0fef82007-06-17 19:56:36 -05002275 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2276 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002277 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002278
2279 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002280 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002281 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002282 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2283 starget->id == ndlp->nlp_sid) {
2284 spin_unlock_irq(shost->host_lock);
2285 return ndlp;
dea31012005-04-17 16:05:31 -05002286 }
2287 }
2288 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002289 return NULL;
2290}
dea31012005-04-17 16:05:31 -05002291
James Smart685f0bf2007-04-25 09:53:08 -04002292static void
2293lpfc_get_starget_port_id(struct scsi_target *starget)
2294{
2295 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2296
2297 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002298}
2299
2300static void
2301lpfc_get_starget_node_name(struct scsi_target *starget)
2302{
James Smart685f0bf2007-04-25 09:53:08 -04002303 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002304
James Smart685f0bf2007-04-25 09:53:08 -04002305 fc_starget_node_name(starget) =
2306 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002307}
2308
2309static void
2310lpfc_get_starget_port_name(struct scsi_target *starget)
2311{
James Smart685f0bf2007-04-25 09:53:08 -04002312 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002313
James Smart685f0bf2007-04-25 09:53:08 -04002314 fc_starget_port_name(starget) =
2315 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002316}
2317
2318static void
dea31012005-04-17 16:05:31 -05002319lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2320{
dea31012005-04-17 16:05:31 -05002321 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002322 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002323 else
James Smartc01f3202006-08-18 17:47:08 -04002324 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002325}
2326
2327
2328#define lpfc_rport_show_function(field, format_string, sz, cast) \
2329static ssize_t \
2330lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2331{ \
2332 struct fc_rport *rport = transport_class_to_rport(cdev); \
2333 struct lpfc_rport_data *rdata = rport->hostdata; \
2334 return snprintf(buf, sz, format_string, \
2335 (rdata->target) ? cast rdata->target->field : 0); \
2336}
2337
2338#define lpfc_rport_rd_attr(field, format_string, sz) \
2339 lpfc_rport_show_function(field, format_string, sz, ) \
2340static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2341
2342
2343struct fc_function_template lpfc_transport_functions = {
2344 /* fixed attributes the driver supports */
2345 .show_host_node_name = 1,
2346 .show_host_port_name = 1,
2347 .show_host_supported_classes = 1,
2348 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002349 .show_host_supported_speeds = 1,
2350 .show_host_maxframe_size = 1,
2351
2352 /* dynamic attributes the driver supports */
2353 .get_host_port_id = lpfc_get_host_port_id,
2354 .show_host_port_id = 1,
2355
2356 .get_host_port_type = lpfc_get_host_port_type,
2357 .show_host_port_type = 1,
2358
2359 .get_host_port_state = lpfc_get_host_port_state,
2360 .show_host_port_state = 1,
2361
2362 /* active_fc4s is shown but doesn't change (thus no get function) */
2363 .show_host_active_fc4s = 1,
2364
2365 .get_host_speed = lpfc_get_host_speed,
2366 .show_host_speed = 1,
2367
2368 .get_host_fabric_name = lpfc_get_host_fabric_name,
2369 .show_host_fabric_name = 1,
2370
2371 /*
2372 * The LPFC driver treats linkdown handling as target loss events
2373 * so there are no sysfs handlers for link_down_tmo.
2374 */
2375
2376 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002377 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002378
2379 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2380 .show_rport_maxframe_size = 1,
2381 .show_rport_supported_classes = 1,
2382
dea31012005-04-17 16:05:31 -05002383 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2384 .show_rport_dev_loss_tmo = 1,
2385
2386 .get_starget_port_id = lpfc_get_starget_port_id,
2387 .show_starget_port_id = 1,
2388
2389 .get_starget_node_name = lpfc_get_starget_node_name,
2390 .show_starget_node_name = 1,
2391
2392 .get_starget_port_name = lpfc_get_starget_port_name,
2393 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002394
2395 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002396 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2397 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002398
James Smart92d7f7b2007-06-17 19:56:38 -05002399 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2400};
2401
James Smart98c9ea52007-10-27 13:37:33 -04002402struct fc_function_template lpfc_vport_transport_functions = {
2403 /* fixed attributes the driver supports */
2404 .show_host_node_name = 1,
2405 .show_host_port_name = 1,
2406 .show_host_supported_classes = 1,
2407 .show_host_supported_fc4s = 1,
2408 .show_host_supported_speeds = 1,
2409 .show_host_maxframe_size = 1,
2410
2411 /* dynamic attributes the driver supports */
2412 .get_host_port_id = lpfc_get_host_port_id,
2413 .show_host_port_id = 1,
2414
2415 .get_host_port_type = lpfc_get_host_port_type,
2416 .show_host_port_type = 1,
2417
2418 .get_host_port_state = lpfc_get_host_port_state,
2419 .show_host_port_state = 1,
2420
2421 /* active_fc4s is shown but doesn't change (thus no get function) */
2422 .show_host_active_fc4s = 1,
2423
2424 .get_host_speed = lpfc_get_host_speed,
2425 .show_host_speed = 1,
2426
2427 .get_host_fabric_name = lpfc_get_host_fabric_name,
2428 .show_host_fabric_name = 1,
2429
2430 /*
2431 * The LPFC driver treats linkdown handling as target loss events
2432 * so there are no sysfs handlers for link_down_tmo.
2433 */
2434
2435 .get_fc_host_stats = lpfc_get_stats,
2436 .reset_fc_host_stats = lpfc_reset_stats,
2437
2438 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2439 .show_rport_maxframe_size = 1,
2440 .show_rport_supported_classes = 1,
2441
2442 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2443 .show_rport_dev_loss_tmo = 1,
2444
2445 .get_starget_port_id = lpfc_get_starget_port_id,
2446 .show_starget_port_id = 1,
2447
2448 .get_starget_node_name = lpfc_get_starget_node_name,
2449 .show_starget_node_name = 1,
2450
2451 .get_starget_port_name = lpfc_get_starget_port_name,
2452 .show_starget_port_name = 1,
2453
2454 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2455 .terminate_rport_io = lpfc_terminate_rport_io,
2456
2457 .vport_disable = lpfc_vport_disable,
2458};
2459
dea31012005-04-17 16:05:31 -05002460void
2461lpfc_get_cfgparam(struct lpfc_hba *phba)
2462{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002463 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2464 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002465 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002466 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2467 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002468 lpfc_ack0_init(phba, lpfc_ack0);
2469 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002470 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002471 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04002472 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05002473 lpfc_use_msi_init(phba, lpfc_use_msi);
James Smart13815c82008-01-11 01:52:48 -05002474 lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
2475 lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002476 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002477 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002478 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05002479 /*
2480 * The total number of segments is the configuration value plus 2
2481 * since the IOCB need a command and response bde.
2482 */
2483 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
dea31012005-04-17 16:05:31 -05002484 /*
2485 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2486 * used to create the sg_dma_buf_pool must be dynamically calculated
2487 */
2488 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2489 sizeof(struct fcp_rsp) +
2490 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002491 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002492 return;
2493}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002494
James Smart3de2a652007-08-02 11:09:59 -04002495void
2496lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2497{
James Smarte8b62012007-08-02 11:10:09 -04002498 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002499 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2500 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2501 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2502 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2503 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2504 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2505 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2506 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2507 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2508 lpfc_max_luns_init(vport, lpfc_max_luns);
2509 lpfc_scan_down_init(vport, lpfc_scan_down);
James Smart7ee5d432007-10-27 13:37:17 -04002510 lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
dea31012005-04-17 16:05:31 -05002511 return;
2512}