svn commit: r208165 - in head/sys: kern mips/conf mips/include mips/mips mips/rmi mips/rmi/dev/xlr

Randall Stewart rrs at FreeBSD.org
Sun May 16 19:43:49 UTC 2010


Author: rrs
Date: Sun May 16 19:43:48 2010
New Revision: 208165
URL: http://svn.freebsd.org/changeset/base/208165

Log:
  This pushes all of JC's patches that I have in place. I
  am now able to run 32 cores ok.. but I still will hang
  on buildworld with a NFS problem. I suspect I am missing
  a patch for the netlogic rge driver.
  
  JC check and see if I am missing anything except your
  core-mask changes
  
  Obtained from:	JC

Modified:
  head/sys/kern/sched_ule.c
  head/sys/kern/subr_smp.c
  head/sys/mips/conf/XLR
  head/sys/mips/include/locore.h
  head/sys/mips/include/param.h
  head/sys/mips/include/smp.h
  head/sys/mips/mips/cpu.c
  head/sys/mips/mips/machdep.c
  head/sys/mips/mips/mp_machdep.c
  head/sys/mips/mips/mpboot.S
  head/sys/mips/mips/pmap.c
  head/sys/mips/rmi/dev/xlr/rge.c
  head/sys/mips/rmi/files.xlr
  head/sys/mips/rmi/interrupt.h
  head/sys/mips/rmi/intr_machdep.c
  head/sys/mips/rmi/iodi.c
  head/sys/mips/rmi/on_chip.c
  head/sys/mips/rmi/pic.h
  head/sys/mips/rmi/xlr_machdep.c
  head/sys/mips/rmi/xlr_pci.c
  head/sys/mips/rmi/xlrconfig.h

Modified: head/sys/kern/sched_ule.c
==============================================================================
--- head/sys/kern/sched_ule.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/kern/sched_ule.c	Sun May 16 19:43:48 2010	(r208165)
@@ -80,7 +80,7 @@ dtrace_vtime_switch_func_t	dtrace_vtime_
 #include <machine/cpu.h>
 #include <machine/smp.h>
 
-#if defined(__sparc64__) || defined(__mips__)
+#if defined(__sparc64__)
 #error "This architecture is not currently compatible with ULE"
 #endif
 

Modified: head/sys/kern/subr_smp.c
==============================================================================
--- head/sys/kern/subr_smp.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/kern/subr_smp.c	Sun May 16 19:43:48 2010	(r208165)
@@ -503,7 +503,10 @@ smp_topo_none(void)
 	top = &group[0];
 	top->cg_parent = NULL;
 	top->cg_child = NULL;
-	top->cg_mask = (1 << mp_ncpus) - 1;
+	if (mp_ncpus == sizeof(top->cg_mask) * 8)
+		top->cg_mask = -1;
+	else
+		top->cg_mask = (1 << mp_ncpus) - 1;
 	top->cg_count = mp_ncpus;
 	top->cg_children = 0;
 	top->cg_level = CG_SHARE_NONE;

Modified: head/sys/mips/conf/XLR
==============================================================================
--- head/sys/mips/conf/XLR	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/conf/XLR	Sun May 16 19:43:48 2010	(r208165)
@@ -59,10 +59,11 @@ include		"../rmi/std.xlr"
 makeoptions	DEBUG=-g		# Build kernel with gdb(1) debug symbols
 #profile		2
 
-#options 	SCHED_ULE		# ULE scheduler
+options 	SCHED_ULE		# ULE scheduler
 #options		VERBOSE_SYSINIT
-options 	SCHED_4BSD		# 4BSD scheduler
-#options 	PREEMPTION		# Enable kernel thread preemption
+#options 	SCHED_4BSD		# 4BSD scheduler
+options         SMP
+options 	PREEMPTION		# Enable kernel thread preemption
 #options 	FULL_PREEMPTION		# Enable kernel thread preemption
 options 	INET			# InterNETworking
 options 	INET6			# IPv6 communications protocols

Modified: head/sys/mips/include/locore.h
==============================================================================
--- head/sys/mips/include/locore.h	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/include/locore.h	Sun May 16 19:43:48 2010	(r208165)
@@ -60,6 +60,7 @@ typedef int mips_prid_t;
 				/*	0x09	unannounced */
 				/*	0x0a	unannounced */
 #define     MIPS_PRID_CID_LEXRA		0x0b	/* Lexra */
+#define     MIPS_PRID_CID_RMI		0x0c	/* RMI */
 #define     MIPS_PRID_CID_CAVIUM	0x0d	/* Cavium */
 #define MIPS_PRID_COPTS(x)	(((x) >> 24) & 0x00ff)	/* Company Options */
 

Modified: head/sys/mips/include/param.h
==============================================================================
--- head/sys/mips/include/param.h	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/include/param.h	Sun May 16 19:43:48 2010	(r208165)
@@ -70,7 +70,7 @@
 #define	MID_MACHINE	0	/* None but has to be defined */
 
 #ifdef SMP
-#define	MAXSMPCPU	16
+#define	MAXSMPCPU	32
 #define	MAXCPU		MAXSMPCPU
 #else
 #define	MAXSMPCPU	1

Modified: head/sys/mips/include/smp.h
==============================================================================
--- head/sys/mips/include/smp.h	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/include/smp.h	Sun May 16 19:43:48 2010	(r208165)
@@ -26,6 +26,7 @@
 #define	IPI_AST			0x0004
 #define	IPI_STOP		0x0008
 #define	IPI_STOP_HARD		0x0008
+#define	IPI_PREEMPT		0x0010
 
 #ifndef LOCORE
 

Modified: head/sys/mips/mips/cpu.c
==============================================================================
--- head/sys/mips/mips/cpu.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/mips/cpu.c	Sun May 16 19:43:48 2010	(r208165)
@@ -178,6 +178,9 @@ cpu_identify(void)
 	case MIPS_PRID_CID_LEXRA:
 		printf("Lexra");
 		break;
+	case MIPS_PRID_CID_RMI:
+		printf("RMI");
+		break;
 	case MIPS_PRID_CID_CAVIUM:
 		printf("Cavium");
 		break;

Modified: head/sys/mips/mips/machdep.c
==============================================================================
--- head/sys/mips/mips/machdep.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/mips/machdep.c	Sun May 16 19:43:48 2010	(r208165)
@@ -346,7 +346,7 @@ mips_vector_init(void)
 	bcopy(MipsTLBMiss, (void *)TLB_MISS_EXC_VEC,
 	      MipsTLBMissEnd - MipsTLBMiss);
 
-#ifdef TARGET_OCTEON
+#if defined(TARGET_OCTEON) || defined(TARGET_XLR_XLS)
 /* Fake, but sufficient, for the 32-bit with 64-bit hardware addresses  */
 	bcopy(MipsTLBMiss, (void *)XTLB_MISS_EXC_VEC,
 	      MipsTLBMissEnd - MipsTLBMiss);

Modified: head/sys/mips/mips/mp_machdep.c
==============================================================================
--- head/sys/mips/mips/mp_machdep.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/mips/mp_machdep.c	Sun May 16 19:43:48 2010	(r208165)
@@ -141,6 +141,10 @@ mips_ipi_handler(void *arg)
 			atomic_clear_int(&stopped_cpus, cpumask);
 			CTR0(KTR_SMP, "IPI_STOP (restart)");
 			break;
+		case IPI_PREEMPT:
+			CTR1(KTR_SMP, "%s: IPI_PREEMPT", __func__);
+			sched_preempt(curthread);
+			break;
 		default:
 			panic("Unknown IPI 0x%0x on cpu %d", ipi, curcpu);
 		}
@@ -234,7 +238,9 @@ cpu_mp_start(void)
 void
 smp_init_secondary(u_int32_t cpuid)
 {
+#ifndef TARGET_XLR_XLS
 	int ipi_int_mask, clock_int_mask;
+#endif
 
 	/* TLB */
 	Mips_SetWIRED(0);
@@ -288,12 +294,16 @@ smp_init_secondary(u_int32_t cpuid)
 	while (smp_started == 0)
 		; /* nothing */
 
+#ifndef TARGET_XLR_XLS
 	/*
 	 * Unmask the clock and ipi interrupts.
 	 */
 	clock_int_mask = hard_int_mask(5);
 	ipi_int_mask = hard_int_mask(platform_ipi_intrnum());
 	set_intr_mask(ALL_INT_MASK & ~(ipi_int_mask | clock_int_mask));
+#else
+	platform_init_ap(cpuid);
+#endif
 
 	/*
 	 * Bootstrap the compare register.

Modified: head/sys/mips/mips/mpboot.S
==============================================================================
--- head/sys/mips/mips/mpboot.S	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/mips/mpboot.S	Sun May 16 19:43:48 2010	(r208165)
@@ -76,9 +76,10 @@ GLOBAL(mpentry)
 
 	PTR_LA	gp, _C_LABEL(_gp)
 
+#ifndef TARGET_XLR_XLS
 	jal	platform_init_ap
 	move	a0, s0
-
+#endif
 	jal	smp_init_secondary
 	move	a0, s0
 

Modified: head/sys/mips/mips/pmap.c
==============================================================================
--- head/sys/mips/mips/pmap.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/mips/pmap.c	Sun May 16 19:43:48 2010	(r208165)
@@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$");
 
 #include <vm/vm.h>
 #include <vm/vm_param.h>
+#include <vm/vm_phys.h>
 #include <sys/lock.h>
 #include <sys/mutex.h>
 #include <vm/vm_kern.h>
@@ -109,6 +110,10 @@ __FBSDID("$FreeBSD$");
 #define	PMAP_SHPGPERPROC 200
 #endif
 
+#if defined(TARGET_XLR_XLS)
+#define HIGHMEM_SUPPORT
+#endif
+
 #if !defined(PMAP_DIAGNOSTIC)
 #define	PMAP_INLINE __inline
 #else
@@ -183,12 +188,18 @@ static int pmap_unuse_pt(pmap_t, vm_offs
 static int init_pte_prot(vm_offset_t va, vm_page_t m, vm_prot_t prot);
 static void pmap_TLB_invalidate_kernel(vm_offset_t);
 static void pmap_TLB_update_kernel(vm_offset_t, pt_entry_t);
+static vm_page_t pmap_alloc_pte_page(pmap_t, unsigned int, int, vm_offset_t *);
+static void pmap_release_pte_page(vm_page_t);
 
 #ifdef SMP
 static void pmap_invalidate_page_action(void *arg);
 static void pmap_invalidate_all_action(void *arg);
 static void pmap_update_page_action(void *arg);
+#endif
 
+#ifdef HIGHMEM_SUPPORT
+static void * pmap_ptpgzone_allocf(uma_zone_t, int, u_int8_t*, int);
+static uma_zone_t ptpgzone;
 #endif
 
 struct local_sysmaps {
@@ -530,6 +541,12 @@ pmap_init(void)
 	pv_entry_max = PMAP_SHPGPERPROC * maxproc + cnt.v_page_count;
 	pv_entry_high_water = 9 * (pv_entry_max / 10);
 	uma_zone_set_obj(pvzone, &pvzone_obj, pv_entry_max);
+
+#ifdef HIGHMEM_SUPPORT
+	ptpgzone = uma_zcreate("PT ENTRY", PAGE_SIZE, NULL,
+	    NULL, NULL, NULL, PAGE_SIZE-1, UMA_ZONE_NOFREE);
+	uma_zone_set_allocf(ptpgzone, pmap_ptpgzone_allocf);
+#endif
 }
 
 /***************************************************
@@ -887,7 +904,7 @@ _pmap_unwire_pte_hold(pmap_t pmap, vm_pa
 	/*
 	 * If the page is finally unwired, simply free it.
 	 */
-	vm_page_free_zero(m);
+	pmap_release_pte_page(m);
 	atomic_subtract_int(&cnt.v_wire_count, 1);
 	return (1);
 }
@@ -947,6 +964,118 @@ pmap_pinit0(pmap_t pmap)
 	bzero(&pmap->pm_stats, sizeof pmap->pm_stats);
 }
 
+#ifdef HIGHMEM_SUPPORT
+static void *
+pmap_ptpgzone_allocf(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
+{
+	vm_page_t m;
+	vm_paddr_t paddr;
+
+	*flags = UMA_SLAB_PRIV;
+	m = vm_phys_alloc_contig(1, 0, MIPS_KSEG0_LARGEST_PHYS,
+	     PAGE_SIZE, PAGE_SIZE);
+	if (m == NULL)
+		return (NULL);
+
+	paddr = VM_PAGE_TO_PHYS(m);
+	return ((void *)MIPS_PHYS_TO_KSEG0(paddr));
+}	
+
+static vm_page_t
+pmap_alloc_pte_page(pmap_t pmap, unsigned int index, int wait, vm_offset_t *vap)
+{
+	vm_paddr_t paddr;
+	void *va;
+	vm_page_t m;
+	int locked;
+
+	locked = mtx_owned(&pmap->pm_mtx);
+	if (locked) {
+		mtx_assert(&vm_page_queue_mtx, MA_OWNED);
+		PMAP_UNLOCK(pmap);
+		vm_page_unlock_queues();
+	}
+	va = uma_zalloc(ptpgzone, wait);
+	if (locked) {
+		vm_page_lock_queues();
+		PMAP_LOCK(pmap);
+	}
+	if (va == NULL)
+		return (NULL);
+
+	paddr = MIPS_KSEG0_TO_PHYS(va);
+	m = PHYS_TO_VM_PAGE(paddr);
+	
+	if ((m->flags & PG_ZERO) == 0)
+		bzero(va, PAGE_SIZE);
+	m->pindex = index;
+	m->valid = VM_PAGE_BITS_ALL;
+	m->wire_count = 1;
+	atomic_add_int(&cnt.v_wire_count, 1);
+	*vap = (vm_offset_t)va;
+	return (m);
+}
+
+static void
+pmap_release_pte_page(vm_page_t m)
+{
+	void *va;
+	vm_paddr_t paddr;
+
+	paddr = VM_PAGE_TO_PHYS(m);
+	va = (void *)MIPS_PHYS_TO_KSEG0(paddr);
+	uma_zfree(ptpgzone, va);
+}
+#else
+static vm_page_t
+pmap_alloc_pte_page(pmap_t pmap, unsigned int index, int wait, vm_offset_t *vap)
+{
+	vm_offset_t va;
+	vm_page_t m;
+	int locked, req;
+
+	locked = mtx_owned(&pmap->pm_mtx);
+	req = VM_ALLOC_WIRED | VM_ALLOC_NOOBJ;
+	if (wait & M_WAITOK)
+		req |= VM_ALLOC_NORMAL;
+	else
+		req |= VM_ALLOC_INTERRUPT;
+
+	m = vm_page_alloc(NULL, index, req);
+	if (m == NULL) {
+		if (wait & M_WAITOK) {
+			if (locked) {
+				mtx_assert(&vm_page_queue_mtx, MA_OWNED);
+				PMAP_UNLOCK(pmap);
+				vm_page_unlock_queues();
+			}
+			VM_WAIT;
+			if (locked) {
+				vm_page_lock_queues();
+				PMAP_LOCK(pmap);
+			}
+		}
+		return NULL;
+	}
+	
+	va = MIPS_PHYS_TO_KSEG0(VM_PAGE_TO_PHYS(m));
+	if ((m->flags & PG_ZERO) == 0)
+		bzero((void *)va, PAGE_SIZE);
+	else
+		vm_page_flag_clear(m, PG_ZERO);
+	
+	m->valid = VM_PAGE_BITS_ALL;
+	*vap = (vm_offset_t)va;
+	return (m);
+}
+
+static void
+pmap_release_pte_page(vm_page_t m)
+{
+	vm_page_free(m);
+}
+#endif
+
 /*
  * Initialize a preallocated and zeroed pmap structure,
  * such as one in a vmspace structure.
@@ -955,37 +1084,16 @@ int
 pmap_pinit(pmap_t pmap)
 {
 	vm_offset_t ptdva;
-	vm_paddr_t ptdpa;
 	vm_page_t ptdpg;
 	int i;
-	int req;
 
 	PMAP_LOCK_INIT(pmap);
 
-	req = VM_ALLOC_NOOBJ | VM_ALLOC_NORMAL | VM_ALLOC_WIRED |
-	    VM_ALLOC_ZERO;
-
 	/*
 	 * allocate the page directory page
 	 */
-	while ((ptdpg = vm_page_alloc(NULL, NUSERPGTBLS, req)) == NULL)
-		VM_WAIT;
-
-	ptdpg->valid = VM_PAGE_BITS_ALL;
-
-	ptdpa = VM_PAGE_TO_PHYS(ptdpg);
-	if (ptdpa < MIPS_KSEG0_LARGEST_PHYS) {
-		ptdva = MIPS_PHYS_TO_KSEG0(ptdpa);
-	} else {
-		ptdva = kmem_alloc_nofault(kernel_map, PAGE_SIZE);
-		if (ptdva == 0)
-			panic("pmap_pinit: unable to allocate kva");
-		pmap_kenter(ptdva, ptdpa);
-	}
-
+	ptdpg = pmap_alloc_pte_page(pmap, NUSERPGTBLS, M_WAITOK, &ptdva);
 	pmap->pm_segtab = (pd_entry_t *)ptdva;
-	if ((ptdpg->flags & PG_ZERO) == 0)
-		bzero(pmap->pm_segtab, PAGE_SIZE);
 
 	pmap->pm_active = 0;
 	pmap->pm_ptphint = NULL;
@@ -1006,7 +1114,7 @@ pmap_pinit(pmap_t pmap)
 static vm_page_t
 _pmap_allocpte(pmap_t pmap, unsigned ptepindex, int flags)
 {
-	vm_offset_t pteva, ptepa;
+	vm_offset_t pteva;
 	vm_page_t m;
 	int req;
 
@@ -1018,25 +1126,9 @@ _pmap_allocpte(pmap_t pmap, unsigned pte
 	/*
 	 * Find or fabricate a new pagetable page
 	 */
-	if ((m = vm_page_alloc(NULL, ptepindex, req)) == NULL) {
-		if (flags & M_WAITOK) {
-			PMAP_UNLOCK(pmap);
-			vm_page_unlock_queues();
-			VM_WAIT;
-			vm_page_lock_queues();
-			PMAP_LOCK(pmap);
-		}
-		/*
-		 * Indicate the need to retry.	While waiting, the page
-		 * table page may have been allocated.
-		 */
+	m = pmap_alloc_pte_page(pmap, ptepindex, flags, &pteva);
+	if (m == NULL)
 		return (NULL);
-	}
-	if ((m->flags & PG_ZERO) == 0)
-		pmap_zero_page(m);
-
-	KASSERT(m->queue == PQ_NONE,
-	    ("_pmap_allocpte: %p->queue != PQ_NONE", m));
 
 	/*
 	 * Map the pagetable page into the process address space, if it
@@ -1044,34 +1136,12 @@ _pmap_allocpte(pmap_t pmap, unsigned pte
 	 */
 
 	pmap->pm_stats.resident_count++;
-
-	ptepa = VM_PAGE_TO_PHYS(m);
-	if (ptepa < MIPS_KSEG0_LARGEST_PHYS) {
-		pteva = MIPS_PHYS_TO_KSEG0(ptepa);
-	} else {
-		pteva = kmem_alloc_nofault(kernel_map, PAGE_SIZE);
-		if (pteva == 0)
-			panic("_pmap_allocpte: unable to allocate kva");
-		pmap_kenter(pteva, ptepa);
-	}
-
 	pmap->pm_segtab[ptepindex] = (pd_entry_t)pteva;
 
 	/*
 	 * Set the page table hint
 	 */
 	pmap->pm_ptphint = m;
-
-	/*
-	 * Kernel page tables are allocated in pmap_bootstrap() or
-	 * pmap_growkernel().
-	 */
-	if (is_kernel_pmap(pmap))
-		panic("_pmap_allocpte() called for kernel pmap\n");
-
-	m->valid = VM_PAGE_BITS_ALL;
-	vm_page_flag_clear(m, PG_ZERO);
-
 	return (m);
 }
 
@@ -1158,17 +1228,12 @@ pmap_release(pmap_t pmap)
 	ptdva = (vm_offset_t)pmap->pm_segtab;
 	ptdpg = PHYS_TO_VM_PAGE(vtophys(ptdva));
 
-	if (ptdva >= VM_MIN_KERNEL_ADDRESS) {
-		pmap_kremove(ptdva);
-		kmem_free(kernel_map, ptdva, PAGE_SIZE);
-	} else {
-		KASSERT(MIPS_IS_KSEG0_ADDR(ptdva),
-		    ("pmap_release: 0x%0lx is not in kseg0", (long)ptdva));
-	}
+	KASSERT(MIPS_IS_KSEG0_ADDR(ptdva),
+	    ("pmap_release: 0x%0lx is not in kseg0", (long)ptdva));
 
 	ptdpg->wire_count--;
 	atomic_subtract_int(&cnt.v_wire_count, 1);
-	vm_page_free_zero(ptdpg);
+	pmap_release_pte_page(ptdpg);
 	PMAP_LOCK_DESTROY(pmap);
 }
 
@@ -1178,10 +1243,10 @@ pmap_release(pmap_t pmap)
 void
 pmap_growkernel(vm_offset_t addr)
 {
-	vm_offset_t ptppaddr;
+	vm_offset_t pageva;
 	vm_page_t nkpg;
 	pt_entry_t *pte;
-	int i, req;
+	int i;
 
 	mtx_assert(&kernel_map->system_mtx, MA_OWNED);
 	if (kernel_vm_end == 0) {
@@ -1213,26 +1278,13 @@ pmap_growkernel(vm_offset_t addr)
 		/*
 		 * This index is bogus, but out of the way
 		 */
-		req = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED | VM_ALLOC_NOOBJ;
-		nkpg = vm_page_alloc(NULL, nkpt, req);
+		nkpg = pmap_alloc_pte_page(kernel_pmap, nkpt, M_NOWAIT, &pageva);
+
 		if (!nkpg)
 			panic("pmap_growkernel: no memory to grow kernel");
 
 		nkpt++;
-
-		ptppaddr = VM_PAGE_TO_PHYS(nkpg);
-		if (ptppaddr >= MIPS_KSEG0_LARGEST_PHYS) {
-			/*
-			 * We need to do something here, but I am not sure
-			 * what. We can access anything in the 0 - 512Meg
-			 * region, but if we get a page to go in the kernel
-			 * segmap that is outside of of that we really need
-			 * to have another mapping beyond the temporary ones
-			 * I have. Not sure how to do this yet. FIXME FIXME.
-			 */
-			panic("Gak, can't handle a k-page table outside of lower 512Meg");
-		}
-		pte = (pt_entry_t *)MIPS_PHYS_TO_KSEG0(ptppaddr);
+		pte = (pt_entry_t *)pageva;
 		segtab_pde(kernel_segmap, kernel_vm_end) = (pd_entry_t)pte;
 
 		/*
@@ -1396,7 +1448,8 @@ pmap_remove_entry(struct pmap *pmap, vm_
 		}
 	}
 
-	KASSERT(pv != NULL, ("pmap_remove_entry: pv not found"));
+	KASSERT(pv != NULL, ("pmap_remove_entry: pv not found, pa %lx va %lx",
+	     (u_long)VM_PAGE_TO_PHYS(m), (u_long)va));
 	TAILQ_REMOVE(&m->md.pv_list, pv, pv_list);
 	m->md.pv_list_count--;
 	if (TAILQ_FIRST(&m->md.pv_list) == NULL)

Modified: head/sys/mips/rmi/dev/xlr/rge.c
==============================================================================
--- head/sys/mips/rmi/dev/xlr/rge.c	Sun May 16 19:25:56 2010	(r208164)
+++ head/sys/mips/rmi/dev/xlr/rge.c	Sun May 16 19:43:48 2010	(r208165)
@@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
 #define __RMAN_RESOURCE_VISIBLE
 #include <sys/rman.h>
 #include <sys/taskqueue.h>
+#include <sys/smp.h>
 
 #include <net/if.h>
 #include <net/if_arp.h>
@@ -83,6 +84,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/param.h>
 #include <machine/intr_machdep.h>
 #include <machine/clock.h>	/* for DELAY */
+#include <machine/cpuregs.h>
 #include <machine/bus.h>	/* */
 #include <machine/resource.h>
 #include <mips/rmi/interrupt.h>
@@ -112,7 +114,6 @@ MODULE_DEPEND(rge, ether, 1, 1, 1);
 MODULE_DEPEND(rge, miibus, 1, 1, 1);
 
 /* #define DEBUG */
-/*#define RX_COPY */
 
 #define RGE_TX_THRESHOLD 1024
 #define RGE_TX_Q_SIZE 1024
@@ -204,10 +205,18 @@ ldadd_wu(unsigned int value, unsigned lo
 	return value;
 }
 
+static __inline__ uint32_t 
+xlr_enable_kx(void)
+{
+	uint32_t sr = mips_rd_status();
+
+	mips_wr_status((sr & ~MIPS_SR_INT_IE) | MIPS_SR_KX);
+	return sr;
+}
+
 /* #define mac_stats_add(x, val) ({(x) += (val);}) */
 #define mac_stats_add(x, val) ldadd_wu(val, &x)
 
-
 #define XLR_MAX_CORE 8
 #define RGE_LOCK_INIT(_sc, _name) \
   mtx_init(&(_sc)->rge_mtx, _name, MTX_NETWORK_LOCK, MTX_DEF)
@@ -332,56 +341,6 @@ DRIVER_MODULE(miibus, rge, miibus_driver
 #define STR(x) __STR(x)
 #endif
 
-#define XKPHYS        0x8000000000000000
-/* -- No longer needed RRS
-static __inline__ uint32_t
-lw_40bit_phys(uint64_t phys, int cca)
-{
-	uint64_t addr;
-	uint32_t value = 0;
-	unsigned long flags;
-
-	addr = XKPHYS | ((uint64_t) cca << 59) | (phys & 0xfffffffffcULL);
-
-	enable_KX(flags);
-	__asm__ __volatile__(
-	            ".set push\n"
-	            ".set noreorder\n"
-	            ".set mips64\n"
-	            "lw    %0, 0(%1) \n"
-	            ".set pop\n"
-	    :       "=r"(value)
-	    :       "r"(addr));
-
-	disable_KX(flags);
-	return value;
-}
-*/
-/* -- No longer used RRS
-static __inline__ uint64_t
-ld_40bit_phys(uint64_t phys, int cca)
-{
-	uint64_t addr;
-	uint64_t value = 0;
-	unsigned long flags;
-
-
-	addr = XKPHYS | ((uint64_t) cca << 59) | (phys & 0xfffffffffcULL);
-	enable_KX(flags);
-	__asm__ __volatile__(
-	            ".set push\n"
-	            ".set noreorder\n"
-	            ".set mips64\n"
-	            "ld    %0, 0(%1) \n"
-	            ".set pop\n"
-	    :       "=r"(value)
-	    :       "r"(addr));
-
-	disable_KX(flags);
-	return value;
-}
-*/
-
 void *xlr_tx_ring_mem;
 
 struct tx_desc_node {
@@ -449,7 +408,7 @@ init_p2d_allocation(void)
 
 	for (i = 0; i < 32; i++) {
 		if (cpumask & (1 << i)) {
-			cpu = cpu_ltop_map[i];
+			cpu = i;
 			if (!active_core[cpu / 4]) {
 				active_core[cpu / 4] = 1;
 				xlr_total_active_core++;
@@ -507,7 +466,7 @@ get_p2d_desc(void)
 {
 	struct tx_desc_node *node;
 	struct p2d_tx_desc *tx_desc = NULL;
-	int cpu = xlr_cpu_id();
+	int cpu = xlr_core_id();
 
 	mtx_lock_spin(&tx_desc_lock[cpu]);
 	node = TAILQ_FIRST(&tx_frag_desc[cpu]);
@@ -527,7 +486,7 @@ static void
 free_p2d_desc(struct p2d_tx_desc *tx_desc)
 {
 	struct tx_desc_node *node;
-	int cpu = xlr_cpu_id();
+	int cpu = xlr_core_id();
 
 	mtx_lock_spin(&tx_desc_lock[cpu]);
 	node = TAILQ_FIRST(&free_tx_frag_desc[cpu]);
@@ -553,7 +512,7 @@ build_frag_list(struct mbuf *m_head, str
 	vm_offset_t taddr;
 	uint64_t fr_stid;
 
-	fr_stid = (xlr_cpu_id() << 3) + xlr_thr_id() + 4;
+	fr_stid = (xlr_core_id() << 3) + xlr_thr_id() + 4;
 
 	if (tx_desc == NULL)
 		return 1;
@@ -620,21 +579,6 @@ build_frag_list(struct mbuf *m_head, str
 static void
 release_tx_desc(struct msgrng_msg *msg, int rel_buf)
 {
-	/*
-	 * OLD code: vm_paddr_t paddr = msg->msg0 & 0xffffffffffULL;
-	 * uint64_t temp; struct p2d_tx_desc *tx_desc; struct mbuf *m;
-	 * 
-	 * paddr += (XLR_MAX_TX_FRAGS * sizeof(uint64_t)); *** In o32 we will
-	 * crash here ****** temp = ld_40bit_phys(paddr, 3); tx_desc =
-	 * (struct p2d_tx_desc *)((vm_offset_t)temp);
-	 * 
-	 * if (rel_buf) { paddr += sizeof(uint64_t);
-	 * 
-	 * temp = ld_40bit_phys(paddr, 3);
-	 * 
-	 * m = (struct mbuf *)((vm_offset_t)temp); m_freem(m); } printf("Call
-	 * fre_p2d_desc\n"); free_p2d_desc(tx_desc);
-	 */
 	struct p2d_tx_desc *tx_desc, *chk_addr;
 	struct mbuf *m;
 
@@ -652,52 +596,6 @@ release_tx_desc(struct msgrng_msg *msg, 
 	free_p2d_desc(tx_desc);
 }
 
-#ifdef RX_COPY
-#define RGE_MAX_NUM_DESC (6 * MAX_NUM_DESC)
-uint8_t *rge_rx_buffers[RGE_MAX_NUM_DESC];
-static struct mtx rge_rx_mtx;
-int g_rx_buf_head;
-
-static void
-init_rx_buf(void)
-{
-	int i;
-	uint8_t *buf, *start;
-	uint32_t size, *ptr;
-
-	mtx_init(&rge_rx_mtx, "xlr rx_desc", NULL, MTX_SPIN);
-
-	size = (RGE_MAX_NUM_DESC * (MAX_FRAME_SIZE + XLR_CACHELINE_SIZE));
-
-	start = (uint8_t *) contigmalloc(size, M_DEVBUF, M_NOWAIT | M_ZERO,
-	    0, 0xffffffff, XLR_CACHELINE_SIZE, 0);
-	if (start == NULL)
-		panic("NO RX BUFFERS");
-	buf = start;
-	size = (MAX_FRAME_SIZE + XLR_CACHELINE_SIZE);
-	for (i = 0; i < RGE_MAX_NUM_DESC; i++) {
-		buf = start + (i * size);
-		ptr = (uint32_t *) buf;
-		*ptr = (uint32_t) buf;
-		rge_rx_buffers[i] = buf + XLR_CACHELINE_SIZE;
-	}
-}
-
-static void *
-get_rx_buf(void)
-{
-	void *ptr = NULL;
-
-	mtx_lock_spin(&rge_rx_mtx);
-	if (g_rx_buf_head < RGE_MAX_NUM_DESC) {
-		ptr = (void *)rge_rx_buffers[g_rx_buf_head];
-		g_rx_buf_head++;
-	}
-	mtx_unlock_spin(&rge_rx_mtx);
-	return ptr;
-}
-
-#endif
 
 static struct mbuf *
 get_mbuf(void)
@@ -716,23 +614,16 @@ static void
 free_buf(vm_paddr_t paddr)
 {
 	struct mbuf *m;
-	uint32_t *temp;
-	uint32_t mag, um;
+	uint32_t mag, um, sr;
+
+	sr = xlr_enable_kx();
+	um = xlr_paddr_lw(paddr - XLR_CACHELINE_SIZE);
+	mag = xlr_paddr_lw(paddr - XLR_CACHELINE_SIZE + sizeof(uint32_t));
+	mips_wr_status(sr);
 
-	/*
-	 * This will crash I think. RRS temp = lw_40bit_phys((paddr -
-	 * XLR_CACHELINE_SIZE), 3); m = (struct mbuf *)temp;
-	 */
-	/*
-	 * This gets us a kseg0 address for the mbuf/magic on the ring but
-	 * we need to get the va to free the mbuf. This is stored at *temp;
-	 */
-	temp = (uint32_t *) MIPS_PHYS_TO_KSEG0(paddr - XLR_CACHELINE_SIZE);
-	um = temp[0];
-	mag = temp[1];
 	if (mag != 0xf00bad) {
-		printf("Something is wrong kseg:%p found mag:%x not 0xf00bad\n",
-		    temp, mag);
+		printf("Something is wrong kseg:%lx found mag:%x not 0xf00bad\n",
+		    (u_long)paddr, mag);
 		return;
 	}
 	m = (struct mbuf *)um;
@@ -743,19 +634,13 @@ free_buf(vm_paddr_t paddr)
 static void *
 get_buf(void)
 {
-#ifdef RX_COPY
-	return get_rx_buf();
-#else
 	struct mbuf *m_new = NULL;
-
+	unsigned int *md;
 #ifdef INVARIANTS
 	vm_paddr_t temp1, temp2;
-
 #endif
-	unsigned int *md;
 
 	m_new = get_mbuf();
-
 	if (m_new == NULL)
 		return NULL;
 
@@ -765,8 +650,6 @@ get_buf(void)
 	md[1] = 0xf00bad;
 	m_adj(m_new, XLR_CACHELINE_SIZE);
 
-
-	/* return (void *)m_new; */
 #ifdef INVARIANTS
 	temp1 = vtophys((vm_offset_t)m_new->m_data);
 	temp2 = vtophys((vm_offset_t)m_new->m_data + 1536);
@@ -774,7 +657,6 @@ get_buf(void)
 		panic("ALLOCED BUFFER IS NOT CONTIGUOUS\n");
 #endif
 	return (void *)m_new->m_data;
-#endif
 }
 
 /**********************************************************************
@@ -826,13 +708,13 @@ xlr_mac_send_fr(struct driver_data *priv
 {
 	int stid = priv->rfrbucket;
 	struct msgrng_msg msg;
-	int vcpu = (xlr_cpu_id() << 2) + xlr_thr_id();
+	int vcpu = xlr_cpu_id();
 
 	mac_make_desc_rfr(&msg, addr);
 
 	/* Send the packet to MAC */
-	dbg_msg("mac_%d: Sending free packet %llx to stid %d\n",
-	    priv->instance, addr, stid);
+	dbg_msg("mac_%d: Sending free packet %lx to stid %d\n",
+	    priv->instance, (u_long)addr, stid);
 	if (priv->type == XLR_XGMAC) {
 		while (message_send(1, MSGRNG_CODE_XGMAC, stid, &msg));
 	} else {
@@ -1084,18 +966,25 @@ rmi_xlr_config_pde(struct driver_data *p
 	/* uint32_t desc_pack_ctrl = 0; */
 	uint32_t cpumask;
 
-	cpumask = PCPU_GET(cpumask) | PCPU_GET(other_cpus);
+	cpumask = PCPU_GET(cpumask);
+#ifdef SMP
+	/*
+         * rge may be called before SMP start in a BOOTP/NFSROOT
+         * setup. we will distribute packets to other cpus only when
+         * the SMP is started.
+	 */
+	if (smp_started)
+		cpumask |= PCPU_GET(other_cpus);
+#endif
 
-	for (i = 0; i < 32; i++) {
+	for (i = 0; i < MAXCPU; i++) {
 		if (cpumask & (1 << i)) {
-			cpu = cpu_ltop_map[i];
+			cpu = i;
 			bucket = ((cpu >> 2) << 3);
-			//|(cpu & 0x03);
 			bucket_map |= (1ULL << bucket);
-			dbg_msg("i=%d, cpu=%d, bucket = %d, bucket_map=%llx\n",
-			    i, cpu, bucket, bucket_map);
 		}
 	}
+	printf("rmi_xlr_config_pde: bucket_map=%llx\n", bucket_map);
 
 	/* bucket_map = 0x1; */
 	xlr_write_reg(priv->mmio, R_PDE_CLASS_0, (bucket_map & 0xffffffff));
@@ -1116,6 +1005,28 @@ rmi_xlr_config_pde(struct driver_data *p
 }
 
 static void
+rge_smp_update_pde(void *dummy __unused)
+{
+	int i;
+	struct driver_data *priv;
+	struct rge_softc *sc;
+
+	printf("Updating packet distribution for SMP\n");
+	for (i = 0; i < XLR_MAX_MACS; i++) {
+		sc = dev_mac[i];
+		if (!sc)
+			continue;
+		priv = &(sc->priv);
+		rmi_xlr_mac_set_enable(priv, 0);
+		rmi_xlr_config_pde(priv);
+		rmi_xlr_mac_set_enable(priv, 1);
+	}
+}
+
+SYSINIT(rge_smp_update_pde, SI_SUB_SMP, SI_ORDER_ANY, rge_smp_update_pde, NULL);
+
+
+static void
 rmi_xlr_config_parser(struct driver_data *priv)
 {
 	/*
@@ -1613,10 +1524,7 @@ retry:
 static void
 mac_frin_replenish(void *args /* ignored */ )
 {
-#ifdef RX_COPY
-	return;
-#else
-	int cpu = xlr_cpu_id();
+	int cpu = xlr_core_id();
 	int done = 0;
 	int i = 0;
 
@@ -1685,7 +1593,6 @@ mac_frin_replenish(void *args /* ignored
 		if (done == XLR_MAX_MACS)
 			break;
 	}
-#endif
 }
 
 static volatile uint32_t g_tx_frm_tx_ok=0;
@@ -1716,8 +1623,8 @@ rmi_xlr_mac_msgring_handler(int bucket, 
 	struct rge_softc *sc = NULL;
 	struct driver_data *priv = 0;
 	struct ifnet *ifp;
-	int cpu = xlr_cpu_id();
-	int vcpu = (cpu << 2) + xlr_thr_id();
+	int vcpu = xlr_cpu_id();
+	int cpu = xlr_core_id();
 
 	dbg_msg("mac: bucket=%d, size=%d, code=%d, stid=%d, msg0=%llx msg1=%llx\n",
 	    bucket, size, code, stid, msg->msg0, msg->msg1);
@@ -2098,80 +2005,18 @@ rge_release_resources(struct rge_softc *
 uint32_t gmac_rx_fail[32];
 uint32_t gmac_rx_pass[32];
 
-#ifdef RX_COPY
 static void
 rge_rx(struct rge_softc *sc, vm_paddr_t paddr, int len)
 {
-	/*
-	 * struct mbuf *m = (struct mbuf *)*(unsigned int *)((char *)addr -
-	 * XLR_CACHELINE_SIZE);
-	 */
 	struct mbuf *m;
-	void *ptr;
-	uint32_t *temp;
+	uint32_t tm, mag, sr;
 	struct ifnet *ifp = sc->rge_ifp;
-	unsigned long msgrng_flags;
-	int cpu = PCPU_GET(cpuid);
-
-
-	temp = (uint32_t *) MIPS_PHYS_TO_KSEG0(paddr - XLR_CACHELINE_SIZE);
 
-	ptr = (void *)(temp + XLR_CACHELINE_SIZE);
-	m = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
-	if (m != NULL) {
-		m->m_len = m->m_pkthdr.len = MCLBYTES;
-		m_copyback(m, 0, len + BYTE_OFFSET, ptr);
-		/* align the data */
-		m->m_data += BYTE_OFFSET;
-		m->m_pkthdr.len = m->m_len = len;
-		m->m_pkthdr.rcvif = ifp;
-		gmac_rx_pass[cpu]++;
-	} else {
-		gmac_rx_fail[cpu]++;
-	}
-	msgrng_access_enable(msgrng_flags);
-	xlr_mac_send_fr(&sc->priv, paddr, MAX_FRAME_SIZE);
-	msgrng_access_disable(msgrng_flags);
-
-#ifdef DUMP_PACKETS
-	{
-		int i = 0;
-		unsigned char *buf = (char *)m->m_data;
+	sr = xlr_enable_kx();
+	tm = xlr_paddr_lw(paddr - XLR_CACHELINE_SIZE);
+	mag = xlr_paddr_lw(paddr - XLR_CACHELINE_SIZE + sizeof(uint32_t));
+	mips_wr_status(sr);
 
-		printf("Rx Packet: length=%d\n", len);
-		for (i = 0; i < 64; i++) {
-			if (i && (i % 16) == 0)
-				printf("\n");
-			printf("%02x ", buf[i]);
-		}
-		printf("\n");
-	}
-#endif
-
-
-	if (m) {
-		ifp->if_ipackets++;
-		(*ifp->if_input) (ifp, m);
-	}
-}
-
-#else
-static void
-rge_rx(struct rge_softc *sc, vm_paddr_t paddr, int len)
-{
-	/*
-	 * struct mbuf *m = (struct mbuf *)*(unsigned int *)((char *)addr -
-	 * XLR_CACHELINE_SIZE);
-	 */
-	struct mbuf *m;
-	uint32_t *temp, tm, mag;
-
-	struct ifnet *ifp = sc->rge_ifp;
-
-
-	temp = (uint32_t *) MIPS_PHYS_TO_KSEG0(paddr - XLR_CACHELINE_SIZE);
-	tm = temp[0];
-	mag = temp[1];
 	m = (struct mbuf *)tm;
 	if (mag != 0xf00bad) {
 		/* somebody else packet Error - FIXME in intialization */
@@ -2201,8 +2046,6 @@ rge_rx(struct rge_softc *sc, vm_paddr_t 
 	(*ifp->if_input) (ifp, m);
 }
 
-#endif

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list