Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Jul 2010 03:09:21 GMT
From:      Alexandre Fiveg <afiveg@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180741 for review
Message-ID:  <201007110309.o6B39Lr2057896@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@180741?ac=10

Change 180741 by afiveg@cottonmouth on 2010/07/11 03:08:49

	d_mmap is eliminated from ringmap because of very strange behavior. Now: user-space process calls read(/dev/ringmap ... ) in order get physical addres of ring. Then by calling mmap(/dev/mem, .... , offset=ring_phys_addr) the ring will be mapped into user-space.

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#8 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#8 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#10 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#15 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#23 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#22 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#20 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#12 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#26 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#26 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#10 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#11 edit
.. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#6 edit
.. //depot/projects/soc2010/ringmap/tests/ringmap/main.c#4 edit
.. //depot/projects/soc2010/ringmap/tests/ringmap/mmap.c#4 edit
.. //depot/projects/soc2010/ringmap/tests/ringmap/open.c#4 edit
.. //depot/projects/soc2010/ringmap/tests/ringmap/tests.h#4 edit

Differences ...

==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#8 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#8 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#10 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#15 (text+ko) ====

@@ -56,6 +56,7 @@
 	char dev_path[1024];
 	struct ring tmp_ring;
 	off_t memoffset = 0; 
+	vm_paddr_t ring;
 	bus_addr_t 	rspp;
 
 	RINGMAP_FUNC_DEBUG(start);
@@ -84,13 +85,21 @@
 	 ** Here we map the ring structure into the 
 	 ** memory space of current process.
 	 **/
+	if (read(ringmap_cdev_fd, &ring, sizeof(vm_paddr_t)) == -1) {
+		RINGMAP_ERROR(Can not read phys addr of ring from kernel);
+		return (-1);
+	}
+#ifdef __RINGMAP_DEB
+	printf("[%s] Phys addr of ring 0x%X\n", __func__, ring);
+#endif
+
 	tmp_addr = 
 			mmap(	0, 				/* Kernel gives us the address */
 			sizeof(struct ring), 	/* Number of bytes we are mapping */
 			PROT_WRITE|PROT_READ,	/* We want both read and write */
 			MAP_SHARED, 			/* Changes shoud be visible in kernel */
-			ringmap_cdev_fd, 		/* file decriptor */
-			0);
+			devmem_fd, 				/* /dev/mem device */
+			ring);					/* offset = phys addr of ring */
 	if (tmp_addr == MAP_FAILED){
 		RINGMAP_ERROR("Mapping of Ring Pointers structure failed! Exit!");
 		return -1;
@@ -101,6 +110,10 @@
 		RINGMAP_ERROR("Wrong size of ring buffer!");
 		return -1;
 	}
+	if (p->ring->pid != getpid() ){
+		RINGMAP_ERROR(Wrong ring was mapped! Exit!);
+		return (-1);
+	}
 	
 #if (__RINGMAP_DEB)
 	printf("Virtual address of ring is 0x%X\n", p->ring);
@@ -109,6 +122,8 @@
 	for(i=0 ;i < SLOTS_NUMBER; i++){
 		PRINT_PACKET_ADDR(p->ring, i);
 	}
+
+	PRINT_RING_PTRS(p->ring);
 #endif 
 
 	/* 
@@ -242,6 +257,7 @@
 	
 	if ( RING_IS_EMPTY(ring) ) {
 		RINGMAP_FUNC_DEBUG(Ring is empty. Sleep...);
+		PRINT_RING_PTRS(ring);
 		/* Sleep and wait for new incoming packets */
 		ioctl(ringmap_cdev_fd, IOCTL_SLEEP_WAIT);
 		goto again;
@@ -275,14 +291,13 @@
 		pkthdr.caplen = pkthdr.len = mb->m_len;
 		datap = (caddr_t)U_PACKET(ring, curr_slot);
 
-		ring->slot[curr_slot].is_ok=0;
 		ring->pkt_counter++;
 		--ws;
 
 		(*callback)(user, &pkthdr, datap);
 
 #ifdef __RINGMAP_DEB
-		PRINT_SLOT(ring, ring->cur_slot_user, datap);
+		PRINT_SLOT(ring, ring->cur_slot_user);
 #endif
 
 out:

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#23 (text+ko) ====

@@ -1382,6 +1382,7 @@
 {
 	struct adapter	*adapter = context;
 	struct ifnet	*ifp = adapter->ifp;
+	struct capt_instance *ci = NULL;
 
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
 #ifdef RINGMAP
@@ -1392,8 +1393,12 @@
 			taskqueue_enqueue(adapter->tq, &adapter->rxtx_task);
 #ifdef RINGMAP
 			adapter->rm->funcs->sync_head(adapter->dev);
-
-			wakeup(adapter->rm);
+			
+			SLIST_FOREACH(ci, &adapter->rm->instance_list, next_instance) {
+				if (RING_NOT_EMPTY(ci->ring)){
+					wakeup(ci->ring);
+				}
+			}
 		}
 #endif 
 

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#22 (text+ko) ====

@@ -19,40 +19,38 @@
 #include "ringmap_8254.h"
 
 int rm_8254_set_ringmap_to_adapter(device_t, struct ringmap *);
-int rm_8254_init_slots(struct ring *, device_t);
 struct ringmap * rm_8254_get_ringmap_p(device_t);
 device_t rm_8254_get_device_p(struct cdev *);
 void rm_8254_enable_intr(device_t);
 void rm_8254_disable_intr(device_t);
-int rm_8254_set_slot(struct ring *, struct adapter *, unsigned int);
+int rm_8254_set_slot(struct ring *, device_t, unsigned int);
 void rm_8254_interrupt(void *);
 void rm_8254_delayed_interrupt(void *);
 int rm_8254_print_ring_pointers(struct adapter *, struct ring *);
-void rm_8254_sync_head_tail(device_t, struct ring *);
-void rm_8254_sync_tail(device_t, struct ring *);
+void rm_8254_sync_head_tail(device_t);
+void rm_8254_sync_tail(device_t);
 void rm_8254_sync_head(device_t);
 void rm_8254_delayed_interrupt_per_packet(device_t, int);
 struct ring * rm_8254_find_next(struct adapter *);
-struct ring *rm_8254_alloc_ring(device_t);
 
 extern devclass_t em_devclass;
 extern void	lem_enable_intr(struct adapter *);
 extern void	lem_disable_intr(struct adapter *);
 extern void ringmap_print_slot(struct ring *, unsigned int);
+extern void print_capt_inst(struct capt_instance *);
 
 
 struct ringmap_functions ringmap_f = {
 	rm_8254_set_ringmap_to_adapter,
 	rm_8254_enable_intr,
 	rm_8254_disable_intr,
-	rm_8254_init_slots,
 	rm_8254_interrupt,
 	rm_8254_delayed_interrupt,
 	rm_8254_delayed_interrupt_per_packet,
 	rm_8254_sync_head_tail,
 	rm_8254_sync_tail,
 	rm_8254_sync_head,
-	rm_8254_alloc_ring,
+	rm_8254_set_slot,
 	rm_8254_get_ringmap_p,
 	rm_8254_get_device_p
 };
@@ -68,20 +66,33 @@
  * 2. SYNC_TAIL: RDT =  ring->userrp
  */
 void 
-rm_8254_sync_head_tail(device_t dev, struct ring *ring)
+rm_8254_sync_head_tail(device_t dev)
 {
-	rm_8254_sync_tail(dev, ring);
+	RINGMAP_FUNC_DEBUG(start);
+	rm_8254_sync_tail(dev);
 	rm_8254_sync_head(dev);
+	RINGMAP_FUNC_DEBUG(end);
 }
 
 
 void 
-rm_8254_sync_tail(device_t dev, struct ring *ring)
+rm_8254_sync_tail(device_t dev)
 {
 	struct adapter *adapter;
 	adapter = (struct adapter *)device_get_softc(dev);
+	struct ring *ring = NULL;
+
+	RINGMAP_FUNC_DEBUG(start);
 
-	RINGMAP_HW_SYNC_TAIL(adapter, ring);	/* SW_TAIL ==> HW_TAIL */
+	ring = rm_8254_find_next(adapter);
+
+#ifdef __RINGMAP_DEB
+	printf("Next ring is 0x%X\n", (unsigned int)ring);
+#endif 
+
+	RINGMAP_HW_SYNC_TAIL(adapter, ring);
+
+	RINGMAP_FUNC_DEBUG(end);
 }
 
 
@@ -91,6 +102,8 @@
 	struct capt_instance *ci = NULL;
 	struct adapter *adapter;
 
+	RINGMAP_FUNC_DEBUG(start);
+
 	adapter = (struct adapter *)device_get_softc(dev);
 
 	RINGMAP_LOCK(adapter->rm);
@@ -98,16 +111,22 @@
 	SLIST_FOREACH(ci, &adapter->rm->instance_list, next_instance) {
 		if (ci->ring != NULL) {
 			RINGMAP_HW_SYNC_HEAD(adapter, ci->ring); /* SW_TAIL ==> HW_HEAD */
+#ifdef __RINGMAP_DEB
+			print_capt_inst(ci);
+			PRINT_RING_PTRS(ci->ring);
+#endif 
 		}
 	}
 
 	RINGMAP_UNLOCK(adapter->rm);
+
+	RINGMAP_FUNC_DEBUG(end);
 }
 
 
 /* 
  * This should be called from ISR. Other interrupts are disallowed!
- * It means the functions must be as small as possible 
+ * It means the functions must be as small as possible
  */
 void 
 rm_8254_interrupt(void *arg)
@@ -136,7 +155,7 @@
 #endif
 		if (ci->ring != NULL) {
 			/* TODO: find the next ring */
-			rm_8254_sync_tail(adapter->dev, rm_8254_find_next(adapter));
+			rm_8254_sync_tail(adapter->dev);
 #ifdef RINGMAP_TIMESTAMP
 			getmicrotime(&ci->ring->last_ts);
 #endif
@@ -161,7 +180,7 @@
 		rdt = ci->ring->userrp;
 		dist = R_DISTANCE(rdh, rdt);
 		if (dist <= min_dist) {
-			dist = min_dist;
+			min_dist = dist;
 			min_ci = ci;
 		}
 	}
@@ -193,7 +212,7 @@
 #endif 
 
 #ifdef __RINGMAP_DEB
-			PRINT_SLOT((ci->ring), (slot_num), adapter);
+			PRINT_SLOT((ci->ring), (slot_num));
 #endif 
 		}
 	}
@@ -203,92 +222,12 @@
 }
 
 
-struct ring *
-rm_8254_alloc_ring(device_t dev)
+int
+rm_8254_set_slot(struct ring *ring, device_t dev, unsigned int slot_num)
 {
-	struct ring *ring;
-
-	/* 
-	 * Allocate memory for ring structure 
-	 * Use contigmalloc(9) to get PAGE_SIZE alignment that is needed 
-	 * for memory mapping.  
-	 */
-	ring = (struct ring *) contigmalloc (sizeof(struct ring), 
-			M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
-	if (ring == NULL) { 
-		RINGMAP_ERROR(Can not allocate space for ring structure);
-
-		return (NULL);
-	}
-
-	if (rm_8254_init_slots(ring, dev) == -1) { 
-		RINGMAP_ERROR(The ring is not initialized. Device will not be opened!);
-		contigfree(ring, sizeof(struct ring), M_DEVBUF);
-
-		return (NULL);
-	}	
-
-	return (ring);
-}
-
-
-/*
- * Get adapter structure of device and initialize the 
- * pointers in ring (mbufs, packets, decriptors) with values 
- * got from adapters structure.
- * Returns 0 by success, -1 otherwise.
- */
-int 
-rm_8254_init_slots(struct ring *ring, device_t dev)
-{
-	unsigned int slot_num;
-	struct adapter *adapter;
-
-	RINGMAP_FUNC_DEBUG(start);
-
+	struct adapter *adapter = NULL;
 	adapter = (struct adapter *)device_get_softc(dev);
 
-	/* Check some pointers in the adapter structure */
-	if (adapter->rx_buffer_area == NULL){
-		RINGMAP_ERROR(mbufs array is not allocated)
-		return (-1);
-	}
-	if (adapter->rx_desc_base == NULL){
-		RINGMAP_ERROR(descriptors array is not allocated)
-		return (-1);
-	}
-	if (adapter->num_rx_desc != SLOTS_NUMBER){
-		RINGMAP_ERROR(SLOTS_NUMBER should be equal to the num_rx_desc);
-		return (-1);
-	}
-	
-//	RINGMAP_HW_WRITE_TAIL(adapter, 
-//			(R_MODULO(RINGMAP_HW_READ_HEAD(adapter) - 1))); 
-
-	SW_TAIL(ring) = RINGMAP_HW_READ_TAIL(adapter);
-
-	/* Set ring pointers */
-	for (slot_num = 0 ; slot_num < SLOTS_NUMBER ; slot_num ++){
-		if (rm_8254_set_slot(ring, adapter, slot_num) == -1){
-			RINGMAP_ERROR(Ring initialization failed!);
-			return (-1);
-		}
-#if (__RINGMAP_DEB)
-		ringmap_print_slot(ring, slot_num);
-#endif
-	}
-
-	RINGMAP_FUNC_DEBUG(end);
-
-	return (0);
-}
-
-
-int
-rm_8254_set_slot(struct ring *ring, struct adapter *adapter, 
-		unsigned int slot_num)
-{
-
 #if (__RINGMAP_DEB)
 	printf("[%s] Set slot: %d\n", __func__, slot_num);
 #endif
@@ -331,8 +270,6 @@
 }
 
 
-
-
 /*
  * Disable interrupts on adapter 
  */

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#20 (text+ko) ====

@@ -23,17 +23,17 @@
 
 
 #define RINGMAP_HW_READ_HEAD(adapter)						\
-		RINGMAP_HW_READ_REG(&adapter->hw, E1000_RDH(0))	
+		RINGMAP_HW_READ_REG(&(adapter)->hw, E1000_RDH(0))	
 
 #define RINGMAP_HW_SYNC_HEAD(adapter, ring)					\
 		SW_HEAD(ring) = RINGMAP_HW_READ_HEAD(adapter);	
 
 #define RINGMAP_HW_SYNC_TAIL(adapter, ring)				\
-		RINGMAP_HW_WRITE_REG(&adapter->hw, E1000_RDT(0), ring->userrp)
+		RINGMAP_HW_WRITE_REG(&(adapter)->hw, E1000_RDT(0), (ring)->userrp)
 
 #define RINGMAP_HW_WRITE_TAIL(adapter, val)				\
-		RINGMAP_HW_WRITE_REG(&adapter->hw, E1000_RDT(0), val)
+		RINGMAP_HW_WRITE_REG(&(adapter)->hw, E1000_RDT(0), (val))
 
 #define RINGMAP_HW_READ_TAIL(adapter)						\
-		RINGMAP_HW_READ_REG(&adapter->hw, E1000_RDT(0))
+		RINGMAP_HW_READ_REG(&(adapter)->hw, E1000_RDT(0))
 

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#12 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#26 (text+ko) ====

@@ -36,7 +36,6 @@
 int ringmap_attach (device_t, struct ringmap_functions *);
 int ringmap_detach (device_t);
 void ringmap_close_cb (void *data);
-void ringmap_print_slot(struct ring *, unsigned int);
 void clear_capt_instance(void *);
 void print_capt_inst(struct capt_instance *);
 
@@ -46,7 +45,8 @@
 d_open_t	ringmap_open;
 d_close_t	ringmap_close;
 d_ioctl_t	ringmap_ioctl;
-d_mmap_t	ringmap_mmap;
+d_read_t	ringmap_read;
+//d_mmap_t	ringmap_mmap;
 
 /*
  *	Character Device for access on if_em driver structures
@@ -56,7 +56,8 @@
 	.d_open 	= ringmap_open,
 	.d_close 	= ringmap_close,
 	.d_ioctl	= ringmap_ioctl,
-	.d_mmap		= ringmap_mmap,
+	.d_read		= ringmap_read,
+//	.d_mmap		= ringmap_mmap,
 	.d_name 	= "ringmap_cdev"
 };
 
@@ -97,10 +98,6 @@
 						UID_ROOT, GID_WHEEL, 0666, 
 						RINGMAP_DEVICE"%d", device_get_unit(dev));
 
-	/* Device open counter. Should count how many times the char device was
-	 * opened */
-	rm->open_cnt = 0;
-
 	/* Store adapters device structure */
 	rm->dev = dev;
 
@@ -110,7 +107,7 @@
 	/* Init the mutex to protecting our data */
 	RINGMAP_LOCK_INIT(rm, device_get_nameunit(dev));
 
-	/* set the pointer to ringmap in the adapters structure */
+	/* set the pointer to ringmap into the adapters structure */
 	rm->funcs->set_ringmap_to_adapter(dev, rm);
 
 	RINGMAP_FUNC_DEBUG(end); 
@@ -143,7 +140,6 @@
 	
 	RINGMAP_LOCK_DESTROY(rm);
 
-	// contigfree(rm->funcs, sizeof(struct ringmap_functions), M_DEVBUF);
 	contigfree(rm, sizeof(struct ringmap), M_DEVBUF);
 
 	RINGMAP_FUNC_DEBUG(end);
@@ -160,11 +156,17 @@
 int
 ringmap_open(struct cdev *cdev, int flag, int otyp, struct thread *td)
 {
-	int err = 0;
+	int err = 0, i = 0;
 	struct ringmap *rm = NULL;
+	struct ring *ring = NULL;
 	struct capt_instance *ci = NULL;
 
 	RINGMAP_FUNC_DEBUG(start);
+#ifdef __RINGMAP_DEB
+	printf("cdev = 0x%X, td = %d\n", 
+			(unsigned int)cdev,
+			td->td_proc->p_pid);
+#endif 
 
 	/* a little magic */
 	rm = get_ringmap_p(get_device_p(cdev));
@@ -174,51 +176,84 @@
 		return (EIO);
 	}
 
+	rm->funcs->disable_intr(rm->dev);
+	RINGMAP_LOCK(rm);
+
+	/* check: the current thread shouldn't open(2) more than one time */
+	if (rm->open_cnt) {
+		SLIST_FOREACH(ci, &rm->instance_list, next_instance) {
+			if (ci->td == td) {
+				RINGMAP_ERROR(Device is opened!);
+
+				err = EIO; 
+				goto out;
+			}
+		}
+	}
+
 	/* 
-	 * crete the capturing instance wich will presents 
-	 * current thread and packets ring 
+	 * Allocate memory for ring structure Use contigmalloc(9) to get PAGE_SIZE
+	 * alignment that is needed for memory mapping.  
 	 */
-	MALLOC(ci, struct capt_instance *, 
-			sizeof(struct capt_instance), M_DEVBUF, (M_ZERO | M_WAITOK));
-	if ( ci == NULL ){
-		return (EIO);
+	ring = (struct ring *) contigmalloc (sizeof(struct ring), 
+			M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
+	if (ring == NULL) {
+		RINGMAP_ERROR(Can not allocate space for ring);
+
+		err = EIO; 
+		goto out;
+	}
+	for (i = 0 ; i < SLOTS_NUMBER ; i++){
+		if (rm->funcs->set_slot(ring, rm->dev, i) == -1){
+			RINGMAP_ERROR(Ring initialization failed!);
+			contigfree(ring, sizeof(struct ring), M_DEVBUF);
+
+			err = EIO; 
+			goto out;
+		}
 	}
 
 	/* 
-	 * I think it is safe to disable interupts while we allocate 
-	 * allocate memory for oure structures 
+	 * create the capturing instance wich will represent 
+	 * current thread and packets ring 
 	 */
-	rm->funcs->disable_intr(rm->dev);
+	MALLOC(	ci, struct capt_instance *, 
+			sizeof(struct capt_instance), M_DEVBUF, (M_ZERO | M_WAITOK));
+	if ( ci == NULL ){
+		contigfree(ring, sizeof(struct ring), M_DEVBUF);
 
-	RINGMAP_LOCK(rm);
+		err = EIO; 
+		goto out;
+	}
 	
-	/* Allocate ring */
-	ci->ring = rm->funcs->alloc_ring(rm->dev);
-	if ( ci->ring == NULL ) {
-		RINGMAP_ERROR(The ring is not allocated);
-
-		err = EIO; goto out;
-	}
+	ci->ring = ring;
 	ci->ring->size = SLOTS_NUMBER;
 	ci->td = td;
 	ci->rm = rm;
 
+	ci->ring->pid = ci->td->td_proc->p_pid;
+
 	SLIST_INSERT_HEAD(&rm->instance_list, ci, next_instance);
 
 	if ( devfs_set_cdevpriv((void *)ci, clear_capt_instance) ) {
-		RINGMAP_ERROR(The pointer to the private data is not set!);
-		err = EIO; goto out;
+		RINGMAP_ERROR(Can not store private data!);
+		FREE(ci, M_DEVBUF);
+		contigfree(ring, sizeof(struct ring), M_DEVBUF);
+
+		err = EIO; 
+		goto out;
 	}
 	
-	rm->open_cnt++;
-
+	rm->funcs->sync_head_tail(rm->dev);
 #ifdef __RINGMAP_DEB
 	print_capt_inst(ci);
-#endif 
+	PRINT_RING_PTRS(ci->ring); 
+#endif
+
+	rm->open_cnt++;
 
 out:
 	RINGMAP_UNLOCK(rm);
-
 	rm->funcs->enable_intr(rm->dev);
 
 	RINGMAP_FUNC_DEBUG(end);
@@ -235,6 +270,12 @@
 
 	RINGMAP_FUNC_DEBUG(start);
 
+#ifdef __RINGMAP_DEB
+	printf("cdev = 0x%X, td = %d\n", 
+			(unsigned int)cdev,
+			td->td_proc->p_pid);
+#endif 
+
 	rm = get_ringmap_p(get_device_p(cdev));
 
 	RINGMAP_LOCK(rm);
@@ -243,15 +284,14 @@
 
 #ifdef __RINGMAP_DEB
 	print_capt_inst(ci);
-#endif 
-
+#endif
 
 #ifdef __RINGMAP_DEB
 	SLIST_FOREACH(ki, &rm->instance_list, next_instance) {
 		printf("[%s] Aufter dealocation: ", __func__);
 		print_capt_inst(ki);
 	}
-#endif 	
+#endif
 
 	RINGMAP_UNLOCK(rm);
 
@@ -260,32 +300,18 @@
     return (0);
 }
 
-
-int
-ringmap_mmap(struct cdev *cdev, vm_ooffset_t offset, vm_paddr_t *paddr, 
-				int nprot, vm_memattr_t *memattr)
+int 
+ringmap_read(struct cdev *cdev, struct uio *uio, int ioflag)
 {
-	int err = 0;
 	struct ringmap *rm = NULL;
 	struct capt_instance *ci = NULL;
-	pid_t pid = 0;
+	vm_paddr_t phys_ring;
 
-	pid = curthread->td_proc->p_pid;
+	RINGMAP_FUNC_DEBUG(end);
 
-	RINGMAP_FUNC_DEBUG(start);
-	
 	/* Get pointer to the ringmap structure */
 	rm = get_ringmap_p(get_device_p(cdev));
-	
-	/* Check protections */
-	if (nprot & PROT_EXEC) {
-		RINGMAP_WARN("PROT_EXEC ist set");
-		
-		err = ERESTART; goto out;
-	}
 
-	RINGMAP_LOCK(rm);
-
 	if (devfs_get_cdevpriv((void **)&ci)) {
 		SLIST_FOREACH(ci, &rm->instance_list, next_instance) {
 			if ( ci->td == curthread)
@@ -293,79 +319,151 @@
 		}
 	} 
 
-	*paddr = vtophys(ci->ring);
+	if (ci->td != curthread ){
+		RINGMAP_ERROR(Wrong capturing object!);
+		return(EIO);
+	}
+
+	phys_ring = vtophys(ci->ring);
+#ifdef __RINGMAP_DEB
+	print_capt_inst(ci);
+	PRINT_RING_PTRS(ci->ring);
+	printf("[%s] phys addr of ring 0x%X\n", __func__, phys_ring);
+#endif
 
-out:
-	RINGMAP_UNLOCK(rm);
+	uiomove(&phys_ring, sizeof(phys_ring), uio);
 
 	RINGMAP_FUNC_DEBUG(end);
 
-    return(err);
+	return (0);
 }
 
+//int
+//ringmap_mmap(struct cdev *cdev, vm_ooffset_t offset, vm_paddr_t *paddr, 
+//				int nprot, vm_memattr_t *memattr)
+//{
+//	int err = 0;
+//	struct ringmap *rm = NULL;
+//	struct capt_instance *ci = NULL;
+//	pid_t pid = 0;
+//
+//	pid = curthread->td_proc->p_pid;
+//
+//	RINGMAP_FUNC_DEBUG(start);
+//	
+//	/* Get pointer to the ringmap structure */
+//	rm = get_ringmap_p(get_device_p(cdev));
+//	
+//	rm->funcs->disable_intr(rm->dev);
+//	RINGMAP_LOCK(rm);
+//
+//	if (devfs_get_cdevpriv((void **)&ci)) {
+//		SLIST_FOREACH(ci, &rm->instance_list, next_instance) {
+//			if ( ci->td == curthread)
+//				break;
+//		}
+//	} 
+//#ifdef __RINGMAP_DEB
+//	print_capt_inst(ci);
+//	PRINT_RING_PTRS(ci->ring);
+//	printf("[%s] phys addr of ring 0x%X\n", __func__, vtophys(ci->ring));
+//#endif
+//
+//	*paddr = vtophys(ci->ring);
+//
+//	RINGMAP_UNLOCK(rm);
+//	rm->funcs->enable_intr(rm->dev);
+//
+//	RINGMAP_FUNC_DEBUG(end);
+//
+//    return(err);
+//}
+
 
 int
 ringmap_ioctl (struct cdev *cdev, u_long cmd, caddr_t data, 
 				int fflag, struct thread *td)
 {
 	int err = 0, err_sleep = err_sleep;
-	struct ringmap *ringmap = NULL;
+	struct ringmap *rm = NULL;
 	struct capt_instance *ci;
 
 	RINGMAP_IOCTL(start);
 
+#ifdef __RINGMAP_DEB
+	printf("cdev = 0x%X, td = %d\n", 
+			(unsigned int)cdev,
+			td->td_proc->p_pid);
+#endif 
+
 	/* Eliminate it */
-	ringmap = get_ringmap_p(get_device_p(cdev));
-	if ( ringmap == NULL ){
+	rm = get_ringmap_p(get_device_p(cdev));
+	if ( rm == NULL ){
 		RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished);
 
-		/* TODO: look if ENODEV is a correctly for this case */
+		/* TODO: look whether ENODEV is a correctly for this case */
 		return(ENODEV);
 	}
 
+	RINGMAP_LOCK(rm);
 	if ( devfs_get_cdevpriv((void **)&ci) ) {
 		RINGMAP_IOCTL(Error! Can not get private date!)
 		return (ENODEV);
 	}
+	if (ci->td != curthread){
+
+		RINGMAP_IOCTL(Wrong private data!);
 
+		SLIST_FOREACH(ci, &rm->instance_list, next_instance) {
+			if ( ci->td == curthread)
+				break;
+		}
+	}
+	RINGMAP_UNLOCK(rm);
+
 	switch( cmd ){
 
 		/* Enable  Interrupts */
 		case IOCTL_ENABLE_INTR:
-			ringmap->funcs->enable_intr(ringmap->dev);
+			rm->funcs->enable_intr(rm->dev);
 			RINGMAP_IOCTL(interrupts schould be enabled);
 		break;
 
 		/* Disable  Interrupts */
 		case IOCTL_DISABLE_INTR:
-			ringmap->funcs->disable_intr(ringmap->dev);
+			rm->funcs->disable_intr(rm->dev);
 			RINGMAP_IOCTL(interrupts schould be disabled);
 		break;
 		
 		/* Sleep and wait for new packets */
 		case IOCTL_SLEEP_WAIT:
-			RINGMAP_IOCTL(Sleep and wait for new packets);
 
 			ci->ring->user_wait_kern++;
-			ringmap->funcs->sync_head_tail(ringmap->dev, ci->ring);
+			rm->funcs->sync_head_tail(rm->dev);
 
+#ifdef __RINGMAP_DEB
+			print_capt_inst(ci);
+			PRINT_RING_PTRS(ci->ring);
+#endif
 			/* 
 			 * In the time: from user has called ioctl() until now could 
 			 * come the new packets. It means, before we are going to sleep
 			 * it makes a sence to check if we really must do it :)
 			 */
 			if (RING_IS_EMPTY(ci->ring)) {
-				err_sleep = tsleep(ringmap, (PRI_MIN) | PCATCH, "ioctl", 0);
+				RINGMAP_IOCTL(Sleep and wait for new packets);
+
+				err_sleep = tsleep(ci->ring, (PRI_MIN) | PCATCH, "ioctl", 0);
 			}
 		break;
 
 		case IOCTL_SYNC_HEAD_TAIL:
-			ringmap->funcs->sync_head_tail(ringmap->dev, ci->ring);
+			rm->funcs->sync_head_tail(rm->dev);
 		break;
 
 		/* Synchronize sowftware ring-tail with hardware-ring-tail (RDT) */
 		case IOCTL_SYNC_TAIL:
-			ringmap->funcs->sync_tail(ringmap->dev, ci->ring);
+			rm->funcs->sync_tail(rm->dev);
 		break;
 
 		default:
@@ -412,33 +510,6 @@
 	RINGMAP_FUNC_DEBUG(end);
 }
 
-void
-ringmap_print_slot(struct ring *ring, unsigned int slot_number)
-{
-	printf("\n[%s] Slot Number: %d\n", __func__,  slot_number);
-	printf("---------------- \n");
-
-	printf("physical addr of descriptor[%d] = 0x%X\n", slot_number, 
-			(unsigned int) ring->slot[slot_number].descriptor.phys);
-
-	printf("kernel addr of descriptor[%d] = 0x%X\n", slot_number, 
-			(unsigned int) ring->slot[slot_number].descriptor.kern);
-
-	printf("physical addr of mbuf[%d] = 0x%X\n", slot_number, 
-			(unsigned int) ring->slot[slot_number].mbuf.phys);
-
-	printf("kernel addr of mbuf[%d] = 0x%X\n", slot_number, 
-			(unsigned int) ring->slot[slot_number].mbuf.kern);
-
-	printf("physical addr of packet_buffer[%d] = 0x%X\n", slot_number, 
-			(unsigned int) ring->slot[slot_number].packet.phys);
-
-	printf("kernel addr of packet_buffer[%d] = 0x%X\n", slot_number, 
-			(unsigned int) ring->slot[slot_number].packet.kern);
-
-	printf("---------------- \n");
-}
-
 
 void 
 print_capt_inst(struct capt_instance *ci)

==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#26 (text+ko) ====

@@ -4,7 +4,7 @@
 #define SLOTS_NUMBER		16
 
 /* 
- * Prefix for name of device (for example /dev/ringmap_cdev0 will full name) 
+ * Prefix for name of device (for example /dev/ringmap0 will full name) 
  */
 #define RINGMAP_DEVICE 		"ringmap"
 
@@ -139,6 +139,8 @@
 
 	struct timeval	last_ts;
 
+	unsigned int pid;
+
 	/* Array of slots */
 	struct ring_slot slot[SLOTS_NUMBER];
 };
@@ -201,12 +203,6 @@
 	void (*disable_intr)(device_t);
 
 	/*
-	 * Initialize the ring slots with pointers to the 
-	 * mbufs, packets buffers and descriptors.
-	 */
-	int (*init_slots)(struct ring *, device_t);
-
-	/*
 	 * This function should be calld from ISR. It should contain 
 	 * the very fast executable operations (don't sleep!). 
 	 */
@@ -221,7 +217,7 @@
 
 	/*
 	 * The native driver should have cycle for checking 
-	 * the the packets that was transfered in the RAM from 
+	 * the packets that was transfered in the RAM from 
 	 * network adapter. The function delayed_isr_per_packet()
 	 * should be called from this cycle, so it will be called 
 	 * per packet.
@@ -245,16 +241,16 @@
 	 * 2. SYNC_TAIL: SOFTWARE_TAIL => HARDWARE_TAIL
 	 *		set value from software TAIL-variable: ring->userrp into the
 	 *		hardware TAIL-register. Hardware shouldn't change the content of
-	 *		TAIL-register.  Software after reading one packet in RAM increment
+	 *		TAIL-register.  Software after reading one packet in RAM increments
 	 *		the value of ring->userrp. Kernel will check this value and set it
 	 *		into the hardware TAIL-register.
 	 */
-	void (*sync_head_tail)(device_t, struct ring *);
-	void (*sync_tail)(device_t, struct ring *);
+	void (*sync_head_tail)(device_t);
+	void (*sync_tail)(device_t);
 	void (*sync_head)(device_t);
 
-	/* Alloc memory for our ring and initialize the slots */
-	struct ring *(*alloc_ring)(device_t);
+	/* Initialize the ring slot */
+	int (*set_slot)(struct ring *, device_t, unsigned int);
 
 	struct ringmap *(*dev_to_ringmap)(device_t);
 	device_t (*cdev_to_dev)(struct cdev *);
@@ -286,6 +282,7 @@
  */
 #define IOCTL_SYNC_TAIL			_IO(RINGMAP_IOC_MAGIC, 1) 
 
+/* Synchronize both head and tail */
 #define IOCTL_SYNC_HEAD_TAIL	_IO(RINGMAP_IOC_MAGIC, 2) 
 
 /* 
@@ -418,50 +415,52 @@
 	if (__RINGMAP_DEB) printf(WARN_PREFIX"[%s]: "  #x "\n", __func__);
 
 
-#ifdef _KERNEL
-#define RINGMAP_PRINT_DESC(adapter, i)	\
-	printf("[%s] - DESC INFO: desc_num=%d, status=0x%X, pktlen=%d\n[%s] - ADDRESSES: pkt_virt=0x%X (kern), pkt_phys=0x%X\n", 				\
-		__func__, 												\
-		i, 														\
-		(unsigned int)(adapter->rx_desc_base[i].status) & 255, 	\
-		adapter->rx_desc_base[i].length,						\
-		__func__, 												\
-		(unsigned int)adapter->rx_buffer_area[i].m_head->m_data,\
-		(unsigned int)adapter->rx_desc_base[i].buffer_addr);
+#define PRINT_PKT_BYTES(pktp, i)										\
+   printf("=+= [%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", 	\
+	   __func__, pktp[0], pktp[1], pktp[16], pktp[32], pktp[59]);
+
+#define PRINT_PACKET_ADDR(ring, i)	\
+printf("=+= packet.user=0x%X, packet.phys=0x%X, packet.kern=0x%X\n",  \
+		(unsigned int)ring->slot[i].packet.user, 	\
+		ring->slot[i].packet.phys, 					\
+		ring->slot[i].packet.kern);
+
+#define PRINT_MBUF_ADDR(ring, i)	\
+printf("=+= mbuf.user=0x%X, mbuf.phys=0x%X, mbuf.kern=0x%X\n",  \
+		(unsigned int)ring->slot[i].mbuf.user, 	\
+		ring->slot[i].mbuf.phys, 					\
+		ring->slot[i].mbuf.kern);
 
-#define PRINT_SOME_BYTES_FROM_PKT(adapter, i)				    		\
-   printf("=+= [%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", 	\
-	   __func__,										\
-	   adapter->rx_buffer_area[i].m_head->m_data[0],	\
-	   adapter->rx_buffer_area[i].m_head->m_data[1],	\
-	   adapter->rx_buffer_area[i].m_head->m_data[16],	\
-	   adapter->rx_buffer_area[i].m_head->m_data[32],	\
-	   adapter->rx_buffer_area[i].m_head->m_data[59]);	
-#else 
-#define PRINT_SOME_BYTES_FROM_PKT(pktp, i)								\
-   printf("=+= [%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", 	\
-	   __func__,	\
-	   pktp[0],		\
-	   pktp[1],		\
-	   pktp[16],	\
-	   pktp[32],	\
-	   pktp[59]);	
-#endif
+#define PRINT_DECRIPTOR_ADDR(ring, i)	\
+printf("=+= descr.user=0x%X, descr.phys=0x%X, descr.kern=0x%X\n",  \
+		(unsigned int)ring->slot[i].descriptor.user, 	\
+		ring->slot[i].descriptor.phys, 					\
+		ring->slot[i].descriptor.kern);

>>> TRUNCATED FOR MAIL (1000 lines) <<<



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007110309.o6B39Lr2057896>