xref: /linux/arch/mips/kernel/rtlx.c (revision 552c69b36ebd966186573b9c7a286b390935cce1)
1e01402b1SRalf Baechle /*
25792bf64SSteven J. Hill  * This file is subject to the terms and conditions of the GNU General Public
35792bf64SSteven J. Hill  * License.  See the file "COPYING" in the main directory of this archive
4e01402b1SRalf Baechle  * for more details.
5e01402b1SRalf Baechle  *
65792bf64SSteven J. Hill  * Copyright (C) 2005 MIPS Technologies, Inc.  All rights reserved.
75792bf64SSteven J. Hill  * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org)
85792bf64SSteven J. Hill  * Copyright (C) 2013 Imagination Technologies Ltd.
9e01402b1SRalf Baechle  */
10e01402b1SRalf Baechle #include <linux/kernel.h>
11e01402b1SRalf Baechle #include <linux/fs.h>
122600990eSRalf Baechle #include <linux/syscalls.h>
132600990eSRalf Baechle #include <linux/moduleloader.h>
145792bf64SSteven J. Hill #include <linux/atomic.h>
15174cd4b1SIngo Molnar #include <linux/sched/signal.h>
16174cd4b1SIngo Molnar 
17e01402b1SRalf Baechle #include <asm/mipsmtregs.h>
18bb3d7c7fSRalf Baechle #include <asm/mips_mt.h>
19e01402b1SRalf Baechle #include <asm/processor.h>
20e01402b1SRalf Baechle #include <asm/rtlx.h>
21406b5ee2SYoichi Yuasa #include <asm/setup.h>
225792bf64SSteven J. Hill #include <asm/vpe.h>
23e01402b1SRalf Baechle 
24982f6ffeSRalf Baechle static int sp_stopping;
252c973ef0SDeng-Cheng Zhu struct rtlx_info *rtlx;
262c973ef0SDeng-Cheng Zhu struct chan_waitqueues channel_wqs[RTLX_CHANNELS];
272c973ef0SDeng-Cheng Zhu struct vpe_notifications rtlx_notify;
282c973ef0SDeng-Cheng Zhu void (*aprp_hook)(void) = NULL;
292c973ef0SDeng-Cheng Zhu EXPORT_SYMBOL(aprp_hook);
30e01402b1SRalf Baechle 
dump_rtlx(void)31f5dbeaf5SDavid Rientjes static void __used dump_rtlx(void)
32e01402b1SRalf Baechle {
33e01402b1SRalf Baechle 	int i;
34e01402b1SRalf Baechle 
355792bf64SSteven J. Hill 	pr_info("id 0x%lx state %d\n", rtlx->id, rtlx->state);
362600990eSRalf Baechle 
372600990eSRalf Baechle 	for (i = 0; i < RTLX_CHANNELS; i++) {
382600990eSRalf Baechle 		struct rtlx_channel *chan = &rtlx->channel[i];
392600990eSRalf Baechle 
405792bf64SSteven J. Hill 		pr_info(" rt_state %d lx_state %d buffer_size %d\n",
412600990eSRalf Baechle 			chan->rt_state, chan->lx_state, chan->buffer_size);
422600990eSRalf Baechle 
435792bf64SSteven J. Hill 		pr_info(" rt_read %d rt_write %d\n",
442600990eSRalf Baechle 			chan->rt_read, chan->rt_write);
452600990eSRalf Baechle 
465792bf64SSteven J. Hill 		pr_info(" lx_read %d lx_write %d\n",
472600990eSRalf Baechle 			chan->lx_read, chan->lx_write);
482600990eSRalf Baechle 
495792bf64SSteven J. Hill 		pr_info(" rt_buffer <%s>\n", chan->rt_buffer);
505792bf64SSteven J. Hill 		pr_info(" lx_buffer <%s>\n", chan->lx_buffer);
512600990eSRalf Baechle 	}
522600990eSRalf Baechle }
532600990eSRalf Baechle 
542600990eSRalf Baechle /* call when we have the address of the shared structure from the SP side. */
rtlx_init(struct rtlx_info * rtlxi)552600990eSRalf Baechle static int rtlx_init(struct rtlx_info *rtlxi)
562600990eSRalf Baechle {
57e01402b1SRalf Baechle 	if (rtlxi->id != RTLX_ID) {
585792bf64SSteven J. Hill 		pr_err("no valid RTLX id at 0x%p 0x%lx\n", rtlxi, rtlxi->id);
59afc4841dSRalf Baechle 		return -ENOEXEC;
60e01402b1SRalf Baechle 	}
61e01402b1SRalf Baechle 
62e01402b1SRalf Baechle 	rtlx = rtlxi;
63afc4841dSRalf Baechle 
64afc4841dSRalf Baechle 	return 0;
65e01402b1SRalf Baechle }
66e01402b1SRalf Baechle 
672600990eSRalf Baechle /* notifications */
rtlx_starting(int vpe)682c973ef0SDeng-Cheng Zhu void rtlx_starting(int vpe)
69e01402b1SRalf Baechle {
702600990eSRalf Baechle 	int i;
712600990eSRalf Baechle 	sp_stopping = 0;
72e01402b1SRalf Baechle 
732600990eSRalf Baechle 	/* force a reload of rtlx */
742600990eSRalf Baechle 	rtlx = NULL;
752600990eSRalf Baechle 
762600990eSRalf Baechle 	/* wake up any sleeping rtlx_open's */
772600990eSRalf Baechle 	for (i = 0; i < RTLX_CHANNELS; i++)
782600990eSRalf Baechle 		wake_up_interruptible(&channel_wqs[i].lx_queue);
792600990eSRalf Baechle }
802600990eSRalf Baechle 
rtlx_stopping(int vpe)812c973ef0SDeng-Cheng Zhu void rtlx_stopping(int vpe)
822600990eSRalf Baechle {
832600990eSRalf Baechle 	int i;
842600990eSRalf Baechle 
852600990eSRalf Baechle 	sp_stopping = 1;
862600990eSRalf Baechle 	for (i = 0; i < RTLX_CHANNELS; i++)
872600990eSRalf Baechle 		wake_up_interruptible(&channel_wqs[i].lx_queue);
882600990eSRalf Baechle }
892600990eSRalf Baechle 
902600990eSRalf Baechle 
rtlx_open(int index,int can_sleep)912600990eSRalf Baechle int rtlx_open(int index, int can_sleep)
922600990eSRalf Baechle {
939e346820SRalf Baechle 	struct rtlx_info **p;
9467e2ccceSRalf Baechle 	struct rtlx_channel *chan;
95c4c4018bSRalf Baechle 	enum rtlx_state state;
9667e2ccceSRalf Baechle 	int ret = 0;
972600990eSRalf Baechle 
982600990eSRalf Baechle 	if (index >= RTLX_CHANNELS) {
993dc4bf31SMasanari Iida 		pr_debug("rtlx_open index out of range\n");
1002600990eSRalf Baechle 		return -ENOSYS;
1012600990eSRalf Baechle 	}
1022600990eSRalf Baechle 
103c4c4018bSRalf Baechle 	if (atomic_inc_return(&channel_wqs[index].in_open) > 1) {
1043dc4bf31SMasanari Iida 		pr_debug("rtlx_open channel %d already opened\n", index);
105c4c4018bSRalf Baechle 		ret = -EBUSY;
106c4c4018bSRalf Baechle 		goto out_fail;
1072600990eSRalf Baechle 	}
1082600990eSRalf Baechle 
109e01402b1SRalf Baechle 	if (rtlx == NULL) {
1105792bf64SSteven J. Hill 		p = vpe_get_shared(aprp_cpu_index());
1115792bf64SSteven J. Hill 		if (p == NULL) {
1122600990eSRalf Baechle 			if (can_sleep) {
11335a2af94SPeter Zijlstra 				ret = __wait_event_interruptible(
11435a2af94SPeter Zijlstra 					channel_wqs[index].lx_queue,
1155792bf64SSteven J. Hill 					(p = vpe_get_shared(aprp_cpu_index())));
11667e2ccceSRalf Baechle 				if (ret)
11767e2ccceSRalf Baechle 					goto out_fail;
1182600990eSRalf Baechle 			} else {
1195792bf64SSteven J. Hill 				pr_debug("No SP program loaded, and device opened with O_NONBLOCK\n");
12067e2ccceSRalf Baechle 				ret = -ENOSYS;
12167e2ccceSRalf Baechle 				goto out_fail;
1222600990eSRalf Baechle 			}
123e01402b1SRalf Baechle 		}
124e01402b1SRalf Baechle 
1259e346820SRalf Baechle 		smp_rmb();
126e01402b1SRalf Baechle 		if (*p == NULL) {
1272600990eSRalf Baechle 			if (can_sleep) {
1289e346820SRalf Baechle 				DEFINE_WAIT(wait);
1299e346820SRalf Baechle 
1309e346820SRalf Baechle 				for (;;) {
1311928cc84SKevin D. Kissell 					prepare_to_wait(
1321928cc84SKevin D. Kissell 						&channel_wqs[index].lx_queue,
1331928cc84SKevin D. Kissell 						&wait, TASK_INTERRUPTIBLE);
1349e346820SRalf Baechle 					smp_rmb();
1359e346820SRalf Baechle 					if (*p != NULL)
1369e346820SRalf Baechle 						break;
1379e346820SRalf Baechle 					if (!signal_pending(current)) {
1389e346820SRalf Baechle 						schedule();
1399e346820SRalf Baechle 						continue;
1409e346820SRalf Baechle 					}
1419e346820SRalf Baechle 					ret = -ERESTARTSYS;
14267e2ccceSRalf Baechle 					goto out_fail;
1439e346820SRalf Baechle 				}
1445792bf64SSteven J. Hill 				finish_wait(&channel_wqs[index].lx_queue,
1455792bf64SSteven J. Hill 					    &wait);
14667e2ccceSRalf Baechle 			} else {
1475792bf64SSteven J. Hill 				pr_err(" *vpe_get_shared is NULL. Has an SP program been loaded?\n");
14867e2ccceSRalf Baechle 				ret = -ENOSYS;
14967e2ccceSRalf Baechle 				goto out_fail;
1502600990eSRalf Baechle 			}
1512600990eSRalf Baechle 		}
1522600990eSRalf Baechle 
1532600990eSRalf Baechle 		if ((unsigned int)*p < KSEG0) {
1545792bf64SSteven J. Hill 			pr_warn("vpe_get_shared returned an invalid pointer maybe an error code %d\n",
1551928cc84SKevin D. Kissell 				(int)*p);
15667e2ccceSRalf Baechle 			ret = -ENOSYS;
15767e2ccceSRalf Baechle 			goto out_fail;
1582600990eSRalf Baechle 		}
1592600990eSRalf Baechle 
1605792bf64SSteven J. Hill 		ret = rtlx_init(*p);
1615792bf64SSteven J. Hill 		if (ret < 0)
162c4c4018bSRalf Baechle 			goto out_ret;
1632600990eSRalf Baechle 	}
1642600990eSRalf Baechle 
1652600990eSRalf Baechle 	chan = &rtlx->channel[index];
1662600990eSRalf Baechle 
167c4c4018bSRalf Baechle 	state = xchg(&chan->lx_state, RTLX_STATE_OPENED);
168c4c4018bSRalf Baechle 	if (state == RTLX_STATE_OPENED) {
169c4c4018bSRalf Baechle 		ret = -EBUSY;
170c4c4018bSRalf Baechle 		goto out_fail;
1712600990eSRalf Baechle 	}
1722600990eSRalf Baechle 
17367e2ccceSRalf Baechle out_fail:
174c4c4018bSRalf Baechle 	smp_mb();
175c4c4018bSRalf Baechle 	atomic_dec(&channel_wqs[index].in_open);
176c4c4018bSRalf Baechle 	smp_mb();
17767e2ccceSRalf Baechle 
178c4c4018bSRalf Baechle out_ret:
17967e2ccceSRalf Baechle 	return ret;
1802600990eSRalf Baechle }
1812600990eSRalf Baechle 
rtlx_release(int index)1822600990eSRalf Baechle int rtlx_release(int index)
1832600990eSRalf Baechle {
1841928cc84SKevin D. Kissell 	if (rtlx == NULL) {
1851928cc84SKevin D. Kissell 		pr_err("rtlx_release() with null rtlx\n");
1861928cc84SKevin D. Kissell 		return 0;
1871928cc84SKevin D. Kissell 	}
1882600990eSRalf Baechle 	rtlx->channel[index].lx_state = RTLX_STATE_UNUSED;
1892600990eSRalf Baechle 	return 0;
1902600990eSRalf Baechle }
1912600990eSRalf Baechle 
rtlx_read_poll(int index,int can_sleep)1922600990eSRalf Baechle unsigned int rtlx_read_poll(int index, int can_sleep)
1932600990eSRalf Baechle {
1942600990eSRalf Baechle 	struct rtlx_channel *chan;
1952600990eSRalf Baechle 
1962600990eSRalf Baechle 	if (rtlx == NULL)
1972600990eSRalf Baechle 		return 0;
1982600990eSRalf Baechle 
1992600990eSRalf Baechle 	chan = &rtlx->channel[index];
2002600990eSRalf Baechle 
2012600990eSRalf Baechle 	/* data available to read? */
2022600990eSRalf Baechle 	if (chan->lx_read == chan->lx_write) {
2032600990eSRalf Baechle 		if (can_sleep) {
20435a2af94SPeter Zijlstra 			int ret = __wait_event_interruptible(
20535a2af94SPeter Zijlstra 				channel_wqs[index].lx_queue,
2061928cc84SKevin D. Kissell 				(chan->lx_read != chan->lx_write) ||
20735a2af94SPeter Zijlstra 				sp_stopping);
20867e2ccceSRalf Baechle 			if (ret)
20967e2ccceSRalf Baechle 				return ret;
2102600990eSRalf Baechle 
21167e2ccceSRalf Baechle 			if (sp_stopping)
2122600990eSRalf Baechle 				return 0;
21367e2ccceSRalf Baechle 		} else
2142600990eSRalf Baechle 			return 0;
2152600990eSRalf Baechle 	}
2162600990eSRalf Baechle 
2172600990eSRalf Baechle 	return (chan->lx_write + chan->buffer_size - chan->lx_read)
2182600990eSRalf Baechle 	       % chan->buffer_size;
2192600990eSRalf Baechle }
2202600990eSRalf Baechle 
write_spacefree(int read,int write,int size)2212600990eSRalf Baechle static inline int write_spacefree(int read, int write, int size)
2222600990eSRalf Baechle {
2232600990eSRalf Baechle 	if (read == write) {
2242600990eSRalf Baechle 		/*
2252600990eSRalf Baechle 		 * Never fill the buffer completely, so indexes are always
2262600990eSRalf Baechle 		 * equal if empty and only empty, or !equal if data available
2272600990eSRalf Baechle 		 */
2282600990eSRalf Baechle 		return size - 1;
2292600990eSRalf Baechle 	}
2302600990eSRalf Baechle 
2312600990eSRalf Baechle 	return ((read + size - write) % size) - 1;
2322600990eSRalf Baechle }
2332600990eSRalf Baechle 
rtlx_write_poll(int index)2342600990eSRalf Baechle unsigned int rtlx_write_poll(int index)
2352600990eSRalf Baechle {
2362600990eSRalf Baechle 	struct rtlx_channel *chan = &rtlx->channel[index];
2371928cc84SKevin D. Kissell 
2381928cc84SKevin D. Kissell 	return write_spacefree(chan->rt_read, chan->rt_write,
2391928cc84SKevin D. Kissell 				chan->buffer_size);
2402600990eSRalf Baechle }
2412600990eSRalf Baechle 
rtlx_read(int index,void __user * buff,size_t count)2427f5a7716SRalf Baechle ssize_t rtlx_read(int index, void __user *buff, size_t count)
2432600990eSRalf Baechle {
24461dcc6f4SRalf Baechle 	size_t lx_write, fl = 0L;
2452600990eSRalf Baechle 	struct rtlx_channel *lx;
24646230aa6SRalf Baechle 	unsigned long failed;
2472600990eSRalf Baechle 
2482600990eSRalf Baechle 	if (rtlx == NULL)
2492600990eSRalf Baechle 		return -ENOSYS;
2502600990eSRalf Baechle 
2512600990eSRalf Baechle 	lx = &rtlx->channel[index];
252e01402b1SRalf Baechle 
253bc4809e9SRalf Baechle 	mutex_lock(&channel_wqs[index].mutex);
25461dcc6f4SRalf Baechle 	smp_rmb();
25561dcc6f4SRalf Baechle 	lx_write = lx->lx_write;
25661dcc6f4SRalf Baechle 
257e01402b1SRalf Baechle 	/* find out how much in total */
258e01402b1SRalf Baechle 	count = min(count,
25961dcc6f4SRalf Baechle 		     (size_t)(lx_write + lx->buffer_size - lx->lx_read)
2602600990eSRalf Baechle 		     % lx->buffer_size);
261e01402b1SRalf Baechle 
262e01402b1SRalf Baechle 	/* then how much from the read pointer onwards */
263e01402b1SRalf Baechle 	fl = min(count, (size_t)lx->buffer_size - lx->lx_read);
264e01402b1SRalf Baechle 
26546230aa6SRalf Baechle 	failed = copy_to_user(buff, lx->lx_buffer + lx->lx_read, fl);
26646230aa6SRalf Baechle 	if (failed)
26746230aa6SRalf Baechle 		goto out;
268e01402b1SRalf Baechle 
269e01402b1SRalf Baechle 	/* and if there is anything left at the beginning of the buffer */
2702600990eSRalf Baechle 	if (count - fl)
27146230aa6SRalf Baechle 		failed = copy_to_user(buff + fl, lx->lx_buffer, count - fl);
27246230aa6SRalf Baechle 
27346230aa6SRalf Baechle out:
27446230aa6SRalf Baechle 	count -= failed;
275e01402b1SRalf Baechle 
27661dcc6f4SRalf Baechle 	smp_wmb();
27761dcc6f4SRalf Baechle 	lx->lx_read = (lx->lx_read + count) % lx->buffer_size;
27861dcc6f4SRalf Baechle 	smp_wmb();
279bc4809e9SRalf Baechle 	mutex_unlock(&channel_wqs[index].mutex);
280e01402b1SRalf Baechle 
281afc4841dSRalf Baechle 	return count;
282e01402b1SRalf Baechle }
283e01402b1SRalf Baechle 
rtlx_write(int index,const void __user * buffer,size_t count)2847f5a7716SRalf Baechle ssize_t rtlx_write(int index, const void __user *buffer, size_t count)
285e01402b1SRalf Baechle {
286e01402b1SRalf Baechle 	struct rtlx_channel *rt;
2877f5a7716SRalf Baechle 	unsigned long failed;
28861dcc6f4SRalf Baechle 	size_t rt_read;
289e01402b1SRalf Baechle 	size_t fl;
2902600990eSRalf Baechle 
2912600990eSRalf Baechle 	if (rtlx == NULL)
2925792bf64SSteven J. Hill 		return -ENOSYS;
2932600990eSRalf Baechle 
2942600990eSRalf Baechle 	rt = &rtlx->channel[index];
2952600990eSRalf Baechle 
296bc4809e9SRalf Baechle 	mutex_lock(&channel_wqs[index].mutex);
29761dcc6f4SRalf Baechle 	smp_rmb();
29861dcc6f4SRalf Baechle 	rt_read = rt->rt_read;
29961dcc6f4SRalf Baechle 
3002600990eSRalf Baechle 	/* total number of bytes to copy */
3015792bf64SSteven J. Hill 	count = min_t(size_t, count, write_spacefree(rt_read, rt->rt_write,
3021928cc84SKevin D. Kissell 						     rt->buffer_size));
3032600990eSRalf Baechle 
3042600990eSRalf Baechle 	/* first bit from write pointer to the end of the buffer, or count */
3052600990eSRalf Baechle 	fl = min(count, (size_t) rt->buffer_size - rt->rt_write);
3062600990eSRalf Baechle 
30746230aa6SRalf Baechle 	failed = copy_from_user(rt->rt_buffer + rt->rt_write, buffer, fl);
30846230aa6SRalf Baechle 	if (failed)
30946230aa6SRalf Baechle 		goto out;
3102600990eSRalf Baechle 
3112600990eSRalf Baechle 	/* if there's any left copy to the beginning of the buffer */
3125792bf64SSteven J. Hill 	if (count - fl)
31346230aa6SRalf Baechle 		failed = copy_from_user(rt->rt_buffer, buffer + fl, count - fl);
31446230aa6SRalf Baechle 
31546230aa6SRalf Baechle out:
3167f5a7716SRalf Baechle 	count -= failed;
3172600990eSRalf Baechle 
31861dcc6f4SRalf Baechle 	smp_wmb();
31961dcc6f4SRalf Baechle 	rt->rt_write = (rt->rt_write + count) % rt->buffer_size;
32061dcc6f4SRalf Baechle 	smp_wmb();
321bc4809e9SRalf Baechle 	mutex_unlock(&channel_wqs[index].mutex);
3222600990eSRalf Baechle 
3232c973ef0SDeng-Cheng Zhu 	_interrupt_sp();
3242c973ef0SDeng-Cheng Zhu 
32561dcc6f4SRalf Baechle 	return count;
3262600990eSRalf Baechle }
3272600990eSRalf Baechle 
3282600990eSRalf Baechle 
file_open(struct inode * inode,struct file * filp)3292600990eSRalf Baechle static int file_open(struct inode *inode, struct file *filp)
3302600990eSRalf Baechle {
3311bbfc20dSRalf Baechle 	return rtlx_open(iminor(inode), (filp->f_flags & O_NONBLOCK) ? 0 : 1);
3322600990eSRalf Baechle }
3332600990eSRalf Baechle 
file_release(struct inode * inode,struct file * filp)3342600990eSRalf Baechle static int file_release(struct inode *inode, struct file *filp)
3352600990eSRalf Baechle {
3361bbfc20dSRalf Baechle 	return rtlx_release(iminor(inode));
3372600990eSRalf Baechle }
3382600990eSRalf Baechle 
file_poll(struct file * file,poll_table * wait)3398b9aab09SAl Viro static __poll_t file_poll(struct file *file, poll_table *wait)
3402600990eSRalf Baechle {
341496ad9aaSAl Viro 	int minor = iminor(file_inode(file));
3428b9aab09SAl Viro 	__poll_t mask = 0;
3432600990eSRalf Baechle 
3442600990eSRalf Baechle 	poll_wait(file, &channel_wqs[minor].rt_queue, wait);
3452600990eSRalf Baechle 	poll_wait(file, &channel_wqs[minor].lx_queue, wait);
3462600990eSRalf Baechle 
3472600990eSRalf Baechle 	if (rtlx == NULL)
3482600990eSRalf Baechle 		return 0;
3492600990eSRalf Baechle 
3502600990eSRalf Baechle 	/* data available to read? */
3512600990eSRalf Baechle 	if (rtlx_read_poll(minor, 0))
352*a9a08845SLinus Torvalds 		mask |= EPOLLIN | EPOLLRDNORM;
3532600990eSRalf Baechle 
3542600990eSRalf Baechle 	/* space to write */
3552600990eSRalf Baechle 	if (rtlx_write_poll(minor))
356*a9a08845SLinus Torvalds 		mask |= EPOLLOUT | EPOLLWRNORM;
3572600990eSRalf Baechle 
3582600990eSRalf Baechle 	return mask;
3592600990eSRalf Baechle }
3602600990eSRalf Baechle 
file_read(struct file * file,char __user * buffer,size_t count,loff_t * ppos)3612600990eSRalf Baechle static ssize_t file_read(struct file *file, char __user *buffer, size_t count,
3622600990eSRalf Baechle 			 loff_t *ppos)
3632600990eSRalf Baechle {
364496ad9aaSAl Viro 	int minor = iminor(file_inode(file));
3652600990eSRalf Baechle 
3662600990eSRalf Baechle 	/* data available? */
3675792bf64SSteven J. Hill 	if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1))
3685792bf64SSteven J. Hill 		return 0;	/* -EAGAIN makes 'cat' whine */
3692600990eSRalf Baechle 
37046230aa6SRalf Baechle 	return rtlx_read(minor, buffer, count);
3712600990eSRalf Baechle }
3722600990eSRalf Baechle 
file_write(struct file * file,const char __user * buffer,size_t count,loff_t * ppos)3732600990eSRalf Baechle static ssize_t file_write(struct file *file, const char __user *buffer,
3742600990eSRalf Baechle 			  size_t count, loff_t *ppos)
3752600990eSRalf Baechle {
376496ad9aaSAl Viro 	int minor = iminor(file_inode(file));
377e01402b1SRalf Baechle 
378e01402b1SRalf Baechle 	/* any space left... */
3792600990eSRalf Baechle 	if (!rtlx_write_poll(minor)) {
38035a2af94SPeter Zijlstra 		int ret;
381e01402b1SRalf Baechle 
382e01402b1SRalf Baechle 		if (file->f_flags & O_NONBLOCK)
383afc4841dSRalf Baechle 			return -EAGAIN;
384e01402b1SRalf Baechle 
38535a2af94SPeter Zijlstra 		ret = __wait_event_interruptible(channel_wqs[minor].rt_queue,
38635a2af94SPeter Zijlstra 					   rtlx_write_poll(minor));
38767e2ccceSRalf Baechle 		if (ret)
38867e2ccceSRalf Baechle 			return ret;
389e01402b1SRalf Baechle 	}
390e01402b1SRalf Baechle 
39146230aa6SRalf Baechle 	return rtlx_write(minor, buffer, count);
392e01402b1SRalf Baechle }
393e01402b1SRalf Baechle 
3942c973ef0SDeng-Cheng Zhu const struct file_operations rtlx_fops = {
395e01402b1SRalf Baechle 	.owner =   THIS_MODULE,
3962600990eSRalf Baechle 	.open =    file_open,
3972600990eSRalf Baechle 	.release = file_release,
3982600990eSRalf Baechle 	.write =   file_write,
3992600990eSRalf Baechle 	.read =    file_read,
4006038f373SArnd Bergmann 	.poll =    file_poll,
4016038f373SArnd Bergmann 	.llseek =  noop_llseek,
402e01402b1SRalf Baechle };
403e01402b1SRalf Baechle 
404e01402b1SRalf Baechle module_init(rtlx_module_init);
405e01402b1SRalf Baechle module_exit(rtlx_module_exit);
406afc4841dSRalf Baechle 
407e01402b1SRalf Baechle MODULE_DESCRIPTION("MIPS RTLX");
4082600990eSRalf Baechle MODULE_AUTHOR("Elizabeth Oldham, MIPS Technologies, Inc.");
409e01402b1SRalf Baechle MODULE_LICENSE("GPL");
410