3 * Linux MegaRAID device driver
5 * Copyright (c) 2003-2004 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * FILE : megaraid_mm.c
13 * Version : v2.20.2.3 (Dec 09 2004)
15 * Common management module
18 #include "megaraid_mm.h"
21 // Entry points for char node driver
22 static int mraid_mm_open(struct inode *, struct file *);
23 static int mraid_mm_ioctl(struct inode *, struct file *, uint, unsigned long);
26 // routines to convert to and from the old the format
27 static int mimd_to_kioc(mimd_t __user *, mraid_mmadp_t *, uioc_t *);
28 static int kioc_to_mimd(uioc_t *, mimd_t __user *);
32 static int handle_drvrcmd(void __user *, uint8_t, int *);
33 static int lld_ioctl(mraid_mmadp_t *, uioc_t *);
34 static void ioctl_done(uioc_t *);
35 static void lld_timedout(unsigned long);
36 static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *);
37 static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *);
38 static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *);
39 static void mraid_mm_dealloc_kioc(mraid_mmadp_t *, uioc_t *);
40 static int mraid_mm_attach_buf(mraid_mmadp_t *, uioc_t *, int);
41 static int mraid_mm_setup_dma_pools(mraid_mmadp_t *);
42 static void mraid_mm_free_adp_resources(mraid_mmadp_t *);
43 static void mraid_mm_teardown_dma_pools(mraid_mmadp_t *);
46 static int mraid_mm_compat_ioctl(unsigned int, unsigned int, unsigned long,
50 MODULE_AUTHOR("LSI Logic Corporation");
51 MODULE_DESCRIPTION("LSI Logic Management Module");
52 MODULE_LICENSE("GPL");
53 MODULE_VERSION(LSI_COMMON_MOD_VERSION);
55 static int dbglevel = CL_ANN;
56 module_param_named(dlevel, dbglevel, int, 0);
57 MODULE_PARM_DESC(dlevel, "Debug level (default=0)");
59 EXPORT_SYMBOL(mraid_mm_register_adp);
60 EXPORT_SYMBOL(mraid_mm_unregister_adp);
63 static uint32_t drvr_ver = 0x02200201;
65 static int adapters_count_g;
66 static struct list_head adapters_list_g;
68 wait_queue_head_t wait_q;
70 static struct file_operations lsi_fops = {
71 .open = mraid_mm_open,
72 .ioctl = mraid_mm_ioctl,
77 * mraid_mm_open - open routine for char node interface
81 * allow ioctl operations by apps only if they superuser privilege
84 mraid_mm_open(struct inode *inode, struct file *filep)
87 * Only allow superuser to access private ioctl interface
89 if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
95 * mraid_mm_ioctl - module entry-point for ioctls
96 * @inode : inode (ignored)
97 * @filep : file operations pointer (ignored)
98 * @cmd : ioctl command
99 * @arg : user ioctl packet
102 mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
106 char signature[EXT_IOCTL_SIGN_SZ] = {0};
111 void __user *argp = (void __user *)arg;
114 * Make sure only USCSICMD are issued through this interface.
115 * MIMD application would still fire different command.
118 if ((_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD)) {
123 * Look for signature to see if this is the new or old ioctl format.
125 if (copy_from_user(signature, argp, EXT_IOCTL_SIGN_SZ)) {
126 con_log(CL_ANN, (KERN_WARNING
127 "megaraid cmm: copy from usr addr failed\n"));
131 if (memcmp(signature, EXT_IOCTL_SIGN, EXT_IOCTL_SIGN_SZ) == 0)
137 * At present, we don't support the new ioctl packet
143 * If it is a driver ioctl (as opposed to fw ioctls), then we can
144 * handle the command locally. rval > 0 means it is not a drvr cmd
146 rval = handle_drvrcmd(argp, old_ioctl, &drvrcmd_rval);
154 if ((adp = mraid_mm_get_adapter(argp, &rval)) == NULL) {
159 * Check if adapter can accept ioctl. We may have marked it offline
160 * if any previous kioc had timedout on this controller.
162 if (!adp->quiescent) {
163 con_log(CL_ANN, (KERN_WARNING
164 "megaraid cmm: controller cannot accept cmds due to "
165 "earlier errors\n" ));
170 * The following call will block till a kioc is available
172 kioc = mraid_mm_alloc_kioc(adp);
175 * User sent the old mimd_t ioctl packet. Convert it to uioc_t.
177 if ((rval = mimd_to_kioc(argp, adp, kioc))) {
178 mraid_mm_dealloc_kioc(adp, kioc);
182 kioc->done = ioctl_done;
185 * Issue the IOCTL to the low level driver. After the IOCTL completes
186 * release the kioc if and only if it was _not_ timedout. If it was
187 * timedout, that means that resources are still with low level driver.
189 if ((rval = lld_ioctl(adp, kioc))) {
192 mraid_mm_dealloc_kioc(adp, kioc);
198 * Convert the kioc back to user space
200 rval = kioc_to_mimd(kioc, argp);
203 * Return the kioc to free pool
205 mraid_mm_dealloc_kioc(adp, kioc);
212 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
213 * @umimd : User space mimd_t ioctl packet
214 * @adapter : pointer to the adapter (OUT)
216 static mraid_mmadp_t *
217 mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
219 mraid_mmadp_t *adapter;
225 if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) {
230 adapno = GETADAP(mimd.ui.fcs.adapno);
232 if (adapno >= adapters_count_g) {
240 list_for_each_entry(adapter, &adapters_list_g, list) {
241 if (iterator++ == adapno) break;
253 * handle_drvrcmd - This routine checks if the opcode is a driver
254 * cmd and if it is, handles it.
255 * @arg : packet sent by the user app
256 * @old_ioctl : mimd if 1; uioc otherwise
259 handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval)
261 mimd_t __user *umimd;
278 if (copy_from_user(&kmimd, umimd, sizeof(mimd_t)))
281 opcode = kmimd.ui.fcs.opcode;
282 subopcode = kmimd.ui.fcs.subopcode;
285 * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
286 * GET_NUMADP, then we can handle. Otherwise we should return 1 to
287 * indicate that we cannot handle this.
294 case MEGAIOC_QDRVRVER:
296 if (copy_to_user(kmimd.data, &drvr_ver, sizeof(uint32_t)))
303 *rval = adapters_count_g;
305 if (copy_to_user(kmimd.data, &adapters_count_g,
321 * mimd_to_kioc - Converter from old to new ioctl format
323 * @umimd : user space old MIMD IOCTL
324 * @kioc : kernel space new format IOCTL
326 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
327 * new packet is in kernel space so that driver can perform operations on it
332 mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, uioc_t *kioc)
336 mraid_passthru_t *pthru32;
342 if (copy_from_user(&mimd, umimd, sizeof(mimd_t)))
346 * Applications are not allowed to send extd pthru
348 if ((mimd.mbox[0] == MBOXCMD_PASSTHRU64) ||
349 (mimd.mbox[0] == MBOXCMD_EXTPTHRU))
352 opcode = mimd.ui.fcs.opcode;
353 subopcode = mimd.ui.fcs.subopcode;
354 adapno = GETADAP(mimd.ui.fcs.adapno);
356 if (adapno >= adapters_count_g)
359 kioc->adapno = adapno;
360 kioc->mb_type = MBOX_LEGACY;
361 kioc->app_type = APPTYPE_MIMD;
367 if (subopcode == MEGAIOC_QADAPINFO) {
369 kioc->opcode = GET_ADAP_INFO;
370 kioc->data_dir = UIOC_RD;
371 kioc->xferlen = sizeof(mraid_hba_info_t);
373 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
377 con_log(CL_ANN, (KERN_WARNING
378 "megaraid cmm: Invalid subop\n"));
386 kioc->opcode = MBOX_CMD;
387 kioc->xferlen = mimd.ui.fcs.length;
388 kioc->user_data_len = kioc->xferlen;
389 kioc->user_data = mimd.ui.fcs.buffer;
391 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
394 if (mimd.outlen) kioc->data_dir = UIOC_RD;
395 if (mimd.inlen) kioc->data_dir |= UIOC_WR;
401 kioc->opcode = MBOX_CMD;
402 kioc->xferlen = (mimd.outlen > mimd.inlen) ?
403 mimd.outlen : mimd.inlen;
404 kioc->user_data_len = kioc->xferlen;
405 kioc->user_data = mimd.data;
407 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
410 if (mimd.outlen) kioc->data_dir = UIOC_RD;
411 if (mimd.inlen) kioc->data_dir |= UIOC_WR;
420 * If driver command, nothing else to do
426 * This is a mailbox cmd; copy the mailbox from mimd
428 mbox64 = (mbox64_t *)((unsigned long)kioc->cmdbuf);
429 mbox = &mbox64->mbox32;
430 memcpy(mbox, mimd.mbox, 14);
432 if (mbox->cmd != MBOXCMD_PASSTHRU) { // regular DCMD
434 mbox->xferaddr = (uint32_t)kioc->buf_paddr;
436 if (kioc->data_dir & UIOC_WR) {
437 if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
447 * This is a regular 32-bit pthru cmd; mbox points to pthru struct.
448 * Just like in above case, the beginning for memblk is treated as
449 * a mailbox. The passthru will begin at next 1K boundary. And the
450 * data will start 1K after that.
452 pthru32 = kioc->pthru32;
453 kioc->user_pthru = &umimd->pthru;
454 mbox->xferaddr = (uint32_t)kioc->pthru32_h;
456 if (copy_from_user(pthru32, kioc->user_pthru,
457 sizeof(mraid_passthru_t))) {
461 pthru32->dataxferaddr = kioc->buf_paddr;
462 if (kioc->data_dir & UIOC_WR) {
463 if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
464 pthru32->dataxferlen)) {
473 * mraid_mm_attch_buf - Attach a free dma buffer for required size
475 * @adp : Adapter softstate
476 * @kioc : kioc that the buffer needs to be attached to
477 * @xferlen : required length for buffer
479 * First we search for a pool with smallest buffer that is >= @xferlen. If
480 * that pool has no free buffer, we will try for the next bigger size. If none
481 * is available, we will try to allocate the smallest buffer that is >=
482 * @xferlen and attach it the pool.
485 mraid_mm_attach_buf(mraid_mmadp_t *adp, uioc_t *kioc, int xferlen)
492 kioc->pool_index = -1;
493 kioc->buf_vaddr = NULL;
498 * We need xferlen amount of memory. See if we can get it from our
499 * dma pools. If we don't get exact size, we will try bigger buffer
502 for (i = 0; i < MAX_DMA_POOLS; i++) {
504 pool = &adp->dma_pool_list[i];
506 if (xferlen > pool->buf_size)
509 if (right_pool == -1)
512 spin_lock_irqsave(&pool->lock, flags);
517 kioc->pool_index = i;
518 kioc->buf_vaddr = pool->vaddr;
519 kioc->buf_paddr = pool->paddr;
521 spin_unlock_irqrestore(&pool->lock, flags);
525 spin_unlock_irqrestore(&pool->lock, flags);
531 * If xferlen doesn't match any of our pools, return error
533 if (right_pool == -1)
537 * We did not get any buffer from the preallocated pool. Let us try
538 * to allocate one new buffer. NOTE: This is a blocking call.
540 pool = &adp->dma_pool_list[right_pool];
542 spin_lock_irqsave(&pool->lock, flags);
544 kioc->pool_index = right_pool;
546 kioc->buf_vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL,
548 spin_unlock_irqrestore(&pool->lock, flags);
550 if (!kioc->buf_vaddr)
557 * mraid_mm_alloc_kioc - Returns a uioc_t from free list
558 * @adp : Adapter softstate for this module
560 * The kioc_semaphore is initialized with number of kioc nodes in the
561 * free kioc pool. If the kioc pool is empty, this function blocks till
562 * a kioc becomes free.
565 mraid_mm_alloc_kioc(mraid_mmadp_t *adp)
568 struct list_head* head;
571 down(&adp->kioc_semaphore);
573 spin_lock_irqsave(&adp->kioc_pool_lock, flags);
575 head = &adp->kioc_pool;
577 if (list_empty(head)) {
578 up(&adp->kioc_semaphore);
579 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
581 con_log(CL_ANN, ("megaraid cmm: kioc list empty!\n"));
585 kioc = list_entry(head->next, uioc_t, list);
586 list_del_init(&kioc->list);
588 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
590 memset((caddr_t)(unsigned long)kioc->cmdbuf, 0, sizeof(mbox64_t));
591 memset((caddr_t) kioc->pthru32, 0, sizeof(mraid_passthru_t));
593 kioc->buf_vaddr = NULL;
595 kioc->pool_index =-1;
597 kioc->user_data = NULL;
598 kioc->user_data_len = 0;
599 kioc->user_pthru = NULL;
606 * mraid_mm_dealloc_kioc - Return kioc to free pool
608 * @adp : Adapter softstate
609 * @kioc : uioc_t node to be returned to free pool
612 mraid_mm_dealloc_kioc(mraid_mmadp_t *adp, uioc_t *kioc)
617 if (kioc->pool_index != -1) {
618 pool = &adp->dma_pool_list[kioc->pool_index];
620 /* This routine may be called in non-isr context also */
621 spin_lock_irqsave(&pool->lock, flags);
624 * While attaching the dma buffer, if we didn't get the
625 * required buffer from the pool, we would have allocated
626 * it at the run time and set the free_buf flag. We must
627 * free that buffer. Otherwise, just mark that the buffer is
630 if (kioc->free_buf == 1)
631 pci_pool_free(pool->handle, kioc->buf_vaddr,
636 spin_unlock_irqrestore(&pool->lock, flags);
639 /* Return the kioc to the free pool */
640 spin_lock_irqsave(&adp->kioc_pool_lock, flags);
641 list_add(&kioc->list, &adp->kioc_pool);
642 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
644 /* increment the free kioc count */
645 up(&adp->kioc_semaphore);
651 * lld_ioctl - Routine to issue ioctl to low level drvr
653 * @adp : The adapter handle
654 * @kioc : The ioctl packet with kernel addresses
657 lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
660 struct timer_list timer;
661 struct timer_list *tp = NULL;
663 kioc->status = -ENODATA;
664 rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE);
666 if (rval) return rval;
671 if (adp->timeout > 0) {
675 tp->function = lld_timedout;
676 tp->data = (unsigned long)kioc;
677 tp->expires = jiffies + adp->timeout * HZ;
683 * Wait till the low level driver completes the ioctl. After this
684 * call, the ioctl either completed successfully or timedout.
686 wait_event(wait_q, (kioc->status != -ENODATA));
692 * If the command had timedout, we mark the controller offline
695 if (kioc->timedout) {
704 * ioctl_done - callback from the low level driver
706 * @kioc : completed ioctl packet
709 ioctl_done(uioc_t *kioc)
713 mraid_mmadp_t* adapter;
716 * When the kioc returns from driver, make sure it still doesn't
717 * have ENODATA in status. Otherwise, driver will hang on wait_event
720 if (kioc->status == -ENODATA) {
721 con_log(CL_ANN, (KERN_WARNING
722 "megaraid cmm: lld didn't change status!\n"));
724 kioc->status = -EINVAL;
728 * Check if this kioc was timedout before. If so, nobody is waiting
729 * on this kioc. We don't have to wake up anybody. Instead, we just
730 * have to free the kioc
732 if (kioc->timedout) {
735 adapno = kioc->adapno;
737 con_log(CL_ANN, ( KERN_WARNING "megaraid cmm: completed "
738 "ioctl that was timedout before\n"));
740 list_for_each_entry(adapter, &adapters_list_g, list) {
741 if (iterator++ == adapno) break;
747 mraid_mm_dealloc_kioc( adapter, kioc );
757 * lld_timedout : callback from the expired timer
759 * @ptr : ioctl packet that timed out
762 lld_timedout(unsigned long ptr)
764 uioc_t *kioc = (uioc_t *)ptr;
766 kioc->status = -ETIME;
769 con_log(CL_ANN, (KERN_WARNING "megaraid cmm: ioctl timed out\n"));
776 * kioc_to_mimd : Converter from new back to old format
778 * @kioc : Kernel space IOCTL packet (successfully issued)
779 * @mimd : User space MIMD packet
782 kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd)
789 mraid_passthru_t __user *upthru32;
790 mraid_passthru_t *kpthru32;
792 mraid_hba_info_t *hinfo;
795 if (copy_from_user(&kmimd, mimd, sizeof(mimd_t)))
798 opcode = kmimd.ui.fcs.opcode;
799 subopcode = kmimd.ui.fcs.subopcode;
801 if (opcode == 0x82) {
804 case MEGAIOC_QADAPINFO:
806 hinfo = (mraid_hba_info_t *)(unsigned long)
809 hinfo_to_cinfo(hinfo, &cinfo);
811 if (copy_to_user(kmimd.data, &cinfo, sizeof(cinfo)))
823 mbox64 = (mbox64_t *)(unsigned long)kioc->cmdbuf;
825 if (kioc->user_pthru) {
827 upthru32 = kioc->user_pthru;
828 kpthru32 = kioc->pthru32;
830 if (copy_to_user(&upthru32->scsistatus,
831 &kpthru32->scsistatus,
837 if (kioc->user_data) {
838 if (copy_to_user(kioc->user_data, kioc->buf_vaddr,
839 kioc->user_data_len)) {
844 if (copy_to_user(&mimd->mbox[17],
845 &mbox64->mbox32.status, sizeof(uint8_t))) {
854 * hinfo_to_cinfo - Convert new format hba info into old format
856 * @hinfo : New format, more comprehensive adapter info
857 * @cinfo : Old format adapter info to support mimd_t apps
860 hinfo_to_cinfo(mraid_hba_info_t *hinfo, mcontroller_t *cinfo)
862 if (!hinfo || !cinfo)
865 cinfo->base = hinfo->baseport;
866 cinfo->irq = hinfo->irq;
867 cinfo->numldrv = hinfo->num_ldrv;
868 cinfo->pcibus = hinfo->pci_bus;
869 cinfo->pcidev = hinfo->pci_slot;
870 cinfo->pcifun = PCI_FUNC(hinfo->pci_dev_fn);
871 cinfo->pciid = hinfo->pci_device_id;
872 cinfo->pcivendor = hinfo->pci_vendor_id;
873 cinfo->pcislot = hinfo->pci_slot;
874 cinfo->uid = hinfo->unique_id;
879 * mraid_mm_register_adp - Registration routine for low level drvrs
881 * @adp : Adapter objejct
884 mraid_mm_register_adp(mraid_mmadp_t *lld_adp)
886 mraid_mmadp_t *adapter;
893 if (lld_adp->drvr_type != DRVRTYPE_MBOX)
896 adapter = kmalloc(sizeof(mraid_mmadp_t), GFP_KERNEL);
903 memset(adapter, 0, sizeof(mraid_mmadp_t));
905 adapter->unique_id = lld_adp->unique_id;
906 adapter->drvr_type = lld_adp->drvr_type;
907 adapter->drvr_data = lld_adp->drvr_data;
908 adapter->pdev = lld_adp->pdev;
909 adapter->issue_uioc = lld_adp->issue_uioc;
910 adapter->timeout = lld_adp->timeout;
911 adapter->max_kioc = lld_adp->max_kioc;
912 adapter->quiescent = 1;
915 * Allocate single blocks of memory for all required kiocs,
916 * mailboxes and passthru structures.
918 adapter->kioc_list = kmalloc(sizeof(uioc_t) * lld_adp->max_kioc,
920 adapter->mbox_list = kmalloc(sizeof(mbox64_t) * lld_adp->max_kioc,
922 adapter->pthru_dma_pool = pci_pool_create("megaraid mm pthru pool",
924 sizeof(mraid_passthru_t),
927 if (!adapter->kioc_list || !adapter->mbox_list ||
928 !adapter->pthru_dma_pool) {
930 con_log(CL_ANN, (KERN_WARNING
931 "megaraid cmm: out of memory, %s %d\n", __FUNCTION__,
940 * Slice kioc_list and make a kioc_pool with the individiual kiocs
942 INIT_LIST_HEAD(&adapter->kioc_pool);
943 spin_lock_init(&adapter->kioc_pool_lock);
944 sema_init(&adapter->kioc_semaphore, lld_adp->max_kioc);
946 mbox_list = (mbox64_t *)adapter->mbox_list;
948 for (i = 0; i < lld_adp->max_kioc; i++) {
950 kioc = adapter->kioc_list + i;
951 kioc->cmdbuf = (uint64_t)(unsigned long)(mbox_list + i);
952 kioc->pthru32 = pci_pool_alloc(adapter->pthru_dma_pool,
953 GFP_KERNEL, &kioc->pthru32_h);
955 if (!kioc->pthru32) {
957 con_log(CL_ANN, (KERN_WARNING
958 "megaraid cmm: out of memory, %s %d\n",
959 __FUNCTION__, __LINE__));
963 goto pthru_dma_pool_error;
966 list_add_tail(&kioc->list, &adapter->kioc_pool);
969 // Setup the dma pools for data buffers
970 if ((rval = mraid_mm_setup_dma_pools(adapter)) != 0) {
974 list_add_tail(&adapter->list, &adapters_list_g);
983 pthru_dma_pool_error:
985 for (i = 0; i < lld_adp->max_kioc; i++) {
986 kioc = adapter->kioc_list + i;
988 pci_pool_free(adapter->pthru_dma_pool, kioc->pthru32,
995 if (adapter->kioc_list)
996 kfree(adapter->kioc_list);
998 if (adapter->mbox_list)
999 kfree(adapter->mbox_list);
1001 if (adapter->pthru_dma_pool)
1002 pci_pool_destroy(adapter->pthru_dma_pool);
1011 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1013 * @adp : Adapter softstate
1015 * We maintain a pool of dma buffers per each adapter. Each pool has one
1016 * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
1017 * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
1018 * dont' want to waste too much memory by allocating more buffers per each
1022 mraid_mm_setup_dma_pools(mraid_mmadp_t *adp)
1029 * Create MAX_DMA_POOLS number of pools
1031 bufsize = MRAID_MM_INIT_BUFF_SIZE;
1033 for (i = 0; i < MAX_DMA_POOLS; i++){
1035 pool = &adp->dma_pool_list[i];
1037 pool->buf_size = bufsize;
1038 spin_lock_init(&pool->lock);
1040 pool->handle = pci_pool_create("megaraid mm data buffer",
1041 adp->pdev, bufsize, 16, 0);
1043 if (!pool->handle) {
1044 goto dma_pool_setup_error;
1047 pool->vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL,
1051 goto dma_pool_setup_error;
1053 bufsize = bufsize * 2;
1058 dma_pool_setup_error:
1060 mraid_mm_teardown_dma_pools(adp);
1066 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1067 * Assume no outstanding ioctls to llds.
1069 * @unique_id : UID of the adpater
1072 mraid_mm_unregister_adp(uint32_t unique_id)
1074 mraid_mmadp_t *adapter;
1077 list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
1080 if (adapter->unique_id == unique_id) {
1084 list_del_init(&adapter->list);
1086 mraid_mm_free_adp_resources(adapter);
1091 "megaraid cmm: Unregistered one adapter:%#x\n",
1102 * mraid_mm_free_adp_resources - Free adapter softstate
1104 * @adp : Adapter softstate
1107 mraid_mm_free_adp_resources(mraid_mmadp_t *adp)
1112 mraid_mm_teardown_dma_pools(adp);
1114 for (i = 0; i < adp->max_kioc; i++) {
1116 kioc = adp->kioc_list + i;
1118 pci_pool_free(adp->pthru_dma_pool, kioc->pthru32,
1122 kfree(adp->kioc_list);
1124 kfree(adp->mbox_list);
1126 pci_pool_destroy(adp->pthru_dma_pool);
1134 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1136 * @adp : Adapter softstate
1139 mraid_mm_teardown_dma_pools(mraid_mmadp_t *adp)
1144 for (i = 0; i < MAX_DMA_POOLS; i++) {
1146 pool = &adp->dma_pool_list[i];
1151 pci_pool_free(pool->handle, pool->vaddr,
1154 pci_pool_destroy(pool->handle);
1155 pool->handle = NULL;
1163 * mraid_mm_init : Module entry point
1168 // Announce the driver version
1169 con_log(CL_ANN, (KERN_INFO "megaraid cmm: %s %s\n",
1170 LSI_COMMON_MOD_VERSION, LSI_COMMON_MOD_EXT_VERSION));
1172 majorno = register_chrdev(0, "megadev", &lsi_fops);
1175 con_log(CL_ANN, ("megaraid cmm: cannot get major\n"));
1179 init_waitqueue_head(&wait_q);
1181 INIT_LIST_HEAD(&adapters_list_g);
1183 register_ioctl32_conversion(MEGAIOCCMD, mraid_mm_compat_ioctl);
1190 * mraid_mm_compat_ioctl : 32bit to 64bit ioctl conversion routine
1192 #ifdef CONFIG_COMPAT
1194 mraid_mm_compat_ioctl(unsigned int fd, unsigned int cmd,
1195 unsigned long arg, struct file *filep)
1197 struct inode *inode = filep->f_dentry->d_inode;
1199 return mraid_mm_ioctl(inode, filep, cmd, arg);
1204 * mraid_mm_exit : Module exit point
1209 con_log(CL_DLEVEL1 , ("exiting common mod\n"));
1211 unregister_chrdev(majorno, "megadev");
1212 unregister_ioctl32_conversion(MEGAIOCCMD);
1215 module_init(mraid_mm_init);
1216 module_exit(mraid_mm_exit);
1218 /* vi: set ts=8 sw=8 tw=78: */