aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_attr.c
diff options
context:
space:
mode:
authorJames Smart <James.Smart@Emulex.Com>2007-06-17 20:56:36 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2007-06-17 23:05:45 -0400
commit2e0fef85e098f6794956b8b80b111179fbb4cbb7 (patch)
treef632090be67f95e9a637eeb044938ba1591e848f /drivers/scsi/lpfc/lpfc_attr.c
parent4c2baaaf2ba4875d1d2d59b3b3e1216d3277b17a (diff)
[SCSI] lpfc: NPIV: split ports
The driver is reorganized to separate the handling of the adapter from the handling of the FC port. Adapter handling includes submissions of command requests, receiving responses, and managing adapter resources. The FC port includes the discovery engine, login handling, and the mapping of a Scsi_Host on the "port". Although not a large functional change, as it touches core structures and functions, resulting in a large text delta. Signed-off-by: James Smart <James.Smart@emulex.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_attr.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c443
1 files changed, 239 insertions, 204 deletions
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 95fe77e816f8..b8adff8cea6a 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -76,55 +76,68 @@ static ssize_t
76lpfc_info_show(struct class_device *cdev, char *buf) 76lpfc_info_show(struct class_device *cdev, char *buf)
77{ 77{
78 struct Scsi_Host *host = class_to_shost(cdev); 78 struct Scsi_Host *host = class_to_shost(cdev);
79
79 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); 80 return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
80} 81}
81 82
82static ssize_t 83static ssize_t
83lpfc_serialnum_show(struct class_device *cdev, char *buf) 84lpfc_serialnum_show(struct class_device *cdev, char *buf)
84{ 85{
85 struct Scsi_Host *host = class_to_shost(cdev); 86 struct Scsi_Host *shost = class_to_shost(cdev);
86 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 87 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
88 struct lpfc_hba *phba = vport->phba;
89
87 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); 90 return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
88} 91}
89 92
90static ssize_t 93static ssize_t
91lpfc_modeldesc_show(struct class_device *cdev, char *buf) 94lpfc_modeldesc_show(struct class_device *cdev, char *buf)
92{ 95{
93 struct Scsi_Host *host = class_to_shost(cdev); 96 struct Scsi_Host *shost = class_to_shost(cdev);
94 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 97 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
98 struct lpfc_hba *phba = vport->phba;
99
95 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); 100 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
96} 101}
97 102
98static ssize_t 103static ssize_t
99lpfc_modelname_show(struct class_device *cdev, char *buf) 104lpfc_modelname_show(struct class_device *cdev, char *buf)
100{ 105{
101 struct Scsi_Host *host = class_to_shost(cdev); 106 struct Scsi_Host *shost = class_to_shost(cdev);
102 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 107 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
108 struct lpfc_hba *phba = vport->phba;
109
103 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); 110 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
104} 111}
105 112
106static ssize_t 113static ssize_t
107lpfc_programtype_show(struct class_device *cdev, char *buf) 114lpfc_programtype_show(struct class_device *cdev, char *buf)
108{ 115{
109 struct Scsi_Host *host = class_to_shost(cdev); 116 struct Scsi_Host *shost = class_to_shost(cdev);
110 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 117 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
118 struct lpfc_hba *phba = vport->phba;
119
111 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); 120 return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
112} 121}
113 122
114static ssize_t 123static ssize_t
115lpfc_portnum_show(struct class_device *cdev, char *buf) 124lpfc_vportnum_show(struct class_device *cdev, char *buf)
116{ 125{
117 struct Scsi_Host *host = class_to_shost(cdev); 126 struct Scsi_Host *shost = class_to_shost(cdev);
118 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 127 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
128 struct lpfc_hba *phba = vport->phba;
129
119 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); 130 return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
120} 131}
121 132
122static ssize_t 133static ssize_t
123lpfc_fwrev_show(struct class_device *cdev, char *buf) 134lpfc_fwrev_show(struct class_device *cdev, char *buf)
124{ 135{
125 struct Scsi_Host *host = class_to_shost(cdev); 136 struct Scsi_Host *shost = class_to_shost(cdev);
126 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 137 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
138 struct lpfc_hba *phba = vport->phba;
127 char fwrev[32]; 139 char fwrev[32];
140
128 lpfc_decode_firmware_rev(phba, fwrev, 1); 141 lpfc_decode_firmware_rev(phba, fwrev, 1);
129 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev); 142 return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
130} 143}
@@ -133,59 +146,80 @@ static ssize_t
133lpfc_hdw_show(struct class_device *cdev, char *buf) 146lpfc_hdw_show(struct class_device *cdev, char *buf)
134{ 147{
135 char hdw[9]; 148 char hdw[9];
136 struct Scsi_Host *host = class_to_shost(cdev); 149 struct Scsi_Host *shost = class_to_shost(cdev);
137 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 150 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
151 struct lpfc_hba *phba = vport->phba;
138 lpfc_vpd_t *vp = &phba->vpd; 152 lpfc_vpd_t *vp = &phba->vpd;
153
139 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); 154 lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
140 return snprintf(buf, PAGE_SIZE, "%s\n", hdw); 155 return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
141} 156}
142static ssize_t 157static ssize_t
143lpfc_option_rom_version_show(struct class_device *cdev, char *buf) 158lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
144{ 159{
145 struct Scsi_Host *host = class_to_shost(cdev); 160 struct Scsi_Host *shost = class_to_shost(cdev);
146 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 161 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
162 struct lpfc_hba *phba = vport->phba;
163
147 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); 164 return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
148} 165}
149static ssize_t 166static ssize_t
150lpfc_state_show(struct class_device *cdev, char *buf) 167lpfc_state_show(struct class_device *cdev, char *buf)
151{ 168{
152 struct Scsi_Host *host = class_to_shost(cdev); 169 struct Scsi_Host *shost = class_to_shost(cdev);
153 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 170 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
154 int len = 0; 171 struct lpfc_hba *phba = vport->phba;
155 switch (phba->hba_state) { 172 int len = 0;
156 case LPFC_STATE_UNKNOWN: 173
174 switch (phba->link_state) {
175 case LPFC_LINK_UNKNOWN:
157 case LPFC_WARM_START: 176 case LPFC_WARM_START:
158 case LPFC_INIT_START: 177 case LPFC_INIT_START:
159 case LPFC_INIT_MBX_CMDS: 178 case LPFC_INIT_MBX_CMDS:
160 case LPFC_LINK_DOWN: 179 case LPFC_LINK_DOWN:
161 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); 180 case LPFC_HBA_ERROR:
181 len += snprintf(buf + len, PAGE_SIZE-len, "Link Down");
162 break; 182 break;
163 case LPFC_LINK_UP: 183 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: 184 case LPFC_CLEAR_LA:
174 len += snprintf(buf + len, PAGE_SIZE-len, 185 len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - \n");
175 "Link Up - Discovery\n"); 186
176 break; 187 switch (vport->port_state) {
177 case LPFC_HBA_READY: 188 len += snprintf(buf + len, PAGE_SIZE-len,
178 len += snprintf(buf + len, PAGE_SIZE-len, 189 "initializing\n");
179 "Link Up - Ready:\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
180 if (phba->fc_topology == TOPOLOGY_LOOP) { 214 if (phba->fc_topology == TOPOLOGY_LOOP) {
181 if (phba->fc_flag & FC_PUBLIC_LOOP) 215 if (vport->fc_flag & FC_PUBLIC_LOOP)
182 len += snprintf(buf + len, PAGE_SIZE-len, 216 len += snprintf(buf + len, PAGE_SIZE-len,
183 " Public Loop\n"); 217 " Public Loop\n");
184 else 218 else
185 len += snprintf(buf + len, PAGE_SIZE-len, 219 len += snprintf(buf + len, PAGE_SIZE-len,
186 " Private Loop\n"); 220 " Private Loop\n");
187 } else { 221 } else {
188 if (phba->fc_flag & FC_FABRIC) 222 if (vport->fc_flag & FC_FABRIC)
189 len += snprintf(buf + len, PAGE_SIZE-len, 223 len += snprintf(buf + len, PAGE_SIZE-len,
190 " Fabric\n"); 224 " Fabric\n");
191 else 225 else
@@ -193,29 +227,32 @@ lpfc_state_show(struct class_device *cdev, char *buf)
193 " Point-2-Point\n"); 227 " Point-2-Point\n");
194 } 228 }
195 } 229 }
230
196 return len; 231 return len;
197} 232}
198 233
199static ssize_t 234static ssize_t
200lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf) 235lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
201{ 236{
202 struct Scsi_Host *host = class_to_shost(cdev); 237 struct Scsi_Host *shost = class_to_shost(cdev);
203 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 238 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
204 return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt + 239
205 phba->fc_unmap_cnt); 240 return snprintf(buf, PAGE_SIZE, "%d\n",
241 vport->fc_map_cnt + vport->fc_unmap_cnt);
206} 242}
207 243
208 244
209static int 245static int
210lpfc_issue_lip(struct Scsi_Host *host) 246lpfc_issue_lip(struct Scsi_Host *shost)
211{ 247{
212 struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata; 248 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
249 struct lpfc_hba *phba = vport->phba;
213 LPFC_MBOXQ_t *pmboxq; 250 LPFC_MBOXQ_t *pmboxq;
214 int mbxstatus = MBXERR_ERROR; 251 int mbxstatus = MBXERR_ERROR;
215 252
216 if ((phba->fc_flag & FC_OFFLINE_MODE) || 253 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
217 (phba->fc_flag & FC_BLOCK_MGMT_IO) || 254 (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) ||
218 (phba->hba_state != LPFC_HBA_READY)) 255 (vport->port_state != LPFC_VPORT_READY))
219 return -EPERM; 256 return -EPERM;
220 257
221 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); 258 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
@@ -320,8 +357,10 @@ lpfc_selective_reset(struct lpfc_hba *phba)
320static ssize_t 357static ssize_t
321lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count) 358lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
322{ 359{
323 struct Scsi_Host *host = class_to_shost(cdev); 360 struct Scsi_Host *shost = class_to_shost(cdev);
324 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 361 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
362 struct lpfc_hba *phba = vport->phba;
363
325 int status = -EINVAL; 364 int status = -EINVAL;
326 365
327 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) 366 if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
@@ -336,23 +375,26 @@ lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
336static ssize_t 375static ssize_t
337lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf) 376lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
338{ 377{
339 struct Scsi_Host *host = class_to_shost(cdev); 378 struct Scsi_Host *shost = class_to_shost(cdev);
340 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 379 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
380 struct lpfc_hba *phba = vport->phba;
381
341 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); 382 return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
342} 383}
343 384
344static ssize_t 385static ssize_t
345lpfc_board_mode_show(struct class_device *cdev, char *buf) 386lpfc_board_mode_show(struct class_device *cdev, char *buf)
346{ 387{
347 struct Scsi_Host *host = class_to_shost(cdev); 388 struct Scsi_Host *shost = class_to_shost(cdev);
348 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 389 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
390 struct lpfc_hba *phba = vport->phba;
349 char * state; 391 char * state;
350 392
351 if (phba->hba_state == LPFC_HBA_ERROR) 393 if (phba->link_state == LPFC_HBA_ERROR)
352 state = "error"; 394 state = "error";
353 else if (phba->hba_state == LPFC_WARM_START) 395 else if (phba->link_state == LPFC_WARM_START)
354 state = "warm start"; 396 state = "warm start";
355 else if (phba->hba_state == LPFC_INIT_START) 397 else if (phba->link_state == LPFC_INIT_START)
356 state = "offline"; 398 state = "offline";
357 else 399 else
358 state = "online"; 400 state = "online";
@@ -363,8 +405,9 @@ lpfc_board_mode_show(struct class_device *cdev, char *buf)
363static ssize_t 405static ssize_t
364lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count) 406lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
365{ 407{
366 struct Scsi_Host *host = class_to_shost(cdev); 408 struct Scsi_Host *shost = class_to_shost(cdev);
367 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 409 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
410 struct lpfc_hba *phba = vport->phba;
368 struct completion online_compl; 411 struct completion online_compl;
369 int status=0; 412 int status=0;
370 413
@@ -392,8 +435,9 @@ lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
392static ssize_t 435static ssize_t
393lpfc_poll_show(struct class_device *cdev, char *buf) 436lpfc_poll_show(struct class_device *cdev, char *buf)
394{ 437{
395 struct Scsi_Host *host = class_to_shost(cdev); 438 struct Scsi_Host *shost = class_to_shost(cdev);
396 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 439 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
440 struct lpfc_hba *phba = vport->phba;
397 441
398 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); 442 return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
399} 443}
@@ -402,8 +446,9 @@ static ssize_t
402lpfc_poll_store(struct class_device *cdev, const char *buf, 446lpfc_poll_store(struct class_device *cdev, const char *buf,
403 size_t count) 447 size_t count)
404{ 448{
405 struct Scsi_Host *host = class_to_shost(cdev); 449 struct Scsi_Host *shost = class_to_shost(cdev);
406 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 450 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
451 struct lpfc_hba *phba = vport->phba;
407 uint32_t creg_val; 452 uint32_t creg_val;
408 uint32_t old_val; 453 uint32_t old_val;
409 int val=0; 454 int val=0;
@@ -417,7 +462,7 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
417 if ((val & 0x3) != val) 462 if ((val & 0x3) != val)
418 return -EINVAL; 463 return -EINVAL;
419 464
420 spin_lock_irq(phba->host->host_lock); 465 spin_lock_irq(&phba->hbalock);
421 466
422 old_val = phba->cfg_poll; 467 old_val = phba->cfg_poll;
423 468
@@ -432,16 +477,16 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
432 lpfc_poll_start_timer(phba); 477 lpfc_poll_start_timer(phba);
433 } 478 }
434 } else if (val != 0x0) { 479 } else if (val != 0x0) {
435 spin_unlock_irq(phba->host->host_lock); 480 spin_unlock_irq(&phba->hbalock);
436 return -EINVAL; 481 return -EINVAL;
437 } 482 }
438 483
439 if (!(val & DISABLE_FCP_RING_INT) && 484 if (!(val & DISABLE_FCP_RING_INT) &&
440 (old_val & DISABLE_FCP_RING_INT)) 485 (old_val & DISABLE_FCP_RING_INT))
441 { 486 {
442 spin_unlock_irq(phba->host->host_lock); 487 spin_unlock_irq(&phba->hbalock);
443 del_timer(&phba->fcp_poll_timer); 488 del_timer(&phba->fcp_poll_timer);
444 spin_lock_irq(phba->host->host_lock); 489 spin_lock_irq(&phba->hbalock);
445 creg_val = readl(phba->HCregaddr); 490 creg_val = readl(phba->HCregaddr);
446 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); 491 creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
447 writel(creg_val, phba->HCregaddr); 492 writel(creg_val, phba->HCregaddr);
@@ -450,7 +495,7 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
450 495
451 phba->cfg_poll = val; 496 phba->cfg_poll = val;
452 497
453 spin_unlock_irq(phba->host->host_lock); 498 spin_unlock_irq(&phba->hbalock);
454 499
455 return strlen(buf); 500 return strlen(buf);
456} 501}
@@ -459,8 +504,9 @@ lpfc_poll_store(struct class_device *cdev, const char *buf,
459static ssize_t \ 504static ssize_t \
460lpfc_##attr##_show(struct class_device *cdev, char *buf) \ 505lpfc_##attr##_show(struct class_device *cdev, char *buf) \
461{ \ 506{ \
462 struct Scsi_Host *host = class_to_shost(cdev);\ 507 struct Scsi_Host *shost = class_to_shost(cdev);\
463 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ 508 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
509 struct lpfc_hba *phba = vport->phba;\
464 int val = 0;\ 510 int val = 0;\
465 val = phba->cfg_##attr;\ 511 val = phba->cfg_##attr;\
466 return snprintf(buf, PAGE_SIZE, "%d\n",\ 512 return snprintf(buf, PAGE_SIZE, "%d\n",\
@@ -471,8 +517,9 @@ lpfc_##attr##_show(struct class_device *cdev, char *buf) \
471static ssize_t \ 517static ssize_t \
472lpfc_##attr##_show(struct class_device *cdev, char *buf) \ 518lpfc_##attr##_show(struct class_device *cdev, char *buf) \
473{ \ 519{ \
474 struct Scsi_Host *host = class_to_shost(cdev);\ 520 struct Scsi_Host *shost = class_to_shost(cdev);\
475 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ 521 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
522 struct lpfc_hba *phba = vport->phba;\
476 int val = 0;\ 523 int val = 0;\
477 val = phba->cfg_##attr;\ 524 val = phba->cfg_##attr;\
478 return snprintf(buf, PAGE_SIZE, "%#x\n",\ 525 return snprintf(buf, PAGE_SIZE, "%#x\n",\
@@ -514,8 +561,9 @@ lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
514static ssize_t \ 561static ssize_t \
515lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \ 562lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
516{ \ 563{ \
517 struct Scsi_Host *host = class_to_shost(cdev);\ 564 struct Scsi_Host *shost = class_to_shost(cdev);\
518 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\ 565 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
566 struct lpfc_hba *phba = vport->phba;\
519 int val=0;\ 567 int val=0;\
520 if (!isdigit(buf[0]))\ 568 if (!isdigit(buf[0]))\
521 return -EINVAL;\ 569 return -EINVAL;\
@@ -576,7 +624,7 @@ static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
576static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); 624static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
577static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); 625static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
578static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); 626static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
579static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL); 627static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
580static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); 628static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
581static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); 629static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
582static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL); 630static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
@@ -600,8 +648,9 @@ static ssize_t
600lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf, 648lpfc_soft_wwn_enable_store(struct class_device *cdev, const char *buf,
601 size_t count) 649 size_t count)
602{ 650{
603 struct Scsi_Host *host = class_to_shost(cdev); 651 struct Scsi_Host *shost = class_to_shost(cdev);
604 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 652 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
653 struct lpfc_hba *phba = vport->phba;
605 unsigned int cnt = count; 654 unsigned int cnt = count;
606 655
607 /* 656 /*
@@ -634,8 +683,10 @@ static CLASS_DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
634static ssize_t 683static ssize_t
635lpfc_soft_wwpn_show(struct class_device *cdev, char *buf) 684lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
636{ 685{
637 struct Scsi_Host *host = class_to_shost(cdev); 686 struct Scsi_Host *shost = class_to_shost(cdev);
638 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 687 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
688 struct lpfc_hba *phba = vport->phba;
689
639 return snprintf(buf, PAGE_SIZE, "0x%llx\n", 690 return snprintf(buf, PAGE_SIZE, "0x%llx\n",
640 (unsigned long long)phba->cfg_soft_wwpn); 691 (unsigned long long)phba->cfg_soft_wwpn);
641} 692}
@@ -644,8 +695,9 @@ lpfc_soft_wwpn_show(struct class_device *cdev, char *buf)
644static ssize_t 695static ssize_t
645lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count) 696lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
646{ 697{
647 struct Scsi_Host *host = class_to_shost(cdev); 698 struct Scsi_Host *shost = class_to_shost(cdev);
648 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 699 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
700 struct lpfc_hba *phba = vport->phba;
649 struct completion online_compl; 701 struct completion online_compl;
650 int stat1=0, stat2=0; 702 int stat1=0, stat2=0;
651 unsigned int i, j, cnt=count; 703 unsigned int i, j, cnt=count;
@@ -680,9 +732,9 @@ lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
680 } 732 }
681 } 733 }
682 phba->cfg_soft_wwpn = wwn_to_u64(wwpn); 734 phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
683 fc_host_port_name(host) = phba->cfg_soft_wwpn; 735 fc_host_port_name(shost) = phba->cfg_soft_wwpn;
684 if (phba->cfg_soft_wwnn) 736 if (phba->cfg_soft_wwnn)
685 fc_host_node_name(host) = phba->cfg_soft_wwnn; 737 fc_host_node_name(shost) = phba->cfg_soft_wwnn;
686 738
687 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 739 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
688 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); 740 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
@@ -790,8 +842,9 @@ MODULE_PARM_DESC(lpfc_nodev_tmo,
790static ssize_t 842static ssize_t
791lpfc_nodev_tmo_show(struct class_device *cdev, char *buf) 843lpfc_nodev_tmo_show(struct class_device *cdev, char *buf)
792{ 844{
793 struct Scsi_Host *host = class_to_shost(cdev); 845 struct Scsi_Host *shost = class_to_shost(cdev);
794 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 846 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
847 struct lpfc_hba *phba = vport->phba;
795 int val = 0; 848 int val = 0;
796 val = phba->cfg_devloss_tmo; 849 val = phba->cfg_devloss_tmo;
797 return snprintf(buf, PAGE_SIZE, "%d\n", 850 return snprintf(buf, PAGE_SIZE, "%d\n",
@@ -829,18 +882,6 @@ lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
829 return -EINVAL; 882 return -EINVAL;
830} 883}
831 884
832static void
833lpfc_update_rport_devloss_tmo(struct lpfc_hba *phba)
834{
835 struct lpfc_nodelist *ndlp;
836
837 spin_lock_irq(phba->host->host_lock);
838 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp)
839 if (ndlp->rport)
840 ndlp->rport->dev_loss_tmo = phba->cfg_devloss_tmo;
841 spin_unlock_irq(phba->host->host_lock);
842}
843
844static int 885static int
845lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val) 886lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
846{ 887{
@@ -856,7 +897,6 @@ lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
856 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 897 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
857 phba->cfg_nodev_tmo = val; 898 phba->cfg_nodev_tmo = val;
858 phba->cfg_devloss_tmo = val; 899 phba->cfg_devloss_tmo = val;
859 lpfc_update_rport_devloss_tmo(phba);
860 return 0; 900 return 0;
861 } 901 }
862 902
@@ -892,7 +932,6 @@ lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
892 phba->cfg_nodev_tmo = val; 932 phba->cfg_nodev_tmo = val;
893 phba->cfg_devloss_tmo = val; 933 phba->cfg_devloss_tmo = val;
894 phba->dev_loss_tmo_changed = 1; 934 phba->dev_loss_tmo_changed = 1;
895 lpfc_update_rport_devloss_tmo(phba);
896 return 0; 935 return 0;
897 } 936 }
898 937
@@ -1088,7 +1127,7 @@ LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
1088LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible"); 1127LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
1089 1128
1090 1129
1091struct class_device_attribute *lpfc_host_attrs[] = { 1130struct class_device_attribute *lpfc_hba_attrs[] = {
1092 &class_device_attr_info, 1131 &class_device_attr_info,
1093 &class_device_attr_serialnum, 1132 &class_device_attr_serialnum,
1094 &class_device_attr_modeldesc, 1133 &class_device_attr_modeldesc,
@@ -1136,9 +1175,11 @@ static ssize_t
1136sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 1175sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1137{ 1176{
1138 size_t buf_off; 1177 size_t buf_off;
1139 struct Scsi_Host *host = class_to_shost(container_of(kobj, 1178 struct class_device *cdev = container_of(kobj, struct class_device,
1140 struct class_device, kobj)); 1179 kobj);
1141 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 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;
1142 1183
1143 if ((off + count) > FF_REG_AREA_SIZE) 1184 if ((off + count) > FF_REG_AREA_SIZE)
1144 return -ERANGE; 1185 return -ERANGE;
@@ -1148,18 +1189,16 @@ sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1148 if (off % 4 || count % 4 || (unsigned long)buf % 4) 1189 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1149 return -EINVAL; 1190 return -EINVAL;
1150 1191
1151 spin_lock_irq(phba->host->host_lock); 1192 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1152
1153 if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
1154 spin_unlock_irq(phba->host->host_lock);
1155 return -EPERM; 1193 return -EPERM;
1156 } 1194 }
1157 1195
1196 spin_lock_irq(&phba->hbalock);
1158 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) 1197 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
1159 writel(*((uint32_t *)(buf + buf_off)), 1198 writel(*((uint32_t *)(buf + buf_off)),
1160 phba->ctrl_regs_memmap_p + off + buf_off); 1199 phba->ctrl_regs_memmap_p + off + buf_off);
1161 1200
1162 spin_unlock_irq(phba->host->host_lock); 1201 spin_unlock_irq(&phba->hbalock);
1163 1202
1164 return count; 1203 return count;
1165} 1204}
@@ -1169,9 +1208,11 @@ sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1169{ 1208{
1170 size_t buf_off; 1209 size_t buf_off;
1171 uint32_t * tmp_ptr; 1210 uint32_t * tmp_ptr;
1172 struct Scsi_Host *host = class_to_shost(container_of(kobj, 1211 struct class_device *cdev = container_of(kobj, struct class_device,
1173 struct class_device, kobj)); 1212 kobj);
1174 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 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;
1175 1216
1176 if (off > FF_REG_AREA_SIZE) 1217 if (off > FF_REG_AREA_SIZE)
1177 return -ERANGE; 1218 return -ERANGE;
@@ -1184,14 +1225,14 @@ sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1184 if (off % 4 || count % 4 || (unsigned long)buf % 4) 1225 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1185 return -EINVAL; 1226 return -EINVAL;
1186 1227
1187 spin_lock_irq(phba->host->host_lock); 1228 spin_lock_irq(&phba->hbalock);
1188 1229
1189 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { 1230 for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
1190 tmp_ptr = (uint32_t *)(buf + buf_off); 1231 tmp_ptr = (uint32_t *)(buf + buf_off);
1191 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); 1232 *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
1192 } 1233 }
1193 1234
1194 spin_unlock_irq(phba->host->host_lock); 1235 spin_unlock_irq(&phba->hbalock);
1195 1236
1196 return count; 1237 return count;
1197} 1238}
@@ -1209,7 +1250,7 @@ static struct bin_attribute sysfs_ctlreg_attr = {
1209 1250
1210 1251
1211static void 1252static void
1212sysfs_mbox_idle (struct lpfc_hba * phba) 1253sysfs_mbox_idle(struct lpfc_hba *phba)
1213{ 1254{
1214 phba->sysfs_mbox.state = SMBOX_IDLE; 1255 phba->sysfs_mbox.state = SMBOX_IDLE;
1215 phba->sysfs_mbox.offset = 0; 1256 phba->sysfs_mbox.offset = 0;
@@ -1224,10 +1265,12 @@ sysfs_mbox_idle (struct lpfc_hba * phba)
1224static ssize_t 1265static ssize_t
1225sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count) 1266sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1226{ 1267{
1227 struct Scsi_Host * host = 1268 struct class_device *cdev = container_of(kobj, struct class_device,
1228 class_to_shost(container_of(kobj, struct class_device, kobj)); 1269 kobj);
1229 struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata; 1270 struct Scsi_Host *shost = class_to_shost(cdev);
1230 struct lpfcMboxq * mbox = NULL; 1271 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1272 struct lpfc_hba *phba = vport->phba;
1273 struct lpfcMboxq *mbox = NULL;
1231 1274
1232 if ((count + off) > MAILBOX_CMD_SIZE) 1275 if ((count + off) > MAILBOX_CMD_SIZE)
1233 return -ERANGE; 1276 return -ERANGE;
@@ -1245,7 +1288,7 @@ sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1245 memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); 1288 memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
1246 } 1289 }
1247 1290
1248 spin_lock_irq(host->host_lock); 1291 spin_lock_irq(&phba->hbalock);
1249 1292
1250 if (off == 0) { 1293 if (off == 0) {
1251 if (phba->sysfs_mbox.mbox) 1294 if (phba->sysfs_mbox.mbox)
@@ -1258,7 +1301,7 @@ sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1258 phba->sysfs_mbox.offset != off || 1301 phba->sysfs_mbox.offset != off ||
1259 phba->sysfs_mbox.mbox == NULL ) { 1302 phba->sysfs_mbox.mbox == NULL ) {
1260 sysfs_mbox_idle(phba); 1303 sysfs_mbox_idle(phba);
1261 spin_unlock_irq(host->host_lock); 1304 spin_unlock_irq(&phba->hbalock);
1262 return -EAGAIN; 1305 return -EAGAIN;
1263 } 1306 }
1264 } 1307 }
@@ -1268,7 +1311,7 @@ sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1268 1311
1269 phba->sysfs_mbox.offset = off + count; 1312 phba->sysfs_mbox.offset = off + count;
1270 1313
1271 spin_unlock_irq(host->host_lock); 1314 spin_unlock_irq(&phba->hbalock);
1272 1315
1273 return count; 1316 return count;
1274} 1317}
@@ -1276,10 +1319,11 @@ sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
1276static ssize_t 1319static ssize_t
1277sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count) 1320sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1278{ 1321{
1279 struct Scsi_Host *host = 1322 struct class_device *cdev = container_of(kobj, struct class_device,
1280 class_to_shost(container_of(kobj, struct class_device, 1323 kobj);
1281 kobj)); 1324 struct Scsi_Host *shost = class_to_shost(cdev);
1282 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1325 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1326 struct lpfc_hba *phba = vport->phba;
1283 int rc; 1327 int rc;
1284 1328
1285 if (off > MAILBOX_CMD_SIZE) 1329 if (off > MAILBOX_CMD_SIZE)
@@ -1294,7 +1338,7 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1294 if (off && count == 0) 1338 if (off && count == 0)
1295 return 0; 1339 return 0;
1296 1340
1297 spin_lock_irq(phba->host->host_lock); 1341 spin_lock_irq(&phba->hbalock);
1298 1342
1299 if (off == 0 && 1343 if (off == 0 &&
1300 phba->sysfs_mbox.state == SMBOX_WRITING && 1344 phba->sysfs_mbox.state == SMBOX_WRITING &&
@@ -1317,12 +1361,12 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1317 case MBX_SET_MASK: 1361 case MBX_SET_MASK:
1318 case MBX_SET_SLIM: 1362 case MBX_SET_SLIM:
1319 case MBX_SET_DEBUG: 1363 case MBX_SET_DEBUG:
1320 if (!(phba->fc_flag & FC_OFFLINE_MODE)) { 1364 if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
1321 printk(KERN_WARNING "mbox_read:Command 0x%x " 1365 printk(KERN_WARNING "mbox_read:Command 0x%x "
1322 "is illegal in on-line state\n", 1366 "is illegal in on-line state\n",
1323 phba->sysfs_mbox.mbox->mb.mbxCommand); 1367 phba->sysfs_mbox.mbox->mb.mbxCommand);
1324 sysfs_mbox_idle(phba); 1368 sysfs_mbox_idle(phba);
1325 spin_unlock_irq(phba->host->host_lock); 1369 spin_unlock_irq(&phba->hbalock);
1326 return -EPERM; 1370 return -EPERM;
1327 } 1371 }
1328 case MBX_LOAD_SM: 1372 case MBX_LOAD_SM:
@@ -1352,38 +1396,38 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1352 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", 1396 printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
1353 phba->sysfs_mbox.mbox->mb.mbxCommand); 1397 phba->sysfs_mbox.mbox->mb.mbxCommand);
1354 sysfs_mbox_idle(phba); 1398 sysfs_mbox_idle(phba);
1355 spin_unlock_irq(phba->host->host_lock); 1399 spin_unlock_irq(&phba->hbalock);
1356 return -EPERM; 1400 return -EPERM;
1357 default: 1401 default:
1358 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", 1402 printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
1359 phba->sysfs_mbox.mbox->mb.mbxCommand); 1403 phba->sysfs_mbox.mbox->mb.mbxCommand);
1360 sysfs_mbox_idle(phba); 1404 sysfs_mbox_idle(phba);
1361 spin_unlock_irq(phba->host->host_lock); 1405 spin_unlock_irq(&phba->hbalock);
1362 return -EPERM; 1406 return -EPERM;
1363 } 1407 }
1364 1408
1365 if (phba->fc_flag & FC_BLOCK_MGMT_IO) { 1409 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
1366 sysfs_mbox_idle(phba); 1410 sysfs_mbox_idle(phba);
1367 spin_unlock_irq(host->host_lock); 1411 spin_unlock_irq(&phba->hbalock);
1368 return -EAGAIN; 1412 return -EAGAIN;
1369 } 1413 }
1370 1414
1371 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1415 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1372 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ 1416 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1373 1417
1374 spin_unlock_irq(phba->host->host_lock); 1418 spin_unlock_irq(&phba->hbalock);
1375 rc = lpfc_sli_issue_mbox (phba, 1419 rc = lpfc_sli_issue_mbox (phba,
1376 phba->sysfs_mbox.mbox, 1420 phba->sysfs_mbox.mbox,
1377 MBX_POLL); 1421 MBX_POLL);
1378 spin_lock_irq(phba->host->host_lock); 1422 spin_lock_irq(&phba->hbalock);
1379 1423
1380 } else { 1424 } else {
1381 spin_unlock_irq(phba->host->host_lock); 1425 spin_unlock_irq(&phba->hbalock);
1382 rc = lpfc_sli_issue_mbox_wait (phba, 1426 rc = lpfc_sli_issue_mbox_wait (phba,
1383 phba->sysfs_mbox.mbox, 1427 phba->sysfs_mbox.mbox,
1384 lpfc_mbox_tmo_val(phba, 1428 lpfc_mbox_tmo_val(phba,
1385 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ); 1429 phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
1386 spin_lock_irq(phba->host->host_lock); 1430 spin_lock_irq(&phba->hbalock);
1387 } 1431 }
1388 1432
1389 if (rc != MBX_SUCCESS) { 1433 if (rc != MBX_SUCCESS) {
@@ -1393,7 +1437,7 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1393 phba->sysfs_mbox.mbox = NULL; 1437 phba->sysfs_mbox.mbox = NULL;
1394 } 1438 }
1395 sysfs_mbox_idle(phba); 1439 sysfs_mbox_idle(phba);
1396 spin_unlock_irq(host->host_lock); 1440 spin_unlock_irq(&phba->hbalock);
1397 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; 1441 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
1398 } 1442 }
1399 phba->sysfs_mbox.state = SMBOX_READING; 1443 phba->sysfs_mbox.state = SMBOX_READING;
@@ -1402,7 +1446,7 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1402 phba->sysfs_mbox.state != SMBOX_READING) { 1446 phba->sysfs_mbox.state != SMBOX_READING) {
1403 printk(KERN_WARNING "mbox_read: Bad State\n"); 1447 printk(KERN_WARNING "mbox_read: Bad State\n");
1404 sysfs_mbox_idle(phba); 1448 sysfs_mbox_idle(phba);
1405 spin_unlock_irq(host->host_lock); 1449 spin_unlock_irq(&phba->hbalock);
1406 return -EAGAIN; 1450 return -EAGAIN;
1407 } 1451 }
1408 1452
@@ -1413,7 +1457,7 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1413 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) 1457 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
1414 sysfs_mbox_idle(phba); 1458 sysfs_mbox_idle(phba);
1415 1459
1416 spin_unlock_irq(phba->host->host_lock); 1460 spin_unlock_irq(&phba->hbalock);
1417 1461
1418 return count; 1462 return count;
1419} 1463}
@@ -1430,35 +1474,35 @@ static struct bin_attribute sysfs_mbox_attr = {
1430}; 1474};
1431 1475
1432int 1476int
1433lpfc_alloc_sysfs_attr(struct lpfc_hba *phba) 1477lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
1434{ 1478{
1435 struct Scsi_Host *host = phba->host; 1479 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1436 int error; 1480 int error;
1437 1481
1438 error = sysfs_create_bin_file(&host->shost_classdev.kobj, 1482 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1439 &sysfs_ctlreg_attr); 1483 &sysfs_ctlreg_attr);
1440 if (error) 1484 if (error)
1441 goto out; 1485 goto out;
1442 1486
1443 error = sysfs_create_bin_file(&host->shost_classdev.kobj, 1487 error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
1444 &sysfs_mbox_attr); 1488 &sysfs_mbox_attr);
1445 if (error) 1489 if (error)
1446 goto out_remove_ctlreg_attr; 1490 goto out_remove_ctlreg_attr;
1447 1491
1448 return 0; 1492 return 0;
1449out_remove_ctlreg_attr: 1493out_remove_ctlreg_attr:
1450 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); 1494 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1451out: 1495out:
1452 return error; 1496 return error;
1453} 1497}
1454 1498
1455void 1499void
1456lpfc_free_sysfs_attr(struct lpfc_hba *phba) 1500lpfc_free_sysfs_attr(struct lpfc_vport *vport)
1457{ 1501{
1458 struct Scsi_Host *host = phba->host; 1502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1459 1503
1460 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr); 1504 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
1461 sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr); 1505 sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
1462} 1506}
1463 1507
1464 1508
@@ -1469,26 +1513,28 @@ lpfc_free_sysfs_attr(struct lpfc_hba *phba)
1469static void 1513static void
1470lpfc_get_host_port_id(struct Scsi_Host *shost) 1514lpfc_get_host_port_id(struct Scsi_Host *shost)
1471{ 1515{
1472 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1516 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1517
1473 /* note: fc_myDID already in cpu endianness */ 1518 /* note: fc_myDID already in cpu endianness */
1474 fc_host_port_id(shost) = phba->fc_myDID; 1519 fc_host_port_id(shost) = vport->fc_myDID;
1475} 1520}
1476 1521
1477static void 1522static void
1478lpfc_get_host_port_type(struct Scsi_Host *shost) 1523lpfc_get_host_port_type(struct Scsi_Host *shost)
1479{ 1524{
1480 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1525 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1526 struct lpfc_hba *phba = vport->phba;
1481 1527
1482 spin_lock_irq(shost->host_lock); 1528 spin_lock_irq(shost->host_lock);
1483 1529
1484 if (phba->hba_state == LPFC_HBA_READY) { 1530 if (lpfc_is_link_up(phba)) {
1485 if (phba->fc_topology == TOPOLOGY_LOOP) { 1531 if (phba->fc_topology == TOPOLOGY_LOOP) {
1486 if (phba->fc_flag & FC_PUBLIC_LOOP) 1532 if (vport->fc_flag & FC_PUBLIC_LOOP)
1487 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; 1533 fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
1488 else 1534 else
1489 fc_host_port_type(shost) = FC_PORTTYPE_LPORT; 1535 fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
1490 } else { 1536 } else {
1491 if (phba->fc_flag & FC_FABRIC) 1537 if (vport->fc_flag & FC_FABRIC)
1492 fc_host_port_type(shost) = FC_PORTTYPE_NPORT; 1538 fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
1493 else 1539 else
1494 fc_host_port_type(shost) = FC_PORTTYPE_PTP; 1540 fc_host_port_type(shost) = FC_PORTTYPE_PTP;
@@ -1502,31 +1548,21 @@ lpfc_get_host_port_type(struct Scsi_Host *shost)
1502static void 1548static void
1503lpfc_get_host_port_state(struct Scsi_Host *shost) 1549lpfc_get_host_port_state(struct Scsi_Host *shost)
1504{ 1550{
1505 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1551 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1552 struct lpfc_hba *phba = vport->phba;
1506 1553
1507 spin_lock_irq(shost->host_lock); 1554 spin_lock_irq(shost->host_lock);
1508 1555
1509 if (phba->fc_flag & FC_OFFLINE_MODE) 1556 if (vport->fc_flag & FC_OFFLINE_MODE)
1510 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; 1557 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1511 else { 1558 else {
1512 switch (phba->hba_state) { 1559 switch (phba->link_state) {
1513 case LPFC_STATE_UNKNOWN: 1560 case LPFC_LINK_UNKNOWN:
1514 case LPFC_WARM_START:
1515 case LPFC_INIT_START:
1516 case LPFC_INIT_MBX_CMDS:
1517 case LPFC_LINK_DOWN: 1561 case LPFC_LINK_DOWN:
1518 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; 1562 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
1519 break; 1563 break;
1520 case LPFC_LINK_UP: 1564 case LPFC_LINK_UP:
1521 case LPFC_LOCAL_CFG_LINK:
1522 case LPFC_FLOGI:
1523 case LPFC_FABRIC_CFG_LINK:
1524 case LPFC_NS_REG:
1525 case LPFC_NS_QRY:
1526 case LPFC_BUILD_DISC_LIST:
1527 case LPFC_DISC_AUTH:
1528 case LPFC_CLEAR_LA: 1565 case LPFC_CLEAR_LA:
1529 case LPFC_HBA_READY:
1530 /* Links up, beyond this port_type reports state */ 1566 /* Links up, beyond this port_type reports state */
1531 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; 1567 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1532 break; 1568 break;
@@ -1545,11 +1581,12 @@ lpfc_get_host_port_state(struct Scsi_Host *shost)
1545static void 1581static void
1546lpfc_get_host_speed(struct Scsi_Host *shost) 1582lpfc_get_host_speed(struct Scsi_Host *shost)
1547{ 1583{
1548 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1584 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1585 struct lpfc_hba *phba = vport->phba;
1549 1586
1550 spin_lock_irq(shost->host_lock); 1587 spin_lock_irq(shost->host_lock);
1551 1588
1552 if (phba->hba_state == LPFC_HBA_READY) { 1589 if (lpfc_is_link_up(phba)) {
1553 switch(phba->fc_linkspeed) { 1590 switch(phba->fc_linkspeed) {
1554 case LA_1GHZ_LINK: 1591 case LA_1GHZ_LINK:
1555 fc_host_speed(shost) = FC_PORTSPEED_1GBIT; 1592 fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
@@ -1575,39 +1612,31 @@ lpfc_get_host_speed(struct Scsi_Host *shost)
1575static void 1612static void
1576lpfc_get_host_fabric_name (struct Scsi_Host *shost) 1613lpfc_get_host_fabric_name (struct Scsi_Host *shost)
1577{ 1614{
1578 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata; 1615 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1616 struct lpfc_hba *phba = vport->phba;
1579 u64 node_name; 1617 u64 node_name;
1580 1618
1581 spin_lock_irq(shost->host_lock); 1619 spin_lock_irq(shost->host_lock);
1582 1620
1583 if ((phba->fc_flag & FC_FABRIC) || 1621 if ((vport->fc_flag & FC_FABRIC) ||
1584 ((phba->fc_topology == TOPOLOGY_LOOP) && 1622 ((phba->fc_topology == TOPOLOGY_LOOP) &&
1585 (phba->fc_flag & FC_PUBLIC_LOOP))) 1623 (vport->fc_flag & FC_PUBLIC_LOOP)))
1586 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); 1624 node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
1587 else 1625 else
1588 /* fabric is local port if there is no F/FL_Port */ 1626 /* fabric is local port if there is no F/FL_Port */
1589 node_name = wwn_to_u64(phba->fc_nodename.u.wwn); 1627 node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
1590 1628
1591 spin_unlock_irq(shost->host_lock); 1629 spin_unlock_irq(shost->host_lock);
1592 1630
1593 fc_host_fabric_name(shost) = node_name; 1631 fc_host_fabric_name(shost) = node_name;
1594} 1632}
1595 1633
1596static void
1597lpfc_get_host_symbolic_name (struct Scsi_Host *shost)
1598{
1599 struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
1600
1601 spin_lock_irq(shost->host_lock);
1602 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1603 spin_unlock_irq(shost->host_lock);
1604}
1605
1606static struct fc_host_statistics * 1634static struct fc_host_statistics *
1607lpfc_get_stats(struct Scsi_Host *shost) 1635lpfc_get_stats(struct Scsi_Host *shost)
1608{ 1636{
1609 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1637 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1610 struct lpfc_sli *psli = &phba->sli; 1638 struct lpfc_hba *phba = vport->phba;
1639 struct lpfc_sli *psli = &phba->sli;
1611 struct fc_host_statistics *hs = &phba->link_stats; 1640 struct fc_host_statistics *hs = &phba->link_stats;
1612 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; 1641 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
1613 LPFC_MBOXQ_t *pmboxq; 1642 LPFC_MBOXQ_t *pmboxq;
@@ -1615,7 +1644,15 @@ lpfc_get_stats(struct Scsi_Host *shost)
1615 unsigned long seconds; 1644 unsigned long seconds;
1616 int rc = 0; 1645 int rc = 0;
1617 1646
1618 if (phba->fc_flag & FC_BLOCK_MGMT_IO) 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)
1619 return NULL; 1656 return NULL;
1620 1657
1621 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1658 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -1628,7 +1665,7 @@ lpfc_get_stats(struct Scsi_Host *shost)
1628 pmb->mbxOwner = OWN_HOST; 1665 pmb->mbxOwner = OWN_HOST;
1629 pmboxq->context1 = NULL; 1666 pmboxq->context1 = NULL;
1630 1667
1631 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1668 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1632 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1669 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1633 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1670 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1634 else 1671 else
@@ -1654,7 +1691,7 @@ lpfc_get_stats(struct Scsi_Host *shost)
1654 pmb->mbxOwner = OWN_HOST; 1691 pmb->mbxOwner = OWN_HOST;
1655 pmboxq->context1 = NULL; 1692 pmboxq->context1 = NULL;
1656 1693
1657 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1694 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1658 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1695 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1659 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1696 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1660 else 1697 else
@@ -1711,14 +1748,15 @@ lpfc_get_stats(struct Scsi_Host *shost)
1711static void 1748static void
1712lpfc_reset_stats(struct Scsi_Host *shost) 1749lpfc_reset_stats(struct Scsi_Host *shost)
1713{ 1750{
1714 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1751 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1715 struct lpfc_sli *psli = &phba->sli; 1752 struct lpfc_hba *phba = vport->phba;
1716 struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; 1753 struct lpfc_sli *psli = &phba->sli;
1754 struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
1717 LPFC_MBOXQ_t *pmboxq; 1755 LPFC_MBOXQ_t *pmboxq;
1718 MAILBOX_t *pmb; 1756 MAILBOX_t *pmb;
1719 int rc = 0; 1757 int rc = 0;
1720 1758
1721 if (phba->fc_flag & FC_BLOCK_MGMT_IO) 1759 if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
1722 return; 1760 return;
1723 1761
1724 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1762 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
@@ -1732,7 +1770,7 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1732 pmb->un.varWords[0] = 0x1; /* reset request */ 1770 pmb->un.varWords[0] = 0x1; /* reset request */
1733 pmboxq->context1 = NULL; 1771 pmboxq->context1 = NULL;
1734 1772
1735 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1773 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1736 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1774 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1737 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1775 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1738 else 1776 else
@@ -1751,7 +1789,7 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1751 pmb->mbxOwner = OWN_HOST; 1789 pmb->mbxOwner = OWN_HOST;
1752 pmboxq->context1 = NULL; 1790 pmboxq->context1 = NULL;
1753 1791
1754 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1792 if ((vport->fc_flag & FC_OFFLINE_MODE) ||
1755 (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) 1793 (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
1756 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); 1794 rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
1757 else 1795 else
@@ -1789,13 +1827,13 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1789static struct lpfc_nodelist * 1827static struct lpfc_nodelist *
1790lpfc_get_node_by_target(struct scsi_target *starget) 1828lpfc_get_node_by_target(struct scsi_target *starget)
1791{ 1829{
1792 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1830 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1793 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata; 1831 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1794 struct lpfc_nodelist *ndlp; 1832 struct lpfc_nodelist *ndlp;
1795 1833
1796 spin_lock_irq(shost->host_lock); 1834 spin_lock_irq(shost->host_lock);
1797 /* Search for this, mapped, target ID */ 1835 /* Search for this, mapped, target ID */
1798 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) { 1836 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1799 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE && 1837 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1800 starget->id == ndlp->nlp_sid) { 1838 starget->id == ndlp->nlp_sid) {
1801 spin_unlock_irq(shost->host_lock); 1839 spin_unlock_irq(shost->host_lock);
@@ -1885,9 +1923,6 @@ struct fc_function_template lpfc_transport_functions = {
1885 .get_host_fabric_name = lpfc_get_host_fabric_name, 1923 .get_host_fabric_name = lpfc_get_host_fabric_name,
1886 .show_host_fabric_name = 1, 1924 .show_host_fabric_name = 1,
1887 1925
1888 .get_host_symbolic_name = lpfc_get_host_symbolic_name,
1889 .show_host_symbolic_name = 1,
1890
1891 /* 1926 /*
1892 * The LPFC driver treats linkdown handling as target loss events 1927 * The LPFC driver treats linkdown handling as target loss events
1893 * so there are no sysfs handlers for link_down_tmo. 1928 * so there are no sysfs handlers for link_down_tmo.