[SCSI] mpt fusion: mostly kmalloc + memset conversion to kzalloc
[powerpc.git] / drivers / message / fusion / mptctl.c
index 89695e7..12dfa2e 100644 (file)
@@ -1,10 +1,10 @@
 /*
  *  linux/drivers/message/fusion/mptctl.c
  *      mpt Ioctl driver.
- *      For use with LSI Logic PCI chip/adapters
- *      running LSI Logic Fusion MPT (Message Passing Technology) firmware.
+ *      For use with LSI PCI chip/adapters
+ *      running LSI Fusion MPT (Message Passing Technology) firmware.
  *
- *  Copyright (c) 1999-2007 LSI Logic Corporation
+ *  Copyright (c) 1999-2007 LSI Corporation
  *  (mailto:DL-MPTFusionLinux@lsi.com)
  *
  */
@@ -66,8 +66,8 @@
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_tcq.h>
 
-#define COPYRIGHT      "Copyright (c) 1999-2007 LSI Logic Corporation"
-#define MODULEAUTHOR   "LSI Logic Corporation"
+#define COPYRIGHT      "Copyright (c) 1999-2007 LSI Corporation"
+#define MODULEAUTHOR   "LSI Corporation"
 #include "mptbase.h"
 #include "mptctl.h"
 
@@ -83,7 +83,7 @@ MODULE_VERSION(my_VERSION);
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 
-static int mptctl_id = -1;
+static u8 mptctl_id = MPT_MAX_PROTOCOL_DRIVERS;
 
 static DECLARE_WAIT_QUEUE_HEAD ( mptctl_wait );
 
@@ -342,7 +342,7 @@ static int mptctl_bus_reset(MPT_IOCTL *ioctl)
        SCSITaskMgmt_t  *pScsiTm;
        MPT_SCSI_HOST   *hd;
        int              ii;
-       int              retval;
+       int              retval=0;
 
 
        ioctl->reset &= ~MPTCTL_RESET_OK;
@@ -395,12 +395,19 @@ static int mptctl_bus_reset(MPT_IOCTL *ioctl)
        DBG_DUMP_TM_REQUEST_FRAME(ioctl->ioc, (u32 *)mf);
 
        ioctl->wait_done=0;
-       if ((retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
-            sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP)) != 0) {
-               dfailprintk(ioctl->ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!"
-                       " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
-                       hd->ioc, mf));
-               goto mptctl_bus_reset_done;
+
+       if ((ioctl->ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
+           (ioctl->ioc->facts.MsgVersion >= MPI_VERSION_01_05))
+               mpt_put_msg_frame_hi_pri(mptctl_id, ioctl->ioc, mf);
+       else {
+               retval = mpt_send_handshake_request(mptctl_id, ioctl->ioc,
+                       sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
+               if (retval != 0) {
+                       dfailprintk(ioctl->ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!"
+                               " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
+                               hd->ioc, mf));
+                       goto mptctl_bus_reset_done;
+               }
        }
 
        /* Now wait for the command to complete */
@@ -970,10 +977,9 @@ kbuf_alloc_2_sgl(int bytes, u32 sgdir, int sge_offset, int *frags,
         * structures for the SG elements.
         */
        i = MAX_SGL_BYTES / 8;
-       buflist = kmalloc(i, GFP_USER);
-       if (buflist == NULL)
+       buflist = kzalloc(i, GFP_USER);
+       if (!buflist)
                return NULL;
-       memset(buflist, 0, i);
        buflist_ent = 0;
 
        /* Allocate a single block of memory to store the sg elements and
@@ -1372,13 +1378,12 @@ mptctl_gettargetinfo (unsigned long arg)
         *      15- 8: Bus Number
         *       7- 0: Target ID
         */
-       pmem = kmalloc(numBytes, GFP_KERNEL);
-       if (pmem == NULL) {
+       pmem = kzalloc(numBytes, GFP_KERNEL);
+       if (!pmem) {
                printk(KERN_ERR "%s::mptctl_gettargetinfo() @%d - no memory available!\n",
                                __FILE__, __LINE__);
                return -ENOMEM;
        }
-       memset(pmem, 0, numBytes);
        pdata =  (int *) pmem;
 
        /* Get number of devices
@@ -1563,12 +1568,11 @@ mptctl_eventenable (unsigned long arg)
                /* Have not yet allocated memory - do so now.
                 */
                int sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
-               ioc->events = kmalloc(sz, GFP_KERNEL);
-               if (ioc->events == NULL) {
+               ioc->events = kzalloc(sz, GFP_KERNEL);
+               if (!ioc->events) {
                        printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
                        return -ENOMEM;
                }
-               memset(ioc->events, 0, sz);
                ioc->alloc_total += sz;
 
                ioc->eventContext = 0;
@@ -2187,15 +2191,20 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
 
                DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)mf);
 
-               if (mpt_send_handshake_request(mptctl_id, ioc,
-                       sizeof(SCSITaskMgmt_t), (u32*)mf,
-                       CAN_SLEEP) != 0) {
-                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "_send_handshake FAILED!"
-                               " (ioc %p, mf %p) \n", ioc->name,
-                               ioc, mf));
-                       mptctl_free_tm_flags(ioc);
-                       rc = -ENODATA;
-                       goto done_free_mem;
+               if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
+                   (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
+                       mpt_put_msg_frame_hi_pri(mptctl_id, ioc, mf);
+               else {
+                       rc =mpt_send_handshake_request(mptctl_id, ioc,
+                               sizeof(SCSITaskMgmt_t), (u32*)mf, CAN_SLEEP);
+                       if (rc != 0) {
+                               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT
+                                   "_send_handshake FAILED! (ioc %p, mf %p)\n",
+                                   ioc->name, ioc, mf));
+                               mptctl_free_tm_flags(ioc);
+                               rc = -ENODATA;
+                               goto done_free_mem;
+                       }
                }
 
        } else
@@ -2853,31 +2862,22 @@ static long compat_mpctl_ioctl(struct file *f, unsigned int cmd, unsigned long a
 static int
 mptctl_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
-       int err;
-       int sz;
-       u8 *mem;
+       MPT_IOCTL *mem;
        MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
 
        /*
         * Allocate and inite a MPT_IOCTL structure
        */
-       sz = sizeof (MPT_IOCTL);
-       mem = kmalloc(sz, GFP_KERNEL);
-       if (mem == NULL) {
-               err = -ENOMEM;
-               goto out_fail;
+       mem = kzalloc(sizeof(MPT_IOCTL), GFP_KERNEL);
+       if (!mem) {
+               mptctl_remove(pdev);
+               return -ENOMEM;
        }
 
-       memset(mem, 0, sz);
-       ioc->ioctl = (MPT_IOCTL *) mem;
+       ioc->ioctl = mem;
        ioc->ioctl->ioc = ioc;
        mutex_init(&ioc->ioctl->ioctl_mutex);
        return 0;
-
-out_fail:
-
-       mptctl_remove(pdev);
-       return err;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -2924,7 +2924,8 @@ static int __init mptctl_init(void)
         *  Install our handler
         */
        ++where;
-       if ((mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER)) < 0) {
+       mptctl_id = mpt_register(mptctl_reply, MPTCTL_DRIVER);
+       if (!mptctl_id || mptctl_id >= MPT_MAX_PROTOCOL_DRIVERS) {
                printk(KERN_ERR MYNAM ": ERROR: Failed to register with Fusion MPT base driver\n");
                misc_deregister(&mptctl_miscdev);
                err = -EBUSY;