Skip to content

Commit

Permalink
[SCSI] qla2xxx: Add Fibre Channel Event (FCE) tracing support.
Browse files Browse the repository at this point in the history
FCE support enables the firmware to record FC extended link
services and basic link services frames which have been
transmitted and received by the ISP.  This allows for a limited
view of the FC traffic through the ISP without using a FC
analyzer.  This can be useful in situations where a physical
connection to the FC bus is not possible.

The driver exports this information in two ways -- first, via a
debugfs node exported for all supported ISPs under:

	<debugfs_mount_point>/qla2xxx/qla2xxx_<host_no>/fce

where a read of the 'fce' file will provide a snapshot of the
firmware's FCE buffer; and finally, the FCE buffer will be
extracted during a firmware-dump scenario.

Signed-off-by: Andrew Vasquez <andrew.vasquez@qlogic.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
  • Loading branch information
Andrew Vasquez authored and James Bottomley committed Jan 23, 2008
1 parent 00b6bd2 commit df613b9
Show file tree
Hide file tree
Showing 10 changed files with 405 additions and 14 deletions.
2 changes: 1 addition & 1 deletion drivers/scsi/qla2xxx/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qla2xxx-y := qla_os.o qla_init.o qla_mbx.o qla_iocb.o qla_isr.o qla_gs.o \
qla_dbg.o qla_sup.o qla_attr.o qla_mid.o
qla_dbg.o qla_sup.o qla_attr.o qla_mid.o qla_dfs.o

obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx.o
22 changes: 22 additions & 0 deletions drivers/scsi/qla2xxx/qla_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,7 @@ qla25xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
struct qla25xx_fw_dump *fw;
uint32_t ext_mem_cnt;
void *nxt;
struct qla2xxx_fce_chain *fcec;

risc_address = ext_mem_cnt = 0;
flags = 0;
Expand Down Expand Up @@ -1321,10 +1322,31 @@ qla25xx_fw_dump(scsi_qla_host_t *ha, int hardware_locked)
if (rval != QLA_SUCCESS)
goto qla25xx_fw_dump_failed_0;

/* Fibre Channel Trace Buffer. */
nxt = qla2xxx_copy_queues(ha, nxt);
if (ha->eft)
memcpy(nxt, ha->eft, ntohl(ha->fw_dump->eft_size));

/* Fibre Channel Event Buffer. */
if (!ha->fce)
goto qla25xx_fw_dump_failed_0;

ha->fw_dump->version |= __constant_htonl(DUMP_CHAIN_VARIANT);

fcec = nxt + ntohl(ha->fw_dump->eft_size);
fcec->type = __constant_htonl(DUMP_CHAIN_FCE | DUMP_CHAIN_LAST);
fcec->chain_size = htonl(sizeof(struct qla2xxx_fce_chain) +
fce_calc_size(ha->fce_bufs));
fcec->size = htonl(fce_calc_size(ha->fce_bufs));
fcec->addr_l = htonl(LSD(ha->fce_dma));
fcec->addr_h = htonl(MSD(ha->fce_dma));

iter_reg = fcec->eregs;
for (cnt = 0; cnt < 8; cnt++)
*iter_reg++ = htonl(ha->fce_mb[cnt]);

memcpy(iter_reg, ha->fce, ntohl(fcec->size));

qla25xx_fw_dump_failed_0:
if (rval != QLA_SUCCESS) {
qla_printk(KERN_WARNING, ha,
Expand Down
19 changes: 19 additions & 0 deletions drivers/scsi/qla2xxx/qla_dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,25 @@ struct qla25xx_fw_dump {
#define EFT_BYTES_PER_BUFFER 0x4000
#define EFT_SIZE ((EFT_BYTES_PER_BUFFER) * (EFT_NUM_BUFFERS))

#define FCE_NUM_BUFFERS 64
#define FCE_BYTES_PER_BUFFER 0x400
#define FCE_SIZE ((FCE_BYTES_PER_BUFFER) * (FCE_NUM_BUFFERS))
#define fce_calc_size(b) ((FCE_BYTES_PER_BUFFER) * (b))

struct qla2xxx_fce_chain {
uint32_t type;
uint32_t chain_size;

uint32_t size;
uint32_t addr_l;
uint32_t addr_h;
uint32_t eregs[8];
};

#define DUMP_CHAIN_VARIANT 0x80000000
#define DUMP_CHAIN_FCE 0x7FFFFAF0
#define DUMP_CHAIN_LAST 0x80000000

struct qla2xxx_fw_dump {
uint8_t signature[4];
uint32_t version;
Expand Down
10 changes: 10 additions & 0 deletions drivers/scsi/qla2xxx/qla_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ typedef struct scsi_qla_host {
uint32_t gpsc_supported :1;
uint32_t vsan_enabled :1;
uint32_t npiv_supported :1;
uint32_t fce_enabled :1;
} flags;

atomic_t loop_state;
Expand Down Expand Up @@ -2449,6 +2450,15 @@ typedef struct scsi_qla_host {
dma_addr_t eft_dma;
void *eft;

struct dentry *dfs_dir;
struct dentry *dfs_fce;
dma_addr_t fce_dma;
void *fce;
uint32_t fce_bufs;
uint16_t fce_mb[8];
uint64_t fce_wr, fce_rd;
struct mutex fce_mutex;

uint8_t host_str[16];
uint32_t pci_attr;
uint16_t chip_revision;
Expand Down
175 changes: 175 additions & 0 deletions drivers/scsi/qla2xxx/qla_dfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* QLogic Fibre Channel HBA Driver
* Copyright (c) 2003-2005 QLogic Corporation
*
* See LICENSE.qla2xxx for copyright and licensing details.
*/
#include "qla_def.h"

#include <linux/debugfs.h>
#include <linux/seq_file.h>

static struct dentry *qla2x00_dfs_root;
static atomic_t qla2x00_dfs_root_count;

static int
qla2x00_dfs_fce_show(struct seq_file *s, void *unused)
{
scsi_qla_host_t *ha = s->private;
uint32_t cnt;
uint32_t *fce;
uint64_t fce_start;

mutex_lock(&ha->fce_mutex);

seq_printf(s, "FCE Trace Buffer\n");
seq_printf(s, "In Pointer = %llx\n\n", ha->fce_wr);
seq_printf(s, "Base = %llx\n\n", (unsigned long long) ha->fce_dma);
seq_printf(s, "FCE Enable Registers\n");
seq_printf(s, "%08x %08x %08x %08x %08x %08x\n",
ha->fce_mb[0], ha->fce_mb[2], ha->fce_mb[3], ha->fce_mb[4],
ha->fce_mb[5], ha->fce_mb[6]);

fce = (uint32_t *) ha->fce;
fce_start = (unsigned long long) ha->fce_dma;
for (cnt = 0; cnt < fce_calc_size(ha->fce_bufs) / 4; cnt++) {
if (cnt % 8 == 0)
seq_printf(s, "\n%llx: ",
(unsigned long long)((cnt * 4) + fce_start));
else
seq_printf(s, " ");
seq_printf(s, "%08x", *fce++);
}

seq_printf(s, "\nEnd\n");

mutex_unlock(&ha->fce_mutex);

return 0;
}

static int
qla2x00_dfs_fce_open(struct inode *inode, struct file *file)
{
scsi_qla_host_t *ha = inode->i_private;
int rval;

if (!ha->flags.fce_enabled)
goto out;

mutex_lock(&ha->fce_mutex);

/* Pause tracing to flush FCE buffers. */
rval = qla2x00_disable_fce_trace(ha, &ha->fce_wr, &ha->fce_rd);
if (rval)
qla_printk(KERN_WARNING, ha,
"DebugFS: Unable to disable FCE (%d).\n", rval);

ha->flags.fce_enabled = 0;

mutex_unlock(&ha->fce_mutex);
out:
return single_open(file, qla2x00_dfs_fce_show, ha);
}

static int
qla2x00_dfs_fce_release(struct inode *inode, struct file *file)
{
scsi_qla_host_t *ha = inode->i_private;
int rval;

if (ha->flags.fce_enabled)
goto out;

mutex_lock(&ha->fce_mutex);

/* Re-enable FCE tracing. */
ha->flags.fce_enabled = 1;
memset(ha->fce, 0, fce_calc_size(ha->fce_bufs));
rval = qla2x00_enable_fce_trace(ha, ha->fce_dma, ha->fce_bufs,
ha->fce_mb, &ha->fce_bufs);
if (rval) {
qla_printk(KERN_WARNING, ha,
"DebugFS: Unable to reinitialize FCE (%d).\n", rval);
ha->flags.fce_enabled = 0;
}

mutex_unlock(&ha->fce_mutex);
out:
return single_release(inode, file);
}

static const struct file_operations dfs_fce_ops = {
.open = qla2x00_dfs_fce_open,
.read = seq_read,
.llseek = seq_lseek,
.release = qla2x00_dfs_fce_release,
};

int
qla2x00_dfs_setup(scsi_qla_host_t *ha)
{
if (!IS_QLA25XX(ha))
goto out;
if (!ha->fce)
goto out;

if (qla2x00_dfs_root)
goto create_dir;

atomic_set(&qla2x00_dfs_root_count, 0);
qla2x00_dfs_root = debugfs_create_dir(QLA2XXX_DRIVER_NAME, NULL);
if (!qla2x00_dfs_root) {
qla_printk(KERN_NOTICE, ha,
"DebugFS: Unable to create root directory.\n");
goto out;
}

create_dir:
if (ha->dfs_dir)
goto create_nodes;

mutex_init(&ha->fce_mutex);
ha->dfs_dir = debugfs_create_dir(ha->host_str, qla2x00_dfs_root);
if (!ha->dfs_dir) {
qla_printk(KERN_NOTICE, ha,
"DebugFS: Unable to create ha directory.\n");
goto out;
}

atomic_inc(&qla2x00_dfs_root_count);

create_nodes:
ha->dfs_fce = debugfs_create_file("fce", S_IRUSR, ha->dfs_dir, ha,
&dfs_fce_ops);
if (!ha->dfs_fce) {
qla_printk(KERN_NOTICE, ha,
"DebugFS: Unable to fce node.\n");
goto out;
}
out:
return 0;
}

int
qla2x00_dfs_remove(scsi_qla_host_t *ha)
{
if (ha->dfs_fce) {
debugfs_remove(ha->dfs_fce);
ha->dfs_fce = NULL;
}

if (ha->dfs_dir) {
debugfs_remove(ha->dfs_dir);
ha->dfs_dir = NULL;
atomic_dec(&qla2x00_dfs_root_count);
}

if (atomic_read(&qla2x00_dfs_root_count) == 0 &&
qla2x00_dfs_root) {
debugfs_remove(qla2x00_dfs_root);
qla2x00_dfs_root = NULL;
}

return 0;
}
7 changes: 7 additions & 0 deletions drivers/scsi/qla2xxx/qla_fw.h
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,13 @@ struct device_reg_24xx {
#define TC_EFT_ENABLE 4
#define TC_EFT_DISABLE 5

#define TC_FCE_ENABLE 8
#define TC_FCE_OPTIONS 0
#define TC_FCE_DEFAULT_RX_SIZE 2112
#define TC_FCE_DEFAULT_TX_SIZE 2112
#define TC_FCE_DISABLE 9
#define TC_FCE_DISABLE_TRACE BIT_0

/* MID Support ***************************************************************/

#define MIN_MULTI_ID_FABRIC 64 /* Must be power-of-2. */
Expand Down
13 changes: 13 additions & 0 deletions drivers/scsi/qla2xxx/qla_gbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ qla2x00_enable_eft_trace(scsi_qla_host_t *, dma_addr_t, uint16_t);
extern int
qla2x00_disable_eft_trace(scsi_qla_host_t *);

extern int
qla2x00_enable_fce_trace(scsi_qla_host_t *, dma_addr_t, uint16_t , uint16_t *,
uint32_t *);

extern int
qla2x00_disable_fce_trace(scsi_qla_host_t *, uint64_t *, uint64_t *);

extern int
qla2x00_read_sfp(scsi_qla_host_t *, dma_addr_t, uint16_t, uint16_t, uint16_t);

Expand Down Expand Up @@ -334,4 +341,10 @@ extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
extern void qla2x00_init_host_attr(scsi_qla_host_t *);
extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);

/*
* Global Function Prototypes in qla_dfs.c source file.
*/
extern int qla2x00_dfs_setup(scsi_qla_host_t *);
extern int qla2x00_dfs_remove(scsi_qla_host_t *);
#endif /* _QLA_GBL_H */
Loading

0 comments on commit df613b9

Please sign in to comment.