if_nf10bmac_fdt.c revision 264601
1/*- 2 * Copyright (c) 2013-2014 Bjoern A. Zeeb 3 * All rights reserved. 4 * 5 * This software was developed by SRI International and the University of 6 * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 7 * ("MRC2"), as part of the DARPA MRC research programme. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * This driver is modelled after atse(4). We need to seriously reduce the 31 * per-driver code we have to write^wcopy & paste. 32 */ 33 34#include <sys/cdefs.h> 35__FBSDID("$FreeBSD: head/sys/dev/netfpga10g/nf10bmac/if_nf10bmac_fdt.c 264601 2014-04-17 12:33:26Z bz $"); 36 37#include <sys/param.h> 38#include <sys/bus.h> 39#include <sys/kernel.h> 40#include <sys/module.h> 41#include <sys/rman.h> 42#include <sys/socket.h> 43#include <sys/systm.h> 44 45#include <machine/bus.h> 46#include <machine/resource.h> 47 48#include <net/ethernet.h> 49#include <net/if.h> 50#include <net/if_media.h> 51#include <net/if_var.h> 52 53#include <dev/fdt/fdt_common.h> 54#include <dev/ofw/openfirm.h> 55#include <dev/ofw/ofw_bus.h> 56#include <dev/ofw/ofw_bus_subr.h> 57 58#include "if_nf10bmacreg.h" 59 60static int 61nf10bmac_probe_fdt(device_t dev) 62{ 63 64 if (!ofw_bus_status_okay(dev)) 65 return (ENXIO); 66 67 if (ofw_bus_is_compatible(dev, "netfpag10g,nf10bmac")) { 68 device_set_desc(dev, "NetFPGA-10G Embedded CPU Ethernet Core"); 69 return (BUS_PROBE_DEFAULT); 70 } 71 72 return (ENXIO); 73} 74 75static int 76nf10bmac_attach_fdt(device_t dev) 77{ 78 struct nf10bmac_softc *sc; 79 int error; 80 81 sc = device_get_softc(dev); 82 sc->nf10bmac_dev = dev; 83 sc->nf10bmac_unit = device_get_unit(dev); 84 85 /* 86 * FDT lists our resources. For convenience we use three different 87 * mappings. We need to attach them in the oder specified in .dts: 88 * TX (size 0xc), RX (size 0xc), LOOP (size 0x4). 89 */ 90 91 /* 92 * TX and TX metadata FIFO memory region. 93 * 0x00: 32bit FIFO data, 94 * 0x04: 32bit FIFO metadata, 95 * 0x08: 32bit packet length. 96 */ 97 sc->nf10bmac_tx_mem_rid = 0; 98 sc->nf10bmac_tx_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 99 &sc->nf10bmac_tx_mem_rid, RF_ACTIVE); 100 if (sc->nf10bmac_tx_mem_res == NULL) { 101 device_printf(dev, "failed to map memory for TX FIFO\n"); 102 error = ENXIO; 103 goto err; 104 } 105 if (bootverbose) 106 device_printf(sc->nf10bmac_dev, "TX FIFO at mem %p-%p\n", 107 (void *)rman_get_start(sc->nf10bmac_tx_mem_res), 108 (void *)(rman_get_start(sc->nf10bmac_tx_mem_res) + 109 rman_get_size(sc->nf10bmac_tx_mem_res))); 110 111 /* 112 * RX and RXC metadata FIFO memory region. 113 * 0x00: 32bit FIFO data, 114 * 0x04: 32bit FIFO metadata, 115 * 0x08: 32bit packet length. 116 */ 117 sc->nf10bmac_rx_mem_rid = 1; 118 sc->nf10bmac_rx_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 119 &sc->nf10bmac_rx_mem_rid, RF_ACTIVE); 120 if (sc->nf10bmac_rx_mem_res == NULL) { 121 device_printf(dev, "failed to map memory for RX FIFO\n"); 122 error = ENXIO; 123 goto err; 124 } 125 if (bootverbose) 126 device_printf(sc->nf10bmac_dev, "RX FIFO at mem %p-%p\n", 127 (void *)rman_get_start(sc->nf10bmac_rx_mem_res), 128 (void *)(rman_get_start(sc->nf10bmac_rx_mem_res) + 129 rman_get_size(sc->nf10bmac_rx_mem_res))); 130 131 /* 132 * LOOP memory region (this could be a general control region). 133 * 0x00: 32bit register to enable a Y-"lopback". 134 */ 135 sc->nf10bmac_mem_rid = 2; 136 sc->nf10bmac_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 137 &sc->nf10bmac_mem_rid, RF_ACTIVE); 138 if (sc->nf10bmac_mem_res == NULL) { 139 device_printf(dev, "failed to map memory for CTRL region\n"); 140 error = ENXIO; 141 goto err; 142 } 143 if (bootverbose) 144 device_printf(sc->nf10bmac_dev, "CTRL region at mem %p-%p\n", 145 (void *)rman_get_start(sc->nf10bmac_mem_res), 146 (void *)(rman_get_start(sc->nf10bmac_mem_res) + 147 rman_get_size(sc->nf10bmac_mem_res))); 148 149 error = nf10bmac_attach(dev); 150 if (error) 151 goto err; 152 153 return (0); 154 155err: 156 /* Cleanup. */ 157 nf10bmac_detach_resources(dev); 158 159 return (error); 160} 161 162static device_method_t nf10bmac_methods_fdt[] = { 163 /* Device interface */ 164 DEVMETHOD(device_probe, nf10bmac_probe_fdt), 165 DEVMETHOD(device_attach, nf10bmac_attach_fdt), 166 DEVMETHOD(device_detach, nf10bmac_detach_dev), 167 168 DEVMETHOD_END 169}; 170 171static driver_t nf10bmac_driver_fdt = { 172 "nf10bmac", 173 nf10bmac_methods_fdt, 174 sizeof(struct nf10bmac_softc) 175}; 176 177DRIVER_MODULE(nf10bmac, simplebus, nf10bmac_driver_fdt, nf10bmac_devclass, 0,0); 178 179/* end */ 180