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.c1715
1 files changed, 1519 insertions, 196 deletions
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 50fe07646738..8ab5babdeebc 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -32,6 +32,7 @@
32 32
33#include "lpfc_hw.h" 33#include "lpfc_hw.h"
34#include "lpfc_sli.h" 34#include "lpfc_sli.h"
35#include "lpfc_nl.h"
35#include "lpfc_disc.h" 36#include "lpfc_disc.h"
36#include "lpfc_scsi.h" 37#include "lpfc_scsi.h"
37#include "lpfc.h" 38#include "lpfc.h"
@@ -66,10 +67,16 @@ typedef enum _lpfc_iocb_type {
66 LPFC_ABORT_IOCB 67 LPFC_ABORT_IOCB
67} lpfc_iocb_type; 68} lpfc_iocb_type;
68 69
69 /* SLI-2/SLI-3 provide different sized iocbs. Given a pointer 70/**
70 * to the start of the ring, and the slot number of the 71 * lpfc_cmd_iocb: Get next command iocb entry in the ring.
71 * desired iocb entry, calc a pointer to that entry. 72 * @phba: Pointer to HBA context object.
72 */ 73 * @pring: Pointer to driver SLI ring object.
74 *
75 * This function returns pointer to next command iocb entry
76 * in the command ring. The caller must hold hbalock to prevent
77 * other threads consume the next command iocb.
78 * SLI-2/SLI-3 provide different sized iocbs.
79 **/
73static inline IOCB_t * 80static inline IOCB_t *
74lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 81lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
75{ 82{
@@ -77,6 +84,16 @@ lpfc_cmd_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
77 pring->cmdidx * phba->iocb_cmd_size); 84 pring->cmdidx * phba->iocb_cmd_size);
78} 85}
79 86
87/**
88 * lpfc_resp_iocb: Get next response iocb entry in the ring.
89 * @phba: Pointer to HBA context object.
90 * @pring: Pointer to driver SLI ring object.
91 *
92 * This function returns pointer to next response iocb entry
93 * in the response ring. The caller must hold hbalock to make sure
94 * that no other thread consume the next response iocb.
95 * SLI-2/SLI-3 provide different sized iocbs.
96 **/
80static inline IOCB_t * 97static inline IOCB_t *
81lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 98lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
82{ 99{
@@ -84,6 +101,15 @@ lpfc_resp_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
84 pring->rspidx * phba->iocb_rsp_size); 101 pring->rspidx * phba->iocb_rsp_size);
85} 102}
86 103
104/**
105 * __lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool.
106 * @phba: Pointer to HBA context object.
107 *
108 * This function is called with hbalock held. This function
109 * allocates a new driver iocb object from the iocb pool. If the
110 * allocation is successful, it returns pointer to the newly
111 * allocated iocb object else it returns NULL.
112 **/
87static struct lpfc_iocbq * 113static struct lpfc_iocbq *
88__lpfc_sli_get_iocbq(struct lpfc_hba *phba) 114__lpfc_sli_get_iocbq(struct lpfc_hba *phba)
89{ 115{
@@ -94,6 +120,15 @@ __lpfc_sli_get_iocbq(struct lpfc_hba *phba)
94 return iocbq; 120 return iocbq;
95} 121}
96 122
123/**
124 * lpfc_sli_get_iocbq: Allocates an iocb object from iocb pool.
125 * @phba: Pointer to HBA context object.
126 *
127 * This function is called with no lock held. This function
128 * allocates a new driver iocb object from the iocb pool. If the
129 * allocation is successful, it returns pointer to the newly
130 * allocated iocb object else it returns NULL.
131 **/
97struct lpfc_iocbq * 132struct lpfc_iocbq *
98lpfc_sli_get_iocbq(struct lpfc_hba *phba) 133lpfc_sli_get_iocbq(struct lpfc_hba *phba)
99{ 134{
@@ -106,6 +141,16 @@ lpfc_sli_get_iocbq(struct lpfc_hba *phba)
106 return iocbq; 141 return iocbq;
107} 142}
108 143
144/**
145 * __lpfc_sli_release_iocbq: Release iocb to the iocb pool.
146 * @phba: Pointer to HBA context object.
147 * @iocbq: Pointer to driver iocb object.
148 *
149 * This function is called with hbalock held to release driver
150 * iocb object to the iocb pool. The iotag in the iocb object
151 * does not change for each use of the iocb object. This function
152 * clears all other fields of the iocb object when it is freed.
153 **/
109static void 154static void
110__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) 155__lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
111{ 156{
@@ -118,6 +163,14 @@ __lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
118 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list); 163 list_add_tail(&iocbq->list, &phba->lpfc_iocb_list);
119} 164}
120 165
166/**
167 * lpfc_sli_release_iocbq: Release iocb to the iocb pool.
168 * @phba: Pointer to HBA context object.
169 * @iocbq: Pointer to driver iocb object.
170 *
171 * This function is called with no lock held to release the iocb to
172 * iocb pool.
173 **/
121void 174void
122lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) 175lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
123{ 176{
@@ -131,10 +184,21 @@ lpfc_sli_release_iocbq(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
131 spin_unlock_irqrestore(&phba->hbalock, iflags); 184 spin_unlock_irqrestore(&phba->hbalock, iflags);
132} 185}
133 186
134/* 187/**
135 * Translate the iocb command to an iocb command type used to decide the final 188 * lpfc_sli_iocb_cmd_type: Get the iocb type.
136 * disposition of each completed IOCB. 189 * @iocb_cmnd : iocb command code.
137 */ 190 *
191 * This function is called by ring event handler function to get the iocb type.
192 * This function translates the iocb command to an iocb command type used to
193 * decide the final disposition of each completed IOCB.
194 * The function returns
195 * LPFC_UNKNOWN_IOCB if it is an unsupported iocb
196 * LPFC_SOL_IOCB if it is a solicited iocb completion
197 * LPFC_ABORT_IOCB if it is an abort iocb
198 * LPFC_UNSOL_IOCB if it is an unsolicited iocb
199 *
200 * The caller is not required to hold any lock.
201 **/
138static lpfc_iocb_type 202static lpfc_iocb_type
139lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd) 203lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
140{ 204{
@@ -230,6 +294,17 @@ lpfc_sli_iocb_cmd_type(uint8_t iocb_cmnd)
230 return type; 294 return type;
231} 295}
232 296
297/**
298 * lpfc_sli_ring_map: Issue config_ring mbox for all rings.
299 * @phba: Pointer to HBA context object.
300 *
301 * This function is called from SLI initialization code
302 * to configure every ring of the HBA's SLI interface. The
303 * caller is not required to hold any lock. This function issues
304 * a config_ring mailbox command for each ring.
305 * This function returns zero if successful else returns a negative
306 * error code.
307 **/
233static int 308static int
234lpfc_sli_ring_map(struct lpfc_hba *phba) 309lpfc_sli_ring_map(struct lpfc_hba *phba)
235{ 310{
@@ -262,6 +337,18 @@ lpfc_sli_ring_map(struct lpfc_hba *phba)
262 return ret; 337 return ret;
263} 338}
264 339
340/**
341 * lpfc_sli_ringtxcmpl_put: Adds new iocb to the txcmplq.
342 * @phba: Pointer to HBA context object.
343 * @pring: Pointer to driver SLI ring object.
344 * @piocb: Pointer to the driver iocb object.
345 *
346 * This function is called with hbalock held. The function adds the
347 * new iocb to txcmplq of the given ring. This function always returns
348 * 0. If this function is called for ELS ring, this function checks if
349 * there is a vport associated with the ELS command. This function also
350 * starts els_tmofunc timer if this is an ELS command.
351 **/
265static int 352static int
266lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 353lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
267 struct lpfc_iocbq *piocb) 354 struct lpfc_iocbq *piocb)
@@ -282,6 +369,16 @@ lpfc_sli_ringtxcmpl_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
282 return 0; 369 return 0;
283} 370}
284 371
372/**
373 * lpfc_sli_ringtx_get: Get first element of the txq.
374 * @phba: Pointer to HBA context object.
375 * @pring: Pointer to driver SLI ring object.
376 *
377 * This function is called with hbalock held to get next
378 * iocb in txq of the given ring. If there is any iocb in
379 * the txq, the function returns first iocb in the list after
380 * removing the iocb from the list, else it returns NULL.
381 **/
285static struct lpfc_iocbq * 382static struct lpfc_iocbq *
286lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 383lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
287{ 384{
@@ -293,14 +390,25 @@ lpfc_sli_ringtx_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
293 return cmd_iocb; 390 return cmd_iocb;
294} 391}
295 392
393/**
394 * lpfc_sli_next_iocb_slot: Get next iocb slot in the ring.
395 * @phba: Pointer to HBA context object.
396 * @pring: Pointer to driver SLI ring object.
397 *
398 * This function is called with hbalock held and the caller must post the
399 * iocb without releasing the lock. If the caller releases the lock,
400 * iocb slot returned by the function is not guaranteed to be available.
401 * The function returns pointer to the next available iocb slot if there
402 * is available slot in the ring, else it returns NULL.
403 * If the get index of the ring is ahead of the put index, the function
404 * will post an error attention event to the worker thread to take the
405 * HBA to offline state.
406 **/
296static IOCB_t * 407static IOCB_t *
297lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 408lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
298{ 409{
299 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? 410 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
300 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
301 &phba->slim2p->mbx.us.s2.port[pring->ringno];
302 uint32_t max_cmd_idx = pring->numCiocb; 411 uint32_t max_cmd_idx = pring->numCiocb;
303
304 if ((pring->next_cmdidx == pring->cmdidx) && 412 if ((pring->next_cmdidx == pring->cmdidx) &&
305 (++pring->next_cmdidx >= max_cmd_idx)) 413 (++pring->next_cmdidx >= max_cmd_idx))
306 pring->next_cmdidx = 0; 414 pring->next_cmdidx = 0;
@@ -336,6 +444,18 @@ lpfc_sli_next_iocb_slot (struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
336 return lpfc_cmd_iocb(phba, pring); 444 return lpfc_cmd_iocb(phba, pring);
337} 445}
338 446
447/**
448 * lpfc_sli_next_iotag: Get an iotag for the iocb.
449 * @phba: Pointer to HBA context object.
450 * @iocbq: Pointer to driver iocb object.
451 *
452 * This function gets an iotag for the iocb. If there is no unused iotag and
453 * the iocbq_lookup_len < 0xffff, this function allocates a bigger iotag_lookup
454 * array and assigns a new iotag.
455 * The function returns the allocated iotag if successful, else returns zero.
456 * Zero is not a valid iotag.
457 * The caller is not required to hold any lock.
458 **/
339uint16_t 459uint16_t
340lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq) 460lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
341{ 461{
@@ -399,6 +519,20 @@ lpfc_sli_next_iotag(struct lpfc_hba *phba, struct lpfc_iocbq *iocbq)
399 return 0; 519 return 0;
400} 520}
401 521
522/**
523 * lpfc_sli_submit_iocb: Submit an iocb to the firmware.
524 * @phba: Pointer to HBA context object.
525 * @pring: Pointer to driver SLI ring object.
526 * @iocb: Pointer to iocb slot in the ring.
527 * @nextiocb: Pointer to driver iocb object which need to be
528 * posted to firmware.
529 *
530 * This function is called with hbalock held to post a new iocb to
531 * the firmware. This function copies the new iocb to ring iocb slot and
532 * updates the ring pointers. It adds the new iocb to txcmplq if there is
533 * a completion call back for this iocb else the function will free the
534 * iocb object.
535 **/
402static void 536static void
403lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 537lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
404 IOCB_t *iocb, struct lpfc_iocbq *nextiocb) 538 IOCB_t *iocb, struct lpfc_iocbq *nextiocb)
@@ -441,6 +575,18 @@ lpfc_sli_submit_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
441 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx); 575 writel(pring->cmdidx, &phba->host_gp[pring->ringno].cmdPutInx);
442} 576}
443 577
578/**
579 * lpfc_sli_update_full_ring: Update the chip attention register.
580 * @phba: Pointer to HBA context object.
581 * @pring: Pointer to driver SLI ring object.
582 *
583 * The caller is not required to hold any lock for calling this function.
584 * This function updates the chip attention bits for the ring to inform firmware
585 * that there are pending work to be done for this ring and requests an
586 * interrupt when there is space available in the ring. This function is
587 * called when the driver is unable to post more iocbs to the ring due
588 * to unavailability of space in the ring.
589 **/
444static void 590static void
445lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 591lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
446{ 592{
@@ -460,6 +606,15 @@ lpfc_sli_update_full_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
460 pring->stats.iocb_cmd_full++; 606 pring->stats.iocb_cmd_full++;
461} 607}
462 608
609/**
610 * lpfc_sli_update_ring: Update chip attention register.
611 * @phba: Pointer to HBA context object.
612 * @pring: Pointer to driver SLI ring object.
613 *
614 * This function updates the chip attention register bit for the
615 * given ring to inform HBA that there is more work to be done
616 * in this ring. The caller is not required to hold any lock.
617 **/
463static void 618static void
464lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 619lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
465{ 620{
@@ -468,11 +623,22 @@ lpfc_sli_update_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
468 /* 623 /*
469 * Tell the HBA that there is work to do in this ring. 624 * Tell the HBA that there is work to do in this ring.
470 */ 625 */
471 wmb(); 626 if (!(phba->sli3_options & LPFC_SLI3_CRP_ENABLED)) {
472 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr); 627 wmb();
473 readl(phba->CAregaddr); /* flush */ 628 writel(CA_R0ATT << (ringno * 4), phba->CAregaddr);
629 readl(phba->CAregaddr); /* flush */
630 }
474} 631}
475 632
633/**
634 * lpfc_sli_resume_iocb: Process iocbs in the txq.
635 * @phba: Pointer to HBA context object.
636 * @pring: Pointer to driver SLI ring object.
637 *
638 * This function is called with hbalock held to post pending iocbs
639 * in the txq to the firmware. This function is called when driver
640 * detects space available in the ring.
641 **/
476static void 642static void
477lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 643lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
478{ 644{
@@ -504,6 +670,16 @@ lpfc_sli_resume_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
504 return; 670 return;
505} 671}
506 672
673/**
674 * lpfc_sli_next_hbq_slot: Get next hbq entry for the HBQ.
675 * @phba: Pointer to HBA context object.
676 * @hbqno: HBQ number.
677 *
678 * This function is called with hbalock held to get the next
679 * available slot for the given HBQ. If there is free slot
680 * available for the HBQ it will return pointer to the next available
681 * HBQ entry else it will return NULL.
682 **/
507static struct lpfc_hbq_entry * 683static struct lpfc_hbq_entry *
508lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno) 684lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
509{ 685{
@@ -539,6 +715,15 @@ lpfc_sli_next_hbq_slot(struct lpfc_hba *phba, uint32_t hbqno)
539 hbqp->hbqPutIdx; 715 hbqp->hbqPutIdx;
540} 716}
541 717
718/**
719 * lpfc_sli_hbqbuf_free_all: Free all the hbq buffers.
720 * @phba: Pointer to HBA context object.
721 *
722 * This function is called with no lock held to free all the
723 * hbq buffers while uninitializing the SLI interface. It also
724 * frees the HBQ buffers returned by the firmware but not yet
725 * processed by the upper layers.
726 **/
542void 727void
543lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba) 728lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
544{ 729{
@@ -584,6 +769,18 @@ lpfc_sli_hbqbuf_free_all(struct lpfc_hba *phba)
584 spin_unlock_irqrestore(&phba->hbalock, flags); 769 spin_unlock_irqrestore(&phba->hbalock, flags);
585} 770}
586 771
772/**
773 * lpfc_sli_hbq_to_firmware: Post the hbq buffer to firmware.
774 * @phba: Pointer to HBA context object.
775 * @hbqno: HBQ number.
776 * @hbq_buf: Pointer to HBQ buffer.
777 *
778 * This function is called with the hbalock held to post a
779 * hbq buffer to the firmware. If the function finds an empty
780 * slot in the HBQ, it will post the buffer. The function will return
781 * pointer to the hbq entry if it successfully post the buffer
782 * else it will return NULL.
783 **/
587static struct lpfc_hbq_entry * 784static struct lpfc_hbq_entry *
588lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno, 785lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
589 struct hbq_dmabuf *hbq_buf) 786 struct hbq_dmabuf *hbq_buf)
@@ -612,6 +809,7 @@ lpfc_sli_hbq_to_firmware(struct lpfc_hba *phba, uint32_t hbqno,
612 return hbqe; 809 return hbqe;
613} 810}
614 811
812/* HBQ for ELS and CT traffic. */
615static struct lpfc_hbq_init lpfc_els_hbq = { 813static struct lpfc_hbq_init lpfc_els_hbq = {
616 .rn = 1, 814 .rn = 1,
617 .entry_count = 200, 815 .entry_count = 200,
@@ -623,6 +821,7 @@ static struct lpfc_hbq_init lpfc_els_hbq = {
623 .add_count = 5, 821 .add_count = 5,
624}; 822};
625 823
824/* HBQ for the extra ring if needed */
626static struct lpfc_hbq_init lpfc_extra_hbq = { 825static struct lpfc_hbq_init lpfc_extra_hbq = {
627 .rn = 1, 826 .rn = 1,
628 .entry_count = 200, 827 .entry_count = 200,
@@ -634,51 +833,81 @@ static struct lpfc_hbq_init lpfc_extra_hbq = {
634 .add_count = 5, 833 .add_count = 5,
635}; 834};
636 835
836/* Array of HBQs */
637struct lpfc_hbq_init *lpfc_hbq_defs[] = { 837struct lpfc_hbq_init *lpfc_hbq_defs[] = {
638 &lpfc_els_hbq, 838 &lpfc_els_hbq,
639 &lpfc_extra_hbq, 839 &lpfc_extra_hbq,
640}; 840};
641 841
842/**
843 * lpfc_sli_hbqbuf_fill_hbqs: Post more hbq buffers to HBQ.
844 * @phba: Pointer to HBA context object.
845 * @hbqno: HBQ number.
846 * @count: Number of HBQ buffers to be posted.
847 *
848 * This function is called with no lock held to post more hbq buffers to the
849 * given HBQ. The function returns the number of HBQ buffers successfully
850 * posted.
851 **/
642static int 852static int
643lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count) 853lpfc_sli_hbqbuf_fill_hbqs(struct lpfc_hba *phba, uint32_t hbqno, uint32_t count)
644{ 854{
645 uint32_t i, start, end; 855 uint32_t i, posted = 0;
646 unsigned long flags; 856 unsigned long flags;
647 struct hbq_dmabuf *hbq_buffer; 857 struct hbq_dmabuf *hbq_buffer;
648 858 LIST_HEAD(hbq_buf_list);
649 if (!phba->hbqs[hbqno].hbq_alloc_buffer) 859 if (!phba->hbqs[hbqno].hbq_alloc_buffer)
650 return 0; 860 return 0;
651 861
652 start = phba->hbqs[hbqno].buffer_count; 862 if ((phba->hbqs[hbqno].buffer_count + count) >
653 end = count + start; 863 lpfc_hbq_defs[hbqno]->entry_count)
654 if (end > lpfc_hbq_defs[hbqno]->entry_count) 864 count = lpfc_hbq_defs[hbqno]->entry_count -
655 end = lpfc_hbq_defs[hbqno]->entry_count; 865 phba->hbqs[hbqno].buffer_count;
656 866 if (!count)
867 return 0;
868 /* Allocate HBQ entries */
869 for (i = 0; i < count; i++) {
870 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
871 if (!hbq_buffer)
872 break;
873 list_add_tail(&hbq_buffer->dbuf.list, &hbq_buf_list);
874 }
657 /* Check whether HBQ is still in use */ 875 /* Check whether HBQ is still in use */
658 spin_lock_irqsave(&phba->hbalock, flags); 876 spin_lock_irqsave(&phba->hbalock, flags);
659 if (!phba->hbq_in_use) 877 if (!phba->hbq_in_use)
660 goto out; 878 goto err;
661 879 while (!list_empty(&hbq_buf_list)) {
662 /* Populate HBQ entries */ 880 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
663 for (i = start; i < end; i++) { 881 dbuf.list);
664 hbq_buffer = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba); 882 hbq_buffer->tag = (phba->hbqs[hbqno].buffer_count |
665 if (!hbq_buffer) 883 (hbqno << 16));
666 goto err; 884 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer)) {
667 hbq_buffer->tag = (i | (hbqno << 16));
668 if (lpfc_sli_hbq_to_firmware(phba, hbqno, hbq_buffer))
669 phba->hbqs[hbqno].buffer_count++; 885 phba->hbqs[hbqno].buffer_count++;
670 else 886 posted++;
887 } else
671 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer); 888 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
672 } 889 }
673
674 out:
675 spin_unlock_irqrestore(&phba->hbalock, flags); 890 spin_unlock_irqrestore(&phba->hbalock, flags);
676 return 0; 891 return posted;
677 err: 892err:
678 spin_unlock_irqrestore(&phba->hbalock, flags); 893 spin_unlock_irqrestore(&phba->hbalock, flags);
679 return 1; 894 while (!list_empty(&hbq_buf_list)) {
895 list_remove_head(&hbq_buf_list, hbq_buffer, struct hbq_dmabuf,
896 dbuf.list);
897 (phba->hbqs[hbqno].hbq_free_buffer)(phba, hbq_buffer);
898 }
899 return 0;
680} 900}
681 901
902/**
903 * lpfc_sli_hbqbuf_add_hbqs: Post more HBQ buffers to firmware.
904 * @phba: Pointer to HBA context object.
905 * @qno: HBQ number.
906 *
907 * This function posts more buffers to the HBQ. This function
908 * is called with no lock held. The function returns the number of HBQ entries
909 * successfully allocated.
910 **/
682int 911int
683lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno) 912lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
684{ 913{
@@ -686,6 +915,15 @@ lpfc_sli_hbqbuf_add_hbqs(struct lpfc_hba *phba, uint32_t qno)
686 lpfc_hbq_defs[qno]->add_count)); 915 lpfc_hbq_defs[qno]->add_count));
687} 916}
688 917
918/**
919 * lpfc_sli_hbqbuf_init_hbqs: Post initial buffers to the HBQ.
920 * @phba: Pointer to HBA context object.
921 * @qno: HBQ queue number.
922 *
923 * This function is called from SLI initialization code path with
924 * no lock held to post initial HBQ buffers to firmware. The
925 * function returns the number of HBQ entries successfully allocated.
926 **/
689static int 927static int
690lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno) 928lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
691{ 929{
@@ -693,6 +931,16 @@ lpfc_sli_hbqbuf_init_hbqs(struct lpfc_hba *phba, uint32_t qno)
693 lpfc_hbq_defs[qno]->init_count)); 931 lpfc_hbq_defs[qno]->init_count));
694} 932}
695 933
934/**
935 * lpfc_sli_hbqbuf_find: Find the hbq buffer associated with a tag.
936 * @phba: Pointer to HBA context object.
937 * @tag: Tag of the hbq buffer.
938 *
939 * This function is called with hbalock held. This function searches
940 * for the hbq buffer associated with the given tag in the hbq buffer
941 * list. If it finds the hbq buffer, it returns the hbq_buffer other wise
942 * it returns NULL.
943 **/
696static struct hbq_dmabuf * 944static struct hbq_dmabuf *
697lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag) 945lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
698{ 946{
@@ -716,6 +964,15 @@ lpfc_sli_hbqbuf_find(struct lpfc_hba *phba, uint32_t tag)
716 return NULL; 964 return NULL;
717} 965}
718 966
967/**
968 * lpfc_sli_free_hbq: Give back the hbq buffer to firmware.
969 * @phba: Pointer to HBA context object.
970 * @hbq_buffer: Pointer to HBQ buffer.
971 *
972 * This function is called with hbalock. This function gives back
973 * the hbq buffer to firmware. If the HBQ does not have space to
974 * post the buffer, it will free the buffer.
975 **/
719void 976void
720lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer) 977lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
721{ 978{
@@ -729,6 +986,15 @@ lpfc_sli_free_hbq(struct lpfc_hba *phba, struct hbq_dmabuf *hbq_buffer)
729 } 986 }
730} 987}
731 988
989/**
990 * lpfc_sli_chk_mbx_command: Check if the mailbox is a legitimate mailbox.
991 * @mbxCommand: mailbox command code.
992 *
993 * This function is called by the mailbox event handler function to verify
994 * that the completed mailbox command is a legitimate mailbox command. If the
995 * completed mailbox is not known to the function, it will return MBX_SHUTDOWN
996 * and the mailbox event handler will take the HBA offline.
997 **/
732static int 998static int
733lpfc_sli_chk_mbx_command(uint8_t mbxCommand) 999lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
734{ 1000{
@@ -785,6 +1051,8 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
785 case MBX_REG_VPI: 1051 case MBX_REG_VPI:
786 case MBX_UNREG_VPI: 1052 case MBX_UNREG_VPI:
787 case MBX_HEARTBEAT: 1053 case MBX_HEARTBEAT:
1054 case MBX_PORT_CAPABILITIES:
1055 case MBX_PORT_IOV_CONTROL:
788 ret = mbxCommand; 1056 ret = mbxCommand;
789 break; 1057 break;
790 default: 1058 default:
@@ -793,6 +1061,19 @@ lpfc_sli_chk_mbx_command(uint8_t mbxCommand)
793 } 1061 }
794 return ret; 1062 return ret;
795} 1063}
1064
1065/**
1066 * lpfc_sli_wake_mbox_wait: Completion handler for mbox issued from
1067 * lpfc_sli_issue_mbox_wait.
1068 * @phba: Pointer to HBA context object.
1069 * @pmboxq: Pointer to mailbox command.
1070 *
1071 * This is completion handler function for mailbox commands issued from
1072 * lpfc_sli_issue_mbox_wait function. This function is called by the
1073 * mailbox event handler function with no lock held. This function
1074 * will wake up thread waiting on the wait queue pointed by context1
1075 * of the mailbox.
1076 **/
796static void 1077static void
797lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq) 1078lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
798{ 1079{
@@ -812,6 +1093,17 @@ lpfc_sli_wake_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq)
812 return; 1093 return;
813} 1094}
814 1095
1096
1097/**
1098 * lpfc_sli_def_mbox_cmpl: Default mailbox completion handler.
1099 * @phba: Pointer to HBA context object.
1100 * @pmb: Pointer to mailbox object.
1101 *
1102 * This function is the default mailbox completion handler. It
1103 * frees the memory resources associated with the completed mailbox
1104 * command. If the completed command is a REG_LOGIN mailbox command,
1105 * this function will issue a UREG_LOGIN to re-claim the RPI.
1106 **/
815void 1107void
816lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1108lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
817{ 1109{
@@ -846,6 +1138,19 @@ lpfc_sli_def_mbox_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
846 return; 1138 return;
847} 1139}
848 1140
1141/**
1142 * lpfc_sli_handle_mb_event: Handle mailbox completions from firmware.
1143 * @phba: Pointer to HBA context object.
1144 *
1145 * This function is called with no lock held. This function processes all
1146 * the completed mailbox commands and gives it to upper layers. The interrupt
1147 * service routine processes mailbox completion interrupt and adds completed
1148 * mailbox commands to the mboxq_cmpl queue and signals the worker thread.
1149 * Worker thread call lpfc_sli_handle_mb_event, which will return the
1150 * completed mailbox commands in mboxq_cmpl queue to the upper layers. This
1151 * function returns the mailbox commands to the upper layer by calling the
1152 * completion handler function of each mailbox.
1153 **/
849int 1154int
850lpfc_sli_handle_mb_event(struct lpfc_hba *phba) 1155lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
851{ 1156{
@@ -953,6 +1258,18 @@ lpfc_sli_handle_mb_event(struct lpfc_hba *phba)
953 return 0; 1258 return 0;
954} 1259}
955 1260
1261/**
1262 * lpfc_sli_replace_hbqbuff: Replace the HBQ buffer with a new buffer.
1263 * @phba: Pointer to HBA context object.
1264 * @tag: Tag for the HBQ buffer.
1265 *
1266 * This function is called from unsolicited event handler code path to get the
1267 * HBQ buffer associated with an unsolicited iocb. This function is called with
1268 * no lock held. It returns the buffer associated with the given tag and posts
1269 * another buffer to the firmware. Note that the new buffer must be allocated
1270 * before taking the hbalock and that the hba lock must be held until it is
1271 * finished with the hbq entry swap.
1272 **/
956static struct lpfc_dmabuf * 1273static struct lpfc_dmabuf *
957lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag) 1274lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
958{ 1275{
@@ -962,22 +1279,28 @@ lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
962 dma_addr_t phys; /* mapped address */ 1279 dma_addr_t phys; /* mapped address */
963 unsigned long flags; 1280 unsigned long flags;
964 1281
1282 hbqno = tag >> 16;
1283 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
965 /* Check whether HBQ is still in use */ 1284 /* Check whether HBQ is still in use */
966 spin_lock_irqsave(&phba->hbalock, flags); 1285 spin_lock_irqsave(&phba->hbalock, flags);
967 if (!phba->hbq_in_use) { 1286 if (!phba->hbq_in_use) {
1287 if (new_hbq_entry)
1288 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1289 new_hbq_entry);
968 spin_unlock_irqrestore(&phba->hbalock, flags); 1290 spin_unlock_irqrestore(&phba->hbalock, flags);
969 return NULL; 1291 return NULL;
970 } 1292 }
971 1293
972 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag); 1294 hbq_entry = lpfc_sli_hbqbuf_find(phba, tag);
973 if (hbq_entry == NULL) { 1295 if (hbq_entry == NULL) {
1296 if (new_hbq_entry)
1297 (phba->hbqs[hbqno].hbq_free_buffer)(phba,
1298 new_hbq_entry);
974 spin_unlock_irqrestore(&phba->hbalock, flags); 1299 spin_unlock_irqrestore(&phba->hbalock, flags);
975 return NULL; 1300 return NULL;
976 } 1301 }
977 list_del(&hbq_entry->dbuf.list); 1302 list_del(&hbq_entry->dbuf.list);
978 1303
979 hbqno = tag >> 16;
980 new_hbq_entry = (phba->hbqs[hbqno].hbq_alloc_buffer)(phba);
981 if (new_hbq_entry == NULL) { 1304 if (new_hbq_entry == NULL) {
982 list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list); 1305 list_add_tail(&hbq_entry->dbuf.list, &phba->hbqbuf_in_list);
983 spin_unlock_irqrestore(&phba->hbalock, flags); 1306 spin_unlock_irqrestore(&phba->hbalock, flags);
@@ -997,6 +1320,18 @@ lpfc_sli_replace_hbqbuff(struct lpfc_hba *phba, uint32_t tag)
997 return &new_hbq_entry->dbuf; 1320 return &new_hbq_entry->dbuf;
998} 1321}
999 1322
1323/**
1324 * lpfc_sli_get_buff: Get the buffer associated with the buffer tag.
1325 * @phba: Pointer to HBA context object.
1326 * @pring: Pointer to driver SLI ring object.
1327 * @tag: buffer tag.
1328 *
1329 * This function is called with no lock held. When QUE_BUFTAG_BIT bit
1330 * is set in the tag the buffer is posted for a particular exchange,
1331 * the function will return the buffer without replacing the buffer.
1332 * If the buffer is for unsolicited ELS or CT traffic, this function
1333 * returns the buffer and also posts another buffer to the firmware.
1334 **/
1000static struct lpfc_dmabuf * 1335static struct lpfc_dmabuf *
1001lpfc_sli_get_buff(struct lpfc_hba *phba, 1336lpfc_sli_get_buff(struct lpfc_hba *phba,
1002 struct lpfc_sli_ring *pring, 1337 struct lpfc_sli_ring *pring,
@@ -1008,6 +1343,21 @@ lpfc_sli_get_buff(struct lpfc_hba *phba,
1008 return lpfc_sli_replace_hbqbuff(phba, tag); 1343 return lpfc_sli_replace_hbqbuff(phba, tag);
1009} 1344}
1010 1345
1346
1347/**
1348 * lpfc_sli_process_unsol_iocb: Unsolicited iocb handler.
1349 * @phba: Pointer to HBA context object.
1350 * @pring: Pointer to driver SLI ring object.
1351 * @saveq: Pointer to the unsolicited iocb.
1352 *
1353 * This function is called with no lock held by the ring event handler
1354 * when there is an unsolicited iocb posted to the response ring by the
1355 * firmware. This function gets the buffer associated with the iocbs
1356 * and calls the event handler for the ring. This function handles both
1357 * qring buffers and hbq buffers.
1358 * When the function returns 1 the caller can free the iocb object otherwise
1359 * upper layer functions will free the iocb objects.
1360 **/
1011static int 1361static int
1012lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1362lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1013 struct lpfc_iocbq *saveq) 1363 struct lpfc_iocbq *saveq)
@@ -1192,6 +1542,18 @@ lpfc_sli_process_unsol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1192 return 1; 1542 return 1;
1193} 1543}
1194 1544
1545/**
1546 * lpfc_sli_iocbq_lookup: Find command iocb for the given response iocb.
1547 * @phba: Pointer to HBA context object.
1548 * @pring: Pointer to driver SLI ring object.
1549 * @prspiocb: Pointer to response iocb object.
1550 *
1551 * This function looks up the iocb_lookup table to get the command iocb
1552 * corresponding to the given response iocb using the iotag of the
1553 * response iocb. This function is called with the hbalock held.
1554 * This function returns the command iocb object if it finds the command
1555 * iocb else returns NULL.
1556 **/
1195static struct lpfc_iocbq * 1557static struct lpfc_iocbq *
1196lpfc_sli_iocbq_lookup(struct lpfc_hba *phba, 1558lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1197 struct lpfc_sli_ring *pring, 1559 struct lpfc_sli_ring *pring,
@@ -1217,6 +1579,23 @@ lpfc_sli_iocbq_lookup(struct lpfc_hba *phba,
1217 return NULL; 1579 return NULL;
1218} 1580}
1219 1581
1582/**
1583 * lpfc_sli_process_sol_iocb: process solicited iocb completion.
1584 * @phba: Pointer to HBA context object.
1585 * @pring: Pointer to driver SLI ring object.
1586 * @saveq: Pointer to the response iocb to be processed.
1587 *
1588 * This function is called by the ring event handler for non-fcp
1589 * rings when there is a new response iocb in the response ring.
1590 * The caller is not required to hold any locks. This function
1591 * gets the command iocb associated with the response iocb and
1592 * calls the completion handler for the command iocb. If there
1593 * is no completion handler, the function will free the resources
1594 * associated with command iocb. If the response iocb is for
1595 * an already aborted command iocb, the status of the completion
1596 * is changed to IOSTAT_LOCAL_REJECT/IOERR_SLI_ABORTED.
1597 * This function always returns 1.
1598 **/
1220static int 1599static int
1221lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 1600lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1222 struct lpfc_iocbq *saveq) 1601 struct lpfc_iocbq *saveq)
@@ -1233,6 +1612,17 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1233 if (cmdiocbp) { 1612 if (cmdiocbp) {
1234 if (cmdiocbp->iocb_cmpl) { 1613 if (cmdiocbp->iocb_cmpl) {
1235 /* 1614 /*
1615 * If an ELS command failed send an event to mgmt
1616 * application.
1617 */
1618 if (saveq->iocb.ulpStatus &&
1619 (pring->ringno == LPFC_ELS_RING) &&
1620 (cmdiocbp->iocb.ulpCommand ==
1621 CMD_ELS_REQUEST64_CR))
1622 lpfc_send_els_failure_event(phba,
1623 cmdiocbp, saveq);
1624
1625 /*
1236 * Post all ELS completions to the worker thread. 1626 * Post all ELS completions to the worker thread.
1237 * All other are passed to the completion callback. 1627 * All other are passed to the completion callback.
1238 */ 1628 */
@@ -1282,12 +1672,20 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
1282 return rc; 1672 return rc;
1283} 1673}
1284 1674
1675/**
1676 * lpfc_sli_rsp_pointers_error: Response ring pointer error handler.
1677 * @phba: Pointer to HBA context object.
1678 * @pring: Pointer to driver SLI ring object.
1679 *
1680 * This function is called from the iocb ring event handlers when
1681 * put pointer is ahead of the get pointer for a ring. This function signal
1682 * an error attention condition to the worker thread and the worker
1683 * thread will transition the HBA to offline state.
1684 **/
1285static void 1685static void
1286lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 1686lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1287{ 1687{
1288 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? 1688 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1289 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1290 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1291 /* 1689 /*
1292 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then 1690 * Ring <ringno> handler: portRspPut <portRspPut> is bigger then
1293 * rsp ring <portRspMax> 1691 * rsp ring <portRspMax>
@@ -1312,6 +1710,51 @@ lpfc_sli_rsp_pointers_error(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1312 return; 1710 return;
1313} 1711}
1314 1712
1713/**
1714 * lpfc_poll_eratt: Error attention polling timer timeout handler.
1715 * @ptr: Pointer to address of HBA context object.
1716 *
1717 * This function is invoked by the Error Attention polling timer when the
1718 * timer times out. It will check the SLI Error Attention register for
1719 * possible attention events. If so, it will post an Error Attention event
1720 * and wake up worker thread to process it. Otherwise, it will set up the
1721 * Error Attention polling timer for the next poll.
1722 **/
1723void lpfc_poll_eratt(unsigned long ptr)
1724{
1725 struct lpfc_hba *phba;
1726 uint32_t eratt = 0;
1727
1728 phba = (struct lpfc_hba *)ptr;
1729
1730 /* Check chip HA register for error event */
1731 eratt = lpfc_sli_check_eratt(phba);
1732
1733 if (eratt)
1734 /* Tell the worker thread there is work to do */
1735 lpfc_worker_wake_up(phba);
1736 else
1737 /* Restart the timer for next eratt poll */
1738 mod_timer(&phba->eratt_poll, jiffies +
1739 HZ * LPFC_ERATT_POLL_INTERVAL);
1740 return;
1741}
1742
1743/**
1744 * lpfc_sli_poll_fcp_ring: Handle FCP ring completion in polling mode.
1745 * @phba: Pointer to HBA context object.
1746 *
1747 * This function is called from lpfc_queuecommand, lpfc_poll_timeout,
1748 * lpfc_abort_handler and lpfc_slave_configure when FCP_RING_POLLING
1749 * is enabled.
1750 *
1751 * The caller does not hold any lock.
1752 * The function processes each response iocb in the response ring until it
1753 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
1754 * LE bit set. The function will call the completion handler of the command iocb
1755 * if the response iocb indicates a completion for a command iocb or it is
1756 * an abort completion.
1757 **/
1315void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba) 1758void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1316{ 1759{
1317 struct lpfc_sli *psli = &phba->sli; 1760 struct lpfc_sli *psli = &phba->sli;
@@ -1320,7 +1763,7 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1320 IOCB_t *entry = NULL; 1763 IOCB_t *entry = NULL;
1321 struct lpfc_iocbq *cmdiocbq = NULL; 1764 struct lpfc_iocbq *cmdiocbq = NULL;
1322 struct lpfc_iocbq rspiocbq; 1765 struct lpfc_iocbq rspiocbq;
1323 struct lpfc_pgp *pgp; 1766 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1324 uint32_t status; 1767 uint32_t status;
1325 uint32_t portRspPut, portRspMax; 1768 uint32_t portRspPut, portRspMax;
1326 int type; 1769 int type;
@@ -1330,11 +1773,6 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1330 1773
1331 pring->stats.iocb_event++; 1774 pring->stats.iocb_event++;
1332 1775
1333 pgp = (phba->sli_rev == 3) ?
1334 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1335 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1336
1337
1338 /* 1776 /*
1339 * The next available response entry should never exceed the maximum 1777 * The next available response entry should never exceed the maximum
1340 * entries. If it does, treat it as an adapter hardware error. 1778 * entries. If it does, treat it as an adapter hardware error.
@@ -1372,8 +1810,8 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1372 irsp->un.ulpWord[3], 1810 irsp->un.ulpWord[3],
1373 irsp->un.ulpWord[4], 1811 irsp->un.ulpWord[4],
1374 irsp->un.ulpWord[5], 1812 irsp->un.ulpWord[5],
1375 *(((uint32_t *) irsp) + 6), 1813 *(uint32_t *)&irsp->un1,
1376 *(((uint32_t *) irsp) + 7)); 1814 *((uint32_t *)&irsp->un1 + 1));
1377 } 1815 }
1378 1816
1379 switch (type) { 1817 switch (type) {
@@ -1465,17 +1903,28 @@ void lpfc_sli_poll_fcp_ring(struct lpfc_hba *phba)
1465 return; 1903 return;
1466} 1904}
1467 1905
1468/* 1906/**
1907 * lpfc_sli_handle_fast_ring_event: Handle ring events on FCP ring.
1908 * @phba: Pointer to HBA context object.
1909 * @pring: Pointer to driver SLI ring object.
1910 * @mask: Host attention register mask for this ring.
1911 *
1912 * This function is called from the interrupt context when there is a ring
1913 * event for the fcp ring. The caller does not hold any lock.
1914 * The function processes each response iocb in the response ring until it
1915 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
1916 * LE bit set. The function will call the completion handler of the command iocb
1917 * if the response iocb indicates a completion for a command iocb or it is
1918 * an abort completion. The function will call lpfc_sli_process_unsol_iocb
1919 * function if this is an unsolicited iocb.
1469 * This routine presumes LPFC_FCP_RING handling and doesn't bother 1920 * This routine presumes LPFC_FCP_RING handling and doesn't bother
1470 * to check it explicitly. 1921 * to check it explicitly. This function always returns 1.
1471 */ 1922 **/
1472static int 1923static int
1473lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba, 1924lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1474 struct lpfc_sli_ring *pring, uint32_t mask) 1925 struct lpfc_sli_ring *pring, uint32_t mask)
1475{ 1926{
1476 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? 1927 struct lpfc_pgp *pgp = &phba->port_gp[pring->ringno];
1477 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1478 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1479 IOCB_t *irsp = NULL; 1928 IOCB_t *irsp = NULL;
1480 IOCB_t *entry = NULL; 1929 IOCB_t *entry = NULL;
1481 struct lpfc_iocbq *cmdiocbq = NULL; 1930 struct lpfc_iocbq *cmdiocbq = NULL;
@@ -1548,8 +1997,8 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1548 irsp->un.ulpWord[3], 1997 irsp->un.ulpWord[3],
1549 irsp->un.ulpWord[4], 1998 irsp->un.ulpWord[4],
1550 irsp->un.ulpWord[5], 1999 irsp->un.ulpWord[5],
1551 *(((uint32_t *) irsp) + 6), 2000 *(uint32_t *)&irsp->un1,
1552 *(((uint32_t *) irsp) + 7)); 2001 *((uint32_t *)&irsp->un1 + 1));
1553 } 2002 }
1554 2003
1555 switch (type) { 2004 switch (type) {
@@ -1646,13 +2095,28 @@ lpfc_sli_handle_fast_ring_event(struct lpfc_hba *phba,
1646 return rc; 2095 return rc;
1647} 2096}
1648 2097
2098/**
2099 * lpfc_sli_handle_slow_ring_event: Handle ring events for non-FCP rings.
2100 * @phba: Pointer to HBA context object.
2101 * @pring: Pointer to driver SLI ring object.
2102 * @mask: Host attention register mask for this ring.
2103 *
2104 * This function is called from the worker thread when there is a ring
2105 * event for non-fcp rings. The caller does not hold any lock .
2106 * The function processes each response iocb in the response ring until it
2107 * finds an iocb with LE bit set and chains all the iocbs upto the iocb with
2108 * LE bit set. The function will call lpfc_sli_process_sol_iocb function if the
2109 * response iocb indicates a completion of a command iocb. The function
2110 * will call lpfc_sli_process_unsol_iocb function if this is an unsolicited
2111 * iocb. The function frees the resources or calls the completion handler if
2112 * this iocb is an abort completion. The function returns 0 when the allocated
2113 * iocbs are not freed, otherwise returns 1.
2114 **/
1649int 2115int
1650lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba, 2116lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1651 struct lpfc_sli_ring *pring, uint32_t mask) 2117 struct lpfc_sli_ring *pring, uint32_t mask)
1652{ 2118{
1653 struct lpfc_pgp *pgp = (phba->sli_rev == 3) ? 2119 struct lpfc_pgp *pgp;
1654 &phba->slim2p->mbx.us.s3_pgp.port[pring->ringno] :
1655 &phba->slim2p->mbx.us.s2.port[pring->ringno];
1656 IOCB_t *entry; 2120 IOCB_t *entry;
1657 IOCB_t *irsp = NULL; 2121 IOCB_t *irsp = NULL;
1658 struct lpfc_iocbq *rspiocbp = NULL; 2122 struct lpfc_iocbq *rspiocbp = NULL;
@@ -1666,6 +2130,7 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1666 int rc = 1; 2130 int rc = 1;
1667 unsigned long iflag; 2131 unsigned long iflag;
1668 2132
2133 pgp = &phba->port_gp[pring->ringno];
1669 spin_lock_irqsave(&phba->hbalock, iflag); 2134 spin_lock_irqsave(&phba->hbalock, iflag);
1670 pring->stats.iocb_event++; 2135 pring->stats.iocb_event++;
1671 2136
@@ -1904,6 +2369,16 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba *phba,
1904 return rc; 2369 return rc;
1905} 2370}
1906 2371
2372/**
2373 * lpfc_sli_abort_iocb_ring: Abort all iocbs in the ring.
2374 * @phba: Pointer to HBA context object.
2375 * @pring: Pointer to driver SLI ring object.
2376 *
2377 * This function aborts all iocbs in the given ring and frees all the iocb
2378 * objects in txq. This function issues an abort iocb for all the iocb commands
2379 * in txcmplq. The iocbs in the txcmplq is not guaranteed to complete before
2380 * the return of this function. The caller is not required to hold any locks.
2381 **/
1907void 2382void
1908lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 2383lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1909{ 2384{
@@ -1943,6 +2418,83 @@ lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1943 } 2418 }
1944} 2419}
1945 2420
2421/**
2422 * lpfc_sli_flush_fcp_rings: flush all iocbs in the fcp ring.
2423 * @phba: Pointer to HBA context object.
2424 *
2425 * This function flushes all iocbs in the fcp ring and frees all the iocb
2426 * objects in txq and txcmplq. This function will not issue abort iocbs
2427 * for all the iocb commands in txcmplq, they will just be returned with
2428 * IOERR_SLI_DOWN. This function is invoked with EEH when device's PCI
2429 * slot has been permanently disabled.
2430 **/
2431void
2432lpfc_sli_flush_fcp_rings(struct lpfc_hba *phba)
2433{
2434 LIST_HEAD(txq);
2435 LIST_HEAD(txcmplq);
2436 struct lpfc_iocbq *iocb;
2437 IOCB_t *cmd = NULL;
2438 struct lpfc_sli *psli = &phba->sli;
2439 struct lpfc_sli_ring *pring;
2440
2441 /* Currently, only one fcp ring */
2442 pring = &psli->ring[psli->fcp_ring];
2443
2444 spin_lock_irq(&phba->hbalock);
2445 /* Retrieve everything on txq */
2446 list_splice_init(&pring->txq, &txq);
2447 pring->txq_cnt = 0;
2448
2449 /* Retrieve everything on the txcmplq */
2450 list_splice_init(&pring->txcmplq, &txcmplq);
2451 pring->txcmplq_cnt = 0;
2452 spin_unlock_irq(&phba->hbalock);
2453
2454 /* Flush the txq */
2455 while (!list_empty(&txq)) {
2456 iocb = list_get_first(&txq, struct lpfc_iocbq, list);
2457 cmd = &iocb->iocb;
2458 list_del_init(&iocb->list);
2459
2460 if (!iocb->iocb_cmpl)
2461 lpfc_sli_release_iocbq(phba, iocb);
2462 else {
2463 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2464 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2465 (iocb->iocb_cmpl) (phba, iocb, iocb);
2466 }
2467 }
2468
2469 /* Flush the txcmpq */
2470 while (!list_empty(&txcmplq)) {
2471 iocb = list_get_first(&txcmplq, struct lpfc_iocbq, list);
2472 cmd = &iocb->iocb;
2473 list_del_init(&iocb->list);
2474
2475 if (!iocb->iocb_cmpl)
2476 lpfc_sli_release_iocbq(phba, iocb);
2477 else {
2478 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2479 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2480 (iocb->iocb_cmpl) (phba, iocb, iocb);
2481 }
2482 }
2483}
2484
2485/**
2486 * lpfc_sli_brdready: Check for host status bits.
2487 * @phba: Pointer to HBA context object.
2488 * @mask: Bit mask to be checked.
2489 *
2490 * This function reads the host status register and compares
2491 * with the provided bit mask to check if HBA completed
2492 * the restart. This function will wait in a loop for the
2493 * HBA to complete restart. If the HBA does not restart within
2494 * 15 iterations, the function will reset the HBA again. The
2495 * function returns 1 when HBA fail to restart otherwise returns
2496 * zero.
2497 **/
1946int 2498int
1947lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask) 2499lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1948{ 2500{
@@ -1990,6 +2542,13 @@ lpfc_sli_brdready(struct lpfc_hba *phba, uint32_t mask)
1990 2542
1991#define BARRIER_TEST_PATTERN (0xdeadbeef) 2543#define BARRIER_TEST_PATTERN (0xdeadbeef)
1992 2544
2545/**
2546 * lpfc_reset_barrier: Make HBA ready for HBA reset.
2547 * @phba: Pointer to HBA context object.
2548 *
2549 * This function is called before resetting an HBA. This
2550 * function requests HBA to quiesce DMAs before a reset.
2551 **/
1993void lpfc_reset_barrier(struct lpfc_hba *phba) 2552void lpfc_reset_barrier(struct lpfc_hba *phba)
1994{ 2553{
1995 uint32_t __iomem *resp_buf; 2554 uint32_t __iomem *resp_buf;
@@ -2063,6 +2622,17 @@ restore_hc:
2063 readl(phba->HCregaddr); /* flush */ 2622 readl(phba->HCregaddr); /* flush */
2064} 2623}
2065 2624
2625/**
2626 * lpfc_sli_brdkill: Issue a kill_board mailbox command.
2627 * @phba: Pointer to HBA context object.
2628 *
2629 * This function issues a kill_board mailbox command and waits for
2630 * the error attention interrupt. This function is called for stopping
2631 * the firmware processing. The caller is not required to hold any
2632 * locks. This function calls lpfc_hba_down_post function to free
2633 * any pending commands after the kill. The function will return 1 when it
2634 * fails to kill the board else will return 0.
2635 **/
2066int 2636int
2067lpfc_sli_brdkill(struct lpfc_hba *phba) 2637lpfc_sli_brdkill(struct lpfc_hba *phba)
2068{ 2638{
@@ -2139,6 +2709,17 @@ lpfc_sli_brdkill(struct lpfc_hba *phba)
2139 return ha_copy & HA_ERATT ? 0 : 1; 2709 return ha_copy & HA_ERATT ? 0 : 1;
2140} 2710}
2141 2711
2712/**
2713 * lpfc_sli_brdreset: Reset the HBA.
2714 * @phba: Pointer to HBA context object.
2715 *
2716 * This function resets the HBA by writing HC_INITFF to the control
2717 * register. After the HBA resets, this function resets all the iocb ring
2718 * indices. This function disables PCI layer parity checking during
2719 * the reset.
2720 * This function returns 0 always.
2721 * The caller is not required to hold any locks.
2722 **/
2142int 2723int
2143lpfc_sli_brdreset(struct lpfc_hba *phba) 2724lpfc_sli_brdreset(struct lpfc_hba *phba)
2144{ 2725{
@@ -2191,6 +2772,19 @@ lpfc_sli_brdreset(struct lpfc_hba *phba)
2191 return 0; 2772 return 0;
2192} 2773}
2193 2774
2775/**
2776 * lpfc_sli_brdrestart: Restart the HBA.
2777 * @phba: Pointer to HBA context object.
2778 *
2779 * This function is called in the SLI initialization code path to
2780 * restart the HBA. The caller is not required to hold any lock.
2781 * This function writes MBX_RESTART mailbox command to the SLIM and
2782 * resets the HBA. At the end of the function, it calls lpfc_hba_down_post
2783 * function to free any pending commands. The function enables
2784 * POST only during the first initialization. The function returns zero.
2785 * The function does not guarantee completion of MBX_RESTART mailbox
2786 * command before the return of this function.
2787 **/
2194int 2788int
2195lpfc_sli_brdrestart(struct lpfc_hba *phba) 2789lpfc_sli_brdrestart(struct lpfc_hba *phba)
2196{ 2790{
@@ -2251,6 +2845,16 @@ lpfc_sli_brdrestart(struct lpfc_hba *phba)
2251 return 0; 2845 return 0;
2252} 2846}
2253 2847
2848/**
2849 * lpfc_sli_chipset_init: Wait for the restart of the HBA after a restart.
2850 * @phba: Pointer to HBA context object.
2851 *
2852 * This function is called after a HBA restart to wait for successful
2853 * restart of the HBA. Successful restart of the HBA is indicated by
2854 * HS_FFRDY and HS_MBRDY bits. If the HBA fails to restart even after 15
2855 * iteration, the function will restart the HBA again. The function returns
2856 * zero if HBA successfully restarted else returns negative error code.
2857 **/
2254static int 2858static int
2255lpfc_sli_chipset_init(struct lpfc_hba *phba) 2859lpfc_sli_chipset_init(struct lpfc_hba *phba)
2256{ 2860{
@@ -2336,12 +2940,25 @@ lpfc_sli_chipset_init(struct lpfc_hba *phba)
2336 return 0; 2940 return 0;
2337} 2941}
2338 2942
2943/**
2944 * lpfc_sli_hbq_count: Get the number of HBQs to be configured.
2945 *
2946 * This function calculates and returns the number of HBQs required to be
2947 * configured.
2948 **/
2339int 2949int
2340lpfc_sli_hbq_count(void) 2950lpfc_sli_hbq_count(void)
2341{ 2951{
2342 return ARRAY_SIZE(lpfc_hbq_defs); 2952 return ARRAY_SIZE(lpfc_hbq_defs);
2343} 2953}
2344 2954
2955/**
2956 * lpfc_sli_hbq_entry_count: Calculate total number of hbq entries.
2957 *
2958 * This function adds the number of hbq entries in every HBQ to get
2959 * the total number of hbq entries required for the HBA and returns
2960 * the total count.
2961 **/
2345static int 2962static int
2346lpfc_sli_hbq_entry_count(void) 2963lpfc_sli_hbq_entry_count(void)
2347{ 2964{
@@ -2354,12 +2971,27 @@ lpfc_sli_hbq_entry_count(void)
2354 return count; 2971 return count;
2355} 2972}
2356 2973
2974/**
2975 * lpfc_sli_hbq_size: Calculate memory required for all hbq entries.
2976 *
2977 * This function calculates amount of memory required for all hbq entries
2978 * to be configured and returns the total memory required.
2979 **/
2357int 2980int
2358lpfc_sli_hbq_size(void) 2981lpfc_sli_hbq_size(void)
2359{ 2982{
2360 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry); 2983 return lpfc_sli_hbq_entry_count() * sizeof(struct lpfc_hbq_entry);
2361} 2984}
2362 2985
2986/**
2987 * lpfc_sli_hbq_setup: configure and initialize HBQs.
2988 * @phba: Pointer to HBA context object.
2989 *
2990 * This function is called during the SLI initialization to configure
2991 * all the HBQs and post buffers to the HBQ. The caller is not
2992 * required to hold any locks. This function will return zero if successful
2993 * else it will return negative error code.
2994 **/
2363static int 2995static int
2364lpfc_sli_hbq_setup(struct lpfc_hba *phba) 2996lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2365{ 2997{
@@ -2415,15 +3047,26 @@ lpfc_sli_hbq_setup(struct lpfc_hba *phba)
2415 mempool_free(pmb, phba->mbox_mem_pool); 3047 mempool_free(pmb, phba->mbox_mem_pool);
2416 3048
2417 /* Initially populate or replenish the HBQs */ 3049 /* Initially populate or replenish the HBQs */
2418 for (hbqno = 0; hbqno < hbq_count; ++hbqno) { 3050 for (hbqno = 0; hbqno < hbq_count; ++hbqno)
2419 if (lpfc_sli_hbqbuf_init_hbqs(phba, hbqno)) 3051 lpfc_sli_hbqbuf_init_hbqs(phba, hbqno);
2420 return -ENOMEM;
2421 }
2422 return 0; 3052 return 0;
2423} 3053}
2424 3054
2425static int 3055/**
2426lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode) 3056 * lpfc_sli_config_port: Issue config port mailbox command.
3057 * @phba: Pointer to HBA context object.
3058 * @sli_mode: sli mode - 2/3
3059 *
3060 * This function is called by the sli intialization code path
3061 * to issue config_port mailbox command. This function restarts the
3062 * HBA firmware and issues a config_port mailbox command to configure
3063 * the SLI interface in the sli mode specified by sli_mode
3064 * variable. The caller is not required to hold any locks.
3065 * The function returns 0 if successful, else returns negative error
3066 * code.
3067 **/
3068int
3069lpfc_sli_config_port(struct lpfc_hba *phba, int sli_mode)
2427{ 3070{
2428 LPFC_MBOXQ_t *pmb; 3071 LPFC_MBOXQ_t *pmb;
2429 uint32_t resetcount = 0, rc = 0, done = 0; 3072 uint32_t resetcount = 0, rc = 0, done = 0;
@@ -2460,13 +3103,15 @@ lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2460 if (rc == -ERESTART) { 3103 if (rc == -ERESTART) {
2461 phba->link_state = LPFC_LINK_UNKNOWN; 3104 phba->link_state = LPFC_LINK_UNKNOWN;
2462 continue; 3105 continue;
2463 } else if (rc) { 3106 } else if (rc)
2464 break; 3107 break;
2465 }
2466
2467 phba->link_state = LPFC_INIT_MBX_CMDS; 3108 phba->link_state = LPFC_INIT_MBX_CMDS;
2468 lpfc_config_port(phba, pmb); 3109 lpfc_config_port(phba, pmb);
2469 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 3110 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
3111 phba->sli3_options &= ~(LPFC_SLI3_NPIV_ENABLED |
3112 LPFC_SLI3_HBQ_ENABLED |
3113 LPFC_SLI3_CRP_ENABLED |
3114 LPFC_SLI3_INB_ENABLED);
2470 if (rc != MBX_SUCCESS) { 3115 if (rc != MBX_SUCCESS) {
2471 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 3116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2472 "0442 Adapter failed to init, mbxCmd x%x " 3117 "0442 Adapter failed to init, mbxCmd x%x "
@@ -2476,30 +3121,64 @@ lpfc_do_config_port(struct lpfc_hba *phba, int sli_mode)
2476 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE; 3121 phba->sli.sli_flag &= ~LPFC_SLI2_ACTIVE;
2477 spin_unlock_irq(&phba->hbalock); 3122 spin_unlock_irq(&phba->hbalock);
2478 rc = -ENXIO; 3123 rc = -ENXIO;
2479 } else { 3124 } else
2480 done = 1; 3125 done = 1;
2481 phba->max_vpi = (phba->max_vpi &&
2482 pmb->mb.un.varCfgPort.gmv) != 0
2483 ? pmb->mb.un.varCfgPort.max_vpi
2484 : 0;
2485 }
2486 } 3126 }
2487
2488 if (!done) { 3127 if (!done) {
2489 rc = -EINVAL; 3128 rc = -EINVAL;
2490 goto do_prep_failed; 3129 goto do_prep_failed;
2491 } 3130 }
2492 3131 if (pmb->mb.un.varCfgPort.sli_mode == 3) {
2493 if ((pmb->mb.un.varCfgPort.sli_mode == 3) && 3132 if (!pmb->mb.un.varCfgPort.cMA) {
2494 (!pmb->mb.un.varCfgPort.cMA)) { 3133 rc = -ENXIO;
2495 rc = -ENXIO; 3134 goto do_prep_failed;
3135 }
3136 if (phba->max_vpi && pmb->mb.un.varCfgPort.gmv) {
3137 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
3138 phba->max_vpi = pmb->mb.un.varCfgPort.max_vpi;
3139 } else
3140 phba->max_vpi = 0;
3141 if (pmb->mb.un.varCfgPort.gerbm)
3142 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
3143 if (pmb->mb.un.varCfgPort.gcrp)
3144 phba->sli3_options |= LPFC_SLI3_CRP_ENABLED;
3145 if (pmb->mb.un.varCfgPort.ginb) {
3146 phba->sli3_options |= LPFC_SLI3_INB_ENABLED;
3147 phba->port_gp = phba->mbox->us.s3_inb_pgp.port;
3148 phba->inb_ha_copy = &phba->mbox->us.s3_inb_pgp.ha_copy;
3149 phba->inb_counter = &phba->mbox->us.s3_inb_pgp.counter;
3150 phba->inb_last_counter =
3151 phba->mbox->us.s3_inb_pgp.counter;
3152 } else {
3153 phba->port_gp = phba->mbox->us.s3_pgp.port;
3154 phba->inb_ha_copy = NULL;
3155 phba->inb_counter = NULL;
3156 }
3157 } else {
3158 phba->port_gp = phba->mbox->us.s2.port;
3159 phba->inb_ha_copy = NULL;
3160 phba->inb_counter = NULL;
3161 phba->max_vpi = 0;
2496 } 3162 }
2497
2498do_prep_failed: 3163do_prep_failed:
2499 mempool_free(pmb, phba->mbox_mem_pool); 3164 mempool_free(pmb, phba->mbox_mem_pool);
2500 return rc; 3165 return rc;
2501} 3166}
2502 3167
3168
3169/**
3170 * lpfc_sli_hba_setup: SLI intialization function.
3171 * @phba: Pointer to HBA context object.
3172 *
3173 * This function is the main SLI intialization function. This function
3174 * is called by the HBA intialization code, HBA reset code and HBA
3175 * error attention handler code. Caller is not required to hold any
3176 * locks. This function issues config_port mailbox command to configure
3177 * the SLI, setup iocb rings and HBQ rings. In the end the function
3178 * calls the config_port_post function to issue init_link mailbox
3179 * command and to start the discovery. The function will return zero
3180 * if successful, else it will return negative error code.
3181 **/
2503int 3182int
2504lpfc_sli_hba_setup(struct lpfc_hba *phba) 3183lpfc_sli_hba_setup(struct lpfc_hba *phba)
2505{ 3184{
@@ -2528,22 +3207,20 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba)
2528 break; 3207 break;
2529 } 3208 }
2530 3209
2531 rc = lpfc_do_config_port(phba, mode); 3210 rc = lpfc_sli_config_port(phba, mode);
3211
2532 if (rc && lpfc_sli_mode == 3) 3212 if (rc && lpfc_sli_mode == 3)
2533 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT, 3213 lpfc_printf_log(phba, KERN_ERR, LOG_INIT | LOG_VPORT,
2534 "1820 Unable to select SLI-3. " 3214 "1820 Unable to select SLI-3. "
2535 "Not supported by adapter.\n"); 3215 "Not supported by adapter.\n");
2536 if (rc && mode != 2) 3216 if (rc && mode != 2)
2537 rc = lpfc_do_config_port(phba, 2); 3217 rc = lpfc_sli_config_port(phba, 2);
2538 if (rc) 3218 if (rc)
2539 goto lpfc_sli_hba_setup_error; 3219 goto lpfc_sli_hba_setup_error;
2540 3220
2541 if (phba->sli_rev == 3) { 3221 if (phba->sli_rev == 3) {
2542 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE; 3222 phba->iocb_cmd_size = SLI3_IOCB_CMD_SIZE;
2543 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE; 3223 phba->iocb_rsp_size = SLI3_IOCB_RSP_SIZE;
2544 phba->sli3_options |= LPFC_SLI3_ENABLED;
2545 phba->sli3_options |= LPFC_SLI3_HBQ_ENABLED;
2546
2547 } else { 3224 } else {
2548 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE; 3225 phba->iocb_cmd_size = SLI2_IOCB_CMD_SIZE;
2549 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE; 3226 phba->iocb_rsp_size = SLI2_IOCB_RSP_SIZE;
@@ -2558,8 +3235,7 @@ lpfc_sli_hba_setup(struct lpfc_hba *phba)
2558 if (rc) 3235 if (rc)
2559 goto lpfc_sli_hba_setup_error; 3236 goto lpfc_sli_hba_setup_error;
2560 3237
2561 /* Init HBQs */ 3238 /* Init HBQs */
2562
2563 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) { 3239 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
2564 rc = lpfc_sli_hbq_setup(phba); 3240 rc = lpfc_sli_hbq_setup(phba);
2565 if (rc) 3241 if (rc)
@@ -2581,19 +3257,19 @@ lpfc_sli_hba_setup_error:
2581 return rc; 3257 return rc;
2582} 3258}
2583 3259
2584/*! lpfc_mbox_timeout 3260
2585 * 3261/**
2586 * \pre 3262 * lpfc_mbox_timeout: Timeout call back function for mbox timer.
2587 * \post 3263 * @ptr: context object - pointer to hba structure.
2588 * \param hba Pointer to per struct lpfc_hba structure
2589 * \param l1 Pointer to the driver's mailbox queue.
2590 * \return
2591 * void
2592 *
2593 * \b Description:
2594 * 3264 *
2595 * This routine handles mailbox timeout events at timer interrupt context. 3265 * This is the callback function for mailbox timer. The mailbox
2596 */ 3266 * timer is armed when a new mailbox command is issued and the timer
3267 * is deleted when the mailbox complete. The function is called by
3268 * the kernel timer code when a mailbox does not complete within
3269 * expected time. This function wakes up the worker thread to
3270 * process the mailbox timeout and returns. All the processing is
3271 * done by the worker thread function lpfc_mbox_timeout_handler.
3272 **/
2597void 3273void
2598lpfc_mbox_timeout(unsigned long ptr) 3274lpfc_mbox_timeout(unsigned long ptr)
2599{ 3275{
@@ -2612,6 +3288,15 @@ lpfc_mbox_timeout(unsigned long ptr)
2612 return; 3288 return;
2613} 3289}
2614 3290
3291
3292/**
3293 * lpfc_mbox_timeout_handler: Worker thread function to handle mailbox timeout.
3294 * @phba: Pointer to HBA context object.
3295 *
3296 * This function is called from worker thread when a mailbox command times out.
3297 * The caller is not required to hold any locks. This function will reset the
3298 * HBA and recover all the pending commands.
3299 **/
2615void 3300void
2616lpfc_mbox_timeout_handler(struct lpfc_hba *phba) 3301lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2617{ 3302{
@@ -2666,6 +3351,32 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2666 return; 3351 return;
2667} 3352}
2668 3353
3354/**
3355 * lpfc_sli_issue_mbox: Issue a mailbox command to firmware.
3356 * @phba: Pointer to HBA context object.
3357 * @pmbox: Pointer to mailbox object.
3358 * @flag: Flag indicating how the mailbox need to be processed.
3359 *
3360 * This function is called by discovery code and HBA management code
3361 * to submit a mailbox command to firmware. This function gets the
3362 * hbalock to protect the data structures.
3363 * The mailbox command can be submitted in polling mode, in which case
3364 * this function will wait in a polling loop for the completion of the
3365 * mailbox.
3366 * If the mailbox is submitted in no_wait mode (not polling) the
3367 * function will submit the command and returns immediately without waiting
3368 * for the mailbox completion. The no_wait is supported only when HBA
3369 * is in SLI2/SLI3 mode - interrupts are enabled.
3370 * The SLI interface allows only one mailbox pending at a time. If the
3371 * mailbox is issued in polling mode and there is already a mailbox
3372 * pending, then the function will return an error. If the mailbox is issued
3373 * in NO_WAIT mode and there is a mailbox pending already, the function
3374 * will return MBX_BUSY after queuing the mailbox into mailbox queue.
3375 * The sli layer owns the mailbox object until the completion of mailbox
3376 * command if this function return MBX_BUSY or MBX_SUCCESS. For all other
3377 * return codes the caller owns the mailbox command after the return of
3378 * the function.
3379 **/
2669int 3380int
2670lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag) 3381lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2671{ 3382{
@@ -2676,7 +3387,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2676 int i; 3387 int i;
2677 unsigned long timeout; 3388 unsigned long timeout;
2678 unsigned long drvr_flag = 0; 3389 unsigned long drvr_flag = 0;
2679 volatile uint32_t word0, ldata; 3390 uint32_t word0, ldata;
2680 void __iomem *to_slim; 3391 void __iomem *to_slim;
2681 int processing_queue = 0; 3392 int processing_queue = 0;
2682 3393
@@ -2836,12 +3547,11 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2836 3547
2837 if (psli->sli_flag & LPFC_SLI2_ACTIVE) { 3548 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2838 /* First copy command data to host SLIM area */ 3549 /* First copy command data to host SLIM area */
2839 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, MAILBOX_CMD_SIZE); 3550 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
2840 } else { 3551 } else {
2841 if (mb->mbxCommand == MBX_CONFIG_PORT) { 3552 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2842 /* copy command data into host mbox for cmpl */ 3553 /* copy command data into host mbox for cmpl */
2843 lpfc_sli_pcimem_bcopy(mb, &phba->slim2p->mbx, 3554 lpfc_sli_pcimem_bcopy(mb, phba->mbox, MAILBOX_CMD_SIZE);
2844 MAILBOX_CMD_SIZE);
2845 } 3555 }
2846 3556
2847 /* First copy mbox command data to HBA SLIM, skip past first 3557 /* First copy mbox command data to HBA SLIM, skip past first
@@ -2851,7 +3561,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2851 MAILBOX_CMD_SIZE - sizeof (uint32_t)); 3561 MAILBOX_CMD_SIZE - sizeof (uint32_t));
2852 3562
2853 /* Next copy over first word, with mbxOwner set */ 3563 /* Next copy over first word, with mbxOwner set */
2854 ldata = *((volatile uint32_t *)mb); 3564 ldata = *((uint32_t *)mb);
2855 to_slim = phba->MBslimaddr; 3565 to_slim = phba->MBslimaddr;
2856 writel(ldata, to_slim); 3566 writel(ldata, to_slim);
2857 readl(to_slim); /* flush */ 3567 readl(to_slim); /* flush */
@@ -2883,7 +3593,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2883 3593
2884 if (psli->sli_flag & LPFC_SLI2_ACTIVE) { 3594 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2885 /* First read mbox status word */ 3595 /* First read mbox status word */
2886 word0 = *((volatile uint32_t *)&phba->slim2p->mbx); 3596 word0 = *((uint32_t *)phba->mbox);
2887 word0 = le32_to_cpu(word0); 3597 word0 = le32_to_cpu(word0);
2888 } else { 3598 } else {
2889 /* First read mbox status word */ 3599 /* First read mbox status word */
@@ -2922,12 +3632,11 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2922 3632
2923 if (psli->sli_flag & LPFC_SLI2_ACTIVE) { 3633 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2924 /* First copy command data */ 3634 /* First copy command data */
2925 word0 = *((volatile uint32_t *) 3635 word0 = *((uint32_t *)phba->mbox);
2926 &phba->slim2p->mbx);
2927 word0 = le32_to_cpu(word0); 3636 word0 = le32_to_cpu(word0);
2928 if (mb->mbxCommand == MBX_CONFIG_PORT) { 3637 if (mb->mbxCommand == MBX_CONFIG_PORT) {
2929 MAILBOX_t *slimmb; 3638 MAILBOX_t *slimmb;
2930 volatile uint32_t slimword0; 3639 uint32_t slimword0;
2931 /* Check real SLIM for any errors */ 3640 /* Check real SLIM for any errors */
2932 slimword0 = readl(phba->MBslimaddr); 3641 slimword0 = readl(phba->MBslimaddr);
2933 slimmb = (MAILBOX_t *) & slimword0; 3642 slimmb = (MAILBOX_t *) & slimword0;
@@ -2948,8 +3657,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmbox, uint32_t flag)
2948 3657
2949 if (psli->sli_flag & LPFC_SLI2_ACTIVE) { 3658 if (psli->sli_flag & LPFC_SLI2_ACTIVE) {
2950 /* copy results back to user */ 3659 /* copy results back to user */
2951 lpfc_sli_pcimem_bcopy(&phba->slim2p->mbx, mb, 3660 lpfc_sli_pcimem_bcopy(phba->mbox, mb, MAILBOX_CMD_SIZE);
2952 MAILBOX_CMD_SIZE);
2953 } else { 3661 } else {
2954 /* First copy command data */ 3662 /* First copy command data */
2955 lpfc_memcpy_from_slim(mb, phba->MBslimaddr, 3663 lpfc_memcpy_from_slim(mb, phba->MBslimaddr,
@@ -2980,9 +3688,16 @@ out_not_finished:
2980 return MBX_NOT_FINISHED; 3688 return MBX_NOT_FINISHED;
2981} 3689}
2982 3690
2983/* 3691/**
2984 * Caller needs to hold lock. 3692 * __lpfc_sli_ringtx_put: Add an iocb to the txq.
2985 */ 3693 * @phba: Pointer to HBA context object.
3694 * @pring: Pointer to driver SLI ring object.
3695 * @piocb: Pointer to address of newly added command iocb.
3696 *
3697 * This function is called with hbalock held to add a command
3698 * iocb to the txq when SLI layer cannot submit the command iocb
3699 * to the ring.
3700 **/
2986static void 3701static void
2987__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3702__lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2988 struct lpfc_iocbq *piocb) 3703 struct lpfc_iocbq *piocb)
@@ -2992,6 +3707,23 @@ __lpfc_sli_ringtx_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2992 pring->txq_cnt++; 3707 pring->txq_cnt++;
2993} 3708}
2994 3709
3710/**
3711 * lpfc_sli_next_iocb: Get the next iocb in the txq.
3712 * @phba: Pointer to HBA context object.
3713 * @pring: Pointer to driver SLI ring object.
3714 * @piocb: Pointer to address of newly added command iocb.
3715 *
3716 * This function is called with hbalock held before a new
3717 * iocb is submitted to the firmware. This function checks
3718 * txq to flush the iocbs in txq to Firmware before
3719 * submitting new iocbs to the Firmware.
3720 * If there are iocbs in the txq which need to be submitted
3721 * to firmware, lpfc_sli_next_iocb returns the first element
3722 * of the txq after dequeuing it from txq.
3723 * If there is no iocb in the txq then the function will return
3724 * *piocb and *piocb is set to NULL. Caller needs to check
3725 * *piocb to find if there are more commands in the txq.
3726 **/
2995static struct lpfc_iocbq * 3727static struct lpfc_iocbq *
2996lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3728lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2997 struct lpfc_iocbq **piocb) 3729 struct lpfc_iocbq **piocb)
@@ -3007,9 +3739,30 @@ lpfc_sli_next_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3007 return nextiocb; 3739 return nextiocb;
3008} 3740}
3009 3741
3010/* 3742/**
3011 * Lockless version of lpfc_sli_issue_iocb. 3743 * __lpfc_sli_issue_iocb: Lockless version of lpfc_sli_issue_iocb.
3012 */ 3744 * @phba: Pointer to HBA context object.
3745 * @pring: Pointer to driver SLI ring object.
3746 * @piocb: Pointer to command iocb.
3747 * @flag: Flag indicating if this command can be put into txq.
3748 *
3749 * __lpfc_sli_issue_iocb is used by other functions in the driver
3750 * to issue an iocb command to the HBA. If the PCI slot is recovering
3751 * from error state or if HBA is resetting or if LPFC_STOP_IOCB_EVENT
3752 * flag is turned on, the function returns IOCB_ERROR.
3753 * When the link is down, this function allows only iocbs for
3754 * posting buffers.
3755 * This function finds next available slot in the command ring and
3756 * posts the command to the available slot and writes the port
3757 * attention register to request HBA start processing new iocb.
3758 * If there is no slot available in the ring and
3759 * flag & SLI_IOCB_RET_IOCB is set, the new iocb is added to the
3760 * txq, otherwise the function returns IOCB_BUSY.
3761 *
3762 * This function is called with hbalock held.
3763 * The function will return success after it successfully submit the
3764 * iocb to firmware or after adding to the txq.
3765 **/
3013static int 3766static int
3014__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3767__lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3015 struct lpfc_iocbq *piocb, uint32_t flag) 3768 struct lpfc_iocbq *piocb, uint32_t flag)
@@ -3052,6 +3805,16 @@ __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3052 * can be issued if the link is not up. 3805 * can be issued if the link is not up.
3053 */ 3806 */
3054 switch (piocb->iocb.ulpCommand) { 3807 switch (piocb->iocb.ulpCommand) {
3808 case CMD_GEN_REQUEST64_CR:
3809 case CMD_GEN_REQUEST64_CX:
3810 if (!(phba->sli.sli_flag & LPFC_MENLO_MAINT) ||
3811 (piocb->iocb.un.genreq64.w5.hcsw.Rctl !=
3812 FC_FCP_CMND) ||
3813 (piocb->iocb.un.genreq64.w5.hcsw.Type !=
3814 MENLO_TRANSPORT_TYPE))
3815
3816 goto iocb_busy;
3817 break;
3055 case CMD_QUE_RING_BUF_CN: 3818 case CMD_QUE_RING_BUF_CN:
3056 case CMD_QUE_RING_BUF64_CN: 3819 case CMD_QUE_RING_BUF64_CN:
3057 /* 3820 /*
@@ -3106,6 +3869,19 @@ __lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3106} 3869}
3107 3870
3108 3871
3872/**
3873 * lpfc_sli_issue_iocb: Wrapper function for __lpfc_sli_issue_iocb.
3874 * @phba: Pointer to HBA context object.
3875 * @pring: Pointer to driver SLI ring object.
3876 * @piocb: Pointer to command iocb.
3877 * @flag: Flag indicating if this command can be put into txq.
3878 *
3879 * lpfc_sli_issue_iocb is a wrapper around __lpfc_sli_issue_iocb
3880 * function. This function gets the hbalock and calls
3881 * __lpfc_sli_issue_iocb function and will return the error returned
3882 * by __lpfc_sli_issue_iocb function. This wrapper is used by
3883 * functions which do not hold hbalock.
3884 **/
3109int 3885int
3110lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 3886lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3111 struct lpfc_iocbq *piocb, uint32_t flag) 3887 struct lpfc_iocbq *piocb, uint32_t flag)
@@ -3120,6 +3896,17 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3120 return rc; 3896 return rc;
3121} 3897}
3122 3898
3899/**
3900 * lpfc_extra_ring_setup: Extra ring setup function.
3901 * @phba: Pointer to HBA context object.
3902 *
3903 * This function is called while driver attaches with the
3904 * HBA to setup the extra ring. The extra ring is used
3905 * only when driver needs to support target mode functionality
3906 * or IP over FC functionalities.
3907 *
3908 * This function is called with no lock held.
3909 **/
3123static int 3910static int
3124lpfc_extra_ring_setup( struct lpfc_hba *phba) 3911lpfc_extra_ring_setup( struct lpfc_hba *phba)
3125{ 3912{
@@ -3155,6 +3942,19 @@ lpfc_extra_ring_setup( struct lpfc_hba *phba)
3155 return 0; 3942 return 0;
3156} 3943}
3157 3944
3945/**
3946 * lpfc_sli_async_event_handler: ASYNC iocb handler function.
3947 * @phba: Pointer to HBA context object.
3948 * @pring: Pointer to driver SLI ring object.
3949 * @iocbq: Pointer to iocb object.
3950 *
3951 * This function is called by the slow ring event handler
3952 * function when there is an ASYNC event iocb in the ring.
3953 * This function is called with no lock held.
3954 * Currently this function handles only temperature related
3955 * ASYNC events. The function decodes the temperature sensor
3956 * event message and posts events for the management applications.
3957 **/
3158static void 3958static void
3159lpfc_sli_async_event_handler(struct lpfc_hba * phba, 3959lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3160 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq) 3960 struct lpfc_sli_ring * pring, struct lpfc_iocbq * iocbq)
@@ -3210,6 +4010,17 @@ lpfc_sli_async_event_handler(struct lpfc_hba * phba,
3210} 4010}
3211 4011
3212 4012
4013/**
4014 * lpfc_sli_setup: SLI ring setup function.
4015 * @phba: Pointer to HBA context object.
4016 *
4017 * lpfc_sli_setup sets up rings of the SLI interface with
4018 * number of iocbs per ring and iotags. This function is
4019 * called while driver attach to the HBA and before the
4020 * interrupts are enabled. So there is no need for locking.
4021 *
4022 * This function always returns 0.
4023 **/
3213int 4024int
3214lpfc_sli_setup(struct lpfc_hba *phba) 4025lpfc_sli_setup(struct lpfc_hba *phba)
3215{ 4026{
@@ -3321,6 +4132,17 @@ lpfc_sli_setup(struct lpfc_hba *phba)
3321 return 0; 4132 return 0;
3322} 4133}
3323 4134
4135/**
4136 * lpfc_sli_queue_setup: Queue initialization function.
4137 * @phba: Pointer to HBA context object.
4138 *
4139 * lpfc_sli_queue_setup sets up mailbox queues and iocb queues for each
4140 * ring. This function also initializes ring indices of each ring.
4141 * This function is called during the initialization of the SLI
4142 * interface of an HBA.
4143 * This function is called with no lock held and always returns
4144 * 1.
4145 **/
3324int 4146int
3325lpfc_sli_queue_setup(struct lpfc_hba *phba) 4147lpfc_sli_queue_setup(struct lpfc_hba *phba)
3326{ 4148{
@@ -3349,6 +4171,23 @@ lpfc_sli_queue_setup(struct lpfc_hba *phba)
3349 return 1; 4171 return 1;
3350} 4172}
3351 4173
4174/**
4175 * lpfc_sli_host_down: Vport cleanup function.
4176 * @vport: Pointer to virtual port object.
4177 *
4178 * lpfc_sli_host_down is called to clean up the resources
4179 * associated with a vport before destroying virtual
4180 * port data structures.
4181 * This function does following operations:
4182 * - Free discovery resources associated with this virtual
4183 * port.
4184 * - Free iocbs associated with this virtual port in
4185 * the txq.
4186 * - Send abort for all iocb commands associated with this
4187 * vport in txcmplq.
4188 *
4189 * This function is called with no lock held and always returns 1.
4190 **/
3352int 4191int
3353lpfc_sli_host_down(struct lpfc_vport *vport) 4192lpfc_sli_host_down(struct lpfc_vport *vport)
3354{ 4193{
@@ -3411,6 +4250,21 @@ lpfc_sli_host_down(struct lpfc_vport *vport)
3411 return 1; 4250 return 1;
3412} 4251}
3413 4252
4253/**
4254 * lpfc_sli_hba_down: Resource cleanup function for the HBA.
4255 * @phba: Pointer to HBA context object.
4256 *
4257 * This function cleans up all iocb, buffers, mailbox commands
4258 * while shutting down the HBA. This function is called with no
4259 * lock held and always returns 1.
4260 * This function does the following to cleanup driver resources:
4261 * - Free discovery resources for each virtual port
4262 * - Cleanup any pending fabric iocbs
4263 * - Iterate through the iocb txq and free each entry
4264 * in the list.
4265 * - Free up any buffer posted to the HBA
4266 * - Free mailbox commands in the mailbox queue.
4267 **/
3414int 4268int
3415lpfc_sli_hba_down(struct lpfc_hba *phba) 4269lpfc_sli_hba_down(struct lpfc_hba *phba)
3416{ 4270{
@@ -3501,6 +4355,18 @@ lpfc_sli_hba_down(struct lpfc_hba *phba)
3501 return 1; 4355 return 1;
3502} 4356}
3503 4357
4358/**
4359 * lpfc_sli_pcimem_bcopy: SLI memory copy function.
4360 * @srcp: Source memory pointer.
4361 * @destp: Destination memory pointer.
4362 * @cnt: Number of words required to be copied.
4363 *
4364 * This function is used for copying data between driver memory
4365 * and the SLI memory. This function also changes the endianness
4366 * of each word if native endianness is different from SLI
4367 * endianness. This function can be called with or without
4368 * lock.
4369 **/
3504void 4370void
3505lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt) 4371lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3506{ 4372{
@@ -3518,6 +4384,17 @@ lpfc_sli_pcimem_bcopy(void *srcp, void *destp, uint32_t cnt)
3518 } 4384 }
3519} 4385}
3520 4386
4387
4388/**
4389 * lpfc_sli_ringpostbuf_put: Function to add a buffer to postbufq.
4390 * @phba: Pointer to HBA context object.
4391 * @pring: Pointer to driver SLI ring object.
4392 * @mp: Pointer to driver buffer object.
4393 *
4394 * This function is called with no lock held.
4395 * It always return zero after adding the buffer to the postbufq
4396 * buffer list.
4397 **/
3521int 4398int
3522lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4399lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3523 struct lpfc_dmabuf *mp) 4400 struct lpfc_dmabuf *mp)
@@ -3531,6 +4408,18 @@ lpfc_sli_ringpostbuf_put(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3531 return 0; 4408 return 0;
3532} 4409}
3533 4410
4411/**
4412 * lpfc_sli_get_buffer_tag: Tag allocation function for a buffer posted
4413 * using CMD_QUE_XRI64_CX iocb.
4414 * @phba: Pointer to HBA context object.
4415 *
4416 * When HBQ is enabled, buffers are searched based on tags. This function
4417 * allocates a tag for buffer posted using CMD_QUE_XRI64_CX iocb. The
4418 * tag is bit wise or-ed with QUE_BUFTAG_BIT to make sure that the tag
4419 * does not conflict with tags of buffer posted for unsolicited events.
4420 * The function returns the allocated tag. The function is called with
4421 * no locks held.
4422 **/
3534uint32_t 4423uint32_t
3535lpfc_sli_get_buffer_tag(struct lpfc_hba *phba) 4424lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
3536{ 4425{
@@ -3545,6 +4434,22 @@ lpfc_sli_get_buffer_tag(struct lpfc_hba *phba)
3545 return phba->buffer_tag_count; 4434 return phba->buffer_tag_count;
3546} 4435}
3547 4436
4437/**
4438 * lpfc_sli_ring_taggedbuf_get: Search HBQ buffer associated with
4439 * posted using CMD_QUE_XRI64_CX iocb.
4440 * @phba: Pointer to HBA context object.
4441 * @pring: Pointer to driver SLI ring object.
4442 * @tag: Buffer tag.
4443 *
4444 * Buffers posted using CMD_QUE_XRI64_CX iocb are in pring->postbufq
4445 * list. After HBA DMA data to these buffers, CMD_IOCB_RET_XRI64_CX
4446 * iocb is posted to the response ring with the tag of the buffer.
4447 * This function searches the pring->postbufq list using the tag
4448 * to find buffer associated with CMD_IOCB_RET_XRI64_CX
4449 * iocb. If the buffer is found then lpfc_dmabuf object of the
4450 * buffer is returned to the caller else NULL is returned.
4451 * This function is called with no lock held.
4452 **/
3548struct lpfc_dmabuf * 4453struct lpfc_dmabuf *
3549lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4454lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3550 uint32_t tag) 4455 uint32_t tag)
@@ -3565,7 +4470,7 @@ lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3565 4470
3566 spin_unlock_irq(&phba->hbalock); 4471 spin_unlock_irq(&phba->hbalock);
3567 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 4472 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3568 "0410 Cannot find virtual addr for buffer tag on " 4473 "0402 Cannot find virtual addr for buffer tag on "
3569 "ring %d Data x%lx x%p x%p x%x\n", 4474 "ring %d Data x%lx x%p x%p x%x\n",
3570 pring->ringno, (unsigned long) tag, 4475 pring->ringno, (unsigned long) tag,
3571 slp->next, slp->prev, pring->postbufq_cnt); 4476 slp->next, slp->prev, pring->postbufq_cnt);
@@ -3573,6 +4478,23 @@ lpfc_sli_ring_taggedbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3573 return NULL; 4478 return NULL;
3574} 4479}
3575 4480
4481/**
4482 * lpfc_sli_ringpostbuf_get: SLI2 buffer search function for
4483 * unsolicited ct and els events.
4484 * @phba: Pointer to HBA context object.
4485 * @pring: Pointer to driver SLI ring object.
4486 * @phys: DMA address of the buffer.
4487 *
4488 * This function searches the buffer list using the dma_address
4489 * of unsolicited event to find the driver's lpfc_dmabuf object
4490 * corresponding to the dma_address. The function returns the
4491 * lpfc_dmabuf object if a buffer is found else it returns NULL.
4492 * This function is called by the ct and els unsolicited event
4493 * handlers to get the buffer associated with the unsolicited
4494 * event.
4495 *
4496 * This function is called with no lock held.
4497 **/
3576struct lpfc_dmabuf * 4498struct lpfc_dmabuf *
3577lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4499lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3578 dma_addr_t phys) 4500 dma_addr_t phys)
@@ -3600,6 +4522,17 @@ lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3600 return NULL; 4522 return NULL;
3601} 4523}
3602 4524
4525/**
4526 * lpfc_sli_abort_els_cmpl: Completion handler for the els abort iocbs.
4527 * @phba: Pointer to HBA context object.
4528 * @cmdiocb: Pointer to driver command iocb object.
4529 * @rspiocb: Pointer to driver response iocb object.
4530 *
4531 * This function is the completion handler for the abort iocbs for
4532 * ELS commands. This function is called from the ELS ring event
4533 * handler with no lock held. This function frees memory resources
4534 * associated with the abort iocb.
4535 **/
3603static void 4536static void
3604lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4537lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3605 struct lpfc_iocbq *rspiocb) 4538 struct lpfc_iocbq *rspiocb)
@@ -3665,6 +4598,17 @@ lpfc_sli_abort_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3665 return; 4598 return;
3666} 4599}
3667 4600
4601/**
4602 * lpfc_ignore_els_cmpl: Completion handler for aborted ELS command.
4603 * @phba: Pointer to HBA context object.
4604 * @cmdiocb: Pointer to driver command iocb object.
4605 * @rspiocb: Pointer to driver response iocb object.
4606 *
4607 * The function is called from SLI ring event handler with no
4608 * lock held. This function is the completion handler for ELS commands
4609 * which are aborted. The function frees memory resources used for
4610 * the aborted ELS commands.
4611 **/
3668static void 4612static void
3669lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4613lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3670 struct lpfc_iocbq *rspiocb) 4614 struct lpfc_iocbq *rspiocb)
@@ -3673,7 +4617,7 @@ lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3673 4617
3674 /* ELS cmd tag <ulpIoTag> completes */ 4618 /* ELS cmd tag <ulpIoTag> completes */
3675 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 4619 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3676 "0133 Ignoring ELS cmd tag x%x completion Data: " 4620 "0139 Ignoring ELS cmd tag x%x completion Data: "
3677 "x%x x%x x%x\n", 4621 "x%x x%x x%x\n",
3678 irsp->ulpIoTag, irsp->ulpStatus, 4622 irsp->ulpIoTag, irsp->ulpStatus,
3679 irsp->un.ulpWord[4], irsp->ulpTimeout); 4623 irsp->un.ulpWord[4], irsp->ulpTimeout);
@@ -3684,6 +4628,17 @@ lpfc_ignore_els_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3684 return; 4628 return;
3685} 4629}
3686 4630
4631/**
4632 * lpfc_sli_issue_abort_iotag: Abort function for a command iocb.
4633 * @phba: Pointer to HBA context object.
4634 * @pring: Pointer to driver SLI ring object.
4635 * @cmdiocb: Pointer to driver command iocb object.
4636 *
4637 * This function issues an abort iocb for the provided command
4638 * iocb. This function is called with hbalock held.
4639 * The function returns 0 when it fails due to memory allocation
4640 * failure or when the command iocb is an abort request.
4641 **/
3687int 4642int
3688lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, 4643lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3689 struct lpfc_iocbq *cmdiocb) 4644 struct lpfc_iocbq *cmdiocb)
@@ -3748,6 +4703,8 @@ lpfc_sli_issue_abort_iotag(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3748 iabt->un.acxri.abortIoTag, abtsiocbp->iotag); 4703 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
3749 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0); 4704 retval = __lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
3750 4705
4706 if (retval)
4707 __lpfc_sli_release_iocbq(phba, abtsiocbp);
3751abort_iotag_exit: 4708abort_iotag_exit:
3752 /* 4709 /*
3753 * Caller to this routine should check for IOCB_ERROR 4710 * Caller to this routine should check for IOCB_ERROR
@@ -3757,6 +4714,29 @@ abort_iotag_exit:
3757 return retval; 4714 return retval;
3758} 4715}
3759 4716
4717/**
4718 * lpfc_sli_validate_fcp_iocb: Filtering function, used to find commands
4719 * associated with a vport/SCSI target/lun.
4720 * @iocbq: Pointer to driver iocb object.
4721 * @vport: Pointer to driver virtual port object.
4722 * @tgt_id: SCSI ID of the target.
4723 * @lun_id: LUN ID of the scsi device.
4724 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST
4725 *
4726 * This function acts as iocb filter for functions which abort or count
4727 * all FCP iocbs pending on a lun/SCSI target/SCSI host. It will return
4728 * 0 if the filtering criteria is met for the given iocb and will return
4729 * 1 if the filtering criteria is not met.
4730 * If ctx_cmd == LPFC_CTX_LUN, the function returns 0 only if the
4731 * given iocb is for the SCSI device specified by vport, tgt_id and
4732 * lun_id parameter.
4733 * If ctx_cmd == LPFC_CTX_TGT, the function returns 0 only if the
4734 * given iocb is for the SCSI target specified by vport and tgt_id
4735 * parameters.
4736 * If ctx_cmd == LPFC_CTX_HOST, the function returns 0 only if the
4737 * given iocb is for the SCSI host associated with the given vport.
4738 * This function is called with no locks held.
4739 **/
3760static int 4740static int
3761lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport, 4741lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3762 uint16_t tgt_id, uint64_t lun_id, 4742 uint16_t tgt_id, uint64_t lun_id,
@@ -3800,6 +4780,25 @@ lpfc_sli_validate_fcp_iocb(struct lpfc_iocbq *iocbq, struct lpfc_vport *vport,
3800 return rc; 4780 return rc;
3801} 4781}
3802 4782
4783/**
4784 * lpfc_sli_sum_iocb: Function to count the number of FCP iocbs pending.
4785 * @vport: Pointer to virtual port.
4786 * @tgt_id: SCSI ID of the target.
4787 * @lun_id: LUN ID of the scsi device.
4788 * @ctx_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
4789 *
4790 * This function returns number of FCP commands pending for the vport.
4791 * When ctx_cmd == LPFC_CTX_LUN, the function returns number of FCP
4792 * commands pending on the vport associated with SCSI device specified
4793 * by tgt_id and lun_id parameters.
4794 * When ctx_cmd == LPFC_CTX_TGT, the function returns number of FCP
4795 * commands pending on the vport associated with SCSI target specified
4796 * by tgt_id parameter.
4797 * When ctx_cmd == LPFC_CTX_HOST, the function returns number of FCP
4798 * commands pending on the vport.
4799 * This function returns the number of iocbs which satisfy the filter.
4800 * This function is called without any lock held.
4801 **/
3803int 4802int
3804lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id, 4803lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3805 lpfc_ctx_cmd ctx_cmd) 4804 lpfc_ctx_cmd ctx_cmd)
@@ -3819,6 +4818,17 @@ lpfc_sli_sum_iocb(struct lpfc_vport *vport, uint16_t tgt_id, uint64_t lun_id,
3819 return sum; 4818 return sum;
3820} 4819}
3821 4820
4821/**
4822 * lpfc_sli_abort_fcp_cmpl: Completion handler function for an aborted
4823 * FCP iocb.
4824 * @phba: Pointer to HBA context object
4825 * @cmdiocb: Pointer to command iocb object.
4826 * @rspiocb: Pointer to response iocb object.
4827 *
4828 * This function is called when an aborted FCP iocb completes. This
4829 * function is called by the ring event handler with no lock held.
4830 * This function frees the iocb.
4831 **/
3822void 4832void
3823lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb, 4833lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3824 struct lpfc_iocbq *rspiocb) 4834 struct lpfc_iocbq *rspiocb)
@@ -3827,6 +4837,28 @@ lpfc_sli_abort_fcp_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3827 return; 4837 return;
3828} 4838}
3829 4839
4840/**
4841 * lpfc_sli_abort_iocb: This function issue abort for all SCSI commands
4842 * pending on a SCSI host(vport)/target/lun.
4843 * @vport: Pointer to virtual port.
4844 * @pring: Pointer to driver SLI ring object.
4845 * @tgt_id: SCSI ID of the target.
4846 * @lun_id: LUN ID of the scsi device.
4847 * @abort_cmd: LPFC_CTX_LUN/LPFC_CTX_TGT/LPFC_CTX_HOST.
4848 *
4849 * This function sends an abort command for every SCSI command
4850 * associated with the given virtual port pending on the ring
4851 * filtered by lpfc_sli_validate_fcp_iocb function.
4852 * When abort_cmd == LPFC_CTX_LUN, the function sends abort only to the
4853 * FCP iocbs associated with lun specified by tgt_id and lun_id
4854 * parameters
4855 * When abort_cmd == LPFC_CTX_TGT, the function sends abort only to the
4856 * FCP iocbs associated with SCSI target specified by tgt_id parameter.
4857 * When abort_cmd == LPFC_CTX_HOST, the function sends abort to all
4858 * FCP iocbs associated with virtual port.
4859 * This function returns number of iocbs it failed to abort.
4860 * This function is called with no locks held.
4861 **/
3830int 4862int
3831lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring, 4863lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3832 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd) 4864 uint16_t tgt_id, uint64_t lun_id, lpfc_ctx_cmd abort_cmd)
@@ -3878,6 +4910,24 @@ lpfc_sli_abort_iocb(struct lpfc_vport *vport, struct lpfc_sli_ring *pring,
3878 return errcnt; 4910 return errcnt;
3879} 4911}
3880 4912
4913/**
4914 * lpfc_sli_wake_iocb_wait: iocb completion handler for iocb issued using
4915 * lpfc_sli_issue_iocb_wait.
4916 * @phba: Pointer to HBA context object.
4917 * @cmdiocbq: Pointer to command iocb.
4918 * @rspiocbq: Pointer to response iocb.
4919 *
4920 * This function is the completion handler for iocbs issued using
4921 * lpfc_sli_issue_iocb_wait function. This function is called by the
4922 * ring event handler function without any lock held. This function
4923 * can be called from both worker thread context and interrupt
4924 * context. This function also can be called from other thread which
4925 * cleans up the SLI layer objects.
4926 * This function copy the contents of the response iocb to the
4927 * response iocb memory object provided by the caller of
4928 * lpfc_sli_issue_iocb_wait and then wakes up the thread which
4929 * sleeps for the iocb completion.
4930 **/
3881static void 4931static void
3882lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba, 4932lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3883 struct lpfc_iocbq *cmdiocbq, 4933 struct lpfc_iocbq *cmdiocbq,
@@ -3899,13 +4949,36 @@ lpfc_sli_wake_iocb_wait(struct lpfc_hba *phba,
3899 return; 4949 return;
3900} 4950}
3901 4951
3902/* 4952/**
3903 * Issue the caller's iocb and wait for its completion, but no longer than the 4953 * lpfc_sli_issue_iocb_wait: Synchronous function to issue iocb commands.
3904 * caller's timeout. Note that iocb_flags is cleared before the 4954 * @phba: Pointer to HBA context object..
3905 * lpfc_sli_issue_call since the wake routine sets a unique value and by 4955 * @pring: Pointer to sli ring.
3906 * definition this is a wait function. 4956 * @piocb: Pointer to command iocb.
3907 */ 4957 * @prspiocbq: Pointer to response iocb.
3908 4958 * @timeout: Timeout in number of seconds.
4959 *
4960 * This function issues the iocb to firmware and waits for the
4961 * iocb to complete. If the iocb command is not
4962 * completed within timeout seconds, it returns IOCB_TIMEDOUT.
4963 * Caller should not free the iocb resources if this function
4964 * returns IOCB_TIMEDOUT.
4965 * The function waits for the iocb completion using an
4966 * non-interruptible wait.
4967 * This function will sleep while waiting for iocb completion.
4968 * So, this function should not be called from any context which
4969 * does not allow sleeping. Due to the same reason, this function
4970 * cannot be called with interrupt disabled.
4971 * This function assumes that the iocb completions occur while
4972 * this function sleep. So, this function cannot be called from
4973 * the thread which process iocb completion for this ring.
4974 * This function clears the iocb_flag of the iocb object before
4975 * issuing the iocb and the iocb completion handler sets this
4976 * flag and wakes this thread when the iocb completes.
4977 * The contents of the response iocb will be copied to prspiocbq
4978 * by the completion handler when the command completes.
4979 * This function returns IOCB_SUCCESS when success.
4980 * This function is called with no lock held.
4981 **/
3909int 4982int
3910lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba, 4983lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3911 struct lpfc_sli_ring *pring, 4984 struct lpfc_sli_ring *pring,
@@ -3963,7 +5036,7 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3963 } 5036 }
3964 } else { 5037 } else {
3965 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 5038 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3966 ":0332 IOCB wait issue failed, Data x%x\n", 5039 "0332 IOCB wait issue failed, Data x%x\n",
3967 retval); 5040 retval);
3968 retval = IOCB_ERROR; 5041 retval = IOCB_ERROR;
3969 } 5042 }
@@ -3983,6 +5056,32 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba *phba,
3983 return retval; 5056 return retval;
3984} 5057}
3985 5058
5059/**
5060 * lpfc_sli_issue_mbox_wait: Synchronous function to issue mailbox.
5061 * @phba: Pointer to HBA context object.
5062 * @pmboxq: Pointer to driver mailbox object.
5063 * @timeout: Timeout in number of seconds.
5064 *
5065 * This function issues the mailbox to firmware and waits for the
5066 * mailbox command to complete. If the mailbox command is not
5067 * completed within timeout seconds, it returns MBX_TIMEOUT.
5068 * The function waits for the mailbox completion using an
5069 * interruptible wait. If the thread is woken up due to a
5070 * signal, MBX_TIMEOUT error is returned to the caller. Caller
5071 * should not free the mailbox resources, if this function returns
5072 * MBX_TIMEOUT.
5073 * This function will sleep while waiting for mailbox completion.
5074 * So, this function should not be called from any context which
5075 * does not allow sleeping. Due to the same reason, this function
5076 * cannot be called with interrupt disabled.
5077 * This function assumes that the mailbox completion occurs while
5078 * this function sleep. So, this function cannot be called from
5079 * the worker thread which processes mailbox completion.
5080 * This function is called in the context of HBA management
5081 * applications.
5082 * This function returns MBX_SUCCESS when successful.
5083 * This function is called with no lock held.
5084 **/
3986int 5085int
3987lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq, 5086lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
3988 uint32_t timeout) 5087 uint32_t timeout)
@@ -4027,6 +5126,18 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmboxq,
4027 return retval; 5126 return retval;
4028} 5127}
4029 5128
5129/**
5130 * lpfc_sli_flush_mbox_queue: mailbox queue cleanup function.
5131 * @phba: Pointer to HBA context.
5132 *
5133 * This function is called to cleanup any pending mailbox
5134 * objects in the driver queue before bringing the HBA offline.
5135 * This function is called while resetting the HBA.
5136 * The function is called without any lock held. The function
5137 * takes hbalock to update SLI data structure.
5138 * This function returns 1 when there is an active mailbox
5139 * command pending else returns 0.
5140 **/
4030int 5141int
4031lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba) 5142lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
4032{ 5143{
@@ -4058,8 +5169,74 @@ lpfc_sli_flush_mbox_queue(struct lpfc_hba * phba)
4058 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0; 5169 return (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) ? 1 : 0;
4059} 5170}
4060 5171
5172/**
5173 * lpfc_sli_check_eratt: check error attention events
5174 * @phba: Pointer to HBA context.
5175 *
5176 * This function is called form timer soft interrupt context to check HBA's
5177 * error attention register bit for error attention events.
5178 *
5179 * This fucntion returns 1 when there is Error Attention in the Host Attention
5180 * Register and returns 0 otherwise.
5181 **/
5182int
5183lpfc_sli_check_eratt(struct lpfc_hba *phba)
5184{
5185 uint32_t ha_copy;
5186
5187 /* If somebody is waiting to handle an eratt, don't process it
5188 * here. The brdkill function will do this.
5189 */
5190 if (phba->link_flag & LS_IGNORE_ERATT)
5191 return 0;
5192
5193 /* Check if interrupt handler handles this ERATT */
5194 spin_lock_irq(&phba->hbalock);
5195 if (phba->hba_flag & HBA_ERATT_HANDLED) {
5196 /* Interrupt handler has handled ERATT */
5197 spin_unlock_irq(&phba->hbalock);
5198 return 0;
5199 }
5200
5201 /* Read chip Host Attention (HA) register */
5202 ha_copy = readl(phba->HAregaddr);
5203 if (ha_copy & HA_ERATT) {
5204 /* Read host status register to retrieve error event */
5205 lpfc_sli_read_hs(phba);
5206 /* Set the driver HA work bitmap */
5207 phba->work_ha |= HA_ERATT;
5208 /* Indicate polling handles this ERATT */
5209 phba->hba_flag |= HBA_ERATT_HANDLED;
5210 spin_unlock_irq(&phba->hbalock);
5211 return 1;
5212 }
5213 spin_unlock_irq(&phba->hbalock);
5214 return 0;
5215}
5216
5217/**
5218 * lpfc_sp_intr_handler: The slow-path interrupt handler of lpfc driver.
5219 * @irq: Interrupt number.
5220 * @dev_id: The device context pointer.
5221 *
5222 * This function is directly called from the PCI layer as an interrupt
5223 * service routine when the device is enabled with MSI-X multi-message
5224 * interrupt mode and there are slow-path events in the HBA. However,
5225 * when the device is enabled with either MSI or Pin-IRQ interrupt mode,
5226 * this function is called as part of the device-level interrupt handler.
5227 * When the PCI slot is in error recovery or the HBA is undergoing
5228 * initialization, the interrupt handler will not process the interrupt.
5229 * The link attention and ELS ring attention events are handled by the
5230 * worker thread. The interrupt handler signals the worker thread and
5231 * and returns for these events. This function is called without any
5232 * lock held. It gets the hbalock to access and update SLI data
5233 * structures.
5234 *
5235 * This function returns IRQ_HANDLED when interrupt is handled else it
5236 * returns IRQ_NONE.
5237 **/
4061irqreturn_t 5238irqreturn_t
4062lpfc_intr_handler(int irq, void *dev_id) 5239lpfc_sp_intr_handler(int irq, void *dev_id)
4063{ 5240{
4064 struct lpfc_hba *phba; 5241 struct lpfc_hba *phba;
4065 uint32_t ha_copy; 5242 uint32_t ha_copy;
@@ -4078,48 +5255,52 @@ lpfc_intr_handler(int irq, void *dev_id)
4078 * Get the driver's phba structure from the dev_id and 5255 * Get the driver's phba structure from the dev_id and
4079 * assume the HBA is not interrupting. 5256 * assume the HBA is not interrupting.
4080 */ 5257 */
4081 phba = (struct lpfc_hba *) dev_id; 5258 phba = (struct lpfc_hba *)dev_id;
4082 5259
4083 if (unlikely(!phba)) 5260 if (unlikely(!phba))
4084 return IRQ_NONE; 5261 return IRQ_NONE;
4085 5262
4086 /* If the pci channel is offline, ignore all the interrupts. */
4087 if (unlikely(pci_channel_offline(phba->pcidev)))
4088 return IRQ_NONE;
4089
4090 phba->sli.slistat.sli_intr++;
4091
4092 /* 5263 /*
4093 * Call the HBA to see if it is interrupting. If not, don't claim 5264 * Stuff needs to be attented to when this function is invoked as an
4094 * the interrupt 5265 * individual interrupt handler in MSI-X multi-message interrupt mode
4095 */
4096
4097 /* Ignore all interrupts during initialization. */
4098 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
4099 return IRQ_NONE;
4100
4101 /*
4102 * Read host attention register to determine interrupt source
4103 * Clear Attention Sources, except Error Attention (to
4104 * preserve status) and Link Attention
4105 */
4106 spin_lock(&phba->hbalock);
4107 ha_copy = readl(phba->HAregaddr);
4108 /* If somebody is waiting to handle an eratt don't process it
4109 * here. The brdkill function will do this.
4110 */ 5266 */
4111 if (phba->link_flag & LS_IGNORE_ERATT) 5267 if (phba->intr_type == MSIX) {
4112 ha_copy &= ~HA_ERATT; 5268 /* If the pci channel is offline, ignore all the interrupts */
4113 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); 5269 if (unlikely(pci_channel_offline(phba->pcidev)))
4114 readl(phba->HAregaddr); /* flush */ 5270 return IRQ_NONE;
4115 spin_unlock(&phba->hbalock); 5271 /* Update device-level interrupt statistics */
4116 5272 phba->sli.slistat.sli_intr++;
4117 if (unlikely(!ha_copy)) 5273 /* Ignore all interrupts during initialization. */
4118 return IRQ_NONE; 5274 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5275 return IRQ_NONE;
5276 /* Need to read HA REG for slow-path events */
5277 spin_lock(&phba->hbalock);
5278 ha_copy = readl(phba->HAregaddr);
5279 /* If somebody is waiting to handle an eratt don't process it
5280 * here. The brdkill function will do this.
5281 */
5282 if (phba->link_flag & LS_IGNORE_ERATT)
5283 ha_copy &= ~HA_ERATT;
5284 /* Check the need for handling ERATT in interrupt handler */
5285 if (ha_copy & HA_ERATT) {
5286 if (phba->hba_flag & HBA_ERATT_HANDLED)
5287 /* ERATT polling has handled ERATT */
5288 ha_copy &= ~HA_ERATT;
5289 else
5290 /* Indicate interrupt handler handles ERATT */
5291 phba->hba_flag |= HBA_ERATT_HANDLED;
5292 }
5293 /* Clear up only attention source related to slow-path */
5294 writel((ha_copy & (HA_MBATT | HA_R2_CLR_MSK)),
5295 phba->HAregaddr);
5296 readl(phba->HAregaddr); /* flush */
5297 spin_unlock(&phba->hbalock);
5298 } else
5299 ha_copy = phba->ha_copy;
4119 5300
4120 work_ha_copy = ha_copy & phba->work_ha_mask; 5301 work_ha_copy = ha_copy & phba->work_ha_mask;
4121 5302
4122 if (unlikely(work_ha_copy)) { 5303 if (work_ha_copy) {
4123 if (work_ha_copy & HA_LATT) { 5304 if (work_ha_copy & HA_LATT) {
4124 if (phba->sli.sli_flag & LPFC_PROCESS_LA) { 5305 if (phba->sli.sli_flag & LPFC_PROCESS_LA) {
4125 /* 5306 /*
@@ -4138,7 +5319,7 @@ lpfc_intr_handler(int irq, void *dev_id)
4138 work_ha_copy &= ~HA_LATT; 5319 work_ha_copy &= ~HA_LATT;
4139 } 5320 }
4140 5321
4141 if (work_ha_copy & ~(HA_ERATT|HA_MBATT|HA_LATT)) { 5322 if (work_ha_copy & ~(HA_ERATT | HA_MBATT | HA_LATT)) {
4142 /* 5323 /*
4143 * Turn off Slow Rings interrupts, LPFC_ELS_RING is 5324 * Turn off Slow Rings interrupts, LPFC_ELS_RING is
4144 * the only slow ring. 5325 * the only slow ring.
@@ -4179,31 +5360,13 @@ lpfc_intr_handler(int irq, void *dev_id)
4179 spin_unlock(&phba->hbalock); 5360 spin_unlock(&phba->hbalock);
4180 } 5361 }
4181 } 5362 }
4182
4183 if (work_ha_copy & HA_ERATT) {
4184 /*
4185 * There was a link/board error. Read the
4186 * status register to retrieve the error event
4187 * and process it.
4188 */
4189 phba->sli.slistat.err_attn_event++;
4190 /* Save status info */
4191 phba->work_hs = readl(phba->HSregaddr);
4192 phba->work_status[0] = readl(phba->MBslimaddr + 0xa8);
4193 phba->work_status[1] = readl(phba->MBslimaddr + 0xac);
4194
4195 /* Clear Chip error bit */
4196 writel(HA_ERATT, phba->HAregaddr);
4197 readl(phba->HAregaddr); /* flush */
4198 phba->pport->stopped = 1;
4199 }
4200
4201 spin_lock(&phba->hbalock); 5363 spin_lock(&phba->hbalock);
4202 if ((work_ha_copy & HA_MBATT) && 5364 if (work_ha_copy & HA_ERATT)
4203 (phba->sli.mbox_active)) { 5365 lpfc_sli_read_hs(phba);
5366 if ((work_ha_copy & HA_MBATT) && (phba->sli.mbox_active)) {
4204 pmb = phba->sli.mbox_active; 5367 pmb = phba->sli.mbox_active;
4205 pmbox = &pmb->mb; 5368 pmbox = &pmb->mb;
4206 mbox = &phba->slim2p->mbx; 5369 mbox = phba->mbox;
4207 vport = pmb->vport; 5370 vport = pmb->vport;
4208 5371
4209 /* First check out the status word */ 5372 /* First check out the status word */
@@ -4270,7 +5433,7 @@ lpfc_intr_handler(int irq, void *dev_id)
4270 lpfc_printf_log(phba, 5433 lpfc_printf_log(phba,
4271 KERN_ERR, 5434 KERN_ERR,
4272 LOG_MBOX | LOG_SLI, 5435 LOG_MBOX | LOG_SLI,
4273 "0306 rc should have" 5436 "0350 rc should have"
4274 "been MBX_BUSY"); 5437 "been MBX_BUSY");
4275 goto send_current_mbox; 5438 goto send_current_mbox;
4276 } 5439 }
@@ -4283,6 +5446,7 @@ lpfc_intr_handler(int irq, void *dev_id)
4283 } 5446 }
4284 } else 5447 } else
4285 spin_unlock(&phba->hbalock); 5448 spin_unlock(&phba->hbalock);
5449
4286 if ((work_ha_copy & HA_MBATT) && 5450 if ((work_ha_copy & HA_MBATT) &&
4287 (phba->sli.mbox_active == NULL)) { 5451 (phba->sli.mbox_active == NULL)) {
4288send_current_mbox: 5452send_current_mbox:
@@ -4302,15 +5466,74 @@ send_current_mbox:
4302 spin_unlock(&phba->hbalock); 5466 spin_unlock(&phba->hbalock);
4303 lpfc_worker_wake_up(phba); 5467 lpfc_worker_wake_up(phba);
4304 } 5468 }
5469 return IRQ_HANDLED;
4305 5470
4306 ha_copy &= ~(phba->work_ha_mask); 5471} /* lpfc_sp_intr_handler */
5472
5473/**
5474 * lpfc_fp_intr_handler: The fast-path interrupt handler of lpfc driver.
5475 * @irq: Interrupt number.
5476 * @dev_id: The device context pointer.
5477 *
5478 * This function is directly called from the PCI layer as an interrupt
5479 * service routine when the device is enabled with MSI-X multi-message
5480 * interrupt mode and there is a fast-path FCP IOCB ring event in the
5481 * HBA. However, when the device is enabled with either MSI or Pin-IRQ
5482 * interrupt mode, this function is called as part of the device-level
5483 * interrupt handler. When the PCI slot is in error recovery or the HBA
5484 * is undergoing initialization, the interrupt handler will not process
5485 * the interrupt. The SCSI FCP fast-path ring event are handled in the
5486 * intrrupt context. This function is called without any lock held. It
5487 * gets the hbalock to access and update SLI data structures.
5488 *
5489 * This function returns IRQ_HANDLED when interrupt is handled else it
5490 * returns IRQ_NONE.
5491 **/
5492irqreturn_t
5493lpfc_fp_intr_handler(int irq, void *dev_id)
5494{
5495 struct lpfc_hba *phba;
5496 uint32_t ha_copy;
5497 unsigned long status;
5498
5499 /* Get the driver's phba structure from the dev_id and
5500 * assume the HBA is not interrupting.
5501 */
5502 phba = (struct lpfc_hba *) dev_id;
5503
5504 if (unlikely(!phba))
5505 return IRQ_NONE;
5506
5507 /*
5508 * Stuff needs to be attented to when this function is invoked as an
5509 * individual interrupt handler in MSI-X multi-message interrupt mode
5510 */
5511 if (phba->intr_type == MSIX) {
5512 /* If pci channel is offline, ignore all the interrupts */
5513 if (unlikely(pci_channel_offline(phba->pcidev)))
5514 return IRQ_NONE;
5515 /* Update device-level interrupt statistics */
5516 phba->sli.slistat.sli_intr++;
5517 /* Ignore all interrupts during initialization. */
5518 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5519 return IRQ_NONE;
5520 /* Need to read HA REG for FCP ring and other ring events */
5521 ha_copy = readl(phba->HAregaddr);
5522 /* Clear up only attention source related to fast-path */
5523 spin_lock(&phba->hbalock);
5524 writel((ha_copy & (HA_R0_CLR_MSK | HA_R1_CLR_MSK)),
5525 phba->HAregaddr);
5526 readl(phba->HAregaddr); /* flush */
5527 spin_unlock(&phba->hbalock);
5528 } else
5529 ha_copy = phba->ha_copy;
4307 5530
4308 /* 5531 /*
4309 * Process all events on FCP ring. Take the optimized path for 5532 * Process all events on FCP ring. Take the optimized path for FCP IO.
4310 * FCP IO. Any other IO is slow path and is handled by
4311 * the worker thread.
4312 */ 5533 */
4313 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING))); 5534 ha_copy &= ~(phba->work_ha_mask);
5535
5536 status = (ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
4314 status >>= (4*LPFC_FCP_RING); 5537 status >>= (4*LPFC_FCP_RING);
4315 if (status & HA_RXMASK) 5538 if (status & HA_RXMASK)
4316 lpfc_sli_handle_fast_ring_event(phba, 5539 lpfc_sli_handle_fast_ring_event(phba,
@@ -4319,11 +5542,10 @@ send_current_mbox:
4319 5542
4320 if (phba->cfg_multi_ring_support == 2) { 5543 if (phba->cfg_multi_ring_support == 2) {
4321 /* 5544 /*
4322 * Process all events on extra ring. Take the optimized path 5545 * Process all events on extra ring. Take the optimized path
4323 * for extra ring IO. Any other IO is slow path and is handled 5546 * for extra ring IO.
4324 * by the worker thread.
4325 */ 5547 */
4326 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING))); 5548 status = (ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
4327 status >>= (4*LPFC_EXTRA_RING); 5549 status >>= (4*LPFC_EXTRA_RING);
4328 if (status & HA_RXMASK) { 5550 if (status & HA_RXMASK) {
4329 lpfc_sli_handle_fast_ring_event(phba, 5551 lpfc_sli_handle_fast_ring_event(phba,
@@ -4332,5 +5554,106 @@ send_current_mbox:
4332 } 5554 }
4333 } 5555 }
4334 return IRQ_HANDLED; 5556 return IRQ_HANDLED;
5557} /* lpfc_fp_intr_handler */
5558
5559/**
5560 * lpfc_intr_handler: The device-level interrupt handler of lpfc driver.
5561 * @irq: Interrupt number.
5562 * @dev_id: The device context pointer.
5563 *
5564 * This function is the device-level interrupt handler called from the PCI
5565 * layer when either MSI or Pin-IRQ interrupt mode is enabled and there is
5566 * an event in the HBA which requires driver attention. This function
5567 * invokes the slow-path interrupt attention handling function and fast-path
5568 * interrupt attention handling function in turn to process the relevant
5569 * HBA attention events. This function is called without any lock held. It
5570 * gets the hbalock to access and update SLI data structures.
5571 *
5572 * This function returns IRQ_HANDLED when interrupt is handled, else it
5573 * returns IRQ_NONE.
5574 **/
5575irqreturn_t
5576lpfc_intr_handler(int irq, void *dev_id)
5577{
5578 struct lpfc_hba *phba;
5579 irqreturn_t sp_irq_rc, fp_irq_rc;
5580 unsigned long status1, status2;
5581
5582 /*
5583 * Get the driver's phba structure from the dev_id and
5584 * assume the HBA is not interrupting.
5585 */
5586 phba = (struct lpfc_hba *) dev_id;
5587
5588 if (unlikely(!phba))
5589 return IRQ_NONE;
5590
5591 /* If the pci channel is offline, ignore all the interrupts. */
5592 if (unlikely(pci_channel_offline(phba->pcidev)))
5593 return IRQ_NONE;
5594
5595 /* Update device level interrupt statistics */
5596 phba->sli.slistat.sli_intr++;
5597
5598 /* Ignore all interrupts during initialization. */
5599 if (unlikely(phba->link_state < LPFC_LINK_DOWN))
5600 return IRQ_NONE;
5601
5602 spin_lock(&phba->hbalock);
5603 phba->ha_copy = readl(phba->HAregaddr);
5604 if (unlikely(!phba->ha_copy)) {
5605 spin_unlock(&phba->hbalock);
5606 return IRQ_NONE;
5607 } else if (phba->ha_copy & HA_ERATT) {
5608 if (phba->hba_flag & HBA_ERATT_HANDLED)
5609 /* ERATT polling has handled ERATT */
5610 phba->ha_copy &= ~HA_ERATT;
5611 else
5612 /* Indicate interrupt handler handles ERATT */
5613 phba->hba_flag |= HBA_ERATT_HANDLED;
5614 }
5615
5616 /* Clear attention sources except link and error attentions */
5617 writel((phba->ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
5618 readl(phba->HAregaddr); /* flush */
5619 spin_unlock(&phba->hbalock);
5620
5621 /*
5622 * Invokes slow-path host attention interrupt handling as appropriate.
5623 */
5624
5625 /* status of events with mailbox and link attention */
5626 status1 = phba->ha_copy & (HA_MBATT | HA_LATT | HA_ERATT);
5627
5628 /* status of events with ELS ring */
5629 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
5630 status2 >>= (4*LPFC_ELS_RING);
5631
5632 if (status1 || (status2 & HA_RXMASK))
5633 sp_irq_rc = lpfc_sp_intr_handler(irq, dev_id);
5634 else
5635 sp_irq_rc = IRQ_NONE;
5636
5637 /*
5638 * Invoke fast-path host attention interrupt handling as appropriate.
5639 */
5640
5641 /* status of events with FCP ring */
5642 status1 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_FCP_RING)));
5643 status1 >>= (4*LPFC_FCP_RING);
5644
5645 /* status of events with extra ring */
5646 if (phba->cfg_multi_ring_support == 2) {
5647 status2 = (phba->ha_copy & (HA_RXMASK << (4*LPFC_EXTRA_RING)));
5648 status2 >>= (4*LPFC_EXTRA_RING);
5649 } else
5650 status2 = 0;
5651
5652 if ((status1 & HA_RXMASK) || (status2 & HA_RXMASK))
5653 fp_irq_rc = lpfc_fp_intr_handler(irq, dev_id);
5654 else
5655 fp_irq_rc = IRQ_NONE;
4335 5656
4336} /* lpfc_intr_handler */ 5657 /* Return device-level interrupt handling status */
5658 return (sp_irq_rc == IRQ_HANDLED) ? sp_irq_rc : fp_irq_rc;
5659} /* lpfc_intr_handler */