blob: bd35e9c7b995f5735916906db3a67ddda7ce69fe [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 Smart2e0fef82007-06-17 19:56:36 -0500190 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
191
192 switch (vport->port_state) {
193 len += snprintf(buf + len, PAGE_SIZE-len,
194 "initializing\n");
195 break;
196 case LPFC_LOCAL_CFG_LINK:
197 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500198 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500199 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500200 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500201 case LPFC_FLOGI:
202 case LPFC_FABRIC_CFG_LINK:
203 case LPFC_NS_REG:
204 case LPFC_NS_QRY:
205 case LPFC_BUILD_DISC_LIST:
206 case LPFC_DISC_AUTH:
207 len += snprintf(buf + len, PAGE_SIZE - len,
208 "Discovery\n");
209 break;
210 case LPFC_VPORT_READY:
211 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
212 break;
213
James Smart92d7f7b2007-06-17 19:56:38 -0500214 case LPFC_VPORT_FAILED:
215 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
216 break;
217
218 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500219 len += snprintf(buf + len, PAGE_SIZE - len,
220 "Unknown\n");
221 break;
222 }
223
dea31012005-04-17 16:05:31 -0500224 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500225 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500226 len += snprintf(buf + len, PAGE_SIZE-len,
227 " Public Loop\n");
228 else
229 len += snprintf(buf + len, PAGE_SIZE-len,
230 " Private Loop\n");
231 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500232 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500233 len += snprintf(buf + len, PAGE_SIZE-len,
234 " Fabric\n");
235 else
236 len += snprintf(buf + len, PAGE_SIZE-len,
237 " Point-2-Point\n");
238 }
239 }
James Smart2e0fef82007-06-17 19:56:36 -0500240
dea31012005-04-17 16:05:31 -0500241 return len;
242}
243
244static ssize_t
245lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
246{
James Smart2e0fef82007-06-17 19:56:36 -0500247 struct Scsi_Host *shost = class_to_shost(cdev);
248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
249
250 return snprintf(buf, PAGE_SIZE, "%d\n",
251 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500252}
253
254
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700255static int
James Smart2e0fef82007-06-17 19:56:36 -0500256lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500257{
James Smart2e0fef82007-06-17 19:56:36 -0500258 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
259 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500260 LPFC_MBOXQ_t *pmboxq;
261 int mbxstatus = MBXERR_ERROR;
262
James Smart2e0fef82007-06-17 19:56:36 -0500263 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
264 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
265 (vport->port_state != LPFC_VPORT_READY))
dea31012005-04-17 16:05:31 -0500266 return -EPERM;
267
268 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
269
270 if (!pmboxq)
271 return -ENOMEM;
272
273 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400274 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
275 pmboxq->mb.mbxOwner = OWN_HOST;
276
James Smart33ccf8d2006-08-17 11:57:58 -0400277 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500278
James Smart4db621e2006-07-06 15:49:49 -0400279 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
280 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
281 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
282 phba->cfg_link_speed);
283 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
284 phba->fc_ratov * 2);
285 }
286
James Smart5b8bd0c2007-04-25 09:52:49 -0400287 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500288 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400289 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500290
291 if (mbxstatus == MBXERR_ERROR)
292 return -EIO;
293
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700294 return 0;
dea31012005-04-17 16:05:31 -0500295}
296
James Smart40496f02006-07-06 15:50:22 -0400297static int
James Smart46fa3112007-04-25 09:51:45 -0400298lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
299{
300 struct completion online_compl;
301 struct lpfc_sli_ring *pring;
302 struct lpfc_sli *psli;
303 int status = 0;
304 int cnt = 0;
305 int i;
306
307 init_completion(&online_compl);
308 lpfc_workq_post_event(phba, &status, &online_compl,
309 LPFC_EVT_OFFLINE_PREP);
310 wait_for_completion(&online_compl);
311
312 if (status != 0)
313 return -EIO;
314
315 psli = &phba->sli;
316
317 for (i = 0; i < psli->num_rings; i++) {
318 pring = &psli->ring[i];
319 /* The linkdown event takes 30 seconds to timeout. */
320 while (pring->txcmplq_cnt) {
321 msleep(10);
322 if (cnt++ > 3000) {
323 lpfc_printf_log(phba,
324 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400325 "0466 Outstanding IO when "
326 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400327 break;
328 }
329 }
330 }
331
332 init_completion(&online_compl);
333 lpfc_workq_post_event(phba, &status, &online_compl, type);
334 wait_for_completion(&online_compl);
335
336 if (status != 0)
337 return -EIO;
338
339 return 0;
340}
341
342static int
James Smart40496f02006-07-06 15:50:22 -0400343lpfc_selective_reset(struct lpfc_hba *phba)
344{
345 struct completion online_compl;
346 int status = 0;
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
421 init_completion(&online_compl);
422
James Smart46fa3112007-04-25 09:51:45 -0400423 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500424 lpfc_workq_post_event(phba, &status, &online_compl,
425 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400426 wait_for_completion(&online_compl);
427 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
428 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500429 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400430 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
431 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
432 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500433 else
434 return -EINVAL;
435
Jamie Wellnitz41415862006-02-28 19:25:27 -0500436 if (!status)
437 return strlen(buf);
438 else
439 return -EIO;
440}
441
James Smart311464e2007-08-02 11:10:37 -0400442static int
James Smart858c9f62007-06-17 19:56:39 -0500443lpfc_get_hba_info(struct lpfc_hba *phba,
444 uint32_t *mxri, uint32_t *axri,
445 uint32_t *mrpi, uint32_t *arpi,
446 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500447{
448 struct lpfc_sli *psli = &phba->sli;
449 LPFC_MBOXQ_t *pmboxq;
450 MAILBOX_t *pmb;
451 int rc = 0;
452
453 /*
454 * prevent udev from issuing mailbox commands until the port is
455 * configured.
456 */
457 if (phba->link_state < LPFC_LINK_DOWN ||
458 !phba->mbox_mem_pool ||
459 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
460 return 0;
461
462 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
463 return 0;
464
465 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
466 if (!pmboxq)
467 return 0;
468 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
469
470 pmb = &pmboxq->mb;
471 pmb->mbxCommand = MBX_READ_CONFIG;
472 pmb->mbxOwner = OWN_HOST;
473 pmboxq->context1 = NULL;
474
475 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
476 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
477 rc = MBX_NOT_FINISHED;
478 else
479 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
480
481 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500482 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500483 mempool_free(pmboxq, phba->mbox_mem_pool);
484 return 0;
485 }
486
487 if (mrpi)
488 *mrpi = pmb->un.varRdConfig.max_rpi;
489 if (arpi)
490 *arpi = pmb->un.varRdConfig.avail_rpi;
491 if (mxri)
492 *mxri = pmb->un.varRdConfig.max_xri;
493 if (axri)
494 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500495 if (mvpi)
496 *mvpi = pmb->un.varRdConfig.max_vpi;
497 if (avpi)
498 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500499
500 mempool_free(pmboxq, phba->mbox_mem_pool);
501 return 1;
502}
503
504static ssize_t
505lpfc_max_rpi_show(struct class_device *cdev, char *buf)
506{
507 struct Scsi_Host *shost = class_to_shost(cdev);
508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
509 struct lpfc_hba *phba = vport->phba;
510 uint32_t cnt;
511
James Smart858c9f62007-06-17 19:56:39 -0500512 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500513 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
514 return snprintf(buf, PAGE_SIZE, "Unknown\n");
515}
516
517static ssize_t
518lpfc_used_rpi_show(struct class_device *cdev, char *buf)
519{
520 struct Scsi_Host *shost = class_to_shost(cdev);
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
522 struct lpfc_hba *phba = vport->phba;
523 uint32_t cnt, acnt;
524
James Smart858c9f62007-06-17 19:56:39 -0500525 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500526 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
527 return snprintf(buf, PAGE_SIZE, "Unknown\n");
528}
529
530static ssize_t
531lpfc_max_xri_show(struct class_device *cdev, char *buf)
532{
533 struct Scsi_Host *shost = class_to_shost(cdev);
534 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
535 struct lpfc_hba *phba = vport->phba;
536 uint32_t cnt;
537
James Smart858c9f62007-06-17 19:56:39 -0500538 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500539 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
540 return snprintf(buf, PAGE_SIZE, "Unknown\n");
541}
542
543static ssize_t
544lpfc_used_xri_show(struct class_device *cdev, char *buf)
545{
546 struct Scsi_Host *shost = class_to_shost(cdev);
547 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
548 struct lpfc_hba *phba = vport->phba;
549 uint32_t cnt, acnt;
550
James Smart858c9f62007-06-17 19:56:39 -0500551 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
552 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
553 return snprintf(buf, PAGE_SIZE, "Unknown\n");
554}
555
556static ssize_t
557lpfc_max_vpi_show(struct class_device *cdev, char *buf)
558{
559 struct Scsi_Host *shost = class_to_shost(cdev);
560 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
561 struct lpfc_hba *phba = vport->phba;
562 uint32_t cnt;
563
564 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
565 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
566 return snprintf(buf, PAGE_SIZE, "Unknown\n");
567}
568
569static ssize_t
570lpfc_used_vpi_show(struct class_device *cdev, char *buf)
571{
572 struct Scsi_Host *shost = class_to_shost(cdev);
573 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
574 struct lpfc_hba *phba = vport->phba;
575 uint32_t cnt, acnt;
576
577 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500578 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
579 return snprintf(buf, PAGE_SIZE, "Unknown\n");
580}
581
582static ssize_t
583lpfc_npiv_info_show(struct class_device *cdev, char *buf)
584{
585 struct Scsi_Host *shost = class_to_shost(cdev);
586 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
587 struct lpfc_hba *phba = vport->phba;
588
589 if (!(phba->max_vpi))
590 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
591 if (vport->port_type == LPFC_PHYSICAL_PORT)
592 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
593 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
594}
595
Jamie Wellnitz41415862006-02-28 19:25:27 -0500596static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500597lpfc_poll_show(struct class_device *cdev, char *buf)
598{
James Smart2e0fef82007-06-17 19:56:36 -0500599 struct Scsi_Host *shost = class_to_shost(cdev);
600 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
601 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500602
603 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
604}
605
606static ssize_t
607lpfc_poll_store(struct class_device *cdev, const char *buf,
608 size_t count)
609{
James Smart2e0fef82007-06-17 19:56:36 -0500610 struct Scsi_Host *shost = class_to_shost(cdev);
611 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
612 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500613 uint32_t creg_val;
614 uint32_t old_val;
615 int val=0;
616
617 if (!isdigit(buf[0]))
618 return -EINVAL;
619
620 if (sscanf(buf, "%i", &val) != 1)
621 return -EINVAL;
622
623 if ((val & 0x3) != val)
624 return -EINVAL;
625
James Smart2e0fef82007-06-17 19:56:36 -0500626 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500627
628 old_val = phba->cfg_poll;
629
630 if (val & ENABLE_FCP_RING_POLLING) {
631 if ((val & DISABLE_FCP_RING_INT) &&
632 !(old_val & DISABLE_FCP_RING_INT)) {
633 creg_val = readl(phba->HCregaddr);
634 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
635 writel(creg_val, phba->HCregaddr);
636 readl(phba->HCregaddr); /* flush */
637
638 lpfc_poll_start_timer(phba);
639 }
640 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500641 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500642 return -EINVAL;
643 }
644
645 if (!(val & DISABLE_FCP_RING_INT) &&
646 (old_val & DISABLE_FCP_RING_INT))
647 {
James Smart2e0fef82007-06-17 19:56:36 -0500648 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500649 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500650 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500651 creg_val = readl(phba->HCregaddr);
652 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
653 writel(creg_val, phba->HCregaddr);
654 readl(phba->HCregaddr); /* flush */
655 }
656
657 phba->cfg_poll = val;
658
James Smart2e0fef82007-06-17 19:56:36 -0500659 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500660
661 return strlen(buf);
662}
dea31012005-04-17 16:05:31 -0500663
664#define lpfc_param_show(attr) \
665static ssize_t \
666lpfc_##attr##_show(struct class_device *cdev, char *buf) \
667{ \
James Smart2e0fef82007-06-17 19:56:36 -0500668 struct Scsi_Host *shost = class_to_shost(cdev);\
669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
670 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500671 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400672 val = phba->cfg_##attr;\
673 return snprintf(buf, PAGE_SIZE, "%d\n",\
674 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500675}
676
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400677#define lpfc_param_hex_show(attr) \
678static ssize_t \
679lpfc_##attr##_show(struct class_device *cdev, char *buf) \
680{ \
James Smart2e0fef82007-06-17 19:56:36 -0500681 struct Scsi_Host *shost = class_to_shost(cdev);\
682 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
683 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400684 int val = 0;\
685 val = phba->cfg_##attr;\
686 return snprintf(buf, PAGE_SIZE, "%#x\n",\
687 phba->cfg_##attr);\
688}
689
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400690#define lpfc_param_init(attr, default, minval, maxval) \
691static int \
692lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
693{ \
694 if (val >= minval && val <= maxval) {\
695 phba->cfg_##attr = val;\
696 return 0;\
697 }\
698 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400699 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
700 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400701 phba->cfg_##attr = default;\
702 return -EINVAL;\
703}
704
705#define lpfc_param_set(attr, default, minval, maxval) \
706static int \
707lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
708{ \
709 if (val >= minval && val <= maxval) {\
710 phba->cfg_##attr = val;\
711 return 0;\
712 }\
713 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400714 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
715 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400716 return -EINVAL;\
717}
718
719#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500720static ssize_t \
721lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
722{ \
James Smart2e0fef82007-06-17 19:56:36 -0500723 struct Scsi_Host *shost = class_to_shost(cdev);\
724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
725 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400726 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400727 if (!isdigit(buf[0]))\
728 return -EINVAL;\
729 if (sscanf(buf, "%i", &val) != 1)\
730 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400731 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400732 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400733 else \
734 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500735}
736
James Smart3de2a652007-08-02 11:09:59 -0400737#define lpfc_vport_param_show(attr) \
738static ssize_t \
739lpfc_##attr##_show(struct class_device *cdev, char *buf) \
740{ \
741 struct Scsi_Host *shost = class_to_shost(cdev);\
742 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
743 int val = 0;\
744 val = vport->cfg_##attr;\
745 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
746}
747
748#define lpfc_vport_param_hex_show(attr) \
749static ssize_t \
750lpfc_##attr##_show(struct class_device *cdev, char *buf) \
751{ \
752 struct Scsi_Host *shost = class_to_shost(cdev);\
753 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
754 int val = 0;\
755 val = vport->cfg_##attr;\
756 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
757}
758
759#define lpfc_vport_param_init(attr, default, minval, maxval) \
760static int \
761lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
762{ \
763 if (val >= minval && val <= maxval) {\
764 vport->cfg_##attr = val;\
765 return 0;\
766 }\
James Smarte8b62012007-08-02 11:10:09 -0400767 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
768 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
769 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400770 vport->cfg_##attr = default;\
771 return -EINVAL;\
772}
773
774#define lpfc_vport_param_set(attr, default, minval, maxval) \
775static int \
776lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
777{ \
778 if (val >= minval && val <= maxval) {\
779 vport->cfg_##attr = val;\
780 return 0;\
781 }\
James Smarte8b62012007-08-02 11:10:09 -0400782 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
783 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
784 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400785 return -EINVAL;\
786}
787
788#define lpfc_vport_param_store(attr) \
789static ssize_t \
790lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
791{ \
792 struct Scsi_Host *shost = class_to_shost(cdev);\
793 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
794 int val=0;\
795 if (!isdigit(buf[0]))\
796 return -EINVAL;\
797 if (sscanf(buf, "%i", &val) != 1)\
798 return -EINVAL;\
799 if (lpfc_##attr##_set(vport, val) == 0) \
800 return strlen(buf);\
801 else \
802 return -EINVAL;\
803}
804
805
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400806#define LPFC_ATTR(name, defval, minval, maxval, desc) \
807static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500808module_param(lpfc_##name, int, 0);\
809MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400810lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500811
812#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
813static int lpfc_##name = defval;\
814module_param(lpfc_##name, int, 0);\
815MODULE_PARM_DESC(lpfc_##name, desc);\
816lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400817lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500818static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
819
820#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
821static int lpfc_##name = defval;\
822module_param(lpfc_##name, int, 0);\
823MODULE_PARM_DESC(lpfc_##name, desc);\
824lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400825lpfc_param_init(name, defval, minval, maxval)\
826lpfc_param_set(name, defval, minval, maxval)\
827lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500828static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
829 lpfc_##name##_show, lpfc_##name##_store)
830
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400831#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
832static int lpfc_##name = defval;\
833module_param(lpfc_##name, int, 0);\
834MODULE_PARM_DESC(lpfc_##name, desc);\
835lpfc_param_hex_show(name)\
836lpfc_param_init(name, defval, minval, maxval)\
837static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
838
839#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
840static int lpfc_##name = defval;\
841module_param(lpfc_##name, int, 0);\
842MODULE_PARM_DESC(lpfc_##name, desc);\
843lpfc_param_hex_show(name)\
844lpfc_param_init(name, defval, minval, maxval)\
845lpfc_param_set(name, defval, minval, maxval)\
846lpfc_param_store(name)\
847static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
848 lpfc_##name##_show, lpfc_##name##_store)
849
James Smart3de2a652007-08-02 11:09:59 -0400850#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
851static int lpfc_##name = defval;\
852module_param(lpfc_##name, int, 0);\
853MODULE_PARM_DESC(lpfc_##name, desc);\
854lpfc_vport_param_init(name, defval, minval, maxval)
855
856#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
857static int lpfc_##name = defval;\
858module_param(lpfc_##name, int, 0);\
859MODULE_PARM_DESC(lpfc_##name, desc);\
860lpfc_vport_param_show(name)\
861lpfc_vport_param_init(name, defval, minval, maxval)\
862static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
863
864#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
865static int lpfc_##name = defval;\
866module_param(lpfc_##name, int, 0);\
867MODULE_PARM_DESC(lpfc_##name, desc);\
868lpfc_vport_param_show(name)\
869lpfc_vport_param_init(name, defval, minval, maxval)\
870lpfc_vport_param_set(name, defval, minval, maxval)\
871lpfc_vport_param_store(name)\
872static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
873 lpfc_##name##_show, lpfc_##name##_store)
874
875#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
876static int lpfc_##name = defval;\
877module_param(lpfc_##name, int, 0);\
878MODULE_PARM_DESC(lpfc_##name, desc);\
879lpfc_vport_param_hex_show(name)\
880lpfc_vport_param_init(name, defval, minval, maxval)\
881static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
882
883#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
884static int lpfc_##name = defval;\
885module_param(lpfc_##name, int, 0);\
886MODULE_PARM_DESC(lpfc_##name, desc);\
887lpfc_vport_param_hex_show(name)\
888lpfc_vport_param_init(name, defval, minval, maxval)\
889lpfc_vport_param_set(name, defval, minval, maxval)\
890lpfc_vport_param_store(name)\
891static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
892 lpfc_##name##_show, lpfc_##name##_store)
893
dea31012005-04-17 16:05:31 -0500894static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
895static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
896static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
897static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
898static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500899static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500900static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
901static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
902static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
903static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
904 lpfc_option_rom_version_show, NULL);
905static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
906 lpfc_num_discovered_ports_show, NULL);
907static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
908static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
909 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500910static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
911 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400912static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500913static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
914static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
915static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
916static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
917static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
918static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
919static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
James Smart57127f12007-10-27 13:37:05 -0400920static CLASS_DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show,
921 NULL);
dea31012005-04-17 16:05:31 -0500922
James Smartc3f28af2006-08-18 17:47:18 -0400923
James Smarta12e07b2006-12-02 13:35:30 -0500924static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400925
926static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500927lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400928 size_t count)
929{
James Smart2e0fef82007-06-17 19:56:36 -0500930 struct Scsi_Host *shost = class_to_shost(cdev);
931 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
932 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400933 unsigned int cnt = count;
934
935 /*
936 * We're doing a simple sanity check for soft_wwpn setting.
937 * We require that the user write a specific key to enable
938 * the soft_wwpn attribute to be settable. Once the attribute
939 * is written, the enable key resets. If further updates are
940 * desired, the key must be written again to re-enable the
941 * attribute.
942 *
943 * The "key" is not secret - it is a hardcoded string shown
944 * here. The intent is to protect against the random user or
945 * application that is just writing attributes.
946 */
947
948 /* count may include a LF at end of string */
949 if (buf[cnt-1] == '\n')
950 cnt--;
951
James Smarta12e07b2006-12-02 13:35:30 -0500952 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
953 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400954 return -EINVAL;
955
James Smarta12e07b2006-12-02 13:35:30 -0500956 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400957 return count;
958}
James Smarta12e07b2006-12-02 13:35:30 -0500959static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
960 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400961
962static ssize_t
963lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
964{
James Smart2e0fef82007-06-17 19:56:36 -0500965 struct Scsi_Host *shost = class_to_shost(cdev);
966 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
967 struct lpfc_hba *phba = vport->phba;
968
Randy Dunlapafc071e2006-10-23 21:47:13 -0700969 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
970 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400971}
972
973
974static ssize_t
975lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
976{
James Smart2e0fef82007-06-17 19:56:36 -0500977 struct Scsi_Host *shost = class_to_shost(cdev);
978 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
979 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400980 struct completion online_compl;
981 int stat1=0, stat2=0;
982 unsigned int i, j, cnt=count;
983 u8 wwpn[8];
984
985 /* count may include a LF at end of string */
986 if (buf[cnt-1] == '\n')
987 cnt--;
988
James Smarta12e07b2006-12-02 13:35:30 -0500989 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400990 ((cnt == 17) && (*buf++ != 'x')) ||
991 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
992 return -EINVAL;
993
James Smarta12e07b2006-12-02 13:35:30 -0500994 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400995
996 memset(wwpn, 0, sizeof(wwpn));
997
998 /* Validate and store the new name */
999 for (i=0, j=0; i < 16; i++) {
1000 if ((*buf >= 'a') && (*buf <= 'f'))
1001 j = ((j << 4) | ((*buf++ -'a') + 10));
1002 else if ((*buf >= 'A') && (*buf <= 'F'))
1003 j = ((j << 4) | ((*buf++ -'A') + 10));
1004 else if ((*buf >= '0') && (*buf <= '9'))
1005 j = ((j << 4) | (*buf++ -'0'));
1006 else
1007 return -EINVAL;
1008 if (i % 2) {
1009 wwpn[i/2] = j & 0xff;
1010 j = 0;
1011 }
1012 }
1013 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001014 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001015 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001016 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001017
1018 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1019 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1020
James Smart46fa3112007-04-25 09:51:45 -04001021 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001022 if (stat1)
1023 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001024 "0463 lpfc_soft_wwpn attribute set failed to "
1025 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001026 init_completion(&online_compl);
1027 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1028 wait_for_completion(&online_compl);
1029 if (stat2)
1030 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001031 "0464 lpfc_soft_wwpn attribute set failed to "
1032 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001033 return (stat1 || stat2) ? -EIO : count;
1034}
1035static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1036 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1037
James Smarta12e07b2006-12-02 13:35:30 -05001038static ssize_t
1039lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1040{
James Smart51ef4c22007-08-02 11:10:31 -04001041 struct Scsi_Host *shost = class_to_shost(cdev);
1042 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
James Smarta12e07b2006-12-02 13:35:30 -05001043 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1044 (unsigned long long)phba->cfg_soft_wwnn);
1045}
1046
1047
1048static ssize_t
1049lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
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 unsigned int i, j, cnt=count;
1054 u8 wwnn[8];
1055
1056 /* count may include a LF at end of string */
1057 if (buf[cnt-1] == '\n')
1058 cnt--;
1059
1060 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1061 ((cnt == 17) && (*buf++ != 'x')) ||
1062 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1063 return -EINVAL;
1064
1065 /*
1066 * Allow wwnn to be set many times, as long as the enable is set.
1067 * However, once the wwpn is set, everything locks.
1068 */
1069
1070 memset(wwnn, 0, sizeof(wwnn));
1071
1072 /* Validate and store the new name */
1073 for (i=0, j=0; i < 16; i++) {
1074 if ((*buf >= 'a') && (*buf <= 'f'))
1075 j = ((j << 4) | ((*buf++ -'a') + 10));
1076 else if ((*buf >= 'A') && (*buf <= 'F'))
1077 j = ((j << 4) | ((*buf++ -'A') + 10));
1078 else if ((*buf >= '0') && (*buf <= '9'))
1079 j = ((j << 4) | (*buf++ -'0'));
1080 else
1081 return -EINVAL;
1082 if (i % 2) {
1083 wwnn[i/2] = j & 0xff;
1084 j = 0;
1085 }
1086 }
1087 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1088
1089 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1090 "lpfc%d: soft_wwnn set. Value will take effect upon "
1091 "setting of the soft_wwpn\n", phba->brd_no);
1092
1093 return count;
1094}
1095static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1096 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1097
James Smartc3f28af2006-08-18 17:47:18 -04001098
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001099static int lpfc_poll = 0;
1100module_param(lpfc_poll, int, 0);
1101MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1102 " 0 - none,"
1103 " 1 - poll with interrupts enabled"
1104 " 3 - poll and disable FCP ring interrupts");
1105
1106static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1107 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001108
James Smart92d7f7b2007-06-17 19:56:38 -05001109int lpfc_sli_mode = 0;
1110module_param(lpfc_sli_mode, int, 0);
1111MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1112 " 0 - auto (SLI-3 if supported),"
1113 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1114 " 3 - select SLI-3");
1115
James Smart78b2d852007-08-02 11:10:21 -04001116LPFC_ATTR_R(enable_npiv, 0, 0, 1, "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05001117
dea31012005-04-17 16:05:31 -05001118/*
James Smartc01f3202006-08-18 17:47:08 -04001119# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1120# until the timer expires. Value range is [0,255]. Default value is 30.
1121*/
1122static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1123static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1124module_param(lpfc_nodev_tmo, int, 0);
1125MODULE_PARM_DESC(lpfc_nodev_tmo,
1126 "Seconds driver will hold I/O waiting "
1127 "for a device to come back");
1128static ssize_t
1129lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1130{
James Smart2e0fef82007-06-17 19:56:36 -05001131 struct Scsi_Host *shost = class_to_shost(cdev);
1132 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001133 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001134 val = vport->cfg_devloss_tmo;
1135 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001136}
1137
1138static int
James Smart3de2a652007-08-02 11:09:59 -04001139lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001140{
James Smart3de2a652007-08-02 11:09:59 -04001141 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1142 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1143 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001144 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1145 "0402 Ignoring nodev_tmo module "
1146 "parameter because devloss_tmo is "
1147 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001148 return 0;
1149 }
1150
1151 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001152 vport->cfg_nodev_tmo = val;
1153 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001154 return 0;
1155 }
James Smarte8b62012007-08-02 11:10:09 -04001156 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1157 "0400 lpfc_nodev_tmo attribute cannot be set to"
1158 " %d, allowed range is [%d, %d]\n",
1159 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001160 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001161 return -EINVAL;
1162}
1163
James Smart7054a602007-04-25 09:52:34 -04001164static void
James Smart3de2a652007-08-02 11:09:59 -04001165lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001166{
James Smart858c9f62007-06-17 19:56:39 -05001167 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001168 struct lpfc_nodelist *ndlp;
1169
James Smart51ef4c22007-08-02 11:10:31 -04001170 shost = lpfc_shost_from_vport(vport);
1171 spin_lock_irq(shost->host_lock);
1172 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
1173 if (ndlp->rport)
1174 ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
1175 spin_unlock_irq(shost->host_lock);
James Smart7054a602007-04-25 09:52:34 -04001176}
1177
James Smartc01f3202006-08-18 17:47:08 -04001178static int
James Smart3de2a652007-08-02 11:09:59 -04001179lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001180{
James Smart3de2a652007-08-02 11:09:59 -04001181 if (vport->dev_loss_tmo_changed ||
1182 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001183 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1184 "0401 Ignoring change to nodev_tmo "
1185 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001186 return 0;
1187 }
James Smartc01f3202006-08-18 17:47:08 -04001188 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001189 vport->cfg_nodev_tmo = val;
1190 vport->cfg_devloss_tmo = val;
1191 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001192 return 0;
1193 }
James Smarte8b62012007-08-02 11:10:09 -04001194 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1195 "0403 lpfc_nodev_tmo attribute cannot be set to"
1196 "%d, allowed range is [%d, %d]\n",
1197 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001198 return -EINVAL;
1199}
1200
James Smart3de2a652007-08-02 11:09:59 -04001201lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001202
1203static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1204 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1205
1206/*
1207# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1208# disappear until the timer expires. Value range is [0,255]. Default
1209# value is 30.
1210*/
1211module_param(lpfc_devloss_tmo, int, 0);
1212MODULE_PARM_DESC(lpfc_devloss_tmo,
1213 "Seconds driver will hold I/O waiting "
1214 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001215lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1216 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1217lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001218static int
James Smart3de2a652007-08-02 11:09:59 -04001219lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001220{
1221 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001222 vport->cfg_nodev_tmo = val;
1223 vport->cfg_devloss_tmo = val;
1224 vport->dev_loss_tmo_changed = 1;
1225 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001226 return 0;
1227 }
1228
James Smarte8b62012007-08-02 11:10:09 -04001229 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1230 "0404 lpfc_devloss_tmo attribute cannot be set to"
1231 " %d, allowed range is [%d, %d]\n",
1232 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001233 return -EINVAL;
1234}
1235
James Smart3de2a652007-08-02 11:09:59 -04001236lpfc_vport_param_store(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001237static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1238 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1239
1240/*
dea31012005-04-17 16:05:31 -05001241# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1242# deluged with LOTS of information.
1243# You can set a bit mask to record specific types of verbose messages:
1244#
1245# LOG_ELS 0x1 ELS events
1246# LOG_DISCOVERY 0x2 Link discovery events
1247# LOG_MBOX 0x4 Mailbox events
1248# LOG_INIT 0x8 Initialization events
1249# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001250# LOG_FCP 0x40 FCP traffic history
1251# LOG_NODE 0x80 Node table events
1252# LOG_MISC 0x400 Miscellaneous events
1253# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001254# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001255# LOG_LIBDFC 0x2000 LIBDFC events
1256# LOG_ALL_MSG 0xffff LOG all messages
1257*/
James Smarte8b62012007-08-02 11:10:09 -04001258LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1259 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001260
1261/*
1262# lun_queue_depth: This parameter is used to limit the number of outstanding
1263# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1264*/
James Smart3de2a652007-08-02 11:09:59 -04001265LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1266 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001267
1268/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001269# hba_queue_depth: This parameter is used to limit the number of outstanding
1270# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1271# value is greater than the maximum number of exchanges supported by the HBA,
1272# then maximum number of exchanges supported by the HBA is used to determine
1273# the hba_queue_depth.
1274*/
1275LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1276 "Max number of FCP commands we can queue to a lpfc HBA");
1277
1278/*
James Smart92d7f7b2007-06-17 19:56:38 -05001279# peer_port_login: This parameter allows/prevents logins
1280# between peer ports hosted on the same physical port.
1281# When this parameter is set 0 peer ports of same physical port
1282# are not allowed to login to each other.
1283# When this parameter is set 1 peer ports of same physical port
1284# are allowed to login to each other.
1285# Default value of this parameter is 0.
1286*/
James Smart3de2a652007-08-02 11:09:59 -04001287LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1288 "Allow peer ports on the same physical port to login to each "
1289 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001290
1291/*
James Smart3de2a652007-08-02 11:09:59 -04001292# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001293# between Virtual Ports and remote initiators.
1294# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1295# other initiators and will attempt to PLOGI all remote ports.
1296# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1297# remote ports and will not attempt to PLOGI to other initiators.
1298# This parameter does not restrict to the physical port.
1299# This parameter does not restrict logins to Fabric resident remote ports.
1300# Default value of this parameter is 1.
1301*/
James Smart3de2a652007-08-02 11:09:59 -04001302static int lpfc_restrict_login = 1;
1303module_param(lpfc_restrict_login, int, 0);
1304MODULE_PARM_DESC(lpfc_restrict_login,
1305 "Restrict virtual ports login to remote initiators.");
1306lpfc_vport_param_show(restrict_login);
1307
1308static int
1309lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1310{
1311 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001312 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1313 "0449 lpfc_restrict_login attribute cannot "
1314 "be set to %d, allowed range is [0, 1]\n",
1315 val);
James Smart3de2a652007-08-02 11:09:59 -04001316 vport->cfg_restrict_login = 1;
1317 return -EINVAL;
1318 }
1319 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1320 vport->cfg_restrict_login = 0;
1321 return 0;
1322 }
1323 vport->cfg_restrict_login = val;
1324 return 0;
1325}
1326
1327static int
1328lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1329{
1330 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001331 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1332 "0450 lpfc_restrict_login attribute cannot "
1333 "be set to %d, allowed range is [0, 1]\n",
1334 val);
James Smart3de2a652007-08-02 11:09:59 -04001335 vport->cfg_restrict_login = 1;
1336 return -EINVAL;
1337 }
1338 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001339 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1340 "0468 lpfc_restrict_login must be 0 for "
1341 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001342 vport->cfg_restrict_login = 0;
1343 return 0;
1344 }
1345 vport->cfg_restrict_login = val;
1346 return 0;
1347}
1348lpfc_vport_param_store(restrict_login);
1349static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1350 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001351
1352/*
dea31012005-04-17 16:05:31 -05001353# Some disk devices have a "select ID" or "select Target" capability.
1354# From a protocol standpoint "select ID" usually means select the
1355# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1356# annex" which contains a table that maps a "select ID" (a number
1357# between 0 and 7F) to an ALPA. By default, for compatibility with
1358# older drivers, the lpfc driver scans this table from low ALPA to high
1359# ALPA.
1360#
1361# Turning on the scan-down variable (on = 1, off = 0) will
1362# cause the lpfc driver to use an inverted table, effectively
1363# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1364#
1365# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1366# and will not work across a fabric. Also this parameter will take
1367# effect only in the case when ALPA map is not available.)
1368*/
James Smart3de2a652007-08-02 11:09:59 -04001369LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1370 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001371
1372/*
dea31012005-04-17 16:05:31 -05001373# lpfc_topology: link topology for init link
1374# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001375# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001376# 0x02 = attempt point-to-point mode only
1377# 0x04 = attempt loop mode only
1378# 0x06 = attempt point-to-point mode then loop
1379# Set point-to-point mode if you want to run as an N_Port.
1380# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1381# Default value is 0.
1382*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001383LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -05001384
1385/*
1386# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1387# connection.
1388# 0 = auto select (default)
1389# 1 = 1 Gigabaud
1390# 2 = 2 Gigabaud
1391# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001392# 8 = 8 Gigabaud
1393# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001394*/
James Smartb87eab32007-04-25 09:53:28 -04001395LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -05001396
1397/*
1398# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1399# Value range is [2,3]. Default value is 3.
1400*/
James Smart3de2a652007-08-02 11:09:59 -04001401LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1402 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001403
1404/*
1405# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1406# is [0,1]. Default value is 0.
1407*/
James Smart3de2a652007-08-02 11:09:59 -04001408LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1409 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001410
1411/*
1412# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1413# range is [0,1]. Default value is 0.
1414*/
1415LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1416
1417/*
1418# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1419# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001420# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001421# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1422# cr_delay is set to 0.
1423*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001424LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001425 "interrupt response is generated");
1426
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001427LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001428 "interrupt response is generated");
1429
1430/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001431# lpfc_multi_ring_support: Determines how many rings to spread available
1432# cmd/rsp IOCB entries across.
1433# Value range is [1,2]. Default value is 1.
1434*/
1435LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1436 "SLI rings to spread IOCB entries across");
1437
1438/*
James Smarta4bc3372006-12-02 13:34:16 -05001439# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1440# identifies what rctl value to configure the additional ring for.
1441# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1442*/
1443LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1444 255, "Identifies RCTL for additional ring configuration");
1445
1446/*
1447# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1448# identifies what type value to configure the additional ring for.
1449# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1450*/
1451LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1452 255, "Identifies TYPE for additional ring configuration");
1453
1454/*
dea31012005-04-17 16:05:31 -05001455# lpfc_fdmi_on: controls FDMI support.
1456# 0 = no FDMI support
1457# 1 = support FDMI without attribute of hostname
1458# 2 = support FDMI with attribute of hostname
1459# Value range [0,2]. Default value is 0.
1460*/
James Smart3de2a652007-08-02 11:09:59 -04001461LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001462
1463/*
1464# Specifies the maximum number of ELS cmds we can have outstanding (for
1465# discovery). Value range is [1,64]. Default value = 32.
1466*/
James Smart3de2a652007-08-02 11:09:59 -04001467LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001468 "during discovery");
1469
1470/*
James Smart65a29c12006-07-06 15:50:50 -04001471# lpfc_max_luns: maximum allowed LUN.
1472# Value range is [0,65535]. Default value is 255.
1473# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001474*/
James Smart3de2a652007-08-02 11:09:59 -04001475LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001476
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001477/*
1478# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1479# Value range is [1,255], default value is 10.
1480*/
1481LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1482 "Milliseconds driver will wait between polling FCP ring");
1483
James Smart4ff43242006-12-02 13:34:56 -05001484/*
1485# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1486# support this feature
1487# 0 = MSI disabled (default)
1488# 1 = MSI enabled
1489# Value range is [0,1]. Default value is 0.
1490*/
1491LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1492
James Smartc3f28af2006-08-18 17:47:18 -04001493
James Smart92d7f7b2007-06-17 19:56:38 -05001494
James Smart2e0fef82007-06-17 19:56:36 -05001495struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001496 &class_device_attr_info,
1497 &class_device_attr_serialnum,
1498 &class_device_attr_modeldesc,
1499 &class_device_attr_modelname,
1500 &class_device_attr_programtype,
1501 &class_device_attr_portnum,
1502 &class_device_attr_fwrev,
1503 &class_device_attr_hdw,
1504 &class_device_attr_option_rom_version,
1505 &class_device_attr_state,
1506 &class_device_attr_num_discovered_ports,
1507 &class_device_attr_lpfc_drvr_version,
James Smart57127f12007-10-27 13:37:05 -04001508 &class_device_attr_lpfc_temp_sensor,
dea31012005-04-17 16:05:31 -05001509 &class_device_attr_lpfc_log_verbose,
1510 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001511 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001512 &class_device_attr_lpfc_peer_port_login,
dea31012005-04-17 16:05:31 -05001513 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001514 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001515 &class_device_attr_lpfc_fcp_class,
1516 &class_device_attr_lpfc_use_adisc,
1517 &class_device_attr_lpfc_ack0,
1518 &class_device_attr_lpfc_topology,
1519 &class_device_attr_lpfc_scan_down,
1520 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001521 &class_device_attr_lpfc_cr_delay,
1522 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001523 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001524 &class_device_attr_lpfc_multi_ring_rctl,
1525 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001526 &class_device_attr_lpfc_fdmi_on,
1527 &class_device_attr_lpfc_max_luns,
James Smart78b2d852007-08-02 11:10:21 -04001528 &class_device_attr_lpfc_enable_npiv,
dea31012005-04-17 16:05:31 -05001529 &class_device_attr_nport_evt_cnt,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001530 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001531 &class_device_attr_max_vpi,
1532 &class_device_attr_used_vpi,
1533 &class_device_attr_max_rpi,
1534 &class_device_attr_used_rpi,
1535 &class_device_attr_max_xri,
1536 &class_device_attr_used_xri,
1537 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001538 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001539 &class_device_attr_lpfc_poll,
1540 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001541 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001542 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001543 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001544 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001545 NULL,
1546};
1547
James Smart3de2a652007-08-02 11:09:59 -04001548struct class_device_attribute *lpfc_vport_attrs[] = {
1549 &class_device_attr_info,
1550 &class_device_attr_state,
1551 &class_device_attr_num_discovered_ports,
1552 &class_device_attr_lpfc_drvr_version,
1553
1554 &class_device_attr_lpfc_log_verbose,
1555 &class_device_attr_lpfc_lun_queue_depth,
1556 &class_device_attr_lpfc_nodev_tmo,
1557 &class_device_attr_lpfc_devloss_tmo,
1558 &class_device_attr_lpfc_hba_queue_depth,
1559 &class_device_attr_lpfc_peer_port_login,
1560 &class_device_attr_lpfc_restrict_login,
1561 &class_device_attr_lpfc_fcp_class,
1562 &class_device_attr_lpfc_use_adisc,
1563 &class_device_attr_lpfc_fdmi_on,
1564 &class_device_attr_lpfc_max_luns,
1565 &class_device_attr_nport_evt_cnt,
James Smart3de2a652007-08-02 11:09:59 -04001566 &class_device_attr_npiv_info,
1567 NULL,
1568};
1569
dea31012005-04-17 16:05:31 -05001570static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001571sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1572 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001573{
1574 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001575 struct class_device *cdev = container_of(kobj, struct class_device,
1576 kobj);
1577 struct Scsi_Host *shost = class_to_shost(cdev);
1578 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1579 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001580
1581 if ((off + count) > FF_REG_AREA_SIZE)
1582 return -ERANGE;
1583
1584 if (count == 0) return 0;
1585
1586 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1587 return -EINVAL;
1588
James Smart2e0fef82007-06-17 19:56:36 -05001589 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001590 return -EPERM;
1591 }
1592
James Smart2e0fef82007-06-17 19:56:36 -05001593 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001594 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1595 writel(*((uint32_t *)(buf + buf_off)),
1596 phba->ctrl_regs_memmap_p + off + buf_off);
1597
James Smart2e0fef82007-06-17 19:56:36 -05001598 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001599
1600 return count;
1601}
1602
1603static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001604sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1605 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001606{
1607 size_t buf_off;
1608 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001609 struct class_device *cdev = container_of(kobj, struct class_device,
1610 kobj);
1611 struct Scsi_Host *shost = class_to_shost(cdev);
1612 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1613 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001614
1615 if (off > FF_REG_AREA_SIZE)
1616 return -ERANGE;
1617
1618 if ((off + count) > FF_REG_AREA_SIZE)
1619 count = FF_REG_AREA_SIZE - off;
1620
1621 if (count == 0) return 0;
1622
1623 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1624 return -EINVAL;
1625
James Smart2e0fef82007-06-17 19:56:36 -05001626 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001627
1628 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1629 tmp_ptr = (uint32_t *)(buf + buf_off);
1630 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1631 }
1632
James Smart2e0fef82007-06-17 19:56:36 -05001633 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001634
1635 return count;
1636}
1637
1638static struct bin_attribute sysfs_ctlreg_attr = {
1639 .attr = {
1640 .name = "ctlreg",
1641 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001642 },
1643 .size = 256,
1644 .read = sysfs_ctlreg_read,
1645 .write = sysfs_ctlreg_write,
1646};
1647
1648
1649static void
James Smart2e0fef82007-06-17 19:56:36 -05001650sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001651{
1652 phba->sysfs_mbox.state = SMBOX_IDLE;
1653 phba->sysfs_mbox.offset = 0;
1654
1655 if (phba->sysfs_mbox.mbox) {
1656 mempool_free(phba->sysfs_mbox.mbox,
1657 phba->mbox_mem_pool);
1658 phba->sysfs_mbox.mbox = NULL;
1659 }
1660}
1661
1662static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001663sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1664 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001665{
James Smart2e0fef82007-06-17 19:56:36 -05001666 struct class_device *cdev = container_of(kobj, struct class_device,
1667 kobj);
1668 struct Scsi_Host *shost = class_to_shost(cdev);
1669 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1670 struct lpfc_hba *phba = vport->phba;
1671 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001672
1673 if ((count + off) > MAILBOX_CMD_SIZE)
1674 return -ERANGE;
1675
1676 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1677 return -EINVAL;
1678
1679 if (count == 0)
1680 return 0;
1681
1682 if (off == 0) {
1683 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1684 if (!mbox)
1685 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001686 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001687 }
1688
James Smart2e0fef82007-06-17 19:56:36 -05001689 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001690
1691 if (off == 0) {
1692 if (phba->sysfs_mbox.mbox)
1693 mempool_free(mbox, phba->mbox_mem_pool);
1694 else
1695 phba->sysfs_mbox.mbox = mbox;
1696 phba->sysfs_mbox.state = SMBOX_WRITING;
1697 } else {
1698 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1699 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001700 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001701 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001702 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001703 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001704 }
1705 }
1706
1707 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1708 buf, count);
1709
1710 phba->sysfs_mbox.offset = off + count;
1711
James Smart2e0fef82007-06-17 19:56:36 -05001712 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001713
1714 return count;
1715}
1716
1717static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001718sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1719 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001720{
James Smart2e0fef82007-06-17 19:56:36 -05001721 struct class_device *cdev = container_of(kobj, struct class_device,
1722 kobj);
1723 struct Scsi_Host *shost = class_to_shost(cdev);
1724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1725 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001726 int rc;
1727
James Smart1dcb58e2007-04-25 09:51:30 -04001728 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001729 return -ERANGE;
1730
James Smart1dcb58e2007-04-25 09:51:30 -04001731 if ((count + off) > MAILBOX_CMD_SIZE)
1732 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001733
1734 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1735 return -EINVAL;
1736
1737 if (off && count == 0)
1738 return 0;
1739
James Smart2e0fef82007-06-17 19:56:36 -05001740 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001741
1742 if (off == 0 &&
1743 phba->sysfs_mbox.state == SMBOX_WRITING &&
1744 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1745
1746 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1747 /* Offline only */
1748 case MBX_WRITE_NV:
1749 case MBX_INIT_LINK:
1750 case MBX_DOWN_LINK:
1751 case MBX_CONFIG_LINK:
1752 case MBX_CONFIG_RING:
1753 case MBX_RESET_RING:
1754 case MBX_UNREG_LOGIN:
1755 case MBX_CLEAR_LA:
1756 case MBX_DUMP_CONTEXT:
1757 case MBX_RUN_DIAGS:
1758 case MBX_RESTART:
1759 case MBX_FLASH_WR_ULA:
1760 case MBX_SET_MASK:
1761 case MBX_SET_SLIM:
1762 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001763 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001764 printk(KERN_WARNING "mbox_read:Command 0x%x "
1765 "is illegal in on-line state\n",
1766 phba->sysfs_mbox.mbox->mb.mbxCommand);
1767 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001768 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001769 return -EPERM;
1770 }
1771 case MBX_LOAD_SM:
1772 case MBX_READ_NV:
1773 case MBX_READ_CONFIG:
1774 case MBX_READ_RCONFIG:
1775 case MBX_READ_STATUS:
1776 case MBX_READ_XRI:
1777 case MBX_READ_REV:
1778 case MBX_READ_LNK_STAT:
1779 case MBX_DUMP_MEMORY:
1780 case MBX_DOWN_LOAD:
1781 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001782 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001783 case MBX_LOAD_AREA:
1784 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001785 case MBX_BEACON:
1786 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001787 break;
1788 case MBX_READ_SPARM64:
1789 case MBX_READ_LA:
1790 case MBX_READ_LA64:
1791 case MBX_REG_LOGIN:
1792 case MBX_REG_LOGIN64:
1793 case MBX_CONFIG_PORT:
1794 case MBX_RUN_BIU_DIAG:
1795 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1796 phba->sysfs_mbox.mbox->mb.mbxCommand);
1797 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001798 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001799 return -EPERM;
1800 default:
1801 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1802 phba->sysfs_mbox.mbox->mb.mbxCommand);
1803 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001804 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001805 return -EPERM;
1806 }
1807
James Smart92d7f7b2007-06-17 19:56:38 -05001808 phba->sysfs_mbox.mbox->vport = vport;
1809
James Smart2e0fef82007-06-17 19:56:36 -05001810 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001811 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001812 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001813 return -EAGAIN;
1814 }
1815
James Smart2e0fef82007-06-17 19:56:36 -05001816 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001817 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1818
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001820 rc = lpfc_sli_issue_mbox (phba,
1821 phba->sysfs_mbox.mbox,
1822 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001823 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001824
1825 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001826 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001827 rc = lpfc_sli_issue_mbox_wait (phba,
1828 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001829 lpfc_mbox_tmo_val(phba,
1830 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001831 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001832 }
1833
1834 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001835 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04001836 phba->sysfs_mbox.mbox = NULL;
1837 }
dea31012005-04-17 16:05:31 -05001838 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001839 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001840 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001841 }
1842 phba->sysfs_mbox.state = SMBOX_READING;
1843 }
1844 else if (phba->sysfs_mbox.offset != off ||
1845 phba->sysfs_mbox.state != SMBOX_READING) {
1846 printk(KERN_WARNING "mbox_read: Bad State\n");
1847 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001848 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001849 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001850 }
1851
1852 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1853
1854 phba->sysfs_mbox.offset = off + count;
1855
James Smart1dcb58e2007-04-25 09:51:30 -04001856 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001857 sysfs_mbox_idle(phba);
1858
James Smart2e0fef82007-06-17 19:56:36 -05001859 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001860
1861 return count;
1862}
1863
1864static struct bin_attribute sysfs_mbox_attr = {
1865 .attr = {
1866 .name = "mbox",
1867 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001868 },
James Smart1dcb58e2007-04-25 09:51:30 -04001869 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001870 .read = sysfs_mbox_read,
1871 .write = sysfs_mbox_write,
1872};
1873
1874int
James Smart2e0fef82007-06-17 19:56:36 -05001875lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001876{
James Smart2e0fef82007-06-17 19:56:36 -05001877 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001878 int error;
1879
James Smart2e0fef82007-06-17 19:56:36 -05001880 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001881 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001882 if (error)
1883 goto out;
1884
James Smart2e0fef82007-06-17 19:56:36 -05001885 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001886 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05001887 if (error)
1888 goto out_remove_ctlreg_attr;
1889
1890 return 0;
1891out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05001892 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001893out:
1894 return error;
1895}
1896
1897void
James Smart2e0fef82007-06-17 19:56:36 -05001898lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001899{
James Smart2e0fef82007-06-17 19:56:36 -05001900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001901
James Smart2e0fef82007-06-17 19:56:36 -05001902 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1903 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001904}
1905
1906
1907/*
1908 * Dynamic FC Host Attributes Support
1909 */
1910
1911static void
1912lpfc_get_host_port_id(struct Scsi_Host *shost)
1913{
James Smart2e0fef82007-06-17 19:56:36 -05001914 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1915
dea31012005-04-17 16:05:31 -05001916 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05001917 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001918}
1919
1920static void
1921lpfc_get_host_port_type(struct Scsi_Host *shost)
1922{
James Smart2e0fef82007-06-17 19:56:36 -05001923 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1924 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001925
1926 spin_lock_irq(shost->host_lock);
1927
James Smart92d7f7b2007-06-17 19:56:38 -05001928 if (vport->port_type == LPFC_NPIV_PORT) {
1929 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1930 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001931 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05001932 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05001933 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1934 else
1935 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1936 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001937 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05001938 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1939 else
1940 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1941 }
1942 } else
1943 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1944
1945 spin_unlock_irq(shost->host_lock);
1946}
1947
1948static void
1949lpfc_get_host_port_state(struct Scsi_Host *shost)
1950{
James Smart2e0fef82007-06-17 19:56:36 -05001951 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1952 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001953
1954 spin_lock_irq(shost->host_lock);
1955
James Smart2e0fef82007-06-17 19:56:36 -05001956 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05001957 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1958 else {
James Smart2e0fef82007-06-17 19:56:36 -05001959 switch (phba->link_state) {
1960 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05001961 case LPFC_LINK_DOWN:
1962 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1963 break;
1964 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05001965 case LPFC_CLEAR_LA:
1966 case LPFC_HBA_READY:
1967 /* Links up, beyond this port_type reports state */
1968 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1969 break;
1970 case LPFC_HBA_ERROR:
1971 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1972 break;
1973 default:
1974 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1975 break;
1976 }
1977 }
1978
1979 spin_unlock_irq(shost->host_lock);
1980}
1981
1982static void
1983lpfc_get_host_speed(struct Scsi_Host *shost)
1984{
James Smart2e0fef82007-06-17 19:56:36 -05001985 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1986 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001987
1988 spin_lock_irq(shost->host_lock);
1989
James Smart2e0fef82007-06-17 19:56:36 -05001990 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001991 switch(phba->fc_linkspeed) {
1992 case LA_1GHZ_LINK:
1993 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1994 break;
1995 case LA_2GHZ_LINK:
1996 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1997 break;
1998 case LA_4GHZ_LINK:
1999 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2000 break;
James Smartb87eab32007-04-25 09:53:28 -04002001 case LA_8GHZ_LINK:
2002 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2003 break;
dea31012005-04-17 16:05:31 -05002004 default:
2005 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2006 break;
2007 }
2008 }
2009
2010 spin_unlock_irq(shost->host_lock);
2011}
2012
2013static void
2014lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2015{
James Smart2e0fef82007-06-17 19:56:36 -05002016 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2017 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002018 u64 node_name;
dea31012005-04-17 16:05:31 -05002019
2020 spin_lock_irq(shost->host_lock);
2021
James Smart2e0fef82007-06-17 19:56:36 -05002022 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002023 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002024 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002025 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002026 else
2027 /* fabric is local port if there is no F/FL_Port */
James Smart2e0fef82007-06-17 19:56:36 -05002028 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05002029
2030 spin_unlock_irq(shost->host_lock);
2031
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002032 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002033}
2034
dea31012005-04-17 16:05:31 -05002035static struct fc_host_statistics *
2036lpfc_get_stats(struct Scsi_Host *shost)
2037{
James Smart2e0fef82007-06-17 19:56:36 -05002038 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2039 struct lpfc_hba *phba = vport->phba;
2040 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002041 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002042 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002043 LPFC_MBOXQ_t *pmboxq;
2044 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002045 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002046 int rc = 0;
dea31012005-04-17 16:05:31 -05002047
James Smart92d7f7b2007-06-17 19:56:38 -05002048 /*
2049 * prevent udev from issuing mailbox commands until the port is
2050 * configured.
2051 */
James Smart2e0fef82007-06-17 19:56:36 -05002052 if (phba->link_state < LPFC_LINK_DOWN ||
2053 !phba->mbox_mem_pool ||
2054 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002055 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002056
2057 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002058 return NULL;
2059
dea31012005-04-17 16:05:31 -05002060 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2061 if (!pmboxq)
2062 return NULL;
2063 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2064
2065 pmb = &pmboxq->mb;
2066 pmb->mbxCommand = MBX_READ_STATUS;
2067 pmb->mbxOwner = OWN_HOST;
2068 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002069 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002070
James Smart2e0fef82007-06-17 19:56:36 -05002071 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002072 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002073 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002074 else
dea31012005-04-17 16:05:31 -05002075 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2076
2077 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002078 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002079 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002080 return NULL;
2081 }
2082
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002083 memset(hs, 0, sizeof (struct fc_host_statistics));
2084
dea31012005-04-17 16:05:31 -05002085 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2086 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2087 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2088 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2089
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002090 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002091 pmb->mbxCommand = MBX_READ_LNK_STAT;
2092 pmb->mbxOwner = OWN_HOST;
2093 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002094 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002095
James Smart2e0fef82007-06-17 19:56:36 -05002096 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002097 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002098 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002099 else
dea31012005-04-17 16:05:31 -05002100 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2101
2102 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002103 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002104 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002105 return NULL;
2106 }
2107
2108 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2109 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2110 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2111 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2112 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2113 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2114 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2115
James Smart64ba8812006-08-02 15:24:34 -04002116 hs->link_failure_count -= lso->link_failure_count;
2117 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2118 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2119 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2120 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2121 hs->invalid_crc_count -= lso->invalid_crc_count;
2122 hs->error_frames -= lso->error_frames;
2123
dea31012005-04-17 16:05:31 -05002124 if (phba->fc_topology == TOPOLOGY_LOOP) {
2125 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002126 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002127 hs->nos_count = -1;
2128 } else {
2129 hs->lip_count = -1;
2130 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002131 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002132 }
2133
2134 hs->dumped_frames = -1;
2135
James Smart64ba8812006-08-02 15:24:34 -04002136 seconds = get_seconds();
2137 if (seconds < psli->stats_start)
2138 hs->seconds_since_last_reset = seconds +
2139 ((unsigned long)-1 - psli->stats_start);
2140 else
2141 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002142
James Smart1dcb58e2007-04-25 09:51:30 -04002143 mempool_free(pmboxq, phba->mbox_mem_pool);
2144
dea31012005-04-17 16:05:31 -05002145 return hs;
2146}
2147
James Smart64ba8812006-08-02 15:24:34 -04002148static void
2149lpfc_reset_stats(struct Scsi_Host *shost)
2150{
James Smart2e0fef82007-06-17 19:56:36 -05002151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2152 struct lpfc_hba *phba = vport->phba;
2153 struct lpfc_sli *psli = &phba->sli;
2154 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002155 LPFC_MBOXQ_t *pmboxq;
2156 MAILBOX_t *pmb;
2157 int rc = 0;
2158
James Smart2e0fef82007-06-17 19:56:36 -05002159 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002160 return;
2161
James Smart64ba8812006-08-02 15:24:34 -04002162 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2163 if (!pmboxq)
2164 return;
2165 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2166
2167 pmb = &pmboxq->mb;
2168 pmb->mbxCommand = MBX_READ_STATUS;
2169 pmb->mbxOwner = OWN_HOST;
2170 pmb->un.varWords[0] = 0x1; /* reset request */
2171 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002172 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002173
James Smart2e0fef82007-06-17 19:56:36 -05002174 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002175 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2176 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2177 else
2178 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2179
2180 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002181 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002182 mempool_free(pmboxq, phba->mbox_mem_pool);
2183 return;
2184 }
2185
2186 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2187 pmb->mbxCommand = MBX_READ_LNK_STAT;
2188 pmb->mbxOwner = OWN_HOST;
2189 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002190 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002191
James Smart2e0fef82007-06-17 19:56:36 -05002192 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002193 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2194 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2195 else
2196 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2197
2198 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002199 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002200 mempool_free( pmboxq, phba->mbox_mem_pool);
2201 return;
2202 }
2203
2204 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2205 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2206 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2207 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2208 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2209 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2210 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2211 lso->link_events = (phba->fc_eventTag >> 1);
2212
2213 psli->stats_start = get_seconds();
2214
James Smart1dcb58e2007-04-25 09:51:30 -04002215 mempool_free(pmboxq, phba->mbox_mem_pool);
2216
James Smart64ba8812006-08-02 15:24:34 -04002217 return;
2218}
dea31012005-04-17 16:05:31 -05002219
2220/*
2221 * The LPFC driver treats linkdown handling as target loss events so there
2222 * are no sysfs handlers for link_down_tmo.
2223 */
James Smart685f0bf2007-04-25 09:53:08 -04002224
2225static struct lpfc_nodelist *
2226lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002227{
James Smart2e0fef82007-06-17 19:56:36 -05002228 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2229 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002230 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002231
2232 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002233 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002234 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002235 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2236 starget->id == ndlp->nlp_sid) {
2237 spin_unlock_irq(shost->host_lock);
2238 return ndlp;
dea31012005-04-17 16:05:31 -05002239 }
2240 }
2241 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002242 return NULL;
2243}
dea31012005-04-17 16:05:31 -05002244
James Smart685f0bf2007-04-25 09:53:08 -04002245static void
2246lpfc_get_starget_port_id(struct scsi_target *starget)
2247{
2248 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2249
2250 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002251}
2252
2253static void
2254lpfc_get_starget_node_name(struct scsi_target *starget)
2255{
James Smart685f0bf2007-04-25 09:53:08 -04002256 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002257
James Smart685f0bf2007-04-25 09:53:08 -04002258 fc_starget_node_name(starget) =
2259 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002260}
2261
2262static void
2263lpfc_get_starget_port_name(struct scsi_target *starget)
2264{
James Smart685f0bf2007-04-25 09:53:08 -04002265 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002266
James Smart685f0bf2007-04-25 09:53:08 -04002267 fc_starget_port_name(starget) =
2268 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002269}
2270
2271static void
dea31012005-04-17 16:05:31 -05002272lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2273{
dea31012005-04-17 16:05:31 -05002274 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002275 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002276 else
James Smartc01f3202006-08-18 17:47:08 -04002277 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002278}
2279
2280
2281#define lpfc_rport_show_function(field, format_string, sz, cast) \
2282static ssize_t \
2283lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2284{ \
2285 struct fc_rport *rport = transport_class_to_rport(cdev); \
2286 struct lpfc_rport_data *rdata = rport->hostdata; \
2287 return snprintf(buf, sz, format_string, \
2288 (rdata->target) ? cast rdata->target->field : 0); \
2289}
2290
2291#define lpfc_rport_rd_attr(field, format_string, sz) \
2292 lpfc_rport_show_function(field, format_string, sz, ) \
2293static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2294
2295
2296struct fc_function_template lpfc_transport_functions = {
2297 /* fixed attributes the driver supports */
2298 .show_host_node_name = 1,
2299 .show_host_port_name = 1,
2300 .show_host_supported_classes = 1,
2301 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002302 .show_host_supported_speeds = 1,
2303 .show_host_maxframe_size = 1,
2304
2305 /* dynamic attributes the driver supports */
2306 .get_host_port_id = lpfc_get_host_port_id,
2307 .show_host_port_id = 1,
2308
2309 .get_host_port_type = lpfc_get_host_port_type,
2310 .show_host_port_type = 1,
2311
2312 .get_host_port_state = lpfc_get_host_port_state,
2313 .show_host_port_state = 1,
2314
2315 /* active_fc4s is shown but doesn't change (thus no get function) */
2316 .show_host_active_fc4s = 1,
2317
2318 .get_host_speed = lpfc_get_host_speed,
2319 .show_host_speed = 1,
2320
2321 .get_host_fabric_name = lpfc_get_host_fabric_name,
2322 .show_host_fabric_name = 1,
2323
2324 /*
2325 * The LPFC driver treats linkdown handling as target loss events
2326 * so there are no sysfs handlers for link_down_tmo.
2327 */
2328
2329 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002330 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002331
2332 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2333 .show_rport_maxframe_size = 1,
2334 .show_rport_supported_classes = 1,
2335
dea31012005-04-17 16:05:31 -05002336 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2337 .show_rport_dev_loss_tmo = 1,
2338
2339 .get_starget_port_id = lpfc_get_starget_port_id,
2340 .show_starget_port_id = 1,
2341
2342 .get_starget_node_name = lpfc_get_starget_node_name,
2343 .show_starget_node_name = 1,
2344
2345 .get_starget_port_name = lpfc_get_starget_port_name,
2346 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002347
2348 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002349 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2350 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002351
2352 .vport_create = lpfc_vport_create,
2353 .vport_delete = lpfc_vport_delete,
2354 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2355};
2356
2357struct fc_function_template lpfc_vport_transport_functions = {
2358 /* fixed attributes the driver supports */
2359 .show_host_node_name = 1,
2360 .show_host_port_name = 1,
2361 .show_host_supported_classes = 1,
2362 .show_host_supported_fc4s = 1,
2363 .show_host_supported_speeds = 1,
2364 .show_host_maxframe_size = 1,
2365
2366 /* dynamic attributes the driver supports */
2367 .get_host_port_id = lpfc_get_host_port_id,
2368 .show_host_port_id = 1,
2369
2370 .get_host_port_type = lpfc_get_host_port_type,
2371 .show_host_port_type = 1,
2372
2373 .get_host_port_state = lpfc_get_host_port_state,
2374 .show_host_port_state = 1,
2375
2376 /* active_fc4s is shown but doesn't change (thus no get function) */
2377 .show_host_active_fc4s = 1,
2378
2379 .get_host_speed = lpfc_get_host_speed,
2380 .show_host_speed = 1,
2381
2382 .get_host_fabric_name = lpfc_get_host_fabric_name,
2383 .show_host_fabric_name = 1,
dea31012005-04-17 16:05:31 -05002384
2385 /*
2386 * The LPFC driver treats linkdown handling as target loss events
2387 * so there are no sysfs handlers for link_down_tmo.
2388 */
2389
2390 .get_fc_host_stats = lpfc_get_stats,
2391 .reset_fc_host_stats = lpfc_reset_stats,
2392
2393 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2394 .show_rport_maxframe_size = 1,
2395 .show_rport_supported_classes = 1,
2396
2397 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2398 .show_rport_dev_loss_tmo = 1,
2399
2400 .get_starget_port_id = lpfc_get_starget_port_id,
2401 .show_starget_port_id = 1,
2402
2403 .get_starget_node_name = lpfc_get_starget_node_name,
2404 .show_starget_node_name = 1,
2405
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002406 .get_starget_port_name = lpfc_get_starget_port_name,
2407 .show_starget_port_name = 1,
2408
dea31012005-04-17 16:05:31 -05002409 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2410 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002411
2412 .vport_disable = lpfc_vport_disable,
dea31012005-04-17 16:05:31 -05002413};
2414
2415void
2416lpfc_get_cfgparam(struct lpfc_hba *phba)
2417{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002418 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2419 lpfc_cr_count_init(phba, lpfc_cr_count);
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002420 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002421 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2422 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002423 lpfc_ack0_init(phba, lpfc_ack0);
2424 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002425 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002426 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart78b2d852007-08-02 11:10:21 -04002427 lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
James Smart4ff43242006-12-02 13:34:56 -05002428 lpfc_use_msi_init(phba, lpfc_use_msi);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002429 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002430 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002431 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05002432 /*
2433 * The total number of segments is the configuration value plus 2
2434 * since the IOCB need a command and response bde.
2435 */
2436 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
dea31012005-04-17 16:05:31 -05002437 /*
2438 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2439 * used to create the sg_dma_buf_pool must be dynamically calculated
2440 */
2441 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2442 sizeof(struct fcp_rsp) +
2443 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002444 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002445 return;
2446}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002447
James Smart3de2a652007-08-02 11:09:59 -04002448void
2449lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2450{
James Smarte8b62012007-08-02 11:10:09 -04002451 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002452 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2453 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2454 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2455 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2456 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2457 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2458 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2459 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2460 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2461 lpfc_max_luns_init(vport, lpfc_max_luns);
2462 lpfc_scan_down_init(vport, lpfc_scan_down);
dea31012005-04-17 16:05:31 -05002463 return;
2464}