Skip to contentSkip to conversation

staging: fnic2 Driver Introduction

PATCH In review Oliver Smith-Denny 3 participants 19 messages Apr 5, 2018 – Apr 12, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover staging: fnic2 Driver Introduction

Hi,

Cisco is developing a target mode driver for its HBA interface called fNIC which stands for FCoE NIC. This is a new storage functionality supported on UCS platforms with VIC adapters. The driver is developed for the Linux LIO target mode stack. This driver is named fnic2 to distinguish it from the existing Cisco FCoE driver, which only supports SCSI initiator mode. We intend to include this driver in the Linux staging tree while we continue to develop it.

The new driver will include many new features as compared to the existing fnic driver:

- Support for SCSI Target Mode (This patch)

- Multiqueue support

- NVMe over FC support

We appreciate any comment from the Linux community.

Thank you,

Oliver Smith-Denny

#1 lore raw

PATCH 1/10 staging: fnic2 add initialization

These files contain module load and unload, global driver context, PCI registration, PCI probe and remove, and definitions of the fnic2 global context.

---
 drivers/staging/fnic2/src/fnic2.h      | 256 ++++++++++++
 drivers/staging/fnic2/src/fnic2_main.c | 711 +++++++++++++++++++++++++++++++++
 2 files changed, 967 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fnic2.h
 create mode 100644 drivers/staging/fnic2/src/fnic2_main.c
drivers/staging/fnic2/src/fnic2.h new file +256 -0
new file mode 100644
index 0000000..81b54da
@@ -0,0 +1,256 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2017 Cisco Systems, Inc.  All rights reserved.
+ */
+#ifndef _FNIC2_H_
+#define _FNIC2_H_
+
+#include <linux/interrupt.h>
+#include <linux/netdevice.h>
+#include <linux/workqueue.h>
+#include <linux/bitops.h>
+#include <linux/version.h>
+#include <linux/mempool.h>
+#include <linux/cpumask.h>
+#include "fnic2_fdls.h"
+#include "fnic2_res.h"
+#include "vnic_dev.h"
+#include "vnic_wq.h"
+#include "vnic_rq.h"
+#include "vnic_cq.h"
+#include "vnic_wq_copy.h"
+#include "vnic_intr.h"
+#include "vnic_stats.h"
+#include "vnic_scsi.h"
+#include "fnic2_lio.h"
+
+#define DRV_NAME			"fnic2"
+#define DRV_DESCRIPTION		"Cisco FCoE Target Driver"
+#define DRV_VERSION			"0.0.0.1"
+#define JIFFIES_PER_MINUTE      	(60 * HZ)
+
+#define DESC_CLEAN_LOW_WATERMARK	8
+#define FNIC2_MAX_TCMDS 		1024
+#define MAX_FNIC2S 			16
+#define MAX_DATA_LENGTH		(1024 * 1024)
+#define ABTS_MASK			0x10000
+
+#define SCSI_READ_MASK	0x08
+#define SCSI_WRITE_MASK	0x0A
+#define IS_SCSI_READ_CMD(_cmd_)  ((_cmd_->fchdr.r_ctl == FC_R_CTL_FC4_CMD) && ((_cmd_->cdb[0] & 0x1F) == SCSI_READ_MASK))
+#define IS_SCSI_WRITE_CMD(_cmd_) ((_cmd_->fchdr.r_ctl == FC_R_CTL_FC4_CMD) && ((_cmd_->cdb[0] & 0x1F) == SCSI_WRITE_MASK))
+
+extern const char *fnic2_state_str[];
+extern unsigned int fnic2_log_level;
+
+enum fnic2_intx_intr_index {
+	FNIC2_INTX_WQ_RQ_COPYWQ,
+	FNIC2_INTX_ERR,
+	FNIC2_INTX_NOTIFY
+};
+
+enum fnic2_msix_intr_index {
+	FNIC2_MSIX_RQ,
+	FNIC2_MSIX_WQ,
+	FNIC2_MSIX_WQ_COPY,
+	FNIC2_MSIX_ERR_NOTIFY,
+	FNIC2_MSIX_INTR_MAX
+};
+
+struct fnic2_msix_entry {
+	int		requested;
+	char		devname[IFNAMSIZ];
+	irqreturn_t	(*isr)(int, void *);
+	void		*devid;
+};
+
+enum fnic2_state {
+	FNIC2_IN_FC_MODE = 0,
+	FNIC2_IN_FC_TRANS_ETH_MODE,
+	FNIC2_IN_ETH_MODE,
+	FNIC2_IN_ETH_TRANS_FC_MODE
+};
+
+#define SCSI_NO_TAG -1
+
+#define FNIC2_WQ_COPY_MAX 1
+#define FNIC2_WQ_MAX 1
+#define FNIC2_RQ_MAX 1
+#define FNIC2_CQ_MAX (FNIC2_WQ_COPY_MAX + FNIC2_WQ_MAX + FNIC2_RQ_MAX)
+
+struct fnic2_frame_list {
+	/*
+	 * Link to frame lists
+	 */
+	struct list_head	links;
+	void			*fp;
+	int			frame_len;
+	int			rx_ethhdr_stripped;
+};
+
+/* Per-instance private data structure */
+struct fnic2 {
+	int						fnic2_num;
+	struct fnic2_lport				lport;
+	struct vnic_dev_bar				bar0;
+
+	struct msix_entry				msix_entry[FNIC2_MSIX_INTR_MAX];
+	struct fnic2_msix_entry				msix[FNIC2_MSIX_INTR_MAX];
+
+	struct vnic_stats				*stats;
+
+	/* time of stats update */
+	unsigned long					stats_time;
+
+	/* time of stats reset */
+	unsigned long					stats_reset_time;
+
+	struct vnic_nic_cfg				*nic_cfg;
+	char						name[IFNAMSIZ];
+
+	/* used for MSI interrupts */
+	struct timer_list				notify_timer;
+
+	unsigned int					fnic2_max_tag_id;
+	unsigned int					err_intr_offset;
+	unsigned int					link_intr_offset;
+
+	unsigned int					wq_count;
+	unsigned int					cq_count;
+
+	atomic64_t					io_cmpl_skip;
+
+	/* fnic2 device in removal */
+	uint32_t					in_remove:1;
+
+	/* stop proc. rx frames, link events */
+	uint32_t					stop_rx_link_events:1;
+
+	/* Device remove thread blocks */
+	struct completion				*remove_wait;
+
+	/* IO Counter */
+	atomic_t					in_flight;
+
+	bool						internal_reset_progress;
+
+	/* fill hole */
+	uint32_t _reserved;
+
+	enum						fnic2_state state;
+	spinlock_t					fnic2_lock;
+
+	/* VLAN tag including priority */
+	uint16_t					vlan_id;
+
+	uint8_t						data_src_addr[ETH_ALEN];
+
+	/* Internal statistics */
+	uint64_t					fcp_input_bytes;
+	uint64_t 					fcp_output_bytes;
+
+	uint32_t					link_down_cnt;
+	int						link_status;
+
+	struct list_head				list;
+	struct pci_dev					*pdev;
+	struct vnic_fc_config				config;
+	struct vnic_dev					*vdev;
+	unsigned int					raw_wq_count;
+	unsigned int					wq_copy_count;
+	unsigned int					rq_count;
+	int						fw_ack_index[FNIC2_WQ_COPY_MAX];
+	unsigned short					fw_ack_recd[FNIC2_WQ_COPY_MAX];
+	unsigned short					wq_copy_desc_low[FNIC2_WQ_COPY_MAX];
+	unsigned int					intr_count;
+	uint32_t __iomem				*legacy_pba;
+	struct fnic2_host_tag				*tags;
+
+	struct work_struct				link_work;
+	struct work_struct				frame_work;
+	struct list_head				frame_queue;
+	struct list_head				tx_queue;
+
+	/*** FIP related data members  -- start ***/
+	void						(*set_vlan)(struct fnic2 *, uint16_t vlan);
+	struct work_struct				fip_work;
+	struct list_head				fip_frame_queue;
+	struct list_head				vlan_list;
+	spinlock_t					vlans_lock;
+	struct timer_list				retry_fip_timer;
+	struct timer_list				fcs_ka_timer;
+	struct timer_list				enode_ka_timer;
+	struct timer_list				vn_ka_timer;
+
+	struct work_struct				event_work;
+	/*** FIP related data members  -- end ***/
+
+	/* copy work queue cache line section */
+	____cacheline_aligned struct vnic_wq_copy	wq_copy[FNIC2_WQ_COPY_MAX];
+	/* completion queue cache line section */
+	____cacheline_aligned struct vnic_cq		cq[FNIC2_CQ_MAX];
+
+	spinlock_t 					wq_copy_lock[FNIC2_WQ_COPY_MAX];
+
+	/* work queue cache line section */
+	____cacheline_aligned struct vnic_wq		wq[FNIC2_WQ_MAX];
+	spinlock_t					wq_lock[FNIC2_WQ_MAX];
+
+	/* receive queue cache line section */
+	____cacheline_aligned struct vnic_rq		rq[FNIC2_RQ_MAX];
+
+	/* interrupt resource cache line section */
+	____cacheline_aligned struct vnic_intr		intr[FNIC2_MSIX_INTR_MAX];
+
+       /* fnic2 related structures */
+	struct fnic2_lio				lio;
+	struct list_head				tcmd_list_free;
+	struct fnic2_cmd				*tcmd_pool;
+	spinlock_t					free_list_lock;
+
+	/* DBG related, temp */
+	int						freecmds;
+};
+
+static inline int get_cpu_to_queue(uint32_t tag)
+{
+	return tag % num_online_cpus();
+}
+
+extern struct workqueue_struct *fnic2_event_queue;
+extern struct workqueue_struct *fip_event_queue;
+extern struct workqueue_struct *fnic2_tcmd_wq;
+
+void fnic2_clear_intr_mode(struct fnic2 *fnic2);
+int fnic2_set_intr_mode(struct fnic2 *fnic2);
+void fnic2_free_intr(struct fnic2 *fnic2);
+int fnic2_request_intr(struct fnic2 *fnic2);
+
+void fnic2_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
+void fnic2_handle_frame(struct work_struct *work);
+void fnic2_handle_fip_frame(struct work_struct *work);
+void fnic2_handle_link(struct work_struct *work);
+int fnic2_rq_cmpl_handler(struct fnic2 *fnic2, int);
+int fnic2_alloc_rq_frame(struct vnic_rq *rq);
+void fnic2_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
+void fnic2_flush_tx(struct fnic2 *);
+int fnic2_wq_copy_cmpl_handler(struct fnic2 *fnic2, int);
+int fnic2_wq_cmpl_handler(struct fnic2 *fnic2, int);
+void fnic2_wq_copy_cleanup_handler(struct vnic_wq_copy *wq, struct fcpio_host_req *desc);
+int fnic2_fw_reset_handler(struct fnic2 *fnic2);
+const char *fnic2_state_to_str(unsigned int state);
+
+void fnic2_log_q_error(struct fnic2 *fnic2);
+void fnic2_handle_link_event(struct fnic2 *fnic2);
+
+void fnic2_send_fcp_resp(struct fnic2_cmd *tcmd);
+void fnic2_send_tmr_resp(struct fnic2_cmd *tcmd, u32 status, u8 code);
+void fnic2_complete_tm_rsp(struct fnic2_cmd *tcmd);
+void fnic2_send_abort_to_lio(struct fnic2_cmd *tcmd);
+void fnic2_send_abort_to_fw(struct fnic2_cmd *tcmd);
+void fnic2_fw_abort_done(struct fnic2_cmd *tcmd);
+void fnic2_recv_tcmd_timeout_intr(struct timer_list *timer);
+
+struct fnic2_sess *fnic2_find_session(struct fnic2 *fnic2, uint64_t wwpn);
+struct fnic2_sess *fnic2_find_sess_s_id(struct fnic2 *fnic2, uint32_t s_id);
+#endif /* _FNIC2_H_ */
drivers/staging/fnic2/src/fnic2_main.c new file +711 -0

711 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 2/10 staging: fnic2 add resource allocation

In reply to Oliver Smith-Denny

These files contain logic for interrupts, resource allocation, and initialization of hardware queues.

---
 drivers/staging/fnic2/src/fnic2_isr.c | 324 +++++++++++++++++++++++++
 drivers/staging/fnic2/src/fnic2_res.c | 430 ++++++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/fnic2_res.h | 120 ++++++++++
 3 files changed, 874 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fnic2_isr.c
 create mode 100644 drivers/staging/fnic2/src/fnic2_res.c
 create mode 100644 drivers/staging/fnic2/src/fnic2_res.h
drivers/staging/fnic2/src/fnic2_isr.c new file +324 -0
new file mode 100644
index 0000000..07cf1a4
@@ -0,0 +1,324 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/pci.h>
+#include <linux/interrupt.h>
+#include "vnic_dev.h"
+#include "vnic_intr.h"
+#include "vnic_stats.h"
+#include "fnic2.h"
+
+static irqreturn_t fnic2_isr_legacy(int irq, void *data)
+{
+	struct fnic2 *fnic2 = data;
+	uint32_t pba;
+	unsigned long work_done = 0;
+
+	pba = vnic_intr_legacy_pba(fnic2->legacy_pba);
+	if (!pba)
+		return IRQ_NONE;
+
+	if (pba & (1 << FNIC2_INTX_NOTIFY)) {
+		vnic_intr_return_all_credits(&fnic2->intr[FNIC2_INTX_NOTIFY]);
+		fnic2_handle_link_event(fnic2);
+	}
+
+	if (pba & (1 << FNIC2_INTX_ERR)) {
+		vnic_intr_return_all_credits(&fnic2->intr[FNIC2_INTX_ERR]);
+		fnic2_log_q_error(fnic2);
+	}
+
+	if (pba & (1 << FNIC2_INTX_WQ_RQ_COPYWQ)) {
+		work_done += fnic2_wq_copy_cmpl_handler(fnic2, -1);
+		work_done += fnic2_wq_cmpl_handler(fnic2, -1);
+		work_done += fnic2_rq_cmpl_handler(fnic2, -1);
+
+		vnic_intr_return_credits(&fnic2->intr[FNIC2_INTX_WQ_RQ_COPYWQ],
+					 work_done,
+					 1 /* unmask intr */,
+					 1 /* reset intr timer */);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t fnic2_isr_msi(int irq, void *data)
+{
+	struct fnic2 *fnic2 = data;
+	unsigned long work_done = 0;
+
+	work_done += fnic2_wq_copy_cmpl_handler(fnic2, -1);
+	work_done += fnic2_wq_cmpl_handler(fnic2, -1);
+	work_done += fnic2_rq_cmpl_handler(fnic2, -1);
+
+	vnic_intr_return_credits(&fnic2->intr[0],
+				 work_done,
+				 1 /* unmask intr */,
+				 1 /* reset intr timer */);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t fnic2_isr_msix_rq(int irq, void *data)
+{
+	struct fnic2 *fnic2 = data;
+	unsigned long rq_work_done = 0;
+
+	rq_work_done = fnic2_rq_cmpl_handler(fnic2, -1);
+	vnic_intr_return_credits(&fnic2->intr[FNIC2_MSIX_RQ],
+				 rq_work_done,
+				 1 /* unmask intr */,
+				 1 /* reset intr timer */);
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t fnic2_isr_msix_wq(int irq, void *data)
+{
+	struct fnic2 *fnic2 = data;
+	unsigned long wq_work_done = 0;
+
+	wq_work_done = fnic2_wq_cmpl_handler(fnic2, -1);
+	vnic_intr_return_credits(&fnic2->intr[FNIC2_MSIX_WQ],
+				 wq_work_done,
+				 1 /* unmask intr */,
+				 1 /* reset intr timer */);
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t fnic2_isr_msix_wq_copy(int irq, void *data)
+{
+	struct fnic2 *fnic2 = data;
+	unsigned long wq_copy_work_done = 0;
+
+	wq_copy_work_done = fnic2_wq_copy_cmpl_handler(fnic2, -1);
+	vnic_intr_return_credits(&fnic2->intr[FNIC2_MSIX_WQ_COPY],
+				 wq_copy_work_done,
+				 1 /* unmask intr */,
+				 1 /* reset intr timer */);
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t fnic2_isr_msix_err_notify(int irq, void *data)
+{
+	struct fnic2 *fnic2 = data;
+
+	vnic_intr_return_all_credits(&fnic2->intr[FNIC2_MSIX_ERR_NOTIFY]);
+	fnic2_log_q_error(fnic2);
+	fnic2_handle_link_event(fnic2);
+
+	return IRQ_HANDLED;
+}
+
+void fnic2_free_intr(struct fnic2 *fnic2)
+{
+	int i;
+
+	switch (vnic_dev_get_intr_mode(fnic2->vdev)) {
+	case VNIC_DEV_INTR_MODE_INTX:
+	case VNIC_DEV_INTR_MODE_MSI:
+		free_irq(fnic2->pdev->irq, fnic2);
+		break;
+
+	case VNIC_DEV_INTR_MODE_MSIX:
+		for (i = 0; i < ARRAY_SIZE(fnic2->msix); i++)
+			if (fnic2->msix[i].requested)
+				free_irq(fnic2->msix_entry[i].vector,
+					 fnic2->msix[i].devid);
+		break;
+
+	default:
+		break;
+	}
+}
+
+int fnic2_request_intr(struct fnic2 *fnic2)
+{
+	int err = 0;
+	int i;
+
+	switch (vnic_dev_get_intr_mode(fnic2->vdev)) {
+
+	case VNIC_DEV_INTR_MODE_INTX:
+		err = request_irq(fnic2->pdev->irq, &fnic2_isr_legacy,
+				  IRQF_SHARED, DRV_NAME, fnic2);
+		break;
+
+	case VNIC_DEV_INTR_MODE_MSI:
+		err = request_irq(fnic2->pdev->irq, &fnic2_isr_msi,
+				  0, fnic2->name, fnic2);
+		break;
+
+	case VNIC_DEV_INTR_MODE_MSIX:
+
+		sprintf(fnic2->msix[FNIC2_MSIX_RQ].devname,
+			"%.11s-fcs-rq", fnic2->name);
+		fnic2->msix[FNIC2_MSIX_RQ].isr = fnic2_isr_msix_rq;
+		fnic2->msix[FNIC2_MSIX_RQ].devid = fnic2;
+
+		sprintf(fnic2->msix[FNIC2_MSIX_WQ].devname,
+			"%.11s-fcs-wq", fnic2->name);
+		fnic2->msix[FNIC2_MSIX_WQ].isr = fnic2_isr_msix_wq;
+		fnic2->msix[FNIC2_MSIX_WQ].devid = fnic2;
+
+		sprintf(fnic2->msix[FNIC2_MSIX_WQ_COPY].devname,
+			"%.11s-scsi-wq", fnic2->name);
+		fnic2->msix[FNIC2_MSIX_WQ_COPY].isr = fnic2_isr_msix_wq_copy;
+		fnic2->msix[FNIC2_MSIX_WQ_COPY].devid = fnic2;
+
+		sprintf(fnic2->msix[FNIC2_MSIX_ERR_NOTIFY].devname,
+			"%.11s-err-notify", fnic2->name);
+		fnic2->msix[FNIC2_MSIX_ERR_NOTIFY].isr =
+			fnic2_isr_msix_err_notify;
+		fnic2->msix[FNIC2_MSIX_ERR_NOTIFY].devid = fnic2;
+
+		for (i = 0; i < ARRAY_SIZE(fnic2->msix); i++) {
+			err = request_irq(fnic2->msix_entry[i].vector,
+					  fnic2->msix[i].isr, 0,
+					  fnic2->msix[i].devname,
+					  fnic2->msix[i].devid);
+			if (err) {
+				pr_err("MSIX: request_irq failed %d\n",
+					err);
+				fnic2_free_intr(fnic2);
+				break;
+			}
+			fnic2->msix[i].requested = 1;
+		}
+		break;
+
+	default:
+		break;
+	}
+
+	return err;
+}
+
+int fnic2_set_intr_mode(struct fnic2 *fnic2)
+{
+	unsigned int n = ARRAY_SIZE(fnic2->rq);
+	unsigned int m = ARRAY_SIZE(fnic2->wq);
+	unsigned int o = ARRAY_SIZE(fnic2->wq_copy);
+	unsigned int i;
+
+	/*
+	 * Set interrupt mode (INTx, MSI, MSI-X) depending
+	 * system capabilities.
+	 *
+	 * Try MSI-X first
+	 *
+	 * We need n RQs, m WQs, o Copy WQs, n+m+o CQs, and n+m+o+1 INTRs
+	 * (last INTR is used for WQ/RQ errors and notification area)
+	 */
+
+	WARN_ON(ARRAY_SIZE(fnic2->msix_entry) < n + m + o + 1);
+	for (i = 0; i < n + m + o + 1; i++)
+		fnic2->msix_entry[i].entry = i;
+
+	if (fnic2->rq_count >= n &&
+	    fnic2->raw_wq_count >= m &&
+	    fnic2->wq_copy_count >= o &&
+	    fnic2->cq_count >= n + m + o) {
+		if (!pci_enable_msix_exact(fnic2->pdev, fnic2->msix_entry,
+				    n + m + o + 1)) {
+			fnic2->rq_count = n;
+			fnic2->raw_wq_count = m;
+			fnic2->wq_copy_count = o;
+			fnic2->wq_count = m + o;
+			fnic2->cq_count = n + m + o;
+			fnic2->intr_count = n + m + o + 1;
+			fnic2->err_intr_offset = FNIC2_MSIX_ERR_NOTIFY;
+
+			pr_debug("Using MSI-X Interrupts\n");
+			vnic_dev_set_intr_mode(fnic2->vdev,
+					       VNIC_DEV_INTR_MODE_MSIX);
+			return 0;
+		}
+	}
+
+	/*
+	 * Next try MSI
+	 * We need 1 RQ, 1 WQ, 1 WQ_COPY, 3 CQs, and 1 INTR
+	 */
+	if (fnic2->rq_count >= 1 &&
+	    fnic2->raw_wq_count >= 1 &&
+	    fnic2->wq_copy_count >= 1 &&
+	    fnic2->cq_count >= 3 &&
+	    fnic2->intr_count >= 1 &&
+	    !pci_enable_msi(fnic2->pdev)) {
+
+		fnic2->rq_count = 1;
+		fnic2->raw_wq_count = 1;
+		fnic2->wq_copy_count = 1;
+		fnic2->wq_count = 2;
+		fnic2->cq_count = 3;
+		fnic2->intr_count = 1;
+		fnic2->err_intr_offset = 0;
+
+		pr_debug("Using MSI Interrupts\n");
+		vnic_dev_set_intr_mode(fnic2->vdev, VNIC_DEV_INTR_MODE_MSI);
+
+		return 0;
+	}
+
+	/*
+	 * Next try INTx
+	 * We need 1 RQ, 1 WQ, 1 WQ_COPY, 3 CQs, and 3 INTRs
+	 * 1 INTR is used for all 3 queues, 1 INTR for queue errors
+	 * 1 INTR for notification area
+	 */
+
+	if (fnic2->rq_count >= 1 &&
+	    fnic2->raw_wq_count >= 1 &&
+	    fnic2->wq_copy_count >= 1 &&
+	    fnic2->cq_count >= 3 &&
+	    fnic2->intr_count >= 3) {
+
+		fnic2->rq_count = 1;
+		fnic2->raw_wq_count = 1;
+		fnic2->wq_copy_count = 1;
+		fnic2->cq_count = 3;
+		fnic2->intr_count = 3;
+
+		pr_debug("Using Legacy Interrupts\n");
+		vnic_dev_set_intr_mode(fnic2->vdev, VNIC_DEV_INTR_MODE_INTX);
+
+		return 0;
+	}
+
+	vnic_dev_set_intr_mode(fnic2->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
+
+	return -EINVAL;
+}
+
+void fnic2_clear_intr_mode(struct fnic2 *fnic2)
+{
+	switch (vnic_dev_get_intr_mode(fnic2->vdev)) {
+	case VNIC_DEV_INTR_MODE_MSIX:
+		pci_disable_msix(fnic2->pdev);
+		break;
+	case VNIC_DEV_INTR_MODE_MSI:
+		pci_disable_msi(fnic2->pdev);
+		break;
+	default:
+		break;
+	}
+
+	vnic_dev_set_intr_mode(fnic2->vdev, VNIC_DEV_INTR_MODE_INTX);
+}
drivers/staging/fnic2/src/fnic2_res.c new file +430 -0

430 lines not on this page · raw message

drivers/staging/fnic2/src/fnic2_res.h new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 3/10 staging: fnic2 add fip handling

In reply to Oliver Smith-Denny

These files contain structures and functions for handling FIP frames.

---
 drivers/staging/fnic2/src/fip.c | 804 ++++++++++++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/fip.h | 336 +++++++++++++++++
 2 files changed, 1140 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fip.c
 create mode 100644 drivers/staging/fnic2/src/fip.h
drivers/staging/fnic2/src/fip.c new file +804 -0
new file mode 100644
index 0000000..42c2cf3
@@ -0,0 +1,804 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*! \file */
+#include "fnic2.h"
+#include "fip.h"
+
+extern struct workqueue_struct *fip_event_queue;
+
+void fnic2_fcoe_send_vlan_req(struct fnic2 *fnic2);
+static void fnic2_fcoe_start_fcf_discovery(struct fnic2 *fnic2);
+static void fnic2_fcoe_start_flogi(struct fnic2 *fnic2);
+static void fnic2_fcoe_process_cvl(struct fnic2 *fnic2, struct fip_header *fiph);
+static void fnic2_vlan_discovery_timeout(struct fnic2 *fnic2);
+
+int drop_rsp = true;
+
+/****************************** Functions ***********************************/
+
+/**
+ * fnic2_fcoe_reset_vlans
+ *
+ * Frees up the list of discovered vlans
+ *
+ * @param fnic2 fnic2 driver instance
+ */
+
+void fnic2_fcoe_reset_vlans(struct fnic2 *fnic2)
+{
+	unsigned long flags;
+	struct fcoe_vlan *vlan, *next;
+
+        pr_debug("fnic2 0x%pK enter reset vlan\n", fnic2);
+	spin_lock_irqsave(&fnic2->vlans_lock, flags);
+	if (!list_empty(&fnic2->vlan_list)) {
+	    list_for_each_entry_safe(vlan, next, &fnic2->vlan_list, list) {
+		list_del(&vlan->list);
+		kfree(vlan);
+	    }
+	}
+
+	spin_unlock_irqrestore(&fnic2->vlans_lock, flags);
+        pr_debug("fnic2 0x%pK reset vlan done\n", fnic2);
+}
+
+/*
+ * fnic2_fcoe_send_vlan_req
+ *
+ * Sends FIP vlan request to all FCFs MAC
+ *
+ * @param fnic2 fnic2 driver instance
+ */
+
+void fnic2_fcoe_send_vlan_req(struct fnic2 *fnic2)
+{
+	struct fnic2_lport *lport = &fnic2->lport;
+	uint64_t vlan_tov;
+
+	int fr_len;
+	struct fip_vlan_req vlan_req;
+
+	pr_debug("fnic2 0x%pK Enter send vlan req\n", fnic2);
+	fnic2_fcoe_reset_vlans(fnic2);
+
+	fnic2->set_vlan(fnic2, 0);
+	pr_debug("fnic2 0x%pK set vlan done\n", fnic2);
+
+	fr_len = sizeof(struct fip_vlan_req);
+
+	pr_debug("got MAC %x %x %x %x %x %x\n",
+		lport->hwmac[0], lport->hwmac[1], lport->hwmac[2],
+		lport->hwmac[3], lport->hwmac[4], lport->hwmac[5]);
+
+	memcpy(&vlan_req, &fip_vlan_reqmpl, fr_len);
+	memcpy(vlan_req.eth.smac, lport->hwmac, ETH_ALEN);
+	memcpy(vlan_req.mac_desc.mac, lport->hwmac, ETH_ALEN);
+
+	fnic2_send_fip_frame(lport, &vlan_req, fr_len);
+	pr_debug("fnic2 0x%pK vlan req frame sent\n", fnic2);
+
+	lport->fip.state = FDLS_FIP_VLAN_DISCOVERY_STARTED;
+
+	pr_debug("fnic2 0x%pK set timer\n", fnic2);
+	vlan_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_FIPVLAN_TOV);
+	mod_timer(&fnic2->retry_fip_timer, round_jiffies(vlan_tov));
+	pr_debug("fnic2 0x%pK timer done\n", fnic2);
+}
+
+/**
+ * fnic2_fcoe_process_vlan_resp
+ *
+ * Processes the vlan response from one FCF and populates VLAN list.
+ * Will wait for responses from multiple FCFs until timeout.
+ *
+ * @param fnic2 fnic2 driver instance
+ * @param fiph received fip frame
+ */
+
+static void fnic2_fcoe_process_vlan_resp(struct fnic2 *fnic2, struct fip_header *fiph)
+{
+	struct fip_vlan_notif *vlan_notif = (struct fip_vlan_notif *) fiph;
+	uint16_t vid;
+	int num_vlan = 0;
+	int cur_desc, desc_len;
+	struct fcoe_vlan *vlan;
+	struct fip_vlan_desc *vlan_desc;
+	unsigned long flags;
+
+        pr_debug("fnic2 0x%pK got vlan resp\n", fnic2);
+
+	desc_len = ntohs(vlan_notif->fip.desc_len);
+        pr_debug("desc_len %d\n", desc_len);
+
+	spin_lock_irqsave(&fnic2->vlans_lock, flags);
+
+	cur_desc = 0;
+	while (desc_len > 0) {
+		vlan_desc = (struct fip_vlan_desc *)
+		    (((char *)vlan_notif->vlans_desc) + cur_desc * 4);
+		if (vlan_desc->type == FIP_TYPE_VLAN) {
+			if (vlan_desc->len != 1) {
+				pr_debug("Invalid descriptor length %x in VLan response\n",
+					vlan_desc->len);
+
+			}
+			num_vlan++;
+			vid = ntohs(vlan_desc->vlan);
+			pr_debug("process_vlan_resp: FIP VLAN %d\n", vid);
+			vlan = kmalloc(sizeof(*vlan), GFP_ATOMIC);
+
+			if (!vlan) {
+				/* retry from timer */
+				spin_unlock_irqrestore(&fnic2->vlans_lock, flags);
+				goto out;
+			}
+			memset(vlan, 0, sizeof(struct fcoe_vlan));
+			vlan->vid = vid & 0x0fff;
+			vlan->state = FIP_VLAN_AVAIL;
+			list_add_tail(&vlan->list, &fnic2->vlan_list);
+			break;
+		} else {
+                        pr_debug("Invalid descriptor type %x in VLan response\n",
+				vlan_desc->type);
+			// Note : received a type=2 descriptor here i.e. FIP
+			// MAC Address Descriptor
+		}
+		cur_desc += vlan_desc->len;
+		desc_len -= vlan_desc->len;
+	}
+
+	/* any VLAN descriptors present ? */
+	if (num_vlan == 0) {
+		pr_debug("fnic2 0x%pK No VLAN descriptors in FIP VLAN response\n", fnic2);
+	}
+
+	spin_unlock_irqrestore(&fnic2->vlans_lock, flags);
+
+out:
+	return;
+}
+
+/**
+ * fnic2_fcoe_start_fcf_discovery
+ *
+ * Starts FIP FCF discovery in a selected vlan
+ *
+ * @param fnic2 fnic2 driver instance
+ */
+
+static void fnic2_fcoe_start_fcf_discovery(struct fnic2 *fnic2)
+{
+	struct fnic2_lport *lport = &fnic2->lport;
+	uint64_t fcs_tov;
+
+	int fr_len;
+	struct fip_discovery disc_sol;
+
+	pr_debug("fnic2 0x%pK start fcf discovery\n", fnic2);
+	fr_len = sizeof(struct fip_discovery);
+	memset(lport->selected_fcf.fcf_mac, 0, ETH_ALEN);
+
+	memcpy(&disc_sol, &fip_discoverympl, fr_len);
+	memcpy(disc_sol.eth.smac, lport->hwmac, ETH_ALEN);
+	memcpy(disc_sol.mac_desc.mac, lport->hwmac, ETH_ALEN);
+	lport->selected_fcf.fcf_priority = 0xFF;
+
+	disc_sol.name_desc.name = cpu_to_be64(lport->wwnn);
+	fnic2_send_fip_frame(lport, &disc_sol, fr_len);
+
+	lport->fip.state = FDLS_FIP_FCF_DISCOVERY_STARTED;
+
+	fcs_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_FCS_TOV);
+	mod_timer(&fnic2->retry_fip_timer, round_jiffies(fcs_tov));
+
+	pr_debug("fnic2 0x%pK Started FCF discovery", fnic2);
+
+}
+
+/*
+ * fnic2_fcoe_fip_discovery_resp
+ *
+ * Processes FCF advertisements.
+ * They can be:
+ * solicited   Sent in response of a discover FCF FIP request
+ *             We will only store the information of the FCF with
+ *             highest priority.
+ *             We wait until timeout in case of multiple FCFs.
+ * unsolicited Sent periodically by the FCF for keep alive.
+ *             If FLOGI is in progress or completed and the advertisement is
+ *             received by our selected FCF, refresh the keep alive timer.
+ *
+ * @param fnic2 fnic2 driver instance
+ * @param fiph received frame
+ */
+
+static void fnic2_fcoe_fip_discovery_resp(struct fnic2 *fnic2, struct fip_header *fiph)
+{
+	struct fnic2_lport *lport = &fnic2->lport;
+	struct fip_disc_adv *disc_adv = (struct fip_disc_adv *) fiph;
+	uint64_t fcs_ka_tov;
+	int desc_len = ntohs(disc_adv->fip.desc_len);
+
+        pr_debug("fnic2 0x%pK In fcf discovery resp\n", fnic2);
+        pr_debug("fip state %d\n", lport->fip.state);
+
+	if (!(desc_len == 12)) {
+		pr_debug("struct fip_disc_adv invalid Descriptor List len %x\n",
+			desc_len);
+	}
+        if (!((disc_adv->prio_desc.type == 1) && (disc_adv->prio_desc.len == 1)) ||
+		!((disc_adv->mac_desc.type == 2) && (disc_adv->mac_desc.len == 2)) ||
+		!((disc_adv->name_desc.type == 4) && (disc_adv->name_desc.len == 3)) ||
+		!((disc_adv->fabric_desc.type == 5) &&
+		(disc_adv->fabric_desc.len == 4)) ||
+		!((disc_adv->fka_adv_desc.type == 12) &&
+		(disc_adv->fabric_desc.len == 2))) {// this len comes 4 ??
+		pr_debug("struct fip_disc_adv invalid Descriptor type and len mix:  type %x len %x | type %x len %x | type %x len%x |type %x len %x | type %x len %x\n",
+			disc_adv->prio_desc.type, disc_adv->prio_desc.len,
+			disc_adv->mac_desc.type, disc_adv->mac_desc.len,
+			disc_adv->name_desc.type, disc_adv->name_desc.len,
+			disc_adv->fabric_desc.type, disc_adv->fabric_desc.len,
+			disc_adv->fka_adv_desc.type, disc_adv->fabric_desc.len);
+	}
+
+	if (lport->fip.state == FDLS_FIP_FCF_DISCOVERY_STARTED) {
+		if (ntohs(disc_adv->fip.flags) & FIP_FLAG_S) {
+			pr_debug("fnic2 0x%pK Solicited adv\n", fnic2);
+
+			if ((disc_adv->prio_desc.priority <
+				lport->selected_fcf.fcf_priority) &&
+				(ntohs(disc_adv->fip.flags) & FIP_FLAG_A)) {
+
+				pr_debug("fnic2 0x%pK FCF Available\n", fnic2);
+				memcpy(lport->selected_fcf.fcf_mac,
+					disc_adv->mac_desc.mac, ETH_ALEN);
+				lport->selected_fcf.fcf_priority =
+					disc_adv->prio_desc.priority;
+				lport->selected_fcf.fka_adv_period =
+					ntohl(disc_adv->fka_adv_desc.fka_adv);
+				pr_debug("adv time %d",
+					lport->selected_fcf.fka_adv_period);
+				lport->selected_fcf.ka_disabled =
+					(disc_adv->fka_adv_desc.rsvd_D & 1);
+			}
+		} else {
+			// ignore
+		}
+	} else if ((lport->fip.state == FDLS_FIP_FLOGI_STARTED) ||
+		(lport->fip.state == FDLS_FIP_FLOGI_COMPLETE)) {
+		if (!(ntohs(disc_adv->fip.flags) & FIP_FLAG_S)) {
+			//  same fcf
+			if (memcmp(lport->selected_fcf.fcf_mac,
+				disc_adv->mac_desc.mac, ETH_ALEN) == 0) {
+				if (lport->selected_fcf.fka_adv_period !=
+					ntohl(disc_adv->fka_adv_desc.fka_adv)) {
+					lport->selected_fcf.fka_adv_period =
+						ntohl(disc_adv->fka_adv_desc.fka_adv);
+					pr_debug("change fka to %d",
+						lport->selected_fcf.fka_adv_period);
+				}
+				if (!((lport->selected_fcf.ka_disabled) ||
+					(lport->selected_fcf.fka_adv_period == 0))) {
+
+					fcs_ka_tov = jiffies +
+						3 * msecs_to_jiffies(lport->selected_fcf.fka_adv_period);
+					mod_timer(&fnic2->fcs_ka_timer, round_jiffies(fcs_ka_tov));
+
+				}
+			}
+		}
+	}
+}
+
+/*
+ * fnic2_fcoe_start_flogi
+ *
+ * Sends FIP FLOGI to the selected FCF
+ *
+ * @param fnic2 fnic2 driver instance
+ */
+
+static void fnic2_fcoe_start_flogi(struct fnic2 *fnic2)
+{
+        struct fnic2_lport *lport = &fnic2->lport;
+
+	int fr_len;
+	struct fip_flogi flogi_req;
+	uint64_t flogi_tov;
+
+	fr_len = sizeof(struct fip_flogi);
+        pr_debug("fnic2 0x%pK Start fip FLOGI\n", fnic2);
+
+	memcpy(&flogi_req, &fip_flogimpl, fr_len);
+	memcpy(flogi_req.eth.smac, lport->hwmac, ETH_ALEN);
+	if (lport->usefip) {
+	    memcpy(flogi_req.eth.dmac, lport->selected_fcf.fcf_mac, ETH_ALEN);
+	}
+	flogi_req.flogi_desc.flogi.nport_name = cpu_to_be64(lport->wwpn);
+	flogi_req.flogi_desc.flogi.node_name = cpu_to_be64(lport->wwnn);
+
+	fnic2_send_fip_frame(lport, &flogi_req, fr_len);
+	lport->fip.flogi_retry++;
+
+	lport->fip.state = FDLS_FIP_FLOGI_STARTED;
+        flogi_tov = jiffies + msecs_to_jiffies(fnic2->config.flogi_timeout);
+	mod_timer(&fnic2->retry_fip_timer, round_jiffies(flogi_tov));
+}
+
+/*
+ * fnic2_fcoe_process_flogi_resp
+ *
+ * Processes FLOGI response from FCF.
+ * If successful saves assigned fc_id and MAC, programs firmware
+ * and starts fdls discovery.
+ * Else restarts vlan discovery.
+ *
+ * @param fnic2 fnic2 driver instance
+ * @param fiph received frame
+ */
+
+void fnic2_fcoe_process_flogi_resp(struct fnic2 *fnic2, struct fip_header *fiph)
+{
+	struct fnic2_lport *lport = &fnic2->lport;
+	struct fip_flogi_rsp *flogi_rsp = (struct fip_flogi_rsp *) fiph;
+	int desc_len;
+	uint32_t s_id;
+
+        pr_debug("fnic2 0x%pK FIP FLOGI rsp\n", fnic2);
+	desc_len = ntohs(flogi_rsp->fip.desc_len);
+	if (desc_len != 38) {
+		pr_debug("%s invalid Descriptor List len %x\n",
+			__func__, desc_len);
+	}
+	if (!((flogi_rsp->rsp_desc.type == 7) && (flogi_rsp->rsp_desc.len == 36)) ||
+		!((flogi_rsp->mac_desc.type == 2) && (flogi_rsp->mac_desc.len == 2))) {
+                pr_debug("dropping frame. %s invalid Descriptor type and len mix:\n flogi_rsp->rsp_desc.type %x flogi_rsp->rsp_desc.len %x flogi_rsp->mac_desc.type %x flogi_rsp->mac_desc.len %x\n",
+			__func__, flogi_rsp->rsp_desc.type, flogi_rsp->rsp_desc.len,
+			flogi_rsp->mac_desc.type, flogi_rsp->mac_desc.len);
+
+	}
+	s_id = ntoh24(flogi_rsp->rsp_desc.els.fchdr.s_id);
+	if ((flogi_rsp->rsp_desc.els.fchdr.f_ctl[0] != 0x98) ||
+		(flogi_rsp->rsp_desc.els.fchdr.r_ctl != 0x23) ||
+		(s_id != 0xFFFFFE) ||
+		(flogi_rsp->rsp_desc.els.fchdr.ox_id != FNIC2_FLOGI_OXID) ||
+		(flogi_rsp->rsp_desc.els.fchdr.type != 0x01)) {
+                pr_debug("fnic2_fcoe_process_flogi_resp received Flogi resp with some Invalid fc frame bits s_id %x FCTL %x R_CTL %x type %x OX_ID %x Dropping the frame\n",
+			s_id,
+			ntoh24(flogi_rsp->rsp_desc.els.fchdr.f_ctl),
+			flogi_rsp->rsp_desc.els.fchdr.r_ctl,
+			flogi_rsp->rsp_desc.els.fchdr.type,
+			flogi_rsp->rsp_desc.els.fchdr.ox_id);
+		return;
+	}
+
+	if (lport->fip.state == FDLS_FIP_FLOGI_STARTED) {
+		pr_debug("fnic2 0x%pK rsp for pending FLOGI\n", fnic2);
+
+		del_timer_sync(&fnic2->retry_fip_timer);
+
+		if ((ntohs(flogi_rsp->fip.desc_len) == 38) &&
+			(flogi_rsp->rsp_desc.els.command == FC_LS_ACC)) {
+
+			pr_debug("fnic2 0x%pK FLOGI success\n", fnic2);
+			memcpy(lport->fpma, flogi_rsp->mac_desc.mac, ETH_ALEN);
+			lport->fcid = ntoh24(flogi_rsp->rsp_desc.els.fchdr.d_id);
+
+			lport->r_a_tov =
+				ntohl(flogi_rsp->rsp_desc.els.u.csp_flogi.r_a_tov);
+			lport->e_d_tov =
+				ntohl(flogi_rsp->rsp_desc.els.u.csp_flogi.e_d_tov);
+			memcpy(fnic2->lport.fcfmac, lport->selected_fcf.fcf_mac,
+				ETH_ALEN);
+			vnic_dev_add_addr(fnic2->vdev, flogi_rsp->mac_desc.mac);
+
+			if (fnic2_fdls_register_portid(lport, lport->fcid, NULL) != 0) {
+				pr_debug("fnic2 0x%pK flogi registration failed\n", fnic2);
+				return;
+			}
+
+			lport->fip.state = FDLS_FIP_FLOGI_COMPLETE;
+			lport->state = FNIC2_IPORT_STATE_FABRIC_DISC;
+			pr_debug("lport->state: %d\n",
+				lport->state);
+			fnic2_fdls_disc_start(lport);
+			if (!lport->selected_fcf.ka_disabled) {
+				uint64_t tov;
+
+				tov = jiffies + msecs_to_jiffies(FCOE_CTLR_ENODE_KA_TOV);
+				mod_timer(&fnic2->enode_ka_timer, round_jiffies(tov));
+
+				tov = jiffies + msecs_to_jiffies(FCOE_CTLR_VN_KA_TOV);
+				mod_timer(&fnic2->vn_ka_timer, round_jiffies(tov));
+
+			}
+		} else {
+			/*
+			 * If there's FLOGI rejects - clear all
+			 * fcf's & restart from scratch
+			 * start FCoE VLAN discovery
+			 */
+			fnic2_fcoe_send_vlan_req(fnic2);
+
+			lport->fip.state = FDLS_FIP_VLAN_DISCOVERY_STARTED;
+		}
+	}
+}
+
+/*
+ * fnic2_common_fip_cleanup
+ *
+ * Cleans up FCF info and timers in case of link down/CVL
+ *
+ * @param fnic2 fnic2 driver instance
+ */
+
+void fnic2_common_fip_cleanup(struct fnic2 *fnic2)
+{
+
+        struct fnic2_lport *lport = &fnic2->lport;
+
+	if (!lport->usefip)
+		return;
+        pr_debug("fnic2 0x%pK fip cleanup\n", fnic2);
+
+	// cleanup flogi form hw
+	fnic2_fw_reset_handler(fnic2);
+
+	lport->fip.state = FDLS_FIP_INIT;
+
+	del_timer_sync(&fnic2->retry_fip_timer);
+	del_timer_sync(&fnic2->fcs_ka_timer);
+	del_timer_sync(&fnic2->enode_ka_timer);
+	del_timer_sync(&fnic2->vn_ka_timer);
+
+	vnic_dev_del_addr(fnic2->vdev, lport->fpma);
+
+	memset(lport->fpma, 0, ETH_ALEN);
+	lport->fcid = 0;
+	lport->r_a_tov = 0;
+	lport->e_d_tov = 0;
+	memset(fnic2->lport.fcfmac, 0, ETH_ALEN);
+	memset(lport->selected_fcf.fcf_mac, 0, ETH_ALEN);
+	lport->selected_fcf.fcf_priority = 0;
+	lport->selected_fcf.fka_adv_period = 0;
+	lport->selected_fcf.ka_disabled = 0;
+
+	fnic2_fcoe_reset_vlans(fnic2);
+}
+
+/*
+ * fnic2_fcoe_process_cvl
+ *
+ * Processes Clear Virtual Link from FCF
+ * Verifies that cvl is received from our current FCF for our assigned MAC
+ * Cleans up and restarts the vlan discovery
+ *
+ * @param fnic2 fnic2 driver instance
+ * @param fiph received frame
+ */
+
+static void fnic2_fcoe_process_cvl(struct fnic2 *fnic2, struct fip_header *fiph)
+{
+        struct fnic2_lport *lport = &fnic2->lport;
+	struct fip_cvl *cvl_msg = (struct fip_cvl *) fiph;
+	int i;
+	int found = false;
+
+        pr_debug("fnic2 0x%pK clear virtual link handler\n", fnic2);
+
+	if (!((cvl_msg->fcf_mac_desc.type == 2) &&
+		(cvl_msg->fcf_mac_desc.len == 2)) ||
+		!((cvl_msg->name_desc.type == 4) &&
+		(cvl_msg->name_desc.len == 3))) {
+
+                pr_debug("fnic2_fcoe_process_cvl invalid Descriptor type and len mix: fcf_mac_desc.type %x fcf_mac_desc.len %x  cvl_msg->name_desc.type %x cvl_msg->name_desc.len %x\n",
+			cvl_msg->fcf_mac_desc.type, cvl_msg->fcf_mac_desc.len,
+			cvl_msg->name_desc.type, cvl_msg->name_desc.len);
+	}
+
+	if (memcmp(lport->selected_fcf.fcf_mac, cvl_msg->fcf_mac_desc.mac,
+	    ETH_ALEN) == 0) {
+		for (i = 0; i < ((ntohs(fiph->desc_len) / 5) - 1); i++) {
+			if (!((cvl_msg->vn_ports_desc[i].type == 11) &&
+			    (cvl_msg->vn_ports_desc[i].len == 5))) {
+
+				pr_debug("fnic2_fcoe_process_cvl invalid Descriptor type and len mix: vn_ports_desc[i].type %d vn_ports_desc[i].len %d\n",
+					cvl_msg->vn_ports_desc[i].type,
+					cvl_msg->vn_ports_desc[i].len);
+			}
+			if (memcmp(lport->fpma,
+			    cvl_msg->vn_ports_desc[i].vn_port_mac,
+			    ETH_ALEN) == 0) {
+				found = true;
+				break;
+			}
+		}
+		if (!found)
+			return;
+		fnic2_common_fip_cleanup(fnic2);
+		fnic2_fdls_link_down(lport);
+
+		fnic2_fcoe_send_vlan_req(fnic2);
+	}
+}
+
+/*
+ * fdls_fip_recv_frame
+ *
+ * Demultiplexer for FIP frames
+ *
+ * @param fnic2 driver instance
+ * @param frame received ethernet frame
+ * @return Frame processed by FIP
+ */
+
+int fdls_fip_recv_frame(struct fnic2 *fnic2, void *frame)
+{
+    struct eth_hdr *eth = (struct eth_hdr *) frame;
+    struct fip_header *fiph;
+    uint16_t protocol;
+    uint8_t sub;
+
+    if (eth->eth_type == ntohs(FIP_ETH_TYPE)) {
+
+	fiph = (struct fip_header *) (eth+1);
+	protocol = ntohs(fiph->protocol);
+	sub = ntohs(fiph->subcode);
+
+	pr_debug("recv fip frame op %x sub %x\n",
+		protocol, sub);
+
+	if (protocol == FIP_DISCOVERY && sub == FIP_SUBCODE_RESP) {
+		fnic2_fcoe_fip_discovery_resp(fnic2, fiph);
+	} else if (protocol == FIP_VLAN_DISC && sub == FIP_SUBCODE_RESP) {
+		fnic2_fcoe_process_vlan_resp(fnic2, fiph);
+	} else if (protocol == FIP_KA_CVL && sub == FIP_SUBCODE_RESP) {
+		fnic2_fcoe_process_cvl(fnic2, fiph);
+	} else if (protocol == FIP_FLOGI && sub == FIP_SUBCODE_RESP) {
+		fnic2_fcoe_process_flogi_resp(fnic2, fiph);
+	}
+	return 1;
+    }
+    return 0;
+}
+
+/*
+ * fnic2_handle_fip_timer
+ *
+ * Timeout handler for FIP discover phase.
+ * Based on the current state, starts next phase or restarts discovery
+ *
+ * @param data Opaque pointer to fnic2 structure
+ */
+
+void fnic2_handle_fip_timer(struct timer_list *timer)
+{
+	struct fnic2 *fnic2 = container_of(timer, struct fnic2, retry_fip_timer);
+        struct fnic2_lport *lport = &fnic2->lport;
+
+        pr_debug("fnic2 0x%pK fip timeout\n", fnic2);
+
+	if (lport->fip.state == FDLS_FIP_VLAN_DISCOVERY_STARTED) {
+		// pr_debug("vlan discovey timeout\n");
+		fnic2_vlan_discovery_timeout(fnic2);
+	} else if (lport->fip.state == FDLS_FIP_FCF_DISCOVERY_STARTED) {
+		uint8_t zmac[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
+
+		pr_debug("fnic2 0x%pK fcf discovey timeout\n", fnic2);
+		if (memcmp(lport->selected_fcf.fcf_mac, zmac, ETH_ALEN) != 0) {
+			fnic2_fcoe_start_flogi(fnic2);
+			if (!((lport->selected_fcf.ka_disabled) ||
+				(lport->selected_fcf.fka_adv_period == 0))) {
+				uint64_t fcf_tov;
+
+				fcf_tov = jiffies +
+					3 * msecs_to_jiffies(lport->selected_fcf.fka_adv_period);
+				mod_timer(&fnic2->fcs_ka_timer, round_jiffies(fcf_tov));
+			}
+		} else {
+			pr_debug("fnic2 0x%pK FCF discovey timeout\n", fnic2);
+			fnic2_vlan_discovery_timeout(fnic2);
+		}
+	} else if (lport->fip.state == FDLS_FIP_FLOGI_STARTED) {
+		pr_debug("fnic2 0x%pK flogi timeout\n", fnic2);
+		if (lport->fip.flogi_retry < fnic2->config.flogi_retries) {
+			fnic2_fcoe_start_flogi(fnic2);
+		} else {
+			fnic2_vlan_discovery_timeout(fnic2);
+		}
+	}
+}
+
+/*
+ * fnic2_handle_enode_ka_timer
+ *
+ * FIP node keep alive.
+ *
+ * @param data Opaque pointer to fnic2 struct
+ */
+void fnic2_handle_enode_ka_timer(struct timer_list *timer)
+{
+    struct fnic2 *fnic2 = container_of(timer, struct fnic2, enode_ka_timer);
+    struct fnic2_lport *lport = &fnic2->lport;
+    int fr_len;
+    struct fip_enode_ka enode_ka;
+    uint64_t enode_ka_tov;
+
+    pr_debug("fnic2 0x%pK ka timer\n", fnic2);
+
+    if (lport->fip.state != FDLS_FIP_FLOGI_COMPLETE) {
+	return;
+    }
+
+    fr_len = sizeof(struct fip_enode_ka);
+
+    memcpy(&enode_ka, &fip_enode_kampl, fr_len);
+    memcpy(enode_ka.eth.smac, lport->hwmac, ETH_ALEN);
+    memcpy(enode_ka.eth.dmac, lport->selected_fcf.fcf_mac, ETH_ALEN);
+    memcpy(enode_ka.mac_desc.mac, lport->hwmac, ETH_ALEN);
+
+    fnic2_send_fip_frame(lport, &enode_ka, fr_len);
+    enode_ka_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_ENODE_KA_TOV);
+    mod_timer(&fnic2->enode_ka_timer, round_jiffies(enode_ka_tov));
+}
+
+/*
+ * fnic2_handle_vn_ka_timer
+ *
+ * FIP virtual port keep alive.
+ *
+ * @param data Opaque pointer to fnic2 structure
+ */
+
+void fnic2_handle_vn_ka_timer(struct timer_list *timer)
+{
+	struct fnic2 *fnic2 = container_of(timer, struct fnic2, vn_ka_timer);
+        struct fnic2_lport *lport = &fnic2->lport;
+	int fr_len;
+	struct fip_vn_port_ka vn_port_ka;
+	uint64_t vn_ka_tov;
+	uint8_t fcid[3];
+
+        pr_debug("fnic2 0x%pK vn port ka timer\n", fnic2);
+
+	if (lport->fip.state != FDLS_FIP_FLOGI_COMPLETE) {
+		return;
+	}
+
+	fr_len = sizeof(struct fip_vn_port_ka);
+
+	memcpy(&vn_port_ka, &fip_vn_port_kampl, fr_len);
+	memcpy(vn_port_ka.eth.smac, lport->hwmac, ETH_ALEN);
+        memcpy(vn_port_ka.eth.dmac, lport->selected_fcf.fcf_mac, ETH_ALEN);
+	memcpy(vn_port_ka.mac_desc.mac, lport->hwmac, ETH_ALEN);
+	memcpy(vn_port_ka.vn_port_desc.vn_port_mac, lport->fpma, ETH_ALEN);
+	hton24(fcid, lport->fcid);
+	memcpy(vn_port_ka.vn_port_desc.vn_port_id, fcid, 3);
+	vn_port_ka.vn_port_desc.vn_port_name = cpu_to_be64(lport->wwpn);
+
+	fnic2_send_fip_frame(lport, &vn_port_ka, fr_len);
+	vn_ka_tov = jiffies + msecs_to_jiffies(FCOE_CTLR_VN_KA_TOV);
+	mod_timer(&fnic2->vn_ka_timer, round_jiffies(vn_ka_tov));
+}
+
+/*
+ * fnic2_vlan_discovery_timeout
+ *
+ * End of VLAN discovery or FCF discovery time window
+ * Start the FCF discovery if VLAN was never used
+ * Retry in case of FCF not responding or move to next VLAN
+ *
+ * @param fnic2 fnic2 driver instance
+ */
+
+static void fnic2_vlan_discovery_timeout(struct fnic2 *fnic2)
+{
+	struct fcoe_vlan *vlan;
+        struct fnic2_lport *lport = &fnic2->lport;
+	unsigned long flags;
+
+	spin_lock_irqsave(&fnic2->fnic2_lock, flags);
+	if (fnic2->stop_rx_link_events) {
+		spin_unlock_irqrestore(&fnic2->fnic2_lock, flags);
+		return;
+	}
+	spin_unlock_irqrestore(&fnic2->fnic2_lock, flags);
+
+	if (!lport->usefip)
+		 return;
+
+	spin_lock_irqsave(&fnic2->vlans_lock, flags);
+	if (list_empty(&fnic2->vlan_list)) {
+		/* no vlans available, try again */
+		spin_unlock_irqrestore(&fnic2->vlans_lock, flags);
+		fnic2_fcoe_send_vlan_req(fnic2);
+		return;
+	}
+
+	vlan = list_first_entry(&fnic2->vlan_list, struct fcoe_vlan, list);
+
+	if (vlan->state == FIP_VLAN_SENT) {
+		if (vlan->sol_count >= FCOE_CTLR_MAX_SOL) {
+			/*
+			 * no response on this vlan, remove  from the list.
+			 * Try the next vlan
+			 */
+			list_del(&vlan->list);
+			kfree(vlan);
+			vlan = NULL;
+			if (list_empty(&fnic2->vlan_list)) {
+			    /* we exhausted all vlans, restart vlan disc */
+			    spin_unlock_irqrestore(&fnic2->vlans_lock, flags);
+			    fnic2_fcoe_send_vlan_req(fnic2);
+			    return;
+			}
+			/* check the next vlan */
+			vlan = list_first_entry(&fnic2->vlan_list, struct fcoe_vlan, list);
+
+			fnic2->set_vlan(fnic2, vlan->vid);
+			vlan->state = FIP_VLAN_SENT; /* sent now */
+
+		}
+	} else {
+		fnic2->set_vlan(fnic2, vlan->vid);
+		vlan->state = FIP_VLAN_SENT; /* sent now */
+	}
+	vlan->sol_count++;
+	spin_unlock_irqrestore(&fnic2->vlans_lock, flags);
+	fnic2_fcoe_start_fcf_discovery(fnic2);
+}
+
+/*
+ * fnic2_work_on_fcs_ka_timer - finish handling fcs_ka_timer in process context
+ *
+ * We need to finish this timer in a process context so that we do
+ * not hand in fip_common_cleanup. Here we clean up, bring the link down
+ * and restart all FIP discovery.
+ *
+ * @work - the work queue that we will be servicing
+ */
+void fnic2_work_on_fcs_ka_timer(struct work_struct *work)
+{
+	struct fnic2 *fnic2 = container_of(work, struct fnic2, fip_work);
+	struct fnic2_lport *lport = &fnic2->lport;
+
+	pr_debug("fnic2 0x%pK fcs ka timeout\n", fnic2);
+
+	fnic2_common_fip_cleanup(fnic2);
+	fnic2_fdls_link_down(lport);
+
+	lport->state = FNIC2_IPORT_STATE_FIP;
+	fnic2_fcoe_send_vlan_req(fnic2);
+}
+
+/*
+ * fnic2_handle_fcs_ka_timer
+ *
+ * No keep alives received from FCF. Clean up, bring the link down
+ * and restart all the FIP discovery.
+ *
+ * @param data Opaque pointer to fnic2 structure
+ */
+void fnic2_handle_fcs_ka_timer(struct timer_list *timer)
+{
+	struct fnic2 *fnic2 = container_of(timer, struct fnic2, fcs_ka_timer);
+	INIT_WORK(&fnic2->fip_work, fnic2_work_on_fcs_ka_timer);
+	queue_work(fip_event_queue, &fnic2->fip_work);
+}
drivers/staging/fnic2/src/fip.h new file +336 -0

336 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 4/10 staging: fnic2 add fdls system

In reply to Oliver Smith-Denny

These files contain Fibre Channel discovery handling and fabric services.

---
 drivers/staging/fnic2/src/fdls_disc.c  | 1539 ++++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/fdls_fc.h    |  403 +++++++++
 drivers/staging/fnic2/src/fdls_if.c    | 1254 ++++++++++++++++++++++++++
 drivers/staging/fnic2/src/fnic2_fdls.h |  232 +++++
 4 files changed, 3428 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fdls_disc.c
 create mode 100644 drivers/staging/fnic2/src/fdls_fc.h
 create mode 100644 drivers/staging/fnic2/src/fdls_if.c
 create mode 100644 drivers/staging/fnic2/src/fnic2_fdls.h
drivers/staging/fnic2/src/fdls_disc.c new file +1539 -0
new file mode 100644
index 0000000..e955116
@@ -0,0 +1,1539 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "fnic2.h"
+#include "fdls_fc.h"
+#include "fnic2_fdls.h"
+
+static void fdls_send_rpn_id(struct fnic2_lport *lport);
+struct fnic2_rport *fnic2_find_rport_by_fcid(struct fnic2_lport *lport, uint32_t fcid);
+struct fnic2_rport *fnic2_find_rport(struct fnic2_lport *lport, uint64_t wwpn);
+void fnic2_fdls_remove_rport(struct fnic2_lport *lport, struct fnic2_rport *rport);
+struct fnic2_rport *fnic2_fdls_add_rport(struct fnic2_lport *lport, struct fnic2_rport *rport);
+struct fnic2_rport *fdls_create_rport(struct fnic2_lport *lport, uint32_t fcid, uint64_t wwpn);
+void fdls_delete_rport(struct fnic2_lport *lport, struct fnic2_rport *rport);
+
+extern int fnic2_session_create(struct fnic2 *fnic2, struct fnic2_rport *rport);
+
+/* Frame initialization */
+
+/*
+ * Variables:
+ * s_id
+ */
+struct fc_els fnic2_flogi_req = {
+	.fchdr = {.r_ctl = 0x22, .d_id = {0xFF, 0xFF, 0xFE},
+		.type = 0x01, .f_ctl = {FNIC2_ELS_REQ_FCTL, 0x00, 0x00},
+	.ox_id = FNIC2_FLOGI_OXID, .rx_id = 0xFFFF},
+	.command = FC_ELS_FLOGI_REQ,
+	.u.csp_flogi = {.fc_ph_ver = FNIC2_FC_PH_VER,
+	.b2b_credits = FNIC2_FC_B2B_CREDIT,
+	.b2b_rdf_size = FNIC2_FC_B2B_RDF_SZ},
+	.spc3 = {0x88, 0x00}
+};
+
+/*
+ * Variables:
+ * s_id, d_id(nport logins), ox_id(nport logins), nport_name, node_name
+ */
+struct fc_els fnic2_plogi_req = {
+	.fchdr = {.r_ctl = 0x22, .d_id = {0xFF, 0xFF, 0xFC}, .type = 0x01,
+		.f_ctl = {FNIC2_ELS_REQ_FCTL, 0x00, 0x00}, .ox_id = FNIC2_PLOGI_FABRIC_OXID,
+		.rx_id = 0xFFFF},
+	.command = FC_ELS_PLOGI_REQ,
+	.u.csp_plogi = {.fc_ph_ver = FNIC2_FC_PH_VER,
+		.b2b_credits = FNIC2_FC_B2B_CREDIT, .features = 0x0080,
+		.b2b_rdf_size = FNIC2_FC_B2B_RDF_SZ,
+		.total_concur_seqs = FNIC2_FC_CONCUR_SEQS,
+		.ro_info = FNIC2_FC_RO_INFO, .e_d_tov = FNIC2_E_D_TOV},
+	.spc3 = {0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
+		 0x00, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}
+};
+
+/*
+ * Variables:
+ * s_id, d_id(nport logins), ox_id(nport logins), nport_name, node_name
+ */
+struct fc_els fnic2_plogi_resp = {
+	.fchdr = {.r_ctl = 0x23, .type = 0x01,
+		.f_ctl = {FNIC2_ELS_REP_FCTL, 0x00, 0x00} },
+	.command = FC_LS_ACC,
+	.u.csp_plogi = {.fc_ph_ver = FNIC2_FC_PH_VER,
+		.b2b_credits = FNIC2_FC_B2B_CREDIT, .features = 0x0080,
+		.b2b_rdf_size = FNIC2_FC_B2B_RDF_SZ,
+	.total_concur_seqs = FNIC2_FC_CONCUR_SEQS,
+	.ro_info = FNIC2_FC_RO_INFO, .e_d_tov = FNIC2_E_D_TOV},
+	.spc3 = {0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
+		 0x00, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}
+};
+
+/*
+ * Variables:
+ * s_id, port_id, port_name
+ */
+struct fc_rpn_id fnic2_rpn_id_req = {
+	.fchdr = {.r_ctl = 0x02, .d_id = {0xFF, 0xFF, 0xFC}, .type = 0x20,
+		.f_ctl = {FNIC2_ELS_REQ_FCTL, 0x00, 0x00}, .ox_id = FNIC2_RPN_REQ_OXID,
+		.rx_id = 0xFFFF},
+	.fc_ct_hdr = {.rev = 0x01, .fs_type = 0xFC, .fs_subtype = 0x02,
+			.command = FC_CT_RPN_CMD}
+};
+
+/*
+ * Variables:
+ * s_id, port_id, port_name
+ */
+struct fc_rft_id fnic2_rft_id_req = {
+	.fchdr = {.r_ctl = 0x02, .d_id = {0xFF, 0xFF, 0xFC}, .type = 0x20,
+		.f_ctl = {FNIC2_ELS_REQ_FCTL, 0x00, 0x00}, .ox_id = FNIC2_RFT_REQ_OXID,
+		.rx_id = 0xFFFF},
+	.fc_ct_hdr = {.rev = 0x01, .fs_type = 0xFC, .fs_subtype = 0x02,
+			.command = FC_CT_RFT_CMD}
+};
+
+/*
+ * Variables:
+ * s_id, port_id, port_name
+ */
+struct fc_rff_id fnic2_rff_id_req = {
+	.fchdr = {.r_ctl = 0x02, .d_id = {0xFF, 0xFF, 0xFC}, .type = 0x20,
+		.f_ctl = {FNIC2_ELS_REQ_FCTL, 0x00, 0x00}, .ox_id = FNIC2_RFF_REQ_OXID,
+		.rx_id = 0xFFFF},
+	.fc_ct_hdr = {.rev = 0x01, .fs_type = 0xFC, .fs_subtype = 0x02,
+			.command = FC_CT_RFF_CMD},
+	.tgt = 0x1,
+	.fc4_type = 0x8
+};
+
+/*
+ * Variables:
+ * d_id, s_id, ox_id
+ */
+struct fc_els_prli fnic2_prli_resp = {
+	.fchdr = {.r_ctl = 0x23, .type = 0x01,
+		.f_ctl = {FNIC2_ELS_REP_FCTL, 0x00, 0x00} },
+	.command = FC_LS_ACC,
+	.page_len = 16,
+	.payload_len = 0x1400,
+	.sp = {.type = 0x08, .flags = 0x0021, .csp = 0x12040000}
+};
+
+/*
+ * Variables:
+ * d_id, ox_id, rx_id
+ */
+struct fc_els_acc fnic2_els_acc = {
+	.fchdr = {.r_ctl = 0x23, .d_id = {0xFF, 0xFF, 0xFD}, .type = 0x01,
+		.f_ctl = {FNIC2_ELS_REP_FCTL, 0x00, 0x00} },
+	.command = FC_LS_ACC,
+};
+
+struct fc_els_reject fnic2_els_rjt = {
+	.fchdr = {.r_ctl = 0x23, .type = 0x01, .f_ctl = {FNIC2_ELS_REP_FCTL, 0x00, 0x00} },
+	.command = FC_LS_REJ,
+};
+
+/*
+ * Variables:
+ * d_id, ox_id, rx_id
+ */
+struct fc_abts_ba_acc fnic2_ba_acc = {
+	.fchdr = {.r_ctl = 0x84,
+		.f_ctl = {FNIC2_FCP_RSP_FCTL, 0x00, 0x00}},
+	.low_seq_cnt = 0, .high_seq_cnt = 0xFFFF,
+};
+
+
+/*
+ * Variables:
+ * d_id, ox_id, rx_id, fcid, wwpn
+ */
+struct fc_logo_req fnic2_logo_req = {
+	.fchdr = {.r_ctl = 0x22, .type = 0x01,
+		.f_ctl = {FNIC2_ELS_REQ_FCTL, 0x00, 0x00} },
+	.command = FC_ELS_LOGO,
+};
+
+#define FDLS_TGT_OXID_POOL_SZ   (0x800)
+#define FDLS_TGT_OXID_BLOCK_SZ  (0x200)
+#define FDLS_PLOGI_OXID_BASE    (0x2000)
+#define FDLS_PRLI_OXID_BASE     (0x2200)
+
+uint8_t tgt_ox_id_pool[FDLS_TGT_OXID_POOL_SZ];
+
+/* Private Functions */
+static void fnic2_fdls_start_plogi(struct fnic2_lport *lport);
+
+static void fdls_init_tgt_ox_id_pool(void)
+{
+	memset(tgt_ox_id_pool, 0, FDLS_TGT_OXID_POOL_SZ);
+}
+
+static uint16_t fdls_alloc_tgt_ox_id(uint16_t base)
+{
+	int i;
+	int start, end;
+
+	start = base - FDLS_PLOGI_OXID_BASE;
+	end = start + FDLS_TGT_OXID_BLOCK_SZ;
+
+	for (i = start; i < end; i++) {
+		if (tgt_ox_id_pool[i] == 0) {
+			tgt_ox_id_pool[i] = 1;
+			return (i + FDLS_PLOGI_OXID_BASE);
+		}
+	}
+	return 0xFFFF;
+}
+static void fdls_free_tgt_ox_id(uint16_t ox_id)
+{
+	if (tgt_ox_id_pool[ox_id - FDLS_PLOGI_OXID_BASE] != 1)
+		pr_debug("%s Free unused ox_id:%x\n",
+			 __func__, ox_id);
+	tgt_ox_id_pool[ox_id - FDLS_PLOGI_OXID_BASE] = 0;
+}
+
+static void fdls_process_flogi_rsp(struct fnic2_lport *lport, struct fc_hdr *fchdr, void *rx_frame)
+{
+	struct fnic2_fdls_fabric *fabric = &lport->fabric;
+	struct fc_els *flogi_rsp = (struct fc_els *)fchdr;
+	uint8_t *fcid;
+	int rdf_size;
+	struct fc_els_reject *els_rjt;
+	uint8_t fcmac[6] = {0x0E, 0XFC, 0x00, 0x00, 0x00, 0x00};
+
+	pr_debug("lport 0x%pK fnic2_fcoe_process_flogi_resp\n", lport);
+
+	if (fabric->state != FDLS_STATE_FABRIC_FLOGI) {
+		pr_debug("Flogi resp recvd in state %d. Dropping\n",
+			fabric->state);
+		return;
+	}
+
+	switch (flogi_rsp->command) {
+	case FC_LS_ACC:
+
+		if (lport->fabric.timer_pending) {
+			pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+			del_timer_sync(&fabric->retry_timer);
+		}
+		lport->fabric.timer_pending = 0;
+		lport->fabric.retry_counter = 0;
+
+		fcid = fchdr->d_id;
+		lport->fcid = ntoh24(fcid);
+
+		pr_debug("Flogi resp Accepted: 0x%08x\n", lport->fcid);
+
+		/* Learn the Service Params */
+		rdf_size = ntohl(flogi_rsp->u.csp_flogi.b2b_rdf_size);
+		if ((rdf_size >= FNIC2_FCOE_MIN_FRAME_SZ)  &&
+		    (rdf_size < FNIC2_FCOE_MAX_FRAME_SZ))
+			lport->mfs = rdf_size;
+
+		pr_debug("mfs from fabric:%d, set:%d\n", rdf_size, lport->mfs);
+		lport->r_a_tov = ntohl(flogi_rsp->u.csp_flogi.r_a_tov);
+		lport->e_d_tov = ntohl(flogi_rsp->u.csp_flogi.e_d_tov);
+
+		if (flogi_rsp->u.csp_flogi.features & FNIC2_FC_EDTOV_NSEC)
+			lport->e_d_tov = lport->e_d_tov / FNIC2_NSEC_TO_MSEC;
+
+		pr_debug("from fabric:%d, %d\n", lport->r_a_tov, lport->e_d_tov);
+
+		fnic2_fdls_learn_fcoe_macs(lport, rx_frame, fcid);
+
+		if (fnic2_fdls_register_portid(lport, lport->fcid, rx_frame) !=
+		    0) {
+			pr_debug("lport 0x%pK flogi registration failed\n", lport);
+			break;
+		}
+
+		memcpy(&fcmac[3], fcid, 3);
+		pr_debug("Adding vnic_dev_mac addr:%02x %02x %02x %02x %02x %02x\n",
+			fcmac[0], fcmac[1], fcmac[2], fcmac[3], fcmac[4], fcmac[5]);
+		vnic_dev_add_addr(lport->fnic2->vdev, fcmac);
+
+		fnic2_fdls_start_plogi(lport);
+		break;
+
+	case FC_LS_REJ:
+		els_rjt = (struct fc_els_reject *)fchdr;
+		if (((els_rjt->reason_code == FC_ELS_RJT_LOGICAL_BUSY) ||
+		    (els_rjt->reason_code == FC_ELS_RJT_BUSY)) &&
+		    (fabric->retry_counter < lport->max_flogi_retries)) {
+
+			pr_debug("lport 0x%pK Flogi returned FC_LS_REJ BUSY retry from timer routine..\n",
+				lport);
+
+			/*Retry Flogi again from the timer routine.*/
+			fabric->flags |= FNIC2_FDLS_RETRY_FRAME;
+			// change the name , make it common
+		} else {
+			pr_debug("lport 0x%pK Flogi returned FC_LS_REJ... halting discovery.\n", lport);
+			if (fabric->timer_pending) {
+				pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+				del_timer_sync(&fabric->retry_timer);
+			}
+			fabric->timer_pending = 0;
+			fabric->retry_counter = 0;
+		}
+		break;
+
+	default:
+		pr_debug("Flogi resp Not Accepted: %x\n", flogi_rsp->command);
+		/* TBD Handle it */
+		break;
+	}
+}
+
+static void fdls_process_fabric_plogi_rsp(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_els *plogi_rsp = (struct fc_els *)fchdr;
+	struct fc_els_reject *els_rjt = (struct fc_els_reject *)fchdr;
+
+	pr_debug("lport 0x%pK fnic2_fcoe_process_fabric_plogi_resp", lport);
+	if (lport->fabric.state != FDLS_STATE_FABRIC_PLOGI) {
+		pr_debug("plogi resp recvd in state %d. dropping\n",
+			 lport->fabric.state);
+		return;
+	}
+
+	switch (plogi_rsp->command) {
+	case FC_LS_ACC:
+		if (lport->fabric.timer_pending) {
+			pr_debug("lport 0x%pK Canceling fabric disc timer", lport);
+			del_timer_sync(&(lport->fabric.retry_timer));
+		}
+		lport->fabric.timer_pending = 0;
+		lport->fabric.retry_counter = 0;
+		fdls_send_rpn_id(lport);
+		lport->fabric.state = FDLS_STATE_RPN_ID;
+		break;
+
+	case FC_LS_REJ:
+		if (((els_rjt->reason_code == FC_ELS_RJT_LOGICAL_BUSY) ||
+			(els_rjt->reason_code == FC_ELS_RJT_BUSY)) &&
+			(lport->fabric.retry_counter < lport->max_plogi_retries)) {
+			pr_debug("lport 0x%pK Fabric plogi returned FC_LS_REJ BUSY retry from timer routine..\n", lport);
+
+			/*Retry Fabric Plogi again from the timer routine.*/
+			lport->fabric.flags |= FNIC2_FDLS_RETRY_FRAME;
+			return;
+		} else {
+			pr_debug("lport 0x%pK Fabric Plogi returned FC_LS_REJ...halting discovery.\n", lport);
+			if (lport->fabric.timer_pending) {
+				pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+				del_timer_sync(&(lport->fabric.retry_timer));
+			}
+
+			lport->fabric.timer_pending = 0;
+			lport->fabric.retry_counter = 0;
+			return;
+		}
+		break;
+
+	default:
+		pr_debug("plogi resp Not Accepted: %x", plogi_rsp->command);
+		/* TBD Handle it */
+		break;
+	}
+}
+
+void fdls_send_logout(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_logo_req logo;
+	uint8_t s_id[3];
+
+	memcpy(&logo, &fnic2_logo_req, sizeof(struct fc_logo_req));
+
+	hton24(s_id, lport->fcid);
+
+	memcpy(logo.fchdr.s_id, s_id, 3);
+	memcpy(logo.fchdr.d_id, fchdr->s_id, 3);
+	logo.fchdr.ox_id = FNIC2_LOGO_REQ_OXID;
+
+	memcpy(&logo.fcid, s_id, 3);
+	logo.wwpn = lport->wwpn;
+
+	fnic2_send_fcoe_frame(lport, &logo, sizeof(struct fc_logo_req));
+}
+
+/*
+ * fdls_construct_logo_req - build a logo request for session timeout
+ *
+ * @lport - the fnic2 local fc port
+ * @fchdr - the fc_hdr from the machine we want to logo with
+ * @sess - the session that will hold the logo request
+ *
+ * This function is used primarily in the case of a session timeout
+ * where we don't have an explicit lport or fchdr, so we need to
+ * construct one at the time that we initiate a session timer.
+ * The logo will then be used in the event of a session
+ * timeout and be freed from there.
+ */
+void fdls_construct_logo_req(struct fnic2_lport *lport,
+			     struct fc_hdr *fchdr,
+			     struct fnic2_sess *sess)
+{
+	struct fc_logo_req logo;
+	uint8_t s_id[3];
+
+	memcpy(&logo, &fnic2_logo_req, sizeof(struct fc_logo_req));
+
+	hton24(s_id, lport->fcid);
+
+	memcpy(logo.fchdr.s_id, s_id, 3);
+        memcpy(logo.fchdr.d_id, fchdr->s_id, 3);
+        logo.fchdr.ox_id = FNIC2_LOGO_REQ_OXID;
+
+	memcpy(&logo.fcid, s_id, 3);
+	logo.wwpn = lport->wwpn;
+
+	memcpy(&sess->timer_logo_req, &logo, sizeof(struct fc_logo_req));
+
+	return;
+
+}
+
+static void fdls_send_logo_resp(struct fnic2_lport *lport, struct fc_hdr *req_fchdr)
+{
+	struct fc_els_acc logo_resp;
+	uint16_t  ox_id;
+	uint8_t fcid[3];
+
+	memcpy(&logo_resp, &fnic2_els_acc, sizeof(struct fc_els_acc));
+
+	hton24(fcid, lport->fcid);
+	memcpy(&logo_resp.fchdr.s_id, fcid, 3);
+
+	ox_id = req_fchdr->ox_id;
+	logo_resp.fchdr.ox_id = ox_id;
+
+	logo_resp.fchdr.rx_id = FNIC2_LOGO_RESP_OXID; //TBD_REVISIT
+	fnic2_send_fcoe_frame(lport, &logo_resp, sizeof(struct fc_els_acc));
+}
+
+static void fdls_start_fabric_timer(struct fnic2_lport *lport)
+{
+	uint32_t fabric_tov;
+
+	lport->fabric.retry_counter++;
+	fabric_tov = jiffies + msecs_to_jiffies(2 * lport->e_d_tov);
+	mod_timer(&lport->fabric.retry_timer, round_jiffies(fabric_tov));
+	lport->fabric.timer_pending = 1;
+}
+
+static void fdls_start_abort_timer(struct fnic2_lport *lport)
+{
+	uint32_t abort_tov;
+
+	abort_tov = jiffies + msecs_to_jiffies(2 * lport->r_a_tov);
+	mod_timer(&lport->fabric.retry_timer, round_jiffies(abort_tov));
+	lport->fabric.timer_pending = 1;
+}
+
+static void fdls_send_fabric_abts(struct fnic2_lport *lport)
+{
+
+	uint8_t fcid[3];
+	struct fc_hdr  fc_ABTS_s = {
+		.r_ctl  = 0x81, //ABTS
+		.d_id    = {0xFF, 0xFF, 0xFF},
+		.cs_ctl = 0x00,
+		.s_id = {0x00, 0x00, 0x00},
+		.type   = 0x00,
+		.f_ctl  = {FNIC2_REQ_ABTS_FCTL, 0x00, 0x00},
+		.seq_id = 0x00,
+		.df_ctl = 0x00,
+		.seq_cnt = 0x0000,
+		.rx_id  = 0xFFFF,
+		.param  = 0x00000000, // bit:0 =0 Abort a exchange
+	};
+
+	struct fc_hdr *pfc_ABTS = &fc_ABTS_s;
+
+	switch (lport->fabric.state) {
+	case FDLS_STATE_FABRIC_FLOGI:
+		fc_ABTS_s.ox_id = FNIC2_FLOGI_OXID;
+		fc_ABTS_s.d_id[2] = 0xFE;
+		lport->fabric.flags |= FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+		break;
+
+	case FDLS_STATE_FABRIC_PLOGI:
+		hton24(fcid, lport->fcid);
+		memcpy(pfc_ABTS->s_id, fcid, 3);
+		fc_ABTS_s.ox_id = FNIC2_PLOGI_FABRIC_OXID;
+		fc_ABTS_s.d_id[2] = 0xFC;
+		lport->fabric.flags |= FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+		break;
+
+	case FDLS_STATE_RPN_ID:
+		hton24(fcid, lport->fcid);
+		memcpy(pfc_ABTS->s_id, fcid, 3);
+		fc_ABTS_s.ox_id = FNIC2_RPN_REQ_OXID;
+		fc_ABTS_s.d_id[2] = 0xFC;
+		lport->fabric.flags |= FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+		break;
+	case FDLS_STATE_REGISTER_FC4_TYPES:
+		hton24(fcid, lport->fcid);
+		memcpy(pfc_ABTS->s_id, fcid, 3);
+		fc_ABTS_s.ox_id = FNIC2_RFT_REQ_OXID;
+		fc_ABTS_s.d_id[2] = 0xFC;
+		lport->fabric.flags |= FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+		break;
+	case FDLS_STATE_REGISTER_FC4_FEATURES:
+		hton24(fcid, lport->fcid);
+		memcpy(pfc_ABTS->s_id, fcid, 3);
+		fc_ABTS_s.ox_id = FNIC2_RFF_REQ_OXID;
+		fc_ABTS_s.d_id[2] = 0xFC;
+		lport->fabric.flags |= FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+		break;
+	default:
+		break;
+	}
+	pr_debug("%s %d\n", __func__, lport->fabric.state);
+
+	fnic2_send_fcoe_frame(lport, &fc_ABTS_s, sizeof(struct fc_hdr));
+	fdls_start_abort_timer(lport);
+}
+
+static void fdls_send_fabric_flogi(struct fnic2_lport *lport)
+{
+	struct fc_els flogi;
+
+	memcpy(&flogi, &fnic2_flogi_req, sizeof(struct fc_els));
+	flogi.nport_name = cpu_to_be64(lport->wwpn);
+	flogi.node_name = cpu_to_be64(lport->wwnn);
+	flogi.u.csp_flogi.b2b_rdf_size = htons(lport->mfs);
+	flogi.u.csp_flogi.r_a_tov = htonl(lport->r_a_tov);
+	flogi.u.csp_flogi.e_d_tov = htonl(lport->e_d_tov);
+
+	fnic2_send_fcoe_frame(lport, &flogi, sizeof(struct fc_els));
+	fdls_start_fabric_timer(lport);
+}
+
+static void fdls_send_fabric_plogi(struct fnic2_lport *lport)
+{
+	struct fc_els plogi;
+	struct fc_hdr *fchdr = &plogi.fchdr;
+	uint8_t fcid[3];
+
+	pr_debug("%s lport 0x%pK\n", __func__, lport);
+
+	memcpy(&plogi, &fnic2_plogi_req, sizeof(struct fc_els));
+
+	hton24(fcid, lport->fcid);
+
+	memcpy(fchdr->s_id, fcid, 3);
+	plogi.nport_name = cpu_to_be64(lport->wwpn);
+	plogi.node_name = cpu_to_be64(lport->wwnn);
+
+	fnic2_send_fcoe_frame(lport, &plogi, sizeof(struct fc_els));
+	fdls_start_fabric_timer(lport);
+}
+
+static void fdls_send_rpn_id(struct fnic2_lport *lport)
+{
+	struct fc_rpn_id rpn_id;
+	uint8_t fcid[3];
+
+	memcpy(&rpn_id, &fnic2_rpn_id_req, sizeof(struct fc_rpn_id));
+
+	hton24(fcid, lport->fcid);
+
+	memcpy(&rpn_id.fchdr.s_id, fcid, 3);
+	memcpy(rpn_id.port_id, fcid, 3);
+	rpn_id.port_name = cpu_to_be64(lport->wwpn);
+
+	fnic2_send_fcoe_frame(lport, &rpn_id, sizeof(struct fc_rpn_id));
+	fdls_start_fabric_timer(lport);
+}
+
+static void fdls_send_register_fc4_types(struct fnic2_lport *lport)
+{
+	struct fc_rft_id rft_id;
+	uint8_t fcid[3];
+
+	memcpy(&rft_id, &fnic2_rft_id_req, sizeof(struct fc_rft_id));
+
+	hton24(fcid, lport->fcid);
+
+	memcpy(&rft_id.fchdr.s_id, fcid, 3);
+	memcpy(rft_id.port_id, fcid, 3);
+	rft_id.fc4_types[2] = 1;
+	fnic2_send_fcoe_frame(lport, &rft_id, sizeof(struct fc_rft_id));
+	fdls_start_fabric_timer(lport);
+}
+
+static void fdls_send_register_fc4_features(struct fnic2_lport *lport)
+{
+	struct fc_rff_id rff_id;
+	uint8_t fcid[3];
+
+	memcpy(&rff_id, &fnic2_rff_id_req, sizeof(struct fc_rff_id));
+
+	hton24(fcid, lport->fcid);
+
+	memcpy(&rff_id.fchdr.s_id, fcid, 3);
+	memcpy(rff_id.port_id, fcid, 3);
+
+	fnic2_send_fcoe_frame(lport, &rff_id, sizeof(struct fc_rff_id));
+	fdls_start_fabric_timer(lport);
+}
+
+static void fdls_process_rpn_id_rsp(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fnic2_fdls_fabric *fdls = &lport->fabric;
+	struct fc_rpn_id *rpn_rsp = (struct fc_rpn_id *)fchdr;
+	struct fc_els_reject *els_rjt = (struct fc_els_reject *)fchdr;
+	uint16_t rsp;
+
+	rsp = rpn_rsp->fc_ct_hdr.command;
+	pr_debug("%s 0x%04x\n", __func__, (uint32_t)rsp);
+
+	switch (rsp) {
+	case FC_CT_ACC:
+		if (lport->fabric.timer_pending) {
+			pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+			del_timer_sync(&fdls->retry_timer);
+		}
+		lport->fabric.timer_pending = 0;
+		fdls->retry_counter = 0;
+		fdls_send_register_fc4_types(lport);
+		fdls->state = FDLS_STATE_REGISTER_FC4_TYPES;
+		break;
+	case FC_LS_REJ:
+		if (((els_rjt->reason_code == FC_ELS_RJT_LOGICAL_BUSY) ||
+			(els_rjt->reason_code == FC_ELS_RJT_BUSY)) &&
+			(fdls->retry_counter < FDLS_RETRY_COUNT)) {
+
+			pr_debug("lport 0x%pK Rpn_id returned FC_LS_REJ BUSY retry from timer routine..\n", lport);
+
+		/*Retry again from the timer routine.*/
+			fdls->flags |= FNIC2_FDLS_RETRY_FRAME;
+		} else {
+			pr_debug("lport 0x%pK Rpn_id returned FC_LS_REJ...halting discovery.\n", lport);
+			if (fdls->timer_pending) {
+				pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+				del_timer_sync(&fdls->retry_timer);
+			}
+			fdls->timer_pending = 0;
+			fdls->retry_counter = 0;
+		}
+		break;
+	default:
+		break;
+	}
+}
+
+static void fdls_process_rft_id_rsp(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fnic2_fdls_fabric *fdls = &lport->fabric;
+	struct fc_rft_id *rft_rsp = (struct fc_rft_id *)fchdr;
+	struct fc_els_reject *els_rjt = (struct fc_els_reject *)fchdr;
+	uint16_t rsp;
+
+	rsp = rft_rsp->fc_ct_hdr.command;
+	pr_debug("%s 0x%04x\n", __func__, (uint32_t)rsp);
+
+	switch (rsp) {
+	case FC_CT_ACC:
+		if (lport->fabric.timer_pending) {
+			pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+			del_timer_sync(&fdls->retry_timer);
+		}
+		lport->fabric.timer_pending = 0;
+		fdls->retry_counter = 0;
+		fdls->state = FDLS_STATE_REGISTER_FC4_FEATURES;
+		break;
+	case FC_LS_REJ:
+		if (((els_rjt->reason_code == FC_ELS_RJT_LOGICAL_BUSY) ||
+			(els_rjt->reason_code == FC_ELS_RJT_BUSY)) &&
+			(fdls->retry_counter < FDLS_RETRY_COUNT)) {
+
+			pr_debug("lport 0x%pK rft_id returned FC_LS_REJ BUSY retry from timer routine..\n",
+				lport);
+
+			/*Retry again from the timer routine.*/
+			fdls->flags |= FNIC2_FDLS_RETRY_FRAME;
+		} else {
+			pr_debug("lport 0x%pK rft_id returned FC_LS_REJ...halting discovery.\n", lport);
+			if (fdls->timer_pending) {
+				pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+				del_timer_sync(&fdls->retry_timer);
+			}
+			fdls->timer_pending = 0;
+			fdls->retry_counter = 0;
+		}
+		break;
+	default:
+		break;
+	}
+}
+
+static void fdls_process_rff_id_rsp(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fnic2_fdls_fabric *fdls = &lport->fabric;
+	struct fc_rff_id *rff_rsp = (struct fc_rff_id *)fchdr;
+	struct fc_els_reject *els_rjt = (struct fc_els_reject *)fchdr;
+	uint16_t rsp;
+
+	rsp = rff_rsp->fc_ct_hdr.command;
+	pr_debug("%s 0x%04x\n", __func__, (uint32_t)rsp);
+
+	switch (rsp) {
+	case FC_CT_ACC:
+		if (lport->fabric.timer_pending) {
+			pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+			del_timer_sync(&fdls->retry_timer);
+		}
+		lport->fabric.timer_pending = 0;
+		fdls->retry_counter = 0;
+		// we are done
+		fdls->state = FDLS_STATE_TGT_ONLINE;
+		break;
+	case FC_LS_REJ:
+		if (((els_rjt->reason_code == FC_ELS_RJT_LOGICAL_BUSY) ||
+			(els_rjt->reason_code == FC_ELS_RJT_BUSY)) &&
+			(fdls->retry_counter < FDLS_RETRY_COUNT)) {
+
+			pr_debug("lport 0x%pK rff_id returned FC_LS_REJ BUSY retry from timer routine..\n", lport);
+
+			/*Retry again from the timer routine.*/
+			fdls->flags |= FNIC2_FDLS_RETRY_FRAME;
+		} else {
+			pr_debug("lport 0x%pK rff_id returned FC_LS_REJ...halting discovery.\n",
+				lport);
+			if (fdls->timer_pending) {
+				pr_debug("lport 0x%pK Canceling fabric disc timer\n", lport);
+				del_timer_sync(&fdls->retry_timer);
+			}
+			fdls->timer_pending = 0;
+			fdls->retry_counter = 0;
+		}
+		break;
+	default:
+		break;
+	}
+}
+
+static void fdls_error_fabric_disc(struct fnic2_lport *lport)
+{
+	pr_debug("FDLS discovery error from %d state\n", lport->fabric.state);
+
+	/* TBD_REVISIT what to do */
+
+}
+
+void fdls_fabric_timer_callback(struct timer_list *timer)
+{
+	struct fnic2_fdls_fabric *fabric = container_of(timer, struct fnic2_fdls_fabric, retry_timer);
+	struct fnic2_lport *lport = container_of(fabric, struct fnic2_lport, fabric);
+
+	pr_debug("%s %d %d %d %d\n", __func__,
+		lport->fabric.timer_pending, lport->fabric.state,
+		lport->fabric.retry_counter, lport->max_flogi_retries);
+
+
+	/* TBD - do we need this? timeout while rx frame in the queue? */
+	if (!lport->fabric.timer_pending)
+		return;
+
+	lport->fabric.timer_pending = 0;
+
+	/*The fabric state indicates which frames have time out, and we retry*/
+	switch (lport->fabric.state) {
+	case FDLS_STATE_FABRIC_FLOGI:
+		// Flogi received a LS_RJT with busy we retry from here
+		if ((lport->fabric.flags & FNIC2_FDLS_RETRY_FRAME) &&
+		    (lport->fabric.retry_counter < lport->max_flogi_retries)) {
+			lport->fabric.flags &= ~FNIC2_FDLS_RETRY_FRAME;
+			fdls_send_fabric_flogi(lport);
+			return;
+		}
+		// Flogi has time out 2*ed_tov send abts
+		if (!(lport->fabric.flags & FNIC2_FDLS_FABRIC_ABORT_ISSUED)) {
+			fdls_send_fabric_abts(lport);
+		} else {
+			/* Flogi ABTS have timed out and we have waited
+			 * (2 * ra_tov), we can retry safely with same
+			 * exchange id
+			 */
+			if (lport->fabric.retry_counter <
+			    lport->max_flogi_retries) {
+				lport->fabric.flags &=
+				    ~FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+				fdls_send_fabric_flogi(lport);
+			} else {
+				fdls_error_fabric_disc(lport);
+			}
+		}
+		break;
+	case FDLS_STATE_FABRIC_PLOGI:
+		// Plogi received a LS_RJT with busy we retry from here
+		if ((lport->fabric.flags & FNIC2_FDLS_RETRY_FRAME) &&
+		    (lport->fabric.retry_counter < lport->max_plogi_retries)) {
+			lport->fabric.flags &= ~FNIC2_FDLS_RETRY_FRAME;
+			fdls_send_fabric_plogi(lport);
+			return;
+		}
+		// Plogi has time out 2*ed_tov send abts
+		if (!(lport->fabric.flags & FNIC2_FDLS_FABRIC_ABORT_ISSUED)) {
+			fdls_send_fabric_abts(lport);
+		} else {
+			/* plogi ABTS has timed out and we have waited
+			 * (2 * ra_tov) can retry safely with same
+			 * exchange id
+			 */
+			if (lport->fabric.retry_counter <
+			    lport->max_plogi_retries) {
+				lport->fabric.flags &=
+				    ~FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+				fdls_send_fabric_plogi(lport);
+			} else {
+				fdls_error_fabric_disc(lport);
+			}
+		}
+		break;
+	case FDLS_STATE_RPN_ID:
+		//Rpn_id received a LS_RJT with busy we retry from here
+		if ((lport->fabric.flags & FNIC2_FDLS_RETRY_FRAME) &&
+		    (lport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
+			lport->fabric.flags &= ~FNIC2_FDLS_RETRY_FRAME;
+			fdls_send_rpn_id(lport);
+			return;
+		}
+		// RPN have timed out send abts
+		if (!(lport->fabric.flags & FNIC2_FDLS_FABRIC_ABORT_ISSUED))
+			fdls_send_fabric_abts(lport);
+		else // ABTS has timed out (2*ra_tov)
+			fnic2_fdls_start_plogi(lport); //go back to fabric Plogi
+		break;
+	case FDLS_STATE_REGISTER_FC4_TYPES:
+		// Register FC4 types received a LS_RJT with busy we retry from
+		if ((lport->fabric.flags & FNIC2_FDLS_RETRY_FRAME) &&
+			(lport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
+			lport->fabric.flags &= ~FNIC2_FDLS_RETRY_FRAME;
+			fdls_send_register_fc4_types(lport);
+			return;
+		}
+		break;
+	case FDLS_STATE_REGISTER_FC4_FEATURES:
+		// Register FC4 features received a LS_RJT with busy we retry from here
+		if ((lport->fabric.flags & FNIC2_FDLS_RETRY_FRAME) &&
+			(lport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
+			lport->fabric.flags &= ~FNIC2_FDLS_RETRY_FRAME;
+			fdls_send_register_fc4_features(lport);
+			return;
+		}
+		// Register FC4 features have timed out send abts
+		if (!(lport->fabric.flags & FNIC2_FDLS_FABRIC_ABORT_ISSUED))
+			fdls_send_fabric_abts(lport);
+		else // ABTS has timed out (2*ra_tov)
+			fnic2_fdls_start_plogi(lport); //go back to fabric Plogi
+		break;
+	default:
+		break;
+	}
+}
+
+static void fnic2_fdls_start_flogi(struct fnic2_lport *lport)
+{
+	lport->fabric.retry_counter = 0;
+	fdls_send_fabric_flogi(lport);
+	lport->fabric.state = FDLS_STATE_FABRIC_FLOGI;
+	lport->fabric.flags = 0;
+}
+
+static void fnic2_fdls_start_plogi(struct fnic2_lport *lport)
+{
+	lport->fabric.retry_counter = 0;
+	fdls_send_fabric_plogi(lport);
+	lport->fabric.state = FDLS_STATE_FABRIC_PLOGI;
+	lport->fabric.flags &= ~FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+}
+
+static void fdls_process_fabric_abts_rsp(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	uint32_t s_id;
+	struct fc_abts_ba_acc *ba_acc = (struct fc_abts_ba_acc *)fchdr;
+	struct fc_abts_ba_rjt *ba_rjt;
+	uint32_t fabric_state = lport->fabric.state;
+
+	s_id = ntoh24(fchdr->s_id);
+	ba_rjt = (struct fc_abts_ba_rjt *)fchdr;
+
+	if (!((s_id == FC_DIR_SERVER) || (s_id == FC_DOMAIN_CONTR) ||
+		(s_id == FC_FABRIC_CONTROLLER))) {
+		pr_debug("fdls received abts_rsp with invalid SID %x.. dropping the frame.\n",
+			s_id);
+		return;
+	}
+
+	if (lport->fabric.timer_pending) {
+		pr_debug("lport 0x%pK Canceling fabric disc timer", lport);
+		del_timer_sync(&(lport->fabric.retry_timer));
+	}
+	lport->fabric.timer_pending = 0;
+	lport->fabric.flags &= ~FNIC2_FDLS_FABRIC_ABORT_ISSUED;
+
+	if (fchdr->r_ctl == FNIC2_BA_ACC_RCTL) {
+		pr_debug("fdls received abts_rsp BA_ACC for fabric_state %d ox_id %x\n",
+			fabric_state, ba_acc->ox_id);
+	} else if (fchdr->r_ctl == FNIC2_BA_RJT_RCTL) {
+		pr_debug("fdls received BA_RJT for fabric_state %d ox_id %x with reason code:%x reason code explanation:%x\n",
+			fabric_state, ba_rjt->fchdr.ox_id, ba_rjt->reason_code, ba_rjt->reason_explanation);
+	}
+
+	//currently error handling/retry logic is same for ABTS BA_ACC & BA_RJT
+	switch (fabric_state) {
+	case FDLS_STATE_FABRIC_FLOGI:
+		if (fchdr->ox_id == FNIC2_FLOGI_OXID) {
+			if (lport->fabric.retry_counter < lport->max_flogi_retries)
+				fdls_send_fabric_flogi(lport);
+			else
+				fdls_error_fabric_disc(lport);
+		} else {
+			pr_debug("fdls received unknown abts_rsp ox_id %x in FDLS_STATE_FABRIC_FLOGI state.. dropping the frame\n",
+				fchdr->ox_id);
+		}
+		break;
+
+	case FDLS_STATE_FABRIC_PLOGI:
+		if (fchdr->ox_id == FNIC2_PLOGI_FABRIC_OXID) {
+			if (lport->fabric.retry_counter < lport->max_plogi_retries)
+				fdls_send_fabric_plogi(lport);
+			else
+				fdls_error_fabric_disc(lport);
+		} else {
+			pr_debug("fdls received unknown abts_rsp ox_id %x in FDLS_STATE_FABRIC_PLOGI state.. dropping the frame\n",
+				fchdr->ox_id);
+		}
+		break;
+	case FDLS_STATE_RPN_ID:
+		if (ba_acc->ox_id == FNIC2_RPN_REQ_OXID) {
+			if (lport->fabric.retry_counter < FDLS_RETRY_COUNT) {
+				fdls_send_rpn_id(lport);
+			} else {
+				//go back to fabric Plogi
+				fnic2_fdls_start_plogi(lport);
+			}
+		} else {
+			pr_debug("fdls received unknown abts_rsp ox_id %x in FDLS_STATE_RPN_ID state.. dropping the frame\n",
+				fchdr->ox_id);
+		}
+		break;
+	case FDLS_STATE_REGISTER_FC4_TYPES:
+		if (ba_acc->ox_id == FNIC2_RFT_REQ_OXID) {
+			if (lport->fabric.retry_counter < FDLS_RETRY_COUNT) {
+				fdls_send_register_fc4_types(lport);
+			} else {
+				//go back to fabric Plogi
+				fnic2_fdls_start_plogi(lport);
+			}
+		} else {
+			pr_debug("fdls received unknown abts_rsp ox_id %x in FDLS_STATE_REGISTER_FC4_TYPES state.. dropping the frame\n",
+				fchdr->ox_id);
+		}
+		break;
+	case FDLS_STATE_REGISTER_FC4_FEATURES:
+		if (ba_acc->ox_id == FNIC2_RFF_REQ_OXID) {
+			if (lport->fabric.retry_counter < FDLS_RETRY_COUNT) {
+				fdls_send_register_fc4_features(lport);
+			} else {
+				//go back to fabric Plogi
+				fnic2_fdls_start_plogi(lport);
+			}
+		} else {
+			pr_debug("fdls received unknown abts_rsp ox_id %x in FDLS_STATE_REGISTER_FC4_FEATURES state.. dropping the frame\n",
+				fchdr->ox_id);
+		}
+		break;
+	default:
+		return;
+	}
+}
+
+static void fdls_process_plogi_req(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_els_reject   plogi_rej;
+	struct fc_els       plogi_acc;
+	struct fc_els       *plogi_req;
+	struct fnic2_rport   *rport;
+
+	uint16_t  rx_id;
+
+	if (lport->fcid != ntoh24(fchdr->d_id)) {
+		pr_debug("lport 0x%pK fdls received Plogi with illegal frame bits dropping..\n",
+			lport);
+		return;
+	}
+	pr_debug("%s from fcid:%x\n", __func__, ntoh24(fchdr->s_id));
+
+	if (fchdr->s_id[0] != 0xFF) {
+
+		plogi_req = (struct fc_els *) fchdr;
+		rport = fnic2_find_rport(lport, plogi_req->nport_name);
+
+		if (rport != NULL)
+			fdls_delete_rport(lport, rport);
+
+		pr_err("Allocating rport\n");
+
+		rport = fdls_create_rport(lport, ntoh24(fchdr->s_id),
+					 plogi_req->nport_name);
+
+		if (rport == NULL)
+			goto send_plogi_rej;
+
+		pr_err("New rport %pK\n", rport);
+
+		memcpy(&plogi_acc, &fnic2_plogi_resp, sizeof(struct fc_els));
+
+		memcpy(plogi_acc.fchdr.s_id, fchdr->d_id, 3);
+		memcpy(&plogi_acc.fchdr.d_id, fchdr->s_id, 3);
+
+		rx_id = htons(fdls_alloc_tgt_ox_id(FDLS_PLOGI_OXID_BASE));
+		if (rx_id == 0xFFFF) {
+			// Log and Err TBD
+
+			pr_debug("lport 0x%pK fdls_tgt_send_plogi_acc.. rx_id not available\n", lport);
+			return;
+		}
+		pr_debug("fdls_tgt_send_plogi_acc rx_id %x\n", ntohs(rx_id));
+
+		plogi_acc.fchdr.ox_id = fchdr->ox_id;
+		plogi_acc.fchdr.rx_id = rx_id;
+		plogi_acc.nport_name = cpu_to_be64(lport->wwpn);
+		plogi_acc.node_name = cpu_to_be64(lport->wwnn);
+
+		fnic2_send_fcoe_frame(lport, &plogi_acc, sizeof(struct fc_els));
+
+		// TBD should we run a timer ???
+		fdls_free_tgt_ox_id(ntohs(rx_id));
+
+	} else {
+send_plogi_rej:
+		memcpy(&plogi_rej, &fnic2_els_rjt,
+			sizeof(struct fc_els_reject));
+		plogi_rej.reason_code = 0x0B;
+		plogi_rej.reason_expl = 0x0;
+		plogi_rej.vendor_specific = 0x0;
+		memcpy(&plogi_rej.fchdr.s_id, fchdr->d_id, 3);
+		memcpy(&plogi_rej.fchdr.d_id, fchdr->s_id, 3);
+
+		rx_id = fchdr->ox_id;
+		plogi_rej.fchdr.rx_id = rx_id;
+		plogi_rej.fchdr.ox_id = fchdr->ox_id;
+
+		fnic2_send_fcoe_frame(lport, &plogi_rej,
+					sizeof(struct fc_els_reject));
+	}
+}
+
+static void fdls_send_rej(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_els_reject els_rej;
+
+	memcpy(&els_rej, &fnic2_els_rjt, sizeof(struct fc_els_reject));
+
+	memcpy(&els_rej.fchdr.s_id, fchdr->d_id, 3);
+	memcpy(&els_rej.fchdr.d_id, fchdr->s_id, 3);
+
+	els_rej.reason_code = 0x0B;
+	els_rej.fchdr.rx_id = 0xFFFF;
+	els_rej.fchdr.ox_id = fchdr->ox_id;
+
+	fnic2_send_fcoe_frame(lport, &els_rej, sizeof(struct fc_els_reject));
+}
+
+static void fdls_send_els_acc(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_els_acc els_acc;
+
+	memcpy(&els_acc, &fnic2_els_acc, sizeof(struct fc_els_acc));
+
+	memcpy(&els_acc.fchdr.s_id, fchdr->d_id, 3);
+	memcpy(&els_acc.fchdr.d_id, fchdr->s_id, 3);
+
+	els_acc.fchdr.rx_id = 0xFFFF;
+	els_acc.fchdr.ox_id = fchdr->ox_id;
+
+	fnic2_send_fcoe_frame(lport, &els_acc, sizeof(struct fc_els_acc));
+
+}
+
+void fdls_send_ba_acc(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_abts_ba_acc ba_acc;
+
+	memcpy(&ba_acc, &fnic2_ba_acc, sizeof(struct fc_abts_ba_acc));
+
+	memcpy(&ba_acc.fchdr.s_id, fchdr->d_id, 3);
+	memcpy(&ba_acc.fchdr.d_id, fchdr->s_id, 3);
+
+	ba_acc.fchdr.rx_id = fchdr->rx_id;
+	ba_acc.rx_id = ba_acc.fchdr.rx_id;
+	ba_acc.fchdr.ox_id = fchdr->ox_id;
+	ba_acc.ox_id = ba_acc.fchdr.ox_id;
+
+	fnic2_send_fcoe_frame(lport, &ba_acc, sizeof(struct fc_abts_ba_acc));
+
+}
+
+static void fdls_process_prli_req(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_els_prli  prli_acc;
+	struct fnic2_rport   *rport;
+	uint16_t  rx_id;
+
+	if (lport->fcid != ntoh24(fchdr->d_id)) {
+		pr_debug("lport 0x%pK fdls received PRLI to wrong d_id - dropping..\n", lport);
+		return;
+	}
+	pr_debug("%s from fcid:%x\n", __func__, ntoh24(fchdr->s_id));
+
+	rport = fnic2_find_rport_by_fcid(lport, ntoh24(fchdr->s_id));
+
+	pr_err("Found rport %pK\n", rport);
+
+	if (rport) {
+
+		rx_id = htons(fdls_alloc_tgt_ox_id(FDLS_PRLI_OXID_BASE));
+		if (rx_id == 0xFFFF) {
+			// Log and Err TBD
+
+			pr_debug("lport 0x%pK fdls_tgt_send_prli_acc.. rx_id not available\n", lport);
+			fdls_send_rej(lport, fchdr);
+			return;
+		}
+		if (!fnic2_session_create(lport->fnic2, rport)) {
+
+			memcpy(&prli_acc, &fnic2_prli_resp, sizeof(struct fc_els_prli));
+
+			memcpy(&prli_acc.fchdr.s_id, fchdr->d_id, 3);
+			memcpy(&prli_acc.fchdr.d_id, fchdr->s_id, 3);
+
+			pr_debug("fdls_tgt_send_prli_acc..rx_id %x\n", ntohs(rx_id));
+
+			prli_acc.fchdr.rx_id = rx_id;
+			prli_acc.fchdr.ox_id = fchdr->ox_id;
+
+			fnic2_send_fcoe_frame(lport, &prli_acc, sizeof(struct fc_els_prli));
+
+
+			// TBD should we run a timer ???
+			fdls_free_tgt_ox_id(ntohs(rx_id));
+		} else {
+			fdls_send_rej(lport, fchdr);
+		}
+	} else {
+		fdls_send_logout(lport, fchdr);
+	}
+}
+
+
+static void fdls_process_logo_req(struct fnic2_lport *lport, struct fc_hdr *fchdr)
+{
+	struct fc_logo_req *logo = (struct fc_logo_req *)fchdr;
+	uint32_t nport_id;
+	uint64_t nport_name;
+	struct fnic2_rport *rport;
+
+	nport_id = ntoh24(logo->fcid);
+	nport_name = logo->wwpn;
+
+	pr_debug("%s fcid: %x\n", __func__, nport_id);
+	rport = fnic2_find_rport_by_fcid(lport, nport_id);
+
+	if (!rport) {
+		/* We are not logged in with the nport, log and drop...*/
+		pr_debug("fdls recevied LOGO from an rport not logged in: %x\n",
+			nport_id);
+		return;
+	}
+	if (rport->fcid != nport_id) {
+		/* nport_id changed. TBD_REVISIT */
+		pr_debug("fdls recevied LOGO with invalid source port fcid: %x\n",
+			nport_id);
+		return;
+	}
+
+	fdls_delete_rport(lport, rport);
+	fdls_send_logo_resp(lport, &logo->fchdr);
+}
+
+/* Public Functions */
+
+void fnic2_fdls_disc_start(struct fnic2_lport *lport)
+{
+	if (!lport->usefip)
+		fnic2_fdls_start_flogi(lport);
+	else //review: plogi to name server
+		fnic2_fdls_start_plogi(lport);
+}
+
+/*
+ * Performs a validation for all FCOE frames and return the frame type
+ */
+static int fnic2_fdls_validate_and_get_frame_type(struct fnic2_lport *lport, void *rx_frame,
+	int len, int fchdr_offset)
+{
+	struct fc_hdr *fchdr;
+	uint8_t type;
+	uint8_t *fc_payload;
+	uint16_t ox_id;
+	uint32_t s_id;
+	uint32_t d_id;
+
+	struct fnic2_fdls_fabric *fabric = &lport->fabric;
+
+	fchdr = (struct fc_hdr *)((uint8_t *)rx_frame + fchdr_offset);
+	ox_id = fchdr->ox_id;
+	fc_payload = (uint8_t *)fchdr + sizeof(struct fc_hdr);
+	type = *fc_payload;
+
+	s_id = ntoh24(fchdr->s_id);
+	d_id = ntoh24(fchdr->d_id);
+
+	//some common validation
+	if (lport->fcid)
+		if (fabric->state > FDLS_STATE_FABRIC_FLOGI) {
+			if ((lport->fcid != d_id) ||
+				(fchdr->cs_ctl != FNIC2_FC_CS_CTL)) {
+				pr_debug("Invalid frame received with DID %x IPortfcid %x fabric state %x R_CTL %x type %x OX_ID %x  RX_ID %x CS_CTL %x Dropping\n",
+					d_id, lport->fcid, fabric->state,
+					fchdr->r_ctl, fchdr->type, fchdr->ox_id,
+					fchdr->rx_id, fchdr->cs_ctl);
+				return -1;
+			}
+		}
+
+	// ABTS response
+	if ((fchdr->r_ctl == FNIC2_BA_ACC_RCTL) ||
+		(fchdr->r_ctl == FNIC2_BA_RJT_RCTL)) {
+		if (fchdr->type != FNIC2_FC_TYPE_BLS) {
+			pr_debug("fdls recevied ABTS with some Invalid frame bits S_ID %x FCTL %x R_CTL %x type %x. Dropping the frame\n",
+				s_id, ntoh24(fchdr->f_ctl), fchdr->r_ctl, fchdr->type);
+			return -1;
+
+		}
+		return FNIC2_BLS_ABTS_RSP;
+	}
+
+	//unsolicited requests frames
+	if (fchdr->r_ctl == FNIC2_R_CTL_UNSOLICITED) {
+		switch (type) {
+		case FC_ELS_LOGO:
+			if ((fchdr->f_ctl[0] != FNIC2_F_CTL_FIRST_LAST_SEQ_INIT) ||
+			    (fchdr->type != FNIC2_FC_TYPE_ELS)) {
+				pr_debug("fdls recevied LOGO with some Invalid frame bits S_ID %x FCTL %x R_CTL %x type %x. Dropping the frame\n",
+					s_id, ntoh24(fchdr->f_ctl), fchdr->r_ctl,
+					fchdr->type);
+				return -1;
+			}
+			return FNIC2_ELS_LOGO_REQ;
+		case FC_ELS_PLOGI_REQ:
+			return FNIC2_ELS_PLOGI_REQ;
+		case FC_ELS_PRLI_REQ:
+			return FNIC2_ELS_PRLI_REQ;
+		case FC_ELS_RTV_REQ:
+			return FNIC2_ELS_RTV_REQ;
+		case FC_ELS_RRQ_REQ:
+			return FNIC2_ELS_RRQ_REQ;
+		default:
+			pr_debug("fdls_recv_frame unsupported frame: %d\n", type);
+			return -1;
+		}
+	}
+
+	// Only responses for requests we sent
+	if (fchdr->f_ctl[0] & FNIC2_F_CTL_EXCH_RESPONDER) {
+
+		if (ntohs(ox_id) == FNIC2_LOGO_REQ_OXID)
+			return FNIC2_TPORT_LOGO_RSP;
+
+		/*response from fabric*/
+		switch (ox_id) {
+		case FNIC2_FLOGI_OXID:
+		if (type == FC_LS_ACC) {
+			if ((fchdr->f_ctl[0] != FNIC2_F_CTL_LAST_END_SEQ) ||
+				(fchdr->r_ctl != FNIC2_R_CTL_SOLICITED_CTRL_REPLY) ||
+				(s_id != FC_DOMAIN_CONTR) ||
+				(fchdr->type != FNIC2_FC_TYPE_ELS)) {
+				pr_debug("fdls recevied Flogi resp with some Invalid frame bits s_id %x FCTL %x R_CTL %x type %x. Dropping the frame.\n",
+					s_id, ntoh24(fchdr->f_ctl),
+					fchdr->r_ctl, fchdr->type);
+				return -1;
+			}
+		}
+		return FNIC2_FABRIC_FLOGI_RSP;
+
+		case FNIC2_PLOGI_FABRIC_OXID:
+		if (type == FC_LS_ACC) {
+			if ((fchdr->f_ctl[0] != FNIC2_F_CTL_LAST_END_SEQ) ||
+				(fchdr->r_ctl != FNIC2_R_CTL_SOLICITED_CTRL_REPLY) ||
+				(s_id != FC_DIR_SERVER) ||
+				(fchdr->type != FNIC2_FC_TYPE_ELS)) {
+				pr_debug("fdls recevied Plogi resp with some Invalid frame bits s_id %x FCTL %x R_CTL %x type %x. Dropping the frame.\n",
+					s_id, ntoh24(fchdr->f_ctl),
+					fchdr->r_ctl, fchdr->type);
+				return -1;
+			}
+		}
+		return FNIC2_FABRIC_PLOGI_RSP;
+
+		case FNIC2_RPN_REQ_OXID:
+		if (type == FC_LS_ACC) {
+			if ((fchdr->f_ctl[0] != FNIC2_F_CTL_LAST_END_SEQ) ||
+				(fchdr->r_ctl != FNIC2_R_CTL_SCTL) ||
+				(s_id != FC_DIR_SERVER) ||
+				(fchdr->type != FNIC2_FC_TYPE_FC_GS))  {
+				pr_debug("fdls recevied rpn_id_rsp with some Invalid frame bits s_id %x FCTL %x R_CTL %x type %x. Dropping the frame.\n",
+					s_id, ntoh24(fchdr->f_ctl),
+					fchdr->r_ctl, fchdr->type);
+				return -1;
+			}
+		}
+		return FNIC2_FABRIC_RPN_RSP;
+		case FNIC2_RFT_REQ_OXID:
+		if (type == FC_LS_ACC) {
+			if ((fchdr->f_ctl[0] != FNIC2_F_CTL_LAST_END_SEQ) ||
+				(fchdr->r_ctl != FNIC2_R_CTL_SCTL) ||
+				(s_id != FC_DIR_SERVER) ||
+				(fchdr->type != FNIC2_FC_TYPE_FC_GS))  {
+				pr_debug("fdls recevied rft_id_rsp with some Invalid frame bits s_id %x FCTL %x R_CTL %x type %x. Dropping the frame.\n",
+					s_id, ntoh24(fchdr->f_ctl),
+					fchdr->r_ctl, fchdr->type);
+				return -1;
+			}
+		}
+		return FNIC2_FABRIC_RFT_RSP;
+		case FNIC2_RFF_REQ_OXID:
+		if (type == FC_LS_ACC) {
+			if ((fchdr->f_ctl[0] != FNIC2_F_CTL_LAST_END_SEQ) ||
+				(fchdr->r_ctl != FNIC2_R_CTL_SCTL) ||
+				(s_id != FC_DIR_SERVER) ||
+				(fchdr->type != FNIC2_FC_TYPE_FC_GS))  {
+				pr_debug("fdls recevied rff_id_rsp with some Invalid frame bits s_id %x FCTL %x R_CTL %x type%x. Dropping the frame.\n",
+					s_id, ntoh24(fchdr->f_ctl),
+					fchdr->r_ctl, fchdr->type);
+				return -1;
+			}
+		}
+		return FNIC2_FABRIC_RFF_RSP;
+		default:
+		/* Drop the Rx frame and log/stats it */
+		pr_debug("fdls_recv_frame Solicited response Unknown ox_id: %x\n", ox_id);
+		return -1;
+		}
+	}
+	return -1;
+}
+
+void fnic2_fdls_recv_frame(struct fnic2_lport *lport, void *rx_frame, int len,
+	int fchdr_offset)
+{
+	uint16_t ox_id;
+	struct fc_hdr *fchdr;
+	uint32_t s_id = 0;
+	uint32_t d_id = 0;
+	char *frame_data = rx_frame;
+
+	int frame_type;
+
+	fchdr = (struct fc_hdr *)((uint8_t *)(frame_data + fchdr_offset));
+
+	s_id = ntoh24(fchdr->s_id);
+	d_id = ntoh24(fchdr->d_id);
+	pr_debug("fdls_recv_frame received frame of len %x with SID %x DID %x R_CTL %x F_CTL %x OX_ID %x RX_ID %x seq_id %x seq_cnt %x type %x offset %d\n",
+		len, s_id, d_id, fchdr->r_ctl, ntoh24(fchdr->f_ctl),
+		ntohs(fchdr->ox_id), fchdr->rx_id, fchdr->seq_id, fchdr->seq_cnt,
+		fchdr->type, fchdr_offset);
+
+	frame_type = fnic2_fdls_validate_and_get_frame_type(lport, frame_data,
+	    len, fchdr_offset);
+
+	switch (frame_type) {
+
+	case FNIC2_FABRIC_FLOGI_RSP:
+		fdls_process_flogi_rsp(lport, fchdr, frame_data);
+		break;
+
+	case FNIC2_FABRIC_PLOGI_RSP:
+		fdls_process_fabric_plogi_rsp(lport, fchdr);
+		break;
+	case FNIC2_FABRIC_RPN_RSP:
+		fdls_process_rpn_id_rsp(lport, fchdr);
+		break;
+	case FNIC2_FABRIC_RFT_RSP:
+		fdls_process_rft_id_rsp(lport, fchdr);
+		break;
+	case FNIC2_FABRIC_RFF_RSP:
+		fdls_process_rff_id_rsp(lport, fchdr);
+		break;
+	case FNIC2_BLS_ABTS_RSP:
+		ox_id = fchdr->ox_id;
+		if ((lport->fabric.flags & FNIC2_FDLS_FABRIC_ABORT_ISSUED) &&
+			(ox_id >= FNIC2_FLOGI_OXID && ox_id <= FNIC2_RFF_REQ_OXID)) {
+			fdls_process_fabric_abts_rsp(lport, fchdr);
+		}
+		break;
+
+	case FNIC2_ELS_PLOGI_REQ:
+		fdls_process_plogi_req(lport, fchdr);
+		break;
+	case FNIC2_ELS_PRLI_REQ:
+		fdls_process_prli_req(lport, fchdr);
+	break;
+	case FNIC2_ELS_RTV_REQ:
+		fdls_send_rej(lport, fchdr);
+		break;
+	case FNIC2_ELS_RRQ_REQ:
+		fdls_send_els_acc(lport, fchdr);
+		break;
+	case FNIC2_ELS_LOGO_REQ:
+		fdls_process_logo_req(lport, fchdr);
+		break;
+	default:
+		// pr_debug("Received unknown FCoE frame of len: %d. dropping.\n", len);
+		break;
+	}
+}
+
+void fnic2_fdls_disc_init(struct fnic2_lport *lport)
+{
+	fdls_init_tgt_ox_id_pool();
+	lport->fabric.state = FDLS_STATE_INIT;
+}
+
+void fnic2_fdls_link_down(struct fnic2_lport *lport)
+{
+	struct fnic2_rport *rport, *next;
+
+	pr_debug("%s lport 0x%pK\n", __func__, lport);
+
+	lport->fabric.state = FDLS_STATE_LINKDOWN;
+	lport->fabric.flags = 0;
+
+	fnic2_scsi_fcpio_reset(lport);
+
+	fdls_init_tgt_ox_id_pool();
+
+	list_for_each_entry_safe(rport, next, &lport->rport_list, links)   {
+		pr_debug("removing rport: %x", rport->fcid);
+		if (rport->state != fdls_rport_state_offlining)
+			fdls_delete_rport(lport, rport);
+	}
+
+	pr_debug("%s lport 0x%pK\n", __func__, lport);
+}
+
+struct fnic2_rport *fdls_create_rport(struct fnic2_lport *lport, uint32_t fcid, uint64_t wwpn)
+{
+	struct fnic2_rport rport;
+
+	pr_debug("%s fcid:%x, wwpn: %llx\n", __func__, fcid, wwpn);
+
+	memset(&rport, 0, sizeof(struct fnic2_rport));
+
+	rport.fcid = fcid;
+	rport.wwpn = wwpn;
+
+	rport.lport = lport;
+
+	rport.state = fdls_rport_state_plogi;
+	return fnic2_fdls_add_rport(lport, &rport);
+}
+
+void fdls_delete_rport(struct fnic2_lport *lport, struct fnic2_rport *rport)
+{
+	struct fnic2_sess *sess;
+	struct se_session *se_sess;
+
+	if (rport->state == fdls_rport_state_offlining)
+		return;
+	rport->state = fdls_rport_state_offlining;
+	// remove session, cleanup LIO
+	sess = fnic2_find_session(lport->fnic2, rport->wwpn);
+	if (sess) {
+		if ((try_to_del_timer_sync(&sess->sess_timer)) < 0)
+			pr_err("Failed to delete session %pK\n", sess);
+		se_sess = sess->se_sess;
+		target_sess_cmd_list_set_waiting(se_sess);
+		target_wait_for_sess_cmds(se_sess);
+
+		transport_deregister_session_configfs(se_sess);
+		transport_deregister_session(se_sess);
+		sess->se_sess = NULL;
+		list_del(&sess->list);
+		lport->fnic2->lio.sess_count--;
+		kfree(sess);
+	}
+	fnic2_fdls_remove_rport(lport, rport);
+}
+
+void fnic2_fdls_remove_rport(struct fnic2_lport *lport, struct fnic2_rport *rport)
+{
+	list_del(&rport->links);
+	kfree(rport);
+}
+
+
+struct fnic2_rport *fnic2_fdls_add_rport(struct fnic2_lport *lport, struct fnic2_rport *rport)
+{
+	struct fnic2_rport *new_rport;
+
+	new_rport = kmalloc(sizeof(struct fnic2_rport), GFP_ATOMIC);
+	if (new_rport == NULL)
+		return NULL;
+	pr_debug("created rport rport: %pK\n", new_rport);
+	memcpy(new_rport, rport, sizeof(struct fnic2_rport));
+
+	list_add_tail(&new_rport->links, &lport->rport_list);
+
+	return new_rport;
+}
+
+struct fnic2_rport *fnic2_find_rport(struct fnic2_lport *lport, uint64_t wwpn)
+{
+	struct fnic2_rport *rport;
+	struct list_head *init;
+
+	list_for_each(init, &lport->rport_list) {
+
+	rport =  list_entry(init, struct fnic2_rport, links);
+	if (rport->wwpn == wwpn)
+		return rport;
+	}
+	return NULL;
+}
+
+struct fnic2_rport *fnic2_find_rport_by_fcid(struct fnic2_lport *lport, uint32_t fcid)
+{
+	struct fnic2_rport *rport;
+	struct list_head *init;
+
+	list_for_each(init, &lport->rport_list) {
+
+		rport =  list_entry(init, struct fnic2_rport, links);
+		if (rport->fcid == fcid)
+			return rport;
+	}
+	return NULL;
+}
drivers/staging/fnic2/src/fdls_fc.h new file +403 -0

403 lines not on this page · raw message

drivers/staging/fnic2/src/fdls_if.c new file +1254 -0

1,058 lines not on this page · raw message

drivers/staging/fnic2/src/fnic2_fdls.h new file +232 -0

232 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.8.3.1

Part of the diff is not shown here. View the raw message.

#13 lore raw

PATCH 5/10 staging: fnic2 add LIO interface

In reply to Oliver Smith-Denny

These files contains structures and callback functions for communicating with LIO.

---
 drivers/staging/fnic2/src/fnic2_lio.c | 815 ++++++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/fnic2_lio.h | 113 +++++
 2 files changed, 928 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fnic2_lio.c
 create mode 100644 drivers/staging/fnic2/src/fnic2_lio.h
drivers/staging/fnic2/src/fnic2_lio.c new file +815 -0
new file mode 100644
index 0000000..64ca5d2
@@ -0,0 +1,815 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2017 Cisco Systems, Inc.  All rights reserved.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/version.h>
+#include <generated/utsrelease.h>
+#include <linux/utsname.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/kthread.h>
+#include <linux/types.h>
+#include <linux/string.h>
+#include <linux/list.h>
+#include <linux/configfs.h>
+#include <linux/ctype.h>
+#include <asm/unaligned.h>
+#include <scsi/scsi.h>
+#include <scsi/scsi_common.h>
+#include <scsi/scsi_proto.h>
+#include <scsi/fc/fc_fcp.h>
+#include "fnic2.h"
+#include "fnic2_lio.h"
+
+extern struct fnic2 *find_fnic2_wwpn(uint64_t wwpn);
+extern int fnic2_send_to_fw(struct fnic2_cmd *tcmd, int req_type);
+extern void fnic2_free_fw_res(struct fnic2_cmd *tcmd);
+extern void fnic2_free_tcmd(struct fnic2_cmd *tcmd);
+
+#define FT_VERSION "0.1"
+
+static const struct target_core_fabric_ops fnic2_ops;
+
+/*
+ * Parse WWN.
+ * If strict, we require lower-case hex and colon separators to be sure
+ * the name is the same as what would be generated by ft_format_wwn()
+ * so the name and wwn are mapped one-to-one.
+ */
+static ssize_t ft_parse_wwn(const char *name, uint64_t *wwn, int strict)
+{
+	const char *cp;
+	char c;
+	uint32_t byte = 0;
+	uint32_t pos = 0;
+	uint32_t err;
+	int val;
+
+	*wwn = 0;
+	for (cp = name; cp < &name[FNIC2_NAMELEN - 1]; cp++) {
+		c = *cp;
+		if (c == '\n' && cp[1] == '\0')
+			continue;
+		if (strict && pos++ == 2 && byte++ < 7) {
+			pos = 0;
+			if (c == ':')
+				continue;
+			err = 1;
+			goto fail;
+		}
+		if (c == '\0') {
+			err = 2;
+			if (strict && byte != 8)
+				goto fail;
+			return cp - name;
+		}
+		err = 3;
+		val = hex_to_bin(c);
+		if (val < 0 || (strict && isupper(c)))
+			goto fail;
+		*wwn = (*wwn << 4) | val;
+	}
+	err = 4;
+fail:
+	pr_debug("err %u len %zu pos %u byte %u\n",
+		err, cp - name, pos, byte);
+	return -1;
+}
+
+static int fnic2_parse_wwpn(const char *wwn, uint64_t *wwpn)
+{
+	int i;
+	int shift = 60;
+	unsigned char c;
+	unsigned long long uint64_t = 0, d64;
+
+	for (i = 0; i < 23; i++) {
+		c = wwn[i];
+		if (c == ':')
+			continue;
+
+		if (c >= '0' && c <= '9') {
+			d64 = c - '0';
+		} else if (c >= 'A' && c <= 'F') {
+			d64 = 0xA + (c - 'A');
+		} else if (c >= 'a' && c <= 'f') {
+			d64 = 0xA + (c - 'a');
+		} else {
+			pr_err("Invalid WWPN %c\n", c);
+			return -1;
+		}
+
+		uint64_t = (d64 << shift) | uint64_t;
+		shift = shift - 4;
+	}
+	*wwpn = uint64_t;
+	return 0;
+
+}
+
+static ssize_t ft_format_wwn(char *buf, size_t len, uint64_t wwn)
+{
+	uint8_t b[8];
+
+	put_unaligned_be64(wwn, b);
+	return snprintf(buf, len,
+		 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",
+		 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]);
+}
+
+static ssize_t ft_wwn_show(void *arg, char *buf)
+{
+	uint64_t *wwn = arg;
+	ssize_t len;
+
+	len = ft_format_wwn(buf, PAGE_SIZE - 2, *wwn);
+	buf[len++] = '\n';
+	return len;
+}
+
+static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len)
+{
+	ssize_t ret;
+	uint64_t wwn;
+
+	ret = ft_parse_wwn(buf, &wwn, 0);
+	if (ret > 0)
+		*(uint64_t *)arg = wwn;
+	return ret;
+}
+
+/*
+ * ACL auth ops.
+ */
+
+static ssize_t ft_nacl_port_name_show(struct config_item *item, char *page)
+{
+	struct se_node_acl *se_nacl = acl_to_nacl(item);
+	struct ft_node_acl *acl = container_of(se_nacl,
+			struct ft_node_acl, se_node_acl);
+
+	return ft_wwn_show(&acl->node_auth.port_name, page);
+}
+
+static ssize_t ft_nacl_port_name_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct se_node_acl *se_nacl = acl_to_nacl(item);
+	struct ft_node_acl *acl = container_of(se_nacl,
+			struct ft_node_acl, se_node_acl);
+
+	return ft_wwn_store(&acl->node_auth.port_name, page, count);
+}
+
+static ssize_t ft_nacl_node_name_show(struct config_item *item,
+		char *page)
+{
+	struct se_node_acl *se_nacl = acl_to_nacl(item);
+	struct ft_node_acl *acl = container_of(se_nacl,
+			struct ft_node_acl, se_node_acl);
+
+	return ft_wwn_show(&acl->node_auth.node_name, page);
+}
+
+static ssize_t ft_nacl_node_name_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct se_node_acl *se_nacl = acl_to_nacl(item);
+	struct ft_node_acl *acl = container_of(se_nacl,
+			struct ft_node_acl, se_node_acl);
+
+	return ft_wwn_store(&acl->node_auth.node_name, page, count);
+}
+
+CONFIGFS_ATTR(ft_nacl_, node_name);
+CONFIGFS_ATTR(ft_nacl_, port_name);
+
+static ssize_t ft_nacl_tag_show(struct config_item *item,
+		char *page)
+{
+	return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
+}
+
+static ssize_t ft_nacl_tag_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct se_node_acl *se_nacl = acl_to_nacl(item);
+	int ret;
+
+	ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
+
+	if (ret < 0)
+		return ret;
+	return count;
+}
+
+CONFIGFS_ATTR(ft_nacl_, tag);
+
+static struct configfs_attribute *ft_nacl_base_attrs[] = {
+	&ft_nacl_attr_port_name,
+	&ft_nacl_attr_node_name,
+	&ft_nacl_attr_tag,
+	NULL,
+};
+
+/*
+ * ACL ops.
+ */
+
+static int ft_init_nodeacl(struct se_node_acl *nacl, const char *name)
+{
+	struct ft_node_acl *acl =
+		container_of(nacl, struct ft_node_acl, se_node_acl);
+	uint64_t wwpn;
+
+	pr_err("Creating ACL for %s\n", name);
+
+	if (ft_parse_wwn(name, &wwpn, 1) < 0)
+		return -EINVAL;
+	pr_err("Created ACL for %s %llx\n", name, wwpn);
+
+	acl->node_auth.port_name = wwpn;
+	return 0;
+}
+
+static ssize_t ft_wwn_version_show(struct config_item *item, char *page)
+{
+        return sprintf(page, "CISCO SYSTEMS, INC. " FT_VERSION " on %s/%s on "
+                ""UTS_RELEASE"\n",  utsname()->sysname, utsname()->machine);
+}
+
+CONFIGFS_ATTR_RO(ft_wwn_, version);
+
+static struct configfs_attribute *ft_wwn_attrs[] = {
+	&ft_wwn_attr_version,
+	NULL,
+};
+
+/* fabric */
+static int fnic2_check_true(struct se_portal_group *se_tpg)
+{
+	return 1;
+}
+
+static int fnic2_check_false(struct se_portal_group *se_tpg)
+{
+	return 0;
+}
+
+static char *fnic2_get_fabric_name(void)
+{
+	return "fnic2";
+}
+
+static char *fnic2_get_fabric_wwn(struct se_portal_group *se_tpg)
+{
+	struct fnic2_tpg *tpg = container_of(se_tpg,
+				struct fnic2_tpg, se_tpg);
+	struct fnic2_lio_lport *lport = tpg->lport;
+
+
+	return &lport->lport_name[0];
+}
+
+static uint16_t fnic2_get_tag(struct se_portal_group *se_tpg)
+{
+	struct fnic2_tpg *tpg = container_of(se_tpg,
+				struct fnic2_tpg, se_tpg);
+	return tpg->lport_tpgt;
+}
+
+static uint32_t fnic2_tpg_get_inst_index(struct se_portal_group *se_tpg)
+{
+	return 1;
+}
+
+static int fnic2_check_stop_free(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *tcmd = container_of(se_cmd,
+                struct fnic2_cmd, se_cmd);
+	pr_debug("check stop free for tag %x\n", tcmd->cmd_tag);
+	return target_put_sess_cmd(se_cmd);
+}
+
+static void fnic2_release_cmd(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *tcmd = container_of(se_cmd,
+		struct fnic2_cmd, se_cmd);
+
+	pr_debug("DEBUG %s: %x, is_write: %d, rx_id: %x\n",
+		__func__, tcmd->cmd_tag, tcmd->flags & FNIC2_TCMD_WRITECMD, tcmd->rx_id);
+
+	if (tcmd->se_cmd.t_data_sg)
+		pr_err("t_data_sg not NULL\n");
+	fnic2_free_tcmd(tcmd);
+
+	return;
+}
+
+static uint32_t fnic2_sess_get_index(struct se_session *se_sess)
+{
+	return 0;
+}
+
+static int fnic2_write_pending(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *tcmd = container_of(se_cmd,
+		struct fnic2_cmd, se_cmd);
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tcmd->lock, flags);
+
+	if (tcmd->flags & FNIC2_TCMD_ABORTED) {
+		spin_unlock_irqrestore(&tcmd->lock, flags);
+		return 0;
+	}
+
+	spin_unlock_irqrestore(&tcmd->lock, flags);
+
+	pr_debug("DEBUG write_pending tag: %x\n", tcmd->cmd_tag);
+
+	/* Check the se->cmd status and process accordingly */
+	if (se_cmd->scsi_status != SAM_STAT_GOOD) {
+		pr_err("ERROR fn: %s ln: %d, sts: %d\n",
+			__func__, __LINE__, se_cmd->scsi_status);
+		/* TBD send_resp or wait for q_sts? */
+		return 0;
+	}
+
+	tcmd->data_len_xfer = se_cmd->data_length;
+	if (tcmd->data_len_req != tcmd->data_len_xfer) {
+		/* TBD */
+		pr_err("ERROR fn: %s ln: %d\n", __func__, __LINE__);
+	}
+
+	tcmd->sgcnt = se_cmd->t_data_nents;
+	tcmd->sgl = se_cmd->t_data_sg;
+	tcmd->dma_direction = PCI_DMA_FROMDEVICE;
+
+	ret = fnic2_send_to_fw(tcmd, FCPIO_TCMD_RECV_DATA);
+
+	return ret;
+}
+
+static int fnic2_queue_status(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *tcmd = container_of(se_cmd,
+		struct fnic2_cmd, se_cmd);
+	unsigned long flags;
+
+	pr_debug("DEBUG queue_status tag: %x\n", tcmd->cmd_tag);
+
+	spin_lock_irqsave(&tcmd->lock, flags);
+
+	if (tcmd->flags & FNIC2_TCMD_ABORTED) {
+		spin_unlock_irqrestore(&tcmd->lock, flags);
+		return 0;
+	}
+
+	spin_unlock_irqrestore(&tcmd->lock, flags);
+
+	if (se_cmd->scsi_status != SAM_STAT_GOOD) {
+		pr_err("WARNING: Cmd %x SCSI Status Error: %x, cmd_tag: %x\n",
+			tcmd->ox_id, se_cmd->scsi_status, tcmd->cmd_tag);
+	}
+
+	fnic2_send_fcp_resp(tcmd);
+
+	/* Delete I/O timer if it is active */
+	if ((try_to_del_timer_sync(&tcmd->io_timer)) < 0)
+                pr_err("Could not delete timer on tcmd tag %x\n", tcmd->cmd_tag);
+
+	if (tcmd->flags & FNIC2_TCMD_WRITECMD)
+		fnic2_free_fw_res(tcmd);
+	else
+		transport_generic_free_cmd(se_cmd, 0);
+
+	return 0;
+}
+
+/*
+ * fnic2_queue_tm_rsp
+ * LIO has completed a task management command
+ * send a "bubble" command to fw that will be processed after
+ * all the aborted commands, then send the task mgmt response to initiator
+ */
+static void fnic2_queue_tm_rsp(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *tcmd = container_of(se_cmd,
+				 struct fnic2_cmd, se_cmd);
+	struct fnic2 *fnic2 = tcmd->fnic2;
+	unsigned long flags;
+	struct fcpio_host_req *host_req;
+        struct fcpio_host_req *desc;
+        struct vnic_wq_copy *wq;
+
+        pr_err("TMR RESPONSE se_cmd %pK tcmd %pK\n", se_cmd, tcmd);
+
+	spin_lock_irqsave(&tcmd->lock, flags);
+
+	if (tcmd->flags & (FNIC2_TCMD_IS_ABTS | FNIC2_TCMD_ABORTED)) {
+		spin_unlock_irqrestore(&tcmd->lock, flags);
+		return;
+	}
+	spin_unlock_irqrestore(&tcmd->lock, flags);
+
+        /* Fill the structure to send it to fw */
+        host_req = kzalloc(sizeof(struct fcpio_host_req), GFP_KERNEL);
+        WARN_ON(host_req == NULL);
+        host_req->hdr.type = FCPIO_TCMD_TASK_MGMT;
+        host_req->hdr.fcpio_tag = tcmd->cmd_tag;
+
+        spin_lock_irqsave(&fnic2->wq_copy_lock[0], flags);
+        /* Use the Copy WQ to send it to FW */
+        wq = &fnic2->wq_copy[0];
+
+        if (vnic_wq_copy_desc_avail(wq) <= fnic2->wq_copy_desc_low[0])
+                free_wq_copy_descs(fnic2, wq);
+
+        if (unlikely(!vnic_wq_copy_desc_avail(wq))) {
+                pr_err("DEBUG ERROR no wq desc for free_cmd\n");
+                kfree(host_req);
+                spin_unlock_irqrestore(&fnic2->wq_copy_lock[0], flags);
+                return;
+        }
+
+        desc = vnic_wq_copy_next_desc(wq);
+        memcpy(desc, host_req, sizeof(struct fcpio_host_req));
+
+        vnic_wq_copy_post(wq);
+        spin_unlock_irqrestore(&fnic2->wq_copy_lock[0], flags);
+
+        kfree(host_req);
+}
+
+void fnic2_send_abort_to_lio(struct fnic2_cmd *abort_tcmd)
+{
+	int tmr_flags, ret;
+	struct fnic2_cmd *killed_tcmd = abort_tcmd->killed_tcmd;
+	struct fc_hdr *fchdr = (struct fc_hdr *)killed_tcmd->rx_frame;
+	struct fnic2 *fnic2 = killed_tcmd->fnic2;
+	struct fnic2_sess *sess;
+	uint32_t s_id;
+
+	s_id = ntoh24(fchdr->s_id);
+	sess = fnic2_find_sess_s_id(fnic2, s_id);
+
+	if (!sess) {
+	    // TBD cleanup
+	    return;
+	}
+
+	// TBD sanity check on killed_tcmd ???
+
+	tmr_flags = TARGET_SCF_ACK_KREF | TARGET_SCF_LOOKUP_LUN_FROM_TAG;
+
+	ret= target_submit_tmr(&abort_tcmd->se_cmd, sess->se_sess, NULL,
+			0,
+			killed_tcmd,
+			TMR_ABORT_TASK, GFP_ATOMIC,
+			killed_tcmd->cmd_tag,
+			tmr_flags);
+
+	if (ret) {
+		pr_err("%s submitting tmr failed\n", __func__);
+		/* LIO failed the ABTS req, but I/O will be
+		* handled by Lun Reset or I/O timer reaper
+		*/
+	}
+}
+
+/*
+ * fnic2_complete_tm_rsp
+ * fw has aborted all exchanges
+ * send the final task management function response to initiator
+ */
+void fnic2_complete_tm_rsp(struct fnic2_cmd *tcmd)
+{
+	struct se_cmd *se_cmd = &tcmd->se_cmd;
+        struct se_tmr_req *tmr = se_cmd->se_tmr_req;
+        enum fcp_resp_rsp_codes code;
+	unsigned long flags;
+
+        pr_err("TMR RESPONSE fw completed - se_cmd %pK tcmd %pK tmr %pK\n",
+                se_cmd, tcmd, tmr);
+
+	spin_lock_irqsave(&tcmd->lock, flags);
+
+	if (tcmd->flags & (FNIC2_TCMD_IS_ABTS | FNIC2_TCMD_ABORTED)) {
+		spin_unlock_irqrestore(&tcmd->lock, flags);
+		return;
+	}
+	spin_unlock_irqrestore(&tcmd->lock, flags);
+
+        switch (tmr->response) {
+        case TMR_FUNCTION_COMPLETE:
+                code = FCP_TMF_CMPL;
+                break;
+        case TMR_LUN_DOES_NOT_EXIST:
+                code = FCP_TMF_INVALID_LUN;
+                break;
+        case TMR_FUNCTION_REJECTED:
+                code = FCP_TMF_REJECTED;
+                break;
+        case TMR_TASK_DOES_NOT_EXIST:
+        case TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED:
+        default:
+                code = FCP_TMF_FAILED;
+                break;
+        }
+        pr_err("TMR RESPONSE fn %d resp %d fcp code %d\n",
+                  tmr->function, tmr->response, code);
+
+        fnic2_send_tmr_resp(tcmd, SAM_STAT_GOOD, code);
+
+        transport_generic_free_cmd(se_cmd, 0);
+}
+
+/*
+ * fnic2_aborted_task
+ * callback from LIO for each aborted real task (by ABTS or LUN RESET)
+ */
+static void fnic2_aborted_task(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *killed_tcmd = container_of(se_cmd, struct fnic2_cmd, se_cmd);
+	struct fnic2_cmd *abort_tcmd;
+
+	pr_err("tcmd %pK aborted by LIO\n", killed_tcmd);
+
+	if (killed_tcmd->flags & FNIC2_TCMD_ABORTED) {
+		/* ABTS path - already aborted with fw */
+		abort_tcmd = killed_tcmd->abort_tcmd;
+		transport_generic_free_cmd(&abort_tcmd->se_cmd, 0);
+	} else {
+		/* LUN RESET path - must abort with fw */
+		fnic2_send_abort_to_fw(killed_tcmd);
+	}
+}
+
+/*
+ * fnic2_fw_abort_done
+ * callback from fw for each aborted task (ABTS or LUN RESET)
+ */
+void fnic2_fw_abort_done(struct fnic2_cmd *tcmd)
+{
+	struct fnic2 *fnic2;
+	struct fc_hdr *fchdr;
+	struct fnic2_cmd *killed_tcmd;
+
+	pr_err("tcmd %pK aborted by fw\n", tcmd);
+
+	if (tcmd->flags & FNIC2_TCMD_IS_ABTS) {
+                /* ABTS path */
+		/* send ba_acc and abort with LIO */
+
+		killed_tcmd = tcmd->killed_tcmd;
+		// TBD killed_cmd sanity check
+
+		fnic2 = killed_tcmd->fnic2;
+		fchdr = (struct fc_hdr *)killed_tcmd->rx_frame;
+
+		fdls_send_ba_acc(&fnic2->lport, fchdr);
+		fnic2_send_abort_to_lio(tcmd);
+        }
+}
+
+/* configfs */
+
+static struct se_portal_group *fnic2_make_tpg(struct se_wwn *wwn,
+					      struct config_group *group,
+					      const char *name)
+{
+	struct fnic2_lio_lport *lport = container_of(wwn,
+			struct fnic2_lio_lport, lport_wwn);
+
+	struct fnic2_tpg *tpg;
+	unsigned long tpgt;
+	struct fnic2 *fnic2 = lport->fnic2;
+	int ret;
+
+	pr_debug("name: %s\n", name);
+
+	if (strstr(name, "tpgt_") != name)
+		return ERR_PTR(-EINVAL);
+	if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)
+		return ERR_PTR(-EINVAL);
+
+	tpg = kzalloc(sizeof(struct fnic2_tpg), GFP_KERNEL);
+	if (!tpg) {
+		pr_err("Unable to allocate struct fnic2_tpg\n");
+		return ERR_PTR(-ENOMEM);
+	}
+	tpg->lport = lport;
+	tpg->lport_tpgt = tpgt;
+
+	ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);
+	if (ret < 0) {
+		pr_err("Error returned by core_tpg_register: %d\n",
+			ret);
+		kfree(tpg);
+		return ERR_PTR(-EFAULT);
+	}
+
+	fnic2 = lport->fnic2;
+	fnic2->lio.tpg = tpg;
+
+	return &tpg->se_tpg;
+}
+
+static void fnic2_drop_tpg(struct se_portal_group *se_tpg)
+{
+	struct fnic2_tpg *tpg = container_of(se_tpg,
+				struct fnic2_tpg, se_tpg);
+
+	core_tpg_deregister(se_tpg);
+	kfree(tpg);
+}
+
+static struct se_wwn *fnic2_make_lport(struct target_fabric_configfs *tf,
+				       struct config_group *group,
+				       const char *name)
+{
+	struct fnic2 *fnic2;
+	struct fnic2_lio_lport *lport;
+	uint64_t wwpn;
+
+	if (!name) {
+		pr_err("%s Null lport name received\n", __func__);
+		return NULL;
+
+	}
+	pr_debug("%s: lport name %s\n", __func__, name);
+
+	if (fnic2_parse_wwpn(name, &wwpn) < 0)
+		return ERR_PTR(-EINVAL);
+
+	pr_debug("%s: wwpn %llx\n", __func__, wwpn);
+
+	fnic2 = find_fnic2_wwpn(wwpn);
+	if (!fnic2) {
+		pr_err("Could not find fnic2 with wwpn: %llx\n",
+			wwpn);
+		return ERR_PTR(-EINVAL);
+	}
+	if (fnic2->lio.lport) {
+		pr_err("%s: lport already created %llx\n",
+			__func__, wwpn);
+		return ERR_PTR(-EEXIST);
+	}
+	lport = kzalloc(sizeof(struct fnic2_lio_lport), GFP_KERNEL);
+	if (!lport) {
+		pr_err("Unable to allocate struct fnic2_lio_lport\n");
+		WARN_ON(1);
+		return ERR_PTR(-ENOMEM);
+	}
+	lport->lport_wwpn = wwpn;
+
+	fnic2->lio.lport = lport;
+	lport->fnic2 = fnic2;
+
+	return (&lport->lport_wwn);
+}
+
+int fnic2_write_pending_status(struct se_cmd *se_cmd)
+{
+	return 0;
+}
+
+void fnic2_set_default_node_attrs(struct se_node_acl *nacl)
+{
+	return;
+}
+
+int fnic2_get_cmd_state(struct se_cmd *se_cmd)
+{
+	return 0;
+}
+
+int fnic2_queue_data_in(struct se_cmd *se_cmd)
+{
+	struct fnic2_cmd *tcmd = container_of(se_cmd,
+		struct fnic2_cmd, se_cmd);
+	int ret;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tcmd->lock, flags);
+
+	if (tcmd->flags & (FNIC2_TCMD_IS_ABTS | FNIC2_TCMD_ABORTED)) {
+		spin_unlock_irqrestore(&tcmd->lock, flags);
+		return 0;
+	}
+
+	spin_unlock_irqrestore(&tcmd->lock, flags);
+
+	pr_debug("DEBUG data_in tag: %x, sts: %x\n",
+		tcmd->cmd_tag, se_cmd->scsi_status);
+
+	/* Check the se->cmd status and process accordingly */
+	if (se_cmd->scsi_status != SAM_STAT_GOOD) {
+		/* TBD would LIO call data_in in case of error status? */
+		pr_err("Scsi status: %x, cmdtag: %d\n",
+			se_cmd->scsi_status, tcmd->cmd_tag);
+		return 0;
+	}
+
+	tcmd->data_len_xfer = se_cmd->data_length;
+
+	if (tcmd->data_len_xfer == 0) {
+		pr_debug("DEBUG Zero len Data tag: %x\n", tcmd->cmd_tag);
+		tcmd->rx_id = 0xffff;
+		fnic2_send_fcp_resp(tcmd);
+		transport_generic_free_cmd(&tcmd->se_cmd, 0);
+		return 0;
+	}
+
+	if (tcmd->data_len_req != tcmd->data_len_xfer) {
+		pr_debug("%s data_len_req: %d, data_len_xfer: %d\n",
+			__func__, tcmd->data_len_req, tcmd->data_len_xfer);
+	}
+	tcmd->sgcnt = se_cmd->t_data_nents;
+	tcmd->sgl = se_cmd->t_data_sg;
+	tcmd->dma_direction = PCI_DMA_TODEVICE;
+
+	ret = fnic2_send_to_fw(tcmd, FCPIO_TCMD_SEND_DATA);
+	return ret;
+}
+
+static void fnic2_drop_lport(struct se_wwn *wwn)
+{
+	struct fnic2_lio_lport *lport = container_of(wwn,
+				struct fnic2_lio_lport, lport_wwn);
+	struct fnic2 *fnic2;
+
+	/* Free from the corresponding fnic2 */
+	fnic2 = find_fnic2_wwpn(lport->lport_wwpn);
+	if (!fnic2) {
+		pr_err("%s: Unable to find fnic2 for the wwpn %llx\n",
+			__func__, lport->lport_wwpn);
+		return;
+	}
+	if (!fnic2->lio.lport) {
+		pr_err("%s lport does not exist %llx\n",
+			__func__, lport->lport_wwpn);
+		return;
+	}
+
+	fnic2->lio.lport = NULL;
+	kfree(lport);
+}
+
+
+/* Registration */
+
+static const struct target_core_fabric_ops fnic2_ops = {
+	.module                         	= THIS_MODULE,
+	.name                           	= "fnic2",
+	.node_acl_size				= sizeof(struct ft_node_acl),
+	.get_fabric_name                	= fnic2_get_fabric_name,
+	.tpg_get_wwn                    	= fnic2_get_fabric_wwn,
+	.tpg_get_tag                    	= fnic2_get_tag,
+	.tpg_check_demo_mode            	= fnic2_check_false,
+	.tpg_check_demo_mode_cache      	= fnic2_check_true,
+	.tpg_check_demo_mode_write_protect	= fnic2_check_false,
+	.tpg_check_prod_mode_write_protect	= fnic2_check_false,
+	.tpg_get_inst_index             	= fnic2_tpg_get_inst_index,
+	.check_stop_free			= fnic2_check_stop_free,
+	.release_cmd                    	= fnic2_release_cmd,
+	.sess_get_index                 	= fnic2_sess_get_index,
+	.sess_get_initiator_sid         	= NULL,
+	.write_pending                  	= fnic2_write_pending,
+	.write_pending_status           	= fnic2_write_pending_status,
+	.set_default_node_attributes    	= fnic2_set_default_node_attrs,
+	.get_cmd_state                  	= fnic2_get_cmd_state,
+	.queue_data_in                  	= fnic2_queue_data_in,
+	.queue_status                  		= fnic2_queue_status,
+	.queue_tm_rsp                   	= fnic2_queue_tm_rsp,
+	.aborted_task                   	= fnic2_aborted_task,
+	/*
+	 * Setup function pointers for generic logic in target_core_fabric_configfs.c
+	 */
+	.fabric_make_wwn                	= fnic2_make_lport,
+	.fabric_drop_wwn                	= fnic2_drop_lport,
+	.fabric_make_tpg                	= fnic2_make_tpg,
+	.fabric_drop_tpg                	= fnic2_drop_tpg,
+	.fabric_init_nodeacl			= &ft_init_nodeacl,
+
+	.tfc_wwn_attrs                  	= ft_wwn_attrs,
+	.tfc_tpg_nacl_base_attrs        	= ft_nacl_base_attrs,
+};
+
+int fnic2_lio_init(void)
+{
+	int ret = 0;
+
+	ret = target_register_template(&fnic2_ops);
+	return ret;
+};
+
+void fnic2_lio_cleanup(void)
+{
+	target_unregister_template(&fnic2_ops);
+};
drivers/staging/fnic2/src/fnic2_lio.h new file +113 -0

113 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 6/10 staging: fnic2 add main frame processing

In reply to Oliver Smith-Denny

These files contain logic for handling Fibre Channel frames and communication with firmware and LIO.

---
 drivers/staging/fnic2/src/fcpio.h     |  347 ++++++++++
 drivers/staging/fnic2/src/fnic2_cmd.c | 1164 +++++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/fnic2_io.h  |   32 +
 3 files changed, 1543 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fcpio.h
 create mode 100644 drivers/staging/fnic2/src/fnic2_cmd.c
 create mode 100644 drivers/staging/fnic2/src/fnic2_io.h
drivers/staging/fnic2/src/fcpio.h new file +347 -0
new file mode 100644
index 0000000..7c8b879
@@ -0,0 +1,347 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _FCPIO_H_
+#define _FCPIO_H_
+
+#include <linux/if_ether.h>
+
+/*
+ * This header file includes all of the data structures used for
+ * communication by the host driver to the fcp firmware.
+ */
+
+/*
+ * Exchange and sequence id space allocated to the host driver
+ */
+#define FCPIO_HOST_EXCH_RANGE_START         0x1000
+
+/*
+ * Command entry type
+ */
+enum fcpio_type {
+	/*
+	 * Initiator request types
+	 */
+	FCPIO_ICMND_16 = 0x1,
+	FCPIO_ICMND_32,
+	FCPIO_ICMND_CMPL,
+	FCPIO_ITMF,
+	FCPIO_ITMF_CMPL,
+
+	/*
+	 * Target request types
+	 */
+	FCPIO_TCMD_SEND_DATA = 0x11,	/* Send RD DATA, Send Resp, Free Xchg */
+	FCPIO_TCMD_RECV_DATA,	/* Send Xfer Rdy, Xfer recvd data to SGL */
+	FCPIO_TCMD_FREE_CMD,	/* Free the resources of cmd with given tag */
+	FCPIO_TCMD_SEND_RESP,	/* Send Resp for Cmd, Free Xchg */
+	FCPIO_TCMD_ABORT_CMD,
+	FCPIO_TCMD_TASK_MGMT,
+
+	/*
+	 * Misc request types
+	 */
+	FCPIO_ACK = 0x20,
+	FCPIO_RESET,
+	FCPIO_RESET_CMPL,
+	FCPIO_FLOGI_REG,
+	FCPIO_FLOGI_REG_CMPL,
+	FCPIO_ECHO,
+	FCPIO_ECHO_CMPL,
+	FCPIO_LUNMAP_CHNG,
+	FCPIO_LUNMAP_REQ,
+	FCPIO_LUNMAP_REQ_CMPL,
+	FCPIO_FLOGI_FIP_REG,
+	FCPIO_FLOGI_FIP_REG_CMPL,
+};
+
+/*
+ * Header status codes from the firmware
+ */
+enum fcpio_status {
+	FCPIO_SUCCESS = 0,              /* request was successful */
+
+	/*
+	 * If a request to the firmware is rejected, the original request
+	 * header will be returned with the status set to one of the following:
+	 */
+	FCPIO_INVALID_HEADER,    /* header contains invalid data */
+	FCPIO_OUT_OF_RESOURCE,   /* out of resources to complete request */
+	FCPIO_INVALID_PARAM,     /* some parameter in request is invalid */
+	FCPIO_REQ_NOT_SUPPORTED, /* request type is not supported */
+	FCPIO_IO_NOT_FOUND,      /* requested I/O was not found */
+
+	/*
+	 * Once a request is processed, the firmware will usually return
+	 * a cmpl message type.  In cases where errors occurred,
+	 * the header status field would be filled in with one of the following:
+	 */
+	FCPIO_ABORTED = 0x41,     /* request was aborted */
+	FCPIO_TIMEOUT,            /* request was timed out */
+	FCPIO_SGL_INVALID,        /* request was aborted due to sgl error */
+	FCPIO_MSS_INVALID,        /* request was aborted due to mss error */
+	FCPIO_DATA_CNT_MISMATCH,  /* recv/sent more/less data than exp. */
+	FCPIO_FW_ERR,             /* request was terminated due to fw error */
+	FCPIO_ITMF_REJECTED,      /* itmf req was rejected by remote node */
+	FCPIO_ITMF_FAILED,        /* itmf req was failed by remote node */
+	FCPIO_ITMF_INCORRECT_LUN, /* itmf req targeted incorrect LUN */
+	FCPIO_CMND_REJECTED,      /* request was invalid and rejected */
+	FCPIO_NO_PATH_AVAIL,      /* no paths to the lun was available */
+	FCPIO_PATH_FAILED,        /* i/o sent to current path failed */
+	FCPIO_LUNMAP_CHNG_PEND,   /* i/o rejected due to lunmap change */
+};
+
+/*
+ * The header for an fcpio request, whether from the firmware or from the
+ * host driver
+ */
+struct fcpio_header {
+	uint8_t            type;	/* enum fcpio_type */
+	uint8_t            status;	/* header status entry */
+	uint16_t           _resvd;	/* reserved */
+	uint32_t	   fcpio_tag;	/* header tag */
+};
+
+static inline void fcpio_header_enc(struct fcpio_header *hdr,
+				    uint8_t type, uint8_t status,
+				    uint32_t tag)
+{
+	hdr->type = type;
+	hdr->status = status;
+	hdr->_resvd = 0;
+	hdr->fcpio_tag = tag;
+}
+
+static inline void fcpio_header_dec(struct fcpio_header *hdr,
+				    uint8_t *type, uint8_t *status,
+				    uint32_t *tag)
+{
+	*type = hdr->type;
+	*status = hdr->status;
+	*tag = hdr->fcpio_tag;
+}
+
+#define CDB_16      16
+#define CDB_32      32
+#define LUN_ADDRESS 8
+
+/*
+ * fcpio_tcmd_data: host -> firmware request
+ * used to request the firmware to send data (rd) or receive data(wr)
+ * in target mode
+ * Used by: FCPIO_TCMD_SEND_DATA & FCPIO_TCMD_RECV_DATA
+ */
+
+struct fcpio_tcmd_data {
+	uint8_t		d_id[3];
+	uint8_t		rsvd;
+	uint8_t		s_id[3];
+	uint8_t		rsvd1;
+	uint16_t	ox_id;
+	uint8_t		rsvd2[2];
+	uint32_t	data_len;
+	uint64_t	sgl_pa;
+	uint16_t	sgl_cnt;
+	uint8_t		send_resp;	/* change it to common flags? */
+	uint8_t		rsp_iu_flags;
+	uint32_t	resid;
+	uint8_t		rsvd3[2];
+	u_int8_t        type;		/* command type read/Write */
+	u_int8_t        rsvd4;		/* reserved */
+	u_int32_t       rel_offset;	/* data sequence relative offset */
+	u_int16_t       npiv_id;	/* FC vNIC only: npiv id of request */
+	u_int16_t       mss;		/* FC vNIC only: max burst */
+	u_int32_t       r_a_tov;	/* FC vNIC only: R_A_TOV in msec */
+	u_int32_t       e_d_tov;
+} __attribute__((__packed__));
+
+/*
+ * fcpio_tcmd_fw_resp: firmware -> host response
+ * used by firmware to send response for a tcmd request
+ * Used as a response for:
+ * FCPIO_TCMD_SEND_DATA
+ * FCPIO_TCMD_RECV_DATA
+ * FCPIO_TCMD_FREE_CMD
+ *
+ */
+struct fcpio_tcmd_fw_rsp {
+	uint8_t		error_code;
+	uint8_t		rsvd;
+	uint16_t	rx_id;
+};
+
+/*
+ * fcpio_tabort: host -> firmware request
+ *
+ * used by the host to request the firmware to abort a target request that was
+ * received by the firmware
+ */
+struct fcpio_tabort {
+	uint32_t   cmd_tag;	/* tag of the target request */
+};
+
+enum fcpio_flogi_reg_format_type {
+	FCPIO_FLOGI_REG_DEF_DEST = 0,	/* Use the oui | s_id mac format */
+	FCPIO_FLOGI_REG_GW_DEST,	/* Use the fixed gateway mac */
+};
+
+/*
+ * fcpio_flogi_reg: host -> firmware request
+ *
+ * fc vnic only
+ * used by the host to notify the firmware of the lif's s_id
+ * and destination mac address format
+ */
+struct fcpio_flogi_reg {
+	uint8_t format;
+	uint8_t s_id[3];		/* FC vNIC only: Source S_ID */
+	uint8_t gateway_mac[ETH_ALEN];	/* Destination gateway mac */
+	uint16_t _resvd;
+	uint32_t r_a_tov;		/* R_A_TOV in msec */
+	uint32_t e_d_tov;		/* E_D_TOV in msec */
+};
+
+/*
+ * fcpio_flogi_fip_reg: host -> firmware request
+ *
+ * fc vnic only
+ * used by the host to notify the firmware of the lif's s_id
+ * and destination mac address format
+ */
+struct fcpio_flogi_fip_reg {
+	uint8_t    _resvd0;
+	uint8_t     s_id[3];		/* FC vNIC only: Source S_ID */
+	uint8_t     fcf_mac[ETH_ALEN];	/* FCF Target destination mac */
+	uint16_t   _resvd1;
+	uint32_t   r_a_tov;		/* R_A_TOV in msec */
+	uint32_t   e_d_tov;		/* E_D_TOV in msec */
+	uint8_t    ha_mac[ETH_ALEN];	/* Host adapter source mac */
+	uint16_t   _resvd2;
+};
+
+/*
+ * Basic structure for all fcpio structures that are sent from the host to the
+ * firmware.  They are 128 bytes per structure.
+ */
+#define FCPIO_HOST_REQ_LEN      128     /* expected length of host requests */
+
+struct fcpio_host_req {
+	struct fcpio_header hdr;
+
+	union {
+		/*
+		 * Defines space needed for request
+		 */
+		uint8_t buf[FCPIO_HOST_REQ_LEN - sizeof(struct fcpio_header)];
+
+		/*
+		 * Target host requests
+		 */
+		struct fcpio_tabort		tabort;
+		struct fcpio_tcmd_data		tdata;
+
+		/*
+		 * Misc requests
+		 */
+		struct fcpio_flogi_reg		flogi_reg;
+		struct fcpio_flogi_fip_reg	flogi_fip_reg;
+	} u;
+};
+
+/*
+ * Task Management request
+ */
+enum tmr_type {
+	FCPIO_TTMF_ABT_TASK             = 0x01,	/* abort task */
+	FCPIO_TTMF_ABT_TASK_SET         = 0x02,	/* abort task set */
+	FCPIO_TTMF_CLR_TASK_SET         = 0x04,	/* clear task set */
+	FCPIO_TTMF_LUN_RESET            = 0x10,	/* logical unit reset task mgmt */
+	FCPIO_TTMF_CLR_ACA		= 0x40	/* Clear ACA condition */
+};
+
+/*
+ * fcpio_ack: firmware -> host response
+ *
+ * used by firmware to notify the host of the last work request received
+ */
+struct fcpio_ack {
+	uint16_t  request_out;	/* last host entry received */
+	uint16_t  _resvd;
+};
+
+/*
+ * fcpio_reset_cmpl: firmware -> host response
+ *
+ * use by firmware to respond to the host's reset request
+ */
+struct fcpio_reset_cmpl {
+	uint16_t   vnic_id;
+};
+
+/*
+ * Basic structure for all fcpio structures that are sent from the firmware to
+ * the host.  They are 64 bytes per structure.
+ */
+#define FCPIO_FW_REQ_LEN        64      /* expected length of fw requests */
+struct fcpio_fw_req {
+	struct fcpio_header hdr;
+
+	union {
+		/*
+		 * Defines space needed for request
+		 */
+		uint8_t buf[FCPIO_FW_REQ_LEN - sizeof(struct fcpio_header)];
+
+		/*
+		 * Target firmware responses
+		 */
+		struct fcpio_tcmd_fw_rsp	trsp;
+
+		/*
+		 * Firmware response to work received
+		 */
+		struct fcpio_ack		ack;
+
+		/*
+		 * Misc requests
+		 */
+	} u;
+};
+
+static inline void fcpio_color_dec(struct fcpio_fw_req *fw_req, uint8_t *color)
+{
+	uint8_t *c = ((uint8_t *) fw_req) + sizeof(struct fcpio_fw_req) - 1;
+
+	*color = *c >> 7;
+
+	/*
+	 * Make sure color bit is read from desc *before* other fields
+	 * are read from desc.  Hardware guarantees color bit is last
+	 * bit (byte) written.  Adding the rmb() prevents the compiler
+	 * and/or CPU from reordering the reads which would potentially
+	 * result in reading stale values.
+	 */
+
+	rmb();
+
+}
+
+#define FNIC2_SGL_SZ	(256 * 16)
+#define FNIC2_SGL_ALIGN	(16)
+
+#endif /* _FCPIO_H_ */
drivers/staging/fnic2/src/fnic2_cmd.c new file +1164 -0

1,164 lines not on this page · raw message

drivers/staging/fnic2/src/fnic2_io.h new file +32 -0
new file mode 100644
index 0000000..59cb97e
@@ -0,0 +1,32 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _FNIC2_IO_H_
+#define _FNIC2_IO_H_
+
+#include <scsi/fc/fc_fcp.h>
+
+#define FNIC2_DFLT_SG_DESC_CNT	32
+#define FNIC2_MAX_SG_DESC_CNT	256	/* Maximum descriptors per sgl */
+
+struct host_sg_desc {
+	__le64		addr;
+	__le32		len;
+	uint32_t	_resvd;
+};
+
+#endif /* _FNIC2_IO_H_ */
Signature · 1 line
1.8.3.1
#15 lore raw

PATCH 7/10 staging: fnic2 add queue descriptors

In reply to Oliver Smith-Denny

These files contain queueing interfaces for software.

---
 drivers/staging/fnic2/src/cq_desc.h      |  74 +++++++++++++++
 drivers/staging/fnic2/src/cq_enet_desc.h | 158 +++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/cq_exch_desc.h | 104 ++++++++++++++++++++
 drivers/staging/fnic2/src/rq_enet_desc.h |  45 +++++++++
 drivers/staging/fnic2/src/wq_enet_desc.h |  69 ++++++++++++++
 5 files changed, 450 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/cq_desc.h
 create mode 100644 drivers/staging/fnic2/src/cq_enet_desc.h
 create mode 100644 drivers/staging/fnic2/src/cq_exch_desc.h
 create mode 100644 drivers/staging/fnic2/src/rq_enet_desc.h
 create mode 100644 drivers/staging/fnic2/src/wq_enet_desc.h
drivers/staging/fnic2/src/cq_desc.h new file +74 -0
new file mode 100644
index 0000000..638753d
@@ -0,0 +1,74 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef _CQ_DESC_H_
+#define _CQ_DESC_H_
+
+/*
+ * Completion queue descriptor types
+ */
+enum cq_desc_types {
+	CQ_DESC_TYPE_RQ_ENET = 3,
+	CQ_DESC_TYPE_RQ_FCP = 4,
+};
+
+/* Completion queue descriptor: 16B
+ *
+ * All completion queues have this basic layout.  The
+ * type_specific area is unique for each completion
+ * queue type.
+ */
+struct cq_desc {
+	__le16 completed_index;
+	__le16 q_number;
+	uint8_t type_specific[11];
+	uint8_t type_color;
+};
+
+#define CQ_DESC_TYPE_BITS        4
+#define CQ_DESC_TYPE_MASK        ((1 << CQ_DESC_TYPE_BITS) - 1)
+#define CQ_DESC_COLOR_MASK       1
+#define CQ_DESC_COLOR_SHIFT      7
+#define CQ_DESC_Q_NUM_BITS       10
+#define CQ_DESC_Q_NUM_MASK       ((1 << CQ_DESC_Q_NUM_BITS) - 1)
+#define CQ_DESC_COMP_NDX_BITS    12
+#define CQ_DESC_COMP_NDX_MASK    ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
+
+static inline void cq_desc_dec(const struct cq_desc *desc_arg, uint8_t *type, uint8_t *color, uint16_t *q_number, uint16_t *completed_index)
+{
+	const struct cq_desc *desc = desc_arg;
+	const uint8_t type_color = desc->type_color;
+
+	*color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
+
+	/*
+	 * Make sure color bit is read from desc *before* other fields
+	 * are read from desc.  Hardware guarantees color bit is last
+	 * bit (byte) written.  Adding the rmb() prevents the compiler
+	 * and/or CPU from reordering the reads which would potentially
+	 * result in reading stale values.
+	 */
+
+	rmb();
+
+	*type = type_color & CQ_DESC_TYPE_MASK;
+	*q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
+	*completed_index = le16_to_cpu(desc->completed_index) &
+		CQ_DESC_COMP_NDX_MASK;
+}
+
+#endif /* _CQ_DESC_H_ */
drivers/staging/fnic2/src/cq_enet_desc.h new file +158 -0

158 lines not on this page · raw message

drivers/staging/fnic2/src/cq_exch_desc.h new file +104 -0

104 lines not on this page · raw message

drivers/staging/fnic2/src/rq_enet_desc.h new file +45 -0

45 lines not on this page · raw message

drivers/staging/fnic2/src/wq_enet_desc.h new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#16 lore raw

PATCH 8/10 staging: fnic2 add vnic queue interface

In reply to Oliver Smith-Denny

These files contain low level queueing interfaces
for hardware.

---
 drivers/staging/fnic2/src/vnic_cq.c      |  85 ++++++++++++
 drivers/staging/fnic2/src/vnic_cq.h      | 120 ++++++++++++++++
 drivers/staging/fnic2/src/vnic_cq_copy.h |  61 ++++++++
 drivers/staging/fnic2/src/vnic_rq.c      | 196 ++++++++++++++++++++++++++
 drivers/staging/fnic2/src/vnic_rq.h      | 231 +++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/vnic_wq.c      | 183 ++++++++++++++++++++++++
 drivers/staging/fnic2/src/vnic_wq.h      | 174 +++++++++++++++++++++++
 drivers/staging/fnic2/src/vnic_wq_copy.c | 115 +++++++++++++++
 drivers/staging/fnic2/src/vnic_wq_copy.h | 127 +++++++++++++++++
 9 files changed, 1292 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/vnic_cq.c
 create mode 100644 drivers/staging/fnic2/src/vnic_cq.h
 create mode 100644 drivers/staging/fnic2/src/vnic_cq_copy.h
 create mode 100644 drivers/staging/fnic2/src/vnic_rq.c
 create mode 100644 drivers/staging/fnic2/src/vnic_rq.h
 create mode 100644 drivers/staging/fnic2/src/vnic_wq.c
 create mode 100644 drivers/staging/fnic2/src/vnic_wq.h
 create mode 100644 drivers/staging/fnic2/src/vnic_wq_copy.c
 create mode 100644 drivers/staging/fnic2/src/vnic_wq_copy.h
drivers/staging/fnic2/src/vnic_cq.c new file +85 -0
new file mode 100644
index 0000000..ac78b1b
@@ -0,0 +1,85 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/pci.h>
+#include "vnic_dev.h"
+#include "vnic_cq.h"
+
+void vnic_cq_free(struct vnic_cq *cq)
+{
+	vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
+
+	cq->ctrl = NULL;
+}
+
+int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
+		  unsigned int desc_count, unsigned int desc_size)
+{
+	int err;
+
+	cq->index = index;
+	cq->vdev = vdev;
+
+	cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
+	if (!cq->ctrl) {
+		pr_err("Failed to hook CQ[%d] resource\n", index);
+		return -EINVAL;
+	}
+
+	err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);
+	if (err)
+		return err;
+
+	return 0;
+}
+
+void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
+		  unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
+		  unsigned int cq_tail_color, unsigned int interrupt_enable,
+		  unsigned int cq_entry_enable, unsigned int cq_message_enable,
+		  unsigned int interrupt_offset, uint64_t cq_message_addr)
+{
+	uint64_t paddr;
+
+	paddr = (uint64_t)cq->ring.base_addr | VNIC_PADDR_TARGET;
+	writeq(paddr, &cq->ctrl->ring_base);
+	iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
+	iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
+	iowrite32(color_enable, &cq->ctrl->color_enable);
+	iowrite32(cq_head, &cq->ctrl->cq_head);
+	iowrite32(cq_tail, &cq->ctrl->cq_tail);
+	iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
+	iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
+	iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
+	iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
+	iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
+	writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
+}
+
+void vnic_cq_clean(struct vnic_cq *cq)
+{
+	cq->to_clean = 0;
+	cq->last_color = 0;
+
+	iowrite32(0, &cq->ctrl->cq_head);
+	iowrite32(0, &cq->ctrl->cq_tail);
+	iowrite32(1, &cq->ctrl->cq_tail_color);
+
+	vnic_dev_clear_desc_ring(&cq->ring);
+}
drivers/staging/fnic2/src/vnic_cq.h new file +120 -0

120 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_cq_copy.h new file +61 -0

61 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_rq.c new file +196 -0

196 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_rq.h new file +231 -0

231 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_wq.c new file +183 -0

183 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_wq.h new file +174 -0

174 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_wq_copy.c new file +115 -0

115 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_wq_copy.h new file +127 -0

127 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#17 lore raw

PATCH 9/10 staging: fnic2 add vnic handling

In reply to Oliver Smith-Denny

These files contain low level interfaces for managing hardware and firmware features.

---
 drivers/staging/fnic2/src/vnic_dev.c      | 701 ++++++++++++++++++++++++++++++
 drivers/staging/fnic2/src/vnic_dev.h      | 163 +++++++
 drivers/staging/fnic2/src/vnic_devcmd.h   | 349 +++++++++++++++
 drivers/staging/fnic2/src/vnic_intr.c     |  61 +++
 drivers/staging/fnic2/src/vnic_intr.h     | 116 +++++
 drivers/staging/fnic2/src/vnic_nic.h      |  78 ++++
 drivers/staging/fnic2/src/vnic_resource.h |  50 +++
 drivers/staging/fnic2/src/vnic_scsi.h     |  88 ++++
 drivers/staging/fnic2/src/vnic_stats.h    |  68 +++
 9 files changed, 1674 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/vnic_dev.c
 create mode 100644 drivers/staging/fnic2/src/vnic_dev.h
 create mode 100644 drivers/staging/fnic2/src/vnic_devcmd.h
 create mode 100644 drivers/staging/fnic2/src/vnic_intr.c
 create mode 100644 drivers/staging/fnic2/src/vnic_intr.h
 create mode 100644 drivers/staging/fnic2/src/vnic_nic.h
 create mode 100644 drivers/staging/fnic2/src/vnic_resource.h
 create mode 100644 drivers/staging/fnic2/src/vnic_scsi.h
 create mode 100644 drivers/staging/fnic2/src/vnic_stats.h
drivers/staging/fnic2/src/vnic_dev.c new file +701 -0
new file mode 100644
index 0000000..5e04d63
@@ -0,0 +1,701 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+#include <linux/if_ether.h>
+#include <linux/slab.h>
+#include "vnic_resource.h"
+#include "vnic_devcmd.h"
+#include "vnic_dev.h"
+#include "vnic_stats.h"
+
+struct vnic_res {
+	void __iomem	*vaddr;
+	unsigned int	count;
+};
+
+struct vnic_dev {
+	void				*priv;
+	struct pci_dev			*pdev;
+	struct vnic_res			res[RES_TYPE_MAX];
+	enum vnic_dev_intr_mode		intr_mode;
+	struct vnic_devcmd __iomem	*devcmd;
+	struct vnic_devcmd_notify	*notify;
+	struct vnic_devcmd_notify	notify_copy;
+	dma_addr_t			notify_pa;
+	uint32_t			*linkstatus;
+	dma_addr_t			linkstatus_pa;
+	struct vnic_stats		*stats;
+	dma_addr_t			stats_pa;
+	struct vnic_devcmd_fw_info	*fw_info;
+	dma_addr_t			fw_info_pa;
+};
+
+#define VNIC_MAX_RES_HDR_SIZE \
+	(sizeof(struct vnic_resource_header) + \
+	sizeof(struct vnic_resource) * RES_TYPE_MAX)
+#define VNIC_RES_STRIDE	128
+
+void *vnic_dev_priv(struct vnic_dev *vdev)
+{
+	return vdev->priv;
+}
+
+static int vnic_dev_discover_res(struct vnic_dev *vdev,
+				 struct vnic_dev_bar *bar)
+{
+	struct vnic_resource_header __iomem *rh;
+	struct vnic_resource __iomem *r;
+	uint8_t type;
+
+	if (bar->len < VNIC_MAX_RES_HDR_SIZE) {
+		pr_err("vNIC BAR0 res hdr length error\n");
+		return -EINVAL;
+	}
+
+	rh = bar->vaddr;
+	if (!rh) {
+		pr_err("vNIC BAR0 res hdr not mem-mapped\n");
+		return -EINVAL;
+	}
+
+	if (ioread32(&rh->magic) != VNIC_RES_MAGIC ||
+		ioread32(&rh->version) != VNIC_RES_VERSION) {
+		pr_err("vNIC BAR0 res magic/version error exp %lx/%lx curr %x/%x\n",
+			VNIC_RES_MAGIC, VNIC_RES_VERSION,
+			ioread32(&rh->magic), ioread32(&rh->version));
+		return -EINVAL;
+	}
+
+	r = (struct vnic_resource __iomem *)(rh + 1);
+
+	while ((type = ioread8(&r->type)) != RES_TYPE_EOL) {
+
+		uint8_t bar_num = ioread8(&r->bar);
+		uint32_t bar_offset = ioread32(&r->bar_offset);
+		uint32_t count = ioread32(&r->count);
+		uint32_t len;
+
+		r++;
+
+		if (bar_num != 0)  /* only mapping in BAR0 resources */
+			continue;
+
+		switch (type) {
+		case RES_TYPE_WQ:
+		case RES_TYPE_RQ:
+		case RES_TYPE_CQ:
+		case RES_TYPE_INTR_CTRL:
+			/* each count is stride bytes long */
+			len = count * VNIC_RES_STRIDE;
+			if (len + bar_offset > bar->len) {
+				pr_err("vNIC BAR0 resource %d out-of-bounds, offset 0x%x + size 0x%x > bar len 0x%lx\n",
+					type, bar_offset,
+					len,
+					bar->len);
+				return -EINVAL;
+			}
+			break;
+		case RES_TYPE_INTR_PBA_LEGACY:
+		case RES_TYPE_DEVCMD:
+			len = count;
+			break;
+		default:
+			continue;
+		}
+
+		vdev->res[type].count = count;
+		vdev->res[type].vaddr = (char __iomem *)bar->vaddr + bar_offset;
+	}
+
+	return 0;
+}
+
+unsigned int vnic_dev_get_res_count(struct vnic_dev *vdev,
+				    enum vnic_res_type type)
+{
+	return vdev->res[type].count;
+}
+
+void __iomem *vnic_dev_get_res(struct vnic_dev *vdev, enum vnic_res_type type,
+			       unsigned int index)
+{
+	if (!vdev->res[type].vaddr)
+		return NULL;
+
+	switch (type) {
+	case RES_TYPE_WQ:
+	case RES_TYPE_RQ:
+	case RES_TYPE_CQ:
+	case RES_TYPE_INTR_CTRL:
+		return (char __iomem *)vdev->res[type].vaddr +
+					index * VNIC_RES_STRIDE;
+	default:
+		return (char __iomem *)vdev->res[type].vaddr;
+	}
+}
+
+unsigned int vnic_dev_desc_ring_size(struct vnic_dev_ring *ring,
+				     unsigned int desc_count,
+				     unsigned int desc_size)
+{
+	/* The base address of the desc rings must be 512 byte aligned.
+	 * Descriptor count is aligned to groups of 32 descriptors.  A
+	 * count of 0 means the maximum 4096 descriptors.  Descriptor
+	 * size is aligned to 16 bytes.
+	 */
+
+	unsigned int count_align = 32;
+	unsigned int desc_align = 16;
+
+	ring->base_align = 512;
+
+	if (desc_count == 0)
+		desc_count = 4096;
+
+	ring->desc_count = ALIGN(desc_count, count_align);
+
+	ring->desc_size = ALIGN(desc_size, desc_align);
+
+	ring->size = ring->desc_count * ring->desc_size;
+	ring->size_unaligned = ring->size + ring->base_align;
+
+	return ring->size_unaligned;
+}
+
+void vnic_dev_clear_desc_ring(struct vnic_dev_ring *ring)
+{
+	memset(ring->descs, 0, ring->size);
+}
+
+int vnic_dev_alloc_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring,
+			     unsigned int desc_count, unsigned int desc_size)
+{
+	vnic_dev_desc_ring_size(ring, desc_count, desc_size);
+
+	ring->descs_unaligned = pci_alloc_consistent(vdev->pdev,
+		ring->size_unaligned,
+		&ring->base_addr_unaligned);
+
+	if (!ring->descs_unaligned) {
+		pr_err("Failed to allocate ring. size = %d, aborting\n",
+			(int)ring->size);
+		return -ENOMEM;
+	}
+
+	ring->base_addr = ALIGN(ring->base_addr_unaligned,
+		ring->base_align);
+	ring->descs = (uint8_t *)ring->descs_unaligned +
+		(ring->base_addr - ring->base_addr_unaligned);
+
+	vnic_dev_clear_desc_ring(ring);
+
+	ring->desc_avail = ring->desc_count - 1;
+
+	return 0;
+}
+
+void vnic_dev_free_desc_ring(struct vnic_dev *vdev, struct vnic_dev_ring *ring)
+{
+	if (ring->descs) {
+		pci_free_consistent(vdev->pdev,
+			ring->size_unaligned,
+			ring->descs_unaligned,
+			ring->base_addr_unaligned);
+		ring->descs = NULL;
+	}
+}
+
+int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,
+		 uint64_t *a0, uint64_t *a1, int wait)
+{
+	struct vnic_devcmd __iomem *devcmd = vdev->devcmd;
+	int delay;
+	uint32_t status;
+	int dev_cmd_err[] = {
+		/* convert from fw's version of error.h to host's version */
+		0,	/* ERR_SUCCESS */
+		EINVAL,	/* ERR_EINVAL */
+		EFAULT,	/* ERR_EFAULT */
+		EPERM,	/* ERR_EPERM */
+		EBUSY,  /* ERR_EBUSY */
+	};
+	int err;
+
+	status = ioread32(&devcmd->status);
+	if (status & STAT_BUSY) {
+		pr_err("Busy devcmd %d\n", _CMD_N(cmd));
+		return -EBUSY;
+	}
+
+	if (_CMD_DIR(cmd) & _CMD_DIR_WRITE) {
+		writeq(*a0, &devcmd->args[0]);
+		writeq(*a1, &devcmd->args[1]);
+		wmb();
+	}
+
+	iowrite32(cmd, &devcmd->cmd);
+
+	if ((_CMD_FLAGS(cmd) & _CMD_FLAGS_NOWAIT))
+			return 0;
+
+	for (delay = 0; delay < wait; delay++) {
+
+		udelay(100);
+
+		status = ioread32(&devcmd->status);
+		if (!(status & STAT_BUSY)) {
+
+			if (status & STAT_ERROR) {
+				err = dev_cmd_err[(int)readq(&devcmd->args[0])];
+				pr_err("Error %d devcmd %d\n",
+					err, _CMD_N(cmd));
+				return -err;
+			}
+
+			if (_CMD_DIR(cmd) & _CMD_DIR_READ) {
+				rmb();
+				*a0 = readq(&devcmd->args[0]);
+				*a1 = readq(&devcmd->args[1]);
+			}
+
+			return 0;
+		}
+	}
+
+	pr_err("Timedout devcmd %d\n", _CMD_N(cmd));
+	return -ETIMEDOUT;
+}
+
+int vnic_dev_fw_info(struct vnic_dev *vdev, struct vnic_devcmd_fw_info **fw_info)
+{
+	uint64_t a0, a1 = 0;
+	int wait = 1000;
+	int err = 0;
+
+	if (!vdev->fw_info) {
+		vdev->fw_info = pci_alloc_consistent(vdev->pdev,
+			sizeof(struct vnic_devcmd_fw_info),
+			&vdev->fw_info_pa);
+		if (!vdev->fw_info)
+			return -ENOMEM;
+
+		a0 = vdev->fw_info_pa;
+
+		/* only get fw_info once and cache it */
+		err = vnic_dev_cmd(vdev, CMD_MCPU_FW_INFO, &a0, &a1, wait);
+	}
+
+	*fw_info = vdev->fw_info;
+
+	return err;
+}
+
+int vnic_dev_spec(struct vnic_dev *vdev, unsigned int offset, unsigned int size,
+		  void *value)
+{
+	uint64_t a0, a1;
+	int wait = 1000;
+	int err;
+
+	a0 = offset;
+	a1 = size;
+
+	err = vnic_dev_cmd(vdev, CMD_DEV_SPEC, &a0, &a1, wait);
+
+	switch (size) {
+	case 1:
+		*(uint8_t *)value = (uint8_t)a0;
+		break;
+	case 2:
+		*(uint16_t *)value = (uint16_t)a0;
+		break;
+	case 4:
+		*(uint32_t *)value = (uint32_t)a0;
+		break;
+	case 8:
+		*(uint64_t *)value = a0;
+		break;
+	default:
+		BUG();
+		break;
+	}
+
+	return err;
+}
+
+int vnic_dev_stats_clear(struct vnic_dev *vdev)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_STATS_CLEAR, &a0, &a1, wait);
+}
+
+int vnic_dev_stats_dump(struct vnic_dev *vdev, struct vnic_stats **stats)
+{
+	uint64_t a0, a1;
+	int wait = 1000;
+
+	if (!vdev->stats) {
+		vdev->stats = pci_alloc_consistent(vdev->pdev,
+			sizeof(struct vnic_stats), &vdev->stats_pa);
+		if (!vdev->stats)
+			return -ENOMEM;
+	}
+
+	*stats = vdev->stats;
+	a0 = vdev->stats_pa;
+	a1 = sizeof(struct vnic_stats);
+
+	return vnic_dev_cmd(vdev, CMD_STATS_DUMP, &a0, &a1, wait);
+}
+
+int vnic_dev_close(struct vnic_dev *vdev)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_CLOSE, &a0, &a1, wait);
+}
+
+int vnic_dev_enable(struct vnic_dev *vdev)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_ENABLE, &a0, &a1, wait);
+}
+
+int vnic_dev_disable(struct vnic_dev *vdev)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_DISABLE, &a0, &a1, wait);
+}
+
+int vnic_dev_open(struct vnic_dev *vdev, int arg)
+{
+	uint64_t a0 = (uint32_t)arg, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_OPEN, &a0, &a1, wait);
+}
+
+int vnic_dev_open_done(struct vnic_dev *vdev, int *done)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+	int err;
+
+	*done = 0;
+
+	err = vnic_dev_cmd(vdev, CMD_OPEN_STATUS, &a0, &a1, wait);
+	if (err)
+		return err;
+
+	*done = (a0 == 0);
+
+	return 0;
+}
+
+int vnic_dev_soft_reset(struct vnic_dev *vdev, int arg)
+{
+	uint64_t a0 = (uint32_t)arg, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_SOFT_RESET, &a0, &a1, wait);
+}
+
+int vnic_dev_soft_reset_done(struct vnic_dev *vdev, int *done)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+	int err;
+
+	*done = 0;
+
+	err = vnic_dev_cmd(vdev, CMD_SOFT_RESET_STATUS, &a0, &a1, wait);
+	if (err)
+		return err;
+
+	*done = (a0 == 0);
+
+	return 0;
+}
+
+int vnic_dev_hang_notify(struct vnic_dev *vdev)
+{
+	uint64_t a0, a1;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_HANG_NOTIFY, &a0, &a1, wait);
+}
+
+int vnic_dev_mac_addr(struct vnic_dev *vdev, uint8_t *mac_addr)
+{
+	uint64_t a0, a1;
+	int wait = 1000;
+	int err, i;
+
+	for (i = 0; i < ETH_ALEN; i++)
+		mac_addr[i] = 0;
+
+	err = vnic_dev_cmd(vdev, CMD_MAC_ADDR, &a0, &a1, wait);
+	if (err)
+		return err;
+
+	for (i = 0; i < ETH_ALEN; i++)
+		mac_addr[i] = ((uint8_t *)&a0)[i];
+
+	return 0;
+}
+
+void vnic_dev_packet_filter(struct vnic_dev *vdev, int directed, int multicast,
+			    int broadcast, int promisc, int allmulti)
+{
+	uint64_t a0, a1 = 0;
+	int wait = 1000;
+	int err;
+
+	a0 = (directed ? CMD_PFILTER_DIRECTED : 0) |
+	     (multicast ? CMD_PFILTER_MULTICAST : 0) |
+	     (broadcast ? CMD_PFILTER_BROADCAST : 0) |
+	     (promisc ? CMD_PFILTER_PROMISCUOUS : 0) |
+	     (allmulti ? CMD_PFILTER_ALL_MULTICAST : 0);
+
+	err = vnic_dev_cmd(vdev, CMD_PACKET_FILTER, &a0, &a1, wait);
+	if (err)
+		pr_err("Can't set packet filter\n");
+}
+
+void vnic_dev_add_addr(struct vnic_dev *vdev, uint8_t *addr)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+	int err;
+	int i;
+
+	for (i = 0; i < ETH_ALEN; i++)
+		((uint8_t *)&a0)[i] = addr[i];
+
+	err = vnic_dev_cmd(vdev, CMD_ADDR_ADD, &a0, &a1, wait);
+	if (err)
+		pr_err("Can't add addr %02x:%02x:%02x:%02x:%02x:%02x, %d\n",
+			addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
+			err);
+}
+
+void vnic_dev_del_addr(struct vnic_dev *vdev, uint8_t *addr)
+{
+	uint64_t a0 = 0, a1 = 0;
+	int wait = 1000;
+	int err;
+	int i;
+
+	for (i = 0; i < ETH_ALEN; i++)
+		((uint8_t *)&a0)[i] = addr[i];
+
+	err = vnic_dev_cmd(vdev, CMD_ADDR_DEL, &a0, &a1, wait);
+	if (err)
+		pr_err("Can't del addr %02x:%02x:%02x:%02x:%02x:%02x, %d\n",
+			addr[0], addr[1], addr[2], addr[3], addr[4], addr[5],
+			err);
+}
+
+int vnic_dev_notify_set(struct vnic_dev *vdev, uint16_t intr)
+{
+	uint64_t a0, a1;
+	int wait = 1000;
+
+	if (!vdev->notify) {
+		vdev->notify = pci_alloc_consistent(vdev->pdev,
+			sizeof(struct vnic_devcmd_notify),
+			&vdev->notify_pa);
+		if (!vdev->notify)
+			return -ENOMEM;
+	}
+
+	a0 = vdev->notify_pa;
+	a1 = ((uint64_t)intr << 32) & 0x0000ffff00000000ULL;
+	a1 += sizeof(struct vnic_devcmd_notify);
+
+	return vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
+}
+
+void vnic_dev_notify_unset(struct vnic_dev *vdev)
+{
+	uint64_t a0, a1;
+	int wait = 1000;
+
+	a0 = 0;  /* paddr = 0 to unset notify buffer */
+	a1 = 0x0000ffff00000000ULL; /* intr num = -1 to unreg for intr */
+	a1 += sizeof(struct vnic_devcmd_notify);
+
+	vnic_dev_cmd(vdev, CMD_NOTIFY, &a0, &a1, wait);
+}
+
+static int vnic_dev_notify_ready(struct vnic_dev *vdev)
+{
+	uint32_t *words;
+	unsigned int nwords = sizeof(struct vnic_devcmd_notify) / 4;
+	unsigned int i;
+	uint32_t csum;
+
+	if (!vdev->notify)
+		return 0;
+
+	do {
+		csum = 0;
+		memcpy(&vdev->notify_copy, vdev->notify,
+			sizeof(struct vnic_devcmd_notify));
+		words = (uint32_t *)&vdev->notify_copy;
+		for (i = 1; i < nwords; i++)
+			csum += words[i];
+	} while (csum != words[0]);
+
+	return 1;
+}
+
+int vnic_dev_init(struct vnic_dev *vdev, int arg)
+{
+	uint64_t a0 = (uint32_t)arg, a1 = 0;
+	int wait = 1000;
+
+	return vnic_dev_cmd(vdev, CMD_INIT, &a0, &a1, wait);
+}
+
+uint16_t vnic_dev_set_default_vlan(struct vnic_dev *vdev, uint16_t new_default_vlan)
+{
+	uint64_t a0 = new_default_vlan, a1 = 0;
+	int wait = 1000;
+	int old_vlan = 0;
+
+	old_vlan = vnic_dev_cmd(vdev, CMD_SET_DEFAULT_VLAN, &a0, &a1, wait);
+	return (uint16_t)old_vlan;
+}
+
+int vnic_dev_link_status(struct vnic_dev *vdev)
+{
+	if (vdev->linkstatus)
+		return *vdev->linkstatus;
+
+	if (!vnic_dev_notify_ready(vdev))
+		return 0;
+
+	return vdev->notify_copy.link_state;
+}
+
+uint32_t vnic_dev_port_speed(struct vnic_dev *vdev)
+{
+	if (!vnic_dev_notify_ready(vdev))
+		return 0;
+
+	return vdev->notify_copy.port_speed;
+}
+
+uint32_t vnic_dev_msg_lvl(struct vnic_dev *vdev)
+{
+	if (!vnic_dev_notify_ready(vdev))
+		return 0;
+
+	return vdev->notify_copy.msglvl;
+}
+
+uint32_t vnic_dev_mtu(struct vnic_dev *vdev)
+{
+	if (!vnic_dev_notify_ready(vdev))
+		return 0;
+
+	return vdev->notify_copy.mtu;
+}
+
+uint32_t vnic_dev_link_down_cnt(struct vnic_dev *vdev)
+{
+	if (!vnic_dev_notify_ready(vdev))
+		return 0;
+
+	return vdev->notify_copy.link_down_cnt;
+}
+
+void vnic_dev_set_intr_mode(struct vnic_dev *vdev, enum vnic_dev_intr_mode intr_mode)
+{
+	vdev->intr_mode = intr_mode;
+}
+
+enum vnic_dev_intr_mode vnic_dev_get_intr_mode(
+	struct vnic_dev *vdev)
+{
+	return vdev->intr_mode;
+}
+
+void vnic_dev_unregister(struct vnic_dev *vdev)
+{
+	if (vdev) {
+		if (vdev->notify)
+			pci_free_consistent(vdev->pdev,
+				sizeof(struct vnic_devcmd_notify),
+				vdev->notify,
+				vdev->notify_pa);
+		if (vdev->linkstatus)
+			pci_free_consistent(vdev->pdev,
+				sizeof(uint32_t),
+				vdev->linkstatus,
+				vdev->linkstatus_pa);
+		if (vdev->stats)
+			pci_free_consistent(vdev->pdev,
+				sizeof(struct vnic_stats),
+				vdev->stats, vdev->stats_pa);
+		if (vdev->fw_info)
+			pci_free_consistent(vdev->pdev,
+				sizeof(struct vnic_devcmd_fw_info),
+				vdev->fw_info, vdev->fw_info_pa);
+		kfree(vdev);
+	}
+}
+
+struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,
+				   void *priv, struct pci_dev *pdev, struct vnic_dev_bar *bar)
+{
+	if (!vdev) {
+		vdev = kzalloc(sizeof(struct vnic_dev), GFP_KERNEL);
+		if (!vdev)
+			return NULL;
+	}
+
+	vdev->priv = priv;
+	vdev->pdev = pdev;
+
+	if (vnic_dev_discover_res(vdev, bar))
+		goto err_out;
+
+	vdev->devcmd = vnic_dev_get_res(vdev, RES_TYPE_DEVCMD, 0);
+	if (!vdev->devcmd)
+		goto err_out;
+
+	return vdev;
+
+err_out:
+	vnic_dev_unregister(vdev);
+	return NULL;
+}
drivers/staging/fnic2/src/vnic_dev.h new file +163 -0

163 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_devcmd.h new file +349 -0

349 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_intr.c new file +61 -0

61 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_intr.h new file +116 -0

116 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_nic.h new file +78 -0

78 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_resource.h new file +50 -0

50 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_scsi.h new file +88 -0

88 lines not on this page · raw message

drivers/staging/fnic2/src/vnic_stats.h new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#18 lore raw

PATCH 10/10 staging: fnic2 add build and config

In reply to Oliver Smith-Denny

These files contain build and config files.

---
 drivers/staging/Kconfig            |  2 ++
 drivers/staging/Makefile           |  1 +
 drivers/staging/fnic2/Kconfig      |  6 ++++++
 drivers/staging/fnic2/LICENSE      | 13 +++++++++++++
 drivers/staging/fnic2/Makefile     |  3 +++
 drivers/staging/fnic2/TODO         | 14 ++++++++++++++
 drivers/staging/fnic2/src/Makefile | 28 ++++++++++++++++++++++++++++
 7 files changed, 67 insertions(+)
 create mode 100644 drivers/staging/fnic2/Kconfig
 create mode 100644 drivers/staging/fnic2/LICENSE
 create mode 100644 drivers/staging/fnic2/Makefile
 create mode 100644 drivers/staging/fnic2/TODO
 create mode 100644 drivers/staging/fnic2/src/Makefile
drivers/staging/Kconfig +2 -0
index d5926f0..239e322 100644
@@ -132,4 +132,6 @@ source "drivers/staging/mt7621-eth/Kconfig"
 
 source "drivers/staging/mt7621-dts/Kconfig"
 
+source "drivers/staging/fnic2/Kconfig"
+
 endif # STAGING
drivers/staging/Makefile +1 -0
index 919753c..fdd9a63 100644
@@ -57,3 +57,4 @@ obj-$(CONFIG_SOC_MT7621)	+= mt7621-dma/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-mmc/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-eth/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-dts/
+obj-$(CONFIG_FNIC2)		+= fnic2/
drivers/staging/fnic2/Kconfig new file +6 -0
new file mode 100644
index 0000000..3983c30
@@ -0,0 +1,6 @@
+config FNIC2
+        tristate "FNIC2 - CISCO FCoE HBA Driver"
+        depends on PCI && X86 && TARGET_CORE
+        help
+         This enables support for the Cisco FNIC2 FCoE HBA Driver
+         with SCSI Target Mode.
drivers/staging/fnic2/LICENSE new file +13 -0
new file mode 100644
index 0000000..1889afb
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+This program is free software; you may redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; version 2 of the License.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
drivers/staging/fnic2/Makefile new file +3 -0
new file mode 100644
index 0000000..8f14039
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+obj-$(CONFIG_FNIC2)	+= src/
drivers/staging/fnic2/TODO new file +14 -0
new file mode 100644
index 0000000..5d93ec3
@@ -0,0 +1,14 @@
+* Add multiqueue support
+* Integrate vnic files with other drivers
+* Coding style changes (already ran smatch, sparse, checkpatch)
+* run them + coccinelle after further changes
+* Add NVME over FC support
+* Check per cmd locking to see if needed
+* Change statically allocated cmd pool to mempool
+* Add function headers
+
+Send patches to:
+	Greg Kroah-Hartman <[email protected]>
+	Arulprabhu Ponnusamy <[email protected]>
+	Gian Carlo Boffa <[email protected]>
+	Oliver Smith-Denny <[email protected]>
drivers/staging/fnic2/src/Makefile new file +28 -0
new file mode 100644
index 0000000..0d22ffc
@@ -0,0 +1,28 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2018 Cisco Systems, Inc.
+# Makefile_wrap
+# This file prepended for out-of-kernel make by ofc/release/*/Makefile
+
+#
+# Add -I for building a set of modules out-of-kernel where they have
+# their own set of include files for include/scsi, for example.
+#
+CPPFLAGS := $(SUBTREE_INCLUDE) $(CPPFLAGS)
+# end of Makefile_wrap
+obj-$(CONFIG_FNIC2) += fnic2.o
+
+fnic2-y := \
+        fnic2_isr.o \
+	fnic2_main.o \
+	fnic2_res.o \
+	vnic_cq.o \
+	vnic_dev.o \
+	vnic_intr.o \
+	vnic_rq.o \
+	vnic_wq_copy.o \
+	vnic_wq.o \
+        fdls_if.o \
+	fip.o \
+	fdls_disc.o \
+	fnic2_cmd.o	\
+	fnic2_lio.o
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 01/10] staging: fnic2 add initialization

In reply to Oliver Smith-Denny
Quoted 12 lines · Oliver Smith-Denny

These files contain module load and unload, global driver context, PCI registration, PCI probe and remove, and definitions of the fnic2 global context.

Quoted 6 lines
---
 drivers/staging/fnic2/src/fnic2.h      | 256 ++++++++++++
 drivers/staging/fnic2/src/fnic2_main.c | 711 +++++++++++++++++++++++++++++++++
 2 files changed, 967 insertions(+)
 create mode 100644 drivers/staging/fnic2/src/fnic2.h
 create mode 100644 drivers/staging/fnic2/src/fnic2_main.c

Why is this a drivers/staging/ driver at all? What is keeping you from getting this merged into the "proper" place in the kernel?

If you have a staging driver, you have to have a TODO file in the directory listing what is keeping this in the staging section.

Also, one tiny thing to fix up:

drivers/staging/fnic2/src/fnic2.h line 2

Quoted 5 lines
drivers/staging/fnic2/src/fnic2.h new file +2 -0
@@ -0,0 +1,256 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0

Please read the documentation on how to properly use SPDX tags on kernel files. This needs to be the first line of the file.

thanks,

greg k-h

#9 lore raw

Re: [PATCH 02/10] staging: fnic2 add resource allocation

In reply to Oliver Smith-Denny
Quoted 10 lines · Oliver Smith-Denny
drivers/staging/fnic2/src/fnic2_isr.c new file +7 -0
@@ -0,0 +1,324 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.

drivers/staging/fnic2/src/fnic2_isr.c line 17

Quoted 10 lines
drivers/staging/fnic2/src/fnic2_isr.c new file +10 -0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */

No need for the messy boilerplate text if you have a SPDX line, please remove both of those paragraphs.

thanks,

greg k-h

#11 lore raw

Re: [PATCH 03/10] staging: fnic2 add fip handling

In reply to Oliver Smith-Denny
Quoted 12 lines · Oliver Smith-Denny
drivers/staging/fnic2/src/fip.c new file +9 -0
@@ -0,0 +1,804 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0
+ * Copyright 2018 Cisco Systems, Inc.  All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,

drivers/staging/fnic2/src/fip.c line 19

Quoted 10 lines
drivers/staging/fnic2/src/fip.c new file +10 -0
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*! \file */

What is that line for?

#3 lore raw

Re: [PATCH 01/10] staging: fnic2 add initialization

In reply to Greg Kroah-Hartman
Quoted 5 lines · Greg Kroah-Hartman

Why is this a drivers/staging/ driver at all? What is keeping you from getting this merged into the "proper" place in the kernel?

If you have a staging driver, you have to have a TODO file in the directory listing what is keeping this in the staging section.

Sorry Greg, we do have a TODO file in the directory, but it was part of patch 10/10. I can move that to be part of patch 01/10.

We think that this driver is a drivers/staging driver because there are some changes we want to make before submitting the driver to the "proper" place. Specifically, we want to change how we allocate memory (move from a static allocation to a mempool scenario), which will require some other code changes. Also, we want to investigate if we need to change our locking schema. We think that making this driver part of the drivers/staging community will allow interested people to try the driver in its current state and offer up ideas as to its continued development.

If you think that this driver doesn't belong in the drivers/staging community, we are happy to explore getting the driver fully ready on our side and getting it into the "proper" place.

Quoted 2 lines

Please read the documentation on how to properly use SPDX tags on kernel files. This needs to be the first line of the file.

Thanks Greg, I fixed the SPDX tags and removed all the boilerplate, including the LICENSE file. Also, I have updated the MAINTAINERS file, which accidentally slipped by my first patch set. If you think that drivers/staging is a good temporary home for this driver, then I will send another patchset with the changes, as well as the changes from your other replies to patch 02/10 and patch 03/10.

Thanks for your help,

Oliver Smith-Denny

#4 lore raw

Re: [PATCH 01/10] staging: fnic2 add initialization

Quoted 9 lines · Oliver Smith-Denny
Quoted 5 lines · Greg Kroah-Hartman

Why is this a drivers/staging/ driver at all? What is keeping you from getting this merged into the "proper" place in the kernel?

If you have a staging driver, you have to have a TODO file in the directory listing what is keeping this in the staging section.

Sorry Greg, we do have a TODO file in the directory, but it was part of patch 10/10. I can move that to be part of patch 01/10.

Ah, I missed that, sorry.

Quoted 6 lines

We think that this driver is a drivers/staging driver because there are some changes we want to make before submitting the driver to the "proper" place. Specifically, we want to change how we allocate memory (move from a static allocation to a mempool scenario), which will require some other code changes.

Why not just take a week and do that? I can't take any new patches until 4.17-rc1 is out anyway.

Quoted 1 line

Also, we want to investigate if we need to change our locking schema.

Again, why not just take the time to do that?

Quoted 3 lines

We think that making this driver part of the drivers/staging community will allow interested people to try the driver in its current state and offer up ideas as to its continued development.

Have you asked the scsi developers what they think about this?

And why not copy the staging developer mailing list on this patch series?

Quoted 4 lines

If you think that this driver doesn't belong in the drivers/staging community, we are happy to explore getting the driver fully ready on our side and getting it into the "proper" place.

I'll take anything in staging as long as it has the correct license and builds, that's not an issue :) But I do want to get agreement from the SCSI maintainers that this is ok to have in this part of the kernel as sometimes it can cause merge issues if there are core api changes.

Quoted 10 lines
Quoted 2 lines

Please read the documentation on how to properly use SPDX tags on kernel files. This needs to be the first line of the file.

Thanks Greg, I fixed the SPDX tags and removed all the boilerplate, including the LICENSE file. Also, I have updated the MAINTAINERS file, which accidentally slipped by my first patch set. If you think that drivers/staging is a good temporary home for this driver, then I will send another patchset with the changes, as well as the changes from your other replies to patch 02/10 and patch 03/10.

A respin of this would be nice, and again, I can't do anything with it until 4.17-rc1 is out.

thanks,

greg k-h

#5 lore raw

Re: [PATCH 01/10] staging: fnic2 add initialization

Quoted 2 lines · Greg Kroah-Hartman

Why not just take a week and do that? I can't take any new patches until 4.17-rc1 is out anyway.

Thanks for your help in figuring out the best way forward for this driver. We will work to finish the TODOs on our end before 4.17-rc1 is out to see if we can have the driver in a finished state to submit directly to the SCSI maintainers. If staging still seems a viable option after 4.17-rc1 comes out, then I will resubmit the patch after talking with the SCSI developers.

Quoted 2 lines

And why not copy the staging developer mailing list on this patch series?

My bad, I missed that there was a staging developer mailing list. If we continue down the staging route, I will CC them.

Quoted 4 lines

I'll take anything in staging as long as it has the correct license and builds, that's not an issue :) But I do want to get agreement from the SCSI maintainers that this is ok to have in this part of the kernel as sometimes it can cause merge issues if there are core api changes.

Sounds good. Thanks again for all your help.

Oliver Smith-Denny

#6 lore raw

Re: [PATCH 01/10] staging: fnic2 add initialization

In reply to Greg Kroah-Hartman

Greg,

Quoted 8 lines
Quoted 3 lines

If you think that this driver doesn't belong in the drivers/staging community, we are happy to explore getting the driver fully ready on our side and getting it into the "proper" place.

I'll take anything in staging as long as it has the correct license and builds, that's not an issue :) But I do want to get agreement from the SCSI maintainers that this is ok to have in this part of the kernel as sometimes it can cause merge issues if there are core api changes.

This is the first I hear of fnic2.

My initial questions are: Why is a new driver necessary? Why can't the existing fnic driver be extended? And if it can't, what can be shared between the two drivers?

A good place to have that discussion would be on linux-scsi...

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#7 lore raw

Re: [PATCH 01/10] staging: fnic2 add initialization

Quoted 6 lines · Martin K. Petersen

My initial questions are: Why is a new driver necessary? Why can't the existing fnic driver be extended? And if it can't, what can be shared between the two drivers?

A good place to have that discussion would be on linux-scsi...

Hi Martin,

Thanks for taking some time to discuss fnic2. linux-scsi is CC'ed to this thread, for their input.

The main focus of the fnic2 driver is FCoE target mode support, NVMe over FC initiator & target drivers, and Multi-queue support. We think these changes need a new framework that we have developed in fnic2.

However, we do believe that a significant number of files and interfaces can be shared between the two drivers. Specifically, all interaction with the Cisco VNIC hardware can be shared. Also, there are some driver-specific queueing interfaces that can be shared between the drivers. This will allow us to share a significant number of files between fnic and fnic2. We are currently looking at how the common files can be shared, which was one of our TODOs for when we were looking at including this driver in the staging area.

Thanks,
Oliver Smith-Denny