2 * Copyright (c) 2012 Semihalf.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
36 #include <sys/malloc.h>
38 #include <sys/socket.h>
39 #include <sys/sysctl.h>
40 #include <sys/sockio.h>
42 #include <net/ethernet.h>
44 #include <net/if_dl.h>
45 #include <net/if_media.h>
46 #include <net/if_types.h>
47 #include <net/if_arp.h>
49 #include <dev/mii/mii.h>
50 #include <dev/mii/miivar.h>
52 #include "miibus_if.h"
54 #include <contrib/ncsw/inc/integrations/dpaa_integration_ext.h>
55 #include <contrib/ncsw/inc/Peripherals/fm_mac_ext.h>
56 #include <contrib/ncsw/inc/Peripherals/fm_port_ext.h>
57 #include <contrib/ncsw/inc/xx_ext.h>
61 #include "if_dtsec_im.h"
65 * @group dTSEC FMan PORT routines.
68 static e_RxStoreResponse
69 dtsec_im_fm_port_rx_callback(t_Handle app, uint8_t *data, uint16_t length,
70 uint16_t status, uint8_t position, t_Handle buf_context)
72 struct dtsec_softc *sc;
75 /* TODO STATUS / Position checking */
78 m = m_devget(data, length, 0, sc->sc_ifnet, NULL);
80 (*sc->sc_ifnet->if_input)(sc->sc_ifnet, m);
84 return (e_RX_STORE_RESPONSE_CONTINUE);
88 dtsec_im_fm_port_tx_conf_callback(t_Handle app, uint8_t *data, uint16_t status,
92 /* TODO: Check status */
97 dtsec_im_fm_port_rx_get_buf(t_Handle buffer_pool, t_Handle *buf_context_handle)
99 struct dtsec_softc *sc;
104 buffer = XX_MallocSmart(FM_PORT_BUFFER_SIZE, 0, sizeof(void *));
106 device_printf(sc->sc_dev, "couldn't allocate RX buffer.\n");
112 dtsec_im_fm_port_rx_put_buf(t_Handle buffer_pool, uint8_t *buffer,
113 t_Handle buf_context)
116 XX_FreeSmart(buffer);
121 dtsec_im_fm_port_rx_init(struct dtsec_softc *sc, int unit)
123 t_FmPortParams params;
124 t_BufferPoolInfo *pool_params;
125 t_FmPortImRxTxParams *im_params;
128 memset(¶ms, 0, sizeof(params));
130 params.baseAddr = sc->sc_fm_base + sc->sc_port_rx_hw_id;
131 params.h_Fm = sc->sc_fmh;
132 params.portType = dtsec_fm_port_rx_type(sc->sc_eth_dev_type);
133 params.portId = sc->sc_eth_id;
134 params.independentModeEnable = TRUE;
135 params.liodnBase = FM_PORT_LIODN_BASE;
136 params.f_Exception = dtsec_fm_port_rx_exception_callback;
139 im_params = ¶ms.specificParams.imRxTxParams;
140 im_params->h_FmMuram = sc->sc_muramh;
141 im_params->liodnOffset = FM_PORT_LIODN_OFFSET;
142 im_params->dataMemId = FM_PORT_MEM_ID;
143 im_params->dataMemAttributes = FM_PORT_MEM_ATTR;
144 im_params->f_RxStore = dtsec_im_fm_port_rx_callback;
146 pool_params = ¶ms.specificParams.imRxTxParams.rxPoolParams;
147 pool_params->h_BufferPool = sc;
148 pool_params->f_GetBuf = dtsec_im_fm_port_rx_get_buf;
149 pool_params->f_PutBuf = dtsec_im_fm_port_rx_put_buf;
150 pool_params->bufferSize = FM_PORT_BUFFER_SIZE;
152 sc->sc_rxph = FM_PORT_Config(¶ms);
153 if (sc->sc_rxph == NULL) {
154 device_printf(sc->sc_dev, "couldn't configure FM Port RX.\n");
158 error = FM_PORT_Init(sc->sc_rxph);
160 device_printf(sc->sc_dev, "couldn't initialize FM Port RX.\n");
161 FM_PORT_Free(sc->sc_rxph);
166 device_printf(sc->sc_dev, "RX hw port 0x%02x initialized.\n",
167 sc->sc_port_rx_hw_id);
173 dtsec_im_fm_port_tx_init(struct dtsec_softc *sc, int unit)
175 t_FmPortParams params;
176 t_FmPortImRxTxParams *im_params;
179 memset(¶ms, 0, sizeof(params));
181 params.baseAddr = sc->sc_fm_base + sc->sc_port_tx_hw_id;
182 params.h_Fm = sc->sc_fmh;
183 params.portType = dtsec_fm_port_tx_type(sc->sc_eth_dev_type);
184 params.portId = unit;
185 params.independentModeEnable = TRUE;
186 params.liodnBase = FM_PORT_LIODN_BASE;
187 params.f_Exception = dtsec_fm_port_tx_exception_callback;
190 im_params = ¶ms.specificParams.imRxTxParams;
191 im_params->h_FmMuram = sc->sc_muramh;
192 im_params->liodnOffset = FM_PORT_LIODN_OFFSET;
193 im_params->dataMemId = FM_PORT_MEM_ID;
194 im_params->dataMemAttributes = FM_PORT_MEM_ATTR;
195 im_params->f_TxConf = dtsec_im_fm_port_tx_conf_callback;
197 sc->sc_txph = FM_PORT_Config(¶ms);
198 if (sc->sc_txph == NULL) {
199 device_printf(sc->sc_dev, "couldn't configure FM Port TX.\n");
203 error = FM_PORT_Init(sc->sc_txph);
205 device_printf(sc->sc_dev, "couldn't initialize FM Port TX.\n");
206 FM_PORT_Free(sc->sc_txph);
211 device_printf(sc->sc_dev, "TX hw port 0x%02x initialized.\n",
212 sc->sc_port_tx_hw_id);
220 * @group dTSEC IFnet routines.
224 dtsec_im_if_start_locked(struct dtsec_softc *sc)
231 DTSEC_LOCK_ASSERT(sc);
232 /* TODO: IFF_DRV_OACTIVE */
234 if ((sc->sc_mii->mii_media_status & IFM_ACTIVE) == 0)
237 if ((sc->sc_ifnet->if_drv_flags & IFF_DRV_RUNNING) != IFF_DRV_RUNNING)
240 while (!IFQ_DRV_IS_EMPTY(&sc->sc_ifnet->if_snd)) {
241 IFQ_DRV_DEQUEUE(&sc->sc_ifnet->if_snd, m);
245 length = m_length(m, NULL);
246 buffer = XX_MallocSmart(length, 0, sizeof(void *));
252 m_copydata(m, 0, length, buffer);
255 error = FM_PORT_ImTx(sc->sc_txph, buffer, length, TRUE, buffer);
257 /* TODO: Ring full */
258 XX_FreeSmart(buffer);