No logical code change in this pathc.

Only Style 9 changes for mrsas driver.

Reviewed by:	ambrisko
MFC after:	2 weeks
Sponsored by:	AVAGO Technologies
This commit is contained in:
Kashyap D Desai 2014-10-08 10:14:37 +00:00
parent 5d28b9ed32
commit 8e72737119
7 changed files with 7662 additions and 7742 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,43 +1,38 @@
/* /*
* Copyright (c) 2014, LSI Corp. * Copyright (c) 2014, LSI Corp. All rights reserved. Author: Marian Choy
* All rights reserved.
* Author: Marian Choy
* Support: freebsdraid@lsi.com * Support: freebsdraid@lsi.com
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are
* are met: * met:
* *
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright notice,
* notice, this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer. 2. Redistributions
* 2. Redistributions in binary form must reproduce the above copyright * in binary form must reproduce the above copyright notice, this list of
* notice, this list of conditions and the following disclaimer in * conditions and the following disclaimer in the documentation and/or other
* the documentation and/or other materials provided with the * materials provided with the distribution. 3. Neither the name of the
* distribution. * <ORGANIZATION> nor the names of its contributors may be used to endorse or
* 3. Neither the name of the <ORGANIZATION> nor the names of its * promote products derived from this software without specific prior written
* contributors may be used to endorse or promote products derived * permission.
* from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation * The views and conclusions contained in the software and documentation are
* are those of the authors and should not be interpreted as representing * those of the authors and should not be interpreted as representing
* official policies,either expressed or implied, of the FreeBSD Project. * official policies,either expressed or implied, of the FreeBSD Project.
* *
* Send feedback to: <megaraidfbsd@lsi.com> * Send feedback to: <megaraidfbsd@lsi.com> Mail to: LSI Corporation, 1621
* Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 * Barber Lane, Milpitas, CA 95035 ATTN: MegaRaid FreeBSD
* ATTN: MegaRaid FreeBSD
* *
*/ */
@ -47,462 +42,464 @@ __FBSDID("$FreeBSD$");
#include <dev/mrsas/mrsas.h> #include <dev/mrsas/mrsas.h>
#include <dev/mrsas/mrsas_ioctl.h> #include <dev/mrsas/mrsas_ioctl.h>
/* /*
* Function prototypes * Function prototypes
*/ */
int mrsas_alloc_mfi_cmds(struct mrsas_softc *sc); int mrsas_alloc_mfi_cmds(struct mrsas_softc *sc);
int mrsas_passthru(struct mrsas_softc *sc, void *arg, u_long ioctlCmd); int mrsas_passthru(struct mrsas_softc *sc, void *arg, u_long ioctlCmd);
void mrsas_free_ioc_cmd(struct mrsas_softc *sc); void mrsas_free_ioc_cmd(struct mrsas_softc *sc);
void mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd); void mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
void * mrsas_alloc_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd); void *mrsas_alloc_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd);
static int mrsas_create_frame_pool(struct mrsas_softc *sc); static int mrsas_create_frame_pool(struct mrsas_softc *sc);
static void mrsas_alloc_cb(void *arg, bus_dma_segment_t *segs, static void
int nsegs, int error); mrsas_alloc_cb(void *arg, bus_dma_segment_t *segs,
int nsegs, int error);
extern struct mrsas_mfi_cmd* mrsas_get_mfi_cmd(struct mrsas_softc *sc); extern struct mrsas_mfi_cmd *mrsas_get_mfi_cmd(struct mrsas_softc *sc);
extern void mrsas_release_mfi_cmd(struct mrsas_mfi_cmd *cmd); extern void mrsas_release_mfi_cmd(struct mrsas_mfi_cmd *cmd);
extern int mrsas_issue_blocked_cmd(struct mrsas_softc *sc, extern int
mrsas_issue_blocked_cmd(struct mrsas_softc *sc,
struct mrsas_mfi_cmd *cmd); struct mrsas_mfi_cmd *cmd);
/** /*
* mrsas_passthru: Handle pass-through commands * mrsas_passthru: Handle pass-through commands
* input: Adapter instance soft state * input: Adapter instance soft state argument pointer
* argument pointer
* *
* This function is called from mrsas_ioctl() to handle pass-through and * This function is called from mrsas_ioctl() to handle pass-through and ioctl
* ioctl commands to Firmware. * commands to Firmware.
*/ */
int mrsas_passthru( struct mrsas_softc *sc, void *arg, u_long ioctlCmd ) int
mrsas_passthru(struct mrsas_softc *sc, void *arg, u_long ioctlCmd)
{ {
struct mrsas_iocpacket *user_ioc = (struct mrsas_iocpacket *)arg; struct mrsas_iocpacket *user_ioc = (struct mrsas_iocpacket *)arg;
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
struct mrsas_iocpacket32 *user_ioc32 = (struct mrsas_iocpacket32 *)arg; struct mrsas_iocpacket32 *user_ioc32 = (struct mrsas_iocpacket32 *)arg;
#endif #endif
union mrsas_frame *in_cmd = (union mrsas_frame *) &(user_ioc->frame.raw); union mrsas_frame *in_cmd = (union mrsas_frame *)&(user_ioc->frame.raw);
struct mrsas_mfi_cmd *cmd = NULL; struct mrsas_mfi_cmd *cmd = NULL;
bus_dma_tag_t ioctl_data_tag[MAX_IOCTL_SGE]; bus_dma_tag_t ioctl_data_tag[MAX_IOCTL_SGE];
bus_dmamap_t ioctl_data_dmamap[MAX_IOCTL_SGE]; bus_dmamap_t ioctl_data_dmamap[MAX_IOCTL_SGE];
void *ioctl_data_mem[MAX_IOCTL_SGE]; // ioctl data virtual addr void *ioctl_data_mem[MAX_IOCTL_SGE];
bus_addr_t ioctl_data_phys_addr[MAX_IOCTL_SGE]; // ioctl data phys addr bus_addr_t ioctl_data_phys_addr[MAX_IOCTL_SGE];
bus_dma_tag_t ioctl_sense_tag = 0; bus_dma_tag_t ioctl_sense_tag = 0;
bus_dmamap_t ioctl_sense_dmamap = 0; bus_dmamap_t ioctl_sense_dmamap = 0;
void *ioctl_sense_mem = 0; void *ioctl_sense_mem = 0;
bus_addr_t ioctl_sense_phys_addr = 0; bus_addr_t ioctl_sense_phys_addr = 0;
int i, ioctl_data_size=0, ioctl_sense_size, ret=0; int i, ioctl_data_size = 0, ioctl_sense_size, ret = 0;
struct mrsas_sge32 *kern_sge32; struct mrsas_sge32 *kern_sge32;
unsigned long *sense_ptr; unsigned long *sense_ptr;
uint8_t *iov_base_ptrin=NULL; uint8_t *iov_base_ptrin = NULL;
size_t iov_len=0; size_t iov_len = 0;
/* /*
* Check for NOP from MegaCli... MegaCli can issue a DCMD of 0. In this * Check for NOP from MegaCli... MegaCli can issue a DCMD of 0. In
* case do nothing and return 0 to it as status. * this case do nothing and return 0 to it as status.
*/ */
if (in_cmd->dcmd.opcode == 0) { if (in_cmd->dcmd.opcode == 0) {
device_printf(sc->mrsas_dev, "In %s() Got a NOP\n", __func__); device_printf(sc->mrsas_dev, "In %s() Got a NOP\n", __func__);
user_ioc->frame.hdr.cmd_status = MFI_STAT_OK; user_ioc->frame.hdr.cmd_status = MFI_STAT_OK;
return (0); return (0);
} }
/* Validate SGL length */
if (user_ioc->sge_count > MAX_IOCTL_SGE) {
device_printf(sc->mrsas_dev, "In %s() SGL is too long (%d > 8).\n",
__func__, user_ioc->sge_count);
return (ENOENT);
}
/* Get a command */
cmd = mrsas_get_mfi_cmd(sc);
if (!cmd) {
device_printf(sc->mrsas_dev, "Failed to get a free cmd for IOCTL\n");
return (ENOMEM);
}
/*
* User's IOCTL packet has 2 frames (maximum). Copy those two frames
* into our cmd's frames. cmd->frame's context will get overwritten
* when we copy from user's frames. So set that value alone
* separately
*/
memcpy(cmd->frame, user_ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE);
cmd->frame->hdr.context = cmd->index;
cmd->frame->hdr.pad_0 = 0;
cmd->frame->hdr.flags &= ~(MFI_FRAME_IEEE | MFI_FRAME_SGL64 |
MFI_FRAME_SENSE64);
/* Validate SGL length */ /*
if (user_ioc->sge_count > MAX_IOCTL_SGE) { * The management interface between applications and the fw uses MFI
device_printf(sc->mrsas_dev, "In %s() SGL is too long (%d > 8).\n", * frames. E.g, RAID configuration changes, LD property changes etc
__func__, user_ioc->sge_count); * are accomplishes through different kinds of MFI frames. The driver
return(ENOENT); * needs to care only about substituting user buffers with kernel
} * buffers in SGLs. The location of SGL is embedded in the struct
* iocpacket itself.
*/
kern_sge32 = (struct mrsas_sge32 *)
((unsigned long)cmd->frame + user_ioc->sgl_off);
/* Get a command */ /*
cmd = mrsas_get_mfi_cmd(sc); * For each user buffer, create a mirror buffer and copy in
if (!cmd) { */
device_printf(sc->mrsas_dev, "Failed to get a free cmd for IOCTL\n"); for (i = 0; i < user_ioc->sge_count; i++) {
return(ENOMEM); if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) {
} if (!user_ioc->sgl[i].iov_len)
continue;
/* ioctl_data_size = user_ioc->sgl[i].iov_len;
* User's IOCTL packet has 2 frames (maximum). Copy those two
* frames into our cmd's frames. cmd->frame's context will get
* overwritten when we copy from user's frames. So set that value
* alone separately
*/
memcpy(cmd->frame, user_ioc->frame.raw, 2 * MEGAMFI_FRAME_SIZE);
cmd->frame->hdr.context = cmd->index;
cmd->frame->hdr.pad_0 = 0;
cmd->frame->hdr.flags &= ~(MFI_FRAME_IEEE | MFI_FRAME_SGL64 |
MFI_FRAME_SENSE64);
/*
* The management interface between applications and the fw uses
* MFI frames. E.g, RAID configuration changes, LD property changes
* etc are accomplishes through different kinds of MFI frames. The
* driver needs to care only about substituting user buffers with
* kernel buffers in SGLs. The location of SGL is embedded in the
* struct iocpacket itself.
*/
kern_sge32 = (struct mrsas_sge32 *)
((unsigned long)cmd->frame + user_ioc->sgl_off);
/*
* For each user buffer, create a mirror buffer and copy in
*/
for (i=0; i < user_ioc->sge_count; i++) {
if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) {
if (!user_ioc->sgl[i].iov_len)
continue;
ioctl_data_size = user_ioc->sgl[i].iov_len;
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
} else { } else {
if (!user_ioc32->sgl[i].iov_len) if (!user_ioc32->sgl[i].iov_len)
continue; continue;
ioctl_data_size = user_ioc32->sgl[i].iov_len; ioctl_data_size = user_ioc32->sgl[i].iov_len;
#endif #endif
} }
if (bus_dma_tag_create( sc->mrsas_parent_tag, // parent if (bus_dma_tag_create(sc->mrsas_parent_tag,
1, 0, // algnmnt, boundary 1, 0,
BUS_SPACE_MAXADDR_32BIT,// lowaddr BUS_SPACE_MAXADDR_32BIT,
BUS_SPACE_MAXADDR, // highaddr BUS_SPACE_MAXADDR,
NULL, NULL, // filter, filterarg NULL, NULL,
ioctl_data_size, // maxsize ioctl_data_size,
1, // msegments 1,
ioctl_data_size, // maxsegsize ioctl_data_size,
BUS_DMA_ALLOCNOW, // flags BUS_DMA_ALLOCNOW,
NULL, NULL, // lockfunc, lockarg NULL, NULL,
&ioctl_data_tag[i])) { &ioctl_data_tag[i])) {
device_printf(sc->mrsas_dev, "Cannot allocate ioctl data tag\n"); device_printf(sc->mrsas_dev, "Cannot allocate ioctl data tag\n");
ret = ENOMEM;
goto out;
}
if (bus_dmamem_alloc(ioctl_data_tag[i], (void **)&ioctl_data_mem[i],
(BUS_DMA_NOWAIT | BUS_DMA_ZERO), &ioctl_data_dmamap[i])) {
device_printf(sc->mrsas_dev, "Cannot allocate ioctl data mem\n");
ret = ENOMEM; ret = ENOMEM;
goto out; goto out;
} }
if (bus_dmamap_load(ioctl_data_tag[i], ioctl_data_dmamap[i], if (bus_dmamem_alloc(ioctl_data_tag[i], (void **)&ioctl_data_mem[i],
ioctl_data_mem[i], ioctl_data_size, mrsas_alloc_cb, (BUS_DMA_NOWAIT | BUS_DMA_ZERO), &ioctl_data_dmamap[i])) {
&ioctl_data_phys_addr[i], BUS_DMA_NOWAIT)) { device_printf(sc->mrsas_dev, "Cannot allocate ioctl data mem\n");
device_printf(sc->mrsas_dev, "Cannot load ioctl data mem\n");
ret = ENOMEM; ret = ENOMEM;
goto out; goto out;
} }
if (bus_dmamap_load(ioctl_data_tag[i], ioctl_data_dmamap[i],
ioctl_data_mem[i], ioctl_data_size, mrsas_alloc_cb,
&ioctl_data_phys_addr[i], BUS_DMA_NOWAIT)) {
device_printf(sc->mrsas_dev, "Cannot load ioctl data mem\n");
ret = ENOMEM;
goto out;
}
/* Save the physical address and length */
kern_sge32[i].phys_addr = (u_int32_t)ioctl_data_phys_addr[i];
/* Save the physical address and length */ if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) {
kern_sge32[i].phys_addr = (u_int32_t)ioctl_data_phys_addr[i]; kern_sge32[i].length = user_ioc->sgl[i].iov_len;
if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) { iov_base_ptrin = user_ioc->sgl[i].iov_base;
kern_sge32[i].length = user_ioc->sgl[i].iov_len; iov_len = user_ioc->sgl[i].iov_len;
iov_base_ptrin = user_ioc->sgl[i].iov_base;
iov_len = user_ioc->sgl[i].iov_len;
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
} else { } else {
kern_sge32[i].length = user_ioc32->sgl[i].iov_len; kern_sge32[i].length = user_ioc32->sgl[i].iov_len;
iov_base_ptrin = PTRIN(user_ioc32->sgl[i].iov_base); iov_base_ptrin = PTRIN(user_ioc32->sgl[i].iov_base);
iov_len = user_ioc32->sgl[i].iov_len; iov_len = user_ioc32->sgl[i].iov_len;
#endif #endif
}
/* Copy in data from user space */
ret = copyin(iov_base_ptrin, ioctl_data_mem[i], iov_len);
if (ret) {
device_printf(sc->mrsas_dev, "IOCTL copyin failed!\n");
goto out;
}
} }
/* Copy in data from user space */ ioctl_sense_size = user_ioc->sense_len;
ret = copyin(iov_base_ptrin, ioctl_data_mem[i], iov_len);
if (ret) {
device_printf(sc->mrsas_dev, "IOCTL copyin failed!\n");
goto out;
}
}
ioctl_sense_size = user_ioc->sense_len; if (user_ioc->sense_len) {
if (bus_dma_tag_create(sc->mrsas_parent_tag,
if (user_ioc->sense_len) { 1, 0,
if (bus_dma_tag_create( sc->mrsas_parent_tag, // parent BUS_SPACE_MAXADDR_32BIT,
1, 0, // algnmnt, boundary BUS_SPACE_MAXADDR,
BUS_SPACE_MAXADDR_32BIT,// lowaddr NULL, NULL,
BUS_SPACE_MAXADDR, // highaddr ioctl_sense_size,
NULL, NULL, // filter, filterarg 1,
ioctl_sense_size, // maxsize ioctl_sense_size,
1, // msegments BUS_DMA_ALLOCNOW,
ioctl_sense_size, // maxsegsize NULL, NULL,
BUS_DMA_ALLOCNOW, // flags &ioctl_sense_tag)) {
NULL, NULL, // lockfunc, lockarg device_printf(sc->mrsas_dev, "Cannot allocate ioctl sense tag\n");
&ioctl_sense_tag)) { ret = ENOMEM;
device_printf(sc->mrsas_dev, "Cannot allocate ioctl sense tag\n");
ret = ENOMEM;
goto out; goto out;
} }
if (bus_dmamem_alloc(ioctl_sense_tag, (void **)&ioctl_sense_mem, if (bus_dmamem_alloc(ioctl_sense_tag, (void **)&ioctl_sense_mem,
(BUS_DMA_NOWAIT | BUS_DMA_ZERO), &ioctl_sense_dmamap)) { (BUS_DMA_NOWAIT | BUS_DMA_ZERO), &ioctl_sense_dmamap)) {
device_printf(sc->mrsas_dev, "Cannot allocate ioctl sense mem\n"); device_printf(sc->mrsas_dev, "Cannot allocate ioctl sense mem\n");
ret = ENOMEM; ret = ENOMEM;
goto out; goto out;
} }
if (bus_dmamap_load(ioctl_sense_tag, ioctl_sense_dmamap, if (bus_dmamap_load(ioctl_sense_tag, ioctl_sense_dmamap,
ioctl_sense_mem, ioctl_sense_size, mrsas_alloc_cb, ioctl_sense_mem, ioctl_sense_size, mrsas_alloc_cb,
&ioctl_sense_phys_addr, BUS_DMA_NOWAIT)) { &ioctl_sense_phys_addr, BUS_DMA_NOWAIT)) {
device_printf(sc->mrsas_dev, "Cannot load ioctl sense mem\n"); device_printf(sc->mrsas_dev, "Cannot load ioctl sense mem\n");
ret = ENOMEM; ret = ENOMEM;
goto out; goto out;
} }
sense_ptr = sense_ptr =
(unsigned long *)((unsigned long)cmd->frame + user_ioc->sense_off); (unsigned long *)((unsigned long)cmd->frame + user_ioc->sense_off);
sense_ptr = ioctl_sense_mem; sense_ptr = ioctl_sense_mem;
} }
/*
* Set the sync_cmd flag so that the ISR knows not to complete this
* cmd to the SCSI mid-layer
*/
cmd->sync_cmd = 1;
mrsas_issue_blocked_cmd(sc, cmd);
cmd->sync_cmd = 0;
/* /*
* Set the sync_cmd flag so that the ISR knows not to complete this * copy out the kernel buffers to user buffers
* cmd to the SCSI mid-layer */
*/ for (i = 0; i < user_ioc->sge_count; i++) {
cmd->sync_cmd = 1; if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) {
mrsas_issue_blocked_cmd(sc, cmd); iov_base_ptrin = user_ioc->sgl[i].iov_base;
cmd->sync_cmd = 0; iov_len = user_ioc->sgl[i].iov_len;
/*
* copy out the kernel buffers to user buffers
*/
for (i = 0; i < user_ioc->sge_count; i++) {
if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) {
iov_base_ptrin = user_ioc->sgl[i].iov_base;
iov_len = user_ioc->sgl[i].iov_len;
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
} else { } else {
iov_base_ptrin = PTRIN(user_ioc32->sgl[i].iov_base); iov_base_ptrin = PTRIN(user_ioc32->sgl[i].iov_base);
iov_len = user_ioc32->sgl[i].iov_len; iov_len = user_ioc32->sgl[i].iov_len;
#endif #endif
} }
ret = copyout(ioctl_data_mem[i], iov_base_ptrin, iov_len); ret = copyout(ioctl_data_mem[i], iov_base_ptrin, iov_len);
if (ret) { if (ret) {
device_printf(sc->mrsas_dev, "IOCTL copyout failed!\n"); device_printf(sc->mrsas_dev, "IOCTL copyout failed!\n");
goto out; goto out;
} }
} }
/* /*
* copy out the sense * copy out the sense
*/ */
if (user_ioc->sense_len) { if (user_ioc->sense_len) {
/* /*
* sense_buff points to the location that has the user * sense_buff points to the location that has the user sense
* sense buffer address * buffer address
*/ */
sense_ptr = (unsigned long *) ((unsigned long)user_ioc->frame.raw + sense_ptr = (unsigned long *)((unsigned long)user_ioc->frame.raw +
user_ioc->sense_off); user_ioc->sense_off);
ret = copyout(ioctl_sense_mem, (unsigned long*)*sense_ptr, ret = copyout(ioctl_sense_mem, (unsigned long *)*sense_ptr,
user_ioc->sense_len); user_ioc->sense_len);
if (ret) { if (ret) {
device_printf(sc->mrsas_dev, "IOCTL sense copyout failed!\n"); device_printf(sc->mrsas_dev, "IOCTL sense copyout failed!\n");
goto out; goto out;
} }
} }
/*
/* * Return command status to user space
* Return command status to user space */
*/ memcpy(&user_ioc->frame.hdr.cmd_status, &cmd->frame->hdr.cmd_status,
memcpy(&user_ioc->frame.hdr.cmd_status, &cmd->frame->hdr.cmd_status, sizeof(u_int8_t));
sizeof(u_int8_t));
out: out:
/* /*
* Release sense buffer * Release sense buffer
*/ */
if (ioctl_sense_phys_addr) if (ioctl_sense_phys_addr)
bus_dmamap_unload(ioctl_sense_tag, ioctl_sense_dmamap); bus_dmamap_unload(ioctl_sense_tag, ioctl_sense_dmamap);
if (ioctl_sense_mem != NULL) if (ioctl_sense_mem != NULL)
bus_dmamem_free(ioctl_sense_tag, ioctl_sense_mem, ioctl_sense_dmamap); bus_dmamem_free(ioctl_sense_tag, ioctl_sense_mem, ioctl_sense_dmamap);
if (ioctl_sense_tag != NULL) if (ioctl_sense_tag != NULL)
bus_dma_tag_destroy(ioctl_sense_tag); bus_dma_tag_destroy(ioctl_sense_tag);
/* /*
* Release data buffers * Release data buffers
*/ */
for (i = 0; i < user_ioc->sge_count; i++) { for (i = 0; i < user_ioc->sge_count; i++) {
if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) { if (ioctlCmd == MRSAS_IOC_FIRMWARE_PASS_THROUGH64) {
if (!user_ioc->sgl[i].iov_len) if (!user_ioc->sgl[i].iov_len)
continue; continue;
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
} else { } else {
if (!user_ioc32->sgl[i].iov_len) if (!user_ioc32->sgl[i].iov_len)
continue; continue;
#endif #endif
} }
if (ioctl_data_phys_addr[i]) if (ioctl_data_phys_addr[i])
bus_dmamap_unload(ioctl_data_tag[i], ioctl_data_dmamap[i]); bus_dmamap_unload(ioctl_data_tag[i], ioctl_data_dmamap[i]);
if (ioctl_data_mem[i] != NULL) if (ioctl_data_mem[i] != NULL)
bus_dmamem_free(ioctl_data_tag[i], ioctl_data_mem[i], bus_dmamem_free(ioctl_data_tag[i], ioctl_data_mem[i],
ioctl_data_dmamap[i]); ioctl_data_dmamap[i]);
if (ioctl_data_tag[i] != NULL) if (ioctl_data_tag[i] != NULL)
bus_dma_tag_destroy(ioctl_data_tag[i]); bus_dma_tag_destroy(ioctl_data_tag[i]);
} }
/* Free command */ /* Free command */
mrsas_release_mfi_cmd(cmd); mrsas_release_mfi_cmd(cmd);
return(ret); return (ret);
} }
/** /*
* mrsas_alloc_mfi_cmds: Allocates the command packets * mrsas_alloc_mfi_cmds: Allocates the command packets
* input: Adapter instance soft state * input: Adapter instance soft state
* *
* Each IOCTL or passthru command that is issued to the FW are wrapped in a * Each IOCTL or passthru command that is issued to the FW are wrapped in a
* local data structure called mrsas_mfi_cmd. The frame embedded in this * local data structure called mrsas_mfi_cmd. The frame embedded in this
* mrsas_mfi is issued to FW. The array is used only to look up the * mrsas_mfi is issued to FW. The array is used only to look up the
* mrsas_mfi_cmd given the context. The free commands are maintained in a * mrsas_mfi_cmd given the context. The free commands are maintained in a
* linked list. * linked list.
*/ */
int mrsas_alloc_mfi_cmds(struct mrsas_softc *sc) int
mrsas_alloc_mfi_cmds(struct mrsas_softc *sc)
{ {
int i, j; int i, j;
u_int32_t max_cmd; u_int32_t max_cmd;
struct mrsas_mfi_cmd *cmd; struct mrsas_mfi_cmd *cmd;
max_cmd = MRSAS_MAX_MFI_CMDS; max_cmd = MRSAS_MAX_MFI_CMDS;
/* /*
* sc->mfi_cmd_list is an array of struct mrsas_mfi_cmd pointers. Allocate the * sc->mfi_cmd_list is an array of struct mrsas_mfi_cmd pointers.
* dynamic array first and then allocate individual commands. * Allocate the dynamic array first and then allocate individual
*/ * commands.
sc->mfi_cmd_list = malloc(sizeof(struct mrsas_mfi_cmd*)*max_cmd, M_MRSAS, M_NOWAIT); */
if (!sc->mfi_cmd_list) { sc->mfi_cmd_list = malloc(sizeof(struct mrsas_mfi_cmd *) * max_cmd, M_MRSAS, M_NOWAIT);
device_printf(sc->mrsas_dev, "Cannot alloc memory for mfi_cmd cmd_list.\n"); if (!sc->mfi_cmd_list) {
return(ENOMEM); device_printf(sc->mrsas_dev, "Cannot alloc memory for mfi_cmd cmd_list.\n");
} return (ENOMEM);
memset(sc->mfi_cmd_list, 0, sizeof(struct mrsas_mfi_cmd *)*max_cmd); }
for (i = 0; i < max_cmd; i++) { memset(sc->mfi_cmd_list, 0, sizeof(struct mrsas_mfi_cmd *) * max_cmd);
sc->mfi_cmd_list[i] = malloc(sizeof(struct mrsas_mfi_cmd), for (i = 0; i < max_cmd; i++) {
M_MRSAS, M_NOWAIT); sc->mfi_cmd_list[i] = malloc(sizeof(struct mrsas_mfi_cmd),
if (!sc->mfi_cmd_list[i]) { M_MRSAS, M_NOWAIT);
for (j = 0; j < i; j++) if (!sc->mfi_cmd_list[i]) {
free(sc->mfi_cmd_list[j],M_MRSAS); for (j = 0; j < i; j++)
free(sc->mfi_cmd_list, M_MRSAS); free(sc->mfi_cmd_list[j], M_MRSAS);
sc->mfi_cmd_list = NULL; free(sc->mfi_cmd_list, M_MRSAS);
return(ENOMEM); sc->mfi_cmd_list = NULL;
} return (ENOMEM);
} }
}
for (i = 0; i < max_cmd; i++) { for (i = 0; i < max_cmd; i++) {
cmd = sc->mfi_cmd_list[i]; cmd = sc->mfi_cmd_list[i];
memset(cmd, 0, sizeof(struct mrsas_mfi_cmd)); memset(cmd, 0, sizeof(struct mrsas_mfi_cmd));
cmd->index = i; cmd->index = i;
cmd->ccb_ptr = NULL; cmd->ccb_ptr = NULL;
cmd->sc = sc; cmd->sc = sc;
TAILQ_INSERT_TAIL(&(sc->mrsas_mfi_cmd_list_head), cmd, next); TAILQ_INSERT_TAIL(&(sc->mrsas_mfi_cmd_list_head), cmd, next);
} }
/* create a frame pool and assign one frame to each command */ /* create a frame pool and assign one frame to each command */
if (mrsas_create_frame_pool(sc)) { if (mrsas_create_frame_pool(sc)) {
device_printf(sc->mrsas_dev, "Cannot allocate DMA frame pool.\n"); device_printf(sc->mrsas_dev, "Cannot allocate DMA frame pool.\n");
for (i = 0; i < MRSAS_MAX_MFI_CMDS; i++) { // Free the frames /* Free the frames */
cmd = sc->mfi_cmd_list[i]; for (i = 0; i < MRSAS_MAX_MFI_CMDS; i++) {
mrsas_free_frame(sc, cmd); cmd = sc->mfi_cmd_list[i];
} mrsas_free_frame(sc, cmd);
if (sc->mficmd_frame_tag != NULL) }
bus_dma_tag_destroy(sc->mficmd_frame_tag); if (sc->mficmd_frame_tag != NULL)
return(ENOMEM); bus_dma_tag_destroy(sc->mficmd_frame_tag);
} return (ENOMEM);
}
return(0); return (0);
} }
/** /*
* mrsas_create_frame_pool - Creates DMA pool for cmd frames * mrsas_create_frame_pool: Creates DMA pool for cmd frames
* input: Adapter soft state * input: Adapter soft state
* *
* Each command packet has an embedded DMA memory buffer that is used for * Each command packet has an embedded DMA memory buffer that is used for
* filling MFI frame and the SG list that immediately follows the frame. This * filling MFI frame and the SG list that immediately follows the frame. This
* function creates those DMA memory buffers for each command packet by using * function creates those DMA memory buffers for each command packet by using
* PCI pool facility. pad_0 is initialized to 0 to prevent corrupting value * PCI pool facility. pad_0 is initialized to 0 to prevent corrupting value
* of context and could cause FW crash. * of context and could cause FW crash.
*/ */
static int mrsas_create_frame_pool(struct mrsas_softc *sc) static int
mrsas_create_frame_pool(struct mrsas_softc *sc)
{ {
int i; int i;
struct mrsas_mfi_cmd *cmd; struct mrsas_mfi_cmd *cmd;
if (bus_dma_tag_create( sc->mrsas_parent_tag, // parent if (bus_dma_tag_create(sc->mrsas_parent_tag,
1, 0, // algnmnt, boundary 1, 0,
BUS_SPACE_MAXADDR_32BIT,// lowaddr BUS_SPACE_MAXADDR_32BIT,
BUS_SPACE_MAXADDR, // highaddr BUS_SPACE_MAXADDR,
NULL, NULL, // filter, filterarg NULL, NULL,
MRSAS_MFI_FRAME_SIZE, // maxsize MRSAS_MFI_FRAME_SIZE,
1, // msegments 1,
MRSAS_MFI_FRAME_SIZE, // maxsegsize MRSAS_MFI_FRAME_SIZE,
BUS_DMA_ALLOCNOW, // flags BUS_DMA_ALLOCNOW,
NULL, NULL, // lockfunc, lockarg NULL, NULL,
&sc->mficmd_frame_tag)) { &sc->mficmd_frame_tag)) {
device_printf(sc->mrsas_dev, "Cannot create MFI frame tag\n"); device_printf(sc->mrsas_dev, "Cannot create MFI frame tag\n");
return (ENOMEM); return (ENOMEM);
} }
for (i = 0; i < MRSAS_MAX_MFI_CMDS; i++) {
cmd = sc->mfi_cmd_list[i];
cmd->frame = mrsas_alloc_frame(sc, cmd);
if (cmd->frame == NULL) {
device_printf(sc->mrsas_dev, "Cannot alloc MFI frame memory\n");
return (ENOMEM);
}
memset(cmd->frame, 0, MRSAS_MFI_FRAME_SIZE);
cmd->frame->io.context = cmd->index;
cmd->frame->io.pad_0 = 0;
}
for (i = 0; i < MRSAS_MAX_MFI_CMDS; i++) { return (0);
cmd = sc->mfi_cmd_list[i];
cmd->frame = mrsas_alloc_frame(sc, cmd);
if (cmd->frame == NULL) {
device_printf(sc->mrsas_dev, "Cannot alloc MFI frame memory\n");
return (ENOMEM);
}
memset(cmd->frame, 0, MRSAS_MFI_FRAME_SIZE);
cmd->frame->io.context = cmd->index;
cmd->frame->io.pad_0 = 0;
}
return(0);
}
/**
* mrsas_alloc_frame - Allocates MFI Frames
* input: Adapter soft state
*
* Create bus DMA memory tag and dmamap and load memory for MFI frames.
* Returns virtual memory pointer to allocated region.
*/
void *mrsas_alloc_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd)
{
u_int32_t frame_size = MRSAS_MFI_FRAME_SIZE;
if (bus_dmamem_alloc(sc->mficmd_frame_tag, (void **)&cmd->frame_mem,
BUS_DMA_NOWAIT, &cmd->frame_dmamap)) {
device_printf(sc->mrsas_dev, "Cannot alloc MFI frame memory\n");
return (NULL);
}
if (bus_dmamap_load(sc->mficmd_frame_tag, cmd->frame_dmamap,
cmd->frame_mem, frame_size, mrsas_alloc_cb,
&cmd->frame_phys_addr, BUS_DMA_NOWAIT)) {
device_printf(sc->mrsas_dev, "Cannot load IO request memory\n");
return (NULL);
}
return(cmd->frame_mem);
} }
/* /*
* mrsas_alloc_cb: Callback function of bus_dmamap_load() * mrsas_alloc_frame: Allocates MFI Frames
* input: callback argument, * input: Adapter soft state
* machine dependent type that describes DMA segments,
* number of segments,
* error code.
* *
* This function is for the driver to receive mapping information resultant * Create bus DMA memory tag and dmamap and load memory for MFI frames. Returns
* of the bus_dmamap_load(). The information is actually not being used, * virtual memory pointer to allocated region.
* but the address is saved anyway.
*/ */
static void mrsas_alloc_cb(void *arg, bus_dma_segment_t *segs, void *
int nsegs, int error) mrsas_alloc_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd)
{ {
bus_addr_t *addr; u_int32_t frame_size = MRSAS_MFI_FRAME_SIZE;
addr = arg; if (bus_dmamem_alloc(sc->mficmd_frame_tag, (void **)&cmd->frame_mem,
*addr = segs[0].ds_addr; BUS_DMA_NOWAIT, &cmd->frame_dmamap)) {
device_printf(sc->mrsas_dev, "Cannot alloc MFI frame memory\n");
return (NULL);
}
if (bus_dmamap_load(sc->mficmd_frame_tag, cmd->frame_dmamap,
cmd->frame_mem, frame_size, mrsas_alloc_cb,
&cmd->frame_phys_addr, BUS_DMA_NOWAIT)) {
device_printf(sc->mrsas_dev, "Cannot load IO request memory\n");
return (NULL);
}
return (cmd->frame_mem);
} }
/** /*
* mrsas_free_frames: Frees memory for MFI frames * mrsas_alloc_cb: Callback function of bus_dmamap_load()
* input: Adapter soft state * input: callback argument,
* machine dependent type that describes DMA segments,
* number of segments,
* error code.
* *
* Deallocates MFI frames memory. Called from mrsas_free_mem() during * This function is for the driver to receive mapping information resultant of
* detach and error case during creation of frame pool. * the bus_dmamap_load(). The information is actually not being used, but the
* address is saved anyway.
*/ */
void mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd) static void
mrsas_alloc_cb(void *arg, bus_dma_segment_t *segs,
int nsegs, int error)
{ {
if (cmd->frame_phys_addr) bus_addr_t *addr;
bus_dmamap_unload(sc->mficmd_frame_tag, cmd->frame_dmamap);
if (cmd->frame_mem != NULL) addr = arg;
bus_dmamem_free(sc->mficmd_frame_tag, cmd->frame_mem, cmd->frame_dmamap); *addr = segs[0].ds_addr;
}
/*
* mrsas_free_frames: Frees memory for MFI frames
* input: Adapter soft state
*
* Deallocates MFI frames memory. Called from mrsas_free_mem() during detach
* and error case during creation of frame pool.
*/
void
mrsas_free_frame(struct mrsas_softc *sc, struct mrsas_mfi_cmd *cmd)
{
if (cmd->frame_phys_addr)
bus_dmamap_unload(sc->mficmd_frame_tag, cmd->frame_dmamap);
if (cmd->frame_mem != NULL)
bus_dmamem_free(sc->mficmd_frame_tag, cmd->frame_mem, cmd->frame_dmamap);
} }

View File

@ -1,43 +1,38 @@
/* /*
* Copyright (c) 2014, LSI Corp. * Copyright (c) 2014, LSI Corp. All rights reserved. Author: Marian Choy
* All rights reserved.
* Author: Marian Choy
* Support: freebsdraid@lsi.com * Support: freebsdraid@lsi.com
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are
* are met: * met:
* *
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright notice,
* notice, this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer. 2. Redistributions
* 2. Redistributions in binary form must reproduce the above copyright * in binary form must reproduce the above copyright notice, this list of
* notice, this list of conditions and the following disclaimer in * conditions and the following disclaimer in the documentation and/or other
* the documentation and/or other materials provided with the * materials provided with the distribution. 3. Neither the name of the
* distribution. * <ORGANIZATION> nor the names of its contributors may be used to endorse or
* 3. Neither the name of the <ORGANIZATION> nor the names of its * promote products derived from this software without specific prior written
* contributors may be used to endorse or promote products derived * permission.
* from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation * The views and conclusions contained in the software and documentation are
* are those of the authors and should not be interpreted as representing * those of the authors and should not be interpreted as representing
* official policies,either expressed or implied, of the FreeBSD Project. * official policies,either expressed or implied, of the FreeBSD Project.
* *
* Send feedback to: <megaraidfbsd@lsi.com> * Send feedback to: <megaraidfbsd@lsi.com> Mail to: LSI Corporation, 1621
* Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 * Barber Lane, Milpitas, CA 95035 ATTN: MegaRaid FreeBSD
* ATTN: MegaRaid FreeBSD
* *
*/ */
@ -45,11 +40,11 @@
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
#ifndef MRSAS_IOCTL_H #ifndef MRSAS_IOCTL_H
#define MRSAS_IOCTL_H #define MRSAS_IOCTL_H
#ifndef _IOWR #ifndef _IOWR
#include <sys/ioccom.h> #include <sys/ioccom.h>
#endif /* !_IOWR */ #endif /* !_IOWR */
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
/* Compilation error FIX */ /* Compilation error FIX */
@ -61,69 +56,71 @@ __FBSDID("$FreeBSD$");
#endif #endif
/* /*
* We need to use the same values as the mfi driver until MegaCli adds * We need to use the same values as the mfi driver until MegaCli adds
* support for this (mrsas) driver: * support for this (mrsas) driver: M is for MegaRAID. (This is typically the
* M is for MegaRAID. (This is typically the vendor or product initial) * vendor or product initial) 1 arbitrary. (This may be used to segment kinds
* 1 arbitrary. (This may be used to segment kinds of commands. * of commands. (1-9 status, 10-20 policy, etc.) struct mrsas_iocpacket
* (1-9 status, 10-20 policy, etc.) * (sizeof() this parameter will be used.) These three values are encoded
* struct mrsas_iocpacket (sizeof() this parameter will be used.) * into a somewhat unique, 32-bit value.
* These three values are encoded into a somewhat unique, 32-bit value.
*/ */
#define MRSAS_IOC_FIRMWARE_PASS_THROUGH64 _IOWR('M', 1, struct mrsas_iocpacket) #define MRSAS_IOC_FIRMWARE_PASS_THROUGH64 _IOWR('M', 1, struct mrsas_iocpacket)
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
#define MRSAS_IOC_FIRMWARE_PASS_THROUGH32 _IOWR('M', 1, struct mrsas_iocpacket32) #define MRSAS_IOC_FIRMWARE_PASS_THROUGH32 _IOWR('M', 1, struct mrsas_iocpacket32)
#endif #endif
#define MRSAS_IOC_SCAN_BUS _IO('M', 10) #define MRSAS_IOC_SCAN_BUS _IO('M', 10)
#define MRSAS_LINUX_CMD32 0xc1144d01 #define MRSAS_LINUX_CMD32 0xc1144d01
#define MAX_IOCTL_SGE 16 #define MAX_IOCTL_SGE 16
#define MFI_FRAME_DIR_READ 0x0010 #define MFI_FRAME_DIR_READ 0x0010
#define MFI_CMD_LD_SCSI_IO 0x03 #define MFI_CMD_LD_SCSI_IO 0x03
#define INQUIRY_CMD 0x12 #define INQUIRY_CMD 0x12
#define INQUIRY_CMDLEN 6 #define INQUIRY_CMDLEN 6
#define INQUIRY_REPLY_LEN 96 #define INQUIRY_REPLY_LEN 96
#define INQUIRY_VENDOR 8 /* Offset in reply data to vendor name */ #define INQUIRY_VENDOR 8 /* Offset in reply data to
#define SCSI_SENSE_BUFFERSIZE 96 * vendor name */
#define SCSI_SENSE_BUFFERSIZE 96
#define MEGAMFI_RAW_FRAME_SIZE 128 #define MEGAMFI_RAW_FRAME_SIZE 128
#pragma pack(1) #pragma pack(1)
struct mrsas_iocpacket { struct mrsas_iocpacket {
u_int16_t host_no; u_int16_t host_no;
u_int16_t __pad1; u_int16_t __pad1;
u_int32_t sgl_off; u_int32_t sgl_off;
u_int32_t sge_count; u_int32_t sge_count;
u_int32_t sense_off; u_int32_t sense_off;
u_int32_t sense_len; u_int32_t sense_len;
union { union {
u_int8_t raw[MEGAMFI_RAW_FRAME_SIZE]; u_int8_t raw[MEGAMFI_RAW_FRAME_SIZE];
struct mrsas_header hdr; struct mrsas_header hdr;
} frame; } frame;
struct iovec sgl[MAX_IOCTL_SGE]; struct iovec sgl[MAX_IOCTL_SGE];
}; };
#pragma pack() #pragma pack()
#ifdef COMPAT_FREEBSD32 #ifdef COMPAT_FREEBSD32
#pragma pack(1) #pragma pack(1)
struct mrsas_iocpacket32 { struct mrsas_iocpacket32 {
u_int16_t host_no; u_int16_t host_no;
u_int16_t __pad1; u_int16_t __pad1;
u_int32_t sgl_off; u_int32_t sgl_off;
u_int32_t sge_count; u_int32_t sge_count;
u_int32_t sense_off; u_int32_t sense_off;
u_int32_t sense_len; u_int32_t sense_len;
union { union {
u_int8_t raw[MEGAMFI_RAW_FRAME_SIZE]; u_int8_t raw[MEGAMFI_RAW_FRAME_SIZE];
struct mrsas_header hdr; struct mrsas_header hdr;
} frame; } frame;
struct iovec32 sgl[MAX_IOCTL_SGE]; struct iovec32 sgl[MAX_IOCTL_SGE];
}; };
#pragma pack()
#endif /* COMPAT_FREEBSD32 */
#endif /* MRSAS_IOCTL_H */ #pragma pack()
#endif /* COMPAT_FREEBSD32 */
#endif /* MRSAS_IOCTL_H */

View File

@ -1,48 +1,43 @@
/* /*
* Copyright (c) 2014, LSI Corp. * Copyright (c) 2014, LSI Corp. All rights reserved. Author: Kashyap Desai,
* All rights reserved. * Sibananda Sahu Support: freebsdraid@lsi.com
* Author: Kashyap Desai, Sibananda Sahu
* Support: freebsdraid@lsi.com
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions are
* are met: * met:
* *
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright notice,
* notice, this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer. 2. Redistributions
* 2. Redistributions in binary form must reproduce the above copyright * in binary form must reproduce the above copyright notice, this list of
* notice, this list of conditions and the following disclaimer in * conditions and the following disclaimer in the documentation and/or other
* the documentation and/or other materials provided with the * materials provided with the distribution. 3. Neither the name of the
* distribution. * <ORGANIZATION> nor the names of its contributors may be used to endorse or
* 3. Neither the name of the <ORGANIZATION> nor the names of its * promote products derived from this software without specific prior written
* contributors may be used to endorse or promote products derived * permission.
* from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation * The views and conclusions contained in the software and documentation are
* are those of the authors and should not be interpreted as representing * those of the authors and should not be interpreted as representing
* official policies,either expressed or implied, of the FreeBSD Project. * official policies,either expressed or implied, of the FreeBSD Project.
* *
* Send feedback to: <megaraidfbsd@lsi.com> * Send feedback to: <megaraidfbsd@lsi.com> Mail to: LSI Corporation, 1621
* Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 * Barber Lane, Milpitas, CA 95035 ATTN: MegaRaid FreeBSD
* ATTN: MegaRaid FreeBSD
* *
* $FreeBSD$
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -58,7 +53,7 @@
#include <sys/proc.h> #include <sys/proc.h>
#include <machine/bus.h> #include <machine/bus.h>
#if defined(__amd64__) /* Assume amd64 wants 32 bit Linux */ #if defined(__amd64__) /* Assume amd64 wants 32 bit Linux */
#include <machine/../linux32/linux.h> #include <machine/../linux32/linux.h>
#include <machine/../linux32/linux32_proto.h> #include <machine/../linux32/linux32_proto.h>
#else #else
@ -72,26 +67,26 @@
#include <dev/mrsas/mrsas_ioctl.h> #include <dev/mrsas/mrsas_ioctl.h>
/* There are multiple ioctl number ranges that need to be handled */ /* There are multiple ioctl number ranges that need to be handled */
#define MRSAS_LINUX_IOCTL_MIN 0x4d00 #define MRSAS_LINUX_IOCTL_MIN 0x4d00
#define MRSAS_LINUX_IOCTL_MAX 0x4d01 #define MRSAS_LINUX_IOCTL_MAX 0x4d01
static linux_ioctl_function_t mrsas_linux_ioctl; static linux_ioctl_function_t mrsas_linux_ioctl;
static struct linux_ioctl_handler mrsas_linux_handler = {mrsas_linux_ioctl, static struct linux_ioctl_handler mrsas_linux_handler = {mrsas_linux_ioctl,
MRSAS_LINUX_IOCTL_MIN, MRSAS_LINUX_IOCTL_MIN,
MRSAS_LINUX_IOCTL_MAX}; MRSAS_LINUX_IOCTL_MAX};
SYSINIT (mrsas_register, SI_SUB_KLD, SI_ORDER_MIDDLE, SYSINIT(mrsas_register, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_register_handler, &mrsas_linux_handler); linux_ioctl_register_handler, &mrsas_linux_handler);
SYSUNINIT(mrsas_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE, SYSUNINIT(mrsas_unregister, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_ioctl_unregister_handler, &mrsas_linux_handler); linux_ioctl_unregister_handler, &mrsas_linux_handler);
static struct linux_device_handler mrsas_device_handler = static struct linux_device_handler mrsas_device_handler =
{ "mrsas", "megaraid_sas", "mrsas0", "megaraid_sas_ioctl_node", -1, 0, 1}; {"mrsas", "megaraid_sas", "mrsas0", "megaraid_sas_ioctl_node", -1, 0, 1};
SYSINIT (mrsas_register2, SI_SUB_KLD, SI_ORDER_MIDDLE, SYSINIT(mrsas_register2, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_device_register_handler, &mrsas_device_handler); linux_device_register_handler, &mrsas_device_handler);
SYSUNINIT(mrsas_unregister2, SI_SUB_KLD, SI_ORDER_MIDDLE, SYSUNINIT(mrsas_unregister2, SI_SUB_KLD, SI_ORDER_MIDDLE,
linux_device_unregister_handler, &mrsas_device_handler); linux_device_unregister_handler, &mrsas_device_handler);
static int static int
mrsas_linux_modevent(module_t mod __unused, int cmd __unused, void *data __unused) mrsas_linux_modevent(module_t mod __unused, int cmd __unused, void *data __unused)
@ -99,28 +94,36 @@ mrsas_linux_modevent(module_t mod __unused, int cmd __unused, void *data __unuse
return (0); return (0);
} }
/*
* mrsas_linux_ioctl: linux emulator IOCtl commands entry point.
*
* This function is the entry point for IOCtls from linux binaries.
* It calls the mrsas_ioctl function for processing
* depending on the IOCTL command received.
*/
static int static int
mrsas_linux_ioctl(struct thread *p, struct linux_ioctl_args *args) mrsas_linux_ioctl(struct thread *p, struct linux_ioctl_args *args)
{ {
#if (__FreeBSD_version >= 1000000) #if (__FreeBSD_version >= 1000000)
cap_rights_t rights; cap_rights_t rights;
#endif
#endif
struct file *fp; struct file *fp;
int error; int error;
u_long cmd = args->cmd; u_long cmd = args->cmd;
if (cmd != MRSAS_LINUX_CMD32){ if (cmd != MRSAS_LINUX_CMD32) {
error = ENOTSUP; error = ENOTSUP;
goto END; goto END;
} }
#if (__FreeBSD_version >= 1000000)
#if (__FreeBSD_version >= 1000000)
error = fget(p, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp); error = fget(p, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
#elif (__FreeBSD_version <= 900000) #elif (__FreeBSD_version <= 900000)
error = fget(p, args->fd, &fp); error = fget(p, args->fd, &fp);
#else /* For FreeBSD version greater than 9.0.0 but less than 10.0.0 */ #else /* For FreeBSD version greater than
* 9.0.0 but less than 10.0.0 */
error = fget(p, args->fd, CAP_IOCTL, &fp); error = fget(p, args->fd, CAP_IOCTL, &fp);
#endif #endif
if (error != 0) if (error != 0)
goto END; goto END;