[PATCH] isdn4linux: Siemens Gigaset base driver: fix disconnect handling
[safe/jmp/linux-2.6] / drivers / isdn / gigaset / gigaset.h
index d77588d..22b9693 100644 (file)
@@ -2,7 +2,7 @@
  * Siemens Gigaset 307x driver
  * Common header file for all connection variants
  *
- * Written by Stefan Eilers <Eilers.Stefan@epost.de>
+ * Written by Stefan Eilers
  *        and Hansjoerg Lipp <hjlipp@web.de>
  *
  * =====================================================================
@@ -55,9 +55,6 @@
 #define GIG_RETRYCID
 #define GIG_X75
 
-#define MAX_TIMER_INDEX 1000
-#define MAX_SEQ_INDEX   1000
-
 #define GIG_TICK 100           /* in milliseconds */
 
 /* timeout values (unit: 1 sec) */
 
 #define MAXACT 3
 
-#define IFNULL(a) \
-       if (unlikely(!(a)))
-
-#define IFNULLRET(a) \
-       if (unlikely(!(a))) { \
-               err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
-               return; \
-       }
-
-#define IFNULLRETVAL(a,b) \
-       if (unlikely(!(a))) { \
-               err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
-               return (b); \
-       }
-
-#define IFNULLCONT(a) \
-       if (unlikely(!(a))) { \
-               err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
-               continue; \
-       }
-
-#define IFNULLGOTO(a,b) \
-       if (unlikely(!(a))) { \
-               err("%s==NULL at %s:%d!", #a, __FILE__, __LINE__); \
-               goto b; \
-       }
-
 extern int gigaset_debuglevel; /* "needs" cast to (enum debuglevel) */
 
 /* any combination of these can be given with the 'debug=' parameter to insmod,
  * e.g. 'insmod usb_gigaset.o debug=0x2c' will set DEBUG_OPEN, DEBUG_CMD and
  * DEBUG_INTR.
  */
-enum debuglevel { /* up to 24 bits (atomic_t) */
+enum debuglevel {
        DEBUG_REG         = 0x0002, /* serial port I/O register operations */
        DEBUG_OPEN        = 0x0004, /* open/close serial port */
        DEBUG_INTR        = 0x0008, /* interrupt processing */
@@ -171,7 +141,7 @@ enum debuglevel { /* up to 24 bits (atomic_t) */
                        printk(KERN_DEBUG KBUILD_MODNAME ": " format "\n", \
                               ## arg); \
        } while (0)
-#define DEBUG_DEFAULT (DEBUG_INIT | DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
+#define DEBUG_DEFAULT (DEBUG_TRANSCMD | DEBUG_CMD | DEBUG_USBREQ)
 
 #else
 
@@ -181,7 +151,7 @@ enum debuglevel { /* up to 24 bits (atomic_t) */
 #endif
 
 void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
-                       size_t len, const unsigned char *buf, int from_user);
+                       size_t len, const unsigned char *buf);
 
 /* connection state */
 #define ZSAU_NONE                      0
@@ -402,7 +372,7 @@ struct at_state_t {
        struct list_head        list;
        int                     waiting;
        int                     getstring;
-       atomic_t                timer_index;
+       unsigned                timer_index;
        unsigned long           timer_expires;
        int                     timer_active;
        unsigned int            ConState;       /* State of connection */
@@ -411,7 +381,7 @@ struct at_state_t {
        int                     int_var[VAR_NUM];       /* see VAR_XXXX */
        char                    *str_var[STR_NUM];      /* see STR_XXXX */
        unsigned                pending_commands;       /* see PC_XXXX */
-       atomic_t                seq_index;
+       unsigned                seq_index;
 
        struct cardstate        *cs;
        struct bc_state         *bcs;
@@ -511,10 +481,11 @@ struct cardstate {
        unsigned fwver[4];
        int gotfwver;
 
-       atomic_t running;               /* !=0 if events are handled */
-       atomic_t connected;             /* !=0 if hardware is connected */
+       unsigned running;               /* !=0 if events are handled */
+       unsigned connected;             /* !=0 if hardware is connected */
+       unsigned isdn_up;               /* !=0 after ISDN_STAT_RUN */
 
-       atomic_t cidmode;
+       unsigned cidmode;
 
        int myid;                       /* id for communication with LL */
        isdn_if iif;
@@ -524,7 +495,7 @@ struct cardstate {
        int cs_init;
        int ignoreframes;               /* frames to ignore after setting up the
                                           B channel */
-       struct semaphore sem;           /* locks this structure:
+       struct mutex mutex;             /* locks this structure:
                                         *   connected is not changed,
                                         *   hardware_up is not changed,
                                         *   MState is not changed to or from
@@ -555,7 +526,7 @@ struct cardstate {
 
        /* event queue */
        struct event_t events[MAX_EVENTS];
-       atomic_t ev_tail, ev_head;
+       unsigned ev_tail, ev_head;
        spinlock_t ev_lock;
 
        /* current modem response */
@@ -656,8 +627,7 @@ struct gigaset_ops {
        /* Called by gigaset_freecs() for freeing bcs->hw.xxx */
        int (*freebcshw)(struct bc_state *bcs);
 
-       /* Called by gigaset_stop() or gigaset_bchannel_down() for resetting
-          bcs->hw.xxx */
+       /* Called by gigaset_bchannel_down() for resetting bcs->hw.xxx */
        void (*reinitbcshw)(struct bc_state *bcs);
 
        /* Called by gigaset_initcs() for setting up cs->hw.xxx */
@@ -778,8 +748,8 @@ void gigaset_handle_modem_response(struct cardstate *cs);
  */
 
 /* initialize sysfs for device */
-void gigaset_init_dev_sysfs(struct usb_interface *interface);
-void gigaset_free_dev_sysfs(struct usb_interface *interface);
+void gigaset_init_dev_sysfs(struct cardstate *cs);
+void gigaset_free_dev_sysfs(struct cardstate *cs);
 
 /* ===========================================================================
  *  Functions implemented in common.c/gigaset.h
@@ -805,7 +775,6 @@ struct gigaset_driver *gigaset_initdriver(unsigned minor, unsigned minors,
 /* Deallocate driver structure. */
 void gigaset_freedriver(struct gigaset_driver *drv);
 void gigaset_debugdrivers(void);
-struct cardstate *gigaset_get_cs_by_minor(unsigned minor);
 struct cardstate *gigaset_get_cs_by_tty(struct tty_struct *tty);
 struct cardstate *gigaset_get_cs_by_id(int id);
 
@@ -851,7 +820,7 @@ static inline void gigaset_schedule_event(struct cardstate *cs)
 {
        unsigned long flags;
        spin_lock_irqsave(&cs->lock, flags);
-       if (atomic_read(&cs->running))
+       if (cs->running)
                tasklet_schedule(&cs->event_tasklet);
        spin_unlock_irqrestore(&cs->lock, flags);
 }
@@ -879,23 +848,6 @@ static inline void gigaset_bchannel_up(struct bc_state *bcs)
 /* handling routines for sk_buff */
 /* ============================= */
 
-/* private version of __skb_put()
- * append 'len' bytes to the content of 'skb', already knowing that the
- * existing buffer can accomodate them
- * returns a pointer to the location where the new bytes should be copied to
- * This function does not take any locks so it must be called with the
- * appropriate locks held only.
- */
-static inline unsigned char *gigaset_skb_put_quick(struct sk_buff *skb,
-                                                  unsigned int len)
-{
-       unsigned char *tmp = skb->tail;
-       /*SKB_LINEAR_ASSERT(skb);*/             /* not needed here */
-       skb->tail += len;
-       skb->len += len;
-       return tmp;
-}
-
 /* pass received skb to LL
  * Warning: skb must not be accessed anymore!
  */
@@ -929,47 +881,9 @@ static inline void gigaset_rcv_error(struct sk_buff *procskb,
 /* bitwise byte inversion table */
 extern __u8 gigaset_invtab[];  /* in common.c */
 
-
 /* append received bytes to inbuf */
-static inline int gigaset_fill_inbuf(struct inbuf_t *inbuf,
-                                    const unsigned char *src,
-                                    unsigned numbytes)
-{
-       unsigned n, head, tail, bytesleft;
-
-       gig_dbg(DEBUG_INTR, "received %u bytes", numbytes);
-
-       if (!numbytes)
-               return 0;
-
-       bytesleft = numbytes;
-       tail = atomic_read(&inbuf->tail);
-       head = atomic_read(&inbuf->head);
-       gig_dbg(DEBUG_INTR, "buffer state: %u -> %u", head, tail);
-
-       while (bytesleft) {
-               if (head > tail)
-                       n = head - 1 - tail;
-               else if (head == 0)
-                       n = (RBUFSIZE-1) - tail;
-               else
-                       n = RBUFSIZE - tail;
-               if (!n) {
-                       dev_err(inbuf->cs->dev,
-                               "buffer overflow (%u bytes lost)", bytesleft);
-                       break;
-               }
-               if (n > bytesleft)
-                       n = bytesleft;
-               memcpy(inbuf->data + tail, src, n);
-               bytesleft -= n;
-               tail = (tail + n) % RBUFSIZE;
-               src += n;
-       }
-       gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
-       atomic_set(&inbuf->tail, tail);
-       return numbytes != bytesleft;
-}
+int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
+                      unsigned numbytes);
 
 /* ===========================================================================
  *  Functions implemented in interface.c