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.5 (Jan 21 2005)
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);
61 EXPORT_SYMBOL(mraid_mm_adapter_app_handle);
64 static uint32_t drvr_ver = 0x02200201;
66 static int adapters_count_g;
67 static struct list_head adapters_list_g;
69 static wait_queue_head_t wait_q;
71 static struct file_operations lsi_fops = {
72 .open = mraid_mm_open,
73 .ioctl = mraid_mm_ioctl,
78 * mraid_mm_open - open routine for char node interface
82 * allow ioctl operations by apps only if they superuser privilege
85 mraid_mm_open(struct inode *inode, struct file *filep)
88 * Only allow superuser to access private ioctl interface
90 if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
96 * mraid_mm_ioctl - module entry-point for ioctls
97 * @inode : inode (ignored)
98 * @filep : file operations pointer (ignored)
99 * @cmd : ioctl command
100 * @arg : user ioctl packet
103 mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
107 char signature[EXT_IOCTL_SIGN_SZ] = {0};
112 void __user *argp = (void __user *)arg;
115 * Make sure only USCSICMD are issued through this interface.
116 * MIMD application would still fire different command.
119 if ((_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD)) {
124 * Look for signature to see if this is the new or old ioctl format.
126 if (copy_from_user(signature, argp, EXT_IOCTL_SIGN_SZ)) {
127 con_log(CL_ANN, (KERN_WARNING
128 "megaraid cmm: copy from usr addr failed\n"));
132 if (memcmp(signature, EXT_IOCTL_SIGN, EXT_IOCTL_SIGN_SZ) == 0)
138 * At present, we don't support the new ioctl packet
144 * If it is a driver ioctl (as opposed to fw ioctls), then we can
145 * handle the command locally. rval > 0 means it is not a drvr cmd
147 rval = handle_drvrcmd(argp, old_ioctl, &drvrcmd_rval);
155 if ((adp = mraid_mm_get_adapter(argp, &rval)) == NULL) {
160 * Check if adapter can accept ioctl. We may have marked it offline
161 * if any previous kioc had timedout on this controller.
163 if (!adp->quiescent) {
164 con_log(CL_ANN, (KERN_WARNING
165 "megaraid cmm: controller cannot accept cmds due to "
166 "earlier errors\n" ));
171 * The following call will block till a kioc is available
173 kioc = mraid_mm_alloc_kioc(adp);
176 * User sent the old mimd_t ioctl packet. Convert it to uioc_t.
178 if ((rval = mimd_to_kioc(argp, adp, kioc))) {
179 mraid_mm_dealloc_kioc(adp, kioc);
183 kioc->done = ioctl_done;
186 * Issue the IOCTL to the low level driver. After the IOCTL completes
187 * release the kioc if and only if it was _not_ timedout. If it was
188 * timedout, that means that resources are still with low level driver.
190 if ((rval = lld_ioctl(adp, kioc))) {
193 mraid_mm_dealloc_kioc(adp, kioc);
199 * Convert the kioc back to user space
201 rval = kioc_to_mimd(kioc, argp);
204 * Return the kioc to free pool
206 mraid_mm_dealloc_kioc(adp, kioc);
213 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
214 * @umimd : User space mimd_t ioctl packet
215 * @adapter : pointer to the adapter (OUT)
217 static mraid_mmadp_t *
218 mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
220 mraid_mmadp_t *adapter;
226 if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) {
231 adapno = GETADAP(mimd.ui.fcs.adapno);
233 if (adapno >= adapters_count_g) {
241 list_for_each_entry(adapter, &adapters_list_g, list) {
242 if (iterator++ == adapno) break;
254 * handle_drvrcmd - This routine checks if the opcode is a driver
255 * cmd and if it is, handles it.
256 * @arg : packet sent by the user app
257 * @old_ioctl : mimd if 1; uioc otherwise
260 handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval)
262 mimd_t __user *umimd;
279 if (copy_from_user(&kmimd, umimd, sizeof(mimd_t)))
282 opcode = kmimd.ui.fcs.opcode;
283 subopcode = kmimd.ui.fcs.subopcode;
286 * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
287 * GET_NUMADP, then we can handle. Otherwise we should return 1 to
288 * indicate that we cannot handle this.
295 case MEGAIOC_QDRVRVER:
297 if (copy_to_user(kmimd.data, &drvr_ver, sizeof(uint32_t)))
304 *rval = adapters_count_g;
306 if (copy_to_user(kmimd.data, &adapters_count_g,
322 * mimd_to_kioc - Converter from old to new ioctl format
324 * @umimd : user space old MIMD IOCTL
325 * @kioc : kernel space new format IOCTL
327 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
328 * new packet is in kernel space so that driver can perform operations on it
333 mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, uioc_t *kioc)
337 mraid_passthru_t *pthru32;
343 if (copy_from_user(&mimd, umimd, sizeof(mimd_t)))
347 * Applications are not allowed to send extd pthru
349 if ((mimd.mbox[0] == MBOXCMD_PASSTHRU64) ||
350 (mimd.mbox[0] == MBOXCMD_EXTPTHRU))
353 opcode = mimd.ui.fcs.opcode;
354 subopcode = mimd.ui.fcs.subopcode;
355 adapno = GETADAP(mimd.ui.fcs.adapno);
357 if (adapno >= adapters_count_g)
360 kioc->adapno = adapno;
361 kioc->mb_type = MBOX_LEGACY;
362 kioc->app_type = APPTYPE_MIMD;
368 if (subopcode == MEGAIOC_QADAPINFO) {
370 kioc->opcode = GET_ADAP_INFO;
371 kioc->data_dir = UIOC_RD;
372 kioc->xferlen = sizeof(mraid_hba_info_t);
374 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
378 con_log(CL_ANN, (KERN_WARNING
379 "megaraid cmm: Invalid subop\n"));
387 kioc->opcode = MBOX_CMD;
388 kioc->xferlen = mimd.ui.fcs.length;
389 kioc->user_data_len = kioc->xferlen;
390 kioc->user_data = mimd.ui.fcs.buffer;
392 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
395 if (mimd.outlen) kioc->data_dir = UIOC_RD;
396 if (mimd.inlen) kioc->data_dir |= UIOC_WR;
402 kioc->opcode = MBOX_CMD;
403 kioc->xferlen = (mimd.outlen > mimd.inlen) ?
404 mimd.outlen : mimd.inlen;
405 kioc->user_data_len = kioc->xferlen;
406 kioc->user_data = mimd.data;
408 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
411 if (mimd.outlen) kioc->data_dir = UIOC_RD;
412 if (mimd.inlen) kioc->data_dir |= UIOC_WR;
421 * If driver command, nothing else to do
427 * This is a mailbox cmd; copy the mailbox from mimd
429 mbox64 = (mbox64_t *)((unsigned long)kioc->cmdbuf);
430 mbox = &mbox64->mbox32;
431 memcpy(mbox, mimd.mbox, 14);
433 if (mbox->cmd != MBOXCMD_PASSTHRU) { // regular DCMD
435 mbox->xferaddr = (uint32_t)kioc->buf_paddr;
437 if (kioc->data_dir & UIOC_WR) {
438 if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
448 * This is a regular 32-bit pthru cmd; mbox points to pthru struct.
449 * Just like in above case, the beginning for memblk is treated as
450 * a mailbox. The passthru will begin at next 1K boundary. And the
451 * data will start 1K after that.
453 pthru32 = kioc->pthru32;
454 kioc->user_pthru = &umimd->pthru;
455 mbox->xferaddr = (uint32_t)kioc->pthru32_h;
457 if (copy_from_user(pthru32, kioc->user_pthru,
458 sizeof(mraid_passthru_t))) {
462 pthru32->dataxferaddr = kioc->buf_paddr;
463 if (kioc->data_dir & UIOC_WR) {
464 if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
465 pthru32->dataxferlen)) {
474 * mraid_mm_attch_buf - Attach a free dma buffer for required size
476 * @adp : Adapter softstate
477 * @kioc : kioc that the buffer needs to be attached to
478 * @xferlen : required length for buffer
480 * First we search for a pool with smallest buffer that is >= @xferlen. If
481 * that pool has no free buffer, we will try for the next bigger size. If none
482 * is available, we will try to allocate the smallest buffer that is >=
483 * @xferlen and attach it the pool.
486 mraid_mm_attach_buf(mraid_mmadp_t *adp, uioc_t *kioc, int xferlen)
493 kioc->pool_index = -1;
494 kioc->buf_vaddr = NULL;
499 * We need xferlen amount of memory. See if we can get it from our
500 * dma pools. If we don't get exact size, we will try bigger buffer
503 for (i = 0; i < MAX_DMA_POOLS; i++) {
505 pool = &adp->dma_pool_list[i];
507 if (xferlen > pool->buf_size)
510 if (right_pool == -1)
513 spin_lock_irqsave(&pool->lock, flags);
518 kioc->pool_index = i;
519 kioc->buf_vaddr = pool->vaddr;
520 kioc->buf_paddr = pool->paddr;
522 spin_unlock_irqrestore(&pool->lock, flags);
526 spin_unlock_irqrestore(&pool->lock, flags);
532 * If xferlen doesn't match any of our pools, return error
534 if (right_pool == -1)
538 * We did not get any buffer from the preallocated pool. Let us try
539 * to allocate one new buffer. NOTE: This is a blocking call.
541 pool = &adp->dma_pool_list[right_pool];
543 spin_lock_irqsave(&pool->lock, flags);
545 kioc->pool_index = right_pool;
547 kioc->buf_vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL,
549 spin_unlock_irqrestore(&pool->lock, flags);
551 if (!kioc->buf_vaddr)
558 * mraid_mm_alloc_kioc - Returns a uioc_t from free list
559 * @adp : Adapter softstate for this module
561 * The kioc_semaphore is initialized with number of kioc nodes in the
562 * free kioc pool. If the kioc pool is empty, this function blocks till
563 * a kioc becomes free.
566 mraid_mm_alloc_kioc(mraid_mmadp_t *adp)
569 struct list_head* head;
572 down(&adp->kioc_semaphore);
574 spin_lock_irqsave(&adp->kioc_pool_lock, flags);
576 head = &adp->kioc_pool;
578 if (list_empty(head)) {
579 up(&adp->kioc_semaphore);
580 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
582 con_log(CL_ANN, ("megaraid cmm: kioc list empty!\n"));
586 kioc = list_entry(head->next, uioc_t, list);
587 list_del_init(&kioc->list);
589 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
591 memset((caddr_t)(unsigned long)kioc->cmdbuf, 0, sizeof(mbox64_t));
592 memset((caddr_t) kioc->pthru32, 0, sizeof(mraid_passthru_t));
594 kioc->buf_vaddr = NULL;
596 kioc->pool_index =-1;
598 kioc->user_data = NULL;
599 kioc->user_data_len = 0;
600 kioc->user_pthru = NULL;
607 * mraid_mm_dealloc_kioc - Return kioc to free pool
609 * @adp : Adapter softstate
610 * @kioc : uioc_t node to be returned to free pool
613 mraid_mm_dealloc_kioc(mraid_mmadp_t *adp, uioc_t *kioc)
618 if (kioc->pool_index != -1) {
619 pool = &adp->dma_pool_list[kioc->pool_index];
621 /* This routine may be called in non-isr context also */
622 spin_lock_irqsave(&pool->lock, flags);
625 * While attaching the dma buffer, if we didn't get the
626 * required buffer from the pool, we would have allocated
627 * it at the run time and set the free_buf flag. We must
628 * free that buffer. Otherwise, just mark that the buffer is
631 if (kioc->free_buf == 1)
632 pci_pool_free(pool->handle, kioc->buf_vaddr,
637 spin_unlock_irqrestore(&pool->lock, flags);
640 /* Return the kioc to the free pool */
641 spin_lock_irqsave(&adp->kioc_pool_lock, flags);
642 list_add(&kioc->list, &adp->kioc_pool);
643 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
645 /* increment the free kioc count */
646 up(&adp->kioc_semaphore);
652 * lld_ioctl - Routine to issue ioctl to low level drvr
654 * @adp : The adapter handle
655 * @kioc : The ioctl packet with kernel addresses
658 lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
661 struct timer_list timer;
662 struct timer_list *tp = NULL;
664 kioc->status = -ENODATA;
665 rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE);
667 if (rval) return rval;
672 if (adp->timeout > 0) {
676 tp->function = lld_timedout;
677 tp->data = (unsigned long)kioc;
678 tp->expires = jiffies + adp->timeout * HZ;
684 * Wait till the low level driver completes the ioctl. After this
685 * call, the ioctl either completed successfully or timedout.
687 wait_event(wait_q, (kioc->status != -ENODATA));
693 * If the command had timedout, we mark the controller offline
696 if (kioc->timedout) {
705 * ioctl_done - callback from the low level driver
707 * @kioc : completed ioctl packet
710 ioctl_done(uioc_t *kioc)
714 mraid_mmadp_t* adapter;
717 * When the kioc returns from driver, make sure it still doesn't
718 * have ENODATA in status. Otherwise, driver will hang on wait_event
721 if (kioc->status == -ENODATA) {
722 con_log(CL_ANN, (KERN_WARNING
723 "megaraid cmm: lld didn't change status!\n"));
725 kioc->status = -EINVAL;
729 * Check if this kioc was timedout before. If so, nobody is waiting
730 * on this kioc. We don't have to wake up anybody. Instead, we just
731 * have to free the kioc
733 if (kioc->timedout) {
736 adapno = kioc->adapno;
738 con_log(CL_ANN, ( KERN_WARNING "megaraid cmm: completed "
739 "ioctl that was timedout before\n"));
741 list_for_each_entry(adapter, &adapters_list_g, list) {
742 if (iterator++ == adapno) break;
748 mraid_mm_dealloc_kioc( adapter, kioc );
758 * lld_timedout : callback from the expired timer
760 * @ptr : ioctl packet that timed out
763 lld_timedout(unsigned long ptr)
765 uioc_t *kioc = (uioc_t *)ptr;
767 kioc->status = -ETIME;
770 con_log(CL_ANN, (KERN_WARNING "megaraid cmm: ioctl timed out\n"));
777 * kioc_to_mimd : Converter from new back to old format
779 * @kioc : Kernel space IOCTL packet (successfully issued)
780 * @mimd : User space MIMD packet
783 kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd)
790 mraid_passthru_t __user *upthru32;
791 mraid_passthru_t *kpthru32;
793 mraid_hba_info_t *hinfo;
796 if (copy_from_user(&kmimd, mimd, sizeof(mimd_t)))
799 opcode = kmimd.ui.fcs.opcode;
800 subopcode = kmimd.ui.fcs.subopcode;
802 if (opcode == 0x82) {
805 case MEGAIOC_QADAPINFO:
807 hinfo = (mraid_hba_info_t *)(unsigned long)
810 hinfo_to_cinfo(hinfo, &cinfo);
812 if (copy_to_user(kmimd.data, &cinfo, sizeof(cinfo)))
824 mbox64 = (mbox64_t *)(unsigned long)kioc->cmdbuf;
826 if (kioc->user_pthru) {
828 upthru32 = kioc->user_pthru;
829 kpthru32 = kioc->pthru32;
831 if (copy_to_user(&upthru32->scsistatus,
832 &kpthru32->scsistatus,
838 if (kioc->user_data) {
839 if (copy_to_user(kioc->user_data, kioc->buf_vaddr,
840 kioc->user_data_len)) {
845 if (copy_to_user(&mimd->mbox[17],
846 &mbox64->mbox32.status, sizeof(uint8_t))) {
855 * hinfo_to_cinfo - Convert new format hba info into old format
857 * @hinfo : New format, more comprehensive adapter info
858 * @cinfo : Old format adapter info to support mimd_t apps
861 hinfo_to_cinfo(mraid_hba_info_t *hinfo, mcontroller_t *cinfo)
863 if (!hinfo || !cinfo)
866 cinfo->base = hinfo->baseport;
867 cinfo->irq = hinfo->irq;
868 cinfo->numldrv = hinfo->num_ldrv;
869 cinfo->pcibus = hinfo->pci_bus;
870 cinfo->pcidev = hinfo->pci_slot;
871 cinfo->pcifun = PCI_FUNC(hinfo->pci_dev_fn);
872 cinfo->pciid = hinfo->pci_device_id;
873 cinfo->pcivendor = hinfo->pci_vendor_id;
874 cinfo->pcislot = hinfo->pci_slot;
875 cinfo->uid = hinfo->unique_id;
880 * mraid_mm_register_adp - Registration routine for low level drvrs
882 * @adp : Adapter objejct
885 mraid_mm_register_adp(mraid_mmadp_t *lld_adp)
887 mraid_mmadp_t *adapter;
894 if (lld_adp->drvr_type != DRVRTYPE_MBOX)
897 adapter = kmalloc(sizeof(mraid_mmadp_t), GFP_KERNEL);
904 memset(adapter, 0, sizeof(mraid_mmadp_t));
906 adapter->unique_id = lld_adp->unique_id;
907 adapter->drvr_type = lld_adp->drvr_type;
908 adapter->drvr_data = lld_adp->drvr_data;
909 adapter->pdev = lld_adp->pdev;
910 adapter->issue_uioc = lld_adp->issue_uioc;
911 adapter->timeout = lld_adp->timeout;
912 adapter->max_kioc = lld_adp->max_kioc;
913 adapter->quiescent = 1;
916 * Allocate single blocks of memory for all required kiocs,
917 * mailboxes and passthru structures.
919 adapter->kioc_list = kmalloc(sizeof(uioc_t) * lld_adp->max_kioc,
921 adapter->mbox_list = kmalloc(sizeof(mbox64_t) * lld_adp->max_kioc,
923 adapter->pthru_dma_pool = pci_pool_create("megaraid mm pthru pool",
925 sizeof(mraid_passthru_t),
928 if (!adapter->kioc_list || !adapter->mbox_list ||
929 !adapter->pthru_dma_pool) {
931 con_log(CL_ANN, (KERN_WARNING
932 "megaraid cmm: out of memory, %s %d\n", __FUNCTION__,
941 * Slice kioc_list and make a kioc_pool with the individiual kiocs
943 INIT_LIST_HEAD(&adapter->kioc_pool);
944 spin_lock_init(&adapter->kioc_pool_lock);
945 sema_init(&adapter->kioc_semaphore, lld_adp->max_kioc);
947 mbox_list = (mbox64_t *)adapter->mbox_list;
949 for (i = 0; i < lld_adp->max_kioc; i++) {
951 kioc = adapter->kioc_list + i;
952 kioc->cmdbuf = (uint64_t)(unsigned long)(mbox_list + i);
953 kioc->pthru32 = pci_pool_alloc(adapter->pthru_dma_pool,
954 GFP_KERNEL, &kioc->pthru32_h);
956 if (!kioc->pthru32) {
958 con_log(CL_ANN, (KERN_WARNING
959 "megaraid cmm: out of memory, %s %d\n",
960 __FUNCTION__, __LINE__));
964 goto pthru_dma_pool_error;
967 list_add_tail(&kioc->list, &adapter->kioc_pool);
970 // Setup the dma pools for data buffers
971 if ((rval = mraid_mm_setup_dma_pools(adapter)) != 0) {
975 list_add_tail(&adapter->list, &adapters_list_g);
984 pthru_dma_pool_error:
986 for (i = 0; i < lld_adp->max_kioc; i++) {
987 kioc = adapter->kioc_list + i;
989 pci_pool_free(adapter->pthru_dma_pool, kioc->pthru32,
996 if (adapter->kioc_list)
997 kfree(adapter->kioc_list);
999 if (adapter->mbox_list)
1000 kfree(adapter->mbox_list);
1002 if (adapter->pthru_dma_pool)
1003 pci_pool_destroy(adapter->pthru_dma_pool);
1013 * mraid_mm_adapter_app_handle - return the application handle for this adapter
1015 * For the given driver data, locate the adadpter in our global list and
1016 * return the corresponding handle, which is also used by applications to
1017 * uniquely identify an adapter.
1019 * @param unique_id : adapter unique identifier
1021 * @return adapter handle if found in the list
1022 * @return 0 if adapter could not be located, should never happen though
1025 mraid_mm_adapter_app_handle(uint32_t unique_id)
1027 mraid_mmadp_t *adapter;
1031 list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
1033 if (adapter->unique_id == unique_id) {
1035 return MKADAP(index);
1046 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1048 * @adp : Adapter softstate
1050 * We maintain a pool of dma buffers per each adapter. Each pool has one
1051 * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
1052 * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
1053 * dont' want to waste too much memory by allocating more buffers per each
1057 mraid_mm_setup_dma_pools(mraid_mmadp_t *adp)
1064 * Create MAX_DMA_POOLS number of pools
1066 bufsize = MRAID_MM_INIT_BUFF_SIZE;
1068 for (i = 0; i < MAX_DMA_POOLS; i++){
1070 pool = &adp->dma_pool_list[i];
1072 pool->buf_size = bufsize;
1073 spin_lock_init(&pool->lock);
1075 pool->handle = pci_pool_create("megaraid mm data buffer",
1076 adp->pdev, bufsize, 16, 0);
1078 if (!pool->handle) {
1079 goto dma_pool_setup_error;
1082 pool->vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL,
1086 goto dma_pool_setup_error;
1088 bufsize = bufsize * 2;
1093 dma_pool_setup_error:
1095 mraid_mm_teardown_dma_pools(adp);
1101 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1102 * Assume no outstanding ioctls to llds.
1104 * @unique_id : UID of the adpater
1107 mraid_mm_unregister_adp(uint32_t unique_id)
1109 mraid_mmadp_t *adapter;
1112 list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
1115 if (adapter->unique_id == unique_id) {
1119 list_del_init(&adapter->list);
1121 mraid_mm_free_adp_resources(adapter);
1126 "megaraid cmm: Unregistered one adapter:%#x\n",
1137 * mraid_mm_free_adp_resources - Free adapter softstate
1139 * @adp : Adapter softstate
1142 mraid_mm_free_adp_resources(mraid_mmadp_t *adp)
1147 mraid_mm_teardown_dma_pools(adp);
1149 for (i = 0; i < adp->max_kioc; i++) {
1151 kioc = adp->kioc_list + i;
1153 pci_pool_free(adp->pthru_dma_pool, kioc->pthru32,
1157 kfree(adp->kioc_list);
1159 kfree(adp->mbox_list);
1161 pci_pool_destroy(adp->pthru_dma_pool);
1169 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1171 * @adp : Adapter softstate
1174 mraid_mm_teardown_dma_pools(mraid_mmadp_t *adp)
1179 for (i = 0; i < MAX_DMA_POOLS; i++) {
1181 pool = &adp->dma_pool_list[i];
1186 pci_pool_free(pool->handle, pool->vaddr,
1189 pci_pool_destroy(pool->handle);
1190 pool->handle = NULL;
1198 * mraid_mm_init : Module entry point
1203 // Announce the driver version
1204 con_log(CL_ANN, (KERN_INFO "megaraid cmm: %s %s\n",
1205 LSI_COMMON_MOD_VERSION, LSI_COMMON_MOD_EXT_VERSION));
1207 majorno = register_chrdev(0, "megadev", &lsi_fops);
1210 con_log(CL_ANN, ("megaraid cmm: cannot get major\n"));
1214 init_waitqueue_head(&wait_q);
1216 INIT_LIST_HEAD(&adapters_list_g);
1218 register_ioctl32_conversion(MEGAIOCCMD, mraid_mm_compat_ioctl);
1225 * mraid_mm_compat_ioctl : 32bit to 64bit ioctl conversion routine
1227 #ifdef CONFIG_COMPAT
1229 mraid_mm_compat_ioctl(unsigned int fd, unsigned int cmd,
1230 unsigned long arg, struct file *filep)
1232 struct inode *inode = filep->f_dentry->d_inode;
1234 return mraid_mm_ioctl(inode, filep, cmd, arg);
1239 * mraid_mm_exit : Module exit point
1244 con_log(CL_DLEVEL1 , ("exiting common mod\n"));
1246 unregister_chrdev(majorno, "megadev");
1247 unregister_ioctl32_conversion(MEGAIOCCMD);
1250 module_init(mraid_mm_init);
1251 module_exit(mraid_mm_exit);
1253 /* vi: set ts=8 sw=8 tw=78: */