Commit d9a9ea1b authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

greybus: loopback: use the bundle struct device instead of the connector

We are removing struct device from the gb_connection structure in the
near future.  The gb_bundle structure's struct device should be used as
a replacement.

This patch moves the loopback driver to use the bundle pointer instead
of the connection pointer.
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
Reviewed-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Reviewed-by: default avatarAlex Elder <elder@linaro.org>
Reviewed-by: default avatarJohan Hovold <johan@hovoldconsulting.com>
parent 30482c1e
...@@ -107,11 +107,11 @@ static ssize_t field##_##pfx##_show(struct device *dev, \ ...@@ -107,11 +107,11 @@ static ssize_t field##_##pfx##_show(struct device *dev, \
struct device_attribute *attr, \ struct device_attribute *attr, \
char *buf) \ char *buf) \
{ \ { \
struct gb_connection *connection; \ struct gb_bundle *bundle; \
struct gb_loopback *gb; \ struct gb_loopback *gb; \
if (conn) { \ if (conn) { \
connection = to_gb_connection(dev); \ bundle = to_gb_bundle(dev); \
gb = connection->private; \ gb = bundle->private; \
return sprintf(buf, "%u\n", gb->field); \ return sprintf(buf, "%u\n", gb->field); \
} else { \ } else { \
return sprintf(buf, "%u\n", gb_dev.field); \ return sprintf(buf, "%u\n", gb_dev.field); \
...@@ -124,11 +124,11 @@ static ssize_t name##_##field##_##pfx##_show(struct device *dev, \ ...@@ -124,11 +124,11 @@ static ssize_t name##_##field##_##pfx##_show(struct device *dev, \
struct device_attribute *attr, \ struct device_attribute *attr, \
char *buf) \ char *buf) \
{ \ { \
struct gb_connection *connection; \ struct gb_bundle *bundle; \
struct gb_loopback *gb; \ struct gb_loopback *gb; \
if (conn) { \ if (conn) { \
connection = to_gb_connection(dev); \ bundle = to_gb_bundle(dev); \
gb = connection->private; \ gb = bundle->private; \
return sprintf(buf, "%"#type"\n", gb->name.field); \ return sprintf(buf, "%"#type"\n", gb->name.field); \
} else { \ } else { \
return sprintf(buf, "%"#type"\n", gb_dev.name.field); \ return sprintf(buf, "%"#type"\n", gb_dev.name.field); \
...@@ -142,13 +142,13 @@ static ssize_t name##_avg_##pfx##_show(struct device *dev, \ ...@@ -142,13 +142,13 @@ static ssize_t name##_avg_##pfx##_show(struct device *dev, \
char *buf) \ char *buf) \
{ \ { \
struct gb_loopback_stats *stats; \ struct gb_loopback_stats *stats; \
struct gb_connection *connection; \ struct gb_bundle *bundle; \
struct gb_loopback *gb; \ struct gb_loopback *gb; \
u64 avg; \ u64 avg; \
u32 count, rem; \ u32 count, rem; \
if (conn) { \ if (conn) { \
connection = to_gb_connection(dev); \ bundle = to_gb_bundle(dev); \
gb = connection->private; \ gb = bundle->private; \
stats = &gb->name; \ stats = &gb->name; \
} else { \ } else { \
stats = &gb_dev.name; \ stats = &gb_dev.name; \
...@@ -170,8 +170,8 @@ static ssize_t field##_show(struct device *dev, \ ...@@ -170,8 +170,8 @@ static ssize_t field##_show(struct device *dev, \
struct device_attribute *attr, \ struct device_attribute *attr, \
char *buf) \ char *buf) \
{ \ { \
struct gb_connection *connection = to_gb_connection(dev); \ struct gb_bundle *bundle = to_gb_bundle(dev); \
struct gb_loopback *gb = connection->private; \ struct gb_loopback *gb = bundle->private; \
return sprintf(buf, "%"#type"\n", gb->field); \ return sprintf(buf, "%"#type"\n", gb->field); \
} \ } \
static ssize_t field##_store(struct device *dev, \ static ssize_t field##_store(struct device *dev, \
...@@ -180,13 +180,13 @@ static ssize_t field##_store(struct device *dev, \ ...@@ -180,13 +180,13 @@ static ssize_t field##_store(struct device *dev, \
size_t len) \ size_t len) \
{ \ { \
int ret; \ int ret; \
struct gb_connection *connection = to_gb_connection(dev); \ struct gb_bundle *bundle = to_gb_bundle(dev); \
mutex_lock(&gb_dev.mutex); \ mutex_lock(&gb_dev.mutex); \
ret = sscanf(buf, "%"#type, &gb->field); \ ret = sscanf(buf, "%"#type, &gb->field); \
if (ret != 1) \ if (ret != 1) \
len = -EINVAL; \ len = -EINVAL; \
else \ else \
gb_loopback_check_attr(connection); \ gb_loopback_check_attr(&gb_dev, bundle); \
mutex_unlock(&gb_dev.mutex); \ mutex_unlock(&gb_dev.mutex); \
return len; \ return len; \
} \ } \
...@@ -214,13 +214,13 @@ static ssize_t field##_store(struct device *dev, \ ...@@ -214,13 +214,13 @@ static ssize_t field##_store(struct device *dev, \
size_t len) \ size_t len) \
{ \ { \
int ret; \ int ret; \
struct gb_connection *connection = to_gb_connection(dev); \ struct gb_bundle *bundle = to_gb_bundle(dev); \
mutex_lock(&gb_dev.mutex); \ mutex_lock(&gb_dev.mutex); \
ret = sscanf(buf, "%"#type, &gb_dev.field); \ ret = sscanf(buf, "%"#type, &gb_dev.field); \
if (ret != 1) \ if (ret != 1) \
len = -EINVAL; \ len = -EINVAL; \
else \ else \
gb_loopback_check_attr(&gb_dev, connection); \ gb_loopback_check_attr(&gb_dev, bundle); \
mutex_unlock(&gb_dev.mutex); \ mutex_unlock(&gb_dev.mutex); \
return len; \ return len; \
} \ } \
...@@ -228,7 +228,7 @@ static DEVICE_ATTR_RW(field) ...@@ -228,7 +228,7 @@ static DEVICE_ATTR_RW(field)
static void gb_loopback_reset_stats(struct gb_loopback_device *gb_dev); static void gb_loopback_reset_stats(struct gb_loopback_device *gb_dev);
static void gb_loopback_check_attr(struct gb_loopback_device *gb_dev, static void gb_loopback_check_attr(struct gb_loopback_device *gb_dev,
struct gb_connection *connection) struct gb_bundle *bundle)
{ {
struct gb_loopback *gb; struct gb_loopback *gb;
...@@ -244,7 +244,7 @@ static void gb_loopback_check_attr(struct gb_loopback_device *gb_dev, ...@@ -244,7 +244,7 @@ static void gb_loopback_check_attr(struct gb_loopback_device *gb_dev,
gb->iteration_count = 0; gb->iteration_count = 0;
gb->error = 0; gb->error = 0;
if (kfifo_depth < gb_dev->iteration_max) { if (kfifo_depth < gb_dev->iteration_max) {
dev_warn(&connection->dev, dev_warn(&bundle->dev,
"cannot log bytes %u kfifo_depth %u\n", "cannot log bytes %u kfifo_depth %u\n",
gb_dev->iteration_max, kfifo_depth); gb_dev->iteration_max, kfifo_depth);
} }
...@@ -414,14 +414,14 @@ static int gb_loopback_operation_sync(struct gb_loopback *gb, int type, ...@@ -414,14 +414,14 @@ static int gb_loopback_operation_sync(struct gb_loopback *gb, int type,
ret = gb_operation_request_send_sync(operation); ret = gb_operation_request_send_sync(operation);
if (ret) { if (ret) {
dev_err(&gb->connection->dev, dev_err(&gb->connection->bundle->dev,
"synchronous operation failed: %d\n", ret); "synchronous operation failed: %d\n", ret);
} else { } else {
if (response_size == operation->response->payload_size) { if (response_size == operation->response->payload_size) {
memcpy(response, operation->response->payload, memcpy(response, operation->response->payload,
response_size); response_size);
} else { } else {
dev_err(&gb->connection->dev, dev_err(&gb->connection->bundle->dev,
"response size %zu expected %d\n", "response size %zu expected %d\n",
operation->response->payload_size, operation->response->payload_size,
response_size); response_size);
...@@ -482,7 +482,8 @@ static int gb_loopback_transfer(struct gb_loopback *gb, u32 len) ...@@ -482,7 +482,8 @@ static int gb_loopback_transfer(struct gb_loopback *gb, u32 len)
goto gb_error; goto gb_error;
if (memcmp(request->data, response->data, len)) { if (memcmp(request->data, response->data, len)) {
dev_err(&gb->connection->dev, "Loopback Data doesn't match\n"); dev_err(&gb->connection->bundle->dev,
"Loopback Data doesn't match\n");
retval = -EREMOTEIO; retval = -EREMOTEIO;
} }
gb->apbridge_latency_ts = (u32)__le32_to_cpu(response->reserved0); gb->apbridge_latency_ts = (u32)__le32_to_cpu(response->reserved0);
...@@ -506,21 +507,20 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation) ...@@ -506,21 +507,20 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation)
struct gb_connection *connection = operation->connection; struct gb_connection *connection = operation->connection;
struct gb_loopback_transfer_request *request; struct gb_loopback_transfer_request *request;
struct gb_loopback_transfer_response *response; struct gb_loopback_transfer_response *response;
struct device *dev = &connection->bundle->dev;
size_t len; size_t len;
/* By convention, the AP initiates the version operation */ /* By convention, the AP initiates the version operation */
switch (type) { switch (type) {
case GB_REQUEST_TYPE_PROTOCOL_VERSION: case GB_REQUEST_TYPE_PROTOCOL_VERSION:
dev_err(&connection->dev, dev_err(dev, "module-initiated version operation\n");
"module-initiated version operation\n");
return -EINVAL; return -EINVAL;
case GB_LOOPBACK_TYPE_PING: case GB_LOOPBACK_TYPE_PING:
case GB_LOOPBACK_TYPE_SINK: case GB_LOOPBACK_TYPE_SINK:
return 0; return 0;
case GB_LOOPBACK_TYPE_TRANSFER: case GB_LOOPBACK_TYPE_TRANSFER:
if (operation->request->payload_size < sizeof(*request)) { if (operation->request->payload_size < sizeof(*request)) {
dev_err(&connection->dev, dev_err(dev, "transfer request too small (%zu < %zu)\n",
"transfer request too small (%zu < %zu)\n",
operation->request->payload_size, operation->request->payload_size,
sizeof(*request)); sizeof(*request));
return -EINVAL; /* -EMSGSIZE */ return -EINVAL; /* -EMSGSIZE */
...@@ -528,8 +528,7 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation) ...@@ -528,8 +528,7 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation)
request = operation->request->payload; request = operation->request->payload;
len = le32_to_cpu(request->len); len = le32_to_cpu(request->len);
if (len > gb_dev.size_max) { if (len > gb_dev.size_max) {
dev_err(&connection->dev, dev_err(dev, "transfer request too large (%zu > %zu)\n",
"transfer request too large (%zu > %zu)\n",
len, gb_dev.size_max); len, gb_dev.size_max);
return -EINVAL; return -EINVAL;
} }
...@@ -537,8 +536,7 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation) ...@@ -537,8 +536,7 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation)
if (len) { if (len) {
if (!gb_operation_response_alloc(operation, len, if (!gb_operation_response_alloc(operation, len,
GFP_KERNEL)) { GFP_KERNEL)) {
dev_err(&connection->dev, dev_err(dev, "error allocating response\n");
"error allocating response\n");
return -ENOMEM; return -ENOMEM;
} }
response = operation->response->payload; response = operation->response->payload;
...@@ -547,8 +545,7 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation) ...@@ -547,8 +545,7 @@ static int gb_loopback_request_recv(u8 type, struct gb_operation *operation)
} }
return 0; return 0;
default: default:
dev_err(&connection->dev, dev_err(dev, "unsupported request: %hhu\n", type);
"unsupported request: %hhu\n", type);
return -EINVAL; return -EINVAL;
} }
} }
...@@ -755,8 +752,8 @@ static int gb_loopback_fn(void *data) ...@@ -755,8 +752,8 @@ static int gb_loopback_fn(void *data)
/* All threads achieved at least low_count iterations */ /* All threads achieved at least low_count iterations */
if (gb_dev.iteration_count < low_count) { if (gb_dev.iteration_count < low_count) {
gb_dev.iteration_count = low_count; gb_dev.iteration_count = low_count;
sysfs_notify(&gb->connection->dev.kobj, NULL, sysfs_notify(&gb->connection->bundle->dev.kobj,
"iteration_count"); NULL, "iteration_count");
} }
/* Optionally terminate */ /* Optionally terminate */
if (gb_dev.iteration_count == gb_dev.iteration_max) { if (gb_dev.iteration_count == gb_dev.iteration_max) {
...@@ -954,12 +951,12 @@ static int gb_loopback_connection_init(struct gb_connection *connection) ...@@ -954,12 +951,12 @@ static int gb_loopback_connection_init(struct gb_connection *connection)
/* Create per-connection sysfs and debugfs data-points */ /* Create per-connection sysfs and debugfs data-points */
snprintf(name, sizeof(name), "raw_latency_%s", snprintf(name, sizeof(name), "raw_latency_%s",
dev_name(&connection->dev)); dev_name(&connection->bundle->dev));
gb->file = debugfs_create_file(name, S_IFREG | S_IRUGO, gb_dev.root, gb, gb->file = debugfs_create_file(name, S_IFREG | S_IRUGO, gb_dev.root, gb,
&gb_loopback_debugfs_latency_ops); &gb_loopback_debugfs_latency_ops);
gb->connection = connection; gb->connection = connection;
connection->private = gb; connection->bundle->private = gb;
retval = sysfs_create_groups(&connection->dev.kobj, retval = sysfs_create_groups(&connection->bundle->dev.kobj,
loopback_con_groups); loopback_con_groups);
if (retval) if (retval)
goto out_sysfs_dev; goto out_sysfs_dev;
...@@ -995,14 +992,14 @@ static int gb_loopback_connection_init(struct gb_connection *connection) ...@@ -995,14 +992,14 @@ static int gb_loopback_connection_init(struct gb_connection *connection)
out_kfifo0: out_kfifo0:
kfifo_free(&gb->kfifo_lat); kfifo_free(&gb->kfifo_lat);
out_sysfs_conn: out_sysfs_conn:
sysfs_remove_groups(&connection->dev.kobj, loopback_con_groups); sysfs_remove_groups(&connection->bundle->dev.kobj, loopback_con_groups);
out_sysfs_dev: out_sysfs_dev:
if (!gb_dev.count) { if (!gb_dev.count) {
sysfs_remove_groups(kobj, loopback_dev_groups); sysfs_remove_groups(kobj, loopback_dev_groups);
debugfs_remove(gb_dev.file); debugfs_remove(gb_dev.file);
} }
debugfs_remove(gb->file); debugfs_remove(gb->file);
connection->private = NULL; connection->bundle->private = NULL;
out_sysfs: out_sysfs:
mutex_unlock(&gb_dev.mutex); mutex_unlock(&gb_dev.mutex);
kfree(gb); kfree(gb);
...@@ -1012,7 +1009,7 @@ static int gb_loopback_connection_init(struct gb_connection *connection) ...@@ -1012,7 +1009,7 @@ static int gb_loopback_connection_init(struct gb_connection *connection)
static void gb_loopback_connection_exit(struct gb_connection *connection) static void gb_loopback_connection_exit(struct gb_connection *connection)
{ {
struct gb_loopback *gb = connection->private; struct gb_loopback *gb = connection->bundle->private;
struct kobject *kobj = &connection->hd->endo->dev.kobj; struct kobject *kobj = &connection->hd->endo->dev.kobj;
if (!IS_ERR_OR_NULL(gb->task)) if (!IS_ERR_OR_NULL(gb->task))
...@@ -1020,7 +1017,7 @@ static void gb_loopback_connection_exit(struct gb_connection *connection) ...@@ -1020,7 +1017,7 @@ static void gb_loopback_connection_exit(struct gb_connection *connection)
mutex_lock(&gb_dev.mutex); mutex_lock(&gb_dev.mutex);
connection->private = NULL; connection->bundle->private = NULL;
kfifo_free(&gb->kfifo_lat); kfifo_free(&gb->kfifo_lat);
kfifo_free(&gb->kfifo_ts); kfifo_free(&gb->kfifo_ts);
gb_connection_latency_tag_disable(connection); gb_connection_latency_tag_disable(connection);
...@@ -1029,7 +1026,8 @@ static void gb_loopback_connection_exit(struct gb_connection *connection) ...@@ -1029,7 +1026,8 @@ static void gb_loopback_connection_exit(struct gb_connection *connection)
sysfs_remove_groups(kobj, loopback_dev_groups); sysfs_remove_groups(kobj, loopback_dev_groups);
debugfs_remove(gb_dev.file); debugfs_remove(gb_dev.file);
} }
sysfs_remove_groups(&connection->dev.kobj, loopback_con_groups); sysfs_remove_groups(&connection->bundle->dev.kobj,
loopback_con_groups);
debugfs_remove(gb->file); debugfs_remove(gb->file);
list_del(&gb->entry); list_del(&gb->entry);
mutex_unlock(&gb_dev.mutex); mutex_unlock(&gb_dev.mutex);
......
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