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.6 (Mar 7 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 long mraid_mm_compat_ioctl(struct file *, unsigned int, unsigned long);
49 MODULE_AUTHOR("LSI Logic Corporation");
50 MODULE_DESCRIPTION("LSI Logic Management Module");
51 MODULE_LICENSE("GPL");
52 MODULE_VERSION(LSI_COMMON_MOD_VERSION);
54 static int dbglevel = CL_ANN;
55 module_param_named(dlevel, dbglevel, int, 0);
56 MODULE_PARM_DESC(dlevel, "Debug level (default=0)");
58 EXPORT_SYMBOL(mraid_mm_register_adp);
59 EXPORT_SYMBOL(mraid_mm_unregister_adp);
60 EXPORT_SYMBOL(mraid_mm_adapter_app_handle);
63 static uint32_t drvr_ver = 0x02200206;
65 static int adapters_count_g;
66 static struct list_head adapters_list_g;
68 static wait_queue_head_t wait_q;
70 static struct file_operations lsi_fops = {
71 .open = mraid_mm_open,
72 .ioctl = mraid_mm_ioctl,
74 .compat_ioctl = mraid_mm_compat_ioctl,
80 * mraid_mm_open - open routine for char node interface
84 * allow ioctl operations by apps only if they superuser privilege
87 mraid_mm_open(struct inode *inode, struct file *filep)
90 * Only allow superuser to access private ioctl interface
92 if (!capable(CAP_SYS_ADMIN)) return (-EACCES);
98 * mraid_mm_ioctl - module entry-point for ioctls
99 * @inode : inode (ignored)
100 * @filep : file operations pointer (ignored)
101 * @cmd : ioctl command
102 * @arg : user ioctl packet
105 mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
109 char signature[EXT_IOCTL_SIGN_SZ] = {0};
114 void __user *argp = (void __user *)arg;
117 * Make sure only USCSICMD are issued through this interface.
118 * MIMD application would still fire different command.
121 if ((_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD)) {
126 * Look for signature to see if this is the new or old ioctl format.
128 if (copy_from_user(signature, argp, EXT_IOCTL_SIGN_SZ)) {
129 con_log(CL_ANN, (KERN_WARNING
130 "megaraid cmm: copy from usr addr failed\n"));
134 if (memcmp(signature, EXT_IOCTL_SIGN, EXT_IOCTL_SIGN_SZ) == 0)
140 * At present, we don't support the new ioctl packet
146 * If it is a driver ioctl (as opposed to fw ioctls), then we can
147 * handle the command locally. rval > 0 means it is not a drvr cmd
149 rval = handle_drvrcmd(argp, old_ioctl, &drvrcmd_rval);
157 if ((adp = mraid_mm_get_adapter(argp, &rval)) == NULL) {
162 * Check if adapter can accept ioctl. We may have marked it offline
163 * if any previous kioc had timedout on this controller.
165 if (!adp->quiescent) {
166 con_log(CL_ANN, (KERN_WARNING
167 "megaraid cmm: controller cannot accept cmds due to "
168 "earlier errors\n" ));
173 * The following call will block till a kioc is available
175 kioc = mraid_mm_alloc_kioc(adp);
178 * User sent the old mimd_t ioctl packet. Convert it to uioc_t.
180 if ((rval = mimd_to_kioc(argp, adp, kioc))) {
181 mraid_mm_dealloc_kioc(adp, kioc);
185 kioc->done = ioctl_done;
188 * Issue the IOCTL to the low level driver. After the IOCTL completes
189 * release the kioc if and only if it was _not_ timedout. If it was
190 * timedout, that means that resources are still with low level driver.
192 if ((rval = lld_ioctl(adp, kioc))) {
195 mraid_mm_dealloc_kioc(adp, kioc);
201 * Convert the kioc back to user space
203 rval = kioc_to_mimd(kioc, argp);
206 * Return the kioc to free pool
208 mraid_mm_dealloc_kioc(adp, kioc);
215 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
216 * @umimd : User space mimd_t ioctl packet
217 * @adapter : pointer to the adapter (OUT)
219 static mraid_mmadp_t *
220 mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
222 mraid_mmadp_t *adapter;
228 if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) {
233 adapno = GETADAP(mimd.ui.fcs.adapno);
235 if (adapno >= adapters_count_g) {
243 list_for_each_entry(adapter, &adapters_list_g, list) {
244 if (iterator++ == adapno) break;
256 * handle_drvrcmd - This routine checks if the opcode is a driver
257 * cmd and if it is, handles it.
258 * @arg : packet sent by the user app
259 * @old_ioctl : mimd if 1; uioc otherwise
262 handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval)
264 mimd_t __user *umimd;
281 if (copy_from_user(&kmimd, umimd, sizeof(mimd_t)))
284 opcode = kmimd.ui.fcs.opcode;
285 subopcode = kmimd.ui.fcs.subopcode;
288 * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
289 * GET_NUMADP, then we can handle. Otherwise we should return 1 to
290 * indicate that we cannot handle this.
297 case MEGAIOC_QDRVRVER:
299 if (copy_to_user(kmimd.data, &drvr_ver, sizeof(uint32_t)))
306 *rval = adapters_count_g;
308 if (copy_to_user(kmimd.data, &adapters_count_g,
324 * mimd_to_kioc - Converter from old to new ioctl format
326 * @umimd : user space old MIMD IOCTL
327 * @kioc : kernel space new format IOCTL
329 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
330 * new packet is in kernel space so that driver can perform operations on it
335 mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, uioc_t *kioc)
339 mraid_passthru_t *pthru32;
345 if (copy_from_user(&mimd, umimd, sizeof(mimd_t)))
349 * Applications are not allowed to send extd pthru
351 if ((mimd.mbox[0] == MBOXCMD_PASSTHRU64) ||
352 (mimd.mbox[0] == MBOXCMD_EXTPTHRU))
355 opcode = mimd.ui.fcs.opcode;
356 subopcode = mimd.ui.fcs.subopcode;
357 adapno = GETADAP(mimd.ui.fcs.adapno);
359 if (adapno >= adapters_count_g)
362 kioc->adapno = adapno;
363 kioc->mb_type = MBOX_LEGACY;
364 kioc->app_type = APPTYPE_MIMD;
370 if (subopcode == MEGAIOC_QADAPINFO) {
372 kioc->opcode = GET_ADAP_INFO;
373 kioc->data_dir = UIOC_RD;
374 kioc->xferlen = sizeof(mraid_hba_info_t);
376 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
380 con_log(CL_ANN, (KERN_WARNING
381 "megaraid cmm: Invalid subop\n"));
389 kioc->opcode = MBOX_CMD;
390 kioc->xferlen = mimd.ui.fcs.length;
391 kioc->user_data_len = kioc->xferlen;
392 kioc->user_data = mimd.ui.fcs.buffer;
394 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
397 if (mimd.outlen) kioc->data_dir = UIOC_RD;
398 if (mimd.inlen) kioc->data_dir |= UIOC_WR;
404 kioc->opcode = MBOX_CMD;
405 kioc->xferlen = (mimd.outlen > mimd.inlen) ?
406 mimd.outlen : mimd.inlen;
407 kioc->user_data_len = kioc->xferlen;
408 kioc->user_data = mimd.data;
410 if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
413 if (mimd.outlen) kioc->data_dir = UIOC_RD;
414 if (mimd.inlen) kioc->data_dir |= UIOC_WR;
423 * If driver command, nothing else to do
429 * This is a mailbox cmd; copy the mailbox from mimd
431 mbox64 = (mbox64_t *)((unsigned long)kioc->cmdbuf);
432 mbox = &mbox64->mbox32;
433 memcpy(mbox, mimd.mbox, 14);
435 if (mbox->cmd != MBOXCMD_PASSTHRU) { // regular DCMD
437 mbox->xferaddr = (uint32_t)kioc->buf_paddr;
439 if (kioc->data_dir & UIOC_WR) {
440 if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
450 * This is a regular 32-bit pthru cmd; mbox points to pthru struct.
451 * Just like in above case, the beginning for memblk is treated as
452 * a mailbox. The passthru will begin at next 1K boundary. And the
453 * data will start 1K after that.
455 pthru32 = kioc->pthru32;
456 kioc->user_pthru = &umimd->pthru;
457 mbox->xferaddr = (uint32_t)kioc->pthru32_h;
459 if (copy_from_user(pthru32, kioc->user_pthru,
460 sizeof(mraid_passthru_t))) {
464 pthru32->dataxferaddr = kioc->buf_paddr;
465 if (kioc->data_dir & UIOC_WR) {
466 if (copy_from_user(kioc->buf_vaddr, kioc->user_data,
467 pthru32->dataxferlen)) {
476 * mraid_mm_attch_buf - Attach a free dma buffer for required size
478 * @adp : Adapter softstate
479 * @kioc : kioc that the buffer needs to be attached to
480 * @xferlen : required length for buffer
482 * First we search for a pool with smallest buffer that is >= @xferlen. If
483 * that pool has no free buffer, we will try for the next bigger size. If none
484 * is available, we will try to allocate the smallest buffer that is >=
485 * @xferlen and attach it the pool.
488 mraid_mm_attach_buf(mraid_mmadp_t *adp, uioc_t *kioc, int xferlen)
495 kioc->pool_index = -1;
496 kioc->buf_vaddr = NULL;
501 * We need xferlen amount of memory. See if we can get it from our
502 * dma pools. If we don't get exact size, we will try bigger buffer
505 for (i = 0; i < MAX_DMA_POOLS; i++) {
507 pool = &adp->dma_pool_list[i];
509 if (xferlen > pool->buf_size)
512 if (right_pool == -1)
515 spin_lock_irqsave(&pool->lock, flags);
520 kioc->pool_index = i;
521 kioc->buf_vaddr = pool->vaddr;
522 kioc->buf_paddr = pool->paddr;
524 spin_unlock_irqrestore(&pool->lock, flags);
528 spin_unlock_irqrestore(&pool->lock, flags);
534 * If xferlen doesn't match any of our pools, return error
536 if (right_pool == -1)
540 * We did not get any buffer from the preallocated pool. Let us try
541 * to allocate one new buffer. NOTE: This is a blocking call.
543 pool = &adp->dma_pool_list[right_pool];
545 spin_lock_irqsave(&pool->lock, flags);
547 kioc->pool_index = right_pool;
549 kioc->buf_vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL,
551 spin_unlock_irqrestore(&pool->lock, flags);
553 if (!kioc->buf_vaddr)
560 * mraid_mm_alloc_kioc - Returns a uioc_t from free list
561 * @adp : Adapter softstate for this module
563 * The kioc_semaphore is initialized with number of kioc nodes in the
564 * free kioc pool. If the kioc pool is empty, this function blocks till
565 * a kioc becomes free.
568 mraid_mm_alloc_kioc(mraid_mmadp_t *adp)
571 struct list_head* head;
574 down(&adp->kioc_semaphore);
576 spin_lock_irqsave(&adp->kioc_pool_lock, flags);
578 head = &adp->kioc_pool;
580 if (list_empty(head)) {
581 up(&adp->kioc_semaphore);
582 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
584 con_log(CL_ANN, ("megaraid cmm: kioc list empty!\n"));
588 kioc = list_entry(head->next, uioc_t, list);
589 list_del_init(&kioc->list);
591 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
593 memset((caddr_t)(unsigned long)kioc->cmdbuf, 0, sizeof(mbox64_t));
594 memset((caddr_t) kioc->pthru32, 0, sizeof(mraid_passthru_t));
596 kioc->buf_vaddr = NULL;
598 kioc->pool_index =-1;
600 kioc->user_data = NULL;
601 kioc->user_data_len = 0;
602 kioc->user_pthru = NULL;
609 * mraid_mm_dealloc_kioc - Return kioc to free pool
611 * @adp : Adapter softstate
612 * @kioc : uioc_t node to be returned to free pool
615 mraid_mm_dealloc_kioc(mraid_mmadp_t *adp, uioc_t *kioc)
620 if (kioc->pool_index != -1) {
621 pool = &adp->dma_pool_list[kioc->pool_index];
623 /* This routine may be called in non-isr context also */
624 spin_lock_irqsave(&pool->lock, flags);
627 * While attaching the dma buffer, if we didn't get the
628 * required buffer from the pool, we would have allocated
629 * it at the run time and set the free_buf flag. We must
630 * free that buffer. Otherwise, just mark that the buffer is
633 if (kioc->free_buf == 1)
634 pci_pool_free(pool->handle, kioc->buf_vaddr,
639 spin_unlock_irqrestore(&pool->lock, flags);
642 /* Return the kioc to the free pool */
643 spin_lock_irqsave(&adp->kioc_pool_lock, flags);
644 list_add(&kioc->list, &adp->kioc_pool);
645 spin_unlock_irqrestore(&adp->kioc_pool_lock, flags);
647 /* increment the free kioc count */
648 up(&adp->kioc_semaphore);
654 * lld_ioctl - Routine to issue ioctl to low level drvr
656 * @adp : The adapter handle
657 * @kioc : The ioctl packet with kernel addresses
660 lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
663 struct timer_list timer;
664 struct timer_list *tp = NULL;
666 kioc->status = -ENODATA;
667 rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE);
669 if (rval) return rval;
674 if (adp->timeout > 0) {
678 tp->function = lld_timedout;
679 tp->data = (unsigned long)kioc;
680 tp->expires = jiffies + adp->timeout * HZ;
686 * Wait till the low level driver completes the ioctl. After this
687 * call, the ioctl either completed successfully or timedout.
689 wait_event(wait_q, (kioc->status != -ENODATA));
695 * If the command had timedout, we mark the controller offline
698 if (kioc->timedout) {
707 * ioctl_done - callback from the low level driver
709 * @kioc : completed ioctl packet
712 ioctl_done(uioc_t *kioc)
716 mraid_mmadp_t* adapter;
719 * When the kioc returns from driver, make sure it still doesn't
720 * have ENODATA in status. Otherwise, driver will hang on wait_event
723 if (kioc->status == -ENODATA) {
724 con_log(CL_ANN, (KERN_WARNING
725 "megaraid cmm: lld didn't change status!\n"));
727 kioc->status = -EINVAL;
731 * Check if this kioc was timedout before. If so, nobody is waiting
732 * on this kioc. We don't have to wake up anybody. Instead, we just
733 * have to free the kioc
735 if (kioc->timedout) {
738 adapno = kioc->adapno;
740 con_log(CL_ANN, ( KERN_WARNING "megaraid cmm: completed "
741 "ioctl that was timedout before\n"));
743 list_for_each_entry(adapter, &adapters_list_g, list) {
744 if (iterator++ == adapno) break;
750 mraid_mm_dealloc_kioc( adapter, kioc );
760 * lld_timedout : callback from the expired timer
762 * @ptr : ioctl packet that timed out
765 lld_timedout(unsigned long ptr)
767 uioc_t *kioc = (uioc_t *)ptr;
769 kioc->status = -ETIME;
772 con_log(CL_ANN, (KERN_WARNING "megaraid cmm: ioctl timed out\n"));
779 * kioc_to_mimd : Converter from new back to old format
781 * @kioc : Kernel space IOCTL packet (successfully issued)
782 * @mimd : User space MIMD packet
785 kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd)
792 mraid_passthru_t __user *upthru32;
793 mraid_passthru_t *kpthru32;
795 mraid_hba_info_t *hinfo;
798 if (copy_from_user(&kmimd, mimd, sizeof(mimd_t)))
801 opcode = kmimd.ui.fcs.opcode;
802 subopcode = kmimd.ui.fcs.subopcode;
804 if (opcode == 0x82) {
807 case MEGAIOC_QADAPINFO:
809 hinfo = (mraid_hba_info_t *)(unsigned long)
812 hinfo_to_cinfo(hinfo, &cinfo);
814 if (copy_to_user(kmimd.data, &cinfo, sizeof(cinfo)))
826 mbox64 = (mbox64_t *)(unsigned long)kioc->cmdbuf;
828 if (kioc->user_pthru) {
830 upthru32 = kioc->user_pthru;
831 kpthru32 = kioc->pthru32;
833 if (copy_to_user(&upthru32->scsistatus,
834 &kpthru32->scsistatus,
840 if (kioc->user_data) {
841 if (copy_to_user(kioc->user_data, kioc->buf_vaddr,
842 kioc->user_data_len)) {
847 if (copy_to_user(&mimd->mbox[17],
848 &mbox64->mbox32.status, sizeof(uint8_t))) {
857 * hinfo_to_cinfo - Convert new format hba info into old format
859 * @hinfo : New format, more comprehensive adapter info
860 * @cinfo : Old format adapter info to support mimd_t apps
863 hinfo_to_cinfo(mraid_hba_info_t *hinfo, mcontroller_t *cinfo)
865 if (!hinfo || !cinfo)
868 cinfo->base = hinfo->baseport;
869 cinfo->irq = hinfo->irq;
870 cinfo->numldrv = hinfo->num_ldrv;
871 cinfo->pcibus = hinfo->pci_bus;
872 cinfo->pcidev = hinfo->pci_slot;
873 cinfo->pcifun = PCI_FUNC(hinfo->pci_dev_fn);
874 cinfo->pciid = hinfo->pci_device_id;
875 cinfo->pcivendor = hinfo->pci_vendor_id;
876 cinfo->pcislot = hinfo->pci_slot;
877 cinfo->uid = hinfo->unique_id;
882 * mraid_mm_register_adp - Registration routine for low level drvrs
884 * @adp : Adapter objejct
887 mraid_mm_register_adp(mraid_mmadp_t *lld_adp)
889 mraid_mmadp_t *adapter;
896 if (lld_adp->drvr_type != DRVRTYPE_MBOX)
899 adapter = kmalloc(sizeof(mraid_mmadp_t), GFP_KERNEL);
906 memset(adapter, 0, sizeof(mraid_mmadp_t));
908 adapter->unique_id = lld_adp->unique_id;
909 adapter->drvr_type = lld_adp->drvr_type;
910 adapter->drvr_data = lld_adp->drvr_data;
911 adapter->pdev = lld_adp->pdev;
912 adapter->issue_uioc = lld_adp->issue_uioc;
913 adapter->timeout = lld_adp->timeout;
914 adapter->max_kioc = lld_adp->max_kioc;
915 adapter->quiescent = 1;
918 * Allocate single blocks of memory for all required kiocs,
919 * mailboxes and passthru structures.
921 adapter->kioc_list = kmalloc(sizeof(uioc_t) * lld_adp->max_kioc,
923 adapter->mbox_list = kmalloc(sizeof(mbox64_t) * lld_adp->max_kioc,
925 adapter->pthru_dma_pool = pci_pool_create("megaraid mm pthru pool",
927 sizeof(mraid_passthru_t),
930 if (!adapter->kioc_list || !adapter->mbox_list ||
931 !adapter->pthru_dma_pool) {
933 con_log(CL_ANN, (KERN_WARNING
934 "megaraid cmm: out of memory, %s %d\n", __FUNCTION__,
943 * Slice kioc_list and make a kioc_pool with the individiual kiocs
945 INIT_LIST_HEAD(&adapter->kioc_pool);
946 spin_lock_init(&adapter->kioc_pool_lock);
947 sema_init(&adapter->kioc_semaphore, lld_adp->max_kioc);
949 mbox_list = (mbox64_t *)adapter->mbox_list;
951 for (i = 0; i < lld_adp->max_kioc; i++) {
953 kioc = adapter->kioc_list + i;
954 kioc->cmdbuf = (uint64_t)(unsigned long)(mbox_list + i);
955 kioc->pthru32 = pci_pool_alloc(adapter->pthru_dma_pool,
956 GFP_KERNEL, &kioc->pthru32_h);
958 if (!kioc->pthru32) {
960 con_log(CL_ANN, (KERN_WARNING
961 "megaraid cmm: out of memory, %s %d\n",
962 __FUNCTION__, __LINE__));
966 goto pthru_dma_pool_error;
969 list_add_tail(&kioc->list, &adapter->kioc_pool);
972 // Setup the dma pools for data buffers
973 if ((rval = mraid_mm_setup_dma_pools(adapter)) != 0) {
977 list_add_tail(&adapter->list, &adapters_list_g);
986 pthru_dma_pool_error:
988 for (i = 0; i < lld_adp->max_kioc; i++) {
989 kioc = adapter->kioc_list + i;
991 pci_pool_free(adapter->pthru_dma_pool, kioc->pthru32,
998 kfree(adapter->kioc_list);
999 kfree(adapter->mbox_list);
1001 if (adapter->pthru_dma_pool)
1002 pci_pool_destroy(adapter->pthru_dma_pool);
1011 * mraid_mm_adapter_app_handle - return the application handle for this adapter
1013 * For the given driver data, locate the adadpter in our global list and
1014 * return the corresponding handle, which is also used by applications to
1015 * uniquely identify an adapter.
1017 * @param unique_id : adapter unique identifier
1019 * @return adapter handle if found in the list
1020 * @return 0 if adapter could not be located, should never happen though
1023 mraid_mm_adapter_app_handle(uint32_t unique_id)
1025 mraid_mmadp_t *adapter;
1029 list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
1031 if (adapter->unique_id == unique_id) {
1033 return MKADAP(index);
1044 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1046 * @adp : Adapter softstate
1048 * We maintain a pool of dma buffers per each adapter. Each pool has one
1049 * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
1050 * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
1051 * dont' want to waste too much memory by allocating more buffers per each
1055 mraid_mm_setup_dma_pools(mraid_mmadp_t *adp)
1062 * Create MAX_DMA_POOLS number of pools
1064 bufsize = MRAID_MM_INIT_BUFF_SIZE;
1066 for (i = 0; i < MAX_DMA_POOLS; i++){
1068 pool = &adp->dma_pool_list[i];
1070 pool->buf_size = bufsize;
1071 spin_lock_init(&pool->lock);
1073 pool->handle = pci_pool_create("megaraid mm data buffer",
1074 adp->pdev, bufsize, 16, 0);
1076 if (!pool->handle) {
1077 goto dma_pool_setup_error;
1080 pool->vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL,
1084 goto dma_pool_setup_error;
1086 bufsize = bufsize * 2;
1091 dma_pool_setup_error:
1093 mraid_mm_teardown_dma_pools(adp);
1099 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1100 * Assume no outstanding ioctls to llds.
1102 * @unique_id : UID of the adpater
1105 mraid_mm_unregister_adp(uint32_t unique_id)
1107 mraid_mmadp_t *adapter;
1110 list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) {
1113 if (adapter->unique_id == unique_id) {
1117 list_del_init(&adapter->list);
1119 mraid_mm_free_adp_resources(adapter);
1124 "megaraid cmm: Unregistered one adapter:%#x\n",
1135 * mraid_mm_free_adp_resources - Free adapter softstate
1137 * @adp : Adapter softstate
1140 mraid_mm_free_adp_resources(mraid_mmadp_t *adp)
1145 mraid_mm_teardown_dma_pools(adp);
1147 for (i = 0; i < adp->max_kioc; i++) {
1149 kioc = adp->kioc_list + i;
1151 pci_pool_free(adp->pthru_dma_pool, kioc->pthru32,
1155 kfree(adp->kioc_list);
1156 kfree(adp->mbox_list);
1158 pci_pool_destroy(adp->pthru_dma_pool);
1166 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1168 * @adp : Adapter softstate
1171 mraid_mm_teardown_dma_pools(mraid_mmadp_t *adp)
1176 for (i = 0; i < MAX_DMA_POOLS; i++) {
1178 pool = &adp->dma_pool_list[i];
1183 pci_pool_free(pool->handle, pool->vaddr,
1186 pci_pool_destroy(pool->handle);
1187 pool->handle = NULL;
1195 * mraid_mm_init : Module entry point
1200 // Announce the driver version
1201 con_log(CL_ANN, (KERN_INFO "megaraid cmm: %s %s\n",
1202 LSI_COMMON_MOD_VERSION, LSI_COMMON_MOD_EXT_VERSION));
1204 majorno = register_chrdev(0, "megadev", &lsi_fops);
1207 con_log(CL_ANN, ("megaraid cmm: cannot get major\n"));
1211 init_waitqueue_head(&wait_q);
1213 INIT_LIST_HEAD(&adapters_list_g);
1220 * mraid_mm_compat_ioctl : 32bit to 64bit ioctl conversion routine
1222 #ifdef CONFIG_COMPAT
1224 mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd,
1229 err = mraid_mm_ioctl(NULL, filep, cmd, arg);
1236 * mraid_mm_exit : Module exit point
1241 con_log(CL_DLEVEL1 , ("exiting common mod\n"));
1243 unregister_chrdev(majorno, "megadev");
1246 module_init(mraid_mm_init);
1247 module_exit(mraid_mm_exit);
1249 /* vi: set ts=8 sw=8 tw=78: */