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;
38 static int dummy_num_buffers;
40 struct most_c_aim_obj {
48 struct completion cleanup;
50 atomic_t mbo_nq_level;
53 struct mutex start_mutex;
55 struct most_interface *iface;
56 struct most_inst_obj *inst;
57 struct most_channel_config cfg;
60 struct list_head fifo;
62 struct list_head halt_fifo;
63 struct list_head list;
64 struct most_c_aim_obj aim0;
65 struct most_c_aim_obj aim1;
66 struct list_head trash_fifo;
67 struct task_struct *hdm_enqueue_task;
68 wait_queue_head_t hdm_fifo_wq;
71 #define to_c_obj(d) container_of(d, struct most_c_obj, kobj)
73 struct most_inst_obj {
75 struct most_interface *iface;
76 struct list_head channel_list;
77 struct most_c_obj *channel[MAX_CHANNELS];
79 struct list_head list;
83 int most_ch_data_type;
85 } ch_data_type[] = { { MOST_CH_CONTROL, "control\n" },
86 { MOST_CH_ASYNC, "async\n" },
87 { MOST_CH_SYNC, "sync\n" },
88 { MOST_CH_ISOC_AVP, "isoc_avp\n"} };
90 #define to_inst_obj(d) container_of(d, struct most_inst_obj, kobj)
93 * list_pop_mbo - retrieves the first MBO of the list and removes it
94 * @ptr: the list head to grab the MBO from.
96 #define list_pop_mbo(ptr) \
98 struct mbo *_mbo = list_first_entry(ptr, struct mbo, list); \
99 list_del(&_mbo->list); \
104 * ___C H A N N E L___
108 * struct most_c_attr - to access the attributes of a channel object
109 * @attr: attributes of a channel
110 * @show: pointer to the show function
111 * @store: pointer to the store function
114 struct attribute attr;
115 ssize_t (*show)(struct most_c_obj *d,
116 struct most_c_attr *attr,
118 ssize_t (*store)(struct most_c_obj *d,
119 struct most_c_attr *attr,
124 #define to_channel_attr(a) container_of(a, struct most_c_attr, attr)
126 #define MOST_CHNL_ATTR(_name, _mode, _show, _store) \
127 struct most_c_attr most_chnl_attr_##_name = \
128 __ATTR(_name, _mode, _show, _store)
131 * channel_attr_show - show function of channel object
132 * @kobj: pointer to its kobject
133 * @attr: pointer to its attributes
136 static ssize_t channel_attr_show(struct kobject *kobj, struct attribute *attr,
139 struct most_c_attr *channel_attr = to_channel_attr(attr);
140 struct most_c_obj *c_obj = to_c_obj(kobj);
142 if (!channel_attr->show)
145 return channel_attr->show(c_obj, channel_attr, buf);
149 * channel_attr_store - store function of channel object
150 * @kobj: pointer to its kobject
151 * @attr: pointer to its attributes
153 * @len: length of buffer
155 static ssize_t channel_attr_store(struct kobject *kobj,
156 struct attribute *attr,
160 struct most_c_attr *channel_attr = to_channel_attr(attr);
161 struct most_c_obj *c_obj = to_c_obj(kobj);
163 if (!channel_attr->store)
165 return channel_attr->store(c_obj, channel_attr, buf, len);
168 static const struct sysfs_ops most_channel_sysfs_ops = {
169 .show = channel_attr_show,
170 .store = channel_attr_store,
174 * most_free_mbo_coherent - free an MBO and its coherent buffer
175 * @mbo: buffer to be released
178 static void most_free_mbo_coherent(struct mbo *mbo)
180 struct most_c_obj *c = mbo->context;
181 u16 const coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
183 dma_free_coherent(NULL, coherent_buf_size, mbo->virt_address,
186 if (atomic_sub_and_test(1, &c->mbo_ref))
187 complete(&c->cleanup);
191 * flush_channel_fifos - clear the channel fifos
192 * @c: pointer to channel object
194 static void flush_channel_fifos(struct most_c_obj *c)
196 unsigned long flags, hf_flags;
197 struct mbo *mbo, *tmp;
199 if (list_empty(&c->fifo) && list_empty(&c->halt_fifo))
202 spin_lock_irqsave(&c->fifo_lock, flags);
203 list_for_each_entry_safe(mbo, tmp, &c->fifo, list) {
204 list_del(&mbo->list);
205 spin_unlock_irqrestore(&c->fifo_lock, flags);
206 most_free_mbo_coherent(mbo);
207 spin_lock_irqsave(&c->fifo_lock, flags);
209 spin_unlock_irqrestore(&c->fifo_lock, flags);
211 spin_lock_irqsave(&c->fifo_lock, hf_flags);
212 list_for_each_entry_safe(mbo, tmp, &c->halt_fifo, list) {
213 list_del(&mbo->list);
214 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
215 most_free_mbo_coherent(mbo);
216 spin_lock_irqsave(&c->fifo_lock, hf_flags);
218 spin_unlock_irqrestore(&c->fifo_lock, hf_flags);
220 if (unlikely((!list_empty(&c->fifo) || !list_empty(&c->halt_fifo))))
221 pr_info("WARN: fifo | trash fifo not empty\n");
225 * flush_trash_fifo - clear the trash fifo
226 * @c: pointer to channel object
228 static int flush_trash_fifo(struct most_c_obj *c)
230 struct mbo *mbo, *tmp;
233 spin_lock_irqsave(&c->fifo_lock, flags);
234 list_for_each_entry_safe(mbo, tmp, &c->trash_fifo, list) {
235 list_del(&mbo->list);
236 spin_unlock_irqrestore(&c->fifo_lock, flags);
237 most_free_mbo_coherent(mbo);
238 spin_lock_irqsave(&c->fifo_lock, flags);
240 spin_unlock_irqrestore(&c->fifo_lock, flags);
245 * most_channel_release - release function of channel object
246 * @kobj: pointer to channel's kobject
248 static void most_channel_release(struct kobject *kobj)
250 struct most_c_obj *c = to_c_obj(kobj);
255 static ssize_t show_available_directions(struct most_c_obj *c,
256 struct most_c_attr *attr,
259 unsigned int i = c->channel_id;
262 if (c->iface->channel_vector[i].direction & MOST_CH_RX)
263 strcat(buf, "dir_rx ");
264 if (c->iface->channel_vector[i].direction & MOST_CH_TX)
265 strcat(buf, "dir_tx ");
267 return strlen(buf) + 1;
270 static ssize_t show_available_datatypes(struct most_c_obj *c,
271 struct most_c_attr *attr,
274 unsigned int i = c->channel_id;
277 if (c->iface->channel_vector[i].data_type & MOST_CH_CONTROL)
278 strcat(buf, "control ");
279 if (c->iface->channel_vector[i].data_type & MOST_CH_ASYNC)
280 strcat(buf, "async ");
281 if (c->iface->channel_vector[i].data_type & MOST_CH_SYNC)
282 strcat(buf, "sync ");
283 if (c->iface->channel_vector[i].data_type & MOST_CH_ISOC_AVP)
284 strcat(buf, "isoc_avp ");
286 return strlen(buf) + 1;
290 ssize_t show_number_of_packet_buffers(struct most_c_obj *c,
291 struct most_c_attr *attr,
294 unsigned int i = c->channel_id;
296 return snprintf(buf, PAGE_SIZE, "%d\n",
297 c->iface->channel_vector[i].num_buffers_packet);
301 ssize_t show_number_of_stream_buffers(struct most_c_obj *c,
302 struct most_c_attr *attr,
305 unsigned int i = c->channel_id;
307 return snprintf(buf, PAGE_SIZE, "%d\n",
308 c->iface->channel_vector[i].num_buffers_streaming);
312 ssize_t show_size_of_packet_buffer(struct most_c_obj *c,
313 struct most_c_attr *attr,
316 unsigned int i = c->channel_id;
318 return snprintf(buf, PAGE_SIZE, "%d\n",
319 c->iface->channel_vector[i].buffer_size_packet);
323 ssize_t show_size_of_stream_buffer(struct most_c_obj *c,
324 struct most_c_attr *attr,
327 unsigned int i = c->channel_id;
329 return snprintf(buf, PAGE_SIZE, "%d\n",
330 c->iface->channel_vector[i].buffer_size_streaming);
333 static ssize_t show_channel_starving(struct most_c_obj *c,
334 struct most_c_attr *attr,
337 return snprintf(buf, PAGE_SIZE, "%d\n", c->is_starving);
340 #define create_show_channel_attribute(val) \
341 static MOST_CHNL_ATTR(val, S_IRUGO, show_##val, NULL)
343 create_show_channel_attribute(available_directions);
344 create_show_channel_attribute(available_datatypes);
345 create_show_channel_attribute(number_of_packet_buffers);
346 create_show_channel_attribute(number_of_stream_buffers);
347 create_show_channel_attribute(size_of_stream_buffer);
348 create_show_channel_attribute(size_of_packet_buffer);
349 create_show_channel_attribute(channel_starving);
351 static ssize_t show_set_number_of_buffers(struct most_c_obj *c,
352 struct most_c_attr *attr,
355 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.num_buffers);
358 static ssize_t store_set_number_of_buffers(struct most_c_obj *c,
359 struct most_c_attr *attr,
363 int ret = kstrtou16(buf, 0, &c->cfg.num_buffers);
370 static ssize_t show_set_buffer_size(struct most_c_obj *c,
371 struct most_c_attr *attr,
374 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.buffer_size);
377 static ssize_t store_set_buffer_size(struct most_c_obj *c,
378 struct most_c_attr *attr,
382 int ret = kstrtou16(buf, 0, &c->cfg.buffer_size);
389 static ssize_t show_set_direction(struct most_c_obj *c,
390 struct most_c_attr *attr,
393 if (c->cfg.direction & MOST_CH_TX)
394 return snprintf(buf, PAGE_SIZE, "dir_tx\n");
395 else if (c->cfg.direction & MOST_CH_RX)
396 return snprintf(buf, PAGE_SIZE, "dir_rx\n");
397 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
400 static ssize_t store_set_direction(struct most_c_obj *c,
401 struct most_c_attr *attr,
405 if (!strcmp(buf, "dir_rx\n")) {
406 c->cfg.direction = MOST_CH_RX;
407 } else if (!strcmp(buf, "dir_tx\n")) {
408 c->cfg.direction = MOST_CH_TX;
410 pr_info("WARN: invalid attribute settings\n");
416 static ssize_t show_set_datatype(struct most_c_obj *c,
417 struct most_c_attr *attr,
422 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
423 if (c->cfg.data_type & ch_data_type[i].most_ch_data_type)
424 return snprintf(buf, PAGE_SIZE, ch_data_type[i].name);
426 return snprintf(buf, PAGE_SIZE, "unconfigured\n");
429 static ssize_t store_set_datatype(struct most_c_obj *c,
430 struct most_c_attr *attr,
436 for (i = 0; i < ARRAY_SIZE(ch_data_type); i++) {
437 if (!strcmp(buf, ch_data_type[i].name)) {
438 c->cfg.data_type = ch_data_type[i].most_ch_data_type;
443 if (i == ARRAY_SIZE(ch_data_type)) {
444 pr_info("WARN: invalid attribute settings\n");
450 static ssize_t show_set_subbuffer_size(struct most_c_obj *c,
451 struct most_c_attr *attr,
454 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.subbuffer_size);
457 static ssize_t store_set_subbuffer_size(struct most_c_obj *c,
458 struct most_c_attr *attr,
462 int ret = kstrtou16(buf, 0, &c->cfg.subbuffer_size);
469 static ssize_t show_set_packets_per_xact(struct most_c_obj *c,
470 struct most_c_attr *attr,
473 return snprintf(buf, PAGE_SIZE, "%d\n", c->cfg.packets_per_xact);
476 static ssize_t store_set_packets_per_xact(struct most_c_obj *c,
477 struct most_c_attr *attr,
481 int ret = kstrtou16(buf, 0, &c->cfg.packets_per_xact);
488 #define create_channel_attribute(value) \
489 static MOST_CHNL_ATTR(value, S_IRUGO | S_IWUSR, \
493 create_channel_attribute(set_buffer_size);
494 create_channel_attribute(set_number_of_buffers);
495 create_channel_attribute(set_direction);
496 create_channel_attribute(set_datatype);
497 create_channel_attribute(set_subbuffer_size);
498 create_channel_attribute(set_packets_per_xact);
501 * most_channel_def_attrs - array of default attributes of channel object
503 static struct attribute *most_channel_def_attrs[] = {
504 &most_chnl_attr_available_directions.attr,
505 &most_chnl_attr_available_datatypes.attr,
506 &most_chnl_attr_number_of_packet_buffers.attr,
507 &most_chnl_attr_number_of_stream_buffers.attr,
508 &most_chnl_attr_size_of_packet_buffer.attr,
509 &most_chnl_attr_size_of_stream_buffer.attr,
510 &most_chnl_attr_set_number_of_buffers.attr,
511 &most_chnl_attr_set_buffer_size.attr,
512 &most_chnl_attr_set_direction.attr,
513 &most_chnl_attr_set_datatype.attr,
514 &most_chnl_attr_set_subbuffer_size.attr,
515 &most_chnl_attr_set_packets_per_xact.attr,
516 &most_chnl_attr_channel_starving.attr,
520 static struct kobj_type most_channel_ktype = {
521 .sysfs_ops = &most_channel_sysfs_ops,
522 .release = most_channel_release,
523 .default_attrs = most_channel_def_attrs,
526 static struct kset *most_channel_kset;
529 * create_most_c_obj - allocates a channel object
530 * @name: name of the channel object
531 * @parent: parent kobject
533 * This create a channel object and registers it with sysfs.
534 * Returns a pointer to the object or NULL when something went wrong.
536 static struct most_c_obj *
537 create_most_c_obj(const char *name, struct kobject *parent)
539 struct most_c_obj *c;
542 c = kzalloc(sizeof(*c), GFP_KERNEL);
545 c->kobj.kset = most_channel_kset;
546 retval = kobject_init_and_add(&c->kobj, &most_channel_ktype, parent,
549 kobject_put(&c->kobj);
552 kobject_uevent(&c->kobj, KOBJ_ADD);
557 * ___I N S T A N C E___
559 #define MOST_INST_ATTR(_name, _mode, _show, _store) \
560 struct most_inst_attribute most_inst_attr_##_name = \
561 __ATTR(_name, _mode, _show, _store)
563 static struct list_head instance_list;
566 * struct most_inst_attribute - to access the attributes of instance object
567 * @attr: attributes of an instance
568 * @show: pointer to the show function
569 * @store: pointer to the store function
571 struct most_inst_attribute {
572 struct attribute attr;
573 ssize_t (*show)(struct most_inst_obj *d,
574 struct most_inst_attribute *attr,
576 ssize_t (*store)(struct most_inst_obj *d,
577 struct most_inst_attribute *attr,
582 #define to_instance_attr(a) \
583 container_of(a, struct most_inst_attribute, attr)
586 * instance_attr_show - show function for an instance object
587 * @kobj: pointer to kobject
588 * @attr: pointer to attribute struct
591 static ssize_t instance_attr_show(struct kobject *kobj,
592 struct attribute *attr,
595 struct most_inst_attribute *instance_attr;
596 struct most_inst_obj *instance_obj;
598 instance_attr = to_instance_attr(attr);
599 instance_obj = to_inst_obj(kobj);
601 if (!instance_attr->show)
604 return instance_attr->show(instance_obj, instance_attr, buf);
608 * instance_attr_store - store function for an instance object
609 * @kobj: pointer to kobject
610 * @attr: pointer to attribute struct
612 * @len: length of buffer
614 static ssize_t instance_attr_store(struct kobject *kobj,
615 struct attribute *attr,
619 struct most_inst_attribute *instance_attr;
620 struct most_inst_obj *instance_obj;
622 instance_attr = to_instance_attr(attr);
623 instance_obj = to_inst_obj(kobj);
625 if (!instance_attr->store)
628 return instance_attr->store(instance_obj, instance_attr, buf, len);
631 static const struct sysfs_ops most_inst_sysfs_ops = {
632 .show = instance_attr_show,
633 .store = instance_attr_store,
637 * most_inst_release - release function for instance object
638 * @kobj: pointer to instance's kobject
640 * This frees the allocated memory for the instance object
642 static void most_inst_release(struct kobject *kobj)
644 struct most_inst_obj *inst = to_inst_obj(kobj);
649 static ssize_t show_description(struct most_inst_obj *instance_obj,
650 struct most_inst_attribute *attr,
653 return snprintf(buf, PAGE_SIZE, "%s\n",
654 instance_obj->iface->description);
657 static ssize_t show_interface(struct most_inst_obj *instance_obj,
658 struct most_inst_attribute *attr,
661 switch (instance_obj->iface->interface) {
663 return snprintf(buf, PAGE_SIZE, "loopback\n");
665 return snprintf(buf, PAGE_SIZE, "i2c\n");
667 return snprintf(buf, PAGE_SIZE, "i2s\n");
669 return snprintf(buf, PAGE_SIZE, "tsi\n");
671 return snprintf(buf, PAGE_SIZE, "hbi\n");
672 case ITYPE_MEDIALB_DIM:
673 return snprintf(buf, PAGE_SIZE, "mlb_dim\n");
674 case ITYPE_MEDIALB_DIM2:
675 return snprintf(buf, PAGE_SIZE, "mlb_dim2\n");
677 return snprintf(buf, PAGE_SIZE, "usb\n");
679 return snprintf(buf, PAGE_SIZE, "pcie\n");
681 return snprintf(buf, PAGE_SIZE, "unknown\n");
684 #define create_inst_attribute(value) \
685 static MOST_INST_ATTR(value, S_IRUGO, show_##value, NULL)
687 create_inst_attribute(description);
688 create_inst_attribute(interface);
690 static struct attribute *most_inst_def_attrs[] = {
691 &most_inst_attr_description.attr,
692 &most_inst_attr_interface.attr,
696 static struct kobj_type most_inst_ktype = {
697 .sysfs_ops = &most_inst_sysfs_ops,
698 .release = most_inst_release,
699 .default_attrs = most_inst_def_attrs,
702 static struct kset *most_inst_kset;
705 * create_most_inst_obj - creates an instance object
706 * @name: name of the object to be created
708 * This allocates memory for an instance structure, assigns the proper kset
709 * and registers it with sysfs.
711 * Returns a pointer to the instance object or NULL when something went wrong.
713 static struct most_inst_obj *create_most_inst_obj(const char *name)
715 struct most_inst_obj *inst;
718 inst = kzalloc(sizeof(*inst), GFP_KERNEL);
721 inst->kobj.kset = most_inst_kset;
722 retval = kobject_init_and_add(&inst->kobj, &most_inst_ktype, NULL,
725 kobject_put(&inst->kobj);
728 kobject_uevent(&inst->kobj, KOBJ_ADD);
733 * destroy_most_inst_obj - MOST instance release function
734 * @inst: pointer to the instance object
736 * This decrements the reference counter of the instance object.
737 * If the reference count turns zero, its release function is called
739 static void destroy_most_inst_obj(struct most_inst_obj *inst)
741 struct most_c_obj *c, *tmp;
743 list_for_each_entry_safe(c, tmp, &inst->channel_list, list) {
745 flush_channel_fifos(c);
746 kobject_put(&c->kobj);
748 kobject_put(&inst->kobj);
754 struct most_aim_obj {
756 struct list_head list;
757 struct most_aim *driver;
758 char add_link[STRING_SIZE];
759 char remove_link[STRING_SIZE];
762 #define to_aim_obj(d) container_of(d, struct most_aim_obj, kobj)
764 static struct list_head aim_list;
767 * struct most_aim_attribute - to access the attributes of AIM object
768 * @attr: attributes of an AIM
769 * @show: pointer to the show function
770 * @store: pointer to the store function
772 struct most_aim_attribute {
773 struct attribute attr;
774 ssize_t (*show)(struct most_aim_obj *d,
775 struct most_aim_attribute *attr,
777 ssize_t (*store)(struct most_aim_obj *d,
778 struct most_aim_attribute *attr,
783 #define to_aim_attr(a) container_of(a, struct most_aim_attribute, attr)
786 * aim_attr_show - show function of an AIM object
787 * @kobj: pointer to kobject
788 * @attr: pointer to attribute struct
791 static ssize_t aim_attr_show(struct kobject *kobj,
792 struct attribute *attr,
795 struct most_aim_attribute *aim_attr;
796 struct most_aim_obj *aim_obj;
798 aim_attr = to_aim_attr(attr);
799 aim_obj = to_aim_obj(kobj);
804 return aim_attr->show(aim_obj, aim_attr, buf);
808 * aim_attr_store - store function of an AIM object
809 * @kobj: pointer to kobject
810 * @attr: pointer to attribute struct
812 * @len: length of buffer
814 static ssize_t aim_attr_store(struct kobject *kobj,
815 struct attribute *attr,
819 struct most_aim_attribute *aim_attr;
820 struct most_aim_obj *aim_obj;
822 aim_attr = to_aim_attr(attr);
823 aim_obj = to_aim_obj(kobj);
825 if (!aim_attr->store)
827 return aim_attr->store(aim_obj, aim_attr, buf, len);
830 static const struct sysfs_ops most_aim_sysfs_ops = {
831 .show = aim_attr_show,
832 .store = aim_attr_store,
836 * most_aim_release - AIM release function
837 * @kobj: pointer to AIM's kobject
839 static void most_aim_release(struct kobject *kobj)
841 struct most_aim_obj *aim_obj = to_aim_obj(kobj);
846 static ssize_t show_add_link(struct most_aim_obj *aim_obj,
847 struct most_aim_attribute *attr,
850 return snprintf(buf, PAGE_SIZE, "%s\n", aim_obj->add_link);
854 * split_string - parses and changes string in the buffer buf and
855 * splits it into two mandatory and one optional substrings.
857 * @buf: complete string from attribute 'add_channel'
858 * @a: address of pointer to 1st substring (=instance name)
859 * @b: address of pointer to 2nd substring (=channel name)
860 * @c: optional address of pointer to 3rd substring (=user defined name)
864 * Input: "mdev0:ch0@ep_81:my_channel\n" or
865 * "mdev0:ch0@ep_81:my_channel"
867 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c -> "my_channel"
869 * Input: "mdev0:ch0@ep_81\n"
870 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c -> ""
872 * Input: "mdev0:ch0@ep_81"
873 * Output: *a -> "mdev0", *b -> "ch0@ep_81", *c == NULL
875 static int split_string(char *buf, char **a, char **b, char **c)
877 *a = strsep(&buf, ":");
881 *b = strsep(&buf, ":\n");
886 *c = strsep(&buf, ":\n");
892 * get_channel_by_name - get pointer to channel object
893 * @mdev: name of the device instance
894 * @mdev_ch: name of the respective channel
896 * This retrieves the pointer to a channel object.
899 most_c_obj *get_channel_by_name(char *mdev, char *mdev_ch)
901 struct most_c_obj *c, *tmp;
902 struct most_inst_obj *i, *i_tmp;
905 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
906 if (!strcmp(kobject_name(&i->kobj), mdev)) {
911 if (unlikely(!found))
912 return ERR_PTR(-EIO);
914 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
915 if (!strcmp(kobject_name(&c->kobj), mdev_ch)) {
920 if (unlikely(found < 2))
921 return ERR_PTR(-EIO);
926 * store_add_link - store() function for add_link attribute
927 * @aim_obj: pointer to AIM object
928 * @attr: its attributes
930 * @len: buffer length
932 * This parses the string given by buf and splits it into
933 * three substrings. Note: third substring is optional. In case a cdev
934 * AIM is loaded the optional 3rd substring will make up the name of
935 * device node in the /dev directory. If omitted, the device node will
936 * inherit the channel's name within sysfs.
938 * Searches for a pair of device and channel and probes the AIM
941 * (1) echo -n -e "mdev0:ch0@ep_81:my_rxchannel\n" >add_link
942 * (2) echo -n -e "mdev0:ch0@ep_81\n" >add_link
944 * (1) would create the device node /dev/my_rxchannel
945 * (2) would create the device node /dev/mdev0-ch0@ep_81
947 static ssize_t store_add_link(struct most_aim_obj *aim_obj,
948 struct most_aim_attribute *attr,
952 struct most_c_obj *c;
953 struct most_aim **aim_ptr;
954 char buffer[STRING_SIZE];
958 char devnod_buf[STRING_SIZE];
960 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
962 strlcpy(buffer, buf, max_len);
963 strlcpy(aim_obj->add_link, buf, max_len);
965 ret = split_string(buffer, &mdev, &mdev_ch, &mdev_devnod);
969 if (!mdev_devnod || *mdev_devnod == 0) {
970 snprintf(devnod_buf, sizeof(devnod_buf), "%s-%s", mdev,
972 mdev_devnod = devnod_buf;
975 c = get_channel_by_name(mdev, mdev_ch);
980 aim_ptr = &c->aim0.ptr;
981 else if (!c->aim1.ptr)
982 aim_ptr = &c->aim1.ptr;
986 *aim_ptr = aim_obj->driver;
987 ret = aim_obj->driver->probe_channel(c->iface, c->channel_id,
988 &c->cfg, &c->kobj, mdev_devnod);
997 static struct most_aim_attribute most_aim_attr_add_link =
998 __ATTR(add_link, S_IRUGO | S_IWUSR, show_add_link, store_add_link);
1000 static ssize_t show_remove_link(struct most_aim_obj *aim_obj,
1001 struct most_aim_attribute *attr,
1004 return snprintf(buf, PAGE_SIZE, "%s\n", aim_obj->remove_link);
1008 * store_remove_link - store function for remove_link attribute
1009 * @aim_obj: pointer to AIM object
1010 * @attr: its attributes
1012 * @len: buffer length
1015 * echo -n -e "mdev0:ch0@ep_81\n" >remove_link
1017 static ssize_t store_remove_link(struct most_aim_obj *aim_obj,
1018 struct most_aim_attribute *attr,
1022 struct most_c_obj *c;
1023 char buffer[STRING_SIZE];
1027 size_t max_len = min_t(size_t, len + 1, STRING_SIZE);
1029 strlcpy(buffer, buf, max_len);
1030 strlcpy(aim_obj->remove_link, buf, max_len);
1031 ret = split_string(buffer, &mdev, &mdev_ch, NULL);
1035 c = get_channel_by_name(mdev, mdev_ch);
1039 if (aim_obj->driver->disconnect_channel(c->iface, c->channel_id))
1041 if (c->aim0.ptr == aim_obj->driver)
1043 if (c->aim1.ptr == aim_obj->driver)
1048 static struct most_aim_attribute most_aim_attr_remove_link =
1049 __ATTR(remove_link, S_IRUGO | S_IWUSR, show_remove_link,
1052 static struct attribute *most_aim_def_attrs[] = {
1053 &most_aim_attr_add_link.attr,
1054 &most_aim_attr_remove_link.attr,
1058 static struct kobj_type most_aim_ktype = {
1059 .sysfs_ops = &most_aim_sysfs_ops,
1060 .release = most_aim_release,
1061 .default_attrs = most_aim_def_attrs,
1064 static struct kset *most_aim_kset;
1067 * create_most_aim_obj - creates an AIM object
1068 * @name: name of the AIM
1070 * This creates an AIM object assigns the proper kset and registers
1072 * Returns a pointer to the object or NULL if something went wrong.
1074 static struct most_aim_obj *create_most_aim_obj(const char *name)
1076 struct most_aim_obj *most_aim;
1079 most_aim = kzalloc(sizeof(*most_aim), GFP_KERNEL);
1082 most_aim->kobj.kset = most_aim_kset;
1083 retval = kobject_init_and_add(&most_aim->kobj, &most_aim_ktype,
1086 kobject_put(&most_aim->kobj);
1089 kobject_uevent(&most_aim->kobj, KOBJ_ADD);
1094 * destroy_most_aim_obj - AIM release function
1095 * @p: pointer to AIM object
1097 * This decrements the reference counter of the AIM object. If the
1098 * reference count turns zero, its release function will be called.
1100 static void destroy_most_aim_obj(struct most_aim_obj *p)
1102 kobject_put(&p->kobj);
1110 * Instantiation of the MOST bus
1112 static struct bus_type most_bus = {
1117 * Instantiation of the core driver
1119 static struct device_driver mostcore = {
1124 static inline void trash_mbo(struct mbo *mbo)
1126 unsigned long flags;
1127 struct most_c_obj *c = mbo->context;
1129 spin_lock_irqsave(&c->fifo_lock, flags);
1130 list_add(&mbo->list, &c->trash_fifo);
1131 spin_unlock_irqrestore(&c->fifo_lock, flags);
1134 static struct mbo *get_hdm_mbo(struct most_c_obj *c)
1136 unsigned long flags;
1139 spin_lock_irqsave(&c->fifo_lock, flags);
1140 if (c->enqueue_halt || list_empty(&c->halt_fifo))
1143 mbo = list_pop_mbo(&c->halt_fifo);
1144 spin_unlock_irqrestore(&c->fifo_lock, flags);
1148 static void nq_hdm_mbo(struct mbo *mbo)
1150 unsigned long flags;
1151 struct most_c_obj *c = mbo->context;
1153 spin_lock_irqsave(&c->fifo_lock, flags);
1154 list_add_tail(&mbo->list, &c->halt_fifo);
1155 spin_unlock_irqrestore(&c->fifo_lock, flags);
1156 wake_up_interruptible(&c->hdm_fifo_wq);
1159 static int hdm_enqueue_thread(void *data)
1161 struct most_c_obj *c = data;
1163 typeof(c->iface->enqueue) enqueue = c->iface->enqueue;
1165 while (likely(!kthread_should_stop())) {
1166 wait_event_interruptible(c->hdm_fifo_wq,
1167 (mbo = get_hdm_mbo(c)) ||
1168 kthread_should_stop());
1173 if (c->cfg.direction == MOST_CH_RX)
1174 mbo->buffer_length = c->cfg.buffer_size;
1176 if (unlikely(enqueue(mbo->ifp, mbo->hdm_channel_id, mbo))) {
1177 pr_err("hdm enqueue failed\n");
1179 c->hdm_enqueue_task = NULL;
1187 static int run_enqueue_thread(struct most_c_obj *c, int channel_id)
1189 struct task_struct *task =
1190 kthread_run(hdm_enqueue_thread, c, "hdm_fifo_%d",
1194 return PTR_ERR(task);
1196 c->hdm_enqueue_task = task;
1201 * arm_mbo - recycle MBO for further usage
1202 * @mbo: buffer object
1204 * This puts an MBO back to the list to have it ready for up coming
1207 * In case the MBO belongs to a channel that recently has been
1208 * poisoned, the MBO is scheduled to be trashed.
1209 * Calls the completion handler of an attached AIM.
1211 static void arm_mbo(struct mbo *mbo)
1213 unsigned long flags;
1214 struct most_c_obj *c;
1216 BUG_ON((!mbo) || (!mbo->context));
1219 if (c->is_poisoned) {
1224 spin_lock_irqsave(&c->fifo_lock, flags);
1225 ++*mbo->num_buffers_ptr;
1226 list_add_tail(&mbo->list, &c->fifo);
1227 spin_unlock_irqrestore(&c->fifo_lock, flags);
1229 if (c->aim0.refs && c->aim0.ptr->tx_completion)
1230 c->aim0.ptr->tx_completion(c->iface, c->channel_id);
1232 if (c->aim1.refs && c->aim1.ptr->tx_completion)
1233 c->aim1.ptr->tx_completion(c->iface, c->channel_id);
1237 * arm_mbo_chain - helper function that arms an MBO chain for the HDM
1238 * @c: pointer to interface channel
1239 * @dir: direction of the channel
1240 * @compl: pointer to completion function
1242 * This allocates buffer objects including the containing DMA coherent
1243 * buffer and puts them in the fifo.
1244 * Buffers of Rx channels are put in the kthread fifo, hence immediately
1245 * submitted to the HDM.
1247 * Returns the number of allocated and enqueued MBOs.
1249 static int arm_mbo_chain(struct most_c_obj *c, int dir,
1250 void (*compl)(struct mbo *))
1255 u32 coherent_buf_size = c->cfg.buffer_size + c->cfg.extra_len;
1257 atomic_set(&c->mbo_nq_level, 0);
1259 for (i = 0; i < c->cfg.num_buffers; i++) {
1260 mbo = kzalloc(sizeof(*mbo), GFP_KERNEL);
1266 mbo->ifp = c->iface;
1267 mbo->hdm_channel_id = c->channel_id;
1268 mbo->virt_address = dma_alloc_coherent(NULL,
1272 if (!mbo->virt_address) {
1273 pr_info("WARN: No DMA coherent buffer.\n");
1277 mbo->complete = compl;
1278 mbo->num_buffers_ptr = &dummy_num_buffers;
1279 if (dir == MOST_CH_RX) {
1281 atomic_inc(&c->mbo_nq_level);
1295 * most_submit_mbo - submits an MBO to fifo
1296 * @mbo: pointer to the MBO
1299 int most_submit_mbo(struct mbo *mbo)
1301 if (unlikely((!mbo) || (!mbo->context))) {
1302 pr_err("Bad MBO or missing channel reference\n");
1309 EXPORT_SYMBOL_GPL(most_submit_mbo);
1312 * most_write_completion - write completion handler
1313 * @mbo: pointer to MBO
1315 * This recycles the MBO for further usage. In case the channel has been
1316 * poisoned, the MBO is scheduled to be trashed.
1318 static void most_write_completion(struct mbo *mbo)
1320 struct most_c_obj *c;
1322 BUG_ON((!mbo) || (!mbo->context));
1325 if (mbo->status == MBO_E_INVAL)
1326 pr_info("WARN: Tx MBO status: invalid\n");
1327 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE)))
1334 * get_channel_by_iface - get pointer to channel object
1335 * @iface: pointer to interface instance
1338 * This retrieves a pointer to a channel of the given interface and channel ID.
1341 most_c_obj *get_channel_by_iface(struct most_interface *iface, int id)
1343 struct most_inst_obj *i;
1345 if (unlikely(!iface)) {
1346 pr_err("Bad interface\n");
1349 if (unlikely((id < 0) || (id >= iface->num_channels))) {
1350 pr_err("Channel index (%d) out of range\n", id);
1355 pr_err("interface is not registered\n");
1358 return i->channel[id];
1361 int channel_has_mbo(struct most_interface *iface, int id, struct most_aim *aim)
1363 struct most_c_obj *c = get_channel_by_iface(iface, id);
1364 unsigned long flags;
1370 if (c->aim0.refs && c->aim1.refs &&
1371 ((aim == c->aim0.ptr && c->aim0.num_buffers <= 0) ||
1372 (aim == c->aim1.ptr && c->aim1.num_buffers <= 0)))
1375 spin_lock_irqsave(&c->fifo_lock, flags);
1376 empty = list_empty(&c->fifo);
1377 spin_unlock_irqrestore(&c->fifo_lock, flags);
1380 EXPORT_SYMBOL_GPL(channel_has_mbo);
1383 * most_get_mbo - get pointer to an MBO of pool
1384 * @iface: pointer to interface instance
1387 * This attempts to get a free buffer out of the channel fifo.
1388 * Returns a pointer to MBO on success or NULL otherwise.
1390 struct mbo *most_get_mbo(struct most_interface *iface, int id,
1391 struct most_aim *aim)
1394 struct most_c_obj *c;
1395 unsigned long flags;
1396 int *num_buffers_ptr;
1398 c = get_channel_by_iface(iface, id);
1402 if (c->aim0.refs && c->aim1.refs &&
1403 ((aim == c->aim0.ptr && c->aim0.num_buffers <= 0) ||
1404 (aim == c->aim1.ptr && c->aim1.num_buffers <= 0)))
1407 if (aim == c->aim0.ptr)
1408 num_buffers_ptr = &c->aim0.num_buffers;
1409 else if (aim == c->aim1.ptr)
1410 num_buffers_ptr = &c->aim1.num_buffers;
1412 num_buffers_ptr = &dummy_num_buffers;
1414 spin_lock_irqsave(&c->fifo_lock, flags);
1415 if (list_empty(&c->fifo)) {
1416 spin_unlock_irqrestore(&c->fifo_lock, flags);
1419 mbo = list_pop_mbo(&c->fifo);
1421 spin_unlock_irqrestore(&c->fifo_lock, flags);
1423 mbo->num_buffers_ptr = num_buffers_ptr;
1424 mbo->buffer_length = c->cfg.buffer_size;
1427 EXPORT_SYMBOL_GPL(most_get_mbo);
1430 * most_put_mbo - return buffer to pool
1431 * @mbo: buffer object
1433 void most_put_mbo(struct mbo *mbo)
1435 struct most_c_obj *c = mbo->context;
1437 if (c->cfg.direction == MOST_CH_TX) {
1442 atomic_inc(&c->mbo_nq_level);
1444 EXPORT_SYMBOL_GPL(most_put_mbo);
1447 * most_read_completion - read completion handler
1448 * @mbo: pointer to MBO
1450 * This function is called by the HDM when data has been received from the
1451 * hardware and copied to the buffer of the MBO.
1453 * In case the channel has been poisoned it puts the buffer in the trash queue.
1454 * Otherwise, it passes the buffer to an AIM for further processing.
1456 static void most_read_completion(struct mbo *mbo)
1458 struct most_c_obj *c = mbo->context;
1460 if (unlikely(c->is_poisoned || (mbo->status == MBO_E_CLOSE))) {
1465 if (mbo->status == MBO_E_INVAL) {
1467 atomic_inc(&c->mbo_nq_level);
1471 if (atomic_sub_and_test(1, &c->mbo_nq_level)) {
1472 pr_info("WARN: rx device out of buffers\n");
1476 if (c->aim0.refs && c->aim0.ptr->rx_completion &&
1477 c->aim0.ptr->rx_completion(mbo) == 0)
1480 if (c->aim1.refs && c->aim1.ptr->rx_completion &&
1481 c->aim1.ptr->rx_completion(mbo) == 0)
1488 * most_start_channel - prepares a channel for communication
1489 * @iface: pointer to interface instance
1492 * This prepares the channel for usage. Cross-checks whether the
1493 * channel's been properly configured.
1495 * Returns 0 on success or error code otherwise.
1497 int most_start_channel(struct most_interface *iface, int id,
1498 struct most_aim *aim)
1502 struct most_c_obj *c = get_channel_by_iface(iface, id);
1507 mutex_lock(&c->start_mutex);
1508 if (c->aim0.refs + c->aim1.refs > 0)
1509 goto out; /* already started by other aim */
1511 if (!try_module_get(iface->mod)) {
1512 pr_info("failed to acquire HDM lock\n");
1513 mutex_unlock(&c->start_mutex);
1517 c->cfg.extra_len = 0;
1518 if (c->iface->configure(c->iface, c->channel_id, &c->cfg)) {
1519 pr_info("channel configuration failed. Go check settings...\n");
1524 init_waitqueue_head(&c->hdm_fifo_wq);
1526 if (c->cfg.direction == MOST_CH_RX)
1527 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1528 most_read_completion);
1530 num_buffer = arm_mbo_chain(c, c->cfg.direction,
1531 most_write_completion);
1532 if (unlikely(!num_buffer)) {
1533 pr_info("failed to allocate memory\n");
1538 ret = run_enqueue_thread(c, id);
1543 c->aim0.num_buffers = c->cfg.num_buffers / 2;
1544 c->aim1.num_buffers = c->cfg.num_buffers - c->aim0.num_buffers;
1545 atomic_set(&c->mbo_ref, num_buffer);
1548 if (aim == c->aim0.ptr)
1550 if (aim == c->aim1.ptr)
1552 mutex_unlock(&c->start_mutex);
1556 module_put(iface->mod);
1557 mutex_unlock(&c->start_mutex);
1560 EXPORT_SYMBOL_GPL(most_start_channel);
1563 * most_stop_channel - stops a running channel
1564 * @iface: pointer to interface instance
1567 int most_stop_channel(struct most_interface *iface, int id,
1568 struct most_aim *aim)
1570 struct most_c_obj *c;
1572 if (unlikely((!iface) || (id >= iface->num_channels) || (id < 0))) {
1573 pr_err("Bad interface or index out of range\n");
1576 c = get_channel_by_iface(iface, id);
1580 mutex_lock(&c->start_mutex);
1581 if (c->aim0.refs + c->aim1.refs >= 2)
1584 if (c->hdm_enqueue_task)
1585 kthread_stop(c->hdm_enqueue_task);
1586 c->hdm_enqueue_task = NULL;
1589 module_put(iface->mod);
1591 c->is_poisoned = true;
1592 if (c->iface->poison_channel(c->iface, c->channel_id)) {
1593 pr_err("Cannot stop channel %d of mdev %s\n", c->channel_id,
1594 c->iface->description);
1595 mutex_unlock(&c->start_mutex);
1598 flush_trash_fifo(c);
1599 flush_channel_fifos(c);
1601 #ifdef CMPL_INTERRUPTIBLE
1602 if (wait_for_completion_interruptible(&c->cleanup)) {
1603 pr_info("Interrupted while clean up ch %d\n", c->channel_id);
1604 mutex_unlock(&c->start_mutex);
1608 wait_for_completion(&c->cleanup);
1610 c->is_poisoned = false;
1613 if (aim == c->aim0.ptr)
1615 if (aim == c->aim1.ptr)
1617 mutex_unlock(&c->start_mutex);
1620 EXPORT_SYMBOL_GPL(most_stop_channel);
1623 * most_register_aim - registers an AIM (driver) with the core
1624 * @aim: instance of AIM to be registered
1626 int most_register_aim(struct most_aim *aim)
1628 struct most_aim_obj *aim_obj;
1631 pr_err("Bad driver\n");
1634 aim_obj = create_most_aim_obj(aim->name);
1636 pr_info("failed to alloc driver object\n");
1639 aim_obj->driver = aim;
1640 aim->context = aim_obj;
1641 pr_info("registered new application interfacing module %s\n",
1643 list_add_tail(&aim_obj->list, &aim_list);
1646 EXPORT_SYMBOL_GPL(most_register_aim);
1649 * most_deregister_aim - deregisters an AIM (driver) with the core
1650 * @aim: AIM to be removed
1652 int most_deregister_aim(struct most_aim *aim)
1654 struct most_aim_obj *aim_obj;
1655 struct most_c_obj *c, *tmp;
1656 struct most_inst_obj *i, *i_tmp;
1659 pr_err("Bad driver\n");
1663 aim_obj = aim->context;
1665 pr_info("driver not registered.\n");
1668 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1669 list_for_each_entry_safe(c, tmp, &i->channel_list, list) {
1670 if (c->aim0.ptr == aim || c->aim1.ptr == aim)
1671 aim->disconnect_channel(
1672 c->iface, c->channel_id);
1673 if (c->aim0.ptr == aim)
1675 if (c->aim1.ptr == aim)
1679 list_del(&aim_obj->list);
1680 destroy_most_aim_obj(aim_obj);
1681 pr_info("deregistering application interfacing module %s\n", aim->name);
1684 EXPORT_SYMBOL_GPL(most_deregister_aim);
1687 * most_register_interface - registers an interface with core
1688 * @iface: pointer to the instance of the interface description.
1690 * Allocates and initializes a new interface instance and all of its channels.
1691 * Returns a pointer to kobject or an error pointer.
1693 struct kobject *most_register_interface(struct most_interface *iface)
1697 char name[STRING_SIZE];
1698 char channel_name[STRING_SIZE];
1699 struct most_c_obj *c;
1700 struct most_inst_obj *inst;
1702 if (!iface || !iface->enqueue || !iface->configure ||
1703 !iface->poison_channel || (iface->num_channels > MAX_CHANNELS)) {
1704 pr_err("Bad interface or channel overflow\n");
1705 return ERR_PTR(-EINVAL);
1708 id = ida_simple_get(&mdev_id, 0, 0, GFP_KERNEL);
1710 pr_info("Failed to alloc mdev ID\n");
1713 snprintf(name, STRING_SIZE, "mdev%d", id);
1715 inst = create_most_inst_obj(name);
1717 pr_info("Failed to allocate interface instance\n");
1718 ida_simple_remove(&mdev_id, id);
1719 return ERR_PTR(-ENOMEM);
1723 INIT_LIST_HEAD(&inst->channel_list);
1724 inst->iface = iface;
1726 list_add_tail(&inst->list, &instance_list);
1728 for (i = 0; i < iface->num_channels; i++) {
1729 const char *name_suffix = iface->channel_vector[i].name_suffix;
1732 snprintf(channel_name, STRING_SIZE, "ch%d", i);
1733 else if (name_suffix[0] == '@')
1734 snprintf(channel_name, STRING_SIZE, "ch%d%s", i,
1737 snprintf(channel_name, STRING_SIZE, "%s", name_suffix);
1739 /* this increments the reference count of this instance */
1740 c = create_most_c_obj(channel_name, &inst->kobj);
1743 inst->channel[i] = c;
1748 c->keep_mbo = false;
1749 c->enqueue_halt = false;
1750 c->is_poisoned = false;
1751 c->cfg.direction = 0;
1752 c->cfg.data_type = 0;
1753 c->cfg.num_buffers = 0;
1754 c->cfg.buffer_size = 0;
1755 c->cfg.subbuffer_size = 0;
1756 c->cfg.packets_per_xact = 0;
1757 spin_lock_init(&c->fifo_lock);
1758 INIT_LIST_HEAD(&c->fifo);
1759 INIT_LIST_HEAD(&c->trash_fifo);
1760 INIT_LIST_HEAD(&c->halt_fifo);
1761 init_completion(&c->cleanup);
1762 atomic_set(&c->mbo_ref, 0);
1763 mutex_init(&c->start_mutex);
1764 list_add_tail(&c->list, &inst->channel_list);
1766 pr_info("registered new MOST device mdev%d (%s)\n",
1767 inst->dev_id, iface->description);
1771 pr_info("Failed allocate channel(s)\n");
1772 list_del(&inst->list);
1773 ida_simple_remove(&mdev_id, id);
1774 destroy_most_inst_obj(inst);
1775 return ERR_PTR(-ENOMEM);
1777 EXPORT_SYMBOL_GPL(most_register_interface);
1780 * most_deregister_interface - deregisters an interface with core
1781 * @iface: pointer to the interface instance description.
1783 * Before removing an interface instance from the list, all running
1784 * channels are stopped and poisoned.
1786 void most_deregister_interface(struct most_interface *iface)
1788 struct most_inst_obj *i = iface->priv;
1789 struct most_c_obj *c;
1792 pr_info("Bad Interface\n");
1795 pr_info("deregistering MOST device %s (%s)\n", i->kobj.name,
1796 iface->description);
1798 list_for_each_entry(c, &i->channel_list, list) {
1800 c->aim0.ptr->disconnect_channel(c->iface,
1803 c->aim1.ptr->disconnect_channel(c->iface,
1809 ida_simple_remove(&mdev_id, i->dev_id);
1811 destroy_most_inst_obj(i);
1813 EXPORT_SYMBOL_GPL(most_deregister_interface);
1816 * most_stop_enqueue - prevents core from enqueueing MBOs
1817 * @iface: pointer to interface
1820 * This is called by an HDM that _cannot_ attend to its duties and
1821 * is imminent to get run over by the core. The core is not going to
1822 * enqueue any further packets unless the flagging HDM calls
1823 * most_resume enqueue().
1825 void most_stop_enqueue(struct most_interface *iface, int id)
1827 struct most_c_obj *c = get_channel_by_iface(iface, id);
1830 c->enqueue_halt = true;
1832 EXPORT_SYMBOL_GPL(most_stop_enqueue);
1835 * most_resume_enqueue - allow core to enqueue MBOs again
1836 * @iface: pointer to interface
1839 * This clears the enqueue halt flag and enqueues all MBOs currently
1840 * sitting in the wait fifo.
1842 void most_resume_enqueue(struct most_interface *iface, int id)
1844 struct most_c_obj *c = get_channel_by_iface(iface, id);
1848 c->enqueue_halt = false;
1850 wake_up_interruptible(&c->hdm_fifo_wq);
1852 EXPORT_SYMBOL_GPL(most_resume_enqueue);
1854 static int __init most_init(void)
1858 pr_info("init()\n");
1859 INIT_LIST_HEAD(&instance_list);
1860 INIT_LIST_HEAD(&aim_list);
1863 err = bus_register(&most_bus);
1865 pr_info("Cannot register most bus\n");
1869 most_class = class_create(THIS_MODULE, "most");
1870 if (IS_ERR(most_class)) {
1871 pr_info("No udev support.\n");
1872 err = PTR_ERR(most_class);
1876 err = driver_register(&mostcore);
1878 pr_info("Cannot register core driver\n");
1883 device_create(most_class, NULL, 0, NULL, "mostcore");
1884 if (IS_ERR(class_glue_dir)) {
1885 err = PTR_ERR(class_glue_dir);
1890 kset_create_and_add("aims", NULL, &class_glue_dir->kobj);
1891 if (!most_aim_kset) {
1893 goto exit_class_container;
1897 kset_create_and_add("devices", NULL, &class_glue_dir->kobj);
1898 if (!most_inst_kset) {
1900 goto exit_driver_kset;
1906 kset_unregister(most_aim_kset);
1907 exit_class_container:
1908 device_destroy(most_class, 0);
1910 driver_unregister(&mostcore);
1912 class_destroy(most_class);
1914 bus_unregister(&most_bus);
1918 static void __exit most_exit(void)
1920 struct most_inst_obj *i, *i_tmp;
1921 struct most_aim_obj *d, *d_tmp;
1923 pr_info("exit core module\n");
1924 list_for_each_entry_safe(d, d_tmp, &aim_list, list) {
1925 destroy_most_aim_obj(d);
1928 list_for_each_entry_safe(i, i_tmp, &instance_list, list) {
1930 destroy_most_inst_obj(i);
1932 kset_unregister(most_inst_kset);
1933 kset_unregister(most_aim_kset);
1934 device_destroy(most_class, 0);
1935 driver_unregister(&mostcore);
1936 class_destroy(most_class);
1937 bus_unregister(&most_bus);
1938 ida_destroy(&mdev_id);
1941 module_init(most_init);
1942 module_exit(most_exit);
1943 MODULE_LICENSE("GPL");
1944 MODULE_AUTHOR("Christian Gromm <christian.gromm@microchip.com>");
1945 MODULE_DESCRIPTION("Core module of stacked MOST Linux driver");