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/smp_lock.h>
19 #include "megaraid_mm.h"
22 // Entry points for char node driver
23 static int mraid_mm_open(struct inode
*, struct file
*);
24 static int mraid_mm_ioctl(struct inode
*, struct file
*, uint
, unsigned long);
27 // routines to convert to and from the old the format
28 static int mimd_to_kioc(mimd_t __user
*, mraid_mmadp_t
*, uioc_t
*);
29 static int kioc_to_mimd(uioc_t
*, mimd_t __user
*);
33 static int handle_drvrcmd(void __user
*, uint8_t, int *);
34 static int lld_ioctl(mraid_mmadp_t
*, uioc_t
*);
35 static void ioctl_done(uioc_t
*);
36 static void lld_timedout(unsigned long);
37 static void hinfo_to_cinfo(mraid_hba_info_t
*, mcontroller_t
*);
38 static mraid_mmadp_t
*mraid_mm_get_adapter(mimd_t __user
*, int *);
39 static uioc_t
*mraid_mm_alloc_kioc(mraid_mmadp_t
*);
40 static void mraid_mm_dealloc_kioc(mraid_mmadp_t
*, uioc_t
*);
41 static int mraid_mm_attach_buf(mraid_mmadp_t
*, uioc_t
*, int);
42 static int mraid_mm_setup_dma_pools(mraid_mmadp_t
*);
43 static void mraid_mm_free_adp_resources(mraid_mmadp_t
*);
44 static void mraid_mm_teardown_dma_pools(mraid_mmadp_t
*);
47 static long mraid_mm_compat_ioctl(struct file
*, 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
);
63 static uint32_t drvr_ver
= 0x02200207;
65 static int adapters_count_g
;
66 static struct list_head adapters_list_g
;
68 static wait_queue_head_t wait_q
;
70 static const struct file_operations lsi_fops
= {
71 .open
= mraid_mm_open
,
72 .ioctl
= mraid_mm_ioctl
,
74 .compat_ioctl
= mraid_mm_compat_ioctl
,
79 static struct miscdevice megaraid_mm_dev
= {
80 .minor
= MISC_DYNAMIC_MINOR
,
86 * mraid_mm_open - open routine for char node interface
90 * Allow ioctl operations by apps only if they have superuser privilege.
93 mraid_mm_open(struct inode
*inode
, struct file
*filep
)
96 * Only allow superuser to access private ioctl interface
98 if (!capable(CAP_SYS_ADMIN
)) return (-EACCES
);
105 * mraid_mm_ioctl - module entry-point for ioctls
106 * @inode : inode (ignored)
107 * @filep : file operations pointer (ignored)
108 * @cmd : ioctl command
109 * @arg : user ioctl packet
112 mraid_mm_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
,
116 char signature
[EXT_IOCTL_SIGN_SZ
] = {0};
121 void __user
*argp
= (void __user
*)arg
;
124 * Make sure only USCSICMD are issued through this interface.
125 * MIMD application would still fire different command.
128 if ((_IOC_TYPE(cmd
) != MEGAIOC_MAGIC
) && (cmd
!= USCSICMD
)) {
133 * Look for signature to see if this is the new or old ioctl format.
135 if (copy_from_user(signature
, argp
, EXT_IOCTL_SIGN_SZ
)) {
136 con_log(CL_ANN
, (KERN_WARNING
137 "megaraid cmm: copy from usr addr failed\n"));
141 if (memcmp(signature
, EXT_IOCTL_SIGN
, EXT_IOCTL_SIGN_SZ
) == 0)
147 * At present, we don't support the new ioctl packet
153 * If it is a driver ioctl (as opposed to fw ioctls), then we can
154 * handle the command locally. rval > 0 means it is not a drvr cmd
156 rval
= handle_drvrcmd(argp
, old_ioctl
, &drvrcmd_rval
);
164 if ((adp
= mraid_mm_get_adapter(argp
, &rval
)) == NULL
) {
169 * Check if adapter can accept ioctl. We may have marked it offline
170 * if any previous kioc had timedout on this controller.
172 if (!adp
->quiescent
) {
173 con_log(CL_ANN
, (KERN_WARNING
174 "megaraid cmm: controller cannot accept cmds due to "
175 "earlier errors\n" ));
180 * The following call will block till a kioc is available
182 kioc
= mraid_mm_alloc_kioc(adp
);
185 * User sent the old mimd_t ioctl packet. Convert it to uioc_t.
187 if ((rval
= mimd_to_kioc(argp
, adp
, kioc
))) {
188 mraid_mm_dealloc_kioc(adp
, kioc
);
192 kioc
->done
= ioctl_done
;
195 * Issue the IOCTL to the low level driver. After the IOCTL completes
196 * release the kioc if and only if it was _not_ timedout. If it was
197 * timedout, that means that resources are still with low level driver.
199 if ((rval
= lld_ioctl(adp
, kioc
))) {
202 mraid_mm_dealloc_kioc(adp
, kioc
);
208 * Convert the kioc back to user space
210 rval
= kioc_to_mimd(kioc
, argp
);
213 * Return the kioc to free pool
215 mraid_mm_dealloc_kioc(adp
, kioc
);
222 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
223 * @umimd : User space mimd_t ioctl packet
224 * @rval : returned success/error status
226 * The function return value is a pointer to the located @adapter.
228 static mraid_mmadp_t
*
229 mraid_mm_get_adapter(mimd_t __user
*umimd
, int *rval
)
231 mraid_mmadp_t
*adapter
;
237 if (copy_from_user(&mimd
, umimd
, sizeof(mimd_t
))) {
242 adapno
= GETADAP(mimd
.ui
.fcs
.adapno
);
244 if (adapno
>= adapters_count_g
) {
252 list_for_each_entry(adapter
, &adapters_list_g
, list
) {
253 if (iterator
++ == adapno
) break;
265 * handle_drvrcmd - Checks if the opcode is a driver cmd and if it is, handles it.
266 * @arg : packet sent by the user app
267 * @old_ioctl : mimd if 1; uioc otherwise
268 * @rval : pointer for command's returned value (not function status)
271 handle_drvrcmd(void __user
*arg
, uint8_t old_ioctl
, int *rval
)
273 mimd_t __user
*umimd
;
290 if (copy_from_user(&kmimd
, umimd
, sizeof(mimd_t
)))
293 opcode
= kmimd
.ui
.fcs
.opcode
;
294 subopcode
= kmimd
.ui
.fcs
.subopcode
;
297 * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
298 * GET_NUMADP, then we can handle. Otherwise we should return 1 to
299 * indicate that we cannot handle this.
306 case MEGAIOC_QDRVRVER
:
308 if (copy_to_user(kmimd
.data
, &drvr_ver
, sizeof(uint32_t)))
315 *rval
= adapters_count_g
;
317 if (copy_to_user(kmimd
.data
, &adapters_count_g
,
333 * mimd_to_kioc - Converter from old to new ioctl format
334 * @umimd : user space old MIMD IOCTL
335 * @adp : adapter softstate
336 * @kioc : kernel space new format IOCTL
338 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
339 * new packet is in kernel space so that driver can perform operations on it
344 mimd_to_kioc(mimd_t __user
*umimd
, mraid_mmadp_t
*adp
, uioc_t
*kioc
)
348 mraid_passthru_t
*pthru32
;
354 if (copy_from_user(&mimd
, umimd
, sizeof(mimd_t
)))
358 * Applications are not allowed to send extd pthru
360 if ((mimd
.mbox
[0] == MBOXCMD_PASSTHRU64
) ||
361 (mimd
.mbox
[0] == MBOXCMD_EXTPTHRU
))
364 opcode
= mimd
.ui
.fcs
.opcode
;
365 subopcode
= mimd
.ui
.fcs
.subopcode
;
366 adapno
= GETADAP(mimd
.ui
.fcs
.adapno
);
368 if (adapno
>= adapters_count_g
)
371 kioc
->adapno
= adapno
;
372 kioc
->mb_type
= MBOX_LEGACY
;
373 kioc
->app_type
= APPTYPE_MIMD
;
379 if (subopcode
== MEGAIOC_QADAPINFO
) {
381 kioc
->opcode
= GET_ADAP_INFO
;
382 kioc
->data_dir
= UIOC_RD
;
383 kioc
->xferlen
= sizeof(mraid_hba_info_t
);
385 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
389 con_log(CL_ANN
, (KERN_WARNING
390 "megaraid cmm: Invalid subop\n"));
398 kioc
->opcode
= MBOX_CMD
;
399 kioc
->xferlen
= mimd
.ui
.fcs
.length
;
400 kioc
->user_data_len
= kioc
->xferlen
;
401 kioc
->user_data
= mimd
.ui
.fcs
.buffer
;
403 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
406 if (mimd
.outlen
) kioc
->data_dir
= UIOC_RD
;
407 if (mimd
.inlen
) kioc
->data_dir
|= UIOC_WR
;
413 kioc
->opcode
= MBOX_CMD
;
414 kioc
->xferlen
= (mimd
.outlen
> mimd
.inlen
) ?
415 mimd
.outlen
: mimd
.inlen
;
416 kioc
->user_data_len
= kioc
->xferlen
;
417 kioc
->user_data
= mimd
.data
;
419 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
422 if (mimd
.outlen
) kioc
->data_dir
= UIOC_RD
;
423 if (mimd
.inlen
) kioc
->data_dir
|= UIOC_WR
;
432 * If driver command, nothing else to do
438 * This is a mailbox cmd; copy the mailbox from mimd
440 mbox64
= (mbox64_t
*)((unsigned long)kioc
->cmdbuf
);
441 mbox
= &mbox64
->mbox32
;
442 memcpy(mbox
, mimd
.mbox
, 14);
444 if (mbox
->cmd
!= MBOXCMD_PASSTHRU
) { // regular DCMD
446 mbox
->xferaddr
= (uint32_t)kioc
->buf_paddr
;
448 if (kioc
->data_dir
& UIOC_WR
) {
449 if (copy_from_user(kioc
->buf_vaddr
, kioc
->user_data
,
459 * This is a regular 32-bit pthru cmd; mbox points to pthru struct.
460 * Just like in above case, the beginning for memblk is treated as
461 * a mailbox. The passthru will begin at next 1K boundary. And the
462 * data will start 1K after that.
464 pthru32
= kioc
->pthru32
;
465 kioc
->user_pthru
= &umimd
->pthru
;
466 mbox
->xferaddr
= (uint32_t)kioc
->pthru32_h
;
468 if (copy_from_user(pthru32
, kioc
->user_pthru
,
469 sizeof(mraid_passthru_t
))) {
473 pthru32
->dataxferaddr
= kioc
->buf_paddr
;
474 if (kioc
->data_dir
& UIOC_WR
) {
475 if (copy_from_user(kioc
->buf_vaddr
, kioc
->user_data
,
476 pthru32
->dataxferlen
)) {
485 * mraid_mm_attch_buf - Attach a free dma buffer for required size
486 * @adp : Adapter softstate
487 * @kioc : kioc that the buffer needs to be attached to
488 * @xferlen : required length for buffer
490 * First we search for a pool with smallest buffer that is >= @xferlen. If
491 * that pool has no free buffer, we will try for the next bigger size. If none
492 * is available, we will try to allocate the smallest buffer that is >=
493 * @xferlen and attach it the pool.
496 mraid_mm_attach_buf(mraid_mmadp_t
*adp
, uioc_t
*kioc
, int xferlen
)
503 kioc
->pool_index
= -1;
504 kioc
->buf_vaddr
= NULL
;
509 * We need xferlen amount of memory. See if we can get it from our
510 * dma pools. If we don't get exact size, we will try bigger buffer
513 for (i
= 0; i
< MAX_DMA_POOLS
; i
++) {
515 pool
= &adp
->dma_pool_list
[i
];
517 if (xferlen
> pool
->buf_size
)
520 if (right_pool
== -1)
523 spin_lock_irqsave(&pool
->lock
, flags
);
528 kioc
->pool_index
= i
;
529 kioc
->buf_vaddr
= pool
->vaddr
;
530 kioc
->buf_paddr
= pool
->paddr
;
532 spin_unlock_irqrestore(&pool
->lock
, flags
);
536 spin_unlock_irqrestore(&pool
->lock
, flags
);
542 * If xferlen doesn't match any of our pools, return error
544 if (right_pool
== -1)
548 * We did not get any buffer from the preallocated pool. Let us try
549 * to allocate one new buffer. NOTE: This is a blocking call.
551 pool
= &adp
->dma_pool_list
[right_pool
];
553 spin_lock_irqsave(&pool
->lock
, flags
);
555 kioc
->pool_index
= right_pool
;
557 kioc
->buf_vaddr
= pci_pool_alloc(pool
->handle
, GFP_KERNEL
,
559 spin_unlock_irqrestore(&pool
->lock
, flags
);
561 if (!kioc
->buf_vaddr
)
568 * mraid_mm_alloc_kioc - Returns a uioc_t from free list
569 * @adp : Adapter softstate for this module
571 * The kioc_semaphore is initialized with number of kioc nodes in the
572 * free kioc pool. If the kioc pool is empty, this function blocks till
573 * a kioc becomes free.
576 mraid_mm_alloc_kioc(mraid_mmadp_t
*adp
)
579 struct list_head
* head
;
582 down(&adp
->kioc_semaphore
);
584 spin_lock_irqsave(&adp
->kioc_pool_lock
, flags
);
586 head
= &adp
->kioc_pool
;
588 if (list_empty(head
)) {
589 up(&adp
->kioc_semaphore
);
590 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
592 con_log(CL_ANN
, ("megaraid cmm: kioc list empty!\n"));
596 kioc
= list_entry(head
->next
, uioc_t
, list
);
597 list_del_init(&kioc
->list
);
599 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
601 memset((caddr_t
)(unsigned long)kioc
->cmdbuf
, 0, sizeof(mbox64_t
));
602 memset((caddr_t
) kioc
->pthru32
, 0, sizeof(mraid_passthru_t
));
604 kioc
->buf_vaddr
= NULL
;
606 kioc
->pool_index
=-1;
608 kioc
->user_data
= NULL
;
609 kioc
->user_data_len
= 0;
610 kioc
->user_pthru
= NULL
;
617 * mraid_mm_dealloc_kioc - Return kioc to free pool
618 * @adp : Adapter softstate
619 * @kioc : uioc_t node to be returned to free pool
622 mraid_mm_dealloc_kioc(mraid_mmadp_t
*adp
, uioc_t
*kioc
)
627 if (kioc
->pool_index
!= -1) {
628 pool
= &adp
->dma_pool_list
[kioc
->pool_index
];
630 /* This routine may be called in non-isr context also */
631 spin_lock_irqsave(&pool
->lock
, flags
);
634 * While attaching the dma buffer, if we didn't get the
635 * required buffer from the pool, we would have allocated
636 * it at the run time and set the free_buf flag. We must
637 * free that buffer. Otherwise, just mark that the buffer is
640 if (kioc
->free_buf
== 1)
641 pci_pool_free(pool
->handle
, kioc
->buf_vaddr
,
646 spin_unlock_irqrestore(&pool
->lock
, flags
);
649 /* Return the kioc to the free pool */
650 spin_lock_irqsave(&adp
->kioc_pool_lock
, flags
);
651 list_add(&kioc
->list
, &adp
->kioc_pool
);
652 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
654 /* increment the free kioc count */
655 up(&adp
->kioc_semaphore
);
661 * lld_ioctl - Routine to issue ioctl to low level drvr
662 * @adp : The adapter handle
663 * @kioc : The ioctl packet with kernel addresses
666 lld_ioctl(mraid_mmadp_t
*adp
, uioc_t
*kioc
)
669 struct timer_list timer
;
670 struct timer_list
*tp
= NULL
;
672 kioc
->status
= -ENODATA
;
673 rval
= adp
->issue_uioc(adp
->drvr_data
, kioc
, IOCTL_ISSUE
);
675 if (rval
) return rval
;
680 if (adp
->timeout
> 0) {
684 tp
->function
= lld_timedout
;
685 tp
->data
= (unsigned long)kioc
;
686 tp
->expires
= jiffies
+ adp
->timeout
* HZ
;
692 * Wait till the low level driver completes the ioctl. After this
693 * call, the ioctl either completed successfully or timedout.
695 wait_event(wait_q
, (kioc
->status
!= -ENODATA
));
701 * If the command had timedout, we mark the controller offline
704 if (kioc
->timedout
) {
713 * ioctl_done - callback from the low level driver
714 * @kioc : completed ioctl packet
717 ioctl_done(uioc_t
*kioc
)
721 mraid_mmadp_t
* adapter
;
724 * When the kioc returns from driver, make sure it still doesn't
725 * have ENODATA in status. Otherwise, driver will hang on wait_event
728 if (kioc
->status
== -ENODATA
) {
729 con_log(CL_ANN
, (KERN_WARNING
730 "megaraid cmm: lld didn't change status!\n"));
732 kioc
->status
= -EINVAL
;
736 * Check if this kioc was timedout before. If so, nobody is waiting
737 * on this kioc. We don't have to wake up anybody. Instead, we just
738 * have to free the kioc
740 if (kioc
->timedout
) {
743 adapno
= kioc
->adapno
;
745 con_log(CL_ANN
, ( KERN_WARNING
"megaraid cmm: completed "
746 "ioctl that was timedout before\n"));
748 list_for_each_entry(adapter
, &adapters_list_g
, list
) {
749 if (iterator
++ == adapno
) break;
755 mraid_mm_dealloc_kioc( adapter
, kioc
);
765 * lld_timedout - callback from the expired timer
766 * @ptr : ioctl packet that timed out
769 lld_timedout(unsigned long ptr
)
771 uioc_t
*kioc
= (uioc_t
*)ptr
;
773 kioc
->status
= -ETIME
;
776 con_log(CL_ANN
, (KERN_WARNING
"megaraid cmm: ioctl timed out\n"));
783 * kioc_to_mimd - Converter from new back to old format
784 * @kioc : Kernel space IOCTL packet (successfully issued)
785 * @mimd : User space MIMD packet
788 kioc_to_mimd(uioc_t
*kioc
, mimd_t __user
*mimd
)
795 mraid_passthru_t __user
*upthru32
;
796 mraid_passthru_t
*kpthru32
;
798 mraid_hba_info_t
*hinfo
;
801 if (copy_from_user(&kmimd
, mimd
, sizeof(mimd_t
)))
804 opcode
= kmimd
.ui
.fcs
.opcode
;
805 subopcode
= kmimd
.ui
.fcs
.subopcode
;
807 if (opcode
== 0x82) {
810 case MEGAIOC_QADAPINFO
:
812 hinfo
= (mraid_hba_info_t
*)(unsigned long)
815 hinfo_to_cinfo(hinfo
, &cinfo
);
817 if (copy_to_user(kmimd
.data
, &cinfo
, sizeof(cinfo
)))
829 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
831 if (kioc
->user_pthru
) {
833 upthru32
= kioc
->user_pthru
;
834 kpthru32
= kioc
->pthru32
;
836 if (copy_to_user(&upthru32
->scsistatus
,
837 &kpthru32
->scsistatus
,
843 if (kioc
->user_data
) {
844 if (copy_to_user(kioc
->user_data
, kioc
->buf_vaddr
,
845 kioc
->user_data_len
)) {
850 if (copy_to_user(&mimd
->mbox
[17],
851 &mbox64
->mbox32
.status
, sizeof(uint8_t))) {
860 * hinfo_to_cinfo - Convert new format hba info into old format
861 * @hinfo : New format, more comprehensive adapter info
862 * @cinfo : Old format adapter info to support mimd_t apps
865 hinfo_to_cinfo(mraid_hba_info_t
*hinfo
, mcontroller_t
*cinfo
)
867 if (!hinfo
|| !cinfo
)
870 cinfo
->base
= hinfo
->baseport
;
871 cinfo
->irq
= hinfo
->irq
;
872 cinfo
->numldrv
= hinfo
->num_ldrv
;
873 cinfo
->pcibus
= hinfo
->pci_bus
;
874 cinfo
->pcidev
= hinfo
->pci_slot
;
875 cinfo
->pcifun
= PCI_FUNC(hinfo
->pci_dev_fn
);
876 cinfo
->pciid
= hinfo
->pci_device_id
;
877 cinfo
->pcivendor
= hinfo
->pci_vendor_id
;
878 cinfo
->pcislot
= hinfo
->pci_slot
;
879 cinfo
->uid
= hinfo
->unique_id
;
884 * mraid_mm_register_adp - Registration routine for low level drivers
885 * @lld_adp : Adapter objejct
888 mraid_mm_register_adp(mraid_mmadp_t
*lld_adp
)
890 mraid_mmadp_t
*adapter
;
897 if (lld_adp
->drvr_type
!= DRVRTYPE_MBOX
)
900 adapter
= kzalloc(sizeof(mraid_mmadp_t
), GFP_KERNEL
);
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", __func__
,
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 __func__
, __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 kfree(adapter
->kioc_list
);
997 kfree(adapter
->mbox_list
);
999 if (adapter
->pthru_dma_pool
)
1000 pci_pool_destroy(adapter
->pthru_dma_pool
);
1009 * mraid_mm_adapter_app_handle - return the application handle for this adapter
1010 * @unique_id : adapter unique identifier
1012 * For the given driver data, locate the adapter in our global list and
1013 * return the corresponding handle, which is also used by applications to
1014 * uniquely identify an adapter.
1016 * Return adapter handle if found in the list.
1017 * Return 0 if adapter could not be located, should never happen though.
1020 mraid_mm_adapter_app_handle(uint32_t unique_id
)
1022 mraid_mmadp_t
*adapter
;
1026 list_for_each_entry_safe(adapter
, tmp
, &adapters_list_g
, list
) {
1028 if (adapter
->unique_id
== unique_id
) {
1030 return MKADAP(index
);
1041 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1042 * @adp : Adapter softstate
1044 * We maintain a pool of dma buffers per each adapter. Each pool has one
1045 * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
1046 * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
1047 * dont' want to waste too much memory by allocating more buffers per each
1051 mraid_mm_setup_dma_pools(mraid_mmadp_t
*adp
)
1058 * Create MAX_DMA_POOLS number of pools
1060 bufsize
= MRAID_MM_INIT_BUFF_SIZE
;
1062 for (i
= 0; i
< MAX_DMA_POOLS
; i
++){
1064 pool
= &adp
->dma_pool_list
[i
];
1066 pool
->buf_size
= bufsize
;
1067 spin_lock_init(&pool
->lock
);
1069 pool
->handle
= pci_pool_create("megaraid mm data buffer",
1070 adp
->pdev
, bufsize
, 16, 0);
1072 if (!pool
->handle
) {
1073 goto dma_pool_setup_error
;
1076 pool
->vaddr
= pci_pool_alloc(pool
->handle
, GFP_KERNEL
,
1080 goto dma_pool_setup_error
;
1082 bufsize
= bufsize
* 2;
1087 dma_pool_setup_error
:
1089 mraid_mm_teardown_dma_pools(adp
);
1095 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1096 * @unique_id : UID of the adpater
1098 * Assumes no outstanding ioctls to llds.
1101 mraid_mm_unregister_adp(uint32_t unique_id
)
1103 mraid_mmadp_t
*adapter
;
1106 list_for_each_entry_safe(adapter
, tmp
, &adapters_list_g
, list
) {
1109 if (adapter
->unique_id
== unique_id
) {
1113 list_del_init(&adapter
->list
);
1115 mraid_mm_free_adp_resources(adapter
);
1120 "megaraid cmm: Unregistered one adapter:%#x\n",
1131 * mraid_mm_free_adp_resources - Free adapter softstate
1132 * @adp : Adapter softstate
1135 mraid_mm_free_adp_resources(mraid_mmadp_t
*adp
)
1140 mraid_mm_teardown_dma_pools(adp
);
1142 for (i
= 0; i
< adp
->max_kioc
; i
++) {
1144 kioc
= adp
->kioc_list
+ i
;
1146 pci_pool_free(adp
->pthru_dma_pool
, kioc
->pthru32
,
1150 kfree(adp
->kioc_list
);
1151 kfree(adp
->mbox_list
);
1153 pci_pool_destroy(adp
->pthru_dma_pool
);
1161 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1162 * @adp : Adapter softstate
1165 mraid_mm_teardown_dma_pools(mraid_mmadp_t
*adp
)
1170 for (i
= 0; i
< MAX_DMA_POOLS
; i
++) {
1172 pool
= &adp
->dma_pool_list
[i
];
1177 pci_pool_free(pool
->handle
, pool
->vaddr
,
1180 pci_pool_destroy(pool
->handle
);
1181 pool
->handle
= NULL
;
1189 * mraid_mm_init - Module entry point
1196 // Announce the driver version
1197 con_log(CL_ANN
, (KERN_INFO
"megaraid cmm: %s %s\n",
1198 LSI_COMMON_MOD_VERSION
, LSI_COMMON_MOD_EXT_VERSION
));
1200 err
= misc_register(&megaraid_mm_dev
);
1202 con_log(CL_ANN
, ("megaraid cmm: cannot register misc device\n"));
1206 init_waitqueue_head(&wait_q
);
1208 INIT_LIST_HEAD(&adapters_list_g
);
1214 #ifdef CONFIG_COMPAT
1216 * mraid_mm_compat_ioctl - 32bit to 64bit ioctl conversion routine
1217 * @filep : file operations pointer (ignored)
1218 * @cmd : ioctl command
1219 * @arg : user ioctl packet
1222 mraid_mm_compat_ioctl(struct file
*filep
, unsigned int cmd
,
1227 err
= mraid_mm_ioctl(NULL
, filep
, cmd
, arg
);
1234 * mraid_mm_exit - Module exit point
1239 con_log(CL_DLEVEL1
, ("exiting common mod\n"));
1241 misc_deregister(&megaraid_mm_dev
);
1244 module_init(mraid_mm_init
);
1245 module_exit(mraid_mm_exit
);
1247 /* vi: set ts=8 sw=8 tw=78: */