Commit 35c4cbb1 authored by Christoph Lameter's avatar Christoph Lameter Committed by Doug Ledford

IB/core: Create get_perf_mad function in sysfs.c

Create a new function to retrieve performance management
data from the existing code in get_pma_counter().
Reviewed-by: default avatarHal Rosenstock <hal@mellanox.com>
Signed-off-by: default avatarChristoph Lameter <cl@linux.com>
Reviewed-by: default avatarIra Weiny <ira.weiny@intel.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent c09befcb
...@@ -398,21 +398,21 @@ struct port_table_attribute port_pma_attr_##_name = { \ ...@@ -398,21 +398,21 @@ struct port_table_attribute port_pma_attr_##_name = { \
.index = (_offset) | ((_width) << 16) | ((_counter) << 24) \ .index = (_offset) | ((_width) << 16) | ((_counter) << 24) \
} }
static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr, /*
char *buf) * Get a Perfmgmt MAD block of data.
* Returns error code or the number of bytes retrieved.
*/
static int get_perf_mad(struct ib_device *dev, int port_num, int attr,
void *data, int offset, size_t size)
{ {
struct port_table_attribute *tab_attr = struct ib_mad *in_mad;
container_of(attr, struct port_table_attribute, attr); struct ib_mad *out_mad;
int offset = tab_attr->index & 0xffff;
int width = (tab_attr->index >> 16) & 0xff;
struct ib_mad *in_mad = NULL;
struct ib_mad *out_mad = NULL;
size_t mad_size = sizeof(*out_mad); size_t mad_size = sizeof(*out_mad);
u16 out_mad_pkey_index = 0; u16 out_mad_pkey_index = 0;
ssize_t ret; ssize_t ret;
if (!p->ibdev->process_mad) if (!dev->process_mad)
return sprintf(buf, "N/A (no PMA)\n"); return -ENOSYS;
in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL); in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL); out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
...@@ -425,12 +425,12 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr, ...@@ -425,12 +425,12 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT; in_mad->mad_hdr.mgmt_class = IB_MGMT_CLASS_PERF_MGMT;
in_mad->mad_hdr.class_version = 1; in_mad->mad_hdr.class_version = 1;
in_mad->mad_hdr.method = IB_MGMT_METHOD_GET; in_mad->mad_hdr.method = IB_MGMT_METHOD_GET;
in_mad->mad_hdr.attr_id = cpu_to_be16(0x12); /* PortCounters */ in_mad->mad_hdr.attr_id = attr;
in_mad->data[41] = p->port_num; /* PortSelect field */ in_mad->data[41] = port_num; /* PortSelect field */
if ((p->ibdev->process_mad(p->ibdev, IB_MAD_IGNORE_MKEY, if ((dev->process_mad(dev, IB_MAD_IGNORE_MKEY,
p->port_num, NULL, NULL, port_num, NULL, NULL,
(const struct ib_mad_hdr *)in_mad, mad_size, (const struct ib_mad_hdr *)in_mad, mad_size,
(struct ib_mad_hdr *)out_mad, &mad_size, (struct ib_mad_hdr *)out_mad, &mad_size,
&out_mad_pkey_index) & &out_mad_pkey_index) &
...@@ -439,31 +439,49 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr, ...@@ -439,31 +439,49 @@ static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
memcpy(data, out_mad->data + offset, size);
ret = size;
out:
kfree(in_mad);
kfree(out_mad);
return ret;
}
static ssize_t show_pma_counter(struct ib_port *p, struct port_attribute *attr,
char *buf)
{
struct port_table_attribute *tab_attr =
container_of(attr, struct port_table_attribute, attr);
int offset = tab_attr->index & 0xffff;
int width = (tab_attr->index >> 16) & 0xff;
ssize_t ret;
u8 data[8];
ret = get_perf_mad(p->ibdev, p->port_num, cpu_to_be16(0x12), &data,
40 + offset / 8, sizeof(data));
if (ret < 0)
return sprintf(buf, "N/A (no PMA)\n");
switch (width) { switch (width) {
case 4: case 4:
ret = sprintf(buf, "%u\n", (out_mad->data[40 + offset / 8] >> ret = sprintf(buf, "%u\n", (*data >>
(4 - (offset % 8))) & 0xf); (4 - (offset % 8))) & 0xf);
break; break;
case 8: case 8:
ret = sprintf(buf, "%u\n", out_mad->data[40 + offset / 8]); ret = sprintf(buf, "%u\n", *data);
break; break;
case 16: case 16:
ret = sprintf(buf, "%u\n", ret = sprintf(buf, "%u\n",
be16_to_cpup((__be16 *)(out_mad->data + 40 + offset / 8))); be16_to_cpup((__be16 *)data));
break; break;
case 32: case 32:
ret = sprintf(buf, "%u\n", ret = sprintf(buf, "%u\n",
be32_to_cpup((__be32 *)(out_mad->data + 40 + offset / 8))); be32_to_cpup((__be32 *)data));
break; break;
default: default:
ret = 0; ret = 0;
} }
out:
kfree(in_mad);
kfree(out_mad);
return ret; return ret;
} }
......
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