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"
19 #include <linux/smp_lock.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
);
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
,
75 .compat_ioctl
= mraid_mm_compat_ioctl
,
81 * mraid_mm_open - open routine for char node interface
85 * allow ioctl operations by apps only if they superuser privilege
88 mraid_mm_open(struct inode
*inode
, struct file
*filep
)
91 * Only allow superuser to access private ioctl interface
93 if (!capable(CAP_SYS_ADMIN
)) return (-EACCES
);
99 * mraid_mm_ioctl - module entry-point for ioctls
100 * @inode : inode (ignored)
101 * @filep : file operations pointer (ignored)
102 * @cmd : ioctl command
103 * @arg : user ioctl packet
106 mraid_mm_ioctl(struct inode
*inode
, struct file
*filep
, unsigned int cmd
,
110 char signature
[EXT_IOCTL_SIGN_SZ
] = {0};
115 void __user
*argp
= (void __user
*)arg
;
118 * Make sure only USCSICMD are issued through this interface.
119 * MIMD application would still fire different command.
122 if ((_IOC_TYPE(cmd
) != MEGAIOC_MAGIC
) && (cmd
!= USCSICMD
)) {
127 * Look for signature to see if this is the new or old ioctl format.
129 if (copy_from_user(signature
, argp
, EXT_IOCTL_SIGN_SZ
)) {
130 con_log(CL_ANN
, (KERN_WARNING
131 "megaraid cmm: copy from usr addr failed\n"));
135 if (memcmp(signature
, EXT_IOCTL_SIGN
, EXT_IOCTL_SIGN_SZ
) == 0)
141 * At present, we don't support the new ioctl packet
147 * If it is a driver ioctl (as opposed to fw ioctls), then we can
148 * handle the command locally. rval > 0 means it is not a drvr cmd
150 rval
= handle_drvrcmd(argp
, old_ioctl
, &drvrcmd_rval
);
158 if ((adp
= mraid_mm_get_adapter(argp
, &rval
)) == NULL
) {
163 * Check if adapter can accept ioctl. We may have marked it offline
164 * if any previous kioc had timedout on this controller.
166 if (!adp
->quiescent
) {
167 con_log(CL_ANN
, (KERN_WARNING
168 "megaraid cmm: controller cannot accept cmds due to "
169 "earlier errors\n" ));
174 * The following call will block till a kioc is available
176 kioc
= mraid_mm_alloc_kioc(adp
);
179 * User sent the old mimd_t ioctl packet. Convert it to uioc_t.
181 if ((rval
= mimd_to_kioc(argp
, adp
, kioc
))) {
182 mraid_mm_dealloc_kioc(adp
, kioc
);
186 kioc
->done
= ioctl_done
;
189 * Issue the IOCTL to the low level driver. After the IOCTL completes
190 * release the kioc if and only if it was _not_ timedout. If it was
191 * timedout, that means that resources are still with low level driver.
193 if ((rval
= lld_ioctl(adp
, kioc
))) {
196 mraid_mm_dealloc_kioc(adp
, kioc
);
202 * Convert the kioc back to user space
204 rval
= kioc_to_mimd(kioc
, argp
);
207 * Return the kioc to free pool
209 mraid_mm_dealloc_kioc(adp
, kioc
);
216 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
217 * @umimd : User space mimd_t ioctl packet
218 * @adapter : pointer to the adapter (OUT)
220 static mraid_mmadp_t
*
221 mraid_mm_get_adapter(mimd_t __user
*umimd
, int *rval
)
223 mraid_mmadp_t
*adapter
;
229 if (copy_from_user(&mimd
, umimd
, sizeof(mimd_t
))) {
234 adapno
= GETADAP(mimd
.ui
.fcs
.adapno
);
236 if (adapno
>= adapters_count_g
) {
244 list_for_each_entry(adapter
, &adapters_list_g
, list
) {
245 if (iterator
++ == adapno
) break;
257 * handle_drvrcmd - This routine checks if the opcode is a driver
258 * cmd and if it is, handles it.
259 * @arg : packet sent by the user app
260 * @old_ioctl : mimd if 1; uioc otherwise
263 handle_drvrcmd(void __user
*arg
, uint8_t old_ioctl
, int *rval
)
265 mimd_t __user
*umimd
;
282 if (copy_from_user(&kmimd
, umimd
, sizeof(mimd_t
)))
285 opcode
= kmimd
.ui
.fcs
.opcode
;
286 subopcode
= kmimd
.ui
.fcs
.subopcode
;
289 * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or
290 * GET_NUMADP, then we can handle. Otherwise we should return 1 to
291 * indicate that we cannot handle this.
298 case MEGAIOC_QDRVRVER
:
300 if (copy_to_user(kmimd
.data
, &drvr_ver
, sizeof(uint32_t)))
307 *rval
= adapters_count_g
;
309 if (copy_to_user(kmimd
.data
, &adapters_count_g
,
325 * mimd_to_kioc - Converter from old to new ioctl format
327 * @umimd : user space old MIMD IOCTL
328 * @kioc : kernel space new format IOCTL
330 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
331 * new packet is in kernel space so that driver can perform operations on it
336 mimd_to_kioc(mimd_t __user
*umimd
, mraid_mmadp_t
*adp
, uioc_t
*kioc
)
340 mraid_passthru_t
*pthru32
;
346 if (copy_from_user(&mimd
, umimd
, sizeof(mimd_t
)))
350 * Applications are not allowed to send extd pthru
352 if ((mimd
.mbox
[0] == MBOXCMD_PASSTHRU64
) ||
353 (mimd
.mbox
[0] == MBOXCMD_EXTPTHRU
))
356 opcode
= mimd
.ui
.fcs
.opcode
;
357 subopcode
= mimd
.ui
.fcs
.subopcode
;
358 adapno
= GETADAP(mimd
.ui
.fcs
.adapno
);
360 if (adapno
>= adapters_count_g
)
363 kioc
->adapno
= adapno
;
364 kioc
->mb_type
= MBOX_LEGACY
;
365 kioc
->app_type
= APPTYPE_MIMD
;
371 if (subopcode
== MEGAIOC_QADAPINFO
) {
373 kioc
->opcode
= GET_ADAP_INFO
;
374 kioc
->data_dir
= UIOC_RD
;
375 kioc
->xferlen
= sizeof(mraid_hba_info_t
);
377 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
381 con_log(CL_ANN
, (KERN_WARNING
382 "megaraid cmm: Invalid subop\n"));
390 kioc
->opcode
= MBOX_CMD
;
391 kioc
->xferlen
= mimd
.ui
.fcs
.length
;
392 kioc
->user_data_len
= kioc
->xferlen
;
393 kioc
->user_data
= mimd
.ui
.fcs
.buffer
;
395 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
398 if (mimd
.outlen
) kioc
->data_dir
= UIOC_RD
;
399 if (mimd
.inlen
) kioc
->data_dir
|= UIOC_WR
;
405 kioc
->opcode
= MBOX_CMD
;
406 kioc
->xferlen
= (mimd
.outlen
> mimd
.inlen
) ?
407 mimd
.outlen
: mimd
.inlen
;
408 kioc
->user_data_len
= kioc
->xferlen
;
409 kioc
->user_data
= mimd
.data
;
411 if (mraid_mm_attach_buf(adp
, kioc
, kioc
->xferlen
))
414 if (mimd
.outlen
) kioc
->data_dir
= UIOC_RD
;
415 if (mimd
.inlen
) kioc
->data_dir
|= UIOC_WR
;
424 * If driver command, nothing else to do
430 * This is a mailbox cmd; copy the mailbox from mimd
432 mbox64
= (mbox64_t
*)((unsigned long)kioc
->cmdbuf
);
433 mbox
= &mbox64
->mbox32
;
434 memcpy(mbox
, mimd
.mbox
, 14);
436 if (mbox
->cmd
!= MBOXCMD_PASSTHRU
) { // regular DCMD
438 mbox
->xferaddr
= (uint32_t)kioc
->buf_paddr
;
440 if (kioc
->data_dir
& UIOC_WR
) {
441 if (copy_from_user(kioc
->buf_vaddr
, kioc
->user_data
,
451 * This is a regular 32-bit pthru cmd; mbox points to pthru struct.
452 * Just like in above case, the beginning for memblk is treated as
453 * a mailbox. The passthru will begin at next 1K boundary. And the
454 * data will start 1K after that.
456 pthru32
= kioc
->pthru32
;
457 kioc
->user_pthru
= &umimd
->pthru
;
458 mbox
->xferaddr
= (uint32_t)kioc
->pthru32_h
;
460 if (copy_from_user(pthru32
, kioc
->user_pthru
,
461 sizeof(mraid_passthru_t
))) {
465 pthru32
->dataxferaddr
= kioc
->buf_paddr
;
466 if (kioc
->data_dir
& UIOC_WR
) {
467 if (copy_from_user(kioc
->buf_vaddr
, kioc
->user_data
,
468 pthru32
->dataxferlen
)) {
477 * mraid_mm_attch_buf - Attach a free dma buffer for required size
479 * @adp : Adapter softstate
480 * @kioc : kioc that the buffer needs to be attached to
481 * @xferlen : required length for buffer
483 * First we search for a pool with smallest buffer that is >= @xferlen. If
484 * that pool has no free buffer, we will try for the next bigger size. If none
485 * is available, we will try to allocate the smallest buffer that is >=
486 * @xferlen and attach it the pool.
489 mraid_mm_attach_buf(mraid_mmadp_t
*adp
, uioc_t
*kioc
, int xferlen
)
496 kioc
->pool_index
= -1;
497 kioc
->buf_vaddr
= NULL
;
502 * We need xferlen amount of memory. See if we can get it from our
503 * dma pools. If we don't get exact size, we will try bigger buffer
506 for (i
= 0; i
< MAX_DMA_POOLS
; i
++) {
508 pool
= &adp
->dma_pool_list
[i
];
510 if (xferlen
> pool
->buf_size
)
513 if (right_pool
== -1)
516 spin_lock_irqsave(&pool
->lock
, flags
);
521 kioc
->pool_index
= i
;
522 kioc
->buf_vaddr
= pool
->vaddr
;
523 kioc
->buf_paddr
= pool
->paddr
;
525 spin_unlock_irqrestore(&pool
->lock
, flags
);
529 spin_unlock_irqrestore(&pool
->lock
, flags
);
535 * If xferlen doesn't match any of our pools, return error
537 if (right_pool
== -1)
541 * We did not get any buffer from the preallocated pool. Let us try
542 * to allocate one new buffer. NOTE: This is a blocking call.
544 pool
= &adp
->dma_pool_list
[right_pool
];
546 spin_lock_irqsave(&pool
->lock
, flags
);
548 kioc
->pool_index
= right_pool
;
550 kioc
->buf_vaddr
= pci_pool_alloc(pool
->handle
, GFP_KERNEL
,
552 spin_unlock_irqrestore(&pool
->lock
, flags
);
554 if (!kioc
->buf_vaddr
)
561 * mraid_mm_alloc_kioc - Returns a uioc_t from free list
562 * @adp : Adapter softstate for this module
564 * The kioc_semaphore is initialized with number of kioc nodes in the
565 * free kioc pool. If the kioc pool is empty, this function blocks till
566 * a kioc becomes free.
569 mraid_mm_alloc_kioc(mraid_mmadp_t
*adp
)
572 struct list_head
* head
;
575 down(&adp
->kioc_semaphore
);
577 spin_lock_irqsave(&adp
->kioc_pool_lock
, flags
);
579 head
= &adp
->kioc_pool
;
581 if (list_empty(head
)) {
582 up(&adp
->kioc_semaphore
);
583 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
585 con_log(CL_ANN
, ("megaraid cmm: kioc list empty!\n"));
589 kioc
= list_entry(head
->next
, uioc_t
, list
);
590 list_del_init(&kioc
->list
);
592 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
594 memset((caddr_t
)(unsigned long)kioc
->cmdbuf
, 0, sizeof(mbox64_t
));
595 memset((caddr_t
) kioc
->pthru32
, 0, sizeof(mraid_passthru_t
));
597 kioc
->buf_vaddr
= NULL
;
599 kioc
->pool_index
=-1;
601 kioc
->user_data
= NULL
;
602 kioc
->user_data_len
= 0;
603 kioc
->user_pthru
= NULL
;
610 * mraid_mm_dealloc_kioc - Return kioc to free pool
612 * @adp : Adapter softstate
613 * @kioc : uioc_t node to be returned to free pool
616 mraid_mm_dealloc_kioc(mraid_mmadp_t
*adp
, uioc_t
*kioc
)
621 if (kioc
->pool_index
!= -1) {
622 pool
= &adp
->dma_pool_list
[kioc
->pool_index
];
624 /* This routine may be called in non-isr context also */
625 spin_lock_irqsave(&pool
->lock
, flags
);
628 * While attaching the dma buffer, if we didn't get the
629 * required buffer from the pool, we would have allocated
630 * it at the run time and set the free_buf flag. We must
631 * free that buffer. Otherwise, just mark that the buffer is
634 if (kioc
->free_buf
== 1)
635 pci_pool_free(pool
->handle
, kioc
->buf_vaddr
,
640 spin_unlock_irqrestore(&pool
->lock
, flags
);
643 /* Return the kioc to the free pool */
644 spin_lock_irqsave(&adp
->kioc_pool_lock
, flags
);
645 list_add(&kioc
->list
, &adp
->kioc_pool
);
646 spin_unlock_irqrestore(&adp
->kioc_pool_lock
, flags
);
648 /* increment the free kioc count */
649 up(&adp
->kioc_semaphore
);
655 * lld_ioctl - Routine to issue ioctl to low level drvr
657 * @adp : The adapter handle
658 * @kioc : The ioctl packet with kernel addresses
661 lld_ioctl(mraid_mmadp_t
*adp
, uioc_t
*kioc
)
664 struct timer_list timer
;
665 struct timer_list
*tp
= NULL
;
667 kioc
->status
= -ENODATA
;
668 rval
= adp
->issue_uioc(adp
->drvr_data
, kioc
, IOCTL_ISSUE
);
670 if (rval
) return rval
;
675 if (adp
->timeout
> 0) {
679 tp
->function
= lld_timedout
;
680 tp
->data
= (unsigned long)kioc
;
681 tp
->expires
= jiffies
+ adp
->timeout
* HZ
;
687 * Wait till the low level driver completes the ioctl. After this
688 * call, the ioctl either completed successfully or timedout.
690 wait_event(wait_q
, (kioc
->status
!= -ENODATA
));
696 * If the command had timedout, we mark the controller offline
699 if (kioc
->timedout
) {
708 * ioctl_done - callback from the low level driver
710 * @kioc : completed ioctl packet
713 ioctl_done(uioc_t
*kioc
)
717 mraid_mmadp_t
* adapter
;
720 * When the kioc returns from driver, make sure it still doesn't
721 * have ENODATA in status. Otherwise, driver will hang on wait_event
724 if (kioc
->status
== -ENODATA
) {
725 con_log(CL_ANN
, (KERN_WARNING
726 "megaraid cmm: lld didn't change status!\n"));
728 kioc
->status
= -EINVAL
;
732 * Check if this kioc was timedout before. If so, nobody is waiting
733 * on this kioc. We don't have to wake up anybody. Instead, we just
734 * have to free the kioc
736 if (kioc
->timedout
) {
739 adapno
= kioc
->adapno
;
741 con_log(CL_ANN
, ( KERN_WARNING
"megaraid cmm: completed "
742 "ioctl that was timedout before\n"));
744 list_for_each_entry(adapter
, &adapters_list_g
, list
) {
745 if (iterator
++ == adapno
) break;
751 mraid_mm_dealloc_kioc( adapter
, kioc
);
761 * lld_timedout : callback from the expired timer
763 * @ptr : ioctl packet that timed out
766 lld_timedout(unsigned long ptr
)
768 uioc_t
*kioc
= (uioc_t
*)ptr
;
770 kioc
->status
= -ETIME
;
773 con_log(CL_ANN
, (KERN_WARNING
"megaraid cmm: ioctl timed out\n"));
780 * kioc_to_mimd : Converter from new back to old format
782 * @kioc : Kernel space IOCTL packet (successfully issued)
783 * @mimd : User space MIMD packet
786 kioc_to_mimd(uioc_t
*kioc
, mimd_t __user
*mimd
)
793 mraid_passthru_t __user
*upthru32
;
794 mraid_passthru_t
*kpthru32
;
796 mraid_hba_info_t
*hinfo
;
799 if (copy_from_user(&kmimd
, mimd
, sizeof(mimd_t
)))
802 opcode
= kmimd
.ui
.fcs
.opcode
;
803 subopcode
= kmimd
.ui
.fcs
.subopcode
;
805 if (opcode
== 0x82) {
808 case MEGAIOC_QADAPINFO
:
810 hinfo
= (mraid_hba_info_t
*)(unsigned long)
813 hinfo_to_cinfo(hinfo
, &cinfo
);
815 if (copy_to_user(kmimd
.data
, &cinfo
, sizeof(cinfo
)))
827 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
829 if (kioc
->user_pthru
) {
831 upthru32
= kioc
->user_pthru
;
832 kpthru32
= kioc
->pthru32
;
834 if (copy_to_user(&upthru32
->scsistatus
,
835 &kpthru32
->scsistatus
,
841 if (kioc
->user_data
) {
842 if (copy_to_user(kioc
->user_data
, kioc
->buf_vaddr
,
843 kioc
->user_data_len
)) {
848 if (copy_to_user(&mimd
->mbox
[17],
849 &mbox64
->mbox32
.status
, sizeof(uint8_t))) {
858 * hinfo_to_cinfo - Convert new format hba info into old format
860 * @hinfo : New format, more comprehensive adapter info
861 * @cinfo : Old format adapter info to support mimd_t apps
864 hinfo_to_cinfo(mraid_hba_info_t
*hinfo
, mcontroller_t
*cinfo
)
866 if (!hinfo
|| !cinfo
)
869 cinfo
->base
= hinfo
->baseport
;
870 cinfo
->irq
= hinfo
->irq
;
871 cinfo
->numldrv
= hinfo
->num_ldrv
;
872 cinfo
->pcibus
= hinfo
->pci_bus
;
873 cinfo
->pcidev
= hinfo
->pci_slot
;
874 cinfo
->pcifun
= PCI_FUNC(hinfo
->pci_dev_fn
);
875 cinfo
->pciid
= hinfo
->pci_device_id
;
876 cinfo
->pcivendor
= hinfo
->pci_vendor_id
;
877 cinfo
->pcislot
= hinfo
->pci_slot
;
878 cinfo
->uid
= hinfo
->unique_id
;
883 * mraid_mm_register_adp - Registration routine for low level drvrs
885 * @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
= kmalloc(sizeof(mraid_mmadp_t
), GFP_KERNEL
);
907 memset(adapter
, 0, sizeof(mraid_mmadp_t
));
909 adapter
->unique_id
= lld_adp
->unique_id
;
910 adapter
->drvr_type
= lld_adp
->drvr_type
;
911 adapter
->drvr_data
= lld_adp
->drvr_data
;
912 adapter
->pdev
= lld_adp
->pdev
;
913 adapter
->issue_uioc
= lld_adp
->issue_uioc
;
914 adapter
->timeout
= lld_adp
->timeout
;
915 adapter
->max_kioc
= lld_adp
->max_kioc
;
916 adapter
->quiescent
= 1;
919 * Allocate single blocks of memory for all required kiocs,
920 * mailboxes and passthru structures.
922 adapter
->kioc_list
= kmalloc(sizeof(uioc_t
) * lld_adp
->max_kioc
,
924 adapter
->mbox_list
= kmalloc(sizeof(mbox64_t
) * lld_adp
->max_kioc
,
926 adapter
->pthru_dma_pool
= pci_pool_create("megaraid mm pthru pool",
928 sizeof(mraid_passthru_t
),
931 if (!adapter
->kioc_list
|| !adapter
->mbox_list
||
932 !adapter
->pthru_dma_pool
) {
934 con_log(CL_ANN
, (KERN_WARNING
935 "megaraid cmm: out of memory, %s %d\n", __FUNCTION__
,
944 * Slice kioc_list and make a kioc_pool with the individiual kiocs
946 INIT_LIST_HEAD(&adapter
->kioc_pool
);
947 spin_lock_init(&adapter
->kioc_pool_lock
);
948 sema_init(&adapter
->kioc_semaphore
, lld_adp
->max_kioc
);
950 mbox_list
= (mbox64_t
*)adapter
->mbox_list
;
952 for (i
= 0; i
< lld_adp
->max_kioc
; i
++) {
954 kioc
= adapter
->kioc_list
+ i
;
955 kioc
->cmdbuf
= (uint64_t)(unsigned long)(mbox_list
+ i
);
956 kioc
->pthru32
= pci_pool_alloc(adapter
->pthru_dma_pool
,
957 GFP_KERNEL
, &kioc
->pthru32_h
);
959 if (!kioc
->pthru32
) {
961 con_log(CL_ANN
, (KERN_WARNING
962 "megaraid cmm: out of memory, %s %d\n",
963 __FUNCTION__
, __LINE__
));
967 goto pthru_dma_pool_error
;
970 list_add_tail(&kioc
->list
, &adapter
->kioc_pool
);
973 // Setup the dma pools for data buffers
974 if ((rval
= mraid_mm_setup_dma_pools(adapter
)) != 0) {
978 list_add_tail(&adapter
->list
, &adapters_list_g
);
987 pthru_dma_pool_error
:
989 for (i
= 0; i
< lld_adp
->max_kioc
; i
++) {
990 kioc
= adapter
->kioc_list
+ i
;
992 pci_pool_free(adapter
->pthru_dma_pool
, kioc
->pthru32
,
999 if (adapter
->kioc_list
)
1000 kfree(adapter
->kioc_list
);
1002 if (adapter
->mbox_list
)
1003 kfree(adapter
->mbox_list
);
1005 if (adapter
->pthru_dma_pool
)
1006 pci_pool_destroy(adapter
->pthru_dma_pool
);
1016 * mraid_mm_adapter_app_handle - return the application handle for this adapter
1018 * For the given driver data, locate the adadpter in our global list and
1019 * return the corresponding handle, which is also used by applications to
1020 * uniquely identify an adapter.
1022 * @param unique_id : adapter unique identifier
1024 * @return adapter handle if found in the list
1025 * @return 0 if adapter could not be located, should never happen though
1028 mraid_mm_adapter_app_handle(uint32_t unique_id
)
1030 mraid_mmadp_t
*adapter
;
1034 list_for_each_entry_safe(adapter
, tmp
, &adapters_list_g
, list
) {
1036 if (adapter
->unique_id
== unique_id
) {
1038 return MKADAP(index
);
1049 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1051 * @adp : Adapter softstate
1053 * We maintain a pool of dma buffers per each adapter. Each pool has one
1054 * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers.
1055 * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We
1056 * dont' want to waste too much memory by allocating more buffers per each
1060 mraid_mm_setup_dma_pools(mraid_mmadp_t
*adp
)
1067 * Create MAX_DMA_POOLS number of pools
1069 bufsize
= MRAID_MM_INIT_BUFF_SIZE
;
1071 for (i
= 0; i
< MAX_DMA_POOLS
; i
++){
1073 pool
= &adp
->dma_pool_list
[i
];
1075 pool
->buf_size
= bufsize
;
1076 spin_lock_init(&pool
->lock
);
1078 pool
->handle
= pci_pool_create("megaraid mm data buffer",
1079 adp
->pdev
, bufsize
, 16, 0);
1081 if (!pool
->handle
) {
1082 goto dma_pool_setup_error
;
1085 pool
->vaddr
= pci_pool_alloc(pool
->handle
, GFP_KERNEL
,
1089 goto dma_pool_setup_error
;
1091 bufsize
= bufsize
* 2;
1096 dma_pool_setup_error
:
1098 mraid_mm_teardown_dma_pools(adp
);
1104 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1105 * Assume no outstanding ioctls to llds.
1107 * @unique_id : UID of the adpater
1110 mraid_mm_unregister_adp(uint32_t unique_id
)
1112 mraid_mmadp_t
*adapter
;
1115 list_for_each_entry_safe(adapter
, tmp
, &adapters_list_g
, list
) {
1118 if (adapter
->unique_id
== unique_id
) {
1122 list_del_init(&adapter
->list
);
1124 mraid_mm_free_adp_resources(adapter
);
1129 "megaraid cmm: Unregistered one adapter:%#x\n",
1140 * mraid_mm_free_adp_resources - Free adapter softstate
1142 * @adp : Adapter softstate
1145 mraid_mm_free_adp_resources(mraid_mmadp_t
*adp
)
1150 mraid_mm_teardown_dma_pools(adp
);
1152 for (i
= 0; i
< adp
->max_kioc
; i
++) {
1154 kioc
= adp
->kioc_list
+ i
;
1156 pci_pool_free(adp
->pthru_dma_pool
, kioc
->pthru32
,
1160 kfree(adp
->kioc_list
);
1162 kfree(adp
->mbox_list
);
1164 pci_pool_destroy(adp
->pthru_dma_pool
);
1172 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1174 * @adp : Adapter softstate
1177 mraid_mm_teardown_dma_pools(mraid_mmadp_t
*adp
)
1182 for (i
= 0; i
< MAX_DMA_POOLS
; i
++) {
1184 pool
= &adp
->dma_pool_list
[i
];
1189 pci_pool_free(pool
->handle
, pool
->vaddr
,
1192 pci_pool_destroy(pool
->handle
);
1193 pool
->handle
= NULL
;
1201 * mraid_mm_init : Module entry point
1206 // Announce the driver version
1207 con_log(CL_ANN
, (KERN_INFO
"megaraid cmm: %s %s\n",
1208 LSI_COMMON_MOD_VERSION
, LSI_COMMON_MOD_EXT_VERSION
));
1210 majorno
= register_chrdev(0, "megadev", &lsi_fops
);
1213 con_log(CL_ANN
, ("megaraid cmm: cannot get major\n"));
1217 init_waitqueue_head(&wait_q
);
1219 INIT_LIST_HEAD(&adapters_list_g
);
1226 * mraid_mm_compat_ioctl : 32bit to 64bit ioctl conversion routine
1228 #ifdef CONFIG_COMPAT
1230 mraid_mm_compat_ioctl(struct file
*filep
, unsigned int cmd
,
1235 err
= mraid_mm_ioctl(NULL
, filep
, cmd
, arg
);
1242 * mraid_mm_exit : Module exit point
1247 con_log(CL_DLEVEL1
, ("exiting common mod\n"));
1249 unregister_chrdev(majorno
, "megadev");
1252 module_init(mraid_mm_init
);
1253 module_exit(mraid_mm_exit
);
1255 /* vi: set ts=8 sw=8 tw=78: */