socsvn commit: r287699 - soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve

iateaca at FreeBSD.org iateaca at FreeBSD.org
Sun Jun 28 15:59:28 UTC 2015


Author: iateaca
Date: Sun Jun 28 15:59:27 2015
New Revision: 287699
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=287699

Log:
  implement some logging and asserting related with the receive buffer ring

Modified:
  soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_ne2000.c

Modified: soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_ne2000.c
==============================================================================
--- soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_ne2000.c	Sun Jun 28 12:52:28 2015	(r287698)
+++ soc2015/iateaca/bhyve-ne2000-head/usr.sbin/bhyve/pci_ne2000.c	Sun Jun 28 15:59:27 2015	(r287699)
@@ -131,6 +131,9 @@
 ne2000_tap_callback(int fd, enum ev_type type, void *param);
 
 static int
+ne2000_receive_ring_is_valid(struct pci_ne2000_softc *sc);
+
+static int
 ne2000_parse_input(char *opts, char *tap_name, uint8_t *mac);
 
 /*
@@ -260,6 +263,31 @@
 }
 
 static int
+ne2000_receive_ring_is_valid(struct pci_ne2000_softc *sc)
+{
+	uint8_t pstart = 0;
+	uint8_t pstop = 0;
+
+	uint8_t curr = 0;
+	uint8_t bnry = 0;
+
+	pstart = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_PSTART);
+	pstop = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_PSTOP);
+
+	curr = ne2000_get_reg_by_offset(sc, NE2000_P1, ED_P1_CURR);
+	bnry = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_BNRY);
+
+	if (pstart == 0 || pstop == 0)
+		return 0;
+	if (curr < pstart || curr >= pstop)
+		return 0;
+	if (bnry < pstart || bnry >= pstop)
+		return 0;
+
+	return 1;
+}
+
+static int
 ne2000_parse_input(char *opts, char *tap_name, uint8_t *mac)
 {
 	uint8_t len = 0;
@@ -442,6 +470,9 @@
 	uint16_t rbcr = 0;
 	uint16_t rsar = 0;
 
+	uint8_t pstart = 0;
+	uint8_t pstop = 0;
+
 	switch (offset) {
 	case ED_NOVELL_RESET:
 		sc->reset = value;
@@ -469,6 +500,15 @@
 
 		assert(rsar < NE2000_MEM_SIZE);
 
+		if (ne2000_receive_ring_is_valid(sc)) {
+			pstart = ne2000_get_reg_by_offset(sc, NE2000_P0,
+					ED_P0_PSTART);
+			pstop = ne2000_get_reg_by_offset(sc, NE2000_P0,
+					ED_P0_PSTOP);
+			assert(rsar + 1 < pstart * ED_PAGE_SIZE ||
+					rsar >= pstop * ED_PAGE_SIZE);
+		}
+
 		/* copy the value in LOW - HIGH order */
 		sc->ram[rsar]     = value;
 		sc->ram[rsar + 1] = value >> 8;
@@ -515,6 +555,9 @@
 	uint16_t tbcr = 0;
 	uint8_t tpsr = 0;
 
+	uint8_t pstart = 0;
+	uint8_t pstop = 0;
+
 	switch (offset) {
 	case ED_P0_CR:
 		if (value & ED_CR_STP) {
@@ -562,6 +605,20 @@
 			assert(err == 0);
 		}
 		break;
+	case ED_P0_PSTART:
+		DPRINTF("Page Start Register: %d", value);
+		assert(value > 0 && value * ED_PAGE_SIZE < NE2000_MEM_SIZE);
+		break;
+	case ED_P0_PSTOP:
+		DPRINTF("Page Stop Register: %d", value);
+		assert(value > 0 && value * ED_PAGE_SIZE <= NE2000_MEM_SIZE);
+		break;
+	case ED_P0_BNRY:
+		DPRINTF("Boundary Register: %d", value);
+		pstart = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_PSTART);
+		pstop = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_PSTOP);
+		assert(value >= pstart && value < pstop);
+		break;
 	case ED_P0_ISR:
 		ne2000_set_field_by_offset(sc, NE2000_P0, ED_P0_ISR, value, 0);
 		pci_ne2000_update_intr(sc);
@@ -575,8 +632,17 @@
 ne2000_emul_reg_page1(struct pci_ne2000_softc *sc, uint8_t offset,
 		uint8_t value)
 {
+	uint8_t pstart = 0;
+	uint8_t pstop = 0;
+
 	if (offset == ED_P1_CR)
 		return ne2000_emul_reg_page0(sc, offset, value);
+	else if (offset == ED_P1_CURR) {
+		DPRINTF("Current Page Register: %d", value);
+		pstart = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_PSTART);
+		pstop = ne2000_get_reg_by_offset(sc, NE2000_P0, ED_P0_PSTOP);
+		assert(value >= pstart && value < pstop);
+	}
 
 	return 0;
 }


More information about the svn-soc-all mailing list