blob: b7f54fa292282c7b3dafc8f5be5763091d5ccf3c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: netjet.c,v 1.29.2.4 2004/02/11 13:21:34 keil Exp $
2 *
3 * low level stuff for Traverse Technologie NETJet ISDN cards
4 *
5 * Author Karsten Keil
6 * Copyright by Karsten Keil <keil@isdn4linux.de>
Joe Perches475be4d2012-02-19 19:52:38 -08007 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 * Thanks to Traverse Technologies Australia for documents and information
12 *
13 * 16-Apr-2002 - led code added - Guy Ellis (guy@traverse.com.au)
14 *
15 */
16
17#include <linux/init.h>
18#include "hisax.h"
19#include "isac.h"
20#include "hscx.h"
21#include "isdnl1.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/interrupt.h>
23#include <linux/ppp_defs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/io.h>
26#include "netjet.h"
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/* Interface functions */
29
30u_char
31NETjet_ReadIC(struct IsdnCardState *cs, u_char offset)
32{
33 u_char ret;
Joe Perches475be4d2012-02-19 19:52:38 -080034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 cs->hw.njet.auxd &= 0xfc;
Joe Perches475be4d2012-02-19 19:52:38 -080036 cs->hw.njet.auxd |= (offset >> 4) & 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
Joe Perches475be4d2012-02-19 19:52:38 -080038 ret = bytein(cs->hw.njet.isac + ((offset & 0xf) << 2));
39 return (ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42void
43NETjet_WriteIC(struct IsdnCardState *cs, u_char offset, u_char value)
44{
45 cs->hw.njet.auxd &= 0xfc;
Joe Perches475be4d2012-02-19 19:52:38 -080046 cs->hw.njet.auxd |= (offset >> 4) & 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
Joe Perches475be4d2012-02-19 19:52:38 -080048 byteout(cs->hw.njet.isac + ((offset & 0xf) << 2), value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51void
52NETjet_ReadICfifo(struct IsdnCardState *cs, u_char *data, int size)
53{
54 cs->hw.njet.auxd &= 0xfc;
55 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
56 insb(cs->hw.njet.isac, data, size);
57}
58
Joe Perches475be4d2012-02-19 19:52:38 -080059void
Linus Torvalds1da177e2005-04-16 15:20:36 -070060NETjet_WriteICfifo(struct IsdnCardState *cs, u_char *data, int size)
61{
62 cs->hw.njet.auxd &= 0xfc;
63 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
64 outsb(cs->hw.njet.isac, data, size);
65}
66
Adrian Bunk672c3fd2005-06-25 14:59:18 -070067static void fill_mem(struct BCState *bcs, u_int *pos, u_int cnt, int chan, u_char fill)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Joe Perches475be4d2012-02-19 19:52:38 -080069 u_int mask = 0x000000ff, val = 0, *p = pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 u_int i;
Joe Perches475be4d2012-02-19 19:52:38 -080071
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 val |= fill;
73 if (chan) {
74 val <<= 8;
75 mask <<= 8;
76 }
77 mask ^= 0xffffffff;
Joe Perches475be4d2012-02-19 19:52:38 -080078 for (i = 0; i < cnt; i++) {
79 *p &= mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 *p++ |= val;
81 if (p > bcs->hw.tiger.s_end)
82 p = bcs->hw.tiger.send;
83 }
84}
85
Adrian Bunk672c3fd2005-06-25 14:59:18 -070086static void
Linus Torvalds1da177e2005-04-16 15:20:36 -070087mode_tiger(struct BCState *bcs, int mode, int bc)
88{
89 struct IsdnCardState *cs = bcs->cs;
Joe Perches475be4d2012-02-19 19:52:38 -080090 u_char led;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 if (cs->debug & L1_DEB_HSCX)
93 debugl1(cs, "Tiger mode %d bchan %d/%d",
94 mode, bc, bcs->channel);
95 bcs->mode = mode;
96 bcs->channel = bc;
97 switch (mode) {
Joe Perches475be4d2012-02-19 19:52:38 -080098 case (L1_MODE_NULL):
99 fill_mem(bcs, bcs->hw.tiger.send,
100 NETJET_DMA_TXSIZE, bc, 0xff);
101 if (cs->debug & L1_DEB_HSCX)
102 debugl1(cs, "Tiger stat rec %d/%d send %d",
103 bcs->hw.tiger.r_tot, bcs->hw.tiger.r_err,
104 bcs->hw.tiger.s_tot);
105 if ((cs->bcs[0].mode == L1_MODE_NULL) &&
106 (cs->bcs[1].mode == L1_MODE_NULL)) {
107 cs->hw.njet.dmactrl = 0;
108 byteout(cs->hw.njet.base + NETJET_DMACTRL,
109 cs->hw.njet.dmactrl);
110 byteout(cs->hw.njet.base + NETJET_IRQMASK0, 0);
111 }
112 if (cs->typ == ISDN_CTYPE_NETJET_S)
113 {
114 // led off
115 led = bc & 0x01;
116 led = 0x01 << (6 + led); // convert to mask
117 led = ~led;
118 cs->hw.njet.auxd &= led;
119 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
120 }
121 break;
122 case (L1_MODE_TRANS):
123 break;
124 case (L1_MODE_HDLC_56K):
125 case (L1_MODE_HDLC):
126 fill_mem(bcs, bcs->hw.tiger.send,
127 NETJET_DMA_TXSIZE, bc, 0xff);
128 bcs->hw.tiger.r_state = HDLC_ZERO_SEARCH;
129 bcs->hw.tiger.r_tot = 0;
130 bcs->hw.tiger.r_bitcnt = 0;
131 bcs->hw.tiger.r_one = 0;
132 bcs->hw.tiger.r_err = 0;
133 bcs->hw.tiger.s_tot = 0;
134 if (!cs->hw.njet.dmactrl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 fill_mem(bcs, bcs->hw.tiger.send,
Joe Perches475be4d2012-02-19 19:52:38 -0800136 NETJET_DMA_TXSIZE, !bc, 0xff);
137 cs->hw.njet.dmactrl = 1;
138 byteout(cs->hw.njet.base + NETJET_DMACTRL,
139 cs->hw.njet.dmactrl);
140 byteout(cs->hw.njet.base + NETJET_IRQMASK0, 0x0f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 /* was 0x3f now 0x0f for TJ300 and TJ320 GE 13/07/00 */
Joe Perches475be4d2012-02-19 19:52:38 -0800142 }
143 bcs->hw.tiger.sendp = bcs->hw.tiger.send;
144 bcs->hw.tiger.free = NETJET_DMA_TXSIZE;
145 test_and_set_bit(BC_FLG_EMPTY, &bcs->Flag);
146 if (cs->typ == ISDN_CTYPE_NETJET_S)
147 {
148 // led on
149 led = bc & 0x01;
150 led = 0x01 << (6 + led); // convert to mask
151 cs->hw.njet.auxd |= led;
152 byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
153 }
154 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 }
156 if (cs->debug & L1_DEB_HSCX)
157 debugl1(cs, "tiger: set %x %x %x %x/%x pulse=%d",
158 bytein(cs->hw.njet.base + NETJET_DMACTRL),
159 bytein(cs->hw.njet.base + NETJET_IRQMASK0),
160 bytein(cs->hw.njet.base + NETJET_IRQSTAT0),
161 inl(cs->hw.njet.base + NETJET_DMA_READ_ADR),
162 inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR),
163 bytein(cs->hw.njet.base + NETJET_PULSE_CNT));
164}
165
166static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s) {
167 char tmp[128];
168 char *t = tmp;
Joe Perches475be4d2012-02-19 19:52:38 -0800169 int i = count, j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 u_char *p = buf;
171
172 t += sprintf(t, "tiger %s(%4d)", s, count);
Joe Perches475be4d2012-02-19 19:52:38 -0800173 while (i > 0) {
174 if (i > 16)
175 j = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 else
Joe Perches475be4d2012-02-19 19:52:38 -0800177 j = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 QuickHex(t, p, j);
Kees Cook35a4a572013-09-13 14:52:04 -0700179 debugl1(cs, "%s", tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 p += j;
181 i -= j;
182 t = tmp;
183 t += sprintf(t, "tiger %s ", s);
184 }
185}
186
187// macro for 64k
188
Joe Perches475be4d2012-02-19 19:52:38 -0800189#define MAKE_RAW_BYTE for (j = 0; j < 8; j++) { \
190 bitcnt++; \
191 s_val >>= 1; \
192 if (val & 1) { \
193 s_one++; \
194 s_val |= 0x80; \
195 } else { \
196 s_one = 0; \
197 s_val &= 0x7f; \
198 } \
199 if (bitcnt == 8) { \
200 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
201 bitcnt = 0; \
202 } \
203 if (s_one == 5) { \
204 s_val >>= 1; \
205 s_val &= 0x7f; \
206 bitcnt++; \
207 s_one = 0; \
208 } \
209 if (bitcnt == 8) { \
210 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
211 bitcnt = 0; \
212 } \
213 val >>= 1; \
214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216static int make_raw_data(struct BCState *bcs) {
217// this make_raw is for 64k
Joe Perches475be4d2012-02-19 19:52:38 -0800218 register u_int i, s_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 register u_char j;
220 register u_char val;
221 register u_char s_one = 0;
222 register u_char s_val = 0;
223 register u_char bitcnt = 0;
224 u_int fcs;
Joe Perches475be4d2012-02-19 19:52:38 -0800225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (!bcs->tx_skb) {
227 debugl1(bcs->cs, "tiger make_raw: NULL skb");
Joe Perches475be4d2012-02-19 19:52:38 -0800228 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
230 bcs->hw.tiger.sendbuf[s_cnt++] = HDLC_FLAG_VALUE;
231 fcs = PPP_INITFCS;
Joe Perches475be4d2012-02-19 19:52:38 -0800232 for (i = 0; i < bcs->tx_skb->len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 val = bcs->tx_skb->data[i];
Joe Perches475be4d2012-02-19 19:52:38 -0800234 fcs = PPP_FCS(fcs, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 MAKE_RAW_BYTE;
236 }
237 fcs ^= 0xffff;
238 val = fcs & 0xff;
239 MAKE_RAW_BYTE;
Joe Perches475be4d2012-02-19 19:52:38 -0800240 val = (fcs >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 MAKE_RAW_BYTE;
242 val = HDLC_FLAG_VALUE;
Joe Perches475be4d2012-02-19 19:52:38 -0800243 for (j = 0; j < 8; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 bitcnt++;
245 s_val >>= 1;
246 if (val & 1)
247 s_val |= 0x80;
248 else
249 s_val &= 0x7f;
Joe Perches475be4d2012-02-19 19:52:38 -0800250 if (bitcnt == 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
252 bitcnt = 0;
253 }
254 val >>= 1;
255 }
256 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800257 debugl1(bcs->cs, "tiger make_raw: in %u out %d.%d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 bcs->tx_skb->len, s_cnt, bitcnt);
259 if (bitcnt) {
Joe Perches475be4d2012-02-19 19:52:38 -0800260 while (8 > bitcnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 s_val >>= 1;
262 s_val |= 0x80;
263 }
264 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
265 bcs->hw.tiger.sendbuf[s_cnt++] = 0xff; // NJ<->NJ thoughput bug fix
266 }
267 bcs->hw.tiger.sendcnt = s_cnt;
268 bcs->tx_cnt -= bcs->tx_skb->len;
269 bcs->hw.tiger.sp = bcs->hw.tiger.sendbuf;
Joe Perches475be4d2012-02-19 19:52:38 -0800270 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271}
272
273// macro for 56k
274
Joe Perches475be4d2012-02-19 19:52:38 -0800275#define MAKE_RAW_BYTE_56K for (j = 0; j < 8; j++) { \
276 bitcnt++; \
277 s_val >>= 1; \
278 if (val & 1) { \
279 s_one++; \
280 s_val |= 0x80; \
281 } else { \
282 s_one = 0; \
283 s_val &= 0x7f; \
284 } \
285 if (bitcnt == 7) { \
286 s_val >>= 1; \
287 s_val |= 0x80; \
288 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
289 bitcnt = 0; \
290 } \
291 if (s_one == 5) { \
292 s_val >>= 1; \
293 s_val &= 0x7f; \
294 bitcnt++; \
295 s_one = 0; \
296 } \
297 if (bitcnt == 7) { \
298 s_val >>= 1; \
299 s_val |= 0x80; \
300 bcs->hw.tiger.sendbuf[s_cnt++] = s_val; \
301 bitcnt = 0; \
302 } \
303 val >>= 1; \
304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306static int make_raw_data_56k(struct BCState *bcs) {
307// this make_raw is for 56k
Joe Perches475be4d2012-02-19 19:52:38 -0800308 register u_int i, s_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 register u_char j;
310 register u_char val;
311 register u_char s_one = 0;
312 register u_char s_val = 0;
313 register u_char bitcnt = 0;
314 u_int fcs;
Joe Perches475be4d2012-02-19 19:52:38 -0800315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 if (!bcs->tx_skb) {
317 debugl1(bcs->cs, "tiger make_raw_56k: NULL skb");
Joe Perches475be4d2012-02-19 19:52:38 -0800318 return (1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320 val = HDLC_FLAG_VALUE;
Joe Perches475be4d2012-02-19 19:52:38 -0800321 for (j = 0; j < 8; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 bitcnt++;
323 s_val >>= 1;
324 if (val & 1)
325 s_val |= 0x80;
326 else
327 s_val &= 0x7f;
Joe Perches475be4d2012-02-19 19:52:38 -0800328 if (bitcnt == 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 s_val >>= 1;
330 s_val |= 0x80;
331 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
332 bitcnt = 0;
333 }
334 val >>= 1;
335 };
336 fcs = PPP_INITFCS;
Joe Perches475be4d2012-02-19 19:52:38 -0800337 for (i = 0; i < bcs->tx_skb->len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 val = bcs->tx_skb->data[i];
Joe Perches475be4d2012-02-19 19:52:38 -0800339 fcs = PPP_FCS(fcs, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 MAKE_RAW_BYTE_56K;
341 }
342 fcs ^= 0xffff;
343 val = fcs & 0xff;
344 MAKE_RAW_BYTE_56K;
Joe Perches475be4d2012-02-19 19:52:38 -0800345 val = (fcs >> 8) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 MAKE_RAW_BYTE_56K;
347 val = HDLC_FLAG_VALUE;
Joe Perches475be4d2012-02-19 19:52:38 -0800348 for (j = 0; j < 8; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 bitcnt++;
350 s_val >>= 1;
351 if (val & 1)
352 s_val |= 0x80;
353 else
354 s_val &= 0x7f;
Joe Perches475be4d2012-02-19 19:52:38 -0800355 if (bitcnt == 7) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 s_val >>= 1;
357 s_val |= 0x80;
358 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
359 bitcnt = 0;
360 }
361 val >>= 1;
362 }
363 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800364 debugl1(bcs->cs, "tiger make_raw_56k: in %u out %d.%d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 bcs->tx_skb->len, s_cnt, bitcnt);
366 if (bitcnt) {
Joe Perches475be4d2012-02-19 19:52:38 -0800367 while (8 > bitcnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 s_val >>= 1;
369 s_val |= 0x80;
370 }
371 bcs->hw.tiger.sendbuf[s_cnt++] = s_val;
372 bcs->hw.tiger.sendbuf[s_cnt++] = 0xff; // NJ<->NJ thoughput bug fix
373 }
374 bcs->hw.tiger.sendcnt = s_cnt;
375 bcs->tx_cnt -= bcs->tx_skb->len;
376 bcs->hw.tiger.sp = bcs->hw.tiger.sendbuf;
Joe Perches475be4d2012-02-19 19:52:38 -0800377 return (0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380static void got_frame(struct BCState *bcs, int count) {
381 struct sk_buff *skb;
Joe Perches475be4d2012-02-19 19:52:38 -0800382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (!(skb = dev_alloc_skb(count)))
384 printk(KERN_WARNING "TIGER: receive out of memory\n");
385 else {
Johannes Berg59ae1d12017-06-16 14:29:20 +0200386 skb_put_data(skb, bcs->hw.tiger.rcvbuf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 skb_queue_tail(&bcs->rqueue, skb);
388 }
389 test_and_set_bit(B_RCVBUFREADY, &bcs->event);
390 schedule_work(&bcs->tqueue);
Joe Perches475be4d2012-02-19 19:52:38 -0800391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 if (bcs->cs->debug & L1_DEB_RECEIVE_FRAME)
393 printframe(bcs->cs, bcs->hw.tiger.rcvbuf, count, "rec");
394}
395
396
397
Joe Perches475be4d2012-02-19 19:52:38 -0800398static void read_raw(struct BCState *bcs, u_int *buf, int cnt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 int i;
400 register u_char j;
401 register u_char val;
Joe Perches475be4d2012-02-19 19:52:38 -0800402 u_int *pend = bcs->hw.tiger.rec + NETJET_DMA_RXSIZE - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 register u_char state = bcs->hw.tiger.r_state;
404 register u_char r_one = bcs->hw.tiger.r_one;
405 register u_char r_val = bcs->hw.tiger.r_val;
406 register u_int bitcnt = bcs->hw.tiger.r_bitcnt;
407 u_int *p = buf;
408 int bits;
409 u_char mask;
410
Joe Perches475be4d2012-02-19 19:52:38 -0800411 if (bcs->mode == L1_MODE_HDLC) { // it's 64k
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 mask = 0xff;
413 bits = 8;
414 }
415 else { // it's 56K
416 mask = 0x7f;
417 bits = 7;
418 };
Joe Perches475be4d2012-02-19 19:52:38 -0800419 for (i = 0; i < cnt; i++) {
420 val = bcs->channel ? ((*p >> 8) & 0xff) : (*p & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 p++;
422 if (p > pend)
423 p = bcs->hw.tiger.rec;
424 if ((val & mask) == mask) {
425 state = HDLC_ZERO_SEARCH;
426 bcs->hw.tiger.r_tot++;
427 bitcnt = 0;
428 r_one = 0;
429 continue;
430 }
Joe Perches475be4d2012-02-19 19:52:38 -0800431 for (j = 0; j < bits; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 if (state == HDLC_ZERO_SEARCH) {
433 if (val & 1) {
434 r_one++;
435 } else {
Joe Perches475be4d2012-02-19 19:52:38 -0800436 r_one = 0;
437 state = HDLC_FLAG_SEARCH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800439 debugl1(bcs->cs, "tiger read_raw: zBit(%d,%d,%d) %x",
440 bcs->hw.tiger.r_tot, i, j, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
Joe Perches475be4d2012-02-19 19:52:38 -0800442 } else if (state == HDLC_FLAG_SEARCH) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 if (val & 1) {
444 r_one++;
Joe Perches475be4d2012-02-19 19:52:38 -0800445 if (r_one > 6) {
446 state = HDLC_ZERO_SEARCH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 }
448 } else {
Joe Perches475be4d2012-02-19 19:52:38 -0800449 if (r_one == 6) {
450 bitcnt = 0;
451 r_val = 0;
452 state = HDLC_FLAG_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800454 debugl1(bcs->cs, "tiger read_raw: flag(%d,%d,%d) %x",
455 bcs->hw.tiger.r_tot, i, j, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
Joe Perches475be4d2012-02-19 19:52:38 -0800457 r_one = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
Joe Perches475be4d2012-02-19 19:52:38 -0800459 } else if (state == HDLC_FLAG_FOUND) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 if (val & 1) {
461 r_one++;
Joe Perches475be4d2012-02-19 19:52:38 -0800462 if (r_one > 6) {
463 state = HDLC_ZERO_SEARCH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 } else {
465 r_val >>= 1;
466 r_val |= 0x80;
467 bitcnt++;
468 }
469 } else {
Joe Perches475be4d2012-02-19 19:52:38 -0800470 if (r_one == 6) {
471 bitcnt = 0;
472 r_val = 0;
473 r_one = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 val >>= 1;
475 continue;
Joe Perches475be4d2012-02-19 19:52:38 -0800476 } else if (r_one != 5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 r_val >>= 1;
478 r_val &= 0x7f;
479 bitcnt++;
480 }
Joe Perches475be4d2012-02-19 19:52:38 -0800481 r_one = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 }
483 if ((state != HDLC_ZERO_SEARCH) &&
Joe Perches475be4d2012-02-19 19:52:38 -0800484 !(bitcnt & 7)) {
485 state = HDLC_FRAME_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 bcs->hw.tiger.r_fcs = PPP_INITFCS;
487 bcs->hw.tiger.rcvbuf[0] = r_val;
Joe Perches475be4d2012-02-19 19:52:38 -0800488 bcs->hw.tiger.r_fcs = PPP_FCS(bcs->hw.tiger.r_fcs, r_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800490 debugl1(bcs->cs, "tiger read_raw: byte1(%d,%d,%d) rval %x val %x i %x",
491 bcs->hw.tiger.r_tot, i, j, r_val, val,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 bcs->cs->hw.njet.irqstat0);
493 }
494 } else if (state == HDLC_FRAME_FOUND) {
495 if (val & 1) {
496 r_one++;
Joe Perches475be4d2012-02-19 19:52:38 -0800497 if (r_one > 6) {
498 state = HDLC_ZERO_SEARCH;
499 bitcnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 } else {
501 r_val >>= 1;
502 r_val |= 0x80;
503 bitcnt++;
504 }
505 } else {
Joe Perches475be4d2012-02-19 19:52:38 -0800506 if (r_one == 6) {
507 r_val = 0;
508 r_one = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 bitcnt++;
510 if (bitcnt & 7) {
511 debugl1(bcs->cs, "tiger: frame not byte aligned");
Joe Perches475be4d2012-02-19 19:52:38 -0800512 state = HDLC_FLAG_SEARCH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 bcs->hw.tiger.r_err++;
514#ifdef ERROR_STATISTIC
515 bcs->err_inv++;
516#endif
517 } else {
518 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800519 debugl1(bcs->cs, "tiger frame end(%d,%d): fcs(%x) i %x",
520 i, j, bcs->hw.tiger.r_fcs, bcs->cs->hw.njet.irqstat0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (bcs->hw.tiger.r_fcs == PPP_GOODFCS) {
Joe Perches475be4d2012-02-19 19:52:38 -0800522 got_frame(bcs, (bitcnt >> 3) - 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 } else {
524 if (bcs->cs->debug) {
525 debugl1(bcs->cs, "tiger FCS error");
526 printframe(bcs->cs, bcs->hw.tiger.rcvbuf,
Joe Perches475be4d2012-02-19 19:52:38 -0800527 (bitcnt >> 3) - 1, "rec");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 bcs->hw.tiger.r_err++;
529 }
530#ifdef ERROR_STATISTIC
Joe Perches475be4d2012-02-19 19:52:38 -0800531 bcs->err_crc++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532#endif
533 }
Joe Perches475be4d2012-02-19 19:52:38 -0800534 state = HDLC_FLAG_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
Joe Perches475be4d2012-02-19 19:52:38 -0800536 bitcnt = 0;
537 } else if (r_one == 5) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 val >>= 1;
Joe Perches475be4d2012-02-19 19:52:38 -0800539 r_one = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 continue;
541 } else {
542 r_val >>= 1;
543 r_val &= 0x7f;
544 bitcnt++;
545 }
Joe Perches475be4d2012-02-19 19:52:38 -0800546 r_one = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
548 if ((state == HDLC_FRAME_FOUND) &&
Joe Perches475be4d2012-02-19 19:52:38 -0800549 !(bitcnt & 7)) {
550 if ((bitcnt >> 3) >= HSCX_BUFMAX) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 debugl1(bcs->cs, "tiger: frame too big");
Joe Perches475be4d2012-02-19 19:52:38 -0800552 r_val = 0;
553 state = HDLC_FLAG_SEARCH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 bcs->hw.tiger.r_err++;
555#ifdef ERROR_STATISTIC
556 bcs->err_inv++;
557#endif
558 } else {
Joe Perches475be4d2012-02-19 19:52:38 -0800559 bcs->hw.tiger.rcvbuf[(bitcnt >> 3) - 1] = r_val;
560 bcs->hw.tiger.r_fcs =
561 PPP_FCS(bcs->hw.tiger.r_fcs, r_val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563 }
564 }
565 val >>= 1;
566 }
567 bcs->hw.tiger.r_tot++;
568 }
569 bcs->hw.tiger.r_state = state;
570 bcs->hw.tiger.r_one = r_one;
571 bcs->hw.tiger.r_val = r_val;
572 bcs->hw.tiger.r_bitcnt = bitcnt;
573}
574
575void read_tiger(struct IsdnCardState *cs) {
576 u_int *p;
Joe Perches475be4d2012-02-19 19:52:38 -0800577 int cnt = NETJET_DMA_RXSIZE / 2;
578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if ((cs->hw.njet.irqstat0 & cs->hw.njet.last_is0) & NETJET_IRQM0_READ) {
Joe Perches475be4d2012-02-19 19:52:38 -0800580 debugl1(cs, "tiger warn read double dma %x/%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 cs->hw.njet.irqstat0, cs->hw.njet.last_is0);
582#ifdef ERROR_STATISTIC
583 if (cs->bcs[0].mode)
584 cs->bcs[0].err_rdo++;
585 if (cs->bcs[1].mode)
586 cs->bcs[1].err_rdo++;
587#endif
588 return;
589 } else {
590 cs->hw.njet.last_is0 &= ~NETJET_IRQM0_READ;
591 cs->hw.njet.last_is0 |= (cs->hw.njet.irqstat0 & NETJET_IRQM0_READ);
Joe Perches475be4d2012-02-19 19:52:38 -0800592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (cs->hw.njet.irqstat0 & NETJET_IRQM0_READ_1)
594 p = cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE - 1;
595 else
596 p = cs->bcs[0].hw.tiger.rec + cnt - 1;
597 if ((cs->bcs[0].mode == L1_MODE_HDLC) || (cs->bcs[0].mode == L1_MODE_HDLC_56K))
598 read_raw(cs->bcs, p, cnt);
599
600 if ((cs->bcs[1].mode == L1_MODE_HDLC) || (cs->bcs[1].mode == L1_MODE_HDLC_56K))
601 read_raw(cs->bcs + 1, p, cnt);
602 cs->hw.njet.irqstat0 &= ~NETJET_IRQM0_READ;
603}
604
605static void write_raw(struct BCState *bcs, u_int *buf, int cnt);
606
607void netjet_fill_dma(struct BCState *bcs)
608{
609 register u_int *p, *sp;
610 register int cnt;
611
612 if (!bcs->tx_skb)
613 return;
614 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800615 debugl1(bcs->cs, "tiger fill_dma1: c%d %4lx", bcs->channel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 bcs->Flag);
617 if (test_and_set_bit(BC_FLG_BUSY, &bcs->Flag))
618 return;
619 if (bcs->mode == L1_MODE_HDLC) { // it's 64k
620 if (make_raw_data(bcs))
Joe Perches475be4d2012-02-19 19:52:38 -0800621 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623 else { // it's 56k
624 if (make_raw_data_56k(bcs))
Joe Perches475be4d2012-02-19 19:52:38 -0800625 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 };
627 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800628 debugl1(bcs->cs, "tiger fill_dma2: c%d %4lx", bcs->channel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 bcs->Flag);
630 if (test_and_clear_bit(BC_FLG_NOFRAME, &bcs->Flag)) {
631 write_raw(bcs, bcs->hw.tiger.sendp, bcs->hw.tiger.free);
632 } else if (test_and_clear_bit(BC_FLG_HALF, &bcs->Flag)) {
633 p = bus_to_virt(inl(bcs->cs->hw.njet.base + NETJET_DMA_READ_ADR));
634 sp = bcs->hw.tiger.sendp;
635 if (p == bcs->hw.tiger.s_end)
Joe Perches475be4d2012-02-19 19:52:38 -0800636 p = bcs->hw.tiger.send - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (sp == bcs->hw.tiger.s_end)
Joe Perches475be4d2012-02-19 19:52:38 -0800638 sp = bcs->hw.tiger.send - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 cnt = p - sp;
Joe Perches475be4d2012-02-19 19:52:38 -0800640 if (cnt < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 write_raw(bcs, bcs->hw.tiger.sendp, bcs->hw.tiger.free);
642 } else {
643 p++;
644 cnt++;
645 if (p > bcs->hw.tiger.s_end)
646 p = bcs->hw.tiger.send;
647 p++;
648 cnt++;
649 if (p > bcs->hw.tiger.s_end)
650 p = bcs->hw.tiger.send;
651 write_raw(bcs, p, bcs->hw.tiger.free - cnt);
652 }
653 } else if (test_and_clear_bit(BC_FLG_EMPTY, &bcs->Flag)) {
654 p = bus_to_virt(inl(bcs->cs->hw.njet.base + NETJET_DMA_READ_ADR));
655 cnt = bcs->hw.tiger.s_end - p;
656 if (cnt < 2) {
657 p = bcs->hw.tiger.send + 1;
Joe Perches475be4d2012-02-19 19:52:38 -0800658 cnt = NETJET_DMA_TXSIZE / 2 - 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 } else {
660 p++;
661 p++;
Joe Perches475be4d2012-02-19 19:52:38 -0800662 if (cnt <= (NETJET_DMA_TXSIZE / 2))
663 cnt += NETJET_DMA_TXSIZE / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 cnt--;
665 cnt--;
666 }
667 write_raw(bcs, p, cnt);
668 }
669 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800670 debugl1(bcs->cs, "tiger fill_dma3: c%d %4lx", bcs->channel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 bcs->Flag);
672}
673
674static void write_raw(struct BCState *bcs, u_int *buf, int cnt) {
Joe Perches475be4d2012-02-19 19:52:38 -0800675 u_int mask, val, *p = buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 u_int i, s_cnt;
Joe Perches475be4d2012-02-19 19:52:38 -0800677
678 if (cnt <= 0)
679 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 if (test_bit(BC_FLG_BUSY, &bcs->Flag)) {
Joe Perches475be4d2012-02-19 19:52:38 -0800681 if (bcs->hw.tiger.sendcnt > cnt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 s_cnt = cnt;
683 bcs->hw.tiger.sendcnt -= cnt;
684 } else {
685 s_cnt = bcs->hw.tiger.sendcnt;
686 bcs->hw.tiger.sendcnt = 0;
687 }
688 if (bcs->channel)
689 mask = 0xffff00ff;
690 else
691 mask = 0xffffff00;
Joe Perches475be4d2012-02-19 19:52:38 -0800692 for (i = 0; i < s_cnt; i++) {
693 val = bcs->channel ? ((bcs->hw.tiger.sp[i] << 8) & 0xff00) :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 (bcs->hw.tiger.sp[i]);
Joe Perches475be4d2012-02-19 19:52:38 -0800695 *p &= mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 *p++ |= val;
Joe Perches475be4d2012-02-19 19:52:38 -0800697 if (p > bcs->hw.tiger.s_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 p = bcs->hw.tiger.send;
699 }
700 bcs->hw.tiger.s_tot += s_cnt;
701 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800702 debugl1(bcs->cs, "tiger write_raw: c%d %p-%p %d/%d %d %x", bcs->channel,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 buf, p, s_cnt, cnt,
704 bcs->hw.tiger.sendcnt, bcs->cs->hw.njet.irqstat0);
705 if (bcs->cs->debug & L1_DEB_HSCX_FIFO)
706 printframe(bcs->cs, bcs->hw.tiger.sp, s_cnt, "snd");
707 bcs->hw.tiger.sp += s_cnt;
708 bcs->hw.tiger.sendp = p;
709 if (!bcs->hw.tiger.sendcnt) {
710 if (!bcs->tx_skb) {
Joe Perches475be4d2012-02-19 19:52:38 -0800711 debugl1(bcs->cs, "tiger write_raw: NULL skb s_cnt %d", s_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 } else {
Joe Perches475be4d2012-02-19 19:52:38 -0800713 if (test_bit(FLG_LLI_L1WAKEUP, &bcs->st->lli.flag) &&
714 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 u_long flags;
716 spin_lock_irqsave(&bcs->aclock, flags);
717 bcs->ackcnt += bcs->tx_skb->len;
718 spin_unlock_irqrestore(&bcs->aclock, flags);
719 schedule_event(bcs, B_ACKPENDING);
720 }
721 dev_kfree_skb_any(bcs->tx_skb);
722 bcs->tx_skb = NULL;
723 }
724 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
725 bcs->hw.tiger.free = cnt - s_cnt;
Joe Perches475be4d2012-02-19 19:52:38 -0800726 if (bcs->hw.tiger.free > (NETJET_DMA_TXSIZE / 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 test_and_set_bit(BC_FLG_HALF, &bcs->Flag);
728 else {
729 test_and_clear_bit(BC_FLG_HALF, &bcs->Flag);
730 test_and_set_bit(BC_FLG_NOFRAME, &bcs->Flag);
731 }
732 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
733 netjet_fill_dma(bcs);
734 } else {
735 mask ^= 0xffffffff;
736 if (s_cnt < cnt) {
Joe Perches475be4d2012-02-19 19:52:38 -0800737 for (i = s_cnt; i < cnt; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 *p++ |= mask;
Joe Perches475be4d2012-02-19 19:52:38 -0800739 if (p > bcs->hw.tiger.s_end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 p = bcs->hw.tiger.send;
741 }
742 if (bcs->cs->debug & L1_DEB_HSCX)
743 debugl1(bcs->cs, "tiger write_raw: fill rest %d",
744 cnt - s_cnt);
745 }
746 test_and_set_bit(B_XMTBUFREADY, &bcs->event);
747 schedule_work(&bcs->tqueue);
748 }
749 }
750 } else if (test_and_clear_bit(BC_FLG_NOFRAME, &bcs->Flag)) {
751 test_and_set_bit(BC_FLG_HALF, &bcs->Flag);
752 fill_mem(bcs, buf, cnt, bcs->channel, 0xff);
753 bcs->hw.tiger.free += cnt;
754 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800755 debugl1(bcs->cs, "tiger write_raw: fill half");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 } else if (test_and_clear_bit(BC_FLG_HALF, &bcs->Flag)) {
757 test_and_set_bit(BC_FLG_EMPTY, &bcs->Flag);
758 fill_mem(bcs, buf, cnt, bcs->channel, 0xff);
759 if (bcs->cs->debug & L1_DEB_HSCX)
Joe Perches475be4d2012-02-19 19:52:38 -0800760 debugl1(bcs->cs, "tiger write_raw: fill full");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 }
762}
763
764void write_tiger(struct IsdnCardState *cs) {
Joe Perches475be4d2012-02-19 19:52:38 -0800765 u_int *p, cnt = NETJET_DMA_TXSIZE / 2;
766
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if ((cs->hw.njet.irqstat0 & cs->hw.njet.last_is0) & NETJET_IRQM0_WRITE) {
Joe Perches475be4d2012-02-19 19:52:38 -0800768 debugl1(cs, "tiger warn write double dma %x/%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 cs->hw.njet.irqstat0, cs->hw.njet.last_is0);
770#ifdef ERROR_STATISTIC
771 if (cs->bcs[0].mode)
772 cs->bcs[0].err_tx++;
773 if (cs->bcs[1].mode)
774 cs->bcs[1].err_tx++;
775#endif
776 return;
777 } else {
778 cs->hw.njet.last_is0 &= ~NETJET_IRQM0_WRITE;
779 cs->hw.njet.last_is0 |= (cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE);
Joe Perches475be4d2012-02-19 19:52:38 -0800780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 if (cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE_1)
782 p = cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE - 1;
783 else
784 p = cs->bcs[0].hw.tiger.send + cnt - 1;
785 if ((cs->bcs[0].mode == L1_MODE_HDLC) || (cs->bcs[0].mode == L1_MODE_HDLC_56K))
786 write_raw(cs->bcs, p, cnt);
787 if ((cs->bcs[1].mode == L1_MODE_HDLC) || (cs->bcs[1].mode == L1_MODE_HDLC_56K))
788 write_raw(cs->bcs + 1, p, cnt);
789 cs->hw.njet.irqstat0 &= ~NETJET_IRQM0_WRITE;
790}
791
792static void
793tiger_l2l1(struct PStack *st, int pr, void *arg)
794{
795 struct BCState *bcs = st->l1.bcs;
796 struct sk_buff *skb = arg;
797 u_long flags;
798
799 switch (pr) {
Joe Perches475be4d2012-02-19 19:52:38 -0800800 case (PH_DATA | REQUEST):
801 spin_lock_irqsave(&bcs->cs->lock, flags);
802 if (bcs->tx_skb) {
803 skb_queue_tail(&bcs->squeue, skb);
804 } else {
805 bcs->tx_skb = skb;
806 bcs->cs->BC_Send_Data(bcs);
807 }
808 spin_unlock_irqrestore(&bcs->cs->lock, flags);
809 break;
810 case (PH_PULL | INDICATION):
811 spin_lock_irqsave(&bcs->cs->lock, flags);
812 if (bcs->tx_skb) {
813 printk(KERN_WARNING "tiger_l2l1: this shouldn't happen\n");
814 } else {
815 bcs->tx_skb = skb;
816 bcs->cs->BC_Send_Data(bcs);
817 }
818 spin_unlock_irqrestore(&bcs->cs->lock, flags);
819 break;
820 case (PH_PULL | REQUEST):
821 if (!bcs->tx_skb) {
822 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
823 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
824 } else
825 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
826 break;
827 case (PH_ACTIVATE | REQUEST):
828 spin_lock_irqsave(&bcs->cs->lock, flags);
829 test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
830 mode_tiger(bcs, st->l1.mode, st->l1.bc);
831 /* 2001/10/04 Christoph Ersfeld, Formula-n Europe AG */
832 spin_unlock_irqrestore(&bcs->cs->lock, flags);
833 bcs->cs->cardmsg(bcs->cs, MDL_BC_ASSIGN, (void *)(&st->l1.bc));
834 l1_msg_b(st, pr, arg);
835 break;
836 case (PH_DEACTIVATE | REQUEST):
837 /* 2001/10/04 Christoph Ersfeld, Formula-n Europe AG */
838 bcs->cs->cardmsg(bcs->cs, MDL_BC_RELEASE, (void *)(&st->l1.bc));
839 l1_msg_b(st, pr, arg);
840 break;
841 case (PH_DEACTIVATE | CONFIRM):
842 spin_lock_irqsave(&bcs->cs->lock, flags);
843 test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
844 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
845 mode_tiger(bcs, 0, st->l1.bc);
846 spin_unlock_irqrestore(&bcs->cs->lock, flags);
847 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850}
851
852
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700853static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854close_tigerstate(struct BCState *bcs)
855{
856 mode_tiger(bcs, 0, bcs->channel);
857 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
Jesper Juhl3c7208f2005-11-07 01:01:29 -0800858 kfree(bcs->hw.tiger.rcvbuf);
859 bcs->hw.tiger.rcvbuf = NULL;
860 kfree(bcs->hw.tiger.sendbuf);
861 bcs->hw.tiger.sendbuf = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 skb_queue_purge(&bcs->rqueue);
863 skb_queue_purge(&bcs->squeue);
864 if (bcs->tx_skb) {
865 dev_kfree_skb_any(bcs->tx_skb);
866 bcs->tx_skb = NULL;
867 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
868 }
869 }
870}
871
872static int
873open_tigerstate(struct IsdnCardState *cs, struct BCState *bcs)
874{
875 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
876 if (!(bcs->hw.tiger.rcvbuf = kmalloc(HSCX_BUFMAX, GFP_ATOMIC))) {
877 printk(KERN_WARNING
878 "HiSax: No memory for tiger.rcvbuf\n");
879 return (1);
880 }
881 if (!(bcs->hw.tiger.sendbuf = kmalloc(RAW_BUFMAX, GFP_ATOMIC))) {
882 printk(KERN_WARNING
883 "HiSax: No memory for tiger.sendbuf\n");
884 return (1);
885 }
886 skb_queue_head_init(&bcs->rqueue);
887 skb_queue_head_init(&bcs->squeue);
888 }
889 bcs->tx_skb = NULL;
890 bcs->hw.tiger.sendcnt = 0;
891 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
892 bcs->event = 0;
893 bcs->tx_cnt = 0;
894 return (0);
895}
896
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700897static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898setstack_tiger(struct PStack *st, struct BCState *bcs)
899{
900 bcs->channel = st->l1.bc;
901 if (open_tigerstate(st->l1.hardware, bcs))
902 return (-1);
903 st->l1.bcs = bcs;
904 st->l2.l2l1 = tiger_l2l1;
905 setstack_manager(st);
906 bcs->st = st;
907 setstack_l1_B(st);
908 return (0);
909}
910
Joe Perches475be4d2012-02-19 19:52:38 -0800911
Karsten Keil67eb5db2006-07-10 04:44:11 -0700912void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913inittiger(struct IsdnCardState *cs)
914{
915 if (!(cs->bcs[0].hw.tiger.send = kmalloc(NETJET_DMA_TXSIZE * sizeof(unsigned int),
Joe Perches475be4d2012-02-19 19:52:38 -0800916 GFP_KERNEL | GFP_DMA))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 printk(KERN_WARNING
918 "HiSax: No memory for tiger.send\n");
919 return;
920 }
Joe Perches475be4d2012-02-19 19:52:38 -0800921 cs->bcs[0].hw.tiger.s_irq = cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE / 2 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 cs->bcs[0].hw.tiger.s_end = cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE - 1;
923 cs->bcs[1].hw.tiger.send = cs->bcs[0].hw.tiger.send;
924 cs->bcs[1].hw.tiger.s_irq = cs->bcs[0].hw.tiger.s_irq;
925 cs->bcs[1].hw.tiger.s_end = cs->bcs[0].hw.tiger.s_end;
Joe Perches475be4d2012-02-19 19:52:38 -0800926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 memset(cs->bcs[0].hw.tiger.send, 0xff, NETJET_DMA_TXSIZE * sizeof(unsigned int));
928 debugl1(cs, "tiger: send buf %p - %p", cs->bcs[0].hw.tiger.send,
929 cs->bcs[0].hw.tiger.send + NETJET_DMA_TXSIZE - 1);
930 outl(virt_to_bus(cs->bcs[0].hw.tiger.send),
Joe Perches475be4d2012-02-19 19:52:38 -0800931 cs->hw.njet.base + NETJET_DMA_READ_START);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 outl(virt_to_bus(cs->bcs[0].hw.tiger.s_irq),
Joe Perches475be4d2012-02-19 19:52:38 -0800933 cs->hw.njet.base + NETJET_DMA_READ_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 outl(virt_to_bus(cs->bcs[0].hw.tiger.s_end),
Joe Perches475be4d2012-02-19 19:52:38 -0800935 cs->hw.njet.base + NETJET_DMA_READ_END);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (!(cs->bcs[0].hw.tiger.rec = kmalloc(NETJET_DMA_RXSIZE * sizeof(unsigned int),
Joe Perches475be4d2012-02-19 19:52:38 -0800937 GFP_KERNEL | GFP_DMA))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 printk(KERN_WARNING
939 "HiSax: No memory for tiger.rec\n");
940 return;
941 }
942 debugl1(cs, "tiger: rec buf %p - %p", cs->bcs[0].hw.tiger.rec,
943 cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE - 1);
944 cs->bcs[1].hw.tiger.rec = cs->bcs[0].hw.tiger.rec;
945 memset(cs->bcs[0].hw.tiger.rec, 0xff, NETJET_DMA_RXSIZE * sizeof(unsigned int));
946 outl(virt_to_bus(cs->bcs[0].hw.tiger.rec),
Joe Perches475be4d2012-02-19 19:52:38 -0800947 cs->hw.njet.base + NETJET_DMA_WRITE_START);
948 outl(virt_to_bus(cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE / 2 - 1),
949 cs->hw.njet.base + NETJET_DMA_WRITE_IRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 outl(virt_to_bus(cs->bcs[0].hw.tiger.rec + NETJET_DMA_RXSIZE - 1),
Joe Perches475be4d2012-02-19 19:52:38 -0800951 cs->hw.njet.base + NETJET_DMA_WRITE_END);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 debugl1(cs, "tiger: dmacfg %x/%x pulse=%d",
953 inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR),
954 inl(cs->hw.njet.base + NETJET_DMA_READ_ADR),
955 bytein(cs->hw.njet.base + NETJET_PULSE_CNT));
956 cs->hw.njet.last_is0 = 0;
957 cs->bcs[0].BC_SetStack = setstack_tiger;
958 cs->bcs[1].BC_SetStack = setstack_tiger;
959 cs->bcs[0].BC_Close = close_tigerstate;
960 cs->bcs[1].BC_Close = close_tigerstate;
961}
962
Adrian Bunk672c3fd2005-06-25 14:59:18 -0700963static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964releasetiger(struct IsdnCardState *cs)
965{
Jesper Juhl3c7208f2005-11-07 01:01:29 -0800966 kfree(cs->bcs[0].hw.tiger.send);
967 cs->bcs[0].hw.tiger.send = NULL;
968 cs->bcs[1].hw.tiger.send = NULL;
969 kfree(cs->bcs[0].hw.tiger.rec);
970 cs->bcs[0].hw.tiger.rec = NULL;
971 cs->bcs[1].hw.tiger.rec = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972}
973
974void
975release_io_netjet(struct IsdnCardState *cs)
976{
977 byteout(cs->hw.njet.base + NETJET_IRQMASK0, 0);
978 byteout(cs->hw.njet.base + NETJET_IRQMASK1, 0);
979 releasetiger(cs);
980 release_region(cs->hw.njet.base, 256);
981}