Skip to contentSkip to conversation

bfa: Brocade BFA FC SCSI driver (bfad)

PATCH In review Krishna Gudipati 2 participants 3 messages Mar 24, 2009 – Mar 25, 2009

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

PATCH 1/5 bfa: Brocade BFA FC SCSI driver (bfad)

From: Krishna Chaitanya Gudipati <[email protected]>

This patch contains Brocade linux driver specific code that interfaces to upper layer linux kernel for PCI, SCSI mid-layer, sysfs related stuff. The code handles things such as module load/unload, PCI probe/release, handling interrupts, interfacing with sysfs etc. It interacts with the firmware/hardware via the code under files with prefix bfa_*.

---
 bfad.c           | 1339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 bfad_attr.c      |  660 +++++++++++++++++++++++++++
 bfad_attr.h      |   67 ++
 bfad_drv.h       |  359 ++++++++++++++
 bfad_fwimg.c     |   95 +++
 bfad_im.c        | 1325 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 bfad_im.h        |  205 ++++++++
 bfad_im_compat.h |   37 +
 bfad_intr.c      |  331 +++++++++++++
 bfad_ipfc.h      |   42 +
 bfad_os.c        |   56 ++
 bfad_tm.h        |   59 ++
 bfad_trcmod.h    |   52 ++
 13 files changed, 4627 insertions(+)
drivers/scsi/bfa/bfad.c +1339 -0
diff -urpN orig/drivers/scsi/bfa/bfad.c patch/drivers/scsi/bfa/bfad.c
@@ -0,0 +1,1339 @@
+/*
+ * Copyright (c)  2005-2008 Brocade Communications Systems, Inc.
+ * All rights reserved
+ * www.brocade.com
+ *
+ * Linux driver for Brocade Fibre Channel Host Bus Adapter.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License (GPL) Version 2 as
+ * published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+/**
+ *  bfad.c Linux driver PCI interface module.
+ */
+
+#include <linux/module.h>
+#include "bfad_drv.h"
+#include "bfad_im.h"
+#include "bfad_tm.h"
+#include "bfad_ipfc.h"
+#include "bfad_trcmod.h"
+#include <bfa_rport.h>
+
+BFA_TRC_FILE(LDRV, BFAD);
+
+static bfa_status_t bfad_fc4_port_new(struct bfad_s *bfad,
+				struct bfad_port_s *port, int roles);
+static void bfad_fc4_port_delete(struct bfad_s *bfad,
+				struct bfad_port_s *port, int roles);
+
+struct semaphore bfad_sem;
+int bfad_scan_done;
+
+LIST_HEAD(bfad_list);
+
+static	int	bfad_inst;
+int             supported_fc4s;
+
+char 		*host_name;
+char 		*os_name;
+char 		*os_patch;
+int		num_rports;
+int		num_ios;
+int		num_tms;
+int		num_fcxps;
+int		num_ufbufs;
+int		reqq_size;
+int		rspq_size;
+int		num_sgpgs;
+int		rport_del_timeout = BFA_RPORT_DEF_DEL_TIMEOUT;
+int             bfa_lun_queue_depth = BFAD_LUN_QUEUE_DEPTH;
+int             bfa_io_max_sge = BFAD_IO_MAX_SGE;
+int		log_level = BFA_LOG_WARNING;
+int		ioc_auto_recover = BFA_TRUE;
+int		ipfc_enable = BFA_FALSE;
+int		ipfc_mtu = -1;
+int             linkup_delay = 30;
+
+void
+bfad_flags_set(struct bfad_s *bfad, u32 flags)
+{
+	if (bfad)
+		bfad->bfad_flags |= flags;
+}
+
+/**
+ *  BFA callbacks
+ */
+void
+bfad_hcb_comp(void *arg, bfa_status_t status)
+{
+	struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg;
+
+	fcomp->status = status;
+	complete(&fcomp->comp);
+}
+
+/**
+ * bfa_init callback
+ */
+void
+bfa_cb_init(void *drv, bfa_status_t init_status)
+{
+	struct bfad_s         *bfad = drv;
+
+	if (init_status == BFA_STATUS_OK)
+		bfad->bfad_flags |= BFAD_HAL_INIT_DONE;
+
+	complete(&bfad->comp);
+}
+
+/**
+ * bfa_stop callback
+ */
+void
+bfa_cb_stop(void *drv, bfa_status_t stop_status)
+{
+	struct bfad_s         *bfad = drv;
+
+	/* Signal the BFAD stop waiting thread */
+	complete(&bfad->comp);
+}
+
+/**
+ * bfa_ioc_diable() callback.
+ */
+void
+bfa_cb_ioc_disable(void *drv)
+{
+	struct bfad_s         *bfad = drv;
+
+	complete(&bfad->disable_comp);
+}
+
+void
+bfa_cb_exit(struct bfad_s *drv)
+{
+	complete(&drv->comp);
+}
+
+void
+bfa_cb_rport_qos_scn_flowid(void *rport,
+			struct bfa_rport_qos_attr_s old_qos_attr,
+			struct bfa_rport_qos_attr_s new_qos_attr)
+{
+}
+void
+bfa_cb_rport_online(void *rport)
+{
+}
+void
+bfa_cb_rport_offline(void *rport)
+{
+}
+void
+bfa_cb_rport_qos_scn_prio(void *rport,
+			struct bfa_rport_qos_attr_s old_qos_attr,
+			struct bfa_rport_qos_attr_s new_qos_attr)
+{
+}
+
+void
+bfa_cb_itnim_sler(void *itnim)
+{
+}
+
+
+/**
+ *  bfa callbacks
+ */
+static struct bfad_port_s *
+bfad_get_drv_port(struct bfad_s *bfad, struct bfad_vf_s *vf_drv,
+			struct bfad_vport_s *vp_drv)
+{
+	return ((vp_drv) ? (&(vp_drv)->drv_port)
+		: ((vf_drv) ? (&(vf_drv)->base_port) : (&(bfad)->pport)));
+}
+
+struct bfad_port_s *
+bfa_cb_port_new(struct bfad_s *bfad, struct bfa_lport_s *port,
+			enum bfa_port_role roles, struct bfad_vf_s *vf_drv,
+			struct bfad_vport_s *vp_drv)
+{
+	bfa_status_t    rc;
+	struct bfad_port_s    *port_drv;
+
+	if (!vp_drv && !vf_drv) {
+		port_drv = &bfad->pport;
+		port_drv->pvb_type = BFAD_PORT_PHYS_BASE;
+	} else if (!vp_drv && vf_drv) {
+		port_drv = &vf_drv->base_port;
+		port_drv->pvb_type = BFAD_PORT_VF_BASE;
+	} else if (vp_drv && !vf_drv) {
+		port_drv = &vp_drv->drv_port;
+		port_drv->pvb_type = BFAD_PORT_PHYS_VPORT;
+	} else {
+		port_drv = &vp_drv->drv_port;
+		port_drv->pvb_type = BFAD_PORT_VF_VPORT;
+	}
+	port_drv->bfa_lport = port;
+	port_drv->roles = roles;
+	rc = bfad_fc4_port_new(bfad, port_drv, roles);
+	if (rc != BFA_STATUS_OK) {
+		bfad_fc4_port_delete(bfad, port_drv, roles);
+		port_drv = NULL;
+	}
+
+	return port_drv;
+}
+
+void
+bfa_cb_lport_delete(struct bfad_s *bfad, enum bfa_port_role roles,
+			struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
+{
+	struct bfad_port_s    *port_drv;
+
+	/* this will be only called from rmmod context */
+	if (vp_drv && !vp_drv->comp_del) {
+		port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
+		bfa_trc(bfad, roles);
+		bfad_fc4_port_delete(bfad, port_drv, roles);
+	}
+}
+
+void
+bfa_cb_lport_online(struct bfad_s *bfad, enum bfa_port_role roles,
+			struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
+{
+	struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
+
+	if (roles & BFA_PORT_ROLE_FCP_IM)
+		bfad_im_port_online(bfad, port_drv);
+
+	if (roles & BFA_PORT_ROLE_FCP_TM)
+		bfad_tm_port_online(bfad, port_drv);
+
+	if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
+		bfad_ipfc_port_online(bfad, port_drv);
+
+	bfad_flags_set(bfad, BFAD_PORT_ONLINE);
+}
+
+void
+bfa_cb_lport_offline(struct bfad_s *bfad, enum bfa_port_role roles,
+			struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv)
+{
+	struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv);
+
+	if (roles & BFA_PORT_ROLE_FCP_IM)
+		bfad_im_port_offline(bfad, port_drv);
+
+	if (roles & BFA_PORT_ROLE_FCP_TM)
+		bfad_tm_port_offline(bfad, port_drv);
+
+	if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
+		bfad_ipfc_port_offline(bfad, port_drv);
+}
+
+void
+bfa_cb_vf_stop(struct bfad_vf_s *vf_drv)
+{
+}
+
+void
+bfa_cb_vport_delete(struct bfad_vport_s *vport_drv)
+{
+	bfa_trc(vport_drv->drv_port.bfad, (int)vport_drv->comp_del);
+	if (vport_drv->comp_del) {
+		complete(vport_drv->comp_del);
+		return;
+	}
+
+	kfree(vport_drv);
+}
+
+/**
+ * FCS RPORT alloc callback, after successful PLOGI by FCS
+ */
+bfa_status_t
+bfa_cb_rport_alloc(struct bfad_s *bfad, struct bfa_rport_s *rport,
+		    struct bfad_rport_s **rport_drv)
+{
+	bfa_status_t    rc = BFA_STATUS_OK;
+
+	*rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC);
+	if (*rport_drv == NULL) {
+		rc = BFA_STATUS_ENOMEM;
+		goto ext;
+	}
+	(*rport_drv)->rport = rport;
+ext:
+	return rc;
+}
+
+/**
+ * FCS RPORT free callback.
+ */
+void
+bfa_cb_rport_free(struct bfad_s *bfad, struct bfad_rport_s **rport_drv)
+{
+	kfree(*rport_drv);
+}
+
+
+
+void
+bfad_hal_mem_release(struct bfad_s *bfad)
+{
+	int             i;
+	struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
+	struct bfa_mem_elem_s *meminfo_elem;
+
+	for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
+		meminfo_elem = &hal_meminfo->meminfo[i];
+		if (meminfo_elem->kva != NULL) {
+			switch (meminfo_elem->mem_type) {
+			case BFA_MEM_TYPE_KVA:
+				vfree(meminfo_elem->kva);
+				break;
+			case BFA_MEM_TYPE_DMA:
+				bfad_os_dma_free(bfad, meminfo_elem);
+				break;
+			default:
+				bfa_assert(0);
+				break;
+			}
+		}
+	}
+
+	memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s));
+}
+
+void
+bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg)
+{
+	if (num_rports > 0)
+		bfa_cfg->fwcfg.num_rports = num_rports;
+	if (num_ios > 0)
+		bfa_cfg->fwcfg.num_ioim_reqs = num_ios;
+	if (num_tms > 0)
+		bfa_cfg->fwcfg.num_tskim_reqs = num_tms;
+	if (num_fcxps > 0)
+		bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps;
+	if (num_ufbufs > 0)
+		bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs;
+	if (reqq_size > 0)
+		bfa_cfg->drvcfg.num_reqq_elems = reqq_size;
+	if (rspq_size > 0)
+		bfa_cfg->drvcfg.num_rspq_elems = rspq_size;
+	if (num_sgpgs > 0)
+		bfa_cfg->drvcfg.num_sgpgs = num_sgpgs;
+	/* TODO read role from config file FCS_BRINGUP*/
+	bfa_cfg->drvcfg.bport_role = BFA_PORT_ROLE_FCP_IM;
+
+}
+
+bfa_status_t
+bfad_hal_mem_alloc(struct bfad_s *bfad)
+{
+	int             i;
+	struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo;
+	struct bfa_mem_elem_s *meminfo_elem;
+	dma_addr_t      phys_addr;
+	void           *kva;
+	bfa_status_t    rc = BFA_STATUS_OK;
+
+	bfa_cfg_get_default(&bfad->ioc_cfg);
+	bfad_update_hal_cfg(&bfad->ioc_cfg);
+	bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs ;
+	bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo);
+
+	for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
+		meminfo_elem = &hal_meminfo->meminfo[i];
+		switch (meminfo_elem->mem_type) {
+		case BFA_MEM_TYPE_KVA:
+			kva = vmalloc(meminfo_elem->mem_len);
+			if (kva == NULL) {
+				bfad_hal_mem_release(bfad);
+				rc = BFA_STATUS_ENOMEM;
+				goto ext;
+			}
+			memset(kva, 0, meminfo_elem->mem_len);
+			meminfo_elem->kva = kva;
+			break;
+		case BFA_MEM_TYPE_DMA:
+			kva = bfad_os_dma_alloc(bfad, meminfo_elem, &phys_addr);
+			if (kva == NULL) {
+				bfad_hal_mem_release(bfad);
+				rc = BFA_STATUS_ENOMEM;
+				goto ext;
+			}
+			memset(kva, 0, meminfo_elem->mem_len);
+			meminfo_elem->kva = kva;
+			meminfo_elem->dma = phys_addr;
+			break;
+		default:
+			break;
+
+		}
+	}
+ext:
+	return rc;
+}
+
+struct bfad_s *
+bfad_find_bfad_by_inst_no(int inst_no)
+{
+	struct bfad_s         *bfad = NULL, *rc = NULL;
+
+	down(&bfad_sem);
+	list_for_each_entry(bfad, &bfad_list, list_entry) {
+		if (bfad->inst_no == inst_no) {
+			rc = bfad;
+			break;
+		}
+	}
+	up(&bfad_sem);
+	return rc;
+}
+
+bfa_status_t
+bfad_fc4_probe(struct bfad_s *bfad)
+{
+	int             rc;
+
+	rc = bfad_im_probe(bfad);
+	if (rc != BFA_STATUS_OK)
+		goto ext;
+
+	bfad_tm_probe(bfad);
+
+	if (ipfc_enable)
+		bfad_ipfc_probe(bfad);
+ext:
+	return rc;
+}
+
+void
+bfad_fc4_probe_undo(struct bfad_s *bfad)
+{
+	bfad_im_probe_undo(bfad);
+	bfad_tm_probe_undo(bfad);
+	if (ipfc_enable)
+		bfad_ipfc_probe_undo(bfad);
+}
+
+static void
+bfad_fc4_probe_post(struct bfad_s *bfad)
+{
+	if (bfad->im)
+		bfad_im_probe_post(bfad->im);
+
+	bfad_tm_probe_post(bfad);
+	if (ipfc_enable)
+		bfad_ipfc_probe_post(bfad);
+}
+
+static bfa_status_t
+bfad_fc4_port_new(struct bfad_s *bfad, struct bfad_port_s *port, int roles)
+{
+	int             rc = BFA_STATUS_FAILED;
+
+	if (roles & BFA_PORT_ROLE_FCP_IM)
+		rc = bfad_im_port_new(bfad, port);
+	if (rc != BFA_STATUS_OK)
+		goto ext;
+
+	if (roles & BFA_PORT_ROLE_FCP_TM)
+		rc = bfad_tm_port_new(bfad, port);
+	if (rc != BFA_STATUS_OK)
+		goto ext;
+
+	if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
+		rc = bfad_ipfc_port_new(bfad, port, port->pvb_type);
+ext:
+	return rc;
+}
+
+static void
+bfad_fc4_port_delete(struct bfad_s *bfad, struct bfad_port_s *port, int roles)
+{
+	if (roles & BFA_PORT_ROLE_FCP_IM)
+		bfad_im_port_delete(bfad, port);
+
+	if (roles & BFA_PORT_ROLE_FCP_TM)
+		bfad_tm_port_delete(bfad, port);
+
+	if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable)
+		bfad_ipfc_port_delete(bfad, port);
+}
+
+/**
+ * Create a vport under a vf.
+ */
+bfa_status_t
+bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
+			struct bfa_port_cfg_s *port_cfg)
+{
+	struct bfad_vport_s   *vport;
+	int             rc = BFA_STATUS_OK;
+	unsigned long   flags;
+
+	vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL);
+	if (!vport) {
+		rc = BFA_STATUS_ENOMEM;
+		goto ext;
+	}
+
+	vport->drv_port.bfad = bfad;
+	spin_lock_irqsave(&bfad->bfad_lock, flags);
+	rc = bfa_vport_create(&vport->bfa_vport, &bfad->bfa, vf_id,
+				  port_cfg, vport);
+	bfa_trc(bfad, rc);
+	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+
+	if (rc != BFA_STATUS_OK)
+		goto ext_free_vport;
+
+	if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) {
+		rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port);
+		if (rc != BFA_STATUS_OK)
+			goto ext_free_fcs_vport;
+	}
+	bfa_trc(bfad, port_cfg->roles);
+
+	spin_lock_irqsave(&bfad->bfad_lock, flags);
+	bfa_vport_start(&vport->bfa_vport);
+	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+
+	bfa_trc(bfad, BFA_STATUS_OK);
+	return BFA_STATUS_OK;
+
+ext_free_fcs_vport:
+ext_free_vport:
+	kfree(vport);
+ext:
+	bfa_trc(bfad, rc);
+	return rc;
+}
+
+/**
+ * Create a vf and its base vport implicitely.
+ */
+bfa_status_t
+bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
+			struct bfa_port_cfg_s *port_cfg)
+{
+	struct bfad_vf_s      *vf;
+	int             rc = BFA_STATUS_OK;
+
+	vf = kzalloc(sizeof(struct bfad_vf_s), GFP_KERNEL);
+	if (!vf) {
+		rc = BFA_STATUS_FAILED;
+		goto ext;
+	}
+
+	rc = bfa_vf_create(&vf->bfa_vf, &bfad->bfa, vf_id, port_cfg,
+			       vf);
+	if (rc != BFA_STATUS_OK)
+		kfree(vf);
+ext:
+	return rc;
+}
+
+void
+bfad_bfa_tmo(unsigned long data)
+{
+	struct bfad_s         *bfad = (struct bfad_s *) data;
+	unsigned long   flags;
+	struct list_head         doneq;
+
+	spin_lock_irqsave(&bfad->bfad_lock, flags);
+	bfa_timer_tick(&bfad->bfa);
+	bfa_comp_deq(&bfad->bfa, &doneq);
+	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+
+	if (!list_empty(&doneq)) {
+		bfa_comp_process(&bfad->bfa, &doneq);
+		spin_lock_irqsave(&bfad->bfad_lock, flags);
+		bfa_comp_free(&bfad->bfa, &doneq);
+		spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+	}
+
+	mod_timer(&bfad->hal_tmo,
+		  jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
+}
+
+void
+bfad_init_timer(struct bfad_s *bfad)
+{
+	init_timer(&bfad->hal_tmo);
+	bfad->hal_tmo.function = bfad_bfa_tmo;
+	bfad->hal_tmo.data = (unsigned long)bfad;
+
+	mod_timer(&bfad->hal_tmo,
+		  jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
+}
+
+int
+bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
+{
+	unsigned long   bar0_len;
+	int             rc = -ENODEV;
+
+	if (pci_enable_device(pdev)) {
+		BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n", pdev);
+		goto out;
+	}
+
+	if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
+		goto out_disable_device;
+
+	pci_set_master(pdev);
+
+
+	if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) != 0)
+		if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
+			BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail %p\n", pdev);
+			goto out_release_region;
+		}
+#ifdef SUPPORT_PCI_AER
+	/*
+	 * Enable PCIE Advanced Error Recovery (AER) if the kernel version
+	 * supports.
+	 */
+	BFAD_ENABLE_PCIE_AER(pdev);
+#endif
+
+	bfad->pci_bar0_map = pci_resource_start(pdev, 0);
+	bar0_len = pci_resource_len(pdev, 0);
+	bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);
+
+	if (bfad->pci_bar0_kva == NULL) {
+		BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
+		goto out_release_region;
+	}
+
+	bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
+	bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
+	bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
+	bfad->hal_pcidev.device_id = pdev->device;
+	bfad->pci_name = pci_name(pdev);
+
+	bfad->pci_attr.vendor_id = pdev->vendor;
+	bfad->pci_attr.device_id = pdev->device;
+	bfad->pci_attr.ssid = pdev->subsystem_device;
+	bfad->pci_attr.ssvid = pdev->subsystem_vendor;
+	bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
+
+	bfad->pcidev = pdev;
+	return 0;
+
+out_release_region:
+	pci_release_regions(pdev);
+out_disable_device:
+	pci_disable_device(pdev);
+out:
+	return rc;
+}
+
+void
+bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
+{
+	pci_release_regions(pdev);
+	pci_disable_device(pdev);
+	pci_set_drvdata(pdev, NULL);
+}
+
+void
+bfad_fcs_port_cfg(struct bfad_s *bfad)
+{
+	struct bfa_port_cfg_s  port_cfg;
+	struct bfa_pport_attr_s attr;
+	char            symname[BFA_SYMNAME_MAXLEN];
+
+	sprintf(symname, "%s-%d", BFAD_DRIVER_NAME, bfad->inst_no);
+	memcpy(port_cfg.sym_name.symname, symname, strlen(symname));
+	bfa_pport_get_attr(&bfad->bfa, &attr);
+	port_cfg.nwwn = attr.nwwn;
+	port_cfg.pwwn = attr.pwwn;
+
+	//bfa_cfg_base_port(&bfad->bfa, &port_cfg);TODO
+}
+
+bfa_status_t
+bfad_drv_init(struct bfad_s *bfad)
+{
+	bfa_status_t    rc;
+	struct bfa_driver_info_s driver_info;
+
+	bfad->cfg_data.rport_del_timeout = rport_del_timeout;
+	bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth;
+	bfad->cfg_data.io_max_sge = bfa_io_max_sge;
+	bfad->cfg_data.binding_method = FCP_PWWN_BINDING;
+
+	rc = bfad_hal_mem_alloc(bfad);
+	if (rc != BFA_STATUS_OK) {
+		printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n",
+				bfad->inst_no);
+		goto out_hal_mem_alloc_failure;
+	}
+
+	bfa_init_log(&bfad->bfa, bfad->logmod);
+	bfa_init_trc(&bfad->bfa, bfad->trcmod);
+	bfa_init_aen(&bfad->bfa, bfad->aen);
+	bfa_init_plog(&bfad->bfa, &bfad->plog_buf);
+	bfa_plog_init(&bfad->plog_buf);
+	bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START,
+		     0, "Driver Attach");
+
+	bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo,
+		       &bfad->hal_pcidev);
+
+	init_completion(&bfad->comp);
+	bfa_init(&bfad->bfa);
+	bfa_driver_info_init(&bfad->bfa, &driver_info);
+
+	bfad_init_timer(bfad);
+	bfa_isr_enable(&bfad->bfa);
+
+	/* Enable Interrupt and wait bfa_init completion */
+	if (bfad_setup_intr(bfad)) {
+		printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n",
+			bfad->inst_no);
+		goto out_setup_intr_failure;
+	}
+	wait_for_completion(&bfad->comp);
+
+	memset(&driver_info, 0, sizeof(driver_info));
+	strncpy(driver_info.version, BFAD_DRIVER_VERSION,
+				sizeof(driver_info.version) - 1);
+	if (host_name)
+		strncpy(driver_info.host_machine_name, host_name,
+				sizeof(driver_info.host_machine_name) - 1);
+	if (os_name)
+		strncpy(driver_info.host_os_name, os_name,
+				sizeof(driver_info.host_os_name) - 1);
+	if (os_patch)
+		strncpy(driver_info.host_os_patch, os_patch,
+				sizeof(driver_info.host_os_patch) - 1);
+
+	strncpy(driver_info.os_device_name, bfad->pci_name,
+				sizeof(driver_info.os_device_name - 1));
+
+
+	bfad->bfad_flags |= BFAD_DRV_INIT_DONE;
+	return BFA_STATUS_OK;
+
+out_setup_intr_failure:
+	del_timer_sync(&bfad->hal_tmo);
+	bfa_detach(&bfad->bfa);
+	bfad_hal_mem_release(bfad);
+out_hal_mem_alloc_failure:
+	return BFA_STATUS_FAILED;
+}
+
+void
+bfad_drv_uninit(struct bfad_s *bfad)
+{
+	bfad_remove_intr(bfad);
+	del_timer_sync(&bfad->hal_tmo);
+	bfa_detach(&bfad->bfa);
+	bfad_hal_mem_release(bfad);
+}
+
+void
+bfad_drv_start(struct bfad_s *bfad)
+{
+	unsigned long   flags;
+
+	spin_lock_irqsave(&bfad->bfad_lock, flags);
+	bfa_start(&bfad->bfa);
+	bfad->bfad_flags |= BFAD_HAL_START_DONE;
+	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+
+	bfad_fc4_probe_post(bfad);
+}
+
+void
+bfad_drv_stop(struct bfad_s *bfad)
+{
+	unsigned long   flags;
+
+	spin_lock_irqsave(&bfad->bfad_lock, flags);
+	init_completion(&bfad->comp);
+	bfad->pport.flags |= BFAD_PORT_DELETE;
+	bfa_stop(&bfad->bfa);
+	bfad->bfad_flags &= ~BFAD_HAL_START_DONE;
+	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+	wait_for_completion(&bfad->comp);
+}
+
+bfa_status_t
+bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role)
+{
+	int             rc = BFA_STATUS_OK;
+
+	/* Allocate scsi_host for the physical port */
+	if ((supported_fc4s & BFA_PORT_ROLE_FCP_IM)
+	    && (role & BFA_PORT_ROLE_FCP_IM)) {
+		if (bfad->pport.im_port == NULL) {
+			rc = BFA_STATUS_FAILED;
+			goto out;
+		}
+
+		rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port);
+		if (rc != BFA_STATUS_OK)
+			goto out;
+
+		bfad->pport.roles |= BFA_PORT_ROLE_FCP_IM;
+	}
+
+	bfad->bfad_flags |= BFAD_CFG_PPORT_DONE;
+
+out:
+	return rc;
+}
+
+void
+bfad_uncfg_pport(struct bfad_s *bfad)
+{
+
+	if ((bfad->pport.roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) {
+		bfad_ipfc_port_delete(bfad, &bfad->pport);
+		bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IPFC;
+	}
+
+	if ((supported_fc4s & BFA_PORT_ROLE_FCP_IM)
+	    && (bfad->pport.roles & BFA_PORT_ROLE_FCP_IM)) {
+		bfad_im_scsi_host_free(bfad, bfad->pport.im_port);
+		bfad_im_port_clean(bfad->pport.im_port);
+		kfree(bfad->pport.im_port);
+		bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IM;
+	}
+
+	bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE;
+}
+
+void bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
+{
+}
+void bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
+{
+}
+void bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
+{
+}
+void bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
+{
+}
+
+void
+bfad_drv_log_level_set(struct bfad_s *bfad)
+{
+	if (log_level > BFA_LOG_INVALID && log_level <= BFA_LOG_LEVEL_MAX)
+		bfa_log_set_level_all(&bfad->log_data, log_level);
+}
+
+ /*
+  *  PCI_entry PCI driver entries * {
+  */
+
+/**
+ * PCI probe entry.
+ */
+int
+bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid)
+{
+	struct bfad_s   *bfad;
+	int             error = -ENODEV, retval;
+	char            buf[16];
+
+	/* For single port cards - only claim function 0 */
+	if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P)
+	    && (PCI_FUNC(pdev->devfn) != 0))
+		return -ENODEV;
+
+	/* FCS_BRINGUP*/
+	if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G2P)
+	    && (PCI_FUNC(pdev->devfn) != 0))
+		return -ENODEV;
+
+	BFA_TRACE(BFA_INFO, "bfad_pci_probe entry");
+
+	bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL);
+	if (!bfad) {
+		error = -ENOMEM;
+		goto out;
+	}
+
+	bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL);
+	if (!bfad->trcmod) {
+		printk(KERN_WARNING "Error alloc trace buffer!\n");
+		error = -ENOMEM;
+		goto out_alloc_trace_failure;
+	}
+
+	/* LOG/TRACE INIT */
+	bfa_trc_init(bfad->trcmod);
+	bfa_trc(bfad, bfad_inst);
+
+	bfad->logmod = &bfad->log_data;
+	sprintf(buf, "%d", bfad_inst);
+	bfa_log_init(bfad->logmod, buf, bfa_os_printf);
+
+	bfad_drv_log_level_set(bfad);
+
+	bfad->aen = &bfad->aen_buf;
+
+	if (!(bfad_load_fwimg(pdev))) {
+		kfree(bfad->trcmod);
+		goto out_alloc_trace_failure;
+	}
+
+	retval = bfad_pci_init(pdev, bfad);
+	if (retval) {
+		printk(KERN_WARNING "bfad_pci_init failure!\n");
+		error = retval;
+		goto out_pci_init_failure;
+	}
+
+	down(&bfad_sem);
+	bfad->inst_no = bfad_inst++;
+	list_add_tail(&bfad_list, &bfad->list_entry);
+	up(&bfad_sem);
+
+	spin_lock_init(&bfad->bfad_lock);
+	pci_set_drvdata(pdev, bfad);
+
+	bfad->ref_count = 0;
+	bfad->pport.bfad = bfad;
+
+
+	retval = bfad_drv_init(bfad);
+	if (retval != BFA_STATUS_OK)
+		goto out_drv_init_failure;
+	if (!(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
+		printk(KERN_WARNING "bfad%d: hal init failed\n", bfad->inst_no);
+		goto ok;
+	}
+
+	retval = bfad_cfg_pport(bfad, BFA_PORT_ROLE_FCP_IM);
+	if (retval != BFA_STATUS_OK)
+		goto out_cfg_pport_failure;
+
+	/* BFAD level FC4 (IM/TM/IPFC) specific resource allocation */
+	retval = bfad_fc4_probe(bfad);
+	if (retval != BFA_STATUS_OK) {
+		printk(KERN_WARNING "bfad_fc4_probe failed\n");
+		goto out_fc4_probe_failure;
+	}
+
+	bfad_drv_start(bfad);
+	bfa_log(bfad->logmod, BFA_LOG_LINUX_DEVICE_CLAIMED, bfad->pci_name);
+ok:
+	return 0;
+
+out_fc4_probe_failure:
+	bfad_fc4_probe_undo(bfad);
+	bfad_uncfg_pport(bfad);
+out_cfg_pport_failure:
+	bfad_drv_uninit(bfad);
+out_drv_init_failure:
+	down(&bfad_sem);
+	bfad_inst--;
+	list_del(&bfad->list_entry);
+	up(&bfad_sem);
+	bfad_pci_uninit(pdev, bfad);
+out_pci_init_failure:
+	kfree(bfad->trcmod);
+out_alloc_trace_failure:
+	kfree(bfad);
+out:
+	return error;
+}
+
+/**
+ * PCI remove entry.
+ */
+void
+bfad_pci_remove(struct pci_dev *pdev)
+{
+	struct bfad_s         *bfad = pci_get_drvdata(pdev);
+	unsigned long   flags;
+
+	bfa_trc(bfad, bfad->inst_no);
+
+	if ((bfad->bfad_flags & BFAD_DRV_INIT_DONE)
+	    && !(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) {
+		bfad_remove_intr(bfad);
+		del_timer_sync(&bfad->hal_tmo);
+		goto hal_detach;
+	} else if (!(bfad->bfad_flags & BFAD_DRV_INIT_DONE)) {
+		goto remove_sysfs;
+	}
+
+	if (bfad->bfad_flags & BFAD_HAL_START_DONE)
+		bfad_drv_stop(bfad);
+
+	bfad_remove_intr(bfad);
+
+	del_timer_sync(&bfad->hal_tmo);
+	bfad_fc4_probe_undo(bfad);
+
+	if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE)
+		bfad_uncfg_pport(bfad);
+
+hal_detach:
+	spin_lock_irqsave(&bfad->bfad_lock, flags);
+	bfa_detach(&bfad->bfa);
+	spin_unlock_irqrestore(&bfad->bfad_lock, flags);
+	bfad_hal_mem_release(bfad);
+remove_sysfs:
+
+	down(&bfad_sem);
+	bfad_inst--;
+	list_del(&bfad->list_entry);
+	up(&bfad_sem);
+	bfad_pci_uninit(pdev, bfad);
+
+	kfree(bfad->trcmod);
+	kfree(bfad);
+}
+
+#define BFAD_MAX_PCIIDS	4
+struct pci_device_id bfad_id_table[BFAD_MAX_PCIIDS] = {
+	{
+	 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
+	 .device = BFA_PCI_DEVICE_ID_FC_8G2P,
+	 .subvendor = PCI_ANY_ID,
+	 .subdevice = PCI_ANY_ID,
+	 },
+	{
+	 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
+	 .device = BFA_PCI_DEVICE_ID_FC_8G1P,
+	 .subvendor = PCI_ANY_ID,
+	 .subdevice = PCI_ANY_ID,
+	 },
+	{
+	 .vendor = BFA_PCI_VENDOR_ID_BROCADE,
+	 .device = BFA_PCI_DEVICE_ID_CT,
+	 .subvendor = PCI_ANY_ID,
+	 .subdevice = PCI_ANY_ID,
+	 .class = (PCI_CLASS_SERIAL_FIBER << 8),
+	 .class_mask = ~0,
+	 },
+
+	{0, 0},
+};
+
+MODULE_DEVICE_TABLE(pci, bfad_id_table);
+
+/**
+ *  Linux driver module functions
+ */
+
+bfa_status_t
+bfad_fc4_module_init(void)
+{
+	int             rc;
+
+	rc = bfad_im_module_init();
+	if (rc != BFA_STATUS_OK)
+		goto ext;
+
+	bfad_tm_module_init();
+	if (ipfc_enable)
+		bfad_ipfc_module_init();
+ext:
+	return rc;
+}
+
+void
+bfad_fc4_module_exit(void)
+{
+	if (ipfc_enable)
+		bfad_ipfc_module_exit();
+	bfad_tm_module_exit();
+	bfad_im_module_exit();
+}
+
+/**
+ * Driver module init.
+ */
+static int __init
+bfad_init(void)
+{
+	int             error = 0;
+
+	printk(KERN_INFO "Brocade BFA FC SCSI driver - version: %s\n",
+	bfa_version);
+
+	error = bfad_fc4_module_init();
+	if (error) {
+		error = -ENOMEM;
+		printk(KERN_WARNING "bfad_fc4_module_init failure\n");
+		goto ext;
+	}
+
+	sema_init(&bfad_sem, 1);
+
+	if (!strcmp(FCPI_NAME, " fcpim"))
+		supported_fc4s |= BFA_PORT_ROLE_FCP_IM;
+	if (!strcmp(FCPT_NAME, " fcptm"))
+		supported_fc4s |= BFA_PORT_ROLE_FCP_TM;
+	if (!strcmp(IPFC_NAME, " ipfc"))
+		supported_fc4s |= BFA_PORT_ROLE_FCP_IPFC;
+
+	bfa_ioc_auto_recover(ioc_auto_recover);
+	bfa_rport_set_del_timeout(rport_del_timeout);
+	error = pci_register_driver(bfad_pci_driver_p);
+
+	down(&bfad_sem);
+	bfad_scan_done = 1;
+	up(&bfad_sem);
+
+	if (error) {
+		printk(KERN_WARNING "pci_register_driver failure\n");
+		goto ext;
+	}
+
+
+	return 0;
+
+ext:
+	bfad_fc4_module_exit();
+	return error;
+}
+
+/**
+ * Driver module exit.
+ */
+static void __exit
+bfad_exit(void)
+{
+	pci_unregister_driver(bfad_pci_driver_p);
+	bfad_fc4_module_exit();
+}
+
+#define BFAD_PROTO_NAME FCPI_NAME FCPT_NAME IPFC_NAME
+
+module_init(bfad_init);
+module_exit(bfad_exit);
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME);
+MODULE_AUTHOR("Brocade Communications Systems, Inc.");
+MODULE_VERSION(BFAD_DRIVER_VERSION);
+
+
+
+
+
+module_param(os_name, charp, S_IRUGO | S_IWUSR);
+module_param(os_patch, charp, S_IRUGO | S_IWUSR);
+module_param(host_name, charp, S_IRUGO | S_IWUSR);
+module_param(num_rports, int, S_IRUGO | S_IWUSR);
+module_param(num_ios, int, S_IRUGO | S_IWUSR);
+module_param(num_tms, int, S_IRUGO | S_IWUSR);
+module_param(num_fcxps, int, S_IRUGO | S_IWUSR);
+module_param(num_ufbufs, int, S_IRUGO | S_IWUSR);
+module_param(reqq_size, int, S_IRUGO | S_IWUSR);
+module_param(rspq_size, int, S_IRUGO | S_IWUSR);
+module_param(num_sgpgs, int, S_IRUGO | S_IWUSR);
+module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR);
+module_param(msix_disable, int, S_IRUGO | S_IWUSR);
+module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR);
+module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR);
+module_param(log_level, int, S_IRUGO | S_IWUSR);
+module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR);
+module_param(ipfc_enable, int, S_IRUGO | S_IWUSR);
+module_param(ipfc_mtu, int, S_IRUGO | S_IWUSR);
+module_param(linkup_delay, int, S_IRUGO | S_IWUSR);
+
+#ifdef CONFIG_PM
+int             pci_save_state(struct pci_dev *pdev);
+int             pci_restore_state(struct pci_dev *pdev);
+#endif
+
+void *
+bfad_os_dma_alloc(struct bfad_s *bfad, struct bfa_mem_elem_s *meminfo_elem,
+		dma_addr_t      *phys_addr)
+{
+	return dma_alloc_coherent(&bfad->pcidev->dev,
+		meminfo_elem->mem_len,
+		phys_addr, GFP_KERNEL);
+}
+
+void
+bfad_os_dma_free(struct bfad_s *bfad, struct bfa_mem_elem_s *meminfo_elem)
+{
+	dma_free_coherent(&bfad->pcidev->dev,
+			meminfo_elem->mem_len,
+			meminfo_elem->kva,
+			(dma_addr_t) meminfo_elem->dma);
+}
+
+#ifdef CONFIG_PM
+/**
+ * PCI suspend entry.
+ */
+static int
+bfad_os_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+	struct bfad_s         *bfad = pci_get_drvdata(pdev);
+	pci_power_t     device_state;
+
+	device_state = pci_choose_state(pdev, state);
+
+	pci_save_state(pdev);
+	init_completion(&bfad->suspend);
+	wait_for_completion(&bfad->suspend);
+	pci_disable_device(pdev);
+	pci_set_power_state(pdev, device_state);
+
+	return 0;
+}
+
+/**
+ * PCI resume entry.
+ */
+static int
+bfad_os_resume(struct pci_dev *pdev)
+{
+
+	/* Resume the device power state to D0 */
+	pci_set_power_state(pdev, 0);
+
+	/* Restore all device PCI configuation space to its original state. */
+	pci_restore_state(pdev);
+
+	if (pci_enable_device(pdev))
+		goto out;
+
+	return 0;
+
+out:
+	return 1;
+
+}
+#endif
+
+#ifdef SUPPORT_PCI_AER
+/*
+ * PCI error recovery support, this fearure is only availbe for kernel
+ * .6.16 or later.
+ */
+/**
+ * PCI Error Recovery entry, error detected.
+ */
+static          pci_ers_result_t
+bfad_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
+{
+	struct bfad_s         *bfad = pci_get_drvdata(pdev);
+
+	switch (state) {
+	case pci_channel_io_perm_failure:
+		/*
+		 * PCI bus has permanently failed. This is
+		 * unrecoveralbe, Do we need to do the cleanup like PCI
+		 * remove? or kernel will automatically do it?
+		 */
+		return PCI_ERS_RESULT_DISCONNECT;
+
+	case pci_channel_io_frozen:
+
+	default:
+
+		init_completion(&bfad->comp);
+		bfa_stop(&bfad->bfa);
+		wait_for_completion_timeout(&bfad->comp, BFAD_STOP_TIMEOUT);
+
+		pci_disable_device(pdev);
+
+		break;
+	}
+
+	/*
+	 * Request a slot reset
+	 */
+	return PCI_ERS_RESULT_NEED_RESET;
+}
+
+/**
+ * PCI Error Recovery entry, re-initialize the chip.
+ */
+static          pci_ers_result_t
+bfad_pci_slot_reset(struct pci_dev *pdev)
+{
+	struct bfad_s         *bfad = pci_get_drvdata(pdev);
+	int             retval;
+
+	if (pci_enable_device(pdev))
+		goto out;
+
+	pci_set_master(pdev);
+
+	retval = pci_set_mwi(pdev);
+
+	if (retval)
+		dev_printk(KERN_WARNING, &pdev->dev,
+			   "Warning: pci_set_mwi returned %d\n", retval);
+
+	if (pci_set_dma_mask(bfad->pcidev, DMA_64BIT_MASK) != 0)
+		if (pci_set_dma_mask(bfad->pcidev, DMA_32BIT_MASK) != 0)
+			goto out_disable_device;
+
+	BFAD_ENABLE_PCIE_AER(pdev);
+
+	/* bfa should still keep all the BFAD and port config info */
+	bfa_start(&bfad->bfa);
+
+	return PCI_ERS_RESULT_RECOVERED;
+
+out_disable_device:
+	pci_disable_device(pdev);
+out:
+	return PCI_ERS_RESULT_DISCONNECT;
+
+}
+
+/*
+ * PCI error recovery support, this fearure is only available for kernel
+ * 2.6.16 or later. At this point, we only define error_detected and
+ * slot_reset.
+ */
+static struct pci_error_handlers bfad_err_handler = {
+	.error_detected = bfad_pci_error_detected,
+	.slot_reset = bfad_pci_slot_reset,
+};
+#endif
+
+static struct pci_driver bfad_pci_driver = {
+	.name = BFAD_DRIVER_NAME,
+	.id_table = bfad_id_table,
+	.probe = bfad_pci_probe,
+	.remove = __devexit_p(bfad_pci_remove),
+#ifdef CONFIG_PM
+	.suspend = bfad_os_suspend,
+	.resume = bfad_os_resume,
+#endif
+
+#ifdef SUPPORT_PCI_AER
+	/*
+	 * PCI error recovery support, this fearure is only available for
+	 * kernel 2.6.16 or later.
+	 */
+	.err_handler = &bfad_err_handler,
+#endif
+};
+
+struct pci_driver *bfad_pci_driver_p = &bfad_pci_driver;
+
+
drivers/scsi/bfa/bfad_attr.c +660 -0

660 lines not on this page · raw message

drivers/scsi/bfa/bfad_attr.h +67 -0

67 lines not on this page · raw message

drivers/scsi/bfa/bfad_drv.h +359 -0

359 lines not on this page · raw message

drivers/scsi/bfa/bfad_fwimg.c +95 -0

95 lines not on this page · raw message

drivers/scsi/bfa/bfad_im.c +1325 -0

480 lines not on this page · raw message

drivers/scsi/bfa/bfad_im.h +205 -0

205 lines not on this page · raw message

drivers/scsi/bfa/bfad_im_compat.h +37 -0
diff -urpN orig/drivers/scsi/bfa/bfad_im_compat.h patch/drivers/scsi/bfa/bfad_im_compat.h

Lines of this file are not shown. View the raw message.

drivers/scsi/bfa/bfad_intr.c +331 -0

331 lines not on this page · raw message

drivers/scsi/bfa/bfad_ipfc.h +42 -0

42 lines not on this page · raw message

drivers/scsi/bfa/bfad_os.c +56 -0

56 lines not on this page · raw message

drivers/scsi/bfa/bfad_tm.h +59 -0

59 lines not on this page · raw message

drivers/scsi/bfa/bfad_trcmod.h +52 -0

52 lines not on this page · raw message

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

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

#1 lore raw
Quoted 30 lines · Krishna Gudipati

From: Krishna Chaitanya Gudipati <[email protected]>

This patch contains Brocade linux driver specific code that interfaces to upper layer linux kernel for PCI, SCSI mid-layer, sysfs related stuff. The code handles things such as module load/unload, PCI probe/release, handling interrupts, interfacing with sysfs etc. It interacts with the firmware/hardware via the code under files with prefix bfa_*.

drivers/scsi/bfa/bfad.c +20 -0
+int
+bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
+{
+       unsigned long   bar0_len;
+       int             rc = -ENODEV;
+
+       if (pci_enable_device(pdev)) {
+               BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n", pdev);
+               goto out;
+       }
+
+       if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
+               goto out_disable_device;
+
+       pci_set_master(pdev);
+
+
+       if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) != 0)
+               if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
+                       BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail %p\n",
Quoted 2 lines

pdev); + goto out_release_region;
+ }

Save the return value of pci_set_dma_mask() to rc and use this as error code.

drivers/scsi/bfa/bfad.c line 617

Quoted 11 lines
drivers/scsi/bfa/bfad.c +11 -0
+#ifdef SUPPORT_PCI_AER
+       /*
+        * Enable PCIE Advanced Error Recovery (AER) if the kernel version
+        * supports.
+        */
+       BFAD_ENABLE_PCIE_AER(pdev);
+#endif
+
+       bfad->pci_bar0_map = pci_resource_start(pdev, 0);
+       bar0_len = pci_resource_len(pdev, 0);
+       bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);

bfad->pci_bar0_kva = pci_iomap(pdev, 0, 0);

Quoted 17 lines
drivers/scsi/bfa/bfad.c +17 -0
+       if (bfad->pci_bar0_kva == NULL) {
+               BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
+               goto out_release_region;
+       }
+
+       bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
+       bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
+       bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
+       bfad->hal_pcidev.device_id = pdev->device;
+       bfad->pci_name = pci_name(pdev);
+
+       bfad->pci_attr.vendor_id = pdev->vendor;
+       bfad->pci_attr.device_id = pdev->device;
+       bfad->pci_attr.ssid = pdev->subsystem_device;
+       bfad->pci_attr.ssvid = pdev->subsystem_vendor;
+       bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
+

drivers/scsi/bfa/bfad.c line 645

Quoted 10 lines
drivers/scsi/bfa/bfad.c +10 -0
+       bfad->pcidev = pdev;
+       return 0;
+
+out_release_region:
+       pci_release_regions(pdev);
+out_disable_device:
+       pci_disable_device(pdev);
+out:
+       return rc;
+}

What about using devres for your driver? (See Documentation/driver-model/devres.txt) This would take care of the release_regions and disable device in the error paths here and also in the remove handler.

drivers/scsi/bfa/bfad_intr.c line 28

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+/**
+ *  bfa_isr BFA driver interrupt functions
+ */
+irqreturn_t bfad_intx(int irq, void *dev_id);

This declaration isn't needed at all as the function follows directly after that.

Quoted 6 lines
drivers/scsi/bfa/bfad_intr.c +6 -0
+/**
+ * Line based interrupt handler.
+ */
+irqreturn_t
+bfad_intx(int irq, void *dev_id)
+{

[...]

drivers/scsi/bfa/bfad_intr.c line 202

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+static int
+bfad_install_msix_handler(struct bfad_s *bfad)
+{
+	int             i, error = 0;
           ^^^^^^^^^^^^^

One space.

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+	for (i = 0; i < bfad->nvec; i++) {
+		error = request_irq(bfad->msix_tab[i].msix.vector,
+				    bfad->msix_tab[i].handler, 0,
+				    BFAD_DRIVER_NAME, bfad);

drivers/scsi/bfa/bfad_intr.c line 217

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+		printk(KERN_WARNING "%s: bfad%d irq %d\n", __FUNCTION__,
+			 bfad->inst_no, bfad->msix_tab[i].msix.vector);
+
+		if (error) {
+			int             j;
+
+			for (j = 0; j < i; j++)
+				free_irq(bfad->msix_tab[j].msix.vector, bfad);
+
+			return 1;

"return error" would allow doint something useful with this value later (e.g. printing them in your warning) so one can actually see what went wrong.

Quoted 18 lines
drivers/scsi/bfa/bfad_intr.c +18 -0
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * Setup MSIX based interrupt.
+ */
+int
+bfad_setup_intr(struct bfad_s *bfad)
+{
+	int             error = 0;
+
+	if (!msix_disable) {
+		u32 mask = 0, i, num_bit = 0, max_bit = 0;
+		struct msix_entry msix_entries[MAX_MSIX_ENTRY];
+

drivers/scsi/bfa/bfad_intr.c line 245

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+		/* Call BFA to get the msix map for this PCI function.  */
+		bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit);
+
+		/* Set up the msix entry table */
+		bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
+
+		error = pci_enable_msix(bfad->pcidev, msix_entries, bfad->nvec);
+		if (error) {
+			/*
+			 * Only error number of vector is available.

"of vectors are"

drivers/scsi/bfa/bfad_intr.c line 256

Quoted 11 lines
drivers/scsi/bfa/bfad_intr.c +11 -0
+			 * We don't have a mechanism to map multiple
+			 * interrupts into one vector, so even if we
+			 * can try to request less vectors, we don't
+			 * know how to associate interrupt events to
+			 *  vectors. Linux doesn't dupicate vectors
+			 * in the MSIX table for this case.
+			 */
+
+			printk(KERN_WARNING
+				"%s: enable_msix failed, %d bfad%d\n",
+			       __FUNCTION__, error, bfad->inst_no);

Also the message should really be more descriptive, like "enable_msix for %i vectors failed, only %i vectors available". And if you use dev_warn() that function will add the correct device description for you (You should use it whereever possible).

__FUNCTION__ should not be used anymore, use __func__. Or remove it completely, it's rather obvious where this message actually comes from.

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+
+			goto line_based;
+		}
+

drivers/scsi/bfa/bfad_intr.c line 270

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+		/* Save the vectors */
+		for (i = 0; i < bfad->nvec; i++)
+			bfad->msix_tab[i].msix.vector = msix_entries[i].vector;
+
+		/* Set up interrupt handler for each vectors */
+		if (bfad_install_msix_handler(bfad)) {
+			printk(KERN_WARNING "%s: install_msix failed, bfad%d\n",
+			       __FUNCTION__, bfad->inst_no);
+			goto line_based;
+		}

This is just your choice, but when MSI was requested and the number of interrupts were reserved successfully and now installing the IRQ handler fails this should IMHO be an error and not a situation to fallback to line based. YMMV.

drivers/scsi/bfa/bfad_intr.c line 280

Quoted 9 lines
drivers/scsi/bfa/bfad_intr.c +9 -0
+		bfad->bfad_flags |= BFAD_MSIX_ON;
+
+		goto success;
+	}
+
+line_based:
+	error = 0;
+	if (request_irq
+	    (bfad->pcidev->irq, (irq_handler_t) bfad_intx, BFAD_IRQ_FLAGS,

Cast not needed, bfad_intx() should be of the correct signature.

Quoted 23 lines
drivers/scsi/bfa/bfad_intr.c +23 -0
+	     BFAD_DRIVER_NAME, bfad) != 0) {
+		/* Enable interrupt handler failed */
+		return 1;
+	}
+success:
+	return error;
+}
+
+void
+bfad_remove_intr(struct bfad_s *bfad)
+{
+	int             i;
+
+	if (bfad->bfad_flags & BFAD_MSIX_ON) {
+		for (i = 0; i < bfad->nvec; i++)
+			free_irq(bfad->msix_tab[i].msix.vector, bfad);
+
+		pci_disable_msix(bfad->pcidev);
+		bfad->bfad_flags &= ~BFAD_MSIX_ON;
+	} else {
+		free_irq(bfad->pcidev->irq, bfad);
+	}
+}

drivers/scsi/bfa/bfad_intr.c line 313

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+
+#else /* CONFIG_PCI_MSI */
+/**
+ * Setup line-based interrupt.
+ */
+int
+bfad_setup_intr(struct bfad_s *bfad)
+{
+	if (request_irq
+	    (bfad->pcidev->irq, (irq_handler_t) bfad_intx, SA_SHIRQ,

Same here.

Quoted 8 lines
drivers/scsi/bfa/bfad_intr.c +8 -0
+	     BFAD_DRIVER_NAME, bfad) != 0) {
+		/* Enable interrupt handler failed */
+		return 1;
+	}
+
+	return 0;
+}
+

drivers/scsi/bfa/bfad_intr.c line 331

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+void
+bfad_remove_intr(struct bfad_s *bfad)
+{
+	bfa_trc(bfad, bfad->pcidev->irq);
+	free_irq(bfad->pcidev->irq, bfad);
+}
+
+#endif /* CONFIG_PCI_MSI */
+
+

Remove trailing empty lines.

Greetings,

Eike

#2 lore raw

Thanks Eike for reviewing our code. We are considering all the changes suggested by you for our driver and we are going to incorporate most of the changes suggested in our next submission.

Thanks,
Krishna Chaitanya Gudipati.

-----Original Message-----
From: Rolf Eike Beer [mailto:[email protected]]
Sent: Tuesday, March 24, 2009 4:06 AM
To: Krishna Gudipati
Cc: [email protected]; Jing Huang; [email protected]; [email protected]; Ramkumar Vadivelu; Vinodh Ravindran
Subject: Re: [PATCH 1/5] bfa: Brocade BFA FC SCSI driver (bfad)

Quoted 3 lines · Krishna Gudipati

From: Krishna Chaitanya Gudipati <[email protected]>

This patch contains Brocade linux driver specific code that interfaces

to

Quoted 1 line

upper layer linux kernel for PCI, SCSI mid-layer, sysfs related stuff.

The

Quoted 1 line

code handles things such as module load/unload, PCI probe/release,

handling

drivers/scsi/bfa/bfad.c

Quoted 13 lines

interrupts, interfacing with sysfs etc. It interacts with the firmware/hardware via the code under files with prefix bfa_*.

drivers/scsi/bfa/bfad.c +8 -0
+int
+bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
+{
+       unsigned long   bar0_len;
+       int             rc = -ENODEV;
+
+       if (pci_enable_device(pdev)) {
+               BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n",

pdev);

drivers/scsi/bfa/bfad.c

Quoted 12 lines
drivers/scsi/bfa/bfad.c +12 -0
+               goto out;
+       }
+
+       if (pci_request_regions(pdev, BFAD_DRIVER_NAME))
+               goto out_disable_device;
+
+       pci_set_master(pdev);
+
+
+       if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) != 0)
+               if (pci_set_dma_mask(pdev, DMA_32BIT_MASK) != 0) {
+                       BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail

%p\n",

Quoted 2 lines

pdev); + goto out_release_region;
+ }

Save the return value of pci_set_dma_mask() to rc and use this as error code.

drivers/scsi/bfa/bfad.c

Quoted 3 lines
drivers/scsi/bfa/bfad.c +3 -0
+#ifdef SUPPORT_PCI_AER
+       /*
+        * Enable PCIE Advanced Error Recovery (AER) if the kernel

version

drivers/scsi/bfa/bfad.c line 617

Quoted 8 lines
drivers/scsi/bfa/bfad.c +8 -0
+        * supports.
+        */
+       BFAD_ENABLE_PCIE_AER(pdev);
+#endif
+
+       bfad->pci_bar0_map = pci_resource_start(pdev, 0);
+       bar0_len = pci_resource_len(pdev, 0);
+       bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);

bfad->pci_bar0_kva = pci_iomap(pdev, 0, 0);

Quoted 17 lines
drivers/scsi/bfa/bfad.c +17 -0
+       if (bfad->pci_bar0_kva == NULL) {
+               BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
+               goto out_release_region;
+       }
+
+       bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn);
+       bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn);
+       bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva;
+       bfad->hal_pcidev.device_id = pdev->device;
+       bfad->pci_name = pci_name(pdev);
+
+       bfad->pci_attr.vendor_id = pdev->vendor;
+       bfad->pci_attr.device_id = pdev->device;
+       bfad->pci_attr.ssid = pdev->subsystem_device;
+       bfad->pci_attr.ssvid = pdev->subsystem_vendor;
+       bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn);
+

drivers/scsi/bfa/bfad.c line 645

Quoted 10 lines
drivers/scsi/bfa/bfad.c +10 -0
+       bfad->pcidev = pdev;
+       return 0;
+
+out_release_region:
+       pci_release_regions(pdev);
+out_disable_device:
+       pci_disable_device(pdev);
+out:
+       return rc;
+}

What about using devres for your driver? (See Documentation/driver-model/devres.txt) This would take care of the release_regions and disable device in the error paths here and also in the
remove handler.

drivers/scsi/bfa/bfad_intr.c line 28

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+/**
+ *  bfa_isr BFA driver interrupt functions
+ */
+irqreturn_t bfad_intx(int irq, void *dev_id);

This declaration isn't needed at all as the function follows directly after
that.

Quoted 6 lines
drivers/scsi/bfa/bfad_intr.c +6 -0
+/**
+ * Line based interrupt handler.
+ */
+irqreturn_t
+bfad_intx(int irq, void *dev_id)
+{

[...]

drivers/scsi/bfa/bfad_intr.c line 202

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+static int
+bfad_install_msix_handler(struct bfad_s *bfad)
+{
+	int             i, error = 0;
           ^^^^^^^^^^^^^

One space.

drivers/scsi/bfa/bfad_intr.c

Quoted 12 lines
drivers/scsi/bfa/bfad_intr.c +12 -0
+	for (i = 0; i < bfad->nvec; i++) {
+		error = request_irq(bfad->msix_tab[i].msix.vector,
+				    bfad->msix_tab[i].handler, 0,
+				    BFAD_DRIVER_NAME, bfad);
+		printk(KERN_WARNING "%s: bfad%d irq %d\n", __FUNCTION__,
+			 bfad->inst_no, bfad->msix_tab[i].msix.vector);
+
+		if (error) {
+			int             j;
+
+			for (j = 0; j < i; j++)
+				free_irq(bfad->msix_tab[j].msix.vector,

bfad);

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+			return 1;

"return error" would allow doint something useful with this value later (e.g.
printing them in your warning) so one can actually see what went wrong.

Quoted 9 lines
drivers/scsi/bfa/bfad_intr.c +9 -0
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * Setup MSIX based interrupt.
+ */

drivers/scsi/bfa/bfad_intr.c

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+int
+bfad_setup_intr(struct bfad_s *bfad)
+{
+	int             error = 0;
+
+	if (!msix_disable) {
+		u32 mask = 0, i, num_bit = 0, max_bit = 0;
+		struct msix_entry msix_entries[MAX_MSIX_ENTRY];
+
+		/* Call BFA to get the msix map for this PCI function.

*/

drivers/scsi/bfa/bfad_intr.c

Quoted 6 lines
drivers/scsi/bfa/bfad_intr.c +6 -0
+		bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit);
+
+		/* Set up the msix entry table */
+		bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
+
+		error = pci_enable_msix(bfad->pcidev, msix_entries,

bfad->nvec);

drivers/scsi/bfa/bfad_intr.c line 245

Quoted 3 lines
drivers/scsi/bfa/bfad_intr.c +3 -0
+		if (error) {
+			/*
+			 * Only error number of vector is available.

"of vectors are"

drivers/scsi/bfa/bfad_intr.c line 256

Quoted 11 lines
drivers/scsi/bfa/bfad_intr.c +11 -0
+			 * We don't have a mechanism to map multiple
+			 * interrupts into one vector, so even if we
+			 * can try to request less vectors, we don't
+			 * know how to associate interrupt events to
+			 *  vectors. Linux doesn't dupicate vectors
+			 * in the MSIX table for this case.
+			 */
+
+			printk(KERN_WARNING
+				"%s: enable_msix failed, %d bfad%d\n",
+			       __FUNCTION__, error, bfad->inst_no);

Also the message should really be more descriptive, like "enable_msix for %i
vectors failed, only %i vectors available". And if you use dev_warn() that
function will add the correct device description for you (You should use it
whereever possible).

__FUNCTION__ should not be used anymore, use __func__. Or remove it completely, it's rather obvious where this message actually comes from.

drivers/scsi/bfa/bfad_intr.c

Quoted 7 lines
drivers/scsi/bfa/bfad_intr.c +7 -0
+
+			goto line_based;
+		}
+
+		/* Save the vectors */
+		for (i = 0; i < bfad->nvec; i++)
+			bfad->msix_tab[i].msix.vector =

msix_entries[i].vector;

drivers/scsi/bfa/bfad_intr.c

Quoted 4 lines
drivers/scsi/bfa/bfad_intr.c +4 -0
+
+		/* Set up interrupt handler for each vectors */
+		if (bfad_install_msix_handler(bfad)) {
+			printk(KERN_WARNING "%s: install_msix failed,

bfad%d\n",

drivers/scsi/bfa/bfad_intr.c line 270

Quoted 3 lines
drivers/scsi/bfa/bfad_intr.c +3 -0
+			       __FUNCTION__, bfad->inst_no);
+			goto line_based;
+		}

This is just your choice, but when MSI was requested and the number of interrupts were reserved successfully and now installing the IRQ handler

fails this should IMHO be an error and not a situation to fallback to line
based. YMMV.

drivers/scsi/bfa/bfad_intr.c

Quoted 9 lines
drivers/scsi/bfa/bfad_intr.c +9 -0
+		bfad->bfad_flags |= BFAD_MSIX_ON;
+
+		goto success;
+	}
+
+line_based:
+	error = 0;
+	if (request_irq
+	    (bfad->pcidev->irq, (irq_handler_t) bfad_intx,

BFAD_IRQ_FLAGS,

Cast not needed, bfad_intx() should be of the correct signature.

Quoted 23 lines
drivers/scsi/bfa/bfad_intr.c +23 -0
+	     BFAD_DRIVER_NAME, bfad) != 0) {
+		/* Enable interrupt handler failed */
+		return 1;
+	}
+success:
+	return error;
+}
+
+void
+bfad_remove_intr(struct bfad_s *bfad)
+{
+	int             i;
+
+	if (bfad->bfad_flags & BFAD_MSIX_ON) {
+		for (i = 0; i < bfad->nvec; i++)
+			free_irq(bfad->msix_tab[i].msix.vector, bfad);
+
+		pci_disable_msix(bfad->pcidev);
+		bfad->bfad_flags &= ~BFAD_MSIX_ON;
+	} else {
+		free_irq(bfad->pcidev->irq, bfad);
+	}
+}

drivers/scsi/bfa/bfad_intr.c line 313

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+
+#else /* CONFIG_PCI_MSI */
+/**
+ * Setup line-based interrupt.
+ */
+int
+bfad_setup_intr(struct bfad_s *bfad)
+{
+	if (request_irq
+	    (bfad->pcidev->irq, (irq_handler_t) bfad_intx, SA_SHIRQ,

Same here.

Quoted 8 lines
drivers/scsi/bfa/bfad_intr.c +8 -0
+	     BFAD_DRIVER_NAME, bfad) != 0) {
+		/* Enable interrupt handler failed */
+		return 1;
+	}
+
+	return 0;
+}
+

drivers/scsi/bfa/bfad_intr.c line 331

Quoted 10 lines
drivers/scsi/bfa/bfad_intr.c +10 -0
+void
+bfad_remove_intr(struct bfad_s *bfad)
+{
+	bfa_trc(bfad, bfad->pcidev->irq);
+	free_irq(bfad->pcidev->irq, bfad);
+}
+
+#endif /* CONFIG_PCI_MSI */
+
+

Remove trailing empty lines.

Greetings,

Eike