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

📄 commsup.c

📁 linux-2.4.29操作系统的源码
💻 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 *    commuication. * * */#include <linux/config.h>#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 <asm/semaphore.h>#include <linux/blk.h>#include <asm/uaccess.h>#include "scsi.h"#include "hosts.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){	if((dev->hw_fib_va = pci_alloc_consistent(dev->pdev, sizeof(struct hw_fib) * AAC_NUM_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, sizeof(struct hw_fib) * AAC_NUM_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;		if(fib_map_alloc(dev)<0)		return -ENOMEM;			hw_fib_va = dev->hw_fib_va;	hw_fib_pa = dev->hw_fib_pa;	memset(hw_fib_va, 0, sizeof(struct hw_fib) * AAC_NUM_FIB);	/*	 *	Initialise the fibs	 */	for (i = 0, fibptr = &dev->fibs[i]; i < AAC_NUM_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(sizeof(struct hw_fib));		fibptr->hw_fib_pa = hw_fib_pa;		hw_fib_va = (struct hw_fib *)((unsigned char *)hw_fib_va + sizeof(struct hw_fib));		hw_fib_pa = hw_fib_pa + sizeof(struct hw_fib); 	}	/*	 *	Add the fib chain to the free list	 */	dev->fibs[AAC_NUM_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 *	wait for fibs to become free. */ 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)		BUG();	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 = cpu_to_le32(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, 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(sizeof(struct hw_fib));	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(sizeof(struct hw_fib));}/** *	fib_deallocate		-	deallocate a fib *	@fibptr: fib to deallocate * *	Will deallocate and return to the free pool the FIB pointed to by the *	caller. */ 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 = cpu_to_le32(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;	/*	 *	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];		*index = le32_to_cpu(*(q->headers.producer));	if ((*index - 2) == le32_to_cpu(*(q->headers.consumer)))			*nonotify = 1; 	if (qid == AdapHighCmdQueue) {	        if (*index >= ADAP_HIGH_CMD_ENTRIES)        		*index = 0;	} else if (qid == AdapNormCmdQueue) {	        if (*index >= ADAP_NORM_CMD_ENTRIES) 			*index = 0; /* Wrap to front of the Producer Queue. */	}	else if (qid == AdapHighRespQueue) 	{	        if (*index >= ADAP_HIGH_RESP_ENTRIES)			*index = 0;	}	else if (qid == AdapNormRespQueue) 	{		if (*index >= ADAP_NORM_RESP_ENTRIES) 			*index = 0; /* Wrap to front of the Producer Queue. */	}	else BUG();        if (*index + 1 == le32_to_cpu(*(q->headers.consumer))) { /* Queue is full */		printk(KERN_WARNING "Queue %d full, %ld 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;	struct aac_queue * q = &dev->queues->queue[qid];			spin_lock_irqsave(q->lock, q->SavedIrql);	    	if (qid == AdapHighCmdQueue || 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 if (qid == AdapHighRespQueue || qid == AdapNormRespQueue)	{	        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 = fibptr->hw_fib_pa;	return 0;}/** *	aac_insert_entry	-	insert a queue entry *	@dev: Adapter *	@index: Index of entry to insert *	@qid: Queue number *	@nonotify: Suppress adapter notification * *	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

⌨️ 快捷键说明

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