11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * 31da177e4SLinus Torvalds * Linux MegaRAID device driver 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (c) 2003-2004 LSI Logic Corporation. 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 81da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 91da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 101da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 111da177e4SLinus Torvalds * 121da177e4SLinus Torvalds * FILE : megaraid_mm.c 130b4972d5SJu, Seokmann * Version : v2.20.2.7 (Jul 16 2006) 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * Common management module 161da177e4SLinus Torvalds */ 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds #include "megaraid_mm.h" 191da177e4SLinus Torvalds 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds // Entry points for char node driver 221da177e4SLinus Torvalds static int mraid_mm_open(struct inode *, struct file *); 231da177e4SLinus Torvalds static int mraid_mm_ioctl(struct inode *, struct file *, uint, unsigned long); 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds // routines to convert to and from the old the format 271da177e4SLinus Torvalds static int mimd_to_kioc(mimd_t __user *, mraid_mmadp_t *, uioc_t *); 281da177e4SLinus Torvalds static int kioc_to_mimd(uioc_t *, mimd_t __user *); 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds // Helper functions 321da177e4SLinus Torvalds static int handle_drvrcmd(void __user *, uint8_t, int *); 331da177e4SLinus Torvalds static int lld_ioctl(mraid_mmadp_t *, uioc_t *); 341da177e4SLinus Torvalds static void ioctl_done(uioc_t *); 351da177e4SLinus Torvalds static void lld_timedout(unsigned long); 361da177e4SLinus Torvalds static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *); 371da177e4SLinus Torvalds static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *); 381da177e4SLinus Torvalds static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *); 391da177e4SLinus Torvalds static void mraid_mm_dealloc_kioc(mraid_mmadp_t *, uioc_t *); 401da177e4SLinus Torvalds static int mraid_mm_attach_buf(mraid_mmadp_t *, uioc_t *, int); 411da177e4SLinus Torvalds static int mraid_mm_setup_dma_pools(mraid_mmadp_t *); 421da177e4SLinus Torvalds static void mraid_mm_free_adp_resources(mraid_mmadp_t *); 431da177e4SLinus Torvalds static void mraid_mm_teardown_dma_pools(mraid_mmadp_t *); 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds #ifdef CONFIG_COMPAT 461da177e4SLinus Torvalds static long mraid_mm_compat_ioctl(struct file *, unsigned int, unsigned long); 471da177e4SLinus Torvalds #endif 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds MODULE_AUTHOR("LSI Logic Corporation"); 501da177e4SLinus Torvalds MODULE_DESCRIPTION("LSI Logic Management Module"); 511da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 521da177e4SLinus Torvalds MODULE_VERSION(LSI_COMMON_MOD_VERSION); 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static int dbglevel = CL_ANN; 551da177e4SLinus Torvalds module_param_named(dlevel, dbglevel, int, 0); 561da177e4SLinus Torvalds MODULE_PARM_DESC(dlevel, "Debug level (default=0)"); 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds EXPORT_SYMBOL(mraid_mm_register_adp); 591da177e4SLinus Torvalds EXPORT_SYMBOL(mraid_mm_unregister_adp); 601da177e4SLinus Torvalds EXPORT_SYMBOL(mraid_mm_adapter_app_handle); 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static int majorno; 63672b2d38SJu, Seokmann static uint32_t drvr_ver = 0x02200206; 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds static int adapters_count_g; 661da177e4SLinus Torvalds static struct list_head adapters_list_g; 671da177e4SLinus Torvalds 681da177e4SLinus Torvalds static wait_queue_head_t wait_q; 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds static struct file_operations lsi_fops = { 711da177e4SLinus Torvalds .open = mraid_mm_open, 721da177e4SLinus Torvalds .ioctl = mraid_mm_ioctl, 731da177e4SLinus Torvalds #ifdef CONFIG_COMPAT 741da177e4SLinus Torvalds .compat_ioctl = mraid_mm_compat_ioctl, 751da177e4SLinus Torvalds #endif 761da177e4SLinus Torvalds .owner = THIS_MODULE, 771da177e4SLinus Torvalds }; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds /** 801da177e4SLinus Torvalds * mraid_mm_open - open routine for char node interface 81*a69b74d3SRandy Dunlap * @inode : unused 821da177e4SLinus Torvalds * @filep : unused 831da177e4SLinus Torvalds * 84*a69b74d3SRandy Dunlap * Allow ioctl operations by apps only if they have superuser privilege. 851da177e4SLinus Torvalds */ 861da177e4SLinus Torvalds static int 871da177e4SLinus Torvalds mraid_mm_open(struct inode *inode, struct file *filep) 881da177e4SLinus Torvalds { 891da177e4SLinus Torvalds /* 901da177e4SLinus Torvalds * Only allow superuser to access private ioctl interface 911da177e4SLinus Torvalds */ 921da177e4SLinus Torvalds if (!capable(CAP_SYS_ADMIN)) return (-EACCES); 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds return 0; 951da177e4SLinus Torvalds } 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds /** 981da177e4SLinus Torvalds * mraid_mm_ioctl - module entry-point for ioctls 991da177e4SLinus Torvalds * @inode : inode (ignored) 1001da177e4SLinus Torvalds * @filep : file operations pointer (ignored) 1011da177e4SLinus Torvalds * @cmd : ioctl command 1021da177e4SLinus Torvalds * @arg : user ioctl packet 1031da177e4SLinus Torvalds */ 1041da177e4SLinus Torvalds static int 1051da177e4SLinus Torvalds mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, 1061da177e4SLinus Torvalds unsigned long arg) 1071da177e4SLinus Torvalds { 1081da177e4SLinus Torvalds uioc_t *kioc; 1091da177e4SLinus Torvalds char signature[EXT_IOCTL_SIGN_SZ] = {0}; 1101da177e4SLinus Torvalds int rval; 1111da177e4SLinus Torvalds mraid_mmadp_t *adp; 1121da177e4SLinus Torvalds uint8_t old_ioctl; 1131da177e4SLinus Torvalds int drvrcmd_rval; 1141da177e4SLinus Torvalds void __user *argp = (void __user *)arg; 1151da177e4SLinus Torvalds 1161da177e4SLinus Torvalds /* 1171da177e4SLinus Torvalds * Make sure only USCSICMD are issued through this interface. 1181da177e4SLinus Torvalds * MIMD application would still fire different command. 1191da177e4SLinus Torvalds */ 1201da177e4SLinus Torvalds 1211da177e4SLinus Torvalds if ((_IOC_TYPE(cmd) != MEGAIOC_MAGIC) && (cmd != USCSICMD)) { 1221da177e4SLinus Torvalds return (-EINVAL); 1231da177e4SLinus Torvalds } 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds /* 1261da177e4SLinus Torvalds * Look for signature to see if this is the new or old ioctl format. 1271da177e4SLinus Torvalds */ 1281da177e4SLinus Torvalds if (copy_from_user(signature, argp, EXT_IOCTL_SIGN_SZ)) { 1291da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING 1301da177e4SLinus Torvalds "megaraid cmm: copy from usr addr failed\n")); 1311da177e4SLinus Torvalds return (-EFAULT); 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds if (memcmp(signature, EXT_IOCTL_SIGN, EXT_IOCTL_SIGN_SZ) == 0) 1351da177e4SLinus Torvalds old_ioctl = 0; 1361da177e4SLinus Torvalds else 1371da177e4SLinus Torvalds old_ioctl = 1; 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds /* 1401da177e4SLinus Torvalds * At present, we don't support the new ioctl packet 1411da177e4SLinus Torvalds */ 1421da177e4SLinus Torvalds if (!old_ioctl ) 1431da177e4SLinus Torvalds return (-EINVAL); 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds /* 1461da177e4SLinus Torvalds * If it is a driver ioctl (as opposed to fw ioctls), then we can 1471da177e4SLinus Torvalds * handle the command locally. rval > 0 means it is not a drvr cmd 1481da177e4SLinus Torvalds */ 1491da177e4SLinus Torvalds rval = handle_drvrcmd(argp, old_ioctl, &drvrcmd_rval); 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds if (rval < 0) 1521da177e4SLinus Torvalds return rval; 1531da177e4SLinus Torvalds else if (rval == 0) 1541da177e4SLinus Torvalds return drvrcmd_rval; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds rval = 0; 1571da177e4SLinus Torvalds if ((adp = mraid_mm_get_adapter(argp, &rval)) == NULL) { 1581da177e4SLinus Torvalds return rval; 1591da177e4SLinus Torvalds } 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds /* 1621da177e4SLinus Torvalds * Check if adapter can accept ioctl. We may have marked it offline 1631da177e4SLinus Torvalds * if any previous kioc had timedout on this controller. 1641da177e4SLinus Torvalds */ 1651da177e4SLinus Torvalds if (!adp->quiescent) { 1661da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING 1671da177e4SLinus Torvalds "megaraid cmm: controller cannot accept cmds due to " 1681da177e4SLinus Torvalds "earlier errors\n" )); 1691da177e4SLinus Torvalds return -EFAULT; 1701da177e4SLinus Torvalds } 1711da177e4SLinus Torvalds 1721da177e4SLinus Torvalds /* 1731da177e4SLinus Torvalds * The following call will block till a kioc is available 1741da177e4SLinus Torvalds */ 1751da177e4SLinus Torvalds kioc = mraid_mm_alloc_kioc(adp); 1761da177e4SLinus Torvalds 1771da177e4SLinus Torvalds /* 1781da177e4SLinus Torvalds * User sent the old mimd_t ioctl packet. Convert it to uioc_t. 1791da177e4SLinus Torvalds */ 1801da177e4SLinus Torvalds if ((rval = mimd_to_kioc(argp, adp, kioc))) { 1811da177e4SLinus Torvalds mraid_mm_dealloc_kioc(adp, kioc); 1821da177e4SLinus Torvalds return rval; 1831da177e4SLinus Torvalds } 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds kioc->done = ioctl_done; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds /* 1881da177e4SLinus Torvalds * Issue the IOCTL to the low level driver. After the IOCTL completes 1891da177e4SLinus Torvalds * release the kioc if and only if it was _not_ timedout. If it was 1901da177e4SLinus Torvalds * timedout, that means that resources are still with low level driver. 1911da177e4SLinus Torvalds */ 1921da177e4SLinus Torvalds if ((rval = lld_ioctl(adp, kioc))) { 1931da177e4SLinus Torvalds 1941da177e4SLinus Torvalds if (!kioc->timedout) 1951da177e4SLinus Torvalds mraid_mm_dealloc_kioc(adp, kioc); 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds return rval; 1981da177e4SLinus Torvalds } 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds /* 2011da177e4SLinus Torvalds * Convert the kioc back to user space 2021da177e4SLinus Torvalds */ 2031da177e4SLinus Torvalds rval = kioc_to_mimd(kioc, argp); 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds /* 2061da177e4SLinus Torvalds * Return the kioc to free pool 2071da177e4SLinus Torvalds */ 2081da177e4SLinus Torvalds mraid_mm_dealloc_kioc(adp, kioc); 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds return rval; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds 2141da177e4SLinus Torvalds /** 2151da177e4SLinus Torvalds * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet 2161da177e4SLinus Torvalds * @umimd : User space mimd_t ioctl packet 217*a69b74d3SRandy Dunlap * @rval : returned success/error status 218*a69b74d3SRandy Dunlap * 219*a69b74d3SRandy Dunlap * The function return value is a pointer to the located @adapter. 2201da177e4SLinus Torvalds */ 2211da177e4SLinus Torvalds static mraid_mmadp_t * 2221da177e4SLinus Torvalds mraid_mm_get_adapter(mimd_t __user *umimd, int *rval) 2231da177e4SLinus Torvalds { 2241da177e4SLinus Torvalds mraid_mmadp_t *adapter; 2251da177e4SLinus Torvalds mimd_t mimd; 2261da177e4SLinus Torvalds uint32_t adapno; 2271da177e4SLinus Torvalds int iterator; 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) { 2311da177e4SLinus Torvalds *rval = -EFAULT; 2321da177e4SLinus Torvalds return NULL; 2331da177e4SLinus Torvalds } 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds adapno = GETADAP(mimd.ui.fcs.adapno); 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds if (adapno >= adapters_count_g) { 2381da177e4SLinus Torvalds *rval = -ENODEV; 2391da177e4SLinus Torvalds return NULL; 2401da177e4SLinus Torvalds } 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds adapter = NULL; 2431da177e4SLinus Torvalds iterator = 0; 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds list_for_each_entry(adapter, &adapters_list_g, list) { 2461da177e4SLinus Torvalds if (iterator++ == adapno) break; 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds if (!adapter) { 2501da177e4SLinus Torvalds *rval = -ENODEV; 2511da177e4SLinus Torvalds return NULL; 2521da177e4SLinus Torvalds } 2531da177e4SLinus Torvalds 2541da177e4SLinus Torvalds return adapter; 2551da177e4SLinus Torvalds } 2561da177e4SLinus Torvalds 257*a69b74d3SRandy Dunlap /** 258*a69b74d3SRandy Dunlap * handle_drvrcmd - Checks if the opcode is a driver cmd and if it is, handles it. 2591da177e4SLinus Torvalds * @arg : packet sent by the user app 2601da177e4SLinus Torvalds * @old_ioctl : mimd if 1; uioc otherwise 261*a69b74d3SRandy Dunlap * @rval : pointer for command's returned value (not function status) 2621da177e4SLinus Torvalds */ 2631da177e4SLinus Torvalds static int 2641da177e4SLinus Torvalds handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval) 2651da177e4SLinus Torvalds { 2661da177e4SLinus Torvalds mimd_t __user *umimd; 2671da177e4SLinus Torvalds mimd_t kmimd; 2681da177e4SLinus Torvalds uint8_t opcode; 2691da177e4SLinus Torvalds uint8_t subopcode; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds if (old_ioctl) 2721da177e4SLinus Torvalds goto old_packet; 2731da177e4SLinus Torvalds else 2741da177e4SLinus Torvalds goto new_packet; 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds new_packet: 2771da177e4SLinus Torvalds return (-ENOTSUPP); 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds old_packet: 2801da177e4SLinus Torvalds *rval = 0; 2811da177e4SLinus Torvalds umimd = arg; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds if (copy_from_user(&kmimd, umimd, sizeof(mimd_t))) 2841da177e4SLinus Torvalds return (-EFAULT); 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds opcode = kmimd.ui.fcs.opcode; 2871da177e4SLinus Torvalds subopcode = kmimd.ui.fcs.subopcode; 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds /* 2901da177e4SLinus Torvalds * If the opcode is 0x82 and the subopcode is either GET_DRVRVER or 2911da177e4SLinus Torvalds * GET_NUMADP, then we can handle. Otherwise we should return 1 to 2921da177e4SLinus Torvalds * indicate that we cannot handle this. 2931da177e4SLinus Torvalds */ 2941da177e4SLinus Torvalds if (opcode != 0x82) 2951da177e4SLinus Torvalds return 1; 2961da177e4SLinus Torvalds 2971da177e4SLinus Torvalds switch (subopcode) { 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvalds case MEGAIOC_QDRVRVER: 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds if (copy_to_user(kmimd.data, &drvr_ver, sizeof(uint32_t))) 3021da177e4SLinus Torvalds return (-EFAULT); 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds return 0; 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds case MEGAIOC_QNADAP: 3071da177e4SLinus Torvalds 3081da177e4SLinus Torvalds *rval = adapters_count_g; 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds if (copy_to_user(kmimd.data, &adapters_count_g, 3111da177e4SLinus Torvalds sizeof(uint32_t))) 3121da177e4SLinus Torvalds return (-EFAULT); 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds return 0; 3151da177e4SLinus Torvalds 3161da177e4SLinus Torvalds default: 3171da177e4SLinus Torvalds /* cannot handle */ 3181da177e4SLinus Torvalds return 1; 3191da177e4SLinus Torvalds } 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds return 0; 3221da177e4SLinus Torvalds } 3231da177e4SLinus Torvalds 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds /** 3261da177e4SLinus Torvalds * mimd_to_kioc - Converter from old to new ioctl format 3271da177e4SLinus Torvalds * @umimd : user space old MIMD IOCTL 328*a69b74d3SRandy Dunlap * @adp : adapter softstate 3291da177e4SLinus Torvalds * @kioc : kernel space new format IOCTL 3301da177e4SLinus Torvalds * 3311da177e4SLinus Torvalds * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The 3321da177e4SLinus Torvalds * new packet is in kernel space so that driver can perform operations on it 3331da177e4SLinus Torvalds * freely. 3341da177e4SLinus Torvalds */ 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds static int 3371da177e4SLinus Torvalds mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, uioc_t *kioc) 3381da177e4SLinus Torvalds { 3391da177e4SLinus Torvalds mbox64_t *mbox64; 3401da177e4SLinus Torvalds mbox_t *mbox; 3411da177e4SLinus Torvalds mraid_passthru_t *pthru32; 3421da177e4SLinus Torvalds uint32_t adapno; 3431da177e4SLinus Torvalds uint8_t opcode; 3441da177e4SLinus Torvalds uint8_t subopcode; 3451da177e4SLinus Torvalds mimd_t mimd; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds if (copy_from_user(&mimd, umimd, sizeof(mimd_t))) 3481da177e4SLinus Torvalds return (-EFAULT); 3491da177e4SLinus Torvalds 3501da177e4SLinus Torvalds /* 3511da177e4SLinus Torvalds * Applications are not allowed to send extd pthru 3521da177e4SLinus Torvalds */ 3531da177e4SLinus Torvalds if ((mimd.mbox[0] == MBOXCMD_PASSTHRU64) || 3541da177e4SLinus Torvalds (mimd.mbox[0] == MBOXCMD_EXTPTHRU)) 3551da177e4SLinus Torvalds return (-EINVAL); 3561da177e4SLinus Torvalds 3571da177e4SLinus Torvalds opcode = mimd.ui.fcs.opcode; 3581da177e4SLinus Torvalds subopcode = mimd.ui.fcs.subopcode; 3591da177e4SLinus Torvalds adapno = GETADAP(mimd.ui.fcs.adapno); 3601da177e4SLinus Torvalds 3611da177e4SLinus Torvalds if (adapno >= adapters_count_g) 3621da177e4SLinus Torvalds return (-ENODEV); 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds kioc->adapno = adapno; 3651da177e4SLinus Torvalds kioc->mb_type = MBOX_LEGACY; 3661da177e4SLinus Torvalds kioc->app_type = APPTYPE_MIMD; 3671da177e4SLinus Torvalds 3681da177e4SLinus Torvalds switch (opcode) { 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds case 0x82: 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvalds if (subopcode == MEGAIOC_QADAPINFO) { 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds kioc->opcode = GET_ADAP_INFO; 3751da177e4SLinus Torvalds kioc->data_dir = UIOC_RD; 3761da177e4SLinus Torvalds kioc->xferlen = sizeof(mraid_hba_info_t); 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen)) 3791da177e4SLinus Torvalds return (-ENOMEM); 3801da177e4SLinus Torvalds } 3811da177e4SLinus Torvalds else { 3821da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING 3831da177e4SLinus Torvalds "megaraid cmm: Invalid subop\n")); 3841da177e4SLinus Torvalds return (-EINVAL); 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds break; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds case 0x81: 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds kioc->opcode = MBOX_CMD; 3921da177e4SLinus Torvalds kioc->xferlen = mimd.ui.fcs.length; 3931da177e4SLinus Torvalds kioc->user_data_len = kioc->xferlen; 3941da177e4SLinus Torvalds kioc->user_data = mimd.ui.fcs.buffer; 3951da177e4SLinus Torvalds 3961da177e4SLinus Torvalds if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen)) 3971da177e4SLinus Torvalds return (-ENOMEM); 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvalds if (mimd.outlen) kioc->data_dir = UIOC_RD; 4001da177e4SLinus Torvalds if (mimd.inlen) kioc->data_dir |= UIOC_WR; 4011da177e4SLinus Torvalds 4021da177e4SLinus Torvalds break; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvalds case 0x80: 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds kioc->opcode = MBOX_CMD; 4071da177e4SLinus Torvalds kioc->xferlen = (mimd.outlen > mimd.inlen) ? 4081da177e4SLinus Torvalds mimd.outlen : mimd.inlen; 4091da177e4SLinus Torvalds kioc->user_data_len = kioc->xferlen; 4101da177e4SLinus Torvalds kioc->user_data = mimd.data; 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvalds if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen)) 4131da177e4SLinus Torvalds return (-ENOMEM); 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds if (mimd.outlen) kioc->data_dir = UIOC_RD; 4161da177e4SLinus Torvalds if (mimd.inlen) kioc->data_dir |= UIOC_WR; 4171da177e4SLinus Torvalds 4181da177e4SLinus Torvalds break; 4191da177e4SLinus Torvalds 4201da177e4SLinus Torvalds default: 4211da177e4SLinus Torvalds return (-EINVAL); 4221da177e4SLinus Torvalds } 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvalds /* 4251da177e4SLinus Torvalds * If driver command, nothing else to do 4261da177e4SLinus Torvalds */ 4271da177e4SLinus Torvalds if (opcode == 0x82) 4281da177e4SLinus Torvalds return 0; 4291da177e4SLinus Torvalds 4301da177e4SLinus Torvalds /* 4311da177e4SLinus Torvalds * This is a mailbox cmd; copy the mailbox from mimd 4321da177e4SLinus Torvalds */ 4331da177e4SLinus Torvalds mbox64 = (mbox64_t *)((unsigned long)kioc->cmdbuf); 4341da177e4SLinus Torvalds mbox = &mbox64->mbox32; 4351da177e4SLinus Torvalds memcpy(mbox, mimd.mbox, 14); 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvalds if (mbox->cmd != MBOXCMD_PASSTHRU) { // regular DCMD 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds mbox->xferaddr = (uint32_t)kioc->buf_paddr; 4401da177e4SLinus Torvalds 4411da177e4SLinus Torvalds if (kioc->data_dir & UIOC_WR) { 4421da177e4SLinus Torvalds if (copy_from_user(kioc->buf_vaddr, kioc->user_data, 4431da177e4SLinus Torvalds kioc->xferlen)) { 4441da177e4SLinus Torvalds return (-EFAULT); 4451da177e4SLinus Torvalds } 4461da177e4SLinus Torvalds } 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvalds return 0; 4491da177e4SLinus Torvalds } 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvalds /* 4521da177e4SLinus Torvalds * This is a regular 32-bit pthru cmd; mbox points to pthru struct. 4531da177e4SLinus Torvalds * Just like in above case, the beginning for memblk is treated as 4541da177e4SLinus Torvalds * a mailbox. The passthru will begin at next 1K boundary. And the 4551da177e4SLinus Torvalds * data will start 1K after that. 4561da177e4SLinus Torvalds */ 4571da177e4SLinus Torvalds pthru32 = kioc->pthru32; 4581da177e4SLinus Torvalds kioc->user_pthru = &umimd->pthru; 4591da177e4SLinus Torvalds mbox->xferaddr = (uint32_t)kioc->pthru32_h; 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds if (copy_from_user(pthru32, kioc->user_pthru, 4621da177e4SLinus Torvalds sizeof(mraid_passthru_t))) { 4631da177e4SLinus Torvalds return (-EFAULT); 4641da177e4SLinus Torvalds } 4651da177e4SLinus Torvalds 4661da177e4SLinus Torvalds pthru32->dataxferaddr = kioc->buf_paddr; 4671da177e4SLinus Torvalds if (kioc->data_dir & UIOC_WR) { 4681da177e4SLinus Torvalds if (copy_from_user(kioc->buf_vaddr, kioc->user_data, 4691da177e4SLinus Torvalds pthru32->dataxferlen)) { 4701da177e4SLinus Torvalds return (-EFAULT); 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds return 0; 4751da177e4SLinus Torvalds } 4761da177e4SLinus Torvalds 4771da177e4SLinus Torvalds /** 4781da177e4SLinus Torvalds * mraid_mm_attch_buf - Attach a free dma buffer for required size 4791da177e4SLinus Torvalds * @adp : Adapter softstate 4801da177e4SLinus Torvalds * @kioc : kioc that the buffer needs to be attached to 4811da177e4SLinus Torvalds * @xferlen : required length for buffer 4821da177e4SLinus Torvalds * 4831da177e4SLinus Torvalds * First we search for a pool with smallest buffer that is >= @xferlen. If 4841da177e4SLinus Torvalds * that pool has no free buffer, we will try for the next bigger size. If none 4851da177e4SLinus Torvalds * is available, we will try to allocate the smallest buffer that is >= 4861da177e4SLinus Torvalds * @xferlen and attach it the pool. 4871da177e4SLinus Torvalds */ 4881da177e4SLinus Torvalds static int 4891da177e4SLinus Torvalds mraid_mm_attach_buf(mraid_mmadp_t *adp, uioc_t *kioc, int xferlen) 4901da177e4SLinus Torvalds { 4911da177e4SLinus Torvalds mm_dmapool_t *pool; 4921da177e4SLinus Torvalds int right_pool = -1; 4931da177e4SLinus Torvalds unsigned long flags; 4941da177e4SLinus Torvalds int i; 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds kioc->pool_index = -1; 4971da177e4SLinus Torvalds kioc->buf_vaddr = NULL; 4981da177e4SLinus Torvalds kioc->buf_paddr = 0; 4991da177e4SLinus Torvalds kioc->free_buf = 0; 5001da177e4SLinus Torvalds 5011da177e4SLinus Torvalds /* 5021da177e4SLinus Torvalds * We need xferlen amount of memory. See if we can get it from our 5031da177e4SLinus Torvalds * dma pools. If we don't get exact size, we will try bigger buffer 5041da177e4SLinus Torvalds */ 5051da177e4SLinus Torvalds 5061da177e4SLinus Torvalds for (i = 0; i < MAX_DMA_POOLS; i++) { 5071da177e4SLinus Torvalds 5081da177e4SLinus Torvalds pool = &adp->dma_pool_list[i]; 5091da177e4SLinus Torvalds 5101da177e4SLinus Torvalds if (xferlen > pool->buf_size) 5111da177e4SLinus Torvalds continue; 5121da177e4SLinus Torvalds 5131da177e4SLinus Torvalds if (right_pool == -1) 5141da177e4SLinus Torvalds right_pool = i; 5151da177e4SLinus Torvalds 5161da177e4SLinus Torvalds spin_lock_irqsave(&pool->lock, flags); 5171da177e4SLinus Torvalds 5181da177e4SLinus Torvalds if (!pool->in_use) { 5191da177e4SLinus Torvalds 5201da177e4SLinus Torvalds pool->in_use = 1; 5211da177e4SLinus Torvalds kioc->pool_index = i; 5221da177e4SLinus Torvalds kioc->buf_vaddr = pool->vaddr; 5231da177e4SLinus Torvalds kioc->buf_paddr = pool->paddr; 5241da177e4SLinus Torvalds 5251da177e4SLinus Torvalds spin_unlock_irqrestore(&pool->lock, flags); 5261da177e4SLinus Torvalds return 0; 5271da177e4SLinus Torvalds } 5281da177e4SLinus Torvalds else { 5291da177e4SLinus Torvalds spin_unlock_irqrestore(&pool->lock, flags); 5301da177e4SLinus Torvalds continue; 5311da177e4SLinus Torvalds } 5321da177e4SLinus Torvalds } 5331da177e4SLinus Torvalds 5341da177e4SLinus Torvalds /* 5351da177e4SLinus Torvalds * If xferlen doesn't match any of our pools, return error 5361da177e4SLinus Torvalds */ 5371da177e4SLinus Torvalds if (right_pool == -1) 5381da177e4SLinus Torvalds return -EINVAL; 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds /* 5411da177e4SLinus Torvalds * We did not get any buffer from the preallocated pool. Let us try 5421da177e4SLinus Torvalds * to allocate one new buffer. NOTE: This is a blocking call. 5431da177e4SLinus Torvalds */ 5441da177e4SLinus Torvalds pool = &adp->dma_pool_list[right_pool]; 5451da177e4SLinus Torvalds 5461da177e4SLinus Torvalds spin_lock_irqsave(&pool->lock, flags); 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds kioc->pool_index = right_pool; 5491da177e4SLinus Torvalds kioc->free_buf = 1; 5501da177e4SLinus Torvalds kioc->buf_vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL, 5511da177e4SLinus Torvalds &kioc->buf_paddr); 5521da177e4SLinus Torvalds spin_unlock_irqrestore(&pool->lock, flags); 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds if (!kioc->buf_vaddr) 5551da177e4SLinus Torvalds return -ENOMEM; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds return 0; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds 5601da177e4SLinus Torvalds /** 5611da177e4SLinus Torvalds * mraid_mm_alloc_kioc - Returns a uioc_t from free list 5621da177e4SLinus Torvalds * @adp : Adapter softstate for this module 5631da177e4SLinus Torvalds * 5641da177e4SLinus Torvalds * The kioc_semaphore is initialized with number of kioc nodes in the 5651da177e4SLinus Torvalds * free kioc pool. If the kioc pool is empty, this function blocks till 5661da177e4SLinus Torvalds * a kioc becomes free. 5671da177e4SLinus Torvalds */ 5681da177e4SLinus Torvalds static uioc_t * 5691da177e4SLinus Torvalds mraid_mm_alloc_kioc(mraid_mmadp_t *adp) 5701da177e4SLinus Torvalds { 5711da177e4SLinus Torvalds uioc_t *kioc; 5721da177e4SLinus Torvalds struct list_head* head; 5731da177e4SLinus Torvalds unsigned long flags; 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds down(&adp->kioc_semaphore); 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds spin_lock_irqsave(&adp->kioc_pool_lock, flags); 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds head = &adp->kioc_pool; 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds if (list_empty(head)) { 5821da177e4SLinus Torvalds up(&adp->kioc_semaphore); 5831da177e4SLinus Torvalds spin_unlock_irqrestore(&adp->kioc_pool_lock, flags); 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds con_log(CL_ANN, ("megaraid cmm: kioc list empty!\n")); 5861da177e4SLinus Torvalds return NULL; 5871da177e4SLinus Torvalds } 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds kioc = list_entry(head->next, uioc_t, list); 5901da177e4SLinus Torvalds list_del_init(&kioc->list); 5911da177e4SLinus Torvalds 5921da177e4SLinus Torvalds spin_unlock_irqrestore(&adp->kioc_pool_lock, flags); 5931da177e4SLinus Torvalds 5941da177e4SLinus Torvalds memset((caddr_t)(unsigned long)kioc->cmdbuf, 0, sizeof(mbox64_t)); 5951da177e4SLinus Torvalds memset((caddr_t) kioc->pthru32, 0, sizeof(mraid_passthru_t)); 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds kioc->buf_vaddr = NULL; 5981da177e4SLinus Torvalds kioc->buf_paddr = 0; 5991da177e4SLinus Torvalds kioc->pool_index =-1; 6001da177e4SLinus Torvalds kioc->free_buf = 0; 6011da177e4SLinus Torvalds kioc->user_data = NULL; 6021da177e4SLinus Torvalds kioc->user_data_len = 0; 6031da177e4SLinus Torvalds kioc->user_pthru = NULL; 6041da177e4SLinus Torvalds kioc->timedout = 0; 6051da177e4SLinus Torvalds 6061da177e4SLinus Torvalds return kioc; 6071da177e4SLinus Torvalds } 6081da177e4SLinus Torvalds 6091da177e4SLinus Torvalds /** 6101da177e4SLinus Torvalds * mraid_mm_dealloc_kioc - Return kioc to free pool 6111da177e4SLinus Torvalds * @adp : Adapter softstate 6121da177e4SLinus Torvalds * @kioc : uioc_t node to be returned to free pool 6131da177e4SLinus Torvalds */ 6141da177e4SLinus Torvalds static void 6151da177e4SLinus Torvalds mraid_mm_dealloc_kioc(mraid_mmadp_t *adp, uioc_t *kioc) 6161da177e4SLinus Torvalds { 6171da177e4SLinus Torvalds mm_dmapool_t *pool; 6181da177e4SLinus Torvalds unsigned long flags; 6191da177e4SLinus Torvalds 6201da177e4SLinus Torvalds if (kioc->pool_index != -1) { 6211da177e4SLinus Torvalds pool = &adp->dma_pool_list[kioc->pool_index]; 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds /* This routine may be called in non-isr context also */ 6241da177e4SLinus Torvalds spin_lock_irqsave(&pool->lock, flags); 6251da177e4SLinus Torvalds 6261da177e4SLinus Torvalds /* 6271da177e4SLinus Torvalds * While attaching the dma buffer, if we didn't get the 6281da177e4SLinus Torvalds * required buffer from the pool, we would have allocated 6291da177e4SLinus Torvalds * it at the run time and set the free_buf flag. We must 6301da177e4SLinus Torvalds * free that buffer. Otherwise, just mark that the buffer is 6311da177e4SLinus Torvalds * not in use 6321da177e4SLinus Torvalds */ 6331da177e4SLinus Torvalds if (kioc->free_buf == 1) 6341da177e4SLinus Torvalds pci_pool_free(pool->handle, kioc->buf_vaddr, 6351da177e4SLinus Torvalds kioc->buf_paddr); 6361da177e4SLinus Torvalds else 6371da177e4SLinus Torvalds pool->in_use = 0; 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds spin_unlock_irqrestore(&pool->lock, flags); 6401da177e4SLinus Torvalds } 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds /* Return the kioc to the free pool */ 6431da177e4SLinus Torvalds spin_lock_irqsave(&adp->kioc_pool_lock, flags); 6441da177e4SLinus Torvalds list_add(&kioc->list, &adp->kioc_pool); 6451da177e4SLinus Torvalds spin_unlock_irqrestore(&adp->kioc_pool_lock, flags); 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds /* increment the free kioc count */ 6481da177e4SLinus Torvalds up(&adp->kioc_semaphore); 6491da177e4SLinus Torvalds 6501da177e4SLinus Torvalds return; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds /** 6541da177e4SLinus Torvalds * lld_ioctl - Routine to issue ioctl to low level drvr 6551da177e4SLinus Torvalds * @adp : The adapter handle 6561da177e4SLinus Torvalds * @kioc : The ioctl packet with kernel addresses 6571da177e4SLinus Torvalds */ 6581da177e4SLinus Torvalds static int 6591da177e4SLinus Torvalds lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc) 6601da177e4SLinus Torvalds { 6611da177e4SLinus Torvalds int rval; 6621da177e4SLinus Torvalds struct timer_list timer; 6631da177e4SLinus Torvalds struct timer_list *tp = NULL; 6641da177e4SLinus Torvalds 6651da177e4SLinus Torvalds kioc->status = -ENODATA; 6661da177e4SLinus Torvalds rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE); 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds if (rval) return rval; 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds /* 6711da177e4SLinus Torvalds * Start the timer 6721da177e4SLinus Torvalds */ 6731da177e4SLinus Torvalds if (adp->timeout > 0) { 6741da177e4SLinus Torvalds tp = &timer; 6751da177e4SLinus Torvalds init_timer(tp); 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds tp->function = lld_timedout; 6781da177e4SLinus Torvalds tp->data = (unsigned long)kioc; 6791da177e4SLinus Torvalds tp->expires = jiffies + adp->timeout * HZ; 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds add_timer(tp); 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds /* 6851da177e4SLinus Torvalds * Wait till the low level driver completes the ioctl. After this 6861da177e4SLinus Torvalds * call, the ioctl either completed successfully or timedout. 6871da177e4SLinus Torvalds */ 6881da177e4SLinus Torvalds wait_event(wait_q, (kioc->status != -ENODATA)); 6891da177e4SLinus Torvalds if (tp) { 6901da177e4SLinus Torvalds del_timer_sync(tp); 6911da177e4SLinus Torvalds } 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds /* 6941da177e4SLinus Torvalds * If the command had timedout, we mark the controller offline 6951da177e4SLinus Torvalds * before returning 6961da177e4SLinus Torvalds */ 6971da177e4SLinus Torvalds if (kioc->timedout) { 6981da177e4SLinus Torvalds adp->quiescent = 0; 6991da177e4SLinus Torvalds } 7001da177e4SLinus Torvalds 7011da177e4SLinus Torvalds return kioc->status; 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds /** 7061da177e4SLinus Torvalds * ioctl_done - callback from the low level driver 7071da177e4SLinus Torvalds * @kioc : completed ioctl packet 7081da177e4SLinus Torvalds */ 7091da177e4SLinus Torvalds static void 7101da177e4SLinus Torvalds ioctl_done(uioc_t *kioc) 7111da177e4SLinus Torvalds { 7121da177e4SLinus Torvalds uint32_t adapno; 7131da177e4SLinus Torvalds int iterator; 7141da177e4SLinus Torvalds mraid_mmadp_t* adapter; 7151da177e4SLinus Torvalds 7161da177e4SLinus Torvalds /* 7171da177e4SLinus Torvalds * When the kioc returns from driver, make sure it still doesn't 7181da177e4SLinus Torvalds * have ENODATA in status. Otherwise, driver will hang on wait_event 7191da177e4SLinus Torvalds * forever 7201da177e4SLinus Torvalds */ 7211da177e4SLinus Torvalds if (kioc->status == -ENODATA) { 7221da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING 7231da177e4SLinus Torvalds "megaraid cmm: lld didn't change status!\n")); 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds kioc->status = -EINVAL; 7261da177e4SLinus Torvalds } 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds /* 7291da177e4SLinus Torvalds * Check if this kioc was timedout before. If so, nobody is waiting 7301da177e4SLinus Torvalds * on this kioc. We don't have to wake up anybody. Instead, we just 7311da177e4SLinus Torvalds * have to free the kioc 7321da177e4SLinus Torvalds */ 7331da177e4SLinus Torvalds if (kioc->timedout) { 7341da177e4SLinus Torvalds iterator = 0; 7351da177e4SLinus Torvalds adapter = NULL; 7361da177e4SLinus Torvalds adapno = kioc->adapno; 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds con_log(CL_ANN, ( KERN_WARNING "megaraid cmm: completed " 7391da177e4SLinus Torvalds "ioctl that was timedout before\n")); 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds list_for_each_entry(adapter, &adapters_list_g, list) { 7421da177e4SLinus Torvalds if (iterator++ == adapno) break; 7431da177e4SLinus Torvalds } 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds kioc->timedout = 0; 7461da177e4SLinus Torvalds 7471da177e4SLinus Torvalds if (adapter) { 7481da177e4SLinus Torvalds mraid_mm_dealloc_kioc( adapter, kioc ); 7491da177e4SLinus Torvalds } 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds else { 7521da177e4SLinus Torvalds wake_up(&wait_q); 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds } 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds 757*a69b74d3SRandy Dunlap /** 758*a69b74d3SRandy Dunlap * lld_timedout - callback from the expired timer 7591da177e4SLinus Torvalds * @ptr : ioctl packet that timed out 7601da177e4SLinus Torvalds */ 7611da177e4SLinus Torvalds static void 7621da177e4SLinus Torvalds lld_timedout(unsigned long ptr) 7631da177e4SLinus Torvalds { 7641da177e4SLinus Torvalds uioc_t *kioc = (uioc_t *)ptr; 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds kioc->status = -ETIME; 7671da177e4SLinus Torvalds kioc->timedout = 1; 7681da177e4SLinus Torvalds 7691da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING "megaraid cmm: ioctl timed out\n")); 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds wake_up(&wait_q); 7721da177e4SLinus Torvalds } 7731da177e4SLinus Torvalds 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds /** 776*a69b74d3SRandy Dunlap * kioc_to_mimd - Converter from new back to old format 7771da177e4SLinus Torvalds * @kioc : Kernel space IOCTL packet (successfully issued) 7781da177e4SLinus Torvalds * @mimd : User space MIMD packet 7791da177e4SLinus Torvalds */ 7801da177e4SLinus Torvalds static int 7811da177e4SLinus Torvalds kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd) 7821da177e4SLinus Torvalds { 7831da177e4SLinus Torvalds mimd_t kmimd; 7841da177e4SLinus Torvalds uint8_t opcode; 7851da177e4SLinus Torvalds uint8_t subopcode; 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds mbox64_t *mbox64; 7881da177e4SLinus Torvalds mraid_passthru_t __user *upthru32; 7891da177e4SLinus Torvalds mraid_passthru_t *kpthru32; 7901da177e4SLinus Torvalds mcontroller_t cinfo; 7911da177e4SLinus Torvalds mraid_hba_info_t *hinfo; 7921da177e4SLinus Torvalds 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds if (copy_from_user(&kmimd, mimd, sizeof(mimd_t))) 7951da177e4SLinus Torvalds return (-EFAULT); 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds opcode = kmimd.ui.fcs.opcode; 7981da177e4SLinus Torvalds subopcode = kmimd.ui.fcs.subopcode; 7991da177e4SLinus Torvalds 8001da177e4SLinus Torvalds if (opcode == 0x82) { 8011da177e4SLinus Torvalds switch (subopcode) { 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds case MEGAIOC_QADAPINFO: 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds hinfo = (mraid_hba_info_t *)(unsigned long) 8061da177e4SLinus Torvalds kioc->buf_vaddr; 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds hinfo_to_cinfo(hinfo, &cinfo); 8091da177e4SLinus Torvalds 8101da177e4SLinus Torvalds if (copy_to_user(kmimd.data, &cinfo, sizeof(cinfo))) 8111da177e4SLinus Torvalds return (-EFAULT); 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds return 0; 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds default: 8161da177e4SLinus Torvalds return (-EINVAL); 8171da177e4SLinus Torvalds } 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds return 0; 8201da177e4SLinus Torvalds } 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds mbox64 = (mbox64_t *)(unsigned long)kioc->cmdbuf; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds if (kioc->user_pthru) { 8251da177e4SLinus Torvalds 8261da177e4SLinus Torvalds upthru32 = kioc->user_pthru; 8271da177e4SLinus Torvalds kpthru32 = kioc->pthru32; 8281da177e4SLinus Torvalds 8291da177e4SLinus Torvalds if (copy_to_user(&upthru32->scsistatus, 8301da177e4SLinus Torvalds &kpthru32->scsistatus, 8311da177e4SLinus Torvalds sizeof(uint8_t))) { 8321da177e4SLinus Torvalds return (-EFAULT); 8331da177e4SLinus Torvalds } 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds if (kioc->user_data) { 8371da177e4SLinus Torvalds if (copy_to_user(kioc->user_data, kioc->buf_vaddr, 8381da177e4SLinus Torvalds kioc->user_data_len)) { 8391da177e4SLinus Torvalds return (-EFAULT); 8401da177e4SLinus Torvalds } 8411da177e4SLinus Torvalds } 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds if (copy_to_user(&mimd->mbox[17], 8441da177e4SLinus Torvalds &mbox64->mbox32.status, sizeof(uint8_t))) { 8451da177e4SLinus Torvalds return (-EFAULT); 8461da177e4SLinus Torvalds } 8471da177e4SLinus Torvalds 8481da177e4SLinus Torvalds return 0; 8491da177e4SLinus Torvalds } 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds 8521da177e4SLinus Torvalds /** 8531da177e4SLinus Torvalds * hinfo_to_cinfo - Convert new format hba info into old format 8541da177e4SLinus Torvalds * @hinfo : New format, more comprehensive adapter info 8551da177e4SLinus Torvalds * @cinfo : Old format adapter info to support mimd_t apps 8561da177e4SLinus Torvalds */ 8571da177e4SLinus Torvalds static void 8581da177e4SLinus Torvalds hinfo_to_cinfo(mraid_hba_info_t *hinfo, mcontroller_t *cinfo) 8591da177e4SLinus Torvalds { 8601da177e4SLinus Torvalds if (!hinfo || !cinfo) 8611da177e4SLinus Torvalds return; 8621da177e4SLinus Torvalds 8631da177e4SLinus Torvalds cinfo->base = hinfo->baseport; 8641da177e4SLinus Torvalds cinfo->irq = hinfo->irq; 8651da177e4SLinus Torvalds cinfo->numldrv = hinfo->num_ldrv; 8661da177e4SLinus Torvalds cinfo->pcibus = hinfo->pci_bus; 8671da177e4SLinus Torvalds cinfo->pcidev = hinfo->pci_slot; 8681da177e4SLinus Torvalds cinfo->pcifun = PCI_FUNC(hinfo->pci_dev_fn); 8691da177e4SLinus Torvalds cinfo->pciid = hinfo->pci_device_id; 8701da177e4SLinus Torvalds cinfo->pcivendor = hinfo->pci_vendor_id; 8711da177e4SLinus Torvalds cinfo->pcislot = hinfo->pci_slot; 8721da177e4SLinus Torvalds cinfo->uid = hinfo->unique_id; 8731da177e4SLinus Torvalds } 8741da177e4SLinus Torvalds 8751da177e4SLinus Torvalds 876*a69b74d3SRandy Dunlap /** 877*a69b74d3SRandy Dunlap * mraid_mm_register_adp - Registration routine for low level drivers 878*a69b74d3SRandy Dunlap * @lld_adp : Adapter objejct 8791da177e4SLinus Torvalds */ 8801da177e4SLinus Torvalds int 8811da177e4SLinus Torvalds mraid_mm_register_adp(mraid_mmadp_t *lld_adp) 8821da177e4SLinus Torvalds { 8831da177e4SLinus Torvalds mraid_mmadp_t *adapter; 8841da177e4SLinus Torvalds mbox64_t *mbox_list; 8851da177e4SLinus Torvalds uioc_t *kioc; 8861da177e4SLinus Torvalds uint32_t rval; 8871da177e4SLinus Torvalds int i; 8881da177e4SLinus Torvalds 8891da177e4SLinus Torvalds 8901da177e4SLinus Torvalds if (lld_adp->drvr_type != DRVRTYPE_MBOX) 8911da177e4SLinus Torvalds return (-EINVAL); 8921da177e4SLinus Torvalds 8931da177e4SLinus Torvalds adapter = kmalloc(sizeof(mraid_mmadp_t), GFP_KERNEL); 8941da177e4SLinus Torvalds 8955236467aSAdrian Bunk if (!adapter) 8965236467aSAdrian Bunk return -ENOMEM; 8971da177e4SLinus Torvalds 8981da177e4SLinus Torvalds memset(adapter, 0, sizeof(mraid_mmadp_t)); 8991da177e4SLinus Torvalds 9001da177e4SLinus Torvalds adapter->unique_id = lld_adp->unique_id; 9011da177e4SLinus Torvalds adapter->drvr_type = lld_adp->drvr_type; 9021da177e4SLinus Torvalds adapter->drvr_data = lld_adp->drvr_data; 9031da177e4SLinus Torvalds adapter->pdev = lld_adp->pdev; 9041da177e4SLinus Torvalds adapter->issue_uioc = lld_adp->issue_uioc; 9051da177e4SLinus Torvalds adapter->timeout = lld_adp->timeout; 9061da177e4SLinus Torvalds adapter->max_kioc = lld_adp->max_kioc; 9071da177e4SLinus Torvalds adapter->quiescent = 1; 9081da177e4SLinus Torvalds 9091da177e4SLinus Torvalds /* 9101da177e4SLinus Torvalds * Allocate single blocks of memory for all required kiocs, 9111da177e4SLinus Torvalds * mailboxes and passthru structures. 9121da177e4SLinus Torvalds */ 9131da177e4SLinus Torvalds adapter->kioc_list = kmalloc(sizeof(uioc_t) * lld_adp->max_kioc, 9141da177e4SLinus Torvalds GFP_KERNEL); 9151da177e4SLinus Torvalds adapter->mbox_list = kmalloc(sizeof(mbox64_t) * lld_adp->max_kioc, 9161da177e4SLinus Torvalds GFP_KERNEL); 9171da177e4SLinus Torvalds adapter->pthru_dma_pool = pci_pool_create("megaraid mm pthru pool", 9181da177e4SLinus Torvalds adapter->pdev, 9191da177e4SLinus Torvalds sizeof(mraid_passthru_t), 9201da177e4SLinus Torvalds 16, 0); 9211da177e4SLinus Torvalds 9221da177e4SLinus Torvalds if (!adapter->kioc_list || !adapter->mbox_list || 9231da177e4SLinus Torvalds !adapter->pthru_dma_pool) { 9241da177e4SLinus Torvalds 9251da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING 9261da177e4SLinus Torvalds "megaraid cmm: out of memory, %s %d\n", __FUNCTION__, 9271da177e4SLinus Torvalds __LINE__)); 9281da177e4SLinus Torvalds 9291da177e4SLinus Torvalds rval = (-ENOMEM); 9301da177e4SLinus Torvalds 9311da177e4SLinus Torvalds goto memalloc_error; 9321da177e4SLinus Torvalds } 9331da177e4SLinus Torvalds 9341da177e4SLinus Torvalds /* 9351da177e4SLinus Torvalds * Slice kioc_list and make a kioc_pool with the individiual kiocs 9361da177e4SLinus Torvalds */ 9371da177e4SLinus Torvalds INIT_LIST_HEAD(&adapter->kioc_pool); 9381da177e4SLinus Torvalds spin_lock_init(&adapter->kioc_pool_lock); 9391da177e4SLinus Torvalds sema_init(&adapter->kioc_semaphore, lld_adp->max_kioc); 9401da177e4SLinus Torvalds 9411da177e4SLinus Torvalds mbox_list = (mbox64_t *)adapter->mbox_list; 9421da177e4SLinus Torvalds 9431da177e4SLinus Torvalds for (i = 0; i < lld_adp->max_kioc; i++) { 9441da177e4SLinus Torvalds 9451da177e4SLinus Torvalds kioc = adapter->kioc_list + i; 9461da177e4SLinus Torvalds kioc->cmdbuf = (uint64_t)(unsigned long)(mbox_list + i); 9471da177e4SLinus Torvalds kioc->pthru32 = pci_pool_alloc(adapter->pthru_dma_pool, 9481da177e4SLinus Torvalds GFP_KERNEL, &kioc->pthru32_h); 9491da177e4SLinus Torvalds 9501da177e4SLinus Torvalds if (!kioc->pthru32) { 9511da177e4SLinus Torvalds 9521da177e4SLinus Torvalds con_log(CL_ANN, (KERN_WARNING 9531da177e4SLinus Torvalds "megaraid cmm: out of memory, %s %d\n", 9541da177e4SLinus Torvalds __FUNCTION__, __LINE__)); 9551da177e4SLinus Torvalds 9561da177e4SLinus Torvalds rval = (-ENOMEM); 9571da177e4SLinus Torvalds 9581da177e4SLinus Torvalds goto pthru_dma_pool_error; 9591da177e4SLinus Torvalds } 9601da177e4SLinus Torvalds 9611da177e4SLinus Torvalds list_add_tail(&kioc->list, &adapter->kioc_pool); 9621da177e4SLinus Torvalds } 9631da177e4SLinus Torvalds 9641da177e4SLinus Torvalds // Setup the dma pools for data buffers 9651da177e4SLinus Torvalds if ((rval = mraid_mm_setup_dma_pools(adapter)) != 0) { 9661da177e4SLinus Torvalds goto dma_pool_error; 9671da177e4SLinus Torvalds } 9681da177e4SLinus Torvalds 9691da177e4SLinus Torvalds list_add_tail(&adapter->list, &adapters_list_g); 9701da177e4SLinus Torvalds 9711da177e4SLinus Torvalds adapters_count_g++; 9721da177e4SLinus Torvalds 9731da177e4SLinus Torvalds return 0; 9741da177e4SLinus Torvalds 9751da177e4SLinus Torvalds dma_pool_error: 9761da177e4SLinus Torvalds /* Do nothing */ 9771da177e4SLinus Torvalds 9781da177e4SLinus Torvalds pthru_dma_pool_error: 9791da177e4SLinus Torvalds 9801da177e4SLinus Torvalds for (i = 0; i < lld_adp->max_kioc; i++) { 9811da177e4SLinus Torvalds kioc = adapter->kioc_list + i; 9821da177e4SLinus Torvalds if (kioc->pthru32) { 9831da177e4SLinus Torvalds pci_pool_free(adapter->pthru_dma_pool, kioc->pthru32, 9841da177e4SLinus Torvalds kioc->pthru32_h); 9851da177e4SLinus Torvalds } 9861da177e4SLinus Torvalds } 9871da177e4SLinus Torvalds 9881da177e4SLinus Torvalds memalloc_error: 9891da177e4SLinus Torvalds 9901da177e4SLinus Torvalds kfree(adapter->kioc_list); 9911da177e4SLinus Torvalds kfree(adapter->mbox_list); 9921da177e4SLinus Torvalds 9931da177e4SLinus Torvalds if (adapter->pthru_dma_pool) 9941da177e4SLinus Torvalds pci_pool_destroy(adapter->pthru_dma_pool); 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvalds kfree(adapter); 9971da177e4SLinus Torvalds 9981da177e4SLinus Torvalds return rval; 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds 10011da177e4SLinus Torvalds 10021da177e4SLinus Torvalds /** 10031da177e4SLinus Torvalds * mraid_mm_adapter_app_handle - return the application handle for this adapter 1004*a69b74d3SRandy Dunlap * @unique_id : adapter unique identifier 10051da177e4SLinus Torvalds * 1006*a69b74d3SRandy Dunlap * For the given driver data, locate the adapter in our global list and 10071da177e4SLinus Torvalds * return the corresponding handle, which is also used by applications to 10081da177e4SLinus Torvalds * uniquely identify an adapter. 10091da177e4SLinus Torvalds * 1010*a69b74d3SRandy Dunlap * Return adapter handle if found in the list. 1011*a69b74d3SRandy Dunlap * Return 0 if adapter could not be located, should never happen though. 10121da177e4SLinus Torvalds */ 10131da177e4SLinus Torvalds uint32_t 10141da177e4SLinus Torvalds mraid_mm_adapter_app_handle(uint32_t unique_id) 10151da177e4SLinus Torvalds { 10161da177e4SLinus Torvalds mraid_mmadp_t *adapter; 10171da177e4SLinus Torvalds mraid_mmadp_t *tmp; 10181da177e4SLinus Torvalds int index = 0; 10191da177e4SLinus Torvalds 10201da177e4SLinus Torvalds list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) { 10211da177e4SLinus Torvalds 10221da177e4SLinus Torvalds if (adapter->unique_id == unique_id) { 10231da177e4SLinus Torvalds 10241da177e4SLinus Torvalds return MKADAP(index); 10251da177e4SLinus Torvalds } 10261da177e4SLinus Torvalds 10271da177e4SLinus Torvalds index++; 10281da177e4SLinus Torvalds } 10291da177e4SLinus Torvalds 10301da177e4SLinus Torvalds return 0; 10311da177e4SLinus Torvalds } 10321da177e4SLinus Torvalds 10331da177e4SLinus Torvalds 10341da177e4SLinus Torvalds /** 10351da177e4SLinus Torvalds * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter 10361da177e4SLinus Torvalds * @adp : Adapter softstate 10371da177e4SLinus Torvalds * 10381da177e4SLinus Torvalds * We maintain a pool of dma buffers per each adapter. Each pool has one 10391da177e4SLinus Torvalds * buffer. E.g, we may have 5 dma pools - one each for 4k, 8k ... 64k buffers. 10401da177e4SLinus Torvalds * We have just one 4k buffer in 4k pool, one 8k buffer in 8k pool etc. We 10411da177e4SLinus Torvalds * dont' want to waste too much memory by allocating more buffers per each 10421da177e4SLinus Torvalds * pool. 10431da177e4SLinus Torvalds */ 10441da177e4SLinus Torvalds static int 10451da177e4SLinus Torvalds mraid_mm_setup_dma_pools(mraid_mmadp_t *adp) 10461da177e4SLinus Torvalds { 10471da177e4SLinus Torvalds mm_dmapool_t *pool; 10481da177e4SLinus Torvalds int bufsize; 10491da177e4SLinus Torvalds int i; 10501da177e4SLinus Torvalds 10511da177e4SLinus Torvalds /* 10521da177e4SLinus Torvalds * Create MAX_DMA_POOLS number of pools 10531da177e4SLinus Torvalds */ 10541da177e4SLinus Torvalds bufsize = MRAID_MM_INIT_BUFF_SIZE; 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvalds for (i = 0; i < MAX_DMA_POOLS; i++){ 10571da177e4SLinus Torvalds 10581da177e4SLinus Torvalds pool = &adp->dma_pool_list[i]; 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvalds pool->buf_size = bufsize; 10611da177e4SLinus Torvalds spin_lock_init(&pool->lock); 10621da177e4SLinus Torvalds 10631da177e4SLinus Torvalds pool->handle = pci_pool_create("megaraid mm data buffer", 10641da177e4SLinus Torvalds adp->pdev, bufsize, 16, 0); 10651da177e4SLinus Torvalds 10661da177e4SLinus Torvalds if (!pool->handle) { 10671da177e4SLinus Torvalds goto dma_pool_setup_error; 10681da177e4SLinus Torvalds } 10691da177e4SLinus Torvalds 10701da177e4SLinus Torvalds pool->vaddr = pci_pool_alloc(pool->handle, GFP_KERNEL, 10711da177e4SLinus Torvalds &pool->paddr); 10721da177e4SLinus Torvalds 10731da177e4SLinus Torvalds if (!pool->vaddr) 10741da177e4SLinus Torvalds goto dma_pool_setup_error; 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds bufsize = bufsize * 2; 10771da177e4SLinus Torvalds } 10781da177e4SLinus Torvalds 10791da177e4SLinus Torvalds return 0; 10801da177e4SLinus Torvalds 10811da177e4SLinus Torvalds dma_pool_setup_error: 10821da177e4SLinus Torvalds 10831da177e4SLinus Torvalds mraid_mm_teardown_dma_pools(adp); 10841da177e4SLinus Torvalds return (-ENOMEM); 10851da177e4SLinus Torvalds } 10861da177e4SLinus Torvalds 10871da177e4SLinus Torvalds 1088*a69b74d3SRandy Dunlap /** 10891da177e4SLinus Torvalds * mraid_mm_unregister_adp - Unregister routine for low level drivers 10901da177e4SLinus Torvalds * @unique_id : UID of the adpater 1091*a69b74d3SRandy Dunlap * 1092*a69b74d3SRandy Dunlap * Assumes no outstanding ioctls to llds. 10931da177e4SLinus Torvalds */ 10941da177e4SLinus Torvalds int 10951da177e4SLinus Torvalds mraid_mm_unregister_adp(uint32_t unique_id) 10961da177e4SLinus Torvalds { 10971da177e4SLinus Torvalds mraid_mmadp_t *adapter; 10981da177e4SLinus Torvalds mraid_mmadp_t *tmp; 10991da177e4SLinus Torvalds 11001da177e4SLinus Torvalds list_for_each_entry_safe(adapter, tmp, &adapters_list_g, list) { 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds 11031da177e4SLinus Torvalds if (adapter->unique_id == unique_id) { 11041da177e4SLinus Torvalds 11051da177e4SLinus Torvalds adapters_count_g--; 11061da177e4SLinus Torvalds 11071da177e4SLinus Torvalds list_del_init(&adapter->list); 11081da177e4SLinus Torvalds 11091da177e4SLinus Torvalds mraid_mm_free_adp_resources(adapter); 11101da177e4SLinus Torvalds 11111da177e4SLinus Torvalds kfree(adapter); 11121da177e4SLinus Torvalds 11131da177e4SLinus Torvalds con_log(CL_ANN, ( 11141da177e4SLinus Torvalds "megaraid cmm: Unregistered one adapter:%#x\n", 11151da177e4SLinus Torvalds unique_id)); 11161da177e4SLinus Torvalds 11171da177e4SLinus Torvalds return 0; 11181da177e4SLinus Torvalds } 11191da177e4SLinus Torvalds } 11201da177e4SLinus Torvalds 11211da177e4SLinus Torvalds return (-ENODEV); 11221da177e4SLinus Torvalds } 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds /** 11251da177e4SLinus Torvalds * mraid_mm_free_adp_resources - Free adapter softstate 11261da177e4SLinus Torvalds * @adp : Adapter softstate 11271da177e4SLinus Torvalds */ 11281da177e4SLinus Torvalds static void 11291da177e4SLinus Torvalds mraid_mm_free_adp_resources(mraid_mmadp_t *adp) 11301da177e4SLinus Torvalds { 11311da177e4SLinus Torvalds uioc_t *kioc; 11321da177e4SLinus Torvalds int i; 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds mraid_mm_teardown_dma_pools(adp); 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvalds for (i = 0; i < adp->max_kioc; i++) { 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds kioc = adp->kioc_list + i; 11391da177e4SLinus Torvalds 11401da177e4SLinus Torvalds pci_pool_free(adp->pthru_dma_pool, kioc->pthru32, 11411da177e4SLinus Torvalds kioc->pthru32_h); 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds 11441da177e4SLinus Torvalds kfree(adp->kioc_list); 11451da177e4SLinus Torvalds kfree(adp->mbox_list); 11461da177e4SLinus Torvalds 11471da177e4SLinus Torvalds pci_pool_destroy(adp->pthru_dma_pool); 11481da177e4SLinus Torvalds 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds return; 11511da177e4SLinus Torvalds } 11521da177e4SLinus Torvalds 11531da177e4SLinus Torvalds 11541da177e4SLinus Torvalds /** 11551da177e4SLinus Torvalds * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers 11561da177e4SLinus Torvalds * @adp : Adapter softstate 11571da177e4SLinus Torvalds */ 11581da177e4SLinus Torvalds static void 11591da177e4SLinus Torvalds mraid_mm_teardown_dma_pools(mraid_mmadp_t *adp) 11601da177e4SLinus Torvalds { 11611da177e4SLinus Torvalds int i; 11621da177e4SLinus Torvalds mm_dmapool_t *pool; 11631da177e4SLinus Torvalds 11641da177e4SLinus Torvalds for (i = 0; i < MAX_DMA_POOLS; i++) { 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds pool = &adp->dma_pool_list[i]; 11671da177e4SLinus Torvalds 11681da177e4SLinus Torvalds if (pool->handle) { 11691da177e4SLinus Torvalds 11701da177e4SLinus Torvalds if (pool->vaddr) 11711da177e4SLinus Torvalds pci_pool_free(pool->handle, pool->vaddr, 11721da177e4SLinus Torvalds pool->paddr); 11731da177e4SLinus Torvalds 11741da177e4SLinus Torvalds pci_pool_destroy(pool->handle); 11751da177e4SLinus Torvalds pool->handle = NULL; 11761da177e4SLinus Torvalds } 11771da177e4SLinus Torvalds } 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds return; 11801da177e4SLinus Torvalds } 11811da177e4SLinus Torvalds 11821da177e4SLinus Torvalds /** 1183*a69b74d3SRandy Dunlap * mraid_mm_init - Module entry point 11841da177e4SLinus Torvalds */ 11851da177e4SLinus Torvalds static int __init 11861da177e4SLinus Torvalds mraid_mm_init(void) 11871da177e4SLinus Torvalds { 11881da177e4SLinus Torvalds // Announce the driver version 11891da177e4SLinus Torvalds con_log(CL_ANN, (KERN_INFO "megaraid cmm: %s %s\n", 11901da177e4SLinus Torvalds LSI_COMMON_MOD_VERSION, LSI_COMMON_MOD_EXT_VERSION)); 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds majorno = register_chrdev(0, "megadev", &lsi_fops); 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds if (majorno < 0) { 11951da177e4SLinus Torvalds con_log(CL_ANN, ("megaraid cmm: cannot get major\n")); 11961da177e4SLinus Torvalds return majorno; 11971da177e4SLinus Torvalds } 11981da177e4SLinus Torvalds 11991da177e4SLinus Torvalds init_waitqueue_head(&wait_q); 12001da177e4SLinus Torvalds 12011da177e4SLinus Torvalds INIT_LIST_HEAD(&adapters_list_g); 12021da177e4SLinus Torvalds 12031da177e4SLinus Torvalds return 0; 12041da177e4SLinus Torvalds } 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds 12071da177e4SLinus Torvalds #ifdef CONFIG_COMPAT 1208*a69b74d3SRandy Dunlap /** 1209*a69b74d3SRandy Dunlap * mraid_mm_compat_ioctl - 32bit to 64bit ioctl conversion routine 1210*a69b74d3SRandy Dunlap * @filep : file operations pointer (ignored) 1211*a69b74d3SRandy Dunlap * @cmd : ioctl command 1212*a69b74d3SRandy Dunlap * @arg : user ioctl packet 1213*a69b74d3SRandy Dunlap */ 12141da177e4SLinus Torvalds static long 12151da177e4SLinus Torvalds mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd, 12161da177e4SLinus Torvalds unsigned long arg) 12171da177e4SLinus Torvalds { 12181da177e4SLinus Torvalds int err; 1219672b2d38SJu, Seokmann 12201da177e4SLinus Torvalds err = mraid_mm_ioctl(NULL, filep, cmd, arg); 1221672b2d38SJu, Seokmann 12221da177e4SLinus Torvalds return err; 12231da177e4SLinus Torvalds } 12241da177e4SLinus Torvalds #endif 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds /** 1227*a69b74d3SRandy Dunlap * mraid_mm_exit - Module exit point 12281da177e4SLinus Torvalds */ 12291da177e4SLinus Torvalds static void __exit 12301da177e4SLinus Torvalds mraid_mm_exit(void) 12311da177e4SLinus Torvalds { 12321da177e4SLinus Torvalds con_log(CL_DLEVEL1 , ("exiting common mod\n")); 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvalds unregister_chrdev(majorno, "megadev"); 12351da177e4SLinus Torvalds } 12361da177e4SLinus Torvalds 12371da177e4SLinus Torvalds module_init(mraid_mm_init); 12381da177e4SLinus Torvalds module_exit(mraid_mm_exit); 12391da177e4SLinus Torvalds 12401da177e4SLinus Torvalds /* vi: set ts=8 sw=8 tw=78: */ 1241