Commit ccfbaee0 authored by Christian Gromm's avatar Christian Gromm Committed by Greg Kroah-Hartman

staging: most: refactor channel structure

The struct most_c_obj has the same set of attributes for each of two AIMs.
This patch cleans up the code by introducing the new struct most_c_aim_obj
hat contains those fields.
Signed-off-by: default avatarChristian Gromm <christian.gromm@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 71457d48
...@@ -38,6 +38,12 @@ static struct ida mdev_id; ...@@ -38,6 +38,12 @@ static struct ida mdev_id;
static int modref; static int modref;
static int dummy_num_buffers; static int dummy_num_buffers;
struct most_c_aim_obj {
struct most_aim *ptr;
int refs;
int num_buffers;
};
struct most_c_obj { struct most_c_obj {
struct kobject kobj; struct kobject kobj;
struct completion cleanup; struct completion cleanup;
...@@ -56,12 +62,8 @@ struct most_c_obj { ...@@ -56,12 +62,8 @@ struct most_c_obj {
spinlock_t fifo_lock; spinlock_t fifo_lock;
struct list_head halt_fifo; struct list_head halt_fifo;
struct list_head list; struct list_head list;
struct most_aim *first_aim; struct most_c_aim_obj aim0;
struct most_aim *second_aim; struct most_c_aim_obj aim1;
int first_aim_refs;
int second_aim_refs;
int first_num_buffers;
int second_num_buffers;
struct list_head trash_fifo; struct list_head trash_fifo;
struct task_struct *hdm_enqueue_task; struct task_struct *hdm_enqueue_task;
struct mutex stop_task_mutex; struct mutex stop_task_mutex;
...@@ -557,12 +559,12 @@ create_most_c_obj(const char *name, struct kobject *parent) ...@@ -557,12 +559,12 @@ create_most_c_obj(const char *name, struct kobject *parent)
*/ */
static void destroy_most_c_obj(struct most_c_obj *c) static void destroy_most_c_obj(struct most_c_obj *c)
{ {
if (c->first_aim) if (c->aim0.ptr)
c->first_aim->disconnect_channel(c->iface, c->channel_id); c->aim0.ptr->disconnect_channel(c->iface, c->channel_id);
if (c->second_aim) if (c->aim1.ptr)
c->second_aim->disconnect_channel(c->iface, c->channel_id); c->aim1.ptr->disconnect_channel(c->iface, c->channel_id);
c->first_aim = NULL; c->aim0.ptr = NULL;
c->second_aim = NULL; c->aim1.ptr = NULL;
mutex_lock(&deregister_mutex); mutex_lock(&deregister_mutex);
flush_trash_fifo(c); flush_trash_fifo(c);
...@@ -994,10 +996,10 @@ static ssize_t store_add_link(struct most_aim_obj *aim_obj, ...@@ -994,10 +996,10 @@ static ssize_t store_add_link(struct most_aim_obj *aim_obj,
if (IS_ERR(c)) if (IS_ERR(c))
return -ENODEV; return -ENODEV;
if (!c->first_aim) if (!c->aim0.ptr)
aim_ptr = &c->first_aim; aim_ptr = &c->aim0.ptr;
else if (!c->second_aim) else if (!c->aim1.ptr)
aim_ptr = &c->second_aim; aim_ptr = &c->aim1.ptr;
else else
return -ENOSPC; return -ENOSPC;
...@@ -1051,10 +1053,10 @@ static ssize_t store_remove_link(struct most_aim_obj *aim_obj, ...@@ -1051,10 +1053,10 @@ static ssize_t store_remove_link(struct most_aim_obj *aim_obj,
if (IS_ERR(c)) if (IS_ERR(c))
return -ENODEV; return -ENODEV;
if (c->first_aim == aim_obj->driver) if (c->aim0.ptr == aim_obj->driver)
c->first_aim = NULL; c->aim0.ptr = NULL;
if (c->second_aim == aim_obj->driver) if (c->aim1.ptr == aim_obj->driver)
c->second_aim = NULL; c->aim1.ptr = NULL;
if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id)) if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id))
return -EIO; return -EIO;
return len; return len;
...@@ -1240,11 +1242,11 @@ static void arm_mbo(struct mbo *mbo) ...@@ -1240,11 +1242,11 @@ static void arm_mbo(struct mbo *mbo)
list_add_tail(&mbo->list, &c->fifo); list_add_tail(&mbo->list, &c->fifo);
spin_unlock_irqrestore(&c->fifo_lock, flags); spin_unlock_irqrestore(&c->fifo_lock, flags);
if (c->first_aim_refs && c->first_aim->tx_completion) if (c->aim0.refs && c->aim0.ptr->tx_completion)
c->first_aim->tx_completion(c->iface, c->channel_id); c->aim0.ptr->tx_completion(c->iface, c->channel_id);
if (c->second_aim_refs && c->second_aim->tx_completion) if (c->aim1.refs && c->aim1.ptr->tx_completion)
c->second_aim->tx_completion(c->iface, c->channel_id); c->aim1.ptr->tx_completion(c->iface, c->channel_id);
} }
/** /**
...@@ -1401,15 +1403,15 @@ struct mbo *most_get_mbo(struct most_interface *iface, int id, ...@@ -1401,15 +1403,15 @@ struct mbo *most_get_mbo(struct most_interface *iface, int id,
if (unlikely(!c)) if (unlikely(!c))
return NULL; return NULL;
if (c->first_aim_refs && c->second_aim_refs && if (c->aim0.refs && c->aim1.refs &&
((aim == c->first_aim && c->first_num_buffers <= 0) || ((aim == c->aim0.ptr && c->aim0.num_buffers <= 0) ||
(aim == c->second_aim && c->second_num_buffers <= 0))) (aim == c->aim1.ptr && c->aim1.num_buffers <= 0)))
return NULL; return NULL;
if (aim == c->first_aim) if (aim == c->aim0.ptr)
num_buffers_ptr = &c->first_num_buffers; num_buffers_ptr = &c->aim0.num_buffers;
else if (aim == c->second_aim) else if (aim == c->aim1.ptr)
num_buffers_ptr = &c->second_num_buffers; num_buffers_ptr = &c->aim1.num_buffers;
else else
num_buffers_ptr = &dummy_num_buffers; num_buffers_ptr = &dummy_num_buffers;
...@@ -1485,12 +1487,12 @@ static void most_read_completion(struct mbo *mbo) ...@@ -1485,12 +1487,12 @@ static void most_read_completion(struct mbo *mbo)
c->is_starving = 1; c->is_starving = 1;
} }
if (c->first_aim_refs && c->first_aim->rx_completion && if (c->aim0.refs && c->aim0.ptr->rx_completion &&
c->first_aim->rx_completion(mbo) == 0) c->aim0.ptr->rx_completion(mbo) == 0)
return; return;
if (c->second_aim_refs && c->second_aim->rx_completion && if (c->aim1.refs && c->aim1.ptr->rx_completion &&
c->second_aim->rx_completion(mbo) == 0) c->aim1.ptr->rx_completion(mbo) == 0)
return; return;
most_put_mbo(mbo); most_put_mbo(mbo);
...@@ -1517,7 +1519,7 @@ int most_start_channel(struct most_interface *iface, int id, ...@@ -1517,7 +1519,7 @@ int most_start_channel(struct most_interface *iface, int id,
return -EINVAL; return -EINVAL;
mutex_lock(&c->start_mutex); mutex_lock(&c->start_mutex);
if (c->first_aim_refs + c->second_aim_refs > 0) if (c->aim0.refs + c->aim1.refs > 0)
goto out; /* already started by other aim */ goto out; /* already started by other aim */
if (!try_module_get(iface->mod)) { if (!try_module_get(iface->mod)) {
...@@ -1553,15 +1555,15 @@ int most_start_channel(struct most_interface *iface, int id, ...@@ -1553,15 +1555,15 @@ int most_start_channel(struct most_interface *iface, int id,
goto error; goto error;
c->is_starving = 0; c->is_starving = 0;
c->first_num_buffers = c->cfg.num_buffers / 2; c->aim0.num_buffers = c->cfg.num_buffers / 2;
c->second_num_buffers = c->cfg.num_buffers - c->first_num_buffers; c->aim1.num_buffers = c->cfg.num_buffers - c->aim0.num_buffers;
atomic_set(&c->mbo_ref, num_buffer); atomic_set(&c->mbo_ref, num_buffer);
out: out:
if (aim == c->first_aim) if (aim == c->aim0.ptr)
c->first_aim_refs++; c->aim0.refs++;
if (aim == c->second_aim) if (aim == c->aim1.ptr)
c->second_aim_refs++; c->aim1.refs++;
mutex_unlock(&c->start_mutex); mutex_unlock(&c->start_mutex);
return 0; return 0;
...@@ -1593,7 +1595,7 @@ int most_stop_channel(struct most_interface *iface, int id, ...@@ -1593,7 +1595,7 @@ int most_stop_channel(struct most_interface *iface, int id,
return -EINVAL; return -EINVAL;
mutex_lock(&c->start_mutex); mutex_lock(&c->start_mutex);
if (c->first_aim_refs + c->second_aim_refs >= 2) if (c->aim0.refs + c->aim1.refs >= 2)
goto out; goto out;
mutex_lock(&c->stop_task_mutex); mutex_lock(&c->stop_task_mutex);
...@@ -1637,10 +1639,10 @@ int most_stop_channel(struct most_interface *iface, int id, ...@@ -1637,10 +1639,10 @@ int most_stop_channel(struct most_interface *iface, int id,
c->is_poisoned = false; c->is_poisoned = false;
out: out:
if (aim == c->first_aim) if (aim == c->aim0.ptr)
c->first_aim_refs--; c->aim0.refs--;
if (aim == c->second_aim) if (aim == c->aim1.ptr)
c->second_aim_refs--; c->aim1.refs--;
mutex_unlock(&c->start_mutex); mutex_unlock(&c->start_mutex);
return 0; return 0;
} }
...@@ -1694,13 +1696,13 @@ int most_deregister_aim(struct most_aim *aim) ...@@ -1694,13 +1696,13 @@ int most_deregister_aim(struct most_aim *aim)
} }
list_for_each_entry_safe(i, i_tmp, &instance_list, list) { list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
list_for_each_entry_safe(c, tmp, &i->channel_list, list) { list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
if (c->first_aim == aim || c->second_aim == aim) if (c->aim0.ptr == aim || c->aim1.ptr == aim)
aim->disconnect_channel( aim->disconnect_channel(
c->iface, c->channel_id); c->iface, c->channel_id);
if (c->first_aim == aim) if (c->aim0.ptr == aim)
c->first_aim = NULL; c->aim0.ptr = NULL;
if (c->second_aim == aim) if (c->aim1.ptr == aim)
c->second_aim = NULL; c->aim1.ptr = NULL;
} }
} }
list_del(&aim_obj->list); list_del(&aim_obj->list);
...@@ -1834,7 +1836,7 @@ void most_deregister_interface(struct most_interface *iface) ...@@ -1834,7 +1836,7 @@ void most_deregister_interface(struct most_interface *iface)
} }
list_for_each_entry(c, &i->channel_list, list) { list_for_each_entry(c, &i->channel_list, list) {
if (c->first_aim_refs + c->second_aim_refs <= 0) if (c->aim0.refs + c->aim1.refs <= 0)
continue; continue;
mutex_lock(&c->stop_task_mutex); mutex_lock(&c->stop_task_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