summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorCan Erkin Acar <canacar@cvs.openbsd.org>2005-04-01 21:42:37 +0000
committerCan Erkin Acar <canacar@cvs.openbsd.org>2005-04-01 21:42:37 +0000
commit682ef1f846d5b44e96c516dbcdc3bb8c6d4e7ce2 (patch)
tree1c3196a3c60c43cb6d7e67ecb18afed804b6fe9d /sys/dev
parent8a61c85fb5ebd735393a77a5c3f5e9f8076290c9 (diff)
Improve san(4) driver:
* Some KNF, fix return values (from -Exxx to Exxx) * Some string handling paranoia. * Use ifconfig media options to switch between ppp and cHDLC modes, based on patch from claudio@ * tcpdump works, patch from claudio@ * ppp mode now works. Lots of testing & feedback by Greg Mortensen, Additional testing Sean Knox ok alex@, go go go deraadt@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/pci/if_san_common.c113
-rw-r--r--sys/dev/pci/if_san_common.h4
-rw-r--r--sys/dev/pci/if_san_obsd.c190
-rw-r--r--sys/dev/pci/if_san_obsd.h4
-rw-r--r--sys/dev/pci/if_san_te1.c65
-rw-r--r--sys/dev/pci/if_san_te1.h4
-rw-r--r--sys/dev/pci/if_san_xilinx.c112
-rw-r--r--sys/dev/pci/if_sandrv.c180
-rw-r--r--sys/dev/pci/if_sandrv.h4
9 files changed, 350 insertions, 326 deletions
diff --git a/sys/dev/pci/if_san_common.c b/sys/dev/pci/if_san_common.c
index b02e06ad100..801c91e971d 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.6 2005/03/01 18:37:06 mcbride Exp $ */
+/* $OpenBSD: if_san_common.c,v 1.7 2005/04/01 21:42:35 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -104,14 +104,15 @@ static san_detach(void)
int err = 0;
card = LIST_FIRST(&wan_cardlist);
- while (card){
- if (card->disable_comm){
+ while (card) {
+ if (card->disable_comm)
card->disable_comm(card);
- }
- while ((common = LIST_FIRST(&card->dev_head))){
+
+ while ((common = LIST_FIRST(&card->dev_head))) {
LIST_REMOVE(common, next);
- if (card->del_if){
- struct ifnet *ifp = (struct ifnet*)&common->ifp;
+ if (card->del_if) {
+ struct ifnet *ifp =
+ (struct ifnet*)&common->ifp;
log(LOG_INFO, "%s: Deleting interface...\n",
ifp->if_xname);
card->del_if(card, ifp);
@@ -136,7 +137,7 @@ static san_detach(void)
int
-san_dev_attach(void *hw, u_int8_t *devname)
+san_dev_attach(void *hw, u_int8_t *devname, int namelen)
{
sdla_t *card;
wanpipe_common_t *common = NULL;
@@ -146,32 +147,31 @@ san_dev_attach(void *hw, u_int8_t *devname)
if (!card) {
log(LOG_INFO, "%s: Failed allocate new card!\n",
san_drvname);
- return (-EINVAL);
+ return (EINVAL);
}
- memset(card, 0, sizeof(sdla_t));
+ bzero(card, sizeof(sdla_t));
card->magic = WANPIPE_MAGIC;
- wanpipe_generic_name(card, card->devname);
- bcopy(card->devname, devname, strlen(card->devname));
+ wanpipe_generic_name(card, card->devname, sizeof(card->devname));
+ strlcpy(devname, card->devname, namelen);
card->hw = hw;
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) {
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) {
log(LOG_INFO, "%s: Failed set interrupt handler!\n",
card->devname);
sdla_down(card->hw);
- return (-EINVAL);
+ return (EINVAL);
}
switch (card->type) {
@@ -186,7 +186,7 @@ san_dev_attach(void *hw, u_int8_t *devname)
if (common == NULL) {
release_hw(card);
card->configured = 0;
- return (-EINVAL);
+ return (EINVAL);
}
LIST_INSERT_HEAD(&card->dev_head, common, next);
@@ -205,7 +205,8 @@ san_dev_attach(void *hw, u_int8_t *devname)
*
*/
#if 0
-static int shutdown (sdla_t *card)
+static int
+shutdown (sdla_t *card)
{
int err=0;
@@ -261,7 +262,7 @@ 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;
+ int err;
SAN_ASSERT(common == NULL);
SAN_ASSERT(common->card == NULL);
@@ -275,7 +276,7 @@ wan_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr)
break;
default:
- err = 1;
+ err = ENOTTY;
break;
}
return err;
@@ -293,32 +294,31 @@ wan_ioctl_hwprobe(struct ifnet *ifp, void *u_def)
SAN_ASSERT(common == NULL);
SAN_ASSERT(common->card == NULL);
card = common->card;
- memset(&def, 0, sizeof(wanlite_def_t));
+ bzero(&def, sizeof(wanlite_def_t));
/* Get protocol type */
def.proto = common->protocol;
/* Get hardware configuration */
err = sdla_get_hwprobe(card->hw, (void**)&str);
- if (err) {
- return -EINVAL;
- }
- str[strlen(str)] = '\0';
- memcpy(def.hwprobe, str, strlen(str));
+ if (err)
+ return EINVAL;
+
+ strlcpy(def.hwprobe, str, sizeof(def.hwprobe));
/* Get interface configuration */
if (IS_TE1(&card->fe_te.te_cfg)) {
- if (IS_T1(&card->fe_te.te_cfg)) {
+ if (IS_T1(&card->fe_te.te_cfg))
def.iface = IF_IFACE_T1;
- }else{
+ else
def.iface = IF_IFACE_E1;
- }
- memcpy(&def.te_cfg, &card->fe_te.te_cfg, sizeof(sdla_te_cfg_t));
+
+ bcopy(&card->fe_te.te_cfg, &def.te_cfg, sizeof(sdla_te_cfg_t));
}
err = copyout(&def, u_def, sizeof(def));
if (err) {
log(LOG_INFO, "%s: Failed to copy to user space (%d)\n",
card->devname, __LINE__);
- return -ENOMEM;
+ return ENOMEM;
}
return 0;
}
@@ -332,30 +332,25 @@ wan_ioctl_dump(sdla_t *card, void *u_dump)
int err = 0;
err = copyin(u_dump, &dump, sizeof(sdla_dump_t));
- if (err) {
- return -EFAULT;
- }
+ if (err)
+ return err;
sdla_getcfg(card->hw, SDLA_MEMORY, &memory);
- if (dump.magic != WANPIPE_MAGIC) {
- return -EINVAL;
- }
+ if (dump.magic != WANPIPE_MAGIC)
+ return EINVAL;
- if ((dump.offset + dump.length) > memory) {
- return -EINVAL;
- }
+ if ((dump.offset + dump.length) > memory)
+ return EINVAL;
data = malloc(dump.length, M_DEVBUF, M_NOWAIT);
- if (data == NULL) {
- return -ENOMEM;
- }
+ if (data == NULL)
+ return ENOMEM;
sdla_peek(card->hw, dump.offset, data, dump.length);
err = copyout(data, dump.ptr, dump.length);
if (err) {
log(LOG_INFO, "%s: Failed to copy to user space (%d)\n",
card->devname, __LINE__);
- err = -EFAULT;
}
free(data, M_DEVBUF);
return err;
@@ -371,52 +366,54 @@ sdla_isr(void *pcard)
{
sdla_t *card = (sdla_t*)pcard;
- if (card == NULL || card->magic != WANPIPE_MAGIC) return 0;
+ if (card == NULL || card->magic != WANPIPE_MAGIC)
+ return 0;
switch (card->type) {
case SDLA_AFT:
- if (card->isr) {
+ if (card->isr)
card->isr(card);
- }
break;
}
return (1);
}
+// XXX check usage, why is len not used ???
struct mbuf*
wan_mbuf_alloc(int len)
{
struct mbuf *m;
- if (len) {
+ if (len)
MGETHDR(m, M_DONTWAIT, MT_DATA);
- } else {
+ else
MGET(m, M_DONTWAIT, MT_DATA);
- }
+
if (m != NULL) {
- if (m->m_flags & M_PKTHDR) {
+ if (m->m_flags & M_PKTHDR)
m->m_pkthdr.len = 0;
- }
+
m->m_len = 0;
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
return NULL;
}
+
m->m_data += 16;
- return (m);
}
- return NULL;
+ return (m);
}
+// XXX check len while copy?
int
wan_mbuf_to_buffer(struct mbuf **m_org)
{
struct mbuf *m = *m_org, *new = NULL;
- if (m == NULL){
- return -EINVAL;
- }
+ if (m == NULL)
+ return EINVAL;
+
new = wan_mbuf_alloc(0);
if (new){
struct mbuf *tmp = m;
@@ -431,6 +428,6 @@ wan_mbuf_to_buffer(struct mbuf **m_org)
*m_org = new;
return 0;
}
- return -EINVAL;
+ return EINVAL;
}
diff --git a/sys/dev/pci/if_san_common.h b/sys/dev/pci/if_san_common.h
index e40c6158f44..cc449b0547f 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.6 2005/03/01 18:37:06 mcbride Exp $ */
+/* $OpenBSD: if_san_common.h,v 1.7 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -304,7 +304,7 @@ typedef struct wan_udp_hdr{
if (a){ \
log(LOG_INFO, "%s:%d: Critical Error!\n", \
__FUNCTION__,__LINE__); \
- return (-EINVAL); \
+ return (EINVAL); \
}
/****** Data Structures *****************************************************/
diff --git a/sys/dev/pci/if_san_obsd.c b/sys/dev/pci/if_san_obsd.c
index 677ab5debe9..9e539def07d 100644
--- a/sys/dev/pci/if_san_obsd.c
+++ b/sys/dev/pci/if_san_obsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_obsd.c,v 1.8 2005/03/02 15:39:47 claudio Exp $ */
+/* $OpenBSD: if_san_obsd.c,v 1.9 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -74,6 +74,8 @@
#define STATIC static
#endif
+#define PPP_HEADER_LEN 4 /* should be globaly defined by sppp */
+
static sdla_t *wanpipe_generic_getcard(struct ifnet *);
static int wanpipe_generic_ioctl(struct ifnet *, u_long, caddr_t);
@@ -105,16 +107,11 @@ wanpipe_generic_getcard(struct ifnet *ifp)
}
int
-wanpipe_generic_name(sdla_t *card, char *ifname)
+wanpipe_generic_name(sdla_t *card, char *ifname, int len)
{
static int ifunit = 0;
-#if 0
- char if_name[IFNAMSIZ+1];
- snprintf(if_name, strlen(if_name), ifname_format, ifunit++);
- bcopy(if_name, ifname, strlen(if_name));
-#endif
- snprintf(ifname, IFNAMSIZ+1, san_ifname_format, ifunit++);
+ snprintf(ifname, len, san_ifname_format, ifunit++);
return (0);
}
@@ -123,17 +120,20 @@ wanpipe_generic_register(sdla_t *card, struct ifnet *ifp, char *ifname)
{
wanpipe_common_t* common = WAN_IFP_TO_COMMON(ifp);
- if (ifname == NULL || strlen(ifname) > IFNAMSIZ) {
- return (-EINVAL);
- } else {
+ if (ifname == NULL || strlen(ifname) > IFNAMSIZ)
+ return (EINVAL);
+ else
bcopy(ifname, ifp->if_xname, strlen(ifname));
- }
+
IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN);
ifp->if_mtu = PP_MTU;
ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
common->protocol = IF_PROTO_CISCO;
+
((struct sppp *)ifp)->pp_flags |= PP_CISCO;
((struct sppp *)ifp)->pp_flags |= PP_KEEPALIVE;
+ ((struct sppp *)ifp)->pp_framebytes = 3;
+
ifp->if_ioctl = wanpipe_generic_ioctl; /* Will set from new_if() */
ifp->if_start = wanpipe_generic_start;
ifp->if_watchdog = wanpipe_generic_watchdog;
@@ -141,17 +141,19 @@ wanpipe_generic_register(sdla_t *card, struct ifnet *ifp, char *ifname)
if_attach(ifp);
if_alloc_sadl(ifp);
sppp_attach(ifp);
+
#if NBPFILTER > 0
- bpfattach(&ifp->if_bpf, ifp, DLT_NULL, 4);
+ bpfattach(&ifp->if_bpf, ifp, DLT_PPP, PPP_HEADER_LEN);
#endif /* NBPFILTER > 0 */
+
return (0);
}
void
wanpipe_generic_unregister(struct ifnet *ifp)
{
- log(LOG_INFO, "%s: Unregister interface!\n",
- ifp->if_xname);
+ log(LOG_INFO, "%s: Unregister interface!\n", ifp->if_xname);
+
sppp_detach(ifp);
if_free_sadl(ifp);
if_detach(ifp);
@@ -163,16 +165,10 @@ wanpipe_generic_start(struct ifnet *ifp)
sdla_t *card;
struct mbuf *opkt;
int err = 0;
-#if NBPFILTER > 0
-#if 0
- struct mbuf m0;
- u_int32_t af = AF_INET;
-#endif
-#endif /* NBPFILTER > 0 */
- if ((card = wanpipe_generic_getcard(ifp)) == NULL) {
+ if ((card = wanpipe_generic_getcard(ifp)) == NULL)
return;
- }
+
while (1) {
if (sppp_isempty(ifp)) {
/* No more packets in send queue */
@@ -189,28 +185,19 @@ wanpipe_generic_start(struct ifnet *ifp)
}
/* report the packet to BPF if present and attached */
#if NBPFILTER > 0
- if (ifp->if_bpf) {
-#if 0
- m0.m_next = opkt;
- m0.m_len = 4;
- m0.m_data = (char*)&af;
- bpf_mtap(ifp->if_bpf, &m0);
-#endif
+ if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, opkt);
- }
#endif /* NBPFILTER > 0 */
- if (wan_mbuf_to_buffer(&opkt)){
+ if (wan_mbuf_to_buffer(&opkt)) {
m_freem(opkt);
break;
}
err = card->iface_send(opkt, ifp);
- if (err) {
+ if (err)
break;
- }
}
- return;
}
@@ -225,12 +212,19 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
unsigned long ts_map;
int err = 0, s;
- if ((card = wanpipe_generic_getcard(ifp)) == NULL) {
- return (-EINVAL);
- }
+ if ((card = wanpipe_generic_getcard(ifp)) == NULL)
+ return (EINVAL);
+
s = splnet();
+
switch (cmd) {
case SIOCSIFADDR:
+ // XXX because sppp does an implicit setflags
+ log(LOG_INFO, "%s: Bringing interface up.\n",
+ ifp->if_xname);
+ if (card->iface_up)
+ card->iface_up(ifp);
+ wanpipe_generic_start(ifp);
err = 1;
break;
@@ -239,15 +233,14 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
if (card->state != WAN_DISCONNECTED) {
log(LOG_INFO, "%s: Unable to change media type!\n",
ifp->if_xname);
- err = -EINVAL;
- goto ioctl_out;
- }
- err = ifmedia_ioctl(ifp, ifr, &common->ifm, cmd);
- break;
+ err = EINVAL;
+ } else
+ err = ifmedia_ioctl(ifp, ifr, &common->ifm, cmd);
+ goto ioctl_out;
case SIOCGIFMEDIA:
err = ifmedia_ioctl(ifp, ifr, &common->ifm, cmd);
- break;
+ goto ioctl_out;
case SIOCSIFTIMESLOT:
if ((err = suser(p, p->p_acflag)) != 0)
@@ -255,21 +248,20 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
if (card->state != WAN_DISCONNECTED) {
log(LOG_INFO, "%s: Unable to change timeslot map!\n",
ifp->if_xname);
- err = -EINVAL;
+ err = EINVAL;
goto ioctl_out;
}
+
err = copyin(ifr->ifr_data, &ts_map, sizeof(ts_map));
- if (err)
- goto ioctl_out;
- sdla_te_settimeslot(card, ts_map);
- break;
+ if (err == 0)
+ sdla_te_settimeslot(card, ts_map);
+
+ goto ioctl_out;
case SIOCGIFTIMESLOT:
ts_map = sdla_te_gettimeslot(card);
err = copyout(ifr->ifr_data, &ts_map, sizeof(ts_map));
- if (err)
- goto ioctl_out;
- break;
+ goto ioctl_out;
case SIOCSIFFLAGS:
/*
@@ -277,48 +269,45 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
** If down - disable communications. IFF_UP is taken
** care of before entering this function.
*/
+ err = 1;
if ((ifp->if_flags & IFF_UP) == 0) {
+ if ((ifp->if_flags & IFF_RUNNING) == 0)
+ break;
/* bring it down */
log(LOG_INFO, "%s: Bringing interface down.\n",
ifp->if_xname);
- if (!(((struct sppp *)ifp)->pp_flags & PP_CISCO)){
- ((struct sppp*)ifp)->pp_down((struct sppp*)ifp);
- }
- if (card->iface_down) {
+ if (card->iface_down)
card->iface_down(ifp);
- }
- }else{ /* bring it up */
+ } else { /* bring it up */
+ if (ifp->if_flags & IFF_RUNNING)
+ break;
log(LOG_INFO, "%s: Bringing interface up.\n",
ifp->if_xname);
- if (card->iface_up) {
+ if (card->iface_up)
card->iface_up(ifp);
- }
- if (!(((struct sppp *)ifp)->pp_flags & PP_CISCO)){
- ((struct sppp*)ifp)->pp_up((struct sppp*)ifp);
- }
wanpipe_generic_start(ifp);
}
- err = 1;
break;
case SIOC_WANPIPE_DEVICE:
- err = copyin(ifr->ifr_data,
- &ifsettings,
- sizeof(struct if_settings));
+ err = copyin(ifr->ifr_data, &ifsettings,
+ sizeof(struct if_settings));
+
if (err) {
log(LOG_INFO, "%s: Failed to copy from user space!\n",
card->devname);
goto ioctl_out;
}
+
switch (ifsettings.type) {
case IF_GET_PROTO:
ifsettings.type = common->protocol;
err = copyout(&ifsettings, ifr->ifr_data,
sizeof(struct if_settings));
- if (err) {
- log(LOG_INFO, "%s: Failed to copy to uspace!\n",
+ if (err)
+ log(LOG_INFO,
+ "%s: Failed to copy to uspace!\n",
card->devname);
- }
break;
case IF_PROTO_CISCO:
@@ -334,14 +323,14 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
goto ioctl_out;
err = wp_lite_set_te1_cfg(ifp, (struct ifreq*)data);
break;
+
default:
- if (card->iface_ioctl) {
+ if (card->iface_ioctl)
err = card->iface_ioctl(ifp, cmd,
(struct ifreq*)data);
- }
break;
}
- break;
+ goto ioctl_out;
default:
if (card->iface_ioctl) {
@@ -351,9 +340,9 @@ wanpipe_generic_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
break;
}
- if (err) {
+ if (err)
err = sppp_ioctl(ifp, cmd, data);
- }
+
ioctl_out:
splx(s);
return (err);
@@ -382,10 +371,6 @@ wanpipe_generic_input(struct ifnet *ifp, struct mbuf *m)
{
sdla_t *card;
#if NBPFILTER > 0
-#if 0
- struct mbuf m0;
- u_int32_t af = AF_INET;
-#endif
#endif /* NBPFILTER > 0 */
if ((card = wanpipe_generic_getcard(ifp)) == NULL) {
@@ -393,15 +378,8 @@ wanpipe_generic_input(struct ifnet *ifp, struct mbuf *m)
}
m->m_pkthdr.rcvif = ifp;
#if NBPFILTER > 0
- if (ifp->if_bpf) {
-#if 0
- m0.m_next = m;
- m0.m_len = 4;
- m0.m_data = (char*)&af;
- bpf_mtap(ifp->if_bpf, &m0);
-#endif
+ if (ifp->if_bpf)
bpf_mtap(ifp->if_bpf, m);
- }
#endif /* NBPFILTER > 0 */
ifp->if_ipackets ++;
ifp->if_ibytes += m->m_len;
@@ -409,7 +387,8 @@ wanpipe_generic_input(struct ifnet *ifp, struct mbuf *m)
return (0);
}
-int wp_lite_set_proto(struct ifnet *ifp, struct ifreq *ifr)
+int
+wp_lite_set_proto(struct ifnet *ifp, struct ifreq *ifr)
{
wanpipe_common_t *common;
struct if_settings *ifsettings;
@@ -418,50 +397,55 @@ int wp_lite_set_proto(struct ifnet *ifp, struct ifreq *ifr)
if ((common = ifp->if_softc) == NULL) {
log(LOG_INFO, "%s: Private structure is null!\n",
ifp->if_xname);
- return (-EINVAL);
+ return (EINVAL);
}
- ifsettings = (struct if_settings*)ifr->ifr_data;
+
+ ifsettings = (struct if_settings*) ifr->ifr_data;
+
switch (ifsettings->type) {
case IF_PROTO_CISCO:
+ if (common->protocol == IF_PROTO_CISCO)
+ return 0;
((struct sppp *)ifp)->pp_flags |= PP_CISCO;
((struct sppp *)ifp)->pp_flags |= PP_KEEPALIVE;
common->protocol = IF_PROTO_CISCO;
break;
case IF_PROTO_PPP:
+ if (common->protocol == IF_PROTO_PPP)
+ return 0;
((struct sppp *)ifp)->pp_flags &= ~PP_CISCO;
- ((struct sppp *)ifp)->pp_flags &= ~PP_KEEPALIVE;
+ ((struct sppp *)ifp)->pp_flags |= PP_KEEPALIVE;
common->protocol = IF_PROTO_PPP;
break;
}
+
err = sppp_ioctl(ifp, SIOCSIFFLAGS, ifr);
return (err);
}
-int wp_lite_set_te1_cfg(struct ifnet *ifp, struct ifreq *ifr)
+int
+wp_lite_set_te1_cfg(struct ifnet *ifp, struct ifreq *ifr)
{
sdla_t *card;
struct if_settings *ifsettings;
sdla_te_cfg_t te_cfg;
int err = 0;
- if ((card = wanpipe_generic_getcard(ifp)) == NULL) {
- return (-EINVAL);
- }
+ if ((card = wanpipe_generic_getcard(ifp)) == NULL)
+ return (EINVAL);
+
ifsettings = (struct if_settings*)ifr->ifr_data;
- err = copyin(ifsettings->ifs_te1,
- &te_cfg,
- sizeof(sdla_te_cfg_t));
+ err = copyin(ifsettings->ifs_te1, &te_cfg, sizeof(sdla_te_cfg_t));
- if (ifsettings->flags & SANCFG_CLOCK_FLAG){
+ if (ifsettings->flags & SANCFG_CLOCK_FLAG)
card->fe_te.te_cfg.te_clock = te_cfg.te_clock;
- }
+
switch (ifsettings->type) {
case IF_IFACE_T1:
- if (ifsettings->flags & SANCFG_LBO_FLAG){
+ if (ifsettings->flags & SANCFG_LBO_FLAG)
card->fe_te.te_cfg.lbo = te_cfg.lbo;
- }
break;
}
+
return (err);
}
-
diff --git a/sys/dev/pci/if_san_obsd.h b/sys/dev/pci/if_san_obsd.h
index b0050fdc21d..250fbe92b02 100644
--- a/sys/dev/pci/if_san_obsd.h
+++ b/sys/dev/pci/if_san_obsd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_obsd.h,v 1.4 2004/12/07 06:10:24 mcbride Exp $ */
+/* $OpenBSD: if_san_obsd.h,v 1.5 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -92,7 +92,7 @@ typedef struct {
# if defined(_KERNEL)
struct ifnet *wanpipe_generic_alloc (sdla_t *);
void wanpipe_generic_free (struct ifnet *);
-int wanpipe_generic_name (sdla_t *, char *);
+int wanpipe_generic_name (sdla_t *, char *, int);
int wanpipe_generic_register(sdla_t *, struct ifnet *, char *);
void wanpipe_generic_unregister(struct ifnet *);
int wanpipe_generic_open(struct ifnet *);
diff --git a/sys/dev/pci/if_san_te1.c b/sys/dev/pci/if_san_te1.c
index 8cc76449369..385d024e8e0 100644
--- a/sys/dev/pci/if_san_te1.c
+++ b/sys/dev/pci/if_san_te1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_te1.c,v 1.7 2005/03/01 18:37:07 mcbride Exp $ */
+/* $OpenBSD: if_san_te1.c,v 1.8 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -41,6 +41,7 @@
#include <sys/errno.h>
#include <sys/mbuf.h>
#include <sys/socket.h>
+#include <sys/sockio.h>
#include <sys/kernel.h>
#include <sys/time.h>
#include <sys/timeout.h>
@@ -55,6 +56,7 @@
#include <netinet/ip.h>
#include <dev/pci/if_san_common.h>
+#include <dev/pci/if_san_obsd.h>
@@ -1567,7 +1569,7 @@ WriteTPSCReg(sdla_t *card, int reg, int channel, unsigned char value)
if (busy_flag == 1) {
log(LOG_INFO, "%s: Failed to write to TPSC Reg[%02x]<-%02x!\n",
card->devname, reg, value);
- err = -EBUSY;
+ err = EBUSY;
goto write_tpsc_done;
}
@@ -1579,7 +1581,7 @@ WriteTPSCReg(sdla_t *card, int reg, int channel, unsigned char value)
for (i = 0; i < MAX_BUSY_READ; i++) {
temp = READ_REG(REG_TPSC_MICRO_ACCESS_STATUS);
if ((temp & BIT_TPSC_BUSY) == 0x0) {
- err = -EBUSY;
+ err = EBUSY;
goto write_tpsc_done;
}
}
@@ -1672,7 +1674,7 @@ WriteRPSCReg(sdla_t* card, int reg, int channel, unsigned char value)
if (busy_flag == 1) {
log(LOG_INFO, "%s: Failed to write to RPSC Reg[%02x]<-%02x!\n",
card->devname, reg, value);
- err = -EBUSY;
+ err = EBUSY;
goto write_rpsc_done;
}
@@ -1683,7 +1685,7 @@ WriteRPSCReg(sdla_t* card, int reg, int channel, unsigned char value)
for (i = 0; i < MAX_BUSY_READ; i++) {
temp = READ_REG(REG_RPSC_MICRO_ACCESS_STATUS);
if ((temp & BIT_RPSC_BUSY) == 0x0) {
- err = -EBUSY;
+ err = EBUSY;
goto write_rpsc_done;
}
}
@@ -1901,7 +1903,8 @@ static int DisableRxChannel(sdla_t* card, int channel)
/*
* Set default T1 configuration
*/
-int sdla_te_defcfg(void *pte_cfg)
+int
+sdla_te_defcfg(void *pte_cfg)
{
sdla_te_cfg_t *te_cfg = (sdla_te_cfg_t*)pte_cfg;
@@ -1916,13 +1919,40 @@ int sdla_te_defcfg(void *pte_cfg)
}
-int sdla_te_setcfg(void *pcard, struct ifmedia *ifm)
+int
+sdla_te_setcfg(struct ifnet *ifp, struct ifmedia *ifm)
{
- sdla_t *card = (sdla_t*)pcard;
- sdla_te_cfg_t *te_cfg = (sdla_te_cfg_t*)&card->fe_te.te_cfg;
+ struct ifreq ifr;
+ struct if_settings ifs;
+
+ wanpipe_common_t *common = (wanpipe_common_t *)ifp->if_softc;
+ sdla_t *card = (sdla_t*)common->card;
+ sdla_te_cfg_t *te_cfg = (sdla_te_cfg_t*)&card->fe_te.te_cfg;
+ int ret;
+
+ if (IFM_TYPE(ifm->ifm_media) != IFM_TDM)
+ return (EINVAL);
+
+ bcopy(ifp->if_xname, ifr.ifr_name, sizeof(ifr.ifr_name));
+ bzero(&ifs, sizeof(ifs));
+ ifr.ifr_data = (caddr_t) &ifs;
+
+ if ((ifm->ifm_media & IFM_OMASK) == IFM_TDM_PPP)
+ ifs.type = IF_PROTO_PPP;
+ else if ((ifm->ifm_media & IFM_OMASK) == 0)
+ ifs.type = IF_PROTO_CISCO;
+ else {
+ log(LOG_INFO, "%s: Unsupported ifmedia options\n",
+ card->devname);
+ return (EINVAL);
+ }
- switch (ifm->ifm_media) {
- case(IFM_TDM|IFM_TDM_T1):
+ ret = wp_lite_set_proto(ifp, &ifr);
+ if (ret != 0)
+ return (ret);
+
+ switch (IFM_SUBTYPE(ifm->ifm_media)) {
+ case IFM_TDM_T1:
#ifdef DEBUG_INIT
log(LOG_INFO, "%s: Setting T1 media type!\n",
card->devname);
@@ -1931,7 +1961,7 @@ int sdla_te_setcfg(void *pcard, struct ifmedia *ifm)
te_cfg->lcode = WAN_LC_B8ZS;
te_cfg->frame = WAN_FR_ESF;
break;
- case(IFM_TDM|IFM_TDM_T1_AMI):
+ case IFM_TDM_T1_AMI:
#ifdef DEBUG_INIT
log(LOG_INFO, "%s: Setting T1 AMI media type!\n",
card->devname);
@@ -1940,7 +1970,7 @@ int sdla_te_setcfg(void *pcard, struct ifmedia *ifm)
te_cfg->lcode = WAN_LC_AMI;
te_cfg->frame = WAN_FR_ESF;
break;
- case(IFM_TDM|IFM_TDM_E1):
+ case IFM_TDM_E1:
#ifdef DEBUG_INIT
log(LOG_INFO, "%s: Setting E1 media type!\n",
card->devname);
@@ -1949,7 +1979,7 @@ int sdla_te_setcfg(void *pcard, struct ifmedia *ifm)
te_cfg->lcode = WAN_LC_HDB3;
te_cfg->frame = WAN_FR_NCRC4;
break;
- case(IFM_TDM|IFM_TDM_E1_AMI):
+ case IFM_TDM_E1_AMI:
#ifdef DEBUG_INIT
log(LOG_INFO, "%s: Setting E1 AMI media type!\n",
card->devname);
@@ -1961,9 +1991,10 @@ int sdla_te_setcfg(void *pcard, struct ifmedia *ifm)
default:
log(LOG_INFO, "%s: Unsupported ifmedia type (%04X)\n",
card->devname, ifm->ifm_media);
- return -EINVAL;
+ return (EINVAL);
}
- return 0;
+
+ return (0);
}
/*
@@ -1992,7 +2023,7 @@ sdla_te_gettimeslot(void* pcard)
* Configure Sangoma TE1 board
*
* Arguments:
- * Returns: 0 - TE1 configred successfully, otherwise -EINVAL.
+ * Returns: 0 - TE1 configred successfully, otherwise EINVAL.
*/
short
sdla_te_config(void* card_id)
diff --git a/sys/dev/pci/if_san_te1.h b/sys/dev/pci/if_san_te1.h
index 457f5b62d63..1bc988fbc9d 100644
--- a/sys/dev/pci/if_san_te1.h
+++ b/sys/dev/pci/if_san_te1.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_te1.h,v 1.4 2004/12/07 06:10:24 mcbride Exp $ */
+/* $OpenBSD: if_san_te1.h,v 1.5 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -946,7 +946,7 @@ typedef struct {
EXTERN int sdla_te_defcfg(void *);
-EXTERN int sdla_te_setcfg(void *, struct ifmedia *);
+EXTERN int sdla_te_setcfg(struct ifnet *, struct ifmedia *);
EXTERN void sdla_te_settimeslot(void *, unsigned long);
EXTERN unsigned long sdla_te_gettimeslot(void *);
EXTERN short sdla_te_config(void *);
diff --git a/sys/dev/pci/if_san_xilinx.c b/sys/dev/pci/if_san_xilinx.c
index 62896559742..7f6c6ab7986 100644
--- a/sys/dev/pci/if_san_xilinx.c
+++ b/sys/dev/pci/if_san_xilinx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_san_xilinx.c,v 1.7 2005/03/01 18:37:07 mcbride Exp $ */
+/* $OpenBSD: if_san_xilinx.c,v 1.8 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -370,6 +370,16 @@ wan_xilinx_init(sdla_t *card)
ifmedia_add(&sc->common.ifm, IFM_TDM|IFM_TDM_T1_AMI, 0, NULL);
ifmedia_add(&sc->common.ifm, IFM_TDM|IFM_TDM_E1, 0, NULL);
ifmedia_add(&sc->common.ifm, IFM_TDM|IFM_TDM_E1_AMI, 0, NULL);
+
+ ifmedia_add(&sc->common.ifm,
+ IFM_TDM|IFM_TDM_T1|IFM_TDM_PPP, 0, NULL);
+ ifmedia_add(&sc->common.ifm,
+ IFM_TDM|IFM_TDM_T1_AMI|IFM_TDM_PPP, 0, NULL);
+ ifmedia_add(&sc->common.ifm,
+ IFM_TDM|IFM_TDM_E1|IFM_TDM_PPP, 0, NULL);
+ ifmedia_add(&sc->common.ifm,
+ IFM_TDM|IFM_TDM_E1_AMI|IFM_TDM_PPP, 0, NULL);
+
ifmedia_set(&sc->common.ifm, IFM_TDM|IFM_TDM_T1);
} else {
/* Currently we not support ifmedia types for other
@@ -437,10 +447,10 @@ wan_ifmedia_upd(struct ifnet *ifp)
WAN_ASSERT(common == NULL);
WAN_ASSERT(common->card == NULL);
card = (sdla_t *)common->card;
- if (IS_TE1(&card->fe_te.te_cfg)) {
- return (sdla_te_setcfg(card, &common->ifm));
- }
- return (-EINVAL);
+ if (IS_TE1(&card->fe_te.te_cfg))
+ return (sdla_te_setcfg(ifp, &common->ifm));
+
+ return (EINVAL);
}
@@ -467,7 +477,7 @@ wan_xilinx_up(struct ifnet *ifp)
if (!sc->dma_mtu) {
log(LOG_INFO, "%s:%s: Error invalid MTU %d\n",
card->devname, sc->if_name, ifp->if_mtu);
- return (-EINVAL);
+ return (EINVAL);
}
#ifdef DEBUG_INIT
@@ -476,12 +486,12 @@ wan_xilinx_up(struct ifnet *ifp)
#endif
err = aft_alloc_rx_dma_buff(card, sc, card->u.xilinx.dma_per_ch);
if (err) {
- return (-EINVAL);
+ return (EINVAL);
}
err = xilinx_chip_configure(card);
if (err) {
- return (-EINVAL);
+ return (EINVAL);
}
card->isr = &wp_xilinx_isr;
@@ -489,7 +499,7 @@ wan_xilinx_up(struct ifnet *ifp)
err = xilinx_dev_configure(card, sc);
if (err) {
xilinx_chip_unconfigure(card);
- return (-EINVAL);
+ return (EINVAL);
}
xilinx_delay(1);
@@ -605,7 +615,7 @@ wan_xilinx_send(struct mbuf* m, struct ifnet* ifp)
if (m == NULL) {
/* This should never happen. Just a sanity check.
*/
- return (-EINVAL);
+ return (EINVAL);
}
if (card->state != WAN_CONNECTED) {
@@ -614,7 +624,7 @@ wan_xilinx_send(struct mbuf* m, struct ifnet* ifp)
* drop this packet!
*/
m_freem(m);
- return (-EINVAL);
+ return (EINVAL);
} else {
@@ -643,7 +653,7 @@ wan_xilinx_send(struct mbuf* m, struct ifnet* ifp)
*/
m_freem(m);
ifp->if_flags |= IFF_OACTIVE;
- return (-EBUSY);
+ return (EBUSY);
} else {
wan_xilinx_dma_tx_try:
IF_ENQUEUE(&sc->wp_tx_pending_list, m);
@@ -664,7 +674,7 @@ wan_xilinx_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr)
int err = 0;
if (!sc) {
- return (-ENODEV);
+ return (ENODEV);
}
card = (sdla_t *)sc->common.card;
@@ -673,7 +683,7 @@ wan_xilinx_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr)
case SIOC_WANPIPE_PIPEMON:
if (IF_QFULL(&sc->udp_queue)) {
- return (-EBUSY);
+ return (EBUSY);
}
/*
@@ -681,18 +691,18 @@ wan_xilinx_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr)
* here before spin lock
*/
if (bit_test((u_int8_t *)&card->in_isr, 0)) {
- return (-EBUSY);
+ return (EBUSY);
}
m = wan_mbuf_alloc(sizeof(wan_udp_pkt_t));
if (m == NULL) {
- return (-ENOMEM);
+ return (ENOMEM);
}
wan_udp_pkt = mtod(m, wan_udp_pkt_t *);
if (copyin(ifr->ifr_data, &wan_udp_pkt->wan_udp_hdr,
sizeof(wan_udp_hdr_t))) {
m_freem(m);
- return (-EFAULT);
+ return (EFAULT);
}
IF_ENQUEUE(&sc->udp_queue, m);
@@ -701,7 +711,7 @@ wan_xilinx_ioctl(struct ifnet *ifp, int cmd, struct ifreq *ifr)
if (copyout(&wan_udp_pkt->wan_udp_hdr, ifr->ifr_data,
sizeof(wan_udp_hdr_t))) {
m_freem(m);
- return (-EFAULT);
+ return (EFAULT);
}
IF_DEQUEUE(&sc->udp_queue, m);
@@ -740,9 +750,9 @@ process_udp_mgmt_pkt(sdla_t* card, struct ifnet* ifp,
struct timeval tv;
IF_POLL(&sc->udp_queue, m);
- if (m == NULL) {
- return (-EINVAL);
- }
+ if (m == NULL)
+ return (EINVAL);
+
wan_udp_pkt = mtod(m, wan_udp_pkt_t *);
trace_info=&sc->trace_info;
@@ -970,7 +980,7 @@ xilinx_chip_configure(sdla_t *card)
} else {
log(LOG_INFO, "%s: Error: Xilinx doesn't "
"support non T1/E1 interface!\n", card->devname);
- return (-EINVAL);
+ return (EINVAL);
}
sdla_bus_write_4(card->hw, XILINX_CHIP_CFG_REG, reg);
@@ -1039,7 +1049,7 @@ xilinx_chip_configure(sdla_t *card)
default:
log(LOG_INFO, "%s: Error Invalid Security ID = 0x%X\n",
card->devname, adptr_security);
- /* return -EINVAL;*/
+ /* return EINVAL;*/
}
#endif
@@ -1062,7 +1072,7 @@ xilinx_chip_configure(sdla_t *card)
if (sdla_te_config(card)) {
log(LOG_INFO, "%s: Failed %s configuratoin!\n", card->devname,
IS_T1(&card->fe_te.te_cfg)?"T1":"E1");
- return (-EINVAL);
+ return (EINVAL);
}
xilinx_delay(1);
@@ -1187,7 +1197,7 @@ xilinx_dev_configure(sdla_t *card, xilinx_softc_t *sc)
sc->logic_ch_num=-1;
if (!IS_TE1(&card->fe_te.te_cfg)) {
- return (-EINVAL);
+ return (EINVAL);
}
if (IS_E1(&card->fe_te.te_cfg)) {
@@ -1204,7 +1214,7 @@ xilinx_dev_configure(sdla_t *card, xilinx_softc_t *sc)
if (sc->time_slot_map == 0) {
log(LOG_INFO, "%s: Invalid Channel Selection 0x%lX\n",
card->devname, sc->time_slot_map);
- return (-EINVAL);
+ return (EINVAL);
}
#ifdef DEBUG_INIT
@@ -1244,7 +1254,7 @@ xilinx_dev_configure(sdla_t *card, xilinx_softc_t *sc)
"%ld, aready in use!\n",
card->devname, sc->if_name, (i+1));
- return (-EEXIST);
+ return (EEXIST);
}
/* Calculate the number of timeslots for this if */
@@ -1257,7 +1267,7 @@ xilinx_dev_configure(sdla_t *card, xilinx_softc_t *sc)
sc->logic_ch_num = request_xilinx_logical_channel_num(card,
sc, &free_logic_ch);
if (sc->logic_ch_num == -1) {
- return (-EBUSY);
+ return (EBUSY);
}
xilinx_delay(1);
@@ -1667,14 +1677,14 @@ static int xilinx_dma_rx(sdla_t *card, xilinx_softc_t *sc)
if (bit_test((u_int8_t *)&reg, RxDMA_HI_DMA_GO_READY_BIT)) {
log(LOG_INFO, "%s: Error: RxDMA GO Ready bit set on dma Rx\n",
card->devname);
- return -EFAULT;
+ return (EFAULT);
}
#endif
if (sc->rx_dma_mbuf) {
log(LOG_INFO, "%s: Critial Error: Rx Dma Buf busy!\n",
sc->if_name);
- return (-EINVAL);
+ return (EINVAL);
}
IF_DEQUEUE(&sc->wp_rx_free_list, sc->rx_dma_mbuf);
@@ -1684,7 +1694,7 @@ static int xilinx_dma_rx(sdla_t *card, xilinx_softc_t *sc)
"Free=%d Comp=%d!\n", sc->if_name,
sc->wp_rx_free_list.ifq_len,
sc->wp_rx_complete_list.ifq_len);
- return (-ENOMEM);
+ return (ENOMEM);
}
rx_el = mtod(sc->rx_dma_mbuf, wp_rx_element_t *);
@@ -1698,7 +1708,7 @@ static int xilinx_dma_rx(sdla_t *card, xilinx_softc_t *sc)
if (!bus_addr) {
log(LOG_INFO, "%s: %s Critical error pci_map_single() "
"failed!\n", sc->if_name, __FUNCTION__);
- return -EINVAL;
+ return EINVAL;
}
rx_el->dma_addr = bus_addr;
@@ -1771,7 +1781,7 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc)
log(LOG_INFO, "%s: TX_BUSY set (%s:%d)!\n",
sc->if_name, __FUNCTION__, __LINE__);
#endif
- return -EBUSY;
+ return EBUSY;
}
bit_set((u_int8_t *)&sc->dma_status, TX_BUSY);
@@ -1815,14 +1825,14 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc)
log(LOG_INFO, "%s: Error: TxDMA GO Ready bit set "
"on dma Tx 0x%X\n", card->devname, reg);
bit_clear((u_int8_t *)&sc->dma_status, TX_BUSY);
- return (-EFAULT);
+ return (EFAULT);
}
IF_DEQUEUE(&sc->wp_tx_pending_list, m);
if (!m) {
bit_clear((u_int8_t *)&sc->dma_status, TX_BUSY);
- return (-ENOBUFS);
+ return (ENOBUFS);
} else {
len = m->m_len;
if (len > MAX_XILINX_TX_DMA_SIZE) {
@@ -1834,7 +1844,7 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc)
MAX_XILINX_TX_DMA_SIZE, __FUNCTION__, __LINE__);
m_freem(m);
bit_clear((u_int8_t *)&sc->dma_status, TX_BUSY);
- return (-EINVAL);
+ return (EINVAL);
}
if (mtod(m, u_int32_t) & 0x03) {
@@ -1860,7 +1870,7 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc)
m_freem(m);
bit_clear((u_int8_t *)&sc->dma_status,
TX_BUSY);
- return (-EINVAL);
+ return (EINVAL);
}
err = bus_dmamem_map(
dmat,
@@ -1880,7 +1890,7 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc)
m_freem(m);
bit_clear((u_int8_t *)&sc->dma_status,
TX_BUSY);
- return (-EINVAL);
+ return (EINVAL);
}
bit_set((u_int8_t *)&sc->tx_dma_status,
TX_DMA_BUF_INIT);
@@ -1902,7 +1912,7 @@ xilinx_dma_tx(sdla_t *card, xilinx_softc_t *sc)
}
bit_clear((u_int8_t *)&sc->dma_status, TX_BUSY);
- return (-EINVAL);
+ return (EINVAL);
}
sc->tx_dma_mbuf = m;
@@ -2477,7 +2487,7 @@ aft_alloc_rx_dma_buff(sdla_t *card, xilinx_softc_t *sc, int num)
if (m == NULL) {
log(LOG_INFO, "%s: %s no memory\n",
sc->if_name, __FUNCTION__);
- return (-ENOMEM);
+ return (ENOMEM);
}
IF_ENQUEUE(&sc->wp_rx_free_list, m);
}
@@ -2607,7 +2617,7 @@ fifo_error_interrupt(sdla_t *card, unsigned long reg)
sc->logic_ch_num, i);
#endif
xilinx_tx_fifo_under_recover(card, sc);
- err=-EINVAL;
+ err=EINVAL;
}
}
}
@@ -2667,7 +2677,7 @@ fifo_error_interrupt(sdla_t *card, unsigned long reg)
bit_set((u_int8_t *)&sc->pkt_error,
WP_FIFO_ERROR_BIT);
- err = -EINVAL;
+ err = EINVAL;
}
}
}
@@ -3263,11 +3273,11 @@ xilinx_write_ctrl_hdlc(sdla_t *card, u_int32_t timeslot,
if ((ticks-timeout) > 1) {
log(LOG_INFO, "%s: Error: Access to timeslot %d "
"timed out!\n", card->devname, ts_orig);
- return (-EIO);
+ return (EIO);
}
}
- return (-EIO);
+ return (EIO);
}
static int
@@ -3283,7 +3293,9 @@ set_chan_state(sdla_t *card, struct ifnet *ifp, int state)
log(LOG_INFO, "%s: Setting idle_start to 0\n", sc->if_name);
#endif
bit_clear((u_int8_t *)&sc->idle_start, 0);
- }
+ sc->common.ifp.pp_up(&sc->common.ifp);
+ } else if (state == WAN_DISCONNECTED)
+ sc->common.ifp.pp_down(&sc->common.ifp);
return (0);
}
@@ -3323,7 +3335,7 @@ static int request_fifo_baddr_and_size(sdla_t *card, xilinx_softc_t *sc)
} else {
log(LOG_INFO, "%s: Invalid number of timeslots %d\n",
card->devname, sc->num_of_time_slots);
- return (-EINVAL);
+ return (EINVAL);
}
} else {
if (sc->num_of_time_slots == (NUM_OF_E1_CHANNELS-1)) {
@@ -3345,7 +3357,7 @@ static int request_fifo_baddr_and_size(sdla_t *card, xilinx_softc_t *sc)
} else {
log(LOG_INFO, "%s:%s: Invalid number of timeslots %d\n",
card->devname, sc->if_name, sc->num_of_time_slots);
- return (-EINVAL);
+ return (EINVAL);
}
}
@@ -3359,7 +3371,7 @@ static int request_fifo_baddr_and_size(sdla_t *card, xilinx_softc_t *sc)
log(LOG_INFO, "%s:%s: Error: Failed to obtain fifo size %d "
"or addr %d\n", card->devname, sc->if_name, fifo_size,
sc->fifo_base_addr);
- return (-EINVAL);
+ return (EINVAL);
}
#ifdef DEBUG_INIT
@@ -3548,7 +3560,7 @@ aft_core_ready(sdla_t *card)
/* The HDLC Core is not ready! we have
** an error. */
if (++cnt > 5) {
- return (-EINVAL);
+ return (EINVAL);
} else {
DELAY(500);
/* WARNING: we cannot do this while in
@@ -3559,5 +3571,5 @@ aft_core_ready(sdla_t *card)
}
}
- return (-EINVAL);
+ return (EINVAL);
}
diff --git a/sys/dev/pci/if_sandrv.c b/sys/dev/pci/if_sandrv.c
index 741aff7ca0e..7a7d3ae058f 100644
--- a/sys/dev/pci/if_sandrv.c
+++ b/sys/dev/pci/if_sandrv.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_sandrv.c,v 1.9 2005/03/13 10:47:24 brad Exp $ */
+/* $OpenBSD: if_sandrv.c,v 1.10 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -231,13 +231,12 @@ san_match(struct device *parent, void *match, void *aux)
u_int16_t vendor_id = PCI_VENDOR(pa->pa_id);
u_int16_t device_id = PCI_DEVICE(pa->pa_id);
- if (!(vendor_id == SANGOMA_PCI_VENDOR &&
- device_id == SANGOMA_PCI_DEVICE) ||
- (vendor_id == SANGOMA_PCI_VENDOR_OLD &&
- device_id == SANGOMA_PCI_DEVICE)) {
- return (0);
+ if ((vendor_id == SANGOMA_PCI_VENDOR ||
+ vendor_id == SANGOMA_PCI_VENDOR_OLD) &&
+ device_id == SANGOMA_PCI_DEVICE) {
+ return (1);
}
- return (1);
+ return (0);
}
#define PCI_CBIO 0x10
@@ -337,7 +336,7 @@ sdladrv_init(void)
for (i=0; i<MAX_S514_CARDS; i++)
pci_slot_ar[i] = 0xFF;
- memset(&sdla_adapter_cnt,0,sizeof(sdla_hw_type_cnt_t));
+ bzero(&sdla_adapter_cnt, sizeof(sdla_hw_type_cnt_t));
return (0);
}
@@ -359,9 +358,8 @@ sdladrv_exit(void)
while (elm_hw) {
sdlahw_t *tmp = elm_hw;
elm_hw = LIST_NEXT(elm_hw, next);
- if (sdla_hw_unregister(tmp->hwcard, tmp->cpu_no) == -EBUSY){
- return -EBUSY;
- }
+ if (sdla_hw_unregister(tmp->hwcard, tmp->cpu_no) == EBUSY)
+ return EBUSY;
}
LIST_INIT(&sdlahw_head);
@@ -372,9 +370,8 @@ sdladrv_exit(void)
if (sdla_card_unregister(tmp->hw_type,
tmp->slot_no,
tmp->bus_no,
- tmp->ioport) == -EBUSY){
- return -EBUSY;
- }
+ tmp->ioport) == EBUSY)
+ return EBUSY;
}
LIST_INIT(&sdlahw_card_head);
@@ -385,7 +382,7 @@ sdladrv_exit(void)
if (tmp->used){
log(LOG_INFO, "HW probe info is in used (%s)\n",
elm_hw_probe->hw_info);
- return -EBUSY;
+ return EBUSY;
}
LIST_REMOVE(tmp, next);
free(tmp, M_DEVBUF);
@@ -400,10 +397,10 @@ sdla_save_hw_probe(sdlahw_t *hw, int port)
sdla_hw_probe_t *tmp_hw_probe;
tmp_hw_probe = malloc(sizeof(sdla_hw_probe_t), M_DEVBUF, M_NOWAIT);
- if (!tmp_hw_probe)
+ if (tmp_hw_probe == NULL)
return;
- memset(tmp_hw_probe,0,sizeof(sdla_hw_probe_t));
+ bzero(tmp_hw_probe, sizeof(sdla_hw_probe_t));
snprintf(tmp_hw_probe->hw_info, sizeof(tmp_hw_probe->hw_info),
"%s : SLOT=%d : BUS=%d : IRQ=%d : CPU=%c : PORT=%s",
@@ -492,21 +489,21 @@ sdla_pci_probe(int atype, struct pci_attach_args *pa)
irq = (u_int8_t)pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_INTLINE);
/* Map and establish the interrupt */
- if (pci_intr_map(pa,&ih)) {
+ if (pci_intr_map(pa, &ih)) {
printf(": couldn't map interrupt\n");
- return (-EINVAL);
+ return (EINVAL);
}
intrstr = pci_intr_string(pa->pa_pc, ih);
- if (intrstr != NULL) {
+ if (intrstr != NULL)
printf(" %s\n", intrstr);
- }
+
Sangoma_cards_no ++;
reg_new_card:
Sangoma_PCI_cards_no ++;
hwcard = sdla_card_register(atype, slot, bus);
- if (hwcard == NULL) {
- return (-EINVAL);
- }
+ if (hwcard == NULL)
+ return (EINVAL);
+
hwcard->memt = pa->pa_memt;
hwcard->ih = ih;
hwcard->pa = *pa;
@@ -517,16 +514,17 @@ reg_new_card:
case A101_ADPTR_2TE1:
hw = sdla_aft_hw_select(hwcard, cpu, irq, pa);
sdla_adapter_cnt.AFT_adapters++;
- if (atype == A101_ADPTR_2TE1) dual_cpu = 1;
+ if (atype == A101_ADPTR_2TE1)
+ dual_cpu = 1;
break;
}
if (hw == NULL)
- return (-EINVAL);
- if (san_dev_attach(hw, hw->devname)) {
- return (-EINVAL);
- }
+ return (EINVAL);
+ if (san_dev_attach(hw, hw->devname, sizeof(hw->devname)))
+ return (EINVAL);
+
hw->used++;
if (dual_cpu && cpu == SDLA_CPU_A) {
@@ -538,7 +536,7 @@ reg_new_card:
}
int
-sdla_intr_establish(void *phw, int(*intr_func)(void*), void* intr_arg)
+sdla_intr_establish(void *phw, int (*intr_func)(void*), void* intr_arg)
{
sdlahw_t *hw = (sdlahw_t*)phw;
sdlahw_card_t *hwcard;
@@ -546,9 +544,9 @@ sdla_intr_establish(void *phw, int(*intr_func)(void*), void* intr_arg)
WAN_ASSERT(hw == NULL);
hwcard = hw->hwcard;
if (pci_intr_establish(hwcard->pa.pa_pc, hwcard->ih, IPL_NET,
- intr_func, intr_arg, "san") == NULL) {
- return (-EINVAL);
- }
+ intr_func, intr_arg, "san") == NULL)
+ return (EINVAL);
+
return 0;
}
@@ -559,7 +557,7 @@ sdla_intr_disestablish(void *phw)
log(LOG_INFO, "%d: Disestablish interrupt is not defined!\n",
hw->devname);
- return (-EINVAL);
+ return (EINVAL);
}
int
@@ -568,8 +566,8 @@ sdla_get_hw_devices(void)
return (Sangoma_devices_no);
}
-void
-*sdla_get_hw_adptr_cnt(void)
+void*
+sdla_get_hw_adptr_cnt(void)
{
return (&sdla_adapter_cnt);
}
@@ -580,15 +578,14 @@ sdla_card_register(u_int16_t atype, int slot_no, int bus_no)
sdlahw_card_t *new_hwcard, *last_hwcard;
new_hwcard = sdla_card_search(atype, slot_no, bus_no);
- if (new_hwcard) {
+ if (new_hwcard)
return (new_hwcard);
- }
+
new_hwcard = malloc(sizeof(sdlahw_card_t), M_DEVBUF, M_NOWAIT);
- if (!new_hwcard) {
+ if (!new_hwcard)
return (NULL);
- }
- memset(new_hwcard,0,sizeof(sdlahw_card_t));
+ bzero(new_hwcard, sizeof(sdlahw_card_t));
new_hwcard->atype = atype;
new_hwcard->slot_no = slot_no;
@@ -599,15 +596,15 @@ sdla_card_register(u_int16_t atype, int slot_no, int bus_no)
sdladrv_init();
}
LIST_FOREACH(last_hwcard, &sdlahw_card_head, next) {
- if (!LIST_NEXT(last_hwcard, next)) {
+ if (!LIST_NEXT(last_hwcard, next))
break;
- }
}
- if (last_hwcard) {
+
+ if (last_hwcard)
LIST_INSERT_AFTER(last_hwcard, new_hwcard, next);
- } else {
+ else
LIST_INSERT_HEAD(&sdlahw_card_head, new_hwcard, next);
- }
+
return (new_hwcard);
}
@@ -630,13 +627,13 @@ sdla_card_unregister(u_int16_t atype, int slot_no, int bus_no, int ioport)
log(LOG_INFO,
"Error: Card didn't find %04X card (slot=%d, bus=%d)\n"
atype, slot_no, bus_no);
- return -EFAULT;
+ return (EFAULT)
}
if (tmp_card->used){
log(LOG_INFO,
"Error: Card is still in used (slot=%d,bus=%d,used=%d)\n",
slot_no, bus_no, tmp_card->used);
- return -EBUSY;
+ return (EBUSY);
}
LIST_REMOVE(tmp_card, next);
free(tmp_card, M_DEVBUF);
@@ -650,13 +647,12 @@ sdla_card_search(u_int16_t atype, int slot_no, int bus_no)
sdlahw_card_t* tmp_card;
LIST_FOREACH(tmp_card, &sdlahw_card_head, next) {
- if (tmp_card->atype != atype) {
+ if (tmp_card->atype != atype)
continue;
- }
+
if (tmp_card->slot_no == slot_no &&
- tmp_card->bus_no == bus_no) {
+ tmp_card->bus_no == bus_no)
return (tmp_card);
- }
}
return (NULL);
}
@@ -668,14 +664,14 @@ sdla_hw_register(sdlahw_card_t *card, int cpu_no, int irq, void *dev)
new_hw = sdla_hw_search(card->atype, card->slot_no,
card->bus_no, cpu_no);
- if (new_hw) {
+ if (new_hw)
return (new_hw);
- }
+
new_hw = malloc(sizeof(sdlahw_t), M_DEVBUF, M_NOWAIT);
if (!new_hw)
return (NULL);
- memset(new_hw,0,sizeof(sdlahw_t));
+ bzero(new_hw, sizeof(sdlahw_t));
new_hw->cpu_no = cpu_no;
new_hw->irq = irq;
@@ -687,15 +683,14 @@ sdla_hw_register(sdlahw_card_t *card, int cpu_no, int irq, void *dev)
card->used++;
LIST_FOREACH(last_hw, &sdlahw_head, next) {
- if (!LIST_NEXT(last_hw, next)) {
+ if (!LIST_NEXT(last_hw, next))
break;
- }
}
- if (last_hw) {
+ if (last_hw)
LIST_INSERT_AFTER(last_hw, new_hw, next);
- }else{
+ else
LIST_INSERT_HEAD(&sdlahw_head, new_hw, next);
- }
+
return (new_hw);
}
@@ -706,28 +701,28 @@ sdla_hw_unregister(sdlahw_card_t* hwcard, int cpu_no)
sdlahw_t* tmp_hw;
int i;
- LIST_FOREACH(tmp_hw, &sdlahw_head, next){
- if (tmp_hw->hwcard != hwcard){
+ LIST_FOREACH(tmp_hw, &sdlahw_head, next) {
+ if (tmp_hw->hwcard != hwcard)
continue;
- }
- if (tmp_hw->cpu_no == cpu_no){
+
+ if (tmp_hw->cpu_no == cpu_no)
break;
- }
}
- if (tmp_hw == NULL){
+
+ if (tmp_hw == NULL) {
log(LOG_INFO,
"Error: Failed to find device (slot=%d,bus=%d,cpu=%c)\n",
hwcard->slot_no, hwcard->bus_no, SDLA_GET_CPU(cpu_no));
- return -EFAULT;
+ return (EFAULT);
}
- if (tmp_hw->used){
+ if (tmp_hw->used) {
log(LOG_INFO,
"Error: Device is still in used (slot=%d,bus=%d,cpu=%c,%d)\n",
hwcard->slot_no,
hwcard->bus_no,
SDLA_GET_CPU(cpu_no),
hwcard->used);
- return -EBUSY;
+ return (EBUSY);
}
tmp_hw->hwprobe = NULL;
@@ -735,7 +730,8 @@ sdla_hw_unregister(sdlahw_card_t* hwcard, int cpu_no)
hwcard->used--; /* Decrement card usage */
LIST_REMOVE(tmp_hw, next);
free(tmp_hw, M_DEVBUF);
- return 0;
+
+ return (0);
}
#endif
@@ -744,24 +740,27 @@ sdla_hw_search(u_int16_t atype, int slot_no, int bus_no, int cpu_no)
{
sdlahw_t* tmp_hw;
+
LIST_FOREACH(tmp_hw, &sdlahw_head, next) {
if (tmp_hw->hwcard == NULL) {
log(LOG_INFO,
"Critical Error: sdla_cpu_search: line %d\n",
__LINE__);
+ // XXX REMOVE in LIST_FOREACH
LIST_REMOVE(tmp_hw, next);
continue;
}
if (tmp_hw->hwcard->atype != atype) {
+ // XXX why ???
LIST_REMOVE(tmp_hw, next);
continue;
}
if (tmp_hw->hwcard->slot_no == slot_no &&
tmp_hw->hwcard->bus_no == bus_no &&
- tmp_hw->cpu_no == cpu_no) {
+ tmp_hw->cpu_no == cpu_no)
return (tmp_hw);
- }
}
+
return (NULL);
}
@@ -792,7 +791,7 @@ sdla_setup(void *phw)
default:
log(LOG_INFO, "%s: Invalid card type %x\n",
hw->devname, hw->hwcard->type);
- return (-EINVAL);
+ return (EINVAL);
}
hw->dpmsize = SDLA_WINDOWSIZE;
@@ -827,7 +826,7 @@ sdla_down(void *phw)
break;
default:
- return (-EINVAL);
+ return (EINVAL);
}
return (0);
}
@@ -946,7 +945,7 @@ sdla_peek(void *phw, unsigned long addr, void *buf, unsigned len)
WAN_ASSERT(hw->hwcard == NULL);
card = hw->hwcard;
if (addr + len > hw->memory) /* verify arguments */
- return (-EINVAL);
+ return (EINVAL);
switch (card->type) {
case SDLA_AFT:
@@ -956,7 +955,7 @@ sdla_peek(void *phw, unsigned long addr, void *buf, unsigned len)
default:
log(LOG_INFO, "%s: Invalid card type 0x%X\n",
__FUNCTION__,card->type);
- err = -EINVAL;
+ err = (EINVAL);
break;
}
return (err);
@@ -1015,7 +1014,7 @@ sdla_poke(void *phw, unsigned long addr, void *buf, unsigned len)
WAN_ASSERT(hw->hwcard == NULL);
card = hw->hwcard;
if (addr + len > hw->memory) { /* verify arguments */
- return (-EINVAL);
+ return (EINVAL);
}
switch (card->type) {
@@ -1026,7 +1025,7 @@ sdla_poke(void *phw, unsigned long addr, void *buf, unsigned len)
default:
log(LOG_INFO, "%s: Invalid card type 0x%X\n",
__FUNCTION__,card->type);
- err = -EINVAL;
+ err = (EINVAL);
break;
}
return (err);
@@ -1129,7 +1128,7 @@ sdla_detect_aft(sdlahw_t *hw)
printf("%s: No PCI memory allocated to card\n",
hw->devname);
}
- return (-EINVAL);
+ return (EINVAL);
}
#ifdef DEBUG
log(LOG_INFO, "%s: AFT PCI memory at 0x%lX\n",
@@ -1138,7 +1137,7 @@ sdla_detect_aft(sdlahw_t *hw)
sdla_pci_read_config_byte(hw, PCI_INTLINE, (u_int8_t*)&hw->irq);
if (hw->irq == PCI_IRQ_NOT_ALLOCATED) {
printf("%s: IRQ not allocated to AFT adapter\n", hw->devname);
- return (-EINVAL);
+ return (EINVAL);
}
#ifdef DEBUG
@@ -1153,7 +1152,7 @@ sdla_detect_aft(sdlahw_t *hw)
0, &hw->dpmbase);
if (!hw->dpmbase) {
printf("%s: couldn't map memory\n", hw->devname);
- return (-EINVAL);
+ return (EINVAL);
}
hw->status |= SDLA_MEM_MAPPED;
@@ -1188,9 +1187,9 @@ sdla_detect(sdlahw_t *hw)
err = sdla_detect_aft(hw);
break;
}
- if (err) {
+ if (err)
sdla_down(hw);
- }
+
return (err);
}
@@ -1233,18 +1232,18 @@ sdla_check_mismatch(void *phw, unsigned char media)
log(LOG_INFO, "%s: Error: Card type mismatch: "
"User=T1/E1 Actual=%s\n", hw->devname,
SDLA_ADPTR_DECODE(hwcard->atype));
- return (-EIO);
+ return (EIO);
}
hwcard->atype = S5144_ADPTR_1_CPU_T1E1;
- }else if (media == WAN_MEDIA_56K) {
+ } else if (media == WAN_MEDIA_56K) {
if (hwcard->atype != S5145_ADPTR_1_CPU_56K) {
log(LOG_INFO, "%s: Error: Card type mismatch: "
"User=56K Actual=%s\n", hw->devname,
SDLA_ADPTR_DECODE(hwcard->atype));
- return (-EIO);
+ return (EIO);
}
- }else{
+ } else {
if (hwcard->atype == S5145_ADPTR_1_CPU_56K ||
hwcard->atype == S5144_ADPTR_1_CPU_T1E1 ||
hwcard->atype == S5147_ADPTR_2_CPU_T1E1 ||
@@ -1252,9 +1251,10 @@ sdla_check_mismatch(void *phw, unsigned char media)
log(LOG_INFO, "%s: Error: Card type mismatch: "
"User=S514(1/2/3) Actual=%s\n", hw->devname,
SDLA_ADPTR_DECODE(hwcard->atype));
- return (-EIO);
+ return (EIO);
}
}
+
return (0);
}
@@ -1335,9 +1335,9 @@ sdla_get_hwprobe(void *phw, void **str)
WAN_ASSERT(hw == NULL);
SDLA_MAGIC(hw);
- if (hw->hwprobe) {
+ if (hw->hwprobe)
*str = hw->hwprobe->hw_info;
- }
+
return (0);
}
diff --git a/sys/dev/pci/if_sandrv.h b/sys/dev/pci/if_sandrv.h
index 789e167b4a6..1dfb096c249 100644
--- a/sys/dev/pci/if_sandrv.h
+++ b/sys/dev/pci/if_sandrv.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_sandrv.h,v 1.3 2004/07/16 15:11:45 alex Exp $ */
+/* $OpenBSD: if_sandrv.h,v 1.4 2005/04/01 21:42:36 canacar Exp $ */
/*-
* Copyright (c) 2001-2004 Sangoma Technologies (SAN)
@@ -296,7 +296,7 @@ typedef struct sdla_hw_type_cnt
}sdla_hw_type_cnt_t;
/****** Function Prototypes *************************************************/
-extern int san_dev_attach(void*, u_int8_t*);
+extern int san_dev_attach(void*, u_int8_t*, int);
/* Hardware interface function */
extern int sdladrv_init(void);