FreeBSD/sys/dev/sn/if_sn.c
/*
 * Function: sn_probe(device_t dev)
 *
 * Purpose:
 *      Tests to see if a given ioaddr points to an SMC9xxx chip.
 *      Tries to cause as little damage as possible if it's not a SMC chip.
 *      Returns a 0 on success
 *
 * Algorithm:
 *      (1) see if the high byte of BANK_SELECT is 0x33
 *      (2) compare the ioaddr with the base register's address
 *      (3) see if I recognize the chip ID in the appropriate register
 *
 *
 */
sn_probe(device_t dev)
Purpose:
Tests to see if a given ioaddr points to an SMC9xxx chip.
Tries to cause as little damage as possible if it's not a SMC chip.
Returns a 0 on success

(1) see if the high byte of BANK_SELECT is 0x33
(2) compare the ioaddr with the base register's address
(3) see if I recognize the chip ID in the appropriate register
sn_probe ( device_t dev ) Purpose : Tests to see if a given ioaddr points to an SMC9xxx chip . Tries to cause as little damage as possible if it ' s not a SMC chip . Returns a 0 on success ( 1 ) see if the high byte of BANK_SELECT is 0x33 ( 2 ) compare the ioaddr with the base register ' s address ( 3 ) see if I recognize the chip ID in the appropriate register
int 
sn_probe(device_t dev)
{
	struct sn_softc *sc = device_get_softc(dev);
	uint16_t        bank;
	uint16_t        revision_register;
	uint16_t        base_address_register;
	int		err;
	if ((err = sn_activate(dev)) != 0)
		return err;
	bank = CSR_READ_2(sc, BANK_SELECT_REG_W);
	if ((bank & BSR_DETECT_MASK) != BSR_DETECT_VALUE) {
#ifdef	SN_DEBUG
		device_printf(dev, "test1 failed\n");
#endif
		goto error;
	}
	CSR_WRITE_2(sc, BANK_SELECT_REG_W, 0x0000);
	bank = CSR_READ_2(sc, BANK_SELECT_REG_W);
	if ((bank & BSR_DETECT_MASK) != BSR_DETECT_VALUE) {
#ifdef	SN_DEBUG
		device_printf(dev, "test2 failed\n");
#endif
		goto error;
	}
	CSR_WRITE_2(sc, BANK_SELECT_REG_W, 0x0001);
	base_address_register = (CSR_READ_2(sc, BASE_ADDR_REG_W) >> 3) & 0x3e0;
	if (rman_get_start(sc->port_res) != base_address_register) {
#ifdef	SN_DEBUG
		device_printf(dev, "test3 failed ioaddr = 0x%x, "
		    "base_address_register = 0x%x\n",
		    rman_get_start(sc->port_res), base_address_register);
#endif
		goto error;
	}
	CSR_WRITE_2(sc, BANK_SELECT_REG_W, 0x3);
	revision_register = CSR_READ_2(sc, REVISION_REG_W);
	if (!chip_ids[(revision_register >> 4) & 0xF]) {
#ifdef	SN_DEBUG
		device_printf(dev, "test4 failed\n");
#endif
		goto error;
	}
	sn_deactivate(dev);
	return 0;
 error:
	sn_deactivate(dev);
	return ENXIO;
}
int sn_probe ( device_t dev ) { struct sn_softc * sc = device_get_softc ( dev ) ; uint16_t bank ; uint16_t revision_register ; uint16_t base_address_register ; int err ; if ( ( err = sn_activate ( dev ) ) != 0 ) return err ; bank = CSR_READ_2 ( sc , BANK_SELECT_REG_W ) ; if ( ( bank & BSR_DETECT_MASK ) != BSR_DETECT_VALUE ) { #ifdef SN_DEBUG device_printf ( dev , " \n " ) ; #endif goto error ; } CSR_WRITE_2 ( sc , BANK_SELECT_REG_W , 0x0000 ) ; bank = CSR_READ_2 ( sc , BANK_SELECT_REG_W ) ; if ( ( bank & BSR_DETECT_MASK ) != BSR_DETECT_VALUE ) { #ifdef SN_DEBUG device_printf ( dev , " \n " ) ; #endif goto error ; } CSR_WRITE_2 ( sc , BANK_SELECT_REG_W , 0x0001 ) ; base_address_register = ( CSR_READ_2 ( sc , BASE_ADDR_REG_W ) >> 3 ) & 0x3e0 ; if ( rman_get_start ( sc -> port_res ) != base_address_register ) { #ifdef SN_DEBUG device_printf ( dev , " " " \n " , rman_get_start ( sc -> port_res ) , base_address_register ) ; #endif goto error ; } CSR_WRITE_2 ( sc , BANK_SELECT_REG_W , 0x3 ) ; revision_register = CSR_READ_2 ( sc , REVISION_REG_W ) ; if ( ! chip_ids [ ( revision_register >> 4 ) & 0xF ] ) { #ifdef SN_DEBUG device_printf ( dev , " \n " ) ; #endif goto error ; } sn_deactivate ( dev ) ; return 0 ; error : sn_deactivate ( dev ) ; return ENXIO ; }
Function: sn_probe(device_t dev)
 Purpose:
      Tests to see if a given ioaddr points to an SMC9xxx chip.
Function : sn_probe ( device_t dev ) Purpose : Tests to see if a given ioaddr points to an SMC9xxx chip .
/*
	 * First, see if the high byte is 0x33
	 */ /*
	 * The above MIGHT indicate a device, but I need to write to further
	 * test this.  Go to bank 0, then test that the register still
	 * reports the high byte is 0x33.
	 */ /*
	 * well, we've already written once, so hopefully another time won't
	 * hurt.  This time, I need to switch the bank register to bank 1, so
	 * I can access the base address register.  The contents of the
	 * BASE_ADDR_REG_W register, after some jiggery pokery, is expected
	 * to match the I/O port address where the adapter is being probed.
	 */ /*
		 * Well, the base address register didn't match.  Must not
		 * have been a SMC chip after all.
		 */ /*
	 * Check if the revision register is something that I recognize.
	 * These might need to be added to later, as future revisions could
	 * be added.
	 */ /*
		 * I don't regonize this chip, so...
		 */ /*
	 * at this point I'll assume that the chip is an SMC9xxx. It might be
	 * prudent to check a listing of MAC addresses against the hardware
	 * address, or do some other tests.
	 */