Lines Matching refs:sc

125 static int	llan_add_rxbuf(struct llan_softc *sc, struct llan_xfer *rx);
126 static int llan_set_multicast(struct llan_softc *sc);
155 struct llan_softc *sc;
159 sc = device_get_softc(dev);
160 sc->dev = dev;
164 OF_getprop(node, "local-mac-address", sc->mac_address,
165 sizeof(sc->mac_address));
166 OF_getencprop(node, "reg", &sc->unit, sizeof(sc->unit));
168 mtx_init(&sc->io_lock, "llan", NULL, MTX_DEF);
171 sc->irqid = 0;
172 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqid,
175 if (!sc->irq) {
177 mtx_destroy(&sc->io_lock);
181 bus_setup_intr(dev, sc->irq, INTR_TYPE_MISC | INTR_MPSAFE |
182 INTR_ENTROPY, NULL, llan_intr, sc, &sc->irq_cookie);
188 0, NULL, NULL, &sc->rx_dma_tag);
192 0, NULL, NULL, &sc->rxbuf_dma_tag);
196 busdma_lock_mutex, &sc->io_lock, &sc->tx_dma_tag);
198 error = bus_dmamem_alloc(sc->rx_dma_tag, (void **)&sc->rx_buf,
199 BUS_DMA_WAITOK | BUS_DMA_ZERO, &sc->rx_buf_map);
200 error = bus_dmamap_load(sc->rx_dma_tag, sc->rx_buf_map, sc->rx_buf,
201 LLAN_RX_BUF_LEN, llan_rx_load_cb, sc, 0);
204 bus_dmamap_create(sc->tx_dma_tag, 0, &sc->tx_dma_map);
208 error = bus_dmamap_create(sc->rxbuf_dma_tag, 0,
209 &sc->rx_xfer[i].rx_dmamap);
210 sc->rx_xfer[i].rx_mbuf = NULL;
214 sc->ifp = if_alloc(IFT_ETHER);
215 sc->ifp->if_softc = sc;
217 if_initname(sc->ifp, device_get_name(dev), device_get_unit(dev));
218 sc->ifp->if_mtu = ETHERMTU; /* XXX max-frame-size from OF? */
219 sc->ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
220 sc->ifp->if_hwassist = 0; /* XXX: ibm,illan-options */
221 sc->ifp->if_capabilities = 0;
222 sc->ifp->if_capenable = 0;
223 sc->ifp->if_start = llan_start;
224 sc->ifp->if_ioctl = llan_ioctl;
225 sc->ifp->if_init = llan_init;
227 ifmedia_init(&sc->media, IFM_IMASK, llan_media_change,
229 ifmedia_add(&sc->media, IFM_ETHER | IFM_AUTO, 0, NULL);
230 ifmedia_set(&sc->media, IFM_ETHER | IFM_AUTO);
232 IFQ_SET_MAXLEN(&sc->ifp->if_snd, LLAN_MAX_TX_PACKETS);
233 sc->ifp->if_snd.ifq_drv_maxlen = LLAN_MAX_TX_PACKETS;
234 IFQ_SET_READY(&sc->ifp->if_snd);
236 ether_ifattach(sc->ifp, &sc->mac_address[2]);
239 if_link_state_change(sc->ifp, LINK_STATE_UP);
247 struct llan_softc *sc = ifp->if_softc;
249 if (IFM_TYPE(sc->media.ifm_media) != IFM_ETHER)
252 if (IFM_SUBTYPE(sc->media.ifm_media) != IFM_AUTO)
269 struct llan_softc *sc = xsc;
271 sc->rx_buf_phys = segs[0].ds_addr;
272 sc->rx_buf_len = segs[0].ds_len - 2*PAGE_SIZE;
273 sc->input_buf_phys = segs[0].ds_addr + segs[0].ds_len - PAGE_SIZE;
274 sc->filter_buf_phys = segs[0].ds_addr + segs[0].ds_len - 2*PAGE_SIZE;
280 struct llan_softc *sc = xsc;
285 mtx_lock(&sc->io_lock);
287 phyp_hcall(H_FREE_LOGICAL_LAN, sc->unit);
290 sc->rx_dma_slot = 0;
291 sc->rx_valid_val = 1;
294 rx_buf_desc |= (sc->rx_buf_len << 32);
295 rx_buf_desc |= sc->rx_buf_phys;
296 memcpy(&macaddr, sc->mac_address, 8);
297 err = phyp_hcall(H_REGISTER_LOGICAL_LAN, sc->unit, sc->input_buf_phys,
298 rx_buf_desc, sc->filter_buf_phys, macaddr);
301 llan_add_rxbuf(sc, &sc->rx_xfer[i]);
303 phyp_hcall(H_VIO_SIGNAL, sc->unit, 1); /* Enable interrupts */
306 sc->ifp->if_drv_flags |= IFF_DRV_RUNNING;
307 sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
309 mtx_unlock(&sc->io_lock);
312 llan_intr(sc);
316 llan_add_rxbuf(struct llan_softc *sc, struct llan_xfer *rx)
322 mtx_assert(&sc->io_lock, MA_OWNED);
330 bus_dmamap_sync(sc->rxbuf_dma_tag, rx->rx_dmamap,
332 bus_dmamap_unload(sc->rxbuf_dma_tag, rx->rx_dmamap);
338 error = bus_dmamap_load_mbuf_sg(sc->rxbuf_dma_tag, rx->rx_dmamap, m,
341 device_printf(sc->dev,
352 bus_dmamap_sync(sc->rxbuf_dma_tag, rx->rx_dmamap, BUS_DMASYNC_PREREAD);
357 error = phyp_hcall(H_ADD_LOGICAL_LAN_BUFFER, sc->unit, rx->rx_bufdesc);
370 struct llan_softc *sc = xsc;
374 mtx_lock(&sc->io_lock);
376 phyp_hcall(H_VIO_SIGNAL, sc->unit, 0);
378 while ((sc->rx_buf[sc->rx_dma_slot].control >> 7) == sc->rx_valid_val) {
379 rx = (struct llan_xfer *)sc->rx_buf[sc->rx_dma_slot].handle;
381 m_adj(m, sc->rx_buf[sc->rx_dma_slot].offset - 8);
382 m->m_len = sc->rx_buf[sc->rx_dma_slot].length;
385 if (llan_add_rxbuf(sc, rx) != 0) {
386 if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1);
387 phyp_hcall(H_ADD_LOGICAL_LAN_BUFFER, sc->unit,
392 if_inc_counter(sc->ifp, IFCOUNTER_IPACKETS, 1);
393 m_adj(m, sc->rx_buf[sc->rx_dma_slot].offset);
394 m->m_len = sc->rx_buf[sc->rx_dma_slot].length;
395 m->m_pkthdr.rcvif = sc->ifp;
397 sc->rx_dma_slot++;
399 if (sc->rx_dma_slot >= sc->rx_buf_len/sizeof(sc->rx_buf[0])) {
400 sc->rx_dma_slot = 0;
401 sc->rx_valid_val = !sc->rx_valid_val;
404 mtx_unlock(&sc->io_lock);
405 (*sc->ifp->if_input)(sc->ifp, m);
406 mtx_lock(&sc->io_lock);
409 phyp_hcall(H_VIO_SIGNAL, sc->unit, 1);
416 if ((sc->rx_buf[sc->rx_dma_slot].control >> 7) == sc->rx_valid_val)
419 mtx_unlock(&sc->io_lock);
426 struct llan_softc *sc = xsc;
438 phyp_hcall(H_SEND_LOGICAL_LAN, sc->unit, bufdescs[0],
451 struct llan_softc *sc = ifp->if_softc;
456 mtx_assert(&sc->io_lock, MA_OWNED);
481 bus_dmamap_load_mbuf(sc->tx_dma_tag, sc->tx_dma_map,
482 mb_head, llan_send_packet, sc, 0);
483 bus_dmamap_unload(sc->tx_dma_tag, sc->tx_dma_map);
491 struct llan_softc *sc = ifp->if_softc;
493 mtx_lock(&sc->io_lock);
495 mtx_unlock(&sc->io_lock);
499 llan_set_multicast(struct llan_softc *sc)
501 struct ifnet *ifp = sc->ifp;
505 mtx_assert(&sc->io_lock, MA_OWNED);
507 phyp_hcall(H_MULTICAST_CTRL, sc->unit, LLAN_CLEAR_MULTICAST, 0);
516 phyp_hcall(H_MULTICAST_CTRL, sc->unit, LLAN_ADD_MULTICAST,
528 struct llan_softc *sc = ifp->if_softc;
533 mtx_lock(&sc->io_lock);
534 if ((sc->ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
535 llan_set_multicast(sc);
536 mtx_unlock(&sc->io_lock);
540 err = ifmedia_ioctl(ifp, (struct ifreq *)data, &sc->media, cmd);