Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * IPACX specific routines |
| 4 | * |
| 5 | * Author Joerg Petersohn |
| 6 | * Derived from hisax_isac.c, isac.c, hscx.c and others |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This software may be used and distributed according to the terms |
| 9 | * of the GNU General Public License, incorporated herein by reference. |
| 10 | * |
| 11 | */ |
| 12 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include "hisax_if.h" |
| 16 | #include "hisax.h" |
| 17 | #include "isdnl1.h" |
| 18 | #include "ipacx.h" |
| 19 | |
| 20 | #define DBUSY_TIMER_VALUE 80 |
| 21 | #define TIMER3_VALUE 7000 |
| 22 | #define MAX_DFRAME_LEN_L1 300 |
| 23 | #define B_FIFO_SIZE 64 |
| 24 | #define D_FIFO_SIZE 32 |
| 25 | |
| 26 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 27 | // ipacx interrupt mask values |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #define _MASK_IMASK 0x2E // global mask |
| 29 | #define _MASKB_IMASK 0x0B |
| 30 | #define _MASKD_IMASK 0x03 // all on |
| 31 | |
| 32 | //---------------------------------------------------------- |
| 33 | // local function declarations |
| 34 | //---------------------------------------------------------- |
| 35 | static void ph_command(struct IsdnCardState *cs, unsigned int command); |
| 36 | static inline void cic_int(struct IsdnCardState *cs); |
| 37 | static void dch_l2l1(struct PStack *st, int pr, void *arg); |
| 38 | static void dbusy_timer_handler(struct IsdnCardState *cs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | static void dch_empty_fifo(struct IsdnCardState *cs, int count); |
| 40 | static void dch_fill_fifo(struct IsdnCardState *cs); |
| 41 | static inline void dch_int(struct IsdnCardState *cs); |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 42 | static void dch_setstack(struct PStack *st, struct IsdnCardState *cs); |
| 43 | static void dch_init(struct IsdnCardState *cs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | static void bch_l2l1(struct PStack *st, int pr, void *arg); |
| 45 | static void bch_empty_fifo(struct BCState *bcs, int count); |
| 46 | static void bch_fill_fifo(struct BCState *bcs); |
| 47 | static void bch_int(struct IsdnCardState *cs, u_char hscx); |
| 48 | static void bch_mode(struct BCState *bcs, int mode, int bc); |
| 49 | static void bch_close_state(struct BCState *bcs); |
| 50 | static int bch_open_state(struct IsdnCardState *cs, struct BCState *bcs); |
| 51 | static int bch_setstack(struct PStack *st, struct BCState *bcs); |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 52 | static void bch_init(struct IsdnCardState *cs, int hscx); |
| 53 | static void clear_pending_ints(struct IsdnCardState *cs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | //---------------------------------------------------------- |
| 56 | // Issue Layer 1 command to chip |
| 57 | //---------------------------------------------------------- |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 58 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | ph_command(struct IsdnCardState *cs, unsigned int command) |
| 60 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 61 | if (cs->debug & L1_DEB_ISAC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | debugl1(cs, "ph_command (%#x) in (%#x)", command, |
| 63 | cs->dc.isac.ph_state); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 64 | //################################### |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | // printk(KERN_INFO "ph_command (%#x)\n", command); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 66 | //################################### |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | cs->writeisac(cs, IPACX_CIX0, (command << 4) | 0x0E); |
| 68 | } |
| 69 | |
| 70 | //---------------------------------------------------------- |
| 71 | // Transceiver interrupt handler |
| 72 | //---------------------------------------------------------- |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 73 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | cic_int(struct IsdnCardState *cs) |
| 75 | { |
| 76 | u_char event; |
| 77 | |
| 78 | event = cs->readisac(cs, IPACX_CIR0) >> 4; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 79 | if (cs->debug & L1_DEB_ISAC) debugl1(cs, "cic_int(event=%#x)", event); |
| 80 | //######################################### |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | // printk(KERN_INFO "cic_int(%x)\n", event); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 82 | //######################################### |
| 83 | cs->dc.isac.ph_state = event; |
| 84 | schedule_event(cs, D_L1STATECHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | //========================================================== |
| 88 | // D channel functions |
| 89 | //========================================================== |
| 90 | |
| 91 | //---------------------------------------------------------- |
| 92 | // Command entry point |
| 93 | //---------------------------------------------------------- |
| 94 | static void |
| 95 | dch_l2l1(struct PStack *st, int pr, void *arg) |
| 96 | { |
| 97 | struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware; |
| 98 | struct sk_buff *skb = arg; |
David S. Miller | d462003 | 2011-04-17 16:40:30 -0700 | [diff] [blame] | 99 | u_char cda1_cr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | switch (pr) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 102 | case (PH_DATA | REQUEST): |
| 103 | if (cs->debug & DEB_DLOG_HEX) LogFrame(cs, skb->data, skb->len); |
| 104 | if (cs->debug & DEB_DLOG_VERBOSE) dlogframe(cs, skb, 0); |
| 105 | if (cs->tx_skb) { |
| 106 | skb_queue_tail(&cs->sq, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #ifdef L2FRAME_DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 108 | if (cs->debug & L1_DEB_LAPD) Logl2Frame(cs, skb, "PH_DATA Queued", 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 110 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | cs->tx_skb = skb; |
| 112 | cs->tx_cnt = 0; |
| 113 | #ifdef L2FRAME_DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 114 | if (cs->debug & L1_DEB_LAPD) Logl2Frame(cs, skb, "PH_DATA", 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #endif |
| 116 | dch_fill_fifo(cs); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 117 | } |
| 118 | break; |
| 119 | |
| 120 | case (PH_PULL | INDICATION): |
| 121 | if (cs->tx_skb) { |
| 122 | if (cs->debug & L1_DEB_WARN) |
| 123 | debugl1(cs, " l2l1 tx_skb exist this shouldn't happen"); |
| 124 | skb_queue_tail(&cs->sq, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 126 | } |
| 127 | if (cs->debug & DEB_DLOG_HEX) LogFrame(cs, skb->data, skb->len); |
| 128 | if (cs->debug & DEB_DLOG_VERBOSE) dlogframe(cs, skb, 0); |
| 129 | cs->tx_skb = skb; |
| 130 | cs->tx_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #ifdef L2FRAME_DEBUG |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 132 | if (cs->debug & L1_DEB_LAPD) Logl2Frame(cs, skb, "PH_DATA_PULLED", 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #endif |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 134 | dch_fill_fifo(cs); |
| 135 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 137 | case (PH_PULL | REQUEST): |
| 138 | #ifdef L2FRAME_DEBUG |
| 139 | if (cs->debug & L1_DEB_LAPD) debugl1(cs, "-> PH_REQUEST_PULL"); |
| 140 | #endif |
| 141 | if (!cs->tx_skb) { |
| 142 | clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags); |
| 143 | st->l1.l1l2(st, PH_PULL | CONFIRM, NULL); |
| 144 | } else |
| 145 | set_bit(FLG_L1_PULL_REQ, &st->l1.Flags); |
| 146 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 148 | case (HW_RESET | REQUEST): |
| 149 | case (HW_ENABLE | REQUEST): |
| 150 | if ((cs->dc.isac.ph_state == IPACX_IND_RES) || |
| 151 | (cs->dc.isac.ph_state == IPACX_IND_DR) || |
| 152 | (cs->dc.isac.ph_state == IPACX_IND_DC)) |
| 153 | ph_command(cs, IPACX_CMD_TIM); |
| 154 | else |
| 155 | ph_command(cs, IPACX_CMD_RES); |
| 156 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 158 | case (HW_INFO3 | REQUEST): |
| 159 | ph_command(cs, IPACX_CMD_AR8); |
| 160 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 162 | case (HW_TESTLOOP | REQUEST): |
| 163 | cs->writeisac(cs, IPACX_CDA_TSDP10, 0x80); // Timeslot 0 is B1 |
| 164 | cs->writeisac(cs, IPACX_CDA_TSDP11, 0x81); // Timeslot 0 is B1 |
| 165 | cda1_cr = cs->readisac(cs, IPACX_CDA1_CR); |
| 166 | (void) cs->readisac(cs, IPACX_CDA2_CR); |
| 167 | if ((long)arg & 1) { // loop B1 |
| 168 | cs->writeisac(cs, IPACX_CDA1_CR, cda1_cr | 0x0a); |
| 169 | } |
| 170 | else { // B1 off |
| 171 | cs->writeisac(cs, IPACX_CDA1_CR, cda1_cr & ~0x0a); |
| 172 | } |
| 173 | if ((long)arg & 2) { // loop B2 |
| 174 | cs->writeisac(cs, IPACX_CDA1_CR, cda1_cr | 0x14); |
| 175 | } |
| 176 | else { // B2 off |
| 177 | cs->writeisac(cs, IPACX_CDA1_CR, cda1_cr & ~0x14); |
| 178 | } |
| 179 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 181 | case (HW_DEACTIVATE | RESPONSE): |
| 182 | skb_queue_purge(&cs->rq); |
| 183 | skb_queue_purge(&cs->sq); |
| 184 | if (cs->tx_skb) { |
| 185 | dev_kfree_skb_any(cs->tx_skb); |
| 186 | cs->tx_skb = NULL; |
| 187 | } |
| 188 | if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) |
| 189 | del_timer(&cs->dbusytimer); |
| 190 | break; |
| 191 | |
| 192 | default: |
| 193 | if (cs->debug & L1_DEB_WARN) debugl1(cs, "dch_l2l1 unknown %04x", pr); |
| 194 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | //---------------------------------------------------------- |
| 199 | //---------------------------------------------------------- |
| 200 | static void |
| 201 | dbusy_timer_handler(struct IsdnCardState *cs) |
| 202 | { |
| 203 | struct PStack *st; |
| 204 | int rbchd, stard; |
| 205 | |
| 206 | if (test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) { |
| 207 | rbchd = cs->readisac(cs, IPACX_RBCHD); |
| 208 | stard = cs->readisac(cs, IPACX_STARD); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 209 | if (cs->debug) |
| 210 | debugl1(cs, "D-Channel Busy RBCHD %02x STARD %02x", rbchd, stard); |
| 211 | if (!(stard & 0x40)) { // D-Channel Busy |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | set_bit(FLG_L1_DBUSY, &cs->HW_Flags); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 213 | for (st = cs->stlist; st; st = st->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | st->l1.l1l2(st, PH_PAUSE | INDICATION, NULL); // flow control on |
| 215 | } |
| 216 | } else { |
| 217 | // seems we lost an interrupt; reset transceiver */ |
| 218 | clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags); |
| 219 | if (cs->tx_skb) { |
| 220 | dev_kfree_skb_any(cs->tx_skb); |
| 221 | cs->tx_cnt = 0; |
| 222 | cs->tx_skb = NULL; |
| 223 | } else { |
| 224 | printk(KERN_WARNING "HiSax: ISAC D-Channel Busy no skb\n"); |
| 225 | debugl1(cs, "D-Channel Busy no skb"); |
| 226 | } |
| 227 | cs->writeisac(cs, IPACX_CMDRD, 0x01); // Tx reset, generates XPR |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | //---------------------------------------------------------- |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | // Fill buffer from receive FIFO |
| 234 | //---------------------------------------------------------- |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 235 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | dch_empty_fifo(struct IsdnCardState *cs, int count) |
| 237 | { |
| 238 | u_char *ptr; |
| 239 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 240 | if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | debugl1(cs, "dch_empty_fifo()"); |
| 242 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 243 | // message too large, remove |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if ((cs->rcvidx + count) >= MAX_DFRAME_LEN_L1) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 245 | if (cs->debug & L1_DEB_WARN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | debugl1(cs, "dch_empty_fifo() incoming message too large"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 247 | cs->writeisac(cs, IPACX_CMDRD, 0x80); // RMC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | cs->rcvidx = 0; |
| 249 | return; |
| 250 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | ptr = cs->rcvbuf + cs->rcvidx; |
| 253 | cs->rcvidx += count; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | cs->readisacfifo(cs, ptr, count); |
| 256 | cs->writeisac(cs, IPACX_CMDRD, 0x80); // RMC |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 257 | |
| 258 | if (cs->debug & L1_DEB_ISAC_FIFO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | char *t = cs->dlog; |
| 260 | |
| 261 | t += sprintf(t, "dch_empty_fifo() cnt %d", count); |
| 262 | QuickHex(t, ptr, count); |
Kees Cook | 35a4a57 | 2013-09-13 14:52:04 -0700 | [diff] [blame] | 263 | debugl1(cs, "%s", cs->dlog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | //---------------------------------------------------------- |
| 268 | // Fill transmit FIFO |
| 269 | //---------------------------------------------------------- |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 270 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | dch_fill_fifo(struct IsdnCardState *cs) |
| 272 | { |
| 273 | int count; |
| 274 | u_char cmd, *ptr; |
| 275 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 276 | if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | debugl1(cs, "dch_fill_fifo()"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (!cs->tx_skb) return; |
| 280 | count = cs->tx_skb->len; |
| 281 | if (count <= 0) return; |
| 282 | |
| 283 | if (count > D_FIFO_SIZE) { |
| 284 | count = D_FIFO_SIZE; |
| 285 | cmd = 0x08; // XTF |
| 286 | } else { |
| 287 | cmd = 0x0A; // XTF | XME |
| 288 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | ptr = cs->tx_skb->data; |
| 291 | skb_pull(cs->tx_skb, count); |
| 292 | cs->tx_cnt += count; |
| 293 | cs->writeisacfifo(cs, ptr, count); |
| 294 | cs->writeisac(cs, IPACX_CMDRD, cmd); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 295 | |
| 296 | // set timeout for transmission contol |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | if (test_and_set_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) { |
| 298 | debugl1(cs, "dch_fill_fifo dbusytimer running"); |
| 299 | del_timer(&cs->dbusytimer); |
| 300 | } |
| 301 | init_timer(&cs->dbusytimer); |
| 302 | cs->dbusytimer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ)/1000); |
| 303 | add_timer(&cs->dbusytimer); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 304 | |
| 305 | if (cs->debug & L1_DEB_ISAC_FIFO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | char *t = cs->dlog; |
| 307 | |
| 308 | t += sprintf(t, "dch_fill_fifo() cnt %d", count); |
| 309 | QuickHex(t, ptr, count); |
Kees Cook | 35a4a57 | 2013-09-13 14:52:04 -0700 | [diff] [blame] | 310 | debugl1(cs, "%s", cs->dlog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | //---------------------------------------------------------- |
| 315 | // D channel interrupt handler |
| 316 | //---------------------------------------------------------- |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 317 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | dch_int(struct IsdnCardState *cs) |
| 319 | { |
| 320 | struct sk_buff *skb; |
| 321 | u_char istad, rstad; |
| 322 | int count; |
| 323 | |
| 324 | istad = cs->readisac(cs, IPACX_ISTAD); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 325 | //############################################## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | // printk(KERN_WARNING "dch_int(istad=%02x)\n", istad); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 327 | //############################################## |
| 328 | |
| 329 | if (istad & 0x80) { // RME |
| 330 | rstad = cs->readisac(cs, IPACX_RSTAD); |
| 331 | if ((rstad & 0xf0) != 0xa0) { // !(VFR && !RDO && CRC && !RAB) |
| 332 | if (!(rstad & 0x80)) |
| 333 | if (cs->debug & L1_DEB_WARN) |
| 334 | debugl1(cs, "dch_int(): invalid frame"); |
| 335 | if ((rstad & 0x40)) |
| 336 | if (cs->debug & L1_DEB_WARN) |
| 337 | debugl1(cs, "dch_int(): RDO"); |
| 338 | if (!(rstad & 0x20)) |
| 339 | if (cs->debug & L1_DEB_WARN) |
| 340 | debugl1(cs, "dch_int(): CRC error"); |
| 341 | cs->writeisac(cs, IPACX_CMDRD, 0x80); // RMC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } else { // received frame ok |
| 343 | count = cs->readisac(cs, IPACX_RBCLD); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 344 | if (count) count--; // RSTAB is last byte |
| 345 | count &= D_FIFO_SIZE - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | if (count == 0) count = D_FIFO_SIZE; |
| 347 | dch_empty_fifo(cs, count); |
| 348 | if ((count = cs->rcvidx) > 0) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 349 | cs->rcvidx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (!(skb = dev_alloc_skb(count))) |
| 351 | printk(KERN_WARNING "HiSax dch_int(): receive out of memory\n"); |
| 352 | else { |
| 353 | memcpy(skb_put(skb, count), cs->rcvbuf, count); |
| 354 | skb_queue_tail(&cs->rq, skb); |
| 355 | } |
| 356 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 357 | } |
| 358 | cs->rcvidx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | schedule_event(cs, D_RCVBUFREADY); |
| 360 | } |
| 361 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 362 | if (istad & 0x40) { // RPF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | dch_empty_fifo(cs, D_FIFO_SIZE); |
| 364 | } |
| 365 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 366 | if (istad & 0x20) { // RFO |
| 367 | if (cs->debug & L1_DEB_WARN) debugl1(cs, "dch_int(): RFO"); |
| 368 | cs->writeisac(cs, IPACX_CMDRD, 0x40); //RRES |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 370 | |
| 371 | if (istad & 0x10) { // XPR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) |
| 373 | del_timer(&cs->dbusytimer); |
| 374 | if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags)) |
| 375 | schedule_event(cs, D_CLEARBUSY); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 376 | if (cs->tx_skb) { |
| 377 | if (cs->tx_skb->len) { |
| 378 | dch_fill_fifo(cs); |
| 379 | goto afterXPR; |
| 380 | } |
| 381 | else { |
| 382 | dev_kfree_skb_irq(cs->tx_skb); |
| 383 | cs->tx_skb = NULL; |
| 384 | cs->tx_cnt = 0; |
| 385 | } |
| 386 | } |
| 387 | if ((cs->tx_skb = skb_dequeue(&cs->sq))) { |
| 388 | cs->tx_cnt = 0; |
| 389 | dch_fill_fifo(cs); |
| 390 | } |
| 391 | else { |
| 392 | schedule_event(cs, D_XMTBUFREADY); |
| 393 | } |
| 394 | } |
| 395 | afterXPR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 397 | if (istad & 0x0C) { // XDU or XMR |
| 398 | if (cs->debug & L1_DEB_WARN) debugl1(cs, "dch_int(): XDU"); |
| 399 | if (cs->tx_skb) { |
| 400 | skb_push(cs->tx_skb, cs->tx_cnt); // retransmit |
| 401 | cs->tx_cnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | dch_fill_fifo(cs); |
| 403 | } else { |
| 404 | printk(KERN_WARNING "HiSax: ISAC XDU no skb\n"); |
| 405 | debugl1(cs, "ISAC XDU no skb"); |
| 406 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | //---------------------------------------------------------- |
| 411 | //---------------------------------------------------------- |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 412 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | dch_setstack(struct PStack *st, struct IsdnCardState *cs) |
| 414 | { |
| 415 | st->l1.l1hw = dch_l2l1; |
| 416 | } |
| 417 | |
| 418 | //---------------------------------------------------------- |
| 419 | //---------------------------------------------------------- |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 420 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | dch_init(struct IsdnCardState *cs) |
| 422 | { |
| 423 | printk(KERN_INFO "HiSax: IPACX ISDN driver v0.1.0\n"); |
| 424 | |
| 425 | cs->setstack_d = dch_setstack; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 426 | |
Geliang Tang | aff55a3 | 2017-03-23 21:15:57 +0800 | [diff] [blame] | 427 | setup_timer(&cs->dbusytimer, (void *)dbusy_timer_handler, (long)cs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 429 | cs->writeisac(cs, IPACX_TR_CONF0, 0x00); // clear LDD |
| 430 | cs->writeisac(cs, IPACX_TR_CONF2, 0x00); // enable transmitter |
| 431 | cs->writeisac(cs, IPACX_MODED, 0xC9); // transparent mode 0, RAC, stop/go |
| 432 | cs->writeisac(cs, IPACX_MON_CR, 0x00); // disable monitor channel |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | |
| 436 | //========================================================== |
| 437 | // B channel functions |
| 438 | //========================================================== |
| 439 | |
| 440 | //---------------------------------------------------------- |
| 441 | // Entry point for commands |
| 442 | //---------------------------------------------------------- |
| 443 | static void |
| 444 | bch_l2l1(struct PStack *st, int pr, void *arg) |
| 445 | { |
| 446 | struct BCState *bcs = st->l1.bcs; |
| 447 | struct sk_buff *skb = arg; |
| 448 | u_long flags; |
| 449 | |
| 450 | switch (pr) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 451 | case (PH_DATA | REQUEST): |
| 452 | spin_lock_irqsave(&bcs->cs->lock, flags); |
| 453 | if (bcs->tx_skb) { |
| 454 | skb_queue_tail(&bcs->squeue, skb); |
| 455 | } else { |
| 456 | bcs->tx_skb = skb; |
| 457 | set_bit(BC_FLG_BUSY, &bcs->Flag); |
| 458 | bcs->hw.hscx.count = 0; |
| 459 | bch_fill_fifo(bcs); |
| 460 | } |
| 461 | spin_unlock_irqrestore(&bcs->cs->lock, flags); |
| 462 | break; |
| 463 | case (PH_PULL | INDICATION): |
| 464 | spin_lock_irqsave(&bcs->cs->lock, flags); |
| 465 | if (bcs->tx_skb) { |
| 466 | printk(KERN_WARNING "HiSax bch_l2l1(): this shouldn't happen\n"); |
| 467 | } else { |
| 468 | set_bit(BC_FLG_BUSY, &bcs->Flag); |
| 469 | bcs->tx_skb = skb; |
| 470 | bcs->hw.hscx.count = 0; |
| 471 | bch_fill_fifo(bcs); |
| 472 | } |
| 473 | spin_unlock_irqrestore(&bcs->cs->lock, flags); |
| 474 | break; |
| 475 | case (PH_PULL | REQUEST): |
| 476 | if (!bcs->tx_skb) { |
| 477 | clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags); |
| 478 | st->l1.l1l2(st, PH_PULL | CONFIRM, NULL); |
| 479 | } else |
| 480 | set_bit(FLG_L1_PULL_REQ, &st->l1.Flags); |
| 481 | break; |
| 482 | case (PH_ACTIVATE | REQUEST): |
| 483 | spin_lock_irqsave(&bcs->cs->lock, flags); |
| 484 | set_bit(BC_FLG_ACTIV, &bcs->Flag); |
| 485 | bch_mode(bcs, st->l1.mode, st->l1.bc); |
| 486 | spin_unlock_irqrestore(&bcs->cs->lock, flags); |
| 487 | l1_msg_b(st, pr, arg); |
| 488 | break; |
| 489 | case (PH_DEACTIVATE | REQUEST): |
| 490 | l1_msg_b(st, pr, arg); |
| 491 | break; |
| 492 | case (PH_DEACTIVATE | CONFIRM): |
| 493 | spin_lock_irqsave(&bcs->cs->lock, flags); |
| 494 | clear_bit(BC_FLG_ACTIV, &bcs->Flag); |
| 495 | clear_bit(BC_FLG_BUSY, &bcs->Flag); |
| 496 | bch_mode(bcs, 0, st->l1.bc); |
| 497 | spin_unlock_irqrestore(&bcs->cs->lock, flags); |
| 498 | st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL); |
| 499 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | //---------------------------------------------------------- |
| 504 | // Read B channel fifo to receive buffer |
| 505 | //---------------------------------------------------------- |
| 506 | static void |
| 507 | bch_empty_fifo(struct BCState *bcs, int count) |
| 508 | { |
| 509 | u_char *ptr, hscx; |
| 510 | struct IsdnCardState *cs; |
| 511 | int cnt; |
| 512 | |
| 513 | cs = bcs->cs; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 514 | hscx = bcs->hw.hscx.hscx; |
| 515 | if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | debugl1(cs, "bch_empty_fifo()"); |
| 517 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 518 | // message too large, remove |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (bcs->hw.hscx.rcvidx + count > HSCX_BUFMAX) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 520 | if (cs->debug & L1_DEB_WARN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | debugl1(cs, "bch_empty_fifo() incoming packet too large"); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 522 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x80); // RMC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | bcs->hw.hscx.rcvidx = 0; |
| 524 | return; |
| 525 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx; |
| 528 | cnt = count; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 529 | while (cnt--) *ptr++ = cs->BC_Read_Reg(cs, hscx, IPACX_RFIFOB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x80); // RMC |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx; |
| 533 | bcs->hw.hscx.rcvidx += count; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 534 | |
| 535 | if (cs->debug & L1_DEB_HSCX_FIFO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | char *t = bcs->blog; |
| 537 | |
| 538 | t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count); |
| 539 | QuickHex(t, ptr, count); |
Kees Cook | 35a4a57 | 2013-09-13 14:52:04 -0700 | [diff] [blame] | 540 | debugl1(cs, "%s", bcs->blog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | //---------------------------------------------------------- |
| 545 | // Fill buffer to transmit FIFO |
| 546 | //---------------------------------------------------------- |
| 547 | static void |
| 548 | bch_fill_fifo(struct BCState *bcs) |
| 549 | { |
| 550 | struct IsdnCardState *cs; |
| 551 | int more, count, cnt; |
| 552 | u_char *ptr, *p, hscx; |
| 553 | |
| 554 | cs = bcs->cs; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 555 | if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | debugl1(cs, "bch_fill_fifo()"); |
| 557 | |
| 558 | if (!bcs->tx_skb) return; |
| 559 | if (bcs->tx_skb->len <= 0) return; |
| 560 | |
| 561 | hscx = bcs->hw.hscx.hscx; |
| 562 | more = (bcs->mode == L1_MODE_TRANS) ? 1 : 0; |
| 563 | if (bcs->tx_skb->len > B_FIFO_SIZE) { |
| 564 | more = 1; |
| 565 | count = B_FIFO_SIZE; |
| 566 | } else { |
| 567 | count = bcs->tx_skb->len; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 568 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | cnt = count; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | p = ptr = bcs->tx_skb->data; |
| 572 | skb_pull(bcs->tx_skb, count); |
| 573 | bcs->tx_cnt -= count; |
| 574 | bcs->hw.hscx.count += count; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 575 | while (cnt--) cs->BC_Write_Reg(cs, hscx, IPACX_XFIFOB, *p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, (more ? 0x08 : 0x0a)); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 577 | |
| 578 | if (cs->debug & L1_DEB_HSCX_FIFO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | char *t = bcs->blog; |
| 580 | |
Julia Lawall | eeb4e6d | 2014-12-07 20:20:47 +0100 | [diff] [blame] | 581 | t += sprintf(t, "%s() B-%d cnt %d", __func__, hscx, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | QuickHex(t, ptr, count); |
Kees Cook | 35a4a57 | 2013-09-13 14:52:04 -0700 | [diff] [blame] | 583 | debugl1(cs, "%s", bcs->blog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
| 587 | //---------------------------------------------------------- |
| 588 | // B channel interrupt handler |
| 589 | //---------------------------------------------------------- |
| 590 | static void |
| 591 | bch_int(struct IsdnCardState *cs, u_char hscx) |
| 592 | { |
| 593 | u_char istab; |
| 594 | struct BCState *bcs; |
| 595 | struct sk_buff *skb; |
| 596 | int count; |
| 597 | u_char rstab; |
| 598 | |
| 599 | bcs = cs->bcs + hscx; |
| 600 | istab = cs->BC_Read_Reg(cs, hscx, IPACX_ISTAB); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 601 | //############################################## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | // printk(KERN_WARNING "bch_int(istab=%02x)\n", istab); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 603 | //############################################## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | if (!test_bit(BC_FLG_INIT, &bcs->Flag)) return; |
| 605 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 606 | if (istab & 0x80) { // RME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | rstab = cs->BC_Read_Reg(cs, hscx, IPACX_RSTAB); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 608 | if ((rstab & 0xf0) != 0xa0) { // !(VFR && !RDO && CRC && !RAB) |
| 609 | if (!(rstab & 0x80)) |
| 610 | if (cs->debug & L1_DEB_WARN) |
| 611 | debugl1(cs, "bch_int() B-%d: invalid frame", hscx); |
| 612 | if ((rstab & 0x40) && (bcs->mode != L1_MODE_NULL)) |
| 613 | if (cs->debug & L1_DEB_WARN) |
| 614 | debugl1(cs, "bch_int() B-%d: RDO mode=%d", hscx, bcs->mode); |
| 615 | if (!(rstab & 0x20)) |
| 616 | if (cs->debug & L1_DEB_WARN) |
| 617 | debugl1(cs, "bch_int() B-%d: CRC error", hscx); |
| 618 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x80); // RMC |
| 619 | } |
| 620 | else { // received frame ok |
| 621 | count = cs->BC_Read_Reg(cs, hscx, IPACX_RBCLB) & (B_FIFO_SIZE - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | if (count == 0) count = B_FIFO_SIZE; |
| 623 | bch_empty_fifo(bcs, count); |
| 624 | if ((count = bcs->hw.hscx.rcvidx - 1) > 0) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 625 | if (cs->debug & L1_DEB_HSCX_FIFO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | debugl1(cs, "bch_int Frame %d", count); |
| 627 | if (!(skb = dev_alloc_skb(count))) |
| 628 | printk(KERN_WARNING "HiSax bch_int(): receive frame out of memory\n"); |
| 629 | else { |
| 630 | memcpy(skb_put(skb, count), bcs->hw.hscx.rcvbuf, count); |
| 631 | skb_queue_tail(&bcs->rqueue, skb); |
| 632 | } |
| 633 | } |
| 634 | } |
| 635 | bcs->hw.hscx.rcvidx = 0; |
| 636 | schedule_event(bcs, B_RCVBUFREADY); |
| 637 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 638 | |
| 639 | if (istab & 0x40) { // RPF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | bch_empty_fifo(bcs, B_FIFO_SIZE); |
| 641 | |
| 642 | if (bcs->mode == L1_MODE_TRANS) { // queue every chunk |
| 643 | // receive transparent audio data |
| 644 | if (!(skb = dev_alloc_skb(B_FIFO_SIZE))) |
| 645 | printk(KERN_WARNING "HiSax bch_int(): receive transparent out of memory\n"); |
| 646 | else { |
| 647 | memcpy(skb_put(skb, B_FIFO_SIZE), bcs->hw.hscx.rcvbuf, B_FIFO_SIZE); |
| 648 | skb_queue_tail(&bcs->rqueue, skb); |
| 649 | } |
| 650 | bcs->hw.hscx.rcvidx = 0; |
| 651 | schedule_event(bcs, B_RCVBUFREADY); |
| 652 | } |
| 653 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 654 | |
| 655 | if (istab & 0x20) { // RFO |
| 656 | if (cs->debug & L1_DEB_WARN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | debugl1(cs, "bch_int() B-%d: RFO error", hscx); |
| 658 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x40); // RRES |
| 659 | } |
| 660 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 661 | if (istab & 0x10) { // XPR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | if (bcs->tx_skb) { |
| 663 | if (bcs->tx_skb->len) { |
| 664 | bch_fill_fifo(bcs); |
| 665 | goto afterXPR; |
| 666 | } else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 667 | if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) && |
| 668 | (PACKET_NOACK != bcs->tx_skb->pkt_type)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | u_long flags; |
| 670 | spin_lock_irqsave(&bcs->aclock, flags); |
| 671 | bcs->ackcnt += bcs->hw.hscx.count; |
| 672 | spin_unlock_irqrestore(&bcs->aclock, flags); |
| 673 | schedule_event(bcs, B_ACKPENDING); |
| 674 | } |
| 675 | } |
| 676 | dev_kfree_skb_irq(bcs->tx_skb); |
| 677 | bcs->hw.hscx.count = 0; |
| 678 | bcs->tx_skb = NULL; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) { |
| 681 | bcs->hw.hscx.count = 0; |
| 682 | set_bit(BC_FLG_BUSY, &bcs->Flag); |
| 683 | bch_fill_fifo(bcs); |
| 684 | } else { |
| 685 | clear_bit(BC_FLG_BUSY, &bcs->Flag); |
| 686 | schedule_event(bcs, B_XMTBUFREADY); |
| 687 | } |
| 688 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 689 | afterXPR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 691 | if (istab & 0x04) { // XDU |
| 692 | if (bcs->mode == L1_MODE_TRANS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | bch_fill_fifo(bcs); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 694 | } |
| 695 | else { |
| 696 | if (bcs->tx_skb) { // restart transmitting the whole frame |
| 697 | skb_push(bcs->tx_skb, bcs->hw.hscx.count); |
| 698 | bcs->tx_cnt += bcs->hw.hscx.count; |
| 699 | bcs->hw.hscx.count = 0; |
| 700 | } |
| 701 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x01); // XRES |
| 702 | if (cs->debug & L1_DEB_WARN) |
| 703 | debugl1(cs, "bch_int() B-%d XDU error", hscx); |
| 704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
| 708 | //---------------------------------------------------------- |
| 709 | //---------------------------------------------------------- |
| 710 | static void |
| 711 | bch_mode(struct BCState *bcs, int mode, int bc) |
| 712 | { |
| 713 | struct IsdnCardState *cs = bcs->cs; |
| 714 | int hscx = bcs->hw.hscx.hscx; |
| 715 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 716 | bc = bc ? 1 : 0; // in case bc is greater than 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (cs->debug & L1_DEB_HSCX) |
Joe Perches | 9920239 | 2010-11-10 18:54:58 +0000 | [diff] [blame] | 718 | debugl1(cs, "mode_bch() switch B-%d mode %d chan %d", hscx, mode, bc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | bcs->mode = mode; |
| 720 | bcs->channel = bc; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 721 | |
| 722 | // map controller to according timeslot |
| 723 | if (!hscx) |
| 724 | { |
| 725 | cs->writeisac(cs, IPACX_BCHA_TSDP_BC1, 0x80 | bc); |
| 726 | cs->writeisac(cs, IPACX_BCHA_CR, 0x88); |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | cs->writeisac(cs, IPACX_BCHB_TSDP_BC1, 0x80 | bc); |
| 731 | cs->writeisac(cs, IPACX_BCHB_CR, 0x88); |
| 732 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | switch (mode) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 735 | case (L1_MODE_NULL): |
| 736 | cs->BC_Write_Reg(cs, hscx, IPACX_MODEB, 0xC0); // rec off |
| 737 | cs->BC_Write_Reg(cs, hscx, IPACX_EXMB, 0x30); // std adj. |
| 738 | cs->BC_Write_Reg(cs, hscx, IPACX_MASKB, 0xFF); // ints off |
| 739 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x41); // validate adjustments |
| 740 | break; |
| 741 | case (L1_MODE_TRANS): |
| 742 | cs->BC_Write_Reg(cs, hscx, IPACX_MODEB, 0x88); // ext transp mode |
| 743 | cs->BC_Write_Reg(cs, hscx, IPACX_EXMB, 0x00); // xxx00000 |
| 744 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x41); // validate adjustments |
| 745 | cs->BC_Write_Reg(cs, hscx, IPACX_MASKB, _MASKB_IMASK); |
| 746 | break; |
| 747 | case (L1_MODE_HDLC): |
| 748 | cs->BC_Write_Reg(cs, hscx, IPACX_MODEB, 0xC8); // transp mode 0 |
| 749 | cs->BC_Write_Reg(cs, hscx, IPACX_EXMB, 0x01); // idle=hdlc flags crc enabled |
| 750 | cs->BC_Write_Reg(cs, hscx, IPACX_CMDRB, 0x41); // validate adjustments |
| 751 | cs->BC_Write_Reg(cs, hscx, IPACX_MASKB, _MASKB_IMASK); |
| 752 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
| 756 | //---------------------------------------------------------- |
| 757 | //---------------------------------------------------------- |
| 758 | static void |
| 759 | bch_close_state(struct BCState *bcs) |
| 760 | { |
| 761 | bch_mode(bcs, 0, bcs->channel); |
| 762 | if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) { |
Jesper Juhl | 3c7208f | 2005-11-07 01:01:29 -0800 | [diff] [blame] | 763 | kfree(bcs->hw.hscx.rcvbuf); |
| 764 | bcs->hw.hscx.rcvbuf = NULL; |
| 765 | kfree(bcs->blog); |
| 766 | bcs->blog = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | skb_queue_purge(&bcs->rqueue); |
| 768 | skb_queue_purge(&bcs->squeue); |
| 769 | if (bcs->tx_skb) { |
| 770 | dev_kfree_skb_any(bcs->tx_skb); |
| 771 | bcs->tx_skb = NULL; |
| 772 | clear_bit(BC_FLG_BUSY, &bcs->Flag); |
| 773 | } |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | //---------------------------------------------------------- |
| 778 | //---------------------------------------------------------- |
| 779 | static int |
| 780 | bch_open_state(struct IsdnCardState *cs, struct BCState *bcs) |
| 781 | { |
| 782 | if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) { |
| 783 | if (!(bcs->hw.hscx.rcvbuf = kmalloc(HSCX_BUFMAX, GFP_ATOMIC))) { |
| 784 | printk(KERN_WARNING |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 785 | "HiSax open_bchstate(): No memory for hscx.rcvbuf\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | clear_bit(BC_FLG_INIT, &bcs->Flag); |
| 787 | return (1); |
| 788 | } |
| 789 | if (!(bcs->blog = kmalloc(MAX_BLOG_SPACE, GFP_ATOMIC))) { |
| 790 | printk(KERN_WARNING |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 791 | "HiSax open_bchstate: No memory for bcs->blog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | clear_bit(BC_FLG_INIT, &bcs->Flag); |
| 793 | kfree(bcs->hw.hscx.rcvbuf); |
| 794 | bcs->hw.hscx.rcvbuf = NULL; |
| 795 | return (2); |
| 796 | } |
| 797 | skb_queue_head_init(&bcs->rqueue); |
| 798 | skb_queue_head_init(&bcs->squeue); |
| 799 | } |
| 800 | bcs->tx_skb = NULL; |
| 801 | clear_bit(BC_FLG_BUSY, &bcs->Flag); |
| 802 | bcs->event = 0; |
| 803 | bcs->hw.hscx.rcvidx = 0; |
| 804 | bcs->tx_cnt = 0; |
| 805 | return (0); |
| 806 | } |
| 807 | |
| 808 | //---------------------------------------------------------- |
| 809 | //---------------------------------------------------------- |
| 810 | static int |
| 811 | bch_setstack(struct PStack *st, struct BCState *bcs) |
| 812 | { |
| 813 | bcs->channel = st->l1.bc; |
| 814 | if (bch_open_state(st->l1.hardware, bcs)) return (-1); |
| 815 | st->l1.bcs = bcs; |
| 816 | st->l2.l2l1 = bch_l2l1; |
| 817 | setstack_manager(st); |
| 818 | bcs->st = st; |
| 819 | setstack_l1_B(st); |
| 820 | return (0); |
| 821 | } |
| 822 | |
| 823 | //---------------------------------------------------------- |
| 824 | //---------------------------------------------------------- |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 825 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | bch_init(struct IsdnCardState *cs, int hscx) |
| 827 | { |
| 828 | cs->bcs[hscx].BC_SetStack = bch_setstack; |
| 829 | cs->bcs[hscx].BC_Close = bch_close_state; |
| 830 | cs->bcs[hscx].hw.hscx.hscx = hscx; |
| 831 | cs->bcs[hscx].cs = cs; |
| 832 | bch_mode(cs->bcs + hscx, 0, hscx); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | //========================================================== |
| 837 | // Shared functions |
| 838 | //========================================================== |
| 839 | |
| 840 | //---------------------------------------------------------- |
| 841 | // Main interrupt handler |
| 842 | //---------------------------------------------------------- |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 843 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | interrupt_ipacx(struct IsdnCardState *cs) |
| 845 | { |
| 846 | u_char ista; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | while ((ista = cs->readisac(cs, IPACX_ISTA))) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 849 | //################################################# |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | // printk(KERN_WARNING "interrupt_ipacx(ista=%02x)\n", ista); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 851 | //################################################# |
| 852 | if (ista & 0x80) bch_int(cs, 0); // B channel interrupts |
| 853 | if (ista & 0x40) bch_int(cs, 1); |
| 854 | |
| 855 | if (ista & 0x01) dch_int(cs); // D channel |
| 856 | if (ista & 0x10) cic_int(cs); // Layer 1 state |
| 857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | //---------------------------------------------------------- |
| 861 | // Clears chip interrupt status |
| 862 | //---------------------------------------------------------- |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 863 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | clear_pending_ints(struct IsdnCardState *cs) |
| 865 | { |
| 866 | int ista; |
| 867 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 868 | // all interrupts off |
| 869 | cs->writeisac(cs, IPACX_MASK, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | cs->writeisac(cs, IPACX_MASKD, 0xff); |
| 871 | cs->BC_Write_Reg(cs, 0, IPACX_MASKB, 0xff); |
| 872 | cs->BC_Write_Reg(cs, 1, IPACX_MASKB, 0xff); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 873 | |
| 874 | ista = cs->readisac(cs, IPACX_ISTA); |
| 875 | if (ista & 0x80) cs->BC_Read_Reg(cs, 0, IPACX_ISTAB); |
| 876 | if (ista & 0x40) cs->BC_Read_Reg(cs, 1, IPACX_ISTAB); |
| 877 | if (ista & 0x10) cs->readisac(cs, IPACX_CIR0); |
| 878 | if (ista & 0x01) cs->readisac(cs, IPACX_ISTAD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | //---------------------------------------------------------- |
| 882 | // Does chip configuration work |
| 883 | // Work to do depends on bit mask in part |
| 884 | //---------------------------------------------------------- |
Karsten Keil | 67eb5db | 2006-07-10 04:44:11 -0700 | [diff] [blame] | 885 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | init_ipacx(struct IsdnCardState *cs, int part) |
| 887 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 888 | if (part & 1) { // initialise chip |
| 889 | //################################################## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | // printk(KERN_INFO "init_ipacx(%x)\n", part); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 891 | //################################################## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | clear_pending_ints(cs); |
| 893 | bch_init(cs, 0); |
| 894 | bch_init(cs, 1); |
| 895 | dch_init(cs); |
| 896 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 897 | if (part & 2) { // reenable all interrupts and start chip |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | cs->BC_Write_Reg(cs, 0, IPACX_MASKB, _MASKB_IMASK); |
| 899 | cs->BC_Write_Reg(cs, 1, IPACX_MASKB, _MASKB_IMASK); |
| 900 | cs->writeisac(cs, IPACX_MASKD, _MASKD_IMASK); |
| 901 | cs->writeisac(cs, IPACX_MASK, _MASK_IMASK); // global mask register |
| 902 | |
| 903 | // reset HDLC Transmitters/receivers |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 904 | cs->writeisac(cs, IPACX_CMDRD, 0x41); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | cs->BC_Write_Reg(cs, 0, IPACX_CMDRB, 0x41); |
| 906 | cs->BC_Write_Reg(cs, 1, IPACX_CMDRB, 0x41); |
| 907 | ph_command(cs, IPACX_CMD_RES); |
| 908 | } |
| 909 | } |
| 910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | //----------------- end of file ----------------------- |