summaryrefslogtreecommitdiff
path: root/xpp/xbus-core.c
diff options
context:
space:
mode:
Diffstat (limited to 'xpp/xbus-core.c')
-rw-r--r--xpp/xbus-core.c106
1 files changed, 5 insertions, 101 deletions
diff --git a/xpp/xbus-core.c b/xpp/xbus-core.c
index 961c361..9f73a86 100644
--- a/xpp/xbus-core.c
+++ b/xpp/xbus-core.c
@@ -55,7 +55,6 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer,
/* Command line parameters */
extern int print_dbg;
-extern int max_queue_len;
/* Forward declarations */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
@@ -133,105 +132,6 @@ void xbus_packet_free(xbus_t *xbus, xpacket_t *p)
// xbus->busname, atomic_read(&xbus->packet_counter));
}
-/*------------------------- Packet Queues --------------------------*/
-void init_xbus_packet_queue(packet_queue_t *q, const char name[])
-{
- INIT_LIST_HEAD(&q->head);
- spin_lock_init(&q->lock);
- q->count = 0;
- q->worst_count = 0;
- q->overflows = 0;
- snprintf(q->qname, XPD_NAMELEN, "%s", name);
-}
-
-#if 0
-/*
- * Assume the queue is locked
- */
-void __dump_packet_queue(const char *msg, packet_queue_t *q)
-{
- xpacket_t *tmp;
-
- list_for_each_entry(tmp, &q->head, list) {
- dump_packet(msg, tmp);
- }
-}
-#endif
-
-void drain_xbus_packet_queue(xbus_t *xbus, packet_queue_t *q)
-{
- unsigned long flags;
- xpacket_t *pack;
- xpacket_t *next;
-
- spin_lock_irqsave(&q->lock, flags);
- DBG("queue=%s count=%d\n", q->qname, q->count);
- DBG(" total packets count=%d\n", atomic_read(&xpacket_count));
- list_for_each_entry_safe(pack, next, &q->head, list) {
- list_del(&pack->list);
- q->count--;
- xbus->ops->packet_free(xbus, pack);
- }
- if(q->count != 0)
- ERR("drain_xbus_packet_queue: queue %s still has %d packets\n",
- q->qname, q->count);
- spin_unlock_irqrestore(&q->lock, flags);
-}
-
-void xbus_enqueue_packet(xbus_t *xbus, packet_queue_t *q, xpacket_t *pack)
-{
- unsigned long flags;
-
- spin_lock_irqsave(&q->lock, flags);
-
- if(q->count >= max_queue_len) {
- static unsigned long last_notice = 0; // rate limit
-
- if((jiffies - last_notice) < HZ) {
- NOTICE("xbus_enqueue_packet: dropping packet (queue len = %d, max=%d)\n",
- q->count, max_queue_len);
- last_notice = jiffies;
- }
- q->overflows++;
- xbus->ops->packet_free(xbus, pack);
- goto out;
- }
- list_add_tail(&pack->list, &q->head);
- q->count++;
-
- if(q->count > q->worst_count)
- q->worst_count = q->count;
-
- if(q->count < max_queue_len/100 && q->worst_count > q->count) // Decay worst_count
- q->worst_count--;
-
- // dump_packet("ENQUEUED", pack, print_dbg);
-out:
- spin_unlock_irqrestore(&q->lock, flags);
-}
-
-xpacket_t *xbus_dequeue_packet(packet_queue_t *q)
-{
- unsigned long flags;
- struct list_head *p;
- xpacket_t *pack = NULL;
-
- spin_lock_irqsave(&q->lock, flags);
-
- if(list_empty(&q->head)) {
- // DBG("LIST EMPTY (count=%d)\n", q->count);
- goto out;
- }
- p = q->head.next;
- list_del(p);
- q->count--;
- pack = list_entry(p, xpacket_t, list);
- // dump_packet("DEQUEUED", pack, print_dbg);
-out:
- spin_unlock_irqrestore(&q->lock, flags);
- return pack;
-}
-
/*------------------------- Bus Management -------------------------*/
xbus_t *xbus_of(int xbus_num)
@@ -430,7 +330,6 @@ void xbus_activate(xbus_t *xbus)
BUG_ON(!xbus);
ops = xbus->ops;
BUG_ON(!ops);
- BUG_ON(!xbus->priv);
/* Sanity checks */
BUG_ON(!ops->packet_send);
BUG_ON(!ops->packet_new || !ops->packet_free);
@@ -504,6 +403,7 @@ static void xbus_free(xbus_t *xbus)
if(!xbus)
return;
spin_lock_irqsave(&xbuses_lock, flags);
+ BUG_ON(!xbus_of(xbus->num));
BUG_ON(xbus != xbus_of(xbus->num));
xbuses_array[xbus->num] = NULL;
bus_count--;
@@ -658,6 +558,10 @@ void xbus_remove(xbus_t *xbus)
int ret;
BUG_ON(!xbus);
+ if(!xbus_of(xbus->num)) {
+ DBG("XBUS #%d was already removed. Skip.\n", xbus->num);
+ return;
+ }
DBG("%s\n", xbus->busname);
/* Block until no one use */