summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorRyan Thomas McBride <mcbride@cvs.openbsd.org>2004-06-26 22:19:39 +0000
committerRyan Thomas McBride <mcbride@cvs.openbsd.org>2004-06-26 22:19:39 +0000
commit2a067aca6c8a9d0ae2c0257d804be5957ff172bb (patch)
treeb3fbd2b01ff2f77a07eb65b40f6c47a99a599b87 /sys
parent4c93ccd7fbf311c1d223eefe8a6fb5dcec07f704 (diff)
KNF
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/if_san_common.c139
-rw-r--r--sys/dev/pci/if_san_common.h124
2 files changed, 133 insertions, 130 deletions
diff --git a/sys/dev/pci/if_san_common.c b/sys/dev/pci/if_san_common.c
index aa4c482b9e5..a2fb3330dee 100644
--- a/sys/dev/pci/if_san_common.c
+++ b/sys/dev/pci/if_san_common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_common.c,v 1.2 2004/06/26 20:17:23 mcbride Exp $ */
+/* $OpenBSD: if_san_common.c,v 1.3 2004/06/26 22:19:38 mcbride Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -69,31 +69,28 @@
# include <dev/pci/if_san_common.h>
# include <dev/pci/if_san_obsd.h>
-/****** Defines & Macros ****************************************************/
-
#ifdef _DEBUG_
#define STATIC
#else
#define STATIC static
#endif
-/****** Function Prototypes *************************************************/
-
/* WAN link driver entry points */
#if 0
static int shutdown(sdla_t *card);
#endif
/* Miscellaneous functions */
-static int wan_ioctl(struct ifnet* ifp, int cmd, struct ifreq* ifr);
-static int sdla_isr (void* dev_id);
+static int wan_ioctl(struct ifnet*, int, struct ifreq *);
+static int sdla_isr(void *);
-static void release_hw (sdla_t *card);
+static void release_hw(sdla_t *card);
-static int wan_ioctl_dump(sdla_t* card, void* u_dump);
-static int wan_ioctl_hwprobe(struct ifnet* ifp, void* u_def);
+static int wan_ioctl_dump(sdla_t *, void *);
+static int wan_ioctl_hwprobe(struct ifnet *, void *);
-/****** Global Data **********************************************************
+/*
+ * Global Data
* Note: All data must be explicitly initialized!!!
*/
@@ -140,17 +137,18 @@ static san_detach(void)
#endif
-int san_dev_attach (void *hw, u_int8_t *devname)
+int
+san_dev_attach(void *hw, u_int8_t *devname)
{
sdla_t *card;
wanpipe_common_t *common = NULL;
int err = 0;
card=malloc(sizeof(sdla_t), M_DEVBUF, M_NOWAIT);
- if (!card){
+ if (!card) {
log(LOG_INFO, "%s: Failed allocate new card!\n",
san_drvname);
- return -EINVAL;
+ return (-EINVAL);
}
memset(card, 0, sizeof(sdla_t));
card->magic = WANPIPE_MAGIC;
@@ -160,25 +158,25 @@ int san_dev_attach (void *hw, u_int8_t *devname)
LIST_INIT(&card->dev_head);
sdla_getcfg(card->hw, SDLA_CARDTYPE, &card->type);
- if (sdla_is_te1(card->hw)){
+ if (sdla_is_te1(card->hw)) {
sdla_te_defcfg(&card->fe_te.te_cfg);
}
err = sdla_setup(card->hw);
- if (err){
+ if (err) {
log(LOG_INFO, "%s: Hardware setup Failed %d\n",
card->devname,err);
- return -EINVAL;
+ return (-EINVAL);
}
err = sdla_intr_establish(card->hw, sdla_isr, (void*)card);
- if (err){
+ if (err) {
log(LOG_INFO, "%s: Failed set interrupt handler!\n",
card->devname);
sdla_down(card->hw);
- return -EINVAL;
+ return (-EINVAL);
}
- switch (card->type){
+ switch (card->type) {
case SDLA_AFT:
#if defined(DEBUG_INIT)
log(LOG_INFO, "%s: Starting AFT Hardware Init.\n",
@@ -187,10 +185,10 @@ int san_dev_attach (void *hw, u_int8_t *devname)
common = wan_xilinx_init(card);
break;
}
- if (common == NULL){
+ if (common == NULL) {
release_hw(card);
card->configured = 0;
- return -EINVAL;
+ return (-EINVAL);
}
LIST_INSERT_HEAD(&card->dev_head, common, next);
@@ -198,12 +196,12 @@ int san_dev_attach (void *hw, u_int8_t *devname)
card->critical = 0;
card->state = WAN_DISCONNECTED;
card->ioctl = wan_ioctl;
- return 0;
+ return (0);
}
-/*============================================================================
- * Shut down WAN link driver.
+/*
+ * Shut down WAN link driver.
* o shut down adapter hardware
* o release system resources.
*
@@ -213,14 +211,14 @@ static int shutdown (sdla_t *card)
{
int err=0;
- if (card->state == WAN_UNCONFIGURED){
+ if (card->state == WAN_UNCONFIGURED) {
return 0;
}
card->state = WAN_UNCONFIGURED;
bit_set((u_int8_t*)&card->critical, PERI_CRIT);
- /* In case of piggibacking, make sure that
+ /* In case of piggibacking, make sure that
* we never try to shutdown both devices at the same
* time, because they depend on one another */
@@ -230,9 +228,9 @@ static int shutdown (sdla_t *card)
release_hw(card);
/* only free the allocated I/O range if not an S514 adapter */
- if (!card->configured){
+ if (!card->configured) {
card->hw = NULL;
- if (card->same_cpu){
+ if (card->same_cpu) {
card->same_cpu->hw = NULL;
card->same_cpu->same_cpu = NULL;
card->same_cpu=NULL;
@@ -245,7 +243,8 @@ static int shutdown (sdla_t *card)
}
#endif
-static void release_hw (sdla_t *card)
+static void
+release_hw(sdla_t *card)
{
log(LOG_INFO, "%s: Master shutting down\n",card->devname);
sdla_down(card->hw);
@@ -255,27 +254,29 @@ static void release_hw (sdla_t *card)
}
-/****** Driver IOCTL Handlers ***********************************************/
+/*
+ * Driver IOCTL Handlers
+ */
static int
-wan_ioctl(struct ifnet* ifp, int cmd, struct ifreq* ifr)
+wan_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr)
{
sdla_t *card;
wanpipe_common_t *common = WAN_IFP_TO_COMMON(ifp);
int err = 0;
- if (common == NULL){
+ if (common == NULL) {
log(LOG_INFO, "%s: Invalid softc pointer (%s:%d)!\n",
- ifp->if_xname, __FUNCTION__, __LINE__);
- return -EINVAL;
+ ifp->if_xname, __FUNCTION__, __LINE__);
+ return (-EINVAL);
}
card = common->card;
- if (card == NULL){
+ if (card == NULL) {
log(LOG_INFO, "%s: Card private structure corrupted (%s:%d)!\n",
- ifp->if_xname, __FUNCTION__, __LINE__);
- return -EINVAL;
+ ifp->if_xname, __FUNCTION__, __LINE__);
+ return (-EINVAL);
}
- switch (cmd){
+ switch (cmd) {
case SIOC_WANPIPE_HWPROBE:
err = wan_ioctl_hwprobe(ifp, ifr->ifr_data);
break;
@@ -291,25 +292,25 @@ wan_ioctl(struct ifnet* ifp, int cmd, struct ifreq* ifr)
return err;
}
-
-static int wan_ioctl_hwprobe(struct ifnet* ifp, void* u_def)
+static int
+wan_ioctl_hwprobe(struct ifnet *ifp, void *u_def)
{
- sdla_t* card = NULL;
- wanlite_def_t def;
- unsigned char* str;
- int err;
+ sdla_t *card = NULL;
+ wanlite_def_t def;
+ unsigned char *str;
+ int err;
card = ((wanpipe_common_t*)ifp->if_softc)->card;
memset(&def, 0, sizeof(wanlite_def_t));
sdla_get_hwprobe(card->hw, (void**)&str);
- if (err){
+ if (err) {
return -EINVAL;
}
str[strlen(str)] = '\0';
memcpy(def.hwprobe, str, strlen(str));
/* Get interface configuration */
- if (IS_TE1(&card->fe_te.te_cfg)){
- if (IS_T1(&card->fe_te.te_cfg)){
+ if (IS_TE1(&card->fe_te.te_cfg)) {
+ if (IS_T1(&card->fe_te.te_cfg)) {
def.iface = IF_IFACE_T1;
}else{
def.iface = IF_IFACE_E1;
@@ -318,15 +319,16 @@ static int wan_ioctl_hwprobe(struct ifnet* ifp, void* u_def)
}
err = copyout(&def, u_def, sizeof(def));
- if (err){
+ if (err) {
log(LOG_INFO, "%s: Failed to copy to user space (%d)\n",
- card->devname, __LINE__);
+ card->devname, __LINE__);
return -ENOMEM;
}
return 0;
}
-static int wan_ioctl_dump(sdla_t* card, void* u_dump)
+static int
+wan_ioctl_dump(sdla_t *card, void *u_dump)
{
sdla_dump_t dump;
void* data;
@@ -334,27 +336,27 @@ static int wan_ioctl_dump(sdla_t* card, void* u_dump)
int err = 0;
err = copyin(u_dump, &dump, sizeof(sdla_dump_t));
- if (err){
+ if (err) {
return -EFAULT;
}
sdla_getcfg(card->hw, SDLA_MEMORY, &memory);
- if (dump.magic != WANPIPE_MAGIC){
+ if (dump.magic != WANPIPE_MAGIC) {
return -EINVAL;
}
- if ((dump.offset + dump.length) > memory){
+ if ((dump.offset + dump.length) > memory) {
return -EINVAL;
}
data = malloc(dump.length, M_DEVBUF, M_NOWAIT);
- if (data == NULL){
+ if (data == NULL) {
return -ENOMEM;
}
sdla_peek(card->hw, dump.offset, data, dump.length);
err = copyout(data, dump.ptr, dump.length);
- if (err){
+ if (err) {
log(LOG_INFO, "%s: Failed to copy to user space (%d)\n",
card->devname, __LINE__);
err = -EFAULT;
@@ -363,41 +365,40 @@ static int wan_ioctl_dump(sdla_t* card, void* u_dump)
return err;
}
-/******* Miscellaneous ******************************************************/
-/*============================================================================
+/*
* SDLA Interrupt Service Routine.
* o call protocol-specific interrupt service routine, if any.
*/
-int sdla_isr (void* pcard)
+int
+sdla_isr(void *pcard)
{
- sdla_t *card = (sdla_t*)pcard;
+ sdla_t *card = (sdla_t*)pcard;
if (card == NULL || card->magic != WANPIPE_MAGIC) return 0;
- switch (card->type){
+ switch (card->type) {
case SDLA_AFT:
- if (card->isr){
+ if (card->isr) {
card->isr(card);
}
break;
}
- return 1;
+ return (1);
}
-struct mbuf* wan_mbuf_alloc(void)
+struct mbuf *
+wan_mbuf_alloc(void)
{
struct mbuf *m;
MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m != NULL){
+ if (m != NULL) {
MCLGET(m, M_DONTWAIT);
- if ((m->m_flags & M_EXT) == 0){
+ if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
m = NULL;
}
}
- return m;
+ return (m);
}
-
-/****** End *********************************************************/
diff --git a/sys/dev/pci/if_san_common.h b/sys/dev/pci/if_san_common.h
index aba543a807c..9bdb7eb318c 100644
--- a/sys/dev/pci/if_san_common.h
+++ b/sys/dev/pci/if_san_common.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_common.h,v 1.2 2004/06/26 20:17:23 mcbride Exp $ */
+/* $OpenBSD: if_san_common.h,v 1.3 2004/06/26 22:19:38 mcbride Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -42,7 +42,7 @@
#define WAN_OPENBSD_PLATFORM 0x06
#define WAN_PLATFORM_ID WAN_OPENBSD_PLATFORM
#define WANPIPE_MAGIC 0x414C4453L /* signature: 'SDLA' reversed */
-
+
#define ROUTER_NAME "wanrouter" /* in case we ever change it */
#define ROUTER_IOCTL 'W' /* for IOCTL calls */
@@ -52,10 +52,19 @@
/* IOCTL codes for /proc/router/<device> entries (up to 255) */
# define WANPIPE_DUMP _IOW(ROUTER_IOCTL, 16, wan_conf_t)
# define WANPIPE_EXEC _IOWR(ROUTER_IOCTL, 17, wan_conf_t)
-# define SIOC_WANPIPE_PIPEMON _IOWR('i', 150, struct ifreq) /* get monitor statistics */
-# define SIOC_WANPIPE_DEVICE _IOWR('i', 151, struct ifreq) /* set generic device */
-# define SIOC_WANPIPE_HWPROBE _IOWR('i', 152, struct ifreq) /* get hwprobe string */
-# define SIOC_WANPIPE_DUMP _IOWR('i', 153, struct ifreq) /* get memdump string (GENERIC) */
+
+/* get monitor statistics */
+# define SIOC_WANPIPE_PIPEMON _IOWR('i', 150, struct ifreq)
+
+/* set generic device */
+# define SIOC_WANPIPE_DEVICE _IOWR('i', 151, struct ifreq)
+
+/* get hwprobe string */
+# define SIOC_WANPIPE_HWPROBE _IOWR('i', 152, struct ifreq)
+
+/* get memdump string (GENERIC) */
+# define SIOC_WANPIPE_DUMP _IOWR('i', 153, struct ifreq)
+
/* clocking options */
#define WANOPT_EXTERNAL 0
@@ -65,9 +74,9 @@
#define WANOPT_RS232 0
#define WANOPT_V35 1
-#define WAN_UDP_FAILED_CMD 0xCF
-#define WAN_UDP_INVALID_CMD 0xCE
-#define WAN_UDP_TIMEOUT_CMD 0xAA
+#define WAN_UDP_FAILED_CMD 0xCF
+#define WAN_UDP_INVALID_CMD 0xCE
+#define WAN_UDP_TIMEOUT_CMD 0xAA
#define WAN_UDP_INVALID_NET_CMD 0xCD
#define WANOPT_NO 0
@@ -110,8 +119,7 @@ enum wan_states
#define WAN_MODEM_DTR 0x0010 /* DTR line active */
#define WAN_MODEM_RTS 0x0020 /* RTS line active */
-typedef struct wan_conf
-{
+typedef struct wan_conf {
char devname[IFNAMSIZ+1];
void* arg;
} wan_conf_t;
@@ -128,7 +136,7 @@ typedef struct wan_conf
#define UDPMGMT_REPLY 0x02
#define UDP_OFFSET 12
-#define MAX_FT1_RETRY 100
+#define MAX_FT1_RETRY 100
/* General Critical Flags */
enum {
@@ -142,16 +150,14 @@ enum {
* Data structures for IOCTL calls.
*/
-typedef struct sdla_dump /* WANPIPE_DUMP */
-{
+typedef struct sdla_dump { /* WANPIPE_DUMP */
unsigned long magic; /* for verification */
unsigned long offset; /* absolute adapter memory address */
unsigned long length; /* block length */
void* ptr; /* -> buffer */
} sdla_dump_t;
-typedef struct sdla_exec /* WANPIPE_EXEC */
-{
+typedef struct sdla_exec { /* WANPIPE_EXEC */
unsigned long magic; /* for verification */
void* cmd; /* -> command structure */
void* data; /* -> data buffer */
@@ -159,23 +165,21 @@ typedef struct sdla_exec /* WANPIPE_EXEC */
#define TRC_INCOMING_FRM 0x00
#define TRC_OUTGOING_FRM 0x01
-typedef struct
-{
+typedef struct {
unsigned char status;
- unsigned char data_avail;
+ unsigned char data_avail;
unsigned short real_length;
- unsigned short time_stamp;
- unsigned long sec;
- unsigned long usec;
+ unsigned short time_stamp;
+ unsigned long sec;
+ unsigned long usec;
unsigned char data[0];
} wan_trace_pkt_t;
-typedef struct wan_trace
-{
+typedef struct wan_trace {
unsigned long tracing_enabled;
struct ifqueue ifq;
unsigned int trace_timeout;
- unsigned int max_trace_queue;
+ unsigned int max_trace_queue;
} wan_trace_t;
@@ -184,12 +188,12 @@ typedef struct wan_trace
*******************************************************/
#define GLOBAL_UDP_SIGNATURE "WANPIPE"
#define GLOBAL_UDP_SIGNATURE_LEN 7
-#define UDPMGMT_UDP_PROTOCOL 0x11
+#define UDPMGMT_UDP_PROTOCOL 0x11
#define WAN_UDP_CMD_START 0x60
#define WAN_GET_PROTOCOL (WAN_UDP_CMD_START+0)
#define WAN_GET_PLATFORM (WAN_UDP_CMD_START+1)
#define WAN_GET_MEDIA_TYPE (WAN_UDP_CMD_START+2)
-#define WAN_UDP_CMD_END 0x6F
+#define WAN_UDP_CMD_END 0x6F
#define WAN_FE_CMD_START 0x90
#define WAN_FE_CMD_END 0x9F
@@ -198,7 +202,7 @@ typedef struct wan_trace
#define WAN_INTERFACE_CMD_END 0xAF
#define WAN_FE_UDP_CMD_START 0xB0
-#define WAN_FE_UDP_CMD_END 0xBF
+#define WAN_FE_UDP_CMD_END 0xBF
typedef struct {
unsigned char signature[8];
@@ -237,7 +241,7 @@ typedef struct wan_udp_hdr{
#define wan_udphdr_aft_num_frames wan_udphdr_u.aft.trace_info.num_frames
#define wan_udphdr_aft_ismoredata wan_udphdr_u.aft.trace_info.ismoredata
-#define wan_udphdr_aft_data wan_udphdr_u.aft.data
+#define wan_udphdr_aft_data wan_udphdr_u.aft.data
#define wan_udphdr_data wan_udphdr_u.data
} wan_udp_hdr_t;
@@ -268,11 +272,13 @@ typedef struct wan_udp_hdr{
#endif
#define is_digit(ch) (((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')?1:0)
-#define is_alpha(ch) ((((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'z')||\
- ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'Z'))?1:0)
-#define is_hex_digit(ch) ((((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')||\
- ((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'f')||\
- ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'F'))?1:0)
+
+#define is_alpha(ch) ((((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'z')|| \
+ ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'Z'))?1:0)
+
+#define is_hex_digit(ch) ((((ch)>=(unsigned)'0'&&(ch)<=(unsigned)'9')|| \
+ ((ch)>=(unsigned)'a'&&(ch)<=(unsigned)'f')||\
+ ((ch)>=(unsigned)'A'&&(ch)<=(unsigned)'F'))?1:0)
#if !defined(offsetof)
# define offsetof(type, member) ((size_t)(&((type*)0)->member))
#endif
@@ -295,23 +301,22 @@ typedef struct wan_udp_pkt {
#define wan_udp_command wan_udp_hdr.wan_udphdr_command
#define wan_udp_data_len wan_udp_hdr.wan_udphdr_data_len
#define wan_udp_return_code wan_udp_hdr.wan_udphdr_return_code
-#define wan_udp_hdlc_PF_bit wan_udp_hdr.wan_udphdr_hdlc_PF_bit
-#define wan_udp_fr_dlci wan_udp_hdr.wan_udphdr_fr_dlci
-#define wan_udp_fr_attr wan_udp_hdr.wan_udphdr_fr_attr
-#define wan_udp_fr_rxlost1 wan_udp_hdr.wan_udphdr_fr_rxlost1
-#define wan_udp_fr_rxlost2 wan_udp_hdr.wan_udphdr_fr_rxlost2
+#define wan_udp_hdlc_PF_bit wan_udp_hdr.wan_udphdr_hdlc_PF_bit
+#define wan_udp_fr_dlci wan_udp_hdr.wan_udphdr_fr_dlci
+#define wan_udp_fr_attr wan_udp_hdr.wan_udphdr_fr_attr
+#define wan_udp_fr_rxlost1 wan_udp_hdr.wan_udphdr_fr_rxlost1
+#define wan_udp_fr_rxlost2 wan_udp_hdr.wan_udphdr_fr_rxlost2
#define wan_udp_chdlc_num_frames wan_udp_hdr.wan_udphdr_chdlc_num_frames
#define wan_udp_chdlc_ismoredata wan_udp_hdr.wan_udphdr_chdlc_ismoredata
#define wan_udp_chdlc_data wan_udp_hdr.wan_udphdr_chdlc_data
#define wan_udp_aft_num_frames wan_udp_hdr.wan_udphdr_aft_num_frames
-#define wan_udp_aft_ismoredata wan_udp_hdr.wan_udphdr_aft_ismoredata
+#define wan_udp_aft_ismoredata wan_udp_hdr.wan_udphdr_aft_ismoredata
#define wan_udp_data wan_udp_hdr.wan_udphdr_data
} wan_udp_pkt_t;
#define WAN_IFP_TO_COMMON(ifp) (wanpipe_common_t*)((ifp)->if_softc)
-typedef struct wanpipe_common
-{
+typedef struct wanpipe_common {
struct sppp ifp;
void *card;
struct timeout dev_timer;
@@ -321,17 +326,16 @@ typedef struct wanpipe_common
LIST_ENTRY(wanpipe_common) next;
} wanpipe_common_t;
-typedef struct
-{
- unsigned long time_slot_map;
- unsigned long logic_ch_map;
- unsigned char num_of_time_slots;
- unsigned char top_logic_ch;
- unsigned long bar;
- void *trace_info;
- void *dev_to_ch_map[MAX_E1_CHANNELS];
- void *rx_dma_ptr;
- void *tx_dma_ptr;
+typedef struct {
+ unsigned long time_slot_map;
+ unsigned long logic_ch_map;
+ unsigned char num_of_time_slots;
+ unsigned char top_logic_ch;
+ unsigned long bar;
+ void *trace_info;
+ void *dev_to_ch_map[MAX_E1_CHANNELS];
+ void *rx_dma_ptr;
+ void *tx_dma_ptr;
unsigned short num_of_ch;/* Number of logical channels */
unsigned short dma_per_ch;/* DMA buffers per logic channel */
unsigned short mru_trans;/* MRU of transparent channels */
@@ -347,8 +351,7 @@ typedef struct
* This structure is needed because we handle multiple cards, otherwise
* static data would do it.
*/
-typedef struct sdla
-{
+typedef struct sdla {
unsigned magic;
char devname[IFNAMSIZ+1]; /* card name */
void *hw; /* hw configuration */
@@ -368,12 +371,11 @@ typedef struct sdla
unsigned long configured; /* configurations status */
int (*del_if) (struct sdla*, struct ifnet*);
void (*isr)(struct sdla*); /* interrupt service routine */
- void (*poll)(struct sdla*); /* polling routine */
+ void (*poll)(struct sdla*); /* polling routine */
int (*exec)(struct sdla*, void*, void*);
int (*ioctl) (struct ifnet*, int, struct ifreq*);
- union
- {
+ union {
sdla_xilinx_t xilinx;
} u;
@@ -383,9 +385,9 @@ typedef struct sdla
sdla_te_softc_t te_sc;
} u_fe;
- unsigned char front_end_status;
- WRITE_FRONT_END_REG_T* write_front_end_reg;
- READ_FRONT_END_REG_T* read_front_end_reg;
+ unsigned char front_end_status;
+ WRITE_FRONT_END_REG_T* write_front_end_reg;
+ READ_FRONT_END_REG_T* read_front_end_reg;
void (*te_enable_timer) (void*);
void (*te_link_state) (void*);