2017-11-07 13:58:41 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-03-31 07:51:59 +00:00
|
|
|
/*
|
|
|
|
* Loopback bridge driver for the Greybus loopback module.
|
|
|
|
*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
* Copyright 2014 Linaro Ltd.
|
|
|
|
*/
|
2016-02-11 12:52:49 +00:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2015-07-28 17:34:36 +00:00
|
|
|
#include <linux/mutex.h>
|
2015-03-31 07:51:59 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/kthread.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/random.h>
|
2015-03-31 21:01:45 +00:00
|
|
|
#include <linux/sizes.h>
|
2015-07-28 17:34:38 +00:00
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/kfifo.h>
|
2015-08-16 23:55:03 +00:00
|
|
|
#include <linux/debugfs.h>
|
2015-09-14 09:48:46 +00:00
|
|
|
#include <linux/list_sort.h>
|
2015-12-07 01:59:05 +00:00
|
|
|
#include <linux/spinlock.h>
|
2015-12-07 01:59:06 +00:00
|
|
|
#include <linux/workqueue.h>
|
2015-12-11 13:46:52 +00:00
|
|
|
#include <linux/atomic.h>
|
2016-07-14 20:13:00 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2019-08-25 05:54:27 +00:00
|
|
|
#include <linux/greybus.h>
|
2015-04-16 07:53:59 +00:00
|
|
|
#include <asm/div64.h>
|
|
|
|
|
2015-08-11 12:50:54 +00:00
|
|
|
#define NSEC_PER_DAY 86400000000000ULL
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
struct gb_loopback_stats {
|
2015-08-03 17:57:14 +00:00
|
|
|
u32 min;
|
|
|
|
u32 max;
|
2015-07-21 22:50:08 +00:00
|
|
|
u64 sum;
|
2015-08-03 17:57:15 +00:00
|
|
|
u32 count;
|
2015-03-31 07:51:59 +00:00
|
|
|
};
|
|
|
|
|
2015-08-16 23:55:03 +00:00
|
|
|
struct gb_loopback_device {
|
|
|
|
struct dentry *root;
|
|
|
|
u32 count;
|
2015-12-03 17:29:41 +00:00
|
|
|
size_t size_max;
|
2015-08-16 23:55:04 +00:00
|
|
|
|
2015-12-07 01:59:05 +00:00
|
|
|
/* We need to take a lock in atomic context */
|
|
|
|
spinlock_t lock;
|
2015-12-07 01:59:06 +00:00
|
|
|
wait_queue_head_t wq;
|
2015-08-16 23:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct gb_loopback_device gb_dev;
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
struct gb_loopback_async_operation {
|
|
|
|
struct gb_loopback *gb;
|
|
|
|
struct gb_operation *operation;
|
2017-11-02 14:32:52 +00:00
|
|
|
ktime_t ts;
|
2015-12-07 01:59:06 +00:00
|
|
|
int (*completion)(struct gb_loopback_async_operation *op_async);
|
|
|
|
};
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
struct gb_loopback {
|
|
|
|
struct gb_connection *connection;
|
|
|
|
|
2015-08-16 23:55:03 +00:00
|
|
|
struct dentry *file;
|
2015-08-16 23:55:07 +00:00
|
|
|
struct kfifo kfifo_lat;
|
2015-07-28 17:34:36 +00:00
|
|
|
struct mutex mutex;
|
2015-03-31 07:51:59 +00:00
|
|
|
struct task_struct *task;
|
2015-12-11 10:49:45 +00:00
|
|
|
struct device *dev;
|
2015-12-03 17:29:41 +00:00
|
|
|
wait_queue_head_t wq;
|
2015-12-11 13:46:52 +00:00
|
|
|
wait_queue_head_t wq_completion;
|
|
|
|
atomic_t outstanding_operations;
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2015-08-16 23:55:04 +00:00
|
|
|
/* Per connection stats */
|
2017-11-02 14:32:52 +00:00
|
|
|
ktime_t ts;
|
2015-03-31 07:51:59 +00:00
|
|
|
struct gb_loopback_stats latency;
|
|
|
|
struct gb_loopback_stats throughput;
|
2015-07-21 22:50:10 +00:00
|
|
|
struct gb_loopback_stats requests_per_second;
|
2015-10-15 15:10:45 +00:00
|
|
|
struct gb_loopback_stats apbridge_unipro_latency;
|
2016-05-19 15:52:39 +00:00
|
|
|
struct gb_loopback_stats gbphy_firmware_latency;
|
2015-08-16 23:55:04 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
int type;
|
2015-12-07 01:59:06 +00:00
|
|
|
int async;
|
2015-12-11 10:49:45 +00:00
|
|
|
int id;
|
2015-12-03 17:29:41 +00:00
|
|
|
u32 size;
|
|
|
|
u32 iteration_max;
|
2015-08-16 23:55:04 +00:00
|
|
|
u32 iteration_count;
|
2015-12-07 01:59:07 +00:00
|
|
|
int us_wait;
|
2015-03-31 07:51:59 +00:00
|
|
|
u32 error;
|
2015-12-07 01:59:06 +00:00
|
|
|
u32 requests_completed;
|
|
|
|
u32 requests_timedout;
|
|
|
|
u32 timeout;
|
|
|
|
u32 jiffy_timeout;
|
|
|
|
u32 timeout_min;
|
|
|
|
u32 timeout_max;
|
2015-12-11 13:46:53 +00:00
|
|
|
u32 outstanding_operations_max;
|
2015-12-03 17:29:41 +00:00
|
|
|
u64 elapsed_nsecs;
|
2015-10-15 15:10:44 +00:00
|
|
|
u32 apbridge_latency_ts;
|
2016-05-19 15:52:39 +00:00
|
|
|
u32 gbphy_latency_ts;
|
2016-03-08 16:40:16 +00:00
|
|
|
|
|
|
|
u32 send_count;
|
2015-03-31 07:51:59 +00:00
|
|
|
};
|
|
|
|
|
2015-12-11 10:49:45 +00:00
|
|
|
static struct class loopback_class = {
|
|
|
|
.name = "gb_loopback",
|
|
|
|
};
|
|
|
|
static DEFINE_IDA(loopback_ida);
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
/* Min/max values in jiffies */
|
|
|
|
#define GB_LOOPBACK_TIMEOUT_MIN 1
|
|
|
|
#define GB_LOOPBACK_TIMEOUT_MAX 10000
|
|
|
|
|
2015-07-28 17:34:38 +00:00
|
|
|
#define GB_LOOPBACK_FIFO_DEFAULT 8192
|
|
|
|
|
2017-01-13 20:54:51 +00:00
|
|
|
static unsigned int kfifo_depth = GB_LOOPBACK_FIFO_DEFAULT;
|
2015-07-28 17:34:38 +00:00
|
|
|
module_param(kfifo_depth, uint, 0444);
|
|
|
|
|
|
|
|
/* Maximum size of any one send data buffer we support */
|
|
|
|
#define MAX_PACKET_SIZE (PAGE_SIZE * 2)
|
|
|
|
|
2015-12-07 01:59:07 +00:00
|
|
|
#define GB_LOOPBACK_US_WAIT_MAX 1000000
|
2015-03-31 07:51:59 +00:00
|
|
|
|
|
|
|
/* interface sysfs attributes */
|
2015-12-03 17:29:41 +00:00
|
|
|
#define gb_loopback_ro_attr(field) \
|
|
|
|
static ssize_t field##_show(struct device *dev, \
|
2015-03-31 07:51:59 +00:00
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2015-12-03 17:29:41 +00:00
|
|
|
return sprintf(buf, "%u\n", gb->field); \
|
2015-03-31 07:51:59 +00:00
|
|
|
} \
|
2015-12-03 17:29:41 +00:00
|
|
|
static DEVICE_ATTR_RO(field)
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
#define gb_loopback_ro_stats_attr(name, field, type) \
|
|
|
|
static ssize_t name##_##field##_show(struct device *dev, \
|
2015-03-31 07:51:59 +00:00
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2020-05-25 06:10:43 +00:00
|
|
|
/* Report 0 for min and max if no transfer succeeded */ \
|
2016-03-11 16:23:37 +00:00
|
|
|
if (!gb->requests_completed) \
|
|
|
|
return sprintf(buf, "0\n"); \
|
2018-12-04 20:58:20 +00:00
|
|
|
return sprintf(buf, "%" #type "\n", gb->name.field); \
|
2015-03-31 07:51:59 +00:00
|
|
|
} \
|
2015-12-03 17:29:41 +00:00
|
|
|
static DEVICE_ATTR_RO(name##_##field)
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
#define gb_loopback_ro_avg_attr(name) \
|
|
|
|
static ssize_t name##_avg_show(struct device *dev, \
|
2015-08-03 17:57:18 +00:00
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
2015-08-16 23:55:11 +00:00
|
|
|
struct gb_loopback_stats *stats; \
|
|
|
|
struct gb_loopback *gb; \
|
2016-02-25 17:19:16 +00:00
|
|
|
u64 avg, rem; \
|
|
|
|
u32 count; \
|
2015-12-11 10:49:45 +00:00
|
|
|
gb = dev_get_drvdata(dev); \
|
2015-12-03 17:29:41 +00:00
|
|
|
stats = &gb->name; \
|
2015-08-16 23:55:11 +00:00
|
|
|
count = stats->count ? stats->count : 1; \
|
2016-03-08 15:37:37 +00:00
|
|
|
avg = stats->sum + count / 2000000; /* round closest */ \
|
2015-08-16 23:55:11 +00:00
|
|
|
rem = do_div(avg, count); \
|
2016-03-08 15:37:36 +00:00
|
|
|
rem *= 1000000; \
|
|
|
|
do_div(rem, count); \
|
2016-02-25 17:19:16 +00:00
|
|
|
return sprintf(buf, "%llu.%06u\n", avg, (u32)rem); \
|
2015-08-03 17:57:18 +00:00
|
|
|
} \
|
2015-12-03 17:29:41 +00:00
|
|
|
static DEVICE_ATTR_RO(name##_avg)
|
2015-08-03 17:57:18 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
#define gb_loopback_stats_attrs(field) \
|
|
|
|
gb_loopback_ro_stats_attr(field, min, u); \
|
|
|
|
gb_loopback_ro_stats_attr(field, max, u); \
|
|
|
|
gb_loopback_ro_avg_attr(field)
|
2015-03-31 07:51:59 +00:00
|
|
|
|
|
|
|
#define gb_loopback_attr(field, type) \
|
|
|
|
static ssize_t field##_show(struct device *dev, \
|
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2018-12-04 20:58:20 +00:00
|
|
|
return sprintf(buf, "%" #type "\n", gb->field); \
|
2015-03-31 07:51:59 +00:00
|
|
|
} \
|
|
|
|
static ssize_t field##_store(struct device *dev, \
|
|
|
|
struct device_attribute *attr, \
|
|
|
|
const char *buf, \
|
|
|
|
size_t len) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2015-12-03 17:29:41 +00:00
|
|
|
mutex_lock(&gb->mutex); \
|
2015-03-31 07:51:59 +00:00
|
|
|
ret = sscanf(buf, "%"#type, &gb->field); \
|
|
|
|
if (ret != 1) \
|
2015-07-28 17:34:36 +00:00
|
|
|
len = -EINVAL; \
|
|
|
|
else \
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_check_attr(gb, bundle); \
|
|
|
|
mutex_unlock(&gb->mutex); \
|
2015-03-31 07:51:59 +00:00
|
|
|
return len; \
|
|
|
|
} \
|
|
|
|
static DEVICE_ATTR_RW(field)
|
|
|
|
|
2015-08-16 23:55:11 +00:00
|
|
|
#define gb_dev_loopback_ro_attr(field, conn) \
|
|
|
|
static ssize_t field##_show(struct device *dev, \
|
2015-08-16 23:55:04 +00:00
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2015-12-03 17:29:41 +00:00
|
|
|
return sprintf(buf, "%u\n", gb->field); \
|
2015-08-16 23:55:04 +00:00
|
|
|
} \
|
|
|
|
static DEVICE_ATTR_RO(field)
|
|
|
|
|
|
|
|
#define gb_dev_loopback_rw_attr(field, type) \
|
|
|
|
static ssize_t field##_show(struct device *dev, \
|
|
|
|
struct device_attribute *attr, \
|
|
|
|
char *buf) \
|
|
|
|
{ \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2018-12-04 20:58:20 +00:00
|
|
|
return sprintf(buf, "%" #type "\n", gb->field); \
|
2015-08-16 23:55:04 +00:00
|
|
|
} \
|
|
|
|
static ssize_t field##_store(struct device *dev, \
|
|
|
|
struct device_attribute *attr, \
|
|
|
|
const char *buf, \
|
|
|
|
size_t len) \
|
|
|
|
{ \
|
|
|
|
int ret; \
|
2015-12-11 10:49:45 +00:00
|
|
|
struct gb_loopback *gb = dev_get_drvdata(dev); \
|
2015-12-03 17:29:41 +00:00
|
|
|
mutex_lock(&gb->mutex); \
|
|
|
|
ret = sscanf(buf, "%"#type, &gb->field); \
|
2015-08-16 23:55:04 +00:00
|
|
|
if (ret != 1) \
|
|
|
|
len = -EINVAL; \
|
|
|
|
else \
|
2015-12-11 10:49:45 +00:00
|
|
|
gb_loopback_check_attr(gb); \
|
2015-12-03 17:29:41 +00:00
|
|
|
mutex_unlock(&gb->mutex); \
|
2015-08-16 23:55:04 +00:00
|
|
|
return len; \
|
|
|
|
} \
|
|
|
|
static DEVICE_ATTR_RW(field)
|
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
static void gb_loopback_reset_stats(struct gb_loopback *gb);
|
2015-12-11 10:49:45 +00:00
|
|
|
static void gb_loopback_check_attr(struct gb_loopback *gb)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2015-12-07 01:59:07 +00:00
|
|
|
if (gb->us_wait > GB_LOOPBACK_US_WAIT_MAX)
|
|
|
|
gb->us_wait = GB_LOOPBACK_US_WAIT_MAX;
|
2015-12-03 17:29:41 +00:00
|
|
|
if (gb->size > gb_dev.size_max)
|
|
|
|
gb->size = gb_dev.size_max;
|
2015-12-07 01:59:06 +00:00
|
|
|
gb->requests_timedout = 0;
|
|
|
|
gb->requests_completed = 0;
|
2015-12-03 17:29:41 +00:00
|
|
|
gb->iteration_count = 0;
|
2016-03-08 16:40:16 +00:00
|
|
|
gb->send_count = 0;
|
2015-12-03 17:29:41 +00:00
|
|
|
gb->error = 0;
|
|
|
|
|
|
|
|
if (kfifo_depth < gb->iteration_max) {
|
2015-12-11 10:49:45 +00:00
|
|
|
dev_warn(gb->dev,
|
2015-12-03 17:29:41 +00:00
|
|
|
"cannot log bytes %u kfifo_depth %u\n",
|
|
|
|
gb->iteration_max, kfifo_depth);
|
2015-07-28 17:34:39 +00:00
|
|
|
}
|
2015-12-03 17:29:41 +00:00
|
|
|
kfifo_reset_out(&gb->kfifo_lat);
|
2015-07-28 17:34:39 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
switch (gb->type) {
|
2015-07-13 19:20:48 +00:00
|
|
|
case GB_LOOPBACK_TYPE_PING:
|
|
|
|
case GB_LOOPBACK_TYPE_TRANSFER:
|
2015-07-13 19:20:49 +00:00
|
|
|
case GB_LOOPBACK_TYPE_SINK:
|
2015-12-07 01:59:06 +00:00
|
|
|
gb->jiffy_timeout = usecs_to_jiffies(gb->timeout);
|
|
|
|
if (!gb->jiffy_timeout)
|
|
|
|
gb->jiffy_timeout = GB_LOOPBACK_TIMEOUT_MIN;
|
|
|
|
else if (gb->jiffy_timeout > GB_LOOPBACK_TIMEOUT_MAX)
|
|
|
|
gb->jiffy_timeout = GB_LOOPBACK_TIMEOUT_MAX;
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_reset_stats(gb);
|
|
|
|
wake_up(&gb->wq);
|
2015-07-13 19:20:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2015-12-03 17:29:41 +00:00
|
|
|
gb->type = 0;
|
2015-07-13 19:20:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Time to send and receive one message */
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_stats_attrs(latency);
|
2015-07-21 22:50:10 +00:00
|
|
|
/* Number of requests sent per second on this cport */
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_stats_attrs(requests_per_second);
|
2015-03-31 07:51:59 +00:00
|
|
|
/* Quantity of data sent and received on this cport */
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_stats_attrs(throughput);
|
2015-10-15 15:10:45 +00:00
|
|
|
/* Latency across the UniPro link from APBridge's perspective */
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_stats_attrs(apbridge_unipro_latency);
|
2015-10-15 15:10:45 +00:00
|
|
|
/* Firmware induced overhead in the GPBridge */
|
2016-05-19 15:52:39 +00:00
|
|
|
gb_loopback_stats_attrs(gbphy_firmware_latency);
|
2015-12-03 17:29:41 +00:00
|
|
|
|
2015-07-21 22:50:09 +00:00
|
|
|
/* Number of errors encountered during loop */
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_ro_attr(error);
|
2015-12-07 01:59:06 +00:00
|
|
|
/* Number of requests successfully completed async */
|
|
|
|
gb_loopback_ro_attr(requests_completed);
|
|
|
|
/* Number of requests timed out async */
|
|
|
|
gb_loopback_ro_attr(requests_timedout);
|
|
|
|
/* Timeout minimum in useconds */
|
|
|
|
gb_loopback_ro_attr(timeout_min);
|
|
|
|
/* Timeout minimum in useconds */
|
|
|
|
gb_loopback_ro_attr(timeout_max);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
|
|
|
/*
|
2015-07-21 22:50:07 +00:00
|
|
|
* Type of loopback message to send based on protocol type definitions
|
2015-03-31 07:51:59 +00:00
|
|
|
* 0 => Don't send message
|
2015-07-21 22:50:07 +00:00
|
|
|
* 2 => Send ping message continuously (message without payload)
|
2015-08-03 17:57:10 +00:00
|
|
|
* 3 => Send transfer message continuously (message with payload,
|
2015-07-21 22:50:07 +00:00
|
|
|
* payload returned in response)
|
|
|
|
* 4 => Send a sink message (message with payload, no payload in response)
|
2015-03-31 07:51:59 +00:00
|
|
|
*/
|
2015-08-16 23:55:04 +00:00
|
|
|
gb_dev_loopback_rw_attr(type, d);
|
2015-03-31 07:51:59 +00:00
|
|
|
/* Size of transfer message payload: 0-4096 bytes */
|
2015-08-16 23:55:04 +00:00
|
|
|
gb_dev_loopback_rw_attr(size, u);
|
2015-05-12 02:16:36 +00:00
|
|
|
/* Time to wait between two messages: 0-1000 ms */
|
2015-12-07 01:59:07 +00:00
|
|
|
gb_dev_loopback_rw_attr(us_wait, d);
|
2015-07-21 22:50:08 +00:00
|
|
|
/* Maximum iterations for a given operation: 1-(2^32-1), 0 implies infinite */
|
2015-08-16 23:55:04 +00:00
|
|
|
gb_dev_loopback_rw_attr(iteration_max, u);
|
|
|
|
/* The current index of the for (i = 0; i < iteration_max; i++) loop */
|
2015-08-16 23:55:11 +00:00
|
|
|
gb_dev_loopback_ro_attr(iteration_count, false);
|
2015-12-07 01:59:06 +00:00
|
|
|
/* A flag to indicate synchronous or asynchronous operations */
|
|
|
|
gb_dev_loopback_rw_attr(async, u);
|
|
|
|
/* Timeout of an individual asynchronous request */
|
|
|
|
gb_dev_loopback_rw_attr(timeout, u);
|
2015-12-11 13:46:53 +00:00
|
|
|
/* Maximum number of in-flight operations before back-off */
|
|
|
|
gb_dev_loopback_rw_attr(outstanding_operations_max, u);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
static struct attribute *loopback_attrs[] = {
|
|
|
|
&dev_attr_latency_min.attr,
|
|
|
|
&dev_attr_latency_max.attr,
|
|
|
|
&dev_attr_latency_avg.attr,
|
|
|
|
&dev_attr_requests_per_second_min.attr,
|
|
|
|
&dev_attr_requests_per_second_max.attr,
|
|
|
|
&dev_attr_requests_per_second_avg.attr,
|
|
|
|
&dev_attr_throughput_min.attr,
|
|
|
|
&dev_attr_throughput_max.attr,
|
|
|
|
&dev_attr_throughput_avg.attr,
|
|
|
|
&dev_attr_apbridge_unipro_latency_min.attr,
|
|
|
|
&dev_attr_apbridge_unipro_latency_max.attr,
|
|
|
|
&dev_attr_apbridge_unipro_latency_avg.attr,
|
2016-05-19 15:52:39 +00:00
|
|
|
&dev_attr_gbphy_firmware_latency_min.attr,
|
|
|
|
&dev_attr_gbphy_firmware_latency_max.attr,
|
|
|
|
&dev_attr_gbphy_firmware_latency_avg.attr,
|
2015-03-31 07:51:59 +00:00
|
|
|
&dev_attr_type.attr,
|
|
|
|
&dev_attr_size.attr,
|
2015-12-07 01:59:07 +00:00
|
|
|
&dev_attr_us_wait.attr,
|
2015-07-21 22:50:08 +00:00
|
|
|
&dev_attr_iteration_count.attr,
|
|
|
|
&dev_attr_iteration_max.attr,
|
2015-12-07 01:59:06 +00:00
|
|
|
&dev_attr_async.attr,
|
2015-12-03 17:29:41 +00:00
|
|
|
&dev_attr_error.attr,
|
2015-12-07 01:59:06 +00:00
|
|
|
&dev_attr_requests_completed.attr,
|
|
|
|
&dev_attr_requests_timedout.attr,
|
|
|
|
&dev_attr_timeout.attr,
|
2015-12-11 13:46:53 +00:00
|
|
|
&dev_attr_outstanding_operations_max.attr,
|
2015-12-07 01:59:06 +00:00
|
|
|
&dev_attr_timeout_min.attr,
|
|
|
|
&dev_attr_timeout_max.attr,
|
2015-03-31 07:51:59 +00:00
|
|
|
NULL,
|
|
|
|
};
|
2015-12-03 17:29:41 +00:00
|
|
|
ATTRIBUTE_GROUPS(loopback);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2016-02-25 17:19:15 +00:00
|
|
|
static void gb_loopback_calculate_stats(struct gb_loopback *gb, bool error);
|
2015-12-07 01:59:06 +00:00
|
|
|
|
2015-08-16 23:55:05 +00:00
|
|
|
static u32 gb_loopback_nsec_to_usec_latency(u64 elapsed_nsecs)
|
|
|
|
{
|
|
|
|
do_div(elapsed_nsecs, NSEC_PER_USEC);
|
2017-03-25 05:20:07 +00:00
|
|
|
return elapsed_nsecs;
|
2015-08-16 23:55:05 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 23:55:06 +00:00
|
|
|
static u64 __gb_loopback_calc_latency(u64 t1, u64 t2)
|
|
|
|
{
|
|
|
|
if (t2 > t1)
|
|
|
|
return t2 - t1;
|
|
|
|
else
|
|
|
|
return NSEC_PER_DAY - t2 + t1;
|
|
|
|
}
|
|
|
|
|
2017-11-02 14:32:52 +00:00
|
|
|
static u64 gb_loopback_calc_latency(ktime_t ts, ktime_t te)
|
2015-08-11 12:50:53 +00:00
|
|
|
{
|
2017-11-02 14:32:52 +00:00
|
|
|
return __gb_loopback_calc_latency(ktime_to_ns(ts), ktime_to_ns(te));
|
2015-08-11 12:50:53 +00:00
|
|
|
}
|
|
|
|
|
2015-09-14 09:48:47 +00:00
|
|
|
static int gb_loopback_operation_sync(struct gb_loopback *gb, int type,
|
|
|
|
void *request, int request_size,
|
|
|
|
void *response, int response_size)
|
2015-07-13 19:20:49 +00:00
|
|
|
{
|
2015-09-14 09:48:47 +00:00
|
|
|
struct gb_operation *operation;
|
2017-11-02 14:32:52 +00:00
|
|
|
ktime_t ts, te;
|
2015-09-14 09:48:47 +00:00
|
|
|
int ret;
|
2015-07-13 19:20:49 +00:00
|
|
|
|
2017-11-02 14:32:52 +00:00
|
|
|
ts = ktime_get();
|
2015-09-14 09:48:47 +00:00
|
|
|
operation = gb_operation_create(gb->connection, type, request_size,
|
|
|
|
response_size, GFP_KERNEL);
|
2016-02-25 17:19:14 +00:00
|
|
|
if (!operation)
|
|
|
|
return -ENOMEM;
|
2015-07-13 19:20:50 +00:00
|
|
|
|
2015-09-14 09:48:47 +00:00
|
|
|
if (request_size)
|
|
|
|
memcpy(operation->request->payload, request, request_size);
|
|
|
|
|
|
|
|
ret = gb_operation_request_send_sync(operation);
|
|
|
|
if (ret) {
|
2015-10-16 23:55:46 +00:00
|
|
|
dev_err(&gb->connection->bundle->dev,
|
2015-09-14 09:48:47 +00:00
|
|
|
"synchronous operation failed: %d\n", ret);
|
2016-02-25 17:19:14 +00:00
|
|
|
goto out_put_operation;
|
2015-09-14 09:48:47 +00:00
|
|
|
} else {
|
|
|
|
if (response_size == operation->response->payload_size) {
|
|
|
|
memcpy(response, operation->response->payload,
|
|
|
|
response_size);
|
|
|
|
} else {
|
2015-10-16 23:55:46 +00:00
|
|
|
dev_err(&gb->connection->bundle->dev,
|
2015-09-14 09:48:47 +00:00
|
|
|
"response size %zu expected %d\n",
|
|
|
|
operation->response->payload_size,
|
|
|
|
response_size);
|
2016-02-25 17:19:14 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_put_operation;
|
2015-09-14 09:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-27 00:59:15 +00:00
|
|
|
|
2017-11-02 14:32:52 +00:00
|
|
|
te = ktime_get();
|
2015-08-16 23:55:02 +00:00
|
|
|
|
|
|
|
/* Calculate the total time the message took */
|
2017-11-02 14:32:52 +00:00
|
|
|
gb->elapsed_nsecs = gb_loopback_calc_latency(ts, te);
|
2015-08-16 23:55:02 +00:00
|
|
|
|
2016-02-25 17:19:14 +00:00
|
|
|
out_put_operation:
|
|
|
|
gb_operation_put(operation);
|
|
|
|
|
2015-09-14 09:48:47 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-07-13 19:20:49 +00:00
|
|
|
|
2015-12-11 13:46:52 +00:00
|
|
|
static void gb_loopback_async_wait_all(struct gb_loopback *gb)
|
|
|
|
{
|
|
|
|
wait_event(gb->wq_completion,
|
|
|
|
!atomic_read(&gb->outstanding_operations));
|
|
|
|
}
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
static void gb_loopback_async_operation_callback(struct gb_operation *operation)
|
|
|
|
{
|
|
|
|
struct gb_loopback_async_operation *op_async;
|
|
|
|
struct gb_loopback *gb;
|
2017-11-02 14:32:52 +00:00
|
|
|
ktime_t te;
|
2017-11-06 01:32:22 +00:00
|
|
|
int result;
|
2015-12-07 01:59:06 +00:00
|
|
|
|
2017-11-02 14:32:52 +00:00
|
|
|
te = ktime_get();
|
2017-11-06 01:32:22 +00:00
|
|
|
result = gb_operation_result(operation);
|
|
|
|
op_async = gb_operation_get_data(operation);
|
2015-12-07 01:59:06 +00:00
|
|
|
gb = op_async->gb;
|
2017-11-06 01:32:22 +00:00
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
mutex_lock(&gb->mutex);
|
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
if (!result && op_async->completion)
|
|
|
|
result = op_async->completion(op_async);
|
2015-12-07 01:59:06 +00:00
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
if (!result) {
|
2017-11-02 14:32:52 +00:00
|
|
|
gb->elapsed_nsecs = gb_loopback_calc_latency(op_async->ts, te);
|
2017-11-06 01:32:22 +00:00
|
|
|
} else {
|
|
|
|
gb->error++;
|
|
|
|
if (result == -ETIMEDOUT)
|
|
|
|
gb->requests_timedout++;
|
2015-12-07 01:59:06 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
gb->iteration_count++;
|
|
|
|
gb_loopback_calculate_stats(gb, result);
|
2015-12-07 01:59:06 +00:00
|
|
|
|
|
|
|
mutex_unlock(&gb->mutex);
|
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
dev_dbg(&gb->connection->bundle->dev, "complete operation %d\n",
|
2015-12-07 01:59:06 +00:00
|
|
|
operation->id);
|
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
/* Wake up waiters */
|
|
|
|
atomic_dec(&op_async->gb->outstanding_operations);
|
|
|
|
wake_up(&gb->wq_completion);
|
2015-12-07 01:59:06 +00:00
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
/* Release resources */
|
|
|
|
gb_operation_put(operation);
|
|
|
|
kfree(op_async);
|
2015-12-07 01:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_loopback_async_operation(struct gb_loopback *gb, int type,
|
|
|
|
void *request, int request_size,
|
|
|
|
int response_size,
|
|
|
|
void *completion)
|
|
|
|
{
|
|
|
|
struct gb_loopback_async_operation *op_async;
|
|
|
|
struct gb_operation *operation;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
op_async = kzalloc(sizeof(*op_async), GFP_KERNEL);
|
|
|
|
if (!op_async)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
operation = gb_operation_create(gb->connection, type, request_size,
|
|
|
|
response_size, GFP_KERNEL);
|
|
|
|
if (!operation) {
|
2015-12-11 13:46:51 +00:00
|
|
|
kfree(op_async);
|
|
|
|
return -ENOMEM;
|
2015-12-07 01:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (request_size)
|
|
|
|
memcpy(operation->request->payload, request, request_size);
|
|
|
|
|
2017-11-06 01:32:22 +00:00
|
|
|
gb_operation_set_data(operation, op_async);
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
op_async->gb = gb;
|
|
|
|
op_async->operation = operation;
|
|
|
|
op_async->completion = completion;
|
|
|
|
|
2017-11-02 14:32:52 +00:00
|
|
|
op_async->ts = ktime_get();
|
2017-11-06 01:32:22 +00:00
|
|
|
|
2015-12-11 13:46:52 +00:00
|
|
|
atomic_inc(&gb->outstanding_operations);
|
2015-12-07 01:59:06 +00:00
|
|
|
ret = gb_operation_request_send(operation,
|
|
|
|
gb_loopback_async_operation_callback,
|
2017-11-06 01:32:22 +00:00
|
|
|
jiffies_to_msecs(gb->jiffy_timeout),
|
2015-12-07 01:59:06 +00:00
|
|
|
GFP_KERNEL);
|
2017-11-06 01:32:22 +00:00
|
|
|
if (ret) {
|
|
|
|
atomic_dec(&gb->outstanding_operations);
|
|
|
|
gb_operation_put(operation);
|
|
|
|
kfree(op_async);
|
|
|
|
}
|
2015-12-07 01:59:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_loopback_sync_sink(struct gb_loopback *gb, u32 len)
|
2015-09-14 09:48:47 +00:00
|
|
|
{
|
|
|
|
struct gb_loopback_transfer_request *request;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
request = kmalloc(len + sizeof(*request), GFP_KERNEL);
|
|
|
|
if (!request)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
request->len = cpu_to_le32(len);
|
|
|
|
retval = gb_loopback_operation_sync(gb, GB_LOOPBACK_TYPE_SINK,
|
|
|
|
request, len + sizeof(*request),
|
|
|
|
NULL, 0);
|
2015-07-13 19:20:49 +00:00
|
|
|
kfree(request);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
static int gb_loopback_sync_transfer(struct gb_loopback *gb, u32 len)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
|
|
|
struct gb_loopback_transfer_request *request;
|
|
|
|
struct gb_loopback_transfer_response *response;
|
|
|
|
int retval;
|
|
|
|
|
2015-12-03 17:29:39 +00:00
|
|
|
gb->apbridge_latency_ts = 0;
|
2016-05-19 15:52:39 +00:00
|
|
|
gb->gbphy_latency_ts = 0;
|
2015-12-03 17:29:39 +00:00
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
request = kmalloc(len + sizeof(*request), GFP_KERNEL);
|
|
|
|
if (!request)
|
|
|
|
return -ENOMEM;
|
|
|
|
response = kmalloc(len + sizeof(*response), GFP_KERNEL);
|
|
|
|
if (!response) {
|
|
|
|
kfree(request);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2015-08-14 11:37:10 +00:00
|
|
|
memset(request->data, 0x5A, len);
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
request->len = cpu_to_le32(len);
|
2015-09-14 09:48:47 +00:00
|
|
|
retval = gb_loopback_operation_sync(gb, GB_LOOPBACK_TYPE_TRANSFER,
|
|
|
|
request, len + sizeof(*request),
|
|
|
|
response, len + sizeof(*response));
|
2015-03-31 07:51:59 +00:00
|
|
|
if (retval)
|
|
|
|
goto gb_error;
|
|
|
|
|
2015-08-14 11:37:11 +00:00
|
|
|
if (memcmp(request->data, response->data, len)) {
|
2015-10-16 23:55:46 +00:00
|
|
|
dev_err(&gb->connection->bundle->dev,
|
|
|
|
"Loopback Data doesn't match\n");
|
2015-03-31 07:51:59 +00:00
|
|
|
retval = -EREMOTEIO;
|
2015-08-14 11:37:11 +00:00
|
|
|
}
|
2015-10-15 15:10:45 +00:00
|
|
|
gb->apbridge_latency_ts = (u32)__le32_to_cpu(response->reserved0);
|
2016-05-19 15:52:39 +00:00
|
|
|
gb->gbphy_latency_ts = (u32)__le32_to_cpu(response->reserved1);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
|
|
|
gb_error:
|
|
|
|
kfree(request);
|
|
|
|
kfree(response);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
static int gb_loopback_sync_ping(struct gb_loopback *gb)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2015-09-14 09:48:47 +00:00
|
|
|
return gb_loopback_operation_sync(gb, GB_LOOPBACK_TYPE_PING,
|
|
|
|
NULL, 0, NULL, 0);
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
static int gb_loopback_async_sink(struct gb_loopback *gb, u32 len)
|
|
|
|
{
|
|
|
|
struct gb_loopback_transfer_request *request;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
request = kmalloc(len + sizeof(*request), GFP_KERNEL);
|
|
|
|
if (!request)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
request->len = cpu_to_le32(len);
|
|
|
|
retval = gb_loopback_async_operation(gb, GB_LOOPBACK_TYPE_SINK,
|
|
|
|
request, len + sizeof(*request),
|
|
|
|
0, NULL);
|
|
|
|
kfree(request);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_loopback_async_transfer_complete(
|
|
|
|
struct gb_loopback_async_operation *op_async)
|
|
|
|
{
|
|
|
|
struct gb_loopback *gb;
|
|
|
|
struct gb_operation *operation;
|
|
|
|
struct gb_loopback_transfer_request *request;
|
|
|
|
struct gb_loopback_transfer_response *response;
|
|
|
|
size_t len;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
gb = op_async->gb;
|
|
|
|
operation = op_async->operation;
|
|
|
|
request = operation->request->payload;
|
|
|
|
response = operation->response->payload;
|
|
|
|
len = le32_to_cpu(request->len);
|
|
|
|
|
|
|
|
if (memcmp(request->data, response->data, len)) {
|
|
|
|
dev_err(&gb->connection->bundle->dev,
|
|
|
|
"Loopback Data doesn't match operation id %d\n",
|
|
|
|
operation->id);
|
|
|
|
retval = -EREMOTEIO;
|
|
|
|
} else {
|
|
|
|
gb->apbridge_latency_ts =
|
|
|
|
(u32)__le32_to_cpu(response->reserved0);
|
2016-05-19 15:52:39 +00:00
|
|
|
gb->gbphy_latency_ts =
|
2015-12-07 01:59:06 +00:00
|
|
|
(u32)__le32_to_cpu(response->reserved1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_loopback_async_transfer(struct gb_loopback *gb, u32 len)
|
|
|
|
{
|
|
|
|
struct gb_loopback_transfer_request *request;
|
|
|
|
int retval, response_len;
|
|
|
|
|
|
|
|
request = kmalloc(len + sizeof(*request), GFP_KERNEL);
|
|
|
|
if (!request)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
memset(request->data, 0x5A, len);
|
|
|
|
|
|
|
|
request->len = cpu_to_le32(len);
|
|
|
|
response_len = sizeof(struct gb_loopback_transfer_response);
|
|
|
|
retval = gb_loopback_async_operation(gb, GB_LOOPBACK_TYPE_TRANSFER,
|
|
|
|
request, len + sizeof(*request),
|
|
|
|
len + response_len,
|
|
|
|
gb_loopback_async_transfer_complete);
|
|
|
|
if (retval)
|
|
|
|
goto gb_error;
|
|
|
|
|
|
|
|
gb_error:
|
|
|
|
kfree(request);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gb_loopback_async_ping(struct gb_loopback *gb)
|
|
|
|
{
|
|
|
|
return gb_loopback_async_operation(gb, GB_LOOPBACK_TYPE_PING,
|
|
|
|
NULL, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
static int gb_loopback_request_handler(struct gb_operation *operation)
|
2015-05-12 02:16:39 +00:00
|
|
|
{
|
|
|
|
struct gb_connection *connection = operation->connection;
|
|
|
|
struct gb_loopback_transfer_request *request;
|
|
|
|
struct gb_loopback_transfer_response *response;
|
2015-10-16 23:55:46 +00:00
|
|
|
struct device *dev = &connection->bundle->dev;
|
2015-07-13 23:53:13 +00:00
|
|
|
size_t len;
|
2015-05-12 02:16:39 +00:00
|
|
|
|
|
|
|
/* By convention, the AP initiates the version operation */
|
2016-02-12 10:38:29 +00:00
|
|
|
switch (operation->type) {
|
2015-05-12 02:16:39 +00:00
|
|
|
case GB_LOOPBACK_TYPE_PING:
|
2015-07-13 19:20:49 +00:00
|
|
|
case GB_LOOPBACK_TYPE_SINK:
|
2015-05-12 02:16:39 +00:00
|
|
|
return 0;
|
|
|
|
case GB_LOOPBACK_TYPE_TRANSFER:
|
|
|
|
if (operation->request->payload_size < sizeof(*request)) {
|
2015-10-16 23:55:46 +00:00
|
|
|
dev_err(dev, "transfer request too small (%zu < %zu)\n",
|
2015-05-12 02:16:39 +00:00
|
|
|
operation->request->payload_size,
|
|
|
|
sizeof(*request));
|
|
|
|
return -EINVAL; /* -EMSGSIZE */
|
|
|
|
}
|
|
|
|
request = operation->request->payload;
|
|
|
|
len = le32_to_cpu(request->len);
|
2015-08-16 23:55:04 +00:00
|
|
|
if (len > gb_dev.size_max) {
|
2015-10-16 23:55:46 +00:00
|
|
|
dev_err(dev, "transfer request too large (%zu > %zu)\n",
|
2015-08-16 23:55:04 +00:00
|
|
|
len, gb_dev.size_max);
|
2015-07-13 19:20:50 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-11-19 12:46:43 +00:00
|
|
|
if (!gb_operation_response_alloc(operation,
|
|
|
|
len + sizeof(*response), GFP_KERNEL)) {
|
|
|
|
dev_err(dev, "error allocating response\n");
|
|
|
|
return -ENOMEM;
|
2015-05-12 02:16:39 +00:00
|
|
|
}
|
2015-11-19 12:46:43 +00:00
|
|
|
response = operation->response->payload;
|
|
|
|
response->len = cpu_to_le32(len);
|
|
|
|
if (len)
|
|
|
|
memcpy(response->data, request->data, len);
|
|
|
|
|
2015-05-12 02:16:39 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
2016-02-12 10:38:29 +00:00
|
|
|
dev_err(dev, "unsupported request: %u\n", operation->type);
|
2015-05-12 02:16:39 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
static void gb_loopback_reset_stats(struct gb_loopback *gb)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
|
|
|
struct gb_loopback_stats reset = {
|
2015-08-03 17:57:14 +00:00
|
|
|
.min = U32_MAX,
|
2015-03-31 07:51:59 +00:00
|
|
|
};
|
2015-08-16 23:55:04 +00:00
|
|
|
|
|
|
|
/* Reset per-connection stats */
|
2015-12-03 17:29:41 +00:00
|
|
|
memcpy(&gb->latency, &reset,
|
|
|
|
sizeof(struct gb_loopback_stats));
|
|
|
|
memcpy(&gb->throughput, &reset,
|
|
|
|
sizeof(struct gb_loopback_stats));
|
|
|
|
memcpy(&gb->requests_per_second, &reset,
|
|
|
|
sizeof(struct gb_loopback_stats));
|
|
|
|
memcpy(&gb->apbridge_unipro_latency, &reset,
|
|
|
|
sizeof(struct gb_loopback_stats));
|
2016-05-19 15:52:39 +00:00
|
|
|
memcpy(&gb->gbphy_firmware_latency, &reset,
|
2015-12-03 17:29:41 +00:00
|
|
|
sizeof(struct gb_loopback_stats));
|
2015-08-16 23:55:04 +00:00
|
|
|
|
2015-12-07 01:59:08 +00:00
|
|
|
/* Should be initialized at least once per transaction set */
|
|
|
|
gb->apbridge_latency_ts = 0;
|
2016-05-19 15:52:39 +00:00
|
|
|
gb->gbphy_latency_ts = 0;
|
2017-11-02 14:32:52 +00:00
|
|
|
gb->ts = ktime_set(0, 0);
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 17:57:13 +00:00
|
|
|
static void gb_loopback_update_stats(struct gb_loopback_stats *stats, u32 val)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2015-07-21 22:50:08 +00:00
|
|
|
if (stats->min > val)
|
|
|
|
stats->min = val;
|
|
|
|
if (stats->max < val)
|
|
|
|
stats->max = val;
|
|
|
|
stats->sum += val;
|
|
|
|
stats->count++;
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 17:19:15 +00:00
|
|
|
static void gb_loopback_update_stats_window(struct gb_loopback_stats *stats,
|
|
|
|
u64 val, u32 count)
|
|
|
|
{
|
|
|
|
stats->sum += val;
|
|
|
|
stats->count += count;
|
|
|
|
|
|
|
|
do_div(val, count);
|
|
|
|
if (stats->min > val)
|
|
|
|
stats->min = val;
|
|
|
|
if (stats->max < val)
|
|
|
|
stats->max = val;
|
|
|
|
}
|
|
|
|
|
2015-07-21 22:50:10 +00:00
|
|
|
static void gb_loopback_requests_update(struct gb_loopback *gb, u32 latency)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2016-02-25 17:19:15 +00:00
|
|
|
u64 req = gb->requests_completed * USEC_PER_SEC;
|
2015-07-21 22:50:08 +00:00
|
|
|
|
2016-02-25 17:19:15 +00:00
|
|
|
gb_loopback_update_stats_window(&gb->requests_per_second, req, latency);
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2015-07-21 22:50:08 +00:00
|
|
|
static void gb_loopback_throughput_update(struct gb_loopback *gb, u32 latency)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2016-02-25 17:19:15 +00:00
|
|
|
u64 aggregate_size = sizeof(struct gb_operation_msg_hdr) * 2;
|
2015-07-13 19:20:51 +00:00
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
switch (gb->type) {
|
2015-07-13 19:20:51 +00:00
|
|
|
case GB_LOOPBACK_TYPE_PING:
|
|
|
|
break;
|
|
|
|
case GB_LOOPBACK_TYPE_SINK:
|
|
|
|
aggregate_size += sizeof(struct gb_loopback_transfer_request) +
|
2015-12-03 17:29:41 +00:00
|
|
|
gb->size;
|
2015-07-13 19:20:51 +00:00
|
|
|
break;
|
|
|
|
case GB_LOOPBACK_TYPE_TRANSFER:
|
|
|
|
aggregate_size += sizeof(struct gb_loopback_transfer_request) +
|
|
|
|
sizeof(struct gb_loopback_transfer_response) +
|
2015-12-03 17:29:41 +00:00
|
|
|
gb->size * 2;
|
2015-07-13 19:20:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2015-07-21 22:50:08 +00:00
|
|
|
|
2016-02-25 17:19:15 +00:00
|
|
|
aggregate_size *= gb->requests_completed;
|
|
|
|
aggregate_size *= USEC_PER_SEC;
|
|
|
|
gb_loopback_update_stats_window(&gb->throughput, aggregate_size,
|
|
|
|
latency);
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 17:19:15 +00:00
|
|
|
static void gb_loopback_calculate_latency_stats(struct gb_loopback *gb)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
|
|
|
u32 lat;
|
|
|
|
|
2015-07-21 22:50:08 +00:00
|
|
|
/* Express latency in terms of microseconds */
|
2015-08-16 23:55:05 +00:00
|
|
|
lat = gb_loopback_nsec_to_usec_latency(gb->elapsed_nsecs);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2015-08-16 23:55:12 +00:00
|
|
|
/* Log latency stastic */
|
2015-07-21 22:50:08 +00:00
|
|
|
gb_loopback_update_stats(&gb->latency, lat);
|
2015-08-16 23:55:04 +00:00
|
|
|
|
|
|
|
/* Raw latency log on a per thread basis */
|
2015-08-16 23:55:07 +00:00
|
|
|
kfifo_in(&gb->kfifo_lat, (unsigned char *)&lat, sizeof(lat));
|
2015-07-21 22:50:08 +00:00
|
|
|
|
2015-10-15 15:10:45 +00:00
|
|
|
/* Log the firmware supplied latency values */
|
|
|
|
gb_loopback_update_stats(&gb->apbridge_unipro_latency,
|
|
|
|
gb->apbridge_latency_ts);
|
2016-05-19 15:52:39 +00:00
|
|
|
gb_loopback_update_stats(&gb->gbphy_firmware_latency,
|
|
|
|
gb->gbphy_latency_ts);
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-25 17:19:15 +00:00
|
|
|
static void gb_loopback_calculate_stats(struct gb_loopback *gb, bool error)
|
|
|
|
{
|
|
|
|
u64 nlat;
|
|
|
|
u32 lat;
|
2017-11-02 14:32:52 +00:00
|
|
|
ktime_t te;
|
2016-02-25 17:19:15 +00:00
|
|
|
|
|
|
|
if (!error) {
|
|
|
|
gb->requests_completed++;
|
|
|
|
gb_loopback_calculate_latency_stats(gb);
|
|
|
|
}
|
|
|
|
|
2017-11-02 14:32:52 +00:00
|
|
|
te = ktime_get();
|
|
|
|
nlat = gb_loopback_calc_latency(gb->ts, te);
|
2016-02-25 17:19:15 +00:00
|
|
|
if (nlat >= NSEC_PER_SEC || gb->iteration_count == gb->iteration_max) {
|
|
|
|
lat = gb_loopback_nsec_to_usec_latency(nlat);
|
|
|
|
|
|
|
|
gb_loopback_throughput_update(gb, lat);
|
|
|
|
gb_loopback_requests_update(gb, lat);
|
|
|
|
|
|
|
|
if (gb->iteration_count != gb->iteration_max) {
|
|
|
|
gb->ts = te;
|
|
|
|
gb->requests_completed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 13:46:53 +00:00
|
|
|
static void gb_loopback_async_wait_to_send(struct gb_loopback *gb)
|
|
|
|
{
|
|
|
|
if (!(gb->async && gb->outstanding_operations_max))
|
|
|
|
return;
|
|
|
|
wait_event_interruptible(gb->wq_completion,
|
|
|
|
(atomic_read(&gb->outstanding_operations) <
|
|
|
|
gb->outstanding_operations_max) ||
|
|
|
|
kthread_should_stop());
|
|
|
|
}
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
static int gb_loopback_fn(void *data)
|
|
|
|
{
|
|
|
|
int error = 0;
|
2015-12-07 01:59:07 +00:00
|
|
|
int us_wait = 0;
|
2015-08-16 23:55:04 +00:00
|
|
|
int type;
|
2016-07-14 20:13:00 +00:00
|
|
|
int ret;
|
2015-08-16 23:55:04 +00:00
|
|
|
u32 size;
|
2016-03-08 16:40:16 +00:00
|
|
|
|
2015-08-03 17:57:11 +00:00
|
|
|
struct gb_loopback *gb = data;
|
2016-07-14 20:13:00 +00:00
|
|
|
struct gb_bundle *bundle = gb->connection->bundle;
|
|
|
|
|
|
|
|
ret = gb_pm_runtime_get_sync(bundle);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2015-07-24 09:02:56 +00:00
|
|
|
while (1) {
|
2016-07-14 20:13:00 +00:00
|
|
|
if (!gb->type) {
|
|
|
|
gb_pm_runtime_put_autosuspend(bundle);
|
2015-12-03 17:29:41 +00:00
|
|
|
wait_event_interruptible(gb->wq, gb->type ||
|
2015-07-24 09:02:56 +00:00
|
|
|
kthread_should_stop());
|
2016-07-14 20:13:00 +00:00
|
|
|
ret = gb_pm_runtime_get_sync(bundle);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-11 13:46:53 +00:00
|
|
|
if (kthread_should_stop())
|
|
|
|
break;
|
2015-12-07 01:59:06 +00:00
|
|
|
|
2015-12-11 13:46:53 +00:00
|
|
|
/* Limit the maximum number of in-flight async operations */
|
|
|
|
gb_loopback_async_wait_to_send(gb);
|
2015-07-24 09:02:56 +00:00
|
|
|
if (kthread_should_stop())
|
|
|
|
break;
|
2015-07-28 17:34:36 +00:00
|
|
|
|
2015-08-16 23:55:04 +00:00
|
|
|
mutex_lock(&gb->mutex);
|
2015-12-03 17:29:41 +00:00
|
|
|
|
|
|
|
/* Optionally terminate */
|
2016-03-08 16:40:16 +00:00
|
|
|
if (gb->send_count == gb->iteration_max) {
|
2016-12-22 00:37:28 +00:00
|
|
|
mutex_unlock(&gb->mutex);
|
|
|
|
|
2022-06-06 09:57:45 +00:00
|
|
|
/* Wait for synchronous and asynchronous completion */
|
2016-12-22 00:37:28 +00:00
|
|
|
gb_loopback_async_wait_all(gb);
|
|
|
|
|
|
|
|
/* Mark complete unless user-space has poked us */
|
|
|
|
mutex_lock(&gb->mutex);
|
2016-02-25 17:19:15 +00:00
|
|
|
if (gb->iteration_count == gb->iteration_max) {
|
|
|
|
gb->type = 0;
|
2016-03-08 16:40:16 +00:00
|
|
|
gb->send_count = 0;
|
2016-02-26 10:39:48 +00:00
|
|
|
sysfs_notify(&gb->dev->kobj, NULL,
|
2019-08-25 05:54:26 +00:00
|
|
|
"iteration_count");
|
2016-12-22 00:37:28 +00:00
|
|
|
dev_dbg(&bundle->dev, "load test complete\n");
|
|
|
|
} else {
|
|
|
|
dev_dbg(&bundle->dev,
|
|
|
|
"continuing on with new test set\n");
|
2016-02-25 17:19:15 +00:00
|
|
|
}
|
2015-08-16 23:55:04 +00:00
|
|
|
mutex_unlock(&gb->mutex);
|
2015-12-03 17:29:41 +00:00
|
|
|
continue;
|
2015-08-16 23:55:04 +00:00
|
|
|
}
|
2015-12-03 17:29:41 +00:00
|
|
|
size = gb->size;
|
2015-12-07 01:59:07 +00:00
|
|
|
us_wait = gb->us_wait;
|
2015-12-03 17:29:41 +00:00
|
|
|
type = gb->type;
|
2017-11-02 14:32:52 +00:00
|
|
|
if (ktime_to_ns(gb->ts) == 0)
|
|
|
|
gb->ts = ktime_get();
|
2015-12-03 17:29:38 +00:00
|
|
|
|
2015-08-16 23:55:04 +00:00
|
|
|
/* Else operations to perform */
|
2015-12-07 01:59:06 +00:00
|
|
|
if (gb->async) {
|
2017-01-11 00:55:59 +00:00
|
|
|
if (type == GB_LOOPBACK_TYPE_PING)
|
2015-12-07 01:59:06 +00:00
|
|
|
error = gb_loopback_async_ping(gb);
|
2017-01-11 00:55:59 +00:00
|
|
|
else if (type == GB_LOOPBACK_TYPE_TRANSFER)
|
2015-12-07 01:59:06 +00:00
|
|
|
error = gb_loopback_async_transfer(gb, size);
|
2017-01-11 00:55:59 +00:00
|
|
|
else if (type == GB_LOOPBACK_TYPE_SINK)
|
2015-12-07 01:59:06 +00:00
|
|
|
error = gb_loopback_async_sink(gb, size);
|
|
|
|
|
2017-11-06 01:32:20 +00:00
|
|
|
if (error) {
|
2015-12-07 01:59:06 +00:00
|
|
|
gb->error++;
|
2017-11-06 01:32:20 +00:00
|
|
|
gb->iteration_count++;
|
|
|
|
}
|
2015-12-07 01:59:06 +00:00
|
|
|
} else {
|
|
|
|
/* We are effectively single threaded here */
|
|
|
|
if (type == GB_LOOPBACK_TYPE_PING)
|
|
|
|
error = gb_loopback_sync_ping(gb);
|
|
|
|
else if (type == GB_LOOPBACK_TYPE_TRANSFER)
|
|
|
|
error = gb_loopback_sync_transfer(gb, size);
|
|
|
|
else if (type == GB_LOOPBACK_TYPE_SINK)
|
|
|
|
error = gb_loopback_sync_sink(gb, size);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
gb->error++;
|
|
|
|
gb->iteration_count++;
|
2016-02-25 17:19:15 +00:00
|
|
|
gb_loopback_calculate_stats(gb, !!error);
|
2015-12-07 01:59:06 +00:00
|
|
|
}
|
2016-03-08 16:40:16 +00:00
|
|
|
gb->send_count++;
|
2017-11-06 01:32:19 +00:00
|
|
|
mutex_unlock(&gb->mutex);
|
2017-01-26 11:37:32 +00:00
|
|
|
|
|
|
|
if (us_wait) {
|
|
|
|
if (us_wait < 20000)
|
|
|
|
usleep_range(us_wait, us_wait + 100);
|
|
|
|
else
|
|
|
|
msleep(us_wait / 1000);
|
|
|
|
}
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
2016-07-14 20:13:00 +00:00
|
|
|
|
|
|
|
gb_pm_runtime_put_autosuspend(bundle);
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-16 23:55:07 +00:00
|
|
|
static int gb_loopback_dbgfs_latency_show_common(struct seq_file *s,
|
|
|
|
struct kfifo *kfifo,
|
|
|
|
struct mutex *mutex)
|
2015-08-16 23:55:03 +00:00
|
|
|
{
|
|
|
|
u32 latency;
|
|
|
|
int retval;
|
|
|
|
|
2015-08-16 23:55:07 +00:00
|
|
|
if (kfifo_len(kfifo) == 0) {
|
2015-08-16 23:55:03 +00:00
|
|
|
retval = -EAGAIN;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2015-08-16 23:55:07 +00:00
|
|
|
mutex_lock(mutex);
|
|
|
|
retval = kfifo_out(kfifo, &latency, sizeof(latency));
|
2015-08-16 23:55:03 +00:00
|
|
|
if (retval > 0) {
|
|
|
|
seq_printf(s, "%u", latency);
|
|
|
|
retval = 0;
|
|
|
|
}
|
2015-08-16 23:55:07 +00:00
|
|
|
mutex_unlock(mutex);
|
2015-08-16 23:55:03 +00:00
|
|
|
done:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-08-16 23:55:07 +00:00
|
|
|
static int gb_loopback_dbgfs_latency_show(struct seq_file *s, void *unused)
|
|
|
|
{
|
|
|
|
struct gb_loopback *gb = s->private;
|
|
|
|
|
|
|
|
return gb_loopback_dbgfs_latency_show_common(s, &gb->kfifo_lat,
|
|
|
|
&gb->mutex);
|
|
|
|
}
|
2018-12-15 08:53:12 +00:00
|
|
|
DEFINE_SHOW_ATTRIBUTE(gb_loopback_dbgfs_latency);
|
2015-08-16 23:55:03 +00:00
|
|
|
|
2015-08-16 23:55:04 +00:00
|
|
|
#define DEBUGFS_NAMELEN 32
|
2015-08-16 23:55:03 +00:00
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
static int gb_loopback_probe(struct gb_bundle *bundle,
|
|
|
|
const struct greybus_bundle_id *id)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2016-02-12 10:38:29 +00:00
|
|
|
struct greybus_descriptor_cport *cport_desc;
|
|
|
|
struct gb_connection *connection;
|
2015-03-31 07:51:59 +00:00
|
|
|
struct gb_loopback *gb;
|
2015-12-11 10:49:45 +00:00
|
|
|
struct device *dev;
|
2015-03-31 07:51:59 +00:00
|
|
|
int retval;
|
2015-08-16 23:55:03 +00:00
|
|
|
char name[DEBUGFS_NAMELEN];
|
2015-12-07 01:59:05 +00:00
|
|
|
unsigned long flags;
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
if (bundle->num_cports != 1)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
cport_desc = &bundle->cport_desc[0];
|
|
|
|
if (cport_desc->protocol_id != GREYBUS_PROTOCOL_LOOPBACK)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
gb = kzalloc(sizeof(*gb), GFP_KERNEL);
|
|
|
|
if (!gb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
connection = gb_connection_create(bundle, le16_to_cpu(cport_desc->id),
|
|
|
|
gb_loopback_request_handler);
|
|
|
|
if (IS_ERR(connection)) {
|
|
|
|
retval = PTR_ERR(connection);
|
|
|
|
goto out_kzalloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
gb->connection = connection;
|
|
|
|
greybus_set_drvdata(bundle, gb);
|
|
|
|
|
2015-12-03 17:29:41 +00:00
|
|
|
init_waitqueue_head(&gb->wq);
|
2015-12-11 13:46:52 +00:00
|
|
|
init_waitqueue_head(&gb->wq_completion);
|
|
|
|
atomic_set(&gb->outstanding_operations, 0);
|
2015-12-03 17:29:41 +00:00
|
|
|
gb_loopback_reset_stats(gb);
|
|
|
|
|
2015-12-07 01:59:06 +00:00
|
|
|
/* Reported values to user-space for min/max timeouts */
|
|
|
|
gb->timeout_min = jiffies_to_usecs(GB_LOOPBACK_TIMEOUT_MIN);
|
|
|
|
gb->timeout_max = jiffies_to_usecs(GB_LOOPBACK_TIMEOUT_MAX);
|
|
|
|
|
2015-08-16 23:55:11 +00:00
|
|
|
if (!gb_dev.count) {
|
|
|
|
/* Calculate maximum payload */
|
|
|
|
gb_dev.size_max = gb_operation_get_payload_size_max(connection);
|
|
|
|
if (gb_dev.size_max <=
|
|
|
|
sizeof(struct gb_loopback_transfer_request)) {
|
|
|
|
retval = -EINVAL;
|
2016-02-12 10:38:29 +00:00
|
|
|
goto out_connection_destroy;
|
2015-08-16 23:55:11 +00:00
|
|
|
}
|
|
|
|
gb_dev.size_max -= sizeof(struct gb_loopback_transfer_request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create per-connection sysfs and debugfs data-points */
|
2015-09-23 16:31:33 +00:00
|
|
|
snprintf(name, sizeof(name), "raw_latency_%s",
|
2015-10-16 23:55:46 +00:00
|
|
|
dev_name(&connection->bundle->dev));
|
2017-02-09 16:30:12 +00:00
|
|
|
gb->file = debugfs_create_file(name, S_IFREG | 0444, gb_dev.root, gb,
|
2018-12-15 08:53:12 +00:00
|
|
|
&gb_loopback_dbgfs_latency_fops);
|
2015-12-11 10:49:45 +00:00
|
|
|
|
|
|
|
gb->id = ida_simple_get(&loopback_ida, 0, 0, GFP_KERNEL);
|
|
|
|
if (gb->id < 0) {
|
|
|
|
retval = gb->id;
|
2016-02-12 10:38:29 +00:00
|
|
|
goto out_debugfs_remove;
|
2015-12-11 10:49:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
retval = gb_connection_enable(connection);
|
|
|
|
if (retval)
|
|
|
|
goto out_ida_remove;
|
|
|
|
|
2015-12-11 10:49:45 +00:00
|
|
|
dev = device_create_with_groups(&loopback_class,
|
|
|
|
&connection->bundle->dev,
|
|
|
|
MKDEV(0, 0), gb, loopback_groups,
|
|
|
|
"gb_loopback%d", gb->id);
|
|
|
|
if (IS_ERR(dev)) {
|
|
|
|
retval = PTR_ERR(dev);
|
2016-02-12 10:38:29 +00:00
|
|
|
goto out_connection_disable;
|
2015-12-11 10:49:45 +00:00
|
|
|
}
|
|
|
|
gb->dev = dev;
|
2015-07-13 19:20:50 +00:00
|
|
|
|
2015-07-28 17:34:38 +00:00
|
|
|
/* Allocate kfifo */
|
2015-08-16 23:55:07 +00:00
|
|
|
if (kfifo_alloc(&gb->kfifo_lat, kfifo_depth * sizeof(u32),
|
2019-08-25 05:54:26 +00:00
|
|
|
GFP_KERNEL)) {
|
2015-07-28 17:34:38 +00:00
|
|
|
retval = -ENOMEM;
|
2015-12-11 10:49:45 +00:00
|
|
|
goto out_conn;
|
2015-07-28 17:34:38 +00:00
|
|
|
}
|
|
|
|
/* Fork worker thread */
|
2015-07-28 17:34:36 +00:00
|
|
|
mutex_init(&gb->mutex);
|
2015-03-31 07:51:59 +00:00
|
|
|
gb->task = kthread_run(gb_loopback_fn, gb, "gb_loopback");
|
|
|
|
if (IS_ERR(gb->task)) {
|
2015-05-12 02:16:35 +00:00
|
|
|
retval = PTR_ERR(gb->task);
|
2017-11-02 14:32:51 +00:00
|
|
|
goto out_kfifo;
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 01:59:05 +00:00
|
|
|
spin_lock_irqsave(&gb_dev.lock, flags);
|
2015-08-16 23:55:03 +00:00
|
|
|
gb_dev.count++;
|
2015-12-07 01:59:05 +00:00
|
|
|
spin_unlock_irqrestore(&gb_dev.lock, flags);
|
|
|
|
|
|
|
|
gb_connection_latency_tag_enable(connection);
|
2016-07-14 20:13:00 +00:00
|
|
|
|
|
|
|
gb_pm_runtime_put_autosuspend(bundle);
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
return 0;
|
|
|
|
|
2017-11-02 14:32:51 +00:00
|
|
|
out_kfifo:
|
2015-08-16 23:55:07 +00:00
|
|
|
kfifo_free(&gb->kfifo_lat);
|
2015-12-11 10:49:45 +00:00
|
|
|
out_conn:
|
|
|
|
device_unregister(dev);
|
2016-02-12 10:38:29 +00:00
|
|
|
out_connection_disable:
|
|
|
|
gb_connection_disable(connection);
|
|
|
|
out_ida_remove:
|
2015-12-11 10:49:45 +00:00
|
|
|
ida_simple_remove(&loopback_ida, gb->id);
|
2016-02-12 10:38:29 +00:00
|
|
|
out_debugfs_remove:
|
2015-08-16 23:55:03 +00:00
|
|
|
debugfs_remove(gb->file);
|
2016-02-12 10:38:29 +00:00
|
|
|
out_connection_destroy:
|
|
|
|
gb_connection_destroy(connection);
|
2015-12-07 01:59:05 +00:00
|
|
|
out_kzalloc:
|
2015-03-31 07:51:59 +00:00
|
|
|
kfree(gb);
|
2015-08-03 17:57:20 +00:00
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
static void gb_loopback_disconnect(struct gb_bundle *bundle)
|
2015-03-31 07:51:59 +00:00
|
|
|
{
|
2016-02-12 10:38:29 +00:00
|
|
|
struct gb_loopback *gb = greybus_get_drvdata(bundle);
|
2015-12-07 01:59:05 +00:00
|
|
|
unsigned long flags;
|
2016-07-14 20:13:00 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gb_pm_runtime_get_sync(bundle);
|
|
|
|
if (ret)
|
|
|
|
gb_pm_runtime_get_noresume(bundle);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
gb_connection_disable(gb->connection);
|
|
|
|
|
2015-03-31 07:51:59 +00:00
|
|
|
if (!IS_ERR_OR_NULL(gb->task))
|
|
|
|
kthread_stop(gb->task);
|
2015-07-28 17:34:38 +00:00
|
|
|
|
2015-08-16 23:55:07 +00:00
|
|
|
kfifo_free(&gb->kfifo_lat);
|
2016-02-12 10:38:29 +00:00
|
|
|
gb_connection_latency_tag_disable(gb->connection);
|
2015-08-16 23:55:03 +00:00
|
|
|
debugfs_remove(gb->file);
|
2016-02-12 10:38:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: gb_loopback_async_wait_all() is redundant now, as connection
|
|
|
|
* is disabled at the beginning and so we can't have any more
|
|
|
|
* incoming/outgoing requests.
|
|
|
|
*/
|
2015-12-11 13:46:52 +00:00
|
|
|
gb_loopback_async_wait_all(gb);
|
2015-12-07 01:59:05 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&gb_dev.lock, flags);
|
|
|
|
gb_dev.count--;
|
|
|
|
spin_unlock_irqrestore(&gb_dev.lock, flags);
|
|
|
|
|
2015-12-11 10:49:45 +00:00
|
|
|
device_unregister(gb->dev);
|
|
|
|
ida_simple_remove(&loopback_ida, gb->id);
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
gb_connection_destroy(gb->connection);
|
2015-09-14 09:48:41 +00:00
|
|
|
kfree(gb);
|
2015-03-31 07:51:59 +00:00
|
|
|
}
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
static const struct greybus_bundle_id gb_loopback_id_table[] = {
|
|
|
|
{ GREYBUS_DEVICE_CLASS(GREYBUS_CLASS_LOOPBACK) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(greybus, gb_loopback_id_table);
|
|
|
|
|
|
|
|
static struct greybus_driver gb_loopback_driver = {
|
|
|
|
.name = "loopback",
|
|
|
|
.probe = gb_loopback_probe,
|
|
|
|
.disconnect = gb_loopback_disconnect,
|
|
|
|
.id_table = gb_loopback_id_table,
|
2015-03-31 07:51:59 +00:00
|
|
|
};
|
|
|
|
|
2015-07-28 17:34:38 +00:00
|
|
|
static int loopback_init(void)
|
|
|
|
{
|
2015-08-16 23:55:07 +00:00
|
|
|
int retval;
|
|
|
|
|
2015-12-07 01:59:05 +00:00
|
|
|
spin_lock_init(&gb_dev.lock);
|
2015-08-16 23:55:03 +00:00
|
|
|
gb_dev.root = debugfs_create_dir("gb_loopback", NULL);
|
2015-08-16 23:55:04 +00:00
|
|
|
|
2015-12-11 10:49:45 +00:00
|
|
|
retval = class_register(&loopback_class);
|
|
|
|
if (retval)
|
|
|
|
goto err;
|
|
|
|
|
2016-02-12 10:38:29 +00:00
|
|
|
retval = greybus_register(&gb_loopback_driver);
|
2015-12-11 10:49:45 +00:00
|
|
|
if (retval)
|
|
|
|
goto err_unregister;
|
|
|
|
|
|
|
|
return 0;
|
2015-08-16 23:55:07 +00:00
|
|
|
|
2015-12-11 10:49:45 +00:00
|
|
|
err_unregister:
|
|
|
|
class_unregister(&loopback_class);
|
|
|
|
err:
|
2015-08-16 23:55:07 +00:00
|
|
|
debugfs_remove_recursive(gb_dev.root);
|
|
|
|
return retval;
|
2015-07-28 17:34:38 +00:00
|
|
|
}
|
|
|
|
module_init(loopback_init);
|
|
|
|
|
|
|
|
static void __exit loopback_exit(void)
|
|
|
|
{
|
2015-08-16 23:55:03 +00:00
|
|
|
debugfs_remove_recursive(gb_dev.root);
|
2016-02-12 10:38:29 +00:00
|
|
|
greybus_deregister(&gb_loopback_driver);
|
2015-12-11 10:49:45 +00:00
|
|
|
class_unregister(&loopback_class);
|
|
|
|
ida_destroy(&loopback_ida);
|
2015-07-28 17:34:38 +00:00
|
|
|
}
|
|
|
|
module_exit(loopback_exit);
|
2015-03-31 07:51:59 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|