diff --git a/drivers/dahdi/xpp/card_bri.c b/drivers/dahdi/xpp/card_bri.c index f4addc3..30598f2 100644 --- a/drivers/dahdi/xpp/card_bri.c +++ b/drivers/dahdi/xpp/card_bri.c @@ -40,30 +40,32 @@ static const char rcsid[] = "$Id$"; #endif static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ -static DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)"); -static DEF_PARM_BOOL(nt_keepalive, 1, 0644, "Force BRI_NT to keep trying connection"); +static DEF_PARM(uint, poll_interval, 500, 0644, + "Poll channel state interval in milliseconds (0 - disable)"); +static DEF_PARM_BOOL(nt_keepalive, 1, 0644, + "Force BRI_NT to keep trying connection"); enum xhfc_states { - ST_RESET = 0, /* G/F0 */ + ST_RESET = 0, /* G/F0 */ /* TE */ - ST_TE_SENSING = 2, /* F2 */ - ST_TE_DEACTIVATED = 3, /* F3 */ - ST_TE_SIGWAIT = 4, /* F4 */ - ST_TE_IDENT = 5, /* F5 */ - ST_TE_SYNCED = 6, /* F6 */ - ST_TE_ACTIVATED = 7, /* F7 */ - ST_TE_LOST_FRAMING = 8, /* F8 */ + ST_TE_SENSING = 2, /* F2 */ + ST_TE_DEACTIVATED = 3, /* F3 */ + ST_TE_SIGWAIT = 4, /* F4 */ + ST_TE_IDENT = 5, /* F5 */ + ST_TE_SYNCED = 6, /* F6 */ + ST_TE_ACTIVATED = 7, /* F7 */ + ST_TE_LOST_FRAMING = 8, /* F8 */ /* NT */ - ST_NT_DEACTIVATED = 1, /* G1 */ - ST_NT_ACTIVATING = 2, /* G2 */ - ST_NT_ACTIVATED = 3, /* G3 */ - ST_NT_DEACTIVTING = 4, /* G4 */ + ST_NT_DEACTIVATED = 1, /* G1 */ + ST_NT_ACTIVATING = 2, /* G2 */ + ST_NT_ACTIVATED = 3, /* G3 */ + ST_NT_DEACTIVTING = 4, /* G4 */ }; #ifdef CONFIG_PROC_FS static const char *xhfc_state_name(bool is_nt, enum xhfc_states state) { - const char *p; + const char *p; #define _E(x) [ST_ ## x] = #x static const char *te_names[] = { @@ -111,9 +113,9 @@ static const char *xhfc_state_name(bool is_nt, enum xhfc_states state) #define HFC_TIMER_T3 8000 /* 8s activation timer T3 */ #define HFC_TIMER_OFF -1 /* timer disabled */ -#define A_SU_WR_STA 0x30 /* ST/Up state machine register */ +#define A_SU_WR_STA 0x30 /* ST/Up state machine register */ #define V_SU_LD_STA 0x10 -#define V_SU_ACT 0x60 /* start activation/deactivation */ +#define V_SU_ACT 0x60 /* start activation/deactivation */ #define STA_DEACTIVATE 0x40 /* start deactivation in A_SU_WR_STA */ #define STA_ACTIVATE 0x60 /* start activation in A_SU_WR_STA */ #define V_SU_SET_G2_G3 0x80 @@ -121,13 +123,13 @@ static const char *xhfc_state_name(bool is_nt, enum xhfc_states state) #define A_SU_RD_STA 0x30 typedef union { struct { - __u8 v_su_sta:4; - __u8 v_su_fr_sync:1; - __u8 v_su_t2_exp:1; - __u8 v_su_info0:1; - __u8 v_g2_g3:1; + __u8 v_su_sta:4; + __u8 v_su_fr_sync:1; + __u8 v_su_t2_exp:1; + __u8 v_su_info0:1; + __u8 v_g2_g3:1; } bits; - __u8 reg; + __u8 reg; } su_rd_sta_t; #define REG30_LOST 3 /* in polls */ @@ -149,7 +151,8 @@ static int write_state_register(xpd_t *xpd, __u8 value); static bool bri_packet_is_valid(xpacket_t *pack); static void bri_packet_dump(const char *msg, xpacket_t *pack); #ifdef CONFIG_PROC_FS -static int proc_bri_info_read(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_bri_info_read(char *page, char **start, off_t off, int count, + int *eof, void *data); #endif static int bri_spanconfig(struct file *file, struct dahdi_span *span, struct dahdi_lineconfig *lc); @@ -162,29 +165,28 @@ static int bri_shutdown(struct dahdi_span *span); #define PROC_BRI_INFO_FNAME "bri_info" enum led_state { - BRI_LED_OFF = 0x0, - BRI_LED_ON = 0x1, + BRI_LED_OFF = 0x0, + BRI_LED_ON = 0x1, /* * We blink by software from driver, so that * if the driver malfunction that blink would stop. */ - // BRI_LED_BLINK_SLOW = 0x2, /* 1/2 a second blink cycle */ - // BRI_LED_BLINK_FAST = 0x3 /* 1/4 a second blink cycle */ + // BRI_LED_BLINK_SLOW = 0x2, /* 1/2 a second blink cycle */ + // BRI_LED_BLINK_FAST = 0x3 /* 1/4 a second blink cycle */ }; enum bri_led_names { - GREEN_LED = 0, - RED_LED = 1 + GREEN_LED = 0, + RED_LED = 1 }; #define NUM_LEDS 2 #define LED_TICKS 100 - struct bri_leds { - __u8 state:2; - __u8 led_sel:1; /* 0 - GREEN, 1 - RED */ - __u8 reserved:5; + __u8 state:2; + __u8 led_sel:1; /* 0 - GREEN, 1 - RED */ + __u8 reserved:5; }; #ifndef MAX_DFRAME_LEN_L1 @@ -194,42 +196,41 @@ struct bri_leds { #define DCHAN_BUFSIZE MAX_DFRAME_LEN_L1 struct BRI_priv_data { - struct proc_dir_entry *bri_info; - su_rd_sta_t state_register; - bool initialized; - int t1; /* timer 1 for NT deactivation */ - int t3; /* timer 3 for TE activation */ - ulong l1_flags; - bool reg30_good; - uint reg30_ticks; - bool layer1_up; + struct proc_dir_entry *bri_info; + su_rd_sta_t state_register; + bool initialized; + int t1; /* timer 1 for NT deactivation */ + int t3; /* timer 3 for TE activation */ + ulong l1_flags; + bool reg30_good; + uint reg30_ticks; + bool layer1_up; /* * D-Chan: buffers + extra state info. */ - atomic_t hdlc_pending; - bool txframe_begin; + atomic_t hdlc_pending; + bool txframe_begin; - uint tick_counter; - uint poll_counter; - uint dchan_tx_counter; - uint dchan_rx_counter; - uint dchan_rx_drops; - bool dchan_alive; - uint dchan_alive_ticks; - uint dchan_notx_ticks; - uint dchan_norx_ticks; - enum led_state ledstate[NUM_LEDS]; + uint tick_counter; + uint poll_counter; + uint dchan_tx_counter; + uint dchan_rx_counter; + uint dchan_rx_drops; + bool dchan_alive; + uint dchan_alive_ticks; + uint dchan_notx_ticks; + uint dchan_norx_ticks; + enum led_state ledstate[NUM_LEDS]; }; -static xproto_table_t PROTO_TABLE(BRI); - +static xproto_table_t PROTO_TABLE(BRI); DEF_RPACKET_DATA(BRI, SET_LED, /* Set one of the LED's */ - struct bri_leds bri_leds; - ); + struct bri_leds bri_leds;); -static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state); +static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, + enum led_state to_led_state); #define DO_LED(xpd, which, tostate) \ CALL_PROTO(BRI, SET_LED, (xpd)->xbus, (xpd), (which), (tostate)) @@ -237,24 +238,25 @@ static /* 0x33 */ DECLARE_CMD(BRI, SET_LED, enum bri_led_names which_led, enum l #define DEBUG_BUF_SIZE (100) static void dump_hex_buf(xpd_t *xpd, char *msg, __u8 *buf, size_t len) { - char debug_buf[DEBUG_BUF_SIZE + 1]; - int i; - int n = 0; + char debug_buf[DEBUG_BUF_SIZE + 1]; + int i; + int n = 0; debug_buf[0] = '\0'; for (i = 0; i < len && n < DEBUG_BUF_SIZE; i++) - n += snprintf(&debug_buf[n], DEBUG_BUF_SIZE - n, "%02X ", buf[i]); - XPD_NOTICE(xpd, "%s[0..%zd]: %s%s\n", msg, len-1, debug_buf, - (n >= DEBUG_BUF_SIZE)?"...":""); + n += snprintf(&debug_buf[n], DEBUG_BUF_SIZE - n, "%02X ", + buf[i]); + XPD_NOTICE(xpd, "%s[0..%zd]: %s%s\n", msg, len - 1, debug_buf, + (n >= DEBUG_BUF_SIZE) ? "..." : ""); } static void dump_dchan_packet(xpd_t *xpd, bool transmit, __u8 *buf, int len) { - struct BRI_priv_data *priv; - char msgbuf[MAX_PROC_WRITE]; - char ftype = '?'; - char *direction; - int frame_begin; + struct BRI_priv_data *priv; + char msgbuf[MAX_PROC_WRITE]; + char ftype = '?'; + char *direction; + int frame_begin; priv = xpd->priv; BUG_ON(!priv); @@ -275,14 +277,16 @@ static void dump_dchan_packet(xpd_t *xpd, bool transmit, __u8 *buf, int len) else XPD_NOTICE(xpd, "Unknown frame type 0x%X\n", buf[0]); - snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = (%c) ", direction, ftype); + snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = (%c) ", direction, + ftype); } else { snprintf(msgbuf, MAX_PROC_WRITE, "D-Chan %s = ", direction); } dump_hex_buf(xpd, msgbuf, buf, len); } -static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer, int value) +static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer, + int value) { if (value == HFC_TIMER_OFF) XPD_DBG(SIGNAL, xpd, "Timer %s DISABLE\n", name); @@ -293,7 +297,7 @@ static void set_bri_timer(xpd_t *xpd, const char *name, int *bri_timer, int valu static void dchan_state(xpd_t *xpd, bool up) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -305,7 +309,8 @@ static void dchan_state(xpd_t *xpd, bool up) priv->dchan_alive = 1; } else { XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel STOPPED\n"); - priv->dchan_rx_counter = priv->dchan_tx_counter = priv->dchan_rx_drops = 0; + priv->dchan_rx_counter = priv->dchan_tx_counter = + priv->dchan_rx_drops = 0; priv->dchan_alive = 0; priv->dchan_alive_ticks = 0; } @@ -313,7 +318,7 @@ static void dchan_state(xpd_t *xpd, bool up) static void layer1_state(xpd_t *xpd, bool up) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -321,21 +326,21 @@ static void layer1_state(xpd_t *xpd, bool up) if (priv->layer1_up == up) return; priv->layer1_up = up; - XPD_DBG(SIGNAL, xpd, "STATE CHANGE: Layer1 %s\n", (up)?"UP":"DOWN"); + XPD_DBG(SIGNAL, xpd, "STATE CHANGE: Layer1 %s\n", (up) ? "UP" : "DOWN"); if (!up) dchan_state(xpd, 0); } static void te_activation(xpd_t *xpd, bool on) { - struct BRI_priv_data *priv; - __u8 curr_state; + struct BRI_priv_data *priv; + __u8 curr_state; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); curr_state = priv->state_register.bits.v_su_sta; - XPD_DBG(SIGNAL, xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(SIGNAL, xpd, "%s\n", (on) ? "ON" : "OFF"); if (on) { if (curr_state == ST_TE_DEACTIVATED) { XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_TE\n"); @@ -347,84 +352,84 @@ static void te_activation(xpd_t *xpd, bool on) "HFC_L1_ACTIVATE_TE (state %d, ignored)\n", curr_state); } - } else { /* happen only because of T3 expiry */ + } else { /* happen only because of T3 expiry */ switch (curr_state) { - case ST_TE_DEACTIVATED: /* F3 */ - case ST_TE_SYNCED: /* F6 */ - case ST_TE_ACTIVATED: /* F7 */ - XPD_DBG(SIGNAL, xpd, - "HFC_L1_FORCE_DEACTIVATE_TE (state %d, ignored)\n", - curr_state); - break; - case ST_TE_SIGWAIT: /* F4 */ - case ST_TE_IDENT: /* F5 */ - case ST_TE_LOST_FRAMING: /* F8 */ - XPD_DBG(SIGNAL, xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n"); - write_state_register(xpd, STA_DEACTIVATE); - break; - default: - XPD_NOTICE(xpd, "Bad TE state: %d\n", curr_state); - break; + case ST_TE_DEACTIVATED: /* F3 */ + case ST_TE_SYNCED: /* F6 */ + case ST_TE_ACTIVATED: /* F7 */ + XPD_DBG(SIGNAL, xpd, + "HFC_L1_FORCE_DEACTIVATE_TE (state %d, ignored)\n", + curr_state); + break; + case ST_TE_SIGWAIT: /* F4 */ + case ST_TE_IDENT: /* F5 */ + case ST_TE_LOST_FRAMING: /* F8 */ + XPD_DBG(SIGNAL, xpd, "HFC_L1_FORCE_DEACTIVATE_TE\n"); + write_state_register(xpd, STA_DEACTIVATE); + break; + default: + XPD_NOTICE(xpd, "Bad TE state: %d\n", curr_state); + break; } } } static void nt_activation(xpd_t *xpd, bool on) { - struct BRI_priv_data *priv; - __u8 curr_state; + struct BRI_priv_data *priv; + __u8 curr_state; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); curr_state = priv->state_register.bits.v_su_sta; - XPD_DBG(SIGNAL, xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(SIGNAL, xpd, "%s\n", (on) ? "ON" : "OFF"); if (on) { switch (curr_state) { - case ST_RESET: /* F/G 0 */ - case ST_NT_DEACTIVATED: /* G1 */ - case ST_NT_DEACTIVTING: /* G4 */ - XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_NT\n"); - set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_T1); - set_bit(HFC_L1_ACTIVATING, &priv->l1_flags); - write_state_register(xpd, STA_ACTIVATE); - break; - case ST_NT_ACTIVATING: /* G2 */ - case ST_NT_ACTIVATED: /* G3 */ - XPD_DBG(SIGNAL, xpd, - "HFC_L1_ACTIVATE_NT (in state %d, ignored)\n", - curr_state); - break; + case ST_RESET: /* F/G 0 */ + case ST_NT_DEACTIVATED: /* G1 */ + case ST_NT_DEACTIVTING: /* G4 */ + XPD_DBG(SIGNAL, xpd, "HFC_L1_ACTIVATE_NT\n"); + set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_T1); + set_bit(HFC_L1_ACTIVATING, &priv->l1_flags); + write_state_register(xpd, STA_ACTIVATE); + break; + case ST_NT_ACTIVATING: /* G2 */ + case ST_NT_ACTIVATED: /* G3 */ + XPD_DBG(SIGNAL, xpd, + "HFC_L1_ACTIVATE_NT (in state %d, ignored)\n", + curr_state); + break; } } else { switch (curr_state) { - case ST_RESET: /* F/G 0 */ - case ST_NT_DEACTIVATED: /* G1 */ - case ST_NT_DEACTIVTING: /* G4 */ - XPD_DBG(SIGNAL, xpd, - "HFC_L1_DEACTIVATE_NT (in state %d, ignored)\n", - curr_state); - break; - case ST_NT_ACTIVATING: /* G2 */ - case ST_NT_ACTIVATED: /* G3 */ - XPD_DBG(SIGNAL, xpd, "HFC_L1_DEACTIVATE_NT\n"); - write_state_register(xpd, STA_DEACTIVATE); - break; - default: - XPD_NOTICE(xpd, "Bad NT state: %d\n", curr_state); - break; + case ST_RESET: /* F/G 0 */ + case ST_NT_DEACTIVATED: /* G1 */ + case ST_NT_DEACTIVTING: /* G4 */ + XPD_DBG(SIGNAL, xpd, + "HFC_L1_DEACTIVATE_NT (in state %d, ignored)\n", + curr_state); + break; + case ST_NT_ACTIVATING: /* G2 */ + case ST_NT_ACTIVATED: /* G3 */ + XPD_DBG(SIGNAL, xpd, "HFC_L1_DEACTIVATE_NT\n"); + write_state_register(xpd, STA_DEACTIVATE); + break; + default: + XPD_NOTICE(xpd, "Bad NT state: %d\n", curr_state); + break; } } } - /* * D-Chan receive */ -static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, int len) +static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, + int len) { - struct BRI_priv_data *priv; - __u8 status; + struct BRI_priv_data *priv; + __u8 status; priv = xpd->priv; BUG_ON(!priv); @@ -433,9 +438,9 @@ static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, int l dahdi_hdlc_abort(dchan, DAHDI_EVENT_ABORT); return -EPROTO; } - status = buf[len-1]; + status = buf[len - 1]; if (status) { - int event = DAHDI_EVENT_ABORT; + int event = DAHDI_EVENT_ABORT; if (status == 0xFF) { XPD_NOTICE(xpd, "D-Chan RX DROP: ABORT: %d\n", status); @@ -452,19 +457,19 @@ static int bri_check_stat(xpd_t *xpd, struct dahdi_chan *dchan, __u8 *buf, int l static int rx_dchan(xpd_t *xpd, reg_cmd_t *regcmd) { - struct BRI_priv_data *priv; - __u8 *src; - struct dahdi_chan *dchan; - uint len; - bool eoframe; - int ret = 0; + struct BRI_priv_data *priv; + __u8 *src; + struct dahdi_chan *dchan; + uint len; + bool eoframe; + int ret = 0; src = REG_XDATA(regcmd); len = regcmd->bytes; eoframe = regcmd->eoframe; if (len <= 0) return 0; - if (!SPAN_REGISTERED(xpd)) /* Nowhere to copy data */ + if (!SPAN_REGISTERED(xpd)) /* Nowhere to copy data */ return 0; BUG_ON(!xpd); priv = xpd->priv; @@ -501,9 +506,9 @@ out: /* DAHDI calls this when it has data it wants to send to the HDLC controller */ static void bri_hdlc_hard_xmit(struct dahdi_chan *chan) { - xpd_t *xpd = chan->pvt; - struct dahdi_chan *dchan; - struct BRI_priv_data *priv; + xpd_t *xpd = chan->pvt; + struct dahdi_chan *dchan; + struct BRI_priv_data *priv; priv = xpd->priv; BUG_ON(!priv); @@ -521,8 +526,9 @@ static int send_dchan_frame(xpd_t *xpd, xframe_t *xframe, bool is_eof) XPD_DBG(COMMANDS, xpd, "eoframe=%d\n", is_eof); priv = xpd->priv; if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) - && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) { - XPD_DBG(SIGNAL, xpd, "Want to transmit: Kick D-Channel transmiter\n"); + && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) { + XPD_DBG(SIGNAL, xpd, + "Want to transmit: Kick D-Channel transmiter\n"); if (!IS_NT(xpd)) te_activation(xpd, 1); else @@ -545,8 +551,8 @@ static int send_dchan_frame(xpd_t *xpd, xframe_t *xframe, bool is_eof) /* * Fill a single multibyte REGISTER_REQUEST */ -static void fill_multibyte(xpd_t *xpd, xpacket_t *pack, bool eoframe, - char *buf, int len) +static void fill_multibyte(xpd_t *xpd, xpacket_t *pack, bool eoframe, char *buf, + int len) { reg_cmd_t *reg_cmd; char *p; @@ -587,14 +593,14 @@ static int tx_dchan(xpd_t *xpd) BUG_ON(!priv); if (atomic_read(&priv->hdlc_pending) == 0) return 0; - if (!SPAN_REGISTERED(xpd) || - !(PHONEDEV(xpd).span.flags & DAHDI_FLAG_RUNNING)) + if (!SPAN_REGISTERED(xpd) + || !(PHONEDEV(xpd).span.flags & DAHDI_FLAG_RUNNING)) return 0; /* Allocate frame */ xframe = ALLOC_SEND_XFRAME(xpd->xbus); if (!xframe) { XPD_NOTICE(xpd, "%s: failed to allocate new xframe\n", - __func__); + __func__); return -ENOMEM; } for (packet_count = 0, eoframe = 0; !eoframe; packet_count++) { @@ -609,9 +615,8 @@ static int tx_dchan(xpd_t *xpd) /* * A split. Send what we currently have. */ - XPD_NOTICE(xpd, - "%s: xframe is full (%d packets)\n", - __func__, packet_count); + XPD_NOTICE(xpd, "%s: xframe is full (%d packets)\n", + __func__, packet_count); break; } /* Get data from DAHDI */ @@ -639,7 +644,7 @@ static int tx_dchan(xpd_t *xpd) static void bri_proc_remove(xbus_t *xbus, xpd_t *xpd) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -654,16 +659,19 @@ static void bri_proc_remove(xbus_t *xbus, xpd_t *xpd) static int bri_proc_create(xbus_t *xbus, xpd_t *xpd) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; XPD_DBG(PROC, xpd, "\n"); #ifdef CONFIG_PROC_FS XPD_DBG(PROC, xpd, "Creating '%s'\n", PROC_BRI_INFO_FNAME); - priv->bri_info = create_proc_read_entry(PROC_BRI_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_bri_info_read, xpd); + priv->bri_info = + create_proc_read_entry(PROC_BRI_INFO_FNAME, 0444, xpd->proc_xpd_dir, + proc_bri_info_read, xpd); if (!priv->bri_info) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_BRI_INFO_FNAME); + XPD_ERR(xpd, "Failed to create proc file '%s'\n", + PROC_BRI_INFO_FNAME); bri_proc_remove(xbus, xpd); return -EINVAL; } @@ -672,18 +680,21 @@ static int bri_proc_create(xbus_t *xbus, xpd_t *xpd) return 0; } -static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, - __u8 subtype, int subunits, int subunit_ports, bool to_phone) +static xpd_t *BRI_card_new(xbus_t *xbus, int unit, int subunit, + const xproto_table_t *proto_table, __u8 subtype, + int subunits, int subunit_ports, bool to_phone) { - xpd_t *xpd = NULL; - int channels = min(3, CHANNELS_PERXPD); + xpd_t *xpd = NULL; + int channels = min(3, CHANNELS_PERXPD); if (subunit_ports != 1) { XBUS_ERR(xbus, "Bad subunit_ports=%d\n", subunit_ports); return NULL; } XBUS_DBG(GENERAL, xbus, "\n"); - xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct BRI_priv_data), proto_table, channels); + xpd = + xpd_alloc(xbus, unit, subunit, subtype, subunits, + sizeof(struct BRI_priv_data), proto_table, channels); if (!xpd) return NULL; PHONEDEV(xpd).direction = (to_phone) ? TO_PHONE : TO_PSTN; @@ -698,7 +709,7 @@ err: static int BRI_card_init(xbus_t *xbus, xpd_t *xpd) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); XPD_DBG(GENERAL, xpd, "\n"); @@ -744,15 +755,15 @@ static const struct dahdi_span_ops BRI_span_ops = { static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; - struct BRI_priv_data *priv; - int i; + xbus_t *xbus; + struct BRI_priv_data *priv; + int i; BUG_ON(!xpd); xbus = xpd->xbus; priv = xpd->priv; BUG_ON(!xbus); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); if (!on) { /* Nothing to do yet */ return 0; @@ -762,12 +773,12 @@ static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on) PHONEDEV(xpd).span.deflaw = DAHDI_LAW_ALAW; BIT_SET(PHONEDEV(xpd).digital_signalling, 2); /* D-Channel */ for_each_line(xpd, i) { - struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); + struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); XPD_DBG(GENERAL, xpd, "setting BRI channel %d\n", i); snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%02d/%1d%1d/%d", - xpd->type_name, xbus->num, - xpd->addr.unit, xpd->addr.subunit, i); + xpd->type_name, xbus->num, xpd->addr.unit, + xpd->addr.subunit, i); cur_chan->chanpos = i + 1; cur_chan->pvt = xpd; if (i == 2) { /* D-CHAN */ @@ -786,13 +797,13 @@ static int BRI_card_dahdi_preregistration(xpd_t *xpd, bool on) static int BRI_card_dahdi_postregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; + xbus_t *xbus; BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); - return(0); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); + return (0); } static int BRI_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) @@ -809,11 +820,11 @@ static int BRI_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) */ static void handle_leds(xbus_t *xbus, xpd_t *xpd) { - struct BRI_priv_data *priv; - unsigned int timer_count; - int which_led; - int other_led; - int mod; + struct BRI_priv_data *priv; + unsigned int timer_count; + int which_led; + int other_led; + int mod; BUG_ON(!xpd); if (IS_NT(xpd)) { @@ -844,24 +855,24 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd) if (priv->dchan_alive) { mod = timer_count % 1000; switch (mod) { - case 0: - DO_LED(xpd, which_led, BRI_LED_ON); - break; - case 500: - DO_LED(xpd, which_led, BRI_LED_OFF); - break; + case 0: + DO_LED(xpd, which_led, BRI_LED_ON); + break; + case 500: + DO_LED(xpd, which_led, BRI_LED_OFF); + break; } } else if (priv->layer1_up) { mod = timer_count % 1000; switch (mod) { - case 0: - case 100: - DO_LED(xpd, which_led, BRI_LED_ON); - break; - case 50: - case 150: - DO_LED(xpd, which_led, BRI_LED_OFF); - break; + case 0: + case 100: + DO_LED(xpd, which_led, BRI_LED_ON); + break; + case 50: + case 150: + DO_LED(xpd, which_led, BRI_LED_OFF); + break; } } else { if (priv->ledstate[which_led] != BRI_LED_ON) @@ -871,7 +882,7 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd) static void handle_bri_timers(xpd_t *xpd) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -879,16 +890,20 @@ static void handle_bri_timers(xpd_t *xpd) if (IS_NT(xpd)) { if (priv->t1 > HFC_TIMER_OFF) { if (--priv->t1 == 0) { - set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); + set_bri_timer(xpd, "T1", &priv->t1, + HFC_TIMER_OFF); if (!nt_keepalive) { if (priv->state_register.bits.v_su_sta == ST_NT_ACTIVATING) { /* G2 */ - XPD_DBG(SIGNAL, xpd, "T1 Expired. Deactivate NT\n"); - clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); + XPD_DBG(SIGNAL, xpd, + "T1 Expired. Deactivate NT\n"); + clear_bit(HFC_L1_ACTIVATING, + &priv->l1_flags); nt_activation(xpd, 0); /* Deactivate NT */ } else XPD_DBG(SIGNAL, xpd, "T1 Expired. (state %d, ignored)\n", - priv->state_register.bits.v_su_sta); + priv->state_register. + bits.v_su_sta); } } } @@ -896,10 +911,12 @@ static void handle_bri_timers(xpd_t *xpd) if (priv->t3 > HFC_TIMER_OFF) { /* timer expired ? */ if (--priv->t3 == 0) { - XPD_DBG(SIGNAL, xpd, "T3 expired. Deactivate TE\n"); - set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF); + XPD_DBG(SIGNAL, xpd, + "T3 expired. Deactivate TE\n"); + set_bri_timer(xpd, "T3", &priv->t3, + HFC_TIMER_OFF); clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); - te_activation(xpd, 0); /* Deactivate TE */ + te_activation(xpd, 0); /* Deactivate TE */ } } } @@ -910,7 +927,7 @@ static void handle_bri_timers(xpd_t *xpd) */ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -920,21 +937,20 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) if (poll_interval != 0 && (priv->tick_counter % poll_interval) == 0) { // XPD_DBG(GENERAL, xpd, "%d\n", priv->tick_counter); priv->poll_counter++; - xpp_register_request(xbus, xpd, - BRI_PORT(xpd), /* portno */ - 0, /* writing */ - A_SU_RD_STA, /* regnum */ - 0, /* do_subreg */ - 0, /* subreg */ - 0, /* data_low */ - 0, /* do_datah */ - 0, /* data_high */ - 0 /* should_reply */ - ); + xpp_register_request(xbus, xpd, BRI_PORT(xpd), /* portno */ + 0, /* writing */ + A_SU_RD_STA, /* regnum */ + 0, /* do_subreg */ + 0, /* subreg */ + 0, /* data_low */ + 0, /* do_datah */ + 0, /* data_high */ + 0 /* should_reply */ + ); - if (IS_NT(xpd) && nt_keepalive && - !test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) && - !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) { + if (IS_NT(xpd) && nt_keepalive + && !test_bit(HFC_L1_ACTIVATED, &priv->l1_flags) + && !test_bit(HFC_L1_ACTIVATING, &priv->l1_flags)) { XPD_DBG(SIGNAL, xpd, "Kick NT D-Channel\n"); nt_activation(xpd, 1); } @@ -943,20 +959,23 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) priv->dchan_notx_ticks++; priv->dchan_norx_ticks++; priv->dchan_alive_ticks++; - if (priv->dchan_alive && (priv->dchan_notx_ticks > DCHAN_LOST || priv->dchan_norx_ticks > DCHAN_LOST)) { + if (priv->dchan_alive + && (priv->dchan_notx_ticks > DCHAN_LOST + || priv->dchan_norx_ticks > DCHAN_LOST)) { /* * No tx_dchan() or rx_dchan() for many ticks * This D-Channel is probabelly dead. */ dchan_state(xpd, 0); - } else if (priv->dchan_rx_counter > 1 && priv->dchan_tx_counter > 1) { + } else if (priv->dchan_rx_counter > 1 && priv->dchan_tx_counter > 1) { if (!priv->dchan_alive) dchan_state(xpd, 1); } /* Detect Layer1 disconnect */ if (priv->reg30_good && priv->reg30_ticks > poll_interval * REG30_LOST) { /* No reply for 1/2 a second */ - XPD_ERR(xpd, "Lost state tracking for %d ticks\n", priv->reg30_ticks); + XPD_ERR(xpd, "Lost state tracking for %d ticks\n", + priv->reg30_ticks); priv->reg30_good = 0; layer1_state(xpd, 0); } @@ -968,22 +987,23 @@ static int BRI_card_tick(xbus_t *xbus, xpd_t *xpd) return 0; } -static int BRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg) +static int BRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, + unsigned long arg) { BUG_ON(!xpd); if (!XBUS_IS(xpd->xbus, READY)) return -ENODEV; switch (cmd) { - case DAHDI_TONEDETECT: - /* - * Asterisk call all span types with this (FXS specific) - * call. Silently ignore it. - */ - LINE_DBG(SIGNAL, xpd, pos, "BRI: Starting a call\n"); - return -ENOTTY; - default: - report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); - return -ENOTTY; + case DAHDI_TONEDETECT: + /* + * Asterisk call all span types with this (FXS specific) + * call. Silently ignore it. + */ + LINE_DBG(SIGNAL, xpd, pos, "BRI: Starting a call\n"); + return -ENOTTY; + default: + report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); + return -ENOTTY; } return 0; } @@ -1020,11 +1040,11 @@ static int BRI_card_close(xpd_t *xpd, lineno_t pos) static int bri_spanconfig(struct file *file, struct dahdi_span *span, struct dahdi_lineconfig *lc) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - const char *framingstr = ""; - const char *codingstr = ""; - const char *crcstr = ""; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + const char *framingstr = ""; + const char *codingstr = ""; + const char *crcstr = ""; /* framing first */ if (lc->lineconfig & DAHDI_CONFIG_B8ZS) @@ -1043,14 +1063,10 @@ static int bri_spanconfig(struct file *file, struct dahdi_span *span, /* E1's can enable CRC checking */ if (lc->lineconfig & DAHDI_CONFIG_CRC4) crcstr = "CRC4"; - XPD_DBG(GENERAL, xpd, "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n", - IS_NT(xpd)?"NT":"TE", - lc->span, - lc->name, - lc->lbo, - framingstr, codingstr, crcstr, - lc->lineconfig, - lc->sync); + XPD_DBG(GENERAL, xpd, + "[%s]: span=%d (%s) lbo=%d lineconfig=%s/%s/%s (0x%X) sync=%d\n", + IS_NT(xpd) ? "NT" : "TE", lc->span, lc->name, lc->lbo, + framingstr, codingstr, crcstr, lc->lineconfig, lc->sync); PHONEDEV(xpd).timing_priority = lc->sync; elect_syncer("BRI-spanconfig"); /* @@ -1068,7 +1084,8 @@ static int bri_spanconfig(struct file *file, struct dahdi_span *span, static int bri_chanconfig(struct file *file, struct dahdi_chan *chan, int sigtype) { - DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name, sig2str(sigtype)); + DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name, + sig2str(sigtype)); // FIXME: sanity checks: // - should be supported (within the sigcap) // - should not replace fxs <->fxo ??? (covered by previous?) @@ -1080,16 +1097,17 @@ static int bri_chanconfig(struct file *file, struct dahdi_chan *chan, */ static int bri_startup(struct file *file, struct dahdi_span *span) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - struct BRI_priv_data *priv; - struct dahdi_chan *dchan; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct BRI_priv_data *priv; + struct dahdi_chan *dchan; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); if (!XBUS_IS(xpd->xbus, READY)) { - XPD_DBG(GENERAL, xpd, "Startup called by dahdi. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, + "Startup called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "STARTUP\n"); @@ -1114,15 +1132,16 @@ static int bri_startup(struct file *file, struct dahdi_span *span) */ static int bri_shutdown(struct dahdi_span *span) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - struct BRI_priv_data *priv; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); if (!XBUS_IS(xpd->xbus, READY)) { - XPD_DBG(GENERAL, xpd, "Shutdown called by dahdi. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, + "Shutdown called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); @@ -1131,20 +1150,20 @@ static int bri_shutdown(struct dahdi_span *span) return 0; } -static void BRI_card_pcm_recompute(xpd_t *xpd, - xpp_line_t dont_care) +static void BRI_card_pcm_recompute(xpd_t *xpd, xpp_line_t dont_care) { - int i; - int line_count; - xpp_line_t pcm_mask; - uint pcm_len; - xpd_t *main_xpd; - unsigned long flags; + int i; + int line_count; + xpp_line_t pcm_mask; + uint pcm_len; + xpd_t *main_xpd; + unsigned long flags; BUG_ON(!xpd); main_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, 0); if (!main_xpd) { - XPD_DBG(DEVICES, xpd, "Unit 0 is already gone. Ignore request\n"); + XPD_DBG(DEVICES, xpd, + "Unit 0 is already gone. Ignore request\n"); return; } /* @@ -1155,11 +1174,13 @@ static void BRI_card_pcm_recompute(xpd_t *xpd, line_count = 0; pcm_mask = 0; for (i = 0; i < MAX_SUBUNIT; i++) { - xpd_t *sub_xpd = xpd_byaddr(xpd->xbus, main_xpd->addr.unit, i); + xpd_t *sub_xpd = xpd_byaddr(xpd->xbus, main_xpd->addr.unit, i); if (sub_xpd) { - xpp_line_t lines = - PHONEDEV(sub_xpd).offhook_state & ~(PHONEDEV(sub_xpd).digital_signalling); + xpp_line_t lines = + PHONEDEV(sub_xpd). + offhook_state & ~(PHONEDEV(sub_xpd). + digital_signalling); if (lines) { pcm_mask |= PCM_SHIFT(lines, i); @@ -1183,27 +1204,26 @@ static void BRI_card_pcm_recompute(xpd_t *xpd, * The main unit account for all subunits (pcm_len and wanted_pcm_mask). */ pcm_len = (line_count) - ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + line_count * DAHDI_CHUNKSIZE - : 0L; + ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + + line_count * DAHDI_CHUNKSIZE : 0L; update_wanted_pcm_mask(main_xpd, pcm_mask, pcm_len); spin_unlock_irqrestore(&PHONEDEV(main_xpd).lock_recompute_pcm, flags); } static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) { - __u8 *pcm; - unsigned long flags; - int i; - int subunit; - xpp_line_t pcm_mask = 0; - xpp_line_t wanted_lines; - + __u8 *pcm; + unsigned long flags; + int i; + int subunit; + xpp_line_t pcm_mask = 0; + xpp_line_t wanted_lines; BUG_ON(!xpd); BUG_ON(!pack); pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm); for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) { - xpd_t *tmp_xpd; + xpd_t *tmp_xpd; tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit); if (!tmp_xpd || !tmp_xpd->card_present) @@ -1211,20 +1231,24 @@ static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) spin_lock_irqsave(&tmp_xpd->lock, flags); wanted_lines = PHONEDEV(tmp_xpd).wanted_pcm_mask; for_each_line(tmp_xpd, i) { - struct dahdi_chan *chan = XPD_CHAN(tmp_xpd, i); + struct dahdi_chan *chan = XPD_CHAN(tmp_xpd, i); if (IS_SET(wanted_lines, i)) { if (SPAN_REGISTERED(tmp_xpd)) { #ifdef DEBUG_PCMTX - int channo = chan->channo; + int channo = chan->channo; if (pcmtx >= 0 && pcmtx_chan == channo) - memset((u_char *)pcm, pcmtx, DAHDI_CHUNKSIZE); + memset((u_char *)pcm, pcmtx, + DAHDI_CHUNKSIZE); else #endif - memcpy((u_char *)pcm, chan->writechunk, DAHDI_CHUNKSIZE); + memcpy((u_char *)pcm, + chan->writechunk, + DAHDI_CHUNKSIZE); } else - memset((u_char *)pcm, 0x7F, DAHDI_CHUNKSIZE); + memset((u_char *)pcm, 0x7F, + DAHDI_CHUNKSIZE); pcm += DAHDI_CHUNKSIZE; } } @@ -1237,11 +1261,11 @@ static void BRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) { - __u8 *pcm; - xpp_line_t pcm_mask; - unsigned long flags; - int subunit; - int i; + __u8 *pcm; + xpp_line_t pcm_mask; + unsigned long flags; + int subunit; + int i; /* * Subunit 0 handle all other subunits @@ -1252,22 +1276,24 @@ static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) return; pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm); pcm_mask = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, lines); - for (subunit = 0; subunit < MAX_SUBUNIT; subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) { - xpd_t *tmp_xpd; + for (subunit = 0; subunit < MAX_SUBUNIT; + subunit++, pcm_mask >>= SUBUNIT_PCM_SHIFT) { + xpd_t *tmp_xpd; if (!pcm_mask) break; /* optimize */ tmp_xpd = xpd_byaddr(xpd->xbus, xpd->addr.unit, subunit); - if (!tmp_xpd || !tmp_xpd->card_present || !SPAN_REGISTERED(tmp_xpd)) + if (!tmp_xpd || !tmp_xpd->card_present + || !SPAN_REGISTERED(tmp_xpd)) continue; spin_lock_irqsave(&tmp_xpd->lock, flags); for (i = 0; i < 2; i++) { - xpp_line_t tmp_mask = pcm_mask & (BIT(0) | BIT(1)); - volatile u_char *r; + xpp_line_t tmp_mask = pcm_mask & (BIT(0) | BIT(1)); + volatile u_char *r; if (IS_SET(tmp_mask, i)) { r = XPD_CHAN(tmp_xpd, i)->readchunk; - // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE); // DEBUG + // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE); // DEBUG memcpy((u_char *)r, pcm, DAHDI_CHUNKSIZE); pcm += DAHDI_CHUNKSIZE; } @@ -1279,7 +1305,7 @@ static void BRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) static int BRI_timing_priority(xpd_t *xpd) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; priv = xpd->priv; BUG_ON(!priv); @@ -1296,7 +1322,7 @@ int BRI_echocancel_timeslot(xpd_t *xpd, int pos) static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; int i; BUG_ON(!xpd); @@ -1305,11 +1331,11 @@ static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) XPD_DBG(GENERAL, xpd, "0x%8X\n", ec_mask); if (!ECHOOPS(xpd->xbus)) { XPD_DBG(GENERAL, xpd, - "No echo canceller in XBUS: Doing nothing.\n"); + "No echo canceller in XBUS: Doing nothing.\n"); return -EINVAL; } for (i = 0; i < PHONEDEV(xpd).channels - 1; i++) { - int on = BIT(i) & ec_mask; + int on = BIT(i) & ec_mask; CALL_EC_METHOD(ec_set, xpd->xbus, xpd, i, on); } @@ -1319,19 +1345,19 @@ static int BRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) /*---------------- BRI: HOST COMMANDS -------------------------------------*/ -static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, enum led_state to_led_state) +static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, + enum led_state to_led_state) { - int ret = 0; - xframe_t *xframe; - xpacket_t *pack; - struct bri_leds *bri_leds; - struct BRI_priv_data *priv; + int ret = 0; + xframe_t *xframe; + xpacket_t *pack; + struct bri_leds *bri_leds; + struct BRI_priv_data *priv; BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(LEDS, xpd, "%s -> %d\n", - (which_led)?"RED":"GREEN", + XPD_DBG(LEDS, xpd, "%s -> %d\n", (which_led) ? "RED" : "GREEN", to_led_state); XFRAME_NEW_CMD(xframe, pack, xbus, BRI, SET_LED, xpd->xbus_idx); bri_leds = &RPACKET_FIELD(pack, BRI, SET_LED, bri_leds); @@ -1345,28 +1371,27 @@ static /* 0x33 */ HOSTCMD(BRI, SET_LED, enum bri_led_names which_led, enum led_s static int write_state_register(xpd_t *xpd, __u8 value) { - int ret; + int ret; XPD_DBG(REGS, xpd, "value = 0x%02X\n", value); - ret = xpp_register_request(xpd->xbus, xpd, - BRI_PORT(xpd), /* portno */ - 1, /* writing */ - A_SU_WR_STA, /* regnum */ - 0, /* do_subreg */ - 0, /* subreg */ - value, /* data_low */ - 0, /* do_datah */ - 0, /* data_high */ - 0 /* should_reply */ - ); + ret = xpp_register_request(xpd->xbus, xpd, BRI_PORT(xpd), /* portno */ + 1, /* writing */ + A_SU_WR_STA, /* regnum */ + 0, /* do_subreg */ + 0, /* subreg */ + value, /* data_low */ + 0, /* do_datah */ + 0, /* data_high */ + 0 /* should_reply */ + ); return ret; } /*---------------- BRI: Astribank Reply Handlers --------------------------*/ static void su_new_state(xpd_t *xpd, __u8 reg_x30) { - struct BRI_priv_data *priv; - su_rd_sta_t new_state; + struct BRI_priv_data *priv; + su_rd_sta_t new_state; BUG_ON(!xpd); priv = xpd->priv; @@ -1382,79 +1407,78 @@ static void su_new_state(xpd_t *xpd, __u8 reg_x30) priv->reg30_ticks = 0; priv->reg30_good = 1; if (priv->state_register.bits.v_su_sta == new_state.bits.v_su_sta) - return; /* same same */ + return; /* same same */ XPD_DBG(SIGNAL, xpd, "%02X ---> %02X (info0=%d) (%s%i)\n", - priv->state_register.reg, - reg_x30, - new_state.bits.v_su_info0, - IS_NT(xpd)?"G":"F", - new_state.bits.v_su_sta); + priv->state_register.reg, reg_x30, new_state.bits.v_su_info0, + IS_NT(xpd) ? "G" : "F", new_state.bits.v_su_sta); if (!IS_NT(xpd)) { switch (new_state.bits.v_su_sta) { - case ST_TE_DEACTIVATED: /* F3 */ - XPD_DBG(SIGNAL, xpd, "State ST_TE_DEACTIVATED (F3)\n"); - clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags); - layer1_state(xpd, 0); - break; - case ST_TE_SIGWAIT: /* F4 */ - XPD_DBG(SIGNAL, xpd, "State ST_TE_SIGWAIT (F4)\n"); - layer1_state(xpd, 0); - break; - case ST_TE_IDENT: /* F5 */ - XPD_DBG(SIGNAL, xpd, "State ST_TE_IDENT (F5)\n"); - layer1_state(xpd, 0); - break; - case ST_TE_SYNCED: /* F6 */ - XPD_DBG(SIGNAL, xpd, "State ST_TE_SYNCED (F6)\n"); - layer1_state(xpd, 0); - break; - case ST_TE_ACTIVATED: /* F7 */ - XPD_DBG(SIGNAL, xpd, "State ST_TE_ACTIVATED (F7)\n"); - set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF); - clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); - set_bit(HFC_L1_ACTIVATED, &priv->l1_flags); - layer1_state(xpd, 1); - update_xpd_status(xpd, DAHDI_ALARM_NONE); - break; - case ST_TE_LOST_FRAMING: /* F8 */ - XPD_DBG(SIGNAL, xpd, "State ST_TE_LOST_FRAMING (F8)\n"); - layer1_state(xpd, 0); - break; - default: - XPD_NOTICE(xpd, "Bad TE state: %d\n", new_state.bits.v_su_sta); - break; + case ST_TE_DEACTIVATED: /* F3 */ + XPD_DBG(SIGNAL, xpd, "State ST_TE_DEACTIVATED (F3)\n"); + clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags); + layer1_state(xpd, 0); + break; + case ST_TE_SIGWAIT: /* F4 */ + XPD_DBG(SIGNAL, xpd, "State ST_TE_SIGWAIT (F4)\n"); + layer1_state(xpd, 0); + break; + case ST_TE_IDENT: /* F5 */ + XPD_DBG(SIGNAL, xpd, "State ST_TE_IDENT (F5)\n"); + layer1_state(xpd, 0); + break; + case ST_TE_SYNCED: /* F6 */ + XPD_DBG(SIGNAL, xpd, "State ST_TE_SYNCED (F6)\n"); + layer1_state(xpd, 0); + break; + case ST_TE_ACTIVATED: /* F7 */ + XPD_DBG(SIGNAL, xpd, "State ST_TE_ACTIVATED (F7)\n"); + set_bri_timer(xpd, "T3", &priv->t3, HFC_TIMER_OFF); + clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); + set_bit(HFC_L1_ACTIVATED, &priv->l1_flags); + layer1_state(xpd, 1); + update_xpd_status(xpd, DAHDI_ALARM_NONE); + break; + case ST_TE_LOST_FRAMING: /* F8 */ + XPD_DBG(SIGNAL, xpd, "State ST_TE_LOST_FRAMING (F8)\n"); + layer1_state(xpd, 0); + break; + default: + XPD_NOTICE(xpd, "Bad TE state: %d\n", + new_state.bits.v_su_sta); + break; } } else { switch (new_state.bits.v_su_sta) { - case ST_NT_DEACTIVATED: /* G1 */ - XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVATED (G1)\n"); - clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags); - set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); - layer1_state(xpd, 0); - break; - case ST_NT_ACTIVATING: /* G2 */ - XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATING (G2)\n"); - layer1_state(xpd, 0); - if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)) - nt_activation(xpd, 1); - break; - case ST_NT_ACTIVATED: /* G3 */ - XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATED (G3)\n"); - clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); - set_bit(HFC_L1_ACTIVATED, &priv->l1_flags); - set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); - layer1_state(xpd, 1); - update_xpd_status(xpd, DAHDI_ALARM_NONE); - break; - case ST_NT_DEACTIVTING: /* G4 */ - XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVTING (G4)\n"); - set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); - layer1_state(xpd, 0); - break; - default: - XPD_NOTICE(xpd, "Bad NT state: %d\n", new_state.bits.v_su_sta); - break; + case ST_NT_DEACTIVATED: /* G1 */ + XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVATED (G1)\n"); + clear_bit(HFC_L1_ACTIVATED, &priv->l1_flags); + set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); + layer1_state(xpd, 0); + break; + case ST_NT_ACTIVATING: /* G2 */ + XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATING (G2)\n"); + layer1_state(xpd, 0); + if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)) + nt_activation(xpd, 1); + break; + case ST_NT_ACTIVATED: /* G3 */ + XPD_DBG(SIGNAL, xpd, "State ST_NT_ACTIVATED (G3)\n"); + clear_bit(HFC_L1_ACTIVATING, &priv->l1_flags); + set_bit(HFC_L1_ACTIVATED, &priv->l1_flags); + set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); + layer1_state(xpd, 1); + update_xpd_status(xpd, DAHDI_ALARM_NONE); + break; + case ST_NT_DEACTIVTING: /* G4 */ + XPD_DBG(SIGNAL, xpd, "State ST_NT_DEACTIVTING (G4)\n"); + set_bri_timer(xpd, "T1", &priv->t1, HFC_TIMER_OFF); + layer1_state(xpd, 0); + break; + default: + XPD_NOTICE(xpd, "Bad NT state: %d\n", + new_state.bits.v_su_sta); + break; } } priv->state_register.reg = new_state.reg; @@ -1462,11 +1486,11 @@ static void su_new_state(xpd_t *xpd, __u8 reg_x30) static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) { - unsigned long flags; - struct BRI_priv_data *priv; - struct xpd_addr addr; - xpd_t *orig_xpd; - int ret; + unsigned long flags; + struct BRI_priv_data *priv; + struct xpd_addr addr; + xpd_t *orig_xpd; + int ret; /* Map UNIT + PORTNUM to XPD */ orig_xpd = xpd; @@ -1474,10 +1498,10 @@ static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) addr.subunit = info->portnum; xpd = xpd_byaddr(xbus, addr.unit, addr.subunit); if (!xpd) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) < 5) - notify_bad_xpd(__func__, xbus, addr , orig_xpd->xpdname); + notify_bad_xpd(__func__, xbus, addr, orig_xpd->xpdname); return -EPROTO; } spin_lock_irqsave(&xpd->lock, flags); @@ -1485,23 +1509,26 @@ static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) BUG_ON(!priv); if (REG_FIELD(info, do_subreg)) { XPD_DBG(REGS, xpd, "RI %02X %02X %02X\n", - REG_FIELD(info, regnum), REG_FIELD(info, subreg), REG_FIELD(info, data_low)); + REG_FIELD(info, regnum), REG_FIELD(info, subreg), + REG_FIELD(info, data_low)); } else { if (REG_FIELD(info, regnum) != A_SU_RD_STA) XPD_DBG(REGS, xpd, "RD %02X %02X\n", - REG_FIELD(info, regnum), REG_FIELD(info, data_low)); + REG_FIELD(info, regnum), REG_FIELD(info, + data_low)); else XPD_DBG(REGS, xpd, "Got SU_RD_STA=%02X\n", - REG_FIELD(info, data_low)); + REG_FIELD(info, data_low)); } if (info->is_multibyte) { XPD_DBG(REGS, xpd, "Got Multibyte: %d bytes, eoframe: %d\n", - info->bytes, info->eoframe); + info->bytes, info->eoframe); ret = rx_dchan(xpd, info); if (ret < 0) { priv->dchan_rx_drops++; if (atomic_read(&PHONEDEV(xpd).open_counter) > 0) - XPD_NOTICE(xpd, "Multibyte Drop: errno=%d\n", ret); + XPD_NOTICE(xpd, "Multibyte Drop: errno=%d\n", + ret); } goto end; } @@ -1510,10 +1537,11 @@ static int BRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) } /* Update /proc info only if reply relate to the last slic read request */ - if ( - REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) && - REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) && - REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) { + if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) + && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, + do_subreg) + && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, + subreg)) { xpd->last_reply = *info; } @@ -1524,14 +1552,14 @@ end: static int BRI_card_state(xpd_t *xpd, bool on) { - struct BRI_priv_data *priv; + struct BRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF"); if (on) { if (!test_bit(HFC_L1_ACTIVATED, &priv->l1_flags)) { - if ( ! IS_NT(xpd)) + if (!IS_NT(xpd)) te_activation(xpd, 1); else nt_activation(xpd, 1); @@ -1541,47 +1569,41 @@ static int BRI_card_state(xpd_t *xpd, bool on) return 0; } -static const struct xops bri_xops = { - .card_new = BRI_card_new, - .card_init = BRI_card_init, - .card_remove = BRI_card_remove, - .card_tick = BRI_card_tick, - .card_register_reply = BRI_card_register_reply, +static const struct xops bri_xops = { + .card_new = BRI_card_new, + .card_init = BRI_card_init, + .card_remove = BRI_card_remove, + .card_tick = BRI_card_tick, + .card_register_reply = BRI_card_register_reply, }; -static const struct phoneops bri_phoneops = { - .card_dahdi_preregistration = BRI_card_dahdi_preregistration, - .card_dahdi_postregistration = BRI_card_dahdi_postregistration, - .card_hooksig = BRI_card_hooksig, - .card_pcm_recompute = BRI_card_pcm_recompute, - .card_pcm_fromspan = BRI_card_pcm_fromspan, - .card_pcm_tospan = BRI_card_pcm_tospan, - .card_timing_priority = BRI_timing_priority, - .echocancel_timeslot = BRI_echocancel_timeslot, - .echocancel_setmask = BRI_echocancel_setmask, - .card_ioctl = BRI_card_ioctl, - .card_open = BRI_card_open, - .card_close = BRI_card_close, - .card_state = BRI_card_state, +static const struct phoneops bri_phoneops = { + .card_dahdi_preregistration = BRI_card_dahdi_preregistration, + .card_dahdi_postregistration = BRI_card_dahdi_postregistration, + .card_hooksig = BRI_card_hooksig, + .card_pcm_recompute = BRI_card_pcm_recompute, + .card_pcm_fromspan = BRI_card_pcm_fromspan, + .card_pcm_tospan = BRI_card_pcm_tospan, + .card_timing_priority = BRI_timing_priority, + .echocancel_timeslot = BRI_echocancel_timeslot, + .echocancel_setmask = BRI_echocancel_setmask, + .card_ioctl = BRI_card_ioctl, + .card_open = BRI_card_open, + .card_close = BRI_card_close, + .card_state = BRI_card_state, }; static xproto_table_t PROTO_TABLE(BRI) = { - .owner = THIS_MODULE, - .entries = { - /* Table Card Opcode */ - }, - .name = "BRI", /* protocol name */ - .ports_per_subunit = 1, - .type = XPD_TYPE_BRI, - .xops = &bri_xops, - .phoneops = &bri_phoneops, - .packet_is_valid = bri_packet_is_valid, - .packet_dump = bri_packet_dump, -}; + .owner = THIS_MODULE,.entries = { + /* Table Card Opcode */ + },.name = "BRI", /* protocol name */ +.ports_per_subunit = 1,.type = XPD_TYPE_BRI,.xops = + &bri_xops,.phoneops = &bri_phoneops,.packet_is_valid = + bri_packet_is_valid,.packet_dump = bri_packet_dump,}; static bool bri_packet_is_valid(xpacket_t *pack) { - const xproto_entry_t *xe = NULL; + const xproto_entry_t *xe = NULL; // DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(BRI), XPACKET_OP(pack)); return xe != NULL; @@ -1591,15 +1613,17 @@ static void bri_packet_dump(const char *msg, xpacket_t *pack) { DBG(GENERAL, "%s\n", msg); } + /*------------------------- REGISTER Handling --------------------------*/ #ifdef CONFIG_PROC_FS -static int proc_bri_info_read(char *page, char **start, off_t off, int count, int *eof, void *data) +static int proc_bri_info_read(char *page, char **start, off_t off, int count, + int *eof, void *data) { - int len = 0; - unsigned long flags; - xpd_t *xpd = data; - struct BRI_priv_data *priv; + int len = 0; + unsigned long flags; + xpd_t *xpd = data; + struct BRI_priv_data *priv; DBG(PROC, "\n"); if (!xpd) @@ -1609,15 +1633,20 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in BUG_ON(!priv); len += sprintf(page + len, "%05d Layer 1: ", priv->poll_counter); if (priv->reg30_good) { - len += sprintf(page + len, "%-5s ", (priv->layer1_up) ? "UP" : "DOWN"); - len += sprintf(page + len, "%c%d %-15s -- fr_sync=%d t2_exp=%d info0=%d g2_g3=%d\n", - IS_NT(xpd)?'G':'F', - priv->state_register.bits.v_su_sta, - xhfc_state_name(IS_NT(xpd), priv->state_register.bits.v_su_sta), - priv->state_register.bits.v_su_fr_sync, - priv->state_register.bits.v_su_t2_exp, - priv->state_register.bits.v_su_info0, - priv->state_register.bits.v_g2_g3); + len += + sprintf(page + len, "%-5s ", + (priv->layer1_up) ? "UP" : "DOWN"); + len += + sprintf(page + len, + "%c%d %-15s -- fr_sync=%d t2_exp=%d info0=%d g2_g3=%d\n", + IS_NT(xpd) ? 'G' : 'F', + priv->state_register.bits.v_su_sta, + xhfc_state_name(IS_NT(xpd), + priv->state_register.bits.v_su_sta), + priv->state_register.bits.v_su_fr_sync, + priv->state_register.bits.v_su_t2_exp, + priv->state_register.bits.v_su_info0, + priv->state_register.bits.v_g2_g3); } else len += sprintf(page + len, "Unknown\n"); if (IS_NT(xpd)) { @@ -1626,24 +1655,37 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in len += sprintf(page + len, "T3 Timer: %d\n", priv->t3); } len += sprintf(page + len, "Tick Counter: %d\n", priv->tick_counter); - len += sprintf(page + len, "Last Poll Reply: %d ticks ago\n", priv->reg30_ticks); + len += + sprintf(page + len, "Last Poll Reply: %d ticks ago\n", + priv->reg30_ticks); len += sprintf(page + len, "reg30_good=%d\n", priv->reg30_good); - len += sprintf(page + len, "D-Channel: TX=[%5d] RX=[%5d] BAD=[%5d] ", - priv->dchan_tx_counter, priv->dchan_rx_counter, priv->dchan_rx_drops); + len += + sprintf(page + len, "D-Channel: TX=[%5d] RX=[%5d] BAD=[%5d] ", + priv->dchan_tx_counter, priv->dchan_rx_counter, + priv->dchan_rx_drops); if (priv->dchan_alive) { - len += sprintf(page + len, "(alive %d K-ticks)\n", - priv->dchan_alive_ticks/1000); + len += + sprintf(page + len, "(alive %d K-ticks)\n", + priv->dchan_alive_ticks / 1000); } else { len += sprintf(page + len, "(dead)\n"); } - len += sprintf(page + len, "dchan_notx_ticks: %d\n", priv->dchan_notx_ticks); - len += sprintf(page + len, "dchan_norx_ticks: %d\n", priv->dchan_norx_ticks); - len += sprintf(page + len, "LED: %-10s = %d\n", "GREEN", priv->ledstate[GREEN_LED]); - len += sprintf(page + len, "LED: %-10s = %d\n", "RED", priv->ledstate[RED_LED]); + len += + sprintf(page + len, "dchan_notx_ticks: %d\n", + priv->dchan_notx_ticks); + len += + sprintf(page + len, "dchan_norx_ticks: %d\n", + priv->dchan_norx_ticks); + len += + sprintf(page + len, "LED: %-10s = %d\n", "GREEN", + priv->ledstate[GREEN_LED]); + len += + sprintf(page + len, "LED: %-10s = %d\n", "RED", + priv->ledstate[RED_LED]); len += sprintf(page + len, "\nDCHAN:\n"); len += sprintf(page + len, "\n"); spin_unlock_irqrestore(&xpd->lock, flags); - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1657,13 +1699,13 @@ static int proc_bri_info_read(char *page, char **start, off_t off, int count, in static int bri_xpd_probe(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; xpd = dev_to_xpd(dev); /* Is it our device? */ if (xpd->type != XPD_TYPE_BRI) { - XPD_ERR(xpd, "drop suggestion for %s (%d)\n", - dev_name(dev), xpd->type); + XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev), + xpd->type); return -EINVAL; } XPD_DBG(DEVICES, xpd, "SYSFS\n"); @@ -1672,28 +1714,27 @@ static int bri_xpd_probe(struct device *dev) static int bri_xpd_remove(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; xpd = dev_to_xpd(dev); XPD_DBG(DEVICES, xpd, "SYSFS\n"); return 0; } -static struct xpd_driver bri_driver = { - .type = XPD_TYPE_BRI, - .driver = { - .name = "bri", +static struct xpd_driver bri_driver = { + .type = XPD_TYPE_BRI, + .driver = { + .name = "bri", #ifndef OLD_HOTPLUG_SUPPORT - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .probe = bri_xpd_probe, - .remove = bri_xpd_remove - } + .probe = bri_xpd_probe, + .remove = bri_xpd_remove} }; static int __init card_bri_startup(void) { - int ret; + int ret; if ((ret = xpd_driver_register(&bri_driver.driver)) < 0) return ret; diff --git a/drivers/dahdi/xpp/card_bri.h b/drivers/dahdi/xpp/card_bri.h index a7b69de..8c49021 100644 --- a/drivers/dahdi/xpp/card_bri.h +++ b/drivers/dahdi/xpp/card_bri.h @@ -25,7 +25,7 @@ #include "xpd.h" enum bri_opcodes { - XPROTO_NAME(BRI, SET_LED) = 0x33, + XPROTO_NAME(BRI, SET_LED) = 0x33, }; -#endif /* CARD_BRI_H */ +#endif /* CARD_BRI_H */ diff --git a/drivers/dahdi/xpp/card_echo.c b/drivers/dahdi/xpp/card_echo.c index 25d09d9..b70878c 100644 --- a/drivers/dahdi/xpp/card_echo.c +++ b/drivers/dahdi/xpp/card_echo.c @@ -42,25 +42,20 @@ static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); static bool echo_packet_is_valid(xpacket_t *pack); static void echo_packet_dump(const char *msg, xpacket_t *pack); -DEF_RPACKET_DATA(ECHO, SET, - __u8 timeslots[ECHO_TIMESLOTS]; - ); +DEF_RPACKET_DATA(ECHO, SET, __u8 timeslots[ECHO_TIMESLOTS];); -DEF_RPACKET_DATA(ECHO, SET_REPLY, - __u8 status; - __u8 reserved; - ); +DEF_RPACKET_DATA(ECHO, SET_REPLY, __u8 status; __u8 reserved;); struct ECHO_priv_data { }; -static xproto_table_t PROTO_TABLE(ECHO); +static xproto_table_t PROTO_TABLE(ECHO); /*---------------- ECHO: Methods -------------------------------------------*/ static xpd_t *ECHO_card_new(xbus_t *xbus, int unit, int subunit, - const xproto_table_t *proto_table, __u8 subtype, - int subunits, int subunit_ports, bool to_phone) + const xproto_table_t *proto_table, __u8 subtype, + int subunits, int subunit_ports, bool to_phone) { xpd_t *xpd = NULL; int channels = 0; @@ -70,8 +65,9 @@ static xpd_t *ECHO_card_new(xbus_t *xbus, int unit, int subunit, return NULL; } XBUS_DBG(GENERAL, xbus, "\n"); - xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, - sizeof(struct ECHO_priv_data), proto_table, channels); + xpd = + xpd_alloc(xbus, unit, subunit, subtype, subunits, + sizeof(struct ECHO_priv_data), proto_table, channels); if (!xpd) return NULL; xpd->type_name = "ECHO"; @@ -122,19 +118,16 @@ static int ECHO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) static int rate_limit; if ((rate_limit++ % 1003) < 5) - notify_bad_xpd(__func__, xbus, addr, - orig_xpd->xpdname); + notify_bad_xpd(__func__, xbus, addr, orig_xpd->xpdname); return -EPROTO; } spin_lock_irqsave(&xpd->lock, flags); /* Update /proc info only if reply related to last reg read request */ - if ( - REG_FIELD(&xpd->requested_reply, regnum) == - REG_FIELD(info, regnum) && - REG_FIELD(&xpd->requested_reply, do_subreg) == - REG_FIELD(info, do_subreg) && - REG_FIELD(&xpd->requested_reply, subreg) == - REG_FIELD(info, subreg)) { + if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) + && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, + do_subreg) + && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, + subreg)) { xpd->last_reply = *info; } spin_unlock_irqrestore(&xpd->lock, flags); @@ -198,7 +191,7 @@ static int ECHO_ec_set(xpd_t *xpd, int pos, bool on) ts[ts_number] &= ~ts_mask; } LINE_DBG(GENERAL, xpd, pos, "%s = %d -- ts_number=%d ts_mask=0x%X\n", - __func__, on, ts_number, ts_mask); + __func__, on, ts_number, ts_mask); return 0; } @@ -220,7 +213,7 @@ static int ECHO_ec_get(xpd_t *xpd, int pos) } #if 0 LINE_DBG(GENERAL, xpd, pos, "ec_get=%d -- ts_number=%d ts_mask=0x%X\n", - is_on, ts_number, ts_mask); + is_on, ts_number, ts_mask); #endif return is_on; } @@ -233,15 +226,14 @@ static void ECHO_ec_dump(xbus_t *xbus) ts = xbus->echo_state.timeslots; for (i = 0; i + 15 < ECHO_TIMESLOTS; i += 16) { XBUS_DBG(GENERAL, xbus, - "EC-DUMP[%03d]: " - "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X " - "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n", - i, - ts[i+0], ts[i+1], ts[i+2], ts[i+3], ts[i+4], ts[i+5], - ts[i+6], ts[i+7], - ts[i+8], ts[i+9], ts[i+10], ts[i+11], ts[i+12], - ts[i+13], ts[i+14], ts[i+15] - ); + "EC-DUMP[%03d]: " + "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X " + "0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n", + i, ts[i + 0], ts[i + 1], ts[i + 2], ts[i + 3], + ts[i + 4], ts[i + 5], ts[i + 6], ts[i + 7], ts[i + 8], + ts[i + 9], ts[i + 10], ts[i + 11], ts[i + 12], + ts[i + 13], ts[i + 14], ts[i + 15] + ); } } @@ -255,7 +247,7 @@ static int ECHO_ec_update(xbus_t *xbus) /*---------------- ECHO: Astribank Reply Handlers --------------------------*/ HANDLER_DEF(ECHO, SET_REPLY) { - __u8 status; + __u8 status; BUG_ON(!xpd); status = RPACKET_FIELD(pack, ECHO, SET_REPLY, status); @@ -263,39 +255,32 @@ HANDLER_DEF(ECHO, SET_REPLY) return 0; } -static const struct xops echo_xops = { - .card_new = ECHO_card_new, - .card_init = ECHO_card_init, - .card_remove = ECHO_card_remove, - .card_tick = ECHO_card_tick, - .card_register_reply = ECHO_card_register_reply, +static const struct xops echo_xops = { + .card_new = ECHO_card_new, + .card_init = ECHO_card_init, + .card_remove = ECHO_card_remove, + .card_tick = ECHO_card_tick, + .card_register_reply = ECHO_card_register_reply, }; -static const struct echoops echoops = { - .ec_set = ECHO_ec_set, - .ec_get = ECHO_ec_get, - .ec_update = ECHO_ec_update, - .ec_dump = ECHO_ec_dump, +static const struct echoops echoops = { + .ec_set = ECHO_ec_set, + .ec_get = ECHO_ec_get, + .ec_update = ECHO_ec_update, + .ec_dump = ECHO_ec_dump, }; static xproto_table_t PROTO_TABLE(ECHO) = { - .owner = THIS_MODULE, - .entries = { - /* Table Card Opcode */ - XENTRY(ECHO, ECHO, SET_REPLY), - }, - .name = "ECHO", - .ports_per_subunit = 1, - .type = XPD_TYPE_ECHO, - .xops = &echo_xops, - .echoops = &echoops, - .packet_is_valid = echo_packet_is_valid, - .packet_dump = echo_packet_dump, -}; + .owner = THIS_MODULE,.entries = { + /* Table Card Opcode */ +XENTRY(ECHO, ECHO, SET_REPLY),},.name = "ECHO",.ports_per_subunit = + 1,.type = XPD_TYPE_ECHO,.xops = &echo_xops,.echoops = + &echoops,.packet_is_valid = + echo_packet_is_valid,.packet_dump = echo_packet_dump,}; static bool echo_packet_is_valid(xpacket_t *pack) { - const xproto_entry_t *xe = NULL; + const xproto_entry_t *xe = NULL; // DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(ECHO), XPACKET_OP(pack)); return xe != NULL; @@ -309,14 +294,14 @@ static void echo_packet_dump(const char *msg, xpacket_t *pack) /*------------------------- sysfs stuff --------------------------------*/ static int echo_xpd_probe(struct device *dev) { - xpd_t *ec_xpd; - int ret = 0; + xpd_t *ec_xpd; + int ret = 0; ec_xpd = dev_to_xpd(dev); /* Is it our device? */ if (ec_xpd->type != XPD_TYPE_ECHO) { - XPD_ERR(ec_xpd, "drop suggestion for %s (%d)\n", - dev_name(dev), ec_xpd->type); + XPD_ERR(ec_xpd, "drop suggestion for %s (%d)\n", dev_name(dev), + ec_xpd->type); return -EINVAL; } XPD_DBG(DEVICES, ec_xpd, "SYSFS\n"); @@ -325,23 +310,22 @@ static int echo_xpd_probe(struct device *dev) static int echo_xpd_remove(struct device *dev) { - xpd_t *ec_xpd; + xpd_t *ec_xpd; ec_xpd = dev_to_xpd(dev); XPD_DBG(DEVICES, ec_xpd, "SYSFS\n"); return 0; } -static struct xpd_driver echo_driver = { - .type = XPD_TYPE_ECHO, - .driver = { - .name = "echo", +static struct xpd_driver echo_driver = { + .type = XPD_TYPE_ECHO, + .driver = { + .name = "echo", #ifndef OLD_HOTPLUG_SUPPORT - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .probe = echo_xpd_probe, - .remove = echo_xpd_remove - } + .probe = echo_xpd_probe, + .remove = echo_xpd_remove} }; static int __init card_echo_startup(void) diff --git a/drivers/dahdi/xpp/card_echo.h b/drivers/dahdi/xpp/card_echo.h index 81fea05..55c1d73 100644 --- a/drivers/dahdi/xpp/card_echo.h +++ b/drivers/dahdi/xpp/card_echo.h @@ -24,8 +24,8 @@ #include "xpd.h" enum echo_opcodes { - XPROTO_NAME(ECHO, SET) = 0x39, - XPROTO_NAME(ECHO, SET_REPLY) = 0x3A, + XPROTO_NAME(ECHO, SET) = 0x39, + XPROTO_NAME(ECHO, SET_REPLY) = 0x3A, }; -#endif /* CARD_ECHO_H */ +#endif /* CARD_ECHO_H */ diff --git a/drivers/dahdi/xpp/card_fxo.c b/drivers/dahdi/xpp/card_fxo.c index 1eaa215..213aba9 100644 --- a/drivers/dahdi/xpp/card_fxo.c +++ b/drivers/dahdi/xpp/card_fxo.c @@ -34,21 +34,29 @@ static const char rcsid[] = "$Id$"; static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); -static DEF_PARM(uint, poll_battery_interval, 500, 0644, "Poll battery interval in milliseconds (0 - disable)"); +static DEF_PARM(uint, poll_battery_interval, 500, 0644, + "Poll battery interval in milliseconds (0 - disable)"); #ifdef WITH_METERING -static DEF_PARM(uint, poll_metering_interval, 500, 0644, "Poll metering interval in milliseconds (0 - disable)"); +static DEF_PARM(uint, poll_metering_interval, 500, 0644, + "Poll metering interval in milliseconds (0 - disable)"); #endif -static DEF_PARM(int, ring_debounce, 50, 0644, "Number of ticks to debounce a false RING indication"); -static DEF_PARM(int, caller_id_style, 0, 0444, "Caller-Id detection style: 0 - [BELL], 1 - [ETSI_FSK], 2 - [ETSI_DTMF]"); -static DEF_PARM(int, power_denial_safezone, 650, 0644, "msec after offhook to ignore power-denial ( (0 - disable power-denial)"); -static DEF_PARM(int, power_denial_minlen, 80, 0644, "Minimal detected power-denial length (msec) (0 - disable power-denial)"); -static DEF_PARM(uint, battery_threshold, 3, 0644, "Minimum voltage that shows there is battery"); -static DEF_PARM(uint, battery_debounce, 1000, 0644, "Minimum interval (msec) for detection of battery off"); +static DEF_PARM(int, ring_debounce, 50, 0644, + "Number of ticks to debounce a false RING indication"); +static DEF_PARM(int, caller_id_style, 0, 0444, + "Caller-Id detection style: 0 - [BELL], 1 - [ETSI_FSK], 2 - [ETSI_DTMF]"); +static DEF_PARM(int, power_denial_safezone, 650, 0644, + "msec after offhook to ignore power-denial ( (0 - disable power-denial)"); +static DEF_PARM(int, power_denial_minlen, 80, 0644, + "Minimal detected power-denial length (msec) (0 - disable power-denial)"); +static DEF_PARM(uint, battery_threshold, 3, 0644, + "Minimum voltage that shows there is battery"); +static DEF_PARM(uint, battery_debounce, 1000, 0644, + "Minimum interval (msec) for detection of battery off"); enum cid_style { - CID_STYLE_BELL = 0, /* E.g: US (Bellcore) */ - CID_STYLE_ETSI_FSK = 1, /* E.g: UK (British Telecom) */ - CID_STYLE_ETSI_DTMF = 2, /* E.g: DK, Russia */ + CID_STYLE_BELL = 0, /* E.g: US (Bellcore) */ + CID_STYLE_ETSI_FSK = 1, /* E.g: UK (British Telecom) */ + CID_STYLE_ETSI_DTMF = 2, /* E.g: DK, Russia */ }; /* Signaling is opposite (fxs signalling for fxo card) */ @@ -86,9 +94,11 @@ enum fxo_leds { static bool fxo_packet_is_valid(xpacket_t *pack); static void fxo_packet_dump(const char *msg, xpacket_t *pack); #ifdef CONFIG_PROC_FS -static int proc_fxo_info_read(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_fxo_info_read(char *page, char **start, off_t off, int count, + int *eof, void *data); #ifdef WITH_METERING -static int proc_xpd_metering_read(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_xpd_metering_read(char *page, char **start, off_t off, + int count, int *eof, void *data); #endif #endif static void dahdi_report_battery(xpd_t *xpd, lineno_t chan); @@ -99,57 +109,57 @@ static void dahdi_report_battery(xpd_t *xpd, lineno_t chan); #define PROC_METERING_FNAME "metering_read" #endif -#define REG_DAA_CONTROL1 0x05 /* 5 - DAA Control 1 */ -#define REG_DAA_CONTROL1_OH BIT(0) /* Off-Hook. */ -#define REG_DAA_CONTROL1_ONHM BIT(3) /* On-Hook Line Monitor */ +#define REG_DAA_CONTROL1 0x05 /* 5 - DAA Control 1 */ +#define REG_DAA_CONTROL1_OH BIT(0) /* Off-Hook. */ +#define REG_DAA_CONTROL1_ONHM BIT(3) /* On-Hook Line Monitor */ #define DAA_REG_METERING 0x11 /* 17 */ #define DAA_REG_CURRENT 0x1C /* 28 */ #define DAA_REG_VBAT 0x1D /* 29 */ enum battery_state { - BATTERY_UNKNOWN = 0, - BATTERY_ON = 1, - BATTERY_OFF = -1 + BATTERY_UNKNOWN = 0, + BATTERY_ON = 1, + BATTERY_OFF = -1 }; enum polarity_state { - POL_UNKNOWN = 0, - POL_POSITIVE = 1, - POL_NEGATIVE = -1 + POL_UNKNOWN = 0, + POL_POSITIVE = 1, + POL_NEGATIVE = -1 }; enum power_state { - POWER_UNKNOWN = 0, - POWER_ON = 1, - POWER_OFF = -1 + POWER_UNKNOWN = 0, + POWER_ON = 1, + POWER_OFF = -1 }; struct FXO_priv_data { #ifdef WITH_METERING - struct proc_dir_entry *meteringfile; + struct proc_dir_entry *meteringfile; #endif - struct proc_dir_entry *fxo_info; - uint poll_counter; - signed char battery_voltage[CHANNELS_PERXPD]; - signed char battery_current[CHANNELS_PERXPD]; - enum battery_state battery[CHANNELS_PERXPD]; - ushort nobattery_debounce[CHANNELS_PERXPD]; - enum polarity_state polarity[CHANNELS_PERXPD]; - ushort polarity_debounce[CHANNELS_PERXPD]; - enum power_state power[CHANNELS_PERXPD]; - ushort power_denial_delay[CHANNELS_PERXPD]; - ushort power_denial_length[CHANNELS_PERXPD]; - ushort power_denial_safezone[CHANNELS_PERXPD]; - xpp_line_t cidfound; /* 0 - OFF, 1 - ON */ - unsigned int cidtimer[CHANNELS_PERXPD]; - xpp_line_t ledstate[NUM_LEDS]; /* 0 - OFF, 1 - ON */ - xpp_line_t ledcontrol[NUM_LEDS]; /* 0 - OFF, 1 - ON */ - int led_counter[NUM_LEDS][CHANNELS_PERXPD]; - atomic_t ring_debounce[CHANNELS_PERXPD]; + struct proc_dir_entry *fxo_info; + uint poll_counter; + signed char battery_voltage[CHANNELS_PERXPD]; + signed char battery_current[CHANNELS_PERXPD]; + enum battery_state battery[CHANNELS_PERXPD]; + ushort nobattery_debounce[CHANNELS_PERXPD]; + enum polarity_state polarity[CHANNELS_PERXPD]; + ushort polarity_debounce[CHANNELS_PERXPD]; + enum power_state power[CHANNELS_PERXPD]; + ushort power_denial_delay[CHANNELS_PERXPD]; + ushort power_denial_length[CHANNELS_PERXPD]; + ushort power_denial_safezone[CHANNELS_PERXPD]; + xpp_line_t cidfound; /* 0 - OFF, 1 - ON */ + unsigned int cidtimer[CHANNELS_PERXPD]; + xpp_line_t ledstate[NUM_LEDS]; /* 0 - OFF, 1 - ON */ + xpp_line_t ledcontrol[NUM_LEDS]; /* 0 - OFF, 1 - ON */ + int led_counter[NUM_LEDS][CHANNELS_PERXPD]; + atomic_t ring_debounce[CHANNELS_PERXPD]; #ifdef WITH_METERING - uint metering_count[CHANNELS_PERXPD]; - xpp_line_t metering_tone_state; + uint metering_count[CHANNELS_PERXPD]; + xpp_line_t metering_tone_state; #endif }; @@ -170,50 +180,53 @@ struct FXO_priv_data { static const char *power2str(enum power_state pw) { switch (pw) { - case POWER_UNKNOWN: return "UNKNOWN"; - case POWER_OFF: return "OFF"; - case POWER_ON: return "ON"; + case POWER_UNKNOWN: + return "UNKNOWN"; + case POWER_OFF: + return "OFF"; + case POWER_ON: + return "ON"; } return NULL; } static void power_change(xpd_t *xpd, int portno, enum power_state pw) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; priv = xpd->priv; LINE_DBG(SIGNAL, xpd, portno, "power: %s -> %s\n", - power2str(priv->power[portno]), - power2str(pw)); + power2str(priv->power[portno]), power2str(pw)); priv->power[portno] = pw; } static void reset_battery_readings(xpd_t *xpd, lineno_t pos) { - struct FXO_priv_data *priv = xpd->priv; + struct FXO_priv_data *priv = xpd->priv; priv->nobattery_debounce[pos] = 0; priv->power_denial_delay[pos] = 0; power_change(xpd, pos, POWER_UNKNOWN); } -static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) }; +static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) }; /* * LED control is done via DAA register 0x20 */ static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on) { - int ret = 0; - struct FXO_priv_data *priv; - xbus_t *xbus; - __u8 value; + int ret = 0; + struct FXO_priv_data *priv; + xbus_t *xbus; + __u8 value; BUG_ON(!xpd); xbus = xpd->xbus; priv = xpd->priv; which = which % NUM_LEDS; - if (IS_SET(PHONEDEV(xpd).digital_outputs, chan) || IS_SET(PHONEDEV(xpd).digital_inputs, chan)) + if (IS_SET(PHONEDEV(xpd).digital_outputs, chan) + || IS_SET(PHONEDEV(xpd).digital_inputs, chan)) goto out; if (chan == PORT_BROADCAST) { priv->ledstate[which] = (on) ? ~0 : 0; @@ -228,7 +241,8 @@ static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on) value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]); value |= (on) ? BIT(0) : 0; value |= (on) ? BIT(1) : 0; - LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off"); + LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, + (on) ? "on" : "off"); ret = DAA_DIRECT_REQUEST(xbus, xpd, chan, DAA_WRITE, 0x20, value); out: return ret; @@ -236,12 +250,12 @@ out: static void handle_fxo_leds(xpd_t *xpd) { - int i; - unsigned long flags; - const enum fxo_leds colors[] = { LED_GREEN, LED_RED }; - enum fxo_leds color; - unsigned int timer_count; - struct FXO_priv_data *priv; + int i; + unsigned long flags; + const enum fxo_leds colors[] = { LED_GREEN, LED_RED }; + enum fxo_leds color; + unsigned int timer_count; + struct FXO_priv_data *priv; BUG_ON(!xpd); spin_lock_irqsave(&xpd->lock, flags); @@ -249,25 +263,31 @@ static void handle_fxo_leds(xpd_t *xpd) timer_count = xpd->timer_count; for (color = 0; color < ARRAY_SIZE(colors); color++) { for_each_line(xpd, i) { - if (IS_SET(PHONEDEV(xpd).digital_outputs, i) || IS_SET(PHONEDEV(xpd).digital_inputs, i)) + if (IS_SET(PHONEDEV(xpd).digital_outputs, i) + || IS_SET(PHONEDEV(xpd).digital_inputs, i)) continue; - if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) { // Blinking - int mod_value = LED_COUNTER(priv, i, color); + if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) { // Blinking + int mod_value = LED_COUNTER(priv, i, color); if (!mod_value) - mod_value = DEFAULT_LED_PERIOD; /* safety value */ + mod_value = DEFAULT_LED_PERIOD; /* safety value */ // led state is toggled if ((timer_count % mod_value) == 0) { - LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF"); + LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", + (IS_SET + (priv->ledstate[color], + i)) ? "ON" : "OFF"); if (!IS_SET(priv->ledstate[color], i)) { do_led(xpd, i, color, 1); } else { do_led(xpd, i, color, 0); } } - } else if (IS_SET(priv->ledcontrol[color], i) && !IS_SET(priv->ledstate[color], i)) { + } else if (IS_SET(priv->ledcontrol[color], i) + && !IS_SET(priv->ledstate[color], i)) { do_led(xpd, i, color, 1); - } else if (!IS_SET(priv->ledcontrol[color], i) && IS_SET(priv->ledstate[color], i)) { + } else if (!IS_SET(priv->ledcontrol[color], i) + && IS_SET(priv->ledstate[color], i)) { do_led(xpd, i, color, 0); } } @@ -290,7 +310,7 @@ static void update_dahdi_ring(xpd_t *xpd, int pos, bool on) static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_dahdi) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; priv = xpd->priv; BUG_ON(!priv); @@ -320,32 +340,36 @@ static void mark_ring(xpd_t *xpd, lineno_t pos, bool on, bool update_dahdi) static int do_sethook(xpd_t *xpd, int pos, bool to_offhook) { - unsigned long flags; - xbus_t *xbus; - struct FXO_priv_data *priv; - int ret = 0; - __u8 value; + unsigned long flags; + xbus_t *xbus; + struct FXO_priv_data *priv; + int ret = 0; + __u8 value; BUG_ON(!xpd); - BUG_ON(PHONEDEV(xpd).direction == TO_PHONE); // We can SETHOOK state only on PSTN + BUG_ON(PHONEDEV(xpd).direction == TO_PHONE); // We can SETHOOK state only on PSTN xbus = xpd->xbus; priv = xpd->priv; BUG_ON(!priv); if (priv->battery[pos] != BATTERY_ON && to_offhook) { - LINE_NOTICE(xpd, pos, "Cannot take offhook while battery is off!\n"); + LINE_NOTICE(xpd, pos, + "Cannot take offhook while battery is off!\n"); return -EINVAL; } spin_lock_irqsave(&xpd->lock, flags); - mark_ring(xpd, pos, 0, 0); // No more rings - value = REG_DAA_CONTROL1_ONHM; /* Bit 3 is for CID */ + mark_ring(xpd, pos, 0, 0); // No more rings + value = REG_DAA_CONTROL1_ONHM; /* Bit 3 is for CID */ if (to_offhook) value |= REG_DAA_CONTROL1_OH; - LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value, (to_offhook)?"OFFHOOK":"ONHOOK"); + LINE_DBG(SIGNAL, xpd, pos, "SETHOOK: value=0x%02X %s\n", value, + (to_offhook) ? "OFFHOOK" : "ONHOOK"); if (to_offhook) MARK_ON(priv, pos, LED_GREEN); else MARK_OFF(priv, pos, LED_GREEN); - ret = DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, REG_DAA_CONTROL1, value); + ret = + DAA_DIRECT_REQUEST(xbus, xpd, pos, DAA_WRITE, REG_DAA_CONTROL1, + value); mark_offhook(xpd, pos, to_offhook); if (caller_id_style != CID_STYLE_ETSI_DTMF) oht_pcm(xpd, pos, 0); @@ -370,7 +394,7 @@ static int do_sethook(xpd_t *xpd, int pos, bool to_offhook) static void fxo_proc_remove(xbus_t *xbus, xpd_t *xpd) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -394,25 +418,30 @@ static void fxo_proc_remove(xbus_t *xbus, xpd_t *xpd) static int fxo_proc_create(xbus_t *xbus, xpd_t *xpd) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; #ifdef CONFIG_PROC_FS XPD_DBG(PROC, xpd, "Creating FXO_INFO file\n"); - priv->fxo_info = create_proc_read_entry(PROC_FXO_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_fxo_info_read, xpd); + priv->fxo_info = + create_proc_read_entry(PROC_FXO_INFO_FNAME, 0444, xpd->proc_xpd_dir, + proc_fxo_info_read, xpd); if (!priv->fxo_info) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXO_INFO_FNAME); + XPD_ERR(xpd, "Failed to create proc file '%s'\n", + PROC_FXO_INFO_FNAME); fxo_proc_remove(xbus, xpd); return -EINVAL; } SET_PROC_DIRENTRY_OWNER(priv->fxo_info); #ifdef WITH_METERING XPD_DBG(PROC, xpd, "Creating Metering tone file\n"); - priv->meteringfile = create_proc_read_entry(PROC_METERING_FNAME, 0444, xpd->proc_xpd_dir, - proc_xpd_metering_read, xpd); + priv->meteringfile = + create_proc_read_entry(PROC_METERING_FNAME, 0444, xpd->proc_xpd_dir, + proc_xpd_metering_read, xpd); if (!priv->meteringfile) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_METERING_FNAME); + XPD_ERR(xpd, "Failed to create proc file '%s'\n", + PROC_METERING_FNAME); fxo_proc_remove(xbus, xpd); return -EINVAL; } @@ -422,23 +451,26 @@ static int fxo_proc_create(xbus_t *xbus, xpd_t *xpd) return 0; } -static xpd_t *FXO_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, - __u8 subtype, int subunits, int subunit_ports, bool to_phone) +static xpd_t *FXO_card_new(xbus_t *xbus, int unit, int subunit, + const xproto_table_t *proto_table, __u8 subtype, + int subunits, int subunit_ports, bool to_phone) { - xpd_t *xpd = NULL; - int channels; + xpd_t *xpd = NULL; + int channels; if (to_phone) { XBUS_NOTICE(xbus, - "XPD=%d%d: try to instanciate FXO with reverse direction\n", - unit, subunit); + "XPD=%d%d: try to instanciate FXO with reverse direction\n", + unit, subunit); return NULL; } if (subtype == 2) channels = min(2, subunit_ports); else channels = min(8, subunit_ports); - xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct FXO_priv_data), proto_table, channels); + xpd = + xpd_alloc(xbus, unit, subunit, subtype, subunits, + sizeof(struct FXO_priv_data), proto_table, channels); if (!xpd) return NULL; PHONEDEV(xpd).direction = TO_PSTN; @@ -453,8 +485,8 @@ err: static int FXO_card_init(xbus_t *xbus, xpd_t *xpd) { - struct FXO_priv_data *priv; - int i; + struct FXO_priv_data *priv; + int i; BUG_ON(!xpd); priv = xpd->priv; @@ -494,10 +526,10 @@ static int FXO_card_remove(xbus_t *xbus, xpd_t *xpd) static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; - struct FXO_priv_data *priv; - int i; - unsigned int timer_count; + xbus_t *xbus; + struct FXO_priv_data *priv; + int i; + unsigned int timer_count; BUG_ON(!xpd); xbus = xpd->xbus; @@ -505,14 +537,14 @@ static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on) priv = xpd->priv; BUG_ON(!priv); timer_count = xpd->timer_count; - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF"); PHONEDEV(xpd).span.spantype = "FXO"; for_each_line(xpd, i) { - struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); + struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); XPD_DBG(GENERAL, xpd, "setting FXO channel %d\n", i); snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXO/%02d/%1d%1d/%d", - xbus->num, xpd->addr.unit, xpd->addr.subunit, i); + xbus->num, xpd->addr.unit, xpd->addr.subunit, i); cur_chan->chanpos = i + 1; cur_chan->pvt = xpd; cur_chan->sigcap = FXO_DEFAULT_SIGCAP; @@ -530,16 +562,16 @@ static int FXO_card_dahdi_preregistration(xpd_t *xpd, bool on) static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; - struct FXO_priv_data *priv; - int i; + xbus_t *xbus; + struct FXO_priv_data *priv; + int i; BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"ON":"OFF"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "ON" : "OFF"); for_each_line(xpd, i) { dahdi_report_battery(xpd, i); MARK_OFF(priv, i, LED_GREEN); @@ -552,8 +584,8 @@ static int FXO_card_dahdi_postregistration(xpd_t *xpd, bool on) static int FXO_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) { - struct FXO_priv_data *priv; - int ret = 0; + struct FXO_priv_data *priv; + int ret = 0; priv = xpd->priv; BUG_ON(!priv); @@ -561,40 +593,42 @@ static int FXO_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) BUG_ON(PHONEDEV(xpd).direction != TO_PSTN); /* XXX Enable hooksig for FXO XXX */ switch (txsig) { - case DAHDI_TXSIG_START: - case DAHDI_TXSIG_OFFHOOK: - ret = do_sethook(xpd, pos, 1); - break; - case DAHDI_TXSIG_ONHOOK: - ret = do_sethook(xpd, pos, 0); - break; - default: - XPD_NOTICE(xpd, "Can't set tx state to %s (%d)\n", - txsig2str(txsig), txsig); - return -EINVAL; + case DAHDI_TXSIG_START: + case DAHDI_TXSIG_OFFHOOK: + ret = do_sethook(xpd, pos, 1); + break; + case DAHDI_TXSIG_ONHOOK: + ret = do_sethook(xpd, pos, 0); + break; + default: + XPD_NOTICE(xpd, "Can't set tx state to %s (%d)\n", + txsig2str(txsig), txsig); + return -EINVAL; } return ret; } static void dahdi_report_battery(xpd_t *xpd, lineno_t chan) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; if (SPAN_REGISTERED(xpd)) { switch (priv->battery[chan]) { - case BATTERY_UNKNOWN: - /* no-op */ - break; - case BATTERY_OFF: - LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_RED\n"); - dahdi_alarm_channel(XPD_CHAN(xpd, chan), DAHDI_ALARM_RED); - break; - case BATTERY_ON: - LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_NONE\n"); - dahdi_alarm_channel(XPD_CHAN(xpd, chan), DAHDI_ALARM_NONE); - break; + case BATTERY_UNKNOWN: + /* no-op */ + break; + case BATTERY_OFF: + LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_RED\n"); + dahdi_alarm_channel(XPD_CHAN(xpd, chan), + DAHDI_ALARM_RED); + break; + case BATTERY_ON: + LINE_DBG(SIGNAL, xpd, chan, "Send DAHDI_ALARM_NONE\n"); + dahdi_alarm_channel(XPD_CHAN(xpd, chan), + DAHDI_ALARM_NONE); + break; } } } @@ -607,7 +641,7 @@ static int FXO_card_open(xpd_t *xpd, lineno_t chan) static void poll_battery(xbus_t *xbus, xpd_t *xpd) { - int i; + int i; for_each_line(xpd, i) { DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_REG_VBAT, 0); @@ -617,19 +651,20 @@ static void poll_battery(xbus_t *xbus, xpd_t *xpd) #ifdef WITH_METERING static void poll_metering(xbus_t *xbus, xpd_t *xpd) { - int i; + int i; for_each_line(xpd, i) { if (IS_OFFHOOK(xpd, i)) - DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, DAA_REG_METERING, 0); + DAA_DIRECT_REQUEST(xbus, xpd, i, DAA_READ, + DAA_REG_METERING, 0); } } #endif static void handle_fxo_ring(xpd_t *xpd) { - struct FXO_priv_data *priv; - int i; + struct FXO_priv_data *priv; + int i; priv = xpd->priv; for_each_line(xpd, i) { @@ -647,8 +682,8 @@ static void handle_fxo_ring(xpd_t *xpd) static void handle_fxo_power_denial(xpd_t *xpd) { - struct FXO_priv_data *priv; - int i; + struct FXO_priv_data *priv; + int i; if (!power_denial_safezone) return; /* Ignore power denials */ @@ -663,7 +698,8 @@ static void handle_fxo_power_denial(xpd_t *xpd) /* * Poll current, previous answers are meaningless */ - DAA_DIRECT_REQUEST(xpd->xbus, xpd, i, DAA_READ, DAA_REG_CURRENT, 0); + DAA_DIRECT_REQUEST(xpd->xbus, xpd, i, DAA_READ, + DAA_REG_CURRENT, 0); } continue; } @@ -675,8 +711,10 @@ static void handle_fxo_power_denial(xpd_t *xpd) * detected it yet). This would cause false power denials. * So we just flag it and schedule more ticks to wait. */ - LINE_DBG(SIGNAL, xpd, i, "Possible Power Denial Hangup\n"); - priv->power_denial_delay[i] = POWER_DENIAL_DELAY; + LINE_DBG(SIGNAL, xpd, i, + "Possible Power Denial Hangup\n"); + priv->power_denial_delay[i] = + POWER_DENIAL_DELAY; } continue; } @@ -688,7 +726,8 @@ static void handle_fxo_power_denial(xpd_t *xpd) */ priv->power_denial_delay[i]--; if (priv->power_denial_delay[i] <= 0) { - LINE_DBG(SIGNAL, xpd, i, "Power Denial Hangup\n"); + LINE_DBG(SIGNAL, xpd, i, + "Power Denial Hangup\n"); priv->power_denial_delay[i] = 0; /* * Let Asterisk decide what to do @@ -708,9 +747,9 @@ static void handle_fxo_power_denial(xpd_t *xpd) */ static void check_etsi_dtmf(xpd_t *xpd) { - struct FXO_priv_data *priv; - int portno; - unsigned int timer_count; + struct FXO_priv_data *priv; + int portno; + unsigned int timer_count; if (!SPAN_REGISTERED(xpd)) return; @@ -726,22 +765,25 @@ static void check_etsi_dtmf(xpd_t *xpd) /* reset flags if it's been a while */ priv->cidtimer[portno] = timer_count; BIT_CLR(priv->cidfound, portno); - LINE_DBG(SIGNAL, xpd, portno, "Reset CID flag\n"); + LINE_DBG(SIGNAL, xpd, portno, + "Reset CID flag\n"); } continue; } if (timer_count > priv->cidtimer[portno] + 400) { - struct dahdi_chan *chan = XPD_CHAN(xpd, portno); - int sample; - int i; + struct dahdi_chan *chan = XPD_CHAN(xpd, portno); + int sample; + int i; for (i = 0; i < DAHDI_CHUNKSIZE; i++) { sample = DAHDI_XLAW(chan->readchunk[i], chan); if (sample > 16000 || sample < -16000) { priv->cidtimer[portno] = timer_count; BIT_SET(priv->cidfound, portno); - LINE_DBG(SIGNAL, xpd, portno, "Found DTMF CLIP (%d)\n", i); - dahdi_qevent_lock(chan, DAHDI_EVENT_POLARITY); + LINE_DBG(SIGNAL, xpd, portno, + "Found DTMF CLIP (%d)\n", i); + dahdi_qevent_lock(chan, + DAHDI_EVENT_POLARITY); break; } } @@ -751,15 +793,17 @@ static void check_etsi_dtmf(xpd_t *xpd) static int FXO_card_tick(xbus_t *xbus, xpd_t *xpd) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); - if (poll_battery_interval != 0 && (priv->poll_counter % poll_battery_interval) == 0) + if (poll_battery_interval != 0 + && (priv->poll_counter % poll_battery_interval) == 0) poll_battery(xbus, xpd); #ifdef WITH_METERING - if (poll_metering_interval != 0 && (priv->poll_counter % poll_metering_interval) == 0) + if (poll_metering_interval != 0 + && (priv->poll_counter % poll_metering_interval) == 0) poll_metering(xbus, xpd); #endif handle_fxo_leds(xpd); @@ -777,47 +821,55 @@ static int FXO_card_tick(xbus_t *xbus, xpd_t *xpd) * We define the array size explicitly to track possible inconsistencies * if the struct is modified. */ -static const char echotune_regs[sizeof(struct wctdm_echo_coefs)] = {30, 45, 46, 47, 48, 49, 50, 51, 52}; +static const char echotune_regs[sizeof(struct wctdm_echo_coefs)] = + { 30, 45, 46, 47, 48, 49, 50, 51, 52 }; -static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg) +static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, + unsigned long arg) { - int i, ret; - unsigned char echotune_data[ARRAY_SIZE(echotune_regs)]; + int i, ret; + unsigned char echotune_data[ARRAY_SIZE(echotune_regs)]; BUG_ON(!xpd); if (!XBUS_IS(xpd->xbus, READY)) return -ENODEV; switch (cmd) { - case WCTDM_SET_ECHOTUNE: - XPD_DBG(GENERAL, xpd, "-- Setting echo registers: \n"); - /* first off: check if this span is fxs. If not: -EINVALID */ - if (copy_from_user(&echotune_data, (void __user *)arg, sizeof(echotune_data))) - return -EFAULT; + case WCTDM_SET_ECHOTUNE: + XPD_DBG(GENERAL, xpd, "-- Setting echo registers: \n"); + /* first off: check if this span is fxs. If not: -EINVALID */ + if (copy_from_user + (&echotune_data, (void __user *)arg, sizeof(echotune_data))) + return -EFAULT; - for (i = 0; i < ARRAY_SIZE(echotune_regs); i++) { - XPD_DBG(REGS, xpd, "Reg=0x%02X, data=0x%02X\n", echotune_regs[i], echotune_data[i]); - ret = DAA_DIRECT_REQUEST(xpd->xbus, xpd, pos, DAA_WRITE, echotune_regs[i], echotune_data[i]); - if (ret < 0) { - LINE_NOTICE(xpd, pos, "Couldn't write %0x02X to register %0x02X\n", - echotune_data[i], echotune_regs[i]); - return ret; - } - msleep(1); + for (i = 0; i < ARRAY_SIZE(echotune_regs); i++) { + XPD_DBG(REGS, xpd, "Reg=0x%02X, data=0x%02X\n", + echotune_regs[i], echotune_data[i]); + ret = + DAA_DIRECT_REQUEST(xpd->xbus, xpd, pos, DAA_WRITE, + echotune_regs[i], + echotune_data[i]); + if (ret < 0) { + LINE_NOTICE(xpd, pos, + "Couldn't write %0x02X to register %0x02X\n", + echotune_data[i], echotune_regs[i]); + return ret; } + msleep(1); + } - XPD_DBG(GENERAL, xpd, "-- Set echo registers successfully\n"); - break; - case DAHDI_TONEDETECT: - /* - * Asterisk call all span types with this (FXS specific) - * call. Silently ignore it. - */ - LINE_DBG(GENERAL, xpd, pos, - "DAHDI_TONEDETECT (FXO: NOTIMPLEMENTED)\n"); - return -ENOTTY; - default: - report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); - return -ENOTTY; + XPD_DBG(GENERAL, xpd, "-- Set echo registers successfully\n"); + break; + case DAHDI_TONEDETECT: + /* + * Asterisk call all span types with this (FXS specific) + * call. Silently ignore it. + */ + LINE_DBG(GENERAL, xpd, pos, + "DAHDI_TONEDETECT (FXO: NOTIMPLEMENTED)\n"); + return -ENOTTY; + default: + report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); + return -ENOTTY; } return 0; } @@ -828,11 +880,13 @@ static int FXO_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a HANDLER_DEF(FXO, SIG_CHANGED) { - xpp_line_t sig_status = RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_status); - xpp_line_t sig_toggles = RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_toggles); - unsigned long flags; - int i; - struct FXO_priv_data *priv; + xpp_line_t sig_status = + RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_status); + xpp_line_t sig_toggles = + RPACKET_FIELD(pack, FXO, SIG_CHANGED, sig_toggles); + unsigned long flags; + int i; + struct FXO_priv_data *priv; if (!xpd) { notify_bad_xpd(__func__, xbus, XPACKET_ADDR(pack), cmd->name); @@ -840,10 +894,11 @@ HANDLER_DEF(FXO, SIG_CHANGED) } priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(SIGNAL, xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status); + XPD_DBG(SIGNAL, xpd, "(PSTN) sig_toggles=0x%04X sig_status=0x%04X\n", + sig_toggles, sig_status); spin_lock_irqsave(&xpd->lock, flags); for_each_line(xpd, i) { - int debounce; + int debounce; if (IS_SET(sig_toggles, i)) { if (priv->battery[i] == BATTERY_OFF) { @@ -851,18 +906,23 @@ HANDLER_DEF(FXO, SIG_CHANGED) * With poll_battery_interval==0 we cannot have BATTERY_OFF * so we won't get here */ - LINE_NOTICE(xpd, i, "SIG_CHANGED while battery is off. Ignored.\n"); + LINE_NOTICE(xpd, i, + "SIG_CHANGED while battery is off. Ignored.\n"); continue; } /* First report false ring alarms */ debounce = atomic_read(&priv->ring_debounce[i]); if (debounce) - LINE_NOTICE(xpd, i, "debounced false ring (only %d ticks)\n", debounce); + LINE_NOTICE(xpd, i, + "debounced false ring (only %d ticks)\n", + debounce); /* * Now set a new ring alarm. * It will be checked in handle_fxo_ring() */ - debounce = (IS_SET(sig_status, i)) ? ring_debounce : -ring_debounce; + debounce = + (IS_SET(sig_status, i)) ? ring_debounce : + -ring_debounce; atomic_set(&priv->ring_debounce[i], debounce); } } @@ -872,10 +932,10 @@ HANDLER_DEF(FXO, SIG_CHANGED) static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno) { - struct FXO_priv_data *priv; - enum polarity_state pol; - int msec; - signed char volts = (signed char)data_low; + struct FXO_priv_data *priv; + enum polarity_state pol; + int msec; + signed char volts = (signed char)data_low; priv = xpd->priv; BUG_ON(!priv); @@ -887,12 +947,14 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno) * Check for battery voltage fluctuations */ if (priv->battery[portno] != BATTERY_OFF) { - int milliseconds; + int milliseconds; - milliseconds = priv->nobattery_debounce[portno]++ * - poll_battery_interval; + milliseconds = + priv->nobattery_debounce[portno]++ * + poll_battery_interval; if (milliseconds > battery_debounce) { - LINE_DBG(SIGNAL, xpd, portno, "BATTERY OFF voltage=%d\n", volts); + LINE_DBG(SIGNAL, xpd, portno, + "BATTERY OFF voltage=%d\n", volts); priv->battery[portno] = BATTERY_OFF; dahdi_report_battery(xpd, portno); /* What's the polarity ? */ @@ -910,7 +972,8 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno) } else { priv->nobattery_debounce[portno] = 0; if (priv->battery[portno] != BATTERY_ON) { - LINE_DBG(SIGNAL, xpd, portno, "BATTERY ON voltage=%d\n", volts); + LINE_DBG(SIGNAL, xpd, portno, "BATTERY ON voltage=%d\n", + volts); priv->battery[portno] = BATTERY_ON; dahdi_report_battery(xpd, portno); } @@ -952,7 +1015,7 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno) if (msec >= POLREV_THRESHOLD) { priv->polarity_debounce[portno] = 0; if (pol != POL_UNKNOWN && priv->polarity[portno] != POL_UNKNOWN) { - char *polname = NULL; + char *polname = NULL; if (pol == POL_POSITIVE) polname = "Positive"; @@ -961,7 +1024,7 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno) else BUG(); LINE_DBG(SIGNAL, xpd, portno, - "Polarity changed to %s\n", polname); + "Polarity changed to %s\n", polname); /* * Inform dahdi/Asterisk: * 1. Maybe used for hangup detection during offhook @@ -972,8 +1035,10 @@ static void update_battery_voltage(xpd_t *xpd, __u8 data_low, xportno_t portno) oht_pcm(xpd, portno, 1); /* will be cleared on ring/offhook */ if (SPAN_REGISTERED(xpd)) { LINE_DBG(SIGNAL, xpd, portno, - "Send DAHDI_EVENT_POLARITY: %s\n", polname); - dahdi_qevent_lock(XPD_CHAN(xpd, portno), DAHDI_EVENT_POLARITY); + "Send DAHDI_EVENT_POLARITY: %s\n", + polname); + dahdi_qevent_lock(XPD_CHAN(xpd, portno), + DAHDI_EVENT_POLARITY); } } priv->polarity[portno] = pol; @@ -988,7 +1053,7 @@ ignore_reading: static void update_battery_current(xpd_t *xpd, __u8 data_low, xportno_t portno) { - struct FXO_priv_data *priv; + struct FXO_priv_data *priv; priv = xpd->priv; BUG_ON(!priv); @@ -1030,16 +1095,16 @@ ignore_it: static void update_metering_state(xpd_t *xpd, __u8 data_low, lineno_t portno) { - struct FXO_priv_data *priv; - bool metering_tone = data_low & BTD_BIT; - bool old_metering_tone; + struct FXO_priv_data *priv; + bool metering_tone = data_low & BTD_BIT; + bool old_metering_tone; priv = xpd->priv; BUG_ON(!priv); old_metering_tone = IS_SET(priv->metering_tone_state, portno); LINE_DBG(SIGNAL, xpd, portno, "METERING: %s [dL=0x%X] (%d)\n", - (metering_tone) ? "ON" : "OFF", - data_low, priv->metering_count[portno]); + (metering_tone) ? "ON" : "OFF", data_low, + priv->metering_count[portno]); if (metering_tone && !old_metering_tone) { /* Rising edge */ priv->metering_count[portno]++; @@ -1049,42 +1114,42 @@ static void update_metering_state(xpd_t *xpd, __u8 data_low, lineno_t portno) if (metering_tone) { /* Clear the BTD bit */ data_low &= ~BTD_BIT; - DAA_DIRECT_REQUEST(xpd->xbus, xpd, portno, DAA_WRITE, DAA_REG_METERING, data_low); + DAA_DIRECT_REQUEST(xpd->xbus, xpd, portno, DAA_WRITE, + DAA_REG_METERING, data_low); } } #endif static int FXO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) { - struct FXO_priv_data *priv; - lineno_t portno; + struct FXO_priv_data *priv; + lineno_t portno; priv = xpd->priv; BUG_ON(!priv); portno = info->portnum; switch (REG_FIELD(info, regnum)) { - case DAA_REG_VBAT: - update_battery_voltage(xpd, REG_FIELD(info, data_low), portno); - break; - case DAA_REG_CURRENT: - update_battery_current(xpd, REG_FIELD(info, data_low), portno); - break; + case DAA_REG_VBAT: + update_battery_voltage(xpd, REG_FIELD(info, data_low), portno); + break; + case DAA_REG_CURRENT: + update_battery_current(xpd, REG_FIELD(info, data_low), portno); + break; #ifdef WITH_METERING - case DAA_REG_METERING: - update_metering_state(xpd, REG_FIELD(info, data_low), portno); - break; + case DAA_REG_METERING: + update_metering_state(xpd, REG_FIELD(info, data_low), portno); + break; #endif } LINE_DBG(REGS, xpd, portno, "%c reg_num=0x%X, dataL=0x%X dataH=0x%X\n", - ((info->bytes == 3)?'I':'D'), - REG_FIELD(info, regnum), - REG_FIELD(info, data_low), - REG_FIELD(info, data_high)); + ((info->bytes == 3) ? 'I' : 'D'), REG_FIELD(info, regnum), + REG_FIELD(info, data_low), REG_FIELD(info, data_high)); /* Update /proc info only if reply relate to the last slic read request */ - if ( - REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) && - REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) && - REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) { + if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) + && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, + do_subreg) + && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, + subreg)) { xpd->last_reply = *info; } return 0; @@ -1092,8 +1157,8 @@ static int FXO_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) static int FXO_card_state(xpd_t *xpd, bool on) { - int ret = 0; - struct FXO_priv_data *priv; + int ret = 0; + struct FXO_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -1102,47 +1167,40 @@ static int FXO_card_state(xpd_t *xpd, bool on) return ret; } -static const struct xops fxo_xops = { - .card_new = FXO_card_new, - .card_init = FXO_card_init, - .card_remove = FXO_card_remove, - .card_tick = FXO_card_tick, - .card_register_reply = FXO_card_register_reply, +static const struct xops fxo_xops = { + .card_new = FXO_card_new, + .card_init = FXO_card_init, + .card_remove = FXO_card_remove, + .card_tick = FXO_card_tick, + .card_register_reply = FXO_card_register_reply, }; -static const struct phoneops fxo_phoneops = { - .card_dahdi_preregistration = FXO_card_dahdi_preregistration, - .card_dahdi_postregistration = FXO_card_dahdi_postregistration, - .card_hooksig = FXO_card_hooksig, - .card_pcm_recompute = generic_card_pcm_recompute, - .card_pcm_fromspan = generic_card_pcm_fromspan, - .card_pcm_tospan = generic_card_pcm_tospan, - .card_timing_priority = generic_timing_priority, - .echocancel_timeslot = generic_echocancel_timeslot, - .echocancel_setmask = generic_echocancel_setmask, - .card_ioctl = FXO_card_ioctl, - .card_open = FXO_card_open, - .card_state = FXO_card_state, +static const struct phoneops fxo_phoneops = { + .card_dahdi_preregistration = FXO_card_dahdi_preregistration, + .card_dahdi_postregistration = FXO_card_dahdi_postregistration, + .card_hooksig = FXO_card_hooksig, + .card_pcm_recompute = generic_card_pcm_recompute, + .card_pcm_fromspan = generic_card_pcm_fromspan, + .card_pcm_tospan = generic_card_pcm_tospan, + .card_timing_priority = generic_timing_priority, + .echocancel_timeslot = generic_echocancel_timeslot, + .echocancel_setmask = generic_echocancel_setmask, + .card_ioctl = FXO_card_ioctl, + .card_open = FXO_card_open, + .card_state = FXO_card_state, }; static xproto_table_t PROTO_TABLE(FXO) = { - .owner = THIS_MODULE, - .entries = { - /* Prototable Card Opcode */ - XENTRY( FXO, FXO, SIG_CHANGED ), - }, - .name = "FXO", /* protocol name */ - .ports_per_subunit = 8, - .type = XPD_TYPE_FXO, - .xops = &fxo_xops, - .phoneops = &fxo_phoneops, - .packet_is_valid = fxo_packet_is_valid, - .packet_dump = fxo_packet_dump, -}; + .owner = THIS_MODULE,.entries = { + /* Prototable Card Opcode */ + XENTRY(FXO, FXO, SIG_CHANGED),},.name = "FXO", /* protocol name */ +.ports_per_subunit = 8,.type = XPD_TYPE_FXO,.xops = + &fxo_xops,.phoneops = &fxo_phoneops,.packet_is_valid = + fxo_packet_is_valid,.packet_dump = fxo_packet_dump,}; static bool fxo_packet_is_valid(xpacket_t *pack) { - const xproto_entry_t *xe; + const xproto_entry_t *xe; //DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(FXO), XPACKET_OP(pack)); @@ -1157,13 +1215,14 @@ static void fxo_packet_dump(const char *msg, xpacket_t *pack) /*------------------------- DAA Handling --------------------------*/ #ifdef CONFIG_PROC_FS -static int proc_fxo_info_read(char *page, char **start, off_t off, int count, int *eof, void *data) +static int proc_fxo_info_read(char *page, char **start, off_t off, int count, + int *eof, void *data) { - int len = 0; - unsigned long flags; - xpd_t *xpd = data; - struct FXO_priv_data *priv; - int i; + int len = 0; + unsigned long flags; + xpd_t *xpd = data; + struct FXO_priv_data *priv; + int i; if (!xpd) return -ENODEV; @@ -1172,23 +1231,28 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in BUG_ON(!priv); len += sprintf(page + len, "\t%-17s: ", "Channel"); for_each_line(xpd, i) { - if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) + if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) + && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) len += sprintf(page + len, "%4d ", i % 10); } len += sprintf(page + len, "\nLeds:"); len += sprintf(page + len, "\n\t%-17s: ", "state"); for_each_line(xpd, i) { - if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) - len += sprintf(page + len, " %d%d ", - IS_SET(priv->ledstate[LED_GREEN], i), - IS_SET(priv->ledstate[LED_RED], i)); + if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) + && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) + len += + sprintf(page + len, " %d%d ", + IS_SET(priv->ledstate[LED_GREEN], i), + IS_SET(priv->ledstate[LED_RED], i)); } len += sprintf(page + len, "\n\t%-17s: ", "blinking"); for_each_line(xpd, i) { - if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) - len += sprintf(page + len, " %d%d ", - IS_BLINKING(priv, i, LED_GREEN), - IS_BLINKING(priv, i, LED_RED)); + if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) + && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) + len += + sprintf(page + len, " %d%d ", + IS_BLINKING(priv, i, LED_GREEN), + IS_BLINKING(priv, i, LED_RED)); } len += sprintf(page + len, "\nBattery-Data:"); len += sprintf(page + len, "\n\t%-17s: ", "voltage"); @@ -1202,7 +1266,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in len += sprintf(page + len, "\nBattery:"); len += sprintf(page + len, "\n\t%-17s: ", "on"); for_each_line(xpd, i) { - char *bat; + char *bat; if (priv->battery[i] == BATTERY_ON) bat = "+"; @@ -1219,7 +1283,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in len += sprintf(page + len, "\nPolarity-Reverse:"); len += sprintf(page + len, "\n\t%-17s: ", "polarity"); for_each_line(xpd, i) { - char *polname; + char *polname; if (priv->polarity[i] == POL_POSITIVE) polname = "+"; @@ -1236,7 +1300,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in len += sprintf(page + len, "\nPower-Denial:"); len += sprintf(page + len, "\n\t%-17s: ", "power"); for_each_line(xpd, i) { - char *curr; + char *curr; if (priv->power[i] == POWER_ON) curr = "+"; @@ -1248,7 +1312,8 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in } len += sprintf(page + len, "\n\t%-17s: ", "safezone"); for_each_line(xpd, i) { - len += sprintf(page + len, "%4d ", priv->power_denial_safezone[i]); + len += + sprintf(page + len, "%4d ", priv->power_denial_safezone[i]); } len += sprintf(page + len, "\n\t%-17s: ", "delay"); for_each_line(xpd, i) { @@ -1263,7 +1328,7 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in #endif len += sprintf(page + len, "\n"); spin_unlock_irqrestore(&xpd->lock, flags); - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1276,13 +1341,14 @@ static int proc_fxo_info_read(char *page, char **start, off_t off, int count, in #endif #ifdef WITH_METERING -static int proc_xpd_metering_read(char *page, char **start, off_t off, int count, int *eof, void *data) +static int proc_xpd_metering_read(char *page, char **start, off_t off, + int count, int *eof, void *data) { - int len = 0; - unsigned long flags; - xpd_t *xpd = data; - struct FXO_priv_data *priv; - int i; + int len = 0; + unsigned long flags; + xpd_t *xpd = data; + struct FXO_priv_data *priv; + int i; if (!xpd) return -ENODEV; @@ -1291,11 +1357,11 @@ static int proc_xpd_metering_read(char *page, char **start, off_t off, int count spin_lock_irqsave(&xpd->lock, flags); len += sprintf(page + len, "# Chan\tMeter (since last read)\n"); for_each_line(xpd, i) { - len += sprintf(page + len, "%d\t%d\n", - i, priv->metering_count[i]); + len += + sprintf(page + len, "%d\t%d\n", i, priv->metering_count[i]); } spin_unlock_irqrestore(&xpd->lock, flags); - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1305,18 +1371,18 @@ static int proc_xpd_metering_read(char *page, char **start, off_t off, int count len = 0; /* Zero meters */ for_each_line(xpd, i) - priv->metering_count[i] = 0; + priv->metering_count[i] = 0; return len; } #endif static DEVICE_ATTR_READER(fxo_battery_show, dev, buf) { - xpd_t *xpd; - struct FXO_priv_data *priv; - unsigned long flags; - int len = 0; - int i; + xpd_t *xpd; + struct FXO_priv_data *priv; + unsigned long flags; + int len = 0; + int i; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -1326,7 +1392,7 @@ static DEVICE_ATTR_READER(fxo_battery_show, dev, buf) BUG_ON(!priv); spin_lock_irqsave(&xpd->lock, flags); for_each_line(xpd, i) { - char bat; + char bat; if (priv->battery[i] == BATTERY_ON) bat = '+'; @@ -1341,25 +1407,25 @@ static DEVICE_ATTR_READER(fxo_battery_show, dev, buf) return len; } -static DEVICE_ATTR(fxo_battery, S_IRUGO, fxo_battery_show, NULL); - +static DEVICE_ATTR(fxo_battery, S_IRUGO, fxo_battery_show, NULL); static int fxo_xpd_probe(struct device *dev) { - xpd_t *xpd; - int ret; + xpd_t *xpd; + int ret; xpd = dev_to_xpd(dev); /* Is it our device? */ if (xpd->type != XPD_TYPE_FXO) { - XPD_ERR(xpd, "drop suggestion for %s (%d)\n", - dev_name(dev), xpd->type); + XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev), + xpd->type); return -EINVAL; } XPD_DBG(DEVICES, xpd, "SYSFS\n"); ret = device_create_file(dev, &dev_attr_fxo_battery); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(fxo_battery) failed: %d\n", __func__, ret); + XPD_ERR(xpd, "%s: device_create_file(fxo_battery) failed: %d\n", + __func__, ret); goto fail_fxo_battery; } return 0; @@ -1369,7 +1435,7 @@ fail_fxo_battery: static int fxo_xpd_remove(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; xpd = dev_to_xpd(dev); XPD_DBG(DEVICES, xpd, "SYSFS\n"); @@ -1377,24 +1443,24 @@ static int fxo_xpd_remove(struct device *dev) return 0; } -static struct xpd_driver fxo_driver = { - .type = XPD_TYPE_FXO, - .driver = { - .name = "fxo", +static struct xpd_driver fxo_driver = { + .type = XPD_TYPE_FXO, + .driver = { + .name = "fxo", #ifndef OLD_HOTPLUG_SUPPORT - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .probe = fxo_xpd_probe, - .remove = fxo_xpd_remove - } + .probe = fxo_xpd_probe, + .remove = fxo_xpd_remove} }; static int __init card_fxo_startup(void) { - int ret; + int ret; if (ring_debounce <= 0) { - ERR("ring_debounce=%d. Must be positive number of ticks\n", ring_debounce); + ERR("ring_debounce=%d. Must be positive number of ticks\n", + ring_debounce); return -EINVAL; } if ((ret = xpd_driver_register(&fxo_driver.driver)) < 0) diff --git a/drivers/dahdi/xpp/card_fxo.h b/drivers/dahdi/xpp/card_fxo.h index f6f020f..f7289d3 100644 --- a/drivers/dahdi/xpp/card_fxo.h +++ b/drivers/dahdi/xpp/card_fxo.h @@ -25,17 +25,14 @@ #include "xpd.h" enum fxo_opcodes { - XPROTO_NAME(FXO, SIG_CHANGED) = 0x06, -/**/ - XPROTO_NAME(FXO, DAA_WRITE) = 0x0F, /* Write to DAA */ - XPROTO_NAME(FXO, CHAN_CID) = 0x0F, /* Write to DAA */ - XPROTO_NAME(FXO, LED) = 0x0F, /* Write to DAA */ + XPROTO_NAME(FXO, SIG_CHANGED) = 0x06, + /**/ XPROTO_NAME(FXO, DAA_WRITE) = 0x0F, /* Write to DAA */ + XPROTO_NAME(FXO, CHAN_CID) = 0x0F, /* Write to DAA */ + XPROTO_NAME(FXO, LED) = 0x0F, /* Write to DAA */ }; +DEF_RPACKET_DATA(FXO, SIG_CHANGED, xpp_line_t sig_status; /* channels: lsb=1, msb=8 */ + xpp_line_t sig_toggles; /* channels: lsb=1, msb=8 */ + ); -DEF_RPACKET_DATA(FXO, SIG_CHANGED, - xpp_line_t sig_status; /* channels: lsb=1, msb=8 */ - xpp_line_t sig_toggles; /* channels: lsb=1, msb=8 */ - ); - -#endif /* CARD_FXO_H */ +#endif /* CARD_FXO_H */ diff --git a/drivers/dahdi/xpp/card_fxs.c b/drivers/dahdi/xpp/card_fxs.c index 94270ba..f894d6a 100644 --- a/drivers/dahdi/xpp/card_fxs.c +++ b/drivers/dahdi/xpp/card_fxs.c @@ -40,7 +40,8 @@ static DEF_PARM_BOOL(dtmf_detection, 1, 0644, "Do DTMF detection in hardware"); static DEF_PARM(uint, poll_digital_inputs, 1000, 0644, "Poll Digital Inputs"); #endif -static DEF_PARM_BOOL(vmwi_ioctl, 1, 0644, "Asterisk support VMWI notification via ioctl"); +static DEF_PARM_BOOL(vmwi_ioctl, 1, 0644, + "Asterisk support VMWI notification via ioctl"); static DEF_PARM_BOOL(ring_trapez, 0, 0664, "Use trapezoid ring type"); /* Signaling is opposite (fxo signalling for fxs card) */ @@ -79,14 +80,14 @@ enum fxs_leds { /* Values of SLIC linefeed control register (0x40) */ enum fxs_state { - FXS_LINE_OPEN = 0x00, /* Open */ - FXS_LINE_ACTIVE = 0x01, /* Forward active */ - FXS_LINE_OHTRANS = 0x02, /* Forward on-hook transmission */ - FXS_LINE_TIPOPEN = 0x03, /* TIP open */ - FXS_LINE_RING = 0x04, /* Ringing */ - FXS_LINE_REV_ACTIVE = 0x05, /* Reverse active */ - FXS_LINE_REV_OHTRANS = 0x06, /* Reverse on-hook transmission */ - FXS_LINE_RING_OPEN = 0x07 /* RING open */ + FXS_LINE_OPEN = 0x00, /* Open */ + FXS_LINE_ACTIVE = 0x01, /* Forward active */ + FXS_LINE_OHTRANS = 0x02, /* Forward on-hook transmission */ + FXS_LINE_TIPOPEN = 0x03, /* TIP open */ + FXS_LINE_RING = 0x04, /* Ringing */ + FXS_LINE_REV_ACTIVE = 0x05, /* Reverse active */ + FXS_LINE_REV_OHTRANS = 0x06, /* Reverse on-hook transmission */ + FXS_LINE_RING_OPEN = 0x07 /* RING open */ }; #define FXS_LINE_POL_ACTIVE ((reversepolarity) ? FXS_LINE_REV_ACTIVE : FXS_LINE_ACTIVE) @@ -108,9 +109,11 @@ enum fxs_state { static bool fxs_packet_is_valid(xpacket_t *pack); static void fxs_packet_dump(const char *msg, xpacket_t *pack); #ifdef CONFIG_PROC_FS -static int proc_fxs_info_read(char *page, char **start, off_t off, int count, int *eof, void *data); +static int proc_fxs_info_read(char *page, char **start, off_t off, int count, + int *eof, void *data); #ifdef WITH_METERING -static int proc_xpd_metering_write(struct file *file, const char __user *buffer, unsigned long count, void *data); +static int proc_xpd_metering_write(struct file *file, const char __user *buffer, + unsigned long count, void *data); #endif #endif static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos); @@ -123,25 +126,25 @@ static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos); struct FXS_priv_data { #ifdef WITH_METERING - struct proc_dir_entry *meteringfile; + struct proc_dir_entry *meteringfile; #endif - struct proc_dir_entry *fxs_info; - xpp_line_t ledstate[NUM_LEDS]; /* 0 - OFF, 1 - ON */ - xpp_line_t ledcontrol[NUM_LEDS]; /* 0 - OFF, 1 - ON */ - xpp_line_t search_fsk_pattern; - xpp_line_t found_fsk_pattern; - xpp_line_t update_offhook_state; - xpp_line_t want_dtmf_events; /* what dahdi want */ - xpp_line_t want_dtmf_mute; /* what dahdi want */ - xpp_line_t prev_key_down; /* DTMF down sets the bit */ - xpp_line_t neon_blinking; - struct timeval prev_key_time[CHANNELS_PERXPD]; - int led_counter[NUM_LEDS][CHANNELS_PERXPD]; - int ohttimer[CHANNELS_PERXPD]; + struct proc_dir_entry *fxs_info; + xpp_line_t ledstate[NUM_LEDS]; /* 0 - OFF, 1 - ON */ + xpp_line_t ledcontrol[NUM_LEDS]; /* 0 - OFF, 1 - ON */ + xpp_line_t search_fsk_pattern; + xpp_line_t found_fsk_pattern; + xpp_line_t update_offhook_state; + xpp_line_t want_dtmf_events; /* what dahdi want */ + xpp_line_t want_dtmf_mute; /* what dahdi want */ + xpp_line_t prev_key_down; /* DTMF down sets the bit */ + xpp_line_t neon_blinking; + struct timeval prev_key_time[CHANNELS_PERXPD]; + int led_counter[NUM_LEDS][CHANNELS_PERXPD]; + int ohttimer[CHANNELS_PERXPD]; #define OHT_TIMER 6000 /* How long after RING to retain OHT */ - enum fxs_state idletxhookstate[CHANNELS_PERXPD]; /* IDLE changing hook state */ - enum fxs_state lasttxhook[CHANNELS_PERXPD]; - struct dahdi_vmwi_info vmwisetting[CHANNELS_PERXPD]; + enum fxs_state idletxhookstate[CHANNELS_PERXPD]; /* IDLE changing hook state */ + enum fxs_state lasttxhook[CHANNELS_PERXPD]; + struct dahdi_vmwi_info vmwisetting[CHANNELS_PERXPD]; }; /* @@ -157,9 +160,10 @@ struct FXS_priv_data { #define LED_BLINK_RING (1000/8) /* in ticks */ /*---------------- FXS: Static functions ----------------------------------*/ -static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan, enum fxs_state value) +static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan, + enum fxs_state value) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; priv = xpd->priv; LINE_DBG(SIGNAL, xpd, chan, "value=0x%02X\n", value); @@ -169,17 +173,18 @@ static int linefeed_control(xbus_t *xbus, xpd_t *xpd, lineno_t chan, enum fxs_st static int do_chan_power(xbus_t *xbus, xpd_t *xpd, lineno_t chan, bool on) { - int value = (on) ? REG_BATTERY_BATSL : 0x00; + int value = (on) ? REG_BATTERY_BATSL : 0x00; BUG_ON(!xbus); BUG_ON(!xpd); LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "up" : "down"); - return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_BATTERY, value); + return SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_BATTERY, + value); } static void vmwi_search(xpd_t *xpd, lineno_t pos, bool on) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; priv = xpd->priv; BUG_ON(!xpd); @@ -215,9 +220,9 @@ static void vmwi_search(xpd_t *xpd, lineno_t pos, bool on) * The OUTPUT RELAY (actually a relay out) is connected to line 0 and 4 only. */ -// GREEN RED OUTPUT RELAY -static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) }; -static const int led_register_vals[] = { BIT(4), BIT(1), BIT(0) }; +// GREEN RED OUTPUT RELAY +static const int led_register_mask[] = { BIT(7), BIT(6), BIT(5) }; +static const int led_register_vals[] = { BIT(4), BIT(1), BIT(0) }; /* * pos can be: @@ -226,17 +231,18 @@ static const int led_register_vals[] = { BIT(4), BIT(1), BIT(0) }; */ static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on) { - int ret = 0; - struct FXS_priv_data *priv; - int value; - xbus_t *xbus; + int ret = 0; + struct FXS_priv_data *priv; + int value; + xbus_t *xbus; BUG_ON(!xpd); BUG_ON(chan == ALL_LINES); xbus = xpd->xbus; priv = xpd->priv; which = which % NUM_LEDS; - if (IS_SET(PHONEDEV(xpd).digital_outputs, chan) || IS_SET(PHONEDEV(xpd).digital_inputs, chan)) + if (IS_SET(PHONEDEV(xpd).digital_outputs, chan) + || IS_SET(PHONEDEV(xpd).digital_inputs, chan)) goto out; if (chan == PORT_BROADCAST) { priv->ledstate[which] = (on) ? ~0 : 0; @@ -247,50 +253,63 @@ static int do_led(xpd_t *xpd, lineno_t chan, __u8 which, bool on) BIT_CLR(priv->ledstate[which], chan); } } - LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, (on) ? "on" : "off"); + LINE_DBG(LEDS, xpd, chan, "LED: which=%d -- %s\n", which, + (on) ? "on" : "off"); value = BIT(2) | BIT(3); value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[which]); if (on) value |= led_register_vals[which]; - ret = SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, - REG_DIGITAL_IOCTRL, value); + ret = + SLIC_DIRECT_REQUEST(xbus, xpd, chan, SLIC_WRITE, REG_DIGITAL_IOCTRL, + value); out: return ret; } static void handle_fxs_leds(xpd_t *xpd) { - int i; - const enum fxs_leds colors[] = { LED_GREEN, LED_RED }; - enum fxs_leds color; - unsigned int timer_count; - struct FXS_priv_data *priv; + int i; + const enum fxs_leds colors[] = { LED_GREEN, LED_RED }; + enum fxs_leds color; + unsigned int timer_count; + struct FXS_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; timer_count = xpd->timer_count; for (color = 0; color < ARRAY_SIZE(colors); color++) { for_each_line(xpd, i) { - if (IS_SET(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, i)) + if (IS_SET + (PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd). + digital_inputs, i)) continue; - if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) { // Blinking - int mod_value = LED_COUNTER(priv, i, color); + if ((xpd->blink_mode & BIT(i)) || IS_BLINKING(priv, i, color)) { // Blinking + int mod_value = LED_COUNTER(priv, i, color); if (!mod_value) - mod_value = DEFAULT_LED_PERIOD; /* safety value */ + mod_value = DEFAULT_LED_PERIOD; /* safety value */ // led state is toggled if ((timer_count % mod_value) == 0) { - LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", (IS_SET(priv->ledstate[color], i))?"ON":"OFF"); + LINE_DBG(LEDS, xpd, i, "ledstate=%s\n", + (IS_SET + (priv->ledstate[color], + i)) ? "ON" : "OFF"); if (!IS_SET(priv->ledstate[color], i)) { do_led(xpd, i, color, 1); } else { do_led(xpd, i, color, 0); } } - } else if (IS_SET(priv->ledcontrol[color] & ~priv->ledstate[color], i)) { - do_led(xpd, i, color, 1); - } else if (IS_SET(~priv->ledcontrol[color] & priv->ledstate[color], i)) { - do_led(xpd, i, color, 0); + } else + if (IS_SET + (priv->ledcontrol[color] & ~priv-> + ledstate[color], i)) { + do_led(xpd, i, color, 1); + } else + if (IS_SET + (~priv->ledcontrol[color] & priv-> + ledstate[color], i)) { + do_led(xpd, i, color, 0); } } @@ -299,8 +318,8 @@ static void handle_fxs_leds(xpd_t *xpd) static void restore_leds(xpd_t *xpd) { - struct FXS_priv_data *priv; - int i; + struct FXS_priv_data *priv; + int i; priv = xpd->priv; for_each_line(xpd, i) { @@ -314,10 +333,12 @@ static void restore_leds(xpd_t *xpd) #ifdef WITH_METERING static int metering_gen(xpd_t *xpd, lineno_t chan, bool on) { - __u8 value = (on) ? 0x94 : 0x00; + __u8 value = (on) ? 0x94 : 0x00; - LINE_DBG(SIGNAL, xpd, chan, "METERING Generate: %s\n", (on)?"ON":"OFF"); - return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, chan, SLIC_WRITE, 0x23, value); + LINE_DBG(SIGNAL, xpd, chan, "METERING Generate: %s\n", + (on) ? "ON" : "OFF"); + return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, chan, SLIC_WRITE, 0x23, + value); } #endif @@ -325,7 +346,7 @@ static int metering_gen(xpd_t *xpd, lineno_t chan, bool on) static void fxs_proc_remove(xbus_t *xbus, xpd_t *xpd) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -348,25 +369,30 @@ static void fxs_proc_remove(xbus_t *xbus, xpd_t *xpd) static int fxs_proc_create(xbus_t *xbus, xpd_t *xpd) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; #ifdef CONFIG_PROC_FS XPD_DBG(PROC, xpd, "Creating FXS_INFO file\n"); - priv->fxs_info = create_proc_read_entry(PROC_FXS_INFO_FNAME, 0444, xpd->proc_xpd_dir, proc_fxs_info_read, xpd); + priv->fxs_info = + create_proc_read_entry(PROC_FXS_INFO_FNAME, 0444, xpd->proc_xpd_dir, + proc_fxs_info_read, xpd); if (!priv->fxs_info) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_FXS_INFO_FNAME); + XPD_ERR(xpd, "Failed to create proc file '%s'\n", + PROC_FXS_INFO_FNAME); fxs_proc_remove(xbus, xpd); return -EINVAL; } SET_PROC_DIRENTRY_OWNER(priv->fxs_info); #ifdef WITH_METERING XPD_DBG(PROC, xpd, "Creating Metering tone file\n"); - priv->meteringfile = create_proc_entry(PROC_METERING_FNAME, 0200, xpd->proc_xpd_dir); + priv->meteringfile = + create_proc_entry(PROC_METERING_FNAME, 0200, xpd->proc_xpd_dir); if (!priv->meteringfile) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_METERING_FNAME); + XPD_ERR(xpd, "Failed to create proc file '%s'\n", + PROC_METERING_FNAME); fxs_proc_remove(xbus, xpd); return -EINVAL; } @@ -379,21 +405,22 @@ static int fxs_proc_create(xbus_t *xbus, xpd_t *xpd) return 0; } -static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, - __u8 subtype, int subunits, int subunit_ports, bool to_phone) +static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit, + const xproto_table_t *proto_table, __u8 subtype, + int subunits, int subunit_ports, bool to_phone) { - xpd_t *xpd = NULL; - int channels; - int regular_channels; - struct FXS_priv_data *priv; - int i; - int d_inputs = 0; - int d_outputs = 0; + xpd_t *xpd = NULL; + int channels; + int regular_channels; + struct FXS_priv_data *priv; + int i; + int d_inputs = 0; + int d_outputs = 0; if (!to_phone) { XBUS_NOTICE(xbus, - "XPD=%d%d: try to instanciate FXS with reverse direction\n", - unit, subunit); + "XPD=%d%d: try to instanciate FXS with reverse direction\n", + unit, subunit); return NULL; } if (subtype == 2) @@ -407,22 +434,24 @@ static xpd_t *FXS_card_new(xbus_t *xbus, int unit, int subunit, const xproto_tab d_inputs = LINES_DIGI_INP; d_outputs = LINES_DIGI_OUT; } - xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct FXS_priv_data), proto_table, channels); + xpd = + xpd_alloc(xbus, unit, subunit, subtype, subunits, + sizeof(struct FXS_priv_data), proto_table, channels); if (!xpd) return NULL; /* Initialize digital inputs/outputs */ if (d_inputs) { XBUS_DBG(GENERAL, xbus, "Initialize %d digital inputs\n", - d_inputs); + d_inputs); PHONEDEV(xpd).digital_inputs = - BITMASK(d_inputs) << (regular_channels + d_outputs); + BITMASK(d_inputs) << (regular_channels + d_outputs); } else XBUS_DBG(GENERAL, xbus, "No digital inputs\n"); if (d_outputs) { XBUS_DBG(GENERAL, xbus, "Initialize %d digital outputs\n", - d_outputs); + d_outputs); PHONEDEV(xpd).digital_outputs = - BITMASK(d_outputs) << regular_channels; + BITMASK(d_outputs) << regular_channels; } else XBUS_DBG(GENERAL, xbus, "No digital outputs\n"); PHONEDEV(xpd).direction = TO_PHONE; @@ -441,8 +470,8 @@ err: static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) { - int ret = 0; - int i; + int ret = 0; + int i; BUG_ON(!xpd); /* @@ -476,9 +505,12 @@ static int FXS_card_init(xbus_t *xbus, xpd_t *xpd) * So we do this after the LEDs */ for_each_line(xpd, i) { - if (IS_SET(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, i)) + if (IS_SET + (PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd). + digital_inputs, i)) continue; - SLIC_DIRECT_REQUEST(xbus, xpd, i, SLIC_READ, REG_LOOPCLOSURE, 0); + SLIC_DIRECT_REQUEST(xbus, xpd, i, SLIC_READ, REG_LOOPCLOSURE, + 0); } return 0; err: @@ -497,30 +529,33 @@ static int FXS_card_remove(xbus_t *xbus, xpd_t *xpd) static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; - struct FXS_priv_data *priv; - int i; + xbus_t *xbus; + struct FXS_priv_data *priv; + int i; BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); PHONEDEV(xpd).span.spantype = "FXS"; for_each_line(xpd, i) { - struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); + struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); XPD_DBG(GENERAL, xpd, "setting FXS channel %d\n", i); if (IS_SET(PHONEDEV(xpd).digital_outputs, i)) { - snprintf(cur_chan->name, MAX_CHANNAME, "XPP_OUT/%02d/%1d%1d/%d", - xbus->num, xpd->addr.unit, xpd->addr.subunit, i); + snprintf(cur_chan->name, MAX_CHANNAME, + "XPP_OUT/%02d/%1d%1d/%d", xbus->num, + xpd->addr.unit, xpd->addr.subunit, i); } else if (IS_SET(PHONEDEV(xpd).digital_inputs, i)) { - snprintf(cur_chan->name, MAX_CHANNAME, "XPP_IN/%02d/%1d%1d/%d", - xbus->num, xpd->addr.unit, xpd->addr.subunit, i); + snprintf(cur_chan->name, MAX_CHANNAME, + "XPP_IN/%02d/%1d%1d/%d", xbus->num, + xpd->addr.unit, xpd->addr.subunit, i); } else { - snprintf(cur_chan->name, MAX_CHANNAME, "XPP_FXS/%02d/%1d%1d/%d", - xbus->num, xpd->addr.unit, xpd->addr.subunit, i); + snprintf(cur_chan->name, MAX_CHANNAME, + "XPP_FXS/%02d/%1d%1d/%d", xbus->num, + xpd->addr.unit, xpd->addr.subunit, i); } cur_chan->chanpos = i + 1; cur_chan->pvt = xpd; @@ -540,16 +575,16 @@ static int FXS_card_dahdi_preregistration(xpd_t *xpd, bool on) static int FXS_card_dahdi_postregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; - struct FXS_priv_data *priv; - int i; + xbus_t *xbus; + struct FXS_priv_data *priv; + int i; BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); priv = xpd->priv; BUG_ON(!priv); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); for_each_line(xpd, i) { MARK_OFF(priv, i, LED_GREEN); msleep(2); @@ -565,7 +600,7 @@ static int FXS_card_dahdi_postregistration(xpd_t *xpd, bool on) */ static void __do_mute_dtmf(xpd_t *xpd, int pos, bool muteit) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; priv = xpd->priv; LINE_DBG(SIGNAL, xpd, pos, "%s\n", (muteit) ? "MUTE" : "UNMUTE"); @@ -578,10 +613,10 @@ static void __do_mute_dtmf(xpd_t *xpd, int pos, bool muteit) } static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos, - unsigned int msg_waiting) + unsigned int msg_waiting) { - int ret = 0; - struct FXS_priv_data *priv; + int ret = 0; + struct FXS_priv_data *priv; BUG_ON(!xbus); BUG_ON(!xpd); @@ -590,108 +625,141 @@ static int set_vm_led_mode(xbus_t *xbus, xpd_t *xpd, int pos, /* A write to register 0x40 will now turn on/off the VM led */ LINE_DBG(SIGNAL, xpd, pos, "NEON\n"); BIT_SET(priv->neon_blinking, pos); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, 0xE8, 0x03); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, 0xEF, 0x7B); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, 0x9F, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x19); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0xE0); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x01); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0xF0); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x05); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, 0x00, 0x46); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, + 0xE8, 0x03); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, + 0xEF, 0x7B); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, + 0x9F, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x19); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0xE0); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x01); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0xF0); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x05); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, + 0x00, 0x46); } else if (ring_trapez) { LINE_DBG(SIGNAL, xpd, pos, "RINGER: Trapez ring\n"); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x16, 0xC8, 0x00); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x15, 0xAB, 0x5E); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x14, 0x8C, 0x01); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x22, 0x01); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x4A, 0x34); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x30, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x31, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x32, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x33, 0x00); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, - SLIC_WRITE, 0x1D, 0x00, 0x36); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, + 0xC8, 0x00); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, + 0xAB, 0x5E); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, + 0x8C, 0x01); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x01); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x4A, 0x34); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x00); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, + 0x00, 0x36); } else { /* A write to register 0x40 will now turn on/off the ringer */ LINE_DBG(SIGNAL, xpd, pos, "RINGER\n"); BIT_CLR(priv->neon_blinking, pos); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, 0x00, 0x00); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, 0x77, 0x01); - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, 0xFD, 0x7E); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x16, + 0x00, 0x00); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x15, + 0x77, 0x01); + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x14, + 0xFD, 0x7E); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x00); - ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, - 0x4A, 0x34);/* High Vbat~ -82V[Dc] */ - ret += SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, 0x00, 0x36); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x22, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x30, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x31, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x32, 0x00); + ret += + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x33, 0x00); + ret += SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x4A, 0x34); /* High Vbat~ -82V[Dc] */ + ret += + SLIC_INDIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x1D, + 0x00, 0x36); } return (ret ? -EPROTO : 0); } static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos) { - struct FXS_priv_data *priv; - unsigned int msgs; + struct FXS_priv_data *priv; + unsigned int msgs; BUG_ON(!xpd); - if (IS_SET(PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, pos)) + if (IS_SET + (PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs, pos)) return; priv = xpd->priv; msgs = PHONEDEV(xpd).msg_waiting[pos]; LINE_DBG(SIGNAL, xpd, pos, "%s\n", (msgs) ? "ON" : "OFF"); set_vm_led_mode(xbus, xpd, pos, msgs); do_chan_power(xbus, xpd, pos, msgs > 0); - linefeed_control(xbus, xpd, pos, (msgs > 0) ? - FXS_LINE_RING : priv->idletxhookstate[pos]); + linefeed_control(xbus, xpd, pos, + (msgs > + 0) ? FXS_LINE_RING : priv->idletxhookstate[pos]); } static int relay_out(xpd_t *xpd, int pos, bool on) { - int value; - int which = pos; - int relay_channels[] = { 0, 4 }; + int value; + int which = pos; + int relay_channels[] = { 0, 4 }; BUG_ON(!xpd); /* map logical position to output port number (0/1) */ which -= (xpd->subtype == 2) ? 6 : 8; - LINE_DBG(SIGNAL, xpd, pos, "which=%d -- %s\n", which, (on) ? "on" : "off"); + LINE_DBG(SIGNAL, xpd, pos, "which=%d -- %s\n", which, + (on) ? "on" : "off"); which = which % ARRAY_SIZE(relay_channels); value = BIT(2) | BIT(3); - value |= ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[OUTPUT_RELAY]); + value |= + ((BIT(5) | BIT(6) | BIT(7)) & ~led_register_mask[OUTPUT_RELAY]); if (on) value |= led_register_vals[OUTPUT_RELAY]; return SLIC_DIRECT_REQUEST(xpd->xbus, xpd, relay_channels[which], - SLIC_WRITE, REG_DIGITAL_IOCTRL, value); + SLIC_WRITE, REG_DIGITAL_IOCTRL, value); } static int send_ring(xpd_t *xpd, lineno_t chan, bool on) { - int ret = 0; - xbus_t *xbus; - struct FXS_priv_data *priv; - enum fxs_state value = (on) ? FXS_LINE_RING : FXS_LINE_POL_ACTIVE; + int ret = 0; + xbus_t *xbus; + struct FXS_priv_data *priv; + enum fxs_state value = (on) ? FXS_LINE_RING : FXS_LINE_POL_ACTIVE; BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); - LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on)?"on":"off"); + LINE_DBG(SIGNAL, xpd, chan, "%s\n", (on) ? "on" : "off"); priv = xpd->priv; set_vm_led_mode(xbus, xpd, chan, 0); - do_chan_power(xbus, xpd, chan, on); // Power up (for ring) + do_chan_power(xbus, xpd, chan, on); // Power up (for ring) ret = linefeed_control(xbus, xpd, chan, value); if (on) { MARK_BLINK(priv, chan, LED_GREEN, LED_BLINK_RING); @@ -704,148 +772,155 @@ static int send_ring(xpd_t *xpd, lineno_t chan, bool on) static int FXS_card_hooksig(xpd_t *xpd, int pos, enum dahdi_txsig txsig) { - struct FXS_priv_data *priv; - int ret = 0; - struct dahdi_chan *chan = NULL; - enum fxs_state txhook; - unsigned long flags; + struct FXS_priv_data *priv; + int ret = 0; + struct dahdi_chan *chan = NULL; + enum fxs_state txhook; + unsigned long flags; LINE_DBG(SIGNAL, xpd, pos, "%s\n", txsig2str(txsig)); priv = xpd->priv; BUG_ON(PHONEDEV(xpd).direction != TO_PHONE); if (IS_SET(PHONEDEV(xpd).digital_inputs, pos)) { - LINE_DBG(SIGNAL, xpd, pos, "Ignoring signal sent to digital input line\n"); + LINE_DBG(SIGNAL, xpd, pos, + "Ignoring signal sent to digital input line\n"); return 0; } if (SPAN_REGISTERED(xpd)) chan = XPD_CHAN(xpd, pos); switch (txsig) { - case DAHDI_TXSIG_ONHOOK: - spin_lock_irqsave(&xpd->lock, flags); - PHONEDEV(xpd).ringing[pos] = 0; - oht_pcm(xpd, pos, 0); - vmwi_search(xpd, pos, 0); - BIT_CLR(priv->want_dtmf_events, pos); - BIT_CLR(priv->want_dtmf_mute, pos); - __do_mute_dtmf(xpd, pos, 0); - spin_unlock_irqrestore(&xpd->lock, flags); - if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { - LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output OFF\n", txsig2str(txsig)); - ret = relay_out(xpd, pos, 0); - return ret; + case DAHDI_TXSIG_ONHOOK: + spin_lock_irqsave(&xpd->lock, flags); + PHONEDEV(xpd).ringing[pos] = 0; + oht_pcm(xpd, pos, 0); + vmwi_search(xpd, pos, 0); + BIT_CLR(priv->want_dtmf_events, pos); + BIT_CLR(priv->want_dtmf_mute, pos); + __do_mute_dtmf(xpd, pos, 0); + spin_unlock_irqrestore(&xpd->lock, flags); + if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { + LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output OFF\n", + txsig2str(txsig)); + ret = relay_out(xpd, pos, 0); + return ret; + } + if (priv->lasttxhook[pos] == FXS_LINE_OPEN) { + /* + * Restore state after KEWL hangup. + */ + LINE_DBG(SIGNAL, xpd, pos, "KEWL STOP\n"); + linefeed_control(xpd->xbus, xpd, pos, + FXS_LINE_POL_ACTIVE); + if (IS_OFFHOOK(xpd, pos)) + MARK_ON(priv, pos, LED_GREEN); + } + ret = send_ring(xpd, pos, 0); // RING off + if (!IS_OFFHOOK(xpd, pos)) + start_stop_vm_led(xpd->xbus, xpd, pos); + txhook = priv->lasttxhook[pos]; + if (chan) { + switch (chan->sig) { + case DAHDI_SIG_EM: + case DAHDI_SIG_FXOKS: + case DAHDI_SIG_FXOLS: + txhook = priv->idletxhookstate[pos]; + break; + case DAHDI_SIG_FXOGS: + txhook = FXS_LINE_TIPOPEN; + break; } - if (priv->lasttxhook[pos] == FXS_LINE_OPEN) { - /* - * Restore state after KEWL hangup. - */ - LINE_DBG(SIGNAL, xpd, pos, "KEWL STOP\n"); - linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_POL_ACTIVE); - if (IS_OFFHOOK(xpd, pos)) - MARK_ON(priv, pos, LED_GREEN); + } + ret = linefeed_control(xpd->xbus, xpd, pos, txhook); + break; + case DAHDI_TXSIG_OFFHOOK: + if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { + LINE_NOTICE(xpd, pos, + "%s -> Is digital output. Ignored\n", + txsig2str(txsig)); + return -EINVAL; + } + txhook = priv->lasttxhook[pos]; + if (PHONEDEV(xpd).ringing[pos]) { + oht_pcm(xpd, pos, 1); + txhook = FXS_LINE_OHTRANS; + } + PHONEDEV(xpd).ringing[pos] = 0; + if (chan) { + switch (chan->sig) { + case DAHDI_SIG_EM: + txhook = FXS_LINE_POL_ACTIVE; + break; + default: + txhook = priv->idletxhookstate[pos]; + break; } - ret = send_ring(xpd, pos, 0); // RING off - if (!IS_OFFHOOK(xpd, pos)) - start_stop_vm_led(xpd->xbus, xpd, pos); - txhook = priv->lasttxhook[pos]; - if (chan) { - switch (chan->sig) { - case DAHDI_SIG_EM: - case DAHDI_SIG_FXOKS: - case DAHDI_SIG_FXOLS: - txhook = priv->idletxhookstate[pos]; - break; - case DAHDI_SIG_FXOGS: - txhook = FXS_LINE_TIPOPEN; - break; - } - } - ret = linefeed_control(xpd->xbus, xpd, pos, txhook); - break; - case DAHDI_TXSIG_OFFHOOK: - if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { - LINE_NOTICE(xpd, pos, "%s -> Is digital output. Ignored\n", txsig2str(txsig)); - return -EINVAL; - } - txhook = priv->lasttxhook[pos]; - if (PHONEDEV(xpd).ringing[pos]) { - oht_pcm(xpd, pos, 1); - txhook = FXS_LINE_OHTRANS; - } - PHONEDEV(xpd).ringing[pos] = 0; - if (chan) { - switch (chan->sig) { - case DAHDI_SIG_EM: - txhook = FXS_LINE_POL_ACTIVE; - break; - default: - txhook = priv->idletxhookstate[pos]; - break; - } - } - ret = linefeed_control(xpd->xbus, xpd, pos, txhook); - break; - case DAHDI_TXSIG_START: - PHONEDEV(xpd).ringing[pos] = 1; - oht_pcm(xpd, pos, 0); - vmwi_search(xpd, pos, 0); - if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { - LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output ON\n", txsig2str(txsig)); - ret = relay_out(xpd, pos, 1); - return ret; - } - ret = send_ring(xpd, pos, 1); // RING on - break; - case DAHDI_TXSIG_KEWL: - if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { - LINE_DBG(SIGNAL, xpd, pos, "%s -> Is digital output. Ignored\n", txsig2str(txsig)); - return -EINVAL; - } - linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_OPEN); - MARK_OFF(priv, pos, LED_GREEN); - break; - default: - XPD_NOTICE(xpd, "%s: Can't set tx state to %s (%d)\n", - __func__, txsig2str(txsig), txsig); - ret = -EINVAL; + } + ret = linefeed_control(xpd->xbus, xpd, pos, txhook); + break; + case DAHDI_TXSIG_START: + PHONEDEV(xpd).ringing[pos] = 1; + oht_pcm(xpd, pos, 0); + vmwi_search(xpd, pos, 0); + if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { + LINE_DBG(SIGNAL, xpd, pos, "%s -> digital output ON\n", + txsig2str(txsig)); + ret = relay_out(xpd, pos, 1); + return ret; + } + ret = send_ring(xpd, pos, 1); // RING on + break; + case DAHDI_TXSIG_KEWL: + if (IS_SET(PHONEDEV(xpd).digital_outputs, pos)) { + LINE_DBG(SIGNAL, xpd, pos, + "%s -> Is digital output. Ignored\n", + txsig2str(txsig)); + return -EINVAL; + } + linefeed_control(xpd->xbus, xpd, pos, FXS_LINE_OPEN); + MARK_OFF(priv, pos, LED_GREEN); + break; + default: + XPD_NOTICE(xpd, "%s: Can't set tx state to %s (%d)\n", __func__, + txsig2str(txsig), txsig); + ret = -EINVAL; } return ret; } static int set_vmwi(xpd_t *xpd, int pos, unsigned long arg) { - struct FXS_priv_data *priv; - struct dahdi_vmwi_info vmwisetting; - const int vmwi_flags = DAHDI_VMWI_LREV | DAHDI_VMWI_HVDC - | DAHDI_VMWI_HVAC; + struct FXS_priv_data *priv; + struct dahdi_vmwi_info vmwisetting; + const int vmwi_flags = + DAHDI_VMWI_LREV | DAHDI_VMWI_HVDC | DAHDI_VMWI_HVAC; priv = xpd->priv; BUG_ON(!priv); - if (copy_from_user(&vmwisetting, (__user void *)arg, - sizeof(vmwisetting))) + if (copy_from_user + (&vmwisetting, (__user void *)arg, sizeof(vmwisetting))) return -EFAULT; if ((vmwisetting.vmwi_type & ~vmwi_flags) != 0) { LINE_NOTICE(xpd, pos, "Bad DAHDI_VMWI_CONFIG: 0x%X\n", - vmwisetting.vmwi_type); + vmwisetting.vmwi_type); return -EINVAL; } - LINE_DBG(SIGNAL, xpd, pos, - "DAHDI_VMWI_CONFIG: 0x%X\n", - vmwisetting.vmwi_type); + LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI_CONFIG: 0x%X\n", + vmwisetting.vmwi_type); if (VMWI_TYPE(priv, pos, LREV)) { LINE_NOTICE(xpd, pos, - "%s: VMWI(lrev) is not implemented yet. Ignored.\n", - __func__); + "%s: VMWI(lrev) is not implemented yet. Ignored.\n", + __func__); } if (VMWI_TYPE(priv, pos, HVDC)) { LINE_NOTICE(xpd, pos, - "%s: VMWI(hvdc) is not implemented yet. Ignored.\n", - __func__); + "%s: VMWI(hvdc) is not implemented yet. Ignored.\n", + __func__); } if (VMWI_TYPE(priv, pos, HVAC)) { - ; /* VMWI_NEON */ + ; /* VMWI_NEON */ } if (priv->vmwisetting[pos].vmwi_type == 0) { - ; /* Disable VMWI */ + ; /* Disable VMWI */ } priv->vmwisetting[pos] = vmwisetting; set_vm_led_mode(xpd->xbus, xpd, pos, PHONEDEV(xpd).msg_waiting[pos]); @@ -856,12 +931,13 @@ static int set_vmwi(xpd_t *xpd, int pos, unsigned long arg) * Private ioctl() * We don't need it now, since we detect vmwi via FSK patterns */ -static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg) +static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, + unsigned long arg) { - struct FXS_priv_data *priv; - xbus_t *xbus; - int val; - unsigned long flags; + struct FXS_priv_data *priv; + xbus_t *xbus; + int val; + unsigned long flags; BUG_ON(!xpd); priv = xpd->priv; @@ -871,142 +947,156 @@ static int FXS_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a if (!XBUS_IS(xbus, READY)) return -ENODEV; if (pos < 0 || pos >= PHONEDEV(xpd).channels) { - XPD_NOTICE(xpd, "Bad channel number %d in %s(), cmd=%u\n", - pos, __func__, cmd); + XPD_NOTICE(xpd, "Bad channel number %d in %s(), cmd=%u\n", pos, + __func__, cmd); return -EINVAL; } switch (cmd) { - case DAHDI_ONHOOKTRANSFER: - if (get_user(val, (int __user *)arg)) - return -EFAULT; - LINE_DBG(SIGNAL, xpd, pos, "DAHDI_ONHOOKTRANSFER (%d millis)\n", val); - if (IS_SET(PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).digital_outputs, pos)) - return 0; /* Nothing to do */ - oht_pcm(xpd, pos, 1); /* Get ready of VMWI FSK tones */ - if (priv->lasttxhook[pos] == FXS_LINE_POL_ACTIVE || - IS_SET(priv->neon_blinking, pos)) { - priv->ohttimer[pos] = val; - priv->idletxhookstate[pos] = FXS_LINE_POL_OHTRANS; - vmwi_search(xpd, pos, 1); - CALL_PHONE_METHOD(card_pcm_recompute, xpd, priv->search_fsk_pattern); - LINE_DBG(SIGNAL, xpd, pos, "Start OHT_TIMER. wanted_pcm_mask=0x%X\n", PHONEDEV(xpd).wanted_pcm_mask); - } - if (VMWI_NEON(priv, pos) && !IS_OFFHOOK(xpd, pos)) - start_stop_vm_led(xbus, xpd, pos); - return 0; - case DAHDI_TONEDETECT: - if (get_user(val, (int __user *)arg)) - return -EFAULT; - LINE_DBG(SIGNAL, xpd, pos, "DAHDI_TONEDETECT: %s %s (dtmf_detection=%s)\n", - (val & DAHDI_TONEDETECT_ON) ? "ON" : "OFF", - (val & DAHDI_TONEDETECT_MUTE) ? "MUTE" : "NO-MUTE", - (dtmf_detection ? "YES" : "NO")); - if (!dtmf_detection) { - spin_lock_irqsave(&xpd->lock, flags); - if (IS_SET(priv->want_dtmf_events, pos)) { - /* Detection mode changed: Disable DTMF interrupts */ - SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x17, 0); - } - BIT_CLR(priv->want_dtmf_events, pos); - BIT_CLR(priv->want_dtmf_mute, pos); - __do_mute_dtmf(xpd, pos, 0); - spin_unlock_irqrestore(&xpd->lock, flags); - return -ENOTTY; - } - /* - * During natively bridged calls, Asterisk - * will request one of the sides to stop sending - * dtmf events. Check the requested state. - */ + case DAHDI_ONHOOKTRANSFER: + if (get_user(val, (int __user *)arg)) + return -EFAULT; + LINE_DBG(SIGNAL, xpd, pos, "DAHDI_ONHOOKTRANSFER (%d millis)\n", + val); + if (IS_SET + (PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd). + digital_outputs, pos)) + return 0; /* Nothing to do */ + oht_pcm(xpd, pos, 1); /* Get ready of VMWI FSK tones */ + if (priv->lasttxhook[pos] == FXS_LINE_POL_ACTIVE + || IS_SET(priv->neon_blinking, pos)) { + priv->ohttimer[pos] = val; + priv->idletxhookstate[pos] = FXS_LINE_POL_OHTRANS; + vmwi_search(xpd, pos, 1); + CALL_PHONE_METHOD(card_pcm_recompute, xpd, + priv->search_fsk_pattern); + LINE_DBG(SIGNAL, xpd, pos, + "Start OHT_TIMER. wanted_pcm_mask=0x%X\n", + PHONEDEV(xpd).wanted_pcm_mask); + } + if (VMWI_NEON(priv, pos) && !IS_OFFHOOK(xpd, pos)) + start_stop_vm_led(xbus, xpd, pos); + return 0; + case DAHDI_TONEDETECT: + if (get_user(val, (int __user *)arg)) + return -EFAULT; + LINE_DBG(SIGNAL, xpd, pos, + "DAHDI_TONEDETECT: %s %s (dtmf_detection=%s)\n", + (val & DAHDI_TONEDETECT_ON) ? "ON" : "OFF", + (val & DAHDI_TONEDETECT_MUTE) ? "MUTE" : "NO-MUTE", + (dtmf_detection ? "YES" : "NO")); + if (!dtmf_detection) { spin_lock_irqsave(&xpd->lock, flags); - if (val & DAHDI_TONEDETECT_ON) { - if (!IS_SET(priv->want_dtmf_events, pos)) { - /* Detection mode changed: Enable DTMF interrupts */ - LINE_DBG(SIGNAL, xpd, pos, - "DAHDI_TONEDETECT: Enable Hardware DTMF\n"); - SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x17, 1); - } - BIT_SET(priv->want_dtmf_events, pos); - } else { - if (IS_SET(priv->want_dtmf_events, pos)) { - /* Detection mode changed: Disable DTMF interrupts */ - LINE_DBG(SIGNAL, xpd, pos, - "DAHDI_TONEDETECT: Disable Hardware DTMF\n"); - SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, 0x17, 0); - } - BIT_CLR(priv->want_dtmf_events, pos); - } - if (val & DAHDI_TONEDETECT_MUTE) { - BIT_SET(priv->want_dtmf_mute, pos); - } else { - BIT_CLR(priv->want_dtmf_mute, pos); - __do_mute_dtmf(xpd, pos, 0); + if (IS_SET(priv->want_dtmf_events, pos)) { + /* Detection mode changed: Disable DTMF interrupts */ + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, + 0x17, 0); } + BIT_CLR(priv->want_dtmf_events, pos); + BIT_CLR(priv->want_dtmf_mute, pos); + __do_mute_dtmf(xpd, pos, 0); spin_unlock_irqrestore(&xpd->lock, flags); - return 0; - case DAHDI_SETPOLARITY: - if (get_user(val, (int __user *)arg)) - return -EFAULT; - /* - * Asterisk may send us this if chan_dahdi config - * has "hanguponpolarityswitch=yes" to notify - * that the other side has hanged up. - * - * This has no effect on normal phone (but we may - * be connected to another FXO equipment). - * note that this chan_dahdi settings has different - * meaning for FXO, where it signals polarity - * reversal *detection* logic. - * - * It seems that sometimes we get this from - * asterisk in wrong state (e.g: while ringing). - * In these cases, silently ignore it. - */ - if (priv->lasttxhook[pos] == FXS_LINE_RING || priv->lasttxhook[pos] == FXS_LINE_OPEN) { + return -ENOTTY; + } + /* + * During natively bridged calls, Asterisk + * will request one of the sides to stop sending + * dtmf events. Check the requested state. + */ + spin_lock_irqsave(&xpd->lock, flags); + if (val & DAHDI_TONEDETECT_ON) { + if (!IS_SET(priv->want_dtmf_events, pos)) { + /* Detection mode changed: Enable DTMF interrupts */ LINE_DBG(SIGNAL, xpd, pos, - "DAHDI_SETPOLARITY: %s Cannot change when lasttxhook=0x%X\n", - (val)?"ON":"OFF", priv->lasttxhook[pos]); - return -EINVAL; + "DAHDI_TONEDETECT: Enable Hardware DTMF\n"); + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, + 0x17, 1); } - LINE_DBG(SIGNAL, xpd, pos, "DAHDI_SETPOLARITY: %s\n", (val)?"ON":"OFF"); - if ((val && !reversepolarity) || (!val && reversepolarity)) - priv->lasttxhook[pos] |= FXS_LINE_RING; - else - priv->lasttxhook[pos] &= ~FXS_LINE_RING; - linefeed_control(xbus, xpd, pos, priv->lasttxhook[pos]); - return 0; - case DAHDI_VMWI_CONFIG: - if (set_vmwi(xpd, pos, arg) < 0) - return -EINVAL; - return 0; - case DAHDI_VMWI: /* message-waiting led control */ - if (get_user(val, (int __user *)arg)) - return -EFAULT; - if (!vmwi_ioctl) { - static bool notified; + BIT_SET(priv->want_dtmf_events, pos); + } else { + if (IS_SET(priv->want_dtmf_events, pos)) { + /* Detection mode changed: Disable DTMF interrupts */ + LINE_DBG(SIGNAL, xpd, pos, + "DAHDI_TONEDETECT: Disable Hardware DTMF\n"); + SLIC_DIRECT_REQUEST(xbus, xpd, pos, SLIC_WRITE, + 0x17, 0); + } + BIT_CLR(priv->want_dtmf_events, pos); + } + if (val & DAHDI_TONEDETECT_MUTE) { + BIT_SET(priv->want_dtmf_mute, pos); + } else { + BIT_CLR(priv->want_dtmf_mute, pos); + __do_mute_dtmf(xpd, pos, 0); + } + spin_unlock_irqrestore(&xpd->lock, flags); + return 0; + case DAHDI_SETPOLARITY: + if (get_user(val, (int __user *)arg)) + return -EFAULT; + /* + * Asterisk may send us this if chan_dahdi config + * has "hanguponpolarityswitch=yes" to notify + * that the other side has hanged up. + * + * This has no effect on normal phone (but we may + * be connected to another FXO equipment). + * note that this chan_dahdi settings has different + * meaning for FXO, where it signals polarity + * reversal *detection* logic. + * + * It seems that sometimes we get this from + * asterisk in wrong state (e.g: while ringing). + * In these cases, silently ignore it. + */ + if (priv->lasttxhook[pos] == FXS_LINE_RING + || priv->lasttxhook[pos] == FXS_LINE_OPEN) { + LINE_DBG(SIGNAL, xpd, pos, + "DAHDI_SETPOLARITY: %s Cannot change when lasttxhook=0x%X\n", + (val) ? "ON" : "OFF", priv->lasttxhook[pos]); + return -EINVAL; + } + LINE_DBG(SIGNAL, xpd, pos, "DAHDI_SETPOLARITY: %s\n", + (val) ? "ON" : "OFF"); + if ((val && !reversepolarity) || (!val && reversepolarity)) + priv->lasttxhook[pos] |= FXS_LINE_RING; + else + priv->lasttxhook[pos] &= ~FXS_LINE_RING; + linefeed_control(xbus, xpd, pos, priv->lasttxhook[pos]); + return 0; + case DAHDI_VMWI_CONFIG: + if (set_vmwi(xpd, pos, arg) < 0) + return -EINVAL; + return 0; + case DAHDI_VMWI: /* message-waiting led control */ + if (get_user(val, (int __user *)arg)) + return -EFAULT; + if (!vmwi_ioctl) { + static bool notified; - if (!notified++) - LINE_NOTICE(xpd, pos, - "Got DAHDI_VMWI notification but vmwi_ioctl parameter is off. Ignoring.\n"); - return 0; - } - /* Digital inputs/outputs don't have VM leds */ - if (IS_SET(PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).digital_outputs, pos)) - return 0; - PHONEDEV(xpd).msg_waiting[pos] = val; - LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI: %s\n", - (val) ? "yes" : "no"); + if (!notified++) + LINE_NOTICE(xpd, pos, + "Got DAHDI_VMWI notification but vmwi_ioctl parameter is off. Ignoring.\n"); return 0; - default: - report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); + } + /* Digital inputs/outputs don't have VM leds */ + if (IS_SET + (PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd). + digital_outputs, pos)) + return 0; + PHONEDEV(xpd).msg_waiting[pos] = val; + LINE_DBG(SIGNAL, xpd, pos, "DAHDI_VMWI: %s\n", + (val) ? "yes" : "no"); + return 0; + default: + report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); } return -ENOTTY; } static int FXS_card_open(xpd_t *xpd, lineno_t chan) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -1026,7 +1116,7 @@ static int FXS_card_open(xpd_t *xpd, lineno_t chan) static int FXS_card_close(xpd_t *xpd, lineno_t chan) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; BUG_ON(!xpd); LINE_DBG(GENERAL, xpd, chan, "\n"); @@ -1044,15 +1134,15 @@ static int FXS_card_close(xpd_t *xpd, lineno_t chan) * +-----+-----+-----+-----+-----+-----+-----+-----+ * */ -static int input_channels[] = { 6, 7, 2, 3 }; // Slic numbers of input relays +static int input_channels[] = { 6, 7, 2, 3 }; // Slic numbers of input relays static void poll_inputs(xpd_t *xpd) { - int i; + int i; BUG_ON(xpd->xbus_idx != 0); // Only unit #0 has digital inputs for (i = 0; i < ARRAY_SIZE(input_channels); i++) { - __u8 pos = input_channels[i]; + __u8 pos = input_channels[i]; SLIC_DIRECT_REQUEST(xpd->xbus, xpd, pos, SLIC_READ, 0x06, 0); } @@ -1061,15 +1151,15 @@ static void poll_inputs(xpd_t *xpd) static void handle_linefeed(xpd_t *xpd) { - struct FXS_priv_data *priv; - int i; + struct FXS_priv_data *priv; + int i; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); for_each_line(xpd, i) { - if (priv->lasttxhook[i] == FXS_LINE_RING && - !IS_SET(priv->neon_blinking, i)) { + if (priv->lasttxhook[i] == FXS_LINE_RING + && !IS_SET(priv->neon_blinking, i)) { /* RINGing, prepare for OHT */ priv->ohttimer[i] = OHT_TIMER; priv->idletxhookstate[i] = FXS_LINE_POL_OHTRANS; @@ -1077,13 +1167,18 @@ static void handle_linefeed(xpd_t *xpd) if (priv->ohttimer[i]) { priv->ohttimer[i]--; if (!priv->ohttimer[i]) { - LINE_DBG(SIGNAL, xpd, i, "ohttimer expired\n"); - priv->idletxhookstate[i] = FXS_LINE_POL_ACTIVE; + LINE_DBG(SIGNAL, xpd, i, + "ohttimer expired\n"); + priv->idletxhookstate[i] = + FXS_LINE_POL_ACTIVE; oht_pcm(xpd, i, 0); vmwi_search(xpd, i, 0); - if (priv->lasttxhook[i] == FXS_LINE_POL_OHTRANS) { + if (priv->lasttxhook[i] == + FXS_LINE_POL_OHTRANS) { /* Apply the change if appropriate */ - linefeed_control(xpd->xbus, xpd, i, FXS_LINE_POL_ACTIVE); + linefeed_control(xpd->xbus, xpd, + i, + FXS_LINE_POL_ACTIVE); } } } @@ -1097,7 +1192,7 @@ static void handle_linefeed(xpd_t *xpd) */ static inline bool mem_equal(const char a[], const char b[], size_t len) { - int i; + int i; for (i = 0; i < len; i++) if (a[i] != b[i]) @@ -1110,33 +1205,35 @@ static inline bool mem_equal(const char a[], const char b[], size_t len) */ static void detect_vmwi(xpd_t *xpd) { - struct FXS_priv_data *priv; - xbus_t *xbus; - static const __u8 FSK_COMMON_PATTERN[] = { 0xA8, 0x49, 0x22, 0x3B, 0x9F, 0xFF, 0x1F, 0xBB }; - static const __u8 FSK_ON_PATTERN[] = { 0xA2, 0x2C, 0x1F, 0x2C, 0xBB, 0xA1, 0xA5, 0xFF }; - static const __u8 FSK_OFF_PATTERN[] = { 0xA2, 0x2C, 0x28, 0xA5, 0xB1, 0x21, 0x49, 0x9F }; - int i; - xpp_line_t ignore_mask; + struct FXS_priv_data *priv; + xbus_t *xbus; + static const __u8 FSK_COMMON_PATTERN[] = + { 0xA8, 0x49, 0x22, 0x3B, 0x9F, 0xFF, 0x1F, 0xBB }; + static const __u8 FSK_ON_PATTERN[] = + { 0xA2, 0x2C, 0x1F, 0x2C, 0xBB, 0xA1, 0xA5, 0xFF }; + static const __u8 FSK_OFF_PATTERN[] = + { 0xA2, 0x2C, 0x28, 0xA5, 0xB1, 0x21, 0x49, 0x9F }; + int i; + xpp_line_t ignore_mask; BUG_ON(!xpd); xbus = xpd->xbus; priv = xpd->priv; BUG_ON(!priv); ignore_mask = - PHONEDEV(xpd).offhook_state | - ~(PHONEDEV(xpd).oht_pcm_pass) | - ~(priv->search_fsk_pattern) | - PHONEDEV(xpd).digital_inputs | - PHONEDEV(xpd).digital_outputs; + PHONEDEV(xpd).offhook_state | ~(PHONEDEV(xpd). + oht_pcm_pass) | ~(priv-> + search_fsk_pattern) + | PHONEDEV(xpd).digital_inputs | PHONEDEV(xpd).digital_outputs; for_each_line(xpd, i) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); - __u8 *writechunk = chan->writechunk; + struct dahdi_chan *chan = XPD_CHAN(xpd, i); + __u8 *writechunk = chan->writechunk; if (IS_SET(ignore_mask, i)) continue; #if 0 if (writechunk[0] != 0x7F && writechunk[0] != 0) { - int j; + int j; LINE_DBG(GENERAL, xpd, pos, "MSG:"); for (j = 0; j < DAHDI_CHUNKSIZE; j++) { @@ -1147,22 +1244,31 @@ static void detect_vmwi(xpd_t *xpd) printk("\n"); } #endif - if (unlikely(mem_equal(writechunk, FSK_COMMON_PATTERN, DAHDI_CHUNKSIZE))) { - LINE_DBG(SIGNAL, xpd, i, "Found common FSK pattern. Start looking for ON/OFF patterns.\n"); + if (unlikely + (mem_equal + (writechunk, FSK_COMMON_PATTERN, DAHDI_CHUNKSIZE))) { + LINE_DBG(SIGNAL, xpd, i, + "Found common FSK pattern. Start looking for ON/OFF patterns.\n"); BIT_SET(priv->found_fsk_pattern, i); } else if (unlikely(IS_SET(priv->found_fsk_pattern, i))) { BIT_CLR(priv->found_fsk_pattern, i); oht_pcm(xpd, i, 0); - if (unlikely(mem_equal(writechunk, FSK_ON_PATTERN, DAHDI_CHUNKSIZE))) { + if (unlikely + (mem_equal + (writechunk, FSK_ON_PATTERN, DAHDI_CHUNKSIZE))) { LINE_DBG(SIGNAL, xpd, i, "MSG WAITING ON\n"); PHONEDEV(xpd).msg_waiting[i] = 1; start_stop_vm_led(xbus, xpd, i); - } else if (unlikely(mem_equal(writechunk, FSK_OFF_PATTERN, DAHDI_CHUNKSIZE))) { + } else + if (unlikely + (mem_equal + (writechunk, FSK_OFF_PATTERN, + DAHDI_CHUNKSIZE))) { LINE_DBG(SIGNAL, xpd, i, "MSG WAITING OFF\n"); PHONEDEV(xpd).msg_waiting[i] = 0; start_stop_vm_led(xbus, xpd, i); } else { - int j; + int j; LINE_NOTICE(xpd, i, "MSG WAITING Unexpected:"); for (j = 0; j < DAHDI_CHUNKSIZE; j++) { @@ -1176,7 +1282,7 @@ static void detect_vmwi(xpd_t *xpd) static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd) { - struct FXS_priv_data *priv; + struct FXS_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -1197,13 +1303,16 @@ static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd) * now we take care of notification to dahdi and Asterisk */ if (priv->update_offhook_state) { - enum dahdi_rxsig rxsig; - int i; + enum dahdi_rxsig rxsig; + int i; for_each_line(xpd, i) { if (!IS_SET(priv->update_offhook_state, i)) continue; - rxsig = IS_OFFHOOK(xpd, i) ? DAHDI_RXSIG_OFFHOOK : DAHDI_RXSIG_ONHOOK; + rxsig = + IS_OFFHOOK(xpd, + i) ? DAHDI_RXSIG_OFFHOOK : + DAHDI_RXSIG_ONHOOK; notify_rxsig(xpd, i, rxsig); /* Notify after open() */ BIT_CLR(priv->update_offhook_state, i); } @@ -1222,22 +1331,25 @@ static int FXS_card_tick(xbus_t *xbus, xpd_t *xpd) /* * Should be called with spinlocked XPD */ -static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, xpp_line_t change_mask) +static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, + xpp_line_t change_mask) { - xbus_t *xbus; - struct FXS_priv_data *priv; - int i; + xbus_t *xbus; + struct FXS_priv_data *priv; + int i; BUG_ON(!xpd); BUG_ON(PHONEDEV(xpd).direction != TO_PHONE); xbus = xpd->xbus; priv = xpd->priv; - XPD_DBG(SIGNAL, xpd, "offhook=0x%X change_mask=0x%X\n", offhook, change_mask); + XPD_DBG(SIGNAL, xpd, "offhook=0x%X change_mask=0x%X\n", offhook, + change_mask); for_each_line(xpd, i) { - if (IS_SET(PHONEDEV(xpd).digital_outputs, i) || IS_SET(PHONEDEV(xpd).digital_inputs, i)) + if (IS_SET(PHONEDEV(xpd).digital_outputs, i) + || IS_SET(PHONEDEV(xpd).digital_inputs, i)) continue; if (IS_SET(change_mask, i)) { - PHONEDEV(xpd).ringing[i] = 0; /* No more ringing... */ + PHONEDEV(xpd).ringing[i] = 0; /* No more ringing... */ #ifdef WITH_METERING metering_gen(xpd, i, 0); /* Stop metering... */ #endif @@ -1246,7 +1358,8 @@ static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, xpp_line_t change_ * Reset our previous DTMF memories... */ BIT_CLR(priv->prev_key_down, i); - priv->prev_key_time[i].tv_sec = priv->prev_key_time[i].tv_usec = 0L; + priv->prev_key_time[i].tv_sec = + priv->prev_key_time[i].tv_usec = 0L; if (IS_SET(offhook, i)) { LINE_DBG(SIGNAL, xpd, i, "OFFHOOK\n"); MARK_ON(priv, i, LED_GREEN); @@ -1267,18 +1380,20 @@ static void process_hookstate(xpd_t *xpd, xpp_line_t offhook, xpp_line_t change_ HANDLER_DEF(FXS, SIG_CHANGED) { - xpp_line_t sig_status = RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_status); - xpp_line_t sig_toggles = RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_toggles); - unsigned long flags; + xpp_line_t sig_status = + RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_status); + xpp_line_t sig_toggles = + RPACKET_FIELD(pack, FXS, SIG_CHANGED, sig_toggles); + unsigned long flags; BUG_ON(!xpd); BUG_ON(PHONEDEV(xpd).direction != TO_PHONE); - XPD_DBG(SIGNAL, xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n", sig_toggles, sig_status); + XPD_DBG(SIGNAL, xpd, "(PHONE) sig_toggles=0x%04X sig_status=0x%04X\n", + sig_toggles, sig_status); #if 0 - Is this needed? - for_each_line(xpd, i) { + Is this needed ? for_each_line(xpd, i) { if (IS_SET(sig_toggles, i)) - do_chan_power(xpd->xbus, xpd, BIT(i), 0); // Power down (prevent overheating!!!) + do_chan_power(xpd->xbus, xpd, BIT(i), 0); // Power down (prevent overheating!!!) } #endif spin_lock_irqsave(&xpd->lock, flags); @@ -1290,28 +1405,27 @@ HANDLER_DEF(FXS, SIG_CHANGED) #ifdef POLL_DIGITAL_INPUTS static void process_digital_inputs(xpd_t *xpd, const reg_cmd_t *info) { - int i; - bool offhook = (REG_FIELD(info, data_low) & 0x1) == 0; - xpp_line_t lines = BIT(info->portnum); + int i; + bool offhook = (REG_FIELD(info, data_low) & 0x1) == 0; + xpp_line_t lines = BIT(info->portnum); /* Sanity check */ if (!PHONEDEV(xpd).digital_inputs) { - XPD_NOTICE(xpd, - "%s called without digital inputs. Ignored\n", - __func__); + XPD_NOTICE(xpd, "%s called without digital inputs. Ignored\n", + __func__); return; } /* Map SLIC number into line number */ for (i = 0; i < ARRAY_SIZE(input_channels); i++) { - int channo = input_channels[i]; - int newchanno; + int channo = input_channels[i]; + int newchanno; if (IS_SET(lines, channo)) { newchanno = PHONEDEV(xpd).channels - LINES_DIGI_INP + i; BIT_CLR(lines, channo); BIT_SET(lines, newchanno); - PHONEDEV(xpd).ringing[newchanno] = 0; // Stop ringing. No leds for digital inputs. - if (offhook && !IS_OFFHOOK(xpd, newchanno)) { // OFFHOOK + PHONEDEV(xpd).ringing[newchanno] = 0; // Stop ringing. No leds for digital inputs. + if (offhook && !IS_OFFHOOK(xpd, newchanno)) { // OFFHOOK LINE_DBG(SIGNAL, xpd, newchanno, "OFFHOOK\n"); hookstate_changed(xpd, newchanno, 1); } else if (!offhook && IS_OFFHOOK(xpd, newchanno)) { // ONHOOK @@ -1333,13 +1447,13 @@ static const char dtmf_digits[] = { */ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val) { - __u8 digit; - bool key_down = val & 0x10; - bool want_mute; - bool want_event; - struct FXS_priv_data *priv; - struct timeval now; - int msec = 0; + __u8 digit; + bool key_down = val & 0x10; + bool want_mute; + bool want_event; + struct FXS_priv_data *priv; + struct timeval now; + int msec = 0; if (!dtmf_detection) return; @@ -1362,12 +1476,10 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val) msec = usec_diff(&now, &priv->prev_key_time[portnum]) / 1000; priv->prev_key_time[portnum] = now; LINE_DBG(SIGNAL, xpd, portnum, - "[%lu.%06lu] DTMF digit %-4s '%c' (val=%d, want_mute=%s want_event=%s, delta=%d msec)\n", - now.tv_sec, now.tv_usec, - (key_down)?"DOWN":"UP", digit, val, - (want_mute) ? "yes" : "no", - (want_event) ? "yes" : "no", - msec); + "[%lu.%06lu] DTMF digit %-4s '%c' (val=%d, want_mute=%s want_event=%s, delta=%d msec)\n", + now.tv_sec, now.tv_usec, (key_down) ? "DOWN" : "UP", digit, + val, (want_mute) ? "yes" : "no", (want_event) ? "yes" : "no", + msec); /* * FIXME: we currently don't use the want_dtmf_mute until * we are sure about the logic in Asterisk native bridging. @@ -1377,8 +1489,9 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val) __do_mute_dtmf(xpd, portnum, 1); else __do_mute_dtmf(xpd, portnum, 0); - if (want_event) { - int event = (key_down) ? DAHDI_EVENT_DTMFDOWN : DAHDI_EVENT_DTMFUP; + if (want_event) { + int event = + (key_down) ? DAHDI_EVENT_DTMFDOWN : DAHDI_EVENT_DTMFUP; dahdi_qevent_lock(XPD_CHAN(xpd, portnum), event | digit); } @@ -1386,10 +1499,10 @@ static void process_dtmf(xpd_t *xpd, uint portnum, __u8 val) static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) { - unsigned long flags; - struct FXS_priv_data *priv; - __u8 regnum; - bool indirect; + unsigned long flags; + struct FXS_priv_data *priv; + __u8 regnum; + bool indirect; spin_lock_irqsave(&xpd->lock, flags); priv = xpd->priv; @@ -1397,10 +1510,10 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) indirect = (REG_FIELD(info, regnum) == 0x1E); regnum = (indirect) ? REG_FIELD(info, subreg) : REG_FIELD(info, regnum); XPD_DBG(REGS, xpd, "%s reg_num=0x%X, dataL=0x%X dataH=0x%X\n", - (indirect)?"I":"D", - regnum, REG_FIELD(info, data_low), REG_FIELD(info, data_high)); + (indirect) ? "I" : "D", regnum, REG_FIELD(info, data_low), + REG_FIELD(info, data_high)); if (!indirect && regnum == REG_DTMF_DECODE) { - __u8 val = REG_FIELD(info, data_low); + __u8 val = REG_FIELD(info, data_low); process_dtmf(xpd, info->portnum, val); } @@ -1413,9 +1526,9 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) } #endif else if (!indirect && regnum == REG_LOOPCLOSURE) { /* OFFHOOK ? */ - __u8 val = REG_FIELD(info, data_low); - xpp_line_t mask = BIT(info->portnum); - xpp_line_t offhook; + __u8 val = REG_FIELD(info, data_low); + xpp_line_t mask = BIT(info->portnum); + xpp_line_t offhook; /* * Validate reply. Non-existing/disabled ports @@ -1424,22 +1537,25 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) if ((val & REG_LOOPCLOSURE_ZERO) == 0) { offhook = (val & REG_LOOPCLOSURE_LCR) ? mask : 0; LINE_DBG(SIGNAL, xpd, info->portnum, - "REG_LOOPCLOSURE: dataL=0x%X (offhook=0x%X mask=0x%X\n", - val, offhook, mask); + "REG_LOOPCLOSURE: dataL=0x%X (offhook=0x%X mask=0x%X\n", + val, offhook, mask); process_hookstate(xpd, offhook, mask); } } else { #if 0 - XPD_NOTICE(xpd, "Spurious register reply(ignored): %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n", - (indirect)?"I":"D", - regnum, REG_FIELD(info, data_low), REG_FIELD(info, data_high)); + XPD_NOTICE(xpd, + "Spurious register reply(ignored): %s reg_num=0x%X, dataL=0x%X dataH=0x%X\n", + (indirect) ? "I" : "D", regnum, REG_FIELD(info, + data_low), + REG_FIELD(info, data_high)); #endif } /* Update /proc info only if reply relate to the last slic read request */ - if ( - REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) && - REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) && - REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) { + if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) + && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, + do_subreg) + && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, + subreg)) { xpd->last_reply = *info; } spin_unlock_irqrestore(&xpd->lock, flags); @@ -1449,52 +1565,45 @@ static int FXS_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) static int FXS_card_state(xpd_t *xpd, bool on) { BUG_ON(!xpd); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); return 0; } -static const struct xops fxs_xops = { - .card_new = FXS_card_new, - .card_init = FXS_card_init, - .card_remove = FXS_card_remove, - .card_tick = FXS_card_tick, - .card_register_reply = FXS_card_register_reply, +static const struct xops fxs_xops = { + .card_new = FXS_card_new, + .card_init = FXS_card_init, + .card_remove = FXS_card_remove, + .card_tick = FXS_card_tick, + .card_register_reply = FXS_card_register_reply, }; -static const struct phoneops fxs_phoneops = { - .card_dahdi_preregistration = FXS_card_dahdi_preregistration, - .card_dahdi_postregistration = FXS_card_dahdi_postregistration, - .card_hooksig = FXS_card_hooksig, - .card_pcm_recompute = generic_card_pcm_recompute, - .card_pcm_fromspan = generic_card_pcm_fromspan, - .card_pcm_tospan = generic_card_pcm_tospan, - .card_timing_priority = generic_timing_priority, - .echocancel_timeslot = generic_echocancel_timeslot, - .echocancel_setmask = generic_echocancel_setmask, - .card_open = FXS_card_open, - .card_close = FXS_card_close, - .card_ioctl = FXS_card_ioctl, - .card_state = FXS_card_state, +static const struct phoneops fxs_phoneops = { + .card_dahdi_preregistration = FXS_card_dahdi_preregistration, + .card_dahdi_postregistration = FXS_card_dahdi_postregistration, + .card_hooksig = FXS_card_hooksig, + .card_pcm_recompute = generic_card_pcm_recompute, + .card_pcm_fromspan = generic_card_pcm_fromspan, + .card_pcm_tospan = generic_card_pcm_tospan, + .card_timing_priority = generic_timing_priority, + .echocancel_timeslot = generic_echocancel_timeslot, + .echocancel_setmask = generic_echocancel_setmask, + .card_open = FXS_card_open, + .card_close = FXS_card_close, + .card_ioctl = FXS_card_ioctl, + .card_state = FXS_card_state, }; static xproto_table_t PROTO_TABLE(FXS) = { - .owner = THIS_MODULE, - .entries = { - /* Prototable Card Opcode */ - XENTRY( FXS, FXS, SIG_CHANGED ), - }, - .name = "FXS", /* protocol name */ - .ports_per_subunit = 8, - .type = XPD_TYPE_FXS, - .xops = &fxs_xops, - .phoneops = &fxs_phoneops, - .packet_is_valid = fxs_packet_is_valid, - .packet_dump = fxs_packet_dump, -}; + .owner = THIS_MODULE,.entries = { + /* Prototable Card Opcode */ + XENTRY(FXS, FXS, SIG_CHANGED),},.name = "FXS", /* protocol name */ +.ports_per_subunit = 8,.type = XPD_TYPE_FXS,.xops = + &fxs_xops,.phoneops = &fxs_phoneops,.packet_is_valid = + fxs_packet_is_valid,.packet_dump = fxs_packet_dump,}; static bool fxs_packet_is_valid(xpacket_t *pack) { - const xproto_entry_t *xe; + const xproto_entry_t *xe; // DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(FXS), XPACKET_OP(pack)); @@ -1509,30 +1618,27 @@ static void fxs_packet_dump(const char *msg, xpacket_t *pack) /*------------------------- SLIC Handling --------------------------*/ #ifdef CONFIG_PROC_FS -static int proc_fxs_info_read(char *page, char **start, off_t off, int count, int *eof, void *data) +static int proc_fxs_info_read(char *page, char **start, off_t off, int count, + int *eof, void *data) { - int len = 0; - unsigned long flags; - xpd_t *xpd = data; - struct FXS_priv_data *priv; - int i; - int led; + int len = 0; + unsigned long flags; + xpd_t *xpd = data; + struct FXS_priv_data *priv; + int i; + int led; if (!xpd) return -ENODEV; spin_lock_irqsave(&xpd->lock, flags); priv = xpd->priv; BUG_ON(!priv); - len += sprintf(page + len, "%-8s %-10s %-10s %-10s %-10s %-10s\n", - "Channel", - "idletxhookstate", - "lasttxhook", - "ohttimer", - "neon_blinking", - "search_fsk_pattern" - ); + len += + sprintf(page + len, "%-8s %-10s %-10s %-10s %-10s %-10s\n", + "Channel", "idletxhookstate", "lasttxhook", "ohttimer", + "neon_blinking", "search_fsk_pattern"); for_each_line(xpd, i) { - char pref; + char pref; if (IS_SET(PHONEDEV(xpd).digital_outputs, i)) pref = 'O'; @@ -1540,38 +1646,45 @@ static int proc_fxs_info_read(char *page, char **start, off_t off, int count, in pref = 'I'; else pref = ' '; - len += sprintf(page + len, "%c%7d %10d %10d %10d %10d %10d\n", - pref, - i, - priv->idletxhookstate[i], - priv->lasttxhook[i], - priv->ohttimer[i], - IS_SET(priv->neon_blinking, i), - IS_SET(priv->search_fsk_pattern, i) - ); + len += + sprintf(page + len, "%c%7d %10d %10d %10d %10d %10d\n", + pref, i, priv->idletxhookstate[i], + priv->lasttxhook[i], priv->ohttimer[i], + IS_SET(priv->neon_blinking, i), + IS_SET(priv->search_fsk_pattern, i) + ); } len += sprintf(page + len, "\n"); for (led = 0; led < NUM_LEDS; led++) { len += sprintf(page + len, "LED #%d", led); len += sprintf(page + len, "\n\t%-17s: ", "ledstate"); for_each_line(xpd, i) { - if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) - len += sprintf(page + len, "%d ", IS_SET(priv->ledstate[led], i)); + if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) + && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) + len += + sprintf(page + len, "%d ", + IS_SET(priv->ledstate[led], i)); } len += sprintf(page + len, "\n\t%-17s: ", "ledcontrol"); for_each_line(xpd, i) { - if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) - len += sprintf(page + len, "%d ", IS_SET(priv->ledcontrol[led], i)); + if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) + && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) + len += + sprintf(page + len, "%d ", + IS_SET(priv->ledcontrol[led], i)); } len += sprintf(page + len, "\n\t%-17s: ", "led_counter"); for_each_line(xpd, i) { - if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) - len += sprintf(page + len, "%d ", LED_COUNTER(priv,i,led)); + if (!IS_SET(PHONEDEV(xpd).digital_outputs, i) + && !IS_SET(PHONEDEV(xpd).digital_inputs, i)) + len += + sprintf(page + len, "%d ", + LED_COUNTER(priv, i, led)); } len += sprintf(page + len, "\n"); } spin_unlock_irqrestore(&xpd->lock, flags); - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1584,13 +1697,14 @@ static int proc_fxs_info_read(char *page, char **start, off_t off, int count, in #endif #ifdef WITH_METERING -static int proc_xpd_metering_write(struct file *file, const char __user *buffer, unsigned long count, void *data) +static int proc_xpd_metering_write(struct file *file, const char __user *buffer, + unsigned long count, void *data) { - xpd_t *xpd = data; - char buf[MAX_PROC_WRITE]; - lineno_t chan; - int num; - int ret; + xpd_t *xpd = data; + char buf[MAX_PROC_WRITE]; + lineno_t chan; + int num; + int ret; if (!xpd) return -ENODEV; @@ -1603,7 +1717,8 @@ static int proc_xpd_metering_write(struct file *file, const char __user *buffer, buf[count] = '\0'; ret = sscanf(buf, "%d", &num); if (ret != 1) { - XPD_ERR(xpd, "Metering value should be number. Got '%s'\n", buf); + XPD_ERR(xpd, "Metering value should be number. Got '%s'\n", + buf); return -EINVAL; } chan = num; @@ -1621,13 +1736,13 @@ static int proc_xpd_metering_write(struct file *file, const char __user *buffer, static int fxs_xpd_probe(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; xpd = dev_to_xpd(dev); /* Is it our device? */ if (xpd->type != XPD_TYPE_FXS) { - XPD_ERR(xpd, "drop suggestion for %s (%d)\n", - dev_name(dev), xpd->type); + XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev), + xpd->type); return -EINVAL; } XPD_DBG(DEVICES, xpd, "SYSFS\n"); @@ -1636,28 +1751,27 @@ static int fxs_xpd_probe(struct device *dev) static int fxs_xpd_remove(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; xpd = dev_to_xpd(dev); XPD_DBG(DEVICES, xpd, "SYSFS\n"); return 0; } -static struct xpd_driver fxs_driver = { - .type = XPD_TYPE_FXS, - .driver = { - .name = "fxs", +static struct xpd_driver fxs_driver = { + .type = XPD_TYPE_FXS, + .driver = { + .name = "fxs", #ifndef OLD_HOTPLUG_SUPPORT - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .probe = fxs_xpd_probe, - .remove = fxs_xpd_remove - } + .probe = fxs_xpd_probe, + .remove = fxs_xpd_remove} }; static int __init card_fxs_startup(void) { - int ret; + int ret; if ((ret = xpd_driver_register(&fxs_driver.driver)) < 0) return ret; @@ -1665,7 +1779,7 @@ static int __init card_fxs_startup(void) INFO("revision %s\n", XPP_VERSION); #ifdef POLL_DIGITAL_INPUTS INFO("FEATURE: with DIGITAL INPUTS support (polled every %d msec)\n", - poll_digital_inputs); + poll_digital_inputs); #else INFO("FEATURE: without DIGITAL INPUTS support\n"); #endif diff --git a/drivers/dahdi/xpp/card_fxs.h b/drivers/dahdi/xpp/card_fxs.h index 44c8fb0..2b6e267 100644 --- a/drivers/dahdi/xpp/card_fxs.h +++ b/drivers/dahdi/xpp/card_fxs.h @@ -25,17 +25,14 @@ #include "xpd.h" enum fxs_opcodes { - XPROTO_NAME(FXS, SIG_CHANGED) = 0x06, -/**/ - XPROTO_NAME(FXS, CHAN_POWER) = 0x0F, /* Write to SLIC */ - XPROTO_NAME(FXS, CHAN_CID) = 0x0F, /* Write to SLIC */ - XPROTO_NAME(FXS, LED) = 0x0F, /* Write to SLIC */ + XPROTO_NAME(FXS, SIG_CHANGED) = 0x06, + /**/ XPROTO_NAME(FXS, CHAN_POWER) = 0x0F, /* Write to SLIC */ + XPROTO_NAME(FXS, CHAN_CID) = 0x0F, /* Write to SLIC */ + XPROTO_NAME(FXS, LED) = 0x0F, /* Write to SLIC */ }; +DEF_RPACKET_DATA(FXS, SIG_CHANGED, xpp_line_t sig_status; /* channels: lsb=1, msb=8 */ + xpp_line_t sig_toggles; /* channels: lsb=1, msb=8 */ + ); -DEF_RPACKET_DATA(FXS, SIG_CHANGED, - xpp_line_t sig_status; /* channels: lsb=1, msb=8 */ - xpp_line_t sig_toggles; /* channels: lsb=1, msb=8 */ - ); - -#endif /* CARD_FXS_H */ +#endif /* CARD_FXS_H */ diff --git a/drivers/dahdi/xpp/card_global.c b/drivers/dahdi/xpp/card_global.c index b786f31..8918e5c 100644 --- a/drivers/dahdi/xpp/card_global.c +++ b/drivers/dahdi/xpp/card_global.c @@ -32,21 +32,22 @@ static const char rcsid[] = "$Id$"; -DEF_PARM(charp,initdir, "/usr/share/dahdi", 0644, "The directory of card initialization scripts"); +DEF_PARM(charp, initdir, "/usr/share/dahdi", 0644, + "The directory of card initialization scripts"); #define CHIP_REGISTERS "chipregs" -extern int debug; +extern int debug; /*---------------- GLOBAL PROC handling -----------------------------------*/ -static int send_magic_request(xbus_t *xbus, - unsigned unit, xportno_t portno, bool eoftx) +static int send_magic_request(xbus_t *xbus, unsigned unit, xportno_t portno, + bool eoftx) { - xframe_t *xframe; - xpacket_t *pack; - reg_cmd_t *reg_cmd; - int ret; + xframe_t *xframe; + xpacket_t *pack; + reg_cmd_t *reg_cmd; + int ret; /* * Zero length multibyte is legal and has special meaning for the @@ -65,15 +66,15 @@ static int send_magic_request(xbus_t *xbus, dump_xframe(__func__, xbus, xframe, debug); ret = send_cmd_frame(xbus, xframe); if (ret < 0) - PORT_ERR(xbus, unit, portno, - "%s: failed sending xframe\n", __func__); + PORT_ERR(xbus, unit, portno, "%s: failed sending xframe\n", + __func__); return ret; } static int parse_hexbyte(const char *buf) { - char *endp; - unsigned val; + char *endp; + unsigned val; val = simple_strtoul(buf, &endp, 16); if (*endp != '\0' || val > 0xFF) @@ -83,26 +84,26 @@ static int parse_hexbyte(const char *buf) static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) { - int argno; - char num_args; - int portno; - bool writing; - int op; /* [W]rite, [R]ead */ - int addr_mode; /* [D]irect, [I]ndirect, [Mm]ulti */ - bool do_subreg = 0; - int regnum; - int subreg; - int data_low; - bool do_datah; - int data_high; - int ret = -EBADR; + int argno; + char num_args; + int portno; + bool writing; + int op; /* [W]rite, [R]ead */ + int addr_mode; /* [D]irect, [I]ndirect, [Mm]ulti */ + bool do_subreg = 0; + int regnum; + int subreg; + int data_low; + bool do_datah; + int data_high; + int ret = -EBADR; - num_args = 2; /* port + operation */ + num_args = 2; /* port + operation */ if (argc < num_args) { XPD_ERR(xpd, "Not enough arguments (%d)\n", argc); XPD_ERR(xpd, - "Any Command is composed of at least %d words (got only %d)\n", - num_args, argc); + "Any Command is composed of at least %d words (got only %d)\n", + num_args, argc); goto out; } /* Process the arguments */ @@ -125,47 +126,49 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) } op = argv[argno][0]; switch (op) { - case 'W': - writing = 1; - num_args++; /* data low */ - //XPD_DBG(REGS, xpd, "WRITING\n"); - break; - case 'R': - writing = 0; - //XPD_DBG(REGS, xpd, "READING\n"); - break; - default: - XPD_ERR(xpd, "Unknown operation type '%c'\n", op); - goto out; + case 'W': + writing = 1; + num_args++; /* data low */ + //XPD_DBG(REGS, xpd, "WRITING\n"); + break; + case 'R': + writing = 0; + //XPD_DBG(REGS, xpd, "READING\n"); + break; + default: + XPD_ERR(xpd, "Unknown operation type '%c'\n", op); + goto out; } addr_mode = argv[argno][1]; switch (addr_mode) { - case 'I': - XPD_NOTICE(xpd, "'I' is deprecated in register commands. Use 'S' instead.\n"); - /* fall through */ - case 'S': - do_subreg = 1; - num_args += 2; /* register + subreg */ - //XPD_DBG(REGS, xpd, "SUBREG\n"); - break; - case 'D': - do_subreg = 0; - num_args++; /* register */ - //XPD_DBG(REGS, xpd, "DIRECT\n"); - break; - case 'M': - case 'm': - if (op != 'W') { - XPD_ERR(xpd, - "Can use Multibyte (%c) only with op 'W'\n", addr_mode); - goto out; - } - num_args--; /* No data low */ - //XPD_DBG(REGS, xpd, "Multibyte (%c)\n", addr_mode); - break; - default: - XPD_ERR(xpd, "Unknown addressing type '%c'\n", addr_mode); + case 'I': + XPD_NOTICE(xpd, + "'I' is deprecated in register commands. Use 'S' instead.\n"); + /* fall through */ + case 'S': + do_subreg = 1; + num_args += 2; /* register + subreg */ + //XPD_DBG(REGS, xpd, "SUBREG\n"); + break; + case 'D': + do_subreg = 0; + num_args++; /* register */ + //XPD_DBG(REGS, xpd, "DIRECT\n"); + break; + case 'M': + case 'm': + if (op != 'W') { + XPD_ERR(xpd, + "Can use Multibyte (%c) only with op 'W'\n", + addr_mode); goto out; + } + num_args--; /* No data low */ + //XPD_DBG(REGS, xpd, "Multibyte (%c)\n", addr_mode); + break; + default: + XPD_ERR(xpd, "Unknown addressing type '%c'\n", addr_mode); + goto out; } if (argv[argno][2] != '\0') { XPD_ERR(xpd, "Bad operation field '%s'\n", argv[argno]); @@ -173,20 +176,21 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) } if (argc < num_args) { XPD_ERR(xpd, - "Command \"%s\" is composed of at least %d words (got only %d)\n", - argv[argno], num_args, argc); + "Command \"%s\" is composed of at least %d words (got only %d)\n", + argv[argno], num_args, argc); goto out; } argno++; if (addr_mode == 'M' || addr_mode == 'm') { if (argno < argc) { XPD_ERR(xpd, - "Magic-Multibyte(%c) with %d extra arguments\n", - addr_mode, argc - argno); + "Magic-Multibyte(%c) with %d extra arguments\n", + addr_mode, argc - argno); goto out; } - ret = send_magic_request(xpd->xbus, xpd->addr.unit, portno, - addr_mode == 'm'); + ret = + send_magic_request(xpd->xbus, xpd->addr.unit, portno, + addr_mode == 'm'); goto out; } /* Normal (non-Magic) register commands */ @@ -209,7 +213,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) } subreg = parse_hexbyte(argv[argno]); if (subreg < 0) { - XPD_ERR(xpd, "Illegal subregister number '%s'\n", argv[argno]); + XPD_ERR(xpd, "Illegal subregister number '%s'\n", + argv[argno]); goto out; } //XPD_DBG(REGS, xpd, "Subreg is %X\n", subreg); @@ -223,7 +228,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) } data_low = parse_hexbyte(argv[argno]); if (data_low < 0) { - XPD_ERR(xpd, "Illegal data_low number '%s'\n", argv[argno]); + XPD_ERR(xpd, "Illegal data_low number '%s'\n", + argv[argno]); goto out; } //XPD_DBG(REGS, xpd, "Data Low is %X\n", data_low); @@ -238,7 +244,8 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) } data_high = parse_hexbyte(argv[argno]); if (data_high < 0) { - XPD_ERR(xpd, "Illegal data_high number '%s'\n", argv[argno]); + XPD_ERR(xpd, "Illegal data_high number '%s'\n", + argv[argno]); goto out; } //XPD_DBG(REGS, xpd, "Data High is %X\n", data_high); @@ -246,41 +253,37 @@ static int execute_chip_command(xpd_t *xpd, const int argc, char *argv[]) } else data_high = 0; if (argno < argc) { - XPD_ERR(xpd, - "Command contains an extra %d argument\n", - argc - argno); + XPD_ERR(xpd, "Command contains an extra %d argument\n", + argc - argno); goto out; } #if 0 - XPD_DBG(REGS, xpd, - "portno=%d writing=%d regnum=%d do_subreg=%d subreg=%d dataL=%d do_datah=%d dataH=%d\n", - portno, /* portno */ - writing, /* writing */ - regnum, - do_subreg, /* use subreg */ - subreg, /* subreg */ - data_low, - do_datah, /* use data_high*/ - data_high); + XPD_DBG(REGS, xpd, "portno=%d writing=%d regnum=%d do_subreg=%d subreg=%d dataL=%d do_datah=%d dataH=%d\n", portno, /* portno */ + writing, /* writing */ + regnum, do_subreg, /* use subreg */ + subreg, /* subreg */ + data_low, do_datah, /* use data_high */ + data_high); #endif - ret = xpp_register_request(xpd->xbus, xpd, portno, - writing, regnum, do_subreg, subreg, - data_low, do_datah, data_high, 1); + ret = + xpp_register_request(xpd->xbus, xpd, portno, writing, regnum, + do_subreg, subreg, data_low, do_datah, + data_high, 1); out: return ret; } int parse_chip_command(xpd_t *xpd, char *cmdline) { - xbus_t *xbus; - int ret = -EBADR; - __u8 buf[MAX_PROC_WRITE]; - char *str; - char *p; - static const int MAX_ARGS = 10; - char *argv[MAX_ARGS + 1]; - int argc; - int i; + xbus_t *xbus; + int ret = -EBADR; + __u8 buf[MAX_PROC_WRITE]; + char *str; + char *p; + static const int MAX_ARGS = 10; + char *argv[MAX_ARGS + 1]; + int argc; + int i; BUG_ON(!xpd); xbus = xpd->xbus; @@ -295,10 +298,10 @@ int parse_chip_command(xpd_t *xpd, char *cmdline) *p = '\0'; if ((p = strchr(buf, ';')) != NULL) /* Truncate comments */ *p = '\0'; - for (p = buf; *p && (*p == ' ' || *p == '\t'); p++) /* Trim leading whitespace */ + for (p = buf; *p && (*p == ' ' || *p == '\t'); p++) /* Trim leading whitespace */ ; str = p; - for (i = 0; (p = strsep(&str, " \t")) != NULL && i < MAX_ARGS; ) { + for (i = 0; (p = strsep(&str, " \t")) != NULL && i < MAX_ARGS;) { if (*p != '\0') { argv[i] = p; // XPD_DBG(REGS, xpd, "ARG %d = '%s'\n", i, p); @@ -308,7 +311,8 @@ int parse_chip_command(xpd_t *xpd, char *cmdline) argv[i] = NULL; argc = i; if (p) { - XPD_ERR(xpd, "Too many words (%d) to process. Last was '%s'\n", i, p); + XPD_ERR(xpd, "Too many words (%d) to process. Last was '%s'\n", + i, p); goto out; } if (argc) @@ -328,9 +332,9 @@ static void global_packet_dump(const char *msg, xpacket_t *pack); /* 0x07 */ HOSTCMD(GLOBAL, AB_REQUEST) { - int ret = -ENODEV; - xframe_t *xframe; - xpacket_t *pack; + int ret = -ENODEV; + xframe_t *xframe; + xpacket_t *pack; if (!xbus) { DBG(DEVICES, "NO XBUS\n"); @@ -348,23 +352,24 @@ static void global_packet_dump(const char *msg, xpacket_t *pack); } int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno, - bool writing, __u8 regnum, bool do_subreg, __u8 subreg, - __u8 data_low, bool do_datah, __u8 data_high, bool should_reply) + bool writing, __u8 regnum, bool do_subreg, __u8 subreg, + __u8 data_low, bool do_datah, __u8 data_high, + bool should_reply) { - int ret = 0; - xframe_t *xframe; - xpacket_t *pack; - reg_cmd_t *reg_cmd; + int ret = 0; + xframe_t *xframe; + xpacket_t *pack; + reg_cmd_t *reg_cmd; if (!xbus) { DBG(REGS, "NO XBUS\n"); return -EINVAL; } - XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, xpd->xbus_idx); + XFRAME_NEW_CMD(xframe, pack, xbus, GLOBAL, REGISTER_REQUEST, + xpd->xbus_idx); LINE_DBG(REGS, xpd, portno, "%c%c %02X %02X %02X %02X\n", - (writing)?'W':'R', - (do_subreg)?'S':'D', - regnum, subreg, data_low, data_high); + (writing) ? 'W' : 'R', (do_subreg) ? 'S' : 'D', regnum, subreg, + data_low, data_high); reg_cmd = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REQUEST, reg_cmd); reg_cmd->bytes = sizeof(*reg_cmd) - 1; // do not count the 'bytes' field reg_cmd->is_multibyte = 0; @@ -387,7 +392,8 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno, if (should_reply) xpd->requested_reply = *reg_cmd; if (debug & DBG_REGS) { - dump_reg_cmd("REG_REQ", 1, xbus, xpd->addr.unit, reg_cmd->portnum, reg_cmd); + dump_reg_cmd("REG_REQ", 1, xbus, xpd->addr.unit, + reg_cmd->portnum, reg_cmd); dump_packet("REG_REQ", pack, 1); } if (!xframe->usec_towait) { /* default processing time of SPI */ @@ -405,9 +411,9 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno, */ /* 0x19 */ HOSTCMD(GLOBAL, SYNC_SOURCE, enum sync_mode mode, int drift) { - xframe_t *xframe; - xpacket_t *pack; - const char *mode_name; + xframe_t *xframe; + xpacket_t *pack; + const char *mode_name; BUG_ON(!xbus); if ((mode_name = sync_mode_name(mode)) == NULL) { @@ -424,8 +430,8 @@ int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno, /* 0x23 */ HOSTCMD(GLOBAL, RESET_SYNC_COUNTERS) { - xframe_t *xframe; - xpacket_t *pack; + xframe_t *xframe; + xpacket_t *pack; BUG_ON(!xbus); //XBUS_DBG(SYNC, xbus, "\n"); @@ -443,14 +449,14 @@ HANDLER_DEF(GLOBAL, NULL_REPLY) return 0; } -HANDLER_DEF(GLOBAL, AB_DESCRIPTION) /* 0x08 */ -{ - struct xbus_workqueue *worker; - __u8 rev; - struct unit_descriptor *units; - int count_units; - int i; - int ret = 0; +HANDLER_DEF(GLOBAL, AB_DESCRIPTION) +{ /* 0x08 */ + struct xbus_workqueue *worker; + __u8 rev; + struct unit_descriptor *units; + int count_units; + int i; + int ret = 0; if (!xbus) { NOTICE("%s: xbus is gone!!!\n", __func__); @@ -462,19 +468,18 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION) /* 0x08 */ count_units /= sizeof(*units); if (rev != XPP_PROTOCOL_VERSION) { XBUS_NOTICE(xbus, "Bad protocol version %d (should be %d)\n", - rev, XPP_PROTOCOL_VERSION); + rev, XPP_PROTOCOL_VERSION); ret = -EPROTO; goto proto_err; } if (count_units > NUM_UNITS) { XBUS_NOTICE(xbus, "Too many units %d (should be %d)\n", - count_units, NUM_UNITS); + count_units, NUM_UNITS); ret = -EPROTO; goto proto_err; } if (count_units <= 0) { - XBUS_NOTICE(xbus, "Empty astribank? (%d units)\n", - count_units); + XBUS_NOTICE(xbus, "Empty astribank? (%d units)\n", count_units); ret = -EPROTO; goto proto_err; } @@ -482,7 +487,8 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION) /* 0x08 */ ret = -EPROTO; goto proto_err; } - XBUS_INFO(xbus, "DESCRIPTOR: %d cards, protocol revision %d\n", count_units, rev); + XBUS_INFO(xbus, "DESCRIPTOR: %d cards, protocol revision %d\n", + count_units, rev); if (xbus_check_unique(xbus)) return -EBUSY; xbus->revision = rev; @@ -493,11 +499,13 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION) /* 0x08 */ goto out; } for (i = 0; i < count_units; i++) { - struct unit_descriptor *this_unit = &units[i]; - struct card_desc_struct *card_desc; - unsigned long flags; + struct unit_descriptor *this_unit = &units[i]; + struct card_desc_struct *card_desc; + unsigned long flags; - if ((card_desc = KZALLOC(sizeof(struct card_desc_struct), GFP_ATOMIC)) == NULL) { + if ((card_desc = + KZALLOC(sizeof(struct card_desc_struct), + GFP_ATOMIC)) == NULL) { XBUS_ERR(xbus, "Card description allocation failed.\n"); ret = -ENOMEM; goto out; @@ -510,16 +518,14 @@ HANDLER_DEF(GLOBAL, AB_DESCRIPTION) /* 0x08 */ card_desc->numchips = this_unit->numchips; card_desc->ports_per_chip = this_unit->ports_per_chip; card_desc->port_dir = this_unit->port_dir; - card_desc->ports = card_desc->numchips * card_desc->ports_per_chip; - XBUS_INFO(xbus, " CARD %d type=%d.%d ports=%d (%dx%d), port-dir=0x%02X\n", - card_desc->xpd_addr.unit, - card_desc->type, - card_desc->subtype, - card_desc->ports, - card_desc->numchips, - card_desc->ports_per_chip, - card_desc->port_dir - ); + card_desc->ports = + card_desc->numchips * card_desc->ports_per_chip; + XBUS_INFO(xbus, + " CARD %d type=%d.%d ports=%d (%dx%d), port-dir=0x%02X\n", + card_desc->xpd_addr.unit, card_desc->type, + card_desc->subtype, card_desc->ports, + card_desc->numchips, card_desc->ports_per_chip, + card_desc->port_dir); spin_lock_irqsave(&worker->worker_lock, flags); worker->num_units++; XBUS_COUNTER(xbus, UNITS)++; @@ -539,21 +545,23 @@ out: HANDLER_DEF(GLOBAL, REGISTER_REPLY) { - reg_cmd_t *reg = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REPLY, regcmd); + reg_cmd_t *reg = &RPACKET_FIELD(pack, GLOBAL, REGISTER_REPLY, regcmd); if (!xpd) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) < 5) notify_bad_xpd(__func__, xbus, XPACKET_ADDR(pack), ""); return -EPROTO; } if (debug & DBG_REGS) { - dump_reg_cmd("REG_REPLY", 0, xbus, xpd->addr.unit, reg->portnum, reg); + dump_reg_cmd("REG_REPLY", 0, xbus, xpd->addr.unit, reg->portnum, + reg); dump_packet("REG_REPLY", pack, 1); } - if (! XMETHOD(card_register_reply, xpd)) { - XPD_ERR(xpd, "REGISTER_REPLY: without card_register_reply() method\n"); + if (!XMETHOD(card_register_reply, xpd)) { + XPD_ERR(xpd, + "REGISTER_REPLY: without card_register_reply() method\n"); return -EINVAL; } return CALL_XMETHOD(card_register_reply, xpd, reg); @@ -561,9 +569,9 @@ HANDLER_DEF(GLOBAL, REGISTER_REPLY) HANDLER_DEF(GLOBAL, SYNC_REPLY) { - __u8 mode = RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, sync_mode); - __u8 drift = RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, drift); - const char *mode_name; + __u8 mode = RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, sync_mode); + __u8 drift = RPACKET_FIELD(pack, GLOBAL, SYNC_REPLY, drift); + const char *mode_name; BUG_ON(!xbus); if ((mode_name = sync_mode_name(mode)) == NULL) { @@ -580,10 +588,10 @@ HANDLER_DEF(GLOBAL, SYNC_REPLY) HANDLER_DEF(GLOBAL, ERROR_CODE) { - char tmp_name[TMP_NAME_LEN]; - static long rate_limit; - __u8 category_code; - __u8 errorbits; + char tmp_name[TMP_NAME_LEN]; + static long rate_limit; + __u8 category_code; + __u8 errorbits; BUG_ON(!xbus); if ((rate_limit++ % 5003) > 200) @@ -592,12 +600,14 @@ HANDLER_DEF(GLOBAL, ERROR_CODE) errorbits = RPACKET_FIELD(pack, GLOBAL, ERROR_CODE, errorbits); if (!xpd) { snprintf(tmp_name, TMP_NAME_LEN, "%s(%1d%1d)", xbus->busname, - XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack)); + XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack)); } else { - snprintf(tmp_name, TMP_NAME_LEN, "%s/%s", xbus->busname, xpd->xpdname); + snprintf(tmp_name, TMP_NAME_LEN, "%s/%s", xbus->busname, + xpd->xpdname); } - NOTICE("%s: FIRMWARE %s: category=%d errorbits=0x%02X (rate_limit=%ld)\n", - tmp_name, cmd->name, category_code, errorbits, rate_limit); + NOTICE + ("%s: FIRMWARE %s: category=%d errorbits=0x%02X (rate_limit=%ld)\n", + tmp_name, cmd->name, category_code, errorbits, rate_limit); dump_packet("FIRMWARE: ", pack, 1); /* * FIXME: Should implement an error recovery plan @@ -605,24 +615,20 @@ HANDLER_DEF(GLOBAL, ERROR_CODE) return 0; } - xproto_table_t PROTO_TABLE(GLOBAL) = { .entries = { - /* Prototable Card Opcode */ - XENTRY( GLOBAL, GLOBAL, NULL_REPLY ), - XENTRY( GLOBAL, GLOBAL, AB_DESCRIPTION ), - XENTRY( GLOBAL, GLOBAL, SYNC_REPLY ), - XENTRY( GLOBAL, GLOBAL, ERROR_CODE ), - XENTRY( GLOBAL, GLOBAL, REGISTER_REPLY ), - }, - .name = "GLOBAL", - .packet_is_valid = global_packet_is_valid, - .packet_dump = global_packet_dump, -}; + /* Prototable Card Opcode */ +XENTRY(GLOBAL, GLOBAL, NULL_REPLY), XENTRY(GLOBAL, GLOBAL, + AB_DESCRIPTION), + XENTRY(GLOBAL, GLOBAL, SYNC_REPLY), + XENTRY(GLOBAL, GLOBAL, ERROR_CODE), + XENTRY(GLOBAL, GLOBAL, REGISTER_REPLY),},.name = + "GLOBAL",.packet_is_valid = + global_packet_is_valid,.packet_dump = global_packet_dump,}; static bool global_packet_is_valid(xpacket_t *pack) { - const xproto_entry_t *xe; + const xproto_entry_t *xe; //DBG(GENERAL, "\n"); xe = xproto_global_entry(XPACKET_OP(pack)); @@ -638,26 +644,26 @@ static void global_packet_dump(const char *msg, xpacket_t *pack) int run_initialize_registers(xpd_t *xpd) { - int ret; - xbus_t *xbus; - char busstr[MAX_ENV_STR]; - char busnumstr[MAX_ENV_STR]; - char modelstr[MAX_ENV_STR]; - char unitstr[MAX_ENV_STR]; - char subunitsstr[MAX_ENV_STR]; - char typestr[MAX_ENV_STR]; - char directionstr[MAX_ENV_STR]; - char revstr[MAX_ENV_STR]; - char connectorstr[MAX_ENV_STR]; - char xbuslabel[MAX_ENV_STR]; - char init_card[MAX_PATH_STR]; - __u8 direction_mask; - int i; - char *argv[] = { + int ret; + xbus_t *xbus; + char busstr[MAX_ENV_STR]; + char busnumstr[MAX_ENV_STR]; + char modelstr[MAX_ENV_STR]; + char unitstr[MAX_ENV_STR]; + char subunitsstr[MAX_ENV_STR]; + char typestr[MAX_ENV_STR]; + char directionstr[MAX_ENV_STR]; + char revstr[MAX_ENV_STR]; + char connectorstr[MAX_ENV_STR]; + char xbuslabel[MAX_ENV_STR]; + char init_card[MAX_PATH_STR]; + __u8 direction_mask; + int i; + char *argv[] = { init_card, NULL }; - char *envp[] = { + char *envp[] = { busstr, busnumstr, modelstr, @@ -684,40 +690,47 @@ int run_initialize_registers(xpd_t *xpd) } direction_mask = 0; for (i = 0; i < xpd->subunits; i++) { - xpd_t *su = xpd_byaddr(xbus, xpd->addr.unit, i); + xpd_t *su = xpd_byaddr(xbus, xpd->addr.unit, i); if (!su) { - XPD_ERR(xpd, - "Have %d subunits, but not subunit #%d\n", + XPD_ERR(xpd, "Have %d subunits, but not subunit #%d\n", xpd->subunits, i); continue; } - direction_mask |= (PHONEDEV(su).direction == TO_PHONE) ? BIT(i) : 0; + direction_mask |= + (PHONEDEV(su).direction == TO_PHONE) ? BIT(i) : 0; } snprintf(busstr, MAX_ENV_STR, "XBUS_NAME=%s", xbus->busname); snprintf(busnumstr, MAX_ENV_STR, "XBUS_NUMBER=%d", xbus->num); - snprintf(modelstr, MAX_ENV_STR, "XBUS_MODEL_STRING=%s", xbus->transport.model_string); + snprintf(modelstr, MAX_ENV_STR, "XBUS_MODEL_STRING=%s", + xbus->transport.model_string); snprintf(unitstr, MAX_ENV_STR, "UNIT_NUMBER=%d", xpd->addr.unit); snprintf(typestr, MAX_ENV_STR, "UNIT_TYPE=%d", xpd->type); snprintf(subunitsstr, MAX_ENV_STR, "UNIT_SUBUNITS=%d", xpd->subunits); - snprintf(directionstr, MAX_ENV_STR, "UNIT_SUBUNITS_DIR=%d", direction_mask); + snprintf(directionstr, MAX_ENV_STR, "UNIT_SUBUNITS_DIR=%d", + direction_mask); snprintf(revstr, MAX_ENV_STR, "XBUS_REVISION=%d", xbus->revision); - snprintf(connectorstr, MAX_ENV_STR, "XBUS_CONNECTOR=%s", xbus->connector); + snprintf(connectorstr, MAX_ENV_STR, "XBUS_CONNECTOR=%s", + xbus->connector); snprintf(xbuslabel, MAX_ENV_STR, "XBUS_LABEL=%s", xbus->label); - if (snprintf(init_card, MAX_PATH_STR, "%s/init_card_%d_%d", - initdir, xpd->type, xbus->revision) > MAX_PATH_STR) { - XPD_NOTICE(xpd, "Cannot initialize. pathname is longer than %d characters.\n", MAX_PATH_STR); + if (snprintf + (init_card, MAX_PATH_STR, "%s/init_card_%d_%d", initdir, xpd->type, + xbus->revision) > MAX_PATH_STR) { + XPD_NOTICE(xpd, + "Cannot initialize. pathname is longer than %d characters.\n", + MAX_PATH_STR); ret = -E2BIG; goto err; } if (!XBUS_IS(xbus, RECVD_DESC)) { - XBUS_ERR(xbus, "Skipped register initialization. In state %s.\n", - xbus_statename(XBUS_STATE(xbus))); + XBUS_ERR(xbus, + "Skipped register initialization. In state %s.\n", + xbus_statename(XBUS_STATE(xbus))); ret = -ENODEV; goto err; } XPD_DBG(DEVICES, xpd, "running '%s' for type=%d revision=%d\n", - init_card, xpd->type, xbus->revision); + init_card, xpd->type, xbus->revision); ret = call_usermodehelper(init_card, argv, envp, 1); /* * Carefully report results @@ -725,15 +738,18 @@ int run_initialize_registers(xpd_t *xpd) if (ret == 0) XPD_DBG(DEVICES, xpd, "'%s' finished OK\n", init_card); else if (ret < 0) { - XPD_ERR(xpd, "Failed running '%s' (errno %d)\n", init_card, ret); + XPD_ERR(xpd, "Failed running '%s' (errno %d)\n", init_card, + ret); } else { - __u8 exitval = ((unsigned)ret >> 8) & 0xFF; - __u8 sigval = ret & 0xFF; + __u8 exitval = ((unsigned)ret >> 8) & 0xFF; + __u8 sigval = ret & 0xFF; if (!exitval) { - XPD_ERR(xpd, "'%s' killed by signal %d\n", init_card, sigval); + XPD_ERR(xpd, "'%s' killed by signal %d\n", init_card, + sigval); } else { - XPD_ERR(xpd, "'%s' aborted with exitval %d\n", init_card, exitval); + XPD_ERR(xpd, "'%s' aborted with exitval %d\n", + init_card, exitval); } ret = -EINVAL; } diff --git a/drivers/dahdi/xpp/card_global.h b/drivers/dahdi/xpp/card_global.h index c8ce7a7..500fc7f 100644 --- a/drivers/dahdi/xpp/card_global.h +++ b/drivers/dahdi/xpp/card_global.h @@ -26,88 +26,59 @@ #include "xbus-pcm.h" enum global_opcodes { - XPROTO_NAME(GLOBAL, AB_REQUEST) = 0x07, - XPROTO_NAME(GLOBAL, AB_DESCRIPTION) = 0x08, - XPROTO_NAME(GLOBAL, REGISTER_REQUEST) = 0x0F, - XPROTO_NAME(GLOBAL, REGISTER_REPLY) = 0x10, -/**/ - XPROTO_NAME(GLOBAL, PCM_WRITE) = 0x11, - XPROTO_NAME(GLOBAL, PCM_READ) = 0x12, -/**/ - XPROTO_NAME(GLOBAL, SYNC_SOURCE) = 0x19, - XPROTO_NAME(GLOBAL, SYNC_REPLY) = 0x1A, -/**/ - XPROTO_NAME(GLOBAL, ERROR_CODE) = 0x22, - XPROTO_NAME(GLOBAL, RESET_SYNC_COUNTERS) = 0x23, - XPROTO_NAME(GLOBAL, NULL_REPLY) = 0xFE, + XPROTO_NAME(GLOBAL, AB_REQUEST) = 0x07, + XPROTO_NAME(GLOBAL, AB_DESCRIPTION) = 0x08, + XPROTO_NAME(GLOBAL, REGISTER_REQUEST) = 0x0F, + XPROTO_NAME(GLOBAL, REGISTER_REPLY) = 0x10, + /**/ XPROTO_NAME(GLOBAL, PCM_WRITE) = 0x11, + XPROTO_NAME(GLOBAL, PCM_READ) = 0x12, + /**/ XPROTO_NAME(GLOBAL, SYNC_SOURCE) = 0x19, + XPROTO_NAME(GLOBAL, SYNC_REPLY) = 0x1A, + /**/ XPROTO_NAME(GLOBAL, ERROR_CODE) = 0x22, + XPROTO_NAME(GLOBAL, RESET_SYNC_COUNTERS) = 0x23, + XPROTO_NAME(GLOBAL, NULL_REPLY) = 0xFE, }; struct unit_descriptor { - struct xpd_addr addr; - __u8 subtype:4; - __u8 type:4; - __u8 numchips; - __u8 ports_per_chip; - __u8 port_dir; /* bitmask: 0 - PSTN, 1 - PHONE */ - __u8 reserved[2]; - struct xpd_addr ec_addr; + struct xpd_addr addr; + __u8 subtype:4; + __u8 type:4; + __u8 numchips; + __u8 ports_per_chip; + __u8 port_dir; /* bitmask: 0 - PSTN, 1 - PHONE */ + __u8 reserved[2]; + struct xpd_addr ec_addr; }; #define NUM_UNITS 6 DEF_RPACKET_DATA(GLOBAL, NULL_REPLY); -DEF_RPACKET_DATA(GLOBAL, AB_REQUEST, - __u8 rev; - __u8 reserved; - ); -DEF_RPACKET_DATA(GLOBAL, AB_DESCRIPTION, - __u8 rev; - __u8 reserved[3]; - struct unit_descriptor unit_descriptor[NUM_UNITS]; - ); -DEF_RPACKET_DATA(GLOBAL, REGISTER_REQUEST, - reg_cmd_t reg_cmd; - ); -DEF_RPACKET_DATA(GLOBAL, PCM_WRITE, - xpp_line_t lines; - __u8 pcm[PCM_CHUNKSIZE]; - ); -DEF_RPACKET_DATA(GLOBAL, PCM_READ, - xpp_line_t lines; - __u8 pcm[PCM_CHUNKSIZE]; - ); -DEF_RPACKET_DATA(GLOBAL, SYNC_SOURCE, - __u8 sync_mode; - __u8 drift; - ); -DEF_RPACKET_DATA(GLOBAL, SYNC_REPLY, - __u8 sync_mode; - __u8 drift; - ); -DEF_RPACKET_DATA(GLOBAL, REGISTER_REPLY, - reg_cmd_t regcmd; - ); -DEF_RPACKET_DATA(GLOBAL, RESET_SYNC_COUNTERS, - __u8 mask; - ); -DEF_RPACKET_DATA(GLOBAL, ERROR_CODE, - __u8 category_code; - __u8 errorbits; - __u8 bad_packet[0]; - ); +DEF_RPACKET_DATA(GLOBAL, AB_REQUEST, __u8 rev; __u8 reserved;); +DEF_RPACKET_DATA(GLOBAL, AB_DESCRIPTION, __u8 rev; __u8 reserved[3]; + struct unit_descriptor unit_descriptor[NUM_UNITS];); +DEF_RPACKET_DATA(GLOBAL, REGISTER_REQUEST, reg_cmd_t reg_cmd;); +DEF_RPACKET_DATA(GLOBAL, PCM_WRITE, xpp_line_t lines; __u8 pcm[PCM_CHUNKSIZE];); +DEF_RPACKET_DATA(GLOBAL, PCM_READ, xpp_line_t lines; __u8 pcm[PCM_CHUNKSIZE];); +DEF_RPACKET_DATA(GLOBAL, SYNC_SOURCE, __u8 sync_mode; __u8 drift;); +DEF_RPACKET_DATA(GLOBAL, SYNC_REPLY, __u8 sync_mode; __u8 drift;); +DEF_RPACKET_DATA(GLOBAL, REGISTER_REPLY, reg_cmd_t regcmd;); +DEF_RPACKET_DATA(GLOBAL, RESET_SYNC_COUNTERS, __u8 mask;); +DEF_RPACKET_DATA(GLOBAL, ERROR_CODE, __u8 category_code; __u8 errorbits; + __u8 bad_packet[0];); /* 0x07 */ DECLARE_CMD(GLOBAL, AB_REQUEST); /* 0x19 */ DECLARE_CMD(GLOBAL, SYNC_SOURCE, enum sync_mode mode, int drift); /* 0x23 */ DECLARE_CMD(GLOBAL, RESET_SYNC_COUNTERS); int xpp_register_request(xbus_t *xbus, xpd_t *xpd, xportno_t portno, - bool writing, __u8 regnum, bool do_subreg, __u8 subreg, - __u8 data_low, bool do_datah, __u8 data_high, bool should_reply); + bool writing, __u8 regnum, bool do_subreg, __u8 subreg, + __u8 data_low, bool do_datah, __u8 data_high, + bool should_reply); int send_multibyte_request(xbus_t *xbus, unsigned unit, xportno_t portno, - bool eoftx, __u8 *buf, unsigned len); + bool eoftx, __u8 *buf, unsigned len); extern xproto_table_t PROTO_TABLE(GLOBAL); int run_initialize_registers(xpd_t *xpd); int parse_chip_command(xpd_t *xpd, char *cmdline); extern charp initdir; -#endif /* CARD_GLOBAL_H */ +#endif /* CARD_GLOBAL_H */ diff --git a/drivers/dahdi/xpp/card_pri.c b/drivers/dahdi/xpp/card_pri.c index 2abc944..27f1c51 100644 --- a/drivers/dahdi/xpp/card_pri.c +++ b/drivers/dahdi/xpp/card_pri.c @@ -36,7 +36,8 @@ static const char rcsid[] = "$Id$"; static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ -static DEF_PARM(uint, poll_interval, 500, 0644, "Poll channel state interval in milliseconds (0 - disable)"); +static DEF_PARM(uint, poll_interval, 500, 0644, + "Poll channel state interval in milliseconds (0 - disable)"); #define PRI_LINES_BITMASK BITMASK(31) #define PRI_SIGCAP ( \ @@ -66,7 +67,7 @@ static bool is_sigtype_dchan(int sigtype) return 0; } -#define MAX_SLAVES 4 /* we have MUX of 4 clocks */ +#define MAX_SLAVES 4 /* we have MUX of 4 clocks */ #define PRI_PORT(xpd) ((xpd)->addr.subunit) #define CHAN_PER_REGS(p) (((p)->is_esf) ? 2 : 4) @@ -85,10 +86,10 @@ static int apply_pri_protocol(xpd_t *xpd); #define PROC_REGISTER_FNAME "slics" enum pri_protocol { - PRI_PROTO_0 = 0, - PRI_PROTO_E1 = 1, - PRI_PROTO_T1 = 2, - PRI_PROTO_J1 = 3 + PRI_PROTO_0 = 0, + PRI_PROTO_E1 = 1, + PRI_PROTO_T1 = 2, + PRI_PROTO_J1 = 3 }; static const char *protocol_names[] = { @@ -121,13 +122,13 @@ static int pri_num_channels(enum pri_protocol pri_protocol) [PRI_PROTO_E1] = 31, [PRI_PROTO_T1] = 24, [PRI_PROTO_J1] = 0 - }; + }; return num_channels[pri_protocol]; } static const char *type_name(enum pri_protocol pri_protocol) { - static const char *names[4] = { + static const char *names[4] = { [PRI_PROTO_0] = "PRI-Unknown", [PRI_PROTO_E1] = "E1", [PRI_PROTO_T1] = "T1", @@ -142,17 +143,15 @@ static int pri_linecompat(enum pri_protocol pri_protocol) static const int linecompat[] = { [PRI_PROTO_0] = 0, [PRI_PROTO_E1] = - /* coding */ - DAHDI_CONFIG_CCS | - DAHDI_CONFIG_CRC4 | - /* framing */ - DAHDI_CONFIG_AMI | DAHDI_CONFIG_HDB3, + /* coding */ + DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4 | + /* framing */ + DAHDI_CONFIG_AMI | DAHDI_CONFIG_HDB3, [PRI_PROTO_T1] = - /* coding */ - DAHDI_CONFIG_D4 | - DAHDI_CONFIG_ESF | - /* framing */ - DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS, + /* coding */ + DAHDI_CONFIG_D4 | DAHDI_CONFIG_ESF | + /* framing */ + DAHDI_CONFIG_AMI | DAHDI_CONFIG_B8ZS, [PRI_PROTO_J1] = 0 }; @@ -163,29 +162,29 @@ static int pri_linecompat(enum pri_protocol pri_protocol) #define PRI_DCHAN_IDX(priv) ((priv)->dchan_num - 1) enum pri_led_state { - PRI_LED_OFF = 0x0, - PRI_LED_ON = 0x1, + PRI_LED_OFF = 0x0, + PRI_LED_ON = 0x1, /* * We blink by software from driver, so that * if the driver malfunction that blink would stop. */ - // PRI_LED_BLINK_SLOW = 0x2, /* 1/2 a second blink cycle */ - // PRI_LED_BLINK_FAST = 0x3 /* 1/4 a second blink cycle */ + // PRI_LED_BLINK_SLOW = 0x2, /* 1/2 a second blink cycle */ + // PRI_LED_BLINK_FAST = 0x3 /* 1/4 a second blink cycle */ }; enum pri_led_selectors { - BOTTOM_RED_LED = 0, - BOTTOM_GREEN_LED = 1, - TOP_RED_LED = 2, - TOP_GREEN_LED = 3, + BOTTOM_RED_LED = 0, + BOTTOM_GREEN_LED = 1, + TOP_RED_LED = 2, + TOP_GREEN_LED = 3, }; #define NUM_LEDS 4 struct pri_leds { - __u8 state:2; /* enum pri_led_state */ - __u8 led_sel:2; /* enum pri_led_selectors */ - __u8 reserved:4; + __u8 state:2; /* enum pri_led_state */ + __u8 led_sel:2; /* enum pri_led_selectors */ + __u8 reserved:4; }; #define REG_CCB1_T 0x2F /* Clear Channel Register 1 */ @@ -286,26 +285,26 @@ struct pri_leds { #define REG_CMR1_RS (BIT(5) | BIT(4)) #define REG_CMR1_STF BIT(2) -#define REG_RS1_E 0x70 /* Receive CAS Register 1 */ -#define REG_RS2_E 0x71 /* Receive CAS Register 2 */ -#define REG_RS3_E 0x72 /* Receive CAS Register 3 */ -#define REG_RS4_E 0x73 /* Receive CAS Register 4 */ -#define REG_RS5_E 0x74 /* Receive CAS Register 5 */ -#define REG_RS6_E 0x75 /* Receive CAS Register 6 */ -#define REG_RS7_E 0x76 /* Receive CAS Register 7 */ -#define REG_RS8_E 0x77 /* Receive CAS Register 8 */ -#define REG_RS9_E 0x78 /* Receive CAS Register 9 */ -#define REG_RS10_E 0x79 /* Receive CAS Register 10 */ -#define REG_RS11_E 0x7A /* Receive CAS Register 11 */ -#define REG_RS12_E 0x7B /* Receive CAS Register 12 */ -#define REG_RS13_E 0x7C /* Receive CAS Register 13 */ -#define REG_RS14_E 0x7D /* Receive CAS Register 14 */ -#define REG_RS15_E 0x7E /* Receive CAS Register 15 */ -#define REG_RS16_E 0x7F /* Receive CAS Register 16 */ +#define REG_RS1_E 0x70 /* Receive CAS Register 1 */ +#define REG_RS2_E 0x71 /* Receive CAS Register 2 */ +#define REG_RS3_E 0x72 /* Receive CAS Register 3 */ +#define REG_RS4_E 0x73 /* Receive CAS Register 4 */ +#define REG_RS5_E 0x74 /* Receive CAS Register 5 */ +#define REG_RS6_E 0x75 /* Receive CAS Register 6 */ +#define REG_RS7_E 0x76 /* Receive CAS Register 7 */ +#define REG_RS8_E 0x77 /* Receive CAS Register 8 */ +#define REG_RS9_E 0x78 /* Receive CAS Register 9 */ +#define REG_RS10_E 0x79 /* Receive CAS Register 10 */ +#define REG_RS11_E 0x7A /* Receive CAS Register 11 */ +#define REG_RS12_E 0x7B /* Receive CAS Register 12 */ +#define REG_RS13_E 0x7C /* Receive CAS Register 13 */ +#define REG_RS14_E 0x7D /* Receive CAS Register 14 */ +#define REG_RS15_E 0x7E /* Receive CAS Register 15 */ +#define REG_RS16_E 0x7F /* Receive CAS Register 16 */ -#define REG_PC2 0x81 /* Port Configuration 2 */ -#define REG_PC3 0x82 /* Port Configuration 3 */ -#define REG_PC4 0x83 /* Port Configuration 4 */ +#define REG_PC2 0x81 /* Port Configuration 2 */ +#define REG_PC3 0x82 /* Port Configuration 3 */ +#define REG_PC4 0x83 /* Port Configuration 4 */ #define REG_XPM2 0x28 /* Transmit Pulse Mask 2 */ @@ -319,48 +318,47 @@ struct pri_leds { #define NUM_CAS_RS_T (REG_RS12_E - REG_RS1_E + 1) struct PRI_priv_data { - bool clock_source; - enum pri_protocol pri_protocol; - xpp_line_t rbslines; - int deflaw; - unsigned int dchan_num; - bool initialized; - int is_cas; + bool clock_source; + enum pri_protocol pri_protocol; + xpp_line_t rbslines; + int deflaw; + unsigned int dchan_num; + bool initialized; + int is_cas; - unsigned int chanconfig_dchan; + unsigned int chanconfig_dchan; #define NO_DCHAN (0) #define DCHAN(p) ((p)->chanconfig_dchan) #define VALID_DCHAN(p) (DCHAN(p) != NO_DCHAN) #define SET_DCHAN(p, d) do { DCHAN(p) = (d); } while (0); - __u8 cas_rs_e[NUM_CAS_RS_E]; - __u8 cas_ts_e[NUM_CAS_RS_E]; - uint cas_replies; - bool is_esf; - bool local_loopback; - uint poll_noreplies; - uint layer1_replies; - __u8 reg_frs0; - __u8 reg_frs1; - bool layer1_up; - int alarms; - __u8 dchan_tx_sample; - __u8 dchan_rx_sample; - uint dchan_tx_counter; - uint dchan_rx_counter; - bool dchan_alive; - uint dchan_alive_ticks; - enum pri_led_state ledstate[NUM_LEDS]; + __u8 cas_rs_e[NUM_CAS_RS_E]; + __u8 cas_ts_e[NUM_CAS_RS_E]; + uint cas_replies; + bool is_esf; + bool local_loopback; + uint poll_noreplies; + uint layer1_replies; + __u8 reg_frs0; + __u8 reg_frs1; + bool layer1_up; + int alarms; + __u8 dchan_tx_sample; + __u8 dchan_rx_sample; + uint dchan_tx_counter; + uint dchan_rx_counter; + bool dchan_alive; + uint dchan_alive_ticks; + enum pri_led_state ledstate[NUM_LEDS]; }; -static xproto_table_t PROTO_TABLE(PRI); +static xproto_table_t PROTO_TABLE(PRI); DEF_RPACKET_DATA(PRI, SET_LED, /* Set one of the LED's */ - struct pri_leds pri_leds; - ); + struct pri_leds pri_leds;); - -static /* 0x33 */ DECLARE_CMD(PRI, SET_LED, enum pri_led_selectors led_sel, enum pri_led_state to_led_state); +static /* 0x33 */ DECLARE_CMD(PRI, SET_LED, enum pri_led_selectors led_sel, + enum pri_led_state to_led_state); #define DO_LED(xpd, which, tostate) \ CALL_PROTO(PRI, SET_LED, (xpd)->xbus, (xpd), (which), (tostate)) @@ -369,65 +367,52 @@ static /* 0x33 */ DECLARE_CMD(PRI, SET_LED, enum pri_led_selectors led_sel, enum static int query_subunit(xpd_t *xpd, __u8 regnum) { - XPD_DBG(REGS, xpd, "(%d%d): REG=0x%02X\n", - xpd->addr.unit, xpd->addr.subunit, - regnum); - return xpp_register_request( - xpd->xbus, xpd, - PRI_PORT(xpd), /* portno */ - 0, /* writing */ - regnum, - 0, /* do_subreg */ - 0, /* subreg */ - 0, /* data_L */ - 0, /* do_datah */ - 0, /* data_H */ - 0 /* should_reply */ - ); + XPD_DBG(REGS, xpd, "(%d%d): REG=0x%02X\n", xpd->addr.unit, + xpd->addr.subunit, regnum); + return xpp_register_request(xpd->xbus, xpd, PRI_PORT(xpd), /* portno */ + 0, /* writing */ + regnum, 0, /* do_subreg */ + 0, /* subreg */ + 0, /* data_L */ + 0, /* do_datah */ + 0, /* data_H */ + 0 /* should_reply */ + ); } - static int write_subunit(xpd_t *xpd, __u8 regnum, __u8 val) { - XPD_DBG(REGS, xpd, "(%d%d): REG=0x%02X dataL=0x%02X\n", - xpd->addr.unit, xpd->addr.subunit, - regnum, val); - return xpp_register_request( - xpd->xbus, xpd, - PRI_PORT(xpd), /* portno */ - 1, /* writing */ - regnum, - 0, /* do_subreg */ - 0, /* subreg */ - val, /* data_L */ - 0, /* do_datah */ - 0, /* data_H */ - 0 /* should_reply */ - ); + XPD_DBG(REGS, xpd, "(%d%d): REG=0x%02X dataL=0x%02X\n", xpd->addr.unit, + xpd->addr.subunit, regnum, val); + return xpp_register_request(xpd->xbus, xpd, PRI_PORT(xpd), /* portno */ + 1, /* writing */ + regnum, 0, /* do_subreg */ + 0, /* subreg */ + val, /* data_L */ + 0, /* do_datah */ + 0, /* data_H */ + 0 /* should_reply */ + ); } static int pri_write_reg(xpd_t *xpd, int regnum, __u8 val) { - XPD_DBG(REGS, xpd, "(%d%d): REG=0x%02X dataL=0x%02X\n", - xpd->addr.unit, xpd->addr.subunit, - regnum, val); - return xpp_register_request( - xpd->xbus, xpd, - 0, /* portno=0 */ - 1, /* writing */ - regnum, - 0, /* do_subreg */ - 0, /* subreg */ - val, /* data_L */ - 0, /* do_datah */ - 0, /* data_H */ - 0 /* should_reply */ - ); + XPD_DBG(REGS, xpd, "(%d%d): REG=0x%02X dataL=0x%02X\n", xpd->addr.unit, + xpd->addr.subunit, regnum, val); + return xpp_register_request(xpd->xbus, xpd, 0, /* portno=0 */ + 1, /* writing */ + regnum, 0, /* do_subreg */ + 0, /* subreg */ + val, /* data_L */ + 0, /* do_datah */ + 0, /* data_H */ + 0 /* should_reply */ + ); } static int cas_regbase(xpd_t *xpd) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; priv = xpd->priv; switch (priv->pri_protocol) { @@ -447,7 +432,7 @@ static int cas_regbase(xpd_t *xpd) static int cas_numregs(xpd_t *xpd) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; priv = xpd->priv; switch (priv->pri_protocol) { @@ -467,11 +452,11 @@ static int cas_numregs(xpd_t *xpd) static int write_cas_reg(xpd_t *xpd, int rsnum, __u8 val) { - struct PRI_priv_data *priv; - int regbase = cas_regbase(xpd); - int num_cas_rs = cas_numregs(xpd); - int regnum; - bool is_d4 = 0; + struct PRI_priv_data *priv; + int regbase = cas_regbase(xpd); + int num_cas_rs = cas_numregs(xpd); + int regnum; + bool is_d4 = 0; BUG_ON(!xpd); priv = xpd->priv; @@ -490,8 +475,8 @@ static int write_cas_reg(xpd_t *xpd, int rsnum, __u8 val) if (is_d4) { /* same data should be copied to RS7..12 in D4 only */ regnum = REG_RS7_E + rsnum; - XPD_DBG(SIGNAL, xpd, "RBS(TX): reg=0x%X val=0x%02X\n", - regnum, val); + XPD_DBG(SIGNAL, xpd, "RBS(TX): reg=0x%X val=0x%02X\n", regnum, + val); write_subunit(xpd, regnum, val); } return 0; @@ -499,26 +484,24 @@ static int write_cas_reg(xpd_t *xpd, int rsnum, __u8 val) static bool valid_pri_modes(const xpd_t *xpd) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; - if ( - priv->pri_protocol != PRI_PROTO_E1 && - priv->pri_protocol != PRI_PROTO_T1 && - priv->pri_protocol != PRI_PROTO_J1) + if (priv->pri_protocol != PRI_PROTO_E1 + && priv->pri_protocol != PRI_PROTO_T1 + && priv->pri_protocol != PRI_PROTO_J1) return 0; return 1; } -static void PRI_card_pcm_recompute(xpd_t *xpd, - xpp_line_t pcm_mask) +static void PRI_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask) { - struct PRI_priv_data *priv; - int i; - int line_count = 0; - unsigned long flags; - uint pcm_len; + struct PRI_priv_data *priv; + int i; + int line_count = 0; + unsigned long flags; + uint pcm_len; BUG_ON(!xpd); priv = xpd->priv; @@ -527,8 +510,8 @@ static void PRI_card_pcm_recompute(xpd_t *xpd, /* Add/remove all the trivial cases */ pcm_mask |= PHONEDEV(xpd).offhook_state; for_each_line(xpd, i) - if (IS_SET(pcm_mask, i)) - line_count++; + if (IS_SET(pcm_mask, i)) + line_count++; if (priv->is_cas) { if (priv->pri_protocol == PRI_PROTO_E1) { /* CAS: Don't send PCM to D-Channel */ @@ -545,9 +528,8 @@ static void PRI_card_pcm_recompute(xpd_t *xpd, line_count = 1; } pcm_len = (line_count) - ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + - line_count * DAHDI_CHUNKSIZE - : 0L; + ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + + line_count * DAHDI_CHUNKSIZE : 0L; update_wanted_pcm_mask(xpd, pcm_mask, pcm_len); spin_unlock_irqrestore(&PHONEDEV(xpd).lock_recompute_pcm, flags); } @@ -559,55 +541,58 @@ static void PRI_card_pcm_recompute(xpd_t *xpd, */ static int set_pri_proto(xpd_t *xpd, enum pri_protocol set_proto) { - struct PRI_priv_data *priv; - int deflaw; - unsigned int dchan_num; - int default_lineconfig = 0; - int ret; - struct phonedev *phonedev; + struct PRI_priv_data *priv; + int deflaw; + unsigned int dchan_num; + int default_lineconfig = 0; + int ret; + struct phonedev *phonedev; BUG_ON(!xpd); priv = xpd->priv; phonedev = &PHONEDEV(xpd); if (test_bit(DAHDI_FLAGBIT_REGISTERED, &phonedev->span.flags)) { XPD_NOTICE(xpd, "%s: %s already assigned as span %d\n", - __func__, phonedev->span.name, phonedev->span.spanno); + __func__, phonedev->span.name, + phonedev->span.spanno); return -EBUSY; } if (priv->pri_protocol != PRI_PROTO_0) { if (priv->pri_protocol == set_proto) { - XPD_NOTICE(xpd, "Already in protocol %s. Ignored\n", pri_protocol_name(set_proto)); + XPD_NOTICE(xpd, "Already in protocol %s. Ignored\n", + pri_protocol_name(set_proto)); return 0; } else { XPD_INFO(xpd, "Switching from %s to %s\n", - pri_protocol_name(priv->pri_protocol), - pri_protocol_name(set_proto)); + pri_protocol_name(priv->pri_protocol), + pri_protocol_name(set_proto)); } } switch (set_proto) { - case PRI_PROTO_E1: - deflaw = DAHDI_LAW_ALAW; - dchan_num = 16; - default_lineconfig = DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4 | DAHDI_CONFIG_HDB3; - break; - case PRI_PROTO_T1: - deflaw = DAHDI_LAW_MULAW; - dchan_num = 24; - default_lineconfig = DAHDI_CONFIG_ESF | DAHDI_CONFIG_B8ZS; - break; - case PRI_PROTO_J1: - /* - * Check all assumptions - */ - deflaw = DAHDI_LAW_MULAW; - dchan_num = 24; - default_lineconfig = 0; /* FIXME: J1??? */ - XPD_NOTICE(xpd, "J1 is not supported yet\n"); - return -ENOSYS; - default: - XPD_ERR(xpd, "%s: Unknown pri protocol = %d\n", - __func__, set_proto); - return -EINVAL; + case PRI_PROTO_E1: + deflaw = DAHDI_LAW_ALAW; + dchan_num = 16; + default_lineconfig = + DAHDI_CONFIG_CCS | DAHDI_CONFIG_CRC4 | DAHDI_CONFIG_HDB3; + break; + case PRI_PROTO_T1: + deflaw = DAHDI_LAW_MULAW; + dchan_num = 24; + default_lineconfig = DAHDI_CONFIG_ESF | DAHDI_CONFIG_B8ZS; + break; + case PRI_PROTO_J1: + /* + * Check all assumptions + */ + deflaw = DAHDI_LAW_MULAW; + dchan_num = 24; + default_lineconfig = 0; /* FIXME: J1??? */ + XPD_NOTICE(xpd, "J1 is not supported yet\n"); + return -ENOSYS; + default: + XPD_ERR(xpd, "%s: Unknown pri protocol = %d\n", __func__, + set_proto); + return -EINVAL; } priv->pri_protocol = set_proto; priv->is_cas = -1; @@ -619,11 +604,8 @@ static int set_pri_proto(xpd_t *xpd, enum pri_protocol set_proto) priv->local_loopback = 0; xpd->type_name = type_name(priv->pri_protocol); XPD_DBG(GENERAL, xpd, "%s, channels=%d, dchan_num=%d, deflaw=%d\n", - pri_protocol_name(set_proto), - phonedev->channels, - priv->dchan_num, - priv->deflaw - ); + pri_protocol_name(set_proto), phonedev->channels, + priv->dchan_num, priv->deflaw); /* * Must set default now, so layer1 polling (Register REG_FRS0) would * give reliable results. @@ -638,10 +620,10 @@ static int set_pri_proto(xpd_t *xpd, enum pri_protocol set_proto) static void dahdi_update_syncsrc(xpd_t *xpd) { - struct PRI_priv_data *priv; - xpd_t *subxpd; - int best_spanno = 0; - int i; + struct PRI_priv_data *priv; + xpd_t *subxpd; + int best_spanno = 0; + int i; if (!SPAN_REGISTERED(xpd)) return; @@ -652,7 +634,8 @@ static void dahdi_update_syncsrc(xpd_t *xpd) priv = subxpd->priv; if (priv->clock_source && priv->alarms == 0) { if (best_spanno) - XPD_ERR(xpd, "Duplicate XPD's with clock_source=1\n"); + XPD_ERR(xpd, + "Duplicate XPD's with clock_source=1\n"); best_spanno = PHONEDEV(subxpd).span.spanno; } } @@ -661,7 +644,8 @@ static void dahdi_update_syncsrc(xpd_t *xpd) if (!subxpd) continue; if (PHONEDEV(subxpd).span.syncsrc == best_spanno) - XPD_DBG(SYNC, xpd, "Setting SyncSource to span %d\n", best_spanno); + XPD_DBG(SYNC, xpd, "Setting SyncSource to span %d\n", + best_spanno); else XPD_DBG(SYNC, xpd, "Slaving to span %d\n", best_spanno); PHONEDEV(subxpd).span.syncsrc = best_spanno; @@ -677,17 +661,17 @@ static void dahdi_update_syncsrc(xpd_t *xpd) */ static void set_clocking(xpd_t *xpd) { - xbus_t *xbus; - xpd_t *best_xpd = NULL; - int best_subunit = -1; /* invalid */ - unsigned int best_subunit_prio = INT_MAX; - int i; + xbus_t *xbus; + xpd_t *best_xpd = NULL; + int best_subunit = -1; /* invalid */ + unsigned int best_subunit_prio = INT_MAX; + int i; xbus = xpd->xbus; /* Find subunit with best timing priority */ for (i = 0; i < MAX_SLAVES; i++) { - struct PRI_priv_data *priv; - xpd_t *subxpd; + struct PRI_priv_data *priv; + xpd_t *subxpd; subxpd = xpd_byaddr(xbus, xpd->addr.unit, i); if (!subxpd) @@ -695,30 +679,35 @@ static void set_clocking(xpd_t *xpd) priv = subxpd->priv; if (priv->alarms != 0) continue; - if (PHONEDEV(subxpd).timing_priority > 0 && PHONEDEV(subxpd).timing_priority < best_subunit_prio) { + if (PHONEDEV(subxpd).timing_priority > 0 + && PHONEDEV(subxpd).timing_priority < best_subunit_prio) { best_xpd = subxpd; best_subunit = i; best_subunit_prio = PHONEDEV(subxpd).timing_priority; } } /* Now set it */ - if (best_xpd && ((struct PRI_priv_data *)(best_xpd->priv))->clock_source == 0) { - __u8 reg_pc_init[] = { VAL_PC_GPI, VAL_PC_GPI, VAL_PC_GPI }; + if (best_xpd + && ((struct PRI_priv_data *)(best_xpd->priv))->clock_source == 0) { + __u8 reg_pc_init[] = { VAL_PC_GPI, VAL_PC_GPI, VAL_PC_GPI }; for (i = 0; i < ARRAY_SIZE(reg_pc_init); i++) { - __u8 reg_pc = reg_pc_init[i]; + __u8 reg_pc = reg_pc_init[i]; - reg_pc |= (best_subunit & (1 << i)) ? VAL_PC_GPOH : VAL_PC_GPOL; + reg_pc |= + (best_subunit & (1 << i)) ? VAL_PC_GPOH : + VAL_PC_GPOL; XPD_DBG(SYNC, best_xpd, - "ClockSource Set: PC%d=0x%02X\n", 2+i, reg_pc); + "ClockSource Set: PC%d=0x%02X\n", 2 + i, + reg_pc); pri_write_reg(xpd, REG_PC2 + i, reg_pc); } ((struct PRI_priv_data *)(best_xpd->priv))->clock_source = 1; } /* clear old clock sources */ for (i = 0; i < MAX_SLAVES; i++) { - struct PRI_priv_data *priv; - xpd_t *subxpd; + struct PRI_priv_data *priv; + xpd_t *subxpd; subxpd = xpd_byaddr(xbus, xpd->addr.unit, i); if (subxpd && subxpd != best_xpd) { @@ -732,10 +721,10 @@ static void set_clocking(xpd_t *xpd) static void set_reg_lim0(const char *msg, xpd_t *xpd) { - struct PRI_priv_data *priv; - bool is_master_mode; - bool localloop; - __u8 lim0 = 0; + struct PRI_priv_data *priv; + bool is_master_mode; + bool localloop; + __u8 lim0 = 0; BUG_ON(!xpd); priv = xpd->priv; @@ -744,13 +733,13 @@ static void set_reg_lim0(const char *msg, xpd_t *xpd) localloop = priv->local_loopback; lim0 |= (localloop) ? REG_LIM0_LL : 0; if (is_master_mode) - lim0 |= REG_LIM0_MAS; + lim0 |= REG_LIM0_MAS; else lim0 &= ~REG_LIM0_MAS; XPD_DBG(SIGNAL, xpd, "%s(%s): %s, %s\n", __func__, msg, (is_master_mode) ? "MASTER" : "SLAVE", (localloop) ? "LOCALLOOP" : "NO_LOCALLOOP"); - write_subunit(xpd, REG_LIM0 , lim0); + write_subunit(xpd, REG_LIM0, lim0); } /* @@ -771,17 +760,18 @@ static int set_master_mode(const char *msg, xpd_t *xpd) static int set_localloop(xpd_t *xpd, bool localloop) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; if (SPAN_REGISTERED(xpd)) { XPD_NOTICE(xpd, "Registered as span %d. Cannot do %s\n", - PHONEDEV(xpd).span.spanno, __func__); + PHONEDEV(xpd).span.spanno, __func__); return -EBUSY; } priv->local_loopback = localloop; - XPD_DBG(SIGNAL, xpd, "%s: %s\n", __func__, (localloop) ? "LOCALLOOP" : "NO"); + XPD_DBG(SIGNAL, xpd, "%s: %s\n", __func__, + (localloop) ? "LOCALLOOP" : "NO"); set_master_mode(__func__, xpd); return 0; } @@ -789,19 +779,21 @@ static int set_localloop(xpd_t *xpd, bool localloop) #define VALID_CONFIG(bit, flg, str) [bit] = { .flags = flg, .name = str } static const struct { - const char *name; - const int flags; -} valid_spanconfigs[sizeof(unsigned int)*8] = { + const char *name; + const int flags; +} valid_spanconfigs[sizeof(unsigned int) * 8] = { /* These apply to T1 */ - VALID_CONFIG(4, DAHDI_CONFIG_D4, "D4"), - VALID_CONFIG(5, DAHDI_CONFIG_ESF, "ESF"), - VALID_CONFIG(6, DAHDI_CONFIG_AMI, "AMI"), - VALID_CONFIG(7, DAHDI_CONFIG_B8ZS, "B8ZS"), - /* These apply to E1 */ - VALID_CONFIG(8, DAHDI_CONFIG_CCS, "CCS"), - VALID_CONFIG(9, DAHDI_CONFIG_HDB3, "HDB3"), - VALID_CONFIG(10, DAHDI_CONFIG_CRC4, "CRC4"), -}; + VALID_CONFIG(4, DAHDI_CONFIG_D4, "D4"), VALID_CONFIG(5, + DAHDI_CONFIG_ESF, + "ESF"), + VALID_CONFIG(6, DAHDI_CONFIG_AMI, "AMI"), VALID_CONFIG(7, + DAHDI_CONFIG_B8ZS, + "B8ZS"), + /* These apply to E1 */ +VALID_CONFIG(8, DAHDI_CONFIG_CCS, "CCS"), VALID_CONFIG(9, + DAHDI_CONFIG_HDB3, + "HDB3"), + VALID_CONFIG(10, DAHDI_CONFIG_CRC4, "CRC4"),}; /* * Mark the lines as CLEAR or RBS signalling. @@ -813,14 +805,14 @@ static const struct { */ static void set_rbslines(xpd_t *xpd, int channo) { - struct PRI_priv_data *priv; - xpp_line_t new_rbslines = 0; - xpp_line_t modified_lines; - int i; + struct PRI_priv_data *priv; + xpp_line_t new_rbslines = 0; + xpp_line_t modified_lines; + int i; priv = xpd->priv; for_each_line(xpd, i) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); + struct dahdi_chan *chan = XPD_CHAN(xpd, i); if (chan->flags & DAHDI_FLAG_CLEAR) BIT_CLR(new_rbslines, i); @@ -829,15 +821,16 @@ static void set_rbslines(xpd_t *xpd, int channo) } new_rbslines &= BITMASK(PHONEDEV(xpd).channels); modified_lines = priv->rbslines ^ new_rbslines; - XPD_DBG(DEVICES, xpd, "RBSLINES-%d(%s): 0x%X\n", - channo, pri_protocol_name(priv->pri_protocol), new_rbslines); - if ((priv->pri_protocol == PRI_PROTO_T1) || (priv->pri_protocol == PRI_PROTO_J1)) { - __u8 clear_lines = 0; /* Mark clear lines */ - bool reg_changed = 0; + XPD_DBG(DEVICES, xpd, "RBSLINES-%d(%s): 0x%X\n", channo, + pri_protocol_name(priv->pri_protocol), new_rbslines); + if ((priv->pri_protocol == PRI_PROTO_T1) + || (priv->pri_protocol == PRI_PROTO_J1)) { + __u8 clear_lines = 0; /* Mark clear lines */ + bool reg_changed = 0; for_each_line(xpd, i) { - int bytenum = i / 8; - int bitnum = i % 8; + int bytenum = i / 8; + int bitnum = i % 8; if (!IS_SET(new_rbslines, i)) { BIT_SET(clear_lines, (7 - bitnum)); @@ -847,10 +840,14 @@ static void set_rbslines(xpd_t *xpd, int channo) if (bitnum == 7) { if (channo == 0 || reg_changed) { bytenum += REG_CCB1_T; - XPD_DBG(DEVICES, xpd, "RBS(%s): modified=0x%X rbslines=0x%X reg=0x%X clear_lines=0x%X\n", - pri_protocol_name(priv->pri_protocol), - modified_lines, new_rbslines, bytenum, clear_lines); - write_subunit(xpd, bytenum, clear_lines); + XPD_DBG(DEVICES, xpd, + "RBS(%s): modified=0x%X rbslines=0x%X reg=0x%X clear_lines=0x%X\n", + pri_protocol_name(priv-> + pri_protocol), + modified_lines, new_rbslines, + bytenum, clear_lines); + write_subunit(xpd, bytenum, + clear_lines); } clear_lines = 0; reg_changed = 0; @@ -862,7 +859,7 @@ static void set_rbslines(xpd_t *xpd, int channo) static int set_mode_cas(xpd_t *xpd, bool want_cas) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; priv = xpd->priv; XPD_INFO(xpd, "Setting TDM to %s\n", (want_cas) ? "CAS" : "PRI"); @@ -877,23 +874,23 @@ static int set_mode_cas(xpd_t *xpd, bool want_cas) static int pri_lineconfig(xpd_t *xpd, int lineconfig) { - struct PRI_priv_data *priv; - const char *framingstr = ""; - const char *codingstr = ""; - const char *crcstr = ""; + struct PRI_priv_data *priv; + const char *framingstr = ""; + const char *codingstr = ""; + const char *crcstr = ""; #ifdef JAPANEZE_SUPPORT - __u8 rc0 = 0; /* FIXME: PCM offsets */ + __u8 rc0 = 0; /* FIXME: PCM offsets */ #endif - __u8 fmr0 = 0; - __u8 fmr1 = REG_FMR1_ECM; - __u8 fmr2 = 0; - __u8 fmr3 = 0; /* write only for CRC4 */ - __u8 fmr4 = 0; - __u8 cmdr = REG_CMDR_RRES | REG_CMDR_XRES; - __u8 xsp = 0; - unsigned int bad_bits; - bool force_cas = 0; - int i; + __u8 fmr0 = 0; + __u8 fmr1 = REG_FMR1_ECM; + __u8 fmr2 = 0; + __u8 fmr3 = 0; /* write only for CRC4 */ + __u8 fmr4 = 0; + __u8 cmdr = REG_CMDR_RRES | REG_CMDR_XRES; + __u8 xsp = 0; + unsigned int bad_bits; + bool force_cas = 0; + int i; BUG_ON(!xpd); priv = xpd->priv; @@ -903,7 +900,7 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) bad_bits = lineconfig & pri_linecompat(priv->pri_protocol); bad_bits = bad_bits ^ lineconfig; for (i = 0; i < ARRAY_SIZE(valid_spanconfigs); i++) { - unsigned int flags = valid_spanconfigs[i].flags; + unsigned int flags = valid_spanconfigs[i].flags; if (bad_bits & BIT(i)) { if (flags) { @@ -920,8 +917,7 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) } } if (flags && flags != BIT(i)) { - ERR("%s: BUG: i=%d flags=0x%X\n", - __func__, i, flags); + ERR("%s: BUG: i=%d flags=0x%X\n", __func__, i, flags); // BUG(); } } @@ -930,19 +926,19 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) if (priv->pri_protocol == PRI_PROTO_E1) { fmr1 |= REG_FMR1_AFR; fmr2 = REG_FMR2_E_AXRA | REG_FMR2_E_ALMF; /* 0x03 */ - fmr4 = 0x9F; /* E1.XSW: All spare bits = 1*/ + fmr4 = 0x9F; /* E1.XSW: All spare bits = 1 */ xsp |= REG_XSP_E_EBP | REG_XSP_E_AXS | REG_XSP_E_XSIF; } else if (priv->pri_protocol == PRI_PROTO_T1) { fmr1 |= REG_FMR1_PMOD | REG_FMR1_T_CRC; fmr2 = REG_FMR2_T_SSP | REG_FMR2_T_AXRA; /* 0x22 */ fmr4 = 0x0C; xsp &= ~REG_FMR5_T_XTM; - force_cas = 1; /* T1 - Chip always in CAS mode */ + force_cas = 1; /* T1 - Chip always in CAS mode */ } else if (priv->pri_protocol == PRI_PROTO_J1) { fmr1 |= REG_FMR1_PMOD; fmr4 = 0x1C; xsp &= ~REG_FMR5_T_XTM; - force_cas = 1; /* T1 - Chip always in CAS mode */ + force_cas = 1; /* T1 - Chip always in CAS mode */ XPD_ERR(xpd, "J1 unsupported yet\n"); return -ENOSYS; } @@ -951,7 +947,9 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) /* framing first */ if (lineconfig & DAHDI_CONFIG_B8ZS) { framingstr = "B8ZS"; - fmr0 = REG_FMR0_E_XC1 | REG_FMR0_E_XC0 | REG_FMR0_E_RC1 | REG_FMR0_E_RC0; + fmr0 = + REG_FMR0_E_XC1 | REG_FMR0_E_XC0 | REG_FMR0_E_RC1 | + REG_FMR0_E_RC0; } else if (lineconfig & DAHDI_CONFIG_AMI) { framingstr = "AMI"; fmr0 = REG_FMR0_E_XC1 | REG_FMR0_E_RC1; @@ -973,9 +971,12 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) fmr0 |= REG_FMR0_E_RC0; } else if (lineconfig & DAHDI_CONFIG_HDB3) { framingstr = "HDB3"; - fmr0 = REG_FMR0_E_XC1 | REG_FMR0_E_XC0 | REG_FMR0_E_RC1 | REG_FMR0_E_RC0; + fmr0 = + REG_FMR0_E_XC1 | REG_FMR0_E_XC0 | REG_FMR0_E_RC1 | + REG_FMR0_E_RC0; } else { - XPD_NOTICE(xpd, "Bad lineconfig. Not (B8ZS|AMI|HDB3). Ignored.\n"); + XPD_NOTICE(xpd, + "Bad lineconfig. Not (B8ZS|AMI|HDB3). Ignored.\n"); return -EINVAL; } /* then coding */ @@ -1008,34 +1009,41 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) fmr3 |= REG_FMR3_EXTIW; } XPD_DBG(GENERAL, xpd, "[%s] lineconfig=%s/%s/%s %s (0x%X)\n", - (priv->clock_source)?"MASTER":"SLAVE", - framingstr, codingstr, crcstr, - (lineconfig & DAHDI_CONFIG_NOTOPEN)?"YELLOW":"", + (priv->clock_source) ? "MASTER" : "SLAVE", framingstr, + codingstr, crcstr, + (lineconfig & DAHDI_CONFIG_NOTOPEN) ? "YELLOW" : "", lineconfig); set_reg_lim0(__func__, xpd); - XPD_DBG(GENERAL, xpd, "%s: fmr1(0x%02X) = 0x%02X\n", __func__, REG_FMR1, fmr1); + XPD_DBG(GENERAL, xpd, "%s: fmr1(0x%02X) = 0x%02X\n", __func__, REG_FMR1, + fmr1); write_subunit(xpd, REG_FMR1, fmr1); - XPD_DBG(GENERAL, xpd, "%s: fmr2(0x%02X) = 0x%02X\n", __func__, REG_FMR2, fmr2); + XPD_DBG(GENERAL, xpd, "%s: fmr2(0x%02X) = 0x%02X\n", __func__, REG_FMR2, + fmr2); write_subunit(xpd, REG_FMR2, fmr2); - XPD_DBG(GENERAL, xpd, "%s: fmr0(0x%02X) = 0x%02X\n", __func__, REG_FMR0, fmr0); + XPD_DBG(GENERAL, xpd, "%s: fmr0(0x%02X) = 0x%02X\n", __func__, REG_FMR0, + fmr0); write_subunit(xpd, REG_FMR0, fmr0); - XPD_DBG(GENERAL, xpd, "%s: fmr4(0x%02X) = 0x%02X\n", __func__, REG_FMR4, fmr4); + XPD_DBG(GENERAL, xpd, "%s: fmr4(0x%02X) = 0x%02X\n", __func__, REG_FMR4, + fmr4); write_subunit(xpd, REG_FMR4, fmr4); if (fmr3) { - XPD_DBG(GENERAL, xpd, "%s: fmr3(0x%02X) = 0x%02X\n", __func__, REG_FMR3, fmr3); + XPD_DBG(GENERAL, xpd, "%s: fmr3(0x%02X) = 0x%02X\n", __func__, + REG_FMR3, fmr3); write_subunit(xpd, REG_FMR3, fmr3); } - XPD_DBG(GENERAL, xpd, "%s: cmdr(0x%02X) = 0x%02X\n", __func__, REG_CMDR_E, cmdr); + XPD_DBG(GENERAL, xpd, "%s: cmdr(0x%02X) = 0x%02X\n", __func__, + REG_CMDR_E, cmdr); write_subunit(xpd, REG_CMDR_E, cmdr); #ifdef JAPANEZE_SUPPORT if (rc0) { - XPD_DBG(GENERAL, xpd, "%s: rc0(0x%02X) = 0x%02X\n", __func__, REG_RC0, rc0); + XPD_DBG(GENERAL, xpd, "%s: rc0(0x%02X) = 0x%02X\n", __func__, + REG_RC0, rc0); write_subunit(xpd, REG_RC0, rc0); } #endif if (force_cas) { if (priv->pri_protocol == PRI_PROTO_E1) { - int rs1 = 0x0B; + int rs1 = 0x0B; /* * Set correct X1-X3 bits in the E1 CAS MFAS @@ -1047,7 +1055,8 @@ static int pri_lineconfig(xpd_t *xpd, int lineconfig) } xsp |= REG_XSP_E_CASEN; /* Same as REG_FMR5_T_EIBR for T1 */ } - XPD_DBG(GENERAL, xpd, "%s: xsp(0x%02X) = 0x%02X\n", __func__, REG_XSP_E, xsp); + XPD_DBG(GENERAL, xpd, "%s: xsp(0x%02X) = 0x%02X\n", __func__, REG_XSP_E, + xsp); write_subunit(xpd, REG_XSP_E, xsp); return 0; bad_lineconfig: @@ -1057,8 +1066,8 @@ bad_lineconfig: static int pri_set_spantype(struct dahdi_span *span, const char *spantype) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); enum pri_protocol set_proto = PRI_PROTO_0; XPD_INFO(xpd, "%s: %s\n", __func__, spantype); @@ -1073,10 +1082,10 @@ static int pri_set_spantype(struct dahdi_span *span, const char *spantype) static int pri_spanconfig(struct file *file, struct dahdi_span *span, struct dahdi_lineconfig *lc) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - struct PRI_priv_data *priv; - int ret; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct PRI_priv_data *priv; + int ret; BUG_ON(!xpd); priv = xpd->priv; @@ -1090,7 +1099,8 @@ static int pri_spanconfig(struct file *file, struct dahdi_span *span, * We currently ignore it also. */ XPD_DBG(GENERAL, xpd, "[%s] lbo=%d lineconfig=0x%X sync=%d\n", - (priv->clock_source)?"MASTER":"SLAVE", lc->lbo, lc->lineconfig, lc->sync); + (priv->clock_source) ? "MASTER" : "SLAVE", lc->lbo, + lc->lineconfig, lc->sync); ret = pri_lineconfig(xpd, lc->lineconfig); if (!ret) { span->lineconfig = lc->lineconfig; @@ -1109,13 +1119,15 @@ static int pri_spanconfig(struct file *file, struct dahdi_span *span, static int pri_chanconfig(struct file *file, struct dahdi_chan *chan, int sigtype) { - struct phonedev *phonedev = container_of(chan->span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - struct PRI_priv_data *priv; + struct phonedev *phonedev = + container_of(chan->span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; - DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name, sig2str(sigtype)); + DBG(GENERAL, "channel %d (%s) -> %s\n", chan->channo, chan->name, + sig2str(sigtype)); /* * Some bookkeeping to check if we have DChan defined or not * FIXME: actually use this to prevent duplicate DChan definitions @@ -1123,11 +1135,11 @@ static int pri_chanconfig(struct file *file, struct dahdi_chan *chan, */ if (is_sigtype_dchan(sigtype)) { if (VALID_DCHAN(priv) && DCHAN(priv) != chan->channo) { - ERR("channel %d (%s) marked DChan but also channel %d.\n", - chan->channo, chan->name, DCHAN(priv)); + ERR("channel %d (%s) marked DChan but also channel %d.\n", chan->channo, chan->name, DCHAN(priv)); return -EINVAL; } - XPD_DBG(GENERAL, xpd, "channel %d (%s) marked as DChan\n", chan->channo, chan->name); + XPD_DBG(GENERAL, xpd, "channel %d (%s) marked as DChan\n", + chan->channo, chan->name); SET_DCHAN(priv, chan->channo); /* In T1, we don't know before-hand */ if (priv->pri_protocol != PRI_PROTO_E1 && priv->is_cas != 0) { @@ -1135,7 +1147,9 @@ static int pri_chanconfig(struct file *file, struct dahdi_chan *chan, } } else { if (chan->channo == 1) { - XPD_DBG(GENERAL, xpd, "channel %d (%s) marked a not DChan\n", chan->channo, chan->name); + XPD_DBG(GENERAL, xpd, + "channel %d (%s) marked a not DChan\n", + chan->channo, chan->name); SET_DCHAN(priv, NO_DCHAN); } /* In T1, we don't know before-hand */ @@ -1152,24 +1166,27 @@ static int pri_chanconfig(struct file *file, struct dahdi_chan *chan, return 0; } -static xpd_t *PRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_table_t *proto_table, - __u8 subtype, int subunits, int subunit_ports, bool to_phone) +static xpd_t *PRI_card_new(xbus_t *xbus, int unit, int subunit, + const xproto_table_t *proto_table, __u8 subtype, + int subunits, int subunit_ports, bool to_phone) { - xpd_t *xpd = NULL; - struct PRI_priv_data *priv; - int channels = min(31, CHANNELS_PERXPD); /* worst case */ + xpd_t *xpd = NULL; + struct PRI_priv_data *priv; + int channels = min(31, CHANNELS_PERXPD); /* worst case */ if (subunit_ports != 1) { XBUS_ERR(xbus, "Bad subunit_ports=%d\n", subunit_ports); return NULL; } XBUS_DBG(GENERAL, xbus, "\n"); - xpd = xpd_alloc(xbus, unit, subunit, subtype, subunits, sizeof(struct PRI_priv_data), proto_table, channels); + xpd = + xpd_alloc(xbus, unit, subunit, subtype, subunits, + sizeof(struct PRI_priv_data), proto_table, channels); if (!xpd) return NULL; priv = xpd->priv; - priv->pri_protocol = PRI_PROTO_0; /* Default, changes in set_pri_proto() */ - priv->deflaw = DAHDI_LAW_DEFAULT; /* Default, changes in set_pri_proto() */ + priv->pri_protocol = PRI_PROTO_0; /* Default, changes in set_pri_proto() */ + priv->deflaw = DAHDI_LAW_DEFAULT; /* Default, changes in set_pri_proto() */ xpd->type_name = type_name(priv->pri_protocol); xbus->sync_mode_default = SYNC_MODE_AB; return xpd; @@ -1177,8 +1194,8 @@ static xpd_t *PRI_card_new(xbus_t *xbus, int unit, int subunit, const xproto_tab static int PRI_card_init(xbus_t *xbus, xpd_t *xpd) { - struct PRI_priv_data *priv; - int ret = 0; + struct PRI_priv_data *priv; + int ret = 0; BUG_ON(!xpd); XPD_DBG(GENERAL, xpd, "\n"); @@ -1205,7 +1222,7 @@ static int PRI_card_init(xbus_t *xbus, xpd_t *xpd) xpd->type_name = type_name(priv->pri_protocol); PHONEDEV(xpd).direction = TO_PSTN; XPD_DBG(DEVICES, xpd, "%s\n", xpd->type_name); - PHONEDEV(xpd).timing_priority = 1; /* High priority SLAVE */ + PHONEDEV(xpd).timing_priority = 1; /* High priority SLAVE */ set_master_mode(__func__, xpd); for (ret = 0; ret < NUM_LEDS; ret++) { DO_LED(xpd, ret, PRI_LED_ON); @@ -1229,8 +1246,8 @@ static int PRI_card_remove(xbus_t *xbus, xpd_t *xpd) #ifdef DAHDI_AUDIO_NOTIFY static int pri_audio_notify(struct dahdi_chan *chan, int on) { - xpd_t *xpd = chan->pvt; - int pos = chan->chanpos - 1; + xpd_t *xpd = chan->pvt; + int pos = chan->chanpos - 1; BUG_ON(!xpd); LINE_DBG(SIGNAL, xpd, pos, "PRI-AUDIO: %s\n", (on) ? "on" : "off"); @@ -1268,9 +1285,9 @@ static const struct dahdi_span_ops PRI_span_ops = { static int apply_pri_protocol(xpd_t *xpd) { - xbus_t *xbus; - struct PRI_priv_data *priv; - int i; + xbus_t *xbus; + struct PRI_priv_data *priv; + int i; BUG_ON(!xpd); xbus = xpd->xbus; @@ -1282,13 +1299,14 @@ static int apply_pri_protocol(xpd_t *xpd) PHONEDEV(xpd).span.deflaw = priv->deflaw; PHONEDEV(xpd).span.alarms = DAHDI_ALARM_NONE; for_each_line(xpd, i) { - struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); - bool is_dchan = i == PRI_DCHAN_IDX(priv); + struct dahdi_chan *cur_chan = XPD_CHAN(xpd, i); + bool is_dchan = i == PRI_DCHAN_IDX(priv); XPD_DBG(GENERAL, xpd, "setting PRI channel %d (%s)\n", i, - (is_dchan)?"DCHAN":"CLEAR"); + (is_dchan) ? "DCHAN" : "CLEAR"); snprintf(cur_chan->name, MAX_CHANNAME, "XPP_%s/%02d/%1d%1d/%d", - xpd->type_name, xbus->num, xpd->addr.unit, xpd->addr.subunit, i); + xpd->type_name, xbus->num, xpd->addr.unit, + xpd->addr.subunit, i); cur_chan->chanpos = i + 1; cur_chan->pvt = xpd; cur_chan->sigcap = PRI_SIGCAP; @@ -1306,18 +1324,16 @@ static int apply_pri_protocol(xpd_t *xpd) static int PRI_card_dahdi_preregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; - struct PRI_priv_data *priv; + xbus_t *xbus; + struct PRI_priv_data *priv; BUG_ON(!xpd); xbus = xpd->xbus; priv = xpd->priv; BUG_ON(!xbus); XPD_DBG(GENERAL, xpd, "%s (proto=%s, channels=%d, deflaw=%d)\n", - (on)?"on":"off", - pri_protocol_name(priv->pri_protocol), - PHONEDEV(xpd).channels, - priv->deflaw); + (on) ? "on" : "off", pri_protocol_name(priv->pri_protocol), + PHONEDEV(xpd).channels, priv->deflaw); if (!on) { /* Nothing to do yet */ return 0; @@ -1327,19 +1343,19 @@ static int PRI_card_dahdi_preregistration(xpd_t *xpd, bool on) static int PRI_card_dahdi_postregistration(xpd_t *xpd, bool on) { - xbus_t *xbus; + xbus_t *xbus; BUG_ON(!xpd); xbus = xpd->xbus; BUG_ON(!xbus); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); dahdi_update_syncsrc(xpd); - return(0); + return (0); } static void dchan_state(xpd_t *xpd, bool up) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -1355,10 +1371,11 @@ static void dchan_state(xpd_t *xpd, bool up) XPD_DBG(SIGNAL, xpd, "STATE CHANGE: D-Channel RUNNING\n"); priv->dchan_alive = 1; } else { - int d = PRI_DCHAN_IDX(priv); + int d = PRI_DCHAN_IDX(priv); - if (SPAN_REGISTERED(xpd) && d >= 0 && d < PHONEDEV(xpd).channels) { - __u8 *pcm; + if (SPAN_REGISTERED(xpd) && d >= 0 + && d < PHONEDEV(xpd).channels) { + __u8 *pcm; pcm = (__u8 *)XPD_CHAN(xpd, d)->readchunk; pcm[0] = 0x00; @@ -1381,12 +1398,12 @@ static void dchan_state(xpd_t *xpd, bool up) */ static void handle_leds(xbus_t *xbus, xpd_t *xpd) { - struct PRI_priv_data *priv; - unsigned int timer_count; - int which_led; - int other_led; - enum pri_led_state ledstate; - int mod; + struct PRI_priv_data *priv; + unsigned int timer_count; + int which_led; + int other_led; + enum pri_led_state ledstate; + int mod; BUG_ON(!xpd); priv = xpd->priv; @@ -1418,24 +1435,24 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd) if (priv->dchan_alive) { mod = timer_count % 1000; switch (mod) { - case 0: - DO_LED(xpd, which_led, PRI_LED_ON); - break; - case 500: - DO_LED(xpd, which_led, PRI_LED_OFF); - break; + case 0: + DO_LED(xpd, which_led, PRI_LED_ON); + break; + case 500: + DO_LED(xpd, which_led, PRI_LED_OFF); + break; } } else if (priv->layer1_up) { mod = timer_count % 1000; switch (mod) { - case 0: - case 100: - DO_LED(xpd, which_led, PRI_LED_ON); - break; - case 50: - case 150: - DO_LED(xpd, which_led, PRI_LED_OFF); - break; + case 0: + case 100: + DO_LED(xpd, which_led, PRI_LED_ON); + break; + case 50: + case 150: + DO_LED(xpd, which_led, PRI_LED_OFF); + break; } } else { if (priv->ledstate[which_led] != PRI_LED_ON) @@ -1445,7 +1462,7 @@ static void handle_leds(xbus_t *xbus, xpd_t *xpd) static int PRI_card_tick(xbus_t *xbus, xpd_t *xpd) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; @@ -1455,8 +1472,7 @@ static int PRI_card_tick(xbus_t *xbus, xpd_t *xpd) /* * Poll layer1 status (cascade subunits) */ - if (poll_interval != 0 && - ((xpd->timer_count % poll_interval) == 0)) { + if (poll_interval != 0 && ((xpd->timer_count % poll_interval) == 0)) { priv->poll_noreplies++; query_subunit(xpd, REG_FRS0); //query_subunit(xpd, REG_FRS1); @@ -1469,9 +1485,10 @@ static int PRI_card_tick(xbus_t *xbus, xpd_t *xpd) return 0; } -static int PRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg) +static int PRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, + unsigned long arg) { - struct dahdi_chan *chan; + struct dahdi_chan *chan; BUG_ON(!xpd); if (!XBUS_IS(xpd->xbus, READY)) @@ -1485,34 +1502,34 @@ static int PRI_card_ioctl(xpd_t *xpd, int pos, unsigned int cmd, unsigned long a * (FXS signalling) * Ignore them. */ - case DAHDI_TONEDETECT: - LINE_DBG(SIGNAL, xpd, pos, "PRI: TONEDETECT (%s)\n", - (chan->flags & DAHDI_FLAG_AUDIO) ? - "AUDIO" : "SILENCE"); - return -ENOTTY; - case DAHDI_ONHOOKTRANSFER: - LINE_DBG(SIGNAL, xpd, pos, "PRI: ONHOOKTRANSFER\n"); - return -ENOTTY; - case DAHDI_VMWI: - LINE_DBG(SIGNAL, xpd, pos, "PRI: VMWI\n"); - return -ENOTTY; - case DAHDI_VMWI_CONFIG: - LINE_DBG(SIGNAL, xpd, pos, "PRI: VMWI_CONFIG\n"); - return -ENOTTY; - case DAHDI_SETPOLARITY: - LINE_DBG(SIGNAL, xpd, pos, "PRI: SETPOLARITY\n"); - return -ENOTTY; + case DAHDI_TONEDETECT: + LINE_DBG(SIGNAL, xpd, pos, "PRI: TONEDETECT (%s)\n", + (chan-> + flags & DAHDI_FLAG_AUDIO) ? "AUDIO" : "SILENCE"); + return -ENOTTY; + case DAHDI_ONHOOKTRANSFER: + LINE_DBG(SIGNAL, xpd, pos, "PRI: ONHOOKTRANSFER\n"); + return -ENOTTY; + case DAHDI_VMWI: + LINE_DBG(SIGNAL, xpd, pos, "PRI: VMWI\n"); + return -ENOTTY; + case DAHDI_VMWI_CONFIG: + LINE_DBG(SIGNAL, xpd, pos, "PRI: VMWI_CONFIG\n"); + return -ENOTTY; + case DAHDI_SETPOLARITY: + LINE_DBG(SIGNAL, xpd, pos, "PRI: SETPOLARITY\n"); + return -ENOTTY; /* report on really bad ioctl()'s */ - default: - report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); - return -ENOTTY; + default: + report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); + return -ENOTTY; } return 0; } static int PRI_card_close(xpd_t *xpd, lineno_t pos) { - //struct dahdi_chan *chan = XPD_CHAN(xpd, pos); + //struct dahdi_chan *chan = XPD_CHAN(xpd, pos); dchan_state(xpd, 0); return 0; } @@ -1522,15 +1539,16 @@ static int PRI_card_close(xpd_t *xpd, lineno_t pos) */ static int pri_startup(struct file *file, struct dahdi_span *span) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - struct PRI_priv_data *priv; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); if (!XBUS_IS(xpd->xbus, READY)) { - XPD_DBG(GENERAL, xpd, "Startup called by dahdi. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, + "Startup called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "STARTUP\n"); @@ -1546,15 +1564,16 @@ static int pri_startup(struct file *file, struct dahdi_span *span) */ static int pri_shutdown(struct dahdi_span *span) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - struct PRI_priv_data *priv; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct PRI_priv_data *priv; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); if (!XBUS_IS(xpd->xbus, READY)) { - XPD_DBG(GENERAL, xpd, "Shutdown called by dahdi. No Hardware. Ignored\n"); + XPD_DBG(GENERAL, xpd, + "Shutdown called by dahdi. No Hardware. Ignored\n"); return -ENODEV; } XPD_DBG(GENERAL, xpd, "SHUTDOWN\n"); @@ -1565,9 +1584,9 @@ static int pri_shutdown(struct dahdi_span *span) static int encode_rbsbits_e1(xpd_t *xpd, int pos, int bits) { - struct PRI_priv_data *priv; - __u8 val; - int rsnum; + struct PRI_priv_data *priv; + __u8 val; + int rsnum; BUG_ON(!xpd); priv = xpd->priv; @@ -1576,7 +1595,8 @@ static int encode_rbsbits_e1(xpd_t *xpd, int pos, int bits) if (pos == 15) return 0; /* Don't write dchan in CAS */ if (pos < 0 || pos > 31) { - XPD_NOTICE(xpd, "%s: pos=%d out of range. Ignore\n", __func__, pos); + XPD_NOTICE(xpd, "%s: pos=%d out of range. Ignore\n", __func__, + pos); return 0; } if (pos >= 16) { @@ -1595,14 +1615,14 @@ static int encode_rbsbits_e1(xpd_t *xpd, int pos, int bits) static int encode_rbsbits_t1(xpd_t *xpd, int pos, int bits) { - struct PRI_priv_data *priv; - int rsnum; - int chan_per_reg; - int offset; - int width; - uint tx_bits = bits; - uint mask; - __u8 val; + struct PRI_priv_data *priv; + int rsnum; + int chan_per_reg; + int offset; + int width; + uint tx_bits = bits; + uint mask; + __u8 val; BUG_ON(!xpd); priv = xpd->priv; @@ -1625,20 +1645,18 @@ static int encode_rbsbits_t1(xpd_t *xpd, int pos, int bits) val &= ~mask; val |= tx_bits; LINE_DBG(SIGNAL, xpd, pos, - "bits=0x%02X RS%02d(%s) offset=%d tx_bits=0x%02X\n", - bits, rsnum+1, - (priv->is_esf) ? "esf" : "d4", - offset, tx_bits); - write_cas_reg(xpd, rsnum , val); + "bits=0x%02X RS%02d(%s) offset=%d tx_bits=0x%02X\n", bits, + rsnum + 1, (priv->is_esf) ? "esf" : "d4", offset, tx_bits); + write_cas_reg(xpd, rsnum, val); priv->dchan_tx_counter++; return 0; } static void send_idlebits(xpd_t *xpd, bool saveold) { - struct PRI_priv_data *priv; - __u8 save_rs[NUM_CAS_RS_E]; - int i; + struct PRI_priv_data *priv; + __u8 save_rs[NUM_CAS_RS_E]; + int i; if (!SPAN_REGISTERED(xpd)) return; @@ -1648,7 +1666,7 @@ static void send_idlebits(xpd_t *xpd, bool saveold) if (saveold) memcpy(save_rs, priv->cas_ts_e, sizeof(save_rs)); for_each_line(xpd, i) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); + struct dahdi_chan *chan = XPD_CHAN(xpd, i); pri_rbsbits(chan, chan->idlebits); } @@ -1658,22 +1676,22 @@ static void send_idlebits(xpd_t *xpd, bool saveold) static void send_oldbits(xpd_t *xpd) { - struct PRI_priv_data *priv; - int i; + struct PRI_priv_data *priv; + int i; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); XPD_DBG(SIGNAL, xpd, "\n"); for (i = 0; i < cas_numregs(xpd); i++) - write_cas_reg(xpd, i , priv->cas_ts_e[i]); + write_cas_reg(xpd, i, priv->cas_ts_e[i]); } static int pri_rbsbits(struct dahdi_chan *chan, int bits) { - xpd_t *xpd; - struct PRI_priv_data *priv; - int pos; + xpd_t *xpd; + struct PRI_priv_data *priv; + int pos; xpd = chan->pvt; BUG_ON(!xpd); @@ -1686,8 +1704,8 @@ static int pri_rbsbits(struct dahdi_chan *chan, int bits) } if (chan->sig == DAHDI_SIG_NONE) { LINE_DBG(SIGNAL, xpd, pos, - "RBS: TX: sigtyp=%s. , bits=0x%X. Ignore.\n", - sig2str(chan->sig), bits); + "RBS: TX: sigtyp=%s. , bits=0x%X. Ignore.\n", + sig2str(chan->sig), bits); return 0; } if (!priv->layer1_up) { @@ -1700,8 +1718,9 @@ static int pri_rbsbits(struct dahdi_chan *chan, int bits) if (encode_rbsbits_t1(xpd, pos, bits) < 0) return -EINVAL; } else { - XPD_NOTICE(xpd, "%s: protocol %s is not supported yet with CAS\n", - __func__, pri_protocol_name(priv->pri_protocol)); + XPD_NOTICE(xpd, + "%s: protocol %s is not supported yet with CAS\n", + __func__, pri_protocol_name(priv->pri_protocol)); return -EINVAL; } return 0; @@ -1720,13 +1739,13 @@ static int pri_rbsbits(struct dahdi_chan *chan, int bits) */ static void PRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) { - struct PRI_priv_data *priv; - __u8 *pcm; - unsigned long flags; - int i; - xpp_line_t wanted_lines; - int physical_chan; - int physical_mask = 0; + struct PRI_priv_data *priv; + __u8 *pcm; + unsigned long flags; + int i; + xpp_line_t wanted_lines; + int physical_chan; + int physical_mask = 0; BUG_ON(!xpd); BUG_ON(!pack); @@ -1737,7 +1756,7 @@ static void PRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) wanted_lines = PHONEDEV(xpd).wanted_pcm_mask; physical_chan = 0; for_each_line(xpd, i) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); + struct dahdi_chan *chan = XPD_CHAN(xpd, i); if (priv->pri_protocol == PRI_PROTO_E1) { /* In E1 - Only 0'th channel is unused */ @@ -1754,16 +1773,20 @@ static void PRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) physical_mask |= BIT(physical_chan); if (SPAN_REGISTERED(xpd)) { #ifdef DEBUG_PCMTX - int channo = XPD_CHAN(xpd, i)->channo; + int channo = XPD_CHAN(xpd, i)->channo; if (pcmtx >= 0 && pcmtx_chan == channo) - memset((u_char *)pcm, pcmtx, DAHDI_CHUNKSIZE); + memset((u_char *)pcm, pcmtx, + DAHDI_CHUNKSIZE); else #endif - memcpy((u_char *)pcm, chan->writechunk, DAHDI_CHUNKSIZE); + memcpy((u_char *)pcm, chan->writechunk, + DAHDI_CHUNKSIZE); if (i == PRI_DCHAN_IDX(priv)) { - if (priv->dchan_tx_sample != chan->writechunk[0]) { - priv->dchan_tx_sample = chan->writechunk[0]; + if (priv->dchan_tx_sample != + chan->writechunk[0]) { + priv->dchan_tx_sample = + chan->writechunk[0]; priv->dchan_tx_counter++; } else if (chan->writechunk[0] == 0xFF) dchan_state(xpd, 0); @@ -1771,7 +1794,8 @@ static void PRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) chan->writechunk[0] = 0xFF; /* Clobber for next tick */ } } else - memset((u_char *)pcm, DAHDI_XLAW(0, chan), DAHDI_CHUNKSIZE); + memset((u_char *)pcm, DAHDI_XLAW(0, chan), + DAHDI_CHUNKSIZE); pcm += DAHDI_CHUNKSIZE; } physical_chan++; @@ -1793,12 +1817,12 @@ static void PRI_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) */ static void PRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) { - struct PRI_priv_data *priv; - __u8 *pcm; - xpp_line_t physical_mask; - unsigned long flags; - int i; - int logical_chan; + struct PRI_priv_data *priv; + __u8 *pcm; + xpp_line_t physical_mask; + unsigned long flags; + int i; + int logical_chan; if (!SPAN_REGISTERED(xpd)) return; @@ -1809,7 +1833,7 @@ static void PRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) spin_lock_irqsave(&xpd->lock, flags); logical_chan = 0; for (i = 0; i < CHANNELS_PERXPD; i++) { - volatile u_char *r; + volatile u_char *r; if (priv->pri_protocol == PRI_PROTO_E1) { /* In E1 - Only 0'th channel is unused */ @@ -1823,8 +1847,9 @@ static void PRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) if (logical_chan == PRI_DCHAN_IDX(priv) && !priv->is_cas) { if (priv->dchan_rx_sample != pcm[0]) { if (debug & DBG_PCM) { - XPD_INFO(xpd, "RX-D-Chan: prev=0x%X now=0x%X\n", - priv->dchan_rx_sample, pcm[0]); + XPD_INFO(xpd, + "RX-D-Chan: prev=0x%X now=0x%X\n", + priv->dchan_rx_sample, pcm[0]); dump_packet("RX-D-Chan", pack, 1); } priv->dchan_rx_sample = pcm[0]; @@ -1834,7 +1859,7 @@ static void PRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) } if (IS_SET(physical_mask, i)) { r = XPD_CHAN(xpd, logical_chan)->readchunk; - // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE); // DEBUG + // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE); // DEBUG memcpy((u_char *)r, pcm, DAHDI_CHUNKSIZE); pcm += DAHDI_CHUNKSIZE; } @@ -1846,7 +1871,7 @@ static void PRI_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) static int PRI_timing_priority(xpd_t *xpd) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; priv = xpd->priv; BUG_ON(!priv); @@ -1875,11 +1900,11 @@ static int PRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) XPD_DBG(GENERAL, xpd, "0x%8X\n", ec_mask); if (!ECHOOPS(xpd->xbus)) { XPD_DBG(GENERAL, xpd, - "No echo canceller in XBUS: Doing nothing.\n"); + "No echo canceller in XBUS: Doing nothing.\n"); return -EINVAL; } for (i = 0; i < PHONEDEV(xpd).channels; i++) { - int on = BIT(i) & ec_mask; + int on = BIT(i) & ec_mask; if (i == PRI_DCHAN_IDX(priv)) on = 0; @@ -1891,13 +1916,14 @@ static int PRI_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) /*---------------- PRI: HOST COMMANDS -------------------------------------*/ -static /* 0x33 */ HOSTCMD(PRI, SET_LED, enum pri_led_selectors led_sel, enum pri_led_state to_led_state) +static /* 0x33 */ HOSTCMD(PRI, SET_LED, enum pri_led_selectors led_sel, + enum pri_led_state to_led_state) { - int ret = 0; - xframe_t *xframe; - xpacket_t *pack; - struct pri_leds *pri_leds; - struct PRI_priv_data *priv; + int ret = 0; + xframe_t *xframe; + xpacket_t *pack; + struct pri_leds *pri_leds; + struct PRI_priv_data *priv; BUG_ON(!xbus); BUG_ON(!xpd); @@ -1918,21 +1944,21 @@ static /* 0x33 */ HOSTCMD(PRI, SET_LED, enum pri_led_selectors led_sel, enum pri /*---------------- PRI: Astribank Reply Handlers --------------------------*/ static void layer1_state(xpd_t *xpd, __u8 data_low) { - struct PRI_priv_data *priv; - int alarms = DAHDI_ALARM_NONE; - int layer1_up_prev; + struct PRI_priv_data *priv; + int alarms = DAHDI_ALARM_NONE; + int layer1_up_prev; BUG_ON(!xpd); priv = xpd->priv; BUG_ON(!priv); priv->poll_noreplies = 0; if (data_low & REG_FRS0_LOS) - alarms |= DAHDI_ALARM_RED; + alarms |= DAHDI_ALARM_RED; if (data_low & REG_FRS0_AIS) alarms |= DAHDI_ALARM_BLUE; if (data_low & REG_FRS0_RRA) alarms |= DAHDI_ALARM_YELLOW; - layer1_up_prev = priv->layer1_up; + layer1_up_prev = priv->layer1_up; priv->layer1_up = alarms == DAHDI_ALARM_NONE; #if 0 /* @@ -1947,24 +1973,23 @@ static void layer1_state(xpd_t *xpd, __u8 data_low) if (!priv->layer1_up) { dchan_state(xpd, 0); } else if (priv->is_cas && !layer1_up_prev) { - int regbase = cas_regbase(xpd); - int i; + int regbase = cas_regbase(xpd); + int i; - XPD_DBG(SIGNAL , xpd, + XPD_DBG(SIGNAL, xpd, "Returning From Alarm Refreshing Rx register data \n"); for (i = 0; i < cas_numregs(xpd); i++) query_subunit(xpd, regbase + i); } if (SPAN_REGISTERED(xpd) && PHONEDEV(xpd).span.alarms != alarms) { - char str1[MAX_PROC_WRITE]; - char str2[MAX_PROC_WRITE]; + char str1[MAX_PROC_WRITE]; + char str2[MAX_PROC_WRITE]; alarm2str(PHONEDEV(xpd).span.alarms, str1, sizeof(str1)); alarm2str(alarms, str2, sizeof(str2)); XPD_NOTICE(xpd, "Alarms: 0x%X (%s) => 0x%X (%s)\n", - PHONEDEV(xpd).span.alarms, str1, - alarms, str2); + PHONEDEV(xpd).span.alarms, str1, alarms, str2); if (priv->is_cas) { if (alarms == DAHDI_ALARM_NONE) send_oldbits(xpd); @@ -1978,43 +2003,42 @@ static void layer1_state(xpd_t *xpd, __u8 data_low) } priv->reg_frs0 = data_low; priv->layer1_replies++; - XPD_DBG(REGS, xpd, "subunit=%d data_low=0x%02X\n", xpd->addr.subunit, data_low); + XPD_DBG(REGS, xpd, "subunit=%d data_low=0x%02X\n", xpd->addr.subunit, + data_low); } static int decode_cas_e1(xpd_t *xpd, __u8 regnum, __u8 data_low) { - struct PRI_priv_data *priv; - uint pos = regnum - REG_RS2_E; - int rsnum = pos + 2; - int chan1 = pos; - int chan2 = pos + 16; - int val1 = (data_low >> 4) & 0xF; - int val2 = data_low & 0xF; + struct PRI_priv_data *priv; + uint pos = regnum - REG_RS2_E; + int rsnum = pos + 2; + int chan1 = pos; + int chan2 = pos + 16; + int val1 = (data_low >> 4) & 0xF; + int val2 = data_low & 0xF; priv = xpd->priv; BUG_ON(!priv->is_cas); BUG_ON(priv->pri_protocol != PRI_PROTO_E1); XPD_DBG(SIGNAL, xpd, "RBS: RX: data_low=0x%02X\n", data_low); if (pos >= NUM_CAS_RS_E) { - XPD_ERR(xpd, "%s: got bad pos=%d [0-%d]\n", __func__, pos, NUM_CAS_RS_E); + XPD_ERR(xpd, "%s: got bad pos=%d [0-%d]\n", __func__, pos, + NUM_CAS_RS_E); return -EINVAL; } if (chan1 < 0 || chan1 > PHONEDEV(xpd).channels) { - XPD_NOTICE(xpd, "%s: %s CAS: Bad chan1 number (%d)\n", - __func__, - pri_protocol_name(priv->pri_protocol), - chan1); + XPD_NOTICE(xpd, "%s: %s CAS: Bad chan1 number (%d)\n", __func__, + pri_protocol_name(priv->pri_protocol), chan1); return -EINVAL; } if (chan2 < 0 || chan2 > PHONEDEV(xpd).channels) { - XPD_NOTICE(xpd, "%s: %s CAS: Bad chan2 number (%d)\n", - __func__, - pri_protocol_name(priv->pri_protocol), - chan2); + XPD_NOTICE(xpd, "%s: %s CAS: Bad chan2 number (%d)\n", __func__, + pri_protocol_name(priv->pri_protocol), chan2); return -EINVAL; } - XPD_DBG(SIGNAL, xpd, "RBS: RX: RS%02d (channel %2d, channel %2d): 0x%02X -> 0x%02X\n", - rsnum, chan1+1, chan2+1, priv->cas_rs_e[pos], data_low); + XPD_DBG(SIGNAL, xpd, + "RBS: RX: RS%02d (channel %2d, channel %2d): 0x%02X -> 0x%02X\n", + rsnum, chan1 + 1, chan2 + 1, priv->cas_rs_e[pos], data_low); if (SPAN_REGISTERED(xpd)) { dahdi_rbsbits(XPD_CHAN(xpd, chan1), val1); dahdi_rbsbits(XPD_CHAN(xpd, chan2), val2); @@ -2026,11 +2050,11 @@ static int decode_cas_e1(xpd_t *xpd, __u8 regnum, __u8 data_low) static int decode_cas_t1(xpd_t *xpd, __u8 regnum, __u8 data_low) { - struct PRI_priv_data *priv; - uint rsnum; - uint chan_per_reg; - uint width; - int i; + struct PRI_priv_data *priv; + uint rsnum; + uint chan_per_reg; + uint width; + int i; priv = xpd->priv; BUG_ON(!priv->is_cas); @@ -2044,15 +2068,13 @@ static int decode_cas_t1(xpd_t *xpd, __u8 regnum, __u8 data_low) rsnum = rsnum % 6; /* 2 identical banks of 6 registers */ chan_per_reg = CHAN_PER_REGS(priv); width = 8 / chan_per_reg; - XPD_DBG(SIGNAL, xpd, - "RBS: RX(%s,%d): RS%02d data_low=0x%02X\n", - (priv->is_esf) ? "esf" : "d4", - chan_per_reg, - rsnum+1, data_low); + XPD_DBG(SIGNAL, xpd, "RBS: RX(%s,%d): RS%02d data_low=0x%02X\n", + (priv->is_esf) ? "esf" : "d4", chan_per_reg, rsnum + 1, + data_low); for (i = 0; i < chan_per_reg; i++) { - uint rxsig = (data_low >> (i * width)) & BITMASK(width); - int pos; - struct dahdi_chan *chan; + uint rxsig = (data_low >> (i * width)) & BITMASK(width); + int pos; + struct dahdi_chan *chan; if (!priv->is_esf) rxsig <<= 2; @@ -2063,11 +2085,13 @@ static int decode_cas_t1(xpd_t *xpd, __u8 regnum, __u8 data_low) } chan = XPD_CHAN(xpd, pos); if (!chan) { - XPD_ERR(xpd, "%s: Null channel in pos=%d\n", __func__, pos); + XPD_ERR(xpd, "%s: Null channel in pos=%d\n", __func__, + pos); continue; } if (chan->rxsig != rxsig) { - LINE_DBG(SIGNAL, xpd, pos, "i=%d rxsig=0x%02X\n", i, rxsig); + LINE_DBG(SIGNAL, xpd, pos, "i=%d rxsig=0x%02X\n", i, + rxsig); dahdi_rbsbits(chan, rxsig); } } @@ -2077,40 +2101,42 @@ static int decode_cas_t1(xpd_t *xpd, __u8 regnum, __u8 data_low) static void process_cas_dchan(xpd_t *xpd, __u8 regnum, __u8 data_low) { - struct PRI_priv_data *priv; + struct PRI_priv_data *priv; priv = xpd->priv; if (!priv->is_cas) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 10003) == 0) XPD_NOTICE(xpd, "RBS: RX: not in CAS mode. Ignore.\n"); return; } if (!priv->layer1_up) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 10003) == 0) XPD_DBG(SIGNAL, xpd, "RBS: RX: No layer1.\n"); } if (!SPAN_REGISTERED(xpd)) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 10003) == 0) - XPD_DBG(SIGNAL, xpd, "RBS: RX: Span not registered. Ignore.\n"); + XPD_DBG(SIGNAL, xpd, + "RBS: RX: Span not registered. Ignore.\n"); return; } if (priv->pri_protocol == PRI_PROTO_E1) { if (regnum == REG_RS1_E) - return; /* Time slot 0: Ignored for E1 */ + return; /* Time slot 0: Ignored for E1 */ if (regnum < REG_RS2_E) { /* Should not happen, but harmless. Ignore */ if (regnum == REG_RS1_E) return; XPD_NOTICE(xpd, - "%s: received register 0x%X in protocol %s. Ignore\n", - __func__, regnum, pri_protocol_name(priv->pri_protocol)); + "%s: received register 0x%X in protocol %s. Ignore\n", + __func__, regnum, + pri_protocol_name(priv->pri_protocol)); return; } if (decode_cas_e1(xpd, regnum, data_low) < 0) @@ -2118,27 +2144,29 @@ static void process_cas_dchan(xpd_t *xpd, __u8 regnum, __u8 data_low) } else if (priv->pri_protocol == PRI_PROTO_T1) { if (regnum > REG_RS12_E) { XPD_NOTICE(xpd, - "%s: received register 0x%X in protocol %s. Ignore\n", - __func__, regnum, pri_protocol_name(priv->pri_protocol)); + "%s: received register 0x%X in protocol %s. Ignore\n", + __func__, regnum, + pri_protocol_name(priv->pri_protocol)); return; } if (decode_cas_t1(xpd, regnum, data_low) < 0) return; } else { - XPD_NOTICE(xpd, "%s: protocol %s is not supported yet with CAS\n", - __func__, pri_protocol_name(priv->pri_protocol)); + XPD_NOTICE(xpd, + "%s: protocol %s is not supported yet with CAS\n", + __func__, pri_protocol_name(priv->pri_protocol)); } priv->cas_replies++; } static int PRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) { - unsigned long flags; - struct PRI_priv_data *priv; - struct xpd_addr addr; - xpd_t *orig_xpd; - __u8 regnum; - __u8 data_low; + unsigned long flags; + struct PRI_priv_data *priv; + struct xpd_addr addr; + xpd_t *orig_xpd; + __u8 regnum; + __u8 data_low; /* Map UNIT + PORTNUM to XPD */ orig_xpd = xpd; @@ -2148,10 +2176,10 @@ static int PRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) data_low = REG_FIELD(info, data_low); xpd = xpd_byaddr(xbus, addr.unit, addr.subunit); if (!xpd) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) < 5) - notify_bad_xpd(__func__, xbus, addr , orig_xpd->xpdname); + notify_bad_xpd(__func__, xbus, addr, orig_xpd->xpdname); return -EPROTO; } spin_lock_irqsave(&xpd->lock, flags); @@ -2159,7 +2187,7 @@ static int PRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) BUG_ON(!priv); if (info->is_multibyte) { XPD_NOTICE(xpd, "Got Multibyte: %d bytes, eoframe: %d\n", - info->bytes, info->eoframe); + info->bytes, info->eoframe); goto end; } if (regnum == REG_FRS0 && !REG_FIELD(info, do_subreg)) @@ -2172,10 +2200,11 @@ static int PRI_card_register_reply(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *info) } } /* Update /proc info only if reply relate to the last slic read request */ - if ( - REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) && - REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, do_subreg) && - REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, subreg)) { + if (REG_FIELD(&xpd->requested_reply, regnum) == REG_FIELD(info, regnum) + && REG_FIELD(&xpd->requested_reply, do_subreg) == REG_FIELD(info, + do_subreg) + && REG_FIELD(&xpd->requested_reply, subreg) == REG_FIELD(info, + subreg)) { xpd->last_reply = *info; } @@ -2187,49 +2216,43 @@ end: static int PRI_card_state(xpd_t *xpd, bool on) { BUG_ON(!xpd); - XPD_DBG(GENERAL, xpd, "%s\n", (on)?"on":"off"); + XPD_DBG(GENERAL, xpd, "%s\n", (on) ? "on" : "off"); return 0; } -static const struct xops pri_xops = { - .card_new = PRI_card_new, - .card_init = PRI_card_init, - .card_remove = PRI_card_remove, - .card_tick = PRI_card_tick, - .card_register_reply = PRI_card_register_reply, +static const struct xops pri_xops = { + .card_new = PRI_card_new, + .card_init = PRI_card_init, + .card_remove = PRI_card_remove, + .card_tick = PRI_card_tick, + .card_register_reply = PRI_card_register_reply, }; -static const struct phoneops pri_phoneops = { - .card_dahdi_preregistration = PRI_card_dahdi_preregistration, - .card_dahdi_postregistration = PRI_card_dahdi_postregistration, - .card_pcm_recompute = PRI_card_pcm_recompute, - .card_pcm_fromspan = PRI_card_pcm_fromspan, - .card_pcm_tospan = PRI_card_pcm_tospan, - .echocancel_timeslot = PRI_echocancel_timeslot, - .echocancel_setmask = PRI_echocancel_setmask, - .card_timing_priority = PRI_timing_priority, - .card_ioctl = PRI_card_ioctl, - .card_close = PRI_card_close, - .card_state = PRI_card_state, +static const struct phoneops pri_phoneops = { + .card_dahdi_preregistration = PRI_card_dahdi_preregistration, + .card_dahdi_postregistration = PRI_card_dahdi_postregistration, + .card_pcm_recompute = PRI_card_pcm_recompute, + .card_pcm_fromspan = PRI_card_pcm_fromspan, + .card_pcm_tospan = PRI_card_pcm_tospan, + .echocancel_timeslot = PRI_echocancel_timeslot, + .echocancel_setmask = PRI_echocancel_setmask, + .card_timing_priority = PRI_timing_priority, + .card_ioctl = PRI_card_ioctl, + .card_close = PRI_card_close, + .card_state = PRI_card_state, }; static xproto_table_t PROTO_TABLE(PRI) = { - .owner = THIS_MODULE, - .entries = { - /* Table Card Opcode */ - }, - .name = "PRI", /* protocol name */ - .ports_per_subunit = 1, - .type = XPD_TYPE_PRI, - .xops = &pri_xops, - .phoneops = &pri_phoneops, - .packet_is_valid = pri_packet_is_valid, - .packet_dump = pri_packet_dump, -}; + .owner = THIS_MODULE,.entries = { + /* Table Card Opcode */ + },.name = "PRI", /* protocol name */ +.ports_per_subunit = 1,.type = XPD_TYPE_PRI,.xops = + &pri_xops,.phoneops = &pri_phoneops,.packet_is_valid = + pri_packet_is_valid,.packet_dump = pri_packet_dump,}; static bool pri_packet_is_valid(xpacket_t *pack) { - const xproto_entry_t *xe = NULL; + const xproto_entry_t *xe = NULL; // DBG(GENERAL, "\n"); xe = xproto_card_entry(&PROTO_TABLE(PRI), XPACKET_OP(pack)); return xe != NULL; @@ -2239,15 +2262,16 @@ static void pri_packet_dump(const char *msg, xpacket_t *pack) { DBG(GENERAL, "%s\n", msg); } + /*------------------------- REGISTER Handling --------------------------*/ /*------------------------- sysfs stuff --------------------------------*/ static DEVICE_ATTR_READER(pri_protocol_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2263,10 +2287,10 @@ static DEVICE_ATTR_READER(pri_protocol_show, dev, buf) static DEVICE_ATTR_WRITER(pri_protocol_store, dev, buf, count) { - xpd_t *xpd; - enum pri_protocol new_protocol = PRI_PROTO_0; - int i; - int ret; + xpd_t *xpd; + enum pri_protocol new_protocol = PRI_PROTO_0; + int i; + int ret; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2276,8 +2300,8 @@ static DEVICE_ATTR_WRITER(pri_protocol_store, dev, buf, count) i = strcspn(buf, " \r\n"); if (i != 2) { XPD_NOTICE(xpd, - "Protocol name '%s' has %d characters (should be 2). Ignored.\n", - buf, i); + "Protocol name '%s' has %d characters (should be 2). Ignored.\n", + buf, i); return -EINVAL; } if (strnicmp(buf, "E1", 2) == 0) @@ -2288,23 +2312,23 @@ static DEVICE_ATTR_WRITER(pri_protocol_store, dev, buf, count) new_protocol = PRI_PROTO_J1; else { XPD_NOTICE(xpd, - "Unknown PRI protocol '%s' (should be E1|T1|J1). Ignored.\n", - buf); + "Unknown PRI protocol '%s' (should be E1|T1|J1). Ignored.\n", + buf); return -EINVAL; } ret = set_pri_proto(xpd, new_protocol); return (ret < 0) ? ret : count; } -static DEVICE_ATTR(pri_protocol, S_IRUGO | S_IWUSR, pri_protocol_show, - pri_protocol_store); +static DEVICE_ATTR(pri_protocol, S_IRUGO | S_IWUSR, pri_protocol_show, + pri_protocol_store); static DEVICE_ATTR_READER(pri_localloop_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2313,18 +2337,17 @@ static DEVICE_ATTR_READER(pri_localloop_show, dev, buf) priv = xpd->priv; BUG_ON(!priv); spin_lock_irqsave(&xpd->lock, flags); - len += sprintf(buf, "%c\n", - (priv->local_loopback) ? 'Y' : 'N'); + len += sprintf(buf, "%c\n", (priv->local_loopback) ? 'Y' : 'N'); spin_unlock_irqrestore(&xpd->lock, flags); return len; } static DEVICE_ATTR_WRITER(pri_localloop_store, dev, buf, count) { - xpd_t *xpd; - bool ll = 0; - int i; - int ret; + xpd_t *xpd; + bool ll = 0; + int i; + int ret; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2333,8 +2356,8 @@ static DEVICE_ATTR_WRITER(pri_localloop_store, dev, buf, count) return -ENODEV; if ((i = strcspn(buf, " \r\n")) != 1) { XPD_NOTICE(xpd, - "Value '%s' has %d characters (should be 1). Ignored.\n", - buf, i); + "Value '%s' has %d characters (should be 1). Ignored.\n", + buf, i); return -EINVAL; } if (strchr("1Yy", buf[0]) != NULL) @@ -2343,22 +2366,23 @@ static DEVICE_ATTR_WRITER(pri_localloop_store, dev, buf, count) ll = 0; else { XPD_NOTICE(xpd, - "Unknown value '%s' (should be [1Yy]|[0Nn]). Ignored.\n", - buf); + "Unknown value '%s' (should be [1Yy]|[0Nn]). Ignored.\n", + buf); return -EINVAL; } ret = set_localloop(xpd, ll); return (ret < 0) ? ret : count; } -static DEVICE_ATTR(pri_localloop, S_IRUGO | S_IWUSR, pri_localloop_show, pri_localloop_store); +static DEVICE_ATTR(pri_localloop, S_IRUGO | S_IWUSR, pri_localloop_show, + pri_localloop_store); static DEVICE_ATTR_READER(pri_layer1_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2370,28 +2394,30 @@ static DEVICE_ATTR_READER(pri_layer1_show, dev, buf) if (priv->poll_noreplies > 1) len += sprintf(buf + len, "Unknown[%d]", priv->poll_noreplies); else - len += sprintf(buf + len, "%-10s", ((priv->layer1_up) ? "UP" : "DOWN")); + len += + sprintf(buf + len, "%-10s", + ((priv->layer1_up) ? "UP" : "DOWN")); len += sprintf(buf + len, "%d\n", priv->layer1_replies); spin_unlock_irqrestore(&xpd->lock, flags); return len; } -static DEVICE_ATTR(pri_layer1, S_IRUGO, pri_layer1_show, NULL); +static DEVICE_ATTR(pri_layer1, S_IRUGO, pri_layer1_show, NULL); static DEVICE_ATTR_READER(pri_alarms_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; static const struct { - __u8 bits; - const char *name; + __u8 bits; + const char *name; } alarm_types[] = { - { REG_FRS0_LOS, "RED" }, - { REG_FRS0_AIS, "BLUE" }, - { REG_FRS0_RRA, "YELLOW" }, - }; + { + REG_FRS0_LOS, "RED"}, { + REG_FRS0_AIS, "BLUE"}, { + REG_FRS0_RRA, "YELLOW"},}; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2403,11 +2429,13 @@ static DEVICE_ATTR_READER(pri_alarms_show, dev, buf) if (priv->poll_noreplies > 1) len += sprintf(buf + len, "Unknown[%d]", priv->poll_noreplies); else { - int i; + int i; for (i = 0; i < ARRAY_SIZE(alarm_types); i++) { if (priv->reg_frs0 & alarm_types[i].bits) - len += sprintf(buf + len, "%s ", alarm_types[i].name); + len += + sprintf(buf + len, "%s ", + alarm_types[i].name); } } len += sprintf(buf + len, "\n"); @@ -2415,14 +2443,14 @@ static DEVICE_ATTR_READER(pri_alarms_show, dev, buf) return len; } -static DEVICE_ATTR(pri_alarms, S_IRUGO, pri_alarms_show, NULL); +static DEVICE_ATTR(pri_alarms, S_IRUGO, pri_alarms_show, NULL); static DEVICE_ATTR_READER(pri_cas_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2432,10 +2460,10 @@ static DEVICE_ATTR_READER(pri_cas_show, dev, buf) BUG_ON(!priv); spin_lock_irqsave(&xpd->lock, flags); if (priv->is_cas) { - int i; + int i; - len += sprintf(buf + len, - "CAS: replies=%d\n", priv->cas_replies); + len += + sprintf(buf + len, "CAS: replies=%d\n", priv->cas_replies); len += sprintf(buf + len, " CAS-TS: "); for (i = 0; i < NUM_CAS_RS_E; i++) { len += sprintf(buf + len, " %02X", priv->cas_ts_e[i]); @@ -2451,14 +2479,14 @@ static DEVICE_ATTR_READER(pri_cas_show, dev, buf) return len; } -static DEVICE_ATTR(pri_cas, S_IRUGO, pri_cas_show, NULL); +static DEVICE_ATTR(pri_cas, S_IRUGO, pri_cas_show, NULL); static DEVICE_ATTR_READER(pri_dchan_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2467,12 +2495,15 @@ static DEVICE_ATTR_READER(pri_dchan_show, dev, buf) priv = xpd->priv; BUG_ON(!priv); spin_lock_irqsave(&xpd->lock, flags); - len += sprintf(buf + len, "D-Channel: TX=[%5d] (0x%02X) RX=[%5d] (0x%02X) ", - priv->dchan_tx_counter, priv->dchan_tx_sample, - priv->dchan_rx_counter, priv->dchan_rx_sample); + len += + sprintf(buf + len, + "D-Channel: TX=[%5d] (0x%02X) RX=[%5d] (0x%02X) ", + priv->dchan_tx_counter, priv->dchan_tx_sample, + priv->dchan_rx_counter, priv->dchan_rx_sample); if (priv->dchan_alive) { - len += sprintf(buf + len, "(alive %d K-ticks)\n", - priv->dchan_alive_ticks/1000); + len += + sprintf(buf + len, "(alive %d K-ticks)\n", + priv->dchan_alive_ticks / 1000); } else { len += sprintf(buf + len, "(dead)\n"); } @@ -2480,14 +2511,14 @@ static DEVICE_ATTR_READER(pri_dchan_show, dev, buf) return len; } -static DEVICE_ATTR(pri_dchan, S_IRUGO, pri_dchan_show, NULL); +static DEVICE_ATTR(pri_dchan, S_IRUGO, pri_dchan_show, NULL); static DEVICE_ATTR_READER(pri_clocking_show, dev, buf) { - xpd_t *xpd; - struct PRI_priv_data *priv; - unsigned long flags; - int len = 0; + xpd_t *xpd; + struct PRI_priv_data *priv; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -2496,59 +2527,71 @@ static DEVICE_ATTR_READER(pri_clocking_show, dev, buf) priv = xpd->priv; BUG_ON(!priv); spin_lock_irqsave(&xpd->lock, flags); - len += sprintf(buf + len, "%s\n", (priv->clock_source) ? "MASTER" : "SLAVE"); + len += + sprintf(buf + len, "%s\n", + (priv->clock_source) ? "MASTER" : "SLAVE"); spin_unlock_irqrestore(&xpd->lock, flags); return len; } -static DEVICE_ATTR(pri_clocking, S_IRUGO, pri_clocking_show, NULL); +static DEVICE_ATTR(pri_clocking, S_IRUGO, pri_clocking_show, NULL); static int pri_xpd_probe(struct device *dev) { - xpd_t *xpd; - int ret = 0; + xpd_t *xpd; + int ret = 0; xpd = dev_to_xpd(dev); /* Is it our device? */ if (xpd->type != XPD_TYPE_PRI) { - XPD_ERR(xpd, "drop suggestion for %s (%d)\n", - dev_name(dev), xpd->type); + XPD_ERR(xpd, "drop suggestion for %s (%d)\n", dev_name(dev), + xpd->type); return -EINVAL; } XPD_DBG(DEVICES, xpd, "SYSFS\n"); ret = device_create_file(dev, &dev_attr_pri_protocol); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_protocol) failed: %d\n", __func__, ret); + XPD_ERR(xpd, + "%s: device_create_file(pri_protocol) failed: %d\n", + __func__, ret); goto fail_pri_protocol; } ret = device_create_file(dev, &dev_attr_pri_localloop); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_localloop) failed: %d\n", __func__, ret); + XPD_ERR(xpd, + "%s: device_create_file(pri_localloop) failed: %d\n", + __func__, ret); goto fail_pri_localloop; } ret = device_create_file(dev, &dev_attr_pri_layer1); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_layer1) failed: %d\n", __func__, ret); + XPD_ERR(xpd, "%s: device_create_file(pri_layer1) failed: %d\n", + __func__, ret); goto fail_pri_layer1; } ret = device_create_file(dev, &dev_attr_pri_alarms); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_alarms) failed: %d\n", __func__, ret); + XPD_ERR(xpd, "%s: device_create_file(pri_alarms) failed: %d\n", + __func__, ret); goto fail_pri_alarms; } ret = device_create_file(dev, &dev_attr_pri_cas); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_cas) failed: %d\n", __func__, ret); + XPD_ERR(xpd, "%s: device_create_file(pri_cas) failed: %d\n", + __func__, ret); goto fail_pri_cas; } ret = device_create_file(dev, &dev_attr_pri_dchan); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_dchan) failed: %d\n", __func__, ret); + XPD_ERR(xpd, "%s: device_create_file(pri_dchan) failed: %d\n", + __func__, ret); goto fail_pri_dchan; } ret = device_create_file(dev, &dev_attr_pri_clocking); if (ret) { - XPD_ERR(xpd, "%s: device_create_file(pri_clocking) failed: %d\n", __func__, ret); + XPD_ERR(xpd, + "%s: device_create_file(pri_clocking) failed: %d\n", + __func__, ret); goto fail_pri_clocking; } return 0; @@ -2570,7 +2613,7 @@ fail_pri_protocol: static int pri_xpd_remove(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; xpd = dev_to_xpd(dev); XPD_DBG(DEVICES, xpd, "SYSFS\n"); @@ -2584,21 +2627,20 @@ static int pri_xpd_remove(struct device *dev) return 0; } -static struct xpd_driver pri_driver = { - .type = XPD_TYPE_PRI, - .driver = { - .name = "pri", +static struct xpd_driver pri_driver = { + .type = XPD_TYPE_PRI, + .driver = { + .name = "pri", #ifndef OLD_HOTPLUG_SUPPORT - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .probe = pri_xpd_probe, - .remove = pri_xpd_remove - } + .probe = pri_xpd_probe, + .remove = pri_xpd_remove} }; static int __init card_pri_startup(void) { - int ret; + int ret; if ((ret = xpd_driver_register(&pri_driver.driver)) < 0) return ret; diff --git a/drivers/dahdi/xpp/card_pri.h b/drivers/dahdi/xpp/card_pri.h index dbe83c0..4edfd73 100644 --- a/drivers/dahdi/xpp/card_pri.h +++ b/drivers/dahdi/xpp/card_pri.h @@ -25,8 +25,7 @@ #include "xpd.h" enum pri_opcodes { - XPROTO_NAME(PRI, SET_LED) = 0x33, + XPROTO_NAME(PRI, SET_LED) = 0x33, }; - -#endif /* CARD_PRI_H */ +#endif /* CARD_PRI_H */ diff --git a/drivers/dahdi/xpp/dahdi_debug.c b/drivers/dahdi/xpp/dahdi_debug.c index 6c9d052..1f0775a 100644 --- a/drivers/dahdi/xpp/dahdi_debug.c +++ b/drivers/dahdi/xpp/dahdi_debug.c @@ -22,7 +22,7 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #include @@ -35,28 +35,20 @@ static const char rcsid[] = "$Id$"; #define P_(x) [ x ] = { .value = x, .name = #x, } -static struct { +static struct { int value; char *name; } poll_names[] = { - P_(POLLIN), - P_(POLLPRI), - P_(POLLOUT), - P_(POLLERR), - P_(POLLHUP), - P_(POLLNVAL), - P_(POLLRDNORM), - P_(POLLRDBAND), - P_(POLLWRNORM), - P_(POLLWRBAND), - P_(POLLMSG), - P_(POLLREMOVE) + P_(POLLIN), P_(POLLPRI), P_(POLLOUT), P_(POLLERR), P_(POLLHUP), + P_(POLLNVAL), P_(POLLRDNORM), P_(POLLRDBAND), P_(POLLWRNORM), + P_(POLLWRBAND), P_(POLLMSG), P_(POLLREMOVE) }; + #undef P_ void dump_poll(int debug, const char *msg, int poll) { - int i; + int i; for (i = 0; i < ARRAY_SIZE(poll_names); i++) { if (poll & poll_names[i].value) @@ -66,10 +58,10 @@ void dump_poll(int debug, const char *msg, int poll) void alarm2str(int alarm, char *buf, int buflen) { - char *p = buf; - int left = buflen; - int i; - int n; + char *p = buf; + int left = buflen; + int i; + int n; if (!alarm) { snprintf(buf, buflen, "NONE"); @@ -83,7 +75,7 @@ void alarm2str(int alarm, char *buf, int buflen) left -= n; } } - if (p > buf) /* kill last comma */ + if (p > buf) /* kill last comma */ *(p - 1) = '\0'; } diff --git a/drivers/dahdi/xpp/dahdi_debug.h b/drivers/dahdi/xpp/dahdi_debug.h index b93b28d..a621aef 100644 --- a/drivers/dahdi/xpp/dahdi_debug.h +++ b/drivers/dahdi/xpp/dahdi_debug.h @@ -95,11 +95,16 @@ void dump_poll(int debug, const char *msg, int poll); static inline char *rxsig2str(enum dahdi_rxsig sig) { switch (sig) { - case DAHDI_RXSIG_ONHOOK: return "ONHOOK"; - case DAHDI_RXSIG_OFFHOOK: return "OFFHOOK"; - case DAHDI_RXSIG_START: return "START"; - case DAHDI_RXSIG_RING: return "RING"; - case DAHDI_RXSIG_INITIAL: return "INITIAL"; + case DAHDI_RXSIG_ONHOOK: + return "ONHOOK"; + case DAHDI_RXSIG_OFFHOOK: + return "OFFHOOK"; + case DAHDI_RXSIG_START: + return "START"; + case DAHDI_RXSIG_RING: + return "RING"; + case DAHDI_RXSIG_INITIAL: + return "INITIAL"; } return "Unknown rxsig"; } @@ -107,11 +112,16 @@ static inline char *rxsig2str(enum dahdi_rxsig sig) static inline char *txsig2str(enum dahdi_txsig sig) { switch (sig) { - case DAHDI_TXSIG_ONHOOK: return "TXSIG_ONHOOK"; - case DAHDI_TXSIG_OFFHOOK: return "TXSIG_OFFHOOK"; - case DAHDI_TXSIG_START: return "TXSIG_START"; - case DAHDI_TXSIG_KEWL: return "TXSIG_KEWL"; /* Drop battery if possible */ - case DAHDI_TXSIG_TOTAL: break; + case DAHDI_TXSIG_ONHOOK: + return "TXSIG_ONHOOK"; + case DAHDI_TXSIG_OFFHOOK: + return "TXSIG_OFFHOOK"; + case DAHDI_TXSIG_START: + return "TXSIG_START"; + case DAHDI_TXSIG_KEWL: + return "TXSIG_KEWL"; /* Drop battery if possible */ + case DAHDI_TXSIG_TOTAL: + break; } return "Unknown txsig"; } @@ -119,24 +129,42 @@ static inline char *txsig2str(enum dahdi_txsig sig) static inline char *event2str(int event) { switch (event) { - case DAHDI_EVENT_NONE: return "NONE"; - case DAHDI_EVENT_ONHOOK: return "ONHOOK"; - case DAHDI_EVENT_RINGOFFHOOK: return "RINGOFFHOOK"; - case DAHDI_EVENT_WINKFLASH: return "WINKFLASH"; - case DAHDI_EVENT_ALARM: return "ALARM"; - case DAHDI_EVENT_NOALARM: return "NOALARM"; - case DAHDI_EVENT_ABORT: return "ABORT"; - case DAHDI_EVENT_OVERRUN: return "OVERRUN"; - case DAHDI_EVENT_BADFCS: return "BADFCS"; - case DAHDI_EVENT_DIALCOMPLETE: return "DIALCOMPLETE"; - case DAHDI_EVENT_RINGERON: return "RINGERON"; - case DAHDI_EVENT_RINGEROFF: return "RINGEROFF"; - case DAHDI_EVENT_HOOKCOMPLETE: return "HOOKCOMPLETE"; - case DAHDI_EVENT_BITSCHANGED: return "BITSCHANGED"; - case DAHDI_EVENT_PULSE_START: return "PULSE_START"; - case DAHDI_EVENT_TIMER_EXPIRED: return "TIMER_EXPIRED"; - case DAHDI_EVENT_TIMER_PING: return "TIMER_PING"; - case DAHDI_EVENT_POLARITY: return "POLARITY"; + case DAHDI_EVENT_NONE: + return "NONE"; + case DAHDI_EVENT_ONHOOK: + return "ONHOOK"; + case DAHDI_EVENT_RINGOFFHOOK: + return "RINGOFFHOOK"; + case DAHDI_EVENT_WINKFLASH: + return "WINKFLASH"; + case DAHDI_EVENT_ALARM: + return "ALARM"; + case DAHDI_EVENT_NOALARM: + return "NOALARM"; + case DAHDI_EVENT_ABORT: + return "ABORT"; + case DAHDI_EVENT_OVERRUN: + return "OVERRUN"; + case DAHDI_EVENT_BADFCS: + return "BADFCS"; + case DAHDI_EVENT_DIALCOMPLETE: + return "DIALCOMPLETE"; + case DAHDI_EVENT_RINGERON: + return "RINGERON"; + case DAHDI_EVENT_RINGEROFF: + return "RINGEROFF"; + case DAHDI_EVENT_HOOKCOMPLETE: + return "HOOKCOMPLETE"; + case DAHDI_EVENT_BITSCHANGED: + return "BITSCHANGED"; + case DAHDI_EVENT_PULSE_START: + return "PULSE_START"; + case DAHDI_EVENT_TIMER_EXPIRED: + return "TIMER_EXPIRED"; + case DAHDI_EVENT_TIMER_PING: + return "TIMER_PING"; + case DAHDI_EVENT_POLARITY: + return "POLARITY"; } return "Unknown event"; } @@ -144,13 +172,20 @@ static inline char *event2str(int event) static inline char *hookstate2str(int hookstate) { switch (hookstate) { - case DAHDI_ONHOOK: return "DAHDI_ONHOOK"; - case DAHDI_START: return "DAHDI_START"; - case DAHDI_OFFHOOK: return "DAHDI_OFFHOOK"; - case DAHDI_WINK: return "DAHDI_WINK"; - case DAHDI_FLASH: return "DAHDI_FLASH"; - case DAHDI_RING: return "DAHDI_RING"; - case DAHDI_RINGOFF: return "DAHDI_RINGOFF"; + case DAHDI_ONHOOK: + return "DAHDI_ONHOOK"; + case DAHDI_START: + return "DAHDI_START"; + case DAHDI_OFFHOOK: + return "DAHDI_OFFHOOK"; + case DAHDI_WINK: + return "DAHDI_WINK"; + case DAHDI_FLASH: + return "DAHDI_FLASH"; + case DAHDI_RING: + return "DAHDI_RING"; + case DAHDI_RINGOFF: + return "DAHDI_RINGOFF"; } return "Unknown hookstate"; } @@ -159,25 +194,42 @@ static inline char *hookstate2str(int hookstate) static inline char *sig2str(int sig) { switch (sig) { - case DAHDI_SIG_FXSLS: return "FXSLS"; - case DAHDI_SIG_FXSKS: return "FXSKS"; - case DAHDI_SIG_FXSGS: return "FXSGS"; - case DAHDI_SIG_FXOLS: return "FXOLS"; - case DAHDI_SIG_FXOKS: return "FXOKS"; - case DAHDI_SIG_FXOGS: return "FXOGS"; - case DAHDI_SIG_EM: return "E&M"; - case DAHDI_SIG_EM_E1: return "E&M-E1"; - case DAHDI_SIG_CLEAR: return "Clear"; - case DAHDI_SIG_HDLCRAW: return "HDLCRAW"; - case DAHDI_SIG_HDLCFCS: return "HDLCFCS"; - case DAHDI_SIG_HDLCNET: return "HDLCNET"; - case DAHDI_SIG_SLAVE: return "Slave"; - case DAHDI_SIG_CAS: return "CAS"; - case DAHDI_SIG_DACS: return "DACS"; - case DAHDI_SIG_DACS_RBS: return "DACS+RBS"; - case DAHDI_SIG_SF: return "SF (ToneOnly)"; - case DAHDI_SIG_NONE: - break; + case DAHDI_SIG_FXSLS: + return "FXSLS"; + case DAHDI_SIG_FXSKS: + return "FXSKS"; + case DAHDI_SIG_FXSGS: + return "FXSGS"; + case DAHDI_SIG_FXOLS: + return "FXOLS"; + case DAHDI_SIG_FXOKS: + return "FXOKS"; + case DAHDI_SIG_FXOGS: + return "FXOGS"; + case DAHDI_SIG_EM: + return "E&M"; + case DAHDI_SIG_EM_E1: + return "E&M-E1"; + case DAHDI_SIG_CLEAR: + return "Clear"; + case DAHDI_SIG_HDLCRAW: + return "HDLCRAW"; + case DAHDI_SIG_HDLCFCS: + return "HDLCFCS"; + case DAHDI_SIG_HDLCNET: + return "HDLCNET"; + case DAHDI_SIG_SLAVE: + return "Slave"; + case DAHDI_SIG_CAS: + return "CAS"; + case DAHDI_SIG_DACS: + return "DACS"; + case DAHDI_SIG_DACS_RBS: + return "DACS+RBS"; + case DAHDI_SIG_SF: + return "SF (ToneOnly)"; + case DAHDI_SIG_NONE: + break; } return "Unconfigured"; } @@ -186,17 +238,24 @@ static inline char *alarmbit2str(int alarmbit) { /* from dahdi/kernel.h */ switch (1 << alarmbit) { - case DAHDI_ALARM_NONE: return "NONE"; - case DAHDI_ALARM_RECOVER: return "RECOVER"; - case DAHDI_ALARM_LOOPBACK: return "LOOPBACK"; - case DAHDI_ALARM_YELLOW: return "YELLOW"; - case DAHDI_ALARM_RED: return "RED"; - case DAHDI_ALARM_BLUE: return "BLUE"; - case DAHDI_ALARM_NOTOPEN: return "NOTOPEN"; + case DAHDI_ALARM_NONE: + return "NONE"; + case DAHDI_ALARM_RECOVER: + return "RECOVER"; + case DAHDI_ALARM_LOOPBACK: + return "LOOPBACK"; + case DAHDI_ALARM_YELLOW: + return "YELLOW"; + case DAHDI_ALARM_RED: + return "RED"; + case DAHDI_ALARM_BLUE: + return "BLUE"; + case DAHDI_ALARM_NOTOPEN: + return "NOTOPEN"; } return "UNKNOWN"; } void alarm2str(int alarm, char *buf, int buflen); -#endif /* DAHDI_DEBUG_H */ +#endif /* DAHDI_DEBUG_H */ diff --git a/drivers/dahdi/xpp/mmapbus.c b/drivers/dahdi/xpp/mmapbus.c index ffe9358..72f4a39 100644 --- a/drivers/dahdi/xpp/mmapbus.c +++ b/drivers/dahdi/xpp/mmapbus.c @@ -7,7 +7,9 @@ static int mmap_match(struct device *dev, struct device_driver *driver) { return !strncmp(dev_name(dev), driver->name, strlen(driver->name)); } -static int mmap_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size) + +static int mmap_uevent(struct device *dev, char **envp, int num_envp, + char *buffer, int buffer_size) { envp[0] = buffer; envp[1] = NULL; @@ -33,8 +35,6 @@ static struct device mmap_bus = { .release = mmap_bus_release, }; - - int register_mmap_device(struct mmap_device *dev) { dev->dev.bus = &mmap_bus_type; @@ -48,6 +48,7 @@ void unregister_mmap_device(struct mmap_device *dev) { device_unregister(&dev->dev); } + EXPORT_SYMBOL(register_mmap_device); EXPORT_SYMBOL(unregister_mmap_device); @@ -61,6 +62,7 @@ void unregister_mmap_driver(struct mmap_driver *driver) { driver_unregister(&driver->driver); } + EXPORT_SYMBOL(register_mmap_driver); EXPORT_SYMBOL(unregister_mmap_driver); @@ -84,6 +86,7 @@ void unregister_mmap_bus(void) device_unregister(&mmap_bus); bus_unregister(&mmap_bus_type); } + EXPORT_SYMBOL(register_mmap_bus); EXPORT_SYMBOL(unregister_mmap_bus); diff --git a/drivers/dahdi/xpp/mmapdrv.c b/drivers/dahdi/xpp/mmapdrv.c index 8dee19c..73cb866 100644 --- a/drivers/dahdi/xpp/mmapdrv.c +++ b/drivers/dahdi/xpp/mmapdrv.c @@ -19,11 +19,13 @@ #include "xframe_queue.h" /* Check at compile time that sizeof(xframe_t) is a multiple of 4 */ -typedef char sizeof_xframe_t_should_be_divisible_by_4[((sizeof(xframe_t) % 4) == 0) * 2 - 1]; +typedef char + sizeof_xframe_t_should_be_divisible_by_4[((sizeof(xframe_t) % 4) == + 0) * 2 - 1]; #define ssync() __builtin_bfin_ssync() -//#define AB_IN_BUF PF5 +//#define AB_IN_BUF PF5 /* firmware pins */ #define DATA PG8 #define NCONFIG PG9 @@ -39,7 +41,7 @@ typedef char sizeof_xframe_t_should_be_divisible_by_4[((sizeof(xframe_t) % 4) == #define DEBUG_GPIO1 CONF_DONE #define DEBUG_GPIO2 NSTATUS -static int rx_intr_counter; +static int rx_intr_counter; #endif #define FPGA_RX_IRQ IRQ_PF7 @@ -49,9 +51,9 @@ static int rx_intr_counter; #define END_OF_FRAME 0x0001 #define GET_LEN 0x0002 #define START_RD_BURST 0x0008 -#define AS_BF_MODE 0x0010 //stand alone Astribank without USB (Asterisk BlackFin Mode) -#define EC_BF_MODE 0x0020 //all data between Astribank and USB routed thru BF(EchoCanceler BlackFin Mode) -#define NO_BF_MODE 0x0040 //Astribank worke with USB only (no BlackFin Mode) +#define AS_BF_MODE 0x0010 //stand alone Astribank without USB (Asterisk BlackFin Mode) +#define EC_BF_MODE 0x0020 //all data between Astribank and USB routed thru BF(EchoCanceler BlackFin Mode) +#define NO_BF_MODE 0x0040 //Astribank worke with USB only (no BlackFin Mode) #define SET_XA_DIR 0x0080 #define GET_XPD_STS 0x0100 #define GET_CHECKSUM 0x0200 @@ -96,7 +98,8 @@ static void update_counter(struct counter *c, struct timeval *tv1) c->intr_min = diff; if (c->intr_max < diff) c->intr_max = diff; - c->intr_avg = (c->intr_avg*c->intr_count + diff) / (c->intr_count+1); + c->intr_avg = + (c->intr_avg * c->intr_count + diff) / (c->intr_count + 1); c->intr_count++; } @@ -153,18 +156,19 @@ static irqreturn_t xpp_mmap_rx_irq(int irq, void *dev_id) outw(START_RD_BURST, FPGA_BASE_ADDR + 4); insw((unsigned long)FPGA_BASE_ADDR, buf, rxcnt / 2); #if 0 - for (count = 0; count < rxcnt; count+=2) { + for (count = 0; count < rxcnt; count += 2) { unsigned short v = inw(FPGA_BASE_ADDR); buf[count] = v & 0xFF; - buf[count+1] = v >> 8; + buf[count + 1] = v >> 8; } #endif if (rxcnt & 1) - buf[rxcnt-1] = inw(FPGA_BASE_ADDR); + buf[rxcnt - 1] = inw(FPGA_BASE_ADDR); /* Sanity check: length of first packet in frame should be no more than the frame length */ - if (((buf[0] | (buf[1]<<8)) & 0x3FF) > rxcnt) { + if (((buf[0] | (buf[1] << 8)) & 0x3FF) > rxcnt) { if (printk_ratelimit()) { - ERR("Packet len=%d, frame len=%d\n", (buf[0] | (buf[1]<<8)) & 0x3FF, rxcnt); + ERR("Packet len=%d, frame len=%d\n", + (buf[0] | (buf[1] << 8)) & 0x3FF, rxcnt); print_buffer("16 bytes of packet: ", buf, 16); } goto free; @@ -199,7 +203,7 @@ static void send_buffer(unsigned char *buf, unsigned long len) print_buffer("Sent: ", buf, len); outsw((unsigned long)FPGA_BASE_ADDR, buf, len / 2); if (len & 1) - outw((unsigned short)buf[len-1], FPGA_BASE_ADDR); + outw((unsigned short)buf[len - 1], FPGA_BASE_ADDR); outw(END_OF_FRAME, FPGA_BASE_ADDR + 4); } @@ -258,7 +262,9 @@ static int xframe_send_common(xbus_t *xbus, xframe_t *xframe, bool pcm) if (pcm && pcm_in_pool_count >= 1) { static int rate_limit; if ((rate_limit++ % 1000) == 0) - XBUS_ERR(xbus, "Dropped PCM xframe (pcm_in_pool_count=%d).\n", pcm_in_pool_count); + XBUS_ERR(xbus, + "Dropped PCM xframe (pcm_in_pool_count=%d).\n", + pcm_in_pool_count); FREE_SEND_XFRAME(xbus, xframe); pcm_dropped++; } else { @@ -266,7 +272,8 @@ static int xframe_send_common(xbus_t *xbus, xframe_t *xframe, bool pcm) static int rate_limit; spin_unlock_irqrestore(&tx_ready_lock, flags); if ((rate_limit++ % 1000) == 0) - XBUS_ERR(xbus, "Dropped xframe. Cannot enqueue.\n"); + XBUS_ERR(xbus, + "Dropped xframe. Cannot enqueue.\n"); FREE_SEND_XFRAME(xbus, xframe); return -E2BIG; } @@ -284,10 +291,12 @@ static xframe_t *alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) if (!xframe) { static int rate_limit; if ((rate_limit++ % 1000) < 5) - XBUS_ERR(xbus, "frame allocation failed (%d)\n", rate_limit); + XBUS_ERR(xbus, "frame allocation failed (%d)\n", + rate_limit); return NULL; } - xframe_init(xbus, xframe, ((__u8*)xframe) + sizeof(xframe_t), XFRAME_DATASIZE, xbus); + xframe_init(xbus, xframe, ((__u8 *)xframe) + sizeof(xframe_t), + XFRAME_DATASIZE, xbus); return xframe; } @@ -316,28 +325,26 @@ static struct xbus_ops xmmap_ops = { static int fill_proc_queue(char *p, struct xframe_queue *q) { - int len; + int len; - len = sprintf(p, - "%-15s: counts %3d, %3d, %3d worst %3d, overflows %3d worst_lag %02ld.%ld ms\n", - q->name, - q->steady_state_count, - q->count, - q->max_count, - q->worst_count, - q->overflows, - q->worst_lag_usec / 1000, - q->worst_lag_usec % 1000); + len = + sprintf(p, + "%-15s: counts %3d, %3d, %3d worst %3d, overflows %3d worst_lag %02ld.%ld ms\n", + q->name, q->steady_state_count, q->count, q->max_count, + q->worst_count, q->overflows, q->worst_lag_usec / 1000, + q->worst_lag_usec % 1000); xframe_queue_clearstats(q); return len; } static int fill_proc_counter(char *p, struct counter *c) { - return sprintf(p, "min=%ld\nmax=%ld\navg=%ld\ncount=%ld\n", c->intr_min, c->intr_max, c->intr_avg, c->intr_count); + return sprintf(p, "min=%ld\nmax=%ld\navg=%ld\ncount=%ld\n", c->intr_min, + c->intr_max, c->intr_avg, c->intr_count); } -static int xpp_mmap_proc_read(char *page, char **start, off_t off, int count, int *eof, void *data) +static int xpp_mmap_proc_read(char *page, char **start, off_t off, int count, + int *eof, void *data) { int len = 0; len += fill_proc_queue(page + len, &txpool); @@ -347,7 +354,7 @@ static int xpp_mmap_proc_read(char *page, char **start, off_t off, int count, in len += fill_proc_counter(page + len, &rx_counter); len += sprintf(page + len, "\ntx_counter:\n"); len += fill_proc_counter(page + len, &tx_counter); - if (len <= off+count) { + if (len <= off + count) { *eof = 1; tx_counter.intr_min = rx_counter.intr_min = INT_MAX; tx_counter.intr_max = rx_counter.intr_max = 0; @@ -363,14 +370,15 @@ static int xpp_mmap_proc_read(char *page, char **start, off_t off, int count, in return len; } -static int xpp_mmap_proc_write(struct file *file, const char __user *buffer, unsigned long count, void *data) +static int xpp_mmap_proc_write(struct file *file, const char __user *buffer, + unsigned long count, void *data) { int i = 0; char *txchunk, *p, *endp; - if (count >= XFRAME_DATASIZE*3+10) + if (count >= XFRAME_DATASIZE * 3 + 10) return -EINVAL; - p = txchunk = kmalloc(count+1, GFP_KERNEL); + p = txchunk = kmalloc(count + 1, GFP_KERNEL); if (copy_from_user(txchunk, buffer, count)) { count = -EFAULT; goto out; @@ -379,13 +387,15 @@ static int xpp_mmap_proc_write(struct file *file, const char __user *buffer, uns while (*p) { unsigned long value; - while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') p++; - if (*p == '\0') break; + while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r') + p++; + if (*p == '\0') + break; value = simple_strtoul(p, &endp, 16); if (endp == p || value > 0xFF) { - INFO("%s: Bad input\n", __func__); - count = -EINVAL; - goto out; + INFO("%s: Bad input\n", __func__); + count = -EINVAL; + goto out; } p = endp; txchunk[i++] = (char)value; @@ -399,8 +409,8 @@ out: static struct mmap_driver astribank_driver = { .module = THIS_MODULE, .driver = { - .name = "xpp_mmap", - }, + .name = "xpp_mmap", + }, }; static struct mmap_device astribank_dev = { @@ -408,42 +418,43 @@ static struct mmap_device astribank_dev = { .driver = &astribank_driver, }; -static int __init xpp_mmap_load_fpga(u8 *data, size_t size) +static int __init xpp_mmap_load_fpga(u8 * data, size_t size) { size_t i; - bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() | DATA | NCONFIG | DCLK); //set data, nconfig and dclk to port out + bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() | DATA | NCONFIG | DCLK); //set data, nconfig and dclk to port out bfin_write_PORTG_FER(bfin_read_PORTG_FER() & ~(DATA | NCONFIG | DCLK)); - bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() & ~(CONF_DONE | NSTATUS));//set conf_done and nstatus to port in - bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & ~(DATA | NCONFIG | DCLK)); + bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() & ~(CONF_DONE | NSTATUS)); //set conf_done and nstatus to port in + bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & + ~(DATA | NCONFIG | DCLK)); bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() | CONF_DONE | NSTATUS); - bfin_write_PORTGIO_CLEAR(NCONFIG); //reset fpga during configuration holds nCONFIG low - udelay(40); //Tcfg ~40us delay - bfin_write_PORTGIO_SET(NCONFIG); //transition nCONFIG to high - reset end. - udelay(40); //Tcf2ck ~40us delay + bfin_write_PORTGIO_CLEAR(NCONFIG); //reset fpga during configuration holds nCONFIG low + udelay(40); //Tcfg ~40us delay + bfin_write_PORTGIO_SET(NCONFIG); //transition nCONFIG to high - reset end. + udelay(40); //Tcf2ck ~40us delay if (!(bfin_read_PORTGIO() & NSTATUS)) - return -EIO; //report reset faill - Tcf2st1 pass + return -EIO; //report reset faill - Tcf2st1 pass #if 0 if (!(bfin_read_PORTGIO() & CONF_DONE)) return -EIO; #endif bfin_write_PORTGIO_CLEAR(DCLK); - for (i=0; i>= 1; + __u8 >>=1; bfin_write_PORTGIO_SET(DCLK); bfin_write_PORTGIO_CLEAR(DCLK); } if (!(bfin_read_PORTGIO() & NSTATUS)) - return -EIO; //check the nSTATUS + return -EIO; //check the nSTATUS } bfin_write_PORTGIO_CLEAR(DATA); udelay(1); @@ -455,20 +466,22 @@ static int __init xpp_mmap_load_fpga(u8 *data, size_t size) * some pins that were used only during initialization * to be used for debugging from now on. */ - bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() | DEBUG_GPIO1 | DEBUG_GPIO2); //set to port out - bfin_write_PORTG_FER(bfin_read_PORTG_FER() & ~(DEBUG_GPIO1 | DEBUG_GPIO2)); - bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & ~(DEBUG_GPIO1 | DEBUG_GPIO2)); + bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() | DEBUG_GPIO1 | DEBUG_GPIO2); //set to port out + bfin_write_PORTG_FER(bfin_read_PORTG_FER() & + ~(DEBUG_GPIO1 | DEBUG_GPIO2)); + bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & + ~(DEBUG_GPIO1 | DEBUG_GPIO2)); #endif - udelay(40); //tCD2UM - CONF_DONE high to user mode + udelay(40); //tCD2UM - CONF_DONE high to user mode return 0; } static void __exit xpp_mmap_unload_fpga(void) { - bfin_write_PORTGIO_CLEAR(NCONFIG); //reset fpga during configuration holds nCONFIG low - udelay(40); //Tcfg ~40us delay - bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() & ~( DATA | NCONFIG | DCLK)); //disable output pin - bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & ~( CONF_DONE | NSTATUS));//disable input buffer + bfin_write_PORTGIO_CLEAR(NCONFIG); //reset fpga during configuration holds nCONFIG low + udelay(40); //Tcfg ~40us delay + bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() & ~(DATA | NCONFIG | DCLK)); //disable output pin + bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & ~(CONF_DONE | NSTATUS)); //disable input buffer INFO("FPGA Firmware unloaded\n"); } @@ -476,7 +489,8 @@ static int __init xpp_mmap_load_firmware(void) { const struct firmware *fw; int ret; - if ((ret = request_firmware(&fw, "astribank.bin", &astribank_dev.dev)) < 0) + if ((ret = + request_firmware(&fw, "astribank.bin", &astribank_dev.dev)) < 0) return ret; xpp_mmap_load_fpga(fw->data, fw->size); release_firmware(fw); @@ -499,27 +513,31 @@ static int __init xpp_mmap_init(void) goto fail_fw; } - if ((ret = request_irq(FPGA_RX_IRQ, xpp_mmap_rx_irq, IRQF_TRIGGER_RISING, "xpp_mmap_rx", NULL)) < 0) { + if ((ret = + request_irq(FPGA_RX_IRQ, xpp_mmap_rx_irq, IRQF_TRIGGER_RISING, + "xpp_mmap_rx", NULL)) < 0) { ERR("Unable to attach to RX interrupt %d\n", FPGA_RX_IRQ); goto fail_irq_rx; } - if ((ret = request_irq(FPGA_TX_IRQ, xpp_mmap_tx_irq, IRQF_TRIGGER_RISING, "xpp_mmap_tx", NULL)) < 0) { + if ((ret = + request_irq(FPGA_TX_IRQ, xpp_mmap_tx_irq, IRQF_TRIGGER_RISING, + "xpp_mmap_tx", NULL)) < 0) { ERR("Unable to attach to TX interrupt %d\n", FPGA_TX_IRQ); goto fail_irq_tx; } - if (!request_region((resource_size_t)FPGA_BASE_ADDR, 8, "xpp_mmap")) { + if (!request_region((resource_size_t) FPGA_BASE_ADDR, 8, "xpp_mmap")) { ERR("Unable to request memory region at %p\n", FPGA_BASE_ADDR); goto fail_region; } outw(AS_BF_MODE, FPGA_BASE_ADDR + 4); - xframe_cache = kmem_cache_create("xframe_cache", - sizeof(xframe_t) + XFRAME_DATASIZE, - 0, 0, + xframe_cache = + kmem_cache_create("xframe_cache", + sizeof(xframe_t) + XFRAME_DATASIZE, 0, 0, #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) - NULL, + NULL, #endif - NULL); + NULL); if (!xframe_cache) { ret = -ENOMEM; goto fail_cache; @@ -534,7 +552,9 @@ static int __init xpp_mmap_init(void) strncpy(global_xbus->label, "mmap:0", LABEL_SIZE); xframe_queue_init(&txpool, 10, 200, "mmap_txpool", global_xbus); - if (!(proc_entry = create_proc_entry("xpp_mmap", 0, global_xbus->proc_xbus_dir))) { + if (! + (proc_entry = + create_proc_entry("xpp_mmap", 0, global_xbus->proc_xbus_dir))) { ERR("create_proc_entry() failed\n"); ret = -EINVAL; goto fail_proc; @@ -552,7 +572,7 @@ fail_proc: fail_xbus: kmem_cache_destroy(xframe_cache); fail_cache: - release_region((resource_size_t)FPGA_BASE_ADDR, 8); + release_region((resource_size_t) FPGA_BASE_ADDR, 8); fail_region: free_irq(FPGA_TX_IRQ, NULL); fail_irq_tx: @@ -579,7 +599,7 @@ static void __exit xpp_mmap_exit(void) xbus_disconnect(xbus); kmem_cache_destroy(xframe_cache); - release_region((resource_size_t)FPGA_BASE_ADDR, 8); + release_region((resource_size_t) FPGA_BASE_ADDR, 8); free_irq(FPGA_RX_IRQ, NULL); free_irq(FPGA_TX_IRQ, NULL); diff --git a/drivers/dahdi/xpp/parport_debug.c b/drivers/dahdi/xpp/parport_debug.c index 8a1dd53..40eb148 100644 --- a/drivers/dahdi/xpp/parport_debug.c +++ b/drivers/dahdi/xpp/parport_debug.c @@ -22,7 +22,7 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #include @@ -30,21 +30,21 @@ #include #include "parport_debug.h" -static struct parport *debug_sync_parport; -static int parport_toggles[8]; /* 8 bit flip-flop */ +static struct parport *debug_sync_parport; +static int parport_toggles[8]; /* 8 bit flip-flop */ void flip_parport_bit(unsigned char bitnum) { - static unsigned char last_value; + static unsigned char last_value; DEFINE_SPINLOCK(lock); - unsigned long flags; - unsigned char mask; - unsigned char value; + unsigned long flags; + unsigned char mask; + unsigned char value; if (!debug_sync_parport) { if (printk_ratelimit()) { printk(KERN_NOTICE "%s: no debug parallel port\n", - THIS_MODULE->name); + THIS_MODULE->name); } return; } @@ -59,14 +59,16 @@ void flip_parport_bit(unsigned char bitnum) spin_unlock_irqrestore(&lock, flags); parport_write_data(debug_sync_parport, value); } + EXPORT_SYMBOL(flip_parport_bit); static void parport_attach(struct parport *port) { - printk(KERN_INFO "%s: Using %s for debugging\n", THIS_MODULE->name, port->name); + printk(KERN_INFO "%s: Using %s for debugging\n", THIS_MODULE->name, + port->name); if (debug_sync_parport) { printk(KERN_ERR "%s: Using %s, ignore new attachment %s\n", - THIS_MODULE->name, debug_sync_parport->name, port->name); + THIS_MODULE->name, debug_sync_parport->name, port->name); return; } parport_get_port(port); @@ -78,14 +80,14 @@ static void parport_detach(struct parport *port) printk(KERN_INFO "%s: Releasing %s\n", THIS_MODULE->name, port->name); if (debug_sync_parport != port) { printk(KERN_ERR "%s: Using %s, ignore new detachment %s\n", - THIS_MODULE->name, debug_sync_parport->name, port->name); + THIS_MODULE->name, debug_sync_parport->name, port->name); return; } parport_put_port(debug_sync_parport); debug_sync_parport = NULL; } -static struct parport_driver debug_parport_driver = { +static struct parport_driver debug_parport_driver = { .name = "parport_debug", .attach = parport_attach, .detach = parport_detach, @@ -93,7 +95,7 @@ static struct parport_driver debug_parport_driver = { int __init parallel_dbg_init(void) { - int ret; + int ret; ret = parport_register_driver(&debug_parport_driver); return ret; diff --git a/drivers/dahdi/xpp/parport_debug.h b/drivers/dahdi/xpp/parport_debug.h index 138af99..61fd6db 100644 --- a/drivers/dahdi/xpp/parport_debug.h +++ b/drivers/dahdi/xpp/parport_debug.h @@ -28,4 +28,4 @@ void flip_parport_bit(unsigned char bitnum); #define flip_parport_bit(bitnum) #endif -#endif /* PARPORT_DEBUG_H */ +#endif /* PARPORT_DEBUG_H */ diff --git a/drivers/dahdi/xpp/print_fxo_modes.c b/drivers/dahdi/xpp/print_fxo_modes.c index 7ecab36..8fd486e 100644 --- a/drivers/dahdi/xpp/print_fxo_modes.c +++ b/drivers/dahdi/xpp/print_fxo_modes.c @@ -4,10 +4,11 @@ int main(int argc, char *argv[]) { size_t i; - for (i=0; i<(sizeof(fxo_modes)/sizeof(struct fxo_mode)); i++) { - if (fxo_modes[i].name == NULL) break; - int reg16=0, reg26=0, reg30=0, reg31=0x20; - char ring_osc[BUFSIZ]="", ring_x[BUFSIZ] = ""; + for (i = 0; i < (sizeof(fxo_modes) / sizeof(struct fxo_mode)); i++) { + if (fxo_modes[i].name == NULL) + break; + int reg16 = 0, reg26 = 0, reg30 = 0, reg31 = 0x20; + char ring_osc[BUFSIZ] = "", ring_x[BUFSIZ] = ""; reg16 |= (fxo_modes[i].ohs << 6); reg16 |= (fxo_modes[i].rz << 1); @@ -22,11 +23,15 @@ int main(int argc, char *argv[]) reg31 |= (fxo_modes[i].ohs2 << 3); if (fxo_modes[i].ring_osc) - snprintf(ring_osc, BUFSIZ, "ring_osc=%04X", fxo_modes[i].ring_osc); + snprintf(ring_osc, BUFSIZ, "ring_osc=%04X", + fxo_modes[i].ring_osc); if (fxo_modes[i].ring_x) - snprintf(ring_x, BUFSIZ, "ring_x=%04X", fxo_modes[i].ring_x); - printf("%-15s\treg16=%02X\treg26=%02X\treg30=%02X\treg31=%02X\t%s\t%s\n", - fxo_modes[i].name, reg16, reg26, reg30, reg31, ring_osc, ring_x); + snprintf(ring_x, BUFSIZ, "ring_x=%04X", + fxo_modes[i].ring_x); + printf + ("%-15s\treg16=%02X\treg26=%02X\treg30=%02X\treg31=%02X\t%s\t%s\n", + fxo_modes[i].name, reg16, reg26, reg30, reg31, ring_osc, + ring_x); } return 0; } diff --git a/drivers/dahdi/xpp/xbus-core.c b/drivers/dahdi/xpp/xbus-core.c index cdb0250..79c74d3 100644 --- a/drivers/dahdi/xpp/xbus-core.c +++ b/drivers/dahdi/xpp/xbus-core.c @@ -22,7 +22,7 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #include @@ -45,45 +45,51 @@ static const char rcsid[] = "$Id$"; /* Defines */ -#define INITIALIZATION_TIMEOUT (90*HZ) /* in jiffies */ +#define INITIALIZATION_TIMEOUT (90*HZ) /* in jiffies */ #define PROC_XBUSES "xbuses" #define PROC_XBUS_SUMMARY "summary" #ifdef PROTOCOL_DEBUG #ifdef CONFIG_PROC_FS #define PROC_XBUS_COMMAND "command" -static int proc_xbus_command_write(struct file *file, const char __user *buffer, unsigned long count, void *data); +static int proc_xbus_command_write(struct file *file, const char __user *buffer, + unsigned long count, void *data); #endif #endif /* Command line parameters */ extern int debug; -static DEF_PARM(uint, command_queue_length, 1500, 0444, "Maximal command queue length"); -static DEF_PARM(uint, poll_timeout, 1000, 0644, "Timeout (in jiffies) waiting for units to reply"); +static DEF_PARM(uint, command_queue_length, 1500, 0444, + "Maximal command queue length"); +static DEF_PARM(uint, poll_timeout, 1000, 0644, + "Timeout (in jiffies) waiting for units to reply"); static DEF_PARM_BOOL(rx_tasklet, 0, 0644, "Use receive tasklets"); static DEF_PARM_BOOL(dahdi_autoreg, 0, 0644, - "Register devices automatically (1) or not (0)"); + "Register devices automatically (1) or not (0)"); #ifdef CONFIG_PROC_FS -static int xbus_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data); +static int xbus_read_proc(char *page, char **start, off_t off, int count, + int *eof, void *data); #endif -static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv); +static void transport_init(xbus_t *xbus, struct xbus_ops *ops, + ushort max_send_size, + struct device *transport_device, void *priv); static void transport_destroy(xbus_t *xbus); /* Data structures */ static DEFINE_SPINLOCK(xbuses_lock); #ifdef CONFIG_PROC_FS -static struct proc_dir_entry *proc_xbuses; +static struct proc_dir_entry *proc_xbuses; #endif static struct xbus_desc { - xbus_t *xbus; + xbus_t *xbus; } xbuses_array[MAX_BUSES]; static xbus_t *xbus_byhwid(const char *hwid) { - int i; - xbus_t *xbus; + int i; + xbus_t *xbus; for (i = 0; i < ARRAY_SIZE(xbuses_array); i++) { xbus = xbuses_array[i].xbus; @@ -98,16 +104,15 @@ int xbus_check_unique(xbus_t *xbus) if (!xbus) return -ENOENT; if (xbus->label && *(xbus->label)) { - xbus_t *xbus_old; + xbus_t *xbus_old; XBUS_DBG(DEVICES, xbus, "Checking LABEL='%s'\n", xbus->label); xbus_old = xbus_byhwid(xbus->label); if (xbus_old && xbus_old != xbus) { XBUS_NOTICE(xbus_old, - "Duplicate LABEL='%s'. Leave %s unused. refcount_xbus=%d\n", - xbus_old->label, - xbus->busname, - refcount_xbus(xbus_old)); + "Duplicate LABEL='%s'. Leave %s unused. refcount_xbus=%d\n", + xbus_old->label, xbus->busname, + refcount_xbus(xbus_old)); return -EBUSY; } } else { @@ -119,21 +124,29 @@ int xbus_check_unique(xbus_t *xbus) const char *xbus_statename(enum xbus_state st) { switch (st) { - case XBUS_STATE_START: return "START"; - case XBUS_STATE_IDLE: return "IDLE"; - case XBUS_STATE_SENT_REQUEST: return "SENT_REQUEST"; - case XBUS_STATE_RECVD_DESC: return "RECVD_DESC"; - case XBUS_STATE_READY: return "READY"; - case XBUS_STATE_DEACTIVATING: return "DEACTIVATING"; - case XBUS_STATE_DEACTIVATED: return "DEACTIVATED"; - case XBUS_STATE_FAIL: return "FAIL"; + case XBUS_STATE_START: + return "START"; + case XBUS_STATE_IDLE: + return "IDLE"; + case XBUS_STATE_SENT_REQUEST: + return "SENT_REQUEST"; + case XBUS_STATE_RECVD_DESC: + return "RECVD_DESC"; + case XBUS_STATE_READY: + return "READY"; + case XBUS_STATE_DEACTIVATING: + return "DEACTIVATING"; + case XBUS_STATE_DEACTIVATED: + return "DEACTIVATED"; + case XBUS_STATE_FAIL: + return "FAIL"; } return NULL; } static void init_xbus(uint num, xbus_t *xbus) { - struct xbus_desc *desc; + struct xbus_desc *desc; BUG_ON(num >= ARRAY_SIZE(xbuses_array)); desc = &xbuses_array[num]; @@ -142,7 +155,7 @@ static void init_xbus(uint num, xbus_t *xbus) xbus_t *xbus_num(uint num) { - struct xbus_desc *desc; + struct xbus_desc *desc; if (num >= ARRAY_SIZE(xbuses_array)) return NULL; @@ -152,7 +165,7 @@ xbus_t *xbus_num(uint num) static void initialize_xbuses_array(void) { - int i; + int i; for (i = 0; i < ARRAY_SIZE(xbuses_array); i++) init_xbus(i, NULL); @@ -160,7 +173,7 @@ static void initialize_xbuses_array(void) static void finalize_xbuses_array(void) { - int i; + int i; for (i = 0; i < ARRAY_SIZE(xbuses_array); i++) { if (xbuses_array[i].xbus != NULL) { @@ -175,7 +188,7 @@ static void finalize_xbuses_array(void) */ static void xbus_destroy(struct kref *kref) { - xbus_t *xbus; + xbus_t *xbus; xbus = kref_to_xbus(kref); XBUS_NOTICE(xbus, "%s\n", __func__); @@ -184,15 +197,15 @@ static void xbus_destroy(struct kref *kref) xbus_t *get_xbus(const char *msg, uint num) { - unsigned long flags; - xbus_t *xbus; + unsigned long flags; + xbus_t *xbus; spin_lock_irqsave(&xbuses_lock, flags); xbus = xbus_num(num); if (xbus != NULL) { kref_get(&xbus->kref); - XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n", - msg, refcount_xbus(xbus)); + XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n", msg, + refcount_xbus(xbus)); } spin_unlock_irqrestore(&xbuses_lock, flags); return xbus; @@ -200,8 +213,8 @@ xbus_t *get_xbus(const char *msg, uint num) void put_xbus(const char *msg, xbus_t *xbus) { - XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n", - msg, refcount_xbus(xbus)); + XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n", msg, + refcount_xbus(xbus)); kref_put(&xbus->kref, xbus_destroy); } @@ -214,7 +227,8 @@ int refcount_xbus(xbus_t *xbus) /*------------------------- Frame Handling ------------------------*/ -void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize, void *priv) +void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize, + void *priv) { memset(xframe, 0, sizeof(*xframe)); INIT_LIST_HEAD(&xframe->frame_list); @@ -241,7 +255,7 @@ xpacket_t *xframe_next_packet(xframe_t *frm, int len) int newlen = XFRAME_LEN(frm); newlen += len; -// DBG(GENERAL, "len=%d, newlen=%d, frm->frame_len=%d\n", len, newlen, XFRAME_LEN(frm)); +// DBG(GENERAL, "len=%d, newlen=%d, frm->frame_len=%d\n", len, newlen, XFRAME_LEN(frm)); if (newlen > XFRAME_DATASIZE) { return NULL; } @@ -253,42 +267,45 @@ static DEFINE_SPINLOCK(serialize_dump_xframe); static void do_hexdump(const char msg[], __u8 *data, uint16_t len) { - int i; - int debug = DBG_ANY; /* mask global debug */ + int i; + int debug = DBG_ANY; /* mask global debug */ for (i = 0; i < len; i++) DBG(ANY, "%s: %3d> %02X\n", msg, i, data[i]); } -void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, int debug) +void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, + int debug) { - const uint16_t frm_len = XFRAME_LEN(xframe); - xpacket_t *pack; - uint16_t pos = 0; - uint16_t nextpos; - int num = 1; - bool do_print; - unsigned long flags; + const uint16_t frm_len = XFRAME_LEN(xframe); + xpacket_t *pack; + uint16_t pos = 0; + uint16_t nextpos; + int num = 1; + bool do_print; + unsigned long flags; if (xframe->xframe_magic != XFRAME_MAGIC) { - XBUS_ERR(xbus, "%s: bad xframe_magic %lX\n", - __func__, xframe->xframe_magic); + XBUS_ERR(xbus, "%s: bad xframe_magic %lX\n", __func__, + xframe->xframe_magic); return; } spin_lock_irqsave(&serialize_dump_xframe, flags); do { if (pos >= xbus->transport.max_send_size) { if (printk_ratelimit()) { - XBUS_NOTICE(xbus, "%s: xframe overflow (%d bytes)\n", - msg, frm_len); + XBUS_NOTICE(xbus, + "%s: xframe overflow (%d bytes)\n", + msg, frm_len); do_hexdump(msg, xframe->packets, frm_len); } break; } if (pos > frm_len) { if (printk_ratelimit()) { - XBUS_NOTICE(xbus, "%s: packet overflow pos=%d frame_len=%d\n", - msg, pos, frm_len); + XBUS_NOTICE(xbus, + "%s: packet overflow pos=%d frame_len=%d\n", + msg, pos, frm_len); do_hexdump(msg, xframe->packets, frm_len); } break; @@ -296,8 +313,10 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, i pack = (xpacket_t *)&xframe->packets[pos]; if (XPACKET_LEN(pack) <= 0) { if (printk_ratelimit()) { - XBUS_NOTICE(xbus, "%s: xframe -- bad packet_len=%d pos=%d frame_len=%d\n", - msg, XPACKET_LEN(pack), pos, frm_len); + XBUS_NOTICE(xbus, + "%s: xframe -- bad packet_len=%d pos=%d frame_len=%d\n", + msg, XPACKET_LEN(pack), pos, + frm_len); do_hexdump(msg, xframe->packets, frm_len); } break; @@ -305,8 +324,9 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, i nextpos = pos + XPACKET_LEN(pack); if (nextpos > frm_len) { if (printk_ratelimit()) { - XBUS_NOTICE(xbus, "%s: packet overflow nextpos=%d frame_len=%d\n", - msg, nextpos, frm_len); + XBUS_NOTICE(xbus, + "%s: packet overflow nextpos=%d frame_len=%d\n", + msg, nextpos, frm_len); do_hexdump(msg, xframe->packets, frm_len); } break; @@ -314,11 +334,11 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, i do_print = 0; if (debug == DBG_ANY) do_print = 1; - else if (XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_READ) && - XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_WRITE)) + else if (XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_READ) + && XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_WRITE)) do_print = 1; else if (debug & DBG_PCM) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) do_print = 1; @@ -326,17 +346,15 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, i if (do_print) { if (num == 1) { XBUS_DBG(ANY, xbus, "%s: frame_len=%d. %s\n", - msg, frm_len, - (XPACKET_IS_PCM(pack)) - ? "(IS_PCM)" - : ""); + msg, frm_len, (XPACKET_IS_PCM(pack)) + ? "(IS_PCM)" : ""); } - XBUS_DBG(ANY, xbus, " %3d. DATALEN=%d pcm=%d slot=%d OP=0x%02X XPD-%d%d (pos=%d)\n", - num, XPACKET_LEN(pack), - XPACKET_IS_PCM(pack), XPACKET_PCMSLOT(pack), - XPACKET_OP(pack), - XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack), - pos); + XBUS_DBG(ANY, xbus, + " %3d. DATALEN=%d pcm=%d slot=%d OP=0x%02X XPD-%d%d (pos=%d)\n", + num, XPACKET_LEN(pack), XPACKET_IS_PCM(pack), + XPACKET_PCMSLOT(pack), XPACKET_OP(pack), + XPACKET_ADDR_UNIT(pack), + XPACKET_ADDR_SUBUNIT(pack), pos); dump_packet(" ", pack, debug); } num++; @@ -355,12 +373,13 @@ void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, i */ int send_pcm_frame(xbus_t *xbus, xframe_t *xframe) { - struct xbus_ops *ops; - int ret = -ENODEV; + struct xbus_ops *ops; + int ret = -ENODEV; BUG_ON(!xframe); if (!XBUS_IS(xbus, READY)) { - XBUS_ERR(xbus, "Dropped a pcm frame -- hardware is not ready.\n"); + XBUS_ERR(xbus, + "Dropped a pcm frame -- hardware is not ready.\n"); ret = -ENODEV; goto error; } @@ -379,14 +398,15 @@ error: static int really_send_cmd_frame(xbus_t *xbus, xframe_t *xframe) { - struct xbus_ops *ops; - int ret; + struct xbus_ops *ops; + int ret; BUG_ON(!xbus); BUG_ON(!xframe); BUG_ON(xframe->xframe_magic != XFRAME_MAGIC); if (!XBUS_FLAGS(xbus, CONNECTED)) { - XBUS_ERR(xbus, "Dropped command before sending -- hardware deactivated.\n"); + XBUS_ERR(xbus, + "Dropped command before sending -- hardware deactivated.\n"); dump_xframe("Dropped", xbus, xframe, DBG_ANY); FREE_SEND_XFRAME(xbus, xframe); return -ENODEV; @@ -406,9 +426,9 @@ static int really_send_cmd_frame(xbus_t *xbus, xframe_t *xframe) int xbus_command_queue_tick(xbus_t *xbus) { - xframe_t *frm; - int ret = 0; - int packno; + xframe_t *frm; + int ret = 0; + int packno; xbus->command_tick_counter++; xbus->usec_nosend -= 1000; /* That's our budget */ @@ -425,8 +445,8 @@ int xbus_command_queue_tick(xbus_t *xbus) ret = really_send_cmd_frame(xbus, frm); if (ret < 0) { XBUS_ERR(xbus, - "Failed to send from command_queue (ret=%d)\n", - ret); + "Failed to send from command_queue (ret=%d)\n", + ret); xbus_setstate(xbus, XBUS_STATE_FAIL); } } @@ -437,7 +457,7 @@ int xbus_command_queue_tick(xbus_t *xbus) static void xbus_command_queue_clean(xbus_t *xbus) { - xframe_t *frm; + xframe_t *frm; XBUS_DBG(DEVICES, xbus, "count=%d\n", xbus->command_queue.count); xframe_queue_disable(&xbus->command_queue, 1); @@ -448,11 +468,13 @@ static void xbus_command_queue_clean(xbus_t *xbus) static int xbus_command_queue_waitempty(xbus_t *xbus) { - int ret; + int ret; XBUS_DBG(DEVICES, xbus, "Waiting for command_queue to empty\n"); - ret = wait_event_interruptible(xbus->command_queue_empty, - xframe_queue_count(&xbus->command_queue) == 0); + ret = + wait_event_interruptible(xbus->command_queue_empty, + xframe_queue_count(&xbus->command_queue) == + 0); if (ret) { XBUS_ERR(xbus, "waiting for command_queue interrupted!!!\n"); } @@ -461,13 +483,13 @@ static int xbus_command_queue_waitempty(xbus_t *xbus) int send_cmd_frame(xbus_t *xbus, xframe_t *xframe) { - static int rate_limit; - int ret = 0; - + static int rate_limit; + int ret = 0; BUG_ON(xframe->xframe_magic != XFRAME_MAGIC); if (!XBUS_FLAGS(xbus, CONNECTED)) { - XBUS_ERR(xbus, "Dropped command before queueing -- hardware deactivated.\n"); + XBUS_ERR(xbus, + "Dropped command before queueing -- hardware deactivated.\n"); ret = -ENODEV; goto err; } @@ -476,8 +498,8 @@ int send_cmd_frame(xbus_t *xbus, xframe_t *xframe) if (!xframe_enqueue(&xbus->command_queue, xframe)) { if ((rate_limit++ % 1003) == 0) { XBUS_ERR(xbus, - "Dropped command xframe. Cannot enqueue (%d)\n", - rate_limit); + "Dropped command xframe. Cannot enqueue (%d)\n", + rate_limit); dump_xframe(__func__, xbus, xframe, DBG_ANY); } xbus_setstate(xbus, XBUS_STATE_FAIL); @@ -494,15 +516,17 @@ err: static void xframe_enqueue_recv(xbus_t *xbus, xframe_t *xframe) { - int cpu = smp_processor_id(); + int cpu = smp_processor_id(); BUG_ON(!xbus); xbus->cpu_rcv_intr[cpu]++; if (!xframe_enqueue(&xbus->receive_queue, xframe)) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) - XBUS_ERR(xbus, "Failed to enqueue for receive_tasklet (%d)\n", rate_limit); + XBUS_ERR(xbus, + "Failed to enqueue for receive_tasklet (%d)\n", + rate_limit); FREE_RECV_XFRAME(xbus, xframe); /* return to receive_pool */ return; } @@ -514,9 +538,9 @@ static void xframe_enqueue_recv(xbus_t *xbus, xframe_t *xframe) */ static void receive_tasklet_func(unsigned long data) { - xbus_t *xbus = (xbus_t *)data; - xframe_t *xframe = NULL; - int cpu = smp_processor_id(); + xbus_t *xbus = (xbus_t *)data; + xframe_t *xframe = NULL; + int cpu = smp_processor_id(); BUG_ON(!xbus); xbus->cpu_rcv_tasklet[cpu]++; @@ -539,14 +563,14 @@ void xbus_receive_xframe(xbus_t *xbus, xframe_t *xframe) } /*------------------------- Bus Management -------------------------*/ -xpd_t *xpd_of(const xbus_t *xbus, int xpd_num) +xpd_t *xpd_of(const xbus_t *xbus, int xpd_num) { if (!VALID_XPD_NUM(xpd_num)) return NULL; return xbus->xpds[xpd_num]; } -xpd_t *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit) +xpd_t *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit) { if (unit > MAX_UNIT || subunit > MAX_SUBUNIT) return NULL; @@ -555,8 +579,8 @@ xpd_t *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit) int xbus_xpd_bind(xbus_t *xbus, xpd_t *xpd, int unit, int subunit) { - unsigned int xpd_num; - unsigned long flags; + unsigned int xpd_num; + unsigned long flags; BUG_ON(!xbus); xpd_num = XPD_IDX(unit, subunit); @@ -567,10 +591,10 @@ int xbus_xpd_bind(xbus_t *xbus, xpd_t *xpd, int unit, int subunit) BUG(); } if (xbus->xpds[xpd_num] != NULL) { - xpd_t *other = xbus->xpds[xpd_num]; + xpd_t *other = xbus->xpds[xpd_num]; - XBUS_ERR(xbus, "xpd_num=%d is occupied by %p (%s)\n", - xpd_num, other, other->xpdname); + XBUS_ERR(xbus, "xpd_num=%d is occupied by %p (%s)\n", xpd_num, + other, other->xpdname); BUG(); } snprintf(xpd->xpdname, XPD_NAMELEN, "XPD-%1d%1d", unit, subunit); @@ -590,8 +614,8 @@ int xbus_xpd_bind(xbus_t *xbus, xpd_t *xpd, int unit, int subunit) int xbus_xpd_unbind(xbus_t *xbus, xpd_t *xpd) { - unsigned int xpd_num = xpd->xbus_idx; - unsigned long flags; + unsigned int xpd_num = xpd->xbus_idx; + unsigned long flags; XBUS_DBG(DEVICES, xbus, "XPD #%d\n", xpd_num); if (!VALID_XPD_NUM(xpd_num)) { @@ -599,14 +623,15 @@ int xbus_xpd_unbind(xbus_t *xbus, xpd_t *xpd) BUG(); } if (xbus->xpds[xpd_num] == NULL) { - XBUS_ERR(xbus, "%s: slot xpd_num=%d is empty\n", __func__, xpd_num); + XBUS_ERR(xbus, "%s: slot xpd_num=%d is empty\n", __func__, + xpd_num); BUG(); } if (xbus->xpds[xpd_num] != xpd) { - xpd_t *other = xbus->xpds[xpd_num]; + xpd_t *other = xbus->xpds[xpd_num]; XBUS_ERR(xbus, "%s: slot xpd_num=%d is occupied by %p (%s)\n", - __func__, xpd_num, other, other->xpdname); + __func__, xpd_num, other, other->xpdname); BUG(); } spin_lock_irqsave(&xbus->lock, flags); @@ -618,27 +643,22 @@ int xbus_xpd_unbind(xbus_t *xbus, xpd_t *xpd) return 0; } -static int new_card(xbus_t *xbus, - int unit, - __u8 type, - __u8 subtype, - __u8 numchips, - __u8 ports_per_chip, - __u8 ports, - __u8 port_dir) +static int new_card(xbus_t *xbus, int unit, __u8 type, __u8 subtype, + __u8 numchips, __u8 ports_per_chip, __u8 ports, + __u8 port_dir) { - const xproto_table_t *proto_table; - int i; - int subunits; - int ret = 0; - int remaining_ports; - const struct echoops *echoops; + const xproto_table_t *proto_table; + int i; + int subunits; + int ret = 0; + int remaining_ports; + const struct echoops *echoops; proto_table = xproto_get(type); if (!proto_table) { XBUS_NOTICE(xbus, - "CARD %d: missing protocol table for type %d. Ignored.\n", - unit, type); + "CARD %d: missing protocol table for type %d. Ignored.\n", + unit, type); return -EINVAL; } echoops = proto_table->echoops; @@ -646,65 +666,55 @@ static int new_card(xbus_t *xbus, XBUS_INFO(xbus, "Detected ECHO Canceler (%d)\n", unit); if (ECHOOPS(xbus)) { XBUS_NOTICE(xbus, - "CARD %d: tryies to define echoops (type %d) but we already have one. Ignored.\n", - unit, type); + "CARD %d: tryies to define echoops (type %d) but we already have one. Ignored.\n", + unit, type); return -EINVAL; } xbus->echo_state.echoops = echoops; xbus->echo_state.xpd_idx = XPD_IDX(unit, 0); } remaining_ports = ports; - subunits = (ports + proto_table->ports_per_subunit - 1) / - proto_table->ports_per_subunit; - XBUS_DBG(DEVICES, xbus, "CARD %d type=%d.%d ports=%d (%dx%d), %d subunits, port-dir=0x%02X\n", - unit, - type, - subtype, - ports, - numchips, - ports_per_chip, - subunits, - port_dir - ); + subunits = + (ports + proto_table->ports_per_subunit - + 1) / proto_table->ports_per_subunit; + XBUS_DBG(DEVICES, xbus, + "CARD %d type=%d.%d ports=%d (%dx%d), %d subunits, port-dir=0x%02X\n", + unit, type, subtype, ports, numchips, ports_per_chip, subunits, + port_dir); if (type == XPD_TYPE_PRI || type == XPD_TYPE_BRI) xbus->quirks.has_digital_span = 1; if (type == XPD_TYPE_FXO) xbus->quirks.has_fxo = 1; xbus->worker.num_units += subunits - 1; for (i = 0; i < subunits; i++) { - int subunit_ports = proto_table->ports_per_subunit; + int subunit_ports = proto_table->ports_per_subunit; if (subunit_ports > remaining_ports) subunit_ports = remaining_ports; remaining_ports -= proto_table->ports_per_subunit; if (subunit_ports <= 0) { XBUS_NOTICE(xbus, - "Subunit XPD=%d%d without ports (%d of %d)\n", - unit, - i, - subunit_ports, - ports); + "Subunit XPD=%d%d without ports (%d of %d)\n", + unit, i, subunit_ports, ports); ret = -ENODEV; goto out; } if (!XBUS_IS(xbus, RECVD_DESC)) { XBUS_NOTICE(xbus, - "Cannot create XPD=%d%d in state %s\n", - unit, - i, - xbus_statename(XBUS_STATE(xbus))); + "Cannot create XPD=%d%d in state %s\n", + unit, i, xbus_statename(XBUS_STATE(xbus))); ret = -ENODEV; goto out; } - XBUS_DBG(DEVICES, xbus, "Creating XPD=%d%d type=%d.%d (%d ports)\n", - unit, - i, - type, - subtype, subunit_ports); - ret = create_xpd(xbus, proto_table, unit, i, type, subtype, subunits, subunit_ports, port_dir); + XBUS_DBG(DEVICES, xbus, + "Creating XPD=%d%d type=%d.%d (%d ports)\n", unit, i, + type, subtype, subunit_ports); + ret = + create_xpd(xbus, proto_table, unit, i, type, subtype, + subunits, subunit_ports, port_dir); if (ret < 0) { - XBUS_ERR(xbus, "Creation of XPD=%d%d failed %d\n", - unit, i, ret); + XBUS_ERR(xbus, "Creation of XPD=%d%d failed %d\n", unit, + i, ret); goto out; } xbus->worker.num_units_initialized++; @@ -716,7 +726,7 @@ out: static void xbus_release_xpds(xbus_t *xbus) { - int i; + int i; XBUS_DBG(DEVICES, xbus, "[%s] Release XPDS\n", xbus->label); for (i = 0; i < MAX_XPDS; i++) { @@ -729,10 +739,10 @@ static void xbus_release_xpds(xbus_t *xbus) static int xbus_aquire_xpds(xbus_t *xbus) { - unsigned long flags; - int i; - int ret = 0; - xpd_t *xpd; + unsigned long flags; + int i; + int ret = 0; + xpd_t *xpd; XBUS_DBG(DEVICES, xbus, "[%s] Aquire XPDS\n", xbus->label); spin_lock_irqsave(&xbus->lock, flags); @@ -748,7 +758,7 @@ out: spin_unlock_irqrestore(&xbus->lock, flags); return ret; err: - for (--i ; i >= 0; i--) { + for (--i; i >= 0; i--) { xpd = xpd_of(xbus, i); if (xpd) put_xpd(__func__, xpd); @@ -759,7 +769,7 @@ err: static int xpd_initialize(xpd_t *xpd) { - int ret = -ENODEV; + int ret = -ENODEV; if (CALL_XMETHOD(card_init, xpd) < 0) { XPD_ERR(xpd, "Card Initialization failed\n"); @@ -796,7 +806,7 @@ static int xbus_echocancel(xbus_t *xbus, int on) if (!xpd || !IS_PHONEDEV(xpd)) continue; for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) { - int ret; + int ret; xpd = xpd_byaddr(xbus, unit, subunit); if (!xpd || !IS_PHONEDEV(xpd)) @@ -836,17 +846,16 @@ static void xbus_deactivate_xpds(xbus_t *xbus) static int xbus_initialize(xbus_t *xbus) { - int unit; - int subunit; - xpd_t *xpd; - struct timeval time_start; - struct timeval time_end; - unsigned long timediff; - int res = 0; + int unit; + int subunit; + xpd_t *xpd; + struct timeval time_start; + struct timeval time_end; + unsigned long timediff; + int res = 0; do_gettimeofday(&time_start); - XBUS_DBG(DEVICES, xbus, "refcount_xbus=%d\n", - refcount_xbus(xbus)); + XBUS_DBG(DEVICES, xbus, "refcount_xbus=%d\n", refcount_xbus(xbus)); if (xbus_aquire_xpds(xbus) < 0) /* Until end of initialization */ return -EBUSY; for (unit = 0; unit < MAX_UNIT; unit++) { @@ -855,25 +864,26 @@ static int xbus_initialize(xbus_t *xbus) continue; if (!XBUS_IS(xbus, RECVD_DESC)) { XBUS_NOTICE(xbus, - "Cannot initialize UNIT=%d in state %s\n", - unit, - xbus_statename(XBUS_STATE(xbus))); + "Cannot initialize UNIT=%d in state %s\n", + unit, xbus_statename(XBUS_STATE(xbus))); goto err; } if (run_initialize_registers(xpd) < 0) { - XBUS_ERR(xbus, "Register Initialization of card #%d failed\n", unit); + XBUS_ERR(xbus, + "Register Initialization of card #%d failed\n", + unit); goto err; } for (subunit = 0; subunit < MAX_SUBUNIT; subunit++) { - int ret; + int ret; xpd = xpd_byaddr(xbus, unit, subunit); if (!xpd) continue; if (!XBUS_IS(xbus, RECVD_DESC)) { XBUS_ERR(xbus, - "XPD-%d%d Not in 'RECVD_DESC' state\n", - unit, subunit); + "XPD-%d%d Not in 'RECVD_DESC' state\n", + unit, subunit); goto err; } ret = xpd_initialize(xpd); @@ -884,8 +894,9 @@ static int xbus_initialize(xbus_t *xbus) xbus_echocancel(xbus, 1); do_gettimeofday(&time_end); timediff = usec_diff(&time_end, &time_start); - timediff /= 1000*100; - XBUS_INFO(xbus, "Initialized in %ld.%1ld sec\n", timediff/10, timediff%10); + timediff /= 1000 * 100; + XBUS_INFO(xbus, "Initialized in %ld.%1ld sec\n", timediff / 10, + timediff % 10); out: xbus_release_xpds(xbus); /* Initialization done/failed */ return res; @@ -895,7 +906,7 @@ err: goto out; } -int xbus_is_registered(xbus_t *xbus) +int xbus_is_registered(xbus_t *xbus) { return xbus->ddev && xbus->ddev->dev.parent; } @@ -1000,7 +1011,8 @@ void xbus_unregister_dahdi_device(xbus_t *xbus) } if (xbus->ddev) { dahdi_unregister_device(xbus->ddev); - XBUS_NOTICE(xbus, "%s: finished dahdi_unregister_device()\n", __func__); + XBUS_NOTICE(xbus, "%s: finished dahdi_unregister_device()\n", + __func__); xbus_free_ddev(xbus); } for (i = 0; i < MAX_XPDS; i++) { @@ -1017,37 +1029,36 @@ void xbus_unregister_dahdi_device(xbus_t *xbus) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20) static void xbus_populate(struct work_struct *work) { - struct xbus_workqueue *worker = container_of(work, struct xbus_workqueue, xpds_init_work); + struct xbus_workqueue *worker = + container_of(work, struct xbus_workqueue, xpds_init_work); #else void xbus_populate(void *data) { - struct xbus_workqueue *worker = data; + struct xbus_workqueue *worker = data; #endif - xbus_t *xbus; - struct list_head *card; - struct list_head *next_card; - unsigned long flags; - int ret = 0; + xbus_t *xbus; + struct list_head *card; + struct list_head *next_card; + unsigned long flags; + int ret = 0; xbus = container_of(worker, xbus_t, worker); xbus = get_xbus(__func__, xbus->num); /* return in function end */ XBUS_DBG(DEVICES, xbus, "Entering %s\n", __func__); spin_lock_irqsave(&worker->worker_lock, flags); list_for_each_safe(card, next_card, &worker->card_list) { - struct card_desc_struct *card_desc = list_entry(card, struct card_desc_struct, card_list); + struct card_desc_struct *card_desc = + list_entry(card, struct card_desc_struct, card_list); list_del(card); BUG_ON(card_desc->magic != CARD_DESC_MAGIC); /* Release/Reacquire locks around blocking calls */ spin_unlock_irqrestore(&xbus->worker.worker_lock, flags); - ret = new_card(xbus, - card_desc->xpd_addr.unit, - card_desc->type, - card_desc->subtype, - card_desc->numchips, - card_desc->ports_per_chip, - card_desc->ports, - card_desc->port_dir); + ret = + new_card(xbus, card_desc->xpd_addr.unit, card_desc->type, + card_desc->subtype, card_desc->numchips, + card_desc->ports_per_chip, card_desc->ports, + card_desc->port_dir); spin_lock_irqsave(&xbus->worker.worker_lock, flags); KZFREE(card_desc); if (ret) @@ -1055,13 +1066,15 @@ void xbus_populate(void *data) } spin_unlock_irqrestore(&worker->worker_lock, flags); if (xbus_initialize(xbus) < 0) { - XBUS_NOTICE(xbus, "Initialization failed. Leave unused. refcount_xbus=%d\n", - refcount_xbus(xbus)); + XBUS_NOTICE(xbus, + "Initialization failed. Leave unused. refcount_xbus=%d\n", + refcount_xbus(xbus)); goto failed; } if (!xbus_setstate(xbus, XBUS_STATE_READY)) { - XBUS_NOTICE(xbus, "Illegal transition. Leave unused. refcount_xbus=%d\n", - refcount_xbus(xbus)); + XBUS_NOTICE(xbus, + "Illegal transition. Leave unused. refcount_xbus=%d\n", + refcount_xbus(xbus)); goto failed; } worker->xpds_init_done = 1; @@ -1088,7 +1101,7 @@ failed: int xbus_process_worker(xbus_t *xbus) { - struct xbus_workqueue *worker; + struct xbus_workqueue *worker; if (!xbus) { ERR("%s: xbus gone -- skip initialization\n", __func__); @@ -1096,7 +1109,8 @@ int xbus_process_worker(xbus_t *xbus) } worker = &xbus->worker; if (down_trylock(&worker->running_initialization)) { - ERR("%s: xbus is disconnected -- skip initialization\n", __func__); + ERR("%s: xbus is disconnected -- skip initialization\n", + __func__); return 0; } XBUS_DBG(DEVICES, xbus, "\n"); @@ -1118,23 +1132,24 @@ int xbus_process_worker(xbus_t *xbus) static void worker_reset(xbus_t *xbus) { - struct xbus_workqueue *worker; - struct list_head *card; - struct list_head *next_card; - unsigned long flags; - char *name; + struct xbus_workqueue *worker; + struct list_head *card; + struct list_head *next_card; + unsigned long flags; + char *name; BUG_ON(!xbus); worker = &xbus->worker; name = (xbus) ? xbus->busname : "detached"; DBG(DEVICES, "%s\n", name); if (!worker->xpds_init_done) { - NOTICE("%s: worker(%s)->xpds_init_done=%d\n", - __func__, name, worker->xpds_init_done); + NOTICE("%s: worker(%s)->xpds_init_done=%d\n", __func__, name, + worker->xpds_init_done); } spin_lock_irqsave(&worker->worker_lock, flags); list_for_each_safe(card, next_card, &worker->card_list) { - struct card_desc_struct *card_desc = list_entry(card, struct card_desc_struct, card_list); + struct card_desc_struct *card_desc = + list_entry(card, struct card_desc_struct, card_list); BUG_ON(card_desc->magic != CARD_DESC_MAGIC); list_del(card); @@ -1149,7 +1164,7 @@ static void worker_reset(xbus_t *xbus) static void worker_destroy(xbus_t *xbus) { - struct xbus_workqueue *worker; + struct xbus_workqueue *worker; BUG_ON(!xbus); worker = &xbus->worker; @@ -1170,7 +1185,7 @@ static void worker_destroy(xbus_t *xbus) static void worker_init(xbus_t *xbus) { - struct xbus_workqueue *worker; + struct xbus_workqueue *worker; BUG_ON(!xbus); XBUS_DBG(DEVICES, xbus, "\n"); @@ -1190,7 +1205,7 @@ static void worker_init(xbus_t *xbus) */ static int worker_run(xbus_t *xbus) { - struct xbus_workqueue *worker; + struct xbus_workqueue *worker; xbus = get_xbus(__func__, xbus->num); /* return in worker_destroy() */ BUG_ON(!xbus); @@ -1212,12 +1227,11 @@ err: bool xbus_setflags(xbus_t *xbus, int flagbit, bool on) { - unsigned long flags; + unsigned long flags; spin_lock_irqsave(&xbus->transport.state_lock, flags); - XBUS_DBG(DEVICES, xbus, "%s flag %d\n", - (on) ? "Set" : "Clear", - flagbit); + XBUS_DBG(DEVICES, xbus, "%s flag %d\n", (on) ? "Set" : "Clear", + flagbit); if (on) set_bit(flagbit, &(xbus->transport.transport_flags)); else @@ -1228,64 +1242,62 @@ bool xbus_setflags(xbus_t *xbus, int flagbit, bool on) bool xbus_setstate(xbus_t *xbus, enum xbus_state newstate) { - unsigned long flags; - bool ret = 0; - int state_flip = 0; + unsigned long flags; + bool ret = 0; + int state_flip = 0; spin_lock_irqsave(&xbus->transport.state_lock, flags); if (newstate == XBUS_STATE(xbus)) { XBUS_DBG(DEVICES, xbus, "stay at %s\n", - xbus_statename(newstate)); + xbus_statename(newstate)); goto out; } /* Sanity tests */ switch (newstate) { - case XBUS_STATE_START: + case XBUS_STATE_START: + goto bad_state; + case XBUS_STATE_IDLE: + if (!XBUS_IS(xbus, START) && !XBUS_IS(xbus, DEACTIVATED)) goto bad_state; - case XBUS_STATE_IDLE: - if (!XBUS_IS(xbus, START) && - !XBUS_IS(xbus, DEACTIVATED)) - goto bad_state; - break; - case XBUS_STATE_SENT_REQUEST: - if (!XBUS_IS(xbus, IDLE) && - !XBUS_IS(xbus, SENT_REQUEST)) - goto bad_state; - break; - case XBUS_STATE_RECVD_DESC: - if (!XBUS_IS(xbus, SENT_REQUEST)) - goto bad_state; - break; - case XBUS_STATE_READY: - if (!XBUS_IS(xbus, RECVD_DESC)) - goto bad_state; - state_flip = 1; /* We are good */ - break; - case XBUS_STATE_DEACTIVATING: - if (XBUS_IS(xbus, DEACTIVATING)) - goto bad_state; - if (XBUS_IS(xbus, DEACTIVATED)) - goto bad_state; - break; - case XBUS_STATE_DEACTIVATED: - if (!XBUS_IS(xbus, DEACTIVATING)) - goto bad_state; - break; - case XBUS_STATE_FAIL: - if (XBUS_IS(xbus, DEACTIVATING)) - goto bad_state; - if (XBUS_IS(xbus, DEACTIVATED)) - goto bad_state; - break; - default: - XBUS_NOTICE(xbus, "%s: unknown state %d\n", __func__, newstate); - goto out; + break; + case XBUS_STATE_SENT_REQUEST: + if (!XBUS_IS(xbus, IDLE) && !XBUS_IS(xbus, SENT_REQUEST)) + goto bad_state; + break; + case XBUS_STATE_RECVD_DESC: + if (!XBUS_IS(xbus, SENT_REQUEST)) + goto bad_state; + break; + case XBUS_STATE_READY: + if (!XBUS_IS(xbus, RECVD_DESC)) + goto bad_state; + state_flip = 1; /* We are good */ + break; + case XBUS_STATE_DEACTIVATING: + if (XBUS_IS(xbus, DEACTIVATING)) + goto bad_state; + if (XBUS_IS(xbus, DEACTIVATED)) + goto bad_state; + break; + case XBUS_STATE_DEACTIVATED: + if (!XBUS_IS(xbus, DEACTIVATING)) + goto bad_state; + break; + case XBUS_STATE_FAIL: + if (XBUS_IS(xbus, DEACTIVATING)) + goto bad_state; + if (XBUS_IS(xbus, DEACTIVATED)) + goto bad_state; + break; + default: + XBUS_NOTICE(xbus, "%s: unknown state %d\n", __func__, newstate); + goto out; } /* All good */ - XBUS_DBG(DEVICES, xbus, "%s -> %s\n", - xbus_statename(XBUS_STATE(xbus)), - xbus_statename(newstate)); - if (xbus->transport.xbus_state == XBUS_STATE_READY && newstate != XBUS_STATE_READY) + XBUS_DBG(DEVICES, xbus, "%s -> %s\n", xbus_statename(XBUS_STATE(xbus)), + xbus_statename(newstate)); + if (xbus->transport.xbus_state == XBUS_STATE_READY + && newstate != XBUS_STATE_READY) state_flip = -1; /* We became bad */ xbus->transport.xbus_state = newstate; ret = 1; @@ -1299,8 +1311,7 @@ out: return ret; bad_state: XBUS_NOTICE(xbus, "Bad state transition %s -> %s ignored.\n", - xbus_statename(XBUS_STATE(xbus)), - xbus_statename(newstate)); + xbus_statename(XBUS_STATE(xbus)), xbus_statename(newstate)); goto out; } @@ -1321,7 +1332,7 @@ int xbus_activate(xbus_t *xbus) int xbus_connect(xbus_t *xbus) { - struct xbus_ops *ops; + struct xbus_ops *ops; BUG_ON(!xbus); XBUS_DBG(DEVICES, xbus, "\n"); @@ -1374,16 +1385,16 @@ void xbus_disconnect(xbus_t *xbus) transport_destroy(xbus); worker_destroy(xbus); XBUS_DBG(DEVICES, xbus, "Deactivated refcount_xbus=%d\n", - refcount_xbus(xbus)); + refcount_xbus(xbus)); xbus_sysfs_transport_remove(xbus); /* Device-Model */ put_xbus(__func__, xbus); /* from xbus_new() [kref_init()] */ } static xbus_t *xbus_alloc(void) { - unsigned long flags; - xbus_t *xbus; - int i; + unsigned long flags; + xbus_t *xbus; + int i; xbus = KZALLOC(sizeof(xbus_t), GFP_KERNEL); if (!xbus) { @@ -1408,11 +1419,10 @@ out: return xbus; } - void xbus_free(xbus_t *xbus) { - unsigned long flags; - uint num; + unsigned long flags; + uint num; if (!xbus) return; @@ -1425,14 +1435,18 @@ void xbus_free(xbus_t *xbus) #ifdef CONFIG_PROC_FS if (xbus->proc_xbus_dir) { if (xbus->proc_xbus_summary) { - XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", PROC_XBUS_SUMMARY); - remove_proc_entry(PROC_XBUS_SUMMARY, xbus->proc_xbus_dir); + XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", + PROC_XBUS_SUMMARY); + remove_proc_entry(PROC_XBUS_SUMMARY, + xbus->proc_xbus_dir); xbus->proc_xbus_summary = NULL; } #ifdef PROTOCOL_DEBUG if (xbus->proc_xbus_command) { - XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", PROC_XBUS_COMMAND); - remove_proc_entry(PROC_XBUS_COMMAND, xbus->proc_xbus_dir); + XBUS_DBG(PROC, xbus, "Removing proc '%s'\n", + PROC_XBUS_COMMAND); + remove_proc_entry(PROC_XBUS_COMMAND, + xbus->proc_xbus_dir); xbus->proc_xbus_command = NULL; } #endif @@ -1448,10 +1462,11 @@ void xbus_free(xbus_t *xbus) KZFREE(xbus); } -xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv) +xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, + struct device *transport_device, void *priv) { - int err; - xbus_t *xbus = NULL; + int err; + xbus_t *xbus = NULL; BUG_ON(!ops); xbus = xbus_alloc(); @@ -1482,7 +1497,7 @@ xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, struct device *tran err = xbus_sysfs_transport_create(xbus); if (err) { XBUS_ERR(xbus, "SYSFS transport link creation failed: %d\n", - err); + err); goto nobus; } xbus_reset_counters(xbus); @@ -1494,20 +1509,23 @@ xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, struct device *tran err = -EIO; goto nobus; } - xbus->proc_xbus_summary = create_proc_read_entry(PROC_XBUS_SUMMARY, - 0444, xbus->proc_xbus_dir, - xbus_read_proc, - (void *)((unsigned long)(xbus->num))); + xbus->proc_xbus_summary = + create_proc_read_entry(PROC_XBUS_SUMMARY, 0444, xbus->proc_xbus_dir, + xbus_read_proc, + (void *)((unsigned long)(xbus->num))); if (!xbus->proc_xbus_summary) { - XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_XBUS_SUMMARY); + XBUS_ERR(xbus, "Failed to create proc file '%s'\n", + PROC_XBUS_SUMMARY); err = -EIO; goto nobus; } SET_PROC_DIRENTRY_OWNER(xbus->proc_xbus_summary); #ifdef PROTOCOL_DEBUG - xbus->proc_xbus_command = create_proc_entry(PROC_XBUS_COMMAND, 0200, xbus->proc_xbus_dir); + xbus->proc_xbus_command = + create_proc_entry(PROC_XBUS_COMMAND, 0200, xbus->proc_xbus_dir); if (!xbus->proc_xbus_command) { - XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_XBUS_COMMAND); + XBUS_ERR(xbus, "Failed to create proc file '%s'\n", + PROC_XBUS_COMMAND); err = -EIO; goto nobus; } @@ -1516,12 +1534,14 @@ xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, struct device *tran SET_PROC_DIRENTRY_OWNER(xbus->proc_xbus_command); #endif #endif - xframe_queue_init(&xbus->command_queue, 10, command_queue_length, "command_queue", xbus); + xframe_queue_init(&xbus->command_queue, 10, command_queue_length, + "command_queue", xbus); xframe_queue_init(&xbus->receive_queue, 10, 50, "receive_queue", xbus); xframe_queue_init(&xbus->send_pool, 10, 100, "send_pool", xbus); xframe_queue_init(&xbus->receive_pool, 10, 50, "receive_pool", xbus); xframe_queue_init(&xbus->pcm_tospan, 5, 10, "pcm_tospan", xbus); - tasklet_init(&xbus->receive_tasklet, receive_tasklet_func, (unsigned long)xbus); + tasklet_init(&xbus->receive_tasklet, receive_tasklet_func, + (unsigned long)xbus); /* * Create worker after /proc/XBUS-?? so the directory exists * before /proc/XBUS-??/waitfor_xpds tries to get created. @@ -1540,7 +1560,7 @@ nobus: void xbus_reset_counters(xbus_t *xbus) { - int i; + int i; XBUS_DBG(GENERAL, xbus, "Reseting counters\n"); for (i = 0; i < XBUS_COUNTER_MAX; i++) { @@ -1562,10 +1582,10 @@ static bool xpds_done(xbus_t *xbus) int waitfor_xpds(xbus_t *xbus, char *buf) { - struct xbus_workqueue *worker; - unsigned long flags; - int ret; - int len = 0; + struct xbus_workqueue *worker; + unsigned long flags; + int ret; + int len = 0; /* * FIXME: worker is created before ????? @@ -1587,14 +1607,14 @@ int waitfor_xpds(xbus_t *xbus, char *buf) goto out; } XBUS_DBG(DEVICES, xbus, - "Waiting for card init of %d XPD's max %d seconds (%p)\n", - worker->num_units, - INITIALIZATION_TIMEOUT/HZ, - &worker->wait_for_xpd_initialization); - ret = wait_event_interruptible_timeout( - worker->wait_for_xpd_initialization, - xpds_done(xbus), - INITIALIZATION_TIMEOUT); + "Waiting for card init of %d XPD's max %d seconds (%p)\n", + worker->num_units, INITIALIZATION_TIMEOUT / HZ, + &worker->wait_for_xpd_initialization); + ret = + wait_event_interruptible_timeout(worker-> + wait_for_xpd_initialization, + xpds_done(xbus), + INITIALIZATION_TIMEOUT); if (ret == 0) { XBUS_ERR(xbus, "Card Initialization Timeout\n"); len = -ETIMEDOUT; @@ -1605,16 +1625,16 @@ int waitfor_xpds(xbus_t *xbus, char *buf) goto out; } else XBUS_DBG(DEVICES, xbus, - "Finished initialization of %d XPD's in %d seconds.\n", - worker->num_units_initialized, - (INITIALIZATION_TIMEOUT - ret)/HZ); + "Finished initialization of %d XPD's in %d seconds.\n", + worker->num_units_initialized, + (INITIALIZATION_TIMEOUT - ret) / HZ); if (XBUS_IS(xbus, FAIL)) { len += sprintf(buf, "FAILED: %s\n", xbus->busname); } else { spin_lock_irqsave(&xbus->lock, flags); - len += sprintf(buf, "XPDS_READY: %s: %d/%d\n", - xbus->busname, - worker->num_units_initialized, worker->num_units); + len += + sprintf(buf, "XPDS_READY: %s: %d/%d\n", xbus->busname, + worker->num_units_initialized, worker->num_units); spin_unlock_irqrestore(&xbus->lock, flags); } out: @@ -1626,40 +1646,35 @@ out: static int xbus_fill_proc_queue(char *p, struct xframe_queue *q) { - int len; + int len; - len = sprintf(p, - "%-15s: counts %3d, %3d, %3d worst %3d, overflows %3d worst_lag %02ld.%ld ms\n", - q->name, - q->steady_state_count, - q->count, - q->max_count, - q->worst_count, - q->overflows, - q->worst_lag_usec / 1000, - q->worst_lag_usec % 1000); + len = + sprintf(p, + "%-15s: counts %3d, %3d, %3d worst %3d, overflows %3d worst_lag %02ld.%ld ms\n", + q->name, q->steady_state_count, q->count, q->max_count, + q->worst_count, q->overflows, q->worst_lag_usec / 1000, + q->worst_lag_usec % 1000); xframe_queue_clearstats(q); return len; } -static int xbus_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) +static int xbus_read_proc(char *page, char **start, off_t off, int count, + int *eof, void *data) { - xbus_t *xbus; - unsigned long flags; - int len = 0; - int i = (int)((unsigned long)data); + xbus_t *xbus; + unsigned long flags; + int len = 0; + int i = (int)((unsigned long)data); xbus = get_xbus(__func__, i); /* until end of xbus_read_proc */ if (!xbus) goto out; spin_lock_irqsave(&xbus->lock, flags); - len += sprintf(page + len, "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n", - xbus->busname, - xbus->connector, - xbus->label, - (XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing" - ); + len += + sprintf(page + len, "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n", + xbus->busname, xbus->connector, xbus->label, + (XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing"); len += xbus_fill_proc_queue(page + len, &xbus->send_pool); len += xbus_fill_proc_queue(page + len, &xbus->receive_pool); len += xbus_fill_proc_queue(page + len, &xbus->command_queue); @@ -1668,41 +1683,50 @@ static int xbus_read_proc(char *page, char **start, off_t off, int count, int *e if (rx_tasklet) { len += sprintf(page + len, "\ncpu_rcv_intr: "); for_each_online_cpu(i) - len += sprintf(page + len, "%5d ", xbus->cpu_rcv_intr[i]); + len += sprintf(page + len, "%5d ", xbus->cpu_rcv_intr[i]); len += sprintf(page + len, "\ncpu_rcv_tasklet: "); for_each_online_cpu(i) - len += sprintf(page + len, "%5d ", xbus->cpu_rcv_tasklet[i]); + len += + sprintf(page + len, "%5d ", xbus->cpu_rcv_tasklet[i]); len += sprintf(page + len, "\n"); } - len += sprintf(page + len, "self_ticking: %d (last_tick at %ld)\n", - xbus->self_ticking, xbus->ticker.last_sample.tv.tv_sec); - len += sprintf(page + len, "command_tick: %d\n", xbus->command_tick_counter); + len += + sprintf(page + len, "self_ticking: %d (last_tick at %ld)\n", + xbus->self_ticking, xbus->ticker.last_sample.tv.tv_sec); + len += + sprintf(page + len, "command_tick: %d\n", + xbus->command_tick_counter); len += sprintf(page + len, "usec_nosend: %d\n", xbus->usec_nosend); - len += sprintf(page + len, "xbus: pcm_rx_counter = %d, frag = %d\n", - atomic_read(&xbus->pcm_rx_counter), xbus->xbus_frag_count); - len += sprintf(page + len, "max_rx_process = %2ld.%ld ms\n", - xbus->max_rx_process / 1000, - xbus->max_rx_process % 1000); + len += + sprintf(page + len, "xbus: pcm_rx_counter = %d, frag = %d\n", + atomic_read(&xbus->pcm_rx_counter), xbus->xbus_frag_count); + len += + sprintf(page + len, "max_rx_process = %2ld.%ld ms\n", + xbus->max_rx_process / 1000, xbus->max_rx_process % 1000); xbus->max_rx_process = 0; - len += sprintf(page + len, "\nTRANSPORT: max_send_size=%d refcount=%d\n", - MAX_SEND_SIZE(xbus), - atomic_read(&xbus->transport.transport_refcount) - ); + len += + sprintf(page + len, "\nTRANSPORT: max_send_size=%d refcount=%d\n", + MAX_SEND_SIZE(xbus), + atomic_read(&xbus->transport.transport_refcount) + ); len += sprintf(page + len, "PCM Metrices:\n"); - len += sprintf(page + len, "\tPCM TX: min=%ld max=%ld\n", - xbus->min_tx_sync, xbus->max_tx_sync); - len += sprintf(page + len, "\tPCM RX: min=%ld max=%ld\n", - xbus->min_rx_sync, xbus->max_rx_sync); + len += + sprintf(page + len, "\tPCM TX: min=%ld max=%ld\n", + xbus->min_tx_sync, xbus->max_tx_sync); + len += + sprintf(page + len, "\tPCM RX: min=%ld max=%ld\n", + xbus->min_rx_sync, xbus->max_rx_sync); len += sprintf(page + len, "COUNTERS:\n"); for (i = 0; i < XBUS_COUNTER_MAX; i++) { - len += sprintf(page + len, "\t%-15s = %d\n", - xbus_counters[i].name, xbus->counters[i]); + len += + sprintf(page + len, "\t%-15s = %d\n", xbus_counters[i].name, + xbus->counters[i]); } len += sprintf(page + len, "<-- len=%d\n", len); spin_unlock_irqrestore(&xbus->lock, flags); put_xbus(__func__, xbus); /* from xbus_read_proc() */ out: - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1715,20 +1739,22 @@ out: } #ifdef PROTOCOL_DEBUG -static int proc_xbus_command_write(struct file *file, const char __user *buffer, unsigned long count, void *data) +static int proc_xbus_command_write(struct file *file, const char __user *buffer, + unsigned long count, void *data) { - char *buf; - xbus_t *xbus = data; - char *p; - __u8 *pack_start; - __u8 *q; - xframe_t *xframe; - size_t len; - const size_t max_len = xbus->transport.max_send_size; - const size_t max_text = max_len * 3 + 10; + char *buf; + xbus_t *xbus = data; + char *p; + __u8 *pack_start; + __u8 *q; + xframe_t *xframe; + size_t len; + const size_t max_len = xbus->transport.max_send_size; + const size_t max_text = max_len * 3 + 10; if (count > max_text) { - XBUS_ERR(xbus, "%s: line too long (%ld > %zd)\n", __func__, count, max_len); + XBUS_ERR(xbus, "%s: line too long (%ld > %zd)\n", __func__, + count, max_len); return -EFBIG; } /* 3 bytes per hex-digit and space */ @@ -1748,16 +1774,17 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer, */ q = pack_start = buf; for (p = buf; *p;) { - int val; - char hexdigit[3]; + int val; + char hexdigit[3]; while (*p && isspace(*p)) // skip whitespace p++; if (!(*p)) break; if (!isxdigit(*p)) { - XBUS_ERR(xbus, "%s: bad hex value ASCII='0x%X' at position %ld\n", - __func__, *p, (long)(p - buf)); + XBUS_ERR(xbus, + "%s: bad hex value ASCII='0x%X' at position %ld\n", + __func__, *p, (long)(p - buf)); count = -EINVAL; goto out; } @@ -1767,13 +1794,15 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer, if (isxdigit(*p)) hexdigit[1] = *p++; if (sscanf(hexdigit, "%2X", &val) != 1) { - XBUS_ERR(xbus, "%s: bad hex value '%s' at position %ld\n", - __func__, hexdigit, (long)(p - buf)); + XBUS_ERR(xbus, + "%s: bad hex value '%s' at position %ld\n", + __func__, hexdigit, (long)(p - buf)); count = -EINVAL; goto out; } *q++ = val; - XBUS_DBG(GENERAL, xbus, "%3zd> '%s' val=%d\n", q - pack_start, hexdigit, val); + XBUS_DBG(GENERAL, xbus, "%3zd> '%s' val=%d\n", q - pack_start, + hexdigit, val); } len = q - pack_start; xframe = ALLOC_SEND_XFRAME(xbus); @@ -1784,7 +1813,7 @@ static int proc_xbus_command_write(struct file *file, const char __user *buffer, if (len > max_len) len = max_len; atomic_set(&xframe->frame_len, len); - memcpy(xframe->packets, pack_start, len); /* FIXME: checksum? */ + memcpy(xframe->packets, pack_start, len); /* FIXME: checksum? */ dump_xframe("COMMAND", xbus, xframe, debug); send_cmd_frame(xbus, xframe); out: @@ -1793,8 +1822,8 @@ out: } #endif - -static int read_proc_xbuses(char *page, char **start, off_t off, int count, int *eof, void *data) +static int read_proc_xbuses(char *page, char **start, off_t off, int count, + int *eof, void *data) { int len = 0; int i; @@ -1803,19 +1832,19 @@ static int read_proc_xbuses(char *page, char **start, off_t off, int count, int xbus_t *xbus = get_xbus(__func__, i); if (xbus) { - len += sprintf(page + len, "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n", - xbus->busname, - xbus->connector, - xbus->label, - (XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing" - ); + len += + sprintf(page + len, + "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n", + xbus->busname, xbus->connector, xbus->label, + (XBUS_FLAGS(xbus, CONNECTED)) ? "connected" + : "missing"); put_xbus(__func__, xbus); } } #if 0 len += sprintf(page + len, "<-- len=%d\n", len); #endif - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1828,7 +1857,9 @@ static int read_proc_xbuses(char *page, char **start, off_t off, int count, int } #endif -static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv) +static void transport_init(xbus_t *xbus, struct xbus_ops *ops, + ushort max_send_size, + struct device *transport_device, void *priv) { BUG_ON(!xbus); BUG_ON(!ops); @@ -1850,22 +1881,25 @@ static void transport_init(xbus_t *xbus, struct xbus_ops *ops, ushort max_send_s static void transport_destroy(xbus_t *xbus) { - int ret; + int ret; BUG_ON(!xbus); XBUS_DBG(DEVICES, xbus, "Waiting... (transport_refcount=%d)\n", - atomic_read(&xbus->transport.transport_refcount)); - ret = wait_event_interruptible(xbus->transport.transport_unused, - atomic_read(&xbus->transport.transport_refcount) == 0); + atomic_read(&xbus->transport.transport_refcount)); + ret = + wait_event_interruptible(xbus->transport.transport_unused, + atomic_read(&xbus->transport. + transport_refcount) == 0); if (ret) - XBUS_ERR(xbus, "Waiting for transport_refcount interrupted!!!\n"); + XBUS_ERR(xbus, + "Waiting for transport_refcount interrupted!!!\n"); xbus->transport.ops = NULL; xbus->transport.priv = NULL; } struct xbus_ops *transportops_get(xbus_t *xbus) { - struct xbus_ops *ops; + struct xbus_ops *ops; BUG_ON(!xbus); atomic_inc(&xbus->transport.transport_refcount); @@ -1878,7 +1912,7 @@ struct xbus_ops *transportops_get(xbus_t *xbus) void transportops_put(xbus_t *xbus) { - struct xbus_ops *ops; + struct xbus_ops *ops; BUG_ON(!xbus); ops = xbus->transport.ops; @@ -1902,14 +1936,16 @@ static void xbus_core_cleanup(void) int __init xbus_core_init(void) { - int ret = 0; + int ret = 0; initialize_xbuses_array(); #ifdef PROTOCOL_DEBUG INFO("FEATURE: with PROTOCOL_DEBUG\n"); #endif #ifdef CONFIG_PROC_FS - proc_xbuses = create_proc_read_entry(PROC_XBUSES, 0444, xpp_proc_toplevel, read_proc_xbuses, NULL); + proc_xbuses = + create_proc_read_entry(PROC_XBUSES, 0444, xpp_proc_toplevel, + read_proc_xbuses, NULL); if (!proc_xbuses) { ERR("Failed to create proc file %s\n", PROC_XBUSES); ret = -EFAULT; @@ -1925,7 +1961,6 @@ err: return ret; } - void xbus_core_shutdown(void) { xbus_core_cleanup(); diff --git a/drivers/dahdi/xpp/xbus-core.h b/drivers/dahdi/xpp/xbus-core.h index 7a629cf..fc1b53d 100644 --- a/drivers/dahdi/xpp/xbus-core.h +++ b/drivers/dahdi/xpp/xbus-core.h @@ -39,10 +39,10 @@ struct xbus_workqueue; #ifdef __KERNEL__ struct xbus_ops { - int (*xframe_send_pcm)(xbus_t *xbus, xframe_t *xframe); - int (*xframe_send_cmd)(xbus_t *xbus, xframe_t *xframe); - xframe_t *(*alloc_xframe)(xbus_t *xbus, gfp_t gfp_flags); - void (*free_xframe)(xbus_t *xbus, xframe_t *xframe); + int (*xframe_send_pcm) (xbus_t *xbus, xframe_t *xframe); + int (*xframe_send_cmd) (xbus_t *xbus, xframe_t *xframe); + xframe_t *(*alloc_xframe) (xbus_t *xbus, gfp_t gfp_flags); + void (*free_xframe) (xbus_t *xbus, xframe_t *xframe); }; /* @@ -67,19 +67,11 @@ enum { /* yucky, make an instance so we can size it... */ static struct xbus_counters { - char *name; + char *name; } xbus_counters[] = { - C_(UNITS), - C_(TX_XFRAME_PCM), - C_(RX_XFRAME_PCM), - C_(TX_PACK_PCM), - C_(RX_PACK_PCM), - C_(TX_BYTES), - C_(RX_BYTES), - C_(TX_PCM_FRAG), - C_(RX_CMD), - C_(TX_CMD), -}; +C_(UNITS), C_(TX_XFRAME_PCM), C_(RX_XFRAME_PCM), C_(TX_PACK_PCM), + C_(RX_PACK_PCM), C_(TX_BYTES), C_(RX_BYTES), + C_(TX_PCM_FRAG), C_(RX_CMD), C_(TX_CMD),}; #undef C_ @@ -99,17 +91,17 @@ enum xbus_state { const char *xbus_statename(enum xbus_state st); struct xbus_transport { - struct xbus_ops *ops; - void *priv; - struct device *transport_device; - ushort max_send_size; - enum xbus_state xbus_state; - unsigned long transport_flags; - spinlock_t state_lock; - atomic_t transport_refcount; - wait_queue_head_t transport_unused; - spinlock_t lock; - char model_string[MAX_ENV_STR]; + struct xbus_ops *ops; + void *priv; + struct device *transport_device; + ushort max_send_size; + enum xbus_state xbus_state; + unsigned long transport_flags; + spinlock_t state_lock; + atomic_t transport_refcount; + wait_queue_head_t transport_unused; + spinlock_t lock; + char model_string[MAX_ENV_STR]; }; #define MAX_SEND_SIZE(xbus) ((xbus)->transport.max_send_size) @@ -127,15 +119,15 @@ void transportops_put(xbus_t *xbus); * Encapsulate all poll related data of a single xbus. */ struct xbus_workqueue { - struct workqueue_struct *wq; - struct work_struct xpds_init_work; - bool xpds_init_done; - struct list_head card_list; - int num_units; - int num_units_initialized; - wait_queue_head_t wait_for_xpd_initialization; - spinlock_t worker_lock; - struct semaphore running_initialization; + struct workqueue_struct *wq; + struct work_struct xpds_init_work; + bool xpds_init_done; + struct list_head card_list; + int num_units; + int num_units_initialized; + wait_queue_head_t wait_for_xpd_initialization; + spinlock_t worker_lock; + struct semaphore running_initialization; }; /* @@ -152,10 +144,10 @@ void put_xframe(struct xframe_queue *q, xframe_t *xframe); #define FREE_SEND_XFRAME(xbus, xframe) put_xframe(&(xbus)->send_pool, (xframe)) #define FREE_RECV_XFRAME(xbus, xframe) put_xframe(&(xbus)->receive_pool, (xframe)) -xbus_t *xbus_num(uint num); -xbus_t *get_xbus(const char *msg, uint num); -void put_xbus(const char *msg, xbus_t *xbus); -int refcount_xbus(xbus_t *xbus); +xbus_t *xbus_num(uint num); +xbus_t *get_xbus(const char *msg, uint num); +void put_xbus(const char *msg, xbus_t *xbus); +int refcount_xbus(xbus_t *xbus); /* * Echo canceller related data @@ -163,17 +155,17 @@ int refcount_xbus(xbus_t *xbus); #define ECHO_TIMESLOTS 128 struct echoops { - int (*ec_set)(xpd_t *xpd, int pos, bool on); - int (*ec_get)(xpd_t *xpd, int pos); - int (*ec_update)(xbus_t *xbus); - void (*ec_dump)(xbus_t *xbus); + int (*ec_set) (xpd_t *xpd, int pos, bool on); + int (*ec_get) (xpd_t *xpd, int pos); + int (*ec_update) (xbus_t *xbus); + void (*ec_dump) (xbus_t *xbus); }; struct xbus_echo_state { - const struct echoops *echoops; - __u8 timeslots[ECHO_TIMESLOTS]; - int xpd_idx; - struct device_attribute *da[MAX_XPDS]; + const struct echoops *echoops; + __u8 timeslots[ECHO_TIMESLOTS]; + int xpd_idx; + struct device_attribute *da[MAX_XPDS]; }; #define ECHOOPS(xbus) ((xbus)->echo_state.echoops) #define EC_METHOD(name, xbus) (ECHOOPS(xbus)->name) @@ -183,126 +175,128 @@ struct xbus_echo_state { * An xbus is a transport layer for Xorcom Protocol commands */ struct xbus { - char busname[XBUS_NAMELEN]; /* set by xbus_new() */ + char busname[XBUS_NAMELEN]; /* set by xbus_new() */ /* low-level bus drivers set these 2 fields */ - char connector[XBUS_DESCLEN]; - char label[LABEL_SIZE]; - __u8 revision; /* Protocol revision */ - struct xbus_transport transport; - struct dahdi_device *ddev; + char connector[XBUS_DESCLEN]; + char label[LABEL_SIZE]; + __u8 revision; /* Protocol revision */ + struct xbus_transport transport; + struct dahdi_device *ddev; - int num; - struct xpd *xpds[MAX_XPDS]; - struct xbus_echo_state echo_state; + int num; + struct xpd *xpds[MAX_XPDS]; + struct xbus_echo_state echo_state; - int command_tick_counter; - int usec_nosend; /* Firmware flow control */ - struct xframe_queue command_queue; - wait_queue_head_t command_queue_empty; + int command_tick_counter; + int usec_nosend; /* Firmware flow control */ + struct xframe_queue command_queue; + wait_queue_head_t command_queue_empty; - struct xframe_queue send_pool; /* empty xframes for send */ - struct xframe_queue receive_pool; /* empty xframes for receive */ + struct xframe_queue send_pool; /* empty xframes for send */ + struct xframe_queue receive_pool; /* empty xframes for receive */ /* tasklet processing */ - struct xframe_queue receive_queue; - struct tasklet_struct receive_tasklet; - int cpu_rcv_intr[NR_CPUS]; - int cpu_rcv_tasklet[NR_CPUS]; + struct xframe_queue receive_queue; + struct tasklet_struct receive_tasklet; + int cpu_rcv_intr[NR_CPUS]; + int cpu_rcv_tasklet[NR_CPUS]; struct quirks { unsigned int has_fxo:1; unsigned int has_digital_span:1; - } quirks; - bool self_ticking; - enum sync_mode sync_mode; + } quirks; + bool self_ticking; + enum sync_mode sync_mode; /* Managed by low-level drivers: */ - enum sync_mode sync_mode_default; - struct timer_list command_timer; - unsigned int xbus_frag_count; - struct xframe_queue pcm_tospan; + enum sync_mode sync_mode_default; + struct timer_list command_timer; + unsigned int xbus_frag_count; + struct xframe_queue pcm_tospan; - struct xpp_ticker ticker; /* for tick rate */ - struct xpp_drift drift; /* for tick offset */ + struct xpp_ticker ticker; /* for tick rate */ + struct xpp_drift drift; /* for tick offset */ - atomic_t pcm_rx_counter; - unsigned int global_counter; + atomic_t pcm_rx_counter; + unsigned int global_counter; /* Device-Model */ - struct device astribank; + struct device astribank; #define dev_to_xbus(dev) container_of(dev, struct xbus, astribank) - struct kref kref; + struct kref kref; #define kref_to_xbus(k) container_of(k, struct xbus, kref) - spinlock_t lock; + spinlock_t lock; /* PCM metrics */ - struct timeval last_tx_sync; - struct timeval last_rx_sync; - unsigned long max_tx_sync; - unsigned long min_tx_sync; - unsigned long max_rx_sync; - unsigned long min_rx_sync; - unsigned long max_rx_process; /* packet processing time (usec) */ + struct timeval last_tx_sync; + struct timeval last_rx_sync; + unsigned long max_tx_sync; + unsigned long min_tx_sync; + unsigned long max_rx_sync; + unsigned long min_rx_sync; + unsigned long max_rx_process; /* packet processing time (usec) */ #ifdef SAMPLE_TICKS #define SAMPLE_SIZE 1000 - int sample_ticks[SAMPLE_SIZE]; - bool sample_running; - int sample_pos; + int sample_ticks[SAMPLE_SIZE]; + bool sample_running; + int sample_pos; #endif - struct xbus_workqueue worker; + struct xbus_workqueue worker; /* * Sync adjustment */ - int sync_adjustment; - int sync_adjustment_offset; - long pll_updated_at; + int sync_adjustment; + int sync_adjustment_offset; + long pll_updated_at; - atomic_t num_xpds; + atomic_t num_xpds; #ifdef CONFIG_PROC_FS - struct proc_dir_entry *proc_xbus_dir; - struct proc_dir_entry *proc_xbus_summary; + struct proc_dir_entry *proc_xbus_dir; + struct proc_dir_entry *proc_xbus_summary; #ifdef PROTOCOL_DEBUG - struct proc_dir_entry *proc_xbus_command; + struct proc_dir_entry *proc_xbus_command; #endif #endif /* statistics */ - int counters[XBUS_COUNTER_MAX]; + int counters[XBUS_COUNTER_MAX]; }; #endif #define XFRAME_MAGIC 123456L struct xframe { - unsigned long xframe_magic; - struct list_head frame_list; - atomic_t frame_len; - xbus_t *xbus; - struct timeval tv_created; - struct timeval tv_queued; - struct timeval tv_submitted; - struct timeval tv_received; + unsigned long xframe_magic; + struct list_head frame_list; + atomic_t frame_len; + xbus_t *xbus; + struct timeval tv_created; + struct timeval tv_queued; + struct timeval tv_submitted; + struct timeval tv_received; /* filled by transport layer */ - size_t frame_maxlen; - __u8 *packets; /* max XFRAME_DATASIZE */ - __u8 *first_free; - int usec_towait; /* prevent overflowing AB */ - void *priv; + size_t frame_maxlen; + __u8 *packets; /* max XFRAME_DATASIZE */ + __u8 *first_free; + int usec_towait; /* prevent overflowing AB */ + void *priv; }; -void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize, void *priv); +void xframe_init(xbus_t *xbus, xframe_t *xframe, void *buf, size_t maxsize, + void *priv); #define XFRAME_LEN(frame) atomic_read(&(frame)->frame_len) -int xbus_core_init(void); /* Initializer */ -void xbus_core_shutdown(void); /* Terminator */ +int xbus_core_init(void); /* Initializer */ +void xbus_core_shutdown(void); /* Terminator */ /* Frame handling */ -void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, int debug); +void dump_xframe(const char msg[], const xbus_t *xbus, const xframe_t *xframe, + int debug); int send_cmd_frame(xbus_t *xbus, xframe_t *xframe); /* @@ -320,39 +314,40 @@ xpacket_t *xframe_next_packet(xframe_t *xframe, int len); #define XBUS_UNIT(idx) ((idx) / MAX_SUBUNIT) #define XBUS_SUBUNIT(idx) ((idx) % MAX_SUBUNIT) -xpd_t *xpd_of(const xbus_t *xbus, int xpd_num); -xpd_t *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit); -int xbus_check_unique(xbus_t *xbus); -bool xbus_setstate(xbus_t *xbus, enum xbus_state newstate); -bool xbus_setflags(xbus_t *xbus, int flagbit, bool on); -xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, struct device *transport_device, void *priv); -void xbus_free(xbus_t *xbus); -int xbus_connect(xbus_t *xbus); -int xbus_activate(xbus_t *xbus); -void xbus_deactivate(xbus_t *xbus); -void xbus_disconnect(xbus_t *xbus); -void xbus_receive_xframe(xbus_t *xbus, xframe_t *xframe); -int xbus_process_worker(xbus_t *xbus); -int waitfor_xpds(xbus_t *xbus, char *buf); +xpd_t *xpd_of(const xbus_t *xbus, int xpd_num); +xpd_t *xpd_byaddr(const xbus_t *xbus, uint unit, uint subunit); +int xbus_check_unique(xbus_t *xbus); +bool xbus_setstate(xbus_t *xbus, enum xbus_state newstate); +bool xbus_setflags(xbus_t *xbus, int flagbit, bool on); +xbus_t *xbus_new(struct xbus_ops *ops, ushort max_send_size, + struct device *transport_device, void *priv); +void xbus_free(xbus_t *xbus); +int xbus_connect(xbus_t *xbus); +int xbus_activate(xbus_t *xbus); +void xbus_deactivate(xbus_t *xbus); +void xbus_disconnect(xbus_t *xbus); +void xbus_receive_xframe(xbus_t *xbus, xframe_t *xframe); +int xbus_process_worker(xbus_t *xbus); +int waitfor_xpds(xbus_t *xbus, char *buf); -int xbus_xpd_bind(xbus_t *xbus, xpd_t *xpd, int unit, int subunit); -int xbus_xpd_unbind(xbus_t *xbus, xpd_t *xpd); +int xbus_xpd_bind(xbus_t *xbus, xpd_t *xpd, int unit, int subunit); +int xbus_xpd_unbind(xbus_t *xbus, xpd_t *xpd); /* sysfs */ -int xpd_device_register(xbus_t *xbus, xpd_t *xpd); -void xpd_device_unregister(xpd_t *xpd); -int echocancel_xpd(xpd_t *xpd, int on); +int xpd_device_register(xbus_t *xbus, xpd_t *xpd); +void xpd_device_unregister(xpd_t *xpd); +int echocancel_xpd(xpd_t *xpd, int on); -int xbus_is_registered(xbus_t *xbus); -int xbus_register_dahdi_device(xbus_t *xbus); -void xbus_unregister_dahdi_device(xbus_t *xbus); +int xbus_is_registered(xbus_t *xbus); +int xbus_register_dahdi_device(xbus_t *xbus); +void xbus_unregister_dahdi_device(xbus_t *xbus); -int xpp_driver_init(void); -void xpp_driver_exit(void); -int xbus_sysfs_transport_create(xbus_t *xbus); -void xbus_sysfs_transport_remove(xbus_t *xbus); -int xbus_sysfs_create(xbus_t *xbus); -void xbus_sysfs_remove(xbus_t *xbus); +int xpp_driver_init(void); +void xpp_driver_exit(void); +int xbus_sysfs_transport_create(xbus_t *xbus); +void xbus_sysfs_transport_remove(xbus_t *xbus); +int xbus_sysfs_create(xbus_t *xbus); +void xbus_sysfs_remove(xbus_t *xbus); #ifdef OLD_HOTPLUG_SUPPORT_269 /* Copy from new kernels lib/kobject_uevent.c */ @@ -367,7 +362,6 @@ enum kobject_action { }; #endif -void astribank_uevent_send(xbus_t *xbus, enum kobject_action act); - -#endif /* XBUS_CORE_H */ +void astribank_uevent_send(xbus_t *xbus, enum kobject_action act); +#endif /* XBUS_CORE_H */ diff --git a/drivers/dahdi/xpp/xbus-pcm.c b/drivers/dahdi/xpp/xbus-pcm.c index f597a47..2e24db4 100644 --- a/drivers/dahdi/xpp/xbus-pcm.c +++ b/drivers/dahdi/xpp/xbus-pcm.c @@ -22,7 +22,7 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #include @@ -37,29 +37,32 @@ static const char rcsid[] = "$Id$"; extern int debug; #ifdef OPTIMIZE_CHANMUTE -static DEF_PARM_BOOL(optimize_chanmute, 1, 0644, "Optimize by muting inactive channels"); +static DEF_PARM_BOOL(optimize_chanmute, 1, 0644, + "Optimize by muting inactive channels"); #endif static DEF_PARM(int, disable_pcm, 0, 0644, "Disable all PCM transmissions"); #ifdef DEBUG_PCMTX -DEF_PARM(int, pcmtx, -1, 0644, "Forced PCM value to transmit (negative to disable)"); +DEF_PARM(int, pcmtx, -1, 0644, + "Forced PCM value to transmit (negative to disable)"); DEF_PARM(int, pcmtx_chan, 0, 0644, "channel to force PCM value"); #endif -static DEF_PARM_BOOL(disable_pll_sync, 0, 0644, "Disable automatic adjustment of AB clocks"); +static DEF_PARM_BOOL(disable_pll_sync, 0, 0644, + "Disable automatic adjustment of AB clocks"); -static xbus_t *syncer; /* current syncer */ -static atomic_t xpp_tick_counter = ATOMIC_INIT(0); -static struct xpp_ticker dahdi_ticker; +static xbus_t *syncer; /* current syncer */ +static atomic_t xpp_tick_counter = ATOMIC_INIT(0); +static struct xpp_ticker dahdi_ticker; /* * The ref_ticker points to the current referece tick source. * I.e: one of our AB or dahdi_ticker */ -static struct xpp_ticker *ref_ticker; +static struct xpp_ticker *ref_ticker; static DEFINE_SPINLOCK(ref_ticker_lock); static DEFINE_SPINLOCK(elect_syncer_lock); -static bool force_dahdi_sync; /* from /sys/bus/astribanks/drivers/xppdrv/sync */ -static xbus_t *global_ticker; -static struct xpp_ticker global_ticks_series; +static bool force_dahdi_sync; /* from /sys/bus/astribanks/drivers/xppdrv/sync */ +static xbus_t *global_ticker; +static struct xpp_ticker global_ticks_series; #define PROC_SYNC "sync" #define SYNC_CYCLE 500 /* Sampling cycle in usec */ @@ -80,7 +83,7 @@ static struct xpp_ticker global_ticks_series; #define SYNC_ADJ_SLOW 10000 #ifdef DAHDI_SYNC_TICK -static unsigned int dahdi_tick_count; +static unsigned int dahdi_tick_count; #endif /*------------------------- SYNC Handling --------------------------*/ @@ -89,7 +92,7 @@ static void send_drift(xbus_t *xbus, int drift); static void ticker_set_cycle(struct xpp_ticker *ticker, int cycle) { - unsigned long flags; + unsigned long flags; spin_lock_irqsave(&ticker->lock, flags); if (cycle < SYNC_ADJ_QUICK) @@ -111,16 +114,16 @@ static void xpp_ticker_init(struct xpp_ticker *ticker) static int xpp_ticker_step(struct xpp_ticker *ticker, const struct timeval *t) { - unsigned long flags; - long usec; - bool cycled = 0; + unsigned long flags; + long usec; + bool cycled = 0; spin_lock_irqsave(&ticker->lock, flags); ticker->last_sample.tv = *t; if ((ticker->count % ticker->cycle) == ticker->cycle - 1) { /* rate adjust */ - usec = (long)usec_diff( - &ticker->last_sample.tv, - &ticker->first_sample.tv); + usec = + (long)usec_diff(&ticker->last_sample.tv, + &ticker->first_sample.tv); ticker->first_sample = ticker->last_sample; ticker->tick_period = usec / ticker->cycle; cycled = 1; @@ -137,12 +140,12 @@ static int xpp_ticker_step(struct xpp_ticker *ticker, const struct timeval *t) */ static inline void xbus_drift_clear(xbus_t *xbus) { - struct xpp_drift *di = &xbus->drift; + struct xpp_drift *di = &xbus->drift; do_gettimeofday(&di->last_lost_tick.tv); ticker_set_cycle(&xbus->ticker, SYNC_ADJ_QUICK); di->max_speed = -SYNC_ADJ_MAX; - di->min_speed = SYNC_ADJ_MAX; + di->min_speed = SYNC_ADJ_MAX; } void xpp_drift_init(xbus_t *xbus) @@ -184,9 +187,9 @@ static void sample_tick(xbus_t *xbus, int sample) */ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) { - struct xpp_drift *di = &xbus->drift; - struct xpp_ticker *ticker = &xbus->ticker; - unsigned long flags; + struct xpp_drift *di = &xbus->drift; + struct xpp_ticker *ticker = &xbus->ticker; + unsigned long flags; spin_lock_irqsave(&di->lock, flags); xpp_ticker_step(&xbus->ticker, tv); @@ -194,14 +197,15 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) * Do we need to be synchronized and is there an established reference * ticker (another Astribank or another DAHDI device) already? */ - if (ref_ticker && ref_ticker != &xbus->ticker && syncer && xbus->sync_mode == SYNC_MODE_PLL) { - int new_delta_tick = ticker->count - ref_ticker->count; - int lost_ticks = new_delta_tick - di->delta_tick; - long usec_delta; + if (ref_ticker && ref_ticker != &xbus->ticker && syncer + && xbus->sync_mode == SYNC_MODE_PLL) { + int new_delta_tick = ticker->count - ref_ticker->count; + int lost_ticks = new_delta_tick - di->delta_tick; + long usec_delta; di->delta_tick = new_delta_tick; if (lost_ticks) { - static int rate_limit; + static int rate_limit; /* * We just lost some ticks. Just report it and don't @@ -215,8 +219,8 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) * startup. */ XBUS_DBG(SYNC, xbus, "Lost %d tick%s\n", - lost_ticks, - (abs(lost_ticks) > 1) ? "s": ""); + lost_ticks, + (abs(lost_ticks) > 1) ? "s" : ""); } if (abs(lost_ticks) > 100) { xbus_drift_clear(xbus); @@ -224,24 +228,28 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) } } else { /* Sample a delta */ - usec_delta = (long)usec_diff( - &ticker->last_sample.tv, - &ref_ticker->last_sample.tv); + usec_delta = + (long)usec_diff(&ticker->last_sample.tv, + &ref_ticker->last_sample.tv); sample_tick(xbus, usec_delta); - if ((ticker->count % SYNC_CYCLE) > (SYNC_CYCLE - SYNC_CYCLE_SAMPLE)) - di->delta_sum += usec_delta; + if ((ticker->count % SYNC_CYCLE) > + (SYNC_CYCLE - SYNC_CYCLE_SAMPLE)) + di->delta_sum += usec_delta; if ((ticker->count % SYNC_CYCLE) == 0) { /* * Full sampling cycle passed. Let's calculate */ - int offset = di->delta_sum / SYNC_CYCLE_SAMPLE - SYNC_CENTER; - int offset_prev = di->offset_prev; - int speed = xbus->sync_adjustment; - int fix = 0; - int best_speed = (di->max_speed + di->min_speed) >> 1; + int offset = + di->delta_sum / SYNC_CYCLE_SAMPLE - + SYNC_CENTER; + int offset_prev = di->offset_prev; + int speed = xbus->sync_adjustment; + int fix = 0; + int best_speed = + (di->max_speed + di->min_speed) >> 1; - if (offset > 0 && offset < SYNC_DELTA) { + if (offset > 0 && offset < SYNC_DELTA) { speed = best_speed - 1; } else if (offset < 0 && offset > -SYNC_DELTA) { speed = best_speed + 1; @@ -258,26 +266,32 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) if (speed < -SYNC_ADJ_MAX) speed = -SYNC_ADJ_MAX; if (speed > SYNC_ADJ_MAX) - speed = SYNC_ADJ_MAX; + speed = SYNC_ADJ_MAX; if (speed < di->min_speed) - di->min_speed = speed; + di->min_speed = speed; if (speed > di->max_speed) - di->max_speed = speed; + di->max_speed = speed; if (offset > di->offset_max) di->offset_max = offset; if (offset < di->offset_min) di->offset_min = offset; - XBUS_DBG(SYNC, xbus, "offset: %d, min_speed=%d, max_speed=%d, usec_delta(last)=%ld\n", - offset_prev, di->min_speed, di->max_speed, usec_delta); - XBUS_DBG(SYNC, xbus, "ADJ: speed=%d (best_speed=%d) fix=%d\n", - speed, best_speed, fix); + XBUS_DBG(SYNC, xbus, + "offset: %d, min_speed=%d, max_speed=%d, usec_delta(last)=%ld\n", + offset_prev, di->min_speed, + di->max_speed, usec_delta); + XBUS_DBG(SYNC, xbus, + "ADJ: speed=%d (best_speed=%d) fix=%d\n", + speed, best_speed, fix); xbus->sync_adjustment_offset = speed; - if (xbus != syncer && xbus->sync_adjustment != speed) + if (xbus != syncer + && xbus->sync_adjustment != speed) send_drift(xbus, speed); - di->sync_inaccuracy = abs(offset) + abs(di->offset_range) / 2; + di->sync_inaccuracy = + abs(offset) + abs(di->offset_range) / 2; if (ticker->count >= SYNC_CYCLE * SYNC_CONVERGE) { - di->offset_range = di->offset_max - di->offset_min; + di->offset_range = + di->offset_max - di->offset_min; di->offset_min = INT_MAX; di->offset_max = -INT_MAX; if (di->max_speed > best_speed) @@ -286,7 +300,7 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) di->min_speed++; } di->offset_prev = offset; - di->delta_sum = 0; + di->delta_sum = 0; } } } @@ -295,11 +309,11 @@ static void xpp_drift_step(xbus_t *xbus, const struct timeval *tv) const char *sync_mode_name(enum sync_mode mode) { - static const char *sync_mode_names[] = { - [SYNC_MODE_AB] = "AB", - [SYNC_MODE_NONE] = "NONE", - [SYNC_MODE_PLL] = "PLL", - [SYNC_MODE_QUERY] = "QUERY", + static const char *sync_mode_names[] = { + [SYNC_MODE_AB] = "AB", + [SYNC_MODE_NONE] = "NONE", + [SYNC_MODE_PLL] = "PLL", + [SYNC_MODE_QUERY] = "QUERY", }; if (mode >= ARRAY_SIZE(sync_mode_names)) return NULL; @@ -311,7 +325,7 @@ const char *sync_mode_name(enum sync_mode mode) */ static void xpp_set_syncer(xbus_t *xbus, bool on) { - if (!xbus) { /* Special case, no more syncers */ + if (!xbus) { /* Special case, no more syncers */ DBG(SYNC, "No more syncers\n"); syncer = NULL; if (ref_ticker != &dahdi_ticker) @@ -328,14 +342,14 @@ static void xpp_set_syncer(xbus_t *xbus, bool on) ref_ticker = NULL; } else XBUS_DBG(SYNC, xbus, "ignore %s (current syncer: %s)\n", - (on)?"ON":"OFF", - (syncer) ? syncer->busname : "NO-SYNC"); + (on) ? "ON" : "OFF", + (syncer) ? syncer->busname : "NO-SYNC"); } static void xbus_command_timer(unsigned long param) { - xbus_t *xbus = (xbus_t *)param; - struct timeval now; + xbus_t *xbus = (xbus_t *)param; + struct timeval now; BUG_ON(!xbus); do_gettimeofday(&now); @@ -346,7 +360,7 @@ static void xbus_command_timer(unsigned long param) void xbus_set_command_timer(xbus_t *xbus, bool on) { - XBUS_DBG(SYNC, xbus, "%s\n", (on)?"ON":"OFF"); + XBUS_DBG(SYNC, xbus, "%s\n", (on) ? "ON" : "OFF"); if (on) { if (!timer_pending(&xbus->command_timer)) { XBUS_DBG(SYNC, xbus, "add_timer\n"); @@ -359,7 +373,7 @@ void xbus_set_command_timer(xbus_t *xbus, bool on) XBUS_DBG(SYNC, xbus, "del_timer\n"); del_timer(&xbus->command_timer); } - xbus->self_ticking = ! on; + xbus->self_ticking = !on; } /* @@ -367,19 +381,20 @@ void xbus_set_command_timer(xbus_t *xbus, bool on) */ void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift) { - unsigned long flags; - unsigned long flags2; + unsigned long flags; + unsigned long flags2; spin_lock_irqsave(&xbus->lock, flags); spin_lock_irqsave(&ref_ticker_lock, flags2); xbus->sync_adjustment = (signed char)drift; if (xbus->sync_mode == mode) { XBUS_DBG(SYNC, xbus, "Already in mode '%s'. Ignored\n", - sync_mode_name(mode)); + sync_mode_name(mode)); goto out; } XBUS_DBG(SYNC, xbus, "Mode %s (%d), drift=%d (pcm_rx_counter=%d)\n", - sync_mode_name(mode), mode, drift, atomic_read(&xbus->pcm_rx_counter)); + sync_mode_name(mode), mode, drift, + atomic_read(&xbus->pcm_rx_counter)); switch (mode) { case SYNC_MODE_AB: xbus->sync_mode = mode; @@ -393,12 +408,12 @@ void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift) xpp_set_syncer(xbus, 0); global_ticker = xbus; break; - case SYNC_MODE_NONE: /* lost sync source */ + case SYNC_MODE_NONE: /* lost sync source */ xbus->sync_mode = mode; xbus_set_command_timer(xbus, 1); xpp_set_syncer(xbus, 0); break; - case SYNC_MODE_QUERY: /* ignore */ + case SYNC_MODE_QUERY: /* ignore */ break; default: XBUS_ERR(xbus, "%s: unknown mode=0x%X\n", __func__, mode); @@ -410,7 +425,7 @@ out: void xbus_request_sync(xbus_t *xbus, enum sync_mode mode) { - unsigned long flags; + unsigned long flags; BUG_ON(!xbus); XBUS_DBG(SYNC, xbus, "sent request (mode=%d)\n", mode); @@ -436,11 +451,11 @@ void xbus_request_sync(xbus_t *xbus, enum sync_mode mode) static void reset_sync_counters(void) { - int i; + int i; //DBG(SYNC, "%d\n", atomic_read(&xpp_tick_counter)); for (i = 0; i < MAX_BUSES; i++) { - xbus_t *xbus = get_xbus(__func__, i); + xbus_t *xbus = get_xbus(__func__, i); if (xbus == NULL) continue; @@ -448,15 +463,16 @@ static void reset_sync_counters(void) * Don't send to non self_ticking Astribanks: * - Maybe they didn't finish initialization * - Or maybe they didn't answer us in the first place - (e.g: wrong firmware version, etc). + (e.g: wrong firmware version, etc). */ if (xbus->self_ticking) { if (!XBUS_FLAGS(xbus, CONNECTED)) { XBUS_DBG(GENERAL, xbus, - "Dropped packet. Is shutting down.\n"); + "Dropped packet. Is shutting down.\n"); } else { /* Reset sync LEDs once in a while */ - CALL_PROTO(GLOBAL, RESET_SYNC_COUNTERS, xbus, NULL); + CALL_PROTO(GLOBAL, RESET_SYNC_COUNTERS, xbus, + NULL); } } put_xbus(__func__, xbus); @@ -465,8 +481,8 @@ static void reset_sync_counters(void) static void send_drift(xbus_t *xbus, int drift) { - struct timeval now; - const char *msg; + struct timeval now; + const char *msg; BUG_ON(abs(drift) > SYNC_ADJ_MAX); do_gettimeofday(&now); @@ -474,17 +490,19 @@ static void send_drift(xbus_t *xbus, int drift) msg = "up"; else msg = "down"; - XBUS_DBG(SYNC, xbus, "%sDRIFT adjust %s (%d) (last update %ld seconds ago)\n", - (disable_pll_sync) ? "Fake " : "", - msg, drift, now.tv_sec - xbus->pll_updated_at); + XBUS_DBG(SYNC, xbus, + "%sDRIFT adjust %s (%d) (last update %ld seconds ago)\n", + (disable_pll_sync) ? "Fake " : "", msg, drift, + now.tv_sec - xbus->pll_updated_at); if (!disable_pll_sync) - CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_PLL, drift); + CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_PLL, + drift); xbus->pll_updated_at = now.tv_sec; } static void global_tick(void) { - struct timeval now; + struct timeval now; do_gettimeofday(&now); atomic_inc(&xpp_tick_counter); @@ -496,10 +514,10 @@ static void global_tick(void) #ifdef DAHDI_SYNC_TICK void dahdi_sync_tick(struct dahdi_span *span, int is_master) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - static int redundant_ticks; /* for extra spans */ - struct timeval now; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + static int redundant_ticks; /* for extra spans */ + struct timeval now; if (!force_dahdi_sync) goto noop; @@ -509,25 +527,26 @@ void dahdi_sync_tick(struct dahdi_span *span, int is_master) * Detect if any of our spans is dahdi sync master */ if (is_master) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 10003) == 0) - XPD_NOTICE(xpd, "Is a DAHDI sync master: ignore sync from DAHDI\n"); + XPD_NOTICE(xpd, + "Is a DAHDI sync master: ignore sync from DAHDI\n"); goto noop; } /* Now we know for sure someone else is dahdi sync master */ if (syncer) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 5003) == 0) XBUS_DBG(SYNC, syncer, - "is a SYNCer: ignore sync from DAHDI\n"); + "is a SYNCer: ignore sync from DAHDI\n"); goto noop; } /* ignore duplicate calls from all our registered spans */ if ((redundant_ticks++ % total_registered_spans()) != 0) { #if 0 - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) < 16) XPD_NOTICE(xpd, "boop (%d)\n", dahdi_tick_count); @@ -549,16 +568,15 @@ noop: */ static void update_sync_master(xbus_t *new_syncer, bool force_dahdi) { - const char *msg; - int i; - unsigned long flags; + const char *msg; + int i; + unsigned long flags; WARN_ON(new_syncer && force_dahdi); /* Ambigous */ force_dahdi_sync = force_dahdi; msg = (force_dahdi_sync) ? "DAHDI" : "NO-SYNC"; - DBG(SYNC, "%s => %s\n", - (syncer) ? syncer->busname : msg, - (new_syncer) ? new_syncer->busname : msg); + DBG(SYNC, "%s => %s\n", (syncer) ? syncer->busname : msg, + (new_syncer) ? new_syncer->busname : msg); /* * This global locking protects: * - The ref_ticker so it won't be used while we change it. @@ -575,7 +593,7 @@ static void update_sync_master(xbus_t *new_syncer, bool force_dahdi) xbus_drift_clear(syncer); /* Clean old data */ if (new_syncer) { XBUS_DBG(SYNC, new_syncer, "pcm_rx_counter=%d\n", - atomic_read(&new_syncer->pcm_rx_counter)); + atomic_read(&new_syncer->pcm_rx_counter)); force_dahdi_sync = 0; ref_ticker = &new_syncer->ticker; xbus_drift_clear(new_syncer); /* Clean new data */ @@ -590,15 +608,16 @@ static void update_sync_master(xbus_t *new_syncer, bool force_dahdi) DBG(SYNC, "stop unwanted syncers\n"); /* Shut all down except the wanted sync master */ for (i = 0; i < MAX_BUSES; i++) { - xbus_t *xbus = get_xbus(__func__, i); + xbus_t *xbus = get_xbus(__func__, i); if (xbus == NULL) continue; if (XBUS_FLAGS(xbus, CONNECTED) && xbus != new_syncer) { if (xbus->self_ticking) xbus_request_sync(xbus, - xbus->sync_mode_default); + xbus->sync_mode_default); else - XBUS_DBG(SYNC, xbus, "Not self_ticking yet. Ignore\n"); + XBUS_DBG(SYNC, xbus, + "Not self_ticking yet. Ignore\n"); } put_xbus(__func__, xbus); } @@ -606,18 +625,18 @@ static void update_sync_master(xbus_t *new_syncer, bool force_dahdi) void elect_syncer(const char *msg) { - int i; - int j; - uint timing_priority = INT_MAX; - xpd_t *best_xpd = NULL; - xbus_t *the_xbus = NULL; - unsigned long flags; + int i; + int j; + uint timing_priority = INT_MAX; + xpd_t *best_xpd = NULL; + xbus_t *the_xbus = NULL; + unsigned long flags; spin_lock_irqsave(&elect_syncer_lock, flags); DBG(SYNC, "%s: %s syncer=%s\n", __func__, msg, - (syncer) ? syncer->busname : "NULL"); + (syncer) ? syncer->busname : "NULL"); for (i = 0; i < MAX_BUSES; i++) { - xbus_t *xbus = get_xbus(__func__, i); + xbus_t *xbus = get_xbus(__func__, i); if (xbus == NULL) continue; @@ -625,15 +644,18 @@ void elect_syncer(const char *msg) if (!the_xbus) the_xbus = xbus; /* First candidate */ for (j = 0; j < MAX_XPDS; j++) { - xpd_t *xpd = xpd_of(xbus, j); - int prio; + xpd_t *xpd = xpd_of(xbus, j); + int prio; - if (!xpd || !xpd->card_present || !IS_PHONEDEV(xpd)) + if (!xpd || !xpd->card_present + || !IS_PHONEDEV(xpd)) continue; - prio = CALL_PHONE_METHOD(card_timing_priority, xpd); + prio = + CALL_PHONE_METHOD(card_timing_priority, + xpd); if (prio < 0) { DBG(SYNC, "%s/%s: skip sync\n", - xbus->busname, xpd->xpdname); + xbus->busname, xpd->xpdname); continue; } if (prio > 0 && prio < timing_priority) { @@ -646,11 +668,12 @@ void elect_syncer(const char *msg) } if (best_xpd) { the_xbus = best_xpd->xbus; - XPD_DBG(SYNC, best_xpd, "%s: elected with priority %d\n", msg, timing_priority); + XPD_DBG(SYNC, best_xpd, "%s: elected with priority %d\n", msg, + timing_priority); } else if (the_xbus) { XBUS_DBG(SYNC, the_xbus, "%s: elected\n", msg); } else { - unsigned long flags; + unsigned long flags; DBG(SYNC, "%s: No more syncers\n", msg); spin_lock_irqsave(&ref_ticker_lock, flags); @@ -681,10 +704,10 @@ void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len) */ void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask) { - int i; - int line_count = 0; - unsigned long flags; - uint pcm_len; + int i; + int line_count = 0; + unsigned long flags; + uint pcm_len; spin_lock_irqsave(&PHONEDEV(xpd).lock_recompute_pcm, flags); //XPD_DBG(SIGNAL, xpd, "pcm_mask=0x%X\n", pcm_mask); @@ -694,8 +717,8 @@ void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask) pcm_mask &= ~(PHONEDEV(xpd).digital_inputs); pcm_mask &= ~(PHONEDEV(xpd).digital_outputs); for_each_line(xpd, i) - if (IS_SET(pcm_mask, i)) - line_count++; + if (IS_SET(pcm_mask, i)) + line_count++; /* * FIXME: Workaround a bug in sync code of the Astribank. * Send dummy PCM for sync. @@ -705,17 +728,17 @@ void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask) line_count = 1; } pcm_len = (line_count) - ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + line_count * DAHDI_CHUNKSIZE - : 0L; + ? RPACKET_HEADERSIZE + sizeof(xpp_line_t) + + line_count * DAHDI_CHUNKSIZE : 0L; update_wanted_pcm_mask(xpd, pcm_mask, pcm_len); spin_unlock_irqrestore(&PHONEDEV(xpd).lock_recompute_pcm, flags); } void fill_beep(u_char *buf, int num, int duration) { - bool alternate = (duration) ? (jiffies/(duration*1000)) & 0x1 : 0; - int which; - u_char *snd; + bool alternate = (duration) ? (jiffies / (duration * 1000)) & 0x1 : 0; + int which; + u_char *snd; /* * debug tones @@ -739,18 +762,21 @@ void fill_beep(u_char *buf, int num, int duration) static void do_ec(xpd_t *xpd) { - int i; + int i; - for (i = 0;i < PHONEDEV(xpd).span.channels; i++) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); + for (i = 0; i < PHONEDEV(xpd).span.channels; i++) { + struct dahdi_chan *chan = XPD_CHAN(xpd, i); if (unlikely(IS_SET(PHONEDEV(xpd).digital_signalling, i))) /* Don't echo cancel BRI D-chans */ continue; - if (!IS_SET(PHONEDEV(xpd).wanted_pcm_mask, i)) /* No ec for unwanted PCM */ + if (!IS_SET(PHONEDEV(xpd).wanted_pcm_mask, i)) /* No ec for unwanted PCM */ continue; - dahdi_ec_chunk(chan, chan->readchunk, PHONEDEV(xpd).ec_chunk2[i]); - memcpy(PHONEDEV(xpd).ec_chunk2[i], PHONEDEV(xpd).ec_chunk1[i], DAHDI_CHUNKSIZE); - memcpy(PHONEDEV(xpd).ec_chunk1[i], chan->writechunk, DAHDI_CHUNKSIZE); + dahdi_ec_chunk(chan, chan->readchunk, + PHONEDEV(xpd).ec_chunk2[i]); + memcpy(PHONEDEV(xpd).ec_chunk2[i], PHONEDEV(xpd).ec_chunk1[i], + DAHDI_CHUNKSIZE); + memcpy(PHONEDEV(xpd).ec_chunk1[i], chan->writechunk, + DAHDI_CHUNKSIZE); } } @@ -762,26 +788,26 @@ static void do_ec(xpd_t *xpd) set the DAHDI_FLAG_RBS in this case. */ /* Opt: If the span uses A/B bits, set them here */ -int (*rbsbits)(struct dahdi_chan *chan, int bits); +int (*rbsbits) (struct dahdi_chan * chan, int bits); /* Option 2: If you don't know about sig bits, but do have their equivalents (i.e. you can disconnect battery, detect off hook, generate ring, etc directly) then you can just specify a sethook function, and we'll call you with appropriate hook states to set. Still set the DAHDI_FLAG_RBS in this case as well */ -int (*hooksig)(struct dahdi_chan *chan, enum dahdi_txsig hookstate); +int (*hooksig) (struct dahdi_chan * chan, enum dahdi_txsig hookstate); /* Option 3: If you can't use sig bits, you can write a function which handles the individual hook states */ -int (*sethook)(struct dahdi_chan *chan, int hookstate); +int (*sethook) (struct dahdi_chan * chan, int hookstate); #endif static bool pcm_valid(xpd_t *xpd, xpacket_t *pack) { - xpp_line_t lines = RPACKET_FIELD(pack, GLOBAL, PCM_READ, lines); - int i; - int count = 0; - uint16_t good_len; + xpp_line_t lines = RPACKET_FIELD(pack, GLOBAL, PCM_READ, lines); + int i; + int count = 0; + uint16_t good_len; BUG_ON(!pack); BUG_ON(XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_READ)); @@ -799,8 +825,9 @@ static bool pcm_valid(xpd_t *xpd, xpacket_t *pack) XPD_COUNTER(xpd, RECV_ERRORS)++; if ((rate_limit++ % 1000) <= 10) { - XPD_ERR(xpd, "BAD PCM REPLY: packet_len=%d (should be %d), count=%d\n", - XPACKET_LEN(pack), good_len, count); + XPD_ERR(xpd, + "BAD PCM REPLY: packet_len=%d (should be %d), count=%d\n", + XPACKET_LEN(pack), good_len, count); dump_packet("BAD PCM REPLY", pack, 1); } return 0; @@ -808,13 +835,11 @@ static bool pcm_valid(xpd_t *xpd, xpacket_t *pack) return 1; } - - static inline void pcm_frame_out(xbus_t *xbus, xframe_t *xframe) { - unsigned long flags; - struct timeval now; - unsigned long usec; + unsigned long flags; + struct timeval now; + unsigned long usec; spin_lock_irqsave(&xbus->lock, flags); do_gettimeofday(&now); @@ -824,13 +849,15 @@ static inline void pcm_frame_out(xbus_t *xbus, xframe_t *xframe) usec = usec_diff(&now, &xbus->last_tx_sync); xbus->last_tx_sync = now; /* ignore startup statistics */ - if (likely(atomic_read(&xbus->pcm_rx_counter) > BIG_TICK_INTERVAL)) { + if (likely + (atomic_read(&xbus->pcm_rx_counter) > BIG_TICK_INTERVAL)) { if (abs(usec - 1000) > TICK_TOLERANCE) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 5003) == 0) - XBUS_DBG(SYNC, xbus, "Bad PCM TX timing(%d): usec=%ld.\n", - rate_limit, usec); + XBUS_DBG(SYNC, xbus, + "Bad PCM TX timing(%d): usec=%ld.\n", + rate_limit, usec); } if (usec > xbus->max_tx_sync) xbus->max_tx_sync = usec; @@ -840,7 +867,7 @@ static inline void pcm_frame_out(xbus_t *xbus, xframe_t *xframe) } spin_unlock_irqrestore(&xbus->lock, flags); /* OK, really send it */ - if (debug & DBG_PCM ) + if (debug & DBG_PCM) dump_xframe("TX_XFRAME_PCM", xbus, xframe, debug); send_pcm_frame(xbus, xframe); XBUS_COUNTER(xbus, TX_XFRAME_PCM)++; @@ -856,10 +883,10 @@ dropit: */ void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) { - __u8 *pcm; - unsigned long flags; - xpp_line_t wanted_lines; - int i; + __u8 *pcm; + unsigned long flags; + xpp_line_t wanted_lines; + int i; BUG_ON(!xpd); BUG_ON(!pack); @@ -868,18 +895,20 @@ void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) pcm = RPACKET_FIELD(pack, GLOBAL, PCM_WRITE, pcm); spin_lock_irqsave(&xpd->lock, flags); for (i = 0; i < PHONEDEV(xpd).channels; i++) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); + struct dahdi_chan *chan = XPD_CHAN(xpd, i); if (IS_SET(wanted_lines, i)) { if (SPAN_REGISTERED(xpd)) { #ifdef DEBUG_PCMTX - int channo = chan->channo; + int channo = chan->channo; if (pcmtx >= 0 && pcmtx_chan == channo) - memset((u_char *)pcm, pcmtx, DAHDI_CHUNKSIZE); + memset((u_char *)pcm, pcmtx, + DAHDI_CHUNKSIZE); else #endif - memcpy((u_char *)pcm, chan->writechunk, DAHDI_CHUNKSIZE); + memcpy((u_char *)pcm, chan->writechunk, + DAHDI_CHUNKSIZE); } else memset((u_char *)pcm, 0x7F, DAHDI_CHUNKSIZE); pcm += DAHDI_CHUNKSIZE; @@ -891,11 +920,11 @@ void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack) void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) { - __u8 *pcm; - xpp_line_t pcm_mask; - xpp_line_t pcm_mute; - unsigned long flags; - int i; + __u8 *pcm; + xpp_line_t pcm_mask; + xpp_line_t pcm_mute; + unsigned long flags; + int i; pcm = RPACKET_FIELD(pack, GLOBAL, PCM_READ, pcm); pcm_mask = RPACKET_FIELD(pack, GLOBAL, PCM_READ, lines); @@ -908,14 +937,17 @@ void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) if (!SPAN_REGISTERED(xpd)) goto out; for (i = 0; i < PHONEDEV(xpd).channels; i++) { - volatile u_char *r = XPD_CHAN(xpd, i)->readchunk; - bool got_data = IS_SET(pcm_mask, i); + volatile u_char *r = XPD_CHAN(xpd, i)->readchunk; + bool got_data = IS_SET(pcm_mask, i); if (got_data && !IS_SET(pcm_mute, i)) { /* We have and want real data */ - // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE); // DEBUG + // memset((u_char *)r, 0x5A, DAHDI_CHUNKSIZE); // DEBUG memcpy((u_char *)r, pcm, DAHDI_CHUNKSIZE); - } else if (IS_SET(PHONEDEV(xpd).wanted_pcm_mask | PHONEDEV(xpd).silence_pcm, i)) { + } else + if (IS_SET + (PHONEDEV(xpd).wanted_pcm_mask | PHONEDEV(xpd). + silence_pcm, i)) { /* Inject SILENCE */ memset((u_char *)r, 0x7F, DAHDI_CHUNKSIZE); if (IS_SET(PHONEDEV(xpd).silence_pcm, i)) { @@ -923,8 +955,10 @@ void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack) * This will clear the EC buffers until next tick * So we don't have noise residues from the past. */ - memset(PHONEDEV(xpd).ec_chunk2[i], 0x7F, DAHDI_CHUNKSIZE); - memset(PHONEDEV(xpd).ec_chunk1[i], 0x7F, DAHDI_CHUNKSIZE); + memset(PHONEDEV(xpd).ec_chunk2[i], 0x7F, + DAHDI_CHUNKSIZE); + memset(PHONEDEV(xpd).ec_chunk1[i], 0x7F, + DAHDI_CHUNKSIZE); } } if (got_data) @@ -939,6 +973,7 @@ int generic_echocancel_timeslot(xpd_t *xpd, int pos) { return xpd->addr.unit * 32 + pos; } + EXPORT_SYMBOL(generic_echocancel_timeslot); int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) @@ -949,7 +984,7 @@ int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) XPD_DBG(GENERAL, xpd, "0x%8X\n", ec_mask); if (!ECHOOPS(xpd->xbus)) { XPD_DBG(GENERAL, xpd, - "No echo canceller in XBUS: Doing nothing.\n"); + "No echo canceller in XBUS: Doing nothing.\n"); return -EINVAL; } for (i = 0; i < PHONEDEV(xpd).channels; i++) { @@ -959,14 +994,15 @@ int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask) CALL_EC_METHOD(ec_update, xpd->xbus, xpd->xbus); return 0; } + EXPORT_SYMBOL(generic_echocancel_setmask); static int copy_pcm_tospan(xbus_t *xbus, xframe_t *xframe) { - __u8 *xframe_end; - xpacket_t *pack; - __u8 *p; - int ret = -EPROTO; /* Assume error */ + __u8 *xframe_end; + xpacket_t *pack; + __u8 *p; + int ret = -EPROTO; /* Assume error */ if (debug & DBG_PCM) dump_xframe("RX_XFRAME_PCM", xbus, xframe, debug); @@ -975,42 +1011,48 @@ static int copy_pcm_tospan(xbus_t *xbus, xframe_t *xframe) p = xframe->packets; xframe_end = p + XFRAME_LEN(xframe); do { - int len; - xpd_t *xpd; + int len; + xpd_t *xpd; pack = (xpacket_t *)p; len = XPACKET_LEN(pack); /* Sanity checks */ if (unlikely(XPACKET_OP(pack) != XPROTO_NAME(GLOBAL, PCM_READ))) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) { XBUS_NOTICE(xbus, - "%s: Non-PCM packet within a PCM xframe. (%d)\n", - __func__, rate_limit); - dump_xframe("In PCM xframe", xbus, xframe, debug); + "%s: Non-PCM packet within a PCM xframe. (%d)\n", + __func__, rate_limit); + dump_xframe("In PCM xframe", xbus, xframe, + debug); } goto out; } p += len; if (p > xframe_end || len < RPACKET_HEADERSIZE) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) { XBUS_NOTICE(xbus, - "%s: Invalid packet length %d. (%d)\n", - __func__, len, rate_limit); + "%s: Invalid packet length %d. (%d)\n", + __func__, len, rate_limit); dump_xframe("BAD LENGTH", xbus, xframe, debug); } goto out; } - xpd = xpd_byaddr(xbus, XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack)); + xpd = + xpd_byaddr(xbus, XPACKET_ADDR_UNIT(pack), + XPACKET_ADDR_SUBUNIT(pack)); if (unlikely(!xpd)) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) { - notify_bad_xpd(__func__, xbus, XPACKET_ADDR(pack), "RECEIVE PCM"); - dump_xframe("Unknown XPD addr", xbus, xframe, debug); + notify_bad_xpd(__func__, xbus, + XPACKET_ADDR(pack), + "RECEIVE PCM"); + dump_xframe("Unknown XPD addr", xbus, xframe, + debug); } goto out; } @@ -1021,7 +1063,7 @@ static int copy_pcm_tospan(xbus_t *xbus, xframe_t *xframe) CALL_PHONE_METHOD(card_pcm_tospan, xpd, pack); } } while (p < xframe_end); - ret = 0; /* all good */ + ret = 0; /* all good */ XBUS_COUNTER(xbus, RX_XFRAME_PCM)++; out: FREE_RECV_XFRAME(xbus, xframe); @@ -1035,11 +1077,11 @@ int generic_timing_priority(xpd_t *xpd) static void xbus_tick(xbus_t *xbus) { - int i; - xpd_t *xpd; - xframe_t *xframe = NULL; - xpacket_t *pack = NULL; - bool sent_sync_bit = 0; + int i; + xpd_t *xpd; + xframe_t *xframe = NULL; + xpacket_t *pack = NULL; + bool sent_sync_bit = 0; /* * Update dahdi @@ -1048,15 +1090,15 @@ static void xbus_tick(xbus_t *xbus) xpd = xpd_of(xbus, i); if (xpd && SPAN_REGISTERED(xpd)) { #ifdef OPTIMIZE_CHANMUTE - int j; - xpp_line_t xmit_mask = PHONEDEV(xpd).wanted_pcm_mask; + int j; + xpp_line_t xmit_mask = PHONEDEV(xpd).wanted_pcm_mask; xmit_mask |= PHONEDEV(xpd).silence_pcm; xmit_mask |= PHONEDEV(xpd).digital_signalling; for_each_line(xpd, j) { XPD_CHAN(xpd, j)->chanmute = (optimize_chanmute) - ? !IS_SET(xmit_mask, j) - : 0; + ? !IS_SET(xmit_mask, j) + : 0; } #endif /* @@ -1075,31 +1117,36 @@ static void xbus_tick(xbus_t *xbus) if (!IS_PHONEDEV(xpd)) continue; if (SPAN_REGISTERED(xpd)) { - size_t pcm_len = PHONEDEV(xpd).pcm_len; + size_t pcm_len = PHONEDEV(xpd).pcm_len; if (pcm_len && xpd->card_present) { do { - // pack = NULL; /* FORCE single packet frames */ + // pack = NULL; /* FORCE single packet frames */ if (xframe && !pack) { /* FULL frame */ pcm_frame_out(xbus, xframe); xframe = NULL; - XBUS_COUNTER(xbus, TX_PCM_FRAG)++; + XBUS_COUNTER(xbus, + TX_PCM_FRAG)++; } - if (!xframe) { /* Alloc frame */ - xframe = ALLOC_SEND_XFRAME(xbus); + if (!xframe) { /* Alloc frame */ + xframe = + ALLOC_SEND_XFRAME(xbus); if (!xframe) { static int rate_limit; - if ((rate_limit++ % 3001) == 0) + if ((rate_limit++ % + 3001) == 0) XBUS_ERR(xbus, - "%s: failed to allocate new xframe\n", - __func__); + "%s: failed to allocate new xframe\n", + __func__); return; } } - pack = xframe_next_packet(xframe, pcm_len); + pack = + xframe_next_packet(xframe, pcm_len); } while (!pack); - XPACKET_INIT(pack, GLOBAL, PCM_WRITE, xpd->xbus_idx, 1, 0); + XPACKET_INIT(pack, GLOBAL, PCM_WRITE, + xpd->xbus_idx, 1, 0); XPACKET_LEN(pack) = pcm_len; if (!sent_sync_bit) { XPACKET_ADDR_SYNC(pack) = 1; @@ -1110,7 +1157,7 @@ static void xbus_tick(xbus_t *xbus) } } } - if (xframe) /* clean any leftovers */ + if (xframe) /* clean any leftovers */ pcm_frame_out(xbus, xframe); /* * Receive PCM @@ -1118,20 +1165,23 @@ static void xbus_tick(xbus_t *xbus) while ((xframe = xframe_dequeue(&xbus->pcm_tospan)) != NULL) { copy_pcm_tospan(xbus, xframe); if (XPACKET_ADDR_SYNC((xpacket_t *)xframe->packets)) { - struct timeval now; - unsigned long usec; + struct timeval now; + unsigned long usec; do_gettimeofday(&now); usec = usec_diff(&now, &xbus->last_rx_sync); xbus->last_rx_sync = now; /* ignore startup statistics */ - if (likely(atomic_read(&xbus->pcm_rx_counter) > BIG_TICK_INTERVAL)) { + if (likely + (atomic_read(&xbus->pcm_rx_counter) > + BIG_TICK_INTERVAL)) { if (abs(usec - 1000) > TICK_TOLERANCE) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 5003) == 0) - XBUS_DBG(SYNC, xbus, "Bad PCM RX timing(%d): usec=%ld.\n", - rate_limit, usec); + XBUS_DBG(SYNC, xbus, + "Bad PCM RX timing(%d): usec=%ld.\n", + rate_limit, usec); } if (usec > xbus->max_rx_sync) xbus->max_rx_sync = usec; @@ -1162,8 +1212,8 @@ static void xbus_tick(xbus_t *xbus) static void do_tick(xbus_t *xbus, const struct timeval *tv_received) { - int counter = atomic_read(&xpp_tick_counter); - unsigned long flags; + int counter = atomic_read(&xpp_tick_counter); + unsigned long flags; xbus_command_queue_tick(xbus); if (global_ticker == xbus) @@ -1179,12 +1229,12 @@ static void do_tick(xbus_t *xbus, const struct timeval *tv_received) void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe) { if (!xframe_enqueue(&xbus->pcm_tospan, xframe)) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) XBUS_DBG(SYNC, xbus, - "Failed to enqueue received pcm frame. (%d)\n", - rate_limit); + "Failed to enqueue received pcm frame. (%d)\n", + rate_limit); FREE_RECV_XFRAME(xbus, xframe); } /* @@ -1201,9 +1251,9 @@ void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe) int exec_sync_command(const char *buf, size_t count) { - int ret = count; - int xbusno; - xbus_t *xbus; + int ret = count; + int xbusno; + xbus_t *xbus; if (strncmp("DAHDI", buf, 6) == 0) { /* Ignore the newline */ DBG(SYNC, "DAHDI"); @@ -1235,11 +1285,12 @@ int exec_sync_command(const char *buf, size_t count) int fill_sync_string(char *buf, size_t count) { - int len = 0; + int len = 0; if (!syncer) { - len += snprintf(buf, count, "%s\n", - (force_dahdi_sync) ? "DAHDI" : "NO-SYNC"); + len += + snprintf(buf, count, "%s\n", + (force_dahdi_sync) ? "DAHDI" : "NO-SYNC"); } else len += snprintf(buf, count, "SYNC=%02d\n", syncer->num); return len; @@ -1247,11 +1298,11 @@ int fill_sync_string(char *buf, size_t count) int xbus_pcm_init(void *toplevel) { - int ret = 0; + int ret = 0; #ifdef OPTIMIZE_CHANMUTE INFO("FEATURE: with CHANMUTE optimization (%sactivated)\n", - (optimize_chanmute)?"":"de"); + (optimize_chanmute) ? "" : "de"); #endif #ifdef DAHDI_SYNC_TICK INFO("FEATURE: with sync_tick() from DAHDI\n"); @@ -1267,7 +1318,6 @@ void xbus_pcm_shutdown(void) { } - EXPORT_SYMBOL(xbus_request_sync); EXPORT_SYMBOL(got_new_syncer); EXPORT_SYMBOL(elect_syncer); @@ -1283,4 +1333,3 @@ EXPORT_SYMBOL(generic_timing_priority); EXPORT_SYMBOL(pcmtx); EXPORT_SYMBOL(pcmtx_chan); #endif - diff --git a/drivers/dahdi/xpp/xbus-pcm.h b/drivers/dahdi/xpp/xbus-pcm.h index 4e00b80..e64ff06 100644 --- a/drivers/dahdi/xpp/xbus-pcm.h +++ b/drivers/dahdi/xpp/xbus-pcm.h @@ -33,10 +33,10 @@ #ifdef __KERNEL__ enum sync_mode { - SYNC_MODE_NONE = 0x00, - SYNC_MODE_AB = 0x01, /* Astribank sync */ - SYNC_MODE_PLL = 0x03, /* Adjust XPD's PLL according to HOST */ - SYNC_MODE_QUERY = 0x80, + SYNC_MODE_NONE = 0x00, + SYNC_MODE_AB = 0x01, /* Astribank sync */ + SYNC_MODE_PLL = 0x03, /* Adjust XPD's PLL according to HOST */ + SYNC_MODE_QUERY = 0x80, }; /* @@ -46,7 +46,7 @@ enum sync_mode { * time representations. */ struct xpp_timestamp { - struct timeval tv; + struct timeval tv; }; /* @@ -58,12 +58,12 @@ struct xpp_timestamp { * from other dahdi devices). */ struct xpp_ticker { /* for rate calculation */ - int count; - int cycle; - struct xpp_timestamp first_sample; - struct xpp_timestamp last_sample; - int tick_period; /* usec/tick */ - spinlock_t lock; + int count; + int cycle; + struct xpp_timestamp first_sample; + struct xpp_timestamp last_sample; + int tick_period; /* usec/tick */ + spinlock_t lock; }; /* @@ -71,66 +71,65 @@ struct xpp_ticker { /* for rate calculation */ * xbus ticker to a reference ticker. */ struct xpp_drift { - int delta_tick; /* from ref_ticker */ - int lost_ticks; /* occurances */ - int lost_tick_count; - int sync_inaccuracy; - struct xpp_timestamp last_lost_tick; - long delta_sum; - int offset_prev; - int offset_range; - int offset_min; - int offset_max; - int min_speed; - int max_speed; - spinlock_t lock; + int delta_tick; /* from ref_ticker */ + int lost_ticks; /* occurances */ + int lost_tick_count; + int sync_inaccuracy; + struct xpp_timestamp last_lost_tick; + long delta_sum; + int offset_prev; + int offset_range; + int offset_min; + int offset_max; + int min_speed; + int max_speed; + spinlock_t lock; }; void xpp_drift_init(xbus_t *xbus); -static inline long usec_diff(const struct timeval *tv1, const struct timeval *tv2) +static inline long usec_diff(const struct timeval *tv1, + const struct timeval *tv2) { - long diff_sec; - long diff_usec; + long diff_sec; + long diff_usec; diff_sec = tv1->tv_sec - tv2->tv_sec; diff_usec = tv1->tv_usec - tv2->tv_usec; return diff_sec * 1000000 + diff_usec; } - -int xbus_pcm_init(void *top); -void xbus_pcm_shutdown(void); -int send_pcm_frame(xbus_t *xbus, xframe_t *xframe); -void pcm_recompute(xpd_t *xpd, xpp_line_t tmp_pcm_mask); -void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe); -void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len); -void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask); -void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack); -void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack); -int generic_timing_priority(xpd_t *xpd); -int generic_echocancel_timeslot(xpd_t *xpd, int pos); -int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask); -void fill_beep(u_char *buf, int num, int duration); -const char *sync_mode_name(enum sync_mode mode); -void xbus_set_command_timer(xbus_t *xbus, bool on); -void xbus_request_sync(xbus_t *xbus, enum sync_mode mode); -void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift); -int xbus_command_queue_tick(xbus_t *xbus); -void xbus_reset_counters(xbus_t *xbus); -void elect_syncer(const char *msg); -int exec_sync_command(const char *buf, size_t count); -int fill_sync_string(char *buf, size_t count); +int xbus_pcm_init(void *top); +void xbus_pcm_shutdown(void); +int send_pcm_frame(xbus_t *xbus, xframe_t *xframe); +void pcm_recompute(xpd_t *xpd, xpp_line_t tmp_pcm_mask); +void xframe_receive_pcm(xbus_t *xbus, xframe_t *xframe); +void update_wanted_pcm_mask(xpd_t *xpd, xpp_line_t new_mask, uint new_pcm_len); +void generic_card_pcm_recompute(xpd_t *xpd, xpp_line_t pcm_mask); +void generic_card_pcm_fromspan(xpd_t *xpd, xpacket_t *pack); +void generic_card_pcm_tospan(xpd_t *xpd, xpacket_t *pack); +int generic_timing_priority(xpd_t *xpd); +int generic_echocancel_timeslot(xpd_t *xpd, int pos); +int generic_echocancel_setmask(xpd_t *xpd, xpp_line_t ec_mask); +void fill_beep(u_char *buf, int num, int duration); +const char *sync_mode_name(enum sync_mode mode); +void xbus_set_command_timer(xbus_t *xbus, bool on); +void xbus_request_sync(xbus_t *xbus, enum sync_mode mode); +void got_new_syncer(xbus_t *xbus, enum sync_mode mode, int drift); +int xbus_command_queue_tick(xbus_t *xbus); +void xbus_reset_counters(xbus_t *xbus); +void elect_syncer(const char *msg); +int exec_sync_command(const char *buf, size_t count); +int fill_sync_string(char *buf, size_t count); #ifdef DAHDI_SYNC_TICK -void dahdi_sync_tick(struct dahdi_span *span, int is_master); +void dahdi_sync_tick(struct dahdi_span *span, int is_master); #endif #ifdef DEBUG_PCMTX -extern int pcmtx; -extern int pcmtx_chan; +extern int pcmtx; +extern int pcmtx_chan; #endif -#endif /* __KERNEL__ */ - -#endif /* XBUS_PCM_H */ +#endif /* __KERNEL__ */ +#endif /* XBUS_PCM_H */ diff --git a/drivers/dahdi/xpp/xbus-sysfs.c b/drivers/dahdi/xpp/xbus-sysfs.c index 3071910..1af688f 100644 --- a/drivers/dahdi/xpp/xbus-sysfs.c +++ b/drivers/dahdi/xpp/xbus-sysfs.c @@ -22,7 +22,7 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #include @@ -52,7 +52,8 @@ static ssize_t sync_show(struct device_driver *driver, char *buf) return fill_sync_string(buf, PAGE_SIZE); } -static ssize_t sync_store(struct device_driver *driver, const char *buf, size_t count) +static ssize_t sync_store(struct device_driver *driver, const char *buf, + size_t count) { /* DBG(SYNC, "%s\n", buf); */ return exec_sync_command(buf, count); @@ -66,19 +67,18 @@ static struct driver_attribute xpp_attrs[] = { /*--------- Sysfs Bus handling ----*/ static DEVICE_ATTR_READER(xbus_state_show, dev, buf) { - xbus_t *xbus; - int ret; + xbus_t *xbus; + int ret; xbus = dev_to_xbus(dev); ret = XBUS_STATE(xbus); - ret = snprintf(buf, PAGE_SIZE, "%s (%d)\n", - xbus_statename(ret), ret); + ret = snprintf(buf, PAGE_SIZE, "%s (%d)\n", xbus_statename(ret), ret); return ret; } static DEVICE_ATTR_WRITER(xbus_state_store, dev, buf, count) { - xbus_t *xbus; + xbus_t *xbus; xbus = dev_to_xbus(dev); XBUS_DBG(GENERAL, xbus, "%s\n", buf); @@ -87,9 +87,9 @@ static DEVICE_ATTR_WRITER(xbus_state_store, dev, buf, count) else if (XBUS_IS(xbus, IDLE) && strncmp(buf, "start", 5) == 0) xbus_activate(xbus); else { - XBUS_NOTICE(xbus, "%s: Illegal action %s in state %s. Ignored.\n", - __func__, buf, - xbus_statename(XBUS_STATE(xbus))); + XBUS_NOTICE(xbus, + "%s: Illegal action %s in state %s. Ignored.\n", + __func__, buf, xbus_statename(XBUS_STATE(xbus))); return -EINVAL; } return count; @@ -97,34 +97,39 @@ static DEVICE_ATTR_WRITER(xbus_state_store, dev, buf, count) static DEVICE_ATTR_READER(status_show, dev, buf) { - xbus_t *xbus; - int ret; + xbus_t *xbus; + int ret; xbus = dev_to_xbus(dev); - ret = snprintf(buf, PAGE_SIZE, "%s\n", (XBUS_FLAGS(xbus, CONNECTED))?"connected":"missing"); + ret = + snprintf(buf, PAGE_SIZE, "%s\n", + (XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing"); return ret; } static DEVICE_ATTR_READER(timing_show, dev, buf) { - xbus_t *xbus; - struct xpp_drift *driftinfo; - int len = 0; - struct timeval now; + xbus_t *xbus; + struct xpp_drift *driftinfo; + int len = 0; + struct timeval now; do_gettimeofday(&now); xbus = dev_to_xbus(dev); driftinfo = &xbus->drift; - len += snprintf(buf + len, PAGE_SIZE - len, "%-3s", sync_mode_name(xbus->sync_mode)); + len += + snprintf(buf + len, PAGE_SIZE - len, "%-3s", + sync_mode_name(xbus->sync_mode)); if (xbus->sync_mode == SYNC_MODE_PLL) { - len += snprintf(buf + len, PAGE_SIZE - len, - " %5d: lost (%4d,%4d) : ", - xbus->ticker.cycle, - driftinfo->lost_ticks, driftinfo->lost_tick_count); - len += snprintf(buf + len, PAGE_SIZE - len, - "DRIFT %3d %ld sec ago", - xbus->sync_adjustment, - (xbus->pll_updated_at == 0) ? 0 : now.tv_sec - xbus->pll_updated_at); + len += + snprintf(buf + len, PAGE_SIZE - len, + " %5d: lost (%4d,%4d) : ", xbus->ticker.cycle, + driftinfo->lost_ticks, driftinfo->lost_tick_count); + len += + snprintf(buf + len, PAGE_SIZE - len, + "DRIFT %3d %ld sec ago", xbus->sync_adjustment, + (xbus->pll_updated_at == + 0) ? 0 : now.tv_sec - xbus->pll_updated_at); } len += snprintf(buf + len, PAGE_SIZE - len, "\n"); return len; @@ -141,9 +146,9 @@ static DEVICE_ATTR_READER(timing_show, dev, buf) */ static DEVICE_ATTR_READER(samples_show, dev, buf) { - xbus_t *xbus; - int len = 0; - int i; + xbus_t *xbus; + int len = 0; + int i; xbus = dev_to_xbus(dev); if (xbus->sample_running) @@ -151,14 +156,16 @@ static DEVICE_ATTR_READER(samples_show, dev, buf) for (i = 0; i < SAMPLE_SIZE; i++) { if (len > PAGE_SIZE - 20) break; - len += snprintf(buf + len, PAGE_SIZE - len, "%d\n", xbus->sample_ticks[i]); + len += + snprintf(buf + len, PAGE_SIZE - len, "%d\n", + xbus->sample_ticks[i]); } return len; } static DEVICE_ATTR_WRITER(samples_store, dev, buf, count) { - xbus_t *xbus; + xbus_t *xbus; xbus = dev_to_xbus(dev); if (xbus->sample_running) @@ -175,8 +182,8 @@ static DEVICE_ATTR_WRITER(samples_store, dev, buf, count) */ static DEVICE_ATTR_WRITER(cls_store, dev, buf, count) { - xbus_t *xbus; - struct xpp_drift *driftinfo; + xbus_t *xbus; + struct xpp_drift *driftinfo; xbus = dev_to_xbus(dev); driftinfo = &xbus->drift; @@ -194,8 +201,8 @@ static DEVICE_ATTR_WRITER(cls_store, dev, buf, count) static DEVICE_ATTR_READER(waitfor_xpds_show, dev, buf) { - xbus_t *xbus; - int len; + xbus_t *xbus; + int len; xbus = dev_to_xbus(dev); len = waitfor_xpds(xbus, buf); @@ -204,8 +211,8 @@ static DEVICE_ATTR_READER(waitfor_xpds_show, dev, buf) static DEVICE_ATTR_READER(refcount_xbus_show, dev, buf) { - xbus_t *xbus; - int len; + xbus_t *xbus; + int len; xbus = dev_to_xbus(dev); len = sprintf(buf, "%d\n", refcount_xbus(xbus)); @@ -214,17 +221,17 @@ static DEVICE_ATTR_READER(refcount_xbus_show, dev, buf) static DEVICE_ATTR_READER(driftinfo_show, dev, buf) { - xbus_t *xbus; - struct xpp_drift *di; - struct xpp_ticker *ticker; - struct timeval now; - int len = 0; - int hours; - int minutes; - int seconds; - int speed_range; - int uframes_inaccuracy; - int i; + xbus_t *xbus; + struct xpp_drift *di; + struct xpp_ticker *ticker; + struct timeval now; + int len = 0; + int hours; + int minutes; + int seconds; + int speed_range; + int uframes_inaccuracy; + int i; xbus = dev_to_xbus(dev); di = &xbus->drift; @@ -239,25 +246,38 @@ static DEVICE_ATTR_READER(driftinfo_show, dev, buf) hours = minutes / 60; minutes = minutes % 60; #define SHOW(ptr,item) len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", #item, (ptr)->item) - len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d (was %d:%02d:%02d ago)\n", - "lost_ticks", di->lost_ticks, hours, minutes, seconds); + len += + snprintf(buf + len, PAGE_SIZE - len, + "%-15s: %8d (was %d:%02d:%02d ago)\n", "lost_ticks", + di->lost_ticks, hours, minutes, seconds); speed_range = abs(di->max_speed - di->min_speed); uframes_inaccuracy = di->sync_inaccuracy / 125; - len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d ", - "instability", speed_range + uframes_inaccuracy); + len += + snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d ", "instability", + speed_range + uframes_inaccuracy); if (xbus->sync_mode == SYNC_MODE_AB) { buf[len++] = '-'; } else { - for (i = 0; len < PAGE_SIZE - 1 && i < speed_range + uframes_inaccuracy; i++) + for (i = 0; + len < PAGE_SIZE - 1 + && i < speed_range + uframes_inaccuracy; i++) buf[len++] = '#'; } buf[len++] = '\n'; - len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d (uframes)\n", "inaccuracy", uframes_inaccuracy); - len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", "speed_range", speed_range); + len += + snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d (uframes)\n", + "inaccuracy", uframes_inaccuracy); + len += + snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", "speed_range", + speed_range); SHOW(xbus, sync_adjustment); - len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", "offset (usec)", di->offset_prev); + len += + snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", + "offset (usec)", di->offset_prev); SHOW(di, offset_range); - len += snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", "best_speed", (di->max_speed + di->min_speed) / 2); + len += + snprintf(buf + len, PAGE_SIZE - len, "%-15s: %8d\n", "best_speed", + (di->max_speed + di->min_speed) / 2); SHOW(di, min_speed); SHOW(di, max_speed); SHOW(ticker, cycle); @@ -293,33 +313,34 @@ xbus_attr(connector, "%s\n"); xbus_attr(label, "%s\n"); static struct device_attribute xbus_dev_attrs[] = { - __ATTR_RO(connector), - __ATTR_RO(label), + __ATTR_RO(connector), + __ATTR_RO(label), __ATTR_RO(status), __ATTR_RO(timing), __ATTR_RO(refcount_xbus), __ATTR_RO(waitfor_xpds), __ATTR_RO(driftinfo), - __ATTR(cls, S_IWUSR, NULL, cls_store), - __ATTR(xbus_state, S_IRUGO | S_IWUSR, xbus_state_show, xbus_state_store), + __ATTR(cls, S_IWUSR, NULL, cls_store), + __ATTR(xbus_state, S_IRUGO | S_IWUSR, xbus_state_show, + xbus_state_store), #ifdef SAMPLE_TICKS - __ATTR(samples, S_IWUSR | S_IRUGO, samples_show, samples_store), + __ATTR(samples, S_IWUSR | S_IRUGO, samples_show, samples_store), #endif - __ATTR_NULL, + __ATTR_NULL, }; - static int astribank_match(struct device *dev, struct device_driver *driver) { DBG(DEVICES, "SYSFS MATCH: dev->bus_id = %s, driver->name = %s\n", - dev_name(dev), driver->name); + dev_name(dev), driver->name); return 1; } #ifdef OLD_HOTPLUG_SUPPORT -static int astribank_hotplug(struct device *dev, char **envp, int envnum, char *buff, int bufsize) +static int astribank_hotplug(struct device *dev, char **envp, int envnum, + char *buff, int bufsize) { - xbus_t *xbus; + xbus_t *xbus; if (!dev) return -ENODEV; @@ -349,12 +370,13 @@ static int astribank_hotplug(struct device *dev, char **envp, int envnum, char * return err; \ } while (0) -static int astribank_uevent(struct device *dev, char **envp, int num_envp, char *buffer, int buffer_size) +static int astribank_uevent(struct device *dev, char **envp, int num_envp, + char *buffer, int buffer_size) { - xbus_t *xbus; - int i = 0; - int len = 0; - extern char *initdir; + xbus_t *xbus; + int i = 0; + int len = 0; + extern char *initdir; if (!dev) return -ENODEV; @@ -375,8 +397,8 @@ static int astribank_uevent(struct device *dev, char **envp, int num_envp, char static int astribank_uevent(struct device *dev, struct kobj_uevent_env *kenv) { - xbus_t *xbus; - extern char *initdir; + xbus_t *xbus; + extern char *initdir; if (!dev) return -ENODEV; @@ -388,27 +410,27 @@ static int astribank_uevent(struct device *dev, struct kobj_uevent_env *kenv) #endif -#endif /* OLD_HOTPLUG_SUPPORT */ +#endif /* OLD_HOTPLUG_SUPPORT */ void astribank_uevent_send(xbus_t *xbus, enum kobject_action act) { - struct kobject *kobj; + struct kobject *kobj; kobj = &xbus->astribank.kobj; XBUS_DBG(DEVICES, xbus, "SYFS bus_id=%s action=%d\n", - dev_name(&xbus->astribank), act); + dev_name(&xbus->astribank), act); #if defined(OLD_HOTPLUG_SUPPORT_269) { /* Copy from new kernels lib/kobject_uevent.c */ - static const char *str[] = { - [KOBJ_ADD] "add", - [KOBJ_REMOVE] "remove", - [KOBJ_CHANGE] "change", - [KOBJ_MOUNT] "mount", - [KOBJ_UMOUNT] "umount", - [KOBJ_OFFLINE] "offline", - [KOBJ_ONLINE] "online" + static const char *str[] = { + [KOBJ_ADD] "add", + [KOBJ_REMOVE] "remove", + [KOBJ_CHANGE] "change", + [KOBJ_MOUNT] "mount", + [KOBJ_UMOUNT] "umount", + [KOBJ_OFFLINE] "offline", + [KOBJ_ONLINE] "online" }; kobject_hotplug(str[act], kobj); } @@ -421,7 +443,7 @@ void astribank_uevent_send(xbus_t *xbus, enum kobject_action act) static void astribank_release(struct device *dev) { - xbus_t *xbus; + xbus_t *xbus; BUG_ON(!dev); xbus = dev_to_xbus(dev); @@ -429,9 +451,10 @@ static void astribank_release(struct device *dev) XBUS_ERR(xbus, "Try to release CONNECTED device.\n"); BUG(); } - if (!XBUS_IS(xbus, IDLE) && !XBUS_IS(xbus, FAIL) && !XBUS_IS(xbus, DEACTIVATED)) { + if (!XBUS_IS(xbus, IDLE) && !XBUS_IS(xbus, FAIL) + && !XBUS_IS(xbus, DEACTIVATED)) { XBUS_ERR(xbus, "Try to release in state %s\n", - xbus_statename(XBUS_STATE(xbus))); + xbus_statename(XBUS_STATE(xbus))); BUG(); } XBUS_INFO(xbus, "[%s] Astribank Release\n", xbus->label); @@ -439,20 +462,20 @@ static void astribank_release(struct device *dev) } static struct bus_type toplevel_bus_type = { - .name = "astribanks", - .match = astribank_match, + .name = "astribanks", + .match = astribank_match, #ifdef OLD_HOTPLUG_SUPPORT - .hotplug = astribank_hotplug, + .hotplug = astribank_hotplug, #else - .uevent = astribank_uevent, + .uevent = astribank_uevent, #endif - .dev_attrs = xbus_dev_attrs, - .drv_attrs = xpp_attrs, + .dev_attrs = xbus_dev_attrs, + .drv_attrs = xpp_attrs, }; static int astribank_probe(struct device *dev) { - xbus_t *xbus; + xbus_t *xbus; xbus = dev_to_xbus(dev); XBUS_DBG(DEVICES, xbus, "SYSFS\n"); @@ -461,7 +484,7 @@ static int astribank_probe(struct device *dev) static int astribank_remove(struct device *dev) { - xbus_t *xbus; + xbus_t *xbus; xbus = dev_to_xbus(dev); XBUS_INFO(xbus, "[%s] Atribank Remove\n", xbus->label); @@ -469,12 +492,12 @@ static int astribank_remove(struct device *dev) } static struct device_driver xpp_driver = { - .name = "xppdrv", - .bus = &toplevel_bus_type, - .probe = astribank_probe, - .remove = astribank_remove, + .name = "xppdrv", + .bus = &toplevel_bus_type, + .probe = astribank_probe, + .remove = astribank_remove, #ifndef OLD_HOTPLUG_SUPPORT - .owner = THIS_MODULE + .owner = THIS_MODULE #endif }; @@ -482,12 +505,12 @@ static struct device_driver xpp_driver = { static DEVICE_ATTR_READER(chipregs_show, dev, buf) { - xpd_t *xpd; - unsigned long flags; - reg_cmd_t *regs; - bool do_datah; - char datah_str[50]; - int len = 0; + xpd_t *xpd; + unsigned long flags; + reg_cmd_t *regs; + bool do_datah; + char datah_str[50]; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -495,29 +518,34 @@ static DEVICE_ATTR_READER(chipregs_show, dev, buf) return -ENODEV; spin_lock_irqsave(&xpd->lock, flags); regs = &xpd->last_reply; - len += sprintf(buf + len, "# Writing bad data into this file may damage your hardware!\n"); + len += + sprintf(buf + len, + "# Writing bad data into this file may damage your hardware!\n"); len += sprintf(buf + len, "# Consult firmware docs first\n"); len += sprintf(buf + len, "#\n"); do_datah = REG_FIELD(regs, do_datah) ? 1 : 0; if (do_datah) { snprintf(datah_str, ARRAY_SIZE(datah_str), "\t%02X", - REG_FIELD(regs, data_high)); + REG_FIELD(regs, data_high)); } else datah_str[0] = '\0'; if (REG_FIELD(regs, do_subreg)) { - len += sprintf(buf + len, "#CH\tOP\tReg.\tSub\tDL%s\n", - (do_datah) ? "\tDH" : ""); - len += sprintf(buf + len, "%2d\tRS\t%02X\t%02X\t%02X%s\n", - regs->portnum, - REG_FIELD(regs, regnum), REG_FIELD(regs, subreg), - REG_FIELD(regs, data_low), datah_str); + len += + sprintf(buf + len, "#CH\tOP\tReg.\tSub\tDL%s\n", + (do_datah) ? "\tDH" : ""); + len += + sprintf(buf + len, "%2d\tRS\t%02X\t%02X\t%02X%s\n", + regs->portnum, REG_FIELD(regs, regnum), + REG_FIELD(regs, subreg), REG_FIELD(regs, data_low), + datah_str); } else { - len += sprintf(buf + len, "#CH\tOP\tReg.\tDL%s\n", - (do_datah) ? "\tDH" : ""); - len += sprintf(buf + len, "%2d\tRD\t%02X\t%02X%s\n", - regs->portnum, - REG_FIELD(regs, regnum), - REG_FIELD(regs, data_low), datah_str); + len += + sprintf(buf + len, "#CH\tOP\tReg.\tDL%s\n", + (do_datah) ? "\tDH" : ""); + len += + sprintf(buf + len, "%2d\tRD\t%02X\t%02X%s\n", regs->portnum, + REG_FIELD(regs, regnum), REG_FIELD(regs, data_low), + datah_str); } spin_unlock_irqrestore(&xpd->lock, flags); return len; @@ -525,11 +553,11 @@ static DEVICE_ATTR_READER(chipregs_show, dev, buf) static DEVICE_ATTR_WRITER(chipregs_store, dev, buf, count) { - xpd_t *xpd; - const char *p; - char tmp[MAX_PROC_WRITE]; - int i; - int ret; + xpd_t *xpd; + const char *p; + char tmp[MAX_PROC_WRITE]; + int i; + int ret; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -541,14 +569,17 @@ static DEVICE_ATTR_WRITER(chipregs_store, dev, buf, count) i = strcspn(p, "\r\n"); if (i > 0) { if (i >= MAX_PROC_WRITE) { - XPD_NOTICE(xpd, "Command too long (%d chars)\n", i); + XPD_NOTICE(xpd, "Command too long (%d chars)\n", + i); return -E2BIG; } memcpy(tmp, p, i); tmp[i] = '\0'; ret = parse_chip_command(xpd, tmp); if (ret < 0) { - XPD_NOTICE(xpd, "Failed writing command: '%s'\n", tmp); + XPD_NOTICE(xpd, + "Failed writing command: '%s'\n", + tmp); return ret; } } @@ -562,9 +593,9 @@ static DEVICE_ATTR_WRITER(chipregs_store, dev, buf, count) static DEVICE_ATTR_READER(blink_show, dev, buf) { - xpd_t *xpd; - unsigned long flags; - int len = 0; + xpd_t *xpd; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -578,9 +609,9 @@ static DEVICE_ATTR_READER(blink_show, dev, buf) static DEVICE_ATTR_WRITER(blink_store, dev, buf, count) { - xpd_t *xpd; - char *endp; - unsigned long blink; + xpd_t *xpd; + char *endp; + unsigned long blink; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -599,16 +630,18 @@ static DEVICE_ATTR_WRITER(blink_store, dev, buf, count) static DEVICE_ATTR_READER(span_show, dev, buf) { - xpd_t *xpd; - unsigned long flags; - int len = 0; + xpd_t *xpd; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); if (!xpd) return -ENODEV; spin_lock_irqsave(&xpd->lock, flags); - len += sprintf(buf, "%d\n", SPAN_REGISTERED(xpd) ? PHONEDEV(xpd).span.spanno : 0); + len += + sprintf(buf, "%d\n", + SPAN_REGISTERED(xpd) ? PHONEDEV(xpd).span.spanno : 0); spin_unlock_irqrestore(&xpd->lock, flags); return len; } @@ -619,9 +652,9 @@ static DEVICE_ATTR_READER(span_show, dev, buf) */ static DEVICE_ATTR_WRITER(span_store, dev, buf, count) { - xpd_t *xpd; - int dahdi_reg; - int ret; + xpd_t *xpd; + int dahdi_reg; + int ret; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -632,8 +665,7 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count) return -EINVAL; if (!XBUS_IS(xpd->xbus, READY)) return -ENODEV; - XPD_DBG(DEVICES, xpd, - "%s -- deprecated (should use pinned-spans)\n", + XPD_DBG(DEVICES, xpd, "%s -- deprecated (should use pinned-spans)\n", (dahdi_reg) ? "register" : "unregister"); if (xbus_is_registered(xpd->xbus)) { if (dahdi_reg) { @@ -657,8 +689,8 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count) static DEVICE_ATTR_READER(type_show, dev, buf) { - xpd_t *xpd; - int len = 0; + xpd_t *xpd; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -670,9 +702,9 @@ static DEVICE_ATTR_READER(type_show, dev, buf) static DEVICE_ATTR_READER(offhook_show, dev, buf) { - xpd_t *xpd; - int len = 0; - int i; + xpd_t *xpd; + int len = 0; + int i; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -682,7 +714,7 @@ static DEVICE_ATTR_READER(offhook_show, dev, buf) len += sprintf(buf + len, "%d ", IS_OFFHOOK(xpd, i)); } if (len) { - len--; /* backout last space */ + len--; /* backout last space */ } len += sprintf(buf + len, "\n"); return len; @@ -690,9 +722,9 @@ static DEVICE_ATTR_READER(offhook_show, dev, buf) static DEVICE_ATTR_READER(timing_priority_show, dev, buf) { - xpd_t *xpd; - unsigned long flags; - int len = 0; + xpd_t *xpd; + unsigned long flags; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -706,8 +738,8 @@ static DEVICE_ATTR_READER(timing_priority_show, dev, buf) static DEVICE_ATTR_READER(refcount_xpd_show, dev, buf) { - xpd_t *xpd; - int len = 0; + xpd_t *xpd; + int len = 0; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -719,47 +751,49 @@ static DEVICE_ATTR_READER(refcount_xpd_show, dev, buf) static int xpd_match(struct device *dev, struct device_driver *driver) { - struct xpd_driver *xpd_driver; - xpd_t *xpd; + struct xpd_driver *xpd_driver; + xpd_t *xpd; xpd_driver = driver_to_xpd_driver(driver); xpd = dev_to_xpd(dev); if (xpd_driver->type != xpd->type) { - XPD_DBG(DEVICES, xpd, "SYSFS match fail: xpd->type = %d, xpd_driver->type = %d\n", - xpd->type, xpd_driver->type); + XPD_DBG(DEVICES, xpd, + "SYSFS match fail: xpd->type = %d, xpd_driver->type = %d\n", + xpd->type, xpd_driver->type); return 0; } - XPD_DBG(DEVICES, xpd, "SYSFS MATCH: type=%d dev->bus_id = %s, driver->name = %s\n", + XPD_DBG(DEVICES, xpd, + "SYSFS MATCH: type=%d dev->bus_id = %s, driver->name = %s\n", xpd->type, dev_name(dev), driver->name); return 1; } static struct device_attribute xpd_dev_attrs[] = { - __ATTR(chipregs, S_IRUGO | S_IWUSR, chipregs_show, chipregs_store), - __ATTR(blink, S_IRUGO | S_IWUSR, blink_show, blink_store), - __ATTR(span, S_IRUGO | S_IWUSR, span_show, span_store), - __ATTR_RO(type), - __ATTR_RO(offhook), - __ATTR_RO(timing_priority), + __ATTR(chipregs, S_IRUGO | S_IWUSR, chipregs_show, chipregs_store), + __ATTR(blink, S_IRUGO | S_IWUSR, blink_show, blink_store), + __ATTR(span, S_IRUGO | S_IWUSR, span_show, span_store), + __ATTR_RO(type), + __ATTR_RO(offhook), + __ATTR_RO(timing_priority), __ATTR_RO(refcount_xpd), - __ATTR_NULL, + __ATTR_NULL, }; static struct bus_type xpd_type = { - .name = "xpds", - .match = xpd_match, - .dev_attrs = xpd_dev_attrs, + .name = "xpds", + .match = xpd_match, + .dev_attrs = xpd_dev_attrs, }; int xpd_driver_register(struct device_driver *driver) { - int ret; + int ret; DBG(DEVICES, "%s\n", driver->name); driver->bus = &xpd_type; if ((ret = driver_register(driver)) < 0) { - ERR("%s: driver_register(%s) failed. Error number %d", - __func__, driver->name, ret); + ERR("%s: driver_register(%s) failed. Error number %d", __func__, + driver->name, ret); } return ret; } @@ -772,7 +806,7 @@ void xpd_driver_unregister(struct device_driver *driver) static void xpd_release(struct device *dev) { - xpd_t *xpd; + xpd_t *xpd; BUG_ON(!dev); xpd = dev_to_xpd(dev); @@ -782,14 +816,14 @@ static void xpd_release(struct device *dev) int xpd_device_register(xbus_t *xbus, xpd_t *xpd) { - struct device *dev = &xpd->xpd_dev; - int ret; + struct device *dev = &xpd->xpd_dev; + int ret; XPD_DBG(DEVICES, xpd, "SYSFS\n"); dev->bus = &xpd_type; dev->parent = &xbus->astribank; dev_set_name(dev, "%02d:%1x:%1x", xbus->num, xpd->addr.unit, - xpd->addr.subunit); + xpd->addr.subunit); dev_set_drvdata(dev, xpd); dev->release = xpd_release; ret = device_register(dev); @@ -802,8 +836,8 @@ int xpd_device_register(xbus_t *xbus, xpd_t *xpd) void xpd_device_unregister(xpd_t *xpd) { - xbus_t *xbus; - struct device *dev; + xbus_t *xbus; + struct device *dev; xbus = xpd->xbus; BUG_ON(!xbus); @@ -890,8 +924,8 @@ static DEVICE_ATTR_WRITER(echocancel_store, dev, buf, count) return count; } -static DEVICE_ATTR(echocancel, S_IRUGO | S_IWUSR, echocancel_show, - echocancel_store); +static DEVICE_ATTR(echocancel, S_IRUGO | S_IWUSR, echocancel_show, + echocancel_store); int echocancel_xpd(xpd_t *xpd, int on) { @@ -905,19 +939,19 @@ int echocancel_xpd(xpd_t *xpd, int on) ret = device_create_file(&xpd->xpd_dev, &dev_attr_echocancel); if (ret) - XPD_ERR(xpd, - "%s: device_create_file(echocancel) failed: %d\n", + XPD_ERR(xpd, "%s: device_create_file(echocancel) failed: %d\n", __func__, ret); return ret; } + EXPORT_SYMBOL(echocancel_xpd); /*--------- Sysfs Device handling ----*/ void xbus_sysfs_transport_remove(xbus_t *xbus) { - struct device *astribank; + struct device *astribank; BUG_ON(!xbus); XBUS_DBG(DEVICES, xbus, "\n"); @@ -927,9 +961,9 @@ void xbus_sysfs_transport_remove(xbus_t *xbus) int xbus_sysfs_transport_create(xbus_t *xbus) { - struct device *astribank; - struct device *transport_device; - int ret = 0; + struct device *astribank; + struct device *transport_device; + int ret = 0; BUG_ON(!xbus); XBUS_DBG(DEVICES, xbus, "\n"); @@ -940,11 +974,12 @@ int xbus_sysfs_transport_create(xbus_t *xbus) XBUS_ERR(xbus, "%s: Missing transport_device\n", __func__); return -ENODEV; } - ret = sysfs_create_link(&astribank->kobj, &transport_device->kobj, - "transport"); + ret = + sysfs_create_link(&astribank->kobj, &transport_device->kobj, + "transport"); if (ret < 0) { - XBUS_ERR(xbus, "%s: sysfs_create_link failed: %d\n", - __func__, ret); + XBUS_ERR(xbus, "%s: sysfs_create_link failed: %d\n", __func__, + ret); dev_set_drvdata(astribank, NULL); } return ret; @@ -952,7 +987,7 @@ int xbus_sysfs_transport_create(xbus_t *xbus) void xbus_sysfs_remove(xbus_t *xbus) { - struct device *astribank; + struct device *astribank; BUG_ON(!xbus); XBUS_DBG(DEVICES, xbus, "\n"); @@ -966,8 +1001,8 @@ void xbus_sysfs_remove(xbus_t *xbus) int xbus_sysfs_create(xbus_t *xbus) { - struct device *astribank; - int ret = 0; + struct device *astribank; + int ret = 0; BUG_ON(!xbus); astribank = &xbus->astribank; @@ -979,7 +1014,8 @@ int xbus_sysfs_create(xbus_t *xbus) astribank->release = astribank_release; ret = device_register(astribank); if (ret) { - XBUS_ERR(xbus, "%s: device_register failed: %d\n", __func__, ret); + XBUS_ERR(xbus, "%s: device_register failed: %d\n", __func__, + ret); dev_set_drvdata(astribank, NULL); } return ret; @@ -987,22 +1023,22 @@ int xbus_sysfs_create(xbus_t *xbus) int __init xpp_driver_init(void) { - int ret; + int ret; DBG(DEVICES, "SYSFS\n"); if ((ret = bus_register(&toplevel_bus_type)) < 0) { - ERR("%s: bus_register(%s) failed. Error number %d", - __func__, toplevel_bus_type.name, ret); + ERR("%s: bus_register(%s) failed. Error number %d", __func__, + toplevel_bus_type.name, ret); goto failed_toplevel; } if ((ret = driver_register(&xpp_driver)) < 0) { - ERR("%s: driver_register(%s) failed. Error number %d", - __func__, xpp_driver.name, ret); + ERR("%s: driver_register(%s) failed. Error number %d", __func__, + xpp_driver.name, ret); goto failed_xpp_driver; } if ((ret = bus_register(&xpd_type)) < 0) { - ERR("%s: bus_register(%s) failed. Error number %d", - __func__, xpd_type.name, ret); + ERR("%s: bus_register(%s) failed. Error number %d", __func__, + xpd_type.name, ret); goto failed_xpd_bus; } return 0; diff --git a/drivers/dahdi/xpp/xdefs.h b/drivers/dahdi/xpp/xdefs.h index 715c2ff..04373f1 100644 --- a/drivers/dahdi/xpp/xdefs.h +++ b/drivers/dahdi/xpp/xdefs.h @@ -34,7 +34,7 @@ /* This is to enable user-space programs to include this. */ #include -typedef uint8_t __u8; +typedef uint8_t __u8; typedef uint32_t __u32; #include @@ -45,7 +45,10 @@ typedef uint32_t __u32; #define ERR(fmt, ...) printf("ERR: " fmt, ## __VA_ARGS__) #define __user -struct list_head { struct list_head *next; struct list_head *prev; }; +struct list_head { + struct list_head *next; + struct list_head *prev; +}; #endif @@ -53,7 +56,7 @@ struct list_head { struct list_head *next; struct list_head *prev; }; #define ALL_LINES ((lineno_t)-1) -#ifndef BIT /* added in 2.6.24 */ +#ifndef BIT /* added in 2.6.24 */ #define BIT(i) (1UL << (i)) #endif #define BIT_SET(x, i) ((x) |= BIT(i)) @@ -95,10 +98,10 @@ struct list_head { struct list_head *next; struct list_head *prev; }; #define VALID_XPD_NUM(x) ((x) < MAX_XPDS && (x) >= 0) -#define CHAN_BITS 5 /* 0-31 for E1 */ +#define CHAN_BITS 5 /* 0-31 for E1 */ -typedef char *charp; -typedef unsigned char byte; +typedef char *charp; +typedef unsigned char byte; #ifdef __KERNEL__ /* Kernel versions... */ @@ -121,7 +124,7 @@ typedef unsigned char byte; #define OLD_HOTPLUG_SUPPORT // for older kernels #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 10) -#define OLD_HOTPLUG_SUPPORT_269// for way older kernels +#define OLD_HOTPLUG_SUPPORT_269 // for way older kernels #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14) @@ -149,20 +152,20 @@ typedef unsigned char byte; * same linux-2.6-net-infrastructure-updates-to-mac80211-iwl4965.patch * as is the bool typedef. */ #if LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 18) || ! defined(hex_asc) -typedef int bool; +typedef int bool; #endif #endif #else -typedef int bool; +typedef int bool; #endif -typedef struct xbus xbus_t; -typedef struct xpd xpd_t; -typedef struct xframe xframe_t; -typedef struct xpacket xpacket_t; -typedef __u32 xpp_line_t; /* at most 31 lines for E1 */ -typedef byte lineno_t; -typedef byte xportno_t; +typedef struct xbus xbus_t; +typedef struct xpd xpd_t; +typedef struct xframe xframe_t; +typedef struct xpacket xpacket_t; +typedef __u32 xpp_line_t; /* at most 31 lines for E1 */ +typedef byte lineno_t; +typedef byte xportno_t; #define PORT_BROADCAST 255 -#endif /* XDEFS_H */ +#endif /* XDEFS_H */ diff --git a/drivers/dahdi/xpp/xframe_queue.c b/drivers/dahdi/xpp/xframe_queue.c index ac5398a..6ab82be 100644 --- a/drivers/dahdi/xpp/xframe_queue.c +++ b/drivers/dahdi/xpp/xframe_queue.c @@ -7,7 +7,8 @@ extern int debug; static xframe_t *transport_alloc_xframe(xbus_t *xbus, gfp_t gfp_flags); static void transport_free_xframe(xbus_t *xbus, xframe_t *xframe); -void xframe_queue_init(struct xframe_queue *q, unsigned int steady_state_count, unsigned int max_count, const char *name, void *priv) +void xframe_queue_init(struct xframe_queue *q, unsigned int steady_state_count, + unsigned int max_count, const char *name, void *priv) { memset(q, 0, sizeof(*q)); spin_lock_init(&q->lock); @@ -21,34 +22,33 @@ void xframe_queue_init(struct xframe_queue *q, unsigned int steady_state_count, void xframe_queue_clearstats(struct xframe_queue *q) { q->worst_count = 0; - //q->overflows = 0; /* Never clear overflows */ + //q->overflows = 0; /* Never clear overflows */ q->worst_lag_usec = 0L; } static void __xframe_dump_queue(struct xframe_queue *q) { - xframe_t *xframe; - int i = 0; - char prefix[30]; - struct timeval now; + xframe_t *xframe; + int i = 0; + char prefix[30]; + struct timeval now; do_gettimeofday(&now); printk(KERN_DEBUG "%s: dump queue '%s' (first packet in each frame)\n", - THIS_MODULE->name, - q->name); + THIS_MODULE->name, q->name); list_for_each_entry_reverse(xframe, &q->head, frame_list) { - xpacket_t *pack = (xpacket_t *)&xframe->packets[0]; - long usec = usec_diff(&now, &xframe->tv_queued); + xpacket_t *pack = (xpacket_t *)&xframe->packets[0]; + long usec = usec_diff(&now, &xframe->tv_queued); snprintf(prefix, ARRAY_SIZE(prefix), " %3d> %5ld.%03ld msec", - i++, usec / 1000, usec % 1000); + i++, usec / 1000, usec % 1000); dump_packet(prefix, pack, 1); } } static bool __xframe_enqueue(struct xframe_queue *q, xframe_t *xframe) { - int ret = 1; - static int overflow_cnt; + int ret = 1; + static int overflow_cnt; if (unlikely(q->disabled)) { ret = 0; @@ -57,15 +57,12 @@ static bool __xframe_enqueue(struct xframe_queue *q, xframe_t *xframe) if (q->count >= q->max_count) { q->overflows++; if ((overflow_cnt++ % 1000) < 5) { - NOTICE("Overflow of %-15s: counts %3d, %3d, %3d worst %3d, overflows %3d worst_lag %02ld.%ld ms\n", - q->name, - q->steady_state_count, - q->count, - q->max_count, - q->worst_count, - q->overflows, - q->worst_lag_usec / 1000, - q->worst_lag_usec % 1000); + NOTICE + ("Overflow of %-15s: counts %3d, %3d, %3d worst %3d, overflows %3d worst_lag %02ld.%ld ms\n", + q->name, q->steady_state_count, q->count, + q->max_count, q->worst_count, q->overflows, + q->worst_lag_usec / 1000, + q->worst_lag_usec % 1000); __xframe_dump_queue(q); } ret = 0; @@ -81,8 +78,8 @@ out: bool xframe_enqueue(struct xframe_queue *q, xframe_t *xframe) { - unsigned long flags; - int ret; + unsigned long flags; + int ret; spin_lock_irqsave(&q->lock, flags); ret = __xframe_enqueue(q, xframe); @@ -92,10 +89,10 @@ bool xframe_enqueue(struct xframe_queue *q, xframe_t *xframe) static xframe_t *__xframe_dequeue(struct xframe_queue *q) { - xframe_t *frm = NULL; - struct list_head *h; - struct timeval now; - unsigned long usec_lag; + xframe_t *frm = NULL; + struct list_head *h; + struct timeval now; + unsigned long usec_lag; if (list_empty(&q->head)) goto out; @@ -105,8 +102,10 @@ static xframe_t *__xframe_dequeue(struct xframe_queue *q) frm = list_entry(h, xframe_t, frame_list); do_gettimeofday(&now); usec_lag = - (now.tv_sec - frm->tv_queued.tv_sec)*1000*1000 + - (now.tv_usec - frm->tv_queued.tv_usec); + (now.tv_sec - frm->tv_queued.tv_sec) * 1000 * 1000 + (now.tv_usec - + frm-> + tv_queued. + tv_usec); if (q->worst_lag_usec < usec_lag) q->worst_lag_usec = usec_lag; out: @@ -115,14 +114,15 @@ out: xframe_t *xframe_dequeue(struct xframe_queue *q) { - unsigned long flags; - xframe_t *frm; + unsigned long flags; + xframe_t *frm; spin_lock_irqsave(&q->lock, flags); frm = __xframe_dequeue(q); spin_unlock_irqrestore(&q->lock, flags); return frm; } + void xframe_queue_disable(struct xframe_queue *q, bool disabled) { q->disabled = disabled; @@ -130,16 +130,17 @@ void xframe_queue_disable(struct xframe_queue *q, bool disabled) void xframe_queue_clear(struct xframe_queue *q) { - xframe_t *xframe; - xbus_t *xbus = q->priv; - int i = 0; + xframe_t *xframe; + xbus_t *xbus = q->priv; + int i = 0; xframe_queue_disable(q, 1); while ((xframe = xframe_dequeue(q)) != NULL) { transport_free_xframe(xbus, xframe); i++; } - XBUS_DBG(DEVICES, xbus, "%s: finished queue clear (%d items)\n", q->name, i); + XBUS_DBG(DEVICES, xbus, "%s: finished queue clear (%d items)\n", + q->name, i); } uint xframe_queue_count(struct xframe_queue *q) @@ -151,9 +152,9 @@ uint xframe_queue_count(struct xframe_queue *q) static xframe_t *transport_alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) { - struct xbus_ops *ops; - xframe_t *xframe; - unsigned long flags; + struct xbus_ops *ops; + xframe_t *xframe; + unsigned long flags; BUG_ON(!xbus); ops = transportops_get(xbus); @@ -169,8 +170,8 @@ static xframe_t *transport_alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) if ((rate_limit++ % 3001) == 0) XBUS_ERR(xbus, - "Failed xframe allocation from transport (%d)\n", - rate_limit); + "Failed xframe allocation from transport (%d)\n", + rate_limit); transportops_put(xbus); /* fall through */ } @@ -180,8 +181,8 @@ static xframe_t *transport_alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) static void transport_free_xframe(xbus_t *xbus, xframe_t *xframe) { - struct xbus_ops *ops; - unsigned long flags; + struct xbus_ops *ops; + unsigned long flags; BUG_ON(!xbus); ops = xbus->transport.ops; @@ -195,11 +196,11 @@ static void transport_free_xframe(xbus_t *xbus, xframe_t *xframe) static bool xframe_queue_adjust(struct xframe_queue *q) { - xbus_t *xbus; - xframe_t *xframe; - int delta; - unsigned long flags; - int ret = 0; + xbus_t *xbus; + xframe_t *xframe; + int delta; + unsigned long flags; + int ret = 0; BUG_ON(!q); xbus = q->priv; @@ -214,14 +215,16 @@ static bool xframe_queue_adjust(struct xframe_queue *q) static int rate_limit; if ((rate_limit++ % 3001) == 0) - XBUS_ERR(xbus, "%s: failed frame allocation\n", q->name); + XBUS_ERR(xbus, "%s: failed frame allocation\n", + q->name); goto out; } if (!__xframe_enqueue(q, xframe)) { static int rate_limit; if ((rate_limit++ % 3001) == 0) - XBUS_ERR(xbus, "%s: failed enqueueing frame\n", q->name); + XBUS_ERR(xbus, "%s: failed enqueueing frame\n", + q->name); transport_free_xframe(xbus, xframe); goto out; } @@ -233,7 +236,8 @@ static bool xframe_queue_adjust(struct xframe_queue *q) static int rate_limit; if ((rate_limit++ % 3001) == 0) - XBUS_ERR(xbus, "%s: failed dequeueing frame\n", q->name); + XBUS_ERR(xbus, "%s: failed dequeueing frame\n", + q->name); goto out; } transport_free_xframe(xbus, xframe); @@ -246,8 +250,8 @@ out: xframe_t *get_xframe(struct xframe_queue *q) { - xframe_t *xframe; - xbus_t *xbus; + xframe_t *xframe; + xbus_t *xbus; BUG_ON(!q); xbus = (xbus_t *)q->priv; @@ -258,7 +262,8 @@ xframe_t *get_xframe(struct xframe_queue *q) static int rate_limit; if ((rate_limit++ % 3001) == 0) - XBUS_ERR(xbus, "%s STILL EMPTY (%d)\n", q->name, rate_limit); + XBUS_ERR(xbus, "%s STILL EMPTY (%d)\n", q->name, + rate_limit); return NULL; } BUG_ON(xframe->xframe_magic != XFRAME_MAGIC); @@ -279,7 +284,7 @@ xframe_t *get_xframe(struct xframe_queue *q) void put_xframe(struct xframe_queue *q, xframe_t *xframe) { - xbus_t *xbus; + xbus_t *xbus; BUG_ON(!q); xbus = (xbus_t *)q->priv; @@ -294,7 +299,6 @@ void put_xframe(struct xframe_queue *q, xframe_t *xframe) xframe_queue_adjust(q); } - EXPORT_SYMBOL(xframe_queue_init); EXPORT_SYMBOL(xframe_queue_clearstats); EXPORT_SYMBOL(xframe_enqueue); diff --git a/drivers/dahdi/xpp/xframe_queue.h b/drivers/dahdi/xpp/xframe_queue.h index eba94dd..a62fa20 100644 --- a/drivers/dahdi/xpp/xframe_queue.h +++ b/drivers/dahdi/xpp/xframe_queue.h @@ -8,23 +8,22 @@ #define XFRAME_QUEUE_MARGIN 10 struct xframe_queue { - struct list_head head; - bool disabled; - unsigned int count; - unsigned int max_count; - unsigned int steady_state_count; - spinlock_t lock; - const char *name; - void *priv; + struct list_head head; + bool disabled; + unsigned int count; + unsigned int max_count; + unsigned int steady_state_count; + spinlock_t lock; + const char *name; + void *priv; /* statistics */ - unsigned int worst_count; - unsigned int overflows; - unsigned long worst_lag_usec; /* since xframe creation */ + unsigned int worst_count; + unsigned int overflows; + unsigned long worst_lag_usec; /* since xframe creation */ }; -void xframe_queue_init(struct xframe_queue *q, - unsigned int steady_state_count, unsigned int max_count, - const char *name, void *priv); +void xframe_queue_init(struct xframe_queue *q, unsigned int steady_state_count, + unsigned int max_count, const char *name, void *priv); __must_check bool xframe_enqueue(struct xframe_queue *q, xframe_t *xframe); __must_check xframe_t *xframe_dequeue(struct xframe_queue *q); void xframe_queue_clearstats(struct xframe_queue *q); @@ -32,4 +31,4 @@ void xframe_queue_disable(struct xframe_queue *q, bool disabled); void xframe_queue_clear(struct xframe_queue *q); uint xframe_queue_count(struct xframe_queue *q); -#endif /* XFRAME_QUEUE_ */ +#endif /* XFRAME_QUEUE_ */ diff --git a/drivers/dahdi/xpp/xpd.h b/drivers/dahdi/xpp/xpd.h index 8c8c27e..4f3b095 100644 --- a/drivers/dahdi/xpp/xpd.h +++ b/drivers/dahdi/xpp/xpd.h @@ -37,7 +37,7 @@ #include #endif #include -#endif /* __KERNEL__ */ +#endif /* __KERNEL__ */ #include @@ -45,7 +45,7 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 14) /* also added in RHEL kernels with the OpenInfiniband backport: */ #if LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 9) || !defined(DEFINE_SPINLOCK) -typedef unsigned gfp_t; /* Added in 2.6.14 */ +typedef unsigned gfp_t; /* Added in 2.6.14 */ #endif #endif @@ -81,21 +81,21 @@ typedef unsigned gfp_t; /* Added in 2.6.14 */ module_param_array(name, type, &name ## _num_values, 0644); \ MODULE_PARM_DESC(name, desc " ( 1-" __MODULE_STRING(count) ")") #endif -#endif // __KERNEL__ +#endif // __KERNEL__ #define CARD_DESC_MAGIC 0xca9dde5c -struct card_desc_struct { - struct list_head card_list; - u32 magic; - __u8 type; /* LSB: 1 - to_phone, 0 - to_line */ - __u8 subtype; - struct xpd_addr xpd_addr; - __u8 numchips; - __u8 ports_per_chip; - __u8 ports; - __u8 port_dir; - struct xpd_addr ec_addr; /* echo canceler address */ +struct card_desc_struct { + struct list_head card_list; + u32 magic; + __u8 type; /* LSB: 1 - to_phone, 0 - to_line */ + __u8 subtype; + struct xpd_addr xpd_addr; + __u8 numchips; + __u8 ports_per_chip; + __u8 ports; + __u8 port_dir; + struct xpd_addr ec_addr; /* echo canceler address */ }; typedef enum xpd_direction { @@ -120,12 +120,9 @@ enum { /* yucky, make an instance so we can size it... */ static struct xpd_counters { - char *name; + char *name; } xpd_counters[] = { - C_(PCM_READ), - C_(PCM_WRITE), - C_(RECV_ERRORS), -}; +C_(PCM_READ), C_(PCM_WRITE), C_(RECV_ERRORS),}; #undef C_ @@ -138,43 +135,43 @@ enum xpd_state { XPD_STATE_NOHW, }; -bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate); -const char *xpd_statename(enum xpd_state st); +bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate); +const char *xpd_statename(enum xpd_state st); #define PHONEDEV(xpd) ((xpd)->phonedev) #define IS_PHONEDEV(xpd) (PHONEDEV(xpd).phoneops) struct phonedev { - const struct phoneops *phoneops; /* Card level operations */ - struct dahdi_span span; - struct dahdi_chan *chans[32]; + const struct phoneops *phoneops; /* Card level operations */ + struct dahdi_span span; + struct dahdi_chan *chans[32]; #define XPD_CHAN(xpd, chan) (PHONEDEV(xpd).chans[(chan)]) struct dahdi_echocan_state *ec[32]; - int channels; - xpd_direction_t direction; /* TO_PHONE, TO_PSTN */ - xpp_line_t no_pcm; /* Temporary: disable PCM (for USB-1) */ - xpp_line_t offhook_state; /* Actual chip state: 0 - ONHOOK, 1 - OFHOOK */ - xpp_line_t oht_pcm_pass; /* Transfer on-hook PCM */ + int channels; + xpd_direction_t direction; /* TO_PHONE, TO_PSTN */ + xpp_line_t no_pcm; /* Temporary: disable PCM (for USB-1) */ + xpp_line_t offhook_state; /* Actual chip state: 0 - ONHOOK, 1 - OFHOOK */ + xpp_line_t oht_pcm_pass; /* Transfer on-hook PCM */ /* Voice Mail Waiting Indication: */ - unsigned int msg_waiting[CHANNELS_PERXPD]; - xpp_line_t digital_outputs; /* 0 - no, 1 - yes */ - xpp_line_t digital_inputs; /* 0 - no, 1 - yes */ - xpp_line_t digital_signalling; /* BRI signalling channels */ - uint timing_priority; /* from 'span' directives in chan_dahdi.conf */ + unsigned int msg_waiting[CHANNELS_PERXPD]; + xpp_line_t digital_outputs; /* 0 - no, 1 - yes */ + xpp_line_t digital_inputs; /* 0 - no, 1 - yes */ + xpp_line_t digital_signalling; /* BRI signalling channels */ + uint timing_priority; /* from 'span' directives in chan_dahdi.conf */ /* Assure atomicity of changes to pcm_len and wanted_pcm_mask */ - spinlock_t lock_recompute_pcm; + spinlock_t lock_recompute_pcm; /* maintained by card drivers */ - uint pcm_len; /* allocation length of PCM packet (dynamic) */ - xpp_line_t wanted_pcm_mask; - xpp_line_t silence_pcm; /* inject silence during next tick */ - xpp_line_t mute_dtmf; + uint pcm_len; /* allocation length of PCM packet (dynamic) */ + xpp_line_t wanted_pcm_mask; + xpp_line_t silence_pcm; /* inject silence during next tick */ + xpp_line_t mute_dtmf; - bool ringing[CHANNELS_PERXPD]; + bool ringing[CHANNELS_PERXPD]; - atomic_t dahdi_registered; /* Am I fully registered with dahdi */ - atomic_t open_counter; /* Number of open channels */ + atomic_t dahdi_registered; /* Am I fully registered with dahdi */ + atomic_t open_counter; /* Number of open channels */ /* Echo cancelation */ u_char ec_chunk1[CHANNELS_PERXPD][DAHDI_CHUNKSIZE]; @@ -186,51 +183,51 @@ struct phonedev { */ struct xpd { char xpdname[XPD_NAMELEN]; - struct phonedev phonedev; + struct phonedev phonedev; - const struct xops *xops; - xpd_type_t type; - const char *type_name; - __u8 subtype; - int subunits; /* all siblings */ - enum xpd_state xpd_state; - struct device xpd_dev; + const struct xops *xops; + xpd_type_t type; + const char *type_name; + __u8 subtype; + int subunits; /* all siblings */ + enum xpd_state xpd_state; + struct device xpd_dev; #define dev_to_xpd(dev) container_of(dev, struct xpd, xpd_dev) - struct kref kref; + struct kref kref; #define kref_to_xpd(k) container_of(k, struct xpd, kref) - xbus_t *xbus; /* The XBUS we are connected to */ - struct device *echocancel; + xbus_t *xbus; /* The XBUS we are connected to */ + struct device *echocancel; - spinlock_t lock; + spinlock_t lock; - int flags; - unsigned long blink_mode; /* bitmask of blinking ports */ + int flags; + unsigned long blink_mode; /* bitmask of blinking ports */ #define DEFAULT_LED_PERIOD (1000/8) /* in tick */ #ifdef CONFIG_PROC_FS - struct proc_dir_entry *proc_xpd_dir; - struct proc_dir_entry *proc_xpd_summary; + struct proc_dir_entry *proc_xpd_dir; + struct proc_dir_entry *proc_xpd_summary; #endif - int counters[XPD_COUNTER_MAX]; + int counters[XPD_COUNTER_MAX]; - const xproto_table_t *xproto; /* Card level protocol table */ - void *priv; /* Card level private data */ - bool card_present; - reg_cmd_t requested_reply; - reg_cmd_t last_reply; + const xproto_table_t *xproto; /* Card level protocol table */ + void *priv; /* Card level private data */ + bool card_present; + reg_cmd_t requested_reply; + reg_cmd_t last_reply; - unsigned long last_response; /* in jiffies */ - unsigned xbus_idx; /* index in xbus->xpds[] */ - struct xpd_addr addr; + unsigned long last_response; /* in jiffies */ + unsigned xbus_idx; /* index in xbus->xpds[] */ + struct xpd_addr addr; struct list_head xpd_list; - unsigned int timer_count; + unsigned int timer_count; }; #define for_each_line(xpd, i) for ((i) = 0; (i) < PHONEDEV(xpd).channels; (i)++) #define IS_BRI(xpd) ((xpd)->type == XPD_TYPE_BRI) -#define TICK_TOLERANCE 500 /* usec */ +#define TICK_TOLERANCE 500 /* usec */ #ifdef DEBUG_SYNC_PARPORT void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1); @@ -240,7 +237,7 @@ void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1); static inline void *my_kzalloc(size_t size, gfp_t flags) { - void *p; + void *p; p = kmalloc(size, flags); if (p) @@ -249,18 +246,18 @@ static inline void *my_kzalloc(size_t size, gfp_t flags) } struct xpd_driver { - xpd_type_t type; + xpd_type_t type; - struct device_driver driver; + struct device_driver driver; #define driver_to_xpd_driver(driver) container_of(driver, struct xpd_driver, driver) }; -int xpd_driver_register(struct device_driver *driver); -void xpd_driver_unregister(struct device_driver *driver); -xpd_t *get_xpd(const char *msg, xpd_t *xpd); -void put_xpd(const char *msg, xpd_t *xpd); -int refcount_xpd(xpd_t *xpd); +int xpd_driver_register(struct device_driver *driver); +void xpd_driver_unregister(struct device_driver *driver); +xpd_t *get_xpd(const char *msg, xpd_t *xpd); +void put_xpd(const char *msg, xpd_t *xpd); +int refcount_xpd(xpd_t *xpd); #endif -#endif /* XPD_H */ +#endif /* XPD_H */ diff --git a/drivers/dahdi/xpp/xpp_dahdi.c b/drivers/dahdi/xpp/xpp_dahdi.c index 3d75296..5c6626c 100644 --- a/drivers/dahdi/xpp/xpp_dahdi.c +++ b/drivers/dahdi/xpp/xpp_dahdi.c @@ -27,7 +27,7 @@ #include #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #include @@ -57,7 +57,8 @@ struct proc_dir_entry *xpp_proc_toplevel = NULL; #define DELAY_UNTIL_DIALTONE 3000 DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); -static DEF_PARM_BOOL(prefmaster, 0, 0644, "Do we want to be dahdi preferred sync master"); +static DEF_PARM_BOOL(prefmaster, 0, 0644, + "Do we want to be dahdi preferred sync master"); // DEF_ARRAY(int, pcmtx, 4, 0, "Forced PCM values to transmit"); #include "dahdi_debug.h" @@ -75,6 +76,7 @@ static void phonedev_cleanup(xpd_t *xpd); * echo "3,5" > /sys/module/xpp/parameters/parport_xbuses */ static int parport_xbuses[2] = { 0, 1 }; + unsigned int parport_xbuses_num_values; #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 9) module_param_array(parport_xbuses, int, &parport_xbuses_num_values, 0577); @@ -90,13 +92,14 @@ MODULE_PARM_DESC(parport_xbuses, "Id's of xbuses to sample (1-2)"); */ void xbus_flip_bit(xbus_t *xbus, unsigned int bitnum0, unsigned int bitnum1) { - int num = xbus->num; + int num = xbus->num; if (num == parport_xbuses[0]) flip_parport_bit(bitnum0); if (num == parport_xbuses[1]) flip_parport_bit(bitnum1); } + EXPORT_SYMBOL(xbus_flip_bit); #endif @@ -108,7 +111,8 @@ int total_registered_spans(void) } #ifdef CONFIG_PROC_FS -static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data); +static int xpd_read_proc(char *page, char **start, off_t off, int count, + int *eof, void *data); #endif /*------------------------- XPD Management -------------------------*/ @@ -118,7 +122,7 @@ static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eo */ static void xpd_destroy(struct kref *kref) { - xpd_t *xpd; + xpd_t *xpd; xpd = kref_to_xpd(kref); XPD_DBG(DEVICES, xpd, "%s\n", __func__); @@ -134,16 +138,14 @@ int refcount_xpd(xpd_t *xpd) xpd_t *get_xpd(const char *msg, xpd_t *xpd) { - XPD_DBG(DEVICES, xpd, "%s: refcount_xpd=%d\n", - msg, refcount_xpd(xpd)); + XPD_DBG(DEVICES, xpd, "%s: refcount_xpd=%d\n", msg, refcount_xpd(xpd)); kref_get(&xpd->kref); return xpd; } void put_xpd(const char *msg, xpd_t *xpd) { - XPD_DBG(DEVICES, xpd, "%s: refcount_xpd=%d\n", - msg, refcount_xpd(xpd)); + XPD_DBG(DEVICES, xpd, "%s: refcount_xpd=%d\n", msg, refcount_xpd(xpd)); kref_put(&xpd->kref, xpd_destroy); } @@ -152,12 +154,13 @@ static void xpd_proc_remove(xbus_t *xbus, xpd_t *xpd) #ifdef CONFIG_PROC_FS if (xpd->proc_xpd_dir) { if (xpd->proc_xpd_summary) { - XPD_DBG(PROC, xpd, "Removing proc '%s'\n", PROC_XPD_SUMMARY); + XPD_DBG(PROC, xpd, "Removing proc '%s'\n", + PROC_XPD_SUMMARY); remove_proc_entry(PROC_XPD_SUMMARY, xpd->proc_xpd_dir); xpd->proc_xpd_summary = NULL; } XPD_DBG(PROC, xpd, "Removing %s/%s proc directory\n", - xbus->busname, xpd->xpdname); + xbus->busname, xpd->xpdname); remove_proc_entry(xpd->xpdname, xbus->proc_xbus_dir); xpd->proc_xpd_dir = NULL; } @@ -173,10 +176,12 @@ static int xpd_proc_create(xbus_t *xbus, xpd_t *xpd) XPD_ERR(xpd, "Failed to create proc directory\n"); goto err; } - xpd->proc_xpd_summary = create_proc_read_entry(PROC_XPD_SUMMARY, 0444, xpd->proc_xpd_dir, - xpd_read_proc, xpd); + xpd->proc_xpd_summary = + create_proc_read_entry(PROC_XPD_SUMMARY, 0444, xpd->proc_xpd_dir, + xpd_read_proc, xpd); if (!xpd->proc_xpd_summary) { - XPD_ERR(xpd, "Failed to create proc file '%s'\n", PROC_XPD_SUMMARY); + XPD_ERR(xpd, "Failed to create proc file '%s'\n", + PROC_XPD_SUMMARY); goto err; } SET_PROC_DIRENTRY_OWNER(xpd->proc_xpd_summary); @@ -191,7 +196,7 @@ err: void xpd_free(xpd_t *xpd) { - xbus_t *xbus = NULL; + xbus_t *xbus = NULL; if (!xpd) return; @@ -210,43 +215,41 @@ void xpd_free(xpd_t *xpd) /* * This must be last, so the xbus cannot be released before the xpd */ - put_xbus(__func__, xbus); /* was taken in xpd_alloc() */ + put_xbus(__func__, xbus); /* was taken in xpd_alloc() */ } /* * Synchronous part of XPD detection. * Called from new_card() */ -int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, - int unit, - int subunit, - __u8 type, - __u8 subtype, - int subunits, - int subunit_ports, - __u8 port_dir) +int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, int unit, + int subunit, __u8 type, __u8 subtype, int subunits, + int subunit_ports, __u8 port_dir) { - xpd_t *xpd = NULL; - bool to_phone; + xpd_t *xpd = NULL; + bool to_phone; BUG_ON(type == XPD_TYPE_NOMODULE); to_phone = BIT(subunit) & port_dir; BUG_ON(!xbus); xpd = xpd_byaddr(xbus, unit, subunit); if (xpd) { - XPD_NOTICE(xpd, "XPD at %d%d already exists\n", - unit, subunit); + XPD_NOTICE(xpd, "XPD at %d%d already exists\n", unit, subunit); return 0; } if (subunit_ports <= 0 || subunit_ports > CHANNELS_PERXPD) { XBUS_NOTICE(xbus, "Illegal number of ports %d for XPD %d%d\n", - subunit_ports, unit, subunit); + subunit_ports, unit, subunit); return 0; } - xpd = proto_table->xops->card_new(xbus, unit, subunit, proto_table, subtype, subunits, subunit_ports, to_phone); + xpd = + proto_table->xops->card_new(xbus, unit, subunit, proto_table, + subtype, subunits, subunit_ports, + to_phone); if (!xpd) { XBUS_NOTICE(xbus, "card_new(%d,%d,%d,%d,%d) failed. Ignored.\n", - unit, subunit, proto_table->type, subtype, to_phone); + unit, subunit, proto_table->type, subtype, + to_phone); return -EINVAL; } return 0; @@ -263,43 +266,55 @@ int create_xpd(xbus_t *xbus, const xproto_table_t *proto_table, * @eof TODO: figure out procfs * @data an xbus_t pointer with the bus data. */ -static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) +static int xpd_read_proc(char *page, char **start, off_t off, int count, + int *eof, void *data) { - int len = 0; - xpd_t *xpd = data; - int i; + int len = 0; + xpd_t *xpd = data; + int i; if (!xpd) goto out; - len += sprintf(page + len, "%s (%s, card %s, span %d)\n" - "timing_priority: %d\n" - "timer_count: %d span->mainttimer=%d\n" - , - xpd->xpdname, xpd->type_name, - (xpd->card_present) ? "present" : "missing", - (SPAN_REGISTERED(xpd)) ? PHONEDEV(xpd).span.spanno : 0, - PHONEDEV(xpd).timing_priority, - xpd->timer_count, PHONEDEV(xpd).span.mainttimer - ); - len += sprintf(page + len, "xpd_state: %s (%d)\n", - xpd_statename(xpd->xpd_state), xpd->xpd_state); - len += sprintf(page + len, "open_counter=%d refcount=%d\n", - atomic_read(&PHONEDEV(xpd).open_counter), refcount_xpd(xpd)); - len += sprintf(page + len, "Address: U=%d S=%d\n", xpd->addr.unit, xpd->addr.subunit); + len += + sprintf(page + len, + "%s (%s, card %s, span %d)\n" "timing_priority: %d\n" + "timer_count: %d span->mainttimer=%d\n", xpd->xpdname, + xpd->type_name, (xpd->card_present) ? "present" : "missing", + (SPAN_REGISTERED(xpd)) ? PHONEDEV(xpd).span.spanno : 0, + PHONEDEV(xpd).timing_priority, xpd->timer_count, + PHONEDEV(xpd).span.mainttimer); + len += + sprintf(page + len, "xpd_state: %s (%d)\n", + xpd_statename(xpd->xpd_state), xpd->xpd_state); + len += + sprintf(page + len, "open_counter=%d refcount=%d\n", + atomic_read(&PHONEDEV(xpd).open_counter), + refcount_xpd(xpd)); + len += + sprintf(page + len, "Address: U=%d S=%d\n", xpd->addr.unit, + xpd->addr.subunit); len += sprintf(page + len, "Subunits: %d\n", xpd->subunits); len += sprintf(page + len, "Type: %d.%d\n\n", xpd->type, xpd->subtype); len += sprintf(page + len, "pcm_len=%d\n\n", PHONEDEV(xpd).pcm_len); - len += sprintf(page + len, "wanted_pcm_mask=0x%04X\n\n", PHONEDEV(xpd).wanted_pcm_mask); - len += sprintf(page + len, "mute_dtmf=0x%04X\n\n", PHONEDEV(xpd).mute_dtmf); + len += + sprintf(page + len, "wanted_pcm_mask=0x%04X\n\n", + PHONEDEV(xpd).wanted_pcm_mask); + len += + sprintf(page + len, "mute_dtmf=0x%04X\n\n", + PHONEDEV(xpd).mute_dtmf); len += sprintf(page + len, "STATES:"); len += sprintf(page + len, "\n\t%-17s: ", "output_relays"); for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(PHONEDEV(xpd).digital_outputs, i)); + len += + sprintf(page + len, "%d ", + IS_SET(PHONEDEV(xpd).digital_outputs, i)); } len += sprintf(page + len, "\n\t%-17s: ", "input_relays"); for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(PHONEDEV(xpd).digital_inputs, i)); + len += + sprintf(page + len, "%d ", + IS_SET(PHONEDEV(xpd).digital_inputs, i)); } len += sprintf(page + len, "\n\t%-17s: ", "offhook"); for_each_line(xpd, i) { @@ -307,7 +322,9 @@ static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eo } len += sprintf(page + len, "\n\t%-17s: ", "oht_pcm_pass"); for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(PHONEDEV(xpd).oht_pcm_pass, i)); + len += + sprintf(page + len, "%d ", + IS_SET(PHONEDEV(xpd).oht_pcm_pass, i)); } len += sprintf(page + len, "\n\t%-17s: ", "msg_waiting"); for_each_line(xpd, i) { @@ -319,17 +336,20 @@ static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eo } len += sprintf(page + len, "\n\t%-17s: ", "no_pcm"); for_each_line(xpd, i) { - len += sprintf(page + len, "%d ", IS_SET(PHONEDEV(xpd).no_pcm, i)); + len += + sprintf(page + len, "%d ", IS_SET(PHONEDEV(xpd).no_pcm, i)); } #if 1 if (SPAN_REGISTERED(xpd)) { - len += sprintf(page + len, "\nPCM:\n | [readchunk] | [writechunk] | W D"); + len += + sprintf(page + len, + "\nPCM:\n | [readchunk] | [writechunk] | W D"); for_each_line(xpd, i) { - struct dahdi_chan *chan = XPD_CHAN(xpd, i); - __u8 rchunk[DAHDI_CHUNKSIZE]; - __u8 wchunk[DAHDI_CHUNKSIZE]; - __u8 *rp; - __u8 *wp; + struct dahdi_chan *chan = XPD_CHAN(xpd, i); + __u8 rchunk[DAHDI_CHUNKSIZE]; + __u8 wchunk[DAHDI_CHUNKSIZE]; + __u8 *rp; + __u8 *wp; int j; if (IS_SET(PHONEDEV(xpd).digital_outputs, i)) @@ -350,10 +370,14 @@ static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eo for (j = 0; j < DAHDI_CHUNKSIZE; j++) { len += sprintf(page + len, "%02X ", wchunk[j]); } - len += sprintf(page + len, " | %c", - (IS_SET(PHONEDEV(xpd).wanted_pcm_mask, i))?'+':' '); - len += sprintf(page + len, " %c", - (IS_SET(PHONEDEV(xpd).mute_dtmf, i))?'-':' '); + len += + sprintf(page + len, " | %c", + (IS_SET(PHONEDEV(xpd).wanted_pcm_mask, i)) ? + '+' : ' '); + len += + sprintf(page + len, " %c", + (IS_SET(PHONEDEV(xpd).mute_dtmf, i)) ? '-' : + ' '); } } #endif @@ -362,18 +386,22 @@ static int xpd_read_proc(char *page, char **start, off_t off, int count, int *eo len += sprintf(page + len, "\nSignalling:\n"); for_each_line(xpd, i) { struct dahdi_chan *chan = XPD_CHAN(xpd, i); - len += sprintf(page + len, "\t%2d> sigcap=0x%04X sig=0x%04X\n", i, chan->sigcap, chan->sig); + len += + sprintf(page + len, + "\t%2d> sigcap=0x%04X sig=0x%04X\n", i, + chan->sigcap, chan->sig); } } #endif len += sprintf(page + len, "\nCOUNTERS:\n"); for (i = 0; i < XPD_COUNTER_MAX; i++) { - len += sprintf(page + len, "\t\t%-20s = %d\n", - xpd_counters[i].name, xpd->counters[i]); + len += + sprintf(page + len, "\t\t%-20s = %d\n", + xpd_counters[i].name, xpd->counters[i]); } len += sprintf(page + len, "<-- len=%d\n", len); out: - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -390,10 +418,14 @@ out: const char *xpd_statename(enum xpd_state st) { switch (st) { - case XPD_STATE_START: return "START"; - case XPD_STATE_INIT_REGS: return "INIT_REGS"; - case XPD_STATE_READY: return "READY"; - case XPD_STATE_NOHW: return "NOHW"; + case XPD_STATE_START: + return "START"; + case XPD_STATE_INIT_REGS: + return "INIT_REGS"; + case XPD_STATE_READY: + return "READY"; + case XPD_STATE_NOHW: + return "NOHW"; } return NULL; } @@ -412,8 +444,8 @@ bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate) goto badstate; if (xpd->addr.subunit != 0) { XPD_NOTICE(xpd, - "%s: Moving to %s allowed only for subunit 0\n", - __func__, xpd_statename(newstate)); + "%s: Moving to %s allowed only for subunit 0\n", + __func__, xpd_statename(newstate)); goto badstate; } break; @@ -435,21 +467,19 @@ bool xpd_setstate(xpd_t *xpd, enum xpd_state newstate) xpd->xpd_state = newstate; return 1; badstate: - XPD_NOTICE(xpd, "%s: cannot transition: %s (%d) -> %s (%d)\n", - __func__, - xpd_statename(xpd->xpd_state), xpd->xpd_state, - xpd_statename(newstate), newstate); + XPD_NOTICE(xpd, "%s: cannot transition: %s (%d) -> %s (%d)\n", __func__, + xpd_statename(xpd->xpd_state), xpd->xpd_state, + xpd_statename(newstate), newstate); return 0; } - /* * Cleanup/initialize phonedev */ static void phonedev_cleanup(xpd_t *xpd) { - struct phonedev *phonedev = &PHONEDEV(xpd); - unsigned int x; + struct phonedev *phonedev = &PHONEDEV(xpd); + unsigned int x; for (x = 0; x < phonedev->channels; x++) { if (phonedev->chans[x]) { @@ -460,11 +490,12 @@ static void phonedev_cleanup(xpd_t *xpd) } } -__must_check static int phonedev_init(xpd_t *xpd, const xproto_table_t *proto_table, - int channels, xpp_line_t no_pcm) +__must_check static int phonedev_init(xpd_t *xpd, + const xproto_table_t *proto_table, + int channels, xpp_line_t no_pcm) { - struct phonedev *phonedev = &PHONEDEV(xpd); - unsigned int x; + struct phonedev *phonedev = &PHONEDEV(xpd); + unsigned int x; spin_lock_init(&phonedev->lock_recompute_pcm); phonedev->channels = channels; @@ -476,15 +507,17 @@ __must_check static int phonedev_init(xpd_t *xpd, const xproto_table_t *proto_ta atomic_set(&phonedev->dahdi_registered, 0); atomic_set(&phonedev->open_counter, 0); for (x = 0; x < phonedev->channels; x++) { - if (!(phonedev->chans[x] = KZALLOC(sizeof(*(phonedev->chans[x])), GFP_KERNEL))) { + if (! + (phonedev->chans[x] = + KZALLOC(sizeof(*(phonedev->chans[x])), GFP_KERNEL))) { ERR("%s: Unable to allocate channel %d\n", __func__, x); goto err; } - phonedev->ec[x] = KZALLOC(sizeof(*(phonedev->ec[x])), - GFP_KERNEL); + phonedev->ec[x] = + KZALLOC(sizeof(*(phonedev->ec[x])), GFP_KERNEL); if (!phonedev->ec[x]) { ERR("%s: Unable to allocate ec state %d\n", __func__, - x); + x); goto err; } } @@ -498,28 +531,27 @@ err: * xpd_alloc - Allocator for new XPD's * */ -__must_check xpd_t *xpd_alloc(xbus_t *xbus, - int unit, int subunit, - int subtype, int subunits, - size_t privsize, const xproto_table_t *proto_table, int channels) +__must_check xpd_t *xpd_alloc(xbus_t *xbus, int unit, int subunit, int subtype, + int subunits, size_t privsize, + const xproto_table_t *proto_table, int channels) { - xpd_t *xpd = NULL; - size_t alloc_size = sizeof(xpd_t) + privsize; - int type = proto_table->type; - xpp_line_t no_pcm = 0; + xpd_t *xpd = NULL; + size_t alloc_size = sizeof(xpd_t) + privsize; + int type = proto_table->type; + xpp_line_t no_pcm = 0; BUG_ON(!proto_table); - XBUS_DBG(DEVICES, xbus, "type=%d channels=%d (alloc_size=%zd)\n", - type, channels, alloc_size); + XBUS_DBG(DEVICES, xbus, "type=%d channels=%d (alloc_size=%zd)\n", type, + channels, alloc_size); if (channels > CHANNELS_PERXPD) { - XBUS_ERR(xbus, "%s: type=%d: too many channels %d\n", - __func__, type, channels); + XBUS_ERR(xbus, "%s: type=%d: too many channels %d\n", __func__, + type, channels); goto err; } if ((xpd = KZALLOC(alloc_size, GFP_KERNEL)) == NULL) { XBUS_ERR(xbus, "%s: type=%d: Unable to allocate memory\n", - __func__, type); + __func__, type); goto err; } xpd->priv = (__u8 *)xpd + sizeof(xpd_t); @@ -535,9 +567,12 @@ __must_check xpd_t *xpd_alloc(xbus_t *xbus, /* For USB-1 disable some channels */ if (MAX_SEND_SIZE(xbus) < RPACKET_SIZE(GLOBAL, PCM_WRITE)) { - no_pcm = 0x7F | PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd).digital_inputs; - XBUS_NOTICE(xbus, "max xframe size = %d, disabling some PCM channels. no_pcm=0x%04X\n", - MAX_SEND_SIZE(xbus), PHONEDEV(xpd).no_pcm); + no_pcm = + 0x7F | PHONEDEV(xpd).digital_outputs | PHONEDEV(xpd). + digital_inputs; + XBUS_NOTICE(xbus, + "max xframe size = %d, disabling some PCM channels. no_pcm=0x%04X\n", + MAX_SEND_SIZE(xbus), PHONEDEV(xpd).no_pcm); } if (phonedev_init(xpd, proto_table, channels, no_pcm) < 0) goto err; @@ -549,7 +584,7 @@ __must_check xpd_t *xpd_alloc(xbus_t *xbus, * is removed in xpd_free() */ xbus = get_xbus(__func__, xbus->num); /* returned in xpd_free() */ - xproto_get(type); /* will be returned in xpd_free() */ + xproto_get(type); /* will be returned in xpd_free() */ return xpd; err: if (xpd) { @@ -580,16 +615,17 @@ void update_xpd_status(xpd_t *xpd, int alarm_flag) return; } switch (alarm_flag) { - case DAHDI_ALARM_NONE: - xpd->last_response = jiffies; - break; - default: - // Nothing - break; + case DAHDI_ALARM_NONE: + xpd->last_response = jiffies; + break; + default: + // Nothing + break; } if (span->alarms == alarm_flag) return; - XPD_DBG(GENERAL, xpd, "Update XPD alarms: %s -> %02X\n", PHONEDEV(xpd).span.name, alarm_flag); + XPD_DBG(GENERAL, xpd, "Update XPD alarms: %s -> %02X\n", + PHONEDEV(xpd).span.name, alarm_flag); span->alarms = alarm_flag; dahdi_alarm_notify(span); } @@ -661,24 +697,24 @@ void hookstate_changed(xpd_t *xpd, int pos, bool to_offhook) */ BIT_SET(PHONEDEV(xpd).silence_pcm, pos); } - notify_rxsig(xpd, pos, (to_offhook) ? DAHDI_RXSIG_OFFHOOK : DAHDI_RXSIG_ONHOOK); + notify_rxsig(xpd, pos, + (to_offhook) ? DAHDI_RXSIG_OFFHOOK : DAHDI_RXSIG_ONHOOK); } #define XPP_MAX_LEN 512 /*------------------------- Dahdi Interfaces -----------------------*/ - /* * Called from dahdi with spinlock held on chan. Must not call back * dahdi functions. */ int xpp_open(struct dahdi_chan *chan) { - xpd_t *xpd; - xbus_t *xbus; - int pos; - unsigned long flags; + xpd_t *xpd; + xbus_t *xbus; + int pos; + unsigned long flags; if (!chan) { NOTICE("open called on a null chan\n"); @@ -701,9 +737,8 @@ int xpp_open(struct dahdi_chan *chan) } spin_lock_irqsave(&xbus->lock, flags); atomic_inc(&PHONEDEV(xpd).open_counter); - LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", - current->comm, current->pid, - atomic_read(&PHONEDEV(xpd).open_counter)); + LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", current->comm, + current->pid, atomic_read(&PHONEDEV(xpd).open_counter)); spin_unlock_irqrestore(&xbus->lock, flags); if (PHONE_METHOD(card_open, xpd)) CALL_PHONE_METHOD(card_open, xpd, pos); @@ -712,25 +747,24 @@ int xpp_open(struct dahdi_chan *chan) int xpp_close(struct dahdi_chan *chan) { - xpd_t *xpd = chan->pvt; - xbus_t *xbus = xpd->xbus; - int pos = chan->chanpos - 1; - unsigned long flags; + xpd_t *xpd = chan->pvt; + xbus_t *xbus = xpd->xbus; + int pos = chan->chanpos - 1; + unsigned long flags; spin_lock_irqsave(&xbus->lock, flags); spin_unlock_irqrestore(&xbus->lock, flags); if (PHONE_METHOD(card_close, xpd)) CALL_PHONE_METHOD(card_close, xpd, pos); - LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", - current->comm, current->pid, - atomic_read(&PHONEDEV(xpd).open_counter)); - atomic_dec(&PHONEDEV(xpd).open_counter); /* from xpp_open() */ + LINE_DBG(DEVICES, xpd, pos, "%s[%d]: open_counter=%d\n", current->comm, + current->pid, atomic_read(&PHONEDEV(xpd).open_counter)); + atomic_dec(&PHONEDEV(xpd).open_counter); /* from xpp_open() */ return 0; } void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd) { - char *extra_msg = ""; + char *extra_msg = ""; if (_IOC_TYPE(cmd) == 'J') extra_msg = " (for old ZAPTEL)"; @@ -744,48 +778,51 @@ void report_bad_ioctl(const char *msg, xpd_t *xpd, int pos, unsigned int cmd) int xpp_ioctl(struct dahdi_chan *chan, unsigned int cmd, unsigned long arg) { - xpd_t *xpd = chan->pvt; - int pos = chan->chanpos - 1; + xpd_t *xpd = chan->pvt; + int pos = chan->chanpos - 1; if (!xpd) { ERR("%s: channel in pos %d, was already closed. Ignore.\n", - __func__, pos); + __func__, pos); return -ENODEV; } switch (cmd) { - default: - /* Some span-specific commands before we give up: */ - if (PHONE_METHOD(card_ioctl, xpd)) { - return CALL_PHONE_METHOD(card_ioctl, xpd, pos, cmd, arg); - } - report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); - return -ENOTTY; + default: + /* Some span-specific commands before we give up: */ + if (PHONE_METHOD(card_ioctl, xpd)) { + return CALL_PHONE_METHOD(card_ioctl, xpd, pos, cmd, + arg); + } + report_bad_ioctl(THIS_MODULE->name, xpd, pos, cmd); + return -ENOTTY; } return 0; } int xpp_hooksig(struct dahdi_chan *chan, enum dahdi_txsig txsig) { - xpd_t *xpd = chan->pvt; - xbus_t *xbus; + xpd_t *xpd = chan->pvt; + xbus_t *xbus; int pos = chan->chanpos - 1; if (!xpd) { ERR("%s: channel in pos %d, was already closed. Ignore.\n", - __func__, pos); + __func__, pos); return -ENODEV; } if (!PHONE_METHOD(card_hooksig, xpd)) { LINE_ERR(xpd, pos, - "%s: No hooksig method for this channel. Ignore.\n", - __func__); + "%s: No hooksig method for this channel. Ignore.\n", + __func__); return -ENODEV; } xbus = xpd->xbus; BUG_ON(!xbus); - DBG(SIGNAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), txsig); + DBG(SIGNAL, "Setting %s to %s (%d)\n", chan->name, txsig2str(txsig), + txsig); return CALL_PHONE_METHOD(card_hooksig, xpd, pos, txsig); } + EXPORT_SYMBOL(xpp_hooksig); /* Req: Set the requested chunk size. This is the unit in which you must @@ -795,34 +832,34 @@ int xpp_setchunksize(struct dahdi_span *span, int chunksize); /* Enable maintenance modes */ int xpp_maint(struct dahdi_span *span, int cmd) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); - int ret = 0; + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + int ret = 0; #if 0 - char loopback_data[] = "THE-QUICK-BROWN-FOX-JUMPED-OVER-THE-LAZY-DOG"; + char loopback_data[] = "THE-QUICK-BROWN-FOX-JUMPED-OVER-THE-LAZY-DOG"; #endif DBG(GENERAL, "span->mainttimer=%d\n", span->mainttimer); switch (cmd) { - case DAHDI_MAINT_NONE: - INFO("XXX Turn off local and remote loops XXX\n"); - break; - case DAHDI_MAINT_LOCALLOOP: - INFO("XXX Turn on local loopback XXX\n"); - break; - case DAHDI_MAINT_REMOTELOOP: - INFO("XXX Turn on remote loopback XXX\n"); - break; - case DAHDI_MAINT_LOOPUP: - INFO("XXX Send loopup code XXX\n"); - break; - case DAHDI_MAINT_LOOPDOWN: - INFO("XXX Send loopdown code XXX\n"); - break; - default: - ERR("XPP: Unknown maint command: %d\n", cmd); - ret = -EINVAL; - break; + case DAHDI_MAINT_NONE: + INFO("XXX Turn off local and remote loops XXX\n"); + break; + case DAHDI_MAINT_LOCALLOOP: + INFO("XXX Turn on local loopback XXX\n"); + break; + case DAHDI_MAINT_REMOTELOOP: + INFO("XXX Turn on remote loopback XXX\n"); + break; + case DAHDI_MAINT_LOOPUP: + INFO("XXX Send loopup code XXX\n"); + break; + case DAHDI_MAINT_LOOPDOWN: + INFO("XXX Send loopdown code XXX\n"); + break; + default: + ERR("XPP: Unknown maint command: %d\n", cmd); + ret = -EINVAL; + break; } if (span->mainttimer || span->maintstat) update_xpd_status(xpd, DAHDI_ALARM_LOOPBACK); @@ -836,7 +873,7 @@ int xpp_maint(struct dahdi_span *span, int cmd) */ static int xpp_watchdog(struct dahdi_span *span, int cause) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1000) == 0) DBG(GENERAL, "\n"); @@ -848,12 +885,12 @@ static int xpp_watchdog(struct dahdi_span *span, int cause) * Hardware Echo Canceller management */ static void echocan_free(struct dahdi_chan *chan, - struct dahdi_echocan_state *ec) + struct dahdi_echocan_state *ec) { - xpd_t *xpd; - xbus_t *xbus; - int pos = chan->chanpos - 1; - const struct echoops *echoops; + xpd_t *xpd; + xbus_t *xbus; + int pos = chan->chanpos - 1; + const struct echoops *echoops; xpd = chan->pvt; xbus = xpd->xbus; @@ -875,9 +912,9 @@ static const struct dahdi_echocan_ops xpp_ec_ops = { const char *xpp_echocan_name(const struct dahdi_chan *chan) { - xpd_t *xpd; - xbus_t *xbus; - int pos; + xpd_t *xpd; + xbus_t *xbus; + int pos; if (!chan) { NOTICE("%s(NULL)\n", __func__); @@ -893,37 +930,34 @@ const char *xpp_echocan_name(const struct dahdi_chan *chan) * quirks and limitations */ if (xbus->quirks.has_fxo) { - if ( - xbus->quirks.has_digital_span && - xpd->type == XPD_TYPE_FXO) { + if (xbus->quirks.has_digital_span && xpd->type == XPD_TYPE_FXO) { LINE_NOTICE(xpd, pos, - "quirk: give up HWEC on FXO: " - "AB has digital span\n"); + "quirk: give up HWEC on FXO: " + "AB has digital span\n"); return NULL; - } else if ( - xbus->sync_mode != SYNC_MODE_AB && - xpd->type == XPD_TYPE_FXS) { + } else if (xbus->sync_mode != SYNC_MODE_AB + && xpd->type == XPD_TYPE_FXS) { LINE_NOTICE(xpd, pos, - "quirk: give up HWEC on FXS: " - "AB has FXO and is sync slave\n"); + "quirk: give up HWEC on FXS: " + "AB has FXO and is sync slave\n"); return NULL; } } return "XPP"; } + EXPORT_SYMBOL(xpp_echocan_name); -int xpp_echocan_create(struct dahdi_chan *chan, - struct dahdi_echocanparams *ecp, - struct dahdi_echocanparam *p, - struct dahdi_echocan_state **ec) +int xpp_echocan_create(struct dahdi_chan *chan, struct dahdi_echocanparams *ecp, + struct dahdi_echocanparam *p, + struct dahdi_echocan_state **ec) { - xpd_t *xpd; - xbus_t *xbus; - int pos; - struct phonedev *phonedev; - const struct echoops *echoops; - int ret; + xpd_t *xpd; + xbus_t *xbus; + int pos; + struct phonedev *phonedev; + const struct echoops *echoops; + int ret; xpd = chan->pvt; xbus = xpd->xbus; @@ -937,17 +971,18 @@ int xpp_echocan_create(struct dahdi_chan *chan, (*ec)->features = xpp_ec_features; xpd = get_xpd(__func__, xpd); /* Returned in echocan_free() */ LINE_DBG(GENERAL, xpd, pos, "(tap=%d, param_count=%d)\n", - ecp->tap_length, ecp->param_count); + ecp->tap_length, ecp->param_count); ret = CALL_EC_METHOD(ec_set, xbus, xpd, pos, 1); CALL_EC_METHOD(ec_update, xbus, xbus); return ret; } + EXPORT_SYMBOL(xpp_echocan_create); void xpp_span_assigned(struct dahdi_span *span) { - struct phonedev *phonedev = container_of(span, struct phonedev, span); - xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); + struct phonedev *phonedev = container_of(span, struct phonedev, span); + xpd_t *xpd = container_of(phonedev, struct xpd, phonedev); XPD_INFO(xpd, "Span assigned: %d\n", span->spanno); if (xpd->card_present) { @@ -955,6 +990,7 @@ void xpp_span_assigned(struct dahdi_span *span) dahdi_alarm_notify(&phonedev->span); } } + EXPORT_SYMBOL(xpp_span_assigned); static const struct dahdi_span_ops xpp_span_ops = { @@ -984,7 +1020,8 @@ void xpd_set_spanname(xpd_t *xpd) { struct dahdi_span *span = &PHONEDEV(xpd).span; - snprintf(span->name, MAX_SPANNAME, "%s/%s", xpd->xbus->busname, xpd->xpdname); + snprintf(span->name, MAX_SPANNAME, "%s/%s", xpd->xbus->busname, + xpd->xpdname); /* * The "Xorcom XPD" is a prefix in one of the regexes we * use in our dahdi_genconf to match for PRI cards. @@ -992,14 +1029,15 @@ void xpd_set_spanname(xpd_t *xpd) * this horseshit. */ snprintf(span->desc, MAX_SPANDESC, "Xorcom XPD [%s].%d: %s", - xpd->xbus->label, span->offset + 1, xpd->type_name); + xpd->xbus->label, span->offset + 1, xpd->type_name); } + EXPORT_SYMBOL(xpd_set_spanname); static void xpd_init_span(xpd_t *xpd, unsigned offset, int cn) { - struct dahdi_span *span; - int i; + struct dahdi_span *span; + int i; memset(&PHONEDEV(xpd).span, 0, sizeof(struct dahdi_span)); for (i = 0; i < cn; i++) @@ -1022,9 +1060,9 @@ static void xpd_init_span(xpd_t *xpd, unsigned offset, int cn) int xpd_dahdi_preregister(xpd_t *xpd, unsigned offset) { - xbus_t *xbus; - int cn; - struct phonedev *phonedev; + xbus_t *xbus; + int cn; + struct phonedev *phonedev; BUG_ON(!xpd); @@ -1052,7 +1090,7 @@ int xpd_dahdi_preregister(xpd_t *xpd, unsigned offset) int xpd_dahdi_postregister(xpd_t *xpd) { - int cn; + int cn; atomic_inc(&num_registered_spans); atomic_inc(&PHONEDEV(xpd).dahdi_registered); @@ -1093,9 +1131,11 @@ void xpd_dahdi_preunregister(xpd_t *xpd) int j; dahdi_alarm_notify(&PHONEDEV(xpd).span); - XPD_DBG(DEVICES, xpd, "Queuing DAHDI_EVENT_REMOVED on all channels to ask user to release them\n"); - for (j=0; j -extern struct proc_dir_entry *xpp_proc_toplevel; +extern struct proc_dir_entry *xpp_proc_toplevel; #endif #define SPAN_REGISTERED(xpd) atomic_read(&PHONEDEV(xpd).dahdi_registered) -#endif /* XPP_DAHDI_H */ +#endif /* XPP_DAHDI_H */ diff --git a/drivers/dahdi/xpp/xpp_usb.c b/drivers/dahdi/xpp/xpp_usb.c index ef6d09e..f87c865 100644 --- a/drivers/dahdi/xpp/xpp_usb.c +++ b/drivers/dahdi/xpp/xpp_usb.c @@ -47,11 +47,11 @@ static const char rcsid[] = "$Id$"; static DEF_PARM(int, debug, 0, 0644, "Print DBG statements"); /* must be before dahdi_debug.h */ static DEF_PARM(int, usb1, 0, 0644, "Allow using USB 1.1 interfaces"); static DEF_PARM(uint, tx_sluggish, 2000, 0644, "A sluggish transmit (usec)"); -static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggish to drop a PCM frame"); +static DEF_PARM(uint, drop_pcm_after, 6, 0644, + "Number of consecutive tx_sluggish to drop a PCM frame"); #include "dahdi_debug.h" - #define XUSB_PRINTK(level, xusb, fmt, ...) \ printk(KERN_ ## level "%s-%s: xusb-%d (%s) [%s]: " fmt, #level, \ THIS_MODULE->name, (xusb)->index, xusb->path, xusb->serial, ## __VA_ARGS__) @@ -65,7 +65,7 @@ static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggis /* FIXME: A flag that was deprecated at some point, and rather useless */ /* anyway. Only used in the code or-ed to other flags */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14) -# define URB_ASYNC_UNLINK 0 +#define URB_ASYNC_UNLINK 0 #endif /* Get a minor range for your devices from the usb maintainer */ #define USB_SKEL_MINOR_BASE 192 @@ -75,23 +75,23 @@ static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggis #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0) -# warning "This module is tested only with 2.6 kernels" +#warning "This module is tested only with 2.6 kernels" #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) -# define usb_alloc_coherent(dev, size, mem_flags, dma) \ +#define usb_alloc_coherent(dev, size, mem_flags, dma) \ usb_buffer_alloc(dev, size, mem_flags, dma) -# define usb_free_coherent(dev, size, addr, dma) \ +#define usb_free_coherent(dev, size, addr, dma) \ usb_buffer_free(dev, size, addr, dma) #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 12) -# undef USB_FIELDS_MISSING +#undef USB_FIELDS_MISSING #else -# define USB_FIELDS_MISSING +#define USB_FIELDS_MISSING -# define USB_MAX_STRING 128 -# define USB_GET_STRING(udev, field, buf) \ +#define USB_MAX_STRING 128 +#define USB_GET_STRING(udev, field, buf) \ do { \ if ((udev)->descriptor.field) { \ char tmp[USB_MAX_STRING]; \ @@ -99,7 +99,7 @@ static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggis snprintf((buf), USB_MAX_STRING, "%s", tmp); \ } \ } while (0); -# define USB_GET_IFACE_NAME(udev, iface, buf) \ +#define USB_GET_IFACE_NAME(udev, iface, buf) \ do { \ if ((iface)->desc.iInterface) { \ char tmp[USB_MAX_STRING]; \ @@ -110,16 +110,16 @@ static DEF_PARM(uint, drop_pcm_after, 6, 0644, "Number of consecutive tx_sluggis #endif #ifdef DEBUG_PCM_TIMING -static cycles_t stamp_last_pcm_read; +static cycles_t stamp_last_pcm_read; static cycles_t accumulate_diff; #endif struct xusb_model_info; struct xusb_endpoint { - int ep_addr; - int max_size; - usb_complete_t callback; + int ep_addr; + int max_size; + usb_complete_t callback; }; enum xusb_dir { @@ -132,7 +132,7 @@ static __must_check int xframe_send_cmd(xbus_t *xbus, xframe_t *xframe); static __must_check xframe_t *alloc_xframe(xbus_t *xbus, gfp_t flags); static void free_xframe(xbus_t *xbus, xframe_t *frm); -static struct xbus_ops xusb_ops = { +static struct xbus_ops xusb_ops = { .xframe_send_pcm = xframe_send_pcm, .xframe_send_cmd = xframe_send_cmd, .alloc_xframe = alloc_xframe, @@ -152,14 +152,10 @@ enum { #define C_(x) [ XUSB_N_ ## x ] = { #x } static struct xusb_counters { - char *name; + char *name; } xusb_counters[] = { - C_(RX_FRAMES), - C_(TX_FRAMES), - C_(RX_ERRORS), - C_(TX_ERRORS), - C_(RCV_ZERO_LEN), -}; +C_(RX_FRAMES), C_(TX_FRAMES), C_(RX_ERRORS), C_(TX_ERRORS), + C_(RCV_ZERO_LEN),}; #undef C_ @@ -167,9 +163,9 @@ static struct xusb_counters { #define MAX_PENDING_WRITES 100 -static KMEM_CACHE_T *xusb_cache; +static KMEM_CACHE_T *xusb_cache; -typedef struct xusb xusb_t; +typedef struct xusb xusb_t; /* * A uframe is our low level representation of a frame. @@ -180,13 +176,13 @@ typedef struct xusb xusb_t; * directionality (send/receive) and ownership (xusb). */ struct uframe { - unsigned long uframe_magic; + unsigned long uframe_magic; #define UFRAME_MAGIC 654321L - struct urb urb; - xframe_t xframe; - size_t transfer_buffer_length; - void *transfer_buffer; /* max XFRAME_DATASIZE */ - xusb_t *xusb; + struct urb urb; + xframe_t xframe; + size_t transfer_buffer_length; + void *transfer_buffer; /* max XFRAME_DATASIZE */ + xusb_t *xusb; }; #define urb_to_uframe(urb) container_of(urb, struct uframe, urb) @@ -201,50 +197,50 @@ struct uframe { * USB XPP Bus (a USB Device) */ struct xusb { - uint xbus_num; - struct usb_device *udev; /* save off the usb device pointer */ - struct usb_interface *interface; /* the interface for this device */ - unsigned char minor; /* the starting minor number for this device */ - uint index; - char path[XBUS_DESCLEN]; /* a unique path */ + uint xbus_num; + struct usb_device *udev; /* save off the usb device pointer */ + struct usb_interface *interface; /* the interface for this device */ + unsigned char minor; /* the starting minor number for this device */ + uint index; + char path[XBUS_DESCLEN]; /* a unique path */ - struct xusb_model_info *model_info; - struct xusb_endpoint endpoints[2]; /* RECV/SEND endpoints */ + struct xusb_model_info *model_info; + struct xusb_endpoint endpoints[2]; /* RECV/SEND endpoints */ - int present; /* if the device is not disconnected */ - atomic_t pending_writes; /* submited but not out yet */ - atomic_t pending_reads; /* submited but not in yet */ - struct semaphore sem; /* locks this structure */ - int counters[XUSB_COUNTER_MAX]; + int present; /* if the device is not disconnected */ + atomic_t pending_writes; /* submited but not out yet */ + atomic_t pending_reads; /* submited but not in yet */ + struct semaphore sem; /* locks this structure */ + int counters[XUSB_COUNTER_MAX]; /* metrics */ - struct timeval last_tx; - unsigned int max_tx_delay; - uint usb_tx_delay[NUM_BUCKETS]; - uint sluggish_debounce; - bool drop_next_pcm; /* due to sluggishness */ - atomic_t pcm_tx_drops; - atomic_t usb_sluggish_count; + struct timeval last_tx; + unsigned int max_tx_delay; + uint usb_tx_delay[NUM_BUCKETS]; + uint sluggish_debounce; + bool drop_next_pcm; /* due to sluggishness */ + atomic_t pcm_tx_drops; + atomic_t usb_sluggish_count; #ifdef USB_FIELDS_MISSING /* storage for missing strings in old kernels */ - char manufacturer[USB_MAX_STRING]; - char product[USB_MAX_STRING]; - char serial[USB_MAX_STRING]; - char interface_name[USB_MAX_STRING]; + char manufacturer[USB_MAX_STRING]; + char product[USB_MAX_STRING]; + char serial[USB_MAX_STRING]; + char interface_name[USB_MAX_STRING]; #else - const char *manufacturer; - const char *product; - const char *serial; - const char *interface_name; + const char *manufacturer; + const char *product; + const char *serial; + const char *interface_name; #endif }; static DEFINE_SPINLOCK(xusb_lock); -static xusb_t *xusb_array[MAX_BUSES] = {}; -static unsigned bus_count; +static xusb_t *xusb_array[MAX_BUSES] = { }; +static unsigned bus_count; /* prevent races between open() and disconnect() */ static DEFINE_SEMAPHORE(disconnect_sem); @@ -263,10 +259,12 @@ static DEFINE_SEMAPHORE(disconnect_sem); static void xpp_send_callback(USB_PASS_CB(urb)); static void xpp_receive_callback(USB_PASS_CB(urb)); -static int xusb_probe (struct usb_interface *interface, const struct usb_device_id *id); -static void xusb_disconnect (struct usb_interface *interface); +static int xusb_probe(struct usb_interface *interface, + const struct usb_device_id *id); +static void xusb_disconnect(struct usb_interface *interface); #ifdef CONFIG_PROC_FS -static int xusb_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data); +static int xusb_read_proc(char *page, char **start, off_t off, int count, + int *eof, void *data); #endif /*------------------------------------------------------------------*/ @@ -276,29 +274,30 @@ static int xusb_read_proc(char *page, char **start, off_t off, int count, int *e */ static void uframe_recompute(struct uframe *uframe, enum xusb_dir dir) { - struct urb *urb = &uframe->urb; - xusb_t *xusb = uframe->xusb; - struct usb_device *udev = xusb->udev; - struct xusb_endpoint *xusb_ep = &xusb->endpoints[dir]; - unsigned int ep_addr = xusb_ep->ep_addr; - usb_complete_t urb_cb = xusb_ep->callback; - unsigned int epnum = ep_addr & USB_ENDPOINT_NUMBER_MASK; - int pipe = usb_pipein(ep_addr) - ? usb_rcvbulkpipe(udev, epnum) - : usb_sndbulkpipe(udev, epnum); + struct urb *urb = &uframe->urb; + xusb_t *xusb = uframe->xusb; + struct usb_device *udev = xusb->udev; + struct xusb_endpoint *xusb_ep = &xusb->endpoints[dir]; + unsigned int ep_addr = xusb_ep->ep_addr; + usb_complete_t urb_cb = xusb_ep->callback; + unsigned int epnum = ep_addr & USB_ENDPOINT_NUMBER_MASK; + int pipe = usb_pipein(ep_addr) + ? usb_rcvbulkpipe(udev, epnum) + : usb_sndbulkpipe(udev, epnum); BUG_ON(uframe->uframe_magic != UFRAME_MAGIC); - usb_fill_bulk_urb(urb, udev, pipe, uframe->transfer_buffer, uframe->transfer_buffer_length, urb_cb, uframe); + usb_fill_bulk_urb(urb, udev, pipe, uframe->transfer_buffer, + uframe->transfer_buffer_length, urb_cb, uframe); urb->transfer_flags = (URB_NO_TRANSFER_DMA_MAP | URB_ASYNC_UNLINK); } static xframe_t *alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) { - struct uframe *uframe; - xusb_t *xusb; - void *p; - int size; - static int rate_limit; + struct uframe *uframe; + xusb_t *xusb; + void *p; + int size; + static int rate_limit; BUG_ON(!xbus); xusb = xusb_of(xbus); @@ -306,21 +305,27 @@ static xframe_t *alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) if (!xusb->present) { if ((rate_limit++ % 1003) == 0) XUSB_ERR(xusb, - "abort allocations during device disconnect (%d)\n", rate_limit); + "abort allocations during device disconnect (%d)\n", + rate_limit); return NULL; } - size = min(xusb->endpoints[XUSB_SEND].max_size, xusb->endpoints[XUSB_RECV].max_size); + size = + min(xusb->endpoints[XUSB_SEND].max_size, + xusb->endpoints[XUSB_RECV].max_size); uframe = kmem_cache_alloc(xusb_cache, gfp_flags); if (!uframe) { if ((rate_limit++ % 1003) == 0) - XUSB_ERR(xusb, "frame allocation failed (%d)\n", rate_limit); + XUSB_ERR(xusb, "frame allocation failed (%d)\n", + rate_limit); return NULL; } usb_init_urb(&uframe->urb); - p = usb_alloc_coherent(xusb->udev, size, gfp_flags, &uframe->urb.transfer_dma); + p = usb_alloc_coherent(xusb->udev, size, gfp_flags, + &uframe->urb.transfer_dma); if (!p) { if ((rate_limit++ % 1003) == 0) - XUSB_ERR(xusb, "buffer allocation failed (%d)\n", rate_limit); + XUSB_ERR(xusb, "buffer allocation failed (%d)\n", + rate_limit); kmem_cache_free(xusb_cache, uframe); return NULL; } @@ -328,20 +333,20 @@ static xframe_t *alloc_xframe(xbus_t *xbus, gfp_t gfp_flags) uframe->transfer_buffer_length = size; uframe->transfer_buffer = p; uframe->xusb = xusb; - xframe_init(xbus, &uframe->xframe, uframe->transfer_buffer, uframe->transfer_buffer_length, uframe); + xframe_init(xbus, &uframe->xframe, uframe->transfer_buffer, + uframe->transfer_buffer_length, uframe); return &uframe->xframe; } static void free_xframe(xbus_t *xbus, xframe_t *xframe) { - struct uframe *uframe = xframe_to_uframe(xframe); - struct urb *urb = &uframe->urb; + struct uframe *uframe = xframe_to_uframe(xframe); + struct urb *urb = &uframe->urb; BUG_ON(xbus->transport.priv != uframe->xusb); //XUSB_INFO(uframe->xusb, "frame_free\n"); usb_free_coherent(urb->dev, uframe->transfer_buffer_length, - urb->transfer_buffer, - urb->transfer_dma); + urb->transfer_buffer, urb->transfer_dma); memset(uframe, 0, sizeof(*uframe)); kmem_cache_free(xusb_cache, uframe); } @@ -353,21 +358,22 @@ static void free_xframe(xbus_t *xbus, xframe_t *xframe) */ static int do_send_xframe(xbus_t *xbus, xframe_t *xframe) { - struct urb *urb; - xusb_t *xusb; - int ret = 0; - struct uframe *uframe; + struct urb *urb; + xusb_t *xusb; + int ret = 0; + struct uframe *uframe; BUG_ON(!xframe); BUG_ON(xframe->xframe_magic != XFRAME_MAGIC); xusb = xusb_of(xbus); BUG_ON(!xusb); if (!xusb->present) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) XUSB_ERR(xusb, - "abort do_send_xframe during device disconnect (%d)\n", rate_limit); + "abort do_send_xframe during device disconnect (%d)\n", + rate_limit); ret = -ENODEV; goto failure; } @@ -375,12 +381,12 @@ static int do_send_xframe(xbus_t *xbus, xframe_t *xframe) * If something really bad happend, do not overflow the USB stack */ if (atomic_read(&xusb->pending_writes) > MAX_PENDING_WRITES) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 5000) == 0) XUSB_ERR(xusb, - "USB device is totaly stuck. Dropping packets (#%d).\n", - rate_limit); + "USB device is totaly stuck. Dropping packets (#%d).\n", + rate_limit); ret = -ENODEV; goto failure; } @@ -399,12 +405,12 @@ static int do_send_xframe(xbus_t *xbus, xframe_t *xframe) if ((rate_limit++ % 1000) == 0) XBUS_ERR(xbus, "%s: usb_submit_urb failed: %d\n", - __func__, ret); + __func__, ret); ret = -EBADF; goto failure; } -// if (debug) -// dump_xframe("USB_FRAME_SEND", xbus, xframe, debug); +// if (debug) +// dump_xframe("USB_FRAME_SEND", xbus, xframe, debug); atomic_inc(&xusb->pending_writes); return 0; failure: @@ -418,7 +424,7 @@ failure: */ static int xframe_send_pcm(xbus_t *xbus, xframe_t *xframe) { - xusb_t *xusb; + xusb_t *xusb; BUG_ON(!xbus); BUG_ON(!xframe); @@ -448,10 +454,10 @@ static int xframe_send_cmd(xbus_t *xbus, xframe_t *xframe) */ static bool xusb_listen(xusb_t *xusb) { - xbus_t *xbus = xbus_num(xusb->xbus_num); - xframe_t *xframe; - struct uframe *uframe; - int ret = 0; + xbus_t *xbus = xbus_num(xusb->xbus_num); + xframe_t *xframe; + struct uframe *uframe; + int ret = 0; BUG_ON(!xbus); xframe = ALLOC_RECV_XFRAME(xbus); @@ -467,7 +473,7 @@ static bool xusb_listen(xusb_t *xusb) if ((rate_limit++ % 1000) == 0) XBUS_ERR(xbus, "%s: usb_submit_urb failed: %d\n", - __func__, ret); + __func__, ret); FREE_RECV_XFRAME(xbus, xframe); goto out; } @@ -484,40 +490,36 @@ enum XUSB_MODELS { }; static const struct xusb_model_info { - const char *desc; - int iface_num; - struct xusb_endpoint in; - struct xusb_endpoint out; + const char *desc; + int iface_num; + struct xusb_endpoint in; + struct xusb_endpoint out; } model_table[] = { [MODEL_FPGA_XPD] = { - .iface_num = 0, - .in = { .ep_addr = 0x86 }, - .out = { .ep_addr = 0x02 }, - .desc = "FPGA_XPD" - }, -}; + .iface_num = 0,.in = { + .ep_addr = 0x86},.out = { +.ep_addr = 0x02},.desc = "FPGA_XPD"},}; /* table of devices that work with this driver */ -static const struct usb_device_id xusb_table [] = { - { USB_DEVICE(0xE4E4, 0x1132), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_FXS - { USB_DEVICE(0xE4E4, 0x1142), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_1141 - { USB_DEVICE(0xE4E4, 0x1152), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_1151 - { USB_DEVICE(0xE4E4, 0x1162), .driver_info=(kernel_ulong_t)&model_table[MODEL_FPGA_XPD] }, // FPGA_1161 - { } /* Terminating entry */ +static const struct usb_device_id xusb_table[] = { + {USB_DEVICE(0xE4E4, 0x1132),.driver_info = (kernel_ulong_t) & model_table[MODEL_FPGA_XPD]}, // FPGA_FXS + {USB_DEVICE(0xE4E4, 0x1142),.driver_info = (kernel_ulong_t) & model_table[MODEL_FPGA_XPD]}, // FPGA_1141 + {USB_DEVICE(0xE4E4, 0x1152),.driver_info = (kernel_ulong_t) & model_table[MODEL_FPGA_XPD]}, // FPGA_1151 + {USB_DEVICE(0xE4E4, 0x1162),.driver_info = (kernel_ulong_t) & model_table[MODEL_FPGA_XPD]}, // FPGA_1161 + {} /* Terminating entry */ }; -MODULE_DEVICE_TABLE (usb, xusb_table); - +MODULE_DEVICE_TABLE(usb, xusb_table); /* usb specific object needed to register this driver with the usb subsystem */ static struct usb_driver xusb_driver = { #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16) - .owner = THIS_MODULE, + .owner = THIS_MODULE, #endif - .name = "xpp_usb", - .probe = xusb_probe, - .disconnect = xusb_disconnect, - .id_table = xusb_table, + .name = "xpp_usb", + .probe = xusb_probe, + .disconnect = xusb_disconnect, + .id_table = xusb_table, }; /* @@ -539,7 +541,7 @@ static struct file_operations xusb_fops = { * the use-counter again before calling release() * or should the open() function fail. */ - .owner = THIS_MODULE, + .owner = THIS_MODULE, }; /* @@ -547,13 +549,13 @@ static struct file_operations xusb_fops = { * and to have the device registered with devfs and the driver core */ static struct usb_class_driver xusb_class = { - .name = "usb/xpp_usb%d", - .fops = &xusb_fops, + .name = "usb/xpp_usb%d", + .fops = &xusb_fops, /* FIXME: The sysfs class interfase seems to have chaged around here */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15) - .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, + .mode = S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, #endif - .minor_base = USB_SKEL_MINOR_BASE, + .minor_base = USB_SKEL_MINOR_BASE, }; /* @@ -568,18 +570,21 @@ static struct usb_class_driver xusb_class = { */ static int check_usb1(struct usb_endpoint_descriptor *endpoint) { - const char *msg = (usb_pipein(endpoint->bEndpointAddress))?"input":"output"; + const char *msg = + (usb_pipein(endpoint->bEndpointAddress)) ? "input" : "output"; if (endpoint->wMaxPacketSize >= sizeof(xpacket_t)) return 1; if (usb1) { - NOTICE("USB1 endpoint detected: USB %s endpoint 0x%X support only wMaxPacketSize=%d.\n", - msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize); + NOTICE + ("USB1 endpoint detected: USB %s endpoint 0x%X support only wMaxPacketSize=%d.\n", + msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize); return 1; } - NOTICE("USB1 endpoint detected. Device disabled. To enable: usb1=1, and read docs. (%s, endpoint %d, size %d).\n", - msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize); + NOTICE + ("USB1 endpoint detected. Device disabled. To enable: usb1=1, and read docs. (%s, endpoint %d, size %d).\n", + msg, endpoint->bEndpointAddress, endpoint->wMaxPacketSize); return 0; } @@ -588,11 +593,12 @@ static int check_usb1(struct usb_endpoint_descriptor *endpoint) * check out the endpoints * FIXME: Should be simplified (above 2.6.10) to use usb_dev->ep_in[0..16] and usb_dev->ep_out[0..16] */ -static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, struct xusb_model_info *model_info) +static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, + struct xusb_model_info *model_info) { - struct usb_endpoint_descriptor *endpoint; - struct xusb_endpoint *xusb_ep; - int ep_addr; + struct usb_endpoint_descriptor *endpoint; + struct xusb_endpoint *xusb_ep; + int ep_addr; int i; #define BULK_ENDPOINT(ep) (((ep)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) @@ -602,8 +608,9 @@ static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, st ep_addr = endpoint->bEndpointAddress; if (!BULK_ENDPOINT(endpoint)) { - DBG(DEVICES, "endpoint 0x%x is not bulk: mbAttributes=0x%X\n", - ep_addr, endpoint->bmAttributes); + DBG(DEVICES, + "endpoint 0x%x is not bulk: mbAttributes=0x%X\n", + ep_addr, endpoint->bmAttributes); continue; } if (usb_pipein(ep_addr)) { // Input @@ -615,7 +622,7 @@ static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, st xusb_ep->max_size = endpoint->wMaxPacketSize; xusb_ep->callback = xpp_receive_callback; } - } else { // Output + } else { // Output if (ep_addr == model_info->out.ep_addr) { if (!check_usb1(endpoint)) return 0; @@ -626,11 +633,14 @@ static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, st } } } - if (!xusb->endpoints[XUSB_RECV].ep_addr || !xusb->endpoints[XUSB_SEND].ep_addr) { + if (!xusb->endpoints[XUSB_RECV].ep_addr + || !xusb->endpoints[XUSB_SEND].ep_addr) { XUSB_ERR(xusb, "Couldn't find bulk-in or bulk-out endpoints\n"); return 0; } - DBG(DEVICES, "in=0x%02X out=0x%02X\n", xusb->endpoints[XUSB_RECV].ep_addr, xusb->endpoints[XUSB_SEND].ep_addr); + DBG(DEVICES, "in=0x%02X out=0x%02X\n", + xusb->endpoints[XUSB_RECV].ep_addr, + xusb->endpoints[XUSB_SEND].ep_addr); return 1; } @@ -651,24 +661,27 @@ static int set_endpoints(xusb_t *xusb, struct usb_host_interface *iface_desc, st * Called by the usb core when a new device is connected that it thinks * this driver might be interested in. */ -static int xusb_probe(struct usb_interface *interface, const struct usb_device_id *id) +static int xusb_probe(struct usb_interface *interface, + const struct usb_device_id *id) { - struct usb_device *udev = interface_to_usbdev(interface); - struct usb_host_interface *iface_desc = usb_altnum_to_altsetting(interface, 0); - xusb_t *xusb = NULL; - struct xusb_model_info *model_info = (struct xusb_model_info*)id->driver_info; + struct usb_device *udev = interface_to_usbdev(interface); + struct usb_host_interface *iface_desc = + usb_altnum_to_altsetting(interface, 0); + xusb_t *xusb = NULL; + struct xusb_model_info *model_info = + (struct xusb_model_info *)id->driver_info; #ifdef CONFIG_PROC_FS - struct proc_dir_entry *procsummary = NULL; + struct proc_dir_entry *procsummary = NULL; #endif - xbus_t *xbus = NULL; - unsigned long flags; - int retval = -ENOMEM; - int i; + xbus_t *xbus = NULL; + unsigned long flags; + int retval = -ENOMEM; + int i; DBG(DEVICES, "New XUSB device MODEL=%s\n", model_info->desc); if (iface_desc->desc.bInterfaceNumber != model_info->iface_num) { DBG(DEVICES, "Skip interface #%d != #%d\n", - iface_desc->desc.bInterfaceNumber, model_info->iface_num); + iface_desc->desc.bInterfaceNumber, model_info->iface_num); return -ENODEV; } if ((retval = DO_USB_RESET_DEVICE(udev)) < 0) { @@ -677,7 +690,7 @@ static int xusb_probe(struct usb_interface *interface, const struct usb_device_i } if (!model_info) { ERR("Missing endpoint setup for this device %d:%d\n", - udev->descriptor.idVendor, udev->descriptor.idProduct); + udev->descriptor.idVendor, udev->descriptor.idProduct); retval = -ENODEV; goto probe_failed; } @@ -713,18 +726,18 @@ static int xusb_probe(struct usb_interface *interface, const struct usb_device_i USB_GET_STRING(udev, iProduct, xusb->product); USB_GET_IFACE_NAME(udev, iface_desc, xusb->interface_name); #endif - INFO("XUSB: %s -- %s -- %s\n", - xusb->manufacturer, xusb->product, xusb->interface_name); + INFO("XUSB: %s -- %s -- %s\n", xusb->manufacturer, xusb->product, + xusb->interface_name); /* allow device read, write and ioctl */ xusb->present = 1; /* we can register the device now, as it is ready */ usb_set_intfdata(interface, xusb); - retval = usb_register_dev (interface, &xusb_class); + retval = usb_register_dev(interface, &xusb_class); if (retval) { /* something prevented us from registering this driver */ - ERR ("Not able to get a minor for this device.\n"); + ERR("Not able to get a minor for this device.\n"); goto probe_failed; } @@ -732,17 +745,19 @@ static int xusb_probe(struct usb_interface *interface, const struct usb_device_i /* let the user know what node this device is now attached to */ DBG(DEVICES, "USB XPP device now attached to minor %d\n", xusb->minor); - xbus = xbus_new(&xusb_ops, min(xusb->endpoints[XUSB_SEND].max_size, xusb->endpoints[XUSB_RECV].max_size), &udev->dev, xusb); + xbus = + xbus_new(&xusb_ops, + min(xusb->endpoints[XUSB_SEND].max_size, + xusb->endpoints[XUSB_RECV].max_size), &udev->dev, + xusb); if (!xbus) { retval = -ENOMEM; goto probe_failed; } snprintf(xbus->transport.model_string, - ARRAY_SIZE(xbus->transport.model_string), - "usb:%04x/%04x/%x", - udev->descriptor.idVendor, - udev->descriptor.idProduct, - udev->descriptor.bcdDevice); + ARRAY_SIZE(xbus->transport.model_string), "usb:%04x/%04x/%x", + udev->descriptor.idVendor, udev->descriptor.idProduct, + udev->descriptor.bcdDevice); spin_lock_irqsave(&xusb_lock, flags); for (i = 0; i < MAX_BUSES; i++) { if (xusb_array[i] == NULL) @@ -763,11 +778,14 @@ static int xusb_probe(struct usb_interface *interface, const struct usb_device_i XUSB_DBG(DEVICES, xusb, "GOT XPP USB BUS: %s\n", xbus->connector); #ifdef CONFIG_PROC_FS - DBG(PROC, "Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n"); - procsummary = create_proc_read_entry(PROC_USBXPP_SUMMARY, 0444, xbus->proc_xbus_dir, - xusb_read_proc, xusb); + DBG(PROC, + "Creating proc entry " PROC_USBXPP_SUMMARY " in bus proc dir.\n"); + procsummary = + create_proc_read_entry(PROC_USBXPP_SUMMARY, 0444, + xbus->proc_xbus_dir, xusb_read_proc, xusb); if (!procsummary) { - XBUS_ERR(xbus, "Failed to create proc file '%s'\n", PROC_USBXPP_SUMMARY); + XBUS_ERR(xbus, "Failed to create proc file '%s'\n", + PROC_USBXPP_SUMMARY); // FIXME: better error handling retval = -EIO; goto probe_failed; @@ -778,7 +796,7 @@ static int xusb_probe(struct usb_interface *interface, const struct usb_device_i xusb->xbus_num = xbus->num; /* prepare several pending frames for receive side */ for (i = 0; i < 10; i++) - xusb_listen(xusb); + xusb_listen(xusb); xbus_connect(xbus); return retval; probe_failed: @@ -795,13 +813,16 @@ probe_failed: if (xbus) { #ifdef CONFIG_PROC_FS if (procsummary) { - XBUS_DBG(PROC, xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); - remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir); + XBUS_DBG(PROC, xbus, + "Remove proc_entry: " PROC_USBXPP_SUMMARY + "\n"); + remove_proc_entry(PROC_USBXPP_SUMMARY, + xbus->proc_xbus_dir); procsummary = NULL; } #endif ERR("Calling xbus_disconnect()\n"); - xbus_disconnect(xbus); // Blocking until fully deactivated! + xbus_disconnect(xbus); // Blocking until fully deactivated! } return retval; } @@ -819,14 +840,16 @@ probe_failed: */ static void xusb_disconnect(struct usb_interface *interface) { - struct usb_host_interface *iface_desc = usb_altnum_to_altsetting(interface, 0); - xusb_t *xusb; - xbus_t *xbus; - int i; + struct usb_host_interface *iface_desc = + usb_altnum_to_altsetting(interface, 0); + xusb_t *xusb; + xbus_t *xbus; + int i; - DBG(DEVICES, "CALLED on interface #%d\n", iface_desc->desc.bInterfaceNumber); + DBG(DEVICES, "CALLED on interface #%d\n", + iface_desc->desc.bInterfaceNumber); /* prevent races with open() */ - down (&disconnect_sem); + down(&disconnect_sem); xusb = usb_get_intfdata(interface); usb_set_intfdata(interface, NULL); @@ -843,38 +866,40 @@ static void xusb_disconnect(struct usb_interface *interface) #ifdef CONFIG_PROC_FS if (xbus->proc_xbus_dir) { - XBUS_DBG(PROC, xbus, "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); + XBUS_DBG(PROC, xbus, + "Remove proc_entry: " PROC_USBXPP_SUMMARY "\n"); remove_proc_entry(PROC_USBXPP_SUMMARY, xbus->proc_xbus_dir); } #endif - xbus_disconnect(xbus); // Blocking until fully deactivated! + xbus_disconnect(xbus); // Blocking until fully deactivated! - down (&xusb->sem); + down(&xusb->sem); /* give back our minor */ usb_deregister_dev(interface, &xusb_class); - up (&xusb->sem); + up(&xusb->sem); DBG(DEVICES, "Semaphore released\n"); XUSB_INFO(xusb, "now disconnected\n"); KZFREE(xusb); - up (&disconnect_sem); + up(&disconnect_sem); } static void xpp_send_callback(USB_PASS_CB(urb)) { - struct uframe *uframe = urb_to_uframe(urb); - xframe_t *xframe = &uframe->xframe; - xusb_t *xusb = uframe->xusb; - xbus_t *xbus = xbus_num(xusb->xbus_num); - struct timeval now; - long usec; - int writes = atomic_read(&xusb->pending_writes); - int i; + struct uframe *uframe = urb_to_uframe(urb); + xframe_t *xframe = &uframe->xframe; + xusb_t *xusb = uframe->xusb; + xbus_t *xbus = xbus_num(xusb->xbus_num); + struct timeval now; + long usec; + int writes = atomic_read(&xusb->pending_writes); + int i; if (!xbus) { - XUSB_ERR(xusb, "Sent URB does not belong to a valid xbus anymore...\n"); + XUSB_ERR(xusb, + "Sent URB does not belong to a valid xbus anymore...\n"); return; } //flip_parport_bit(6); @@ -891,12 +916,12 @@ static void xpp_send_callback(USB_PASS_CB(urb)) if (unlikely(usec > tx_sluggish)) { atomic_inc(&xusb->usb_sluggish_count); if (xusb->sluggish_debounce++ > drop_pcm_after) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 500) /* skip first messages */ XUSB_NOTICE(xusb, - "Sluggish USB. Dropping next PCM frame (pending_writes=%d)\n", - writes); + "Sluggish USB. Dropping next PCM frame (pending_writes=%d)\n", + writes); atomic_inc(&xusb->pcm_tx_drops); xusb->drop_next_pcm = 1; xusb->sluggish_debounce = 0; @@ -904,12 +929,13 @@ static void xpp_send_callback(USB_PASS_CB(urb)) } else xusb->sluggish_debounce = 0; /* sync/async unlink faults aren't errors */ - if (urb->status && !(urb->status == -ENOENT || urb->status == -ECONNRESET)) { - static int rate_limit; + if (urb->status + && !(urb->status == -ENOENT || urb->status == -ECONNRESET)) { + static int rate_limit; if ((rate_limit++ % 1000) < 10) { XUSB_ERR(xusb, - "nonzero write bulk status received: %d (pending_writes=%d)\n", - urb->status, writes); + "nonzero write bulk status received: %d (pending_writes=%d)\n", + urb->status, writes); dump_xframe("usb-write-error", xbus, xframe, DBG_ANY); } XUSB_COUNTER(xusb, TX_ERRORS)++; @@ -922,18 +948,19 @@ static void xpp_send_callback(USB_PASS_CB(urb)) static void xpp_receive_callback(USB_PASS_CB(urb)) { - struct uframe *uframe = urb_to_uframe(urb); - xframe_t *xframe = &uframe->xframe; - xusb_t *xusb = uframe->xusb; - xbus_t *xbus = xbus_num(xusb->xbus_num); - size_t size; - bool do_resubmit = 1; - struct timeval now; + struct uframe *uframe = urb_to_uframe(urb); + xframe_t *xframe = &uframe->xframe; + xusb_t *xusb = uframe->xusb; + xbus_t *xbus = xbus_num(xusb->xbus_num); + size_t size; + bool do_resubmit = 1; + struct timeval now; do_gettimeofday(&now); atomic_dec(&xusb->pending_reads); if (!xbus) { - XUSB_ERR(xusb, "Received URB does not belong to a valid xbus anymore...\n"); + XUSB_ERR(xusb, + "Received URB does not belong to a valid xbus anymore...\n"); return; } if (!xusb->present) { @@ -941,24 +968,26 @@ static void xpp_receive_callback(USB_PASS_CB(urb)) goto err; } if (urb->status) { - DBG(GENERAL, "nonzero read bulk status received: %d\n", urb->status); + DBG(GENERAL, "nonzero read bulk status received: %d\n", + urb->status); XUSB_COUNTER(xusb, RX_ERRORS)++; goto err; } size = urb->actual_length; if (size == 0) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 5003) == 0) - XUSB_NOTICE(xusb, "Received a zero length URBs (%d)\n", rate_limit); + XUSB_NOTICE(xusb, "Received a zero length URBs (%d)\n", + rate_limit); XUSB_COUNTER(xusb, RCV_ZERO_LEN)++; goto err; } atomic_set(&xframe->frame_len, size); xframe->tv_received = now; -// if (debug) -// dump_xframe("USB_FRAME_RECEIVE", xbus, xframe, debug); +// if (debug) +// dump_xframe("USB_FRAME_RECEIVE", xbus, xframe, debug); XUSB_COUNTER(xusb, RX_FRAMES)++; /* Send UP */ xbus_receive_xframe(xbus, xframe); @@ -971,7 +1000,6 @@ err: goto end; } - /*------------------------- Initialization -------------------------*/ static void xpp_usb_cleanup(void) @@ -984,21 +1012,21 @@ static void xpp_usb_cleanup(void) static int __init xpp_usb_init(void) { - int ret; + int ret; //xusb_t *xusb; INFO("revision %s\n", XPP_VERSION); - xusb_cache = kmem_cache_create("xusb_cache", - sizeof(xframe_t) + XFRAME_DATASIZE, + xusb_cache = + kmem_cache_create("xusb_cache", sizeof(xframe_t) + XFRAME_DATASIZE, #if (LINUX_VERSION_CODE == KERNEL_VERSION(2, 6, 22)) && defined(CONFIG_SLUB) - 0, SLAB_STORE_USER, + 0, SLAB_STORE_USER, #else - 0, 0, + 0, 0, #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) - NULL, + NULL, #endif - NULL); + NULL); if (!xusb_cache) { ret = -ENOMEM; goto failure; @@ -1016,7 +1044,6 @@ failure: return ret; } - static void __exit xpp_usb_shutdown(void) { DBG(GENERAL, "\n"); @@ -1025,71 +1052,81 @@ static void __exit xpp_usb_shutdown(void) xpp_usb_cleanup(); } - - #ifdef CONFIG_PROC_FS -static int xusb_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data) +static int xusb_read_proc(char *page, char **start, off_t off, int count, + int *eof, void *data) { - int len = 0; - unsigned long flags; - int i; + int len = 0; + unsigned long flags; + int i; //unsigned long stamp = jiffies; - xusb_t *xusb = data; - uint usb_tx_delay[NUM_BUCKETS]; - const int mark_limit = tx_sluggish/USEC_BUCKET; + xusb_t *xusb = data; + uint usb_tx_delay[NUM_BUCKETS]; + const int mark_limit = tx_sluggish / USEC_BUCKET; if (!xusb) goto out; // TODO: probably needs a per-xusb lock: spin_lock_irqsave(&xusb_lock, flags); - len += sprintf(page + len, "Device: %03d/%03d\n", - xusb->udev->bus->busnum, - xusb->udev->devnum - ); - len += sprintf(page + len, "USB: manufacturer=%s\n", xusb->manufacturer); + len += + sprintf(page + len, "Device: %03d/%03d\n", xusb->udev->bus->busnum, + xusb->udev->devnum); + len += + sprintf(page + len, "USB: manufacturer=%s\n", xusb->manufacturer); len += sprintf(page + len, "USB: product=%s\n", xusb->product); len += sprintf(page + len, "USB: serial=%s\n", xusb->serial); - len += sprintf(page + len, "Minor: %d\nModel Info: %s\n", - xusb->minor, xusb->model_info->desc); - len += sprintf(page + len, "Endpoints:\n" - "\tIn: 0x%02X - Size: %d)\n" - "\tOut: 0x%02X - Size: %d)\n", - xusb->endpoints[XUSB_RECV].ep_addr, - xusb->endpoints[XUSB_RECV].max_size, - xusb->endpoints[XUSB_SEND].ep_addr, - xusb->endpoints[XUSB_SEND].max_size - ); - len += sprintf(page + len, "\npending_writes=%d\n", atomic_read(&xusb->pending_writes)); - len += sprintf(page + len, "pending_reads=%d\n", atomic_read(&xusb->pending_reads)); + len += + sprintf(page + len, "Minor: %d\nModel Info: %s\n", xusb->minor, + xusb->model_info->desc); + len += + sprintf(page + len, + "Endpoints:\n" "\tIn: 0x%02X - Size: %d)\n" + "\tOut: 0x%02X - Size: %d)\n", + xusb->endpoints[XUSB_RECV].ep_addr, + xusb->endpoints[XUSB_RECV].max_size, + xusb->endpoints[XUSB_SEND].ep_addr, + xusb->endpoints[XUSB_SEND].max_size); + len += + sprintf(page + len, "\npending_writes=%d\n", + atomic_read(&xusb->pending_writes)); + len += + sprintf(page + len, "pending_reads=%d\n", + atomic_read(&xusb->pending_reads)); len += sprintf(page + len, "max_tx_delay=%d\n", xusb->max_tx_delay); xusb->max_tx_delay = 0; #ifdef DEBUG_PCM_TIMING - len += sprintf(page + len, "\nstamp_last_pcm_read=%lld accumulate_diff=%lld\n", stamp_last_pcm_read, accumulate_diff); + len += + sprintf(page + len, + "\nstamp_last_pcm_read=%lld accumulate_diff=%lld\n", + stamp_last_pcm_read, accumulate_diff); #endif memcpy(usb_tx_delay, xusb->usb_tx_delay, sizeof(usb_tx_delay)); - len += sprintf(page + len, "usb_tx_delay[%d,%d,%d]: ", - USEC_BUCKET, BUCKET_START, NUM_BUCKETS); + len += + sprintf(page + len, "usb_tx_delay[%d,%d,%d]: ", USEC_BUCKET, + BUCKET_START, NUM_BUCKETS); for (i = BUCKET_START; i < NUM_BUCKETS; i++) { - len += sprintf(page + len, "%6d ", - usb_tx_delay[i]); + len += sprintf(page + len, "%6d ", usb_tx_delay[i]); if (i == mark_limit) len += sprintf(page + len, "| "); } - len += sprintf(page + len, "\nPCM_TX_DROPS: %5d (sluggish: %d)\n", - atomic_read(&xusb->pcm_tx_drops), - atomic_read(&xusb->usb_sluggish_count) - ); + len += + sprintf(page + len, "\nPCM_TX_DROPS: %5d (sluggish: %d)\n", + atomic_read(&xusb->pcm_tx_drops), + atomic_read(&xusb->usb_sluggish_count) + ); len += sprintf(page + len, "\nCOUNTERS:\n"); for (i = 0; i < XUSB_COUNTER_MAX; i++) { - len += sprintf(page + len, "\t%-15s = %d\n", xusb_counters[i].name, xusb->counters[i]); + len += + sprintf(page + len, "\t%-15s = %d\n", xusb_counters[i].name, + xusb->counters[i]); } #if 0 len += sprintf(page + len, "<-- len=%d\n", len); #endif spin_unlock_irqrestore(&xusb_lock, flags); out: - if (len <= off+count) + if (len <= off + count) *eof = 1; *start = page + off; len -= off; @@ -1103,8 +1140,6 @@ out: #endif - - MODULE_DESCRIPTION("XPP USB Transport Driver"); MODULE_AUTHOR("Oron Peled "); MODULE_LICENSE("GPL"); diff --git a/drivers/dahdi/xpp/xproto.c b/drivers/dahdi/xpp/xproto.c index 1283fba..ba48abf 100644 --- a/drivers/dahdi/xpp/xproto.c +++ b/drivers/dahdi/xpp/xproto.c @@ -30,7 +30,7 @@ static const char rcsid[] = "$Id$"; -extern int debug; +extern int debug; static const xproto_table_t *xprotocol_tables[XPD_TYPE_NOMODULE]; @@ -40,12 +40,14 @@ static const xproto_table_t *xprotocol_tables[XPD_TYPE_NOMODULE]; bool valid_xpd_addr(const struct xpd_addr *addr) { - return ((addr->subunit & ~BITMASK(SUBUNIT_BITS)) == 0) && ((addr->unit & ~BITMASK(UNIT_BITS)) == 0); + return ((addr->subunit & ~BITMASK(SUBUNIT_BITS)) == 0) + && ((addr->unit & ~BITMASK(UNIT_BITS)) == 0); } /*---------------- General Protocol Management ----------------------------*/ -const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, __u8 opcode) +const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, + __u8 opcode) { const xproto_entry_t *xe; @@ -82,11 +84,12 @@ const xproto_table_t *xproto_get(xpd_type_t cardtype) if (cardtype >= XPD_TYPE_NOMODULE) return NULL; xtable = xprotocol_tables[cardtype]; - if (!xtable) { /* Try to load the relevant module */ + if (!xtable) { /* Try to load the relevant module */ int ret = request_module(XPD_TYPE_PREFIX "%d", cardtype); if (ret != 0) { - NOTICE("%s: Failed to load module for type=%d. exit status=%d.\n", - __func__, cardtype, ret); + NOTICE + ("%s: Failed to load module for type=%d. exit status=%d.\n", + __func__, cardtype, ret); /* Drop through: we may be lucky... */ } xtable = xprotocol_tables[cardtype]; @@ -94,10 +97,12 @@ const xproto_table_t *xproto_get(xpd_type_t cardtype) if (xtable) { BUG_ON(!xtable->owner); #ifdef CONFIG_MODULE_UNLOAD - DBG(GENERAL, "%s refcount was %d\n", xtable->name, module_refcount(xtable->owner)); + DBG(GENERAL, "%s refcount was %d\n", xtable->name, + module_refcount(xtable->owner)); #endif if (!try_module_get(xtable->owner)) { - ERR("%s: try_module_get for %s failed.\n", __func__, xtable->name); + ERR("%s: try_module_get for %s failed.\n", __func__, + xtable->name); return NULL; } } @@ -108,7 +113,8 @@ void xproto_put(const xproto_table_t *xtable) { BUG_ON(!xtable); #ifdef CONFIG_MODULE_UNLOAD - DBG(GENERAL, "%s refcount was %d\n", xtable->name, module_refcount(xtable->owner)); + DBG(GENERAL, "%s refcount was %d\n", xtable->name, + module_refcount(xtable->owner)); BUG_ON(module_refcount(xtable->owner) <= 0); #endif module_put(xtable->owner); @@ -123,33 +129,37 @@ xproto_handler_t xproto_card_handler(const xproto_table_t *table, __u8 opcode) return xe->handler; } -void notify_bad_xpd(const char *funcname, xbus_t *xbus, const struct xpd_addr addr, const char *msg) +void notify_bad_xpd(const char *funcname, xbus_t *xbus, + const struct xpd_addr addr, const char *msg) { - XBUS_NOTICE(xbus, "%s: non-existing address (%1d%1d): %s\n", - funcname, addr.unit, addr.subunit, msg); + XBUS_NOTICE(xbus, "%s: non-existing address (%1d%1d): %s\n", funcname, + addr.unit, addr.subunit, msg); } static int packet_process(xbus_t *xbus, xpacket_t *pack) { - __u8 op; - const xproto_entry_t *xe; - xproto_handler_t handler; - xproto_table_t *table; - xpd_t *xpd; - int ret = -EPROTO; + __u8 op; + const xproto_entry_t *xe; + xproto_handler_t handler; + xproto_table_t *table; + xpd_t *xpd; + int ret = -EPROTO; BUG_ON(!pack); if (!valid_xpd_addr(&XPACKET_ADDR(pack))) { if (printk_ratelimit()) { XBUS_NOTICE(xbus, "%s: from %d%d: bad address.\n", - __func__, - XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack)); - dump_packet("packet_process -- bad address", pack, debug); + __func__, XPACKET_ADDR_UNIT(pack), + XPACKET_ADDR_SUBUNIT(pack)); + dump_packet("packet_process -- bad address", pack, + debug); } goto out; } op = XPACKET_OP(pack); - xpd = xpd_byaddr(xbus, XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack)); + xpd = + xpd_byaddr(xbus, XPACKET_ADDR_UNIT(pack), + XPACKET_ADDR_SUBUNIT(pack)); /* XPD may be NULL (e.g: during bus polling */ xe = xproto_global_entry(op); /*-------- Validations -----------*/ @@ -158,28 +168,32 @@ static int packet_process(xbus_t *xbus, xpacket_t *pack) if (!xpd) { if (printk_ratelimit()) { - XBUS_NOTICE(xbus, "%s: from %d%d opcode=0x%02X: no such global command.\n", - __func__, - XPACKET_ADDR_UNIT(pack), XPACKET_ADDR_SUBUNIT(pack), op); - dump_packet("packet_process -- no such global command", pack, 1); + XBUS_NOTICE(xbus, + "%s: from %d%d opcode=0x%02X: no such global command.\n", + __func__, XPACKET_ADDR_UNIT(pack), + XPACKET_ADDR_SUBUNIT(pack), op); + dump_packet + ("packet_process -- no such global command", + pack, 1); } goto out; } xtable = xproto_table(xpd->type); if (!xtable) { if (printk_ratelimit()) - XPD_ERR(xpd, "%s: no protocol table (type=%d)\n", - __func__, - xpd->type); + XPD_ERR(xpd, + "%s: no protocol table (type=%d)\n", + __func__, xpd->type); goto out; } xe = xproto_card_entry(xtable, op); if (!xe) { if (printk_ratelimit()) { - XPD_NOTICE(xpd, "%s: bad command (type=%d,opcode=0x%x)\n", - __func__, - xpd->type, op); - dump_packet("packet_process -- bad command", pack, 1); + XPD_NOTICE(xpd, + "%s: bad command (type=%d,opcode=0x%x)\n", + __func__, xpd->type, op); + dump_packet("packet_process -- bad command", + pack, 1); } goto out; } @@ -189,12 +203,13 @@ static int packet_process(xbus_t *xbus, xpacket_t *pack) if (!table->packet_is_valid(pack)) { if (printk_ratelimit()) { ERR("xpp: %s: wrong size %d for opcode=0x%02X\n", - __func__, XPACKET_LEN(pack), op); - dump_packet("packet_process -- wrong size", pack, debug); + __func__, XPACKET_LEN(pack), op); + dump_packet("packet_process -- wrong size", pack, + debug); } goto out; } - ret = 0; /* All well */ + ret = 0; /* All well */ handler = xe->handler; BUG_ON(!handler); XBUS_COUNTER(xbus, RX_BYTES) += XPACKET_LEN(pack); @@ -205,11 +220,11 @@ out: static int xframe_receive_cmd(xbus_t *xbus, xframe_t *xframe) { - __u8 *xframe_end; - xpacket_t *pack; - __u8 *p; - int len; - int ret; + __u8 *xframe_end; + xpacket_t *pack; + __u8 *p; + int len; + int ret; if (debug & DBG_COMMANDS) dump_xframe("RX-CMD", xbus, xframe, DBG_ANY); @@ -220,21 +235,24 @@ static int xframe_receive_cmd(xbus_t *xbus, xframe_t *xframe) len = XPACKET_LEN(pack); /* Sanity checks */ if (unlikely(XPACKET_OP(pack) == XPROTO_NAME(GLOBAL, PCM_READ))) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) { - XBUS_DBG(GENERAL, xbus, "A PCM packet within a Non-PCM xframe\n"); - dump_xframe("In Non-PCM xframe", xbus, xframe, debug); + XBUS_DBG(GENERAL, xbus, + "A PCM packet within a Non-PCM xframe\n"); + dump_xframe("In Non-PCM xframe", xbus, xframe, + debug); } ret = -EPROTO; goto out; } p += len; if (p > xframe_end || len < RPACKET_HEADERSIZE) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) { - XBUS_NOTICE(xbus, "Invalid packet length %d\n", len); + XBUS_NOTICE(xbus, "Invalid packet length %d\n", + len); dump_xframe("BAD LENGTH", xbus, xframe, debug); } ret = -EPROTO; @@ -251,13 +269,13 @@ out: int xframe_receive(xbus_t *xbus, xframe_t *xframe) { - int ret = 0; - struct timeval now; - struct timeval tv_received; - int usec; + int ret = 0; + struct timeval now; + struct timeval tv_received; + int usec; if (XFRAME_LEN(xframe) < RPACKET_HEADERSIZE) { - static int rate_limit; + static int rate_limit; if ((rate_limit++ % 1003) == 0) { XBUS_NOTICE(xbus, "short xframe\n"); @@ -285,8 +303,9 @@ int xframe_receive(xbus_t *xbus, xframe_t *xframe) } /* Calculate total processing time */ do_gettimeofday(&now); - usec = (now.tv_sec - tv_received.tv_sec) * 1000000 + - now.tv_usec - tv_received.tv_usec; + usec = + (now.tv_sec - tv_received.tv_sec) * 1000000 + now.tv_usec - + tv_received.tv_usec; if (usec > xbus->max_rx_process) xbus->max_rx_process = usec; return ret; @@ -297,23 +316,19 @@ int xframe_receive(xbus_t *xbus, xframe_t *xframe) void dump_packet(const char *msg, const xpacket_t *packet, bool debug) { - __u8 op = XPACKET_OP(packet); - __u8 *addr = (__u8 *)&XPACKET_ADDR(packet); + __u8 op = XPACKET_OP(packet); + __u8 *addr = (__u8 *)&XPACKET_ADDR(packet); if (!debug) return; - printk(KERN_DEBUG "%s: XPD=%1X-%1X%c (0x%X) OP=0x%02X LEN=%d", - msg, - XPACKET_ADDR_UNIT(packet), - XPACKET_ADDR_SUBUNIT(packet), - (XPACKET_ADDR_SYNC(packet))?'+':' ', - *addr, - op, - XPACKET_LEN(packet)); + printk(KERN_DEBUG "%s: XPD=%1X-%1X%c (0x%X) OP=0x%02X LEN=%d", msg, + XPACKET_ADDR_UNIT(packet), XPACKET_ADDR_SUBUNIT(packet), + (XPACKET_ADDR_SYNC(packet)) ? '+' : ' ', *addr, op, + XPACKET_LEN(packet)); #if VERBOSE_DEBUG { int i; - __u8 *p = (__u8 *)packet; + __u8 *p = (__u8 *)packet; printk(" BYTES: "); for (i = 0; i < XPACKET_LEN(packet); i++) { @@ -321,11 +336,9 @@ void dump_packet(const char *msg, const xpacket_t *packet, bool debug) if (i >= sizeof(xpacket_t)) { if (limiter < ERR_REPORT_LIMIT) { - ERR("%s: length overflow i=%d > sizeof(xpacket_t)=%lu\n", - __func__, i+1, (long)sizeof(xpacket_t)); + ERR("%s: length overflow i=%d > sizeof(xpacket_t)=%lu\n", __func__, i + 1, (long)sizeof(xpacket_t)); } else if (limiter == ERR_REPORT_LIMIT) { - ERR("%s: error packet #%d... squelsh reports.\n", - __func__, limiter); + ERR("%s: error packet #%d... squelsh reports.\n", __func__, limiter); } limiter++; break; @@ -338,74 +351,74 @@ void dump_packet(const char *msg, const xpacket_t *packet, bool debug) printk("\n"); } -void dump_reg_cmd(const char msg[], bool writing, xbus_t *xbus, - __u8 unit, xportno_t port, const reg_cmd_t *regcmd) +void dump_reg_cmd(const char msg[], bool writing, xbus_t *xbus, __u8 unit, + xportno_t port, const reg_cmd_t *regcmd) { - char action; - char modifier; - char port_buf[MAX_PROC_WRITE]; - char reg_buf[MAX_PROC_WRITE]; - char data_buf[MAX_PROC_WRITE]; + char action; + char modifier; + char port_buf[MAX_PROC_WRITE]; + char reg_buf[MAX_PROC_WRITE]; + char data_buf[MAX_PROC_WRITE]; if (regcmd->bytes > sizeof(*regcmd) - 1) { /* The size byte is not included */ - PORT_NOTICE(xbus, unit, port, "%s: %s: Too long: regcmd->bytes = %d\n", - __func__, msg, regcmd->bytes); + PORT_NOTICE(xbus, unit, port, + "%s: %s: Too long: regcmd->bytes = %d\n", __func__, + msg, regcmd->bytes); return; } if (regcmd->is_multibyte) { - char buf[MAX_PROC_WRITE + 1]; - int i; - int n = 0; - size_t len = regcmd->bytes; - const __u8 *p = REG_XDATA(regcmd); + char buf[MAX_PROC_WRITE + 1]; + int i; + int n = 0; + size_t len = regcmd->bytes; + const __u8 *p = REG_XDATA(regcmd); buf[0] = '\0'; for (i = 0; i < len && n < MAX_PROC_WRITE; i++) - n += snprintf(&buf[n], MAX_PROC_WRITE - n, "%02X ", p[i]); + n += snprintf(&buf[n], MAX_PROC_WRITE - n, "%02X ", + p[i]); PORT_DBG(REGS, xbus, unit, port, - "UNIT-%d PORT-%d: Multibyte(eoframe=%d) %s[0..%zd]: %s%s\n", - unit, port, regcmd->eoframe, - msg, len-1, buf, (n >= MAX_PROC_WRITE)?"...":""); + "UNIT-%d PORT-%d: Multibyte(eoframe=%d) %s[0..%zd]: %s%s\n", + unit, port, regcmd->eoframe, msg, len - 1, buf, + (n >= MAX_PROC_WRITE) ? "..." : ""); return; } if (regcmd->bytes != sizeof(*regcmd) - 1) { /* The size byte is not included */ - PORT_NOTICE(xbus, unit, port, "%s: %s: Wrong size: regcmd->bytes = %d\n", - __func__, msg, regcmd->bytes); + PORT_NOTICE(xbus, unit, port, + "%s: %s: Wrong size: regcmd->bytes = %d\n", + __func__, msg, regcmd->bytes); return; } - snprintf(port_buf, MAX_PROC_WRITE, "%d%s", - regcmd->portnum, - (REG_FIELD(regcmd, all_ports_broadcast)) ? "*" : ""); + snprintf(port_buf, MAX_PROC_WRITE, "%d%s", regcmd->portnum, + (REG_FIELD(regcmd, all_ports_broadcast)) ? "*" : ""); action = (REG_FIELD(regcmd, read_request)) ? 'R' : 'W'; modifier = 'D'; if (REG_FIELD(regcmd, do_subreg)) { snprintf(reg_buf, MAX_PROC_WRITE, "%02X %02X", - REG_FIELD(regcmd, regnum), - REG_FIELD(regcmd, subreg)); + REG_FIELD(regcmd, regnum), REG_FIELD(regcmd, subreg)); modifier = 'S'; } else { snprintf(reg_buf, MAX_PROC_WRITE, "%02X", - REG_FIELD(regcmd, regnum)); + REG_FIELD(regcmd, regnum)); } if (REG_FIELD(regcmd, read_request)) { data_buf[0] = '\0'; } else if (REG_FIELD(regcmd, do_datah)) { snprintf(data_buf, MAX_PROC_WRITE, "%02X %02X", - REG_FIELD(regcmd, data_low), - REG_FIELD(regcmd, data_high)); + REG_FIELD(regcmd, data_low), REG_FIELD(regcmd, + data_high)); modifier = 'I'; } else { snprintf(data_buf, MAX_PROC_WRITE, "%02X", - REG_FIELD(regcmd, data_low)); + REG_FIELD(regcmd, data_low)); } - PORT_DBG(REGS, xbus, unit, port, "%s: %s %c%c %s %s\n", - msg, port_buf, action, modifier, - reg_buf, data_buf); + PORT_DBG(REGS, xbus, unit, port, "%s: %s %c%c %s %s\n", msg, port_buf, + action, modifier, reg_buf, data_buf); } const char *xproto_name(xpd_type_t xpd_type) { - const xproto_table_t *proto_table; + const xproto_table_t *proto_table; BUG_ON(xpd_type >= XPD_TYPE_NOMODULE); proto_table = xprotocol_tables[xpd_type]; @@ -428,10 +441,10 @@ const char *xproto_name(xpd_type_t xpd_type) int xproto_register(const xproto_table_t *proto_table) { - int type; - const char *name; - const struct xops *xops; - const struct phoneops *phoneops; + int type; + const char *name; + const struct xops *xops; + const struct phoneops *phoneops; BUG_ON(!proto_table); type = proto_table->type; @@ -442,7 +455,8 @@ int xproto_register(const xproto_table_t *proto_table) } DBG(GENERAL, "%s (%d)\n", name, type); if (xprotocol_tables[type]) - NOTICE("%s: overriding registration of %s (%d)\n", __func__, name, type); + NOTICE("%s: overriding registration of %s (%d)\n", __func__, + name, type); xops = proto_table->xops; CHECK_XOP(xops, card_new); CHECK_XOP(xops, card_init); @@ -460,7 +474,7 @@ int xproto_register(const xproto_table_t *proto_table) CHECK_PHONEOP(phoneops, card_dahdi_preregistration); CHECK_PHONEOP(phoneops, card_dahdi_postregistration); /* optional method -- call after testing: */ - /*CHECK_PHONEOP(phoneops, card_ioctl);*/ + /*CHECK_PHONEOP(phoneops, card_ioctl); */ } xprotocol_tables[type] = proto_table; @@ -469,8 +483,8 @@ int xproto_register(const xproto_table_t *proto_table) void xproto_unregister(const xproto_table_t *proto_table) { - int type; - const char *name; + int type; + const char *name; BUG_ON(!proto_table); type = proto_table->type; @@ -481,7 +495,8 @@ void xproto_unregister(const xproto_table_t *proto_table) return; } if (!xprotocol_tables[type]) - NOTICE("%s: xproto type %s (%d) is already unregistered\n", __func__, name, type); + NOTICE("%s: xproto type %s (%d) is already unregistered\n", + __func__, name, type); xprotocol_tables[type] = NULL; } diff --git a/drivers/dahdi/xpp/xproto.h b/drivers/dahdi/xpp/xproto.h index 9bc38b0..b67bbfd 100644 --- a/drivers/dahdi/xpp/xproto.h +++ b/drivers/dahdi/xpp/xproto.h @@ -35,10 +35,10 @@ #define XPP_PROTOCOL_VERSION 30 struct xpd_addr { - uint8_t subunit:SUBUNIT_BITS; - uint8_t reserved:1; - uint8_t unit:UNIT_BITS; - uint8_t sync_master:1; + uint8_t subunit:SUBUNIT_BITS; + uint8_t reserved:1; + uint8_t unit:UNIT_BITS; + uint8_t sync_master:1; } PACKED; #define MKADDR(p, u, s) do { \ @@ -48,12 +48,12 @@ struct xpd_addr { } while (0) struct xpacket_header { - uint16_t packet_len:10; - uint16_t reserved:1; - uint16_t is_pcm:1; - uint16_t pcmslot:4; - uint8_t opcode; - struct xpd_addr addr; + uint16_t packet_len:10; + uint16_t reserved:1; + uint16_t is_pcm:1; + uint16_t pcmslot:4; + uint8_t opcode; + struct xpd_addr addr; } PACKED; #define XPACKET_OP(p) ((p)->head.opcode) @@ -81,7 +81,7 @@ struct xpacket_header { #define XPD_TYPE_ECHO 5 // Octasic echo canceller #define XPD_TYPE_NOMODULE 7 -typedef byte xpd_type_t; +typedef byte xpd_type_t; #define XPD_TYPE_PREFIX "xpd-type-" @@ -167,25 +167,25 @@ bool valid_xpd_addr(const struct xpd_addr *addr); #define MULTIBYTE_MAX_LEN 5 /* FPGA firmware limitation */ typedef struct reg_cmd { - byte bytes:3; /* Length (for Multibyte) */ - __u8 eoframe:1; /* For BRI -- end of frame */ - __u8 portnum:3; /* For port specific registers */ - __u8 is_multibyte:1; + byte bytes:3; /* Length (for Multibyte) */ + __u8 eoframe:1; /* For BRI -- end of frame */ + __u8 portnum:3; /* For port specific registers */ + __u8 is_multibyte:1; union { struct { - __u8 reserved:4; - __u8 do_datah:1; - __u8 do_subreg:1; - __u8 read_request:1; - __u8 all_ports_broadcast:1; - __u8 regnum; - __u8 subreg; - __u8 data_low; - __u8 data_high; + __u8 reserved:4; + __u8 do_datah:1; + __u8 do_subreg:1; + __u8 read_request:1; + __u8 all_ports_broadcast:1; + __u8 regnum; + __u8 subreg; + __u8 data_low; + __u8 data_high; } PACKED r; /* For Write-Multibyte commands in BRI */ struct { - __u8 xdata[MULTIBYTE_MAX_LEN]; + __u8 xdata[MULTIBYTE_MAX_LEN]; } PACKED d; } PACKED alt; } PACKED reg_cmd_t; @@ -197,18 +197,16 @@ typedef struct reg_cmd { #ifdef __KERNEL__ /*--------------------------- protocol tables ----------------------------------*/ -typedef struct xproto_entry xproto_entry_t; -typedef struct xproto_table xproto_table_t; +typedef struct xproto_entry xproto_entry_t; +typedef struct xproto_table xproto_table_t; -typedef int (*xproto_handler_t)( - xbus_t *xbus, - xpd_t *xpd, - const xproto_entry_t *cmd, - xpacket_t *pack); +typedef int (*xproto_handler_t) (xbus_t *xbus, xpd_t *xpd, + const xproto_entry_t *cmd, xpacket_t *pack); const xproto_table_t *xproto_get(xpd_type_t cardtype); void xproto_put(const xproto_table_t *xtable); -const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, __u8 opcode); +const xproto_entry_t *xproto_card_entry(const xproto_table_t *table, + __u8 opcode); xproto_handler_t xproto_card_handler(const xproto_table_t *table, __u8 opcode); const xproto_entry_t *xproto_global_entry(__u8 opcode); @@ -231,49 +229,50 @@ xproto_handler_t xproto_global_handler(__u8 opcode); (PHONE_METHOD(name, (xpd))((xpd), ## __VA_ARGS__ )) struct phoneops { - void (*card_pcm_recompute)(xpd_t *xpd, xpp_line_t pcm_mask); - void (*card_pcm_fromspan)(xpd_t *xpd, xpacket_t *pack); - void (*card_pcm_tospan)(xpd_t *xpd, xpacket_t *pack); - int (*echocancel_timeslot)(xpd_t *xpd, int pos); - int (*echocancel_setmask)(xpd_t *xpd, xpp_line_t ec_mask); - int (*card_timing_priority)(xpd_t *xpd); - int (*card_dahdi_preregistration)(xpd_t *xpd, bool on); - int (*card_dahdi_postregistration)(xpd_t *xpd, bool on); - int (*card_hooksig)(xpd_t *xpd, int pos, enum dahdi_txsig txsig); - int (*card_ioctl)(xpd_t *xpd, int pos, unsigned int cmd, unsigned long arg); - int (*card_open)(xpd_t *xpd, lineno_t pos); - int (*card_close)(xpd_t *xpd, lineno_t pos); - int (*card_state)(xpd_t *xpd, bool on); + void (*card_pcm_recompute) (xpd_t *xpd, xpp_line_t pcm_mask); + void (*card_pcm_fromspan) (xpd_t *xpd, xpacket_t *pack); + void (*card_pcm_tospan) (xpd_t *xpd, xpacket_t *pack); + int (*echocancel_timeslot) (xpd_t *xpd, int pos); + int (*echocancel_setmask) (xpd_t *xpd, xpp_line_t ec_mask); + int (*card_timing_priority) (xpd_t *xpd); + int (*card_dahdi_preregistration) (xpd_t *xpd, bool on); + int (*card_dahdi_postregistration) (xpd_t *xpd, bool on); + int (*card_hooksig) (xpd_t *xpd, int pos, enum dahdi_txsig txsig); + int (*card_ioctl) (xpd_t *xpd, int pos, unsigned int cmd, + unsigned long arg); + int (*card_open) (xpd_t *xpd, lineno_t pos); + int (*card_close) (xpd_t *xpd, lineno_t pos); + int (*card_state) (xpd_t *xpd, bool on); }; struct xops { - xpd_t *(*card_new)(xbus_t *xbus, int unit, int subunit, - const xproto_table_t *proto_table, __u8 subtype, - int subunits, int subunit_ports, bool to_phone); - int (*card_init)(xbus_t *xbus, xpd_t *xpd); - int (*card_remove)(xbus_t *xbus, xpd_t *xpd); - int (*card_tick)(xbus_t *xbus, xpd_t *xpd); - int (*card_register_reply)(xbus_t *xbus, xpd_t *xpd, reg_cmd_t *reg); + xpd_t *(*card_new) (xbus_t *xbus, int unit, int subunit, + const xproto_table_t *proto_table, __u8 subtype, + int subunits, int subunit_ports, bool to_phone); + int (*card_init) (xbus_t *xbus, xpd_t *xpd); + int (*card_remove) (xbus_t *xbus, xpd_t *xpd); + int (*card_tick) (xbus_t *xbus, xpd_t *xpd); + int (*card_register_reply) (xbus_t *xbus, xpd_t *xpd, reg_cmd_t *reg); }; struct xproto_entry { - xproto_handler_t handler; - int datalen; - const char *name; - xproto_table_t *table; + xproto_handler_t handler; + int datalen; + const char *name; + xproto_table_t *table; }; struct xproto_table { - struct module *owner; - xproto_entry_t entries[256]; /* Indexed by opcode */ - const struct xops *xops; /* Card level operations */ - const struct phoneops *phoneops; /* DAHDI operations */ - const struct echoops *echoops; /* Echo Canceller operations */ - xpd_type_t type; - __u8 ports_per_subunit; - const char *name; - bool (*packet_is_valid)(xpacket_t *pack); - void (*packet_dump)(const char *msg, xpacket_t *pack); + struct module *owner; + xproto_entry_t entries[256]; /* Indexed by opcode */ + const struct xops *xops; /* Card level operations */ + const struct phoneops *phoneops; /* DAHDI operations */ + const struct echoops *echoops; /* Echo Canceller operations */ + xpd_type_t type; + __u8 ports_per_subunit; + const char *name; + bool (*packet_is_valid) (xpacket_t *pack); + void (*packet_dump) (const char *msg, xpacket_t *pack); }; #include "card_global.h" @@ -282,11 +281,10 @@ struct xproto_table { #include "card_bri.h" #include "card_pri.h" - #define MEMBER(card, op) RPACKET_TYPE(card, op) RPACKET_NAME(card, op) struct xpacket { - struct xpacket_header head; + struct xpacket_header head; union { MEMBER(GLOBAL, NULL_REPLY); MEMBER(GLOBAL, PCM_WRITE); @@ -297,20 +295,22 @@ struct xpacket { MEMBER(FXS, SIG_CHANGED); MEMBER(FXO, SIG_CHANGED); - __u8 data[0]; + __u8 data[0]; }; /* Last byte is chksum */ } PACKED; void dump_packet(const char *msg, const xpacket_t *packet, bool debug); -void dump_reg_cmd(const char msg[], bool writing, xbus_t *xbus, __u8 unit, xportno_t port, const reg_cmd_t *regcmd); +void dump_reg_cmd(const char msg[], bool writing, xbus_t *xbus, __u8 unit, + xportno_t port, const reg_cmd_t *regcmd); int xframe_receive(xbus_t *xbus, xframe_t *xframe); -void notify_bad_xpd(const char *funcname, xbus_t *xbus, const struct xpd_addr addr, const char *msg); +void notify_bad_xpd(const char *funcname, xbus_t *xbus, + const struct xpd_addr addr, const char *msg); int xproto_register(const xproto_table_t *proto_table); void xproto_unregister(const xproto_table_t *proto_table); const xproto_entry_t *xproto_global_entry(__u8 opcode); const char *xproto_name(xpd_type_t xpd_type); -#endif /* __KERNEL__ */ +#endif /* __KERNEL__ */ -#endif /* XPROTO_H */ +#endif /* XPROTO_H */