Patchwork [3/7] megasas: Codingstyle fixes

login
register
mail settings
Submitter Hannes Reinecke
Date June 15, 2010, 3:16 p.m.
Message ID <20100615151620.094652B964@ochil.suse.de>
Download mbox | patch
Permalink /patch/55731/
State New
Headers show

Comments

Hannes Reinecke - June 15, 2010, 3:16 p.m.
Fixup code to match Codingstyle as suggested by blueswirl.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 hw/megasas.c | 1209 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 562 insertions(+), 647 deletions(-)
Nicholas A. Bellinger - June 16, 2010, 8:58 a.m.
On Tue, 2010-06-15 at 17:16 +0200, Hannes Reinecke wrote:
> Fixup code to match Codingstyle as suggested by blueswirl.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  hw/megasas.c | 1209 +++++++++++++++++++++++++++-------------------------------
>  1 files changed, 562 insertions(+), 647 deletions(-)
> 

Commited.

--nab

Patch

diff --git a/hw/megasas.c b/hw/megasas.c
index 753d5dc..6ddb757 100644
--- a/hw/megasas.c
+++ b/hw/megasas.c
@@ -33,19 +33,49 @@ 
 do { printf("megasas: " fmt , ## __VA_ARGS__); } while (0)
 #define BADF(fmt, ...) \
 do { fprintf(stderr, "megasas: error: " fmt , ## __VA_ARGS__); exit(1);} while (0)
+#ifdef DEBUG_MEGASAS_REG
+#define DPRINTF_REG DPRINTF
+#else
+#define DPRINTF_REG(fmt, ...) do {} while(0)
+#endif
+#ifdef DEBUG_MEGASAS_QUEUE
+#define DPRINTF_QUEUE DPRINTF
+#else
+#define DPRINTF_QUEUE(fmt, ...) do {} while(0)
+#endif
+#ifdef DEBUG_MEGASAS_MFI
+#define DPRINTF_MFI DPRINTF
+#else
+#define DPRINTF_MFI(fmt, ...) do {} while(0)
+#endif
+#ifdef DEBUG_MEGASAS_IO
+#define DPRINTF_IO DPRINTF
+#else
+#define DPRINTF_IO(fmt, ...) do {} while(0)
+#endif
+#ifdef DEBUG_MEGASAS_DCMD
+#define DPRINTF_DCMD DPRINTF
+#else
+#define DPRINTF_DCMD(fmt, ...) do {} while(0)
+#endif
 #else
 #define DPRINTF(fmt, ...) do {} while(0)
+#define DPRINTF_REG DPRINTF
+#define DPRINTF_QUEUE DPRINTF
+#define DPRINTF_MFI DPRINTF
+#define DPRINTF_IO DPRINTF
+#define DPRINTF_DCMD DPRINTF
 #define BADF(fmt, ...) \
 do { fprintf(stderr, "megasas: error: " fmt , ## __VA_ARGS__);} while (0)
 #endif
 
 /* Static definitions */
 #define MEGASAS_VERSION "1.02"
-#define MEGASAS_MAX_FRAMES 2048		/* Firmware limit at 65535 */
-#define MEGASAS_DEFAULT_FRAMES 1000	/* Windows requires this */
-#define MEGASAS_MAX_SGE 255		/* Firmware limit */
+#define MEGASAS_MAX_FRAMES 2048         /* Firmware limit at 65535 */
+#define MEGASAS_DEFAULT_FRAMES 1000     /* Windows requires this */
+#define MEGASAS_MAX_SGE 255             /* Firmware limit */
 #define MEGASAS_DEFAULT_SGE 80
-#define MEGASAS_MAX_SECTORS 0xFFFF	/* No real limit */
+#define MEGASAS_MAX_SECTORS 0xFFFF      /* No real limit */
 #define MEGASAS_MAX_ARRAYS 128
 
 const char *mfi_frame_desc[] = {
@@ -129,22 +159,22 @@  static void megasas_map_sgl(struct megasas_cmd_t *cmd, int pa_offset)
 
     qemu_sglist_init(&cmd->sg, cmd->frame->header.sge_count);
     for (i = 0; i < cmd->frame->header.sge_count; i++) {
-	target_phys_addr_t pa, iov_pa;
-
-	pa = cmd->pa + pa_offset;
-	if (is_sgl64)
-	    iov_pa = ldq_phys(pa);
-	else
-	    iov_pa = ldl_phys(pa);
-	qemu_sglist_add(&cmd->sg, iov_pa, ldl_phys(pa + sgl_addr_size));
-	pa_offset += sgl_addr_size + sizeof(uint32_t);
+        target_phys_addr_t pa, iov_pa;
+
+        pa = cmd->pa + pa_offset;
+        if (is_sgl64)
+            iov_pa = ldq_phys(pa);
+        else
+            iov_pa = ldl_phys(pa);
+        qemu_sglist_add(&cmd->sg, iov_pa, ldl_phys(pa + sgl_addr_size));
+        pa_offset += sgl_addr_size + sizeof(uint32_t);
     }
 }
 
 static void megasas_unmap_sgl(struct megasas_cmd_t *cmd)
 {
     if (cmd->frame->header.sge_count)
-	qemu_sglist_destroy(&cmd->sg);
+        qemu_sglist_destroy(&cmd->sg);
 }
 
 /*
@@ -160,10 +190,10 @@  static void megasas_build_sense(struct megasas_cmd_t *cmd, SCSISense sense)
 
     sense_ptr = qemu_mallocz(cmd->frame->header.sense_len);
     sense_len = scsi_build_sense(SENSE_CODE(INVALID_OPCODE), sense_ptr,
-				 cmd->frame->header.sense_len, 0);
+                                 cmd->frame->header.sense_len, 0);
     pa_lo = le32_to_cpu(cmd->frame->pass.sense_addr_lo);
     if (is_sense64)
-	pa_hi = le32_to_cpu(cmd->frame->pass.sense_addr_hi);
+        pa_hi = le32_to_cpu(cmd->frame->pass.sense_addr_hi);
     pa = ((uint64_t) pa_hi << 32) | pa_lo;
     cpu_physical_memory_write(pa, sense_ptr, sense_len);
     megasas_frame_set_sense_len(cmd->pa, sense_len);
@@ -171,13 +201,13 @@  static void megasas_build_sense(struct megasas_cmd_t *cmd, SCSISense sense)
 }
 
 static int megasas_setup_inquiry(SCSIRequest *req, int pg,
-				 uint8_t *buf, int len)
+                                 uint8_t *buf, int len)
 {
     uint8_t cdb[6] = { INQUIRY, 0, 0, 0, 0, 0};
 
     if (pg > 0) {
-	cdb[1] = 0x1;
-	cdb[2] = pg;
+        cdb[1] = 0x1;
+        cdb[2] = pg;
     }
     cdb[3] = (len >> 8) & 0xff;
     cdb[4] = (len & 0xff);
@@ -197,21 +227,21 @@  static uint64_t megasas_fw_time(void)
 
     curtime = gmtime(&now);
     bcd_time = ((uint64_t)curtime->tm_sec & 0xff) << 48 |
-	((uint64_t)curtime->tm_min & 0xff)  << 40 |
-	((uint64_t)curtime->tm_hour & 0xff) << 32 |
-	((uint64_t)curtime->tm_mday & 0xff) << 24 |
-	((uint64_t)curtime->tm_mon & 0xff)  << 16 |
-	((uint64_t)(curtime->tm_year + 1900) & 0xffff);
+        ((uint64_t)curtime->tm_min & 0xff)  << 40 |
+        ((uint64_t)curtime->tm_hour & 0xff) << 32 |
+        ((uint64_t)curtime->tm_mday & 0xff) << 24 |
+        ((uint64_t)curtime->tm_mon & 0xff)  << 16 |
+        ((uint64_t)(curtime->tm_year + 1900) & 0xffff);
 
     return bcd_time;
 }
 
-static uint64_t megasas_gen_sas_addr(unsigned long id)
+static uint64_t megasas_gen_sas_addr(uint64_t id)
 {
     uint64_t addr;
 
-    addr = ((uint64_t)0x5001a4a << 36);
-    addr |= ((uint64_t)id & 0xfffffffff);
+    addr = 0x5001a4aULL << 36;
+    addr |= id & 0xfffffffff;
 
     return addr;
 }
@@ -223,24 +253,24 @@  static uint64_t megasas_gen_sas_addr(unsigned long id)
 static void megasas_dump_frame(struct megasas_cmd_t *cmd)
 {
     DPRINTF("Frame %x: p%p context %x\n"
-	    "\t%016lx %016lx\n\t%016lx %016lx\n"
-	    "\t%016lx %016lx\n\t%016lx %016lx\n",
-	    cmd->index, cmd->frame, cmd->context,
-	    be64_to_cpu(cmd->frame->raw[0]),
-	    be64_to_cpu(cmd->frame->raw[1]),
-	    be64_to_cpu(cmd->frame->raw[2]),
-	    be64_to_cpu(cmd->frame->raw[3]),
-	    be64_to_cpu(cmd->frame->raw[4]),
-	    be64_to_cpu(cmd->frame->raw[5]),
-	    be64_to_cpu(cmd->frame->raw[6]),
-	    be64_to_cpu(cmd->frame->raw[7]));
+            "\t%016lx %016lx\n\t%016lx %016lx\n"
+            "\t%016lx %016lx\n\t%016lx %016lx\n",
+            cmd->index, cmd->frame, cmd->context,
+            be64_to_cpu(cmd->frame->raw[0]),
+            be64_to_cpu(cmd->frame->raw[1]),
+            be64_to_cpu(cmd->frame->raw[2]),
+            be64_to_cpu(cmd->frame->raw[3]),
+            be64_to_cpu(cmd->frame->raw[4]),
+            be64_to_cpu(cmd->frame->raw[5]),
+            be64_to_cpu(cmd->frame->raw[6]),
+            be64_to_cpu(cmd->frame->raw[7]));
 }
 
 static inline int megasas_next_index(MPTState *s, int index)
 {
     index++;
     if (index == s->fw_cmds)
-	index = 0;
+        index = 0;
     return index;
 }
 
@@ -253,12 +283,12 @@  static inline struct megasas_cmd_t *megasas_lookup_frame(MPTState *s,
     index = s->reply_queue_index;
 
     while (num < s->fw_cmds) {
-	if (s->frames[index].pa && s->frames[index].pa == frame) {
-	    cmd = &s->frames[index];
-	    break;
-	}
-	index = megasas_next_index(s, index);
-	num++;
+        if (s->frames[index].pa && s->frames[index].pa == frame) {
+            cmd = &s->frames[index];
+            break;
+        }
+        index = megasas_next_index(s, index);
+        num++;
     }
 
     return cmd;
@@ -272,27 +302,23 @@  static inline struct megasas_cmd_t *megasas_next_frame(MPTState *s,
 
     cmd = megasas_lookup_frame(s, frame);
     if (cmd) {
-#ifdef DEBUG_MEGASAS_QUEUE
-	DPRINTF("Found mapped frame %x pa %lx\n", cmd->index, cmd->pa);
-#endif
-	if (cmd->context != -1)
-	    DPRINTF("Frame %x context %x not finished\n",
-		    cmd->index, cmd->context);
-	return cmd;
+        DPRINTF_QUEUE("Found mapped frame %x pa %lx\n", cmd->index, cmd->pa);
+        if (cmd->context != -1)
+            DPRINTF("Frame %x context %x not finished\n",
+                    cmd->index, cmd->context);
+        return cmd;
     }
     index = s->reply_queue_index;
     num = 0;
     while (num < s->fw_cmds) {
-	if (!s->frames[index].pa) {
-	    cmd = &s->frames[index];
-	    break;
-	}
-	index = megasas_next_index(s, index);
-	num++;
+        if (!s->frames[index].pa) {
+            cmd = &s->frames[index];
+            break;
+        }
+        index = megasas_next_index(s, index);
+        num++;
     }
-#ifdef DEBUG_MEGASAS_QUEUE
-    DPRINTF("Return new frame %x cmd %p\n", index, cmd);
-#endif
+    DPRINTF_QUEUE("Return new frame %x cmd %p\n", index, cmd);
     return cmd;
 }
 
@@ -306,35 +332,33 @@  megasas_enqueue_frame(MPTState *s, target_phys_addr_t frame)
     cmd = megasas_next_frame(s, frame);
     /* All frames busy */
     if (!cmd)
-	return NULL;
+        return NULL;
     if (!cmd->pa) {
-	cmd->pa = frame;
-	cmd->frame = cpu_physical_memory_map(frame, &frame_size_p, 0);
-	if (frame_size_p != frame_size) {
-	    DPRINTF("failed to map frame %lu\n", (unsigned long)frame);
-	    if (cmd->frame) {
-		cpu_physical_memory_unmap(cmd->frame, frame_size_p, 0, 0);
-		cmd->frame = NULL;
-		cmd->pa = 0;
-	    }
-	    s->event_count++;
-	    return NULL;
-	}
+        cmd->pa = frame;
+        cmd->frame = cpu_physical_memory_map(frame, &frame_size_p, 0);
+        if (frame_size_p != frame_size) {
+            DPRINTF("failed to map frame %lu\n", (unsigned long)frame);
+            if (cmd->frame) {
+                cpu_physical_memory_unmap(cmd->frame, frame_size_p, 0, 0);
+                cmd->frame = NULL;
+                cmd->pa = 0;
+            }
+            s->event_count++;
+            return NULL;
+        }
     }
 
     cmd->context = le32_to_cpu(cmd->frame->header.context);
     if (cmd->context != cmd->index) {
-	DPRINTF("Non-matching context %x, correcting to %x\n",
-		cmd->context, cmd->index);
-	megasas_dump_frame(cmd);
-	cmd->context = cmd->index;
+        DPRINTF("Non-matching context %x, correcting to %x\n",
+                cmd->context, cmd->index);
+        megasas_dump_frame(cmd);
+        cmd->context = cmd->index;
     }
     s->busy++;
 
-#ifdef DEBUG_MEGASAS_QUEUE
-    DPRINTF("Enqueue frame %x context %x tail %x busy %d\n",
-	    cmd->index, cmd->context, s->reply_queue_index, s->busy);
-#endif
+    DPRINTF_QUEUE("Enqueue frame %x context %x tail %x busy %d\n",
+                  cmd->index, cmd->context, s->reply_queue_index, s->busy);
 
     return cmd;
 }
@@ -347,10 +371,8 @@  static void megasas_dequeue_frame(MPTState *s, int context)
     s->busy--;
 
     if (!MEGASAS_INTR_ENABLED(s)) {
-#ifdef DEBUG_MEGASAS_QUEUE
-	DPRINTF("Complete frame context %x\n", context);
-#endif
-	return;
+        DPRINTF_QUEUE("Complete frame context %x\n", context);
+        return;
     }
 
     /* Put command on the reply queue */
@@ -358,15 +380,13 @@  static void megasas_dequeue_frame(MPTState *s, int context)
     stl_phys(s->reply_queue_pa + tail * sizeof(uint32_t), context);
 
     s->reply_queue_index = megasas_next_index(s, tail);
-#ifdef DEBUG_MEGASAS_QUEUE
-    DPRINTF("Complete frame context %x tail %x busy %d doorbell %d\n",
-	    context, tail, s->busy, s->doorbell);
-#endif
+    DPRINTF_QUEUE("Complete frame context %x tail %x busy %d doorbell %d\n",
+                  context, tail, s->busy, s->doorbell);
 
     /* Notify HBA */
     s->doorbell++;
     if (s->doorbell == 1) {
-	qemu_irq_raise(s->dev.irq[0]);
+        qemu_irq_raise(s->dev.irq[0]);
     }
 }
 
@@ -375,11 +395,9 @@  static int megasas_finish_command(MPTState *s, struct megasas_cmd_t *cmd)
     int context = -1;
 
     if (!cmd) {
-#ifdef DEBUG_MEGASAS_QUEUE
-	DPRINTF("No frame to complete\n");
-#endif
-	s->event_count++;
-	return -1;
+        DPRINTF_QUEUE("No frame to complete\n");
+        s->event_count++;
+        return -1;
     }
     context = cmd->context;
     cmd->context = -1;
@@ -390,8 +408,8 @@  static int megasas_finish_command(MPTState *s, struct megasas_cmd_t *cmd)
 static void megasas_abort_command(struct megasas_cmd_t *cmd)
 {
     if (cmd->req) {
-	scsi_req_put(cmd->req);
-	cmd->req = NULL;
+        scsi_req_put(cmd->req);
+        cmd->req = NULL;
     }
 }
 
@@ -404,19 +422,17 @@  static int megasas_init_firmware(MPTState *s, struct megasas_cmd_t *cmd)
     pa_lo = le32_to_cpu(cmd->frame->init.qinfo_new_addr_lo);
     pa_hi = le32_to_cpu(cmd->frame->init.qinfo_new_addr_hi);
     iq_pa = (((uint64_t) pa_hi << 32) | pa_lo);
-#ifdef DEBUG_MEGASAS_MFI
-    DPRINTF("MFI init firmware: xfer len %d pa %lx\n", (int)iq_pl,
-	    (unsigned long)iq_pa);
-#endif
+    DPRINTF_MFI("MFI init firmware: xfer len %d pa %lx\n", (int)iq_pl,
+                (unsigned long)iq_pa);
     initq_size = sizeof(*initq);
     initq = cpu_physical_memory_map(iq_pa, &initq_size, 0);
     if (initq_size != sizeof(*initq)) {
-	DPRINTF("MFI init firmware: failed to map queue mem\n");
-	if (initq)
-	    cpu_physical_memory_unmap(initq, initq_size, 0, 0);
-	s->fw_state = MFI_FWSTATE_FAULT;
-	s->event_count++;
-	goto out;
+        DPRINTF("MFI init firmware: failed to map queue mem\n");
+        if (initq)
+            cpu_physical_memory_unmap(initq, initq_size, 0, 0);
+        s->fw_state = MFI_FWSTATE_FAULT;
+        s->event_count++;
+        goto out;
     }
     s->reply_queue_len = le32_to_cpu(initq->rq_entries);
     pa_lo = le32_to_cpu(initq->rq_addr_lo);
@@ -428,11 +444,9 @@  static int megasas_init_firmware(MPTState *s, struct megasas_cmd_t *cmd)
     pa_lo = le32_to_cpu(initq->pi_addr_lo);
     pa_hi = le32_to_cpu(initq->pi_addr_hi);
     s->producer_pa = ((uint64_t) pa_hi << 32) | pa_lo;
-#ifdef DEBUG_MEGASAS_MFI
-    DPRINTF("MFI init firmware: queue at %lx len %d head %lx tail %lx\n",
-	    (unsigned long)s->reply_queue_pa, s->reply_queue_len,
-	    (unsigned long)s->producer_pa, (unsigned long)s->consumer_pa);
-#endif
+    DPRINTF_MFI("MFI init firmware: queue at %lx len %d head %lx tail %lx\n",
+                (unsigned long)s->reply_queue_pa, s->reply_queue_len,
+                (unsigned long)s->producer_pa, (unsigned long)s->consumer_pa);
     s->reply_queue_index = ldl_phys(s->producer_pa);
     s->fw_state = MFI_FWSTATE_OPERATIONAL;
 out:
@@ -447,35 +461,33 @@  static int megasas_map_dcmd(struct megasas_cmd_t *cmd)
     uint16_t flags = le16_to_cpu(cmd->frame->header.flags);
     int is_sgl64 = (flags & MFI_FRAME_SGL64) ? 1 : 0;
 
-    if (cmd->frame->header.sge_count == 0) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("Zero DCMD sge count\n");
-#endif
-	cmd->iov_size = 0;
-	cmd->iov_buf = NULL;
-	return 0;
+    if (!cmd->frame->header.sge_count) {
+        DPRINTF_DCMD("Zero DCMD sge count\n");
+        cmd->iov_size = 0;
+        cmd->iov_buf = NULL;
+        return 0;
     } else if (cmd->frame->header.sge_count > 1) {
-	DPRINTF("Invalid DCMD sge count %d\n",
-		cmd->frame->header.sge_count);
-	return -1;
+        DPRINTF("Invalid DCMD sge count %d\n",
+                cmd->frame->header.sge_count);
+        return -1;
     }
     if (is_sgl64) {
-	iov_pa = le64_to_cpu(cmd->frame->dcmd.sgl.sg64[0].addr);
-	iov_size = le32_to_cpu(cmd->frame->dcmd.sgl.sg64[0].len);
+        iov_pa = le64_to_cpu(cmd->frame->dcmd.sgl.sg64[0].addr);
+        iov_size = le32_to_cpu(cmd->frame->dcmd.sgl.sg64[0].len);
     } else {
-	iov_pa = le32_to_cpu(cmd->frame->dcmd.sgl.sg32[0].addr);
-	iov_size = le32_to_cpu(cmd->frame->dcmd.sgl.sg32[0].len);
+        iov_pa = le32_to_cpu(cmd->frame->dcmd.sgl.sg32[0].addr);
+        iov_size = le32_to_cpu(cmd->frame->dcmd.sgl.sg32[0].len);
     }
     iov_size_p = iov_size;
     cmd->iov_buf = cpu_physical_memory_map(iov_pa, &iov_size_p, 1);
     if (iov_size_p != iov_size) {
-	DPRINTF("failed to map dcmd buffer\n");
-	if (cmd->iov_buf) {
-	    cpu_physical_memory_unmap(cmd->iov_buf, iov_size, 1, 0);
-	    cmd->iov_buf = NULL;
-	    cmd->iov_size = 0;
-	}
-	return -1;
+        DPRINTF("failed to map dcmd buffer\n");
+        if (cmd->iov_buf) {
+            cpu_physical_memory_unmap(cmd->iov_buf, iov_size, 1, 0);
+            cmd->iov_buf = NULL;
+            cmd->iov_size = 0;
+        }
+        return -1;
     }
     cmd->iov_size = iov_size;
     return iov_size;
@@ -488,17 +500,19 @@  static int megasas_finish_dcmd(struct megasas_cmd_t *cmd, uint32_t size)
     int sgl_addr_size = is_sgl64 ? sizeof(uint64_t) : sizeof(uint32_t);
 
     if (size > cmd->iov_size) {
-	DPRINTF("DCMD buffer overflow %u/%ld\n",
-		size, cmd->iov_size);
-	size = cmd->iov_size;
+        DPRINTF("DCMD buffer overflow %u/%ld\n",
+                size, cmd->iov_size);
+        size = cmd->iov_size;
+    }
+    if (!cmd->iov_buf) {
+        return 0;
     }
-    if (!cmd->iov_buf)
-	return 0;
 
     cpu_physical_memory_unmap(cmd->iov_buf, cmd->iov_size, 1, size);
-    if (cmd->iov_size > size)
-	stl_phys(cmd->pa + offsetof(struct mfi_dcmd_frame,sgl) + sgl_addr_size, size);
-
+    if (cmd->iov_size > size) {
+        stl_phys(cmd->pa + offsetof(struct mfi_dcmd_frame,sgl)
+                 + sgl_addr_size, size);
+    }
     return size;
 }
 
@@ -508,21 +522,18 @@  static int megasas_ctrl_get_info(MPTState *s, struct megasas_cmd_t *cmd)
     int n, num_ld_disks = 0;
 
     for (n = 0; n < s->fw_luns; n++) {
-	if (s->bus.devs[n])
-	    num_ld_disks++;
+        if (s->bus.devs[n])
+            num_ld_disks++;
     }
 
     memset(cmd->iov_buf, 0x0, cmd->iov_size);
     if (cmd->iov_size != sizeof(struct mfi_ctrl_info)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("Ctrl Get Info: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("Ctrl Get Info: invalid xfer_len %ld\n",
+                     cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("MFI DCMD get controller info\n");
-#endif
+    DPRINTF_DCMD("MFI DCMD get controller info\n");
     info->pci.vendor = PCI_VENDOR_ID_LSI_LOGIC;
     info->pci.device = PCI_DEVICE_ID_LSI_SAS1078;
     info->pci.subvendor = PCI_VENDOR_ID_LSI_LOGIC;
@@ -534,12 +545,12 @@  static int megasas_ctrl_get_info(MPTState *s, struct megasas_cmd_t *cmd)
     info->device.port_addr[0] = megasas_gen_sas_addr((unsigned long)s);
 
     memcpy(info->product_name,"MegaRAID SAS 8708EM2", 20);
-    sprintf(info->serial_number,"QEMU%08lx",(unsigned long)s & 0xFFFFFFFF);
-    sprintf(info->package_version,"%s-QEMU", QEMU_VERSION);
-    strcpy(info->image_component[0].name, "APP");
-    strcpy(info->image_component[0].version, MEGASAS_VERSION "-QEMU");
-    strcpy(info->image_component[0].build_date, __DATE__);
-    strcpy(info->image_component[0].build_time, __TIME__);
+    snprintf(info->serial_number, 32, "QEMU%08lx",(unsigned long)s & 0xFFFFFFFF);
+    snprintf(info->package_version, 0x60, "%s-QEMU", QEMU_VERSION);
+    memcpy(info->image_component[0].name, "APP", 8);
+    memcpy(info->image_component[0].version, MEGASAS_VERSION "-QEMU", 32);
+    memcpy(info->image_component[0].build_date, __DATE__, 16);
+    memcpy(info->image_component[0].build_time, __TIME__, 16);
     info->image_component_count = 1;
     info->current_fw_time = megasas_fw_time();
     info->max_arms = 32;
@@ -594,10 +605,8 @@  static int megasas_mfc_get_defaults(MPTState *s, struct megasas_cmd_t *cmd)
 
     memset(cmd->iov_buf, 0x0, cmd->iov_size);
     if (cmd->iov_size != sizeof(struct mfi_defaults)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("MFC Get defaults: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("MFC Get defaults: invalid xfer_len %ld\n", cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
     info->stripe_size = 3;
@@ -621,10 +630,8 @@  static int megasas_dcmd_get_bios_info(MPTState *s, struct megasas_cmd_t *cmd)
 
     memset(cmd->iov_buf, 0x0, cmd->iov_size);
     if (cmd->iov_size != sizeof(struct mfi_bios_data)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("Get BIOS info: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("Get BIOS info: invalid xfer_len %ld\n", cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
     info->continue_on_error = 1;
 
@@ -674,34 +681,29 @@  static int megasas_dcmd_pd_get_list(MPTState *s, struct megasas_cmd_t *cmd)
     memset(cmd->iov_buf, 0, cmd->iov_size);
     offset = 8;
     if (cmd->iov_size < (offset + sizeof(struct mfi_pd_address))) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("PD get list: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("PD get list: invalid xfer_len %ld\n", cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
     max_luns = (cmd->iov_size - offset) / sizeof(struct mfi_pd_address);
-    if (max_luns > s->fw_luns)
-	max_luns = s->fw_luns;
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("PD get list: returning info for %d PDs\n", max_luns);
-#endif
+    if (max_luns > s->fw_luns) {
+        max_luns = s->fw_luns;
+    }
+    DPRINTF_DCMD("PD get list: returning info for %d PDs\n", max_luns);
 
     for (dev_id = 0; dev_id < max_luns; dev_id++) {
-	SCSIDevice *sdev;
-
-	sdev = s->bus.devs[dev_id];
-	if (sdev) {
-	    info->addr[num_pd_disks].device_id = dev_id;
-	    info->addr[num_pd_disks].encl_device_id = dev_id;
-	    info->addr[num_pd_disks].sas_addr[0] = megasas_gen_sas_addr((unsigned long)sdev);
-	    num_pd_disks ++;
-	    offset += sizeof(struct mfi_pd_address);
-	}
+        SCSIDevice *sdev;
+
+        sdev = s->bus.devs[dev_id];
+        if (sdev) {
+            info->addr[num_pd_disks].device_id = dev_id;
+            info->addr[num_pd_disks].encl_device_id = dev_id;
+            info->addr[num_pd_disks].sas_addr[0] = megasas_gen_sas_addr((unsigned long)sdev);
+            num_pd_disks ++;
+            offset += sizeof(struct mfi_pd_address);
+        }
     }
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("PD get list: %d PDs, size %d\n", num_pd_disks, offset);
-#endif
+    DPRINTF_DCMD("PD get list: %d PDs, size %d\n", num_pd_disks, offset);
 
     info->size = offset;
     info->count = num_pd_disks;
@@ -716,56 +718,52 @@  static int megasas_dcmd_pd_list_query(MPTState *s, struct megasas_cmd_t *cmd)
     /* mbox0 contains flags */
     flags = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("PD query list: flags %x\n", flags);
-#endif
+    DPRINTF_DCMD("PD query list: flags %x\n", flags);
 
-    if (flags == MR_PD_QUERY_TYPE_ALL || s->is_jbod)
-	return megasas_dcmd_pd_get_list(s, cmd);
+    if (flags == MR_PD_QUERY_TYPE_ALL || s->is_jbod) {
+        return megasas_dcmd_pd_get_list(s, cmd);
+    }
 
     return MFI_STAT_OK;
 }
 
 static int megasas_pd_get_info_submit(SCSIDevice * sdev, int lun,
-				      struct megasas_cmd_t *cmd)
+                                      struct megasas_cmd_t *cmd)
 {
     struct mfi_pd_info * info = cmd->iov_buf;
     SCSIRequest *req;
 
     if (info->inquiry_data[4] == 0) {
-	/* Additional length is zero, resubmit */
-	req = scsi_req_get(sdev, (uint32_t) -1, lun);
-	if (!req)
-	    return MFI_STAT_FLASH_ALLOC_FAIL;
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("PD get info submit std inquiry to dev %d\n", lun);
-#endif
-	req->hba_private = cmd;
-	megasas_setup_inquiry(req, 0, info->inquiry_data,
-			      sizeof(info->inquiry_data));
-	return MFI_STAT_INVALID_STATUS;
+        /* Additional length is zero, resubmit */
+        req = scsi_req_get(sdev, (uint32_t) -1, lun);
+        if (!req) {
+            return MFI_STAT_FLASH_ALLOC_FAIL;
+        }
+        DPRINTF_DCMD("PD get info submit std inquiry to dev %d\n", lun);
+        req->hba_private = cmd;
+        megasas_setup_inquiry(req, 0, info->inquiry_data,
+                              sizeof(info->inquiry_data));
+        return MFI_STAT_INVALID_STATUS;
     } else if (info->vpd_page83[3] == 0) {
-	/* Additional length is zero, resubmit */
-	req = scsi_req_get(sdev, (uint32_t) -1, lun);
-	if (!req)
-	    return MFI_STAT_FLASH_ALLOC_FAIL;
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("PD get info submit vpd inquiry to dev %d\n", lun);
-#endif
-	req->hba_private = cmd;
-	megasas_setup_inquiry(req, 0x83,(uint8_t *)info->vpd_page83,
-			      sizeof(info->vpd_page83));
-	return MFI_STAT_INVALID_STATUS;
+        /* Additional length is zero, resubmit */
+        req = scsi_req_get(sdev, (uint32_t) -1, lun);
+        if (!req) {
+            return MFI_STAT_FLASH_ALLOC_FAIL;
+        }
+        DPRINTF_DCMD("PD get info submit vpd inquiry to dev %d\n", lun);
+        req->hba_private = cmd;
+        megasas_setup_inquiry(req, 0x83,(uint8_t *)info->vpd_page83,
+                              sizeof(info->vpd_page83));
+        return MFI_STAT_INVALID_STATUS;
     }
 
     /* Finished, set FW state */
-    if (cmd->state->is_jbod)
-	info->fw_state = MFI_PD_STATE_SYSTEM;
-    else
-	info->fw_state = MFI_PD_STATE_ONLINE;
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("PD get info set state for dev %d to %x\n", lun, info->fw_state);
-#endif
+    if (cmd->state->is_jbod) {
+        info->fw_state = MFI_PD_STATE_SYSTEM;
+    } else {
+        info->fw_state = MFI_PD_STATE_ONLINE;
+    }
+    DPRINTF_DCMD("PD get info set state for dev %d to %x\n", lun, info->fw_state);
     return MFI_STAT_OK;
 }
 
@@ -779,33 +777,30 @@  static int megasas_dcmd_pd_get_info(MPTState *s, struct megasas_cmd_t *cmd)
 
     memset(cmd->iov_buf, 0, cmd->iov_size);
     if (cmd->iov_size != sizeof(struct mfi_pd_info)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("PD get info: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("PD get info: invalid xfer_len %ld\n", cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
     /* mbox0 has the ID */
     pd_id = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("PD get info for dev %d\n", pd_id);
-#endif
+    DPRINTF_DCMD("PD get info for dev %d\n", pd_id);
+
     sdev = s->bus.devs[pd_id];
     info->ref.v.device_id = pd_id;
 
     if (sdev) {
-	info->state.ddf.v.pd_type.in_vd = 1;
-	info->state.ddf.v.pd_type.intf = 0x2;
-	bdrv_get_geometry(sdev->conf.dinfo->bdrv, &pd_size);
-	info->raw_size = pd_size;
-	info->non_coerced_size = pd_size;
-	info->coerced_size = pd_size;
-	info->fw_state = MFI_PD_STATE_OFFLINE;
-	info->path_info.count = 1;
-	info->path_info.sas_addr[0] = megasas_gen_sas_addr((unsigned long)sdev);
-	/* Submit inquiry */
-	retval = megasas_pd_get_info_submit(cmd->sdev, pd_id, cmd);
+        info->state.ddf.v.pd_type.in_vd = 1;
+        info->state.ddf.v.pd_type.intf = 0x2;
+        bdrv_get_geometry(sdev->conf.dinfo->bdrv, &pd_size);
+        info->raw_size = pd_size;
+        info->non_coerced_size = pd_size;
+        info->coerced_size = pd_size;
+        info->fw_state = MFI_PD_STATE_OFFLINE;
+        info->path_info.count = 1;
+        info->path_info.sas_addr[0] = megasas_gen_sas_addr((unsigned long)sdev);
+        /* Submit inquiry */
+        retval = megasas_pd_get_info_submit(cmd->sdev, pd_id, cmd);
     }
 
     return retval;
@@ -814,64 +809,55 @@  static int megasas_dcmd_pd_get_info(MPTState *s, struct megasas_cmd_t *cmd)
 static int megasas_dcmd_ld_get_list(MPTState *s, struct megasas_cmd_t *cmd)
 {
     struct mfi_ld_list *info = cmd->iov_buf;
-    uint32_t num_ld_disks = 0, max_ld_disks = s->fw_luns;
+    uint32_t num_ld_disks = 0, max_ld_disks = s->is_jbod ? 0 : s->fw_luns;
     uint64_t ld_size;
     uint8_t n;
     int offset;
 
     memset(cmd->iov_buf, 0, cmd->iov_size);
     if (cmd->iov_size != sizeof(struct mfi_ld_list)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("LD get list: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("LD get list: invalid xfer_len %ld\n", cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
-    if (s->is_jbod)
-	max_ld_disks = 0;
+    DPRINTF_DCMD("LD get list: returning info for %d LDs\n", max_ld_disks);
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("LD get list: returning info for %d LDs\n", max_ld_disks);
-#endif
     for (n = 0; n < max_ld_disks; n++) {
-	SCSIDevice *sdev;
-
-	sdev = s->bus.devs[n];
-	if (sdev) {
-	    bdrv_get_geometry(sdev->conf.dinfo->bdrv, &ld_size);
-	    ld_size *= 512;
-	    info->ld_list[num_ld_disks].ld.v.target_id = n;
-	    info->ld_list[num_ld_disks].state = MFI_LD_STATE_OPTIMAL;
-	    info->ld_list[num_ld_disks].size = ld_size;
-	    num_ld_disks ++;
-	    offset += 18;
-	}
+        SCSIDevice *sdev;
+
+        sdev = s->bus.devs[n];
+        if (sdev) {
+            bdrv_get_geometry(sdev->conf.dinfo->bdrv, &ld_size);
+            ld_size *= 512;
+            info->ld_list[num_ld_disks].ld.v.target_id = n;
+            info->ld_list[num_ld_disks].state = MFI_LD_STATE_OPTIMAL;
+            info->ld_list[num_ld_disks].size = ld_size;
+            num_ld_disks ++;
+            offset += 18;
+        }
     }
     info->ld_count = num_ld_disks;
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("LD get list: found %d LDs\n", num_ld_disks);
-#endif
+    DPRINTF_DCMD("LD get list: found %d LDs\n", num_ld_disks);
 
     return MFI_STAT_OK;
 }
 
 static int megasas_ld_get_info_submit(SCSIDevice * sdev, int lun,
-				      struct megasas_cmd_t *cmd)
+                                      struct megasas_cmd_t *cmd)
 {
     struct mfi_ld_info * info = cmd->iov_buf;
     SCSIRequest *req;
 
     if (info->vpd_page83[3] == 0) {
-	req = scsi_req_get(sdev, (uint32_t) -1, lun);
-	if (!req)
-	    return MFI_STAT_FLASH_ALLOC_FAIL;
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("LD get info submit vpd inquiry to dev %d\n", lun);
-#endif
-	req->hba_private = cmd;
-	megasas_setup_inquiry(req, 0x83,(uint8_t *)info->vpd_page83,
-			      sizeof(info->vpd_page83));
-	return MFI_STAT_INVALID_STATUS;
+        req = scsi_req_get(sdev, (uint32_t) -1, lun);
+        if (!req) {
+            return MFI_STAT_FLASH_ALLOC_FAIL;
+        }
+        DPRINTF_DCMD("LD get info submit vpd inquiry to dev %d\n", lun);
+        req->hba_private = cmd;
+        megasas_setup_inquiry(req, 0x83,(uint8_t *)info->vpd_page83,
+                              sizeof(info->vpd_page83));
+        return MFI_STAT_INVALID_STATUS;
     }
     info->ld_config.params.state = MFI_LD_STATE_OPTIMAL;
     return MFI_STAT_OK;
@@ -887,29 +873,26 @@  static int megasas_dcmd_ld_get_info(MPTState *s, struct megasas_cmd_t *cmd)
 
     memset(cmd->iov_buf, 0, cmd->iov_size);
     if (cmd->iov_size != sizeof(struct mfi_ld_info)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("LD get info: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("LD get info: invalid xfer_len %ld\n", cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
     /* mbox0 has the ID */
     ld_id = le16_to_cpu(cmd->frame->dcmd.mbox[0]);
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("LD get info for dev %d\n", ld_id);
-#endif
+    DPRINTF_DCMD("LD get info for dev %d\n", ld_id);
+
     sdev = s->bus.devs[ld_id];
     info->ld_config.properties.ld.v.target_id = ld_id;
 
     if (sdev) {
-	info->ld_config.params.stripe_size = 3;
-	info->ld_config.params.num_drives = 1;
-	info->ld_config.params.state = MFI_LD_STATE_OFFLINE;
-	info->ld_config.params.is_consistent = 1;
-	bdrv_get_geometry(sdev->conf.dinfo->bdrv, &ld_size);
-	info->size = ld_size;
-	retval = megasas_ld_get_info_submit(cmd->sdev, ld_id, cmd);
+        info->ld_config.params.stripe_size = 3;
+        info->ld_config.params.num_drives = 1;
+        info->ld_config.params.state = MFI_LD_STATE_OFFLINE;
+        info->ld_config.params.is_consistent = 1;
+        bdrv_get_geometry(sdev->conf.dinfo->bdrv, &ld_size);
+        info->size = ld_size;
+        retval = megasas_ld_get_info_submit(cmd->sdev, ld_id, cmd);
     }
 
     return retval;
@@ -920,16 +903,12 @@  static int megasas_dcmd_get_properties(MPTState *s, struct megasas_cmd_t *cmd)
     struct mfi_ctrl_props *info = cmd->iov_buf;
 
     if (cmd->iov_size != sizeof(struct mfi_ctrl_props)) {
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("DCMD get properties: invalid xfer_len %ld\n", cmd->iov_size);
-#endif
-	memset(cmd->iov_buf, 0, cmd->iov_size);
-	return MFI_STAT_INVALID_PARAMETER;
+        DPRINTF_DCMD("DCMD get properties: invalid xfer_len %ld\n", cmd->iov_size);
+        memset(cmd->iov_buf, 0, cmd->iov_size);
+        return MFI_STAT_INVALID_PARAMETER;
     }
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("DCMD get properties\n");
-#endif
+    DPRINTF_DCMD("DCMD get properties\n");
     info->pred_fail_poll_interval = 300;
     info->intr_throttle_cnt = 16;
     info->intr_throttle_timeout = 50;
@@ -950,18 +929,14 @@  static int megasas_dcmd_get_properties(MPTState *s, struct megasas_cmd_t *cmd)
 
 static int megasas_cache_flush(MPTState *s, struct megasas_cmd_t *cmd)
 {
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("MFI DCMD Cache flush\n");
-#endif
+    DPRINTF_DCMD("MFI DCMD Cache flush\n");
     qemu_aio_flush();
     return MFI_STAT_OK;
 }
 
 static int megasas_ctrl_shutdown(MPTState *s, struct megasas_cmd_t *cmd)
 {
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("MFI DCMD Controller shutdown\n");
-#endif
+    DPRINTF_DCMD("MFI DCMD Controller shutdown\n");
     s->fw_state = MFI_FWSTATE_READY;
     return MFI_STAT_OK;
 }
@@ -970,50 +945,46 @@  static int megasas_dcmd_set_properties(MPTState *s, struct megasas_cmd_t *cmd)
 {
     uint8_t *dummy;
 
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("DCMD set properties\n");
-#endif
+    DPRINTF_DCMD("DCMD set properties\n");
     dummy = cmd->iov_buf;
-    DPRINTF("Properties dump\n");
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x00], dummy[0x01], dummy[0x02], dummy[0x03],
-	    dummy[0x04], dummy[0x05], dummy[0x06], dummy[0x07]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x08], dummy[0x09], dummy[0x0a], dummy[0x0b],
-	    dummy[0x0c], dummy[0x0d], dummy[0x0e], dummy[0x0f]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x10], dummy[0x11], dummy[0x12], dummy[0x13],
-	    dummy[0x14], dummy[0x15], dummy[0x16], dummy[0x17]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x18], dummy[0x19], dummy[0x1a], dummy[0x1b],
-	    dummy[0x1c], dummy[0x1d], dummy[0x1e], dummy[0x1f]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x20], dummy[0x21], dummy[0x22], dummy[0x23],
-	    dummy[0x24], dummy[0x25], dummy[0x26], dummy[0x27]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x28], dummy[0x29], dummy[0x2a], dummy[0x2b],
-	    dummy[0x2c], dummy[0x2d], dummy[0x2e], dummy[0x2f]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x30], dummy[0x31], dummy[0x32], dummy[0x33],
-	    dummy[0x34], dummy[0x35], dummy[0x36], dummy[0x37]);
-    DPRINTF("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
-	    dummy[0x38], dummy[0x39], dummy[0x3a], dummy[0x3b],
-	    dummy[0x3c], dummy[0x3d], dummy[0x3e], dummy[0x3f]);
+    DPRINTF_DCMD("Properties dump\n");
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x00], dummy[0x01], dummy[0x02], dummy[0x03],
+            dummy[0x04], dummy[0x05], dummy[0x06], dummy[0x07]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x08], dummy[0x09], dummy[0x0a], dummy[0x0b],
+            dummy[0x0c], dummy[0x0d], dummy[0x0e], dummy[0x0f]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x10], dummy[0x11], dummy[0x12], dummy[0x13],
+            dummy[0x14], dummy[0x15], dummy[0x16], dummy[0x17]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x18], dummy[0x19], dummy[0x1a], dummy[0x1b],
+            dummy[0x1c], dummy[0x1d], dummy[0x1e], dummy[0x1f]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x20], dummy[0x21], dummy[0x22], dummy[0x23],
+            dummy[0x24], dummy[0x25], dummy[0x26], dummy[0x27]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x28], dummy[0x29], dummy[0x2a], dummy[0x2b],
+            dummy[0x2c], dummy[0x2d], dummy[0x2e], dummy[0x2f]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x30], dummy[0x31], dummy[0x32], dummy[0x33],
+            dummy[0x34], dummy[0x35], dummy[0x36], dummy[0x37]);
+    DPRINTF_DCMD("%02x %02x %02x %0x2 %02x %02x %02x %02x\n",
+            dummy[0x38], dummy[0x39], dummy[0x3a], dummy[0x3b],
+            dummy[0x3c], dummy[0x3d], dummy[0x3e], dummy[0x3f]);
     return MFI_STAT_OK;
 }
 
 static int megasas_dcmd_dummy(MPTState *s, struct megasas_cmd_t *cmd)
 {
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("DCMD dummy: xfer_len %ld\n", cmd->iov_size);
-#endif
+    DPRINTF_DCMD("DCMD dummy: xfer_len %ld\n", cmd->iov_size);
     memset(cmd->iov_buf, 0, cmd->iov_size);
 
     return MFI_STAT_OK;
 }
 
 
-struct dcmd_cmd_tbl_t {
+static const struct dcmd_cmd_tbl_t {
     int opcode;
     int (*func)(MPTState *s, struct megasas_cmd_t *cmd);
 } dcmd_cmd_tbl[] = {
@@ -1069,35 +1040,32 @@  static int megasas_handle_dcmd(MPTState *s, struct megasas_cmd_t *cmd)
 {
     int opcode, size = 0, len;
     int retval = 0;
-    struct dcmd_cmd_tbl_t *cmdptr = dcmd_cmd_tbl;
+    const struct dcmd_cmd_tbl_t *cmdptr = dcmd_cmd_tbl;
 
     opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("frame %d: MFI DCMD opcode %x\n", cmd->index, opcode);
-#endif
+    DPRINTF_DCMD("frame %d: MFI DCMD opcode %x\n", cmd->index, opcode);
     len = megasas_map_dcmd(cmd);
     if (len < 0) {
-	return MFI_STAT_MEMORY_NOT_AVAILABLE;
+        return MFI_STAT_MEMORY_NOT_AVAILABLE;
+    }
+    while (cmdptr->opcode != -1 && cmdptr->opcode != opcode) {
+        cmdptr++;
     }
-    while (cmdptr->opcode != -1 && cmdptr->opcode != opcode)
-	cmdptr++;
     if (cmdptr->opcode == -1) {
-	DPRINTF("MFI DCMD %x unhandled (len %d)\n", opcode, len);
-	retval = megasas_dcmd_dummy(s, cmd);
+        DPRINTF("MFI DCMD %x unhandled (len %d)\n", opcode, len);
+        retval = megasas_dcmd_dummy(s, cmd);
     } else {
-	retval = cmdptr->func(s, cmd);
+        retval = cmdptr->func(s, cmd);
     }
     if (retval != MFI_STAT_INVALID_STATUS) {
-	size = megasas_finish_dcmd(cmd, cmd->iov_size);
-#ifdef DEBUG_MEGASAS_DCMD
-	DPRINTF("MFI DCMD wrote %d bytes\n", size);
-#endif
+        size = megasas_finish_dcmd(cmd, cmd->iov_size);
+        DPRINTF_DCMD("MFI DCMD wrote %d bytes\n", size);
     }
     return retval;
 }
 
 static int megasas_finish_internal_dcmd(struct megasas_cmd_t *cmd,
-					SCSIRequest *req)
+                                        SCSIRequest *req)
 {
     int opcode;
     int retval = MFI_STAT_OK;
@@ -1105,31 +1073,24 @@  static int megasas_finish_internal_dcmd(struct megasas_cmd_t *cmd,
 
     opcode = le32_to_cpu(cmd->frame->dcmd.opcode);
     scsi_req_put(req);
-#ifdef DEBUG_MEGASAS_DCMD
-    DPRINTF("DCMD finish internal cmd %x lun %d\n", opcode, lun);
-#endif
+    DPRINTF_DCMD("DCMD finish internal cmd %x lun %d\n", opcode, lun);
     switch (opcode) {
-	case MFI_DCMD_PD_GET_INFO:
-#ifdef DEBUG_MEGASAS_DCMD
-	    DPRINTF("Internal DCMD PD get info\n");
-#endif
-	    retval = megasas_pd_get_info_submit(cmd->sdev, lun, cmd);
-	    break;
-	case MFI_DCMD_LD_GET_INFO:
-#ifdef DEBUG_MEGASAS_DCMD
-	    DPRINTF("Internal DCMD LD get info\n");
-#endif
-	    retval = megasas_ld_get_info_submit(cmd->sdev, lun, cmd);
-	    break;
-	default:
-#ifdef DEBUG_MEGASAS_DCMD
-	    DPRINTF("Invalid internal DCMD\n");
-#endif
-	    retval = MFI_STAT_INVALID_DCMD;
-	    break;
+        case MFI_DCMD_PD_GET_INFO:
+            DPRINTF_DCMD("Internal DCMD PD get info\n");
+            retval = megasas_pd_get_info_submit(cmd->sdev, lun, cmd);
+            break;
+        case MFI_DCMD_LD_GET_INFO:
+            DPRINTF_DCMD("Internal DCMD LD get info\n");
+            retval = megasas_ld_get_info_submit(cmd->sdev, lun, cmd);
+            break;
+        default:
+            DPRINTF_DCMD("Invalid internal DCMD\n");
+            retval = MFI_STAT_INVALID_DCMD;
+            break;
+    }
+    if (retval != MFI_STAT_INVALID_STATUS) {
+        megasas_finish_dcmd(cmd, cmd->iov_size);
     }
-    if (retval != MFI_STAT_INVALID_STATUS)
-	megasas_finish_dcmd(cmd, cmd->iov_size);
     return retval;
 }
 
@@ -1139,46 +1100,43 @@  static int megasas_handle_scsi(MPTState *s, struct megasas_cmd_t *cmd, int is_lo
 
     cdb = cmd->frame->pass.cdb;
 
-    if (cmd->frame->header.target_id < s->fw_luns)
-	cmd->sdev = s->bus.devs[cmd->frame->header.target_id];
+    if (cmd->frame->header.target_id < s->fw_luns) {
+        cmd->sdev = s->bus.devs[cmd->frame->header.target_id];
+    }
 
-#ifdef DEBUG_MEGASAS_IO
-    DPRINTF("%s %s dev %x lun %x sdev %p xfer %d\n",
-	    mfi_frame_desc[cmd->frame->header.frame_cmd],
-	    is_logical?"logical":"physical",
-	    cmd->frame->header.target_id, cmd->frame->header.lun_id,
-	    cmd->sdev, cmd->frame->header.data_len);
-#endif
+    DPRINTF_IO("%s %s dev %x lun %x sdev %p xfer %d\n",
+               mfi_frame_desc[cmd->frame->header.frame_cmd],
+               is_logical ? "logical" : "physical",
+               cmd->frame->header.target_id, cmd->frame->header.lun_id,
+               cmd->sdev, cmd->frame->header.data_len);
 
     if (!cmd->sdev || (s->is_jbod && is_logical)) {
-#ifdef DEBUG_MEGASAS_IO
-	DPRINTF("%s %s dev %x/%x target not present\n",
-		mfi_frame_desc[cmd->frame->header.frame_cmd],
-		is_logical?"logical":"physical",
-		cmd->frame->header.target_id,
-		cmd->frame->header.lun_id);
-#endif
-	return MFI_STAT_DEVICE_NOT_FOUND;
+        DPRINTF_IO("%s %s dev %x/%x target not present\n",
+                   mfi_frame_desc[cmd->frame->header.frame_cmd],
+                   is_logical ? "logical" : "physical",
+                   cmd->frame->header.target_id,
+                   cmd->frame->header.lun_id);
+        return MFI_STAT_DEVICE_NOT_FOUND;
     }
 
     if (cmd->frame->header.cdb_len > 16) {
-	DPRINTF("%s dev %x/%x invalid cdb len %d\n",
-		mfi_frame_desc[cmd->frame->header.frame_cmd],
-		cmd->frame->header.target_id, cmd->frame->header.lun_id,
-		cmd->frame->header.cdb_len);
-	megasas_build_sense(cmd, SENSE_CODE(INVALID_OPCODE));
-	megasas_frame_set_scsi_status(cmd->pa, CHECK_CONDITION << 1);
-	s->event_count++;
-	return MFI_STAT_SCSI_DONE_WITH_ERROR;
+        DPRINTF("%s dev %x/%x invalid cdb len %d\n",
+                mfi_frame_desc[cmd->frame->header.frame_cmd],
+                cmd->frame->header.target_id, cmd->frame->header.lun_id,
+                cmd->frame->header.cdb_len);
+        megasas_build_sense(cmd, SENSE_CODE(INVALID_OPCODE));
+        megasas_frame_set_scsi_status(cmd->pa, CHECK_CONDITION << 1);
+        s->event_count++;
+        return MFI_STAT_SCSI_DONE_WITH_ERROR;
     }
 
     cmd->req = scsi_req_get(cmd->sdev, cmd->frame->header.context, cmd->frame->header.lun_id);
     cmd->req->hba_private = cmd;
     scsi_req_parse(cmd->req, cdb);
     if (cmd->frame->header.data_len != cmd->req->cmd.xfer) {
-	DPRINTF("xfer length mismatch, frame %u cdb %u\n",
-		cmd->frame->header.data_len, (unsigned)cmd->req->cmd.xfer);
-	s->event_count++;
+        DPRINTF("xfer length mismatch, frame %u cdb %u\n",
+                cmd->frame->header.data_len, (unsigned)cmd->req->cmd.xfer);
+        s->event_count++;
     }
 
     megasas_map_sgl(cmd, offsetof(struct mfi_pass_frame, sgl));
@@ -1198,33 +1156,30 @@  static int megasas_handle_io(MPTState *s, struct megasas_cmd_t *cmd)
     lba_start_hi = le32_to_cpu(cmd->frame->io.lba_hi);
     lba_start = ((uint64_t)lba_start_hi << 32) | lba_start_lo;
 
-    if (cmd->frame->header.target_id < s->fw_luns)
-	cmd->sdev = s->bus.devs[cmd->frame->header.target_id];
+    if (cmd->frame->header.target_id < s->fw_luns) {
+        cmd->sdev = s->bus.devs[cmd->frame->header.target_id];
+    }
 
-#ifdef DEBUG_MEGASAS_IO
-    DPRINTF("%s dev %x lun %x lba %lx count %lx\n",
-	    mfi_frame_desc[cmd->frame->header.frame_cmd],
-	    cmd->frame->header.target_id, cmd->frame->header.lun_id,
-	    (unsigned long)lba_start, (unsigned long)lba_count);
-#endif
+    DPRINTF_IO("%s dev %x lun %x lba %lx count %lx\n",
+               mfi_frame_desc[cmd->frame->header.frame_cmd],
+               cmd->frame->header.target_id, cmd->frame->header.lun_id,
+               (unsigned long)lba_start, (unsigned long)lba_count);
     if (!cmd->sdev) {
-#ifdef DEBUG_MEGSAS_IO
-	DPRINTF("%s dev %x/%x LUN not present\n",
-		mfi_frame_desc[cmd->frame->header.frame_cmd],
-		cmd->frame->header.target_id, cmd->frame->header.lun_id);
-#endif
-	return MFI_STAT_DEVICE_NOT_FOUND;
+        DPRINTF_IO("%s dev %x/%x LUN not present\n",
+                   mfi_frame_desc[cmd->frame->header.frame_cmd],
+                   cmd->frame->header.target_id, cmd->frame->header.lun_id);
+        return MFI_STAT_DEVICE_NOT_FOUND;
     }
 
     if (cmd->frame->header.cdb_len > 16) {
-	DPRINTF("%s dev %x/%x invalid cdb len %d\n",
-		mfi_frame_desc[cmd->frame->header.frame_cmd],
-		cmd->frame->header.target_id, cmd->frame->header.lun_id,
-		cmd->frame->header.cdb_len);
-	megasas_build_sense(cmd, SENSE_CODE(INVALID_OPCODE));
-	megasas_frame_set_scsi_status(cmd->pa, CHECK_CONDITION << 1);
-	s->event_count++;
-	return MFI_STAT_SCSI_DONE_WITH_ERROR;
+        DPRINTF("%s dev %x/%x invalid cdb len %d\n",
+                mfi_frame_desc[cmd->frame->header.frame_cmd],
+                cmd->frame->header.target_id, cmd->frame->header.lun_id,
+                cmd->frame->header.cdb_len);
+        megasas_build_sense(cmd, SENSE_CODE(INVALID_OPCODE));
+        megasas_frame_set_scsi_status(cmd->pa, CHECK_CONDITION << 1);
+        s->event_count++;
+        return MFI_STAT_SCSI_DONE_WITH_ERROR;
     }
 
     cmd->req = scsi_req_get(cmd->sdev, cmd->frame->header.context, cmd->frame->header.lun_id);
@@ -1238,16 +1193,16 @@  static int megasas_handle_io(MPTState *s, struct megasas_cmd_t *cmd)
 }
 
 static int megasas_finish_internal_command(struct megasas_cmd_t *cmd,
-					   SCSIRequest *req)
+                                           SCSIRequest *req)
 {
     int retval = MFI_STAT_INVALID_CMD;
 
     switch (cmd->frame->header.frame_cmd) {
-	case MFI_CMD_DCMD:
-	    retval = megasas_finish_internal_dcmd(cmd, req);
-	    break;
-	default:
-	    break;
+        case MFI_CMD_DCMD:
+            retval = megasas_finish_internal_dcmd(cmd, req);
+            break;
+        default:
+            break;
     }
     return retval;
 }
@@ -1260,46 +1215,44 @@  static void megasas_command_complete(SCSIRequest *req)
 
     cmd = req->hba_private;
     if (!cmd) {
-	/*
+        /*
 	 * Bad. A command has been completed but we couldn't find it.
 	 * Only safe way out of here is to terminate everything and
 	 * hope the HBA recovers.
 	 */
-	DPRINTF("SCSI request tag %x not found", req->tag);
-	return;
+        DPRINTF("SCSI request tag %x not found", req->tag);
+        return;
     }
 
     if (cmd->req != req) {
-	/*
+        /*
 	 * Internal command complete
 	 */
-	cmd_status = megasas_finish_internal_command(cmd, req);
-	if (cmd_status == MFI_STAT_INVALID_STATUS)
-	    return;
+        cmd_status = megasas_finish_internal_command(cmd, req);
+        if (cmd_status == MFI_STAT_INVALID_STATUS) {
+            return;
+        }
     } else {
-
-#ifdef DEBUG_MEGASAS_IO
-	DPRINTF("%s req %p cmd %p lun %p finished with status %x len %u\n",
-		mfi_frame_desc[cmd->frame->header.frame_cmd], req, cmd, cmd->sdev,
-		req->status, (unsigned)req->xferlen);
-#endif
-	if (req->status == CHECK_CONDITION << 1) {
-	    megasas_build_sense(cmd, cmd->sdev->sense);
-	    cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
-	    scsi_dev_clear_sense(cmd->sdev);
-	}
-
-	megasas_unmap_sgl(cmd);
-	megasas_frame_set_scsi_status(cmd->pa, cmd->req->status);
-	scsi_req_put(cmd->req);
-	cmd->req = NULL;
+        DPRINTF_IO("%s req %p cmd %p lun %p finished with status %x len %u\n",
+                   mfi_frame_desc[cmd->frame->header.frame_cmd], req, cmd, cmd->sdev,
+                   req->status, (unsigned)req->xferlen);
+        if (req->status == CHECK_CONDITION << 1) {
+            megasas_build_sense(cmd, cmd->sdev->sense);
+            cmd_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
+            scsi_dev_clear_sense(cmd->sdev);
+        }
+
+        megasas_unmap_sgl(cmd);
+        megasas_frame_set_scsi_status(cmd->pa, cmd->req->status);
+        scsi_req_put(cmd->req);
+        cmd->req = NULL;
     }
     context = megasas_finish_command(cmd->state, cmd);
     if (context == -1) {
-	DPRINTF("Invalid context for cmd %p\n", cmd);
+        DPRINTF("Invalid context for cmd %p\n", cmd);
     } else {
-	megasas_frame_set_cmd_status(cmd->pa, cmd_status);
-	megasas_dequeue_frame(cmd->state, context);
+        megasas_frame_set_cmd_status(cmd->pa, cmd_status);
+        megasas_dequeue_frame(cmd->state, context);
     }
 }
 
@@ -1315,15 +1268,15 @@  static int megasas_handle_abort(MPTState *s, struct megasas_cmd_t *cmd)
 
     abort_cmd = megasas_lookup_frame(s, abort_addr);
     if (!abort_cmd) {
-	DPRINTF("No active command for frame context %x\n", abort_ctx);
-	s->event_count++;
-	return MFI_STAT_OK;
+        DPRINTF("No active command for frame context %x\n", abort_ctx);
+        s->event_count++;
+        return MFI_STAT_OK;
     }
     if (abort_cmd->frame->header.context != abort_ctx) {
-	DPRINTF("abort frame %x: invalid context %x\n", abort_cmd->index,
-		abort_cmd->frame->header.context);
-	s->event_count++;
-	return MFI_STAT_ABORT_NOT_POSSIBLE;
+        DPRINTF("abort frame %x: invalid context %x\n", abort_cmd->index,
+                abort_cmd->frame->header.context);
+        s->event_count++;
+        return MFI_STAT_ABORT_NOT_POSSIBLE;
     }
     DPRINTF("aborting frame %x\n", abort_cmd->index);
     megasas_dump_frame(abort_cmd);
@@ -1333,7 +1286,7 @@  static int megasas_handle_abort(MPTState *s, struct megasas_cmd_t *cmd)
 }
 
 static void megasas_handle_frame(MPTState *s, target_phys_addr_t frame_addr,
-				 uint32_t frame_count)
+                                 uint32_t frame_count)
 {
     uint8_t frame_cmd;
     uint8_t frame_status = MFI_STAT_INVALID_CMD;
@@ -1343,66 +1296,60 @@  static void megasas_handle_frame(MPTState *s, target_phys_addr_t frame_addr,
     frame_cmd = megasas_frame_get_cmd(frame_addr);
     frame_context = megasas_frame_get_context(frame_addr);
 
-#ifdef DEBUG_MEGASAS_MFI
-    DPRINTF("MFI cmd %x context %x count %d\n",
-	    frame_cmd, frame_context, frame_count);
-#endif
+    DPRINTF_MFI("MFI cmd %x context %x count %d\n",
+                frame_cmd, frame_context, frame_count);
 
     cmd = megasas_enqueue_frame(s, frame_addr);
     if (!cmd) {
-	/* reply queue full */
-	megasas_frame_set_scsi_status(frame_addr, BUSY << 1);
-	frame_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
-	s->event_count++;
-	goto frame_done;
+        /* reply queue full */
+        megasas_frame_set_scsi_status(frame_addr, BUSY << 1);
+        frame_status = MFI_STAT_SCSI_DONE_WITH_ERROR;
+        s->event_count++;
+        goto frame_done;
     }
     switch (cmd->frame->header.frame_cmd) {
-	case MFI_CMD_INIT:
-	    megasas_init_firmware(s, cmd);
-	    frame_status = MFI_STAT_OK;
-	    break;
-	case MFI_CMD_DCMD:
-	    frame_status = megasas_handle_dcmd(s, cmd);
-	    break;
-	case MFI_CMD_ABORT:
-	    frame_status = megasas_handle_abort(s, cmd);
-	    break;
-	case MFI_CMD_PD_SCSI_IO:
-	    frame_status = megasas_handle_scsi(s, cmd, 0);
-	    break;
-	case MFI_CMD_LD_SCSI_IO:
-	    frame_status = megasas_handle_scsi(s, cmd, 1);
-	    break;
-	case MFI_CMD_LD_READ:
-	case MFI_CMD_LD_WRITE:
-	    frame_status = megasas_handle_io(s, cmd);
-	    break;
-	default:
-	    DPRINTF("Unhandled MFI cmd %x\n", cmd->frame->header.frame_cmd);
-	    s->event_count++;
-	    break;
+        case MFI_CMD_INIT:
+            megasas_init_firmware(s, cmd);
+            frame_status = MFI_STAT_OK;
+            break;
+        case MFI_CMD_DCMD:
+            frame_status = megasas_handle_dcmd(s, cmd);
+            break;
+        case MFI_CMD_ABORT:
+            frame_status = megasas_handle_abort(s, cmd);
+            break;
+        case MFI_CMD_PD_SCSI_IO:
+            frame_status = megasas_handle_scsi(s, cmd, 0);
+            break;
+        case MFI_CMD_LD_SCSI_IO:
+            frame_status = megasas_handle_scsi(s, cmd, 1);
+            break;
+        case MFI_CMD_LD_READ:
+        case MFI_CMD_LD_WRITE:
+            frame_status = megasas_handle_io(s, cmd);
+            break;
+        default:
+            DPRINTF("Unhandled MFI cmd %x\n", cmd->frame->header.frame_cmd);
+            s->event_count++;
+            break;
     }
 frame_done:
     if (frame_status != MFI_STAT_INVALID_STATUS) {
-	megasas_frame_set_cmd_status(frame_addr, frame_status);
-	megasas_finish_command(s, cmd);
-	megasas_dequeue_frame(s, frame_context);
+        megasas_frame_set_cmd_status(frame_addr, frame_status);
+        megasas_finish_command(s, cmd);
+        megasas_dequeue_frame(s, frame_context);
     }
 }
 
 static uint32_t megasas_mmio_readb(void *opaque, target_phys_addr_t addr)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readb mmio 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readb mmio 0x%lx\n", (unsigned long)addr);
     return 0;
 }
 
 static uint32_t megasas_mmio_readw(void *opaque, target_phys_addr_t addr)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readw mmio 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readw mmio 0x%lx\n", (unsigned long)addr);
     return 0;
 }
 
@@ -1410,109 +1357,97 @@  static uint32_t megasas_mmio_readl(void *opaque, target_phys_addr_t addr)
 {
     MPTState *s = opaque;
 
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readl mmio 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readl mmio 0x%lx\n", (unsigned long)addr);
     switch (addr) {
-	case MFI_IDB:
-	    return 0;
-	case MFI_OMSG0:
-	case MFI_OSP0:
-	    return (s->fw_state & MFI_FWSTATE_MASK) | ((s->fw_sge & 0xff) << 16) | (s->fw_cmds & 0xFFFF);
-	case MFI_OSTS:
-	    if (MEGASAS_INTR_ENABLED(s) && s->doorbell)
-		return MFI_1078_RM | s->doorbell;
-	    break;
-	case MFI_OMSK:
-	    return s->intr_mask;
-	case MFI_ODCR0:
-	    return s->doorbell;
-	default:
-	    BADF("readb 0x%lx\n", (unsigned long)addr);
-	    break;
+        case MFI_IDB:
+            return 0;
+        case MFI_OMSG0:
+        case MFI_OSP0:
+            return (s->fw_state & MFI_FWSTATE_MASK) | ((s->fw_sge & 0xff) << 16) | (s->fw_cmds & 0xFFFF);
+        case MFI_OSTS:
+            if (MEGASAS_INTR_ENABLED(s) && s->doorbell)
+                return MFI_1078_RM | s->doorbell;
+            break;
+        case MFI_OMSK:
+            return s->intr_mask;
+        case MFI_ODCR0:
+            return s->doorbell;
+        default:
+            BADF("readb 0x%lx\n", (unsigned long)addr);
+            break;
     }
     return 0;
 }
 
 static void megasas_mmio_writeb(void *opaque, target_phys_addr_t addr,
-				uint32_t val)
+                                uint32_t val)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writeb mmio %lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writeb mmio %lx: %x\n", (unsigned long)addr, val);
 }
 
 static void megasas_mmio_writew(void *opaque, target_phys_addr_t addr,
-				uint32_t val)
+                                uint32_t val)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writew mmio %lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writew mmio %lx: %x\n", (unsigned long)addr, val);
 }
 
 static void megasas_mmio_writel(void *opaque, target_phys_addr_t addr,
-				uint32_t val)
+                                uint32_t val)
 {
     MPTState *s = opaque;
     target_phys_addr_t frame_addr;
     uint32_t frame_count;
     int i;
 
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writel mmio %lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writel mmio %lx: %x\n", (unsigned long)addr, val);
 
     switch (addr) {
-	case MFI_IDB:
-	    if (val & MFI_FWINIT_ABORT) {
-		/* Abort all pending cmds */
-		for (i = 0; i <= s->fw_cmds; i++)
-		    megasas_abort_command(&s->frames[i]);
-	    }
-	    if (val & MFI_FWINIT_READY) {
-		/* move to FW READY */
-		megasas_soft_reset(s);
-	    }
-	    if (val & MFI_FWINIT_MFIMODE) {
-		/* discard MFIs */
-	    }
-	    break;
-	case MFI_OMSK:
-	    s->intr_mask = val;
-	    if (!MEGASAS_INTR_ENABLED(s)) {
-		qemu_irq_lower(s->dev.irq[0]);
-	    }
-	    break;
-	case MFI_ODCR0:
-	    /* Update reply queue pointer */
-#ifdef DEBUG_MEGASAS_QUEUE
-	    DPRINTF("Update reply queue head %x busy %d\n",
-		    s->reply_queue_index, s->busy);
-#endif
-	    stl_phys(s->producer_pa, s->reply_queue_index);
-	    s->doorbell = 0;
-	    qemu_irq_lower(s->dev.irq[0]);
-	    break;
-	case MFI_IQPH:
-	    s->frame_hi = val;
-	    break;
-	case MFI_IQPL:
-	case MFI_IQP:
-	    /* Received MFI frames; up to 8 contiguous frames */
-	    frame_addr = (val & ~0xF);
-	    /* Add possible 64 bit offset */
-	    frame_addr |= (uint64_t)s->frame_hi;
-	    s->frame_hi = 0;
-	    frame_count = (val >> 1) & 0x7;
-#ifdef DEBUG_MEGASAS_MFI
-	    DPRINTF("Received frame addr %lx count %d\n",
-		    (unsigned long)frame_addr, frame_count);
-#endif
-	    megasas_handle_frame(s, frame_addr, frame_count);
-	    break;
-	default:
-	    BADF("writel 0x%lx: %x\n", (unsigned long)addr, val);
-	    break;
+        case MFI_IDB:
+            if (val & MFI_FWINIT_ABORT) {
+                /* Abort all pending cmds */
+                for (i = 0; i <= s->fw_cmds; i++)
+                    megasas_abort_command(&s->frames[i]);
+            }
+            if (val & MFI_FWINIT_READY) {
+                /* move to FW READY */
+                megasas_soft_reset(s);
+            }
+            if (val & MFI_FWINIT_MFIMODE) {
+                /* discard MFIs */
+            }
+            break;
+        case MFI_OMSK:
+            s->intr_mask = val;
+            if (!MEGASAS_INTR_ENABLED(s)) {
+                qemu_irq_lower(s->dev.irq[0]);
+            }
+            break;
+        case MFI_ODCR0:
+            /* Update reply queue pointer */
+            DPRINTF_QUEUE("Update reply queue head %x busy %d\n",
+                          s->reply_queue_index, s->busy);
+            stl_phys(s->producer_pa, s->reply_queue_index);
+            s->doorbell = 0;
+            qemu_irq_lower(s->dev.irq[0]);
+            break;
+        case MFI_IQPH:
+            s->frame_hi = val;
+            break;
+        case MFI_IQPL:
+        case MFI_IQP:
+            /* Received MFI frames; up to 8 contiguous frames */
+            frame_addr = (val & ~0xF);
+            /* Add possible 64 bit offset */
+            frame_addr |= (uint64_t)s->frame_hi;
+            s->frame_hi = 0;
+            frame_count = (val >> 1) & 0x7;
+            DPRINTF_MFI("Received frame addr %lx count %d\n",
+                        (unsigned long)frame_addr, frame_count);
+            megasas_handle_frame(s, frame_addr, frame_count);
+            break;
+        default:
+            BADF("writel 0x%lx: %x\n", (unsigned long)addr, val);
+            break;
     }
 }
 
@@ -1530,47 +1465,35 @@  static CPUWriteMemoryFunc * const megasas_mmio_writefn[3] = {
 
 static uint32_t megasas_io_readb(void *opaque, uint32_t addr)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readb reg 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readb reg 0x%lx\n", (unsigned long)addr);
     return 0;
 }
 
 static uint32_t megasas_io_readw(void *opaque, uint32_t addr)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readw reg 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readw reg 0x%lx\n", (unsigned long)addr);
     return 0;
 }
 
 static uint32_t megasas_io_readl(void *opaque, uint32_t addr)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readl reg 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readl reg 0x%lx\n", (unsigned long)addr);
     return megasas_mmio_readl(opaque, addr & 0xff);
 }
 
 static void megasas_io_writeb(void *opaque, uint32_t addr, uint32_t val)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writeb reg 0x%lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writeb reg 0x%lx: %x\n", (unsigned long)addr, val);
 }
 
 static void megasas_io_writew(void *opaque, uint32_t addr, uint32_t val)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writew reg 0x%lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writew reg 0x%lx: %x\n", (unsigned long)addr, val);
 }
 
 static void megasas_io_writel(void *opaque, uint32_t addr, uint32_t val)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writel reg 0x%lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writel reg 0x%lx: %x\n", (unsigned long)addr, val);
     megasas_mmio_writel(opaque, addr & 0xff, val);
 }
 
@@ -1588,18 +1511,14 @@  static CPUWriteMemoryFunc * const megasas_io_writefn[3] = {
 
 static uint32_t megasas_queue_readl(void *opaque, target_phys_addr_t addr)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("readl queue 0x%lx\n", (unsigned long)addr);
-#endif
+    DPRINTF_REG("readl queue 0x%lx\n", (unsigned long)addr);
     return 0;
 }
 
 static void megasas_queue_writel(void *opaque, target_phys_addr_t addr,
-				 uint32_t val)
+                                 uint32_t val)
 {
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("writel queue %lx: %x\n", (unsigned long)addr, val);
-#endif
+    DPRINTF_REG("writel queue %lx: %x\n", (unsigned long)addr, val);
 }
 
 static CPUReadMemoryFunc * const megasas_queue_readfn[3] = {
@@ -1631,13 +1550,11 @@  static void megasas_soft_reset(MPTState *s)
 }
 
 static void megasas_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
-				 pcibus_t addr, pcibus_t size, int type)
+                                 pcibus_t addr, pcibus_t size, int type)
 {
     MPTState *s = DO_UPCAST(MPTState, dev, pci_dev);
 
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("Mapping MMIO region %d at %08lx\n", region_num, (unsigned long)addr);
-#endif
+    DPRINTF_REG("Mapping MMIO region %d at %08lx\n", region_num, (unsigned long)addr);
     cpu_register_physical_memory(addr, size, s->mmio_io_addr);
     s->event_count++;
 }
@@ -1647,9 +1564,7 @@  static void megasas_io_mapfunc(PCIDevice *pci_dev, int region_num,
 {
     MPTState *s = DO_UPCAST(MPTState, dev, pci_dev);
 
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("Mapping IO region %d at %08lx\n", region_num, (unsigned long)addr);
-#endif
+    DPRINTF_REG("Mapping IO region %d at %08lx\n", region_num, (unsigned long)addr);
     register_ioport_write(addr, size, 1, megasas_io_writeb, s);
     register_ioport_write(addr, size, 2, megasas_io_writew, s);
     register_ioport_write(addr, size, 4, megasas_io_writel, s);
@@ -1664,9 +1579,7 @@  static void megasas_queue_mapfunc(PCIDevice *pci_dev, int region_num,
 {
     MPTState *s = DO_UPCAST(MPTState, dev, pci_dev);
 
-#ifdef DEBUG_MEGASAS_REG
-    DPRINTF("Mapping QUEUE region %d at %08lx\n", region_num, (unsigned long)addr);
-#endif
+    DPRINTF_REG("Mapping QUEUE region %d at %08lx\n", region_num, (unsigned long)addr);
     cpu_register_physical_memory(addr, size, s->queue_addr);
     s->event_count++;
 }
@@ -1677,7 +1590,7 @@  static void megasas_scsi_reset(DeviceState *dev)
     int i;
 
     for (i = 0; i <= s->fw_cmds; i++)
-	    megasas_abort_command(&s->frames[i]);
+        megasas_abort_command(&s->frames[i]);
 
     megasas_soft_reset(s);
 }
@@ -1702,10 +1615,10 @@  static int megasas_scsi_load(QEMUFile *f, void *opaque, int version_id)
     int ret;
 
     if (version_id > 0)
-	return -EINVAL;
+        return -EINVAL;
 
     if ((ret = pci_device_load(&s->dev, f)) < 0)
-	return ret;
+        return ret;
 
     qemu_get_sbe32s(f, &s->fw_state);
     qemu_get_sbe32s(f, &s->intr_mask);
@@ -1752,36 +1665,38 @@  static int megasas_scsi_init(PCIDevice *dev)
     s->mmio_io_addr = cpu_register_io_memory(megasas_mmio_readfn,
                                              megasas_mmio_writefn, s);
     s->io_addr = cpu_register_io_memory(megasas_io_readfn,
-					megasas_io_writefn, s);
+                                        megasas_io_writefn, s);
     s->queue_addr = cpu_register_io_memory(megasas_queue_readfn,
-					   megasas_queue_writefn, s);
+                                           megasas_queue_writefn, s);
     pci_register_bar((struct PCIDevice *)s, 0, 0x40000,
                            PCI_BASE_ADDRESS_SPACE_MEMORY, megasas_mmio_mapfunc);
     pci_register_bar((struct PCIDevice *)s, 2, 256,
                            PCI_BASE_ADDRESS_SPACE_IO, megasas_io_mapfunc);
     pci_register_bar((struct PCIDevice *)s, 3, 0x40000,
                            PCI_BASE_ADDRESS_SPACE_MEMORY, megasas_queue_mapfunc);
-    if (s->fw_sge > MEGASAS_MAX_SGE)
-	s->fw_sge = MEGASAS_MAX_SGE;
-    if (s->fw_cmds > MEGASAS_MAX_FRAMES)
-	s->fw_cmds = MEGASAS_MAX_FRAMES;
+    if (s->fw_sge > MEGASAS_MAX_SGE) {
+        s->fw_sge = MEGASAS_MAX_SGE;
+    }
+    if (s->fw_cmds > MEGASAS_MAX_FRAMES) {
+        s->fw_cmds = MEGASAS_MAX_FRAMES;
+    }
     if (s->raid_mode_str) {
-	if (!strcmp(s->raid_mode_str, "jbod"))
-	    s->is_jbod = 1;
-	else
-	    s->is_jbod = 0;
+        if (!strcmp(s->raid_mode_str, "jbod"))
+            s->is_jbod = 1;
+        else
+            s->is_jbod = 0;
     }
     DPRINTF("Using %d sges, %d cmds, %s mode\n",
-	    s->fw_sge, s->fw_cmds, s->is_jbod?"jbod":"raid");
+            s->fw_sge, s->fw_cmds, s->is_jbod ? "jbod" : "raid");
     s->fw_luns = (MFI_MAX_LD > MAX_SCSI_DEVS) ?
-	MAX_SCSI_DEVS : MFI_MAX_LD;
+        MAX_SCSI_DEVS : MFI_MAX_LD;
     s->producer_pa = 0;
     s->consumer_pa = 0;
     for (i = 0; i < s->fw_cmds; i++) {
-	s->frames[i].index = i;
-	s->frames[i].context = -1;
-	s->frames[i].pa = 0;
-	s->frames[i].state = s;
+        s->frames[i].index = i;
+        s->frames[i].context = -1;
+        s->frames[i].pa = 0;
+        s->frames[i].state = s;
     }
 
     scsi_bus_new(&s->bus, &dev->qdev, 1, s->fw_luns, megasas_command_complete);
@@ -1798,12 +1713,12 @@  static PCIDeviceInfo megasas_info = {
     .init       = megasas_scsi_init,
     .exit       = megasas_scsi_uninit,
     .qdev.props = (Property[]) {
-	DEFINE_PROP_UINT32("max_sge", MPTState, fw_sge,
-			   MEGASAS_DEFAULT_SGE),
-	DEFINE_PROP_UINT32("max_cmds", MPTState, fw_cmds,
-			   MEGASAS_DEFAULT_FRAMES),
-	DEFINE_PROP_STRING("mode", MPTState, raid_mode_str),
-	DEFINE_PROP_END_OF_LIST(),
+        DEFINE_PROP_UINT32("max_sge", MPTState, fw_sge,
+                           MEGASAS_DEFAULT_SGE),
+        DEFINE_PROP_UINT32("max_cmds", MPTState, fw_cmds,
+                           MEGASAS_DEFAULT_FRAMES),
+        DEFINE_PROP_STRING("mode", MPTState, raid_mode_str),
+        DEFINE_PROP_END_OF_LIST(),
     },
 };