522 lines
14 KiB
C
522 lines
14 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright(c) 1999 - 2018 Intel Corporation. */
|
|
|
|
#include <linux/debugfs.h>
|
|
#include <linux/module.h>
|
|
|
|
#include "ixgbe.h"
|
|
#include "ixgbe_phy.h"
|
|
|
|
static struct dentry *ixgbe_dbg_root;
|
|
|
|
static char ixgbe_dbg_reg_ops_buf[256] = "";
|
|
|
|
static ssize_t ixgbe_dbg_common_ops_read(struct file *filp, char __user *buffer,
|
|
size_t count, loff_t *ppos,
|
|
char *dbg_buf)
|
|
{
|
|
struct ixgbe_adapter *adapter = filp->private_data;
|
|
char *buf;
|
|
int len;
|
|
|
|
/* don't allow partial reads */
|
|
if (*ppos != 0)
|
|
return 0;
|
|
|
|
buf = kasprintf(GFP_KERNEL, "%s: %s\n",
|
|
adapter->netdev->name, dbg_buf);
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
|
|
if (count < strlen(buf)) {
|
|
kfree(buf);
|
|
return -ENOSPC;
|
|
}
|
|
|
|
len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
|
|
|
|
kfree(buf);
|
|
return len;
|
|
}
|
|
|
|
/**
|
|
* ixgbe_dbg_reg_ops_read - read for reg_ops datum
|
|
* @filp: the opened file
|
|
* @buffer: where to write the data for the user to read
|
|
* @count: the size of the user's buffer
|
|
* @ppos: file position offset
|
|
**/
|
|
static ssize_t ixgbe_dbg_reg_ops_read(struct file *filp, char __user *buffer,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos,
|
|
ixgbe_dbg_reg_ops_buf);
|
|
}
|
|
|
|
/**
|
|
* ixgbe_dbg_reg_ops_write - write into reg_ops datum
|
|
* @filp: the opened file
|
|
* @buffer: where to find the user's data
|
|
* @count: the length of the user's data
|
|
* @ppos: file position offset
|
|
**/
|
|
static ssize_t ixgbe_dbg_reg_ops_write(struct file *filp,
|
|
const char __user *buffer,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ixgbe_adapter *adapter = filp->private_data;
|
|
int len;
|
|
|
|
/* don't allow partial writes */
|
|
if (*ppos != 0)
|
|
return 0;
|
|
if (count >= sizeof(ixgbe_dbg_reg_ops_buf))
|
|
return -ENOSPC;
|
|
|
|
len = simple_write_to_buffer(ixgbe_dbg_reg_ops_buf,
|
|
sizeof(ixgbe_dbg_reg_ops_buf)-1,
|
|
ppos,
|
|
buffer,
|
|
count);
|
|
if (len < 0)
|
|
return len;
|
|
|
|
ixgbe_dbg_reg_ops_buf[len] = '\0';
|
|
|
|
if (strncmp(ixgbe_dbg_reg_ops_buf, "write", 5) == 0) {
|
|
u32 reg, value;
|
|
int cnt;
|
|
cnt = sscanf(&ixgbe_dbg_reg_ops_buf[5], "%x %x", ®, &value);
|
|
if (cnt == 2) {
|
|
IXGBE_WRITE_REG(&adapter->hw, reg, value);
|
|
value = IXGBE_READ_REG(&adapter->hw, reg);
|
|
e_dev_info("write: 0x%08x = 0x%08x\n", reg, value);
|
|
} else {
|
|
e_dev_info("write <reg> <value>\n");
|
|
}
|
|
} else if (strncmp(ixgbe_dbg_reg_ops_buf, "read", 4) == 0) {
|
|
u32 reg, value;
|
|
int cnt;
|
|
cnt = sscanf(&ixgbe_dbg_reg_ops_buf[4], "%x", ®);
|
|
if (cnt == 1) {
|
|
value = IXGBE_READ_REG(&adapter->hw, reg);
|
|
snprintf(ixgbe_dbg_reg_ops_buf,
|
|
sizeof(ixgbe_dbg_reg_ops_buf),
|
|
"0x%08x = 0x%08x", reg, value);
|
|
} else {
|
|
e_dev_info("read <reg>\n");
|
|
}
|
|
} else {
|
|
e_dev_info("Unknown command %s\n", ixgbe_dbg_reg_ops_buf);
|
|
e_dev_info("Available commands:\n");
|
|
e_dev_info(" read <reg>\n");
|
|
e_dev_info(" write <reg> <value>\n");
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations ixgbe_dbg_reg_ops_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = simple_open,
|
|
.read = ixgbe_dbg_reg_ops_read,
|
|
.write = ixgbe_dbg_reg_ops_write,
|
|
};
|
|
|
|
static char ixgbe_dbg_netdev_ops_buf[256] = "";
|
|
|
|
/**
|
|
* ixgbe_dbg_netdev_ops_read - read for netdev_ops datum
|
|
* @filp: the opened file
|
|
* @buffer: where to write the data for the user to read
|
|
* @count: the size of the user's buffer
|
|
* @ppos: file position offset
|
|
**/
|
|
static ssize_t ixgbe_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
return ixgbe_dbg_common_ops_read(filp, buffer, count, ppos,
|
|
ixgbe_dbg_netdev_ops_buf);
|
|
}
|
|
|
|
/**
|
|
* ixgbe_dbg_netdev_ops_write - write into netdev_ops datum
|
|
* @filp: the opened file
|
|
* @buffer: where to find the user's data
|
|
* @count: the length of the user's data
|
|
* @ppos: file position offset
|
|
**/
|
|
static ssize_t ixgbe_dbg_netdev_ops_write(struct file *filp,
|
|
const char __user *buffer,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ixgbe_adapter *adapter = filp->private_data;
|
|
int len;
|
|
|
|
/* don't allow partial writes */
|
|
if (*ppos != 0)
|
|
return 0;
|
|
if (count >= sizeof(ixgbe_dbg_netdev_ops_buf))
|
|
return -ENOSPC;
|
|
|
|
len = simple_write_to_buffer(ixgbe_dbg_netdev_ops_buf,
|
|
sizeof(ixgbe_dbg_netdev_ops_buf)-1,
|
|
ppos,
|
|
buffer,
|
|
count);
|
|
if (len < 0)
|
|
return len;
|
|
|
|
ixgbe_dbg_netdev_ops_buf[len] = '\0';
|
|
|
|
if (strncmp(ixgbe_dbg_netdev_ops_buf, "tx_timeout", 10) == 0) {
|
|
/* TX Queue number below is wrong, but ixgbe does not use it */
|
|
adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev,
|
|
UINT_MAX);
|
|
e_dev_info("tx_timeout called\n");
|
|
} else {
|
|
e_dev_info("Unknown command: %s\n", ixgbe_dbg_netdev_ops_buf);
|
|
e_dev_info("Available commands:\n");
|
|
e_dev_info(" tx_timeout\n");
|
|
}
|
|
return count;
|
|
}
|
|
|
|
static const struct file_operations ixgbe_dbg_netdev_ops_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = simple_open,
|
|
.read = ixgbe_dbg_netdev_ops_read,
|
|
.write = ixgbe_dbg_netdev_ops_write,
|
|
};
|
|
|
|
#define IXGBE_SFF_I2C_MAX 32
|
|
|
|
struct ixgbe_sff_i2c_ctx {
|
|
struct ixgbe_adapter *adapter;
|
|
int resp_len;
|
|
char resp[IXGBE_SFF_I2C_MAX * 3 + 16];
|
|
};
|
|
|
|
static int ixgbe_dbg_sff_i2c_open(struct inode *inode, struct file *filp)
|
|
{
|
|
struct ixgbe_sff_i2c_ctx *ctx;
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
ctx->adapter = inode->i_private;
|
|
filp->private_data = ctx;
|
|
return 0;
|
|
}
|
|
|
|
static int ixgbe_dbg_sff_i2c_release(struct inode *inode, struct file *filp)
|
|
{
|
|
kfree(filp->private_data);
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t ixgbe_dbg_sff_i2c_write(struct file *filp,
|
|
const char __user *ubuf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ixgbe_sff_i2c_ctx *ctx = filp->private_data;
|
|
struct ixgbe_hw *hw = &ctx->adapter->hw;
|
|
u8 data[IXGBE_SFF_I2C_MAX];
|
|
u8 wdata[IXGBE_SFF_I2C_MAX];
|
|
char cmd[160];
|
|
unsigned int addr, raddr, delay, n, wn, v;
|
|
int status, off, consumed, i;
|
|
char op;
|
|
|
|
if (*ppos != 0 || count >= sizeof(cmd))
|
|
return -EINVAL;
|
|
if (copy_from_user(cmd, ubuf, count))
|
|
return -EFAULT;
|
|
cmd[count] = '\0';
|
|
|
|
if (sscanf(cmd, " %c %x %n", &op, &addr, &off) < 2)
|
|
return -EINVAL;
|
|
|
|
if (op == 'r') {
|
|
if (sscanf(cmd + off, "%x", &n) != 1 || n < 1 ||
|
|
n > IXGBE_SFF_I2C_MAX)
|
|
return -EINVAL;
|
|
status = ixgbe_i2c_raw_read(hw, addr, data, n);
|
|
} else if (op == 'w') {
|
|
n = 0;
|
|
while (n < IXGBE_SFF_I2C_MAX &&
|
|
sscanf(cmd + off, "%x%n", &v, &consumed) == 1) {
|
|
data[n++] = v;
|
|
off += consumed;
|
|
}
|
|
status = ixgbe_i2c_raw_write(hw, addr, data, n);
|
|
} else if (op == 'x') {
|
|
if (sscanf(cmd + off, "%x %u %x %n", &raddr, &delay, &n,
|
|
&consumed) < 3)
|
|
return -EINVAL;
|
|
off += consumed;
|
|
if (n > IXGBE_SFF_I2C_MAX || delay > 50000)
|
|
return -EINVAL;
|
|
wn = 0;
|
|
while (wn < IXGBE_SFF_I2C_MAX &&
|
|
sscanf(cmd + off, "%x%n", &v, &consumed) == 1) {
|
|
wdata[wn++] = v;
|
|
off += consumed;
|
|
}
|
|
status = ixgbe_i2c_raw_xfer(hw, addr, wdata, wn, delay,
|
|
raddr, data, n);
|
|
} else {
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (status) {
|
|
ctx->resp_len = scnprintf(ctx->resp, sizeof(ctx->resp),
|
|
"err %d\n", status);
|
|
} else if (op == 'r' || (op == 'x' && n)) {
|
|
off = scnprintf(ctx->resp, sizeof(ctx->resp), "ok");
|
|
for (i = 0; i < n; i++)
|
|
off += scnprintf(ctx->resp + off,
|
|
sizeof(ctx->resp) - off,
|
|
" %02x", data[i]);
|
|
off += scnprintf(ctx->resp + off, sizeof(ctx->resp) - off,
|
|
"\n");
|
|
ctx->resp_len = off;
|
|
} else {
|
|
ctx->resp_len = scnprintf(ctx->resp, sizeof(ctx->resp), "ok\n");
|
|
}
|
|
|
|
*ppos = 0;
|
|
return count;
|
|
}
|
|
|
|
static ssize_t ixgbe_dbg_sff_i2c_read(struct file *filp, char __user *ubuf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ixgbe_sff_i2c_ctx *ctx = filp->private_data;
|
|
|
|
return simple_read_from_buffer(ubuf, count, ppos, ctx->resp,
|
|
ctx->resp_len);
|
|
}
|
|
|
|
static const struct file_operations ixgbe_dbg_sff_i2c_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = ixgbe_dbg_sff_i2c_open,
|
|
.release = ixgbe_dbg_sff_i2c_release,
|
|
.read = ixgbe_dbg_sff_i2c_read,
|
|
.write = ixgbe_dbg_sff_i2c_write,
|
|
};
|
|
|
|
/* In-kernel timestamp-latch experiments. The BAR is unmappable from userspace
|
|
* under IO_STRICT_DEVMEM, and the latch re-arms on RXSTMPH read, so the tight
|
|
* poll+drain loop lives here; userspace supplies the traffic concurrently.
|
|
*/
|
|
struct ixgbe_ts_bench_ctx {
|
|
struct ixgbe_adapter *adapter;
|
|
char resp[512];
|
|
int resp_len;
|
|
};
|
|
|
|
static int ixgbe_dbg_ts_bench_open(struct inode *inode, struct file *filp)
|
|
{
|
|
struct ixgbe_ts_bench_ctx *ctx;
|
|
|
|
ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
|
|
if (!ctx)
|
|
return -ENOMEM;
|
|
ctx->adapter = inode->i_private;
|
|
filp->private_data = ctx;
|
|
return 0;
|
|
}
|
|
|
|
static int ixgbe_dbg_ts_bench_release(struct inode *inode, struct file *filp)
|
|
{
|
|
kfree(filp->private_data);
|
|
return 0;
|
|
}
|
|
|
|
/* Wait up to ms for TSYNCRXCTL.VALID; return 1 if it armed. */
|
|
static int ixgbe_ts_wait_valid(struct ixgbe_hw *hw, unsigned int ms)
|
|
{
|
|
unsigned long end = jiffies + msecs_to_jiffies(ms);
|
|
|
|
do {
|
|
if (IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL) &
|
|
IXGBE_TSYNCRXCTL_VALID)
|
|
return 1;
|
|
cpu_relax();
|
|
cond_resched();
|
|
} while (time_before(jiffies, end));
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t ixgbe_dbg_ts_bench_write(struct file *filp,
|
|
const char __user *ubuf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ixgbe_ts_bench_ctx *ctx = filp->private_data;
|
|
struct ixgbe_hw *hw = &ctx->adapter->hw;
|
|
char cmd[64];
|
|
unsigned int arg;
|
|
u32 save_ctl, save_etqf3;
|
|
int off;
|
|
char op[16];
|
|
|
|
if (*ppos != 0 || count >= sizeof(cmd))
|
|
return -EINVAL;
|
|
if (copy_from_user(cmd, ubuf, count))
|
|
return -EFAULT;
|
|
cmd[count] = '\0';
|
|
|
|
if (sscanf(cmd, "%15s %n", op, &off) < 1)
|
|
return -EINVAL;
|
|
|
|
save_ctl = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
|
|
save_etqf3 = IXGBE_READ_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588));
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPH); /* drain any stale latch */
|
|
|
|
if (strcmp(op, "arm") == 0) {
|
|
/* arm <ctl>: write raw ctl, poll for a raw-frame latch. */
|
|
if (sscanf(cmd + off, "%x", &arg) != 1)
|
|
return -EINVAL;
|
|
IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, arg);
|
|
{
|
|
u32 rb = IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL);
|
|
int valid = ixgbe_ts_wait_valid(hw, 600);
|
|
|
|
ctx->resp_len = scnprintf(ctx->resp, sizeof(ctx->resp),
|
|
"ctl_wrote=%08x ctl_readback=%08x valid=%d STMPL=%08x STMPH=%08x SATRL=%08x SATRH=%08x\n",
|
|
arg, rb, valid,
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPL),
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPH),
|
|
IXGBE_READ_REG(hw, IXGBE_RXSATRL),
|
|
IXGBE_READ_REG(hw, IXGBE_RXSATRH));
|
|
}
|
|
} else if (strcmp(op, "control") == 0) {
|
|
/* Positive control: L2 PTPv2 event latch via ETQF slot 3. */
|
|
IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
|
|
IXGBE_ETQF_1588 | IXGBE_ETQF_FILTER_EN |
|
|
ETH_P_1588);
|
|
IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, IXGBE_TSYNCRXCTL_ENABLED |
|
|
IXGBE_TSYNCRXCTL_TYPE_L2_V2);
|
|
{
|
|
int valid = ixgbe_ts_wait_valid(hw, 600);
|
|
u32 satrh = IXGBE_READ_REG(hw, IXGBE_RXSATRH);
|
|
|
|
ctx->resp_len = scnprintf(ctx->resp, sizeof(ctx->resp),
|
|
"valid=%d STMPL=%08x STMPH=%08x SATRL=%08x SATRH=%08x satr_seq=%04x SYSTIML=%08x SYSTIMH=%08x\n",
|
|
valid,
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPL),
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPH),
|
|
IXGBE_READ_REG(hw, IXGBE_RXSATRL),
|
|
satrh, swab16(satrh >> 16),
|
|
IXGBE_READ_REG(hw, IXGBE_SYSTIML),
|
|
IXGBE_READ_REG(hw, IXGBE_SYSTIMH));
|
|
}
|
|
} else if (strcmp(op, "latchrate") == 0) {
|
|
/* latchrate <ms>: count serviced latches over the window while
|
|
* userspace floods L2 PTP frames. Re-arm by reading RXSTMPH.
|
|
*/
|
|
unsigned long end;
|
|
u32 captured = 0, distinct = 0;
|
|
unsigned long *seen;
|
|
|
|
if (sscanf(cmd + off, "%u", &arg) != 1 || arg == 0 || arg > 10000)
|
|
return -EINVAL;
|
|
seen = kcalloc(BITS_TO_LONGS(65536), sizeof(long), GFP_KERNEL);
|
|
if (!seen)
|
|
return -ENOMEM;
|
|
IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588),
|
|
IXGBE_ETQF_1588 | IXGBE_ETQF_FILTER_EN |
|
|
ETH_P_1588);
|
|
IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, IXGBE_TSYNCRXCTL_ENABLED |
|
|
IXGBE_TSYNCRXCTL_TYPE_L2_V2);
|
|
end = jiffies + msecs_to_jiffies(arg);
|
|
do {
|
|
if (IXGBE_READ_REG(hw, IXGBE_TSYNCRXCTL) &
|
|
IXGBE_TSYNCRXCTL_VALID) {
|
|
u32 seq = IXGBE_READ_REG(hw, IXGBE_RXSATRH) >>
|
|
16;
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPL);
|
|
IXGBE_READ_REG(hw, IXGBE_RXSTMPH); /* re-arm */
|
|
captured++;
|
|
if (!__test_and_set_bit(seq, seen))
|
|
distinct++;
|
|
}
|
|
cpu_relax();
|
|
cond_resched();
|
|
} while (time_before(jiffies, end));
|
|
ctx->resp_len = scnprintf(ctx->resp, sizeof(ctx->resp),
|
|
"window_ms=%u captured=%u distinct_seq=%u rate=%u/s\n",
|
|
arg, captured, distinct, captured * 1000 / arg);
|
|
kfree(seen);
|
|
} else {
|
|
return -EINVAL;
|
|
}
|
|
|
|
IXGBE_WRITE_REG(hw, IXGBE_TSYNCRXCTL, save_ctl);
|
|
IXGBE_WRITE_REG(hw, IXGBE_ETQF(IXGBE_ETQF_FILTER_1588), save_etqf3);
|
|
*ppos = 0;
|
|
return count;
|
|
}
|
|
|
|
static ssize_t ixgbe_dbg_ts_bench_read(struct file *filp, char __user *ubuf,
|
|
size_t count, loff_t *ppos)
|
|
{
|
|
struct ixgbe_ts_bench_ctx *ctx = filp->private_data;
|
|
|
|
return simple_read_from_buffer(ubuf, count, ppos, ctx->resp,
|
|
ctx->resp_len);
|
|
}
|
|
|
|
static const struct file_operations ixgbe_dbg_ts_bench_fops = {
|
|
.owner = THIS_MODULE,
|
|
.open = ixgbe_dbg_ts_bench_open,
|
|
.release = ixgbe_dbg_ts_bench_release,
|
|
.read = ixgbe_dbg_ts_bench_read,
|
|
.write = ixgbe_dbg_ts_bench_write,
|
|
};
|
|
|
|
/**
|
|
* ixgbe_dbg_adapter_init - setup the debugfs directory for the adapter
|
|
* @adapter: the adapter that is starting up
|
|
**/
|
|
void ixgbe_dbg_adapter_init(struct ixgbe_adapter *adapter)
|
|
{
|
|
const char *name = pci_name(adapter->pdev);
|
|
|
|
adapter->ixgbe_dbg_adapter = debugfs_create_dir(name, ixgbe_dbg_root);
|
|
debugfs_create_file("reg_ops", 0600, adapter->ixgbe_dbg_adapter,
|
|
adapter, &ixgbe_dbg_reg_ops_fops);
|
|
debugfs_create_file("netdev_ops", 0600, adapter->ixgbe_dbg_adapter,
|
|
adapter, &ixgbe_dbg_netdev_ops_fops);
|
|
debugfs_create_file("sff_i2c", 0600, adapter->ixgbe_dbg_adapter,
|
|
adapter, &ixgbe_dbg_sff_i2c_fops);
|
|
debugfs_create_file("ts_bench", 0600, adapter->ixgbe_dbg_adapter,
|
|
adapter, &ixgbe_dbg_ts_bench_fops);
|
|
}
|
|
|
|
/**
|
|
* ixgbe_dbg_adapter_exit - clear out the adapter's debugfs entries
|
|
* @adapter: the adapter that is exiting
|
|
**/
|
|
void ixgbe_dbg_adapter_exit(struct ixgbe_adapter *adapter)
|
|
{
|
|
debugfs_remove_recursive(adapter->ixgbe_dbg_adapter);
|
|
adapter->ixgbe_dbg_adapter = NULL;
|
|
}
|
|
|
|
/**
|
|
* ixgbe_dbg_init - start up debugfs for the driver
|
|
**/
|
|
void ixgbe_dbg_init(void)
|
|
{
|
|
ixgbe_dbg_root = debugfs_create_dir(ixgbe_driver_name, NULL);
|
|
}
|
|
|
|
/**
|
|
* ixgbe_dbg_exit - clean out the driver's debugfs entries
|
|
**/
|
|
void ixgbe_dbg_exit(void)
|
|
{
|
|
debugfs_remove_recursive(ixgbe_dbg_root);
|
|
}
|