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.7 (Jul 16 2006)
15 * Common management module
17 #include <linux/sched.h>
18 #include <linux/slab.h>
19 #include <linux/smp_lock.h>
20 #include "megaraid_mm.h"
23 // Entry points for char node driver
24 static int mraid_mm_open(struct inode
*, struct file
*);
25 static int mraid_mm_ioctl(struct inode
*, struct file
*, uint
, unsigned long);
28 // routines to convert to and from the old the format
29 static int mimd_to_kioc(mimd_t __user
*, mraid_mmadp_t
*, uioc_t
*);
30 static int kioc_to_mimd(uioc_t
*, mimd_t __user
*);
34 static int handle_drvrcmd(void __user
*, uint8_t, int *);
35 static int lld_ioctl(mraid_mmadp_t
*, uioc_t
*);
36 static void ioctl_done(uioc_t
*);
37 static void lld_timedout(unsigned long);
38 static void hinfo_to_cinfo(mraid_hba_info_t
*, mcontroller_t
*);
39 static mraid_mmadp_t
*mraid_mm_get_adapter(mimd_t __user
*, int *);
40 static uioc_t
*mraid_mm_alloc_kioc(mraid_mmadp_t
*);
41 static void mraid_mm_dealloc_kioc(mraid_mmadp_t
*, uioc_t
*);
42 static int mraid_mm_attach_buf(mraid_mmadp_t
*, uioc_t
*, int);
43 static int mraid_mm_setup_dma_pools(mraid_mmadp_t
*);
44 static void mraid_mm_free_adp_resources(mraid_mmadp_t
*);
45 static void mraid_mm_teardown_dma_pools(mraid_mmadp_t
*);
48 static long mraid_mm_compat_ioctl(struct file
*, unsigned int, unsigned long);
51 MODULE_AUTHOR("LSI Logic Corporation");
52 MODULE_DESCRIPTION("LSI Logic Management Module");
53 MODULE_LICENSE("GPL");
54 MODULE_VERSION(LSI_COMMON_MOD_VERSION
);
56 static int dbglevel
= CL_ANN
;
57 module_param_named(dlevel
, dbglevel
, int, 0);
58 MODULE_PARM_DESC(dlevel
, "Debug level (default=0)");
60 EXPORT_SYMBOL(mraid_mm_register_adp
);
61 EXPORT_SYMBOL(mraid_mm_unregister_adp
);
62 EXPORT_SYMBOL(mraid_mm_adapter_app_handle
);
64 static uint32_t drvr_ver
= 0x02200207;
66 static int adapters_count_g
;
67 static struct list_head adapters_list_g
;
69 static wait_queue_head_t wait_q
;
71 static const struct file_operations lsi_fops
= {
72 .open
= mraid_mm_open
,
73 .ioctl
= mraid_mm_ioctl
,
75 .compat_ioctl
= mraid_mm_compat_ioctl
,
80 static struct miscdevice megaraid_mm_dev
= {
81 .minor
= MISC_DYNAMIC_MINOR
,
87 * mraid_mm_open - open routine for char node interface
91 * Allow ioctl operations by apps only if they have superuser privilege.
94 mraid_mm_open(struct inode
*inode
, struct file
*filep
)
97 * Only allow superuser to access private ioctl interface
99 if (!capable(CAP_SYS_ADMIN
)) return (-EACCES
);
106 * mraid_mm_ioctl - module entry-point for ioctls
107 * @inode : inode (ignored)
108 * @filep : file operations pointer (ignored)
109 * @cmd : ioctl command
110 * @arg : user ioctl packet
113 mraid_mm_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
,
117 char signature
[EXT_IOCTL_SIGN_SZ
] = {0};
122 void __user
*argp
= (void __user
*)arg
;
125 * Make sure only USCSICMD are issued through this interface.
126 * MIMD application would still fire different command.
129 if ((_IOC_TYPE(cmd
) != MEGAIOC_MAGIC
) && (cmd
!= USCSICMD
)) {
134 * Look for signature to see if this is the new or old ioctl format.
136 if (copy_from_user(signature
, argp
, EXT_IOCTL_SIGN_SZ
)) {
137 con_log(CL_ANN
, (KERN_WARNING
138 "megaraid cmm: copy from usr addr failed\n"));
142 if (memcmp(signature
, EXT_IOCTL_SIGN
, EXT_IOCTL_SIGN_SZ
) == 0)
148 * At present, we don't support the new ioctl packet
154 * If it is a driver ioctl (as opposed to fw ioctls), then we can
155 * handle the command locally. rval > 0 means it is not a drvr cmd
157 rval
= handle_drvrcmd(argp
, old_ioctl
, &drvrcmd_rval
);
165 if ((adp
= mraid_mm_get_adapter(argp
, &rval
)) == NULL
) {
170 * Check if adapter can accept ioctl. We may have marked it offline
171 * if any previous kioc had timedout on this controller.
173 if (!adp
->quiescent
) {
174 con_log(CL_ANN
, (KERN_WARNING
175 "megaraid cmm: controller cannot accept cmds due to "
176 "earlier errors\n" ));
181 * The following call will block till a kioc is available
183 kioc
= mraid_mm_alloc_kioc(adp
);
186 * User sent the old mimd_t ioctl packet. Convert it to uioc_t.
188 if ((rval
= mimd_to_kioc(argp
, adp
, kioc
))) {
189 mraid_mm_dealloc_kioc(adp
, kioc
);
193 kioc
->done
= ioctl_done
;
196 * Issue the IOCTL to the low level driver. After the IOCTL completes
197 * release the kioc if and only if it was _not_ timedout. If it was
198 * timedout, that means that resources are still with low level driver.
200 if ((rval
= lld_ioctl(adp
, kioc
))) {
203 mraid_mm_dealloc_kioc(adp
, kioc
);
209 * Convert the kioc back to user space
211 rval
= kioc_to_mimd(kioc
, argp
);
214 * Return the kioc to free pool
216 mraid_mm_dealloc_kioc(adp
, kioc
);
223 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
224 * @umimd : User space mimd_t ioctl packet
225 * @rval : returned success/error status
227 * The function return value is a pointer to the located @adapter.
229 static mraid_mmadp_t
*
230 mraid_mm_get_adapter(mimd_t __user
*umimd
, int *rval
)
232 mraid_mmadp_t
*adapter
;
238 if (copy_from_user(&mimd
, umimd
, sizeof(mimd_t
))) {
243 adapno
= GETADAP(mimd
.ui
.fcs
.adapno
);
245 if (adapno
>= adapters_count_g
) {
253 list_for_each_entry(adapter
, &adapters_list_g
, list
) {
254 if (iterator
++ == adapno
) break;
266 * handle_drvrcmd - Checks if the opcode is a driver cmd and if it is, handles it.
267 * @arg : packet sent by the user app
268 * @old_ioctl : mimd if 1; uioc otherwise
269 * @rval : pointer for command's returned value (not function status)
272 handle_drvrcmd(void __user
*arg
, uint8_t old_ioctl
, int *rval
)
274 mimd_t __user
*umimd
;
291 if (copy_from_user(&kmimd
, umimd
, sizeof(mimd_t
)))
294 opcode
= kmimd
.ui
.fcs
.opcode
;
295 subopcode
= kmimd
.ui
.fcs
.subopcode
;
298 * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
299 * GET_NUMADP, then we can handle. Otherwise we should return 1 to
300 * indicate that we cannot handle this.
307 case MEGAIOC_QDRVRVER
:
309 if (copy_to_user(kmimd
.data
, &drvr_ver
, sizeof(uint32_t)))
316 *rval
= adapters_count_g
;
318 if (copy_to_user(kmimd
.data
, &adapters_count_g
,
334 * mimd_to_kioc - Converter from old to new ioctl format
335 * @umimd : user space old MIMD IOCTL
336 * @adp : adapter softstate
337 * @kioc : kernel space new format IOCTL
339 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
340 * new packet is in kernel space so that driver can perform operations on it
345 mimd_to_kioc(mimd_t __user
*umimd
, mraid_mmadp_t
*adp
, uioc_t
*kioc
)
349 mraid_passthru_t
*pthru32
;
355 if (copy_from_user(&mimd
, umimd
, sizeof(mimd_t
)))
359 * Applications are not allowed to send extd pthru
361 if ((mimd
.mbox
[0] == MBOXCMD_PASSTHRU64
) ||
362 (mimd
.mbox
[0] == MBOXCMD_EXTPTHRU
))
365 opcode
= mimd
.ui
.fcs
.opcode
;
366 subopcode
= mimd
.ui
.fcs
.subopcode
;
367 adapno
= GETADAP(mimd
.ui
.fcs
.adapno
);
369 if (adapno
>= adapters_count_g
)
372 kioc
->adapno
= adapno
;
373 kioc
->mb_type
= MBOX_LEGACY
;
374 kioc
->app_type
= APPTYPE_MIMD
;
380 if (subopcode
== MEGAIOC_QADAPINFO
) {
382 kioc
->opcode
= GET_ADAP_INFO
;
383 kioc
->data_dir
= UIOC_RD
;
384 kioc
->xferlen
= sizeof(mraid_hba_info_t
);
386 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
390 con_log(CL_ANN
, (KERN_WARNING
391 "megaraid cmm: Invalid subop\n"));
399 kioc
->opcode
= MBOX_CMD
;
400 kioc
->xferlen
= mimd
.ui
.fcs
.length
;
401 kioc
->user_data_len
= kioc
->xferlen
;
402 kioc
->user_data
= mimd
.ui
.fcs
.buffer
;
404 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
407 if (mimd
.outlen
) kioc
->data_dir
= UIOC_RD
;
408 if (mimd
.inlen
) kioc
->data_dir
|= UIOC_WR
;
414 kioc
->opcode
= MBOX_CMD
;
415 kioc
->xferlen
= (mimd
.outlen
> mimd
.inlen
) ?
416 mimd
.outlen
: mimd
.inlen
;
417 kioc
->user_data_len
= kioc
->xferlen
;
418 kioc
->user_data
= mimd
.data
;
420 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
423 if (mimd
.outlen
) kioc
->data_dir
= UIOC_RD
;
424 if (mimd
.inlen
) kioc
->data_dir
|= UIOC_WR
;
433 * If driver command, nothing else to do
439 * This is a mailbox cmd; copy the mailbox from mimd
441 mbox64
= (mbox64_t
*)((unsigned long)kioc
->cmdbuf
);
442 mbox
= &mbox64
->mbox32
;
443 memcpy(mbox
, mimd
.mbox
, 14);
445 if (mbox
->cmd
!= MBOXCMD_PASSTHRU
) { // regular DCMD
447 mbox
->xferaddr
= (uint32_t)kioc
->buf_paddr
;
449 if (kioc
->data_dir
& UIOC_WR
) {
450 if (copy_from_user(kioc
->buf_vaddr
, kioc
->user_data
,
460 * This is a regular 32-bit pthru cmd; mbox points to pthru struct.
461 * Just like in above case, the beginning for memblk is treated as
462 * a mailbox. The passthru will begin at next 1K boundary. And the
463 * data will start 1K after that.
465 pthru32
= kioc
->pthru32
;
466 kioc
->user_pthru
= &umimd
->pthru
;
467 mbox
->xferaddr
= (uint32_t)kioc
->pthru32_h
;
469 if (copy_from_user(pthru32
, kioc
->user_pthru
,
470 sizeof(mraid_passthru_t
))) {
474 pthru32
->dataxferaddr
= kioc
->buf_paddr
;
475 if (kioc
->data_dir
& UIOC_WR
) {
476 if (copy_from_user(kioc
->buf_vaddr
, kioc
->user_data
,
477 pthru32
->dataxferlen
)) {
486 * mraid_mm_attch_buf - Attach a free dma buffer for required size
487 * @adp : Adapter softstate
488 * @kioc : kioc that the buffer needs to be attached to
489 * @xferlen : required length for buffer
491 * First we search for a pool with smallest buffer that is >= @xferlen. If
492 * that pool has no free buffer, we will try for the next bigger size. If none
493 * is available, we will try to allocate the smallest buffer that is >=
494 * @xferlen and attach it the pool.
497 mraid_mm_attach_buf(mraid_mmadp_t
*adp
, uioc_t
*kioc
, int xferlen
)
504 kioc
->pool_index
= -1;
505 kioc
->buf_vaddr
= NULL
;
510 * We need xferlen amount of memory. See if we can get it from our
511 * dma pools. If we don't get exact size, we will try bigger buffer
514 for (i
= 0; i
< MAX_DMA_POOLS
; i
++) {
516 pool
= &adp
->dma_pool_list
[i
];
518 if (xferlen
> pool
->buf_size
)
521 if (right_pool
== -1)
524 spin_lock_irqsave(&pool
->lock
, flags
);
529 kioc
->pool_index
= i
;
530 kioc
->buf_vaddr
= pool
->vaddr
;
531 kioc
->buf_paddr
= pool
->paddr
;
533 spin_unlock_irqrestore(&pool
->lock
, flags
);
537 spin_unlock_irqrestore(&pool
->lock
, flags
);
543 * If xferlen doesn't match any of our pools, return error
545 if (right_pool
== -1)
549 * We did not get any buffer from the preallocated pool. Let us try
550 * to allocate one new buffer. NOTE: This is a blocking call.
552 pool
= &adp
->dma_pool_list
[right_pool
];
554 spin_lock_irqsave(&pool
->lock
, flags
);
556 kioc
->pool_index
= right_pool
;
558 kioc
->buf_vaddr
= pci_pool_alloc(pool
->handle
, GFP_KERNEL
,
560 spin_unlock_irqrestore(&pool
->lock
, flags
);
562 if (!kioc
->buf_vaddr
)
569 * mraid_mm_alloc_kioc - Returns a uioc_t from free list
570 * @adp : Adapter softstate for this module
572 * The kioc_semaphore is initialized with number of kioc nodes in the
573 * free kioc pool. If the kioc pool is empty, this function blocks till
574 * a kioc becomes free.
577 mraid_mm_alloc_kioc(mraid_mmadp_t
*adp
)
580 struct list_head
* head
;
583 down(&adp
->kioc_semaphore
);
585 spin_lock_irqsave(&adp
->kioc_pool_lock
, flags
);
587 head
= &adp
->kioc_pool
;
589 if (list_empty(head
)) {
590 up(&adp
->kioc_semaphore
);
591 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
593 con_log(CL_ANN
, ("megaraid cmm: kioc list empty!\n"));
597 kioc
= list_entry(head
->next
, uioc_t
, list
);
598 list_del_init(&kioc
->list
);
600 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
602 memset((caddr_t
)(unsigned long)kioc
->cmdbuf
, 0, sizeof(mbox64_t
));
603 memset((caddr_t
) kioc
->pthru32
, 0, sizeof(mraid_passthru_t
));
605 kioc
->buf_vaddr
= NULL
;
607 kioc
->pool_index
=-1;
609 kioc
->user_data
= NULL
;
610 kioc
->user_data_len
= 0;
611 kioc
->user_pthru
= NULL
;
618 * mraid_mm_dealloc_kioc - Return kioc to free pool
619 * @adp : Adapter softstate
620 * @kioc : uioc_t node to be returned to free pool
623 mraid_mm_dealloc_kioc(mraid_mmadp_t
*adp
, uioc_t
*kioc
)
628 if (kioc
->pool_index
!= -1) {
629 pool
= &adp
->dma_pool_list
[kioc
->pool_index
];
631 /* This routine may be called in non-isr context also */
632 spin_lock_irqsave(&pool
->lock
, flags
);
635 * While attaching the dma buffer, if we didn't get the
636 * required buffer from the pool, we would have allocated
637 * it at the run time and set the free_buf flag. We must
638 * free that buffer. Otherwise, just mark that the buffer is
641 if (kioc
->free_buf
== 1)
642 pci_pool_free(pool
->handle
, kioc
->buf_vaddr
,
647 spin_unlock_irqrestore(&pool
->lock
, flags
);
650 /* Return the kioc to the free pool */
651 spin_lock_irqsave(&adp
->kioc_pool_lock
, flags
);
652 list_add(&kioc
->list
, &adp
->kioc_pool
);
653 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
655 /* increment the free kioc count */
656 up(&adp
->kioc_semaphore
);
662 * lld_ioctl - Routine to issue ioctl to low level drvr
663 * @adp : The adapter handle
664 * @kioc : The ioctl packet with kernel addresses
667 lld_ioctl(mraid_mmadp_t
*adp
, uioc_t
*kioc
)
670 struct timer_list timer
;
671 struct timer_list
*tp
= NULL
;
673 kioc
->status
= -ENODATA
;
674 rval
= adp
->issue_uioc(adp
->drvr_data
, kioc
, IOCTL_ISSUE
);
676 if (rval
) return rval
;
681 if (adp
->timeout
> 0) {
685 tp
->function
= lld_timedout
;
686 tp
->data
= (unsigned long)kioc
;
687 tp
->expires
= jiffies
+ adp
->timeout
* HZ
;
693 * Wait till the low level driver completes the ioctl. After this
694 * call, the ioctl either completed successfully or timedout.
696 wait_event(wait_q
, (kioc
->status
!= -ENODATA
));
702 * If the command had timedout, we mark the controller offline
705 if (kioc
->timedout
) {
714 * ioctl_done - callback from the low level driver
715 * @kioc : completed ioctl packet
718 ioctl_done(uioc_t
*kioc
)
722 mraid_mmadp_t
* adapter
;
725 * When the kioc returns from driver, make sure it still doesn't
726 * have ENODATA in status. Otherwise, driver will hang on wait_event
729 if (kioc
->status
== -ENODATA
) {
730 con_log(CL_ANN
, (KERN_WARNING
731 "megaraid cmm: lld didn't change status!\n"));
733 kioc
->status
= -EINVAL
;
737 * Check if this kioc was timedout before. If so, nobody is waiting
738 * on this kioc. We don't have to wake up anybody. Instead, we just
739 * have to free the kioc
741 if (kioc
->timedout
) {
744 adapno
= kioc
->adapno
;
746 con_log(CL_ANN
, ( KERN_WARNING
"megaraid cmm: completed "
747 "ioctl that was timedout before\n"));
749 list_for_each_entry(adapter
, &adapters_list_g
, list
) {
750 if (iterator
++ == adapno
) break;
756 mraid_mm_dealloc_kioc( adapter
, kioc
);
766 * lld_timedout - callback from the expired timer
767 * @ptr : ioctl packet that timed out
770 lld_timedout(unsigned long ptr
)
772 uioc_t
*kioc
= (uioc_t
*)ptr
;
774 kioc
->status
= -ETIME
;
777 con_log(CL_ANN
, (KERN_WARNING
"megaraid cmm: ioctl timed out\n"));
784 * kioc_to_mimd - Converter from new back to old format
785 * @kioc : Kernel space IOCTL packet (successfully issued)
786 * @mimd : User space MIMD packet
789 kioc_to_mimd(uioc_t
*kioc
, mimd_t __user
*mimd
)
796 mraid_passthru_t __user
*upthru32
;
797 mraid_passthru_t
*kpthru32
;
799 mraid_hba_info_t
*hinfo
;
802 if (copy_from_user(&kmimd
, mimd
, sizeof(mimd_t
)))
805 opcode
= kmimd
.ui
.fcs
.opcode
;
806 subopcode
= kmimd
.ui
.fcs
.subopcode
;
808 if (opcode
== 0x82) {
811 case MEGAIOC_QADAPINFO
:
813 hinfo
= (mraid_hba_info_t
*)(unsigned long)
816 hinfo_to_cinfo(hinfo
, &cinfo
);
818 if (copy_to_user(kmimd
.data
, &cinfo
, sizeof(cinfo
)))
830 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
832 if (kioc
->user_pthru
) {
834 upthru32
= kioc
->user_pthru
;
835 kpthru32
= kioc
->pthru32
;
837 if (copy_to_user(&upthru32
->scsistatus
,
838 &kpthru32
->scsistatus
,
844 if (kioc
->user_data
) {
845 if (copy_to_user(kioc
->user_data
, kioc
->buf_vaddr
,
846 kioc
->user_data_len
)) {
851 if (copy_to_user(&mimd
->mbox
[17],
852 &mbox64
->mbox32
.status
, sizeof(uint8_t))) {
861 * hinfo_to_cinfo - Convert new format hba info into old format
862 * @hinfo : New format, more comprehensive adapter info
863 * @cinfo : Old format adapter info to support mimd_t apps
866 hinfo_to_cinfo(mraid_hba_info_t
*hinfo
, mcontroller_t
*cinfo
)
868 if (!hinfo
|| !cinfo
)
871 cinfo
->base
= hinfo
->baseport
;
872 cinfo
->irq
= hinfo
->irq
;
873 cinfo
->numldrv
= hinfo
->num_ldrv
;
874 cinfo
->pcibus
= hinfo
->pci_bus
;
875 cinfo
->pcidev
= hinfo
->pci_slot
;
876 cinfo
->pcifun
= PCI_FUNC(hinfo
->pci_dev_fn
);
877 cinfo
->pciid
= hinfo
->pci_device_id
;
878 cinfo
->pcivendor
= hinfo
->pci_vendor_id
;
879 cinfo
->pcislot
= hinfo
->pci_slot
;
880 cinfo
->uid
= hinfo
->unique_id
;
885 * mraid_mm_register_adp - Registration routine for low level drivers
886 * @lld_adp : Adapter objejct
889 mraid_mm_register_adp(mraid_mmadp_t
*lld_adp
)
891 mraid_mmadp_t
*adapter
;
898 if (lld_adp
->drvr_type
!= DRVRTYPE_MBOX
)
901 adapter
= kzalloc(sizeof(mraid_mmadp_t
), GFP_KERNEL
);
907 adapter
->unique_id
= lld_adp
->unique_id
;
908 adapter
->drvr_type
= lld_adp
->drvr_type
;
909 adapter
->drvr_data
= lld_adp
->drvr_data
;
910 adapter
->pdev
= lld_adp
->pdev
;
911 adapter
->issue_uioc
= lld_adp
->issue_uioc
;
912 adapter
->timeout
= lld_adp
->timeout
;
913 adapter
->max_kioc
= lld_adp
->max_kioc
;
914 adapter
->quiescent
= 1;
917 * Allocate single blocks of memory for all required kiocs,
918 * mailboxes and passthru structures.
920 adapter
->kioc_list
= kmalloc(sizeof(uioc_t
) * lld_adp
->max_kioc
,
922 adapter
->mbox_list
= kmalloc(sizeof(mbox64_t
) * lld_adp
->max_kioc
,
924 adapter
->pthru_dma_pool
= pci_pool_create("megaraid mm pthru pool",
926 sizeof(mraid_passthru_t
),
929 if (!adapter
->kioc_list
|| !adapter
->mbox_list
||
930 !adapter
->pthru_dma_pool
) {
932 con_log(CL_ANN
, (KERN_WARNING
933 "megaraid cmm: out of memory, %s %d\n", __func__
,
942 * Slice kioc_list and make a kioc_pool with the individiual kiocs
944 INIT_LIST_HEAD(&adapter
->kioc_pool
);
945 spin_lock_init(&adapter
->kioc_pool_lock
);
946 sema_init(&adapter
->kioc_semaphore
, lld_adp
->max_kioc
);
948 mbox_list
= (mbox64_t
*)adapter
->mbox_list
;
950 for (i
= 0; i
< lld_adp
->max_kioc
; i
++) {
952 kioc
= adapter
->kioc_list
+ i
;
953 kioc
->cmdbuf
= (uint64_t)(unsigned long)(mbox_list
+ i
);
954 kioc
->pthru32
= pci_pool_alloc(adapter
->pthru_dma_pool
,
955 GFP_KERNEL
, &kioc
->pthru32_h
);
957 if (!kioc
->pthru32
) {
959 con_log(CL_ANN
, (KERN_WARNING
960 "megaraid cmm: out of memory, %s %d\n",
961 __func__
, __LINE__
));
965 goto pthru_dma_pool_error
;
968 list_add_tail(&kioc
->list
, &adapter
->kioc_pool
);
971 // Setup the dma pools for data buffers
972 if ((rval
= mraid_mm_setup_dma_pools(adapter
)) != 0) {
976 list_add_tail(&adapter
->list
, &adapters_list_g
);
985 pthru_dma_pool_error
:
987 for (i
= 0; i
< lld_adp
->max_kioc
; i
++) {
988 kioc
= adapter
->kioc_list
+ i
;
990 pci_pool_free(adapter
->pthru_dma_pool
, kioc
->pthru32
,
997 kfree(adapter
->kioc_list
);
998 kfree(adapter
->mbox_list
);
1000 if (adapter
->pthru_dma_pool
)
1001 pci_pool_destroy(adapter
->pthru_dma_pool
);
1010 * mraid_mm_adapter_app_handle - return the application handle for this adapter
1011 * @unique_id : adapter unique identifier
1013 * For the given driver data, locate the adapter in our global list and
1014 * return the corresponding handle, which is also used by applications to
1015 * uniquely identify an adapter.
1017 * Return adapter handle if found in the list.
1018 * Return 0 if adapter could not be located, should never happen though.
1021 mraid_mm_adapter_app_handle(uint32_t unique_id
)
1023 mraid_mmadp_t
*adapter
;
1027 list_for_each_entry_safe(adapter
, tmp
, &adapters_list_g
, list
) {
1029 if (adapter
->unique_id
== unique_id
) {
1031 return MKADAP(index
);
1042 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1043 * @adp : Adapter softstate
1045 * We maintain a pool of dma buffers per each adapter. Each pool has one
1046 * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
1047 * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
1048 * dont' want to waste too much memory by allocating more buffers per each
1052 mraid_mm_setup_dma_pools(mraid_mmadp_t
*adp
)
1059 * Create MAX_DMA_POOLS number of pools
1061 bufsize
= MRAID_MM_INIT_BUFF_SIZE
;
1063 for (i
= 0; i
< MAX_DMA_POOLS
; i
++){
1065 pool
= &adp
->dma_pool_list
[i
];
1067 pool
->buf_size
= bufsize
;
1068 spin_lock_init(&pool
->lock
);
1070 pool
->handle
= pci_pool_create("megaraid mm data buffer",
1071 adp
->pdev
, bufsize
, 16, 0);
1073 if (!pool
->handle
) {
1074 goto dma_pool_setup_error
;
1077 pool
->vaddr
= pci_pool_alloc(pool
->handle
, GFP_KERNEL
,
1081 goto dma_pool_setup_error
;
1083 bufsize
= bufsize
* 2;
1088 dma_pool_setup_error
:
1090 mraid_mm_teardown_dma_pools(adp
);
1096 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1097 * @unique_id : UID of the adpater
1099 * Assumes no outstanding ioctls to llds.
1102 mraid_mm_unregister_adp(uint32_t unique_id
)
1104 mraid_mmadp_t
*adapter
;
1107 list_for_each_entry_safe(adapter
, tmp
, &adapters_list_g
, list
) {
1110 if (adapter
->unique_id
== unique_id
) {
1114 list_del_init(&adapter
->list
);
1116 mraid_mm_free_adp_resources(adapter
);
1121 "megaraid cmm: Unregistered one adapter:%#x\n",
1132 * mraid_mm_free_adp_resources - Free adapter softstate
1133 * @adp : Adapter softstate
1136 mraid_mm_free_adp_resources(mraid_mmadp_t
*adp
)
1141 mraid_mm_teardown_dma_pools(adp
);
1143 for (i
= 0; i
< adp
->max_kioc
; i
++) {
1145 kioc
= adp
->kioc_list
+ i
;
1147 pci_pool_free(adp
->pthru_dma_pool
, kioc
->pthru32
,
1151 kfree(adp
->kioc_list
);
1152 kfree(adp
->mbox_list
);
1154 pci_pool_destroy(adp
->pthru_dma_pool
);
1162 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1163 * @adp : Adapter softstate
1166 mraid_mm_teardown_dma_pools(mraid_mmadp_t
*adp
)
1171 for (i
= 0; i
< MAX_DMA_POOLS
; i
++) {
1173 pool
= &adp
->dma_pool_list
[i
];
1178 pci_pool_free(pool
->handle
, pool
->vaddr
,
1181 pci_pool_destroy(pool
->handle
);
1182 pool
->handle
= NULL
;
1190 * mraid_mm_init - Module entry point
1197 // Announce the driver version
1198 con_log(CL_ANN
, (KERN_INFO
"megaraid cmm: %s %s\n",
1199 LSI_COMMON_MOD_VERSION
, LSI_COMMON_MOD_EXT_VERSION
));
1201 err
= misc_register(&megaraid_mm_dev
);
1203 con_log(CL_ANN
, ("megaraid cmm: cannot register misc device\n"));
1207 init_waitqueue_head(&wait_q
);
1209 INIT_LIST_HEAD(&adapters_list_g
);
1215 #ifdef CONFIG_COMPAT
1217 * mraid_mm_compat_ioctl - 32bit to 64bit ioctl conversion routine
1218 * @filep : file operations pointer (ignored)
1219 * @cmd : ioctl command
1220 * @arg : user ioctl packet
1223 mraid_mm_compat_ioctl(struct file
*filep
, unsigned int cmd
,
1228 err
= mraid_mm_ioctl(NULL
, filep
, cmd
, arg
);
1235 * mraid_mm_exit - Module exit point
1240 con_log(CL_DLEVEL1
, ("exiting common mod\n"));
1242 misc_deregister(&megaraid_mm_dev
);
1245 module_init(mraid_mm_init
);
1246 module_exit(mraid_mm_exit
);
1248 /* vi: set ts=8 sw=8 tw=78: */