Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Jul 2010 23:40:44 GMT
From:      Alexandre Fiveg <afiveg@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180673 for review
Message-ID:  <201007082340.o68NeiuY033095@repoman.freebsd.org>

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

Change 180673 by afiveg@cottonmouth on 2010/07/08 23:39:49

	new small designe chages: from now ringmap doesn't try to find out the type of controller and set hardware-dependent functions. The generic drivers attach() function calls ringmap_attach() and passes in the pointer to ringmap_functions as parameter. 

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#7 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#7 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#9 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#14 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#22 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#21 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#19 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#11 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#25 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#25 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#9 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#10 edit
.. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#5 edit

Differences ...

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


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


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

@@ -75,7 +75,6 @@
 #include <machine/bus.h>
 #include "../../sys/net/ringmap.h"
 
-extern int check_module(const char *);
 extern int init_mmapped_capturing(const char *device, pcap_t *);
 #endif 
 
@@ -275,9 +274,6 @@
 		goto fail;
 
 #ifdef RINGMAP
-	if (check_module(source) < 0){
-		goto fail;
-	}
 	if (init_mmapped_capturing(source, p) < 0){
 		goto fail;
 	}

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

@@ -32,70 +32,15 @@
 #include "../../sys/net/ringmap.h"
 
 
-/* File descriptor of fiveg_cdev */
+/* File descriptor of /dev/ringmap */
 int ringmap_cdev_fd = -1;
 
 /***	F U N C T I O N S	***/
-int check_module (const char *);
 int init_mmapped_capturing(const char *device, pcap_t *);
 void uninit_mmapped_capturing(pcap_t *);
 int pcap_read_ringmap(pcap_t *, int , pcap_handler , u_char *);
 
 
-/* 
- * Check if  module is loaded.
- * Get descripor of /dev/ringmap (open)
- *
- * The name of linker file: MOD_NAME (ringmap.h)
- * Return: 	fileid 	- 	of kld file on success. 
- * 			<0 		- 	otherwise 
- */
-int
-check_module (const char *device)
-{
-	int error = 0;
-	kvm_t *kd;
-	struct nlist nl[]={ {NULL}, {NULL}, };
-	char dev_path[1024], cmd[1024];
-	char errbuf[_POSIX2_LINE_MAX];
-
-	RINGMAP_FUNC_DEBUG(start);
-
-	/* Try to find our module */
-	error = kldfind(MOD_NAME);
-	if (error == -1){
-		/* Module seems to be not loaded */
-		printf("[%s] Module %s is not loaded\n", __func__, MOD_NAME);
-		return(-1);
-	} else {
-		
-		RINGMAP_FUNC_DEBUG(ringmap module is loaded);
-
-		sprintf(cmd, "ls /dev/| grep %s > /dev/null",RINGMAP_DEVICE);
-		if (system(cmd)){
-			printf("[%s] ringmap driver is NOT loaded\n", __func__);
-			return (-1);			
-		}
-
-		RINGMAP_FUNC_DEBUG(/dev/ringmap_cdev is created);
-
-		/* dev_path = "/dev/RINGMAP_DEVICE_em[0,1]" */
-		sprintf(dev_path, "/dev/"RINGMAP_DEVICE"1");
-
-		/* Open fiveg_cdev device for communication with our driver */
-		if ((ringmap_cdev_fd = open(dev_path, O_RDWR)) == -1) {
-			printf("[%s] Error by opening %s \n", __func__, dev_path);
-			perror("/dev/" RINGMAP_DEVICE);
-			return(-2);
-		}
-	}
-
-	printf(RINGMAP_PREFIX"ringmap-Driver %s is loaded!\n", MOD_NAME);
-
-	return (error);
-}
-
-
 /********************************************************
  * Open  (/dev/ringmap) device to communicate with 
  * kernel. Map buffers by calling mmap (/dev/mem, ...)
@@ -108,66 +53,64 @@
 	int devmem_fd, i;
 	long num_of_bytes;
 	void *tmp_addr;
+	char dev_path[1024];
 	struct ring tmp_ring;
-
-	/* temp variable for save physical addresses (for mmap(/dev/mem)) */
 	off_t memoffset = 0; 
-	
-	/* Physical addres of ring structure */
-	bus_addr_t nic_statspp,	rspp;
+	bus_addr_t 	rspp;
 
 	RINGMAP_FUNC_DEBUG(start);
 
-	if ( p == NULL ){
-		RINGMAP_ERROR(NULL pointer to the pcap structure);
-		return (-1);
+	sprintf(dev_path, "/dev/%s",device);
+
+	/* Open /dev/ringmap device for communication with our driver */
+	if ((ringmap_cdev_fd = open(dev_path, O_RDWR)) == -1) {
+		printf("[%s] Error by opening %s \n", __func__, dev_path);
+		perror("/dev/" RINGMAP_DEVICE);
+		return(-1);
 	}
-	
-	p->ring = NULL;
 
-	/* Open mem device for mmaping of kernel memory regions in space of our process */
+	/* 
+	 * Open mem device for mmaping of kernel memory regions in space of our
+	 * process 
+	 */
 	if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){
 		perror("/dev/mem");
 		return (-1); 
 	}
 
-	if (ringmap_cdev_fd < 0){
-		RINGMAP_ERROR(ringmap char device is not open);
-		return (-1);
-	}
-	tmp_addr = mmap(0, sizeof(struct ring), PROT_WRITE|PROT_READ, MAP_SHARED, ringmap_cdev_fd, 0);
+	/**
+	 ** !!! Very important piece of code !!!
+	 **
+	 ** Here we map the ring structure into the 
+	 ** memory space of current process.
+	 **/
+	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);
 	if (tmp_addr == MAP_FAILED){
 		RINGMAP_ERROR("Mapping of Ring Pointers structure failed! Exit!");
 		return -1;
 	}
-#if (__RINGMAP_DEB)
-	printf("Virtual address of ring is 0x%X\n", tmp_addr);
-#endif 
 
 	p->ring = (struct ring *)tmp_addr;
-	if (p->ring->size == 0){
-		RINGMAP_ERROR("Wrong size of ring buffer! Exit!");
+	if (p->ring->size != SLOTS_NUMBER){
+		RINGMAP_ERROR("Wrong size of ring buffer!");
 		return -1;
 	}
 	
 #if (__RINGMAP_DEB)
+	printf("Virtual address of ring is 0x%X\n", p->ring);
 	printf("Ring Size = %d \n", p->ring->size);
-#endif 
 
 	for(i=0 ;i < SLOTS_NUMBER; i++){
-		printf("%d. packet.phys=0x%X\n ", i, p->ring->slot[i].packet.phys);
-
+		PRINT_PACKET_ADDR(p->ring, i);
 	}
-//	memoffset = (off_t)p->ring->hw_stats.phys;
-//	tmp_addr = mmap(0, sizeof(struct e1000_hw_stats), PROT_WRITE|PROT_READ, MAP_SHARED, devmem_fd, memoffset);
-//	if (tmp_addr == MAP_FAILED){
-//		RINGMAP_ERROR("Mapping of Statistics structure failed! Exit!");
-//		return -1;
-//	}
-//	p->nic_statistics = (struct e1000_hw_stats *)tmp_addr;
-
+#endif 
 
-
 	/* 
 	 * Mapping mbufs from kern to userspace. 
 	 * mbufs internal pointers contain kernel space addresses - 
@@ -179,72 +122,42 @@
 		/* Map mbuf */
 		memoffset = (off_t)p->ring->slot[i].mbuf.phys;
 		tmp_addr = 
-				mmap (		
-					0, 						/*	System will choose the addrress */
-					sizeof(struct mbuf),	/*	Size of mapped region = mbuf 	*/
-					PROT_WRITE|PROT_READ,	/*	protection: write & read 		*/
-					MAP_SHARED,				/*	shared maping					*/
-					devmem_fd,				/*	device is /dev/mem				*/
-					memoffset				/*	offset is physical addres 		*/
-				);
+			mmap (		
+				0, 						/*	System will choose the addrress */
+				sizeof(struct mbuf),	/*	Size of mapped region = mbuf 	*/
+				PROT_WRITE|PROT_READ,	/*	protection: write & read 		*/
+				MAP_SHARED,				/*	shared maping					*/
+				devmem_fd,				/*	device is /dev/mem				*/
+				memoffset				/*	offset is physical addres 		*/
+			);
 		if (tmp_addr == MAP_FAILED){
-			printf(ERR_PREFIX"[%s] Mapping of mbuf %d failed! Exit!\n", 
+			printf(ERR_PREFIX"[%s] Mapping of mbuf %d failed!\n", 
 								__func__, i);
 			return -1;
 		}
 		p->ring->slot[i].mbuf.user = (vm_offset_t)tmp_addr;
 
-
 		/* Map packet data */
 		memoffset = (off_t)p->ring->slot[i].packet.phys;
 		tmp_addr = 
-			mmap(0, MCLBYTES, PROT_WRITE|PROT_READ, MAP_SHARED,				
-				devmem_fd, memoffset);
+			mmap(	0, 
+					MCLBYTES, 
+					PROT_WRITE|PROT_READ, 
+					MAP_SHARED,				
+					devmem_fd, 
+					memoffset);
 		if (tmp_addr == MAP_FAILED){
-			printf(ERR_PREFIX"[%s] Mapping of packets buffer %d failed! Exit!\n", __func__, i);
+			printf(ERR_PREFIX"[%s] Mapping of packets buffer %d failed!\n", 
+					__func__, i);
 			return -1;
 		}
 		p->ring->slot[i].packet.user = (vm_offset_t)tmp_addr;
 		
-
-//		/* Map descriptor structure */
-//		memoffset = (off_t)p->ring->slot[i].descriptor.phys;
-//		tmp_addr = 
-//			mmap (		
-//				0, 						/*	System will choose the addrress */
-//				16,						/*	Size of region = descr struct	*/
-//				PROT_WRITE|PROT_READ,	/*	protection: write & read 		*/
-//				MAP_SHARED,				/*	shared maping					*/
-//				devmem_fd,				/*	device is /dev/mem				*/
-//				memoffset				/*	offset is physical addres 		*/
-//				);
-//		if (tmp_addr == MAP_FAILED){
-//			printf(ERR_PREFIX"[%s] Mapping of descriptor structure %d failed! Exit!\n", __func__, i);
-//			return -1;
-//		}
-//		p->ring->slot[i].descriptor.user = (vm_offset_t)tmp_addr;
-
-
 #if (__RINGMAP_DEB)
-	printf("[%s] %d packet.user=0x%X, packet.phys=0x%X, packet.kern=0x%X\n ", 
-		__func__, i, 
-		(unsigned int)p->ring->slot[i].packet.user, 
-		p->ring->slot[i].packet.phys, p->ring->slot[i].packet.kern);
+		PRINT_PACKET_ADDR(p->ring, i);
 #endif
 	}
 
-	/* Init our pcap variables */
-//	p->pkt_counter	=	0;
-//	p->buffer_fill	=	0;
-//	p->buffer_0		=	0;
-//	p->buffer_128	=	0;
-//	p->buffer_256	=	0;
-//	p->buffer_512	=	0;
-//	p->buffer_1024	=	0;
-//	p->buffer_2048 	=	0;
-//	p->buffer_4096	=	0;
-
-
 	/* Close memory device */
 	if (close(devmem_fd) == -1){
 		perror("close()");
@@ -255,6 +168,7 @@
 	return (0);
 }
 
+
 /*
  * Unmap buffers and free mem alocations 
  */
@@ -284,17 +198,11 @@
 					__func__, i);
 	}
 
-	if (p->ring != NULL){
-		tmp_res = munmap(p->ring, sizeof(struct ring));
-		if (tmp_res == -1)
-			printf(ERR_PREFIX"[%s] Error by unmapping of ring pointer structure %d\n", __func__, i);
+	tmp_res = munmap(p->ring, sizeof(struct ring));
+	if (tmp_res == -1) {
+		RINGMAP_ERROR(Unmaping the ring pointer);
 	}
 
-	//if (p->nic_statistics != NULL){
-	//	tmp_res = munmap(p->nic_statistics, sizeof(struct e1000_hw_stats));
-	//	if (tmp_res == -1)
-	//		printf(ERR_PREFIX"[%s] Error by unmapping of statistic structure %d\n", __func__, i);
-	//}
 out:	
 	if (ringmap_cdev_fd >= 0){
 		if ( close(ringmap_cdev_fd) == -1 )
@@ -304,6 +212,7 @@
 	RINGMAP_FUNC_DEBUG(end);
 }
 
+
 int
 pcap_read_ringmap(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
 {
@@ -331,12 +240,8 @@
 
 again: 
 	
-#ifdef __RINGMAP_DEB
-// 	printf("[%s] user to kern distance = %d\n", __func__, 
-		//	SW_TAIL_TO_HEAD_DIST(ring));
-#endif
-
 	if ( RING_IS_EMPTY(ring) ) {
+		RINGMAP_FUNC_DEBUG(Ring is empty. Sleep...);
 		/* Sleep and wait for new incoming packets */
 		ioctl(ringmap_cdev_fd, IOCTL_SLEEP_WAIT);
 		goto again;
@@ -370,6 +275,7 @@
 		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;
 
@@ -410,6 +316,7 @@
 	return (err);
 }
 
+
 int 
 print_ring_stats(pcap_t *p)
 {

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

@@ -82,7 +82,7 @@
 
 #include "e1000_api.h"
 #ifdef RINGMAP
-#include <net/ringmap.h>
+#include <../../net/ringmap.h>
 #endif
 #include "if_lem.h"
 
@@ -273,8 +273,10 @@
 
 #ifdef RINGMAP
 
-extern int ringmap_attach (device_t);
+extern int ringmap_attach (device_t, struct ringmap_functions *);
 extern int ringmap_detach (device_t);
+
+extern struct ringmap_functions ringmap_f;
 #endif 
 
 #ifdef DEVICE_POLLING
@@ -684,7 +686,7 @@
 	    device_get_nameunit(dev));
 
 #ifdef RINGMAP
-	ringmap_attach (dev);
+	ringmap_attach (dev, &ringmap_f);
 #endif 
 
 	INIT_DEBUGOUT("lem_attach: end");
@@ -1383,7 +1385,7 @@
 
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
 #ifdef RINGMAP
-		if (adapter->rm != NULL) {
+		if ((adapter->rm != NULL) && (adapter->rm->open_cnt > 0)) {
 			adapter->rm->funcs->delayed_isr(context);
 #endif
 		if (lem_rxeof(adapter, adapter->rx_process_limit) != 0)
@@ -1395,6 +1397,7 @@
 		}
 #endif 
 
+#ifdef RINGMAP
 #if (RINGMAP_TX_ENABLE)
 		EM_TX_LOCK(adapter);
 		lem_txeof(adapter);
@@ -1402,6 +1405,7 @@
 			lem_start_locked(ifp);
 		EM_TX_UNLOCK(adapter);
 #endif
+#endif
 	}
 
 	lem_enable_intr(adapter);

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

@@ -41,6 +41,21 @@
 extern void ringmap_print_slot(struct ring *, unsigned int);
 
 
+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_get_ringmap_p,
+	rm_8254_get_device_p
+};
 
 
 /* 
@@ -247,8 +262,8 @@
 		return (-1);
 	}
 	
-	RINGMAP_HW_WRITE_TAIL(adapter, 
-			(R_MODULO(RINGMAP_HW_READ_HEAD(adapter) - 1))); 
+//	RINGMAP_HW_WRITE_TAIL(adapter, 
+//			(R_MODULO(RINGMAP_HW_READ_HEAD(adapter) - 1))); 
 
 	SW_TAIL(ring) = RINGMAP_HW_READ_TAIL(adapter);
 

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


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


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

@@ -33,30 +33,16 @@
 
 #include "ringmap.h"
 
-int ringmap_attach (device_t);
+int ringmap_attach (device_t, struct ringmap_functions *);
 int ringmap_detach (device_t);
-int is_supported (unsigned int);
-int set_ringmap_funcs (struct ringmap *, unsigned int);
 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 *);
 
 struct ringmap *(*get_ringmap_p)(device_t);
 device_t 		(*get_device_p)(struct cdev *);
 
-extern int rm_8254_set_ringmap_to_adapter(device_t, struct ringmap *);
-extern struct ringmap * rm_8254_get_ringmap_p(device_t);
-extern device_t rm_8254_get_device_p(struct cdev *);
-extern void rm_8254_enable_intr(device_t);
-extern void rm_8254_disable_intr(device_t);
-extern void rm_8254_interrupt(void *);
-extern void rm_8254_delayed_interrupt(void *);
-extern void rm_8254_sync_head_tail(device_t, struct ring *);
-extern void rm_8254_sync_tail(device_t, struct ring *);
-extern void rm_8254_sync_head(device_t);
-extern void rm_8254_delayed_interrupt_per_packet(device_t, int);
-extern struct ring *rm_8254_alloc_ring(device_t);
-
 d_open_t	ringmap_open;
 d_close_t	ringmap_close;
 d_ioctl_t	ringmap_ioctl;
@@ -74,98 +60,18 @@
 	.d_name 	= "ringmap_cdev"
 };
 
-struct device_type supported_devices[] =
-{
-	/* PCI ID,	Controller	*/
-
-	{ 0x1079 , 	8254 },	/* 8254GB, COPPER, Dual Port */
-	{ 0x105E , 	8257 },	/* 82571EB, COPPER, PCIe Dual Port */ 	
-	{ 0, 0} 			/* last entry */
-};
-
-/*
- * If pci_dev_id is supported by ringmap, then controller_type related to this
- * pci_dev_id will be returned. Look for device_type structure in ringmap.h! 
- * Im -curent branch only  8254* controllers are supported. The list of
- * supported controllers doesn't include all of them, but only the controllers
- * that I've tested.
- */
-int 
-is_supported (unsigned int pci_dev_id)
-{
-	struct device_type *dt;
-
-	dt = supported_devices;
-	while (dt->pci_device_id != 0) {
-		if (pci_dev_id == dt->pci_device_id){
-			return (dt->controller_type);
-		}
-		dt++;
-	}
-	return (0);
-}
-
-/*
- * Set hardware-dependent functions 
- */
-int
-set_ringmap_funcs (struct ringmap *rm, unsigned int controller_type)
-{
-
-	switch(controller_type) {
-		case 8254:
-			RINGMAP_FUNC_DEBUG(Controller Type: 8254);
-			
-			rm->funcs->set_ringmap_to_adapter = 
-				rm_8254_set_ringmap_to_adapter;
-			rm->funcs->enable_intr  		= rm_8254_enable_intr;
-			rm->funcs->disable_intr 		= rm_8254_disable_intr;
-			rm->funcs->isr		 			= rm_8254_interrupt;
-			rm->funcs->delayed_isr			= rm_8254_delayed_interrupt;
-			rm->funcs->delayed_isr_per_packet = 
-				rm_8254_delayed_interrupt_per_packet;
-			rm->funcs->sync_head_tail 		= rm_8254_sync_head_tail;
-			rm->funcs->sync_tail 			= rm_8254_sync_tail;
-			rm->funcs->sync_head 			= rm_8254_sync_head;
-			rm->funcs->alloc_ring			= rm_8254_alloc_ring;
-
-			get_ringmap_p = rm_8254_get_ringmap_p;
-			get_device_p  =	rm_8254_get_device_p;
-		break;
-
-		case 8257:
-			RINGMAP_FUNC_DEBUG(Controller Type: 8257);
-			RINGMAP_FUNC_DEBUG(Now not supported!);
-
-		break;
-
-		default:
-			RINGMAP_FUNC_DEBUG(Unsupported Controller Type!);
-	}
-	return (0);
-}
 
 /*
  * Will called from if_em.c before returning from 
  * em_attach() function.  
  */
 int 
-ringmap_attach(device_t dev) 
+ringmap_attach(device_t dev, struct ringmap_functions *rf) 
 {	
-	struct ringmap *rm;
-	struct ringmap_functions *funcs;
-	unsigned int pci_dev_id = 0;
-	unsigned int controller_type = 0;
+	struct ringmap *rm = NULL;
 
 	RINGMAP_FUNC_DEBUG(begin);
 
-	pci_dev_id = pci_get_device(dev);
-
-	/* Make sure we are support this controller */
-	controller_type = is_supported(pci_dev_id);
-	if (!(controller_type))
-		return (-1);
-
 	rm = (struct ringmap *) contigmalloc (sizeof(struct ringmap), 
 							M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
 	if (rm == NULL) { 
@@ -173,24 +79,15 @@
 		return (-1); 
 	}
 
-	funcs = (struct ringmap_functions *) contigmalloc 
-			(
-				sizeof (struct ringmap_functions),
-				M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0
-			);
-	if (funcs == NULL) { 
-		RINGMAP_ERROR(Can not allocate space for ringmap_functions structure); 
-		return (-1); 
-	}
-	rm->funcs 	= funcs;
-	/* Set functions for ringmap functionality depending on controller type */
-	set_ringmap_funcs(rm, controller_type);
+	rm->funcs = rf;
+
+	get_ringmap_p = rf->dev_to_ringmap;
+	get_device_p = rf->cdev_to_dev;
 
 	/* 
 	 * Create char device for communication with user-space. The user-space
-	 * process wich want to capture should first open this device. Then, by
-	 * syscalls 
-	 * on this device it will: 
+	 * process wich want to capture packets should first open this device.
+	 * Then, by syscalls on this device it will: 
 	 * - 	get physical adresses of packet buffers for mapping them in its 
 	 * 		virtual memory space 
 	 *
@@ -207,7 +104,7 @@
 	/* Store adapters device structure */
 	rm->dev = dev;
 
-	/* Initialize our list of capturing instances */
+	/* Initialize the list of capturing instances */
 	SLIST_INIT(&rm->instance_list);
 
 	/* Init the mutex to protecting our data */
@@ -246,7 +143,7 @@
 	
 	RINGMAP_LOCK_DESTROY(rm);
 
-	contigfree(rm->funcs, sizeof(struct ringmap_functions), M_DEVBUF);
+	// contigfree(rm->funcs, sizeof(struct ringmap_functions), M_DEVBUF);
 	contigfree(rm, sizeof(struct ringmap), M_DEVBUF);
 
 	RINGMAP_FUNC_DEBUG(end);
@@ -256,10 +153,9 @@
 
 
 /******************************************************************
- * Open device and get the pointer of user process structure. 
- * We will use the address space of this process to map there 
- * the mbufs and buffers with packets data. So it all will 
- * be accesseble in this user proccess.
+ * This func will called as result of open(2). Here we allocate 
+ * the memory for the new packets ring that will associated with 
+ * current thread. 
  ******************************************************************/
 int
 ringmap_open(struct cdev *cdev, int flag, int otyp, struct thread *td)
@@ -270,11 +166,6 @@
 
 	RINGMAP_FUNC_DEBUG(start);
 
-#if (__RINGMAP_DEB) 
-	printf("[%s]: dev_t=%d, flag=%x, otyp=%x\n", 
-			__func__, dev2udev(cdev), flag, otyp);
-#endif
-
 	/* a little magic */
 	rm = get_ringmap_p(get_device_p(cdev));
 	if ( rm == NULL ) {
@@ -283,6 +174,10 @@
 		return (EIO);
 	}
 
+	/* 
+	 * crete the capturing instance wich will presents 
+	 * current thread and packets ring 
+	 */
 	MALLOC(ci, struct capt_instance *, 
 			sizeof(struct capt_instance), M_DEVBUF, (M_ZERO | M_WAITOK));
 	if ( ci == NULL ){
@@ -300,7 +195,7 @@
 	/* Allocate ring */
 	ci->ring = rm->funcs->alloc_ring(rm->dev);
 	if ( ci->ring == NULL ) {
-		RINGMAP_ERROR(Error! Please debug!);
+		RINGMAP_ERROR(The ring is not allocated);
 
 		err = EIO; goto out;
 	}
@@ -311,16 +206,14 @@
 	SLIST_INSERT_HEAD(&rm->instance_list, ci, next_instance);
 
 	if ( devfs_set_cdevpriv((void *)ci, clear_capt_instance) ) {
-		RINGMAP_ERROR(Ooooooooooooooohhhhhhhh !!!!!);
+		RINGMAP_ERROR(The pointer to the private data is not set!);
 		err = EIO; goto out;
 	}
 	
 	rm->open_cnt++;
+
 #ifdef __RINGMAP_DEB
-	printf("[%s] currthread->proc->pid: %d \n", __func__, curthread->td_proc->p_pid);
-	printf("[%s] ci->td->proc->pid: %d\n", __func__, ci->td->td_proc->p_pid);
-
-	printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring);
+	print_capt_inst(ci);
 #endif 
 
 out:
@@ -333,7 +226,6 @@
 	return (err);
 }
 
-
 int
 ringmap_close(struct cdev *cdev, int flag, int otyp, struct thread *td)
 {
@@ -350,17 +242,14 @@
 	devfs_get_cdevpriv((void **)&ci);
 
 #ifdef __RINGMAP_DEB
-	printf("[%s] ci->td->proc->pid: %d\n", __func__, ci->td->td_proc->p_pid);
-	printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring);
+	print_capt_inst(ci);
 #endif 
 
-	rm->open_cnt--;
 
 #ifdef __RINGMAP_DEB
 	SLIST_FOREACH(ki, &rm->instance_list, next_instance) {
-	printf("[%s] Aufter dealocation: ", __func__);
-	printf("[%s] ki->td->proc->pid: %d\n", __func__, ki->td->td_proc->p_pid);
-	printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ki->ring);
+		printf("[%s] Aufter dealocation: ", __func__);
+		print_capt_inst(ki);
 	}
 #endif 	
 
@@ -395,7 +284,6 @@
 		err = ERESTART; goto out;
 	}
 
-	/* -> Critical Section: begin */
 	RINGMAP_LOCK(rm);
 
 	if (devfs_get_cdevpriv((void **)&ci)) {
@@ -426,6 +314,7 @@
 
 	RINGMAP_IOCTL(start);
 
+	/* Eliminate it */
 	ringmap = get_ringmap_p(get_device_p(cdev));
 	if ( ringmap == NULL ){
 		RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished);
@@ -494,17 +383,18 @@
 clear_capt_instance(void * data)
 {
 	struct capt_instance *ci = NULL;
+	struct ringmap *rm = NULL;
 
 	RINGMAP_FUNC_DEBUG(start);
 
 	if ( data != NULL ) {
 		ci = (struct capt_instance *)data;
-		RINGMAP_LOCK(ci->rm);
+		rm = ci->rm;
+
+		RINGMAP_LOCK(rm);
 #ifdef __RINGMAP_DEB
-	printf("[%s] ci->td->proc->pid: %d\n", __func__, ci->td->td_proc->p_pid);
-	printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring);
+		print_capt_inst(ci);
 #endif 
-
 		if ( ci->ring != NULL ){
 			contigfree(ci->ring, sizeof(struct ring), M_DEVBUF);
 			SLIST_REMOVE(&ci->rm->instance_list, ci, capt_instance, next_instance);
@@ -515,7 +405,9 @@
 		RINGMAP_FUNC_DEBUG(NULL pointer to the capturing instance!);
 	}
 	
-	RINGMAP_UNLOCK(ci->rm);
+	rm->open_cnt--;
+
+	RINGMAP_UNLOCK(rm);
 
 	RINGMAP_FUNC_DEBUG(end);
 }
@@ -546,3 +438,16 @@
 
 	printf("---------------- \n");
 }
+
+
+void 
+print_capt_inst(struct capt_instance *ci)
+{
+	if (ci != NULL) {
+		printf("[%s] ci->td->proc->pid: %d\n", 
+				__func__, ci->td->td_proc->p_pid);
+
+		printf("[%s] Ring Kernel Addr:0x%X\n", 
+				__func__, (unsigned int)ci->ring);
+	}
+}

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

@@ -6,7 +6,7 @@
 /* 
  * Prefix for name of device (for example /dev/ringmap_cdev0 will full name) 
  */
-#define RINGMAP_DEVICE 		"ringmap_cdev"
+#define RINGMAP_DEVICE 		"ringmap"
 
 /* Name of module to be loaded*/
 #define MOD_NAME 			"if_ringmap.ko"
@@ -147,11 +147,6 @@
 #ifdef _KERNEL
 struct ringmap_functions;
 
-struct device_type {
-	unsigned int pci_device_id;
-	unsigned int controller_type;
-};
-
 struct capt_instance {
 	struct thread *td;
 	struct ring *ring;
@@ -260,6 +255,9 @@
 
 	/* Alloc memory for our ring and initialize the slots */
 	struct ring *(*alloc_ring)(device_t);
+
+	struct ringmap *(*dev_to_ringmap)(device_t);
+	device_t (*cdev_to_dev)(struct cdev *);
 };
 
 /* MUTEX */
@@ -460,3 +458,10 @@
 		PRINT_SOME_BYTES_FROM_PKT((arg), (i));							\
 		printf("=+= =============================\n\n");				\
 	}
+
+#define PRINT_PACKET_ADDR(ring, i)	\
+printf("[%s] %d packet.user=0x%X, packet.phys=0x%X, packet.kern=0x%X\n ",  \
+		__func__, i, 								\
+		(unsigned int)ring->slot[i].packet.user, 	\
+		ring->slot[i].packet.phys, 					\
+		ring->slot[i].packet.kern);

==== //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#9 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#10 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#5 (text+ko) ====




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