mirror of
https://github.com/DigitalDevices/dddvb.git
synced 2023-10-10 13:37:43 +02:00
backwards compatibility
This commit is contained in:
parent
04fc90e4d6
commit
b42358eaa2
@ -1382,7 +1382,10 @@ static int dvb_net_add_if(struct dvb_net *dvbnet, u16 pid, u8 feedtype)
|
||||
return -EINVAL;
|
||||
|
||||
net = alloc_netdev(sizeof(struct dvb_net_priv), "dvb",
|
||||
NET_NAME_UNKNOWN, dvb_net_setup);
|
||||
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0))
|
||||
NET_NAME_UNKNOWN,
|
||||
#endif
|
||||
dvb_net_setup);
|
||||
if (!net)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -56,6 +56,9 @@ void dvb_ringbuffer_init(struct dvb_ringbuffer *rbuf, void *data, size_t len)
|
||||
|
||||
int dvb_ringbuffer_empty(struct dvb_ringbuffer *rbuf)
|
||||
{
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
return (rbuf->pread == rbuf->pwrite);
|
||||
#else
|
||||
/* smp_load_acquire() to load write pointer on reader side
|
||||
* this pairs with smp_store_release() in dvb_ringbuffer_write(),
|
||||
* dvb_ringbuffer_write_user(), or dvb_ringbuffer_reset()
|
||||
@ -63,6 +66,7 @@ int dvb_ringbuffer_empty(struct dvb_ringbuffer *rbuf)
|
||||
* for memory barriers also see Documentation/circular-buffers.txt
|
||||
*/
|
||||
return (rbuf->pread == smp_load_acquire(&rbuf->pwrite));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -88,11 +92,15 @@ ssize_t dvb_ringbuffer_avail(struct dvb_ringbuffer *rbuf)
|
||||
{
|
||||
ssize_t avail;
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
avail = rbuf->pwrite - rbuf->pread;
|
||||
#else
|
||||
/* smp_load_acquire() to load write pointer on reader side
|
||||
* this pairs with smp_store_release() in dvb_ringbuffer_write(),
|
||||
* dvb_ringbuffer_write_user(), or dvb_ringbuffer_reset()
|
||||
*/
|
||||
avail = smp_load_acquire(&rbuf->pwrite) - rbuf->pread;
|
||||
#endif
|
||||
if (avail < 0)
|
||||
avail += rbuf->size;
|
||||
return avail;
|
||||
@ -102,6 +110,9 @@ ssize_t dvb_ringbuffer_avail(struct dvb_ringbuffer *rbuf)
|
||||
|
||||
void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf)
|
||||
{
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pread = smp_load_acquire(&rbuf->pwrite;
|
||||
#else
|
||||
/* dvb_ringbuffer_flush() counts as read operation
|
||||
* smp_load_acquire() to load write pointer
|
||||
* smp_store_release() to update read pointer, this ensures that the
|
||||
@ -109,18 +120,23 @@ void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf)
|
||||
* calls on other cpu cores
|
||||
*/
|
||||
smp_store_release(&rbuf->pread, smp_load_acquire(&rbuf->pwrite));
|
||||
#endif
|
||||
rbuf->error = 0;
|
||||
}
|
||||
EXPORT_SYMBOL(dvb_ringbuffer_flush);
|
||||
|
||||
void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf)
|
||||
{
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pread = rbuf->pwrite = 0;
|
||||
#else
|
||||
/* dvb_ringbuffer_reset() counts as read and write operation
|
||||
* smp_store_release() to update read pointer
|
||||
*/
|
||||
smp_store_release(&rbuf->pread, 0);
|
||||
/* smp_store_release() to update write pointer */
|
||||
smp_store_release(&rbuf->pwrite, 0);
|
||||
#endif
|
||||
rbuf->error = 0;
|
||||
}
|
||||
|
||||
@ -146,18 +162,25 @@ ssize_t dvb_ringbuffer_read_user(struct dvb_ringbuffer *rbuf, u8 __user *buf, si
|
||||
return -EFAULT;
|
||||
buf += split;
|
||||
todo -= split;
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pread = 0;
|
||||
#else
|
||||
/* smp_store_release() for read pointer update to ensure
|
||||
* that buf is not overwritten until read is complete,
|
||||
* this pairs with ACCESS_ONCE() in dvb_ringbuffer_free()
|
||||
*/
|
||||
smp_store_release(&rbuf->pread, 0);
|
||||
#endif
|
||||
}
|
||||
if (copy_to_user(buf, rbuf->data+rbuf->pread, todo))
|
||||
return -EFAULT;
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pread = (rbuf->pread + todo) % rbuf->size;
|
||||
#else
|
||||
/* smp_store_release() to update read pointer, see above */
|
||||
smp_store_release(&rbuf->pread, (rbuf->pread + todo) % rbuf->size);
|
||||
|
||||
#endif
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -171,16 +194,24 @@ void dvb_ringbuffer_read(struct dvb_ringbuffer *rbuf, u8 *buf, size_t len)
|
||||
memcpy(buf, rbuf->data+rbuf->pread, split);
|
||||
buf += split;
|
||||
todo -= split;
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pread = 0;
|
||||
#else
|
||||
/* smp_store_release() for read pointer update to ensure
|
||||
* that buf is not overwritten until read is complete,
|
||||
* this pairs with ACCESS_ONCE() in dvb_ringbuffer_free()
|
||||
*/
|
||||
smp_store_release(&rbuf->pread, 0);
|
||||
#endif
|
||||
}
|
||||
memcpy(buf, rbuf->data+rbuf->pread, todo);
|
||||
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pread = (rbuf->pread + todo) % rbuf->size;
|
||||
#else
|
||||
/* smp_store_release() to update read pointer, see above */
|
||||
smp_store_release(&rbuf->pread, (rbuf->pread + todo) % rbuf->size);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -195,16 +226,24 @@ ssize_t dvb_ringbuffer_write(struct dvb_ringbuffer *rbuf, const u8 *buf, size_t
|
||||
memcpy(rbuf->data+rbuf->pwrite, buf, split);
|
||||
buf += split;
|
||||
todo -= split;
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pwrite = 0;
|
||||
#else
|
||||
/* smp_store_release() for write pointer update to ensure that
|
||||
* written data is visible on other cpu cores before the pointer
|
||||
* update, this pairs with smp_load_acquire() in
|
||||
* dvb_ringbuffer_empty() or dvb_ringbuffer_avail()
|
||||
*/
|
||||
smp_store_release(&rbuf->pwrite, 0);
|
||||
#endif
|
||||
}
|
||||
memcpy(rbuf->data+rbuf->pwrite, buf, todo);
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pwrite = (rbuf->pwrite + todo) % rbuf->size;
|
||||
#else
|
||||
/* smp_store_release() for write pointer update, see above */
|
||||
smp_store_release(&rbuf->pwrite, (rbuf->pwrite + todo) % rbuf->size);
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
@ -224,18 +263,26 @@ ssize_t dvb_ringbuffer_write_user(struct dvb_ringbuffer *rbuf,
|
||||
return len - todo;
|
||||
buf += split;
|
||||
todo -= split;
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pwrite = 0;
|
||||
#else
|
||||
/* smp_store_release() for write pointer update to ensure that
|
||||
* written data is visible on other cpu cores before the pointer
|
||||
* update, this pairs with smp_load_acquire() in
|
||||
* dvb_ringbuffer_empty() or dvb_ringbuffer_avail()
|
||||
*/
|
||||
smp_store_release(&rbuf->pwrite, 0);
|
||||
#endif
|
||||
}
|
||||
status = copy_from_user(rbuf->data+rbuf->pwrite, buf, todo);
|
||||
if (status)
|
||||
return len - todo;
|
||||
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0))
|
||||
rbuf->pwrite = (rbuf->pwrite + todo) % rbuf->size;
|
||||
#else
|
||||
/* smp_store_release() for write pointer update, see above */
|
||||
smp_store_release(&rbuf->pwrite, (rbuf->pwrite + todo) % rbuf->size);
|
||||
#endif
|
||||
|
||||
return len;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user