1/*- 2 * Copyright (c) 2003-2009 RMI Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 31 unchanged lines hidden (view full) --- 40 * The XLS device supports upto 8 10/100/1000 Ethernet MACs or max 2 10G 41 * Ethernet MACs. The 1G MACs are of SGMII and 10G MACs are of XAUI 42 * interface. These ports are part of two network accelerators. 43 * The nlge driver configures and initializes non-SPI4 Ethernet ports in the 44 * XLR/XLS devices and enables data transfer on them. 45 */ 46 47#include <sys/cdefs.h> |
48__FBSDID("$FreeBSD: head/sys/mips/rmi/dev/nlge/if_nlge.c 212758 2010-09-16 19:13:55Z jchandra $"); |
49 50#ifdef HAVE_KERNEL_OPTION_HEADERS 51#include "opt_device_polling.h" 52#endif 53 54#include <sys/endian.h> 55#include <sys/systm.h> 56#include <sys/sockio.h> --- 238 unchanged lines hidden (view full) --- 295static devclass_t nlge_devclass; 296 297DRIVER_MODULE(nlna, iodi, nlna_driver, nlna_devclass, 0, 0); 298DRIVER_MODULE(nlge, nlna, nlge_driver, nlge_devclass, 0, 0); 299DRIVER_MODULE(miibus, nlge, miibus_driver, miibus_devclass, 0, 0); 300 301static uma_zone_t nl_tx_desc_zone; 302 |
303static __inline void 304atomic_incr_long(unsigned long *addr) |
305{ |
306 /* XXX: fix for 64 bit */ 307 unsigned int *iaddr = (unsigned int *)addr; |
308 |
309 xlr_ldaddwu(1, iaddr); |
310} 311 312static int 313nlna_probe(device_t dev) 314{ 315 return (BUS_PROBE_DEFAULT); 316} 317 --- 342 unchanged lines hidden (view full) --- 660 } else { 661 m_freem((struct mbuf *)(uintptr_t)phys_addr); 662 } 663 664 ifp = sc->nlge_if; 665 if (ifp->if_drv_flags & IFF_DRV_OACTIVE){ 666 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; 667 } |
668 atomic_incr_long((tx_error) ? &ifp->if_oerrors: &ifp->if_opackets); |
669 } else if (ctrl == CTRL_SNGL || ctrl == CTRL_START) { 670 /* Rx Packet */ 671 672 nlge_rx(sc, phys_addr, length); 673 nlna_submit_rx_free_desc(na_sc, 1); /* return free descr to NA */ 674 } else { 675 printf("[%s]: unrecognized ctrl=%d!\n", __FUNCTION__, ctrl); 676 } --- 66 unchanged lines hidden (view full) --- 743 * able to add to it not invoke nlge_start to drian the 744 * queue. The driver may have to do something in addition 745 * to reset'ing the OACTIVE bit when a trasnmit free-back 746 * is received. 747 */ 748 //ifp->if_drv_flags |= IFF_DRV_OACTIVE; 749 //IF_PREPEND(&ifp->if_snd, m); 750 m_freem(m); |
751 atomic_incr_long(&ifp->if_iqdrops); |
752 } 753 return; 754} 755 756static void 757nlge_rx(struct nlge_softc *sc, vm_paddr_t paddr, int len) 758{ |
759 struct ifnet *ifp; 760 struct mbuf *m; 761 uint64_t tm, mag; 762 uint32_t sr; |
763 764 sr = xlr_enable_kx(); |
765 tm = xlr_paddr_ld(paddr - XLR_CACHELINE_SIZE); 766 mag = xlr_paddr_ld(paddr - XLR_CACHELINE_SIZE + sizeof(uint64_t)); 767 xlr_restore_kx(sr); |
768 769 m = (struct mbuf *)(intptr_t)tm; 770 if (mag != 0xf00bad) { 771 /* somebody else's packet. Error - FIXME in intialization */ 772 printf("cpu %d: *ERROR* Not my packet paddr %llx\n", 773 xlr_core_id(), (uint64_t) paddr); 774 return; 775 } 776 777 ifp = sc->nlge_if; 778 /* align the data */ 779 m->m_data += BYTE_OFFSET; 780 m->m_pkthdr.len = m->m_len = len; 781 m->m_pkthdr.rcvif = ifp; 782 |
783 atomic_incr_long(&ifp->if_ipackets); |
784 (*ifp->if_input)(ifp, m); 785} 786 787static int 788nlge_mii_write(struct device *dev, int phyaddr, int regidx, int regval) 789{ 790 struct nlge_softc *sc; 791 --- 1081 unchanged lines hidden (view full) --- 1873 1874 while (len) { 1875 if (msg_sz == (FMN_SZ - 1)) { 1876 p2p = uma_zalloc(nl_tx_desc_zone, M_NOWAIT); 1877 if (p2p == NULL) { 1878 return 2; 1879 } 1880 /* |
1881 * Save the virtual address in the descriptor, 1882 * it makes freeing easy. |
1883 */ 1884 p2p->frag[XLR_MAX_TX_FRAGS] = |
1885 (uint64_t)(vm_offset_t)p2p; |
1886 cur_p2d = &p2p->frag[0]; 1887 is_p2p = 1; 1888 } else if (msg_sz == (FMN_SZ - 2 + XLR_MAX_TX_FRAGS)) { 1889 uma_zfree(nl_tx_desc_zone, p2p); 1890 return 1; 1891 } 1892 paddr = vtophys(buf); 1893 frag_sz = PAGE_SIZE - (buf & PAGE_MASK); --- 12 unchanged lines hidden (view full) --- 1906 if (msg_sz == 0) { 1907 printf("Zero-length mbuf chain ??\n"); 1908 *n_entries = msg_sz ; 1909 return 0; 1910 } 1911 1912 cur_p2d[-1] |= (1ULL << 63); /* set eop in most-recent p2d */ 1913 *cur_p2d = (1ULL << 63) | ((uint64_t)fb_stn_id << 54) | |
1914 (vm_offset_t) mbuf_chain; /* XXX: fix 64 bit */ |
1915 *tx_desc = p2p; 1916 1917 if (is_p2p) { 1918 paddr = vtophys(p2p); 1919 p2p_sz++; 1920 fmn_msg->msg3 = (1ULL << 62) | ((uint64_t)fb_stn_id << 54) | 1921 ((uint64_t)(p2p_sz * 8) << 40) | paddr; 1922 *n_entries = FMN_SZ; --- 24 unchanged lines hidden (view full) --- 1947 return (0); 1948} 1949 1950static void 1951release_tx_desc(vm_paddr_t paddr) 1952{ 1953 struct nlge_tx_desc *tx_desc; 1954 uint32_t sr; |
1955 uint64_t vaddr; |
1956 1957 paddr += (XLR_MAX_TX_FRAGS * sizeof(uint64_t)); 1958 sr = xlr_enable_kx(); |
1959 vaddr = xlr_paddr_ld(paddr); 1960 xlr_restore_kx(sr); |
1961 |
1962 tx_desc = (struct nlge_tx_desc*)(intptr_t)vaddr; |
1963 uma_zfree(nl_tx_desc_zone, tx_desc); 1964} 1965 1966static void * 1967get_buf(void) 1968{ |
1969 struct mbuf *m_new; 1970 uint64_t *md; 1971#ifdef INVARIANTS 1972 vm_paddr_t temp1, temp2; 1973#endif |
1974 1975 if ((m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR)) == NULL) |
1976 return (NULL); |
1977 m_new->m_len = m_new->m_pkthdr.len = MCLBYTES; 1978 m_adj(m_new, XLR_CACHELINE_SIZE - ((unsigned int)m_new->m_data & 0x1f)); |
1979 md = (uint64_t *)m_new->m_data; 1980 md[0] = (intptr_t)m_new; /* Back Ptr */ |
1981 md[1] = 0xf00bad; 1982 m_adj(m_new, XLR_CACHELINE_SIZE); 1983 |
1984#ifdef INVARIANTS |
1985 temp1 = vtophys((vm_offset_t) m_new->m_data); 1986 temp2 = vtophys((vm_offset_t) m_new->m_data + 1536); 1987 if ((temp1 + 1536) != temp2) 1988 panic("ALLOCED BUFFER IS NOT CONTIGUOUS\n"); |
1989#endif |
1990 1991 return ((void *)m_new->m_data); 1992} 1993 1994static int 1995nlge_gmac_config_speed(struct nlge_softc *sc, int quick) 1996{ 1997 struct mii_data *md; --- 382 unchanged lines hidden --- |