Module Name:    src
Committed By:   thorpej
Date:           Mon Jul 26 16:45:56 UTC 2021

Modified Files:
        src/sys/dev/eisa: ahb.c ahbreg.h

Log Message:
- Type hygiene.
- Rename ahb_ecb::hashkey to ahb_ecb::ecb_dma_addr, and use that value
  rather than recomputing it all the time.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/eisa/ahb.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/eisa/ahbreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/eisa/ahb.c
diff -u src/sys/dev/eisa/ahb.c:1.67 src/sys/dev/eisa/ahb.c:1.68
--- src/sys/dev/eisa/ahb.c:1.67	Sat Jul 24 15:52:16 2021
+++ src/sys/dev/eisa/ahb.c	Mon Jul 26 16:45:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahb.c,v 1.67 2021/07/24 15:52:16 thorpej Exp $	*/
+/*	$NetBSD: ahb.c,v 1.68 2021/07/26 16:45:56 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahb.c,v 1.67 2021/07/24 15:52:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahb.c,v 1.68 2021/07/26 16:45:56 thorpej Exp $");
 
 #include "opt_ddb.h"
 
@@ -108,7 +108,7 @@ struct ahb_softc {
 /*
  * Offset of an ECB from the beginning of the ECB DMA mapping.
  */
-#define	AHB_ECB_OFF(e)	(((u_long)(e)) - ((u_long)&sc->sc_ecbs[0]))
+#define	AHB_ECB_OFF(e)	(((uintptr_t)(e)) - ((uintptr_t)&sc->sc_ecbs[0]))
 
 struct ahb_probe_data {
 	int sc_irq;
@@ -121,7 +121,7 @@ static void	ahb_send_immed(struct ahb_so
 static int	ahbintr(void *);
 static void	ahb_free_ecb(struct ahb_softc *, struct ahb_ecb *);
 static struct	ahb_ecb *ahb_get_ecb(struct ahb_softc *);
-static struct	ahb_ecb *ahb_ecb_phys_kv(struct ahb_softc *, physaddr);
+static struct	ahb_ecb *ahb_ecb_phys_kv(struct ahb_softc *, uint32_t);
 static void	ahb_done(struct ahb_softc *, struct ahb_ecb *);
 static int	ahb_find(bus_space_tag_t, bus_space_handle_t,
 		    struct ahb_probe_data *);
@@ -294,12 +294,7 @@ ahb_send_mbox(struct ahb_softc *sc, int 
 		Debugger();
 	}
 
-	/*
-	 * don't know if this will work.
-	 * XXX WHAT DOES THIS COMMENT MEAN?!  --thorpej
-	 */
-	bus_space_write_4(iot, ioh, MBOXOUT0,
-	    sc->sc_dmamap_ecb->dm_segs[0].ds_addr + AHB_ECB_OFF(ecb));
+	bus_space_write_4(iot, ioh, MBOXOUT0, ecb->ecb_dma_addr);
 	bus_space_write_1(iot, ioh, ATTN, opcode |
 		ecb->xs->xs_periph->periph_target);
 
@@ -309,7 +304,7 @@ ahb_send_mbox(struct ahb_softc *sc, int 
 }
 
 /*
- * Function to  send an immediate type command to the adapter
+ * Function to send an immediate type command to the adapter
  */
 static void
 ahb_send_immed(struct ahb_softc *sc, u_int32_t cmd, struct ahb_ecb *ecb)
@@ -454,13 +449,14 @@ ahb_init_ecb(struct ahb_softc *sc, struc
 		return (error);
 	}
 
+	ecb->ecb_dma_addr = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
+	    AHB_ECB_OFF(ecb);
+
 	/*
 	 * put in the phystokv hash table
 	 * Never gets taken out.
 	 */
-	ecb->hashkey = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
-	    AHB_ECB_OFF(ecb);
-	hashnum = ECB_HASH(ecb->hashkey);
+	hashnum = ECB_HASH(ecb->ecb_dma_addr);
 	ecb->nexthash = sc->sc_ecbhash[hashnum];
 	sc->sc_ecbhash[hashnum] = ecb;
 	ahb_reset_ecb(sc, ecb);
@@ -513,13 +509,13 @@ ahb_get_ecb(struct ahb_softc *sc)
  * given a physical address, find the ecb that it corresponds to.
  */
 static struct ahb_ecb *
-ahb_ecb_phys_kv(struct ahb_softc *sc, physaddr ecb_phys)
+ahb_ecb_phys_kv(struct ahb_softc *sc, uint32_t ecb_phys)
 {
 	int hashnum = ECB_HASH(ecb_phys);
 	struct ahb_ecb *ecb = sc->sc_ecbhash[hashnum];
 
 	while (ecb) {
-		if (ecb->hashkey == ecb_phys)
+		if (ecb->ecb_dma_addr == ecb_phys)
 			break;
 		ecb = ecb->nexthash;
 	}
@@ -867,11 +863,11 @@ ahb_scsipi_request(struct scsipi_channel
 		ecb->opt2 = periph->periph_lun | ECB_NRB;
 		memcpy(&ecb->scsi_cmd, xs->cmd,
 		    ecb->scsi_cmd_length = xs->cmdlen);
-		ecb->sense_ptr = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
-		    AHB_ECB_OFF(ecb) + offsetof(struct ahb_ecb, ecb_sense);
+		ecb->sense_ptr = ecb->ecb_dma_addr +
+		    offsetof(struct ahb_ecb, ecb_sense);
 		ecb->req_sense_length = sizeof(ecb->ecb_sense);
-		ecb->status = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
-		    AHB_ECB_OFF(ecb) + offsetof(struct ahb_ecb, ecb_status);
+		ecb->status = ecb->ecb_dma_addr +
+		    offsetof(struct ahb_ecb, ecb_status);
 		ecb->ecb_status.host_stat = 0x00;
 		ecb->ecb_status.target_stat = 0x00;
 
@@ -927,17 +923,16 @@ ahb_scsipi_request(struct scsipi_channel
 				    ecb->dmamap_xfer->dm_segs[seg].ds_len;
 			}
 
-			ecb->data_addr = sc->sc_dmamap_ecb->dm_segs[0].ds_addr +
-			    AHB_ECB_OFF(ecb) +
+			ecb->data_addr = ecb->ecb_dma_addr +
 			    offsetof(struct ahb_ecb, ahb_dma);
 			ecb->data_length = ecb->dmamap_xfer->dm_nsegs *
 			    sizeof(struct ahb_dma_seg);
 			ecb->opt1 |= ECB_S_G;
 		} else {	/* No data xfer, use non S/G values */
-			ecb->data_addr = (physaddr)0;
+			ecb->data_addr = 0;
 			ecb->data_length = 0;
 		}
-		ecb->link_addr = (physaddr)0;
+		ecb->link_addr = 0;
 
 		bus_dmamap_sync(sc->sc_dmat, sc->sc_dmamap_ecb,
 		    AHB_ECB_OFF(ecb), sizeof(struct ahb_ecb),

Index: src/sys/dev/eisa/ahbreg.h
diff -u src/sys/dev/eisa/ahbreg.h:1.17 src/sys/dev/eisa/ahbreg.h:1.18
--- src/sys/dev/eisa/ahbreg.h:1.17	Sat Jul 24 15:44:16 2021
+++ src/sys/dev/eisa/ahbreg.h	Mon Jul 26 16:45:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ahbreg.h,v 1.17 2021/07/24 15:44:16 thorpej Exp $	*/
+/*	$NetBSD: ahbreg.h,v 1.18 2021/07/26 16:45:56 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -45,9 +45,6 @@
  * functioning of this software in any circumstances.
  */
 
-typedef u_int32_t physaddr;
-typedef u_int32_t physlen;
-
 /*
  * Offset of AHA1740 registers, relative from slot base.
  */
@@ -133,12 +130,12 @@ typedef u_int32_t physlen;
 #define	AHB_NSEG	33	/* number of DMA segments supported */
 
 struct ahb_dma_seg {
-	physaddr seg_addr;
-	physlen seg_len;
+	uint32_t seg_addr;
+	uint32_t seg_len;
 };
 
 struct ahb_ecb_status {
-	u_short status;
+	uint16_t status;
 #define	ST_DON	0x0001
 #define	ST_DU	0x0002
 #define	ST_QF	0x0008
@@ -151,7 +148,7 @@ struct ahb_ecb_status {
 #define	ST_INI	0x0800
 #define	ST_ME	0x1000
 #define	ST_ECA	0x4000
-	u_char  host_stat;
+	uint8_t  host_stat;
 #define	HS_OK			0x00
 #define	HS_CMD_ABORTED_HOST	0x04
 #define	HS_CMD_ABORTED_ADAPTER	0x05
@@ -159,29 +156,29 @@ struct ahb_ecb_status {
 #define	HS_HARDWARE_ERR		0x20
 #define	HS_SCSI_RESET_ADAPTER	0x22
 #define	HS_SCSI_RESET_INCOMING	0x23
-	u_char  target_stat;
-	u_int32_t  resid_count;
-	u_int32_t  resid_addr;
-	u_short addit_status;
-	u_char  sense_len;
-	u_char  unused[9];
-	u_char  cdb[6];
+	uint8_t  target_stat;
+	uint32_t  resid_count;
+	uint32_t  resid_addr;
+	uint16_t addit_status;
+	uint8_t  sense_len;
+	uint8_t  unused[9];
+	uint8_t  cdb[6];
 };
 
 struct ahb_ecb {
-	u_char  opcode;
+	uint8_t  opcode;
 #define	ECB_SCSI_OP	0x01
-	        u_char:4;
-	u_char  options:3;
-	        u_char:1;
-	short   opt1;
+	        uint8_t:4;
+	uint8_t  options:3;
+	        uint8_t:1;
+	uint16_t opt1;
 #define	ECB_CNE	0x0001
 #define	ECB_DI	0x0080
 #define	ECB_SES	0x0400
 #define	ECB_S_G	0x1000
 #define	ECB_DSB	0x4000
 #define	ECB_ARS	0x8000
-	short   opt2;
+	uint16_t opt2;
 #define	ECB_LUN	0x0007
 #define	ECB_TAG	0x0008
 #define	ECB_TT	0x0030
@@ -192,18 +189,18 @@ struct ahb_ecb {
 #define	ECB_CHK	0x0800
 #define	ECB_REC	0x4000
 #define	ECB_NRB	0x8000
-	u_short unused1;
-	physaddr data_addr;
-	physlen  data_length;
-	physaddr status;
-	physaddr link_addr;
-	short   unused2;
-	short   unused3;
-	physaddr sense_ptr;
-	u_char  req_sense_length;
-	u_char  scsi_cmd_length;
-	short   cksum;
-	u_char	scsi_cmd[12];
+	uint16_t unused1;
+	uint32_t data_addr;
+	uint32_t data_length;
+	uint32_t status;
+	uint32_t link_addr;
+	uint16_t unused2;
+	uint16_t unused3;
+	uint32_t sense_ptr;
+	uint8_t  req_sense_length;
+	uint8_t  scsi_cmd_length;
+	uint16_t cksum;
+	uint8_t	scsi_cmd[12];
 
 	/*-----------------end of hardware supported fields----------------*/
 
@@ -213,7 +210,7 @@ struct ahb_ecb {
 
 	TAILQ_ENTRY(ahb_ecb) chain;
 	struct ahb_ecb *nexthash;
-	int32_t hashkey;
+	uint32_t ecb_dma_addr;
 	struct scsipi_xfer *xs;	/* the scsipi_xfer for this cmd */
 	int flags;
 #define	ECB_ALLOC	0x01

Reply via email to