summaryrefslogtreecommitdiffstats
path: root/sys/dev/dpt/dpt_scsi.c
diff options
context:
space:
mode:
authorgibbs <gibbs@FreeBSD.org>1998-09-15 08:33:38 +0000
committergibbs <gibbs@FreeBSD.org>1998-09-15 08:33:38 +0000
commit589d4a338b39b4f9e27060b9b9c717ae520f8905 (patch)
treec4a36ecfbf82749363f81dbb7ccb7eed321da23b /sys/dev/dpt/dpt_scsi.c
parent766d4620976e348ecb44cd6fc16aeceee88fe1ca (diff)
downloadFreeBSD-src-589d4a338b39b4f9e27060b9b9c717ae520f8905.zip
FreeBSD-src-589d4a338b39b4f9e27060b9b9c717ae520f8905.tar.gz
Conver the DPT driver to CAM. The dpt_control interface is not yet
functional, but will be in another day or so.
Diffstat (limited to 'sys/dev/dpt/dpt_scsi.c')
-rw-r--r--sys/dev/dpt/dpt_scsi.c4595
1 files changed, 1637 insertions, 2958 deletions
diff --git a/sys/dev/dpt/dpt_scsi.c b/sys/dev/dpt/dpt_scsi.c
index b71af5e..99dea45 100644
--- a/sys/dev/dpt/dpt_scsi.c
+++ b/sys/dev/dpt/dpt_scsi.c
@@ -1,4 +1,4 @@
-/**
+/*
* Copyright (c) 1997 by Simon Shapiro
* All Rights Reserved
*
@@ -27,7 +27,7 @@
* SUCH DAMAGE.
*/
-/**
+/*
* dpt_scsi.c: SCSI dependant code for the DPT driver
*
* credits: Assisted by Mike Neuffer in the early low level DPT code
@@ -37,34 +37,13 @@
* Last but not least, many thanx to UCB and the FreeBSD
* team for creating and maintaining such a wonderful O/S.
*
- * TODO: * Add ISA probe code.
- * * Add driver-level RSID-0. This will allow interoperability with
+ * TODO: * Add ISA probe code.
+ * * Add driver-level RAID-0. This will allow interoperability with
* NiceTry, M$-Doze, Win-Dog, Slowlaris, etc., in recognizing RAID
* arrays that span controllers (Wow!).
*/
-/**
- * IMPORTANT:
- * There are two critical section "levels" used in this driver:
- * splcam() and splsoftcam(). Splcam() protects us from re-entrancy
- * from both our software and hardware interrupt handler. Splsoftcam()
- * protects us only from our software interrupt handler. The two
- * main data structures that need protection are the submitted and
- * completed queue.
- *
- * There are three places where the submitted queue is accessed:
- *
- * 1. dpt_run_queue inserts into the queue
- * 2. dpt_intr removes from the queue
- * 3 dpt_handle_timeouts potentially removes from the queue.
- *
- * There are three places where the the completed queue is accessed:
- * 1. dpt_intr() inserts into the queue
- * 2. dpt_sintr() removes from the queue
- * 3. dpt_handle_timeouts potentially inserts into the queue
- */
-
-#ident "$Id: dpt_scsi.c,v 1.11 1998/08/16 23:37:54 bde Exp $"
+#ident "$Id: dpt_scsi.c,v 1.12 1998/08/26 19:11:22 gibbs Exp $"
#define _DPT_C_
@@ -75,421 +54,1715 @@
#include <sys/buf.h>
#include <sys/kernel.h>
-#include <machine/ipl.h>
-#include <scsi/scsiconf.h>
-#include <scsi/scsi_disk.h>
+#include <stddef.h> /* For offsetof */
+#include <machine/bus_memio.h>
+#include <machine/bus_pio.h>
+#include <machine/bus.h>
#include <machine/clock.h>
+#include <cam/cam.h>
+#include <cam/cam_ccb.h>
+#include <cam/cam_sim.h>
+#include <cam/cam_xpt_sim.h>
+#include <cam/cam_debug.h>
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_message.h>
+
#include <vm/vm.h>
#include <vm/pmap.h>
-/* The HBA reset option uses the same timer as the lost IRQ option*/
-#ifdef DPT_RESET_HBA
-#ifndef DPT_LOST_IRQ
-#define DPT_LOST_IRQ
-#endif
-#endif
-
-#include <sys/dpt.h>
-
-#ifdef INLINE
-#undef INLINE
-#endif
-
-#define INLINE __inline
-#define INLINE_Q
+#include <dev/dpt/dpt.h>
/* dpt_isa.c, dpt_eisa.c, and dpt_pci.c need this in a central place */
+int dpt_controllers_present;
-int dpt_controllers_present = 0;
+u_long dpt_unit; /* Next unit number to use */
-/* Function Prototypes */
+/* The linked list of softc structures */
+struct dpt_softc_list dpt_softcs = TAILQ_HEAD_INITIALIZER(dpt_softcs);
#define microtime_now dpt_time_now()
-static INLINE u_int32_t dpt_inl(dpt_softc_t * dpt, u_int32_t offset);
-static INLINE u_int8_t dpt_inb(dpt_softc_t * dpt, u_int32_t offset);
-static INLINE void
-dpt_outb(dpt_softc_t * dpt, u_int32_t offset,
- u_int8_t value);
-static INLINE void
-dpt_outl(dpt_softc_t * dpt, u_int32_t offset,
- u_int32_t value);
-static INLINE_Q void dpt_Qpush_free(dpt_softc_t * dpt, dpt_ccb_t * ccb);
-static INLINE_Q dpt_ccb_t *dpt_Qpop_free(dpt_softc_t * dpt);
-static INLINE_Q void dpt_Qadd_waiting(dpt_softc_t * dpt, dpt_ccb_t * ccb);
-static INLINE_Q void dpt_Qpush_waiting(dpt_softc_t * dpt, dpt_ccb_t * ccb);
-static INLINE_Q void
-dpt_Qremove_waiting(dpt_softc_t * dpt,
- dpt_ccb_t * ccb);
-static INLINE_Q void
-dpt_Qadd_submitted(dpt_softc_t * dpt,
- dpt_ccb_t * ccb);
-static INLINE_Q void
-dpt_Qremove_submitted(dpt_softc_t * dpt,
- dpt_ccb_t * ccb);
-static INLINE_Q void
-dpt_Qadd_completed(dpt_softc_t * dpt,
- dpt_ccb_t * ccb);
-static INLINE_Q void
-dpt_Qremove_completed(dpt_softc_t * dpt,
- dpt_ccb_t * ccb);
-static int
-dpt_send_eata_command(dpt_softc_t * dpt,
- eata_ccb_t * cmd_block,
- u_int8_t command,
- int32_t retries,
- u_int8_t ifc, u_int8_t code,
- u_int8_t code2);
-static INLINE int
-dpt_send_immediate(dpt_softc_t * dpt,
- eata_ccb_t * cmd_block,
- u_int8_t ifc, u_int8_t code,
- u_int8_t code2);
-static INLINE int dpt_just_reset(dpt_softc_t * dpt);
-static INLINE int dpt_raid_busy(dpt_softc_t * dpt);
-static INLINE void dpt_sched_queue(dpt_softc_t * dpt);
-
-#ifdef DPT_MEASURE_PERFORMANCE
-static void
-dpt_IObySize(dpt_softc_t * dpt, dpt_ccb_t * ccb,
- int op, int index);
-#endif
+#define dpt_inl(dpt, port) \
+ bus_space_read_4((dpt)->tag, (dpt)->bsh, port)
+#define dpt_inb(dpt, port) \
+ bus_space_read_1((dpt)->tag, (dpt)->bsh, port)
+#define dpt_outl(dpt, port, value) \
+ bus_space_write_4((dpt)->tag, (dpt)->bsh, port, value)
+#define dpt_outb(dpt, port, value) \
+ bus_space_write_1((dpt)->tag, (dpt)->bsh, port, value)
-static void dpt_swi_register(void *);
+/*
+ * These will have to be setup by parameters passed at boot/load time. For
+ * perfromance reasons, we make them constants for the time being.
+ */
+#define dpt_min_segs DPT_MAX_SEGS
+#define dpt_max_segs DPT_MAX_SEGS
-#ifdef DPT_HANDLE_TIMEOUTS
-static void dpt_handle_timeouts(dpt_softc_t * dpt);
-static void dpt_timeout(void *dpt);
-#endif
+/* Definitions for our use of the SIM private CCB area */
+#define ccb_dccb_ptr spriv_ptr0
+#define ccb_dpt_ptr spriv_ptr1
+
+/* ================= Private Inline Function declarations ===================*/
+static __inline int dpt_just_reset(dpt_softc_t * dpt);
+static __inline int dpt_raid_busy(dpt_softc_t * dpt);
+static __inline int dpt_wait(dpt_softc_t *dpt, u_int bits,
+ u_int state);
+static __inline struct dpt_ccb* dptgetccb(struct dpt_softc *dpt);
+static __inline void dptfreeccb(struct dpt_softc *dpt,
+ struct dpt_ccb *dccb);
+static __inline u_int32_t dptccbvtop(struct dpt_softc *dpt,
+ struct dpt_ccb *dccb);
+
+static __inline int dpt_send_immediate(dpt_softc_t *dpt,
+ eata_ccb_t *cmd_block,
+ u_int32_t cmd_busaddr,
+ u_int retries,
+ u_int ifc, u_int code,
+ u_int code2);
+
+/* ==================== Private Function declarations =======================*/
+static void dptmapmem(void *arg, bus_dma_segment_t *segs,
+ int nseg, int error);
+
+static struct sg_map_node*
+ dptallocsgmap(struct dpt_softc *dpt);
+
+static int dptallocccbs(dpt_softc_t *dpt);
+
+static int dpt_get_conf(dpt_softc_t *dpt, dpt_ccb_t *dccb,
+ u_int32_t dccb_busaddr, u_int size,
+ u_int page, u_int target, int extent);
+static void dpt_detect_cache(dpt_softc_t *dpt, dpt_ccb_t *dccb,
+ u_int32_t dccb_busaddr,
+ u_int8_t *buff);
+
+static void dpt_poll(struct cam_sim *sim);
+
+static void dptexecuteccb(void *arg, bus_dma_segment_t *dm_segs,
+ int nseg, int error);
+
+static void dpt_action(struct cam_sim *sim, union ccb *ccb);
+
+static int dpt_send_eata_command(dpt_softc_t *dpt, eata_ccb_t *cmd,
+ u_int32_t cmd_busaddr,
+ u_int command, u_int retries,
+ u_int ifc, u_int code,
+ u_int code2);
+static void dptprocesserror(dpt_softc_t *dpt, dpt_ccb_t *dccb,
+ union ccb *ccb, u_int hba_stat,
+ u_int scsi_stat, u_int32_t resid);
+
+static void dpttimeout(void *arg);
+static void dptshutdown(int howto, void *arg);
+
+/* ================= Private Inline Function definitions ====================*/
+static __inline int
+dpt_just_reset(dpt_softc_t * dpt)
+{
+ if ((dpt_inb(dpt, 2) == 'D')
+ && (dpt_inb(dpt, 3) == 'P')
+ && (dpt_inb(dpt, 4) == 'T')
+ && (dpt_inb(dpt, 5) == 'H'))
+ return (1);
+ else
+ return (0);
+}
-#ifdef DPT_LOST_IRQ
-static void dpt_irq_timeout(void *dpt);
-#endif
+static __inline int
+dpt_raid_busy(dpt_softc_t * dpt)
+{
+ if ((dpt_inb(dpt, 0) == 'D')
+ && (dpt_inb(dpt, 1) == 'P')
+ && (dpt_inb(dpt, 2) == 'T'))
+ return (1);
+ else
+ return (0);
+}
-typedef struct scsi_inquiry_data s_inq_data_t;
+static __inline int
+dpt_wait(dpt_softc_t *dpt, u_int bits, u_int state)
+{
+ int i;
+ u_int c;
+ for (i = 0; i < 20000; i++) { /* wait 20ms for not busy */
+ c = dpt_inb(dpt, HA_RSTATUS) & bits;
+ if (c == state)
+ return (0);
+ else
+ DELAY(50);
+ }
+ return (-1);
+}
-static int
-dpt_scatter_gather(dpt_softc_t * dpt, dpt_ccb_t * ccb,
- u_int32_t data_length,
- caddr_t data);
-static int dpt_alloc_freelist(dpt_softc_t * dpt);
-static void dpt_run_queue(dpt_softc_t * dpt, int requests);
-static void dpt_complete(dpt_softc_t * dpt);
-static int
-dpt_process_completion(dpt_softc_t * dpt,
- dpt_ccb_t * ccb);
-static void
-dpt_set_target(int redo, dpt_softc_t * dpt,
- u_int8_t bus, u_int8_t target, u_int8_t lun, int mode,
- u_int16_t length, u_int16_t offset, dpt_ccb_t * ccb);
-static void
-dpt_target_ccb(dpt_softc_t * dpt, int bus, u_int8_t target, u_int8_t lun,
- dpt_ccb_t * ccb, int mode, u_int8_t command,
- u_int16_t length, u_int16_t offset);
-static void dpt_target_done(dpt_softc_t * dpt, int bus, dpt_ccb_t * ccb);
-static void dpt_user_cmd_done(dpt_softc_t * dpt, int bus, dpt_ccb_t * ccb);
+static __inline struct dpt_ccb*
+dptgetccb(struct dpt_softc *dpt)
+{
+ struct dpt_ccb* dccb;
+ int s;
+
+ s = splcam();
+ if ((dccb = SLIST_FIRST(&dpt->free_dccb_list)) != NULL) {
+ SLIST_REMOVE_HEAD(&dpt->free_dccb_list, links);
+ dpt->free_dccbs--;
+ } else if (dpt->total_dccbs < dpt->max_dccbs) {
+ dptallocccbs(dpt);
+ dccb = SLIST_FIRST(&dpt->free_dccb_list);
+ if (dccb == NULL)
+ printf("dpt%d: Can't malloc DCCB\n", dpt->unit);
+ else {
+ SLIST_REMOVE_HEAD(&dpt->free_dccb_list, links);
+ dpt->free_dccbs--;
+ }
+ }
+ splx(s);
+ return (dccb);
+}
+static __inline void
+dptfreeccb(struct dpt_softc *dpt, struct dpt_ccb *dccb)
+{
+ int s;
+
+ s = splcam();
+ if ((dccb->state & DCCB_ACTIVE) != 0)
+ LIST_REMOVE(&dccb->ccb->ccb_h, sim_links.le);
+ if ((dccb->state & DCCB_RELEASE_SIMQ) != 0)
+ dccb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
+ else if (dpt->resource_shortage != 0
+ && (dccb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
+ dccb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
+ dpt->resource_shortage = FALSE;
+ }
+ dccb->state = DCCB_FREE;
+ SLIST_INSERT_HEAD(&dpt->free_dccb_list, dccb, links);
+ ++dpt->free_dccbs;
+ splx(s);
+}
-u_int8_t dpt_blinking_led(dpt_softc_t * dpt);
-int
-dpt_user_cmd(dpt_softc_t * dpt, eata_pt_t * user_cmd,
- caddr_t cmdarg, int minor_no);
-void dpt_detect_cache(dpt_softc_t * dpt);
-void dpt_shutdown(int howto, void *dpt);
-static void hex_dump(u_int8_t * data, int length, char *name, int no);
-char *i2bin(unsigned int no, int length);
-dpt_conf_t *
-dpt_get_conf(dpt_softc_t * dpt, u_int8_t page, u_int8_t target,
- u_int8_t size, int extent);
-static dpt_inq_t *dpt_get_board_data(dpt_softc_t * dpt, u_int32_t target_id);
-int dpt_setup(dpt_softc_t * dpt, dpt_conf_t * conf);
-int dpt_attach(dpt_softc_t * dpt);
-static int32_t dpt_scsi_cmd(struct scsi_xfer * xs);
-static void dptminphys(struct buf * bp);
-static void dpt_sintr(void);
-void dpt_intr(void *arg);
-static char *scsi_cmd_name(u_int8_t cmd);
-
-dpt_rb_t
-dpt_register_buffer(int unit,
- u_int8_t channel,
- u_int8_t target,
- u_int8_t lun,
- u_int8_t mode,
- u_int16_t length,
- u_int16_t offset,
- dpt_rec_buff callback,
- dpt_rb_op_t op);
-int
-dpt_send_buffer(int unit,
- u_int8_t channel,
- u_int8_t target,
- u_int8_t lun,
- u_int8_t mode,
- u_int16_t length,
- u_int16_t offset,
- void *data,
- buff_wr_done callback);
-
-extern void (*ihandlers[32]) __P((void));
-
-u_long dpt_unit; /* This one is kernel-related, do not touch! */
+static __inline u_int32_t
+dptccbvtop(struct dpt_softc *dpt, struct dpt_ccb *dccb)
+{
+ return (dpt->dpt_ccb_busbase
+ + (u_int32_t)((caddr_t)dccb - (caddr_t)dpt->dpt_dccbs));
+}
-/* The linked list of softc structures */
-TAILQ_HEAD(, dpt_softc) dpt_softc_list = TAILQ_HEAD_INITIALIZER(dpt_softc_list);
+static __inline struct dpt_ccb *
+dptccbptov(struct dpt_softc *dpt, u_int32_t busaddr)
+{
+ return (dpt->dpt_dccbs
+ + ((struct dpt_ccb *)busaddr
+ - (struct dpt_ccb *)dpt->dpt_ccb_busbase));
+}
/*
- * These will have to be setup by parameters passed at boot/load time. For
- * perfromance reasons, we make them constants for the time being.
+ * Send a command for immediate execution by the DPT
+ * See above function for IMPORTANT notes.
*/
-#define dpt_min_segs DPT_MAX_SEGS
-#define dpt_max_segs DPT_MAX_SEGS
-
-static struct scsi_adapter dpt_switch =
-{
- dpt_scsi_cmd,
- dptminphys,
- NULL,
- NULL,
- NULL,
- "dpt",
- {0, 0}
-};
-
-static struct scsi_device dpt_dev =
+static __inline int
+dpt_send_immediate(dpt_softc_t *dpt, eata_ccb_t *cmd_block,
+ u_int32_t cmd_busaddr, u_int retries,
+ u_int ifc, u_int code, u_int code2)
{
- NULL, /* Use default error handler */
- NULL, /* have a queue, served by this */
- NULL, /* have no async handler */
- NULL, /* Use default 'done' routine */
- "dpt",
- 0,
- {0, 0}
-};
+ return (dpt_send_eata_command(dpt, cmd_block, cmd_busaddr,
+ EATA_CMD_IMMEDIATE, retries, ifc,
+ code, code2));
+}
-/* Software Interrupt Vector */
+/* ===================== Private Function definitions =======================*/
static void
-dpt_swi_register(void *unused)
+dptmapmem(void *arg, bus_dma_segment_t *segs, int nseg, int error)
{
- ihandlers[SWI_CAMBIO] = dpt_sintr;
+ bus_addr_t *busaddrp;
+
+ busaddrp = (bus_addr_t *)arg;
+ *busaddrp = segs->ds_addr;
}
-SYSINIT(dpt_camswi, SI_SUB_DRIVERS, SI_ORDER_FIRST, dpt_swi_register, NULL)
-/* These functions allows us to do memory mapped I/O, if hardware supported. */
+static struct sg_map_node *
+dptallocsgmap(struct dpt_softc *dpt)
+{
+ struct sg_map_node *sg_map;
+
+ sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
+
+ if (sg_map == NULL)
+ return (NULL);
+
+ /* Allocate S/G space for the next batch of CCBS */
+ if (bus_dmamem_alloc(dpt->sg_dmat, (void **)&sg_map->sg_vaddr,
+ BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) {
+ free(sg_map, M_DEVBUF);
+ return (NULL);
+ }
- static INLINE u_int8_t
- dpt_inb(dpt_softc_t * dpt, u_int32_t offset)
+ SLIST_INSERT_HEAD(&dpt->sg_maps, sg_map, links);
+
+ bus_dmamap_load(dpt->sg_dmat, sg_map->sg_dmamap, sg_map->sg_vaddr,
+ PAGE_SIZE, dptmapmem, &sg_map->sg_physaddr, /*flags*/0);
+
+ return (sg_map);
+}
+
+/*
+ * Allocate another chunk of CCB's. Return count of entries added.
+ * Assumed to be called at splcam().
+ */
+static int
+dptallocccbs(dpt_softc_t *dpt)
{
- u_int8_t result;
+ struct dpt_ccb *next_ccb;
+ struct sg_map_node *sg_map;
+ bus_addr_t physaddr;
+ dpt_sg_t *segs;
+ int newcount;
+ int i;
+
+ next_ccb = &dpt->dpt_dccbs[dpt->total_dccbs];
- if (dpt->v_membase != NULL) {
- result = dpt->v_membase[offset];
+ if (next_ccb == dpt->dpt_dccbs) {
+ /*
+ * First time through. Re-use the S/G
+ * space we allocated for initialization
+ * CCBS.
+ */
+ sg_map = SLIST_FIRST(&dpt->sg_maps);
} else {
- result = inb(dpt->io_base + offset);
+ sg_map = dptallocsgmap(dpt);
}
- return (result);
+
+ if (sg_map == NULL)
+ return (0);
+
+ segs = sg_map->sg_vaddr;
+ physaddr = sg_map->sg_physaddr;
+
+ newcount = (PAGE_SIZE / (dpt->sgsize * sizeof(dpt_sg_t)));
+ for (i = 0; dpt->total_dccbs < dpt->max_dccbs && i < newcount; i++) {
+ int error;
+
+ error = bus_dmamap_create(dpt->buffer_dmat, /*flags*/0,
+ &next_ccb->dmamap);
+ if (error != 0)
+ break;
+ next_ccb->sg_list = segs;
+ next_ccb->sg_busaddr = htonl(physaddr);
+ next_ccb->eata_ccb.cp_dataDMA = htonl(physaddr);
+ next_ccb->eata_ccb.cp_statDMA = htonl(dpt->sp_physaddr);
+ next_ccb->eata_ccb.cp_reqDMA =
+ htonl(dptccbvtop(dpt, next_ccb)
+ + offsetof(struct dpt_ccb, sense_data));
+ next_ccb->eata_ccb.cp_busaddr = dpt->dpt_ccb_busend;
+
+ next_ccb->state = DCCB_FREE;
+ SLIST_INSERT_HEAD(&dpt->free_dccb_list, next_ccb, links);
+ segs += dpt->sgsize;;
+ physaddr += (dpt->sgsize * sizeof(dpt_sg_t));
+ dpt->dpt_ccb_busend += sizeof(*next_ccb);
+ next_ccb++;
+ dpt->total_dccbs++;
+ }
+ return (i);
}
-static INLINE u_int32_t
-dpt_inl(dpt_softc_t * dpt, u_int32_t offset)
+/*
+ * Read a configuration page into the supplied dpt_cont_t buffer.
+ */
+static int
+dpt_get_conf(dpt_softc_t *dpt, dpt_ccb_t *dccb, u_int32_t dccb_busaddr,
+ u_int size, u_int page, u_int target, int extent)
{
- u_int32_t result;
+ eata_ccb_t *cp;
- if (dpt->v_membase != NULL) {
- result = *(volatile u_int32_t *) (&dpt->v_membase[offset]);
- } else {
- result = inl(dpt->io_base + offset);
+ u_int16_t *ip;
+ u_int8_t status, sig1, sig2, sig3;
+
+ int ndx;
+ int ospl;
+ int result;
+
+ cp = &dccb->eata_ccb;
+ bzero((void *)dpt->sp, sizeof(*dpt->sp));
+
+ cp->Interpret = 1;
+ cp->DataIn = 1;
+ cp->Auto_Req_Sen = 1;
+ cp->reqlen = sizeof(struct scsi_sense_data);
+
+ cp->cp_id = target;
+ cp->cp_LUN = 0; /* In the EATA packet */
+ cp->cp_lun = 0; /* In the SCSI command */
+
+ cp->cp_scsi_cmd = INQUIRY;
+ cp->cp_len = size;
+
+ cp->cp_extent = extent;
+
+ cp->cp_page = page;
+ cp->cp_channel = 0; /* DNC, Interpret mode is set */
+ cp->cp_identify = 1;
+ cp->cp_datalen = htonl(size);
+
+ ospl = splcam();
+
+ /*
+ * This could be a simple for loop, but we suspected the compiler To
+ * have optimized it a bit too much. Wait for the controller to
+ * become ready
+ */
+ while (((status = dpt_inb(dpt, HA_RSTATUS)) != (HA_SREADY | HA_SSC)
+ && (status != (HA_SREADY | HA_SSC | HA_SERROR))
+ && (status != (HA_SDRDY | HA_SERROR | HA_SDRQ)))
+ || (dpt_wait(dpt, HA_SBUSY, 0))) {
+
+ /*
+ * RAID Drives still Spinning up? (This should only occur if
+ * the DPT controller is in a NON PC (PCI?) platform).
+ */
+ if (dpt_raid_busy(dpt)) {
+ printf("dpt%d WARNING: Get_conf() RSUS failed.\n",
+ dpt->unit);
+ splx(ospl);
+ return (0);
+ }
}
- return (result);
+
+ DptStat_Reset_BUSY(dpt->sp);
+
+ /*
+ * XXXX We might want to do something more clever than aborting at
+ * this point, like resetting (rebooting) the controller and trying
+ * again.
+ */
+ if ((result = dpt_send_eata_command(dpt, cp, dccb_busaddr,
+ EATA_CMD_DMA_SEND_CP,
+ 10000, 0, 0, 0)) != 0) {
+ printf("dpt%d WARNING: Get_conf() failed (%d) to send "
+ "EATA_CMD_DMA_READ_CONFIG\n",
+ dpt->unit, result);
+ splx(ospl);
+ return (0);
+ }
+ /* Wait for two seconds for a response. This can be slow */
+ for (ndx = 0;
+ (ndx < 20000)
+ && !((status = dpt_inb(dpt, HA_RAUXSTAT)) & HA_AIRQ);
+ ndx++) {
+ DELAY(50);
+ }
+
+ /* Grab the status and clear interrupts */
+ status = dpt_inb(dpt, HA_RSTATUS);
+
+ splx(ospl);
+
+ /*
+ * Check the status carefully. Return only if the
+ * command was successful.
+ */
+ if (((status & HA_SERROR) == 0)
+ && (dpt->sp->hba_stat == 0)
+ && (dpt->sp->scsi_stat == 0)
+ && (dpt->sp->residue_len == 0))
+ return (0);
+ return (1);
}
-static INLINE void
-dpt_outb(dpt_softc_t * dpt, u_int32_t offset, u_int8_t value)
+/* Detect Cache parameters and size */
+static void
+dpt_detect_cache(dpt_softc_t *dpt, dpt_ccb_t *dccb, u_int32_t dccb_busaddr,
+ u_int8_t *buff)
{
- if (dpt->v_membase != NULL) {
- dpt->v_membase[offset] = value;
- } else {
- outb(dpt->io_base + offset, value);
+ eata_ccb_t *cp;
+ u_int8_t *param;
+ int size;
+ int bytes;
+ int result;
+ int ospl;
+ int ndx;
+ u_int8_t status;
+
+ /*
+ * Default setting, for best perfromance..
+ * This is what virtually all cards default to..
+ */
+ dpt->cache_type = DPT_CACHE_WRITEBACK;
+ dpt->cache_size = 0;
+
+ cp = &dccb->eata_ccb;
+ bzero((void *)dpt->sp, sizeof(dpt->sp));
+ bzero(buff, 512);
+
+ /* Setup the command structure */
+ cp->Interpret = 1;
+ cp->DataIn = 1;
+ cp->Auto_Req_Sen = 1;
+ cp->reqlen = sizeof(struct scsi_sense_data);
+
+ cp->cp_id = 0; /* who cares? The HBA will interpret.. */
+ cp->cp_LUN = 0; /* In the EATA packet */
+ cp->cp_lun = 0; /* In the SCSI command */
+ cp->cp_channel = 0;
+
+ cp->cp_scsi_cmd = EATA_CMD_DMA_SEND_CP;
+ cp->cp_len = 56;
+
+ cp->cp_extent = 0;
+ cp->cp_page = 0;
+ cp->cp_identify = 1;
+ cp->cp_dispri = 1;
+
+ /*
+ * Build the EATA Command Packet structure
+ * for a Log Sense Command.
+ */
+ cp->cp_cdb[0] = 0x4d;
+ cp->cp_cdb[1] = 0x0;
+ cp->cp_cdb[2] = 0x40 | 0x33;
+ cp->cp_cdb[7] = 1;
+
+ cp->cp_datalen = htonl(512);
+
+ ospl = splcam();
+ result = dpt_send_eata_command(dpt, cp, dccb_busaddr,
+ EATA_CMD_DMA_SEND_CP,
+ 10000, 0, 0, 0);
+ if (result != 0) {
+ printf("dpt%d WARNING: detect_cache() failed (%d) to send "
+ "EATA_CMD_DMA_SEND_CP\n", dpt->unit, result);
+ splx(ospl);
+ return;
+ }
+ /* Wait for two seconds for a response. This can be slow... */
+ for (ndx = 0;
+ (ndx < 20000) &&
+ !((status = dpt_inb(dpt, HA_RAUXSTAT)) & HA_AIRQ);
+ ndx++) {
+ DELAY(50);
+ }
+
+ /* Grab the status and clear interrupts */
+ status = dpt_inb(dpt, HA_RSTATUS);
+ splx(ospl);
+
+ /*
+ * Sanity check
+ */
+ if (buff[0] != 0x33) {
+ return;
+ }
+ bytes = DPT_HCP_LENGTH(buff);
+ param = DPT_HCP_FIRST(buff);
+
+ if (DPT_HCP_CODE(param) != 1) {
+ /*
+ * DPT Log Page layout error
+ */
+ printf("dpt%d: NOTICE: Log Page (1) layout error\n",
+ dpt->unit);
+ return;
}
+ if (!(param[4] & 0x4)) {
+ dpt->cache_type = DPT_NO_CACHE;
+ return;
+ }
+ while (DPT_HCP_CODE(param) != 6) {
+ param = DPT_HCP_NEXT(param);
+ if ((param < buff)
+ || (param >= &buff[bytes])) {
+ return;
+ }
+ }
+
+ if (param[4] & 0x2) {
+ /*
+ * Cache disabled
+ */
+ dpt->cache_type = DPT_NO_CACHE;
+ return;
+ }
+
+ if (param[4] & 0x4) {
+ dpt->cache_type = DPT_CACHE_WRITETHROUGH;
+ }
+
+ /* XXX This isn't correct. This log parameter only has two bytes.... */
+#if 0
+ dpt->cache_size = param[5]
+ | (param[6] << 8)
+ | (param[7] << 16)
+ | (param[8] << 24);
+#endif
+}
+
+static void
+dpt_poll(struct cam_sim *sim)
+{
+ dpt_intr(cam_sim_softc(sim));
}
-static INLINE void
-dpt_outl(dpt_softc_t * dpt, u_int32_t offset, u_int32_t value)
+static void
+dptexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
{
- if (dpt->v_membase != NULL) {
- *(volatile u_int32_t *) (&dpt->v_membase[offset]) = value;
+ struct dpt_ccb *dccb;
+ union ccb *ccb;
+ struct dpt_softc *dpt;
+ int s, i;
+
+ dccb = (struct dpt_ccb *)arg;
+ ccb = dccb->ccb;
+ dpt = (struct dpt_softc *)ccb->ccb_h.ccb_dpt_ptr;
+
+ if (error != 0) {
+ if (error != EFBIG)
+ printf("dpt%d: Unexepected error 0x%x returned from "
+ "bus_dmamap_load\n", dpt->unit);
+ if (ccb->ccb_h.status == CAM_REQ_INPROG) {
+ xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
+ ccb->ccb_h.status = CAM_REQ_TOO_BIG|CAM_DEV_QFRZN;
+ }
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+ return;
+ }
+
+ if (nseg != 0) {
+ dpt_sg_t *sg;
+ bus_dma_segment_t *end_seg;
+ bus_dmasync_op_t op;
+
+ end_seg = dm_segs + nseg;
+
+ /* Copy the segments into our SG list */
+ sg = dccb->sg_list;
+ while (dm_segs < end_seg) {
+ sg->seg_len = htonl(dm_segs->ds_len);
+ sg->seg_addr = htonl(dm_segs->ds_addr);
+ sg++;
+ dm_segs++;
+ }
+
+ if (nseg > 1) {
+ dccb->eata_ccb.scatter = 1;
+ dccb->eata_ccb.cp_dataDMA = dccb->sg_busaddr;
+ dccb->eata_ccb.cp_datalen =
+ htonl(nseg * sizeof(dpt_sg_t));
+ } else {
+ dccb->eata_ccb.cp_dataDMA = dccb->sg_list[0].seg_addr;
+ dccb->eata_ccb.cp_datalen = dccb->sg_list[0].seg_len;
+ }
+
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
+ op = BUS_DMASYNC_PREREAD;
+ else
+ op = BUS_DMASYNC_PREWRITE;
+
+ bus_dmamap_sync(dpt->buffer_dmat, dccb->dmamap, op);
+
} else {
- outl(dpt->io_base + offset, value);
+ dccb->eata_ccb.cp_dataDMA = 0;
+ dccb->eata_ccb.cp_datalen = 0;
+ }
+
+ s = splcam();
+
+ /*
+ * Last time we need to check if this CCB needs to
+ * be aborted.
+ */
+ if (ccb->ccb_h.status != CAM_REQ_INPROG) {
+ if (nseg != 0)
+ bus_dmamap_unload(dpt->buffer_dmat, dccb->dmamap);
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+ splx(s);
+ return;
}
+
+ dccb->state |= DCCB_ACTIVE;
+ ccb->ccb_h.status |= CAM_SIM_QUEUED;
+ LIST_INSERT_HEAD(&dpt->pending_ccb_list, &ccb->ccb_h, sim_links.le);
+ ccb->ccb_h.timeout_ch =
+ timeout(dpttimeout, (caddr_t)dccb,
+ (ccb->ccb_h.timeout * hz) / 1000);
+ if (dpt_send_eata_command(dpt, &dccb->eata_ccb,
+ dccb->eata_ccb.cp_busaddr,
+ EATA_CMD_DMA_SEND_CP, 0, 0, 0, 0) != 0) {
+ ccb->ccb_h.status = CAM_NO_HBA; /* HBA dead or just busy?? */
+ if (nseg != 0)
+ bus_dmamap_unload(dpt->buffer_dmat, dccb->dmamap);
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+ }
+
+ splx(s);
}
-static INLINE void
-dpt_sched_queue(dpt_softc_t * dpt)
+static void
+dpt_action(struct cam_sim *sim, union ccb *ccb)
{
- if (dpt->state & DPT_HA_QUIET) {
- printf("dpt%d: Under Quiet Busses Condition. "
- "No Commands are submitted\n", dpt->unit);
+ struct dpt_softc *dpt;
+ int s;
+
+ CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("dpt_action\n"));
+
+ dpt = (struct dpt_softc *)cam_sim_softc(sim);
+
+ if ((dpt->state & DPT_HA_SHUTDOWN_ACTIVE) != 0) {
+ xpt_print_path(ccb->ccb_h.path);
+ printf("controller is shutdown. Aborting CCB.\n");
+ ccb->ccb_h.status = CAM_NO_HBA;
+ xpt_done(ccb);
return;
}
- setsoftcambio();
+
+ switch (ccb->ccb_h.func_code) {
+ /* Common cases first */
+ case XPT_SCSI_IO: /* Execute the requested I/O operation */
+ {
+ struct ccb_scsiio *csio;
+ struct ccb_hdr *ccbh;
+ struct dpt_ccb *dccb;
+ struct eata_ccb *eccb;
+
+ csio = &ccb->csio;
+ ccbh = &ccb->ccb_h;
+ /* Max CDB length is 12 bytes */
+ if (csio->cdb_len > 12) {
+ ccb->ccb_h.status = CAM_REQ_INVALID;
+ xpt_done(ccb);
+ return;
+ }
+ if ((dccb = dptgetccb(dpt)) == NULL) {
+ int s;
+
+ s = splcam();
+ dpt->resource_shortage = 1;
+ splx(s);
+ xpt_freeze_simq(sim, /*count*/1);
+ ccb->ccb_h.status = CAM_REQUEUE_REQ;
+ xpt_done(ccb);
+ return;
+ }
+ eccb = &dccb->eata_ccb;
+
+ /* Link dccb and ccb so we can find one from the other */
+ dccb->ccb = ccb;
+ ccb->ccb_h.ccb_dccb_ptr = dccb;
+ ccb->ccb_h.ccb_dpt_ptr = dpt;
+
+ /*
+ * Explicitly set all flags so that the compiler can
+ * be smart about setting our bit flags.
+ */
+ eccb->SCSI_Reset = 0;
+ eccb->HBA_Init = 0;
+ eccb->Auto_Req_Sen = (ccb->ccb_h.flags & CAM_DIS_AUTOSENSE)
+ ? 0 : 1;
+ eccb->scatter = 0;
+ eccb->Quick = 0;
+ eccb->Interpret =
+ ccb->ccb_h.target_id == dpt->hostid[cam_sim_bus(sim)]
+ ? 1 : 0;
+ eccb->DataOut = (ccb->ccb_h.flags & CAM_DIR_OUT) ? 1 : 0;
+ eccb->DataIn = (ccb->ccb_h.flags & CAM_DIR_IN) ? 1 : 0;
+ eccb->reqlen = csio->sense_len;
+ eccb->cp_id = ccb->ccb_h.target_id;
+ eccb->cp_channel = cam_sim_bus(sim);
+ eccb->cp_LUN = ccb->ccb_h.target_lun;
+ eccb->cp_luntar = 0;
+ eccb->cp_dispri = (ccb->ccb_h.flags & CAM_DIS_DISCONNECT)
+ ? 0 : 1;
+ eccb->cp_identify = 1;
+ /*
+ * XXX JGibbs
+ * These are supposedly used for tagged queuing.
+ * We should honor the tag type in the incoming CCB, but
+ * I don't have DPT documentation to ensure that I do
+ * this correctly.
+ */
+ eccb->cp_msg[0] = 0;
+ eccb->cp_msg[1] = 0;
+ eccb->cp_msg[2] = 0;
+
+ if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0) {
+ if ((ccb->ccb_h.flags & CAM_CDB_PHYS) == 0) {
+ bcopy(csio->cdb_io.cdb_ptr,
+ eccb->cp_cdb, csio->cdb_len);
+ } else {
+ /* I guess I could map it in... */
+ ccb->ccb_h.status = CAM_REQ_INVALID;
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+ return;
+ }
+ } else {
+ bcopy(csio->cdb_io.cdb_bytes,
+ eccb->cp_cdb, csio->cdb_len);
+ }
+ /*
+ * If we have any data to send with this command,
+ * map it into bus space.
+ */
+ /* Only use S/G if there is a transfer */
+ if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
+ if ((ccbh->flags & CAM_SCATTER_VALID) == 0) {
+ /*
+ * We've been given a pointer
+ * to a single buffer.
+ */
+ if ((ccbh->flags & CAM_DATA_PHYS) == 0) {
+ int s;
+ int error;
+
+ s = splsoftvm();
+ error =
+ bus_dmamap_load(dpt->buffer_dmat,
+ dccb->dmamap,
+ csio->data_ptr,
+ csio->dxfer_len,
+ dptexecuteccb,
+ dccb, /*flags*/0);
+ if (error == EINPROGRESS) {
+ /*
+ * So as to maintain ordering,
+ * freeze the controller queue
+ * until our mapping is
+ * returned.
+ */
+ xpt_freeze_simq(sim, 1);
+ dccb->state |= CAM_RELEASE_SIMQ;
+ CAM_RELEASE_SIMQ;
+ }
+ splx(s);
+ } else {
+ struct bus_dma_segment seg;
+
+ /* Pointer to physical buffer */
+ seg.ds_addr =
+ (bus_addr_t)csio->data_ptr;
+ seg.ds_len = csio->dxfer_len;
+ dptexecuteccb(dccb, &seg, 1, 0);
+ }
+ } else {
+ struct bus_dma_segment *segs;
+
+ if ((ccbh->flags & CAM_DATA_PHYS) != 0)
+ panic("btaction - Physical "
+ "segment pointers "
+ "unsupported");
+
+ if ((ccbh->flags&CAM_SG_LIST_PHYS)==0)
+ panic("btaction - Virtual "
+ "segment addresses "
+ "unsupported");
+
+ /* Just use the segments provided */
+ segs = (struct bus_dma_segment *)
+ csio->data_ptr;
+ dptexecuteccb(dccb, segs, csio->sglist_cnt, 0);
+ }
+ } else {
+ /*
+ * XXX JGibbs.
+ * Does it want them both on or both off?
+ * CAM_DIR_NONE is both on, so this code can
+ * be removed if this is also what the DPT
+ * exptects.
+ */
+ eccb->DataOut = 0;
+ eccb->DataIn = 0;
+ dptexecuteccb(dccb, NULL, 0, 0);
+ }
+ break;
+ }
+ case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
+ case XPT_ABORT: /* Abort the specified CCB */
+ /* XXX Implement */
+ ccb->ccb_h.status = CAM_REQ_INVALID;
+ xpt_done(ccb);
+ break;
+ case XPT_SET_TRAN_SETTINGS:
+ {
+ ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
+ xpt_done(ccb);
+ break;
+ }
+ case XPT_GET_TRAN_SETTINGS:
+ /* Get default/user set transfer settings for the target */
+ {
+ struct ccb_trans_settings *cts;
+ u_int target_mask;
+
+ cts = &ccb->cts;
+ target_mask = 0x01 << ccb->ccb_h.target_id;
+ if ((cts->flags & CCB_TRANS_USER_SETTINGS) != 0) {
+ cts->flags = CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB;
+ cts->bus_width = (dpt->max_id > 7)
+ ? MSG_EXT_WDTR_BUS_8_BIT
+ : MSG_EXT_WDTR_BUS_16_BIT;
+ cts->sync_period = 25; /* 10MHz */
+
+ if (cts->sync_period != 0)
+ cts->sync_offset = 15;
+
+ cts->valid = CCB_TRANS_SYNC_RATE_VALID
+ | CCB_TRANS_SYNC_OFFSET_VALID
+ | CCB_TRANS_BUS_WIDTH_VALID
+ | CCB_TRANS_DISC_VALID
+ | CCB_TRANS_TQ_VALID;
+ ccb->ccb_h.status = CAM_REQ_CMP;
+ } else {
+ ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
+ }
+ xpt_done(ccb);
+ break;
+ }
+ case XPT_CALC_GEOMETRY:
+ {
+ struct ccb_calc_geometry *ccg;
+ u_int32_t size_mb;
+ u_int32_t secs_per_cylinder;
+ int extended;
+
+ /*
+ * XXX Use Adaptec translation until I find out how to
+ * get this information from the card.
+ */
+ ccg = &ccb->ccg;
+ size_mb = ccg->volume_size
+ / ((1024L * 1024L) / ccg->block_size);
+ extended = 1;
+
+ if (size_mb > 1024 && extended) {
+ ccg->heads = 255;
+ ccg->secs_per_track = 63;
+ } else {
+ ccg->heads = 64;
+ ccg->secs_per_track = 32;
+ }
+ secs_per_cylinder = ccg->heads * ccg->secs_per_track;
+ ccg->cylinders = ccg->volume_size / secs_per_cylinder;
+ ccb->ccb_h.status = CAM_REQ_CMP;
+ xpt_done(ccb);
+ break;
+ }
+ case XPT_RESET_BUS: /* Reset the specified SCSI bus */
+ {
+ /* XXX Implement */
+ ccb->ccb_h.status = CAM_REQ_CMP;
+ xpt_done(ccb);
+ break;
+ }
+ case XPT_TERM_IO: /* Terminate the I/O process */
+ /* XXX Implement */
+ ccb->ccb_h.status = CAM_REQ_INVALID;
+ xpt_done(ccb);
+ break;
+ case XPT_PATH_INQ: /* Path routing inquiry */
+ {
+ struct ccb_pathinq *cpi = &ccb->cpi;
+
+ cpi->version_num = 1;
+ cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
+ if (dpt->max_id > 7)
+ cpi->hba_inquiry |= PI_WIDE_16;
+ cpi->target_sprt = 0;
+ cpi->hba_misc = 0;
+ cpi->hba_eng_cnt = 0;
+ cpi->max_target = dpt->max_id;
+ cpi->max_lun = dpt->max_lun;
+ cpi->initiator_id = dpt->hostid[cam_sim_bus(sim)];
+ cpi->bus_id = cam_sim_bus(sim);
+ strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+ strncpy(cpi->hba_vid, "DPT", HBA_IDLEN);
+ strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
+ cpi->unit_number = cam_sim_unit(sim);
+ cpi->ccb_h.status = CAM_REQ_CMP;
+ xpt_done(ccb);
+ break;
+ }
+ default:
+ ccb->ccb_h.status = CAM_REQ_INVALID;
+ xpt_done(ccb);
+ break;
+ }
}
-static INLINE int
-dpt_wait(dpt_softc_t * dpt, u_int8_t bits, u_int8_t state)
+/*
+ * This routine will try to send an EATA command to the DPT HBA.
+ * It will, by default, try 20,000 times, waiting 50us between tries.
+ * It returns 0 on success and 1 on failure.
+ * It is assumed to be called at splcam().
+ */
+static int
+dpt_send_eata_command(dpt_softc_t *dpt, eata_ccb_t *cmd_block,
+ u_int32_t cmd_busaddr, u_int command, u_int retries,
+ u_int ifc, u_int code, u_int code2)
{
- int i;
- u_int8_t c;
+ u_int loop;
+ u_int result;
+ u_int test;
+
+ if (!retries)
+ retries = 20000;
- for (i = 0; i < 20000; i++) { /* wait 20ms for not busy */
- c = dpt_inb(dpt, HA_RSTATUS) & bits;
- if (c == state)
- return (0);
+ /*
+ * I hate this polling nonsense. Wish there was a way to tell the DPT
+ * to go get commands at its own pace, or to interrupt when ready.
+ * In the mean time we will measure how many itterations it really
+ * takes.
+ */
+ for (loop = 0; loop < retries; loop++) {
+ if ((dpt_inb(dpt, HA_RAUXSTAT) & HA_ABUSY) == 0)
+ break;
else
DELAY(50);
}
- return (-1);
+
+ if (loop < retries) {
+#ifdef DPT_MEASURE_PERFORMANCE
+ if (loop > dpt->performance.max_eata_tries)
+ dpt->performance.max_eata_tries = loop;
+
+ if (loop < dpt->performance.min_eata_tries)
+ dpt->performance.min_eata_tries = loop;
+#endif
+ } else {
+#ifdef DPT_MEASURE_PERFORMANCE
+ ++dpt->performance.command_too_busy;
+#endif
+ return (1);
+ }
+
+ /* The controller is alive, advance the wedge timer */
+#ifdef DPT_RESET_HBA
+ dpt->last_contact = microtime_now;
+#endif
+
+ if (cmd_block == NULL)
+ cmd_busaddr = 0;
+#if (BYTE_ORDER == BIG_ENDIAN)
+ else {
+ cmd_busaddr = ((cmd_busaddr >> 24) & 0xFF)
+ | ((cmd_busaddr >> 16) & 0xFF)
+ | ((cmd_busaddr >> 8) & 0xFF)
+ | (cmd_busaddr & 0xFF);
+ }
+#endif
+ /* And now the address */
+ dpt_outl(dpt, HA_WDMAADDR, cmd_busaddr);
+
+ if (command == EATA_CMD_IMMEDIATE) {
+ if (cmd_block == NULL) {
+ dpt_outb(dpt, HA_WCODE2, code2);
+ dpt_outb(dpt, HA_WCODE, code);
+ }
+ dpt_outb(dpt, HA_WIFC, ifc);
+ }
+ dpt_outb(dpt, HA_WCOMMAND, command);
+
+ return (0);
}
-static INLINE int
-dpt_just_reset(dpt_softc_t * dpt)
+
+/* ==================== Exported Function definitions =======================*/
+struct dpt_softc *
+dpt_alloc(u_int unit, bus_space_tag_t tag, bus_space_handle_t bsh)
{
- if ((dpt_inb(dpt, 2) == 'D')
- && (dpt_inb(dpt, 3) == 'P')
- && (dpt_inb(dpt, 4) == 'T')
- && (dpt_inb(dpt, 5) == 'H'))
- return (1);
- else
- return (0);
+ struct dpt_softc *dpt;
+ int i;
+
+ dpt = (struct dpt_softc *)malloc(sizeof(*dpt), M_DEVBUF, M_NOWAIT);
+ if (dpt == NULL) {
+ printf("dpt%d: Unable to allocate softc\n", dpt->unit);
+ return (NULL);
+ }
+
+ bzero(dpt, sizeof(dpt_softc_t));
+ dpt->tag = tag;
+ dpt->bsh = bsh;
+ dpt->unit = unit;
+ SLIST_INIT(&dpt->free_dccb_list);
+ LIST_INIT(&dpt->pending_ccb_list);
+ TAILQ_INSERT_TAIL(&dpt_softcs, dpt, links);
+ for (i = 0; i < MAX_CHANNELS; i++)
+ dpt->resetlevel[i] = DPT_HA_OK;
+
+#ifdef DPT_MEASURE_PERFORMANCE
+ dpt_reset_performance(dpt);
+#endif /* DPT_MEASURE_PERFORMANCE */
+ return (dpt);
}
-static INLINE int
-dpt_raid_busy(dpt_softc_t * dpt)
+void
+dpt_free(struct dpt_softc *dpt)
{
- if ((dpt_inb(dpt, 0) == 'D')
- && (dpt_inb(dpt, 1) == 'P')
- && (dpt_inb(dpt, 2) == 'T'))
- return (1);
+ switch (dpt->init_level) {
+ default:
+ case 5:
+ bus_dmamap_unload(dpt->dccb_dmat, dpt->dccb_dmamap);
+ case 4:
+ bus_dmamem_free(dpt->dccb_dmat, dpt->dpt_dccbs,
+ dpt->dccb_dmamap);
+ bus_dmamap_destroy(dpt->dccb_dmat, dpt->dccb_dmamap);
+ case 3:
+ bus_dma_tag_destroy(dpt->dccb_dmat);
+ case 2:
+ bus_dma_tag_destroy(dpt->buffer_dmat);
+ case 1:
+ {
+ struct sg_map_node *sg_map;
+
+ while ((sg_map = SLIST_FIRST(&dpt->sg_maps)) != NULL) {
+ SLIST_REMOVE_HEAD(&dpt->sg_maps, links);
+ bus_dmamap_unload(dpt->sg_dmat,
+ sg_map->sg_dmamap);
+ bus_dmamem_free(dpt->sg_dmat, sg_map->sg_vaddr,
+ sg_map->sg_dmamap);
+ free(sg_map, M_DEVBUF);
+ }
+ bus_dma_tag_destroy(dpt->sg_dmat);
+ }
+ case 0:
+ break;
+ }
+ TAILQ_REMOVE(&dpt_softcs, dpt, links);
+ free(dpt, M_DEVBUF);
+}
+
+u_int8_t string_sizes[] =
+{
+ sizeof(((dpt_inq_t*)NULL)->vendor),
+ sizeof(((dpt_inq_t*)NULL)->modelNum),
+ sizeof(((dpt_inq_t*)NULL)->firmware),
+ sizeof(((dpt_inq_t*)NULL)->protocol),
+};
+
+int
+dpt_init(struct dpt_softc *dpt)
+{
+ dpt_conf_t conf;
+ struct sg_map_node *sg_map;
+ dpt_ccb_t *dccb;
+ u_int8_t *strp;
+ int index;
+ int i;
+ int retval;
+ u_int8_t byte;
+
+#ifdef DPT_RESET_BOARD
+ printf("dpt%d: resetting HBA\n", dpt->unit);
+ dpt_outb(dpt, HA_WCOMMAND, EATA_CMD_RESET);
+ DELAY(750000);
+ /* XXX Shouldn't we poll a status register or something??? */
+#endif
+ /* DMA tag for our S/G structures. We allocate in page sized chunks */
+ if (bus_dma_tag_create(dpt->parent_dmat, /*alignment*/0, /*boundary*/0,
+ /*lowaddr*/BUS_SPACE_MAXADDR,
+ /*highaddr*/BUS_SPACE_MAXADDR,
+ /*filter*/NULL, /*filterarg*/NULL,
+ PAGE_SIZE, /*nsegments*/1,
+ /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+ /*flags*/0, &dpt->sg_dmat) != 0) {
+ goto error_exit;
+ }
+
+ dpt->init_level++;
+
+ /*
+ * We allocate our DPT ccbs as a contiguous array of bus dma'able
+ * memory. To get the allocation size, we need to know how many
+ * ccbs the card supports. This requires a ccb. We solve this
+ * chicken and egg problem by allocating some re-usable S/G space
+ * up front, and treating it as our status packet, CCB, and target
+ * memory space for these commands.
+ */
+ sg_map = dptallocsgmap(dpt);
+ if (sg_map == NULL)
+ goto error_exit;
+
+ dpt->sp = (volatile dpt_sp_t *)sg_map->sg_vaddr;
+ dccb = (struct dpt_ccb *)&dpt->sp[1];
+ bzero(dccb, sizeof(*dccb));
+ dpt->sp_physaddr = sg_map->sg_physaddr;
+ dccb->eata_ccb.cp_dataDMA =
+ htonl(sg_map->sg_physaddr + sizeof(dpt_sp_t) + sizeof(*dccb));
+ dccb->eata_ccb.cp_busaddr = ~0;
+ dccb->eata_ccb.cp_statDMA = htonl(dpt->sp_physaddr);
+ dccb->eata_ccb.cp_reqDMA = htonl(dpt->sp_physaddr + sizeof(*dccb)
+ + offsetof(struct dpt_ccb, sense_data));
+
+ /* Okay. Fetch our config */
+ bzero(&dccb[1], sizeof(conf)); /* data area */
+ retval = dpt_get_conf(dpt, dccb, sg_map->sg_physaddr + sizeof(dpt_sp_t),
+ sizeof(conf), 0xc1, 7, 1);
+
+ if (retval != 0) {
+ printf("dpt%d: Failed to get board configuration\n", dpt->unit);
+ return (retval);
+ }
+ bcopy(&dccb[1], &conf, sizeof(conf));
+
+ bzero(&dccb[1], sizeof(dpt->board_data));
+ retval = dpt_get_conf(dpt, dccb, sg_map->sg_physaddr + sizeof(dpt_sp_t),
+ sizeof(dpt->board_data), 0, conf.scsi_id0, 0);
+ if (retval != 0) {
+ printf("dpt%d: Failed to get inquiry information\n", dpt->unit);
+ return (retval);
+ }
+ bcopy(&dccb[1], &dpt->board_data, sizeof(dpt->board_data));
+
+ dpt_detect_cache(dpt, dccb, sg_map->sg_physaddr + sizeof(dpt_sp_t),
+ (u_int8_t *)&dccb[1]);
+
+ switch (ntohl(conf.splen)) {
+ case DPT_EATA_REVA:
+ dpt->EATA_revision = 'a';
+ break;
+ case DPT_EATA_REVB:
+ dpt->EATA_revision = 'b';
+ break;
+ case DPT_EATA_REVC:
+ dpt->EATA_revision = 'c';
+ break;
+ case DPT_EATA_REVZ:
+ dpt->EATA_revision = 'z';
+ break;
+ default:
+ dpt->EATA_revision = '?';
+ }
+
+ dpt->max_id = conf.MAX_ID;
+ dpt->max_lun = conf.MAX_LUN;
+ dpt->irq = conf.IRQ;
+ dpt->dma_channel = (8 - conf.DMA_channel) & 7;
+ dpt->channels = conf.MAX_CHAN + 1;
+ dpt->state |= DPT_HA_OK;
+ if (conf.SECOND)
+ dpt->primary = FALSE;
else
+ dpt->primary = TRUE;
+
+ dpt->more_support = conf.MORE_support;
+
+ if (strncmp(dpt->board_data.firmware, "07G0", 4) >= 0)
+ dpt->immediate_support = 1;
+ else
+ dpt->immediate_support = 0;
+
+ dpt->broken_INQUIRY = FALSE;
+
+ dpt->cplen = ntohl(conf.cplen);
+ dpt->cppadlen = ntohs(conf.cppadlen);
+ dpt->max_dccbs = ntohs(conf.queuesiz);
+
+ dpt->hostid[0] = conf.scsi_id0;
+ dpt->hostid[1] = conf.scsi_id1;
+ dpt->hostid[2] = conf.scsi_id2;
+
+ if (conf.SG_64K) {
+ dpt->sgsize = SG_SIZE_BIG;
+ } else if ((ntohs(conf.SGsiz) < 1)
+ || (ntohs(conf.SGsiz) > SG_SIZE)) {
+ /* Just a sanity check */
+ dpt->sgsize = SG_SIZE;
+ } else {
+ dpt->sgsize = ntohs(conf.SGsiz);
+ }
+
+ if (dpt->sgsize > dpt_max_segs)
+ dpt->sgsize = dpt_max_segs;
+
+ /* DMA tag for mapping buffers into device visible space. */
+ if (bus_dma_tag_create(dpt->parent_dmat, /*alignment*/0, /*boundary*/0,
+ /*lowaddr*/BUS_SPACE_MAXADDR,
+ /*highaddr*/BUS_SPACE_MAXADDR,
+ /*filter*/NULL, /*filterarg*/NULL,
+ /*maxsize*/MAXBSIZE, /*nsegments*/dpt->sgsize,
+ /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+ /*flags*/BUS_DMA_ALLOCNOW,
+ &dpt->buffer_dmat) != 0) {
+ goto error_exit;
+ }
+
+ dpt->init_level++;
+
+ /* DMA tag for our ccb structures and interrupt status packet */
+ if (bus_dma_tag_create(dpt->parent_dmat, /*alignment*/0, /*boundary*/0,
+ /*lowaddr*/BUS_SPACE_MAXADDR,
+ /*highaddr*/BUS_SPACE_MAXADDR,
+ /*filter*/NULL, /*filterarg*/NULL,
+ (dpt->max_dccbs * sizeof(struct dpt_ccb))
+ + sizeof(dpt_sp_t),
+ /*nsegments*/1,
+ /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
+ /*flags*/0, &dpt->dccb_dmat) != 0) {
+ goto error_exit;
+ }
+
+ dpt->init_level++;
+
+ /* Allocation for our ccbs and interrupt status packet */
+ if (bus_dmamem_alloc(dpt->dccb_dmat, (void **)&dpt->dpt_dccbs,
+ BUS_DMA_NOWAIT, &dpt->dccb_dmamap) != 0) {
+ goto error_exit;
+ }
+
+ dpt->init_level++;
+
+ /* And permanently map them */
+ bus_dmamap_load(dpt->dccb_dmat, dpt->dccb_dmamap,
+ dpt->dpt_dccbs,
+ (dpt->max_dccbs * sizeof(struct dpt_ccb))
+ + sizeof(dpt_sp_t),
+ dptmapmem, &dpt->dpt_ccb_busbase, /*flags*/0);
+
+ dpt->dpt_ccb_busend = dpt->dpt_ccb_busbase;
+
+ dpt->sp = (dpt_sp_t*)&dpt->dpt_dccbs[dpt->max_dccbs];
+ dpt->sp_physaddr = dpt->dpt_ccb_busbase
+ + (dpt->max_dccbs * sizeof(dpt_ccb_t));
+ dpt->init_level++;
+
+ /* Allocate our first batch of ccbs */
+ if (dptallocccbs(dpt) == 0)
+ return (2);
+
+ /* Prepare for Target Mode */
+ dpt->target_mode_enabled = 1;
+
+ /* Nuke excess spaces from inquiry information */
+ strp = dpt->board_data.vendor;
+ for (i = 0; i < sizeof(string_sizes); i++) {
+ index = string_sizes[i] - 1;
+ while (index && (strp[index] == ' '))
+ strp[index--] = '\0';
+ strp += string_sizes[i];
+ }
+
+ printf("dpt%d: %.8s %.16s FW Rev. %.4s, ",
+ dpt->unit, dpt->board_data.vendor,
+ dpt->board_data.modelNum, dpt->board_data.firmware);
+
+ printf("%d channel%s, ", dpt->channels, dpt->channels > 1 ? "s" : "");
+
+ if (dpt->cache_type != DPT_NO_CACHE
+ && dpt->cache_size != 0) {
+ printf("%s Cache, ",
+ dpt->cache_type == DPT_CACHE_WRITETHROUGH
+ ? "Write-Through" : "Write-Back");
+ }
+
+ printf("%d CCBs\n", dpt->max_dccbs);
+ return (0);
+
+error_exit:
+ return (1);
+}
+
+int
+dpt_attach(dpt_softc_t *dpt)
+{
+ struct cam_devq *devq;
+ int i;
+
+ /*
+ * Create the device queue for our SIM.
+ */
+ devq = cam_simq_alloc(dpt->max_dccbs);
+ if (devq == NULL)
return (0);
+
+ for (i = 0; i < dpt->channels; i++) {
+ /*
+ * Construct our SIM entry
+ */
+ dpt->sims[i] = cam_sim_alloc(dpt_action, dpt_poll, "dpt",
+ dpt, dpt->unit, /*untagged*/2,
+ /*tagged*/dpt->max_dccbs, devq);
+ if (xpt_bus_register(dpt->sims[i], i) != CAM_SUCCESS) {
+ cam_sim_free(dpt->sims[i], /*free_devq*/i == 0);
+ break;
+ }
+
+ if (xpt_create_path(&dpt->paths[i], /*periph*/NULL,
+ cam_sim_path(dpt->sims[i]),
+ CAM_TARGET_WILDCARD,
+ CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
+ xpt_bus_deregister(cam_sim_path(dpt->sims[i]));
+ cam_sim_free(dpt->sims[i], /*free_devq*/i == 0);
+ break;
+ }
+
+ }
+ if (i > 0)
+ at_shutdown(dptshutdown, dpt, SHUTDOWN_FINAL);
+ return (i);
}
+
+/*
+ * This is the interrupt handler for the DPT driver.
+ */
+void
+dpt_intr(void *arg)
+{
+ dpt_softc_t *dpt;
+ dpt_ccb_t *dccb;
+ union ccb *ccb;
+ u_int status;
+ u_int aux_status;
+ u_int hba_stat;
+ u_int scsi_stat;
+ u_int32_t residue_len; /* Number of bytes not transferred */
+
+ dpt = (dpt_softc_t *)arg;
+
+ /* First order of business is to check if this interrupt is for us */
+ while (((aux_status = dpt_inb(dpt, HA_RAUXSTAT)) & HA_AIRQ) != 0) {
+
+ /*
+ * What we want to do now, is to capture the status, all of it,
+ * move it where it belongs, wake up whoever sleeps waiting to
+ * process this result, and get out of here.
+ */
+ if (dpt->sp->ccb_busaddr < dpt->dpt_ccb_busbase
+ || dpt->sp->ccb_busaddr >= dpt->dpt_ccb_busend) {
+ printf("Encountered bogus status packet\n");
+ status = dpt_inb(dpt, HA_RSTATUS);
+ return;
+ }
+
+ dccb = dptccbptov(dpt, dpt->sp->ccb_busaddr);
+
+ dpt->sp->ccb_busaddr = ~0;
+
+ /* Ignore status packets with EOC not set */
+ if (dpt->sp->EOC == 0) {
+ printf("dpt%d ERROR: Request %d recieved with "
+ "clear EOC.\n Marking as LOST.\n",
+ dpt->unit, dccb->transaction_id);
+
+#ifdef DPT_HANDLE_TIMEOUTS
+ dccb->state |= DPT_CCB_STATE_MARKED_LOST;
+#endif
+ /* This CLEARS the interrupt! */
+ status = dpt_inb(dpt, HA_RSTATUS);
+ continue;
+ }
+ dpt->sp->EOC = 0;
+
+ /*
+ * Double buffer the status information so the hardware can
+ * work on updating the status packet while we decifer the
+ * one we were just interrupted for.
+ * According to Mark Salyzyn, we only need few pieces of it.
+ */
+ hba_stat = dpt->sp->hba_stat;
+ scsi_stat = dpt->sp->scsi_stat;
+ residue_len = dpt->sp->residue_len;
+
+ /* Clear interrupts, check for error */
+ if ((status = dpt_inb(dpt, HA_RSTATUS)) & HA_SERROR) {
+ /*
+ * Error Condition. Check for magic cookie. Exit
+ * this test on earliest sign of non-reset condition
+ */
+
+ /* Check that this is not a board reset interrupt */
+ if (dpt_just_reset(dpt)) {
+ printf("dpt%d: HBA rebooted.\n"
+ " All transactions should be "
+ "resubmitted\n",
+ dpt->unit);
+
+ printf("dpt%d: >>---->> This is incomplete, "
+ "fix me.... <<----<<", dpt->unit);
+ panic("DPT Rebooted");
+
+ }
+ }
+ /* Process CCB */
+ ccb = dccb->ccb;
+ untimeout(dpttimeout, dccb, ccb->ccb_h.timeout_ch);
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
+ bus_dmasync_op_t op;
+
+ if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
+ op = BUS_DMASYNC_POSTREAD;
+ else
+ op = BUS_DMASYNC_POSTWRITE;
+ bus_dmamap_sync(dpt->buffer_dmat, dccb->dmamap, op);
+ bus_dmamap_unload(dpt->buffer_dmat, dccb->dmamap);
+ }
+
+ /* Common Case inline... */
+ if (hba_stat == HA_NO_ERROR) {
+ ccb->csio.scsi_status = scsi_stat;
+ ccb->ccb_h.status = 0;
+ switch (scsi_stat) {
+ case SCSI_STATUS_OK:
+ ccb->ccb_h.status |= CAM_REQ_CMP;
+ break;
+ case SCSI_STATUS_CHECK_COND:
+ case SCSI_STATUS_CMD_TERMINATED:
+ bcopy(&dccb->sense_data, &ccb->csio.sense_data,
+ ccb->csio.sense_len);
+ ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
+ /* FALLTHROUGH */
+ default:
+ ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
+ /* XXX Freeze DevQ */
+ break;
+ }
+ ccb->csio.resid = residue_len;
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+ } else {
+ dptprocesserror(dpt, dccb, ccb, hba_stat, scsi_stat,
+ residue_len);
+ }
+ }
+}
+
+static void
+dptprocesserror(dpt_softc_t *dpt, dpt_ccb_t *dccb, union ccb *ccb,
+ u_int hba_stat, u_int scsi_stat, u_int32_t resid)
+{
+ ccb->csio.resid = resid;
+ switch (hba_stat) {
+ case HA_ERR_SEL_TO:
+ ccb->ccb_h.status = CAM_SEL_TIMEOUT;
+ break;
+ case HA_ERR_CMD_TO:
+ ccb->ccb_h.status = CAM_CMD_TIMEOUT;
+ break;
+ case HA_SCSIBUS_RESET:
+ case HA_HBA_POWER_UP: /* Similar effect to a bus reset??? */
+ ccb->ccb_h.status = CAM_SCSI_BUS_RESET;
+ break;
+ case HA_CP_ABORTED:
+ case HA_CP_RESET: /* XXX ??? */
+ case HA_CP_ABORT_NA: /* XXX ??? */
+ case HA_CP_RESET_NA: /* XXX ??? */
+ ccb->ccb_h.status = CAM_REQ_ABORTED;
+ break;
+ case HA_PCI_PARITY:
+ case HA_PCI_MABORT:
+ case HA_PCI_TABORT:
+ case HA_PCI_STABORT:
+ case HA_BUS_PARITY:
+ case HA_PARITY_ERR:
+ case HA_ECC_ERR:
+ ccb->ccb_h.status = CAM_UNCOR_PARITY;
+ break;
+ case HA_UNX_MSGRJCT:
+ ccb->ccb_h.status = CAM_MSG_REJECT_REC;
+ break;
+ case HA_UNX_BUSPHASE:
+ ccb->ccb_h.status = CAM_SEQUENCE_FAIL;
+ break;
+ case HA_UNX_BUS_FREE:
+ ccb->ccb_h.status = CAM_UNEXP_BUSFREE;
+ break;
+ case HA_SCSI_HUNG:
+ case HA_RESET_STUCK:
+ /*
+ * Dead??? Can the controller get unstuck
+ * from these conditions
+ */
+ ccb->ccb_h.status = CAM_NO_HBA;
+ break;
+ case HA_RSENSE_FAIL:
+ ccb->ccb_h.status = CAM_AUTOSENSE_FAIL;
+ break;
+ default:
+ printf("dpt%d: Undocumented Error %x", dpt->unit, hba_stat);
+ printf("Please mail this message to shimon@i-connect.net\n");
+ ccb->ccb_h.status = CAM_REQ_CMP_ERR;
+ break;
+ }
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+}
+
+static void
+dpttimeout(void *arg)
+{
+ struct dpt_ccb *dccb;
+ union ccb *ccb;
+ struct dpt_softc *dpt;
+ int s;
+
+ dccb = (struct dpt_ccb *)arg;
+ ccb = dccb->ccb;
+ dpt = (struct dpt_softc *)ccb->ccb_h.ccb_dpt_ptr;
+ xpt_print_path(ccb->ccb_h.path);
+ printf("CCB 0x%x - timed out\n", dccb);
+
+ s = splcam();
+
+ if ((dccb->state & DCCB_ACTIVE) == 0) {
+ xpt_print_path(ccb->ccb_h.path);
+ printf("CCB 0x%x - timed out CCB already completed\n", dccb);
+ splx(s);
+ return;
+ }
+
+ /* Do an abort. I have no idea what this really does... */
+ dpt_send_immediate(dpt, &dccb->eata_ccb, dccb->eata_ccb.cp_busaddr,
+ /*retries*/20000, EATA_SPECIFIC_ABORT, 0, 0);
+ ccb->ccb_h.status = CAM_CMD_TIMEOUT;
+ dptfreeccb(dpt, dccb);
+ xpt_done(ccb);
+ splx(s);
+}
+
+/*
+ * Shutdown the controller and ensure that the cache is completely flushed.
+ * Called via at_shutdown(9) after all disk access has completed.
+ */
+static void
+dptshutdown(int howto, void *arg)
+{
+ dpt_softc_t *dpt;
+
+ dpt = (dpt_softc_t *)arg;
+
+ printf("dpt%d: Shutting down (mode %x) HBA. Please wait...\n",
+ dpt->unit, howto);
+
+ /*
+ * What we do for a shutdown, is give the DPT early power loss warning
+ */
+ dpt_send_immediate(dpt, NULL, 0, EATA_POWER_OFF_WARN, 0, 0, 0);
+ DELAY(1000 * 1000 * 5);
+ printf("dpt%d: Controller was warned of shutdown and is now "
+ "disabled\n", dpt->unit);
+}
+
+/*============================================================================*/
+
+#if 0
#ifdef DPT_RESET_HBA
/*
** Function name : dpt_reset_hba
**
** Description : Reset the HBA and properly discard all pending work
-** Input : Minor Device Number
+** Input : Softc
** Output : Nothing
*/
-
static void
dpt_reset_hba(dpt_softc_t *dpt)
{
- eata_ccb_t *ccb;
- int ospl;
- dpt_ccb_t dccb, *dccbp;
- int result;
- struct scsi_xfer *xs;
+ eata_ccb_t *ccb;
+ int ospl;
+ dpt_ccb_t dccb, *dccbp;
+ int result;
+ struct scsi_xfer *xs;
- /* Prepare a control block. The SCSI command part is immaterial */
- dccb.xs = NULL;
- dccb.flags = 0;
- dccb.state = DPT_CCB_STATE_NEW;
- dccb.std_callback = NULL;
- dccb.wrbuff_callback = NULL;
-
- ccb = &dccb.eata_ccb;
- ccb->CP_OpCode = EATA_CMD_RESET;
- ccb->SCSI_Reset = 0;
- ccb->HBA_Init = 1;
- ccb->Auto_Req_Sen = 1;
- ccb->cp_id = 0; /* Should be ignored */
- ccb->DataIn = 1;
- ccb->DataOut = 0;
- ccb->Interpret = 1;
- ccb->reqlen = htonl(sizeof(struct scsi_sense_data));
- ccb->cp_statDMA = htonl(vtophys(&ccb->cp_statDMA));
- ccb->cp_reqDMA = htonl(vtophys(&ccb->cp_reqDMA));
- ccb->cp_viraddr = (u_int32_t) & ccb;
-
- ccb->cp_msg[0] = HA_IDENTIFY_MSG | HA_DISCO_RECO;
- ccb->cp_scsi_cmd = 0; /* Should be ignored */
-
- /* Lock up the submitted queue. We are very persistant here */
- ospl = splcam();
- while (dpt->queue_status & DPT_SUBMITTED_QUEUE_ACTIVE) {
- DELAY(100);
- }
+ /* Prepare a control block. The SCSI command part is immaterial */
+ dccb.xs = NULL;
+ dccb.flags = 0;
+ dccb.state = DPT_CCB_STATE_NEW;
+ dccb.std_callback = NULL;
+ dccb.wrbuff_callback = NULL;
+
+ ccb = &dccb.eata_ccb;
+ ccb->CP_OpCode = EATA_CMD_RESET;
+ ccb->SCSI_Reset = 0;
+ ccb->HBA_Init = 1;
+ ccb->Auto_Req_Sen = 1;
+ ccb->cp_id = 0; /* Should be ignored */
+ ccb->DataIn = 1;
+ ccb->DataOut = 0;
+ ccb->Interpret = 1;
+ ccb->reqlen = htonl(sizeof(struct scsi_sense_data));
+ ccb->cp_statDMA = htonl(vtophys(&ccb->cp_statDMA));
+ ccb->cp_reqDMA = htonl(vtophys(&ccb->cp_reqDMA));
+ ccb->cp_viraddr = (u_int32_t) & ccb;
+
+ ccb->cp_msg[0] = HA_IDENTIFY_MSG | HA_DISCO_RECO;
+ ccb->cp_scsi_cmd = 0; /* Should be ignored */
+
+ /* Lock up the submitted queue. We are very persistant here */
+ ospl = splcam();
+ while (dpt->queue_status & DPT_SUBMITTED_QUEUE_ACTIVE) {
+ DELAY(100);
+ }
- dpt->queue_status |= DPT_SUBMITTED_QUEUE_ACTIVE;
- splx(ospl);
-
- /* Send the RESET message */
- if ((result = dpt_send_eata_command(dpt, &dccb.eata_ccb,
- EATA_CMD_RESET, 0, 0, 0, 0)) != 0) {
- printf("dpt%d: Failed to send the RESET message.\n"
- " Trying cold boot (ouch!)\n", dpt->unit);
+ dpt->queue_status |= DPT_SUBMITTED_QUEUE_ACTIVE;
+ splx(ospl);
+
+ /* Send the RESET message */
+ if ((result = dpt_send_eata_command(dpt, &dccb.eata_ccb,
+ EATA_CMD_RESET, 0, 0, 0, 0)) != 0) {
+ printf("dpt%d: Failed to send the RESET message.\n"
+ " Trying cold boot (ouch!)\n", dpt->unit);
- if ((result = dpt_send_eata_command(dpt, &dccb.eata_ccb,
- EATA_COLD_BOOT, 0, 0, 0, 0))
- != 0) {
- panic("dpt%d: Faild to cold boot the HBA\n", dpt->unit);
- }
+ if ((result = dpt_send_eata_command(dpt, &dccb.eata_ccb,
+ EATA_COLD_BOOT, 0, 0,
+ 0, 0)) != 0) {
+ panic("dpt%d: Faild to cold boot the HBA\n",
+ dpt->unit);
+ }
#ifdef DPT_MEASURE_PERFORMANCE
- dpt->performance.cold_boots++;
+ dpt->performance.cold_boots++;
#endif /* DPT_MEASURE_PERFORMANCE */
- }
+ }
#ifdef DPT_MEASURE_PERFORMANCE
dpt->performance.warm_starts++;
#endif /* DPT_MEASURE_PERFORMANCE */
- printf("dpt%d: Aborting pending requests. O/S should re-submit\n",
- dpt->unit);
+ printf("dpt%d: Aborting pending requests. O/S should re-submit\n",
+ dpt->unit);
- while ((dccbp = TAILQ_FIRST(&dpt->completed_ccbs)) != NULL) {
- struct scsi_xfer *xs = dccbp->xs;
+ while ((dccbp = TAILQ_FIRST(&dpt->completed_ccbs)) != NULL) {
+ struct scsi_xfer *xs = dccbp->xs;
- /* Not all transactions have xs structs */
- if (xs != NULL) {
- /* Tell the kernel proper this did not complete well */
- xs->error |= XS_SELTIMEOUT;
- xs->flags |= SCSI_ITSDONE;
- scsi_done(xs);
- }
+ /* Not all transactions have xs structs */
+ if (xs != NULL) {
+ /* Tell the kernel proper this did not complete well */
+ xs->error |= XS_SELTIMEOUT;
+ xs->flags |= SCSI_ITSDONE;
+ scsi_done(xs);
+ }
- dpt_Qremove_submitted(dpt, dccbp);
+ dpt_Qremove_submitted(dpt, dccbp);
- /* Remember, Callbacks are NOT in the standard queue */
- if (dccbp->std_callback != NULL) {
- (dccbp->std_callback) (dpt, dccbp->eata_ccb.cp_channel, dccbp);
- } else {
- ospl = splcam();
- dpt_Qpush_free(dpt, dccbp);
- splx(ospl);
+ /* Remember, Callbacks are NOT in the standard queue */
+ if (dccbp->std_callback != NULL) {
+ (dccbp->std_callback)(dpt, dccbp->eata_ccb.cp_channel,
+ dccbp);
+ } else {
+ ospl = splcam();
+ dpt_Qpush_free(dpt, dccbp);
+ splx(ospl);
+ }
}
- }
-
- printf("dpt%d: reset done aborting all pending commands\n", dpt->unit);
- dpt->queue_status &= ~DPT_SUBMITTED_QUEUE_ACTIVE;
+
+ printf("dpt%d: reset done aborting all pending commands\n", dpt->unit);
+ dpt->queue_status &= ~DPT_SUBMITTED_QUEUE_ACTIVE;
}
#endif /* DPT_RESET_HBA */
-/**
+/*
* Build a Command Block for target mode READ/WRITE BUFFER,
* with the ``sync'' bit ON.
*
* Although the length and offset are 24 bit fields in the command, they cannot
* exceed 8192 bytes, so we take them as short integers andcheck their range.
- * If they are sensless, we round them to zero offset, maximum length and complain.
+ * If they are sensless, we round them to zero offset, maximum length and
+ * complain.
*/
static void
@@ -540,14 +1813,14 @@ dpt_target_ccb(dpt_softc_t * dpt, int bus, u_int8_t target, u_int8_t lun,
cp->cp_cdb[8] = length & 0xFF; /* Length LSB */
cp->cp_cdb[9] = 0; /* No sync, no match bits */
- /**
+ /*
* This could be optimized to live in dpt_register_buffer.
- * We keep it here, just in case the kernel decides to reallocate pages
+ * We keep it here, just in case the kernel decides to reallocate pages
*/
if (dpt_scatter_gather(dpt, ccb, DPT_RW_BUFFER_SIZE,
dpt->rw_buffer[bus][target][lun])) {
- printf("dpt%d: Failed to setup Scatter/Gather for Target-Mode buffer\n",
- dpt->unit);
+ printf("dpt%d: Failed to setup Scatter/Gather for "
+ "Target-Mode buffer\n", dpt->unit);
}
}
@@ -558,7 +1831,7 @@ dpt_set_target(int redo, dpt_softc_t * dpt,
u_int8_t bus, u_int8_t target, u_int8_t lun, int mode,
u_int16_t length, u_int16_t offset, dpt_ccb_t * ccb)
{
- int ospl;
+ int ospl;
if (dpt->target_mode_enabled) {
ospl = splcam();
@@ -583,7 +1856,7 @@ dpt_set_target(int redo, dpt_softc_t * dpt,
}
}
-/**
+/*
* Schedule a buffer to be sent to another target.
* The work will be scheduled and the callback provided will be called when
* the work is actually done.
@@ -593,14 +1866,8 @@ dpt_set_target(int redo, dpt_softc_t * dpt,
*/
int
-dpt_send_buffer(int unit,
- u_int8_t channel,
- u_int8_t target,
- u_int8_t lun,
- u_int8_t mode,
- u_int16_t length,
- u_int16_t offset,
- void *data,
+dpt_send_buffer(int unit, u_int8_t channel, u_int8_t target, u_int8_t lun,
+ u_int8_t mode, u_int16_t length, u_int16_t offset, void *data,
buff_wr_done callback)
{
dpt_softc_t *dpt;
@@ -727,26 +1994,18 @@ dpt_target_done(dpt_softc_t * dpt, int bus, dpt_ccb_t * ccb)
dpt->target_ccb[br_channel][br_target][br_lun] = NULL;
dpt_Qpush_free(dpt, ccb);
splx(ospl);
-
}
-/**
+/*
* Use this function to register a client for a buffer read target operation.
* The function you register will be called every time a buffer is received
* by the target mode code.
*/
-
dpt_rb_t
-dpt_register_buffer(int unit,
- u_int8_t channel,
- u_int8_t target,
- u_int8_t lun,
- u_int8_t mode,
- u_int16_t length,
- u_int16_t offset,
- dpt_rec_buff callback,
- dpt_rb_op_t op)
+dpt_register_buffer(int unit, u_int8_t channel, u_int8_t target, u_int8_t lun,
+ u_int8_t mode, u_int16_t length, u_int16_t offset,
+ dpt_rec_buff callback, dpt_rb_op_t op)
{
dpt_softc_t *dpt;
dpt_ccb_t *ccb = NULL;
@@ -788,7 +2047,8 @@ valid_unit:
/* Now grab the newest CCB */
if ((ccb = dpt_Qpop_free(dpt)) == NULL) {
splx(ospl);
- panic("dpt%d: Got a NULL CCB from pop_free()\n", dpt->unit);
+ panic("dpt%d: Got a NULL CCB from pop_free()\n",
+ dpt->unit);
}
splx(ospl);
@@ -796,18 +2056,18 @@ valid_unit:
ccb->status = DPT_CCB_STATE_NEW;
dpt->target_ccb[channel][target][lun] = ccb;
- dpt->rw_buffer[channel][target][lun] = malloc(DPT_RW_BUFFER_SIZE,
- M_DEVBUF, M_NOWAIT);
+ dpt->rw_buffer[channel][target][lun] =
+ malloc(DPT_RW_BUFFER_SIZE, M_DEVBUF, M_NOWAIT);
if (dpt->rw_buffer[channel][target][lun] == NULL) {
- printf("dpt%d: Failed to allocate Target-Mode buffer\n",
- dpt->unit);
+ printf("dpt%d: Failed to allocate "
+ "Target-Mode buffer\n", dpt->unit);
ospl = splsoftcam();
dpt_Qpush_free(dpt, ccb);
splx(ospl);
return (NO_RESOURCES);
}
- dpt_set_target(0, dpt, channel, target, lun, mode, length,
- offset, ccb);
+ dpt_set_target(0, dpt, channel, target, lun, mode,
+ length, offset, ccb);
return (SUCCESSFULLY_REGISTERED);
} else
return (NOT_REGISTERED);
@@ -832,103 +2092,6 @@ valid_unit:
}
}
-/**
- * This routine will try to send an EATA command to the DPT HBA.
- * It will, by default, try AHZ times, waiting 10ms between tries.
- * It returns 0 on success and 1 on failure.
- * It assumes the caller protects it with splbio() or some such.
- *
- * IMPORTANT: We do NOT protect the ports from multiple access in here.
- * You are expected to do it in the calling routine.
- * Here, we cannot have any clue as to the scope of your work.
- */
-
-static int
-dpt_send_eata_command(dpt_softc_t * dpt, eata_ccb_t * cmd_block,
- u_int8_t command, int32_t retries,
- u_int8_t ifc, u_int8_t code, u_int8_t code2)
-{
- int32_t loop;
- u_int8_t result;
- u_int32_t test;
- u_int32_t swapped_cmdaddr;
-
- if (!retries)
- retries = 10000;
-
- /*
- * I hate this polling nonsense. Wish there was a way to tell the DPT
- * to go get commands at its own pace, or to interrupt when ready.
- * In the mean time we will measure how many itterations it really
- * takes.
- */
- for (loop = 0; loop < retries; loop++) {
- if ((dpt_inb(dpt, HA_RAUXSTAT) & HA_ABUSY) == 0)
- break;
- else
- DELAY(50);
- }
-
- if (loop < retries) {
-#ifdef DPT_MEASURE_PERFORMANCE
- if (loop > dpt->performance.max_eata_tries)
- dpt->performance.max_eata_tries = loop;
-
- if (loop < dpt->performance.min_eata_tries)
- dpt->performance.min_eata_tries = loop;
-#endif
- } else {
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.command_too_busy;
-#endif
- return (1);
- }
-
- /* The controller is alive, advance the wedge timer */
-#ifdef DPT_RESET_HBA
- dpt->last_contact = microtime_now;
-#endif
-
- if (cmd_block != NULL) {
- swapped_cmdaddr = vtophys(cmd_block);
-
-#if (BYTE_ORDER == BIG_ENDIAN)
- swapped_cmdaddr = ((swapped_cmdaddr >> 24) & 0xFF)
- | ((swapped_cmdaddr >> 16) & 0xFF)
- | ((swapped_cmdaddr >> 8) & 0xFF)
- | (swapped_cmdaddr & 0xFF);
-#endif
- } else {
- swapped_cmdaddr = 0;
- }
- /* And now the address */
- dpt_outl(dpt, HA_WDMAADDR, swapped_cmdaddr);
-
- if (command == EATA_CMD_IMMEDIATE) {
- if (cmd_block == NULL) {
- dpt_outb(dpt, HA_WCODE2, code2);
- dpt_outb(dpt, HA_WCODE, code);
- }
- dpt_outb(dpt, HA_WIFC, ifc);
- }
- dpt_outb(dpt, HA_WCOMMAND, command);
-
- return (0);
-}
-
-/**
- * Send a command for immediate execution by the DPT
- * See above function for IMPORTANT notes.
- */
-
-static INLINE int
-dpt_send_immediate(dpt_softc_t * dpt, eata_ccb_t * cmd_block,
- u_int8_t ifc, u_int8_t code, u_int8_t code2)
-{
- return (dpt_send_eata_command(dpt, cmd_block, EATA_CMD_IMMEDIATE,
- /* retries */ 1000000, ifc, code, code2));
-}
-
/* Return the state of the blinking DPT LED's */
u_int8_t
dpt_blinking_led(dpt_softc_t * dpt)
@@ -957,23 +2120,22 @@ dpt_blinking_led(dpt_softc_t * dpt)
return (result);
}
-/**
+/*
* Execute a command which did not come from the kernel's SCSI layer.
* The only way to map user commands to bus and target is to comply with the
* standard DPT wire-down scheme:
*/
-
int
dpt_user_cmd(dpt_softc_t * dpt, eata_pt_t * user_cmd,
caddr_t cmdarg, int minor_no)
{
- int channel, target, lun;
- int huh;
- int result;
- int ospl;
- int submitted;
- dpt_ccb_t *ccb;
- void *data;
+ dpt_ccb_t *ccb;
+ void *data;
+ int channel, target, lun;
+ int huh;
+ int result;
+ int ospl;
+ int submitted;
data = NULL;
channel = minor2hba(minor_no);
@@ -981,16 +2143,16 @@ dpt_user_cmd(dpt_softc_t * dpt, eata_pt_t * user_cmd,
lun = minor2lun(minor_no);
if ((channel > (dpt->channels - 1))
- || (target > dpt->max_id)
- || (lun > dpt->max_lun))
+ || (target > dpt->max_id)
+ || (lun > dpt->max_lun))
return (ENXIO);
if (target == dpt->sc_scsi_link[channel].adapter_targ) {
/* This one is for the controller itself */
if ((user_cmd->eataID[0] != 'E')
- || (user_cmd->eataID[1] != 'A')
- || (user_cmd->eataID[2] != 'T')
- || (user_cmd->eataID[3] != 'A')) {
+ || (user_cmd->eataID[1] != 'A')
+ || (user_cmd->eataID[2] != 'T')
+ || (user_cmd->eataID[3] != 'A')) {
return (ENXIO);
}
}
@@ -1194,1845 +2356,6 @@ dpt_user_cmd_done(dpt_softc_t * dpt, int bus, dpt_ccb_t * ccb)
return;
}
-/* Detect Cache parameters and size */
-
-void
-dpt_detect_cache(dpt_softc_t * dpt)
-{
- int size;
- int bytes;
- int result;
- int ospl;
- int ndx;
- u_int8_t status;
- char name[64];
- char *param;
- char *buff;
- eata_ccb_t cp;
-
- dpt_sp_t sp;
- struct scsi_sense_data snp;
-
- /**
- * We lock out the hardware early, so that we can either complete the
- * operation or bust out right away.
- */
-
- sprintf(name, "FreeBSD DPT Driver, version %d.%d.%d",
- DPT_RELEASE, DPT_VERSION, DPT_PATCH);
-
- /**
- * Default setting, for best perfromance..
- * This is what virtually all cards default to..
- */
- dpt->cache_type = DPT_CACHE_WRITEBACK;
- dpt->cache_size = 0;
-
- if ((buff = malloc(512, M_DEVBUF, M_NOWAIT)) == NULL) {
- printf("dpt%d: Failed to allocate %d bytes for a work "
- "buffer\n",
- dpt->unit, 512);
- return;
- }
- bzero(&cp, sizeof(eata_ccb_t));
- bzero((int8_t *) & sp, sizeof(dpt_sp_t));
- bzero((int8_t *) & snp, sizeof(struct scsi_sense_data));
- bzero(buff, 512);
-
- /* Setup the command structure */
- cp.Interpret = 1;
- cp.DataIn = 1;
- cp.Auto_Req_Sen = 1;
- cp.reqlen = (u_int8_t) sizeof(struct scsi_sense_data);
-
- cp.cp_id = 0; /* who cares? The HBA will interpret.. */
- cp.cp_LUN = 0; /* In the EATA packet */
- cp.cp_lun = 0; /* In the SCSI command */
- cp.cp_channel = 0;
-
- cp.cp_scsi_cmd = EATA_CMD_DMA_SEND_CP;
- cp.cp_len = 56;
- cp.cp_dataDMA = htonl(vtophys(buff));
- cp.cp_statDMA = htonl(vtophys(&sp));
- cp.cp_reqDMA = htonl(vtophys(&snp));
-
- cp.cp_identify = 1;
- cp.cp_dispri = 1;
-
- /**
- * Build the EATA Command Packet structure
- * for a Log Sense Command.
- */
-
- cp.cp_cdb[0] = 0x4d;
- cp.cp_cdb[1] = 0x0;
- cp.cp_cdb[2] = 0x40 | 0x33;
- cp.cp_cdb[7] = 1;
-
- cp.cp_datalen = htonl(512);
-
- ospl = splcam();
- result = dpt_send_eata_command(dpt, &cp, EATA_CMD_DMA_SEND_CP,
- 10000, 0, 0, 0);
- if (result != 0) {
- printf("dpt%d WARNING: detect_cache() failed (%d) to send "
- "EATA_CMD_DMA_SEND_CP\n", dpt->unit, result);
- free(buff, M_TEMP);
- splx(ospl);
- return;
- }
- /* Wait for two seconds for a response. This can be slow... */
- for (ndx = 0;
- (ndx < 20000) &&
- !((status = dpt_inb(dpt, HA_RAUXSTAT)) & HA_AIRQ);
- ndx++) {
- DELAY(50);
- }
-
- /* Grab the status and clear interrupts */
- status = dpt_inb(dpt, HA_RSTATUS);
- splx(ospl);
-
- /**
- * Sanity check
- */
- if (buff[0] != 0x33) {
- return;
- }
- bytes = DPT_HCP_LENGTH(buff);
- param = DPT_HCP_FIRST(buff);
-
- if (DPT_HCP_CODE(param) != 1) {
- /**
- * DPT Log Page layout error
- */
- printf("dpt%d: NOTICE: Log Page (1) layout error\n",
- dpt->unit);
- return;
- }
- if (!(param[4] & 0x4)) {
- dpt->cache_type = DPT_NO_CACHE;
- return;
- }
- while (DPT_HCP_CODE(param) != 6) {
- param = DPT_HCP_NEXT(param);
- if ((param < buff)
- || (param >= &buff[bytes])) {
- return;
- }
- }
-
- if (param[4] & 0x2) {
- /**
- * Cache disabled
- */
- dpt->cache_type = DPT_NO_CACHE;
- return;
- }
- if (param[4] & 0x4) {
- dpt->cache_type = DPT_CACHE_WRITETHROUGH;
- return;
- }
- dpt->cache_size = param[5]
- | (param[6] < 8)
- | (param[7] << 16)
- | (param[8] << 24);
-
- return;
-}
-
-/**
- * Initializes the softc structure and allocate all sorts of storage.
- * Returns 0 on good luck, 1-n otherwise (error condition sensitive).
- */
-
-int
-dpt_setup(dpt_softc_t * dpt, dpt_conf_t * conf)
-{
- dpt_inq_t *board_data;
- u_long rev;
- int ndx;
- int ospl;
- dpt_ccb_t *ccb;
-
- board_data = dpt_get_board_data(dpt, conf->scsi_id0);
- if (board_data == NULL) {
- printf("dpt%d ERROR: Get_board_data() failure. "
- "Setup ignored!\n", dpt->unit);
- return (1);
- }
- dpt->total_ccbs_count = 0;
- dpt->free_ccbs_count = 0;
- dpt->waiting_ccbs_count = 0;
- dpt->submitted_ccbs_count = 0;
- dpt->completed_ccbs_count = 0;
-
- switch (ntohl(conf->splen)) {
- case DPT_EATA_REVA:
- dpt->EATA_revision = 'a';
- break;
- case DPT_EATA_REVB:
- dpt->EATA_revision = 'b';
- break;
- case DPT_EATA_REVC:
- dpt->EATA_revision = 'c';
- break;
- case DPT_EATA_REVZ:
- dpt->EATA_revision = 'z';
- break;
- default:
- dpt->EATA_revision = '?';
- }
-
- (void) memcpy(&dpt->board_data, board_data, sizeof(dpt_inq_t));
-
- dpt->bustype = IS_PCI; /* We only support and operate on PCI devices */
- dpt->channels = conf->MAX_CHAN + 1;
- dpt->max_id = conf->MAX_ID;
- dpt->max_lun = conf->MAX_LUN;
- dpt->state |= DPT_HA_OK;
-
- if (conf->SECOND)
- dpt->primary = FALSE;
- else
- dpt->primary = TRUE;
-
- dpt->more_support = conf->MORE_support;
-
- if (board_data == NULL) {
- rev = ('?' << 24)
- | ('-' << 16)
- | ('?' << 8)
- | '-';
- } else {
- /* Convert from network byte order to a "string" */
- rev = (dpt->board_data.firmware[0] << 24)
- | (dpt->board_data.firmware[1] << 16)
- | (dpt->board_data.firmware[2] << 8)
- | dpt->board_data.firmware[3];
- }
-
- if (rev >= (('0' << 24) + ('7' << 16) + ('G' << 8) + '0'))
- dpt->immediate_support = 1;
- else
- dpt->immediate_support = 0;
-
- dpt->broken_INQUIRY = FALSE;
-
- for (ndx = 0; ndx < MAX_CHANNELS; ndx++)
- dpt->resetlevel[ndx] = DPT_HA_OK;
-
- dpt->cplen = ntohl(conf->cplen);
- dpt->cppadlen = ntohs(conf->cppadlen);
- dpt->queuesize = ntohs(conf->queuesiz);
-
- dpt->hostid[0] = conf->scsi_id0;
- dpt->hostid[1] = conf->scsi_id1;
- dpt->hostid[2] = conf->scsi_id2;
-
- if (conf->SG_64K) {
- dpt->sgsize = SG_SIZE_BIG;
- } else if ((ntohs(conf->SGsiz) < 1)
- || (ntohs(conf->SGsiz) > SG_SIZE)) {
- /* Just a sanity check */
- dpt->sgsize = SG_SIZE;
- } else {
- dpt->sgsize = ntohs(conf->SGsiz);
- }
-
- if (dpt->sgsize > dpt_max_segs)
- dpt->sgsize = dpt_max_segs;
-
- if (dpt_alloc_freelist(dpt) != 0) {
- return (2);
- }
- /* Prepare for Target Mode */
- ospl = splsoftcam();
- dpt->target_mode_enabled = 1;
- splx(ospl);
-
- return (0);
-}
-
-/**
- * The following function returns a pointer to a buffer which MUST be freed by
- * The caller, a la free(result, M_DEVBUF)
- *
- * This function (and its like) assumes it is only running during system
- * initialization!
- */
-static dpt_inq_t *
-dpt_get_board_data(dpt_softc_t * dpt, u_int32_t target_id)
-{
- /* get_conf returns 512 bytes, most of which are zeros... */
- return ((dpt_inq_t *) dpt_get_conf(dpt, 0, target_id,
- sizeof(dpt_inq_t), 0));
-}
-
-/**
- * The following function returns a pointer to a buffer which MUST be freed by
- * the caller, a la ``free(result, M_TEMP);''
- */
-dpt_conf_t *
-dpt_get_conf(dpt_softc_t * dpt, u_int8_t page, u_int8_t target,
- u_int8_t size, int extent)
-{
- dpt_sp_t sp;
- eata_ccb_t cp;
-
- /* Get_conf returns 512 bytes, most of which are zeros... */
- dpt_conf_t *config;
-
- u_short *ip;
- u_int8_t status, sig1, sig2, sig3;
-
- int ndx;
- int ospl;
- int result;
-
- struct scsi_sense_data snp;
- if ((config = (dpt_conf_t *) malloc(512, M_TEMP, M_WAITOK)) == NULL)
- return (NULL);
-
- bzero(&cp, sizeof(eata_ccb_t));
- bzero((int8_t *) & sp, sizeof(dpt_sp_t));
- bzero(config, size);
-
- cp.Interpret = 1;
- cp.DataIn = 1;
- cp.Auto_Req_Sen = 1;
- cp.reqlen = sizeof(struct scsi_sense_data);
-
- cp.cp_id = target;
- cp.cp_LUN = 0; /* In the EATA packet */
- cp.cp_lun = 0; /* In the SCSI command */
-
- cp.cp_scsi_cmd = INQUIRY;
- cp.cp_len = size;
-
- cp.cp_extent = extent;
-
- cp.cp_page = page;
- cp.cp_channel = 0; /* DNC, Interpret mode is set */
- cp.cp_identify = 1;
- cp.cp_datalen = htonl(size);
- cp.cp_dataDMA = htonl(vtophys(config));
- cp.cp_statDMA = htonl(vtophys(&sp));
- cp.cp_reqDMA = htonl(vtophys(&snp));
- cp.cp_viraddr = (u_int32_t) & cp;
-
- ospl = splcam();
-
-#ifdef DPT_RESET_BOARD
- printf("dpt%d: get_conf() resetting HBA at %x.\n",
- dpt->unit, BaseRegister(dpt));
- dpt_outb(dpt, HA_WCOMMAND, EATA_CMD_RESET);
- DELAY(750000);
-#endif
-
- /**
- * This could be a simple for loop, but we suspected the compiler To
- * have optimized it a bit too much. Wait for the controller to
- * become ready
- */
- while ((((status = dpt_inb(dpt, HA_RSTATUS)) != (HA_SREADY | HA_SSC))
- && (status != (HA_SREADY | HA_SSC | HA_SERROR))
- && /* This results from the `wd' probe at our
- * addresses */
- (status != (HA_SDRDY | HA_SERROR | HA_SDRQ)))
- || (dpt_wait(dpt, HA_SBUSY, 0))) {
- /**
- * RAID Drives still Spinning up? (This should only occur if
- * the DPT controller is in a NON PC (PCI?) platform).
- */
- if (dpt_raid_busy(dpt)) {
- printf("dpt%d WARNING: Get_conf() RSUS failed for "
- "HBA at %x\n", dpt->unit, BaseRegister(dpt));
- free(config, M_TEMP);
- splx(ospl);
- return (NULL);
- }
- }
-
- DptStat_Reset_BUSY(&sp);
-
- /**
- * XXXX We might want to do something more clever than aborting at
- * this point, like resetting (rebooting) the controller and trying
- * again.
- */
- if ((result = dpt_send_eata_command(dpt, &cp, EATA_CMD_DMA_SEND_CP,
- 10000, 0, 0, 0)) != 0) {
- printf("dpt%d WARNING: Get_conf() failed (%d) to send "
- "EATA_CMD_DMA_READ_CONFIG\n",
- dpt->unit, result);
- free(config, M_TEMP);
- splx(ospl);
- return (NULL);
- }
- /* Wait for two seconds for a response. This can be slow */
- for (ndx = 0;
- (ndx < 20000)
- && !((status = dpt_inb(dpt, HA_RAUXSTAT)) & HA_AIRQ);
- ndx++) {
- DELAY(50);
- }
-
- /* Grab the status and clear interrupts */
- status = dpt_inb(dpt, HA_RSTATUS);
-
- splx(ospl);
-
- /**
- * Check the status carefully. Return only if the
- * command was successful.
- */
- if (((status & HA_SERROR) == 0)
- && (sp.hba_stat == 0)
- && (sp.scsi_stat == 0)
- && (sp.residue_len == 0)) {
- return (config);
- }
- free(config, M_TEMP);
- return (NULL);
-}
-
-/* This gets called once per SCSI bus defined in config! */
-
-int
-dpt_attach(dpt_softc_t * dpt)
-{
- struct scsibus_data *scbus;
-
- int ndx;
- int idx;
- int channel;
- int target;
- int lun;
-
- struct scsi_inquiry_data *inq;
-
- for (ndx = 0; ndx < dpt->channels; ndx++) {
- /**
- * We do not setup target nor lun on the assumption that
- * these are being set for individual devices that will be
- * attached to the bus later.
- */
- dpt->sc_scsi_link[ndx].adapter_unit = dpt->unit;
- dpt->sc_scsi_link[ndx].adapter_targ = dpt->hostid[ndx];
- dpt->sc_scsi_link[ndx].fordriver = 0;
- dpt->sc_scsi_link[ndx].adapter_softc = dpt;
- dpt->sc_scsi_link[ndx].adapter = &dpt_switch;
-
- /*
- * These appear to be the # of openings per that DEVICE, not
- * the DPT!
- */
- dpt->sc_scsi_link[ndx].opennings = dpt->queuesize;
- dpt->sc_scsi_link[ndx].device = &dpt_dev;
- dpt->sc_scsi_link[ndx].adapter_bus = ndx;
-
- /**
- * Prepare the scsibus_data area for the upperlevel scsi
- * code.
- */
- if ((scbus = scsi_alloc_bus()) == NULL)
- return 0;
-
- dpt->sc_scsi_link[ndx].scsibus = ndx;
- scbus->maxtarg = dpt->max_id;
- scbus->adapter_link = &dpt->sc_scsi_link[ndx];
-
- /*
- * Invite the SCSI control layer to probe the busses.
- */
-
- dpt->handle_interrupts = 1; /* Now we are ready to work */
- scsi_attachdevs(scbus);
- scbus = (struct scsibus_data *) NULL;
- }
-
- return (1);
-}
-
-/**
- * Allocate another chunk of CCB's. Return 0 on success, 1 otherwise.
- * If the free list is empty, we allocate a block of entries and add them
- * to the list. We obtain, at most, DPT_FREE_LIST_INCREMENT CCB's at a time.
- * If we cannot, we will try fewer entries until we succeed.
- * For every CCB, we allocate a maximal Scatter/Gather list.
- * This routine also initializes all the static data that pertains to this CCB.
- */
-
-/**
- * XXX JGibbs - How big are your SG lists? Remeber that the kernel malloc
- * uses buckets and mallocs in powers of two. So, if your
- * SG list is not a power of two (up to PAGESIZE), you might
- * waste a lot of memory. This was the reason the ahc driver
- * allocats multiple SG lists at a time up to a PAGESIZE.
- * Just something to keep in mind.
- * YYY Simon - Up to 8192 entries, each entry is two ulongs, comes to 64K.
- * In reality they are much smaller, so you are right.
- */
-static int
-dpt_alloc_freelist(dpt_softc_t * dpt)
-{
- dpt_ccb_t *nccbp;
- dpt_sg_t *sg;
- u_int8_t *buff;
- int ospl;
- int incr;
- int ndx;
- int ccb_count;
-
- ccb_count = DPT_FREE_LIST_INCREMENT;
-
-#ifdef DPT_RESTRICTED_FREELIST
- if (dpt->total_ccbs_count != 0) {
- printf("dpt%d: Restricted FreeList, No more than %d entries "
- "allowed\n", dpt->unit, dpt->total_ccbs_count);
- return (-1);
- }
-#endif
-
- /**
- * Allocate a group of dpt_ccb's. Work on the CCB's, one at a time
- */
- ospl = splsoftcam();
- for (ndx = 0; ndx < ccb_count; ndx++) {
- size_t alloc_size;
- dpt_sg_t *sgbuff;
-
- alloc_size = sizeof(dpt_ccb_t); /* About 200 bytes */
-
- if (alloc_size > PAGE_SIZE) {
- /*
- * Does not fit in a page. we try to fit in a
- * contigious block of memory. If not, we will, later
- * try to allocate smaller, and smaller chunks. There
- * is a tradeof between memory and performance here.
- * We know.this (crude) algorithm works well on
- * machines with plenty of memory. We have seen it
- * allocate in excess of 8MB.
- */
- nccbp = (dpt_ccb_t *) contigmalloc(alloc_size,
- M_DEVBUF, M_NOWAIT,
- 0, ~0,
- PAGE_SIZE,
- 0x10000);
- } else {
- /* fits all in one page */
- nccbp = (dpt_ccb_t *) malloc(alloc_size, M_DEVBUF,
- M_NOWAIT);
- }
-
- if (nccbp == (dpt_ccb_t *) NULL) {
- printf("dpt%d ERROR: Alloc_free_list() failed to "
- "allocate %d\n",
- dpt->unit, ndx);
- splx(ospl);
- return (-1);
- }
- alloc_size = sizeof(dpt_sg_t) * dpt->sgsize;
-
- if (alloc_size > PAGE_SIZE) {
- /* Does not fit in a page */
- sgbuff = (dpt_sg_t *) contigmalloc(alloc_size,
- M_DEVBUF, M_NOWAIT,
- 0, ~0,
- PAGE_SIZE,
- 0x10000);
- } else {
- /* fits all in one page */
- sgbuff = (dpt_sg_t *) malloc(alloc_size, M_DEVBUF,
- M_NOWAIT);
- }
-
- /**
- * If we cannot allocate sg lists, we do not want the entire
- * list
- */
- if (sgbuff == (dpt_sg_t *) NULL) {
- free(nccbp, M_DEVBUF);
- --ndx;
- break;
- }
- /* Clean up the mailboxes */
- bzero(sgbuff, alloc_size);
- bzero(nccbp, sizeof(dpt_ccb_t));
- /*
- * this line is nullified by the one below.
- * nccbp->eata_ccb.cp_dataDMA = (u_int32_t) sgbuff; Thanx,
- * Mike!
- */
- nccbp->sg_list = sgbuff;
-
- /**
- * Now that we have a new block of free CCB's, put them into
- * the free list. We always add to the head of the list and
- * always take form the head of the list (LIFO). Each ccb
- * has its own Scatter/Gather list. They are all of the same
- * size, Regardless of how much is used.
- *
- * While looping through all the new CCB's, we initialize them
- * properly. These items NEVER change; They are mostly
- * self-pointers, relative to the CCB itself.
- */
- dpt_Qpush_free(dpt, nccbp);
- ++dpt->total_ccbs_count;
-
- nccbp->eata_ccb.cp_dataDMA = htonl(vtophys(nccbp->sg_list));
- nccbp->eata_ccb.cp_viraddr = (u_int32_t) nccbp; /* Unique */
- nccbp->eata_ccb.cp_statDMA = htonl(vtophys(&dpt->sp));
-
- /**
- * See dpt_intr for why we make ALL CCB's ``have the same''
- * Status Packet
- */
- nccbp->eata_ccb.cp_reqDMA = htonl(vtophys(&nccbp->sense_data));
- }
-
- splx(ospl);
-
- return (0);
-}
-
-/**
- * Prepare the data area for DMA.
- */
-static int
-dpt_scatter_gather(dpt_softc_t * dpt, dpt_ccb_t * ccb, u_int32_t data_length,
- caddr_t data)
-{
- int seg;
- int thiskv;
- int bytes_this_seg;
- int bytes_this_page;
- u_int32_t datalen;
- vm_offset_t vaddr;
- u_int32_t paddr;
- u_int32_t nextpaddr;
- dpt_sg_t *sg;
-
- /* we start with Scatter/Gather OFF */
- ccb->eata_ccb.scatter = 0;
-
- if (data_length) {
- if (ccb->flags & SCSI_DATA_IN) {
- ccb->eata_ccb.DataIn = 1;
- }
- if (ccb->flags & SCSI_DATA_OUT) {
- ccb->eata_ccb.DataOut = 1;
- }
- seg = 0;
- datalen = data_length;
- vaddr = (vm_offset_t) data;
- paddr = vtophys(vaddr);
- ccb->eata_ccb.cp_dataDMA = htonl(vtophys(ccb->sg_list));
- sg = ccb->sg_list;
-
- while ((datalen > 0) && (seg < dpt->sgsize)) {
- /* put in the base address and length */
- sg->seg_addr = paddr;
- sg->seg_len = 0;
-
- /* do it at least once */
- nextpaddr = paddr;
-
- while ((datalen > 0) && (paddr == nextpaddr)) {
- u_int32_t size;
-
- /**
- * This page is contiguous (physically) with
- * the the last, just extend the length
- */
-
- /* how far to the end of the page */
- nextpaddr = trunc_page(paddr) + PAGE_SIZE;
-
- /* Compute the maximum size */
-
- size = nextpaddr - paddr;
- if (size > datalen)
- size = datalen;
-
- sg->seg_len += size;
- vaddr += size;
- datalen -= size;
- if (datalen > 0)
- paddr = vtophys(vaddr);
- }
-
- /* Next page isn't contiguous, finish the seg */
- sg->seg_addr = htonl(sg->seg_addr);
- sg->seg_len = htonl(sg->seg_len);
- seg++;
- sg++;
- }
-
- if (datalen) {
- /* There's still data, must have run out of segs! */
- printf("dpt%d: scsi_cmd() Too Many (%d) DMA segs "
- "(%d bytes left)\n",
- dpt->unit, dpt->sgsize, datalen);
- return (1);
- }
- if (seg == 1) {
- /**
- * After going through all this trouble, we
- * still have only one segment. As an
- * optimization measure, we will do the
- * I/O as a single, non-S/G operation.
- */
- ccb->eata_ccb.cp_dataDMA = ccb->sg_list[0].seg_addr;
- ccb->eata_ccb.cp_datalen = ccb->sg_list[0].seg_len;
- } else {
- /**
- * There is more than one segment. Use S/G.
- */
- ccb->eata_ccb.scatter = 1;
- ccb->eata_ccb.cp_datalen =
- htonl(seg * sizeof(dpt_sg_t));
- }
- } else { /* datalen == 0 */
- /* No data xfer */
- ccb->eata_ccb.cp_datalen = 0;
- ccb->eata_ccb.cp_dataDMA = 0;
- }
-
- return (0);
-}
-
-/**
- * This function obtains a CCB for a command and attempts to queue it to the
- * Controller.
- *
- * CCB Obtaining: Is done by getting the first entry in the free list for the
- * HBA. If we fail to get an scb, we send a TRY_LATER to the caller.
- *
- * XXX - JGibbs: XS_DRIVER_STUFFUP is equivalent to failing the I/O in the
- * current SCSI layer.
- *
- * Command Queuing: Is done by putting the command at the end of the waiting
- * queue. This assures fair chance for all commands to be processed.
- * If the queue was empty (has only this, current command in it, we try to
- * submit it to the HBA. Otherwise we return SUCCESSFULLY_QUEUED.
- */
-
-static int32_t
-dpt_scsi_cmd(struct scsi_xfer * xs)
-{
- dpt_softc_t *dpt;
- int incr;
- int ndx;
- int ospl;
- int huh;
-
- u_int32_t flags;
- dpt_ccb_t *ccb;
- u_int8_t status;
- u_int32_t aux_status = 0; /* Initialized to shut GCC up */
- int result;
-
- int channel, target, lun;
-
- struct scsi_inquiry_data *inq;
-
- dpt = (dpt_softc_t *) xs->sc_link->adapter_softc;
-
- flags = xs->flags;
- channel = xs->sc_link->adapter_bus;
- target = xs->sc_link->target;
- lun = xs->sc_link->lun;
-
-#ifdef DPT_HANDLE_TIMEOUTS
- ospl = splsoftcam();
- if ((dpt->state & DPT_HA_TIMEOUTS_SET) == 0) {
- dpt->state |= DPT_HA_TIMEOUTS_SET;
- timeout(dpt_timeout, dpt, hz * 10);
- }
- splx(ospl);
-#endif
-
-#ifdef DPT_LOST_IRQ
- ospl = splcam();
- if ((dpt->state & DPT_LOST_IRQ_SET) == 0) {
- printf("dpt%d: Initializing Lost IRQ Timer\n", dpt->unit);
-#ifdef DPT_RESET_HBA
- printf("dpt%d: HBA will reset if irresponsive for %d seconds\n",
- dpt->unit, DPT_RESET_HBA);
- dpt->last_contact = microtime_now;
-#endif
- dpt->state |= DPT_LOST_IRQ_SET;
- timeout(dpt_irq_timeout, dpt, hz);
- }
- splx(ospl);
-#endif
-
- /**
- * Examine the command flags and handle properly. XXXX We are not
- * handling external resets right now. Needs to be added. We do not
- * care about the SCSI_NOSLEEP flag as we do not sleep here. We have
- * to observe the SCSI_NOMASK flag, though.
- */
- if (xs->flags & SCSI_RESET) {
- printf("dpt%d: Unsupported option...\n"
- " I refuse to Reset b%dt%du%d...!\n",
- dpt->unit, channel, target, lun);
- xs->error = XS_DRIVER_STUFFUP;
- return (COMPLETE);
- }
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE) {
- printf("dpt%d ERROR: Command \"%s\" recieved for b%dt%du%d\n"
- " but controller is shutdown; Aborting...\n",
- dpt->unit,
- scsi_cmd_name(xs->cmd->opcode),
- channel, target, lun);
- xs->error = XS_DRIVER_STUFFUP;
- return (COMPLETE);
- }
- if (flags & ITSDONE) {
- printf("dpt%d WARNING: scsi_cmd(%s) already done on "
- "b%dt%du%d?!\n",
- dpt->unit, scsi_cmd_name(xs->cmd->opcode),
- channel, target, lun);
- xs->flags &= ~ITSDONE;
- }
- if (!(flags & INUSE)) {
- printf("dpt%d WARNING: Unit not in use in scsi_cmd(%s) "
- "on b%dt%du%d?!\n",
- dpt->unit, scsi_cmd_name(xs->cmd->opcode), channel,
- target, lun);
- xs->flags |= INUSE;
- }
- /**
- * We do not want to be disrupted when doing this, or another caller
- * may do the same thing.
- */
- ospl = splsoftcam();
-
- /* Process the free list */
- if ((TAILQ_EMPTY(&dpt->free_ccbs)) && dpt_alloc_freelist(dpt)) {
- printf("dpt%d ERROR: Cannot allocate any more free CCB's.\n"
- " Will try later\n",
- dpt->unit);
- xs->error = XS_DRIVER_STUFFUP;
- splx(ospl);
- return (COMPLETE);
- }
- /* Now grab the newest CCB */
- if ((ccb = dpt_Qpop_free(dpt)) == NULL) {
- /*
- * No need to panic here. We can continue with only as many
- * CCBs as we have.
- */
- printf("dpt%d ERROR: Got a NULL CCB from pop_free()\n",
- dpt->unit);
- xs->error = XS_DRIVER_STUFFUP;
- splx(ospl);
- return (COMPLETE);
- }
-#ifdef DPT_HANDLE_TIMEOUTS
- ccb->status &= ~(DPT_CCB_STATE_ABORTED | DPT_CCB_STATE_MARKED_LOST);
-#endif
-
- splx(ospl);
- bcopy(xs->cmd, ccb->eata_ccb.cp_cdb, xs->cmdlen);
-
- /* Put all the CCB population stuff below */
- ccb->xs = xs;
- ccb->flags = flags;
- /* We NEVER reset the bus from a command */
- ccb->eata_ccb.SCSI_Reset = 0;
- /* We NEVER re-boot the HBA from a * command */
- ccb->eata_ccb.HBA_Init = 0;
- ccb->eata_ccb.Auto_Req_Sen = 1; /* We always want this feature */
- ccb->eata_ccb.reqlen = htonl(sizeof(struct scsi_sense_data));
- ccb->std_callback = NULL;
- ccb->wrbuff_callback = NULL;
-
- if (xs->sc_link->target == xs->sc_link->adapter_targ) {
- ccb->eata_ccb.Interpret = 1;
- } else {
- ccb->eata_ccb.Interpret = 0;
- }
-
- ccb->eata_ccb.scatter = 0; /* S/G is OFF now */
- ccb->eata_ccb.DataIn = 0;
- ccb->eata_ccb.DataOut = 0;
-
- /* At this time we do not deal with the RAID internals */
- ccb->eata_ccb.FWNEST = 0;
- ccb->eata_ccb.Phsunit = 0;
- /* We do not do SMARTROM kind of things */
- ccb->eata_ccb.I_AT = 0;
- /* We do not inhibit the cache at this time */
- ccb->eata_ccb.Disable_Cache = 0;
- ccb->eata_ccb.cp_channel = channel;
- ccb->eata_ccb.cp_id = target;
- ccb->eata_ccb.cp_LUN = lun; /**
- * In the EATA packet. We do not
- * change the SCSI command yet
- */
- /* We are currently dealing with target LUN's, not ROUTINEs */
- ccb->eata_ccb.cp_luntar = 0;
-
- /**
- * XXXX - We grant the target disconnect prvileges, except in polled
- * mode (????).
- */
- if ((ccb->flags & SCSI_NOMASK) || !dpt->handle_interrupts) {
- ccb->eata_ccb.cp_dispri = 0;
- } else {
- ccb->eata_ccb.cp_dispri = 1;
- }
-
- /* we always ask for Identify */
- ccb->eata_ccb.cp_identify = 1;
-
- /**
- * These three are used for command queues and tags. How do we use
- * them?
- *
- * XXX - JGibbs: Most likely like so: ccb->eata_ccb.cp_msg[0] =
- * MSG_SIMPLEQ_TAG; ccb->eata_ccb.cp_msg[1] = tagid;
- * ccb->eata_ccb.cp_msg[2] = 0;
- *
- * YYY - Shimon: Thanx! We still do not do that as the current
- * firmware does it automatically, including on RAID arrays.
- */
-
- ccb->eata_ccb.cp_msg[0] = 0;
- ccb->eata_ccb.cp_msg[1] = 0;
- ccb->eata_ccb.cp_msg[2] = 0;
-
- /* End of CCB population */
-
- if (dpt_scatter_gather(dpt, ccb, xs->datalen, xs->data) != 0) {
- xs->error = XS_DRIVER_STUFFUP;
- ospl = splsoftcam();
- dpt_Qpush_free(dpt, ccb);
- splx(ospl);
- return (COMPLETE);
- }
- xs->resid = 0;
- xs->status = 0;
-
- /**
- * This is the polled mode section. If we are here to honor
- * SCSI_NOMASK, during scsi_attachdevs(), please notice that
- * interrupts are ENABLED in the system (2.2.1) and that the DPT
- * WILL generate them, unless we turn them off!
- */
-
- /**
- * XXX - JGibbs: Polled mode was a botch at best. It's nice to
- * know that it goes completely away with the CAM code.
- * YYY - Simon: Take it out once the rest is stable. Be careful about
- * how you wait for commands to complete when you switch
- * to interrupt mode in the scanning code (initiated by
- * scsi_attachdevs).
- * Disabling it in 2.2 causes a hung system.
- */
-
- if ((ccb->flags & SCSI_NOMASK) || !dpt->handle_interrupts) {
- /**
- * This is an ``immediate'' command. Poll it! We poll by
- * partially bypassing the queues. We first submit the
- * command by asking dpt_run_queue() to queue it. Then we
- * poll its status packet, until it completes. Then we give
- * it to dpt_process_completion() to analyze and then we
- * return.
- */
-
- /*
- * Increase the number of commands queueable for a device. We
- * force each device to the maximum allowed for its HBA. This
- * appears wrong but all it will do is cause excessive
- * commands to sit in our queue. On the other hand, we can
- * burst as many commands as the DPT can take for a single
- * device. We do it here, so only while in polled mode (early
- * boot) do we waste time on it. We have no clean way
- * to overrule sdattach() zeal in depressing the opennings
- * back to one if it is more than 1.
- */
- if (xs->sc_link->opennings < dpt->queuesize) {
- xs->sc_link->opennings = dpt->queuesize;
- }
- /**
- * This test only protects us from submitting polled
- * commands during Non-polled times. We assumed polled
- * commands go in serially, one at a time. BTW, we have NOT
- * checked, nor verified the scope of the disaster that WILL
- * follow going into polled mode after being in interrupt
- * mode for any length of time.
- */
- if (dpt->submitted_ccbs_count < dpt->queuesize) {
- /**
- * Submit the request to the DPT. Unfortunately, ALL
- * this must be done as an atomic operation :-(
- */
- ccb->eata_ccb.cp_viraddr = (u_int32_t) & ccb;
-#define dpt_SP htonl(vtophys(&ccb->status_packet))
-#define dpt_sense htonl(vtophys(&ccb->sense_data))
- ccb->eata_ccb.cp_statDMA = dpt_SP;
- ccb->eata_ccb.cp_reqDMA = dpt_sense;
-
- /* Try to queue a command */
- ospl = splcam();
- result = dpt_send_eata_command(dpt, &ccb->eata_ccb,
- EATA_CMD_DMA_SEND_CP,
- 0, 0, 0, 0);
-
- if (result != 0) {
- dpt_Qpush_free(dpt, ccb);
- xs->error = XS_DRIVER_STUFFUP;
- splx(ospl);
- return (COMPLETE);
- }
- } else {
- xs->error = XS_DRIVER_STUFFUP;
- dpt_Qpush_free(dpt, ccb);
- splx(ospl);
- return (COMPLETE);
- }
-
- for (ndx = 0;
- (ndx < xs->timeout)
- && !((aux_status = dpt_inb(dpt, HA_RAUXSTAT))
- & HA_AIRQ);
- ndx++) {
- DELAY(50);
- }
-
- /**
- * Get the status and clear the interrupt flag on the
- * controller
- */
- status = dpt_inb(dpt, HA_RSTATUS);
- splx(ospl);
-
- ccb->status_reg = status;
- ccb->aux_status_reg = aux_status;
- /* This will setup the xs flags */
- dpt_process_completion(dpt, ccb);
-
- ospl = splsoftcam();
- if ((status & HA_SERROR) || (ndx == xs->timeout)) {
- xs->error = XS_DRIVER_STUFFUP;
- }
-#ifdef DPT_RESET_HBA
- else {
- /*
- * We received a reply and did not time out.
- * Advance the wedge counter.
- */
- dpt->last_contact = microtime_now;
- }
-#endif /* DPT_RESET_HBA */
-
- dpt_Qpush_free(dpt, ccb);
- splx(ospl);
- return (COMPLETE);
- } else {
- /**
- * Not a polled command.
- * The command can be queued normally.
- * We start a critical section PRIOR to submitting to the DPT,
- * and end it AFTER it moves to the submitted queue.
- * If not, we cal (and will!) be hit with a completion
- * interrupt while the command is in suspense between states.
- */
-
- ospl = splsoftcam();
- ccb->transaction_id = ++dpt->commands_processed;
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.command_count[ccb->eata_ccb.cp_scsi_cmd];
- ccb->command_started = microtime_now;
-#endif
- dpt_Qadd_waiting(dpt, ccb);
- splx(ospl);
-
- dpt_sched_queue(dpt);
- }
-
- return (SUCCESSFULLY_QUEUED);
-}
-
-/**
- * This function returns the transfer size in bytes,
- * as a function of the maximum number of Scatter/Gather
- * segments. It should do so for a given HBA, but right now it returns
- * dpt_min_segs, which is the SMALLEST number, from the ``weakest'' HBA found.
- */
-
-static void
-dptminphys(struct buf * bp)
-{
- /**
- * This IS a performance sensitive routine.
- * It gets called at least once per I/O. Sometimes more
- */
-
- if (dpt_min_segs == 0) {
- panic("DPT: Minphys without attach!\n");
- }
- if (bp->b_bcount > ((dpt_min_segs - 1) * PAGE_SIZE)) {
-#ifdef DPT_DEBUG_MINPHYS
- printf("DPT: Block size of %lx is larger than %x. Truncating\n",
- bp->b_bcount, ((dpt_min_segs - 1) * PAGE_SIZE));
-#endif
- bp->b_bcount = ((dpt_min_segs - 1) * PAGE_SIZE);
- }
-}
-
-/*
- * This function goes to the waiting queue, peels off a request, gives it to
- * the DPT HBA and returns. It takes care of some housekeeping details first.
- * The requests argument tells us how many requests to try and send to the
- * DPT. A requests = 0 will attempt to send as many as the controller can
- * take.
- */
-
-static void
-dpt_run_queue(dpt_softc_t * dpt, int requests)
-{
- int req;
- int ospl;
- int ndx;
- int result;
-
- u_int8_t status, aux_status;
-
- eata_ccb_t *ccb;
- dpt_ccb_t *dccb;
-
- if (TAILQ_EMPTY(&dpt->waiting_ccbs)) {
- return; /* Nothing to do if the list is empty */
- }
- if (!requests)
- requests = dpt->queuesize;
-
- /* Main work loop */
- for (req = 0; (req < requests) && dpt->waiting_ccbs_count
- && (dpt->submitted_ccbs_count < dpt->queuesize); req++) {
- /**
- * Move the request from the waiting list to the submitted
- * list, and submit to the DPT.
- * We enter a critical section BEFORE even looking at the
- * queue, and exit it AFTER the ccb has moved to a
- * destination queue.
- * This is normally the submitted queue but can be the waiting
- * queue again, if pushing the command into the DPT failed.
- */
-
- ospl = splsoftcam();
- dccb = TAILQ_FIRST(&dpt->waiting_ccbs);
-
- if (dccb == NULL) {
- /* We have yet to see one report of this condition */
- panic("dpt%d ERROR: Race condition in run_queue "
- "(w%ds%d)\n",
- dpt->unit, dpt->waiting_ccbs_count,
- dpt->submitted_ccbs_count);
- splx(ospl);
- return;
- }
- dpt_Qremove_waiting(dpt, dccb);
- splx(ospl);
-
- /**
- * Assign exact values here. We manipulate these values
- * indirectly elsewhere, so BE CAREFUL!
- */
- dccb->eata_ccb.cp_viraddr = (u_int32_t) dccb;
- dccb->eata_ccb.cp_statDMA = htonl(vtophys(&dpt->sp));
- dccb->eata_ccb.cp_reqDMA = htonl(vtophys(&dccb->sense_data));
-
- if (dccb->xs != NULL)
- bzero(&dccb->xs->sense, sizeof(struct scsi_sense_data));
-
- /* Try to queue a command */
- ospl = splcam();
-
- if ((result = dpt_send_eata_command(dpt, &dccb->eata_ccb,
- EATA_CMD_DMA_SEND_CP, 0,
- 0, 0, 0)) != 0) {
- dpt_Qpush_waiting(dpt, dccb);
- splx(ospl);
- return;
- }
- dpt_Qadd_submitted(dpt, dccb);
- splx(ospl);
- }
-}
-
-/**
- * This is the interrupt handler for the DPT driver.
- * This routine runs at splcam (or whatever was configured for this device).
- */
-
-void
-dpt_intr(void *arg)
-{
- dpt_softc_t *dpt;
- dpt_softc_t *ldpt;
-
- u_int8_t status, aux_status;
-
- dpt_ccb_t *dccb;
- dpt_ccb_t *tccb;
- eata_ccb_t *ccb;
-
- dpt = (dpt_softc_t *) arg;
-
-#ifdef DPT_INTR_DELAY
- DELAY(DPT_INTR_DELAY);
-#endif
-
-#ifdef DPT_MEASURE_PERFORMANCE
- dpt->performance.intr_started = microtime_now;
-#endif
-
- /* First order of business is to check if this interrupt is for us */
- aux_status = dpt_inb(dpt, HA_RAUXSTAT);
- if (!(aux_status & HA_AIRQ)) {
-#ifdef DPT_LOST_IRQ
- if (dpt->state & DPT_LOST_IRQ_ACTIVE) {
- dpt->state &= ~DPT_LOST_IRQ_ACTIVE;
- return;
- }
-#endif
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.spurious_interrupts;
-#endif
- return;
- }
-
- /* The controller is alive, advance the wedge timer */
-#ifdef DPT_RESET_HBA
- dpt->last_contact = microtime_now;
-#endif
-
- if (!dpt->handle_interrupts) {
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.aborted_interrupts;
-#endif
- status = dpt_inb(dpt, HA_RSTATUS); /* This CLEARS interrupts! */
- return;
- }
- /**
- * What we want to do now, is to capture the status, all of it, move
- * it where it belongs, wake up whoever sleeps waiting to process
- * this result, and get out of here.
- */
-
- dccb = dpt->sp.ccb; /**
- * There is a very SERIOUS and dangerous
- * assumption here. We assume that EVERY
- * interrupt is in response to some request we
- * put to the DPT. IOW, we assume that the
- * Virtual Address of CP always has a valid
- * pointer that we put in! How will the DPT
- * behave if it is in Target mode? How does it
- * (and our driver) know it switches from
- * Initiator to target? What will the SP be
- * when a target mode interrupt is received?
- */
-
-#ifdef DPT_VERIFY_HINTR
- dpt->sp.ccb = (dpt_ccb_t *) 0x55555555;
-#else
- dpt->sp.ccb = (dpt_ccb_t *) NULL;
-#endif
-
-#ifdef DPT_HANDLE_TIMEOUTS
- if (dccb->state & DPT_CCB_STATE_MARKED_LOST) {
- u_int32_t age;
- struct scsi_xfer *xs = dccb->xs;
-
- age = dpt_time_delta(dccb->command_started, microtime_now);
-
- printf("dpt%d: Salvaging Tx %d from the jaws of destruction "
- "(%d/%d)\n",
- dpt->unit, dccb->transaction_id, xs->timeout, age);
- dccb->state |= DPT_CCB_STATE_MARKED_SALVAGED;
- dccb->state &= ~DPT_CCB_STATE_MARKED_LOST;
- }
-#endif
-
- /* Ignore status packets with EOC not set */
- if (dpt->sp.EOC == 0) {
- printf("dpt%d ERROR: Request %d recieved with clear EOC.\n"
- " Marking as LOST.\n",
- dpt->unit, dccb->transaction_id);
-#ifdef DPT_VERIFY_HINTR
- dpt->sp.ccb = (dpt_sp_t *) 0x55555555;
-#else
- dpt->sp.ccb = (dpt_sp_t *) NULL;
-#endif
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.aborted_interrupts;
-#endif
-
-#ifdef DPT_HANDLE_TIMEOUTS
- dccb->state |= DPT_CCB_STATE_MARKED_LOST;
-#endif
- /* This CLEARS the interrupt! */
- status = dpt_inb(dpt, HA_RSTATUS);
- return;
- }
- dpt->sp.EOC = 0;
-
-#ifdef DPT_VERIFY_HINTR
- /*
- * Make SURE the next caller is legitimate. If they are not, we will
- * find 0x55555555 here. We see 0x000000 or 0xffffffff when the PCi
- * bus has DMA troubles (as when behing a PCI-PCI * bridge .
- */
- if ((dccb == NULL)
- || (dccb == (dpt_ccb_t *) ~ 0)
- || (dccb == (dpt_ccb_t *) 0x55555555)) {
- printf("dpt%d: BAD (%p) CCB in SP (AUX status = %s).\n",
- dpt->unit, (void *)dccb,
- i2bin((unsigned long) aux_status,
- sizeof(aux_status) * 8));
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.aborted_interrupts;
-#endif
- /* This CLEARS the interrupt! */
- status = dpt_inb(dpt, HA_RSTATUS);
- return;
- }
- for (tccb = TAILQ_FIRST(&dpt->submitted_ccbs);
- (tccb != NULL) && (tccb != dccb);
- tccb = TAILQ_NEXT(tccb, links));
- if (tccb == NULL) {
- printf("dpt%d: %p is not in the SUBMITTED queue\n",
- dpt->unit, (void *)dccb);
-
- for (tccb = TAILQ_FIRST(&dpt->completed_ccbs);
- (tccb != NULL) && (tccb != dccb);
- tccb = TAILQ_NEXT(tccb, links));
- if (tccb != NULL)
- printf("dpt%d: %p is in the COMPLETED queue\n",
- dpt->unit, (void *)dccb);
-
- for (tccb = TAILQ_FIRST(&dpt->waiting_ccbs);
- (tccb != NULL) && (tccb != dccb);
- tccb = TAILQ_NEXT(tccb, links));
- if (tccb != NULL)
- printf("dpt%d: %p is in the WAITING queue\n",
- dpt->unit, (void *)dccb);
-
- for (tccb = TAILQ_FIRST(&dpt->free_ccbs);
- (tccb != NULL) && (tccb != dccb);
- tccb = TAILQ_NEXT(tccb, links));
- if (tccb != NULL)
- printf("dpt%d: %p is in the FREE queue\n",
- dpt->unit, (void *)dccb);
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.aborted_interrupts;
-#endif
- /* This CLEARS the interrupt! */
- status = dpt_inb(dpt, HA_RSTATUS);
- return;
- }
-#endif /* DPT_VERIFY_HINTR */
-
- /**
- * Copy the status packet from the general area to the dpt_ccb.
- * According to Mark Salyzyn, we only need few pieces of it.
- * Originally we had:
- * bcopy((void *) &dpt->sp, (void *) &dccb->status_packet,
- * sizeof(dpt_sp_t));
- */
- dccb->status_packet.hba_stat = dpt->sp.hba_stat;
- dccb->status_packet.scsi_stat = dpt->sp.scsi_stat;
- dccb->status_packet.residue_len = dpt->sp.residue_len;
-
- /* Make sure the EOC bit is OFF! */
- dpt->sp.EOC = 0;
-
- /* Clear interrupts, check for error */
- if ((status = dpt_inb(dpt, HA_RSTATUS)) & HA_SERROR) {
- /**
- * Error Condition. Check for magic cookie. Exit this test
- * on earliest sign of non-reset condition
- */
-
- /* Check that this is not a board reset interrupt */
- if (dpt_just_reset(dpt)) {
- printf("dpt%d: HBA rebooted.\n"
- " All transactions should be "
- "resubmitted\n",
- dpt->unit);
-
- printf("dpt%d: >>---->> This is incomplete, fix me"
- ".... <<----<<",
- dpt->unit);
- printf(" Incomplete Code; Re-queue the lost "
- "commands\n");
- Debugger("DPT Rebooted");
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ++dpt->performance.aborted_interrupts;
-#endif
- return;
- }
- }
- dccb->status_reg = status;
- dccb->aux_status_reg = aux_status;
-
- /* Mark BOTH queues as busy */
- dpt->queue_status |= (DPT_SUBMITTED_QUEUE_ACTIVE
- | DPT_COMPLETED_QUEUE_ACTIVE);
- dpt_Qremove_submitted(dpt, dccb);
- dpt_Qadd_completed(dpt, dccb);
- dpt->queue_status &= ~(DPT_SUBMITTED_QUEUE_ACTIVE
- | DPT_COMPLETED_QUEUE_ACTIVE);
- dpt_sched_queue(dpt);
-
-#ifdef DPT_MEASURE_PERFORMANCE
- {
- u_int32_t result;
-
- result = dpt_time_delta(dpt->performance.intr_started, microtime_now);
-
- if (result != ~0) {
- if (dpt->performance.max_intr_time < result)
- dpt->performance.max_intr_time = result;
-
- if (result < dpt->performance.min_intr_time) {
- dpt->performance.min_intr_time = result;
- }
- }
- }
-#endif
-}
-
-/*
- * This function is the DPT_ISR Software Interrupt Service Routine. When the
- * DPT completes a SCSI command, it puts the results in a Status Packet, sets
- * up two 1-byte registers and generates an interrupt. We catch this
- * interrupt in dpt_intr and copy the whole status to the proper CCB. Once
- * this is done, we generate a software interrupt that calls this routine.
- * The routine then scans ALL the complete queues of all the DPT HBA's and
- * processes ALL the commands that are in the queue.
- *
- * XXXX REMEMBER: We always scan ALL the queues of all the HBA's. Always
- * starting with the first controller registered (dpt0). This creates
- * an ``unfair'' opportunity for the first controllers in being served.
- * Careful instrumentation may prove a need to change this policy.
- *
- * This command rns at splSOFTcam. Remember that.
- */
-
-static void
-dpt_sintr(void)
-{
- dpt_softc_t *dpt;
- int ospl;
-
- /* Find which DPT needs help */
- for (dpt = TAILQ_FIRST(&dpt_softc_list);
- dpt != NULL;
- dpt = TAILQ_NEXT(dpt, links)) {
- /*
- * Drain the completed queue, to make room for new, " waiting
- * requests. We change to splcam to block interrupts from
- * mucking with " the completed queue
- */
- ospl = splcam();
- if (dpt->queue_status & DPT_SINTR_ACTIVE) {
- splx(ospl);
- continue;
- }
- dpt->queue_status |= DPT_SINTR_ACTIVE;
-
- if (!TAILQ_EMPTY(&dpt->completed_ccbs)) {
- splx(ospl);
- dpt_complete(dpt);
- ospl = splcam();
- }
- /* Submit as many waiting requests as the DPT can take */
- if (!TAILQ_EMPTY(&dpt->waiting_ccbs)) {
- dpt_run_queue(dpt, 0);
- }
- dpt->queue_status &= ~DPT_SINTR_ACTIVE;
- splx(ospl);
- }
-}
-
-/**
- * Scan the complete queue for a given controller and process ALL the completed
- * commands in the queue.
- */
-
-static void
-dpt_complete(dpt_softc_t * dpt)
-{
- dpt_ccb_t *ccb;
- int ospl;
-
- ospl = splcam();
-
- if (dpt->queue_status & DPT_COMPLETED_QUEUE_ACTIVE) {
- splx(ospl);
- return;
- }
- dpt->queue_status |= DPT_COMPLETED_QUEUE_ACTIVE;
-
- while ((ccb = TAILQ_FIRST(&dpt->completed_ccbs)) != NULL) {
- struct scsi_xfer *xs;
-
- dpt_Qremove_completed(dpt, ccb);
- splx(ospl);
-
- /* Process this completed request */
- if (dpt_process_completion(dpt, ccb) == 0) {
- xs = ccb->xs;
-
- if (ccb->std_callback != NULL) {
- (ccb->std_callback) (dpt, ccb->eata_ccb.cp_channel,
- ccb);
- } else {
- ospl = splcam();
- dpt_Qpush_free(dpt, ccb);
- splx(ospl);
-
-#ifdef DPT_MEASURE_PERFORMANCE
- {
- u_int32_t result;
-
-#define time_delta dpt_time_delta(ccb->command_started, ccb->command_ended)
-#define maxctime dpt->performance.max_command_time[ccb->eata_ccb.cp_scsi_cmd]
-#define minctime dpt->performance.min_command_time[ccb->eata_ccb.cp_scsi_cmd]
-
- ccb->command_ended = microtime_now;
- result = time_delta;
-
- if (result != ~0) {
- if (maxctime < result) {
- maxctime = result;
- }
- if ((minctime == 0)
- || (minctime > result))
- minctime = result;
- }
- }
-#endif
-
- scsi_done(xs);
- }
- ospl = splcam();
- }
- }
- splx(ospl);
-
- /**
- * As per Justin's suggestion, we now will call the run_queue for
- * this HBA. This is done in case there are left-over requests that
- * were not submitted yet.
- */
- dpt_run_queue(dpt, 0);
- ospl = splsoftcam();
- dpt->queue_status &= ~DPT_COMPLETED_QUEUE_ACTIVE;
- splx(ospl);
-}
-
-#ifdef DPT_MEASURE_PERFORMANCE
-/**
- * Given a dpt_ccb and a scsi_xfr structures,
- * this functions translates the result of a SCSI operation.
- * It returns values in the structures pointed by the arguments.
- * This function does NOT attempt to protect itself from bad influence!
- */
-
-#define WRITE_OP 1
-#define READ_OP 2
-#define min_submitR dpt->performance.read_by_size_min_time[index]
-#define max_submitR dpt->performance.read_by_size_max_time[index]
-#define min_submitW dpt->performance.write_by_size_min_time[index]
-#define max_submitW dpt->performance.write_by_size_max_time[index]
-
-static void
-dpt_IObySize(dpt_softc_t * dpt, dpt_ccb_t * ccb, int op, int index)
-{
- if (op == READ_OP) {
- ++dpt->performance.read_by_size_count[index];
- if (ccb->submitted_time < min_submitR)
- min_submitR = ccb->submitted_time;
-
- if (ccb->submitted_time > max_submitR)
- max_submitR = ccb->submitted_time;
- } else { /* WRITE operation */
- ++dpt->performance.write_by_size_count[index];
- if (ccb->submitted_time < min_submitW)
- min_submitW = ccb->submitted_time;
-
- if (ccb->submitted_time > max_submitW)
- max_submitW = ccb->submitted_time;
- }
-}
-#endif
-
-static int
-dpt_process_completion(dpt_softc_t * dpt,
- dpt_ccb_t * ccb)
-{
- int ospl;
- struct scsi_xfer *xs;
-
- if (ccb == NULL) {
- panic("dpt%d: Improper argumet to process_completion (%p)\n",
- dpt->unit, (void *)ccb);
- } else {
- xs = ccb->xs;
- }
-
-#ifdef DPT_MEASURE_PERFORMANCE
- {
- u_int32_t size;
- struct scsi_rw_big *cmd;
- int op_type;
-
- cmd = (struct scsi_rw_big *) &ccb->eata_ccb.cp_scsi_cmd;
-
- switch (cmd->op_code) {
- case 0xa8: /* 12-byte READ */
- case 0x08: /* 6-byte READ */
- case 0x28: /* 10-byte READ */
- op_type = READ_OP;
- break;
- case 0x0a: /* 6-byte WRITE */
- case 0xaa: /* 12-byte WRITE */
- case 0x2a: /* 10-byte WRITE */
- op_type = WRITE_OP;
- break;
- default:
- op_type = 0;
- break;
- }
-
- if (op_type != 0) {
-
- size = (((u_int32_t) cmd->length2 << 8)
- | ((u_int32_t) cmd->length1)) << 9;
-
- switch (size) {
- case 512:
- dpt_IObySize(dpt, ccb, op_type, SIZE_512);
- break;
- case 1024:
- dpt_IObySize(dpt, ccb, op_type, SIZE_1K);
- break;
- case 2048:
- dpt_IObySize(dpt, ccb, op_type, SIZE_2K);
- break;
- case 4096:
- dpt_IObySize(dpt, ccb, op_type, SIZE_4K);
- break;
- case 8192:
- dpt_IObySize(dpt, ccb, op_type, SIZE_8K);
- break;
- case 16384:
- dpt_IObySize(dpt, ccb, op_type, SIZE_16K);
- break;
- case 32768:
- dpt_IObySize(dpt, ccb, op_type, SIZE_32K);
- break;
- case 65536:
- dpt_IObySize(dpt, ccb, op_type, SIZE_64K);
- break;
- default:
- if (size > (1 << 16))
- dpt_IObySize(dpt, ccb, op_type,
- SIZE_BIGGER);
-
- else
- dpt_IObySize(dpt, ccb, op_type,
- SIZE_OTHER);
- break;
- }
- }
- }
-#endif /* DPT_MEASURE_PERFORMANCE */
-
-
- switch ((int) ccb->status_packet.hba_stat) {
- case HA_NO_ERROR:
- if (xs != NULL) {
- xs->error = XS_NOERROR;
- xs->flags |= SCSI_ITSDONE;
- }
- break;
- case HA_ERR_SEL_TO:
- case HA_ERR_CMD_TO:
- if (xs != NULL) {
- xs->error |= XS_SELTIMEOUT;
- xs->flags |= SCSI_ITSDONE;
- }
- break;
- case HA_SCSIBUS_RESET:
- case HA_CP_ABORTED:
- case HA_CP_RESET:
- case HA_PCI_PARITY:
- case HA_PCI_MABORT:
- case HA_PCI_TABORT:
- case HA_PCI_STABORT:
- case HA_BUS_PARITY:
- case HA_UNX_MSGRJCT:
- if (ccb->retries++ > DPT_RETRIES) {
- if (xs != NULL) {
- xs->error |= XS_SENSE;
- xs->flags |= SCSI_ITSDONE;
- }
- } else {
- ospl = splsoftcam();
- dpt_Qpush_waiting(dpt, ccb);
- splx(ospl);
- dpt_sched_queue(dpt);
- }
- break;
- case HA_HBA_POWER_UP:
- case HA_UNX_BUSPHASE:
- case HA_UNX_BUS_FREE:
- case HA_SCSI_HUNG:
- case HA_RESET_STUCK:
- if (ccb->retries++ > DPT_RETRIES) {
- if (xs != NULL) {
- xs->error |= XS_SENSE;
- xs->flags |= SCSI_ITSDONE;
- }
- } else {
- ospl = splsoftcam();
- dpt_Qpush_waiting(dpt, ccb);
- splx(ospl);
- dpt_sched_queue(dpt);
- return (1);
- }
- break;
- case HA_RSENSE_FAIL:
- if (ccb->status_packet.EOC) {
- if (xs != NULL) {
- xs->error |= XS_SENSE;
- xs->flags |= SCSI_ITSDONE;
- }
- } else {
- if (ccb->retries++ > DPT_RETRIES) {
- if (xs != NULL) {
- xs->error |= XS_SENSE;
- xs->flags |= SCSI_ITSDONE;
- }
- } else {
- ospl = splsoftcam();
- dpt_Qpush_waiting(dpt, ccb);
- splx(ospl);
- dpt_sched_queue(dpt);
- return (1);
- }
- }
- break;
- case HA_PARITY_ERR:
- case HA_CP_ABORT_NA:
- case HA_CP_RESET_NA:
- case HA_ECC_ERR:
- if (xs != NULL) {
- xs->error |= XS_SENSE;
- xs->flags |= SCSI_ITSDONE;
- }
- break;
- default:
- printf("dpt%d: Undocumented Error %x",
- dpt->unit, ccb->status_packet.hba_stat);
- if (xs != NULL) {
- xs->error |= XS_SENSE;
- xs->flags |= SCSI_ITSDONE;
- }
- Debugger("Please mail this message to shimon@i-connect.net");
- break;
- }
-
- if (xs != NULL) {
- if ((xs->error & XS_SENSE))
- bcopy(&ccb->sense_data, &xs->sense,
- sizeof(struct scsi_sense_data));
-
- if (ccb->status_packet.residue_len != 0) {
- xs->flags |= SCSI_RESID_VALID;
- xs->resid = ccb->status_packet.residue_len;
- }
- }
- return (0);
-}
-
-#ifdef DPT_LOST_IRQ
-/**
- * This functions handles the calling of the interrupt routine on a periodic
- * basis.
- * It is a completely ugly hack which purpose is to handle the problem of
- * missing interrupts on certain platforms..
- *
- * An additional task is to optionally check if the controller is wedged.
- * A wedeged controller is one which has not accepted a command, nor sent
- * an interrupt in the last DPT_RESET_HBA seconds.
- */
-
-static void
-dpt_irq_timeout(void *arg)
-{
- dpt_softc_t *dpt = (dpt_softc_t *) arg;
- int ospl;
-
-
- if (!(dpt->state & DPT_LOST_IRQ_ACTIVE)) {
- ospl = splcam();
- dpt->state |= DPT_LOST_IRQ_ACTIVE;
- dpt_intr(dpt);
- splx(ospl);
- if (dpt->state & DPT_LOST_IRQ_ACTIVE) {
- printf("dpt %d: %d lost Interrupts Recovered\n",
- dpt->unit, ++dpt->lost_interrupts);
- }
-#ifdef DPT_RESET_HBA
- {
- int max_wedge, contact_delta;
-
- if (TAILQ_EMPTY(&dpt->waiting_ccbs)) {
- dpt->last_contact = microtime_now;
- } else {
- /* If nothing is waiting, we cannot assume we are wedged */
- if (DPT_RESET_HBA < 1)
- max_wedge = 1000000;
- else
- max_wedge = 1000000 * DPT_RESET_HBA;
-
- contact_delta = dpt_time_delta(dpt->last_contact,
- microtime_now);
-
- if (contact_delta > max_wedge) {
- printf("dpt%d: Appears wedged for %d.%d (%d.0)seconds.\n"
- " Resetting\n",
- dpt->unit, contact_delta/1000000,
- (contact_delta % 1000000) / 100000,
- DPT_RESET_HBA);
- dpt_reset_hba(dpt);
- }
- }
- }
-#endif /* DPT_RESET_HBA */
-
- dpt->state &= ~DPT_LOST_IRQ_ACTIVE;
- }
- timeout(dpt_irq_timeout, (caddr_t) dpt, hz * 1);
-}
-
-#endif /* DPT_LOST_IRQ */
-
#ifdef DPT_HANDLE_TIMEOUTS
/**
* This function walks down the SUBMITTED queue.
@@ -3186,648 +2509,4 @@ dpt_timeout(void *arg)
#endif /* DPT_HANDLE_TIMEOUTS */
-/*
- * Remove a ccb from the completed queue
- */
-static INLINE_Q void
-dpt_Qremove_completed(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
-#ifdef DPT_MEASURE_PERFORMANCE
- u_int32_t complete_time;
-
- complete_time = dpt_time_delta(ccb->command_ended, microtime_now);
-
- if (complete_time != ~0) {
- if (dpt->performance.max_complete_time < complete_time)
- dpt->performance.max_complete_time = complete_time;
- if (complete_time < dpt->performance.min_complete_time)
- dpt->performance.min_complete_time = complete_time;
- }
-#endif
-
- TAILQ_REMOVE(&dpt->completed_ccbs, ccb, links);
- --dpt->completed_ccbs_count; /* One less completed ccb in the
- * queue */
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- wakeup(&dpt);
-}
-
-/**
- * Pop the most recently used ccb off the (HEAD of the) FREE ccb queue
- */
-static INLINE_Q dpt_ccb_t *
-dpt_Qpop_free(dpt_softc_t * dpt)
-{
- dpt_ccb_t *ccb;
-
- if ((ccb = TAILQ_FIRST(&dpt->free_ccbs)) == NULL) {
- if (dpt_alloc_freelist(dpt))
- return (ccb);
- else
- return (dpt_Qpop_free(dpt));
- } else {
- TAILQ_REMOVE(&dpt->free_ccbs, ccb, links);
- --dpt->free_ccbs_count;
- }
-
- return (ccb);
-}
-
-/**
- * Put a (now freed) ccb back into the HEAD of the FREE ccb queue
- */
-static INLINE_Q void
-dpt_Qpush_free(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
-#ifdef DPT_FREELIST_IS_STACK
- TAILQ_INSERT_HEAD(&dpt->free_ccbs, ccb, links);
-#else
- TAILQ_INSERT_TAIL(&dpt->free_ccbs, ccb, links);
#endif
-
- ++dpt->free_ccbs_count;
-}
-
-/**
- * Add a request to the TAIL of the WAITING ccb queue
- */
-static INLINE_Q void
-dpt_Qadd_waiting(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
- TAILQ_INSERT_TAIL(&dpt->waiting_ccbs, ccb, links);
- ++dpt->waiting_ccbs_count;
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ccb->command_ended = microtime_now;
- if (dpt->waiting_ccbs_count > dpt->performance.max_waiting_count)
- dpt->performance.max_waiting_count = dpt->waiting_ccbs_count;
-#endif
-
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- wakeup(&dpt);
-}
-
-/**
- * Add a request to the HEAD of the WAITING ccb queue
- */
-static INLINE_Q void
-dpt_Qpush_waiting(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
- TAILQ_INSERT_HEAD(&dpt->waiting_ccbs, ccb, links);
- ++dpt->waiting_ccbs_count;
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ccb->command_ended = microtime_now;
-
- if (dpt->performance.max_waiting_count < dpt->waiting_ccbs_count)
- dpt->performance.max_waiting_count = dpt->waiting_ccbs_count;
-
-#endif
-
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- wakeup(&dpt);
-}
-
-/**
- * Remove a ccb from the waiting queue
- */
-static INLINE_Q void
-dpt_Qremove_waiting(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
-#ifdef DPT_MEASURE_PERFORMANCE
- u_int32_t waiting_time;
-
- waiting_time = dpt_time_delta(ccb->command_ended, microtime_now);
-
- if (waiting_time != ~0) {
- if (dpt->performance.max_waiting_time < waiting_time)
- dpt->performance.max_waiting_time = waiting_time;
- if (waiting_time < dpt->performance.min_waiting_time)
- dpt->performance.min_waiting_time = waiting_time;
- }
-#endif
-
- TAILQ_REMOVE(&dpt->waiting_ccbs, ccb, links);
- --dpt->waiting_ccbs_count; /* One less waiting ccb in the queue */
-
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- wakeup(&dpt);
-}
-
-/**
- * Add a request to the TAIL of the SUBMITTED ccb queue
- */
-static INLINE_Q void
-dpt_Qadd_submitted(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
- TAILQ_INSERT_TAIL(&dpt->submitted_ccbs, ccb, links);
- ++dpt->submitted_ccbs_count;
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ccb->command_ended = microtime_now;
- if (dpt->performance.max_submit_count < dpt->submitted_ccbs_count)
- dpt->performance.max_submit_count = dpt->submitted_ccbs_count;
-#endif
-
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- wakeup(&dpt);
-}
-
-/**
- * Add a request to the TAIL of the Completed ccb queue
- */
-static INLINE_Q void
-dpt_Qadd_completed(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
- TAILQ_INSERT_TAIL(&dpt->completed_ccbs, ccb, links);
- ++dpt->completed_ccbs_count;
-
-#ifdef DPT_MEASURE_PERFORMANCE
- ccb->command_ended = microtime_now;
- if (dpt->performance.max_complete_count < dpt->completed_ccbs_count)
- dpt->performance.max_complete_count =
- dpt->completed_ccbs_count;
-#endif
-
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- wakeup(&dpt);
-}
-
-/**
- * Remove a ccb from the submitted queue
- */
-static INLINE_Q void
-dpt_Qremove_submitted(dpt_softc_t * dpt, dpt_ccb_t * ccb)
-{
-#ifdef DPT_MEASURE_PERFORMANCE
- u_int32_t submit_time;
-
- submit_time = dpt_time_delta(ccb->command_ended, microtime_now);
-
- if (submit_time != ~0) {
- ccb->submitted_time = submit_time;
- if (dpt->performance.max_submit_time < submit_time)
- dpt->performance.max_submit_time = submit_time;
- if (submit_time < dpt->performance.min_submit_time)
- dpt->performance.min_submit_time = submit_time;
- } else {
- ccb->submitted_time = 0;
- }
-
-#endif
-
- TAILQ_REMOVE(&dpt->submitted_ccbs, ccb, links);
- --dpt->submitted_ccbs_count; /* One less submitted ccb in the
- * queue */
-
- if ((dpt->state & DPT_HA_SHUTDOWN_ACTIVE)
- || (dpt->state & DPT_HA_QUIET))
- wakeup(&dpt);
-}
-
-/**
- * Handle Shutdowns.
- * Gets registered by the dpt_pci.c registar and called AFTER the system did
- * all its sync work.
- */
-
-void
-dpt_shutdown(int howto, void *arg_dpt)
-{
- dpt_softc_t *ldpt;
- u_int8_t channel;
- u_int32_t target;
- u_int32_t lun;
- int waiting;
- int submitted;
- int completed;
- int huh;
- int wait_is_over;
- int ospl;
- dpt_softc_t *dpt;
-
- dpt = (dpt_softc_t *) arg_dpt;
-
- printf("dpt%d: Shutting down (mode %d) HBA. Please wait...",
- dpt->unit, howto);
- wait_is_over = 0;
-
- ospl = splcam();
- dpt->state |= DPT_HA_SHUTDOWN_ACTIVE;
- splx(ospl);
-
- while ((((waiting = dpt->waiting_ccbs_count) != 0)
- || ((submitted = dpt->submitted_ccbs_count) != 0)
- || ((completed = dpt->completed_ccbs_count) != 0))
- && (wait_is_over == 0)) {
-#ifdef DPT_DEBUG_SHUTDOWN
- printf("dpt%d: Waiting for queues w%ds%dc%d to deplete\n",
- dpt->unit, dpt->waiting_ccbs_count,
- dpt->submitted_ccbs_count,
- dpt->completed_ccbs_count);
-#endif
- huh = tsleep((void *) dpt, PCATCH | PRIBIO, "dptoff", 100 * hz);
- switch (huh) {
- case 0:
- /* Wakeup call received */
- goto checkit;
- break;
- case EWOULDBLOCK:
- /* Timer Expired */
- printf("dpt%d: Shutdown timer expired with queues at "
- "w%ds%dc%d\n",
- dpt->unit, dpt->waiting_ccbs_count,
- dpt->submitted_ccbs_count,
- dpt->completed_ccbs_count);
- ++wait_is_over;
- break;
- default:
- /* anything else */
- printf("dpt%d: Shutdown UNKNOWN with qeueues at "
- "w%ds%dc%d\n",
- dpt->unit, dpt->waiting_ccbs_count,
- dpt->submitted_ccbs_count,
- dpt->completed_ccbs_count);
- ++wait_is_over;
- break;
- }
-checkit:
-
- }
-
- /**
- * What we do for a shutdown, is give the DPT early power loss
- * warning
- */
-#ifdef DPT_SHUTDOWN_SLEEP
- DELAY(DPT_SHUTDOWN_SLEEP * 1000);
-
- if (dpt->state & DPT_HA_SHUTDOWN_ACTIVE) {
- ospl = splcam();
- dpt->state &= ~DPT_HA_SHUTDOWN_ACTIVE;
- splx(ospl);
- printf("dpt%d: WARNING: After sleeping for about 100 seconds, "
- "I am re-enabled\n",
- dpt->unit);
- printf(" Any further I/O is NOT guaranteed to "
- "complete!\n");
- }
-#else
- (void) dpt_send_immediate(dpt, NULL, EATA_POWER_OFF_WARN, 0, 0);
- printf("dpt%d: Controller was warned of shutdown and is now "
- "disabled\n",
- dpt->unit);
-#endif
-
- return;
-}
-
-/* A primitive subset of isgraph. Used by hex_dump below */
-#define IsGraph(val) ((((val) >= ' ') && ((val) <= '~')))
-
-/**
- * This function dumps bytes to the screen in hex format.
- */
-static void
-hex_dump(u_int8_t * data, int length, char *name, int no)
-{
- int line, column, ndx;
-
- printf("Kernel Hex Dump for %s-%d at %p (%d bytes)\n",
- name, no, data, length);
-
- /* Zero out all the counters and repeat for as many bytes as we have */
- for (ndx = 0, column = 0, line = 0; ndx < length; ndx++) {
- /* Print relative offset at the beginning of every line */
- if (column == 0)
- printf("%04x ", ndx);
-
- /* Print the byte as two hex digits, followed by a space */
- printf("%02x ", data[ndx]);
-
- /* Split the row of 16 bytes in half */
- if (++column == 8) {
- printf(" ");
- }
- /* St the end of each row of 16 bytes, put a space ... */
- if (column == 16) {
- printf(" ");
-
- /* ... and then print the ASCII-visible on a line. */
- for (column = 0; column < 16; column++) {
- int ascii_pos = ndx - 15 + column;
-
- /**
- * Non-printable and non-ASCII are just a
- * dot. ;-(
- */
- if (IsGraph(data[ascii_pos]))
- printf("%c", data[ascii_pos]);
- else
- printf(".");
- }
-
- /* Each line ends with a new line */
- printf("\n");
- column = 0;
-
- /**
- * Every 256 bytes (16 lines of 16 bytes each) have
- * an empty line, separating them from the next
- * ``page''. Yes, I programmed on a Z-80, where a
- * page was 256 bytes :-)
- */
- if (++line > 15) {
- printf("\n");
- line = 0;
- }
- }
- }
-
- /**
- * We are basically done. We do want, however, to handle the ASCII
- * translation of fractional lines.
- */
- if ((ndx == length) && (column != 0)) {
- int modulus = 16 - column, spaces = modulus * 3,
- skip;
-
- /**
- * Skip to the right, as many spaces as there are bytes
- * ``missing'' ...
- */
- for (skip = 0; skip < spaces; skip++)
- printf(" ");
-
- /* ... And the gap separating the hex dump from the ASCII */
- printf(" ");
-
- /**
- * Do not forget the extra space that splits the hex dump
- * vertically
- */
- if (column < 8)
- printf(" ");
-
- for (column = 0; column < (16 - modulus); column++) {
- int ascii_pos = ndx - (16 - modulus) + column;
-
- if (IsGraph(data[ascii_pos]))
- printf("%c", data[ascii_pos]);
- else
- printf(".");
- }
- printf("\n");
- }
-}
-
-/**
- * and this one presents an integer as ones and zeros
- */
-static char i2bin_bitmap[48]; /* Used for binary dump of registers */
-
-char *
-i2bin(unsigned int no, int length)
-{
- int ndx, rind;
-
- for (ndx = 0, rind = 0; ndx < 32; ndx++, rind++) {
- i2bin_bitmap[rind] = (((no << ndx) & 0x80000000) ? '1' : '0');
-
- if (((ndx % 4) == 3))
- i2bin_bitmap[++rind] = ' ';
- }
-
- if ((ndx % 4) == 3)
- i2bin_bitmap[rind - 1] = '\0';
- else
- i2bin_bitmap[rind] = '\0';
-
- switch (length) {
- case 8:
- return (i2bin_bitmap + 30);
- break;
- case 16:
- return (i2bin_bitmap + 20);
- break;
- case 24:
- return (i2bin_bitmap + 10);
- break;
- case 32:
- return (i2bin_bitmap);
- default:
- return ("i2bin: Invalid length Specs");
- break;
- }
-}
-
-/**
- * This function translates a SCSI command numeric code to a human readable
- * string.
- * The string contains the class of devices, scope, description, (length),
- * and [SCSI III documentation section].
- */
-
-static char *
-scsi_cmd_name(u_int8_t cmd)
-{
- switch (cmd) {
- case 0x40:
- return ("Change Definition [7.1]");
- break;
- case 0x39:
- return ("Compare [7,2]");
- break;
- case 0x18:
- return ("Copy [7.3]");
- break;
- case 0x3a:
- return ("Copy and Verify [7.4]");
- break;
- case 0x04:
- return ("Format Unit [6.1.1]");
- break;
- case 0x12:
- return ("Inquiry [7.5]");
- break;
- case 0x36:
- return ("lock/Unlock Cache [6.1.2]");
- break;
- case 0x4c:
- return ("Log Select [7.6]");
- break;
- case 0x4d:
- return ("Log Sense [7.7]");
- break;
- case 0x15:
- return ("Mode select (6) [7.8]");
- break;
- case 0x55:
- return ("Mode Select (10) [7.9]");
- break;
- case 0x1a:
- return ("Mode Sense (6) [7.10]");
- break;
- case 0x5a:
- return ("Mode Sense (10) [7.11]");
- break;
- case 0xa7:
- return ("Move Medium Attached [SMC]");
- break;
- case 0x5e:
- return ("Persistent Reserve In [7.12]");
- break;
- case 0x5f:
- return ("Persistent Reserve Out [7.13]");
- break;
- case 0x1e:
- return ("Prevent/Allow Medium Removal [7.14]");
- break;
- case 0x08:
- return ("Read, Receive (6) [6.1.5]");
- break;
- case 0x28:
- return ("Read (10) [6.1.5]");
- break;
- case 0xa8:
- return ("Read (12) [6.1.5]");
- break;
- case 0x3c:
- return ("Read Buffer [7.15]");
- break;
- case 0x25:
- return ("Read Capacity [6.1.6]");
- break;
- case 0x37:
- return ("Read Defect Data (10) [6.1.7]");
- break;
- case 0xb7:
- return ("Read Defect Data (12) [6.2.5]");
- break;
- case 0xb4:
- return ("Read Element Status Attached [SMC]");
- break;
- case 0x3e:
- return ("Read Long [6.1.8]");
- break;
- case 0x07:
- return ("Reassign Blocks [6.1.9]");
- break;
- case 0x81:
- return ("Rebuild [6.1.10]");
- break;
- case 0x1c:
- return ("Receive Diagnostics Result [7.16]");
- break;
- case 0x82:
- return ("Regenerate [6.1.11]");
- break;
- case 0x17:
- return ("Release(6) [7.17]");
- break;
- case 0x57:
- return ("Release(10) [7.18]");
- break;
- case 0xa0:
- return ("Report LUNs [7.19]");
- break;
- case 0x03:
- return ("Request Sense [7.20]");
- break;
- case 0x16:
- return ("Resereve (6) [7.21]");
- break;
- case 0x56:
- return ("Reserve(10) [7.22]");
- break;
- case 0x2b:
- return ("Reserve(10) [6.1.12]");
- break;
- case 0x1d:
- return ("Send Disagnostics [7.23]");
- break;
- case 0x33:
- return ("Set Limit (10) [6.1.13]");
- break;
- case 0xb3:
- return ("Set Limit (12) [6.2.8]");
- break;
- case 0x1b:
- return ("Start/Stop Unit [6.1.14]");
- break;
- case 0x35:
- return ("Synchronize Cache [6.1.15]");
- break;
- case 0x00:
- return ("Test Unit Ready [7.24]");
- break;
- case 0x3d:
- return ("Update Block (6.2.9");
- break;
- case 0x2f:
- return ("Verify (10) [6.1.16, 6.2.10]");
- break;
- case 0xaf:
- return ("Verify (12) [6.2.11]");
- break;
- case 0x0a:
- return ("Write, Send (6) [6.1.17, 9.2]");
- break;
- case 0x2a:
- return ("Write (10) [6.1.18]");
- break;
- case 0xaa:
- return ("Write (12) [6.2.13]");
- break;
- case 0x2e:
- return ("Write and Verify (10) [6.1.19, 6.2.14]");
- break;
- case 0xae:
- return ("Write and Verify (12) [6.1.19, 6.2.15]");
- break;
- case 0x03b:
- return ("Write Buffer [7.25]");
- break;
- case 0x03f:
- return ("Write Long [6.1.20]");
- break;
- case 0x041:
- return ("Write Same [6.1.21]");
- break;
- case 0x052:
- return ("XD Read [6.1.22]");
- break;
- case 0x050:
- return ("XD Write [6.1.22]");
- break;
- case 0x080:
- return ("XD Write Extended [6.1.22]");
- break;
- case 0x051:
- return ("XO Write [6.1.22]");
- break;
- default:
- return ("Unknown SCSI Command");
- }
-}
-
-/* End of the DPT driver */
-
-/**
- * Hello emacs, these are the
- * Local Variables:
- * c-indent-level: 8
- * c-continued-statement-offset: 8
- * c-continued-brace-offset: 0
- * c-brace-offset: -8
- * c-brace-imaginary-offset: 0
- * c-argdecl-indent: 8
- * c-label-offset: -8
- * c++-hanging-braces: 1
- * c++-access-specifier-offset: -8
- * c++-empty-arglist-indent: 8
- * c++-friend-offset: 0
- * End:
- */
-
-
OpenPOWER on IntegriCloud