socsvn commit: r303801 - soc2016/vincenzo/head/sys/dev/netmap

vincenzo at FreeBSD.org vincenzo at FreeBSD.org
Tue May 24 17:04:03 UTC 2016


Author: vincenzo
Date: Tue May 24 17:04:01 2016
New Revision: 303801
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=303801

Log:
  ptnet: add core lock

Modified:
  soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c

Modified: soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c
==============================================================================
--- soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c	Tue May 24 17:02:42 2016	(r303800)
+++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c	Tue May 24 17:04:01 2016	(r303801)
@@ -93,6 +93,18 @@
 	char			hwaddr[ETHER_ADDR_LEN];
 };
 
+#define PTNET_CORE_LOCK_INIT(_sc)	do {			\
+		snprintf((_sc)->core_mtx_name, sizeof((_sc)->core_mtx_name),	\
+			 "%s", device_get_nameunit(sc->dev));			\
+		mtx_init(&(_sc)->core_mtx, (_sc)->core_mtx_name,		\
+			 "ptnet core lock", MTX_DEF);				\
+	} while (0)
+
+#define PTNET_CORE_LOCK_FINI(_sc)	mtx_destroy(&(_sc)->core_mtx)
+
+#define PTNET_CORE_LOCK(_sc)	mtx_lock(&(_sc)->core_mtx)
+#define PTNET_CORE_UNLOCK(_sc)	mtx_unlock(&(_sc)->core_mtx)
+
 static int	ptnet_probe(device_t);
 static int	ptnet_attach(device_t);
 static int	ptnet_detach(device_t);
@@ -152,6 +164,9 @@
 
 	sc = device_get_softc(dev);
 	sc->dev = dev;
+
+	PTNET_CORE_LOCK_INIT(sc);
+
 	sc->ifp = ifp = if_alloc(IFT_ETHER);
 	if (ifp == NULL) {
 		device_printf(dev, "Failed to allocate ifnet\n");
@@ -188,8 +203,12 @@
 static int
 ptnet_detach(device_t dev)
 {
+	struct ptnet_softc *sc = device_get_softc(dev);
+
 	printf("%s\n", __func__);
 
+	PTNET_CORE_LOCK_FINI(sc);
+
 	return (0);
 }
 
@@ -257,12 +276,10 @@
 	ifmr->ifm_status = IFM_AVALID;
 	ifmr->ifm_active = IFM_ETHER;
 
-	//lock
 	if (1) {
 		ifmr->ifm_status |= IFM_ACTIVE;
 		ifmr->ifm_active |= IFM_10G_T | IFM_FDX;
 	} else {
 		ifmr->ifm_active |= IFM_NONE;
 	}
-	//unlock
 }


More information about the svn-soc-all mailing list