Return approriate errors to userland.

This commit is contained in:
Nicolas Souchu 1999-02-14 14:36:45 +00:00
parent 9429c06824
commit 4012f363f2
3 changed files with 52 additions and 20 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: smb.c,v 1.6 1999/01/14 22:55:03 nsouch Exp $
* $Id: smb.c,v 1.7 1999/02/13 17:57:19 nsouch Exp $
*
*/
#include <sys/param.h>
@ -160,7 +160,7 @@ smbwrite(dev_t dev, struct uio * uio, int ioflag)
{
/* not supported */
return (EINVAL);
return (ENODEV);
}
static int
@ -168,7 +168,7 @@ smbread(dev_t dev, struct uio * uio, int ioflag)
{
/* not supported */
return (EINVAL);
return (ENODEV);
}
static int
@ -191,56 +191,59 @@ smbioctl(dev_t dev, u_long cmd, caddr_t data, int flags, struct proc *p)
switch (cmd) {
case SMB_QUICK_WRITE:
error=smbus_quick(parent, s->slave, SMB_QWRITE);
error = smbus_error(smbus_quick(parent, s->slave, SMB_QWRITE));
break;
case SMB_QUICK_READ:
error=smbus_quick(parent, s->slave, SMB_QREAD);
error = smbus_error(smbus_quick(parent, s->slave, SMB_QREAD));
break;
case SMB_SENDB:
error=smbus_sendb(parent, s->slave, s->cmd);
error = smbus_error(smbus_sendb(parent, s->slave, s->cmd));
break;
case SMB_RECVB:
error=smbus_recvb(parent, s->slave, &s->cmd);
error = smbus_error(smbus_recvb(parent, s->slave, &s->cmd));
break;
case SMB_WRITEB:
error=smbus_writeb(parent, s->slave, s->cmd, s->data.byte);
error = smbus_error(smbus_writeb(parent, s->slave, s->cmd,
s->data.byte));
break;
case SMB_WRITEW:
error=smbus_writew(parent, s->slave, s->cmd, s->data.word);
error = smbus_error(smbus_writew(parent, s->slave,
s->cmd, s->data.word));
break;
case SMB_READB:
if (s->data.byte_ptr)
error=smbus_readb(parent, s->slave, s->cmd,
s->data.byte_ptr);
error = smbus_error(smbus_readb(parent, s->slave,
s->cmd, s->data.byte_ptr));
break;
case SMB_READW:
if (s->data.word_ptr)
error=smbus_readw(parent, s->slave, s->cmd, s->data.word_ptr);
error = smbus_error(smbus_readw(parent, s->slave,
s->cmd, s->data.word_ptr));
break;
case SMB_PCALL:
if (s->data.process.rdata)
error=smbus_pcall(parent, s->slave, s->cmd,
s->data.process.sdata, s->data.process.rdata);
error = smbus_error(smbus_pcall(parent, s->slave, s->cmd,
s->data.process.sdata, s->data.process.rdata));
break;
case SMB_BWRITE:
if (s->count && s->data.byte_ptr)
error=smbus_bwrite(parent, s->slave, s->cmd, s->count,
s->data.byte_ptr);
error = smbus_error(smbus_bwrite(parent, s->slave,
s->cmd, s->count, s->data.byte_ptr));
break;
case SMB_BREAD:
if (s->count && s->data.byte_ptr)
error=smbus_bread(parent, s->slave, s->cmd, s->count,
s->data.byte_ptr);
error = smbus_error(smbus_bread(parent, s->slave,
s->cmd, s->count, s->data.byte_ptr));
break;
default:

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: smbconf.c,v 1.4 1999/01/09 18:08:23 nsouch Exp $
* $Id: smbconf.c,v 1.5 1999/02/13 17:57:19 nsouch Exp $
*
*/
#include <sys/param.h>
@ -52,6 +52,34 @@ smbus_intr(device_t bus, u_char devaddr, char low, char high, int error)
return;
}
/*
* smbus_error()
*
* Converts an smbus error to a unix error.
*/
int
smbus_error(int smb_error)
{
int error = 0;
if (smb_error == SMB_ENOERR)
return (0);
if (smb_error & (SMB_ENOTSUPP)) {
error = ENODEV;
} else if (smb_error & (SMB_ENOACK)) {
error = ENXIO;
} else if (smb_error & (SMB_ETIMEOUT)) {
error = EWOULDBLOCK;
} else if (smb_error & (SMB_EBUSY)) {
error = EBUSY;
} else {
error = EINVAL;
}
return (error);
}
/*
* smbus_alloc_bus()
*

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: smbconf.h,v 1.3 1999/01/27 19:58:53 dillon Exp $
* $Id: smbconf.h,v 1.4 1999/02/13 17:57:19 nsouch Exp $
*/
#ifndef __SMBONF_H
#define __SMBONF_H
@ -74,6 +74,7 @@
extern int smbus_request_bus(device_t, device_t, int);
extern int smbus_release_bus(device_t, device_t);
extern device_t smbus_alloc_bus(device_t);
extern int smbus_error(int error);
extern void smbus_intr(device_t, u_char, char low, char high, int error);