| 884 | } |
| 885 | |
| 886 | static int |
| 887 | emac_attach(device_t dev) |
| 888 | { |
| 889 | struct emac_softc *sc; |
| 890 | struct ifnet *ifp; |
| 891 | int error, rid; |
| 892 | uint8_t eaddr[ETHER_ADDR_LEN]; |
| 893 | |
| 894 | sc = device_get_softc(dev); |
| 895 | sc->emac_dev = dev; |
| 896 | |
| 897 | error = 0; |
| 898 | mtx_init(&sc->emac_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, |
| 899 | MTX_DEF); |
| 900 | callout_init_mtx(&sc->emac_tick_ch, &sc->emac_mtx, 0); |
| 901 | |
| 902 | rid = 0; |
| 903 | sc->emac_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, |
| 904 | RF_ACTIVE); |
| 905 | if (sc->emac_res == NULL) { |
| 906 | device_printf(dev, "unable to map memory\n"); |
| 907 | error = ENXIO; |
| 908 | goto fail; |
| 909 | } |
| 910 | |
| 911 | sc->emac_tag = rman_get_bustag(sc->emac_res); |
| 912 | sc->emac_handle = rman_get_bushandle(sc->emac_res); |
| 913 | |
| 914 | rid = 0; |
| 915 | sc->emac_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, |
| 916 | RF_SHAREABLE | RF_ACTIVE); |
| 917 | if (sc->emac_irq == NULL) { |
| 918 | device_printf(dev, "cannot allocate IRQ resources.\n"); |
| 919 | error = ENXIO; |
| 920 | goto fail; |
| 921 | } |
| 922 | /* Create device sysctl node. */ |
| 923 | SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), |
| 924 | SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), |
| 925 | OID_AUTO, "process_limit", |
| 926 | CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, |
| 927 | &sc->emac_rx_process_limit, 0, sysctl_hw_emac_proc_limit, "I", |
| 928 | "max number of Rx events to process"); |
| 929 | |
| 930 | sc->emac_rx_process_limit = EMAC_PROC_DEFAULT; |
| 931 | error = resource_int_value(device_get_name(dev), device_get_unit(dev), |
| 932 | "process_limit", &sc->emac_rx_process_limit); |
| 933 | if (error == 0) { |
| 934 | if (sc->emac_rx_process_limit < EMAC_PROC_MIN || |
| 935 | sc->emac_rx_process_limit > EMAC_PROC_MAX) { |
| 936 | device_printf(dev, "process_limit value out of range; " |
| 937 | "using default: %d\n", EMAC_PROC_DEFAULT); |
| 938 | sc->emac_rx_process_limit = EMAC_PROC_DEFAULT; |
| 939 | } |
| 940 | } |
| 941 | /* Setup EMAC */ |
| 942 | error = emac_sys_setup(sc); |
| 943 | if (error != 0) |
nothing calls this directly
no test coverage detected