From 6df759e1d943760b9bc0ad2d03c22258ba44106e Mon Sep 17 00:00:00 2001 From: bapt Date: Thu, 15 Oct 2015 15:51:40 +0000 Subject: Add generic storage structure for both mpr and mps to simplify code Use correct ioctl on mpr Prevent duplication in headers between mps_ioctl.h and mpr_ioctl.h Sponsored by: Gandi.net --- usr.sbin/mpsutil/mpr_ioctl.h | 2 ++ usr.sbin/mpsutil/mps_cmd.c | 61 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 12 deletions(-) (limited to 'usr.sbin/mpsutil') diff --git a/usr.sbin/mpsutil/mpr_ioctl.h b/usr.sbin/mpsutil/mpr_ioctl.h index 5ec482f..82627b9 100644 --- a/usr.sbin/mpsutil/mpr_ioctl.h +++ b/usr.sbin/mpsutil/mpr_ioctl.h @@ -360,6 +360,7 @@ typedef struct mpr_btdh_mapping #define MPRIO_RAID_ACTION _IOWR('M', 205, struct mpr_raid_action) #define MPRIO_MPR_COMMAND _IOWR('M', 210, struct mpr_usr_command) +#ifndef MPTIOCTL #define MPTIOCTL ('I') #define MPTIOCTL_GET_ADAPTER_DATA _IOWR(MPTIOCTL, 1,\ struct mpr_adapter_data) @@ -382,5 +383,6 @@ typedef struct mpr_btdh_mapping struct mpr_reg_access) #define MPTIOCTL_BTDH_MAPPING _IOWR(MPTIOCTL, 11,\ struct mpr_btdh_mapping) +#endif #endif /* !_MPR_IOCTL_H_ */ diff --git a/usr.sbin/mpsutil/mps_cmd.c b/usr.sbin/mpsutil/mps_cmd.c index ce1d583..50d15f7 100644 --- a/usr.sbin/mpsutil/mps_cmd.c +++ b/usr.sbin/mpsutil/mps_cmd.c @@ -38,6 +38,7 @@ __RCSID("$FreeBSD$"); #include #else #include "mps_ioctl.h" +#include "mpr_ioctl.h" #endif #include #include @@ -219,6 +220,26 @@ static const char *mps_ioc_status_codes[] = { "Diagnostic released", /* 0x00A0 */ }; +struct mprs_pass_thru { + uint64_t PtrRequest; + uint64_t PtrReply; + uint64_t PtrData; + uint32_t RequestSize; + uint32_t ReplySize; + uint32_t DataSize; + uint32_t DataDirection; + uint64_t PtrDataOut; + uint32_t DataOutSize; + uint32_t Timeout; +}; + +struct mprs_btdh_mapping { + uint16_t TargetID; + uint16_t Bus; + uint16_t DevHandle; + uint16_t Reserved; +}; + const char * mps_ioc_status(U16 IOCStatus) { @@ -237,9 +258,8 @@ int mps_map_btdh(int fd, uint16_t *devhandle, uint16_t *bus, uint16_t *target) { int error; - struct mps_btdh_mapping map; + struct mprs_btdh_mapping map; - bzero(&map, sizeof(map)); map.Bus = *bus; map.TargetID = *target; map.DevHandle = *devhandle; @@ -640,7 +660,7 @@ mps_user_command(int fd, void *req, uint32_t req_len, void *reply, cmd.len = len; cmd.flags = flags; - if (ioctl(fd, MPSIO_MPS_COMMAND, &cmd) < 0) + if (ioctl(fd, is_mps ? MPSIO_MPS_COMMAND : MPRIO_MPR_COMMAND, &cmd) < 0) return (errno); return (0); } @@ -650,7 +670,7 @@ mps_pass_command(int fd, void *req, uint32_t req_len, void *reply, uint32_t reply_len, void *data_in, uint32_t datain_len, void *data_out, uint32_t dataout_len, uint32_t timeout) { - struct mps_pass_thru pass; + struct mprs_pass_thru pass; pass.PtrRequest = (uint64_t)(uintptr_t)req; pass.PtrReply = (uint64_t)(uintptr_t)reply; @@ -660,14 +680,31 @@ mps_pass_command(int fd, void *req, uint32_t req_len, void *reply, pass.ReplySize = reply_len; pass.DataSize = datain_len; pass.DataOutSize = dataout_len; - if (datain_len && dataout_len) - pass.DataDirection = MPS_PASS_THRU_DIRECTION_BOTH; - else if (datain_len) - pass.DataDirection = MPS_PASS_THRU_DIRECTION_READ; - else if (dataout_len) - pass.DataDirection = MPS_PASS_THRU_DIRECTION_WRITE; - else - pass.DataDirection = MPS_PASS_THRU_DIRECTION_NONE; + if (datain_len && dataout_len) { + if (is_mps) { + pass.DataDirection = MPS_PASS_THRU_DIRECTION_BOTH; + } else { + pass.DataDirection = MPR_PASS_THRU_DIRECTION_BOTH; + } + } else if (datain_len) { + if (is_mps) { + pass.DataDirection = MPS_PASS_THRU_DIRECTION_READ; + } else { + pass.DataDirection = MPR_PASS_THRU_DIRECTION_READ; + } + } else if (dataout_len) { + if (is_mps) { + pass.DataDirection = MPS_PASS_THRU_DIRECTION_WRITE; + } else { + pass.DataDirection = MPR_PASS_THRU_DIRECTION_WRITE; + } + } else { + if (is_mps) { + pass.DataDirection = MPS_PASS_THRU_DIRECTION_NONE; + } else { + pass.DataDirection = MPR_PASS_THRU_DIRECTION_NONE; + } + } pass.Timeout = timeout; if (ioctl(fd, MPTIOCTL_PASS_THRU, &pass) < 0) -- cgit v1.1