static int ipmi_ioctl(struct file *file, unsigned int cmd, unsigned long data) { int rv = -EINVAL; struct ipmi_file_private *priv = file->private_data; void __user *arg = (void __user *)data; switch (cmd) { case IPMICTL_SEND_COMMAND: { struct ipmi_req req; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } rv = handle_send_req(priv->user, &req, priv->default_retries, priv->default_retry_time_ms); break; } case IPMICTL_SEND_COMMAND_SETTIME: { struct ipmi_req_settime req; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } rv = handle_send_req(priv->user, &req.req, req.retries, req.retry_time_ms); break; } case IPMICTL_RECEIVE_MSG: case IPMICTL_RECEIVE_MSG_TRUNC: { struct ipmi_recv rsp; int addr_len; struct list_head *entry; struct ipmi_recv_msg *msg; unsigned long flags; rv = 0; if (copy_from_user(&rsp, arg, sizeof(rsp))) { rv = -EFAULT; break; } /* We claim a mutex because we don't want two users getting something from the queue at a time. Since we have to release the spinlock before we can copy the data to the user, it's possible another user will grab something from the queue, too. Then the messages might get out of order if something fails and the message gets put back onto the queue. This mutex prevents that problem. */ mutex_lock(&priv->recv_mutex); /* Grab the message off the list. */ spin_lock_irqsave(&(priv->recv_msg_lock), flags); if (list_empty(&(priv->recv_msgs))) { spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); rv = -EAGAIN; goto recv_err; } entry = priv->recv_msgs.next; msg = list_entry(entry, struct ipmi_recv_msg, link); list_del(entry); spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); addr_len = ipmi_addr_length(msg->addr.addr_type); if (rsp.addr_len < addr_len) { rv = -EINVAL; goto recv_putback_on_err; } if (copy_to_user(rsp.addr, &(msg->addr), addr_len)) { rv = -EFAULT; goto recv_putback_on_err; } rsp.addr_len = addr_len; rsp.recv_type = msg->recv_type; rsp.msgid = msg->msgid; rsp.msg.netfn = msg->msg.netfn; rsp.msg.cmd = msg->msg.cmd; if (msg->msg.data_len > 0) { if (rsp.msg.data_len < msg->msg.data_len) { rv = -EMSGSIZE; if (cmd == IPMICTL_RECEIVE_MSG_TRUNC) { msg->msg.data_len = rsp.msg.data_len; } else { goto recv_putback_on_err; } } if (copy_to_user(rsp.msg.data, msg->msg.data, msg->msg.data_len)) { rv = -EFAULT; goto recv_putback_on_err; } rsp.msg.data_len = msg->msg.data_len; } else { rsp.msg.data_len = 0; } if (copy_to_user(arg, &rsp, sizeof(rsp))) { rv = -EFAULT; goto recv_putback_on_err; } mutex_unlock(&priv->recv_mutex); ipmi_free_recv_msg(msg); break; recv_putback_on_err: /* If we got an error, put the message back onto the head of the queue. */ spin_lock_irqsave(&(priv->recv_msg_lock), flags); list_add(entry, &(priv->recv_msgs)); spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); mutex_unlock(&priv->recv_mutex); break; recv_err: mutex_unlock(&priv->recv_mutex); break; } case IPMICTL_REGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_UNREGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_REGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_UNREGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_SET_GETS_EVENTS_CMD: { int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_gets_events(priv->user, val); break; } /* The next four are legacy, not per-channel. */ case IPMICTL_SET_MY_ADDRESS_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_address(priv->user, 0, val); break; } case IPMICTL_GET_MY_ADDRESS_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_address(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_LUN_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, 0, val); break; } case IPMICTL_GET_MY_LUN_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_LUN(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } return ipmi_set_my_address(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_address(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; if (copy_from_user(&parms, arg, sizeof(parms))) { rv = -EFAULT; break; } priv->default_retries = parms.retries; priv->default_retry_time_ms = parms.retry_time_ms; rv = 0; break; } case IPMICTL_GET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; parms.retries = priv->default_retries; parms.retry_time_ms = priv->default_retry_time_ms; if (copy_to_user(arg, &parms, sizeof(parms))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_GET_MAINTENANCE_MODE_CMD: { int mode; mode = ipmi_get_maintenance_mode(priv->user); if (copy_to_user(arg, &mode, sizeof(mode))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_SET_MAINTENANCE_MODE_CMD: { int mode; if (copy_from_user(&mode, arg, sizeof(mode))) { rv = -EFAULT; break; } rv = ipmi_set_maintenance_mode(priv->user, mode); break; } } return rv; }
static int ipmi_ioctl(struct file *file, unsigned int cmd, unsigned long data) { int rv = -EINVAL; struct ipmi_file_private *priv = file->private_data; void __user *arg = (void __user *)data; switch (cmd) { case IPMICTL_SEND_COMMAND: { struct ipmi_req req; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } rv = handle_send_req(priv->user, &req, priv->default_retries, priv->default_retry_time_ms); break; } case IPMICTL_SEND_COMMAND_SETTIME: { struct ipmi_req_settime req; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } rv = handle_send_req(priv->user, &req.req, req.retries, req.retry_time_ms); break; } case IPMICTL_RECEIVE_MSG: case IPMICTL_RECEIVE_MSG_TRUNC: { struct ipmi_recv rsp; int addr_len; struct list_head *entry; struct ipmi_recv_msg *msg; unsigned long flags; rv = 0; if (copy_from_user(&rsp, arg, sizeof(rsp))) { rv = -EFAULT; break; } mutex_lock(&priv->recv_mutex); spin_lock_irqsave(&(priv->recv_msg_lock), flags); if (list_empty(&(priv->recv_msgs))) { spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); rv = -EAGAIN; goto recv_err; } entry = priv->recv_msgs.next; msg = list_entry(entry, struct ipmi_recv_msg, link); list_del(entry); spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); addr_len = ipmi_addr_length(msg->addr.addr_type); if (rsp.addr_len < addr_len) { rv = -EINVAL; goto recv_putback_on_err; } if (copy_to_user(rsp.addr, &(msg->addr), addr_len)) { rv = -EFAULT; goto recv_putback_on_err; } rsp.addr_len = addr_len; rsp.recv_type = msg->recv_type; rsp.msgid = msg->msgid; rsp.msg.netfn = msg->msg.netfn; rsp.msg.cmd = msg->msg.cmd; if (msg->msg.data_len > 0) { if (rsp.msg.data_len < msg->msg.data_len) { rv = -EMSGSIZE; if (cmd == IPMICTL_RECEIVE_MSG_TRUNC) { msg->msg.data_len = rsp.msg.data_len; } else { goto recv_putback_on_err; } } if (copy_to_user(rsp.msg.data, msg->msg.data, msg->msg.data_len)) { rv = -EFAULT; goto recv_putback_on_err; } rsp.msg.data_len = msg->msg.data_len; } else { rsp.msg.data_len = 0; } if (copy_to_user(arg, &rsp, sizeof(rsp))) { rv = -EFAULT; goto recv_putback_on_err; } mutex_unlock(&priv->recv_mutex); ipmi_free_recv_msg(msg); break; recv_putback_on_err: spin_lock_irqsave(&(priv->recv_msg_lock), flags); list_add(entry, &(priv->recv_msgs)); spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); mutex_unlock(&priv->recv_mutex); break; recv_err: mutex_unlock(&priv->recv_mutex); break; } case IPMICTL_REGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_UNREGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_REGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_UNREGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_SET_GETS_EVENTS_CMD: { int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_gets_events(priv->user, val); break; } case IPMICTL_SET_MY_ADDRESS_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_address(priv->user, 0, val); break; } case IPMICTL_GET_MY_ADDRESS_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_address(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_LUN_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, 0, val); break; } case IPMICTL_GET_MY_LUN_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_LUN(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } return ipmi_set_my_address(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_address(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; if (copy_from_user(&parms, arg, sizeof(parms))) { rv = -EFAULT; break; } priv->default_retries = parms.retries; priv->default_retry_time_ms = parms.retry_time_ms; rv = 0; break; } case IPMICTL_GET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; parms.retries = priv->default_retries; parms.retry_time_ms = priv->default_retry_time_ms; if (copy_to_user(arg, &parms, sizeof(parms))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_GET_MAINTENANCE_MODE_CMD: { int mode; mode = ipmi_get_maintenance_mode(priv->user); if (copy_to_user(arg, &mode, sizeof(mode))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_SET_MAINTENANCE_MODE_CMD: { int mode; if (copy_from_user(&mode, arg, sizeof(mode))) { rv = -EFAULT; break; } rv = ipmi_set_maintenance_mode(priv->user, mode); break; } } return rv; }
static int ipmi_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data) { int rv = -EINVAL; struct ipmi_file_private *priv = file->private_data; switch (cmd) { case IPMICTL_SEND_COMMAND: { struct ipmi_req req; struct ipmi_addr addr; unsigned char msgdata[IPMI_MAX_MSG_LENGTH]; if (copy_from_user(&req, (void *) data, sizeof(req))) { rv = -EFAULT; break; } if (req.addr_len > sizeof(struct ipmi_addr)) { rv = -EINVAL; break; } if (copy_from_user(&addr, req.addr, req.addr_len)) { rv = -EFAULT; break; } rv = ipmi_validate_addr(&addr, req.addr_len); if (rv) break; if (req.msg.data != NULL) { if (req.msg.data_len > IPMI_MAX_MSG_LENGTH) { rv = -EMSGSIZE; break; } if (copy_from_user(&msgdata, req.msg.data, req.msg.data_len)) { rv = -EFAULT; break; } } else { req.msg.data_len = 0; } req.msg.data = msgdata; rv = ipmi_request(priv->user, &addr, req.msgid, &(req.msg), 0); break; } case IPMICTL_RECEIVE_MSG: case IPMICTL_RECEIVE_MSG_TRUNC: { struct ipmi_recv rsp; int addr_len; struct list_head *entry; struct ipmi_recv_msg *msg; unsigned long flags; rv = 0; if (copy_from_user(&rsp, (void *) data, sizeof(rsp))) { rv = -EFAULT; break; } /* We claim a semaphore because we don't want two users getting something from the queue at a time. Since we have to release the spinlock before we can copy the data to the user, it's possible another user will grab something from the queue, too. Then the messages might get out of order if something fails and the message gets put back onto the queue. This semaphore prevents that problem. */ down(&(priv->recv_sem)); /* Grab the message off the list. */ spin_lock_irqsave(&(priv->recv_msg_lock), flags); if (list_empty(&(priv->recv_msgs))) { spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); rv = -EAGAIN; goto recv_err; } entry = priv->recv_msgs.next; msg = list_entry(entry, struct ipmi_recv_msg, link); list_del(entry); spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); addr_len = ipmi_addr_length(msg->addr.addr_type); if (rsp.addr_len < addr_len) { rv = -EINVAL; goto recv_putback_on_err; } if (copy_to_user(rsp.addr, &(msg->addr), addr_len)) { rv = -EFAULT; goto recv_putback_on_err; } rsp.addr_len = addr_len; rsp.recv_type = msg->recv_type; rsp.msgid = msg->msgid; rsp.msg.netfn = msg->msg.netfn; rsp.msg.cmd = msg->msg.cmd; if (msg->msg.data_len > 0) { if (rsp.msg.data_len < msg->msg.data_len) { rv = -EMSGSIZE; if (cmd == IPMICTL_RECEIVE_MSG_TRUNC) { msg->msg.data_len = rsp.msg.data_len; } else { goto recv_putback_on_err; } } if (copy_to_user(rsp.msg.data, msg->msg.data, msg->msg.data_len)) { rv = -EFAULT; goto recv_putback_on_err; } rsp.msg.data_len = msg->msg.data_len; } else { rsp.msg.data_len = 0; } if (copy_to_user((void *) data, &rsp, sizeof(rsp))) { rv = -EFAULT; goto recv_putback_on_err; } up(&(priv->recv_sem)); ipmi_free_recv_msg(msg); break; recv_putback_on_err: /* If we got an error, put the message back onto the head of the queue. */ spin_lock_irqsave(&(priv->recv_msg_lock), flags); list_add(entry, &(priv->recv_msgs)); spin_unlock_irqrestore(&(priv->recv_msg_lock), flags); up(&(priv->recv_sem)); break; recv_err: up(&(priv->recv_sem)); break; } case IPMICTL_REGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, (void *) data, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd); break; } case IPMICTL_UNREGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, (void *) data, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd); break; } case IPMICTL_SET_GETS_EVENTS_CMD: { int val; if (copy_from_user(&val, (void *) data, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_gets_events(priv->user, val); break; } case IPMICTL_SET_MY_ADDRESS_CMD: { unsigned int val; if (copy_from_user(&val, (void *) data, sizeof(val))) { rv = -EFAULT; break; } ipmi_set_my_address(priv->user, val); rv = 0; break; } case IPMICTL_GET_MY_ADDRESS_CMD: { unsigned int val; val = ipmi_get_my_address(priv->user); if (copy_to_user((void *) data, &val, sizeof(val))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_SET_MY_LUN_CMD: { unsigned int val; if (copy_from_user(&val, (void *) data, sizeof(val))) { rv = -EFAULT; break; } ipmi_set_my_LUN(priv->user, val); rv = 0; break; } case IPMICTL_GET_MY_LUN_CMD: { unsigned int val; val = ipmi_get_my_LUN(priv->user); if (copy_to_user((void *) data, &val, sizeof(val))) { rv = -EFAULT; break; } rv = 0; break; } } return rv; }
static long ipmi_ioctl(struct file *file, unsigned int cmd, unsigned long data) { int rv = -EINVAL; struct ipmi_file_private *priv = file->private_data; void __user *arg = (void __user *)data; switch (cmd) { case IPMICTL_SEND_COMMAND: { struct ipmi_req req; int retries; unsigned int retry_time_ms; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } mutex_lock(&priv->recv_mutex); retries = priv->default_retries; retry_time_ms = priv->default_retry_time_ms; mutex_unlock(&priv->recv_mutex); rv = handle_send_req(priv->user, &req, retries, retry_time_ms); break; } case IPMICTL_SEND_COMMAND_SETTIME: { struct ipmi_req_settime req; if (copy_from_user(&req, arg, sizeof(req))) { rv = -EFAULT; break; } rv = handle_send_req(priv->user, &req.req, req.retries, req.retry_time_ms); break; } case IPMICTL_RECEIVE_MSG: case IPMICTL_RECEIVE_MSG_TRUNC: { struct ipmi_recv rsp; if (copy_from_user(&rsp, arg, sizeof(rsp))) rv = -EFAULT; else rv = handle_recv(priv, cmd == IPMICTL_RECEIVE_MSG_TRUNC, &rsp, copyout_recv, arg); break; } case IPMICTL_REGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_UNREGISTER_FOR_CMD: { struct ipmi_cmdspec val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, IPMI_CHAN_ALL); break; } case IPMICTL_REGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_register_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_UNREGISTER_FOR_CMD_CHANS: { struct ipmi_cmdspec_chans val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_unregister_for_cmd(priv->user, val.netfn, val.cmd, val.chans); break; } case IPMICTL_SET_GETS_EVENTS_CMD: { int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_gets_events(priv->user, val); break; } /* The next four are legacy, not per-channel. */ case IPMICTL_SET_MY_ADDRESS_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_address(priv->user, 0, val); break; } case IPMICTL_GET_MY_ADDRESS_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_address(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_LUN_CMD: { unsigned int val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, 0, val); break; } case IPMICTL_GET_MY_LUN_CMD: { unsigned int val; unsigned char rval; rv = ipmi_get_my_LUN(priv->user, 0, &rval); if (rv) break; val = rval; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } return ipmi_set_my_address(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_ADDRESS_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_address(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_set_my_LUN(priv->user, val.channel, val.value); break; } case IPMICTL_GET_MY_CHANNEL_LUN_CMD: { struct ipmi_channel_lun_address_set val; if (copy_from_user(&val, arg, sizeof(val))) { rv = -EFAULT; break; } rv = ipmi_get_my_LUN(priv->user, val.channel, &val.value); if (rv) break; if (copy_to_user(arg, &val, sizeof(val))) { rv = -EFAULT; break; } break; } case IPMICTL_SET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; if (copy_from_user(&parms, arg, sizeof(parms))) { rv = -EFAULT; break; } mutex_lock(&priv->recv_mutex); priv->default_retries = parms.retries; priv->default_retry_time_ms = parms.retry_time_ms; mutex_unlock(&priv->recv_mutex); rv = 0; break; } case IPMICTL_GET_TIMING_PARMS_CMD: { struct ipmi_timing_parms parms; mutex_lock(&priv->recv_mutex); parms.retries = priv->default_retries; parms.retry_time_ms = priv->default_retry_time_ms; mutex_unlock(&priv->recv_mutex); if (copy_to_user(arg, &parms, sizeof(parms))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_GET_MAINTENANCE_MODE_CMD: { int mode; mode = ipmi_get_maintenance_mode(priv->user); if (copy_to_user(arg, &mode, sizeof(mode))) { rv = -EFAULT; break; } rv = 0; break; } case IPMICTL_SET_MAINTENANCE_MODE_CMD: { int mode; if (copy_from_user(&mode, arg, sizeof(mode))) { rv = -EFAULT; break; } rv = ipmi_set_maintenance_mode(priv->user, mode); break; } default: rv = -ENOTTY; break; } return rv; }