blob: c1cedc3d1b70d28060842b223fc0246ed3d30bea [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
71management_version_show(struct class_device *cdev, char *buf)
72{
73 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
74}
75
76static ssize_t
77lpfc_info_show(struct class_device *cdev, char *buf)
78{
79 struct Scsi_Host *host = class_to_shost(cdev);
James Smart2e0fef82007-06-17 19:56:36 -050080
dea31012005-04-17 16:05:31 -050081 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
82}
83
84static ssize_t
85lpfc_serialnum_show(struct class_device *cdev, char *buf)
86{
James Smart2e0fef82007-06-17 19:56:36 -050087 struct Scsi_Host *shost = class_to_shost(cdev);
88 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
89 struct lpfc_hba *phba = vport->phba;
90
dea31012005-04-17 16:05:31 -050091 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
92}
93
94static ssize_t
95lpfc_modeldesc_show(struct class_device *cdev, char *buf)
96{
James Smart2e0fef82007-06-17 19:56:36 -050097 struct Scsi_Host *shost = class_to_shost(cdev);
98 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
99 struct lpfc_hba *phba = vport->phba;
100
dea31012005-04-17 16:05:31 -0500101 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
102}
103
104static ssize_t
105lpfc_modelname_show(struct class_device *cdev, char *buf)
106{
James Smart2e0fef82007-06-17 19:56:36 -0500107 struct Scsi_Host *shost = class_to_shost(cdev);
108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
109 struct lpfc_hba *phba = vport->phba;
110
dea31012005-04-17 16:05:31 -0500111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
112}
113
114static ssize_t
115lpfc_programtype_show(struct class_device *cdev, char *buf)
116{
James Smart2e0fef82007-06-17 19:56:36 -0500117 struct Scsi_Host *shost = class_to_shost(cdev);
118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
119 struct lpfc_hba *phba = vport->phba;
120
dea31012005-04-17 16:05:31 -0500121 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
122}
123
124static ssize_t
James Smart2e0fef82007-06-17 19:56:36 -0500125lpfc_vportnum_show(struct class_device *cdev, char *buf)
dea31012005-04-17 16:05:31 -0500126{
James Smart2e0fef82007-06-17 19:56:36 -0500127 struct Scsi_Host *shost = class_to_shost(cdev);
128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
dea31012005-04-17 16:05:31 -0500131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
132}
133
134static ssize_t
135lpfc_fwrev_show(struct class_device *cdev, char *buf)
136{
James Smart2e0fef82007-06-17 19:56:36 -0500137 struct Scsi_Host *shost = class_to_shost(cdev);
138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
139 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500140 char fwrev[32];
James Smart2e0fef82007-06-17 19:56:36 -0500141
dea31012005-04-17 16:05:31 -0500142 lpfc_decode_firmware_rev(phba, fwrev, 1);
James Smart92d7f7b2007-06-17 19:56:38 -0500143 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
dea31012005-04-17 16:05:31 -0500144}
145
146static ssize_t
147lpfc_hdw_show(struct class_device *cdev, char *buf)
148{
149 char hdw[9];
James Smart2e0fef82007-06-17 19:56:36 -0500150 struct Scsi_Host *shost = class_to_shost(cdev);
151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500153 lpfc_vpd_t *vp = &phba->vpd;
James Smart2e0fef82007-06-17 19:56:36 -0500154
dea31012005-04-17 16:05:31 -0500155 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
156 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
157}
158static ssize_t
159lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
160{
James Smart2e0fef82007-06-17 19:56:36 -0500161 struct Scsi_Host *shost = class_to_shost(cdev);
162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
164
dea31012005-04-17 16:05:31 -0500165 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
166}
167static ssize_t
168lpfc_state_show(struct class_device *cdev, char *buf)
169{
James Smart2e0fef82007-06-17 19:56:36 -0500170 struct Scsi_Host *shost = class_to_shost(cdev);
171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
172 struct lpfc_hba *phba = vport->phba;
173 int len = 0;
174
175 switch (phba->link_state) {
176 case LPFC_LINK_UNKNOWN:
Jamie Wellnitz41415862006-02-28 19:25:27 -0500177 case LPFC_WARM_START:
dea31012005-04-17 16:05:31 -0500178 case LPFC_INIT_START:
179 case LPFC_INIT_MBX_CMDS:
180 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500181 case LPFC_HBA_ERROR:
dea31012005-04-17 16:05:31 -0500182 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
183 break;
184 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -0500185 case LPFC_CLEAR_LA:
dea31012005-04-17 16:05:31 -0500186 case LPFC_HBA_READY:
James Smart2e0fef82007-06-17 19:56:36 -0500187 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
188
189 switch (vport->port_state) {
190 len += snprintf(buf + len, PAGE_SIZE-len,
191 "initializing\n");
192 break;
193 case LPFC_LOCAL_CFG_LINK:
194 len += snprintf(buf + len, PAGE_SIZE-len,
James Smart92d7f7b2007-06-17 19:56:38 -0500195 "Configuring Link\n");
James Smart2e0fef82007-06-17 19:56:36 -0500196 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500197 case LPFC_FDISC:
James Smart2e0fef82007-06-17 19:56:36 -0500198 case LPFC_FLOGI:
199 case LPFC_FABRIC_CFG_LINK:
200 case LPFC_NS_REG:
201 case LPFC_NS_QRY:
202 case LPFC_BUILD_DISC_LIST:
203 case LPFC_DISC_AUTH:
204 len += snprintf(buf + len, PAGE_SIZE - len,
205 "Discovery\n");
206 break;
207 case LPFC_VPORT_READY:
208 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
209 break;
210
James Smart92d7f7b2007-06-17 19:56:38 -0500211 case LPFC_VPORT_FAILED:
212 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
213 break;
214
215 case LPFC_VPORT_UNKNOWN:
James Smart2e0fef82007-06-17 19:56:36 -0500216 len += snprintf(buf + len, PAGE_SIZE - len,
217 "Unknown\n");
218 break;
219 }
220
dea31012005-04-17 16:05:31 -0500221 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500222 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -0500223 len += snprintf(buf + len, PAGE_SIZE-len,
224 " Public Loop\n");
225 else
226 len += snprintf(buf + len, PAGE_SIZE-len,
227 " Private Loop\n");
228 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500229 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -0500230 len += snprintf(buf + len, PAGE_SIZE-len,
231 " Fabric\n");
232 else
233 len += snprintf(buf + len, PAGE_SIZE-len,
234 " Point-2-Point\n");
235 }
236 }
James Smart2e0fef82007-06-17 19:56:36 -0500237
dea31012005-04-17 16:05:31 -0500238 return len;
239}
240
241static ssize_t
242lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
243{
James Smart2e0fef82007-06-17 19:56:36 -0500244 struct Scsi_Host *shost = class_to_shost(cdev);
245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
246
247 return snprintf(buf, PAGE_SIZE, "%d\n",
248 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea31012005-04-17 16:05:31 -0500249}
250
251
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700252static int
James Smart2e0fef82007-06-17 19:56:36 -0500253lpfc_issue_lip(struct Scsi_Host *shost)
dea31012005-04-17 16:05:31 -0500254{
James Smart2e0fef82007-06-17 19:56:36 -0500255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
256 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500257 LPFC_MBOXQ_t *pmboxq;
258 int mbxstatus = MBXERR_ERROR;
259
James Smart2e0fef82007-06-17 19:56:36 -0500260 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
261 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
262 (vport->port_state != LPFC_VPORT_READY))
dea31012005-04-17 16:05:31 -0500263 return -EPERM;
264
265 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
266
267 if (!pmboxq)
268 return -ENOMEM;
269
270 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
James Smart4db621e2006-07-06 15:49:49 -0400271 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
272 pmboxq->mb.mbxOwner = OWN_HOST;
273
James Smart33ccf8d2006-08-17 11:57:58 -0400274 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea31012005-04-17 16:05:31 -0500275
James Smart4db621e2006-07-06 15:49:49 -0400276 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
277 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
278 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
279 phba->cfg_link_speed);
280 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
281 phba->fc_ratov * 2);
282 }
283
James Smart5b8bd0c2007-04-25 09:52:49 -0400284 lpfc_set_loopback_flag(phba);
James Smart858c9f62007-06-17 19:56:39 -0500285 if (mbxstatus != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -0400286 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500287
288 if (mbxstatus == MBXERR_ERROR)
289 return -EIO;
290
Andrew Vasquez91ca7b02005-10-27 16:03:37 -0700291 return 0;
dea31012005-04-17 16:05:31 -0500292}
293
James Smart40496f02006-07-06 15:50:22 -0400294static int
James Smart46fa3112007-04-25 09:51:45 -0400295lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
296{
297 struct completion online_compl;
298 struct lpfc_sli_ring *pring;
299 struct lpfc_sli *psli;
300 int status = 0;
301 int cnt = 0;
302 int i;
303
304 init_completion(&online_compl);
305 lpfc_workq_post_event(phba, &status, &online_compl,
306 LPFC_EVT_OFFLINE_PREP);
307 wait_for_completion(&online_compl);
308
309 if (status != 0)
310 return -EIO;
311
312 psli = &phba->sli;
313
314 for (i = 0; i < psli->num_rings; i++) {
315 pring = &psli->ring[i];
316 /* The linkdown event takes 30 seconds to timeout. */
317 while (pring->txcmplq_cnt) {
318 msleep(10);
319 if (cnt++ > 3000) {
320 lpfc_printf_log(phba,
321 KERN_WARNING, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -0400322 "0466 Outstanding IO when "
323 "bringing Adapter offline\n");
James Smart46fa3112007-04-25 09:51:45 -0400324 break;
325 }
326 }
327 }
328
329 init_completion(&online_compl);
330 lpfc_workq_post_event(phba, &status, &online_compl, type);
331 wait_for_completion(&online_compl);
332
333 if (status != 0)
334 return -EIO;
335
336 return 0;
337}
338
339static int
James Smart40496f02006-07-06 15:50:22 -0400340lpfc_selective_reset(struct lpfc_hba *phba)
341{
342 struct completion online_compl;
343 int status = 0;
344
James Smart46fa3112007-04-25 09:51:45 -0400345 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smart40496f02006-07-06 15:50:22 -0400346
347 if (status != 0)
James Smart46fa3112007-04-25 09:51:45 -0400348 return status;
James Smart40496f02006-07-06 15:50:22 -0400349
350 init_completion(&online_compl);
351 lpfc_workq_post_event(phba, &status, &online_compl,
352 LPFC_EVT_ONLINE);
353 wait_for_completion(&online_compl);
354
355 if (status != 0)
356 return -EIO;
357
358 return 0;
359}
360
361static ssize_t
362lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
363{
James Smart2e0fef82007-06-17 19:56:36 -0500364 struct Scsi_Host *shost = class_to_shost(cdev);
365 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
366 struct lpfc_hba *phba = vport->phba;
367
James Smart40496f02006-07-06 15:50:22 -0400368 int status = -EINVAL;
369
370 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
371 status = lpfc_selective_reset(phba);
372
373 if (status == 0)
374 return strlen(buf);
375 else
376 return status;
377}
378
dea31012005-04-17 16:05:31 -0500379static ssize_t
380lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
381{
James Smart2e0fef82007-06-17 19:56:36 -0500382 struct Scsi_Host *shost = class_to_shost(cdev);
383 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
384 struct lpfc_hba *phba = vport->phba;
385
dea31012005-04-17 16:05:31 -0500386 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
387}
388
389static ssize_t
Jamie Wellnitz41415862006-02-28 19:25:27 -0500390lpfc_board_mode_show(struct class_device *cdev, char *buf)
391{
James Smart2e0fef82007-06-17 19:56:36 -0500392 struct Scsi_Host *shost = class_to_shost(cdev);
393 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
394 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500395 char * state;
396
James Smart2e0fef82007-06-17 19:56:36 -0500397 if (phba->link_state == LPFC_HBA_ERROR)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500398 state = "error";
James Smart2e0fef82007-06-17 19:56:36 -0500399 else if (phba->link_state == LPFC_WARM_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500400 state = "warm start";
James Smart2e0fef82007-06-17 19:56:36 -0500401 else if (phba->link_state == LPFC_INIT_START)
Jamie Wellnitz41415862006-02-28 19:25:27 -0500402 state = "offline";
403 else
404 state = "online";
405
406 return snprintf(buf, PAGE_SIZE, "%s\n", state);
407}
408
409static ssize_t
410lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
411{
James Smart2e0fef82007-06-17 19:56:36 -0500412 struct Scsi_Host *shost = class_to_shost(cdev);
413 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
414 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz41415862006-02-28 19:25:27 -0500415 struct completion online_compl;
416 int status=0;
417
418 init_completion(&online_compl);
419
James Smart46fa3112007-04-25 09:51:45 -0400420 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
Jamie Wellnitz41415862006-02-28 19:25:27 -0500421 lpfc_workq_post_event(phba, &status, &online_compl,
422 LPFC_EVT_ONLINE);
James Smart46fa3112007-04-25 09:51:45 -0400423 wait_for_completion(&online_compl);
424 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
425 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500426 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
James Smart46fa3112007-04-25 09:51:45 -0400427 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
428 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
429 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500430 else
431 return -EINVAL;
432
Jamie Wellnitz41415862006-02-28 19:25:27 -0500433 if (!status)
434 return strlen(buf);
435 else
436 return -EIO;
437}
438
James Smart92d7f7b2007-06-17 19:56:38 -0500439int
James Smart858c9f62007-06-17 19:56:39 -0500440lpfc_get_hba_info(struct lpfc_hba *phba,
441 uint32_t *mxri, uint32_t *axri,
442 uint32_t *mrpi, uint32_t *arpi,
443 uint32_t *mvpi, uint32_t *avpi)
James Smart92d7f7b2007-06-17 19:56:38 -0500444{
445 struct lpfc_sli *psli = &phba->sli;
446 LPFC_MBOXQ_t *pmboxq;
447 MAILBOX_t *pmb;
448 int rc = 0;
449
450 /*
451 * prevent udev from issuing mailbox commands until the port is
452 * configured.
453 */
454 if (phba->link_state < LPFC_LINK_DOWN ||
455 !phba->mbox_mem_pool ||
456 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
457 return 0;
458
459 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
460 return 0;
461
462 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
463 if (!pmboxq)
464 return 0;
465 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
466
467 pmb = &pmboxq->mb;
468 pmb->mbxCommand = MBX_READ_CONFIG;
469 pmb->mbxOwner = OWN_HOST;
470 pmboxq->context1 = NULL;
471
472 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
473 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
474 rc = MBX_NOT_FINISHED;
475 else
476 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
477
478 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -0500479 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -0500480 mempool_free(pmboxq, phba->mbox_mem_pool);
481 return 0;
482 }
483
484 if (mrpi)
485 *mrpi = pmb->un.varRdConfig.max_rpi;
486 if (arpi)
487 *arpi = pmb->un.varRdConfig.avail_rpi;
488 if (mxri)
489 *mxri = pmb->un.varRdConfig.max_xri;
490 if (axri)
491 *axri = pmb->un.varRdConfig.avail_xri;
James Smart858c9f62007-06-17 19:56:39 -0500492 if (mvpi)
493 *mvpi = pmb->un.varRdConfig.max_vpi;
494 if (avpi)
495 *avpi = pmb->un.varRdConfig.avail_vpi;
James Smart92d7f7b2007-06-17 19:56:38 -0500496
497 mempool_free(pmboxq, phba->mbox_mem_pool);
498 return 1;
499}
500
501static ssize_t
502lpfc_max_rpi_show(struct class_device *cdev, char *buf)
503{
504 struct Scsi_Host *shost = class_to_shost(cdev);
505 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
506 struct lpfc_hba *phba = vport->phba;
507 uint32_t cnt;
508
James Smart858c9f62007-06-17 19:56:39 -0500509 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500510 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
511 return snprintf(buf, PAGE_SIZE, "Unknown\n");
512}
513
514static ssize_t
515lpfc_used_rpi_show(struct class_device *cdev, char *buf)
516{
517 struct Scsi_Host *shost = class_to_shost(cdev);
518 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
519 struct lpfc_hba *phba = vport->phba;
520 uint32_t cnt, acnt;
521
James Smart858c9f62007-06-17 19:56:39 -0500522 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500523 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
524 return snprintf(buf, PAGE_SIZE, "Unknown\n");
525}
526
527static ssize_t
528lpfc_max_xri_show(struct class_device *cdev, char *buf)
529{
530 struct Scsi_Host *shost = class_to_shost(cdev);
531 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
532 struct lpfc_hba *phba = vport->phba;
533 uint32_t cnt;
534
James Smart858c9f62007-06-17 19:56:39 -0500535 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
James Smart92d7f7b2007-06-17 19:56:38 -0500536 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
537 return snprintf(buf, PAGE_SIZE, "Unknown\n");
538}
539
540static ssize_t
541lpfc_used_xri_show(struct class_device *cdev, char *buf)
542{
543 struct Scsi_Host *shost = class_to_shost(cdev);
544 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
545 struct lpfc_hba *phba = vport->phba;
546 uint32_t cnt, acnt;
547
James Smart858c9f62007-06-17 19:56:39 -0500548 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
549 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
550 return snprintf(buf, PAGE_SIZE, "Unknown\n");
551}
552
553static ssize_t
554lpfc_max_vpi_show(struct class_device *cdev, char *buf)
555{
556 struct Scsi_Host *shost = class_to_shost(cdev);
557 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
558 struct lpfc_hba *phba = vport->phba;
559 uint32_t cnt;
560
561 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
562 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
563 return snprintf(buf, PAGE_SIZE, "Unknown\n");
564}
565
566static ssize_t
567lpfc_used_vpi_show(struct class_device *cdev, char *buf)
568{
569 struct Scsi_Host *shost = class_to_shost(cdev);
570 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
571 struct lpfc_hba *phba = vport->phba;
572 uint32_t cnt, acnt;
573
574 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
James Smart92d7f7b2007-06-17 19:56:38 -0500575 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
576 return snprintf(buf, PAGE_SIZE, "Unknown\n");
577}
578
579static ssize_t
580lpfc_npiv_info_show(struct class_device *cdev, char *buf)
581{
582 struct Scsi_Host *shost = class_to_shost(cdev);
583 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
584 struct lpfc_hba *phba = vport->phba;
585
586 if (!(phba->max_vpi))
587 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
588 if (vport->port_type == LPFC_PHYSICAL_PORT)
589 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
590 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
591}
592
Jamie Wellnitz41415862006-02-28 19:25:27 -0500593static ssize_t
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500594lpfc_poll_show(struct class_device *cdev, char *buf)
595{
James Smart2e0fef82007-06-17 19:56:36 -0500596 struct Scsi_Host *shost = class_to_shost(cdev);
597 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
598 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500599
600 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
601}
602
603static ssize_t
604lpfc_poll_store(struct class_device *cdev, const char *buf,
605 size_t count)
606{
James Smart2e0fef82007-06-17 19:56:36 -0500607 struct Scsi_Host *shost = class_to_shost(cdev);
608 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
609 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500610 uint32_t creg_val;
611 uint32_t old_val;
612 int val=0;
613
614 if (!isdigit(buf[0]))
615 return -EINVAL;
616
617 if (sscanf(buf, "%i", &val) != 1)
618 return -EINVAL;
619
620 if ((val & 0x3) != val)
621 return -EINVAL;
622
James Smart2e0fef82007-06-17 19:56:36 -0500623 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500624
625 old_val = phba->cfg_poll;
626
627 if (val & ENABLE_FCP_RING_POLLING) {
628 if ((val & DISABLE_FCP_RING_INT) &&
629 !(old_val & DISABLE_FCP_RING_INT)) {
630 creg_val = readl(phba->HCregaddr);
631 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
632 writel(creg_val, phba->HCregaddr);
633 readl(phba->HCregaddr); /* flush */
634
635 lpfc_poll_start_timer(phba);
636 }
637 } else if (val != 0x0) {
James Smart2e0fef82007-06-17 19:56:36 -0500638 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500639 return -EINVAL;
640 }
641
642 if (!(val & DISABLE_FCP_RING_INT) &&
643 (old_val & DISABLE_FCP_RING_INT))
644 {
James Smart2e0fef82007-06-17 19:56:36 -0500645 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500646 del_timer(&phba->fcp_poll_timer);
James Smart2e0fef82007-06-17 19:56:36 -0500647 spin_lock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500648 creg_val = readl(phba->HCregaddr);
649 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
650 writel(creg_val, phba->HCregaddr);
651 readl(phba->HCregaddr); /* flush */
652 }
653
654 phba->cfg_poll = val;
655
James Smart2e0fef82007-06-17 19:56:36 -0500656 spin_unlock_irq(&phba->hbalock);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -0500657
658 return strlen(buf);
659}
dea31012005-04-17 16:05:31 -0500660
661#define lpfc_param_show(attr) \
662static ssize_t \
663lpfc_##attr##_show(struct class_device *cdev, char *buf) \
664{ \
James Smart2e0fef82007-06-17 19:56:36 -0500665 struct Scsi_Host *shost = class_to_shost(cdev);\
666 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
667 struct lpfc_hba *phba = vport->phba;\
dea31012005-04-17 16:05:31 -0500668 int val = 0;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400669 val = phba->cfg_##attr;\
670 return snprintf(buf, PAGE_SIZE, "%d\n",\
671 phba->cfg_##attr);\
dea31012005-04-17 16:05:31 -0500672}
673
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400674#define lpfc_param_hex_show(attr) \
675static ssize_t \
676lpfc_##attr##_show(struct class_device *cdev, char *buf) \
677{ \
James Smart2e0fef82007-06-17 19:56:36 -0500678 struct Scsi_Host *shost = class_to_shost(cdev);\
679 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
680 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400681 int val = 0;\
682 val = phba->cfg_##attr;\
683 return snprintf(buf, PAGE_SIZE, "%#x\n",\
684 phba->cfg_##attr);\
685}
686
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400687#define lpfc_param_init(attr, default, minval, maxval) \
688static int \
689lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
690{ \
691 if (val >= minval && val <= maxval) {\
692 phba->cfg_##attr = val;\
693 return 0;\
694 }\
695 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400696 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
697 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400698 phba->cfg_##attr = default;\
699 return -EINVAL;\
700}
701
702#define lpfc_param_set(attr, default, minval, maxval) \
703static int \
704lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
705{ \
706 if (val >= minval && val <= maxval) {\
707 phba->cfg_##attr = val;\
708 return 0;\
709 }\
710 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
James Smarte8b62012007-08-02 11:10:09 -0400711 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
712 "allowed range is ["#minval", "#maxval"]\n", val); \
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400713 return -EINVAL;\
714}
715
716#define lpfc_param_store(attr) \
dea31012005-04-17 16:05:31 -0500717static ssize_t \
718lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
719{ \
James Smart2e0fef82007-06-17 19:56:36 -0500720 struct Scsi_Host *shost = class_to_shost(cdev);\
721 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
722 struct lpfc_hba *phba = vport->phba;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400723 int val=0;\
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400724 if (!isdigit(buf[0]))\
725 return -EINVAL;\
726 if (sscanf(buf, "%i", &val) != 1)\
727 return -EINVAL;\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400728 if (lpfc_##attr##_set(phba, val) == 0) \
James.Smart@Emulex.Com755c0d02005-10-28 20:29:06 -0400729 return strlen(buf);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400730 else \
731 return -EINVAL;\
dea31012005-04-17 16:05:31 -0500732}
733
James Smart3de2a652007-08-02 11:09:59 -0400734#define lpfc_vport_param_show(attr) \
735static ssize_t \
736lpfc_##attr##_show(struct class_device *cdev, char *buf) \
737{ \
738 struct Scsi_Host *shost = class_to_shost(cdev);\
739 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
740 int val = 0;\
741 val = vport->cfg_##attr;\
742 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
743}
744
745#define lpfc_vport_param_hex_show(attr) \
746static ssize_t \
747lpfc_##attr##_show(struct class_device *cdev, char *buf) \
748{ \
749 struct Scsi_Host *shost = class_to_shost(cdev);\
750 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
751 int val = 0;\
752 val = vport->cfg_##attr;\
753 return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
754}
755
756#define lpfc_vport_param_init(attr, default, minval, maxval) \
757static int \
758lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
759{ \
760 if (val >= minval && val <= maxval) {\
761 vport->cfg_##attr = val;\
762 return 0;\
763 }\
James Smarte8b62012007-08-02 11:10:09 -0400764 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
765 "0449 lpfc_"#attr" attribute cannot be set to %d, "\
766 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400767 vport->cfg_##attr = default;\
768 return -EINVAL;\
769}
770
771#define lpfc_vport_param_set(attr, default, minval, maxval) \
772static int \
773lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
774{ \
775 if (val >= minval && val <= maxval) {\
776 vport->cfg_##attr = val;\
777 return 0;\
778 }\
James Smarte8b62012007-08-02 11:10:09 -0400779 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
780 "0450 lpfc_"#attr" attribute cannot be set to %d, "\
781 "allowed range is ["#minval", "#maxval"]\n", val); \
James Smart3de2a652007-08-02 11:09:59 -0400782 return -EINVAL;\
783}
784
785#define lpfc_vport_param_store(attr) \
786static ssize_t \
787lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
788{ \
789 struct Scsi_Host *shost = class_to_shost(cdev);\
790 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
791 int val=0;\
792 if (!isdigit(buf[0]))\
793 return -EINVAL;\
794 if (sscanf(buf, "%i", &val) != 1)\
795 return -EINVAL;\
796 if (lpfc_##attr##_set(vport, val) == 0) \
797 return strlen(buf);\
798 else \
799 return -EINVAL;\
800}
801
802
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400803#define LPFC_ATTR(name, defval, minval, maxval, desc) \
804static int lpfc_##name = defval;\
dea31012005-04-17 16:05:31 -0500805module_param(lpfc_##name, int, 0);\
806MODULE_PARM_DESC(lpfc_##name, desc);\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400807lpfc_param_init(name, defval, minval, maxval)
dea31012005-04-17 16:05:31 -0500808
809#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
810static int lpfc_##name = defval;\
811module_param(lpfc_##name, int, 0);\
812MODULE_PARM_DESC(lpfc_##name, desc);\
813lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400814lpfc_param_init(name, defval, minval, maxval)\
dea31012005-04-17 16:05:31 -0500815static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
816
817#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
818static int lpfc_##name = defval;\
819module_param(lpfc_##name, int, 0);\
820MODULE_PARM_DESC(lpfc_##name, desc);\
821lpfc_param_show(name)\
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -0400822lpfc_param_init(name, defval, minval, maxval)\
823lpfc_param_set(name, defval, minval, maxval)\
824lpfc_param_store(name)\
dea31012005-04-17 16:05:31 -0500825static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
826 lpfc_##name##_show, lpfc_##name##_store)
827
James.Smart@Emulex.Com93a20f72005-10-28 20:29:32 -0400828#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
829static int lpfc_##name = defval;\
830module_param(lpfc_##name, int, 0);\
831MODULE_PARM_DESC(lpfc_##name, desc);\
832lpfc_param_hex_show(name)\
833lpfc_param_init(name, defval, minval, maxval)\
834static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
835
836#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
837static int lpfc_##name = defval;\
838module_param(lpfc_##name, int, 0);\
839MODULE_PARM_DESC(lpfc_##name, desc);\
840lpfc_param_hex_show(name)\
841lpfc_param_init(name, defval, minval, maxval)\
842lpfc_param_set(name, defval, minval, maxval)\
843lpfc_param_store(name)\
844static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
845 lpfc_##name##_show, lpfc_##name##_store)
846
James Smart3de2a652007-08-02 11:09:59 -0400847#define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
848static int lpfc_##name = defval;\
849module_param(lpfc_##name, int, 0);\
850MODULE_PARM_DESC(lpfc_##name, desc);\
851lpfc_vport_param_init(name, defval, minval, maxval)
852
853#define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
854static int lpfc_##name = defval;\
855module_param(lpfc_##name, int, 0);\
856MODULE_PARM_DESC(lpfc_##name, desc);\
857lpfc_vport_param_show(name)\
858lpfc_vport_param_init(name, defval, minval, maxval)\
859static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
860
861#define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
862static int lpfc_##name = defval;\
863module_param(lpfc_##name, int, 0);\
864MODULE_PARM_DESC(lpfc_##name, desc);\
865lpfc_vport_param_show(name)\
866lpfc_vport_param_init(name, defval, minval, maxval)\
867lpfc_vport_param_set(name, defval, minval, maxval)\
868lpfc_vport_param_store(name)\
869static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
870 lpfc_##name##_show, lpfc_##name##_store)
871
872#define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
873static int lpfc_##name = defval;\
874module_param(lpfc_##name, int, 0);\
875MODULE_PARM_DESC(lpfc_##name, desc);\
876lpfc_vport_param_hex_show(name)\
877lpfc_vport_param_init(name, defval, minval, maxval)\
878static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
879
880#define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
881static int lpfc_##name = defval;\
882module_param(lpfc_##name, int, 0);\
883MODULE_PARM_DESC(lpfc_##name, desc);\
884lpfc_vport_param_hex_show(name)\
885lpfc_vport_param_init(name, defval, minval, maxval)\
886lpfc_vport_param_set(name, defval, minval, maxval)\
887lpfc_vport_param_store(name)\
888static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
889 lpfc_##name##_show, lpfc_##name##_store)
890
dea31012005-04-17 16:05:31 -0500891static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
892static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
893static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
894static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
895static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
James Smart2e0fef82007-06-17 19:56:36 -0500896static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea31012005-04-17 16:05:31 -0500897static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
898static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
899static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
900static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
901 lpfc_option_rom_version_show, NULL);
902static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
903 lpfc_num_discovered_ports_show, NULL);
904static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
905static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
906 NULL);
907static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
908 NULL);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500909static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
910 lpfc_board_mode_show, lpfc_board_mode_store);
James Smart40496f02006-07-06 15:50:22 -0400911static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
James Smart92d7f7b2007-06-17 19:56:38 -0500912static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
913static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
914static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
915static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
916static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
917static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
918static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
dea31012005-04-17 16:05:31 -0500919
James Smartc3f28af2006-08-18 17:47:18 -0400920
James Smarta12e07b2006-12-02 13:35:30 -0500921static char *lpfc_soft_wwn_key = "C99G71SL8032A";
James Smartc3f28af2006-08-18 17:47:18 -0400922
923static ssize_t
James Smarta12e07b2006-12-02 13:35:30 -0500924lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
James Smartc3f28af2006-08-18 17:47:18 -0400925 size_t count)
926{
James Smart2e0fef82007-06-17 19:56:36 -0500927 struct Scsi_Host *shost = class_to_shost(cdev);
928 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
929 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400930 unsigned int cnt = count;
931
932 /*
933 * We're doing a simple sanity check for soft_wwpn setting.
934 * We require that the user write a specific key to enable
935 * the soft_wwpn attribute to be settable. Once the attribute
936 * is written, the enable key resets. If further updates are
937 * desired, the key must be written again to re-enable the
938 * attribute.
939 *
940 * The "key" is not secret - it is a hardcoded string shown
941 * here. The intent is to protect against the random user or
942 * application that is just writing attributes.
943 */
944
945 /* count may include a LF at end of string */
946 if (buf[cnt-1] == '\n')
947 cnt--;
948
James Smarta12e07b2006-12-02 13:35:30 -0500949 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
950 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
James Smartc3f28af2006-08-18 17:47:18 -0400951 return -EINVAL;
952
James Smarta12e07b2006-12-02 13:35:30 -0500953 phba->soft_wwn_enable = 1;
James Smartc3f28af2006-08-18 17:47:18 -0400954 return count;
955}
James Smarta12e07b2006-12-02 13:35:30 -0500956static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
957 lpfc_soft_wwn_enable_store);
James Smartc3f28af2006-08-18 17:47:18 -0400958
959static ssize_t
960lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
961{
James Smart2e0fef82007-06-17 19:56:36 -0500962 struct Scsi_Host *shost = class_to_shost(cdev);
963 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
964 struct lpfc_hba *phba = vport->phba;
965
Randy Dunlapafc071e2006-10-23 21:47:13 -0700966 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
967 (unsigned long long)phba->cfg_soft_wwpn);
James Smartc3f28af2006-08-18 17:47:18 -0400968}
969
970
971static ssize_t
972lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
973{
James Smart2e0fef82007-06-17 19:56:36 -0500974 struct Scsi_Host *shost = class_to_shost(cdev);
975 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
976 struct lpfc_hba *phba = vport->phba;
James Smartc3f28af2006-08-18 17:47:18 -0400977 struct completion online_compl;
978 int stat1=0, stat2=0;
979 unsigned int i, j, cnt=count;
980 u8 wwpn[8];
981
982 /* count may include a LF at end of string */
983 if (buf[cnt-1] == '\n')
984 cnt--;
985
James Smarta12e07b2006-12-02 13:35:30 -0500986 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
James Smartc3f28af2006-08-18 17:47:18 -0400987 ((cnt == 17) && (*buf++ != 'x')) ||
988 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
989 return -EINVAL;
990
James Smarta12e07b2006-12-02 13:35:30 -0500991 phba->soft_wwn_enable = 0;
James Smartc3f28af2006-08-18 17:47:18 -0400992
993 memset(wwpn, 0, sizeof(wwpn));
994
995 /* Validate and store the new name */
996 for (i=0, j=0; i < 16; i++) {
997 if ((*buf >= 'a') && (*buf <= 'f'))
998 j = ((j << 4) | ((*buf++ -'a') + 10));
999 else if ((*buf >= 'A') && (*buf <= 'F'))
1000 j = ((j << 4) | ((*buf++ -'A') + 10));
1001 else if ((*buf >= '0') && (*buf <= '9'))
1002 j = ((j << 4) | (*buf++ -'0'));
1003 else
1004 return -EINVAL;
1005 if (i % 2) {
1006 wwpn[i/2] = j & 0xff;
1007 j = 0;
1008 }
1009 }
1010 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
James Smart2e0fef82007-06-17 19:56:36 -05001011 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
James Smarta12e07b2006-12-02 13:35:30 -05001012 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05001013 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
James Smartc3f28af2006-08-18 17:47:18 -04001014
1015 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1016 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
1017
James Smart46fa3112007-04-25 09:51:45 -04001018 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
James Smartc3f28af2006-08-18 17:47:18 -04001019 if (stat1)
1020 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001021 "0463 lpfc_soft_wwpn attribute set failed to "
1022 "reinit adapter - %d\n", stat1);
James Smartc3f28af2006-08-18 17:47:18 -04001023 init_completion(&online_compl);
1024 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
1025 wait_for_completion(&online_compl);
1026 if (stat2)
1027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
James Smarte8b62012007-08-02 11:10:09 -04001028 "0464 lpfc_soft_wwpn attribute set failed to "
1029 "reinit adapter - %d\n", stat2);
James Smartc3f28af2006-08-18 17:47:18 -04001030 return (stat1 || stat2) ? -EIO : count;
1031}
1032static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
1033 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
1034
James Smarta12e07b2006-12-02 13:35:30 -05001035static ssize_t
1036lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
1037{
1038 struct Scsi_Host *host = class_to_shost(cdev);
1039 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1040 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
1041 (unsigned long long)phba->cfg_soft_wwnn);
1042}
1043
1044
1045static ssize_t
1046lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
1047{
1048 struct Scsi_Host *host = class_to_shost(cdev);
1049 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1050 unsigned int i, j, cnt=count;
1051 u8 wwnn[8];
1052
1053 /* count may include a LF at end of string */
1054 if (buf[cnt-1] == '\n')
1055 cnt--;
1056
1057 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
1058 ((cnt == 17) && (*buf++ != 'x')) ||
1059 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
1060 return -EINVAL;
1061
1062 /*
1063 * Allow wwnn to be set many times, as long as the enable is set.
1064 * However, once the wwpn is set, everything locks.
1065 */
1066
1067 memset(wwnn, 0, sizeof(wwnn));
1068
1069 /* Validate and store the new name */
1070 for (i=0, j=0; i < 16; i++) {
1071 if ((*buf >= 'a') && (*buf <= 'f'))
1072 j = ((j << 4) | ((*buf++ -'a') + 10));
1073 else if ((*buf >= 'A') && (*buf <= 'F'))
1074 j = ((j << 4) | ((*buf++ -'A') + 10));
1075 else if ((*buf >= '0') && (*buf <= '9'))
1076 j = ((j << 4) | (*buf++ -'0'));
1077 else
1078 return -EINVAL;
1079 if (i % 2) {
1080 wwnn[i/2] = j & 0xff;
1081 j = 0;
1082 }
1083 }
1084 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
1085
1086 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
1087 "lpfc%d: soft_wwnn set. Value will take effect upon "
1088 "setting of the soft_wwpn\n", phba->brd_no);
1089
1090 return count;
1091}
1092static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
1093 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
1094
James Smartc3f28af2006-08-18 17:47:18 -04001095
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001096static int lpfc_poll = 0;
1097module_param(lpfc_poll, int, 0);
1098MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
1099 " 0 - none,"
1100 " 1 - poll with interrupts enabled"
1101 " 3 - poll and disable FCP ring interrupts");
1102
1103static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
1104 lpfc_poll_show, lpfc_poll_store);
dea31012005-04-17 16:05:31 -05001105
James Smart92d7f7b2007-06-17 19:56:38 -05001106int lpfc_sli_mode = 0;
1107module_param(lpfc_sli_mode, int, 0);
1108MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1109 " 0 - auto (SLI-3 if supported),"
1110 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1111 " 3 - select SLI-3");
1112
James Smart858c9f62007-06-17 19:56:39 -05001113LPFC_ATTR_R(npiv_enable, 0, 0, 1, "Enable NPIV functionality");
James Smart92d7f7b2007-06-17 19:56:38 -05001114
dea31012005-04-17 16:05:31 -05001115/*
James Smartc01f3202006-08-18 17:47:08 -04001116# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
1117# until the timer expires. Value range is [0,255]. Default value is 30.
1118*/
1119static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
1120static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
1121module_param(lpfc_nodev_tmo, int, 0);
1122MODULE_PARM_DESC(lpfc_nodev_tmo,
1123 "Seconds driver will hold I/O waiting "
1124 "for a device to come back");
1125static ssize_t
1126lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
1127{
James Smart2e0fef82007-06-17 19:56:36 -05001128 struct Scsi_Host *shost = class_to_shost(cdev);
1129 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smartc01f3202006-08-18 17:47:08 -04001130 int val = 0;
James Smart3de2a652007-08-02 11:09:59 -04001131 val = vport->cfg_devloss_tmo;
1132 return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
James Smartc01f3202006-08-18 17:47:08 -04001133}
1134
1135static int
James Smart3de2a652007-08-02 11:09:59 -04001136lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001137{
James Smart3de2a652007-08-02 11:09:59 -04001138 if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
1139 vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
1140 if (val != LPFC_DEF_DEVLOSS_TMO)
James Smarte8b62012007-08-02 11:10:09 -04001141 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1142 "0402 Ignoring nodev_tmo module "
1143 "parameter because devloss_tmo is "
1144 "set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001145 return 0;
1146 }
1147
1148 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001149 vport->cfg_nodev_tmo = val;
1150 vport->cfg_devloss_tmo = val;
James Smartc01f3202006-08-18 17:47:08 -04001151 return 0;
1152 }
James Smarte8b62012007-08-02 11:10:09 -04001153 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1154 "0400 lpfc_nodev_tmo attribute cannot be set to"
1155 " %d, allowed range is [%d, %d]\n",
1156 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smart3de2a652007-08-02 11:09:59 -04001157 vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
James Smartc01f3202006-08-18 17:47:08 -04001158 return -EINVAL;
1159}
1160
James Smart7054a602007-04-25 09:52:34 -04001161static void
James Smart3de2a652007-08-02 11:09:59 -04001162lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
James Smart7054a602007-04-25 09:52:34 -04001163{
James Smart549e55c2007-08-02 11:09:51 -04001164 struct lpfc_vport **vports;
James Smart858c9f62007-06-17 19:56:39 -05001165 struct Scsi_Host *shost;
James Smart7054a602007-04-25 09:52:34 -04001166 struct lpfc_nodelist *ndlp;
James Smart549e55c2007-08-02 11:09:51 -04001167 int i;
James Smart7054a602007-04-25 09:52:34 -04001168
James Smart3de2a652007-08-02 11:09:59 -04001169 vports = lpfc_create_vport_work_array(vport->phba);
James Smart549e55c2007-08-02 11:09:51 -04001170 if (vports != NULL)
1171 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
1172 shost = lpfc_shost_from_vport(vports[i]);
1173 spin_lock_irq(shost->host_lock);
1174 list_for_each_entry(ndlp, &vports[i]->fc_nodes,
1175 nlp_listp)
James Smart858c9f62007-06-17 19:56:39 -05001176 if (ndlp->rport)
1177 ndlp->rport->dev_loss_tmo =
James Smart3de2a652007-08-02 11:09:59 -04001178 vport->cfg_devloss_tmo;
James Smart549e55c2007-08-02 11:09:51 -04001179 spin_unlock_irq(shost->host_lock);
1180 }
1181 lpfc_destroy_vport_work_array(vports);
James Smart7054a602007-04-25 09:52:34 -04001182}
1183
James Smartc01f3202006-08-18 17:47:08 -04001184static int
James Smart3de2a652007-08-02 11:09:59 -04001185lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001186{
James Smart3de2a652007-08-02 11:09:59 -04001187 if (vport->dev_loss_tmo_changed ||
1188 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
James Smarte8b62012007-08-02 11:10:09 -04001189 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1190 "0401 Ignoring change to nodev_tmo "
1191 "because devloss_tmo is set.\n");
James Smartc01f3202006-08-18 17:47:08 -04001192 return 0;
1193 }
James Smartc01f3202006-08-18 17:47:08 -04001194 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001195 vport->cfg_nodev_tmo = val;
1196 vport->cfg_devloss_tmo = val;
1197 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001198 return 0;
1199 }
James Smarte8b62012007-08-02 11:10:09 -04001200 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1201 "0403 lpfc_nodev_tmo attribute cannot be set to"
1202 "%d, allowed range is [%d, %d]\n",
1203 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001204 return -EINVAL;
1205}
1206
James Smart3de2a652007-08-02 11:09:59 -04001207lpfc_vport_param_store(nodev_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001208
1209static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
1210 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
1211
1212/*
1213# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
1214# disappear until the timer expires. Value range is [0,255]. Default
1215# value is 30.
1216*/
1217module_param(lpfc_devloss_tmo, int, 0);
1218MODULE_PARM_DESC(lpfc_devloss_tmo,
1219 "Seconds driver will hold I/O waiting "
1220 "for a device to come back");
James Smart3de2a652007-08-02 11:09:59 -04001221lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
1222 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
1223lpfc_vport_param_show(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001224static int
James Smart3de2a652007-08-02 11:09:59 -04001225lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
James Smartc01f3202006-08-18 17:47:08 -04001226{
1227 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
James Smart3de2a652007-08-02 11:09:59 -04001228 vport->cfg_nodev_tmo = val;
1229 vport->cfg_devloss_tmo = val;
1230 vport->dev_loss_tmo_changed = 1;
1231 lpfc_update_rport_devloss_tmo(vport);
James Smartc01f3202006-08-18 17:47:08 -04001232 return 0;
1233 }
1234
James Smarte8b62012007-08-02 11:10:09 -04001235 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1236 "0404 lpfc_devloss_tmo attribute cannot be set to"
1237 " %d, allowed range is [%d, %d]\n",
1238 val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
James Smartc01f3202006-08-18 17:47:08 -04001239 return -EINVAL;
1240}
1241
James Smart3de2a652007-08-02 11:09:59 -04001242lpfc_vport_param_store(devloss_tmo)
James Smartc01f3202006-08-18 17:47:08 -04001243static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
1244 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
1245
1246/*
dea31012005-04-17 16:05:31 -05001247# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
1248# deluged with LOTS of information.
1249# You can set a bit mask to record specific types of verbose messages:
1250#
1251# LOG_ELS 0x1 ELS events
1252# LOG_DISCOVERY 0x2 Link discovery events
1253# LOG_MBOX 0x4 Mailbox events
1254# LOG_INIT 0x8 Initialization events
1255# LOG_LINK_EVENT 0x10 Link events
dea31012005-04-17 16:05:31 -05001256# LOG_FCP 0x40 FCP traffic history
1257# LOG_NODE 0x80 Node table events
1258# LOG_MISC 0x400 Miscellaneous events
1259# LOG_SLI 0x800 SLI events
James Smartc7743952006-12-02 13:34:42 -05001260# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea31012005-04-17 16:05:31 -05001261# LOG_LIBDFC 0x2000 LIBDFC events
1262# LOG_ALL_MSG 0xffff LOG all messages
1263*/
James Smarte8b62012007-08-02 11:10:09 -04001264LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
1265 "Verbose logging bit-mask");
dea31012005-04-17 16:05:31 -05001266
1267/*
1268# lun_queue_depth: This parameter is used to limit the number of outstanding
1269# commands per FCP LUN. Value range is [1,128]. Default value is 30.
1270*/
James Smart3de2a652007-08-02 11:09:59 -04001271LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
1272 "Max number of FCP commands we can queue to a specific LUN");
dea31012005-04-17 16:05:31 -05001273
1274/*
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001275# hba_queue_depth: This parameter is used to limit the number of outstanding
1276# commands per lpfc HBA. Value range is [32,8192]. If this parameter
1277# value is greater than the maximum number of exchanges supported by the HBA,
1278# then maximum number of exchanges supported by the HBA is used to determine
1279# the hba_queue_depth.
1280*/
1281LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
1282 "Max number of FCP commands we can queue to a lpfc HBA");
1283
1284/*
James Smart92d7f7b2007-06-17 19:56:38 -05001285# peer_port_login: This parameter allows/prevents logins
1286# between peer ports hosted on the same physical port.
1287# When this parameter is set 0 peer ports of same physical port
1288# are not allowed to login to each other.
1289# When this parameter is set 1 peer ports of same physical port
1290# are allowed to login to each other.
1291# Default value of this parameter is 0.
1292*/
James Smart3de2a652007-08-02 11:09:59 -04001293LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
1294 "Allow peer ports on the same physical port to login to each "
1295 "other.");
James Smart92d7f7b2007-06-17 19:56:38 -05001296
1297/*
James Smart3de2a652007-08-02 11:09:59 -04001298# restrict_login: This parameter allows/prevents logins
James Smart92d7f7b2007-06-17 19:56:38 -05001299# between Virtual Ports and remote initiators.
1300# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1301# other initiators and will attempt to PLOGI all remote ports.
1302# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1303# remote ports and will not attempt to PLOGI to other initiators.
1304# This parameter does not restrict to the physical port.
1305# This parameter does not restrict logins to Fabric resident remote ports.
1306# Default value of this parameter is 1.
1307*/
James Smart3de2a652007-08-02 11:09:59 -04001308static int lpfc_restrict_login = 1;
1309module_param(lpfc_restrict_login, int, 0);
1310MODULE_PARM_DESC(lpfc_restrict_login,
1311 "Restrict virtual ports login to remote initiators.");
1312lpfc_vport_param_show(restrict_login);
1313
1314static int
1315lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
1316{
1317 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001318 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1319 "0449 lpfc_restrict_login attribute cannot "
1320 "be set to %d, allowed range is [0, 1]\n",
1321 val);
James Smart3de2a652007-08-02 11:09:59 -04001322 vport->cfg_restrict_login = 1;
1323 return -EINVAL;
1324 }
1325 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1326 vport->cfg_restrict_login = 0;
1327 return 0;
1328 }
1329 vport->cfg_restrict_login = val;
1330 return 0;
1331}
1332
1333static int
1334lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
1335{
1336 if (val < 0 || val > 1) {
James Smarte8b62012007-08-02 11:10:09 -04001337 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1338 "0450 lpfc_restrict_login attribute cannot "
1339 "be set to %d, allowed range is [0, 1]\n",
1340 val);
James Smart3de2a652007-08-02 11:09:59 -04001341 vport->cfg_restrict_login = 1;
1342 return -EINVAL;
1343 }
1344 if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
James Smarte8b62012007-08-02 11:10:09 -04001345 lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
1346 "0468 lpfc_restrict_login must be 0 for "
1347 "Physical ports.\n");
James Smart3de2a652007-08-02 11:09:59 -04001348 vport->cfg_restrict_login = 0;
1349 return 0;
1350 }
1351 vport->cfg_restrict_login = val;
1352 return 0;
1353}
1354lpfc_vport_param_store(restrict_login);
1355static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
1356 lpfc_restrict_login_show, lpfc_restrict_login_store);
James Smart92d7f7b2007-06-17 19:56:38 -05001357
1358/*
dea31012005-04-17 16:05:31 -05001359# Some disk devices have a "select ID" or "select Target" capability.
1360# From a protocol standpoint "select ID" usually means select the
1361# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
1362# annex" which contains a table that maps a "select ID" (a number
1363# between 0 and 7F) to an ALPA. By default, for compatibility with
1364# older drivers, the lpfc driver scans this table from low ALPA to high
1365# ALPA.
1366#
1367# Turning on the scan-down variable (on = 1, off = 0) will
1368# cause the lpfc driver to use an inverted table, effectively
1369# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
1370#
1371# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1372# and will not work across a fabric. Also this parameter will take
1373# effect only in the case when ALPA map is not available.)
1374*/
James Smart3de2a652007-08-02 11:09:59 -04001375LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
1376 "Start scanning for devices from highest ALPA to lowest");
dea31012005-04-17 16:05:31 -05001377
1378/*
dea31012005-04-17 16:05:31 -05001379# lpfc_topology: link topology for init link
1380# 0x0 = attempt loop mode then point-to-point
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001381# 0x01 = internal loopback mode
dea31012005-04-17 16:05:31 -05001382# 0x02 = attempt point-to-point mode only
1383# 0x04 = attempt loop mode only
1384# 0x06 = attempt point-to-point mode then loop
1385# Set point-to-point mode if you want to run as an N_Port.
1386# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1387# Default value is 0.
1388*/
Jamie Wellnitz367c2712006-02-28 19:25:32 -05001389LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea31012005-04-17 16:05:31 -05001390
1391/*
1392# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1393# connection.
1394# 0 = auto select (default)
1395# 1 = 1 Gigabaud
1396# 2 = 2 Gigabaud
1397# 4 = 4 Gigabaud
James Smartb87eab32007-04-25 09:53:28 -04001398# 8 = 8 Gigabaud
1399# Value range is [0,8]. Default value is 0.
dea31012005-04-17 16:05:31 -05001400*/
James Smartb87eab32007-04-25 09:53:28 -04001401LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea31012005-04-17 16:05:31 -05001402
1403/*
1404# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1405# Value range is [2,3]. Default value is 3.
1406*/
James Smart3de2a652007-08-02 11:09:59 -04001407LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
1408 "Select Fibre Channel class of service for FCP sequences");
dea31012005-04-17 16:05:31 -05001409
1410/*
1411# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1412# is [0,1]. Default value is 0.
1413*/
James Smart3de2a652007-08-02 11:09:59 -04001414LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
1415 "Use ADISC on rediscovery to authenticate FCP devices");
dea31012005-04-17 16:05:31 -05001416
1417/*
1418# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1419# range is [0,1]. Default value is 0.
1420*/
1421LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1422
1423/*
1424# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1425# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
James Smart7054a602007-04-25 09:52:34 -04001426# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea31012005-04-17 16:05:31 -05001427# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1428# cr_delay is set to 0.
1429*/
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001430LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea31012005-04-17 16:05:31 -05001431 "interrupt response is generated");
1432
Jamie Wellnitz8189fd12006-02-28 19:25:35 -05001433LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea31012005-04-17 16:05:31 -05001434 "interrupt response is generated");
1435
1436/*
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001437# lpfc_multi_ring_support: Determines how many rings to spread available
1438# cmd/rsp IOCB entries across.
1439# Value range is [1,2]. Default value is 1.
1440*/
1441LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1442 "SLI rings to spread IOCB entries across");
1443
1444/*
James Smarta4bc3372006-12-02 13:34:16 -05001445# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1446# identifies what rctl value to configure the additional ring for.
1447# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1448*/
1449LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1450 255, "Identifies RCTL for additional ring configuration");
1451
1452/*
1453# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1454# identifies what type value to configure the additional ring for.
1455# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1456*/
1457LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1458 255, "Identifies TYPE for additional ring configuration");
1459
1460/*
dea31012005-04-17 16:05:31 -05001461# lpfc_fdmi_on: controls FDMI support.
1462# 0 = no FDMI support
1463# 1 = support FDMI without attribute of hostname
1464# 2 = support FDMI with attribute of hostname
1465# Value range [0,2]. Default value is 0.
1466*/
James Smart3de2a652007-08-02 11:09:59 -04001467LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
dea31012005-04-17 16:05:31 -05001468
1469/*
1470# Specifies the maximum number of ELS cmds we can have outstanding (for
1471# discovery). Value range is [1,64]. Default value = 32.
1472*/
James Smart3de2a652007-08-02 11:09:59 -04001473LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea31012005-04-17 16:05:31 -05001474 "during discovery");
1475
1476/*
James Smart65a29c12006-07-06 15:50:50 -04001477# lpfc_max_luns: maximum allowed LUN.
1478# Value range is [0,65535]. Default value is 255.
1479# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea31012005-04-17 16:05:31 -05001480*/
James Smart3de2a652007-08-02 11:09:59 -04001481LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
dea31012005-04-17 16:05:31 -05001482
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001483/*
1484# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1485# Value range is [1,255], default value is 10.
1486*/
1487LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1488 "Milliseconds driver will wait between polling FCP ring");
1489
James Smart4ff43242006-12-02 13:34:56 -05001490/*
1491# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1492# support this feature
1493# 0 = MSI disabled (default)
1494# 1 = MSI enabled
1495# Value range is [0,1]. Default value is 0.
1496*/
1497LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1498
James Smartc3f28af2006-08-18 17:47:18 -04001499
James Smart92d7f7b2007-06-17 19:56:38 -05001500
James Smart2e0fef82007-06-17 19:56:36 -05001501struct class_device_attribute *lpfc_hba_attrs[] = {
dea31012005-04-17 16:05:31 -05001502 &class_device_attr_info,
1503 &class_device_attr_serialnum,
1504 &class_device_attr_modeldesc,
1505 &class_device_attr_modelname,
1506 &class_device_attr_programtype,
1507 &class_device_attr_portnum,
1508 &class_device_attr_fwrev,
1509 &class_device_attr_hdw,
1510 &class_device_attr_option_rom_version,
1511 &class_device_attr_state,
1512 &class_device_attr_num_discovered_ports,
1513 &class_device_attr_lpfc_drvr_version,
1514 &class_device_attr_lpfc_log_verbose,
1515 &class_device_attr_lpfc_lun_queue_depth,
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05001516 &class_device_attr_lpfc_hba_queue_depth,
James Smart92d7f7b2007-06-17 19:56:38 -05001517 &class_device_attr_lpfc_peer_port_login,
dea31012005-04-17 16:05:31 -05001518 &class_device_attr_lpfc_nodev_tmo,
James Smartc01f3202006-08-18 17:47:08 -04001519 &class_device_attr_lpfc_devloss_tmo,
dea31012005-04-17 16:05:31 -05001520 &class_device_attr_lpfc_fcp_class,
1521 &class_device_attr_lpfc_use_adisc,
1522 &class_device_attr_lpfc_ack0,
1523 &class_device_attr_lpfc_topology,
1524 &class_device_attr_lpfc_scan_down,
1525 &class_device_attr_lpfc_link_speed,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001526 &class_device_attr_lpfc_cr_delay,
1527 &class_device_attr_lpfc_cr_count,
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05001528 &class_device_attr_lpfc_multi_ring_support,
James Smarta4bc3372006-12-02 13:34:16 -05001529 &class_device_attr_lpfc_multi_ring_rctl,
1530 &class_device_attr_lpfc_multi_ring_type,
dea31012005-04-17 16:05:31 -05001531 &class_device_attr_lpfc_fdmi_on,
1532 &class_device_attr_lpfc_max_luns,
James Smart858c9f62007-06-17 19:56:39 -05001533 &class_device_attr_lpfc_npiv_enable,
dea31012005-04-17 16:05:31 -05001534 &class_device_attr_nport_evt_cnt,
1535 &class_device_attr_management_version,
Jamie Wellnitz41415862006-02-28 19:25:27 -05001536 &class_device_attr_board_mode,
James Smart92d7f7b2007-06-17 19:56:38 -05001537 &class_device_attr_max_vpi,
1538 &class_device_attr_used_vpi,
1539 &class_device_attr_max_rpi,
1540 &class_device_attr_used_rpi,
1541 &class_device_attr_max_xri,
1542 &class_device_attr_used_xri,
1543 &class_device_attr_npiv_info,
James Smart40496f02006-07-06 15:50:22 -04001544 &class_device_attr_issue_reset,
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05001545 &class_device_attr_lpfc_poll,
1546 &class_device_attr_lpfc_poll_tmo,
James Smart4ff43242006-12-02 13:34:56 -05001547 &class_device_attr_lpfc_use_msi,
James Smarta12e07b2006-12-02 13:35:30 -05001548 &class_device_attr_lpfc_soft_wwnn,
James Smartc3f28af2006-08-18 17:47:18 -04001549 &class_device_attr_lpfc_soft_wwpn,
James Smarta12e07b2006-12-02 13:35:30 -05001550 &class_device_attr_lpfc_soft_wwn_enable,
dea31012005-04-17 16:05:31 -05001551 NULL,
1552};
1553
James Smart3de2a652007-08-02 11:09:59 -04001554struct class_device_attribute *lpfc_vport_attrs[] = {
1555 &class_device_attr_info,
1556 &class_device_attr_state,
1557 &class_device_attr_num_discovered_ports,
1558 &class_device_attr_lpfc_drvr_version,
1559
1560 &class_device_attr_lpfc_log_verbose,
1561 &class_device_attr_lpfc_lun_queue_depth,
1562 &class_device_attr_lpfc_nodev_tmo,
1563 &class_device_attr_lpfc_devloss_tmo,
1564 &class_device_attr_lpfc_hba_queue_depth,
1565 &class_device_attr_lpfc_peer_port_login,
1566 &class_device_attr_lpfc_restrict_login,
1567 &class_device_attr_lpfc_fcp_class,
1568 &class_device_attr_lpfc_use_adisc,
1569 &class_device_attr_lpfc_fdmi_on,
1570 &class_device_attr_lpfc_max_luns,
1571 &class_device_attr_nport_evt_cnt,
1572 &class_device_attr_management_version,
1573 &class_device_attr_npiv_info,
1574 NULL,
1575};
1576
dea31012005-04-17 16:05:31 -05001577static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001578sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1579 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001580{
1581 size_t buf_off;
James Smart2e0fef82007-06-17 19:56:36 -05001582 struct class_device *cdev = container_of(kobj, struct class_device,
1583 kobj);
1584 struct Scsi_Host *shost = class_to_shost(cdev);
1585 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1586 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001587
1588 if ((off + count) > FF_REG_AREA_SIZE)
1589 return -ERANGE;
1590
1591 if (count == 0) return 0;
1592
1593 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1594 return -EINVAL;
1595
James Smart2e0fef82007-06-17 19:56:36 -05001596 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001597 return -EPERM;
1598 }
1599
James Smart2e0fef82007-06-17 19:56:36 -05001600 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001601 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1602 writel(*((uint32_t *)(buf + buf_off)),
1603 phba->ctrl_regs_memmap_p + off + buf_off);
1604
James Smart2e0fef82007-06-17 19:56:36 -05001605 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001606
1607 return count;
1608}
1609
1610static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001611sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1612 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001613{
1614 size_t buf_off;
1615 uint32_t * tmp_ptr;
James Smart2e0fef82007-06-17 19:56:36 -05001616 struct class_device *cdev = container_of(kobj, struct class_device,
1617 kobj);
1618 struct Scsi_Host *shost = class_to_shost(cdev);
1619 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1620 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001621
1622 if (off > FF_REG_AREA_SIZE)
1623 return -ERANGE;
1624
1625 if ((off + count) > FF_REG_AREA_SIZE)
1626 count = FF_REG_AREA_SIZE - off;
1627
1628 if (count == 0) return 0;
1629
1630 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1631 return -EINVAL;
1632
James Smart2e0fef82007-06-17 19:56:36 -05001633 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001634
1635 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1636 tmp_ptr = (uint32_t *)(buf + buf_off);
1637 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1638 }
1639
James Smart2e0fef82007-06-17 19:56:36 -05001640 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001641
1642 return count;
1643}
1644
1645static struct bin_attribute sysfs_ctlreg_attr = {
1646 .attr = {
1647 .name = "ctlreg",
1648 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001649 },
1650 .size = 256,
1651 .read = sysfs_ctlreg_read,
1652 .write = sysfs_ctlreg_write,
1653};
1654
1655
1656static void
James Smart2e0fef82007-06-17 19:56:36 -05001657sysfs_mbox_idle(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001658{
1659 phba->sysfs_mbox.state = SMBOX_IDLE;
1660 phba->sysfs_mbox.offset = 0;
1661
1662 if (phba->sysfs_mbox.mbox) {
1663 mempool_free(phba->sysfs_mbox.mbox,
1664 phba->mbox_mem_pool);
1665 phba->sysfs_mbox.mbox = NULL;
1666 }
1667}
1668
1669static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001670sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1671 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001672{
James Smart2e0fef82007-06-17 19:56:36 -05001673 struct class_device *cdev = container_of(kobj, struct class_device,
1674 kobj);
1675 struct Scsi_Host *shost = class_to_shost(cdev);
1676 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1677 struct lpfc_hba *phba = vport->phba;
1678 struct lpfcMboxq *mbox = NULL;
dea31012005-04-17 16:05:31 -05001679
1680 if ((count + off) > MAILBOX_CMD_SIZE)
1681 return -ERANGE;
1682
1683 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1684 return -EINVAL;
1685
1686 if (count == 0)
1687 return 0;
1688
1689 if (off == 0) {
1690 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1691 if (!mbox)
1692 return -ENOMEM;
James Smartfc6c12b2006-03-07 15:04:19 -05001693 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05001694 }
1695
James Smart2e0fef82007-06-17 19:56:36 -05001696 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001697
1698 if (off == 0) {
1699 if (phba->sysfs_mbox.mbox)
1700 mempool_free(mbox, phba->mbox_mem_pool);
1701 else
1702 phba->sysfs_mbox.mbox = mbox;
1703 phba->sysfs_mbox.state = SMBOX_WRITING;
1704 } else {
1705 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1706 phba->sysfs_mbox.offset != off ||
James Smart92d7f7b2007-06-17 19:56:38 -05001707 phba->sysfs_mbox.mbox == NULL) {
dea31012005-04-17 16:05:31 -05001708 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001709 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001710 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001711 }
1712 }
1713
1714 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1715 buf, count);
1716
1717 phba->sysfs_mbox.offset = off + count;
1718
James Smart2e0fef82007-06-17 19:56:36 -05001719 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001720
1721 return count;
1722}
1723
1724static ssize_t
Zhang Rui91a69022007-06-09 13:57:22 +08001725sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1726 char *buf, loff_t off, size_t count)
dea31012005-04-17 16:05:31 -05001727{
James Smart2e0fef82007-06-17 19:56:36 -05001728 struct class_device *cdev = container_of(kobj, struct class_device,
1729 kobj);
1730 struct Scsi_Host *shost = class_to_shost(cdev);
1731 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1732 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001733 int rc;
1734
James Smart1dcb58e2007-04-25 09:51:30 -04001735 if (off > MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001736 return -ERANGE;
1737
James Smart1dcb58e2007-04-25 09:51:30 -04001738 if ((count + off) > MAILBOX_CMD_SIZE)
1739 count = MAILBOX_CMD_SIZE - off;
dea31012005-04-17 16:05:31 -05001740
1741 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1742 return -EINVAL;
1743
1744 if (off && count == 0)
1745 return 0;
1746
James Smart2e0fef82007-06-17 19:56:36 -05001747 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001748
1749 if (off == 0 &&
1750 phba->sysfs_mbox.state == SMBOX_WRITING &&
1751 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1752
1753 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1754 /* Offline only */
1755 case MBX_WRITE_NV:
1756 case MBX_INIT_LINK:
1757 case MBX_DOWN_LINK:
1758 case MBX_CONFIG_LINK:
1759 case MBX_CONFIG_RING:
1760 case MBX_RESET_RING:
1761 case MBX_UNREG_LOGIN:
1762 case MBX_CLEAR_LA:
1763 case MBX_DUMP_CONTEXT:
1764 case MBX_RUN_DIAGS:
1765 case MBX_RESTART:
1766 case MBX_FLASH_WR_ULA:
1767 case MBX_SET_MASK:
1768 case MBX_SET_SLIM:
1769 case MBX_SET_DEBUG:
James Smart2e0fef82007-06-17 19:56:36 -05001770 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea31012005-04-17 16:05:31 -05001771 printk(KERN_WARNING "mbox_read:Command 0x%x "
1772 "is illegal in on-line state\n",
1773 phba->sysfs_mbox.mbox->mb.mbxCommand);
1774 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001775 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001776 return -EPERM;
1777 }
1778 case MBX_LOAD_SM:
1779 case MBX_READ_NV:
1780 case MBX_READ_CONFIG:
1781 case MBX_READ_RCONFIG:
1782 case MBX_READ_STATUS:
1783 case MBX_READ_XRI:
1784 case MBX_READ_REV:
1785 case MBX_READ_LNK_STAT:
1786 case MBX_DUMP_MEMORY:
1787 case MBX_DOWN_LOAD:
1788 case MBX_UPDATE_CFG:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001789 case MBX_KILL_BOARD:
dea31012005-04-17 16:05:31 -05001790 case MBX_LOAD_AREA:
1791 case MBX_LOAD_EXP_ROM:
Jamie Wellnitz41415862006-02-28 19:25:27 -05001792 case MBX_BEACON:
1793 case MBX_DEL_LD_ENTRY:
dea31012005-04-17 16:05:31 -05001794 break;
1795 case MBX_READ_SPARM64:
1796 case MBX_READ_LA:
1797 case MBX_READ_LA64:
1798 case MBX_REG_LOGIN:
1799 case MBX_REG_LOGIN64:
1800 case MBX_CONFIG_PORT:
1801 case MBX_RUN_BIU_DIAG:
1802 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1803 phba->sysfs_mbox.mbox->mb.mbxCommand);
1804 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001805 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001806 return -EPERM;
1807 default:
1808 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1809 phba->sysfs_mbox.mbox->mb.mbxCommand);
1810 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001811 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001812 return -EPERM;
1813 }
1814
James Smart92d7f7b2007-06-17 19:56:38 -05001815 phba->sysfs_mbox.mbox->vport = vport;
1816
James Smart2e0fef82007-06-17 19:56:36 -05001817 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
James Smart46fa3112007-04-25 09:51:45 -04001818 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_unlock_irq(&phba->hbalock);
James Smart46fa3112007-04-25 09:51:45 -04001820 return -EAGAIN;
1821 }
1822
James Smart2e0fef82007-06-17 19:56:36 -05001823 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea31012005-04-17 16:05:31 -05001824 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1825
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 (phba,
1828 phba->sysfs_mbox.mbox,
1829 MBX_POLL);
James Smart2e0fef82007-06-17 19:56:36 -05001830 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001831
1832 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001833 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001834 rc = lpfc_sli_issue_mbox_wait (phba,
1835 phba->sysfs_mbox.mbox,
James Smarta309a6b2006-08-01 07:33:43 -04001836 lpfc_mbox_tmo_val(phba,
1837 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001838 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001839 }
1840
1841 if (rc != MBX_SUCCESS) {
James Smart1dcb58e2007-04-25 09:51:30 -04001842 if (rc == MBX_TIMEOUT) {
James Smart1dcb58e2007-04-25 09:51:30 -04001843 phba->sysfs_mbox.mbox = NULL;
1844 }
dea31012005-04-17 16:05:31 -05001845 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001846 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001847 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea31012005-04-17 16:05:31 -05001848 }
1849 phba->sysfs_mbox.state = SMBOX_READING;
1850 }
1851 else if (phba->sysfs_mbox.offset != off ||
1852 phba->sysfs_mbox.state != SMBOX_READING) {
1853 printk(KERN_WARNING "mbox_read: Bad State\n");
1854 sysfs_mbox_idle(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001855 spin_unlock_irq(&phba->hbalock);
James Smart8f6d98d2006-08-01 07:34:00 -04001856 return -EAGAIN;
dea31012005-04-17 16:05:31 -05001857 }
1858
1859 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1860
1861 phba->sysfs_mbox.offset = off + count;
1862
James Smart1dcb58e2007-04-25 09:51:30 -04001863 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea31012005-04-17 16:05:31 -05001864 sysfs_mbox_idle(phba);
1865
James Smart2e0fef82007-06-17 19:56:36 -05001866 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001867
1868 return count;
1869}
1870
1871static struct bin_attribute sysfs_mbox_attr = {
1872 .attr = {
1873 .name = "mbox",
1874 .mode = S_IRUSR | S_IWUSR,
dea31012005-04-17 16:05:31 -05001875 },
James Smart1dcb58e2007-04-25 09:51:30 -04001876 .size = MAILBOX_CMD_SIZE,
dea31012005-04-17 16:05:31 -05001877 .read = sysfs_mbox_read,
1878 .write = sysfs_mbox_write,
1879};
1880
1881int
James Smart2e0fef82007-06-17 19:56:36 -05001882lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001883{
James Smart2e0fef82007-06-17 19:56:36 -05001884 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001885 int error;
1886
James Smart2e0fef82007-06-17 19:56:36 -05001887 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001888 &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001889 if (error)
1890 goto out;
1891
James Smart2e0fef82007-06-17 19:56:36 -05001892 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
James Smart92d7f7b2007-06-17 19:56:38 -05001893 &sysfs_mbox_attr);
dea31012005-04-17 16:05:31 -05001894 if (error)
1895 goto out_remove_ctlreg_attr;
1896
1897 return 0;
1898out_remove_ctlreg_attr:
James Smart2e0fef82007-06-17 19:56:36 -05001899 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001900out:
1901 return error;
1902}
1903
1904void
James Smart2e0fef82007-06-17 19:56:36 -05001905lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001906{
James Smart2e0fef82007-06-17 19:56:36 -05001907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001908
James Smart2e0fef82007-06-17 19:56:36 -05001909 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1910 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea31012005-04-17 16:05:31 -05001911}
1912
1913
1914/*
1915 * Dynamic FC Host Attributes Support
1916 */
1917
1918static void
1919lpfc_get_host_port_id(struct Scsi_Host *shost)
1920{
James Smart2e0fef82007-06-17 19:56:36 -05001921 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1922
dea31012005-04-17 16:05:31 -05001923 /* note: fc_myDID already in cpu endianness */
James Smart2e0fef82007-06-17 19:56:36 -05001924 fc_host_port_id(shost) = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001925}
1926
1927static void
1928lpfc_get_host_port_type(struct Scsi_Host *shost)
1929{
James Smart2e0fef82007-06-17 19:56:36 -05001930 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1931 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001932
1933 spin_lock_irq(shost->host_lock);
1934
James Smart92d7f7b2007-06-17 19:56:38 -05001935 if (vport->port_type == LPFC_NPIV_PORT) {
1936 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1937 } else if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001938 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -05001939 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea31012005-04-17 16:05:31 -05001940 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1941 else
1942 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1943 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001944 if (vport->fc_flag & FC_FABRIC)
dea31012005-04-17 16:05:31 -05001945 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1946 else
1947 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1948 }
1949 } else
1950 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1951
1952 spin_unlock_irq(shost->host_lock);
1953}
1954
1955static void
1956lpfc_get_host_port_state(struct Scsi_Host *shost)
1957{
James Smart2e0fef82007-06-17 19:56:36 -05001958 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001960
1961 spin_lock_irq(shost->host_lock);
1962
James Smart2e0fef82007-06-17 19:56:36 -05001963 if (vport->fc_flag & FC_OFFLINE_MODE)
dea31012005-04-17 16:05:31 -05001964 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1965 else {
James Smart2e0fef82007-06-17 19:56:36 -05001966 switch (phba->link_state) {
1967 case LPFC_LINK_UNKNOWN:
dea31012005-04-17 16:05:31 -05001968 case LPFC_LINK_DOWN:
1969 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1970 break;
1971 case LPFC_LINK_UP:
dea31012005-04-17 16:05:31 -05001972 case LPFC_CLEAR_LA:
1973 case LPFC_HBA_READY:
1974 /* Links up, beyond this port_type reports state */
1975 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1976 break;
1977 case LPFC_HBA_ERROR:
1978 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1979 break;
1980 default:
1981 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1982 break;
1983 }
1984 }
1985
1986 spin_unlock_irq(shost->host_lock);
1987}
1988
1989static void
1990lpfc_get_host_speed(struct Scsi_Host *shost)
1991{
James Smart2e0fef82007-06-17 19:56:36 -05001992 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1993 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001994
1995 spin_lock_irq(shost->host_lock);
1996
James Smart2e0fef82007-06-17 19:56:36 -05001997 if (lpfc_is_link_up(phba)) {
dea31012005-04-17 16:05:31 -05001998 switch(phba->fc_linkspeed) {
1999 case LA_1GHZ_LINK:
2000 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
2001 break;
2002 case LA_2GHZ_LINK:
2003 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
2004 break;
2005 case LA_4GHZ_LINK:
2006 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
2007 break;
James Smartb87eab32007-04-25 09:53:28 -04002008 case LA_8GHZ_LINK:
2009 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
2010 break;
dea31012005-04-17 16:05:31 -05002011 default:
2012 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
2013 break;
2014 }
2015 }
2016
2017 spin_unlock_irq(shost->host_lock);
2018}
2019
2020static void
2021lpfc_get_host_fabric_name (struct Scsi_Host *shost)
2022{
James Smart2e0fef82007-06-17 19:56:36 -05002023 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2024 struct lpfc_hba *phba = vport->phba;
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002025 u64 node_name;
dea31012005-04-17 16:05:31 -05002026
2027 spin_lock_irq(shost->host_lock);
2028
James Smart2e0fef82007-06-17 19:56:36 -05002029 if ((vport->fc_flag & FC_FABRIC) ||
dea31012005-04-17 16:05:31 -05002030 ((phba->fc_topology == TOPOLOGY_LOOP) &&
James Smart2e0fef82007-06-17 19:56:36 -05002031 (vport->fc_flag & FC_PUBLIC_LOOP)))
Andrew Morton68ce1eb2005-09-21 09:46:54 -07002032 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea31012005-04-17 16:05:31 -05002033 else
2034 /* fabric is local port if there is no F/FL_Port */
James Smart2e0fef82007-06-17 19:56:36 -05002035 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea31012005-04-17 16:05:31 -05002036
2037 spin_unlock_irq(shost->host_lock);
2038
Andrew Vasquezf631b4b2005-08-31 15:23:12 -07002039 fc_host_fabric_name(shost) = node_name;
dea31012005-04-17 16:05:31 -05002040}
2041
dea31012005-04-17 16:05:31 -05002042static struct fc_host_statistics *
2043lpfc_get_stats(struct Scsi_Host *shost)
2044{
James Smart2e0fef82007-06-17 19:56:36 -05002045 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2046 struct lpfc_hba *phba = vport->phba;
2047 struct lpfc_sli *psli = &phba->sli;
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002048 struct fc_host_statistics *hs = &phba->link_stats;
James Smart64ba8812006-08-02 15:24:34 -04002049 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea31012005-04-17 16:05:31 -05002050 LPFC_MBOXQ_t *pmboxq;
2051 MAILBOX_t *pmb;
James Smart64ba8812006-08-02 15:24:34 -04002052 unsigned long seconds;
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002053 int rc = 0;
dea31012005-04-17 16:05:31 -05002054
James Smart92d7f7b2007-06-17 19:56:38 -05002055 /*
2056 * prevent udev from issuing mailbox commands until the port is
2057 * configured.
2058 */
James Smart2e0fef82007-06-17 19:56:36 -05002059 if (phba->link_state < LPFC_LINK_DOWN ||
2060 !phba->mbox_mem_pool ||
2061 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002062 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002063
2064 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002065 return NULL;
2066
dea31012005-04-17 16:05:31 -05002067 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2068 if (!pmboxq)
2069 return NULL;
2070 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
2071
2072 pmb = &pmboxq->mb;
2073 pmb->mbxCommand = MBX_READ_STATUS;
2074 pmb->mbxOwner = OWN_HOST;
2075 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002076 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002077
James Smart2e0fef82007-06-17 19:56:36 -05002078 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002079 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002080 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002081 else
dea31012005-04-17 16:05:31 -05002082 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2083
2084 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002085 if (rc != MBX_TIMEOUT)
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002086 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002087 return NULL;
2088 }
2089
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -04002090 memset(hs, 0, sizeof (struct fc_host_statistics));
2091
dea31012005-04-17 16:05:31 -05002092 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
2093 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
2094 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
2095 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
2096
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002097 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea31012005-04-17 16:05:31 -05002098 pmb->mbxCommand = MBX_READ_LNK_STAT;
2099 pmb->mbxOwner = OWN_HOST;
2100 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002101 pmboxq->vport = vport;
dea31012005-04-17 16:05:31 -05002102
James Smart2e0fef82007-06-17 19:56:36 -05002103 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002104 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea31012005-04-17 16:05:31 -05002105 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
James.Smart@Emulex.Com433c3572005-10-28 20:28:56 -04002106 else
dea31012005-04-17 16:05:31 -05002107 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2108
2109 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002110 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05002111 mempool_free(pmboxq, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002112 return NULL;
2113 }
2114
2115 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2116 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2117 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2118 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2119 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2120 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2121 hs->error_frames = pmb->un.varRdLnk.crcCnt;
2122
James Smart64ba8812006-08-02 15:24:34 -04002123 hs->link_failure_count -= lso->link_failure_count;
2124 hs->loss_of_sync_count -= lso->loss_of_sync_count;
2125 hs->loss_of_signal_count -= lso->loss_of_signal_count;
2126 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
2127 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
2128 hs->invalid_crc_count -= lso->invalid_crc_count;
2129 hs->error_frames -= lso->error_frames;
2130
dea31012005-04-17 16:05:31 -05002131 if (phba->fc_topology == TOPOLOGY_LOOP) {
2132 hs->lip_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002133 hs->lip_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002134 hs->nos_count = -1;
2135 } else {
2136 hs->lip_count = -1;
2137 hs->nos_count = (phba->fc_eventTag >> 1);
James Smart64ba8812006-08-02 15:24:34 -04002138 hs->nos_count -= lso->link_events;
dea31012005-04-17 16:05:31 -05002139 }
2140
2141 hs->dumped_frames = -1;
2142
James Smart64ba8812006-08-02 15:24:34 -04002143 seconds = get_seconds();
2144 if (seconds < psli->stats_start)
2145 hs->seconds_since_last_reset = seconds +
2146 ((unsigned long)-1 - psli->stats_start);
2147 else
2148 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea31012005-04-17 16:05:31 -05002149
James Smart1dcb58e2007-04-25 09:51:30 -04002150 mempool_free(pmboxq, phba->mbox_mem_pool);
2151
dea31012005-04-17 16:05:31 -05002152 return hs;
2153}
2154
James Smart64ba8812006-08-02 15:24:34 -04002155static void
2156lpfc_reset_stats(struct Scsi_Host *shost)
2157{
James Smart2e0fef82007-06-17 19:56:36 -05002158 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
2159 struct lpfc_hba *phba = vport->phba;
2160 struct lpfc_sli *psli = &phba->sli;
2161 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
James Smart64ba8812006-08-02 15:24:34 -04002162 LPFC_MBOXQ_t *pmboxq;
2163 MAILBOX_t *pmb;
2164 int rc = 0;
2165
James Smart2e0fef82007-06-17 19:56:36 -05002166 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
James Smart46fa3112007-04-25 09:51:45 -04002167 return;
2168
James Smart64ba8812006-08-02 15:24:34 -04002169 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2170 if (!pmboxq)
2171 return;
2172 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2173
2174 pmb = &pmboxq->mb;
2175 pmb->mbxCommand = MBX_READ_STATUS;
2176 pmb->mbxOwner = OWN_HOST;
2177 pmb->un.varWords[0] = 0x1; /* reset request */
2178 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002179 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002180
James Smart2e0fef82007-06-17 19:56:36 -05002181 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002182 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2183 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2184 else
2185 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2186
2187 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002188 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002189 mempool_free(pmboxq, phba->mbox_mem_pool);
2190 return;
2191 }
2192
2193 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
2194 pmb->mbxCommand = MBX_READ_LNK_STAT;
2195 pmb->mbxOwner = OWN_HOST;
2196 pmboxq->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05002197 pmboxq->vport = vport;
James Smart64ba8812006-08-02 15:24:34 -04002198
James Smart2e0fef82007-06-17 19:56:36 -05002199 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
James Smart64ba8812006-08-02 15:24:34 -04002200 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
2201 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
2202 else
2203 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
2204
2205 if (rc != MBX_SUCCESS) {
James Smart858c9f62007-06-17 19:56:39 -05002206 if (rc != MBX_TIMEOUT)
James Smart64ba8812006-08-02 15:24:34 -04002207 mempool_free( pmboxq, phba->mbox_mem_pool);
2208 return;
2209 }
2210
2211 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
2212 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
2213 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
2214 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
2215 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
2216 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
2217 lso->error_frames = pmb->un.varRdLnk.crcCnt;
2218 lso->link_events = (phba->fc_eventTag >> 1);
2219
2220 psli->stats_start = get_seconds();
2221
James Smart1dcb58e2007-04-25 09:51:30 -04002222 mempool_free(pmboxq, phba->mbox_mem_pool);
2223
James Smart64ba8812006-08-02 15:24:34 -04002224 return;
2225}
dea31012005-04-17 16:05:31 -05002226
2227/*
2228 * The LPFC driver treats linkdown handling as target loss events so there
2229 * are no sysfs handlers for link_down_tmo.
2230 */
James Smart685f0bf2007-04-25 09:53:08 -04002231
2232static struct lpfc_nodelist *
2233lpfc_get_node_by_target(struct scsi_target *starget)
dea31012005-04-17 16:05:31 -05002234{
James Smart2e0fef82007-06-17 19:56:36 -05002235 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
2236 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
James Smart685f0bf2007-04-25 09:53:08 -04002237 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002238
2239 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002240 /* Search for this, mapped, target ID */
James Smart2e0fef82007-06-17 19:56:36 -05002241 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002242 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
2243 starget->id == ndlp->nlp_sid) {
2244 spin_unlock_irq(shost->host_lock);
2245 return ndlp;
dea31012005-04-17 16:05:31 -05002246 }
2247 }
2248 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002249 return NULL;
2250}
dea31012005-04-17 16:05:31 -05002251
James Smart685f0bf2007-04-25 09:53:08 -04002252static void
2253lpfc_get_starget_port_id(struct scsi_target *starget)
2254{
2255 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
2256
2257 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea31012005-04-17 16:05:31 -05002258}
2259
2260static void
2261lpfc_get_starget_node_name(struct scsi_target *starget)
2262{
James Smart685f0bf2007-04-25 09:53:08 -04002263 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002264
James Smart685f0bf2007-04-25 09:53:08 -04002265 fc_starget_node_name(starget) =
2266 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002267}
2268
2269static void
2270lpfc_get_starget_port_name(struct scsi_target *starget)
2271{
James Smart685f0bf2007-04-25 09:53:08 -04002272 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea31012005-04-17 16:05:31 -05002273
James Smart685f0bf2007-04-25 09:53:08 -04002274 fc_starget_port_name(starget) =
2275 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea31012005-04-17 16:05:31 -05002276}
2277
2278static void
dea31012005-04-17 16:05:31 -05002279lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2280{
dea31012005-04-17 16:05:31 -05002281 if (timeout)
James Smartc01f3202006-08-18 17:47:08 -04002282 rport->dev_loss_tmo = timeout;
dea31012005-04-17 16:05:31 -05002283 else
James Smartc01f3202006-08-18 17:47:08 -04002284 rport->dev_loss_tmo = 1;
dea31012005-04-17 16:05:31 -05002285}
2286
2287
2288#define lpfc_rport_show_function(field, format_string, sz, cast) \
2289static ssize_t \
2290lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
2291{ \
2292 struct fc_rport *rport = transport_class_to_rport(cdev); \
2293 struct lpfc_rport_data *rdata = rport->hostdata; \
2294 return snprintf(buf, sz, format_string, \
2295 (rdata->target) ? cast rdata->target->field : 0); \
2296}
2297
2298#define lpfc_rport_rd_attr(field, format_string, sz) \
2299 lpfc_rport_show_function(field, format_string, sz, ) \
2300static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
2301
2302
2303struct fc_function_template lpfc_transport_functions = {
2304 /* fixed attributes the driver supports */
2305 .show_host_node_name = 1,
2306 .show_host_port_name = 1,
2307 .show_host_supported_classes = 1,
2308 .show_host_supported_fc4s = 1,
dea31012005-04-17 16:05:31 -05002309 .show_host_supported_speeds = 1,
2310 .show_host_maxframe_size = 1,
2311
2312 /* dynamic attributes the driver supports */
2313 .get_host_port_id = lpfc_get_host_port_id,
2314 .show_host_port_id = 1,
2315
2316 .get_host_port_type = lpfc_get_host_port_type,
2317 .show_host_port_type = 1,
2318
2319 .get_host_port_state = lpfc_get_host_port_state,
2320 .show_host_port_state = 1,
2321
2322 /* active_fc4s is shown but doesn't change (thus no get function) */
2323 .show_host_active_fc4s = 1,
2324
2325 .get_host_speed = lpfc_get_host_speed,
2326 .show_host_speed = 1,
2327
2328 .get_host_fabric_name = lpfc_get_host_fabric_name,
2329 .show_host_fabric_name = 1,
2330
2331 /*
2332 * The LPFC driver treats linkdown handling as target loss events
2333 * so there are no sysfs handlers for link_down_tmo.
2334 */
2335
2336 .get_fc_host_stats = lpfc_get_stats,
James Smart64ba8812006-08-02 15:24:34 -04002337 .reset_fc_host_stats = lpfc_reset_stats,
dea31012005-04-17 16:05:31 -05002338
2339 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2340 .show_rport_maxframe_size = 1,
2341 .show_rport_supported_classes = 1,
2342
dea31012005-04-17 16:05:31 -05002343 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2344 .show_rport_dev_loss_tmo = 1,
2345
2346 .get_starget_port_id = lpfc_get_starget_port_id,
2347 .show_starget_port_id = 1,
2348
2349 .get_starget_node_name = lpfc_get_starget_node_name,
2350 .show_starget_node_name = 1,
2351
2352 .get_starget_port_name = lpfc_get_starget_port_name,
2353 .show_starget_port_name = 1,
Andrew Vasquez91ca7b02005-10-27 16:03:37 -07002354
2355 .issue_fc_host_lip = lpfc_issue_lip,
James Smartc01f3202006-08-18 17:47:08 -04002356 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2357 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002358
2359 .vport_create = lpfc_vport_create,
2360 .vport_delete = lpfc_vport_delete,
2361 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2362};
2363
2364struct fc_function_template lpfc_vport_transport_functions = {
2365 /* fixed attributes the driver supports */
2366 .show_host_node_name = 1,
2367 .show_host_port_name = 1,
2368 .show_host_supported_classes = 1,
2369 .show_host_supported_fc4s = 1,
2370 .show_host_supported_speeds = 1,
2371 .show_host_maxframe_size = 1,
2372
2373 /* dynamic attributes the driver supports */
2374 .get_host_port_id = lpfc_get_host_port_id,
2375 .show_host_port_id = 1,
2376
2377 .get_host_port_type = lpfc_get_host_port_type,
2378 .show_host_port_type = 1,
2379
2380 .get_host_port_state = lpfc_get_host_port_state,
2381 .show_host_port_state = 1,
2382
2383 /* active_fc4s is shown but doesn't change (thus no get function) */
2384 .show_host_active_fc4s = 1,
2385
2386 .get_host_speed = lpfc_get_host_speed,
2387 .show_host_speed = 1,
2388
2389 .get_host_fabric_name = lpfc_get_host_fabric_name,
2390 .show_host_fabric_name = 1,
dea31012005-04-17 16:05:31 -05002391
2392 /*
2393 * The LPFC driver treats linkdown handling as target loss events
2394 * so there are no sysfs handlers for link_down_tmo.
2395 */
2396
2397 .get_fc_host_stats = lpfc_get_stats,
2398 .reset_fc_host_stats = lpfc_reset_stats,
2399
2400 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2401 .show_rport_maxframe_size = 1,
2402 .show_rport_supported_classes = 1,
2403
2404 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2405 .show_rport_dev_loss_tmo = 1,
2406
2407 .get_starget_port_id = lpfc_get_starget_port_id,
2408 .show_starget_port_id = 1,
2409
2410 .get_starget_node_name = lpfc_get_starget_node_name,
2411 .show_starget_node_name = 1,
2412
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002413 .get_starget_port_name = lpfc_get_starget_port_name,
2414 .show_starget_port_name = 1,
2415
Jamie Wellnitzcf5bf972006-02-28 22:33:08 -05002416 .issue_fc_host_lip = lpfc_issue_lip,
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002417 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2418 .terminate_rport_io = lpfc_terminate_rport_io,
James Smart92d7f7b2007-06-17 19:56:38 -05002419
2420 .vport_disable = lpfc_vport_disable,
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002421};
2422
2423void
2424lpfc_get_cfgparam(struct lpfc_hba *phba)
2425{
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002426 lpfc_cr_delay_init(phba, lpfc_cr_delay);
2427 lpfc_cr_count_init(phba, lpfc_cr_count);
2428 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
James Smarta4bc3372006-12-02 13:34:16 -05002429 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
2430 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002431 lpfc_ack0_init(phba, lpfc_ack0);
2432 lpfc_topology_init(phba, lpfc_topology);
James.Smart@Emulex.Com7bcbb752005-10-28 20:29:13 -04002433 lpfc_link_speed_init(phba, lpfc_link_speed);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002434 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
James Smart858c9f62007-06-17 19:56:39 -05002435 lpfc_npiv_enable_init(phba, lpfc_npiv_enable);
James Smart4ff43242006-12-02 13:34:56 -05002436 lpfc_use_msi_init(phba, lpfc_use_msi);
James.Smart@Emulex.Com875fbdf2005-11-29 16:32:13 -05002437 phba->cfg_poll = lpfc_poll;
James Smarta12e07b2006-12-02 13:35:30 -05002438 phba->cfg_soft_wwnn = 0L;
James Smartc3f28af2006-08-18 17:47:18 -04002439 phba->cfg_soft_wwpn = 0L;
dea31012005-04-17 16:05:31 -05002440 /*
2441 * The total number of segments is the configuration value plus 2
2442 * since the IOCB need a command and response bde.
2443 */
2444 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
dea31012005-04-17 16:05:31 -05002445 /*
2446 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
2447 * used to create the sg_dma_buf_pool must be dynamically calculated
2448 */
2449 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
2450 sizeof(struct fcp_rsp) +
2451 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
James Smart7054a602007-04-25 09:52:34 -04002452 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
James Smart3de2a652007-08-02 11:09:59 -04002453 return;
2454}
Jamie Wellnitzb28485a2006-02-28 19:25:21 -05002455
James Smart3de2a652007-08-02 11:09:59 -04002456void
2457lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
2458{
James Smarte8b62012007-08-02 11:10:09 -04002459 lpfc_log_verbose_init(vport, lpfc_log_verbose);
James Smart3de2a652007-08-02 11:09:59 -04002460 lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
2461 lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
2462 lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
2463 lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
2464 lpfc_restrict_login_init(vport, lpfc_restrict_login);
2465 lpfc_fcp_class_init(vport, lpfc_fcp_class);
2466 lpfc_use_adisc_init(vport, lpfc_use_adisc);
2467 lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
2468 lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
2469 lpfc_max_luns_init(vport, lpfc_max_luns);
2470 lpfc_scan_down_init(vport, lpfc_scan_down);
dea31012005-04-17 16:05:31 -05002471 return;
2472}