Index: uspace/srv/hw/netif/dp8390/dp8390.c
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390.c	(revision b590c21969e84cc37c042fe33dc10778006e293d)
+++ uspace/srv/hw/netif/dp8390/dp8390.c	(revision d3a0af7ed10e1245cda2188e4579de026afa89e8)
@@ -54,12 +54,11 @@
 static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst);
 static int dp_pkt2user(dpeth_t *dep, int page, int length);
-static void dp_pio8_user2nic(dpeth_t *dep, iovec_dat_t *iovp, vir_bytes offset, int nic_addr, vir_bytes count);
-static void dp_pio16_user2nic(dpeth_t *dep, iovec_dat_t *iovp, vir_bytes offset, int nic_addr, vir_bytes count);
-static void dp_pio8_nic2user(dpeth_t *dep, int nic_addr, iovec_dat_t *iovp, vir_bytes offset, vir_bytes count);
-static void dp_pio16_nic2user(dpeth_t *dep, int nic_addr, iovec_dat_t *iovp, vir_bytes offset, vir_bytes count);
+static void dp_pio8_user2nic(dpeth_t *dep, iovec_dat_t *iovp, size_t offset, int nic_addr, size_t count);
+static void dp_pio16_user2nic(dpeth_t *dep, iovec_dat_t *iovp, size_t offset, int nic_addr, size_t count);
+static void dp_pio8_nic2user(dpeth_t *dep, int nic_addr, iovec_dat_t *iovp, size_t offset, size_t count);
+static void dp_pio16_nic2user(dpeth_t *dep, int nic_addr, iovec_dat_t *iovp, size_t offset, size_t count);
 static void dp_next_iovec(iovec_dat_t *iovp);
 static void conf_hw(dpeth_t *dep);
 static void reply(dpeth_t *dep, int err, int may_block);
-static void get_userdata(int user_proc, vir_bytes user_addr, vir_bytes count, void *loc_addr);
 static void insb(port_t port, void *buf, size_t size);
 static void insw(port_t port, void *buf, size_t size);
@@ -205,5 +204,4 @@
 			sizeof(iovec_t), dep->de_write_iovec.iod_iovec);
 		dep->de_write_iovec.iod_iovec_s = count;
-		dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
 		dep->de_write_iovec.iod_iovec_addr = (vir_bytes) mp->DL_ADDR;
 		
@@ -216,5 +214,4 @@
 			mp->DL_COUNT;
 		dep->de_write_iovec.iod_iovec_s = 1;
-		dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
 		dep->de_write_iovec.iod_iovec_addr = 0;
 		size= mp->DL_COUNT;
@@ -222,8 +219,8 @@
 */
 	size = packet_get_data_length(packet);
-	dep->de_write_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_get_data(packet);
+	dep->de_write_iovec.iod_iovec[0].iov_addr = (void *) packet_get_data(packet);
 	dep->de_write_iovec.iod_iovec[0].iov_size = size;
 	dep->de_write_iovec.iod_iovec_s = 1;
-	dep->de_write_iovec.iod_iovec_addr = (uintptr_t) NULL;
+	dep->de_write_iovec.iod_iovec_addr = NULL;
 	
 	if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED) {
@@ -556,5 +553,5 @@
 	//unsigned pageno, curr, next;
 	int pageno, curr, next;
-	vir_bytes length;
+	size_t length;
 	int packet_processed, r;
 	uint16_t eth_type;
@@ -683,8 +680,8 @@
 		return ENOMEM;
 	
-	dep->de_read_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_suffix(packet, length);
+	dep->de_read_iovec.iod_iovec[0].iov_addr = (void *) packet_suffix(packet, length);
 	dep->de_read_iovec.iod_iovec[0].iov_size = length;
 	dep->de_read_iovec.iod_iovec_s = 1;
-	dep->de_read_iovec.iod_iovec_addr = (uintptr_t) NULL;
+	dep->de_read_iovec.iod_iovec_addr = NULL;
 	
 	last = page + (length - 1) / DP_PAGESIZE;
@@ -720,113 +717,105 @@
 }
 
-static void dp_pio8_user2nic(dpeth_t *dep, iovec_dat_t *iovp, vir_bytes offset, int nic_addr, vir_bytes count)
+static void dp_pio8_user2nic(dpeth_t *dep, iovec_dat_t *iovp, size_t offset, int nic_addr, size_t count)
 {
 //	phys_bytes phys_user;
 	int i;
-	vir_bytes bytes;
-
+	size_t bytes;
+	
 	outb_reg0(dep, DP_ISR, ISR_RDC);
-
-	outb_reg0(dep, DP_RBCR0, count &0xFF);
+	
+	outb_reg0(dep, DP_RBCR0, count & 0xFF);
 	outb_reg0(dep, DP_RBCR1, count >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
 	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
 	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
+	
+	i = 0;
+	while (count > 0) {
+		if (i >= IOVEC_NR) {
 			dp_next_iovec(iovp);
-			i= 0;
+			i = 0;
 			continue;
 		}
+		
 		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
+		
+		if (offset >= iovp->iod_iovec[i].iov_size) {
 			offset -= iovp->iod_iovec[i].iov_size;
 			i++;
 			continue;
 		}
+		
 		bytes = iovp->iod_iovec[i].iov_size - offset;
 		if (bytes > count)
 			bytes = count;
-
-		do_vir_outsb(dep->de_data_port, iovp->iod_proc_nr,
-			iovp->iod_iovec[i].iov_addr + offset, bytes);
+		
+		do_vir_outsb(dep->de_data_port, iovp->iod_iovec[i].iov_addr + offset, bytes);
 		count -= bytes;
 		offset += bytes;
 	}
+	
 	assert(count == 0);
-
-	for (i= 0; i<100; i++)
-	{
-		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
+	
+	for (i = 0; i < 100; i++) {
+		if (inb_reg0(dep, DP_ISR) & ISR_RDC)
 			break;
 	}
+	
 	if (i == 100)
 		fprintf(stderr, "dp8390: remote dma failed to complete\n");
 }
 
-/*===========================================================================*
- *				dp_pio16_user2nic			     *
- *===========================================================================*/
-static void dp_pio16_user2nic(dep, iovp, offset, nic_addr, count)
-dpeth_t *dep;
-iovec_dat_t *iovp;
-vir_bytes offset;
-int nic_addr;
-vir_bytes count;
-{
-	vir_bytes vir_user;
-	vir_bytes ecount;
-	int i, r, user_proc;
-	vir_bytes bytes;
+static void dp_pio16_user2nic(dpeth_t *dep, iovec_dat_t *iovp, size_t offset, int nic_addr, size_t count)
+{
+	void *vir_user;
+	size_t ecount;
+	int i, r;
+	size_t bytes;
 	//uint8_t two_bytes[2];
 	uint16_t two_bytes;
 	int odd_byte;
-
-	ecount= (count+1) &~1;
-	odd_byte= 0;
-
+	
+	ecount = (count + 1) & ~1;
+	odd_byte = 0;
+	
 	outb_reg0(dep, DP_ISR, ISR_RDC);
-	outb_reg0(dep, DP_RBCR0, ecount &0xFF);
+	outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
 	outb_reg0(dep, DP_RBCR1, ecount >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
 	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
 	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
+	
+	i = 0;
+	while (count > 0) {
+		if (i >= IOVEC_NR) {
 			dp_next_iovec(iovp);
-			i= 0;
+			i = 0;
 			continue;
 		}
+		
 		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
+		
+		if (offset >= iovp->iod_iovec[i].iov_size) {
 			offset -= iovp->iod_iovec[i].iov_size;
 			i++;
 			continue;
 		}
+		
 		bytes = iovp->iod_iovec[i].iov_size - offset;
 		if (bytes > count)
 			bytes = count;
-
-		user_proc= iovp->iod_proc_nr;
-		vir_user= iovp->iod_iovec[i].iov_addr + offset;
-		if (odd_byte)
-		{
-			r= sys_vircopy(user_proc, D, vir_user, 
-			//	SELF, D, (vir_bytes)&two_bytes[1], 1);
-				SELF, D, (vir_bytes)&(((uint8_t *)&two_bytes)[1]), 1);
+		
+		vir_user = iovp->iod_iovec[i].iov_addr + offset;
+		
+		if (odd_byte) {
+			r = sys_vircopy(user_proc, D, vir_user,
+			//	SELF, D, (vir_bytes) &two_bytes[1], 1);
+				SELF, D, &(((uint8_t *) &two_bytes)[1]), 1);
+			
 			if (r != EOK)
 				fprintf(stderr, "DP8390: dp_pio16_user2nic: sys_vircopy failed\n");
 			
-			//outw(dep->de_data_port, *(uint16_t *)two_bytes);
+			//outw(dep->de_data_port, *(uint16_t *) two_bytes);
 			outw(dep->de_data_port, two_bytes);
 			count--;
@@ -835,12 +824,12 @@
 			vir_user++;
 			odd_byte= 0;
+			
 			if (!bytes)
 				continue;
 		}
-		ecount= bytes &~1;
-		if (ecount != 0)
-		{
-			do_vir_outsw(dep->de_data_port, user_proc, vir_user,
-				ecount);
+		
+		ecount= bytes & ~1;
+		if (ecount != 0) {
+			do_vir_outsw(dep->de_data_port, vir_user, ecount);
 			count -= ecount;
 			offset += ecount;
@@ -848,10 +837,12 @@
 			vir_user += ecount;
 		}
-		if (bytes)
-		{
+		
+		if (bytes) {
 			assert(bytes == 1);
-			r= sys_vircopy(user_proc, D, vir_user, 
-			//	SELF, D, (vir_bytes)&two_bytes[0], 1);
-				SELF, D, (vir_bytes)&(((uint8_t *)&two_bytes)[0]), 1);
+			
+			r = sys_vircopy(user_proc, D, vir_user,
+			//	SELF, D, (vir_bytes) &two_bytes[0], 1);
+				SELF, D, &(((uint8_t *) &two_bytes)[0]), 1);
+			
 			if (r != EOK)
 				fprintf(stderr, "DP8390: dp_pio16_user2nic: sys_vircopy failed\n");
@@ -864,121 +855,105 @@
 		}
 	}
+	
 	assert(count == 0);
-
+	
 	if (odd_byte)
-		//outw(dep->de_data_port, *(uint16_t *)two_bytes);
+		//outw(dep->de_data_port, *(uint16_t *) two_bytes);
 		outw(dep->de_data_port, two_bytes);
-
-	for (i= 0; i<100; i++)
-	{
+	
+	for (i = 0; i < 100; i++) {
 		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
 			break;
 	}
+	
 	if (i == 100)
 		fprintf(stderr, "dp8390: remote dma failed to complete\n");
 }
 
-/*===========================================================================*
- *				dp_pio8_nic2user			     *
- *===========================================================================*/
-static void dp_pio8_nic2user(dep, nic_addr, iovp, offset, count)
-dpeth_t *dep;
-int nic_addr;
-iovec_dat_t *iovp;
-vir_bytes offset;
-vir_bytes count;
+static void dp_pio8_nic2user(dpeth_t *dep, int nic_addr, iovec_dat_t *iovp, size_t offset, size_t count)
 {
 //	phys_bytes phys_user;
 	int i;
-	vir_bytes bytes;
-
-	outb_reg0(dep, DP_RBCR0, count &0xFF);
+	size_t bytes;
+	
+	outb_reg0(dep, DP_RBCR0, count & 0xFF);
 	outb_reg0(dep, DP_RBCR1, count >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
 	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
 	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
+	
+	i = 0;
+	while (count > 0) {
+		if (i >= IOVEC_NR) {
 			dp_next_iovec(iovp);
 			i= 0;
 			continue;
 		}
+		
 		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
+		
+		if (offset >= iovp->iod_iovec[i].iov_size) {
 			offset -= iovp->iod_iovec[i].iov_size;
 			i++;
 			continue;
 		}
+		
 		bytes = iovp->iod_iovec[i].iov_size - offset;
 		if (bytes > count)
 			bytes = count;
-
-		do_vir_insb(dep->de_data_port, iovp->iod_proc_nr,
-			iovp->iod_iovec[i].iov_addr + offset, bytes);
+		
+		do_vir_insb(dep->de_data_port, iovp->iod_iovec[i].iov_addr + offset, bytes);
 		count -= bytes;
 		offset += bytes;
 	}
+	
 	assert(count == 0);
 }
 
-/*===========================================================================*
- *				dp_pio16_nic2user			     *
- *===========================================================================*/
-static void dp_pio16_nic2user(dep, nic_addr, iovp, offset, count)
-dpeth_t *dep;
-int nic_addr;
-iovec_dat_t *iovp;
-vir_bytes offset;
-vir_bytes count;
-{
-	vir_bytes vir_user;
-	vir_bytes ecount;
-	int i, r, user_proc;
-	vir_bytes bytes;
+static void dp_pio16_nic2user(dpeth_t *dep, int nic_addr, iovec_dat_t *iovp, size_t offset, size_t count)
+{
+	void *vir_user;
+	size_t ecount;
+	int i, r;
+	size_t bytes;
 	//uint8_t two_bytes[2];
 	uint16_t two_bytes;
 	int odd_byte;
-
-	ecount= (count+1) &~1;
-	odd_byte= 0;
-
-	outb_reg0(dep, DP_RBCR0, ecount &0xFF);
+	
+	ecount = (count + 1) & ~1;
+	odd_byte = 0;
+	
+	outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
 	outb_reg0(dep, DP_RBCR1, ecount >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
 	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
 	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
+	
+	i = 0;
+	while (count > 0) {
+		if (i >= IOVEC_NR) {
 			dp_next_iovec(iovp);
-			i= 0;
+			i = 0;
 			continue;
 		}
+		
 		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
+		
+		if (offset >= iovp->iod_iovec[i].iov_size) {
 			offset -= iovp->iod_iovec[i].iov_size;
 			i++;
 			continue;
 		}
+		
 		bytes = iovp->iod_iovec[i].iov_size - offset;
 		if (bytes > count)
 			bytes = count;
-
-		user_proc= iovp->iod_proc_nr;
-		vir_user= iovp->iod_iovec[i].iov_addr + offset;
-		if (odd_byte)
-		{
+		
+		vir_user = iovp->iod_iovec[i].iov_addr + offset;
+		
+		if (odd_byte) {
 			//r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[1],
-			r= sys_vircopy(SELF, D, (vir_bytes)&(((uint8_t *)&two_bytes)[1]),
-				user_proc, D, vir_user,  1);
+			r= sys_vircopy(SELF, D, &(((uint8_t *) &two_bytes)[1]),
+			    user_proc, D, vir_user, 1);
 			if (r != EOK)
 				fprintf(stderr, "DP8390: dp_pio16_nic2user: sys_vircopy failed\n");
@@ -989,12 +964,12 @@
 			vir_user++;
 			odd_byte= 0;
+			
 			if (!bytes)
 				continue;
 		}
-		ecount= bytes &~1;
-		if (ecount != 0)
-		{
-			do_vir_insw(dep->de_data_port, user_proc, vir_user,
-				ecount);
+		
+		ecount= bytes & ~1;
+		if (ecount != 0) {
+			do_vir_insw(dep->de_data_port, vir_user, ecount);
 			count -= ecount;
 			offset += ecount;
@@ -1002,12 +977,13 @@
 			vir_user += ecount;
 		}
-		if (bytes)
-		{
+		
+		if (bytes) {
 			assert(bytes == 1);
-			//*(uint16_t *)two_bytes= inw(dep->de_data_port);
-			two_bytes= inw(dep->de_data_port);
-			//r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[0],
-			r= sys_vircopy(SELF, D, (vir_bytes)&(((uint8_t *)&two_bytes)[0]),
-				user_proc, D, vir_user,  1);
+			
+			//*(uint16_t *) two_bytes= inw(dep->de_data_port);
+			two_bytes = inw(dep->de_data_port);
+			//r= sys_vircopy(SELF, D, (vir_bytes) &two_bytes[0],
+			r = sys_vircopy(SELF, D, &(((uint8_t *) &two_bytes)[0]),
+			    user_proc, D, vir_user,  1);
 			if (r != EOK)
 				fprintf(stderr, "DP8390: dp_pio16_nic2user: sys_vircopy failed\n");
@@ -1020,42 +996,35 @@
 		}
 	}
+	
 	assert(count == 0);
 }
 
-/*===========================================================================*
- *				dp_next_iovec				     *
- *===========================================================================*/
-static void dp_next_iovec(iovp)
-iovec_dat_t *iovp;
+static void dp_next_iovec(iovec_dat_t *iovp)
 {
 	assert(iovp->iod_iovec_s > IOVEC_NR);
-
+	
 	iovp->iod_iovec_s -= IOVEC_NR;
-
 	iovp->iod_iovec_addr += IOVEC_NR * sizeof(iovec_t);
-
-	get_userdata(iovp->iod_proc_nr, iovp->iod_iovec_addr, 
-		(iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
-		sizeof(iovec_t), iovp->iod_iovec); 
-}
-
-/*===========================================================================*
- *				conf_hw					     *
- *===========================================================================*/
-static void conf_hw(dep)
-dpeth_t *dep;
+	
+	memcpy(iovp->iod_iovec, iovp->iod_iovec_addr,
+	    (iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
+	    sizeof(iovec_t));
+}
+
+static void conf_hw(dpeth_t *dep)
 {
 //	static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0 	/* ,... */};
-
+	
 //	int ifnr;
 //	dp_conf_t *dcp;
-
+	
 //	dep->de_mode= DEM_DISABLED;	/* Superfluous */
 //	ifnr= dep-de_table;
-
+	
 //	dcp= &dp_conf[ifnr];
 //	update_conf(dep, dcp);
 //	if (dep->de_mode != DEM_ENABLED)
 //		return;
+	
 	if (!ne_probe(dep)) {
 		printf("%s: No ethernet card found at %#lx\n",
@@ -1064,31 +1033,23 @@
 		return;
 	}
-
-/* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000;
-
+	
 	dep->de_mode = DEM_ENABLED;
-
 	dep->de_flags = DEF_EMPTY;
 //	dep->de_stat = empty_stat;
 }
 
-/*===========================================================================*
- *				reply					     *
- *===========================================================================*/
-static void reply(dep, err, may_block)
-dpeth_t *dep;
-int err;
-int may_block;
+static void reply(dpeth_t *dep, int err, int may_block)
 {
 /*	message reply;
 	int status;
 	int r;
-
+	
 	status = 0;
 	if (dep->de_flags &DEF_PACK_SEND)
 		status |= DL_PACK_SEND;
+	
 	if (dep->de_flags &DEF_PACK_RECV)
 		status |= DL_PACK_RECV;
-
+	
 	reply.m_type = DL_TASK_REPLY;
 	reply.DL_PORT = dep - de_table;
@@ -1096,15 +1057,12 @@
 	reply.DL_STAT = status | ((u32_t) err << 16);
 	reply.DL_COUNT = dep->de_read_s;
-	reply.DL_CLCK = 0;	*//* Don't know */
-/*	r= send(dep->de_client, &reply);
-
-	if (r == ELOCKED && may_block)
-	{
-#if 0
+	reply.DL_CLCK = 0;  *//* Don't know */
+	
+/*	r = send(dep->de_client, &reply);
+	if (r == ELOCKED && may_block) {
 		printf("send locked\n");
-#endif
 		return;
 	}
-
+	
 	if (r < 0)
 		fprintf(stderr, "dp8390: send failed\n");
@@ -1114,28 +1072,10 @@
 }
 
-/*===========================================================================*
- *				get_userdata				     *
- *===========================================================================*/
-static void get_userdata(user_proc, user_addr, count, loc_addr)
-int user_proc;
-vir_bytes user_addr;
-vir_bytes count;
-void *loc_addr;
-{
-	int r;
-
-	r= sys_vircopy(user_proc, D, user_addr,
-		SELF, D, (vir_bytes)loc_addr, count);
-	if (r != EOK)
-		fprintf(stderr, "DP8390: get_userdata: sys_vircopy failed\n");
-}
-
 static void insb(port_t port, void *buf, size_t size)
 {
 	size_t i;
-
-	for(i = 0; i < size; ++ i){
+	
+	for (i = 0; i < size; i++)
 		*((uint8_t *) buf + i) = inb(port);
-	}
 }
 
@@ -1143,8 +1083,7 @@
 {
 	size_t i;
-
-	for(i = 0; i * 2 < size; ++ i){
+	
+	for (i = 0; i * 2 < size; i++)
 		*((uint16_t *) buf + i) = inw(port);
-	}
 }
 
@@ -1152,8 +1091,7 @@
 {
 	size_t i;
-
-	for(i = 0; i < size; ++ i){
+	
+	for (i = 0; i < size; i++)
 		outb(port, *((uint8_t *) buf + i));
-	}
 }
 
@@ -1161,8 +1099,7 @@
 {
 	size_t i;
-
-	for(i = 0; i * 2 < size; ++ i){
+	
+	for (i = 0; i * 2 < size; i++)
 		outw(port, *((uint16_t *) buf + i));
-	}
 }
 
