<div><div>+</div><div>+#define CPSW_DUMP_QUEUE(sc, q) do {<span class="Apple-tab-span" style="white-space:pre">                               </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>IF_DEBUG(sc) {<span class="Apple-tab-span" style="white-space:pre">                                              </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_dump_queue(sc, q);<span class="Apple-tab-span" style="white-space:pre">                             </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}<span class="Apple-tab-span" style="white-space:pre">                                                   </span>\</div><div>+} while (0)</div><div>+</div><div>+static void</div><div>+cpsw_init_slots(struct cpsw_softc *sc)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>struct cpsw_slot *slot;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>int i;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>STAILQ_INIT(&sc->avail);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>/* Put the slot descriptors onto the global avail list. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>for (i = 0; i < sizeof(sc->_slots) / sizeof(sc->_slots[0]); i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>slot = &sc->_slots[i];</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>slot->bd_offset = cpsw_cpdma_bd_offset(i);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>STAILQ_INSERT_TAIL(&sc->avail, slot, next);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>}</div><div>+}</div><div>+</div><div>+static int</div><div>+cpsw_add_slots(struct cpsw_softc *sc, struct cpsw_queue *queue, int requested)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>const int max_slots = sizeof(sc->_slots) / sizeof(sc->_slots[0]);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>struct cpsw_slot *slot;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>int i;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>if (requested < 0)</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>requested = max_slots;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>for (i = 0; i < requested; ++i) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>slot = STAILQ_FIRST(&sc->avail);</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>if (slot == NULL)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>return (0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>if (bus_dmamap_create(sc->mbuf_dtag, 0, &slot->dmamap)) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                 </span>device_printf(sc->dev, "failed to create dmamap\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>return (ENOMEM);</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>slot->resemble = malloc(CPSW_RESEMBLE_BUFFER_LEN+(CPSW_RESEMBLE_BUFFER_ALIGN-1), M_DEVBUF, M_NOWAIT | M_ZERO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>if (slot->resemble == NULL) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>device_printf(sc->dev, "failed to create resemble buffer\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">                  </span>return (ENOMEM);</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>}</div><div>+        slot->align_res = ((uint32_t)(slot->resemble) +CPSW_RESEMBLE_BUFFER_ALIGN-1)&(~(CPSW_RESEMBLE_BUFFER_ALIGN-1)); </div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>STAILQ_REMOVE_HEAD(&sc->avail, next);</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>STAILQ_INSERT_TAIL(&queue->avail, slot, next);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>++queue->avail_queue_len;</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>++queue->queue_slots;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>return (0);</div><div>+}</div><div>+</div><div>+static void</div><div>+cpsw_free_slot(struct cpsw_softc *sc, struct cpsw_slot *slot)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int error;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>if (slot->dmamap) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>if (slot->mbuf)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                  </span>bus_dmamap_unload(sc->mbuf_dtag, slot->dmamap);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>error = bus_dmamap_destroy(sc->mbuf_dtag, slot->dmamap);</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>KASSERT(error == 0, ("Mapping still active"));</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>slot->dmamap = NULL;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (slot->mbuf) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>m_freem(slot->mbuf);</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>slot->mbuf = NULL;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (slot->resemble){</div><div>+         free(slot->resemble, M_DEVBUF);</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span> slot->resemble = NULL;</div><div>+         slot->align_res = NULL;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+}</div><div>+</div><div>+static void</div><div>+cpsw_reset(struct cpsw_softc *sc)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>int i;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>callout_stop(&sc->watchdog.callout);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Reset RMII/RGMII wrapper. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_write_4(sc, CPSW_WR_SOFT_RESET, 1);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>while (cpsw_read_4(sc, CPSW_WR_SOFT_RESET) & 1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Disable TX and RX interrupts for all cores. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>for (i = 0; i < 3; ++i) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>cpsw_write_4(sc, CPSW_WR_C_RX_THRESH_EN(i), 0x00);</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>cpsw_write_4(sc, CPSW_WR_C_TX_EN(i), 0x00);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>cpsw_write_4(sc, CPSW_WR_C_RX_EN(i), 0x00);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>cpsw_write_4(sc, CPSW_WR_C_MISC_EN(i), 0x00);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Reset CPSW subsystem. */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_write_4(sc, CPSW_SS_SOFT_RESET, 1);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>while (cpsw_read_4(sc, CPSW_SS_SOFT_RESET) & 1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Reset Sliver port 1 and 2 */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>for (i = 0; i < 2; i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>/* Reset */</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>cpsw_write_4(sc, CPSW_SL_SOFT_RESET(i), 1);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>while (cpsw_read_4(sc, CPSW_SL_SOFT_RESET(i)) & 1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                      </span>;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Reset DMA controller. */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_write_4(sc, CPSW_CPDMA_SOFT_RESET, 1);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>while (cpsw_read_4(sc, CPSW_CPDMA_SOFT_RESET) & 1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Disable TX & RX DMA */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_write_4(sc, CPSW_CPDMA_TX_CONTROL, 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_write_4(sc, CPSW_CPDMA_RX_CONTROL, 0);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Clear all queues. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>for (i = 0; i < 8; i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>cpsw_write_4(sc, CPSW_CPDMA_TX_HDP(i), 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>cpsw_write_4(sc, CPSW_CPDMA_RX_HDP(i), 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>cpsw_write_4(sc, CPSW_CPDMA_TX_CP(i), 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_write_4(sc, CPSW_CPDMA_RX_CP(i), 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Clear all interrupt Masks */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_write_4(sc, CPSW_CPDMA_RX_INTMASK_CLEAR, 0xFFFFFFFF);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>cpsw_write_4(sc, CPSW_CPDMA_TX_INTMASK_CLEAR, 0xFFFFFFFF);</div><div>+}</div><div>+</div><div>+static void</div><div>+cpsw_init(struct cpsw_softc *sc)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>struct cpsw_slot *slot;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>uint32_t reg;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>/* Clear ALE */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_write_4(sc, CPSW_ALE_CONTROL, CPSW_ALE_CTL_CLEAR_TBL);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Enable ALE */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>reg = CPSW_ALE_CTL_ENABLE;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>if (sc->dualemac)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>reg |= (CPSW_ALE_CTL_VLAN_AWARE);</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, CPSW_ALE_CONTROL, reg);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>/* Set Host Port Mapping. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_4(sc, CPSW_PORT_P0_CPDMA_TX_PRI_MAP, 0x76543210);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_4(sc, CPSW_PORT_P0_CPDMA_RX_CH_MAP, 0);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>/* Initialize ALE: set host port to forwarding(3). */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_write_4(sc, CPSW_ALE_PORTCTL(0), 3);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, CPSW_SS_PTYPE, 0);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Enable statistics for ports 0, 1 and 2 */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_4(sc, CPSW_SS_STAT_PORT_EN, 7);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>/* Experiment:  Turn off flow control */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>/* This seems to fix the watchdog resets that have plagued</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>   earlier versions of this driver; I'm not yet sure if there</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>   are negative effects yet. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_4(sc, CPSW_SS_FLOW_CONTROL, 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>/* Make IP hdr aligned with 4 */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_write_4(sc, CPSW_CPDMA_RX_BUFFER_OFFSET, 2);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Initialize RX Buffer Descriptors */</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>cpsw_write_4(sc, CPSW_CPDMA_RX_FREEBUFFER(0), 0);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Enable TX & RX DMA */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_4(sc, CPSW_CPDMA_TX_CONTROL, 1);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_write_4(sc, CPSW_CPDMA_RX_CONTROL, 1);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Enable Interrupts for core 0 */</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>cpsw_write_4(sc, CPSW_WR_C_RX_THRESH_EN(0), 0xFF);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>cpsw_write_4(sc, CPSW_WR_C_RX_EN(0), 0xFF);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_write_4(sc, CPSW_WR_C_MISC_EN(0), 0x1F);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>/* Enable host Error Interrupt */</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, CPSW_CPDMA_DMA_INTMASK_SET, 3);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>/* Enable interrupts for RX Channel 0 */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_write_4(sc, CPSW_CPDMA_RX_INTMASK_SET, 1);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>/* Initialze MDIO - ENABLE, PREAMBLE=0, FAULTENB, CLKDIV=0xFF */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>/* TODO Calculate MDCLK=CLK/(CLKDIV+1) */</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, MDIOCONTROL, MDIOCTL_ENABLE | MDIOCTL_FAULTENB | 0xff);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>/* Select MII in GMII_SEL, Internal Delay mode */</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>ti_scm_reg_write_4(0x650, 0);</div><div>+#else</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>cm_write(CONTROL_MOD_BASE+CPSW_GMII_SEL,</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>GMIISEL_GMII2_SEL(RGMII_MODE)|GMIISEL_GMII1_SEL(RGMII_MODE)|0x30);</div><div>+#endif<span class="Apple-tab-span" style="white-space:pre">    </span></div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>/* Initialize active queues. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>slot = STAILQ_FIRST(&sc->tx.active);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>if (slot != NULL)</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_write_hdp_slot(sc, &sc->tx, slot);</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>slot = STAILQ_FIRST(&sc->rx.active);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>if (slot != NULL)</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_write_hdp_slot(sc, &sc->rx, slot);</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>cpsw_rx_enqueue(sc);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>/* Activate network interface. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>sc->rx.running = 1;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>sc->tx.running = 1;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>sc->watchdog.timer = 0;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>callout_init(&sc->watchdog.callout, 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>callout_reset(&sc->watchdog.callout, hz, cpsw_tx_watchdog, sc);</div><div>+}</div><div>+</div><div>+/*</div><div>+ *</div><div>+ * Device Probe, Attach, Detach.</div><div>+ *</div><div>+ */</div><div>+</div><div>+static int</div><div>+cpsw_probe(device_t dev)</div><div>+{</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>if (!ofw_bus_status_okay(dev))</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>return (ENXIO);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>if (!ofw_bus_is_compatible(dev, "ti,cpsw"))</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>return (ENXIO);</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>device_set_desc(dev, "3-port Switch Ethernet Subsystem");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return (BUS_PROBE_DEFAULT);</div><div>+}</div><div>+</div><div>+static int</div><div>+cpsw_intr_attach(struct cpsw_softc *sc)</div><div>+{</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>/* Note: We don't use sc->irq_res[2] (TX interrupt) */</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (bus_setup_intr(sc->dev, sc->irq_res[1],</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>    INTR_TYPE_NET | INTR_MPSAFE, NULL, cpsw_intr_rx_thresh,</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>    sc, &sc->ih_cookie[0]) != 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>return (-1);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (bus_setup_intr(sc->dev, sc->irq_res[2],</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>    INTR_TYPE_NET | INTR_MPSAFE, NULL, cpsw_intr_rx,</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>    sc, &sc->ih_cookie[1]) != 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>return (-1);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (bus_setup_intr(sc->dev, sc->irq_res[4],</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>    INTR_TYPE_NET | INTR_MPSAFE, NULL, cpsw_intr_misc,</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>    sc, &sc->ih_cookie[3]) != 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>return (-1);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>return (0);</div><div>+}</div><div>+</div><div>+static void</div><div>+cpsw_intr_detach(struct cpsw_softc *sc)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>int i;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>for (i = 0; i < CPSW_INTR_COUNT; i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>if (sc->ih_cookie[i]) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                  </span>bus_teardown_intr(sc->dev, sc->irq_res[i],</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>    sc->ih_cookie[i]);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+}</div><div>+#ifndef __rtems__</div><div>+static int</div><div>+cpsw_get_fdt_data(struct cpsw_softc *sc, int port)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>char *name;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>int len, phy, vlan;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>pcell_t phy_id[3], vlan_id;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>phandle_t child;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>unsigned long mdio_child_addr;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>/* Find any slave with phy_id */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>phy = -1;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>vlan = -1;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>for (child = OF_child(sc->node); child != 0; child = OF_peer(child)) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>if (OF_getprop_alloc(child, "name", 1, (void **)&name) < 0)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                        </span>continue;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>if (sscanf(name, "slave@%x", &mdio_child_addr) != 1) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                        </span>free(name, M_OFWPROP);</div><div>+<span class="Apple-tab-span" style="white-space:pre">                      </span>continue;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>free(name, M_OFWPROP);</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>if (mdio_child_addr != slave_mdio_addr[port])</div><div>+<span class="Apple-tab-span" style="white-space:pre">                       </span>continue;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>len = OF_getproplen(child, "phy_id");</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>if (len / sizeof(pcell_t) == 2) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>/* Get phy address from fdt */</div><div>+<span class="Apple-tab-span" style="white-space:pre">                      </span>if (OF_getencprop(child, "phy_id", phy_id, len) > 0)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                           </span>phy = phy_id[1];</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>len = OF_getproplen(child, "dual_emac_res_vlan");</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>if (len / sizeof(pcell_t) == 1) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>/* Get phy address from fdt */</div><div>+<span class="Apple-tab-span" style="white-space:pre">                      </span>if (OF_getencprop(child, "dual_emac_res_vlan",</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>    &vlan_id, len) > 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                          </span>vlan = vlan_id;</div><div>+<span class="Apple-tab-span" style="white-space:pre">                     </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>break;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (phy == -1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>sc->port[port].phy = phy;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>sc->port[port].vlan = vlan;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>return (0);</div><div>+}</div><div>+#endif</div><div>+</div><div>+static int</div><div>+cpsw_attach(device_t dev)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>bus_dma_segment_t segs[1];</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>int error, i, nsegs;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>struct cpsw_softc *sc;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>uint32_t reg;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>sc = device_get_softc(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>sc->dev = dev;</div><div>+    getbinuptime(&sc->attach_uptime);</div><div>+</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>sc->node = ofw_bus_get_node(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span></div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>if (OF_getencprop(sc->node, "active_slave", &sc->active_slave,</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>    sizeof(sc->active_slave)) <= 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>sc->active_slave = 0;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (sc->active_slave > 1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>sc->active_slave = 1;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>if (OF_hasprop(sc->node, "dual_emac"))</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>sc->dualemac = 1;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>for (i = 0; i < CPSW_PORTS; i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>if (!sc->dualemac && i != sc->active_slave)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>continue;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>if (cpsw_get_fdt_data(sc, i) != 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                        </span>device_printf(dev,</div><div>+<span class="Apple-tab-span" style="white-space:pre">                  </span>    "failed to get PHY address from FDT\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+#else</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>sc->debug = 0;</div><div>+    sc->active_slave = 0;</div><div>+    sc->dualemac = 1;</div><div>+    sc->port[0].phy = 4;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>sc->port[0].vlan = 2;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>sc->port[1].phy = 6;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>sc->port[1].vlan = 3;</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>/* Initialize mutexes */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>mtx_init(&sc->tx.lock, device_get_nameunit(dev),</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>    "cpsw TX lock", MTX_DEF);</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>mtx_init(&sc->rx.lock, device_get_nameunit(dev),</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>    "cpsw RX lock", MTX_DEF);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Allocate IRQ resources */</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>error = bus_alloc_resources(dev, irq_res_spec, sc->irq_res);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>if (error) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>device_printf(dev, "could not allocate IRQ resources\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>sc->mem_rid = 0;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, </div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>    &sc->mem_rid, RF_ACTIVE);</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>if (sc->mem_res == NULL) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>device_printf(sc->dev, "failed to allocate memory resource\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+#else</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>error = bus_alloc_resources(dev, irq_res_spec, sc->irq_res);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>if (error) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>device_printf(dev, "could not allocate resources\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>reg = cpsw_read_4(sc, CPSW_SS_IDVER);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>device_printf(dev, "CPSW SS Version %d.%d (%d)\n", (reg >> 8 & 0x7),</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>reg & 0xFF, (reg >> 11) & 0x1F);</div><div>+</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_add_sysctls(sc);</div><div>+#endif</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Allocate a busdma tag and DMA safe memory for mbufs. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>error = bus_dma_tag_create(</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>bus_get_dma_tag(sc->dev),<span class="Apple-tab-span" style="white-space:pre">        </span>/* parent */</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>1, 0,<span class="Apple-tab-span" style="white-space:pre">                               </span>/* alignment, boundary */</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>BUS_SPACE_MAXADDR_32BIT,<span class="Apple-tab-span" style="white-space:pre">    </span>/* lowaddr */</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>BUS_SPACE_MAXADDR,<span class="Apple-tab-span" style="white-space:pre">          </span>/* highaddr */</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>NULL, NULL,<span class="Apple-tab-span" style="white-space:pre">                 </span>/* filtfunc, filtfuncarg */</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>MCLBYTES, CPSW_TXFRAGS,<span class="Apple-tab-span" style="white-space:pre">             </span>/* maxsize, nsegments */</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>MCLBYTES, 0,<span class="Apple-tab-span" style="white-space:pre">                        </span>/* maxsegsz, flags */</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>NULL, NULL,<span class="Apple-tab-span" style="white-space:pre">                 </span>/* lockfunc, lockfuncarg */</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>&sc->mbuf_dtag);<span class="Apple-tab-span" style="white-space:pre">             </span>/* dmatag */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>if (error) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>device_printf(dev, "bus_dma_tag_create failed\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>return (error);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Allocate the null mbuf and pre-sync it. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>sc->null_mbuf = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>memset(sc->null_mbuf->m_data, 0, sc->null_mbuf->m_ext.ext_size);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>bus_dmamap_create(sc->mbuf_dtag, 0, &sc->null_mbuf_dmamap);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>bus_dmamap_load_mbuf_sg(sc->mbuf_dtag, sc->null_mbuf_dmamap,</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>    sc->null_mbuf, segs, &nsegs, BUS_DMA_NOWAIT);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>bus_dmamap_sync(sc->mbuf_dtag, sc->null_mbuf_dmamap,</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>    BUS_DMASYNC_PREWRITE);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>sc->null_mbuf_paddr = segs[0].ds_addr;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_init_slots(sc);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>/* Allocate slots to TX and RX queues. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>STAILQ_INIT(&sc->rx.avail);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>STAILQ_INIT(&sc->rx.active);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>STAILQ_INIT(&sc->tx.avail);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>STAILQ_INIT(&sc->tx.active);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>// For now:  128 slots to TX, rest to RX.</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>// XXX TODO: start with 32/64 and grow dynamically based on demand.</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>if (cpsw_add_slots(sc, &sc->tx, 128) ||</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>    cpsw_add_slots(sc, &sc->rx, -1)) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>device_printf(dev, "failed to allocate dmamaps\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>return (ENOMEM);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>device_printf(dev, "Initial queue size TX=%d RX=%d\n",</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>    sc->tx.queue_slots, sc->rx.queue_slots);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>sc->tx.hdp_offset = CPSW_CPDMA_TX_HDP(0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>sc->rx.hdp_offset = CPSW_CPDMA_RX_HDP(0);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>if (cpsw_intr_attach(sc) == -1) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>device_printf(dev, "failed to setup interrupts\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Reset the controller. */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_reset(sc);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_init(sc);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>for (i = 0; i < CPSW_PORTS; i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>if (!sc->dualemac && i != sc->active_slave)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>continue;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>sc->port[i].dev = device_add_child(dev, "cpswp", i);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>if (sc->port[i].dev == NULL) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>cpsw_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>printf("attach child failure!\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">                        </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>bus_generic_attach(dev);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>return (0);</div><div>+}</div><div>+</div><div>+static int</div><div>+cpsw_detach(device_t dev)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>struct cpsw_softc *sc;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>int error, i;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>bus_generic_detach(dev);</div><div>+ <span class="Apple-tab-span" style="white-space:pre">   </span>sc = device_get_softc(dev);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>for (i = 0; i < CPSW_PORTS; i++) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>if (sc->port[i].dev)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                     </span>device_delete_child(dev, sc->port[i].dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (device_is_attached(dev)) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>callout_stop(&sc->watchdog.callout);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>callout_drain(&sc->watchdog.callout);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Stop and release all interrupts */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_intr_detach(sc);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>/* Free dmamaps and mbufs */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>for (i = 0; i < sizeof(sc->_slots) / sizeof(sc->_slots[0]); ++i)</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_free_slot(sc, &sc->_slots[i]);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>/* Free null mbuf. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>if (sc->null_mbuf_dmamap) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>bus_dmamap_unload(sc->mbuf_dtag, sc->null_mbuf_dmamap);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>error = bus_dmamap_destroy(sc->mbuf_dtag, sc->null_mbuf_dmamap);</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>KASSERT(error == 0, ("Mapping still active"));</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>m_freem(sc->null_mbuf);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Free DMA tag */</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>if (sc->mbuf_dtag) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>error = bus_dma_tag_destroy(sc->mbuf_dtag);</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>KASSERT(error == 0, ("Unable to destroy DMA tag"));</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>}</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>/* Free IO memory handler */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>if (sc->mem_res != NULL)</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>bus_release_resources(dev, irq_res_spec, sc->irq_res);</div><div>+#else</div><div>+    /* Free IO memory handler */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>bus_release_resources(dev, irq_res_spec, sc->irq_res);</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>/* Destroy mutexes */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>mtx_destroy(&sc->rx.lock);</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>mtx_destroy(&sc->tx.lock);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>return (0);</div><div>+}</div><div>+#ifndef __rtems__</div><div>+static phandle_t</div><div>+cpsw_get_node(device_t bus, device_t dev)</div><div>+{</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>/* Share controller node with port device. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>return (ofw_bus_get_node(bus));</div><div>+}</div><div>+#endif</div><div>+static int</div><div>+cpswp_probe(device_t dev)</div><div>+{</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>if (device_get_unit(dev) > 1) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>device_printf(dev, "Only two ports are supported.\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>device_set_desc(dev, "Ethernet Switch Port");</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>return (BUS_PROBE_DEFAULT);</div><div>+}</div><div>+</div><div>+static int</div><div>+cpswp_attach(device_t dev)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>int error;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>struct ifnet *ifp;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>struct cpswp_softc *sc;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>uint32_t reg;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>uint8_t mac_addr[ETHER_ADDR_LEN];</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>sc = device_get_softc(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>sc->dev = dev;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>sc->pdev = device_get_parent(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>sc->swsc = device_get_softc(sc->pdev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>sc->unit = device_get_unit(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>sc->phy = sc->swsc->port[sc->unit].phy;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>sc->vlan = sc->swsc->port[sc->unit].vlan;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>if (sc->swsc->dualemac && sc->vlan == -1)</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>sc->vlan = sc->unit + 1;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>if (sc->unit == 0) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>sc->physel = MDIOUSERPHYSEL0;</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>sc->phyaccess = MDIOUSERACCESS0;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>} else {</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>sc->physel = MDIOUSERPHYSEL1;</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>sc->phyaccess = MDIOUSERACCESS1;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>mtx_init(&sc->lock, device_get_nameunit(dev), "cpsw port lock",</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>    MTX_DEF);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>/* Allocate network interface */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>ifp = sc->ifp = if_alloc(IFT_ETHER);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>if (ifp == NULL) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>cpswp_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>printf("alloc if failure!\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>return (ENXIO);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if_initname(ifp, device_get_name(sc->dev), sc->unit);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>ifp->if_softc = sc;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>ifp->if_flags = IFF_SIMPLEX | IFF_MULTICAST | IFF_BROADCAST;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>ifp->if_capabilities = IFCAP_VLAN_MTU | IFCAP_HWCSUM; //FIXME VLAN?</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>ifp->if_capenable = ifp->if_capabilities;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>ifp->if_init = cpswp_init;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>ifp->if_start = cpswp_start;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>ifp->if_ioctl = cpswp_ioctl;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>ifp->if_snd.ifq_drv_maxlen = sc->swsc->tx.queue_slots;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>IFQ_SET_MAXLEN(&ifp->if_snd, ifp->if_snd.ifq_drv_maxlen);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>IFQ_SET_READY(&ifp->if_snd);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Get high part of MAC address from control module (mac_id[0|1]_hi) */</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>ti_scm_reg_read_4(0x634 + sc->unit * 8, &reg);</div><div>+#else</div><div>+    reg = cm_read(CONTROL_MOD_BASE+0x634 + sc->unit * 8);</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>mac_addr[0] = reg & 0xFF;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>mac_addr[1] = (reg >>  8) & 0xFF;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>mac_addr[2] = (reg >> 16) & 0xFF;</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>mac_addr[3] = (reg >> 24) & 0xFF;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Get low part of MAC address from control module (mac_id[0|1]_lo) */</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>ti_scm_reg_read_4(0x630 + sc->unit * 8, &reg);</div><div>+#else</div><div>+    reg = cm_read(CONTROL_MOD_BASE+0x630+ sc->unit * 8);</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>mac_addr[4] = reg & 0xFF;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>mac_addr[5] = (reg >>  8) & 0xFF;</div><div>+   </div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>error = mii_attach(dev, &sc->miibus, ifp, cpswp_ifmedia_upd,</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    cpswp_ifmedia_sts, BMSR_DEFCAPMASK, sc->phy, MII_OFFSET_ANY, 0);</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (error) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>device_printf(dev, "attaching PHYs failed\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>cpswp_detach(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>return (error);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>sc->mii = device_get_softc(sc->miibus);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>/* Select PHY and enable interrupts */</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>cpsw_write_4(sc->swsc, sc->physel,</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>    MDIO_PHYSEL_LINKINTENB | (sc->phy & 0x1F));</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>ether_ifattach(sc->ifp, mac_addr);</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>callout_init(&sc->mii_callout, 0);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>return (0);</div><div>+}</div><div>+</div><div>+static int</div><div>+cpswp_detach(device_t dev)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>struct cpswp_softc *sc;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>sc = device_get_softc(dev);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>CPSWP_DEBUGF(sc, (""));</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (device_is_attached(dev)) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>ether_ifdetach(sc->ifp);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>CPSW_PORT_LOCK(sc);</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>cpswp_stop_locked(sc);</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>CPSW_PORT_UNLOCK(sc);</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>callout_drain(&sc->mii_callout);</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>}</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>bus_generic_detach(dev);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>if_free(sc->ifp);</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>mtx_destroy(&sc->lock);</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>return (0);</div><div>+}</div></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From: </b> "yao0718";<29171383@qq.com>;</div><div><b>Date: </b> Tue, Jul 5, 2016 03:17 PM</div><div><b>To: </b> "devel"<devel@rtems.org>; <wbr></div><div></div><div><b>Subject: </b> Re:  [3/6] add ti cpsw driver file part 1</div></div><div><br></div><div><div>diff -ruN ./rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpsw.c ./am335x_bsp/rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpsw.c</div><div>--- ./rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpsw.c<span class="Apple-tab-span" style="white-space:pre">       </span>1970-01-01 08:00:00.000000000 +0800</div><div>+++ ./am335x_bsp/rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpsw.c<span class="Apple-tab-span" style="white-space:pre">   </span>2016-07-05 09:22:41.794327800 +0800</div><div>@@ -0,0 +1,2772 @@</div><div>+#include <machine/rtems-bsd-kernel-space.h></div><div>+/*-</div><div>+ * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org></div><div>+ * Copyright (c) 2016 Rubicon Communications, LLC (Netgate)</div><div>+ * All rights reserved.</div><div>+ *</div><div>+ * Redistribution and use in source and binary forms, with or without</div><div>+ * modification, are permitted provided that the following conditions</div><div>+ * are met:</div><div>+ * 1. Redistributions of source code must retain the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer.</div><div>+ * 2. Redistributions in binary form must reproduce the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer in the</div><div>+ *    documentation and/or other materials provided with the distribution.</div><div>+ *</div><div>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND</div><div>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</div><div>+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</div><div>+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE</div><div>+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</div><div>+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</div><div>+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</div><div>+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</div><div>+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</div><div>+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</div><div>+ * SUCH DAMAGE.</div><div>+ */</div><div>+</div><div>+/*</div><div>+ * TI Common Platform Ethernet Switch (CPSW) Driver</div><div>+ * Found in TI8148 "DaVinci" and AM335x "Sitara" SoCs.</div><div>+ *</div><div>+ * This controller is documented in the AM335x Technical Reference</div><div>+ * Manual, in the TMS320DM814x DaVinci Digital Video Processors TRM</div><div>+ * and in the TMS320C6452 3 Port Switch Ethernet Subsystem TRM.</div><div>+ *</div><div>+ * It is basically a single Ethernet port (port 0) wired internally to</div><div>+ * a 3-port store-and-forward switch connected to two independent</div><div>+ * "sliver" controllers (port 1 and port 2).  You can operate the</div><div>+ * controller in a variety of different ways by suitably configuring</div><div>+ * the slivers and the Address Lookup Engine (ALE) that routes packets</div><div>+ * between the ports.</div><div>+ *</div><div>+ * This code was developed and tested on a BeagleBone with</div><div>+ * an AM335x SoC.</div><div>+ */</div><div>+</div><div>+#include <sys/cdefs.h></div><div>+__FBSDID("$FreeBSD$");</div><div>+</div><div>+#include <rtems/bsd/sys/param.h></div><div>+#include <sys/systm.h></div><div>+#include <sys/endian.h></div><div>+#include <sys/mbuf.h></div><div>+#ifndef __rtems__</div><div>+#include <sys/lock.h></div><div>+#else</div><div>+#include <rtems/bsd/sys/lock.h></div><div>+#endif</div><div>+#include <sys/mutex.h></div><div>+#include <sys/kernel.h></div><div>+#include <sys/module.h></div><div>+#include <sys/socket.h></div><div>+#include <sys/sysctl.h></div><div>+</div><div>+#include <net/ethernet.h></div><div>+#include <net/bpf.h></div><div>+#include <net/if.h></div><div>+#include <net/if_arp.h></div><div>+#include <net/if_dl.h></div><div>+#include <net/if_media.h></div><div>+#include <net/if_types.h></div><div>+#include <net/if_var.h></div><div>+#include <net/if_vlan_var.h></div><div>+</div><div>+#include <netinet/in_systm.h></div><div>+#include <netinet/in.h></div><div>+#include <netinet/ip.h></div><div>+</div><div>+#include <sys/sockio.h></div><div>+#include <sys/bus.h></div><div>+#include <machine/bus.h></div><div>+#include <sys/rman.h></div><div>+#include <machine/resource.h></div><div>+</div><div>+#include <dev/mii/mii.h></div><div>+#include <dev/mii/miivar.h></div><div>+#ifndef __rtems__</div><div>+#include <dev/fdt/fdt_common.h></div><div>+#include <dev/ofw/ofw_bus.h></div><div>+#include <dev/ofw/ofw_bus_subr.h></div><div>+#endif</div><div>+#include "if_cpswreg.h"</div><div>+#include "if_cpswvar.h"</div><div>+#ifndef __rtems__ </div><div>+#include <arm/ti/ti_scm.h></div><div>+#endif</div><div>+#include <rtems/bsd/local/miibus_if.h></div><div>+#include <sys/malloc.h></div><div>+</div><div>+/* Device probe/attach/detach. */</div><div>+static int cpsw_probe(device_t);</div><div>+static void cpsw_init_slots(struct cpsw_softc *);</div><div>+static int cpsw_attach(device_t);</div><div>+static void cpsw_free_slot(struct cpsw_softc *, struct cpsw_slot *);</div><div>+static int cpsw_detach(device_t);</div><div>+</div><div>+/* Device probe/attach/detach. */</div><div>+static int cpswp_probe(device_t);</div><div>+static int cpswp_attach(device_t);</div><div>+static int cpswp_detach(device_t);</div><div>+#ifndef __rtems__ </div><div>+static phandle_t cpsw_get_node(device_t, device_t);</div><div>+#endif</div><div>+/* Device Init/shutdown. */</div><div>+static int cpsw_shutdown(device_t);</div><div>+static void cpswp_init(void *);</div><div>+static void cpswp_init_locked(void *);</div><div>+static void cpswp_stop_locked(struct cpswp_softc *);</div><div>+</div><div>+/* Device Suspend/Resume. */</div><div>+static int cpsw_suspend(device_t);</div><div>+static int cpsw_resume(device_t);</div><div>+</div><div>+/* Ioctl. */</div><div>+static int cpswp_ioctl(struct ifnet *, u_long command, caddr_t data);</div><div>+</div><div>+static int cpswp_miibus_readreg(device_t, int phy, int reg);</div><div>+static int cpswp_miibus_writereg(device_t, int phy, int reg, int value);</div><div>+static void cpswp_miibus_statchg(device_t);</div><div>+</div><div>+/* Send/Receive packets. */</div><div>+static void cpsw_intr_rx(void *arg);</div><div>+static struct mbuf *cpsw_rx_dequeue(struct cpsw_softc *);</div><div>+static void cpsw_rx_enqueue(struct cpsw_softc *);</div><div>+static void cpswp_start(struct ifnet *);</div><div>+static void cpswp_tx_enqueue(struct cpswp_softc *);</div><div>+static int cpsw_tx_dequeue(struct cpsw_softc *);</div><div>+</div><div>+/* Misc interrupts and watchdog. */</div><div>+static void cpsw_intr_rx_thresh(void *);</div><div>+static void cpsw_intr_misc(void *);</div><div>+static void cpswp_tick(void *);</div><div>+static void cpswp_ifmedia_sts(struct ifnet *, struct ifmediareq *);</div><div>+static int cpswp_ifmedia_upd(struct ifnet *);</div><div>+static void cpsw_tx_watchdog(void *);</div><div>+</div><div>+/* ALE support */</div><div>+static void cpsw_ale_read_entry(struct cpsw_softc *, uint16_t, uint32_t *);</div><div>+static void cpsw_ale_write_entry(struct cpsw_softc *, uint16_t, uint32_t *);</div><div>+static int cpsw_ale_mc_entry_set(struct cpsw_softc *, uint8_t, int, uint8_t *);</div><div>+static void cpsw_ale_dump_table(struct cpsw_softc *);</div><div>+static int cpsw_ale_update_vlan_table(struct cpsw_softc *, int, int, int);</div><div>+static int cpswp_ale_update_addresses(struct cpswp_softc *, int);</div><div>+</div><div>+/* Statistics and sysctls. */</div><div>+#ifndef __rtems__</div><div>+static void cpsw_add_sysctls(struct cpsw_softc *);</div><div>+static void cpsw_stats_collect(struct cpsw_softc *);</div><div>+static int cpsw_stats_sysctl(SYSCTL_HANDLER_ARGS);</div><div>+#endif</div><div>+</div><div>+/*</div><div>+ * Arbitrary limit on number of segments in an mbuf to be transmitted.</div><div>+ * Packets with more segments than this will be defragmented before</div><div>+ * they are queued.</div><div>+ */</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>CPSW_TXFRAGS<span class="Apple-tab-span" style="white-space:pre">                </span>8</div><div>+</div><div>+/* Shared resources. */</div><div>+static device_method_t cpsw_methods[] = {</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* Device interface */</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>DEVMETHOD(device_probe,<span class="Apple-tab-span" style="white-space:pre">             </span>cpsw_probe),</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>DEVMETHOD(device_attach,<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_attach),</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>DEVMETHOD(device_detach,<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_detach),</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>DEVMETHOD(device_shutdown,<span class="Apple-tab-span" style="white-space:pre">  </span>cpsw_shutdown),</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>DEVMETHOD(device_suspend,<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_suspend),</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>DEVMETHOD(device_resume,<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_resume),</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>/* OFW methods */</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>DEVMETHOD(ofw_bus_get_node,<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_get_node),</div><div>+#endif<span class="Apple-tab-span" style="white-space:pre">       </span></div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>DEVMETHOD_END</div><div>+};</div><div>+</div><div>+static driver_t cpsw_driver = {</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>"cpsw",</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_methods,</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>sizeof(struct cpsw_softc),</div><div>+};</div><div>+</div><div>+static devclass_t cpsw_devclass;</div><div>+</div><div>+#ifndef __rtems__</div><div>+DRIVER_MODULE(cpsw, simplebus, cpsw_driver, cpsw_devclass, 0, 0);</div><div>+#else</div><div>+DRIVER_MODULE(cpsw, nexus, cpsw_driver, cpsw_devclass, 0, 0);</div><div>+#endif</div><div>+/* Port/Slave resources. */</div><div>+static device_method_t cpswp_methods[] = {</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* Device interface */</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>DEVMETHOD(device_probe,<span class="Apple-tab-span" style="white-space:pre">             </span>cpswp_probe),</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>DEVMETHOD(device_attach,<span class="Apple-tab-span" style="white-space:pre">    </span>cpswp_attach),</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>DEVMETHOD(device_detach,<span class="Apple-tab-span" style="white-space:pre">    </span>cpswp_detach),</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>/* MII interface */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>DEVMETHOD(miibus_readreg,<span class="Apple-tab-span" style="white-space:pre">   </span>cpswp_miibus_readreg),</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>DEVMETHOD(miibus_writereg,<span class="Apple-tab-span" style="white-space:pre">  </span>cpswp_miibus_writereg),</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>DEVMETHOD(miibus_statchg,<span class="Apple-tab-span" style="white-space:pre">   </span>cpswp_miibus_statchg),</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>DEVMETHOD_END</div><div>+};</div><div>+</div><div>+static driver_t cpswp_driver = {</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>"cpswp",</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>cpswp_methods,</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>sizeof(struct cpswp_softc),</div><div>+};</div><div>+</div><div>+static devclass_t cpswp_devclass;</div><div>+</div><div>+DRIVER_MODULE(cpswp, cpsw, cpswp_driver, cpswp_devclass, 0, 0);</div><div>+DRIVER_MODULE(miibus, cpswp, miibus_driver, miibus_devclass, 0, 0);</div><div>+MODULE_DEPEND(cpsw, ether, 1, 1, 1);</div><div>+MODULE_DEPEND(cpswp, miibus, 1, 1, 1);</div><div>+</div><div>+static uint32_t slave_mdio_addr[] = { 0x4a100200, 0x4a100300 };</div><div>+</div><div>+static struct resource_spec irq_res_spec[] = {</div><div>+#ifdef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>{ SYS_RES_MEMORY, 0, RF_ACTIVE },</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>{ SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE },</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{ SYS_RES_IRQ, 1, RF_ACTIVE | RF_SHAREABLE },</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{ SYS_RES_IRQ, 2, RF_ACTIVE | RF_SHAREABLE },</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{ SYS_RES_IRQ, 3, RF_ACTIVE | RF_SHAREABLE },</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{ -1, 0 }</div><div>+};</div><div>+</div><div>+/* Number of entries here must match size of stats</div><div>+ * array in struct cpswp_softc. */</div><div>+static struct cpsw_stat {</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>int<span class="Apple-tab-span" style="white-space:pre"> </span>reg;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>char *oid;</div><div>+} cpsw_stat_sysctls[CPSW_SYSCTL_COUNT] = {</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{0x00, "GoodRxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>{0x04, "BroadcastRxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x08, "MulticastRxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x0C, "PauseRxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>{0x10, "RxCrcErrors"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>{0x14, "RxAlignErrors"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>{0x18, "OversizeRxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{0x1c, "RxJabbers"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x20, "ShortRxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>{0x24, "RxFragments"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>{0x30, "RxOctets"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{0x34, "GoodTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>{0x38, "BroadcastTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x3c, "MulticastTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x40, "PauseTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>{0x44, "DeferredTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{0x48, "CollisionsTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>{0x4c, "SingleCollisionTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{0x50, "MultipleCollisionTxFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x54, "ExcessiveCollisions"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>{0x58, "LateCollisions"},</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>{0x5c, "TxUnderrun"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>{0x60, "CarrierSenseErrors"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>{0x64, "TxOctets"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{0x68, "RxTx64OctetFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x6c, "RxTx65to127OctetFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>{0x70, "RxTx128to255OctetFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{0x74, "RxTx256to511OctetFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{0x78, "RxTx512to1024OctetFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>{0x7c, "RxTx1024upOctetFrames"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>{0x80, "NetOctets"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>{0x84, "RxStartOfFrameOverruns"},</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>{0x88, "RxMiddleOfFrameOverruns"},</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>{0x8c, "RxDmaOverruns"}</div><div>+};</div><div>+</div><div>+/*</div><div>+ * Basic debug support.</div><div>+ */</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>IF_DEBUG(_sc)<span class="Apple-tab-span" style="white-space:pre">               </span>if ((_sc)->if_flags & IFF_DEBUG)</div><div>+</div><div>+static void</div><div>+cpsw_debugf_head(const char *funcname)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>int t = (int)(time_second % (24 * 60 * 60));</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>printf("%02d:%02d:%02d %s ", t / (60 * 60), (t / 60) % 60, t % 60, funcname);</div><div>+}</div><div>+</div><div>+#include <machine/stdarg.h></div><div>+static void</div><div>+cpsw_debugf(const char *fmt, ...)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>va_list ap;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>va_start(ap, fmt);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>vprintf(fmt, ap);</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>va_end(ap);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>printf("\n");</div><div>+</div><div>+}</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>CPSW_DEBUGF(_sc, a) do {<span class="Apple-tab-span" style="white-space:pre">                                    </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (sc->debug) {<span class="Apple-tab-span" style="white-space:pre">                                         </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_debugf_head(__func__);<span class="Apple-tab-span" style="white-space:pre">                         </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_debugf a;<span class="Apple-tab-span" style="white-space:pre">                                              </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}<span class="Apple-tab-span" style="white-space:pre">                                                           </span>\</div><div>+} while (0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSWP_DEBUGF(_sc, a) do {<span class="Apple-tab-span" style="white-space:pre">                                   </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>IF_DEBUG((_sc)) {<span class="Apple-tab-span" style="white-space:pre">                                           </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_debugf_head(__func__);<span class="Apple-tab-span" style="white-space:pre">                         </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_debugf a;<span class="Apple-tab-span" style="white-space:pre">                                              </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}<span class="Apple-tab-span" style="white-space:pre">                                                           </span>\</div><div>+} while (0)</div><div>+</div><div>+</div><div>+/*</div><div>+ * Locking macros</div><div>+ */</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_TX_LOCK(sc) do {<span class="Apple-tab-span" style="white-space:pre">                                               </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_assert(&(sc)->rx.lock, MA_NOTOWNED);<span class="Apple-tab-span" style="white-space:pre">             </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_lock(&(sc)->tx.lock);<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+} while (0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_TX_UNLOCK(sc)<span class="Apple-tab-span" style="white-space:pre">  </span>mtx_unlock(&(sc)->tx.lock)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>CPSW_TX_LOCK_ASSERT(sc)<span class="Apple-tab-span" style="white-space:pre">     </span>mtx_assert(&(sc)->tx.lock, MA_OWNED)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">  </span>CPSW_RX_LOCK(sc) do {<span class="Apple-tab-span" style="white-space:pre">                                               </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_assert(&(sc)->tx.lock, MA_NOTOWNED);<span class="Apple-tab-span" style="white-space:pre">             </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_lock(&(sc)->rx.lock);<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+} while (0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_RX_UNLOCK(sc)<span class="Apple-tab-span" style="white-space:pre">          </span>mtx_unlock(&(sc)->rx.lock)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>CPSW_RX_LOCK_ASSERT(sc)<span class="Apple-tab-span" style="white-space:pre">     </span>mtx_assert(&(sc)->rx.lock, MA_OWNED)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">  </span>CPSW_GLOBAL_LOCK(sc) do {<span class="Apple-tab-span" style="white-space:pre">                                   </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>if ((mtx_owned(&(sc)->tx.lock) ? 1 : 0) !=<span class="Apple-tab-span" style="white-space:pre">           </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>    (mtx_owned(&(sc)->rx.lock) ? 1 : 0)) {<span class="Apple-tab-span" style="white-space:pre">         </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">                   </span>panic("cpsw deadlock possibility detection!");<span class="Apple-tab-span" style="white-space:pre">    </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>}<span class="Apple-tab-span" style="white-space:pre">                                                   </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_lock(&(sc)->tx.lock);<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_lock(&(sc)->rx.lock);<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+} while (0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_GLOBAL_UNLOCK(sc) do {<span class="Apple-tab-span" style="white-space:pre">                                 </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>CPSW_RX_UNLOCK(sc);<span class="Apple-tab-span" style="white-space:pre">                                 </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>CPSW_TX_UNLOCK(sc);<span class="Apple-tab-span" style="white-space:pre">                                 </span>\</div><div>+} while (0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_GLOBAL_LOCK_ASSERT(sc) do {<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>CPSW_TX_LOCK_ASSERT(sc);<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>CPSW_RX_LOCK_ASSERT(sc);<span class="Apple-tab-span" style="white-space:pre">                            </span>\</div><div>+} while (0)</div><div>+</div><div>+#define CPSW_PORT_LOCK(_sc) do {<span class="Apple-tab-span" style="white-space:pre">                                        </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_assert(&(_sc)->lock, MA_NOTOWNED);<span class="Apple-tab-span" style="white-space:pre">                       </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>mtx_lock(&(_sc)->lock);<span class="Apple-tab-span" style="white-space:pre">                                      </span>\</div><div>+} while (0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_PORT_UNLOCK(_sc)<span class="Apple-tab-span" style="white-space:pre">       </span>mtx_unlock(&(_sc)->lock)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_PORT_LOCK_ASSERT(_sc)<span class="Apple-tab-span" style="white-space:pre">  </span>mtx_assert(&(_sc)->lock, MA_OWNED)</div><div>+</div><div>+/*</div><div>+ * Read/Write macros</div><div>+ */</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_read_4(_sc, _reg)<span class="Apple-tab-span" style="white-space:pre">              </span>bus_read_4((_sc)->irq_res[0], (_reg))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_write_4(_sc, _reg, _val)<span class="Apple-tab-span" style="white-space:pre">                                       </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>bus_write_4((_sc)->irq_res[0], (_reg), (_val))</div><div>+</div><div>+#define BUS_SPACE_PHYSADDR(res, offs) \</div><div>+        ((u_int)(rman_get_start(res)+(offs)))</div><div>+#define CONTROL_MOD_BASE 0x44E10000</div><div>+#define CPSW_GMII_SEL<span class="Apple-tab-span" style="white-space:pre">                   </span>         (0x0650)</div><div>+/* GMII_SEL Register Field */</div><div>+#define GMIISEL_RMII2_IO_CLK_EN<span class="Apple-tab-span" style="white-space:pre">   </span>             (1UL<<(7))</div><div>+#define GMIISEL_RMII1_IO_CLK_EN<span class="Apple-tab-span" style="white-space:pre">  </span>             (1UL<<(6))</div><div>+#define GMIISEL_RGMII2_IDMODE<span class="Apple-tab-span" style="white-space:pre">    </span>             (1UL<<(5))</div><div>+#define GMIISEL_RGMII1_IDMODE<span class="Apple-tab-span" style="white-space:pre">    </span>             (1UL<<(4))</div><div>+#define GMIISEL_GMII2_SEL(val)<span class="Apple-tab-span" style="white-space:pre">   </span>             ((0x3 & (val)) << 2)</div><div>+#define GMIISEL_GMII1_SEL(val)<span class="Apple-tab-span" style="white-space:pre">     </span>             ((0x3 & (val)) << 0)</div><div>+#define GMII_MODE<span class="Apple-tab-span" style="white-space:pre">  </span>                              0</div><div>+#define RMII_MODE<span class="Apple-tab-span" style="white-space:pre"> </span>                              1</div><div>+#define RGMII_MODE<span class="Apple-tab-span" style="white-space:pre">        </span>                          2</div><div>+</div><div>+</div><div>+#define cm_read(a)    (*(volatile uint32_t *)(a))</div><div>+#define cm_write(a,v) (*(volatile uint32_t *)(a) = (v))</div><div>+</div><div>+</div><div>+</div><div>+</div><div>+</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_cpdma_bd_offset(i)<span class="Apple-tab-span" style="white-space:pre">     </span>(CPSW_CPPI_RAM_OFFSET + ((i)*16))</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_cpdma_bd_paddr(sc, slot)<span class="Apple-tab-span" style="white-space:pre">                                       </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>BUS_SPACE_PHYSADDR(sc->irq_res[0], slot->bd_offset)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>cpsw_cpdma_read_bd(sc, slot, val)<span class="Apple-tab-span" style="white-space:pre">                           </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>bus_read_region_4(sc->irq_res[0], slot->bd_offset, (uint32_t *) val, 4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_cpdma_write_bd(sc, slot, val)<span class="Apple-tab-span" style="white-space:pre">                          </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>bus_write_region_4(sc->irq_res[0], slot->bd_offset, (uint32_t *) val, 4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_cpdma_write_bd_next(sc, slot, next_slot)<span class="Apple-tab-span" style="white-space:pre">                       </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, slot->bd_offset, cpsw_cpdma_bd_paddr(sc, next_slot))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>cpsw_cpdma_read_bd_flags(sc, slot)<span class="Apple-tab-span" style="white-space:pre">                          </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>bus_read_2(sc->irq_res[0], slot->bd_offset + 14)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_write_hdp_slot(sc, queue, slot)<span class="Apple-tab-span" style="white-space:pre">                                </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, (queue)->hdp_offset, cpsw_cpdma_bd_paddr(sc, slot))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CP_OFFSET (CPSW_CPDMA_TX_CP(0) - CPSW_CPDMA_TX_HDP(0))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>cpsw_read_cp(sc, queue)<span class="Apple-tab-span" style="white-space:pre">                                             </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_read_4(sc, (queue)->hdp_offset + CP_OFFSET) </div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>cpsw_write_cp(sc, queue, val)<span class="Apple-tab-span" style="white-space:pre">                                       </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_4(sc, (queue)->hdp_offset + CP_OFFSET, (val))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">  </span>cpsw_write_cp_slot(sc, queue, slot)<span class="Apple-tab-span" style="white-space:pre">                         </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>cpsw_write_cp(sc, queue, cpsw_cpdma_bd_paddr(sc, slot))</div><div>+</div><div>+#if 0</div><div>+/* XXX temporary function versions for debugging. */</div><div>+static void</div><div>+cpsw_write_hdp_slotX(struct cpsw_softc *sc, struct cpsw_queue *queue, struct cpsw_slot *slot)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>uint32_t reg = queue->hdp_offset;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>uint32_t v = cpsw_cpdma_bd_paddr(sc, slot);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_DEBUGF(("HDP <=== 0x%08x (was 0x%08x)", v, cpsw_read_4(sc, reg)));</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_4(sc, reg, v);</div><div>+}</div><div>+static void</div><div>+cpsw_write_cp_slotX(struct cpsw_softc *sc, struct cpsw_queue *queue, struct cpsw_slot *slot)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>uint32_t v = cpsw_cpdma_bd_paddr(sc, slot);</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_DEBUGF(("CP <=== 0x%08x (expecting 0x%08x)", v, cpsw_read_cp(sc, queue)));</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>cpsw_write_cp(sc, queue, v);</div><div>+}</div><div>+#endif</div><div>+</div><div>+/*</div><div>+ * Expanded dump routines for verbose debugging.</div><div>+ */</div><div>+static void</div><div>+cpsw_dump_slot(struct cpsw_softc *sc, struct cpsw_slot *slot)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>static const char *flags[] = {"SOP", "EOP", "Owner", "EOQ",</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>    "TDownCmplt", "PassCRC", "Long", "Short", "MacCtl", "Overrun",</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>    "PktErr1", "PortEn/PktErr0", "RxVlanEncap", "Port2", "Port1",</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>    "Port0"};</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>struct cpsw_cpdma_bd bd;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>const char *sep;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>int i;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>cpsw_cpdma_read_bd(sc, slot, &bd);</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>printf("BD Addr: 0x%08x   Next: 0x%08x\n", cpsw_cpdma_bd_paddr(sc, slot), bd.next);</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>printf("  BufPtr: 0x%08x   BufLen: 0x%08x\n", bd.bufptr, bd.buflen);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>printf("  BufOff: 0x%08x   PktLen: 0x%08x\n", bd.bufoff, bd.pktlen);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>printf("  Flags: ");</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>sep = "";</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>for (i = 0; i < 16; ++i) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">               </span>if (bd.flags & (1 << (15 - i))) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                 </span>printf("%s%s", sep, flags[i]);</div><div>+<span class="Apple-tab-span" style="white-space:pre">                    </span>sep = ",";</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>printf("\n");</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>if (slot->mbuf) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>printf("  Ether:  %14D\n",</div><div>+<span class="Apple-tab-span" style="white-space:pre">              </span>    (char *)(slot->mbuf->m_data), " ");</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>printf("  Packet: %16D\n",</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>    (char *)(slot->mbuf->m_data) + 14, " ");</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>+}</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_DUMP_SLOT(cs, slot) do {<span class="Apple-tab-span" style="white-space:pre">                               </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>IF_DEBUG(sc) {<span class="Apple-tab-span" style="white-space:pre">                                              </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>cpsw_dump_slot(sc, slot);<span class="Apple-tab-span" style="white-space:pre">                   </span>\</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>}<span class="Apple-tab-span" style="white-space:pre">                                                   </span>\</div><div>+} while (0)</div><div>+</div><div>+static void</div><div>+cpsw_dump_queue(struct cpsw_softc *sc, struct cpsw_slots *q)</div><div>+{</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>struct cpsw_slot *slot;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>int i = 0;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>int others = 0;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>STAILQ_FOREACH(slot, q, next) {</div><div>+<span class="Apple-tab-span" style="white-space:pre">             </span>if (i > 4)</div><div>+<span class="Apple-tab-span" style="white-space:pre">                       </span>++others;</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>else</div><div>+<span class="Apple-tab-span" style="white-space:pre">                        </span>cpsw_dump_slot(sc, slot);</div><div>+<span class="Apple-tab-span" style="white-space:pre">           </span>++i;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>if (others)</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>printf(" ... and %d more.\n", others);</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>printf("\n");</div><div>+}</div></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From: </b> "yao0718";<29171383@qq.com>;</div><div><b>Date: </b> Tue, Jul 5, 2016 03:15 PM</div><div><b>To: </b> "devel"<devel@rtems.org>; <wbr></div><div></div><div><b>Subject: </b> Re: [2/6] add ti cpsw head file</div></div><div><br></div><div><div>diff -ruN ./rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswreg.h ./am335x_bsp/rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswreg.h</div><div>--- ./rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswreg.h<span class="Apple-tab-span" style="white-space:pre">      </span>1970-01-01 08:00:00.000000000 +0800</div><div>+++ ./am335x_bsp/rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswreg.h<span class="Apple-tab-span" style="white-space:pre">        </span>2016-03-18 11:38:45.324075400 +0800</div><div>@@ -0,0 +1,178 @@</div><div>+/*-</div><div>+ * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org></div><div>+ * All rights reserved.</div><div>+ *</div><div>+ * Redistribution and use in source and binary forms, with or without</div><div>+ * modification, are permitted provided that the following conditions</div><div>+ * are met:</div><div>+ * 1. Redistributions of source code must retain the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer.</div><div>+ * 2. Redistributions in binary form must reproduce the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer in the</div><div>+ *    documentation and/or other materials provided with the distribution.</div><div>+ *</div><div>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND</div><div>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</div><div>+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</div><div>+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE</div><div>+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</div><div>+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</div><div>+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</div><div>+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</div><div>+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</div><div>+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</div><div>+ * SUCH DAMAGE.</div><div>+ *</div><div>+ * $FreeBSD$</div><div>+ */</div><div>+</div><div>+#ifndef<span class="Apple-tab-span" style="white-space:pre">   </span>_IF_CPSWREG_H</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span>_IF_CPSWREG_H</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span>CPSW_SS_OFFSET<span class="Apple-tab-span" style="white-space:pre">                      </span>0x0000</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SS_IDVER<span class="Apple-tab-span" style="white-space:pre">                       </span>(CPSW_SS_OFFSET + 0x00)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_SS_SOFT_RESET<span class="Apple-tab-span" style="white-space:pre">          </span>(CPSW_SS_OFFSET + 0x08)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_SS_STAT_PORT_EN<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_SS_OFFSET + 0x0C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_SS_PTYPE<span class="Apple-tab-span" style="white-space:pre">                       </span>(CPSW_SS_OFFSET + 0x10)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_SS_FLOW_CONTROL<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_SS_OFFSET + 0x24)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_PORT_OFFSET<span class="Apple-tab-span" style="white-space:pre">            </span>0x0100</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_PORT_P_MAX_BLKS(p)<span class="Apple-tab-span" style="white-space:pre">             </span>(CPSW_PORT_OFFSET + 0x08 + ((p) * 0x100))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>CPSW_PORT_P_BLK_CNT(p)<span class="Apple-tab-span" style="white-space:pre">              </span>(CPSW_PORT_OFFSET + 0x0C + ((p) * 0x100))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>CPSW_PORT_P_VLAN(p)<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_PORT_OFFSET + 0x14 + ((p) * 0x100))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>CPSW_PORT_P_TX_PRI_MAP(p)<span class="Apple-tab-span" style="white-space:pre">   </span>(CPSW_PORT_OFFSET + 0x118 + ((p-1) * 0x100))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_PORT_P0_CPDMA_TX_PRI_MAP<span class="Apple-tab-span" style="white-space:pre">       </span>(CPSW_PORT_OFFSET + 0x01C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_PORT_P0_CPDMA_RX_CH_MAP<span class="Apple-tab-span" style="white-space:pre">        </span>(CPSW_PORT_OFFSET + 0x020)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_PORT_P_SA_LO(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_PORT_OFFSET + 0x120 + ((p-1) * 0x100))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_PORT_P_SA_HI(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_PORT_OFFSET + 0x124 + ((p-1) * 0x100))</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_CPDMA_OFFSET<span class="Apple-tab-span" style="white-space:pre">           </span>0x0800</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_CPDMA_TX_CONTROL<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_CPDMA_OFFSET + 0x04)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_TX_TEARDOWN<span class="Apple-tab-span" style="white-space:pre">              </span>(CPSW_CPDMA_OFFSET + 0x08)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_CONTROL<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_CPDMA_OFFSET + 0x14)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_TEARDOWN<span class="Apple-tab-span" style="white-space:pre">              </span>(CPSW_CPDMA_OFFSET + 0x18)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_SOFT_RESET<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_CPDMA_OFFSET + 0x1c)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_DMACONTROL<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_CPDMA_OFFSET + 0x20)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_DMASTATUS<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_CPDMA_OFFSET + 0x24)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_BUFFER_OFFSET<span class="Apple-tab-span" style="white-space:pre"> </span>(CPSW_CPDMA_OFFSET + 0x28)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_TX_INTSTAT_RAW<span class="Apple-tab-span" style="white-space:pre">   </span>(CPSW_CPDMA_OFFSET + 0x80)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_TX_INTSTAT_MASKED<span class="Apple-tab-span" style="white-space:pre">        </span>(CPSW_CPDMA_OFFSET + 0x84)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_TX_INTMASK_SET<span class="Apple-tab-span" style="white-space:pre">   </span>(CPSW_CPDMA_OFFSET + 0x88)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_TX_INTMASK_CLEAR<span class="Apple-tab-span" style="white-space:pre"> </span>(CPSW_CPDMA_OFFSET + 0x8C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_CPDMA_EOI_VECTOR<span class="Apple-tab-span" style="white-space:pre"> </span>(CPSW_CPDMA_OFFSET + 0x94)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_INTSTAT_RAW<span class="Apple-tab-span" style="white-space:pre">   </span>(CPSW_CPDMA_OFFSET + 0xA0)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_INTSTAT_MASKED<span class="Apple-tab-span" style="white-space:pre">        </span>(CPSW_CPDMA_OFFSET + 0xA4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_INTMASK_SET<span class="Apple-tab-span" style="white-space:pre">   </span>(CPSW_CPDMA_OFFSET + 0xA8)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_INTMASK_CLEAR<span class="Apple-tab-span" style="white-space:pre"> </span>(CPSW_CPDMA_OFFSET + 0xAc)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_DMA_INTSTAT_RAW<span class="Apple-tab-span" style="white-space:pre">  </span>(CPSW_CPDMA_OFFSET + 0xB0)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_DMA_INTSTAT_MASKED<span class="Apple-tab-span" style="white-space:pre">       </span>(CPSW_CPDMA_OFFSET + 0xB4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_DMA_INTMASK_SET<span class="Apple-tab-span" style="white-space:pre">  </span>(CPSW_CPDMA_OFFSET + 0xB8)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_DMA_INTMASK_CLEAR<span class="Apple-tab-span" style="white-space:pre">        </span>(CPSW_CPDMA_OFFSET + 0xBC)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_CPDMA_RX_FREEBUFFER(p)<span class="Apple-tab-span" style="white-space:pre"> </span>(CPSW_CPDMA_OFFSET + 0x0e0 + ((p) * 0x04))</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_STATS_OFFSET<span class="Apple-tab-span" style="white-space:pre">           </span>0x0900</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_STATERAM_OFFSET<span class="Apple-tab-span" style="white-space:pre">                </span>0x0A00</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_CPDMA_TX_HDP(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_STATERAM_OFFSET + 0x00 + ((p) * 0x04))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_CPDMA_RX_HDP(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_STATERAM_OFFSET + 0x20 + ((p) * 0x04))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_CPDMA_TX_CP(p)<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_STATERAM_OFFSET + 0x40 + ((p) * 0x04))</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_CPDMA_RX_CP(p)<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_STATERAM_OFFSET + 0x60 + ((p) * 0x04))</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_CPTS_OFFSET<span class="Apple-tab-span" style="white-space:pre">            </span>0x0C00</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_ALE_OFFSET<span class="Apple-tab-span" style="white-space:pre">                     </span>0x0D00</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_ALE_CONTROL<span class="Apple-tab-span" style="white-space:pre">            </span>(CPSW_ALE_OFFSET + 0x08)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span> CPSW_ALE_CTL_ENABLE<span class="Apple-tab-span" style="white-space:pre">                </span>(1U << 31)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span> CPSW_ALE_CTL_CLEAR_TBL<span class="Apple-tab-span" style="white-space:pre">             </span>(1 << 30)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPSW_ALE_CTL_BYPASS<span class="Apple-tab-span" style="white-space:pre">                </span>(1 << 4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_ALE_CTL_VLAN_AWARE<span class="Apple-tab-span" style="white-space:pre">    </span>(1 << 2)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_ALE_TBLCTL<span class="Apple-tab-span" style="white-space:pre">                     </span>(CPSW_ALE_OFFSET + 0x20)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>CPSW_ALE_TBLW2<span class="Apple-tab-span" style="white-space:pre">                      </span>(CPSW_ALE_OFFSET + 0x34)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>CPSW_ALE_TBLW1<span class="Apple-tab-span" style="white-space:pre">                      </span>(CPSW_ALE_OFFSET + 0x38)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span>CPSW_ALE_TBLW0<span class="Apple-tab-span" style="white-space:pre">                      </span>(CPSW_ALE_OFFSET + 0x3C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span> ALE_MCAST(_a)<span class="Apple-tab-span" style="white-space:pre">                      </span>((_a[1] >> 8) & 1)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span> ALE_MCAST_FWD<span class="Apple-tab-span" style="white-space:pre">                      </span>(3 << 30)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> ALE_PORTS(_a)<span class="Apple-tab-span" style="white-space:pre">                      </span>((_a[2] >> 2) & 7)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span> ALE_TYPE(_a)<span class="Apple-tab-span" style="white-space:pre">                       </span>((_a[1] >> 28) & 3)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span> ALE_TYPE_ADDR<span class="Apple-tab-span" style="white-space:pre">                      </span>1</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span> ALE_TYPE_VLAN<span class="Apple-tab-span" style="white-space:pre">                      </span>2</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span> ALE_TYPE_VLAN_ADDR<span class="Apple-tab-span" style="white-space:pre">         </span>3</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span> ALE_VLAN(_a)<span class="Apple-tab-span" style="white-space:pre">                       </span>((_a[1] >> 16) & 0xfff)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span> ALE_VLAN_REGFLOOD(_a)<span class="Apple-tab-span" style="white-space:pre">              </span>((_a[0] >> 8) & 7)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span> ALE_VLAN_UNREGFLOOD(_a)<span class="Apple-tab-span" style="white-space:pre">    </span>((_a[0] >> 16) & 7)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span> ALE_VLAN_UNTAG(_a)<span class="Apple-tab-span" style="white-space:pre">         </span>((_a[0] >> 24) & 7)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span> ALE_VLAN_MEMBERS(_a)<span class="Apple-tab-span" style="white-space:pre">               </span>(_a[0] & 7)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_ALE_PORTCTL(p)<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_ALE_OFFSET + 0x40 + ((p) * 0x04))</div><div>+</div><div>+/* SL1 is at 0x0D80, SL2 is at 0x0DC0 */</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_SL_OFFSET<span class="Apple-tab-span" style="white-space:pre">                      </span>0x0D80</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_MACCONTROL(p)<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x04)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_SL_MACTL_IFCTL_B<span class="Apple-tab-span" style="white-space:pre">              </span>(1 << 16)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPSW_SL_MACTL_IFCTL_A<span class="Apple-tab-span" style="white-space:pre">              </span>(1 << 15)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPSW_SL_MACTL_GIG<span class="Apple-tab-span" style="white-space:pre">          </span>(1 << 7)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_SL_MACTL_GMII_ENABLE<span class="Apple-tab-span" style="white-space:pre">  </span>(1 << 5)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_SL_MACTL_FULLDUPLEX<span class="Apple-tab-span" style="white-space:pre">   </span>(1 << 0)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_MACSTATUS(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x08)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_SOFT_RESET(p)<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x0C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_RX_MAXLEN(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x10)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_RX_PAUSE(p)<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x18)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_TX_PAUSE(p)<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x1C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_SL_RX_PRI_MAP(p)<span class="Apple-tab-span" style="white-space:pre">               </span>(CPSW_SL_OFFSET + (0x40 * (p)) + 0x24)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>MDIO_OFFSET<span class="Apple-tab-span" style="white-space:pre">                 </span>0x1000</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>MDIOCONTROL<span class="Apple-tab-span" style="white-space:pre">                 </span>(MDIO_OFFSET + 0x04)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span> MDIOCTL_ENABLE<span class="Apple-tab-span" style="white-space:pre">                     </span>(1 << 30)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> MDIOCTL_FAULTENB<span class="Apple-tab-span" style="white-space:pre">           </span>(1 << 18)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>MDIOLINKINTRAW<span class="Apple-tab-span" style="white-space:pre">                      </span>(MDIO_OFFSET + 0x10)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>MDIOLINKINTMASKED<span class="Apple-tab-span" style="white-space:pre">           </span>(MDIO_OFFSET + 0x14)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>MDIOUSERACCESS0<span class="Apple-tab-span" style="white-space:pre">                     </span>(MDIO_OFFSET + 0x80)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>MDIOUSERPHYSEL0<span class="Apple-tab-span" style="white-space:pre">                     </span>(MDIO_OFFSET + 0x84)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>MDIOUSERACCESS1<span class="Apple-tab-span" style="white-space:pre">                     </span>(MDIO_OFFSET + 0x88)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>MDIOUSERPHYSEL1<span class="Apple-tab-span" style="white-space:pre">                     </span>(MDIO_OFFSET + 0x8C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span> MDIO_PHYSEL_LINKINTENB<span class="Apple-tab-span" style="white-space:pre">             </span>(1 << 6)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> MDIO_PHYACCESS_GO<span class="Apple-tab-span" style="white-space:pre">          </span>(1U << 31)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">     </span> MDIO_PHYACCESS_WRITE<span class="Apple-tab-span" style="white-space:pre">               </span>(1 << 30)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> MDIO_PHYACCESS_ACK<span class="Apple-tab-span" style="white-space:pre">         </span>(1 << 29)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_WR_OFFSET<span class="Apple-tab-span" style="white-space:pre">                      </span>0x1200</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_SOFT_RESET<span class="Apple-tab-span" style="white-space:pre">          </span>(CPSW_WR_OFFSET + 0x04)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_WR_CONTROL<span class="Apple-tab-span" style="white-space:pre">                     </span>(CPSW_WR_OFFSET + 0x08)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_WR_INT_CONTROL<span class="Apple-tab-span" style="white-space:pre">         </span>(CPSW_WR_OFFSET + 0x0c)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span>CPSW_WR_C_RX_THRESH_EN(p)<span class="Apple-tab-span" style="white-space:pre">   </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x10)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_RX_EN(p)<span class="Apple-tab-span" style="white-space:pre">          </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x14)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_TX_EN(p)<span class="Apple-tab-span" style="white-space:pre">          </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x18)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_MISC_EN(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x1C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_RX_THRESH_STAT(p)<span class="Apple-tab-span" style="white-space:pre"> </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x40)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_RX_STAT(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x44)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_TX_STAT(p)<span class="Apple-tab-span" style="white-space:pre">                </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x48)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_WR_C_MISC_STAT(p)<span class="Apple-tab-span" style="white-space:pre">              </span>(CPSW_WR_OFFSET + (0x10 * (p)) + 0x4C)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_WR_C_MISC_EVNT_PEND<span class="Apple-tab-span" style="white-space:pre">   </span>(1 << 4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_WR_C_MISC_STAT_PEND<span class="Apple-tab-span" style="white-space:pre">   </span>(1 << 3)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_WR_C_MISC_HOST_PEND<span class="Apple-tab-span" style="white-space:pre">   </span>(1 << 2)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_WR_C_MISC_MDIOLINK<span class="Apple-tab-span" style="white-space:pre">    </span>(1 << 1)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPSW_WR_C_MISC_MDIOUSER<span class="Apple-tab-span" style="white-space:pre">    </span>(1 << 0)</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_CPPI_RAM_OFFSET<span class="Apple-tab-span" style="white-space:pre">                </span>0x2000</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_CPPI_RAM_SIZE<span class="Apple-tab-span" style="white-space:pre">          </span>0x2000</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span>CPSW_MEMWINDOW_SIZE<span class="Apple-tab-span" style="white-space:pre">         </span>0x4000</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPDMA_BD_SOP<span class="Apple-tab-span" style="white-space:pre">                       </span>(1 << 15)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPDMA_BD_EOP<span class="Apple-tab-span" style="white-space:pre">                       </span>(1 << 14)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPDMA_BD_OWNER<span class="Apple-tab-span" style="white-space:pre">                     </span>(1 << 13)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPDMA_BD_EOQ<span class="Apple-tab-span" style="white-space:pre">                       </span>(1 << 12)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPDMA_BD_TDOWNCMPLT<span class="Apple-tab-span" style="white-space:pre">                </span>(1 << 11)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">      </span> CPDMA_BD_PKT_ERR_MASK<span class="Apple-tab-span" style="white-space:pre">              </span>(3 << 4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPDMA_BD_TO_PORT<span class="Apple-tab-span" style="white-space:pre">           </span>(1 << 4)</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">       </span> CPDMA_BD_PORT_MASK<span class="Apple-tab-span" style="white-space:pre">         </span>3</div><div>+</div><div>+struct cpsw_cpdma_bd {</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>volatile uint32_t next;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>volatile uint32_t bufptr;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>volatile uint16_t buflen;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>volatile uint16_t bufoff;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>volatile uint16_t pktlen;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>volatile uint16_t flags;</div><div>+};</div><div>+</div><div>+#endif /*_IF_CPSWREG_H */</div><div><br></div><div>diff -ruN ./rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswvar.h ./am335x_bsp/rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswvar.h</div><div>--- ./rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswvar.h<span class="Apple-tab-span" style="white-space:pre">       </span>1970-01-01 08:00:00.000000000 +0800</div><div>+++ ./am335x_bsp/rtems-libbsd/freebsd/sys/arm/ti/cpsw/if_cpswvar.h<span class="Apple-tab-span" style="white-space:pre">        </span>2016-07-02 21:43:26.205209800 +0800</div><div>@@ -0,0 +1,147 @@</div><div>+/*-</div><div>+ * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org></div><div>+ * All rights reserved.</div><div>+ *</div><div>+ * Redistribution and use in source and binary forms, with or without</div><div>+ * modification, are permitted provided that the following conditions</div><div>+ * are met:</div><div>+ * 1. Redistributions of source code must retain the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer.</div><div>+ * 2. Redistributions in binary form must reproduce the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer in the</div><div>+ *    documentation and/or other materials provided with the distribution.</div><div>+ *</div><div>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND</div><div>+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</div><div>+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</div><div>+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE</div><div>+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</div><div>+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</div><div>+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</div><div>+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</div><div>+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</div><div>+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</div><div>+ * SUCH DAMAGE.</div><div>+ *</div><div>+ * $FreeBSD$</div><div>+ */</div><div>+</div><div>+#ifndef<span class="Apple-tab-span" style="white-space:pre">   </span>_IF_CPSWVAR_H</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span>_IF_CPSWVAR_H</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">        </span>CPSW_PORTS<span class="Apple-tab-span" style="white-space:pre">          </span>2</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">    </span>CPSW_INTR_COUNT<span class="Apple-tab-span" style="white-space:pre">             </span>4</div><div>+</div><div>+/* MII BUS  */</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_MIIBUS_RETRIES<span class="Apple-tab-span" style="white-space:pre"> </span>10</div><div>+#define<span class="Apple-tab-span" style="white-space:pre">   </span>CPSW_MIIBUS_DELAY<span class="Apple-tab-span" style="white-space:pre">   </span>2000</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_MAX_ALE_ENTRIES<span class="Apple-tab-span" style="white-space:pre">        </span>1024</div><div>+</div><div>+#define<span class="Apple-tab-span" style="white-space:pre"> </span>CPSW_SYSCTL_COUNT<span class="Apple-tab-span" style="white-space:pre">   </span>34</div><div>+</div><div>+#define CPSW_RESEMBLE_BUFFER_LEN  2048</div><div>+#define CPSW_RESEMBLE_BUFFER_ALIGN 4</div><div>+struct cpsw_slot {</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>uint32_t bd_offset;  /* Offset of corresponding BD within CPPI RAM. */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>bus_dmamap_t dmamap;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>struct mbuf *mbuf;</div><div>+/* yao0718 add  why cppi dma can not send when address misalign 32 bits*/</div><div>+    uint8_t  *resemble;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>uint8_t  *align_res;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>STAILQ_ENTRY(cpsw_slot) next;</div><div>+};</div><div>+STAILQ_HEAD(cpsw_slots, cpsw_slot);</div><div>+</div><div>+struct cpsw_queue {</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>struct mtx<span class="Apple-tab-span" style="white-space:pre">  </span>lock;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>running;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>struct cpsw_slots active;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>struct cpsw_slots avail;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>queue_adds; /* total bufs added */</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>queue_removes; /* total bufs removed */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>queue_removes_at_last_tick; /* Used by watchdog */</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>queue_slots;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>active_queue_len;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>max_active_queue_len;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>avail_queue_len;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>max_avail_queue_len;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>longest_chain; /* Largest # segments in a single packet. */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>hdp_offset;</div><div>+};</div><div>+</div><div>+struct cpsw_port {</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>device_t<span class="Apple-tab-span" style="white-space:pre">    </span>dev;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>phy;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>vlan;</div><div>+};</div><div>+</div><div>+struct cpsw_softc {</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>device_t<span class="Apple-tab-span" style="white-space:pre">    </span>dev;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>active_slave;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>debug;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>dualemac;</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>phandle_t<span class="Apple-tab-span" style="white-space:pre">   </span>node;</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>struct bintime<span class="Apple-tab-span" style="white-space:pre">      </span>attach_uptime; /* system uptime when attach happened. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>struct cpsw_port port[2];</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* RX and TX buffer tracking */</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>struct cpsw_queue rx, tx;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* We expect 1 memory resource and 4 interrupts from the device tree. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>void<span class="Apple-tab-span" style="white-space:pre">                </span>*ih_cookie[CPSW_INTR_COUNT];</div><div>+#ifndef __rtems__</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>mem_rid;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>struct resource<span class="Apple-tab-span" style="white-space:pre">     </span>*mem_res;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>struct resource<span class="Apple-tab-span" style="white-space:pre">     </span>*irq_res[CPSW_INTR_COUNT];</div><div>+#else</div><div>+    struct resource<span class="Apple-tab-span" style="white-space:pre">        </span>*irq_res[1+CPSW_INTR_COUNT];</div><div>+#endif</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>/* An mbuf full of nulls for TX padding. */</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>bus_dmamap_t null_mbuf_dmamap;</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>struct mbuf *null_mbuf;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>bus_addr_t null_mbuf_paddr;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>bus_dma_tag_t<span class="Apple-tab-span" style="white-space:pre">       </span>mbuf_dtag;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>struct {</div><div>+<span class="Apple-tab-span" style="white-space:pre">            </span>int resets;</div><div>+<span class="Apple-tab-span" style="white-space:pre">         </span>int timer;</div><div>+<span class="Apple-tab-span" style="white-space:pre">          </span>struct callout  callout;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>} watchdog;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>/* 64-bit versions of 32-bit hardware statistics counters */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>uint64_t shadow_stats[CPSW_SYSCTL_COUNT];</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>/* CPPI STATERAM has 512 slots for building TX/RX queues. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>/* TODO: Size here supposedly varies with different versions</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>   of the controller.  Check DaVinci specs and find a good</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>   way to adjust this.  One option is to have a separate</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>   Device Tree parameter for number slots; another option</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>   is to calculate it from the memory size in the device tree. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>struct cpsw_slot _slots[CPSW_CPPI_RAM_SIZE / sizeof(struct cpsw_cpdma_bd)];</div><div>+<span class="Apple-tab-span" style="white-space:pre"> </span>struct cpsw_slots avail;</div><div>+};</div><div>+</div><div>+struct cpswp_softc {</div><div>+<span class="Apple-tab-span" style="white-space:pre">      </span>device_t<span class="Apple-tab-span" style="white-space:pre">    </span>dev;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>device_t<span class="Apple-tab-span" style="white-space:pre">    </span>miibus;</div><div>+<span class="Apple-tab-span" style="white-space:pre">     </span>device_t<span class="Apple-tab-span" style="white-space:pre">    </span>pdev;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>media_status;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>unit;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>int<span class="Apple-tab-span" style="white-space:pre">         </span>vlan;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>struct bintime<span class="Apple-tab-span" style="white-space:pre">      </span>init_uptime; /* system uptime when init happened. */</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>struct callout<span class="Apple-tab-span" style="white-space:pre">      </span>mii_callout;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>struct cpsw_softc *swsc;</div><div>+<span class="Apple-tab-span" style="white-space:pre">    </span>struct ifnet<span class="Apple-tab-span" style="white-space:pre">        </span>*ifp;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>struct mii_data<span class="Apple-tab-span" style="white-space:pre">     </span>*mii;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>struct mtx<span class="Apple-tab-span" style="white-space:pre">  </span>lock;</div><div>+<span class="Apple-tab-span" style="white-space:pre">       </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>if_flags;</div><div>+<span class="Apple-tab-span" style="white-space:pre">   </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>phy;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>phyaccess;</div><div>+<span class="Apple-tab-span" style="white-space:pre">  </span>uint32_t<span class="Apple-tab-span" style="white-space:pre">    </span>physel;</div><div>+};</div><div>+</div><div>+#endif /*_IF_CPSWVAR_H */</div></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>From: </b> "yao0718";<29171383@qq.com>;</div><div><b>Date: </b> Tue, Jul 5, 2016 03:11 PM</div><div><b>To: </b> "devel"<devel@rtems.org>; <wbr></div><div></div><div><b>Subject: </b> [0/6] ti cpsw driver port from freebsd for am335x </div></div><div><br></div><div><span style="font-family: 'lucida Grande', Verdana, 'Microsoft YaHei'; line-height: 23.8px;">I add cpsw driver from freebsd and modify some code for my board, my board is not beagleblack, so i am not sure it can work fine in BB board,to reduce phy find process, I  set phy address 4 and 6 for which phy address on my board,my board has two eth port ,I set dualmac when attach;</span></div><div><span style="font-family: 'lucida Grande', Verdana, 'Microsoft YaHei'; line-height: 23.8px;">can somebody test it on beaglebone and merge to beaglebone  bsp?</span></div><div><span style="font-family: 'lucida Grande', Verdana, 'Microsoft YaHei'; line-height: 23.8px;"><br></span></div></div></div></div>