+/***********************************************\
+* Get a MBO and then Send it *
+\***********************************************/
+BT_MBO *bt_send_mbo( int unit,
+ int flags,
+ int cmd,
+ struct bt_ccb *ccb )
+{
+ unsigned opri;
+ BT_MBO *wmbo; /* Mail Box Out pointer */
+ struct bt_mbx *wmbx; /* Mail Box pointer specified unit */
+ int i, wait;
+
+ wmbx = &bt_mbx[unit];
+
+ if (!(flags & SCSI_NOMASK))
+ opri = splbio();
+
+ /* Get the Target OUT mail Box pointer and move to Next */
+ wmbo = wmbx->tmbo;
+ wmbx->tmbo = ( wmbo == &( wmbx->mbo[BT_MBX_SIZE - 1 ] ) ?
+ &(wmbx->mbo[0]) : wmbo + 1 );
+
+ /*
+ * Check the outmail box is free or not
+ * Note: Under the normal operation, it shuld NOT happen to wait.
+ */
+ while ( wmbo->cmd != BT_MBO_FREE ) {
+
+ wait = BT_CMD_TIMEOUT_FUDGE * delaycount;
+ /* Enable MBO available interrupt */
+ outb(BT_CMD_DATA_PORT,BT_MBO_INTR_EN);
+ for (i=0; i< wait; i++)
+ {
+ if (!(inb(BT_CTRL_STAT_PORT) & BT_CDF))
+ break;
+ }
+ if (i >= wait)
+ {
+ printf("bt_send_mbo: bt742a cmd/data port full\n");
+ outb(BT_CTRL_STAT_PORT, BT_SRST);
+ return( (BT_MBO *)0 );
+ }
+ outb(BT_CMD_DATA_PORT, 0x01); /* Enable */
+ sleep( wmbx, PRIBIO);
+ }
+
+ /* Link CCB to the Mail Box */
+ wmbo->ccb_addr = KVTOPHYS(ccb);
+ ccb->mbx = wmbo;
+ wmbo->cmd = cmd;