Browse Source

qcacmn: Remove cds from napi hot_plug_notifier functionality

Instead of using cds to get the hif context in the notifier callback
rely on the context_of semantics to traverse back to the hif context.

Change-Id: I7d57f9dcf8c09836c34ce16a4acaa8c3bc1624b9
CRs-Fixed: 1092842
Houston Hoffman 8 years ago
parent
commit
fec8ed1234
3 changed files with 38 additions and 35 deletions
  1. 1 1
      hif/inc/hif.h
  2. 9 7
      hif/inc/hif_napi.h
  3. 28 27
      hif/src/hif_napi.c

+ 1 - 1
hif/inc/hif.h

@@ -241,7 +241,6 @@ struct qca_napi_cpu {
  *
  * A variable of this type will be stored in hif module context.
  */
-
 struct qca_napi_data {
 	spinlock_t           lock;
 	uint32_t             state;
@@ -253,6 +252,7 @@ struct qca_napi_data {
 	struct qca_napi_cpu  napi_cpu[NR_CPUS];
 	int                  lilcl_head, bigcl_head;
 	enum qca_napi_tput_state napi_mode;
+	struct notifier_block hnc_cpu_notifier;
 };
 
 /**

+ 9 - 7
hif/inc/hif_napi.h

@@ -157,19 +157,21 @@ int hif_napi_poll(struct hif_opaque_softc *hif_ctx,
  */
 /* fw-declare to make compiler happy */
 struct qca_napi_data;
-static inline int hif_napi_cpu_init(void *ctx) { return 0; }
-static inline int hif_napi_cpu_deinit(void *ctx) { return 0; }
+static inline int hif_napi_cpu_init(struct hif_opaque_softc *hif)
+{ return 0; }
+
+static inline int hif_napi_cpu_deinit(struct hif_opaque_softc *hif)
+{ return 0; }
+
 static inline int hif_napi_serialize(struct hif_opaque_softc *hif, int is_on)
-{
-	return -EPERM;
-}
+{ return -EPERM; }
 #else /* HELIUMPLUS - NAPI CPU symbols are valid */
 
 /*
  * prototype signatures
  */
-int hif_napi_cpu_init(void *);
-int hif_napi_cpu_deinit(void *);
+int hif_napi_cpu_init(struct hif_opaque_softc *hif);
+int hif_napi_cpu_deinit(struct hif_opaque_softc *hif);
 
 int hif_napi_cpu_migrate(struct qca_napi_data *napid, int cpu, int action);
 int hif_napi_cpu_blacklist(bool is_on);

+ 28 - 27
hif/src/hif_napi.c

@@ -46,7 +46,6 @@
 #include <linux/pm.h>
 
 /* Driver headers */
-#include <cds_api.h>
 #include <hif_napi.h>
 #include <hif_debug.h>
 #include <hif_io32.h>
@@ -125,7 +124,7 @@ int hif_napi_create(struct hif_opaque_softc   *hif_ctx,
 
 		napid->state |= HIF_NAPI_INITED;
 
-		rc = hif_napi_cpu_init(napid);
+		rc = hif_napi_cpu_init(hif_ctx);
 		if (rc != 0) {
 			HIF_ERROR("NAPI_initialization failed,. %d", rc);
 			goto hnc_err;
@@ -261,7 +260,7 @@ int hif_napi_destroy(struct hif_opaque_softc *hif_ctx,
 			 * set the whole structure to uninitialized state
 			 */
 			if (napid->ce_map == 0) {
-				rc = hif_napi_cpu_deinit(napid);
+				rc = hif_napi_cpu_deinit(hif_ctx);
 				/* caller is tolerant to receiving !=0 rc */
 
 				memset(napid,
@@ -966,14 +965,9 @@ static int hnc_cpu_notify_cb(struct notifier_block *nb,
 
 	NAPI_DEBUG("-->%s(act=%ld, cpu=%ld)", __func__, action, cpu);
 
-	hif = (struct hif_opaque_softc *)cds_get_context(QDF_MODULE_ID_HIF);
-	if (qdf_likely(hif != NULL))
-		napid = hif_napi_get_all(hif);
-	if (qdf_unlikely(napid == NULL)) {
-		NAPI_DEBUG("%s: hif/napid NULL (%p/%p)",
-			   __func__, hif, napid);
-		goto lab_hnc_notify;
-	}
+	napid = qdf_container_of(nb, struct qca_napi_data, hnc_cpu_notifier);
+	hif = &qdf_container_of(napid, struct hif_softc, napi_data)->osc;
+
 	switch (action) {
 	case CPU_ONLINE:
 		napid->napi_cpu[cpu].state = QCA_NAPI_CPU_UP;
@@ -1007,14 +1001,19 @@ static int hnc_cpu_notify_cb(struct notifier_block *nb,
 		NAPI_DEBUG("%s: ignored. action: %ld", __func__, action);
 		break;
 	} /* switch */
-lab_hnc_notify:
 	NAPI_DEBUG("<--%s [%d]", __func__, rc);
 	return rc;
 }
 
 /**
  * hnc_hotplug_hook() - installs a hotplug notifier
+ * @hif_sc: hif_sc context
  * @register: !0 => register , =0 => deregister
+ *
+ * Because the callback relies on the data layout of
+ * struct hif_softc & its napi_data member, this callback
+ * registration requires that the hif_softc is passed in.
+ *
  * Note that this is different from the cpu notifier used by
  * rx_thread (cds_schedule.c).
  * We may consider combining these modifiers in the future.
@@ -1022,19 +1021,21 @@ lab_hnc_notify:
  * Return: 0: success
  *        <0: error
  */
-static struct notifier_block hnc_cpu_notifier = {
-	.notifier_call = hnc_cpu_notify_cb,
-};
-static int hnc_hotplug_hook(int install)
+static int hnc_hotplug_hook(struct hif_softc *hif_sc, int install)
 {
 	int rc = 0;
 
 	NAPI_DEBUG("-->%s(%d)", __func__, install);
 
-	if (install)
-		rc = register_hotcpu_notifier(&hnc_cpu_notifier);
-	else
-		unregister_hotcpu_notifier(&hnc_cpu_notifier);
+	if (install) {
+		hif_sc->napi_data.hnc_cpu_notifier.notifier_call
+			= hnc_cpu_notify_cb;
+		rc = register_hotcpu_notifier(
+			&hif_sc->napi_data.hnc_cpu_notifier);
+	} else {
+		unregister_hotcpu_notifier(
+			&hif_sc->napi_data.hnc_cpu_notifier);
+	}
 
 	NAPI_DEBUG("<--%s()[%d]", __func__, rc);
 	return rc;
@@ -1081,11 +1082,11 @@ static int hnc_tput_hook(int install)
  * Return: 0: OK
  *         <0: error code
  */
-int hif_napi_cpu_init(void *ctx)
+int hif_napi_cpu_init(struct hif_opaque_softc *hif)
 {
 	int rc = 0;
 	int i;
-	struct qca_napi_data *napid = (struct qca_napi_data *)ctx;
+	struct qca_napi_data *napid = &HIF_GET_SOFTC(hif)->napi_data;
 	struct qca_napi_cpu *cpus = napid->napi_cpu;
 
 	NAPI_DEBUG("--> ");
@@ -1118,7 +1119,7 @@ int hif_napi_cpu_init(void *ctx)
 		goto lab_err_topology;
 
 	/* install hotplug notifier */
-	rc = hnc_hotplug_hook(1);
+	rc = hnc_hotplug_hook(HIF_GET_SOFTC(hif), 1);
 	if (0 != rc)
 		goto lab_err_hotplug;
 
@@ -1129,7 +1130,7 @@ int hif_napi_cpu_init(void *ctx)
 
 lab_err_hotplug:
 	hnc_tput_hook(0);
-	hnc_hotplug_hook(0);
+	hnc_hotplug_hook(HIF_GET_SOFTC(hif), 0);
 lab_err_topology:
 	memset(napid->napi_cpu, 0, sizeof(struct qca_napi_cpu) * NR_CPUS);
 lab_rss_init:
@@ -1145,10 +1146,10 @@ lab_rss_init:
  * - clears cpu topology table
  * Return: 0: OK
  */
-int hif_napi_cpu_deinit(void *ctx)
+int hif_napi_cpu_deinit(struct hif_opaque_softc *hif)
 {
 	int rc = 0;
-	struct qca_napi_data *napid = (struct qca_napi_data *)ctx;
+	struct qca_napi_data *napid = &HIF_GET_SOFTC(hif)->napi_data;
 
 	NAPI_DEBUG("-->%s(...)", __func__);
 
@@ -1156,7 +1157,7 @@ int hif_napi_cpu_deinit(void *ctx)
 	rc = hnc_tput_hook(0);
 
 	/* uninstall hotplug notifier */
-	rc = hnc_hotplug_hook(0);
+	rc = hnc_hotplug_hook(HIF_GET_SOFTC(hif), 0);
 
 	/* clear the topology table */
 	memset(napid->napi_cpu, 0, sizeof(struct qca_napi_cpu) * NR_CPUS);