Debian Codegraph @

drivers/dahdi/xpp/card_bri.c

raw symbols SCIP
1 /*
2 * Written by Oron Peled <[email protected]>
3 * Copyright (C) 2004-2006, Xorcom
4 *
5 * Parts derived from Cologne demo driver for the chip.
6 *
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25 #include <linux/init.h>
26 #include <linux/module.h>
27 #include <linux/fs.h>
28 #include <linux/delay.h>
29 #include <linux/seq_file.h>
30 #include "xpd.h"
31 #include "xproto.h"
32 #include "xpp_dahdi.h"
33 #include "card_bri.h"
34 #include "dahdi_debug.h"
35 #include "xbus-core.h"
36
37 static const char rcsid[] = "$Id$";
38
39 #ifndef DAHDI_SIG_HARDHDLC
40 #error Cannot build BRI without HARDHDLC supprt
41 #endif
42
43 /* must be before dahdi_debug.h */
44 static DEF_PARM(int, debug, 0, 0644, "Print DBG statements");
45 static DEF_PARM(uint, poll_interval, 500, 0644,
46 "Poll channel state interval in milliseconds (0 - disable)");
47 static DEF_PARM_BOOL(nt_keepalive, 1, 0644,
48 "Force BRI_NT to keep trying connection");
49
50 enum xhfc_states {
51 ST_RESET = 0, /* G/F0 */
52 /* TE */
53 ST_TE_SENSING = 2, /* F2 */
54 ST_TE_DEACTIVATED = 3, /* F3 */
55 ST_TE_SIGWAIT = 4, /* F4 */
56 ST_TE_IDENT = 5, /* F5 */
57 ST_TE_SYNCED = 6, /* F6 */
58 ST_TE_ACTIVATED = 7, /* F7 */
59 ST_TE_LOST_FRAMING = 8, /* F8 */
60 /* NT */
61 ST_NT_DEACTIVATED = 1, /* G1 */
62 ST_NT_ACTIVATING = 2, /* G2 */
63 ST_NT_ACTIVATED = 3, /* G3 */
64 ST_NT_DEACTIVTING = 4, /* G4 */
65 };
66
67 #ifdef CONFIG_PROC_FS
68 static const char *xhfc_state_name(bool is_nt, enum xhfc_states state)
69 {
70 const char *p;
71
72 #define _E(x) [ST_ ## x] = #x
73 static const char *te_names[] = {
74 _E(RESET),
75 _E(TE_SENSING),
76 _E(TE_DEACTIVATED),
77 _E(TE_SIGWAIT),
78 _E(TE_IDENT),
79 _E(TE_SYNCED),
80 _E(TE_ACTIVATED),
81 _E(TE_LOST_FRAMING),
82 };
83 static const char *nt_names[] = {
84 _E(RESET),
85 _E(NT_DEACTIVATED),
86 _E(NT_ACTIVATING),
87 _E(NT_ACTIVATED),
88 _E(NT_DEACTIVTING),
89 };
90 #undef _E
91 if (is_nt) {
92 if (state > ST_NT_DEACTIVTING)
93 p = "NT ???";
94 else
95 p = nt_names[state];
96 } else {
97 if (state > ST_TE_LOST_FRAMING)
98 p = "TE ???";
99 else
100 p = te_names[state];
101 }
102 return p;
103 }
104 #endif
105
106 /* xhfc Layer1 physical commands */
107 #define HFC_L1_ACTIVATE_TE 0x01
108 #define HFC_L1_FORCE_DEACTIVATE_TE 0x02
109 #define HFC_L1_ACTIVATE_NT 0x03
110 #define HFC_L1_DEACTIVATE_NT 0x04
111
112 #define HFC_L1_ACTIVATING 1
113 #define HFC_L1_ACTIVATED 2
114 #define HFC_TIMER_T1 2500
115 #define HFC_TIMER_T3 8000 /* 8s activation timer T3 */
116 #define HFC_TIMER_OFF -1 /* timer disabled */
117
118 #define A_SU_WR_STA 0x30 /* ST/Up state machine register */
119 #define V_SU_LD_STA 0x10
120 #define V_SU_ACT 0x60 /* start activation/deactivation */
121 #define STA_DEACTIVATE 0x40 /* start deactivation in A_SU_WR_STA */
122 #define STA_ACTIVATE 0x60 /* start activation in A_SU_WR_STA */
123 #define V_SU_SET_G2_G3 0x80
124
125 #define A_SU_RD_STA 0x30
126 typedef union {
127 struct {
128 __u8 v_su_sta:4;
129 __u8 v_su_fr_sync:1;
130 __u8 v_su_t2_exp:1;
131 __u8 v_su_info0:1;
132 __u8 v_g2_g3:1;
133 } bits;
134 __u8 reg;
135 } su_rd_sta_t;
136
137 #define REG30_LOST 3 /* in polls */
138 #define DCHAN_LOST 15000 /* in ticks */
139
140 #define BRI_DCHAN_SIGCAP DAHDI_SIG_HARDHDLC
141 #define BRI_BCHAN_SIGCAP (DAHDI_SIG_CLEAR | DAHDI_SIG_DACS)
142
143 #define IS_NT(xpd) (PHONEDEV(xpd).direction == TO_PHONE)
144 #define BRI_PORT(xpd) ((xpd)->addr.subunit)
145
146 /* shift in PCM highway */
147 #define SUBUNIT_PCM_SHIFT 4
148 #define PCM_SHIFT(mask, sunit) ((mask) << (SUBUNIT_PCM_SHIFT * (sunit)))
149
150 /*---------------- BRI Protocol Commands ----------------------------------*/
151
152 static int write_state_register(xpd_t *xpd, __u8 value);
153 static bool bri_packet_is_valid(xpacket_t *pack);
154 static void bri_packet_dump(const char *msg, xpacket_t *pack);
155 #ifdef CONFIG_PROC_FS
156 static const struct file_operations proc_bri_info_ops;
157 #endif
158 static int bri_spanconfig(struct file *file, struct dahdi_span *span,
159 struct dahdi_lineconfig *lc);
160 static int bri_chanconfig(struct file *file, struct dahdi_chan *chan,
161 int sigtype);
162 static int bri_startup(struct file *file, struct dahdi_span *span);
163 static int bri_shutdown(struct dahdi_span *span);
164
165 #define PROC_BRI_INFO_FNAME "bri_info"
166
167 enum led_state {
168 BRI_LED_OFF = 0x0,
169 BRI_LED_ON = 0x1,
170 /*
171 * We blink by software from driver, so that
172 * if the driver malfunction that blink would stop.
173 */
174 // BRI_LED_BLINK_SLOW = 0x2, /* 1/2 a second blink cycle */
175 // BRI_LED_BLINK_FAST = 0x3 /* 1/4 a second blink cycle */
176 };
177
178 enum bri_led_names {
179 GREEN_LED = 0,
180 RED_LED = 1
181 };
182
183 #define NUM_LEDS 2
184 #define LED_TICKS 100
185
186 struct bri_leds {
187 __u8 state:2;
188 __u8 led_sel:1; /* 0 - GREEN, 1 - RED */
189 __u8 reserved:5;
190 };
191
192 #ifndef MAX_DFRAME_LEN_L1
193 #define MAX_DFRAME_LEN_L1 300
194 #endif
195
196 #define DCHAN_BUFSIZE MAX_DFRAME_LEN_L1
197
198 struct BRI_priv_data {
199 struct proc_dir_entry *bri_info;
200 su_rd_sta_t state_register;
201 bool initialized;
202 bool dchan_is_open;
203 int t1; /* timer 1 for NT deactivation */
204 int t3; /* timer 3 for TE activation */
205 ulong l1_flags;
206 bool reg30_good;
207 uint reg30_ticks;
208 bool layer1_up;
209
210 /*
211 * D-Chan: buffers + extra state info.
212 */
213 atomic_t hdlc_pending;
214 bool txframe_begin;
215
216 uint tick_counter;
217 uint poll_counter;
218 uint dchan_tx_counter;
219 uint dchan_rx_counter;
220 uint dchan_rx_drops;
221 bool dchan_alive;
222 uint dchan_alive_ticks;
223 uint dchan_notx_ticks;
224 uint dchan_norx_ticks;
225 enum led_state ledstate[NUM_LEDS];
226 };
227
228 static xproto_table_t PROTO_TABLE(BRI);
229
230 DEF_RPACKET_DATA(BRI, SET_LED, /* Set one of the LED's */
231 struct bri_leds bri_leds;);
232
233 static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led,
234 enum led_state to_led_state);
235
236 #define DO_LED(xpd, which, tostate) \
237 CALL_PROTO(BRI, SET_LED, (xpd)->xbus, (xpd), (which), (tostate))
238
239 #define DEBUG_BUF_SIZE (100)
240 static void dump_hex_buf(xpd_t *xpd, char *msg, __u8 *buf, size_t len)
241 {
242 char debug_buf[DEBUG_BUF_SIZE + 1];
243 int i;
244 int n = 0;
245
246 debug_buf[0] = '\0';
247 for (i = 0; i < len && n < DEBUG_BUF_SIZE; i++)
248 n += snprintf(&debug_buf[n], DEBUG_BUF_SIZE - n, "%02X ",
249 buf[i]);
250 XPD_NOTICE(xpd, "%s[0..%zd]: %s%s\n", msg, len - 1, debug_buf,
251 (n >= DEBUG_BUF_SIZE) ? "..." : "");
252 }
253
254 static void dump_dchan_packet(xpd_t *xpd, bool transmit, __u8 *buf, int len)
255 {
256 struct BRI_priv_data *priv;
257 char msgbuf[MAX_PROC_WRITE];
258 char ftype = '?';
259 char *direction;
260 int frame_begin;
261
262 priv = xpd->priv;
263 BUG_ON(!priv);
264 if (transmit) {
265 direction = "TX";
266 frame_begin = priv->txframe_begin;
267 } else {
268 direction = "RX";
269 frame_begin = 1;
270 }
271 if (frame_begin) { /* Packet start */
272 if (!IS_SET(buf[0], 7))
273 ftype = 'I'; /* Information */
274 else if (IS_SET(buf[0], 7) && !IS_SET(buf[0], 6))
275 ftype = 'S'; /* Supervisory */
276 else if (IS_SET(buf[0], 7) && IS_SET(buf[0], 6))
277 ftype = 'U'; /* Unnumbered */
278 else
279 XPD_NOTICE(xpd, "Unknown frame type 0x%X\n", buf[0]);
280
281 snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = (%c) ", direction,
282 ftype);
283 } else {
284 snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = ", direction);
285 }
286 dump_hex_buf(xpd, msgbuf, buf, len);
287 }
288
289 static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer,
290 int value)
291 {
292 if (value == HFC_TIMER_OFF)
293 XPD_DBG(SIGNAL, xpd, "Timer %s DISABLE\n", name);
294 else
295 XPD_DBG(SIGNAL, xpd, "Timer %s: set to %d\n", name, value);
296 *bri_timer = value;
297 }
298
299 static void dchan_state(xpd_t *xpd, bool up)
300 {
301 struct BRI_priv_data *priv;
302
303 BUG_ON(!xpd);
304 priv = xpd->priv;
305 BUG_ON(!priv);
306 if (priv->dchan_alive == up)
307 return;
308 if (up) {
309 XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel RUNNING\n");
310 priv->dchan_alive = 1;
311 } else {
312 XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel STOPPED\n");
313 priv->dchan_rx_counter = priv->dchan_tx_counter =
314 priv->dchan_rx_drops = 0;
315 priv->dchan_alive = 0;
316 priv->dchan_alive_ticks = 0;
317 }
318 }
319
320 static void layer1_state(xpd_t *xpd, bool up)
321 {
322 struct BRI_priv_data *priv;
323
324 BUG_ON(!xpd);
325 priv = xpd->priv;
326 BUG_ON(!priv);
327 if (priv->layer1_up == up)
328 return;
329 priv->layer1_up = up;
330 XPD_DBG(SIGNAL, xpd, "STATE CHANGE: Layer1 %s\n", (up) ? "UP" : "DOWN");
331 if (!up)
332 dchan_state(xpd, 0);
333 }
334
335 static void te_activation(xpd_t *xpd, bool on)
336 {
337 struct BRI_priv_data *priv;
338 __u8 curr_state;
339
340 BUG_ON(!xpd);
341 priv = xpd->priv;
342 BUG_ON(!priv);
343 curr_state = priv->state_register.bits.v_su_sta;
344 XPD_DBG(SIGNAL, xpd, "%s\n", (on) ? "ON" : "OFF");
345 if (on) {
346 if (curr_state == ST_TE_DEACTIVATED) {
347 XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_TE\n");
348 set_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
349 write_state_register(xpd, STA_ACTIVATE);
350 set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_T3);
351 } else {
352 XPD_DBG(SIGNAL, xpd,
353 "HFC_L1_ACTIVATE_TE (state %d, ignored)\n",
354 curr_state);
355 }
356 } else { /* happen only because of T3 expiry */
357 switch (curr_state) {
358 case ST_TE_DEACTIVATED: /* F3 */
359 case ST_TE_SYNCED: /* F6 */
360 case ST_TE_ACTIVATED: /* F7 */
361 XPD_DBG(SIGNAL, xpd,
362 "HFC_L1_FORCE_DEACTIVATE_TE "
363 "(state %d, ignored)\n",
364 curr_state);
365 break;
366 case ST_TE_SIGWAIT: /* F4 */
367 case ST_TE_IDENT: /* F5 */
368 case ST_TE_LOST_FRAMING: /* F8 */
369 XPD_DBG(SIGNAL, xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n");
370 write_state_register(xpd, STA_DEACTIVATE);
371 break;
372 default:
373 XPD_NOTICE(xpd, "Bad TE state: %d\n", curr_state);
374 break;
375 }
376 }
377 }
378
379 static void nt_activation(xpd_t *xpd, bool on)
380 {
381 struct BRI_priv_data *priv;
382 __u8 curr_state;
383
384 BUG_ON(!xpd);
385 priv = xpd->priv;
386 BUG_ON(!priv);
387 curr_state = priv->state_register.bits.v_su_sta;
388 XPD_DBG(SIGNAL, xpd, "%s\n", (on) ? "ON" : "OFF");
389 if (on) {
390 switch (curr_state) {
391 case ST_RESET: /* F/G 0 */
392 case ST_NT_DEACTIVATED: /* G1 */
393 case ST_NT_DEACTIVTING: /* G4 */
394 XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_NT\n");
395 set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_T1);
396 set_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
397 write_state_register(xpd, STA_ACTIVATE);
398 break;
399 case ST_NT_ACTIVATING: /* G2 */
400 case ST_NT_ACTIVATED: /* G3 */
401 XPD_DBG(SIGNAL, xpd,
402 "HFC_L1_ACTIVATE_NT (in state %d, ignored)\n",
403 curr_state);
404 break;
405 }
406 } else {
407 switch (curr_state) {
408 case ST_RESET: /* F/G 0 */
409 case ST_NT_DEACTIVATED: /* G1 */
410 case ST_NT_DEACTIVTING: /* G4 */
411 XPD_DBG(SIGNAL, xpd,
412 "HFC_L1_DEACTIVATE_NT (in state %d, ignored)\n",
413 curr_state);
414 break;
415 case ST_NT_ACTIVATING: /* G2 */
416 case ST_NT_ACTIVATED: /* G3 */
417 XPD_DBG(SIGNAL, xpd, "HFC_L1_DEACTIVATE_NT\n");
418 write_state_register(xpd, STA_DEACTIVATE);
419 break;
420 default:
421 XPD_NOTICE(xpd, "Bad NT state: %d\n", curr_state);
422 break;
423 }
424 }
425 }
426
427 /*
428 * D-Chan receive
429 */
430 static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf,
431 int len)
432 {
433 struct BRI_priv_data *priv;
434 __u8 status;
435
436 priv = xpd->priv;
437 BUG_ON(!priv);
438 if (len <= 0) {
439 XPD_NOTICE(xpd, "D-Chan RX DROP: short frame (len=%d)\n", len);
440 dahdi_hdlc_abort(dchan, DAHDI_EVENT_ABORT);
441 return -EPROTO;
442 }
443 status = buf[len - 1];
444 if (status) {
445 int event = DAHDI_EVENT_ABORT;
446
447 if (status == 0xFF) {
448 XPD_NOTICE(xpd, "D-Chan RX DROP: ABORT: %d\n", status);
449 } else {
450 XPD_NOTICE(xpd, "D-Chan RX DROP: BADFCS: %d\n", status);
451 event = DAHDI_EVENT_BADFCS;
452 }
453 dump_hex_buf(xpd, "D-Chan RX: current packet", buf, len);
454 dahdi_hdlc_abort(dchan, event);
455 return -EPROTO;
456 }
457 return 0;
458 }
459
460 static int rx_dchan(xpd_t *xpd, reg_cmd_t *regcmd)
461 {
462 struct BRI_priv_data *priv;
463 __u8 *src;
464 struct dahdi_chan *dchan;
465 uint len;
466 bool eoframe;
467 int ret = 0;
468
469 src = REG_XDATA(regcmd);
470 len = regcmd->h.bytes;
471 eoframe = regcmd->h.eoframe;
472 if (len <= 0)
473 return 0;
474 if (!SPAN_REGISTERED(xpd)) /* Nowhere to copy data */
475 return 0;
476 BUG_ON(!xpd);
477 priv = xpd->priv;
478 BUG_ON(!priv);
479 dchan = XPD_CHAN(xpd, 2);
480 if (!IS_OFFHOOK(xpd, 2)) { /* D-chan is used? */
481 static int rate_limit;
482
483 if ((rate_limit++ % 1000) == 0)
484 XPD_DBG(SIGNAL, xpd, "D-Chan unused\n");
485 goto out;
486 }
487 XPD_DBG(GENERAL, xpd, "D-Chan RX: eoframe=%d len=%d\n", eoframe, len);
488 dahdi_hdlc_putbuf(dchan, src, (eoframe) ? len - 1 : len);
489 if (!eoframe)
490 goto out;
491 if ((ret = bri_check_stat(xpd, dchan, src, len)) < 0)
492 goto out;
493 /*
494 * Tell Dahdi that we received len-1 bytes.
495 * They include the data and a 2-byte checksum.
496 * The last byte (that we don't pass on) is 0 if the
497 * checksum is correct. If it were wrong, we would drop the
498 * packet in the "if (src[len-1])" above.
499 */
500 dahdi_hdlc_finish(dchan);
501 priv->dchan_rx_counter++;
502 priv->dchan_norx_ticks = 0;
503 out:
504 return ret;
505 }
506
507 /*
508 * D-Chan transmit
509 */
510 /*
511 * DAHDI calls this when it has data it wants to send to
512 * the HDLC controller
513 */
514 static void bri_hdlc_hard_xmit(struct dahdi_chan *chan)
515 {
516 xpd_t *xpd = chan->pvt;
517 struct dahdi_chan *dchan;
518 struct BRI_priv_data *priv;
519
520 priv = xpd->priv;
521 BUG_ON(!priv);
522 dchan = XPD_CHAN(xpd, 2);
523 if (dchan == chan)
524 atomic_inc(&priv->hdlc_pending);
525 }
526
527 static int send_dchan_frame(xpd_t *xpd, xframe_t *xframe, bool is_eof)
528 {
529 struct BRI_priv_data *priv;
530 int ret;
531
532 XPD_DBG(COMMANDS, xpd, "eoframe=%d\n", is_eof);
533 priv = xpd->priv;
534 if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)
535 && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
536 XPD_DBG(SIGNAL, xpd,
537 "Want to transmit: Kick D-Channel transmiter\n");
538 if (!IS_NT(xpd))
539 te_activation(xpd, 1);
540 else
541 nt_activation(xpd, 1);
542 }
543 dump_xframe("send_dchan_frame", xpd->xbus, xframe, debug);
544 ret = send_cmd_frame(xpd->xbus, xframe);
545 if (ret < 0)
546 XPD_ERR(xpd, "%s: failed sending xframe\n", __func__);
547 if (is_eof) {
548 atomic_dec(&priv->hdlc_pending);
549 priv->dchan_tx_counter++;
550 priv->txframe_begin = 1;
551 } else
552 priv->txframe_begin = 0;
553 priv->dchan_notx_ticks = 0;
554 return ret;
555 }
556
557 /*
558 * Fill a single multibyte REGISTER_REQUEST
559 */
560 static void fill_multibyte(xpd_t *xpd, xpacket_t *pack,
561 bool eoframe, char *buf, int len)
562 {
563 reg_cmd_t *reg_cmd;
564 char *p;
565
566 XPACKET_INIT(pack, GLOBAL, REGISTER_REQUEST, xpd->xbus_idx, 0, 0);
567 XPACKET_LEN(pack) = XFRAME_CMD_LEN(REG);
568 reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd);
569 reg_cmd->h.bytes = len;
570 reg_cmd->h.is_multibyte = 1;
571 reg_cmd->h.portnum = xpd->addr.subunit;
572 reg_cmd->h.eoframe = eoframe;
573 p = REG_XDATA(reg_cmd);
574 memcpy(p, buf, len);
575 if (debug)
576 dump_dchan_packet(xpd, 1, p, len);
577 }
578
579 /*
580 * Transmit available D-Channel frames
581 *
582 * - FPGA firmware expect to get this as a sequence of REGISTER_REQUEST
583 * multibyte commands.
584 * - The payload of each command is limited to MULTIBYTE_MAX_LEN bytes.
585 * - We batch several REGISTER_REQUEST packets into a single xframe.
586 * - The xframe is terminated when we get a bri "end of frame"
587 * or when the xframe is full (should not happen).
588 */
589 static int tx_dchan(xpd_t *xpd)
590 {
591 struct BRI_priv_data *priv;
592 xframe_t *xframe;
593 xpacket_t *pack;
594 int packet_count;
595 int eoframe;
596 int ret;
597
598 priv = xpd->priv;
599 BUG_ON(!priv);
600 if (atomic_read(&priv->hdlc_pending) == 0)
601 return 0;
602 if (!SPAN_REGISTERED(xpd)
603 || !(PHONEDEV(xpd).span.flags & DAHDI_FLAG_RUNNING))
604 return 0;
605 /* Allocate frame */
606 xframe = ALLOC_SEND_XFRAME(xpd->xbus);
607 if (!xframe) {
608 XPD_NOTICE(xpd, "%s: failed to allocate new xframe\n",
609 __func__);
610 return -ENOMEM;
611 }
612 for (packet_count = 0, eoframe = 0; !eoframe; packet_count++) {
613 int packet_len = XFRAME_CMD_LEN(REG);
614 char buf[MULTIBYTE_MAX_LEN];
615 int len = MULTIBYTE_MAX_LEN;
616
617 /* Reserve packet */
618 pack = xframe_next_packet(xframe, packet_len);
619 if (!pack) {
620 BUG_ON(!packet_count);
621 /*
622 * A split. Send what we currently have.
623 */
624 XPD_NOTICE(xpd, "%s: xframe is full (%d packets)\n",
625 __func__, packet_count);
626 break;
627 }
628 /* Get data from DAHDI */
629 eoframe = dahdi_hdlc_getbuf(XPD_CHAN(xpd, 2), buf, &len);
630 if (len <= 0) {
631 /*
632 * Already checked priv->hdlc_pending,
633 * should never get here.
634 */
635 if (printk_ratelimit())
636 XPD_ERR(xpd,
637 "%s: hdlc_pending, but nothing "
638 "to transmit?\n", __func__);
639 FREE_SEND_XFRAME(xpd->xbus, xframe);
640 return -EINVAL;
641 }
642 BUG_ON(len > MULTIBYTE_MAX_LEN);
643 fill_multibyte(xpd, pack, eoframe != 0, buf, len);
644 }
645 return send_dchan_frame(xpd, xframe, eoframe != 0);
646 return ret;
647 }
648
649 /*---------------- BRI: Methods -------------------------------------------*/
650
651 static void bri_proc_remove(xbus_t *xbus, xpd_t *xpd)
652 {
653 struct BRI_priv_data *priv;
654
655 BUG_ON(!xpd);
656 priv = xpd->priv;
657 XPD_DBG(PROC, xpd, "\n");
658 #ifdef CONFIG_PROC_FS
659 if (priv->bri_info) {
660 XPD_DBG(PROC, xpd, "Removing '%s'\n", PROC_BRI_INFO_FNAME);
661 remove_proc_entry(PROC_BRI_INFO_FNAME, xpd->proc_xpd_dir);
662 }
663 #endif
664 }
665
666 static int bri_proc_create(xbus_t *xbus, xpd_t *xpd)
667 {
668 struct BRI_priv_data *priv;
669
670 BUG_ON(!xpd);
671 priv = xpd->priv;
672 XPD_DBG(PROC, xpd, "\n");
673 #ifdef CONFIG_PROC_FS
674 XPD_DBG(PROC, xpd, "Creating '%s'\n", PROC_BRI_INFO_FNAME);
675 priv->bri_info = proc_create_data(PROC_BRI_INFO_FNAME, 0444,
676 xpd->proc_xpd_dir, &proc_bri_info_ops, xpd);
677 if (!priv->bri_info) {
678 XPD_ERR(xpd, "Failed to create proc file '%s'\n",
679 PROC_BRI_INFO_FNAME);
680 bri_proc_remove(xbus, xpd);
681 return -EINVAL;
682 }
683 SET_PROC_DIRENTRY_OWNER(priv->bri_info);
684 #endif
685 return 0;
686 }
687
688 static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit,
689 const xproto_table_t *proto_table,
690 const struct unit_descriptor *unit_descriptor,
691 bool to_phone)
692 {
693 xpd_t *xpd = NULL;
694 int channels = min(3, CHANNELS_PERXPD);
695
696 if ((unit_descriptor->ports_per_chip < 1) ||
697 (unit_descriptor->ports_per_chip > 4)) {
698 XBUS_ERR(xbus, "Bad ports_per_chip=%d\n",
699 unit_descriptor->ports_per_chip);
700 return NULL;
701 }
702 if ((unit_descriptor->numchips) < 1 ||
703 (unit_descriptor->numchips > 2)) {
704 XBUS_ERR(xbus, "Bad numchips=%d\n",
705 unit_descriptor->numchips);
706 return NULL;
707 }
708 XBUS_DBG(GENERAL, xbus, "\n");
709 xpd =
710 xpd_alloc(xbus, unit, subunit,
711 sizeof(struct BRI_priv_data), proto_table, unit_descriptor, channels);
712 if (!xpd)
713 return NULL;
714 PHONEDEV(xpd).direction = (to_phone) ? TO_PHONE : TO_PSTN;
715 xpd->type_name = (to_phone) ? "BRI_NT" : "BRI_TE";
716 xbus->sync_mode_default = SYNC_MODE_AB;
717 if (bri_proc_create(xbus, xpd) < 0)
718 goto err;
719 return xpd;
720 err:
721 xpd_free(xpd);
722 return NULL;
723 }
724
725 static int BRI_card_init(xbus_t *xbus, xpd_t *xpd)
726 {
727 struct BRI_priv_data *priv;
728
729 BUG_ON(!xpd);
730 XPD_DBG(GENERAL, xpd, "\n");
731 priv = xpd->priv;
732 DO_LED(xpd, GREEN_LED, BRI_LED_OFF);
733 DO_LED(xpd, RED_LED, BRI_LED_OFF);
734 set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
735 write_state_register(xpd, 0); /* Enable L1 state machine */
736 priv->initialized = 1;
737 return 0;
738 }
739
740 static int BRI_card_remove(xbus_t *xbus, xpd_t *xpd)
741 {
742 BUG_ON(!xpd);
743 XPD_DBG(GENERAL, xpd, "\n");
744 bri_proc_remove(xbus, xpd);
745 return 0;
746 }
747
748 #ifdef DAHDI_AUDIO_NOTIFY
749 static int bri_audio_notify(struct dahdi_chan *chan, int on)
750 {
751 xpd_t *xpd = chan->pvt;
752 int pos = chan->chanpos - 1;
753
754 BUG_ON(!xpd);
755 LINE_DBG(SIGNAL, xpd, pos, "BRI-AUDIO: %s\n", (on) ? "on" : "off");
756 mark_offhook(xpd, pos, on);
757 return 0;
758 }
759 #endif
760
761 static const struct dahdi_span_ops BRI_span_ops = {
762 .owner = THIS_MODULE,
763 .spanconfig = bri_spanconfig,
764 .chanconfig = bri_chanconfig,
765 .startup = bri_startup,
766 .shutdown = bri_shutdown,
767 .hdlc_hard_xmit = bri_hdlc_hard_xmit,
768 .open = xpp_open,
769 .close = xpp_close,
770 .hooksig = xpp_hooksig, /* Only with RBS bits */
771 .ioctl = xpp_ioctl,
772 .maint = xpp_maint,
773 .echocan_create = xpp_echocan_create,
774 .echocan_name = xpp_echocan_name,
775 .assigned = xpp_span_assigned,
776 #ifdef DAHDI_SYNC_TICK
777 .sync_tick = dahdi_sync_tick,
778 #endif
779 #ifdef CONFIG_DAHDI_WATCHDOG
780 .watchdog = xpp_watchdog,
781 #endif
782
783 #ifdef DAHDI_AUDIO_NOTIFY
784 .audio_notify = bri_audio_notify,
785 #endif
786 };
787
788 static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on)
789 {
790 xbus_t *xbus;
791 struct BRI_priv_data *priv;
792 int i;
793
794 BUG_ON(!xpd);
795 xbus = xpd->xbus;
796 priv = xpd->priv;
797 BUG_ON(!xbus);
798 XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
799 if (!on) {
800 /* Nothing to do yet */
801 return 0;
802 }
803 PHONEDEV(xpd).span.spantype =
804 (PHONEDEV(xpd).direction == TO_PHONE)
805 ? SPANTYPE_DIGITAL_BRI_NT
806 : SPANTYPE_DIGITAL_BRI_TE;
807 PHONEDEV(xpd).span.linecompat = DAHDI_CONFIG_AMI | DAHDI_CONFIG_CCS;
808 PHONEDEV(xpd).span.deflaw = DAHDI_LAW_ALAW;
809 BIT_SET(PHONEDEV(xpd).digital_signalling, 2); /* D-Channel */
810 for_each_line(xpd, i) {
811 struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i);
812
813 XPD_DBG(GENERAL, xpd, "setting BRI channel %d\n", i);
814 snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%02d/%1d%1d/%d",
815 xpd->type_name, xbus->num, xpd->addr.unit,
816 xpd->addr.subunit, i);
817 cur_chan->chanpos = i + 1;
818 cur_chan->pvt = xpd;
819 if (i == 2) { /* D-CHAN */
820 cur_chan->sigcap = BRI_DCHAN_SIGCAP;
821 clear_bit(DAHDI_FLAGBIT_HDLC, &cur_chan->flags);
822 priv->txframe_begin = 1;
823 atomic_set(&priv->hdlc_pending, 0);
824 } else {
825 cur_chan->sigcap = BRI_BCHAN_SIGCAP;
826 }
827 }
828 CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
829 PHONEDEV(xpd).span.ops = &BRI_span_ops;
830 return 0;
831 }
832
833 static int BRI_card_dahdi_postregistration(xpd_t *xpd, bool on)
834 {
835 xbus_t *xbus;
836
837 BUG_ON(!xpd);
838 xbus = xpd->xbus;
839 BUG_ON(!xbus);
840 XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off");
841 return (0);
842 }
843
844 static int BRI_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig)
845 {
846 LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig));
847 return 0;
848 }
849
850 /*
851 * LED managment is done by the driver now:
852 * - Turn constant ON RED/GREEN led to indicate NT/TE port
853 * - Very fast "Double Blink" to indicate Layer1 alive (without D-Channel)
854 * - Constant blink (1/2 sec cycle) to indicate D-Channel alive.
855 */
856 static void handle_leds(xbus_t *xbus, xpd_t *xpd)
857 {
858 struct BRI_priv_data *priv;
859 unsigned int timer_count;
860 int which_led;
861 int other_led;
862 int mod;
863
864 BUG_ON(!xpd);
865 if (IS_NT(xpd)) {
866 which_led = RED_LED;
867 other_led = GREEN_LED;
868 } else {
869 which_led = GREEN_LED;
870 other_led = RED_LED;
871 }
872 priv = xpd->priv;
873 BUG_ON(!priv);
874 timer_count = xpd->timer_count;
875 if (xpd->blink_mode) {
876 if ((timer_count % DEFAULT_LED_PERIOD) == 0) {
877 // led state is toggled
878 if (priv->ledstate[which_led] == BRI_LED_OFF) {
879 DO_LED(xpd, which_led, BRI_LED_ON);
880 DO_LED(xpd, other_led, BRI_LED_ON);
881 } else {
882 DO_LED(xpd, which_led, BRI_LED_OFF);
883 DO_LED(xpd, other_led, BRI_LED_OFF);
884 }
885 }
886 return;
887 }
888 if (priv->ledstate[other_led] != BRI_LED_OFF)
889 DO_LED(xpd, other_led, BRI_LED_OFF);
890 if (priv->dchan_alive) {
891 mod = timer_count % 1000;
892 switch (mod) {
893 case 0:
894 DO_LED(xpd, which_led, BRI_LED_ON);
895 break;
896 case 500:
897 DO_LED(xpd, which_led, BRI_LED_OFF);
898 break;
899 }
900 } else if (priv->layer1_up) {
901 mod = timer_count % 1000;
902 switch (mod) {
903 case 0:
904 case 100:
905 DO_LED(xpd, which_led, BRI_LED_ON);
906 break;
907 case 50:
908 case 150:
909 DO_LED(xpd, which_led, BRI_LED_OFF);
910 break;
911 }
912 } else {
913 if (priv->ledstate[which_led] != BRI_LED_ON)
914 DO_LED(xpd, which_led, BRI_LED_ON);
915 }
916 }
917
918 static void handle_bri_timers(xpd_t *xpd)
919 {
920 struct BRI_priv_data *priv;
921
922 BUG_ON(!xpd);
923 priv = xpd->priv;
924 BUG_ON(!priv);
925 if (IS_NT(xpd)) {
926 if (priv->t1 > HFC_TIMER_OFF) {
927 if (--priv->t1 == 0) {
928 set_bri_timer(xpd, "T1", &priv->t1,
929 HFC_TIMER_OFF);
930 if (!nt_keepalive) {
931 /* G2 */
932 if (priv->state_register.bits.v_su_sta == ST_NT_ACTIVATING) {
933 XPD_DBG(SIGNAL, xpd,
934 "T1 Expired. "
935 "Deactivate NT\n");
936 clear_bit(HFC_L1_ACTIVATING,
937 &priv->l1_flags);
938 /* Deactivate NT */
939 nt_activation(xpd, 0);
940 } else
941 XPD_DBG(SIGNAL, xpd,
942 "T1 Expired. "
943 "(state %d, ignored)\n",
944 priv->state_register.
945 bits.v_su_sta);
946 }
947 }
948 }
949 } else {
950 if (priv->t3 > HFC_TIMER_OFF) {
951 /* timer expired ? */
952 if (--priv->t3 == 0) {
953 XPD_DBG(SIGNAL, xpd,
954 "T3 expired. Deactivate TE\n");
955 set_bri_timer(xpd, "T3", &priv->t3,
956 HFC_TIMER_OFF);
957 clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
958 te_activation(xpd, 0); /* Deactivate TE */
959 }
960 }
961 }
962 }
963
964 /* Poll the register ST/Up-State-machine Register, to see if the cable
965 * if a cable is connected to the port.
966 */
967 static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd)
968 {
969 struct BRI_priv_data *priv;
970
971 BUG_ON(!xpd);
972 priv = xpd->priv;
973 BUG_ON(!priv);
974 if (!priv->initialized || !xbus->self_ticking)
975 return 0;
976 if (poll_interval != 0 && (priv->tick_counter % poll_interval) == 0) {
977 // XPD_DBG(GENERAL, xpd, "%d\n", priv->tick_counter);
978 priv->poll_counter++;
979 xpp_register_request(xbus, xpd,
980 BRI_PORT(xpd), /* portno */
981 0, /* writing */
982 A_SU_RD_STA, /* regnum */
983 0, /* do_subreg */
984 0, /* subreg */
985 0, /* data_low */
986 0, /* do_datah */
987 0, /* data_high */
988 0, /* should_reply */
989 0 /* do_expander */
990 );
991
992 if (IS_NT(xpd) && nt_keepalive
993 && !test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)
994 && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) {
995 XPD_DBG(SIGNAL, xpd, "Kick NT D-Channel\n");
996 nt_activation(xpd, 1);
997 }
998 }
999 /* Detect D-Channel disconnect heuristic */
1000 priv->dchan_notx_ticks++;
1001 priv->dchan_norx_ticks++;
1002 priv->dchan_alive_ticks++;
1003 if (priv->dchan_alive
1004 && (priv->dchan_notx_ticks > DCHAN_LOST
1005 || priv->dchan_norx_ticks > DCHAN_LOST)) {
1006 /*
1007 * No tx_dchan() or rx_dchan() for many ticks
1008 * This D-Channel is probabelly dead.
1009 */
1010 dchan_state(xpd, 0);
1011 } else if (priv->dchan_rx_counter > 1 && priv->dchan_tx_counter > 1) {
1012 if (!priv->dchan_alive)
1013 dchan_state(xpd, 1);
1014 }
1015 /* Detect Layer1 disconnect */
1016 if (priv->reg30_good && priv->reg30_ticks > poll_interval * REG30_LOST) {
1017 /* No reply for 1/2 a second */
1018 XPD_ERR(xpd, "Lost state tracking for %d ticks\n",
1019 priv->reg30_ticks);
1020 priv->reg30_good = 0;
1021 layer1_state(xpd, 0);
1022 }
1023 handle_leds(xbus, xpd);
1024 handle_bri_timers(xpd);
1025 tx_dchan(xpd);
1026 priv->tick_counter++;
1027 priv->reg30_ticks++;
1028 return 0;
1029 }
1030
1031 static int BRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd,
1032 unsigned long arg)
1033 {
1034 BUG_ON(!xpd);
1035 if (!XBUS_IS(xpd->xbus, READY))
1036 return -ENODEV;
1037 switch (cmd) {
1038 case DAHDI_TONEDETECT:
1039 /*
1040 * Asterisk call all span types with this (FXS specific)
1041 * call. Silently ignore it.
1042 */
1043 LINE_DBG(SIGNAL, xpd, pos, "BRI: Starting a call\n");
1044 return -ENOTTY;
1045 default:
1046 report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd);
1047 return -ENOTTY;
1048 }
1049 return 0;
1050 }
1051
1052 static int BRI_card_open(xpd_t *xpd, lineno_t pos)
1053 {
1054 struct BRI_priv_data *priv;
1055
1056 BUG_ON(!xpd);
1057 priv = xpd->priv;
1058 if (pos == 2) {
1059 priv->dchan_is_open = 1;
1060 LINE_DBG(SIGNAL, xpd, pos, "OFFHOOK the whole span\n");
1061 BIT_SET(PHONEDEV(xpd).offhook_state, 0);
1062 BIT_SET(PHONEDEV(xpd).offhook_state, 1);
1063 BIT_SET(PHONEDEV(xpd).offhook_state, 2);
1064 CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
1065 }
1066 return 0;
1067 }
1068
1069 static int BRI_card_close(xpd_t *xpd, lineno_t pos)
1070 {
1071 struct BRI_priv_data *priv;
1072
1073 priv = xpd->priv;
1074 /* Clear D-Channel pending data */
1075 if (pos == 2) {
1076 LINE_DBG(SIGNAL, xpd, pos, "ONHOOK the whole span\n");
1077 BIT_CLR(PHONEDEV(xpd).offhook_state, 0);
1078 BIT_CLR(PHONEDEV(xpd).offhook_state, 1);
1079 BIT_CLR(PHONEDEV(xpd).offhook_state, 2);
1080 CALL_PHONE_METHOD(card_pcm_recompute, xpd, 0);
1081 priv->dchan_is_open = 0;
1082 } else if (!priv->dchan_is_open)
1083 mark_offhook(xpd, pos, 0); /* e.g: patgen/pattest */
1084 return 0;
1085 }
1086
1087 /*
1088 * Called only for 'span' keyword in /etc/dahdi/system.conf
1089 */
1090 static int bri_spanconfig(struct file *file, struct dahdi_span *span,
1091 struct dahdi_lineconfig *lc)
1092 {
1093 struct phonedev *phonedev = container_of(span, struct phonedev, span);
1094 xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
1095 const char *framingstr = "";
1096 const char *codingstr = "";
1097 const char *crcstr = "";
1098
1099 /* framing first */
1100 if (lc->lineconfig & DAHDI_CONFIG_B8ZS)
1101 framingstr = "B8ZS";
1102 else if (lc->lineconfig & DAHDI_CONFIG_AMI)
1103 framingstr = "AMI";
1104 else if (lc->lineconfig & DAHDI_CONFIG_HDB3)
1105 framingstr = "HDB3";
1106 /* then coding */
1107 if (lc->lineconfig & DAHDI_CONFIG_ESF)
1108 codingstr = "ESF";
1109 else if (lc->lineconfig & DAHDI_CONFIG_D4)
1110 codingstr = "D4";
1111 else if (lc->lineconfig & DAHDI_CONFIG_CCS)
1112 codingstr = "CCS";
1113 /* E1's can enable CRC checking */
1114 if (lc->lineconfig & DAHDI_CONFIG_CRC4)
1115 crcstr = "CRC4";
1116 XPD_DBG(GENERAL, xpd,
1117 "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n",
1118 IS_NT(xpd) ? "NT" : "TE", lc->span, lc->name, lc->lbo,
1119 framingstr, codingstr, crcstr, lc->lineconfig, lc->sync);
1120 PHONEDEV(xpd).timing_priority = lc->sync;
1121 elect_syncer("BRI-spanconfig");
1122 /*
1123 * FIXME: validate
1124 */
1125 span->lineconfig = lc->lineconfig;
1126 return 0;
1127 }
1128
1129 /*
1130 * Set signalling type (if appropriate)
1131 * Called from dahdi with spinlock held on chan. Must not call back
1132 * dahdi functions.
1133 */
1134 static int bri_chanconfig(struct file *file, struct dahdi_chan *chan,
1135 int sigtype)
1136 {
1137 DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name,
1138 sig2str(sigtype));
1139 // FIXME: sanity checks:
1140 // - should be supported (within the sigcap)
1141 // - should not replace fxs <->fxo ??? (covered by previous?)
1142 return 0;
1143 }
1144
1145 /*
1146 * Called only for 'span' keyword in /etc/dahdi/system.conf
1147 */
1148 static int bri_startup(struct file *file, struct dahdi_span *span)
1149 {
1150 struct phonedev *phonedev = container_of(span, struct phonedev, span);
1151 xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
1152 struct BRI_priv_data *priv;
1153 struct dahdi_chan *dchan;
1154
1155 BUG_ON(!xpd);
1156 priv = xpd->priv;
1157 BUG_ON(!priv);
1158 if (!XBUS_IS(xpd->xbus, READY)) {
1159 XPD_DBG(GENERAL, xpd,
1160 "Startup called by dahdi. No Hardware. Ignored\n");
1161 return -ENODEV;
1162 }
1163 XPD_DBG(GENERAL, xpd, "STARTUP\n");
1164 // Turn on all channels
1165 CALL_PHONE_METHOD(card_state, xpd, 1);
1166 if (SPAN_REGISTERED(xpd)) {
1167 dchan = XPD_CHAN(xpd, 2);
1168 span->flags |= DAHDI_FLAG_RUNNING;
1169 /*
1170 * Dahdi (wrongly) assume that D-Channel need HDLC decoding
1171 * and during dahdi registration override our flags.
1172 *
1173 * Don't Get Mad, Get Even: Now we override dahdi :-)
1174 */
1175 clear_bit(DAHDI_FLAGBIT_HDLC, &dchan->flags);
1176 }
1177 return 0;
1178 }
1179
1180 /*
1181 * Called only for 'span' keyword in /etc/dahdi/system.conf
1182 */
1183 static int bri_shutdown(struct dahdi_span *span)
1184 {
1185 struct phonedev *phonedev = container_of(span, struct phonedev, span);
1186 xpd_t *xpd = container_of(phonedev, struct xpd, phonedev);
1187 struct BRI_priv_data *priv;
1188
1189 BUG_ON(!xpd);
1190 priv = xpd->priv;
1191 BUG_ON(!priv);
1192 if (!XBUS_IS(xpd->xbus, READY)) {
1193 XPD_DBG(GENERAL, xpd,
1194 "Shutdown called by dahdi. No Hardware. Ignored\n");
1195 return -ENODEV;
1196 }
1197 XPD_DBG(GENERAL, xpd, "SHUTDOWN\n");
1198 // Turn off all channels
1199 CALL_PHONE_METHOD(card_state, xpd, 0);
1200 return 0;
1201 }
1202
1203 static void BRI_card_pcm_recompute(xpd_t *xpd, xpp_line_t dont_care)
1204 {
1205 int i;
1206 int line_count;
1207 xpp_line_t pcm_mask;
1208 uint pcm_len;
1209 xpd_t *main_xpd;
1210 unsigned long flags;
1211
1212 BUG_ON(!xpd);
1213 main_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, 0);
1214 if (!main_xpd) {
1215 XPD_DBG(DEVICES, xpd,
1216 "Unit 0 is already gone. Ignore request\n");
1217 return;
1218 }
1219 /*
1220 * We calculate all subunits, so use the main lock
1221 * as a mutex for the whole operation.
1222 */
1223 spin_lock_irqsave(&PHONEDEV(main_xpd).lock_recompute_pcm, flags);
1224 line_count = 0;
1225 pcm_mask = 0;
1226 for (i = 0; i < MAX_SUBUNIT; i++) {
1227 xpd_t *sub_xpd = xpd_byaddr(xpd->xbus, main_xpd->addr.unit, i);
1228
1229 if (sub_xpd) {
1230 xpp_line_t lines =
1231 PHONEDEV(sub_xpd).
1232 offhook_state & ~(PHONEDEV(sub_xpd).
1233 digital_signalling);
1234
1235 if (lines) {
1236 pcm_mask |= PCM_SHIFT(lines, i);
1237 line_count += 2;
1238 }
1239 /* subunits have fake pcm_len and wanted_pcm_mask */
1240 if (i > 0)
1241 update_wanted_pcm_mask(sub_xpd, lines, 0);
1242 }
1243 }
1244 /*
1245 * FIXME: Workaround a bug in sync code of the Astribank.
1246 * Send dummy PCM for sync.
1247 */
1248 if (main_xpd->addr.unit == 0 && line_count == 0) {
1249 pcm_mask = BIT(0);
1250 line_count = 1;
1251 }
1252 /*
1253 * The main unit account for all subunits (pcm_len and wanted_pcm_mask).
1254 */
1255 pcm_len = (line_count)
1256 ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) +
1257 line_count * DAHDI_CHUNKSIZE : 0L;
1258 update_wanted_pcm_mask(main_xpd, pcm_mask, pcm_len);
1259 spin_unlock_irqrestore(&PHONEDEV(main_xpd).lock_recompute_pcm, flags);
1260 }
1261
1262 static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack)
1263 {
1264 __u8 *pcm;
1265 unsigned long flags;
1266 int i;
1267 int subunit;
1268 xpp_line_t pcm_mask = 0;
1269 xpp_line_t wanted_lines;
1270
1271 BUG_ON(!xpd);
1272 BUG_ON(!pack);
1273 pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm);
1274 for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) {
1275 xpd_t *tmp_xpd;
1276
1277 tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit);
1278 if (!tmp_xpd || !tmp_xpd->card_present)
1279 continue;
1280 spin_lock_irqsave(&tmp_xpd->lock, flags);
1281 wanted_lines = PHONEDEV(tmp_xpd).wanted_pcm_mask;
1282 for_each_line(tmp_xpd, i) {
1283 struct dahdi_chan *chan = XPD_CHAN(tmp_xpd, i);
1284
1285 if (IS_SET(wanted_lines, i)) {
1286 if (SPAN_REGISTERED(tmp_xpd)) {
1287 #ifdef DEBUG_PCMTX
1288 int channo = chan->channo;
1289
1290 if (pcmtx >= 0 && pcmtx_chan == channo)
1291 memset((u_char *)pcm, pcmtx,
1292 DAHDI_CHUNKSIZE);
1293 else
1294 #endif
1295 memcpy((u_char *)pcm,
1296 chan->writechunk,
1297 DAHDI_CHUNKSIZE);
1298 } else
1299 memset((u_char *)pcm, 0x7F,
1300 DAHDI_CHUNKSIZE);
1301 pcm += DAHDI_CHUNKSIZE;
1302 }
1303 }
1304 pcm_mask |= PCM_SHIFT(wanted_lines, subunit);
1305 XPD_COUNTER(tmp_xpd, PCM_WRITE)++;
1306 spin_unlock_irqrestore(&tmp_xpd->lock, flags);
1307 }
1308 RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines) = pcm_mask;
1309 }
1310
1311 static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack)
1312 {
1313 __u8 *pcm;
1314 xpp_line_t pcm_mask;
1315 unsigned long flags;
1316 int subunit;
1317 int i;
1318
1319 /*
1320 * Subunit 0 handle all other subunits
1321 */
1322 if (xpd->addr.subunit != 0)
1323 return;
1324 if (!SPAN_REGISTERED(xpd))
1325 return;
1326 pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm);
1327 pcm_mask = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines);
1328 for (subunit = 0; subunit < MAX_SUBUNIT;
1329 subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) {
1330 xpd_t *tmp_xpd;
1331
1332 if (!pcm_mask)
1333 break; /* optimize */
1334 tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit);
1335 if (!tmp_xpd || !tmp_xpd->card_present
1336 || !SPAN_REGISTERED(tmp_xpd))
1337 continue;
1338 spin_lock_irqsave(&tmp_xpd->lock, flags);
1339 for (i = 0; i < 2; i++) {
1340 xpp_line_t tmp_mask = pcm_mask & (BIT(0) | BIT(1));
1341 volatile u_char *r;
1342
1343 if (IS_SET(tmp_mask, i)) {
1344 r = XPD_CHAN(tmp_xpd, i)->readchunk;
1345 #if 0
1346 /* DEBUG */
1347 memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE);
1348 #endif
1349 memcpy((u_char *)r, pcm, DAHDI_CHUNKSIZE);
1350 pcm += DAHDI_CHUNKSIZE;
1351 }
1352 }
1353 XPD_COUNTER(tmp_xpd, PCM_READ)++;
1354 spin_unlock_irqrestore(&tmp_xpd->lock, flags);
1355 }
1356 }
1357
1358 static int BRI_timing_priority(xpd_t *xpd)
1359 {
1360 struct BRI_priv_data *priv;
1361
1362 priv = xpd->priv;
1363 BUG_ON(!priv);
1364 if (priv->layer1_up)
1365 return PHONEDEV(xpd).timing_priority;
1366 XPD_DBG(SYNC, xpd, "No timing priority (no layer1)\n");
1367 return -ENOENT;
1368 }
1369
1370 static int BRI_echocancel_timeslot(xpd_t *xpd, int pos)
1371 {
1372 return xpd->addr.subunit * 4 + pos;
1373 }
1374
1375 static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask)
1376 {
1377 struct BRI_priv_data *priv;
1378 int i;
1379
1380 BUG_ON(!xpd);
1381 priv = xpd->priv;
1382 BUG_ON(!priv);
1383 XPD_DBG(GENERAL, xpd, "0x%8X\n", ec_mask);
1384 if (!ECHOOPS(xpd->xbus)) {
1385 XPD_DBG(GENERAL, xpd,
1386 "No echo canceller in XBUS: Doing nothing.\n");
1387 return -EINVAL;
1388 }
1389 for (i = 0; i < PHONEDEV(xpd).channels - 1; i++) {
1390 int on = BIT(i) & ec_mask;
1391
1392 CALL_EC_METHOD(ec_set, xpd->xbus, xpd, i, on);
1393 }
1394 CALL_EC_METHOD(ec_update, xpd->xbus, xpd->xbus);
1395 return 0;
1396 }
1397
1398 /*---------------- BRI: HOST COMMANDS -------------------------------------*/
1399
1400 static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led,
1401 enum led_state to_led_state)
1402 {
1403 int ret = 0;
1404 xframe_t *xframe;
1405 xpacket_t *pack;
1406 struct bri_leds *bri_leds;
1407 struct BRI_priv_data *priv;
1408
1409 BUG_ON(!xbus);
1410 priv = xpd->priv;
1411 BUG_ON(!priv);
1412 XPD_DBG(LEDS, xpd, "%s -> %d\n", (which_led) ? "RED" : "GREEN",
1413 to_led_state);
1414 XFRAME_NEW_CMD(xframe, pack, xbus, BRI, SET_LED, xpd->xbus_idx);
1415 bri_leds = &RPACKET_FIELD(pack, BRI, SET_LED, bri_leds);
1416 bri_leds->state = to_led_state;
1417 bri_leds->led_sel = which_led;
1418 XPACKET_LEN(pack) = RPACKET_SIZE(BRI, SET_LED);
1419 ret = send_cmd_frame(xbus, xframe);
1420 priv->ledstate[which_led] = to_led_state;
1421 return ret;
1422 }
1423
1424 static int write_state_register(xpd_t *xpd, __u8 value)
1425 {
1426 int ret;
1427
1428 XPD_DBG(REGS, xpd, "value = 0x%02X\n", value);
1429 ret = xpp_register_request(xpd->xbus, xpd,
1430 BRI_PORT(xpd), /* portno */
1431 1, /* writing */
1432 A_SU_WR_STA, /* regnum */
1433 0, /* do_subreg */
1434 0, /* subreg */
1435 value, /* data_low */
1436 0, /* do_datah */
1437 0, /* data_high */
1438 0, /* should_reply */
1439 0 /* do_expander */
1440 );
1441 return ret;
1442 }
1443
1444 /*---------------- BRI: Astribank Reply Handlers --------------------------*/
1445 static void su_new_state(xpd_t *xpd, __u8 reg_x30)
1446 {
1447 struct BRI_priv_data *priv;
1448 su_rd_sta_t new_state;
1449
1450 BUG_ON(!xpd);
1451 priv = xpd->priv;
1452 BUG_ON(!priv);
1453 if (!priv->initialized) {
1454 XPD_ERR(xpd, "%s called on uninitialized AB\n", __func__);
1455 return;
1456 }
1457 new_state.reg = reg_x30;
1458 if (new_state.bits.v_su_t2_exp)
1459 XPD_NOTICE(xpd, "T2 Expired\n");
1460 priv->reg30_ticks = 0;
1461 priv->reg30_good = 1;
1462 if (priv->state_register.bits.v_su_sta == new_state.bits.v_su_sta)
1463 return; /* same same */
1464 XPD_DBG(SIGNAL, xpd, "%02X ---> %02X (info0=%d) (%s%i)\n",
1465 priv->state_register.reg, reg_x30, new_state.bits.v_su_info0,
1466 IS_NT(xpd) ? "G" : "F", new_state.bits.v_su_sta);
1467 if (!IS_NT(xpd)) {
1468 switch (new_state.bits.v_su_sta) {
1469 case ST_TE_DEACTIVATED: /* F3 */
1470 XPD_DBG(SIGNAL, xpd, "State ST_TE_DEACTIVATED (F3)\n");
1471 clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
1472 layer1_state(xpd, 0);
1473 break;
1474 case ST_TE_SIGWAIT: /* F4 */
1475 XPD_DBG(SIGNAL, xpd, "State ST_TE_SIGWAIT (F4)\n");
1476 layer1_state(xpd, 0);
1477 break;
1478 case ST_TE_IDENT: /* F5 */
1479 XPD_DBG(SIGNAL, xpd, "State ST_TE_IDENT (F5)\n");
1480 layer1_state(xpd, 0);
1481 break;
1482 case ST_TE_SYNCED: /* F6 */
1483 XPD_DBG(SIGNAL, xpd, "State ST_TE_SYNCED (F6)\n");
1484 layer1_state(xpd, 0);
1485 break;
1486 case ST_TE_ACTIVATED: /* F7 */
1487 XPD_DBG(SIGNAL, xpd, "State ST_TE_ACTIVATED (F7)\n");
1488 set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF);
1489 clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
1490 set_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
1491 layer1_state(xpd, 1);
1492 update_xpd_status(xpd, DAHDI_ALARM_NONE);
1493 break;
1494 case ST_TE_LOST_FRAMING: /* F8 */
1495 XPD_DBG(SIGNAL, xpd, "State ST_TE_LOST_FRAMING (F8)\n");
1496 layer1_state(xpd, 0);
1497 break;
1498 default:
1499 XPD_NOTICE(xpd, "Bad TE state: %d\n",
1500 new_state.bits.v_su_sta);
1501 break;
1502 }
1503
1504 } else {
1505 switch (new_state.bits.v_su_sta) {
1506 case ST_NT_DEACTIVATED: /* G1 */
1507 XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVATED (G1)\n");
1508 clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
1509 set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
1510 layer1_state(xpd, 0);
1511 break;
1512 case ST_NT_ACTIVATING: /* G2 */
1513 XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATING (G2)\n");
1514 layer1_state(xpd, 0);
1515 if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags))
1516 nt_activation(xpd, 1);
1517 break;
1518 case ST_NT_ACTIVATED: /* G3 */
1519 XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATED (G3)\n");
1520 clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags);
1521 set_bit(HFC_L1_ACTIVATED, &priv->l1_flags);
1522 set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
1523 layer1_state(xpd, 1);
1524 update_xpd_status(xpd, DAHDI_ALARM_NONE);
1525 break;
1526 case ST_NT_DEACTIVTING: /* G4 */
1527 XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVTING (G4)\n");
1528 set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF);
1529 layer1_state(xpd, 0);
1530 break;
1531 default:
1532 XPD_NOTICE(xpd, "Bad NT state: %d\n",
1533 new_state.bits.v_su_sta);
1534 break;
1535 }
1536 }
1537 priv->state_register.reg = new_state.reg;
1538 }
1539
1540 static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info)
1541 {
1542 unsigned long flags;
1543 struct BRI_priv_data *priv;
1544 struct xpd_addr addr;
1545 xpd_t *orig_xpd;
1546 int ret;
1547
1548 /* Map UNIT + PORTNUM to XPD */
1549 orig_xpd = xpd;
1550 addr.unit = orig_xpd->addr.unit;
1551 addr.subunit = info->h.portnum;
1552 xpd = xpd_byaddr(xbus, addr.unit, addr.subunit);
1553 if (!xpd) {
1554 static int rate_limit;
1555
1556 if ((rate_limit++ % 1003) < 5)
1557 notify_bad_xpd(__func__, xbus, addr, orig_xpd->xpdname);
1558 return -EPROTO;
1559 }
1560 spin_lock_irqsave(&xpd->lock, flags);
1561 priv = xpd->priv;
1562 BUG_ON(!priv);
1563 if (REG_FIELD(info, do_subreg)) {
1564 XPD_DBG(REGS, xpd, "RI %02X %02X %02X\n",
1565 REG_FIELD(info, regnum), REG_FIELD(info, subreg),
1566 REG_FIELD(info, data_low));
1567 } else {
1568 if (REG_FIELD(info, regnum) != A_SU_RD_STA)
1569 XPD_DBG(REGS, xpd, "RD %02X %02X\n",
1570 REG_FIELD(info, regnum), REG_FIELD(info,
1571 data_low));
1572 else
1573 XPD_DBG(REGS, xpd, "Got SU_RD_STA=%02X\n",
1574 REG_FIELD(info, data_low));
1575 }
1576 if (info->h.is_multibyte) {
1577 XPD_DBG(REGS, xpd, "Got Multibyte: %d bytes, eoframe: %d\n",
1578 info->h.bytes, info->h.eoframe);
1579 ret = rx_dchan(xpd, info);
1580 if (ret < 0) {
1581 priv->dchan_rx_drops++;
1582 if (atomic_read(&PHONEDEV(xpd).open_counter) > 0)
1583 XPD_NOTICE(xpd, "Multibyte Drop: errno=%d\n",
1584 ret);
1585 }
1586 goto end;
1587 }
1588 if (REG_FIELD(info, regnum) == A_SU_RD_STA)
1589 su_new_state(xpd, REG_FIELD(info, data_low));
1590
1591 /* Update /proc info only if reply relate to the last slic read request */
1592 if (REG_FIELD(&xpd->requested_reply, regnum) ==
1593 REG_FIELD(info, regnum)
1594 && REG_FIELD(&xpd->requested_reply, do_subreg) ==
1595 REG_FIELD(info, do_subreg)
1596 && REG_FIELD(&xpd->requested_reply, subreg) ==
1597 REG_FIELD(info, subreg)) {
1598 xpd->last_reply = *info;
1599 }
1600
1601 end:
1602 spin_unlock_irqrestore(&xpd->lock, flags);
1603 return 0;
1604 }
1605
1606 static int BRI_card_state(xpd_t *xpd, bool on)
1607 {
1608 struct BRI_priv_data *priv;
1609
1610 BUG_ON(!xpd);
1611 priv = xpd->priv;
1612 XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF");
1613 if (on) {
1614 if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)) {
1615 if (!IS_NT(xpd))
1616 te_activation(xpd, 1);
1617 else
1618 nt_activation(xpd, 1);
1619 }
1620 } else if (IS_NT(xpd))
1621 nt_activation(xpd, 0);
1622 return 0;
1623 }
1624
1625 static const struct xops bri_xops = {
1626 .card_new = BRI_card_new,
1627 .card_init = BRI_card_init,
1628 .card_remove = BRI_card_remove,
1629 .card_tick = BRI_card_tick,
1630 .card_register_reply = BRI_card_register_reply,
1631 };
1632
1633 static const struct phoneops bri_phoneops = {
1634 .card_dahdi_preregistration = BRI_card_dahdi_preregistration,
1635 .card_dahdi_postregistration = BRI_card_dahdi_postregistration,
1636 .card_hooksig = BRI_card_hooksig,
1637 .card_pcm_recompute = BRI_card_pcm_recompute,
1638 .card_pcm_fromspan = BRI_card_pcm_fromspan,
1639 .card_pcm_tospan = BRI_card_pcm_tospan,
1640 .card_timing_priority = BRI_timing_priority,
1641 .echocancel_timeslot = BRI_echocancel_timeslot,
1642 .echocancel_setmask = BRI_echocancel_setmask,
1643 .card_ioctl = BRI_card_ioctl,
1644 .card_open = BRI_card_open,
1645 .card_close = BRI_card_close,
1646 .card_state = BRI_card_state,
1647 };
1648
1649 static xproto_table_t PROTO_TABLE(BRI) = {
1650 .owner = THIS_MODULE,
1651 .entries = {
1652 /* Table Card Opcode */
1653 },
1654 .name = "BRI", /* protocol name */
1655 .ports_per_subunit = 1,
1656 .type = XPD_TYPE_BRI,
1657 .xops = &bri_xops,
1658 .phoneops = &bri_phoneops,
1659 .packet_is_valid = bri_packet_is_valid,
1660 .packet_dump = bri_packet_dump,
1661 };
1662
1663 static bool bri_packet_is_valid(xpacket_t *pack)
1664 {
1665 const xproto_entry_t *xe = NULL;
1666 // DBG(GENERAL, "\n");
1667 xe = xproto_card_entry(&PROTO_TABLE(BRI), XPACKET_OP(pack));
1668 return xe != NULL;
1669 }
1670
1671 static void bri_packet_dump(const char *msg, xpacket_t *pack)
1672 {
1673 DBG(GENERAL, "%s\n", msg);
1674 }
1675
1676 /*------------------------- REGISTER Handling --------------------------*/
1677
1678 #ifdef CONFIG_PROC_FS
1679 static int proc_bri_info_show(struct seq_file *sfile, void *not_used)
1680 {
1681 unsigned long flags;
1682 xpd_t *xpd = sfile->private;
1683 struct BRI_priv_data *priv;
1684
1685 DBG(PROC, "\n");
1686 if (!xpd)
1687 return -ENODEV;
1688 spin_lock_irqsave(&xpd->lock, flags);
1689 priv = xpd->priv;
1690 BUG_ON(!priv);
1691 seq_printf(sfile, "%05d Layer 1: ", priv->poll_counter);
1692 if (priv->reg30_good) {
1693 seq_printf(sfile, "%-5s ", (priv->layer1_up) ? "UP" : "DOWN");
1694 seq_printf(sfile,
1695 "%c%d %-15s -- fr_sync=%d t2_exp=%d info0=%d g2_g3=%d\n",
1696 IS_NT(xpd) ? 'G' : 'F',
1697 priv->state_register.bits.v_su_sta,
1698 xhfc_state_name(IS_NT(xpd),
1699 priv->state_register.bits.v_su_sta),
1700 priv->state_register.bits.v_su_fr_sync,
1701 priv->state_register.bits.v_su_t2_exp,
1702 priv->state_register.bits.v_su_info0,
1703 priv->state_register.bits.v_g2_g3);
1704 } else {
1705 seq_printf(sfile, "Unknown\n");
1706 }
1707 if (IS_NT(xpd))
1708 seq_printf(sfile, "T1 Timer: %d\n", priv->t1);
1709 else
1710 seq_printf(sfile, "T3 Timer: %d\n", priv->t3);
1711 seq_printf(sfile, "Tick Counter: %d\n", priv->tick_counter);
1712 seq_printf(sfile, "Last Poll Reply: %d ticks ago\n",
1713 priv->reg30_ticks);
1714 seq_printf(sfile, "reg30_good=%d\n", priv->reg30_good);
1715 seq_printf(sfile, "D-Channel: TX=[%5d] RX=[%5d] BAD=[%5d] ",
1716 priv->dchan_tx_counter, priv->dchan_rx_counter,
1717 priv->dchan_rx_drops);
1718 if (priv->dchan_alive) {
1719 seq_printf(sfile, "(alive %d K-ticks)\n",
1720 priv->dchan_alive_ticks / 1000);
1721 } else {
1722 seq_printf(sfile, "(dead)\n");
1723 }
1724 seq_printf(sfile, "dchan_notx_ticks: %d\n",
1725 priv->dchan_notx_ticks);
1726 seq_printf(sfile, "dchan_norx_ticks: %d\n",
1727 priv->dchan_norx_ticks);
1728 seq_printf(sfile, "LED: %-10s = %d\n", "GREEN",
1729 priv->ledstate[GREEN_LED]);
1730 seq_printf(sfile, "LED: %-10s = %d\n", "RED",
1731 priv->ledstate[RED_LED]);
1732 seq_printf(sfile, "\nDCHAN:\n");
1733 seq_printf(sfile, "\n");
1734 spin_unlock_irqrestore(&xpd->lock, flags);
1735 return 0;
1736 }
1737
1738 static int proc_bri_info_open(struct inode *inode, struct file *file)
1739 {
1740 return single_open(file, proc_bri_info_show, PDE_DATA(inode));
1741 }
1742
1743 static const struct file_operations proc_bri_info_ops = {
1744 .owner = THIS_MODULE,
1745 .open = proc_bri_info_open,
1746 .read = seq_read,
1747 .llseek = seq_lseek,
1748 .release = single_release,
1749 };
1750 #endif
1751
1752 static int bri_xpd_probe(struct device *dev)
1753 {
1754 xpd_t *xpd;
1755
1756 xpd = dev_to_xpd(dev);
1757 /* Is it our device? */
1758 if (xpd->xpd_type != XPD_TYPE_BRI) {
1759 XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev),
1760 xpd->xpd_type);
1761 return -EINVAL;
1762 }
1763 XPD_DBG(DEVICES, xpd, "SYSFS\n");
1764 return 0;
1765 }
1766
1767 static int bri_xpd_remove(struct device *dev)
1768 {
1769 xpd_t *xpd;
1770
1771 xpd = dev_to_xpd(dev);
1772 XPD_DBG(DEVICES, xpd, "SYSFS\n");
1773 return 0;
1774 }
1775
1776 static struct xpd_driver bri_driver = {
1777 .xpd_type = XPD_TYPE_BRI,
1778 .driver = {
1779 .name = "bri",
1780 .owner = THIS_MODULE,
1781 .probe = bri_xpd_probe,
1782 .remove = bri_xpd_remove}
1783 };
1784
1785 static int __init card_bri_startup(void)
1786 {
1787 int ret;
1788
1789 if ((ret = xpd_driver_register(&bri_driver.driver)) < 0)
1790 return ret;
1791 xproto_register(&PROTO_TABLE(BRI));
1792 return 0;
1793 }
1794
1795 static void __exit card_bri_cleanup(void)
1796 {
1797 DBG(GENERAL, "\n");
1798 xproto_unregister(&PROTO_TABLE(BRI));
1799 xpd_driver_unregister(&bri_driver.driver);
1800 }
1801
1802 MODULE_DESCRIPTION("XPP BRI Card Driver");
1803 MODULE_AUTHOR("Oron Peled <[email protected]>");
1804 MODULE_LICENSE("GPL");
1805 MODULE_ALIAS_XPD(XPD_TYPE_BRI);
1806
1807 module_init(card_bri_startup);
1808 module_exit(card_bri_cleanup);