"MSG IN",
 };
 
-static __u8 NCR_700_SDTR_msg[] = {
-       0x01,                   /* Extended message */
-       0x03,                   /* Extended message Length */
-       0x01,                   /* SDTR Extended message */
-       NCR_700_MIN_PERIOD,
-       NCR_700_MAX_OFFSET
-};
-
 /* This translates the SDTR message offset and period to a value
  * which can be loaded into the SXFER_REG.
  *
                return 0;
 
        if(period < hostdata->min_period) {
-               printk(KERN_WARNING "53c700: Period %dns is less than this chip's minimum, setting to %d\n", period*4, NCR_700_SDTR_msg[3]*4);
+               printk(KERN_WARNING "53c700: Period %dns is less than this chip's minimum, setting to %d\n", period*4, NCR_700_MIN_PERIOD*4);
                period = hostdata->min_period;
        }
        XFERP = (period*4 * hostdata->sync_clock)/1000 - 4;
 
        if(hostdata->fast &&
           NCR_700_is_flag_clear(SCp->device, NCR_700_DEV_NEGOTIATED_SYNC)) {
-               memcpy(&hostdata->msgout[count], NCR_700_SDTR_msg,
-                      sizeof(NCR_700_SDTR_msg));
-               hostdata->msgout[count+3] = spi_period(SCp->device->sdev_target);
-               hostdata->msgout[count+4] = spi_offset(SCp->device->sdev_target);
-               count += sizeof(NCR_700_SDTR_msg);
+               count += spi_populate_sync_msg(&hostdata->msgout[count],
+                               spi_period(SCp->device->sdev_target),
+                               spi_offset(SCp->device->sdev_target));
                NCR_700_set_flag(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION);
        }
 
 
                ADDMSGO(BUS_DEVICE_RESET);
        } else if (SYNCNEG==0 && SYNCHRONOUS) {
                CURRENT_SC->SCp.phase |= syncneg;
-               ADDMSGO(EXTENDED_MESSAGE);
-               ADDMSGO(3);
-               ADDMSGO(EXTENDED_SDTR);
-               ADDMSGO(50);            /* 200ns */
-               ADDMSGO(8);             /* 8 byte req/ack offset */
-
+               MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
                SYNCNEG=1;              /* negotiation in progress */
        }
 
 
 {
        if (offset == 0)
                period = AHD_ASYNC_XFER_PERIOD;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR_LEN;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_SDTR;
-       ahd->msgout_buf[ahd->msgout_index++] = period;
-       ahd->msgout_buf[ahd->msgout_index++] = offset;
+       ahd->msgout_index += spi_populate_sync_msg(
+                       ahd->msgout_buf + ahd->msgout_index, period, offset);
        ahd->msgout_len += 5;
        if (bootverbose) {
                printf("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
 ahd_construct_wdtr(struct ahd_softc *ahd, struct ahd_devinfo *devinfo,
                   u_int bus_width)
 {
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR_LEN;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_WDTR;
-       ahd->msgout_buf[ahd->msgout_index++] = bus_width;
+       ahd->msgout_index += spi_populate_width_msg(
+                       ahd->msgout_buf + ahd->msgout_index, bus_width);
        ahd->msgout_len += 4;
        if (bootverbose) {
                printf("(%s:%c:%d:%d): Sending WDTR %x\n",
                ppr_options |= MSG_EXT_PPR_PCOMP_EN;
        if (offset == 0)
                period = AHD_ASYNC_XFER_PERIOD;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXTENDED;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR_LEN;
-       ahd->msgout_buf[ahd->msgout_index++] = MSG_EXT_PPR;
-       ahd->msgout_buf[ahd->msgout_index++] = period;
-       ahd->msgout_buf[ahd->msgout_index++] = 0;
-       ahd->msgout_buf[ahd->msgout_index++] = offset;
-       ahd->msgout_buf[ahd->msgout_index++] = bus_width;
-       ahd->msgout_buf[ahd->msgout_index++] = ppr_options;
+       ahd->msgout_index += spi_populate_ppr_msg(
+                       ahd->msgout_buf + ahd->msgout_index, period, offset,
+                       bus_width, ppr_options);
        ahd->msgout_len += 8;
        if (bootverbose) {
                printf("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
 
 {
        if (offset == 0)
                period = AHC_ASYNC_XFER_PERIOD;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR_LEN;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_SDTR;
-       ahc->msgout_buf[ahc->msgout_index++] = period;
-       ahc->msgout_buf[ahc->msgout_index++] = offset;
+       ahc->msgout_index += spi_populate_sync_msg(
+                       ahc->msgout_buf + ahc->msgout_index, period, offset);
        ahc->msgout_len += 5;
        if (bootverbose) {
                printf("(%s:%c:%d:%d): Sending SDTR period %x, offset %x\n",
 ahc_construct_wdtr(struct ahc_softc *ahc, struct ahc_devinfo *devinfo,
                   u_int bus_width)
 {
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR_LEN;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_WDTR;
-       ahc->msgout_buf[ahc->msgout_index++] = bus_width;
+       ahc->msgout_index += spi_populate_width_msg(
+                       ahc->msgout_buf + ahc->msgout_index, bus_width);
        ahc->msgout_len += 4;
        if (bootverbose) {
                printf("(%s:%c:%d:%d): Sending WDTR %x\n",
 {
        if (offset == 0)
                period = AHC_ASYNC_XFER_PERIOD;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXTENDED;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR_LEN;
-       ahc->msgout_buf[ahc->msgout_index++] = MSG_EXT_PPR;
-       ahc->msgout_buf[ahc->msgout_index++] = period;
-       ahc->msgout_buf[ahc->msgout_index++] = 0;
-       ahc->msgout_buf[ahc->msgout_index++] = offset;
-       ahc->msgout_buf[ahc->msgout_index++] = bus_width;
-       ahc->msgout_buf[ahc->msgout_index++] = ppr_options;
+       ahc->msgout_index += spi_populate_ppr_msg(
+                       ahc->msgout_buf + ahc->msgout_index, period, offset,
+                       bus_width, ppr_options);
        ahc->msgout_len += 8;
        if (bootverbose) {
                printf("(%s:%c:%d:%d): Sending PPR bus_width %x, period %x, "
 
 
        switch (nego) {
        case NS_SYNC:
-               msgptr[msglen++] = EXTENDED_MESSAGE;
-               msgptr[msglen++] = 3;
-               msgptr[msglen++] = EXTENDED_SDTR;
-               msgptr[msglen++] = tp->maxoffs ? tp->minsync : 0;
-               msgptr[msglen++] = tp->maxoffs;
+               msglen += spi_populate_sync_msg(msgptr + msglen,
+                               tp->maxoffs ? tp->minsync : 0, tp->maxoffs);
                break;
        case NS_WIDE:
-               msgptr[msglen++] = EXTENDED_MESSAGE;
-               msgptr[msglen++] = 2;
-               msgptr[msglen++] = EXTENDED_WDTR;
-               msgptr[msglen++] = tp->usrwide;
+               msglen += spi_populate_width_msg(msgptr + msglen, tp->usrwide);
                break;
        }
 
                spi_offset(starget) = ofs;
                ncr_setsync(np, cp, scntl3, (fak<<5)|ofs);
 
-               np->msgout[0] = EXTENDED_MESSAGE;
-               np->msgout[1] = 3;
-               np->msgout[2] = EXTENDED_SDTR;
-               np->msgout[3] = per;
-               np->msgout[4] = ofs;
-
+               spi_populate_sync_msg(np->msgout, per, ofs);
                cp->nego_status = NS_SYNC;
 
                if (DEBUG_FLAGS & DEBUG_NEGO) {
 
                spi_width(starget) = wide;
                ncr_setwide(np, cp, wide, 1);
-
-               np->msgout[0] = EXTENDED_MESSAGE;
-               np->msgout[1] = 2;
-               np->msgout[2] = EXTENDED_WDTR;
-               np->msgout[3] = wide;
+               spi_populate_width_msg(np->msgout, wide);
 
                np->msgin [0] = NOP;
 
 
 }
 EXPORT_SYMBOL(spi_display_xfer_agreement);
 
+int spi_populate_width_msg(unsigned char *msg, int width)
+{
+       msg[0] = EXTENDED_MESSAGE;
+       msg[1] = 2;
+       msg[2] = EXTENDED_WDTR;
+       msg[3] = width;
+       return 4;
+}
+
+int spi_populate_sync_msg(unsigned char *msg, int period, int offset)
+{
+       msg[0] = EXTENDED_MESSAGE;
+       msg[1] = 3;
+       msg[2] = EXTENDED_SDTR;
+       msg[3] = period;
+       msg[4] = offset;
+       return 5;
+}
+
+int spi_populate_ppr_msg(unsigned char *msg, int period, int offset,
+               int width, int options)
+{
+       msg[0] = EXTENDED_MESSAGE;
+       msg[1] = 6;
+       msg[2] = EXTENDED_PPR;
+       msg[3] = period;
+       msg[4] = 0;
+       msg[5] = offset;
+       msg[6] = width;
+       msg[7] = options;
+       return 8;
+}
+
 #ifdef CONFIG_SCSI_CONSTANTS
 static const char * const one_byte_msgs[] = {
 /* 0x00 */ "Command Complete", NULL, "Save Pointers",
 
 
 #include <linux/slab.h>
 #include <asm/param.h>         /* for timeouts in units of HZ */
-#include <scsi/scsi_dbg.h>
 
 #include "sym_glue.h"
 #include "sym_nvram.h"
 
        switch (nego) {
        case NS_SYNC:
-               msgptr[msglen++] = M_EXTENDED;
-               msgptr[msglen++] = 3;
-               msgptr[msglen++] = M_X_SYNC_REQ;
-               msgptr[msglen++] = goal->period;
-               msgptr[msglen++] = goal->offset;
+               msglen += spi_populate_sync_msg(msgptr + msglen, goal->period,
+                               goal->offset);
                break;
        case NS_WIDE:
-               msgptr[msglen++] = M_EXTENDED;
-               msgptr[msglen++] = 2;
-               msgptr[msglen++] = M_X_WIDE_REQ;
-               msgptr[msglen++] = goal->width;
+               msglen += spi_populate_width_msg(msgptr + msglen, goal->width);
                break;
        case NS_PPR:
-               msgptr[msglen++] = M_EXTENDED;
-               msgptr[msglen++] = 6;
-               msgptr[msglen++] = M_X_PPR_REQ;
-               msgptr[msglen++] = goal->period;
-               msgptr[msglen++] = 0;
-               msgptr[msglen++] = goal->offset;
-               msgptr[msglen++] = goal->width;
-               msgptr[msglen++] = (goal->iu ? PPR_OPT_IU : 0) |
+               msglen += spi_populate_ppr_msg(msgptr + msglen, goal->period,
+                               goal->offset, goal->width,
+                               (goal->iu ? PPR_OPT_IU : 0) |
                                        (goal->dt ? PPR_OPT_DT : 0) |
-                                       (goal->qas ? PPR_OPT_QAS : 0);
+                                       (goal->qas ? PPR_OPT_QAS : 0));
                break;
        }
 
        /*
         *  It was a request. Prepare an answer message.
         */
-       np->msgout[0] = M_EXTENDED;
-       np->msgout[1] = 3;
-       np->msgout[2] = M_X_SYNC_REQ;
-       np->msgout[3] = per;
-       np->msgout[4] = ofs;
+       spi_populate_sync_msg(np->msgout, per, ofs);
 
        if (DEBUG_FLAGS & DEBUG_NEGO) {
                sym_print_nego_msg(np, target, "sync msgout", np->msgout);
        /*
         *  It was a request. Prepare an answer message.
         */
-       np->msgout[0] = M_EXTENDED;
-       np->msgout[1] = 6;
-       np->msgout[2] = M_X_PPR_REQ;
-       np->msgout[3] = per;
-       np->msgout[4] = 0;
-       np->msgout[5] = ofs;
-       np->msgout[6] = wide;
-       np->msgout[7] = opts;
+       spi_populate_ppr_msg(np->msgout, per, ofs, wide, opts);
 
        if (DEBUG_FLAGS & DEBUG_NEGO) {
                sym_print_nego_msg(np, target, "ppr msgout", np->msgout);
        /*
         *  It was a request. Prepare an answer message.
         */
-       np->msgout[0] = M_EXTENDED;
-       np->msgout[1] = 2;
-       np->msgout[2] = M_X_WIDE_REQ;
-       np->msgout[3] = wide;
+       spi_populate_width_msg(np->msgout, wide);
 
        np->msgin [0] = M_NOOP;
 
                 * a single SCSI command (Suggested by Justin Gibbs).
                 */
                if (tp->tgoal.offset) {
-                       np->msgout[0] = M_EXTENDED;
-                       np->msgout[1] = 3;
-                       np->msgout[2] = M_X_SYNC_REQ;
-                       np->msgout[3] = tp->tgoal.period;
-                       np->msgout[4] = tp->tgoal.offset;
+                       spi_populate_sync_msg(np->msgout, tp->tgoal.period,
+                                       tp->tgoal.offset);
 
                        if (DEBUG_FLAGS & DEBUG_NEGO) {
                                sym_print_nego_msg(np, cp->target,
 
 void spi_dv_device(struct scsi_device *);
 void spi_display_xfer_agreement(struct scsi_target *);
 int spi_print_msg(const unsigned char *);
+int spi_populate_width_msg(unsigned char *msg, int width);
+int spi_populate_sync_msg(unsigned char *msg, int period, int offset);
+int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width,
+               int options);
 
 #endif /* SCSI_TRANSPORT_SPI_H */