[svn-commits] sruffell: linux/trunk r6217 - /linux/trunk/drivers/dahdi/wctc4xxp/base.c
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Mar 23 18:48:20 CDT 2009
Author: sruffell
Date: Mon Mar 23 18:48:16 2009
New Revision: 6217
URL: http://svn.digium.com/svn-view/dahdi?view=rev&rev=6217
Log:
Refactor channel command handling.
Makes commands and reponses clearer and easier to trouble shoot, reduces
pressure on the stack, and brings driver closer to kernel coding standards.
Modified:
linux/trunk/drivers/dahdi/wctc4xxp/base.c
Modified: linux/trunk/drivers/dahdi/wctc4xxp/base.c
URL: http://svn.digium.com/svn-view/dahdi/linux/trunk/drivers/dahdi/wctc4xxp/base.c?view=diff&rev=6217&r1=6216&r2=6217
==============================================================================
--- linux/trunk/drivers/dahdi/wctc4xxp/base.c (original)
+++ linux/trunk/drivers/dahdi/wctc4xxp/base.c Mon Mar 23 18:48:16 2009
@@ -1,7 +1,7 @@
/*
* Wildcard TC400B Driver
*
- * Copyright (C) 2006-2008, Digium, Inc.
+ * Copyright (C) 2006-2009, Digium, Inc.
*
* All rights reserved.
*
@@ -30,7 +30,7 @@
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
-#include <asm/io.h>
+#include <linux/io.h>
#include <linux/jiffies.h>
#include <linux/moduleparam.h>
#include <linux/firmware.h>
@@ -48,7 +48,7 @@
#define WORKQUEUE 1
#define TASKLET 2
-#ifndef DEFERRED_PROCESSING
+#ifndef DEFERRED_PROCESSING
# define DEFERRED_PROCESSING WORKQUEUE
#endif
@@ -63,16 +63,16 @@
#define WARN_ALWAYS() WARN_ON(1)
#define DTE_PRINTK(_lvl, _fmt, _args...) \
- printk(KERN_##_lvl "%s: %s: " _fmt, THIS_MODULE->name, \
- (wc)->board_name, ## _args)
-
-#define DTE_DEBUG(_dbgmask, _fmt, _args...) \
- if ((debug & _dbgmask) == (_dbgmask)) { \
- printk(KERN_DEBUG "%s: %s: " _fmt, THIS_MODULE->name, \
- (wc)->board_name, ## _args); \
- } \
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
+ printk(KERN_##_lvl "%s: %s: " _fmt, THIS_MODULE->name, \
+ (wc)->board_name, ## _args)
+
+#define DTE_DEBUG(_dbgmask, _fmt, _args...) \
+ if ((debug & _dbgmask) == (_dbgmask)) { \
+ printk(KERN_DEBUG "%s: %s: " _fmt, THIS_MODULE->name, \
+ (wc)->board_name, ## _args); \
+ } \
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
#ifndef WARN_ON_ONCE
#define WARN_ON_ONCE(__condition) do { \
static int __once = 1; \
@@ -82,12 +82,12 @@
WARN_ON(0); \
} \
} \
-} while(0)
+} while (0)
#endif
#endif
#define INVALID 999 /* Used to mark invalid channels, commands, etc.. */
-#define MAX_CHANNEL_PACKETS 5 /* Never let more than 5 outstanding packets exist for any channel. */
+#define MAX_CHANNEL_PACKETS 5
#define G729_LENGTH 20
#define G723_LENGTH 30
@@ -103,13 +103,13 @@
#define MAX_CAPTURED_PACKETS 5000
/* The following bit fields are used to set the various debug levels. */
-#define DTE_DEBUG_GENERAL (1 << 0) /* 1 */
-#define DTE_DEBUG_CHANNEL_SETUP (1 << 1) /* 2 */
-#define DTE_DEBUG_RTP_TX (1 << 2) /* 4 */
-#define DTE_DEBUG_RTP_RX (1 << 3) /* 8 */
-#define DTE_DEBUG_RX_TIMEOUT (1 << 4) /* 16 */
-#define DTE_DEBUG_NETWORK_IF (1 << 5) /* 32 */
-#define DTE_DEBUG_NETWORK_EARLY (1 << 6) /* 64 */
+#define DTE_DEBUG_GENERAL (1 << 0) /* 1 */
+#define DTE_DEBUG_CHANNEL_SETUP (1 << 1) /* 2 */
+#define DTE_DEBUG_RTP_TX (1 << 2) /* 4 */
+#define DTE_DEBUG_RTP_RX (1 << 3) /* 8 */
+#define DTE_DEBUG_RX_TIMEOUT (1 << 4) /* 16 */
+#define DTE_DEBUG_NETWORK_IF (1 << 5) /* 32 */
+#define DTE_DEBUG_NETWORK_EARLY (1 << 6) /* 64 */
static int debug;
static char *mode;
@@ -148,7 +148,7 @@
struct udphdr udphdr;
struct rtphdr rtphdr;
__u8 payload[0];
-}__attribute__((packed));
+} __attribute__((packed));
/* Ethernet packet type for communication control information to the DTE. */
struct csm_encaps_hdr {
@@ -168,167 +168,25 @@
__le16 params[0];
} __attribute__((packed));
-struct csm_create_channel_cmd {
- struct csm_encaps_hdr hdr;
- __le16 channel_type;
- __le16 timeslot;
-} __attribute__((packed));
-
-#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 */
-#endif
-#endif
-
-#define CMD_MSG_TDM_SELECT_BUS_MODE_LEN 30
-#define CMD_MSG_TDM_SELECT_BUS_MODE(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x01, 0x00,0x06,0x17,0x04, 0xFF,0xFF, \
- 0x04,0x00 }
-#define CMD_MSG_TDM_ENABLE_BUS_LEN 30
-#define CMD_MSG_TDM_ENABLE_BUS(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x02, 0x00,0x06,0x05,0x04, 0xFF,0xFF, \
- 0x04,0x00 }
-#define CMD_MSG_SUPVSR_SETUP_TDM_PARMS_LEN 34
-#define CMD_MSG_SUPVSR_SETUP_TDM_PARMS(s,p1,p2,p3) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x10, p1, 0x00,0x06,0x07,0x04, 0xFF,0xFF, \
- p2,0x83, 0x00,0x0C, 0x00,0x00, p3,0x00 }
-#define CMD_MSG_TDM_OPT_LEN 30
-#define CMD_MSG_TDM_OPT(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x35,0x04, 0xFF,0xFF, \
- 0x00,0x00 }
-#define CMD_MSG_DEVICE_SET_COUNTRY_CODE_LEN 30
-#define CMD_MSG_DEVICE_SET_COUNTRY_CODE(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x1B,0x04, 0xFF,0xFF, \
- 0x00,0x00 }
-
-/* CPU Commands */
-#define CMD_MSG_SET_ARM_CLK_LEN 32
-#define CMD_MSG_SET_ARM_CLK(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0C, 0x00, 0x00,0x06,0x11,0x04, 0x00,0x00, \
- 0x2C,0x01, 0x00,0x00 }
-#define CMD_MSG_SET_SPU_CLK_LEN 32
-#define CMD_MSG_SET_SPU_CLK(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0C, 0x00, 0x00,0x06,0x12,0x04, 0x00,0x00, \
- 0x2C,0x01, 0x00,0x00 }
-#define CMD_MSG_SPU_FEATURES_CONTROL_LEN 30
-#define CMD_MSG_SPU_FEATURES_CONTROL(s,p1) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x13,0x00, 0xFF,0xFF, \
- p1,0x00 }
-#define CMD_MSG_DEVICE_STATUS_CONFIG_LEN 30
-#define CMD_MSG_DEVICE_STATUS_CONFIG(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x0F,0x04, 0xFF,0xFF, \
- 0x05,0x00 }
-
-/* General IP/RTP Commands */
-#define CMD_MSG_SET_ETH_HEADER_LEN 44
-#define CMD_MSG_SET_ETH_HEADER(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x18, 0x00, 0x00,0x06,0x00,0x01, 0xFF,0xFF, \
- 0x01,0x00, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x00,0x11,0x22,0x33,0x44,0x55, 0x08,0x00 }
-#define CMD_MSG_IP_SERVICE_CONFIG_LEN 30
-#define CMD_MSG_IP_SERVICE_CONFIG(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x02,0x03, 0xFF,0xFF, \
- 0x00,0x02 }
-#define CMD_MSG_ARP_SERVICE_CONFIG_LEN 30
-#define CMD_MSG_ARP_SERVICE_CONFIG(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x05,0x01, 0xFF,0xFF, \
- 0x01,0x00 }
-#define CMD_MSG_ICMP_SERVICE_CONFIG_LEN 30
-#define CMD_MSG_ICMP_SERVICE_CONFIG(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x04,0x03, 0xFF,0xFF, \
- 0x01,0xFF }
-#define CMD_MSG_IP_OPTIONS_LEN 30
-#define CMD_MSG_IP_OPTIONS(s) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x06,0x03, 0xFF,0xFF, \
- 0x02,0x00 }
-
#define CONTROL_PACKET_OPCODE 0x0001
/* Control bits */
-#define LITTLE_ENDIAN 0x01
-#define SUPPRESS_ACK 0x40
-#define MESSAGE_PACKET 0x80
+#define LITTLE_ENDIAN 0x01
+#define SUPPRESS_ACK 0x40
+#define MESSAGE_PACKET 0x80
#define SUPERVISOR_CHANNEL 0xffff
/* Supervisor function codes */
-#define SUPVSR_CREATE_CHANNEL 0x0010
+#define SUPVSR_CREATE_CHANNEL 0x0010
#define MONITOR_LIVE_INDICATION_TYPE 0x75
-#define CONFIG_CHANGE_TYPE 0x00
-#define CONFIG_DEVICE_CLASS 0x06
-
-#define CMD_MSG_QUERY_CHANNEL_LEN 30
-#define CMD_MSG_QUERY_CHANNEL(s,t) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x01,0x06,0x10,0x00, 0x00,0x00, \
- (t&0x00FF), ((t&0xFF00) >> 8) }
-
-#define CMD_MSG_TRANS_CONNECT_LEN 38
-#define CMD_MSG_TRANS_CONNECT(s,e,c1,c2,f1,f2) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x12, 0x00, 0x00,0x06,0x22,0x93, 0x00,0x00, \
- e,0x00, (c1&0x00FF),((c1&0xFF00)>>8), f1,0x00, (c2&0x00FF),((c2&0xFF00)>>8), f2,0x00 }
-#define CMD_MSG_DESTROY_CHANNEL_LEN 32
-#define CMD_MSG_DESTROY_CHANNEL(s,t) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, 0xFF,0xFF, 0x0A, 0x00, 0x00,0x06,0x11,0x00, 0x00,0x00, \
- (t&0x00FF),((t&0xFF00)>>8), 0x00, 0x00 }
+#define CONFIG_CHANGE_TYPE 0x00
+#define CONFIG_CHANNEL_CLASS 0x02
+#define CONFIG_DEVICE_CLASS 0x06
/* Individual channel config commands */
-#define CMD_MSG_SET_IP_HDR_CHANNEL_LEN 58
-#define CMD_MSG_SET_IP_HDR_CHANNEL(s,c,t2,t1) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00) >> 8),(c&0x00FF), 0x26, 0x00, 0x00,0x02,0x00,0x90, 0x00,0x00, \
- 0x00,0x00, 0x45,0x00, 0x00,0x00, 0x00,0x00, 0x40,0x00, 0x80,0x11, 0x00,0x00, \
- 0xC0,0xA8,0x09,0x03, 0xC0,0xA8,0x09,0x03, \
- ((t2&0xFF00)>>8)+0x50,(t2&0x00FF), ((t1&0xFF00)>>8)+0x50,(t1&0x00FF), 0x00,0x00, 0x00,0x00 }
-#define CMD_MSG_VOIP_VCEOPT_LEN 40
-#define CMD_MSG_VOIP_VCEOPT(s,c,l,w) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00)>>8),(c&0x00FF), 0x12, 0x00, 0x00,0x02,0x01,0x80, 0x00,0x00, \
- 0x21,l, 0x00,0x1C, 0x04,0x00, 0x00,0x00, w,0x00, 0x80,0x11 }
-#define CMD_MSG_VOIP_VOPENA_LEN 44
-#define CMD_MSG_VOIP_VOPENA(s,c,f) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00)>>8),(c&0x00FF), 0x16, 0x00, 0x00,0x02,0x00,0x80, 0x00,0x00, \
- 0x01,0x00, 0x80,f, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x12,0x34, 0x56,0x78, 0x00,0x00 }
-#define CMD_MSG_VOIP_VOPENA_CLOSE_LEN 32
-#define CMD_MSG_VOIP_VOPENA_CLOSE(s,c) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00)>>8),(c&0x00FF), 0x0A, 0x00, 0x00,0x02,0x00,0x80, 0x00,0x00, \
- 0x00,0x00, 0x00,0x00 }
-#define CMD_MSG_VOIP_INDCTRL_LEN 32
-#define CMD_MSG_VOIP_INDCTRL(s,c) {0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00)>>8),(c&0x00FF), 0x0A, 0x00, 0x00,0x02,0x84,0x80, 0x00,0x00, \
- 0x07,0x00, 0x00,0x00 }
-#define CMD_MSG_VOIP_DTMFOPT_LEN 32
-#define CMD_MSG_VOIP_DTMFOPT(s,c) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00)>>8),(c&0x00FF), 0x0A, 0x00, 0x00,0x02,0x02,0x80, 0x00,0x00, \
- 0x08,0x00, 0x00,0x00 }
-
-#define CMD_MSG_VOIP_TONECTL_LEN 32
-#define CMD_MSG_VOIP_TONECTL(s,c) { \
- 0x00,0x11,0x22,0x33,0x44,0x55, 0xAA,0xBB,0xCC,0xDD,0xEE,0xFF, 0x88,0x9B, \
- 0x00,0x01, s&0x0F, 0x01, ((c&0xFF00)>>8),(c&0x00FF), 0x0A, 0x00, 0x00,0x02,0x5B,0x80, 0x00,0x00, \
- 0x00,0x00, 0x00,0x00 }
-
#define MAX_FRAME_SIZE 1518
-#define SFRAME_SIZE MAX_FRAME_SIZE
+#define SFRAME_SIZE MAX_FRAME_SIZE
/* Transcoder buffer (tcb) */
struct tcb {
@@ -343,7 +201,7 @@
#define TX_COMPLETE (1 << 1)
#define DO_NOT_CAPTURE (1 << 2)
#define __WAIT_FOR_ACK (1 << 3)
-#define __WAIT_FOR_RESPONSE (1 << 4)
+#define __WAIT_FOR_RESPONSE (1 << 4)
#define DTE_CMD_TIMEOUT (1 << 5)
#define WAIT_FOR_ACK (__WAIT_FOR_ACK | DO_NOT_AUTO_FREE)
#define WAIT_FOR_RESPONSE (__WAIT_FOR_RESPONSE | DO_NOT_AUTO_FREE)
@@ -353,15 +211,23 @@
struct timer_list timer;
void *data;
/* The number of bytes available in data. */
- int data_len;
+ int data_len;
};
-static inline void *hdr_from_cmd(struct tcb *cmd) {
+static inline void *hdr_from_cmd(struct tcb *cmd)
+{
return cmd->data;
}
-static inline void
-initialize_cmd(struct tcb *cmd, unsigned long cmd_flags)
+static inline const struct csm_encaps_hdr *
+response_header(struct tcb *cmd)
+{
+ BUG_ON(!cmd->response);
+ return (const struct csm_encaps_hdr *)(cmd)->response->data;
+}
+
+static inline void
+initialize_cmd(struct tcb *cmd, unsigned long cmd_flags)
{
memset(cmd, 0, sizeof(*cmd));
INIT_LIST_HEAD(&cmd->node);
@@ -371,7 +237,7 @@
cmd->data_len = SFRAME_SIZE;
}
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
/*! Used to allocate commands to submit to the dte. */
kmem_cache_t *cmd_cache;
#else
@@ -385,9 +251,8 @@
struct tcb *cmd;
cmd = kmem_cache_alloc(cmd_cache, alloc_flags);
- if (likely(cmd)) {
+ if (likely(cmd))
initialize_cmd(cmd, cmd_flags);
- }
return cmd;
}
@@ -397,26 +262,22 @@
return __alloc_cmd(GFP_KERNEL, 0);
}
-static void
+static void
__free_cmd(struct tcb *cmd)
{
- if (cmd->data != &cmd->cmd[0]) {
+ if (cmd->data != &cmd->cmd[0])
kfree(cmd->data);
- }
kmem_cache_free(cmd_cache, cmd);
return;
}
-static void
+static void
free_cmd(struct tcb *cmd)
{
- if (cmd->response) {
+ if (cmd->response)
__free_cmd(cmd->response);
- }
__free_cmd(cmd);
}
-
-typedef enum { DECODER=0, ENCODER, } encode_t;
struct channel_stats {
atomic_t packets_sent;
@@ -424,26 +285,20 @@
};
struct channel_pvt {
- spinlock_t lock; /* Lock for this structure */
- encode_t encoder; /* If we're an encoder */
+ spinlock_t lock; /* Lock for this structure */
+ int encoder; /* If we're an encoder */
struct wcdte *wc;
-
- unsigned int timestamp;
- unsigned int seqno;
-
- unsigned int cmd_seqno;
-
- unsigned int timeslot_in_num; /* DTE channel on which results will be received from */
- unsigned int timeslot_out_num; /* DTE channel to send data to */
-
- unsigned int chan_in_num; /* DTE channel on which results will be received from */
- unsigned int chan_out_num; /* DTE channel to send data to */
-
+ u32 timestamp;
+ u16 seqno;
+ u8 cmd_seqno;
+ u16 timeslot_in_num; /* DTE timeslot to receive from */
+ u16 timeslot_out_num; /* DTE timeslot to send data to */
+ u16 chan_in_num; /* DTE channel to receive from */
+ u16 chan_out_num; /* DTE channel to send data to */
struct channel_stats stats;
-
u16 last_dte_seqno;
- unsigned char ssrc;
- struct list_head rx_queue; /* Transcoded packets for this channel. */
+ u8 ssrc;
+ struct list_head rx_queue; /* Transcoded packets for this channel. */
};
struct wcdte {
@@ -455,7 +310,7 @@
wait_queue_head_t waitq;
struct semaphore chansem;
#define DTE_READY 1
-#define DTE_SHUTDOWN 2
+#define DTE_SHUTDOWN 2
unsigned long flags;
spinlock_t cmd_list_lock;
@@ -477,7 +332,7 @@
unsigned long iobase;
struct wctc4xxp_descriptor_ring *txd;
struct wctc4xxp_descriptor_ring *rxd;
-
+
struct dahdi_transcoder *uencode;
struct dahdi_transcoder *udecode;
struct channel_pvt *encoders;
@@ -496,7 +351,7 @@
struct sk_buff_head captured_packets;
struct net_device *netdev;
struct net_device_stats net_stats;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
struct napi_struct napi;
#endif
struct timer_list watchdog;
@@ -522,39 +377,15 @@
}
-static inline void wctc4xxp_set_ready(struct wcdte *wc) {
+static inline void wctc4xxp_set_ready(struct wcdte *wc)
+{
set_bit(DTE_READY, &wc->flags);
}
-static inline int wctc4xxp_is_ready(struct wcdte *wc) {
+
+static inline int wctc4xxp_is_ready(struct wcdte *wc)
+{
return test_bit(DTE_READY, &wc->flags);
}
-
-#if 1
- /* \todo This macro is a candidate for removal. It's still here because of
- * how the commands are passed to this dahdi_send_cmd */
-#define wctc4xxp_send_cmd(wc, command) ({ \
- int __res; \
- u8 _cmd[] = command; \
- struct tcb *__cmd; \
- if (!(__cmd=__alloc_cmd(GFP_KERNEL, WAIT_FOR_RESPONSE))) \
- return -ENOMEM; \
- BUG_ON(sizeof(_cmd) > SFRAME_SIZE); \
- memcpy(__cmd->data, _cmd, sizeof(_cmd)); \
- __cmd->data_len = sizeof(_cmd); \
- __res = __wctc4xxp_send_cmd(wc, __cmd); \
- __res; \
-})
-#define wctc4xxp_create_cmd(wc, command) ({ \
- u8 _command[] = command; \
- struct tcb *_cmd; \
- if (!(_cmd=__alloc_cmd(GFP_KERNEL, WAIT_FOR_RESPONSE))) \
- return -ENOMEM; \
- BUG_ON(sizeof(_command) > SFRAME_SIZE); \
- memcpy(_cmd->data, _command, sizeof(_command)); \
- _cmd->data_len = sizeof(_command); \
- _cmd; \
-})
-#endif
#define DTE_FORMAT_ULAW 0x00
#define DTE_FORMAT_G723_1 0x04
@@ -565,29 +396,29 @@
static inline u8 wctc4xxp_dahdifmt_to_dtefmt(unsigned int fmt)
{
u8 pt;
-
- switch(fmt) {
- case DAHDI_FORMAT_G723_1:
- pt = DTE_FORMAT_G723_1;
- break;
- case DAHDI_FORMAT_ULAW:
- pt = DTE_FORMAT_ULAW;
- break;
- case DAHDI_FORMAT_ALAW:
- pt = DTE_FORMAT_ALAW;
- break;
- case DAHDI_FORMAT_G729A:
- pt = DTE_FORMAT_G729A;
- break;
- default:
- pt = DTE_FORMAT_UNDEF;
- break;
+
+ switch (fmt) {
+ case DAHDI_FORMAT_G723_1:
+ pt = DTE_FORMAT_G723_1;
+ break;
+ case DAHDI_FORMAT_ULAW:
+ pt = DTE_FORMAT_ULAW;
+ break;
+ case DAHDI_FORMAT_ALAW:
+ pt = DTE_FORMAT_ALAW;
+ break;
+ case DAHDI_FORMAT_G729A:
+ pt = DTE_FORMAT_G729A;
+ break;
+ default:
+ pt = DTE_FORMAT_UNDEF;
+ break;
}
return pt;
}
-static struct sk_buff *
+static struct sk_buff *
tcb_to_skb(struct net_device *netdev, const struct tcb *cmd)
{
struct sk_buff *skb;
@@ -596,12 +427,12 @@
skb->dev = netdev;
skb_put(skb, cmd->data_len);
memcpy(skb->data, cmd->data, cmd->data_len);
- skb->protocol = eth_type_trans(skb,netdev);
+ skb->protocol = eth_type_trans(skb, netdev);
}
return skb;
}
-/**
+/**
* wctc4xxp_skb_to_cmd - Convert a socket buffer (skb) to a tcb
* @wc: The transcoder that we're going to send this command to.
* @skb: socket buffer to convert.
@@ -612,68 +443,58 @@
{
const gfp_t alloc_flags = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
struct tcb *cmd;
- /* const static char dev_mac[] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; */
- if ((cmd = __alloc_cmd(alloc_flags, 0))) {
+ cmd = __alloc_cmd(alloc_flags, 0);
+ if (cmd) {
int res;
cmd->data_len = skb->len;
- if ((res = skb_copy_bits(skb, 0, cmd->data, cmd->data_len))) {
- DTE_PRINTK(WARNING,
+ res = skb_copy_bits(skb, 0, cmd->data, cmd->data_len);
+ if (res) {
+ DTE_PRINTK(WARNING,
"Failed call to skb_copy_bits.\n");
free_cmd(cmd);
cmd = NULL;
}
- /* When we set up our interface we indicated that we do not
- * support ARP. Therefore, the destination MAC on packets
- * arriving from the kernel networking components are not
- * going to be correct. Let's fix that here.
- */
- /* \todo let us just use whatever was in the packet already... */
- /* memcpy(&cmd->cmd[6], dev_mac, sizeof(dev_mac)); */
}
return cmd;
}
-static void
+static void
wctc4xxp_net_set_multi(struct net_device *netdev)
{
struct wcdte *wc = wcdte_from_netdev(netdev);
- DTE_DEBUG(DTE_DEBUG_GENERAL, "%s promiscuity:%d\n",
- __FUNCTION__, netdev->promiscuity);
-}
-
-static int
+ DTE_DEBUG(DTE_DEBUG_GENERAL, "%s promiscuity:%d\n",
+ __func__, netdev->promiscuity);
+}
+
+static int
wctc4xxp_net_up(struct net_device *netdev)
{
struct wcdte *wc = wcdte_from_netdev(netdev);
- DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
-#if 1
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+ DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __func__);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
netif_poll_enable(netdev);
#else
napi_enable(&wc->napi);
#endif
-#endif
return 0;
}
-static int
+static int
wctc4xxp_net_down(struct net_device *netdev)
{
struct wcdte *wc = wcdte_from_netdev(netdev);
- DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __FUNCTION__);
-#if 1
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+ DTE_DEBUG(DTE_DEBUG_GENERAL, "%s\n", __func__);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
netif_poll_disable(netdev);
#else
napi_disable(&wc->napi);
#endif
-#endif
return 0;
}
static void wctc4xxp_transmit_cmd(struct wcdte *, struct tcb *);
-static int
+static int
wctc4xxp_net_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct wcdte *wc = wcdte_from_netdev(netdev);
@@ -681,10 +502,11 @@
/* We set DO_NOT_CAPTURE because this packet was already captured by
* in code higher up in the networking stack. We don't want to
- * capture it twice.
+ * capture it twice.
*/
- if ((cmd = wctc4xxp_skb_to_cmd(wc, skb))) {
- cmd->flags |= DO_NOT_CAPTURE;
+ cmd = wctc4xxp_skb_to_cmd(wc, skb);
+ if (cmd) {
+ cmd->flags |= DO_NOT_CAPTURE;
wctc4xxp_transmit_cmd(wc, cmd);
}
@@ -692,7 +514,7 @@
return NETDEV_TX_OK;
}
-static int
+static int
wctc4xxp_net_receive(struct wcdte *wc, int max)
{
int count = 0;
@@ -700,15 +522,14 @@
WARN_ON(0 == max);
while ((skb = skb_dequeue(&wc->captured_packets))) {
netif_receive_skb(skb);
- if (++count >= max) {
+ if (++count >= max)
break;
- }
}
return count;
}
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
-static int
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
+static int
wctc4xxp_poll(struct net_device *netdev, int *budget)
{
struct wcdte *wc = wcdte_from_netdev(netdev);
@@ -728,7 +549,7 @@
}
}
#else
-static int
+static int
wctc4xxp_poll(struct napi_struct *napi, int budget)
{
struct wcdte *wc = container_of(napi, struct wcdte, napi);
@@ -755,20 +576,20 @@
}
/* Wait until this device is put into promiscuous mode, or we timeout. */
-static void
+static void
wctc4xxp_net_waitfor_promiscuous(struct wcdte *wc)
{
unsigned int seconds = 15;
unsigned long start = jiffies;
struct net_device *netdev = wc->netdev;
- DTE_PRINTK(INFO,
+ DTE_PRINTK(INFO,
"Waiting %d seconds for adapter to be placed in " \
"promiscuous mode for early trace.\n", seconds);
while (!netdev->promiscuity) {
if (signal_pending(current)) {
- DTE_PRINTK(INFO,
+ DTE_PRINTK(INFO,
"Aborting wait due to signal.\n");
break;
}
@@ -784,11 +605,11 @@
static int wctc4xxp_turn_off_booted_led(struct wcdte *wc);
static void wctc4xxp_turn_on_booted_led(struct wcdte *wc);
-static int
+static int
wctc4xxp_net_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
{
struct wcdte *wc = wcdte_from_netdev(netdev);
- switch(cmd) {
+ switch (cmd) {
case 0x89f0:
down(&wc->chansem);
wctc4xxp_turn_off_booted_led(wc);
@@ -803,15 +624,15 @@
return 0;
}
-/**
+/**
* wctc4xxp_net_register - Register a new network interface.
* @wc: transcoder card to register the interface for.
*
* The network interface is primarily used for debugging in order to watch the
* traffic between the transcoder and the host.
- *
+ *
*/
-static int
+static int
wctc4xxp_net_register(struct wcdte *wc)
{
int res;
@@ -842,15 +663,16 @@
netdev->do_ioctl = &wctc4xxp_net_ioctl;
netdev->promiscuity = 0;
netdev->flags |= IFF_NOARP;
-# if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
netdev->poll = &wctc4xxp_poll;
netdev->weight = 64;
# else
netif_napi_add(netdev, &wc->napi, &wctc4xxp_poll, 64);
# endif
- if ((res = register_netdev(netdev))) {
- DTE_PRINTK(WARNING,
+ res = register_netdev(netdev);
+ if (res) {
+ DTE_PRINTK(WARNING,
"Failed to register network device %s.\n",
wc->board_name);
goto error_sw;
@@ -859,33 +681,29 @@
wc->netdev = netdev;
skb_queue_head_init(&wc->captured_packets);
- if (debug & DTE_DEBUG_NETWORK_EARLY) {
+ if (debug & DTE_DEBUG_NETWORK_EARLY)
wctc4xxp_net_waitfor_promiscuous(wc);
- }
-
- DTE_PRINTK(DEBUG,
+
+ DTE_PRINTK(DEBUG,
"Created network device %s for debug.\n", wc->board_name);
return 0;
error_sw:
- if (netdev) free_netdev(netdev);
+ if (netdev)
+ free_netdev(netdev);
return res;
}
-static void
+static void
wctc4xxp_net_unregister(struct wcdte *wc)
{
struct sk_buff *skb;
- if (!wc->netdev) {
+
+ if (!wc->netdev)
return;
- }
-
unregister_netdev(wc->netdev);
-
- while ((skb = skb_dequeue(&wc->captured_packets))) {
+ while ((skb = skb_dequeue(&wc->captured_packets)))
kfree_skb(skb);
- }
-
free_netdev(wc->netdev);
wc->netdev = NULL;
}
@@ -897,29 +715,27 @@
* @cmd: command to send to network stack.
*
*/
-static void
+static void
wctc4xxp_net_capture_cmd(struct wcdte *wc, const struct tcb *cmd)
{
struct sk_buff *skb;
struct net_device *netdev = wc->netdev;
- if (!netdev) {
+ if (!netdev)
return;
- }
/* No need to capture if there isn't anyone listening. */
- if (!(netdev->flags & IFF_UP)) {
+ if (!(netdev->flags & IFF_UP))
return;
- }
-
+
if (skb_queue_len(&wc->captured_packets) > MAX_CAPTURED_PACKETS) {
WARN_ON_ONCE(1);
return;
}
- if (!(skb = tcb_to_skb(netdev, cmd))) {
+ skb = tcb_to_skb(netdev, cmd);
+ if (!skb)
return;
- }
skb_queue_tail(&wc->captured_packets, skb);
# if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
@@ -947,7 +763,7 @@
struct wctc4xxp_descriptor_ring {
/* Pointer to an array of descriptors to give to hardware. */
- struct wctc4xxp_descriptor* desc;
+ struct wctc4xxp_descriptor *desc;
/* Read completed buffers from the head. */
unsigned int head;
/* Write ready buffers to the tail. */
@@ -972,54 +788,52 @@
* wctc4xxp_descriptor - Returns the desriptor at index.
* @dr: The descriptor ring we're using.
* @index: index of the descriptor we want.
- *
+ *
* We need this function because we do not know what the padding on the
* descriptors will be. Otherwise, we would just use an array.
*/
static inline struct wctc4xxp_descriptor *
wctc4xxp_descriptor(struct wctc4xxp_descriptor_ring *dr, int index)
{
- return (struct wctc4xxp_descriptor *)((u8*)dr->desc +
+ return (struct wctc4xxp_descriptor *)((u8 *)dr->desc +
((sizeof(*dr->desc) + dr->padding) * index));
}
static int
-wctc4xxp_initialize_descriptor_ring(struct pci_dev *pdev, struct wctc4xxp_descriptor_ring *dr,
- u32 des1, unsigned int direction)
-{
- int i;
+wctc4xxp_initialize_descriptor_ring(struct pci_dev *pdev,
+ struct wctc4xxp_descriptor_ring *dr, u32 des1, unsigned int direction)
+{
+ int i;
const u32 END_OF_RING = 0x02000000;
u8 cache_line_size = 0;
struct wctc4xxp_descriptor *d;
+ int add_padding;
BUG_ON(!pdev);
BUG_ON(!dr);
- if (pci_read_config_byte(pdev, 0x0c, &cache_line_size)) {
- /* \todo Print an error message... */
+ if (pci_read_config_byte(pdev, 0x0c, &cache_line_size))
return -EIO;
- }
memset(dr, 0, sizeof(*dr));
/*
* Add some padding to each descriptor to ensure that they are
- * aligned on host system cache-line boundaries, but only for the
+ * aligned on host system cache-line boundaries, but only for the
* cache-line sizes that we support.
*
*/
- if ((0x08 == cache_line_size) || (0x10 == cache_line_size) ||
- (0x20 == cache_line_size))
- {
+ add_padding = (0x08 == cache_line_size) ||
+ (0x10 == cache_line_size) ||
+ (0x20 == cache_line_size);
+ if (add_padding)
dr->padding = (cache_line_size*sizeof(u32)) - sizeof(*d);
- }
-
- dr->desc = pci_alloc_consistent(pdev,
+
+ dr->desc = pci_alloc_consistent(pdev,
(sizeof(*d)+dr->padding)*DRING_SIZE, &dr->desc_dma);
- if (!dr->desc) {
+ if (!dr->desc)
return -ENOMEM;
- }
memset(dr->desc, 0, (sizeof(*d) + dr->padding) * DRING_SIZE);
for (i = 0; i < DRING_SIZE; ++i) {
@@ -1036,12 +850,12 @@
#define OWN_BIT cpu_to_le32(0x80000000)
#define OWNED(_d_) (((_d_)->des0)&OWN_BIT)
-#define SET_OWNED(_d_) do { wmb(); (_d_)->des0 |= OWN_BIT; wmb();} while (0)
+#define SET_OWNED(_d_) do { wmb(); (_d_)->des0 |= OWN_BIT; wmb(); } while (0)
static const unsigned int BUFFER1_SIZE_MASK = 0x7ff;
-static int
-wctc4xxp_submit(struct wctc4xxp_descriptor_ring* dr, struct tcb *c)
+static int
+wctc4xxp_submit(struct wctc4xxp_descriptor_ring *dr, struct tcb *c)
{
volatile struct wctc4xxp_descriptor *d;
unsigned int len;
@@ -1055,7 +869,7 @@
}
spin_lock_irqsave(&dr->lock, flags);
- d = wctc4xxp_descriptor(dr, dr->tail);
+ d = wctc4xxp_descriptor(dr, dr->tail);
WARN_ON(!d);
if (d->buffer1) {
spin_unlock_irqrestore(&dr->lock, flags);
@@ -1064,10 +878,10 @@
}
d->des1 &= cpu_to_le32(~(BUFFER1_SIZE_MASK));
d->des1 |= cpu_to_le32(len & BUFFER1_SIZE_MASK);
- d->buffer1 = pci_map_single(dr->pdev, c->data,
- SFRAME_SIZE, dr->direction);
-
- SET_OWNED(d); /* That's it until the hardware is done with it. */
+ d->buffer1 = pci_map_single(dr->pdev, c->data,
+ SFRAME_SIZE, dr->direction);
+
+ SET_OWNED(d); /* That's it until the hardware is done with it. */
dr->pending[dr->tail] = c;
dr->tail = ++dr->tail & DRING_MASK;
++dr->count;
@@ -1075,7 +889,7 @@
return 0;
}
-static inline struct tcb*
+static inline struct tcb*
wctc4xxp_retrieve(struct wctc4xxp_descriptor_ring *dr)
{
volatile struct wctc4xxp_descriptor *d;
@@ -1085,11 +899,11 @@
spin_lock_irqsave(&dr->lock, flags);
d = wctc4xxp_descriptor(dr, head);
if (d->buffer1 && !OWNED(d)) {
- pci_unmap_single(dr->pdev, d->buffer1,
- SFRAME_SIZE, dr->direction);
+ pci_unmap_single(dr->pdev, d->buffer1,
+ SFRAME_SIZE, dr->direction);
c = dr->pending[head];
WARN_ON(!c);
- dr->head = (++head) & DRING_MASK;
+ dr->head = (++head) & DRING_MASK;
d->buffer1 = 0;
--dr->count;
WARN_ON(!c);
@@ -1102,7 +916,7 @@
return c;
}
-static inline int wctc4xxp_getcount(struct wctc4xxp_descriptor_ring *dr)
+static inline int wctc4xxp_getcount(struct wctc4xxp_descriptor_ring *dr)
{
int count;
unsigned long flags;
@@ -1112,19 +926,19 @@
return count;
}
-static inline void
+static inline void
__wctc4xxp_setctl(struct wcdte *wc, unsigned int addr, unsigned int val)
{
outl(val, wc->iobase + addr);
}
-static inline unsigned int
+static inline unsigned int
__wctc4xxp_getctl(struct wcdte *wc, unsigned int addr)
{
return inl(wc->iobase + addr);
}
-static inline void
+static inline void
wctc4xxp_setctl(struct wcdte *wc, unsigned int addr, unsigned int val)
{
spin_lock_bh(&wc->reglock);
@@ -1132,13 +946,13 @@
spin_unlock_bh(&wc->reglock);
}
-static inline void
-wctc4xxp_receive_demand_poll(struct wcdte *wc)
+static inline void
+wctc4xxp_receive_demand_poll(struct wcdte *wc)
{
__wctc4xxp_setctl(wc, 0x0010, 0x00000000);
}
-static inline void
+static inline void
wctc4xxp_transmit_demand_poll(struct wcdte *wc)
{
__wctc4xxp_setctl(wc, 0x0008, 0x00000000);
@@ -1154,7 +968,8 @@
/* Returns the size, in bytes, of a CSM_ENCAPS packet, given the number of
* parameters used. */
-#define SIZE_WITH_N_PARAMETERS(__n) (sizeof(struct csm_encaps_hdr) + ((__n) * (sizeof(u16))))
+#define SIZE_WITH_N_PARAMETERS(__n) (sizeof(struct csm_encaps_hdr) + \
+ ((__n) * (sizeof(u16))))
/* There are 20 bytes in the ethernet header and the common CSM_ENCAPS header
* that we don't want in the length of the actual CSM_ENCAPS command */
@@ -1163,7 +978,9 @@
static const u8 dst_mac[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
static const u8 src_mac[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
-static void
+static int wctc4xxp_transmit_cmd_and_wait(struct wcdte *wc, struct tcb *cmd);
+
+static void
setup_common_header(struct wcdte *wc, struct csm_encaps_hdr *hdr)
{
memcpy(hdr->ethhdr.h_dest, dst_mac, sizeof(dst_mac));
@@ -1171,7 +988,7 @@
hdr->ethhdr.h_proto = cpu_to_be16(ETH_P_CSM_ENCAPS);
}
-static void
+static void
setup_supervisor_header(struct wcdte *wc, struct csm_encaps_hdr *hdr)
{
setup_common_header(wc, hdr);
@@ -1182,132 +999,454 @@
hdr->channel = cpu_to_be16(SUPERVISOR_CHANNEL);
}
-static void
-__wctc4xxp_create_channel_cmd(struct wcdte *wc, struct tcb *cmd, u16 timeslot)
-{
- struct csm_create_channel_cmd *c;
- c = hdr_from_cmd(cmd);
-
- BUG_ON(timeslot > 0x01ff);
-
- setup_supervisor_header(wc, &c->hdr);
-
- c->hdr.length = LENGTH_WITH_N_PARAMETERS(2);
- c->hdr.index = 0x0;
- c->hdr.type = CONFIG_CHANGE_TYPE;
- c->hdr.class = CONFIG_DEVICE_CLASS;
- c->hdr.function = cpu_to_le16(SUPVSR_CREATE_CHANNEL);
- c->hdr.reserved = 0x0000;
-
- c->channel_type = cpu_to_le16(0x0002); /* Channel type is VoIP */
- c->timeslot = cpu_to_le16(timeslot);
-
- cmd->flags |= WAIT_FOR_RESPONSE;
- cmd->data_len = sizeof(*c);
-}
-
-static struct tcb *
-wctc4xxp_create_channel_cmd(struct wcdte *wc, u16 timeslot)
-{
- struct tcb *cmd;
- if (!(cmd = alloc_cmd())) {
- return NULL;
- }
- __wctc4xxp_create_channel_cmd(wc, cmd, timeslot);
- return cmd;
-}
-
-static void
-__wctc4xxp_create_set_arm_clk_cmd(struct wcdte *wc, struct tcb *cmd)
+static void
+setup_channel_header(struct channel_pvt *pvt, struct csm_encaps_hdr *hdr)
+{
+ setup_common_header(pvt->wc, hdr);
+ hdr->op_code = cpu_to_be16(CONTROL_PACKET_OPCODE);
+ hdr->seq_num = (pvt->cmd_seqno++)&0xf;
+ hdr->channel = cpu_to_be16(pvt->chan_in_num);
+}
+
+static void
+create_supervisor_cmd(struct wcdte *wc, struct tcb *cmd, u8 type, u8 class,
+ u16 function, const u16 *parameters, int num_parameters)
{
struct csm_encaps_hdr *hdr = cmd->data;
- BUG_ON(SIZE_WITH_N_PARAMETERS(2) > cmd->data_len);
+ int i;
+
+ if (cmd->response) {
+ free_cmd(cmd->response);
+ cmd->response = NULL;
+ }
setup_supervisor_header(wc, hdr);
- hdr->length = LENGTH_WITH_N_PARAMETERS(2);
- hdr->index = 0x0;
- hdr->type = CONFIG_CHANGE_TYPE;
- hdr->class = CONFIG_DEVICE_CLASS;
- hdr->function = cpu_to_le16(0x0411);
- hdr->reserved = 0x0000;
- hdr->params[0] = cpu_to_le16(0x012c);
- hdr->params[1] = cpu_to_le16(0x0000);
-
- cmd->flags |= WAIT_FOR_RESPONSE;
- cmd->data_len = SIZE_WITH_N_PARAMETERS(2);
- return;
+ hdr->length = LENGTH_WITH_N_PARAMETERS(num_parameters);
+ hdr->index = 0;
+ hdr->type = type;
+ hdr->class = class;
+ hdr->function = cpu_to_le16(function);
+ hdr->reserved = 0;
+
+ for (i = 0; i < num_parameters; ++i)
+ hdr->params[i] = cpu_to_le16(parameters[i]);
+
+ cmd->flags = WAIT_FOR_RESPONSE;
+ cmd->data_len = SIZE_WITH_N_PARAMETERS(num_parameters);
+}
+
+static void
+create_channel_cmd(struct channel_pvt *pvt, struct tcb *cmd, u8 type, u8 class,
+ u16 function, const u16 *parameters, int num_parameters)
+{
+ int i;
+ struct csm_encaps_hdr *hdr = cmd->data;
+
+ if (cmd->response) {
+ free_cmd(cmd->response);
+ cmd->response = NULL;
+ }
+
+ setup_channel_header(pvt, hdr);
+
+ hdr->length = LENGTH_WITH_N_PARAMETERS(num_parameters);
+ hdr->index = 0;
+ hdr->type = type;
+ hdr->class = class;
+ hdr->function = cpu_to_le16(function);
+ hdr->reserved = 0;
+
+ for (i = 0; i < num_parameters; ++i)
+ hdr->params[i] = cpu_to_le16(parameters[i]);
+
+ cmd->flags = WAIT_FOR_RESPONSE;
+ cmd->data_len = SIZE_WITH_N_PARAMETERS(num_parameters);
+}
+
+static int
+send_create_channel_cmd(struct wcdte *wc, struct tcb *cmd, u16 timeslot,
+ u16 *channel_number)
+{
+ int res;
+ const u16 parameters[] = {0x0002, timeslot};
+
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE, CONFIG_DEVICE_CLASS,
+ SUPVSR_CREATE_CHANNEL, parameters, ARRAY_SIZE(parameters));
+
+ res = wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+ if (res)
+ return res;
+
+ if (0x0000 != response_header(cmd)->params[0]) {
+ /* The DTE failed to create the channel. */
+ /* TODO put some debug information here. */
+ WARN_ON(1);
+ free_cmd(cmd->response);
+ cmd->response = NULL;
+ return -EIO;
+ }
+ *channel_number = le16_to_cpu(response_header(cmd)->params[1]);
+ free_cmd(cmd->response);
+ cmd->response = NULL;
+ return 0;
+}
+
+static int
+send_set_arm_clk_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0x012c, 0x0000};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0411, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_set_spu_clk_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0x012c, 0x0000};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0412, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_tdm_select_bus_mode_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0x0004};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0417, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_set_eth_header_cmd(struct wcdte *wc, struct tcb *cmd,
+ const u8 *host_mac, const u8 *assigned_mac)
+{
+ u16 parameters[8];
+ u16 *part;
+
+ parameters[0] = 0x0001;
+ part = (u16 *)host_mac;
+ parameters[1] = part[0];
+ parameters[2] = part[1];
+ parameters[3] = part[2];
+ part = (u16 *)assigned_mac;
+ parameters[4] = part[0];
+ parameters[5] = part[1];
+ parameters[6] = part[2];
+ parameters[7] = 0x0008;
+
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0100, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_supvsr_setup_tdm_parms(struct wcdte *wc, struct tcb *cmd,
+ u8 bus_number)
+{
+ const u16 parameters[] = {0x8380, 0x0c00, 0, (bus_number << 2)&0xc};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0407, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_ip_service_config_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0x0200};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0302, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_arp_service_config_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0x0001};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0105, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_icmp_service_config_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0xff01};
+ create_supervisor_cmd(wc, cmd, CONFIG_CHANGE_TYPE,
+ CONFIG_DEVICE_CLASS, 0x0304, parameters, ARRAY_SIZE(parameters));
+ return wctc4xxp_transmit_cmd_and_wait(wc, cmd);
+}
+
+static int
+send_device_set_country_code_cmd(struct wcdte *wc, struct tcb *cmd)
+{
+ const u16 parameters[] = {0x0000};
[... 2480 lines stripped ...]
More information about the svn-commits
mailing list