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