Commit 0cc06a63 authored by Federico Vaga's avatar Federico Vaga Committed by Federico Vaga

kernel: use kfifo instead of home-made fifo

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent a814a6f0
......@@ -64,6 +64,7 @@ enum ft_command {
#include <linux/timer.h>
#include <linux/fmc.h>
#include <linux/version.h>
#include <linux/kfifo.h>
#define FT_USER_OFFSET_RANGE 1000000000 /* picoseconds */
......@@ -114,11 +115,6 @@ struct ft_wr_timestamp {
int channel;
};
struct ft_sw_fifo {
unsigned long head, tail, count, size;
struct ft_wr_timestamp *t;
};
struct ft_channel_state {
unsigned long flags;
int expected_edge;
......@@ -127,7 +123,7 @@ struct ft_channel_state {
int32_t user_offset;
struct ft_wr_timestamp prev_ts;
struct ft_sw_fifo fifo;
struct kfifo fifo;
};
/* Main TDC device context */
......
......@@ -22,6 +22,7 @@
#include <linux/init.h>
#include <linux/list.h>
#include <linux/io.h>
#include <linux/kfifo.h>
#include <linux/fmc.h>
#include <linux/fmc-sdb.h>
......@@ -52,27 +53,22 @@ static int ft_init_channel(struct fmctdc_dev *ft, int channel)
struct ft_channel_state *st = &ft->channels[channel - 1];
st->expected_edge = 1;
st->fifo.size = ft_buffer_size;
st->fifo.t =
kmalloc(sizeof(struct ft_wr_timestamp) * st->fifo.size, GFP_KERNEL);
if (!st->fifo.t)
return -ENOMEM;
return 0;
return kfifo_alloc(&st->fifo,
sizeof(struct ft_wr_timestamp) * ft_buffer_size,
GFP_KERNEL);
}
static void ft_reset_channel(struct fmctdc_dev *ft, int channel)
{
struct ft_channel_state *st = &ft->channels[channel - FT_CH_1];
st->fifo.head = 0;
st->fifo.tail = 0;
st->fifo.count = 0;
st->cur_seq_id = 0;
st->expected_edge = 1;
clear_bit(FT_FLAG_CH_INPUT_READY, &st->flags);
ft_zio_kill_buffer(ft, channel);
kfifo_reset(&st->fifo);
}
int ft_enable_termination(struct fmctdc_dev *ft, int channel, int enable)
......@@ -165,7 +161,7 @@ static void ft_channels_exit(struct fmctdc_dev *ft)
int i;
for (i = FT_CH_1; i <= FT_NUM_CHANNELS; i++)
kfree(ft->channels[i - 1].fifo.t);
kfifo_free(&ft->channels[i - 1].fifo);
}
struct ft_modlist {
......
......@@ -20,6 +20,7 @@
#include <linux/bitops.h>
#include <linux/spinlock.h>
#include <linux/io.h>
#include <linux/kfifo.h>
#include <linux/zio.h>
#include <linux/zio-trigger.h>
......@@ -58,24 +59,22 @@ int ft_read_sw_fifo(struct fmctdc_dev *ft, int channel,
struct ft_wr_timestamp ts;
struct ft_channel_state *st;
unsigned long flags;
int ret;
st = &ft->channels[channel - 1];
if (!chan->active_block)
return -EAGAIN;
if (!st->fifo.count)
ret = kfifo_out_spinlocked(&st->fifo, &ts,
sizeof(struct ft_wr_timestamp), &ft->lock);
if (!ret) {
return -EAGAIN;
/* Copy the sample to local storage */
spin_lock_irqsave(&ft->lock, flags);
ts = st->fifo.t[st->fifo.tail];
st->fifo.tail++;
if (st->fifo.tail == st->fifo.size)
st->fifo.tail = 0;
st->fifo.count--;
spin_unlock_irqrestore(&ft->lock, flags);
} else if (ret < sizeof(struct ft_wr_timestamp)) {
dev_err(&ft->zdev->head.dev,
"Somethig wrong with kfifo buffer\n");
return -EINVAL;
}
/* Write the timestamp in the trigger, it will reach the control */
ti->tstamp.tv_sec = ts.seconds;
......@@ -107,23 +106,6 @@ int ft_read_sw_fifo(struct fmctdc_dev *ft, int channel,
return 0;
}
static inline void enqueue_timestamp(struct fmctdc_dev *ft, int channel,
struct ft_wr_timestamp *ts)
{
struct ft_sw_fifo *fifo = &ft->channels[channel - 1].fifo;
unsigned long flags;
/* fixme: consider independent locks for each channel. */
spin_lock_irqsave(&ft->lock, flags);
fifo->t[fifo->head] = *ts;
fifo->head = (fifo->head + 1) % fifo->size;
if (fifo->count < fifo->size)
fifo->count++;
else
fifo->tail = (fifo->tail + 1) % fifo->size;
spin_unlock_irqrestore(&ft->lock, flags);
}
static inline void process_timestamp(struct fmctdc_dev *ft,
struct ft_hw_timestamp *hwts,
......@@ -208,7 +190,8 @@ static inline void process_timestamp(struct fmctdc_dev *ft,
}
/* Put the timestamp in the FIFO */
enqueue_timestamp(ft, channel, &ts);
kfifo_in_spinlocked(&st->fifo, &ts,
sizeof(struct ft_wr_timestamp), &ft->lock);
}
/* Wait for the next raising edge */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment