rtlx.c (7034228792cc561e79ff8600f02884bd4c80e287) rtlx.c (496ad9aa8ef448058e36ca7a787c61f2e63f0f54)
1/*
2 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
3 * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org)
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *

--- 238 unchanged lines hidden (view full) ---

247 return 0;
248 }
249 rtlx->channel[index].lx_state = RTLX_STATE_UNUSED;
250 return 0;
251}
252
253unsigned int rtlx_read_poll(int index, int can_sleep)
254{
1/*
2 * Copyright (C) 2005 MIPS Technologies, Inc. All rights reserved.
3 * Copyright (C) 2005, 06 Ralf Baechle (ralf@linux-mips.org)
4 *
5 * This program is free software; you can distribute it and/or modify it
6 * under the terms of the GNU General Public License (Version 2) as
7 * published by the Free Software Foundation.
8 *

--- 238 unchanged lines hidden (view full) ---

247 return 0;
248 }
249 rtlx->channel[index].lx_state = RTLX_STATE_UNUSED;
250 return 0;
251}
252
253unsigned int rtlx_read_poll(int index, int can_sleep)
254{
255 struct rtlx_channel *chan;
255 struct rtlx_channel *chan;
256
256
257 if (rtlx == NULL)
258 return 0;
257 if (rtlx == NULL)
258 return 0;
259
259
260 chan = &rtlx->channel[index];
260 chan = &rtlx->channel[index];
261
262 /* data available to read? */
263 if (chan->lx_read == chan->lx_write) {
264 if (can_sleep) {
265 int ret = 0;
266
267 __wait_event_interruptible(channel_wqs[index].lx_queue,
268 (chan->lx_read != chan->lx_write) ||

--- 125 unchanged lines hidden (view full) ---

394
395static int file_release(struct inode *inode, struct file *filp)
396{
397 return rtlx_release(iminor(inode));
398}
399
400static unsigned int file_poll(struct file *file, poll_table * wait)
401{
261
262 /* data available to read? */
263 if (chan->lx_read == chan->lx_write) {
264 if (can_sleep) {
265 int ret = 0;
266
267 __wait_event_interruptible(channel_wqs[index].lx_queue,
268 (chan->lx_read != chan->lx_write) ||

--- 125 unchanged lines hidden (view full) ---

394
395static int file_release(struct inode *inode, struct file *filp)
396{
397 return rtlx_release(iminor(inode));
398}
399
400static unsigned int file_poll(struct file *file, poll_table * wait)
401{
402 int minor;
402 int minor = iminor(file_inode(file));
403 unsigned int mask = 0;
404
403 unsigned int mask = 0;
404
405 minor = iminor(file->f_path.dentry->d_inode);
406
407 poll_wait(file, &channel_wqs[minor].rt_queue, wait);
408 poll_wait(file, &channel_wqs[minor].lx_queue, wait);
409
410 if (rtlx == NULL)
411 return 0;
412
413 /* data available to read? */
414 if (rtlx_read_poll(minor, 0))

--- 4 unchanged lines hidden (view full) ---

419 mask |= POLLOUT | POLLWRNORM;
420
421 return mask;
422}
423
424static ssize_t file_read(struct file *file, char __user * buffer, size_t count,
425 loff_t * ppos)
426{
405 poll_wait(file, &channel_wqs[minor].rt_queue, wait);
406 poll_wait(file, &channel_wqs[minor].lx_queue, wait);
407
408 if (rtlx == NULL)
409 return 0;
410
411 /* data available to read? */
412 if (rtlx_read_poll(minor, 0))

--- 4 unchanged lines hidden (view full) ---

417 mask |= POLLOUT | POLLWRNORM;
418
419 return mask;
420}
421
422static ssize_t file_read(struct file *file, char __user * buffer, size_t count,
423 loff_t * ppos)
424{
427 int minor = iminor(file->f_path.dentry->d_inode);
425 int minor = iminor(file_inode(file));
428
429 /* data available? */
430 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1)) {
431 return 0; // -EAGAIN makes cat whinge
432 }
433
434 return rtlx_read(minor, buffer, count);
435}
436
437static ssize_t file_write(struct file *file, const char __user * buffer,
438 size_t count, loff_t * ppos)
439{
426
427 /* data available? */
428 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1)) {
429 return 0; // -EAGAIN makes cat whinge
430 }
431
432 return rtlx_read(minor, buffer, count);
433}
434
435static ssize_t file_write(struct file *file, const char __user * buffer,
436 size_t count, loff_t * ppos)
437{
440 int minor;
441 struct rtlx_channel *rt;
438 int minor = iminor(file_inode(file));
439 struct rtlx_channel *rt = &rtlx->channel[minor];
442
440
443 minor = iminor(file->f_path.dentry->d_inode);
444 rt = &rtlx->channel[minor];
445
446 /* any space left... */
447 if (!rtlx_write_poll(minor)) {
448 int ret = 0;
449
450 if (file->f_flags & O_NONBLOCK)
451 return -EAGAIN;
452
453 __wait_event_interruptible(channel_wqs[minor].rt_queue,
441 /* any space left... */
442 if (!rtlx_write_poll(minor)) {
443 int ret = 0;
444
445 if (file->f_flags & O_NONBLOCK)
446 return -EAGAIN;
447
448 __wait_event_interruptible(channel_wqs[minor].rt_queue,
454 rtlx_write_poll(minor),
455 ret);
449 rtlx_write_poll(minor),
450 ret);
456 if (ret)
457 return ret;
458 }
459
460 return rtlx_write(minor, buffer, count);
461}
462
463static const struct file_operations rtlx_fops = {
464 .owner = THIS_MODULE,
451 if (ret)
452 return ret;
453 }
454
455 return rtlx_write(minor, buffer, count);
456}
457
458static const struct file_operations rtlx_fops = {
459 .owner = THIS_MODULE,
465 .open = file_open,
460 .open = file_open,
466 .release = file_release,
467 .write = file_write,
461 .release = file_release,
462 .write = file_write,
468 .read = file_read,
469 .poll = file_poll,
463 .read = file_read,
464 .poll = file_poll,
470 .llseek = noop_llseek,
471};
472
473static struct irqaction rtlx_irq = {
474 .handler = rtlx_interrupt,
475 .name = "RTLX",
476};
477

--- 85 unchanged lines hidden ---
465 .llseek = noop_llseek,
466};
467
468static struct irqaction rtlx_irq = {
469 .handler = rtlx_interrupt,
470 .name = "RTLX",
471};
472

--- 85 unchanged lines hidden ---