aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_sli.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_sli.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c727
1 files changed, 366 insertions, 361 deletions
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index a1e721459e2b..1edac15eed40 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -52,9 +52,9 @@
52 "Data: x%x x%x x%x\n", \ 52 "Data: x%x x%x x%x\n", \
53 phba->brd_no, \ 53 phba->brd_no, \
54 mb->mbxCommand, \ 54 mb->mbxCommand, \
55 phba->hba_state, \ 55 phba->pport->port_state, \
56 psli->sli_flag, \ 56 psli->sli_flag, \
57 flag); 57 flag)
58 58
59 59
60/* There are only four IOCB completion types. */ 60/* There are only four IOCB completion types. */
@@ -65,8 +65,8 @@ typedef enum _lpfc_iocb_type {
65 LPFC_ABORT_IOCB 65 LPFC_ABORT_IOCB
66} lpfc_iocb_type; 66} lpfc_iocb_type;
67 67
68struct lpfc_iocbq * 68static struct lpfc_iocbq *
69lpfc_sli_get_iocbq(struct lpfc_hba * phba) 69__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
70{ 70{
71 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list; 71 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
72 struct lpfc_iocbq * iocbq = NULL; 72 struct lpfc_iocbq * iocbq = NULL;
@@ -75,10 +75,22 @@ lpfc_sli_get_iocbq(struct lpfc_hba * phba)
75 return iocbq; 75 return iocbq;
76} 76}
77 77
78struct lpfc_iocbq *
79lpfc_sli_get_iocbq(struct lpfc_hba *phba)
80{
81 struct lpfc_iocbq * iocbq = NULL;
82 unsigned long iflags;
83
84 spin_lock_irqsave(&phba->hbalock, iflags);
85 iocbq = __lpfc_sli_get_iocbq(phba);
86 spin_unlock_irqrestore(&phba->hbalock, iflags);
87 return iocbq;
88}
89
78void 90void
79lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq) 91__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
80{ 92{
81 size_t start_clean = (size_t)(&((struct lpfc_iocbq *)NULL)->iocb); 93 size_t start_clean = offsetof(struct lpfc_iocbq, iocb);
82 94
83 /* 95 /*
84 * Clean all volatile data fields, preserve iotag and node struct. 96 * Clean all volatile data fields, preserve iotag and node struct.
@@ -87,6 +99,19 @@ lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
87 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); 99 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
88} 100}
89 101
102void
103lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
104{
105 unsigned long iflags;
106
107 /*
108 * Clean all volatile data fields, preserve iotag and node struct.
109 */
110 spin_lock_irqsave(&phba->hbalock, iflags);
111 __lpfc_sli_release_iocbq(phba, iocbq);
112 spin_unlock_irqrestore(&phba->hbalock, iflags);
113}
114
90/* 115/*
91 * Translate the iocb command to an iocb command type used to decide the final 116 * Translate the iocb command to an iocb command type used to decide the final
92 * disposition of each completed IOCB. 117 * disposition of each completed IOCB.
@@ -166,14 +191,14 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
166} 191}
167 192
168static int 193static int
169lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb) 194lpfc_sli_ring_map(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
170{ 195{
171 struct lpfc_sli *psli = &phba->sli; 196 struct lpfc_sli *psli = &phba->sli;
172 MAILBOX_t *pmbox = &pmb->mb; 197 MAILBOX_t *pmbox = &pmb->mb;
173 int i, rc; 198 int i, rc;
174 199
175 for (i = 0; i < psli->num_rings; i++) { 200 for (i = 0; i < psli->num_rings; i++) {
176 phba->hba_state = LPFC_INIT_MBX_CMDS; 201 phba->link_state = LPFC_INIT_MBX_CMDS;
177 lpfc_config_ring(phba, i, pmb); 202 lpfc_config_ring(phba, i, pmb);
178 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 203 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
179 if (rc != MBX_SUCCESS) { 204 if (rc != MBX_SUCCESS) {
@@ -187,7 +212,7 @@ lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb)
187 pmbox->mbxCommand, 212 pmbox->mbxCommand,
188 pmbox->mbxStatus, 213 pmbox->mbxStatus,
189 i); 214 i);
190 phba->hba_state = LPFC_HBA_ERROR; 215 phba->link_state = LPFC_HBA_ERROR;
191 return -ENXIO; 216 return -ENXIO;
192 } 217 }
193 } 218 }
@@ -195,20 +220,20 @@ lpfc_sli_ring_map(struct lpfc_hba * phba, LPFC_MBOXQ_t *pmb)
195} 220}
196 221
197static int 222static int
198lpfc_sli_ringtxcmpl_put(struct lpfc_hba * phba, 223lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
199 struct lpfc_sli_ring * pring, struct lpfc_iocbq * piocb) 224 struct lpfc_iocbq *piocb)
200{ 225{
201 list_add_tail(&piocb->list, &pring->txcmplq); 226 list_add_tail(&piocb->list, &pring->txcmplq);
202 pring->txcmplq_cnt++; 227 pring->txcmplq_cnt++;
203 if (unlikely(pring->ringno == LPFC_ELS_RING)) 228 if (unlikely(pring->ringno == LPFC_ELS_RING))
204 mod_timer(&phba->els_tmofunc, 229 mod_timer(&piocb->vport->els_tmofunc,
205 jiffies + HZ * (phba->fc_ratov << 1)); 230 jiffies + HZ * (phba->fc_ratov << 1));
206 231
207 return (0); 232 return 0;
208} 233}
209 234
210static struct lpfc_iocbq * 235static struct lpfc_iocbq *
211lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring) 236lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
212{ 237{
213 struct list_head *dlp; 238 struct list_head *dlp;
214 struct lpfc_iocbq *cmd_iocb; 239 struct lpfc_iocbq *cmd_iocb;
@@ -224,7 +249,7 @@ lpfc_sli_ringtx_get(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
224 */ 249 */
225 pring->txq_cnt--; 250 pring->txq_cnt--;
226 } 251 }
227 return (cmd_iocb); 252 return cmd_iocb;
228} 253}
229 254
230static IOCB_t * 255static IOCB_t *
@@ -249,7 +274,7 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
249 phba->brd_no, pring->ringno, 274 phba->brd_no, pring->ringno,
250 pring->local_getidx, max_cmd_idx); 275 pring->local_getidx, max_cmd_idx);
251 276
252 phba->hba_state = LPFC_HBA_ERROR; 277 phba->link_state = LPFC_HBA_ERROR;
253 /* 278 /*
254 * All error attention handlers are posted to 279 * All error attention handlers are posted to
255 * worker thread 280 * worker thread
@@ -272,33 +297,30 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
272} 297}
273 298
274uint16_t 299uint16_t
275lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq) 300lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
276{ 301{
277 struct lpfc_iocbq ** new_arr; 302 struct lpfc_iocbq **new_arr;
278 struct lpfc_iocbq ** old_arr; 303 struct lpfc_iocbq **old_arr;
279 size_t new_len; 304 size_t new_len;
280 struct lpfc_sli *psli = &phba->sli; 305 struct lpfc_sli *psli = &phba->sli;
281 uint16_t iotag; 306 uint16_t iotag;
282 307
283 spin_lock_irq(phba->host->host_lock); 308 spin_lock_irq(&phba->hbalock);
284 iotag = psli->last_iotag; 309 iotag = psli->last_iotag;
285 if(++iotag < psli->iocbq_lookup_len) { 310 if(++iotag < psli->iocbq_lookup_len) {
286 psli->last_iotag = iotag; 311 psli->last_iotag = iotag;
287 psli->iocbq_lookup[iotag] = iocbq; 312 psli->iocbq_lookup[iotag] = iocbq;
288 spin_unlock_irq(phba->host->host_lock); 313 spin_unlock_irq(&phba->hbalock);
289 iocbq->iotag = iotag; 314 iocbq->iotag = iotag;
290 return iotag; 315 return iotag;
291 } 316 } else if (psli->iocbq_lookup_len < (0xffff
292 else if (psli->iocbq_lookup_len < (0xffff
293 - LPFC_IOCBQ_LOOKUP_INCREMENT)) { 317 - LPFC_IOCBQ_LOOKUP_INCREMENT)) {
294 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT; 318 new_len = psli->iocbq_lookup_len + LPFC_IOCBQ_LOOKUP_INCREMENT;
295 spin_unlock_irq(phba->host->host_lock); 319 spin_unlock_irq(&phba->hbalock);
296 new_arr = kmalloc(new_len * sizeof (struct lpfc_iocbq *), 320 new_arr = kzalloc(new_len * sizeof (struct lpfc_iocbq *),
297 GFP_KERNEL); 321 GFP_KERNEL);
298 if (new_arr) { 322 if (new_arr) {
299 memset((char *)new_arr, 0, 323 spin_lock_irq(&phba->hbalock);
300 new_len * sizeof (struct lpfc_iocbq *));
301 spin_lock_irq(phba->host->host_lock);
302 old_arr = psli->iocbq_lookup; 324 old_arr = psli->iocbq_lookup;
303 if (new_len <= psli->iocbq_lookup_len) { 325 if (new_len <= psli->iocbq_lookup_len) {
304 /* highly unprobable case */ 326 /* highly unprobable case */
@@ -307,11 +329,11 @@ lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
307 if(++iotag < psli->iocbq_lookup_len) { 329 if(++iotag < psli->iocbq_lookup_len) {
308 psli->last_iotag = iotag; 330 psli->last_iotag = iotag;
309 psli->iocbq_lookup[iotag] = iocbq; 331 psli->iocbq_lookup[iotag] = iocbq;
310 spin_unlock_irq(phba->host->host_lock); 332 spin_unlock_irq(&phba->hbalock);
311 iocbq->iotag = iotag; 333 iocbq->iotag = iotag;
312 return iotag; 334 return iotag;
313 } 335 }
314 spin_unlock_irq(phba->host->host_lock); 336 spin_unlock_irq(&phba->hbalock);
315 return 0; 337 return 0;
316 } 338 }
317 if (psli->iocbq_lookup) 339 if (psli->iocbq_lookup)
@@ -322,13 +344,13 @@ lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocbq)
322 psli->iocbq_lookup_len = new_len; 344 psli->iocbq_lookup_len = new_len;
323 psli->last_iotag = iotag; 345 psli->last_iotag = iotag;
324 psli->iocbq_lookup[iotag] = iocbq; 346 psli->iocbq_lookup[iotag] = iocbq;
325 spin_unlock_irq(phba->host->host_lock); 347 spin_unlock_irq(&phba->hbalock);
326 iocbq->iotag = iotag; 348 iocbq->iotag = iotag;
327 kfree(old_arr); 349 kfree(old_arr);
328 return iotag; 350 return iotag;
329 } 351 }
330 } else 352 } else
331 spin_unlock_irq(phba->host->host_lock); 353 spin_unlock_irq(&phba->hbalock);
332 354
333 lpfc_printf_log(phba, KERN_ERR,LOG_SLI, 355 lpfc_printf_log(phba, KERN_ERR,LOG_SLI,
334 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n", 356 "%d:0318 Failed to allocate IOTAG.last IOTAG is %d\n",
@@ -361,7 +383,7 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
361 if (nextiocb->iocb_cmpl) 383 if (nextiocb->iocb_cmpl)
362 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb); 384 lpfc_sli_ringtxcmpl_put(phba, pring, nextiocb);
363 else 385 else
364 lpfc_sli_release_iocbq(phba, nextiocb); 386 __lpfc_sli_release_iocbq(phba, nextiocb);
365 387
366 /* 388 /*
367 * Let the HBA know what IOCB slot will be the next one the 389 * Let the HBA know what IOCB slot will be the next one the
@@ -373,8 +395,7 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
373} 395}
374 396
375static void 397static void
376lpfc_sli_update_full_ring(struct lpfc_hba * phba, 398lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
377 struct lpfc_sli_ring *pring)
378{ 399{
379 int ringno = pring->ringno; 400 int ringno = pring->ringno;
380 401
@@ -393,8 +414,7 @@ lpfc_sli_update_full_ring(struct lpfc_hba * phba,
393} 414}
394 415
395static void 416static void
396lpfc_sli_update_ring(struct lpfc_hba * phba, 417lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
397 struct lpfc_sli_ring *pring)
398{ 418{
399 int ringno = pring->ringno; 419 int ringno = pring->ringno;
400 420
@@ -407,7 +427,7 @@ lpfc_sli_update_ring(struct lpfc_hba * phba,
407} 427}
408 428
409static void 429static void
410lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring) 430lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
411{ 431{
412 IOCB_t *iocb; 432 IOCB_t *iocb;
413 struct lpfc_iocbq *nextiocb; 433 struct lpfc_iocbq *nextiocb;
@@ -420,7 +440,7 @@ lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
420 * (d) IOCB processing is not blocked by the outstanding mbox command. 440 * (d) IOCB processing is not blocked by the outstanding mbox command.
421 */ 441 */
422 if (pring->txq_cnt && 442 if (pring->txq_cnt &&
423 (phba->hba_state > LPFC_LINK_DOWN) && 443 lpfc_is_link_up(phba) &&
424 (pring->ringno != phba->sli.fcp_ring || 444 (pring->ringno != phba->sli.fcp_ring ||
425 phba->sli.sli_flag & LPFC_PROCESS_LA) && 445 phba->sli.sli_flag & LPFC_PROCESS_LA) &&
426 !(pring->flag & LPFC_STOP_IOCB_MBX)) { 446 !(pring->flag & LPFC_STOP_IOCB_MBX)) {
@@ -440,11 +460,13 @@ lpfc_sli_resume_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring)
440 460
441/* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */ 461/* lpfc_sli_turn_on_ring is only called by lpfc_sli_handle_mb_event below */
442static void 462static void
443lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno) 463lpfc_sli_turn_on_ring(struct lpfc_hba *phba, int ringno)
444{ 464{
445 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno]; 465 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[ringno];
466 unsigned long iflags;
446 467
447 /* If the ring is active, flag it */ 468 /* If the ring is active, flag it */
469 spin_lock_irqsave(&phba->hbalock, iflags);
448 if (phba->sli.ring[ringno].cmdringaddr) { 470 if (phba->sli.ring[ringno].cmdringaddr) {
449 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) { 471 if (phba->sli.ring[ringno].flag & LPFC_STOP_IOCB_MBX) {
450 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX; 472 phba->sli.ring[ringno].flag &= ~LPFC_STOP_IOCB_MBX;
@@ -453,11 +475,10 @@ lpfc_sli_turn_on_ring(struct lpfc_hba * phba, int ringno)
453 */ 475 */
454 phba->sli.ring[ringno].local_getidx 476 phba->sli.ring[ringno].local_getidx
455 = le32_to_cpu(pgp->cmdGetInx); 477 = le32_to_cpu(pgp->cmdGetInx);
456 spin_lock_irq(phba->host->host_lock);
457 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]); 478 lpfc_sli_resume_iocb(phba, &phba->sli.ring[ringno]);
458 spin_unlock_irq(phba->host->host_lock);
459 } 479 }
460 } 480 }
481 spin_unlock_irqrestore(&phba->hbalock, iflags);
461} 482}
462 483
463static int 484static int
@@ -517,10 +538,10 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
517 ret = MBX_SHUTDOWN; 538 ret = MBX_SHUTDOWN;
518 break; 539 break;
519 } 540 }
520 return (ret); 541 return ret;
521} 542}
522static void 543static void
523lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq) 544lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
524{ 545{
525 wait_queue_head_t *pdone_q; 546 wait_queue_head_t *pdone_q;
526 547
@@ -536,7 +557,7 @@ lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
536} 557}
537 558
538void 559void
539lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 560lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
540{ 561{
541 struct lpfc_dmabuf *mp; 562 struct lpfc_dmabuf *mp;
542 uint16_t rpi; 563 uint16_t rpi;
@@ -553,9 +574,9 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
553 * If a REG_LOGIN succeeded after node is destroyed or node 574 * If a REG_LOGIN succeeded after node is destroyed or node
554 * is in re-discovery driver need to cleanup the RPI. 575 * is in re-discovery driver need to cleanup the RPI.
555 */ 576 */
556 if (!(phba->fc_flag & FC_UNLOADING) && 577 if (!(phba->pport->load_flag & FC_UNLOADING) &&
557 (pmb->mb.mbxCommand == MBX_REG_LOGIN64) && 578 pmb->mb.mbxCommand == MBX_REG_LOGIN64 &&
558 (!pmb->mb.mbxStatus)) { 579 !pmb->mb.mbxStatus) {
559 580
560 rpi = pmb->mb.un.varWords[0]; 581 rpi = pmb->mb.un.varWords[0];
561 lpfc_unreg_login(phba, rpi, pmb); 582 lpfc_unreg_login(phba, rpi, pmb);
@@ -565,24 +586,22 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
565 return; 586 return;
566 } 587 }
567 588
568 mempool_free( pmb, phba->mbox_mem_pool); 589 mempool_free(pmb, phba->mbox_mem_pool);
569 return; 590 return;
570} 591}
571 592
572int 593int
573lpfc_sli_handle_mb_event(struct lpfc_hba * phba) 594lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
574{ 595{
575 MAILBOX_t *mbox; 596 MAILBOX_t *mbox, *pmbox;
576 MAILBOX_t *pmbox;
577 LPFC_MBOXQ_t *pmb; 597 LPFC_MBOXQ_t *pmb;
578 struct lpfc_sli *psli;
579 int i, rc; 598 int i, rc;
580 uint32_t process_next; 599 uint32_t process_next;
600 unsigned long iflags;
581 601
582 psli = &phba->sli;
583 /* We should only get here if we are in SLI2 mode */ 602 /* We should only get here if we are in SLI2 mode */
584 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) { 603 if (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE)) {
585 return (1); 604 return 1;
586 } 605 }
587 606
588 phba->sli.slistat.mbox_event++; 607 phba->sli.slistat.mbox_event++;
@@ -616,15 +635,18 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
616 pmbox->mbxCommand, 635 pmbox->mbxCommand,
617 pmbox->mbxStatus); 636 pmbox->mbxStatus);
618 637
619 spin_lock_irq(phba->host->host_lock); 638 spin_lock_irq(&phba->hbalock);
620 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; 639 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
621 spin_unlock_irq(phba->host->host_lock); 640 spin_unlock_irq(&phba->hbalock);
622 return (1); 641 return 1;
623 } 642 }
624 643
625 mbout: 644 mbout:
626 del_timer_sync(&phba->sli.mbox_tmo); 645 del_timer_sync(&phba->sli.mbox_tmo);
627 phba->work_hba_events &= ~WORKER_MBOX_TMO; 646
647 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
648 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
649 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
628 650
629 /* 651 /*
630 * It is a fatal error if unknown mbox command completion. 652 * It is a fatal error if unknown mbox command completion.
@@ -639,10 +661,10 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
639 "%d:0323 Unknown Mailbox command %x Cmpl\n", 661 "%d:0323 Unknown Mailbox command %x Cmpl\n",
640 phba->brd_no, 662 phba->brd_no,
641 pmbox->mbxCommand); 663 pmbox->mbxCommand);
642 phba->hba_state = LPFC_HBA_ERROR; 664 phba->link_state = LPFC_HBA_ERROR;
643 phba->work_hs = HS_FFER3; 665 phba->work_hs = HS_FFER3;
644 lpfc_handle_eratt(phba); 666 lpfc_handle_eratt(phba);
645 return (0); 667 return 0;
646 } 668 }
647 669
648 phba->sli.mbox_active = NULL; 670 phba->sli.mbox_active = NULL;
@@ -659,15 +681,15 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
659 pmbox->mbxCommand, 681 pmbox->mbxCommand,
660 pmbox->mbxStatus, 682 pmbox->mbxStatus,
661 pmbox->un.varWords[0], 683 pmbox->un.varWords[0],
662 phba->hba_state); 684 phba->pport->port_state);
663 pmbox->mbxStatus = 0; 685 pmbox->mbxStatus = 0;
664 pmbox->mbxOwner = OWN_HOST; 686 pmbox->mbxOwner = OWN_HOST;
665 spin_lock_irq(phba->host->host_lock); 687 spin_lock_irq(&phba->hbalock);
666 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 688 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
667 spin_unlock_irq(phba->host->host_lock); 689 spin_unlock_irq(&phba->hbalock);
668 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); 690 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
669 if (rc == MBX_SUCCESS) 691 if (rc == MBX_SUCCESS)
670 return (0); 692 return 0;
671 } 693 }
672 } 694 }
673 695
@@ -699,12 +721,12 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
699 721
700 do { 722 do {
701 process_next = 0; /* by default don't loop */ 723 process_next = 0; /* by default don't loop */
702 spin_lock_irq(phba->host->host_lock); 724 spin_lock_irq(&phba->hbalock);
703 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 725 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
704 726
705 /* Process next mailbox command if there is one */ 727 /* Process next mailbox command if there is one */
706 if ((pmb = lpfc_mbox_get(phba))) { 728 if ((pmb = lpfc_mbox_get(phba))) {
707 spin_unlock_irq(phba->host->host_lock); 729 spin_unlock_irq(&phba->hbalock);
708 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); 730 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
709 if (rc == MBX_NOT_FINISHED) { 731 if (rc == MBX_NOT_FINISHED) {
710 pmb->mb.mbxStatus = MBX_NOT_FINISHED; 732 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
@@ -713,7 +735,7 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
713 continue; /* loop back */ 735 continue; /* loop back */
714 } 736 }
715 } else { 737 } else {
716 spin_unlock_irq(phba->host->host_lock); 738 spin_unlock_irq(&phba->hbalock);
717 /* Turn on IOCB processing */ 739 /* Turn on IOCB processing */
718 for (i = 0; i < phba->sli.num_rings; i++) 740 for (i = 0; i < phba->sli.num_rings; i++)
719 lpfc_sli_turn_on_ring(phba, i); 741 lpfc_sli_turn_on_ring(phba, i);
@@ -721,7 +743,7 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
721 743
722 } while (process_next); 744 } while (process_next);
723 745
724 return (0); 746 return 0;
725} 747}
726static int 748static int
727lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 749lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
@@ -795,9 +817,9 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
795} 817}
796 818
797static struct lpfc_iocbq * 819static struct lpfc_iocbq *
798lpfc_sli_iocbq_lookup(struct lpfc_hba * phba, 820lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
799 struct lpfc_sli_ring * pring, 821 struct lpfc_sli_ring *pring,
800 struct lpfc_iocbq * prspiocb) 822 struct lpfc_iocbq *prspiocb)
801{ 823{
802 struct lpfc_iocbq *cmd_iocb = NULL; 824 struct lpfc_iocbq *cmd_iocb = NULL;
803 uint16_t iotag; 825 uint16_t iotag;
@@ -821,16 +843,18 @@ lpfc_sli_iocbq_lookup(struct lpfc_hba * phba,
821} 843}
822 844
823static int 845static int
824lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, 846lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
825 struct lpfc_iocbq *saveq) 847 struct lpfc_iocbq *saveq)
826{ 848{
827 struct lpfc_iocbq * cmdiocbp; 849 struct lpfc_iocbq *cmdiocbp;
828 int rc = 1; 850 int rc = 1;
829 unsigned long iflag; 851 unsigned long iflag;
830 852
831 /* Based on the iotag field, get the cmd IOCB from the txcmplq */ 853 /* Based on the iotag field, get the cmd IOCB from the txcmplq */
832 spin_lock_irqsave(phba->host->host_lock, iflag); 854 spin_lock_irqsave(&phba->hbalock, iflag);
833 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq); 855 cmdiocbp = lpfc_sli_iocbq_lookup(phba, pring, saveq);
856 spin_unlock_irqrestore(&phba->hbalock, iflag);
857
834 if (cmdiocbp) { 858 if (cmdiocbp) {
835 if (cmdiocbp->iocb_cmpl) { 859 if (cmdiocbp->iocb_cmpl) {
836 /* 860 /*
@@ -846,17 +870,8 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
846 saveq->iocb.un.ulpWord[4] = 870 saveq->iocb.un.ulpWord[4] =
847 IOERR_SLI_ABORTED; 871 IOERR_SLI_ABORTED;
848 } 872 }
849 spin_unlock_irqrestore(phba->host->host_lock,
850 iflag);
851 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
852 spin_lock_irqsave(phba->host->host_lock, iflag);
853 }
854 else {
855 spin_unlock_irqrestore(phba->host->host_lock,
856 iflag);
857 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
858 spin_lock_irqsave(phba->host->host_lock, iflag);
859 } 873 }
874 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
860 } else 875 } else
861 lpfc_sli_release_iocbq(phba, cmdiocbp); 876 lpfc_sli_release_iocbq(phba, cmdiocbp);
862 } else { 877 } else {
@@ -885,12 +900,11 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
885 } 900 }
886 } 901 }
887 902
888 spin_unlock_irqrestore(phba->host->host_lock, iflag);
889 return rc; 903 return rc;
890} 904}
891 905
892static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba, 906static void
893 struct lpfc_sli_ring * pring) 907lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
894{ 908{
895 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 909 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
896 /* 910 /*
@@ -904,7 +918,7 @@ static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
904 le32_to_cpu(pgp->rspPutInx), 918 le32_to_cpu(pgp->rspPutInx),
905 pring->numRiocb); 919 pring->numRiocb);
906 920
907 phba->hba_state = LPFC_HBA_ERROR; 921 phba->link_state = LPFC_HBA_ERROR;
908 922
909 /* 923 /*
910 * All error attention handlers are posted to 924 * All error attention handlers are posted to
@@ -918,10 +932,10 @@ static void lpfc_sli_rsp_pointers_error(struct lpfc_hba * phba,
918 return; 932 return;
919} 933}
920 934
921void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba) 935void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
922{ 936{
923 struct lpfc_sli * psli = &phba->sli; 937 struct lpfc_sli *psli = &phba->sli;
924 struct lpfc_sli_ring * pring = &psli->ring[LPFC_FCP_RING]; 938 struct lpfc_sli_ring *pring = &psli->ring[LPFC_FCP_RING];
925 IOCB_t *irsp = NULL; 939 IOCB_t *irsp = NULL;
926 IOCB_t *entry = NULL; 940 IOCB_t *entry = NULL;
927 struct lpfc_iocbq *cmdiocbq = NULL; 941 struct lpfc_iocbq *cmdiocbq = NULL;
@@ -933,6 +947,7 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
933 uint32_t rsp_cmpl = 0; 947 uint32_t rsp_cmpl = 0;
934 void __iomem *to_slim; 948 void __iomem *to_slim;
935 uint32_t ha_copy; 949 uint32_t ha_copy;
950 unsigned long iflags;
936 951
937 pring->stats.iocb_event++; 952 pring->stats.iocb_event++;
938 953
@@ -960,7 +975,7 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
960 975
961 lpfc_sli_pcimem_bcopy((uint32_t *) entry, 976 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
962 (uint32_t *) &rspiocbq.iocb, 977 (uint32_t *) &rspiocbq.iocb,
963 sizeof (IOCB_t)); 978 sizeof(IOCB_t));
964 irsp = &rspiocbq.iocb; 979 irsp = &rspiocbq.iocb;
965 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK); 980 type = lpfc_sli_iocb_cmd_type(irsp->ulpCommand & CMD_IOCB_MASK);
966 pring->stats.iocb_rsp++; 981 pring->stats.iocb_rsp++;
@@ -998,8 +1013,10 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
998 break; 1013 break;
999 } 1014 }
1000 1015
1016 spin_lock_irqsave(&phba->hbalock, iflags);
1001 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring, 1017 cmdiocbq = lpfc_sli_iocbq_lookup(phba, pring,
1002 &rspiocbq); 1018 &rspiocbq);
1019 spin_unlock_irqrestore(&phba->hbalock, iflags);
1003 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) { 1020 if ((cmdiocbq) && (cmdiocbq->iocb_cmpl)) {
1004 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, 1021 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1005 &rspiocbq); 1022 &rspiocbq);
@@ -1045,13 +1062,16 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
1045 ha_copy >>= (LPFC_FCP_RING * 4); 1062 ha_copy >>= (LPFC_FCP_RING * 4);
1046 1063
1047 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) { 1064 if ((rsp_cmpl > 0) && (ha_copy & HA_R0RE_REQ)) {
1065 spin_lock_irqsave(&phba->hbalock, iflags);
1048 pring->stats.iocb_rsp_full++; 1066 pring->stats.iocb_rsp_full++;
1049 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4)); 1067 status = ((CA_R0ATT | CA_R0RE_RSP) << (LPFC_FCP_RING * 4));
1050 writel(status, phba->CAregaddr); 1068 writel(status, phba->CAregaddr);
1051 readl(phba->CAregaddr); 1069 readl(phba->CAregaddr);
1070 spin_unlock_irqrestore(&phba->hbalock, iflags);
1052 } 1071 }
1053 if ((ha_copy & HA_R0CE_RSP) && 1072 if ((ha_copy & HA_R0CE_RSP) &&
1054 (pring->flag & LPFC_CALL_RING_AVAILABLE)) { 1073 (pring->flag & LPFC_CALL_RING_AVAILABLE)) {
1074 spin_lock_irqsave(&phba->hbalock, iflags);
1055 pring->flag &= ~LPFC_CALL_RING_AVAILABLE; 1075 pring->flag &= ~LPFC_CALL_RING_AVAILABLE;
1056 pring->stats.iocb_cmd_empty++; 1076 pring->stats.iocb_cmd_empty++;
1057 1077
@@ -1062,6 +1082,7 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
1062 if ((pring->lpfc_sli_cmd_available)) 1082 if ((pring->lpfc_sli_cmd_available))
1063 (pring->lpfc_sli_cmd_available) (phba, pring); 1083 (pring->lpfc_sli_cmd_available) (phba, pring);
1064 1084
1085 spin_unlock_irqrestore(&phba->hbalock, iflags);
1065 } 1086 }
1066 1087
1067 return; 1088 return;
@@ -1072,10 +1093,10 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba * phba)
1072 * to check it explicitly. 1093 * to check it explicitly.
1073 */ 1094 */
1074static int 1095static int
1075lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba, 1096lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1076 struct lpfc_sli_ring * pring, uint32_t mask) 1097 struct lpfc_sli_ring *pring, uint32_t mask)
1077{ 1098{
1078 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno]; 1099 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1079 IOCB_t *irsp = NULL; 1100 IOCB_t *irsp = NULL;
1080 IOCB_t *entry = NULL; 1101 IOCB_t *entry = NULL;
1081 struct lpfc_iocbq *cmdiocbq = NULL; 1102 struct lpfc_iocbq *cmdiocbq = NULL;
@@ -1086,9 +1107,9 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1086 lpfc_iocb_type type; 1107 lpfc_iocb_type type;
1087 unsigned long iflag; 1108 unsigned long iflag;
1088 uint32_t rsp_cmpl = 0; 1109 uint32_t rsp_cmpl = 0;
1089 void __iomem *to_slim; 1110 void __iomem *to_slim;
1090 1111
1091 spin_lock_irqsave(phba->host->host_lock, iflag); 1112 spin_lock_irqsave(&phba->hbalock, iflag);
1092 pring->stats.iocb_event++; 1113 pring->stats.iocb_event++;
1093 1114
1094 /* 1115 /*
@@ -1099,7 +1120,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1099 portRspPut = le32_to_cpu(pgp->rspPutInx); 1120 portRspPut = le32_to_cpu(pgp->rspPutInx);
1100 if (unlikely(portRspPut >= portRspMax)) { 1121 if (unlikely(portRspPut >= portRspMax)) {
1101 lpfc_sli_rsp_pointers_error(phba, pring); 1122 lpfc_sli_rsp_pointers_error(phba, pring);
1102 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1123 spin_unlock_irqrestore(&phba->hbalock, iflag);
1103 return 1; 1124 return 1;
1104 } 1125 }
1105 1126
@@ -1117,7 +1138,7 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1117 1138
1118 lpfc_sli_pcimem_bcopy((uint32_t *) entry, 1139 lpfc_sli_pcimem_bcopy((uint32_t *) entry,
1119 (uint32_t *) &rspiocbq.iocb, 1140 (uint32_t *) &rspiocbq.iocb,
1120 sizeof (IOCB_t)); 1141 sizeof(IOCB_t));
1121 INIT_LIST_HEAD(&(rspiocbq.list)); 1142 INIT_LIST_HEAD(&(rspiocbq.list));
1122 irsp = &rspiocbq.iocb; 1143 irsp = &rspiocbq.iocb;
1123 1144
@@ -1161,19 +1182,19 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1161 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, 1182 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1162 &rspiocbq); 1183 &rspiocbq);
1163 } else { 1184 } else {
1164 spin_unlock_irqrestore( 1185 spin_unlock_irqrestore(&phba->hbalock,
1165 phba->host->host_lock, iflag); 1186 iflag);
1166 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq, 1187 (cmdiocbq->iocb_cmpl)(phba, cmdiocbq,
1167 &rspiocbq); 1188 &rspiocbq);
1168 spin_lock_irqsave(phba->host->host_lock, 1189 spin_lock_irqsave(&phba->hbalock,
1169 iflag); 1190 iflag);
1170 } 1191 }
1171 } 1192 }
1172 break; 1193 break;
1173 case LPFC_UNSOL_IOCB: 1194 case LPFC_UNSOL_IOCB:
1174 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1195 spin_unlock_irqrestore(&phba->hbalock, iflag);
1175 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq); 1196 lpfc_sli_process_unsol_iocb(phba, pring, &rspiocbq);
1176 spin_lock_irqsave(phba->host->host_lock, iflag); 1197 spin_lock_irqsave(&phba->hbalock, iflag);
1177 break; 1198 break;
1178 default: 1199 default:
1179 if (irsp->ulpCommand == CMD_ADAPTER_MSG) { 1200 if (irsp->ulpCommand == CMD_ADAPTER_MSG) {
@@ -1228,31 +1249,31 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba * phba,
1228 1249
1229 } 1250 }
1230 1251
1231 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1252 spin_unlock_irqrestore(&phba->hbalock, iflag);
1232 return rc; 1253 return rc;
1233} 1254}
1234 1255
1235 1256
1236int 1257int
1237lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba, 1258lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1238 struct lpfc_sli_ring * pring, uint32_t mask) 1259 struct lpfc_sli_ring *pring, uint32_t mask)
1239{ 1260{
1261 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1240 IOCB_t *entry; 1262 IOCB_t *entry;
1241 IOCB_t *irsp = NULL; 1263 IOCB_t *irsp = NULL;
1242 struct lpfc_iocbq *rspiocbp = NULL; 1264 struct lpfc_iocbq *rspiocbp = NULL;
1243 struct lpfc_iocbq *next_iocb; 1265 struct lpfc_iocbq *next_iocb;
1244 struct lpfc_iocbq *cmdiocbp; 1266 struct lpfc_iocbq *cmdiocbp;
1245 struct lpfc_iocbq *saveq; 1267 struct lpfc_iocbq *saveq;
1246 struct lpfc_pgp *pgp = &phba->slim2p->mbx.us.s2.port[pring->ringno];
1247 uint8_t iocb_cmd_type; 1268 uint8_t iocb_cmd_type;
1248 lpfc_iocb_type type; 1269 lpfc_iocb_type type;
1249 uint32_t status, free_saveq; 1270 uint32_t status, free_saveq;
1250 uint32_t portRspPut, portRspMax; 1271 uint32_t portRspPut, portRspMax;
1251 int rc = 1; 1272 int rc = 1;
1252 unsigned long iflag; 1273 unsigned long iflag;
1253 void __iomem *to_slim; 1274 void __iomem *to_slim;
1254 1275
1255 spin_lock_irqsave(phba->host->host_lock, iflag); 1276 spin_lock_irqsave(&phba->hbalock, iflag);
1256 pring->stats.iocb_event++; 1277 pring->stats.iocb_event++;
1257 1278
1258 /* 1279 /*
@@ -1274,8 +1295,8 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1274 phba->brd_no, 1295 phba->brd_no,
1275 pring->ringno, portRspPut, portRspMax); 1296 pring->ringno, portRspPut, portRspMax);
1276 1297
1277 phba->hba_state = LPFC_HBA_ERROR; 1298 phba->link_state = LPFC_HBA_ERROR;
1278 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1299 spin_unlock_irqrestore(&phba->hbalock, iflag);
1279 1300
1280 phba->work_hs = HS_FFER3; 1301 phba->work_hs = HS_FFER3;
1281 lpfc_handle_eratt(phba); 1302 lpfc_handle_eratt(phba);
@@ -1299,14 +1320,14 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1299 * received. 1320 * received.
1300 */ 1321 */
1301 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx); 1322 entry = IOCB_ENTRY(pring->rspringaddr, pring->rspidx);
1302 rspiocbp = lpfc_sli_get_iocbq(phba); 1323 rspiocbp = __lpfc_sli_get_iocbq(phba);
1303 if (rspiocbp == NULL) { 1324 if (rspiocbp == NULL) {
1304 printk(KERN_ERR "%s: out of buffers! Failing " 1325 printk(KERN_ERR "%s: out of buffers! Failing "
1305 "completion.\n", __FUNCTION__); 1326 "completion.\n", __FUNCTION__);
1306 break; 1327 break;
1307 } 1328 }
1308 1329
1309 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof (IOCB_t)); 1330 lpfc_sli_pcimem_bcopy(entry, &rspiocbp->iocb, sizeof(IOCB_t));
1310 irsp = &rspiocbp->iocb; 1331 irsp = &rspiocbp->iocb;
1311 1332
1312 if (++pring->rspidx >= portRspMax) 1333 if (++pring->rspidx >= portRspMax)
@@ -1366,17 +1387,17 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1366 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK; 1387 iocb_cmd_type = irsp->ulpCommand & CMD_IOCB_MASK;
1367 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type); 1388 type = lpfc_sli_iocb_cmd_type(iocb_cmd_type);
1368 if (type == LPFC_SOL_IOCB) { 1389 if (type == LPFC_SOL_IOCB) {
1369 spin_unlock_irqrestore(phba->host->host_lock, 1390 spin_unlock_irqrestore(&phba->hbalock,
1370 iflag); 1391 iflag);
1371 rc = lpfc_sli_process_sol_iocb(phba, pring, 1392 rc = lpfc_sli_process_sol_iocb(phba, pring,
1372 saveq); 1393 saveq);
1373 spin_lock_irqsave(phba->host->host_lock, iflag); 1394 spin_lock_irqsave(&phba->hbalock, iflag);
1374 } else if (type == LPFC_UNSOL_IOCB) { 1395 } else if (type == LPFC_UNSOL_IOCB) {
1375 spin_unlock_irqrestore(phba->host->host_lock, 1396 spin_unlock_irqrestore(&phba->hbalock,
1376 iflag); 1397 iflag);
1377 rc = lpfc_sli_process_unsol_iocb(phba, pring, 1398 rc = lpfc_sli_process_unsol_iocb(phba, pring,
1378 saveq); 1399 saveq);
1379 spin_lock_irqsave(phba->host->host_lock, iflag); 1400 spin_lock_irqsave(&phba->hbalock, iflag);
1380 } else if (type == LPFC_ABORT_IOCB) { 1401 } else if (type == LPFC_ABORT_IOCB) {
1381 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) && 1402 if ((irsp->ulpCommand != CMD_XRI_ABORTED_CX) &&
1382 ((cmdiocbp = 1403 ((cmdiocbp =
@@ -1386,15 +1407,15 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1386 routine */ 1407 routine */
1387 if (cmdiocbp->iocb_cmpl) { 1408 if (cmdiocbp->iocb_cmpl) {
1388 spin_unlock_irqrestore( 1409 spin_unlock_irqrestore(
1389 phba->host->host_lock, 1410 &phba->hbalock,
1390 iflag); 1411 iflag);
1391 (cmdiocbp->iocb_cmpl) (phba, 1412 (cmdiocbp->iocb_cmpl) (phba,
1392 cmdiocbp, saveq); 1413 cmdiocbp, saveq);
1393 spin_lock_irqsave( 1414 spin_lock_irqsave(
1394 phba->host->host_lock, 1415 &phba->hbalock,
1395 iflag); 1416 iflag);
1396 } else 1417 } else
1397 lpfc_sli_release_iocbq(phba, 1418 __lpfc_sli_release_iocbq(phba,
1398 cmdiocbp); 1419 cmdiocbp);
1399 } 1420 }
1400 } else if (type == LPFC_UNKNOWN_IOCB) { 1421 } else if (type == LPFC_UNKNOWN_IOCB) {
@@ -1425,17 +1446,13 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1425 } 1446 }
1426 1447
1427 if (free_saveq) { 1448 if (free_saveq) {
1428 if (!list_empty(&saveq->list)) { 1449 list_for_each_entry_safe(rspiocbp, next_iocb,
1429 list_for_each_entry_safe(rspiocbp, 1450 &saveq->list, list) {
1430 next_iocb, 1451 list_del(&rspiocbp->list);
1431 &saveq->list, 1452 __lpfc_sli_release_iocbq(phba,
1432 list) { 1453 rspiocbp);
1433 list_del(&rspiocbp->list);
1434 lpfc_sli_release_iocbq(phba,
1435 rspiocbp);
1436 }
1437 } 1454 }
1438 lpfc_sli_release_iocbq(phba, saveq); 1455 __lpfc_sli_release_iocbq(phba, saveq);
1439 } 1456 }
1440 } 1457 }
1441 1458
@@ -1470,24 +1487,21 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1470 1487
1471 } 1488 }
1472 1489
1473 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1490 spin_unlock_irqrestore(&phba->hbalock, iflag);
1474 return rc; 1491 return rc;
1475} 1492}
1476 1493
1477int 1494void
1478lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 1495lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1479{ 1496{
1480 LIST_HEAD(completions); 1497 LIST_HEAD(completions);
1481 struct lpfc_iocbq *iocb, *next_iocb; 1498 struct lpfc_iocbq *iocb, *next_iocb;
1482 IOCB_t *cmd = NULL; 1499 IOCB_t *cmd = NULL;
1483 int errcnt;
1484
1485 errcnt = 0;
1486 1500
1487 /* Error everything on txq and txcmplq 1501 /* Error everything on txq and txcmplq
1488 * First do the txq. 1502 * First do the txq.
1489 */ 1503 */
1490 spin_lock_irq(phba->host->host_lock); 1504 spin_lock_irq(&phba->hbalock);
1491 list_splice_init(&pring->txq, &completions); 1505 list_splice_init(&pring->txq, &completions);
1492 pring->txq_cnt = 0; 1506 pring->txq_cnt = 0;
1493 1507
@@ -1495,26 +1509,25 @@ lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1495 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) 1509 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1496 lpfc_sli_issue_abort_iotag(phba, pring, iocb); 1510 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1497 1511
1498 spin_unlock_irq(phba->host->host_lock); 1512 spin_unlock_irq(&phba->hbalock);
1499 1513
1500 while (!list_empty(&completions)) { 1514 while (!list_empty(&completions)) {
1501 iocb = list_get_first(&completions, struct lpfc_iocbq, list); 1515 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1502 cmd = &iocb->iocb; 1516 cmd = &iocb->iocb;
1503 list_del(&iocb->list); 1517 list_del(&iocb->list);
1504 1518
1505 if (iocb->iocb_cmpl) { 1519 if (!iocb->iocb_cmpl)
1520 lpfc_sli_release_iocbq(phba, iocb);
1521 else {
1506 cmd->ulpStatus = IOSTAT_LOCAL_REJECT; 1522 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1507 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; 1523 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1508 (iocb->iocb_cmpl) (phba, iocb, iocb); 1524 (iocb->iocb_cmpl) (phba, iocb, iocb);
1509 } else 1525 }
1510 lpfc_sli_release_iocbq(phba, iocb);
1511 } 1526 }
1512
1513 return errcnt;
1514} 1527}
1515 1528
1516int 1529int
1517lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask) 1530lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1518{ 1531{
1519 uint32_t status; 1532 uint32_t status;
1520 int i = 0; 1533 int i = 0;
@@ -1541,7 +1554,8 @@ lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1541 msleep(2500); 1554 msleep(2500);
1542 1555
1543 if (i == 15) { 1556 if (i == 15) {
1544 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */ 1557 /* Do post */
1558 phba->pport->port_state = LPFC_STATE_UNKNOWN;
1545 lpfc_sli_brdrestart(phba); 1559 lpfc_sli_brdrestart(phba);
1546 } 1560 }
1547 /* Read the HBA Host Status Register */ 1561 /* Read the HBA Host Status Register */
@@ -1550,7 +1564,7 @@ lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1550 1564
1551 /* Check to see if any errors occurred during init */ 1565 /* Check to see if any errors occurred during init */
1552 if ((status & HS_FFERM) || (i >= 20)) { 1566 if ((status & HS_FFERM) || (i >= 20)) {
1553 phba->hba_state = LPFC_HBA_ERROR; 1567 phba->link_state = LPFC_HBA_ERROR;
1554 retval = 1; 1568 retval = 1;
1555 } 1569 }
1556 1570
@@ -1559,7 +1573,7 @@ lpfc_sli_brdready(struct lpfc_hba * phba, uint32_t mask)
1559 1573
1560#define BARRIER_TEST_PATTERN (0xdeadbeef) 1574#define BARRIER_TEST_PATTERN (0xdeadbeef)
1561 1575
1562void lpfc_reset_barrier(struct lpfc_hba * phba) 1576void lpfc_reset_barrier(struct lpfc_hba *phba)
1563{ 1577{
1564 uint32_t __iomem *resp_buf; 1578 uint32_t __iomem *resp_buf;
1565 uint32_t __iomem *mbox_buf; 1579 uint32_t __iomem *mbox_buf;
@@ -1584,12 +1598,12 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
1584 hc_copy = readl(phba->HCregaddr); 1598 hc_copy = readl(phba->HCregaddr);
1585 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); 1599 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1586 readl(phba->HCregaddr); /* flush */ 1600 readl(phba->HCregaddr); /* flush */
1587 phba->fc_flag |= FC_IGNORE_ERATT; 1601 phba->link_flag |= LS_IGNORE_ERATT;
1588 1602
1589 if (readl(phba->HAregaddr) & HA_ERATT) { 1603 if (readl(phba->HAregaddr) & HA_ERATT) {
1590 /* Clear Chip error bit */ 1604 /* Clear Chip error bit */
1591 writel(HA_ERATT, phba->HAregaddr); 1605 writel(HA_ERATT, phba->HAregaddr);
1592 phba->stopped = 1; 1606 phba->pport->stopped = 1;
1593 } 1607 }
1594 1608
1595 mbox = 0; 1609 mbox = 0;
@@ -1606,7 +1620,7 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
1606 1620
1607 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) { 1621 if (readl(resp_buf + 1) != ~(BARRIER_TEST_PATTERN)) {
1608 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE || 1622 if (phba->sli.sli_flag & LPFC_SLI2_ACTIVE ||
1609 phba->stopped) 1623 phba->pport->stopped)
1610 goto restore_hc; 1624 goto restore_hc;
1611 else 1625 else
1612 goto clear_errat; 1626 goto clear_errat;
@@ -1623,17 +1637,17 @@ clear_errat:
1623 1637
1624 if (readl(phba->HAregaddr) & HA_ERATT) { 1638 if (readl(phba->HAregaddr) & HA_ERATT) {
1625 writel(HA_ERATT, phba->HAregaddr); 1639 writel(HA_ERATT, phba->HAregaddr);
1626 phba->stopped = 1; 1640 phba->pport->stopped = 1;
1627 } 1641 }
1628 1642
1629restore_hc: 1643restore_hc:
1630 phba->fc_flag &= ~FC_IGNORE_ERATT; 1644 phba->link_flag &= ~LS_IGNORE_ERATT;
1631 writel(hc_copy, phba->HCregaddr); 1645 writel(hc_copy, phba->HCregaddr);
1632 readl(phba->HCregaddr); /* flush */ 1646 readl(phba->HCregaddr); /* flush */
1633} 1647}
1634 1648
1635int 1649int
1636lpfc_sli_brdkill(struct lpfc_hba * phba) 1650lpfc_sli_brdkill(struct lpfc_hba *phba)
1637{ 1651{
1638 struct lpfc_sli *psli; 1652 struct lpfc_sli *psli;
1639 LPFC_MBOXQ_t *pmb; 1653 LPFC_MBOXQ_t *pmb;
@@ -1650,7 +1664,7 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1650 LOG_SLI, 1664 LOG_SLI,
1651 "%d:0329 Kill HBA Data: x%x x%x\n", 1665 "%d:0329 Kill HBA Data: x%x x%x\n",
1652 phba->brd_no, 1666 phba->brd_no,
1653 phba->hba_state, 1667 phba->pport->port_state,
1654 psli->sli_flag); 1668 psli->sli_flag);
1655 1669
1656 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, 1670 if ((pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool,
@@ -1658,13 +1672,13 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1658 return 1; 1672 return 1;
1659 1673
1660 /* Disable the error attention */ 1674 /* Disable the error attention */
1661 spin_lock_irq(phba->host->host_lock); 1675 spin_lock_irq(&phba->hbalock);
1662 status = readl(phba->HCregaddr); 1676 status = readl(phba->HCregaddr);
1663 status &= ~HC_ERINT_ENA; 1677 status &= ~HC_ERINT_ENA;
1664 writel(status, phba->HCregaddr); 1678 writel(status, phba->HCregaddr);
1665 readl(phba->HCregaddr); /* flush */ 1679 readl(phba->HCregaddr); /* flush */
1666 phba->fc_flag |= FC_IGNORE_ERATT; 1680 phba->link_flag |= LS_IGNORE_ERATT;
1667 spin_unlock_irq(phba->host->host_lock); 1681 spin_unlock_irq(&phba->hbalock);
1668 1682
1669 lpfc_kill_board(phba, pmb); 1683 lpfc_kill_board(phba, pmb);
1670 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 1684 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
@@ -1673,9 +1687,9 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1673 if (retval != MBX_SUCCESS) { 1687 if (retval != MBX_SUCCESS) {
1674 if (retval != MBX_BUSY) 1688 if (retval != MBX_BUSY)
1675 mempool_free(pmb, phba->mbox_mem_pool); 1689 mempool_free(pmb, phba->mbox_mem_pool);
1676 spin_lock_irq(phba->host->host_lock); 1690 spin_lock_irq(&phba->hbalock);
1677 phba->fc_flag &= ~FC_IGNORE_ERATT; 1691 phba->link_flag &= ~LS_IGNORE_ERATT;
1678 spin_unlock_irq(phba->host->host_lock); 1692 spin_unlock_irq(&phba->hbalock);
1679 return 1; 1693 return 1;
1680 } 1694 }
1681 1695
@@ -1698,22 +1712,22 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1698 del_timer_sync(&psli->mbox_tmo); 1712 del_timer_sync(&psli->mbox_tmo);
1699 if (ha_copy & HA_ERATT) { 1713 if (ha_copy & HA_ERATT) {
1700 writel(HA_ERATT, phba->HAregaddr); 1714 writel(HA_ERATT, phba->HAregaddr);
1701 phba->stopped = 1; 1715 phba->pport->stopped = 1;
1702 } 1716 }
1703 spin_lock_irq(phba->host->host_lock); 1717 spin_lock_irq(&phba->hbalock);
1704 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 1718 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1705 phba->fc_flag &= ~FC_IGNORE_ERATT; 1719 phba->link_flag &= ~LS_IGNORE_ERATT;
1706 spin_unlock_irq(phba->host->host_lock); 1720 spin_unlock_irq(&phba->hbalock);
1707 1721
1708 psli->mbox_active = NULL; 1722 psli->mbox_active = NULL;
1709 lpfc_hba_down_post(phba); 1723 lpfc_hba_down_post(phba);
1710 phba->hba_state = LPFC_HBA_ERROR; 1724 phba->link_state = LPFC_HBA_ERROR;
1711 1725
1712 return (ha_copy & HA_ERATT ? 0 : 1); 1726 return ha_copy & HA_ERATT ? 0 : 1;
1713} 1727}
1714 1728
1715int 1729int
1716lpfc_sli_brdreset(struct lpfc_hba * phba) 1730lpfc_sli_brdreset(struct lpfc_hba *phba)
1717{ 1731{
1718 struct lpfc_sli *psli; 1732 struct lpfc_sli *psli;
1719 struct lpfc_sli_ring *pring; 1733 struct lpfc_sli_ring *pring;
@@ -1725,12 +1739,12 @@ lpfc_sli_brdreset(struct lpfc_hba * phba)
1725 /* Reset HBA */ 1739 /* Reset HBA */
1726 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 1740 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1727 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no, 1741 "%d:0325 Reset HBA Data: x%x x%x\n", phba->brd_no,
1728 phba->hba_state, psli->sli_flag); 1742 phba->pport->port_state, psli->sli_flag);
1729 1743
1730 /* perform board reset */ 1744 /* perform board reset */
1731 phba->fc_eventTag = 0; 1745 phba->fc_eventTag = 0;
1732 phba->fc_myDID = 0; 1746 phba->pport->fc_myDID = 0;
1733 phba->fc_prevDID = 0; 1747 phba->pport->fc_prevDID = 0;
1734 1748
1735 /* Turn off parity checking and serr during the physical reset */ 1749 /* Turn off parity checking and serr during the physical reset */
1736 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value); 1750 pci_read_config_word(phba->pcidev, PCI_COMMAND, &cfg_value);
@@ -1760,12 +1774,12 @@ lpfc_sli_brdreset(struct lpfc_hba * phba)
1760 pring->missbufcnt = 0; 1774 pring->missbufcnt = 0;
1761 } 1775 }
1762 1776
1763 phba->hba_state = LPFC_WARM_START; 1777 phba->link_state = LPFC_WARM_START;
1764 return 0; 1778 return 0;
1765} 1779}
1766 1780
1767int 1781int
1768lpfc_sli_brdrestart(struct lpfc_hba * phba) 1782lpfc_sli_brdrestart(struct lpfc_hba *phba)
1769{ 1783{
1770 MAILBOX_t *mb; 1784 MAILBOX_t *mb;
1771 struct lpfc_sli *psli; 1785 struct lpfc_sli *psli;
@@ -1773,14 +1787,14 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
1773 volatile uint32_t word0; 1787 volatile uint32_t word0;
1774 void __iomem *to_slim; 1788 void __iomem *to_slim;
1775 1789
1776 spin_lock_irq(phba->host->host_lock); 1790 spin_lock_irq(&phba->hbalock);
1777 1791
1778 psli = &phba->sli; 1792 psli = &phba->sli;
1779 1793
1780 /* Restart HBA */ 1794 /* Restart HBA */
1781 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 1795 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
1782 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no, 1796 "%d:0337 Restart HBA Data: x%x x%x\n", phba->brd_no,
1783 phba->hba_state, psli->sli_flag); 1797 phba->pport->port_state, psli->sli_flag);
1784 1798
1785 word0 = 0; 1799 word0 = 0;
1786 mb = (MAILBOX_t *) &word0; 1800 mb = (MAILBOX_t *) &word0;
@@ -1794,7 +1808,7 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
1794 readl(to_slim); /* flush */ 1808 readl(to_slim); /* flush */
1795 1809
1796 /* Only skip post after fc_ffinit is completed */ 1810 /* Only skip post after fc_ffinit is completed */
1797 if (phba->hba_state) { 1811 if (phba->pport->port_state) {
1798 skip_post = 1; 1812 skip_post = 1;
1799 word0 = 1; /* This is really setting up word1 */ 1813 word0 = 1; /* This is really setting up word1 */
1800 } else { 1814 } else {
@@ -1806,10 +1820,10 @@ lpfc_sli_brdrestart(struct lpfc_hba * phba)
1806 readl(to_slim); /* flush */ 1820 readl(to_slim); /* flush */
1807 1821
1808 lpfc_sli_brdreset(phba); 1822 lpfc_sli_brdreset(phba);
1809 phba->stopped = 0; 1823 phba->pport->stopped = 0;
1810 phba->hba_state = LPFC_INIT_START; 1824 phba->link_state = LPFC_INIT_START;
1811 1825
1812 spin_unlock_irq(phba->host->host_lock); 1826 spin_unlock_irq(&phba->hbalock);
1813 1827
1814 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets)); 1828 memset(&psli->lnk_stat_offsets, 0, sizeof(psli->lnk_stat_offsets));
1815 psli->stats_start = get_seconds(); 1829 psli->stats_start = get_seconds();
@@ -1850,7 +1864,7 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1850 "timeout, status reg x%x\n", 1864 "timeout, status reg x%x\n",
1851 phba->brd_no, 1865 phba->brd_no,
1852 status); 1866 status);
1853 phba->hba_state = LPFC_HBA_ERROR; 1867 phba->link_state = LPFC_HBA_ERROR;
1854 return -ETIMEDOUT; 1868 return -ETIMEDOUT;
1855 } 1869 }
1856 1870
@@ -1866,7 +1880,7 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1866 "chipset, status reg x%x\n", 1880 "chipset, status reg x%x\n",
1867 phba->brd_no, 1881 phba->brd_no,
1868 status); 1882 status);
1869 phba->hba_state = LPFC_HBA_ERROR; 1883 phba->link_state = LPFC_HBA_ERROR;
1870 return -EIO; 1884 return -EIO;
1871 } 1885 }
1872 1886
@@ -1879,7 +1893,8 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1879 } 1893 }
1880 1894
1881 if (i == 15) { 1895 if (i == 15) {
1882 phba->hba_state = LPFC_STATE_UNKNOWN; /* Do post */ 1896 /* Do post */
1897 phba->pport->port_state = LPFC_STATE_UNKNOWN;
1883 lpfc_sli_brdrestart(phba); 1898 lpfc_sli_brdrestart(phba);
1884 } 1899 }
1885 /* Read the HBA Host Status Register */ 1900 /* Read the HBA Host Status Register */
@@ -1897,7 +1912,7 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1897 "status reg x%x\n", 1912 "status reg x%x\n",
1898 phba->brd_no, 1913 phba->brd_no,
1899 status); 1914 status);
1900 phba->hba_state = LPFC_HBA_ERROR; 1915 phba->link_state = LPFC_HBA_ERROR;
1901 return -EIO; 1916 return -EIO;
1902 } 1917 }
1903 1918
@@ -1912,31 +1927,31 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
1912} 1927}
1913 1928
1914int 1929int
1915lpfc_sli_hba_setup(struct lpfc_hba * phba) 1930lpfc_sli_hba_setup(struct lpfc_hba *phba)
1916{ 1931{
1917 LPFC_MBOXQ_t *pmb; 1932 LPFC_MBOXQ_t *pmb;
1918 uint32_t resetcount = 0, rc = 0, done = 0; 1933 uint32_t resetcount = 0, rc = 0, done = 0;
1919 1934
1920 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1935 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1921 if (!pmb) { 1936 if (!pmb) {
1922 phba->hba_state = LPFC_HBA_ERROR; 1937 phba->link_state = LPFC_HBA_ERROR;
1923 return -ENOMEM; 1938 return -ENOMEM;
1924 } 1939 }
1925 1940
1926 while (resetcount < 2 && !done) { 1941 while (resetcount < 2 && !done) {
1927 spin_lock_irq(phba->host->host_lock); 1942 spin_lock_irq(&phba->hbalock);
1928 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE; 1943 phba->sli.sli_flag |= LPFC_SLI_MBOX_ACTIVE;
1929 spin_unlock_irq(phba->host->host_lock); 1944 spin_unlock_irq(&phba->hbalock);
1930 phba->hba_state = LPFC_STATE_UNKNOWN; 1945 phba->pport->port_state = LPFC_STATE_UNKNOWN;
1931 lpfc_sli_brdrestart(phba); 1946 lpfc_sli_brdrestart(phba);
1932 msleep(2500); 1947 msleep(2500);
1933 rc = lpfc_sli_chipset_init(phba); 1948 rc = lpfc_sli_chipset_init(phba);
1934 if (rc) 1949 if (rc)
1935 break; 1950 break;
1936 1951
1937 spin_lock_irq(phba->host->host_lock); 1952 spin_lock_irq(&phba->hbalock);
1938 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 1953 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1939 spin_unlock_irq(phba->host->host_lock); 1954 spin_unlock_irq(&phba->hbalock);
1940 resetcount++; 1955 resetcount++;
1941 1956
1942 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0 1957 /* Call pre CONFIG_PORT mailbox command initialization. A value of 0
@@ -1946,13 +1961,13 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
1946 */ 1961 */
1947 rc = lpfc_config_port_prep(phba); 1962 rc = lpfc_config_port_prep(phba);
1948 if (rc == -ERESTART) { 1963 if (rc == -ERESTART) {
1949 phba->hba_state = 0; 1964 phba->pport->port_state = 0;
1950 continue; 1965 continue;
1951 } else if (rc) { 1966 } else if (rc) {
1952 break; 1967 break;
1953 } 1968 }
1954 1969
1955 phba->hba_state = LPFC_INIT_MBX_CMDS; 1970 phba->link_state = LPFC_INIT_MBX_CMDS;
1956 lpfc_config_port(phba, pmb); 1971 lpfc_config_port(phba, pmb);
1957 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 1972 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
1958 if (rc == MBX_SUCCESS) 1973 if (rc == MBX_SUCCESS)
@@ -1963,7 +1978,10 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
1963 "CONFIG_PORT, mbxStatus x%x Data: x%x\n", 1978 "CONFIG_PORT, mbxStatus x%x Data: x%x\n",
1964 phba->brd_no, pmb->mb.mbxCommand, 1979 phba->brd_no, pmb->mb.mbxCommand,
1965 pmb->mb.mbxStatus, 0); 1980 pmb->mb.mbxStatus, 0);
1981 spin_lock_irq(&phba->hbalock);
1966 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; 1982 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
1983 spin_unlock_irq(&phba->hbalock);
1984 rc = -ENXIO;
1967 } 1985 }
1968 } 1986 }
1969 if (!done) 1987 if (!done)
@@ -1982,7 +2000,7 @@ lpfc_sli_hba_setup(struct lpfc_hba * phba)
1982 2000
1983 goto lpfc_sli_hba_setup_exit; 2001 goto lpfc_sli_hba_setup_exit;
1984lpfc_sli_hba_setup_error: 2002lpfc_sli_hba_setup_error:
1985 phba->hba_state = LPFC_HBA_ERROR; 2003 phba->link_state = LPFC_HBA_ERROR;
1986lpfc_sli_hba_setup_exit: 2004lpfc_sli_hba_setup_exit:
1987 mempool_free(pmb, phba->mbox_mem_pool); 2005 mempool_free(pmb, phba->mbox_mem_pool);
1988 return rc; 2006 return rc;
@@ -2004,36 +2022,34 @@ lpfc_sli_hba_setup_exit:
2004void 2022void
2005lpfc_mbox_timeout(unsigned long ptr) 2023lpfc_mbox_timeout(unsigned long ptr)
2006{ 2024{
2007 struct lpfc_hba *phba; 2025 struct lpfc_hba *phba = (struct lpfc_hba *) phba;
2008 unsigned long iflag; 2026 unsigned long iflag;
2027 uint32_t tmo_posted;
2009 2028
2010 phba = (struct lpfc_hba *)ptr; 2029 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
2011 spin_lock_irqsave(phba->host->host_lock, iflag); 2030 tmo_posted = (phba->pport->work_port_events & WORKER_MBOX_TMO) == 0;
2012 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) { 2031 if (!tmo_posted)
2013 phba->work_hba_events |= WORKER_MBOX_TMO; 2032 phba->pport->work_port_events |= WORKER_MBOX_TMO;
2033 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
2034
2035 if (!tmo_posted) {
2014 if (phba->work_wait) 2036 if (phba->work_wait)
2015 wake_up(phba->work_wait); 2037 wake_up(phba->work_wait);
2016 } 2038 }
2017 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2018} 2039}
2019 2040
2020void 2041void
2021lpfc_mbox_timeout_handler(struct lpfc_hba *phba) 2042lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2022{ 2043{
2023 LPFC_MBOXQ_t *pmbox; 2044 LPFC_MBOXQ_t *pmbox = phba->sli.mbox_active;
2024 MAILBOX_t *mb; 2045 MAILBOX_t *mb = &pmbox->mb;
2025 struct lpfc_sli *psli = &phba->sli; 2046 struct lpfc_sli *psli = &phba->sli;
2026 struct lpfc_sli_ring *pring; 2047 struct lpfc_sli_ring *pring;
2027 2048
2028 spin_lock_irq(phba->host->host_lock); 2049 if (!(phba->pport->work_port_events & WORKER_MBOX_TMO)) {
2029 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
2030 spin_unlock_irq(phba->host->host_lock);
2031 return; 2050 return;
2032 } 2051 }
2033 2052
2034 pmbox = phba->sli.mbox_active;
2035 mb = &pmbox->mb;
2036
2037 /* Mbox cmd <mbxCommand> timeout */ 2053 /* Mbox cmd <mbxCommand> timeout */
2038 lpfc_printf_log(phba, 2054 lpfc_printf_log(phba,
2039 KERN_ERR, 2055 KERN_ERR,
@@ -2041,7 +2057,7 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2041 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n", 2057 "%d:0310 Mailbox command x%x timeout Data: x%x x%x x%p\n",
2042 phba->brd_no, 2058 phba->brd_no,
2043 mb->mbxCommand, 2059 mb->mbxCommand,
2044 phba->hba_state, 2060 phba->pport->port_state,
2045 phba->sli.sli_flag, 2061 phba->sli.sli_flag,
2046 phba->sli.mbox_active); 2062 phba->sli.mbox_active);
2047 2063
@@ -2049,11 +2065,14 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2049 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing 2065 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2050 * it to fail all oustanding SCSI IO. 2066 * it to fail all oustanding SCSI IO.
2051 */ 2067 */
2052 phba->hba_state = LPFC_STATE_UNKNOWN; 2068 spin_lock_irq(&phba->pport->work_port_lock);
2053 phba->work_hba_events &= ~WORKER_MBOX_TMO; 2069 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2054 phba->fc_flag |= FC_ESTABLISH_LINK; 2070 spin_unlock_irq(&phba->pport->work_port_lock);
2071 spin_lock_irq(&phba->hbalock);
2072 phba->link_state = LPFC_LINK_UNKNOWN;
2073 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2055 psli->sli_flag &= ~LPFC_SLI2_ACTIVE; 2074 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2056 spin_unlock_irq(phba->host->host_lock); 2075 spin_unlock_irq(&phba->hbalock);
2057 2076
2058 pring = &psli->ring[psli->fcp_ring]; 2077 pring = &psli->ring[psli->fcp_ring];
2059 lpfc_sli_abort_iocb_ring(phba, pring); 2078 lpfc_sli_abort_iocb_ring(phba, pring);
@@ -2075,10 +2094,10 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2075} 2094}
2076 2095
2077int 2096int
2078lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag) 2097lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2079{ 2098{
2080 MAILBOX_t *mb; 2099 MAILBOX_t *mb;
2081 struct lpfc_sli *psli; 2100 struct lpfc_sli *psli = &phba->sli;
2082 uint32_t status, evtctr; 2101 uint32_t status, evtctr;
2083 uint32_t ha_copy; 2102 uint32_t ha_copy;
2084 int i; 2103 int i;
@@ -2090,27 +2109,25 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2090 if (unlikely(pci_channel_offline(phba->pcidev))) 2109 if (unlikely(pci_channel_offline(phba->pcidev)))
2091 return MBX_NOT_FINISHED; 2110 return MBX_NOT_FINISHED;
2092 2111
2112 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2093 psli = &phba->sli; 2113 psli = &phba->sli;
2094 2114
2095 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2096
2097
2098 mb = &pmbox->mb; 2115 mb = &pmbox->mb;
2099 status = MBX_SUCCESS; 2116 status = MBX_SUCCESS;
2100 2117
2101 if (phba->hba_state == LPFC_HBA_ERROR) { 2118 if (phba->link_state == LPFC_HBA_ERROR) {
2102 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); 2119 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2103 2120
2104 /* Mbox command <mbxCommand> cannot issue */ 2121 /* Mbox command <mbxCommand> cannot issue */
2105 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) 2122 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2106 return (MBX_NOT_FINISHED); 2123 return MBX_NOT_FINISHED;
2107 } 2124 }
2108 2125
2109 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT && 2126 if (mb->mbxCommand != MBX_KILL_BOARD && flag & MBX_NOWAIT &&
2110 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) { 2127 !(readl(phba->HCregaddr) & HC_MBINT_ENA)) {
2111 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); 2128 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2112 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) 2129 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag)
2113 return (MBX_NOT_FINISHED); 2130 return MBX_NOT_FINISHED;
2114 } 2131 }
2115 2132
2116 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) { 2133 if (psli->sli_flag & LPFC_SLI_MBOX_ACTIVE) {
@@ -2120,20 +2137,18 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2120 */ 2137 */
2121 2138
2122 if (flag & MBX_POLL) { 2139 if (flag & MBX_POLL) {
2123 spin_unlock_irqrestore(phba->host->host_lock, 2140 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2124 drvr_flag);
2125 2141
2126 /* Mbox command <mbxCommand> cannot issue */ 2142 /* Mbox command <mbxCommand> cannot issue */
2127 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) 2143 LOG_MBOX_CANNOT_ISSUE_DATA(phba, mb, psli, flag);
2128 return (MBX_NOT_FINISHED); 2144 return MBX_NOT_FINISHED;
2129 } 2145 }
2130 2146
2131 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) { 2147 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE)) {
2132 spin_unlock_irqrestore(phba->host->host_lock, 2148 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2133 drvr_flag);
2134 /* Mbox command <mbxCommand> cannot issue */ 2149 /* Mbox command <mbxCommand> cannot issue */
2135 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag) 2150 LOG_MBOX_CANNOT_ISSUE_DATA(phba, mb, psli, flag);
2136 return (MBX_NOT_FINISHED); 2151 return MBX_NOT_FINISHED;
2137 } 2152 }
2138 2153
2139 /* Handle STOP IOCB processing flag. This is only meaningful 2154 /* Handle STOP IOCB processing flag. This is only meaningful
@@ -2163,15 +2178,14 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2163 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n", 2178 "%d:0308 Mbox cmd issue - BUSY Data: x%x x%x x%x x%x\n",
2164 phba->brd_no, 2179 phba->brd_no,
2165 mb->mbxCommand, 2180 mb->mbxCommand,
2166 phba->hba_state, 2181 phba->pport->port_state,
2167 psli->sli_flag, 2182 psli->sli_flag,
2168 flag); 2183 flag);
2169 2184
2170 psli->slistat.mbox_busy++; 2185 psli->slistat.mbox_busy++;
2171 spin_unlock_irqrestore(phba->host->host_lock, 2186 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2172 drvr_flag);
2173 2187
2174 return (MBX_BUSY); 2188 return MBX_BUSY;
2175 } 2189 }
2176 2190
2177 /* Handle STOP IOCB processing flag. This is only meaningful 2191 /* Handle STOP IOCB processing flag. This is only meaningful
@@ -2198,11 +2212,10 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2198 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) && 2212 if (!(psli->sli_flag & LPFC_SLI2_ACTIVE) &&
2199 (mb->mbxCommand != MBX_KILL_BOARD)) { 2213 (mb->mbxCommand != MBX_KILL_BOARD)) {
2200 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 2214 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2201 spin_unlock_irqrestore(phba->host->host_lock, 2215 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2202 drvr_flag);
2203 /* Mbox command <mbxCommand> cannot issue */ 2216 /* Mbox command <mbxCommand> cannot issue */
2204 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag); 2217 LOG_MBOX_CANNOT_ISSUE_DATA( phba, mb, psli, flag);
2205 return (MBX_NOT_FINISHED); 2218 return MBX_NOT_FINISHED;
2206 } 2219 }
2207 /* timeout active mbox command */ 2220 /* timeout active mbox command */
2208 mod_timer(&psli->mbox_tmo, (jiffies + 2221 mod_timer(&psli->mbox_tmo, (jiffies +
@@ -2216,9 +2229,9 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2216 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n", 2229 "%d:0309 Mailbox cmd x%x issue Data: x%x x%x x%x\n",
2217 phba->brd_no, 2230 phba->brd_no,
2218 mb->mbxCommand, 2231 mb->mbxCommand,
2219 phba->hba_state, 2232 phba->pport->port_state,
2220 psli->sli_flag, 2233 psli->sli_flag,
2221 flag); 2234 flag);
2222 2235
2223 psli->slistat.mbox_cmd++; 2236 psli->slistat.mbox_cmd++;
2224 evtctr = psli->slistat.mbox_event; 2237 evtctr = psli->slistat.mbox_event;
@@ -2285,12 +2298,12 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2285 /* Wait for command to complete */ 2298 /* Wait for command to complete */
2286 while (((word0 & OWN_CHIP) == OWN_CHIP) || 2299 while (((word0 & OWN_CHIP) == OWN_CHIP) ||
2287 (!(ha_copy & HA_MBATT) && 2300 (!(ha_copy & HA_MBATT) &&
2288 (phba->hba_state > LPFC_WARM_START))) { 2301 (phba->link_state > LPFC_WARM_START))) {
2289 if (i-- <= 0) { 2302 if (i-- <= 0) {
2290 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 2303 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2291 spin_unlock_irqrestore(phba->host->host_lock, 2304 spin_unlock_irqrestore(&phba->hbalock,
2292 drvr_flag); 2305 drvr_flag);
2293 return (MBX_NOT_FINISHED); 2306 return MBX_NOT_FINISHED;
2294 } 2307 }
2295 2308
2296 /* Check if we took a mbox interrupt while we were 2309 /* Check if we took a mbox interrupt while we were
@@ -2299,12 +2312,12 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2299 && (evtctr != psli->slistat.mbox_event)) 2312 && (evtctr != psli->slistat.mbox_event))
2300 break; 2313 break;
2301 2314
2302 spin_unlock_irqrestore(phba->host->host_lock, 2315 spin_unlock_irqrestore(&phba->hbalock,
2303 drvr_flag); 2316 drvr_flag);
2304 2317
2305 msleep(1); 2318 msleep(1);
2306 2319
2307 spin_lock_irqsave(phba->host->host_lock, drvr_flag); 2320 spin_lock_irqsave(&phba->hbalock, drvr_flag);
2308 2321
2309 if (psli->sli_flag & LPFC_SLI2_ACTIVE) { 2322 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2310 /* First copy command data */ 2323 /* First copy command data */
@@ -2342,7 +2355,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2342 MAILBOX_CMD_SIZE); 2355 MAILBOX_CMD_SIZE);
2343 if ((mb->mbxCommand == MBX_DUMP_MEMORY) && 2356 if ((mb->mbxCommand == MBX_DUMP_MEMORY) &&
2344 pmbox->context2) { 2357 pmbox->context2) {
2345 lpfc_memcpy_from_slim((void *)pmbox->context2, 2358 lpfc_memcpy_from_slim((void *) pmbox->context2,
2346 phba->MBslimaddr + DMP_RSP_OFFSET, 2359 phba->MBslimaddr + DMP_RSP_OFFSET,
2347 mb->un.varDmp.word_cnt); 2360 mb->un.varDmp.word_cnt);
2348 } 2361 }
@@ -2355,23 +2368,27 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2355 status = mb->mbxStatus; 2368 status = mb->mbxStatus;
2356 } 2369 }
2357 2370
2358 spin_unlock_irqrestore(phba->host->host_lock, drvr_flag); 2371 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
2359 return (status); 2372 return status;
2360} 2373}
2361 2374
2362static int 2375static int
2363lpfc_sli_ringtx_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, 2376lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2364 struct lpfc_iocbq * piocb) 2377 struct lpfc_iocbq *piocb)
2365{ 2378{
2379 unsigned long iflags;
2380
2366 /* Insert the caller's iocb in the txq tail for later processing. */ 2381 /* Insert the caller's iocb in the txq tail for later processing. */
2382 spin_lock_irqsave(&phba->hbalock, iflags);
2367 list_add_tail(&piocb->list, &pring->txq); 2383 list_add_tail(&piocb->list, &pring->txq);
2368 pring->txq_cnt++; 2384 pring->txq_cnt++;
2369 return (0); 2385 spin_unlock_irqrestore(&phba->hbalock, iflags);
2386 return 0;
2370} 2387}
2371 2388
2372static struct lpfc_iocbq * 2389static struct lpfc_iocbq *
2373lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 2390lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2374 struct lpfc_iocbq ** piocb) 2391 struct lpfc_iocbq **piocb)
2375{ 2392{
2376 struct lpfc_iocbq * nextiocb; 2393 struct lpfc_iocbq * nextiocb;
2377 2394
@@ -2389,6 +2406,7 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2389 struct lpfc_iocbq *piocb, uint32_t flag) 2406 struct lpfc_iocbq *piocb, uint32_t flag)
2390{ 2407{
2391 struct lpfc_iocbq *nextiocb; 2408 struct lpfc_iocbq *nextiocb;
2409 unsigned long iflags;
2392 IOCB_t *iocb; 2410 IOCB_t *iocb;
2393 2411
2394 /* If the PCI channel is in offline state, do not post iocbs. */ 2412 /* If the PCI channel is in offline state, do not post iocbs. */
@@ -2398,7 +2416,7 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2398 /* 2416 /*
2399 * We should never get an IOCB if we are in a < LINK_DOWN state 2417 * We should never get an IOCB if we are in a < LINK_DOWN state
2400 */ 2418 */
2401 if (unlikely(phba->hba_state < LPFC_LINK_DOWN)) 2419 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
2402 return IOCB_ERROR; 2420 return IOCB_ERROR;
2403 2421
2404 /* 2422 /*
@@ -2408,7 +2426,7 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2408 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX)) 2426 if (unlikely(pring->flag & LPFC_STOP_IOCB_MBX))
2409 goto iocb_busy; 2427 goto iocb_busy;
2410 2428
2411 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) { 2429 if (unlikely(phba->link_state == LPFC_LINK_DOWN)) {
2412 /* 2430 /*
2413 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF 2431 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2414 * can be issued if the link is not up. 2432 * can be issued if the link is not up.
@@ -2439,6 +2457,7 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2439 !(phba->sli.sli_flag & LPFC_PROCESS_LA))) 2457 !(phba->sli.sli_flag & LPFC_PROCESS_LA)))
2440 goto iocb_busy; 2458 goto iocb_busy;
2441 2459
2460 spin_lock_irqsave(&phba->hbalock, iflags);
2442 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) && 2461 while ((iocb = lpfc_sli_next_iocb_slot(phba, pring)) &&
2443 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb))) 2462 (nextiocb = lpfc_sli_next_iocb(phba, pring, &piocb)))
2444 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb); 2463 lpfc_sli_submit_iocb(phba, pring, iocb, nextiocb);
@@ -2447,6 +2466,7 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2447 lpfc_sli_update_ring(phba, pring); 2466 lpfc_sli_update_ring(phba, pring);
2448 else 2467 else
2449 lpfc_sli_update_full_ring(phba, pring); 2468 lpfc_sli_update_full_ring(phba, pring);
2469 spin_unlock_irqrestore(&phba->hbalock, iflags);
2450 2470
2451 if (!piocb) 2471 if (!piocb)
2452 return IOCB_SUCCESS; 2472 return IOCB_SUCCESS;
@@ -2454,7 +2474,9 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2454 goto out_busy; 2474 goto out_busy;
2455 2475
2456 iocb_busy: 2476 iocb_busy:
2477 spin_lock_irqsave(&phba->hbalock, iflags);
2457 pring->stats.iocb_cmd_delay++; 2478 pring->stats.iocb_cmd_delay++;
2479 spin_unlock_irqrestore(&phba->hbalock, iflags);
2458 2480
2459 out_busy: 2481 out_busy:
2460 2482
@@ -2539,6 +2561,7 @@ lpfc_sli_setup(struct lpfc_hba *phba)
2539 /* numCiocb and numRiocb are used in config_port */ 2561 /* numCiocb and numRiocb are used in config_port */
2540 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES; 2562 pring->numCiocb = SLI2_IOCB_CMD_R1_ENTRIES;
2541 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES; 2563 pring->numRiocb = SLI2_IOCB_RSP_R1_ENTRIES;
2564 pring->iotag_max = phba->cfg_hba_queue_depth;
2542 pring->num_mask = 0; 2565 pring->num_mask = 0;
2543 break; 2566 break;
2544 case LPFC_ELS_RING: /* ring 2 - ELS / CT */ 2567 case LPFC_ELS_RING: /* ring 2 - ELS / CT */
@@ -2591,14 +2614,14 @@ lpfc_sli_setup(struct lpfc_hba *phba)
2591} 2614}
2592 2615
2593int 2616int
2594lpfc_sli_queue_setup(struct lpfc_hba * phba) 2617lpfc_sli_queue_setup(struct lpfc_hba *phba)
2595{ 2618{
2596 struct lpfc_sli *psli; 2619 struct lpfc_sli *psli;
2597 struct lpfc_sli_ring *pring; 2620 struct lpfc_sli_ring *pring;
2598 int i; 2621 int i;
2599 2622
2600 psli = &phba->sli; 2623 psli = &phba->sli;
2601 spin_lock_irq(phba->host->host_lock); 2624 spin_lock_irq(&phba->hbalock);
2602 INIT_LIST_HEAD(&psli->mboxq); 2625 INIT_LIST_HEAD(&psli->mboxq);
2603 /* Initialize list headers for txq and txcmplq as double linked lists */ 2626 /* Initialize list headers for txq and txcmplq as double linked lists */
2604 for (i = 0; i < psli->num_rings; i++) { 2627 for (i = 0; i < psli->num_rings; i++) {
@@ -2612,15 +2635,15 @@ lpfc_sli_queue_setup(struct lpfc_hba * phba)
2612 INIT_LIST_HEAD(&pring->iocb_continueq); 2635 INIT_LIST_HEAD(&pring->iocb_continueq);
2613 INIT_LIST_HEAD(&pring->postbufq); 2636 INIT_LIST_HEAD(&pring->postbufq);
2614 } 2637 }
2615 spin_unlock_irq(phba->host->host_lock); 2638 spin_unlock_irq(&phba->hbalock);
2616 return (1); 2639 return 1;
2617} 2640}
2618 2641
2619int 2642int
2620lpfc_sli_hba_down(struct lpfc_hba * phba) 2643lpfc_sli_hba_down(struct lpfc_hba *phba)
2621{ 2644{
2622 LIST_HEAD(completions); 2645 LIST_HEAD(completions);
2623 struct lpfc_sli *psli; 2646 struct lpfc_sli *psli = &phba->sli;
2624 struct lpfc_sli_ring *pring; 2647 struct lpfc_sli_ring *pring;
2625 LPFC_MBOXQ_t *pmb; 2648 LPFC_MBOXQ_t *pmb;
2626 struct lpfc_iocbq *iocb; 2649 struct lpfc_iocbq *iocb;
@@ -2628,10 +2651,9 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
2628 int i; 2651 int i;
2629 unsigned long flags = 0; 2652 unsigned long flags = 0;
2630 2653
2631 psli = &phba->sli;
2632 lpfc_hba_down_prep(phba); 2654 lpfc_hba_down_prep(phba);
2633 2655
2634 spin_lock_irqsave(phba->host->host_lock, flags); 2656 spin_lock_irqsave(&phba->hbalock, flags);
2635 for (i = 0; i < psli->num_rings; i++) { 2657 for (i = 0; i < psli->num_rings; i++) {
2636 pring = &psli->ring[i]; 2658 pring = &psli->ring[i];
2637 pring->flag |= LPFC_DEFERRED_RING_EVENT; 2659 pring->flag |= LPFC_DEFERRED_RING_EVENT;
@@ -2644,51 +2666,48 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
2644 pring->txq_cnt = 0; 2666 pring->txq_cnt = 0;
2645 2667
2646 } 2668 }
2647 spin_unlock_irqrestore(phba->host->host_lock, flags); 2669 spin_unlock_irqrestore(&phba->hbalock, flags);
2648 2670
2649 while (!list_empty(&completions)) { 2671 while (!list_empty(&completions)) {
2650 iocb = list_get_first(&completions, struct lpfc_iocbq, list); 2672 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2651 cmd = &iocb->iocb; 2673 cmd = &iocb->iocb;
2652 list_del(&iocb->list); 2674 list_del(&iocb->list);
2653 2675
2654 if (iocb->iocb_cmpl) { 2676 if (!iocb->iocb_cmpl)
2677 lpfc_sli_release_iocbq(phba, iocb);
2678 else {
2655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT; 2679 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2656 cmd->un.ulpWord[4] = IOERR_SLI_DOWN; 2680 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2657 (iocb->iocb_cmpl) (phba, iocb, iocb); 2681 (iocb->iocb_cmpl) (phba, iocb, iocb);
2658 } else 2682 }
2659 lpfc_sli_release_iocbq(phba, iocb);
2660 } 2683 }
2661 2684
2662 /* Return any active mbox cmds */ 2685 /* Return any active mbox cmds */
2663 del_timer_sync(&psli->mbox_tmo); 2686 del_timer_sync(&psli->mbox_tmo);
2664 spin_lock_irqsave(phba->host->host_lock, flags); 2687
2665 phba->work_hba_events &= ~WORKER_MBOX_TMO; 2688 spin_lock_irqsave(&phba->pport->work_port_lock, flags);
2666 if (psli->mbox_active) { 2689 phba->pport->work_port_events &= ~WORKER_MBOX_TMO;
2667 pmb = psli->mbox_active; 2690 spin_unlock_irqrestore(&phba->pport->work_port_lock, flags);
2691
2692 pmb = psli->mbox_active;
2693 if (pmb) {
2694 psli->mbox_active = NULL;
2668 pmb->mb.mbxStatus = MBX_NOT_FINISHED; 2695 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2696 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2669 if (pmb->mbox_cmpl) { 2697 if (pmb->mbox_cmpl) {
2670 spin_unlock_irqrestore(phba->host->host_lock, flags);
2671 pmb->mbox_cmpl(phba,pmb); 2698 pmb->mbox_cmpl(phba,pmb);
2672 spin_lock_irqsave(phba->host->host_lock, flags);
2673 } 2699 }
2674 } 2700 }
2675 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2676 psli->mbox_active = NULL;
2677 2701
2678 /* Return any pending mbox cmds */ 2702 /* Return any pending mbox cmds */
2679 while ((pmb = lpfc_mbox_get(phba)) != NULL) { 2703 while ((pmb = lpfc_mbox_get(phba)) != NULL) {
2680 pmb->mb.mbxStatus = MBX_NOT_FINISHED; 2704 pmb->mb.mbxStatus = MBX_NOT_FINISHED;
2681 if (pmb->mbox_cmpl) { 2705 if (pmb->mbox_cmpl) {
2682 spin_unlock_irqrestore(phba->host->host_lock, flags);
2683 pmb->mbox_cmpl(phba,pmb); 2706 pmb->mbox_cmpl(phba,pmb);
2684 spin_lock_irqsave(phba->host->host_lock, flags);
2685 } 2707 }
2686 } 2708 }
2687
2688 INIT_LIST_HEAD(&psli->mboxq); 2709 INIT_LIST_HEAD(&psli->mboxq);
2689 2710
2690 spin_unlock_irqrestore(phba->host->host_lock, flags);
2691
2692 return 1; 2711 return 1;
2693} 2712}
2694 2713
@@ -2710,14 +2729,15 @@ lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
2710} 2729}
2711 2730
2712int 2731int
2713lpfc_sli_ringpostbuf_put(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, 2732lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2714 struct lpfc_dmabuf * mp) 2733 struct lpfc_dmabuf *mp)
2715{ 2734{
2716 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up 2735 /* Stick struct lpfc_dmabuf at end of postbufq so driver can look it up
2717 later */ 2736 later */
2737 spin_lock_irq(&phba->hbalock);
2718 list_add_tail(&mp->list, &pring->postbufq); 2738 list_add_tail(&mp->list, &pring->postbufq);
2719
2720 pring->postbufq_cnt++; 2739 pring->postbufq_cnt++;
2740 spin_unlock_irq(&phba->hbalock);
2721 return 0; 2741 return 0;
2722} 2742}
2723 2743
@@ -2730,40 +2750,41 @@ lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2730 struct list_head *slp = &pring->postbufq; 2750 struct list_head *slp = &pring->postbufq;
2731 2751
2732 /* Search postbufq, from the begining, looking for a match on phys */ 2752 /* Search postbufq, from the begining, looking for a match on phys */
2753 spin_lock_irq(&phba->hbalock);
2733 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { 2754 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
2734 if (mp->phys == phys) { 2755 if (mp->phys == phys) {
2735 list_del_init(&mp->list); 2756 list_del_init(&mp->list);
2736 pring->postbufq_cnt--; 2757 pring->postbufq_cnt--;
2758 spin_unlock_irq(&phba->hbalock);
2737 return mp; 2759 return mp;
2738 } 2760 }
2739 } 2761 }
2740 2762
2763 spin_unlock_irq(&phba->hbalock);
2741 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2764 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2742 "%d:0410 Cannot find virtual addr for mapped buf on " 2765 "%d:0410 Cannot find virtual addr for mapped buf on "
2743 "ring %d Data x%llx x%p x%p x%x\n", 2766 "ring %d Data x%llx x%p x%p x%x\n",
2744 phba->brd_no, pring->ringno, (unsigned long long)phys, 2767 phba->brd_no, pring->ringno, (unsigned long long) phys,
2745 slp->next, slp->prev, pring->postbufq_cnt); 2768 slp->next, slp->prev, pring->postbufq_cnt);
2746 return NULL; 2769 return NULL;
2747} 2770}
2748 2771
2749static void 2772static void
2750lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 2773lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2751 struct lpfc_iocbq * rspiocb) 2774 struct lpfc_iocbq *rspiocb)
2752{ 2775{
2753 IOCB_t *irsp; 2776 IOCB_t *irsp = &rspiocb->iocb;
2754 uint16_t abort_iotag, abort_context; 2777 uint16_t abort_iotag, abort_context;
2755 struct lpfc_iocbq *abort_iocb, *rsp_ab_iocb; 2778 struct lpfc_iocbq *abort_iocb, *rsp_ab_iocb;
2756 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING]; 2779 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
2757 2780
2758 abort_iocb = NULL; 2781 abort_iocb = NULL;
2759 irsp = &rspiocb->iocb;
2760
2761 spin_lock_irq(phba->host->host_lock);
2762 2782
2763 if (irsp->ulpStatus) { 2783 if (irsp->ulpStatus) {
2764 abort_context = cmdiocb->iocb.un.acxri.abortContextTag; 2784 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
2765 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag; 2785 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
2766 2786
2787 spin_lock_irq(&phba->hbalock);
2767 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag) 2788 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
2768 abort_iocb = phba->sli.iocbq_lookup[abort_iotag]; 2789 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
2769 2790
@@ -2777,41 +2798,40 @@ lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2777 * make sure we have the right iocbq before taking it 2798 * make sure we have the right iocbq before taking it
2778 * off the txcmplq and try to call completion routine. 2799 * off the txcmplq and try to call completion routine.
2779 */ 2800 */
2780 if (abort_iocb && 2801 if (!abort_iocb ||
2781 abort_iocb->iocb.ulpContext == abort_context && 2802 abort_iocb->iocb.ulpContext != abort_context ||
2782 abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) { 2803 (abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) == 0)
2804 spin_unlock_irq(&phba->hbalock);
2805 else {
2783 list_del(&abort_iocb->list); 2806 list_del(&abort_iocb->list);
2784 pring->txcmplq_cnt--; 2807 pring->txcmplq_cnt--;
2808 spin_unlock_irq(&phba->hbalock);
2785 2809
2786 rsp_ab_iocb = lpfc_sli_get_iocbq(phba); 2810 rsp_ab_iocb = lpfc_sli_get_iocbq(phba);
2787 if (rsp_ab_iocb == NULL) 2811 if (rsp_ab_iocb == NULL)
2788 lpfc_sli_release_iocbq(phba, abort_iocb); 2812 lpfc_sli_release_iocbq(phba, abort_iocb);
2789 else { 2813 else {
2790 abort_iocb->iocb_flag &= 2814 abort_iocb->iocb_flag &= ~LPFC_DRIVER_ABORTED;
2791 ~LPFC_DRIVER_ABORTED;
2792 rsp_ab_iocb->iocb.ulpStatus = 2815 rsp_ab_iocb->iocb.ulpStatus =
2793 IOSTAT_LOCAL_REJECT; 2816 IOSTAT_LOCAL_REJECT;
2794 rsp_ab_iocb->iocb.un.ulpWord[4] = 2817 rsp_ab_iocb->iocb.un.ulpWord[4] =
2795 IOERR_SLI_ABORTED; 2818 IOERR_SLI_ABORTED;
2796 spin_unlock_irq(phba->host->host_lock); 2819 (abort_iocb->iocb_cmpl)(phba, abort_iocb,
2797 (abort_iocb->iocb_cmpl) 2820 rsp_ab_iocb);
2798 (phba, abort_iocb, rsp_ab_iocb);
2799 spin_lock_irq(phba->host->host_lock);
2800 lpfc_sli_release_iocbq(phba, rsp_ab_iocb); 2821 lpfc_sli_release_iocbq(phba, rsp_ab_iocb);
2801 } 2822 }
2802 } 2823 }
2803 } 2824 }
2804 2825
2805 lpfc_sli_release_iocbq(phba, cmdiocb); 2826 lpfc_sli_release_iocbq(phba, cmdiocb);
2806 spin_unlock_irq(phba->host->host_lock);
2807 return; 2827 return;
2808} 2828}
2809 2829
2810int 2830int
2811lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba, 2831lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2812 struct lpfc_sli_ring * pring, 2832 struct lpfc_iocbq *cmdiocb)
2813 struct lpfc_iocbq * cmdiocb)
2814{ 2833{
2834 struct lpfc_vport *vport = cmdiocb->vport;
2815 struct lpfc_iocbq *abtsiocbp; 2835 struct lpfc_iocbq *abtsiocbp;
2816 IOCB_t *icmd = NULL; 2836 IOCB_t *icmd = NULL;
2817 IOCB_t *iabt = NULL; 2837 IOCB_t *iabt = NULL;
@@ -2821,14 +2841,14 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2821 * to abort. 2841 * to abort.
2822 */ 2842 */
2823 icmd = &cmdiocb->iocb; 2843 icmd = &cmdiocb->iocb;
2824 if ((icmd->ulpCommand == CMD_ABORT_XRI_CN) || 2844 if (icmd->ulpCommand == CMD_ABORT_XRI_CN ||
2825 (icmd->ulpCommand == CMD_CLOSE_XRI_CN)) 2845 icmd->ulpCommand == CMD_CLOSE_XRI_CN)
2826 return 0; 2846 return 0;
2827 2847
2828 /* If we're unloading, interrupts are disabled so we 2848 /* If we're unloading, interrupts are disabled so we
2829 * need to cleanup the iocb here. 2849 * need to cleanup the iocb here.
2830 */ 2850 */
2831 if (phba->fc_flag & FC_UNLOADING) 2851 if (vport->load_flag & FC_UNLOADING)
2832 goto abort_iotag_exit; 2852 goto abort_iotag_exit;
2833 2853
2834 /* issue ABTS for this IOCB based on iotag */ 2854 /* issue ABTS for this IOCB based on iotag */
@@ -2848,7 +2868,7 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2848 iabt->ulpLe = 1; 2868 iabt->ulpLe = 1;
2849 iabt->ulpClass = icmd->ulpClass; 2869 iabt->ulpClass = icmd->ulpClass;
2850 2870
2851 if (phba->hba_state >= LPFC_LINK_UP) 2871 if (phba->link_state >= LPFC_LINK_UP)
2852 iabt->ulpCommand = CMD_ABORT_XRI_CN; 2872 iabt->ulpCommand = CMD_ABORT_XRI_CN;
2853 else 2873 else
2854 iabt->ulpCommand = CMD_CLOSE_XRI_CN; 2874 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
@@ -2863,25 +2883,12 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2863 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); 2883 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
2864 2884
2865abort_iotag_exit: 2885abort_iotag_exit:
2866 2886 /*
2867 /* If we could not issue an abort dequeue the iocb and handle 2887 * Caller to this routine should check for IOCB_ERROR
2868 * the completion here. 2888 * and handle it properly. This routine no longer removes
2889 * iocb off txcmplq and call compl in case of IOCB_ERROR.
2869 */ 2890 */
2870 if (retval == IOCB_ERROR) { 2891 return retval;
2871 list_del(&cmdiocb->list);
2872 pring->txcmplq_cnt--;
2873
2874 if (cmdiocb->iocb_cmpl) {
2875 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2876 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2877 spin_unlock_irq(phba->host->host_lock);
2878 (cmdiocb->iocb_cmpl) (phba, cmdiocb, cmdiocb);
2879 spin_lock_irq(phba->host->host_lock);
2880 } else
2881 lpfc_sli_release_iocbq(phba, cmdiocb);
2882 }
2883
2884 return 1;
2885} 2892}
2886 2893
2887static int 2894static int
@@ -2930,7 +2937,7 @@ lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, uint16_t tgt_id,
2930 2937
2931int 2938int
2932lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 2939lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2933 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd) 2940 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd ctx_cmd)
2934{ 2941{
2935 struct lpfc_iocbq *iocbq; 2942 struct lpfc_iocbq *iocbq;
2936 int sum, i; 2943 int sum, i;
@@ -2947,14 +2954,10 @@ lpfc_sli_sum_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2947} 2954}
2948 2955
2949void 2956void
2950lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 2957lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2951 struct lpfc_iocbq * rspiocb) 2958 struct lpfc_iocbq *rspiocb)
2952{ 2959{
2953 unsigned long iflags;
2954
2955 spin_lock_irqsave(phba->host->host_lock, iflags);
2956 lpfc_sli_release_iocbq(phba, cmdiocb); 2960 lpfc_sli_release_iocbq(phba, cmdiocb);
2957 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2958 return; 2961 return;
2959} 2962}
2960 2963
@@ -2972,8 +2975,8 @@ lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2972 for (i = 1; i <= phba->sli.last_iotag; i++) { 2975 for (i = 1; i <= phba->sli.last_iotag; i++) {
2973 iocbq = phba->sli.iocbq_lookup[i]; 2976 iocbq = phba->sli.iocbq_lookup[i];
2974 2977
2975 if (lpfc_sli_validate_fcp_iocb (iocbq, tgt_id, lun_id, 2978 if (lpfc_sli_validate_fcp_iocb(iocbq, tgt_id, lun_id, 0,
2976 0, abort_cmd) != 0) 2979 abort_cmd) != 0)
2977 continue; 2980 continue;
2978 2981
2979 /* issue ABTS for this IOCB based on iotag */ 2982 /* issue ABTS for this IOCB based on iotag */
@@ -2989,8 +2992,9 @@ lpfc_sli_abort_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2989 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag; 2992 abtsiocb->iocb.un.acxri.abortIoTag = cmd->ulpIoTag;
2990 abtsiocb->iocb.ulpLe = 1; 2993 abtsiocb->iocb.ulpLe = 1;
2991 abtsiocb->iocb.ulpClass = cmd->ulpClass; 2994 abtsiocb->iocb.ulpClass = cmd->ulpClass;
2995 abtsiocb->vport = phba->pport;
2992 2996
2993 if (phba->hba_state >= LPFC_LINK_UP) 2997 if (lpfc_is_link_up(phba))
2994 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN; 2998 abtsiocb->iocb.ulpCommand = CMD_ABORT_XRI_CN;
2995 else 2999 else
2996 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN; 3000 abtsiocb->iocb.ulpCommand = CMD_CLOSE_XRI_CN;
@@ -3016,14 +3020,14 @@ lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3016 wait_queue_head_t *pdone_q; 3020 wait_queue_head_t *pdone_q;
3017 unsigned long iflags; 3021 unsigned long iflags;
3018 3022
3019 spin_lock_irqsave(phba->host->host_lock, iflags); 3023 spin_lock_irqsave(&phba->hbalock, iflags);
3020 cmdiocbq->iocb_flag |= LPFC_IO_WAKE; 3024 cmdiocbq->iocb_flag |= LPFC_IO_WAKE;
3021 if (cmdiocbq->context2 && rspiocbq) 3025 if (cmdiocbq->context2 && rspiocbq)
3022 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb, 3026 memcpy(&((struct lpfc_iocbq *)cmdiocbq->context2)->iocb,
3023 &rspiocbq->iocb, sizeof(IOCB_t)); 3027 &rspiocbq->iocb, sizeof(IOCB_t));
3024 3028
3025 pdone_q = cmdiocbq->context_un.wait_queue; 3029 pdone_q = cmdiocbq->context_un.wait_queue;
3026 spin_unlock_irqrestore(phba->host->host_lock, iflags); 3030 spin_unlock_irqrestore(&phba->hbalock, iflags);
3027 if (pdone_q) 3031 if (pdone_q)
3028 wake_up(pdone_q); 3032 wake_up(pdone_q);
3029 return; 3033 return;
@@ -3036,10 +3040,10 @@ lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3036 * definition this is a wait function. 3040 * definition this is a wait function.
3037 */ 3041 */
3038int 3042int
3039lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba, 3043lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3040 struct lpfc_sli_ring * pring, 3044 struct lpfc_sli_ring *pring,
3041 struct lpfc_iocbq * piocb, 3045 struct lpfc_iocbq *piocb,
3042 struct lpfc_iocbq * prspiocbq, 3046 struct lpfc_iocbq *prspiocbq,
3043 uint32_t timeout) 3047 uint32_t timeout)
3044{ 3048{
3045 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); 3049 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
@@ -3071,11 +3075,11 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
3071 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0); 3075 retval = lpfc_sli_issue_iocb(phba, pring, piocb, 0);
3072 if (retval == IOCB_SUCCESS) { 3076 if (retval == IOCB_SUCCESS) {
3073 timeout_req = timeout * HZ; 3077 timeout_req = timeout * HZ;
3074 spin_unlock_irq(phba->host->host_lock); 3078 spin_unlock_irq(&phba->hbalock);
3075 timeleft = wait_event_timeout(done_q, 3079 timeleft = wait_event_timeout(done_q,
3076 piocb->iocb_flag & LPFC_IO_WAKE, 3080 piocb->iocb_flag & LPFC_IO_WAKE,
3077 timeout_req); 3081 timeout_req);
3078 spin_lock_irq(phba->host->host_lock); 3082 spin_lock_irq(&phba->hbalock);
3079 3083
3080 if (piocb->iocb_flag & LPFC_IO_WAKE) { 3084 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 3085 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
@@ -3117,7 +3121,7 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
3117} 3121}
3118 3122
3119int 3123int
3120lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq, 3124lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3121 uint32_t timeout) 3125 uint32_t timeout)
3122{ 3126{
3123 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); 3127 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
@@ -3125,7 +3129,7 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3125 3129
3126 /* The caller must leave context1 empty. */ 3130 /* The caller must leave context1 empty. */
3127 if (pmboxq->context1 != 0) { 3131 if (pmboxq->context1 != 0) {
3128 return (MBX_NOT_FINISHED); 3132 return MBX_NOT_FINISHED;
3129 } 3133 }
3130 3134
3131 /* setup wake call as IOCB callback */ 3135 /* setup wake call as IOCB callback */
@@ -3158,9 +3162,10 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3158int 3162int
3159lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) 3163lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3160{ 3164{
3165 struct lpfc_vport *vport = phba->pport;
3161 int i = 0; 3166 int i = 0;
3162 3167
3163 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !phba->stopped) { 3168 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE && !vport->stopped) {
3164 if (i++ > LPFC_MBOX_TMO * 1000) 3169 if (i++ > LPFC_MBOX_TMO * 1000)
3165 return 1; 3170 return 1;
3166 3171
@@ -3176,7 +3181,7 @@ lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
3176irqreturn_t 3181irqreturn_t
3177lpfc_intr_handler(int irq, void *dev_id) 3182lpfc_intr_handler(int irq, void *dev_id)
3178{ 3183{
3179 struct lpfc_hba *phba; 3184 struct lpfc_hba *phba;
3180 uint32_t ha_copy; 3185 uint32_t ha_copy;
3181 uint32_t work_ha_copy; 3186 uint32_t work_ha_copy;
3182 unsigned long status; 3187 unsigned long status;
@@ -3204,7 +3209,7 @@ lpfc_intr_handler(int irq, void *dev_id)
3204 */ 3209 */
3205 3210
3206 /* Ignore all interrupts during initialization. */ 3211 /* Ignore all interrupts during initialization. */
3207 if (unlikely(phba->hba_state < LPFC_LINK_DOWN)) 3212 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
3208 return IRQ_NONE; 3213 return IRQ_NONE;
3209 3214
3210 /* 3215 /*
@@ -3212,16 +3217,16 @@ lpfc_intr_handler(int irq, void *dev_id)
3212 * Clear Attention Sources, except Error Attention (to 3217 * Clear Attention Sources, except Error Attention (to
3213 * preserve status) and Link Attention 3218 * preserve status) and Link Attention
3214 */ 3219 */
3215 spin_lock(phba->host->host_lock); 3220 spin_lock(&phba->hbalock);
3216 ha_copy = readl(phba->HAregaddr); 3221 ha_copy = readl(phba->HAregaddr);
3217 /* If somebody is waiting to handle an eratt don't process it 3222 /* If somebody is waiting to handle an eratt don't process it
3218 * here. The brdkill function will do this. 3223 * here. The brdkill function will do this.
3219 */ 3224 */
3220 if (phba->fc_flag & FC_IGNORE_ERATT) 3225 if (phba->link_flag & LS_IGNORE_ERATT)
3221 ha_copy &= ~HA_ERATT; 3226 ha_copy &= ~HA_ERATT;
3222 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); 3227 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3223 readl(phba->HAregaddr); /* flush */ 3228 readl(phba->HAregaddr); /* flush */
3224 spin_unlock(phba->host->host_lock); 3229 spin_unlock(&phba->hbalock);
3225 3230
3226 if (unlikely(!ha_copy)) 3231 if (unlikely(!ha_copy))
3227 return IRQ_NONE; 3232 return IRQ_NONE;
@@ -3235,13 +3240,13 @@ lpfc_intr_handler(int irq, void *dev_id)
3235 * Turn off Link Attention interrupts 3240 * Turn off Link Attention interrupts
3236 * until CLEAR_LA done 3241 * until CLEAR_LA done
3237 */ 3242 */
3238 spin_lock(phba->host->host_lock); 3243 spin_lock(&phba->hbalock);
3239 phba->sli.sli_flag &= ~LPFC_PROCESS_LA; 3244 phba->sli.sli_flag &= ~LPFC_PROCESS_LA;
3240 control = readl(phba->HCregaddr); 3245 control = readl(phba->HCregaddr);
3241 control &= ~HC_LAINT_ENA; 3246 control &= ~HC_LAINT_ENA;
3242 writel(control, phba->HCregaddr); 3247 writel(control, phba->HCregaddr);
3243 readl(phba->HCregaddr); /* flush */ 3248 readl(phba->HCregaddr); /* flush */
3244 spin_unlock(phba->host->host_lock); 3249 spin_unlock(&phba->hbalock);
3245 } 3250 }
3246 else 3251 else
3247 work_ha_copy &= ~HA_LATT; 3252 work_ha_copy &= ~HA_LATT;
@@ -3253,18 +3258,18 @@ lpfc_intr_handler(int irq, void *dev_id)
3253 /* 3258 /*
3254 * Turn off Slow Rings interrupts 3259 * Turn off Slow Rings interrupts
3255 */ 3260 */
3256 spin_lock(phba->host->host_lock); 3261 spin_lock(&phba->hbalock);
3257 control = readl(phba->HCregaddr); 3262 control = readl(phba->HCregaddr);
3258 control &= ~(HC_R0INT_ENA << i); 3263 control &= ~(HC_R0INT_ENA << i);
3259 writel(control, phba->HCregaddr); 3264 writel(control, phba->HCregaddr);
3260 readl(phba->HCregaddr); /* flush */ 3265 readl(phba->HCregaddr); /* flush */
3261 spin_unlock(phba->host->host_lock); 3266 spin_unlock(&phba->hbalock);
3262 } 3267 }
3263 } 3268 }
3264 } 3269 }
3265 3270
3266 if (work_ha_copy & HA_ERATT) { 3271 if (work_ha_copy & HA_ERATT) {
3267 phba->hba_state = LPFC_HBA_ERROR; 3272 phba->link_state = LPFC_HBA_ERROR;
3268 /* 3273 /*
3269 * There was a link/board error. Read the 3274 * There was a link/board error. Read the
3270 * status register to retrieve the error event 3275 * status register to retrieve the error event
@@ -3279,14 +3284,14 @@ lpfc_intr_handler(int irq, void *dev_id)
3279 /* Clear Chip error bit */ 3284 /* Clear Chip error bit */
3280 writel(HA_ERATT, phba->HAregaddr); 3285 writel(HA_ERATT, phba->HAregaddr);
3281 readl(phba->HAregaddr); /* flush */ 3286 readl(phba->HAregaddr); /* flush */
3282 phba->stopped = 1; 3287 phba->pport->stopped = 1;
3283 } 3288 }
3284 3289
3285 spin_lock(phba->host->host_lock); 3290 spin_lock(&phba->hbalock);
3286 phba->work_ha |= work_ha_copy; 3291 phba->work_ha |= work_ha_copy;
3287 if (phba->work_wait) 3292 if (phba->work_wait)
3288 wake_up(phba->work_wait); 3293 wake_up(phba->work_wait);
3289 spin_unlock(phba->host->host_lock); 3294 spin_unlock(&phba->hbalock);
3290 } 3295 }
3291 3296
3292 ha_copy &= ~(phba->work_ha_mask); 3297 ha_copy &= ~(phba->work_ha_mask);