2 * core.c - Implementation of core module of MOST Linux driver stack
4 * Copyright (C) 2013-2015 Microchip Technology Germany II GmbH & Co. KG
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
11 * This file is licensed under GPLv2.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/init.h>
19 #include <linux/device.h>
20 #include <linux/list.h>
21 #include <linux/poll.h>
22 #include <linux/wait.h>
23 #include <linux/kobject.h>
24 #include <linux/mutex.h>
25 #include <linux/completion.h>
26 #include <linux/sysfs.h>
27 #include <linux/kthread.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/idr.h>
32 #define MAX_CHANNELS 64
33 #define STRING_SIZE 80
35 static struct class *most_class;
36 static struct device *class_glue_dir;
37 static struct ida mdev_id;
42 struct completion cleanup;
44 atomic_t mbo_nq_level;
49 struct most_interface *iface;
50 struct most_inst_obj *inst;
51 struct most_channel_config cfg;
54 struct list_head fifo;
56 struct list_head halt_fifo;
57 struct list_head list;
58 struct most_aim *first_aim;
59 struct most_aim *second_aim;
60 struct list_head trash_fifo;
61 struct task_struct *hdm_enqueue_task;
62 struct mutex stop_task_mutex;
63 wait_queue_head_t hdm_fifo_wq;
65 #define to_c_obj(d) container_of(d, struct most_c_obj, kobj)
67 struct most_inst_obj {
70 struct most_interface *iface;
71 struct list_head channel_list;
72 struct most_c_obj *channel[MAX_CHANNELS];
74 struct list_head list;
76 #define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
79 * list_pop_mbo - retrieves the first MBO of the list and removes it
80 * @ptr: the list head to grab the MBO from.
82 #define list_pop_mbo(ptr) \
84 struct mbo *_mbo = list_first_entry(ptr, struct mbo, list); \
85 list_del(&_mbo->list); \
89 static struct mutex deregister_mutex;
96 * struct most_c_attr - to access the attributes of a channel object
97 * @attr: attributes of a channel
98 * @show: pointer to the show function
99 * @store: pointer to the store function
102 struct attribute attr;
103 ssize_t (*show)(struct most_c_obj *d,
104 struct most_c_attr *attr,
106 ssize_t (*store)(struct most_c_obj *d,
107 struct most_c_attr *attr,
111 #define to_channel_attr(a) container_of(a, struct most_c_attr, attr)
113 #define MOST_CHNL_ATTR(_name, _mode, _show, _store) \
114 struct most_c_attr most_chnl_attr_##_name = \
115 __ATTR(_name, _mode, _show, _store)
118 * channel_attr_show - show function of channel object
119 * @kobj: pointer to its kobject
120 * @attr: pointer to its attributes
123 static ssize_t channel_attr_show(struct kobject *kobj, struct attribute *attr,
126 struct most_c_attr *channel_attr = to_channel_attr(attr);
127 struct most_c_obj *c_obj = to_c_obj(kobj);
129 if (!channel_attr->show)
132 return channel_attr->show(c_obj, channel_attr, buf);
136 * channel_attr_store - store function of channel object
137 * @kobj: pointer to its kobject
138 * @attr: pointer to its attributes
140 * @len: length of buffer
142 static ssize_t channel_attr_store(struct kobject *kobj,
143 struct attribute *attr,
147 struct most_c_attr *channel_attr = to_channel_attr(attr);
148 struct most_c_obj *c_obj = to_c_obj(kobj);
150 if (!channel_attr->store)
152 return channel_attr->store(c_obj, channel_attr, buf, len);
155 static const struct sysfs_ops most_channel_sysfs_ops = {
156 .show = channel_attr_show,
157 .store = channel_attr_store,
161 * most_free_mbo_coherent - free an MBO and its coherent buffer
162 * @mbo: buffer to be released
165 static void most_free_mbo_coherent(struct mbo *mbo)
167 struct most_c_obj *c = mbo->context;
168 u16 const coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
170 dma_free_coherent(NULL, coherent_buf_size, mbo->virt_address,
173 if (atomic_sub_and_test(1, &c->mbo_ref))
174 complete(&c->cleanup);
178 * flush_channel_fifos - clear the channel fifos
179 * @c: pointer to channel object
181 static void flush_channel_fifos(struct most_c_obj *c)
183 unsigned long flags, hf_flags;
184 struct mbo *mbo, *tmp;
186 if (list_empty(&c->fifo) && list_empty(&c->halt_fifo))
189 spin_lock_irqsave(&c->fifo_lock, flags);
190 list_for_each_entry_safe(mbo, tmp, &c->fifo, list) {
191 list_del(&mbo->list);
192 spin_unlock_irqrestore(&c->fifo_lock, flags);
193 most_free_mbo_coherent(mbo);
194 spin_lock_irqsave(&c->fifo_lock, flags);
196 spin_unlock_irqrestore(&c->fifo_lock, flags);
198 spin_lock_irqsave(&c->fifo_lock, hf_flags);
199 list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) {
200 list_del(&mbo->list);
201 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
202 most_free_mbo_coherent(mbo);
203 spin_lock_irqsave(&c->fifo_lock, hf_flags);
205 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
207 if (unlikely((!list_empty(&c->fifo) || !list_empty(&c->halt_fifo))))
208 pr_info("WARN: fifo | trash fifo not empty\n");
212 * flush_trash_fifo - clear the trash fifo
213 * @c: pointer to channel object
215 static int flush_trash_fifo(struct most_c_obj *c)
217 struct mbo *mbo, *tmp;
220 spin_lock_irqsave(&c->fifo_lock, flags);
221 list_for_each_entry_safe(mbo, tmp, &c->trash_fifo, list) {
222 list_del(&mbo->list);
223 spin_unlock_irqrestore(&c->fifo_lock, flags);
224 most_free_mbo_coherent(mbo);
225 spin_lock_irqsave(&c->fifo_lock, flags);
227 spin_unlock_irqrestore(&c->fifo_lock, flags);
232 * most_channel_release - release function of channel object
233 * @kobj: pointer to channel's kobject
235 static void most_channel_release(struct kobject *kobj)
237 struct most_c_obj *c = to_c_obj(kobj);
242 static ssize_t show_available_directions(struct most_c_obj *c,
243 struct most_c_attr *attr,
246 unsigned int i = c->channel_id;
249 if (c->iface->channel_vector[i].direction & MOST_CH_RX)
250 strcat(buf, "dir_rx ");
251 if (c->iface->channel_vector[i].direction & MOST_CH_TX)
252 strcat(buf, "dir_tx ");
254 return strlen(buf) + 1;
257 static ssize_t show_available_datatypes(struct most_c_obj *c,
258 struct most_c_attr *attr,
261 unsigned int i = c->channel_id;
264 if (c->iface->channel_vector[i].data_type & MOST_CH_CONTROL)
265 strcat(buf, "control ");
266 if (c->iface->channel_vector[i].data_type & MOST_CH_ASYNC)
267 strcat(buf, "async ");
268 if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC)
269 strcat(buf, "sync ");
270 if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC_AVP)
271 strcat(buf, "isoc_avp ");
273 return strlen(buf) + 1;
277 ssize_t show_number_of_packet_buffers(struct most_c_obj *c,
278 struct most_c_attr *attr,
281 unsigned int i = c->channel_id;
283 return snprintf(buf, PAGE_SIZE, "%d\n",
284 c->iface->channel_vector[i].num_buffers_packet);
288 ssize_t show_number_of_stream_buffers(struct most_c_obj *c,
289 struct most_c_attr *attr,
292 unsigned int i = c->channel_id;
294 return snprintf(buf, PAGE_SIZE, "%d\n",
295 c->iface->channel_vector[i].num_buffers_streaming);
299 ssize_t show_size_of_packet_buffer(struct most_c_obj *c,
300 struct most_c_attr *attr,
303 unsigned int i = c->channel_id;
305 return snprintf(buf, PAGE_SIZE, "%d\n",
306 c->iface->channel_vector[i].buffer_size_packet);
310 ssize_t show_size_of_stream_buffer(struct most_c_obj *c,
311 struct most_c_attr *attr,
314 unsigned int i = c->channel_id;
316 return snprintf(buf, PAGE_SIZE, "%d\n",
317 c->iface->channel_vector[i].buffer_size_streaming);
320 static ssize_t show_channel_starving(struct most_c_obj *c,
321 struct most_c_attr *attr,
324 return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
328 #define create_show_channel_attribute(val) \
329 static MOST_CHNL_ATTR(val, S_IRUGO, show_##val, NULL)
331 create_show_channel_attribute(available_directions);
332 create_show_channel_attribute(available_datatypes);
333 create_show_channel_attribute(number_of_packet_buffers);
334 create_show_channel_attribute(number_of_stream_buffers);
335 create_show_channel_attribute(size_of_stream_buffer);
336 create_show_channel_attribute(size_of_packet_buffer);
337 create_show_channel_attribute(channel_starving);
339 static ssize_t show_set_number_of_buffers(struct most_c_obj *c,
340 struct most_c_attr *attr,
343 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers);
346 static ssize_t store_set_number_of_buffers(struct most_c_obj *c,
347 struct most_c_attr *attr,
351 int ret = kstrtou16(buf, 0, &c->cfg.num_buffers);
358 static ssize_t show_set_buffer_size(struct most_c_obj *c,
359 struct most_c_attr *attr,
362 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size);
365 static ssize_t store_set_buffer_size(struct most_c_obj *c,
366 struct most_c_attr *attr,
370 int ret = kstrtou16(buf, 0, &c->cfg.buffer_size);
377 static ssize_t show_set_direction(struct most_c_obj *c,
378 struct most_c_attr *attr,
381 if (c->cfg.direction & MOST_CH_TX)
382 return snprintf(buf, PAGE_SIZE, "dir_tx\n");
383 else if (c->cfg.direction & MOST_CH_RX)
384 return snprintf(buf, PAGE_SIZE, "dir_rx\n");
385 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
388 static ssize_t store_set_direction(struct most_c_obj *c,
389 struct most_c_attr *attr,
393 if (!strcmp(buf, "dir_rx\n"))
394 c->cfg.direction = MOST_CH_RX;
395 else if (!strcmp(buf, "dir_tx\n"))
396 c->cfg.direction = MOST_CH_TX;
398 pr_info("WARN: invalid attribute settings\n");
404 static ssize_t show_set_datatype(struct most_c_obj *c,
405 struct most_c_attr *attr,
408 if (c->cfg.data_type & MOST_CH_CONTROL)
409 return snprintf(buf, PAGE_SIZE, "control\n");
410 else if (c->cfg.data_type & MOST_CH_ASYNC)
411 return snprintf(buf, PAGE_SIZE, "async\n");
412 else if (c->cfg.data_type & MOST_CH_SYNC)
413 return snprintf(buf, PAGE_SIZE, "sync\n");
414 else if (c->cfg.data_type & MOST_CH_ISOC_AVP)
415 return snprintf(buf, PAGE_SIZE, "isoc_avp\n");
416 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
419 static ssize_t store_set_datatype(struct most_c_obj *c,
420 struct most_c_attr *attr,
424 if (!strcmp(buf, "control\n"))
425 c->cfg.data_type = MOST_CH_CONTROL;
426 else if (!strcmp(buf, "async\n"))
427 c->cfg.data_type = MOST_CH_ASYNC;
428 else if (!strcmp(buf, "sync\n"))
429 c->cfg.data_type = MOST_CH_SYNC;
430 else if (!strcmp(buf, "isoc_avp\n"))
431 c->cfg.data_type = MOST_CH_ISOC_AVP;
433 pr_info("WARN: invalid attribute settings\n");
439 static ssize_t show_set_subbuffer_size(struct most_c_obj *c,
440 struct most_c_attr *attr,
443 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size);
446 static ssize_t store_set_subbuffer_size(struct most_c_obj *c,
447 struct most_c_attr *attr,
451 int ret = kstrtou16(buf, 0, &c->cfg.subbuffer_size);
458 static ssize_t show_set_packets_per_xact(struct most_c_obj *c,
459 struct most_c_attr *attr,
462 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact);
465 static ssize_t store_set_packets_per_xact(struct most_c_obj *c,
466 struct most_c_attr *attr,
470 int ret = kstrtou16(buf, 0, &c->cfg.packets_per_xact);
477 #define create_channel_attribute(value) \
478 static MOST_CHNL_ATTR(value, S_IRUGO | S_IWUSR, \
482 create_channel_attribute(set_buffer_size);
483 create_channel_attribute(set_number_of_buffers);
484 create_channel_attribute(set_direction);
485 create_channel_attribute(set_datatype);
486 create_channel_attribute(set_subbuffer_size);
487 create_channel_attribute(set_packets_per_xact);
491 * most_channel_def_attrs - array of default attributes of channel object
493 static struct attribute *most_channel_def_attrs[] = {
494 &most_chnl_attr_available_directions.attr,
495 &most_chnl_attr_available_datatypes.attr,
496 &most_chnl_attr_number_of_packet_buffers.attr,
497 &most_chnl_attr_number_of_stream_buffers.attr,
498 &most_chnl_attr_size_of_packet_buffer.attr,
499 &most_chnl_attr_size_of_stream_buffer.attr,
500 &most_chnl_attr_set_number_of_buffers.attr,
501 &most_chnl_attr_set_buffer_size.attr,
502 &most_chnl_attr_set_direction.attr,
503 &most_chnl_attr_set_datatype.attr,
504 &most_chnl_attr_set_subbuffer_size.attr,
505 &most_chnl_attr_set_packets_per_xact.attr,
506 &most_chnl_attr_channel_starving.attr,
510 static struct kobj_type most_channel_ktype = {
511 .sysfs_ops = &most_channel_sysfs_ops,
512 .release = most_channel_release,
513 .default_attrs = most_channel_def_attrs,
516 static struct kset *most_channel_kset;
519 * create_most_c_obj - allocates a channel object
520 * @name: name of the channel object
521 * @parent: parent kobject
523 * This create a channel object and registers it with sysfs.
524 * Returns a pointer to the object or NULL when something went wrong.
526 static struct most_c_obj *
527 create_most_c_obj(const char *name, struct kobject *parent)
529 struct most_c_obj *c;
532 c = kzalloc(sizeof(*c), GFP_KERNEL);
535 c->kobj.kset = most_channel_kset;
536 retval = kobject_init_and_add(&c->kobj, &most_channel_ktype, parent,
539 kobject_put(&c->kobj);
542 kobject_uevent(&c->kobj, KOBJ_ADD);
547 * destroy_most_c_obj - channel release function
548 * @c: pointer to channel object
550 * This decrements the reference counter of the channel object.
551 * If the reference count turns zero, its release function is called.
553 static void destroy_most_c_obj(struct most_c_obj *c)
556 c->first_aim->disconnect_channel(c->iface, c->channel_id);
558 c->second_aim->disconnect_channel(c->iface, c->channel_id);
560 c->second_aim = NULL;
562 mutex_lock(&deregister_mutex);
564 flush_channel_fifos(c);
565 mutex_unlock(&deregister_mutex);
566 kobject_put(&c->kobj);
570 * ___I N S T A N C E___
572 #define MOST_INST_ATTR(_name, _mode, _show, _store) \
573 struct most_inst_attribute most_inst_attr_##_name = \
574 __ATTR(_name, _mode, _show, _store)
576 static struct list_head instance_list;
579 * struct most_inst_attribute - to access the attributes of instance object
580 * @attr: attributes of an instance
581 * @show: pointer to the show function
582 * @store: pointer to the store function
584 struct most_inst_attribute {
585 struct attribute attr;
586 ssize_t (*show)(struct most_inst_obj *d,
587 struct most_inst_attribute *attr,
589 ssize_t (*store)(struct most_inst_obj *d,
590 struct most_inst_attribute *attr,
594 #define to_instance_attr(a) \
595 container_of(a, struct most_inst_attribute, attr)
598 * instance_attr_show - show function for an instance object
599 * @kobj: pointer to kobject
600 * @attr: pointer to attribute struct
603 static ssize_t instance_attr_show(struct kobject *kobj,
604 struct attribute *attr,
607 struct most_inst_attribute *instance_attr;
608 struct most_inst_obj *instance_obj;
610 instance_attr = to_instance_attr(attr);
611 instance_obj = to_inst_obj(kobj);
613 if (!instance_attr->show)
616 return instance_attr->show(instance_obj, instance_attr, buf);
620 * instance_attr_store - store function for an instance object
621 * @kobj: pointer to kobject
622 * @attr: pointer to attribute struct
624 * @len: length of buffer
626 static ssize_t instance_attr_store(struct kobject *kobj,
627 struct attribute *attr,
631 struct most_inst_attribute *instance_attr;
632 struct most_inst_obj *instance_obj;
634 instance_attr = to_instance_attr(attr);
635 instance_obj = to_inst_obj(kobj);
637 if (!instance_attr->store)
640 return instance_attr->store(instance_obj, instance_attr, buf, len);
643 static const struct sysfs_ops most_inst_sysfs_ops = {
644 .show = instance_attr_show,
645 .store = instance_attr_store,
649 * most_inst_release - release function for instance object
650 * @kobj: pointer to instance's kobject
652 * This frees the allocated memory for the instance object
654 static void most_inst_release(struct kobject *kobj)
656 struct most_inst_obj *inst = to_inst_obj(kobj);
661 static ssize_t show_description(struct most_inst_obj *instance_obj,
662 struct most_inst_attribute *attr,
665 return snprintf(buf, PAGE_SIZE, "%s\n",
666 instance_obj->iface->description);
669 static ssize_t show_interface(struct most_inst_obj *instance_obj,
670 struct most_inst_attribute *attr,
673 switch (instance_obj->iface->interface) {
675 return snprintf(buf, PAGE_SIZE, "loopback\n");
677 return snprintf(buf, PAGE_SIZE, "i2c\n");
679 return snprintf(buf, PAGE_SIZE, "i2s\n");
681 return snprintf(buf, PAGE_SIZE, "tsi\n");
683 return snprintf(buf, PAGE_SIZE, "hbi\n");
684 case ITYPE_MEDIALB_DIM:
685 return snprintf(buf, PAGE_SIZE, "mlb_dim\n");
686 case ITYPE_MEDIALB_DIM2:
687 return snprintf(buf, PAGE_SIZE, "mlb_dim2\n");
689 return snprintf(buf, PAGE_SIZE, "usb\n");
691 return snprintf(buf, PAGE_SIZE, "pcie\n");
693 return snprintf(buf, PAGE_SIZE, "unknown\n");
696 #define create_inst_attribute(value) \
697 static MOST_INST_ATTR(value, S_IRUGO, show_##value, NULL)
699 create_inst_attribute(description);
700 create_inst_attribute(interface);
702 static struct attribute *most_inst_def_attrs[] = {
703 &most_inst_attr_description.attr,
704 &most_inst_attr_interface.attr,
708 static struct kobj_type most_inst_ktype = {
709 .sysfs_ops = &most_inst_sysfs_ops,
710 .release = most_inst_release,
711 .default_attrs = most_inst_def_attrs,
714 static struct kset *most_inst_kset;
718 * create_most_inst_obj - creates an instance object
719 * @name: name of the object to be created
721 * This allocates memory for an instance structure, assigns the proper kset
722 * and registers it with sysfs.
724 * Returns a pointer to the instance object or NULL when something went wrong.
726 static struct most_inst_obj *create_most_inst_obj(const char *name)
728 struct most_inst_obj *inst;
731 inst = kzalloc(sizeof(*inst), GFP_KERNEL);
734 inst->kobj.kset = most_inst_kset;
735 retval = kobject_init_and_add(&inst->kobj, &most_inst_ktype, NULL,
738 kobject_put(&inst->kobj);
741 kobject_uevent(&inst->kobj, KOBJ_ADD);
746 * destroy_most_inst_obj - MOST instance release function
747 * @inst: pointer to the instance object
749 * This decrements the reference counter of the instance object.
750 * If the reference count turns zero, its release function is called
752 static void destroy_most_inst_obj(struct most_inst_obj *inst)
754 struct most_c_obj *c, *tmp;
756 /* need to destroy channels first, since
757 * each channel incremented the
758 * reference count of the inst->kobj
760 list_for_each_entry_safe(c, tmp, &inst->channel_list, list) {
761 destroy_most_c_obj(c);
763 kobject_put(&inst->kobj);
769 struct most_aim_obj {
771 struct list_head list;
772 struct most_aim *driver;
773 char add_link[STRING_SIZE];
774 char remove_link[STRING_SIZE];
776 #define to_aim_obj(d) container_of(d, struct most_aim_obj, kobj)
778 static struct list_head aim_list;
782 * struct most_aim_attribute - to access the attributes of AIM object
783 * @attr: attributes of an AIM
784 * @show: pointer to the show function
785 * @store: pointer to the store function
787 struct most_aim_attribute {
788 struct attribute attr;
789 ssize_t (*show)(struct most_aim_obj *d,
790 struct most_aim_attribute *attr,
792 ssize_t (*store)(struct most_aim_obj *d,
793 struct most_aim_attribute *attr,
797 #define to_aim_attr(a) container_of(a, struct most_aim_attribute, attr)
800 * aim_attr_show - show function of an AIM object
801 * @kobj: pointer to kobject
802 * @attr: pointer to attribute struct
805 static ssize_t aim_attr_show(struct kobject *kobj,
806 struct attribute *attr,
809 struct most_aim_attribute *aim_attr;
810 struct most_aim_obj *aim_obj;
812 aim_attr = to_aim_attr(attr);
813 aim_obj = to_aim_obj(kobj);
818 return aim_attr->show(aim_obj, aim_attr, buf);
822 * aim_attr_store - store function of an AIM object
823 * @kobj: pointer to kobject
824 * @attr: pointer to attribute struct
826 * @len: length of buffer
828 static ssize_t aim_attr_store(struct kobject *kobj,
829 struct attribute *attr,
833 struct most_aim_attribute *aim_attr;
834 struct most_aim_obj *aim_obj;
836 aim_attr = to_aim_attr(attr);
837 aim_obj = to_aim_obj(kobj);
839 if (!aim_attr->store)
841 return aim_attr->store(aim_obj, aim_attr, buf, len);
844 static const struct sysfs_ops most_aim_sysfs_ops = {
845 .show = aim_attr_show,
846 .store = aim_attr_store,
850 * most_aim_release - AIM release function
851 * @kobj: pointer to AIM's kobject
853 static void most_aim_release(struct kobject *kobj)
855 struct most_aim_obj *aim_obj = to_aim_obj(kobj);
860 static ssize_t show_add_link(struct most_aim_obj *aim_obj,
861 struct most_aim_attribute *attr,
864 return snprintf(buf, PAGE_SIZE, "%s\n", aim_obj->add_link);
868 * split_string - parses and changes string in the buffer buf and
869 * splits it into two mandatory and one optional substrings.
871 * @buf: complete string from attribute 'add_channel'
872 * @a: address of pointer to 1st substring (=instance name)
873 * @b: address of pointer to 2nd substring (=channel name)
874 * @c: optional address of pointer to 3rd substring (=user defined name)
878 * Input: "mdev0:ch0@ep_81:my_channel\n" or
879 * "mdev0:ch0@ep_81:my_channel"
881 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c -> "my_channel"
883 * Input: "mdev0:ch0@ep_81\n"
884 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c -> ""
886 * Input: "mdev0:ch0@ep_81"
887 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c == NULL
889 static int split_string(char *buf, char **a, char **b, char **c)
891 *a = strsep(&buf, ":");
895 *b = strsep(&buf, ":\n");
900 *c = strsep(&buf, ":\n");
906 * get_channel_by_name - get pointer to channel object
907 * @mdev: name of the device instance
908 * @mdev_ch: name of the respective channel
910 * This retrieves the pointer to a channel object.
913 most_c_obj *get_channel_by_name(char *mdev, char *mdev_ch)
915 struct most_c_obj *c, *tmp;
916 struct most_inst_obj *i, *i_tmp;
919 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
920 if (!strcmp(kobject_name(&i->kobj), mdev)) {
925 if (unlikely(!found))
926 return ERR_PTR(-EIO);
928 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
929 if (!strcmp(kobject_name(&c->kobj), mdev_ch)) {
934 if (unlikely(2 > found))
935 return ERR_PTR(-EIO);
940 * store_add_link - store() function for add_link attribute
941 * @aim_obj: pointer to AIM object
942 * @attr: its attributes
944 * @len: buffer length
946 * This parses the string given by buf and splits it into
947 * three substrings. Note: third substring is optional. In case a cdev
948 * AIM is loaded the optional 3rd substring will make up the name of
949 * device node in the /dev directory. If omitted, the device node will
950 * inherit the channel's name within sysfs.
952 * Searches for a pair of device and channel and probes the AIM
955 * (1) echo -n -e "mdev0:ch0@ep_81:my_rxchannel\n" >add_link
956 * (2) echo -n -e "mdev0:ch0@ep_81\n" >add_link
958 * (1) would create the device node /dev/my_rxchannel
959 * (2) would create the device node /dev/mdev0-ch0@ep_81
961 static ssize_t store_add_link(struct most_aim_obj *aim_obj,
962 struct most_aim_attribute *attr,
966 struct most_c_obj *c;
967 struct most_aim **aim_ptr;
968 char buffer[STRING_SIZE];
972 char devnod_buf[STRING_SIZE];
974 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
976 strlcpy(buffer, buf, max_len);
977 strlcpy(aim_obj->add_link, buf, max_len);
979 ret = split_string(buffer, &mdev, &mdev_ch, &mdev_devnod);
983 if (!mdev_devnod || *mdev_devnod == 0) {
984 snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev, mdev_ch);
985 mdev_devnod = devnod_buf;
988 c = get_channel_by_name(mdev, mdev_ch);
993 aim_ptr = &c->first_aim;
994 else if (!c->second_aim)
995 aim_ptr = &c->second_aim;
999 ret = aim_obj->driver->probe_channel(c->iface, c->channel_id,
1000 &c->cfg, &c->kobj, mdev_devnod);
1003 *aim_ptr = aim_obj->driver;
1007 static struct most_aim_attribute most_aim_attr_add_link =
1008 __ATTR(add_link, S_IRUGO | S_IWUSR, show_add_link, store_add_link);
1010 static ssize_t show_remove_link(struct most_aim_obj *aim_obj,
1011 struct most_aim_attribute *attr,
1014 return snprintf(buf, PAGE_SIZE, "%s\n", aim_obj->remove_link);
1018 * store_remove_link - store function for remove_link attribute
1019 * @aim_obj: pointer to AIM object
1020 * @attr: its attributes
1022 * @len: buffer length
1025 * echo -n -e "mdev0:ch0@ep_81\n" >remove_link
1027 static ssize_t store_remove_link(struct most_aim_obj *aim_obj,
1028 struct most_aim_attribute *attr,
1032 struct most_c_obj *c;
1033 char buffer[STRING_SIZE];
1037 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
1039 strlcpy(buffer, buf, max_len);
1040 strlcpy(aim_obj->remove_link, buf, max_len);
1041 ret = split_string(buffer, &mdev, &mdev_ch, NULL);
1045 c = get_channel_by_name(mdev, mdev_ch);
1049 if (c->first_aim == aim_obj->driver)
1050 c->first_aim = NULL;
1051 if (c->second_aim == aim_obj->driver)
1052 c->second_aim = NULL;
1053 if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id))
1058 static struct most_aim_attribute most_aim_attr_remove_link =
1059 __ATTR(remove_link, S_IRUGO | S_IWUSR, show_remove_link, store_remove_link);
1061 static struct attribute *most_aim_def_attrs[] = {
1062 &most_aim_attr_add_link.attr,
1063 &most_aim_attr_remove_link.attr,
1067 static struct kobj_type most_aim_ktype = {
1068 .sysfs_ops = &most_aim_sysfs_ops,
1069 .release = most_aim_release,
1070 .default_attrs = most_aim_def_attrs,
1073 static struct kset *most_aim_kset;
1076 * create_most_aim_obj - creates an AIM object
1077 * @name: name of the AIM
1079 * This creates an AIM object assigns the proper kset and registers
1081 * Returns a pointer to the object or NULL if something went wrong.
1083 static struct most_aim_obj *create_most_aim_obj(const char *name)
1085 struct most_aim_obj *most_aim;
1088 most_aim = kzalloc(sizeof(*most_aim), GFP_KERNEL);
1091 most_aim->kobj.kset = most_aim_kset;
1092 retval = kobject_init_and_add(&most_aim->kobj, &most_aim_ktype,
1095 kobject_put(&most_aim->kobj);
1098 kobject_uevent(&most_aim->kobj, KOBJ_ADD);
1103 * destroy_most_aim_obj - AIM release function
1104 * @p: pointer to AIM object
1106 * This decrements the reference counter of the AIM object. If the
1107 * reference count turns zero, its release function will be called.
1109 static void destroy_most_aim_obj(struct most_aim_obj *p)
1111 kobject_put(&p->kobj);
1120 * Instantiation of the MOST bus
1122 static struct bus_type most_bus = {
1127 * Instantiation of the core driver
1129 static struct device_driver mostcore = {
1134 static inline void trash_mbo(struct mbo *mbo)
1136 unsigned long flags;
1137 struct most_c_obj *c = mbo->context;
1139 spin_lock_irqsave(&c->fifo_lock, flags);
1140 list_add(&mbo->list, &c->trash_fifo);
1141 spin_unlock_irqrestore(&c->fifo_lock, flags);
1144 static struct mbo *get_hdm_mbo(struct most_c_obj *c)
1146 unsigned long flags;
1149 spin_lock_irqsave(&c->fifo_lock, flags);
1150 if (c->enqueue_halt || list_empty(&c->halt_fifo))
1153 mbo = list_pop_mbo(&c->halt_fifo);
1154 spin_unlock_irqrestore(&c->fifo_lock, flags);
1158 static void nq_hdm_mbo(struct mbo *mbo)
1160 unsigned long flags;
1161 struct most_c_obj *c = mbo->context;
1163 spin_lock_irqsave(&c->fifo_lock, flags);
1164 list_add_tail(&mbo->list, &c->halt_fifo);
1165 spin_unlock_irqrestore(&c->fifo_lock, flags);
1166 wake_up_interruptible(&c->hdm_fifo_wq);
1169 static int hdm_enqueue_thread(void *data)
1171 struct most_c_obj *c = data;
1173 typeof(c->iface->enqueue) enqueue = c->iface->enqueue;
1175 while (likely(!kthread_should_stop())) {
1176 wait_event_interruptible(c->hdm_fifo_wq,
1177 (mbo = get_hdm_mbo(c))
1178 || kthread_should_stop());
1183 if (c->cfg.direction == MOST_CH_RX)
1184 mbo->buffer_length = c->cfg.buffer_size;
1186 if (unlikely(enqueue(mbo->ifp, mbo->hdm_channel_id, mbo))) {
1187 pr_err("hdm enqueue failed\n");
1189 c->hdm_enqueue_task = NULL;
1197 static int run_enqueue_thread(struct most_c_obj *c, int channel_id)
1199 struct task_struct *task =
1200 kthread_run(&hdm_enqueue_thread, c, "hdm_fifo_%d", channel_id);
1203 return PTR_ERR(task);
1205 c->hdm_enqueue_task = task;
1210 * arm_mbo - recycle MBO for further usage
1211 * @mbo: buffer object
1213 * This puts an MBO back to the list to have it ready for up coming
1216 * In case the MBO belongs to a channel that recently has been
1217 * poisoned, the MBO is scheduled to be trashed.
1218 * Calls the completion handler of an attached AIM.
1220 static void arm_mbo(struct mbo *mbo)
1222 unsigned long flags;
1223 struct most_c_obj *c;
1225 BUG_ON((!mbo) || (!mbo->context));
1228 if (c->is_poisoned) {
1233 spin_lock_irqsave(&c->fifo_lock, flags);
1234 list_add_tail(&mbo->list, &c->fifo);
1235 spin_unlock_irqrestore(&c->fifo_lock, flags);
1237 if (c->second_aim && c->second_aim->tx_completion)
1238 c->second_aim->tx_completion(c->iface, c->channel_id);
1239 if (c->first_aim && c->first_aim->tx_completion)
1240 c->first_aim->tx_completion(c->iface, c->channel_id);
1244 * arm_mbo_chain - helper function that arms an MBO chain for the HDM
1245 * @c: pointer to interface channel
1246 * @dir: direction of the channel
1247 * @compl: pointer to completion function
1249 * This allocates buffer objects including the containing DMA coherent
1250 * buffer and puts them in the fifo.
1251 * Buffers of Rx channels are put in the kthread fifo, hence immediately
1252 * submitted to the HDM.
1254 * Returns the number of allocated and enqueued MBOs.
1256 static int arm_mbo_chain(struct most_c_obj *c, int dir,
1257 void (*compl)(struct mbo *))
1262 u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
1264 atomic_set(&c->mbo_nq_level, 0);
1266 for (i = 0; i < c->cfg.num_buffers; i++) {
1267 mbo = kzalloc(sizeof(*mbo), GFP_KERNEL);
1269 pr_info("WARN: Allocation of MBO failed.\n");
1274 mbo->ifp = c->iface;
1275 mbo->hdm_channel_id = c->channel_id;
1276 mbo->virt_address = dma_alloc_coherent(NULL,
1280 if (!mbo->virt_address) {
1281 pr_info("WARN: No DMA coherent buffer.\n");
1285 mbo->complete = compl;
1286 if (dir == MOST_CH_RX) {
1288 atomic_inc(&c->mbo_nq_level);
1302 * most_submit_mbo - submits an MBO to fifo
1303 * @mbo: pointer to the MBO
1306 int most_submit_mbo(struct mbo *mbo)
1308 struct most_c_obj *c;
1309 struct most_inst_obj *i;
1311 if (unlikely((!mbo) || (!mbo->context))) {
1312 pr_err("Bad MBO or missing channel reference\n");
1318 if (unlikely(atomic_read(&i->tainted)))
1324 EXPORT_SYMBOL_GPL(most_submit_mbo);
1327 * most_write_completion - write completion handler
1328 * @mbo: pointer to MBO
1330 * This recycles the MBO for further usage. In case the channel has been
1331 * poisoned, the MBO is scheduled to be trashed.
1333 static void most_write_completion(struct mbo *mbo)
1335 struct most_c_obj *c;
1337 BUG_ON((!mbo) || (!mbo->context));
1340 if (mbo->status == MBO_E_INVAL)
1341 pr_info("WARN: Tx MBO status: invalid\n");
1342 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE)))
1349 * get_channel_by_iface - get pointer to channel object
1350 * @iface: pointer to interface instance
1353 * This retrieves a pointer to a channel of the given interface and channel ID.
1356 most_c_obj *get_channel_by_iface(struct most_interface *iface, int id)
1358 struct most_inst_obj *i;
1360 if (unlikely(!iface)) {
1361 pr_err("Bad interface\n");
1364 if (unlikely((id < 0) || (id >= iface->num_channels))) {
1365 pr_err("Channel index (%d) out of range\n", id);
1370 pr_err("interface is not registered\n");
1373 return i->channel[id];
1377 * most_get_mbo - get pointer to an MBO of pool
1378 * @iface: pointer to interface instance
1381 * This attempts to get a free buffer out of the channel fifo.
1382 * Returns a pointer to MBO on success or NULL otherwise.
1384 struct mbo *most_get_mbo(struct most_interface *iface, int id)
1387 struct most_c_obj *c;
1388 unsigned long flags;
1390 c = get_channel_by_iface(iface, id);
1393 spin_lock_irqsave(&c->fifo_lock, flags);
1394 if (list_empty(&c->fifo)) {
1395 spin_unlock_irqrestore(&c->fifo_lock, flags);
1398 mbo = list_pop_mbo(&c->fifo);
1399 spin_unlock_irqrestore(&c->fifo_lock, flags);
1400 mbo->buffer_length = c->cfg.buffer_size;
1403 EXPORT_SYMBOL_GPL(most_get_mbo);
1407 * most_put_mbo - return buffer to pool
1408 * @mbo: buffer object
1410 void most_put_mbo(struct mbo *mbo)
1412 struct most_c_obj *c;
1413 struct most_inst_obj *i;
1418 if (unlikely(atomic_read(&i->tainted))) {
1419 mbo->status = MBO_E_CLOSE;
1423 if (c->cfg.direction == MOST_CH_TX) {
1428 atomic_inc(&c->mbo_nq_level);
1430 EXPORT_SYMBOL_GPL(most_put_mbo);
1433 * most_read_completion - read completion handler
1434 * @mbo: pointer to MBO
1436 * This function is called by the HDM when data has been received from the
1437 * hardware and copied to the buffer of the MBO.
1439 * In case the channel has been poisoned it puts the buffer in the trash queue.
1440 * Otherwise, it passes the buffer to an AIM for further processing.
1442 static void most_read_completion(struct mbo *mbo)
1444 struct most_c_obj *c;
1447 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE)))
1450 if (mbo->status == MBO_E_INVAL) {
1452 atomic_inc(&c->mbo_nq_level);
1456 if (atomic_sub_and_test(1, &c->mbo_nq_level)) {
1457 pr_info("WARN: rx device out of buffers\n");
1461 if (c->first_aim && c->first_aim->rx_completion &&
1462 c->first_aim->rx_completion(mbo) == 0)
1464 if (c->second_aim && c->second_aim->rx_completion &&
1465 c->second_aim->rx_completion(mbo) == 0)
1467 pr_info("WARN: no driver linked with this channel\n");
1468 mbo->status = MBO_E_CLOSE;
1474 * most_start_channel - prepares a channel for communication
1475 * @iface: pointer to interface instance
1478 * This prepares the channel for usage. Cross-checks whether the
1479 * channel's been properly configured.
1481 * Returns 0 on success or error code otherwise.
1483 int most_start_channel(struct most_interface *iface, int id)
1487 struct most_c_obj *c = get_channel_by_iface(iface, id);
1495 if (!try_module_get(iface->mod)) {
1496 pr_info("failed to acquire HDM lock\n");
1501 c->cfg.extra_len = 0;
1502 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) {
1503 pr_info("channel configuration failed. Go check settings...\n");
1508 init_waitqueue_head(&c->hdm_fifo_wq);
1510 if (c->cfg.direction == MOST_CH_RX)
1511 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1512 most_read_completion);
1514 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1515 most_write_completion);
1516 if (unlikely(0 == num_buffer)) {
1517 pr_info("failed to allocate memory\n");
1522 ret = run_enqueue_thread(c, id);
1526 c->is_started = true;
1528 atomic_set(&c->mbo_ref, num_buffer);
1532 module_put(iface->mod);
1536 EXPORT_SYMBOL_GPL(most_start_channel);
1539 * most_stop_channel - stops a running channel
1540 * @iface: pointer to interface instance
1543 int most_stop_channel(struct most_interface *iface, int id)
1545 struct most_c_obj *c;
1547 if (unlikely((!iface) || (id >= iface->num_channels) || (id < 0))) {
1548 pr_err("Bad interface or index out of range\n");
1551 c = get_channel_by_iface(iface, id);
1558 mutex_lock(&c->stop_task_mutex);
1559 if (c->hdm_enqueue_task)
1560 kthread_stop(c->hdm_enqueue_task);
1561 c->hdm_enqueue_task = NULL;
1562 mutex_unlock(&c->stop_task_mutex);
1564 mutex_lock(&deregister_mutex);
1565 if (atomic_read(&c->inst->tainted)) {
1566 mutex_unlock(&deregister_mutex);
1569 mutex_unlock(&deregister_mutex);
1571 if (iface->mod && modref) {
1572 module_put(iface->mod);
1576 c->is_poisoned = true;
1577 if (c->iface->poison_channel(c->iface, c->channel_id)) {
1578 pr_err("Cannot stop channel %d of mdev %s\n", c->channel_id,
1579 c->iface->description);
1582 flush_trash_fifo(c);
1583 flush_channel_fifos(c);
1585 #ifdef CMPL_INTERRUPTIBLE
1586 if (wait_for_completion_interruptible(&c->cleanup)) {
1587 pr_info("Interrupted while clean up ch %d\n", c->channel_id);
1591 wait_for_completion(&c->cleanup);
1593 c->is_poisoned = false;
1594 c->is_started = false;
1597 EXPORT_SYMBOL_GPL(most_stop_channel);
1600 * most_register_aim - registers an AIM (driver) with the core
1601 * @aim: instance of AIM to be registered
1603 int most_register_aim(struct most_aim *aim)
1605 struct most_aim_obj *aim_obj;
1608 pr_err("Bad driver\n");
1611 aim_obj = create_most_aim_obj(aim->name);
1613 pr_info("failed to alloc driver object\n");
1616 aim_obj->driver = aim;
1617 aim->context = aim_obj;
1618 pr_info("registered new application interfacing module %s\n",
1620 list_add_tail(&aim_obj->list, &aim_list);
1623 EXPORT_SYMBOL_GPL(most_register_aim);
1626 * most_deregister_aim - deregisters an AIM (driver) with the core
1627 * @aim: AIM to be removed
1629 int most_deregister_aim(struct most_aim *aim)
1631 struct most_aim_obj *aim_obj;
1632 struct most_c_obj *c, *tmp;
1633 struct most_inst_obj *i, *i_tmp;
1636 pr_err("Bad driver\n");
1640 aim_obj = aim->context;
1642 pr_info("driver not registered.\n");
1645 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1646 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
1647 if (c->first_aim == aim || c->second_aim == aim)
1648 aim->disconnect_channel(
1649 c->iface, c->channel_id);
1650 if (c->first_aim == aim)
1651 c->first_aim = NULL;
1652 if (c->second_aim == aim)
1653 c->second_aim = NULL;
1656 list_del(&aim_obj->list);
1657 destroy_most_aim_obj(aim_obj);
1658 pr_info("deregistering application interfacing module %s\n", aim->name);
1661 EXPORT_SYMBOL_GPL(most_deregister_aim);
1664 * most_register_interface - registers an interface with core
1665 * @iface: pointer to the instance of the interface description.
1667 * Allocates and initializes a new interface instance and all of its channels.
1668 * Returns a pointer to kobject or an error pointer.
1670 struct kobject *most_register_interface(struct most_interface *iface)
1674 char name[STRING_SIZE];
1675 char channel_name[STRING_SIZE];
1676 struct most_c_obj *c;
1677 struct most_inst_obj *inst;
1679 if (!iface || !iface->enqueue || !iface->configure ||
1680 !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) {
1681 pr_err("Bad interface or channel overflow\n");
1682 return ERR_PTR(-EINVAL);
1685 id = ida_simple_get(&mdev_id, 0, 0, GFP_KERNEL);
1687 pr_info("Failed to alloc mdev ID\n");
1690 snprintf(name, STRING_SIZE, "mdev%d", id);
1692 inst = create_most_inst_obj(name);
1694 pr_info("Failed to allocate interface instance\n");
1695 return ERR_PTR(-ENOMEM);
1699 INIT_LIST_HEAD(&inst->channel_list);
1700 inst->iface = iface;
1702 atomic_set(&inst->tainted, 0);
1703 list_add_tail(&inst->list, &instance_list);
1705 for (i = 0; i < iface->num_channels; i++) {
1706 const char *name_suffix = iface->channel_vector[i].name_suffix;
1709 snprintf(channel_name, STRING_SIZE, "ch%d", i);
1710 else if (name_suffix[0] == '@')
1711 snprintf(channel_name, STRING_SIZE, "ch%d%s", i,
1714 snprintf(channel_name, STRING_SIZE, "%s", name_suffix);
1716 /* this increments the reference count of this instance */
1717 c = create_most_c_obj(channel_name, &inst->kobj);
1720 inst->channel[i] = c;
1725 c->keep_mbo = false;
1726 c->enqueue_halt = false;
1727 c->is_poisoned = false;
1728 c->is_started = false;
1729 c->cfg.direction = 0;
1730 c->cfg.data_type = 0;
1731 c->cfg.num_buffers = 0;
1732 c->cfg.buffer_size = 0;
1733 c->cfg.subbuffer_size = 0;
1734 c->cfg.packets_per_xact = 0;
1735 spin_lock_init(&c->fifo_lock);
1736 INIT_LIST_HEAD(&c->fifo);
1737 INIT_LIST_HEAD(&c->trash_fifo);
1738 INIT_LIST_HEAD(&c->halt_fifo);
1739 init_completion(&c->cleanup);
1740 atomic_set(&c->mbo_ref, 0);
1741 mutex_init(&c->stop_task_mutex);
1742 list_add_tail(&c->list, &inst->channel_list);
1744 pr_info("registered new MOST device mdev%d (%s)\n",
1745 inst->dev_id, iface->description);
1749 pr_info("Failed allocate channel(s)\n");
1750 list_del(&inst->list);
1751 destroy_most_inst_obj(inst);
1752 return ERR_PTR(-ENOMEM);
1754 EXPORT_SYMBOL_GPL(most_register_interface);
1757 * most_deregister_interface - deregisters an interface with core
1758 * @iface: pointer to the interface instance description.
1760 * Before removing an interface instance from the list, all running
1761 * channels are stopped and poisoned.
1763 void most_deregister_interface(struct most_interface *iface)
1765 struct most_inst_obj *i = iface->priv;
1766 struct most_c_obj *c;
1768 mutex_lock(&deregister_mutex);
1770 pr_info("Bad Interface\n");
1771 mutex_unlock(&deregister_mutex);
1774 pr_info("deregistering MOST device %s (%s)\n", i->kobj.name,
1775 iface->description);
1777 atomic_set(&i->tainted, 1);
1778 mutex_unlock(&deregister_mutex);
1781 if (iface->mod && modref)
1782 module_put(iface->mod);
1786 list_for_each_entry(c, &i->channel_list, list) {
1790 mutex_lock(&c->stop_task_mutex);
1791 if (c->hdm_enqueue_task)
1792 kthread_stop(c->hdm_enqueue_task);
1793 c->hdm_enqueue_task = NULL;
1794 mutex_unlock(&c->stop_task_mutex);
1796 if (iface->poison_channel(iface, c->channel_id))
1797 pr_err("Can't poison channel %d\n", c->channel_id);
1799 ida_simple_remove(&mdev_id, i->dev_id);
1801 destroy_most_inst_obj(i);
1803 EXPORT_SYMBOL_GPL(most_deregister_interface);
1806 * most_stop_enqueue - prevents core from enqueueing MBOs
1807 * @iface: pointer to interface
1810 * This is called by an HDM that _cannot_ attend to its duties and
1811 * is imminent to get run over by the core. The core is not going to
1812 * enqueue any further packets unless the flagging HDM calls
1813 * most_resume enqueue().
1815 void most_stop_enqueue(struct most_interface *iface, int id)
1817 struct most_c_obj *c = get_channel_by_iface(iface, id);
1820 c->enqueue_halt = true;
1822 EXPORT_SYMBOL_GPL(most_stop_enqueue);
1825 * most_resume_enqueue - allow core to enqueue MBOs again
1826 * @iface: pointer to interface
1829 * This clears the enqueue halt flag and enqueues all MBOs currently
1830 * sitting in the wait fifo.
1832 void most_resume_enqueue(struct most_interface *iface, int id)
1834 struct most_c_obj *c = get_channel_by_iface(iface, id);
1838 c->enqueue_halt = false;
1840 wake_up_interruptible(&c->hdm_fifo_wq);
1842 EXPORT_SYMBOL_GPL(most_resume_enqueue);
1844 static int __init most_init(void)
1846 pr_info("init()\n");
1847 INIT_LIST_HEAD(&instance_list);
1848 INIT_LIST_HEAD(&aim_list);
1849 mutex_init(&deregister_mutex);
1852 if (bus_register(&most_bus)) {
1853 pr_info("Cannot register most bus\n");
1857 most_class = class_create(THIS_MODULE, "most");
1858 if (IS_ERR(most_class)) {
1859 pr_info("No udev support.\n");
1862 if (driver_register(&mostcore)) {
1863 pr_info("Cannot register core driver\n");
1868 device_create(most_class, NULL, 0, NULL, "mostcore");
1869 if (!class_glue_dir)
1873 kset_create_and_add("aims", NULL, &class_glue_dir->kobj);
1875 goto exit_class_container;
1878 kset_create_and_add("devices", NULL, &class_glue_dir->kobj);
1879 if (!most_inst_kset)
1880 goto exit_driver_kset;
1885 kset_unregister(most_aim_kset);
1886 exit_class_container:
1887 device_destroy(most_class, 0);
1889 driver_unregister(&mostcore);
1891 class_destroy(most_class);
1893 bus_unregister(&most_bus);
1898 static void __exit most_exit(void)
1900 struct most_inst_obj *i, *i_tmp;
1901 struct most_aim_obj *d, *d_tmp;
1903 pr_info("exit core module\n");
1904 list_for_each_entry_safe(d, d_tmp, &aim_list, list) {
1905 destroy_most_aim_obj(d);
1908 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1910 destroy_most_inst_obj(i);
1912 kset_unregister(most_inst_kset);
1913 kset_unregister(most_aim_kset);
1914 device_destroy(most_class, 0);
1915 driver_unregister(&mostcore);
1916 class_destroy(most_class);
1917 bus_unregister(&most_bus);
1918 ida_destroy(&mdev_id);
1921 module_init(most_init);
1922 module_exit(most_exit);
1923 MODULE_LICENSE("GPL");
1924 MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
1925 MODULE_DESCRIPTION("Core module of stacked MOST Linux driver");