efct: Broadcom (Emulex) FC Target driver
Subsystems (2)
PATCH v9 21/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.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
Use atomic_add_return instead of atomic_add
Use cmpxchg for setting abort_in_progress
--- drivers/scsi/elx/efct/efct_hw.c | 574 ++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 41 +++ 2 files changed, 615 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +574 -0
@@ -1557,3 +1557,577 @@ efct_issue_mbox_rqst(void *base, void *cmd, void *cb, void *arg)return 0 ; } + +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); +list_add_tail (&io->list_entry, &hw->io_inuse); + io->state =EFCT_HW_IO_STATE_INUSE ; + io->abort_reqtag =U32_MAX ; + io->wq = hw->wq_cpu_array[raw_smp_processor_id ()]; +if (!io->wq) { +efc_log_err (hw->os,"WQ not assigned for cpu:%d\n" , +raw_smp_processor_id ()); + io->wq = hw->hw_wq[0 ]; + } +kref_init (&io->ref); + io->release = efct_hw_io_free_internal; + }else { +atomic_add (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; +} + +static void +efct_hw_io_free_move_correct_list (struct efct_hw *hw, +struct efct_hw_io *io) +{ +/* +* When an IO is freed, depending on the exchange busy flag, +* move it to the correct list. +*/ +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); +} + +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 (!list_empty (&io->list_entry) && !list_empty (&hw->io_inuse)) { +list_del_init (&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); +} + +struct efct_hw_io * +efct_hw_io_lookup (struct efct_hw *hw,u32 xri) +{ +u32 ioindex; + + ioindex = xri - hw->sli.ext[SLI4_RSRC_XRI ].base[0 ]; +return hw->io[ioindex]; +} + +int +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 -EIO ; + } + +/* 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 : + +/* 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 =EFCT_TARGET_WRITE_SKIPS ; + + io->n_sge =1 ; +break ; +case EFCT_HW_IO_TARGET_READ : +/* +* For FCP_TSEND64, the first 2 entries are SKIP SGE's +*/ + 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 -EIO ; + } + +/* +* 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 0 ; +} + +int +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 -EIO ; + } + +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 -EIO ; + } + + 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++; + +return 0 ; +} + +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; + +/* +* 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; + + 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, len, status, ext, io->arg); + } + +if (io->abort_done) { +efct_hw_done_t done = io->abort_done; + + io->abort_done =NULL ; +done (io, len, status, ext, io->abort_arg); + } + +/* clear abort bit to indicate abort is complete */ + io->abort_in_progress = false; + +/* 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); +} + +static void +efct_hw_fill_abort_wqe (struct efct_hw *hw,struct efct_hw_wqe *wqe) +{ +struct sli4_abort_wqe *abort = (void *)wqe->wqebuf; + +memset (abort,0 , hw->sli.wqe_size); + + abort->criteria =SLI4_ABORT_CRITERIA_XRI_TAG ; + abort->ia_ir_byte |= wqe->send_abts ?0 :1 ; + +/* Suppress ABTS retries */ + abort->ia_ir_byte |=SLI4_ABRT_WQE_IR ; + + abort->t_tag =cpu_to_le32 (wqe->id); + abort->command =SLI4_WQE_ABORT ; + abort->request_tag =cpu_to_le16 (wqe->abort_reqtag); + + abort->dw10w0_flags =cpu_to_le16 (SLI4_ABRT_WQE_QOSD ); + + abort->cq_id =cpu_to_le16 (SLI4_CQ_DEFAULT ); +} + +int +efct_hw_io_abort (struct efct_hw *hw,struct efct_hw_io *io_to_abort, +bool send_abts,void *cb,void *arg) +{ +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 -EIO ; + } + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os,"cannot send IO abort, HW state=%d\n" , + hw->state); +return -EIO ; + } + +/* take a reference on IO being aborted */ +if (kref_get_unless_zero (&io_to_abort->ref) ==0 ) { +/* command no longer active */ +efc_log_debug (hw->os, +"io not active xri=0x%x tag=0x%x\n" , + io_to_abort->indicator, io_to_abort->reqtag); +return -ENOENT ; + } + +/* Must have a valid WQ reference */ +if (!io_to_abort->wq) { +efc_log_debug (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 -ENOENT ; + } + +/* +* Validation checks complete; now check to see if already being +* aborted, if not set the flag. +*/ +if (cmpxchg (&io_to_abort->abort_in_progress, false, true)) { +/* 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 -EINPROGRESS ; + } + +/* +* 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; + +/* 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 -ENOSPC ; + } + + io_to_abort->abort_reqtag = wqcb->instance_index; + io_to_abort->wqe.send_abts = send_abts; + io_to_abort->wqe.id = io_to_abort->indicator; + io_to_abort->wqe.abort_reqtag = io_to_abort->abort_reqtag; + +/* +* 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; +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, + flags); +return 0 ; + } +spin_unlock_irqrestore (&io_to_abort->wq->queue->lock, flags); + } + +efct_hw_fill_abort_wqe (hw, &io_to_abort->wqe); + +/* 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 +*/ +if (efct_hw_wq_write (io_to_abort->wq, &io_to_abort->wqe)) { + io_to_abort->abort_in_progress = false; +/* efct_ref_get(): same function */ +kref_put (&io_to_abort->ref, io_to_abort->release); +return -EIO ; + } + +return 0 ; +} + +void +efct_hw_reqtag_pool_free (struct efct_hw *hw) +{ +u32 i; +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_init (&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; +}
drivers/scsi/elx/efct/efct_hw.h +41 -0
45 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v9 21/31] elx: efct: Hardware IO and SGL initialization
Hi James,
Quoted 10 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.Co-developed-by Ram Vegesna <[email protected]>Signed-off-by Ram Vegesna <[email protected]>Signed-off-by James Smart <[email protected]>Reviewed-by Daniel Wagner <[email protected]>
The
if (cmpxchg(&io_to_abort->abort_in_progress, false, true)) {
in this patch causes ARCH=arm allmodconfig to fail because CONFIG_CPU_V6=y and older do not support running cmpxchg() on bool (anything less than int from what I can tell) when instrumentation is enabled:
ERROR: modpost: "__bad_cmpxchg" [drivers/scsi/elx/efct.ko] undefined!
https://elixir.bootlin.com/linux/v5.13-rc6/source/arch/arm/include/asm/cmpxchg.h#L164
I guess this could be turned into an int, although the structure grows slightly in size of the cmpxchg could be unrolled, similar to commit f5f4c615982d ("drm: Convert cmpxchg(bool) back to a two step operation").
Cheers,
Nathan
PATCH v9 22/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.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_hw.c | 360 ++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 39 ++++ drivers/scsi/elx/efct/efct_io.c | 191 +++++++++++++++++ drivers/scsi/elx/efct/efct_io.h | 174 +++++++++++++++ 4 files changed, 764 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 +360 -0
@@ -2131,3 +2131,363 @@ efct_hw_reqtag_get_instance(struct efct_hw *hw, u32 instance_index)return wqcb; } + +int +efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id) +{ +int index =-1 ; +int i = 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[i].in_use && hash[i].id == id) + index = hash[i].index; +else + i = (i +1 ) & (EFCT_HW_Q_HASH_SIZE -1 ); + }while (index ==-1 && hash[i].in_use); + +return index; +} + +int +efct_hw_process (struct efct_hw *hw,u32 vector, +u32 max_isr_time_msec) +{ +struct hw_eq *eq; + +/* +* 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 0 ; + +/* Get pointer to struct hw_eq */ + eq = hw->hw_eq[vector]; +if (!eq) +return 0 ; + + eq->use_count++; + +return efct_hw_eq_process (hw, eq, max_isr_time_msec); +} + +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; +u64 tstart; +u64 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 0 ; +} + +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 ) ? -EIO :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_init (&wqe->list_entry); +_efct_hw_wq_write (wq, wqe); + +if (wqe->abort_wqe_submit_needed) { + wqe->abort_wqe_submit_needed = false; +efct_hw_fill_abort_wqe (wq->hw, wqe); +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 ; +/* completion type */ +enum sli4_qentry ctype; +u32 n_processed =0 ; +u32 tstart, telapsed; + + tstart =jiffies_to_msecs (jiffies); + +while (!sli_cq_read (&hw->sli, cq->queue, cqe)) { +int status; + + 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 SLI4_QENTRY_ASYNC : +sli_cqe_async (&hw->sli, cqe); +break ; +case SLI4_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 SLI4_QENTRY_WQ : +efct_hw_wq_process (hw, cq, cqe, status, rid); +break ; +case SLI4_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 SLI4_QENTRY_RQ : +efct_hw_rqpair_process_rq (hw, cq, cqe); +break ; +case SLI4_QENTRY_XABT : { +efct_hw_xabt_process (hw, cq, cqe, rid); +break ; + } +default : +efc_log_debug (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,"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, 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_init (&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 0 ; +}
drivers/scsi/elx/efct/efct_hw.h +39 -0
@@ -652,4 +652,43 @@ efct_hw_reqtag_free(struct efct_hw *hw, struct hw_wq_callback *wqcb);struct hw_wq_callback *efct_hw_reqtag_get_instance (struct efct_hw *hw,u32 instance_index); +/* RQ completion handlers for RQ pair mode */ +int +efct_hw_rqpair_process_rq (struct efct_hw *hw, +struct hw_cq *cq,u8 *cqe); +int +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; +} + +int +efct_efc_hw_sequence_free (struct efc *efc,struct efc_hw_sequence *seq); + +static inline int +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); +} + +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); +void +efct_hw_wq_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,int status,u16 rid); +void +efct_hw_xabt_process (struct efct_hw *hw,struct hw_cq *cq, +u8 *cqe,u16 rid); +int +efct_hw_process (struct efct_hw *hw,u32 vector,u32 max_isr_time_msec); +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 +191 -0
191 lines not on this page · raw message
drivers/scsi/elx/efct/efct_io.h new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v9 23/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.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_unsol.c | 492 +++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_unsol.h | 17 + 2 files changed, 509 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_unsol.c new file +492 -0
@@ -0,0 +1,492 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2021 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.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 struct efct_node * +efct_node_find (struct efct *efct,u32 port_id,u32 node_id) +{ +struct efct_node *node; +u64 id = (u64 )port_id <<32 | node_id; + +/* +* During node shutdown, Lookup will be removed first, +* before announcing to backend. So, no new IOs will be allowed +*/ +/* Find a target node, given s_id and d_id */ + node =xa_load (&efct->lookup, id); +if (node) +kref_get (&node->ref); + +return node; +} + +static int +efct_dispatch_frame (struct efct *efct,struct efc_hw_sequence *seq) +{ +struct efct_node *node; +struct fc_frame_header *hdr; +u32 s_id, d_id; + + hdr = seq->header->dma.virt; + +/* extract the s_id and d_id */ + s_id =ntoh24 (hdr->fh_s_id); + d_id =ntoh24 (hdr->fh_d_id); + +if (!(hdr->fh_type ==FC_TYPE_FCP || hdr->fh_type ==FC_TYPE_BLS )) +return -EIO ; + +if (hdr->fh_type ==FC_TYPE_FCP ) { + node =efct_node_find (efct, d_id, s_id); +if (!node) { +efc_log_err (efct, +"Node not found, drop cmd d_id:%x s_id:%x\n" , + d_id, s_id); +efct_hw_sequence_free (&efct->hw, seq); +return 0 ; + } + +efct_dispatch_fcp_cmd (node, seq); + }else { + node =efct_node_find (efct, d_id, s_id); +if (!node) { +efc_log_err (efct,"ABTS: Node not found, d_id:%x s_id:%x\n" , + d_id, s_id); +return -EIO ; + } + +efc_log_err (efct,"Received ABTS for Node:%p\n" , node); +efct_node_recv_abts_frame (node, seq); + } + +kref_put (&node->ref, node->release); +efct_hw_sequence_free (&efct->hw, seq); +return 0 ; +} + +int +efct_unsolicited_cb (void *arg,struct efc_hw_sequence *seq) +{ +struct efct *efct = arg; + +/* Process FCP command */ +if (!efct_dispatch_frame (efct, seq)) +return 0 ; + +/* Forward frame to discovery lib */ +efc_dispatch_frame (efct->efcport, seq); +return 0 ; +} + +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 0 ; +} + +static void +efct_dispatch_unsol_tmf (struct efct_io *io,u8 tm_flags,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 & tm_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 */ +efc_log_err (io->node->efct,"TMF x%x rejected\n" , tm_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 payload (%zd) less than (%zd)\n" , +be16_to_cpu (fchdr->fh_ox_id), + seq->payload->dma.len,sizeof (struct fcp_cmnd )); +return -EIO ; + } +return 0 ; +} + +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 efct_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->efct; +struct efct_hw *hw = &efct->hw; +int 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 -EIO ; + } + +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 -EIO ; + } + +/* Copy the payload in */ +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_debug (efct,"efct_hw_send_frame failed: %d\n" , rc); + +return rc; +} + +static int +efct_sframe_send_fcp_rsp (struct efct_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 efct_node *node, +struct efc_hw_sequence *seq) +{ +struct fcp_resp_with_ext fcprsp; +struct fcp_cmnd *fcpcmd = seq->payload->dma.virt; +int rc =0 ; +unsigned long flags =0 ; +struct efct *efct = node->efct; + +/* 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 ; +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_debug (efct,"efct_sframe_send_fcp_rsp failed %d\n" , rc); + +return rc; +} + +int +efct_dispatch_fcp_cmd (struct efct_node *node,struct efc_hw_sequence *seq) +{ +struct efct *efct = node->efct; +struct fc_frame_header *fchdr = seq->header->dma.virt; +struct fcp_cmnd *cmnd =NULL ; +struct efct_io *io =NULL ; +u32 lun =U32_MAX ; + +if (!seq->payload) { +efc_log_err (efct,"Sequence payload is NULL.\n" ); +return -EIO ; + } + + cmnd = seq->payload->dma.virt; + +/* perform FCP_CMND validation check(s) */ +if (efct_validate_fcp_cmd (efct, seq)) +return -EIO ; + + lun =scsilun_to_int (&cmnd->fc_lun); +if (lun ==U32_MAX ) +return -EIO ; + + io =efct_scsi_io_alloc (node); +if (!io) { +int rc; + +/* 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_unsol_tmf (io, cmnd->fc_tm_flags, 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 -EIO ; + } +/* +* 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 0 ; +} + +static int +efct_process_abts (struct efct_io *io,struct fc_frame_header *hdr) +{ +struct efct_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 +*/ +efc_log_info (node->efct,"Abort 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, +*/ +efc_log_info (node->efct,"Abort: ox_id [%04x], IO not found\n" , + ox_id); + +/* Send a BA_RJT */ +efct_bls_send_rjt (io, hdr); + } +return 0 ; +} + +int +efct_node_recv_abts_frame (struct efct_node *node,struct efc_hw_sequence *seq) +{ +struct efct *efct = node->efct; +struct fc_frame_header *hdr = seq->header->dma.virt; +struct efct_io *io =NULL ; + + node->abort_cnt++; + io =efct_scsi_io_alloc (node); +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 { +efc_log_err (efct, +"SCSI IO allocation failed for ABTS received " ); +efc_log_err (efct,"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 0 ; +}
drivers/scsi/elx/efct/efct_unsol.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2021 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#if !defined(__OSC_UNSOL_H__) +#define __OSC_UNSOL_H__ + +int +efct_unsolicited_cb (void *arg,struct efc_hw_sequence *seq); +int +efct_dispatch_fcp_cmd (struct efct_node *node,struct efc_hw_sequence *seq); +int +efct_node_recv_abts_frame (struct efct_node *node,struct efc_hw_sequence *seq); + +#endif /* __OSC_UNSOL_H__ */
Signature · 1 line
2.26.2
PATCH v9 24/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.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_scsi.c | 1159 +++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_scsi.h | 203 +++++ 2 files changed, 1362 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 +1159 -0
@@ -0,0 +1,1159 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2021 Broadcom. All Rights Reserved. The term +* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +*/ + +#include "efct_driver.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) + +struct efct_io * +efct_scsi_io_alloc (struct efct_node *node) +{ +struct efct *efct; +struct efct_xport *xport; +struct efct_io *io; +unsigned long flags =0 ; + + efct = node->efct; + + xport = efct->xport; + +spin_lock_irqsave (&node->active_ios_lock, flags); + + io =efct_io_pool_io_alloc (efct->xport->io_pool); +if (!io) { +efc_log_err (efct,"IO alloc Failed\n" ); +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; + +/* set generic fields */ + io->efct = efct; + io->node = node; +kref_get (&node->ref); + +/* set type and name */ + io->io_type =EFCT_IO_TYPE_IO ; + io->display_name ="scsi_io" ; + + io->cmd_ini = false; + io->cmd_tgt = true; + +/* Add to node's active_ios list */ +INIT_LIST_HEAD (&io->list_entry); +list_add (&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 efct_node *node = io->node; +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_init (&io->list_entry); +spin_unlock_irqrestore (&node->active_ios_lock, flags); + +kref_put (&node->ref, node->release); + 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)); +kref_put (&io->ref, io->release); +} + +static void +efct_target_io_cb (struct efct_hw_io *hio,u32 length,int status, +u32 ext_status,void *app) +{ +u32 flags =0 ; +struct efct_io *io = app; +struct efct *efct; +enum efct_scsi_io_status scsi_stat =EFCT_SCSI_STATUS_GOOD ; +efct_scsi_io_cb_t cb; + +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; + +if (!io->scsi_tgt_cb) { +efct_scsi_check_pending (efct); +return ; + } + +/* Call target server completion */ + cb = io->scsi_tgt_cb; + +/* 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 -EIO ; + } + +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 0 ; +} + +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 void +efct_scsi_check_pending_async_cb (struct efct_hw *hw,int status, +u8 *mqe,void *arg) +{ +struct efct_io *io = arg; + +if (io) { +efct_hw_done_t cb = io->hw_cb; + +if (!io->hw_cb) +return ; + + io->hw_cb =NULL ; + (cb)(io->hio,0 ,SLI4_FC_WCQE_STATUS_DISPATCH_ERROR ,0 , io); + } +} + +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; + + io->iparam.fcp_tgt.vpi = io->node->vpi; + io->iparam.fcp_tgt.rpi = io->node->rpi; + io->iparam.fcp_tgt.s_id = io->node->port_fc_id; + io->iparam.fcp_tgt.d_id = io->node->node_fc_id; + io->iparam.fcp_tgt.xmit_len = io->wire_len; + + rc =efct_hw_io_send (&io->efct->hw, io->hio_type, io->hio, + &io->iparam, io->hw_cb, io); +break ; +default : +scsi_io_printf (io,"Unknown IO type=%d\n" , io->io_type); + rc = -EIO ; +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,0 , +SLI4_FC_WCQE_STATUS_SUCCESS ,0 , io); + rc =0 ; +break ; + } + +/* 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 ; +efct_hw_done_t cb = io->hw_cb; + +if (rc != -ENOENT && rc != -EINPROGRESS ) { + status =-1 ; +scsi_io_printf (io,"Failed to abort IO rc=%d\n" , + rc); + } +cb (io->hio,0 , status,0 , io); + rc =0 ; + } + +break ; + } +default : +scsi_io_printf (io,"Unknown IO type=%d\n" , io->io_type); + rc = -EIO ; +break ; + } +return rc; +} + +static struct efct_io * +efct_scsi_dispatch_pending (struct efct *efct) +{ +struct efct_xport *xport = efct->xport; +struct efct_io *io =NULL ; +struct efct_hw_io *hio; +unsigned long flags =0 ; +int status; + +spin_lock_irqsave (&xport->io_pending_lock, flags); + +if (!list_empty (&xport->io_pending_list)) { + io = list_first_entry(&xport->io_pending_list, struct efct_io, + io_pending_link); +list_del_init (&io->io_pending_link); + } + +if (!io) { +spin_unlock_irqrestore (&xport->io_pending_lock, flags); +return NULL ; + } + +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) +return NULL ; + +/* +* 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_debug (efct,"call hw async failed\n" ); + } + } + +return io; +} + +void +efct_scsi_check_pending (struct efct *efct) +{ +struct efct_xport *xport = efct->xport; +struct efct_io *io =NULL ; +int count =0 ; +unsigned long flags =0 ; +int dispatch =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 ; + } + +while (efct_scsi_dispatch_pending (efct)) + count++; + +if (count) { +atomic_sub_return (1 , &xport->io_pending_recursing); +return ; + } + +/* +* 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. +*/ + +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 && io->io_to_abort->hio) { +/* This IO has a HW IO, so it is +* active. Dispatch the abort. +*/ + dispatch =1 ; +list_del_init (&io->io_pending_link); +atomic_sub_return (1 , &xport->io_pending_count); +break ; + } + } + +spin_unlock_irqrestore (&xport->io_pending_lock, flags); + +if (dispatch) { +if (efct_scsi_io_dispatch_no_hw_io (io)) { +if (efct_hw_async_call (&efct->hw, + efct_scsi_check_pending_async_cb, io)) { +efc_log_debug (efct,"hw async failed\n" ); + } + } + } + +atomic_sub_return (1 , &xport->io_pending_recursing); +} + +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 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 0 ; + } + +/* We successfully allocated a HW IO; dispatch to HW */ +return efct_scsi_io_dispatch_hw_io (io, hio); +} + +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 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; + 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; +/* Always try auto resp */ +bool auto_resp = true; +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; + +if (!fcprsp) { +efc_log_err (efct,"NULL response buffer\n" ); +return -EIO ; + } + + sns_data = (u8 *)io->rspbuf.virt +sizeof (*fcprsp); + + 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 -EIO ; + } + + 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,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 0 ; +} + +static int +efct_target_send_bls_resp (struct efct_io *io, +efct_scsi_io_cb_t cb,void *arg) +{ +struct efct_node *node = io->node; +struct sli_bls_params *bls = &io->iparam.bls; +struct efct *efct = node->efct; +struct fc_ba_acc *acc; +int rc; + +/* fill out IO structure with everything needed to send BA_ACC */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + bls->ox_id = io->init_task_tag; + bls->rx_id = io->abort_rx_id; + bls->vpi = io->node->vpi; + bls->rpi = io->node->rpi; + bls->s_id =U32_MAX ; + bls->d_id = io->node->node_fc_id; + bls->rpi_registered = true; + + acc = (void *)bls->payload; + acc->ba_ox_id =cpu_to_be16 (bls->ox_id); + acc->ba_rx_id =cpu_to_be16 (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_hw_bls_send (efct,FC_RCTL_BA_ACC , bls, + efct_target_bls_resp_cb, io); +return rc; +} + +static int efct_bls_send_rjt_cb (struct efct_hw_io *hio,u32 length,int status, +u32 ext_status,void *app) +{ +struct efct_io *io = app; + +efct_scsi_io_free (io); +return 0 ; +} + +struct efct_io * +efct_bls_send_rjt (struct efct_io *io,struct fc_frame_header *hdr) +{ +struct efct_node *node = io->node; +struct sli_bls_params *bls = &io->iparam.bls; +struct efct *efct = node->efct; +struct fc_ba_rjt *acc; +int rc; + +/* 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 =be16_to_cpu (hdr->fh_ox_id); + +/* fill out iparam fields */ +memset (&io->iparam,0 ,sizeof (io->iparam)); + bls->ox_id =be16_to_cpu (hdr->fh_ox_id); + bls->rx_id =be16_to_cpu (hdr->fh_rx_id); + bls->vpi = io->node->vpi; + bls->rpi = io->node->rpi; + bls->s_id =U32_MAX ; + bls->d_id = io->node->node_fc_id; + bls->rpi_registered = true; + + acc = (void *)bls->payload; + acc->br_reason =ELS_RJT_UNAB ; + acc->br_explan =ELS_EXPL_NONE ; + + rc =efct_hw_bls_send (efct,FC_RCTL_BA_RJT , bls, efct_bls_send_rjt_cb, + io); +if (rc) { +efc_log_err (efct,"efct_scsi_io_dispatch() failed: %d\n" , rc); +efct_scsi_io_free (io); + io =NULL ; + } +return io; +} + +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; +struct { +struct fcp_resp_with_ext rsp_ext; +struct fcp_resp_rsp_info info; + } *fcprsp; +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->rsp_ext.resp.fr_flags |=FCP_SNS_LEN_VAL ; + +if (addl_rsp_info) { +memcpy (fcprsp->info._fr_resvd, addl_rsp_info, +sizeof (fcprsp->info._fr_resvd)); + } + fcprsp->info.rsp_code = fcp_rspcode; + + io->wire_len =sizeof (*fcprsp); + + fcprsp->rsp_ext.ext.fr_rsp_len = +cpu_to_be32 (sizeof (struct fcp_resp_rsp_info )); + + 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,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_scsi_io_cb_t abort_cb; +void *abort_cb_arg; + + efct = io->efct; + +if (!io->abort_cb) + goto done; + + abort_cb = io->abort_cb; + 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: +/* 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 0 ; +} + +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 -EIO ; + } + +/* +* 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 -EIO ; + } + +/* 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_debug (io->efct,"completion for non-busy io 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 +203 -0
203 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v9 25/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.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
Use bool for tpg enabled flag:
efct_lio_tpg_get_inst_index() : return 1. efct_lio_sess_get_index(): return 0.
Return tgt_io state from efct_lio_get_cmd_state()
--- drivers/scsi/elx/efct/efct_lio.c | 1698 ++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_lio.h | 189 ++++ 2 files changed, 1887 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 +1698 -0
@@ -0,0 +1,1698 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2021 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" + +/* +* lio_wq is used to call the LIO backed during creation or deletion of +* sessions. This brings serialization to the session management as we create +* single threaded work queue. +*/ +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 0 ; +} + +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 0 ; +} + +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" , 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; + +if (!tpg->nport || !tpg->nport->efct) { +pr_err ("%s: Unable to find EFCT device\n" , __func__); +return -EINVAL ; + } + + efct = tpg->nport->efct; + efc = efct->efcport; + +if (kstrtoul (page,0 , &op) <0 ) +return -EINVAL ; + +if (op ==1 ) { +int ret; + + tpg->enabled = true; +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_nport =NULL ; +efc_log_debug (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->nport) +efct_scsi_tgt_del_nport (efc, efc->domain->nport); + + tpg->enabled = false; + }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" , 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; +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 ) { + tpg->enabled = true; +efc_log_debug (efct,"enable portal group %d\n" , tpg->tpgt); + +if (efc->domain) { +int ret; + + ret =efc_nport_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); + + tpg->enabled = false; +/* only physical nport should exist, free lio_nport +* allocated in efct_lio_make_nport +*/ +if (efc->domain) { +efc_nport_vport_del (efct->efcport, efc->domain, + lio_vport->npiv_wwpn, + lio_vport->npiv_wwnn); +return count; + } + }else { +return -EINVAL ; + } +return count; +} + +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->nport->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 1 ; +} + +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,"Abort done, status:%d\n" , scsi_status); +return 0 ; +} + +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 (ocp->rsp_sent) +return ; + +/* command has been aborted, cleanup here */ + ocp->aborting = true; + ocp->err =EFCT_SCSI_STATUS_ABORTED ; +/* terminate the exchange */ +efct_scsi_tgt_abort_io (io, efct_lio_abort_tgt_cb,NULL ); +} + +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_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_CMPL_CMD ); +efct_scsi_io_complete (io); +atomic_sub_return (1 , &efct->tgt_efct.ios_in_use); +} + +static void efct_lio_close_session (struct se_session *se_sess) +{ +struct efc_node *node = se_sess->fabric_sess_ptr; + +pr_debug ("se_sess=%p node=%p" , se_sess, node); + +if (!node) { +pr_debug ("node is NULL" ); +return ; + } + +efc_node_post_shutdown (node,NULL ); +} + +static u32 efct_lio_sess_get_index (struct se_session *se_sess) +{ +return 0 ; +} + +static void efct_lio_set_default_node_attrs (struct se_node_acl *nacl) +{ +} + +static int efct_lio_get_cmd_state (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); + +if (!io) +return 0 ; + +return io->tgt_io.state; +} + +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->pci, cmd->t_data_sg, + cmd->t_data_nents, cmd->data_direction); +if (ocp->seg_map_cnt ==0 ) +return -EFAULT ; +return 0 ; +} + +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->pci, 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); + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_GENERIC_FREE ); +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +return 0 ; +} + +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 ; + +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)) + ;/* do nothing */ + +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 ; + +return efct_scsi_recv_wr_data (io, flags, sgl, curcnt, length, + efct_lio_datamove_done,NULL ); +} + +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 ; + +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 ; + +efct_set_lio_io_state (io,EFCT_LIO_STATE_SCSI_SEND_RD_DATA ); + +return efct_scsi_send_rd_data (io, flags, sgl, curcnt, length, + efct_lio_datamove_done,NULL ); +} + +static void +efct_lio_send_resp (struct efct_io *io,enum efct_scsi_io_status scsi_status, +u32 flags) +{ +struct efct_scsi_cmd_resp rsp; +struct efct_scsi_tgt_io *ocp = &io->tgt_io; +struct se_cmd *cmd = &io->tgt_io.cmd; +int rc; + +if (flags &EFCT_SCSI_IO_CMPL_RSP_SENT ) { + ocp->rsp_sent = true; +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_GENERIC_FREE ); +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +return ; + } + +/* 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, send rsp failed %d\n" , rc); +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_GENERIC_FREE ); +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); + }else { + ocp->rsp_sent = true; + } +} + +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; + +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) { +int rc; + +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) +return 0 ; + + 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 0 ; + } + +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 { +efct_lio_send_resp (io, scsi_status, flags); + } +return 0 ; +} + +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); + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_GENERIC_FREE ); +transport_generic_free_cmd (&io->tgt_io.cmd,0 ); +return 0 ; +} + +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 0 ; +} + +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) +{ +struct efct *efct; + +/* Search for the HBA that has this WWPN */ +list_for_each_entry (efct, &efct_devices, list_entry) { + +if (wwpn ==efct_get_wwpn (&efct->hw)) +return efct; + } + +return NULL ; +} + +static struct se_wwn * +efct_lio_make_nport (struct target_fabric_configfs *tf, +struct config_group *group,const char *name) +{ +struct efct_lio_nport *lio_nport; +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_nport =kzalloc (sizeof (*lio_nport),GFP_KERNEL ); +if (!lio_nport) +return ERR_PTR (-ENOMEM ); + + lio_nport->efct = efct; + lio_nport->wwpn = wwpn; +efct_format_wwn (lio_nport->wwpn_str,sizeof (lio_nport->wwpn_str), +"naa." , wwpn); + efct->tgt_efct.lio_nport = lio_nport; + +return &lio_nport->nport_wwn; +} + +static struct se_wwn * +efct_lio_npiv_make_nport (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 =kzalloc (sizeof (*vport_list),GFP_KERNEL ); +if (!vport_list) { +kfree (lio_vport); +return ERR_PTR (-ENOMEM ); + } + + 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); + +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_nport (struct se_wwn *wwn) +{ +struct efct_lio_nport *lio_nport = + container_of(wwn, struct efct_lio_nport, nport_wwn); +struct efct *efct = lio_nport->efct; + +/* only physical nport should exist, free lio_nport allocated +* in efct_lio_make_nport. +*/ +kfree (efct->tgt_efct.lio_nport); + efct->tgt_efct.lio_nport =NULL ; +} + +static void +efct_lio_npiv_drop_nport (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); + +if (lio_vport->fc_vport) +fc_vport_terminate (lio_vport->fc_vport); + +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_nport *lio_nport = + container_of(wwn, struct efct_lio_nport, nport_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->nport = lio_nport; + tpg->tpgt = n; + tpg->enabled = false; + + 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_nport->efct; + efct->tgt_efct.tpg = tpg; +efc_log_debug (efct,"create portal group %d\n" , tpg->tpgt); + +xa_init (&efct->lookup); +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); + +struct efct *efct = tpg->nport->efct; + +efc_log_debug (efct,"drop portal group %d\n" , tpg->tpgt); + tpg->nport->efct->tgt_efct.tpg =NULL ; +core_tpg_deregister (se_tpg); +xa_destroy (&efct->lookup); +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; + tpg->enabled = false; + + 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 0 ; +} + +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->nport->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_debug (efct,"found tpg on vport\n" ); + tpg = lio_vport->tpg; +break ; + } + } +spin_unlock_irqrestore (&efct->tgt_efct.efct_lio_lock, flags); +return tpg; +} + +static void +_efct_tgt_node_free (struct kref *arg) +{ + struct efct_node *tgt_node = container_of(arg, struct efct_node, ref); +struct efc_node *node = tgt_node->node; + +efc_scsi_del_initiator_complete (node->efc, node); +kfree (tgt_node); +} + +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_node *tgt_node; +struct efct *efct = node->efc->base; + + tgt_node =kzalloc (sizeof (*tgt_node),GFP_KERNEL ); +if (!tgt_node) +return -ENOMEM ; + +kref_init (&tgt_node->ref); + tgt_node->release = _efct_tgt_node_free; + + tgt_node->session = se_sess; + node->tgt_node = tgt_node; + tgt_node->efct = efct; + + tgt_node->node = node; + + tgt_node->node_fc_id = node->rnode.fc_id; + tgt_node->port_fc_id = node->nport->fc_id; + tgt_node->vpi = node->nport->indicator; + tgt_node->rpi = node->rnode.indicator; + +spin_lock_init (&tgt_node->active_ios_lock); +INIT_LIST_HEAD (&tgt_node->active_ios); + +return 0 ; +} + +int efct_scsi_tgt_new_device (struct efct *efct) +{ +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 -EIO ; + } + +spin_lock_init (&efct->tgt_efct.efct_lio_lock); +INIT_LIST_HEAD (&efct->tgt_efct.vport_list); + +return 0 ; +} + +int efct_scsi_tgt_del_device (struct efct *efct) +{ +flush_workqueue (lio_wq); + +return 0 ; +} + +int +efct_scsi_tgt_new_nport (struct efc *efc,struct efc_nport *nport) +{ +struct efct *efct = nport->efc->base; + +efc_log_debug (efct,"New SPORT: %s bound to %s\n" , nport->display_name, + efct->tgt_efct.lio_nport->wwpn_str); + +return 0 ; +} + +void +efct_scsi_tgt_del_nport (struct efc *efc,struct efc_nport *nport) +{ +efc_log_debug (efc,"Del SPORT: %s\n" , nport->display_name); +} + +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; +struct efct_node *tgt_node; +struct se_portal_group *se_tpg; +struct se_session *se_sess; +int watermark; +int ini_count; +u64 id; + +/* 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" ); +kfree (wq_data); +efc_scsi_sess_reg_complete (node, -EIO ); +return ; + } + +efc_log_debug (efct,"new initiator sess=%p node=%p id: %llx\n" , + se_sess, node, id); + + tgt_node = node->tgt_node; + id = (u64 ) tgt_node->port_fc_id <<32 | tgt_node->node_fc_id; + +if (xa_err (xa_store (&efct->lookup, id, tgt_node,GFP_KERNEL ))) +efc_log_err (efct,"Node lookup store failed\n" ); + +efc_scsi_sess_reg_complete (node,0 ); + +/* update IO watermark: increment initiator count */ + ini_count =atomic_add_return (1 , &efct->tgt_efct.initiator_count); + watermark = efct->tgt_efct.watermark_max - + ini_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); +} + +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_SCSI_CALL_ASYNC ; +} + +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_node *tgt_node; +struct se_session *se_sess; + + tgt_node = node->tgt_node; +if (!tgt_node) { +/* base driver has sent back-to-back requests +* to unreg session with no intervening +* register +*/ +efc_log_err (efct,"unreg session for NULL session\n" ); +efc_scsi_del_initiator_complete (node->efc, node); +return ; + } + + se_sess = tgt_node->session; +efc_log_debug (efct,"unreg session se_sess=%p node=%p\n" , + se_sess, node); + +/* first flag all session commands to complete */ +target_stop_session (se_sess); + +/* now wait for session commands to complete */ +target_wait_for_sess_cmds (se_sess); +target_remove_session (se_sess); + tgt_node->session =NULL ; + node->tgt_node =NULL ; +kref_put (&tgt_node->ref, tgt_node->release); + +kfree (wq_data); +} + +int efct_scsi_del_initiator (struct efc *efc,struct efc_node *node,int reason) +{ +struct efct *efct = node->efc->base; +struct efct_node *tgt_node = node->tgt_node; +struct efct_lio_wq_data *wq_data; +int watermark; +int ini_count; +u64 id; + +if (reason ==EFCT_SCSI_INITIATOR_MISSING ) +return EFC_SCSI_CALL_COMPLETE ; + +if (!tgt_node) { +efc_log_err (efct,"tgt_node is NULL\n" ); +return -EIO ; + } + + wq_data =kzalloc (sizeof (*wq_data),GFP_ATOMIC ); +if (!wq_data) +return -ENOMEM ; + + id = (u64 ) tgt_node->port_fc_id <<32 | tgt_node->node_fc_id; +xa_erase (&efct->lookup, id); + + 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 +*/ + ini_count =atomic_sub_return (1 , &efct->tgt_efct.initiator_count); + + watermark = efct->tgt_efct.watermark_max - + ini_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 EFC_SCSI_CALL_ASYNC ; +} + +void 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 se_cmd *se_cmd = &io->tgt_io.cmd; +struct efct *efct = io->efct; +char *ddir; +struct efct_node *tgt_node; +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; + se_sess = tgt_node->session; +if (!se_sess) { +efc_log_err (efct,"No session found to submit IO se_cmd: %p\n" , + &ocp->cmd); +efct_scsi_io_free (io); +return ; + } + +efct_set_lio_io_state (io,EFCT_LIO_STATE_TGT_SUBMIT_CMD ); + rc =target_init_cmd (se_cmd, se_sess, &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 init cmd se_cmd: %p\n" , se_cmd); +efct_scsi_io_free (io); +return ; + } + +if (target_submit_prep (se_cmd, cdb,NULL ,0 ,NULL ,0 , +NULL ,0 ,GFP_ATOMIC )) +return ; + +target_submit (se_cmd); +} + +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_node *tgt_node; +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; + + se_sess = tgt_node->session; +if (!se_sess) +return 0 ; + + 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 0 ; + +tmf_fail: +efct_scsi_send_tmf_resp (tmfio,EFCT_SCSI_TMF_FUNCTION_REJECTED , +NULL , efct_lio_null_tmf_done,NULL ); +return 0 ; +} + +/* 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_nport, + .fabric_drop_wwn = efct_lio_drop_nport, + .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_nport, + .fabric_drop_wwn = efct_lio_npiv_drop_nport, + .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 0 ; +} + +int efct_scsi_tgt_driver_exit (void ) +{ +target_unregister_template (&efct_lio_ops); +target_unregister_template (&efct_lio_npiv_ops); +return 0 ; +}
drivers/scsi/elx/efct/efct_lio.h new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v9 26/31 elx: efct: Hardware IO submission routines
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines that write IO to Work queue, send SRRs and raw frames.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_hw.c | 511 ++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 14 + 2 files changed, 525 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +511 -0
@@ -2491,3 +2491,514 @@ efct_hw_flush(struct efct_hw *hw)return 0 ; } + +int +efct_hw_wq_write (struct hw_wq *wq,struct efct_hw_wqe *wqe) +{ +int rc =0 ; +unsigned long flags =0 ; + +spin_lock_irqsave (&wq->queue->lock, flags); +if (list_empty (&wq->pending_list)) { +if (wq->free_count >0 ) { + rc =_efct_hw_wq_write (wq, wqe); + }else { +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); +return rc; + } + +INIT_LIST_HEAD (&wqe->list_entry); +list_add_tail (&wqe->list_entry, &wq->pending_list); + wq->wq_pending_count++; +while (wq->free_count >0 ) { + wqe = list_first_entry(&wq->pending_list, struct efct_hw_wqe, + list_entry); +if (!wqe) +break ; + +list_del_init (&wqe->list_entry); + rc =_efct_hw_wq_write (wq, wqe); +if (rc) +break ; + +if (wqe->abort_wqe_submit_needed) { + wqe->abort_wqe_submit_needed = false; +efct_hw_fill_abort_wqe (wq->hw, wqe); + +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); + +return rc; +} + +int +efct_efc_bls_send (struct efc *efc,u32 type,struct sli_bls_params *bls) +{ +struct efct *efct = efc->base; + +return efct_hw_bls_send (efct, type, bls,NULL ,NULL ); +} + +int +efct_hw_bls_send (struct efct *efct,u32 type,struct sli_bls_params *bls_params, +void *cb,void *arg) +{ +struct efct_hw *hw = &efct->hw; +struct efct_hw_io *hio; +struct sli_bls_payload bls; +int rc; + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os, +"cannot send BLS, HW state=%d\n" , hw->state); +return -EIO ; + } + + hio =efct_hw_io_alloc (hw); +if (!hio) { +efc_log_err (hw->os,"HIO allocation failed\n" ); +return -EIO ; + } + + hio->done = cb; + hio->arg = arg; + + bls_params->xri = hio->indicator; + bls_params->tag = hio->reqtag; + +if (type ==FC_RCTL_BA_ACC ) { + hio->type =EFCT_HW_BLS_ACC ; + bls.type =SLI4_SLI_BLS_ACC ; +memcpy (&bls.u.acc, bls_params->payload,sizeof (bls.u.acc)); + }else { + hio->type =EFCT_HW_BLS_RJT ; + bls.type =SLI4_SLI_BLS_RJT ; +memcpy (&bls.u.rjt, bls_params->payload,sizeof (bls.u.rjt)); + } + + bls.ox_id =cpu_to_le16 (bls_params->ox_id); + bls.rx_id =cpu_to_le16 (bls_params->rx_id); + +if (sli_xmit_bls_rsp64_wqe (&hw->sli, hio->wqe.wqebuf, + &bls, bls_params)) { +efc_log_err (hw->os,"XMIT_BLS_RSP64 WQE error\n" ); +return -EIO ; + } + + hio->xbusy = true; + +/* +* Add IO to active io wqe list before submitting, in case the +* wcqe processing preempts this thread. +*/ + hio->wq->use_count++; + rc =efct_hw_wq_write (hio->wq, &hio->wqe); +if (rc >=0 ) { +/* non-negative return is success */ + rc =0 ; + }else { +/* failed to write wqe, remove from active wqe list */ +efc_log_err (hw->os, +"sli_queue_write failed: %d\n" , rc); + hio->xbusy = false; + } + +return rc; +} + +static int +efct_els_ssrs_send_cb (struct efct_hw_io *hio,u32 length,int status, +u32 ext_status,void *arg) +{ +struct efc_disc_io *io = arg; + +efc_disc_io_complete (io, length, status, ext_status); +return 0 ; +} + +static inline void +efct_fill_els_params (struct efc_disc_io *io,struct sli_els_params *params) +{ +u8 *cmd = io->req.virt; + + params->cmd = *cmd; + params->s_id = io->s_id; + params->d_id = io->d_id; + params->ox_id = io->iparam.els.ox_id; + params->rpi = io->rpi; + params->vpi = io->vpi; + params->rpi_registered = io->rpi_registered; + params->xmit_len = io->xmit_len; + params->rsp_len = io->rsp_len; + params->timeout = io->iparam.els.timeout; +} + +static inline void +efct_fill_ct_params (struct efc_disc_io *io,struct sli_ct_params *params) +{ + params->r_ctl = io->iparam.ct.r_ctl; + params->type = io->iparam.ct.type; + params->df_ctl = io->iparam.ct.df_ctl; + params->d_id = io->d_id; + params->ox_id = io->iparam.ct.ox_id; + params->rpi = io->rpi; + params->vpi = io->vpi; + params->rpi_registered = io->rpi_registered; + params->xmit_len = io->xmit_len; + params->rsp_len = io->rsp_len; + params->timeout = io->iparam.ct.timeout; +} + +/** +* efct_els_hw_srrs_send() - Send a single request and response cmd. +* @efc: efc library structure +* @io: Discovery IO used to hold els and ct cmd context. +* +* This routine supports communication sequences consisting of a single +* request and single response between two endpoints. Examples include: +* - Sending an ELS request. +* - Sending an ELS response - To send an ELS response, the caller must provide +* the OX_ID from the received request. +* - Sending a FC Common Transport (FC-CT) request - To send a FC-CT request, +* the caller must provide the R_CTL, TYPE, and DF_CTL +* values to place in the FC frame header. +* +* Return: Status of the request. +*/ +int +efct_els_hw_srrs_send (struct efc *efc,struct efc_disc_io *io) +{ +struct efct *efct = efc->base; +struct efct_hw_io *hio; +struct efct_hw *hw = &efct->hw; +struct efc_dma *send = &io->req; +struct efc_dma *receive = &io->rsp; +struct sli4_sge *sge =NULL ; +int rc =0 ; +u32 len = io->xmit_len; +u32 sge0_flags; +u32 sge1_flags; + + hio =efct_hw_io_alloc (hw); +if (!hio) { +pr_err ("HIO alloc failed\n" ); +return -EIO ; + } + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_debug (hw->os, +"cannot send SRRS, HW state=%d\n" , hw->state); +return -EIO ; + } + + hio->done = efct_els_ssrs_send_cb; + hio->arg = io; + + sge = hio->sgl->virt; + +/* clear both SGE */ +memset (hio->sgl->virt,0 ,2 *sizeof (struct sli4_sge )); + + sge0_flags =le32_to_cpu (sge[0 ].dw2_flags); + sge1_flags =le32_to_cpu (sge[1 ].dw2_flags); +if (send->size) { + sge[0 ].buffer_address_high = +cpu_to_le32 (upper_32_bits (send->phys)); + sge[0 ].buffer_address_low = +cpu_to_le32 (lower_32_bits (send->phys)); + + sge0_flags |= (SLI4_SGE_TYPE_DATA <<SLI4_SGE_TYPE_SHIFT ); + + sge[0 ].buffer_length =cpu_to_le32 (len); + } + +if (io->io_type ==EFC_DISC_IO_ELS_REQ || + io->io_type ==EFC_DISC_IO_CT_REQ ) { + sge[1 ].buffer_address_high = +cpu_to_le32 (upper_32_bits (receive->phys)); + sge[1 ].buffer_address_low = +cpu_to_le32 (lower_32_bits (receive->phys)); + + sge1_flags |= (SLI4_SGE_TYPE_DATA <<SLI4_SGE_TYPE_SHIFT ); + sge1_flags |=SLI4_SGE_LAST ; + + sge[1 ].buffer_length =cpu_to_le32 (receive->size); + }else { + sge0_flags |=SLI4_SGE_LAST ; + } + + sge[0 ].dw2_flags =cpu_to_le32 (sge0_flags); + sge[1 ].dw2_flags =cpu_to_le32 (sge1_flags); + +switch (io->io_type) { +case EFC_DISC_IO_ELS_REQ : { +struct sli_els_params els_params; + + hio->type =EFCT_HW_ELS_REQ ; +efct_fill_els_params (io, &els_params); + els_params.xri = hio->indicator; + els_params.tag = hio->reqtag; + +if (sli_els_request64_wqe (&hw->sli, hio->wqe.wqebuf, hio->sgl, + &els_params)) { +efc_log_err (hw->os,"REQ WQE error\n" ); + rc = -EIO ; + } +break ; + } +case EFC_DISC_IO_ELS_RESP : { +struct sli_els_params els_params; + + hio->type =EFCT_HW_ELS_RSP ; +efct_fill_els_params (io, &els_params); + els_params.xri = hio->indicator; + els_params.tag = hio->reqtag; +if (sli_xmit_els_rsp64_wqe (&hw->sli, hio->wqe.wqebuf, send, + &els_params)){ +efc_log_err (hw->os,"RSP WQE error\n" ); + rc = -EIO ; + } +break ; + } +case EFC_DISC_IO_CT_REQ : { +struct sli_ct_params ct_params; + + hio->type =EFCT_HW_FC_CT ; +efct_fill_ct_params (io, &ct_params); + ct_params.xri = hio->indicator; + ct_params.tag = hio->reqtag; +if (sli_gen_request64_wqe (&hw->sli, hio->wqe.wqebuf, hio->sgl, + &ct_params)){ +efc_log_err (hw->os,"GEN WQE error\n" ); + rc = -EIO ; + } +break ; + } +case EFC_DISC_IO_CT_RESP : { +struct sli_ct_params ct_params; + + hio->type =EFCT_HW_FC_CT_RSP ; +efct_fill_ct_params (io, &ct_params); + ct_params.xri = hio->indicator; + ct_params.tag = hio->reqtag; +if (sli_xmit_sequence64_wqe (&hw->sli, hio->wqe.wqebuf, hio->sgl, + &ct_params)){ +efc_log_err (hw->os,"XMIT SEQ WQE error\n" ); + rc = -EIO ; + } +break ; + } +default : +efc_log_err (hw->os,"bad SRRS type %#x\n" , io->io_type); + rc = -EIO ; + } + +if (rc ==0 ) { + hio->xbusy = true; + +/* +* Add IO to active io wqe list before submitting, in case the +* wcqe processing preempts this thread. +*/ + hio->wq->use_count++; + rc =efct_hw_wq_write (hio->wq, &hio->wqe); +if (rc >=0 ) { +/* non-negative return is success */ + rc =0 ; + }else { +/* failed to write wqe, remove from active wqe list */ +efc_log_err (hw->os, +"sli_queue_write failed: %d\n" , rc); + hio->xbusy = false; + } + } + +return rc; +} + +int +efct_hw_io_send (struct efct_hw *hw,enum efct_hw_io_type type, +struct efct_hw_io *io,union efct_hw_io_param_u *iparam, +void *cb,void *arg) +{ +int rc =0 ; +bool send_wqe = true; + +if (!io) { +pr_err ("bad parm hw=%p io=%p\n" , hw, io); +return -EIO ; + } + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) { +efc_log_err (hw->os,"cannot send IO, HW state=%d\n" , hw->state); +return -EIO ; + } + +/* +* Save state needed during later stages +*/ + io->type = type; + io->done = cb; + io->arg = arg; + +/* +* Format the work queue entry used to send the IO +*/ +switch (type) { +case EFCT_HW_IO_TARGET_WRITE : { +u16 *flags = &iparam->fcp_tgt.flags; +struct fcp_txrdy *xfer = io->xfer_rdy.virt; + +/* +* Fill in the XFER_RDY for IF_TYPE 0 devices +*/ + xfer->ft_data_ro =cpu_to_be32 (iparam->fcp_tgt.offset); + xfer->ft_burst_len =cpu_to_be32 (iparam->fcp_tgt.xmit_len); + +if (io->xbusy) + *flags |=SLI4_IO_CONTINUATION ; +else + *flags &= ~SLI4_IO_CONTINUATION ; + iparam->fcp_tgt.xri = io->indicator; + iparam->fcp_tgt.tag = io->reqtag; + +if (sli_fcp_treceive64_wqe (&hw->sli, io->wqe.wqebuf, + &io->def_sgl, io->first_data_sge, +SLI4_CQ_DEFAULT , +0 ,0 , &iparam->fcp_tgt)) { +efc_log_err (hw->os,"TRECEIVE WQE error\n" ); + rc = -EIO ; + } +break ; + } +case EFCT_HW_IO_TARGET_READ : { +u16 *flags = &iparam->fcp_tgt.flags; + +if (io->xbusy) + *flags |=SLI4_IO_CONTINUATION ; +else + *flags &= ~SLI4_IO_CONTINUATION ; + + iparam->fcp_tgt.xri = io->indicator; + iparam->fcp_tgt.tag = io->reqtag; + +if (sli_fcp_tsend64_wqe (&hw->sli, io->wqe.wqebuf, + &io->def_sgl, io->first_data_sge, +SLI4_CQ_DEFAULT , +0 ,0 , &iparam->fcp_tgt)) { +efc_log_err (hw->os,"TSEND WQE error\n" ); + rc = -EIO ; + } +break ; + } +case EFCT_HW_IO_TARGET_RSP : { +u16 *flags = &iparam->fcp_tgt.flags; + +if (io->xbusy) + *flags |=SLI4_IO_CONTINUATION ; +else + *flags &= ~SLI4_IO_CONTINUATION ; + + iparam->fcp_tgt.xri = io->indicator; + iparam->fcp_tgt.tag = io->reqtag; + +if (sli_fcp_trsp64_wqe (&hw->sli, io->wqe.wqebuf, + &io->def_sgl,SLI4_CQ_DEFAULT , +0 , &iparam->fcp_tgt)) { +efc_log_err (hw->os,"TRSP WQE error\n" ); + rc = -EIO ; + } + +break ; + } +default : +efc_log_err (hw->os,"unsupported IO type %#x\n" , type); + rc = -EIO ; + } + +if (send_wqe && rc ==0 ) { + io->xbusy = true; + +/* +* Add IO to active io wqe list before submitting, in case the +* wcqe processing preempts this thread. +*/ + hw->tcmd_wq_submit[io->wq->instance]++; + io->wq->use_count++; + rc =efct_hw_wq_write (io->wq, &io->wqe); +if (rc >=0 ) { +/* non-negative return is success */ + rc =0 ; + }else { +/* failed to write wqe, remove from active wqe list */ +efc_log_err (hw->os, +"sli_queue_write failed: %d\n" , rc); + io->xbusy = false; + } + } + +return rc; +} + +int +efct_hw_send_frame (struct efct_hw *hw,struct fc_frame_header *hdr, +u8 sof,u8 eof,struct efc_dma *payload, +struct efct_hw_send_frame_context *ctx, +void (*callback)(void *arg,u8 *cqe,int status), +void *arg) +{ +int rc; +struct efct_hw_wqe *wqe; +u32 xri; +struct hw_wq *wq; + + wqe = &ctx->wqe; + +/* populate the callback object */ + ctx->hw = hw; + +/* Fetch and populate request tag */ + ctx->wqcb =efct_hw_reqtag_alloc (hw, callback, arg); +if (!ctx->wqcb) { +efc_log_err (hw->os,"can't allocate request tag\n" ); +return -ENOSPC ; + } + + wq = hw->hw_wq[0 ]; + +/* Set XRI and RX_ID in the header based on which WQ, and which +* send_frame_io we are using +*/ + xri = wq->send_frame_io->indicator; + +/* Build the send frame WQE */ + rc =sli_send_frame_wqe (&hw->sli, wqe->wqebuf, + sof, eof, (u32 *)hdr, payload, payload->len, +EFCT_HW_SEND_FRAME_TIMEOUT , xri, + ctx->wqcb->instance_index); +if (rc) { +efc_log_err (hw->os,"sli_send_frame_wqe failed: %d\n" , rc); +return -EIO ; + } + +/* Write to WQ */ + rc =efct_hw_wq_write (wq, wqe); +if (rc) { +efc_log_err (hw->os,"efct_hw_wq_write failed: %d\n" , rc); +return -EIO ; + } + + wq->use_count++; + +return 0 ; +}
drivers/scsi/elx/efct/efct_hw.h +14 -0
@@ -690,5 +690,19 @@ int efct_hw_process(struct efct_hw *hw, u32 vector, u32 max_isr_time_msec);int efct_hw_queue_hash_find (struct efct_queue_hash *hash,u16 id); +int efct_hw_wq_write (struct hw_wq *wq,struct efct_hw_wqe *wqe); +int +efct_hw_send_frame (struct efct_hw *hw,struct fc_frame_header *hdr, +u8 sof,u8 eof,struct efc_dma *payload, +struct efct_hw_send_frame_context *ctx, +void (*callback)(void *arg,u8 *cqe,int status), +void *arg); +int +efct_els_hw_srrs_send (struct efc *efc,struct efc_disc_io *io); +int +efct_efc_bls_send (struct efc *efc,u32 type,struct sli_bls_params *bls); +int +efct_hw_bls_send (struct efct *efct,u32 type,struct sli_bls_params *bls_params, +void *cb,void *arg);#endif /* __EFCT_H__ */
Signature · 1 line
2.26.2
PATCH v9 27/31 elx: efct: link and host statistics
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines to retrieve link stats and host stats. Add Firmware update helper routines.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_hw.c | 327 ++++++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 29 +++ 2 files changed, 356 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +327 -0
@@ -8,6 +8,23 @@#include "efct_hw.h" #include "efct_unsol.h" +struct efct_hw_link_stat_cb_arg { +void (*cb)(int status,u32 num_counters, +struct efct_hw_link_stat_counts *counters,void *arg); +void *arg; +}; + +struct efct_hw_host_stat_cb_arg { +void (*cb)(int status,u32 num_counters, +struct efct_hw_host_stat_counts *counters,void *arg); +void *arg; +}; + +struct efct_hw_fw_wr_cb_arg { +void (*cb)(int status,u32 bytes_written,u32 change_status,void *arg); +void *arg; +}; +struct efct_mbox_rqst_ctx {int (*callback)(struct efc *efc,int status,u8 *mqe,void *arg);void *arg;
@@ -3002,3 +3019,313 @@ efct_hw_send_frame(struct efct_hw *hw, struct fc_frame_header *hdr,return 0 ; } + +static int +efct_hw_cb_link_stat (struct efct_hw *hw,int status, +u8 *mqe,void *arg) +{ +struct sli4_cmd_read_link_stats *mbox_rsp; +struct efct_hw_link_stat_cb_arg *cb_arg = arg; +struct efct_hw_link_stat_counts counts[EFCT_HW_LINK_STAT_MAX ]; +u32 num_counters, i; +u32 mbox_rsp_flags =0 ; + + mbox_rsp = (struct sli4_cmd_read_link_stats *)mqe; + mbox_rsp_flags =le32_to_cpu (mbox_rsp->dw1_flags); + num_counters = (mbox_rsp_flags &SLI4_READ_LNKSTAT_GEC ) ?20 :13 ; +memset (counts,0 ,sizeof (struct efct_hw_link_stat_counts ) * +EFCT_HW_LINK_STAT_MAX ); + +/* Fill overflow counts, mask starts from SLI4_READ_LNKSTAT_W02OF*/ +for (i =0 ; i <EFCT_HW_LINK_STAT_MAX ; i++) + counts[i].overflow = (mbox_rsp_flags & (1 << (i +2 ))); + + counts[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT ].counter = +le32_to_cpu (mbox_rsp->linkfail_errcnt); + counts[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT ].counter = +le32_to_cpu (mbox_rsp->losssync_errcnt); + counts[EFCT_HW_LINK_STAT_LOSS_OF_SIGNAL_COUNT ].counter = +le32_to_cpu (mbox_rsp->losssignal_errcnt); + counts[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT ].counter = +le32_to_cpu (mbox_rsp->primseq_errcnt); + counts[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT ].counter = +le32_to_cpu (mbox_rsp->inval_txword_errcnt); + counts[EFCT_HW_LINK_STAT_CRC_COUNT ].counter = +le32_to_cpu (mbox_rsp->crc_errcnt); + counts[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_TIMEOUT_COUNT ].counter = +le32_to_cpu (mbox_rsp->primseq_eventtimeout_cnt); + counts[EFCT_HW_LINK_STAT_ELASTIC_BUFFER_OVERRUN_COUNT ].counter = +le32_to_cpu (mbox_rsp->elastic_bufoverrun_errcnt); + counts[EFCT_HW_LINK_STAT_ARB_TIMEOUT_COUNT ].counter = +le32_to_cpu (mbox_rsp->arbit_fc_al_timeout_cnt); + counts[EFCT_HW_LINK_STAT_ADVERTISED_RCV_B2B_CREDIT ].counter = +le32_to_cpu (mbox_rsp->adv_rx_buftor_to_buf_credit); + counts[EFCT_HW_LINK_STAT_CURR_RCV_B2B_CREDIT ].counter = +le32_to_cpu (mbox_rsp->curr_rx_buf_to_buf_credit); + counts[EFCT_HW_LINK_STAT_ADVERTISED_XMIT_B2B_CREDIT ].counter = +le32_to_cpu (mbox_rsp->adv_tx_buf_to_buf_credit); + counts[EFCT_HW_LINK_STAT_CURR_XMIT_B2B_CREDIT ].counter = +le32_to_cpu (mbox_rsp->curr_tx_buf_to_buf_credit); + counts[EFCT_HW_LINK_STAT_RCV_EOFA_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_eofa_cnt); + counts[EFCT_HW_LINK_STAT_RCV_EOFDTI_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_eofdti_cnt); + counts[EFCT_HW_LINK_STAT_RCV_EOFNI_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_eofni_cnt); + counts[EFCT_HW_LINK_STAT_RCV_SOFF_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_soff_cnt); + counts[EFCT_HW_LINK_STAT_RCV_DROPPED_NO_AER_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_dropped_no_aer_cnt); + counts[EFCT_HW_LINK_STAT_RCV_DROPPED_NO_RPI_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_dropped_no_avail_rpi_rescnt); + counts[EFCT_HW_LINK_STAT_RCV_DROPPED_NO_XRI_COUNT ].counter = +le32_to_cpu (mbox_rsp->rx_dropped_no_avail_xri_rescnt); + +if (cb_arg) { +if (cb_arg->cb) { +if (status ==0 &&le16_to_cpu (mbox_rsp->hdr.status)) + status =le16_to_cpu (mbox_rsp->hdr.status); + cb_arg->cb (status, num_counters, counts, cb_arg->arg); + } + +kfree (cb_arg); + } + +return 0 ; +} + +int +efct_hw_get_link_stats (struct efct_hw *hw,u8 req_ext_counters, +u8 clear_overflow_flags,u8 clear_all_counters, +void (*cb)(int status,u32 num_counters, +struct efct_hw_link_stat_counts *counters, +void *arg), +void *arg) +{ +int rc = -EIO ; +struct efct_hw_link_stat_cb_arg *cb_arg; +u8 mbxdata[SLI4_BMBX_SIZE ]; + + cb_arg =kzalloc (sizeof (*cb_arg),GFP_ATOMIC ); +if (!cb_arg) +return -ENOMEM ; + + cb_arg->cb = cb; + cb_arg->arg = arg; + +/* Send the HW command */ +if (!sli_cmd_read_link_stats (&hw->sli, mbxdata, req_ext_counters, + clear_overflow_flags, clear_all_counters)) + rc =efct_hw_command (hw, mbxdata,EFCT_CMD_NOWAIT , + efct_hw_cb_link_stat, cb_arg); + +if (rc) +kfree (cb_arg); + +return rc; +} + +static int +efct_hw_cb_host_stat (struct efct_hw *hw,int status,u8 *mqe,void *arg) +{ +struct sli4_cmd_read_status *mbox_rsp = + (struct sli4_cmd_read_status *)mqe; +struct efct_hw_host_stat_cb_arg *cb_arg = arg; +struct efct_hw_host_stat_counts counts[EFCT_HW_HOST_STAT_MAX ]; +u32 num_counters =EFCT_HW_HOST_STAT_MAX ; + +memset (counts,0 ,sizeof (struct efct_hw_host_stat_counts ) * +EFCT_HW_HOST_STAT_MAX ); + + counts[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT ].counter = +le32_to_cpu (mbox_rsp->trans_kbyte_cnt); + counts[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT ].counter = +le32_to_cpu (mbox_rsp->recv_kbyte_cnt); + counts[EFCT_HW_HOST_STAT_TX_FRAME_COUNT ].counter = +le32_to_cpu (mbox_rsp->trans_frame_cnt); + counts[EFCT_HW_HOST_STAT_RX_FRAME_COUNT ].counter = +le32_to_cpu (mbox_rsp->recv_frame_cnt); + counts[EFCT_HW_HOST_STAT_TX_SEQ_COUNT ].counter = +le32_to_cpu (mbox_rsp->trans_seq_cnt); + counts[EFCT_HW_HOST_STAT_RX_SEQ_COUNT ].counter = +le32_to_cpu (mbox_rsp->recv_seq_cnt); + counts[EFCT_HW_HOST_STAT_TOTAL_EXCH_ORIG ].counter = +le32_to_cpu (mbox_rsp->tot_exchanges_orig); + counts[EFCT_HW_HOST_STAT_TOTAL_EXCH_RESP ].counter = +le32_to_cpu (mbox_rsp->tot_exchanges_resp); + counts[EFCT_HW_HOSY_STAT_RX_P_BSY_COUNT ].counter = +le32_to_cpu (mbox_rsp->recv_p_bsy_cnt); + counts[EFCT_HW_HOST_STAT_RX_F_BSY_COUNT ].counter = +le32_to_cpu (mbox_rsp->recv_f_bsy_cnt); + counts[EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_RQ_BUF_COUNT ].counter = +le32_to_cpu (mbox_rsp->no_rq_buf_dropped_frames_cnt); + counts[EFCT_HW_HOST_STAT_EMPTY_RQ_TIMEOUT_COUNT ].counter = +le32_to_cpu (mbox_rsp->empty_rq_timeout_cnt); + counts[EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_XRI_COUNT ].counter = +le32_to_cpu (mbox_rsp->no_xri_dropped_frames_cnt); + counts[EFCT_HW_HOST_STAT_EMPTY_XRI_POOL_COUNT ].counter = +le32_to_cpu (mbox_rsp->empty_xri_pool_cnt); + +if (cb_arg) { +if (cb_arg->cb) { +if (status ==0 &&le16_to_cpu (mbox_rsp->hdr.status)) + status =le16_to_cpu (mbox_rsp->hdr.status); + cb_arg->cb (status, num_counters, counts, cb_arg->arg); + } + +kfree (cb_arg); + } + +return 0 ; +} + +int +efct_hw_get_host_stats (struct efct_hw *hw,u8 cc, +void (*cb)(int status,u32 num_counters, +struct efct_hw_host_stat_counts *counters, +void *arg), +void *arg) +{ +int rc = -EIO ; +struct efct_hw_host_stat_cb_arg *cb_arg; +u8 mbxdata[SLI4_BMBX_SIZE ]; + + cb_arg =kmalloc (sizeof (*cb_arg),GFP_ATOMIC ); +if (!cb_arg) +return -ENOMEM ; + + cb_arg->cb = cb; + cb_arg->arg = arg; + +/* Send the HW command to get the host stats */ +if (!sli_cmd_read_status (&hw->sli, mbxdata, cc)) + rc =efct_hw_command (hw, mbxdata,EFCT_CMD_NOWAIT , + efct_hw_cb_host_stat, cb_arg); + +if (rc) { +efc_log_debug (hw->os,"READ_HOST_STATS failed\n" ); +kfree (cb_arg); + } + +return rc; +} + +struct efct_hw_async_call_ctx { +efct_hw_async_cb_t callback; +void *arg; +u8 cmd[SLI4_BMBX_SIZE ]; +}; + +static void +efct_hw_async_cb (struct efct_hw *hw,int status,u8 *mqe,void *arg) +{ +struct efct_hw_async_call_ctx *ctx = arg; + +if (ctx) { +if (ctx->callback) + (*ctx->callback)(hw, status, mqe, ctx->arg); + +kfree (ctx); + } +} + +int +efct_hw_async_call (struct efct_hw *hw,efct_hw_async_cb_t callback,void *arg) +{ +struct efct_hw_async_call_ctx *ctx; +int rc; + +/* +* Allocate a callback context (which includes the mbox cmd buffer), +* we need this to be persistent as the mbox cmd submission may be +* queued and executed later execution. +*/ + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + + ctx->callback = callback; + ctx->arg = arg; + +/* Build and send a NOP mailbox command */ +if (sli_cmd_common_nop (&hw->sli, ctx->cmd,0 )) { +efc_log_err (hw->os,"COMMON_NOP format failure\n" ); +kfree (ctx); +return -EIO ; + } + + rc =efct_hw_command (hw, ctx->cmd,EFCT_CMD_NOWAIT , efct_hw_async_cb, + ctx); +if (rc) { +efc_log_err (hw->os,"COMMON_NOP command failure, rc=%d\n" , rc); +kfree (ctx); +return -EIO ; + } +return 0 ; +} + +static int +efct_hw_cb_fw_write (struct efct_hw *hw,int status,u8 *mqe,void *arg) +{ +struct sli4_cmd_sli_config *mbox_rsp = + (struct sli4_cmd_sli_config *)mqe; +struct sli4_rsp_cmn_write_object *wr_obj_rsp; +struct efct_hw_fw_wr_cb_arg *cb_arg = arg; +u32 bytes_written; +u16 mbox_status; +u32 change_status; + + wr_obj_rsp = (struct sli4_rsp_cmn_write_object *) + &mbox_rsp->payload.embed; + bytes_written =le32_to_cpu (wr_obj_rsp->actual_write_length); + mbox_status =le16_to_cpu (mbox_rsp->hdr.status); + change_status = (le32_to_cpu (wr_obj_rsp->change_status_dword) & +RSP_CHANGE_STATUS ); + +if (cb_arg) { +if (cb_arg->cb) { +if (!status && mbox_status) + status = mbox_status; + cb_arg->cb (status, bytes_written, change_status, + cb_arg->arg); + } + +kfree (cb_arg); + } + +return 0 ; +} + +int +efct_hw_firmware_write (struct efct_hw *hw,struct efc_dma *dma,u32 size, +u32 offset,int last, +void (*cb)(int status,u32 bytes_written, +u32 change_status,void *arg), +void *arg) +{ +int rc = -EIO ; +u8 mbxdata[SLI4_BMBX_SIZE ]; +struct efct_hw_fw_wr_cb_arg *cb_arg; +int noc =0 ; + + cb_arg =kzalloc (sizeof (*cb_arg),GFP_KERNEL ); +if (!cb_arg) +return -ENOMEM ; + + cb_arg->cb = cb; + cb_arg->arg = arg; + +/* Write a portion of a firmware image to the device */ +if (!sli_cmd_common_write_object (&hw->sli, mbxdata, + noc, last, size, offset,"/prg/" , + dma)) + rc =efct_hw_command (hw, mbxdata,EFCT_CMD_NOWAIT , + efct_hw_cb_fw_write, cb_arg); + +if (rc !=0 ) { +efc_log_debug (hw->os,"COMMON_WRITE_OBJECT failed\n" ); +kfree (cb_arg); + } + +return rc; +}
drivers/scsi/elx/efct/efct_hw.h +29 -0
@@ -705,4 +705,33 @@ int efct_hw_bls_send(struct efct *efct, u32 type, struct sli_bls_params *bls_params, void *cb, void *arg); +/* Function for retrieving link statistics */ +int +efct_hw_get_link_stats (struct efct_hw *hw, +u8 req_ext_counters, +u8 clear_overflow_flags, +u8 clear_all_counters, +void (*efct_hw_link_stat_cb_t)(int status, +u32 num_counters, +struct efct_hw_link_stat_counts *counters,void *arg), +void *arg); +/* Function for retrieving host statistics */ +int +efct_hw_get_host_stats (struct efct_hw *hw, +u8 cc, +void (*efct_hw_host_stat_cb_t)(int status, +u32 num_counters, +struct efct_hw_host_stat_counts *counters,void *arg), +void *arg); +int +efct_hw_firmware_write (struct efct_hw *hw,struct efc_dma *dma, +u32 size,u32 offset,int last, +void (*cb)(int status,u32 bytes_written, +u32 change_status,void *arg), +void *arg); +typedef void (*efct_hw_async_cb_t )(struct efct_hw *hw,int status, +u8 *mqe,void *arg); +int +efct_hw_async_call (struct efct_hw *hw,efct_hw_async_cb_t callback,void *arg); +#endif /* __EFCT_H__ */
Signature · 1 line
2.26.2
PATCH v9 28/31 elx: efct: xport and hardware teardown routines
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Routines to detach xport and hardware objects.
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_hw.c | 251 +++++++++++++++++++++++++++++ drivers/scsi/elx/efct/efct_hw.h | 27 ++++ drivers/scsi/elx/efct/efct_xport.c | 178 ++++++++++++++++++++ 3 files changed, 456 insertions(+)
drivers/scsi/elx/efct/efct_hw.c +251 -0
@@ -3329,3 +3329,254 @@ efct_hw_firmware_write(struct efct_hw *hw, struct efc_dma *dma, u32 size,return rc; } + +static int +efct_hw_cb_port_control (struct efct_hw *hw,int status,u8 *mqe, +void *arg) +{ +return 0 ; +} + +int +efct_hw_port_control (struct efct_hw *hw,enum efct_hw_port ctrl, +uintptr_t value, +void (*cb)(int status,uintptr_t value,void *arg), +void *arg) +{ +int rc = -EIO ; +u8 link[SLI4_BMBX_SIZE ]; +u32 speed =0 ; +u8 reset_alpa =0 ; + +switch (ctrl) { +case EFCT_HW_PORT_INIT : +if (!sli_cmd_config_link (&hw->sli, link)) + rc =efct_hw_command (hw, link,EFCT_CMD_NOWAIT , + efct_hw_cb_port_control,NULL ); + +if (rc !=0 ) { +efc_log_err (hw->os,"CONFIG_LINK failed\n" ); +break ; + } + speed = hw->config.speed; + reset_alpa = (u8)(value &0xff ); + + rc = -EIO ; +if (!sli_cmd_init_link (&hw->sli, link, speed, reset_alpa)) + rc =efct_hw_command (hw, link,EFCT_CMD_NOWAIT , + efct_hw_cb_port_control,NULL ); +/* Free buffer on error, since no callback is coming */ +if (rc) +efc_log_err (hw->os,"INIT_LINK failed\n" ); +break ; + +case EFCT_HW_PORT_SHUTDOWN : +if (!sli_cmd_down_link (&hw->sli, link)) + rc =efct_hw_command (hw, link,EFCT_CMD_NOWAIT , + efct_hw_cb_port_control,NULL ); +/* Free buffer on error, since no callback is coming */ +if (rc) +efc_log_err (hw->os,"DOWN_LINK failed\n" ); +break ; + +default : +efc_log_debug (hw->os,"unhandled control %#x\n" , ctrl); +break ; + } + +return rc; +} + +void +efct_hw_teardown (struct efct_hw *hw) +{ +u32 i =0 ; +u32 destroy_queues; +u32 free_memory; +struct efc_dma *dma; +struct efct *efct = hw->os; + + destroy_queues = (hw->state ==EFCT_HW_STATE_ACTIVE ); + free_memory = (hw->state !=EFCT_HW_STATE_UNINITIALIZED ); + +/* Cancel Sliport Healthcheck */ +if (hw->sliport_healthcheck) { + hw->sliport_healthcheck =0 ; +efct_hw_config_sli_port_health_check (hw,0 ,0 ); + } + +if (hw->state !=EFCT_HW_STATE_QUEUES_ALLOCATED ) { + hw->state =EFCT_HW_STATE_TEARDOWN_IN_PROGRESS ; + +efct_hw_flush (hw); + +if (list_empty (&hw->cmd_head)) +efc_log_debug (hw->os, +"All commands completed on MQ queue\n" ); +else +efc_log_debug (hw->os, +"Some cmds still pending on MQ queue\n" ); + +/* Cancel any remaining commands */ +efct_hw_command_cancel (hw); + }else { + hw->state =EFCT_HW_STATE_TEARDOWN_IN_PROGRESS ; + } + +dma_free_coherent (&efct->pci->dev, + hw->rnode_mem.size, hw->rnode_mem.virt, + hw->rnode_mem.phys); +memset (&hw->rnode_mem,0 ,sizeof (struct efc_dma )); + +if (hw->io) { +for (i =0 ; i < hw->config.n_io; i++) { +if (hw->io[i] && hw->io[i]->sgl && + hw->io[i]->sgl->virt) { +dma_free_coherent (&efct->pci->dev, + hw->io[i]->sgl->size, + hw->io[i]->sgl->virt, + hw->io[i]->sgl->phys); + } +kfree (hw->io[i]); + hw->io[i] =NULL ; + } +kfree (hw->io); + hw->io =NULL ; +kfree (hw->wqe_buffs); + hw->wqe_buffs =NULL ; + } + + dma = &hw->xfer_rdy; +dma_free_coherent (&efct->pci->dev, + dma->size, dma->virt, dma->phys); +memset (dma,0 ,sizeof (struct efc_dma )); + + dma = &hw->loop_map; +dma_free_coherent (&efct->pci->dev, + dma->size, dma->virt, dma->phys); +memset (dma,0 ,sizeof (struct efc_dma )); + +for (i =0 ; i < hw->wq_count; i++) +sli_queue_free (&hw->sli, &hw->wq[i], destroy_queues, + free_memory); + +for (i =0 ; i < hw->rq_count; i++) +sli_queue_free (&hw->sli, &hw->rq[i], destroy_queues, + free_memory); + +for (i =0 ; i < hw->mq_count; i++) +sli_queue_free (&hw->sli, &hw->mq[i], destroy_queues, + free_memory); + +for (i =0 ; i < hw->cq_count; i++) +sli_queue_free (&hw->sli, &hw->cq[i], destroy_queues, + free_memory); + +for (i =0 ; i < hw->eq_count; i++) +sli_queue_free (&hw->sli, &hw->eq[i], destroy_queues, + free_memory); + +/* Free rq buffers */ +efct_hw_rx_free (hw); + +efct_hw_queue_teardown (hw); + +kfree (hw->wq_cpu_array); + +sli_teardown (&hw->sli); + +/* record the fact that the queues are non-functional */ + hw->state =EFCT_HW_STATE_UNINITIALIZED ; + +/* free sequence free pool */ +kfree (hw->seq_pool); + hw->seq_pool =NULL ; + +/* free hw_wq_callback pool */ +efct_hw_reqtag_pool_free (hw); + +mempool_destroy (hw->cmd_ctx_pool); +mempool_destroy (hw->mbox_rqst_pool); + +/* Mark HW setup as not having been called */ + hw->hw_setup_called = false; +} + +static int +efct_hw_sli_reset (struct efct_hw *hw,enum efct_hw_reset reset, +enum efct_hw_state prev_state) +{ +int rc =0 ; + +switch (reset) { +case EFCT_HW_RESET_FUNCTION : +efc_log_debug (hw->os,"issuing function level reset\n" ); +if (sli_reset (&hw->sli)) { +efc_log_err (hw->os,"sli_reset failed\n" ); + rc = -EIO ; + } +break ; +case EFCT_HW_RESET_FIRMWARE : +efc_log_debug (hw->os,"issuing firmware reset\n" ); +if (sli_fw_reset (&hw->sli)) { +efc_log_err (hw->os,"sli_soft_reset failed\n" ); + rc = -EIO ; + } +/* +* Because the FW reset leaves the FW in a non-running state, +* follow that with a regular reset. +*/ +efc_log_debug (hw->os,"issuing function level reset\n" ); +if (sli_reset (&hw->sli)) { +efc_log_err (hw->os,"sli_reset failed\n" ); + rc = -EIO ; + } +break ; +default : +efc_log_err (hw->os,"unknown type - no reset performed\n" ); + hw->state = prev_state; + rc = -EINVAL ; +break ; + } + +return rc; +} + +int +efct_hw_reset (struct efct_hw *hw,enum efct_hw_reset reset) +{ +int rc =0 ; +enum efct_hw_state prev_state = hw->state; + +if (hw->state !=EFCT_HW_STATE_ACTIVE ) +efc_log_debug (hw->os, +"HW state %d is not active\n" , hw->state); + + hw->state =EFCT_HW_STATE_RESET_IN_PROGRESS ; + +/* +* If the prev_state is already reset/teardown in progress, +* don't continue further +*/ +if (prev_state ==EFCT_HW_STATE_RESET_IN_PROGRESS || + prev_state ==EFCT_HW_STATE_TEARDOWN_IN_PROGRESS ) +return efct_hw_sli_reset (hw, reset, prev_state); + +if (prev_state !=EFCT_HW_STATE_UNINITIALIZED ) { +efct_hw_flush (hw); + +if (list_empty (&hw->cmd_head)) +efc_log_debug (hw->os, +"All commands completed on MQ queue\n" ); +else +efc_log_err (hw->os, +"Some commands still pending on MQ queue\n" ); + } + +/* Reset the chip */ + rc =efct_hw_sli_reset (hw, reset, prev_state); +if (rc == -EINVAL ) +return -EIO ; + +return rc; +}
drivers/scsi/elx/efct/efct_hw.h +27 -0
@@ -734,4 +734,31 @@ typedef void (*efct_hw_async_cb_t)(struct efct_hw *hw, int status,int efct_hw_async_call (struct efct_hw *hw,efct_hw_async_cb_t callback,void *arg); +struct hw_eq *efct_hw_new_eq (struct efct_hw *hw,u32 entry_count); +struct hw_cq *efct_hw_new_cq (struct hw_eq *eq,u32 entry_count); +u32 +efct_hw_new_cq_set (struct hw_eq *eqs[],struct hw_cq *cqs[], +u32 num_cqs,u32 entry_count); +struct hw_mq *efct_hw_new_mq (struct hw_cq *cq,u32 entry_count); +struct hw_wq +*efct_hw_new_wq (struct hw_cq *cq,u32 entry_count); +u32 +efct_hw_new_rq_set (struct hw_cq *cqs[],struct hw_rq *rqs[], +u32 num_rq_pairs,u32 entry_count); +void efct_hw_del_eq (struct hw_eq *eq); +void efct_hw_del_cq (struct hw_cq *cq); +void efct_hw_del_mq (struct hw_mq *mq); +void efct_hw_del_wq (struct hw_wq *wq); +void efct_hw_del_rq (struct hw_rq *rq); +void efct_hw_queue_teardown (struct efct_hw *hw); +void efct_hw_teardown (struct efct_hw *hw); +int +efct_hw_reset (struct efct_hw *hw,enum efct_hw_reset reset); + +int +efct_hw_port_control (struct efct_hw *hw,enum efct_hw_port ctrl, +uintptr_t value, +void (*cb)(int status,uintptr_t value,void *arg), +void *arg); +#endif /* __EFCT_H__ */
drivers/scsi/elx/efct/efct_xport.c +178 -0
181 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v9 29/31 elx: efct: scsi_transport_fc host interface support
In reply to James SmartThis patch continues the efct driver population.
This patch adds driver definitions for:
Integration with the scsi_fc_transport host interfaces
---
v9:
Non-functional changes:
Remove EFC_SUCCESS/EFC_FAIL defines and use 0 and -Exxx errno values. Remove EFCT_xxx/EFCT_HW_RTN_xxx defines and use appropriate -Exxx errno
values.
Correct indentation on line continuations.
--- drivers/scsi/elx/efct/efct_xport.c | 436 +++++++++++++++++++++++++++++ 1 file changed, 436 insertions(+)
drivers/scsi/elx/efct/efct_xport.c +436 -0
@@ -676,3 +676,439 @@ efct_scsi_del_device(struct efct *efct)scsi_host_put (efct->shost); efct->shost =NULL ; } + +static void +efct_get_host_port_id (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +struct efc *efc = efct->efcport; +struct efc_nport *nport; + +if (efc->domain && efc->domain->nport) { + nport = efc->domain->nport; +fc_host_port_id (shost) = nport->fc_id; + } +} + +static void +efct_get_host_port_type (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +struct efc *efc = efct->efcport; +int type =FC_PORTTYPE_UNKNOWN ; + +if (efc->domain && efc->domain->nport) { +if (efc->domain->is_loop) { + type =FC_PORTTYPE_LPORT ; + }else { +struct efc_nport *nport = efc->domain->nport; + +if (nport->is_vport) + type =FC_PORTTYPE_NPIV ; +else if (nport->topology ==EFC_NPORT_TOPO_P2P ) + type =FC_PORTTYPE_PTP ; +else if (nport->topology ==EFC_NPORT_TOPO_UNKNOWN ) + type =FC_PORTTYPE_UNKNOWN ; +else + type =FC_PORTTYPE_NPORT ; + } + } +fc_host_port_type (shost) = type; +} + +static void +efct_get_host_vport_type (struct Scsi_Host *shost) +{ +fc_host_port_type (shost) =FC_PORTTYPE_NPIV ; +} + +static void +efct_get_host_port_state (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +union efct_xport_stats_u status; +int rc; + + rc =efct_xport_status (efct->xport,EFCT_XPORT_PORT_STATUS , &status); +if ((!rc) && (status.value ==EFCT_XPORT_PORT_ONLINE )) +fc_host_port_state (shost) =FC_PORTSTATE_ONLINE ; +else +fc_host_port_state (shost) =FC_PORTSTATE_OFFLINE ; +} + +static void +efct_get_host_speed (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +struct efc *efc = efct->efcport; +union efct_xport_stats_u speed; +u32 fc_speed =FC_PORTSPEED_UNKNOWN ; +int rc; + +if (!efc->domain || !efc->domain->nport) { +fc_host_speed (shost) = fc_speed; +return ; + } + + rc =efct_xport_status (efct->xport,EFCT_XPORT_LINK_SPEED , &speed); +if (!rc) { +switch (speed.value) { +case 1000 : + fc_speed =FC_PORTSPEED_1GBIT ; +break ; +case 2000 : + fc_speed =FC_PORTSPEED_2GBIT ; +break ; +case 4000 : + fc_speed =FC_PORTSPEED_4GBIT ; +break ; +case 8000 : + fc_speed =FC_PORTSPEED_8GBIT ; +break ; +case 10000 : + fc_speed =FC_PORTSPEED_10GBIT ; +break ; +case 16000 : + fc_speed =FC_PORTSPEED_16GBIT ; +break ; +case 32000 : + fc_speed =FC_PORTSPEED_32GBIT ; +break ; +case 64000 : + fc_speed =FC_PORTSPEED_64GBIT ; +break ; +case 128000 : + fc_speed =FC_PORTSPEED_128GBIT ; +break ; + } + } + +fc_host_speed (shost) = fc_speed; +} + +static void +efct_get_host_fabric_name (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +struct efc *efc = efct->efcport; + +if (efc->domain) { +struct fc_els_flogi *sp = + (struct fc_els_flogi *) + efc->domain->flogi_service_params; + +fc_host_fabric_name (shost) =be64_to_cpu (sp->fl_wwnn); + } +} + +static struct fc_host_statistics * +efct_get_stats (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +union efct_xport_stats_u stats; +struct efct_xport *xport = efct->xport; +int rc =0 ; + + rc =efct_xport_status (xport,EFCT_XPORT_LINK_STATISTICS , &stats); +if (rc) { +pr_err ("efct_xport_status returned non 0 - %d\n" , rc); +return NULL ; + } + + vport->fc_host_stats.loss_of_sync_count = + stats.stats.link_stats.loss_of_sync_error_count; + vport->fc_host_stats.link_failure_count = + stats.stats.link_stats.link_failure_error_count; + vport->fc_host_stats.prim_seq_protocol_err_count = + stats.stats.link_stats.primitive_sequence_error_count; + vport->fc_host_stats.invalid_tx_word_count = + stats.stats.link_stats.invalid_transmission_word_error_count; + vport->fc_host_stats.invalid_crc_count = + stats.stats.link_stats.crc_error_count; +/* mbox returns kbyte count so we need to convert to words */ + vport->fc_host_stats.tx_words = + stats.stats.host_stats.transmit_kbyte_count *256 ; +/* mbox returns kbyte count so we need to convert to words */ + vport->fc_host_stats.rx_words = + stats.stats.host_stats.receive_kbyte_count *256 ; + vport->fc_host_stats.tx_frames = + stats.stats.host_stats.transmit_frame_count; + vport->fc_host_stats.rx_frames = + stats.stats.host_stats.receive_frame_count; + + vport->fc_host_stats.fcp_input_requests = + xport->fcp_stats.input_requests; + vport->fc_host_stats.fcp_output_requests = + xport->fcp_stats.output_requests; + vport->fc_host_stats.fcp_output_megabytes = + xport->fcp_stats.output_bytes >>20 ; + vport->fc_host_stats.fcp_input_megabytes = + xport->fcp_stats.input_bytes >>20 ; + vport->fc_host_stats.fcp_control_requests = + xport->fcp_stats.control_requests; + +return &vport->fc_host_stats; +} + +static void +efct_reset_stats (struct Scsi_Host *shost) +{ +struct efct_vport *vport = (struct efct_vport *)shost->hostdata; +struct efct *efct = vport->efct; +/* argument has no purpose for this action */ +union efct_xport_stats_u dummy; +int rc; + + rc =efct_xport_status (efct->xport,EFCT_XPORT_LINK_STAT_RESET , &dummy); +if (rc) +pr_err ("efct_xport_status returned non 0 - %d\n" , rc); +} + +static int +efct_issue_lip (struct Scsi_Host *shost) +{ +struct efct_vport *vport = + shost ? (struct efct_vport *)shost->hostdata :NULL ; +struct efct *efct = vport ? vport->efct :NULL ; + +if (!shost || !vport || !efct) { +pr_err ("%s: shost=%p vport=%p efct=%p\n" , __func__, + shost, vport, efct); +return -EPERM ; + } + +/* +* Bring the link down gracefully then re-init the link. +* The firmware will re-initialize the Fibre Channel interface as +* required. It does not issue a LIP. +*/ + +if (efct_xport_control (efct->xport,EFCT_XPORT_PORT_OFFLINE )) +efc_log_debug (efct,"EFCT_XPORT_PORT_OFFLINE failed\n" ); + +if (efct_xport_control (efct->xport,EFCT_XPORT_PORT_ONLINE )) +efc_log_debug (efct,"EFCT_XPORT_PORT_ONLINE failed\n" ); + +return 0 ; +} + +struct efct_vport * +efct_scsi_new_vport (struct efct *efct,struct device *dev) +{ +struct Scsi_Host *shost =NULL ; +int error =0 ; +struct efct_vport *vport =NULL ; + + shost =scsi_host_alloc (&efct_template,sizeof (*vport)); +if (!shost) { +efc_log_err (efct,"failed to allocate Scsi_Host struct\n" ); +return NULL ; + } + +/* save efct information to shost LLD-specific space */ + vport = (struct efct_vport *)shost->hostdata; + vport->efct = efct; + vport->is_vport = true; + + shost->can_queue = efct->hw.config.n_io; + shost->max_cmd_len =16 ;/* 16-byte CDBs */ + shost->max_id =0xffff ; + shost->max_lun =0xffffffff ; + +/* can only accept (from mid-layer) as many SGEs as we've pre-regited*/ + shost->sg_tablesize =sli_get_max_sgl (&efct->hw.sli); + +/* attach FC Transport template to shost */ + shost->transportt = efct_vport_fc_tt; +efc_log_debug (efct,"vport transport template=%p\n" , + efct_vport_fc_tt); + +/* get pci_dev structure and add host to SCSI ML */ + error =scsi_add_host_with_dma (shost, dev, &efct->pci->dev); +if (error) { +efc_log_debug (efct,"failed scsi_add_host_with_dma\n" ); +return NULL ; + } + +/* Set symbolic name for host port */ +snprintf (fc_host_symbolic_name (shost), +sizeof (fc_host_symbolic_name (shost)), +"Emulex %s FV%s DV%s" , efct->model, efct->hw.sli.fw_name[0 ], +EFCT_DRIVER_VERSION ); + +/* Set host port supported classes */ +fc_host_supported_classes (shost) =FC_COS_CLASS3 ; + +fc_host_supported_speeds (shost) =efct_get_link_supported_speeds (efct); + vport->shost = shost; + +return vport; +} + +int efct_scsi_del_vport (struct efct *efct,struct Scsi_Host *shost) +{ +if (shost) { +efc_log_debug (efct, +"Unregistering vport with Transport Layer\n" ); +efct_xport_remove_host (shost); +efc_log_debug (efct,"Unregistering vport with SCSI Midlayer\n" ); +scsi_remove_host (shost); +scsi_host_put (shost); +return 0 ; + } +return -EIO ; +} + +static int +efct_vport_create (struct fc_vport *fc_vport,bool disable) +{ +struct Scsi_Host *shost = fc_vport ? fc_vport->shost :NULL ; +struct efct_vport *pport = shost ? + (struct efct_vport *)shost->hostdata : +NULL ; +struct efct *efct = pport ? pport->efct :NULL ; +struct efct_vport *vport =NULL ; + +if (!fc_vport || !shost || !efct) + goto fail; + + vport =efct_scsi_new_vport (efct, &fc_vport->dev); +if (!vport) { +efc_log_err (efct,"failed to create vport\n" ); + goto fail; + } + + vport->fc_vport = fc_vport; + vport->npiv_wwpn = fc_vport->port_name; + vport->npiv_wwnn = fc_vport->node_name; +fc_host_node_name (vport->shost) = vport->npiv_wwnn; +fc_host_port_name (vport->shost) = vport->npiv_wwpn; + *(struct efct_vport **)fc_vport->dd_data = vport; + +return 0 ; + +fail: +return -EIO ; +} + +static int +efct_vport_delete (struct fc_vport *fc_vport) +{ +struct efct_vport *vport = *(struct efct_vport **)fc_vport->dd_data; +struct Scsi_Host *shost = vport ? vport->shost :NULL ; +struct efct *efct = vport ? vport->efct :NULL ; +int rc; + + rc =efct_scsi_del_vport (efct, shost); + +if (rc) +pr_err ("%s: vport delete failed\n" , __func__); + +return rc; +} + +static int +efct_vport_disable (struct fc_vport *fc_vport,bool disable) +{ +return 0 ; +} + +static struct fc_function_template efct_xport_functions = { + .get_host_port_id = efct_get_host_port_id, + .get_host_port_type = efct_get_host_port_type, + .get_host_port_state = efct_get_host_port_state, + .get_host_speed = efct_get_host_speed, + .get_host_fabric_name = efct_get_host_fabric_name, + + .get_fc_host_stats = efct_get_stats, + .reset_fc_host_stats = efct_reset_stats, + + .issue_fc_host_lip = efct_issue_lip, + + .vport_disable = efct_vport_disable, + +/* allocation lengths for host-specific data */ + .dd_fcrport_size =sizeof (struct efct_rport_data ), + .dd_fcvport_size =128 ,/* should be sizeof(...) */ + +/* remote port fixed attributes */ + .show_rport_maxframe_size =1 , + .show_rport_supported_classes =1 , + .show_rport_dev_loss_tmo =1 , + +/* target dynamic attributes */ + .show_starget_node_name =1 , + .show_starget_port_name =1 , + .show_starget_port_id =1 , + +/* host fixed attributes */ + .show_host_node_name =1 , + .show_host_port_name =1 , + .show_host_supported_classes =1 , + .show_host_supported_fc4s =1 , + .show_host_supported_speeds =1 , + .show_host_maxframe_size =1 , + +/* host dynamic attributes */ + .show_host_port_id =1 , + .show_host_port_type =1 , + .show_host_port_state =1 , +/* active_fc4s is shown but doesn't change (thus no get function) */ + .show_host_active_fc4s =1 , + .show_host_speed =1 , + .show_host_fabric_name =1 , + .show_host_symbolic_name =1 , + .vport_create = efct_vport_create, + .vport_delete = efct_vport_delete, +}; + +static struct fc_function_template efct_vport_functions = { + .get_host_port_id = efct_get_host_port_id, + .get_host_port_type = efct_get_host_vport_type, + .get_host_port_state = efct_get_host_port_state, + .get_host_speed = efct_get_host_speed, + .get_host_fabric_name = efct_get_host_fabric_name, + + .get_fc_host_stats = efct_get_stats, + .reset_fc_host_stats = efct_reset_stats, + + .issue_fc_host_lip = efct_issue_lip, + +/* allocation lengths for host-specific data */ + .dd_fcrport_size =sizeof (struct efct_rport_data ), + .dd_fcvport_size =128 ,/* should be sizeof(...) */ + +/* remote port fixed attributes */ + .show_rport_maxframe_size =1 , + .show_rport_supported_classes =1 , + .show_rport_dev_loss_tmo =1 , + +/* target dynamic attributes */ + .show_starget_node_name =1 , + .show_starget_port_name =1 , + .show_starget_port_id =1 , + +/* host fixed attributes */ + .show_host_node_name =1 , + .show_host_port_name =1 , + .show_host_supported_classes =1 , + .show_host_supported_fc4s =1 , + .show_host_supported_speeds =1 , + .show_host_maxframe_size =1 , + +/* host dynamic attributes */ + .show_host_port_id =1 , + .show_host_port_type =1 , + .show_host_port_state =1 , +/* active_fc4s is shown but doesn't change (thus no get function) */ + .show_host_active_fc4s =1 , + .show_host_speed =1 , + .show_host_fabric_name =1 , + .show_host_symbolic_name =1 , +};
Signature · 1 line
2.26.2
PATCH v9 30/31 elx: efct: Add Makefile and Kconfig for efct driver
In reply to James SmartThis patch completes the efct driver population.
This patch adds driver definitions for:
Adds the efct driver Kconfig and Makefiles
--- drivers/scsi/elx/Kconfig | 9 +++++++++ drivers/scsi/elx/Makefile | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 drivers/scsi/elx/Kconfig create mode 100644 drivers/scsi/elx/Makefile
drivers/scsi/elx/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +config SCSI_EFCT + tristate "Emulex Fibre Channel Target" + depends on PCI && SCSI + depends on TARGET_CORE + depends on SCSI_FC_ATTRS + select CRC_T10DIF + help + The efct driver provides enhanced SCSI Target Mode + support for specific SLI-4 adapters.
drivers/scsi/elx/Makefile new file +18 -0
@@ -0,0 +1,18 @@ +#// SPDX-License-Identifier: GPL-2.0 +#/* +# * Copyright (C) 2021 Broadcom. All Rights Reserved. The term +# * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. +# */ + + +obj-$(CONFIG_SCSI_EFCT) := efct.o + +efct-objs := efct/efct_driver.o efct/efct_io.o efct/efct_scsi.o \ + efct/efct_xport.o efct/efct_hw.o efct/efct_hw_queues.o \ + efct/efct_lio.o efct/efct_unsol.o + +efct-objs += libefc/efc_cmds.o libefc/efc_domain.o libefc/efc_fabric.o \ + libefc/efc_node.o libefc/efc_nport.o libefc/efc_device.o \ + libefc/efclib.o libefc/efc_sm.o libefc/efc_els.o + +efct-objs += libefc_sli/sli4.o
Signature · 1 line
2.26.2
PATCH v9 31/31 elx: efct: Tie into kernel Kconfig and build process
In reply to James SmartThis final patch ties the efct driver into the kernel Kconfig and build linkages in the drivers/scsi directory.
--- drivers/scsi/Kconfig | 2 ++ drivers/scsi/Makefile | 1 + 2 files changed, 3 insertions(+)
drivers/scsi/Kconfig +2 -0
@@ -1157,6 +1157,8 @@ config SCSI_LPFC_DEBUG_FS This makes debugging information from the lpfc driver available via the debugfs filesystem. +source "drivers/scsi/elx/Kconfig" + config SCSI_SIM710 tristate "Simple 53c710 SCSI support (Compaq, NCR machines)" depends on EISA && SCSI
drivers/scsi/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_SCSI_QLOGIC_1280) += qla1280.o obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx/ obj-$(CONFIG_SCSI_QLA_ISCSI) += libiscsi.o qla4xxx/ obj-$(CONFIG_SCSI_LPFC) += lpfc/ +obj-$(CONFIG_SCSI_EFCT) += elx/ obj-$(CONFIG_SCSI_BFA_FC) += bfa/ obj-$(CONFIG_SCSI_CHELSIO_FCOE) += csiostor/ obj-$(CONFIG_SCSI_DMX3191D) += dmx3191d.o
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH v9 31/31] elx: efct: Tie into kernel Kconfig and build process
I love your patch! Yet something to improve:
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next linus/master v5.13-rc4 next-20210601] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/James-Smart/efct-Broadcom-Emulex-FC-Target-driver/20210602-075737 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next config: xtensa-allyesconfig (attached as .config) compiler: xtensa-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d427d024bf41ddef344a2b1e842eb5d58231d825
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review James-Smart/efct-Broadcom-Emulex-FC-Target-driver/20210602-075737 git checkout d427d024bf41ddef344a2b1e842eb5d58231d825
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=xtensa
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
.exit.text' referenced in section __jump_table' of fs/cifs/cifsfs.o: defined in discarded section `.exit.text' of fs/cifs/cifsfs.o
.exit.text' referenced in section __jump_table' of fs/cifs/cifsfs.o: defined in discarded section `.exit.text' of fs/cifs/cifsfs.o
.exit.text' referenced in section __jump_table' of fs/fuse/inode.o: defined in discarded section `.exit.text' of fs/fuse/inode.o
.exit.text' referenced in section __jump_table' of fs/fuse/inode.o: defined in discarded section `.exit.text' of fs/fuse/inode.o
.exit.text' referenced in section __jump_table' of fs/ceph/super.o: defined in discarded section `.exit.text' of fs/ceph/super.o
.exit.text' referenced in section __jump_table' of fs/ceph/super.o: defined in discarded section `.exit.text' of fs/ceph/super.o
.exit.text' referenced in section __jump_table' of drivers/rapidio/rio_cm.o: defined in discarded section `.exit.text' of drivers/rapidio/rio_cm.o
.exit.text' referenced in section __jump_table' of drivers/rapidio/rio_cm.o: defined in discarded section `.exit.text' of drivers/rapidio/rio_cm.o
.exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen2.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen2.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen2.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen2.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen2.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen2.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen2.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen2.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen3.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen3.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen3.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen3.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen3.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen3.o .exit.text' referenced in section __jump_table' of drivers/rapidio/switches/idt_gen3.o: defined in discarded section .exit.text' of drivers/rapidio/switches/idt_gen3.o .exit.text' referenced in section __jump_table' of drivers/video/fbdev/vt8623fb.o: defined in discarded section .exit.text' of drivers/video/fbdev/vt8623fb.o .exit.text' referenced in section __jump_table' of drivers/video/fbdev/vt8623fb.o: defined in discarded section .exit.text' of drivers/video/fbdev/vt8623fb.o .exit.text' referenced in section __jump_table' of drivers/video/fbdev/s3fb.o: defined in discarded section .exit.text' of drivers/video/fbdev/s3fb.o .exit.text' referenced in section __jump_table' of drivers/video/fbdev/s3fb.o: defined in discarded section .exit.text' of drivers/video/fbdev/s3fb.o .exit.text' referenced in section __jump_table' of drivers/video/fbdev/arkfb.o: defined in discarded section .exit.text' of drivers/video/fbdev/arkfb.o .exit.text' referenced in section __jump_table' of drivers/video/fbdev/arkfb.o: defined in discarded section .exit.text' of drivers/video/fbdev/arkfb.o .exit.text' referenced in section __jump_table' of drivers/misc/phantom.o: defined in discarded section `.exit.text' of drivers/misc/phantom.o
.exit.text' referenced in section __jump_table' of drivers/misc/phantom.o: defined in discarded section `.exit.text' of drivers/misc/phantom.o
.exit.text' referenced in section __jump_table' of drivers/misc/habanalabs/common/habanalabs_drv.o: defined in discarded section .exit.text' of drivers/misc/habanalabs/common/habanalabs_drv.o .exit.text' referenced in section __jump_table' of drivers/misc/habanalabs/common/habanalabs_drv.o: defined in discarded section .exit.text' of drivers/misc/habanalabs/common/habanalabs_drv.o .exit.text' referenced in section __jump_table' of drivers/scsi/fcoe/fcoe.o: defined in discarded section `.exit.text' of drivers/scsi/fcoe/fcoe.o
.exit.text' referenced in section __jump_table' of drivers/scsi/fcoe/fcoe.o: defined in discarded section `.exit.text' of drivers/scsi/fcoe/fcoe.o
xtensa-linux-ld: drivers/scsi/elx/efct/efct_hw.o: in function `efct_hw_wq_write':
>> efct_hw.c:(.text+0x77b0): undefined reference to `__cmpxchg_called_with_bad_pointer'
xtensa-linux-ld: drivers/scsi/elx/efct/efct_hw.o: in function `efct_hw_io_abort':
efct_hw.c:(.text+0x7999): undefined reference to `__cmpxchg_called_with_bad_pointer'
.exit.text' referenced in section __jump_table' of drivers/scsi/cxgbi/libcxgbi.o: defined in discarded section .exit.text' of drivers/scsi/cxgbi/libcxgbi.o .exit.text' referenced in section __jump_table' of drivers/scsi/cxgbi/libcxgbi.o: defined in discarded section .exit.text' of drivers/scsi/cxgbi/libcxgbi.o .exit.text' referenced in section __jump_table' of drivers/target/target_core_configfs.o: defined in discarded section .exit.text' of drivers/target/target_core_configfs.o .exit.text' referenced in section __jump_table' of drivers/target/target_core_configfs.o: defined in discarded section .exit.text' of drivers/target/target_core_configfs.o .exit.text' referenced in section __jump_table' of drivers/mtd/maps/pcmciamtd.o: defined in discarded section .exit.text' of drivers/mtd/maps/pcmciamtd.o .exit.text' referenced in section __jump_table' of drivers/mtd/maps/pcmciamtd.o: defined in discarded section .exit.text' of drivers/mtd/maps/pcmciamtd.o .exit.text' referenced in section __jump_table' of drivers/net/wireless/zydas/zd1211rw/zd_usb.o: defined in discarded section .exit.text' of drivers/net/wireless/zydas/zd1211rw/zd_usb.o .exit.text' referenced in section __jump_table' of drivers/net/wireless/zydas/zd1211rw/zd_usb.o: defined in discarded section .exit.text' of drivers/net/wireless/zydas/zd1211rw/zd_usb.o .exit.text' referenced in section __jump_table' of drivers/net/wireless/ray_cs.o: defined in discarded section .exit.text' of drivers/net/wireless/ray_cs.o .exit.text' referenced in section __jump_table' of drivers/net/wireless/ray_cs.o: defined in discarded section .exit.text' of drivers/net/wireless/ray_cs.o .exit.text' referenced in section __jump_table' of drivers/net/wireless/mac80211_hwsim.o: defined in discarded section .exit.text' of drivers/net/wireless/mac80211_hwsim.o .exit.text' referenced in section __jump_table' of drivers/net/wireless/mac80211_hwsim.o: defined in discarded section .exit.text' of drivers/net/wireless/mac80211_hwsim.o .exit.text' referenced in section __jump_table' of drivers/usb/gadget/legacy/inode.o: defined in discarded section .exit.text' of drivers/usb/gadget/legacy/inode.o .exit.text' referenced in section __jump_table' of drivers/usb/gadget/legacy/inode.o: defined in discarded section .exit.text' of drivers/usb/gadget/legacy/inode.o .exit.text' referenced in section __jump_table' of drivers/usb/gadget/legacy/g_ffs.o: defined in discarded section .exit.text' of drivers/usb/gadget/legacy/g_ffs.o .exit.text' referenced in section __jump_table' of drivers/usb/gadget/legacy/g_ffs.o: defined in discarded section .exit.text' of drivers/usb/gadget/legacy/g_ffs.o .exit.text' referenced in section __jump_table' of drivers/media/common/siano/smscoreapi.o: defined in discarded section .exit.text' of drivers/media/common/siano/smscoreapi.o .exit.text' referenced in section __jump_table' of drivers/media/common/siano/smscoreapi.o: defined in discarded section .exit.text' of drivers/media/common/siano/smscoreapi.o .exit.text' referenced in section __jump_table' of drivers/vme/bridges/vme_fake.o: defined in discarded section .exit.text' of drivers/vme/bridges/vme_fake.o .exit.text' referenced in section __jump_table' of drivers/vme/bridges/vme_fake.o: defined in discarded section .exit.text' of drivers/vme/bridges/vme_fake.o .exit.text' referenced in section __jump_table' of net/netfilter/nf_conntrack_h323_main.o: defined in discarded section .exit.text' of net/netfilter/nf_conntrack_h323_main.o .exit.text' referenced in section __jump_table' of net/netfilter/nf_conntrack_h323_main.o: defined in discarded section .exit.text' of net/netfilter/nf_conntrack_h323_main.o .exit.text' referenced in section __jump_table' of net/netfilter/ipset/ip_set_core.o: defined in discarded section .exit.text' of net/netfilter/ipset/ip_set_core.o .exit.text' referenced in section __jump_table' of net/netfilter/ipset/ip_set_core.o: defined in discarded section .exit.text' of net/netfilter/ipset/ip_set_core.o .exit.text' referenced in section __jump_table' of net/bluetooth/6lowpan.o: defined in discarded section .exit.text' of net/bluetooth/6lowpan.o .exit.text' referenced in section __jump_table' of net/bluetooth/6lowpan.o: defined in discarded section .exit.text' of net/bluetooth/6lowpan.o .exit.text' referenced in section __jump_table' of net/ceph/ceph_common.o: defined in discarded section `.exit.text' of net/ceph/ceph_common.o
.exit.text' referenced in section __jump_table' of net/ceph/ceph_common.o: defined in discarded section `.exit.text' of net/ceph/ceph_common.o
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH v9 31/31] elx: efct: Tie into kernel Kconfig and build process
In reply to James SmartI love your patch! Yet something to improve:
Hi James,
I love your patch! Yet something to improve:
[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next linus/master v5.13-rc4 next-20210601] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/James-Smart/efct-Broadcom-Emulex-FC-Target-driver/20210602-075737 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next config: riscv-allyesconfig (attached as .config) compiler: riscv64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/d427d024bf41ddef344a2b1e842eb5d58231d825
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review James-Smart/efct-Broadcom-Emulex-FC-Target-driver/20210602-075737 git checkout d427d024bf41ddef344a2b1e842eb5d58231d825
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=riscv
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from <command-line>:
drivers/scsi/elx/efct/efct_hw.c: In function 'efct_hw_io_abort':
>> include/linux/compiler_types.h:328:38: error: call to '__compiletime_assert_386' declared with attribute error: BUILD_BUG failed
328 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:309:4: note: in definition of macro '__compiletime_assert'
309 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:328:2: note: in expansion of macro '_compiletime_assert'
328 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:59:21: note: in expansion of macro 'BUILD_BUG_ON_MSG'
59 | #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
| ^~~~~~~~~~~~~~~~
arch/riscv/include/asm/cmpxchg.h:335:3: note: in expansion of macro 'BUILD_BUG'
335 | BUILD_BUG(); \
| ^~~~~~~~~
arch/riscv/include/asm/cmpxchg.h:344:23: note: in expansion of macro '__cmpxchg'
344 | (__typeof__(*(ptr))) __cmpxchg((ptr), \
| ^~~~~~~~~
drivers/scsi/elx/efct/efct_hw.c:1972:6: note: in expansion of macro 'cmpxchg'
1972 | if (cmpxchg(&io_to_abort->abort_in_progress, false, true)) {
| ^~~~~~~vim +/__compiletime_assert_386 +328 include/linux/compiler_types.h
eb5c2d4b45e3d2 Will Deacon 2020-07-21 314 eb5c2d4b45e3d2 Will Deacon 2020-07-21 315 #define _compiletime_assert(condition, msg, prefix, suffix) \ eb5c2d4b45e3d2 Will Deacon 2020-07-21 316 __compiletime_assert(condition, msg, prefix, suffix) eb5c2d4b45e3d2 Will Deacon 2020-07-21 317 eb5c2d4b45e3d2 Will Deacon 2020-07-21 318 /** eb5c2d4b45e3d2 Will Deacon 2020-07-21 319 * compiletime_assert - break build and emit msg if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 320 * @condition: a compile-time constant condition to check eb5c2d4b45e3d2 Will Deacon 2020-07-21 321 * @msg: a message to emit if condition is false eb5c2d4b45e3d2 Will Deacon 2020-07-21 322 * eb5c2d4b45e3d2 Will Deacon 2020-07-21 323 * In tradition of POSIX assert, this macro will break the build if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 324 * supplied condition is *false*, emitting the supplied error message if the eb5c2d4b45e3d2 Will Deacon 2020-07-21 325 * compiler has support to do so. eb5c2d4b45e3d2 Will Deacon 2020-07-21 326 */ eb5c2d4b45e3d2 Will Deacon 2020-07-21 327 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @328 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)eb5c2d4b45e3d2 Will Deacon 2020-07-21 329
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Martin K. Petersen
AppliedJames,
Quoted 2 lines
This patch set is a request to incorporate the new Broadcom (Emulex) FC target driver, efct, into the kernel source tree.
Applied to 5.14/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering