📄 cciss.c
字号:
/* * Disk Array driver for Compaq SMART2 Controllers * Copyright 2000 Compaq Computer Corporation * * 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 of the License, 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, GOOD TITLE or * NON INFRINGEMENT. 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; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Questions/Comments/Bugfixes to arrays@compaq.com * */#include <linux/config.h> /* CONFIG_PROC_FS */#include <linux/module.h>#include <linux/version.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/kernel.h>#include <linux/slab.h>#include <linux/delay.h>#include <linux/major.h>#include <linux/fs.h>#include <linux/blkpg.h>#include <linux/timer.h>#include <linux/proc_fs.h>#include <linux/init.h> #include <linux/hdreg.h>#include <linux/spinlock.h>#include <asm/uaccess.h>#include <asm/io.h>#include <linux/blk.h>#include <linux/blkdev.h>#include <linux/genhd.h>#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))#define DRIVER_NAME "Compaq CISS Driver (v 2.4.5)"#define DRIVER_VERSION CCISS_DRIVER_VERSION(2,4,5)/* Embedded module documentation macros - see modules.h */MODULE_AUTHOR("Charles M. White III - Compaq Computer Corporation");MODULE_DESCRIPTION("Driver for Compaq Smart Array Controller 5300");MODULE_LICENSE("GPL");#include "cciss_cmd.h"#include "cciss.h"#include <linux/cciss_ioctl.h>/* define the PCI info for the cards we can control */const struct pci_device_id cciss_pci_device_id[] = { { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISS, 0x0E11, 0x4070, 0, 0, 0}, { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4080, 0, 0, 0}, { PCI_VENDOR_ID_COMPAQ, PCI_DEVICE_ID_COMPAQ_CISSB, 0x0E11, 0x4082, 0, 0, 0}, {0,}};MODULE_DEVICE_TABLE(pci, cciss_pci_device_id);#define NR_PRODUCTS (sizeof(products)/sizeof(struct board_type))/* board_id = Subsystem Device ID & Vendor ID * product = Marketing Name for the board * access = Address of the struct of function pointers */static struct board_type products[] = { { 0x40700E11, "Smart Array 5300", &SA5_access }, { 0x40800E11, "Smart Array 5i", &SA5B_access}, { 0x40820E11, "Smart Array 532", &SA5B_access},};/* How long to wait (in millesconds) for board to go into simple mode */#define MAX_CONFIG_WAIT 1000 #define READ_AHEAD 128#define NR_CMDS 128 /* #commands that can be outstanding */#define MAX_CTLR 8#define CCISS_DMA_MASK 0xFFFFFFFF /* 32 bit DMA */static ctlr_info_t *hba[MAX_CTLR];static struct proc_dir_entry *proc_cciss;static void do_cciss_request(request_queue_t *q);static int cciss_open(struct inode *inode, struct file *filep);static int cciss_release(struct inode *inode, struct file *filep);static int cciss_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg);static int revalidate_allvol(kdev_t dev);static int revalidate_logvol(kdev_t dev, int maxusage);static int frevalidate_logvol(kdev_t dev);static void cciss_getgeometry(int cntl_num);static inline void addQ(CommandList_struct **Qptr, CommandList_struct *c);static void start_io( ctlr_info_t *h);#ifdef CONFIG_PROC_FSstatic int cciss_proc_get_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data);static void cciss_procinit(int i);#elsestatic int cciss_proc_get_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data) { return 0;}static void cciss_procinit(int i) {}#endif /* CONFIG_PROC_FS */static struct block_device_operations cciss_fops = { owner: THIS_MODULE, open: cciss_open, release: cciss_release, ioctl: cciss_ioctl, revalidate: frevalidate_logvol,};/* * Report information about this controller. */#ifdef CONFIG_PROC_FSstatic int cciss_proc_get_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data){ off_t pos = 0; off_t len = 0; int size, i, ctlr; ctlr_info_t *h = (ctlr_info_t*)data; drive_info_struct *drv; ctlr = h->ctlr; size = sprintf(buffer, "%s: Compaq %s Controller\n" " Board ID: 0x%08lx\n" " Firmware Version: %c%c%c%c\n" " Memory Address: 0x%08lx\n" " IRQ: %d\n" " Logical drives: %d\n" " Current Q depth: %d\n" " Current # commands on controller %d\n" " Max Q depth since init: %d\n" " Max # commands on controller since init: %d\n" " Max SG entries since init: %d\n\n", h->devname, h->product_name, (unsigned long)h->board_id, h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], h->firm_ver[3], (unsigned long)h->vaddr, (unsigned int)h->intr, h->num_luns, h->Qdepth, h->commands_outstanding, h->maxQsinceinit, h->max_outstanding, h->maxSG); pos += size; len += size; for(i=0; i<h->num_luns; i++) { drv = &h->drv[i]; size = sprintf(buffer+len, "cciss/c%dd%d: blksz=%d nr_blocks=%d\n", ctlr, i, drv->block_size, drv->nr_blocks); pos += size; len += size; } size = sprintf(buffer+len, "nr_allocs = %d\nnr_frees = %d\n", h->nr_allocs, h->nr_frees); pos += size; len += size; *eof = 1; *start = buffer+offset; len -= offset; if (len>length) len = length; return len;}/* * Get us a file in /proc/cciss that says something about each controller. * Create /proc/cciss if it doesn't exist yet. */static void __init cciss_procinit(int i){ if (proc_cciss == NULL) { proc_cciss = proc_mkdir("cciss", proc_root_driver); if (!proc_cciss) return; } create_proc_read_entry(hba[i]->devname, 0, proc_cciss, cciss_proc_get_info, hba[i]);}#endif /* CONFIG_PROC_FS *//* * For operations that cannot sleep, a command block is allocated at init, * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track * which ones are free or in use. For operations that can wait for kmalloc * to possible sleep, this routine can be called with get_from_pool set to 0. * cmd_free() MUST be called with a got_from_pool set to 0 if cmd_alloc was. */ static CommandList_struct * cmd_alloc(ctlr_info_t *h, int get_from_pool){ CommandList_struct *c; int i; u64bit temp64; dma_addr_t cmd_dma_handle, err_dma_handle; if (!get_from_pool) { c = (CommandList_struct *) pci_alloc_consistent( h->pdev, sizeof(CommandList_struct), &cmd_dma_handle); if(c==NULL) return NULL; memset(c, 0, sizeof(CommandList_struct)); c->err_info = (ErrorInfo_struct *)pci_alloc_consistent( h->pdev, sizeof(ErrorInfo_struct), &err_dma_handle); if (c->err_info == NULL) { pci_free_consistent(h->pdev, sizeof(CommandList_struct), c, cmd_dma_handle); return NULL; } memset(c->err_info, 0, sizeof(ErrorInfo_struct)); } else /* get it out of the controllers pool */ { do { i = find_first_zero_bit(h->cmd_pool_bits, NR_CMDS); if (i == NR_CMDS) return NULL; } while(test_and_set_bit(i%32, h->cmd_pool_bits+(i/32)) != 0);#ifdef CCISS_DEBUG printk(KERN_DEBUG "cciss: using command buffer %d\n", i);#endif c = h->cmd_pool + i; memset(c, 0, sizeof(CommandList_struct)); cmd_dma_handle = h->cmd_pool_dhandle + i*sizeof(CommandList_struct); c->err_info = h->errinfo_pool + i; memset(c->err_info, 0, sizeof(ErrorInfo_struct)); err_dma_handle = h->errinfo_pool_dhandle + i*sizeof(ErrorInfo_struct); h->nr_allocs++; } c->busaddr = (__u32) cmd_dma_handle; temp64.val = (__u64) err_dma_handle; c->ErrDesc.Addr.lower = temp64.val32.lower; c->ErrDesc.Addr.upper = temp64.val32.upper; c->ErrDesc.Len = sizeof(ErrorInfo_struct); c->ctlr = h->ctlr; return c;}/* * Frees a command block that was previously allocated with cmd_alloc(). */static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool){ int i; u64bit temp64; if( !got_from_pool) { temp64.val32.lower = c->ErrDesc.Addr.lower; temp64.val32.upper = c->ErrDesc.Addr.upper; pci_free_consistent(h->pdev, sizeof(ErrorInfo_struct), c->err_info, (dma_addr_t) temp64.val); pci_free_consistent(h->pdev, sizeof(CommandList_struct), c, (dma_addr_t) c->busaddr); } else { i = c - h->cmd_pool; clear_bit(i%32, h->cmd_pool_bits+(i/32)); h->nr_frees++; }}/* * fills in the disk information. */static void cciss_geninit( int ctlr){ drive_info_struct *drv; int i,j; /* Loop through each real device */ hba[ctlr]->gendisk.nr_real = 0; for(i=0; i< NWD; i++) { drv = &(hba[ctlr]->drv[i]); if( !(drv->nr_blocks)) continue; hba[ctlr]->hd[i << NWD_SHIFT].nr_sects = hba[ctlr]->sizes[i << NWD_SHIFT] = drv->nr_blocks; /* for each partition */ for(j=0; j<MAX_PART; j++) { hba[ctlr]->blocksizes[(i<<NWD_SHIFT) + j] = 1024; hba[ctlr]->hardsizes[ (i<<NWD_SHIFT) + j] = drv->block_size; } hba[ctlr]->gendisk.nr_real++; }}/* * Open. Make sure the device is really there. */static int cciss_open(struct inode *inode, struct file *filep){ int ctlr = MAJOR(inode->i_rdev) - MAJOR_NR; int dsk = MINOR(inode->i_rdev) >> NWD_SHIFT;#ifdef CCISS_DEBUG printk(KERN_DEBUG "cciss_open %x (%x:%x)\n", inode->i_rdev, ctlr, dsk);#endif /* CCISS_DEBUG */ if (ctlr > MAX_CTLR || hba[ctlr] == NULL) return -ENXIO; if (!suser() && hba[ctlr]->sizes[ MINOR(inode->i_rdev)] == 0) return -ENXIO; /* * Root is allowed to open raw volume zero even if its not configured * so array config can still work. I don't think I really like this, * but I'm already using way to many device nodes to claim another one * for "raw controller". */ if (suser() && (hba[ctlr]->sizes[MINOR(inode->i_rdev)] == 0) && (MINOR(inode->i_rdev)!= 0)) return -ENXIO; hba[ctlr]->drv[dsk].usage_count++; hba[ctlr]->usage_count++; return 0;}/* * Close. Sync first. */static int cciss_release(struct inode *inode, struct file *filep){ int ctlr = MAJOR(inode->i_rdev) - MAJOR_NR; int dsk = MINOR(inode->i_rdev) >> NWD_SHIFT;#ifdef CCISS_DEBUG printk(KERN_DEBUG "cciss_release %x (%x:%x)\n", inode->i_rdev, ctlr, dsk);#endif /* CCISS_DEBUG */ /* fsync_dev(inode->i_rdev); */ hba[ctlr]->drv[dsk].usage_count--; hba[ctlr]->usage_count--; return 0;}/* * ioctl */static int cciss_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg){ int ctlr = MAJOR(inode->i_rdev) - MAJOR_NR; int dsk = MINOR(inode->i_rdev) >> NWD_SHIFT; int diskinfo[4]; struct hd_geometry *geo = (struct hd_geometry *)arg;#ifdef CCISS_DEBUG printk(KERN_DEBUG "cciss_ioctl: Called with cmd=%x %lx\n", cmd, arg);#endif /* CCISS_DEBUG */ switch(cmd) { case HDIO_GETGEO: if (hba[ctlr]->drv[dsk].cylinders) { diskinfo[0] = hba[ctlr]->drv[dsk].heads; diskinfo[1] = hba[ctlr]->drv[dsk].sectors; diskinfo[2] = hba[ctlr]->drv[dsk].cylinders; } else { diskinfo[0] = 0xff; diskinfo[1] = 0x3f; diskinfo[2] = hba[ctlr]->drv[dsk].nr_blocks / (0xff*0x3f); } put_user(diskinfo[0], &geo->heads); put_user(diskinfo[1], &geo->sectors); put_user(diskinfo[2], &geo->cylinders); put_user(hba[ctlr]->hd[MINOR(inode->i_rdev)].start_sect, &geo->start); return 0; case BLKGETSIZE: put_user(hba[ctlr]->hd[MINOR(inode->i_rdev)].nr_sects, (unsigned long *)arg); return 0; case BLKGETSIZE64: put_user((u64)hba[ctlr]->hd[MINOR(inode->i_rdev)].nr_sects << 9, (u64*)arg); return 0; case BLKRRPART: return revalidate_logvol(inode->i_rdev, 1); case BLKFLSBUF: case BLKBSZSET: case BLKBSZGET: case BLKROSET: case BLKROGET:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -