aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_attr.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c760
1 files changed, 547 insertions, 213 deletions
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 5dfda9778c80..860a52c090f4 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -39,6 +39,7 @@
39#include "lpfc_version.h" 39#include "lpfc_version.h"
40#include "lpfc_compat.h" 40#include "lpfc_compat.h"
41#include "lpfc_crtn.h" 41#include "lpfc_crtn.h"
42#include "lpfc_vport.h"
42 43
43#define LPFC_DEF_DEVLOSS_TMO 30 44#define LPFC_DEF_DEVLOSS_TMO 30
44#define LPFC_MIN_DEVLOSS_TMO 1 45#define LPFC_MIN_DEVLOSS_TMO 1
@@ -76,116 +77,156 @@ static ssize_t
76lpfc_info_show(struct class_device *cdev, char *buf) 77lpfc_info_show(struct class_device *cdev, char *buf)
77{ 78{
78 struct Scsi_Host *host = class_to_shost(cdev); 79 struct Scsi_Host *host = class_to_shost(cdev);
80
79 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); 81 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
80} 82}
81 83
82static ssize_t 84static ssize_t
83lpfc_serialnum_show(struct class_device *cdev, char *buf) 85lpfc_serialnum_show(struct class_device *cdev, char *buf)
84{ 86{
85 struct Scsi_Host *host = class_to_shost(cdev); 87 struct Scsi_Host *shost = class_to_shost(cdev);
86 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 88 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
89 struct lpfc_hba *phba = vport->phba;
90
87 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); 91 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
88} 92}
89 93
90static ssize_t 94static ssize_t
91lpfc_modeldesc_show(struct class_device *cdev, char *buf) 95lpfc_modeldesc_show(struct class_device *cdev, char *buf)
92{ 96{
93 struct Scsi_Host *host = class_to_shost(cdev); 97 struct Scsi_Host *shost = class_to_shost(cdev);
94 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 98 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
99 struct lpfc_hba *phba = vport->phba;
100
95 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); 101 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
96} 102}
97 103
98static ssize_t 104static ssize_t
99lpfc_modelname_show(struct class_device *cdev, char *buf) 105lpfc_modelname_show(struct class_device *cdev, char *buf)
100{ 106{
101 struct Scsi_Host *host = class_to_shost(cdev); 107 struct Scsi_Host *shost = class_to_shost(cdev);
102 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 108 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
109 struct lpfc_hba *phba = vport->phba;
110
103 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); 111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
104} 112}
105 113
106static ssize_t 114static ssize_t
107lpfc_programtype_show(struct class_device *cdev, char *buf) 115lpfc_programtype_show(struct class_device *cdev, char *buf)
108{ 116{
109 struct Scsi_Host *host = class_to_shost(cdev); 117 struct Scsi_Host *shost = class_to_shost(cdev);
110 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 118 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
119 struct lpfc_hba *phba = vport->phba;
120
111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); 121 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
112} 122}
113 123
114static ssize_t 124static ssize_t
115lpfc_portnum_show(struct class_device *cdev, char *buf) 125lpfc_vportnum_show(struct class_device *cdev, char *buf)
116{ 126{
117 struct Scsi_Host *host = class_to_shost(cdev); 127 struct Scsi_Host *shost = class_to_shost(cdev);
118 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 128 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
129 struct lpfc_hba *phba = vport->phba;
130
119 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); 131 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
120} 132}
121 133
122static ssize_t 134static ssize_t
123lpfc_fwrev_show(struct class_device *cdev, char *buf) 135lpfc_fwrev_show(struct class_device *cdev, char *buf)
124{ 136{
125 struct Scsi_Host *host = class_to_shost(cdev); 137 struct Scsi_Host *shost = class_to_shost(cdev);
126 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 138 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
139 struct lpfc_hba *phba = vport->phba;
127 char fwrev[32]; 140 char fwrev[32];
141
128 lpfc_decode_firmware_rev(phba, fwrev, 1); 142 lpfc_decode_firmware_rev(phba, fwrev, 1);
129 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev); 143 return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
130} 144}
131 145
132static ssize_t 146static ssize_t
133lpfc_hdw_show(struct class_device *cdev, char *buf) 147lpfc_hdw_show(struct class_device *cdev, char *buf)
134{ 148{
135 char hdw[9]; 149 char hdw[9];
136 struct Scsi_Host *host = class_to_shost(cdev); 150 struct Scsi_Host *shost = class_to_shost(cdev);
137 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 151 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
152 struct lpfc_hba *phba = vport->phba;
138 lpfc_vpd_t *vp = &phba->vpd; 153 lpfc_vpd_t *vp = &phba->vpd;
154
139 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); 155 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
140 return snprintf(buf, PAGE_SIZE, "%s\n", hdw); 156 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
141} 157}
142static ssize_t 158static ssize_t
143lpfc_option_rom_version_show(struct class_device *cdev, char *buf) 159lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
144{ 160{
145 struct Scsi_Host *host = class_to_shost(cdev); 161 struct Scsi_Host *shost = class_to_shost(cdev);
146 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 162 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
163 struct lpfc_hba *phba = vport->phba;
164
147 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); 165 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
148} 166}
149static ssize_t 167static ssize_t
150lpfc_state_show(struct class_device *cdev, char *buf) 168lpfc_state_show(struct class_device *cdev, char *buf)
151{ 169{
152 struct Scsi_Host *host = class_to_shost(cdev); 170 struct Scsi_Host *shost = class_to_shost(cdev);
153 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 171 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
154 int len = 0; 172 struct lpfc_hba *phba = vport->phba;
155 switch (phba->hba_state) { 173 int len = 0;
156 case LPFC_STATE_UNKNOWN: 174
175 switch (phba->link_state) {
176 case LPFC_LINK_UNKNOWN:
157 case LPFC_WARM_START: 177 case LPFC_WARM_START:
158 case LPFC_INIT_START: 178 case LPFC_INIT_START:
159 case LPFC_INIT_MBX_CMDS: 179 case LPFC_INIT_MBX_CMDS:
160 case LPFC_LINK_DOWN: 180 case LPFC_LINK_DOWN:
181 case LPFC_HBA_ERROR:
161 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); 182 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
162 break; 183 break;
163 case LPFC_LINK_UP: 184 case LPFC_LINK_UP:
164 case LPFC_LOCAL_CFG_LINK:
165 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
166 break;
167 case LPFC_FLOGI:
168 case LPFC_FABRIC_CFG_LINK:
169 case LPFC_NS_REG:
170 case LPFC_NS_QRY:
171 case LPFC_BUILD_DISC_LIST:
172 case LPFC_DISC_AUTH:
173 case LPFC_CLEAR_LA: 185 case LPFC_CLEAR_LA:
174 len += snprintf(buf + len, PAGE_SIZE-len,
175 "Link Up - Discovery\n");
176 break;
177 case LPFC_HBA_READY: 186 case LPFC_HBA_READY:
178 len += snprintf(buf + len, PAGE_SIZE-len, 187 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
179 "Link Up - Ready:\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,
195 "Configuring Link\n");
196 break;
197 case LPFC_FDISC:
198 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
211 case LPFC_VPORT_FAILED:
212 len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
213 break;
214
215 case LPFC_VPORT_UNKNOWN:
216 len += snprintf(buf + len, PAGE_SIZE - len,
217 "Unknown\n");
218 break;
219 }
220
180 if (phba->fc_topology == TOPOLOGY_LOOP) { 221 if (phba->fc_topology == TOPOLOGY_LOOP) {
181 if (phba->fc_flag & FC_PUBLIC_LOOP) 222 if (vport->fc_flag & FC_PUBLIC_LOOP)
182 len += snprintf(buf + len, PAGE_SIZE-len, 223 len += snprintf(buf + len, PAGE_SIZE-len,
183 " Public Loop\n"); 224 " Public Loop\n");
184 else 225 else
185 len += snprintf(buf + len, PAGE_SIZE-len, 226 len += snprintf(buf + len, PAGE_SIZE-len,
186 " Private Loop\n"); 227 " Private Loop\n");
187 } else { 228 } else {
188 if (phba->fc_flag & FC_FABRIC) 229 if (vport->fc_flag & FC_FABRIC)
189 len += snprintf(buf + len, PAGE_SIZE-len, 230 len += snprintf(buf + len, PAGE_SIZE-len,
190 " Fabric\n"); 231 " Fabric\n");
191 else 232 else
@@ -193,29 +234,32 @@ lpfc_state_show(struct class_device *cdev, char *buf)
193 " Point-2-Point\n"); 234 " Point-2-Point\n");
194 } 235 }
195 } 236 }
237
196 return len; 238 return len;
197} 239}
198 240
199static ssize_t 241static ssize_t
200lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf) 242lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
201{ 243{
202 struct Scsi_Host *host = class_to_shost(cdev); 244 struct Scsi_Host *shost = class_to_shost(cdev);
203 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 245 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
204 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt + 246
205 phba->fc_unmap_cnt); 247 return snprintf(buf, PAGE_SIZE, "%d\n",
248 vport->fc_map_cnt + vport->fc_unmap_cnt);
206} 249}
207 250
208 251
209static int 252static int
210lpfc_issue_lip(struct Scsi_Host *host) 253lpfc_issue_lip(struct Scsi_Host *shost)
211{ 254{
212 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata; 255 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
256 struct lpfc_hba *phba = vport->phba;
213 LPFC_MBOXQ_t *pmboxq; 257 LPFC_MBOXQ_t *pmboxq;
214 int mbxstatus = MBXERR_ERROR; 258 int mbxstatus = MBXERR_ERROR;
215 259
216 if ((phba->fc_flag & FC_OFFLINE_MODE) || 260 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
217 (phba->fc_flag & FC_BLOCK_MGMT_IO) || 261 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
218 (phba->hba_state != LPFC_HBA_READY)) 262 (vport->port_state != LPFC_VPORT_READY))
219 return -EPERM; 263 return -EPERM;
220 264
221 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); 265 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
@@ -238,9 +282,7 @@ lpfc_issue_lip(struct Scsi_Host *host)
238 } 282 }
239 283
240 lpfc_set_loopback_flag(phba); 284 lpfc_set_loopback_flag(phba);
241 if (mbxstatus == MBX_TIMEOUT) 285 if (mbxstatus != MBX_TIMEOUT)
242 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
243 else
244 mempool_free(pmboxq, phba->mbox_mem_pool); 286 mempool_free(pmboxq, phba->mbox_mem_pool);
245 287
246 if (mbxstatus == MBXERR_ERROR) 288 if (mbxstatus == MBXERR_ERROR)
@@ -320,8 +362,10 @@ lpfc_selective_reset(struct lpfc_hba *phba)
320static ssize_t 362static ssize_t
321lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count) 363lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
322{ 364{
323 struct Scsi_Host *host = class_to_shost(cdev); 365 struct Scsi_Host *shost = class_to_shost(cdev);
324 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
367 struct lpfc_hba *phba = vport->phba;
368
325 int status = -EINVAL; 369 int status = -EINVAL;
326 370
327 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) 371 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
@@ -336,23 +380,26 @@ lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
336static ssize_t 380static ssize_t
337lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) 381lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
338{ 382{
339 struct Scsi_Host *host = class_to_shost(cdev); 383 struct Scsi_Host *shost = class_to_shost(cdev);
340 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 384 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
385 struct lpfc_hba *phba = vport->phba;
386
341 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 387 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
342} 388}
343 389
344static ssize_t 390static ssize_t
345lpfc_board_mode_show(struct class_device *cdev, char *buf) 391lpfc_board_mode_show(struct class_device *cdev, char *buf)
346{ 392{
347 struct Scsi_Host *host = class_to_shost(cdev); 393 struct Scsi_Host *shost = class_to_shost(cdev);
348 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 394 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
395 struct lpfc_hba *phba = vport->phba;
349 char * state; 396 char * state;
350 397
351 if (phba->hba_state == LPFC_HBA_ERROR) 398 if (phba->link_state == LPFC_HBA_ERROR)
352 state = "error"; 399 state = "error";
353 else if (phba->hba_state == LPFC_WARM_START) 400 else if (phba->link_state == LPFC_WARM_START)
354 state = "warm start"; 401 state = "warm start";
355 else if (phba->hba_state == LPFC_INIT_START) 402 else if (phba->link_state == LPFC_INIT_START)
356 state = "offline"; 403 state = "offline";
357 else 404 else
358 state = "online"; 405 state = "online";
@@ -363,8 +410,9 @@ lpfc_board_mode_show(struct class_device *cdev, char *buf)
363static ssize_t 410static ssize_t
364lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count) 411lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
365{ 412{
366 struct Scsi_Host *host = class_to_shost(cdev); 413 struct Scsi_Host *shost = class_to_shost(cdev);
367 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 414 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
415 struct lpfc_hba *phba = vport->phba;
368 struct completion online_compl; 416 struct completion online_compl;
369 int status=0; 417 int status=0;
370 418
@@ -389,11 +437,166 @@ lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
389 return -EIO; 437 return -EIO;
390} 438}
391 439
440int
441lpfc_get_hba_info(struct lpfc_hba *phba,
442 uint32_t *mxri, uint32_t *axri,
443 uint32_t *mrpi, uint32_t *arpi,
444 uint32_t *mvpi, uint32_t *avpi)
445{
446 struct lpfc_sli *psli = &phba->sli;
447 LPFC_MBOXQ_t *pmboxq;
448 MAILBOX_t *pmb;
449 int rc = 0;
450
451 /*
452 * prevent udev from issuing mailbox commands until the port is
453 * configured.
454 */
455 if (phba->link_state < LPFC_LINK_DOWN ||
456 !phba->mbox_mem_pool ||
457 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
458 return 0;
459
460 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
461 return 0;
462
463 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
464 if (!pmboxq)
465 return 0;
466 memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
467
468 pmb = &pmboxq->mb;
469 pmb->mbxCommand = MBX_READ_CONFIG;
470 pmb->mbxOwner = OWN_HOST;
471 pmboxq->context1 = NULL;
472
473 if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
474 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
475 rc = MBX_NOT_FINISHED;
476 else
477 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
478
479 if (rc != MBX_SUCCESS) {
480 if (rc != MBX_TIMEOUT)
481 mempool_free(pmboxq, phba->mbox_mem_pool);
482 return 0;
483 }
484
485 if (mrpi)
486 *mrpi = pmb->un.varRdConfig.max_rpi;
487 if (arpi)
488 *arpi = pmb->un.varRdConfig.avail_rpi;
489 if (mxri)
490 *mxri = pmb->un.varRdConfig.max_xri;
491 if (axri)
492 *axri = pmb->un.varRdConfig.avail_xri;
493 if (mvpi)
494 *mvpi = pmb->un.varRdConfig.max_vpi;
495 if (avpi)
496 *avpi = pmb->un.varRdConfig.avail_vpi;
497
498 mempool_free(pmboxq, phba->mbox_mem_pool);
499 return 1;
500}
501
502static ssize_t
503lpfc_max_rpi_show(struct class_device *cdev, char *buf)
504{
505 struct Scsi_Host *shost = class_to_shost(cdev);
506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
507 struct lpfc_hba *phba = vport->phba;
508 uint32_t cnt;
509
510 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
511 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
512 return snprintf(buf, PAGE_SIZE, "Unknown\n");
513}
514
515static ssize_t
516lpfc_used_rpi_show(struct class_device *cdev, char *buf)
517{
518 struct Scsi_Host *shost = class_to_shost(cdev);
519 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
520 struct lpfc_hba *phba = vport->phba;
521 uint32_t cnt, acnt;
522
523 if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
524 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
525 return snprintf(buf, PAGE_SIZE, "Unknown\n");
526}
527
528static ssize_t
529lpfc_max_xri_show(struct class_device *cdev, char *buf)
530{
531 struct Scsi_Host *shost = class_to_shost(cdev);
532 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
533 struct lpfc_hba *phba = vport->phba;
534 uint32_t cnt;
535
536 if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
537 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
538 return snprintf(buf, PAGE_SIZE, "Unknown\n");
539}
540
541static ssize_t
542lpfc_used_xri_show(struct class_device *cdev, char *buf)
543{
544 struct Scsi_Host *shost = class_to_shost(cdev);
545 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
546 struct lpfc_hba *phba = vport->phba;
547 uint32_t cnt, acnt;
548
549 if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
550 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
551 return snprintf(buf, PAGE_SIZE, "Unknown\n");
552}
553
554static ssize_t
555lpfc_max_vpi_show(struct class_device *cdev, char *buf)
556{
557 struct Scsi_Host *shost = class_to_shost(cdev);
558 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
559 struct lpfc_hba *phba = vport->phba;
560 uint32_t cnt;
561
562 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
563 return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
564 return snprintf(buf, PAGE_SIZE, "Unknown\n");
565}
566
567static ssize_t
568lpfc_used_vpi_show(struct class_device *cdev, char *buf)
569{
570 struct Scsi_Host *shost = class_to_shost(cdev);
571 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
572 struct lpfc_hba *phba = vport->phba;
573 uint32_t cnt, acnt;
574
575 if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
576 return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
577 return snprintf(buf, PAGE_SIZE, "Unknown\n");
578}
579
580static ssize_t
581lpfc_npiv_info_show(struct class_device *cdev, char *buf)
582{
583 struct Scsi_Host *shost = class_to_shost(cdev);
584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
585 struct lpfc_hba *phba = vport->phba;
586
587 if (!(phba->max_vpi))
588 return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
589 if (vport->port_type == LPFC_PHYSICAL_PORT)
590 return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
591 return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
592}
593
392static ssize_t 594static ssize_t
393lpfc_poll_show(struct class_device *cdev, char *buf) 595lpfc_poll_show(struct class_device *cdev, char *buf)
394{ 596{
395 struct Scsi_Host *host = class_to_shost(cdev); 597 struct Scsi_Host *shost = class_to_shost(cdev);
396 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 598 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
599 struct lpfc_hba *phba = vport->phba;
397 600
398 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); 601 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
399} 602}
@@ -402,8 +605,9 @@ static ssize_t
402lpfc_poll_store(struct class_device *cdev, const char *buf, 605lpfc_poll_store(struct class_device *cdev, const char *buf,
403 size_t count) 606 size_t count)
404{ 607{
405 struct Scsi_Host *host = class_to_shost(cdev); 608 struct Scsi_Host *shost = class_to_shost(cdev);
406 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 609 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
610 struct lpfc_hba *phba = vport->phba;
407 uint32_t creg_val; 611 uint32_t creg_val;
408 uint32_t old_val; 612 uint32_t old_val;
409 int val=0; 613 int val=0;
@@ -417,7 +621,7 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
417 if ((val & 0x3) != val) 621 if ((val & 0x3) != val)
418 return -EINVAL; 622 return -EINVAL;
419 623
420 spin_lock_irq(phba->host->host_lock); 624 spin_lock_irq(&phba->hbalock);
421 625
422 old_val = phba->cfg_poll; 626 old_val = phba->cfg_poll;
423 627
@@ -432,16 +636,16 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
432 lpfc_poll_start_timer(phba); 636 lpfc_poll_start_timer(phba);
433 } 637 }
434 } else if (val != 0x0) { 638 } else if (val != 0x0) {
435 spin_unlock_irq(phba->host->host_lock); 639 spin_unlock_irq(&phba->hbalock);
436 return -EINVAL; 640 return -EINVAL;
437 } 641 }
438 642
439 if (!(val & DISABLE_FCP_RING_INT) && 643 if (!(val & DISABLE_FCP_RING_INT) &&
440 (old_val & DISABLE_FCP_RING_INT)) 644 (old_val & DISABLE_FCP_RING_INT))
441 { 645 {
442 spin_unlock_irq(phba->host->host_lock); 646 spin_unlock_irq(&phba->hbalock);
443 del_timer(&phba->fcp_poll_timer); 647 del_timer(&phba->fcp_poll_timer);
444 spin_lock_irq(phba->host->host_lock); 648 spin_lock_irq(&phba->hbalock);
445 creg_val = readl(phba->HCregaddr); 649 creg_val = readl(phba->HCregaddr);
446 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); 650 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
447 writel(creg_val, phba->HCregaddr); 651 writel(creg_val, phba->HCregaddr);
@@ -450,7 +654,7 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
450 654
451 phba->cfg_poll = val; 655 phba->cfg_poll = val;
452 656
453 spin_unlock_irq(phba->host->host_lock); 657 spin_unlock_irq(&phba->hbalock);
454 658
455 return strlen(buf); 659 return strlen(buf);
456} 660}
@@ -459,8 +663,9 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
459static ssize_t \ 663static ssize_t \
460lpfc_##attr##_show(struct class_device *cdev, char *buf) \ 664lpfc_##attr##_show(struct class_device *cdev, char *buf) \
461{ \ 665{ \
462 struct Scsi_Host *host = class_to_shost(cdev);\ 666 struct Scsi_Host *shost = class_to_shost(cdev);\
463 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ 667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
668 struct lpfc_hba *phba = vport->phba;\
464 int val = 0;\ 669 int val = 0;\
465 val = phba->cfg_##attr;\ 670 val = phba->cfg_##attr;\
466 return snprintf(buf, PAGE_SIZE, "%d\n",\ 671 return snprintf(buf, PAGE_SIZE, "%d\n",\
@@ -471,8 +676,9 @@ lpfc_##attr##_show(struct class_device *cdev, char *buf) \
471static ssize_t \ 676static ssize_t \
472lpfc_##attr##_show(struct class_device *cdev, char *buf) \ 677lpfc_##attr##_show(struct class_device *cdev, char *buf) \
473{ \ 678{ \
474 struct Scsi_Host *host = class_to_shost(cdev);\ 679 struct Scsi_Host *shost = class_to_shost(cdev);\
475 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ 680 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
681 struct lpfc_hba *phba = vport->phba;\
476 int val = 0;\ 682 int val = 0;\
477 val = phba->cfg_##attr;\ 683 val = phba->cfg_##attr;\
478 return snprintf(buf, PAGE_SIZE, "%#x\n",\ 684 return snprintf(buf, PAGE_SIZE, "%#x\n",\
@@ -514,8 +720,9 @@ lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
514static ssize_t \ 720static ssize_t \
515lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ 721lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
516{ \ 722{ \
517 struct Scsi_Host *host = class_to_shost(cdev);\ 723 struct Scsi_Host *shost = class_to_shost(cdev);\
518 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ 724 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
725 struct lpfc_hba *phba = vport->phba;\
519 int val=0;\ 726 int val=0;\
520 if (!isdigit(buf[0]))\ 727 if (!isdigit(buf[0]))\
521 return -EINVAL;\ 728 return -EINVAL;\
@@ -576,7 +783,7 @@ static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
576static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); 783static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
577static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); 784static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
578static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); 785static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
579static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL); 786static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
580static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); 787static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
581static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); 788static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
582static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL); 789static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
@@ -592,6 +799,13 @@ static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
592static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, 799static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
593 lpfc_board_mode_show, lpfc_board_mode_store); 800 lpfc_board_mode_show, lpfc_board_mode_store);
594static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); 801static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
802static CLASS_DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
803static CLASS_DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
804static CLASS_DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
805static CLASS_DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
806static CLASS_DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
807static CLASS_DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
808static CLASS_DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
595 809
596 810
597static char *lpfc_soft_wwn_key = "C99G71SL8032A"; 811static char *lpfc_soft_wwn_key = "C99G71SL8032A";
@@ -600,8 +814,9 @@ static ssize_t
600lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf, 814lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
601 size_t count) 815 size_t count)
602{ 816{
603 struct Scsi_Host *host = class_to_shost(cdev); 817 struct Scsi_Host *shost = class_to_shost(cdev);
604 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 818 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
819 struct lpfc_hba *phba = vport->phba;
605 unsigned int cnt = count; 820 unsigned int cnt = count;
606 821
607 /* 822 /*
@@ -634,8 +849,10 @@ static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
634static ssize_t 849static ssize_t
635lpfc_soft_wwpn_show(struct class_device *cdev, char *buf) 850lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
636{ 851{
637 struct Scsi_Host *host = class_to_shost(cdev); 852 struct Scsi_Host *shost = class_to_shost(cdev);
638 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
854 struct lpfc_hba *phba = vport->phba;
855
639 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 856 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
640 (unsigned long long)phba->cfg_soft_wwpn); 857 (unsigned long long)phba->cfg_soft_wwpn);
641} 858}
@@ -644,8 +861,9 @@ lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
644static ssize_t 861static ssize_t
645lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count) 862lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
646{ 863{
647 struct Scsi_Host *host = class_to_shost(cdev); 864 struct Scsi_Host *shost = class_to_shost(cdev);
648 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 865 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
866 struct lpfc_hba *phba = vport->phba;
649 struct completion online_compl; 867 struct completion online_compl;
650 int stat1=0, stat2=0; 868 int stat1=0, stat2=0;
651 unsigned int i, j, cnt=count; 869 unsigned int i, j, cnt=count;
@@ -680,9 +898,9 @@ lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
680 } 898 }
681 } 899 }
682 phba->cfg_soft_wwpn = wwn_to_u64(wwpn); 900 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
683 fc_host_port_name(host) = phba->cfg_soft_wwpn; 901 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
684 if (phba->cfg_soft_wwnn) 902 if (phba->cfg_soft_wwnn)
685 fc_host_node_name(host) = phba->cfg_soft_wwnn; 903 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
686 904
687 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 905 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
688 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); 906 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
@@ -777,6 +995,15 @@ MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
777static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, 995static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
778 lpfc_poll_show, lpfc_poll_store); 996 lpfc_poll_show, lpfc_poll_store);
779 997
998int lpfc_sli_mode = 0;
999module_param(lpfc_sli_mode, int, 0);
1000MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
1001 " 0 - auto (SLI-3 if supported),"
1002 " 2 - select SLI-2 even on SLI-3 capable HBAs,"
1003 " 3 - select SLI-3");
1004
1005LPFC_ATTR_R(npiv_enable, 0, 0, 1, "Enable NPIV functionality");
1006
780/* 1007/*
781# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear 1008# lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
782# until the timer expires. Value range is [0,255]. Default value is 30. 1009# until the timer expires. Value range is [0,255]. Default value is 30.
@@ -790,8 +1017,9 @@ MODULE_PARM_DESC(lpfc_nodev_tmo,
790static ssize_t 1017static ssize_t
791lpfc_nodev_tmo_show(struct class_device *cdev, char *buf) 1018lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
792{ 1019{
793 struct Scsi_Host *host = class_to_shost(cdev); 1020 struct Scsi_Host *shost = class_to_shost(cdev);
794 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1021 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1022 struct lpfc_hba *phba = vport->phba;
795 int val = 0; 1023 int val = 0;
796 val = phba->cfg_devloss_tmo; 1024 val = phba->cfg_devloss_tmo;
797 return snprintf(buf, PAGE_SIZE, "%d\n", 1025 return snprintf(buf, PAGE_SIZE, "%d\n",
@@ -832,13 +1060,19 @@ lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
832static void 1060static void
833lpfc_update_rport_devloss_tmo(struct lpfc_hba *phba) 1061lpfc_update_rport_devloss_tmo(struct lpfc_hba *phba)
834{ 1062{
1063 struct lpfc_vport *vport;
1064 struct Scsi_Host *shost;
835 struct lpfc_nodelist *ndlp; 1065 struct lpfc_nodelist *ndlp;
836 1066
837 spin_lock_irq(phba->host->host_lock); 1067 list_for_each_entry(vport, &phba->port_list, listentry) {
838 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) 1068 shost = lpfc_shost_from_vport(vport);
839 if (ndlp->rport) 1069 spin_lock_irq(shost->host_lock);
840 ndlp->rport->dev_loss_tmo = phba->cfg_devloss_tmo; 1070 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
841 spin_unlock_irq(phba->host->host_lock); 1071 if (ndlp->rport)
1072 ndlp->rport->dev_loss_tmo =
1073 phba->cfg_devloss_tmo;
1074 spin_unlock_irq(shost->host_lock);
1075 }
842} 1076}
843 1077
844static int 1078static int
@@ -946,6 +1180,33 @@ LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
946 "Max number of FCP commands we can queue to a lpfc HBA"); 1180 "Max number of FCP commands we can queue to a lpfc HBA");
947 1181
948/* 1182/*
1183# peer_port_login: This parameter allows/prevents logins
1184# between peer ports hosted on the same physical port.
1185# When this parameter is set 0 peer ports of same physical port
1186# are not allowed to login to each other.
1187# When this parameter is set 1 peer ports of same physical port
1188# are allowed to login to each other.
1189# Default value of this parameter is 0.
1190*/
1191LPFC_ATTR_R(peer_port_login, 0, 0, 1,
1192 "Allow peer ports on the same physical port to login to each "
1193 "other.");
1194
1195/*
1196# vport_restrict_login: This parameter allows/prevents logins
1197# between Virtual Ports and remote initiators.
1198# When this parameter is not set (0) Virtual Ports will accept PLOGIs from
1199# other initiators and will attempt to PLOGI all remote ports.
1200# When this parameter is set (1) Virtual Ports will reject PLOGIs from
1201# remote ports and will not attempt to PLOGI to other initiators.
1202# This parameter does not restrict to the physical port.
1203# This parameter does not restrict logins to Fabric resident remote ports.
1204# Default value of this parameter is 1.
1205*/
1206LPFC_ATTR_RW(vport_restrict_login, 1, 0, 1,
1207 "Restrict virtual ports login to remote initiators.");
1208
1209/*
949# Some disk devices have a "select ID" or "select Target" capability. 1210# Some disk devices have a "select ID" or "select Target" capability.
950# From a protocol standpoint "select ID" usually means select the 1211# From a protocol standpoint "select ID" usually means select the
951# Fibre channel "ALPA". In the FC-AL Profile there is an "informative 1212# Fibre channel "ALPA". In the FC-AL Profile there is an "informative
@@ -1088,7 +1349,8 @@ LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1088LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible"); 1349LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1089 1350
1090 1351
1091struct class_device_attribute *lpfc_host_attrs[] = { 1352
1353struct class_device_attribute *lpfc_hba_attrs[] = {
1092 &class_device_attr_info, 1354 &class_device_attr_info,
1093 &class_device_attr_serialnum, 1355 &class_device_attr_serialnum,
1094 &class_device_attr_modeldesc, 1356 &class_device_attr_modeldesc,
@@ -1104,6 +1366,8 @@ struct class_device_attribute *lpfc_host_attrs[] = {
1104 &class_device_attr_lpfc_log_verbose, 1366 &class_device_attr_lpfc_log_verbose,
1105 &class_device_attr_lpfc_lun_queue_depth, 1367 &class_device_attr_lpfc_lun_queue_depth,
1106 &class_device_attr_lpfc_hba_queue_depth, 1368 &class_device_attr_lpfc_hba_queue_depth,
1369 &class_device_attr_lpfc_peer_port_login,
1370 &class_device_attr_lpfc_vport_restrict_login,
1107 &class_device_attr_lpfc_nodev_tmo, 1371 &class_device_attr_lpfc_nodev_tmo,
1108 &class_device_attr_lpfc_devloss_tmo, 1372 &class_device_attr_lpfc_devloss_tmo,
1109 &class_device_attr_lpfc_fcp_class, 1373 &class_device_attr_lpfc_fcp_class,
@@ -1119,9 +1383,17 @@ struct class_device_attribute *lpfc_host_attrs[] = {
1119 &class_device_attr_lpfc_multi_ring_type, 1383 &class_device_attr_lpfc_multi_ring_type,
1120 &class_device_attr_lpfc_fdmi_on, 1384 &class_device_attr_lpfc_fdmi_on,
1121 &class_device_attr_lpfc_max_luns, 1385 &class_device_attr_lpfc_max_luns,
1386 &class_device_attr_lpfc_npiv_enable,
1122 &class_device_attr_nport_evt_cnt, 1387 &class_device_attr_nport_evt_cnt,
1123 &class_device_attr_management_version, 1388 &class_device_attr_management_version,
1124 &class_device_attr_board_mode, 1389 &class_device_attr_board_mode,
1390 &class_device_attr_max_vpi,
1391 &class_device_attr_used_vpi,
1392 &class_device_attr_max_rpi,
1393 &class_device_attr_used_rpi,
1394 &class_device_attr_max_xri,
1395 &class_device_attr_used_xri,
1396 &class_device_attr_npiv_info,
1125 &class_device_attr_issue_reset, 1397 &class_device_attr_issue_reset,
1126 &class_device_attr_lpfc_poll, 1398 &class_device_attr_lpfc_poll,
1127 &class_device_attr_lpfc_poll_tmo, 1399 &class_device_attr_lpfc_poll_tmo,
@@ -1137,9 +1409,11 @@ sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1137 char *buf, loff_t off, size_t count) 1409 char *buf, loff_t off, size_t count)
1138{ 1410{
1139 size_t buf_off; 1411 size_t buf_off;
1140 struct Scsi_Host *host = class_to_shost(container_of(kobj, 1412 struct class_device *cdev = container_of(kobj, struct class_device,
1141 struct class_device, kobj)); 1413 kobj);
1142 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1414 struct Scsi_Host *shost = class_to_shost(cdev);
1415 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1416 struct lpfc_hba *phba = vport->phba;
1143 1417
1144 if ((off + count) > FF_REG_AREA_SIZE) 1418 if ((off + count) > FF_REG_AREA_SIZE)
1145 return -ERANGE; 1419 return -ERANGE;
@@ -1149,18 +1423,16 @@ sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1149 if (off % 4 || count % 4 || (unsigned long)buf % 4) 1423 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1150 return -EINVAL; 1424 return -EINVAL;
1151 1425
1152 spin_lock_irq(phba->host->host_lock); 1426 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1153
1154 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1155 spin_unlock_irq(phba->host->host_lock);
1156 return -EPERM; 1427 return -EPERM;
1157 } 1428 }
1158 1429
1430 spin_lock_irq(&phba->hbalock);
1159 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) 1431 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1160 writel(*((uint32_t *)(buf + buf_off)), 1432 writel(*((uint32_t *)(buf + buf_off)),
1161 phba->ctrl_regs_memmap_p + off + buf_off); 1433 phba->ctrl_regs_memmap_p + off + buf_off);
1162 1434
1163 spin_unlock_irq(phba->host->host_lock); 1435 spin_unlock_irq(&phba->hbalock);
1164 1436
1165 return count; 1437 return count;
1166} 1438}
@@ -1171,9 +1443,11 @@ sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1171{ 1443{
1172 size_t buf_off; 1444 size_t buf_off;
1173 uint32_t * tmp_ptr; 1445 uint32_t * tmp_ptr;
1174 struct Scsi_Host *host = class_to_shost(container_of(kobj, 1446 struct class_device *cdev = container_of(kobj, struct class_device,
1175 struct class_device, kobj)); 1447 kobj);
1176 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1448 struct Scsi_Host *shost = class_to_shost(cdev);
1449 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1450 struct lpfc_hba *phba = vport->phba;
1177 1451
1178 if (off > FF_REG_AREA_SIZE) 1452 if (off > FF_REG_AREA_SIZE)
1179 return -ERANGE; 1453 return -ERANGE;
@@ -1186,14 +1460,14 @@ sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1186 if (off % 4 || count % 4 || (unsigned long)buf % 4) 1460 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1187 return -EINVAL; 1461 return -EINVAL;
1188 1462
1189 spin_lock_irq(phba->host->host_lock); 1463 spin_lock_irq(&phba->hbalock);
1190 1464
1191 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { 1465 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1192 tmp_ptr = (uint32_t *)(buf + buf_off); 1466 tmp_ptr = (uint32_t *)(buf + buf_off);
1193 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); 1467 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1194 } 1468 }
1195 1469
1196 spin_unlock_irq(phba->host->host_lock); 1470 spin_unlock_irq(&phba->hbalock);
1197 1471
1198 return count; 1472 return count;
1199} 1473}
@@ -1210,7 +1484,7 @@ static struct bin_attribute sysfs_ctlreg_attr = {
1210 1484
1211 1485
1212static void 1486static void
1213sysfs_mbox_idle (struct lpfc_hba * phba) 1487sysfs_mbox_idle(struct lpfc_hba *phba)
1214{ 1488{
1215 phba->sysfs_mbox.state = SMBOX_IDLE; 1489 phba->sysfs_mbox.state = SMBOX_IDLE;
1216 phba->sysfs_mbox.offset = 0; 1490 phba->sysfs_mbox.offset = 0;
@@ -1226,10 +1500,12 @@ static ssize_t
1226sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr, 1500sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1227 char *buf, loff_t off, size_t count) 1501 char *buf, loff_t off, size_t count)
1228{ 1502{
1229 struct Scsi_Host * host = 1503 struct class_device *cdev = container_of(kobj, struct class_device,
1230 class_to_shost(container_of(kobj, struct class_device, kobj)); 1504 kobj);
1231 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata; 1505 struct Scsi_Host *shost = class_to_shost(cdev);
1232 struct lpfcMboxq * mbox = NULL; 1506 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1507 struct lpfc_hba *phba = vport->phba;
1508 struct lpfcMboxq *mbox = NULL;
1233 1509
1234 if ((count + off) > MAILBOX_CMD_SIZE) 1510 if ((count + off) > MAILBOX_CMD_SIZE)
1235 return -ERANGE; 1511 return -ERANGE;
@@ -1247,7 +1523,7 @@ sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1247 memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); 1523 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
1248 } 1524 }
1249 1525
1250 spin_lock_irq(host->host_lock); 1526 spin_lock_irq(&phba->hbalock);
1251 1527
1252 if (off == 0) { 1528 if (off == 0) {
1253 if (phba->sysfs_mbox.mbox) 1529 if (phba->sysfs_mbox.mbox)
@@ -1258,9 +1534,9 @@ sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1258 } else { 1534 } else {
1259 if (phba->sysfs_mbox.state != SMBOX_WRITING || 1535 if (phba->sysfs_mbox.state != SMBOX_WRITING ||
1260 phba->sysfs_mbox.offset != off || 1536 phba->sysfs_mbox.offset != off ||
1261 phba->sysfs_mbox.mbox == NULL ) { 1537 phba->sysfs_mbox.mbox == NULL) {
1262 sysfs_mbox_idle(phba); 1538 sysfs_mbox_idle(phba);
1263 spin_unlock_irq(host->host_lock); 1539 spin_unlock_irq(&phba->hbalock);
1264 return -EAGAIN; 1540 return -EAGAIN;
1265 } 1541 }
1266 } 1542 }
@@ -1270,7 +1546,7 @@ sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
1270 1546
1271 phba->sysfs_mbox.offset = off + count; 1547 phba->sysfs_mbox.offset = off + count;
1272 1548
1273 spin_unlock_irq(host->host_lock); 1549 spin_unlock_irq(&phba->hbalock);
1274 1550
1275 return count; 1551 return count;
1276} 1552}
@@ -1279,10 +1555,11 @@ static ssize_t
1279sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr, 1555sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1280 char *buf, loff_t off, size_t count) 1556 char *buf, loff_t off, size_t count)
1281{ 1557{
1282 struct Scsi_Host *host = 1558 struct class_device *cdev = container_of(kobj, struct class_device,
1283 class_to_shost(container_of(kobj, struct class_device, 1559 kobj);
1284 kobj)); 1560 struct Scsi_Host *shost = class_to_shost(cdev);
1285 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1561 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1562 struct lpfc_hba *phba = vport->phba;
1286 int rc; 1563 int rc;
1287 1564
1288 if (off > MAILBOX_CMD_SIZE) 1565 if (off > MAILBOX_CMD_SIZE)
@@ -1297,7 +1574,7 @@ sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1297 if (off && count == 0) 1574 if (off && count == 0)
1298 return 0; 1575 return 0;
1299 1576
1300 spin_lock_irq(phba->host->host_lock); 1577 spin_lock_irq(&phba->hbalock);
1301 1578
1302 if (off == 0 && 1579 if (off == 0 &&
1303 phba->sysfs_mbox.state == SMBOX_WRITING && 1580 phba->sysfs_mbox.state == SMBOX_WRITING &&
@@ -1320,12 +1597,12 @@ sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1320 case MBX_SET_MASK: 1597 case MBX_SET_MASK:
1321 case MBX_SET_SLIM: 1598 case MBX_SET_SLIM:
1322 case MBX_SET_DEBUG: 1599 case MBX_SET_DEBUG:
1323 if (!(phba->fc_flag & FC_OFFLINE_MODE)) { 1600 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1324 printk(KERN_WARNING "mbox_read:Command 0x%x " 1601 printk(KERN_WARNING "mbox_read:Command 0x%x "
1325 "is illegal in on-line state\n", 1602 "is illegal in on-line state\n",
1326 phba->sysfs_mbox.mbox->mb.mbxCommand); 1603 phba->sysfs_mbox.mbox->mb.mbxCommand);
1327 sysfs_mbox_idle(phba); 1604 sysfs_mbox_idle(phba);
1328 spin_unlock_irq(phba->host->host_lock); 1605 spin_unlock_irq(&phba->hbalock);
1329 return -EPERM; 1606 return -EPERM;
1330 } 1607 }
1331 case MBX_LOAD_SM: 1608 case MBX_LOAD_SM:
@@ -1355,48 +1632,48 @@ sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1355 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", 1632 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1356 phba->sysfs_mbox.mbox->mb.mbxCommand); 1633 phba->sysfs_mbox.mbox->mb.mbxCommand);
1357 sysfs_mbox_idle(phba); 1634 sysfs_mbox_idle(phba);
1358 spin_unlock_irq(phba->host->host_lock); 1635 spin_unlock_irq(&phba->hbalock);
1359 return -EPERM; 1636 return -EPERM;
1360 default: 1637 default:
1361 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", 1638 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1362 phba->sysfs_mbox.mbox->mb.mbxCommand); 1639 phba->sysfs_mbox.mbox->mb.mbxCommand);
1363 sysfs_mbox_idle(phba); 1640 sysfs_mbox_idle(phba);
1364 spin_unlock_irq(phba->host->host_lock); 1641 spin_unlock_irq(&phba->hbalock);
1365 return -EPERM; 1642 return -EPERM;
1366 } 1643 }
1367 1644
1368 if (phba->fc_flag & FC_BLOCK_MGMT_IO) { 1645 phba->sysfs_mbox.mbox->vport = vport;
1646
1647 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
1369 sysfs_mbox_idle(phba); 1648 sysfs_mbox_idle(phba);
1370 spin_unlock_irq(host->host_lock); 1649 spin_unlock_irq(&phba->hbalock);
1371 return -EAGAIN; 1650 return -EAGAIN;
1372 } 1651 }
1373 1652
1374 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1653 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1375 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ 1654 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1376 1655
1377 spin_unlock_irq(phba->host->host_lock); 1656 spin_unlock_irq(&phba->hbalock);
1378 rc = lpfc_sli_issue_mbox (phba, 1657 rc = lpfc_sli_issue_mbox (phba,
1379 phba->sysfs_mbox.mbox, 1658 phba->sysfs_mbox.mbox,
1380 MBX_POLL); 1659 MBX_POLL);
1381 spin_lock_irq(phba->host->host_lock); 1660 spin_lock_irq(&phba->hbalock);
1382 1661
1383 } else { 1662 } else {
1384 spin_unlock_irq(phba->host->host_lock); 1663 spin_unlock_irq(&phba->hbalock);
1385 rc = lpfc_sli_issue_mbox_wait (phba, 1664 rc = lpfc_sli_issue_mbox_wait (phba,
1386 phba->sysfs_mbox.mbox, 1665 phba->sysfs_mbox.mbox,
1387 lpfc_mbox_tmo_val(phba, 1666 lpfc_mbox_tmo_val(phba,
1388 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ); 1667 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
1389 spin_lock_irq(phba->host->host_lock); 1668 spin_lock_irq(&phba->hbalock);
1390 } 1669 }
1391 1670
1392 if (rc != MBX_SUCCESS) { 1671 if (rc != MBX_SUCCESS) {
1393 if (rc == MBX_TIMEOUT) { 1672 if (rc == MBX_TIMEOUT) {
1394 phba->sysfs_mbox.mbox->mbox_cmpl =
1395 lpfc_sli_def_mbox_cmpl;
1396 phba->sysfs_mbox.mbox = NULL; 1673 phba->sysfs_mbox.mbox = NULL;
1397 } 1674 }
1398 sysfs_mbox_idle(phba); 1675 sysfs_mbox_idle(phba);
1399 spin_unlock_irq(host->host_lock); 1676 spin_unlock_irq(&phba->hbalock);
1400 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; 1677 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1401 } 1678 }
1402 phba->sysfs_mbox.state = SMBOX_READING; 1679 phba->sysfs_mbox.state = SMBOX_READING;
@@ -1405,7 +1682,7 @@ sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1405 phba->sysfs_mbox.state != SMBOX_READING) { 1682 phba->sysfs_mbox.state != SMBOX_READING) {
1406 printk(KERN_WARNING "mbox_read: Bad State\n"); 1683 printk(KERN_WARNING "mbox_read: Bad State\n");
1407 sysfs_mbox_idle(phba); 1684 sysfs_mbox_idle(phba);
1408 spin_unlock_irq(host->host_lock); 1685 spin_unlock_irq(&phba->hbalock);
1409 return -EAGAIN; 1686 return -EAGAIN;
1410 } 1687 }
1411 1688
@@ -1416,7 +1693,7 @@ sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
1416 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) 1693 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
1417 sysfs_mbox_idle(phba); 1694 sysfs_mbox_idle(phba);
1418 1695
1419 spin_unlock_irq(phba->host->host_lock); 1696 spin_unlock_irq(&phba->hbalock);
1420 1697
1421 return count; 1698 return count;
1422} 1699}
@@ -1432,35 +1709,35 @@ static struct bin_attribute sysfs_mbox_attr = {
1432}; 1709};
1433 1710
1434int 1711int
1435lpfc_alloc_sysfs_attr(struct lpfc_hba *phba) 1712lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
1436{ 1713{
1437 struct Scsi_Host *host = phba->host; 1714 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1438 int error; 1715 int error;
1439 1716
1440 error = sysfs_create_bin_file(&host->shost_classdev.kobj, 1717 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1441 &sysfs_ctlreg_attr); 1718 &sysfs_ctlreg_attr);
1442 if (error) 1719 if (error)
1443 goto out; 1720 goto out;
1444 1721
1445 error = sysfs_create_bin_file(&host->shost_classdev.kobj, 1722 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1446 &sysfs_mbox_attr); 1723 &sysfs_mbox_attr);
1447 if (error) 1724 if (error)
1448 goto out_remove_ctlreg_attr; 1725 goto out_remove_ctlreg_attr;
1449 1726
1450 return 0; 1727 return 0;
1451out_remove_ctlreg_attr: 1728out_remove_ctlreg_attr:
1452 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); 1729 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1453out: 1730out:
1454 return error; 1731 return error;
1455} 1732}
1456 1733
1457void 1734void
1458lpfc_free_sysfs_attr(struct lpfc_hba *phba) 1735lpfc_free_sysfs_attr(struct lpfc_vport *vport)
1459{ 1736{
1460 struct Scsi_Host *host = phba->host; 1737 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1461 1738
1462 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr); 1739 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1463 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); 1740 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1464} 1741}
1465 1742
1466 1743
@@ -1471,26 +1748,30 @@ lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1471static void 1748static void
1472lpfc_get_host_port_id(struct Scsi_Host *shost) 1749lpfc_get_host_port_id(struct Scsi_Host *shost)
1473{ 1750{
1474 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1752
1475 /* note: fc_myDID already in cpu endianness */ 1753 /* note: fc_myDID already in cpu endianness */
1476 fc_host_port_id(shost) = phba->fc_myDID; 1754 fc_host_port_id(shost) = vport->fc_myDID;
1477} 1755}
1478 1756
1479static void 1757static void
1480lpfc_get_host_port_type(struct Scsi_Host *shost) 1758lpfc_get_host_port_type(struct Scsi_Host *shost)
1481{ 1759{
1482 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1760 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1761 struct lpfc_hba *phba = vport->phba;
1483 1762
1484 spin_lock_irq(shost->host_lock); 1763 spin_lock_irq(shost->host_lock);
1485 1764
1486 if (phba->hba_state == LPFC_HBA_READY) { 1765 if (vport->port_type == LPFC_NPIV_PORT) {
1766 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1767 } else if (lpfc_is_link_up(phba)) {
1487 if (phba->fc_topology == TOPOLOGY_LOOP) { 1768 if (phba->fc_topology == TOPOLOGY_LOOP) {
1488 if (phba->fc_flag & FC_PUBLIC_LOOP) 1769 if (vport->fc_flag & FC_PUBLIC_LOOP)
1489 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 1770 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1490 else 1771 else
1491 fc_host_port_type(shost) = FC_PORTTYPE_LPORT; 1772 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1492 } else { 1773 } else {
1493 if (phba->fc_flag & FC_FABRIC) 1774 if (vport->fc_flag & FC_FABRIC)
1494 fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 1775 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1495 else 1776 else
1496 fc_host_port_type(shost) = FC_PORTTYPE_PTP; 1777 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
@@ -1504,29 +1785,20 @@ lpfc_get_host_port_type(struct Scsi_Host *shost)
1504static void 1785static void
1505lpfc_get_host_port_state(struct Scsi_Host *shost) 1786lpfc_get_host_port_state(struct Scsi_Host *shost)
1506{ 1787{
1507 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1788 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1789 struct lpfc_hba *phba = vport->phba;
1508 1790
1509 spin_lock_irq(shost->host_lock); 1791 spin_lock_irq(shost->host_lock);
1510 1792
1511 if (phba->fc_flag & FC_OFFLINE_MODE) 1793 if (vport->fc_flag & FC_OFFLINE_MODE)
1512 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 1794 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1513 else { 1795 else {
1514 switch (phba->hba_state) { 1796 switch (phba->link_state) {
1515 case LPFC_STATE_UNKNOWN: 1797 case LPFC_LINK_UNKNOWN:
1516 case LPFC_WARM_START:
1517 case LPFC_INIT_START:
1518 case LPFC_INIT_MBX_CMDS:
1519 case LPFC_LINK_DOWN: 1798 case LPFC_LINK_DOWN:
1520 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 1799 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1521 break; 1800 break;
1522 case LPFC_LINK_UP: 1801 case LPFC_LINK_UP:
1523 case LPFC_LOCAL_CFG_LINK:
1524 case LPFC_FLOGI:
1525 case LPFC_FABRIC_CFG_LINK:
1526 case LPFC_NS_REG:
1527 case LPFC_NS_QRY:
1528 case LPFC_BUILD_DISC_LIST:
1529 case LPFC_DISC_AUTH:
1530 case LPFC_CLEAR_LA: 1802 case LPFC_CLEAR_LA:
1531 case LPFC_HBA_READY: 1803 case LPFC_HBA_READY:
1532 /* Links up, beyond this port_type reports state */ 1804 /* Links up, beyond this port_type reports state */
@@ -1547,11 +1819,12 @@ lpfc_get_host_port_state(struct Scsi_Host *shost)
1547static void 1819static void
1548lpfc_get_host_speed(struct Scsi_Host *shost) 1820lpfc_get_host_speed(struct Scsi_Host *shost)
1549{ 1821{
1550 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1822 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1823 struct lpfc_hba *phba = vport->phba;
1551 1824
1552 spin_lock_irq(shost->host_lock); 1825 spin_lock_irq(shost->host_lock);
1553 1826
1554 if (phba->hba_state == LPFC_HBA_READY) { 1827 if (lpfc_is_link_up(phba)) {
1555 switch(phba->fc_linkspeed) { 1828 switch(phba->fc_linkspeed) {
1556 case LA_1GHZ_LINK: 1829 case LA_1GHZ_LINK:
1557 fc_host_speed(shost) = FC_PORTSPEED_1GBIT; 1830 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
@@ -1577,39 +1850,31 @@ lpfc_get_host_speed(struct Scsi_Host *shost)
1577static void 1850static void
1578lpfc_get_host_fabric_name (struct Scsi_Host *shost) 1851lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1579{ 1852{
1580 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1853 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1854 struct lpfc_hba *phba = vport->phba;
1581 u64 node_name; 1855 u64 node_name;
1582 1856
1583 spin_lock_irq(shost->host_lock); 1857 spin_lock_irq(shost->host_lock);
1584 1858
1585 if ((phba->fc_flag & FC_FABRIC) || 1859 if ((vport->fc_flag & FC_FABRIC) ||
1586 ((phba->fc_topology == TOPOLOGY_LOOP) && 1860 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1587 (phba->fc_flag & FC_PUBLIC_LOOP))) 1861 (vport->fc_flag & FC_PUBLIC_LOOP)))
1588 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); 1862 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
1589 else 1863 else
1590 /* fabric is local port if there is no F/FL_Port */ 1864 /* fabric is local port if there is no F/FL_Port */
1591 node_name = wwn_to_u64(phba->fc_nodename.u.wwn); 1865 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
1592 1866
1593 spin_unlock_irq(shost->host_lock); 1867 spin_unlock_irq(shost->host_lock);
1594 1868
1595 fc_host_fabric_name(shost) = node_name; 1869 fc_host_fabric_name(shost) = node_name;
1596} 1870}
1597 1871
1598static void
1599lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1600{
1601 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1602
1603 spin_lock_irq(shost->host_lock);
1604 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1605 spin_unlock_irq(shost->host_lock);
1606}
1607
1608static struct fc_host_statistics * 1872static struct fc_host_statistics *
1609lpfc_get_stats(struct Scsi_Host *shost) 1873lpfc_get_stats(struct Scsi_Host *shost)
1610{ 1874{
1611 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1875 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1612 struct lpfc_sli *psli = &phba->sli; 1876 struct lpfc_hba *phba = vport->phba;
1877 struct lpfc_sli *psli = &phba->sli;
1613 struct fc_host_statistics *hs = &phba->link_stats; 1878 struct fc_host_statistics *hs = &phba->link_stats;
1614 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; 1879 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1615 LPFC_MBOXQ_t *pmboxq; 1880 LPFC_MBOXQ_t *pmboxq;
@@ -1617,7 +1882,16 @@ lpfc_get_stats(struct Scsi_Host *shost)
1617 unsigned long seconds; 1882 unsigned long seconds;
1618 int rc = 0; 1883 int rc = 0;
1619 1884
1620 if (phba->fc_flag & FC_BLOCK_MGMT_IO) 1885 /*
1886 * prevent udev from issuing mailbox commands until the port is
1887 * configured.
1888 */
1889 if (phba->link_state < LPFC_LINK_DOWN ||
1890 !phba->mbox_mem_pool ||
1891 (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
1892 return NULL;
1893
1894 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1621 return NULL; 1895 return NULL;
1622 1896
1623 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1897 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -1629,17 +1903,16 @@ lpfc_get_stats(struct Scsi_Host *shost)
1629 pmb->mbxCommand = MBX_READ_STATUS; 1903 pmb->mbxCommand = MBX_READ_STATUS;
1630 pmb->mbxOwner = OWN_HOST; 1904 pmb->mbxOwner = OWN_HOST;
1631 pmboxq->context1 = NULL; 1905 pmboxq->context1 = NULL;
1906 pmboxq->vport = vport;
1632 1907
1633 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1908 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1634 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1909 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1635 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1910 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1636 else 1911 else
1637 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 1912 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1638 1913
1639 if (rc != MBX_SUCCESS) { 1914 if (rc != MBX_SUCCESS) {
1640 if (rc == MBX_TIMEOUT) 1915 if (rc != MBX_TIMEOUT)
1641 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1642 else
1643 mempool_free(pmboxq, phba->mbox_mem_pool); 1916 mempool_free(pmboxq, phba->mbox_mem_pool);
1644 return NULL; 1917 return NULL;
1645 } 1918 }
@@ -1655,18 +1928,17 @@ lpfc_get_stats(struct Scsi_Host *shost)
1655 pmb->mbxCommand = MBX_READ_LNK_STAT; 1928 pmb->mbxCommand = MBX_READ_LNK_STAT;
1656 pmb->mbxOwner = OWN_HOST; 1929 pmb->mbxOwner = OWN_HOST;
1657 pmboxq->context1 = NULL; 1930 pmboxq->context1 = NULL;
1931 pmboxq->vport = vport;
1658 1932
1659 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1933 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1660 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1934 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1661 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1935 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1662 else 1936 else
1663 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 1937 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1664 1938
1665 if (rc != MBX_SUCCESS) { 1939 if (rc != MBX_SUCCESS) {
1666 if (rc == MBX_TIMEOUT) 1940 if (rc != MBX_TIMEOUT)
1667 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 1941 mempool_free(pmboxq, phba->mbox_mem_pool);
1668 else
1669 mempool_free( pmboxq, phba->mbox_mem_pool);
1670 return NULL; 1942 return NULL;
1671 } 1943 }
1672 1944
@@ -1713,14 +1985,15 @@ lpfc_get_stats(struct Scsi_Host *shost)
1713static void 1985static void
1714lpfc_reset_stats(struct Scsi_Host *shost) 1986lpfc_reset_stats(struct Scsi_Host *shost)
1715{ 1987{
1716 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1988 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1717 struct lpfc_sli *psli = &phba->sli; 1989 struct lpfc_hba *phba = vport->phba;
1718 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; 1990 struct lpfc_sli *psli = &phba->sli;
1991 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
1719 LPFC_MBOXQ_t *pmboxq; 1992 LPFC_MBOXQ_t *pmboxq;
1720 MAILBOX_t *pmb; 1993 MAILBOX_t *pmb;
1721 int rc = 0; 1994 int rc = 0;
1722 1995
1723 if (phba->fc_flag & FC_BLOCK_MGMT_IO) 1996 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1724 return; 1997 return;
1725 1998
1726 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1999 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -1733,17 +2006,16 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1733 pmb->mbxOwner = OWN_HOST; 2006 pmb->mbxOwner = OWN_HOST;
1734 pmb->un.varWords[0] = 0x1; /* reset request */ 2007 pmb->un.varWords[0] = 0x1; /* reset request */
1735 pmboxq->context1 = NULL; 2008 pmboxq->context1 = NULL;
2009 pmboxq->vport = vport;
1736 2010
1737 if ((phba->fc_flag & FC_OFFLINE_MODE) || 2011 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1738 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 2012 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1739 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 2013 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1740 else 2014 else
1741 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 2015 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1742 2016
1743 if (rc != MBX_SUCCESS) { 2017 if (rc != MBX_SUCCESS) {
1744 if (rc == MBX_TIMEOUT) 2018 if (rc != MBX_TIMEOUT)
1745 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1746 else
1747 mempool_free(pmboxq, phba->mbox_mem_pool); 2019 mempool_free(pmboxq, phba->mbox_mem_pool);
1748 return; 2020 return;
1749 } 2021 }
@@ -1752,17 +2024,16 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1752 pmb->mbxCommand = MBX_READ_LNK_STAT; 2024 pmb->mbxCommand = MBX_READ_LNK_STAT;
1753 pmb->mbxOwner = OWN_HOST; 2025 pmb->mbxOwner = OWN_HOST;
1754 pmboxq->context1 = NULL; 2026 pmboxq->context1 = NULL;
2027 pmboxq->vport = vport;
1755 2028
1756 if ((phba->fc_flag & FC_OFFLINE_MODE) || 2029 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1757 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 2030 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1758 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 2031 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1759 else 2032 else
1760 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); 2033 rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
1761 2034
1762 if (rc != MBX_SUCCESS) { 2035 if (rc != MBX_SUCCESS) {
1763 if (rc == MBX_TIMEOUT) 2036 if (rc != MBX_TIMEOUT)
1764 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1765 else
1766 mempool_free( pmboxq, phba->mbox_mem_pool); 2037 mempool_free( pmboxq, phba->mbox_mem_pool);
1767 return; 2038 return;
1768 } 2039 }
@@ -1791,13 +2062,13 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1791static struct lpfc_nodelist * 2062static struct lpfc_nodelist *
1792lpfc_get_node_by_target(struct scsi_target *starget) 2063lpfc_get_node_by_target(struct scsi_target *starget)
1793{ 2064{
1794 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 2065 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1795 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata; 2066 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1796 struct lpfc_nodelist *ndlp; 2067 struct lpfc_nodelist *ndlp;
1797 2068
1798 spin_lock_irq(shost->host_lock); 2069 spin_lock_irq(shost->host_lock);
1799 /* Search for this, mapped, target ID */ 2070 /* Search for this, mapped, target ID */
1800 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) { 2071 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1801 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && 2072 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1802 starget->id == ndlp->nlp_sid) { 2073 starget->id == ndlp->nlp_sid) {
1803 spin_unlock_irq(shost->host_lock); 2074 spin_unlock_irq(shost->host_lock);
@@ -1887,8 +2158,66 @@ struct fc_function_template lpfc_transport_functions = {
1887 .get_host_fabric_name = lpfc_get_host_fabric_name, 2158 .get_host_fabric_name = lpfc_get_host_fabric_name,
1888 .show_host_fabric_name = 1, 2159 .show_host_fabric_name = 1,
1889 2160
1890 .get_host_symbolic_name = lpfc_get_host_symbolic_name, 2161 /*
1891 .show_host_symbolic_name = 1, 2162 * The LPFC driver treats linkdown handling as target loss events
2163 * so there are no sysfs handlers for link_down_tmo.
2164 */
2165
2166 .get_fc_host_stats = lpfc_get_stats,
2167 .reset_fc_host_stats = lpfc_reset_stats,
2168
2169 .dd_fcrport_size = sizeof(struct lpfc_rport_data),
2170 .show_rport_maxframe_size = 1,
2171 .show_rport_supported_classes = 1,
2172
2173 .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
2174 .show_rport_dev_loss_tmo = 1,
2175
2176 .get_starget_port_id = lpfc_get_starget_port_id,
2177 .show_starget_port_id = 1,
2178
2179 .get_starget_node_name = lpfc_get_starget_node_name,
2180 .show_starget_node_name = 1,
2181
2182 .get_starget_port_name = lpfc_get_starget_port_name,
2183 .show_starget_port_name = 1,
2184
2185 .issue_fc_host_lip = lpfc_issue_lip,
2186 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
2187 .terminate_rport_io = lpfc_terminate_rport_io,
2188
2189 .vport_create = lpfc_vport_create,
2190 .vport_delete = lpfc_vport_delete,
2191 .dd_fcvport_size = sizeof(struct lpfc_vport *),
2192};
2193
2194struct fc_function_template lpfc_vport_transport_functions = {
2195 /* fixed attributes the driver supports */
2196 .show_host_node_name = 1,
2197 .show_host_port_name = 1,
2198 .show_host_supported_classes = 1,
2199 .show_host_supported_fc4s = 1,
2200 .show_host_supported_speeds = 1,
2201 .show_host_maxframe_size = 1,
2202
2203 /* dynamic attributes the driver supports */
2204 .get_host_port_id = lpfc_get_host_port_id,
2205 .show_host_port_id = 1,
2206
2207 .get_host_port_type = lpfc_get_host_port_type,
2208 .show_host_port_type = 1,
2209
2210 .get_host_port_state = lpfc_get_host_port_state,
2211 .show_host_port_state = 1,
2212
2213 /* active_fc4s is shown but doesn't change (thus no get function) */
2214 .show_host_active_fc4s = 1,
2215
2216 .get_host_speed = lpfc_get_host_speed,
2217 .show_host_speed = 1,
2218
2219 .get_host_fabric_name = lpfc_get_host_fabric_name,
2220 .show_host_fabric_name = 1,
1892 2221
1893 /* 2222 /*
1894 * The LPFC driver treats linkdown handling as target loss events 2223 * The LPFC driver treats linkdown handling as target loss events
@@ -1917,6 +2246,8 @@ struct fc_function_template lpfc_transport_functions = {
1917 .issue_fc_host_lip = lpfc_issue_lip, 2246 .issue_fc_host_lip = lpfc_issue_lip,
1918 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, 2247 .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
1919 .terminate_rport_io = lpfc_terminate_rport_io, 2248 .terminate_rport_io = lpfc_terminate_rport_io,
2249
2250 .vport_disable = lpfc_vport_disable,
1920}; 2251};
1921 2252
1922void 2253void
@@ -1939,6 +2270,9 @@ lpfc_get_cfgparam(struct lpfc_hba *phba)
1939 lpfc_discovery_threads_init(phba, lpfc_discovery_threads); 2270 lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
1940 lpfc_max_luns_init(phba, lpfc_max_luns); 2271 lpfc_max_luns_init(phba, lpfc_max_luns);
1941 lpfc_poll_tmo_init(phba, lpfc_poll_tmo); 2272 lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
2273 lpfc_peer_port_login_init(phba, lpfc_peer_port_login);
2274 lpfc_npiv_enable_init(phba, lpfc_npiv_enable);
2275 lpfc_vport_restrict_login_init(phba, lpfc_vport_restrict_login);
1942 lpfc_use_msi_init(phba, lpfc_use_msi); 2276 lpfc_use_msi_init(phba, lpfc_use_msi);
1943 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo); 2277 lpfc_devloss_tmo_init(phba, lpfc_devloss_tmo);
1944 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo); 2278 lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);