⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mptctl.c

📁 内核linux2.4.20,可跟rtlinux3.2打补丁 组成实时linux系统,编译内核
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  linux/drivers/message/fusion/mptctl.c *      Fusion MPT misc device (ioctl) driver. *      For use with PCI chip/adapter(s): *          LSIFC9xx/LSI409xx Fibre Channel *      running LSI Logic Fusion MPT (Message Passing Technology) firmware. * *  Credits: *      This driver would not exist if not for Alan Cox's development *      of the linux i2o driver. * *      A huge debt of gratitude is owed to David S. Miller (DaveM) *      for fixing much of the stupid and broken stuff in the early *      driver while porting to sparc64 platform.  THANK YOU! * *      A big THANKS to Eddie C. Dost for fixing the ioctl path *      and most importantly f/w download on sparc64 platform! *      (plus Eddie's other helpful hints and insights) * *      Thanks to Arnaldo Carvalho de Melo for finding and patching *      a potential memory leak in mpt_ioctl_do_fw_download(), *      and for some kmalloc insight:-) * *      (see also mptbase.c) * *  Copyright (c) 1999-2001 LSI Logic Corporation *  Originally By: Steven J. Ralston, Noah Romer *  (mailto:Steve.Ralston@lsil.com) * *  $Id: mptctl.c,v 1.25.4.1 2001/08/24 20:07:06 sralston Exp $ *//*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//*    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; version 2 of the License.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    NO WARRANTY    THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR    CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT    LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is    solely responsible for determining the appropriateness of using and    distributing the Program and assumes all risks associated with its    exercise of rights under this Agreement, including but not limited to    the risks and costs of program errors, damage to or loss of data,    programs or equipment, and unavailability or interruption of operations.    DISCLAIMER OF LIABILITY    NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL    DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED    HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#include <linux/version.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/slab.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/miscdevice.h>#include <asm/io.h>#include <asm/uaccess.h>#include <linux/proc_fs.h>#define COPYRIGHT	"Copyright (c) 1999-2001 LSI Logic Corporation"#define MODULEAUTHOR	"Steven J. Ralston, Noah Romer"#include "mptbase.h"/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#define my_NAME		"Fusion MPT misc device (ioctl) driver"#define my_VERSION	MPT_LINUX_VERSION_COMMON#define MYNAM		"mptctl"EXPORT_NO_SYMBOLS;MODULE_AUTHOR(MODULEAUTHOR);MODULE_DESCRIPTION(my_NAME);MODULE_LICENSE("GPL");/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static int mptctl_id = -1;static int rwperf_reset = 0;static struct semaphore mptctl_syscall_sem_ioc[MPT_MAX_ADAPTERS];/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static int mpt_ioctl_rwperf(unsigned long arg);static int mpt_ioctl_rwperf_status(unsigned long arg);static int mpt_ioctl_rwperf_reset(unsigned long arg);static int mpt_ioctl_fw_download(unsigned long arg);static int mpt_ioctl_do_fw_download(int ioc, char *ufwbuf, size_t fwlen);static int mpt_ioctl_scsi_cmd(unsigned long arg);/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* * Scatter gather list (SGL) sizes and limits... *///#define MAX_SCSI_FRAGS	9#define MAX_FRAGS_SPILL1	9#define MAX_FRAGS_SPILL2	15#define FRAGS_PER_BUCKET	(MAX_FRAGS_SPILL2 + 1)//#define MAX_CHAIN_FRAGS	64//#define MAX_CHAIN_FRAGS	(15+15+15+16)#define MAX_CHAIN_FRAGS		(4 * MAX_FRAGS_SPILL2 + 1)//  Define max sg LIST bytes ( == (#frags + #chains) * 8 bytes each)//  Works out to: 592d bytes!     (9+1)*8 + 4*(15+1)*8//                  ^----------------- 80 + 512#define MAX_SGL_BYTES		((MAX_FRAGS_SPILL1 + 1 + (4 * FRAGS_PER_BUCKET)) * 8)/* linux only seems to ever give 128kB MAX contiguous (GFP_USER) mem bytes */#define MAX_KMALLOC_SZ		(128*1024)struct buflist {	u8	*kptr;	int	 len;};#define myMAX_TARGETS	(1<<4)#define myMAX_LUNS	(1<<3)#define myMAX_T_MASK	(myMAX_TARGETS-1)#define myMAX_L_MASK	(myMAX_LUNS-1)static u8  DevInUse[myMAX_TARGETS][myMAX_LUNS] = {{0,0}};static u32 DevIosCount[myMAX_TARGETS][myMAX_LUNS] = {{0,0}};static u32 fwReplyBuffer[16];static pMPIDefaultReply_t ReplyMsg = NULL;/* some private forw protos */static SGESimple32_t *kbuf_alloc_2_sgl( int bytes, u32 dir, int *frags,		struct buflist **blp, dma_addr_t *sglbuf_dma, MPT_ADAPTER *ioc);static void kfree_sgl( SGESimple32_t *sgl, dma_addr_t sgl_dma,		struct buflist *buflist, MPT_ADAPTER *ioc);/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//** *	mptctl_syscall_down - Down the MPT adapter syscall semaphore. *	@ioc: Pointer to MPT adapter *	@nonblock: boolean, non-zero if O_NONBLOCK is set * *	All of the mptctl commands can potentially sleep, which is illegal *	with a spinlock held, thus we perform mutual exclusion here. * *	Returns negative errno on error, or zero for success. */static inline intmptctl_syscall_down(MPT_ADAPTER *ioc, int nonblock){	dprintk((KERN_INFO MYNAM "::mpt_syscall_down(%p,%d) called\n", ioc, nonblock));	if (nonblock) {		if (down_trylock(&mptctl_syscall_sem_ioc[ioc->id]))			return -EAGAIN;	} else {		if (down_interruptible(&mptctl_syscall_sem_ioc[ioc->id]))			return -ERESTARTSYS;	}	return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* *  This is the callback for any message we have posted. The message itself *  will be returned to the message pool when we return from the IRQ * *  This runs in irq context so be short and sweet. */static intmptctl_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply){	u8 targ;	//dprintk((KERN_DEBUG MYNAM ": Got mptctl_reply()!\n"));	if (req && req->u.hdr.Function == MPI_FUNCTION_SCSI_IO_REQUEST) {		targ = req->u.scsireq.TargetID & myMAX_T_MASK;		DevIosCount[targ][0]--;	} else if (reply && req && req->u.hdr.Function == MPI_FUNCTION_FW_DOWNLOAD) {		// NOTE: Expects/requires non-Turbo reply!		dprintk((KERN_INFO MYNAM ": Caching MPI_FUNCTION_FW_DOWNLOAD reply!\n"));		memcpy(fwReplyBuffer, reply, MIN(sizeof(fwReplyBuffer), 4*reply->u.reply.MsgLength));		ReplyMsg = (pMPIDefaultReply_t) fwReplyBuffer;	}	return 1;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* *  struct file_operations functionality.  *  Members: *	llseek, write, read, ioctl, open, release *//*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,9)static loff_tmptctl_llseek(struct file *file, loff_t offset, int origin){	return -ESPIPE;}#define no_llseek mptctl_llseek#endif/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static ssize_tmptctl_write(struct file *file, const char *buf, size_t count, loff_t *ppos){	printk(KERN_ERR MYNAM ": ioctl WRITE not yet supported\n");	return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static ssize_tmptctl_read(struct file *file, char *buf, size_t count, loff_t *ptr){	return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* *  MPT ioctl handler */static intmpt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg){	struct mpt_ioctl_sanity	*usanity = (struct mpt_ioctl_sanity *) arg;	struct mpt_ioctl_sanity	 ksanity;	int iocnum;	unsigned iocnumX;	int nonblock = (file->f_flags & O_NONBLOCK);	int ret;	MPT_ADAPTER *iocp = NULL;	dprintk((KERN_INFO MYNAM "::mpt_ioctl() called\n"));	if (copy_from_user(&ksanity, usanity, sizeof(ksanity))) {		printk(KERN_ERR "%s::mpt_ioctl() @%d - "				"Unable to copy mpt_ioctl_sanity data @ %p\n",				__FILE__, __LINE__, (void*)usanity);		return -EFAULT;	}	ret = -ENXIO;				/* (-6) No such device or address */	/* Verify intended MPT adapter */	iocnumX = ksanity.iocnum & 0xFF;	if (((iocnum = mpt_verify_adapter(iocnumX, &iocp)) < 0) ||	    (iocp == NULL)) {		printk(KERN_ERR "%s::mpt_ioctl() @%d - ioc%d not found!\n",				__FILE__, __LINE__, iocnumX);		return -ENODEV;	}	if ((ret = mptctl_syscall_down(iocp, nonblock)) != 0)		return ret;	dprintk((KERN_INFO MYNAM "::mpt_ioctl() - Using %s\n", iocp->name));	switch(cmd) {	case MPTRWPERF:		ret = mpt_ioctl_rwperf(arg);		break;	case MPTRWPERF_CHK:		ret = mpt_ioctl_rwperf_status(arg);		break;	case MPTRWPERF_RESET:		ret = mpt_ioctl_rwperf_reset(arg);		break;	case MPTFWDOWNLOAD:		ret = mpt_ioctl_fw_download(arg);		break;	case MPTSCSICMD:		ret = mpt_ioctl_scsi_cmd(arg);		break;	default:		ret = -EINVAL;	}	up(&mptctl_syscall_sem_ioc[iocp->id]);	return ret;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static int mptctl_open(struct inode *inode, struct file *file){	/*	 * Should support multiple management users	 */	return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static int mptctl_release(struct inode *inode, struct file *file){	return 0;}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/static intmpt_ioctl_fw_download(unsigned long arg){	struct mpt_fw_xfer	*ufwdl = (struct mpt_fw_xfer *) arg;	struct mpt_fw_xfer	 kfwdl;	dprintk((KERN_INFO "mpt_ioctl_fwdl called. mptctl_id = %xh\n", mptctl_id)); //tc	if (copy_from_user(&kfwdl, ufwdl, sizeof(struct mpt_fw_xfer))) {		printk(KERN_ERR "%s@%d::_ioctl_fwdl - "				"Unable to copy mpt_fw_xfer struct @ %p\n",				__FILE__, __LINE__, (void*)ufwdl);		return -EFAULT;	}	return mpt_ioctl_do_fw_download(kfwdl.iocnum, kfwdl.bufp, kfwdl.fwlen);}/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*//* * MPT FW Download */static intmpt_ioctl_do_fw_download(int ioc, char *ufwbuf, size_t fwlen){	FWDownload_t		*dlmsg;	MPT_FRAME_HDR		*mf;	MPT_ADAPTER		*iocp;//	char			*fwbuf;//	dma_addr_t		 fwbuf_dma;	FWDownloadTCSGE_t	*fwVoodoo;//	SGEAllUnion_t		*fwSgl;	int			 ret;	SGESimple32_t	*sgl;	SGESimple32_t	*sgOut, *sgIn;	dma_addr_t	 sgl_dma;	struct buflist	*buflist = NULL;	struct buflist	*bl = NULL;	int		 numfrags = 0;	int		 maxfrags;	int		 n = 0;	u32		 sgdir;	u32		 nib;	int		 fw_bytes_copied = 0;	u16		 iocstat;	int		 i;	dprintk((KERN_INFO "mpt_ioctl_do_fwdl called. mptctl_id = %xh.\n", mptctl_id));	dprintk((KERN_INFO "DbG: kfwdl.bufp  = %p\n", ufwbuf));	dprintk((KERN_INFO "DbG: kfwdl.fwlen = %d\n", (int)fwlen));	dprintk((KERN_INFO "DbG: kfwdl.ioc   = %04xh\n", ioc));	if ((ioc = mpt_verify_adapter(ioc, &iocp)) < 0) {		printk("%s@%d::_ioctl_fwdl - ioc%d not found!\n",				__FILE__, __LINE__, ioc);		return -ENXIO; /* (-6) No such device or address */	}	if ((mf = mpt_get_msg_frame(mptctl_id, ioc)) == NULL)		return -EAGAIN;	dlmsg = (FWDownload_t*) mf;	fwVoodoo = (FWDownloadTCSGE_t *) &dlmsg->SGL;	sgOut = (SGESimple32_t *) (fwVoodoo + 1);	/*	 * Construct f/w download request	 */	dlmsg->ImageType = MPI_FW_DOWNLOAD_ITYPE_FW;	dlmsg->Reserved = 0;	dlmsg->ChainOffset = 0;	dlmsg->Function = MPI_FUNCTION_FW_DOWNLOAD;	dlmsg->Reserved1[0] = dlmsg->Reserved1[1] = dlmsg->Reserved1[2] = 0;	dlmsg->MsgFlags = 0;	fwVoodoo->Reserved = 0;	fwVoodoo->ContextSize = 0;	fwVoodoo->DetailsLength = 12;	fwVoodoo->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;	fwVoodoo->Reserved1 = 0;	fwVoodoo->ImageOffset = 0;	fwVoodoo->ImageSize = cpu_to_le32(fwlen);	/*	 * Need to kmalloc area(s) for holding firmware image bytes.	 * But we need to do it piece meal, using a proper	 * scatter gather list (with 128kB MAX hunks).	 * 	 * A practical limit here might be # of sg hunks that fit into	 * a single IOC request frame; 12 or 8 (see below), so:	 * For FC9xx: 12 x 128kB == 1.5 mB (max)	 * For C1030:  8 x 128kB == 1   mB (max)	 * We could support chaining, but things get ugly(ier:)	 */	sgdir = 0x04000000;		/* IOC will READ from sys mem */	if ((sgl = kbuf_alloc_2_sgl(fwlen, sgdir, &numfrags, &buflist, &sgl_dma, iocp)) == NULL)		return -ENOMEM;	/*	 * We should only need SGL with 2 simple_32bit entries (up to 256 kB)	 * for FC9xx f/w image, but calculate max number of sge hunks	 * we can fit into a request frame, and limit ourselves to that.	 * (currently no chain support)	 * For FC9xx: (128-12-16)/8 = 12.5 = 12	 * For C1030:  (96-12-16)/8 =  8.5 =  8	 */	maxfrags = (iocp->req_sz - sizeof(MPIHeader_t) - sizeof(FWDownloadTCSGE_t)) / sizeof(SGESimple32_t);	if (numfrags > maxfrags) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -