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

📄 commsup.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *	Adaptec AAC series RAID controller driver *	(c) Copyright 2001 Red Hat Inc.	<alan@redhat.com> * * based on the old aacraid driver that is.. * Adaptec aacraid device driver for Linux. * * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com) * * 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; either version 2, or (at your option) * any later version. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING.  If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * Module Name: *  commsup.c * * Abstract: Contain all routines that are required for FSA host/adapter *    communication. * */#include <linux/kernel.h>#include <linux/init.h>#include <linux/types.h>#include <linux/sched.h>#include <linux/pci.h>#include <linux/spinlock.h>#include <linux/slab.h>#include <linux/completion.h>#include <linux/blkdev.h>#include <scsi/scsi_host.h>#include <scsi/scsi_device.h>#include <asm/semaphore.h>#include <asm/delay.h>#include "aacraid.h"/** *	fib_map_alloc		-	allocate the fib objects *	@dev: Adapter to allocate for * *	Allocate and map the shared PCI space for the FIB blocks used to *	talk to the Adaptec firmware. */ static int fib_map_alloc(struct aac_dev *dev){	dprintk((KERN_INFO	  "allocate hardware fibs pci_alloc_consistent(%p, %d * (%d + %d), %p)\n",	  dev->pdev, dev->max_fib_size, dev->scsi_host_ptr->can_queue,	  AAC_NUM_MGT_FIB, &dev->hw_fib_pa));	if((dev->hw_fib_va = pci_alloc_consistent(dev->pdev, dev->max_fib_size	  * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB),	  &dev->hw_fib_pa))==NULL)		return -ENOMEM;	return 0;}/** *	fib_map_free		-	free the fib objects *	@dev: Adapter to free * *	Free the PCI mappings and the memory allocated for FIB blocks *	on this adapter. */void fib_map_free(struct aac_dev *dev){	pci_free_consistent(dev->pdev, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB), dev->hw_fib_va, dev->hw_fib_pa);}/** *	fib_setup	-	setup the fibs *	@dev: Adapter to set up * *	Allocate the PCI space for the fibs, map it and then intialise the *	fib area, the unmapped fib data and also the free list */int fib_setup(struct aac_dev * dev){	struct fib *fibptr;	struct hw_fib *hw_fib_va;	dma_addr_t hw_fib_pa;	int i;	while (((i = fib_map_alloc(dev)) == -ENOMEM)	 && (dev->scsi_host_ptr->can_queue > (64 - AAC_NUM_MGT_FIB))) {		dev->init->MaxIoCommands = cpu_to_le32((dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB) >> 1);		dev->scsi_host_ptr->can_queue = le32_to_cpu(dev->init->MaxIoCommands) - AAC_NUM_MGT_FIB;	}	if (i<0)		return -ENOMEM;			hw_fib_va = dev->hw_fib_va;	hw_fib_pa = dev->hw_fib_pa;	memset(hw_fib_va, 0, dev->max_fib_size * (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB));	/*	 *	Initialise the fibs	 */	for (i = 0, fibptr = &dev->fibs[i]; i < (dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); i++, fibptr++) 	{		fibptr->dev = dev;		fibptr->hw_fib = hw_fib_va;		fibptr->data = (void *) fibptr->hw_fib->data;		fibptr->next = fibptr+1;	/* Forward chain the fibs */		init_MUTEX_LOCKED(&fibptr->event_wait);		spin_lock_init(&fibptr->event_lock);		hw_fib_va->header.XferState = cpu_to_le32(0xffffffff);		hw_fib_va->header.SenderSize = cpu_to_le16(dev->max_fib_size);		fibptr->hw_fib_pa = hw_fib_pa;		hw_fib_va = (struct hw_fib *)((unsigned char *)hw_fib_va + dev->max_fib_size);		hw_fib_pa = hw_fib_pa + dev->max_fib_size;	}	/*	 *	Add the fib chain to the free list	 */	dev->fibs[dev->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB - 1].next = NULL;	/*	 *	Enable this to debug out of queue space	 */	dev->free_fib = &dev->fibs[0];	return 0;}/** *	fib_alloc	-	allocate a fib *	@dev: Adapter to allocate the fib for * *	Allocate a fib from the adapter fib pool. If the pool is empty we *	return NULL. */ struct fib * fib_alloc(struct aac_dev *dev){	struct fib * fibptr;	unsigned long flags;	spin_lock_irqsave(&dev->fib_lock, flags);	fibptr = dev->free_fib;		if(!fibptr){		spin_unlock_irqrestore(&dev->fib_lock, flags);		return fibptr;	}	dev->free_fib = fibptr->next;	spin_unlock_irqrestore(&dev->fib_lock, flags);	/*	 *	Set the proper node type code and node byte size	 */	fibptr->type = FSAFS_NTC_FIB_CONTEXT;	fibptr->size = sizeof(struct fib);	/*	 *	Null out fields that depend on being zero at the start of	 *	each I/O	 */	fibptr->hw_fib->header.XferState = 0;	fibptr->callback = NULL;	fibptr->callback_data = NULL;	return fibptr;}/** *	fib_free	-	free a fib *	@fibptr: fib to free up * *	Frees up a fib and places it on the appropriate queue *	(either free or timed out) */ void fib_free(struct fib * fibptr){	unsigned long flags;	spin_lock_irqsave(&fibptr->dev->fib_lock, flags);	if (fibptr->flags & FIB_CONTEXT_FLAG_TIMED_OUT) {		aac_config.fib_timeouts++;		fibptr->next = fibptr->dev->timeout_fib;		fibptr->dev->timeout_fib = fibptr;	} else {		if (fibptr->hw_fib->header.XferState != 0) {			printk(KERN_WARNING "fib_free, XferState != 0, fibptr = 0x%p, XferState = 0x%x\n", 				 (void*)fibptr, 				 le32_to_cpu(fibptr->hw_fib->header.XferState));		}		fibptr->next = fibptr->dev->free_fib;		fibptr->dev->free_fib = fibptr;	}		spin_unlock_irqrestore(&fibptr->dev->fib_lock, flags);}/** *	fib_init	-	initialise a fib *	@fibptr: The fib to initialize *	 *	Set up the generic fib fields ready for use */ void fib_init(struct fib *fibptr){	struct hw_fib *hw_fib = fibptr->hw_fib;	hw_fib->header.StructType = FIB_MAGIC;	hw_fib->header.Size = cpu_to_le16(fibptr->dev->max_fib_size);	hw_fib->header.XferState = cpu_to_le32(HostOwned | FibInitialized | FibEmpty | FastResponseCapable);	hw_fib->header.SenderFibAddress = 0; /* Filled in later if needed */	hw_fib->header.ReceiverFibAddress = cpu_to_le32(fibptr->hw_fib_pa);	hw_fib->header.SenderSize = cpu_to_le16(fibptr->dev->max_fib_size);}/** *	fib_deallocate		-	deallocate a fib *	@fibptr: fib to deallocate * *	Will deallocate and return to the free pool the FIB pointed to by the *	caller. */ static void fib_dealloc(struct fib * fibptr){	struct hw_fib *hw_fib = fibptr->hw_fib;	if(hw_fib->header.StructType != FIB_MAGIC) 		BUG();	hw_fib->header.XferState = 0;        }/* *	Commuication primitives define and support the queuing method we use to *	support host to adapter commuication. All queue accesses happen through *	these routines and are the only routines which have a knowledge of the *	 how these queues are implemented. */ /** *	aac_get_entry		-	get a queue entry *	@dev: Adapter *	@qid: Queue Number *	@entry: Entry return *	@index: Index return *	@nonotify: notification control * *	With a priority the routine returns a queue entry if the queue has free entries. If the queue *	is full(no free entries) than no entry is returned and the function returns 0 otherwise 1 is *	returned. */ static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entry, u32 * index, unsigned long *nonotify){	struct aac_queue * q;	unsigned long idx;	/*	 *	All of the queues wrap when they reach the end, so we check	 *	to see if they have reached the end and if they have we just	 *	set the index back to zero. This is a wrap. You could or off	 *	the high bits in all updates but this is a bit faster I think.	 */	q = &dev->queues->queue[qid];	idx = *index = le32_to_cpu(*(q->headers.producer));	/* Interrupt Moderation, only interrupt for first two entries */	if (idx != le32_to_cpu(*(q->headers.consumer))) {		if (--idx == 0) {			if (qid == AdapNormCmdQueue)				idx = ADAP_NORM_CMD_ENTRIES;			else				idx = ADAP_NORM_RESP_ENTRIES;		}		if (idx != le32_to_cpu(*(q->headers.consumer)))			*nonotify = 1; 	}	if (qid == AdapNormCmdQueue) {	        if (*index >= ADAP_NORM_CMD_ENTRIES) 			*index = 0; /* Wrap to front of the Producer Queue. */	} else {		if (*index >= ADAP_NORM_RESP_ENTRIES) 			*index = 0; /* Wrap to front of the Producer Queue. */	}        if ((*index + 1) == le32_to_cpu(*(q->headers.consumer))) { /* Queue is full */		printk(KERN_WARNING "Queue %d full, %u outstanding.\n",				qid, q->numpending);		return 0;	} else {	        *entry = q->base + *index;		return 1;	}}   /** *	aac_queue_get		-	get the next free QE *	@dev: Adapter *	@index: Returned index *	@priority: Priority of fib *	@fib: Fib to associate with the queue entry *	@wait: Wait if queue full *	@fibptr: Driver fib object to go with fib *	@nonotify: Don't notify the adapter * *	Gets the next free QE off the requested priorty adapter command *	queue and associates the Fib with the QE. The QE represented by *	index is ready to insert on the queue when this routine returns *	success. */static int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify){	struct aac_entry * entry = NULL;	int map = 0;	    	if (qid == AdapNormCmdQueue) {		/*  if no entries wait for some if caller wants to */        	while (!aac_get_entry(dev, qid, &entry, index, nonotify))         	{			printk(KERN_ERR "GetEntries failed\n");		}	        /*	         *	Setup queue entry with a command, status and fib mapped	         */	        entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));	        map = 1;	} else {	        while(!aac_get_entry(dev, qid, &entry, index, nonotify)) 	        {			/* if no entries wait for some if caller wants to */		}        	/*        	 *	Setup queue entry with command, status and fib mapped        	 */        	entry->size = cpu_to_le32(le16_to_cpu(hw_fib->header.Size));        	entry->addr = hw_fib->header.SenderFibAddress;     			/* Restore adapters pointer to the FIB */		hw_fib->header.ReceiverFibAddress = hw_fib->header.SenderFibAddress;	/* Let the adapter now where to find its data */        	map = 0;	}	/*	 *	If MapFib is true than we need to map the Fib and put pointers	 *	in the queue entry.	 */	if (map)		entry->addr = cpu_to_le32(fibptr->hw_fib_pa);	return 0;}/* *	Define the highest level of host to adapter communication routines.  *	These routines will support host to adapter FS commuication. These  *	routines have no knowledge of the commuication method used. This level *	sends and receives FIBs. This level has no knowledge of how these FIBs *	get passed back and forth. *//** *	fib_send	-	send a fib to the adapter *	@command: Command to send *	@fibptr: The fib *	@size: Size of fib data area *	@priority: Priority of Fib *	@wait: Async/sync select *	@reply: True if a reply is wanted *	@callback: Called with reply *	@callback_data: Passed to callback * *	Sends the requested FIB to the adapter and optionally will wait for a *	response FIB. If the caller does not wish to wait for a response than *	an event to wait on must be supplied. This event will be set when a *	response FIB is received from the adapter. */ int fib_send(u16 command, struct fib * fibptr, unsigned long size,  int priority, int wait, int reply, fib_callback callback, void * callback_data){	struct aac_dev * dev = fibptr->dev;	struct hw_fib * hw_fib = fibptr->hw_fib;	struct aac_queue * q;	unsigned long flags = 0;	unsigned long qflags;	if (!(hw_fib->header.XferState & cpu_to_le32(HostOwned)))		return -EBUSY;	/*	 *	There are 5 cases with the wait and reponse requested flags. 	 *	The only invalid cases are if the caller requests to wait and	 *	does not request a response and if the caller does not want a	 *	response and the Fib is not allocated from pool. If a response	 *	is not requesed the Fib will just be deallocaed by the DPC	 *	routine when the response comes back from the adapter. No	 *	further processing will be done besides deleting the Fib. We 	 *	will have a debug mode where the adapter can notify the host	 *	it had a problem and the host can log that fact.	 */	if (wait && !reply) {		return -EINVAL;	} else if (!wait && reply) {		hw_fib->header.XferState |= cpu_to_le32(Async | ResponseExpected);		FIB_COUNTER_INCREMENT(aac_config.AsyncSent);	} else if (!wait && !reply) {		hw_fib->header.XferState |= cpu_to_le32(NoResponseExpected);		FIB_COUNTER_INCREMENT(aac_config.NoResponseSent);	} else if (wait && reply) {		hw_fib->header.XferState |= cpu_to_le32(ResponseExpected);		FIB_COUNTER_INCREMENT(aac_config.NormalSent);	} 	/*	 *	Map the fib into 32bits by using the fib number	 */	hw_fib->header.SenderFibAddress = cpu_to_le32(((u32)(fibptr - dev->fibs)) << 2);	hw_fib->header.SenderData = (u32)(fibptr - dev->fibs);	/*	 *	Set FIB state to indicate where it came from and if we want a	 *	response from the adapter. Also load the command from the	 *	caller.	 *	 *	Map the hw fib pointer as a 32bit value	 */

⌨️ 快捷键说明

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