efct: Broadcom (Emulex) FC Target driver
Subsystems (2)
Re: [PATCH v3 17/31] elx: efct: Hardware queues creation and deletion
In reply to James SmartQuoted 48 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines for queue creation, deletion, and configuration.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Removed all Queue topology parsing code
Reworked queue creation code.--- drivers/scsi/elx/efct/efct_hw_queues.c | 765 +++++++++++++++++++++++++++++++++ 1 file changed, 765 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_hw_queues.cdrivers/scsi/elx/efct/efct_hw_queues.c new file +25
-0@@ -0,0 +1,765 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_hw.h" +#include "efct_unsol.h" + +/** +* SLI queues are created and initialized +*/ +enum efct_hw_rtn +efct_hw_init_queues (struct efct_hw *hw) +{ +struct hw_eq *eq =NULL ; +struct hw_cq *cq =NULL ; +struct hw_wq *wq =NULL ; +struct hw_rq *rq =NULL ; +struct hw_mq *mq =NULL ; + + hw->eq_count =0 ; + hw->cq_count =0 ; + hw->mq_count =0 ;
drivers/scsi/elx/efct/efct_hw_queues.c line 35
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ hw->wq_count =0 ; + hw->rq_count =0 ; + hw->hw_rq_count =0 ; +INIT_LIST_HEAD (&hw->eq_list); + +/* Create EQ */ + eq =efct_hw_new_eq (hw,EFCT_HW_EQ_DEPTH ); +if (!eq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ;
Not sure if it's worth to intorduce EFCT_HW_RTN_NO_MEMORY, because ENOMEM is pretty good match and ENOMEM is used in other places already.
Quoted 41 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +41
-0+ } + +/* Create RQ*/ + cq =efct_hw_new_cq (eq, hw->num_qentries[SLI_QTYPE_CQ ]); +if (!cq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + + rq =efct_hw_new_rq (cq,EFCT_HW_RQ_ENTRIES_DEF ); +if (!rq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* Create MQ*/ + cq =efct_hw_new_cq (eq, hw->num_qentries[SLI_QTYPE_CQ ]); +if (!cq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + + mq =efct_hw_new_mq (cq,EFCT_HW_MQ_DEPTH ); +if (!mq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* Create WQ */ + cq =efct_hw_new_cq (eq, hw->num_qentries[SLI_QTYPE_CQ ]); +if (!cq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } + + wq =efct_hw_new_wq (cq, hw->num_qentries[SLI_QTYPE_WQ ]); +if (!wq) { +efct_hw_queue_teardown (hw); +return EFCT_HW_RTN_NO_MEMORY ; + } +
drivers/scsi/elx/efct/efct_hw_queues.c line 86
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+return EFCT_HW_RTN_SUCCESS ; +} + +/* Allocate a new EQ object */ +struct hw_eq * +efct_hw_new_eq (struct efct_hw *hw,u32 entry_count) +{ +struct hw_eq *eq =kmalloc (sizeof (*eq),GFP_KERNEL ); + +if (eq) {
if (!eq) return NULL;
drivers/scsi/elx/efct/efct_hw_queues.c line 87
Quoted 1 line
drivers/scsi/elx/efct/efct_hw_queues.c new file +1
-0+memset (eq,0 ,sizeof (*eq));
kzalloc instead kmalloc + memset
Quoted 5 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +5
-0+ eq->type =SLI_QTYPE_EQ ; + eq->hw = hw; + eq->entry_count = entry_count; + eq->instance = hw->eq_count++; + eq->queue = &hw->eq[eq->instance];
drivers/scsi/elx/efct/efct_hw_queues.c line 102
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+INIT_LIST_HEAD (&eq->cq_list); + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_EQ , + eq->queue, + entry_count,NULL )) { +efc_log_err (hw->os, +"EQ[%d] allocation failure\n" , + eq->instance); +kfree (eq); + eq =NULL ;
return NULL;
Quoted 13 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +13
-0+ }else { +sli_eq_modify_delay (&hw->sli, eq->queue, +1 ,0 ,8 ); + hw->hw_eq[eq->instance] = eq; +INIT_LIST_HEAD (&eq->list_entry); +list_add_tail (&eq->list_entry, &hw->eq_list); +efc_log_debug (hw->os, +"create eq[%2d] id %3d len %4d\n" , + eq->instance, eq->queue->id, + eq->entry_count); + } + } +return eq;
drivers/scsi/elx/efct/efct_hw_queues.c line 125
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+} + +/* Allocate a new CQ object */ +struct hw_cq * +efct_hw_new_cq (struct hw_eq *eq,u32 entry_count) +{ +struct efct_hw *hw = eq->hw; +struct hw_cq *cq =kmalloc (sizeof (*cq),GFP_KERNEL ); + +if (cq) {
if (!cq) return NULL;
drivers/scsi/elx/efct/efct_hw_queues.c line 126
Quoted 1 line
drivers/scsi/elx/efct/efct_hw_queues.c new file +1
-0+memset (cq,0 ,sizeof (*cq));
kzalloc instead of kmalloc + memset
Quoted 6 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +6
-0+ cq->eq = eq; + cq->type =SLI_QTYPE_CQ ; + cq->instance = eq->hw->cq_count++; + cq->entry_count = entry_count; + cq->queue = &hw->cq[cq->instance]; +
drivers/scsi/elx/efct/efct_hw_queues.c line 142
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+INIT_LIST_HEAD (&cq->q_list); + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_CQ , cq->queue, + cq->entry_count, eq->queue)) { +efc_log_err (hw->os, +"CQ[%d] allocation failure len=%d\n" , + eq->instance, + eq->entry_count); +kfree (cq); + cq =NULL ;
return NULL;
Quoted 25 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +25
-0+ }else { + hw->hw_cq[cq->instance] = cq; +INIT_LIST_HEAD (&cq->list_entry); +list_add_tail (&cq->list_entry, &eq->cq_list); +efc_log_debug (hw->os, +"create cq[%2d] id %3d len %4d\n" , + cq->instance, cq->queue->id, + cq->entry_count); + } + } +return cq; +} + +/* Allocate a new CQ Set of objects */ +u32 +efct_hw_new_cq_set (struct hw_eq *eqs[],struct hw_cq *cqs[], +u32 num_cqs,u32 entry_count) +{ +u32 i; +struct efct_hw *hw = eqs[0 ]->hw; +struct sli4 *sli4 = &hw->sli; +struct hw_cq *cq =NULL ; +struct sli4_queue *qs[SLI_MAX_CQ_SET_COUNT ]; +struct sli4_queue *assefct[SLI_MAX_CQ_SET_COUNT ]; +
drivers/scsi/elx/efct/efct_hw_queues.c line 177
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+/* Initialise CQS pointers to NULL */ +for (i =0 ; i < num_cqs; i++) + cqs[i] =NULL ; + +for (i =0 ; i < num_cqs; i++) { + cq =kmalloc (sizeof (*cq),GFP_KERNEL ); +if (!cq) + goto error; + +memset (cq,0 ,sizeof (*cq));
kzalloc()
Quoted 17 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +17
-0+ cqs[i] = cq; + cq->eq = eqs[i]; + cq->type =SLI_QTYPE_CQ ; + cq->instance = hw->cq_count++; + cq->entry_count = entry_count; + cq->queue = &hw->cq[cq->instance]; + qs[i] = cq->queue; + assefct[i] = eqs[i]->queue; +INIT_LIST_HEAD (&cq->q_list); + } + +if (!sli_cq_alloc_set (sli4, qs, num_cqs, entry_count, assefct)) { +efc_log_err (hw->os,"Failed to create CQ Set.\n" ); + goto error; + } + +for (i =0 ; i < num_cqs; i++) {
drivers/scsi/elx/efct/efct_hw_queues.c line 204
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ hw->hw_cq[cqs[i]->instance] = cqs[i]; +INIT_LIST_HEAD (&cqs[i]->list_entry); +list_add_tail (&cqs[i]->list_entry, &cqs[i]->eq->cq_list); + } + +return EFC_SUCCESS ; + +error: +for (i =0 ; i < num_cqs; i++) { +kfree (cqs[i]);
if (cqs[i]) kfree(cqs[i]);
drivers/scsi/elx/efct/efct_hw_queues.c line 217
Quoted 13 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +13
-0+ cqs[i] =NULL ; + } +return EFC_FAIL ; +} + +/* Allocate a new MQ object */ +struct hw_mq * +efct_hw_new_mq (struct hw_cq *cq,u32 entry_count) +{ +struct efct_hw *hw = cq->eq->hw; +struct hw_mq *mq =kmalloc (sizeof (*mq),GFP_KERNEL ); + +if (mq) {
if (!mq)
return
drivers/scsi/elx/efct/efct_hw_queues.c line 218
Quoted 1 line
drivers/scsi/elx/efct/efct_hw_queues.c new file +1
-0+memset (mq,0 ,sizeof (*mq));
kzalloc
Quoted 26 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +26
-0+ mq->cq = cq; + mq->type =SLI_QTYPE_MQ ; + mq->instance = cq->eq->hw->mq_count++; + mq->entry_count = entry_count; + mq->entry_size =EFCT_HW_MQ_DEPTH ; + mq->queue = &hw->mq[mq->instance]; + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_MQ , + mq->queue, + mq->entry_size, + cq->queue)) { +efc_log_err (hw->os,"MQ allocation failure\n" ); +kfree (mq); + mq =NULL ; + }else { + hw->hw_mq[mq->instance] = mq; +INIT_LIST_HEAD (&mq->list_entry); +list_add_tail (&mq->list_entry, &cq->q_list); +efc_log_debug (hw->os, +"create mq[%2d] id %3d len %4d\n" , + mq->instance, mq->queue->id, + mq->entry_count); + } + } +return mq; +}
drivers/scsi/elx/efct/efct_hw_queues.c line 254
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ +/* Allocate a new WQ object */ +struct hw_wq * +efct_hw_new_wq (struct hw_cq *cq,u32 entry_count) +{ +struct efct_hw *hw = cq->eq->hw; +struct hw_wq *wq =kmalloc (sizeof (*wq),GFP_KERNEL ); + +if (wq) { +memset (wq,0 ,sizeof (*wq));
same above
Quoted 6 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +6
-0+ wq->hw = cq->eq->hw; + wq->cq = cq; + wq->type =SLI_QTYPE_WQ ; + wq->instance = cq->eq->hw->wq_count++; + wq->entry_count = entry_count; + wq->queue = &hw->wq[wq->instance];
drivers/scsi/elx/efct/efct_hw_queues.c line 270
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ wq->wqec_set_count =EFCT_HW_WQEC_SET_COUNT ; + wq->wqec_count = wq->wqec_set_count; + wq->free_count = wq->entry_count -1 ; +INIT_LIST_HEAD (&wq->pending_list); + +if (sli_queue_alloc (&hw->sli,SLI_QTYPE_WQ , wq->queue, + wq->entry_count, cq->queue)) { +efc_log_err (hw->os,"WQ allocation failure\n" ); +kfree (wq); + wq =NULL ;
return NULL;
Quoted 12 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +12
-0+ }else { + hw->hw_wq[wq->instance] = wq; +INIT_LIST_HEAD (&wq->list_entry); +list_add_tail (&wq->list_entry, &cq->q_list); +efc_log_debug (hw->os, +"create wq[%2d] id %3d len %4d cls %d\n" , + wq->instance, wq->queue->id, + wq->entry_count, wq->class); + } + } +return wq; +}
drivers/scsi/elx/efct/efct_hw_queues.c line 292
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ +/* Allocate an RQ object, which encapsulates 2 SLI queues (for rq pair) */ +struct hw_rq * +efct_hw_new_rq (struct hw_cq *cq,u32 entry_count) +{ +struct efct_hw *hw = cq->eq->hw; +struct hw_rq *rq =kmalloc (sizeof (*rq),GFP_KERNEL ); + +if (rq) { +memset (rq,0 ,sizeof (*rq));
and again :)
Quoted 78 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +78
-0+ rq->instance = hw->hw_rq_count++; + rq->cq = cq; + rq->type =SLI_QTYPE_RQ ; + rq->entry_count = entry_count; + +/* Create the header RQ */ + rq->hdr = &hw->rq[hw->rq_count]; + rq->hdr_entry_size =EFCT_HW_RQ_HEADER_SIZE ; + +if (sli_fc_rq_alloc (&hw->sli, rq->hdr, + rq->entry_count, + rq->hdr_entry_size, + cq->queue, + true)) { +efc_log_err (hw->os, +"RQ allocation failure - header\n" ); +kfree (rq); +return NULL ; + } +/* Update hw_rq_lookup[] */ + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; +efc_log_debug (hw->os, +"create rq[%2d] id %3d len %4d hdr size %4d\n" , + rq->instance, rq->hdr->id, rq->entry_count, + rq->hdr_entry_size); + +/* Create the default data RQ */ + rq->data = &hw->rq[hw->rq_count]; + rq->data_entry_size = hw->config.rq_default_buffer_size; + +if (sli_fc_rq_alloc (&hw->sli, rq->data, + rq->entry_count, + rq->data_entry_size, + cq->queue, + false)) { +efc_log_err (hw->os, +"RQ allocation failure - first burst\n" ); +kfree (rq); +return NULL ; + } +/* Update hw_rq_lookup[] */ + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; +efc_log_debug (hw->os, +"create rq[%2d] id %3d len %4d data size %4d\n" , + rq->instance, rq->data->id, rq->entry_count, + rq->data_entry_size); + + hw->hw_rq[rq->instance] = rq; +INIT_LIST_HEAD (&rq->list_entry); +list_add_tail (&rq->list_entry, &cq->q_list); + + rq->rq_tracker =kmalloc_array (rq->entry_count, +sizeof (struct efc_hw_sequence *), +GFP_ATOMIC ); +if (!rq->rq_tracker) +return NULL ; + +memset (rq->rq_tracker,0 , + rq->entry_count *sizeof (struct efc_hw_sequence *)); + } +return rq; +} + +/** +* Allocate an RQ object SET, where each element in set +* encapsulates 2 SLI queues (for rq pair) +*/ +u32 +efct_hw_new_rq_set (struct hw_cq *cqs[],struct hw_rq *rqs[], +u32 num_rq_pairs,u32 entry_count) +{ +struct efct_hw *hw = cqs[0 ]->eq->hw; +struct hw_rq *rq =NULL ; +struct sli4_queue *qs[SLI_MAX_RQ_SET_COUNT *2 ] = {NULL }; +u32 i, q_count, size; +
drivers/scsi/elx/efct/efct_hw_queues.c line 380
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+/* Initialise RQS pointers */ +for (i =0 ; i < num_rq_pairs; i++) + rqs[i] =NULL ; + +for (i =0 , q_count =0 ; i < num_rq_pairs; i++, q_count +=2 ) { + rq =kmalloc (sizeof (*rq),GFP_KERNEL ); +if (!rq) + goto error; + +memset (rq,0 ,sizeof (*rq));
kzalloc
Quoted 40 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +40
-0+ rqs[i] = rq; + rq->instance = hw->hw_rq_count++; + rq->cq = cqs[i]; + rq->type =SLI_QTYPE_RQ ; + rq->entry_count = entry_count; + +/* Header RQ */ + rq->hdr = &hw->rq[hw->rq_count]; + rq->hdr_entry_size =EFCT_HW_RQ_HEADER_SIZE ; + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; + qs[q_count] = rq->hdr; + +/* Data RQ */ + rq->data = &hw->rq[hw->rq_count]; + rq->data_entry_size = hw->config.rq_default_buffer_size; + hw->hw_rq_lookup[hw->rq_count] = rq->instance; + hw->rq_count++; + qs[q_count +1 ] = rq->data; + + rq->rq_tracker =NULL ; + } + +if (!sli_fc_rq_set_alloc (&hw->sli, num_rq_pairs, qs, + cqs[0 ]->queue->id, + rqs[0 ]->entry_count, + rqs[0 ]->hdr_entry_size, + rqs[0 ]->data_entry_size)) { +efc_log_err (hw->os, +"RQ Set allocation failure for base CQ=%d\n" , + cqs[0 ]->queue->id); + goto error; + } + +for (i =0 ; i < num_rq_pairs; i++) { + hw->hw_rq[rqs[i]->instance] = rqs[i]; +INIT_LIST_HEAD (&rqs[i]->list_entry); +list_add_tail (&rqs[i]->list_entry, &cqs[i]->q_list); + size =sizeof (struct efc_hw_sequence *) * rqs[i]->entry_count; + rqs[i]->rq_tracker =kmalloc (size,GFP_KERNEL );
drivers/scsi/elx/efct/efct_hw_queues.c line 430
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+if (!rqs[i]->rq_tracker) + goto error; + } + +return EFC_SUCCESS ; + +error: +for (i =0 ; i < num_rq_pairs; i++) { +if (rqs[i]) { +kfree (rqs[i]->rq_tracker);
Is rq_tracker always a valid pointer?
Quoted 16 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +16
-0+kfree (rqs[i]); + } + } + +return EFC_FAIL ; +} + +void +efct_hw_del_eq (struct hw_eq *eq) +{ +if (eq) { +struct hw_cq *cq; +struct hw_cq *cq_next; + +list_for_each_entry_safe (cq, cq_next, &eq->cq_list, list_entry) +efct_hw_del_cq (cq);
drivers/scsi/elx/efct/efct_hw_queues.c line 456
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+list_del (&eq->list_entry); + eq->hw->hw_eq[eq->instance] =NULL ; +kfree (eq); + } +} + +void +efct_hw_del_cq (struct hw_cq *cq) +{ +if (cq) {
if (!cq)
return;
Quoted 18 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +18
-0+struct hw_q *q; +struct hw_q *q_next; + +list_for_each_entry_safe (q, q_next, &cq->q_list, list_entry) { +switch (q->type) { +case SLI_QTYPE_MQ : +efct_hw_del_mq ((struct hw_mq *)q); +break ; +case SLI_QTYPE_WQ : +efct_hw_del_wq ((struct hw_wq *)q); +break ; +case SLI_QTYPE_RQ : +efct_hw_del_rq ((struct hw_rq *)q); +break ; +default : +break ; + } + }
drivers/scsi/elx/efct/efct_hw_queues.c line 484
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+list_del (&cq->list_entry); + cq->eq->hw->hw_cq[cq->instance] =NULL ; +kfree (cq); + } +} + +void +efct_hw_del_mq (struct hw_mq *mq) +{ +if (mq) {
if (!mq)
return;
drivers/scsi/elx/efct/efct_hw_queues.c line 494
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+list_del (&mq->list_entry); + mq->cq->eq->hw->hw_mq[mq->instance] =NULL ; +kfree (mq); + } +} + +void +efct_hw_del_wq (struct hw_wq *wq) +{ +if (wq) {
if (!wq)
return;
drivers/scsi/elx/efct/efct_hw_queues.c line 506
Quoted 12 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +12
-0+list_del (&wq->list_entry); + wq->cq->eq->hw->hw_wq[wq->instance] =NULL ; +kfree (wq); + } +} + +void +efct_hw_del_rq (struct hw_rq *rq) +{ +struct efct_hw *hw =NULL ; + +if (rq) {
if (!rq)
return;
Quoted 41 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +41
-0+/* Free RQ tracker */ +kfree (rq->rq_tracker); + rq->rq_tracker =NULL ; +list_del (&rq->list_entry); + hw = rq->cq->eq->hw; + hw->hw_rq[rq->instance] =NULL ; +kfree (rq); + } +} + +void +efct_hw_queue_dump (struct efct_hw *hw) +{ +struct hw_eq *eq; +struct hw_cq *cq; +struct hw_q *q; +struct hw_mq *mq; +struct hw_wq *wq; +struct hw_rq *rq; + +list_for_each_entry (eq, &hw->eq_list, list_entry) { +efc_log_debug (hw->os,"eq[%d] id %2d\n" , + eq->instance, eq->queue->id); +list_for_each_entry (cq, &eq->cq_list, list_entry) { +efc_log_debug (hw->os,"cq[%d] id %2d current\n" , + cq->instance, cq->queue->id); +list_for_each_entry (q, &cq->q_list, list_entry) { +switch (q->type) { +case SLI_QTYPE_MQ : + mq = (struct hw_mq *)q; +efc_log_debug (hw->os, +" mq[%d] id %2d\n" , + mq->instance, mq->queue->id); +break ; +case SLI_QTYPE_WQ : + wq = (struct hw_wq *)q; +efc_log_debug (hw->os, +" wq[%d] id %2d\n" , + wq->instance, wq->queue->id); +break ; +case SLI_QTYPE_RQ :
drivers/scsi/elx/efct/efct_hw_queues.c line 557
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ rq = (struct hw_rq *)q; +efc_log_debug (hw->os, +" rq[%d] hdr id %2d\n" , + rq->instance, rq->hdr->id); +break ; +default : +break ; + } + } + }
Maybe move inner loop into function.
drivers/scsi/elx/efct/efct_hw_queues.c line 567
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ } +} + +void +efct_hw_queue_teardown (struct efct_hw *hw) +{ +struct hw_eq *eq; +struct hw_eq *eq_next; + +if (hw->eq_list.next) {
if (!hw->eq_list.next) return;
Quoted 46 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +46
-0+list_for_each_entry_safe (eq, eq_next, &hw->eq_list, + list_entry) { +efct_hw_del_eq (eq); + } + } +} + +static inline int +efct_hw_rqpair_find (struct efct_hw *hw,u16 rq_id) +{ +return efct_hw_queue_hash_find (hw->rq_hash, rq_id); +} + +static struct efc_hw_sequence * +efct_hw_rqpair_get (struct efct_hw *hw,u16 rqindex,u16 bufindex) +{ +struct sli4_queue *rq_hdr = &hw->rq[rqindex]; +struct efc_hw_sequence *seq =NULL ; +struct hw_rq *rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; +unsigned long flags =0 ; + +if (bufindex >= rq_hdr->length) { +efc_log_err (hw->os, +"RQidx %d bufidx %d exceed ring len %d for id %d\n" , + rqindex, bufindex, rq_hdr->length, rq_hdr->id); +return NULL ; + } + +/* rq_hdr lock also covers rqindex+1 queue */ +spin_lock_irqsave (&rq_hdr->lock, flags); + + seq = rq->rq_tracker[bufindex]; + rq->rq_tracker[bufindex] =NULL ; + +if (!seq) { +efc_log_err (hw->os, +"RQbuf NULL, rqidx %d, bufidx %d, cur q idx = %d\n" , + rqindex, bufindex, rq_hdr->index); + } + +spin_unlock_irqrestore (&rq_hdr->lock, flags); +return seq; +} + +int +efct_hw_rqpair_process_rq(struct efct_hw *hw, struct hw_cq *cq,
drivers/scsi/elx/efct/efct_hw_queues.c line 623
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+ u8 *cqe) +{ +u16 rq_id; +u32 index; +int rqindex; +int rq_status; +u32 h_len; +u32 p_len; +struct efc_hw_sequence *seq; +struct hw_rq *rq;
the alignemnt of the variables is inconsistent
Quoted 74 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +74
-0+ + rq_status =sli_fc_rqe_rqid_and_index (&hw->sli, cqe, + &rq_id, &index); +if (rq_status !=0 ) { +switch (rq_status) { +case SLI4_FC_ASYNC_RQ_BUF_LEN_EXCEEDED : +case SLI4_FC_ASYNC_RQ_DMA_FAILURE : +/* just get RQ buffer then return to chip */ + rqindex =efct_hw_rqpair_find (hw, rq_id); +if (rqindex <0 ) { +efc_log_test (hw->os, +"status=%#x: lookup fail id=%#x\n" , + rq_status, rq_id); +break ; + } + +/* get RQ buffer */ + seq =efct_hw_rqpair_get (hw, rqindex, index); + +/* return to chip */ +if (efct_hw_rqpair_sequence_free (hw, seq)) { +efc_log_test (hw->os, +"status=%#x,fail rtrn buf to RQ\n" , + rq_status); +break ; + } +break ; +case SLI4_FC_ASYNC_RQ_INSUFF_BUF_NEEDED : +case SLI4_FC_ASYNC_RQ_INSUFF_BUF_FRM_DISC : +/* +* since RQ buffers were not consumed, cannot return +* them to chip +* fall through +*/ +efc_log_debug (hw->os,"Warning: RCQE status=%#x,\n" , + rq_status); +default : +break ; + } +return EFC_FAIL ; + } + + rqindex =efct_hw_rqpair_find (hw, rq_id); +if (rqindex <0 ) { +efc_log_test (hw->os,"Error: rq_id lookup failed for id=%#x\n" , + rq_id); +return EFC_FAIL ; + } + + rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; + rq->use_count++; + + seq =efct_hw_rqpair_get (hw, rqindex, index); +if (WARN_ON (!seq)) +return EFC_FAIL ; + + seq->hw = hw; + seq->auto_xrdy =0 ; + seq->out_of_xris =0 ; + seq->hio =NULL ; + +sli_fc_rqe_length (&hw->sli, cqe, &h_len, &p_len); + seq->header->dma.len = h_len; + seq->payload->dma.len = p_len; + seq->fcfi =sli_fc_rqe_fcfi (&hw->sli, cqe); + seq->hw_priv = cq->eq; + +efct_unsolicited_cb (hw->os, seq); + +return EFC_SUCCESS ; +} + +static int +efct_hw_rqpair_put (struct efct_hw *hw,struct efc_hw_sequence *seq)
drivers/scsi/elx/efct/efct_hw_queues.c line 707
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +10
-0+{ +struct sli4_queue *rq_hdr = &hw->rq[seq->header->rqindex]; +struct sli4_queue *rq_payload = &hw->rq[seq->payload->rqindex]; +u32 hw_rq_index = hw->hw_rq_lookup[seq->header->rqindex]; +struct hw_rq *rq = hw->hw_rq[hw_rq_index]; +u32 phys_hdr[2 ]; +u32 phys_payload[2 ]; +int qindex_hdr; +int qindex_payload; +unsigned long flags =0 ;
the alignemnt of the variables is inconsistent
Quoted 61 lines
drivers/scsi/elx/efct/efct_hw_queues.c new file +58
-0+ +/* Update the RQ verification lookup tables */ + phys_hdr[0 ] =upper_32_bits (seq->header->dma.phys); + phys_hdr[1 ] =lower_32_bits (seq->header->dma.phys); + phys_payload[0 ] =upper_32_bits (seq->payload->dma.phys); + phys_payload[1 ] =lower_32_bits (seq->payload->dma.phys); + +/* rq_hdr lock also covers payload / header->rqindex+1 queue */ +spin_lock_irqsave (&rq_hdr->lock, flags); + +/* +* Note: The header must be posted last for buffer pair mode because +* posting on the header queue posts the payload queue as well. +* We do not ring the payload queue independently in RQ pair mode. +*/ + qindex_payload =sli_rq_write (&hw->sli, rq_payload, + (void *)phys_payload); + qindex_hdr =sli_rq_write (&hw->sli, rq_hdr, (void *)phys_hdr); +if (qindex_hdr <0 || + qindex_payload <0 ) { +efc_log_err (hw->os,"RQ_ID=%#x write failed\n" , rq_hdr->id); +spin_unlock_irqrestore (&rq_hdr->lock, flags); +return EFCT_HW_RTN_ERROR ; + } + +/* ensure the indexes are the same */ +WARN_ON (qindex_hdr != qindex_payload); + +/* Update the lookup table */ +if (!rq->rq_tracker[qindex_hdr]) { + rq->rq_tracker[qindex_hdr] = seq; + }else { +efc_log_test (hw->os, +"expected rq_tracker[%d][%d] buffer to be NULL\n" , + hw_rq_index, qindex_hdr); + } + +spin_unlock_irqrestore (&rq_hdr->lock, flags); +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_rqpair_sequence_free (struct efct_hw *hw, +struct efc_hw_sequence *seq) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; + +/* +* Post the data buffer first. Because in RQ pair mode, ringing the +* doorbell of the header ring will post the data buffer as well. +*/ +if (efct_hw_rqpair_put (hw, seq)) { +efc_log_err (hw->os,"error writing buffers\n" ); +return EFCT_HW_RTN_ERROR ; + } + +return rc; +}Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 18/31 elx: efct: RQ buffer, memory pool allocation and deallocation APIs
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
RQ data buffer allocation and deallocate. Memory pool allocation and deallocation APIs. Mailbox command submission and completion routines.
---
v3:
efct_utils.c file is removed. Replaced efct_pool, efct_varray and efct_array with other alternatives.
--- drivers/scsi/elx/efct/efct_hw.c | 375 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 7 + 2 files changed, 382 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +375 -0
@@ -1114,3 +1114,378 @@ efct_get_wwpn(struct efct_hw *hw)memcpy (p, sli->wwpn,sizeof (p));return get_unaligned_be64 (p); } + +/* +* An efct_hw_rx_buffer_t array is allocated, +* along with the required DMA mem +*/ +static struct efc_hw_rq_buffer * +efct_hw_rx_buffer_alloc (struct efct_hw *hw,u32 rqindex,u32 count, +u32 size) +{ +struct efct *efct = hw->os; +struct efc_hw_rq_buffer *rq_buf =NULL ; +struct efc_hw_rq_buffer *prq; +u32 i; + +if (count !=0 ) { + rq_buf =kmalloc_array (count,sizeof (*rq_buf),GFP_ATOMIC ); +if (!rq_buf) +return NULL ; +memset (rq_buf,0 ,sizeof (*rq_buf) * count); + +for (i =0 , prq = rq_buf; i < count; i ++, prq++) { + prq->rqindex = rqindex; + prq->dma.size = size; + prq->dma.virt =dma_alloc_coherent (&efct->pcidev->dev, + prq->dma.size, + &prq->dma.phys, +GFP_DMA ); +if (!prq->dma.virt) { +efc_log_err (hw->os,"DMA allocation failed\n" ); +kfree (rq_buf); + rq_buf =NULL ; +break ; + } + } + } +return rq_buf; +} + +static void +efct_hw_rx_buffer_free (struct efct_hw *hw, +struct efc_hw_rq_buffer *rq_buf, +u32 count) +{ +struct efct *efct = hw->os; +u32 i; +struct efc_hw_rq_buffer *prq; + +if (rq_buf) { +for (i =0 , prq = rq_buf; i < count; i++, prq++) { +dma_free_coherent (&efct->pcidev->dev, + prq->dma.size, prq->dma.virt, + prq->dma.phys); +memset (&prq->dma,0 ,sizeof (struct efc_dma )); + } + +kfree (rq_buf); + } +} + +enum efct_hw_rtn +efct_hw_rx_allocate (struct efct_hw *hw) +{ +struct efct *efct = hw->os; +u32 i; +int rc =EFCT_HW_RTN_SUCCESS ; +u32 rqindex =0 ; +struct hw_rq *rq; +u32 hdr_size =EFCT_HW_RQ_SIZE_HDR ; +u32 payload_size = hw->config.rq_default_buffer_size; + + rqindex =0 ; + +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; + +/* Allocate header buffers */ + rq->hdr_buf =efct_hw_rx_buffer_alloc (hw, rqindex, + rq->entry_count, + hdr_size); +if (!rq->hdr_buf) { +efc_log_err (efct, +"efct_hw_rx_buffer_alloc hdr_buf failed\n" ); + rc =EFCT_HW_RTN_ERROR ; +break ; + } + +efc_log_debug (hw->os, +"rq[%2d] rq_id %02d header %4d by %4d bytes\n" , + i, rq->hdr->id, rq->entry_count, hdr_size); + + rqindex++; + +/* Allocate payload buffers */ + rq->payload_buf =efct_hw_rx_buffer_alloc (hw, rqindex, + rq->entry_count, + payload_size); +if (!rq->payload_buf) { +efc_log_err (efct, +"efct_hw_rx_buffer_alloc fb_buf failed\n" ); + rc =EFCT_HW_RTN_ERROR ; +break ; + } +efc_log_debug (hw->os, +"rq[%2d] rq_id %02d default %4d by %4d bytes\n" , + i, rq->data->id, rq->entry_count, payload_size); + rqindex++; + } + +return rc ?EFCT_HW_RTN_ERROR :EFCT_HW_RTN_SUCCESS ; +} + +/* Post the RQ data buffers to the chip */ +enum efct_hw_rtn +efct_hw_rx_post (struct efct_hw *hw) +{ +u32 i; +u32 idx; +u32 rq_idx; +int rc =0 ; + +if (!hw->seq_pool) { +u32 count =0 ; + +for (i =0 ; i < hw->hw_rq_count; i++) + count += hw->hw_rq[i]->entry_count; + + hw->seq_pool =kmalloc_array (count, +sizeof (struct efc_hw_sequence ),GFP_KERNEL ); +if (!hw->seq_pool) +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* +* In RQ pair mode, we MUST post the header and payload buffer at the +* same time. +*/ +for (rq_idx =0 , idx =0 ; rq_idx < hw->hw_rq_count; rq_idx++) { +struct hw_rq *rq = hw->hw_rq[rq_idx]; + +for (i =0 ; i < rq->entry_count -1 ; i++) { +struct efc_hw_sequence *seq; + + seq = hw->seq_pool + idx *sizeof (*seq); +if (!seq) { + rc =-1 ; +break ; + } + idx++; + seq->header = &rq->hdr_buf[i]; + seq->payload = &rq->payload_buf[i]; + rc =efct_hw_sequence_free (hw, seq); +if (rc) +break ; + } +if (rc) +break ; + } + +if (rc && hw->seq_pool) +kfree (hw->seq_pool); + +return rc; +} + +void +efct_hw_rx_free (struct efct_hw *hw) +{ +struct hw_rq *rq; +u32 i; + +/* Free hw_rq buffers */ +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; +if (rq) { +efct_hw_rx_buffer_free (hw, rq->hdr_buf, + rq->entry_count); + rq->hdr_buf =NULL ; +efct_hw_rx_buffer_free (hw, rq->payload_buf, + rq->entry_count); + rq->payload_buf =NULL ; + } + } +} + +static int +efct_hw_cmd_submit_pending (struct efct_hw *hw) +{ +struct efct_command_ctx *ctx =NULL ; +int rc =0 ; + +/* Assumes lock held */ + +/* Only submit MQE if there's room */ +while (hw->cmd_head_count < (EFCT_HW_MQ_DEPTH -1 ) && + !list_empty (&hw->cmd_pending)) { + ctx =list_first_entry (&hw->cmd_pending, + struct efct_command_ctx, list_entry); +if (!ctx) +break ; + +list_del (&ctx->list_entry); + +INIT_LIST_HEAD (&ctx->list_entry); +list_add_tail (&ctx->list_entry, &hw->cmd_head); + hw->cmd_head_count++; +if (sli_mq_write (&hw->sli, hw->mq, ctx->buf) <0 ) { +efc_log_test (hw->os, +"sli_queue_write failed: %d\n" , rc); + rc =-1 ; +break ; + } + } +return rc; +} + +/* +* Send a mailbox command to the hardware, and either wait for a completion +* (EFCT_CMD_POLL) or get an optional asynchronous completion (EFCT_CMD_NOWAIT). +*/ +enum efct_hw_rtn +efct_hw_command (struct efct_hw *hw,u8 *cmd,u32 opts,void *cb,void *arg) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_ERROR ; +unsigned long flags =0 ; +void *bmbx =NULL ; + +/* +* If the chip is in an error state (UE'd) then reject this mailbox +* command. +*/ +if (sli_fw_error_status (&hw->sli) >0 ) { +efc_log_crit (hw->os, +"Chip is in an error state - reset needed\n" ); +efc_log_crit (hw->os, +"status=%#x error1=%#x error2=%#x\n" , +sli_reg_read_status (&hw->sli), +sli_reg_read_err1 (&hw->sli), +sli_reg_read_err2 (&hw->sli)); + +return EFCT_HW_RTN_ERROR ; + } + +if (opts ==EFCT_CMD_POLL ) { +spin_lock_irqsave (&hw->cmd_lock, flags); + bmbx = hw->sli.bmbx.virt; + +memset (bmbx,0 ,SLI4_BMBX_SIZE ); +memcpy (bmbx, cmd,SLI4_BMBX_SIZE ); + +if (sli_bmbx_command (&hw->sli) ==0 ) { + rc =EFCT_HW_RTN_SUCCESS ; +memcpy (cmd, bmbx,SLI4_BMBX_SIZE ); + } +spin_unlock_irqrestore (&hw->cmd_lock, flags); + }else if (opts ==EFCT_CMD_NOWAIT ) { +struct efct_command_ctx *ctx =NULL ; + + ctx =kmalloc (sizeof (*ctx),GFP_ATOMIC ); +if (!ctx) +return EFCT_HW_RTN_NO_RESOURCES ; + +memset (ctx,0 ,sizeof (struct efct_command_ctx )); + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os, +"Can't send command, HW state=%d\n" , + hw->state); +kfree (ctx); +return EFCT_HW_RTN_ERROR ; + } + +if (cb) { + ctx->cb = cb; + ctx->arg = arg; + } + ctx->buf = cmd; + ctx->ctx = hw; + +spin_lock_irqsave (&hw->cmd_lock, flags); + +/* Add to pending list */ +INIT_LIST_HEAD (&ctx->list_entry); +list_add_tail (&ctx->list_entry, &hw->cmd_pending); + +/* Submit as much of the pending list as we can */ +if (efct_hw_cmd_submit_pending (hw) ==0 ) + rc =EFCT_HW_RTN_SUCCESS ; + +spin_unlock_irqrestore (&hw->cmd_lock, flags); + } + +return rc; +} + +static int +efct_hw_command_process (struct efct_hw *hw,int status,u8 *mqe, +size_t size) +{ +struct efct_command_ctx *ctx =NULL ; +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->cmd_lock, flags); +if (!list_empty (&hw->cmd_head)) { + ctx =list_first_entry (&hw->cmd_head, + struct efct_command_ctx, list_entry); +list_del (&ctx->list_entry); + } +if (!ctx) { +efc_log_err (hw->os,"no command context?!?\n" ); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +return EFC_FAIL ; + } + + hw->cmd_head_count--; + +/* Post any pending requests */ +efct_hw_cmd_submit_pending (hw); + +spin_unlock_irqrestore (&hw->cmd_lock, flags); + +if (ctx->cb) { +if (ctx->buf) +memcpy (ctx->buf, mqe, size); + + ctx->cb (hw, status, ctx->buf, ctx->arg); + } + +memset (ctx,0 ,sizeof (struct efct_command_ctx )); +kfree (ctx); + +return EFC_SUCCESS ; +} + +static int +efct_hw_mq_process (struct efct_hw *hw, +int status,struct sli4_queue *mq) +{ +u8 mqe[SLI4_BMBX_SIZE ]; + +if (!sli_mq_read (&hw->sli, mq, mqe)) +efct_hw_command_process (hw, status, mqe, mq->size); + +return EFC_SUCCESS ; +} + +static int +efct_hw_command_cancel (struct efct_hw *hw) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->cmd_lock, flags); + +/* +* Manually clean up remaining commands. Note: since this calls +* efct_hw_command_process(), we'll also process the cmd_pending +* list, so no need to manually clean that out. +*/ +while (!list_empty (&hw->cmd_head)) { +u8 mqe[SLI4_BMBX_SIZE ] = {0 }; +struct efct_command_ctx *ctx = + list_first_entry(&hw->cmd_head, struct efct_command_ctx, list_entry); + +efc_log_test (hw->os,"hung command %08x\n" , + !ctx ?U32_MAX : + (!ctx->buf ?U32_MAX : + *((u32 *)ctx->buf))); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +efct_hw_command_process (hw,-1 , mqe,SLI4_BMBX_SIZE ); +spin_lock_irqsave (&hw->cmd_lock, flags); + } + +spin_unlock_irqrestore (&hw->cmd_lock, flags); + +return EFC_SUCCESS ; +}
drivers/scsi/elx/efct/efct_hw.h +7 -0
@@ -629,4 +629,11 @@ efct_get_wwnn(struct efct_hw *hw);extern uint64_t efct_get_wwpn (struct efct_hw *hw); +enum efct_hw_rtn efct_hw_rx_allocate (struct efct_hw *hw); +enum efct_hw_rtn efct_hw_rx_post (struct efct_hw *hw); +void efct_hw_rx_free (struct efct_hw *hw); +extern enum efct_hw_rtn +efct_hw_command (struct efct_hw *hw,u8 *cmd,u32 opts,void *cb, +void *arg); +#endif /* __EFCT_H__ */
Signature · 1 line
2.16.4
Re: [PATCH v3 18/31] elx: efct: RQ buffer, memory pool allocation and deallocation APIs
Quoted 209 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
RQ data buffer allocation and deallocate. Memory pool allocation and deallocation APIs. Mailbox command submission and completion routines.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
efct_utils.cfile is removed. Replacedefct_pool,efct_varrayandefct_arraywith other alternatives.--- drivers/scsi/elx/efct/efct_hw.c | 375 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 7 + 2 files changed, 382 insertions(+)drivers/scsi/elx/efct/efct_hw.c +182
-0@@ -1114,3 +1114,378 @@ efct_get_wwpn(struct efct_hw *hw)memcpy (p, sli->wwpn,sizeof (p));return get_unaligned_be64 (p); } + +/* +* An efct_hw_rx_buffer_t array is allocated, +* along with the required DMA mem +*/ +static struct efc_hw_rq_buffer * +efct_hw_rx_buffer_alloc (struct efct_hw *hw,u32 rqindex,u32 count, +u32 size) +{ +struct efct *efct = hw->os; +struct efc_hw_rq_buffer *rq_buf =NULL ; +struct efc_hw_rq_buffer *prq; +u32 i; + +if (count !=0 ) { + rq_buf =kmalloc_array (count,sizeof (*rq_buf),GFP_ATOMIC ); +if (!rq_buf) +return NULL ; +memset (rq_buf,0 ,sizeof (*rq_buf) * count); + +for (i =0 , prq = rq_buf; i < count; i ++, prq++) { + prq->rqindex = rqindex; + prq->dma.size = size; + prq->dma.virt =dma_alloc_coherent (&efct->pcidev->dev, + prq->dma.size, + &prq->dma.phys, +GFP_DMA ); +if (!prq->dma.virt) { +efc_log_err (hw->os,"DMA allocation failed\n" ); +kfree (rq_buf); + rq_buf =NULL ; +break ; + } + } + } +return rq_buf; +} + +static void +efct_hw_rx_buffer_free (struct efct_hw *hw, +struct efc_hw_rq_buffer *rq_buf, +u32 count) +{ +struct efct *efct = hw->os; +u32 i; +struct efc_hw_rq_buffer *prq; + +if (rq_buf) { +for (i =0 , prq = rq_buf; i < count; i++, prq++) { +dma_free_coherent (&efct->pcidev->dev, + prq->dma.size, prq->dma.virt, + prq->dma.phys); +memset (&prq->dma,0 ,sizeof (struct efc_dma )); + } + +kfree (rq_buf); + } +} + +enum efct_hw_rtn +efct_hw_rx_allocate (struct efct_hw *hw) +{ +struct efct *efct = hw->os; +u32 i; +int rc =EFCT_HW_RTN_SUCCESS ; +u32 rqindex =0 ; +struct hw_rq *rq; +u32 hdr_size =EFCT_HW_RQ_SIZE_HDR ; +u32 payload_size = hw->config.rq_default_buffer_size; + + rqindex =0 ; + +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; + +/* Allocate header buffers */ + rq->hdr_buf =efct_hw_rx_buffer_alloc (hw, rqindex, + rq->entry_count, + hdr_size); +if (!rq->hdr_buf) { +efc_log_err (efct, +"efct_hw_rx_buffer_alloc hdr_buf failed\n" ); + rc =EFCT_HW_RTN_ERROR ; +break ; + } + +efc_log_debug (hw->os, +"rq[%2d] rq_id %02d header %4d by %4d bytes\n" , + i, rq->hdr->id, rq->entry_count, hdr_size); + + rqindex++; + +/* Allocate payload buffers */ + rq->payload_buf =efct_hw_rx_buffer_alloc (hw, rqindex, + rq->entry_count, + payload_size); +if (!rq->payload_buf) { +efc_log_err (efct, +"efct_hw_rx_buffer_alloc fb_buf failed\n" ); + rc =EFCT_HW_RTN_ERROR ; +break ; + } +efc_log_debug (hw->os, +"rq[%2d] rq_id %02d default %4d by %4d bytes\n" , + i, rq->data->id, rq->entry_count, payload_size); + rqindex++; + } + +return rc ?EFCT_HW_RTN_ERROR :EFCT_HW_RTN_SUCCESS ; +} + +/* Post the RQ data buffers to the chip */ +enum efct_hw_rtn +efct_hw_rx_post (struct efct_hw *hw) +{ +u32 i; +u32 idx; +u32 rq_idx; +int rc =0 ; + +if (!hw->seq_pool) { +u32 count =0 ; + +for (i =0 ; i < hw->hw_rq_count; i++) + count += hw->hw_rq[i]->entry_count; + + hw->seq_pool =kmalloc_array (count, +sizeof (struct efc_hw_sequence ),GFP_KERNEL ); +if (!hw->seq_pool) +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* +* In RQ pair mode, we MUST post the header and payload buffer at the +* same time. +*/ +for (rq_idx =0 , idx =0 ; rq_idx < hw->hw_rq_count; rq_idx++) { +struct hw_rq *rq = hw->hw_rq[rq_idx]; + +for (i =0 ; i < rq->entry_count -1 ; i++) { +struct efc_hw_sequence *seq; + + seq = hw->seq_pool + idx *sizeof (*seq); +if (!seq) { + rc =-1 ; +break ; + } + idx++; + seq->header = &rq->hdr_buf[i]; + seq->payload = &rq->payload_buf[i]; + rc =efct_hw_sequence_free (hw, seq); +if (rc) +break ; + } +if (rc) +break ; + } + +if (rc && hw->seq_pool) +kfree (hw->seq_pool); + +return rc; +} + +void +efct_hw_rx_free (struct efct_hw *hw) +{ +struct hw_rq *rq; +u32 i; + +/* Free hw_rq buffers */ +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; +if (rq) { +efct_hw_rx_buffer_free (hw, rq->hdr_buf, + rq->entry_count); + rq->hdr_buf =NULL ; +efct_hw_rx_buffer_free (hw, rq->payload_buf, + rq->entry_count); + rq->payload_buf =NULL ; + } + }
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1308
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+} + +static int +efct_hw_cmd_submit_pending (struct efct_hw *hw) +{ +struct efct_command_ctx *ctx =NULL ; +int rc =0 ; + +/* Assumes lock held */ +
So make it a regular lockdep annotation then.
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1316
Quoted 7 lines
drivers/scsi/elx/efct/efct_hw.c +7
-0+/* Only submit MQE if there's room */ +while (hw->cmd_head_count < (EFCT_HW_MQ_DEPTH -1 ) && + !list_empty(&hw->cmd_pending)) > + ctx = list_first_entry(&hw->cmd_pending, + struct efct_command_ctx, list_entry); +if (!ctx) +break ; +
Seeing that you always check for !ctx you might as well drop the '!list_empty' condition from the while() statement.
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1317
Quoted 2 lines
drivers/scsi/elx/efct/efct_hw.c +2
-0+list_del (&ctx->list_entry); +
And it might even be better to use 'list_for_each_entry_safe()' here
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1327
Quoted 9 lines
drivers/scsi/elx/efct/efct_hw.c +9
-0+INIT_LIST_HEAD (&ctx->list_entry); +list_add_tail (&ctx->list_entry, &hw->cmd_head); + hw->cmd_head_count++; +if (sli_mq_write (&hw->sli, hw->mq, ctx->buf) <0 ) { +efc_log_test (hw->os, +"sli_queue_write failed: %d\n" , rc); + rc =-1 ; +break ; + }
and break here for the 'cmd_head_count' condition.
Quoted 33 lines
drivers/scsi/elx/efct/efct_hw.c +33
-0+ } +return rc; +} + +/* +* Send a mailbox command to the hardware, and either wait for a completion +* (EFCT_CMD_POLL) or get an optional asynchronous completion (EFCT_CMD_NOWAIT). +*/ +enum efct_hw_rtn +efct_hw_command (struct efct_hw *hw,u8 *cmd,u32 opts,void *cb,void *arg) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_ERROR ; +unsigned long flags =0 ; +void *bmbx =NULL ; + +/* +* If the chip is in an error state (UE'd) then reject this mailbox +* command. +*/ +if (sli_fw_error_status (&hw->sli) >0 ) { +efc_log_crit (hw->os, +"Chip is in an error state - reset needed\n" ); +efc_log_crit (hw->os, +"status=%#x error1=%#x error2=%#x\n" , +sli_reg_read_status (&hw->sli), +sli_reg_read_err1 (&hw->sli), +sli_reg_read_err2 (&hw->sli)); + +return EFCT_HW_RTN_ERROR ; + } + +if (opts ==EFCT_CMD_POLL ) { +spin_lock_irqsave (&hw->cmd_lock, flags);
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1370
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ bmbx = hw->sli.bmbx.virt; + +memset (bmbx,0 ,SLI4_BMBX_SIZE ); +memcpy (bmbx, cmd,SLI4_BMBX_SIZE ); + +if (sli_bmbx_command (&hw->sli) ==0 ) { + rc =EFCT_HW_RTN_SUCCESS ; +memcpy (cmd, bmbx,SLI4_BMBX_SIZE ); + } +spin_unlock_irqrestore (&hw->cmd_lock, flags);
See? You even _have_ a preallocated mailbox.
So you could use that to facilitate the loop topology detection I've commented on in an earlier patch.
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1379
Quoted 9 lines
drivers/scsi/elx/efct/efct_hw.c +9
-0+ }else if (opts ==EFCT_CMD_NOWAIT ) { +struct efct_command_ctx *ctx =NULL ; + + ctx =kmalloc (sizeof (*ctx),GFP_ATOMIC ); +if (!ctx) +return EFCT_HW_RTN_NO_RESOURCES ; + +memset (ctx,0 ,sizeof (struct efct_command_ctx )); +
But now you go and spoil it all again.
At the very least use a mempool here; not sure how frequent these calls are, but we're talking to the hardware here, so I assume it'll happen more than just once.
Quoted 15 lines
drivers/scsi/elx/efct/efct_hw.c +15
-0+if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os, +"Can't send command, HW state=%d\n" , + hw->state); +kfree (ctx); +return EFCT_HW_RTN_ERROR ; + } + +if (cb) { + ctx->cb = cb; + ctx->arg = arg; + } + ctx->buf = cmd; + ctx->ctx = hw; +
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1404
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+spin_lock_irqsave (&hw->cmd_lock, flags); + +/* Add to pending list */ +INIT_LIST_HEAD (&ctx->list_entry); +list_add_tail (&ctx->list_entry, &hw->cmd_pending); + +/* Submit as much of the pending list as we can */ +if (efct_hw_cmd_submit_pending (hw) ==0 ) + rc =EFCT_HW_RTN_SUCCESS ; +
Indentation?
Quoted 32 lines
drivers/scsi/elx/efct/efct_hw.c +32
-0+spin_unlock_irqrestore (&hw->cmd_lock, flags); + } + +return rc; +} + +static int +efct_hw_command_process (struct efct_hw *hw,int status,u8 *mqe, +size_t size) +{ +struct efct_command_ctx *ctx =NULL ; +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->cmd_lock, flags); +if (!list_empty (&hw->cmd_head)) { + ctx =list_first_entry (&hw->cmd_head, + struct efct_command_ctx, list_entry); +list_del (&ctx->list_entry); + } +if (!ctx) { +efc_log_err (hw->os,"no command context?!?\n" ); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +return EFC_FAIL ; + } + + hw->cmd_head_count--; + +/* Post any pending requests */ +efct_hw_cmd_submit_pending (hw); + +spin_unlock_irqrestore (&hw->cmd_lock, flags); +
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1446
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+if (ctx->cb) { +if (ctx->buf) +memcpy (ctx->buf, mqe, size); + + ctx->cb (hw, status, ctx->buf, ctx->arg); + } + +memset (ctx,0 ,sizeof (struct efct_command_ctx )); +kfree (ctx); +
memset() before kfree() is pointless.
Use KASAN et al if you suspect memory issues.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 18/31] elx: efct: RQ buffer, memory pool allocation and deallocation APIs
On 4/16/2020 12:24 AM, Hannes Reinecke wrote:
...
Quoted 2 lines
But now you go and spoil it all again.
At the very least use a mempool here; not sure how frequent these calls are, but we're talking to the hardware here, so I assume it'll happen more than just once.
we will move to a mempool
Agree with the rest of the comments and will address them.
-- james
Re: [PATCH v3 18/31] elx: efct: RQ buffer, memory pool allocation and deallocation APIs
In reply to James SmartQuoted 32 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
RQ data buffer allocation and deallocate. Memory pool allocation and deallocation APIs. Mailbox command submission and completion routines.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
efct_utils.cfile is removed. Replacedefct_pool,efct_varrayandefct_arraywith other alternatives.--- drivers/scsi/elx/efct/efct_hw.c | 375 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 7 + 2 files changed, 382 insertions(+)drivers/scsi/elx/efct/efct_hw.c +5
-0@@ -1114,3 +1114,378 @@ efct_get_wwpn(struct efct_hw *hw)memcpy (p, sli->wwpn,sizeof (p));return get_unaligned_be64 (p); } + +/* +* An efct_hw_rx_buffer_t array is allocated, +* along with the required DMA mem +*/
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1131
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+static struct efc_hw_rq_buffer * +efct_hw_rx_buffer_alloc (struct efct_hw *hw,u32 rqindex,u32 count, +u32 size) +{ +struct efct *efct = hw->os; +struct efc_hw_rq_buffer *rq_buf =NULL ; +struct efc_hw_rq_buffer *prq; +u32 i; + +if (count !=0 ) {
if (count == 0)
return NULL;
and then there is no need to pre-initialize rq_buf
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1135
Quoted 4 lines
drivers/scsi/elx/efct/efct_hw.c +4
-0+ rq_buf =kmalloc_array (count,sizeof (*rq_buf),GFP_ATOMIC ); +if (!rq_buf) +return NULL ; +memset (rq_buf,0 ,sizeof (*rq_buf) * count);
kzalloc
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1143
Quoted 8 lines
drivers/scsi/elx/efct/efct_hw.c +8
-0+ +for (i =0 , prq = rq_buf; i < count; i ++, prq++) { + prq->rqindex = rqindex; + prq->dma.size = size; + prq->dma.virt =dma_alloc_coherent (&efct->pcidev->dev, + prq->dma.size, + &prq->dma.phys, +GFP_DMA );
GFP_KERNEL
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1148
Quoted 5 lines
drivers/scsi/elx/efct/efct_hw.c +5
-0+if (!prq->dma.virt) { +efc_log_err (hw->os,"DMA allocation failed\n" ); +kfree (rq_buf); + rq_buf =NULL ; +break ;
return NULL;
Quoted 6 lines
drivers/scsi/elx/efct/efct_hw.c +6
-0+ } + } + } +return rq_buf; +} +
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1164
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+static void +efct_hw_rx_buffer_free (struct efct_hw *hw, +struct efc_hw_rq_buffer *rq_buf, +u32 count) +{ +struct efct *efct = hw->os; +u32 i; +struct efc_hw_rq_buffer *prq; + +if (rq_buf) {
if (!rq_buf)
return;
Quoted 131 lines
drivers/scsi/elx/efct/efct_hw.c +131
-0+for (i =0 , prq = rq_buf; i < count; i++, prq++) { +dma_free_coherent (&efct->pcidev->dev, + prq->dma.size, prq->dma.virt, + prq->dma.phys); +memset (&prq->dma,0 ,sizeof (struct efc_dma )); + } + +kfree (rq_buf); + } +} + +enum efct_hw_rtn +efct_hw_rx_allocate (struct efct_hw *hw) +{ +struct efct *efct = hw->os; +u32 i; +int rc =EFCT_HW_RTN_SUCCESS ; +u32 rqindex =0 ; +struct hw_rq *rq; +u32 hdr_size =EFCT_HW_RQ_SIZE_HDR ; +u32 payload_size = hw->config.rq_default_buffer_size; + + rqindex =0 ; + +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; + +/* Allocate header buffers */ + rq->hdr_buf =efct_hw_rx_buffer_alloc (hw, rqindex, + rq->entry_count, + hdr_size); +if (!rq->hdr_buf) { +efc_log_err (efct, +"efct_hw_rx_buffer_alloc hdr_buf failed\n" ); + rc =EFCT_HW_RTN_ERROR ; +break ; + } + +efc_log_debug (hw->os, +"rq[%2d] rq_id %02d header %4d by %4d bytes\n" , + i, rq->hdr->id, rq->entry_count, hdr_size); + + rqindex++; + +/* Allocate payload buffers */ + rq->payload_buf =efct_hw_rx_buffer_alloc (hw, rqindex, + rq->entry_count, + payload_size); +if (!rq->payload_buf) { +efc_log_err (efct, +"efct_hw_rx_buffer_alloc fb_buf failed\n" ); + rc =EFCT_HW_RTN_ERROR ; +break ; + } +efc_log_debug (hw->os, +"rq[%2d] rq_id %02d default %4d by %4d bytes\n" , + i, rq->data->id, rq->entry_count, payload_size); + rqindex++; + } + +return rc ?EFCT_HW_RTN_ERROR :EFCT_HW_RTN_SUCCESS ; +} + +/* Post the RQ data buffers to the chip */ +enum efct_hw_rtn +efct_hw_rx_post (struct efct_hw *hw) +{ +u32 i; +u32 idx; +u32 rq_idx; +int rc =0 ; + +if (!hw->seq_pool) { +u32 count =0 ; + +for (i =0 ; i < hw->hw_rq_count; i++) + count += hw->hw_rq[i]->entry_count; + + hw->seq_pool =kmalloc_array (count, +sizeof (struct efc_hw_sequence ),GFP_KERNEL ); +if (!hw->seq_pool) +return EFCT_HW_RTN_NO_MEMORY ; + } + +/* +* In RQ pair mode, we MUST post the header and payload buffer at the +* same time. +*/ +for (rq_idx =0 , idx =0 ; rq_idx < hw->hw_rq_count; rq_idx++) { +struct hw_rq *rq = hw->hw_rq[rq_idx]; + +for (i =0 ; i < rq->entry_count -1 ; i++) { +struct efc_hw_sequence *seq; + + seq = hw->seq_pool + idx *sizeof (*seq); +if (!seq) { + rc =-1 ; +break ; + } + idx++; + seq->header = &rq->hdr_buf[i]; + seq->payload = &rq->payload_buf[i]; + rc =efct_hw_sequence_free (hw, seq); +if (rc) +break ; + } +if (rc) +break ; + } + +if (rc && hw->seq_pool) +kfree (hw->seq_pool); + +return rc; +} + +void +efct_hw_rx_free (struct efct_hw *hw) +{ +struct hw_rq *rq; +u32 i; + +/* Free hw_rq buffers */ +for (i =0 ; i < hw->hw_rq_count; i++) { + rq = hw->hw_rq[i]; +if (rq) { +efct_hw_rx_buffer_free (hw, rq->hdr_buf, + rq->entry_count); + rq->hdr_buf =NULL ; +efct_hw_rx_buffer_free (hw, rq->payload_buf, + rq->entry_count);
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1305
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ rq->payload_buf =NULL ; + } + } +} + +static int +efct_hw_cmd_submit_pending (struct efct_hw *hw) +{ +struct efct_command_ctx *ctx =NULL ; +int rc =0 ;
back to plain numbers.
Quoted 59 lines
drivers/scsi/elx/efct/efct_hw.c +59
-0+ +/* Assumes lock held */ + +/* Only submit MQE if there's room */ +while (hw->cmd_head_count < (EFCT_HW_MQ_DEPTH -1 ) && + !list_empty (&hw->cmd_pending)) { + ctx =list_first_entry (&hw->cmd_pending, + struct efct_command_ctx, list_entry); +if (!ctx) +break ; + +list_del (&ctx->list_entry); + +INIT_LIST_HEAD (&ctx->list_entry); +list_add_tail (&ctx->list_entry, &hw->cmd_head); + hw->cmd_head_count++; +if (sli_mq_write (&hw->sli, hw->mq, ctx->buf) <0 ) { +efc_log_test (hw->os, +"sli_queue_write failed: %d\n" , rc); + rc =-1 ; +break ; + } + } +return rc; +} + +/* +* Send a mailbox command to the hardware, and either wait for a completion +* (EFCT_CMD_POLL) or get an optional asynchronous completion (EFCT_CMD_NOWAIT). +*/ +enum efct_hw_rtn +efct_hw_command (struct efct_hw *hw,u8 *cmd,u32 opts,void *cb,void *arg) +{ +enum efct_hw_rtn rc =EFCT_HW_RTN_ERROR ; +unsigned long flags =0 ; +void *bmbx =NULL ; + +/* +* If the chip is in an error state (UE'd) then reject this mailbox +* command. +*/ +if (sli_fw_error_status (&hw->sli) >0 ) { +efc_log_crit (hw->os, +"Chip is in an error state - reset needed\n" ); +efc_log_crit (hw->os, +"status=%#x error1=%#x error2=%#x\n" , +sli_reg_read_status (&hw->sli), +sli_reg_read_err1 (&hw->sli), +sli_reg_read_err2 (&hw->sli)); + +return EFCT_HW_RTN_ERROR ; + } + +if (opts ==EFCT_CMD_POLL ) { +spin_lock_irqsave (&hw->cmd_lock, flags); + bmbx = hw->sli.bmbx.virt; + +memset (bmbx,0 ,SLI4_BMBX_SIZE ); +memcpy (bmbx, cmd,SLI4_BMBX_SIZE );
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1374
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ +if (sli_bmbx_command (&hw->sli) ==0 ) { + rc =EFCT_HW_RTN_SUCCESS ; +memcpy (cmd, bmbx,SLI4_BMBX_SIZE ); + } +spin_unlock_irqrestore (&hw->cmd_lock, flags); + }else if (opts ==EFCT_CMD_NOWAIT ) { +struct efct_command_ctx *ctx =NULL ; + + ctx =kmalloc (sizeof (*ctx),GFP_ATOMIC );
GPF_KERNEL
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1378
Quoted 4 lines
drivers/scsi/elx/efct/efct_hw.c +4
-0+if (!ctx) +return EFCT_HW_RTN_NO_RESOURCES ; + +memset (ctx,0 ,sizeof (struct efct_command_ctx ));
kzalloc
Quoted 56 lines
drivers/scsi/elx/efct/efct_hw.c +56
-0+ +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os, +"Can't send command, HW state=%d\n" , + hw->state); +kfree (ctx); +return EFCT_HW_RTN_ERROR ; + } + +if (cb) { + ctx->cb = cb; + ctx->arg = arg; + } + ctx->buf = cmd; + ctx->ctx = hw; + +spin_lock_irqsave (&hw->cmd_lock, flags); + +/* Add to pending list */ +INIT_LIST_HEAD (&ctx->list_entry); +list_add_tail (&ctx->list_entry, &hw->cmd_pending); + +/* Submit as much of the pending list as we can */ +if (efct_hw_cmd_submit_pending (hw) ==0 ) + rc =EFCT_HW_RTN_SUCCESS ; + +spin_unlock_irqrestore (&hw->cmd_lock, flags); + } + +return rc; +} + +static int +efct_hw_command_process (struct efct_hw *hw,int status,u8 *mqe, +size_t size) +{ +struct efct_command_ctx *ctx =NULL ; +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->cmd_lock, flags); +if (!list_empty (&hw->cmd_head)) { + ctx =list_first_entry (&hw->cmd_head, + struct efct_command_ctx, list_entry); +list_del (&ctx->list_entry); + } +if (!ctx) { +efc_log_err (hw->os,"no command context?!?\n" ); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +return EFC_FAIL ; + } + + hw->cmd_head_count--; + +/* Post any pending requests */ +efct_hw_cmd_submit_pending (hw); +
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1444
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+spin_unlock_irqrestore (&hw->cmd_lock, flags); + +if (ctx->cb) { +if (ctx->buf) +memcpy (ctx->buf, mqe, size); + + ctx->cb (hw, status, ctx->buf, ctx->arg); + } + +memset (ctx,0 ,sizeof (struct efct_command_ctx ));
memset is no needed before kfree
Quoted 23 lines
drivers/scsi/elx/efct/efct_hw.c +23
-0+kfree (ctx); + +return EFC_SUCCESS ; +} + +static int +efct_hw_mq_process (struct efct_hw *hw, +int status,struct sli4_queue *mq) +{ +u8 mqe[SLI4_BMBX_SIZE ]; + +if (!sli_mq_read (&hw->sli, mq, mqe)) +efct_hw_command_process (hw, status, mqe, mq->size); + +return EFC_SUCCESS ; +} + +static int +efct_hw_command_cancel (struct efct_hw *hw) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->cmd_lock, flags);
drivers/scsi/elx/efct/efct_hw.c efct_get_wwpn(struct efct_hw *hw) · line 1477
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ +/* +* Manually clean up remaining commands. Note: since this calls +* efct_hw_command_process(), we'll also process the cmd_pending +* list, so no need to manually clean that out. +*/ +while (!list_empty (&hw->cmd_head)) { +u8 mqe[SLI4_BMBX_SIZE ] = {0 }; +struct efct_command_ctx *ctx = + list_first_entry(&hw->cmd_head, struct efct_command_ctx, list_entry);
struct eftc_command_ctx *ctx; ctx = list_first_entry(&hw->cmd_head, struct efct_command_ctx, list_entry);
Quoted 33 lines
drivers/scsi/elx/efct/efct_hw.c +14
-0+ +efc_log_test (hw->os,"hung command %08x\n" , + !ctx ?U32_MAX : + (!ctx->buf ?U32_MAX : + *((u32 *)ctx->buf))); +spin_unlock_irqrestore (&hw->cmd_lock, flags); +efct_hw_command_process (hw,-1 , mqe,SLI4_BMBX_SIZE ); +spin_lock_irqsave (&hw->cmd_lock, flags); + } + +spin_unlock_irqrestore (&hw->cmd_lock, flags); + +return EFC_SUCCESS ; +}drivers/scsi/elx/efct/efct_hw.h +7
-0@@ -629,4 +629,11 @@ efct_get_wwnn(struct efct_hw *hw);extern uint64_t efct_get_wwpn (struct efct_hw *hw); +enum efct_hw_rtn efct_hw_rx_allocate (struct efct_hw *hw); +enum efct_hw_rtn efct_hw_rx_post (struct efct_hw *hw); +void efct_hw_rx_free (struct efct_hw *hw); +extern enum efct_hw_rtn +efct_hw_command (struct efct_hw *hw,u8 *cmd,u32 opts,void *cb, +void *arg); +#endif /* __EFCT_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 19/31 elx: efct: Hardware IO and SGL initialization
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines to create IO interfaces (wqs, etc), SGL initialization, and configure hardware features.
---
v3:
Request tag pool(reqtag_pool) handling fuctions.
--- drivers/scsi/elx/efct/efct_hw.c | 657 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 42 +++ 2 files changed, 699 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +657 -0
@@ -1489,3 +1489,660 @@ efct_hw_command_cancel(struct efct_hw *hw)return EFC_SUCCESS ; } + +static inline struct efct_hw_io * +_efct_hw_io_alloc (struct efct_hw *hw) +{ +struct efct_hw_io *io =NULL ; + +if (!list_empty (&hw->io_free)) { + io = list_first_entry(&hw->io_free, struct efct_hw_io, + list_entry); +list_del (&io->list_entry); + } +if (io) { +INIT_LIST_HEAD (&io->list_entry); +INIT_LIST_HEAD (&io->wqe_link); +INIT_LIST_HEAD (&io->dnrx_link); +list_add_tail (&io->list_entry, &hw->io_inuse); + io->state =EFCT_HW_IO_STATE_INUSE ; + io->abort_reqtag =U32_MAX ; + io->wq = hw->hw_wq[0 ]; +kref_init (&io->ref); + io->release = efct_hw_io_free_internal; + }else { +atomic_add_return (1 , &hw->io_alloc_failed_count); + } + +return io; +} + +struct efct_hw_io * +efct_hw_io_alloc (struct efct_hw *hw) +{ +struct efct_hw_io *io =NULL ; +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->io_lock, flags); + io =_efct_hw_io_alloc (hw); +spin_unlock_irqrestore (&hw->io_lock, flags); + +return io; +} + +/* +* When an IO is freed, depending on the exchange busy flag, and other +* workarounds, move it to the correct list. +*/ +static void +efct_hw_io_free_move_correct_list (struct efct_hw *hw, +struct efct_hw_io *io) +{ +if (io->xbusy) { +/* +* add to wait_free list and wait for XRI_ABORTED CQEs to clean +* up +*/ +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &hw->io_wait_free); + io->state =EFCT_HW_IO_STATE_WAIT_FREE ; + }else { +/* IO not busy, add to free list */ +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &hw->io_free); + io->state =EFCT_HW_IO_STATE_FREE ; + } +} + +static inline void +efct_hw_io_free_common (struct efct_hw *hw,struct efct_hw_io *io) +{ +/* initialize IO fields */ +efct_hw_init_free_io (io); + +/* Restore default SGL */ +efct_hw_io_restore_sgl (hw, io); +} + +/** +* Free a previously-allocated HW IO object. Called when +* IO refcount goes to zero (host-owned IOs only). +*/ +void +efct_hw_io_free_internal (struct kref *arg) +{ +unsigned long flags =0 ; +struct efct_hw_io *io = + container_of(arg, struct efct_hw_io, ref); +struct efct_hw *hw = io->hw; + +/* perform common cleanup */ +efct_hw_io_free_common (hw, io); + +spin_lock_irqsave (&hw->io_lock, flags); +/* remove from in-use list */ +if (io->list_entry.next && + !list_empty (&hw->io_inuse)) { +list_del (&io->list_entry); +efct_hw_io_free_move_correct_list (hw, io); + } +spin_unlock_irqrestore (&hw->io_lock, flags); +} + +int +efct_hw_io_free (struct efct_hw *hw,struct efct_hw_io *io) +{ +return kref_put (&io->ref, io->release); +} + +u8 +efct_hw_io_inuse (struct efct_hw *hw,struct efct_hw_io *io) +{ +return (refcount_read (&io->ref.refcount) >0 ); +} + +struct efct_hw_io * +efct_hw_io_lookup (struct efct_hw *hw,u32 xri) +{ +u32 ioindex; + + ioindex = xri - hw->sli.extent[SLI_RSRC_XRI ].base[0 ]; +return hw->io[ioindex]; +} + +enum efct_hw_rtn +efct_hw_io_register_sgl (struct efct_hw *hw,struct efct_hw_io *io, +struct efc_dma *sgl, +u32 sgl_count) +{ +if (hw->sli.sgl_pre_registered) { +efc_log_err (hw->os, +"can't use temp SGL with pre-registered SGLs\n" ); +return EFCT_HW_RTN_ERROR ; + } + io->ovfl_sgl = sgl; + io->ovfl_sgl_count = sgl_count; + +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_io_init_sges (struct efct_hw *hw,struct efct_hw_io *io, +enum efct_hw_io_type type) +{ +struct sli4_sge *data =NULL ; +u32 i =0 ; +u32 skips =0 ; +u32 sge_flags =0 ; + +if (!io) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p\n" , hw, io); +return EFCT_HW_RTN_ERROR ; + } + +/* Clear / reset the scatter-gather list */ + io->sgl = &io->def_sgl; + io->sgl_count = io->def_sgl_count; + io->first_data_sge =0 ; + +memset (io->sgl->virt,0 ,2 *sizeof (struct sli4_sge )); + io->n_sge =0 ; + io->sge_offset =0 ; + + io->type = type; + + data = io->sgl->virt; + +/* +* Some IO types have underlying hardware requirements on the order +* of SGEs. Process all special entries here. +*/ +switch (type) { +case EFCT_HW_IO_TARGET_WRITE : +#define EFCT_TARGET_WRITE_SKIPS 2 + skips =EFCT_TARGET_WRITE_SKIPS ; + +/* populate host resident XFER_RDY buffer */ + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags &= (~SLI4_SGE_TYPE_MASK ); + sge_flags |= (SLI4_SGE_TYPE_DATA <<SLI4_SGE_TYPE_SHIFT ); + data->buffer_address_high = +cpu_to_le32 (upper_32_bits (io->xfer_rdy.phys)); + data->buffer_address_low = +cpu_to_le32 (lower_32_bits (io->xfer_rdy.phys)); + data->buffer_length =cpu_to_le32 (io->xfer_rdy.size); + data->dw2_flags =cpu_to_le32 (sge_flags); + data++; + + skips--; + + io->n_sge =1 ; +break ; +case EFCT_HW_IO_TARGET_READ : +/* +* For FCP_TSEND64, the first 2 entries are SKIP SGE's +*/ +#define EFCT_TARGET_READ_SKIPS 2 + skips =EFCT_TARGET_READ_SKIPS ; +break ; +case EFCT_HW_IO_TARGET_RSP : +/* +* No skips, etc. for FCP_TRSP64 +*/ +break ; +default : +efc_log_err (hw->os,"unsupported IO type %#x\n" , type); +return EFCT_HW_RTN_ERROR ; + } + +/* +* Write skip entries +*/ +for (i =0 ; i < skips; i++) { + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags &= (~SLI4_SGE_TYPE_MASK ); + sge_flags |= (SLI4_SGE_TYPE_SKIP <<SLI4_SGE_TYPE_SHIFT ); + data->dw2_flags =cpu_to_le32 (sge_flags); + data++; + } + + io->n_sge += skips; + +/* +* Set last +*/ + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags |=SLI4_SGE_LAST ; + data->dw2_flags =cpu_to_le32 (sge_flags); + +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_io_add_sge (struct efct_hw *hw,struct efct_hw_io *io, +uintptr_t addr,u32 length) +{ +struct sli4_sge *data =NULL ; +u32 sge_flags =0 ; + +if (!io || !addr || !length) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p addr=%lx length=%u\n" , + hw, io, addr, length); +return EFCT_HW_RTN_ERROR ; + } + +if (length > hw->sli.sge_supported_length) { +efc_log_err (hw->os, +"length of SGE %d bigger than allowed %d\n" , + length, hw->sli.sge_supported_length); +return EFCT_HW_RTN_ERROR ; + } + + data = io->sgl->virt; + data += io->n_sge; + + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags &= ~SLI4_SGE_TYPE_MASK ; + sge_flags |=SLI4_SGE_TYPE_DATA <<SLI4_SGE_TYPE_SHIFT ; + sge_flags &= ~SLI4_SGE_DATA_OFFSET_MASK ; + sge_flags |=SLI4_SGE_DATA_OFFSET_MASK & io->sge_offset; + + data->buffer_address_high =cpu_to_le32 (upper_32_bits (addr)); + data->buffer_address_low =cpu_to_le32 (lower_32_bits (addr)); + data->buffer_length =cpu_to_le32 (length); + +/* +* Always assume this is the last entry and mark as such. +* If this is not the first entry unset the "last SGE" +* indication for the previous entry +*/ + sge_flags |=SLI4_SGE_LAST ; + data->dw2_flags =cpu_to_le32 (sge_flags); + +if (io->n_sge) { + sge_flags =le32_to_cpu (data[-1 ].dw2_flags); + sge_flags &= ~SLI4_SGE_LAST ; + data[-1 ].dw2_flags =cpu_to_le32 (sge_flags); + } + +/* Set first_data_bde if not previously set */ +if (io->first_data_sge ==0 ) + io->first_data_sge = io->n_sge; + + io->sge_offset += length; + io->n_sge++; + +/* Update the linked segment length (only executed after overflow has +* begun) +*/ +if (io->ovfl_lsp) + io->ovfl_lsp->dw3_seglen = +cpu_to_le32 (io->n_sge *sizeof (struct sli4_sge ) & +SLI4_LSP_SGE_SEGLEN ); + +return EFCT_HW_RTN_SUCCESS ; +} + +void +efct_hw_io_abort_all (struct efct_hw *hw) +{ +struct efct_hw_io *io_to_abort =NULL ; +struct efct_hw_io *next_io =NULL ; + +list_for_each_entry_safe (io_to_abort, next_io, + &hw->io_inuse, list_entry) { +efct_hw_io_abort (hw, io_to_abort, true,NULL ,NULL ); + } +} + +static void +efct_hw_wq_process_abort (void *arg,u8 *cqe,int status) +{ +struct efct_hw_io *io = arg; +struct efct_hw *hw = io->hw; +u32 ext =0 ; +u32 len =0 ; +struct hw_wq_callback *wqcb; +unsigned long flags =0 ; + +/* +* For IOs that were aborted internally, we may need to issue the +* callback here depending on whether a XRI_ABORTED CQE is expected ot +* not. If the status is Local Reject/No XRI, then +* issue the callback now. +*/ + ext =sli_fc_ext_status (&hw->sli, cqe); +if (status ==SLI4_FC_WCQE_STATUS_LOCAL_REJECT && + ext ==SLI4_FC_LOCAL_REJECT_NO_XRI && + io->done) { +efct_hw_done_t done = io->done; +void *arg = io->arg; + + io->done =NULL ; + +/* +* Use latched status as this is always saved for an internal +* abort Note: We wont have both a done and abort_done +* function, so don't worry about +* clobbering the len, status and ext fields. +*/ + status = io->saved_status; + len = io->saved_len; + ext = io->saved_ext; + io->status_saved = false; +done (io, io->rnode, len, status, ext, arg); + } + +if (io->abort_done) { +efct_hw_done_t done = io->abort_done; +void *arg = io->abort_arg; + + io->abort_done =NULL ; + +done (io, io->rnode, len, status, ext, arg); + } +spin_lock_irqsave (&hw->io_abort_lock, flags); +/* clear abort bit to indicate abort is complete */ + io->abort_in_progress = false; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); + +/* Free the WQ callback */ +if (io->abort_reqtag ==U32_MAX ) { +efc_log_err (hw->os,"HW IO already freed\n" ); +return ; + } + + wqcb =efct_hw_reqtag_get_instance (hw, io->abort_reqtag); +efct_hw_reqtag_free (hw, wqcb); + +/* +* Call efct_hw_io_free() because this releases the WQ reservation as +* well as doing the refcount put. Don't duplicate the code here. +*/ + (void )efct_hw_io_free (hw, io); +} + +enum efct_hw_rtn +efct_hw_io_abort (struct efct_hw *hw,struct efct_hw_io *io_to_abort, +bool send_abts,void *cb,void *arg) +{ +enum sli4_abort_type atype =SLI_ABORT_MAX ; +u32 id =0 , mask =0 ; +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +struct hw_wq_callback *wqcb; +unsigned long flags =0 ; + +if (!io_to_abort) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p\n" , + hw, io_to_abort); +return EFCT_HW_RTN_ERROR ; + } + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os,"cannot send IO abort, HW state=%d\n" , + hw->state); +return EFCT_HW_RTN_ERROR ; + } + +/* take a reference on IO being aborted */ +if (kref_get_unless_zero (&io_to_abort->ref) ==0 ) { +/* command no longer active */ +efc_log_test (hw->os, +"io not active xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return EFCT_HW_RTN_IO_NOT_ACTIVE ; + } + +/* Must have a valid WQ reference */ +if (!io_to_abort->wq) { +efc_log_test (hw->os,"io_to_abort xri=0x%x not active on WQ\n" , + io_to_abort->indicator); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +return EFCT_HW_RTN_IO_NOT_ACTIVE ; + } + +/* +* Validation checks complete; now check to see if already being +* aborted +*/ +spin_lock_irqsave (&hw->io_abort_lock, flags); +if (io_to_abort->abort_in_progress) { +spin_unlock_irqrestore (&hw->io_abort_lock, flags); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +efc_log_debug (hw->os, +"io already being aborted xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return EFCT_HW_RTN_IO_ABORT_IN_PROGRESS ; + } + +/* +* This IO is not already being aborted. Set flag so we won't try to +* abort it again. After all, we only have one abort_done callback. +*/ + io_to_abort->abort_in_progress = true; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); + +/* +* If we got here, the possibilities are: +* - host owned xri +* - io_to_abort->wq_index != U32_MAX +* - submit ABORT_WQE to same WQ +* - port owned xri: +* - rxri: io_to_abort->wq_index == U32_MAX +* - submit ABORT_WQE to any WQ +* - non-rxri +* - io_to_abort->index != U32_MAX +* - submit ABORT_WQE to same WQ +* - io_to_abort->index == U32_MAX +* - submit ABORT_WQE to any WQ +*/ + io_to_abort->abort_done = cb; + io_to_abort->abort_arg = arg; + + atype =SLI_ABORT_XRI ; + id = io_to_abort->indicator; + +/* Allocate a request tag for the abort portion of this IO */ + wqcb =efct_hw_reqtag_alloc (hw, efct_hw_wq_process_abort, io_to_abort); +if (!wqcb) { +efc_log_err (hw->os,"can't allocate request tag\n" ); +return EFCT_HW_RTN_NO_RESOURCES ; + } + io_to_abort->abort_reqtag = wqcb->instance_index; + +/* +* If the wqe is on the pending list, then set this wqe to be +* aborted when the IO's wqe is removed from the list. +*/ +if (io_to_abort->wq) { +spin_lock_irqsave (&io_to_abort->wq->queue->lock, flags); +if (io_to_abort->wqe.list_entry.next) { + io_to_abort->wqe.abort_wqe_submit_needed = true; + io_to_abort->wqe.send_abts = send_abts; + io_to_abort->wqe.id = id; + io_to_abort->wqe.abort_reqtag = + io_to_abort->abort_reqtag; +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, + flags); +return EFC_SUCCESS ; + } +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, flags); + } + +if (sli_abort_wqe (&hw->sli, io_to_abort->wqe.wqebuf, + hw->sli.wqe_size, atype, send_abts, id, mask, + io_to_abort->abort_reqtag,SLI4_CQ_DEFAULT )) { +efc_log_err (hw->os,"ABORT WQE error\n" ); + io_to_abort->abort_reqtag =U32_MAX ; +efct_hw_reqtag_free (hw, wqcb); + rc =EFCT_HW_RTN_ERROR ; + } + +if (rc ==EFCT_HW_RTN_SUCCESS ) { + +/* ABORT_WQE does not actually utilize an XRI on the Port, +* therefore, keep xbusy as-is to track the exchange's state, +* not the ABORT_WQE's state +*/ + rc =efct_hw_wq_write (io_to_abort->wq, &io_to_abort->wqe); +if (rc >0 ) +/* non-negative return is success */ + rc =0 ; +/* +* can't abort an abort so skip adding to timed wqe +* list +*/ + } + +if (rc !=EFCT_HW_RTN_SUCCESS ) { +spin_lock_irqsave (&hw->io_abort_lock, flags); + io_to_abort->abort_in_progress = false; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); + } +return rc; +} + +void +efct_hw_reqtag_pool_free (struct efct_hw *hw) +{ +u32 i =0 ; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; +struct hw_wq_callback *wqcb =NULL ; + +if (reqtag_pool) { +for (i =0 ; i <U16_MAX ; i++) { + wqcb = reqtag_pool->tags[i]; +if (!wqcb) +continue ; + +kfree (wqcb); + } +kfree (reqtag_pool); + hw->wq_reqtag_pool =NULL ; + } +} + +struct reqtag_pool * +efct_hw_reqtag_pool_alloc (struct efct_hw *hw) +{ +u32 i =0 ; +struct reqtag_pool *reqtag_pool; +struct hw_wq_callback *wqcb; + + reqtag_pool =kzalloc (sizeof (*reqtag_pool),GFP_KERNEL ); +if (!reqtag_pool) +return NULL ; + +INIT_LIST_HEAD (&reqtag_pool->freelist); +/* initialize reqtag pool lock */ +spin_lock_init (&reqtag_pool->lock); +for (i =0 ; i <U16_MAX ; i++) { + wqcb =kmalloc (sizeof (*wqcb),GFP_KERNEL ); +if (!wqcb) +break ; + + reqtag_pool->tags[i] = wqcb; + wqcb->instance_index = i; + wqcb->callback =NULL ; + wqcb->arg =NULL ; +INIT_LIST_HEAD (&wqcb->list_entry); +list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); + } + +return reqtag_pool; +} + +struct hw_wq_callback * +efct_hw_reqtag_alloc (struct efct_hw *hw, +void (*callback)(void *arg,u8 *cqe,int status), +void *arg) +{ +struct hw_wq_callback *wqcb =NULL ; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; +unsigned long flags =0 ; + +if (!callback) +return wqcb; + +spin_lock_irqsave (&reqtag_pool->lock, flags); + +if (!list_empty (&reqtag_pool->freelist)) { + wqcb =list_first_entry (&reqtag_pool->freelist, + struct hw_wq_callback, list_entry); + } + +if (wqcb) { +list_del (&wqcb->list_entry); +spin_unlock_irqrestore (&reqtag_pool->lock, flags); + wqcb->callback = callback; + wqcb->arg = arg; + }else { +spin_unlock_irqrestore (&reqtag_pool->lock, flags); + } + +return wqcb; +} + +void +efct_hw_reqtag_free (struct efct_hw *hw,struct hw_wq_callback *wqcb) +{ +unsigned long flags =0 ; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; + +if (!wqcb->callback) +efc_log_err (hw->os,"WQCB is already freed\n" ); + +spin_lock_irqsave (&reqtag_pool->lock, flags); + wqcb->callback =NULL ; + wqcb->arg =NULL ; +INIT_LIST_HEAD (&wqcb->list_entry); +list_add (&wqcb->list_entry, &hw->wq_reqtag_pool->freelist); +spin_unlock_irqrestore (&reqtag_pool->lock, flags); +} + +struct hw_wq_callback * +efct_hw_reqtag_get_instance (struct efct_hw *hw,u32 instance_index) +{ +struct hw_wq_callback *wqcb; + + wqcb = hw->wq_reqtag_pool->tags[instance_index]; +if (!wqcb) +efc_log_err (hw->os,"wqcb for instance %d is null\n" , + instance_index); + +return wqcb; +} + +void +efct_hw_reqtag_reset (struct efct_hw *hw) +{ +struct hw_wq_callback *wqcb; +u32 i; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; +struct list_head *p, *n; + +/* Remove all from freelist */ +list_for_each_safe (p, n, &reqtag_pool->freelist) { + wqcb = list_entry(p, struct hw_wq_callback, list_entry); + +if (wqcb) +list_del (&wqcb->list_entry); + } + +/* Put them all back */ +for (i =0 ; i <ARRAY_SIZE (reqtag_pool->tags); i++) { + wqcb = reqtag_pool->tags[i]; + wqcb->instance_index = i; + wqcb->callback =NULL ; + wqcb->arg =NULL ; +INIT_LIST_HEAD (&wqcb->list_entry); +list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); + } +}
drivers/scsi/elx/efct/efct_hw.h +42 -0
47 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 19/31] elx: efct: Hardware IO and SGL initialization
Quoted 21 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines to create IO interfaces (wqs, etc), SGL initialization, and configure hardware features.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Request tagpool(reqtag_pool)handling fuctions.--- drivers/scsi/elx/efct/efct_hw.c | 657 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 42 +++ 2 files changed, 699 insertions(+)drivers/scsi/elx/efct/efct_hw.c +0
-0
[ .. ]
Quoted 103 lines
drivers/scsi/elx/efct/efct_hw.c +103
-0+enum efct_hw_rtn +efct_hw_io_abort (struct efct_hw *hw,struct efct_hw_io *io_to_abort, +bool send_abts,void *cb,void *arg) +{ +enum sli4_abort_type atype =SLI_ABORT_MAX ; +u32 id =0 , mask =0 ; +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +struct hw_wq_callback *wqcb; +unsigned long flags =0 ; + +if (!io_to_abort) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p\n" , + hw, io_to_abort); +return EFCT_HW_RTN_ERROR ; + } + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os,"cannot send IO abort, HW state=%d\n" , + hw->state); +return EFCT_HW_RTN_ERROR ; + } + +/* take a reference on IO being aborted */ +if (kref_get_unless_zero (&io_to_abort->ref) ==0 ) { +/* command no longer active */ +efc_log_test (hw->os, +"io not active xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return EFCT_HW_RTN_IO_NOT_ACTIVE ; + } + +/* Must have a valid WQ reference */ +if (!io_to_abort->wq) { +efc_log_test (hw->os,"io_to_abort xri=0x%x not active on WQ\n" , + io_to_abort->indicator); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +return EFCT_HW_RTN_IO_NOT_ACTIVE ; + } + +/* +* Validation checks complete; now check to see if already being +* aborted +*/ +spin_lock_irqsave (&hw->io_abort_lock, flags); +if (io_to_abort->abort_in_progress) { +spin_unlock_irqrestore (&hw->io_abort_lock, flags); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +efc_log_debug (hw->os, +"io already being aborted xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return EFCT_HW_RTN_IO_ABORT_IN_PROGRESS ; + } + +/* +* This IO is not already being aborted. Set flag so we won't try to +* abort it again. After all, we only have one abort_done callback. +*/ + io_to_abort->abort_in_progress = true; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); + +/* +* If we got here, the possibilities are: +* - host owned xri +* - io_to_abort->wq_index != U32_MAX +* - submit ABORT_WQE to same WQ +* - port owned xri: +* - rxri: io_to_abort->wq_index == U32_MAX +* - submit ABORT_WQE to any WQ +* - non-rxri +* - io_to_abort->index != U32_MAX +* - submit ABORT_WQE to same WQ +* - io_to_abort->index == U32_MAX +* - submit ABORT_WQE to any WQ +*/ + io_to_abort->abort_done = cb; + io_to_abort->abort_arg = arg; + + atype =SLI_ABORT_XRI ; + id = io_to_abort->indicator; + +/* Allocate a request tag for the abort portion of this IO */ + wqcb =efct_hw_reqtag_alloc (hw, efct_hw_wq_process_abort, io_to_abort); +if (!wqcb) { +efc_log_err (hw->os,"can't allocate request tag\n" ); +return EFCT_HW_RTN_NO_RESOURCES ; + } + io_to_abort->abort_reqtag = wqcb->instance_index; + +/* +* If the wqe is on the pending list, then set this wqe to be +* aborted when the IO's wqe is removed from the list. +*/ +if (io_to_abort->wq) { +spin_lock_irqsave (&io_to_abort->wq->queue->lock, flags); +if (io_to_abort->wqe.list_entry.next) { + io_to_abort->wqe.abort_wqe_submit_needed = true; + io_to_abort->wqe.send_abts = send_abts; + io_to_abort->wqe.id = id; + io_to_abort->wqe.abort_reqtag = + io_to_abort->abort_reqtag;
drivers/scsi/elx/efct/efct_hw.c efct_hw_command_cancel(struct efct_hw *hw) · line 1979
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, + flags); +return EFC_SUCCESS ; + } +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, flags); + } + +if (sli_abort_wqe (&hw->sli, io_to_abort->wqe.wqebuf, + hw->sli.wqe_size, atype, send_abts, id, mask, + io_to_abort->abort_reqtag,SLI4_CQ_DEFAULT )) {
Wouldn't it be better if we were to pass the 'wqe' directly here?
That would cut down on the number of arguments required, and make the function more readable.
Not to mention that we'll be more efficient if we manage to cut down the number of arguments to '4' or even less, as then we wouldn't need to pass arguments on the stack.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 19/31] elx: efct: Hardware IO and SGL initialization
In reply to James SmartQuoted 60 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines to create IO interfaces (wqs, etc), SGL initialization, and configure hardware features.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Request tagpool(reqtag_pool)handling fuctions.--- drivers/scsi/elx/efct/efct_hw.c | 657 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 42 +++ 2 files changed, 699 insertions(+)drivers/scsi/elx/efct/efct_hw.c +35
-0@@ -1489,3 +1489,660 @@ efct_hw_command_cancel(struct efct_hw *hw)return EFC_SUCCESS ; } + +static inline struct efct_hw_io * +_efct_hw_io_alloc (struct efct_hw *hw) +{ +struct efct_hw_io *io =NULL ; + +if (!list_empty (&hw->io_free)) { + io = list_first_entry(&hw->io_free, struct efct_hw_io, + list_entry); +list_del (&io->list_entry); + } +if (io) { +INIT_LIST_HEAD (&io->list_entry); +INIT_LIST_HEAD (&io->wqe_link); +INIT_LIST_HEAD (&io->dnrx_link); +list_add_tail (&io->list_entry, &hw->io_inuse); + io->state =EFCT_HW_IO_STATE_INUSE ; + io->abort_reqtag =U32_MAX ; + io->wq = hw->hw_wq[0 ]; +kref_init (&io->ref); + io->release = efct_hw_io_free_internal; + }else { +atomic_add_return (1 , &hw->io_alloc_failed_count); + } + +return io; +} + +struct efct_hw_io * +efct_hw_io_alloc (struct efct_hw *hw) +{ +struct efct_hw_io *io =NULL ; +unsigned long flags =0 ; + +spin_lock_irqsave (&hw->io_lock, flags);
drivers/scsi/elx/efct/efct_hw.c efct_hw_command_cancel(struct efct_hw *hw) · line 1536
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ io =_efct_hw_io_alloc (hw); +spin_unlock_irqrestore (&hw->io_lock, flags); + +return io; +} + +/* +* When an IO is freed, depending on the exchange busy flag, and other +* workarounds, move it to the correct list. +*/
kerneldoc
Quoted 30 lines
drivers/scsi/elx/efct/efct_hw.c +30
-0+static void +efct_hw_io_free_move_correct_list (struct efct_hw *hw, +struct efct_hw_io *io) +{ +if (io->xbusy) { +/* +* add to wait_free list and wait for XRI_ABORTED CQEs to clean +* up +*/ +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &hw->io_wait_free); + io->state =EFCT_HW_IO_STATE_WAIT_FREE ; + }else { +/* IO not busy, add to free list */ +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &hw->io_free); + io->state =EFCT_HW_IO_STATE_FREE ; + } +} + +static inline void +efct_hw_io_free_common (struct efct_hw *hw,struct efct_hw_io *io) +{ +/* initialize IO fields */ +efct_hw_init_free_io (io); + +/* Restore default SGL */ +efct_hw_io_restore_sgl (hw, io); +} +
drivers/scsi/elx/efct/efct_hw.c efct_hw_command_cancel(struct efct_hw *hw) · line 1576
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+/** +* Free a previously-allocated HW IO object. Called when +* IO refcount goes to zero (host-owned IOs only). +*/ +void +efct_hw_io_free_internal (struct kref *arg) +{ +unsigned long flags =0 ; +struct efct_hw_io *io = + container_of(arg, struct efct_hw_io, ref);
This fits on one line.
drivers/scsi/elx/efct/efct_hw.c efct_hw_command_cancel(struct efct_hw *hw) · line 1588
Quoted 12 lines
drivers/scsi/elx/efct/efct_hw.c +12
-0+struct efct_hw *hw = io->hw; + +/* perform common cleanup */ +efct_hw_io_free_common (hw, io); + +spin_lock_irqsave (&hw->io_lock, flags); +/* remove from in-use list */ +if (io->list_entry.next && + !list_empty (&hw->io_inuse)) { +list_del (&io->list_entry); +efct_hw_io_free_move_correct_list (hw, io); + }
This doesn need to be extra indendent and the if condition fits on one line.
Quoted 66 lines
drivers/scsi/elx/efct/efct_hw.c +66
-0+spin_unlock_irqrestore (&hw->io_lock, flags); +} + +int +efct_hw_io_free (struct efct_hw *hw,struct efct_hw_io *io) +{ +return kref_put (&io->ref, io->release); +} + +u8 +efct_hw_io_inuse (struct efct_hw *hw,struct efct_hw_io *io) +{ +return (refcount_read (&io->ref.refcount) >0 ); +} + +struct efct_hw_io * +efct_hw_io_lookup (struct efct_hw *hw,u32 xri) +{ +u32 ioindex; + + ioindex = xri - hw->sli.extent[SLI_RSRC_XRI ].base[0 ]; +return hw->io[ioindex]; +} + +enum efct_hw_rtn +efct_hw_io_register_sgl (struct efct_hw *hw,struct efct_hw_io *io, +struct efc_dma *sgl, +u32 sgl_count) +{ +if (hw->sli.sgl_pre_registered) { +efc_log_err (hw->os, +"can't use temp SGL with pre-registered SGLs\n" ); +return EFCT_HW_RTN_ERROR ; + } + io->ovfl_sgl = sgl; + io->ovfl_sgl_count = sgl_count; + +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_io_init_sges (struct efct_hw *hw,struct efct_hw_io *io, +enum efct_hw_io_type type) +{ +struct sli4_sge *data =NULL ; +u32 i =0 ; +u32 skips =0 ; +u32 sge_flags =0 ; + +if (!io) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p\n" , hw, io); +return EFCT_HW_RTN_ERROR ; + } + +/* Clear / reset the scatter-gather list */ + io->sgl = &io->def_sgl; + io->sgl_count = io->def_sgl_count; + io->first_data_sge =0 ; + +memset (io->sgl->virt,0 ,2 *sizeof (struct sli4_sge )); + io->n_sge =0 ; + io->sge_offset =0 ; + + io->type = type; +
drivers/scsi/elx/efct/efct_hw.c efct_hw_command_cancel(struct efct_hw *hw) · line 1664
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ data = io->sgl->virt; + +/* +* Some IO types have underlying hardware requirements on the order +* of SGEs. Process all special entries here. +*/ +switch (type) { +case EFCT_HW_IO_TARGET_WRITE : +#define EFCT_TARGET_WRITE_SKIPS 2 + skips =EFCT_TARGET_WRITE_SKIPS ;
Move the defines out of the function.
Quoted 539 lines
drivers/scsi/elx/efct/efct_hw.c +484
-0+ +/* populate host resident XFER_RDY buffer */ + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags &= (~SLI4_SGE_TYPE_MASK ); + sge_flags |= (SLI4_SGE_TYPE_DATA <<SLI4_SGE_TYPE_SHIFT ); + data->buffer_address_high = +cpu_to_le32 (upper_32_bits (io->xfer_rdy.phys)); + data->buffer_address_low = +cpu_to_le32 (lower_32_bits (io->xfer_rdy.phys)); + data->buffer_length =cpu_to_le32 (io->xfer_rdy.size); + data->dw2_flags =cpu_to_le32 (sge_flags); + data++; + + skips--; + + io->n_sge =1 ; +break ; +case EFCT_HW_IO_TARGET_READ : +/* +* For FCP_TSEND64, the first 2 entries are SKIP SGE's +*/ +#define EFCT_TARGET_READ_SKIPS 2 + skips =EFCT_TARGET_READ_SKIPS ; +break ; +case EFCT_HW_IO_TARGET_RSP : +/* +* No skips, etc. for FCP_TRSP64 +*/ +break ; +default : +efc_log_err (hw->os,"unsupported IO type %#x\n" , type); +return EFCT_HW_RTN_ERROR ; + } + +/* +* Write skip entries +*/ +for (i =0 ; i < skips; i++) { + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags &= (~SLI4_SGE_TYPE_MASK ); + sge_flags |= (SLI4_SGE_TYPE_SKIP <<SLI4_SGE_TYPE_SHIFT ); + data->dw2_flags =cpu_to_le32 (sge_flags); + data++; + } + + io->n_sge += skips; + +/* +* Set last +*/ + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags |=SLI4_SGE_LAST ; + data->dw2_flags =cpu_to_le32 (sge_flags); + +return EFCT_HW_RTN_SUCCESS ; +} + +enum efct_hw_rtn +efct_hw_io_add_sge (struct efct_hw *hw,struct efct_hw_io *io, +uintptr_t addr,u32 length) +{ +struct sli4_sge *data =NULL ; +u32 sge_flags =0 ; + +if (!io || !addr || !length) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p addr=%lx length=%u\n" , + hw, io, addr, length); +return EFCT_HW_RTN_ERROR ; + } + +if (length > hw->sli.sge_supported_length) { +efc_log_err (hw->os, +"length of SGE %d bigger than allowed %d\n" , + length, hw->sli.sge_supported_length); +return EFCT_HW_RTN_ERROR ; + } + + data = io->sgl->virt; + data += io->n_sge; + + sge_flags =le32_to_cpu (data->dw2_flags); + sge_flags &= ~SLI4_SGE_TYPE_MASK ; + sge_flags |=SLI4_SGE_TYPE_DATA <<SLI4_SGE_TYPE_SHIFT ; + sge_flags &= ~SLI4_SGE_DATA_OFFSET_MASK ; + sge_flags |=SLI4_SGE_DATA_OFFSET_MASK & io->sge_offset; + + data->buffer_address_high =cpu_to_le32 (upper_32_bits (addr)); + data->buffer_address_low =cpu_to_le32 (lower_32_bits (addr)); + data->buffer_length =cpu_to_le32 (length); + +/* +* Always assume this is the last entry and mark as such. +* If this is not the first entry unset the "last SGE" +* indication for the previous entry +*/ + sge_flags |=SLI4_SGE_LAST ; + data->dw2_flags =cpu_to_le32 (sge_flags); + +if (io->n_sge) { + sge_flags =le32_to_cpu (data[-1 ].dw2_flags); + sge_flags &= ~SLI4_SGE_LAST ; + data[-1 ].dw2_flags =cpu_to_le32 (sge_flags); + } + +/* Set first_data_bde if not previously set */ +if (io->first_data_sge ==0 ) + io->first_data_sge = io->n_sge; + + io->sge_offset += length; + io->n_sge++; + +/* Update the linked segment length (only executed after overflow has +* begun) +*/ +if (io->ovfl_lsp) + io->ovfl_lsp->dw3_seglen = +cpu_to_le32 (io->n_sge *sizeof (struct sli4_sge ) & +SLI4_LSP_SGE_SEGLEN ); + +return EFCT_HW_RTN_SUCCESS ; +} + +void +efct_hw_io_abort_all (struct efct_hw *hw) +{ +struct efct_hw_io *io_to_abort =NULL ; +struct efct_hw_io *next_io =NULL ; + +list_for_each_entry_safe (io_to_abort, next_io, + &hw->io_inuse, list_entry) { +efct_hw_io_abort (hw, io_to_abort, true,NULL ,NULL ); + } +} + +static void +efct_hw_wq_process_abort (void *arg,u8 *cqe,int status) +{ +struct efct_hw_io *io = arg; +struct efct_hw *hw = io->hw; +u32 ext =0 ; +u32 len =0 ; +struct hw_wq_callback *wqcb; +unsigned long flags =0 ; + +/* +* For IOs that were aborted internally, we may need to issue the +* callback here depending on whether a XRI_ABORTED CQE is expected ot +* not. If the status is Local Reject/No XRI, then +* issue the callback now. +*/ + ext =sli_fc_ext_status (&hw->sli, cqe); +if (status ==SLI4_FC_WCQE_STATUS_LOCAL_REJECT && + ext ==SLI4_FC_LOCAL_REJECT_NO_XRI && + io->done) { +efct_hw_done_t done = io->done; +void *arg = io->arg; + + io->done =NULL ; + +/* +* Use latched status as this is always saved for an internal +* abort Note: We wont have both a done and abort_done +* function, so don't worry about +* clobbering the len, status and ext fields. +*/ + status = io->saved_status; + len = io->saved_len; + ext = io->saved_ext; + io->status_saved = false; +done (io, io->rnode, len, status, ext, arg); + } + +if (io->abort_done) { +efct_hw_done_t done = io->abort_done; +void *arg = io->abort_arg; + + io->abort_done =NULL ; + +done (io, io->rnode, len, status, ext, arg); + } +spin_lock_irqsave (&hw->io_abort_lock, flags); +/* clear abort bit to indicate abort is complete */ + io->abort_in_progress = false; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); + +/* Free the WQ callback */ +if (io->abort_reqtag ==U32_MAX ) { +efc_log_err (hw->os,"HW IO already freed\n" ); +return ; + } + + wqcb =efct_hw_reqtag_get_instance (hw, io->abort_reqtag); +efct_hw_reqtag_free (hw, wqcb); + +/* +* Call efct_hw_io_free() because this releases the WQ reservation as +* well as doing the refcount put. Don't duplicate the code here. +*/ + (void )efct_hw_io_free (hw, io); +} + +enum efct_hw_rtn +efct_hw_io_abort (struct efct_hw *hw,struct efct_hw_io *io_to_abort, +bool send_abts,void *cb,void *arg) +{ +enum sli4_abort_type atype =SLI_ABORT_MAX ; +u32 id =0 , mask =0 ; +enum efct_hw_rtn rc =EFCT_HW_RTN_SUCCESS ; +struct hw_wq_callback *wqcb; +unsigned long flags =0 ; + +if (!io_to_abort) { +efc_log_err (hw->os, +"bad parameter hw=%p io=%p\n" , + hw, io_to_abort); +return EFCT_HW_RTN_ERROR ; + } + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os,"cannot send IO abort, HW state=%d\n" , + hw->state); +return EFCT_HW_RTN_ERROR ; + } + +/* take a reference on IO being aborted */ +if (kref_get_unless_zero (&io_to_abort->ref) ==0 ) { +/* command no longer active */ +efc_log_test (hw->os, +"io not active xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return EFCT_HW_RTN_IO_NOT_ACTIVE ; + } + +/* Must have a valid WQ reference */ +if (!io_to_abort->wq) { +efc_log_test (hw->os,"io_to_abort xri=0x%x not active on WQ\n" , + io_to_abort->indicator); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +return EFCT_HW_RTN_IO_NOT_ACTIVE ; + } + +/* +* Validation checks complete; now check to see if already being +* aborted +*/ +spin_lock_irqsave (&hw->io_abort_lock, flags); +if (io_to_abort->abort_in_progress) { +spin_unlock_irqrestore (&hw->io_abort_lock, flags); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +efc_log_debug (hw->os, +"io already being aborted xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return EFCT_HW_RTN_IO_ABORT_IN_PROGRESS ; + } + +/* +* This IO is not already being aborted. Set flag so we won't try to +* abort it again. After all, we only have one abort_done callback. +*/ + io_to_abort->abort_in_progress = true; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); + +/* +* If we got here, the possibilities are: +* - host owned xri +* - io_to_abort->wq_index != U32_MAX +* - submit ABORT_WQE to same WQ +* - port owned xri: +* - rxri: io_to_abort->wq_index == U32_MAX +* - submit ABORT_WQE to any WQ +* - non-rxri +* - io_to_abort->index != U32_MAX +* - submit ABORT_WQE to same WQ +* - io_to_abort->index == U32_MAX +* - submit ABORT_WQE to any WQ +*/ + io_to_abort->abort_done = cb; + io_to_abort->abort_arg = arg; + + atype =SLI_ABORT_XRI ; + id = io_to_abort->indicator; + +/* Allocate a request tag for the abort portion of this IO */ + wqcb =efct_hw_reqtag_alloc (hw, efct_hw_wq_process_abort, io_to_abort); +if (!wqcb) { +efc_log_err (hw->os,"can't allocate request tag\n" ); +return EFCT_HW_RTN_NO_RESOURCES ; + } + io_to_abort->abort_reqtag = wqcb->instance_index; + +/* +* If the wqe is on the pending list, then set this wqe to be +* aborted when the IO's wqe is removed from the list. +*/ +if (io_to_abort->wq) { +spin_lock_irqsave (&io_to_abort->wq->queue->lock, flags); +if (io_to_abort->wqe.list_entry.next) { + io_to_abort->wqe.abort_wqe_submit_needed = true; + io_to_abort->wqe.send_abts = send_abts; + io_to_abort->wqe.id = id; + io_to_abort->wqe.abort_reqtag = + io_to_abort->abort_reqtag; +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, + flags); +return EFC_SUCCESS ; + } +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, flags); + } + +if (sli_abort_wqe (&hw->sli, io_to_abort->wqe.wqebuf, + hw->sli.wqe_size, atype, send_abts, id, mask, + io_to_abort->abort_reqtag,SLI4_CQ_DEFAULT )) { +efc_log_err (hw->os,"ABORT WQE error\n" ); + io_to_abort->abort_reqtag =U32_MAX ; +efct_hw_reqtag_free (hw, wqcb); + rc =EFCT_HW_RTN_ERROR ; + } + +if (rc ==EFCT_HW_RTN_SUCCESS ) { + +/* ABORT_WQE does not actually utilize an XRI on the Port, +* therefore, keep xbusy as-is to track the exchange's state, +* not the ABORT_WQE's state +*/ + rc =efct_hw_wq_write (io_to_abort->wq, &io_to_abort->wqe); +if (rc >0 ) +/* non-negative return is success */ + rc =0 ; +/* +* can't abort an abort so skip adding to timed wqe +* list +*/ + } + +if (rc !=EFCT_HW_RTN_SUCCESS ) { +spin_lock_irqsave (&hw->io_abort_lock, flags); + io_to_abort->abort_in_progress = false; +spin_unlock_irqrestore (&hw->io_abort_lock, flags); +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); + } +return rc; +} + +void +efct_hw_reqtag_pool_free (struct efct_hw *hw) +{ +u32 i =0 ; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; +struct hw_wq_callback *wqcb =NULL ; + +if (reqtag_pool) { +for (i =0 ; i <U16_MAX ; i++) { + wqcb = reqtag_pool->tags[i]; +if (!wqcb) +continue ; + +kfree (wqcb); + } +kfree (reqtag_pool); + hw->wq_reqtag_pool =NULL ; + } +} + +struct reqtag_pool * +efct_hw_reqtag_pool_alloc (struct efct_hw *hw) +{ +u32 i =0 ; +struct reqtag_pool *reqtag_pool; +struct hw_wq_callback *wqcb; + + reqtag_pool =kzalloc (sizeof (*reqtag_pool),GFP_KERNEL ); +if (!reqtag_pool) +return NULL ; + +INIT_LIST_HEAD (&reqtag_pool->freelist); +/* initialize reqtag pool lock */ +spin_lock_init (&reqtag_pool->lock); +for (i =0 ; i <U16_MAX ; i++) { + wqcb =kmalloc (sizeof (*wqcb),GFP_KERNEL ); +if (!wqcb) +break ; + + reqtag_pool->tags[i] = wqcb; + wqcb->instance_index = i; + wqcb->callback =NULL ; + wqcb->arg =NULL ; +INIT_LIST_HEAD (&wqcb->list_entry); +list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); + } + +return reqtag_pool; +} + +struct hw_wq_callback * +efct_hw_reqtag_alloc (struct efct_hw *hw, +void (*callback)(void *arg,u8 *cqe,int status), +void *arg) +{ +struct hw_wq_callback *wqcb =NULL ; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; +unsigned long flags =0 ; + +if (!callback) +return wqcb; + +spin_lock_irqsave (&reqtag_pool->lock, flags); + +if (!list_empty (&reqtag_pool->freelist)) { + wqcb =list_first_entry (&reqtag_pool->freelist, + struct hw_wq_callback, list_entry); + } + +if (wqcb) { +list_del (&wqcb->list_entry); +spin_unlock_irqrestore (&reqtag_pool->lock, flags); + wqcb->callback = callback; + wqcb->arg = arg; + }else { +spin_unlock_irqrestore (&reqtag_pool->lock, flags); + } + +return wqcb; +} + +void +efct_hw_reqtag_free (struct efct_hw *hw,struct hw_wq_callback *wqcb) +{ +unsigned long flags =0 ; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; + +if (!wqcb->callback) +efc_log_err (hw->os,"WQCB is already freed\n" ); + +spin_lock_irqsave (&reqtag_pool->lock, flags); + wqcb->callback =NULL ; + wqcb->arg =NULL ; +INIT_LIST_HEAD (&wqcb->list_entry); +list_add (&wqcb->list_entry, &hw->wq_reqtag_pool->freelist); +spin_unlock_irqrestore (&reqtag_pool->lock, flags); +} + +struct hw_wq_callback * +efct_hw_reqtag_get_instance (struct efct_hw *hw,u32 instance_index) +{ +struct hw_wq_callback *wqcb; + + wqcb = hw->wq_reqtag_pool->tags[instance_index]; +if (!wqcb) +efc_log_err (hw->os,"wqcb for instance %d is null\n" , + instance_index); + +return wqcb; +} + +void +efct_hw_reqtag_reset (struct efct_hw *hw) +{ +struct hw_wq_callback *wqcb; +u32 i; +struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; +struct list_head *p, *n; + +/* Remove all from freelist */ +list_for_each_safe (p, n, &reqtag_pool->freelist) { + wqcb = list_entry(p, struct hw_wq_callback, list_entry); + +if (wqcb) +list_del (&wqcb->list_entry); + } + +/* Put them all back */ +for (i =0 ; i <ARRAY_SIZE (reqtag_pool->tags); i++) { + wqcb = reqtag_pool->tags[i]; + wqcb->instance_index = i; + wqcb->callback =NULL ; + wqcb->arg =NULL ; +INIT_LIST_HEAD (&wqcb->list_entry); +list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); + } +}drivers/scsi/elx/efct/efct_hw.h +42
-0@@ -635,5 +635,47 @@ void efct_hw_rx_free(struct efct_hw *hw);extern enum efct_hw_rtn efct_hw_command (struct efct_hw *hw,u8 *cmd,u32 opts,void *cb,void *arg); +struct efct_hw_io *efct_hw_io_alloc (struct efct_hw *hw); +int efct_hw_io_free (struct efct_hw *hw,struct efct_hw_io *io); +u8 efct_hw_io_inuse (struct efct_hw *hw,struct efct_hw_io *io); +extern enum efct_hw_rtn +efct_hw_io_send (struct efct_hw *hw,enum efct_hw_io_type type, +struct efct_hw_io *io,u32 len, +union efct_hw_io_param_u *iparam, +struct efc_remote_node *rnode,void *cb,void *arg); +extern enum efct_hw_rtn +efct_hw_io_register_sgl (struct efct_hw *hw,struct efct_hw_io *io, +struct efc_dma *sgl, +u32 sgl_count); +extern enum efct_hw_rtn +efct_hw_io_init_sges (struct efct_hw *hw, +struct efct_hw_io *io,enum efct_hw_io_type type); + +extern enum efct_hw_rtn +efct_hw_io_add_sge (struct efct_hw *hw,struct efct_hw_io *io, +uintptr_t addr,u32 length); +extern enum efct_hw_rtn +efct_hw_io_abort (struct efct_hw *hw,struct efct_hw_io *io_to_abort, +bool send_abts,void *cb,void *arg); +extern u32 +efct_hw_io_get_count (struct efct_hw *hw, +enum efct_hw_io_count_type io_count_type); +extern struct efct_hw_io +*efct_hw_io_lookup (struct efct_hw *hw,u32 indicator); +void efct_hw_io_abort_all (struct efct_hw *hw); +void efct_hw_io_free_internal (struct kref *arg); + +/* HW WQ request tag API */ +struct reqtag_pool *efct_hw_reqtag_pool_alloc (struct efct_hw *hw); +void efct_hw_reqtag_pool_free (struct efct_hw *hw); +extern struct hw_wq_callback +*efct_hw_reqtag_alloc (struct efct_hw *hw, +void (*callback)(void *arg,u8 *cqe, +int status),void *arg); +extern void +efct_hw_reqtag_free (struct efct_hw *hw,struct hw_wq_callback *wqcb); +extern struct hw_wq_callback +*efct_hw_reqtag_get_instance (struct efct_hw *hw,u32 instance_index); +void efct_hw_reqtag_reset (struct efct_hw *hw);#endif /* __EFCT_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 20/31 elx: efct: Hardware queues processing
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines for EQ, CQ, WQ and RQ processing. Routines for IO object pool allocation and deallocation.
---
v3:
Return defined values
Changed IO pool allocation logic to avoid using efct_pool.
--- drivers/scsi/elx/efct/efct_hw.c | 369 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 36 ++++ drivers/scsi/elx/efct/efct_io.c | 198 +++++++++++++++++++++ drivers/scsi/elx/efct/efct_io.h | 191 +++++++++++++++++++++ 4 files changed, 794 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_io.c create mode 100644 drivers/scsi/elx/efct/efct_io.h
drivers/scsi/elx/efct/efct_hw.c +369 -0
@@ -2146,3 +2146,372 @@ efct_hw_reqtag_reset(struct efct_hw *hw)list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); } } + +int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id) +{ +int rc =-1 ; +int index = id & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* +* Since the hash is always bigger than the maximum number of Qs, then +* we never have to worry about an infinite loop. We will always find +* an unused entry. +*/ +do { +if (hash[index].in_use && + hash[index].id == id) + rc = hash[index].index; +else + index = (index +1 ) & (EFCT_HW_Q_HASH_SIZE -1 ); + }while (rc ==-1 && hash[index].in_use); + +return rc; +} + +int +efct_hw_process (struct efct_hw *hw,u32 vector, +u32 max_isr_time_msec) +{ +struct hw_eq *eq; +int rc =0 ; + +/* +* The caller should disable interrupts if they wish to prevent us +* from processing during a shutdown. The following states are defined: +* EFCT_HW_STATE_UNINITIALIZED - No queues allocated +* EFCT_HW_STATE_QUEUES_ALLOCATED - The state after a chip reset, +* queues are cleared. +* EFCT_HW_STATE_ACTIVE - Chip and queues are operational +* EFCT_HW_STATE_RESET_IN_PROGRESS - reset, we still want completions +* EFCT_HW_STATE_TEARDOWN_IN_PROGRESS - We still want mailbox +* completions. +*/ +if (hw->state ==EFCT_HW_STATE_UNINITIALIZED ) +return EFC_SUCCESS ; + +/* Get pointer to struct hw_eq */ + eq = hw->hw_eq[vector]; +if (!eq) +return EFC_SUCCESS ; + + eq->use_count++; + + rc =efct_hw_eq_process (hw, eq, max_isr_time_msec); + +return rc; +} + +int +efct_hw_eq_process (struct efct_hw *hw,struct hw_eq *eq, +u32 max_isr_time_msec) +{ +u8 eqe[sizeof (struct sli4_eqe )] = {0 }; +u32 tcheck_count; +time_t tstart; +time_t telapsed; +bool done = false; + + tcheck_count =EFCT_HW_TIMECHECK_ITERATIONS ; + tstart =jiffies_to_msecs (jiffies); + +while (!done && !sli_eq_read (&hw->sli, eq->queue, eqe)) { +u16 cq_id =0 ; +int rc; + + rc =sli_eq_parse (&hw->sli, eqe, &cq_id); +if (unlikely (rc)) { +if (rc ==SLI4_EQE_STATUS_EQ_FULL ) { +u32 i; + +/* +* Received a sentinel EQE indicating the +* EQ is full. Process all CQs +*/ +for (i =0 ; i < hw->cq_count; i++) +efct_hw_cq_process (hw, hw->hw_cq[i]); +continue ; + }else { +return rc; + } + }else { +int index; + + index =efct_hw_queue_hash_find (hw->cq_hash, cq_id); + +if (likely (index >=0 )) +efct_hw_cq_process (hw, hw->hw_cq[index]); +else +efc_log_err (hw->os,"bad CQ_ID %#06x\n" , + cq_id); + } + +if (eq->queue->n_posted > eq->queue->posted_limit) +sli_queue_arm (&hw->sli, eq->queue, false); + +if (tcheck_count && (--tcheck_count ==0 )) { + tcheck_count =EFCT_HW_TIMECHECK_ITERATIONS ; + telapsed =jiffies_to_msecs (jiffies) - tstart; +if (telapsed >= max_isr_time_msec) + done = true; + } + } +sli_queue_eq_arm (&hw->sli, eq->queue, true); + +return EFC_SUCCESS ; +} + +static int +_efct_hw_wq_write (struct hw_wq *wq,struct efct_hw_wqe *wqe) +{ +int queue_rc; + +/* Every so often, set the wqec bit to generate comsummed completions */ +if (wq->wqec_count) + wq->wqec_count--; + +if (wq->wqec_count ==0 ) { +struct sli4_generic_wqe *genwqe = (void *)wqe->wqebuf; + + genwqe->cmdtype_wqec_byte |=SLI4_GEN_WQE_WQEC ; + wq->wqec_count = wq->wqec_set_count; + } + +/* Decrement WQ free count */ + wq->free_count--; + + queue_rc =sli_wq_write (&wq->hw->sli, wq->queue, wqe->wqebuf); + +return (queue_rc <0 ) ?-1 :0 ; +} + +static void +hw_wq_submit_pending (struct hw_wq *wq,u32 update_free_count) +{ +struct efct_hw_wqe *wqe; +unsigned long flags =0 ; + +spin_lock_irqsave (&wq->queue->lock, flags); + +/* Update free count with value passed in */ + wq->free_count += update_free_count; + +while ((wq->free_count >0 ) && (!list_empty (&wq->pending_list))) { + wqe =list_first_entry (&wq->pending_list, + struct efct_hw_wqe, list_entry); +list_del (&wqe->list_entry); +_efct_hw_wq_write (wq, wqe); + +if (wqe->abort_wqe_submit_needed) { + wqe->abort_wqe_submit_needed = false; +sli_abort_wqe (&wq->hw->sli, wqe->wqebuf, + wq->hw->sli.wqe_size, +SLI_ABORT_XRI , wqe->send_abts, wqe->id, +0 , wqe->abort_reqtag,SLI4_CQ_DEFAULT ); +INIT_LIST_HEAD (&wqe->list_entry); +list_add_tail (&wqe->list_entry, &wq->pending_list); + wq->wq_pending_count++; + } + } + +spin_unlock_irqrestore (&wq->queue->lock, flags); +} + +void +efct_hw_cq_process (struct efct_hw *hw,struct hw_cq *cq) +{ +u8 cqe[sizeof (struct sli4_mcqe )]; +u16 rid =U16_MAX ; +enum sli4_qentry ctype;/* completion type */ +int status; +u32 n_processed =0 ; +u32 tstart, telapsed; + + tstart =jiffies_to_msecs (jiffies); + +while (!sli_cq_read (&hw->sli, cq->queue, cqe)) { + status =sli_cq_parse (&hw->sli, cq->queue, + cqe, &ctype, &rid); +/* +* The sign of status is significant. If status is: +* == 0 : call completed correctly and +* the CQE indicated success +* > 0 : call completed correctly and +* the CQE indicated an error +* < 0 : call failed and no information is available about the +* CQE +*/ +if (status <0 ) { +if (status ==SLI4_MCQE_STATUS_NOT_COMPLETED ) +/* +* Notification that an entry was consumed, +* but not completed +*/ +continue ; + +break ; + } + +switch (ctype) { +case SLI_QENTRY_ASYNC : +sli_cqe_async (&hw->sli, cqe); +break ; +case SLI_QENTRY_MQ : +/* +* Process MQ entry. Note there is no way to determine +* the MQ_ID from the completion entry. +*/ +efct_hw_mq_process (hw, status, hw->mq); +break ; +case SLI_QENTRY_WQ : +efct_hw_wq_process (hw, cq, cqe, status, rid); +break ; +case SLI_QENTRY_WQ_RELEASE : { +u32 wq_id = rid; +int index; +struct hw_wq *wq =NULL ; + + index =efct_hw_queue_hash_find (hw->wq_hash, wq_id); + +if (likely (index >=0 )) { + wq = hw->hw_wq[index]; + }else { +efc_log_err (hw->os,"bad WQ_ID %#06x\n" , wq_id); +break ; + } +/* Submit any HW IOs that are on the WQ pending list */ +hw_wq_submit_pending (wq, wq->wqec_set_count); + +break ; + } + +case SLI_QENTRY_RQ : +efct_hw_rqpair_process_rq (hw, cq, cqe); +break ; +case SLI_QENTRY_XABT : { +efct_hw_xabt_process (hw, cq, cqe, rid); +break ; + } +default : +efc_log_test (hw->os, +"unhandled ctype=%#x rid=%#x\n" , + ctype, rid); +break ; + } + + n_processed++; +if (n_processed == cq->queue->proc_limit) +break ; + +if (cq->queue->n_posted >= cq->queue->posted_limit) +sli_queue_arm (&hw->sli, cq->queue, false); + } + +sli_queue_arm (&hw->sli, cq->queue, true); + +if (n_processed > cq->queue->max_num_processed) + cq->queue->max_num_processed = n_processed; + telapsed =jiffies_to_msecs (jiffies) - tstart; +if (telapsed > cq->queue->max_process_time) + cq->queue->max_process_time = telapsed; +} + +void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid) +{ +struct hw_wq_callback *wqcb; + +if (rid ==EFCT_HW_REQUE_XRI_REGTAG ) { +if (status) +efc_log_err (hw->os,"reque xri failed, status = %d\n" , + status); +return ; + } + + wqcb =efct_hw_reqtag_get_instance (hw, rid); +if (!wqcb) { +efc_log_err (hw->os,"invalid request tag: x%x\n" , rid); +return ; + } + +if (!wqcb->callback) { +efc_log_err (hw->os,"wqcb callback is NULL\n" ); +return ; + } + + (*wqcb->callback)(wqcb->arg, cqe, status); +} + +void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid) +{ +/* search IOs wait free list */ +struct efct_hw_io *io =NULL ; +unsigned long flags =0 ; + + io =efct_hw_io_lookup (hw, rid); +if (!io) { +/* IO lookup failure should never happen */ +efc_log_err (hw->os, +"Error: xabt io lookup failed rid=%#x\n" , rid); +return ; + } + +if (!io->xbusy) +efc_log_debug (hw->os,"xabt io not busy rid=%#x\n" , rid); +else +/* mark IO as no longer busy */ + io->xbusy = false; + +/* +* For IOs that were aborted internally, we need to issue any pending +* callback here. +*/ +if (io->done) { +efct_hw_done_t done = io->done; +void *arg = io->arg; + +/* +* Use latched status as this is always saved for an internal +* abort +*/ +int status = io->saved_status; +u32 len = io->saved_len; +u32 ext = io->saved_ext; + + io->done =NULL ; + io->status_saved = false; + +done (io, io->rnode, len, status, ext, arg); + } + +spin_lock_irqsave (&hw->io_lock, flags); +if (io->state ==EFCT_HW_IO_STATE_INUSE || + io->state ==EFCT_HW_IO_STATE_WAIT_FREE ) { +/* if on wait_free list, caller has already freed IO; +* remove from wait_free list and add to free list. +* if on in-use list, already marked as no longer busy; +* just leave there and wait for caller to free. +*/ +if (io->state ==EFCT_HW_IO_STATE_WAIT_FREE ) { + io->state =EFCT_HW_IO_STATE_FREE ; +list_del (&io->list_entry); +efct_hw_io_free_move_correct_list (hw, io); + } + } +spin_unlock_irqrestore (&hw->io_lock, flags); +} + +static int +efct_hw_flush (struct efct_hw *hw) +{ +u32 i =0 ; + +/* Process any remaining completions */ +for (i =0 ; i < hw->eq_count; i++) +efct_hw_process (hw, i, ~0 ); + +return EFC_SUCCESS ; +}
drivers/scsi/elx/efct/efct_hw.h +36 -0
@@ -678,4 +678,40 @@ extern struct hw_wq_callback *efct_hw_reqtag_get_instance(struct efct_hw *hw, u32 instance_index);void efct_hw_reqtag_reset (struct efct_hw *hw); +/* RQ completion handlers for RQ pair mode */ +extern int +efct_hw_rqpair_process_rq (struct efct_hw *hw, +struct hw_cq *cq,u8 *cqe); +extern +enum efct_hw_rtn efct_hw_rqpair_sequence_free (struct efct_hw *hw, +struct efc_hw_sequence *seq); +static inline void +efct_hw_sequence_copy (struct efc_hw_sequence *dst, +struct efc_hw_sequence *src) +{ +/* Copy src to dst, then zero out the linked list link */ + *dst = *src; +} + +static inline enum efct_hw_rtn +efct_hw_sequence_free (struct efct_hw *hw,struct efc_hw_sequence *seq) +{ +/* Only RQ pair mode is supported */ +return efct_hw_rqpair_sequence_free (hw, seq); +} +extern int +efct_hw_eq_process (struct efct_hw *hw,struct hw_eq *eq, +u32 max_isr_time_msec); +void efct_hw_cq_process (struct efct_hw *hw,struct hw_cq *cq); +extern void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid); +extern void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid); +extern int +efct_hw_process (struct efct_hw *hw,u32 vector,u32 max_isr_time_msec); +extern int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id); +#endif /* __EFCT_H__ */
drivers/scsi/elx/efct/efct_io.c new file +198 -0
198 lines not on this page · raw message
drivers/scsi/elx/efct/efct_io.h new file +191 -0
191 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 20/31] elx: efct: Hardware queues processing
Quoted 183 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines for EQ, CQ, WQ and RQ processing. Routines for IO object pool allocation and deallocation.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Return defined values
Changed IO pool allocation logic to avoid usingefct_pool.--- drivers/scsi/elx/efct/efct_hw.c | 369 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 36 ++++ drivers/scsi/elx/efct/efct_io.c | 198 +++++++++++++++++++++ drivers/scsi/elx/efct/efct_io.h | 191 +++++++++++++++++++++ 4 files changed, 794 insertions(+)create mode 100644
drivers/scsi/elx/efct/efct_io.ccreate mode 100644drivers/scsi/elx/efct/efct_io.hdrivers/scsi/elx/efct/efct_hw.c +153
-0@@ -2146,3 +2146,372 @@ efct_hw_reqtag_reset(struct efct_hw *hw)list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); } } + +int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id) +{ +int rc =-1 ; +int index = id & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* +* Since the hash is always bigger than the maximum number of Qs, then +* we never have to worry about an infinite loop. We will always find +* an unused entry. +*/ +do { +if (hash[index].in_use && + hash[index].id == id) + rc = hash[index].index; +else + index = (index +1 ) & (EFCT_HW_Q_HASH_SIZE -1 ); + }while (rc ==-1 && hash[index].in_use); + +return rc; +} + +int +efct_hw_process (struct efct_hw *hw,u32 vector, +u32 max_isr_time_msec) +{ +struct hw_eq *eq; +int rc =0 ; + +/* +* The caller should disable interrupts if they wish to prevent us +* from processing during a shutdown. The following states are defined: +* EFCT_HW_STATE_UNINITIALIZED - No queues allocated +* EFCT_HW_STATE_QUEUES_ALLOCATED - The state after a chip reset, +* queues are cleared. +* EFCT_HW_STATE_ACTIVE - Chip and queues are operational +* EFCT_HW_STATE_RESET_IN_PROGRESS - reset, we still want completions +* EFCT_HW_STATE_TEARDOWN_IN_PROGRESS - We still want mailbox +* completions. +*/ +if (hw->state ==EFCT_HW_STATE_UNINITIALIZED ) +return EFC_SUCCESS ; + +/* Get pointer to struct hw_eq */ + eq = hw->hw_eq[vector]; +if (!eq) +return EFC_SUCCESS ; + + eq->use_count++; + + rc =efct_hw_eq_process (hw, eq, max_isr_time_msec); + +return rc; +} + +int +efct_hw_eq_process (struct efct_hw *hw,struct hw_eq *eq, +u32 max_isr_time_msec) +{ +u8 eqe[sizeof (struct sli4_eqe )] = {0 }; +u32 tcheck_count; +time_t tstart; +time_t telapsed; +bool done = false; + + tcheck_count =EFCT_HW_TIMECHECK_ITERATIONS ; + tstart =jiffies_to_msecs (jiffies); + +while (!done && !sli_eq_read (&hw->sli, eq->queue, eqe)) { +u16 cq_id =0 ; +int rc; + + rc =sli_eq_parse (&hw->sli, eqe, &cq_id); +if (unlikely (rc)) { +if (rc ==SLI4_EQE_STATUS_EQ_FULL ) { +u32 i; + +/* +* Received a sentinel EQE indicating the +* EQ is full. Process all CQs +*/ +for (i =0 ; i < hw->cq_count; i++) +efct_hw_cq_process (hw, hw->hw_cq[i]); +continue ; + }else { +return rc; + } + }else { +int index; + + index =efct_hw_queue_hash_find (hw->cq_hash, cq_id); + +if (likely (index >=0 )) +efct_hw_cq_process (hw, hw->hw_cq[index]); +else +efc_log_err (hw->os,"bad CQ_ID %#06x\n" , + cq_id); + } + +if (eq->queue->n_posted > eq->queue->posted_limit) +sli_queue_arm (&hw->sli, eq->queue, false); + +if (tcheck_count && (--tcheck_count ==0 )) { + tcheck_count =EFCT_HW_TIMECHECK_ITERATIONS ; + telapsed =jiffies_to_msecs (jiffies) - tstart; +if (telapsed >= max_isr_time_msec) + done = true; + } + } +sli_queue_eq_arm (&hw->sli, eq->queue, true); + +return EFC_SUCCESS ; +} + +static int +_efct_hw_wq_write (struct hw_wq *wq,struct efct_hw_wqe *wqe) +{ +int queue_rc; + +/* Every so often, set the wqec bit to generate comsummed completions */ +if (wq->wqec_count) + wq->wqec_count--; + +if (wq->wqec_count ==0 ) { +struct sli4_generic_wqe *genwqe = (void *)wqe->wqebuf; + + genwqe->cmdtype_wqec_byte |=SLI4_GEN_WQE_WQEC ; + wq->wqec_count = wq->wqec_set_count; + } + +/* Decrement WQ free count */ + wq->free_count--; + + queue_rc =sli_wq_write (&wq->hw->sli, wq->queue, wqe->wqebuf); + +return (queue_rc <0 ) ?-1 :0 ; +} + +static void +hw_wq_submit_pending (struct hw_wq *wq,u32 update_free_count) +{ +struct efct_hw_wqe *wqe; +unsigned long flags =0 ; + +spin_lock_irqsave (&wq->queue->lock, flags); + +/* Update free count with value passed in */ + wq->free_count += update_free_count; + +while ((wq->free_count >0 ) && (!list_empty (&wq->pending_list))) { + wqe =list_first_entry (&wq->pending_list, + struct efct_hw_wqe, list_entry);
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2311
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+list_del (&wqe->list_entry); +_efct_hw_wq_write (wq, wqe); + +if (wqe->abort_wqe_submit_needed) { + wqe->abort_wqe_submit_needed = false; +sli_abort_wqe (&wq->hw->sli, wqe->wqebuf, + wq->hw->sli.wqe_size, +SLI_ABORT_XRI , wqe->send_abts, wqe->id, +0 , wqe->abort_reqtag,SLI4_CQ_DEFAULT ); +INIT_LIST_HEAD (&wqe->list_entry);
See? Would could drop at least 4 arguments by passing in the wqe directly ...
Quoted 643 lines
drivers/scsi/elx/efct/efct_hw.c +206
-0+list_add_tail (&wqe->list_entry, &wq->pending_list); + wq->wq_pending_count++; + } + } + +spin_unlock_irqrestore (&wq->queue->lock, flags); +} + +void +efct_hw_cq_process (struct efct_hw *hw,struct hw_cq *cq) +{ +u8 cqe[sizeof (struct sli4_mcqe )]; +u16 rid =U16_MAX ; +enum sli4_qentry ctype;/* completion type */ +int status; +u32 n_processed =0 ; +u32 tstart, telapsed; + + tstart =jiffies_to_msecs (jiffies); + +while (!sli_cq_read (&hw->sli, cq->queue, cqe)) { + status =sli_cq_parse (&hw->sli, cq->queue, + cqe, &ctype, &rid); +/* +* The sign of status is significant. If status is: +* == 0 : call completed correctly and +* the CQE indicated success +* > 0 : call completed correctly and +* the CQE indicated an error +* < 0 : call failed and no information is available about the +* CQE +*/ +if (status <0 ) { +if (status ==SLI4_MCQE_STATUS_NOT_COMPLETED ) +/* +* Notification that an entry was consumed, +* but not completed +*/ +continue ; + +break ; + } + +switch (ctype) { +case SLI_QENTRY_ASYNC : +sli_cqe_async (&hw->sli, cqe); +break ; +case SLI_QENTRY_MQ : +/* +* Process MQ entry. Note there is no way to determine +* the MQ_ID from the completion entry. +*/ +efct_hw_mq_process (hw, status, hw->mq); +break ; +case SLI_QENTRY_WQ : +efct_hw_wq_process (hw, cq, cqe, status, rid); +break ; +case SLI_QENTRY_WQ_RELEASE : { +u32 wq_id = rid; +int index; +struct hw_wq *wq =NULL ; + + index =efct_hw_queue_hash_find (hw->wq_hash, wq_id); + +if (likely (index >=0 )) { + wq = hw->hw_wq[index]; + }else { +efc_log_err (hw->os,"bad WQ_ID %#06x\n" , wq_id); +break ; + } +/* Submit any HW IOs that are on the WQ pending list */ +hw_wq_submit_pending (wq, wq->wqec_set_count); + +break ; + } + +case SLI_QENTRY_RQ : +efct_hw_rqpair_process_rq (hw, cq, cqe); +break ; +case SLI_QENTRY_XABT : { +efct_hw_xabt_process (hw, cq, cqe, rid); +break ; + } +default : +efc_log_test (hw->os, +"unhandled ctype=%#x rid=%#x\n" , + ctype, rid); +break ; + } + + n_processed++; +if (n_processed == cq->queue->proc_limit) +break ; + +if (cq->queue->n_posted >= cq->queue->posted_limit) +sli_queue_arm (&hw->sli, cq->queue, false); + } + +sli_queue_arm (&hw->sli, cq->queue, true); + +if (n_processed > cq->queue->max_num_processed) + cq->queue->max_num_processed = n_processed; + telapsed =jiffies_to_msecs (jiffies) - tstart; +if (telapsed > cq->queue->max_process_time) + cq->queue->max_process_time = telapsed; +} + +void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid) +{ +struct hw_wq_callback *wqcb; + +if (rid ==EFCT_HW_REQUE_XRI_REGTAG ) { +if (status) +efc_log_err (hw->os,"reque xri failed, status = %d\n" , + status); +return ; + } + + wqcb =efct_hw_reqtag_get_instance (hw, rid); +if (!wqcb) { +efc_log_err (hw->os,"invalid request tag: x%x\n" , rid); +return ; + } + +if (!wqcb->callback) { +efc_log_err (hw->os,"wqcb callback is NULL\n" ); +return ; + } + + (*wqcb->callback)(wqcb->arg, cqe, status); +} + +void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid) +{ +/* search IOs wait free list */ +struct efct_hw_io *io =NULL ; +unsigned long flags =0 ; + + io =efct_hw_io_lookup (hw, rid); +if (!io) { +/* IO lookup failure should never happen */ +efc_log_err (hw->os, +"Error: xabt io lookup failed rid=%#x\n" , rid); +return ; + } + +if (!io->xbusy) +efc_log_debug (hw->os,"xabt io not busy rid=%#x\n" , rid); +else +/* mark IO as no longer busy */ + io->xbusy = false; + +/* +* For IOs that were aborted internally, we need to issue any pending +* callback here. +*/ +if (io->done) { +efct_hw_done_t done = io->done; +void *arg = io->arg; + +/* +* Use latched status as this is always saved for an internal +* abort +*/ +int status = io->saved_status; +u32 len = io->saved_len; +u32 ext = io->saved_ext; + + io->done =NULL ; + io->status_saved = false; + +done (io, io->rnode, len, status, ext, arg); + } + +spin_lock_irqsave (&hw->io_lock, flags); +if (io->state ==EFCT_HW_IO_STATE_INUSE || + io->state ==EFCT_HW_IO_STATE_WAIT_FREE ) { +/* if on wait_free list, caller has already freed IO; +* remove from wait_free list and add to free list. +* if on in-use list, already marked as no longer busy; +* just leave there and wait for caller to free. +*/ +if (io->state ==EFCT_HW_IO_STATE_WAIT_FREE ) { + io->state =EFCT_HW_IO_STATE_FREE ; +list_del (&io->list_entry); +efct_hw_io_free_move_correct_list (hw, io); + } + } +spin_unlock_irqrestore (&hw->io_lock, flags); +} + +static int +efct_hw_flush (struct efct_hw *hw) +{ +u32 i =0 ; + +/* Process any remaining completions */ +for (i =0 ; i < hw->eq_count; i++) +efct_hw_process (hw, i, ~0 ); + +return EFC_SUCCESS ; +}drivers/scsi/elx/efct/efct_hw.h +36
-0@@ -678,4 +678,40 @@ extern struct hw_wq_callback *efct_hw_reqtag_get_instance(struct efct_hw *hw, u32 instance_index);void efct_hw_reqtag_reset (struct efct_hw *hw); +/* RQ completion handlers for RQ pair mode */ +extern int +efct_hw_rqpair_process_rq (struct efct_hw *hw, +struct hw_cq *cq,u8 *cqe); +extern +enum efct_hw_rtn efct_hw_rqpair_sequence_free (struct efct_hw *hw, +struct efc_hw_sequence *seq); +static inline void +efct_hw_sequence_copy (struct efc_hw_sequence *dst, +struct efc_hw_sequence *src) +{ +/* Copy src to dst, then zero out the linked list link */ + *dst = *src; +} + +static inline enum efct_hw_rtn +efct_hw_sequence_free (struct efct_hw *hw,struct efc_hw_sequence *seq) +{ +/* Only RQ pair mode is supported */ +return efct_hw_rqpair_sequence_free (hw, seq); +} +extern int +efct_hw_eq_process (struct efct_hw *hw,struct hw_eq *eq, +u32 max_isr_time_msec); +void efct_hw_cq_process (struct efct_hw *hw,struct hw_cq *cq); +extern void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid); +extern void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid); +extern int +efct_hw_process (struct efct_hw *hw,u32 vector,u32 max_isr_time_msec); +extern int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id); +#endif /* __EFCT_H__ */ drivers/scsi/elx/efct/efct_io.c new file +198
-0@@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_hw.h" +#include "efct_io.h" + +struct efct_io_pool { +struct efct *efct; +spinlock_t lock;/* IO pool lock */ +u32 io_num_ios;/* Total IOs allocated */ +struct efct_io *ios[EFCT_NUM_SCSI_IOS ]; +struct list_head freelist; + +}; + +struct efct_io_pool * +efct_io_pool_create (struct efct *efct,u32 num_sgl) +{ +u32 i =0 ; +struct efct_io_pool *io_pool; +struct efct_io *io; + +/* Allocate the IO pool */ + io_pool =kzalloc (sizeof (*io_pool),GFP_KERNEL ); +if (!io_pool) +return NULL ; + + io_pool->efct = efct; +INIT_LIST_HEAD (&io_pool->freelist); +/* initialize IO pool lock */ +spin_lock_init (&io_pool->lock); + +for (i =0 ; i <EFCT_NUM_SCSI_IOS ; i++) { + io =kmalloc (sizeof (*io),GFP_KERNEL ); +if (!io) +break ; + + io_pool->io_num_ios++; + io_pool->ios[i] = io; + io->tag = i; + io->instance_index = i; + +/* Allocate a response buffer */ + io->rspbuf.size =SCSI_RSP_BUF_LENGTH ; + io->rspbuf.virt =dma_alloc_coherent (&efct->pcidev->dev, + io->rspbuf.size, + &io->rspbuf.phys,GFP_DMA ); +if (!io->rspbuf.virt) { +efc_log_err (efct,"dma_alloc rspbuf failed\n" ); +efct_io_pool_free (io_pool); +return NULL ; + } + +/* Allocate SGL */ + io->sgl =kzalloc (sizeof (*io->sgl) * num_sgl,GFP_ATOMIC ); +if (!io->sgl) { +efct_io_pool_free (io_pool); +return NULL ; + } + +memset (io->sgl,0 ,sizeof (*io->sgl) * num_sgl); + io->sgl_allocated = num_sgl; + io->sgl_count =0 ; + +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &io_pool->freelist); + } + +return io_pool; +} + +int +efct_io_pool_free (struct efct_io_pool *io_pool) +{ +struct efct *efct; +u32 i; +struct efct_io *io; + +if (io_pool) { + efct = io_pool->efct; + +for (i =0 ; i < io_pool->io_num_ios; i++) { + io = io_pool->ios[i]; +if (!io) +continue ; + +kfree (io->sgl); +dma_free_coherent (&efct->pcidev->dev, + io->rspbuf.size, io->rspbuf.virt, + io->rspbuf.phys); +memset (&io->rspbuf,0 ,sizeof (struct efc_dma )); + } + +kfree (io_pool); + efct->xport->io_pool =NULL ; + } + +return EFC_SUCCESS ; +} + +u32 efct_io_pool_allocated (struct efct_io_pool *io_pool) +{ +return io_pool->io_num_ios; +} + +struct efct_io * +efct_io_pool_io_alloc (struct efct_io_pool *io_pool) +{ +struct efct_io *io =NULL ; +struct efct *efct; +unsigned long flags =0 ; + + efct = io_pool->efct; + +spin_lock_irqsave (&io_pool->lock, flags); + +if (!list_empty (&io_pool->freelist)) { + io = list_first_entry(&io_pool->freelist, struct efct_io, + list_entry); + } + +if (io) { +list_del (&io->list_entry); +spin_unlock_irqrestore (&io_pool->lock, flags); + + io->io_type =EFCT_IO_TYPE_MAX ; + io->hio_type =EFCT_HW_IO_MAX ; + io->hio =NULL ; + io->transferred =0 ; + io->efct = efct; + io->timeout =0 ; + io->sgl_count =0 ; + io->tgt_task_tag =0 ; + io->init_task_tag =0 ; + io->hw_tag =0 ; + io->display_name ="pending" ; + io->seq_init =0 ; + io->els_req_free = false; + io->io_free =0 ; + io->release =NULL ; +atomic_add_return (1 , &efct->xport->io_active_count); +atomic_add_return (1 , &efct->xport->io_total_alloc); + }else { +spin_unlock_irqrestore (&io_pool->lock, flags); + } +return io; +} + +/* Free an object used to track an IO */ +void +efct_io_pool_io_free (struct efct_io_pool *io_pool,struct efct_io *io) +{ +struct efct *efct; +struct efct_hw_io *hio =NULL ; +unsigned long flags =0 ; + + efct = io_pool->efct; + +spin_lock_irqsave (&io_pool->lock, flags); + hio = io->hio; + io->hio =NULL ; + io->io_free =1 ; +INIT_LIST_HEAD (&io->list_entry); +list_add (&io->list_entry, &io_pool->freelist); +spin_unlock_irqrestore (&io_pool->lock, flags); + +if (hio) +efct_hw_io_free (&efct->hw, hio); + +atomic_sub_return (1 , &efct->xport->io_active_count); +atomic_add_return (1 , &efct->xport->io_total_free); +} + +/* Find an I/O given it's node and ox_id */ +struct efct_io * +efct_io_find_tgt_io (struct efct *efct,struct efc_node *node, +u16 ox_id,u16 rx_id) +{ +struct efct_io *io =NULL ; +unsigned long flags =0 ; +u8 found = false; + +spin_lock_irqsave (&node->active_ios_lock, flags); +list_for_each_entry (io, &node->active_ios, list_entry) { +if ((io->cmd_tgt && io->init_task_tag == ox_id) && + (rx_id ==0xffff || io->tgt_task_tag == rx_id)) { +if (kref_get_unless_zero (&io->ref)) + found = true; +break ; + } + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return found ? io :NULL ; +}drivers/scsi/elx/efct/efct_io.h new file +181
-0@@ -0,0 +1,191 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_IO_H__) +#define __EFCT_IO_H__ + +#include "efct_lio.h" + +#define EFCT_LOG_ENABLE_IO_ERRORS (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 6)) != 0) : 0) + +#define io_error_log (io, fmt, ...) \ + do { \ + if (EFCT_LOG_ENABLE_IO_ERRORS(io->efct)) \ + efc_log_warn(io->efct, fmt, ##__VA_ARGS__); \ + } while (0) + +#define SCSI_CMD_BUF_LENGTH 48 +#define SCSI_RSP_BUF_LENGTH (FCP_RESP_WITH_EXT + SCSI_SENSE_BUFFERSIZE) +#define EFCT_NUM_SCSI_IOS 8192 + +enum efct_io_type { +EFCT_IO_TYPE_IO =0 , +EFCT_IO_TYPE_ELS , +EFCT_IO_TYPE_CT , +EFCT_IO_TYPE_CT_RESP , +EFCT_IO_TYPE_BLS_RESP , +EFCT_IO_TYPE_ABORT , + +EFCT_IO_TYPE_MAX , +}; + +enum efct_els_state { +EFCT_ELS_REQUEST =0 , +EFCT_ELS_REQUEST_DELAYED , +EFCT_ELS_REQUEST_DELAY_ABORT , +EFCT_ELS_REQ_ABORT , +EFCT_ELS_REQ_ABORTED , +EFCT_ELS_ABORT_IO_COMPL , +}; + +struct efct_io { +struct list_head list_entry; +struct list_head io_pending_link; +/* reference counter and callback function */ +struct kref ref; +void (*release)(struct kref *arg); +/* pointer back to efct */ +struct efct *efct; +/* unique instance index value */ +u32 instance_index; +/* display name */ +const char *display_name; +/* pointer to node */ +struct efc_node *node; +/* (io_pool->io_free_list) free list link */ +/* initiator task tag (OX_ID) for back-end and SCSI logging */ +u32 init_task_tag; +/* target task tag (RX_ID) - for back-end and SCSI logging */ +u32 tgt_task_tag; +/* HW layer unique IO id - for back-end and SCSI logging */ +u32 hw_tag; +/* unique IO identifier */ +u32 tag; +/* SGL */ +struct efct_scsi_sgl *sgl; +/* Number of allocated SGEs */ +u32 sgl_allocated; +/* Number of SGEs in this SGL */ +u32 sgl_count; +/* backend target private IO data */ +struct efct_scsi_tgt_io tgt_io; +/* expected data transfer length, based on FC header */ +u32 exp_xfer_len; + +/* Declarations private to HW/SLI */ +void *hw_priv; + +/* indicates what this struct efct_io structure is used for */ +enum efct_io_type io_type; +struct efct_hw_io *hio; +size_t transferred; + +/* set if auto_trsp was set */ +bool auto_resp; +/* set if low latency request */ +bool low_latency; +/* selected WQ steering request */ +u8 wq_steering; +/* selected WQ class if steering is class */ +u8 wq_class; +/* transfer size for current request */ +u64 xfer_req; +/* target callback function */ +efct_scsi_io_cb_t scsi_tgt_cb; +/* target callback function argument */ +void *scsi_tgt_cb_arg; +/* abort callback function */ +efct_scsi_io_cb_t abort_cb; +/* abort callback function argument */ +void *abort_cb_arg; +/* BLS callback function */ +efct_scsi_io_cb_t bls_cb; +/* BLS callback function argument */ +void *bls_cb_arg; +/* TMF command being processed */ +enum efct_scsi_tmf_cmd tmf_cmd; +/* rx_id from the ABTS that initiated the command abort */ +u16 abort_rx_id; + +/* True if this is a Target command */ +bool cmd_tgt; +/* when aborting, indicates ABTS is to be sent */ +bool send_abts; +/* True if this is an Initiator command */ +bool cmd_ini; +/* True if local node has sequence initiative */ +bool seq_init; +/* iparams for hw io send call */ +union efct_hw_io_param_u iparam; +/* HW IO type */ +enum efct_hw_io_type hio_type; +/* wire length */ +u64 wire_len; +/* saved HW callback */ +void *hw_cb; + +/* for ELS requests/responses */ +/* True if ELS is pending */ +bool els_pend; +/* True if ELS is active */ +bool els_active; +/* ELS request payload buffer */ +struct efc_dma els_req; +/* ELS response payload buffer */ +struct efc_dma els_rsp; +bool els_req_free; +/* Retries remaining */ +u32 els_retries_remaining; +void (*els_callback)(struct efc_node *node, +struct efc_node_cb *cbdata,void *cbarg); +void *els_callback_arg; +/* timeout */ +u32 els_timeout_sec; + +/* delay timer */ +struct timer_list delay_timer; + +/* for abort handling */ +/* pointer to IO to abort */ +struct efct_io *io_to_abort; + +enum efct_els_state state; +/* Protects els cmds */ +spinlock_t els_lock; + +/* SCSI Response buffer */ +struct efc_dma rspbuf; +/* Timeout value in seconds for this IO */ +u32 timeout; +/* CS_CTL priority for this IO */ +u8 cs_ctl; +/* Is io object in freelist > */ +u8 io_free; +u32 app_id; +}; + +struct efct_io_cb_arg { +int status;/* completion status */ +int ext_status;/* extended completion status */ +void *app;/* application argument */ +}; + +struct efct_io_pool * +efct_io_pool_create (struct efct *efct,u32 num_sgl); +extern int +efct_io_pool_free (struct efct_io_pool *io_pool); +extern u32
drivers/scsi/elx/efct/efct_io.h line 191
Quoted 10 lines
drivers/scsi/elx/efct/efct_io.h new file +10
-0+efct_io_pool_allocated(struct efct_io_pool *io_pool); + +extern struct efct_io * +efct_io_pool_io_alloc (struct efct_io_pool *io_pool); +extern void +efct_io_pool_io_free (struct efct_io_pool *io_pool,struct efct_io *io); +extern struct efct_io * +efct_io_find_tgt_io (struct efct *efct,struct efc_node *node, +u16 ox_id,u16 rx_id); +#endif /* __EFCT_IO_H__ */
Other than that:
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 20/31] elx: efct: Hardware queues processing
In reply to James SmartQuoted 27 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines for EQ, CQ, WQ and RQ processing. Routines for IO object pool allocation and deallocation.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Return defined values
Changed IO pool allocation logic to avoid usingefct_pool.--- drivers/scsi/elx/efct/efct_hw.c | 369 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 36 ++++ drivers/scsi/elx/efct/efct_io.c | 198 +++++++++++++++++++++ drivers/scsi/elx/efct/efct_io.h | 191 +++++++++++++++++++++ 4 files changed, 794 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_io.c create mode 100644 drivers/scsi/elx/efct/efct_io.hdrivers/scsi/elx/efct/efct_hw.c +0
-0
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2153
Quoted 8 lines
drivers/scsi/elx/efct/efct_hw.c +5
-0@@ -2146,3 +2146,372 @@ efct_hw_reqtag_reset(struct efct_hw *hw)list_add_tail (&wqcb->list_entry, &reqtag_pool->freelist); } } + +int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id) +{ +int rc =-1 ;
it's not a return code, it's a index what is returned
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2163
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+int index = id & (EFCT_HW_Q_HASH_SIZE -1 ); + +/* +* Since the hash is always bigger than the maximum number of Qs, then +* we never have to worry about an infinite loop. We will always find +* an unused entry. +*/ + do { + if (hash[index].in_use && + hash[index].id == id)
fits on one line
Quoted 40 lines
drivers/scsi/elx/efct/efct_hw.c +40
-0+ rc = hash[index].index; + else + index = (index +1 ) & (EFCT_HW_Q_HASH_SIZE -1 ); + }while (rc ==-1 && hash[index].in_use); + +return rc; +} + +int +efct_hw_process (struct efct_hw *hw,u32 vector, +u32 max_isr_time_msec) +{ +struct hw_eq *eq; +int rc =0 ; + +/* +* The caller should disable interrupts if they wish to prevent us +* from processing during a shutdown. The following states are defined: +* EFCT_HW_STATE_UNINITIALIZED - No queues allocated +* EFCT_HW_STATE_QUEUES_ALLOCATED - The state after a chip reset, +* queues are cleared. +* EFCT_HW_STATE_ACTIVE - Chip and queues are operational +* EFCT_HW_STATE_RESET_IN_PROGRESS - reset, we still want completions +* EFCT_HW_STATE_TEARDOWN_IN_PROGRESS - We still want mailbox +* completions. +*/ +if (hw->state ==EFCT_HW_STATE_UNINITIALIZED ) +return EFC_SUCCESS ; + +/* Get pointer to struct hw_eq */ + eq = hw->hw_eq[vector]; +if (!eq) +return EFC_SUCCESS ; + + eq->use_count++; + + rc =efct_hw_eq_process (hw, eq, max_isr_time_msec); + +return rc; +}
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2213
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ +int +efct_hw_eq_process (struct efct_hw *hw,struct hw_eq *eq, +u32 max_isr_time_msec) +{ +u8 eqe[sizeof (struct sli4_eqe )] = {0 }; +u32 tcheck_count; +time_t tstart; +time_t telapsed; +bool done = false;
variables are not consistently aligned.
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2220
Quoted 7 lines
drivers/scsi/elx/efct/efct_hw.c +7
-0+ + tcheck_count =EFCT_HW_TIMECHECK_ITERATIONS ; + tstart =jiffies_to_msecs (jiffies); + +while (!done && !sli_eq_read (&hw->sli, eq->queue, eqe)) { +u16 cq_id =0 ; +int rc;
same here
Quoted 98 lines
drivers/scsi/elx/efct/efct_hw.c +98
-0+ + rc =sli_eq_parse (&hw->sli, eqe, &cq_id); +if (unlikely (rc)) { +if (rc ==SLI4_EQE_STATUS_EQ_FULL ) { +u32 i; + +/* +* Received a sentinel EQE indicating the +* EQ is full. Process all CQs +*/ +for (i =0 ; i < hw->cq_count; i++) +efct_hw_cq_process (hw, hw->hw_cq[i]); +continue ; + }else { +return rc; + } + }else { +int index; + + index =efct_hw_queue_hash_find (hw->cq_hash, cq_id); + +if (likely (index >=0 )) +efct_hw_cq_process (hw, hw->hw_cq[index]); +else +efc_log_err (hw->os,"bad CQ_ID %#06x\n" , + cq_id); + } + +if (eq->queue->n_posted > eq->queue->posted_limit) +sli_queue_arm (&hw->sli, eq->queue, false); + +if (tcheck_count && (--tcheck_count ==0 )) { + tcheck_count =EFCT_HW_TIMECHECK_ITERATIONS ; + telapsed =jiffies_to_msecs (jiffies) - tstart; +if (telapsed >= max_isr_time_msec) + done = true; + } + } +sli_queue_eq_arm (&hw->sli, eq->queue, true); + +return EFC_SUCCESS ; +} + +static int +_efct_hw_wq_write (struct hw_wq *wq,struct efct_hw_wqe *wqe) +{ +int queue_rc; + +/* Every so often, set the wqec bit to generate comsummed completions */ +if (wq->wqec_count) + wq->wqec_count--; + +if (wq->wqec_count ==0 ) { +struct sli4_generic_wqe *genwqe = (void *)wqe->wqebuf; + + genwqe->cmdtype_wqec_byte |=SLI4_GEN_WQE_WQEC ; + wq->wqec_count = wq->wqec_set_count; + } + +/* Decrement WQ free count */ + wq->free_count--; + + queue_rc =sli_wq_write (&wq->hw->sli, wq->queue, wqe->wqebuf); + +return (queue_rc <0 ) ?-1 :0 ; +} + +static void +hw_wq_submit_pending (struct hw_wq *wq,u32 update_free_count) +{ +struct efct_hw_wqe *wqe; +unsigned long flags =0 ; + +spin_lock_irqsave (&wq->queue->lock, flags); + +/* Update free count with value passed in */ + wq->free_count += update_free_count; + +while ((wq->free_count >0 ) && (!list_empty (&wq->pending_list))) { + wqe =list_first_entry (&wq->pending_list, + struct efct_hw_wqe, list_entry); +list_del (&wqe->list_entry); +_efct_hw_wq_write (wq, wqe); + +if (wqe->abort_wqe_submit_needed) { + wqe->abort_wqe_submit_needed = false; +sli_abort_wqe (&wq->hw->sli, wqe->wqebuf, + wq->hw->sli.wqe_size, +SLI_ABORT_XRI , wqe->send_abts, wqe->id, +0 , wqe->abort_reqtag,SLI4_CQ_DEFAULT ); +INIT_LIST_HEAD (&wqe->list_entry); +list_add_tail (&wqe->list_entry, &wq->pending_list); + wq->wq_pending_count++; + } + } + +spin_unlock_irqrestore (&wq->queue->lock, flags); +}
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2328
Quoted 10 lines
drivers/scsi/elx/efct/efct_hw.c +10
-0+ +void +efct_hw_cq_process (struct efct_hw *hw,struct hw_cq *cq) +{ +u8 cqe[sizeof (struct sli4_mcqe )]; +u16 rid =U16_MAX ; +enum sli4_qentry ctype;/* completion type */ +int status; +u32 n_processed =0 ; +u32 tstart, telapsed;
Please get the aligment of the variables consistent in all functions.
drivers/scsi/elx/efct/efct_hw.c efct_hw_reqtag_reset(struct efct_hw *hw) · line 2334
Quoted 6 lines
drivers/scsi/elx/efct/efct_hw.c +6
-0+ + tstart =jiffies_to_msecs (jiffies); + +while (!sli_cq_read (&hw->sli, cq->queue, cqe)) { + status =sli_cq_parse (&hw->sli, cq->queue, + cqe, &ctype, &rid);
fits on one line
Quoted 283 lines
drivers/scsi/elx/efct/efct_hw.c +183
-0+/* +* The sign of status is significant. If status is: +* == 0 : call completed correctly and +* the CQE indicated success +* > 0 : call completed correctly and +* the CQE indicated an error +* < 0 : call failed and no information is available about the +* CQE +*/ +if (status <0 ) { +if (status ==SLI4_MCQE_STATUS_NOT_COMPLETED ) +/* +* Notification that an entry was consumed, +* but not completed +*/ +continue ; + +break ; + } + +switch (ctype) { +case SLI_QENTRY_ASYNC : +sli_cqe_async (&hw->sli, cqe); +break ; +case SLI_QENTRY_MQ : +/* +* Process MQ entry. Note there is no way to determine +* the MQ_ID from the completion entry. +*/ +efct_hw_mq_process (hw, status, hw->mq); +break ; +case SLI_QENTRY_WQ : +efct_hw_wq_process (hw, cq, cqe, status, rid); +break ; +case SLI_QENTRY_WQ_RELEASE : { +u32 wq_id = rid; +int index; +struct hw_wq *wq =NULL ; + + index =efct_hw_queue_hash_find (hw->wq_hash, wq_id); + +if (likely (index >=0 )) { + wq = hw->hw_wq[index]; + }else { +efc_log_err (hw->os,"bad WQ_ID %#06x\n" , wq_id); +break ; + } +/* Submit any HW IOs that are on the WQ pending list */ +hw_wq_submit_pending (wq, wq->wqec_set_count); + +break ; + } + +case SLI_QENTRY_RQ : +efct_hw_rqpair_process_rq (hw, cq, cqe); +break ; +case SLI_QENTRY_XABT : { +efct_hw_xabt_process (hw, cq, cqe, rid); +break ; + } +default : +efc_log_test (hw->os, +"unhandled ctype=%#x rid=%#x\n" , + ctype, rid); +break ; + } + + n_processed++; +if (n_processed == cq->queue->proc_limit) +break ; + +if (cq->queue->n_posted >= cq->queue->posted_limit) +sli_queue_arm (&hw->sli, cq->queue, false); + } + +sli_queue_arm (&hw->sli, cq->queue, true); + +if (n_processed > cq->queue->max_num_processed) + cq->queue->max_num_processed = n_processed; + telapsed =jiffies_to_msecs (jiffies) - tstart; +if (telapsed > cq->queue->max_process_time) + cq->queue->max_process_time = telapsed; +} + +void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid) +{ +struct hw_wq_callback *wqcb; + +if (rid ==EFCT_HW_REQUE_XRI_REGTAG ) { +if (status) +efc_log_err (hw->os,"reque xri failed, status = %d\n" , + status); +return ; + } + + wqcb =efct_hw_reqtag_get_instance (hw, rid); +if (!wqcb) { +efc_log_err (hw->os,"invalid request tag: x%x\n" , rid); +return ; + } + +if (!wqcb->callback) { +efc_log_err (hw->os,"wqcb callback is NULL\n" ); +return ; + } + + (*wqcb->callback)(wqcb->arg, cqe, status); +} + +void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid) +{ +/* search IOs wait free list */ +struct efct_hw_io *io =NULL ; +unsigned long flags =0 ; + + io =efct_hw_io_lookup (hw, rid); +if (!io) { +/* IO lookup failure should never happen */ +efc_log_err (hw->os, +"Error: xabt io lookup failed rid=%#x\n" , rid); +return ; + } + +if (!io->xbusy) +efc_log_debug (hw->os,"xabt io not busy rid=%#x\n" , rid); +else +/* mark IO as no longer busy */ + io->xbusy = false; + +/* +* For IOs that were aborted internally, we need to issue any pending +* callback here. +*/ +if (io->done) { +efct_hw_done_t done = io->done; +void *arg = io->arg; + +/* +* Use latched status as this is always saved for an internal +* abort +*/ +int status = io->saved_status; +u32 len = io->saved_len; +u32 ext = io->saved_ext; + + io->done =NULL ; + io->status_saved = false; + +done (io, io->rnode, len, status, ext, arg); + } + +spin_lock_irqsave (&hw->io_lock, flags); +if (io->state ==EFCT_HW_IO_STATE_INUSE || + io->state ==EFCT_HW_IO_STATE_WAIT_FREE ) { +/* if on wait_free list, caller has already freed IO; +* remove from wait_free list and add to free list. +* if on in-use list, already marked as no longer busy; +* just leave there and wait for caller to free. +*/ +if (io->state ==EFCT_HW_IO_STATE_WAIT_FREE ) { + io->state =EFCT_HW_IO_STATE_FREE ; +list_del (&io->list_entry); +efct_hw_io_free_move_correct_list (hw, io); + } + } +spin_unlock_irqrestore (&hw->io_lock, flags); +} + +static int +efct_hw_flush (struct efct_hw *hw) +{ +u32 i =0 ; + +/* Process any remaining completions */ +for (i =0 ; i < hw->eq_count; i++) +efct_hw_process (hw, i, ~0 ); + +return EFC_SUCCESS ; +}drivers/scsi/elx/efct/efct_hw.h +36
-0@@ -678,4 +678,40 @@ extern struct hw_wq_callback *efct_hw_reqtag_get_instance(struct efct_hw *hw, u32 instance_index);void efct_hw_reqtag_reset (struct efct_hw *hw); +/* RQ completion handlers for RQ pair mode */ +extern int +efct_hw_rqpair_process_rq (struct efct_hw *hw, +struct hw_cq *cq,u8 *cqe); +extern +enum efct_hw_rtn efct_hw_rqpair_sequence_free (struct efct_hw *hw, +struct efc_hw_sequence *seq); +static inline void +efct_hw_sequence_copy (struct efc_hw_sequence *dst, +struct efc_hw_sequence *src) +{ +/* Copy src to dst, then zero out the linked list link */ + *dst = *src; +} + +static inline enum efct_hw_rtn +efct_hw_sequence_free (struct efct_hw *hw,struct efc_hw_sequence *seq) +{ +/* Only RQ pair mode is supported */ +return efct_hw_rqpair_sequence_free (hw, seq); +} +extern int +efct_hw_eq_process (struct efct_hw *hw,struct hw_eq *eq, +u32 max_isr_time_msec); +void efct_hw_cq_process (struct efct_hw *hw,struct hw_cq *cq); +extern void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid); +extern void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid); +extern int +efct_hw_process (struct efct_hw *hw,u32 vector,u32 max_isr_time_msec); +extern int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id); +#endif /* __EFCT_H__ */ drivers/scsi/elx/efct/efct_io.c new file +49
-0@@ -0,0 +1,198 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_hw.h" +#include "efct_io.h" + +struct efct_io_pool { +struct efct *efct; +spinlock_t lock;/* IO pool lock */ +u32 io_num_ios;/* Total IOs allocated */ +struct efct_io *ios[EFCT_NUM_SCSI_IOS ]; +struct list_head freelist; + +}; + +struct efct_io_pool * +efct_io_pool_create (struct efct *efct,u32 num_sgl) +{ +u32 i =0 ; +struct efct_io_pool *io_pool; +struct efct_io *io; + +/* Allocate the IO pool */ + io_pool =kzalloc (sizeof (*io_pool),GFP_KERNEL ); +if (!io_pool) +return NULL ; + + io_pool->efct = efct; +INIT_LIST_HEAD (&io_pool->freelist); +/* initialize IO pool lock */ +spin_lock_init (&io_pool->lock); + +for (i =0 ; i <EFCT_NUM_SCSI_IOS ; i++) { + io =kmalloc (sizeof (*io),GFP_KERNEL ); +if (!io) +break ; + + io_pool->io_num_ios++; + io_pool->ios[i] = io; + io->tag = i; + io->instance_index = i; + +/* Allocate a response buffer */ + io->rspbuf.size =SCSI_RSP_BUF_LENGTH ; + io->rspbuf.virt = dma_alloc_coherent(&efct->pcidev->dev,
drivers/scsi/elx/efct/efct_io.c line 59
Quoted 10 lines
drivers/scsi/elx/efct/efct_io.c new file +10
-0+ io->rspbuf.size, + &io->rspbuf.phys, GFP_DMA); +if (!io->rspbuf.virt) { +efc_log_err (efct,"dma_alloc rspbuf failed\n" ); +efct_io_pool_free (io_pool); +return NULL ; + } + +/* Allocate SGL */ + io->sgl =kzalloc (sizeof (*io->sgl) * num_sgl,GFP_ATOMIC );
GFP_KERNEL
Quoted 58 lines
drivers/scsi/elx/efct/efct_io.c new file +58
-0+if (!io->sgl) { +efct_io_pool_free (io_pool); +return NULL ; + } + +memset (io->sgl,0 ,sizeof (*io->sgl) * num_sgl); + io->sgl_allocated = num_sgl; + io->sgl_count =0 ; + +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &io_pool->freelist); + } + +return io_pool; +} + +int +efct_io_pool_free (struct efct_io_pool *io_pool) +{ +struct efct *efct; +u32 i; +struct efct_io *io; + +if (io_pool) { + efct = io_pool->efct; + +for (i =0 ; i < io_pool->io_num_ios; i++) { + io = io_pool->ios[i]; +if (!io) +continue ; + +kfree (io->sgl); +dma_free_coherent (&efct->pcidev->dev, + io->rspbuf.size, io->rspbuf.virt, + io->rspbuf.phys); +memset (&io->rspbuf,0 ,sizeof (struct efc_dma )); + } + +kfree (io_pool); + efct->xport->io_pool =NULL ; + } + +return EFC_SUCCESS ; +} + +u32 efct_io_pool_allocated (struct efct_io_pool *io_pool) +{ +return io_pool->io_num_ios; +} + +struct efct_io * +efct_io_pool_io_alloc (struct efct_io_pool *io_pool) +{ +struct efct_io *io =NULL ; +struct efct *efct; +unsigned long flags =0 ; + + efct = io_pool->efct;
drivers/scsi/elx/efct/efct_io.c line 127
Quoted 10 lines
drivers/scsi/elx/efct/efct_io.c new file +10
-0+ +spin_lock_irqsave (&io_pool->lock, flags); + +if (!list_empty (&io_pool->freelist)) { + io = list_first_entry(&io_pool->freelist, struct efct_io, + list_entry); + } + +if (io) { +list_del (&io->list_entry);
Could list_del not be directly after list_first_entry and then the spin_lock_unlock_irqrestore() could directly follow the if body?
Quoted 115 lines
drivers/scsi/elx/efct/efct_io.c new file +71
-0+spin_unlock_irqrestore (&io_pool->lock, flags); + + io->io_type =EFCT_IO_TYPE_MAX ; + io->hio_type =EFCT_HW_IO_MAX ; + io->hio =NULL ; + io->transferred =0 ; + io->efct = efct; + io->timeout =0 ; + io->sgl_count =0 ; + io->tgt_task_tag =0 ; + io->init_task_tag =0 ; + io->hw_tag =0 ; + io->display_name ="pending" ; + io->seq_init =0 ; + io->els_req_free = false; + io->io_free =0 ; + io->release =NULL ; +atomic_add_return (1 , &efct->xport->io_active_count); +atomic_add_return (1 , &efct->xport->io_total_alloc); + }else { +spin_unlock_irqrestore (&io_pool->lock, flags); + } +return io; +} + +/* Free an object used to track an IO */ +void +efct_io_pool_io_free (struct efct_io_pool *io_pool,struct efct_io *io) +{ +struct efct *efct; +struct efct_hw_io *hio =NULL ; +unsigned long flags =0 ; + + efct = io_pool->efct; + +spin_lock_irqsave (&io_pool->lock, flags); + hio = io->hio; + io->hio =NULL ; + io->io_free =1 ; +INIT_LIST_HEAD (&io->list_entry); +list_add (&io->list_entry, &io_pool->freelist); +spin_unlock_irqrestore (&io_pool->lock, flags); + +if (hio) +efct_hw_io_free (&efct->hw, hio); + +atomic_sub_return (1 , &efct->xport->io_active_count); +atomic_add_return (1 , &efct->xport->io_total_free); +} + +/* Find an I/O given it's node and ox_id */ +struct efct_io * +efct_io_find_tgt_io (struct efct *efct,struct efc_node *node, +u16 ox_id,u16 rx_id) +{ +struct efct_io *io =NULL ; +unsigned long flags =0 ; +u8 found = false; + +spin_lock_irqsave (&node->active_ios_lock, flags); +list_for_each_entry (io, &node->active_ios, list_entry) { +if ((io->cmd_tgt && io->init_task_tag == ox_id) && + (rx_id ==0xffff || io->tgt_task_tag == rx_id)) { +if (kref_get_unless_zero (&io->ref)) + found = true; +break ; + } + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return found ? io :NULL ; +}drivers/scsi/elx/efct/efct_io.h new file +38
-0@@ -0,0 +1,191 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_IO_H__) +#define __EFCT_IO_H__ + +#include "efct_lio.h" + +#define EFCT_LOG_ENABLE_IO_ERRORS (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 6)) != 0) : 0) + +#define io_error_log (io, fmt, ...) \ + do { \ + if (EFCT_LOG_ENABLE_IO_ERRORS(io->efct)) \ + efc_log_warn(io->efct, fmt, ##__VA_ARGS__); \ + } while (0) + +#define SCSI_CMD_BUF_LENGTH 48 +#define SCSI_RSP_BUF_LENGTH (FCP_RESP_WITH_EXT + SCSI_SENSE_BUFFERSIZE) +#define EFCT_NUM_SCSI_IOS 8192 + +enum efct_io_type { +EFCT_IO_TYPE_IO =0 , +EFCT_IO_TYPE_ELS , +EFCT_IO_TYPE_CT , +EFCT_IO_TYPE_CT_RESP , +EFCT_IO_TYPE_BLS_RESP , +EFCT_IO_TYPE_ABORT , + +EFCT_IO_TYPE_MAX , +}; + +enum efct_els_state { +EFCT_ELS_REQUEST =0 , + EFCT_ELS_REQUEST_DELAYED,
drivers/scsi/elx/efct/efct_io.h line 48
Quoted 10 lines
drivers/scsi/elx/efct/efct_io.h new file +10
-0+EFCT_ELS_REQUEST_DELAY_ABORT , +EFCT_ELS_REQ_ABORT , +EFCT_ELS_REQ_ABORTED , + EFCT_ELS_ABORT_IO_COMPL, +}; + +struct efct_io { +struct list_head list_entry; +struct list_head io_pending_link; +/* reference counter and callback function */
kerneldoc?
Quoted 146 lines
drivers/scsi/elx/efct/efct_io.h new file +143
-0+struct kref ref; +void (*release)(struct kref *arg); +/* pointer back to efct */ +struct efct *efct; +/* unique instance index value */ +u32 instance_index; +/* display name */ +const char *display_name; +/* pointer to node */ +struct efc_node *node; +/* (io_pool->io_free_list) free list link */ +/* initiator task tag (OX_ID) for back-end and SCSI logging */ +u32 init_task_tag; +/* target task tag (RX_ID) - for back-end and SCSI logging */ +u32 tgt_task_tag; +/* HW layer unique IO id - for back-end and SCSI logging */ +u32 hw_tag; +/* unique IO identifier */ +u32 tag; +/* SGL */ +struct efct_scsi_sgl *sgl; +/* Number of allocated SGEs */ +u32 sgl_allocated; +/* Number of SGEs in this SGL */ +u32 sgl_count; +/* backend target private IO data */ +struct efct_scsi_tgt_io tgt_io; +/* expected data transfer length, based on FC header */ +u32 exp_xfer_len; + +/* Declarations private to HW/SLI */ +void *hw_priv; + +/* indicates what this struct efct_io structure is used for */ +enum efct_io_type io_type; +struct efct_hw_io *hio; +size_t transferred; + +/* set if auto_trsp was set */ +bool auto_resp; +/* set if low latency request */ +bool low_latency; +/* selected WQ steering request */ +u8 wq_steering; +/* selected WQ class if steering is class */ +u8 wq_class; +/* transfer size for current request */ +u64 xfer_req; +/* target callback function */ +efct_scsi_io_cb_t scsi_tgt_cb; +/* target callback function argument */ +void *scsi_tgt_cb_arg; +/* abort callback function */ +efct_scsi_io_cb_t abort_cb; +/* abort callback function argument */ +void *abort_cb_arg; +/* BLS callback function */ +efct_scsi_io_cb_t bls_cb; +/* BLS callback function argument */ +void *bls_cb_arg; +/* TMF command being processed */ +enum efct_scsi_tmf_cmd tmf_cmd; +/* rx_id from the ABTS that initiated the command abort */ +u16 abort_rx_id; + +/* True if this is a Target command */ +bool cmd_tgt; +/* when aborting, indicates ABTS is to be sent */ +bool send_abts; +/* True if this is an Initiator command */ +bool cmd_ini; +/* True if local node has sequence initiative */ +bool seq_init; +/* iparams for hw io send call */ +union efct_hw_io_param_u iparam; +/* HW IO type */ +enum efct_hw_io_type hio_type; +/* wire length */ +u64 wire_len; +/* saved HW callback */ +void *hw_cb; + +/* for ELS requests/responses */ +/* True if ELS is pending */ +bool els_pend; +/* True if ELS is active */ +bool els_active; +/* ELS request payload buffer */ +struct efc_dma els_req; +/* ELS response payload buffer */ +struct efc_dma els_rsp; +bool els_req_free; +/* Retries remaining */ +u32 els_retries_remaining; +void (*els_callback)(struct efc_node *node, +struct efc_node_cb *cbdata,void *cbarg); +void *els_callback_arg; +/* timeout */ +u32 els_timeout_sec; + +/* delay timer */ +struct timer_list delay_timer; + +/* for abort handling */ +/* pointer to IO to abort */ +struct efct_io *io_to_abort; + +enum efct_els_state state; +/* Protects els cmds */ +spinlock_t els_lock; + +/* SCSI Response buffer */ +struct efc_dma rspbuf; +/* Timeout value in seconds for this IO */ +u32 timeout; +/* CS_CTL priority for this IO */ +u8 cs_ctl; +/* Is io object in freelist > */ +u8 io_free; + u32 app_id; +}; + +struct efct_io_cb_arg { +int status;/* completion status */ +int ext_status;/* extended completion status */ +void *app;/* application argument */ +}; + +struct efct_io_pool * +efct_io_pool_create (struct efct *efct,u32 num_sgl); +extern int +efct_io_pool_free (struct efct_io_pool *io_pool); +extern u32 +efct_io_pool_allocated (struct efct_io_pool *io_pool); + +extern struct efct_io * +efct_io_pool_io_alloc (struct efct_io_pool *io_pool); +extern void +efct_io_pool_io_free (struct efct_io_pool *io_pool,struct efct_io *io); +extern struct efct_io * +efct_io_find_tgt_io (struct efct *efct,struct efc_node *node, +u16 ox_id,u16 rx_id); +#endif /* __EFCT_IO_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 21/31 elx: efct: Unsolicited FC frame processing routines
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines to handle unsolicited FC frames.
---
v3:
Return defined values
--- drivers/scsi/elx/efct/efct_hw.c | 1 + drivers/scsi/elx/efct/efct_unsol.c | 813 +++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_unsol.h | 49 +++ 3 files changed, 863 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_unsol.c create mode 100644 drivers/scsi/elx/efct/efct_unsol.h
drivers/scsi/elx/efct/efct_hw.c +1 -0
@@ -6,6 +6,7 @@#include "efct_driver.h" #include "efct_hw.h" +#include "efct_unsol.h" static enum efct_hw_rtn efct_hw_link_event_init (struct efct_hw *hw)
drivers/scsi/elx/efct/efct_unsol.c new file +813 -0
813 lines not on this page · raw message
drivers/scsi/elx/efct/efct_unsol.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 21/31] elx: efct: Unsolicited FC frame processing routines
Quoted 202 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines to handle unsolicited FC frames.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>---
v3:
Return defined values--- drivers/scsi/elx/efct/efct_hw.c | 1 + drivers/scsi/elx/efct/efct_unsol.c | 813 +++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_unsol.h | 49 +++ 3 files changed, 863 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_unsol.c create mode 100644 drivers/scsi/elx/efct/efct_unsol.hdrivers/scsi/elx/efct/efct_hw.c +1
-0@@ -6,6 +6,7 @@#include "efct_driver.h" #include "efct_hw.h" +#include "efct_unsol.h" static enum efct_hw_rtn efct_hw_link_event_init (struct efct_hw *hw)drivers/scsi/elx/efct/efct_unsol.c new file +164
-0@@ -0,0 +1,813 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_els.h" +#include "efct_unsol.h" + +#define frame_printf (efct, hdr, fmt, ...) \ + do { \ + char s_id_text[16]; \ + efc_node_fcid_display(ntoh24((hdr)->fh_s_id), \ + s_id_text, sizeof(s_id_text)); \ + efc_log_debug(efct, "[%06x.%s] %02x/%04x/%04x: " fmt, \ + ntoh24((hdr)->fh_d_id), s_id_text, \ + (hdr)->fh_r_ctl, be16_to_cpu((hdr)->fh_ox_id), \ + be16_to_cpu((hdr)->fh_rx_id), ##__VA_ARGS__); \ + } while (0) + +static int +efct_unsol_process (struct efct *efct,struct efc_hw_sequence *seq) +{ +struct efct_xport_fcfi *xport_fcfi =NULL ; +struct efc_domain *domain; +struct efct_hw *hw = &efct->hw; +unsigned long flags =0 ; + + xport_fcfi = &efct->xport->fcfi; + +/* If the transport FCFI entry is NULL, then drop the frame */ +if (!xport_fcfi) { +efc_log_test (efct, +"FCFI %d is not valid, dropping frame\n" , + seq->fcfi); + +efct_hw_sequence_free (&efct->hw, seq); +return EFC_SUCCESS ; + } + + domain = hw->domain; + +/* +* If we are holding frames or the domain is not yet registered or +* there's already frames on the pending list, +* then add the new frame to pending list +*/ +if (!domain || + xport_fcfi->hold_frames || + !list_empty (&xport_fcfi->pend_frames)) { +spin_lock_irqsave (&xport_fcfi->pend_frames_lock, flags); +INIT_LIST_HEAD (&seq->list_entry); +list_add_tail (&seq->list_entry, &xport_fcfi->pend_frames); +spin_unlock_irqrestore (&xport_fcfi->pend_frames_lock, flags); + +if (domain) { +/* immediately process pending frames */ +efct_domain_process_pending (domain); + } + }else { +/* +* We are not holding frames and pending list is empty, +* just process frame. A non-zero return means the frame +* was not handled - so cleanup +*/ +if (efc_domain_dispatch_frame (domain, seq)) +efct_hw_sequence_free (&efct->hw, seq); + } +return EFC_SUCCESS ; +} + +int +efct_unsolicited_cb (void *arg,struct efc_hw_sequence *seq) +{ +struct efct *efct = arg; +int rc; + + rc =efct_unsol_process (efct, seq); +if (rc) +efct_hw_sequence_free (&efct->hw, seq); + +return EFC_SUCCESS ; +} + +void +efct_process_node_pending (struct efc_node *node) +{ +struct efct *efct = node->efc->base; +struct efc_hw_sequence *seq =NULL ; +u32 pend_frames_processed =0 ; +unsigned long flags =0 ; + +for (;;) { +/* need to check for hold frames condition after each frame +* processed because any given frame could cause a transition +* to a state that holds frames +*/ +if (node->hold_frames) +break ; + +/* Get next frame/sequence */ +spin_lock_irqsave (&node->pend_frames_lock, flags); +if (!list_empty (&node->pend_frames)) { + seq =list_first_entry (&node->pend_frames, + struct efc_hw_sequence, list_entry); +list_del (&seq->list_entry); + } +spin_unlock_irqrestore (&node->pend_frames_lock, flags); + +if (!seq) { + pend_frames_processed = node->pend_frames_processed; + node->pend_frames_processed =0 ; +break ; + } + node->pend_frames_processed++; + +/* now dispatch frame(s) to dispatch function */ +efc_node_dispatch_frame (node, seq); +efct_hw_sequence_free (&efct->hw, seq); + } + +if (pend_frames_processed !=0 ) +efc_log_debug (efct,"%u node frames held and processed\n" , + pend_frames_processed); +} + +static bool efct_domain_frames_held (void *arg) +{ +struct efc_domain *domain = (struct efc_domain *)arg; +struct efct *efct = domain->efc->base; +struct efct_xport_fcfi *xport_fcfi; + + xport_fcfi = &efct->xport->fcfi; +return xport_fcfi->hold_frames; +} + +void +efct_domain_process_pending (struct efc_domain *domain) +{ +struct efct *efct = domain->efc->base; +struct efct_xport_fcfi *xport_fcfi; +struct efc_hw_sequence *seq =NULL ; +u32 pend_frames_processed =0 ; +unsigned long flags =0 ; + + xport_fcfi = &efct->xport->fcfi; + +for (;;) { +/* need to check for hold frames condition after each frame +* processed because any given frame could cause a transition +* to a state that holds frames +*/ +if (efct_domain_frames_held (domain)) +break ; + +/* Get next frame/sequence */ +spin_lock_irqsave (&xport_fcfi->pend_frames_lock, flags); +if (!list_empty (&xport_fcfi->pend_frames)) { + seq =list_first_entry (&xport_fcfi->pend_frames, + struct efc_hw_sequence, + list_entry); +list_del (&seq->list_entry); + }
drivers/scsi/elx/efct/efct_unsol.c line 174
Quoted 10 lines
drivers/scsi/elx/efct/efct_unsol.c new file +10
-0+if (!seq) { + pend_frames_processed = + xport_fcfi->pend_frames_processed; + xport_fcfi->pend_frames_processed =0 ; +spin_unlock_irqrestore (& + xport_fcfi->pend_frames_lock, + flags); +break ; + } + xport_fcfi->pend_frames_processed++;
no need to indent.
Quoted 294 lines
drivers/scsi/elx/efct/efct_unsol.c new file +294
-0+spin_unlock_irqrestore (&xport_fcfi->pend_frames_lock, flags); + +/* now dispatch frame(s) to dispatch function */ +if (efc_domain_dispatch_frame (domain, seq)) +efct_hw_sequence_free (&efct->hw, seq); + + seq =NULL ; + } +if (pend_frames_processed !=0 ) +efc_log_debug (efct,"%u domain frames held and processed\n" , + pend_frames_processed); +} + +static struct efc_hw_sequence * +efct_frame_next (struct list_head *pend_list,spinlock_t *list_lock) +{ +struct efc_hw_sequence *frame =NULL ; +unsigned long flags =0 ; + +spin_lock_irqsave (list_lock, flags); + +if (!list_empty (pend_list)) { + frame =list_first_entry (pend_list, + struct efc_hw_sequence, list_entry); +list_del (&frame->list_entry); + } + +spin_unlock_irqrestore (list_lock, flags); +return frame; +} + +static int +efct_purge_pending (struct efct *efct,struct list_head *pend_list, +spinlock_t *list_lock) +{ +struct efc_hw_sequence *frame; + +for (;;) { + frame =efct_frame_next (pend_list, list_lock); +if (!frame) +break ; + +frame_printf (efct, + (struct fc_frame_header *)frame->header->dma.virt, +"Discarding held frame\n" ); +efct_hw_sequence_free (&efct->hw, frame); + } + +return EFC_SUCCESS ; +} + +int +efct_node_purge_pending (struct efc *efc,struct efc_node *node) +{ +struct efct *efct = efc->base; + +return efct_purge_pending (efct, &node->pend_frames, + &node->pend_frames_lock); +} + +int +efct_domain_purge_pending (struct efc_domain *domain) +{ +struct efct *efct = domain->efc->base; +struct efct_xport_fcfi *xport_fcfi; + + xport_fcfi = &efct->xport->fcfi; +return efct_purge_pending (efct, + &xport_fcfi->pend_frames, + &xport_fcfi->pend_frames_lock); +} + +void +efct_domain_hold_frames (struct efc *efc,struct efc_domain *domain) +{ +struct efct *efct = domain->efc->base; +struct efct_xport_fcfi *xport_fcfi; + + xport_fcfi = &efct->xport->fcfi; +if (!xport_fcfi->hold_frames) { +efc_log_debug (efct,"hold frames set for FCFI %d\n" , + domain->fcf_indicator); + xport_fcfi->hold_frames = true; + } +} + +void +efct_domain_accept_frames (struct efc *efc,struct efc_domain *domain) +{ +struct efct *efct = domain->efc->base; +struct efct_xport_fcfi *xport_fcfi; + + xport_fcfi = &efct->xport->fcfi; +if (xport_fcfi->hold_frames) { +efc_log_debug (efct,"hold frames cleared for FCFI %d\n" , + domain->fcf_indicator); + } + xport_fcfi->hold_frames = false; +efct_domain_process_pending (domain); +} + +static int +efct_fc_tmf_rejected_cb (struct efct_io *io, +enum efct_scsi_io_status scsi_status, +u32 flags,void *arg) +{ +efct_scsi_io_free (io); +return EFC_SUCCESS ; +} + +static void +efct_dispatch_unsolicited_tmf (struct efct_io *io, +u8 task_management_flags, +struct efc_node *node,u32 lun) +{ +u32 i; +struct { +u32 mask; +enum efct_scsi_tmf_cmd cmd; + } tmflist[] = { + {FCP_TMF_ABT_TASK_SET ,EFCT_SCSI_TMF_ABORT_TASK_SET }, + {FCP_TMF_CLR_TASK_SET ,EFCT_SCSI_TMF_CLEAR_TASK_SET }, + {FCP_TMF_LUN_RESET ,EFCT_SCSI_TMF_LOGICAL_UNIT_RESET }, + {FCP_TMF_TGT_RESET ,EFCT_SCSI_TMF_TARGET_RESET }, + {FCP_TMF_CLR_ACA ,EFCT_SCSI_TMF_CLEAR_ACA } }; + + io->exp_xfer_len =0 ; + +for (i =0 ; i <ARRAY_SIZE (tmflist); i++) { +if (tmflist[i].mask & task_management_flags) { + io->tmf_cmd = tmflist[i].cmd; +efct_scsi_recv_tmf (io, lun, tmflist[i].cmd,NULL ,0 ); +break ; + } + } +if (i ==ARRAY_SIZE (tmflist)) { +/* Not handled */ +node_printf (node,"TMF x%x rejected\n" , task_management_flags); +efct_scsi_send_tmf_resp (io,EFCT_SCSI_TMF_FUNCTION_REJECTED , +NULL , efct_fc_tmf_rejected_cb,NULL ); + } +} + +static int +efct_validate_fcp_cmd (struct efct *efct,struct efc_hw_sequence *seq) +{ +/* +* If we received less than FCP_CMND_IU bytes, assume that the frame is +* corrupted in some way and drop it. +* This was seen when jamming the FCTL +* fill bytes field. +*/ +if (seq->payload->dma.len <sizeof (struct fcp_cmnd )) { +struct fc_frame_header *fchdr = seq->header->dma.virt; + +efc_log_debug (efct, +"drop ox_id %04x with payload (%zd) less than (%zd)\n" , +be16_to_cpu (fchdr->fh_ox_id), + seq->payload->dma.len, +sizeof (struct fcp_cmnd )); +return EFC_FAIL ; + } +return EFC_SUCCESS ; +} + +static void +efct_populate_io_fcp_cmd (struct efct_io *io,struct fcp_cmnd *cmnd, +struct fc_frame_header *fchdr,bool sit) +{ + io->init_task_tag =be16_to_cpu (fchdr->fh_ox_id); +/* note, tgt_task_tag, hw_tag set when HW io is allocated */ + io->exp_xfer_len =be32_to_cpu (cmnd->fc_dl); + io->transferred =0 ; + +/* The upper 7 bits of CS_CTL is the frame priority thru the SAN. +* Our assertion here is, the priority given to a frame containing +* the FCP cmd should be the priority given to ALL frames contained +* in that IO. Thus we need to save the incoming CS_CTL here. +*/ +if (ntoh24 (fchdr->fh_f_ctl) &FC_FC_RES_B17 ) + io->cs_ctl = fchdr->fh_cs_ctl; +else + io->cs_ctl =0 ; + + io->seq_init = sit; +} + +static u32 +efct_get_flags_fcp_cmd (struct fcp_cmnd *cmnd) +{ +u32 flags =0 ; + +switch (cmnd->fc_pri_ta &FCP_PTA_MASK ) { +case FCP_PTA_SIMPLE : + flags |=EFCT_SCSI_CMD_SIMPLE ; +break ; +case FCP_PTA_HEADQ : + flags |=EFCT_SCSI_CMD_HEAD_OF_QUEUE ; +break ; +case FCP_PTA_ORDERED : + flags |=EFCT_SCSI_CMD_ORDERED ; +break ; +case FCP_PTA_ACA : + flags |=EFCT_SCSI_CMD_ACA ; +break ; + } +if (cmnd->fc_flags &FCP_CFL_WRDATA ) + flags |=EFCT_SCSI_CMD_DIR_IN ; +if (cmnd->fc_flags &FCP_CFL_RDDATA ) + flags |=EFCT_SCSI_CMD_DIR_OUT ; + +return flags; +} + +static void +efct_sframe_common_send_cb (void *arg,u8 *cqe,int status) +{ +struct efct_hw_send_frame_context *ctx = arg; +struct efct_hw *hw = ctx->hw; + +/* Free WQ completion callback */ +efct_hw_reqtag_free (hw, ctx->wqcb); + +/* Free sequence */ +efct_hw_sequence_free (hw, ctx->seq); +} + +static int +efct_sframe_common_send (struct efc_node *node, +struct efc_hw_sequence *seq, +enum fc_rctl r_ctl,u32 f_ctl, +u8 type,void *payload,u32 payload_len) +{ +struct efct *efct = node->efc->base; +struct efct_hw *hw = &efct->hw; +enum efct_hw_rtn rc =0 ; +struct fc_frame_header *req_hdr = seq->header->dma.virt; +struct fc_frame_header hdr; +struct efct_hw_send_frame_context *ctx; + +u32 heap_size = seq->payload->dma.size; +uintptr_t heap_phys_base = seq->payload->dma.phys; +u8 *heap_virt_base = seq->payload->dma.virt; +u32 heap_offset =0 ; + +/* Build the FC header reusing the RQ header DMA buffer */ +memset (&hdr,0 ,sizeof (hdr)); + hdr.fh_r_ctl = r_ctl; +/* send it back to whomever sent it to us */ +memcpy (hdr.fh_d_id, req_hdr->fh_s_id,sizeof (hdr.fh_d_id)); +memcpy (hdr.fh_s_id, req_hdr->fh_d_id,sizeof (hdr.fh_s_id)); + hdr.fh_type = type; +hton24 (hdr.fh_f_ctl, f_ctl); + hdr.fh_ox_id = req_hdr->fh_ox_id; + hdr.fh_rx_id = req_hdr->fh_rx_id; + hdr.fh_cs_ctl =0 ; + hdr.fh_df_ctl =0 ; + hdr.fh_seq_cnt =0 ; + hdr.fh_parm_offset =0 ; + +/* +* send_frame_seq_id is an atomic, we just let it increment, +* while storing only the low 8 bits to hdr->seq_id +*/ + hdr.fh_seq_id = (u8 )atomic_add_return (1 , &hw->send_frame_seq_id); + hdr.fh_seq_id--; + +/* Allocate and fill in the send frame request context */ + ctx = (void *)(heap_virt_base + heap_offset); + heap_offset +=sizeof (*ctx); +if (heap_offset > heap_size) { +efc_log_err (efct,"Fill send frame failed offset %d size %d\n" , + heap_offset, heap_size); +return EFC_FAIL ; + } + +memset (ctx,0 ,sizeof (*ctx)); + +/* Save sequence */ + ctx->seq = seq; + +/* Allocate a response payload DMA buffer from the heap */ + ctx->payload.phys = heap_phys_base + heap_offset; + ctx->payload.virt = heap_virt_base + heap_offset; + ctx->payload.size = payload_len; + ctx->payload.len = payload_len; + heap_offset += payload_len; +if (heap_offset > heap_size) { +efc_log_err (efct,"Fill send frame failed offset %d size %d\n" , + heap_offset, heap_size); +return EFC_FAIL ; + } + +/* Copy the payload in */
drivers/scsi/elx/efct/efct_unsol.c line 478
Quoted 10 lines
drivers/scsi/elx/efct/efct_unsol.c new file +10
-0+memcpy (ctx->payload.virt, payload, payload_len); + +/* Send */ + rc =efct_hw_send_frame (&efct->hw, (void *)&hdr,FC_SOF_N3 , +FC_EOF_T , &ctx->payload, ctx, + efct_sframe_common_send_cb, ctx); +if (rc) +efc_log_test (efct,"efct_hw_send_frame failed: %d\n" , rc); + +return rc ?-1 :0 ;
return code
Quoted 22 lines
drivers/scsi/elx/efct/efct_unsol.c new file +22
-0+} + +static int +efct_sframe_send_fcp_rsp (struct efc_node *node, +struct efc_hw_sequence *seq, +void *rsp,u32 rsp_len) +{ +return efct_sframe_common_send (node, seq, +FC_RCTL_DD_CMD_STATUS , +FC_FC_EX_CTX | +FC_FC_LAST_SEQ | +FC_FC_END_SEQ | +FC_FC_SEQ_INIT , +FC_TYPE_FCP , + rsp, rsp_len); +} + +static int +efct_sframe_send_task_set_full_or_busy (struct efc_node *node, +struct efc_hw_sequence *seq) +{ +struct fcp_resp_with_ext fcprsp;
drivers/scsi/elx/efct/efct_unsol.c line 510
Quoted 10 lines
drivers/scsi/elx/efct/efct_unsol.c new file +10
-0+struct fcp_cmnd *fcpcmd = seq->payload->dma.virt; +int rc =0 ; +unsigned long flags =0 ; +struct efct *efct = node->efc->base; + +/* construct task set full or busy response */ +memset (&fcprsp,0 ,sizeof (fcprsp)); +spin_lock_irqsave (&node->active_ios_lock, flags); + fcprsp.resp.fr_status =list_empty (&node->active_ios) ? +SAM_STAT_BUSY :SAM_STAT_TASK_SET_FULL ;
no need to indent
drivers/scsi/elx/efct/efct_unsol.c line 519
Quoted 9 lines
drivers/scsi/elx/efct/efct_unsol.c new file +9
-0+spin_unlock_irqrestore (&node->active_ios_lock, flags); + *((u32 *)&fcprsp.ext.fr_resid) =be32_to_cpu (fcpcmd->fc_dl); + +/* send it using send_frame */ + rc =efct_sframe_send_fcp_rsp (node, seq, &fcprsp,sizeof (fcprsp)); +if (rc) +efc_log_test (efct, +"efct_sframe_send_fcp_rsp failed: %d\n" , + rc);
aligmentent
Quoted 181 lines
drivers/scsi/elx/efct/efct_unsol.c new file +181
-0+ +return rc; +} + +int +efct_dispatch_fcp_cmd (struct efc_node *node,struct efc_hw_sequence *seq) +{ +struct efc *efc = node->efc; +struct efct *efct = efc->base; +struct fc_frame_header *fchdr = seq->header->dma.virt; +struct fcp_cmnd *cmnd =NULL ; +struct efct_io *io =NULL ; +u32 lun =U32_MAX ; +int rc =0 ; + +if (!seq->payload) { +efc_log_err (efct,"Sequence payload is NULL.\n" ); +return EFC_FAIL ; + } + + cmnd = seq->payload->dma.virt; + +/* perform FCP_CMND validation check(s) */ +if (efct_validate_fcp_cmd (efct, seq)) +return EFC_FAIL ; + + lun =scsilun_to_int (&cmnd->fc_lun); +if (lun ==U32_MAX ) +return EFC_FAIL ; + + io =efct_scsi_io_alloc (node,EFCT_SCSI_IO_ROLE_RESPONDER ); +if (!io) { +/* Use SEND_FRAME to send task set full or busy */ + rc =efct_sframe_send_task_set_full_or_busy (node, seq); +if (rc) +efc_log_err (efct,"Failed to send busy task: %d\n" , rc); +return rc; + } + + io->hw_priv = seq->hw_priv; + + io->app_id =0 ; + +/* RQ pair, if we got here, SIT=1 */ +efct_populate_io_fcp_cmd (io, cmnd, fchdr, true); + +if (cmnd->fc_tm_flags) { +efct_dispatch_unsolicited_tmf (io, + cmnd->fc_tm_flags, + node, lun); + }else { +u32 flags =efct_get_flags_fcp_cmd (cmnd); + +if (cmnd->fc_flags &FCP_CFL_LEN_MASK ) { +efc_log_err (efct,"Additional CDB not supported\n" ); +return EFC_FAIL ; + } +/* +* Can return failure for things like task set full and UAs, +* no need to treat as a dropped frame if rc != 0 +*/ +efct_scsi_recv_cmd (io, lun, cmnd->fc_cdb, +sizeof (cmnd->fc_cdb), flags); + } + +return EFC_SUCCESS ; +} + +int +efct_sframe_send_bls_acc (struct efc_node *node, +struct efc_hw_sequence *seq) +{ +struct fc_frame_header *behdr = seq->header->dma.virt; +u16 ox_id =be16_to_cpu (behdr->fh_ox_id); +u16 rx_id =be16_to_cpu (behdr->fh_rx_id); +struct fc_ba_acc acc = {0 }; + + acc.ba_ox_id =cpu_to_be16 (ox_id); + acc.ba_rx_id =cpu_to_be16 (rx_id); + acc.ba_low_seq_cnt =cpu_to_be16 (U16_MAX ); + acc.ba_high_seq_cnt =cpu_to_be16 (U16_MAX ); + +return efct_sframe_common_send (node, seq, +FC_RCTL_BA_ACC , +FC_FC_EX_CTX | +FC_FC_LAST_SEQ | +FC_FC_END_SEQ , +FC_TYPE_BLS , + &acc,sizeof (acc)); +} + +void +efct_node_io_cleanup (struct efc *efc,struct efc_node *node,bool force) +{ +struct efct_io *io; +struct efct_io *next; +unsigned long flags =0 ; +struct efct *efct = efc->base; + +spin_lock_irqsave (&node->active_ios_lock, flags); +list_for_each_entry_safe (io, next, &node->active_ios, list_entry) { +list_del (&io->list_entry); +efct_io_pool_io_free (efct->xport->io_pool, io); + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +void +efct_node_els_cleanup (struct efc *efc,struct efc_node *node, +bool force) +{ +struct efct_io *els; +struct efct_io *els_next; +struct efct_io *ls_acc_io; +unsigned long flags =0 ; +struct efct *efct = efc->base; + +/* first cleanup ELS's that are pending (not yet active) */ +spin_lock_irqsave (&node->active_ios_lock, flags); +list_for_each_entry_safe (els, els_next, &node->els_io_pend_list, + list_entry) { +/* +* skip the ELS IO for which a response +* will be sent after shutdown +*/ +if (node->send_ls_acc !=EFC_NODE_SEND_LS_ACC_NONE && + els == node->ls_acc_io) { +continue ; + } +/* +* can't call efct_els_io_free() +* because lock is held; cleanup manually +*/ +node_printf (node,"Freeing pending els %s\n" , + els->display_name); +list_del (&els->list_entry); + +dma_free_coherent (&efct->pcidev->dev, + els->els_rsp.size, els->els_rsp.virt, + els->els_rsp.phys); +dma_free_coherent (&efct->pcidev->dev, + els->els_req.size, els->els_req.virt, + els->els_req.phys); +memset (&els->els_rsp,0 ,sizeof (struct efc_dma )); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); + + ls_acc_io = node->ls_acc_io; + +if (node->ls_acc_io && ls_acc_io->hio) { +/* +* if there's an IO that will result in an LS_ACC after +* shutdown and its HW IO is non-NULL, it better be an +* implicit logout in vanilla sequence coalescing. In this +* case, force the LS_ACC to go out on another XRI (hio) +* since the previous will have been aborted by the UNREG_RPI +*/ +node_printf (node, +"invalidating ls_acc_io due to implicit logo\n" ); + +/* +* No need to abort because the unreg_rpi +* takes care of it, just free +*/ +efct_hw_io_free (&efct->hw, ls_acc_io->hio); + +/* NULL out hio to force the LS_ACC to grab a new XRI */ + ls_acc_io->hio =NULL ; + } +} + +void +efct_node_abort_all_els (struct efc *efc,struct efc_node *node) +{ +struct efct_io *els; +struct efct_io *els_next; +struct efc_node_cb cbdata; +struct efct *efct = efc->base; +unsigned long flags =0 ;
drivers/scsi/elx/efct/efct_unsol.c line 710
Quoted 10 lines
drivers/scsi/elx/efct/efct_unsol.c new file +10
-0+ +memset (&cbdata,0 ,sizeof (struct efc_node_cb )); +spin_lock_irqsave (&node->active_ios_lock, flags); +list_for_each_entry_safe (els, els_next, &node->els_io_active_list, + list_entry) { +if (els->els_req_free) +continue ; +efc_log_debug (efct,"[%s] initiate ELS abort %s\n" , + node->display_name, els->display_name); +spin_unlock_irqrestore (&node->active_ios_lock, flags);
move the debug lot out of the locking section.
Quoted 110 lines
drivers/scsi/elx/efct/efct_unsol.c new file +103
-0+efct_els_abort (els, &cbdata); +spin_lock_irqsave (&node->active_ios_lock, flags); + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +static int +efct_process_abts (struct efct_io *io,struct fc_frame_header *hdr) +{ +struct efc_node *node = io->node; +struct efct *efct = io->efct; +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); +u16 rx_id =be16_to_cpu (hdr->fh_rx_id); +struct efct_io *abortio; + +/* Find IO and attempt to take a reference on it */ + abortio =efct_io_find_tgt_io (efct, node, ox_id, rx_id); + +if (abortio) { +/* Got a reference on the IO. Hold it until backend +* is notified below +*/ +node_printf (node,"Abort request: ox_id [%04x] rx_id [%04x]\n" , + ox_id, rx_id); + +/* +* Save the ox_id for the ABTS as the init_task_tag in our +* manufactured +* TMF IO object +*/ + io->display_name ="abts" ; + io->init_task_tag = ox_id; +/* don't set tgt_task_tag, don't want to confuse with XRI */ + +/* +* Save the rx_id from the ABTS as it is +* needed for the BLS response, +* regardless of the IO context's rx_id +*/ + io->abort_rx_id = rx_id; + +/* Call target server command abort */ + io->tmf_cmd =EFCT_SCSI_TMF_ABORT_TASK ; +efct_scsi_recv_tmf (io, abortio->tgt_io.lun, +EFCT_SCSI_TMF_ABORT_TASK , abortio,0 ); + +/* +* Backend will have taken an additional +* reference on the IO if needed; +* done with current reference. +*/ +kref_put (&abortio->ref, abortio->release); + }else { +/* +* Either IO was not found or it has been +* freed between finding it +* and attempting to get the reference, +*/ +node_printf (node, +"Abort request: ox_id [%04x], IO not found (exists=%d)\n" , + ox_id, (abortio !=NULL )); + +/* Send a BA_RJT */ +efct_bls_send_rjt_hdr (io, hdr); + } +return EFC_SUCCESS ; +} + +int +efct_node_recv_abts_frame (struct efc *efc,struct efc_node *node, +struct efc_hw_sequence *seq) +{ +struct efct *efct = efc->base; +struct fc_frame_header *hdr = seq->header->dma.virt; +struct efct_io *io =NULL ; + + node->abort_cnt++; + + io =efct_scsi_io_alloc (node,EFCT_SCSI_IO_ROLE_RESPONDER ); +if (io) { + io->hw_priv = seq->hw_priv; +/* If we got this far, SIT=1 */ + io->seq_init =1 ; + +/* fill out generic fields */ + io->efct = efct; + io->node = node; + io->cmd_tgt = true; + +efct_process_abts (io, seq->header->dma.virt); + }else { +node_printf (node, +"SCSI IO allocation failed for ABTS received " ); +node_printf (node, +"s_id %06x d_id %06x ox_id %04x rx_id %04x\n" , +ntoh24 (hdr->fh_s_id), +ntoh24 (hdr->fh_d_id), +be16_to_cpu (hdr->fh_ox_id), +be16_to_cpu (hdr->fh_rx_id)); + } + +return EFC_SUCCESS ; +}drivers/scsi/elx/efct/efct_unsol.h new file +1
-0@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */
drivers/scsi/elx/efct/efct_unsol.h line 11
Quoted 10 lines
drivers/scsi/elx/efct/efct_unsol.h new file +10
-0+/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__OSC_UNSOL_H__) +#define __OSC_UNSOL_H__ + +extern int +efct_unsolicited_cb (void *arg,struct efc_hw_sequence *seq);
extern is not needed
Quoted 41 lines
drivers/scsi/elx/efct/efct_unsol.h new file +38
-0+extern int +efct_node_purge_pending (struct efc *efc,struct efc_node *node); +extern void +efct_process_node_pending (struct efc_node *domain); +extern void +efct_domain_process_pending (struct efc_domain *domain); +extern int +efct_domain_purge_pending (struct efc_domain *domain); +extern int +efct_dispatch_unsolicited_bls (struct efc_node *node, +struct efc_hw_sequence *seq); +extern void +efct_domain_hold_frames (struct efc *efc,struct efc_domain *domain); +extern void +efct_domain_accept_frames (struct efc *efc,struct efc_domain *domain); +extern void +efct_seq_coalesce_cleanup (struct efct_hw_io *io,u8 count); +extern int +efct_sframe_send_bls_acc (struct efc_node *node, +struct efc_hw_sequence *seq); +extern int +efct_dispatch_fcp_cmd (struct efc_node *node,struct efc_hw_sequence *seq); + +extern int +efct_node_recv_abts_frame (struct efc *efc,struct efc_node *node, +struct efc_hw_sequence *seq); +extern void +efct_node_els_cleanup (struct efc *efc,struct efc_node *node, +bool force); + +extern void +efct_node_io_cleanup (struct efc *efc,struct efc_node *node, +bool force); + +void +efct_node_abort_all_els (struct efc *efc,struct efc_node *node); + +#endif /* __OSC_UNSOL_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 22/31 elx: efct: Extended link Service IO handling
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Functions to build and send ELS/CT/BLS commands and responses.
---
v3:
Unified log message using cmd_name
Return and drop else, for better indentation and consistency. Changed assertion log messages.
--- drivers/scsi/elx/efct/efct_els.c | 1928 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_els.h | 133 +++ 2 files changed, 2061 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_els.c create mode 100644 drivers/scsi/elx/efct/efct_els.h
drivers/scsi/elx/efct/efct_els.c new file +1928 -0
@@ -0,0 +1,1928 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* Functions to build and send ELS/CT/BLS commands and responses. +*/ + +#include "efct_driver.h" +#include "efct_els.h" + +#define ELS_IOFMT "[i:%04x t:%04x h:%04x]" + +#define EFCT_LOG_ENABLE_ELS_TRACE (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 1)) != 0) : 0) + +#define node_els_trace () \ + do { \ + if (EFCT_LOG_ENABLE_ELS_TRACE(efct)) \ + efc_log_info(efct, "[%s] %-20s\n", \ + node->display_name, __func__); \ + } while (0) + +#define els_io_printf (els, fmt, ...) \ + efc_log_debug((struct efct *)els->node->efc->base,\ + "[%s]" ELS_IOFMT " %-8s " fmt, \ + els->node->display_name,\ + els->init_task_tag, els->tgt_task_tag, els->hw_tag,\ + els->display_name, ##__VA_ARGS__) + +#define EFCT_ELS_RSP_LEN 1024 +#define EFCT_ELS_GID_PT_RSP_LEN 8096 + +static char *cmd_name[] =FC_ELS_CMDS_INIT ; + +void * +efct_els_req_send (struct efc *efc,struct efc_node *node,u32 cmd, +u32 timeout_sec,u32 retries) +{ +struct efct *efct = efc->base; + +efc_log_debug (efct,"send %s\n" , cmd_name[cmd]); + +switch (cmd) { +case ELS_PLOGI : +return efct_send_plogi (node, timeout_sec, retries,NULL ,NULL ); +case ELS_FLOGI : +return efct_send_flogi (node, timeout_sec, retries,NULL ,NULL ); +case ELS_FDISC : +return efct_send_fdisc (node, timeout_sec, retries,NULL ,NULL ); +case ELS_LOGO : +return efct_send_logo (node, timeout_sec, retries,NULL ,NULL ); +case ELS_PRLI : +return efct_send_prli (node, timeout_sec, retries,NULL ,NULL ); +case ELS_ADISC : +return efct_send_adisc (node, timeout_sec, retries,NULL ,NULL ); +case ELS_SCR : +return efct_send_scr (node, timeout_sec, retries,NULL ,NULL ); +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} + +void * +efct_els_resp_send (struct efc *efc,struct efc_node *node, +u32 cmd,u16 ox_id) +{ +struct efct *efct = efc->base; + +switch (cmd) { +case ELS_PLOGI : +efct_send_plogi_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_FLOGI : +efct_send_flogi_acc (node, ox_id,0 ,NULL ,NULL ); +break ; +case ELS_LOGO : +efct_send_logo_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PRLI : +efct_send_prli_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PRLO : +efct_send_prlo_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_ADISC : +efct_send_adisc_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_LS_ACC : +efct_send_ls_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PDISC : +case ELS_FDISC : +case ELS_RSCN : +case ELS_SCR : +efct_send_ls_rjt (efc, node, ox_id,ELS_RJT_UNAB , +ELS_EXPL_NONE ,0 ); +break ; +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} + +struct efct_io * +efct_els_io_alloc (struct efc_node *node,u32 reqlen, +enum efct_els_role role) +{ +return efct_els_io_alloc_size (node, reqlen,EFCT_ELS_RSP_LEN , role); +} + +struct efct_io * +efct_els_io_alloc_size (struct efc_node *node,u32 reqlen, +u32 rsplen,enum efct_els_role role) +{ +struct efct *efct; +struct efct_xport *xport; +struct efct_io *els; +unsigned long flags =0 ; + + efct = node->efc->base; + + xport = efct->xport; + +spin_lock_irqsave (&node->active_ios_lock, flags); + +if (!node->io_alloc_enabled) { +efc_log_debug (efct, +"called with io_alloc_enabled = FALSE\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + + els =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!els) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* initialize refcount */ +kref_init (&els->ref); + els->release = _efct_els_io_free; + +switch (role) { +case EFCT_ELS_ROLE_ORIGINATOR : + els->cmd_ini = true; + els->cmd_tgt = false; +break ; +case EFCT_ELS_ROLE_RESPONDER : + els->cmd_ini = false; + els->cmd_tgt = true; +break ; + } + +/* IO should not have an associated HW IO yet. +* Assigned below. +*/ +if (els->hio) { +efc_log_err (efct,"Error: HW io not null hio:%p\n" , els->hio); +efct_io_pool_io_free (efct->xport->io_pool, els); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* populate generic io fields */ + els->efct = efct; + els->node = node; + +/* set type and ELS-specific fields */ + els->io_type =EFCT_IO_TYPE_ELS ; + els->display_name ="pending" ; + +/* now allocate DMA for request and response */ + els->els_req.size = reqlen; + els->els_req.virt =dma_alloc_coherent (&efct->pcidev->dev, + els->els_req.size, + &els->els_req.phys, +GFP_DMA ); +if (els->els_req.virt) { + els->els_rsp.size = rsplen; + els->els_rsp.virt =dma_alloc_coherent (&efct->pcidev->dev, + els->els_rsp.size, + &els->els_rsp.phys, +GFP_DMA ); +if (!els->els_rsp.virt) { +efc_log_err (efct,"dma_alloc rsp\n" ); +dma_free_coherent (&efct->pcidev->dev, + els->els_req.size, + els->els_req.virt, els->els_req.phys); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + els =NULL ; + } + }else { +efc_log_err (efct,"dma_alloc req\n" ); +efct_io_pool_io_free (efct->xport->io_pool, els); + els =NULL ; + } + +if (els) { +/* initialize fields */ + els->els_retries_remaining = +EFCT_FC_ELS_DEFAULT_RETRIES ; + els->els_pend = false; + els->els_active = false; + +/* add els structure to ELS IO list */ +INIT_LIST_HEAD (&els->list_entry); +list_add_tail (&els->list_entry, + &node->els_io_pend_list); + els->els_pend = true; + } + +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return els; +} + +void +efct_els_io_free (struct efct_io *els) +{ +kref_put (&els->ref, els->release); +} + +void +_efct_els_io_free (struct kref *arg) +{ + struct efct_io *els = container_of(arg, struct efct_io, ref); +struct efct *efct; +struct efc_node *node; +int send_empty_event = false; +unsigned long flags =0 ; + + node = els->node; + efct = node->efc->base; + +spin_lock_irqsave (&node->active_ios_lock, flags); +if (els->els_active) { +/* if active, remove from active list and check empty */ +list_del (&els->list_entry); +/* Send list empty event if the IO allocator +* is disabled, and the list is empty +* If node->io_alloc_enabled was not checked, +* the event would be posted continually +*/ + send_empty_event = (!node->io_alloc_enabled) && +list_empty (&node->els_io_active_list); + els->els_active = false; + }else if (els->els_pend) { +/* if pending, remove from pending list; +* node shutdown isn't gated off the +* pending list (only the active list), +* so no need to check if pending list is empty +*/ +list_del (&els->list_entry); + els->els_pend =0 ; + }else { +efc_log_err (efct, +"Error: els not in pending or active set\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return ; + } + +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +/* free ELS request and response buffers */ +dma_free_coherent (&efct->pcidev->dev, els->els_rsp.size, + els->els_rsp.virt, els->els_rsp.phys); +dma_free_coherent (&efct->pcidev->dev, els->els_req.size, + els->els_req.virt, els->els_req.phys); + +memset (&els->els_rsp,0 ,sizeof (struct efc_dma )); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + +if (send_empty_event) +efc_scsi_io_list_empty (node->efc, node); + +efct_scsi_check_pending (efct); +} + +static void +efct_els_make_active (struct efct_io *els) +{ +struct efc_node *node = els->node; +unsigned long flags =0 ; + +/* move ELS from pending list to active list */ +spin_lock_irqsave (&node->active_ios_lock, flags); +if (els->els_pend) { +if (els->els_active) { +efc_log_err (node->efc, +"Error: els in both pend and active\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, + flags); +return ; + } +/* remove from pending list */ +list_del (&els->list_entry); + els->els_pend = false; + +/* add els structure to ELS IO list */ +INIT_LIST_HEAD (&els->list_entry); +list_add_tail (&els->list_entry, + &node->els_io_active_list); + els->els_active = true; + }else { +/* must be retrying; make sure it's already active */ +if (!els->els_active) { +efc_log_err (node->efc, +"Error: els not in pending or active set\n" ); + } + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +static int efct_els_send (struct efct_io *els,u32 reqlen, +u32 timeout_sec,efct_hw_srrs_cb_t cb) +{ +struct efc_node *node = els->node; + +/* update ELS request counter */ + node->els_req_cnt++; + +/* move ELS from pending list to active list */ +efct_els_make_active (els); + + els->wire_len = reqlen; +return efct_scsi_io_dispatch (els, cb); +} + +static void +efct_els_retry (struct efct_io *els); + +static void +efct_els_delay_timer_cb (struct timer_list *t) +{ +struct efct_io *els =from_timer (els, t, delay_timer); +struct efc_node *node = els->node; + +/* Retry delay timer expired, retry the ELS request, +* Free the HW IO so that a new oxid is used. +*/ +if (els->state ==EFCT_ELS_REQUEST_DELAY_ABORT ) { + node->els_req_cnt++; +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , +NULL ); + }else { +efct_els_retry (els); + } +} + +static void +efct_els_abort_cleanup (struct efct_io *els) +{ +/* handle event for ABORT_WQE +* whatever state ELS happened to be in, propagate aborted even +* up to node state machine in lieu of EFC_HW_SRRS_ELS_* event +*/ +struct efc_node_cb cbdata; + + cbdata.status =0 ; + cbdata.ext_status =0 ; + cbdata.els_rsp = els->els_rsp; +els_io_printf (els,"Request aborted\n" ); +efct_els_io_cleanup (els,EFC_HW_ELS_REQ_ABORTED , &cbdata); +} + +static int +efct_els_req_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *arg) +{ +struct efct_io *els; +struct efc_node *node; +struct efct *efct; +struct efc_node_cb cbdata; +u32 reason_code; + + els = arg; + node = els->node; + efct = node->efc->base; + +if (status !=0 ) +els_io_printf (els,"status x%x ext x%x\n" , status, ext_status); + +/* set the response len element of els->rsp */ + els->els_rsp.len = length; + + cbdata.status = status; + cbdata.ext_status = ext_status; + cbdata.header =NULL ; + cbdata.els_rsp = els->els_rsp; + +/* FW returns the number of bytes received on the link in +* the WCQE, not the amount placed in the buffer; use this info to +* check if there was an overrun. +*/ +if (length > els->els_rsp.size) { +efc_log_warn (efct, +"ELS response returned len=%d > buflen=%zu\n" , + length, els->els_rsp.size); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , &cbdata); +return EFC_SUCCESS ; + } + +/* Post event to ELS IO object */ +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_OK , &cbdata); +break ; + +case SLI4_FC_WCQE_STATUS_LS_RJT : + reason_code = (ext_status >>16 ) &0xff ; + +/* delay and retry if reason code is Logical Busy */ +switch (reason_code) { +case ELS_RJT_BUSY : + els->node->els_req_cnt--; +els_io_printf (els, +"LS_RJT Logical Busy response,delay and retry\n" ); +timer_setup (&els->delay_timer, + efct_els_delay_timer_cb,0 ); +mod_timer (&els->delay_timer, + jiffies +msecs_to_jiffies (5000 )); + els->state =EFCT_ELS_REQUEST_DELAYED ; +break ; +default : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_RJT , + &cbdata); +break ; + } +break ; + +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT : +efct_els_retry (els); +break ; + +case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED : +if (els->state ==EFCT_ELS_ABORT_IO_COMPL ) { +/* completion for ELS that was aborted */ +efct_els_abort_cleanup (els); + }else { +/* completion for ELS received first, +* transition to wait for abort cmpl +*/ + els->state =EFCT_ELS_REQ_ABORTED ; + } + +break ; +default : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); +break ; + } +break ; +default :/* Other error */ +efc_log_warn (efct, +"els req failed status x%x, ext_status, x%x\n" , + status, ext_status); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , &cbdata); +break ; + } + +return EFC_SUCCESS ; +} + +static void efct_els_send_req (struct efc_node *node,struct efct_io *els) +{ +int rc =0 ; +struct efct *efct; + + efct = node->efc->base; + rc =efct_els_send (els, els->els_req.size, + els->els_timeout_sec, efct_els_req_cb); + +if (rc) { +struct efc_node_cb cbdata; + + cbdata.status =INT_MAX ; + cbdata.ext_status =INT_MAX ; + cbdata.els_rsp = els->els_rsp; +efc_log_err (efct,"efct_els_send failed: %d\n" , rc); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); + } +} + +static void +efct_els_retry (struct efct_io *els) +{ +struct efct *efct; +struct efc_node_cb cbdata; + + efct = els->node->efc->base; + cbdata.status =INT_MAX ; + cbdata.ext_status =INT_MAX ; + cbdata.els_rsp = els->els_rsp; + +if (!els->els_retries_remaining) { +efc_log_err (efct,"ELS retries exhausted\n" ); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); +return ; + } + + els->els_retries_remaining--; +/* Free the HW IO so that a new oxid is used.*/ +if (els->hio) { +efct_hw_io_free (&efct->hw, els->hio); + els->hio =NULL ; + } + +efct_els_send_req (els->node, els); +} + +static int +efct_els_acc_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *arg) +{ +struct efct_io *els; +struct efc_node *node; +struct efct *efct; +struct efc_node_cb cbdata; + + els = arg; + node = els->node; + efct = node->efc->base; + + cbdata.status = status; + cbdata.ext_status = ext_status; + cbdata.header =NULL ; + cbdata.els_rsp = els->els_rsp; + +/* Post node event */ +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_CMPL_OK , &cbdata); +break ; + +default :/* Other error */ +efc_log_warn (efct, +"[%s] %-8s failed status x%x, ext_status x%x\n" , + node->display_name, els->display_name, + status, ext_status); +efc_log_warn (efct, +"els acc complete: failed status x%x, ext_status, x%x\n" , + status, ext_status); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_CMPL_FAIL , &cbdata); +break ; + } + +return EFC_SUCCESS ; +} + +static int +efct_els_send_rsp (struct efct_io *els,u32 rsplen) +{ +struct efc_node *node = els->node; + +/* increment ELS completion counter */ + node->els_cmpl_cnt++; + +/* move ELS from pending list to active list */ +efct_els_make_active (els); + + els->wire_len = rsplen; +return efct_scsi_io_dispatch (els, efct_els_acc_cb); +} + +struct efct_io * +efct_send_plogi (struct efc_node *node,u32 timeout_sec, +u32 retries, +void (*cb)(struct efc_node *node, +struct efc_node_cb *cbdata,void *arg),void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_flogi *plogi; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*plogi),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="plogi" ; + +/* Build PLOGI request */ + plogi = els->els_req.virt; + +memcpy (plogi, node->sport->service_params,sizeof (*plogi)); + + plogi->fl_cmd =ELS_PLOGI ; +memset (plogi->_fl_resvd,0 ,sizeof (plogi->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_flogi (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_flogi *flogi; + + efct = node->efc->base; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="flogi" ; + +/* Build FLOGI request */ + flogi = els->els_req.virt; + +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + flogi->fl_cmd =ELS_FLOGI ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_fdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_flogi *fdisc; + + efct = node->efc->base; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*fdisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="fdisc" ; + +/* Build FDISC request */ + fdisc = els->els_req.virt; + +memcpy (fdisc, node->sport->service_params,sizeof (*fdisc)); + fdisc->fl_cmd =ELS_FDISC ; +memset (fdisc->_fl_resvd,0 ,sizeof (fdisc->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_prli (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct *efct = node->efc->base; +struct efct_io *els; +struct { +struct fc_els_prli prli; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="prli" ; + +/* Build PRLI request */ + pp = els->els_req.virt; + +memset (pp,0 ,sizeof (*pp)); + + pp->prli.prli_cmd =ELS_PRLI ; + pp->prli.prli_spp_len =16 ; + pp->prli.prli_len =cpu_to_be16 (sizeof (*pp)); + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_EST_IMG_PAIR ; + pp->spp.spp_params =cpu_to_be32 (FCP_SPPF_RD_XRDY_DIS | + (node->sport->enable_ini ? +FCP_SPPF_INIT_FCN :0 ) | + (node->sport->enable_tgt ? +FCP_SPPF_TARG_FCN :0 )); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_prlo (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct *efct = node->efc->base; +struct efct_io *els; +struct { +struct fc_els_prlo prlo; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="prlo" ; + +/* Build PRLO request */ + pp = els->els_req.virt; + +memset (pp,0 ,sizeof (*pp)); + pp->prlo.prlo_cmd =ELS_PRLO ; + pp->prlo.prlo_obs =0x10 ; + pp->prlo.prlo_len =cpu_to_be16 (sizeof (*pp)); + + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_logo (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_logo *logo; +struct fc_els_flogi *sparams; + + efct = node->efc->base; + +node_els_trace (); + + sparams = (struct fc_els_flogi *)node->sport->service_params; + + els =efct_els_io_alloc (node,sizeof (*logo),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="logo" ; + +/* Build LOGO request */ + + logo = els->els_req.virt; + +memset (logo,0 ,sizeof (*logo)); + logo->fl_cmd =ELS_LOGO ; +hton24 (logo->fl_n_port_id, node->rnode.sport->fc_id); + logo->fl_n_port_wwn = sparams->fl_wwpn; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_adisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_adisc *adisc; +struct fc_els_flogi *sparams; +struct efc_sli_port *sport = node->sport; + + efct = node->efc->base; + +node_els_trace (); + + sparams = (struct fc_els_flogi *)node->sport->service_params; + + els =efct_els_io_alloc (node,sizeof (*adisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="adisc" ; + +/* Build ADISC request */ + + adisc = els->els_req.virt; + +memset (adisc,0 ,sizeof (*adisc)); + adisc->adisc_cmd =ELS_ADISC ; +hton24 (adisc->adisc_hard_addr, sport->fc_id); + adisc->adisc_wwpn = sparams->fl_wwpn; + adisc->adisc_wwnn = sparams->fl_wwnn; +hton24 (adisc->adisc_port_id, node->rnode.sport->fc_id); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_pdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_flogi *pdisc; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pdisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="pdisc" ; + + pdisc = els->els_req.virt; + +memcpy (pdisc, node->sport->service_params,sizeof (*pdisc)); + + pdisc->fl_cmd =ELS_PDISC ; +memset (pdisc->_fl_resvd,0 ,sizeof (pdisc->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_scr (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_scr *req; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*req),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="scr" ; + + req = els->els_req.virt; + +memset (req,0 ,sizeof (*req)); + req->scr_cmd =ELS_SCR ; + req->scr_reg_func =ELS_SCRF_FULL ; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_rscn (struct efc_node *node,u32 timeout_sec,u32 retries, +void *port_ids,u32 port_ids_count,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_rscn *req; +struct fc_els_rscn_page *rscn_page; +u32 length =sizeof (*rscn_page) * port_ids_count; + + length +=sizeof (*req); + +node_els_trace (); + + els =efct_els_io_alloc (node, length,EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rscn" ; + + req = els->els_req.virt; + + req->rscn_cmd =ELS_RSCN ; + req->rscn_page_len =sizeof (struct fc_els_rscn_page ); + req->rscn_plen =cpu_to_be16 (length); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +/* copy in the payload */ + rscn_page = els->els_req.virt +sizeof (*req); +memcpy (rscn_page, port_ids, + port_ids_count *sizeof (*rscn_page)); + +efct_els_send_req (node, els); + +return els; +} + +void * +efct_send_ls_rjt (struct efc *efc,struct efc_node *node, +u32 ox_id,u32 reason_code, +u32 reason_code_expl,u32 vendor_unique) +{ +struct efct_io *io =NULL ; +int rc; +struct efct *efct = node->efc->base; +struct fc_els_ls_rjt *rjt; + + io =efct_els_io_alloc (node,sizeof (*rjt),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + +node_els_trace (); + + io->els_callback =NULL ; + io->els_callback_arg =NULL ; + io->display_name ="ls_rjt" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + rjt = io->els_req.virt; +memset (rjt,0 ,sizeof (*rjt)); + + rjt->er_cmd =ELS_LS_RJT ; + rjt->er_reason = reason_code; + rjt->er_explan = reason_code_expl; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*rjt)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_plogi_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct fc_els_flogi *plogi; +struct fc_els_flogi *req = (struct fc_els_flogi *)node->service_params; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*plogi),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="plogi_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + plogi = io->els_req.virt; + +/* copy our port's service parameters to payload */ +memcpy (plogi, node->sport->service_params,sizeof (*plogi)); + plogi->fl_cmd =ELS_LS_ACC ; +memset (plogi->_fl_resvd,0 ,sizeof (plogi->_fl_resvd)); + +/* Set Application header support bit if requested */ +if (req->fl_csp.sp_features &cpu_to_be16 (FC_SP_FT_BCAST )) + plogi->fl_csp.sp_features |=cpu_to_be16 (FC_SP_FT_BCAST ); + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*plogi)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } +return io; +} + +void * +efct_send_flogi_p2p_acc (struct efc *efc,struct efc_node *node, +u32 ox_id,u32 s_id) +{ +struct efct_io *io =NULL ; +int rc; +struct efct *efct = node->efc->base; +struct fc_els_flogi *flogi; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback =NULL ; + io->els_callback_arg =NULL ; + io->display_name ="flogi_p2p_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + io->iparam.els.s_id = s_id; + + flogi = io->els_req.virt; + +/* copy our port's service parameters to payload */ +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + flogi->fl_cmd =ELS_LS_ACC ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + +memset (flogi->fl_cssp,0 ,sizeof (flogi->fl_cssp)); + + io->hio_type =EFCT_HW_ELS_RSP_SID ; + rc =efct_els_send_rsp (io,sizeof (*flogi)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_flogi_acc (struct efc_node *node,u32 ox_id,u32 is_fport, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct fc_els_flogi *flogi; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="flogi_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + io->iparam.els.s_id = io->node->sport->fc_id; + + flogi = io->els_req.virt; + +/* copy our port's service parameters to payload */ +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + +/* Set F_port */ +if (is_fport) { +/* Set F_PORT and Multiple N_PORT_ID Assignment */ + flogi->fl_csp.sp_r_a_tov |=cpu_to_be32 (3U <<28 ); + } + + flogi->fl_cmd =ELS_LS_ACC ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + +memset (flogi->fl_cssp,0 ,sizeof (flogi->fl_cssp)); + + io->hio_type =EFCT_HW_ELS_RSP_SID ; + rc =efct_els_send_rsp (io,sizeof (*flogi)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io *efct_send_prli_acc (struct efc_node *node, +u32 ox_id,els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct { +struct fc_els_prli prli; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="prli_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + pp = io->els_req.virt; +memset (pp,0 ,sizeof (*pp)); + + pp->prli.prli_cmd =ELS_LS_ACC ; + pp->prli.prli_spp_len =0x10 ; + pp->prli.prli_len =cpu_to_be16 (sizeof (*pp)); + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_EST_IMG_PAIR |FC_SPP_RESP_ACK ; + + pp->spp.spp_params =cpu_to_be32 (FCP_SPPF_RD_XRDY_DIS | + (node->sport->enable_ini ? +FCP_SPPF_INIT_FCN :0 ) | + (node->sport->enable_tgt ? +FCP_SPPF_TARG_FCN :0 )); + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*pp)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_prlo_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct { +struct fc_els_prlo prlo; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="prlo_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + pp = io->els_req.virt; +memset (pp,0 ,sizeof (*pp)); + pp->prlo.prlo_cmd =ELS_LS_ACC ; + pp->prlo.prlo_obs =0x10 ; + pp->prlo.prlo_len =cpu_to_be16 (sizeof (*pp)); + + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_RESP_ACK ; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*pp)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_ls_acc (struct efc_node *node,u32 ox_id,els_cb_t cb, +void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct fc_els_ls_acc *acc; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*acc),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="ls_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + acc = io->els_req.virt; +memset (acc,0 ,sizeof (*acc)); + + acc->la_cmd =ELS_LS_ACC ; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*acc)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_logo_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct_io *io =NULL ; +struct efct *efct = node->efc->base; +struct fc_els_ls_acc *logo; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*logo),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="logo_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + logo = io->els_req.virt; +memset (logo,0 ,sizeof (*logo)); + + logo->la_cmd =ELS_LS_ACC ; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*logo)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_adisc_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct_io *io =NULL ; +struct fc_els_adisc *adisc; +struct fc_els_flogi *sparams; +struct efct *efct; + + efct = node->efc->base; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*adisc),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="adisc_acc" ; + io->init_task_tag = ox_id; + +/* Go ahead and send the ELS_ACC */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + sparams = (struct fc_els_flogi *)node->sport->service_params; + adisc = io->els_req.virt; +memset (adisc,0 ,sizeof (*adisc)); + adisc->adisc_cmd =ELS_LS_ACC ; + adisc->adisc_wwpn = sparams->fl_wwpn; + adisc->adisc_wwnn = sparams->fl_wwnn; +hton24 (adisc->adisc_port_id, node->rnode.sport->fc_id); + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*adisc)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +void * +efct_els_send_ct (struct efc *efc,struct efc_node *node,u32 cmd, +u32 timeout_sec,u32 retries) +{ +struct efct *efct = efc->base; + +switch (cmd) { +case FC_RCTL_ELS_REQ : +efct_ns_send_rftid (node, timeout_sec, retries,NULL ,NULL ); +break ; +case FC_NS_RFF_ID : +efct_ns_send_rffid (node, timeout_sec, retries,NULL ,NULL ); +break ; +case FC_NS_GID_PT : +efct_ns_send_gidpt (node, timeout_sec, retries,NULL ,NULL ); +break ; +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} + +static inline void fcct_build_req_header (struct fc_ct_hdr *hdr, +u16 cmd,u16 max_size) +{ + hdr->ct_rev =FC_CT_REV ; + hdr->ct_fs_type =FC_FST_DIR ; + hdr->ct_fs_subtype =FC_NS_SUBTYPE ; + hdr->ct_options =0 ; + hdr->ct_cmd =cpu_to_be16 (cmd); +/* words */ + hdr->ct_mr_size =cpu_to_be16 (max_size / (sizeof (u32))); + hdr->ct_reason =0 ; + hdr->ct_explan =0 ; + hdr->ct_vendor =0 ; +} + +struct efct_io * +efct_ns_send_rftid (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_ct_hdr *ct; +struct fc_ns_rft_id *rftid; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*ct) +sizeof (*rftid), +EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->iparam.fc_ct.r_ctl =FC_RCTL_ELS_REQ ; + els->iparam.fc_ct.type =FC_TYPE_CT ; + els->iparam.fc_ct.df_ctl =0 ; + els->iparam.fc_ct.timeout = timeout_sec; + + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rftid" ; + + ct = els->els_req.virt; +memset (ct,0 ,sizeof (*ct)); +fcct_build_req_header (ct,FC_NS_RFT_ID ,sizeof (*rftid)); + + rftid = els->els_req.virt +sizeof (*ct); +memset (rftid,0 ,sizeof (*rftid)); +hton24 (rftid->fr_fid.fp_fid, node->rnode.sport->fc_id); + rftid->fr_fts.ff_type_map[FC_TYPE_FCP /FC_NS_BPW ] = +cpu_to_be32 (1 << (FC_TYPE_FCP %FC_NS_BPW )); + + els->hio_type =EFCT_HW_FC_CT ; +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_ns_send_rffid (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_ct_hdr *ct; +struct fc_ns_rff_id *rffid; +u32 size =0 ; + +node_els_trace (); + + size =sizeof (*ct) +sizeof (*rffid); + + els =efct_els_io_alloc (node, size,EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->iparam.fc_ct.r_ctl =FC_RCTL_ELS_REQ ; + els->iparam.fc_ct.type =FC_TYPE_CT ; + els->iparam.fc_ct.df_ctl =0 ; + els->iparam.fc_ct.timeout = timeout_sec; + + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rffid" ; + ct = els->els_req.virt; + +memset (ct,0 ,sizeof (*ct)); +fcct_build_req_header (ct,FC_NS_RFF_ID ,sizeof (*rffid)); + + rffid = els->els_req.virt +sizeof (*ct); +memset (rffid,0 ,sizeof (*rffid)); + +hton24 (rffid->fr_fid.fp_fid, node->rnode.sport->fc_id); +if (node->sport->enable_ini) + rffid->fr_feat |=FCP_FEAT_INIT ; +if (node->sport->enable_tgt) + rffid->fr_feat |=FCP_FEAT_TARG ; + rffid->fr_type =FC_TYPE_FCP ; + + els->hio_type =EFCT_HW_FC_CT ; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_ns_send_gidpt (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els =NULL ; +struct efct *efct = node->efc->base; +struct fc_ct_hdr *ct; +struct fc_ns_gid_pt *gidpt; +u32 size =0 ; + +node_els_trace (); + + size =sizeof (*ct) +sizeof (*gidpt); + els =efct_els_io_alloc_size (node, size, +EFCT_ELS_GID_PT_RSP_LEN , +EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->iparam.fc_ct.r_ctl =FC_RCTL_ELS_REQ ; + els->iparam.fc_ct.type =FC_TYPE_CT ; + els->iparam.fc_ct.df_ctl =0 ; + els->iparam.fc_ct.timeout = timeout_sec; + + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="gidpt" ; + + ct = els->els_req.virt; + +memset (ct,0 ,sizeof (*ct)); +fcct_build_req_header (ct,FC_NS_GID_PT ,sizeof (*gidpt)); + + gidpt = els->els_req.virt +sizeof (*ct); +memset (gidpt,0 ,sizeof (*gidpt)); + gidpt->fn_pt_type =FC_TYPE_FCP ; + + els->hio_type =EFCT_HW_FC_CT ; + +efct_els_send_req (node, els); + +return els; +} + +static int efct_bls_send_rjt_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode,u32 length, +int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; + +efct_scsi_io_free (io); +return EFC_SUCCESS ; +} + +static struct efct_io * +efct_bls_send_rjt (struct efct_io *io,u32 s_id, +u16 ox_id,u16 rx_id) +{ +struct efc_node *node = io->node; +int rc; +struct fc_ba_rjt *acc; +struct efct *efct; + + efct = node->efc->base; + +if (node->rnode.sport->fc_id == s_id) + s_id =U32_MAX ; + +/* fill out generic fields */ + io->efct = efct; + io->node = node; + io->cmd_tgt = true; + +/* fill out BLS Response-specific fields */ + io->io_type =EFCT_IO_TYPE_BLS_RESP ; + io->display_name ="ba_rjt" ; + io->hio_type =EFCT_HW_BLS_RJT ; + io->init_task_tag = ox_id; + +/* fill out iparam fields */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.bls.ox_id = ox_id; + io->iparam.bls.rx_id = rx_id; + + acc = (void *)io->iparam.bls.payload; + +memset (io->iparam.bls.payload,0 , +sizeof (io->iparam.bls.payload)); + acc->br_reason =ELS_RJT_UNAB ; + acc->br_explan =ELS_EXPL_NONE ; + + rc =efct_scsi_io_dispatch (io, efct_bls_send_rjt_cb); +if (rc) { +efc_log_err (efct,"efct_scsi_io_dispatch() failed: %d\n" , rc); +efct_scsi_io_free (io); + io =NULL ; + } +return io; +} + +struct efct_io * +efct_bls_send_rjt_hdr (struct efct_io *io,struct fc_frame_header *hdr) +{ +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); +u16 rx_id =be16_to_cpu (hdr->fh_rx_id); +u32 d_id =ntoh24 (hdr->fh_d_id); + +return efct_bls_send_rjt (io, d_id, ox_id, rx_id); +} + +static int efct_bls_send_acc_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode,u32 length, +int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; + +efct_scsi_io_free (io); +return EFC_SUCCESS ; +} + +static struct efct_io * +efct_bls_send_acc (struct efct_io *io,u32 s_id, +u16 ox_id,u16 rx_id) +{ +struct efc_node *node = io->node; +int rc; +struct fc_ba_acc *acc; +struct efct *efct; + + efct = node->efc->base; + +if (node->rnode.sport->fc_id == s_id) + s_id =U32_MAX ; + +/* fill out generic fields */ + io->efct = efct; + io->node = node; + io->cmd_tgt = true; + +/* fill out BLS Response-specific fields */ + io->io_type =EFCT_IO_TYPE_BLS_RESP ; + io->display_name ="ba_acc" ; + io->hio_type =EFCT_HW_BLS_ACC_SID ; + io->init_task_tag = ox_id; + +/* fill out iparam fields */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.bls.s_id = s_id; + io->iparam.bls.ox_id = ox_id; + io->iparam.bls.rx_id = rx_id; + + acc = (void *)io->iparam.bls.payload; + +memset (io->iparam.bls.payload,0 , +sizeof (io->iparam.bls.payload)); + acc->ba_ox_id =cpu_to_be16 (io->iparam.bls.ox_id); + acc->ba_rx_id =cpu_to_be16 (io->iparam.bls.rx_id); + acc->ba_high_seq_cnt =cpu_to_be16 (U16_MAX ); + + rc =efct_scsi_io_dispatch (io, efct_bls_send_acc_cb); +if (rc) { +efc_log_err (efct,"efct_scsi_io_dispatch() failed: %d\n" , rc); +efct_scsi_io_free (io); + io =NULL ; + } +return io; +} + +void * +efct_bls_send_acc_hdr (struct efc *efc,struct efc_node *node, +struct fc_frame_header *hdr) +{ +struct efct_io *io =NULL ; +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); +u16 rx_id =be16_to_cpu (hdr->fh_rx_id); +u32 d_id =ntoh24 (hdr->fh_d_id); + + io =efct_scsi_io_alloc (node,EFCT_SCSI_IO_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efc,"els IO alloc failed\n" ); +return io; + } + +return efct_bls_send_acc (io, d_id, ox_id, rx_id); +} + +static int +efct_els_abort_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status, +void *app) +{ +struct efct_io *els; +struct efct_io *abort_io =NULL ;/* IO structure used to abort ELS */ +struct efct *efct; + + abort_io = app; + els = abort_io->io_to_abort; + +if (!els || !els->node || !els->node->efc) +return EFC_FAIL ; + + efct = els->node->efc->base; + +if (status !=0 ) +efc_log_warn (efct,"status x%x ext x%x\n" , status, ext_status); + +/* now free the abort IO */ +efct_io_pool_io_free (efct->xport->io_pool, abort_io); + +/* send completion event to indicate abort process is complete +* Note: The ELS SM will already be receiving +* ELS_REQ_OK/FAIL/RJT/ABORTED +*/ +if (els->state ==EFCT_ELS_REQ_ABORTED ) { +/* completion for ELS that was aborted */ +efct_els_abort_cleanup (els); + }else { +/* completion for abort was received first, +* transition to wait for req cmpl +*/ + els->state =EFCT_ELS_ABORT_IO_COMPL ; + } + +/* done with ELS IO to abort */ +kref_put (&els->ref, els->release); +return EFC_SUCCESS ; +} + +static struct efct_io * +efct_els_abort_io (struct efct_io *els,bool send_abts) +{ +struct efct *efct; +struct efct_xport *xport; +int rc; +struct efct_io *abort_io =NULL ; + + efct = els->node->efc->base; + xport = efct->xport; + +/* take a reference on IO being aborted */ +if ((kref_get_unless_zero (&els->ref) ==0 )) { +/* command no longer active */ +efc_log_debug (efct,"els no longer active\n" ); +return NULL ; + } + +/* allocate IO structure to send abort */ + abort_io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!abort_io) { +atomic_add_return (1 , &xport->io_alloc_failed_count); + }else { +/* set generic fields */ + abort_io->efct = efct; + abort_io->node = els->node; + abort_io->cmd_ini = true; + +/* set type and ABORT-specific fields */ + abort_io->io_type =EFCT_IO_TYPE_ABORT ; + abort_io->display_name ="abort_els" ; + abort_io->io_to_abort = els; + abort_io->send_abts = send_abts; + +/* now dispatch IO */ + rc =efct_scsi_io_dispatch_abort (abort_io, efct_els_abort_cb); +if (rc) { +efc_log_err (efct, +"efct_scsi_io_dispatch failed: %d\n" , rc); +efct_io_pool_io_free (efct->xport->io_pool, abort_io); + abort_io =NULL ; + } + } + +/* if something failed, put reference on ELS to abort */ +if (!abort_io) +kref_put (&els->ref, els->release); +return abort_io; +} + +void +efct_els_abort (struct efct_io *els,struct efc_node_cb *arg) +{ +struct efct_io *io =NULL ; +struct efc_node *node; +struct efct *efct; + + node = els->node; + efct = node->efc->base; + +/* request to abort this ELS without an ABTS */ +els_io_printf (els,"ELS abort requested\n" ); +/* Set retries to zero,we are done */ + els->els_retries_remaining =0 ; +if (els->state ==EFCT_ELS_REQUEST ) { + els->state =EFCT_ELS_REQ_ABORT ; + io =efct_els_abort_io (els, false); +if (!io) { +efc_log_err (efct,"efct_els_abort_io failed\n" ); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + arg); + } + + }else if (els->state ==EFCT_ELS_REQUEST_DELAYED ) { +/* mod/resched the timer for a short duration */ +mod_timer (&els->delay_timer, + jiffies +msecs_to_jiffies (1 )); + + els->state =EFCT_ELS_REQUEST_DELAY_ABORT ; + } +} + +void +efct_els_io_cleanup (struct efct_io *els, +enum efc_hw_node_els_event node_evt,void *arg) +{ +/* don't want further events that could come; e.g. abort requests +* from the node state machine; thus, disable state machine +*/ + els->els_req_free = true; +efc_node_post_els_resp (els->node, node_evt, arg); + +/* If this IO has a callback, invoke it */ +if (els->els_callback) { + (*els->els_callback)(els->node, arg, + els->els_callback_arg); + } +efct_els_io_free (els); +} + +int +efct_els_io_list_empty (struct efc_node *node,struct list_head *list) +{ +int empty; +unsigned long flags =0 ; + +spin_lock_irqsave (&node->active_ios_lock, flags); + empty =list_empty (list); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return empty; +} + +static int +efct_ct_acc_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status, +void *arg) +{ +struct efct_io *io = arg; + +efct_els_io_free (io); + +return EFC_SUCCESS ; +} + +int +efct_send_ct_rsp (struct efc *efc,struct efc_node *node,u16 ox_id, +struct fc_ct_hdr *ct_hdr,u32 cmd_rsp_code, +u32 reason_code,u32 reason_code_explanation) +{ +struct efct_io *io =NULL ; +struct fc_ct_hdr *rsp =NULL ; + + io =efct_els_io_alloc (node,256 ,EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efc,"IO alloc failed\n" ); +return EFC_FAIL ; + } + + rsp = io->els_rsp.virt; + io->io_type =EFCT_IO_TYPE_CT_RESP ; + + *rsp = *ct_hdr; + +fcct_build_req_header (rsp, cmd_rsp_code,0 ); + rsp->ct_reason = reason_code; + rsp->ct_explan = reason_code_explanation; + + io->display_name ="ct_rsp" ; + io->init_task_tag = ox_id; + io->wire_len +=sizeof (*rsp); + +memset (&io->iparam,0 ,sizeof (io->iparam)); + + io->io_type =EFCT_IO_TYPE_CT_RESP ; + io->hio_type =EFCT_HW_FC_CT_RSP ; + io->iparam.fc_ct.ox_id = ox_id; + io->iparam.fc_ct.r_ctl =3 ; + io->iparam.fc_ct.type =FC_TYPE_CT ; + io->iparam.fc_ct.df_ctl =0 ; + io->iparam.fc_ct.timeout =5 ; + +if (efct_scsi_io_dispatch (io, efct_ct_acc_cb) <0 ) { +efct_els_io_free (io); +return EFC_FAIL ; + } +return EFC_SUCCESS ; +}
drivers/scsi/elx/efct/efct_els.h new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 22/31] elx: efct: Extended link Service IO handling
Quoted 48 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Functions to build and send ELS/CT/BLS commands and responses.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Unified log message usingcmd_name
Return and drop else, for better indentation and consistency. Changed assertion log messages.--- drivers/scsi/elx/efct/efct_els.c | 1928 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_els.h | 133 +++ 2 files changed, 2061 insertions(+)create mode 100644
drivers/scsi/elx/efct/efct_els.ccreate mode 100644drivers/scsi/elx/efct/efct_els.hdrivers/scsi/elx/efct/efct_els.c new file +22
-0@@ -0,0 +1,1928 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* Functions to build and send ELS/CT/BLS commands and responses. +*/ + +#include "efct_driver.h" +#include "efct_els.h" + +#define ELS_IOFMT "[i:%04x t:%04x h:%04x]" + +#define EFCT_LOG_ENABLE_ELS_TRACE (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 1)) != 0) : 0) + +#define node_els_trace () \ + do { \ + if (EFCT_LOG_ENABLE_ELS_TRACE(efct)) \ + efc_log_info(efct, "[%s] %-20s\n", \
drivers/scsi/elx/efct/efct_els.c line 32
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+ node->display_name, __func__); \ + } while (0) + +#define els_io_printf (els, fmt, ...) \ + efc_log_debug((struct efct *)els->node->efc->base,\ + "[%s]" ELS_IOFMT " %-8s " fmt, \ + els->node->display_name,\ + els->init_task_tag, els->tgt_task_tag, els->hw_tag,\ + els->display_name, ##__VA_ARGS__) +
Why not simply use dyndebug here?
Quoted 25 lines
drivers/scsi/elx/efct/efct_els.c new file +25
-0+#define EFCT_ELS_RSP_LEN 1024 +#define EFCT_ELS_GID_PT_RSP_LEN 8096 + +static char *cmd_name[] =FC_ELS_CMDS_INIT ; + +void * +efct_els_req_send (struct efc *efc,struct efc_node *node,u32 cmd, +u32 timeout_sec,u32 retries) +{ +struct efct *efct = efc->base; + +efc_log_debug (efct,"send %s\n" , cmd_name[cmd]); + +switch (cmd) { +case ELS_PLOGI : +return efct_send_plogi (node, timeout_sec, retries,NULL ,NULL ); +case ELS_FLOGI : +return efct_send_flogi (node, timeout_sec, retries,NULL ,NULL ); +case ELS_FDISC : +return efct_send_fdisc (node, timeout_sec, retries,NULL ,NULL ); +case ELS_LOGO : +return efct_send_logo (node, timeout_sec, retries,NULL ,NULL ); +case ELS_PRLI : +return efct_send_prli (node, timeout_sec, retries,NULL ,NULL ); +case ELS_ADISC :
drivers/scsi/elx/efct/efct_els.c line 67
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+return efct_send_adisc (node, timeout_sec, retries,NULL ,NULL ); +case ELS_SCR : +return efct_send_scr (node, timeout_sec, retries,NULL ,NULL ); +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} +
You and your 'void *' functions always returning NULL ... Please make them normal void functions.
Quoted 32 lines
drivers/scsi/elx/efct/efct_els.c new file +32
-0+void * +efct_els_resp_send (struct efc *efc,struct efc_node *node, +u32 cmd,u16 ox_id) +{ +struct efct *efct = efc->base; + +switch (cmd) { +case ELS_PLOGI : +efct_send_plogi_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_FLOGI : +efct_send_flogi_acc (node, ox_id,0 ,NULL ,NULL ); +break ; +case ELS_LOGO : +efct_send_logo_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PRLI : +efct_send_prli_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PRLO : +efct_send_prlo_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_ADISC : +efct_send_adisc_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_LS_ACC : +efct_send_ls_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PDISC : +case ELS_FDISC : +case ELS_RSCN : +case ELS_SCR :
drivers/scsi/elx/efct/efct_els.c line 109
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+efct_send_ls_rjt (efc, node, ox_id,ELS_RJT_UNAB , +ELS_EXPL_NONE ,0 ); +break ; +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} +
Same here.
Quoted 911 lines
drivers/scsi/elx/efct/efct_els.c new file +911
-0+struct efct_io * +efct_els_io_alloc (struct efc_node *node,u32 reqlen, +enum efct_els_role role) +{ +return efct_els_io_alloc_size (node, reqlen,EFCT_ELS_RSP_LEN , role); +} + +struct efct_io * +efct_els_io_alloc_size (struct efc_node *node,u32 reqlen, +u32 rsplen,enum efct_els_role role) +{ +struct efct *efct; +struct efct_xport *xport; +struct efct_io *els; +unsigned long flags =0 ; + + efct = node->efc->base; + + xport = efct->xport; + +spin_lock_irqsave (&node->active_ios_lock, flags); + +if (!node->io_alloc_enabled) { +efc_log_debug (efct, +"called with io_alloc_enabled = FALSE\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + + els =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!els) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* initialize refcount */ +kref_init (&els->ref); + els->release = _efct_els_io_free; + +switch (role) { +case EFCT_ELS_ROLE_ORIGINATOR : + els->cmd_ini = true; + els->cmd_tgt = false; +break ; +case EFCT_ELS_ROLE_RESPONDER : + els->cmd_ini = false; + els->cmd_tgt = true; +break ; + } + +/* IO should not have an associated HW IO yet. +* Assigned below. +*/ +if (els->hio) { +efc_log_err (efct,"Error: HW io not null hio:%p\n" , els->hio); +efct_io_pool_io_free (efct->xport->io_pool, els); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* populate generic io fields */ + els->efct = efct; + els->node = node; + +/* set type and ELS-specific fields */ + els->io_type =EFCT_IO_TYPE_ELS ; + els->display_name ="pending" ; + +/* now allocate DMA for request and response */ + els->els_req.size = reqlen; + els->els_req.virt =dma_alloc_coherent (&efct->pcidev->dev, + els->els_req.size, + &els->els_req.phys, +GFP_DMA ); +if (els->els_req.virt) { + els->els_rsp.size = rsplen; + els->els_rsp.virt =dma_alloc_coherent (&efct->pcidev->dev, + els->els_rsp.size, + &els->els_rsp.phys, +GFP_DMA ); +if (!els->els_rsp.virt) { +efc_log_err (efct,"dma_alloc rsp\n" ); +dma_free_coherent (&efct->pcidev->dev, + els->els_req.size, + els->els_req.virt, els->els_req.phys); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + els =NULL ; + } + }else { +efc_log_err (efct,"dma_alloc req\n" ); +efct_io_pool_io_free (efct->xport->io_pool, els); + els =NULL ; + } + +if (els) { +/* initialize fields */ + els->els_retries_remaining = +EFCT_FC_ELS_DEFAULT_RETRIES ; + els->els_pend = false; + els->els_active = false; + +/* add els structure to ELS IO list */ +INIT_LIST_HEAD (&els->list_entry); +list_add_tail (&els->list_entry, + &node->els_io_pend_list); + els->els_pend = true; + } + +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return els; +} + +void +efct_els_io_free (struct efct_io *els) +{ +kref_put (&els->ref, els->release); +} + +void +_efct_els_io_free (struct kref *arg) +{ + struct efct_io *els = container_of(arg, struct efct_io, ref); +struct efct *efct; +struct efc_node *node; +int send_empty_event = false; +unsigned long flags =0 ; + + node = els->node; + efct = node->efc->base; + +spin_lock_irqsave (&node->active_ios_lock, flags); +if (els->els_active) { +/* if active, remove from active list and check empty */ +list_del (&els->list_entry); +/* Send list empty event if the IO allocator +* is disabled, and the list is empty +* If node->io_alloc_enabled was not checked, +* the event would be posted continually +*/ + send_empty_event = (!node->io_alloc_enabled) && +list_empty (&node->els_io_active_list); + els->els_active = false; + }else if (els->els_pend) { +/* if pending, remove from pending list; +* node shutdown isn't gated off the +* pending list (only the active list), +* so no need to check if pending list is empty +*/ +list_del (&els->list_entry); + els->els_pend =0 ; + }else { +efc_log_err (efct, +"Error: els not in pending or active set\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return ; + } + +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +/* free ELS request and response buffers */ +dma_free_coherent (&efct->pcidev->dev, els->els_rsp.size, + els->els_rsp.virt, els->els_rsp.phys); +dma_free_coherent (&efct->pcidev->dev, els->els_req.size, + els->els_req.virt, els->els_req.phys); + +memset (&els->els_rsp,0 ,sizeof (struct efc_dma )); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + +if (send_empty_event) +efc_scsi_io_list_empty (node->efc, node); + +efct_scsi_check_pending (efct); +} + +static void +efct_els_make_active (struct efct_io *els) +{ +struct efc_node *node = els->node; +unsigned long flags =0 ; + +/* move ELS from pending list to active list */ +spin_lock_irqsave (&node->active_ios_lock, flags); +if (els->els_pend) { +if (els->els_active) { +efc_log_err (node->efc, +"Error: els in both pend and active\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, + flags); +return ; + } +/* remove from pending list */ +list_del (&els->list_entry); + els->els_pend = false; + +/* add els structure to ELS IO list */ +INIT_LIST_HEAD (&els->list_entry); +list_add_tail (&els->list_entry, + &node->els_io_active_list); + els->els_active = true; + }else { +/* must be retrying; make sure it's already active */ +if (!els->els_active) { +efc_log_err (node->efc, +"Error: els not in pending or active set\n" ); + } + } +spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +static int efct_els_send (struct efct_io *els,u32 reqlen, +u32 timeout_sec,efct_hw_srrs_cb_t cb) +{ +struct efc_node *node = els->node; + +/* update ELS request counter */ + node->els_req_cnt++; + +/* move ELS from pending list to active list */ +efct_els_make_active (els); + + els->wire_len = reqlen; +return efct_scsi_io_dispatch (els, cb); +} + +static void +efct_els_retry (struct efct_io *els); + +static void +efct_els_delay_timer_cb (struct timer_list *t) +{ +struct efct_io *els =from_timer (els, t, delay_timer); +struct efc_node *node = els->node; + +/* Retry delay timer expired, retry the ELS request, +* Free the HW IO so that a new oxid is used. +*/ +if (els->state ==EFCT_ELS_REQUEST_DELAY_ABORT ) { + node->els_req_cnt++; +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , +NULL ); + }else { +efct_els_retry (els); + } +} + +static void +efct_els_abort_cleanup (struct efct_io *els) +{ +/* handle event for ABORT_WQE +* whatever state ELS happened to be in, propagate aborted even +* up to node state machine in lieu of EFC_HW_SRRS_ELS_* event +*/ +struct efc_node_cb cbdata; + + cbdata.status =0 ; + cbdata.ext_status =0 ; + cbdata.els_rsp = els->els_rsp; +els_io_printf (els,"Request aborted\n" ); +efct_els_io_cleanup (els,EFC_HW_ELS_REQ_ABORTED , &cbdata); +} + +static int +efct_els_req_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *arg) +{ +struct efct_io *els; +struct efc_node *node; +struct efct *efct; +struct efc_node_cb cbdata; +u32 reason_code; + + els = arg; + node = els->node; + efct = node->efc->base; + +if (status !=0 ) +els_io_printf (els,"status x%x ext x%x\n" , status, ext_status); + +/* set the response len element of els->rsp */ + els->els_rsp.len = length; + + cbdata.status = status; + cbdata.ext_status = ext_status; + cbdata.header =NULL ; + cbdata.els_rsp = els->els_rsp; + +/* FW returns the number of bytes received on the link in +* the WCQE, not the amount placed in the buffer; use this info to +* check if there was an overrun. +*/ +if (length > els->els_rsp.size) { +efc_log_warn (efct, +"ELS response returned len=%d > buflen=%zu\n" , + length, els->els_rsp.size); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , &cbdata); +return EFC_SUCCESS ; + } + +/* Post event to ELS IO object */ +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_OK , &cbdata); +break ; + +case SLI4_FC_WCQE_STATUS_LS_RJT : + reason_code = (ext_status >>16 ) &0xff ; + +/* delay and retry if reason code is Logical Busy */ +switch (reason_code) { +case ELS_RJT_BUSY : + els->node->els_req_cnt--; +els_io_printf (els, +"LS_RJT Logical Busy response,delay and retry\n" ); +timer_setup (&els->delay_timer, + efct_els_delay_timer_cb,0 ); +mod_timer (&els->delay_timer, + jiffies +msecs_to_jiffies (5000 )); + els->state =EFCT_ELS_REQUEST_DELAYED ; +break ; +default : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_RJT , + &cbdata); +break ; + } +break ; + +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT : +efct_els_retry (els); +break ; + +case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED : +if (els->state ==EFCT_ELS_ABORT_IO_COMPL ) { +/* completion for ELS that was aborted */ +efct_els_abort_cleanup (els); + }else { +/* completion for ELS received first, +* transition to wait for abort cmpl +*/ + els->state =EFCT_ELS_REQ_ABORTED ; + } + +break ; +default : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); +break ; + } +break ; +default :/* Other error */ +efc_log_warn (efct, +"els req failed status x%x, ext_status, x%x\n" , + status, ext_status); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , &cbdata); +break ; + } + +return EFC_SUCCESS ; +} + +static void efct_els_send_req (struct efc_node *node,struct efct_io *els) +{ +int rc =0 ; +struct efct *efct; + + efct = node->efc->base; + rc =efct_els_send (els, els->els_req.size, + els->els_timeout_sec, efct_els_req_cb); + +if (rc) { +struct efc_node_cb cbdata; + + cbdata.status =INT_MAX ; + cbdata.ext_status =INT_MAX ; + cbdata.els_rsp = els->els_rsp; +efc_log_err (efct,"efct_els_send failed: %d\n" , rc); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); + } +} + +static void +efct_els_retry (struct efct_io *els) +{ +struct efct *efct; +struct efc_node_cb cbdata; + + efct = els->node->efc->base; + cbdata.status =INT_MAX ; + cbdata.ext_status =INT_MAX ; + cbdata.els_rsp = els->els_rsp; + +if (!els->els_retries_remaining) { +efc_log_err (efct,"ELS retries exhausted\n" ); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); +return ; + } + + els->els_retries_remaining--; +/* Free the HW IO so that a new oxid is used.*/ +if (els->hio) { +efct_hw_io_free (&efct->hw, els->hio); + els->hio =NULL ; + } + +efct_els_send_req (els->node, els); +} + +static int +efct_els_acc_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *arg) +{ +struct efct_io *els; +struct efc_node *node; +struct efct *efct; +struct efc_node_cb cbdata; + + els = arg; + node = els->node; + efct = node->efc->base; + + cbdata.status = status; + cbdata.ext_status = ext_status; + cbdata.header =NULL ; + cbdata.els_rsp = els->els_rsp; + +/* Post node event */ +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_CMPL_OK , &cbdata); +break ; + +default :/* Other error */ +efc_log_warn (efct, +"[%s] %-8s failed status x%x, ext_status x%x\n" , + node->display_name, els->display_name, + status, ext_status); +efc_log_warn (efct, +"els acc complete: failed status x%x, ext_status, x%x\n" , + status, ext_status); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_CMPL_FAIL , &cbdata); +break ; + } + +return EFC_SUCCESS ; +} + +static int +efct_els_send_rsp (struct efct_io *els,u32 rsplen) +{ +struct efc_node *node = els->node; + +/* increment ELS completion counter */ + node->els_cmpl_cnt++; + +/* move ELS from pending list to active list */ +efct_els_make_active (els); + + els->wire_len = rsplen; +return efct_scsi_io_dispatch (els, efct_els_acc_cb); +} + +struct efct_io * +efct_send_plogi (struct efc_node *node,u32 timeout_sec, +u32 retries, +void (*cb)(struct efc_node *node, +struct efc_node_cb *cbdata,void *arg),void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_flogi *plogi; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*plogi),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="plogi" ; + +/* Build PLOGI request */ + plogi = els->els_req.virt; + +memcpy (plogi, node->sport->service_params,sizeof (*plogi)); + + plogi->fl_cmd =ELS_PLOGI ; +memset (plogi->_fl_resvd,0 ,sizeof (plogi->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_flogi (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_flogi *flogi; + + efct = node->efc->base; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="flogi" ; + +/* Build FLOGI request */ + flogi = els->els_req.virt; + +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + flogi->fl_cmd =ELS_FLOGI ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_fdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_flogi *fdisc; + + efct = node->efc->base; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*fdisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="fdisc" ; + +/* Build FDISC request */ + fdisc = els->els_req.virt; + +memcpy (fdisc, node->sport->service_params,sizeof (*fdisc)); + fdisc->fl_cmd =ELS_FDISC ; +memset (fdisc->_fl_resvd,0 ,sizeof (fdisc->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_prli (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct *efct = node->efc->base; +struct efct_io *els; +struct { +struct fc_els_prli prli; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="prli" ; + +/* Build PRLI request */ + pp = els->els_req.virt; + +memset (pp,0 ,sizeof (*pp)); + + pp->prli.prli_cmd =ELS_PRLI ; + pp->prli.prli_spp_len =16 ; + pp->prli.prli_len =cpu_to_be16 (sizeof (*pp)); + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_EST_IMG_PAIR ; + pp->spp.spp_params =cpu_to_be32 (FCP_SPPF_RD_XRDY_DIS | + (node->sport->enable_ini ? +FCP_SPPF_INIT_FCN :0 ) | + (node->sport->enable_tgt ? +FCP_SPPF_TARG_FCN :0 )); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_prlo (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct *efct = node->efc->base; +struct efct_io *els; +struct { +struct fc_els_prlo prlo; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="prlo" ; + +/* Build PRLO request */ + pp = els->els_req.virt; + +memset (pp,0 ,sizeof (*pp)); + pp->prlo.prlo_cmd =ELS_PRLO ; + pp->prlo.prlo_obs =0x10 ; + pp->prlo.prlo_len =cpu_to_be16 (sizeof (*pp)); + + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_logo (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_logo *logo; +struct fc_els_flogi *sparams; + + efct = node->efc->base; + +node_els_trace (); + + sparams = (struct fc_els_flogi *)node->sport->service_params; + + els =efct_els_io_alloc (node,sizeof (*logo),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="logo" ; + +/* Build LOGO request */ + + logo = els->els_req.virt; + +memset (logo,0 ,sizeof (*logo)); + logo->fl_cmd =ELS_LOGO ; +hton24 (logo->fl_n_port_id, node->rnode.sport->fc_id); + logo->fl_n_port_wwn = sparams->fl_wwpn; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_adisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_adisc *adisc; +struct fc_els_flogi *sparams; +struct efc_sli_port *sport = node->sport; + + efct = node->efc->base; + +node_els_trace (); + + sparams = (struct fc_els_flogi *)node->sport->service_params; + + els =efct_els_io_alloc (node,sizeof (*adisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="adisc" ; + +/* Build ADISC request */ + + adisc = els->els_req.virt; + +memset (adisc,0 ,sizeof (*adisc)); + adisc->adisc_cmd =ELS_ADISC ; +hton24 (adisc->adisc_hard_addr, sport->fc_id); + adisc->adisc_wwpn = sparams->fl_wwpn; + adisc->adisc_wwnn = sparams->fl_wwnn; +hton24 (adisc->adisc_port_id, node->rnode.sport->fc_id); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_pdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_flogi *pdisc; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pdisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="pdisc" ; + + pdisc = els->els_req.virt; + +memcpy (pdisc, node->sport->service_params,sizeof (*pdisc)); + + pdisc->fl_cmd =ELS_PDISC ; +memset (pdisc->_fl_resvd,0 ,sizeof (pdisc->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_scr (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_scr *req; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*req),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="scr" ; + + req = els->els_req.virt; + +memset (req,0 ,sizeof (*req)); + req->scr_cmd =ELS_SCR ; + req->scr_reg_func =ELS_SCRF_FULL ; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_rscn (struct efc_node *node,u32 timeout_sec,u32 retries, +void *port_ids,u32 port_ids_count,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_rscn *req; +struct fc_els_rscn_page *rscn_page; +u32 length =sizeof (*rscn_page) * port_ids_count; + + length +=sizeof (*req); + +node_els_trace (); + + els =efct_els_io_alloc (node, length,EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rscn" ; + + req = els->els_req.virt; + + req->rscn_cmd =ELS_RSCN ; + req->rscn_page_len =sizeof (struct fc_els_rscn_page ); + req->rscn_plen =cpu_to_be16 (length); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +/* copy in the payload */ + rscn_page = els->els_req.virt +sizeof (*req); +memcpy (rscn_page, port_ids, + port_ids_count *sizeof (*rscn_page)); + +efct_els_send_req (node, els); + > + return els; +} + +void * +efct_send_ls_rjt (struct efc *efc,struct efc_node *node, +u32 ox_id,u32 reason_code, +u32 reason_code_expl,u32 vendor_unique) +{ +struct efct_io *io =NULL ; +int rc; +struct efct *efct = node->efc->base; +struct fc_els_ls_rjt *rjt; + + io =efct_els_io_alloc (node,sizeof (*rjt),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + +node_els_trace (); + + io->els_callback =NULL ; + io->els_callback_arg =NULL ; + io->display_name ="ls_rjt" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + rjt = io->els_req.virt; +memset (rjt,0 ,sizeof (*rjt)); + + rjt->er_cmd =ELS_LS_RJT ; + rjt->er_reason = reason_code; + rjt->er_explan = reason_code_expl; +
drivers/scsi/elx/efct/efct_els.c line 1031
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+ io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*rjt)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} +
That is a bit strange.
Sending a response can fail, but (apparently) sending a request cannot; at the very least you don't have (or check) the return value from the send request.
Some intricate scheme I've missed?
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke Teamlead Storage & Networking [email protected] +49 911 74053 688 SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer
Re: [PATCH v3 22/31] elx: efct: Extended link Service IO handling
On 4/16/2020 12:58 AM, Hannes Reinecke wrote:
...
Quoted 5 lines
That is a bit strange.
Sending a response can fail, but (apparently) sending a request cannot; at the very least you don't have (or check) the return value from the send request.Some intricate scheme I've missed?
The send_request fully handles the failure case, which ends up calling the request completion callback with an error status, before send_request returns to the callee. Not handled that way with the response. The response routine handles the error.
Agree with your other comments and will address them. Same thing for comments on patches 19 and 20.
-- james
Re: [PATCH v3 22/31] elx: efct: Extended link Service IO handling
In reply to James SmartQuoted 200 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Functions to build and send ELS/CT/BLS commands and responses.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>---
v3:
Unified log message usingcmd_name
Return and drop else, for better indentation and consistency. Changed assertion log messages.--- drivers/scsi/elx/efct/efct_els.c | 1928 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_els.h | 133 +++ 2 files changed, 2061 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_els.c create mode 100644 drivers/scsi/elx/efct/efct_els.hdrivers/scsi/elx/efct/efct_els.c new file +174
-0@@ -0,0 +1,1928 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +/* +* Functions to build and send ELS/CT/BLS commands and responses. +*/ + +#include "efct_driver.h" +#include "efct_els.h" + +#define ELS_IOFMT "[i:%04x t:%04x h:%04x]" + +#define EFCT_LOG_ENABLE_ELS_TRACE (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 1)) != 0) : 0) + +#define node_els_trace () \ + do { \ + if (EFCT_LOG_ENABLE_ELS_TRACE(efct)) \ + efc_log_info(efct, "[%s] %-20s\n", \ + node->display_name, __func__); \ + } while (0) + +#define els_io_printf (els, fmt, ...) \ + efc_log_debug((struct efct *)els->node->efc->base,\ + "[%s]" ELS_IOFMT " %-8s " fmt, \ + els->node->display_name,\ + els->init_task_tag, els->tgt_task_tag, els->hw_tag,\ + els->display_name, ##__VA_ARGS__) + +#define EFCT_ELS_RSP_LEN 1024 +#define EFCT_ELS_GID_PT_RSP_LEN 8096 + +static char *cmd_name[] =FC_ELS_CMDS_INIT ; + +void * +efct_els_req_send (struct efc *efc,struct efc_node *node,u32 cmd, +u32 timeout_sec,u32 retries) +{ +struct efct *efct = efc->base; + +efc_log_debug (efct,"send %s\n" , cmd_name[cmd]); + +switch (cmd) { +case ELS_PLOGI : +return efct_send_plogi (node, timeout_sec, retries,NULL ,NULL ); +case ELS_FLOGI : +return efct_send_flogi (node, timeout_sec, retries,NULL ,NULL ); +case ELS_FDISC : +return efct_send_fdisc (node, timeout_sec, retries,NULL ,NULL ); +case ELS_LOGO : +return efct_send_logo (node, timeout_sec, retries,NULL ,NULL ); +case ELS_PRLI : +return efct_send_prli (node, timeout_sec, retries,NULL ,NULL ); +case ELS_ADISC : +return efct_send_adisc (node, timeout_sec, retries,NULL ,NULL ); +case ELS_SCR : +return efct_send_scr (node, timeout_sec, retries,NULL ,NULL ); +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} + +void * +efct_els_resp_send (struct efc *efc,struct efc_node *node, +u32 cmd,u16 ox_id) +{ +struct efct *efct = efc->base; + +switch (cmd) { +case ELS_PLOGI : +efct_send_plogi_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_FLOGI : +efct_send_flogi_acc (node, ox_id,0 ,NULL ,NULL ); +break ; +case ELS_LOGO : +efct_send_logo_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PRLI : +efct_send_prli_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PRLO : +efct_send_prlo_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_ADISC : +efct_send_adisc_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_LS_ACC : +efct_send_ls_acc (node, ox_id,NULL ,NULL ); +break ; +case ELS_PDISC : +case ELS_FDISC : +case ELS_RSCN : +case ELS_SCR : +efct_send_ls_rjt (efc, node, ox_id,ELS_RJT_UNAB , +ELS_EXPL_NONE ,0 ); +break ; +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} + +struct efct_io * +efct_els_io_alloc (struct efc_node *node,u32 reqlen, +enum efct_els_role role) +{ +return efct_els_io_alloc_size (node, reqlen,EFCT_ELS_RSP_LEN , role); +} + +struct efct_io * +efct_els_io_alloc_size (struct efc_node *node,u32 reqlen, +u32 rsplen,enum efct_els_role role) +{ +struct efct *efct; +struct efct_xport *xport; +struct efct_io *els; +unsigned long flags =0 ; + + efct = node->efc->base; + + xport = efct->xport; + +spin_lock_irqsave (&node->active_ios_lock, flags); + +if (!node->io_alloc_enabled) { +efc_log_debug (efct, +"called with io_alloc_enabled = FALSE\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + + els =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!els) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* initialize refcount */ +kref_init (&els->ref); + els->release = _efct_els_io_free; + +switch (role) { +case EFCT_ELS_ROLE_ORIGINATOR : + els->cmd_ini = true; + els->cmd_tgt = false; +break ; +case EFCT_ELS_ROLE_RESPONDER : + els->cmd_ini = false; + els->cmd_tgt = true; +break ; + } + +/* IO should not have an associated HW IO yet. +* Assigned below. +*/ +if (els->hio) { +efc_log_err (efct,"Error: HW io not null hio:%p\n" , els->hio); +efct_io_pool_io_free (efct->xport->io_pool, els); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* populate generic io fields */ + els->efct = efct; + els->node = node; +
drivers/scsi/elx/efct/efct_els.c line 184
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+/* set type and ELS-specific fields */ + els->io_type =EFCT_IO_TYPE_ELS ; + els->display_name ="pending" ; + +/* now allocate DMA for request and response */ + els->els_req.size = reqlen; + els->els_req.virt =dma_alloc_coherent (&efct->pcidev->dev, + els->els_req.size, + &els->els_req.phys, +GFP_DMA );
GFP_KERNEL
drivers/scsi/elx/efct/efct_els.c line 190
Quoted 6 lines
drivers/scsi/elx/efct/efct_els.c new file +6
-0+if (els->els_req.virt) { + els->els_rsp.size = rsplen; + els->els_rsp.virt =dma_alloc_coherent (&efct->pcidev->dev, + els->els_rsp.size, + &els->els_rsp.phys, +GFP_DMA );
GFP_KERNEL
Quoted 65 lines
drivers/scsi/elx/efct/efct_els.c new file +65
-0+if (!els->els_rsp.virt) { +efc_log_err (efct,"dma_alloc rsp\n" ); +dma_free_coherent (&efct->pcidev->dev, + els->els_req.size, + els->els_req.virt, els->els_req.phys); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + els =NULL ; + } + }else { +efc_log_err (efct,"dma_alloc req\n" ); +efct_io_pool_io_free (efct->xport->io_pool, els); + els =NULL ; + } + +if (els) { +/* initialize fields */ + els->els_retries_remaining = +EFCT_FC_ELS_DEFAULT_RETRIES ; + els->els_pend = false; + els->els_active = false; + +/* add els structure to ELS IO list */ +INIT_LIST_HEAD (&els->list_entry); +list_add_tail (&els->list_entry, + &node->els_io_pend_list); + els->els_pend = true; + } + +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return els; +} + +void +efct_els_io_free (struct efct_io *els) +{ +kref_put (&els->ref, els->release); +} + +void +_efct_els_io_free (struct kref *arg) +{ + struct efct_io *els = container_of(arg, struct efct_io, ref); +struct efct *efct; +struct efc_node *node; +int send_empty_event = false; +unsigned long flags =0 ; + + node = els->node; + efct = node->efc->base; + +spin_lock_irqsave (&node->active_ios_lock, flags); +if (els->els_active) { +/* if active, remove from active list and check empty */ +list_del (&els->list_entry); +/* Send list empty event if the IO allocator +* is disabled, and the list is empty +* If node->io_alloc_enabled was not checked, +* the event would be posted continually +*/ + send_empty_event = (!node->io_alloc_enabled) && +list_empty (&node->els_io_active_list); + els->els_active = false; + }else if (els->els_pend) { +/* if pending, remove from pending list;
drivers/scsi/elx/efct/efct_els.c line 265
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+* node shutdown isn't gated off the +* pending list (only the active list), +* so no need to check if pending list is empty +*/ +list_del (&els->list_entry); + els->els_pend =0 ; + }else { +efc_log_err (efct, +"Error: els not in pending or active set\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags);
unlock first then log
drivers/scsi/elx/efct/efct_els.c line 267
Quoted 2 lines
drivers/scsi/elx/efct/efct_els.c new file +2
-0+return ; + }
no need to indent
Quoted 23 lines
drivers/scsi/elx/efct/efct_els.c new file +23
-0+ +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +/* free ELS request and response buffers */ +dma_free_coherent (&efct->pcidev->dev, els->els_rsp.size, + els->els_rsp.virt, els->els_rsp.phys); +dma_free_coherent (&efct->pcidev->dev, els->els_req.size, + els->els_req.virt, els->els_req.phys); + +memset (&els->els_rsp,0 ,sizeof (struct efc_dma )); +memset (&els->els_req,0 ,sizeof (struct efc_dma )); +efct_io_pool_io_free (efct->xport->io_pool, els); + +if (send_empty_event) +efc_scsi_io_list_empty (node->efc, node); + +efct_scsi_check_pending (efct); +} + +static void +efct_els_make_active (struct efct_io *els) +{ +struct efc_node *node = els->node;
drivers/scsi/elx/efct/efct_els.c line 300
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+unsigned long flags =0 ; + +/* move ELS from pending list to active list */ +spin_lock_irqsave (&node->active_ios_lock, flags); +if (els->els_pend) { +if (els->els_active) { +efc_log_err (node->efc, +"Error: els in both pend and active\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, + flags);
unlock then log
Quoted 4 lines
drivers/scsi/elx/efct/efct_els.c new file +4
-0+return ; + } +/* remove from pending list */ +list_del (&els->list_entry);
drivers/scsi/elx/efct/efct_els.c line 314
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+ els->els_pend = false; + +/* add els structure to ELS IO list */ +INIT_LIST_HEAD (&els->list_entry); +list_add_tail (&els->list_entry, + &node->els_io_active_list); + els->els_active = true; + }else { +/* must be retrying; make sure it's already active */ +if (!els->els_active) {
} else if (!els->els_active) {drivers/scsi/elx/efct/efct_els.c line 318
Quoted 4 lines
drivers/scsi/elx/efct/efct_els.c new file +4
-0+efc_log_err (node->efc, +"Error: els not in pending or active set\n" ); + } + }
no need to indent
Quoted 24 lines
drivers/scsi/elx/efct/efct_els.c new file +24
-0+spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +static int efct_els_send (struct efct_io *els,u32 reqlen, +u32 timeout_sec,efct_hw_srrs_cb_t cb) +{ +struct efc_node *node = els->node; + +/* update ELS request counter */ + node->els_req_cnt++; + +/* move ELS from pending list to active list */ +efct_els_make_active (els); + + els->wire_len = reqlen; +return efct_scsi_io_dispatch (els, cb); +} + +static void +efct_els_retry (struct efct_io *els); + +static void +efct_els_delay_timer_cb (struct timer_list *t) +{
drivers/scsi/elx/efct/efct_els.c line 352
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+struct efct_io *els =from_timer (els, t, delay_timer); +struct efc_node *node = els->node; + +/* Retry delay timer expired, retry the ELS request, +* Free the HW IO so that a new oxid is used. +*/ +if (els->state ==EFCT_ELS_REQUEST_DELAY_ABORT ) { + node->els_req_cnt++; +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , +NULL );
fits on one line
Quoted 121 lines
drivers/scsi/elx/efct/efct_els.c new file +121
-0+ }else { +efct_els_retry (els); + } +} + +static void +efct_els_abort_cleanup (struct efct_io *els) +{ +/* handle event for ABORT_WQE +* whatever state ELS happened to be in, propagate aborted even +* up to node state machine in lieu of EFC_HW_SRRS_ELS_* event +*/ +struct efc_node_cb cbdata; + + cbdata.status =0 ; + cbdata.ext_status =0 ; + cbdata.els_rsp = els->els_rsp; +els_io_printf (els,"Request aborted\n" ); +efct_els_io_cleanup (els,EFC_HW_ELS_REQ_ABORTED , &cbdata); +} + +static int +efct_els_req_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *arg) +{ +struct efct_io *els; +struct efc_node *node; +struct efct *efct; +struct efc_node_cb cbdata; +u32 reason_code; + + els = arg; + node = els->node; + efct = node->efc->base; + +if (status !=0 ) +els_io_printf (els,"status x%x ext x%x\n" , status, ext_status); + +/* set the response len element of els->rsp */ + els->els_rsp.len = length; + + cbdata.status = status; + cbdata.ext_status = ext_status; + cbdata.header =NULL ; + cbdata.els_rsp = els->els_rsp; + +/* FW returns the number of bytes received on the link in +* the WCQE, not the amount placed in the buffer; use this info to +* check if there was an overrun. +*/ +if (length > els->els_rsp.size) { +efc_log_warn (efct, +"ELS response returned len=%d > buflen=%zu\n" , + length, els->els_rsp.size); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , &cbdata); +return EFC_SUCCESS ; + } + +/* Post event to ELS IO object */ +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_OK , &cbdata); +break ; + +case SLI4_FC_WCQE_STATUS_LS_RJT : + reason_code = (ext_status >>16 ) &0xff ; + +/* delay and retry if reason code is Logical Busy */ +switch (reason_code) { +case ELS_RJT_BUSY : + els->node->els_req_cnt--; +els_io_printf (els, +"LS_RJT Logical Busy response,delay and retry\n" ); +timer_setup (&els->delay_timer, + efct_els_delay_timer_cb,0 ); +mod_timer (&els->delay_timer, + jiffies +msecs_to_jiffies (5000 )); + els->state =EFCT_ELS_REQUEST_DELAYED ; +break ; +default : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_RJT , + &cbdata); +break ; + } +break ; + +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT : +efct_els_retry (els); +break ; + +case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED : +if (els->state ==EFCT_ELS_ABORT_IO_COMPL ) { +/* completion for ELS that was aborted */ +efct_els_abort_cleanup (els); + }else { +/* completion for ELS received first, +* transition to wait for abort cmpl +*/ + els->state =EFCT_ELS_REQ_ABORTED ; + } + +break ; +default : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); +break ; + } +break ; +default :/* Other error */ +efc_log_warn (efct, +"els req failed status x%x, ext_status, x%x\n" , + status, ext_status); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , &cbdata); +break ; + } + +return EFC_SUCCESS ; +} +
drivers/scsi/elx/efct/efct_els.c line 483
Quoted 10 lines
drivers/scsi/elx/efct/efct_els.c new file +10
-0+static void efct_els_send_req (struct efc_node *node,struct efct_io *els) +{ +int rc =0 ; +struct efct *efct; + + efct = node->efc->base; + rc =efct_els_send (els, els->els_req.size, + els->els_timeout_sec, efct_els_req_cb); + +if (rc) {
if (!rc) return;
Quoted 1,587 lines
drivers/scsi/elx/efct/efct_els.c new file +1445
-0+struct efc_node_cb cbdata; + + cbdata.status =INT_MAX ; + cbdata.ext_status =INT_MAX ; + cbdata.els_rsp = els->els_rsp; +efc_log_err (efct,"efct_els_send failed: %d\n" , rc); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); + } +} + +static void +efct_els_retry (struct efct_io *els) +{ +struct efct *efct; +struct efc_node_cb cbdata; + + efct = els->node->efc->base; + cbdata.status =INT_MAX ; + cbdata.ext_status =INT_MAX ; + cbdata.els_rsp = els->els_rsp; + +if (!els->els_retries_remaining) { +efc_log_err (efct,"ELS retries exhausted\n" ); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + &cbdata); +return ; + } + + els->els_retries_remaining--; +/* Free the HW IO so that a new oxid is used.*/ +if (els->hio) { +efct_hw_io_free (&efct->hw, els->hio); + els->hio =NULL ; + } + +efct_els_send_req (els->node, els); +} + +static int +efct_els_acc_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *arg) +{ +struct efct_io *els; +struct efc_node *node; +struct efct *efct; +struct efc_node_cb cbdata; + + els = arg; + node = els->node; + efct = node->efc->base; + + cbdata.status = status; + cbdata.ext_status = ext_status; + cbdata.header =NULL ; + cbdata.els_rsp = els->els_rsp; + +/* Post node event */ +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_CMPL_OK , &cbdata); +break ; + +default :/* Other error */ +efc_log_warn (efct, +"[%s] %-8s failed status x%x, ext_status x%x\n" , + node->display_name, els->display_name, + status, ext_status); +efc_log_warn (efct, +"els acc complete: failed status x%x, ext_status, x%x\n" , + status, ext_status); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_CMPL_FAIL , &cbdata); +break ; + } + +return EFC_SUCCESS ; +} + +static int +efct_els_send_rsp (struct efct_io *els,u32 rsplen) +{ +struct efc_node *node = els->node; + +/* increment ELS completion counter */ + node->els_cmpl_cnt++; + +/* move ELS from pending list to active list */ +efct_els_make_active (els); + + els->wire_len = rsplen; +return efct_scsi_io_dispatch (els, efct_els_acc_cb); +} + +struct efct_io * +efct_send_plogi (struct efc_node *node,u32 timeout_sec, +u32 retries, +void (*cb)(struct efc_node *node, +struct efc_node_cb *cbdata,void *arg),void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_flogi *plogi; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*plogi),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="plogi" ; + +/* Build PLOGI request */ + plogi = els->els_req.virt; + +memcpy (plogi, node->sport->service_params,sizeof (*plogi)); + + plogi->fl_cmd =ELS_PLOGI ; +memset (plogi->_fl_resvd,0 ,sizeof (plogi->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_flogi (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_flogi *flogi; + + efct = node->efc->base; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="flogi" ; + +/* Build FLOGI request */ + flogi = els->els_req.virt; + +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + flogi->fl_cmd =ELS_FLOGI ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_fdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_flogi *fdisc; + + efct = node->efc->base; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*fdisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="fdisc" ; + +/* Build FDISC request */ + fdisc = els->els_req.virt; + +memcpy (fdisc, node->sport->service_params,sizeof (*fdisc)); + fdisc->fl_cmd =ELS_FDISC ; +memset (fdisc->_fl_resvd,0 ,sizeof (fdisc->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_prli (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct *efct = node->efc->base; +struct efct_io *els; +struct { +struct fc_els_prli prli; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="prli" ; + +/* Build PRLI request */ + pp = els->els_req.virt; + +memset (pp,0 ,sizeof (*pp)); + + pp->prli.prli_cmd =ELS_PRLI ; + pp->prli.prli_spp_len =16 ; + pp->prli.prli_len =cpu_to_be16 (sizeof (*pp)); + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_EST_IMG_PAIR ; + pp->spp.spp_params =cpu_to_be32 (FCP_SPPF_RD_XRDY_DIS | + (node->sport->enable_ini ? +FCP_SPPF_INIT_FCN :0 ) | + (node->sport->enable_tgt ? +FCP_SPPF_TARG_FCN :0 )); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_prlo (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct *efct = node->efc->base; +struct efct_io *els; +struct { +struct fc_els_prlo prlo; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="prlo" ; + +/* Build PRLO request */ + pp = els->els_req.virt; + +memset (pp,0 ,sizeof (*pp)); + pp->prlo.prlo_cmd =ELS_PRLO ; + pp->prlo.prlo_obs =0x10 ; + pp->prlo.prlo_len =cpu_to_be16 (sizeof (*pp)); + + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_logo (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_logo *logo; +struct fc_els_flogi *sparams; + + efct = node->efc->base; + +node_els_trace (); + + sparams = (struct fc_els_flogi *)node->sport->service_params; + + els =efct_els_io_alloc (node,sizeof (*logo),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="logo" ; + +/* Build LOGO request */ + + logo = els->els_req.virt; + +memset (logo,0 ,sizeof (*logo)); + logo->fl_cmd =ELS_LOGO ; +hton24 (logo->fl_n_port_id, node->rnode.sport->fc_id); + logo->fl_n_port_wwn = sparams->fl_wwpn; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_adisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct; +struct fc_els_adisc *adisc; +struct fc_els_flogi *sparams; +struct efc_sli_port *sport = node->sport; + + efct = node->efc->base; + +node_els_trace (); + + sparams = (struct fc_els_flogi *)node->sport->service_params; + + els =efct_els_io_alloc (node,sizeof (*adisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="adisc" ; + +/* Build ADISC request */ + + adisc = els->els_req.virt; + +memset (adisc,0 ,sizeof (*adisc)); + adisc->adisc_cmd =ELS_ADISC ; +hton24 (adisc->adisc_hard_addr, sport->fc_id); + adisc->adisc_wwpn = sparams->fl_wwpn; + adisc->adisc_wwnn = sparams->fl_wwnn; +hton24 (adisc->adisc_port_id, node->rnode.sport->fc_id); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_pdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_flogi *pdisc; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*pdisc),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="pdisc" ; + + pdisc = els->els_req.virt; + +memcpy (pdisc, node->sport->service_params,sizeof (*pdisc)); + + pdisc->fl_cmd =ELS_PDISC ; +memset (pdisc->_fl_resvd,0 ,sizeof (pdisc->_fl_resvd)); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_scr (struct efc_node *node,u32 timeout_sec,u32 retries, +els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_scr *req; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*req),EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="scr" ; + + req = els->els_req.virt; + +memset (req,0 ,sizeof (*req)); + req->scr_cmd =ELS_SCR ; + req->scr_reg_func =ELS_SCRF_FULL ; + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_send_rscn (struct efc_node *node,u32 timeout_sec,u32 retries, +void *port_ids,u32 port_ids_count,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_els_rscn *req; +struct fc_els_rscn_page *rscn_page; +u32 length =sizeof (*rscn_page) * port_ids_count; + + length +=sizeof (*req); + +node_els_trace (); + + els =efct_els_io_alloc (node, length,EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->els_timeout_sec = timeout_sec; + els->els_retries_remaining = retries; + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rscn" ; + + req = els->els_req.virt; + + req->rscn_cmd =ELS_RSCN ; + req->rscn_page_len =sizeof (struct fc_els_rscn_page ); + req->rscn_plen =cpu_to_be16 (length); + + els->hio_type =EFCT_HW_ELS_REQ ; + els->iparam.els.timeout = timeout_sec; + +/* copy in the payload */ + rscn_page = els->els_req.virt +sizeof (*req); +memcpy (rscn_page, port_ids, + port_ids_count *sizeof (*rscn_page)); + +efct_els_send_req (node, els); + +return els; +} + +void * +efct_send_ls_rjt (struct efc *efc,struct efc_node *node, +u32 ox_id,u32 reason_code, +u32 reason_code_expl,u32 vendor_unique) +{ +struct efct_io *io =NULL ; +int rc; +struct efct *efct = node->efc->base; +struct fc_els_ls_rjt *rjt; + + io =efct_els_io_alloc (node,sizeof (*rjt),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + +node_els_trace (); + + io->els_callback =NULL ; + io->els_callback_arg =NULL ; + io->display_name ="ls_rjt" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + rjt = io->els_req.virt; +memset (rjt,0 ,sizeof (*rjt)); + + rjt->er_cmd =ELS_LS_RJT ; + rjt->er_reason = reason_code; + rjt->er_explan = reason_code_expl; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*rjt)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_plogi_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct fc_els_flogi *plogi; +struct fc_els_flogi *req = (struct fc_els_flogi *)node->service_params; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*plogi),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="plogi_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + plogi = io->els_req.virt; + +/* copy our port's service parameters to payload */ +memcpy (plogi, node->sport->service_params,sizeof (*plogi)); + plogi->fl_cmd =ELS_LS_ACC ; +memset (plogi->_fl_resvd,0 ,sizeof (plogi->_fl_resvd)); + +/* Set Application header support bit if requested */ +if (req->fl_csp.sp_features &cpu_to_be16 (FC_SP_FT_BCAST )) + plogi->fl_csp.sp_features |=cpu_to_be16 (FC_SP_FT_BCAST ); + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*plogi)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } +return io; +} + +void * +efct_send_flogi_p2p_acc (struct efc *efc,struct efc_node *node, +u32 ox_id,u32 s_id) +{ +struct efct_io *io =NULL ; +int rc; +struct efct *efct = node->efc->base; +struct fc_els_flogi *flogi; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback =NULL ; + io->els_callback_arg =NULL ; + io->display_name ="flogi_p2p_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + io->iparam.els.s_id = s_id; + + flogi = io->els_req.virt; + +/* copy our port's service parameters to payload */ +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + flogi->fl_cmd =ELS_LS_ACC ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + +memset (flogi->fl_cssp,0 ,sizeof (flogi->fl_cssp)); + + io->hio_type =EFCT_HW_ELS_RSP_SID ; + rc =efct_els_send_rsp (io,sizeof (*flogi)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_flogi_acc (struct efc_node *node,u32 ox_id,u32 is_fport, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct fc_els_flogi *flogi; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*flogi),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="flogi_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + io->iparam.els.s_id = io->node->sport->fc_id; + + flogi = io->els_req.virt; + +/* copy our port's service parameters to payload */ +memcpy (flogi, node->sport->service_params,sizeof (*flogi)); + +/* Set F_port */ +if (is_fport) { +/* Set F_PORT and Multiple N_PORT_ID Assignment */ + flogi->fl_csp.sp_r_a_tov |=cpu_to_be32 (3U <<28 ); + } + + flogi->fl_cmd =ELS_LS_ACC ; +memset (flogi->_fl_resvd,0 ,sizeof (flogi->_fl_resvd)); + +memset (flogi->fl_cssp,0 ,sizeof (flogi->fl_cssp)); + + io->hio_type =EFCT_HW_ELS_RSP_SID ; + rc =efct_els_send_rsp (io,sizeof (*flogi)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io *efct_send_prli_acc (struct efc_node *node, +u32 ox_id,els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct { +struct fc_els_prli prli; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="prli_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + pp = io->els_req.virt; +memset (pp,0 ,sizeof (*pp)); + + pp->prli.prli_cmd =ELS_LS_ACC ; + pp->prli.prli_spp_len =0x10 ; + pp->prli.prli_len =cpu_to_be16 (sizeof (*pp)); + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_EST_IMG_PAIR |FC_SPP_RESP_ACK ; + + pp->spp.spp_params =cpu_to_be32 (FCP_SPPF_RD_XRDY_DIS | + (node->sport->enable_ini ? +FCP_SPPF_INIT_FCN :0 ) | + (node->sport->enable_tgt ? +FCP_SPPF_TARG_FCN :0 )); + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*pp)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_prlo_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct { +struct fc_els_prlo prlo; +struct fc_els_spp spp; + } *pp; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*pp),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="prlo_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + pp = io->els_req.virt; +memset (pp,0 ,sizeof (*pp)); + pp->prlo.prlo_cmd =ELS_LS_ACC ; + pp->prlo.prlo_obs =0x10 ; + pp->prlo.prlo_len =cpu_to_be16 (sizeof (*pp)); + + pp->spp.spp_type =FC_TYPE_FCP ; + pp->spp.spp_type_ext =0 ; + pp->spp.spp_flags =FC_SPP_RESP_ACK ; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*pp)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_ls_acc (struct efc_node *node,u32 ox_id,els_cb_t cb, +void *cbarg) +{ +int rc; +struct efct *efct = node->efc->base; +struct efct_io *io =NULL ; +struct fc_els_ls_acc *acc; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*acc),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="ls_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + acc = io->els_req.virt; +memset (acc,0 ,sizeof (*acc)); + + acc->la_cmd =ELS_LS_ACC ; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*acc)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_logo_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct_io *io =NULL ; +struct efct *efct = node->efc->base; +struct fc_els_ls_acc *logo; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*logo),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="logo_acc" ; + io->init_task_tag = ox_id; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + logo = io->els_req.virt; +memset (logo,0 ,sizeof (*logo)); + + logo->la_cmd =ELS_LS_ACC ; + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*logo)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +struct efct_io * +efct_send_adisc_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg) +{ +int rc; +struct efct_io *io =NULL ; +struct fc_els_adisc *adisc; +struct fc_els_flogi *sparams; +struct efct *efct; + + efct = node->efc->base; + +node_els_trace (); + + io =efct_els_io_alloc (node,sizeof (*adisc),EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efct,"els IO alloc failed\n" ); +return io; + } + + io->els_callback = cb; + io->els_callback_arg = cbarg; + io->display_name ="adisc_acc" ; + io->init_task_tag = ox_id; + +/* Go ahead and send the ELS_ACC */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.els.ox_id = ox_id; + + sparams = (struct fc_els_flogi *)node->sport->service_params; + adisc = io->els_req.virt; +memset (adisc,0 ,sizeof (*adisc)); + adisc->adisc_cmd =ELS_LS_ACC ; + adisc->adisc_wwpn = sparams->fl_wwpn; + adisc->adisc_wwnn = sparams->fl_wwnn; +hton24 (adisc->adisc_port_id, node->rnode.sport->fc_id); + + io->hio_type =EFCT_HW_ELS_RSP ; + rc =efct_els_send_rsp (io,sizeof (*adisc)); +if (rc) { +efct_els_io_free (io); + io =NULL ; + } + +return io; +} + +void * +efct_els_send_ct (struct efc *efc,struct efc_node *node,u32 cmd, +u32 timeout_sec,u32 retries) +{ +struct efct *efct = efc->base; + +switch (cmd) { +case FC_RCTL_ELS_REQ : +efct_ns_send_rftid (node, timeout_sec, retries,NULL ,NULL ); +break ; +case FC_NS_RFF_ID : +efct_ns_send_rffid (node, timeout_sec, retries,NULL ,NULL ); +break ; +case FC_NS_GID_PT : +efct_ns_send_gidpt (node, timeout_sec, retries,NULL ,NULL ); +break ; +default : +efc_log_err (efct,"Unhandled command cmd: %x\n" , cmd); + } + +return NULL ; +} + +static inline void fcct_build_req_header (struct fc_ct_hdr *hdr, +u16 cmd,u16 max_size) +{ + hdr->ct_rev =FC_CT_REV ; + hdr->ct_fs_type =FC_FST_DIR ; + hdr->ct_fs_subtype =FC_NS_SUBTYPE ; + hdr->ct_options =0 ; + hdr->ct_cmd =cpu_to_be16 (cmd); +/* words */ + hdr->ct_mr_size =cpu_to_be16 (max_size / (sizeof (u32))); + hdr->ct_reason =0 ; + hdr->ct_explan =0 ; + hdr->ct_vendor =0 ; +} + +struct efct_io * +efct_ns_send_rftid (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_ct_hdr *ct; +struct fc_ns_rft_id *rftid; + +node_els_trace (); + + els =efct_els_io_alloc (node,sizeof (*ct) +sizeof (*rftid), +EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->iparam.fc_ct.r_ctl =FC_RCTL_ELS_REQ ; + els->iparam.fc_ct.type =FC_TYPE_CT ; + els->iparam.fc_ct.df_ctl =0 ; + els->iparam.fc_ct.timeout = timeout_sec; + + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rftid" ; + + ct = els->els_req.virt; +memset (ct,0 ,sizeof (*ct)); +fcct_build_req_header (ct,FC_NS_RFT_ID ,sizeof (*rftid)); + + rftid = els->els_req.virt +sizeof (*ct); +memset (rftid,0 ,sizeof (*rftid)); +hton24 (rftid->fr_fid.fp_fid, node->rnode.sport->fc_id); + rftid->fr_fts.ff_type_map[FC_TYPE_FCP /FC_NS_BPW ] = +cpu_to_be32 (1 << (FC_TYPE_FCP %FC_NS_BPW )); + + els->hio_type =EFCT_HW_FC_CT ; +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_ns_send_rffid (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els; +struct efct *efct = node->efc->base; +struct fc_ct_hdr *ct; +struct fc_ns_rff_id *rffid; +u32 size =0 ; + +node_els_trace (); + + size =sizeof (*ct) +sizeof (*rffid); + + els =efct_els_io_alloc (node, size,EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + els->iparam.fc_ct.r_ctl =FC_RCTL_ELS_REQ ; + els->iparam.fc_ct.type =FC_TYPE_CT ; + els->iparam.fc_ct.df_ctl =0 ; + els->iparam.fc_ct.timeout = timeout_sec; + + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="rffid" ; + ct = els->els_req.virt; + +memset (ct,0 ,sizeof (*ct)); +fcct_build_req_header (ct,FC_NS_RFF_ID ,sizeof (*rffid)); + + rffid = els->els_req.virt +sizeof (*ct); +memset (rffid,0 ,sizeof (*rffid)); + +hton24 (rffid->fr_fid.fp_fid, node->rnode.sport->fc_id); +if (node->sport->enable_ini) + rffid->fr_feat |=FCP_FEAT_INIT ; +if (node->sport->enable_tgt) + rffid->fr_feat |=FCP_FEAT_TARG ; + rffid->fr_type =FC_TYPE_FCP ; + + els->hio_type =EFCT_HW_FC_CT ; + +efct_els_send_req (node, els); + +return els; +} + +struct efct_io * +efct_ns_send_gidpt (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg) +{ +struct efct_io *els =NULL ; +struct efct *efct = node->efc->base; +struct fc_ct_hdr *ct; +struct fc_ns_gid_pt *gidpt; +u32 size =0 ; + +node_els_trace (); + + size =sizeof (*ct) +sizeof (*gidpt); + els =efct_els_io_alloc_size (node, size, +EFCT_ELS_GID_PT_RSP_LEN , +EFCT_ELS_ROLE_ORIGINATOR ); +if (!els) { +efc_log_err (efct,"IO alloc failed\n" ); +return els; + } + + els->iparam.fc_ct.r_ctl =FC_RCTL_ELS_REQ ; + els->iparam.fc_ct.type =FC_TYPE_CT ; + els->iparam.fc_ct.df_ctl =0 ; + els->iparam.fc_ct.timeout = timeout_sec; + + els->els_callback = cb; + els->els_callback_arg = cbarg; + els->display_name ="gidpt" ; + + ct = els->els_req.virt; + +memset (ct,0 ,sizeof (*ct)); +fcct_build_req_header (ct,FC_NS_GID_PT ,sizeof (*gidpt)); + + gidpt = els->els_req.virt +sizeof (*ct); +memset (gidpt,0 ,sizeof (*gidpt)); + gidpt->fn_pt_type =FC_TYPE_FCP ; + + els->hio_type =EFCT_HW_FC_CT ; + +efct_els_send_req (node, els); + +return els; +} + +static int efct_bls_send_rjt_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode,u32 length, +int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; + +efct_scsi_io_free (io); +return EFC_SUCCESS ; +} + +static struct efct_io * +efct_bls_send_rjt (struct efct_io *io,u32 s_id, +u16 ox_id,u16 rx_id) +{ +struct efc_node *node = io->node; +int rc; +struct fc_ba_rjt *acc; +struct efct *efct; + + efct = node->efc->base; + +if (node->rnode.sport->fc_id == s_id) + s_id =U32_MAX ; + +/* fill out generic fields */ + io->efct = efct; + io->node = node; + io->cmd_tgt = true; + +/* fill out BLS Response-specific fields */ + io->io_type =EFCT_IO_TYPE_BLS_RESP ; + io->display_name ="ba_rjt" ; + io->hio_type =EFCT_HW_BLS_RJT ; + io->init_task_tag = ox_id; + +/* fill out iparam fields */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.bls.ox_id = ox_id; + io->iparam.bls.rx_id = rx_id; + + acc = (void *)io->iparam.bls.payload; + +memset (io->iparam.bls.payload,0 , +sizeof (io->iparam.bls.payload)); + acc->br_reason =ELS_RJT_UNAB ; + acc->br_explan =ELS_EXPL_NONE ; + + rc =efct_scsi_io_dispatch (io, efct_bls_send_rjt_cb); +if (rc) { +efc_log_err (efct,"efct_scsi_io_dispatch() failed: %d\n" , rc); +efct_scsi_io_free (io); + io =NULL ; + } +return io; +} + +struct efct_io * +efct_bls_send_rjt_hdr (struct efct_io *io,struct fc_frame_header *hdr) +{ +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); +u16 rx_id =be16_to_cpu (hdr->fh_rx_id); +u32 d_id =ntoh24 (hdr->fh_d_id); + +return efct_bls_send_rjt (io, d_id, ox_id, rx_id); +} + +static int efct_bls_send_acc_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode,u32 length, +int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; + +efct_scsi_io_free (io); +return EFC_SUCCESS ; +} + +static struct efct_io * +efct_bls_send_acc (struct efct_io *io,u32 s_id, +u16 ox_id,u16 rx_id) +{ +struct efc_node *node = io->node; +int rc; +struct fc_ba_acc *acc; +struct efct *efct; + + efct = node->efc->base; + +if (node->rnode.sport->fc_id == s_id) + s_id =U32_MAX ; + +/* fill out generic fields */ + io->efct = efct; + io->node = node; + io->cmd_tgt = true; + +/* fill out BLS Response-specific fields */ + io->io_type =EFCT_IO_TYPE_BLS_RESP ; + io->display_name ="ba_acc" ; + io->hio_type =EFCT_HW_BLS_ACC_SID ; + io->init_task_tag = ox_id; + +/* fill out iparam fields */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.bls.s_id = s_id; + io->iparam.bls.ox_id = ox_id; + io->iparam.bls.rx_id = rx_id; + + acc = (void *)io->iparam.bls.payload; + +memset (io->iparam.bls.payload,0 , +sizeof (io->iparam.bls.payload)); + acc->ba_ox_id =cpu_to_be16 (io->iparam.bls.ox_id); + acc->ba_rx_id =cpu_to_be16 (io->iparam.bls.rx_id); + acc->ba_high_seq_cnt =cpu_to_be16 (U16_MAX ); + + rc =efct_scsi_io_dispatch (io, efct_bls_send_acc_cb); +if (rc) { +efc_log_err (efct,"efct_scsi_io_dispatch() failed: %d\n" , rc); +efct_scsi_io_free (io); + io =NULL ; + } +return io; +} + +void * +efct_bls_send_acc_hdr (struct efc *efc,struct efc_node *node, +struct fc_frame_header *hdr) +{ +struct efct_io *io =NULL ; +u16 ox_id =be16_to_cpu (hdr->fh_ox_id); +u16 rx_id =be16_to_cpu (hdr->fh_rx_id); +u32 d_id =ntoh24 (hdr->fh_d_id); + + io =efct_scsi_io_alloc (node,EFCT_SCSI_IO_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efc,"els IO alloc failed\n" ); +return io; + } + +return efct_bls_send_acc (io, d_id, ox_id, rx_id); +} + +static int +efct_els_abort_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status, +void *app) +{ +struct efct_io *els; +struct efct_io *abort_io =NULL ;/* IO structure used to abort ELS */ +struct efct *efct; + + abort_io = app; + els = abort_io->io_to_abort; + +if (!els || !els->node || !els->node->efc) +return EFC_FAIL ; + + efct = els->node->efc->base; + +if (status !=0 ) +efc_log_warn (efct,"status x%x ext x%x\n" , status, ext_status); + +/* now free the abort IO */ +efct_io_pool_io_free (efct->xport->io_pool, abort_io); + +/* send completion event to indicate abort process is complete +* Note: The ELS SM will already be receiving +* ELS_REQ_OK/FAIL/RJT/ABORTED +*/ +if (els->state ==EFCT_ELS_REQ_ABORTED ) { +/* completion for ELS that was aborted */ +efct_els_abort_cleanup (els); + }else { +/* completion for abort was received first, +* transition to wait for req cmpl +*/ + els->state =EFCT_ELS_ABORT_IO_COMPL ; + } + +/* done with ELS IO to abort */ +kref_put (&els->ref, els->release); +return EFC_SUCCESS ; +} + +static struct efct_io * +efct_els_abort_io (struct efct_io *els,bool send_abts) +{ +struct efct *efct; +struct efct_xport *xport; +int rc; +struct efct_io *abort_io =NULL ; + + efct = els->node->efc->base; + xport = efct->xport; + +/* take a reference on IO being aborted */ +if ((kref_get_unless_zero (&els->ref) ==0 )) { +/* command no longer active */ +efc_log_debug (efct,"els no longer active\n" ); +return NULL ; + } + +/* allocate IO structure to send abort */ + abort_io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!abort_io) { +atomic_add_return (1 , &xport->io_alloc_failed_count); + }else { +/* set generic fields */ + abort_io->efct = efct; + abort_io->node = els->node; + abort_io->cmd_ini = true; + +/* set type and ABORT-specific fields */ + abort_io->io_type =EFCT_IO_TYPE_ABORT ; + abort_io->display_name ="abort_els" ; + abort_io->io_to_abort = els; + abort_io->send_abts = send_abts; + +/* now dispatch IO */ + rc =efct_scsi_io_dispatch_abort (abort_io, efct_els_abort_cb); +if (rc) { +efc_log_err (efct, +"efct_scsi_io_dispatch failed: %d\n" , rc); +efct_io_pool_io_free (efct->xport->io_pool, abort_io); + abort_io =NULL ; + } + } + +/* if something failed, put reference on ELS to abort */ +if (!abort_io) +kref_put (&els->ref, els->release); +return abort_io; +} + +void +efct_els_abort (struct efct_io *els,struct efc_node_cb *arg) +{ +struct efct_io *io =NULL ; +struct efc_node *node; +struct efct *efct; + + node = els->node; + efct = node->efc->base; + +/* request to abort this ELS without an ABTS */ +els_io_printf (els,"ELS abort requested\n" ); +/* Set retries to zero,we are done */ + els->els_retries_remaining =0 ; +if (els->state ==EFCT_ELS_REQUEST ) { + els->state =EFCT_ELS_REQ_ABORT ; + io =efct_els_abort_io (els, false); +if (!io) { +efc_log_err (efct,"efct_els_abort_io failed\n" ); +efct_els_io_cleanup (els,EFC_HW_SRRS_ELS_REQ_FAIL , + arg); + } + + }else if (els->state ==EFCT_ELS_REQUEST_DELAYED ) { +/* mod/resched the timer for a short duration */ +mod_timer (&els->delay_timer, + jiffies +msecs_to_jiffies (1 )); + + els->state =EFCT_ELS_REQUEST_DELAY_ABORT ; + } +} + +void +efct_els_io_cleanup (struct efct_io *els, +enum efc_hw_node_els_event node_evt,void *arg) +{ +/* don't want further events that could come; e.g. abort requests +* from the node state machine; thus, disable state machine +*/ + els->els_req_free = true; +efc_node_post_els_resp (els->node, node_evt, arg); + +/* If this IO has a callback, invoke it */ +if (els->els_callback) { + (*els->els_callback)(els->node, arg, + els->els_callback_arg); + } +efct_els_io_free (els); +} + +int +efct_els_io_list_empty (struct efc_node *node,struct list_head *list) +{ +int empty; +unsigned long flags =0 ; + +spin_lock_irqsave (&node->active_ios_lock, flags); + empty =list_empty (list); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return empty; +} + +static int +efct_ct_acc_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status, +void *arg) +{ +struct efct_io *io = arg; + +efct_els_io_free (io); + +return EFC_SUCCESS ; +} + +int +efct_send_ct_rsp (struct efc *efc,struct efc_node *node,u16 ox_id, +struct fc_ct_hdr *ct_hdr,u32 cmd_rsp_code, +u32 reason_code,u32 reason_code_explanation) +{ +struct efct_io *io =NULL ; +struct fc_ct_hdr *rsp =NULL ; + + io =efct_els_io_alloc (node,256 ,EFCT_ELS_ROLE_RESPONDER ); +if (!io) { +efc_log_err (efc,"IO alloc failed\n" ); +return EFC_FAIL ; + } + + rsp = io->els_rsp.virt; + io->io_type =EFCT_IO_TYPE_CT_RESP ; + + *rsp = *ct_hdr; + +fcct_build_req_header (rsp, cmd_rsp_code,0 ); + rsp->ct_reason = reason_code; + rsp->ct_explan = reason_code_explanation; + + io->display_name ="ct_rsp" ; + io->init_task_tag = ox_id; + io->wire_len +=sizeof (*rsp); + +memset (&io->iparam,0 ,sizeof (io->iparam)); + + io->io_type =EFCT_IO_TYPE_CT_RESP ; + io->hio_type =EFCT_HW_FC_CT_RSP ; + io->iparam.fc_ct.ox_id = ox_id; + io->iparam.fc_ct.r_ctl =3 ; + io->iparam.fc_ct.type =FC_TYPE_CT ; + io->iparam.fc_ct.df_ctl =0 ; + io->iparam.fc_ct.timeout =5 ; + +if (efct_scsi_io_dispatch (io, efct_ct_acc_cb) <0 ) { +efct_els_io_free (io); +return EFC_FAIL ; + } +return EFC_SUCCESS ; +}drivers/scsi/elx/efct/efct_els.h new file +133
-0@@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_ELS_H__) +#define __EFCT_ELS_H__ + +enum efct_els_role { +EFCT_ELS_ROLE_ORIGINATOR , +EFCT_ELS_ROLE_RESPONDER , +}; + +void _efct_els_io_free (struct kref *arg); +extern struct efct_io * +efct_els_io_alloc (struct efc_node *node,u32 reqlen, +enum efct_els_role role); +extern struct efct_io * +efct_els_io_alloc_size (struct efc_node *node,u32 reqlen, +u32 rsplen, +enum efct_els_role role); +void efct_els_io_free (struct efct_io *els); + +extern void * +efct_els_req_send (struct efc *efc,struct efc_node *node, +u32 cmd,u32 timeout_sec,u32 retries); +extern void * +efct_els_send_ct (struct efc *efc,struct efc_node *node, +u32 cmd,u32 timeout_sec,u32 retries); +extern void * +efct_els_resp_send (struct efc *efc,struct efc_node *node, +u32 cmd,u16 ox_id); +void +efct_els_abort (struct efct_io *els,struct efc_node_cb *arg); +/* ELS command send */ +typedef void (*els_cb_t )(struct efc_node *node, +struct efc_node_cb *cbdata,void *arg); +extern struct efct_io * +efct_send_plogi (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_flogi (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_fdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_prli (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_prlo (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_logo (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_adisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_pdisc (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_scr (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_ns_send_rftid (struct efc_node *node, +u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_ns_send_rffid (struct efc_node *node, +u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_ns_send_gidpt (struct efc_node *node,u32 timeout_sec, +u32 retries,els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_rscn (struct efc_node *node,u32 timeout_sec, +u32 retries,void *port_ids, +u32 port_ids_count,els_cb_t cb,void *cbarg); +extern void +efct_els_io_cleanup (struct efct_io *els,enum efc_hw_node_els_event , +void *arg); + +/* ELS acc send */ +extern struct efct_io * +efct_send_ls_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg); + +extern void * +efct_send_ls_rjt (struct efc *efc,struct efc_node *node,u32 ox_id, +u32 reason_cod,u32 reason_code_expl, +u32 vendor_unique); +extern void * +efct_send_flogi_p2p_acc (struct efc *efc,struct efc_node *node, +u32 ox_id,u32 s_id); +extern struct efct_io * +efct_send_flogi_acc (struct efc_node *node,u32 ox_id, +u32 is_fport,els_cb_t cb, +void *cbarg); +extern struct efct_io * +efct_send_plogi_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_prli_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_logo_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_prlo_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg); +extern struct efct_io * +efct_send_adisc_acc (struct efc_node *node,u32 ox_id, +els_cb_t cb,void *cbarg); + +extern void * +efct_bls_send_acc_hdr (struct efc *efc,struct efc_node *node, +struct fc_frame_header *hdr); +extern struct efct_io * +efct_bls_send_rjt_hdr (struct efct_io *io,struct fc_frame_header *hdr); + +extern int +efct_els_io_list_empty (struct efc_node *node,struct list_head *list); + +/* CT */ +extern int +efct_send_ct_rsp (struct efc *efc,struct efc_node *node,u16 ox_id, +struct fc_ct_hdr *ct_hdr, +u32 cmd_rsp_code,u32 reason_code, +u32 reason_code_explanation); + +#endif /* __EFCT_ELS_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 23/31 elx: efct: SCSI IO handling routines
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines for SCSI transport IO alloc, build and send IO.
---
v3:
Removed DIF related code which is not used.
Removed SCSI get property.
--- drivers/scsi/elx/efct/efct_scsi.c | 1192 +++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_scsi.h | 235 ++++++++ 2 files changed, 1427 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_scsi.c create mode 100644 drivers/scsi/elx/efct/efct_scsi.h
drivers/scsi/elx/efct/efct_scsi.c new file +1192 -0
@@ -0,0 +1,1192 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_els.h" +#include "efct_hw.h" + +#define enable_tsend_auto_resp (efct) 1 +#define enable_treceive_auto_resp (efct) 0 + +#define SCSI_IOFMT "[%04x][i:%04x t:%04x h:%04x]" + +#define scsi_io_printf (io, fmt, ...) \ + efc_log_debug(io->efct, "[%s]" SCSI_IOFMT fmt, \ + io->node->display_name, io->instance_index,\ + io->init_task_tag, io->tgt_task_tag, io->hw_tag, ##__VA_ARGS__) + +#define EFCT_LOG_ENABLE_SCSI_TRACE (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 2)) != 0) : 0) + +#define scsi_io_trace (io, fmt, ...) \ + do { \ + if (EFCT_LOG_ENABLE_SCSI_TRACE(io->efct)) \ + scsi_io_printf(io, fmt, ##__VA_ARGS__); \ + } while (0) + +/* Enable the SCSI and Transport IO allocations */ +void +efct_scsi_io_alloc_enable (struct efc *efc,struct efc_node *node) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&node->active_ios_lock, flags); + node->io_alloc_enabled = true; +spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +/* Disable the SCSI and Transport IO allocations */ +void +efct_scsi_io_alloc_disable (struct efc *efc,struct efc_node *node) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&node->active_ios_lock, flags); + node->io_alloc_enabled = false; +spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +struct efct_io * +efct_scsi_io_alloc (struct efc_node *node,enum efct_scsi_io_role role) +{ +struct efct *efct; +struct efc *efcp; +struct efct_xport *xport; +struct efct_io *io; +unsigned long flags =0 ; + + efcp = node->efc; + efct = efcp->base; + + xport = efct->xport; + +spin_lock_irqsave (&node->active_ios_lock, flags); + +if (!node->io_alloc_enabled) { +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + + io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!io) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* initialize refcount */ +kref_init (&io->ref); + io->release = _efct_scsi_io_free; + +if (io->hio) { +efc_log_err (efct, +"assertion failed: io->hio is not NULL\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* set generic fields */ + io->efct = efct; + io->node = node; + +/* set type and name */ + io->io_type =EFCT_IO_TYPE_IO ; + io->display_name ="scsi_io" ; + +switch (role) { +case EFCT_SCSI_IO_ROLE_ORIGINATOR : + io->cmd_ini = true; + io->cmd_tgt = false; +break ; +case EFCT_SCSI_IO_ROLE_RESPONDER : + io->cmd_ini = false; + io->cmd_tgt = true; +break ; + } + +/* Add to node's active_ios list */ +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &node->active_ios); + +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +return io; +} + +void +_efct_scsi_io_free (struct kref *arg) +{ + struct efct_io *io = container_of(arg, struct efct_io, ref); +struct efct *efct = io->efct; +struct efc_node *node = io->node; +int send_empty_event; +unsigned long flags =0 ; + +scsi_io_trace (io,"freeing io 0x%p %s\n" , io, io->display_name); + +if (io->io_free) { +efc_log_err (efct,"IO already freed.\n" ); +return ; + } + +spin_lock_irqsave (&node->active_ios_lock, flags); +list_del (&io->list_entry); + send_empty_event = (!node->io_alloc_enabled) && +list_empty (&node->active_ios); +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +if (send_empty_event) +efc_scsi_io_list_empty (node->efc, node); + + io->node =NULL ; +efct_io_pool_io_free (efct->xport->io_pool, io); +} + +void +efct_scsi_io_free (struct efct_io *io) +{ +scsi_io_trace (io,"freeing io 0x%p %s\n" , io, io->display_name); +WARN_ON (refcount_read (&io->ref.refcount) !=0 ); +kref_put (&io->ref, io->release); +} + +static void +efct_target_io_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status scsi_stat =EFCT_SCSI_STATUS_GOOD ; + +if (!io || !io->efct) { +pr_err ("%s: IO can not be NULL\n" , __func__); +return ; + } + +scsi_io_trace (io,"status x%x ext_status x%x\n" , status, ext_status); + + efct = io->efct; + + io->transferred += length; + +/* Call target server completion */ +if (io->scsi_tgt_cb) { +efct_scsi_io_cb_t cb = io->scsi_tgt_cb; +u32 flags =0 ; + +/* Clear the callback before invoking the callback */ + io->scsi_tgt_cb =NULL ; + +/* if status was good, and auto-good-response was set, +* then callback target-server with IO_CMPL_RSP_SENT, +* otherwise send IO_CMPL +*/ +if (status ==0 && io->auto_resp) + flags |=EFCT_SCSI_IO_CMPL_RSP_SENT ; +else + flags |=EFCT_SCSI_IO_CMPL ; + +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : + scsi_stat =EFCT_SCSI_STATUS_GOOD ; +break ; +case SLI4_FC_WCQE_STATUS_DI_ERROR : +if (ext_status &SLI4_FC_DI_ERROR_GE ) + scsi_stat =EFCT_SCSI_STATUS_DIF_GUARD_ERR ; +else if (ext_status &SLI4_FC_DI_ERROR_AE ) + scsi_stat =EFCT_SCSI_STATUS_DIF_APP_TAG_ERROR ; +else if (ext_status &SLI4_FC_DI_ERROR_RE ) + scsi_stat =EFCT_SCSI_STATUS_DIF_REF_TAG_ERROR ; +else + scsi_stat =EFCT_SCSI_STATUS_DIF_UNKNOWN_ERROR ; +break ; +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_INVALID_RELOFFSET : +case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED : + scsi_stat =EFCT_SCSI_STATUS_ABORTED ; +break ; +case SLI4_FC_LOCAL_REJECT_INVALID_RPI : + scsi_stat =EFCT_SCSI_STATUS_NEXUS_LOST ; +break ; +case SLI4_FC_LOCAL_REJECT_NO_XRI : + scsi_stat =EFCT_SCSI_STATUS_NO_IO ; +break ; +default : +/*we have seen 0x0d(TX_DMA_FAILED err)*/ + scsi_stat =EFCT_SCSI_STATUS_ERROR ; +break ; + } +break ; + +case SLI4_FC_WCQE_STATUS_TARGET_WQE_TIMEOUT : +/* target IO timed out */ + scsi_stat =EFCT_SCSI_STATUS_TIMEDOUT_AND_ABORTED ; +break ; + +case SLI4_FC_WCQE_STATUS_SHUTDOWN : +/* Target IO cancelled by HW */ + scsi_stat =EFCT_SCSI_STATUS_SHUTDOWN ; +break ; + +default : + scsi_stat =EFCT_SCSI_STATUS_ERROR ; +break ; + } + +cb (io, scsi_stat, flags, io->scsi_tgt_cb_arg); + } +efct_scsi_check_pending (efct); +} + +static int +efct_scsi_build_sgls (struct efct_hw *hw,struct efct_hw_io *hio, +struct efct_scsi_sgl *sgl,u32 sgl_count, +enum efct_hw_io_type type) +{ +int rc; +u32 i; +struct efct *efct = hw->os; + +/* Initialize HW SGL */ + rc =efct_hw_io_init_sges (hw, hio, type); +if (rc) { +efc_log_err (efct,"efct_hw_io_init_sges failed: %d\n" , rc); +return EFC_FAIL ; + } + +for (i =0 ; i < sgl_count; i++) { + +/* Add data SGE */ + rc =efct_hw_io_add_sge (hw, hio, + sgl[i].addr, sgl[i].len); +if (rc) { +efc_log_err (efct, +"add sge failed cnt=%d rc=%d\n" , + sgl_count, rc); +return rc; + } + } + +return EFC_SUCCESS ; +} + +static void efc_log_sgl (struct efct_io *io) +{ +struct efct_hw_io *hio = io->hio; +struct sli4_sge *data =NULL ; +u32 *dword =NULL ; +u32 i; +u32 n_sge; + +scsi_io_trace (io,"def_sgl at 0x%x 0x%08x\n" , +upper_32_bits (hio->def_sgl.phys), +lower_32_bits (hio->def_sgl.phys)); + n_sge = (hio->sgl == &hio->def_sgl ? + hio->n_sge : hio->def_sgl_count); +for (i =0 , data = hio->def_sgl.virt; i < n_sge; i++, data++) { + dword = (u32 *)data; + +scsi_io_trace (io,"SGL %2d 0x%08x 0x%08x 0x%08x 0x%08x\n" , + i, dword[0 ], dword[1 ], dword[2 ], dword[3 ]); + +if (dword[2 ] & (1U <<31 )) +break ; + } + +} + +static int +efct_scsi_check_pending_async_cb (struct efct_hw *hw,int status, +u8 *mqe,void *arg) +{ +struct efct_io *io = arg; + +if (io) { +if (io->hw_cb) { +efct_hw_done_t cb = io->hw_cb; + + io->hw_cb =NULL ; + (cb)(io->hio,NULL ,0 , +SLI4_FC_WCQE_STATUS_DISPATCH_ERROR ,0 , io); + } + } +return EFC_SUCCESS ; +} + +static int +efct_scsi_io_dispatch_hw_io (struct efct_io *io,struct efct_hw_io *hio) +{ +int rc =0 ; +struct efct *efct = io->efct; + +/* Got a HW IO; +* update ini/tgt_task_tag with HW IO info and dispatch +*/ + io->hio = hio; +if (io->cmd_tgt) + io->tgt_task_tag = hio->indicator; +else if (io->cmd_ini) + io->init_task_tag = hio->indicator; + io->hw_tag = hio->reqtag; + + hio->eq = io->hw_priv; + +/* Copy WQ steering */ +switch (io->wq_steering) { +case EFCT_SCSI_WQ_STEERING_CLASS >>EFCT_SCSI_WQ_STEERING_SHIFT : + hio->wq_steering =EFCT_HW_WQ_STEERING_CLASS ; +break ; +case EFCT_SCSI_WQ_STEERING_REQUEST >>EFCT_SCSI_WQ_STEERING_SHIFT : + hio->wq_steering =EFCT_HW_WQ_STEERING_REQUEST ; +break ; +case EFCT_SCSI_WQ_STEERING_CPU >>EFCT_SCSI_WQ_STEERING_SHIFT : + hio->wq_steering =EFCT_HW_WQ_STEERING_CPU ; +break ; + } + +switch (io->io_type) { +case EFCT_IO_TYPE_IO : + rc =efct_scsi_build_sgls (&efct->hw, io->hio, + io->sgl, io->sgl_count, io->hio_type); +if (rc) +break ; + +if (EFCT_LOG_ENABLE_SCSI_TRACE (efct)) +efc_log_sgl (io); + +if (io->app_id) + io->iparam.fcp_tgt.app_id = io->app_id; + + rc =efct_hw_io_send (&io->efct->hw, io->hio_type, io->hio, + io->wire_len, &io->iparam, + &io->node->rnode, io->hw_cb, io); +break ; +case EFCT_IO_TYPE_ELS : +case EFCT_IO_TYPE_CT : + rc =efct_hw_srrs_send (&efct->hw, io->hio_type, io->hio, + &io->els_req, io->wire_len, + &io->els_rsp, &io->node->rnode, &io->iparam, + io->hw_cb, io); +break ; +case EFCT_IO_TYPE_CT_RESP : + rc =efct_hw_srrs_send (&efct->hw, io->hio_type, io->hio, + &io->els_rsp, io->wire_len, +NULL , &io->node->rnode, &io->iparam, + io->hw_cb, io); +break ; +case EFCT_IO_TYPE_BLS_RESP : +/* no need to update tgt_task_tag for BLS response since +* the RX_ID will be specified by the payload, not the XRI +*/ + rc =efct_hw_srrs_send (&efct->hw, io->hio_type, io->hio, +NULL ,0 ,NULL , &io->node->rnode, + &io->iparam, io->hw_cb, io); +break ; +default : +scsi_io_printf (io,"Unknown IO type=%d\n" , io->io_type); + rc =-1 ; +break ; + } +return rc; +} + +static int +efct_scsi_io_dispatch_no_hw_io (struct efct_io *io) +{ +int rc; + +switch (io->io_type) { +case EFCT_IO_TYPE_ABORT : { +struct efct_hw_io *hio_to_abort =NULL ; + + hio_to_abort = io->io_to_abort->hio; + +if (!hio_to_abort) { +/* +* If "IO to abort" does not have an +* associated HW IO, immediately make callback with +* success. The command must have been sent to +* the backend, but the data phase has not yet +* started, so we don't have a HW IO. +* +* Note: since the backend shims should be +* taking a reference on io_to_abort, it should not +* be possible to have been completed and freed by +* the backend before the abort got here. +*/ +scsi_io_printf (io,"IO: not active\n" ); + ((efct_hw_done_t )io->hw_cb)(io->hio,NULL ,0 , +SLI4_FC_WCQE_STATUS_SUCCESS ,0 , io); + rc =0 ; + }else { +/* HW IO is valid, abort it */ +scsi_io_printf (io,"aborting\n" ); + rc =efct_hw_io_abort (&io->efct->hw, hio_to_abort, + io->send_abts, io->hw_cb, io); +if (rc) { +int status =SLI4_FC_WCQE_STATUS_SUCCESS ; + +if (rc !=EFCT_HW_RTN_IO_NOT_ACTIVE && + rc !=EFCT_HW_RTN_IO_ABORT_IN_PROGRESS ) { + status =-1 ; +scsi_io_printf (io, +"Failed to abort IO: status=%d\n" , + rc); + } + ((efct_hw_done_t )io->hw_cb)(io->hio, +NULL ,0 , status,0 , io); + rc =0 ; + } + } + +break ; + } +default : +scsi_io_printf (io,"Unknown IO type=%d\n" , io->io_type); + rc =-1 ; +break ; + } +return rc; +} + +/** +* Check for pending IOs to dispatch. +* +* If there are IOs on the pending list, and a HW IO is available, then +* dispatch the IOs. +*/ +void +efct_scsi_check_pending (struct efct *efct) +{ +struct efct_xport *xport = efct->xport; +struct efct_io *io =NULL ; +struct efct_hw_io *hio; +int status; +int count =0 ; +int dispatch; +unsigned long flags =0 ; + +/* Guard against recursion */ +if (atomic_add_return (1 , &xport->io_pending_recursing)) { +/* This function is already running. Decrement and return. */ +atomic_sub_return (1 , &xport->io_pending_recursing); +return ; + } + +do { +spin_lock_irqsave (&xport->io_pending_lock, flags); + status =0 ; + hio =NULL ; +if (!list_empty (&xport->io_pending_list)) { + io =list_first_entry (&xport->io_pending_list, + struct efct_io, + io_pending_link); + } +if (io) { +list_del (&io->io_pending_link); +if (io->io_type ==EFCT_IO_TYPE_ABORT ) { + hio =NULL ; + }else { + hio =efct_hw_io_alloc (&efct->hw); +if (!hio) { +/* +* No HW IO available.Put IO back on +* the front of pending list +*/ +list_add (&xport->io_pending_list, + &io->io_pending_link); + io =NULL ; + }else { + hio->eq = io->hw_priv; + } + } + } +/* Must drop the lock before dispatching the IO */ +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +if (io) { + count++; + +/* +* We pulled an IO off the pending list, +* and either got an HW IO or don't need one +*/ +atomic_sub_return (1 , &xport->io_pending_count); +if (!hio) + status =efct_scsi_io_dispatch_no_hw_io (io); +else + status =efct_scsi_io_dispatch_hw_io (io, hio); +if (status) { +/* +* Invoke the HW callback, but do so in the +* separate execution context,provided by the +* NOP mailbox completion processing context +* by using efct_hw_async_call() +*/ +if (efct_hw_async_call (&efct->hw, + efct_scsi_check_pending_async_cb, + io)) { +efc_log_test (efct, +"call hw async failed\n" ); + } + } + } + }while (io); + +/* +* If nothing was removed from the list, +* we might be in a case where we need to abort an +* active IO and the abort is on the pending list. +* Look for an abort we can dispatch. +*/ +if (count ==0 ) { + dispatch =0 ; + +spin_lock_irqsave (&xport->io_pending_lock, flags); +list_for_each_entry (io, &xport->io_pending_list, + io_pending_link) { +if (io->io_type ==EFCT_IO_TYPE_ABORT ) { +if (io->io_to_abort->hio) { +/* This IO has a HW IO, so it is +* active. Dispatch the abort. +*/ + dispatch =1 ; + }else { +/* Leave this abort on the pending +* list and keep looking +*/ + dispatch =0 ; + } + } +if (dispatch) { +list_del (&io->io_pending_link); +atomic_sub_return (1 , &xport->io_pending_count); +break ; + } + } +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +if (dispatch) { + status =efct_scsi_io_dispatch_no_hw_io (io); +if (status) { +if (efct_hw_async_call (&efct->hw, + efct_scsi_check_pending_async_cb, + io)) { +efc_log_test (efct, +"call to hw async failed\n" ); + } + } + } + } + +atomic_sub_return (1 , &xport->io_pending_recursing); +} + +/** +* An IO is dispatched: +* - if the pending list is not empty, add IO to pending list +* and call a function to process the pending list. +* - if pending list is empty, try to allocate a HW IO. If none +* is available, place this IO at the tail of the pending IO +* list. +* - if HW IO is available, attach this IO to the HW IO and +* submit it. +*/ +int +efct_scsi_io_dispatch (struct efct_io *io,void *cb) +{ +struct efct_hw_io *hio; +struct efct *efct = io->efct; +struct efct_xport *xport = efct->xport; +unsigned long flags =0 ; + + io->hw_cb = cb; + +/* +* if this IO already has a HW IO, then this is either +* not the first phase of the IO. Send it to the HW. +*/ +if (io->hio) +return efct_scsi_io_dispatch_hw_io (io, io->hio); + +/* +* We don't already have a HW IO associated with the IO. First check +* the pending list. If not empty, add IO to the tail and process the +* pending list. +*/ +spin_lock_irqsave (&xport->io_pending_lock, flags); +if (!list_empty (&xport->io_pending_list)) { +/* +* If this is a low latency request, +* the put at the front of the IO pending +* queue, otherwise put it at the end of the queue. +*/ +if (io->low_latency) { +INIT_LIST_HEAD (&io->io_pending_link); +list_add (&xport->io_pending_list, + &io->io_pending_link); + }else { +INIT_LIST_HEAD (&io->io_pending_link); +list_add_tail (&io->io_pending_link, + &xport->io_pending_list); + } +spin_unlock_irqrestore (&xport->io_pending_lock, flags); +atomic_add_return (1 , &xport->io_pending_count); +atomic_add_return (1 , &xport->io_total_pending); + +/* process pending list */ +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; + } +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +/* +* We don't have a HW IO associated with the IO and there's nothing +* on the pending list. Attempt to allocate a HW IO and dispatch it. +*/ + hio =efct_hw_io_alloc (&io->efct->hw); +if (!hio) { +/* Couldn't get a HW IO. Save this IO on the pending list */ +spin_lock_irqsave (&xport->io_pending_lock, flags); +INIT_LIST_HEAD (&io->io_pending_link); +list_add_tail (&io->io_pending_link, &xport->io_pending_list); +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +atomic_add_return (1 , &xport->io_total_pending); +atomic_add_return (1 , &xport->io_pending_count); +return EFC_SUCCESS ; + } + +/* We successfully allocated a HW IO; dispatch to HW */ +return efct_scsi_io_dispatch_hw_io (io, hio); +} + +/** +* An Abort IO is dispatched: +* - if the pending list is not empty, add IO to pending list +* and call a function to process the pending list. +* - if pending list is empty, send abort to the HW. +*/ + +int +efct_scsi_io_dispatch_abort (struct efct_io *io,void *cb) +{ +struct efct *efct = io->efct; +struct efct_xport *xport = efct->xport; +unsigned long flags =0 ; + + io->hw_cb = cb; + +/* +* For aborts, we don't need a HW IO, but we still want +* to pass through the pending list to preserve ordering. +* Thus, if the pending list is not empty, add this abort +* to the pending list and process the pending list. +*/ +spin_lock_irqsave (&xport->io_pending_lock, flags); +if (!list_empty (&xport->io_pending_list)) { +INIT_LIST_HEAD (&io->io_pending_link); +list_add_tail (&io->io_pending_link, + &xport->io_pending_list); +spin_unlock_irqrestore (&xport->io_pending_lock, flags); +atomic_add_return (1 , &xport->io_pending_count); +atomic_add_return (1 , &xport->io_total_pending); + +/* process pending list */ +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; + } +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +/* nothing on pending list, dispatch abort */ +return efct_scsi_io_dispatch_no_hw_io (io); +} + +static inline int +efct_scsi_xfer_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count,u64 xwire_len, +enum efct_hw_io_type type,int enable_ar, +efct_scsi_io_cb_t cb,void *arg) +{ +struct efct *efct; +size_t residual =0 ; + + io->sgl_count = sgl_count; + + efct = io->efct; + +scsi_io_trace (io,"%s wire_len %llu\n" , + (type ==EFCT_HW_IO_TARGET_READ ) ?"send" :"recv" , + xwire_len); + + io->hio_type = type; + + io->scsi_tgt_cb = cb; + io->scsi_tgt_cb_arg = arg; + + residual = io->exp_xfer_len - io->transferred; + io->wire_len = (xwire_len < residual) ? xwire_len : residual; + residual = (xwire_len - io->wire_len); + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.fcp_tgt.ox_id = io->init_task_tag; + io->iparam.fcp_tgt.offset = io->transferred; + io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; + io->iparam.fcp_tgt.timeout = io->timeout; + +/* if this is the last data phase and there is no residual, enable +* auto-good-response +*/ +if (enable_ar && (flags &EFCT_SCSI_LAST_DATAPHASE ) && + residual ==0 && + ((io->transferred + io->wire_len) == io->exp_xfer_len) && + (!(flags &EFCT_SCSI_NO_AUTO_RESPONSE ))) { + io->iparam.fcp_tgt.flags |=SLI4_IO_AUTO_GOOD_RESPONSE ; + io->auto_resp = true; + }else { + io->auto_resp = false; + } + +/* save this transfer length */ + io->xfer_req = io->wire_len; + +/* Adjust the transferred count to account for overrun +* when the residual is calculated in efct_scsi_send_resp +*/ + io->transferred += residual; + +/* Adjust the SGL size if there is overrun */ + +if (residual) { +struct efct_scsi_sgl *sgl_ptr = &io->sgl[sgl_count -1 ]; + +while (residual) { +size_t len = sgl_ptr->len; + +if (len > residual) { + sgl_ptr->len = len - residual; + residual =0 ; + }else { + sgl_ptr->len =0 ; + residual -= len; + io->sgl_count--; + } + sgl_ptr--; + } + } + +/* Set latency and WQ steering */ + io->low_latency = (flags &EFCT_SCSI_LOW_LATENCY ) !=0 ; + io->wq_steering = (flags &EFCT_SCSI_WQ_STEERING_MASK ) >> +EFCT_SCSI_WQ_STEERING_SHIFT ; + io->wq_class = (flags &EFCT_SCSI_WQ_CLASS_MASK ) >> +EFCT_SCSI_WQ_CLASS_SHIFT ; + +if (efct->xport) { +struct efct_xport *xport = efct->xport; + +if (type ==EFCT_HW_IO_TARGET_READ ) { + xport->fcp_stats.input_requests++; + xport->fcp_stats.input_bytes += xwire_len; + }else if (type ==EFCT_HW_IO_TARGET_WRITE ) { + xport->fcp_stats.output_requests++; + xport->fcp_stats.output_bytes += xwire_len; + } + } +return efct_scsi_io_dispatch (io, efct_target_io_cb); +} + +int +efct_scsi_send_rd_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count,u64 len, +efct_scsi_io_cb_t cb,void *arg) +{ +return efct_scsi_xfer_data (io, flags, sgl, sgl_count, + len,EFCT_HW_IO_TARGET_READ , +enable_tsend_auto_resp (io->efct), cb, arg); +} + +int +efct_scsi_recv_wr_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count,u64 len, +efct_scsi_io_cb_t cb,void *arg) +{ +return efct_scsi_xfer_data (io, flags, sgl, sgl_count, len, +EFCT_HW_IO_TARGET_WRITE , +enable_treceive_auto_resp (io->efct), cb, arg); +} + +int +efct_scsi_send_resp (struct efct_io *io,u32 flags, +struct efct_scsi_cmd_resp *rsp, +efct_scsi_io_cb_t cb,void *arg) +{ +struct efct *efct; +int residual; +bool auto_resp = true;/* Always try auto resp */ +u8 scsi_status =0 ; +u16 scsi_status_qualifier =0 ; +u8 *sense_data =NULL ; +u32 sense_data_length =0 ; + + efct = io->efct; + +if (rsp) { + scsi_status = rsp->scsi_status; + scsi_status_qualifier = rsp->scsi_status_qualifier; + sense_data = rsp->sense_data; + sense_data_length = rsp->sense_data_length; + residual = rsp->residual; + }else { + residual = io->exp_xfer_len - io->transferred; + } + + io->wire_len =0 ; + io->hio_type =EFCT_HW_IO_TARGET_RSP ; + + io->scsi_tgt_cb = cb; + io->scsi_tgt_cb_arg = arg; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.fcp_tgt.ox_id = io->init_task_tag; + io->iparam.fcp_tgt.offset =0 ; + io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; + io->iparam.fcp_tgt.timeout = io->timeout; + +/* Set low latency queueing request */ + io->low_latency = (flags &EFCT_SCSI_LOW_LATENCY ) !=0 ; + io->wq_steering = (flags &EFCT_SCSI_WQ_STEERING_MASK ) >> +EFCT_SCSI_WQ_STEERING_SHIFT ; + io->wq_class = (flags &EFCT_SCSI_WQ_CLASS_MASK ) >> +EFCT_SCSI_WQ_CLASS_SHIFT ; + +if (scsi_status !=0 || residual || sense_data_length) { +struct fcp_resp_with_ext *fcprsp = io->rspbuf.virt; +u8 *sns_data = io->rspbuf.virt +sizeof (*fcprsp); + +if (!fcprsp) { +efc_log_err (efct,"NULL response buffer\n" ); +return EFC_FAIL ; + } + + auto_resp = false; + +memset (fcprsp,0 ,sizeof (*fcprsp)); + + io->wire_len +=sizeof (*fcprsp); + + fcprsp->resp.fr_status = scsi_status; + fcprsp->resp.fr_retry_delay = +cpu_to_be16 (scsi_status_qualifier); + +/* set residual status if necessary */ +if (residual !=0 ) { +/* FCP: if data transferred is less than the +* amount expected, then this is an underflow. +* If data transferred would have been greater +* than the amount expected this is an overflow +*/ +if (residual >0 ) { + fcprsp->resp.fr_flags |=FCP_RESID_UNDER ; + fcprsp->ext.fr_resid =cpu_to_be32 (residual); + }else { + fcprsp->resp.fr_flags |=FCP_RESID_OVER ; + fcprsp->ext.fr_resid =cpu_to_be32 (-residual); + } + } + +if (EFCT_SCSI_SNS_BUF_VALID (sense_data) && sense_data_length) { +if (sense_data_length >SCSI_SENSE_BUFFERSIZE ) { +efc_log_err (efct,"Sense exceeds max size.\n" ); +return EFC_FAIL ; + } + + fcprsp->resp.fr_flags |=FCP_SNS_LEN_VAL ; +memcpy (sns_data, sense_data, sense_data_length); + fcprsp->ext.fr_sns_len =cpu_to_be32 (sense_data_length); + io->wire_len += sense_data_length; + } + + io->sgl[0 ].addr = io->rspbuf.phys; +//io->sgl[0].dif_addr = 0; + io->sgl[0 ].len = io->wire_len; + io->sgl_count =1 ; + } + +if (auto_resp) + io->iparam.fcp_tgt.flags |=SLI4_IO_AUTO_GOOD_RESPONSE ; + +return efct_scsi_io_dispatch (io, efct_target_io_cb); +} + +static int +efct_target_bls_resp_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status bls_status; + + efct = io->efct; + +/* BLS isn't really a "SCSI" concept, but use SCSI status */ +if (status) { +io_error_log (io,"s=%#x x=%#x\n" , status, ext_status); + bls_status =EFCT_SCSI_STATUS_ERROR ; + }else { + bls_status =EFCT_SCSI_STATUS_GOOD ; + } + +if (io->bls_cb) { +efct_scsi_io_cb_t bls_cb = io->bls_cb; +void *bls_cb_arg = io->bls_cb_arg; + + io->bls_cb =NULL ; + io->bls_cb_arg =NULL ; + +/* invoke callback */ +bls_cb (io, bls_status,0 , bls_cb_arg); + } + +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; +} + +static int +efct_target_send_bls_resp (struct efct_io *io, +efct_scsi_io_cb_t cb,void *arg) +{ +int rc; +struct fc_ba_acc *acc; + +/* fill out IO structure with everything needed to send BA_ACC */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.bls.ox_id = io->init_task_tag; + io->iparam.bls.rx_id = io->abort_rx_id; + + acc = (void *)io->iparam.bls.payload; + +memset (io->iparam.bls.payload,0 , +sizeof (io->iparam.bls.payload)); + acc->ba_ox_id =cpu_to_be16 (io->iparam.bls.ox_id); + acc->ba_rx_id =cpu_to_be16 (io->iparam.bls.rx_id); + acc->ba_high_seq_cnt =cpu_to_be16 (U16_MAX ); + +/* generic io fields have already been populated */ + +/* set type and BLS-specific fields */ + io->io_type =EFCT_IO_TYPE_BLS_RESP ; + io->display_name ="bls_rsp" ; + io->hio_type =EFCT_HW_BLS_ACC ; + io->bls_cb = cb; + io->bls_cb_arg = arg; + +/* dispatch IO */ + rc =efct_scsi_io_dispatch (io, efct_target_bls_resp_cb); +return rc; +} + +int +efct_scsi_send_tmf_resp (struct efct_io *io, +enum efct_scsi_tmf_resp rspcode, +u8 addl_rsp_info[3 ], +efct_scsi_io_cb_t cb,void *arg) +{ +int rc =-1 ; +struct fcp_resp_with_ext *fcprsp =NULL ; +struct fcp_resp_rsp_info *rspinfo =NULL ; +u8 fcp_rspcode; + + io->wire_len =0 ; + +switch (rspcode) { +case EFCT_SCSI_TMF_FUNCTION_COMPLETE : + fcp_rspcode =FCP_TMF_CMPL ; +break ; +case EFCT_SCSI_TMF_FUNCTION_SUCCEEDED : +case EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND : + fcp_rspcode =FCP_TMF_CMPL ; +break ; +case EFCT_SCSI_TMF_FUNCTION_REJECTED : + fcp_rspcode =FCP_TMF_REJECTED ; +break ; +case EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER : + fcp_rspcode =FCP_TMF_INVALID_LUN ; +break ; +case EFCT_SCSI_TMF_SERVICE_DELIVERY : + fcp_rspcode =FCP_TMF_FAILED ; +break ; +default : + fcp_rspcode =FCP_TMF_REJECTED ; +break ; + } + + io->hio_type =EFCT_HW_IO_TARGET_RSP ; + + io->scsi_tgt_cb = cb; + io->scsi_tgt_cb_arg = arg; + +if (io->tmf_cmd ==EFCT_SCSI_TMF_ABORT_TASK ) { + rc =efct_target_send_bls_resp (io, cb, arg); +return rc; + } + +/* populate the FCP TMF response */ + fcprsp = io->rspbuf.virt; +memset (fcprsp,0 ,sizeof (*fcprsp)); + + fcprsp->resp.fr_flags |=FCP_SNS_LEN_VAL ; + + rspinfo = io->rspbuf.virt +sizeof (*fcprsp); +if (addl_rsp_info) { +memcpy (rspinfo->_fr_resvd, addl_rsp_info, +sizeof (rspinfo->_fr_resvd)); + } + rspinfo->rsp_code = fcp_rspcode; + + io->wire_len =sizeof (*fcprsp) +sizeof (*rspinfo); + + fcprsp->ext.fr_rsp_len =cpu_to_be32 (sizeof (*rspinfo)); + + io->sgl[0 ].addr = io->rspbuf.phys; + io->sgl[0 ].dif_addr =0 ; + io->sgl[0 ].len = io->wire_len; + io->sgl_count =1 ; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.fcp_tgt.ox_id = io->init_task_tag; + io->iparam.fcp_tgt.offset =0 ; + io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; + io->iparam.fcp_tgt.timeout = io->timeout; + + rc =efct_scsi_io_dispatch (io, efct_target_io_cb); + +return rc; +} + +static int +efct_target_abort_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 length,int status, +u32 ext_status,void *app) +{ +struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status scsi_status; + + efct = io->efct; + +if (io->abort_cb) { +efct_scsi_io_cb_t abort_cb = io->abort_cb; +void *abort_cb_arg = io->abort_cb_arg; + + io->abort_cb =NULL ; + io->abort_cb_arg =NULL ; + +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : + scsi_status =EFCT_SCSI_STATUS_GOOD ; +break ; +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_NO_XRI : + scsi_status =EFCT_SCSI_STATUS_NO_IO ; +break ; +case SLI4_FC_LOCAL_REJECT_ABORT_IN_PROGRESS : + scsi_status = +EFCT_SCSI_STATUS_ABORT_IN_PROGRESS ; +break ; +default : +/*we have seen 0x15 (abort in progress)*/ + scsi_status =EFCT_SCSI_STATUS_ERROR ; +break ; + } +break ; +case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE : + scsi_status =EFCT_SCSI_STATUS_CHECK_RESPONSE ; +break ; +default : + scsi_status =EFCT_SCSI_STATUS_ERROR ; +break ; + } +/* invoke callback */ +abort_cb (io->io_to_abort, scsi_status,0 , abort_cb_arg); + } + +/* done with IO to abort,efct_ref_get(): efct_scsi_tgt_abort_io() */ +kref_put (&io->io_to_abort->ref, io->io_to_abort->release); + +efct_io_pool_io_free (efct->xport->io_pool, io); + +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; +} + +int +efct_scsi_tgt_abort_io (struct efct_io *io,efct_scsi_io_cb_t cb,void *arg) +{ +struct efct *efct; +struct efct_xport *xport; +int rc; +struct efct_io *abort_io =NULL ; + + efct = io->efct; + xport = efct->xport; + +/* take a reference on IO being aborted */ +if ((kref_get_unless_zero (&io->ref) ==0 )) { +/* command no longer active */ +scsi_io_printf (io,"command no longer active\n" ); +return EFC_FAIL ; + } + +/* +* allocate a new IO to send the abort request. Use efct_io_alloc() +* directly, as we need an IO object that will not fail allocation +* due to allocations being disabled (in efct_scsi_io_alloc()) +*/ + abort_io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!abort_io) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +kref_put (&io->ref, io->release); +return EFC_FAIL ; + } + +/* Save the target server callback and argument */ +/* set generic fields */ + abort_io->cmd_tgt = true; + abort_io->node = io->node; + +/* set type and abort-specific fields */ + abort_io->io_type =EFCT_IO_TYPE_ABORT ; + abort_io->display_name ="tgt_abort" ; + abort_io->io_to_abort = io; + abort_io->send_abts = false; + abort_io->abort_cb = cb; + abort_io->abort_cb_arg = arg; + +/* now dispatch IO */ + rc =efct_scsi_io_dispatch_abort (abort_io, efct_target_abort_cb); +if (rc) +kref_put (&io->ref, io->release); +return rc; +} + +void +efct_scsi_io_complete (struct efct_io *io) +{ +if (io->io_free) { +efc_log_test (io->efct, +"Got completion for non-busy io with tag 0x%x\n" , + io->tag); +return ; + } + +scsi_io_trace (io,"freeing io 0x%p %s\n" , io, io->display_name); +kref_put (&io->ref, io->release); +}
drivers/scsi/elx/efct/efct_scsi.h new file +235 -0
235 lines not on this page · raw message
Signature · 1 line
2.16.4
Re: [PATCH v3 23/31] elx: efct: SCSI IO handling routines
Quoted 53 lines · James Smart
This patch continues the efct driver population.
This patch adds driver definitions for:
Routines for SCSI transport IO alloc, build and send IO.Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>Reviewed-by Hannes Reinecke <[email protected]>---
v3:
Removed DIF related code which is not used.
Removed SCSI get property.--- drivers/scsi/elx/efct/efct_scsi.c | 1192 +++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_scsi.h | 235 ++++++++ 2 files changed, 1427 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_scsi.c create mode 100644 drivers/scsi/elx/efct/efct_scsi.hdrivers/scsi/elx/efct/efct_scsi.c new file +27
-0@@ -0,0 +1,1192 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.h" +#include "efct_els.h" +#include "efct_hw.h" + +#define enable_tsend_auto_resp (efct) 1 +#define enable_treceive_auto_resp (efct) 0 + +#define SCSI_IOFMT "[%04x][i:%04x t:%04x h:%04x]" + +#define scsi_io_printf (io, fmt, ...) \ + efc_log_debug(io->efct, "[%s]" SCSI_IOFMT fmt, \ + io->node->display_name, io->instance_index,\ + io->init_task_tag, io->tgt_task_tag, io->hw_tag, ##__VA_ARGS__) + +#define EFCT_LOG_ENABLE_SCSI_TRACE (efct) \ + (((efct) != NULL) ? (((efct)->logmask & (1U << 2)) != 0) : 0) + +#define scsi_io_trace (io, fmt, ...) \ + do { \ + if (EFCT_LOG_ENABLE_SCSI_TRACE(io->efct)) \ + scsi_io_printf(io, fmt, ##__VA_ARGS__); \
drivers/scsi/elx/efct/efct_scsi.c line 37
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ }while (0 ) + +/* Enable the SCSI and Transport IO allocations */ +void +efct_scsi_io_alloc_enable(struct efc *efc, struct efc_node *node) +{ + unsigned long flags = 0; + +spin_lock_irqsave (&node->active_ios_lock, flags); + node->io_alloc_enabled = true;
no need to indent
drivers/scsi/elx/efct/efct_scsi.c line 48
Quoted 11 lines
drivers/scsi/elx/efct/efct_scsi.c new file +11
-0+spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +/* Disable the SCSI and Transport IO allocations */ +void +efct_scsi_io_alloc_disable (struct efc *efc,struct efc_node *node) +{ +unsigned long flags =0 ; + +spin_lock_irqsave (&node->active_ios_lock, flags); + node->io_alloc_enabled = false;
no need to indent
Quoted 54 lines
drivers/scsi/elx/efct/efct_scsi.c new file +54
-0+spin_unlock_irqrestore (&node->active_ios_lock, flags); +} + +struct efct_io * +efct_scsi_io_alloc (struct efc_node *node,enum efct_scsi_io_role role) +{ +struct efct *efct; +struct efc *efcp; +struct efct_xport *xport; +struct efct_io *io; +unsigned long flags =0 ; + + efcp = node->efc; + efct = efcp->base; + + xport = efct->xport; + +spin_lock_irqsave (&node->active_ios_lock, flags); + +if (!node->io_alloc_enabled) { +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + + io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!io) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* initialize refcount */ +kref_init (&io->ref); + io->release = _efct_scsi_io_free; + +if (io->hio) { +efc_log_err (efct, +"assertion failed: io->hio is not NULL\n" ); +spin_unlock_irqrestore (&node->active_ios_lock, flags); +return NULL ; + } + +/* set generic fields */ + io->efct = efct; + io->node = node; + +/* set type and name */ + io->io_type =EFCT_IO_TYPE_IO ; + io->display_name ="scsi_io" ; + +switch (role) { +case EFCT_SCSI_IO_ROLE_ORIGINATOR : + io->cmd_ini = true; + io->cmd_tgt = false;
drivers/scsi/elx/efct/efct_scsi.c line 112
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+break ; +case EFCT_SCSI_IO_ROLE_RESPONDER : + io->cmd_ini = false; + io->cmd_tgt = true; +break ; + } + +/* Add to node's active_ios list */ +INIT_LIST_HEAD (&io->list_entry); +list_add_tail (&io->list_entry, &node->active_ios);
no need to indent
Quoted 16 lines
drivers/scsi/elx/efct/efct_scsi.c new file +16
-0+ +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +return io; +} + +void +_efct_scsi_io_free (struct kref *arg) +{ + struct efct_io *io = container_of(arg, struct efct_io, ref); +struct efct *efct = io->efct; +struct efc_node *node = io->node; +int send_empty_event; +unsigned long flags =0 ; + +scsi_io_trace (io,"freeing io 0x%p %s\n" , io, io->display_name);
drivers/scsi/elx/efct/efct_scsi.c line 138
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ +if (io->io_free) { +efc_log_err (efct,"IO already freed.\n" ); +return ; + } + +spin_lock_irqsave (&node->active_ios_lock, flags); +list_del (&io->list_entry); + send_empty_event = (!node->io_alloc_enabled) && +list_empty (&node->active_ios);
no need to indent
Quoted 28 lines
drivers/scsi/elx/efct/efct_scsi.c new file +28
-0+spin_unlock_irqrestore (&node->active_ios_lock, flags); + +if (send_empty_event) +efc_scsi_io_list_empty (node->efc, node); + + io->node =NULL ; +efct_io_pool_io_free (efct->xport->io_pool, io); +} + +void +efct_scsi_io_free (struct efct_io *io) +{ +scsi_io_trace (io,"freeing io 0x%p %s\n" , io, io->display_name); +WARN_ON (refcount_read (&io->ref.refcount) !=0 ); +kref_put (&io->ref, io->release); +} + +static void +efct_target_io_cb (struct efct_hw_io *hio,struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status scsi_stat =EFCT_SCSI_STATUS_GOOD ; + +if (!io || !io->efct) { +pr_err ("%s: IO can not be NULL\n" , __func__); +return ;
drivers/scsi/elx/efct/efct_scsi.c line 176
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ } + +scsi_io_trace (io,"status x%x ext_status x%x\n" , status, ext_status); + + efct = io->efct; + + io->transferred += length; + +/* Call target server completion */ +if (io->scsi_tgt_cb) {
move the following part into a function
Quoted 79 lines
drivers/scsi/elx/efct/efct_scsi.c new file +79
-0+efct_scsi_io_cb_t cb = io->scsi_tgt_cb; +u32 flags =0 ; + +/* Clear the callback before invoking the callback */ + io->scsi_tgt_cb =NULL ; + +/* if status was good, and auto-good-response was set, +* then callback target-server with IO_CMPL_RSP_SENT, +* otherwise send IO_CMPL +*/ +if (status ==0 && io->auto_resp) + flags |=EFCT_SCSI_IO_CMPL_RSP_SENT ; +else + flags |=EFCT_SCSI_IO_CMPL ; + +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : + scsi_stat =EFCT_SCSI_STATUS_GOOD ; +break ; +case SLI4_FC_WCQE_STATUS_DI_ERROR : +if (ext_status &SLI4_FC_DI_ERROR_GE ) + scsi_stat =EFCT_SCSI_STATUS_DIF_GUARD_ERR ; +else if (ext_status &SLI4_FC_DI_ERROR_AE ) + scsi_stat =EFCT_SCSI_STATUS_DIF_APP_TAG_ERROR ; +else if (ext_status &SLI4_FC_DI_ERROR_RE ) + scsi_stat =EFCT_SCSI_STATUS_DIF_REF_TAG_ERROR ; +else + scsi_stat =EFCT_SCSI_STATUS_DIF_UNKNOWN_ERROR ; +break ; +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_INVALID_RELOFFSET : +case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED : + scsi_stat =EFCT_SCSI_STATUS_ABORTED ; +break ; +case SLI4_FC_LOCAL_REJECT_INVALID_RPI : + scsi_stat =EFCT_SCSI_STATUS_NEXUS_LOST ; +break ; +case SLI4_FC_LOCAL_REJECT_NO_XRI : + scsi_stat =EFCT_SCSI_STATUS_NO_IO ; +break ; +default : +/*we have seen 0x0d(TX_DMA_FAILED err)*/ + scsi_stat =EFCT_SCSI_STATUS_ERROR ; +break ; + } +break ; + +case SLI4_FC_WCQE_STATUS_TARGET_WQE_TIMEOUT : +/* target IO timed out */ + scsi_stat =EFCT_SCSI_STATUS_TIMEDOUT_AND_ABORTED ; +break ; + +case SLI4_FC_WCQE_STATUS_SHUTDOWN : +/* Target IO cancelled by HW */ + scsi_stat =EFCT_SCSI_STATUS_SHUTDOWN ; +break ; + +default : + scsi_stat =EFCT_SCSI_STATUS_ERROR ; +break ; + } + +cb (io, scsi_stat, flags, io->scsi_tgt_cb_arg); + } +efct_scsi_check_pending (efct); +} + +static int +efct_scsi_build_sgls (struct efct_hw *hw,struct efct_hw_io *hio, +struct efct_scsi_sgl *sgl,u32 sgl_count, +enum efct_hw_io_type type) +{ +int rc; +u32 i; +struct efct *efct = hw->os; + +/* Initialize HW SGL */ + rc =efct_hw_io_init_sges (hw, hio, type);
drivers/scsi/elx/efct/efct_scsi.c line 265
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+if (rc) { +efc_log_err (efct,"efct_hw_io_init_sges failed: %d\n" , rc); +return EFC_FAIL ; + } + +for (i =0 ; i < sgl_count; i++) { + +/* Add data SGE */ + rc =efct_hw_io_add_sge (hw, hio, + sgl[i].addr, sgl[i].len);
fits on one line
Quoted 14 lines
drivers/scsi/elx/efct/efct_scsi.c new file +14
-0+if (rc) { +efc_log_err (efct, +"add sge failed cnt=%d rc=%d\n" , + sgl_count, rc); +return rc; + } + } + +return EFC_SUCCESS ; +} + +static void efc_log_sgl (struct efct_io *io) +{ +struct efct_hw_io *hio = io->hio;
drivers/scsi/elx/efct/efct_scsi.c line 289
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+struct sli4_sge *data =NULL ; +u32 *dword =NULL ; +u32 i; +u32 n_sge; + +scsi_io_trace (io,"def_sgl at 0x%x 0x%08x\n" , +upper_32_bits (hio->def_sgl.phys), +lower_32_bits (hio->def_sgl.phys)); + n_sge = (hio->sgl == &hio->def_sgl ? + hio->n_sge : hio->def_sgl_count);
fits on one line
Quoted 24 lines
drivers/scsi/elx/efct/efct_scsi.c new file +24
-0+for (i =0 , data = hio->def_sgl.virt; i < n_sge; i++, data++) { + dword = (u32 *)data; + +scsi_io_trace (io,"SGL %2d 0x%08x 0x%08x 0x%08x 0x%08x\n" , + i, dword[0 ], dword[1 ], dword[2 ], dword[3 ]); + +if (dword[2 ] & (1U <<31 )) +break ; + } + +} + +static int +efct_scsi_check_pending_async_cb (struct efct_hw *hw,int status, +u8 *mqe,void *arg) +{ +struct efct_io *io = arg; + +if (io) { +if (io->hw_cb) { +efct_hw_done_t cb = io->hw_cb; + + io->hw_cb =NULL ; + (cb)(io->hio, NULL, 0,
drivers/scsi/elx/efct/efct_scsi.c line 323
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ SLI4_FC_WCQE_STATUS_DISPATCH_ERROR, 0, io); + } + } +return EFC_SUCCESS ; +} + +static int +efct_scsi_io_dispatch_hw_io (struct efct_io *io,struct efct_hw_io *hio) +{ +int rc =0 ;
EFC_SUCCESS ?
Quoted 58 lines
drivers/scsi/elx/efct/efct_scsi.c new file +58
-0+struct efct *efct = io->efct; + +/* Got a HW IO; +* update ini/tgt_task_tag with HW IO info and dispatch +*/ + io->hio = hio; +if (io->cmd_tgt) + io->tgt_task_tag = hio->indicator; +else if (io->cmd_ini) + io->init_task_tag = hio->indicator; + io->hw_tag = hio->reqtag; + + hio->eq = io->hw_priv; + +/* Copy WQ steering */ +switch (io->wq_steering) { +case EFCT_SCSI_WQ_STEERING_CLASS >>EFCT_SCSI_WQ_STEERING_SHIFT : + hio->wq_steering =EFCT_HW_WQ_STEERING_CLASS ; +break ; +case EFCT_SCSI_WQ_STEERING_REQUEST >>EFCT_SCSI_WQ_STEERING_SHIFT : + hio->wq_steering =EFCT_HW_WQ_STEERING_REQUEST ; +break ; +case EFCT_SCSI_WQ_STEERING_CPU >>EFCT_SCSI_WQ_STEERING_SHIFT : + hio->wq_steering =EFCT_HW_WQ_STEERING_CPU ; +break ; + } + +switch (io->io_type) { +case EFCT_IO_TYPE_IO : + rc =efct_scsi_build_sgls (&efct->hw, io->hio, + io->sgl, io->sgl_count, io->hio_type); +if (rc) +break ; + +if (EFCT_LOG_ENABLE_SCSI_TRACE (efct)) +efc_log_sgl (io); + +if (io->app_id) + io->iparam.fcp_tgt.app_id = io->app_id; + + rc =efct_hw_io_send (&io->efct->hw, io->hio_type, io->hio, + io->wire_len, &io->iparam, + &io->node->rnode, io->hw_cb, io); +break ; +case EFCT_IO_TYPE_ELS : +case EFCT_IO_TYPE_CT : + rc =efct_hw_srrs_send (&efct->hw, io->hio_type, io->hio, + &io->els_req, io->wire_len, + &io->els_rsp, &io->node->rnode, &io->iparam, + io->hw_cb, io); +break ; +case EFCT_IO_TYPE_CT_RESP : + rc =efct_hw_srrs_send (&efct->hw, io->hio_type, io->hio, + &io->els_rsp, io->wire_len, +NULL , &io->node->rnode, &io->iparam, + io->hw_cb, io); +break ; +case EFCT_IO_TYPE_BLS_RESP :
drivers/scsi/elx/efct/efct_scsi.c line 391
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+/* no need to update tgt_task_tag for BLS response since +* the RX_ID will be specified by the payload, not the XRI +*/ + rc =efct_hw_srrs_send (&efct->hw, io->hio_type, io->hio, +NULL ,0 ,NULL , &io->node->rnode, + &io->iparam, io->hw_cb, io); +break ; +default : +scsi_io_printf (io,"Unknown IO type=%d\n" , io->io_type); + rc =-1 ;
error code
Quoted 23 lines
drivers/scsi/elx/efct/efct_scsi.c new file +23
-0+break ; + } +return rc; +} + +static int +efct_scsi_io_dispatch_no_hw_io (struct efct_io *io) +{ +int rc; + +switch (io->io_type) { +case EFCT_IO_TYPE_ABORT : { +struct efct_hw_io *hio_to_abort =NULL ; + + hio_to_abort = io->io_to_abort->hio; + +if (!hio_to_abort) { +/* +* If "IO to abort" does not have an +* associated HW IO, immediately make callback with +* success. The command must have been sent to +* the backend, but the data phase has not yet +* started, so we don't have a HW IO.
drivers/scsi/elx/efct/efct_scsi.c line 424
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+* +* Note: since the backend shims should be +* taking a reference on io_to_abort, it should not +* be possible to have been completed and freed by +* the backend before the abort got here. +*/ +scsi_io_printf (io,"IO: not active\n" ); + ((efct_hw_done_t )io->hw_cb)(io->hio,NULL ,0 , +SLI4_FC_WCQE_STATUS_SUCCESS ,0 , io); + rc =0 ;
same as in above function
Quoted 27 lines
drivers/scsi/elx/efct/efct_scsi.c new file +27
-0+ }else { +/* HW IO is valid, abort it */ +scsi_io_printf (io,"aborting\n" ); + rc =efct_hw_io_abort (&io->efct->hw, hio_to_abort, + io->send_abts, io->hw_cb, io); +if (rc) { +int status =SLI4_FC_WCQE_STATUS_SUCCESS ; + +if (rc !=EFCT_HW_RTN_IO_NOT_ACTIVE && + rc !=EFCT_HW_RTN_IO_ABORT_IN_PROGRESS ) { + status =-1 ; +scsi_io_printf (io, +"Failed to abort IO: status=%d\n" , + rc); + } + ((efct_hw_done_t )io->hw_cb)(io->hio, +NULL ,0 , status,0 , io); + rc =0 ; + } + } + +break ; + } +default : +scsi_io_printf (io,"Unknown IO type=%d\n" , io->io_type); + rc =-1 ; +break ;
drivers/scsi/elx/efct/efct_scsi.c line 461
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ } +return rc; +} + +/** +* Check for pending IOs to dispatch. +* +* If there are IOs on the pending list, and a HW IO is available, then +* dispatch the IOs. +*/
proper kerneldoc style?
Quoted 18 lines
drivers/scsi/elx/efct/efct_scsi.c new file +18
-0+void +efct_scsi_check_pending (struct efct *efct) +{ +struct efct_xport *xport = efct->xport; +struct efct_io *io =NULL ; +struct efct_hw_io *hio; +int status; +int count =0 ; +int dispatch; +unsigned long flags =0 ; + +/* Guard against recursion */ +if (atomic_add_return (1 , &xport->io_pending_recursing)) { +/* This function is already running. Decrement and return. */ +atomic_sub_return (1 , &xport->io_pending_recursing); +return ; + } +
drivers/scsi/elx/efct/efct_scsi.c line 489
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ do { + spin_lock_irqsave(&xport->io_pending_lock, flags); + status = 0; + hio = NULL; + if (!list_empty(&xport->io_pending_list)) { + io = list_first_entry(&xport->io_pending_list, + struct efct_io, + io_pending_link); + } + if (io) {
Couldn't this part of the above if body? Could be io == NULL when popped from the list?
drivers/scsi/elx/efct/efct_scsi.c line 490
Quoted 1 line
drivers/scsi/elx/efct/efct_scsi.c new file +1
-0+list_del (&io->io_pending_link);
This says no
Quoted 38 lines
drivers/scsi/elx/efct/efct_scsi.c new file +38
-0+if (io->io_type ==EFCT_IO_TYPE_ABORT ) { + hio =NULL ; + }else { + hio =efct_hw_io_alloc (&efct->hw); +if (!hio) { +/* +* No HW IO available.Put IO back on +* the front of pending list +*/ +list_add (&xport->io_pending_list, + &io->io_pending_link); + io =NULL ; + }else { + hio->eq = io->hw_priv; + } + } + } +/* Must drop the lock before dispatching the IO */ +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +if (io) { + count++; + +/* +* We pulled an IO off the pending list, +* and either got an HW IO or don't need one +*/ +atomic_sub_return (1 , &xport->io_pending_count); +if (!hio) + status =efct_scsi_io_dispatch_no_hw_io (io); +else + status =efct_scsi_io_dispatch_hw_io (io, hio); +if (status) { +/* +* Invoke the HW callback, but do so in the +* separate execution context,provided by the +* NOP mailbox completion processing context +* by using efct_hw_async_call()
drivers/scsi/elx/efct/efct_scsi.c line 538
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+*/ +if (efct_hw_async_call (&efct->hw, + efct_scsi_check_pending_async_cb, + io)) { +efc_log_test (efct, +"call hw async failed\n" ); + } + } + } + }while (io);
This function is a bit long, I think it would be good to split it up.
Quoted 50 lines
drivers/scsi/elx/efct/efct_scsi.c new file +50
-0+ +/* +* If nothing was removed from the list, +* we might be in a case where we need to abort an +* active IO and the abort is on the pending list. +* Look for an abort we can dispatch. +*/ +if (count ==0 ) { + dispatch =0 ; + +spin_lock_irqsave (&xport->io_pending_lock, flags); +list_for_each_entry (io, &xport->io_pending_list, + io_pending_link) { +if (io->io_type ==EFCT_IO_TYPE_ABORT ) { +if (io->io_to_abort->hio) { +/* This IO has a HW IO, so it is +* active. Dispatch the abort. +*/ + dispatch =1 ; + }else { +/* Leave this abort on the pending +* list and keep looking +*/ + dispatch =0 ; + } + } +if (dispatch) { +list_del (&io->io_pending_link); +atomic_sub_return (1 , &xport->io_pending_count); +break ; + } + } +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +if (dispatch) { + status =efct_scsi_io_dispatch_no_hw_io (io); +if (status) { +if (efct_hw_async_call (&efct->hw, + efct_scsi_check_pending_async_cb, + io)) { +efc_log_test (efct, +"call to hw async failed\n" ); + } + } + } + } + +atomic_sub_return (1 , &xport->io_pending_recursing); +} +
drivers/scsi/elx/efct/efct_scsi.c line 598
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+/** +* An IO is dispatched: +* - if the pending list is not empty, add IO to pending list +* and call a function to process the pending list. +* - if pending list is empty, try to allocate a HW IO. If none +* is available, place this IO at the tail of the pending IO +* list. +* - if HW IO is available, attach this IO to the HW IO and +* submit it. +*/
proper kerneldoc style?
Quoted 36 lines
drivers/scsi/elx/efct/efct_scsi.c new file +36
-0+int +efct_scsi_io_dispatch (struct efct_io *io,void *cb) +{ +struct efct_hw_io *hio; +struct efct *efct = io->efct; +struct efct_xport *xport = efct->xport; +unsigned long flags =0 ; + + io->hw_cb = cb; + +/* +* if this IO already has a HW IO, then this is either +* not the first phase of the IO. Send it to the HW. +*/ +if (io->hio) +return efct_scsi_io_dispatch_hw_io (io, io->hio); + +/* +* We don't already have a HW IO associated with the IO. First check +* the pending list. If not empty, add IO to the tail and process the +* pending list. +*/ +spin_lock_irqsave (&xport->io_pending_lock, flags); +if (!list_empty (&xport->io_pending_list)) { +/* +* If this is a low latency request, +* the put at the front of the IO pending +* queue, otherwise put it at the end of the queue. +*/ +if (io->low_latency) { +INIT_LIST_HEAD (&io->io_pending_link); +list_add (&xport->io_pending_list, + &io->io_pending_link); + }else { +INIT_LIST_HEAD (&io->io_pending_link); + list_add_tail(&io->io_pending_link,
drivers/scsi/elx/efct/efct_scsi.c line 644
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ &xport->io_pending_list); + } +spin_unlock_irqrestore (&xport->io_pending_lock, flags); +atomic_add_return (1 , &xport->io_pending_count); +atomic_add_return (1 , &xport->io_total_pending); + +/* process pending list */ +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; + }
no need to indent
Quoted 19 lines
drivers/scsi/elx/efct/efct_scsi.c new file +19
-0+spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +/* +* We don't have a HW IO associated with the IO and there's nothing +* on the pending list. Attempt to allocate a HW IO and dispatch it. +*/ + hio =efct_hw_io_alloc (&io->efct->hw); +if (!hio) { +/* Couldn't get a HW IO. Save this IO on the pending list */ +spin_lock_irqsave (&xport->io_pending_lock, flags); +INIT_LIST_HEAD (&io->io_pending_link); +list_add_tail (&io->io_pending_link, &xport->io_pending_list); +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +atomic_add_return (1 , &xport->io_total_pending); +atomic_add_return (1 , &xport->io_pending_count); +return EFC_SUCCESS ; + } +
drivers/scsi/elx/efct/efct_scsi.c line 673
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+/* We successfully allocated a HW IO; dispatch to HW */ +return efct_scsi_io_dispatch_hw_io (io, hio); +} + +/** +* An Abort IO is dispatched: +* - if the pending list is not empty, add IO to pending list +* and call a function to process the pending list. +* - if pending list is empty, send abort to the HW. +*/
not proper kerneldoc style
Quoted 19 lines
drivers/scsi/elx/efct/efct_scsi.c new file +19
-0+ +int +efct_scsi_io_dispatch_abort (struct efct_io *io,void *cb) +{ +struct efct *efct = io->efct; +struct efct_xport *xport = efct->xport; +unsigned long flags =0 ; + + io->hw_cb = cb; + +/* +* For aborts, we don't need a HW IO, but we still want +* to pass through the pending list to preserve ordering. +* Thus, if the pending list is not empty, add this abort +* to the pending list and process the pending list. +*/ +spin_lock_irqsave (&xport->io_pending_lock, flags); +if (!list_empty (&xport->io_pending_list)) { +INIT_LIST_HEAD (&io->io_pending_link);
drivers/scsi/elx/efct/efct_scsi.c line 702
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+list_add_tail (&io->io_pending_link, + &xport->io_pending_list); +spin_unlock_irqrestore (&xport->io_pending_lock, flags); +atomic_add_return (1 , &xport->io_pending_count); +atomic_add_return (1 , &xport->io_total_pending); + +/* process pending list */ +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; + }
no need to indent
Quoted 35 lines
drivers/scsi/elx/efct/efct_scsi.c new file +35
-0+spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +/* nothing on pending list, dispatch abort */ +return efct_scsi_io_dispatch_no_hw_io (io); +} + +static inline int +efct_scsi_xfer_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count,u64 xwire_len, +enum efct_hw_io_type type,int enable_ar, +efct_scsi_io_cb_t cb,void *arg) +{ +struct efct *efct; +size_t residual =0 ; + + io->sgl_count = sgl_count; + + efct = io->efct; + +scsi_io_trace (io,"%s wire_len %llu\n" , + (type ==EFCT_HW_IO_TARGET_READ ) ?"send" :"recv" , + xwire_len); + + io->hio_type = type; + + io->scsi_tgt_cb = cb; + io->scsi_tgt_cb_arg = arg; + + residual = io->exp_xfer_len - io->transferred; + io->wire_len = (xwire_len < residual) ? xwire_len : residual; + residual = (xwire_len - io->wire_len); + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.fcp_tgt.ox_id = io->init_task_tag; + io->iparam.fcp_tgt.offset = io->transferred;
drivers/scsi/elx/efct/efct_scsi.c line 747
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; + io->iparam.fcp_tgt.timeout = io->timeout; + +/* if this is the last data phase and there is no residual, enable +* auto-good-response +*/ +if (enable_ar && (flags &EFCT_SCSI_LAST_DATAPHASE ) && + residual ==0 && + ((io->transferred + io->wire_len) == io->exp_xfer_len) && + (!(flags &EFCT_SCSI_NO_AUTO_RESPONSE ))) {
This should be reformated in a proper way.
Quoted 158 lines
drivers/scsi/elx/efct/efct_scsi.c new file +158
-0+ io->iparam.fcp_tgt.flags |=SLI4_IO_AUTO_GOOD_RESPONSE ; + io->auto_resp = true; + }else { + io->auto_resp = false; + } + +/* save this transfer length */ + io->xfer_req = io->wire_len; + +/* Adjust the transferred count to account for overrun +* when the residual is calculated in efct_scsi_send_resp +*/ + io->transferred += residual; + +/* Adjust the SGL size if there is overrun */ + +if (residual) { +struct efct_scsi_sgl *sgl_ptr = &io->sgl[sgl_count -1 ]; + +while (residual) { +size_t len = sgl_ptr->len; + +if (len > residual) { + sgl_ptr->len = len - residual; + residual =0 ; + }else { + sgl_ptr->len =0 ; + residual -= len; + io->sgl_count--; + } + sgl_ptr--; + } + } + +/* Set latency and WQ steering */ + io->low_latency = (flags &EFCT_SCSI_LOW_LATENCY ) !=0 ; + io->wq_steering = (flags &EFCT_SCSI_WQ_STEERING_MASK ) >> +EFCT_SCSI_WQ_STEERING_SHIFT ; + io->wq_class = (flags &EFCT_SCSI_WQ_CLASS_MASK ) >> +EFCT_SCSI_WQ_CLASS_SHIFT ; + +if (efct->xport) { +struct efct_xport *xport = efct->xport; + +if (type ==EFCT_HW_IO_TARGET_READ ) { + xport->fcp_stats.input_requests++; + xport->fcp_stats.input_bytes += xwire_len; + }else if (type ==EFCT_HW_IO_TARGET_WRITE ) { + xport->fcp_stats.output_requests++; + xport->fcp_stats.output_bytes += xwire_len; + } + } +return efct_scsi_io_dispatch (io, efct_target_io_cb); +} + +int +efct_scsi_send_rd_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count,u64 len, +efct_scsi_io_cb_t cb,void *arg) +{ +return efct_scsi_xfer_data (io, flags, sgl, sgl_count, + len,EFCT_HW_IO_TARGET_READ , +enable_tsend_auto_resp (io->efct), cb, arg); +} + +int +efct_scsi_recv_wr_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count,u64 len, +efct_scsi_io_cb_t cb,void *arg) +{ +return efct_scsi_xfer_data (io, flags, sgl, sgl_count, len, +EFCT_HW_IO_TARGET_WRITE , +enable_treceive_auto_resp (io->efct), cb, arg); +} + +int +efct_scsi_send_resp (struct efct_io *io,u32 flags, +struct efct_scsi_cmd_resp *rsp, +efct_scsi_io_cb_t cb,void *arg) +{ +struct efct *efct; +int residual; +bool auto_resp = true;/* Always try auto resp */ +u8 scsi_status =0 ; +u16 scsi_status_qualifier =0 ; +u8 *sense_data =NULL ; +u32 sense_data_length =0 ; + + efct = io->efct; + +if (rsp) { + scsi_status = rsp->scsi_status; + scsi_status_qualifier = rsp->scsi_status_qualifier; + sense_data = rsp->sense_data; + sense_data_length = rsp->sense_data_length; + residual = rsp->residual; + }else { + residual = io->exp_xfer_len - io->transferred; + } + + io->wire_len =0 ; + io->hio_type =EFCT_HW_IO_TARGET_RSP ; + + io->scsi_tgt_cb = cb; + io->scsi_tgt_cb_arg = arg; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.fcp_tgt.ox_id = io->init_task_tag; + io->iparam.fcp_tgt.offset =0 ; + io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; + io->iparam.fcp_tgt.timeout = io->timeout; + +/* Set low latency queueing request */ + io->low_latency = (flags &EFCT_SCSI_LOW_LATENCY ) !=0 ; + io->wq_steering = (flags &EFCT_SCSI_WQ_STEERING_MASK ) >> +EFCT_SCSI_WQ_STEERING_SHIFT ; + io->wq_class = (flags &EFCT_SCSI_WQ_CLASS_MASK ) >> +EFCT_SCSI_WQ_CLASS_SHIFT ; + +if (scsi_status !=0 || residual || sense_data_length) { +struct fcp_resp_with_ext *fcprsp = io->rspbuf.virt; +u8 *sns_data = io->rspbuf.virt +sizeof (*fcprsp); + +if (!fcprsp) { +efc_log_err (efct,"NULL response buffer\n" ); +return EFC_FAIL ; + } + + auto_resp = false; + +memset (fcprsp,0 ,sizeof (*fcprsp)); + + io->wire_len +=sizeof (*fcprsp); + + fcprsp->resp.fr_status = scsi_status; + fcprsp->resp.fr_retry_delay = +cpu_to_be16 (scsi_status_qualifier); + +/* set residual status if necessary */ +if (residual !=0 ) { +/* FCP: if data transferred is less than the +* amount expected, then this is an underflow. +* If data transferred would have been greater +* than the amount expected this is an overflow +*/ +if (residual >0 ) { + fcprsp->resp.fr_flags |=FCP_RESID_UNDER ; + fcprsp->ext.fr_resid =cpu_to_be32 (residual); + }else { + fcprsp->resp.fr_flags |=FCP_RESID_OVER ; + fcprsp->ext.fr_resid =cpu_to_be32 (-residual); + } + } + +if (EFCT_SCSI_SNS_BUF_VALID (sense_data) && sense_data_length) { +if (sense_data_length >SCSI_SENSE_BUFFERSIZE ) { +efc_log_err (efct,"Sense exceeds max size.\n" ); +return EFC_FAIL ;
drivers/scsi/elx/efct/efct_scsi.c line 915
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ } + + fcprsp->resp.fr_flags |=FCP_SNS_LEN_VAL ; +memcpy (sns_data, sense_data, sense_data_length); + fcprsp->ext.fr_sns_len =cpu_to_be32 (sense_data_length); + io->wire_len += sense_data_length; + } + + io->sgl[0 ].addr = io->rspbuf.phys; +//io->sgl[0].dif_addr = 0;
debug left over
Quoted 75 lines
drivers/scsi/elx/efct/efct_scsi.c new file +75
-0+ io->sgl[0 ].len = io->wire_len; + io->sgl_count =1 ; + } + +if (auto_resp) + io->iparam.fcp_tgt.flags |=SLI4_IO_AUTO_GOOD_RESPONSE ; + +return efct_scsi_io_dispatch (io, efct_target_io_cb); +} + +static int +efct_target_bls_resp_cb (struct efct_hw_io *hio, +struct efc_remote_node *rnode, +u32 length,int status,u32 ext_status,void *app) +{ +struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status bls_status; + + efct = io->efct; + +/* BLS isn't really a "SCSI" concept, but use SCSI status */ +if (status) { +io_error_log (io,"s=%#x x=%#x\n" , status, ext_status); + bls_status =EFCT_SCSI_STATUS_ERROR ; + }else { + bls_status =EFCT_SCSI_STATUS_GOOD ; + } + +if (io->bls_cb) { +efct_scsi_io_cb_t bls_cb = io->bls_cb; +void *bls_cb_arg = io->bls_cb_arg; + + io->bls_cb =NULL ; + io->bls_cb_arg =NULL ; + +/* invoke callback */ +bls_cb (io, bls_status,0 , bls_cb_arg); + } + +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; +} + +static int +efct_target_send_bls_resp (struct efct_io *io, +efct_scsi_io_cb_t cb,void *arg) +{ +int rc; +struct fc_ba_acc *acc; + +/* fill out IO structure with everything needed to send BA_ACC */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.bls.ox_id = io->init_task_tag; + io->iparam.bls.rx_id = io->abort_rx_id; + + acc = (void *)io->iparam.bls.payload; + +memset (io->iparam.bls.payload,0 , +sizeof (io->iparam.bls.payload)); + acc->ba_ox_id =cpu_to_be16 (io->iparam.bls.ox_id); + acc->ba_rx_id =cpu_to_be16 (io->iparam.bls.rx_id); + acc->ba_high_seq_cnt =cpu_to_be16 (U16_MAX ); + +/* generic io fields have already been populated */ + +/* set type and BLS-specific fields */ + io->io_type =EFCT_IO_TYPE_BLS_RESP ; + io->display_name ="bls_rsp" ; + io->hio_type =EFCT_HW_BLS_ACC ; + io->bls_cb = cb; + io->bls_cb_arg = arg; + +/* dispatch IO */ + rc =efct_scsi_io_dispatch (io, efct_target_bls_resp_cb);
drivers/scsi/elx/efct/efct_scsi.c line 1000
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+return rc; +} + +int +efct_scsi_send_tmf_resp (struct efct_io *io, +enum efct_scsi_tmf_resp rspcode, +u8 addl_rsp_info[3 ], +efct_scsi_io_cb_t cb,void *arg) +{ +int rc =-1 ;
again the error code topic.
Quoted 74 lines
drivers/scsi/elx/efct/efct_scsi.c new file +74
-0+struct fcp_resp_with_ext *fcprsp =NULL ; +struct fcp_resp_rsp_info *rspinfo =NULL ; +u8 fcp_rspcode; + + io->wire_len =0 ; + +switch (rspcode) { +case EFCT_SCSI_TMF_FUNCTION_COMPLETE : + fcp_rspcode =FCP_TMF_CMPL ; +break ; +case EFCT_SCSI_TMF_FUNCTION_SUCCEEDED : +case EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND : + fcp_rspcode =FCP_TMF_CMPL ; +break ; +case EFCT_SCSI_TMF_FUNCTION_REJECTED : + fcp_rspcode =FCP_TMF_REJECTED ; +break ; +case EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER : + fcp_rspcode =FCP_TMF_INVALID_LUN ; +break ; +case EFCT_SCSI_TMF_SERVICE_DELIVERY : + fcp_rspcode =FCP_TMF_FAILED ; +break ; +default : + fcp_rspcode =FCP_TMF_REJECTED ; +break ; + } + + io->hio_type =EFCT_HW_IO_TARGET_RSP ; + + io->scsi_tgt_cb = cb; + io->scsi_tgt_cb_arg = arg; + +if (io->tmf_cmd ==EFCT_SCSI_TMF_ABORT_TASK ) { + rc =efct_target_send_bls_resp (io, cb, arg); +return rc; + } + +/* populate the FCP TMF response */ + fcprsp = io->rspbuf.virt; +memset (fcprsp,0 ,sizeof (*fcprsp)); + + fcprsp->resp.fr_flags |=FCP_SNS_LEN_VAL ; + + rspinfo = io->rspbuf.virt +sizeof (*fcprsp); +if (addl_rsp_info) { +memcpy (rspinfo->_fr_resvd, addl_rsp_info, +sizeof (rspinfo->_fr_resvd)); + } + rspinfo->rsp_code = fcp_rspcode; + + io->wire_len =sizeof (*fcprsp) +sizeof (*rspinfo); + + fcprsp->ext.fr_rsp_len =cpu_to_be32 (sizeof (*rspinfo)); + + io->sgl[0 ].addr = io->rspbuf.phys; + io->sgl[0 ].dif_addr =0 ; + io->sgl[0 ].len = io->wire_len; + io->sgl_count =1 ; + +memset (&io->iparam,0 ,sizeof (io->iparam)); + io->iparam.fcp_tgt.ox_id = io->init_task_tag; + io->iparam.fcp_tgt.offset =0 ; + io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; + io->iparam.fcp_tgt.timeout = io->timeout; + + rc =efct_scsi_io_dispatch (io, efct_target_io_cb); + +return rc; +} + +static int +efct_target_abort_cb(struct efct_hw_io *hio, + struct efc_remote_node *rnode,
drivers/scsi/elx/efct/efct_scsi.c line 1084
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+ u32 length, int status, + u32 ext_status, void *app) +{ + struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status scsi_status; + + efct = io->efct; + +if (io->abort_cb) {
I would move follwing part again into new function.
Quoted 48 lines
drivers/scsi/elx/efct/efct_scsi.c new file +48
-0+efct_scsi_io_cb_t abort_cb = io->abort_cb; +void *abort_cb_arg = io->abort_cb_arg; + + io->abort_cb =NULL ; + io->abort_cb_arg =NULL ; + +switch (status) { +case SLI4_FC_WCQE_STATUS_SUCCESS : + scsi_status =EFCT_SCSI_STATUS_GOOD ; +break ; +case SLI4_FC_WCQE_STATUS_LOCAL_REJECT : +switch (ext_status) { +case SLI4_FC_LOCAL_REJECT_NO_XRI : + scsi_status =EFCT_SCSI_STATUS_NO_IO ; +break ; +case SLI4_FC_LOCAL_REJECT_ABORT_IN_PROGRESS : + scsi_status = +EFCT_SCSI_STATUS_ABORT_IN_PROGRESS ; +break ; +default : +/*we have seen 0x15 (abort in progress)*/ + scsi_status =EFCT_SCSI_STATUS_ERROR ; +break ; + } +break ; +case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE : + scsi_status =EFCT_SCSI_STATUS_CHECK_RESPONSE ; +break ; +default : + scsi_status =EFCT_SCSI_STATUS_ERROR ; +break ; + } +/* invoke callback */ +abort_cb (io->io_to_abort, scsi_status,0 , abort_cb_arg); + } + +/* done with IO to abort,efct_ref_get(): efct_scsi_tgt_abort_io() */ +kref_put (&io->io_to_abort->ref, io->io_to_abort->release); + +efct_io_pool_io_free (efct->xport->io_pool, io); + +efct_scsi_check_pending (efct); +return EFC_SUCCESS ; +} + +int +efct_scsi_tgt_abort_io (struct efct_io *io,efct_scsi_io_cb_t cb,void *arg) +{
drivers/scsi/elx/efct/efct_scsi.c line 1142
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+struct efct *efct; +struct efct_xport *xport; +int rc; +struct efct_io *abort_io =NULL ; + + efct = io->efct; + xport = efct->xport; + +/* take a reference on IO being aborted */ +if ((kref_get_unless_zero (&io->ref) ==0 )) {
the double brackets are not needed
Quoted 34 lines
drivers/scsi/elx/efct/efct_scsi.c new file +34
-0+/* command no longer active */ +scsi_io_printf (io,"command no longer active\n" ); +return EFC_FAIL ; + } + +/* +* allocate a new IO to send the abort request. Use efct_io_alloc() +* directly, as we need an IO object that will not fail allocation +* due to allocations being disabled (in efct_scsi_io_alloc()) +*/ + abort_io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!abort_io) { +atomic_add_return (1 , &xport->io_alloc_failed_count); +kref_put (&io->ref, io->release); +return EFC_FAIL ; + } + +/* Save the target server callback and argument */ +/* set generic fields */ + abort_io->cmd_tgt = true; + abort_io->node = io->node; + +/* set type and abort-specific fields */ + abort_io->io_type =EFCT_IO_TYPE_ABORT ; + abort_io->display_name ="tgt_abort" ; + abort_io->io_to_abort = io; + abort_io->send_abts = false; + abort_io->abort_cb = cb; + abort_io->abort_cb_arg = arg; + +/* now dispatch IO */ + rc =efct_scsi_io_dispatch_abort (abort_io, efct_target_abort_cb); +if (rc) +kref_put (&io->ref, io->release);
drivers/scsi/elx/efct/efct_scsi.c line 1186
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.c new file +10
-0+return rc; +} + +void +efct_scsi_io_complete (struct efct_io *io) +{ +if (io->io_free) { +efc_log_test (io->efct, +"Got completion for non-busy io with tag 0x%x\n" , + io->tag);
code aligment
Quoted 47 lines
drivers/scsi/elx/efct/efct_scsi.c new file +6
-0+return ; + } + +scsi_io_trace (io,"freeing io 0x%p %s\n" , io, io->display_name); +kref_put (&io->ref, io->release); +}drivers/scsi/elx/efct/efct_scsi.h new file +35
-0@@ -0,0 +1,235 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__EFCT_SCSI_H__) +#define __EFCT_SCSI_H__ +#include <scsi/scsi_host.h> +#include <scsi/scsi_transport_fc.h> + +/* efct_scsi_rcv_cmd() efct_scsi_rcv_tmf() flags */ +#define EFCT_SCSI_CMD_DIR_IN (1 << 0) +#define EFCT_SCSI_CMD_DIR_OUT (1 << 1) +#define EFCT_SCSI_CMD_SIMPLE (1 << 2) +#define EFCT_SCSI_CMD_HEAD_OF_QUEUE (1 << 3) +#define EFCT_SCSI_CMD_ORDERED (1 << 4) +#define EFCT_SCSI_CMD_UNTAGGED (1 << 5) +#define EFCT_SCSI_CMD_ACA (1 << 6) +#define EFCT_SCSI_FIRST_BURST_ERR (1 << 7) +#define EFCT_SCSI_FIRST_BURST_ABORTED (1 << 8) + +/* efct_scsi_send_rd_data/recv_wr_data/send_resp flags */ +#define EFCT_SCSI_LAST_DATAPHASE (1 << 0) +#define EFCT_SCSI_NO_AUTO_RESPONSE (1 << 1) +#define EFCT_SCSI_LOW_LATENCY (1 << 2) + +#define EFCT_SCSI_SNS_BUF_VALID (sense) ((sense) && \ + (0x70 == (((const u8 *)(sense))[0] & 0x70))) + +#define EFCT_SCSI_WQ_STEERING_SHIFT 16 +#define EFCT_SCSI_WQ_STEERING_MASK (0xf << EFCT_SCSI_WQ_STEERING_SHIFT) +#define EFCT_SCSI_WQ_STEERING_CLASS (0 << EFCT_SCSI_WQ_STEERING_SHIFT) +#define EFCT_SCSI_WQ_STEERING_REQUEST (1 << EFCT_SCSI_WQ_STEERING_SHIFT) +#define EFCT_SCSI_WQ_STEERING_CPU (2 << EFCT_SCSI_WQ_STEERING_SHIFT)
drivers/scsi/elx/efct/efct_scsi.h line 45
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.h new file +10
-0+ +#define EFCT_SCSI_WQ_CLASS_SHIFT (20) +#define EFCT_SCSI_WQ_CLASS_MASK (0xf << EFCT_SCSI_WQ_CLASS_SHIFT) +#define EFCT_SCSI_WQ_CLASS (x) ((x & EFCT_SCSI_WQ_CLASS_MASK) << \ + EFCT_SCSI_WQ_CLASS_SHIFT) + +#define EFCT_SCSI_WQ_CLASS_LOW_LATENCY 1 + +struct efct_scsi_cmd_resp { +u8 scsi_status;/* SCSI status */
kerneldoc
Quoted 126 lines
drivers/scsi/elx/efct/efct_scsi.h new file +126
-0+u16 scsi_status_qualifier;/* SCSI status qualifier */ +/* pointer to response data buffer */ +u8 *response_data; +/* length of response data buffer (bytes) */ +u32 response_data_length; +u8 *sense_data;/* pointer to sense data buffer */ +/* length of sense data buffer (bytes) */ +u32 sense_data_length; +/* command residual (not used for target), positive value +* indicates an underflow, negative value indicates overflow +*/ +int residual; +/* Command response length received in wcqe */ +u32 response_wire_length; +}; + +struct efct_vport { +struct efct *efct; +bool is_vport; +struct fc_host_statistics fc_host_stats; +struct Scsi_Host *shost; +struct fc_vport *fc_vport; +u64 npiv_wwpn; +u64 npiv_wwnn; +}; + +/* Status values returned by IO callbacks */ +enum efct_scsi_io_status { +EFCT_SCSI_STATUS_GOOD =0 , +EFCT_SCSI_STATUS_ABORTED , +EFCT_SCSI_STATUS_ERROR , +EFCT_SCSI_STATUS_DIF_GUARD_ERR , +EFCT_SCSI_STATUS_DIF_REF_TAG_ERROR , +EFCT_SCSI_STATUS_DIF_APP_TAG_ERROR , +EFCT_SCSI_STATUS_DIF_UNKNOWN_ERROR , +EFCT_SCSI_STATUS_PROTOCOL_CRC_ERROR , +EFCT_SCSI_STATUS_NO_IO , +EFCT_SCSI_STATUS_ABORT_IN_PROGRESS , +EFCT_SCSI_STATUS_CHECK_RESPONSE , +EFCT_SCSI_STATUS_COMMAND_TIMEOUT , +EFCT_SCSI_STATUS_TIMEDOUT_AND_ABORTED , +EFCT_SCSI_STATUS_SHUTDOWN , +EFCT_SCSI_STATUS_NEXUS_LOST , +}; + +struct efct_io ; +struct efc_node ; +struct efc_domain ; +struct efc_sli_port ; + +/* Callback used by send_rd_data(), recv_wr_data(), send_resp() */ +typedef int (*efct_scsi_io_cb_t )(struct efct_io *io, +enum efct_scsi_io_status status, +u32 flags,void *arg); + +/* Callback used by send_rd_io(), send_wr_io() */ +typedef int (*efct_scsi_rsp_io_cb_t )(struct efct_io *io, +enum efct_scsi_io_status status, +struct efct_scsi_cmd_resp *rsp, +u32 flags,void *arg); + +/* efct_scsi_cb_t flags */ +#define EFCT_SCSI_IO_CMPL (1 << 0) +/* IO completed, response sent */ +#define EFCT_SCSI_IO_CMPL_RSP_SENT (1 << 1) +#define EFCT_SCSI_IO_ABORTED (1 << 2) + +/* efct_scsi_recv_tmf() request values */ +enum efct_scsi_tmf_cmd { +EFCT_SCSI_TMF_ABORT_TASK =1 , +EFCT_SCSI_TMF_QUERY_TASK_SET , +EFCT_SCSI_TMF_ABORT_TASK_SET , +EFCT_SCSI_TMF_CLEAR_TASK_SET , +EFCT_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT , +EFCT_SCSI_TMF_LOGICAL_UNIT_RESET , +EFCT_SCSI_TMF_CLEAR_ACA , +EFCT_SCSI_TMF_TARGET_RESET , +}; + +/* efct_scsi_send_tmf_resp() response values */ +enum efct_scsi_tmf_resp { +EFCT_SCSI_TMF_FUNCTION_COMPLETE =1 , +EFCT_SCSI_TMF_FUNCTION_SUCCEEDED , +EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND , +EFCT_SCSI_TMF_FUNCTION_REJECTED , +EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER , +EFCT_SCSI_TMF_SERVICE_DELIVERY , +}; + +struct efct_scsi_sgl { +uintptr_t addr; +uintptr_t dif_addr; +size_t len; +}; + +/* Return values for calls from base driver to libefc */ +#define EFCT_SCSI_CALL_COMPLETE 0/* All work is done */ +#define EFCT_SCSI_CALL_ASYNC 1/* Work will be completed asynchronously */ + +enum efct_scsi_io_role { +EFCT_SCSI_IO_ROLE_ORIGINATOR , +EFCT_SCSI_IO_ROLE_RESPONDER , +}; + +void efct_scsi_io_alloc_enable (struct efc *efc,struct efc_node *node); +void efct_scsi_io_alloc_disable (struct efc *efc,struct efc_node *node); +extern struct efct_io * +efct_scsi_io_alloc (struct efc_node *node,enum efct_scsi_io_role ); +void efct_scsi_io_free (struct efct_io *io); +struct efct_io *efct_io_get_instance (struct efct *efct,u32 index); + +int efct_scsi_tgt_driver_init (void ); +int efct_scsi_tgt_driver_exit (void ); +int efct_scsi_tgt_new_device (struct efct *efct); +int efct_scsi_tgt_del_device (struct efct *efct); +int +efct_scsi_tgt_new_domain (struct efc *efc,struct efc_domain *domain); +void +efct_scsi_tgt_del_domain (struct efc *efc,struct efc_domain *domain); +int +efct_scsi_tgt_new_sport (struct efc *efc,struct efc_sli_port *sport); +void +efct_scsi_tgt_del_sport (struct efc *efc,struct efc_sli_port *sport); +int +efct_scsi_validate_initiator (struct efc *efc,struct efc_node *node); +int
drivers/scsi/elx/efct/efct_scsi.h line 181
Quoted 10 lines
drivers/scsi/elx/efct/efct_scsi.h new file +10
-0+efct_scsi_new_initiator(struct efc *efc, struct efc_node *node); + +enum efct_scsi_del_initiator_reason { +EFCT_SCSI_INITIATOR_DELETED , +EFCT_SCSI_INITIATOR_MISSING , +}; + +extern int +efct_scsi_del_initiator (struct efc *efc,struct efc_node *node, +int reason);
extern not needed
Quoted 58 lines
drivers/scsi/elx/efct/efct_scsi.h new file +54
-0+extern int +efct_scsi_recv_cmd (struct efct_io *io,uint64_t lun,u8 *cdb, +u32 cdb_len,u32 flags); +extern int +efct_scsi_recv_tmf (struct efct_io *tmfio,u32 lun, +enum efct_scsi_tmf_cmd cmd,struct efct_io *abortio, +u32 flags); + +extern int +efct_scsi_send_rd_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count, +u64 wire_len,efct_scsi_io_cb_t cb,void *arg); +extern int +efct_scsi_recv_wr_data (struct efct_io *io,u32 flags, +struct efct_scsi_sgl *sgl,u32 sgl_count, +u64 wire_len,efct_scsi_io_cb_t cb,void *arg); +extern int +efct_scsi_send_resp (struct efct_io *io,u32 flags, +struct efct_scsi_cmd_resp *rsp,efct_scsi_io_cb_t cb, +void *arg); +extern int +efct_scsi_send_tmf_resp (struct efct_io *io, +enum efct_scsi_tmf_resp rspcode, +u8 addl_rsp_info[3 ], +efct_scsi_io_cb_t cb,void *arg); +extern int +efct_scsi_tgt_abort_io (struct efct_io *io,efct_scsi_io_cb_t cb,void *arg); + +void efct_scsi_io_complete (struct efct_io *io); + +int efct_scsi_reg_fc_transport (void ); +int efct_scsi_release_fc_transport (void ); +int efct_scsi_new_device (struct efct *efct); +int efct_scsi_del_device (struct efct *efct); +void _efct_scsi_io_free (struct kref *arg); + +int efct_scsi_send_tmf (struct efc_node *node, +struct efct_io *io, +struct efct_io *io_to_abort,u32 lun, +enum efct_scsi_tmf_cmd tmf, +struct efct_scsi_sgl *sgl, +u32 sgl_count,u32 len, +efct_scsi_rsp_io_cb_t cb,void *arg); + +extern int +efct_scsi_del_vport (struct efct *efct,struct Scsi_Host *shost); +extern struct efct_vport * +efct_scsi_new_vport (struct efct *efct,struct device *dev); + +int efct_scsi_io_dispatch (struct efct_io *io,void *cb); +int efct_scsi_io_dispatch_abort (struct efct_io *io,void *cb); +void efct_scsi_check_pending (struct efct *efct); + +#endif /* __EFCT_SCSI_H__ */ Signature · 1 line
2.16.4
Thanks,
Daniel
PATCH v3 24/31 elx: efct: LIO backend interface routines
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
LIO backend template registration and template functions.
---
v3:
Fixed as per the review comments.
Removed vport pend list. Pending list is tracked based on the sport
assigned to vport.
--- drivers/scsi/elx/efct/efct_lio.c | 1840 ++++++++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_lio.h | 178 ++++ 2 files changed, 2018 insertions(+) create mode 100644 drivers/scsi/elx/efct/efct_lio.c create mode 100644 drivers/scsi/elx/efct/efct_lio.h
drivers/scsi/elx/efct/efct_lio.c new file +1840 -0
@@ -0,0 +1,1840 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include <target/target_core_base.h> +#include <target/target_core_fabric.h> +#include "efct_driver.h" +#include "efct_lio.h" + +static struct workqueue_struct *lio_wq; + +static int +efct_format_wwn (char *str,size_t len,const char *pre,u64 wwn) +{ +u8 a[8 ]; + +put_unaligned_be64 (wwn, a); +return snprintf (str, len,"%s%8phC" , pre, a); +} + +static int +efct_lio_parse_wwn (const char *name,u64 *wwp,u8 npiv) +{ +int num; +u8 b[8 ]; + +if (npiv) { + num =sscanf (name, +"%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" , + &b[0 ], &b[1 ], &b[2 ], &b[3 ], &b[4 ], &b[5 ], &b[6 ], + &b[7 ]); + }else { + num =sscanf (name, +"%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx" , + &b[0 ], &b[1 ], &b[2 ], &b[3 ], &b[4 ], &b[5 ], &b[6 ], + &b[7 ]); + } + +if (num !=8 ) +return -EINVAL ; + + *wwp =get_unaligned_be64 (b); +return EFC_SUCCESS ; +} + +static int +efct_lio_parse_npiv_wwn (const char *name,size_t size,u64 *wwpn,u64 *wwnn) +{ +unsigned int cnt = size; +int rc; + + *wwpn = *wwnn =0 ; +if (name[cnt -1 ] =='\n' || name[cnt -1 ] ==0 ) + cnt--; + +/* validate we have enough characters for WWPN */ +if ((cnt != (16 +1 +16 )) || (name[16 ] !=':' )) +return -EINVAL ; + + rc =efct_lio_parse_wwn (&name[0 ], wwpn,1 ); +if (rc) +return rc; + + rc =efct_lio_parse_wwn (&name[17 ], wwnn,1 ); +if (rc) +return rc; + +return EFC_SUCCESS ; +} + +static ssize_t +efct_lio_tpg_enable_show (struct config_item *item,char *page) +{ +struct se_portal_group *se_tpg =to_tpg (item); +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return snprintf (page,PAGE_SIZE ,"%d\n" ,atomic_read (&tpg->enabled)); +} + +static ssize_t +efct_lio_tpg_enable_store (struct config_item *item,const char *page, +size_t count) +{ +struct se_portal_group *se_tpg =to_tpg (item); +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); +struct efct *efct; +struct efc *efc; +unsigned long op; +int ret; + +if (!tpg->sport || !tpg->sport->efct) { +pr_err ("%s: Unable to find EFCT device\n" , __func__); +return -EINVAL ; + } + + efct = tpg->sport->efct; + efc = efct->efcport; + +if (kstrtoul (page,0 , &op) <0 ) +return -EINVAL ; + +if (op ==1 ) { +atomic_set (&tpg->enabled,1 ); +efc_log_debug (efct,"enable portal group %d\n" , tpg->tpgt); + + ret =efct_xport_control (efct->xport,EFCT_XPORT_PORT_ONLINE ); +if (ret) { + efct->tgt_efct.lio_sport =NULL ; +efc_log_test (efct,"cannot bring port online\n" ); +return ret; + } + }else if (op ==0 ) { +efc_log_debug (efct,"disable portal group %d\n" , tpg->tpgt); + +if (efc->domain && efc->domain->sport) +efct_scsi_tgt_del_sport (efc, efc->domain->sport); + +atomic_set (&tpg->enabled,0 ); + }else { +return -EINVAL ; + } + +return count; +} + +static ssize_t +efct_lio_npiv_tpg_enable_show (struct config_item *item,char *page) +{ +struct se_portal_group *se_tpg =to_tpg (item); +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return snprintf (page,PAGE_SIZE ,"%d\n" ,atomic_read (&tpg->enabled)); +} + +static ssize_t +efct_lio_npiv_tpg_enable_store (struct config_item *item,const char *page, +size_t count) +{ +struct se_portal_group *se_tpg =to_tpg (item); +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); +struct efct_lio_vport *lio_vport = tpg->vport; +struct efct *efct; +struct efc *efc; +int ret; +unsigned long op; + +if (kstrtoul (page,0 , &op) <0 ) +return -EINVAL ; + +if (!lio_vport) { +pr_err ("Unable to find vport\n" ); +return -EINVAL ; + } + + efct = lio_vport->efct; + efc = efct->efcport; + +if (op ==1 ) { +atomic_set (&tpg->enabled,1 ); +efc_log_debug (efct,"enable portal group %d\n" , tpg->tpgt); + +if (efc->domain) { + ret =efc_sport_vport_new (efc->domain, + lio_vport->npiv_wwpn, + lio_vport->npiv_wwnn, +U32_MAX , false, true, +NULL ,NULL ); +if (ret !=0 ) { +efc_log_err (efct,"Failed to create Vport\n" ); +return ret; + } +return count; + } + +if (!(efc_vport_create_spec (efc, lio_vport->npiv_wwnn, + lio_vport->npiv_wwpn,U32_MAX , + false, true,NULL ,NULL ))) +return -ENOMEM ; + + }else if (op ==0 ) { +efc_log_debug (efct,"disable portal group %d\n" , tpg->tpgt); + +atomic_set (&tpg->enabled,0 ); +/* only physical sport should exist, free lio_sport +* allocated in efct_lio_make_sport +*/ +if (efc->domain) { +efc_sport_vport_del (efct->efcport, efc->domain, + lio_vport->npiv_wwpn, + lio_vport->npiv_wwnn); +return count; + } + }else { +return -EINVAL ; + } +return count; +} + +static bool efct_lio_node_is_initiator (struct efc_node *node) +{ +if (!node) +return false; + +if (node->rnode.fc_id && node->rnode.fc_id !=FC_FID_FLOGI && + node->rnode.fc_id !=FC_FID_DIR_SERV && + node->rnode.fc_id !=FC_FID_FCTRL ) { +return true; + } + +return false; +} + +static int efct_lio_tgt_session_data (struct efct *efct,u64 wwpn, +char *buf,int size) +{ +struct efc_sli_port *sport =NULL ; +struct efc_node *node =NULL ; +struct efc *efc = efct->efcport; +u16 loop_id =0 ; +int off =0 , rc =0 ; + +if (!efc->domain) { +efc_log_err (efct,"failed to find efct/domain\n" ); +return EFC_FAIL ; + } + +list_for_each_entry (sport, &efc->domain->sport_list, list_entry) { +if (sport->wwpn != wwpn) +continue ; +list_for_each_entry (node, &sport->node_list, + list_entry) { +/* Dump only remote NPORT sessions */ +if (!efct_lio_node_is_initiator (node)) +continue ; + + rc =snprintf (buf + off, size - off, +"0x%016llx,0x%08x,0x%04x\n" , +get_unaligned_be64 (node->wwpn), + node->rnode.fc_id, loop_id); +if (rc <0 ) +break ; + off += rc; + } + } + +return EFC_SUCCESS ; +} + +static int efct_debugfs_session_open (struct inode *inode,struct file *filp) +{ +struct efct_lio_sport *sport = inode->i_private; +int size =17 *PAGE_SIZE ;/* 34 byte per session*2048 sessions */ + +if (!(filp->f_mode &FMODE_READ )) { + filp->private_data = sport; +return EFC_SUCCESS ; + } + + filp->private_data =kmalloc (size,GFP_KERNEL ); +if (!filp->private_data) +return -ENOMEM ; + +memset (filp->private_data,0 , size); +efct_lio_tgt_session_data (sport->efct, sport->wwpn, filp->private_data, + size); +return EFC_SUCCESS ; +} + +static int efct_debugfs_session_close (struct inode *inode,struct file *filp) +{ +if (filp->f_mode &FMODE_READ ) +kfree (filp->private_data); + +return EFC_SUCCESS ; +} + +static ssize_t efct_debugfs_session_read (struct file *filp,char __user *buf, +size_t count,loff_t *ppos) +{ +if (!(filp->f_mode &FMODE_READ )) +return -EPERM ; +return simple_read_from_buffer (buf, count, ppos, filp->private_data, +strlen (filp->private_data)); +} + +static int efct_npiv_debugfs_session_open (struct inode *inode, +struct file *filp) +{ +struct efct_lio_vport *sport = inode->i_private; +int size =17 *PAGE_SIZE ;/* 34 byte per session*2048 sessions */ + +if (!(filp->f_mode &FMODE_READ )) { + filp->private_data = sport; +return EFC_SUCCESS ; + } + + filp->private_data =kmalloc (size,GFP_KERNEL ); +if (!filp->private_data) +return -ENOMEM ; + +memset (filp->private_data,0 , size); +efct_lio_tgt_session_data (sport->efct, sport->npiv_wwpn, + filp->private_data, size); +return EFC_SUCCESS ; +} + +static const struct file_operations efct_debugfs_session_fops = { + .owner =THIS_MODULE , + .open = efct_debugfs_session_open, + .release = efct_debugfs_session_close, + .read = efct_debugfs_session_read, + .llseek = default_llseek, +}; + +static const struct file_operations efct_npiv_debugfs_session_fops = { + .owner =THIS_MODULE , + .open = efct_npiv_debugfs_session_open, + .release = efct_debugfs_session_close, + .read = efct_debugfs_session_read, + .llseek = default_llseek, +}; + +static char *efct_lio_get_fabric_wwn (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->sport->wwpn_str; +} + +static char *efct_lio_get_npiv_fabric_wwn (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->vport->wwpn_str; +} + +static u16 efct_lio_get_tag (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->tpgt; +} + +static u16 efct_lio_get_npiv_tag (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->tpgt; +} + +static int efct_lio_check_demo_mode (struct se_portal_group *se_tpg) +{ +return 1 ; +} + +static int efct_lio_check_demo_mode_cache (struct se_portal_group *se_tpg) +{ +return 1 ; +} + +static int efct_lio_check_demo_write_protect (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->tpg_attrib.demo_mode_write_protect; +} + +static int +efct_lio_npiv_check_demo_write_protect (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->tpg_attrib.demo_mode_write_protect; +} + +static int efct_lio_check_prod_write_protect (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->tpg_attrib.prod_mode_write_protect; +} + +static int +efct_lio_npiv_check_prod_write_protect (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +return tpg->tpg_attrib.prod_mode_write_protect; +} + +static u32 efct_lio_tpg_get_inst_index (struct se_portal_group *se_tpg) +{ +return EFC_SUCCESS ; +} + +static int efct_lio_check_stop_free (struct se_cmd *se_cmd) +{ +struct efct_scsi_tgt_io *ocp =container_of (se_cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TFO_CHK_STOP_FREE ); +return target_put_sess_cmd (se_cmd); +} + +static int +efct_lio_abort_tgt_cb (struct efct_io *io, +enum efct_scsi_io_status scsi_status, +u32 flags,void *arg) +{ +efct_lio_io_printf (io,"%s\n" , __func__); +return EFC_SUCCESS ; +} + +/* command has been aborted, cleanup here */ +static void efct_lio_aborted_task (struct se_cmd *se_cmd) +{ +struct efct_scsi_tgt_io *ocp =container_of (se_cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TFO_ABORTED_TASK ); + +if (!(se_cmd->transport_state &CMD_T_ABORTED ) || ocp->rsp_sent) +return ; + + ocp->aborting = true; + ocp->err =EFCT_SCSI_STATUS_ABORTED ; +/* terminate the exchange */ +efct_scsi_tgt_abort_io (io, efct_lio_abort_tgt_cb,NULL ); +} + +/* Called when se_cmd's ref count goes to 0 */ +static void efct_lio_release_cmd (struct se_cmd *se_cmd) +{ +struct efct_scsi_tgt_io *ocp =container_of (se_cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); +struct efct *efct = io->efct; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TFO_RELEASE_CMD ); +efct_scsi_io_complete (io); +atomic_sub_return (1 , &efct->tgt_efct.ios_in_use); +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_CMPL_CMD ); +} + +static void efct_lio_close_session (struct se_session *se_sess) +{ +struct efc_node *node = se_sess->fabric_sess_ptr; +struct efct *efct =NULL ; +int rc; + +pr_debug ("se_sess=%p node=%p" , se_sess, node); + +if (!node) { +pr_debug ("node is NULL" ); +return ; + } + + efct = node->efc->base; + rc =efct_xport_control (efct->xport, +EFCT_XPORT_POST_NODE_EVENT , node, +EFCT_XPORT_SHUTDOWN ,NULL ); +if (rc !=0 ) { +efc_log_test (efct, +"Failed to shutdown session %p node %p\n" , + se_sess, node); +return ; + } +} + +static u32 efct_lio_sess_get_index (struct se_session *se_sess) +{ +return EFC_SUCCESS ; +} + +static void efct_lio_set_default_node_attrs (struct se_node_acl *nacl) +{ +} + +static int efct_lio_get_cmd_state (struct se_cmd *se_cmd) +{ +return EFC_SUCCESS ; +} + +static int +efct_lio_sg_map (struct efct_io *io) +{ +struct efct_scsi_tgt_io *ocp = &io->tgt_io; +struct se_cmd *cmd = &ocp->cmd; + + ocp->seg_map_cnt =pci_map_sg (io->efct->pcidev, cmd->t_data_sg, + cmd->t_data_nents, cmd->data_direction); +if (ocp->seg_map_cnt ==0 ) +return -EFAULT ; +return EFC_SUCCESS ; +} + +static void +efct_lio_sg_unmap (struct efct_io *io) +{ +struct efct_scsi_tgt_io *ocp = &io->tgt_io; +struct se_cmd *cmd = &ocp->cmd; + +if (WARN_ON (!ocp->seg_map_cnt || !cmd->t_data_sg)) +return ; + +pci_unmap_sg (io->efct->pcidev, cmd->t_data_sg, + ocp->seg_map_cnt, cmd->data_direction); + ocp->seg_map_cnt =0 ; +} + +static int +efct_lio_status_done (struct efct_io *io, +enum efct_scsi_io_status scsi_status, +u32 flags,void *arg) +{ +struct efct_scsi_tgt_io *ocp = &io->tgt_io; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_RSP_DONE ); +if (scsi_status !=EFCT_SCSI_STATUS_GOOD ) { +efct_lio_io_printf (io,"callback completed with error=%d\n" , + scsi_status); + ocp->err = scsi_status; + } +if (ocp->seg_map_cnt) +efct_lio_sg_unmap (io); + +efct_lio_io_printf (io,"status=%d, err=%d flags=0x%x, dir=%d\n" , + scsi_status, ocp->err, flags, ocp->ddir); + +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_GENERIC_FREE ); +return EFC_SUCCESS ; +} + +static int +efct_lio_datamove_done (struct efct_io *io,enum efct_scsi_io_status scsi_status, +u32 flags,void *arg); + +static int +efct_lio_write_pending (struct se_cmd *cmd) +{ +struct efct_scsi_tgt_io *ocp =container_of (cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); +struct efct_scsi_sgl *sgl = io->sgl; +struct scatterlist *sg; +u32 flags =0 , cnt, curcnt; +u64 length =0 ; +int rc =0 ; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TFO_WRITE_PENDING ); +efct_lio_io_printf (io,"trans_state=0x%x se_cmd_flags=0x%x\n" , + cmd->transport_state, cmd->se_cmd_flags); + +if (ocp->seg_cnt ==0 ) { + ocp->seg_cnt = cmd->t_data_nents; + ocp->cur_seg =0 ; +if (efct_lio_sg_map (io)) { +efct_lio_io_printf (io,"efct_lio_sg_map failed\n" ); +return -EFAULT ; + } + } + curcnt = (ocp->seg_map_cnt - ocp->cur_seg); + curcnt = (curcnt < io->sgl_allocated) ? curcnt : io->sgl_allocated; +/* find current sg */ +for (cnt =0 , sg = cmd->t_data_sg; cnt < ocp->cur_seg; cnt++, + sg =sg_next (sg)) + ; + +for (cnt =0 ; cnt < curcnt; cnt++, sg =sg_next (sg)) { + sgl[cnt].addr =sg_dma_address (sg); + sgl[cnt].dif_addr =0 ; + sgl[cnt].len =sg_dma_len (sg); + length += sgl[cnt].len; + ocp->cur_seg++; + } +if (ocp->cur_seg == ocp->seg_cnt) + flags =EFCT_SCSI_LAST_DATAPHASE ; + rc =efct_scsi_recv_wr_data (io, flags, sgl, curcnt, length, + efct_lio_datamove_done,NULL ); +return rc; +} + +static int +efct_lio_queue_data_in (struct se_cmd *cmd) +{ +struct efct_scsi_tgt_io *ocp =container_of (cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); +struct efct_scsi_sgl *sgl = io->sgl; +struct scatterlist *sg =NULL ; +uint flags =0 , cnt =0 , curcnt =0 ; +u64 length =0 ; +int rc =0 ; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TFO_QUEUE_DATA_IN ); + +if (ocp->seg_cnt ==0 ) { +if (cmd->data_length) { + ocp->seg_cnt = cmd->t_data_nents; + ocp->cur_seg =0 ; +if (efct_lio_sg_map (io)) { +efct_lio_io_printf (io, +"efct_lio_sg_map failed\n" ); +return -EAGAIN ; + } + }else { +/* If command length is 0, send the response status */ +struct efct_scsi_cmd_resp rsp; + +memset (&rsp,0 ,sizeof (rsp)); +efct_lio_io_printf (io, +"cmd : %p length 0, send status\n" , + cmd); +return efct_scsi_send_resp (io,0 , &rsp, + efct_lio_status_done,NULL ); + } + } + curcnt =min (ocp->seg_map_cnt - ocp->cur_seg, io->sgl_allocated); + +while (cnt < curcnt) { + sg = &cmd->t_data_sg[ocp->cur_seg]; + sgl[cnt].addr =sg_dma_address (sg); + sgl[cnt].dif_addr =0 ; +if (ocp->transferred_len +sg_dma_len (sg) >= cmd->data_length) + sgl[cnt].len = cmd->data_length - ocp->transferred_len; +else + sgl[cnt].len =sg_dma_len (sg); + + ocp->transferred_len += sgl[cnt].len; + length += sgl[cnt].len; + ocp->cur_seg++; + cnt++; +if (ocp->transferred_len == cmd->data_length) +break ; + } + +if (ocp->transferred_len == cmd->data_length) { + flags =EFCT_SCSI_LAST_DATAPHASE ; + ocp->seg_cnt = ocp->cur_seg; + } + +/* If there is residual, disable Auto Good Response */ +if (cmd->residual_count) + flags |=EFCT_SCSI_NO_AUTO_RESPONSE ; + + rc =efct_scsi_send_rd_data (io, flags, sgl, curcnt, length, + efct_lio_datamove_done,NULL ); +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_SEND_RD_DATA ); +return rc; +} + +static int +efct_lio_datamove_done (struct efct_io *io, +enum efct_scsi_io_status scsi_status, +u32 flags,void *arg) +{ +struct efct_scsi_tgt_io *ocp = &io->tgt_io; +struct se_cmd *cmd = &io->tgt_io.cmd; +int rc; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_DATA_DONE ); +if (scsi_status !=EFCT_SCSI_STATUS_GOOD ) { +efct_lio_io_printf (io,"callback completed with error=%d\n" , + scsi_status); + ocp->err = scsi_status; + } +efct_lio_io_printf (io,"seg_map_cnt=%d\n" , ocp->seg_map_cnt); +if (ocp->seg_map_cnt) { +if (ocp->err ==EFCT_SCSI_STATUS_GOOD && + ocp->cur_seg < ocp->seg_cnt) { +efct_lio_io_printf (io,"continuing cmd at segm=%d\n" , + ocp->cur_seg); +if (ocp->ddir ==DMA_TO_DEVICE ) + rc =efct_lio_write_pending (&ocp->cmd); +else + rc =efct_lio_queue_data_in (&ocp->cmd); +if (rc ==0 ) +return EFC_SUCCESS ; + ocp->err =EFCT_SCSI_STATUS_ERROR ; +efct_lio_io_printf (io,"could not continue command\n" ); + } +efct_lio_sg_unmap (io); + } + +if (io->tgt_io.aborting) { +efct_lio_io_printf (io,"IO done aborted\n" ); +return EFC_SUCCESS ; + } + +if (ocp->ddir ==DMA_TO_DEVICE ) { +efct_lio_io_printf (io,"Write done, trans_state=0x%x\n" , + io->tgt_io.cmd.transport_state); +if (scsi_status !=EFCT_SCSI_STATUS_GOOD ) { +transport_generic_request_failure (&io->tgt_io.cmd, +TCM_CHECK_CONDITION_ABORT_CMD ); +efct_set_lio_io_state (io, +EFCT_LIO_STATE_TGT_GENERIC_REQ_FAILURE ); + }else { +efct_set_lio_io_state (io, +EFCT_LIO_STATE_TGT_EXECUTE_CMD ); +target_execute_cmd (&io->tgt_io.cmd); + } + }else { +if ((flags &EFCT_SCSI_IO_CMPL_RSP_SENT ) ==0 ) { +struct efct_scsi_cmd_resp rsp; +/* send check condition if an error occurred */ +memset (&rsp,0 ,sizeof (rsp)); + rsp.scsi_status = cmd->scsi_status; + rsp.sense_data = (uint8_t *)io->tgt_io.sense_buffer; + rsp.sense_data_length = cmd->scsi_sense_length; + +/* Check for residual underrun or overrun */ +if (cmd->se_cmd_flags &SCF_OVERFLOW_BIT ) + rsp.residual = -cmd->residual_count; +else if (cmd->se_cmd_flags &SCF_UNDERFLOW_BIT ) + rsp.residual = cmd->residual_count; + + rc =efct_scsi_send_resp (io,0 , &rsp, + efct_lio_status_done,NULL ); +efct_set_lio_io_state (io, +EFCT_LIO_STATE_SCSI_SEND_RSP ); +if (rc !=0 ) { +efct_lio_io_printf (io, +"Read done, failed to send rsp, rc=%d\n" , + rc); +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +efct_set_lio_io_state (io, +EFCT_LIO_STATE_TGT_GENERIC_FREE ); + }else { + ocp->rsp_sent = true; + } + }else { + ocp->rsp_sent = true; +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +efct_set_lio_io_state (io, +EFCT_LIO_STATE_TGT_GENERIC_FREE ); + } + } +return EFC_SUCCESS ; +} + +static int +efct_lio_tmf_done (struct efct_io *io,enum efct_scsi_io_status scsi_status, +u32 flags,void *arg) +{ +efct_lio_tmfio_printf (io,"cmd=%p status=%d, flags=0x%x\n" , + &io->tgt_io.cmd, scsi_status, flags); + +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_GENERIC_FREE ); +return EFC_SUCCESS ; +} + +static int +efct_lio_null_tmf_done (struct efct_io *tmfio, +enum efct_scsi_io_status scsi_status, +u32 flags,void *arg) +{ +efct_lio_tmfio_printf (tmfio,"cmd=%p status=%d, flags=0x%x\n" , + &tmfio->tgt_io.cmd, scsi_status, flags); + +/* free struct efct_io only, no active se_cmd */ +efct_scsi_io_complete (tmfio); +return EFC_SUCCESS ; +} + +static int +efct_lio_queue_status (struct se_cmd *cmd) +{ +struct efct_scsi_cmd_resp rsp; +struct efct_scsi_tgt_io *ocp =container_of (cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); +int rc =0 ; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TFO_QUEUE_STATUS ); +efct_lio_io_printf (io, +"status=0x%x trans_state=0x%x se_cmd_flags=0x%x sns_len=%d\n" , + cmd->scsi_status, cmd->transport_state, cmd->se_cmd_flags, + cmd->scsi_sense_length); + +memset (&rsp,0 ,sizeof (rsp)); + rsp.scsi_status = cmd->scsi_status; + rsp.sense_data = (u8 *)io->tgt_io.sense_buffer; + rsp.sense_data_length = cmd->scsi_sense_length; + +/* Check for residual underrun or overrun, mark negitive value for +* underrun to recognize in HW +*/ +if (cmd->se_cmd_flags &SCF_OVERFLOW_BIT ) + rsp.residual = -cmd->residual_count; +else if (cmd->se_cmd_flags &SCF_UNDERFLOW_BIT ) + rsp.residual = cmd->residual_count; + + rc =efct_scsi_send_resp (io,0 , &rsp, efct_lio_status_done,NULL ); +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_SEND_RSP ); +if (rc ==0 ) + ocp->rsp_sent = true; +return rc; +} + +static void efct_lio_queue_tm_rsp (struct se_cmd *cmd) +{ +struct efct_scsi_tgt_io *ocp =container_of (cmd, + struct efct_scsi_tgt_io, + cmd); + struct efct_io *tmfio = container_of(ocp, struct efct_io, tgt_io); +struct se_tmr_req *se_tmr = cmd->se_tmr_req; +u8 rspcode; + +efct_lio_tmfio_printf (tmfio,"cmd=%p function=0x%x tmr->response=%d\n" , + cmd, se_tmr->function, se_tmr->response); +switch (se_tmr->response) { +case TMR_FUNCTION_COMPLETE : + rspcode =EFCT_SCSI_TMF_FUNCTION_COMPLETE ; +break ; +case TMR_TASK_DOES_NOT_EXIST : + rspcode =EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND ; +break ; +case TMR_LUN_DOES_NOT_EXIST : + rspcode =EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER ; +break ; +case TMR_FUNCTION_REJECTED : +default : + rspcode =EFCT_SCSI_TMF_FUNCTION_REJECTED ; +break ; + } +efct_scsi_send_tmf_resp (tmfio, rspcode,NULL , efct_lio_tmf_done,NULL ); +} + +static struct efct *efct_find_wwpn (u64 wwpn) +{ +int efctidx; +struct efct *efct; + +/* Search for the HBA that has this WWPN */ +for (efctidx =0 ; efctidx <MAX_EFCT_DEVICES ; efctidx++) { + + efct = efct_devices[efctidx]; +if (!efct) +continue ; + +if (wwpn ==efct_get_wwpn (&efct->hw)) +break ; + } + +if (efctidx ==MAX_EFCT_DEVICES ) +return NULL ; + +return efct_devices[efctidx]; +} + +static struct dentry * +efct_create_dfs_session (struct efct *efct,void *data,u8 npiv) +{ +char name[16 ]; + +if (!efct->sess_debugfs_dir) +return NULL ; + +if (!npiv) { +snprintf (name,sizeof (name),"efct-sessions-%d" , + efct->instance_index); +return debugfs_create_file (name,0644 , efct->sess_debugfs_dir, + data, &efct_debugfs_session_fops); + } + +snprintf (name,sizeof (name),"sessions-npiv-%d" , efct->instance_index); + +return debugfs_create_file (name,0644 , efct->sess_debugfs_dir, data, + &efct_npiv_debugfs_session_fops); +} + +static struct se_wwn * +efct_lio_make_sport (struct target_fabric_configfs *tf, +struct config_group *group,const char *name) +{ +struct efct_lio_sport *lio_sport; +struct efct *efct; +int ret; +u64 wwpn; + + ret =efct_lio_parse_wwn (name, &wwpn,0 ); +if (ret) +return ERR_PTR (ret); + + efct =efct_find_wwpn (wwpn); +if (!efct) { +pr_err ("cannot find EFCT for base wwpn %s\n" , name); +return ERR_PTR (-ENXIO ); + } + + lio_sport =kzalloc (sizeof (*lio_sport),GFP_KERNEL ); +if (!lio_sport) +return ERR_PTR (-ENOMEM ); + + lio_sport->efct = efct; + lio_sport->wwpn = wwpn; +efct_format_wwn (lio_sport->wwpn_str,sizeof (lio_sport->wwpn_str), +"naa." , wwpn); + efct->tgt_efct.lio_sport = lio_sport; + + lio_sport->sessions =efct_create_dfs_session (efct, lio_sport,0 ); +return &lio_sport->sport_wwn; +} + +static struct se_wwn * +efct_lio_npiv_make_sport (struct target_fabric_configfs *tf, +struct config_group *group,const char *name) +{ +struct efct_lio_vport *lio_vport; +struct efct *efct; +int ret =-1 ; +u64 p_wwpn, npiv_wwpn, npiv_wwnn; +char *p, *pbuf, tmp[128 ]; +struct efct_lio_vport_list_t *vport_list; +struct fc_vport *new_fc_vport; +struct fc_vport_identifiers vport_id; +unsigned long flags =0 ; + +snprintf (tmp,sizeof (tmp),"%s" , name); + pbuf = &tmp[0 ]; + + p =strsep (&pbuf,"@" ); + +if (!p || !pbuf) { +pr_err ("Unable to find separator operator(@)\n" ); +return ERR_PTR (-EINVAL ); + } + + ret =efct_lio_parse_wwn (p, &p_wwpn,0 ); +if (ret) +return ERR_PTR (ret); + + ret =efct_lio_parse_npiv_wwn (pbuf,strlen (pbuf), &npiv_wwpn, + &npiv_wwnn); +if (ret) +return ERR_PTR (ret); + + efct =efct_find_wwpn (p_wwpn); +if (!efct) { +pr_err ("cannot find EFCT for base wwpn %s\n" , name); +return ERR_PTR (-ENXIO ); + } + + lio_vport =kzalloc (sizeof (*lio_vport),GFP_KERNEL ); +if (!lio_vport) +return ERR_PTR (-ENOMEM ); + + lio_vport->efct = efct; + lio_vport->wwpn = p_wwpn; + lio_vport->npiv_wwpn = npiv_wwpn; + lio_vport->npiv_wwnn = npiv_wwnn; + +efct_format_wwn (lio_vport->wwpn_str,sizeof (lio_vport->wwpn_str), +"naa." , npiv_wwpn); + + vport_list =kmalloc (sizeof (*vport_list),GFP_KERNEL ); +if (!vport_list) { +kfree (lio_vport); +return ERR_PTR (-ENOMEM ); + } + +memset (vport_list,0 ,sizeof (struct efct_lio_vport_list_t )); + vport_list->lio_vport = lio_vport; +spin_lock_irqsave (&efct->tgt_efct.efct_lio_lock, flags); +INIT_LIST_HEAD (&vport_list->list_entry); +list_add_tail (&vport_list->list_entry, &efct->tgt_efct.vport_list); +spin_unlock_irqrestore (&efct->tgt_efct.efct_lio_lock, flags); + + lio_vport->sessions =efct_create_dfs_session (efct, lio_vport,1 ); + +memset (&vport_id,0 ,sizeof (vport_id)); + vport_id.port_name = npiv_wwpn; + vport_id.node_name = npiv_wwnn; + vport_id.roles =FC_PORT_ROLE_FCP_INITIATOR ; + vport_id.vport_type =FC_PORTTYPE_NPIV ; + vport_id.disable = false; + + new_fc_vport =fc_vport_create (efct->shost,0 , &vport_id); +if (!new_fc_vport) { +efc_log_err (efct,"fc_vport_create failed\n" ); +kfree (lio_vport); +kfree (vport_list); +return ERR_PTR (-ENOMEM ); + } + + lio_vport->fc_vport = new_fc_vport; + +return &lio_vport->vport_wwn; +} + +static void +efct_lio_drop_sport (struct se_wwn *wwn) +{ +struct efct_lio_sport *lio_sport =container_of (wwn, + struct efct_lio_sport, sport_wwn); +struct efct *efct = lio_sport->efct; + +/* only physical sport should exist, free lio_sport allocated +* in efct_lio_make_sport. +*/ + +debugfs_remove (lio_sport->sessions); + lio_sport->sessions =NULL ; + +kfree (efct->tgt_efct.lio_sport); + efct->tgt_efct.lio_sport =NULL ; +} + +static void +efct_lio_npiv_drop_sport (struct se_wwn *wwn) +{ +struct efct_lio_vport *lio_vport =container_of (wwn, + struct efct_lio_vport, vport_wwn); +struct efct_lio_vport_list_t *vport, *next_vport; +struct efct *efct = lio_vport->efct; +unsigned long flags =0 ; + +spin_lock_irqsave (&efct->tgt_efct.efct_lio_lock, flags); + +debugfs_remove (lio_vport->sessions); + +if (lio_vport->fc_vport) +fc_vport_terminate (lio_vport->fc_vport); + + lio_vport->sessions =NULL ; + +list_for_each_entry_safe (vport, next_vport, &efct->tgt_efct.vport_list, + list_entry) { +if (vport->lio_vport == lio_vport) { +list_del (&vport->list_entry); +kfree (vport->lio_vport); +kfree (vport); +break ; + } + } +spin_unlock_irqrestore (&efct->tgt_efct.efct_lio_lock, flags); +} + +static struct se_portal_group * +efct_lio_make_tpg (struct se_wwn *wwn,const char *name) +{ +struct efct_lio_sport *lio_sport =container_of (wwn, + struct efct_lio_sport, sport_wwn); +struct efct_lio_tpg *tpg; +struct efct *efct; +unsigned long n; +int ret; + +if (strstr (name,"tpgt_" ) != name) +return ERR_PTR (-EINVAL ); +if (kstrtoul (name +5 ,10 , &n) || n >USHRT_MAX ) +return ERR_PTR (-EINVAL ); + + tpg =kzalloc (sizeof (*tpg),GFP_KERNEL ); +if (!tpg) +return ERR_PTR (-ENOMEM ); + + tpg->sport = lio_sport; + tpg->tpgt = n; +atomic_set (&tpg->enabled,0 ); + + tpg->tpg_attrib.generate_node_acls =1 ; + tpg->tpg_attrib.demo_mode_write_protect =1 ; + tpg->tpg_attrib.cache_dynamic_acls =1 ; + tpg->tpg_attrib.demo_mode_login_only =1 ; + tpg->tpg_attrib.session_deletion_wait =1 ; + + ret =core_tpg_register (wwn, &tpg->tpg,SCSI_PROTOCOL_FCP ); +if (ret <0 ) { +kfree (tpg); +return NULL ; + } + efct = lio_sport->efct; + efct->tgt_efct.tpg = tpg; +efc_log_debug (efct,"create portal group %d\n" , tpg->tpgt); + +return &tpg->tpg; +} + +static void +efct_lio_drop_tpg (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +efc_log_debug (tpg->sport->efct,"drop portal group %d\n" , tpg->tpgt); + tpg->sport->efct->tgt_efct.tpg =NULL ; +core_tpg_deregister (se_tpg); +kfree (tpg); +} + +static struct se_portal_group * +efct_lio_npiv_make_tpg (struct se_wwn *wwn,const char *name) +{ +struct efct_lio_vport *lio_vport =container_of (wwn, + struct efct_lio_vport, vport_wwn); +struct efct_lio_tpg *tpg; +struct efct *efct; +unsigned long n; +int ret; + + efct = lio_vport->efct; +if (strstr (name,"tpgt_" ) != name) +return ERR_PTR (-EINVAL ); +if (kstrtoul (name +5 ,10 , &n) || n >USHRT_MAX ) +return ERR_PTR (-EINVAL ); + +if (n !=1 ) { +efc_log_err (efct,"Invalid tpgt index: %ld provided\n" , n); +return ERR_PTR (-EINVAL ); + } + + tpg =kzalloc (sizeof (*tpg),GFP_KERNEL ); +if (!tpg) +return ERR_PTR (-ENOMEM ); + + tpg->vport = lio_vport; + tpg->tpgt = n; +atomic_set (&tpg->enabled,0 ); + + tpg->tpg_attrib.generate_node_acls =1 ; + tpg->tpg_attrib.demo_mode_write_protect =1 ; + tpg->tpg_attrib.cache_dynamic_acls =1 ; + tpg->tpg_attrib.demo_mode_login_only =1 ; + tpg->tpg_attrib.session_deletion_wait =1 ; + + ret =core_tpg_register (wwn, &tpg->tpg,SCSI_PROTOCOL_FCP ); + +if (ret <0 ) { +kfree (tpg); +return NULL ; + } + lio_vport->tpg = tpg; +efc_log_debug (efct,"create vport portal group %d\n" , tpg->tpgt); + +return &tpg->tpg; +} + +static void +efct_lio_npiv_drop_tpg (struct se_portal_group *se_tpg) +{ +struct efct_lio_tpg *tpg =container_of (se_tpg, + struct efct_lio_tpg, tpg); + +efc_log_debug (tpg->vport->efct,"drop npiv portal group %d\n" , + tpg->tpgt); +core_tpg_deregister (se_tpg); +kfree (tpg); +} + +static int +efct_lio_init_nodeacl (struct se_node_acl *se_nacl,const char *name) +{ +struct efct_lio_nacl *nacl; +u64 wwnn; + +if (efct_lio_parse_wwn (name, &wwnn,0 ) <0 ) +return -EINVAL ; + + nacl = container_of(se_nacl, struct efct_lio_nacl, se_node_acl); + nacl->nport_wwnn = wwnn; + +efct_format_wwn (nacl->nport_name,sizeof (nacl->nport_name),"" , wwnn); +return EFC_SUCCESS ; +} + +static int efct_lio_check_demo_mode_login_only (struct se_portal_group *stpg) +{ + struct efct_lio_tpg *tpg = container_of(stpg, struct efct_lio_tpg, tpg); + +return tpg->tpg_attrib.demo_mode_login_only; +} + +static int +efct_lio_npiv_check_demo_mode_login_only (struct se_portal_group *stpg) +{ + struct efct_lio_tpg *tpg = container_of(stpg, struct efct_lio_tpg, tpg); + +return tpg->tpg_attrib.demo_mode_login_only; +} + +static struct efct_lio_tpg * +efct_get_vport_tpg (struct efc_node *node) +{ +struct efct *efct; +u64 wwpn = node->sport->wwpn; +struct efct_lio_vport_list_t *vport, *next; +struct efct_lio_vport *lio_vport =NULL ; +struct efct_lio_tpg *tpg =NULL ; +unsigned long flags =0 ; + + efct = node->efc->base; +spin_lock_irqsave (&efct->tgt_efct.efct_lio_lock, flags); +list_for_each_entry_safe (vport, next, &efct->tgt_efct.vport_list, + list_entry) { + lio_vport = vport->lio_vport; +if (wwpn && lio_vport && + lio_vport->npiv_wwpn == wwpn) { +efc_log_test (efct,"found tpg on vport\n" ); + tpg = lio_vport->tpg; +break ; + } + } +spin_unlock_irqrestore (&efct->tgt_efct.efct_lio_lock, flags); +return tpg; +} + +static int efct_session_cb (struct se_portal_group *se_tpg, +struct se_session *se_sess,void *private) +{ +struct efc_node *node = private; +struct efct_scsi_tgt_node *tgt_node =NULL ; + + tgt_node =kzalloc (sizeof (*tgt_node),GFP_KERNEL ); +if (!tgt_node) +return EFC_FAIL ; + + tgt_node->session = se_sess; + node->tgt_node = tgt_node; + +return EFC_SUCCESS ; +} + +int efct_scsi_tgt_new_device (struct efct *efct) +{ +int rc =0 ; +u32 total_ios; + +/* Get the max settings */ + efct->tgt_efct.max_sge =sli_get_max_sge (&efct->hw.sli); + efct->tgt_efct.max_sgl =sli_get_max_sgl (&efct->hw.sli); + +/* initialize IO watermark fields */ +atomic_set (&efct->tgt_efct.ios_in_use,0 ); + total_ios = efct->hw.config.n_io; +efc_log_debug (efct,"total_ios=%d\n" , total_ios); + efct->tgt_efct.watermark_min = + (total_ios *EFCT_WATERMARK_LOW_PCT ) /100 ; + efct->tgt_efct.watermark_max = + (total_ios *EFCT_WATERMARK_HIGH_PCT ) /100 ; +atomic_set (&efct->tgt_efct.io_high_watermark, + efct->tgt_efct.watermark_max); +atomic_set (&efct->tgt_efct.watermark_hit,0 ); +atomic_set (&efct->tgt_efct.initiator_count,0 ); + + lio_wq =create_singlethread_workqueue ("efct_lio_worker" ); +if (!lio_wq) { +efc_log_err (efct,"workqueue create failed\n" ); +return -ENOMEM ; + } + +spin_lock_init (&efct->tgt_efct.efct_lio_lock); +INIT_LIST_HEAD (&efct->tgt_efct.vport_list); + +return rc; +} + +int efct_scsi_tgt_del_device (struct efct *efct) +{ +flush_workqueue (lio_wq); + +return EFC_SUCCESS ; +} + +int +efct_scsi_tgt_new_domain (struct efc *efc,struct efc_domain *domain) +{ +return 0 ; +} + +void +efct_scsi_tgt_del_domain (struct efc *efc,struct efc_domain *domain) +{ +} + +/* Called by the libefc when new sli port (sport) is discovered */ +int +efct_scsi_tgt_new_sport (struct efc *efc,struct efc_sli_port *sport) +{ +struct efct *efct = sport->efc->base; + +efc_log_debug (efct,"New SPORT: %s bound to %s\n" , sport->display_name, + efct->tgt_efct.lio_sport->wwpn_str); + +return EFC_SUCCESS ; +} + +/* Called by the libefc when a sport goes away. */ +void +efct_scsi_tgt_del_sport (struct efc *efc,struct efc_sli_port *sport) +{ +efc_log_debug (efc,"Del SPORT: %s\n" , + sport->display_name); +} +/* Called by libefc to validate node. */ +int +efct_scsi_validate_initiator (struct efc *efc,struct efc_node *node) +{ +return 1 ; +} + +static void efct_lio_setup_session (struct work_struct *work) +{ +struct efct_lio_wq_data *wq_data =container_of (work, + struct efct_lio_wq_data, work); +struct efct *efct = wq_data->efct; +struct efc_node *node = wq_data->ptr; +char wwpn[WWN_NAME_LEN ]; +struct efct_lio_tpg *tpg =NULL ; +struct se_portal_group *se_tpg; +struct se_session *se_sess; +int watermark; +int initiator_count; + +/* Check to see if it's belongs to vport, +* if not get physical port +*/ + tpg =efct_get_vport_tpg (node); +if (tpg) { + se_tpg = &tpg->tpg; + }else if (efct->tgt_efct.tpg) { + tpg = efct->tgt_efct.tpg; + se_tpg = &tpg->tpg; + }else { +efc_log_err (efct,"failed to init session\n" ); +return ; + } + +/* +* Format the FCP Initiator port_name into colon +* separated values to match the format by our explicit +* ConfigFS NodeACLs. +*/ +efct_format_wwn (wwpn,sizeof (wwpn),"" , +efc_node_get_wwpn (node)); + + se_sess =target_setup_session (se_tpg,0 ,0 , +TARGET_PROT_NORMAL , + wwpn, node, + efct_session_cb); +if (IS_ERR (se_sess)) { +efc_log_err (efct,"failed to setup session\n" ); +return ; + } + +efc_log_debug (efct,"new initiator se_sess=%p node=%p\n" , + se_sess, node); + +/* update IO watermark: increment initiator count */ + initiator_count = +atomic_add_return (1 , &efct->tgt_efct.initiator_count); + watermark = (efct->tgt_efct.watermark_max - + initiator_count *EFCT_IO_WATERMARK_PER_INITIATOR ); + watermark = (efct->tgt_efct.watermark_min > watermark) ? + efct->tgt_efct.watermark_min : watermark; +atomic_set (&efct->tgt_efct.io_high_watermark, + watermark); + +kfree (wq_data); +} + +/* Called by the libefc when new a new remote initiator is discovered */ +int efct_scsi_new_initiator (struct efc *efc,struct efc_node *node) +{ +struct efct *efct = node->efc->base; +struct efct_lio_wq_data *wq_data; + +/* +* Since LIO only supports initiator validation at thread level, +* we are open minded and accept all callers. +*/ + wq_data =kzalloc (sizeof (*wq_data),GFP_ATOMIC ); +if (!wq_data) +return -ENOMEM ; + + wq_data->ptr = node; + wq_data->efct = efct; +INIT_WORK (&wq_data->work, efct_lio_setup_session); +queue_work (lio_wq, &wq_data->work); +return EFC_SUCCESS ; +} + +static void efct_lio_remove_session (struct work_struct *work) +{ +struct efct_lio_wq_data *wq_data =container_of (work, + struct efct_lio_wq_data, work); +struct efct *efct = wq_data->efct; +struct efc_node *node = wq_data->ptr; +struct efct_scsi_tgt_node *tgt_node =NULL ; +struct se_session *se_sess; + + tgt_node = node->tgt_node; + se_sess = tgt_node->session; + +if (!se_sess) { +/* base driver has sent back-to-back requests +* to unreg session with no intervening +* register +*/ +efc_log_test (efct, +"unreg session for NULL session\n" ); +efc_scsi_del_initiator_complete (node->efc, + node); +return ; + } + +efc_log_debug (efct,"unreg session se_sess=%p node=%p\n" , + se_sess, node); + +/* first flag all session commands to complete */ +target_sess_cmd_list_set_waiting (se_sess); + +/* now wait for session commands to complete */ +target_wait_for_sess_cmds (se_sess); +target_remove_session (se_sess); + +kfree (node->tgt_node); + + node->tgt_node =NULL ; +efc_scsi_del_initiator_complete (node->efc, node); + +kfree (wq_data); +} + +/* Called by the libefc when an initiator goes away. */ +int efct_scsi_del_initiator (struct efc *efc,struct efc_node *node, +int reason) +{ +struct efct *efct = node->efc->base; +struct efct_lio_wq_data *wq_data; +int watermark; +int initiator_count; + +if (reason ==EFCT_SCSI_INITIATOR_MISSING ) +return EFCT_SCSI_CALL_COMPLETE ; + + wq_data =kmalloc (sizeof (*wq_data),GFP_ATOMIC ); +if (!wq_data) +return EFCT_SCSI_CALL_COMPLETE ; + +memset (wq_data,0 ,sizeof (*wq_data)); + wq_data->ptr = node; + wq_data->efct = efct; +INIT_WORK (&wq_data->work, efct_lio_remove_session); +queue_work (lio_wq, &wq_data->work); + +/* +* update IO watermark: decrement initiator count +*/ + initiator_count = +atomic_sub_return (1 , &efct->tgt_efct.initiator_count); + watermark = (efct->tgt_efct.watermark_max - + initiator_count *EFCT_IO_WATERMARK_PER_INITIATOR ); + watermark = (efct->tgt_efct.watermark_min > watermark) ? + efct->tgt_efct.watermark_min : watermark; +atomic_set (&efct->tgt_efct.io_high_watermark, watermark); + +return EFCT_SCSI_CALL_ASYNC ; +} + +int efct_scsi_recv_cmd (struct efct_io *io,uint64_t lun,u8 *cdb, +u32 cdb_len,u32 flags) +{ +struct efct_scsi_tgt_io *ocp = &io->tgt_io; +struct efct *efct = io->efct; +char *ddir; +struct efct_scsi_tgt_node *tgt_node =NULL ; +struct se_session *se_sess; +int rc =0 ; + +memset (ocp,0 ,sizeof (struct efct_scsi_tgt_io )); +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_RECV_CMD ); +atomic_add_return (1 , &efct->tgt_efct.ios_in_use); + +/* set target timeout */ + io->timeout = efct->target_io_timer_sec; + +if (flags &EFCT_SCSI_CMD_SIMPLE ) + ocp->task_attr =TCM_SIMPLE_TAG ; +else if (flags &EFCT_SCSI_CMD_HEAD_OF_QUEUE ) + ocp->task_attr =TCM_HEAD_TAG ; +else if (flags &EFCT_SCSI_CMD_ORDERED ) + ocp->task_attr =TCM_ORDERED_TAG ; +else if (flags &EFCT_SCSI_CMD_ACA ) + ocp->task_attr =TCM_ACA_TAG ; + +switch (flags & (EFCT_SCSI_CMD_DIR_IN |EFCT_SCSI_CMD_DIR_OUT )) { +case EFCT_SCSI_CMD_DIR_IN : + ddir ="FROM_INITIATOR" ; + ocp->ddir =DMA_TO_DEVICE ; +break ; +case EFCT_SCSI_CMD_DIR_OUT : + ddir ="TO_INITIATOR" ; + ocp->ddir =DMA_FROM_DEVICE ; +break ; +case EFCT_SCSI_CMD_DIR_IN |EFCT_SCSI_CMD_DIR_OUT : + ddir ="BIDIR" ; + ocp->ddir =DMA_BIDIRECTIONAL ; +break ; +default : + ddir ="NONE" ; + ocp->ddir =DMA_NONE ; +break ; + } + + ocp->lun = lun; +efct_lio_io_printf (io,"new cmd=0x%x ddir=%s dl=%u\n" , + cdb[0 ], ddir, io->exp_xfer_len); + + tgt_node = io->node->tgt_node; + se_sess = tgt_node->session; +if (se_sess) { +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_SUBMIT_CMD ); + rc =target_submit_cmd (&io->tgt_io.cmd, se_sess, + cdb, &io->tgt_io.sense_buffer[0 ], + ocp->lun, io->exp_xfer_len, + ocp->task_attr, ocp->ddir, +TARGET_SCF_ACK_KREF ); +if (rc) { +efc_log_err (efct,"failed to submit cmd se_cmd: %p\n" , + &ocp->cmd); +efct_scsi_io_free (io); + } + } + +return rc; +} + +int +efct_scsi_recv_tmf (struct efct_io *tmfio,u32 lun, +enum efct_scsi_tmf_cmd cmd, +struct efct_io *io_to_abort,u32 flags) +{ +unsigned char tmr_func; +struct efct *efct = tmfio->efct; +struct efct_scsi_tgt_io *ocp = &tmfio->tgt_io; +struct efct_scsi_tgt_node *tgt_node =NULL ; +struct se_session *se_sess; +int rc; + +memset (ocp,0 ,sizeof (struct efct_scsi_tgt_io )); +efct_set_lio_io_state (tmfio,EFCT_LIO_STATE_SCSI_RECV_TMF ); +atomic_add_return (1 , &efct->tgt_efct.ios_in_use); +efct_lio_tmfio_printf (tmfio,"%s: new tmf %x lun=%u\n" , + tmfio->display_name, cmd, lun); + +switch (cmd) { +case EFCT_SCSI_TMF_ABORT_TASK : + tmr_func =TMR_ABORT_TASK ; +break ; +case EFCT_SCSI_TMF_ABORT_TASK_SET : + tmr_func =TMR_ABORT_TASK_SET ; +break ; +case EFCT_SCSI_TMF_CLEAR_TASK_SET : + tmr_func =TMR_CLEAR_TASK_SET ; +break ; +case EFCT_SCSI_TMF_LOGICAL_UNIT_RESET : + tmr_func =TMR_LUN_RESET ; +break ; +case EFCT_SCSI_TMF_CLEAR_ACA : + tmr_func =TMR_CLEAR_ACA ; +break ; +case EFCT_SCSI_TMF_TARGET_RESET : + tmr_func =TMR_TARGET_WARM_RESET ; +break ; +case EFCT_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT : +case EFCT_SCSI_TMF_QUERY_TASK_SET : +default : + goto tmf_fail; + } + + tmfio->tgt_io.tmf = tmr_func; + tmfio->tgt_io.lun = lun; + tmfio->tgt_io.io_to_abort = io_to_abort; + + tgt_node = tmfio->node->tgt_node; + + se_sess = tgt_node->session; +if (!se_sess) +return EFC_SUCCESS ; + + rc =target_submit_tmr (&ocp->cmd, se_sess,NULL , lun, ocp, tmr_func, +GFP_ATOMIC , tmfio->init_task_tag,TARGET_SCF_ACK_KREF ); + +efct_set_lio_io_state (tmfio,EFCT_LIO_STATE_TGT_SUBMIT_TMR ); +if (rc) + goto tmf_fail; + +return EFC_SUCCESS ; + +tmf_fail: +efct_scsi_send_tmf_resp (tmfio,EFCT_SCSI_TMF_FUNCTION_REJECTED , +NULL , efct_lio_null_tmf_done,NULL ); +return EFC_SUCCESS ; +} + +/* Start items for efct_lio_tpg_attrib_cit */ + +#define DEF_EFCT_TPG_ATTRIB (name) \ + \ +static ssize_t efct_lio_tpg_attrib_##name##_show( \ + struct config_item *item, char *page) \ +{ \ + struct se_portal_group *se_tpg = to_tpg(item); \ + struct efct_lio_tpg *tpg = container_of(se_tpg, \ + struct efct_lio_tpg, tpg); \ + \ + return sprintf(page, "%u\n", tpg->tpg_attrib.name); \ +} \ + \ +static ssize_t efct_lio_tpg_attrib_##name##_store( \ + struct config_item *item, const char *page, size_t count) \ +{ \ + struct se_portal_group *se_tpg = to_tpg(item); \ + struct efct_lio_tpg *tpg = container_of(se_tpg, \ + struct efct_lio_tpg, tpg); \ + struct efct_lio_tpg_attrib *a = &tpg->tpg_attrib; \ + unsigned long val; \ + int ret; \ + \ + ret = kstrtoul(page, 0, &val); \ + if (ret < 0) { \ + pr_err("kstrtoul() failed with ret: %d\n", ret); \ + return ret; \ + } \ + \ + if (val != 0 && val != 1) { \ + pr_err("Illegal boolean value %lu\n", val); \ + return -EINVAL; \ + } \ + \ + a->name = val; \ + \ + return count; \ +} \ +CONFIGFS_ATTR(efct_lio_tpg_attrib_, name) + +DEF_EFCT_TPG_ATTRIB (generate_node_acls); +DEF_EFCT_TPG_ATTRIB (cache_dynamic_acls); +DEF_EFCT_TPG_ATTRIB (demo_mode_write_protect); +DEF_EFCT_TPG_ATTRIB (prod_mode_write_protect); +DEF_EFCT_TPG_ATTRIB (demo_mode_login_only); +DEF_EFCT_TPG_ATTRIB (session_deletion_wait); + +static struct configfs_attribute *efct_lio_tpg_attrib_attrs[] = { + &efct_lio_tpg_attrib_attr_generate_node_acls, + &efct_lio_tpg_attrib_attr_cache_dynamic_acls, + &efct_lio_tpg_attrib_attr_demo_mode_write_protect, + &efct_lio_tpg_attrib_attr_prod_mode_write_protect, + &efct_lio_tpg_attrib_attr_demo_mode_login_only, + &efct_lio_tpg_attrib_attr_session_deletion_wait, +NULL , +}; + +#define DEF_EFCT_NPIV_TPG_ATTRIB (name) \ + \ +static ssize_t efct_lio_npiv_tpg_attrib_##name##_show( \ + struct config_item *item, char *page) \ +{ \ + struct se_portal_group *se_tpg = to_tpg(item); \ + struct efct_lio_tpg *tpg = container_of(se_tpg, \ + struct efct_lio_tpg, tpg); \ + \ + return sprintf(page, "%u\n", tpg->tpg_attrib.name); \ +} \ + \ +static ssize_t efct_lio_npiv_tpg_attrib_##name##_store( \ + struct config_item *item, const char *page, size_t count) \ +{ \ + struct se_portal_group *se_tpg = to_tpg(item); \ + struct efct_lio_tpg *tpg = container_of(se_tpg, \ + struct efct_lio_tpg, tpg); \ + struct efct_lio_tpg_attrib *a = &tpg->tpg_attrib; \ + unsigned long val; \ + int ret; \ + \ + ret = kstrtoul(page, 0, &val); \ + if (ret < 0) { \ + pr_err("kstrtoul() failed with ret: %d\n", ret); \ + return ret; \ + } \ + \ + if (val != 0 && val != 1) { \ + pr_err("Illegal boolean value %lu\n", val); \ + return -EINVAL; \ + } \ + \ + a->name = val; \ + \ + return count; \ +} \ +CONFIGFS_ATTR(efct_lio_npiv_tpg_attrib_, name) + +DEF_EFCT_NPIV_TPG_ATTRIB (generate_node_acls); +DEF_EFCT_NPIV_TPG_ATTRIB (cache_dynamic_acls); +DEF_EFCT_NPIV_TPG_ATTRIB (demo_mode_write_protect); +DEF_EFCT_NPIV_TPG_ATTRIB (prod_mode_write_protect); +DEF_EFCT_NPIV_TPG_ATTRIB (demo_mode_login_only); +DEF_EFCT_NPIV_TPG_ATTRIB (session_deletion_wait); + +static struct configfs_attribute *efct_lio_npiv_tpg_attrib_attrs[] = { + &efct_lio_npiv_tpg_attrib_attr_generate_node_acls, + &efct_lio_npiv_tpg_attrib_attr_cache_dynamic_acls, + &efct_lio_npiv_tpg_attrib_attr_demo_mode_write_protect, + &efct_lio_npiv_tpg_attrib_attr_prod_mode_write_protect, + &efct_lio_npiv_tpg_attrib_attr_demo_mode_login_only, + &efct_lio_npiv_tpg_attrib_attr_session_deletion_wait, +NULL , +}; + +CONFIGFS_ATTR (efct_lio_tpg_, enable); +static struct configfs_attribute *efct_lio_tpg_attrs[] = { + &efct_lio_tpg_attr_enable,NULL }; +CONFIGFS_ATTR (efct_lio_npiv_tpg_, enable); +static struct configfs_attribute *efct_lio_npiv_tpg_attrs[] = { + &efct_lio_npiv_tpg_attr_enable,NULL }; + +static const struct target_core_fabric_ops efct_lio_ops = { + .module =THIS_MODULE , + .fabric_name ="efct" , + .node_acl_size =sizeof (struct efct_lio_nacl ), + .max_data_sg_nents =65535 , + .tpg_get_wwn = efct_lio_get_fabric_wwn, + .tpg_get_tag = efct_lio_get_tag, + .fabric_init_nodeacl = efct_lio_init_nodeacl, + .tpg_check_demo_mode = efct_lio_check_demo_mode, + .tpg_check_demo_mode_cache = efct_lio_check_demo_mode_cache, + .tpg_check_demo_mode_write_protect = efct_lio_check_demo_write_protect, + .tpg_check_prod_mode_write_protect = efct_lio_check_prod_write_protect, + .tpg_get_inst_index = efct_lio_tpg_get_inst_index, + .check_stop_free = efct_lio_check_stop_free, + .aborted_task = efct_lio_aborted_task, + .release_cmd = efct_lio_release_cmd, + .close_session = efct_lio_close_session, + .sess_get_index = efct_lio_sess_get_index, + .write_pending = efct_lio_write_pending, + .set_default_node_attributes = efct_lio_set_default_node_attrs, + .get_cmd_state = efct_lio_get_cmd_state, + .queue_data_in = efct_lio_queue_data_in, + .queue_status = efct_lio_queue_status, + .queue_tm_rsp = efct_lio_queue_tm_rsp, + .fabric_make_wwn = efct_lio_make_sport, + .fabric_drop_wwn = efct_lio_drop_sport, + .fabric_make_tpg = efct_lio_make_tpg, + .fabric_drop_tpg = efct_lio_drop_tpg, + .tpg_check_demo_mode_login_only = efct_lio_check_demo_mode_login_only, + .tpg_check_prot_fabric_only =NULL , + .sess_get_initiator_sid =NULL , + .tfc_tpg_base_attrs = efct_lio_tpg_attrs, + .tfc_tpg_attrib_attrs = efct_lio_tpg_attrib_attrs, +}; + +static const struct target_core_fabric_ops efct_lio_npiv_ops = { + .module =THIS_MODULE , + .fabric_name ="efct_npiv" , + .node_acl_size =sizeof (struct efct_lio_nacl ), + .max_data_sg_nents =65535 , + .tpg_get_wwn = efct_lio_get_npiv_fabric_wwn, + .tpg_get_tag = efct_lio_get_npiv_tag, + .fabric_init_nodeacl = efct_lio_init_nodeacl, + .tpg_check_demo_mode = efct_lio_check_demo_mode, + .tpg_check_demo_mode_cache = efct_lio_check_demo_mode_cache, + .tpg_check_demo_mode_write_protect = + efct_lio_npiv_check_demo_write_protect, + .tpg_check_prod_mode_write_protect = + efct_lio_npiv_check_prod_write_protect, + .tpg_get_inst_index = efct_lio_tpg_get_inst_index, + .check_stop_free = efct_lio_check_stop_free, + .aborted_task = efct_lio_aborted_task, + .release_cmd = efct_lio_release_cmd, + .close_session = efct_lio_close_session, + .sess_get_index = efct_lio_sess_get_index, + .write_pending = efct_lio_write_pending, + .set_default_node_attributes = efct_lio_set_default_node_attrs, + .get_cmd_state = efct_lio_get_cmd_state, + .queue_data_in = efct_lio_queue_data_in, + .queue_status = efct_lio_queue_status, + .queue_tm_rsp = efct_lio_queue_tm_rsp, + .fabric_make_wwn = efct_lio_npiv_make_sport, + .fabric_drop_wwn = efct_lio_npiv_drop_sport, + .fabric_make_tpg = efct_lio_npiv_make_tpg, + .fabric_drop_tpg = efct_lio_npiv_drop_tpg, + .tpg_check_demo_mode_login_only = + efct_lio_npiv_check_demo_mode_login_only, + .tpg_check_prot_fabric_only =NULL , + .sess_get_initiator_sid =NULL , + .tfc_tpg_base_attrs = efct_lio_npiv_tpg_attrs, + .tfc_tpg_attrib_attrs = efct_lio_npiv_tpg_attrib_attrs, +}; + +int efct_scsi_tgt_driver_init (void ) +{ +int rc; + +/* Register the top level struct config_item_type with TCM core */ + rc =target_register_template (&efct_lio_ops); +if (rc <0 ) { +pr_err ("target_fabric_configfs_register failed with %d\n" , rc); +return rc; + } + rc =target_register_template (&efct_lio_npiv_ops); +if (rc <0 ) { +pr_err ("target_fabric_configfs_register failed with %d\n" , rc); +target_unregister_template (&efct_lio_ops); +return rc; + } +return EFC_SUCCESS ; +} + +int efct_scsi_tgt_driver_exit (void ) +{ +target_unregister_template (&efct_lio_ops); +target_unregister_template (&efct_lio_npiv_ops); +return EFC_SUCCESS ; +}
drivers/scsi/elx/efct/efct_lio.h new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
2.16.4