netmap_mem2.c (259412) | netmap_mem2.c (260368) |
---|---|
1/* | 1/* |
2 * Copyright (C) 2012-2013 Matteo Landi, Luigi Rizzo, Giuseppe Lettieri. All rights reserved. | 2 * Copyright (C) 2012-2014 Matteo Landi, Luigi Rizzo, Giuseppe Lettieri. All rights reserved. |
3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the --- 17 unchanged lines hidden (view full) --- 28#endif /* linux */ 29 30#ifdef __APPLE__ 31#include "osx_glue.h" 32#endif /* __APPLE__ */ 33 34#ifdef __FreeBSD__ 35#include <sys/cdefs.h> /* prerequisite */ | 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the --- 17 unchanged lines hidden (view full) --- 28#endif /* linux */ 29 30#ifdef __APPLE__ 31#include "osx_glue.h" 32#endif /* __APPLE__ */ 33 34#ifdef __FreeBSD__ 35#include <sys/cdefs.h> /* prerequisite */ |
36__FBSDID("$FreeBSD: head/sys/dev/netmap/netmap_mem2.c 259412 2013-12-15 08:37:24Z luigi $"); | 36__FBSDID("$FreeBSD: head/sys/dev/netmap/netmap_mem2.c 260368 2014-01-06 12:53:15Z luigi $"); |
37 38#include <sys/types.h> 39#include <sys/malloc.h> 40#include <sys/proc.h> 41#include <vm/vm.h> /* vtophys */ 42#include <vm/pmap.h> /* vtophys */ 43#include <sys/socket.h> /* sockaddrs */ 44#include <sys/selinfo.h> --- 456 unchanged lines hidden (view full) --- 501 u_int clustentries; /* how many objects per entry */ 502 503 /* we store the current request, so we can 504 * detect configuration changes later */ 505 p->r_objtotal = objtotal; 506 p->r_objsize = objsize; 507 508#define MAX_CLUSTSIZE (1<<17) | 37 38#include <sys/types.h> 39#include <sys/malloc.h> 40#include <sys/proc.h> 41#include <vm/vm.h> /* vtophys */ 42#include <vm/pmap.h> /* vtophys */ 43#include <sys/socket.h> /* sockaddrs */ 44#include <sys/selinfo.h> --- 456 unchanged lines hidden (view full) --- 501 u_int clustentries; /* how many objects per entry */ 502 503 /* we store the current request, so we can 504 * detect configuration changes later */ 505 p->r_objtotal = objtotal; 506 p->r_objsize = objsize; 507 508#define MAX_CLUSTSIZE (1<<17) |
509#define LINE_ROUND 64 | 509#define LINE_ROUND NM_CACHE_ALIGN // 64 |
510 if (objsize >= MAX_CLUSTSIZE) { 511 /* we could do it but there is no point */ 512 D("unsupported allocation for %d bytes", objsize); 513 return EINVAL; 514 } 515 /* make sure objsize is a multiple of LINE_ROUND */ 516 i = (objsize & (LINE_ROUND - 1)); 517 if (i) { --- 437 unchanged lines hidden (view full) --- 955 ring = netmap_ring_malloc(na->nm_mem, len); 956 if (ring == NULL) { 957 D("Cannot allocate tx_ring"); 958 goto cleanup; 959 } 960 ND("txring[%d] at %p ofs %d", i, ring); 961 kring->ring = ring; 962 *(uint32_t *)(uintptr_t)&ring->num_slots = ndesc; | 510 if (objsize >= MAX_CLUSTSIZE) { 511 /* we could do it but there is no point */ 512 D("unsupported allocation for %d bytes", objsize); 513 return EINVAL; 514 } 515 /* make sure objsize is a multiple of LINE_ROUND */ 516 i = (objsize & (LINE_ROUND - 1)); 517 if (i) { --- 437 unchanged lines hidden (view full) --- 955 ring = netmap_ring_malloc(na->nm_mem, len); 956 if (ring == NULL) { 957 D("Cannot allocate tx_ring"); 958 goto cleanup; 959 } 960 ND("txring[%d] at %p ofs %d", i, ring); 961 kring->ring = ring; 962 *(uint32_t *)(uintptr_t)&ring->num_slots = ndesc; |
963 *(ssize_t *)(uintptr_t)&ring->buf_ofs = | 963 *(int64_t *)(uintptr_t)&ring->buf_ofs = |
964 (na->nm_mem->pools[NETMAP_IF_POOL].memtotal + 965 na->nm_mem->pools[NETMAP_RING_POOL].memtotal) - 966 netmap_ring_offset(na->nm_mem, ring); 967 | 964 (na->nm_mem->pools[NETMAP_IF_POOL].memtotal + 965 na->nm_mem->pools[NETMAP_RING_POOL].memtotal) - 966 netmap_ring_offset(na->nm_mem, ring); 967 |
968 ring->avail = kring->nr_hwavail; 969 ring->cur = kring->nr_hwcur; | 968 /* copy values from kring */ 969 ring->head = kring->rhead; 970 ring->cur = kring->rcur; 971 ring->tail = kring->rtail; |
970 *(uint16_t *)(uintptr_t)&ring->nr_buf_size = 971 NETMAP_BDG_BUF_SIZE(na->nm_mem); 972 ND("initializing slots for txring"); 973 if (netmap_new_bufs(na->nm_mem, ring->slot, ndesc)) { 974 D("Cannot allocate buffers for tx_ring"); 975 goto cleanup; 976 } 977 } --- 6 unchanged lines hidden (view full) --- 984 if (ring == NULL) { 985 D("Cannot allocate rx_ring"); 986 goto cleanup; 987 } 988 ND("rxring at %p ofs %d", ring); 989 990 kring->ring = ring; 991 *(uint32_t *)(uintptr_t)&ring->num_slots = ndesc; | 972 *(uint16_t *)(uintptr_t)&ring->nr_buf_size = 973 NETMAP_BDG_BUF_SIZE(na->nm_mem); 974 ND("initializing slots for txring"); 975 if (netmap_new_bufs(na->nm_mem, ring->slot, ndesc)) { 976 D("Cannot allocate buffers for tx_ring"); 977 goto cleanup; 978 } 979 } --- 6 unchanged lines hidden (view full) --- 986 if (ring == NULL) { 987 D("Cannot allocate rx_ring"); 988 goto cleanup; 989 } 990 ND("rxring at %p ofs %d", ring); 991 992 kring->ring = ring; 993 *(uint32_t *)(uintptr_t)&ring->num_slots = ndesc; |
992 *(ssize_t *)(uintptr_t)&ring->buf_ofs = | 994 *(int64_t *)(uintptr_t)&ring->buf_ofs = |
993 (na->nm_mem->pools[NETMAP_IF_POOL].memtotal + 994 na->nm_mem->pools[NETMAP_RING_POOL].memtotal) - 995 netmap_ring_offset(na->nm_mem, ring); 996 | 995 (na->nm_mem->pools[NETMAP_IF_POOL].memtotal + 996 na->nm_mem->pools[NETMAP_RING_POOL].memtotal) - 997 netmap_ring_offset(na->nm_mem, ring); 998 |
997 ring->cur = kring->nr_hwcur; 998 ring->avail = kring->nr_hwavail; | 999 /* copy values from kring */ 1000 ring->head = kring->rhead; 1001 ring->cur = kring->rcur; 1002 ring->tail = kring->rtail; |
999 *(int *)(uintptr_t)&ring->nr_buf_size = 1000 NETMAP_BDG_BUF_SIZE(na->nm_mem); 1001 ND("initializing slots for rxring[%d]", i); 1002 if (netmap_new_bufs(na->nm_mem, ring->slot, ndesc)) { 1003 D("Cannot allocate buffers for rx_ring"); 1004 goto cleanup; 1005 } 1006 } --- 134 unchanged lines hidden --- | 1003 *(int *)(uintptr_t)&ring->nr_buf_size = 1004 NETMAP_BDG_BUF_SIZE(na->nm_mem); 1005 ND("initializing slots for rxring[%d]", i); 1006 if (netmap_new_bufs(na->nm_mem, ring->slot, ndesc)) { 1007 D("Cannot allocate buffers for rx_ring"); 1008 goto cleanup; 1009 } 1010 } --- 134 unchanged lines hidden --- |