Commit ab7760ad authored by Armin Schindler's avatar Armin Schindler Committed by Linus Torvalds

[PATCH] ISDN Eicon driver: linked-list handling by kernel api list.h

   Removed own implementations for linked-list handling, use
   Linus kernel API of list.h instead.
parent b3e0c913
/* $Id: adapter.h,v 1.1.2.2 2002/10/02 14:38:37 armin Exp $ */ /* $Id: adapter.h,v 1.4 2004/03/21 17:26:01 armin Exp $ */
#ifndef __DIVA_USER_MODE_IDI_ADAPTER_H__ #ifndef __DIVA_USER_MODE_IDI_ADAPTER_H__
#define __DIVA_USER_MODE_IDI_ADAPTER_H__ #define __DIVA_USER_MODE_IDI_ADAPTER_H__
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#define DIVA_UM_IDI_ADAPTER_REMOVED 0x00000001 #define DIVA_UM_IDI_ADAPTER_REMOVED 0x00000001
typedef struct _diva_um_idi_adapter { typedef struct _diva_um_idi_adapter {
diva_entity_link_t link; struct list_head link;
DESCRIPTOR d; DESCRIPTOR d;
int adapter_nr; int adapter_nr;
diva_entity_queue_t entity_q; /* entities linked to this adapter */ struct list_head entity_q; /* entities linked to this adapter */
dword status; dword status;
} diva_um_idi_adapter_t; } diva_um_idi_adapter_t;
......
/* $Id: capifunc.c,v 1.57 2004/03/20 18:18:03 armin Exp $ /* $Id: capifunc.c,v 1.59 2004/03/21 17:27:32 armin Exp $
* *
* ISDN interface module for Eicon active cards DIVA. * ISDN interface module for Eicon active cards DIVA.
* CAPI Interface common functions * CAPI Interface common functions
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "divacapi.h" #include "divacapi.h"
#include "divasync.h" #include "divasync.h"
#include "capifunc.h" #include "capifunc.h"
#include "dlist.h"
#define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR) #define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR)
#define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG) #define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG)
...@@ -58,11 +57,6 @@ static u16 diva_send_message(struct capi_ctr *, ...@@ -58,11 +57,6 @@ static u16 diva_send_message(struct capi_ctr *,
diva_os_message_buffer_s *); diva_os_message_buffer_s *);
extern void diva_os_set_controller_struct(struct capi_ctr *); extern void diva_os_set_controller_struct(struct capi_ctr *);
/*
* include queue functions
*/
#include "dlist.c"
extern void DIVA_DIDD_Read(DESCRIPTOR *, int); extern void DIVA_DIDD_Read(DESCRIPTOR *, int);
/* /*
...@@ -349,7 +343,7 @@ void sendf(APPL * appl, word command, dword Id, word Number, byte * format, ...) ...@@ -349,7 +343,7 @@ void sendf(APPL * appl, word command, dword Id, word Number, byte * format, ...)
/* /*
* cleanup adapter * cleanup adapter
*/ */
static void clean_adapter(int id, diva_entity_queue_t* free_mem_q) static void clean_adapter(int id, struct list_head *free_mem_q)
{ {
DIVA_CAPI_ADAPTER *a; DIVA_CAPI_ADAPTER *a;
int i, k; int i, k;
...@@ -358,7 +352,7 @@ static void clean_adapter(int id, diva_entity_queue_t* free_mem_q) ...@@ -358,7 +352,7 @@ static void clean_adapter(int id, diva_entity_queue_t* free_mem_q)
k = li_total_channels - a->li_channels; k = li_total_channels - a->li_channels;
if (k == 0) { if (k == 0) {
if (li_config_table) { if (li_config_table) {
diva_q_add_tail(free_mem_q, (diva_entity_link_t*)li_config_table); list_add((struct list_head *)li_config_table, free_mem_q);
li_config_table = NULL; li_config_table = NULL;
} }
} else { } else {
...@@ -383,7 +377,7 @@ static void clean_adapter(int id, diva_entity_queue_t* free_mem_q) ...@@ -383,7 +377,7 @@ static void clean_adapter(int id, diva_entity_queue_t* free_mem_q)
adapter[i].li_base -= a->li_channels; adapter[i].li_base -= a->li_channels;
} }
if (a->plci) if (a->plci)
diva_q_add_tail(free_mem_q, (diva_entity_link_t*)a->plci); list_add((struct list_head *)a->plci, free_mem_q);
memset(a, 0x00, sizeof(DIVA_CAPI_ADAPTER)); memset(a, 0x00, sizeof(DIVA_CAPI_ADAPTER));
while ((max_adapter != 0) && !adapter[max_adapter - 1].request) while ((max_adapter != 0) && !adapter[max_adapter - 1].request)
...@@ -396,13 +390,11 @@ static void clean_adapter(int id, diva_entity_queue_t* free_mem_q) ...@@ -396,13 +390,11 @@ static void clean_adapter(int id, diva_entity_queue_t* free_mem_q)
*/ */
static void divacapi_remove_card(DESCRIPTOR * d) static void divacapi_remove_card(DESCRIPTOR * d)
{ {
struct list_head *tmp;
diva_card *card = NULL; diva_card *card = NULL;
diva_entity_queue_t free_mem_q;
diva_entity_link_t* link;
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
LIST_HEAD(free_mem_q);
diva_q_init (&free_mem_q); struct list_head *link;
struct list_head *tmp;
/* /*
* Set "remove in progress flag". * Set "remove in progress flag".
...@@ -446,8 +438,8 @@ static void divacapi_remove_card(DESCRIPTOR * d) ...@@ -446,8 +438,8 @@ static void divacapi_remove_card(DESCRIPTOR * d)
} }
/* free queued memory areas */ /* free queued memory areas */
while ((link = diva_q_get_head(&free_mem_q))) { list_for_each_safe(link, tmp, &free_mem_q) {
diva_q_remove(&free_mem_q, link); list_del(link);
diva_os_free(0, link); diva_os_free(0, link);
} }
} }
......
/* $Id: diva.c,v 1.17 2003/09/09 06:52:01 schindler Exp $ */ /* $Id: diva.c,v 1.21 2004/03/21 17:30:25 armin Exp $ */
#define CARDTYPE_H_WANT_DATA 1 #define CARDTYPE_H_WANT_DATA 1
#define CARDTYPE_H_WANT_IDI_DATA 0 #define CARDTYPE_H_WANT_IDI_DATA 0
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "platform.h" #include "platform.h"
#include "debuglib.h" #include "debuglib.h"
#include "cardtype.h" #include "cardtype.h"
#include "dlist.h"
#include "pc.h" #include "pc.h"
#include "di_defs.h" #include "di_defs.h"
#include "di.h" #include "di.h"
...@@ -74,15 +73,10 @@ DivaIdiReqFunc(31) ...@@ -74,15 +73,10 @@ DivaIdiReqFunc(31)
struct pt_regs; struct pt_regs;
/*
* include queue functions
*/
#include "dlist.c"
/* /*
** LOCALS ** LOCALS
*/ */
diva_entity_queue_t adapter_queue; static LIST_HEAD(adapter_queue);
typedef struct _diva_get_xlog { typedef struct _diva_get_xlog {
word command; word command;
...@@ -158,6 +152,16 @@ static int diva_find_free_adapters(int base, int nr) ...@@ -158,6 +152,16 @@ static int diva_find_free_adapters(int base, int nr)
return (0); return (0);
} }
static diva_os_xdi_adapter_t *diva_q_get_next(struct list_head * what)
{
diva_os_xdi_adapter_t *a = NULL;
if (what && !list_empty(what))
a = list_entry(what->next, diva_os_xdi_adapter_t, link);
return(a);
}
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Add card to the card list Add card to the card list
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
...@@ -204,7 +208,7 @@ void *diva_driver_add_card(void *pdev, unsigned long CardOrdinal) ...@@ -204,7 +208,7 @@ void *diva_driver_add_card(void *pdev, unsigned long CardOrdinal)
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add card"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add card");
pa = pdiva; pa = pdiva;
for (j = 1; j < nr; j++) { /* slave adapters, if any */ for (j = 1; j < nr; j++) { /* slave adapters, if any */
pa = (diva_os_xdi_adapter_t *) diva_q_get_next(&pa->link); pa = diva_q_get_next(&pa->link);
if (pa && !pa->interface.cleanup_adapter_proc) { if (pa && !pa->interface.cleanup_adapter_proc) {
pa->controller = i + 1 + j; pa->controller = i + 1 + j;
pa->xdi_adapter.ANum = pa->controller; pa->xdi_adapter.ANum = pa->controller;
...@@ -246,7 +250,6 @@ void *diva_driver_add_card(void *pdev, unsigned long CardOrdinal) ...@@ -246,7 +250,6 @@ void *diva_driver_add_card(void *pdev, unsigned long CardOrdinal)
int divasa_xdi_driver_entry(void) int divasa_xdi_driver_entry(void)
{ {
diva_os_initialize_spin_lock(&adapter_lock, "adapter"); diva_os_initialize_spin_lock(&adapter_lock, "adapter");
diva_q_init(&adapter_queue);
memset(&IoAdapters[0], 0x00, sizeof(IoAdapters)); memset(&IoAdapters[0], 0x00, sizeof(IoAdapters));
diva_init_request_array(); diva_init_request_array();
...@@ -259,12 +262,14 @@ int divasa_xdi_driver_entry(void) ...@@ -259,12 +262,14 @@ int divasa_xdi_driver_entry(void)
static diva_os_xdi_adapter_t *get_and_remove_from_queue(void) static diva_os_xdi_adapter_t *get_and_remove_from_queue(void)
{ {
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
diva_os_xdi_adapter_t *a; diva_os_xdi_adapter_t *a = NULL;
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "driver_unload"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "driver_unload");
if ((a = (diva_os_xdi_adapter_t *) diva_q_get_head(&adapter_queue))) if (!list_empty(&adapter_queue)) {
diva_q_remove(&adapter_queue, &a->link); a = list_entry(adapter_queue.next, diva_os_xdi_adapter_t, link);
list_del(adapter_queue.next);
}
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "driver_unload"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "driver_unload");
return (a); return (a);
...@@ -286,7 +291,7 @@ void diva_driver_remove_card(void *pdiva) ...@@ -286,7 +291,7 @@ void diva_driver_remove_card(void *pdiva)
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "remode adapter"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "remode adapter");
for (i = 1; i < 4; i++) { for (i = 1; i < 4; i++) {
if ((pa = (diva_os_xdi_adapter_t *) diva_q_get_next(&pa->link)) if ((pa = diva_q_get_next(&pa->link))
&& !pa->interface.cleanup_adapter_proc) { && !pa->interface.cleanup_adapter_proc) {
a[i] = pa; a[i] = pa;
} else { } else {
...@@ -295,7 +300,7 @@ void diva_driver_remove_card(void *pdiva) ...@@ -295,7 +300,7 @@ void diva_driver_remove_card(void *pdiva)
} }
for (i = 0; ((i < 4) && a[i]); i++) { for (i = 0; ((i < 4) && a[i]); i++) {
diva_q_remove(&adapter_queue, &a[i]->link); list_del(&a[i]->link);
} }
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "driver_unload"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "driver_unload");
...@@ -345,12 +350,12 @@ static void *divas_create_pci_card(int handle, void *pci_dev_handle) ...@@ -345,12 +350,12 @@ static void *divas_create_pci_card(int handle, void *pci_dev_handle)
numbers as master adapter numbers as master adapter
*/ */
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "found_pci_card"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "found_pci_card");
diva_q_add_tail(&adapter_queue, &a->link); list_add_tail(&a->link, &adapter_queue);
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "found_pci_card"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "found_pci_card");
if ((*(pI->init_card)) (a)) { if ((*(pI->init_card)) (a)) {
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "found_pci_card"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "found_pci_card");
diva_q_remove(&adapter_queue, &a->link); list_del(&a->link);
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "found_pci_card"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "found_pci_card");
diva_os_free(0, a); diva_os_free(0, a);
DBG_ERR(("A: can't get adapter resources")); DBG_ERR(("A: can't get adapter resources"));
...@@ -383,21 +388,14 @@ void divasa_xdi_driver_unload(void) ...@@ -383,21 +388,14 @@ void divasa_xdi_driver_unload(void)
/* /*
** Receive and process command from user mode utility ** Receive and process command from user mode utility
*/ */
static int cmp_adapter_nr(const void *what, const diva_entity_link_t * p)
{
diva_os_xdi_adapter_t *a = (diva_os_xdi_adapter_t *) p;
dword nr = (dword) (unsigned long) what;
return (nr != a->controller);
}
void *diva_xdi_open_adapter(void *os_handle, const void *src, void *diva_xdi_open_adapter(void *os_handle, const void *src,
int length, int length,
divas_xdi_copy_from_user_fn_t cp_fn) divas_xdi_copy_from_user_fn_t cp_fn)
{ {
diva_xdi_um_cfg_cmd_t msg; diva_xdi_um_cfg_cmd_t msg;
diva_os_xdi_adapter_t *a; diva_os_xdi_adapter_t *a = NULL;
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
struct list_head *tmp;
if (length < sizeof(diva_xdi_um_cfg_cmd_t)) { if (length < sizeof(diva_xdi_um_cfg_cmd_t)) {
DBG_ERR(("A: A(?) open, msg too small (%d < %d)", DBG_ERR(("A: A(?) open, msg too small (%d < %d)",
...@@ -409,10 +407,12 @@ void *diva_xdi_open_adapter(void *os_handle, const void *src, ...@@ -409,10 +407,12 @@ void *diva_xdi_open_adapter(void *os_handle, const void *src,
return (0); return (0);
} }
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "open_adapter"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "open_adapter");
a = (diva_os_xdi_adapter_t *) diva_q_find(&adapter_queue, list_for_each(tmp, &adapter_queue) {
(void *) (unsigned long) a = list_entry(tmp, diva_os_xdi_adapter_t, link);
msg.adapter, if (a->controller == (int)msg.adapter)
cmp_adapter_nr); break;
a = NULL;
}
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "open_adapter"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "open_adapter");
if (!a) { if (!a) {
...@@ -611,7 +611,7 @@ void diva_add_slave_adapter(diva_os_xdi_adapter_t * a) ...@@ -611,7 +611,7 @@ void diva_add_slave_adapter(diva_os_xdi_adapter_t * a)
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add_slave"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "add_slave");
diva_q_add_tail(&adapter_queue, &a->link); list_add_tail(&a->link, &adapter_queue);
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "add_slave"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "add_slave");
} }
......
/* $Id: divasmain.c,v 1.51 2004/03/20 20:47:08 armin Exp $ /* $Id: divasmain.c,v 1.52 2004/03/21 17:26:01 armin Exp $
* *
* Low level driver for Eicon DIVA Server ISDN cards. * Low level driver for Eicon DIVA Server ISDN cards.
* *
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/list.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/kmod.h> #include <linux/kmod.h>
...@@ -29,7 +30,6 @@ ...@@ -29,7 +30,6 @@
#undef ID_MASK #undef ID_MASK
#undef N_DATA #undef N_DATA
#include "pc.h" #include "pc.h"
#include "dlist.h"
#include "di_defs.h" #include "di_defs.h"
#include "divasync.h" #include "divasync.h"
#include "diva.h" #include "diva.h"
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "diva_dma.h" #include "diva_dma.h"
#include "diva_pci.h" #include "diva_pci.h"
static char *main_revision = "$Revision: 1.51 $"; static char *main_revision = "$Revision: 1.52 $";
static int major; static int major;
......
/* $Id: divasproc.c,v 1.18 2003/09/09 06:46:29 schindler Exp $ /* $Id: divasproc.c,v 1.19 2004/03/21 17:26:01 armin Exp $
* *
* Low level driver for Eicon DIVA Server ISDN cards. * Low level driver for Eicon DIVA Server ISDN cards.
* /proc functions * /proc functions
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/poll.h> #include <linux/poll.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/list.h>
#include "platform.h" #include "platform.h"
#include "debuglib.h" #include "debuglib.h"
#include "dlist.h"
#undef ID_MASK #undef ID_MASK
#undef N_DATA #undef N_DATA
#include "pc.h" #include "pc.h"
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
extern PISDN_ADAPTER IoAdapters[MAX_ADAPTER]; extern PISDN_ADAPTER IoAdapters[MAX_ADAPTER];
extern diva_entity_queue_t adapter_queue;
extern void divas_get_version(char *); extern void divas_get_version(char *);
extern void diva_get_vserial_number(PISDN_ADAPTER IoAdapter, char *buf); extern void diva_get_vserial_number(PISDN_ADAPTER IoAdapter, char *buf);
......
/* $Id: dlist.c,v 1.6 2003/08/25 16:03:35 schindler Exp $ */
#include "platform.h"
#include "dlist.h"
/*
** Initialize linked list
*/
static void diva_q_init(diva_entity_queue_t * q)
{
memset(q, 0x00, sizeof(*q));
}
/*
** Remove element from linked list
*/
static void diva_q_remove(diva_entity_queue_t * q, diva_entity_link_t * what)
{
if (!what->prev) {
if ((q->head = what->next)) {
q->head->prev = 0;
} else {
q->tail = 0;
}
} else if (!what->next) {
q->tail = what->prev;
q->tail->next = 0;
} else {
what->prev->next = what->next;
what->next->prev = what->prev;
}
what->prev = what->next = 0;
}
/*
** Add element to the tail of linked list
*/
static void diva_q_add_tail(diva_entity_queue_t * q, diva_entity_link_t * what)
{
what->next = 0;
if (!q->head) {
what->prev = 0;
q->head = q->tail = what;
} else {
what->prev = q->tail;
q->tail->next = what;
q->tail = what;
}
}
static diva_entity_link_t *diva_q_find(const diva_entity_queue_t * q,
const void *what, diva_q_cmp_fn_t cmp_fn)
{
diva_entity_link_t *diva_current = q->head;
while (diva_current) {
if (!(*cmp_fn) (what, diva_current)) {
break;
}
diva_current = diva_current->next;
}
return (diva_current);
}
static diva_entity_link_t *diva_q_get_head(diva_entity_queue_t * q)
{
return (q->head);
}
static diva_entity_link_t *diva_q_get_next(diva_entity_link_t * what)
{
return ((what) ? what->next : 0);
}
/* $Id: dlist.h,v 1.5 2003/08/25 16:03:35 schindler Exp $ */
#ifndef __DIVA_LINK_H__
#define __DIVA_LINK_H__
struct _diva_entity_link;
typedef struct _diva_entity_link {
struct _diva_entity_link *prev;
struct _diva_entity_link *next;
} diva_entity_link_t;
typedef struct _diva_entity_queue {
diva_entity_link_t *head;
diva_entity_link_t *tail;
} diva_entity_queue_t;
typedef int (*diva_q_cmp_fn_t) (const void *what,
const diva_entity_link_t *);
#endif
/* $Id: entity.h,v 1.1.2.1 2001/02/08 12:25:43 armin Exp $ */ /* $Id: entity.h,v 1.4 2004/03/21 17:26:01 armin Exp $ */
#ifndef __DIVAS_USER_MODE_IDI_ENTITY__ #ifndef __DIVAS_USER_MODE_IDI_ENTITY__
#define __DIVAS_USER_MODE_IDI_ENTITY__ #define __DIVAS_USER_MODE_IDI_ENTITY__
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define DIVA_UM_IDI_ASSIGN_PENDING 0x00000010 #define DIVA_UM_IDI_ASSIGN_PENDING 0x00000010
typedef struct _divas_um_idi_entity { typedef struct _divas_um_idi_entity {
diva_entity_link_t link; /* should be first */ struct list_head link;
diva_um_idi_adapter_t* adapter; /* Back to adapter */ diva_um_idi_adapter_t* adapter; /* Back to adapter */
ENTITY e; ENTITY e;
void* os_ref; void* os_ref;
......
/* $Id: idifunc.c,v 1.13 2003/08/25 14:49:53 schindler Exp $ /* $Id: idifunc.c,v 1.14 2004/03/21 18:13:43 armin Exp $
* *
* Driver for Eicon DIVA Server ISDN cards. * Driver for Eicon DIVA Server ISDN cards.
* User Mode IDI Interface * User Mode IDI Interface
...@@ -49,75 +49,36 @@ static void stop_dbg(void) ...@@ -49,75 +49,36 @@ static void stop_dbg(void)
} }
typedef struct _udiva_card { typedef struct _udiva_card {
struct _udiva_card *next; struct list_head list;
int Id; int Id;
DESCRIPTOR d; DESCRIPTOR d;
} udiva_card; } udiva_card;
static udiva_card *cards; static LIST_HEAD(cards);
static diva_os_spin_lock_t ll_lock; static diva_os_spin_lock_t ll_lock;
/*
* add card to list
*/
static void add_card_to_list(udiva_card * c)
{
diva_os_spin_lock_magic_t old_irql;
diva_os_enter_spin_lock(&ll_lock, &old_irql, "add card");
c->next = cards;
cards = c;
diva_os_leave_spin_lock(&ll_lock, &old_irql, "add card");
}
/* /*
* find card in list * find card in list
*/ */
static udiva_card *find_card_in_list(DESCRIPTOR * d) static udiva_card *find_card_in_list(DESCRIPTOR * d)
{ {
udiva_card *card; udiva_card *card;
struct list_head *tmp;
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
diva_os_enter_spin_lock(&ll_lock, &old_irql, "find card"); diva_os_enter_spin_lock(&ll_lock, &old_irql, "find card");
card = cards; list_for_each(tmp, &cards) {
while (card) { card = list_entry(tmp, udiva_card, list);
if (card->d.request == d->request) { if (card->d.request == d->request) {
diva_os_leave_spin_lock(&ll_lock, &old_irql, diva_os_leave_spin_lock(&ll_lock, &old_irql,
"find card"); "find card");
return (card); return (card);
} }
card = card->next;
} }
diva_os_leave_spin_lock(&ll_lock, &old_irql, "find card"); diva_os_leave_spin_lock(&ll_lock, &old_irql, "find card");
return ((udiva_card *) NULL); return ((udiva_card *) NULL);
} }
/*
* remove card from list
*/
static void remove_card_from_list(udiva_card * c)
{
udiva_card *list = NULL, *last;
diva_os_spin_lock_magic_t old_irql;
diva_os_enter_spin_lock(&ll_lock, &old_irql, "remove card");
list = cards;
last = list;
while (list) {
if (list == c) {
if (cards == c) {
cards = c->next;
} else {
last->next = c->next;
}
break;
}
last = list;
list = list->next;
}
diva_os_leave_spin_lock(&ll_lock, &old_irql, "remove card");
}
/* /*
* new card * new card
*/ */
...@@ -126,6 +87,7 @@ static void um_new_card(DESCRIPTOR * d) ...@@ -126,6 +87,7 @@ static void um_new_card(DESCRIPTOR * d)
int adapter_nr = 0; int adapter_nr = 0;
udiva_card *card = NULL; udiva_card *card = NULL;
IDI_SYNC_REQ sync_req; IDI_SYNC_REQ sync_req;
diva_os_spin_lock_magic_t old_irql;
if (!(card = diva_os_malloc(0, sizeof(udiva_card)))) { if (!(card = diva_os_malloc(0, sizeof(udiva_card)))) {
DBG_ERR(("cannot get buffer for card")); DBG_ERR(("cannot get buffer for card"));
...@@ -140,7 +102,9 @@ static void um_new_card(DESCRIPTOR * d) ...@@ -140,7 +102,9 @@ static void um_new_card(DESCRIPTOR * d)
sync_req.xdi_logical_adapter_number.info.logical_adapter_number; sync_req.xdi_logical_adapter_number.info.logical_adapter_number;
card->Id = adapter_nr; card->Id = adapter_nr;
if (!(diva_user_mode_idi_create_adapter(d, adapter_nr))) { if (!(diva_user_mode_idi_create_adapter(d, adapter_nr))) {
add_card_to_list(card); diva_os_enter_spin_lock(&ll_lock, &old_irql, "add card");
list_add_tail(&card->list, &cards);
diva_os_leave_spin_lock(&ll_lock, &old_irql, "add card");
} else { } else {
DBG_ERR(("could not create user mode idi card %d", DBG_ERR(("could not create user mode idi card %d",
adapter_nr)); adapter_nr));
...@@ -152,6 +116,7 @@ static void um_new_card(DESCRIPTOR * d) ...@@ -152,6 +116,7 @@ static void um_new_card(DESCRIPTOR * d)
*/ */
static void um_remove_card(DESCRIPTOR * d) static void um_remove_card(DESCRIPTOR * d)
{ {
diva_os_spin_lock_magic_t old_irql;
udiva_card *card = NULL; udiva_card *card = NULL;
if (!(card = find_card_in_list(d))) { if (!(card = find_card_in_list(d))) {
...@@ -159,7 +124,9 @@ static void um_remove_card(DESCRIPTOR * d) ...@@ -159,7 +124,9 @@ static void um_remove_card(DESCRIPTOR * d)
return; return;
} }
diva_user_mode_idi_remove_adapter(card->Id); diva_user_mode_idi_remove_adapter(card->Id);
remove_card_from_list(card); diva_os_enter_spin_lock(&ll_lock, &old_irql, "remove card");
list_del(&card->list);
diva_os_leave_spin_lock(&ll_lock, &old_irql, "remove card");
DBG_LOG(("idi proc entry removed for card %d", card->Id)); DBG_LOG(("idi proc entry removed for card %d", card->Id));
diva_os_free(0, card); diva_os_free(0, card);
} }
...@@ -169,20 +136,20 @@ static void um_remove_card(DESCRIPTOR * d) ...@@ -169,20 +136,20 @@ static void um_remove_card(DESCRIPTOR * d)
*/ */
static void DIVA_EXIT_FUNCTION remove_all_idi_proc(void) static void DIVA_EXIT_FUNCTION remove_all_idi_proc(void)
{ {
udiva_card *card, *last; udiva_card *card;
struct list_head *tmp;
diva_os_spin_lock_magic_t old_irql; diva_os_spin_lock_magic_t old_irql;
rescan:
diva_os_enter_spin_lock(&ll_lock, &old_irql, "remove all"); diva_os_enter_spin_lock(&ll_lock, &old_irql, "remove all");
card = cards; list_for_each(tmp, &cards) {
cards = NULL; card = list_entry(tmp, udiva_card, list);
diva_os_leave_spin_lock(&ll_lock, &old_irql, "remove all"); diva_os_leave_spin_lock(&ll_lock, &old_irql, "remove all");
while (card) {
diva_user_mode_idi_remove_adapter(card->Id); diva_user_mode_idi_remove_adapter(card->Id);
last = card; diva_os_free(0, card);
card = card->next; goto rescan;
diva_os_free(0, last);
} }
diva_os_leave_spin_lock(&ll_lock, &old_irql, "remove all");
} }
/* /*
......
/* $Id: os_4bri.c,v 1.25 2003/06/21 17:08:44 schindler Exp $ */ /* $Id: os_4bri.c,v 1.28 2004/03/21 17:26:01 armin Exp $ */
#include "platform.h" #include "platform.h"
#include "debuglib.h" #include "debuglib.h"
#include "cardtype.h" #include "cardtype.h"
#include "dlist.h"
#include "pc.h" #include "pc.h"
#include "pr_pc.h" #include "pr_pc.h"
#include "di_defs.h" #include "di_defs.h"
......
/* $Id: os_bri.c,v 1.18 2003/06/21 17:10:29 schindler Exp $ */ /* $Id: os_bri.c,v 1.21 2004/03/21 17:26:01 armin Exp $ */
#include "platform.h" #include "platform.h"
#include "debuglib.h" #include "debuglib.h"
#include "cardtype.h" #include "cardtype.h"
#include "dlist.h"
#include "pc.h" #include "pc.h"
#include "pr_pc.h" #include "pr_pc.h"
#include "di_defs.h" #include "di_defs.h"
......
/* $Id: os_pri.c,v 1.29 2003/08/25 13:41:27 schindler Exp $ */ /* $Id: os_pri.c,v 1.32 2004/03/21 17:26:01 armin Exp $ */
#include "platform.h" #include "platform.h"
#include "debuglib.h" #include "debuglib.h"
#include "cardtype.h" #include "cardtype.h"
#include "dlist.h"
#include "pc.h" #include "pc.h"
#include "pr_pc.h" #include "pr_pc.h"
#include "di_defs.h" #include "di_defs.h"
......
/* $Id: um_idi.c,v 1.12 2004/01/12 18:00:09 armin Exp $ */ /* $Id: um_idi.c,v 1.14 2004/03/21 17:54:37 armin Exp $ */
#include "platform.h" #include "platform.h"
#include "di_defs.h" #include "di_defs.h"
#include "pc.h" #include "pc.h"
#include "dlist.h"
#include "dqueue.h" #include "dqueue.h"
#include "adapter.h" #include "adapter.h"
#include "entity.h" #include "entity.h"
...@@ -22,7 +21,7 @@ extern void diva_os_wakeup_close(void *os_context); ...@@ -22,7 +21,7 @@ extern void diva_os_wakeup_close(void *os_context);
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
LOCALS LOCALS
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
static diva_entity_queue_t adapter_q; static LIST_HEAD(adapter_q);
static diva_os_spin_lock_t adapter_lock; static diva_os_spin_lock_t adapter_lock;
static diva_um_idi_adapter_t *diva_um_idi_find_adapter(dword nr); static diva_um_idi_adapter_t *diva_um_idi_find_adapter(dword nr);
...@@ -37,17 +36,11 @@ static int process_idi_rc(divas_um_idi_entity_t * e, byte rc); ...@@ -37,17 +36,11 @@ static int process_idi_rc(divas_um_idi_entity_t * e, byte rc);
static int process_idi_ind(divas_um_idi_entity_t * e, byte ind); static int process_idi_ind(divas_um_idi_entity_t * e, byte ind);
static int write_return_code(divas_um_idi_entity_t * e, byte rc); static int write_return_code(divas_um_idi_entity_t * e, byte rc);
/*
* include queue functions
*/
#include "dlist.c"
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
MAIN MAIN
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
int diva_user_mode_idi_init(void) int diva_user_mode_idi_init(void)
{ {
diva_q_init(&adapter_q);
diva_os_initialize_spin_lock(&adapter_lock, "adapter"); diva_os_initialize_spin_lock(&adapter_lock, "adapter");
return (0); return (0);
} }
...@@ -89,18 +82,18 @@ diva_user_mode_idi_adapter_features(diva_um_idi_adapter_t * a, ...@@ -89,18 +82,18 @@ diva_user_mode_idi_adapter_features(diva_um_idi_adapter_t * a,
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
void diva_user_mode_idi_remove_adapter(int adapter_nr) void diva_user_mode_idi_remove_adapter(int adapter_nr)
{ {
diva_um_idi_adapter_t *a = struct list_head *tmp;
(diva_um_idi_adapter_t *) diva_q_get_head(&adapter_q); diva_um_idi_adapter_t *a;
while (a) { list_for_each(tmp, &adapter_q) {
a = list_entry(tmp, diva_um_idi_adapter_t, link);
if (a->adapter_nr == adapter_nr) { if (a->adapter_nr == adapter_nr) {
diva_q_remove(&adapter_q, &a->link); list_del(tmp);
cleanup_adapter(a); cleanup_adapter(a);
DBG_LOG(("DIDD: del adapter(%d)", a->adapter_nr)); DBG_LOG(("DIDD: del adapter(%d)", a->adapter_nr));
diva_os_free(0, a); diva_os_free(0, a);
break; break;
} }
a = (diva_um_idi_adapter_t *) diva_q_get_next(&a->link);
} }
} }
...@@ -109,15 +102,15 @@ void diva_user_mode_idi_remove_adapter(int adapter_nr) ...@@ -109,15 +102,15 @@ void diva_user_mode_idi_remove_adapter(int adapter_nr)
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
void diva_user_mode_idi_finit(void) void diva_user_mode_idi_finit(void)
{ {
diva_um_idi_adapter_t *a = struct list_head *tmp, *safe;
(diva_um_idi_adapter_t *) diva_q_get_head(&adapter_q); diva_um_idi_adapter_t *a;
while (a) { list_for_each_safe(tmp, safe, &adapter_q) {
diva_q_remove(&adapter_q, &a->link); a = list_entry(tmp, diva_um_idi_adapter_t, link);
list_del(tmp);
cleanup_adapter(a); cleanup_adapter(a);
DBG_LOG(("DIDD: del adapter(%d)", a->adapter_nr)); DBG_LOG(("DIDD: del adapter(%d)", a->adapter_nr));
diva_os_free(0, a); diva_os_free(0, a);
a = (diva_um_idi_adapter_t *) diva_q_get_head(&adapter_q);
} }
diva_os_destroy_spin_lock(&adapter_lock, "adapter"); diva_os_destroy_spin_lock(&adapter_lock, "adapter");
} }
...@@ -137,6 +130,7 @@ int diva_user_mode_idi_create_adapter(const DESCRIPTOR * d, int adapter_nr) ...@@ -137,6 +130,7 @@ int diva_user_mode_idi_create_adapter(const DESCRIPTOR * d, int adapter_nr)
return (-1); return (-1);
} }
memset(a, 0x00, sizeof(*a)); memset(a, 0x00, sizeof(*a));
INIT_LIST_HEAD(&a->entity_q);
a->d = *d; a->d = *d;
a->adapter_nr = adapter_nr; a->adapter_nr = adapter_nr;
...@@ -145,46 +139,27 @@ int diva_user_mode_idi_create_adapter(const DESCRIPTOR * d, int adapter_nr) ...@@ -145,46 +139,27 @@ int diva_user_mode_idi_create_adapter(const DESCRIPTOR * d, int adapter_nr)
adapter_nr, a->d.type, a->d.features, a->d.channels)); adapter_nr, a->d.type, a->d.features, a->d.channels));
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "create_adapter"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "create_adapter");
diva_q_add_tail(&adapter_q, &a->link); list_add_tail(&a->link, &adapter_q);
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "create_adapter"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "create_adapter");
return (0); return (0);
} }
static int cmp_adapter_nr(const void *what, const diva_entity_link_t * p)
{
diva_um_idi_adapter_t *a = (diva_um_idi_adapter_t *) p;
dword nr = (dword) (unsigned long) what;
DBG_TRC(("find_adapter: (%d)-(%d)", nr, a->adapter_nr));
return (nr != a->adapter_nr);
}
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
Find adapter by Adapter number Find adapter by Adapter number
------------------------------------------------------------------------ */ ------------------------------------------------------------------------ */
static diva_um_idi_adapter_t *diva_um_idi_find_adapter(dword nr) static diva_um_idi_adapter_t *diva_um_idi_find_adapter(dword nr)
{ {
return (diva_um_idi_adapter_t *) diva_q_find(&adapter_q, diva_um_idi_adapter_t *a = NULL;
(void *) (unsigned struct list_head *tmp;
long) nr,
cmp_adapter_nr);
}
/* ------------------------------------------------------------------------
Return number of adapters in system
------------------------------------------------------------------------ */
int diva_um_idi_nr_of_adapters(void)
{
int i = 0;
const diva_entity_queue_t * q = &adapter_q;
const diva_entity_link_t *diva_current = q->head;
while (diva_current) { list_for_each(tmp, &adapter_q) {
i++; a = list_entry(tmp, diva_um_idi_adapter_t, link);
diva_current = diva_current->next; DBG_TRC(("find_adapter: (%d)-(%d)", nr, a->adapter_nr));
if (a->adapter_nr == (int)nr)
break;
a = NULL;
} }
return(i); return(a);
} }
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
...@@ -193,17 +168,17 @@ int diva_um_idi_nr_of_adapters(void) ...@@ -193,17 +168,17 @@ int diva_um_idi_nr_of_adapters(void)
------------------------------------------------------------------------ */ ------------------------------------------------------------------------ */
static void cleanup_adapter(diva_um_idi_adapter_t * a) static void cleanup_adapter(diva_um_idi_adapter_t * a)
{ {
divas_um_idi_entity_t *e = struct list_head *tmp, *safe;
(divas_um_idi_entity_t *) diva_q_get_head(&a->entity_q); divas_um_idi_entity_t *e;
while (e) { list_for_each_safe(tmp, safe, &a->entity_q) {
diva_q_remove(&a->entity_q, &e->link); e = list_entry(tmp, divas_um_idi_entity_t, link);
list_del(tmp);
cleanup_entity(e); cleanup_entity(e);
if (e->os_context) { if (e->os_context) {
diva_os_wakeup_read(e->os_context); diva_os_wakeup_read(e->os_context);
diva_os_wakeup_close(e->os_context); diva_os_wakeup_close(e->os_context);
} }
e = (divas_um_idi_entity_t *) diva_q_get_head(&a->entity_q);
} }
memset(&a->d, 0x00, sizeof(DESCRIPTOR)); memset(&a->d, 0x00, sizeof(DESCRIPTOR));
} }
...@@ -281,7 +256,7 @@ void *divas_um_idi_create_entity(dword adapter_nr, void *file) ...@@ -281,7 +256,7 @@ void *divas_um_idi_create_entity(dword adapter_nr, void *file)
e->os_ref = file; /* link to os handle */ e->os_ref = file; /* link to os handle */
e->adapter = a; /* link to adapter */ e->adapter = a; /* link to adapter */
diva_q_add_tail(&a->entity_q, &e->link); /* link from adapter */ list_add_tail(&e->link, &a->entity_q); /* link from adapter */
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "create_entity"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "create_entity");
...@@ -305,7 +280,7 @@ int divas_um_idi_delete_entity(int adapter_nr, void *entity) ...@@ -305,7 +280,7 @@ int divas_um_idi_delete_entity(int adapter_nr, void *entity)
diva_os_enter_spin_lock(&adapter_lock, &old_irql, "delete_entity"); diva_os_enter_spin_lock(&adapter_lock, &old_irql, "delete_entity");
if ((a = e->adapter)) { if ((a = e->adapter)) {
diva_q_remove(&a->entity_q, &e->link); list_del(&e->link);
} }
diva_os_leave_spin_lock(&adapter_lock, &old_irql, "delete_entity"); diva_os_leave_spin_lock(&adapter_lock, &old_irql, "delete_entity");
......
/* $Id: um_idi.h,v 1.1.2.2 2002/10/02 14:38:38 armin Exp $ */ /* $Id: um_idi.h,v 1.6 2004/03/21 17:26:01 armin Exp $ */
#ifndef __DIVA_USER_MODE_IDI_CORE_H__ #ifndef __DIVA_USER_MODE_IDI_CORE_H__
#define __DIVA_USER_MODE_IDI_CORE_H__ #define __DIVA_USER_MODE_IDI_CORE_H__
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
*/ */
int diva_user_mode_idi_init(void); int diva_user_mode_idi_init(void);
void diva_user_mode_idi_finit(void); void diva_user_mode_idi_finit(void);
int diva_um_idi_nr_of_adapters(void);
void *divas_um_idi_create_entity(dword adapter_nr, void *file); void *divas_um_idi_create_entity(dword adapter_nr, void *file);
int divas_um_idi_delete_entity(int adapter_nr, void *entity); int divas_um_idi_delete_entity(int adapter_nr, void *entity);
......
/* $Id: xdi_adapter.h,v 1.6 2003/12/05 18:45:05 armin Exp $ */ /* $Id: xdi_adapter.h,v 1.7 2004/03/21 17:26:01 armin Exp $ */
#ifndef __DIVA_OS_XDI_ADAPTER_H__ #ifndef __DIVA_OS_XDI_ADAPTER_H__
#define __DIVA_OS_XDI_ADAPTER_H__ #define __DIVA_OS_XDI_ADAPTER_H__
...@@ -47,7 +47,7 @@ typedef struct _diva_os_idi_adapter_interface { ...@@ -47,7 +47,7 @@ typedef struct _diva_os_idi_adapter_interface {
} diva_os_idi_adapter_interface_t; } diva_os_idi_adapter_interface_t;
typedef struct _diva_os_xdi_adapter { typedef struct _diva_os_xdi_adapter {
diva_entity_link_t link; struct list_head link;
int CardIndex; int CardIndex;
int CardOrdinal; int CardOrdinal;
int controller; /* number of this controller */ int controller; /* number of this controller */
......
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