Commit 85175168 authored by James Bottomley's avatar James Bottomley

SCSI: Add FC transport host attributes

From: 	James.Smart@Emulex.Com

This patch updates the fc_transport with attributes for local FC ports
(e.g. Hosts).  The port attributes are defined per HBAAPI v2.0 definitions.

This patch results in the following in /sys/class:
-----------------------------------------------------

[jsmart@elxware class]$ cd /sys/class
[jsmart@elxware class]$ ls
fc_host       graphics  misc     pci_bus       scsi_host  usb_host
fc_transport  input     net      scsi_device   tty        vc
firmware      mem       netlink  scsi_generic  usb
[jsmart@elxware class]$ cd fc_host
[jsmart@elxware fc_host]$ ls
host4

[jsmart@elxware fc_host]$ cd host4
[jsmart@elxware host4]$ ls
device                 host_port_maxframe_size      host_port_supported_speeds
host_fabric_name       host_port_name               host_port_symbolic_name
host_link_down_tmo     host_port_speed              host_port_type
host_node_name         host_port_state              host_tgtid_bind_type
host_port_active_fc4s  host_port_supported_classes  statistics
host_port_id           host_port_supported_fc4s
[jsmart@elxware host4]$ ls -ld *
lrwxrwxrwx  1 root root    0 Oct 13 18:24 device -> ../../../devices/platform/host4
-r--r--r--  1 root root 4096 Oct 13 18:24 host_fabric_name
-rw-r--r--  1 root root 4096 Oct 13 18:24 host_link_down_tmo
-r--r--r--  1 root root 4096 Oct 13 18:24 host_node_name
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_active_fc4s
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_id
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_maxframe_size
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_name
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_speed
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_state
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_supported_classes
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_supported_fc4s
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_supported_speeds
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_symbolic_name
-r--r--r--  1 root root 4096 Oct 13 18:24 host_port_type
-rw-r--r--  1 root root 4096 Oct 13 18:24 host_tgtid_bind_type
drwxr-xr-x  2 root root    0 Oct 13 18:24 statistics


Using the following script (/tmp/show_attributes):
    #!/bin/sh
    FILES=`ls *`
    for file in $FILES; do
      if [ -f $file ] ; then
        echo "$file : " `cat $file`
      fi
    done

Here's a sample of querying the attributes:

[jsmart@elxware /]$ cd /sys/class/fc_host/host4
[jsmart@elxware host4]$ /tmp/show_attributes
host_fabric_name :  0x33334444ffeeddcc
host_link_down_tmo :  30
host_node_name :  0x78563412aabbccdd
host_port_active_fc4s :  hex: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f
host_port_id :  0x789abc
host_port_maxframe_size :  2511 bytes
host_port_name :  0xefcdab9011223344
host_port_speed :  2 Gbit
host_port_state :  Online
host_port_supported_classes :  Class 2, Class 3
host_port_supported_fc4s :  hex: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f
host_port_supported_speeds :  2 Gbit, 4 Gbit, 10 Gbit
host_port_symbolic_name :  LP9052 Dual Port Adapter
host_port_type :  NPort (fabric via point-to-point)
host_tgtid_bind_type :  wwpn (World Wide Port Name)
Signed-off-by: default avatarJames Bottomley <James.Bottomley@SteelEye.com>
parent 18a1de8b
......@@ -27,6 +27,159 @@
#define FC_PRINTK(x, l, f, a...) printk(l "scsi(%d:%d:%d:%d): " f, (x)->host->host_no, (x)->channel, (x)->id, (x)->lun , ##a)
/*
* Redefine so that we can have same named attributes in the
* sdev/starget/host objects.
*/
#define FC_CLASS_DEVICE_ATTR(_prefix,_name,_mode,_show,_store) \
struct class_device_attribute class_device_attr_##_prefix##_##_name = \
__ATTR(_name,_mode,_show,_store)
#define fc_enum_name_search(title, table_type, table) \
static const char *get_fc_##title##_name(enum table_type table_key) \
{ \
int i; \
char *name = NULL; \
\
for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
if (table[i].value == table_key) { \
name = table[i].name; \
break; \
} \
} \
return name; \
}
#define fc_enum_name_match(title, table_type, table) \
static int get_fc_##title##_match(const char *table_key, \
enum table_type *value) \
{ \
int i; \
\
for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
if (strncmp(table_key, table[i].name, \
table[i].matchlen) == 0) { \
*value = table[i].value; \
return 0; /* success */ \
} \
} \
return 1; /* failure */ \
}
/* Convert fc_port_type values to ascii string name */
static struct {
enum fc_port_type value;
char *name;
} fc_port_type_names[] = {
{ FC_PORTTYPE_UNKNOWN, "Unknown" },
{ FC_PORTTYPE_OTHER, "Other" },
{ FC_PORTTYPE_NOTPRESENT, "Not Present" },
{ FC_PORTTYPE_NPORT, "NPort (fabric via point-to-point)" },
{ FC_PORTTYPE_NLPORT, "NLPort (fabric via loop)" },
{ FC_PORTTYPE_LPORT, "LPort (private loop)" },
{ FC_PORTTYPE_PTP, "Point-To-Point (direct nport connection" },
};
fc_enum_name_search(port_type, fc_port_type, fc_port_type_names)
#define FC_PORTTYPE_MAX_NAMELEN 50
/* Convert fc_port_state values to ascii string name */
static struct {
enum fc_port_state value;
char *name;
} fc_port_state_names[] = {
{ FC_PORTSTATE_UNKNOWN, "Unknown" },
{ FC_PORTSTATE_ONLINE, "Online" },
{ FC_PORTSTATE_OFFLINE, "Offline" },
{ FC_PORTSTATE_BYPASSED, "Bypassed" },
{ FC_PORTSTATE_DIAGNOSTICS, "Diagnostics" },
{ FC_PORTSTATE_LINKDOWN, "Linkdown" },
{ FC_PORTSTATE_ERROR, "Error" },
{ FC_PORTSTATE_LOOPBACK, "Loopback" },
};
fc_enum_name_search(port_state, fc_port_state, fc_port_state_names)
#define FC_PORTSTATE_MAX_NAMELEN 20
/* Convert fc_tgtid_binding_type values to ascii string name */
static struct {
enum fc_tgtid_binding_type value;
char *name;
int matchlen;
} fc_tgtid_binding_type_names[] = {
{ FC_TGTID_BIND_BY_WWPN, "wwpn (World Wide Port Name)", 4 },
{ FC_TGTID_BIND_BY_WWNN, "wwnn (World Wide Node Name)", 4 },
{ FC_TGTID_BIND_BY_ID, "fcportid (FC Address)", 8 },
};
fc_enum_name_search(tgtid_bind_type, fc_tgtid_binding_type,
fc_tgtid_binding_type_names)
fc_enum_name_match(tgtid_bind_type, fc_tgtid_binding_type,
fc_tgtid_binding_type_names)
#define FC_BINDTYPE_MAX_NAMELEN 30
#define fc_bitfield_name_search(title, table) \
static ssize_t \
get_fc_##title##_names(u32 table_key, char *buf) \
{ \
char *prefix = ""; \
ssize_t len = 0; \
int i; \
\
for (i = 0; i < sizeof(table)/sizeof(table[0]); i++) { \
if (table[i].value & table_key) { \
len += sprintf(buf + len, "%s%s", \
prefix, table[i].name); \
prefix = ", "; \
} \
} \
len += sprintf(buf + len, "\n"); \
return len; \
}
/* Convert fc_cos bit values to ascii string name */
static struct {
u32 value;
char *name;
} fc_cos_names[] = {
{ FC_COS_CLASS1, "Class 1" },
{ FC_COS_CLASS2, "Class 2" },
{ FC_COS_CLASS3, "Class 3" },
{ FC_COS_CLASS4, "Class 4" },
{ FC_COS_CLASS6, "Class 6" },
};
fc_bitfield_name_search(cos, fc_cos_names)
/* Convert fc_port_speed bit values to ascii string name */
static struct {
u32 value;
char *name;
} fc_port_speed_names[] = {
{ FC_PORTSPEED_1GBIT, "1 Gbit" },
{ FC_PORTSPEED_2GBIT, "2 Gbit" },
{ FC_PORTSPEED_4GBIT, "4 Gbit" },
{ FC_PORTSPEED_10GBIT, "10 Gbit" },
{ FC_PORTSPEED_NOT_NEGOTIATED, "Not Negotiated" },
};
fc_bitfield_name_search(port_speed, fc_port_speed_names)
static int
show_fc_fc4s (char *buf, u8 *fc4_list)
{
int i, len=0;
for (i = 0; i < FC_FC4_LIST_SIZE; i++, fc4_list++)
len += sprintf(buf + len , "0x%02x ", *fc4_list);
len += sprintf(buf + len, "\n");
return len;
}
static void transport_class_release(struct class_device *class_dev);
static void host_class_release(struct class_device *class_dev);
static void fc_timeout_blocked_host(void *data);
......@@ -35,7 +188,7 @@ static void fc_timeout_blocked_tgt(void *data);
#define FC_STARGET_NUM_ATTRS 4 /* increase this if you add attributes */
#define FC_STARGET_OTHER_ATTRS 0 /* increase this if you add "always on"
* attributes */
#define FC_HOST_NUM_ATTRS 1
#define FC_HOST_NUM_ATTRS 15
struct fc_internal {
struct scsi_transport_template t;
......@@ -108,7 +261,27 @@ static int fc_setup_host_transport_attrs(struct Scsi_Host *shost)
* failure cases. The scsi lldd is responsible for initializing
* all transport attributes to valid values per host.
*/
fc_host_node_name(shost) = -1;
fc_host_port_name(shost) = -1;
fc_host_supported_classes(shost) = FC_COS_UNSPECIFIED;
memset(fc_host_supported_fc4s(shost), 0,
sizeof(fc_host_supported_fc4s(shost)));
memset(fc_host_symbolic_name(shost), 0,
sizeof(fc_host_symbolic_name(shost)));
fc_host_supported_speeds(shost) = FC_PORTSPEED_UNKNOWN;
fc_host_maxframe_size(shost) = -1;
fc_host_port_id(shost) = -1;
fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
memset(fc_host_active_fc4s(shost), 0,
sizeof(fc_host_active_fc4s(shost)));
fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
fc_host_fabric_name(shost) = -1;
fc_host_link_down_tmo(shost) = -1;
fc_host_tgtid_bind_type(shost) = FC_TGTID_BIND_BY_WWPN;
INIT_WORK(&fc_host_link_down_work(shost),
fc_timeout_blocked_host, shost);
return 0;
......@@ -135,7 +308,7 @@ static void host_class_release(struct class_device *class_dev)
/*
* Remote Port Attribute Management
* Remote Port (Target) Attribute Management
*/
#define fc_starget_show_function(field, format_string, cast) \
......@@ -144,12 +317,11 @@ show_fc_starget_##field (struct class_device *cdev, char *buf) \
{ \
struct scsi_target *starget = transport_class_to_starget(cdev); \
struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); \
struct fc_starget_attrs *tp; \
struct fc_internal *i = to_fc_internal(shost->transportt); \
tp = (struct fc_starget_attrs *)&starget->starget_data; \
if (i->f->get_starget_##field) \
i->f->get_starget_##field(starget); \
return snprintf(buf, 20, format_string, cast tp->field); \
return snprintf(buf, 20, format_string, \
cast fc_starget_##field(starget)); \
}
#define fc_starget_store_function(field, format_string) \
......@@ -169,23 +341,23 @@ store_fc_starget_##field(struct class_device *cdev, const char *buf, \
#define fc_starget_rd_attr(field, format_string) \
fc_starget_show_function(field, format_string, ) \
static CLASS_DEVICE_ATTR(field, S_IRUGO, \
static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
show_fc_starget_##field, NULL)
#define fc_starget_rd_attr_cast(field, format_string, cast) \
fc_starget_show_function(field, format_string, (cast)) \
static CLASS_DEVICE_ATTR(field, S_IRUGO, \
static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO, \
show_fc_starget_##field, NULL)
#define fc_starget_rw_attr(field, format_string) \
fc_starget_show_function(field, format_string, ) \
fc_starget_store_function(field, format_string) \
static CLASS_DEVICE_ATTR(field, S_IRUGO | S_IWUSR, \
static FC_CLASS_DEVICE_ATTR(starget, field, S_IRUGO | S_IWUSR, \
show_fc_starget_##field, \
store_fc_starget_##field)
#define SETUP_STARGET_ATTRIBUTE_RD(field) \
i->private_starget_attrs[count] = class_device_attr_##field; \
i->private_starget_attrs[count] = class_device_attr_starget_##field; \
i->private_starget_attrs[count].attr.mode = S_IRUGO; \
i->private_starget_attrs[count].store = NULL; \
i->starget_attrs[count] = &i->private_starget_attrs[count]; \
......@@ -193,7 +365,7 @@ static CLASS_DEVICE_ATTR(field, S_IRUGO | S_IWUSR, \
count++
#define SETUP_STARGET_ATTRIBUTE_RW(field) \
i->private_starget_attrs[count] = class_device_attr_##field; \
i->private_starget_attrs[count] = class_device_attr_starget_##field; \
if (!i->f->set_starget_##field) { \
i->private_starget_attrs[count].attr.mode = S_IRUGO; \
i->private_starget_attrs[count].store = NULL; \
......@@ -209,21 +381,20 @@ fc_starget_rd_attr(port_id, "0x%06x\n");
fc_starget_rw_attr(dev_loss_tmo, "%d\n");
/*
* Host Attribute Management
*/
#define fc_host_show_function(field, format_string, cast) \
#define fc_host_show_function(field, format_string, sz, cast) \
static ssize_t \
show_fc_host_##field (struct class_device *cdev, char *buf) \
{ \
struct Scsi_Host *shost = transport_class_to_shost(cdev); \
struct fc_host_attrs *tp; \
struct fc_internal *i = to_fc_internal(shost->transportt); \
tp = (struct fc_host_attrs *)shost->shost_data; \
if (i->f->get_host_##field) \
i->f->get_host_##field(shost); \
return snprintf(buf, 20, format_string, cast tp->field); \
return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
}
#define fc_host_store_function(field, format_string) \
......@@ -240,23 +411,39 @@ store_fc_host_##field(struct class_device *cdev, const char *buf, \
return count; \
}
#define fc_host_rd_attr(field, format_string) \
fc_host_show_function(field, format_string, ) \
static CLASS_DEVICE_ATTR(host_##field, S_IRUGO, \
#define fc_host_rd_attr(field, format_string, sz) \
fc_host_show_function(field, format_string, sz, ) \
static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
show_fc_host_##field, NULL)
#define fc_host_rd_attr_cast(field, format_string, cast) \
fc_host_show_function(field, format_string, (cast)) \
static CLASS_DEVICE_ATTR(host_##field, S_IRUGO, \
#define fc_host_rd_attr_cast(field, format_string, sz, cast) \
fc_host_show_function(field, format_string, sz, (cast)) \
static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
show_fc_host_##field, NULL)
#define fc_host_rw_attr(field, format_string) \
fc_host_show_function(field, format_string, ) \
#define fc_host_rw_attr(field, format_string, sz) \
fc_host_show_function(field, format_string, sz, ) \
fc_host_store_function(field, format_string) \
static CLASS_DEVICE_ATTR(host_##field, S_IRUGO | S_IWUSR, \
static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO | S_IWUSR, \
show_fc_host_##field, \
store_fc_host_##field)
#define fc_host_rd_enum_attr(title, maxlen) \
static ssize_t \
show_fc_host_##title (struct class_device *cdev, char *buf) \
{ \
struct Scsi_Host *shost = transport_class_to_shost(cdev); \
struct fc_internal *i = to_fc_internal(shost->transportt); \
const char *name; \
if (i->f->get_host_##title) \
i->f->get_host_##title(shost); \
name = get_fc_##title##_name(fc_host_##title(shost)); \
if (!name) \
return -EINVAL; \
return snprintf(buf, maxlen, "%s\n", name); \
} \
static FC_CLASS_DEVICE_ATTR(host, title, S_IRUGO, show_fc_host_##title, NULL)
#define SETUP_HOST_ATTRIBUTE_RD(field) \
i->private_host_attrs[count] = class_device_attr_host_##field; \
i->private_host_attrs[count].attr.mode = S_IRUGO; \
......@@ -275,9 +462,153 @@ static CLASS_DEVICE_ATTR(host_##field, S_IRUGO | S_IWUSR, \
if (i->f->show_host_##field) \
count++
/* The FC Tranport Host Attributes: */
fc_host_rw_attr(link_down_tmo, "%d\n");
#define fc_private_host_show_function(field, format_string, sz, cast) \
static ssize_t \
show_fc_host_##field (struct class_device *cdev, char *buf) \
{ \
struct Scsi_Host *shost = transport_class_to_shost(cdev); \
return snprintf(buf, sz, format_string, cast fc_host_##field(shost)); \
}
#define fc_private_host_rd_attr(field, format_string, sz) \
fc_private_host_show_function(field, format_string, sz, ) \
static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
show_fc_host_##field, NULL)
#define fc_private_host_rd_attr_cast(field, format_string, sz, cast) \
fc_private_host_show_function(field, format_string, sz, (cast)) \
static FC_CLASS_DEVICE_ATTR(host, field, S_IRUGO, \
show_fc_host_##field, NULL)
#define SETUP_PRIVATE_HOST_ATTRIBUTE_RD(field) \
i->private_host_attrs[count] = class_device_attr_host_##field; \
i->private_host_attrs[count].attr.mode = S_IRUGO; \
i->private_host_attrs[count].store = NULL; \
i->host_attrs[count] = &i->private_host_attrs[count]; \
count++
#define SETUP_PRIVATE_HOST_ATTRIBUTE_RW(field) \
i->private_host_attrs[count] = class_device_attr_host_##field; \
i->host_attrs[count] = &i->private_host_attrs[count]; \
count++
/* Fixed Host Attributes */
static ssize_t
show_fc_host_supported_classes (struct class_device *cdev, char *buf)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
if (fc_host_supported_classes(shost) == FC_COS_UNSPECIFIED)
return snprintf(buf, 20, "unspecified\n");
return get_fc_cos_names(fc_host_supported_classes(shost), buf);
}
static FC_CLASS_DEVICE_ATTR(host, supported_classes, S_IRUGO,
show_fc_host_supported_classes, NULL);
static ssize_t
show_fc_host_supported_fc4s (struct class_device *cdev, char *buf)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
return (ssize_t)show_fc_fc4s(buf, fc_host_supported_fc4s(shost));
}
static FC_CLASS_DEVICE_ATTR(host, supported_fc4s, S_IRUGO,
show_fc_host_supported_fc4s, NULL);
static ssize_t
show_fc_host_supported_speeds (struct class_device *cdev, char *buf)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
if (fc_host_supported_speeds(shost) == FC_PORTSPEED_UNKNOWN)
return snprintf(buf, 20, "unknown\n");
return get_fc_port_speed_names(fc_host_supported_speeds(shost), buf);
}
static FC_CLASS_DEVICE_ATTR(host, supported_speeds, S_IRUGO,
show_fc_host_supported_speeds, NULL);
fc_private_host_rd_attr_cast(node_name, "0x%llx\n", 20, unsigned long long);
fc_private_host_rd_attr_cast(port_name, "0x%llx\n", 20, unsigned long long);
fc_private_host_rd_attr(symbolic_name, "%s\n", (FC_SYMBOLIC_NAME_SIZE +1));
fc_private_host_rd_attr(maxframe_size, "%u bytes\n", 20);
/* Dynamic Host Attributes */
static ssize_t
show_fc_host_active_fc4s (struct class_device *cdev, char *buf)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
struct fc_internal *i = to_fc_internal(shost->transportt);
if (i->f->get_host_active_fc4s)
i->f->get_host_active_fc4s(shost);
return (ssize_t)show_fc_fc4s(buf, fc_host_active_fc4s(shost));
}
static FC_CLASS_DEVICE_ATTR(host, active_fc4s, S_IRUGO,
show_fc_host_active_fc4s, NULL);
static ssize_t
show_fc_host_speed (struct class_device *cdev, char *buf)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
struct fc_internal *i = to_fc_internal(shost->transportt);
if (i->f->get_host_speed)
i->f->get_host_speed(shost);
if (fc_host_speed(shost) == FC_PORTSPEED_UNKNOWN)
return snprintf(buf, 20, "unknown\n");
return get_fc_port_speed_names(fc_host_speed(shost), buf);
}
static FC_CLASS_DEVICE_ATTR(host, speed, S_IRUGO,
show_fc_host_speed, NULL);
fc_host_rd_attr(port_id, "0x%06x\n", 20);
fc_host_rd_enum_attr(port_type, FC_PORTTYPE_MAX_NAMELEN);
fc_host_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN);
fc_host_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
fc_host_rw_attr(link_down_tmo, "%d\n", 20);
/* Private Host Attributes */
static ssize_t
show_fc_private_host_tgtid_bind_type(struct class_device *cdev, char *buf)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
const char *name;
name = get_fc_tgtid_bind_type_name(fc_host_tgtid_bind_type(shost));
if (!name)
return -EINVAL;
return snprintf(buf, FC_BINDTYPE_MAX_NAMELEN, "%s\n", name);
}
static ssize_t
store_fc_private_host_tgtid_bind_type(struct class_device *cdev,
const char *buf, size_t count)
{
struct Scsi_Host *shost = transport_class_to_shost(cdev);
enum fc_tgtid_binding_type val;
if (get_fc_tgtid_bind_type_match(buf, &val))
return -EINVAL;
fc_host_tgtid_bind_type(shost) = val;
return count;
}
static FC_CLASS_DEVICE_ATTR(host, tgtid_bind_type, S_IRUGO | S_IWUSR,
show_fc_private_host_tgtid_bind_type,
store_fc_private_host_tgtid_bind_type);
/*
* Host Statistics Management
......@@ -293,14 +624,14 @@ fc_stat_show(const struct class_device *cdev, char *buf, unsigned long offset)
ssize_t ret = -ENOENT;
if (offset > sizeof(struct fc_host_statistics) ||
offset % sizeof(uint64_t) != 0)
offset % sizeof(u64) != 0)
WARN_ON(1);
if (i->f->get_fc_host_stats) {
stats = (i->f->get_fc_host_stats)(shost);
if (stats)
ret = snprintf(buf, 20, "0x%llx\n",
*(uint64_t *)(((u8 *) stats) + offset));
*(u64 *)(((u8 *) stats) + offset));
}
return ret;
}
......@@ -313,7 +644,7 @@ static ssize_t show_fcstat_##name(struct class_device *cd, char *buf) \
return fc_stat_show(cd, buf, \
offsetof(struct fc_host_statistics, name)); \
} \
static CLASS_DEVICE_ATTR(name, S_IRUGO, show_fcstat_##name, NULL)
static FC_CLASS_DEVICE_ATTR(host, name, S_IRUGO, show_fcstat_##name, NULL)
fc_host_statistic(seconds_since_last_reset);
fc_host_statistic(tx_frames);
......@@ -351,31 +682,32 @@ fc_reset_statistics(struct class_device *cdev, const char *buf,
return -ENOENT;
}
static CLASS_DEVICE_ATTR(reset_statistics, S_IWUSR, NULL, fc_reset_statistics);
static FC_CLASS_DEVICE_ATTR(host, reset_statistics, S_IWUSR, NULL,
fc_reset_statistics);
static struct attribute *fc_statistics_attrs[] = {
&class_device_attr_seconds_since_last_reset.attr,
&class_device_attr_tx_frames.attr,
&class_device_attr_tx_words.attr,
&class_device_attr_rx_frames.attr,
&class_device_attr_rx_words.attr,
&class_device_attr_lip_count.attr,
&class_device_attr_nos_count.attr,
&class_device_attr_error_frames.attr,
&class_device_attr_dumped_frames.attr,
&class_device_attr_link_failure_count.attr,
&class_device_attr_loss_of_sync_count.attr,
&class_device_attr_loss_of_signal_count.attr,
&class_device_attr_prim_seq_protocol_err_count.attr,
&class_device_attr_invalid_tx_word_count.attr,
&class_device_attr_invalid_crc_count.attr,
&class_device_attr_fcp_input_requests.attr,
&class_device_attr_fcp_output_requests.attr,
&class_device_attr_fcp_control_requests.attr,
&class_device_attr_fcp_input_megabytes.attr,
&class_device_attr_fcp_output_megabytes.attr,
&class_device_attr_reset_statistics.attr,
&class_device_attr_host_seconds_since_last_reset.attr,
&class_device_attr_host_tx_frames.attr,
&class_device_attr_host_tx_words.attr,
&class_device_attr_host_rx_frames.attr,
&class_device_attr_host_rx_words.attr,
&class_device_attr_host_lip_count.attr,
&class_device_attr_host_nos_count.attr,
&class_device_attr_host_error_frames.attr,
&class_device_attr_host_dumped_frames.attr,
&class_device_attr_host_link_failure_count.attr,
&class_device_attr_host_loss_of_sync_count.attr,
&class_device_attr_host_loss_of_signal_count.attr,
&class_device_attr_host_prim_seq_protocol_err_count.attr,
&class_device_attr_host_invalid_tx_word_count.attr,
&class_device_attr_host_invalid_crc_count.attr,
&class_device_attr_host_fcp_input_requests.attr,
&class_device_attr_host_fcp_output_requests.attr,
&class_device_attr_host_fcp_control_requests.attr,
&class_device_attr_host_fcp_input_megabytes.attr,
&class_device_attr_host_fcp_output_megabytes.attr,
&class_device_attr_host_reset_statistics.attr,
NULL
};
......@@ -433,11 +765,26 @@ fc_attach_transport(struct fc_function_template *ft)
/* setup host attributes */
count=0;
SETUP_HOST_ATTRIBUTE_RD(node_name);
SETUP_HOST_ATTRIBUTE_RD(port_name);
SETUP_HOST_ATTRIBUTE_RD(supported_classes);
SETUP_HOST_ATTRIBUTE_RD(supported_fc4s);
SETUP_HOST_ATTRIBUTE_RD(symbolic_name);
SETUP_HOST_ATTRIBUTE_RD(supported_speeds);
SETUP_HOST_ATTRIBUTE_RD(maxframe_size);
SETUP_HOST_ATTRIBUTE_RD(port_id);
SETUP_HOST_ATTRIBUTE_RD(port_type);
SETUP_HOST_ATTRIBUTE_RD(port_state);
SETUP_HOST_ATTRIBUTE_RD(active_fc4s);
SETUP_HOST_ATTRIBUTE_RD(speed);
SETUP_HOST_ATTRIBUTE_RD(fabric_name);
SETUP_HOST_ATTRIBUTE_RW(link_down_tmo);
BUG_ON(count > FC_HOST_NUM_ATTRS);
/* Transport-managed attributes */
SETUP_PRIVATE_HOST_ATTRIBUTE_RW(tgtid_bind_type);
/* Setup the always-on attributes here */
BUG_ON(count > FC_HOST_NUM_ATTRS);
i->host_attrs[count] = NULL;
......
......@@ -24,11 +24,101 @@
struct scsi_transport_template;
/*
* FC Port definitions - Following FC HBAAPI guidelines
*
* Note: Not all binary values for the different fields match HBAAPI.
* Instead, we use densely packed ordinal values or enums.
* We get away with this as we never present the actual binary values
* externally. For sysfs, we always present the string that describes
* the value. Thus, an admin doesn't need a magic HBAAPI decoder ring
* to understand the values. The HBAAPI user-space library is free to
* convert the strings into the HBAAPI-specified binary values.
*
* Note: Not all HBAAPI-defined values are contained in the definitions
* below. Those not appropriate to an fc_host (e.g. FCP initiator) have
* been removed.
*/
/*
* fc_port_type: If you alter this, you also need to alter scsi_transport_fc.c
* (for the ascii descriptions).
*/
enum fc_port_type {
FC_PORTTYPE_UNKNOWN,
FC_PORTTYPE_OTHER,
FC_PORTTYPE_NOTPRESENT,
FC_PORTTYPE_NPORT, /* Attached to FPort */
FC_PORTTYPE_NLPORT, /* (Public) Loop w/ FLPort */
FC_PORTTYPE_LPORT, /* (Private) Loop w/o FLPort */
FC_PORTTYPE_PTP, /* Point to Point w/ another NPort */
};
/*
* fc_port_state: If you alter this, you also need to alter scsi_transport_fc.c
* (for the ascii descriptions).
*/
enum fc_port_state {
FC_PORTSTATE_UNKNOWN,
FC_PORTSTATE_ONLINE,
FC_PORTSTATE_OFFLINE, /* User has taken Port Offline */
FC_PORTSTATE_BYPASSED,
FC_PORTSTATE_DIAGNOSTICS,
FC_PORTSTATE_LINKDOWN,
FC_PORTSTATE_ERROR,
FC_PORTSTATE_LOOPBACK,
};
/*
* FC Classes of Service
* Note: values are not enumerated, as they can be "or'd" together
* for reporting (e.g. report supported_classes). If you alter this list,
* you also need to alter scsi_transport_fc.c (for the ascii descriptions).
*/
#define FC_COS_UNSPECIFIED 0
#define FC_COS_CLASS1 2
#define FC_COS_CLASS2 4
#define FC_COS_CLASS3 8
#define FC_COS_CLASS4 0x10
#define FC_COS_CLASS6 0x40
/*
* FC Port Speeds
* Note: values are not enumerated, as they can be "or'd" together
* for reporting (e.g. report supported_speeds). If you alter this list,
* you also need to alter scsi_transport_fc.c (for the ascii descriptions).
*/
#define FC_PORTSPEED_UNKNOWN 0 /* Unknown - transceiver
incapable of reporting */
#define FC_PORTSPEED_1GBIT 1
#define FC_PORTSPEED_2GBIT 2
#define FC_PORTSPEED_10GBIT 4
#define FC_PORTSPEED_4GBIT 8
#define FC_PORTSPEED_NOT_NEGOTIATED (1 << 15) /* Speed not established */
/*
* fc_tgtid_binding_type: If you alter this, you also need to alter
* scsi_transport_fc.c (for the ascii descriptions).
*/
enum fc_tgtid_binding_type {
FC_TGTID_BIND_BY_WWPN,
FC_TGTID_BIND_BY_WWNN,
FC_TGTID_BIND_BY_ID,
};
/*
* FC Remote Port (Target) Attributes
*/
struct fc_starget_attrs { /* aka fc_target_attrs */
int port_id;
uint64_t node_name;
uint64_t port_name;
uint32_t dev_loss_tmo; /* Remote Port loss timeout in seconds. */
u64 node_name;
u64 port_name;
u32 dev_loss_tmo; /* Remote Port loss timeout in seconds. */
struct work_struct dev_loss_work;
};
......@@ -51,38 +141,107 @@ struct fc_starget_attrs { /* aka fc_target_attrs */
/* FC Statistics - Following FC HBAAPI v2.0 guidelines */
struct fc_host_statistics {
/* port statistics */
uint64_t seconds_since_last_reset;
uint64_t tx_frames;
uint64_t tx_words;
uint64_t rx_frames;
uint64_t rx_words;
uint64_t lip_count;
uint64_t nos_count;
uint64_t error_frames;
uint64_t dumped_frames;
uint64_t link_failure_count;
uint64_t loss_of_sync_count;
uint64_t loss_of_signal_count;
uint64_t prim_seq_protocol_err_count;
uint64_t invalid_tx_word_count;
uint64_t invalid_crc_count;
u64 seconds_since_last_reset;
u64 tx_frames;
u64 tx_words;
u64 rx_frames;
u64 rx_words;
u64 lip_count;
u64 nos_count;
u64 error_frames;
u64 dumped_frames;
u64 link_failure_count;
u64 loss_of_sync_count;
u64 loss_of_signal_count;
u64 prim_seq_protocol_err_count;
u64 invalid_tx_word_count;
u64 invalid_crc_count;
/* fc4 statistics (only FCP supported currently) */
uint64_t fcp_input_requests;
uint64_t fcp_output_requests;
uint64_t fcp_control_requests;
uint64_t fcp_input_megabytes;
uint64_t fcp_output_megabytes;
u64 fcp_input_requests;
u64 fcp_output_requests;
u64 fcp_control_requests;
u64 fcp_input_megabytes;
u64 fcp_output_megabytes;
};
/*
* FC Local Port (Host) Attributes
*
* Attributes are based on HBAAPI V2.0 definitions.
* Note: OSDeviceName is determined by user-space library
*
* Fixed attributes are not expected to change. The driver is
* expected to set these values after successfully calling scsi_add_host().
* The transport fully manages all get functions w/o driver interaction.
*
* Dynamic attributes are expected to change. The driver participates
* in all get/set operations via functions provided by the driver.
*
* Private attributes are transport-managed values. They are fully
* managed by the transport w/o driver interaction.
*/
#define FC_FC4_LIST_SIZE 32
#define FC_SYMBOLIC_NAME_SIZE 256
struct fc_host_attrs {
uint32_t link_down_tmo; /* Link Down timeout in seconds. */
/* Fixed Attributes */
u64 node_name;
u64 port_name;
u32 supported_classes;
u8 supported_fc4s[FC_FC4_LIST_SIZE];
char symbolic_name[FC_SYMBOLIC_NAME_SIZE];
u32 supported_speeds;
u32 maxframe_size;
/* Dynamic Attributes */
u32 port_id;
enum fc_port_type port_type;
enum fc_port_state port_state;
u8 active_fc4s[FC_FC4_LIST_SIZE];
u32 speed;
u64 fabric_name;
u32 link_down_tmo; /* Link Down timeout in seconds. */
/* Private (Transport-managed) Attributes */
enum fc_tgtid_binding_type tgtid_bind_type;
/* internal data */
struct work_struct link_down_work;
};
#define fc_host_node_name(x) \
(((struct fc_host_attrs *)(x)->shost_data)->node_name)
#define fc_host_port_name(x) \
(((struct fc_host_attrs *)(x)->shost_data)->port_name)
#define fc_host_supported_classes(x) \
(((struct fc_host_attrs *)(x)->shost_data)->supported_classes)
#define fc_host_supported_fc4s(x) \
(((struct fc_host_attrs *)(x)->shost_data)->supported_fc4s)
#define fc_host_symbolic_name(x) \
(((struct fc_host_attrs *)(x)->shost_data)->symbolic_name)
#define fc_host_supported_speeds(x) \
(((struct fc_host_attrs *)(x)->shost_data)->supported_speeds)
#define fc_host_maxframe_size(x) \
(((struct fc_host_attrs *)(x)->shost_data)->maxframe_size)
#define fc_host_port_id(x) \
(((struct fc_host_attrs *)(x)->shost_data)->port_id)
#define fc_host_port_type(x) \
(((struct fc_host_attrs *)(x)->shost_data)->port_type)
#define fc_host_port_state(x) \
(((struct fc_host_attrs *)(x)->shost_data)->port_state)
#define fc_host_active_fc4s(x) \
(((struct fc_host_attrs *)(x)->shost_data)->active_fc4s)
#define fc_host_speed(x) \
(((struct fc_host_attrs *)(x)->shost_data)->speed)
#define fc_host_fabric_name(x) \
(((struct fc_host_attrs *)(x)->shost_data)->fabric_name)
#define fc_host_link_down_tmo(x) \
(((struct fc_host_attrs *)(x)->shost_data)->link_down_tmo)
#define fc_host_tgtid_bind_type(x) \
(((struct fc_host_attrs *)(x)->shost_data)->tgtid_bind_type)
#define fc_host_link_down_work(x) \
(((struct fc_host_attrs *)(x)->shost_data)->link_down_work)
......@@ -93,10 +252,16 @@ struct fc_function_template {
void (*get_starget_node_name)(struct scsi_target *);
void (*get_starget_port_name)(struct scsi_target *);
void (*get_starget_dev_loss_tmo)(struct scsi_target *);
void (*set_starget_dev_loss_tmo)(struct scsi_target *, uint32_t);
void (*set_starget_dev_loss_tmo)(struct scsi_target *, u32);
void (*get_host_port_id)(struct Scsi_Host *);
void (*get_host_port_type)(struct Scsi_Host *);
void (*get_host_port_state)(struct Scsi_Host *);
void (*get_host_active_fc4s)(struct Scsi_Host *);
void (*get_host_speed)(struct Scsi_Host *);
void (*get_host_fabric_name)(struct Scsi_Host *);
void (*get_host_link_down_tmo)(struct Scsi_Host *);
void (*set_host_link_down_tmo)(struct Scsi_Host *, uint32_t);
void (*set_host_link_down_tmo)(struct Scsi_Host *, u32);
struct fc_host_statistics * (*get_fc_host_stats)(struct Scsi_Host *);
void (*reset_fc_host_stats)(struct Scsi_Host *);
......@@ -112,11 +277,25 @@ struct fc_function_template {
unsigned long show_starget_port_name:1;
unsigned long show_starget_dev_loss_tmo:1;
/* host fixed attributes */
unsigned long show_host_node_name:1;
unsigned long show_host_port_name:1;
unsigned long show_host_supported_classes:1;
unsigned long show_host_supported_fc4s:1;
unsigned long show_host_symbolic_name:1;
unsigned long show_host_supported_speeds:1;
unsigned long show_host_maxframe_size:1;
/* host dynamic attributes */
unsigned long show_host_port_id:1;
unsigned long show_host_port_type:1;
unsigned long show_host_port_state:1;
unsigned long show_host_active_fc4s:1;
unsigned long show_host_speed:1;
unsigned long show_host_fabric_name:1;
unsigned long show_host_link_down_tmo:1;
/* Private Attributes */
};
struct scsi_transport_template *fc_attach_transport(struct fc_function_template *);
void fc_release_transport(struct scsi_transport_template *);
int fc_target_block(struct scsi_target *starget);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment