[SCSI] lpfc: NPIV: split ports
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / lpfc / lpfc_attr.c
CommitLineData
dea3101e
JB
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
9413afff 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e
JB
8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * 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. *
dea3101e
JB
20 *******************************************************************/
21
dea3101e 22#include <linux/ctype.h>
46fa311e 23#include <linux/delay.h>
dea3101e
JB
24#include <linux/pci.h>
25#include <linux/interrupt.h>
26
91886523 27#include <scsi/scsi.h>
dea3101e
JB
28#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"
42
c01f3208
JS
43#define LPFC_DEF_DEVLOSS_TMO 30
44#define LPFC_MIN_DEVLOSS_TMO 1
45#define LPFC_MAX_DEVLOSS_TMO 255
dea3101e
JB
46
47static void
48lpfc_jedec_to_ascii(int incr, char hdw[])
49{
50 int i, j;
51 for (i = 0; i < 8; i++) {
52 j = (incr & 0xf);
53 if (j <= 9)
54 hdw[7 - i] = 0x30 + j;
55 else
56 hdw[7 - i] = 0x61 + j - 10;
57 incr = (incr >> 4);
58 }
59 hdw[8] = 0;
60 return;
61}
62
63static ssize_t
64lpfc_drvr_version_show(struct class_device *cdev, char *buf)
65{
66 return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
67}
68
69static ssize_t
70management_version_show(struct class_device *cdev, char *buf)
71{
72 return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
73}
74
75static ssize_t
76lpfc_info_show(struct class_device *cdev, char *buf)
77{
78 struct Scsi_Host *host = class_to_shost(cdev);
2e0fef85 79
dea3101e
JB
80 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
81}
82
83static ssize_t
84lpfc_serialnum_show(struct class_device *cdev, char *buf)
85{
2e0fef85
JS
86 struct Scsi_Host *shost = class_to_shost(cdev);
87 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
88 struct lpfc_hba *phba = vport->phba;
89
dea3101e
JB
90 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
91}
92
93static ssize_t
94lpfc_modeldesc_show(struct class_device *cdev, char *buf)
95{
2e0fef85
JS
96 struct Scsi_Host *shost = class_to_shost(cdev);
97 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
98 struct lpfc_hba *phba = vport->phba;
99
dea3101e
JB
100 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
101}
102
103static ssize_t
104lpfc_modelname_show(struct class_device *cdev, char *buf)
105{
2e0fef85
JS
106 struct Scsi_Host *shost = class_to_shost(cdev);
107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
108 struct lpfc_hba *phba = vport->phba;
109
dea3101e
JB
110 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
111}
112
113static ssize_t
114lpfc_programtype_show(struct class_device *cdev, char *buf)
115{
2e0fef85
JS
116 struct Scsi_Host *shost = class_to_shost(cdev);
117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
118 struct lpfc_hba *phba = vport->phba;
119
dea3101e
JB
120 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
121}
122
123static ssize_t
2e0fef85 124lpfc_vportnum_show(struct class_device *cdev, char *buf)
dea3101e 125{
2e0fef85
JS
126 struct Scsi_Host *shost = class_to_shost(cdev);
127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
128 struct lpfc_hba *phba = vport->phba;
129
dea3101e
JB
130 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
131}
132
133static ssize_t
134lpfc_fwrev_show(struct class_device *cdev, char *buf)
135{
2e0fef85
JS
136 struct Scsi_Host *shost = class_to_shost(cdev);
137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
138 struct lpfc_hba *phba = vport->phba;
dea3101e 139 char fwrev[32];
2e0fef85 140
dea3101e
JB
141 lpfc_decode_firmware_rev(phba, fwrev, 1);
142 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
143}
144
145static ssize_t
146lpfc_hdw_show(struct class_device *cdev, char *buf)
147{
148 char hdw[9];
2e0fef85
JS
149 struct Scsi_Host *shost = class_to_shost(cdev);
150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
dea3101e 152 lpfc_vpd_t *vp = &phba->vpd;
2e0fef85 153
dea3101e
JB
154 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
155 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
156}
157static ssize_t
158lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
159{
2e0fef85
JS
160 struct Scsi_Host *shost = class_to_shost(cdev);
161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
162 struct lpfc_hba *phba = vport->phba;
163
dea3101e
JB
164 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
165}
166static ssize_t
167lpfc_state_show(struct class_device *cdev, char *buf)
168{
2e0fef85
JS
169 struct Scsi_Host *shost = class_to_shost(cdev);
170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
171 struct lpfc_hba *phba = vport->phba;
172 int len = 0;
173
174 switch (phba->link_state) {
175 case LPFC_LINK_UNKNOWN:
41415862 176 case LPFC_WARM_START:
dea3101e
JB
177 case LPFC_INIT_START:
178 case LPFC_INIT_MBX_CMDS:
179 case LPFC_LINK_DOWN:
2e0fef85
JS
180 case LPFC_HBA_ERROR:
181 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down");
dea3101e
JB
182 break;
183 case LPFC_LINK_UP:
dea3101e 184 case LPFC_CLEAR_LA:
2e0fef85
JS
185 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
186
187 switch (vport->port_state) {
188 len += snprintf(buf + len, PAGE_SIZE-len,
189 "initializing\n");
190 break;
191 case LPFC_LOCAL_CFG_LINK:
192 len += snprintf(buf + len, PAGE_SIZE-len,
193 "configuring\n");
194 break;
195 case LPFC_FLOGI:
196 case LPFC_FABRIC_CFG_LINK:
197 case LPFC_NS_REG:
198 case LPFC_NS_QRY:
199 case LPFC_BUILD_DISC_LIST:
200 case LPFC_DISC_AUTH:
201 len += snprintf(buf + len, PAGE_SIZE - len,
202 "Discovery\n");
203 break;
204 case LPFC_VPORT_READY:
205 len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
206 break;
207
208 case LPFC_STATE_UNKNOWN:
209 len += snprintf(buf + len, PAGE_SIZE - len,
210 "Unknown\n");
211 break;
212 }
213
dea3101e 214 if (phba->fc_topology == TOPOLOGY_LOOP) {
2e0fef85 215 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e
JB
216 len += snprintf(buf + len, PAGE_SIZE-len,
217 " Public Loop\n");
218 else
219 len += snprintf(buf + len, PAGE_SIZE-len,
220 " Private Loop\n");
221 } else {
2e0fef85 222 if (vport->fc_flag & FC_FABRIC)
dea3101e
JB
223 len += snprintf(buf + len, PAGE_SIZE-len,
224 " Fabric\n");
225 else
226 len += snprintf(buf + len, PAGE_SIZE-len,
227 " Point-2-Point\n");
228 }
229 }
2e0fef85 230
dea3101e
JB
231 return len;
232}
233
234static ssize_t
235lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
236{
2e0fef85
JS
237 struct Scsi_Host *shost = class_to_shost(cdev);
238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
239
240 return snprintf(buf, PAGE_SIZE, "%d\n",
241 vport->fc_map_cnt + vport->fc_unmap_cnt);
dea3101e
JB
242}
243
244
91ca7b01 245static int
2e0fef85 246lpfc_issue_lip(struct Scsi_Host *shost)
dea3101e 247{
2e0fef85
JS
248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
249 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
250 LPFC_MBOXQ_t *pmboxq;
251 int mbxstatus = MBXERR_ERROR;
252
2e0fef85
JS
253 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
254 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
255 (vport->port_state != LPFC_VPORT_READY))
dea3101e
JB
256 return -EPERM;
257
258 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
259
260 if (!pmboxq)
261 return -ENOMEM;
262
263 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
4db621e0
JS
264 pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
265 pmboxq->mb.mbxOwner = OWN_HOST;
266
33ccf8d1 267 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
dea3101e 268
4db621e0
JS
269 if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
270 memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
271 lpfc_init_link(phba, pmboxq, phba->cfg_topology,
272 phba->cfg_link_speed);
273 mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
274 phba->fc_ratov * 2);
275 }
276
5b8bd0c9 277 lpfc_set_loopback_flag(phba);
dea3101e
JB
278 if (mbxstatus == MBX_TIMEOUT)
279 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
280 else
433c3579 281 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
282
283 if (mbxstatus == MBXERR_ERROR)
284 return -EIO;
285
91ca7b01 286 return 0;
dea3101e
JB
287}
288
40496f07 289static int
46fa311e 290lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
40496f07
JS
291{
292 struct completion online_compl;
46fa311e
JS
293 struct lpfc_sli_ring *pring;
294 struct lpfc_sli *psli;
40496f07 295 int status = 0;
46fa311e
JS
296 int cnt = 0;
297 int i;
40496f07
JS
298
299 init_completion(&online_compl);
300 lpfc_workq_post_event(phba, &status, &online_compl,
46fa311e
JS
301 LPFC_EVT_OFFLINE_PREP);
302 wait_for_completion(&online_compl);
303
304 if (status != 0)
305 return -EIO;
306
307 psli = &phba->sli;
308
309 for (i = 0; i < psli->num_rings; i++) {
310 pring = &psli->ring[i];
311 /* The linkdown event takes 30 seconds to timeout. */
312 while (pring->txcmplq_cnt) {
313 msleep(10);
314 if (cnt++ > 3000) {
315 lpfc_printf_log(phba,
316 KERN_WARNING, LOG_INIT,
317 "%d:0466 Outstanding IO when "
318 "bringing Adapter offline\n",
319 phba->brd_no);
320 break;
321 }
322 }
323 }
324
325 init_completion(&online_compl);
326 lpfc_workq_post_event(phba, &status, &online_compl, type);
40496f07
JS
327 wait_for_completion(&online_compl);
328
329 if (status != 0)
330 return -EIO;
331
46fa311e
JS
332 return 0;
333}
334
335static int
336lpfc_selective_reset(struct lpfc_hba *phba)
337{
338 struct completion online_compl;
339 int status = 0;
340
341 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
342
343 if (status != 0)
344 return status;
345
40496f07
JS
346 init_completion(&online_compl);
347 lpfc_workq_post_event(phba, &status, &online_compl,
348 LPFC_EVT_ONLINE);
349 wait_for_completion(&online_compl);
350
351 if (status != 0)
352 return -EIO;
353
354 return 0;
355}
356
357static ssize_t
358lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
359{
2e0fef85
JS
360 struct Scsi_Host *shost = class_to_shost(cdev);
361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
362 struct lpfc_hba *phba = vport->phba;
363
40496f07
JS
364 int status = -EINVAL;
365
366 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
367 status = lpfc_selective_reset(phba);
368
369 if (status == 0)
370 return strlen(buf);
371 else
372 return status;
373}
374
dea3101e
JB
375static ssize_t
376lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
377{
2e0fef85
JS
378 struct Scsi_Host *shost = class_to_shost(cdev);
379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
380 struct lpfc_hba *phba = vport->phba;
381
dea3101e
JB
382 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
383}
384
41415862
JW
385static ssize_t
386lpfc_board_mode_show(struct class_device *cdev, char *buf)
387{
2e0fef85
JS
388 struct Scsi_Host *shost = class_to_shost(cdev);
389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
41415862
JW
391 char * state;
392
2e0fef85 393 if (phba->link_state == LPFC_HBA_ERROR)
41415862 394 state = "error";
2e0fef85 395 else if (phba->link_state == LPFC_WARM_START)
41415862 396 state = "warm start";
2e0fef85 397 else if (phba->link_state == LPFC_INIT_START)
41415862
JW
398 state = "offline";
399 else
400 state = "online";
401
402 return snprintf(buf, PAGE_SIZE, "%s\n", state);
403}
404
405static ssize_t
406lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
407{
2e0fef85
JS
408 struct Scsi_Host *shost = class_to_shost(cdev);
409 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
410 struct lpfc_hba *phba = vport->phba;
41415862
JW
411 struct completion online_compl;
412 int status=0;
413
414 init_completion(&online_compl);
415
46fa311e 416 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
41415862
JW
417 lpfc_workq_post_event(phba, &status, &online_compl,
418 LPFC_EVT_ONLINE);
46fa311e
JS
419 wait_for_completion(&online_compl);
420 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
421 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
41415862 422 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
46fa311e
JS
423 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
424 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
425 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
41415862
JW
426 else
427 return -EINVAL;
428
41415862
JW
429 if (!status)
430 return strlen(buf);
431 else
432 return -EIO;
433}
434
875fbdfe
JSEC
435static ssize_t
436lpfc_poll_show(struct class_device *cdev, char *buf)
437{
2e0fef85
JS
438 struct Scsi_Host *shost = class_to_shost(cdev);
439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
440 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
441
442 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
443}
444
445static ssize_t
446lpfc_poll_store(struct class_device *cdev, const char *buf,
447 size_t count)
448{
2e0fef85
JS
449 struct Scsi_Host *shost = class_to_shost(cdev);
450 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
451 struct lpfc_hba *phba = vport->phba;
875fbdfe
JSEC
452 uint32_t creg_val;
453 uint32_t old_val;
454 int val=0;
455
456 if (!isdigit(buf[0]))
457 return -EINVAL;
458
459 if (sscanf(buf, "%i", &val) != 1)
460 return -EINVAL;
461
462 if ((val & 0x3) != val)
463 return -EINVAL;
464
2e0fef85 465 spin_lock_irq(&phba->hbalock);
875fbdfe
JSEC
466
467 old_val = phba->cfg_poll;
468
469 if (val & ENABLE_FCP_RING_POLLING) {
470 if ((val & DISABLE_FCP_RING_INT) &&
471 !(old_val & DISABLE_FCP_RING_INT)) {
472 creg_val = readl(phba->HCregaddr);
473 creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
474 writel(creg_val, phba->HCregaddr);
475 readl(phba->HCregaddr); /* flush */
476
477 lpfc_poll_start_timer(phba);
478 }
479 } else if (val != 0x0) {
2e0fef85 480 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
481 return -EINVAL;
482 }
483
484 if (!(val & DISABLE_FCP_RING_INT) &&
485 (old_val & DISABLE_FCP_RING_INT))
486 {
2e0fef85 487 spin_unlock_irq(&phba->hbalock);
875fbdfe 488 del_timer(&phba->fcp_poll_timer);
2e0fef85 489 spin_lock_irq(&phba->hbalock);
875fbdfe
JSEC
490 creg_val = readl(phba->HCregaddr);
491 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
492 writel(creg_val, phba->HCregaddr);
493 readl(phba->HCregaddr); /* flush */
494 }
495
496 phba->cfg_poll = val;
497
2e0fef85 498 spin_unlock_irq(&phba->hbalock);
875fbdfe
JSEC
499
500 return strlen(buf);
501}
dea3101e
JB
502
503#define lpfc_param_show(attr) \
504static ssize_t \
505lpfc_##attr##_show(struct class_device *cdev, char *buf) \
506{ \
2e0fef85
JS
507 struct Scsi_Host *shost = class_to_shost(cdev);\
508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
509 struct lpfc_hba *phba = vport->phba;\
dea3101e 510 int val = 0;\
7bcbb752
JSEC
511 val = phba->cfg_##attr;\
512 return snprintf(buf, PAGE_SIZE, "%d\n",\
513 phba->cfg_##attr);\
514}
515
93a20f74
JSEC
516#define lpfc_param_hex_show(attr) \
517static ssize_t \
518lpfc_##attr##_show(struct class_device *cdev, char *buf) \
519{ \
2e0fef85
JS
520 struct Scsi_Host *shost = class_to_shost(cdev);\
521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
522 struct lpfc_hba *phba = vport->phba;\
93a20f74
JSEC
523 int val = 0;\
524 val = phba->cfg_##attr;\
525 return snprintf(buf, PAGE_SIZE, "%#x\n",\
526 phba->cfg_##attr);\
527}
528
7bcbb752
JSEC
529#define lpfc_param_init(attr, default, minval, maxval) \
530static int \
531lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
532{ \
533 if (val >= minval && val <= maxval) {\
534 phba->cfg_##attr = val;\
535 return 0;\
dea3101e 536 }\
7bcbb752
JSEC
537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
538 "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
539 "allowed range is ["#minval", "#maxval"]\n", \
540 phba->brd_no, val); \
541 phba->cfg_##attr = default;\
542 return -EINVAL;\
dea3101e
JB
543}
544
7bcbb752
JSEC
545#define lpfc_param_set(attr, default, minval, maxval) \
546static int \
547lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
548{ \
549 if (val >= minval && val <= maxval) {\
550 phba->cfg_##attr = val;\
551 return 0;\
552 }\
553 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
554 "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
555 "allowed range is ["#minval", "#maxval"]\n", \
556 phba->brd_no, val); \
557 return -EINVAL;\
558}
559
560#define lpfc_param_store(attr) \
dea3101e
JB
561static ssize_t \
562lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
563{ \
2e0fef85
JS
564 struct Scsi_Host *shost = class_to_shost(cdev);\
565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
566 struct lpfc_hba *phba = vport->phba;\
7bcbb752 567 int val=0;\
93a20f74
JSEC
568 if (!isdigit(buf[0]))\
569 return -EINVAL;\
570 if (sscanf(buf, "%i", &val) != 1)\
571 return -EINVAL;\
7bcbb752 572 if (lpfc_##attr##_set(phba, val) == 0) \
755c0d06 573 return strlen(buf);\
7bcbb752
JSEC
574 else \
575 return -EINVAL;\
dea3101e
JB
576}
577
7bcbb752
JSEC
578#define LPFC_ATTR(name, defval, minval, maxval, desc) \
579static int lpfc_##name = defval;\
dea3101e
JB
580module_param(lpfc_##name, int, 0);\
581MODULE_PARM_DESC(lpfc_##name, desc);\
7bcbb752 582lpfc_param_init(name, defval, minval, maxval)
dea3101e
JB
583
584#define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
585static int lpfc_##name = defval;\
586module_param(lpfc_##name, int, 0);\
587MODULE_PARM_DESC(lpfc_##name, desc);\
588lpfc_param_show(name)\
7bcbb752 589lpfc_param_init(name, defval, minval, maxval)\
dea3101e
JB
590static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
591
592#define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
593static int lpfc_##name = defval;\
594module_param(lpfc_##name, int, 0);\
595MODULE_PARM_DESC(lpfc_##name, desc);\
596lpfc_param_show(name)\
7bcbb752
JSEC
597lpfc_param_init(name, defval, minval, maxval)\
598lpfc_param_set(name, defval, minval, maxval)\
599lpfc_param_store(name)\
dea3101e
JB
600static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
601 lpfc_##name##_show, lpfc_##name##_store)
602
93a20f74
JSEC
603#define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
604static int lpfc_##name = defval;\
605module_param(lpfc_##name, int, 0);\
606MODULE_PARM_DESC(lpfc_##name, desc);\
607lpfc_param_hex_show(name)\
608lpfc_param_init(name, defval, minval, maxval)\
609static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
610
611#define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
612static int lpfc_##name = defval;\
613module_param(lpfc_##name, int, 0);\
614MODULE_PARM_DESC(lpfc_##name, desc);\
615lpfc_param_hex_show(name)\
616lpfc_param_init(name, defval, minval, maxval)\
617lpfc_param_set(name, defval, minval, maxval)\
618lpfc_param_store(name)\
619static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
620 lpfc_##name##_show, lpfc_##name##_store)
621
dea3101e
JB
622static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
623static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
624static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
625static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
626static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
2e0fef85 627static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
dea3101e
JB
628static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
629static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
630static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
631static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
632 lpfc_option_rom_version_show, NULL);
633static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
634 lpfc_num_discovered_ports_show, NULL);
635static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
636static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
637 NULL);
638static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
639 NULL);
41415862
JW
640static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
641 lpfc_board_mode_show, lpfc_board_mode_store);
40496f07 642static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
dea3101e 643
c3f28afa 644
a12e07bc 645static char *lpfc_soft_wwn_key = "C99G71SL8032A";
c3f28afa
JS
646
647static ssize_t
a12e07bc 648lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
c3f28afa
JS
649 size_t count)
650{
2e0fef85
JS
651 struct Scsi_Host *shost = class_to_shost(cdev);
652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
653 struct lpfc_hba *phba = vport->phba;
c3f28afa
JS
654 unsigned int cnt = count;
655
656 /*
657 * We're doing a simple sanity check for soft_wwpn setting.
658 * We require that the user write a specific key to enable
659 * the soft_wwpn attribute to be settable. Once the attribute
660 * is written, the enable key resets. If further updates are
661 * desired, the key must be written again to re-enable the
662 * attribute.
663 *
664 * The "key" is not secret - it is a hardcoded string shown
665 * here. The intent is to protect against the random user or
666 * application that is just writing attributes.
667 */
668
669 /* count may include a LF at end of string */
670 if (buf[cnt-1] == '\n')
671 cnt--;
672
a12e07bc
JS
673 if ((cnt != strlen(lpfc_soft_wwn_key)) ||
674 (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
c3f28afa
JS
675 return -EINVAL;
676
a12e07bc 677 phba->soft_wwn_enable = 1;
c3f28afa
JS
678 return count;
679}
a12e07bc
JS
680static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
681 lpfc_soft_wwn_enable_store);
c3f28afa
JS
682
683static ssize_t
684lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
685{
2e0fef85
JS
686 struct Scsi_Host *shost = class_to_shost(cdev);
687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
688 struct lpfc_hba *phba = vport->phba;
689
afc071e6
RD
690 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
691 (unsigned long long)phba->cfg_soft_wwpn);
c3f28afa
JS
692}
693
694
695static ssize_t
696lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
697{
2e0fef85
JS
698 struct Scsi_Host *shost = class_to_shost(cdev);
699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
700 struct lpfc_hba *phba = vport->phba;
c3f28afa
JS
701 struct completion online_compl;
702 int stat1=0, stat2=0;
703 unsigned int i, j, cnt=count;
704 u8 wwpn[8];
705
706 /* count may include a LF at end of string */
707 if (buf[cnt-1] == '\n')
708 cnt--;
709
a12e07bc 710 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
c3f28afa
JS
711 ((cnt == 17) && (*buf++ != 'x')) ||
712 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
713 return -EINVAL;
714
a12e07bc 715 phba->soft_wwn_enable = 0;
c3f28afa
JS
716
717 memset(wwpn, 0, sizeof(wwpn));
718
719 /* Validate and store the new name */
720 for (i=0, j=0; i < 16; i++) {
721 if ((*buf >= 'a') && (*buf <= 'f'))
722 j = ((j << 4) | ((*buf++ -'a') + 10));
723 else if ((*buf >= 'A') && (*buf <= 'F'))
724 j = ((j << 4) | ((*buf++ -'A') + 10));
725 else if ((*buf >= '0') && (*buf <= '9'))
726 j = ((j << 4) | (*buf++ -'0'));
727 else
728 return -EINVAL;
729 if (i % 2) {
730 wwpn[i/2] = j & 0xff;
731 j = 0;
732 }
733 }
734 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
2e0fef85 735 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
a12e07bc 736 if (phba->cfg_soft_wwnn)
2e0fef85 737 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
c3f28afa
JS
738
739 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
740 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
741
46fa311e 742 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
c3f28afa
JS
743 if (stat1)
744 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
745 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
746 "adapter - %d\n", phba->brd_no, stat1);
747
748 init_completion(&online_compl);
749 lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
750 wait_for_completion(&online_compl);
751 if (stat2)
752 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
753 "%d:0464 lpfc_soft_wwpn attribute set failed to reinit "
754 "adapter - %d\n", phba->brd_no, stat2);
755
756 return (stat1 || stat2) ? -EIO : count;
757}
758static CLASS_DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
759 lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
760
a12e07bc
JS
761static ssize_t
762lpfc_soft_wwnn_show(struct class_device *cdev, char *buf)
763{
764 struct Scsi_Host *host = class_to_shost(cdev);
765 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
766 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
767 (unsigned long long)phba->cfg_soft_wwnn);
768}
769
770
771static ssize_t
772lpfc_soft_wwnn_store(struct class_device *cdev, const char *buf, size_t count)
773{
774 struct Scsi_Host *host = class_to_shost(cdev);
775 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
776 unsigned int i, j, cnt=count;
777 u8 wwnn[8];
778
779 /* count may include a LF at end of string */
780 if (buf[cnt-1] == '\n')
781 cnt--;
782
783 if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
784 ((cnt == 17) && (*buf++ != 'x')) ||
785 ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
786 return -EINVAL;
787
788 /*
789 * Allow wwnn to be set many times, as long as the enable is set.
790 * However, once the wwpn is set, everything locks.
791 */
792
793 memset(wwnn, 0, sizeof(wwnn));
794
795 /* Validate and store the new name */
796 for (i=0, j=0; i < 16; i++) {
797 if ((*buf >= 'a') && (*buf <= 'f'))
798 j = ((j << 4) | ((*buf++ -'a') + 10));
799 else if ((*buf >= 'A') && (*buf <= 'F'))
800 j = ((j << 4) | ((*buf++ -'A') + 10));
801 else if ((*buf >= '0') && (*buf <= '9'))
802 j = ((j << 4) | (*buf++ -'0'));
803 else
804 return -EINVAL;
805 if (i % 2) {
806 wwnn[i/2] = j & 0xff;
807 j = 0;
808 }
809 }
810 phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
811
812 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
813 "lpfc%d: soft_wwnn set. Value will take effect upon "
814 "setting of the soft_wwpn\n", phba->brd_no);
815
816 return count;
817}
818static CLASS_DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
819 lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
820
c3f28afa 821
875fbdfe
JSEC
822static int lpfc_poll = 0;
823module_param(lpfc_poll, int, 0);
824MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
825 " 0 - none,"
826 " 1 - poll with interrupts enabled"
827 " 3 - poll and disable FCP ring interrupts");
828
829static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
830 lpfc_poll_show, lpfc_poll_store);
dea3101e 831
c01f3208
JS
832/*
833# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
834# until the timer expires. Value range is [0,255]. Default value is 30.
835*/
836static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
837static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
838module_param(lpfc_nodev_tmo, int, 0);
839MODULE_PARM_DESC(lpfc_nodev_tmo,
840 "Seconds driver will hold I/O waiting "
841 "for a device to come back");
842static ssize_t
843lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
844{
2e0fef85
JS
845 struct Scsi_Host *shost = class_to_shost(cdev);
846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847 struct lpfc_hba *phba = vport->phba;
c01f3208
JS
848 int val = 0;
849 val = phba->cfg_devloss_tmo;
850 return snprintf(buf, PAGE_SIZE, "%d\n",
851 phba->cfg_devloss_tmo);
852}
853
854static int
855lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
856{
857 static int warned;
858 if (phba->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
859 phba->cfg_nodev_tmo = phba->cfg_devloss_tmo;
860 if (!warned && val != LPFC_DEF_DEVLOSS_TMO) {
861 warned = 1;
862 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
863 "%d:0402 Ignoring nodev_tmo module "
864 "parameter because devloss_tmo is"
865 " set.\n",
866 phba->brd_no);
867 }
868 return 0;
869 }
870
871 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
872 phba->cfg_nodev_tmo = val;
873 phba->cfg_devloss_tmo = val;
874 return 0;
875 }
876 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
877 "%d:0400 lpfc_nodev_tmo attribute cannot be set to %d, "
878 "allowed range is [%d, %d]\n",
879 phba->brd_no, val,
880 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
881 phba->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
882 return -EINVAL;
883}
884
885static int
886lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
887{
888 if (phba->dev_loss_tmo_changed ||
889 (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
890 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
891 "%d:0401 Ignoring change to nodev_tmo "
892 "because devloss_tmo is set.\n",
893 phba->brd_no);
894 return 0;
895 }
896
897 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
898 phba->cfg_nodev_tmo = val;
899 phba->cfg_devloss_tmo = val;
900 return 0;
901 }
902
903 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
904 "%d:0403 lpfc_nodev_tmo attribute cannot be set to %d, "
905 "allowed range is [%d, %d]\n",
906 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
907 LPFC_MAX_DEVLOSS_TMO);
908 return -EINVAL;
909}
910
911lpfc_param_store(nodev_tmo)
912
913static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
914 lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
915
916/*
917# lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
918# disappear until the timer expires. Value range is [0,255]. Default
919# value is 30.
920*/
921module_param(lpfc_devloss_tmo, int, 0);
922MODULE_PARM_DESC(lpfc_devloss_tmo,
923 "Seconds driver will hold I/O waiting "
924 "for a device to come back");
925lpfc_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
926 LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
927lpfc_param_show(devloss_tmo)
928static int
929lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
930{
931 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
932 phba->cfg_nodev_tmo = val;
933 phba->cfg_devloss_tmo = val;
934 phba->dev_loss_tmo_changed = 1;
935 return 0;
936 }
937
938 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
939 "%d:0404 lpfc_devloss_tmo attribute cannot be set to"
940 " %d, allowed range is [%d, %d]\n",
941 phba->brd_no, val, LPFC_MIN_DEVLOSS_TMO,
942 LPFC_MAX_DEVLOSS_TMO);
943 return -EINVAL;
944}
945
946lpfc_param_store(devloss_tmo)
947static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
948 lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
949
dea3101e
JB
950/*
951# lpfc_log_verbose: Only turn this flag on if you are willing to risk being
952# deluged with LOTS of information.
953# You can set a bit mask to record specific types of verbose messages:
954#
955# LOG_ELS 0x1 ELS events
956# LOG_DISCOVERY 0x2 Link discovery events
957# LOG_MBOX 0x4 Mailbox events
958# LOG_INIT 0x8 Initialization events
959# LOG_LINK_EVENT 0x10 Link events
dea3101e
JB
960# LOG_FCP 0x40 FCP traffic history
961# LOG_NODE 0x80 Node table events
962# LOG_MISC 0x400 Miscellaneous events
963# LOG_SLI 0x800 SLI events
c7743956 964# LOG_FCP_ERROR 0x1000 Only log FCP errors
dea3101e
JB
965# LOG_LIBDFC 0x2000 LIBDFC events
966# LOG_ALL_MSG 0xffff LOG all messages
967*/
93a20f74 968LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
dea3101e
JB
969
970/*
971# lun_queue_depth: This parameter is used to limit the number of outstanding
972# commands per FCP LUN. Value range is [1,128]. Default value is 30.
973*/
974LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
975 "Max number of FCP commands we can queue to a specific LUN");
976
b28485ac
JW
977/*
978# hba_queue_depth: This parameter is used to limit the number of outstanding
979# commands per lpfc HBA. Value range is [32,8192]. If this parameter
980# value is greater than the maximum number of exchanges supported by the HBA,
981# then maximum number of exchanges supported by the HBA is used to determine
982# the hba_queue_depth.
983*/
984LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
985 "Max number of FCP commands we can queue to a lpfc HBA");
986
dea3101e
JB
987/*
988# Some disk devices have a "select ID" or "select Target" capability.
989# From a protocol standpoint "select ID" usually means select the
990# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
991# annex" which contains a table that maps a "select ID" (a number
992# between 0 and 7F) to an ALPA. By default, for compatibility with
993# older drivers, the lpfc driver scans this table from low ALPA to high
994# ALPA.
995#
996# Turning on the scan-down variable (on = 1, off = 0) will
997# cause the lpfc driver to use an inverted table, effectively
998# scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
999#
1000# (Note: This "select ID" functionality is a LOOP ONLY characteristic
1001# and will not work across a fabric. Also this parameter will take
1002# effect only in the case when ALPA map is not available.)
1003*/
1004LPFC_ATTR_R(scan_down, 1, 0, 1,
1005 "Start scanning for devices from highest ALPA to lowest");
1006
dea3101e
JB
1007/*
1008# lpfc_topology: link topology for init link
1009# 0x0 = attempt loop mode then point-to-point
367c2713 1010# 0x01 = internal loopback mode
dea3101e
JB
1011# 0x02 = attempt point-to-point mode only
1012# 0x04 = attempt loop mode only
1013# 0x06 = attempt point-to-point mode then loop
1014# Set point-to-point mode if you want to run as an N_Port.
1015# Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
1016# Default value is 0.
1017*/
367c2713 1018LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
dea3101e
JB
1019
1020/*
1021# lpfc_link_speed: Link speed selection for initializing the Fibre Channel
1022# connection.
1023# 0 = auto select (default)
1024# 1 = 1 Gigabaud
1025# 2 = 2 Gigabaud
1026# 4 = 4 Gigabaud
b87eab38
JS
1027# 8 = 8 Gigabaud
1028# Value range is [0,8]. Default value is 0.
dea3101e 1029*/
b87eab38 1030LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
dea3101e
JB
1031
1032/*
1033# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
1034# Value range is [2,3]. Default value is 3.
1035*/
1036LPFC_ATTR_R(fcp_class, 3, 2, 3,
1037 "Select Fibre Channel class of service for FCP sequences");
1038
1039/*
1040# lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
1041# is [0,1]. Default value is 0.
1042*/
1043LPFC_ATTR_RW(use_adisc, 0, 0, 1,
1044 "Use ADISC on rediscovery to authenticate FCP devices");
1045
1046/*
1047# lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
1048# range is [0,1]. Default value is 0.
1049*/
1050LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
1051
1052/*
1053# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
1054# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
7054a606 1055# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
dea3101e
JB
1056# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
1057# cr_delay is set to 0.
1058*/
8189fd19 1059LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
dea3101e
JB
1060 "interrupt response is generated");
1061
8189fd19 1062LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
dea3101e
JB
1063 "interrupt response is generated");
1064
cf5bf97e
JW
1065/*
1066# lpfc_multi_ring_support: Determines how many rings to spread available
1067# cmd/rsp IOCB entries across.
1068# Value range is [1,2]. Default value is 1.
1069*/
1070LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
1071 "SLI rings to spread IOCB entries across");
1072
a4bc3379
JS
1073/*
1074# lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
1075# identifies what rctl value to configure the additional ring for.
1076# Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
1077*/
1078LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
1079 255, "Identifies RCTL for additional ring configuration");
1080
1081/*
1082# lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
1083# identifies what type value to configure the additional ring for.
1084# Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
1085*/
1086LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
1087 255, "Identifies TYPE for additional ring configuration");
1088
dea3101e
JB
1089/*
1090# lpfc_fdmi_on: controls FDMI support.
1091# 0 = no FDMI support
1092# 1 = support FDMI without attribute of hostname
1093# 2 = support FDMI with attribute of hostname
1094# Value range [0,2]. Default value is 0.
1095*/
1096LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
1097
1098/*
1099# Specifies the maximum number of ELS cmds we can have outstanding (for
1100# discovery). Value range is [1,64]. Default value = 32.
1101*/
8189fd19 1102LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
dea3101e
JB
1103 "during discovery");
1104
1105/*
65a29c16
JS
1106# lpfc_max_luns: maximum allowed LUN.
1107# Value range is [0,65535]. Default value is 255.
1108# NOTE: The SCSI layer might probe all allowed LUN on some old targets.
dea3101e 1109*/
65a29c16
JS
1110LPFC_ATTR_R(max_luns, 255, 0, 65535,
1111 "Maximum allowed LUN");
dea3101e 1112
875fbdfe
JSEC
1113/*
1114# lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
1115# Value range is [1,255], default value is 10.
1116*/
1117LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1118 "Milliseconds driver will wait between polling FCP ring");
1119
4ff43246
JS
1120/*
1121# lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
1122# support this feature
1123# 0 = MSI disabled (default)
1124# 1 = MSI enabled
1125# Value range is [0,1]. Default value is 0.
1126*/
1127LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1128
c3f28afa 1129
2e0fef85 1130struct class_device_attribute *lpfc_hba_attrs[] = {
dea3101e
JB
1131 &class_device_attr_info,
1132 &class_device_attr_serialnum,
1133 &class_device_attr_modeldesc,
1134 &class_device_attr_modelname,
1135 &class_device_attr_programtype,
1136 &class_device_attr_portnum,
1137 &class_device_attr_fwrev,
1138 &class_device_attr_hdw,
1139 &class_device_attr_option_rom_version,
1140 &class_device_attr_state,
1141 &class_device_attr_num_discovered_ports,
1142 &class_device_attr_lpfc_drvr_version,
1143 &class_device_attr_lpfc_log_verbose,
1144 &class_device_attr_lpfc_lun_queue_depth,
b28485ac 1145 &class_device_attr_lpfc_hba_queue_depth,
dea3101e 1146 &class_device_attr_lpfc_nodev_tmo,
c01f3208 1147 &class_device_attr_lpfc_devloss_tmo,
dea3101e
JB
1148 &class_device_attr_lpfc_fcp_class,
1149 &class_device_attr_lpfc_use_adisc,
1150 &class_device_attr_lpfc_ack0,
1151 &class_device_attr_lpfc_topology,
1152 &class_device_attr_lpfc_scan_down,
1153 &class_device_attr_lpfc_link_speed,
875fbdfe
JSEC
1154 &class_device_attr_lpfc_cr_delay,
1155 &class_device_attr_lpfc_cr_count,
cf5bf97e 1156 &class_device_attr_lpfc_multi_ring_support,
a4bc3379
JS
1157 &class_device_attr_lpfc_multi_ring_rctl,
1158 &class_device_attr_lpfc_multi_ring_type,
dea3101e
JB
1159 &class_device_attr_lpfc_fdmi_on,
1160 &class_device_attr_lpfc_max_luns,
1161 &class_device_attr_nport_evt_cnt,
1162 &class_device_attr_management_version,
41415862 1163 &class_device_attr_board_mode,
40496f07 1164 &class_device_attr_issue_reset,
875fbdfe
JSEC
1165 &class_device_attr_lpfc_poll,
1166 &class_device_attr_lpfc_poll_tmo,
4ff43246 1167 &class_device_attr_lpfc_use_msi,
a12e07bc 1168 &class_device_attr_lpfc_soft_wwnn,
c3f28afa 1169 &class_device_attr_lpfc_soft_wwpn,
a12e07bc 1170 &class_device_attr_lpfc_soft_wwn_enable,
dea3101e
JB
1171 NULL,
1172};
1173
1174static ssize_t
1175sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1176{
1177 size_t buf_off;
2e0fef85
JS
1178 struct class_device *cdev = container_of(kobj, struct class_device,
1179 kobj);
1180 struct Scsi_Host *shost = class_to_shost(cdev);
1181 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1182 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1183
1184 if ((off + count) > FF_REG_AREA_SIZE)
1185 return -ERANGE;
1186
1187 if (count == 0) return 0;
1188
1189 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1190 return -EINVAL;
1191
2e0fef85 1192 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea3101e
JB
1193 return -EPERM;
1194 }
1195
2e0fef85 1196 spin_lock_irq(&phba->hbalock);
dea3101e
JB
1197 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1198 writel(*((uint32_t *)(buf + buf_off)),
1199 phba->ctrl_regs_memmap_p + off + buf_off);
1200
2e0fef85 1201 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1202
1203 return count;
1204}
1205
1206static ssize_t
1207sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1208{
1209 size_t buf_off;
1210 uint32_t * tmp_ptr;
2e0fef85
JS
1211 struct class_device *cdev = container_of(kobj, struct class_device,
1212 kobj);
1213 struct Scsi_Host *shost = class_to_shost(cdev);
1214 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1215 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1216
1217 if (off > FF_REG_AREA_SIZE)
1218 return -ERANGE;
1219
1220 if ((off + count) > FF_REG_AREA_SIZE)
1221 count = FF_REG_AREA_SIZE - off;
1222
1223 if (count == 0) return 0;
1224
1225 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1226 return -EINVAL;
1227
2e0fef85 1228 spin_lock_irq(&phba->hbalock);
dea3101e
JB
1229
1230 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1231 tmp_ptr = (uint32_t *)(buf + buf_off);
1232 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1233 }
1234
2e0fef85 1235 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1236
1237 return count;
1238}
1239
1240static struct bin_attribute sysfs_ctlreg_attr = {
1241 .attr = {
1242 .name = "ctlreg",
1243 .mode = S_IRUSR | S_IWUSR,
1244 .owner = THIS_MODULE,
1245 },
1246 .size = 256,
1247 .read = sysfs_ctlreg_read,
1248 .write = sysfs_ctlreg_write,
1249};
1250
1251
1252static void
2e0fef85 1253sysfs_mbox_idle(struct lpfc_hba *phba)
dea3101e
JB
1254{
1255 phba->sysfs_mbox.state = SMBOX_IDLE;
1256 phba->sysfs_mbox.offset = 0;
1257
1258 if (phba->sysfs_mbox.mbox) {
1259 mempool_free(phba->sysfs_mbox.mbox,
1260 phba->mbox_mem_pool);
1261 phba->sysfs_mbox.mbox = NULL;
1262 }
1263}
1264
1265static ssize_t
1266sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1267{
2e0fef85
JS
1268 struct class_device *cdev = container_of(kobj, struct class_device,
1269 kobj);
1270 struct Scsi_Host *shost = class_to_shost(cdev);
1271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1272 struct lpfc_hba *phba = vport->phba;
1273 struct lpfcMboxq *mbox = NULL;
dea3101e
JB
1274
1275 if ((count + off) > MAILBOX_CMD_SIZE)
1276 return -ERANGE;
1277
1278 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1279 return -EINVAL;
1280
1281 if (count == 0)
1282 return 0;
1283
1284 if (off == 0) {
1285 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1286 if (!mbox)
1287 return -ENOMEM;
fc6c12bc 1288 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
1289 }
1290
2e0fef85 1291 spin_lock_irq(&phba->hbalock);
dea3101e
JB
1292
1293 if (off == 0) {
1294 if (phba->sysfs_mbox.mbox)
1295 mempool_free(mbox, phba->mbox_mem_pool);
1296 else
1297 phba->sysfs_mbox.mbox = mbox;
1298 phba->sysfs_mbox.state = SMBOX_WRITING;
1299 } else {
1300 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1301 phba->sysfs_mbox.offset != off ||
1302 phba->sysfs_mbox.mbox == NULL ) {
1303 sysfs_mbox_idle(phba);
2e0fef85 1304 spin_unlock_irq(&phba->hbalock);
8f6d98d2 1305 return -EAGAIN;
dea3101e
JB
1306 }
1307 }
1308
1309 memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
1310 buf, count);
1311
1312 phba->sysfs_mbox.offset = off + count;
1313
2e0fef85 1314 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1315
1316 return count;
1317}
1318
1319static ssize_t
1320sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1321{
2e0fef85
JS
1322 struct class_device *cdev = container_of(kobj, struct class_device,
1323 kobj);
1324 struct Scsi_Host *shost = class_to_shost(cdev);
1325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1326 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1327 int rc;
1328
1dcb58e5 1329 if (off > MAILBOX_CMD_SIZE)
dea3101e
JB
1330 return -ERANGE;
1331
1dcb58e5
JS
1332 if ((count + off) > MAILBOX_CMD_SIZE)
1333 count = MAILBOX_CMD_SIZE - off;
dea3101e
JB
1334
1335 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1336 return -EINVAL;
1337
1338 if (off && count == 0)
1339 return 0;
1340
2e0fef85 1341 spin_lock_irq(&phba->hbalock);
dea3101e
JB
1342
1343 if (off == 0 &&
1344 phba->sysfs_mbox.state == SMBOX_WRITING &&
1345 phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
1346
1347 switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
1348 /* Offline only */
1349 case MBX_WRITE_NV:
1350 case MBX_INIT_LINK:
1351 case MBX_DOWN_LINK:
1352 case MBX_CONFIG_LINK:
1353 case MBX_CONFIG_RING:
1354 case MBX_RESET_RING:
1355 case MBX_UNREG_LOGIN:
1356 case MBX_CLEAR_LA:
1357 case MBX_DUMP_CONTEXT:
1358 case MBX_RUN_DIAGS:
1359 case MBX_RESTART:
1360 case MBX_FLASH_WR_ULA:
1361 case MBX_SET_MASK:
1362 case MBX_SET_SLIM:
1363 case MBX_SET_DEBUG:
2e0fef85 1364 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
dea3101e
JB
1365 printk(KERN_WARNING "mbox_read:Command 0x%x "
1366 "is illegal in on-line state\n",
1367 phba->sysfs_mbox.mbox->mb.mbxCommand);
1368 sysfs_mbox_idle(phba);
2e0fef85 1369 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1370 return -EPERM;
1371 }
1372 case MBX_LOAD_SM:
1373 case MBX_READ_NV:
1374 case MBX_READ_CONFIG:
1375 case MBX_READ_RCONFIG:
1376 case MBX_READ_STATUS:
1377 case MBX_READ_XRI:
1378 case MBX_READ_REV:
1379 case MBX_READ_LNK_STAT:
1380 case MBX_DUMP_MEMORY:
1381 case MBX_DOWN_LOAD:
1382 case MBX_UPDATE_CFG:
41415862 1383 case MBX_KILL_BOARD:
dea3101e
JB
1384 case MBX_LOAD_AREA:
1385 case MBX_LOAD_EXP_ROM:
41415862
JW
1386 case MBX_BEACON:
1387 case MBX_DEL_LD_ENTRY:
dea3101e
JB
1388 break;
1389 case MBX_READ_SPARM64:
1390 case MBX_READ_LA:
1391 case MBX_READ_LA64:
1392 case MBX_REG_LOGIN:
1393 case MBX_REG_LOGIN64:
1394 case MBX_CONFIG_PORT:
1395 case MBX_RUN_BIU_DIAG:
1396 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1397 phba->sysfs_mbox.mbox->mb.mbxCommand);
1398 sysfs_mbox_idle(phba);
2e0fef85 1399 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1400 return -EPERM;
1401 default:
1402 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1403 phba->sysfs_mbox.mbox->mb.mbxCommand);
1404 sysfs_mbox_idle(phba);
2e0fef85 1405 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1406 return -EPERM;
1407 }
1408
2e0fef85 1409 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
46fa311e 1410 sysfs_mbox_idle(phba);
2e0fef85 1411 spin_unlock_irq(&phba->hbalock);
46fa311e
JS
1412 return -EAGAIN;
1413 }
1414
2e0fef85 1415 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
dea3101e
JB
1416 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1417
2e0fef85 1418 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1419 rc = lpfc_sli_issue_mbox (phba,
1420 phba->sysfs_mbox.mbox,
1421 MBX_POLL);
2e0fef85 1422 spin_lock_irq(&phba->hbalock);
dea3101e
JB
1423
1424 } else {
2e0fef85 1425 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1426 rc = lpfc_sli_issue_mbox_wait (phba,
1427 phba->sysfs_mbox.mbox,
a309a6b6
JS
1428 lpfc_mbox_tmo_val(phba,
1429 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
2e0fef85 1430 spin_lock_irq(&phba->hbalock);
dea3101e
JB
1431 }
1432
1433 if (rc != MBX_SUCCESS) {
1dcb58e5
JS
1434 if (rc == MBX_TIMEOUT) {
1435 phba->sysfs_mbox.mbox->mbox_cmpl =
1436 lpfc_sli_def_mbox_cmpl;
1437 phba->sysfs_mbox.mbox = NULL;
1438 }
dea3101e 1439 sysfs_mbox_idle(phba);
2e0fef85 1440 spin_unlock_irq(&phba->hbalock);
8f6d98d2 1441 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
dea3101e
JB
1442 }
1443 phba->sysfs_mbox.state = SMBOX_READING;
1444 }
1445 else if (phba->sysfs_mbox.offset != off ||
1446 phba->sysfs_mbox.state != SMBOX_READING) {
1447 printk(KERN_WARNING "mbox_read: Bad State\n");
1448 sysfs_mbox_idle(phba);
2e0fef85 1449 spin_unlock_irq(&phba->hbalock);
8f6d98d2 1450 return -EAGAIN;
dea3101e
JB
1451 }
1452
1453 memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
1454
1455 phba->sysfs_mbox.offset = off + count;
1456
1dcb58e5 1457 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
dea3101e
JB
1458 sysfs_mbox_idle(phba);
1459
2e0fef85 1460 spin_unlock_irq(&phba->hbalock);
dea3101e
JB
1461
1462 return count;
1463}
1464
1465static struct bin_attribute sysfs_mbox_attr = {
1466 .attr = {
1467 .name = "mbox",
1468 .mode = S_IRUSR | S_IWUSR,
1469 .owner = THIS_MODULE,
1470 },
1dcb58e5 1471 .size = MAILBOX_CMD_SIZE,
dea3101e
JB
1472 .read = sysfs_mbox_read,
1473 .write = sysfs_mbox_write,
1474};
1475
1476int
2e0fef85 1477lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
dea3101e 1478{
2e0fef85 1479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e
JB
1480 int error;
1481
2e0fef85 1482 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
dea3101e
JB
1483 &sysfs_ctlreg_attr);
1484 if (error)
1485 goto out;
1486
2e0fef85 1487 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
dea3101e
JB
1488 &sysfs_mbox_attr);
1489 if (error)
1490 goto out_remove_ctlreg_attr;
1491
1492 return 0;
1493out_remove_ctlreg_attr:
2e0fef85 1494 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea3101e
JB
1495out:
1496 return error;
1497}
1498
1499void
2e0fef85 1500lpfc_free_sysfs_attr(struct lpfc_vport *vport)
dea3101e 1501{
2e0fef85 1502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea3101e 1503
2e0fef85
JS
1504 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1505 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
dea3101e
JB
1506}
1507
1508
1509/*
1510 * Dynamic FC Host Attributes Support
1511 */
1512
1513static void
1514lpfc_get_host_port_id(struct Scsi_Host *shost)
1515{
2e0fef85
JS
1516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1517
dea3101e 1518 /* note: fc_myDID already in cpu endianness */
2e0fef85 1519 fc_host_port_id(shost) = vport->fc_myDID;
dea3101e
JB
1520}
1521
1522static void
1523lpfc_get_host_port_type(struct Scsi_Host *shost)
1524{
2e0fef85
JS
1525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1526 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1527
1528 spin_lock_irq(shost->host_lock);
1529
2e0fef85 1530 if (lpfc_is_link_up(phba)) {
dea3101e 1531 if (phba->fc_topology == TOPOLOGY_LOOP) {
2e0fef85 1532 if (vport->fc_flag & FC_PUBLIC_LOOP)
dea3101e
JB
1533 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1534 else
1535 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1536 } else {
2e0fef85 1537 if (vport->fc_flag & FC_FABRIC)
dea3101e
JB
1538 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1539 else
1540 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
1541 }
1542 } else
1543 fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
1544
1545 spin_unlock_irq(shost->host_lock);
1546}
1547
1548static void
1549lpfc_get_host_port_state(struct Scsi_Host *shost)
1550{
2e0fef85
JS
1551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1552 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1553
1554 spin_lock_irq(shost->host_lock);
1555
2e0fef85 1556 if (vport->fc_flag & FC_OFFLINE_MODE)
dea3101e
JB
1557 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1558 else {
2e0fef85
JS
1559 switch (phba->link_state) {
1560 case LPFC_LINK_UNKNOWN:
dea3101e
JB
1561 case LPFC_LINK_DOWN:
1562 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1563 break;
1564 case LPFC_LINK_UP:
dea3101e 1565 case LPFC_CLEAR_LA:
dea3101e
JB
1566 /* Links up, beyond this port_type reports state */
1567 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1568 break;
1569 case LPFC_HBA_ERROR:
1570 fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
1571 break;
1572 default:
1573 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1574 break;
1575 }
1576 }
1577
1578 spin_unlock_irq(shost->host_lock);
1579}
1580
1581static void
1582lpfc_get_host_speed(struct Scsi_Host *shost)
1583{
2e0fef85
JS
1584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1585 struct lpfc_hba *phba = vport->phba;
dea3101e
JB
1586
1587 spin_lock_irq(shost->host_lock);
1588
2e0fef85 1589 if (lpfc_is_link_up(phba)) {
dea3101e
JB
1590 switch(phba->fc_linkspeed) {
1591 case LA_1GHZ_LINK:
1592 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
1593 break;
1594 case LA_2GHZ_LINK:
1595 fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
1596 break;
1597 case LA_4GHZ_LINK:
1598 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1599 break;
b87eab38
JS
1600 case LA_8GHZ_LINK:
1601 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
1602 break;
dea3101e
JB
1603 default:
1604 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1605 break;
1606 }
1607 }
1608
1609 spin_unlock_irq(shost->host_lock);
1610}
1611
1612static void
1613lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1614{
2e0fef85
JS
1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
f631b4be 1617 u64 node_name;
dea3101e
JB
1618
1619 spin_lock_irq(shost->host_lock);
1620
2e0fef85 1621 if ((vport->fc_flag & FC_FABRIC) ||
dea3101e 1622 ((phba->fc_topology == TOPOLOGY_LOOP) &&
2e0fef85 1623 (vport->fc_flag & FC_PUBLIC_LOOP)))
68ce1eb5 1624 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
dea3101e
JB
1625 else
1626 /* fabric is local port if there is no F/FL_Port */
2e0fef85 1627 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
dea3101e
JB
1628
1629 spin_unlock_irq(shost->host_lock);
1630
f631b4be 1631 fc_host_fabric_name(shost) = node_name;
dea3101e
JB
1632}
1633
dea3101e
JB
1634static struct fc_host_statistics *
1635lpfc_get_stats(struct Scsi_Host *shost)
1636{
2e0fef85
JS
1637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1638 struct lpfc_hba *phba = vport->phba;
1639 struct lpfc_sli *psli = &phba->sli;
f888ba3c 1640 struct fc_host_statistics *hs = &phba->link_stats;
64ba8818 1641 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
dea3101e
JB
1642 LPFC_MBOXQ_t *pmboxq;
1643 MAILBOX_t *pmb;
64ba8818 1644 unsigned long seconds;
433c3579 1645 int rc = 0;
dea3101e 1646
2e0fef85
JS
1647 /* prevent udev from issuing mailbox commands
1648 * until the port is configured.
1649 */
1650 if (phba->link_state < LPFC_LINK_DOWN ||
1651 !phba->mbox_mem_pool ||
1652 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
1653 return NULL;
1654
1655 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
1656 return NULL;
1657
dea3101e
JB
1658 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1659 if (!pmboxq)
1660 return NULL;
1661 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
1662
1663 pmb = &pmboxq->mb;
1664 pmb->mbxCommand = MBX_READ_STATUS;
1665 pmb->mbxOwner = OWN_HOST;
1666 pmboxq->context1 = NULL;
1667
2e0fef85 1668 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
433c3579 1669 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea3101e 1670 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 1671 else
dea3101e
JB
1672 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1673
1674 if (rc != MBX_SUCCESS) {
433c3579
JSEC
1675 if (rc == MBX_TIMEOUT)
1676 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1677 else
1678 mempool_free(pmboxq, phba->mbox_mem_pool);
dea3101e
JB
1679 return NULL;
1680 }
1681
f888ba3c
JSEC
1682 memset(hs, 0, sizeof (struct fc_host_statistics));
1683
dea3101e
JB
1684 hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
1685 hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
1686 hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
1687 hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
1688
433c3579 1689 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
dea3101e
JB
1690 pmb->mbxCommand = MBX_READ_LNK_STAT;
1691 pmb->mbxOwner = OWN_HOST;
1692 pmboxq->context1 = NULL;
1693
2e0fef85 1694 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
433c3579 1695 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
dea3101e 1696 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
433c3579 1697 else
dea3101e
JB
1698 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1699
1700 if (rc != MBX_SUCCESS) {
433c3579
JSEC
1701 if (rc == MBX_TIMEOUT)
1702 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1703 else
1704 mempool_free( pmboxq, phba->mbox_mem_pool);
dea3101e
JB
1705 return NULL;
1706 }
1707
1708 hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1709 hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1710 hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1711 hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1712 hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1713 hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1714 hs->error_frames = pmb->un.varRdLnk.crcCnt;
1715
64ba8818
JS
1716 hs->link_failure_count -= lso->link_failure_count;
1717 hs->loss_of_sync_count -= lso->loss_of_sync_count;
1718 hs->loss_of_signal_count -= lso->loss_of_signal_count;
1719 hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
1720 hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
1721 hs->invalid_crc_count -= lso->invalid_crc_count;
1722 hs->error_frames -= lso->error_frames;
1723
dea3101e
JB
1724 if (phba->fc_topology == TOPOLOGY_LOOP) {
1725 hs->lip_count = (phba->fc_eventTag >> 1);
64ba8818 1726 hs->lip_count -= lso->link_events;
dea3101e
JB
1727 hs->nos_count = -1;
1728 } else {
1729 hs->lip_count = -1;
1730 hs->nos_count = (phba->fc_eventTag >> 1);
64ba8818 1731 hs->nos_count -= lso->link_events;
dea3101e
JB
1732 }
1733
1734 hs->dumped_frames = -1;
1735
64ba8818
JS
1736 seconds = get_seconds();
1737 if (seconds < psli->stats_start)
1738 hs->seconds_since_last_reset = seconds +
1739 ((unsigned long)-1 - psli->stats_start);
1740 else
1741 hs->seconds_since_last_reset = seconds - psli->stats_start;
dea3101e 1742
1dcb58e5
JS
1743 mempool_free(pmboxq, phba->mbox_mem_pool);
1744
dea3101e
JB
1745 return hs;
1746}
1747
64ba8818
JS
1748static void
1749lpfc_reset_stats(struct Scsi_Host *shost)
1750{
2e0fef85
JS
1751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1752 struct lpfc_hba *phba = vport->phba;
1753 struct lpfc_sli *psli = &phba->sli;
1754 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
64ba8818
JS
1755 LPFC_MBOXQ_t *pmboxq;
1756 MAILBOX_t *pmb;
1757 int rc = 0;
1758
2e0fef85 1759 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
46fa311e
JS
1760 return;
1761
64ba8818
JS
1762 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1763 if (!pmboxq)
1764 return;
1765 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1766
1767 pmb = &pmboxq->mb;
1768 pmb->mbxCommand = MBX_READ_STATUS;
1769 pmb->mbxOwner = OWN_HOST;
1770 pmb->un.varWords[0] = 0x1; /* reset request */
1771 pmboxq->context1 = NULL;
1772
2e0fef85 1773 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
64ba8818
JS
1774 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1775 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1776 else
1777 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1778
1779 if (rc != MBX_SUCCESS) {
1780 if (rc == MBX_TIMEOUT)
1781 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1782 else
1783 mempool_free(pmboxq, phba->mbox_mem_pool);
1784 return;
1785 }
1786
1787 memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
1788 pmb->mbxCommand = MBX_READ_LNK_STAT;
1789 pmb->mbxOwner = OWN_HOST;
1790 pmboxq->context1 = NULL;
1791
2e0fef85 1792 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
64ba8818
JS
1793 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1794 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1795 else
1796 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1797
1798 if (rc != MBX_SUCCESS) {
1799 if (rc == MBX_TIMEOUT)
1800 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1801 else
1802 mempool_free( pmboxq, phba->mbox_mem_pool);
1803 return;
1804 }
1805
1806 lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
1807 lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
1808 lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
1809 lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
1810 lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
1811 lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
1812 lso->error_frames = pmb->un.varRdLnk.crcCnt;
1813 lso->link_events = (phba->fc_eventTag >> 1);
1814
1815 psli->stats_start = get_seconds();
1816
1dcb58e5
JS
1817 mempool_free(pmboxq, phba->mbox_mem_pool);
1818
64ba8818
JS
1819 return;
1820}
dea3101e
JB
1821
1822/*
1823 * The LPFC driver treats linkdown handling as target loss events so there
1824 * are no sysfs handlers for link_down_tmo.
1825 */
685f0bf7
JS
1826
1827static struct lpfc_nodelist *
1828lpfc_get_node_by_target(struct scsi_target *starget)
dea3101e 1829{
2e0fef85
JS
1830 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1831 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
685f0bf7 1832 struct lpfc_nodelist *ndlp;
dea3101e
JB
1833
1834 spin_lock_irq(shost->host_lock);
685f0bf7 1835 /* Search for this, mapped, target ID */
2e0fef85 1836 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
685f0bf7
JS
1837 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1838 starget->id == ndlp->nlp_sid) {
1839 spin_unlock_irq(shost->host_lock);
1840 return ndlp;
dea3101e
JB
1841 }
1842 }
1843 spin_unlock_irq(shost->host_lock);
685f0bf7
JS
1844 return NULL;
1845}
dea3101e 1846
685f0bf7
JS
1847static void
1848lpfc_get_starget_port_id(struct scsi_target *starget)
1849{
1850 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1851
1852 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
dea3101e
JB
1853}
1854
1855static void
1856lpfc_get_starget_node_name(struct scsi_target *starget)
1857{
685f0bf7 1858 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 1859
685f0bf7
JS
1860 fc_starget_node_name(starget) =
1861 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
dea3101e
JB
1862}
1863
1864static void
1865lpfc_get_starget_port_name(struct scsi_target *starget)
1866{
685f0bf7 1867 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
dea3101e 1868
685f0bf7
JS
1869 fc_starget_port_name(starget) =
1870 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
dea3101e
JB
1871}
1872
dea3101e
JB
1873static void
1874lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1875{
dea3101e 1876 if (timeout)
c01f3208 1877 rport->dev_loss_tmo = timeout;
dea3101e 1878 else
c01f3208 1879 rport->dev_loss_tmo = 1;
dea3101e
JB
1880}
1881
1882
1883#define lpfc_rport_show_function(field, format_string, sz, cast) \
1884static ssize_t \
1885lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
1886{ \
1887 struct fc_rport *rport = transport_class_to_rport(cdev); \
1888 struct lpfc_rport_data *rdata = rport->hostdata; \
1889 return snprintf(buf, sz, format_string, \
1890 (rdata->target) ? cast rdata->target->field : 0); \
1891}
1892
1893#define lpfc_rport_rd_attr(field, format_string, sz) \
1894 lpfc_rport_show_function(field, format_string, sz, ) \
1895static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
1896
1897
1898struct fc_function_template lpfc_transport_functions = {
1899 /* fixed attributes the driver supports */
1900 .show_host_node_name = 1,
1901 .show_host_port_name = 1,
1902 .show_host_supported_classes = 1,
1903 .show_host_supported_fc4s = 1,
dea3101e
JB
1904 .show_host_supported_speeds = 1,
1905 .show_host_maxframe_size = 1,
1906
1907 /* dynamic attributes the driver supports */
1908 .get_host_port_id = lpfc_get_host_port_id,
1909 .show_host_port_id = 1,
1910
1911 .get_host_port_type = lpfc_get_host_port_type,
1912 .show_host_port_type = 1,
1913
1914 .get_host_port_state = lpfc_get_host_port_state,
1915 .show_host_port_state = 1,
1916
1917 /* active_fc4s is shown but doesn't change (thus no get function) */
1918 .show_host_active_fc4s = 1,
1919
1920 .get_host_speed = lpfc_get_host_speed,
1921 .show_host_speed = 1,
1922
1923 .get_host_fabric_name = lpfc_get_host_fabric_name,
1924 .show_host_fabric_name = 1,
1925
1926 /*
1927 * The LPFC driver treats linkdown handling as target loss events
1928 * so there are no sysfs handlers for link_down_tmo.
1929 */
1930
1931 .get_fc_host_stats = lpfc_get_stats,
64ba8818 1932 .reset_fc_host_stats = lpfc_reset_stats,
dea3101e
JB
1933
1934 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
1935 .show_rport_maxframe_size = 1,
1936 .show_rport_supported_classes = 1,
1937
dea3101e
JB
1938 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
1939 .show_rport_dev_loss_tmo = 1,
1940
1941 .get_starget_port_id = lpfc_get_starget_port_id,
1942 .show_starget_port_id = 1,
1943
1944 .get_starget_node_name = lpfc_get_starget_node_name,
1945 .show_starget_node_name = 1,
1946
1947 .get_starget_port_name = lpfc_get_starget_port_name,
1948 .show_starget_port_name = 1,
91ca7b01
AV
1949
1950 .issue_fc_host_lip = lpfc_issue_lip,
c01f3208
JS
1951 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1952 .terminate_rport_io = lpfc_terminate_rport_io,
dea3101e
JB
1953};
1954
1955void
1956lpfc_get_cfgparam(struct lpfc_hba *phba)
1957{
7bcbb752
JSEC
1958 lpfc_log_verbose_init(phba, lpfc_log_verbose);
1959 lpfc_cr_delay_init(phba, lpfc_cr_delay);
1960 lpfc_cr_count_init(phba, lpfc_cr_count);
cf5bf97e 1961 lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
a4bc3379
JS
1962 lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
1963 lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
7bcbb752
JSEC
1964 lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
1965 lpfc_fcp_class_init(phba, lpfc_fcp_class);
1966 lpfc_use_adisc_init(phba, lpfc_use_adisc);
1967 lpfc_ack0_init(phba, lpfc_ack0);
1968 lpfc_topology_init(phba, lpfc_topology);
1969 lpfc_scan_down_init(phba, lpfc_scan_down);
7bcbb752
JSEC
1970 lpfc_link_speed_init(phba, lpfc_link_speed);
1971 lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
1972 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1973 lpfc_max_luns_init(phba, lpfc_max_luns);
875fbdfe 1974 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
4ff43246 1975 lpfc_use_msi_init(phba, lpfc_use_msi);
c01f3208
JS
1976 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1977 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
875fbdfe 1978 phba->cfg_poll = lpfc_poll;
a12e07bc 1979 phba->cfg_soft_wwnn = 0L;
c3f28afa 1980 phba->cfg_soft_wwpn = 0L;
dea3101e
JB
1981
1982 /*
1983 * The total number of segments is the configuration value plus 2
1984 * since the IOCB need a command and response bde.
1985 */
1986 phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
1987
1988 /*
1989 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
1990 * used to create the sg_dma_buf_pool must be dynamically calculated
1991 */
1992 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
1993 sizeof(struct fcp_rsp) +
1994 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1995
b28485ac 1996
7054a606 1997 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
b28485ac 1998
dea3101e
JB
1999 return;
2000}