isdn_net.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* $Id: isdn_net.h,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
  2. *
  3. * header for Linux ISDN subsystem, network related functions (linklevel).
  4. *
  5. * Copyright 1994-1999 by Fritz Elfert (fritz@isdn4linux.de)
  6. * Copyright 1995,96 by Thinking Objects Software GmbH Wuerzburg
  7. * Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. /* Definitions for hupflags: */
  14. #define ISDN_WAITCHARGE 1 /* did not get a charge info yet */
  15. #define ISDN_HAVECHARGE 2 /* We know a charge info */
  16. #define ISDN_CHARGEHUP 4 /* We want to use the charge mechanism */
  17. #define ISDN_INHUP 8 /* Even if incoming, close after huptimeout */
  18. #define ISDN_MANCHARGE 16 /* Charge Interval manually set */
  19. /*
  20. * Definitions for Cisco-HDLC header.
  21. */
  22. #define CISCO_ADDR_UNICAST 0x0f
  23. #define CISCO_ADDR_BROADCAST 0x8f
  24. #define CISCO_CTRL 0x00
  25. #define CISCO_TYPE_CDP 0x2000
  26. #define CISCO_TYPE_SLARP 0x8035
  27. #define CISCO_SLARP_REQUEST 0
  28. #define CISCO_SLARP_REPLY 1
  29. #define CISCO_SLARP_KEEPALIVE 2
  30. extern char *isdn_net_new(char *, struct net_device *);
  31. extern char *isdn_net_newslave(char *);
  32. extern int isdn_net_rm(char *);
  33. extern int isdn_net_rmall(void);
  34. extern int isdn_net_stat_callback(int, isdn_ctrl *);
  35. extern int isdn_net_setcfg(isdn_net_ioctl_cfg *);
  36. extern int isdn_net_getcfg(isdn_net_ioctl_cfg *);
  37. extern int isdn_net_addphone(isdn_net_ioctl_phone *);
  38. extern int isdn_net_getphones(isdn_net_ioctl_phone *, char __user *);
  39. extern int isdn_net_getpeer(isdn_net_ioctl_phone *, isdn_net_ioctl_phone __user *);
  40. extern int isdn_net_delphone(isdn_net_ioctl_phone *);
  41. extern int isdn_net_find_icall(int, int, int, setup_parm *);
  42. extern void isdn_net_hangup(struct net_device *);
  43. extern void isdn_net_dial(void);
  44. extern void isdn_net_autohup(void);
  45. extern int isdn_net_force_hangup(char *);
  46. extern int isdn_net_force_dial(char *);
  47. extern isdn_net_dev *isdn_net_findif(char *);
  48. extern int isdn_net_rcv_skb(int, struct sk_buff *);
  49. extern int isdn_net_dial_req(isdn_net_local *);
  50. extern void isdn_net_writebuf_skb(isdn_net_local *lp, struct sk_buff *skb);
  51. extern void isdn_net_write_super(isdn_net_local *lp, struct sk_buff *skb);
  52. #define ISDN_NET_MAX_QUEUE_LENGTH 2
  53. #define ISDN_MASTER_PRIV(lp) ((isdn_net_local *) netdev_priv(lp->master))
  54. #define ISDN_SLAVE_PRIV(lp) ((isdn_net_local *) netdev_priv(lp->slave))
  55. #define MASTER_TO_SLAVE(master) \
  56. (((isdn_net_local *) netdev_priv(master))->slave)
  57. /*
  58. * is this particular channel busy?
  59. */
  60. static __inline__ int isdn_net_lp_busy(isdn_net_local *lp)
  61. {
  62. if (atomic_read(&lp->frame_cnt) < ISDN_NET_MAX_QUEUE_LENGTH)
  63. return 0;
  64. else
  65. return 1;
  66. }
  67. /*
  68. * For the given net device, this will get a non-busy channel out of the
  69. * corresponding bundle. The returned channel is locked.
  70. */
  71. static __inline__ isdn_net_local * isdn_net_get_locked_lp(isdn_net_dev *nd)
  72. {
  73. unsigned long flags;
  74. isdn_net_local *lp;
  75. spin_lock_irqsave(&nd->queue_lock, flags);
  76. lp = nd->queue; /* get lp on top of queue */
  77. while (isdn_net_lp_busy(nd->queue)) {
  78. nd->queue = nd->queue->next;
  79. if (nd->queue == lp) { /* not found -- should never happen */
  80. lp = NULL;
  81. goto errout;
  82. }
  83. }
  84. lp = nd->queue;
  85. nd->queue = nd->queue->next;
  86. spin_unlock_irqrestore(&nd->queue_lock, flags);
  87. spin_lock(&lp->xmit_lock);
  88. local_bh_disable();
  89. return lp;
  90. errout:
  91. spin_unlock_irqrestore(&nd->queue_lock, flags);
  92. return lp;
  93. }
  94. /*
  95. * add a channel to a bundle
  96. */
  97. static __inline__ void isdn_net_add_to_bundle(isdn_net_dev *nd, isdn_net_local *nlp)
  98. {
  99. isdn_net_local *lp;
  100. unsigned long flags;
  101. spin_lock_irqsave(&nd->queue_lock, flags);
  102. lp = nd->queue;
  103. // printk(KERN_DEBUG "%s: lp:%s(%p) nlp:%s(%p) last(%p)\n",
  104. // __func__, lp->name, lp, nlp->name, nlp, lp->last);
  105. nlp->last = lp->last;
  106. lp->last->next = nlp;
  107. lp->last = nlp;
  108. nlp->next = lp;
  109. nd->queue = nlp;
  110. spin_unlock_irqrestore(&nd->queue_lock, flags);
  111. }
  112. /*
  113. * remove a channel from the bundle it belongs to
  114. */
  115. static __inline__ void isdn_net_rm_from_bundle(isdn_net_local *lp)
  116. {
  117. isdn_net_local *master_lp = lp;
  118. unsigned long flags;
  119. if (lp->master)
  120. master_lp = ISDN_MASTER_PRIV(lp);
  121. // printk(KERN_DEBUG "%s: lp:%s(%p) mlp:%s(%p) last(%p) next(%p) mndq(%p)\n",
  122. // __func__, lp->name, lp, master_lp->name, master_lp, lp->last, lp->next, master_lp->netdev->queue);
  123. spin_lock_irqsave(&master_lp->netdev->queue_lock, flags);
  124. lp->last->next = lp->next;
  125. lp->next->last = lp->last;
  126. if (master_lp->netdev->queue == lp) {
  127. master_lp->netdev->queue = lp->next;
  128. if (lp->next == lp) { /* last in queue */
  129. master_lp->netdev->queue = master_lp->netdev->local;
  130. }
  131. }
  132. lp->next = lp->last = lp; /* (re)set own pointers */
  133. // printk(KERN_DEBUG "%s: mndq(%p)\n",
  134. // __func__, master_lp->netdev->queue);
  135. spin_unlock_irqrestore(&master_lp->netdev->queue_lock, flags);
  136. }