~ubuntu-branches/ubuntu/quantal/zaptel/quantal

« back to all changes in this revision

Viewing changes to kernel/vzaphfc/vzaphfc_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Tzafrir Cohen
  • Date: 2008-08-28 22:58:23 UTC
  • mfrom: (11.1.11 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080828225823-r8bdunirm8hmc76m
Tags: 1:1.4.11~dfsg-2
* Patch xpp_fxs_power: Fixed an issue with hook detection of the Astribank
  FXS module.
* Don't fail init.d script if fxotune fails. This may happen if running it
  when Asterisk is already running.
* Bump standards version to 3.8.0.0 .
* Ignore false lintian warning ("m-a a-i" has "a a").
* Patch xpp_fxo_cid_always: do always pass PCM if that's what the user
  asked.
* Patch vzaphfc_proc_root_dir: fix vzaphfc on 2.6.26.
* Patch wcte12xp_flags: Proper time for irq save flags.
* Patch headers_2627: Fix location of semaphore.h for 2.6.27 .
* Patch xpp_fxs_dtmf_leak: Don't play DTMFs to the wrong channel.
* Patch wctdm_fix_alarm: Fix sending channel alarms.
* Patch device_class_2626: Fix building 2.6.26 (Closes: #493397).
* Using dh_lintian for lintian overrides, hence requiring debhelper 6.0.7.
* Lintian: we know we have direct changes. Too bad we're half-upstream :-(
* Fix doc-base section names. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * zaphfc.c - Zaptel driver for HFC-S PCI A based ISDN BRI cards
 
3
 *
 
4
 * Copyright (C) 2006, headiisue GmbH; Jens Wilke
 
5
 * Copyright (C) 2004 Daniele Orlandi
 
6
 * Copyright (C) 2002, 2003, 2004, Junghanns.NET GmbH
 
7
 *
 
8
 * Jens Wilke <jw_vzaphfc@headissue.com>
 
9
 *
 
10
 * Original author of this code is
 
11
 * Daniele "Vihai" Orlandi <daniele@orlandi.com> 
 
12
 *
 
13
 * Major rewrite of the driver made by
 
14
 * Klaus-Peter Junghanns <kpj@junghanns.net>
 
15
 *
 
16
 * This program is free software and may be modified and
 
17
 * distributed under the terms of the GNU Public License.
 
18
 *
 
19
 * Please read the README file for important infos.
 
20
 */
 
21
 
 
22
#include <linux/spinlock.h>
 
23
#include <linux/init.h>
 
24
#include <linux/pci.h>
 
25
#include <linux/interrupt.h>
 
26
#include <linux/module.h>
 
27
#include <linux/moduleparam.h>
 
28
#include <linux/version.h>
 
29
#include <linux/kernel.h>
 
30
#include <linux/delay.h>
 
31
#include <linux/proc_fs.h>
 
32
#include <linux/netdevice.h>
 
33
#include <linux/if_arp.h>
 
34
 
 
35
#include "vzaphfc.h"
 
36
#include "fifo.h"
 
37
#include "lapd.h"
 
38
 
 
39
#if CONFIG_PCI
 
40
 
 
41
#define ZT_B1 0
 
42
#define ZT_B2 1
 
43
#define ZT_D 2
 
44
 
 
45
#define D 0
 
46
#define B1 1
 
47
#define B2 2
 
48
 
 
49
static int modes = 0; // all TE
 
50
static int nt_modes[hfc_MAX_BOARDS] = { [0 ... (hfc_MAX_BOARDS-1)] = -1 };
 
51
static int force_l1_up = 0;
 
52
static int sniff_zaptel_d_channel = 0;
 
53
static struct proc_dir_entry *hfc_proc_zaphfc_dir;
 
54
 
 
55
#ifdef DEBUG
 
56
int debug_level = 0;
 
57
#endif
 
58
 
 
59
static struct pci_device_id hfc_pci_ids[] = {
 
60
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_2BD0,
 
61
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
62
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B000,
 
63
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
64
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B006,
 
65
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
66
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B007,
 
67
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
68
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B008,
 
69
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
70
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B009,
 
71
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
72
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00A,
 
73
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
74
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00B,
 
75
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
76
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B00C,
 
77
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
78
        {PCI_VENDOR_ID_CCD, PCI_DEVICE_ID_CCD_B100,
 
79
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
80
        {PCI_VENDOR_ID_ABOCOM, PCI_DEVICE_ID_ABOCOM_2BD1,
 
81
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
82
        {PCI_VENDOR_ID_ASUSTEK, PCI_DEVICE_ID_ASUSTEK_0675,
 
83
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
84
        {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_T_CONCEPT,
 
85
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
86
        {PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_A1T,
 
87
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
88
        {PCI_VENDOR_ID_ANIGMA, PCI_DEVICE_ID_ANIGMA_MC145575,
 
89
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
90
        {PCI_VENDOR_ID_ZOLTRIX, PCI_DEVICE_ID_ZOLTRIX_2BD0,
 
91
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
92
        {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_E,
 
93
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
94
        {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_E,
 
95
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
96
        {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_IOM2_A,
 
97
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
98
        {PCI_VENDOR_ID_DIGI, PCI_DEVICE_ID_DIGI_DF_M_A,
 
99
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
100
        {PCI_VENDOR_ID_SITECOM, PCI_DEVICE_ID_SITECOM_3069,
 
101
                PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 
102
        {0,}
 
103
};
 
104
 
 
105
MODULE_DEVICE_TABLE(pci, hfc_pci_ids);
 
106
 
 
107
static int __devinit hfc_probe(struct pci_dev *dev
 
108
                        , const struct pci_device_id *ent);
 
109
static void __devexit hfc_remove(struct pci_dev *dev);
 
110
 
 
111
struct pci_driver hfc_driver = {
 
112
        .name     = hfc_DRIVER_NAME,
 
113
        .id_table = hfc_pci_ids,
 
114
        .probe    = hfc_probe,
 
115
        .remove   = hfc_remove,
 
116
};
 
117
 
 
118
/******************************************
 
119
 * HW routines
 
120
 ******************************************/
 
121
 
 
122
static void hfc_softreset(struct hfc_card *card)
 
123
{
 
124
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
125
                "card %d: "
 
126
                "resetting\n",
 
127
                card->cardnum);
 
128
 
 
129
        hfc_outb(card, hfc_CIRM, hfc_CIRM_RESET);       // softreset on
 
130
        udelay(6);        // wait at least 5.21us
 
131
        hfc_outb(card, hfc_CIRM, 0);    // softreset off
 
132
 
 
133
        set_current_state(TASK_UNINTERRUPTIBLE);
 
134
        schedule_timeout((hfc_RESET_DELAY * HZ) / 1000);        // wait 20 ms
 
135
}
 
136
 
 
137
void hfc_resetCard(struct hfc_card *card)
 
138
{
 
139
        card->regs.m1 = 0;
 
140
        hfc_outb(card, hfc_INT_M1, card->regs.m1);      // no ints
 
141
 
 
142
        card->regs.m2 = 0;
 
143
        hfc_outb(card, hfc_INT_M2, card->regs.m2);      // not at all
 
144
 
 
145
        hfc_softreset(card);
 
146
 
 
147
        card->regs.trm = 0;
 
148
        hfc_outb(card, hfc_TRM, card->regs.trm);
 
149
 
 
150
        // Select the non-capacitive line mode for the S/T interface */
 
151
        card->regs.sctrl = hfc_SCTRL_NONE_CAP;
 
152
 
 
153
        if (card->nt_mode) {
 
154
                // ST-Bit delay for NT-Mode
 
155
                hfc_outb(card, hfc_CLKDEL, hfc_CLKDEL_NT);
 
156
 
 
157
                card->regs.sctrl |= hfc_SCTRL_MODE_NT;
 
158
        } else {
 
159
                // ST-Bit delay for TE-Mode
 
160
                hfc_outb(card, hfc_CLKDEL, hfc_CLKDEL_TE);
 
161
 
 
162
                card->regs.sctrl |= hfc_SCTRL_MODE_TE;
 
163
        }
 
164
 
 
165
        hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
 
166
 
 
167
        // S/T Auto awake
 
168
        card->regs.sctrl_e = hfc_SCTRL_E_AUTO_AWAKE;
 
169
        hfc_outb(card, hfc_SCTRL_E, card->regs.sctrl_e);
 
170
 
 
171
        // No B-channel enabled at startup
 
172
        card->regs.sctrl_r = 0;
 
173
        hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
 
174
 
 
175
        // HFC Master Mode
 
176
        hfc_outb(card, hfc_MST_MODE, hfc_MST_MODE_MASTER);
 
177
 
 
178
        // Connect internal blocks
 
179
        card->regs.connect =
 
180
                hfc_CONNECT_B1_HFC_from_ST |
 
181
                hfc_CONNECT_B1_ST_from_HFC |
 
182
                hfc_CONNECT_B1_GCI_from_HFC |
 
183
                hfc_CONNECT_B2_HFC_from_ST |
 
184
                hfc_CONNECT_B2_ST_from_HFC |
 
185
                hfc_CONNECT_B2_GCI_from_HFC;
 
186
        hfc_outb(card, hfc_CONNECT, card->regs.connect);
 
187
 
 
188
        // All bchans are HDLC by default, not useful, actually
 
189
        // since mode is set during open()
 
190
        hfc_outb(card, hfc_CTMT, 0);
 
191
 
 
192
        // bit order
 
193
        hfc_outb(card, hfc_CIRM, 0);
 
194
 
 
195
        // Enable D-rx FIFO. At least one FIFO must be enabled (by specs)
 
196
        card->regs.fifo_en = hfc_FIFOEN_DRX;
 
197
        hfc_outb(card, hfc_FIFO_EN, card->regs.fifo_en);
 
198
 
 
199
        card->late_irqs=0;
 
200
 
 
201
        // Clear already pending ints
 
202
        hfc_inb(card, hfc_INT_S1);
 
203
        hfc_inb(card, hfc_INT_S2);
 
204
 
 
205
        // Enable IRQ output
 
206
        card->regs.m1 = hfc_INTS_DREC | hfc_INTS_L1STATE | hfc_INTS_TIMER;
 
207
        hfc_outb(card, hfc_INT_M1, card->regs.m1);
 
208
 
 
209
        card->regs.m2 = hfc_M2_IRQ_ENABLE;
 
210
        hfc_outb(card, hfc_INT_M2, card->regs.m2);
 
211
 
 
212
        // Unlocks the states machine
 
213
        hfc_outb(card, hfc_STATES, 0);
 
214
 
 
215
        // There's no need to explicitly activate L1 now.
 
216
        // Activation is managed inside the interrupt routine.
 
217
}
 
218
 
 
219
static void hfc_update_fifo_state(struct hfc_card *card)
 
220
{
 
221
        // I'm not sure if irqsave is needed but there could be a race
 
222
        // condition since hfc_update_fifo_state could be called from
 
223
        // both the IRQ handler and the *_(open|close) functions
 
224
 
 
225
        unsigned long flags;
 
226
        spin_lock_irqsave(&card->chans[B1].lock, flags);
 
227
        if (!card->fifo_suspended &&
 
228
                (card->chans[B1].status == open_framed ||
 
229
                card->chans[B1].status == open_voice)) {
 
230
 
 
231
                if(!(card->regs.fifo_en & hfc_FIFOEN_B1RX)) {
 
232
                        card->regs.fifo_en |= hfc_FIFOEN_B1RX;
 
233
                        hfc_clear_fifo_rx(&card->chans[B1].rx);
 
234
                }
 
235
 
 
236
                if(!(card->regs.fifo_en & hfc_FIFOEN_B1TX)) {
 
237
                        card->regs.fifo_en |= hfc_FIFOEN_B1TX;
 
238
                        hfc_clear_fifo_tx(&card->chans[B1].tx);
 
239
                }
 
240
        } else {
 
241
                if(card->regs.fifo_en & hfc_FIFOEN_B1RX)
 
242
                        card->regs.fifo_en &= ~hfc_FIFOEN_B1RX;
 
243
                if(card->regs.fifo_en & hfc_FIFOEN_B1TX)
 
244
                        card->regs.fifo_en &= ~hfc_FIFOEN_B1TX;
 
245
        }
 
246
        spin_unlock_irqrestore(&card->chans[B1].lock, flags);
 
247
 
 
248
        spin_lock_irqsave(&card->chans[B2].lock, flags);
 
249
        if (!card->fifo_suspended &&
 
250
                (card->chans[B2].status == open_framed ||
 
251
                card->chans[B2].status == open_voice ||
 
252
                card->chans[B2].status == sniff_aux)) {
 
253
 
 
254
                if(!(card->regs.fifo_en & hfc_FIFOEN_B2RX)) {
 
255
                        card->regs.fifo_en |= hfc_FIFOEN_B2RX;
 
256
                        hfc_clear_fifo_rx(&card->chans[B2].rx);
 
257
                }
 
258
 
 
259
                if(!(card->regs.fifo_en & hfc_FIFOEN_B2TX)) {
 
260
                        card->regs.fifo_en |= hfc_FIFOEN_B2TX;
 
261
                        hfc_clear_fifo_tx(&card->chans[B2].tx);
 
262
                }
 
263
        } else {
 
264
                if(card->regs.fifo_en & hfc_FIFOEN_B2RX)
 
265
                        card->regs.fifo_en &= ~hfc_FIFOEN_B2RX;
 
266
                if(card->regs.fifo_en & hfc_FIFOEN_B2TX)
 
267
                        card->regs.fifo_en &= ~hfc_FIFOEN_B2TX;
 
268
        }
 
269
        spin_unlock_irqrestore(&card->chans[B2].lock, flags);
 
270
 
 
271
        spin_lock_irqsave(&card->chans[D].lock, flags);
 
272
        if (!card->fifo_suspended &&
 
273
                card->chans[D].status == open_framed) {
 
274
 
 
275
//              if(!(card->regs.fifo_en & hfc_FIFOEN_DRX)) {
 
276
//                      hfc_clear_fifo_rx(&card->chans[B2].rx);
 
277
//
 
278
//                      card->chans[B2].rx.ugly_framebuf_size = 0;
 
279
//                      card->chans[B2].rx.ugly_framebuf_off = 0;
 
280
//              }
 
281
//
 
282
                if(!(card->regs.fifo_en & hfc_FIFOEN_DTX)) {
 
283
                        card->regs.fifo_en |= hfc_FIFOEN_DTX;
 
284
 
 
285
                        card->chans[D].tx.ugly_framebuf_size = 0;
 
286
                        card->chans[D].tx.ugly_framebuf_off = 0;
 
287
                }
 
288
        } else {
 
289
//              if(card->regs.fifo_en & hfc_FIFOEN_DRX)
 
290
//                      card->regs.fifo_en &= ~hfc_FIFOEN_DRX;
 
291
                if(card->regs.fifo_en & hfc_FIFOEN_DTX)
 
292
                        card->regs.fifo_en &= ~hfc_FIFOEN_DTX;
 
293
        }
 
294
        spin_unlock_irqrestore(&card->chans[D].lock, flags);
 
295
 
 
296
        hfc_outb(card, hfc_FIFO_EN, card->regs.fifo_en);
 
297
}
 
298
 
 
299
static inline void hfc_suspend_fifo(struct hfc_card *card)
 
300
{
 
301
        card->fifo_suspended = TRUE;
 
302
 
 
303
        hfc_update_fifo_state(card);
 
304
 
 
305
        // When L1 goes down D rx receives garbage; it is nice to
 
306
        // clear it to avoid a CRC error on reactivation
 
307
        // udelay is needed because the FIFO deactivation happens
 
308
        // in 250us
 
309
        udelay(250);
 
310
        hfc_clear_fifo_rx(&card->chans[D].rx);
 
311
 
 
312
#ifdef DEBUG
 
313
        if (debug_level >= 3) {
 
314
                printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
315
                        "card %d: "
 
316
                        "FIFOs suspended\n",
 
317
                        card->cardnum);
 
318
        }
 
319
#endif
 
320
}
 
321
 
 
322
static inline void hfc_resume_fifo(struct hfc_card *card)
 
323
{
 
324
        card->fifo_suspended = FALSE;
 
325
 
 
326
        hfc_update_fifo_state(card);
 
327
 
 
328
#ifdef DEBUG
 
329
        if (debug_level >= 3) {
 
330
                printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
331
                        "card %d: "
 
332
                        "FIFOs resumed\n",
 
333
                        card->cardnum);
 
334
        }
 
335
#endif
 
336
}
 
337
 
 
338
static void hfc_check_l1_up(struct hfc_card *card)
 
339
{
 
340
        if ((!card->nt_mode && card->l1_state != 7) ||
 
341
                (card->nt_mode && card->l1_state != 3)) {
 
342
// 0 because this is quite verbose when an inferface is unconnected, jaw                
 
343
#if 0
 
344
                if(debug_level >= 1) {
 
345
                        printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
346
                                "card %d: "
 
347
                                "L1 is down, bringing up L1.\n",
 
348
                                card->cardnum);
 
349
                }
 
350
#endif
 
351
 
 
352
                hfc_outb(card, hfc_STATES, hfc_STATES_DO_ACTION |
 
353
                                        hfc_STATES_ACTIVATE|
 
354
                                        hfc_STATES_NT_G2_G3);
 
355
        }
 
356
}
 
357
 
 
358
/******************************************
 
359
 * /proc interface functions
 
360
 ******************************************/
 
361
 
 
362
struct hfc_status_to_name_names {
 
363
        enum hfc_chan_status status;
 
364
        char *name;
 
365
};
 
366
 
 
367
static char *hfc_status_to_name(int status)
 
368
{
 
369
        struct hfc_status_to_name_names names[] = {
 
370
                { free, "free" },
 
371
                { open_framed, "framed" },
 
372
                { open_voice, "voice" },
 
373
                { sniff_aux, "sniff aux" },
 
374
                { loopback, "loopback" },
 
375
                };
 
376
 
 
377
        int i;
 
378
 
 
379
        for (i=0; i<sizeof(names); i++) {
 
380
                if (names[i].status == status)
 
381
                        return names[i].name;
 
382
        }
 
383
 
 
384
        return "*UNK*";
 
385
}
 
386
 
 
387
static void hfc_hexdump(char *src,char *dst, int size)
 
388
{
 
389
        static char hexchars[] = "0123456789ABCDEF";
 
390
 
 
391
        int i;
 
392
        for(i=0;i<size;i++) {
 
393
                dst[i*2]  = hexchars[(src[i] & 0xf0) >> 4];
 
394
                dst[i*2+1]= hexchars[src[i] & 0xf];
 
395
        }
 
396
 
 
397
        dst[size*2]='\0';
 
398
}
 
399
 
 
400
static int hfc_proc_read_info(char *page, char **start,
 
401
                off_t off, int count, 
 
402
                int *eof, void *data)
 
403
{
 
404
        struct hfc_card *card = data;
 
405
        int len;
 
406
 
 
407
        u8 chip_id;
 
408
        chip_id = hfc_inb(card, hfc_CHIP_ID);
 
409
 
 
410
        len = snprintf(page, PAGE_SIZE,
 
411
                "Driver    : %s\n"
 
412
                "Cardnum   : %d\n"
 
413
                "IRQ       : %d\n"
 
414
                "PCI Mem   : %#08lx (0x%p)\n"
 
415
                "FIFO Mem  : %#08lx (0x%p)\n"
 
416
                "Mode      : %s\n"
 
417
                "CHIP_ID   : %#02x\n"
 
418
                "L1 State  : %c%d\n"
 
419
                "Sync Lost : %s\n"
 
420
                "Late IRQs : %d\n"
 
421
                "FIFO susp : %s\n"
 
422
                "\nChannel     %12s %12s %12s %12s %4s %4s %4s %4s %4s\n"
 
423
                "D         : %12llu %12llu %12llu %12llu %4llu %4llu %4llu %4llu %4llu %c%c %s\n"
 
424
                "B1        : %12llu %12llu %12llu %12llu %4llu %4llu %4llu %4llu %4llu %c%c %s\n"
 
425
                "B2        : %12llu %12llu %12llu %12llu %4llu %4llu %4llu %4llu %4llu %c%c %s\n"
 
426
                ,hfc_DRIVER_STRING
 
427
                ,card->cardnum
 
428
                ,card->pcidev->irq
 
429
                ,card->io_bus_mem, card->io_mem
 
430
                ,(ulong)card->fifo_bus_mem, card->fifo_mem
 
431
                ,card->nt_mode?"NT":"TE"
 
432
                ,chip_id
 
433
                ,card->nt_mode?'G':'F'
 
434
                ,card->l1_state
 
435
                ,card->sync_loss_reported?"YES":"NO"
 
436
                ,card->late_irqs
 
437
                ,card->fifo_suspended?"YES":"NO"
 
438
 
 
439
                ,"RX Frames","TX Frames","RX Bytes","TX Bytes","RXFF","TXFF","RXU","TXU","CRC"
 
440
                ,card->chans[D].rx.frames
 
441
                ,card->chans[D].tx.frames
 
442
                ,card->chans[D].rx.bytes
 
443
                ,card->chans[D].tx.bytes
 
444
                ,card->chans[D].rx.fifo_full
 
445
                ,card->chans[D].tx.fifo_full
 
446
                ,card->chans[D].rx.fifo_underrun
 
447
                ,card->chans[D].tx.fifo_underrun
 
448
                ,card->chans[D].rx.crc
 
449
                ,card->chans[D].open_by_netdev ? 'N' : ' '
 
450
                ,card->chans[D].open_by_zaptel ? 'Z' : ' '
 
451
                ,hfc_status_to_name(card->chans[D].status)
 
452
 
 
453
                ,card->chans[B1].rx.frames
 
454
                ,card->chans[B1].tx.frames
 
455
                ,card->chans[B1].rx.bytes
 
456
                ,card->chans[B1].tx.bytes
 
457
                ,card->chans[B1].rx.fifo_full
 
458
                ,card->chans[B1].tx.fifo_full
 
459
                ,card->chans[B1].rx.fifo_underrun
 
460
                ,card->chans[B1].tx.fifo_underrun
 
461
                ,card->chans[B1].rx.crc
 
462
                ,card->chans[B1].open_by_netdev ? 'N' : ' '
 
463
                ,card->chans[B1].open_by_zaptel ? 'Z' : ' '
 
464
                ,hfc_status_to_name(card->chans[B1].status)
 
465
 
 
466
                ,card->chans[B2].rx.frames
 
467
                ,card->chans[B2].tx.frames
 
468
                ,card->chans[B2].rx.bytes
 
469
                ,card->chans[B2].tx.bytes
 
470
                ,card->chans[B2].rx.fifo_full
 
471
                ,card->chans[B2].tx.fifo_full
 
472
                ,card->chans[B2].rx.fifo_underrun
 
473
                ,card->chans[B2].tx.fifo_underrun
 
474
                ,card->chans[B2].rx.crc
 
475
                ,card->chans[B2].open_by_netdev ? 'N' : ' '
 
476
                ,card->chans[B2].open_by_zaptel ? 'Z' : ' '
 
477
                ,hfc_status_to_name(card->chans[B2].status)
 
478
                );
 
479
 
 
480
        return len;
 
481
}
 
482
 
 
483
static int hfc_proc_read_fifos(char *page, char **start,
 
484
                off_t off, int count, 
 
485
                int *eof, void *data)
 
486
{
 
487
        struct hfc_card *card = data;
 
488
 
 
489
        int len;
 
490
        len = snprintf(page, PAGE_SIZE,
 
491
                "            Receive                Transmit\n"
 
492
                "Channel     F1 F2   Z1   Z2 Used   F1 F2   Z1   Z2 Used\n"
 
493
                "D         : %02x %02x %04x %04x %4d   %02x %02x %04x %04x %4d\n"
 
494
                "B1        : %02x %02x %04x %04x %4d   %02x %02x %04x %04x %4d\n"
 
495
                "B2        : %02x %02x %04x %04x %4d   %02x %02x %04x %04x %4d\n"
 
496
                ,*card->chans[D].rx.f1
 
497
                ,*card->chans[D].rx.f2
 
498
                ,*Z1_F2(&card->chans[D].rx)
 
499
                ,*Z2_F2(&card->chans[D].rx)
 
500
                ,hfc_fifo_used_rx(&card->chans[D].rx)
 
501
                ,*card->chans[D].tx.f1
 
502
                ,*card->chans[D].tx.f2
 
503
                ,*Z1_F1(&card->chans[D].tx)
 
504
                ,*Z2_F1(&card->chans[D].tx)
 
505
                ,hfc_fifo_used_tx(&card->chans[D].tx)
 
506
 
 
507
                ,*card->chans[B1].rx.f1
 
508
                ,*card->chans[B1].rx.f2
 
509
                ,*Z1_F2(&card->chans[B1].rx)
 
510
                ,*Z2_F2(&card->chans[B1].rx)
 
511
                ,hfc_fifo_used_rx(&card->chans[B1].rx)
 
512
                ,*card->chans[B1].tx.f1
 
513
                ,*card->chans[B1].tx.f2
 
514
                ,*Z1_F1(&card->chans[B1].tx)
 
515
                ,*Z2_F1(&card->chans[B1].tx)
 
516
                ,hfc_fifo_used_tx(&card->chans[B1].tx)
 
517
 
 
518
                ,*card->chans[B2].rx.f1
 
519
                ,*card->chans[B2].rx.f2
 
520
                ,*Z1_F2(&card->chans[B2].rx)
 
521
                ,*Z2_F2(&card->chans[B2].rx)
 
522
                ,hfc_fifo_used_rx(&card->chans[B2].rx)
 
523
                ,*card->chans[B2].tx.f1
 
524
                ,*card->chans[B2].tx.f2
 
525
                ,*Z1_F1(&card->chans[B2].tx)
 
526
                ,*Z2_F1(&card->chans[B2].tx)
 
527
                ,hfc_fifo_used_tx(&card->chans[B2].tx)
 
528
                );
 
529
 
 
530
        return len;
 
531
}
 
532
 
 
533
static int hfc_proc_read_bufs(char *page, char **start,
 
534
                off_t off, int count, 
 
535
                int *eof, void *data)
 
536
{
 
537
        struct hfc_card *card = data;
 
538
        int len;
 
539
 
 
540
        char hex_rchunk[3][ZT_CHUNKSIZE * 2 + 1];
 
541
        char hex_wchunk[3][ZT_CHUNKSIZE * 2 + 1];
 
542
 
 
543
        hfc_hexdump(card->chans[D].rx.zaptel_buffer, hex_rchunk[0], ZT_CHUNKSIZE);
 
544
        hfc_hexdump(card->chans[D].tx.zaptel_buffer, hex_wchunk[0], ZT_CHUNKSIZE);
 
545
        hfc_hexdump(card->chans[B1].rx.zaptel_buffer, hex_rchunk[1], ZT_CHUNKSIZE);
 
546
        hfc_hexdump(card->chans[B1].tx.zaptel_buffer, hex_wchunk[1], ZT_CHUNKSIZE);
 
547
        hfc_hexdump(card->chans[B2].rx.zaptel_buffer, hex_rchunk[2], ZT_CHUNKSIZE);
 
548
        hfc_hexdump(card->chans[B2].tx.zaptel_buffer, hex_wchunk[2], ZT_CHUNKSIZE);
 
549
 
 
550
        len = snprintf(page, PAGE_SIZE,
 
551
                "Channel    Read Chunk       Write Chunk\n"
 
552
                "D         : %16s %16s\n"
 
553
                "B1        : %16s %16s\n"
 
554
                "B2        : %16s %16s\n"
 
555
                ,hex_rchunk[0],hex_wchunk[0]
 
556
                ,hex_rchunk[1],hex_wchunk[1]
 
557
                ,hex_rchunk[2],hex_wchunk[2]
 
558
                );
 
559
 
 
560
        return len;
 
561
}
 
562
 
 
563
/******************************************
 
564
 * net_device interface functions
 
565
 ******************************************/
 
566
 
 
567
static int hfc_open(struct net_device *netdev)
 
568
{
 
569
        struct hfc_chan_duplex *chan = netdev->priv;
 
570
        struct hfc_card *card = chan->card;
 
571
 
 
572
        spin_lock(&chan->lock);
 
573
 
 
574
        if (chan->status != free &&
 
575
                (chan->number != D || chan->status != open_framed)) {
 
576
                spin_unlock(&chan->lock);
 
577
                return -EBUSY;
 
578
        }
 
579
 
 
580
        chan->status = open_framed;
 
581
        chan->open_by_netdev = TRUE;
 
582
 
 
583
        spin_unlock(&chan->lock);
 
584
 
 
585
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
586
                "card %d: "
 
587
                "chan %s opened.\n",
 
588
                card->cardnum,
 
589
                chan->name);
 
590
 
 
591
        return 0;
 
592
}
 
593
 
 
594
static int hfc_close(struct net_device *netdev)
 
595
{
 
596
        struct hfc_chan_duplex *chan = netdev->priv;
 
597
        struct hfc_card *card = chan->card;
 
598
 
 
599
        spin_lock(&chan->lock);
 
600
 
 
601
        if (chan->status != open_framed) {
 
602
                spin_unlock(&chan->lock);
 
603
                return -EINVAL;
 
604
        }
 
605
 
 
606
        chan->status = free;
 
607
        chan->open_by_netdev = FALSE;
 
608
 
 
609
        spin_unlock(&chan->lock);
 
610
 
 
611
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
612
                "card %d: "
 
613
                "chan %s closed.\n",
 
614
                card->cardnum,
 
615
                chan->name);
 
616
 
 
617
        return 0;
 
618
}
 
619
 
 
620
static int hfc_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 
621
{
 
622
        struct hfc_chan_duplex *chan = netdev->priv;
 
623
        struct hfc_card *card = chan->card;
 
624
 
 
625
        netdev->trans_start = jiffies;
 
626
 
 
627
        hfc_check_l1_up(card);
 
628
 
 
629
        hfc_fifo_put_frame(&chan->tx, skb->data, skb->len);
 
630
 
 
631
        // We're not called from IRQ handler, otherwise we'd need
 
632
        // dev_kfree_skb
 
633
        dev_kfree_skb(skb);
 
634
 
 
635
        return 0;
 
636
}
 
637
 
 
638
static struct net_device_stats *hfc_get_stats(struct net_device *netdev)
 
639
{
 
640
        struct hfc_chan_duplex *chan = netdev->priv;
 
641
//      struct hfc_card *card = chan->card;
 
642
 
 
643
        return &chan->net_device_stats;
 
644
}
 
645
 
 
646
static void hfc_set_multicast_list(struct net_device *netdev)
 
647
{
 
648
        struct hfc_chan_duplex *chan = netdev->priv;
 
649
        struct hfc_card *card = chan->card;
 
650
 
 
651
        spin_lock(&card->lock);
 
652
 
 
653
        if(netdev->flags & IFF_PROMISC && !card->echo_enabled) {
 
654
                if (card->nt_mode) {
 
655
                        printk(KERN_INFO hfc_DRIVER_PREFIX
 
656
                                "card %d "
 
657
                                "is in NT mode, not going promiscuous\n",
 
658
                                card->cardnum);
 
659
 
 
660
                        spin_unlock(&card->lock);
 
661
                        return;
 
662
                }
 
663
 
 
664
                if (card->chans[B2].status != free) {
 
665
                        printk(KERN_INFO hfc_DRIVER_PREFIX
 
666
                                "card %d: "
 
667
                                "chan %s: is busy, not going promiscuous\n",
 
668
                                card->cardnum,
 
669
                                card->chans[B2].name);
 
670
 
 
671
                        spin_unlock(&card->lock);
 
672
                        return;
 
673
                }
 
674
 
 
675
                card->regs.trm |= hfc_TRM_ECHO;
 
676
                card->regs.m1 |= hfc_INTS_B2REC;
 
677
                card->regs.cirm &= ~hfc_CIRM_B2_REV;
 
678
                card->regs.sctrl &= ~hfc_SCTRL_B2_ENA;
 
679
                card->regs.sctrl_r &= ~hfc_SCTRL_R_B2_ENA;
 
680
                card->regs.connect |= hfc_CONNECT_B2_ST_from_GCI;
 
681
                card->regs.ctmt &= ~hfc_CTMT_TRANSB2;
 
682
 
 
683
                card->chans[B2].status = sniff_aux;
 
684
 
 
685
                card->echo_enabled = TRUE;
 
686
 
 
687
                printk(KERN_INFO hfc_DRIVER_PREFIX
 
688
                        "card %d: "
 
689
                        "chan %s entered echo mode on channel %s\n",
 
690
                        card->cardnum,
 
691
                        chan->name,
 
692
                        card->chans[B2].name);
 
693
 
 
694
        } else if(!(netdev->flags & IFF_PROMISC) && card->echo_enabled) {
 
695
                if (!card->echo_enabled) {
 
696
                        spin_unlock(&card->lock);
 
697
                        return;
 
698
                }
 
699
 
 
700
                card->regs.trm &= ~hfc_TRM_ECHO;
 
701
                card->regs.m1 &= ~hfc_INTS_B2REC;
 
702
                card->regs.cirm |= hfc_CIRM_B2_REV;
 
703
                card->regs.sctrl &= ~hfc_SCTRL_B2_ENA;
 
704
                card->regs.sctrl_r &= ~hfc_SCTRL_R_B2_ENA;
 
705
                card->regs.connect =
 
706
                        hfc_CONNECT_B1_HFC_from_ST |
 
707
                        hfc_CONNECT_B1_ST_from_HFC |
 
708
                        hfc_CONNECT_B1_GCI_from_HFC |
 
709
                        hfc_CONNECT_B2_HFC_from_ST |
 
710
                        hfc_CONNECT_B2_ST_from_HFC |
 
711
                        hfc_CONNECT_B2_GCI_from_HFC;
 
712
 
 
713
                card->chans[B2].status = free;
 
714
 
 
715
                card->echo_enabled = FALSE;
 
716
 
 
717
                printk(KERN_INFO hfc_DRIVER_PREFIX
 
718
                        "card %d: "
 
719
                        "chan %s left promiscuous mode.\n",
 
720
                        card->cardnum,
 
721
                        chan->name);
 
722
        }
 
723
 
 
724
        spin_unlock(&card->lock);
 
725
 
 
726
        hfc_outb(card, hfc_TRM, card->regs.trm);
 
727
        hfc_outb(card, hfc_CIRM, card->regs.cirm);
 
728
        hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
 
729
        hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
 
730
        hfc_outb(card, hfc_CONNECT, card->regs.connect);
 
731
        hfc_outb(card, hfc_CTMT, card->regs.ctmt);
 
732
 
 
733
        // Enable appropriate B receive interrupt
 
734
        hfc_outb(card, hfc_INT_M1, card->regs.m1);
 
735
 
 
736
        hfc_update_fifo_state(card);
 
737
}
 
738
 
 
739
/******************************************
 
740
 * Zaptel interface (zaptel sucks)
 
741
 ******************************************/
 
742
 
 
743
static int hfc_zap_open(struct zt_chan *zaptel_chan)
 
744
{
 
745
        struct hfc_chan_duplex *chan = zaptel_chan->pvt;
 
746
        struct hfc_card *card = chan->card;
 
747
 
 
748
        spin_lock(&chan->lock);
 
749
 
 
750
        switch (chan->number) {
 
751
                case D:
 
752
                        if (chan->status != free &&
 
753
                                chan->status != open_framed) {
 
754
                                spin_unlock(&chan->lock);
 
755
                                return -EBUSY;
 
756
                        }
 
757
 
 
758
                        chan->status = open_framed;
 
759
                break;
 
760
 
 
761
                case B1:
 
762
                case B2:
 
763
                        if (chan->status != free) {
 
764
                                spin_unlock(&chan->lock);
 
765
                                return -EBUSY;
 
766
                        }
 
767
 
 
768
                        chan->status = open_voice;
 
769
                break;
 
770
        }
 
771
 
 
772
        chan->open_by_zaptel = TRUE;
 
773
 
 
774
#ifndef LINUX26
 
775
        MOD_INC_USE_COUNT;
 
776
#else
 
777
        // Zaptel is buggy
 
778
        try_module_get(THIS_MODULE);
 
779
#endif
 
780
 
 
781
        spin_unlock(&chan->lock);
 
782
 
 
783
        switch (chan->number) {
 
784
                case D:
 
785
                break;
 
786
 
 
787
                case B1:
 
788
                        // B1
 
789
                        card->regs.m2 |= hfc_M2_PROC_TRANS;
 
790
                        card->regs.ctmt |= hfc_CTMT_TRANSB1; // Enable transparent mode
 
791
                        card->regs.cirm |= hfc_CIRM_B1_REV; // Reversed bit order
 
792
                        card->regs.sctrl |= hfc_SCTRL_B1_ENA; // Enable transmission
 
793
                        card->regs.sctrl_r |= hfc_SCTRL_R_B1_ENA; // Enable reception
 
794
                break;
 
795
 
 
796
                case B2:
 
797
                        // B2
 
798
                        card->regs.m2 |= hfc_M2_PROC_TRANS;
 
799
                        card->regs.ctmt |= hfc_CTMT_TRANSB2; // Enable transparent mode
 
800
                        card->regs.cirm |= hfc_CIRM_B2_REV; // Reversed bit order
 
801
                        card->regs.sctrl |= hfc_SCTRL_B2_ENA; // Enable transmission
 
802
                        card->regs.sctrl_r |= hfc_SCTRL_R_B2_ENA; // Enable reception
 
803
                break;
 
804
 
 
805
        }
 
806
 
 
807
        // If not already enabled, enable processing transition (8KHz)
 
808
        // interrupt
 
809
        hfc_outb(card, hfc_INT_M2, card->regs.m2);
 
810
        hfc_outb(card, hfc_CTMT, card->regs.ctmt);
 
811
        hfc_outb(card, hfc_CIRM, card->regs.cirm);
 
812
        hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
 
813
        hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
 
814
 
 
815
        hfc_update_fifo_state(card);
 
816
 
 
817
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
818
                "card %d: "
 
819
                "chan %s opened as %s.\n",
 
820
                card->cardnum,
 
821
                chan->name,
 
822
                zaptel_chan->name);
 
823
 
 
824
        return 0;
 
825
}
 
826
 
 
827
static int hfc_zap_close(struct zt_chan *zaptel_chan)
 
828
{
 
829
        struct hfc_chan_duplex *chan = zaptel_chan->pvt;
 
830
        struct hfc_card *card = chan->card;
 
831
 
 
832
        if (!card) {
 
833
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
834
                        "hfc_zap_close called with NULL card\n");
 
835
                return -1;
 
836
        }
 
837
 
 
838
        spin_lock(&chan->lock);
 
839
 
 
840
        if (chan->status == free) {
 
841
                spin_unlock(&chan->lock);
 
842
                return -EINVAL;
 
843
        }
 
844
 
 
845
        chan->status = free;
 
846
        chan->open_by_zaptel = FALSE;
 
847
 
 
848
        spin_unlock(&chan->lock);
 
849
 
 
850
        switch (chan->number) {
 
851
                case D:
 
852
                break;
 
853
 
 
854
                case B1:
 
855
                        // B1
 
856
                        card->regs.ctmt &= ~hfc_CTMT_TRANSB1;
 
857
                        card->regs.cirm &= ~hfc_CIRM_B1_REV;
 
858
                        card->regs.sctrl &= ~hfc_SCTRL_B1_ENA;
 
859
                        card->regs.sctrl_r &= ~hfc_SCTRL_R_B1_ENA;
 
860
                break;
 
861
 
 
862
                case B2:
 
863
                        // B2
 
864
                        card->regs.ctmt &= ~hfc_CTMT_TRANSB2;
 
865
                        card->regs.cirm &= ~hfc_CIRM_B2_REV;
 
866
                        card->regs.sctrl &= ~hfc_SCTRL_B2_ENA;
 
867
                        card->regs.sctrl_r &= ~hfc_SCTRL_R_B2_ENA;
 
868
                break;
 
869
        }
 
870
 
 
871
        if (card->chans[B1].status == free &&
 
872
                card->chans[B2].status == free)
 
873
                card->regs.m2 &= ~hfc_M2_PROC_TRANS;
 
874
 
 
875
        hfc_outb(card, hfc_INT_M2, card->regs.m2);
 
876
        hfc_outb(card, hfc_CTMT, card->regs.ctmt);
 
877
        hfc_outb(card, hfc_CIRM, card->regs.cirm);
 
878
        hfc_outb(card, hfc_SCTRL, card->regs.sctrl);
 
879
        hfc_outb(card, hfc_SCTRL_R, card->regs.sctrl_r);
 
880
 
 
881
        hfc_update_fifo_state(card);
 
882
 
 
883
#ifndef LINUX26
 
884
        MOD_DEC_USE_COUNT;
 
885
#else
 
886
        // Zaptel is buggy
 
887
        module_put(THIS_MODULE);
 
888
#endif
 
889
 
 
890
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
891
                "card %d: "
 
892
                "chan %s closed as %s.\n",
 
893
                card->cardnum,
 
894
                chan->name,
 
895
                zaptel_chan->name);
 
896
 
 
897
        return 0;
 
898
}
 
899
 
 
900
static int hfc_zap_rbsbits(struct zt_chan *chan, int bits)
 
901
{
 
902
        return 0;
 
903
}
 
904
 
 
905
static int hfc_zap_ioctl(struct zt_chan *chan, unsigned int cmd, unsigned long data)
 
906
{
 
907
        switch(cmd) {
 
908
                default:
 
909
                        return -ENOTTY;
 
910
        }
 
911
 
 
912
        return 0;
 
913
}
 
914
 
 
915
static int hfc_zap_startup(struct zt_span *span)
 
916
{
 
917
        struct hfc_card *card = span->pvt;
 
918
        int alreadyrunning;
 
919
 
 
920
        if (!card) {
 
921
                printk(KERN_INFO hfc_DRIVER_PREFIX
 
922
                        "card %d: "
 
923
                        "no card for span at startup!\n",
 
924
                        card->cardnum);
 
925
        }
 
926
 
 
927
        alreadyrunning = span->flags & ZT_FLAG_RUNNING;
 
928
 
 
929
        if (!alreadyrunning) {
 
930
                span->chans[ZT_D].flags &= ~ZT_FLAG_HDLC;
 
931
                span->chans[ZT_D].flags |= ZT_FLAG_BRIDCHAN;
 
932
                span->flags |= ZT_FLAG_RUNNING;
 
933
        }
 
934
 
 
935
        return 0;
 
936
}
 
937
 
 
938
static int hfc_zap_shutdown(struct zt_span *span)
 
939
{
 
940
        return 0;
 
941
}
 
942
 
 
943
static int hfc_zap_maint(struct zt_span *span, int cmd)
 
944
{
 
945
        return 0;
 
946
}
 
947
 
 
948
static int hfc_zap_chanconfig(struct zt_chan *chan, int sigtype)
 
949
{
 
950
        return 0;
 
951
}
 
952
 
 
953
static int hfc_zap_spanconfig(struct zt_span *span, struct zt_lineconfig *lc)
 
954
{
 
955
        span->lineconfig = lc->lineconfig;
 
956
 
 
957
        return 0;
 
958
}
 
959
 
 
960
static int hfc_zap_initialize(struct hfc_card *card)
 
961
{
 
962
        int i;
 
963
        memset(&card->zt_span, 0x0, sizeof(struct zt_span));
 
964
 
 
965
        snprintf(card->zt_span.name, sizeof(card->zt_span.name),
 
966
                 "ZTHFC%d", card->cardnum + 1);
 
967
 
 
968
        snprintf(card->zt_span.desc, sizeof(card->zt_span.desc),
 
969
                        hfc_DRIVER_DESCR " card %d [%s]",
 
970
                        card->cardnum,
 
971
                        card->nt_mode?"NT":"TE");
 
972
 
 
973
        card->zt_span.spanconfig = hfc_zap_spanconfig;
 
974
        card->zt_span.chanconfig = hfc_zap_chanconfig;
 
975
        card->zt_span.startup = hfc_zap_startup;
 
976
        card->zt_span.shutdown = hfc_zap_shutdown;
 
977
        card->zt_span.maint = hfc_zap_maint;
 
978
        card->zt_span.rbsbits = hfc_zap_rbsbits;
 
979
        card->zt_span.open = hfc_zap_open;
 
980
        card->zt_span.close = hfc_zap_close;
 
981
        card->zt_span.ioctl = hfc_zap_ioctl;
 
982
 
 
983
        card->zt_span.chans = card->zt_chans;
 
984
        card->zt_span.channels = 3;
 
985
        card->zt_span.deflaw = ZT_LAW_ALAW;
 
986
        card->zt_span.linecompat = ZT_CONFIG_AMI | ZT_CONFIG_CCS; // <--- this is really BS
 
987
        card->zt_span.offset = 0;
 
988
        init_waitqueue_head(&card->zt_span.maintq);
 
989
        card->zt_span.pvt = card;
 
990
 
 
991
        for (i = 0; i < card->zt_span.channels; i++) {
 
992
                memset(&card->zt_chans[i], 0x0, sizeof(struct zt_chan));
 
993
 
 
994
                snprintf(card->zt_chans[i].name, sizeof(card->zt_chans[i].name),
 
995
                                "ZTHFC%d/%d/%d",
 
996
                                card->cardnum + 1, 0, i + 1);
 
997
 
 
998
                printk(KERN_INFO hfc_DRIVER_PREFIX
 
999
                        "card %d: "
 
1000
                        "registered %s\n",
 
1001
                        card->cardnum,
 
1002
                        card->zt_chans[i].name);
 
1003
 
 
1004
                card->zt_chans[i].sigcap =  ZT_SIG_EM | ZT_SIG_CLEAR |
 
1005
                        ZT_SIG_FXSLS | ZT_SIG_FXSGS |
 
1006
                        ZT_SIG_FXSKS | ZT_SIG_FXOLS |
 
1007
                        ZT_SIG_FXOGS | ZT_SIG_FXOKS |
 
1008
                        ZT_SIG_CAS | ZT_SIG_SF;
 
1009
 
 
1010
                card->zt_chans[i].chanpos = i + 1; 
 
1011
        }
 
1012
 
 
1013
        card->zt_chans[ZT_D].readchunk  = card->chans[D].rx.zaptel_buffer;
 
1014
        card->zt_chans[ZT_D].writechunk = card->chans[D].tx.zaptel_buffer;
 
1015
        card->zt_chans[ZT_D].pvt = &card->chans[D];
 
1016
 
 
1017
        card->zt_chans[ZT_B1].readchunk  = card->chans[B1].rx.zaptel_buffer;
 
1018
        card->zt_chans[ZT_B1].writechunk = card->chans[B1].tx.zaptel_buffer;
 
1019
        card->zt_chans[ZT_B1].pvt = &card->chans[B1];
 
1020
 
 
1021
        card->zt_chans[ZT_B2].readchunk  = card->chans[B2].rx.zaptel_buffer;
 
1022
        card->zt_chans[ZT_B2].writechunk = card->chans[B2].tx.zaptel_buffer;
 
1023
        card->zt_chans[ZT_B2].pvt = &card->chans[B2];
 
1024
 
 
1025
        if (zt_register(&card->zt_span,0)) {
 
1026
                printk(KERN_CRIT "unable to register zaptel device!\n");
 
1027
                return -1;
 
1028
        }
 
1029
 
 
1030
        return 0;
 
1031
}
 
1032
 
 
1033
static void hfc_zap_transmit(struct hfc_chan_simplex *chan)
 
1034
{
 
1035
        hfc_fifo_put(chan, chan->zaptel_buffer, ZT_CHUNKSIZE);
 
1036
}
 
1037
 
 
1038
static void hfc_zap_receive(struct hfc_chan_simplex *chan)
 
1039
{
 
1040
        hfc_fifo_get(chan, chan->zaptel_buffer, ZT_CHUNKSIZE);
 
1041
}
 
1042
 
 
1043
/******************************************
 
1044
 * Interrupt Handler
 
1045
 ******************************************/
 
1046
 
 
1047
static void hfc_handle_timer_interrupt(struct hfc_card *card);
 
1048
static void hfc_handle_state_interrupt(struct hfc_card *card);
 
1049
static void hfc_handle_processing_interrupt(struct hfc_card *card);
 
1050
static void hfc_frame_arrived(struct hfc_chan_duplex *chan);
 
1051
static void hfc_handle_voice(struct hfc_card *card);
 
1052
 
 
1053
ZAP_IRQ_HANDLER(hfc_interrupt)
 
1054
{
 
1055
        struct hfc_card *card = dev_id;
 
1056
        unsigned long flags;
 
1057
        u8 status,s1,s2;
 
1058
 
 
1059
        if (!card) {
 
1060
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1061
                        "spurious interrupt (IRQ %d)\n",
 
1062
                        irq);
 
1063
                return IRQ_NONE;
 
1064
        }
 
1065
 
 
1066
        spin_lock_irqsave(&card->lock, flags);
 
1067
        status = hfc_inb(card, hfc_STATUS);
 
1068
        if (!(status & hfc_STATUS_ANYINT)) {
 
1069
                // maybe we are sharing the irq
 
1070
                spin_unlock_irqrestore(&card->lock,flags);
 
1071
                return IRQ_NONE;
 
1072
        }
 
1073
 
 
1074
        /* We used to ingore the IRQ when the card was in processing
 
1075
         * state but apparently there is no restriction to access the
 
1076
         * card in such state:
 
1077
         *
 
1078
         * Joerg Ciesielski wrote:
 
1079
         * > There is no restriction for the IRQ handler to access
 
1080
         * > HFC-S PCI during processing phase. A IRQ latency of 375 us
 
1081
         * > is also no problem since there are no interrupt sources in
 
1082
         * > HFC-S PCI which must be handled very fast.
 
1083
         * > Due to its deep fifos the IRQ latency can be several ms with
 
1084
         * > out the risk of loosing data. Even the S/T state interrupts
 
1085
         * > must not be handled with a latency less than <5ms.
 
1086
         * >
 
1087
         * > The processing phase only indicates that HFC-S PCI is
 
1088
         * > processing the Fifos as PCI master so that data is read and
 
1089
         * > written in the 32k memory window. But there is no restriction
 
1090
         * > to access data in the memory window during this time.
 
1091
         *
 
1092
         * // if (status & hfc_STATUS_PCI_PROC) {
 
1093
         * // return IRQ_HANDLED;
 
1094
         * // }
 
1095
         */
 
1096
 
 
1097
        s1 = hfc_inb(card, hfc_INT_S1);
 
1098
        s2 = hfc_inb(card, hfc_INT_S2);
 
1099
 
 
1100
        if (s1 != 0) {
 
1101
                if (s1 & hfc_INTS_TIMER) {
 
1102
                        // timer (bit 7)
 
1103
                        hfc_handle_timer_interrupt(card);
 
1104
                }
 
1105
 
 
1106
                if (s1 & hfc_INTS_L1STATE) {
 
1107
                        // state machine (bit 6)
 
1108
                        hfc_handle_state_interrupt(card);
 
1109
                }
 
1110
 
 
1111
                if (s1 & hfc_INTS_DREC) {
 
1112
                        // D chan RX (bit 5)
 
1113
                        hfc_frame_arrived(&card->chans[D]);
 
1114
                }
 
1115
 
 
1116
                if (s1 & hfc_INTS_B1REC) {
 
1117
                        // B1 chan RX (bit 3)
 
1118
                        hfc_frame_arrived(&card->chans[B1]);
 
1119
                }
 
1120
 
 
1121
                if (s1 & hfc_INTS_B2REC) {
 
1122
                        // B2 chan RX (bit 4)
 
1123
                        hfc_frame_arrived(&card->chans[B2]);
 
1124
                }
 
1125
 
 
1126
                if (s1 & hfc_INTS_DTRANS) {
 
1127
                        // D chan TX (bit 2)
 
1128
                }
 
1129
 
 
1130
                if (s1 & hfc_INTS_B1TRANS) {
 
1131
                        // B1 chan TX (bit 0)
 
1132
                }
 
1133
 
 
1134
                if (s1 & hfc_INTS_B2TRANS) {
 
1135
                        // B2 chan TX (bit 1)
 
1136
                }
 
1137
 
 
1138
        }
 
1139
 
 
1140
        if (s2 != 0) {
 
1141
                if (s2 & hfc_M2_PMESEL) {
 
1142
                        // kaboom irq (bit 7)
 
1143
 
 
1144
                        /* CologneChip says:
 
1145
                         *
 
1146
                         * the meaning of this fatal error bit is that HFC-S PCI as PCI
 
1147
                         * master could not access the PCI bus within 125us to finish its
 
1148
                         * data processing. If this happens only very seldom it does not
 
1149
                         * cause big problems but of course some B-channel or D-channel
 
1150
                         * data will be corrupted due to this event.
 
1151
                         *
 
1152
                         * Unfortunately this bit is only set once after the problem occurs
 
1153
                         * and can only be reseted by a software reset. That means it is not
 
1154
                         * easily possible to check how often this fatal error happens.
 
1155
                         */
 
1156
 
 
1157
                        if(!card->sync_loss_reported) {
 
1158
                                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1159
                                        "card %d: "
 
1160
                                        "sync lost, pci performance too low!\n",
 
1161
                                        card->cardnum);
 
1162
 
 
1163
                                card->sync_loss_reported = TRUE;
 
1164
                        }
 
1165
                }
 
1166
 
 
1167
                if (s2 & hfc_M2_GCI_MON_REC) {
 
1168
                        // RxR monitor channel (bit 2)
 
1169
                }
 
1170
 
 
1171
                if (s2 & hfc_M2_GCI_I_CHG) {
 
1172
                        // GCI I-change  (bit 1)
 
1173
                }
 
1174
 
 
1175
                if (s2 & hfc_M2_PROC_TRANS){
 
1176
                        // processing/non-processing transition  (bit 0)
 
1177
                        hfc_handle_processing_interrupt(card);
 
1178
                }
 
1179
 
 
1180
        }
 
1181
 
 
1182
        spin_unlock_irqrestore(&card->lock,flags);
 
1183
 
 
1184
        return IRQ_HANDLED;
 
1185
}
 
1186
 
 
1187
static void hfc_handle_timer_interrupt(struct hfc_card *card)
 
1188
{
 
1189
        if(card->ignore_first_timer_interrupt) {
 
1190
                card->ignore_first_timer_interrupt = FALSE;
 
1191
                return;
 
1192
        }
 
1193
 
 
1194
        if ((card->nt_mode && card->l1_state == 3) ||
 
1195
                (!card->nt_mode && card->l1_state == 7)) {
 
1196
 
 
1197
                card->regs.ctmt &= ~hfc_CTMT_TIMER_MASK;
 
1198
                hfc_outb(card, hfc_CTMT, card->regs.ctmt);
 
1199
 
 
1200
                hfc_resume_fifo(card);
 
1201
        }
 
1202
}
 
1203
 
 
1204
static void hfc_handle_state_interrupt(struct hfc_card *card)
 
1205
{
 
1206
        u8 new_state = hfc_inb(card,hfc_STATES)  & hfc_STATES_STATE_MASK;
 
1207
 
 
1208
#ifdef DEBUG
 
1209
        if (debug_level >= 1) {
 
1210
                printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
1211
                        "card %d: "
 
1212
                        "layer 1 state = %c%d\n",
 
1213
                        card->cardnum,
 
1214
                        card->nt_mode?'G':'F',
 
1215
                        new_state);
 
1216
        }
 
1217
#endif
 
1218
 
 
1219
        if (card->nt_mode) {
 
1220
                // NT mode
 
1221
 
 
1222
                if (new_state == 3) {
 
1223
                        // fix to G3 state (see specs)
 
1224
                        hfc_outb(card, hfc_STATES, hfc_STATES_LOAD_STATE | 3);
 
1225
                }
 
1226
 
 
1227
                if (new_state == 3 && card->l1_state != 3) {
 
1228
                        hfc_resume_fifo(card);
 
1229
                }
 
1230
 
 
1231
                if (new_state != 3 && card->l1_state == 3) {
 
1232
                        hfc_suspend_fifo(card);
 
1233
                }
 
1234
        } else {
 
1235
                if (new_state == 3) {
 
1236
                        // Keep L1 up... zaptel & libpri expects a always up L1...
 
1237
                        // Enable only  when using an unpatched libpri
 
1238
 
 
1239
                        if (force_l1_up) {
 
1240
                                hfc_outb(card, hfc_STATES,
 
1241
                                        hfc_STATES_DO_ACTION |
 
1242
                                        hfc_STATES_ACTIVATE|
 
1243
                                        hfc_STATES_NT_G2_G3);
 
1244
                        }
 
1245
                }
 
1246
 
 
1247
                if (new_state == 7 && card->l1_state != 7) {
 
1248
                        // TE is now active, schedule FIFO activation after
 
1249
                        // some time, otherwise the first frames are lost
 
1250
 
 
1251
                        card->regs.ctmt |= hfc_CTMT_TIMER_50 | hfc_CTMT_TIMER_CLEAR;
 
1252
                        hfc_outb(card, hfc_CTMT, card->regs.ctmt);
 
1253
 
 
1254
                        // Activating the timer firest an interrupt immediately, we
 
1255
                        // obviously need to ignore it
 
1256
                        card->ignore_first_timer_interrupt = TRUE;
 
1257
                }
 
1258
 
 
1259
                if (new_state != 7 && card->l1_state == 7) {
 
1260
                        // TE has become inactive, disable FIFO
 
1261
                        hfc_suspend_fifo(card);
 
1262
                }
 
1263
        }
 
1264
 
 
1265
        card->l1_state = new_state;
 
1266
}
 
1267
 
 
1268
static void hfc_handle_processing_interrupt(struct hfc_card *card)
 
1269
{
 
1270
        int available_bytes=0;
 
1271
 
 
1272
        // Synchronize with the first enabled channel
 
1273
        if(card->regs.fifo_en & hfc_FIFOEN_B1RX)
 
1274
                available_bytes = hfc_fifo_used_rx(&card->chans[B1].rx);
 
1275
        if(card->regs.fifo_en & hfc_FIFOEN_B2RX)
 
1276
                available_bytes = hfc_fifo_used_rx(&card->chans[B2].rx);
 
1277
        else
 
1278
                available_bytes = -1;
 
1279
 
 
1280
        if ((available_bytes == -1 && card->ticks == 8) ||
 
1281
                available_bytes >= ZT_CHUNKSIZE + hfc_RX_FIFO_PRELOAD) {
 
1282
                card->ticks = 0;
 
1283
 
 
1284
                if (available_bytes > ZT_CHUNKSIZE*2 + hfc_RX_FIFO_PRELOAD) {
 
1285
                        card->late_irqs++;
 
1286
                        // we are out of sync, clear fifos, jaw
 
1287
                        hfc_clear_fifo_rx(&card->chans[B1].rx);
 
1288
                        hfc_clear_fifo_tx(&card->chans[B1].tx);
 
1289
                        hfc_clear_fifo_rx(&card->chans[B2].rx);
 
1290
                        hfc_clear_fifo_tx(&card->chans[B2].tx);
 
1291
 
 
1292
#ifdef DEBUG
 
1293
                        if (debug_level >= 4) {
 
1294
                                printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
1295
                                        "card %d: "
 
1296
                                        "late IRQ, %d bytes late\n",
 
1297
                                        card->cardnum,
 
1298
                                        available_bytes -
 
1299
                                                (ZT_CHUNKSIZE +
 
1300
                                                 hfc_RX_FIFO_PRELOAD));
 
1301
                        }
 
1302
#endif
 
1303
                } else {
 
1304
                        hfc_handle_voice(card);
 
1305
                }
 
1306
        }
 
1307
 
 
1308
        card->ticks++;
 
1309
}
 
1310
 
 
1311
static void hfc_sniff_zaptel_d_channel(struct hfc_card *card)
 
1312
{
 
1313
        struct sk_buff *skb =
 
1314
                dev_alloc_skb(card->chans[D].tx.ugly_framebuf_size);
 
1315
 
 
1316
        if (!skb) {
 
1317
                printk(KERN_ERR hfc_DRIVER_PREFIX
 
1318
                        "card %d: "
 
1319
                        "cannot allocate skb: sniffed frame dropped\n",
 
1320
                        card->cardnum);
 
1321
                return;
 
1322
        }
 
1323
 
 
1324
        skb->dev = card->chans[D].netdev;
 
1325
        skb->protocol = htons(card->chans[D].protocol);
 
1326
#ifndef CHECKSUM_HW
 
1327
        skb->ip_summed = CHECKSUM_COMPLETE;
 
1328
#else
 
1329
        skb->ip_summed = CHECKSUM_HW;
 
1330
#endif  
 
1331
        skb->pkt_type = PACKET_OUTGOING;
 
1332
 
 
1333
        memcpy(skb_put(skb, card->chans[D].tx.ugly_framebuf_size),
 
1334
                card->chans[D].tx.ugly_framebuf,
 
1335
                card->chans[D].tx.ugly_framebuf_size);
 
1336
 
 
1337
        netif_rx(skb);
 
1338
}
 
1339
 
 
1340
static void hfc_handle_voice(struct hfc_card *card)
 
1341
{
 
1342
        if (card->chans[B1].status != open_voice &&
 
1343
                card->chans[B2].status != open_voice)
 
1344
                return;
 
1345
 
 
1346
        card->zt_chans[ZT_D].bytes2transmit = 0;
 
1347
        card->zt_chans[ZT_D].maxbytes2transmit = ZT_CHUNKSIZE;
 
1348
 
 
1349
        zt_transmit(&card->zt_span);
 
1350
 
 
1351
        if (card->regs.fifo_en & hfc_FIFOEN_B1TX)
 
1352
                hfc_zap_transmit(&card->chans[B1].tx);
 
1353
        if (card->regs.fifo_en & hfc_FIFOEN_B2TX)
 
1354
                hfc_zap_transmit(&card->chans[B2].tx);
 
1355
 
 
1356
        if (card->zt_chans[ZT_D].bytes2transmit) {
 
1357
                hfc_check_l1_up(card);
 
1358
 
 
1359
                memcpy(card->chans[D].tx.ugly_framebuf +
 
1360
                        card->chans[D].tx.ugly_framebuf_size,
 
1361
                        card->chans[D].tx.zaptel_buffer,
 
1362
                        card->zt_chans[ZT_D].bytes2transmit);
 
1363
 
 
1364
                card->chans[D].tx.ugly_framebuf_size +=
 
1365
                        card->zt_chans[ZT_D].bytes2transmit;
 
1366
 
 
1367
                if (card->zt_chans[ZT_D].eoftx) {
 
1368
                        hfc_fifo_put_frame(&card->chans[D].tx,
 
1369
                                 card->chans[D].tx.ugly_framebuf,
 
1370
                                 card->chans[D].tx.ugly_framebuf_size);
 
1371
 
 
1372
                        if (sniff_zaptel_d_channel)
 
1373
                                hfc_sniff_zaptel_d_channel(card);
 
1374
 
 
1375
                        card->chans[D].tx.ugly_framebuf_size = 0;
 
1376
                        card->zt_chans[ZT_D].eoftx = FALSE;
 
1377
                }
 
1378
        }
 
1379
 
 
1380
        if (card->regs.fifo_en & hfc_FIFOEN_B1RX)
 
1381
                hfc_zap_receive(&card->chans[B1].rx);
 
1382
        else
 
1383
                memset(&card->chans[B1].rx.zaptel_buffer, 0x7f,
 
1384
                        sizeof(card->chans[B1].rx.zaptel_buffer));
 
1385
 
 
1386
        if (card->regs.fifo_en & hfc_FIFOEN_B2RX)
 
1387
                hfc_zap_receive(&card->chans[B2].rx);
 
1388
        else
 
1389
                memset(&card->chans[B2].rx.zaptel_buffer, 0x7f,
 
1390
                        sizeof(card->chans[B1].rx.zaptel_buffer));
 
1391
 
 
1392
        // Echo cancellation
 
1393
        zt_ec_chunk(&card->zt_chans[ZT_B1],
 
1394
                        card->chans[B1].rx.zaptel_buffer,
 
1395
                        card->chans[B1].tx.zaptel_buffer);
 
1396
        zt_ec_chunk(&card->zt_chans[ZT_B2],
 
1397
                        card->chans[B2].rx.zaptel_buffer,
 
1398
                        card->chans[B2].tx.zaptel_buffer);
 
1399
 
 
1400
        // If there's a frame in the FIFO, read it all and make it
 
1401
        // available to zaptel
 
1402
        if (hfc_fifo_has_frames(&card->chans[D].rx)) {
 
1403
                hfc_frame_arrived(&card->chans[D]);
 
1404
        }
 
1405
 
 
1406
        // Stupid zaptel frame handling
 
1407
        if (!card->chans[D].rx.ugly_framebuf_size) {
 
1408
                // hmm....ok, let zaptel receive nothing
 
1409
                card->zt_chans[ZT_D].bytes2receive = 0;
 
1410
                card->zt_chans[ZT_D].eofrx = FALSE;
 
1411
        }
 
1412
        else if (card->chans[D].rx.ugly_framebuf_size -
 
1413
                card->chans[D].rx.ugly_framebuf_off > ZT_CHUNKSIZE) {
 
1414
 
 
1415
                // the frame is longer than ZT_CHUNKSIZE
 
1416
                memcpy(card->chans[D].rx.zaptel_buffer,
 
1417
                        card->chans[D].rx.ugly_framebuf+
 
1418
                        card->chans[D].rx.ugly_framebuf_off,
 
1419
                        ZT_CHUNKSIZE);
 
1420
 
 
1421
                card->zt_chans[ZT_D].bytes2receive = ZT_CHUNKSIZE;
 
1422
                card->zt_chans[ZT_D].eofrx = FALSE;
 
1423
 
 
1424
                card->chans[D].rx.ugly_framebuf_off += ZT_CHUNKSIZE;
 
1425
        } else {
 
1426
                // we can read it all
 
1427
                memcpy(card->chans[D].rx.zaptel_buffer,
 
1428
                        card->chans[D].rx.ugly_framebuf+
 
1429
                        card->chans[D].rx.ugly_framebuf_off,
 
1430
                        card->chans[D].rx.ugly_framebuf_size);
 
1431
 
 
1432
                card->zt_chans[ZT_D].bytes2receive = card->chans[D].rx.ugly_framebuf_size-
 
1433
                        card->chans[D].rx.ugly_framebuf_off;
 
1434
                card->zt_chans[ZT_D].eofrx = TRUE;
 
1435
 
 
1436
                card->chans[D].rx.ugly_framebuf_size = 0;
 
1437
                card->chans[D].rx.ugly_framebuf_off = 0;
 
1438
        }
 
1439
 
 
1440
        if (card->zt_span.flags & ZT_FLAG_RUNNING) {
 
1441
                zt_receive(&card->zt_span);
 
1442
        }
 
1443
 
 
1444
}
 
1445
 
 
1446
static void hfc_frame_arrived(struct hfc_chan_duplex *chan)
 
1447
{
 
1448
        struct hfc_card *card = chan->card;
 
1449
        int antiloop = 16;
 
1450
        struct sk_buff *skb;
 
1451
        
 
1452
        while(hfc_fifo_has_frames(&chan->rx) && --antiloop) {
 
1453
                int frame_size = hfc_fifo_get_frame_size(&chan->rx);
 
1454
 
 
1455
                if (frame_size < 3) {
 
1456
#ifdef DEBUG
 
1457
                        if (debug_level>=2)
 
1458
                                printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
1459
                                        "card %d: "
 
1460
                                        "chan %s: "
 
1461
                                        "invalid frame received, just %d bytes\n",
 
1462
                                        card->cardnum,
 
1463
                                        chan->name,
 
1464
                                        frame_size);
 
1465
#endif
 
1466
 
 
1467
                        hfc_fifo_drop_frame(&chan->rx);
 
1468
 
 
1469
                        chan->net_device_stats.rx_dropped++;
 
1470
 
 
1471
                        continue;
 
1472
                } else if(frame_size == 3) {
 
1473
#ifdef DEBUG
 
1474
                        if (debug_level>=2)
 
1475
                                printk(KERN_DEBUG hfc_DRIVER_PREFIX
 
1476
                                        "card %d: "
 
1477
                                        "chan %s: "
 
1478
                                        "empty frame received\n",
 
1479
                                        card->cardnum,
 
1480
                                        chan->name);
 
1481
#endif
 
1482
 
 
1483
                        hfc_fifo_drop_frame(&chan->rx);
 
1484
 
 
1485
                        chan->net_device_stats.rx_dropped++;
 
1486
 
 
1487
                        continue;
 
1488
                }
 
1489
 
 
1490
                if (chan->open_by_zaptel &&
 
1491
                        card->chans[D].rx.ugly_framebuf_size) {
 
1492
                                // We have to wait for zaptel to transmit the
 
1493
                                // frame... wait for next time
 
1494
 
 
1495
                                break;
 
1496
                }
 
1497
 
 
1498
                skb = dev_alloc_skb(frame_size - 3);
 
1499
 
 
1500
                if (!skb) {
 
1501
                        printk(KERN_ERR hfc_DRIVER_PREFIX
 
1502
                                "card %d: "
 
1503
                                "chan %s: "
 
1504
                                "cannot allocate skb: frame dropped\n",
 
1505
                                card->cardnum,
 
1506
                                chan->name);
 
1507
 
 
1508
                        hfc_fifo_drop_frame(&chan->rx);
 
1509
 
 
1510
                        chan->net_device_stats.rx_dropped++;
 
1511
 
 
1512
                        continue;
 
1513
                }
 
1514
 
 
1515
                // Oh... this is the echo channel... redirect to D
 
1516
                // channel's netdev
 
1517
                if (card->echo_enabled && chan->number == B2) {
 
1518
                        skb->protocol = htons(card->chans[D].protocol);
 
1519
                        skb->dev = card->chans[D].netdev;
 
1520
                        skb->pkt_type = PACKET_OTHERHOST;
 
1521
                } else {
 
1522
                        skb->protocol = htons(chan->protocol);
 
1523
                        skb->dev = chan->netdev;
 
1524
                        skb->pkt_type = PACKET_HOST;
 
1525
                }
 
1526
 
 
1527
#ifndef CHECKSUM_HW
 
1528
                skb->ip_summed = CHECKSUM_COMPLETE;
 
1529
#else
 
1530
                skb->ip_summed = CHECKSUM_HW;
 
1531
#endif
 
1532
 
 
1533
                if (chan->open_by_zaptel) {
 
1534
                        card->chans[D].rx.ugly_framebuf_size = frame_size - 1;
 
1535
 
 
1536
                        if (hfc_fifo_get_frame(&card->chans[D].rx,
 
1537
                                card->chans[D].rx.ugly_framebuf,
 
1538
                                frame_size - 1) == -1) {
 
1539
                                dev_kfree_skb(skb);
 
1540
                                continue;
 
1541
                        }
 
1542
 
 
1543
                        memcpy(skb_put(skb, frame_size - 3),
 
1544
                                card->chans[D].rx.ugly_framebuf,
 
1545
                                frame_size - 3);
 
1546
                } else {
 
1547
                        if (hfc_fifo_get_frame(&chan->rx,
 
1548
                                skb_put(skb, frame_size - 3),
 
1549
                                frame_size - 3) == -1) {
 
1550
                                dev_kfree_skb(skb);
 
1551
                                continue;
 
1552
                        }
 
1553
                }
 
1554
 
 
1555
                chan->net_device_stats.rx_packets++;
 
1556
                chan->net_device_stats.rx_bytes += frame_size - 1;
 
1557
 
 
1558
                netif_rx(skb);
 
1559
        }
 
1560
 
 
1561
        if (!antiloop) 
 
1562
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1563
                        "card %d: "
 
1564
                        "Infinite loop detected\n",
 
1565
                        card->cardnum);
 
1566
}
 
1567
 
 
1568
/******************************************
 
1569
 * Module initialization and cleanup
 
1570
 ******************************************/
 
1571
 
 
1572
static void hfc_setup_lapd(struct hfc_chan_duplex *chan)
 
1573
{
 
1574
        chan->netdev->priv = chan;
 
1575
        chan->netdev->open = hfc_open;
 
1576
        chan->netdev->stop = hfc_close;
 
1577
        chan->netdev->hard_start_xmit = hfc_xmit_frame;
 
1578
        chan->netdev->get_stats = hfc_get_stats;
 
1579
        chan->netdev->set_multicast_list = hfc_set_multicast_list;
 
1580
 
 
1581
        memset(chan->netdev->dev_addr, 0x00, sizeof(chan->netdev->dev_addr));
 
1582
 
 
1583
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 
1584
        SET_MODULE_OWNER(chan->netdev);
 
1585
#endif
 
1586
}
 
1587
 
 
1588
static int __devinit hfc_probe(struct pci_dev *pci_dev,
 
1589
        const struct pci_device_id *ent)
 
1590
{
 
1591
        static int cardnum=0;
 
1592
        int err;
 
1593
        int i;
 
1594
 
 
1595
        struct hfc_card *card = NULL;
 
1596
        card = kmalloc(sizeof(struct hfc_card), GFP_KERNEL);
 
1597
        if (!card) {
 
1598
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1599
                        "unable to kmalloc!\n");
 
1600
                err = -ENOMEM;
 
1601
                goto err_alloc_hfccard;
 
1602
        }
 
1603
 
 
1604
        memset(card, 0x00, sizeof(struct hfc_card));
 
1605
        card->cardnum = cardnum;
 
1606
        card->pcidev = pci_dev;
 
1607
        spin_lock_init(&card->lock);
 
1608
 
 
1609
        pci_set_drvdata(pci_dev, card);
 
1610
 
 
1611
        if ((err = pci_enable_device(pci_dev))) {
 
1612
                goto err_pci_enable_device;
 
1613
        }
 
1614
 
 
1615
        if ((err = pci_set_dma_mask(pci_dev, PCI_DMA_32BIT))) {
 
1616
                printk(KERN_ERR hfc_DRIVER_PREFIX
 
1617
                        "card %d: "
 
1618
                        "No suitable DMA configuration available.\n",
 
1619
                        card->cardnum);
 
1620
                goto err_pci_set_dma_mask;
 
1621
        }
 
1622
 
 
1623
        pci_write_config_word(pci_dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
 
1624
 
 
1625
        if((err = pci_request_regions(pci_dev, hfc_DRIVER_NAME))) {
 
1626
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1627
                        "card %d: "
 
1628
                        "cannot request I/O memory region\n",
 
1629
                        card->cardnum);
 
1630
                goto err_pci_request_regions;
 
1631
        }
 
1632
 
 
1633
        pci_set_master(pci_dev);
 
1634
 
 
1635
        if (!pci_dev->irq) {
 
1636
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1637
                        "card %d: "
 
1638
                        "no irq!\n",
 
1639
                        card->cardnum);
 
1640
                err = -ENODEV;
 
1641
                goto err_noirq;
 
1642
        }
 
1643
 
 
1644
        card->io_bus_mem = pci_resource_start(pci_dev,1);
 
1645
        if (!card->io_bus_mem) {
 
1646
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1647
                        "card %d: "
 
1648
                        "no iomem!\n",
 
1649
                        card->cardnum);
 
1650
                err = -ENODEV;
 
1651
                goto err_noiobase;
 
1652
        }
 
1653
 
 
1654
        if(!(card->io_mem = ioremap(card->io_bus_mem, hfc_PCI_MEM_SIZE))) {
 
1655
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1656
                        "card %d: "
 
1657
                        "cannot ioremap I/O memory\n",
 
1658
                        card->cardnum);
 
1659
                err = -ENODEV;
 
1660
                goto err_ioremap;
 
1661
        }
 
1662
 
 
1663
        // pci_alloc_consistent guarantees alignment (Documentation/DMA-mapping.txt)
 
1664
        card->fifo_mem = pci_alloc_consistent(pci_dev, hfc_FIFO_SIZE, &card->fifo_bus_mem);
 
1665
        if (!card->fifo_mem) {
 
1666
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1667
                        "card %d: "
 
1668
                        "unable to allocate FIFO DMA memory!\n",
 
1669
                        card->cardnum);
 
1670
                err = -ENOMEM;
 
1671
                goto err_alloc_fifo;
 
1672
        }
 
1673
 
 
1674
        memset(card->fifo_mem, 0x00, hfc_FIFO_SIZE);
 
1675
 
 
1676
        card->fifos = card->fifo_mem;
 
1677
 
 
1678
        pci_write_config_dword(card->pcidev, hfc_PCI_MWBA, card->fifo_bus_mem);
 
1679
 
 
1680
        if ((err = request_irq(card->pcidev->irq, &hfc_interrupt,
 
1681
                ZAP_IRQ_SHARED, hfc_DRIVER_NAME, card))) {
 
1682
                printk(KERN_CRIT hfc_DRIVER_PREFIX
 
1683
                        "card %d: "
 
1684
                        "unable to register irq\n",
 
1685
                        card->cardnum);
 
1686
                goto err_request_irq;
 
1687
        }
 
1688
 
 
1689
        card->nt_mode = FALSE;
 
1690
 
 
1691
        if (modes & (1 << card->cardnum))
 
1692
                card->nt_mode = TRUE;
 
1693
 
 
1694
        for (i=0; i<hfc_MAX_BOARDS; i++) {
 
1695
                /* DEBUG printk(KERN_INFO "nt_modes[%i]=%i\n", i, nt_modes[i]); */
 
1696
                if (nt_modes[i] == card->cardnum) {
 
1697
                        card->nt_mode=TRUE;
 
1698
                }
 
1699
        }
 
1700
 
 
1701
//---------------------------------- D
 
1702
        card->chans[D].card = card;
 
1703
        card->chans[D].name = "D";
 
1704
        card->chans[D].status = free;
 
1705
        card->chans[D].number = D;
 
1706
        card->chans[D].protocol = ETH_P_LAPD;
 
1707
        spin_lock_init(&card->chans[D].lock);
 
1708
 
 
1709
        card->chans[D].rx.chan      = &card->chans[D];
 
1710
        card->chans[D].rx.fifo_base = card->fifos + 0x4000;
 
1711
        card->chans[D].rx.z_base    = card->fifos + 0x4000;
 
1712
        card->chans[D].rx.z1_base   = card->fifos + 0x6080;
 
1713
        card->chans[D].rx.z2_base   = card->fifos + 0x6082;
 
1714
        card->chans[D].rx.z_min     = 0x0000;
 
1715
        card->chans[D].rx.z_max     = 0x01FF;
 
1716
        card->chans[D].rx.f_min     = 0x10;
 
1717
        card->chans[D].rx.f_max     = 0x1F;
 
1718
        card->chans[D].rx.f1        = card->fifos + 0x60a0;
 
1719
        card->chans[D].rx.f2        = card->fifos + 0x60a1;
 
1720
        card->chans[D].rx.fifo_size = card->chans[D].rx.z_max - card->chans[D].rx.z_min + 1;
 
1721
        card->chans[D].rx.f_num     = card->chans[D].rx.f_max - card->chans[D].rx.f_min + 1;
 
1722
 
 
1723
        card->chans[D].tx.chan      = &card->chans[D];
 
1724
        card->chans[D].tx.fifo_base = card->fifos + 0x0000;
 
1725
        card->chans[D].tx.z_base    = card->fifos + 0x0000;
 
1726
        card->chans[D].tx.z1_base   = card->fifos + 0x2080;
 
1727
        card->chans[D].tx.z2_base   = card->fifos + 0x2082;
 
1728
        card->chans[D].tx.z_min     = 0x0000;
 
1729
        card->chans[D].tx.z_max     = 0x01FF;
 
1730
        card->chans[D].tx.f_min     = 0x10;
 
1731
        card->chans[D].tx.f_max     = 0x1F;
 
1732
        card->chans[D].tx.f1        = card->fifos + 0x20a0;
 
1733
        card->chans[D].tx.f2        = card->fifos + 0x20a1;
 
1734
        card->chans[D].tx.fifo_size = card->chans[D].tx.z_max - card->chans[D].tx.z_min + 1;
 
1735
        card->chans[D].tx.f_num     = card->chans[D].tx.f_max - card->chans[D].tx.f_min + 1;
 
1736
 
 
1737
        if(!(card->chans[D].netdev = alloc_netdev(0, "isdn%dd", setup_lapd))) {
 
1738
                printk(KERN_ERR hfc_DRIVER_PREFIX
 
1739
                        "net_device alloc failed, abort.\n");
 
1740
                err = -ENOMEM;
 
1741
                goto err_alloc_netdev_d;
 
1742
        }
 
1743
 
 
1744
        hfc_setup_lapd(&card->chans[D]);
 
1745
 
 
1746
        card->chans[D].netdev->irq = card->pcidev->irq;
 
1747
        card->chans[D].netdev->base_addr = card->io_bus_mem;
 
1748
/*      card->chans[D].netdev->rmem_start = card->fifo_bus_mem + 0x4000;
 
1749
        card->chans[D].netdev->rmem_end = card->fifo_bus_mem + 0x4000 +
 
1750
                card->chans[D].rx.fifo_size - 1;*/
 
1751
        card->chans[D].netdev->mem_start = card->fifo_bus_mem + 0x0000;
 
1752
        card->chans[D].netdev->mem_end = card->fifo_bus_mem + 0x0000 +
 
1753
                card->chans[D].tx.fifo_size - 1;
 
1754
 
 
1755
        if((err = register_netdev(card->chans[D].netdev))) {
 
1756
                printk(KERN_INFO hfc_DRIVER_PREFIX
 
1757
                        "card %d: "
 
1758
                        "Cannot register net device, aborting.\n",
 
1759
                        card->cardnum);
 
1760
                goto err_register_netdev_d;
 
1761
        }
 
1762
 
 
1763
//---------------------------------- B1
 
1764
        card->chans[B1].card = card;
 
1765
        card->chans[B1].name = "B1";
 
1766
        card->chans[B1].status = free;
 
1767
        card->chans[B1].number = B1;
 
1768
        card->chans[B1].protocol = 0;
 
1769
        spin_lock_init(&card->chans[B1].lock);
 
1770
 
 
1771
        card->chans[B1].rx.chan      = &card->chans[B1];
 
1772
        card->chans[B1].rx.fifo_base = card->fifos + 0x4200;
 
1773
        card->chans[B1].rx.z_base    = card->fifos + 0x4000;
 
1774
        card->chans[B1].rx.z1_base   = card->fifos + 0x6000;
 
1775
        card->chans[B1].rx.z2_base   = card->fifos + 0x6002;
 
1776
        card->chans[B1].rx.z_min     = 0x0200;
 
1777
        card->chans[B1].rx.z_max     = 0x1FFF;
 
1778
        card->chans[B1].rx.f_min     = 0x00;
 
1779
        card->chans[B1].rx.f_max     = 0x1F;
 
1780
        card->chans[B1].rx.f1        = card->fifos + 0x6080;
 
1781
        card->chans[B1].rx.f2        = card->fifos + 0x6081;
 
1782
        card->chans[B1].rx.fifo_size = card->chans[B1].rx.z_max - card->chans[B1].rx.z_min + 1;
 
1783
        card->chans[B1].rx.f_num     = card->chans[B1].rx.f_max - card->chans[B1].rx.f_min + 1;
 
1784
 
 
1785
        card->chans[B1].tx.chan      = &card->chans[B1];
 
1786
        card->chans[B1].tx.fifo_base = card->fifos + 0x0200;
 
1787
        card->chans[B1].tx.z_base    = card->fifos + 0x0000;
 
1788
        card->chans[B1].tx.z1_base   = card->fifos + 0x2000;
 
1789
        card->chans[B1].tx.z2_base   = card->fifos + 0x2002;
 
1790
        card->chans[B1].tx.z_min     = 0x0200;
 
1791
        card->chans[B1].tx.z_max     = 0x1FFF;
 
1792
        card->chans[B1].tx.f_min     = 0x00;
 
1793
        card->chans[B1].tx.f_max     = 0x1F;
 
1794
        card->chans[B1].tx.f1        = card->fifos + 0x2080;
 
1795
        card->chans[B1].tx.f2        = card->fifos + 0x2081;
 
1796
        card->chans[B1].tx.fifo_size = card->chans[B1].tx.z_max - card->chans[B1].tx.z_min + 1;
 
1797
        card->chans[B1].tx.f_num     = card->chans[B1].tx.f_max - card->chans[B1].tx.f_min + 1;
 
1798
 
 
1799
//      card->chans[B1].netdev->irq = card->pcidev->irq;
 
1800
//      card->chans[B1].netdev->base_addr = card->io_bus_mem;
 
1801
/*      card->chans[B1].netdev->rmem_start = card->fifo_bus_mem + 0x4200;
 
1802
        card->chans[B1].netdev->rmem_end = card->fifo_bus_mem + 0x4200 +
 
1803
                card->chans[B1].rx.fifo_size - 1;*/
 
1804
//      card->chans[B1].netdev->mem_start = card->fifo_bus_mem + 0x0200;
 
1805
//      card->chans[B1].netdev->mem_end = card->fifo_bus_mem + 0x0200 +
 
1806
//              card->chans[B1].tx.fifo_size - 1;
 
1807
 
 
1808
//---------------------------------- B2
 
1809
        card->chans[B2].card = card;
 
1810
        card->chans[B2].name = "B2";
 
1811
        card->chans[B2].status = free;
 
1812
        card->chans[B2].number = B2;
 
1813
        card->chans[B2].protocol = 0;
 
1814
        spin_lock_init(&card->chans[B2].lock);
 
1815
 
 
1816
        card->chans[B2].rx.chan      = &card->chans[B2];
 
1817
        card->chans[B2].rx.fifo_base = card->fifos + 0x6200,
 
1818
        card->chans[B2].rx.z_base    = card->fifos + 0x6000;
 
1819
        card->chans[B2].rx.z1_base   = card->fifos + 0x6100;
 
1820
        card->chans[B2].rx.z2_base   = card->fifos + 0x6102;
 
1821
        card->chans[B2].rx.z_min     = 0x0200;
 
1822
        card->chans[B2].rx.z_max     = 0x1FFF;
 
1823
        card->chans[B2].rx.f_min     = 0x00;
 
1824
        card->chans[B2].rx.f_max     = 0x1F;
 
1825
        card->chans[B2].rx.f1        = card->fifos + 0x6180;
 
1826
        card->chans[B2].rx.f2        = card->fifos + 0x6181;
 
1827
        card->chans[B2].rx.fifo_size = card->chans[B2].rx.z_max - card->chans[B2].rx.z_min + 1;
 
1828
        card->chans[B2].rx.f_num     = card->chans[B2].rx.f_max - card->chans[B2].rx.f_min + 1;
 
1829
 
 
1830
        card->chans[B2].tx.chan      = &card->chans[B2];
 
1831
        card->chans[B2].tx.fifo_base = card->fifos + 0x2200;
 
1832
        card->chans[B2].tx.z_base    = card->fifos + 0x2000;
 
1833
        card->chans[B2].tx.z1_base   = card->fifos + 0x2100;
 
1834
        card->chans[B2].tx.z2_base   = card->fifos + 0x2102;
 
1835
        card->chans[B2].tx.z_min     = 0x0200;
 
1836
        card->chans[B2].tx.z_max     = 0x1FFF;
 
1837
        card->chans[B2].tx.f_min     = 0x00;
 
1838
        card->chans[B2].tx.f_max     = 0x1F;
 
1839
        card->chans[B2].tx.f1        = card->fifos + 0x2180;
 
1840
        card->chans[B2].tx.f2        = card->fifos + 0x2181;
 
1841
        card->chans[B2].tx.fifo_size = card->chans[B2].tx.z_max - card->chans[B2].tx.z_min + 1;
 
1842
        card->chans[B2].tx.f_num     = card->chans[B2].tx.f_max - card->chans[B2].tx.f_min + 1;
 
1843
 
 
1844
//      card->chans[B2].netdev->irq = card->pcidev->irq;
 
1845
//      card->chans[B2].netdev->base_addr = card->io_bus_mem;
 
1846
/*      card->chans[B2].netdev->rmem_start = card->fifo_bus_mem + 0x6200;
 
1847
        card->chans[B2].netdev->rmem_end = card->fifo_bus_mem + 0x6200 +
 
1848
                card->chans[B2].rx.fifo_size - 1;*/
 
1849
//      card->chans[B2].netdev->mem_start = card->fifo_bus_mem + 0x2200;
 
1850
//      card->chans[B2].netdev->mem_end = card->fifo_bus_mem + 0x2200 +
 
1851
//              card->chans[B2].tx.fifo_size - 1;
 
1852
 
 
1853
// -------------------------------------------------------
 
1854
 
 
1855
        hfc_zap_initialize(card);
 
1856
 
 
1857
        snprintf(card->proc_dir_name,
 
1858
                        sizeof(card->proc_dir_name),
 
1859
                        "%d", card->cardnum);
 
1860
        card->proc_dir = proc_mkdir(card->proc_dir_name, hfc_proc_zaphfc_dir);
 
1861
        card->proc_dir->owner = THIS_MODULE;
 
1862
 
 
1863
        card->proc_info = create_proc_read_entry(
 
1864
                        "info", 0444, card->proc_dir,
 
1865
                        hfc_proc_read_info, card);
 
1866
        card->proc_info->owner = THIS_MODULE;
 
1867
 
 
1868
        card->proc_fifos = create_proc_read_entry(
 
1869
                        "fifos", 0400, card->proc_dir,
 
1870
                        hfc_proc_read_fifos, card);
 
1871
        card->proc_fifos->owner = THIS_MODULE;
 
1872
 
 
1873
        card->proc_bufs = create_proc_read_entry(
 
1874
                        "bufs", 0400, card->proc_dir,
 
1875
                        hfc_proc_read_bufs, card);
 
1876
        card->proc_bufs->owner = THIS_MODULE;
 
1877
 
 
1878
        hfc_resetCard(card);
 
1879
 
 
1880
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
1881
                "card %d configured for %s mode at mem %#lx (0x%p) IRQ %u\n",
 
1882
                card->cardnum,
 
1883
                card->nt_mode?"NT":"TE",
 
1884
                card->io_bus_mem,
 
1885
                card->io_mem,
 
1886
                card->pcidev->irq); 
 
1887
 
 
1888
        cardnum++;
 
1889
 
 
1890
        return 0;
 
1891
 
 
1892
//      unregister_netdev(card->chans[D].netdev);
 
1893
err_register_netdev_d:
 
1894
        free_netdev(card->chans[D].netdev);
 
1895
err_alloc_netdev_d:
 
1896
        free_irq(pci_dev->irq, card);
 
1897
err_request_irq:
 
1898
        pci_free_consistent(pci_dev, hfc_FIFO_SIZE,
 
1899
                card->fifo_mem, card->fifo_bus_mem);
 
1900
err_alloc_fifo:
 
1901
        iounmap(card->io_mem);
 
1902
err_ioremap:
 
1903
err_noiobase:
 
1904
err_noirq:
 
1905
        pci_release_regions(pci_dev);
 
1906
err_pci_request_regions:
 
1907
err_pci_set_dma_mask:
 
1908
err_pci_enable_device:
 
1909
        kfree(card);
 
1910
err_alloc_hfccard:
 
1911
        return err;
 
1912
}
 
1913
 
 
1914
static void __devexit hfc_remove(struct pci_dev *pci_dev)
 
1915
{
 
1916
        struct hfc_card *card = pci_get_drvdata(pci_dev);
 
1917
 
 
1918
        unregister_netdev(card->chans[D].netdev);
 
1919
 
 
1920
//      unsigned long flags;
 
1921
//      spin_lock_irqsave(&card->lock,flags);
 
1922
 
 
1923
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
1924
                "card %d: "
 
1925
                "shutting down card at %p.\n",
 
1926
                card->cardnum,
 
1927
                card->io_mem);
 
1928
 
 
1929
        hfc_softreset(card);
 
1930
 
 
1931
        zt_unregister(&card->zt_span);
 
1932
 
 
1933
 
 
1934
        // disable memio and bustmaster
 
1935
        pci_write_config_word(pci_dev, PCI_COMMAND, 0);
 
1936
 
 
1937
//      spin_unlock_irqrestore(&card->lock,flags);
 
1938
 
 
1939
        remove_proc_entry("bufs", card->proc_dir);
 
1940
        remove_proc_entry("fifos", card->proc_dir);
 
1941
        remove_proc_entry("info", card->proc_dir);
 
1942
        remove_proc_entry(card->proc_dir_name, hfc_proc_zaphfc_dir);
 
1943
 
 
1944
        free_irq(pci_dev->irq, card);
 
1945
 
 
1946
        pci_free_consistent(pci_dev, hfc_FIFO_SIZE,
 
1947
                card->fifo_mem, card->fifo_bus_mem);
 
1948
 
 
1949
        iounmap(card->io_mem);
 
1950
 
 
1951
        pci_release_regions(pci_dev);
 
1952
 
 
1953
        pci_disable_device(pci_dev);
 
1954
 
 
1955
        free_netdev(card->chans[D].netdev);
 
1956
        kfree(card);
 
1957
}
 
1958
 
 
1959
/******************************************
 
1960
 * Module stuff
 
1961
 ******************************************/
 
1962
 
 
1963
static int __init hfc_init_module(void)
 
1964
{
 
1965
        int ret;
 
1966
 
 
1967
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
1968
                hfc_DRIVER_STRING " loading\n");
 
1969
 
 
1970
        hfc_proc_zaphfc_dir = proc_mkdir(hfc_DRIVER_NAME, proc_root_driver);
 
1971
 
 
1972
        ret = zap_pci_module(&hfc_driver);
 
1973
        return ret;
 
1974
}
 
1975
 
 
1976
module_init(hfc_init_module);
 
1977
 
 
1978
static void __exit hfc_module_exit(void)
 
1979
{
 
1980
        pci_unregister_driver(&hfc_driver);
 
1981
 
 
1982
        remove_proc_entry(hfc_DRIVER_NAME, proc_root_driver);
 
1983
 
 
1984
        printk(KERN_INFO hfc_DRIVER_PREFIX
 
1985
                hfc_DRIVER_STRING " unloaded\n");
 
1986
}
 
1987
 
 
1988
module_exit(hfc_module_exit);
 
1989
 
 
1990
#endif
 
1991
 
 
1992
MODULE_DESCRIPTION(hfc_DRIVER_DESCR);
 
1993
MODULE_AUTHOR("Jens Wilke <jw_vzaphfc@headissue.com>, Daniele (Vihai) Orlandi <daniele@orlandi.com>");
 
1994
#ifdef MODULE_LICENSE
 
1995
MODULE_LICENSE("GPL");
 
1996
#endif
 
1997
 
 
1998
#ifdef LINUX26
 
1999
 
 
2000
module_param(modes, int, 0444);
 
2001
 
 
2002
/*
 
2003
 * Old 2.6 kernels had module_param_array() macro that receive the counter 
 
2004
 * by value.
 
2005
 */
 
2006
int nt_modes_num_values;
 
2007
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)
 
2008
module_param_array(nt_modes, int, nt_modes_num_values, 0444);
 
2009
#else
 
2010
module_param_array(nt_modes, int, &nt_modes_num_values, 0444);
 
2011
#endif
 
2012
 
 
2013
module_param(force_l1_up, int, 0444);
 
2014
module_param(sniff_zaptel_d_channel, int, 0444);
 
2015
#ifdef DEBUG
 
2016
module_param(debug_level, int, 0444);
 
2017
#endif
 
2018
 
 
2019
#else
 
2020
 
 
2021
MODULE_PARM(modes,"i");
 
2022
MODULE_PARM(force_l1_up,"i");
 
2023
MODULE_PARM(sniff_zaptel_d_channel,"i");
 
2024
#ifdef DEBUG
 
2025
MODULE_PARM(debug_level,"i");
 
2026
#endif
 
2027
 
 
2028
#endif // LINUX26
 
2029
 
 
2030
MODULE_PARM_DESC(modes, "[Deprecated] bit-mask to configure NT mode");
 
2031
MODULE_PARM_DESC(nt_modes, "Comma-separated list of card IDs to configure in NT mode");
 
2032
MODULE_PARM_DESC(force_l1_up, "Don't allow L1 to go down");
 
2033
MODULE_PARM_DESC(sniff_zaptel_d_channel, "Make frames transmitted from zaptel"
 
2034
                                        " appear as received by the board");
 
2035
#ifdef DEBUG
 
2036
MODULE_PARM_DESC(debug_level, "Debug verbosity level");
 
2037
#endif