summaryrefslogtreecommitdiff
path: root/sys/dev/pci/if_san_common.c
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/pci/if_san_common.c
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/pci/if_san_common.c')
-rw-r--r--sys/dev/pci/if_san_common.c113
1 files changed, 55 insertions, 58 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;
}