/*******************************************************************************
* Filename: target_core_mib.c
*
* Copyright (c) 2006-2007 SBE, Inc. All Rights Reserved.
* Copyright (c) 2007-2010 Rising Tide Systems
* Copyright (c) 2008-2010 Linux-iSCSI.org
*
* Nicholas A. Bellinger <nab@linux-iscsi.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
******************************************************************************/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/version.h>
#include <generated/utsrelease.h>
#include <linux/utsname.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/blkdev.h>
#include <scsi/scsi.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_host.h>
#include <target/target_core_base.h>
#include <target/target_core_transport.h>
#include <target/target_core_fabric_ops.h>
#include <target/target_core_configfs.h>
#include "target_core_hba.h"
#include "target_core_mib.h"
/* SCSI mib table index */
static struct scsi_index_table scsi_index_table;
#ifndef INITIAL_JIFFIES
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
#endif
/* SCSI Instance Table */
#define SCSI_INST_SW_INDEX 1
#define SCSI_TRANSPORT_INDEX 1
#define NONE "None"
#define ISPRINT(a) ((a >= ' ') && (a <= '~'))
static inline int list_is_first(const struct list_head *list,
const struct list_head *head)
{
return list->prev == head;
}
static void *locate_hba_start(
struct seq_file *seq,
loff_t *pos)
{
spin_lock(&se_global->g_device_lock);
return seq_list_start(&se_global->g_se_dev_list, *pos);
}
static void *locate_hba_next(
struct seq_file *seq,
void *v,
loff_t *pos)
{
return seq_list_next(v, &se_global->g_se_dev_list, pos);
}
static void locate_hba_stop(struct seq_file *seq, void *v)
{
spin_unlock(&se_global->g_device_lock);
}
/****************************************************************************
* SCSI MIB Tables
****************************************************************************/
/*
* SCSI Instance Table
*/
static void *scsi_inst_seq_start(
struct seq_file *seq,
loff_t *pos)
{
spin_lock(&se_global->hba_lock);
return seq_list_start(&se_global->g_hba_list, *pos);
}
static void *scsi_inst_seq_next(
struct seq_file *seq,
void *v,
loff_t *pos)
{
return seq_list_next(v, &se_global->g_hba_list, pos);
}
static void scsi_inst_seq_stop(struct seq_file *seq, void *v)
{
spin_unlock(&se_global->hba_lock);
}
static int scsi_inst_seq_show(struct seq_file *seq, void *v)
{
struct se_hba *hba = list_entry(v, struct se_hba, hba_list);
if (list_is_first(&hba->hba_list, &se_global->g_hba_list))
seq_puts(seq, "inst sw_indx\n");
seq_printf(seq, "%u %u\n", hba->hba_index, SCSI_INST_SW_INDEX);
seq_printf(seq, "plugin: %s version: %s\n",
hba->transport->name, TARGET_CORE_VERSION);
return 0;
}
static const struct seq_operations scsi_inst_seq_ops = {
.start = scsi_inst_seq_start,
.next = scsi_inst_seq_next,
.stop = scsi_inst_seq_stop,
.show = scsi_inst_seq_show
};
static int scsi_inst_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &scsi_inst_seq_ops);
}
static const struct file_operations scsi_inst_seq_fops = {
.owner = THIS_MODULE,
.open = scsi_inst_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/*
* SCSI Device Table
*/
static void *scsi_dev_seq_start(struct seq_file *seq, loff_t *pos)
{
return locate_hba_start(seq, pos);
}
static void *scsi_dev_seq_next(struct seq_file *seq, void