if_nf10bmac_fdt.c revision 303975
125401Sjb/*- 250476Speter * Copyright (c) 2013-2014 Bjoern A. Zeeb 31573Srgrimes * All rights reserved. 41573Srgrimes * 5262722Smarcel * This software was developed by SRI International and the University of 61573Srgrimes * Cambridge Computer Laboratory under DARPA/AFRL contract FA8750-11-C-0249 7251314Sed * ("MRC2"), as part of the DARPA MRC research programme. 8251314Sed * 9102697Stjr * Redistribution and use in source and binary forms, with or without 10102697Stjr * modification, are permitted provided that the following conditions 11251314Sed * are met: 12132497Stjr * 1. Redistributions of source code must retain the above copyright 13139922Stjr * notice, this list of conditions and the following disclaimer. 14139922Stjr * 2. Redistributions in binary form must reproduce the above copyright 15136609Stjr * notice, this list of conditions and the following disclaimer in the 16121845Stjr * documentation and/or other materials provided with the distribution. 17136604Stjr * 18132497Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19112177Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20112177Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21103218Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22103793Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23227753Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24227753Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26251314Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27251314Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28251314Sed * SUCH DAMAGE. 29251314Sed * 30251314Sed * This driver is modelled after atse(4). We need to seriously reduce the 31251314Sed * per-driver code we have to write^wcopy & paste. 32262722Smarcel */ 33156613Sdeischen 34101305Sbde#include <sys/cdefs.h> 35232935Stheraven__FBSDID("$FreeBSD: releng/11.0/sys/dev/netfpga10g/nf10bmac/if_nf10bmac_fdt.c 267923 2014-06-26 17:26:33Z bz $"); 36101305Sbde 37127608Stjr#include <sys/param.h> 38127608Stjr#include <sys/bus.h> 39238781Sissyl0#include <sys/kernel.h> 40238781Sissyl0#include <sys/module.h> 41123222Stjr#include <sys/rman.h> 42136609Stjr#include <sys/socket.h> 43123222Stjr#include <sys/systm.h> 44139922Stjr 45104406Stjr#include <machine/bus.h> 46104406Stjr#include <machine/resource.h> 47103218Stjr 48123222Stjr#include <net/ethernet.h> 49227753Stheraven#include <net/if.h> 50227753Stheraven#include <net/if_media.h> 51227753Stheraven#include <net/if_var.h> 52136604Stjr 5330624Sbde#include <dev/fdt/fdt_common.h> 54101305Sbde#include <dev/ofw/openfirm.h> 5589255Sbde#include <dev/ofw/ofw_bus.h> 56238919Sissyl0#include <dev/ofw/ofw_bus_subr.h> 57238919Sissyl0 58238919Sissyl0#include "if_nf10bmacreg.h" 59238919Sissyl0 60238919Sissyl0static int 61101408Stjrnf10bmac_probe_fdt(device_t dev) 62101408Stjr{ 63127590Stjr 64101408Stjr if (!ofw_bus_status_okay(dev)) 65101408Stjr return (ENXIO); 66101408Stjr 67101408Stjr if (ofw_bus_is_compatible(dev, "netfpag10g,nf10bmac")) { 68238781Sissyl0 device_set_desc(dev, "NetFPGA-10G Embedded CPU Ethernet Core"); 69238781Sissyl0 return (BUS_PROBE_DEFAULT); 70238781Sissyl0 } 71238781Sissyl0 72238781Sissyl0 return (ENXIO); 73238781Sissyl0} 74238781Sissyl0 75238781Sissyl0static int 76238781Sissyl0nf10bmac_attach_fdt(device_t dev) 77238781Sissyl0{ 78238781Sissyl0 struct nf10bmac_softc *sc; 79238781Sissyl0 int error; 8089255Sbde 81250883Sed sc = device_get_softc(dev); 82132497Stjr sc->nf10bmac_dev = dev; 83250883Sed sc->nf10bmac_unit = device_get_unit(dev); 84132497Stjr 85112177Stjr /* 86103793Stjr * FDT lists our resources. For convenience we use three different 87103793Stjr * mappings. We need to attach them in the oder specified in .dts: 88101313Stjr * LOOP (size 0x1f), TX (0x2f), RX (0x2f), INTR (0xf). 89101253Stjr */ 90 91 /* 92 * LOOP memory region (this could be a general control region). 93 * 0x00: 32/64bit register to enable a Y-"lopback". 94 */ 95 sc->nf10bmac_ctrl_rid = 0; 96 sc->nf10bmac_ctrl_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 97 &sc->nf10bmac_ctrl_rid, RF_ACTIVE); 98 if (sc->nf10bmac_ctrl_res == NULL) { 99 device_printf(dev, "failed to map memory for CTRL region\n"); 100 error = ENXIO; 101 goto err; 102 } 103 if (bootverbose) 104 device_printf(sc->nf10bmac_dev, "CTRL region at mem %p-%p\n", 105 (void *)rman_get_start(sc->nf10bmac_ctrl_res), 106 (void *)(rman_get_start(sc->nf10bmac_ctrl_res) + 107 rman_get_size(sc->nf10bmac_ctrl_res))); 108 109 /* 110 * TX and TX metadata FIFO memory region. 111 * 0x00: 32/64bit FIFO data, 112 * 0x08: 32/64bit FIFO metadata, 113 * 0x10: 32/64bit packet length. 114 */ 115 sc->nf10bmac_tx_mem_rid = 1; 116 sc->nf10bmac_tx_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 117 &sc->nf10bmac_tx_mem_rid, RF_ACTIVE); 118 if (sc->nf10bmac_tx_mem_res == NULL) { 119 device_printf(dev, "failed to map memory for TX FIFO\n"); 120 error = ENXIO; 121 goto err; 122 } 123 if (bootverbose) 124 device_printf(sc->nf10bmac_dev, "TX FIFO at mem %p-%p\n", 125 (void *)rman_get_start(sc->nf10bmac_tx_mem_res), 126 (void *)(rman_get_start(sc->nf10bmac_tx_mem_res) + 127 rman_get_size(sc->nf10bmac_tx_mem_res))); 128 129 /* 130 * RX and RXC metadata FIFO memory region. 131 * 0x00: 32/64bit FIFO data, 132 * 0x08: 32/64bit FIFO metadata, 133 * 0x10: 32/64bit packet length. 134 */ 135 sc->nf10bmac_rx_mem_rid = 2; 136 sc->nf10bmac_rx_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 137 &sc->nf10bmac_rx_mem_rid, RF_ACTIVE); 138 if (sc->nf10bmac_rx_mem_res == NULL) { 139 device_printf(dev, "failed to map memory for RX FIFO\n"); 140 error = ENXIO; 141 goto err; 142 } 143 if (bootverbose) 144 device_printf(sc->nf10bmac_dev, "RX FIFO at mem %p-%p\n", 145 (void *)rman_get_start(sc->nf10bmac_rx_mem_res), 146 (void *)(rman_get_start(sc->nf10bmac_rx_mem_res) + 147 rman_get_size(sc->nf10bmac_rx_mem_res))); 148 149 /* 150 * Interrupt handling registers. 151 * 0x00: 32/64bit register to clear (and disable) the RX interrupt. 152 * 0x08: 32/64bit register to enable or disable the RX interrupt. 153 */ 154 sc->nf10bmac_intr_rid = 3; 155 sc->nf10bmac_intr_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 156 &sc->nf10bmac_intr_rid, RF_ACTIVE); 157 if (sc->nf10bmac_intr_res == NULL) { 158 device_printf(dev, "failed to map memory for INTR region\n"); 159 error = ENXIO; 160 goto err; 161 } 162 if (bootverbose) 163 device_printf(sc->nf10bmac_dev, "INTR region at mem %p-%p\n", 164 (void *)rman_get_start(sc->nf10bmac_intr_res), 165 (void *)(rman_get_start(sc->nf10bmac_intr_res) + 166 rman_get_size(sc->nf10bmac_intr_res))); 167 168 /* (Optional) RX and TX IRQ. */ 169 sc->nf10bmac_rx_irq_rid = 0; 170 sc->nf10bmac_rx_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, 171 &sc->nf10bmac_rx_irq_rid, RF_ACTIVE | RF_SHAREABLE); 172 173 error = nf10bmac_attach(dev); 174 if (error) 175 goto err; 176 177 return (0); 178 179err: 180 /* Cleanup. */ 181 nf10bmac_detach_resources(dev); 182 183 return (error); 184} 185 186static device_method_t nf10bmac_methods_fdt[] = { 187 /* Device interface */ 188 DEVMETHOD(device_probe, nf10bmac_probe_fdt), 189 DEVMETHOD(device_attach, nf10bmac_attach_fdt), 190 DEVMETHOD(device_detach, nf10bmac_detach_dev), 191 192 DEVMETHOD_END 193}; 194 195static driver_t nf10bmac_driver_fdt = { 196 "nf10bmac", 197 nf10bmac_methods_fdt, 198 sizeof(struct nf10bmac_softc) 199}; 200 201DRIVER_MODULE(nf10bmac, simplebus, nf10bmac_driver_fdt, nf10bmac_devclass, 0,0); 202 203/* end */ 204