コード例 #1
0
ファイル: sfxge.c プロジェクト: Karamax/arrakis
// pravin: called from device_attach (sfxge_attach)
static errval_t
sfxge_create(struct sfxge_softc *sc)
{
    efx_nic_t *enp;
    errval_t err = SYS_ERR_OK;
    int error = 0;

    // Create the common code nic object.
    //mtx_init(&sc->enp_lock, "sfxge_nic", NULL, MTX_DEF);
    if ((error = efx_nic_create(sc->family, (efsys_identifier_t *)sc,
        &sc->bar, &sc->enp_lock, &enp)) != 0) {
        printf("efx_nic_create failed\n");
        abort();
    }

    sc->enp = enp;

    // Initialize MCDI to talk to the microcontroller.
    err = sfxge_mcdi_init(sc);
    if (err_is_fail(err)) {
        printf("sfxge_mcdi_init failed\n");
        abort();
    }

    // Probe the NIC and build the configuration data area.
    int status = efx_nic_probe(enp);
    if (status != 0) {
        printf("efx_nic_probe failed\n");
        abort();
    }

    // Initialize the NVRAM.
    if ((error = efx_nvram_init(enp)) != 0) {
        printf("efx_nvram_init failed\n");
        abort();
    }

    // Initialize the VPD.
    if ((error = efx_vpd_init(enp)) != 0) {
        printf("efx_vpd_init failed\n");
        abort();
    }

    // Reset the NIC.
    if ((error = efx_nic_reset(enp)) != 0) {
        printf("efx_nic_reset failed\n");
        abort();
    }

    return err;
} // end function: sfxge_create
コード例 #2
0
ファイル: sfxge.c プロジェクト: AhmadTux/freebsd
static int
sfxge_create(struct sfxge_softc *sc)
{
	device_t dev;
	efx_nic_t *enp;
	int error;

	dev = sc->dev;

	sx_init(&sc->softc_lock, "sfxge_softc");

	sc->stats_node = SYSCTL_ADD_NODE(
		device_get_sysctl_ctx(dev),
		SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
		OID_AUTO, "stats", CTLFLAG_RD, NULL, "Statistics");
	if (!sc->stats_node) {
		error = ENOMEM;
		goto fail;
	}

	TASK_INIT(&sc->task_reset, 0, sfxge_reset, sc);

	(void) pci_enable_busmaster(dev);

	/* Initialize DMA mappings. */
	if ((error = sfxge_dma_init(sc)) != 0)
		goto fail;

	/* Map the device registers. */
	if ((error = sfxge_bar_init(sc)) != 0)
		goto fail;

	error = efx_family(pci_get_vendor(dev), pci_get_device(dev),
	    &sc->family);
	KASSERT(error == 0, ("Family should be filtered by sfxge_probe()"));

	/* Create the common code nic object. */
	mtx_init(&sc->enp_lock, "sfxge_nic", NULL, MTX_DEF);
	if ((error = efx_nic_create(sc->family, (efsys_identifier_t *)sc,
	    &sc->bar, &sc->enp_lock, &enp)) != 0)
		goto fail3;
	sc->enp = enp;

	/* Initialize MCDI to talk to the microcontroller. */
	if ((error = sfxge_mcdi_init(sc)) != 0)
		goto fail4;

	/* Probe the NIC and build the configuration data area. */
	if ((error = efx_nic_probe(enp)) != 0)
		goto fail5;

	/* Initialize the NVRAM. */
	if ((error = efx_nvram_init(enp)) != 0)
		goto fail6;

	/* Initialize the VPD. */
	if ((error = efx_vpd_init(enp)) != 0)
		goto fail7;

	/* Reset the NIC. */
	if ((error = efx_nic_reset(enp)) != 0)
		goto fail8;

	/* Initialize buffer table allocation. */
	sc->buffer_table_next = 0;

	/* Set up interrupts. */
	if ((error = sfxge_intr_init(sc)) != 0)
		goto fail8;

	/* Initialize event processing state. */
	if ((error = sfxge_ev_init(sc)) != 0)
		goto fail11;

	/* Initialize receive state. */
	if ((error = sfxge_rx_init(sc)) != 0)
		goto fail12;

	/* Initialize transmit state. */
	if ((error = sfxge_tx_init(sc)) != 0)
		goto fail13;

	/* Initialize port state. */
	if ((error = sfxge_port_init(sc)) != 0)
		goto fail14;

	sc->init_state = SFXGE_INITIALIZED;

	return (0);

fail14:
	sfxge_tx_fini(sc);

fail13:
	sfxge_rx_fini(sc);

fail12:
	sfxge_ev_fini(sc);

fail11:
	sfxge_intr_fini(sc);

fail8:
	efx_vpd_fini(enp);

fail7:
	efx_nvram_fini(enp);

fail6:
	efx_nic_unprobe(enp);

fail5:
	sfxge_mcdi_fini(sc);

fail4:
	sc->enp = NULL;
	efx_nic_destroy(enp);
	mtx_destroy(&sc->enp_lock);

fail3:
	sfxge_bar_fini(sc);
	(void) pci_disable_busmaster(sc->dev);

fail:
	sc->dev = NULL;
	sx_destroy(&sc->softc_lock);
	return (error);
}