struct canque_slot_t **tail; /* points to NULL pointer for chaining */
struct canque_slot_t *flist; /* points the first entry in the free list */
struct canque_slot_t *entry; /* points to first allocated entry */
- spinlock_t fifo_lock; /* spin_lock_irqsave / spin_lock_irqrestore */
+ can_spinlock_t fifo_lock; /* can_spin_lock_irqsave / can_spin_unlock_irqrestore */
};
#define CAN_FIFOF_DESTROY_b 15
static inline
int canque_fifo_get_inslot(struct canque_fifo_t *fifo, struct canque_slot_t **slotp, int cmd)
{
- unsigned long flags;
+ can_spin_irqflags_t flags;
struct canque_slot_t *slot;
- spin_lock_irqsave(&fifo->fifo_lock, flags);
+ can_spin_lock_irqsave(&fifo->fifo_lock, flags);
/* get the first free slot slot from flist */
if(!(slot=fifo->flist)) {
canque_fifo_set_fl(fifo,OVERRUN);
canque_fifo_set_fl(fifo,FULL);
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
*slotp=NULL;
return -1;
}
/* adjust free slot list */
if(!(fifo->flist=slot->next))
canque_fifo_set_fl(fifo,FULL);
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
*slotp=slot;
slot->slot_flags=cmd&CAN_SLOTF_CMD;
return 1;
int canque_fifo_put_inslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot)
{
int ret;
- unsigned long flags;
+ can_spin_irqflags_t flags;
slot->next=NULL;
- spin_lock_irqsave(&fifo->fifo_lock, flags);
+ can_spin_lock_irqsave(&fifo->fifo_lock, flags);
if(*fifo->tail) printk(KERN_CRIT "canque_fifo_put_inslot: fifo->tail != NULL\n");
*fifo->tail=slot;
fifo->tail=&slot->next;
ret=CAN_FIFOF_EMPTY; /* Fifo has been empty before put */
if(canque_fifo_test_and_clear_fl(fifo,INACTIVE))
ret=CAN_FIFOF_INACTIVE; /* Fifo has been empty before put */
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
return ret;
}
int canque_fifo_abort_inslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot)
{
int ret=0;
- unsigned long flags;
- spin_lock_irqsave(&fifo->fifo_lock, flags);
+ can_spin_irqflags_t flags;
+ can_spin_lock_irqsave(&fifo->fifo_lock, flags);
slot->next=fifo->flist;
fifo->flist=slot;
if(canque_fifo_test_and_clear_fl(fifo,FULL))
ret=CAN_FIFOF_FULL;
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
return ret;
}
static inline
int canque_fifo_test_outslot(struct canque_fifo_t *fifo, struct canque_slot_t **slotp)
{
- unsigned long flags;
+ can_spin_irqflags_t flags;
int cmd;
struct canque_slot_t *slot;
- spin_lock_irqsave(&fifo->fifo_lock, flags);
+ can_spin_lock_irqsave(&fifo->fifo_lock, flags);
if(!(slot=fifo->head)){;
canque_fifo_set_fl(fifo,EMPTY);
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
*slotp=NULL;
return -1;
}
if(!(fifo->head=slot->next))
fifo->tail=&fifo->head;
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
*slotp=slot;
cmd=slot->slot_flags;
int canque_fifo_free_outslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot)
{
int ret=0;
- unsigned long flags;
- spin_lock_irqsave(&fifo->fifo_lock, flags);
+ can_spin_irqflags_t flags;
+ can_spin_lock_irqsave(&fifo->fifo_lock, flags);
slot->next=fifo->flist;
fifo->flist=slot;
if(canque_fifo_test_and_clear_fl(fifo,FULL))
canque_fifo_set_fl(fifo,EMPTY);
ret|=CAN_FIFOF_EMPTY;
}
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
return ret;
}
static inline
int canque_fifo_again_outslot(struct canque_fifo_t *fifo, struct canque_slot_t *slot)
{
- unsigned long flags;
- spin_lock_irqsave(&fifo->fifo_lock, flags);
+ can_spin_irqflags_t flags;
+ can_spin_lock_irqsave(&fifo->fifo_lock, flags);
if(!(slot->next=fifo->head))
fifo->tail=&slot->next;
fifo->head=slot;
- spin_unlock_irqrestore(&fifo->fifo_lock, flags);
+ can_spin_unlock_irqrestore(&fifo->fifo_lock, flags);
return 1;
}
* @filtid: the possible CAN message identifiers filter.
* @filtmask: the filter mask, the comparison considers only
* @filtid bits corresponding to set bits in the @filtmask field.
- * @inpeers: the lists of all peer FIFOs connected by their
+ * @inpeers: the lists of all peers FIFOs connected by their
* input side (@inends) to the same terminal (@struct canque_ends_t).
- * @outpeers: the lists of all peer FIFOs connected by their
+ * @outpeers: the lists of all peers FIFOs connected by their
* output side (@outends) to the same terminal (@struct canque_ends_t).
+ * @activepeers: the lists of peers FIFOs connected by their
+ * output side (@outends) to the same terminal (@struct canque_ends_t)
+ * with same priority and active state.
* @inends: the pointer to the FIFO input side terminal (@struct canque_ends_t).
* @outends: the pointer to the FIFO output side terminal (@struct canque_ends_t).
* @edge_used: the atomic usage counter, mainly used for safe destruction of the edge.
unsigned long filtmask;
struct list_head inpeers;
struct list_head outpeers;
+ struct list_head activepeers;
struct canque_ends_t *inends;
struct canque_ends_t *outends;
atomic_t edge_used;
struct list_head active[CANQUEUE_PRIO_NR];
struct list_head idle;
struct list_head inlist;
- spinlock_t ends_lock; /* spin_lock_irqsave / spin_lock_irqrestore */
+ struct list_head outlist;
+ can_spinlock_t ends_lock; /* can_spin_lock_irqsave / can_spin_unlock_irqrestore */
void (*notify)(struct canque_ends_t *qends, struct canque_edge_t *qedge, int what);
void *context;
union {
wait_queue_head_t readq;
wait_queue_head_t writeq;
wait_queue_head_t emptyq;
+ #ifdef CAN_ENABLE_KERN_FASYNC
+ struct fasync_struct *fasync;
+ #endif /*CAN_ENABLE_KERN_FASYNC*/
} fileinfo;
struct {
wait_queue_head_t daemonq;
static inline
void canque_activate_edge(struct canque_ends_t *inends, struct canque_edge_t *qedge)
{
- unsigned long flags;
+ can_spin_irqflags_t flags;
struct canque_ends_t *outends;
if(qedge->edge_prio>=CANQUEUE_PRIO_NR)
qedge->edge_prio=CANQUEUE_PRIO_NR-1;
- spin_lock_irqsave(&inends->ends_lock, flags);
+ can_spin_lock_irqsave(&inends->ends_lock, flags);
if((outends=qedge->outends)){
- spin_lock(&outends->ends_lock);
- spin_lock(&qedge->fifo.fifo_lock);
+ can_spin_lock(&outends->ends_lock);
+ can_spin_lock(&qedge->fifo.fifo_lock);
if(!canque_fifo_test_fl(&qedge->fifo,EMPTY)){
- list_del(&qedge->outpeers);
- list_add_tail(&qedge->outpeers,&outends->active[qedge->edge_prio]);
+ list_del(&qedge->activepeers);
+ list_add_tail(&qedge->activepeers,&outends->active[qedge->edge_prio]);
}
- spin_unlock(&qedge->fifo.fifo_lock);
- spin_unlock(&outends->ends_lock);
+ can_spin_unlock(&qedge->fifo.fifo_lock);
+ can_spin_unlock(&outends->ends_lock);
}
- spin_unlock_irqrestore(&inends->ends_lock, flags);
+ can_spin_unlock_irqrestore(&inends->ends_lock, flags);
}
/**
int canqueue_ends_init_gen(struct canque_ends_t *qends);
+void canqueue_block_inlist(struct canque_ends_t *qends);
+
+void canqueue_block_outlist(struct canque_ends_t *qends);
+
+int canqueue_ends_kill_inlist(struct canque_ends_t *qends, int send_rest);
+
+int canqueue_ends_kill_outlist(struct canque_ends_t *qends);
/* edge reference and traversal functions */
static inline
void canque_edge_decref(struct canque_edge_t *edge)
{
- unsigned long flags;
+ can_spin_irqflags_t flags;
struct canque_ends_t *inends=edge->inends;
struct canque_ends_t *outends=edge->outends;
int dead_fl;
- spin_lock_irqsave(&inends->ends_lock, flags);
- spin_lock(&outends->ends_lock);
+ can_spin_lock_irqsave(&inends->ends_lock, flags);
+ can_spin_lock(&outends->ends_lock);
if(atomic_dec_and_test(&edge->edge_used)) {
dead_fl=canque_fifo_test_and_set_fl(&edge->fifo,DEAD);
/*This should not be there, but it cannot be outside of the lock :-(*/
canque_notify_bothends(edge,CANQUEUE_NOTIFY_NOUSR);
- spin_unlock(&outends->ends_lock);
- spin_unlock_irqrestore(&inends->ends_lock, flags);
+ can_spin_unlock(&outends->ends_lock);
+ can_spin_unlock_irqrestore(&inends->ends_lock, flags);
canque_edge_do_dead(edge, dead_fl);
} else {
- spin_unlock(&outends->ends_lock);
- spin_unlock_irqrestore(&inends->ends_lock, flags);
+ can_spin_unlock(&outends->ends_lock);
+ can_spin_unlock_irqrestore(&inends->ends_lock, flags);
}
}
static inline
struct canque_edge_t *canque_first_inedge(struct canque_ends_t *qends)
{
- unsigned long flags;
+ can_spin_irqflags_t flags;
struct list_head *entry;
struct canque_edge_t *edge;
- spin_lock_irqsave(&qends->ends_lock, flags);
+ can_spin_lock_irqsave(&qends->ends_lock, flags);
entry=qends->inlist.next;
skip_dead:
if(entry != &qends->inlist) {
} else {
edge=NULL;
}
- spin_unlock_irqrestore(&qends->ends_lock, flags);
+ can_spin_unlock_irqrestore(&qends->ends_lock, flags);
return edge;
}
static inline
struct canque_edge_t *canque_next_inedge(struct canque_ends_t *qends, struct canque_edge_t *edge)
{
- unsigned long flags;
+ can_spin_irqflags_t flags;
struct list_head *entry;
struct canque_edge_t *next;
- spin_lock_irqsave(&qends->ends_lock, flags);
+ can_spin_lock_irqsave(&qends->ends_lock, flags);
entry=edge->inpeers.next;
skip_dead:
if(entry != &qends->inlist) {
} else {
next=NULL;
}
- spin_unlock_irqrestore(&qends->ends_lock, flags);
+ can_spin_unlock_irqrestore(&qends->ends_lock, flags);
canque_edge_decref(edge);
return next;
}
#define canque_for_each_inedge(qends, edge) \
for(edge=canque_first_inedge(qends);edge;edge=canque_next_inedge(qends, edge))
+static inline
+struct canque_edge_t *canque_first_outedge(struct canque_ends_t *qends)
+{
+ can_spin_irqflags_t flags;
+ struct list_head *entry;
+ struct canque_edge_t *edge;
+
+ can_spin_lock_irqsave(&qends->ends_lock, flags);
+ entry=qends->outlist.next;
+ skip_dead:
+ if(entry != &qends->outlist) {
+ edge=list_entry(entry,struct canque_edge_t,outpeers);
+ if(canque_fifo_test_fl(&edge->fifo,DEAD)) {
+ entry=entry->next;
+ goto skip_dead;
+ }
+ canque_edge_incref(edge);
+ } else {
+ edge=NULL;
+ }
+ can_spin_unlock_irqrestore(&qends->ends_lock, flags);
+ return edge;
+}
+
+
+static inline
+struct canque_edge_t *canque_next_outedge(struct canque_ends_t *qends, struct canque_edge_t *edge)
+{
+ can_spin_irqflags_t flags;
+ struct list_head *entry;
+ struct canque_edge_t *next;
+
+ can_spin_lock_irqsave(&qends->ends_lock, flags);
+ entry=edge->outpeers.next;
+ skip_dead:
+ if(entry != &qends->outlist) {
+ next=list_entry(entry,struct canque_edge_t,outpeers);
+ if(canque_fifo_test_fl(&edge->fifo,DEAD)) {
+ entry=entry->next;
+ goto skip_dead;
+ }
+ canque_edge_incref(next);
+ } else {
+ next=NULL;
+ }
+ can_spin_unlock_irqrestore(&qends->ends_lock, flags);
+ canque_edge_decref(edge);
+ return next;
+}
+
+#define canque_for_each_outedge(qends, edge) \
+ for(edge=canque_first_outedge(qends);edge;edge=canque_next_outedge(qends, edge))
+
/* Linux kernel specific functions */
struct canque_edge_t *canque_new_edge_kern(int slotsnr);