Browse Source

qcacld-3.0: Use request manager for DISA encrypt/decrypt

We are transitioning to the new request manager framework. Change
hdd_encrypt_decrypt_msg() and hdd_encrypt_decrypt_msg_cb() to this
framework.

Note that this framework provides the infrastructure to pass data from
the response thread to the request thread and hence eliminates the
need to maintain a separate encrypt_decrypt_msg_context.

Change-Id: Ic0a0357566a2a8b39d73cb82371219315034019e
CRs-Fixed: 2005316
Jeff Johnson 8 years ago
parent
commit
b915baefbd
3 changed files with 79 additions and 136 deletions
  1. 78 104
      core/hdd/src/wlan_hdd_disa.c
  2. 1 30
      core/hdd/src/wlan_hdd_disa.h
  3. 0 2
      core/hdd/src/wlan_hdd_main.c

+ 78 - 104
core/hdd/src/wlan_hdd_disa.c

@@ -24,50 +24,51 @@
  */
 
 #include "wlan_hdd_disa.h"
+#include "wlan_hdd_request_manager.h"
 #include "sme_api.h"
 
-#define ENCRYPT_DECRYPT_CONTEXT_MAGIC 0x4475354
 #define WLAN_WAIT_TIME_ENCRYPT_DECRYPT 1000
 
 
 /**
  * hdd_encrypt_decrypt_msg_context - hdd encrypt/decrypt message context
- *
- * @magic: magic number
- * @completion: Completion variable for encrypt/decrypt message
- * @response_event: encrypt/decrypt message request wait event
+ * @status: status of response. 0: no error, -ENOMEM: unable to allocate
+ *   memory for the response payload
+ * @request: encrypt/decrypt request
+ * @response: encrypt/decrypt response
  */
 struct hdd_encrypt_decrypt_msg_context {
-	unsigned int magic;
-	struct completion completion;
+	int status;
+	struct encrypt_decrypt_req_params request;
 	struct sir_encrypt_decrypt_rsp_params response;
 };
-static struct hdd_encrypt_decrypt_msg_context encrypt_decrypt_msg_context;
 
 /**
- * hdd_encrypt_decrypt_msg_cb () - sends encrypt/decrypt data to user space
+ * hdd_encrypt_decrypt_msg_cb () - encrypt/decrypt response message handler
+ * @cookie: hdd request cookie
  * @encrypt_decrypt_rsp_params: encrypt/decrypt response parameters
  *
  * Return: none
  */
-static void hdd_encrypt_decrypt_msg_cb(void *hdd_context,
+static void hdd_encrypt_decrypt_msg_cb(void *cookie,
 	struct sir_encrypt_decrypt_rsp_params *encrypt_decrypt_rsp_params)
 {
-	hdd_context_t *hdd_ctx = hdd_context;
-	int ret;
+	struct hdd_request *request;
 	struct hdd_encrypt_decrypt_msg_context *context;
 
 	ENTER();
 
-	ret = wlan_hdd_validate_context(hdd_ctx);
-	if (ret)
-		return;
-
 	if (!encrypt_decrypt_rsp_params) {
 		hdd_err("rsp params is NULL");
 		return;
 	}
 
+	request = hdd_request_get(cookie);
+	if (!request) {
+		hdd_err("Obsolete request");
+		return;
+	}
+
 	print_hex_dump(KERN_INFO, "Data in hdd_encrypt_decrypt_msg_cb: ",
 		DUMP_PREFIX_NONE, 16, 1,
 		encrypt_decrypt_rsp_params->data,
@@ -78,49 +79,34 @@ static void hdd_encrypt_decrypt_msg_cb(void *hdd_context,
 		encrypt_decrypt_rsp_params->status,
 		encrypt_decrypt_rsp_params->data_length);
 
-	spin_lock(&hdd_context_lock);
-
-	context = &encrypt_decrypt_msg_context;
-	/* The caller presumably timed out so there is nothing we can do */
-	if (context->magic != ENCRYPT_DECRYPT_CONTEXT_MAGIC) {
-		spin_unlock(&hdd_context_lock);
-		return;
-	}
-
-	/* context is valid so caller is still waiting */
+	context = hdd_request_priv(request);
 	context->response = *encrypt_decrypt_rsp_params;
-
+	context->status = 0;
 	if (encrypt_decrypt_rsp_params->data_length) {
 		context->response.data =
 			qdf_mem_malloc(sizeof(uint8_t) *
 				encrypt_decrypt_rsp_params->data_length);
-		if (context->response.data == NULL) {
-			hdd_err("cdf_mem_alloc failed for data");
-			spin_unlock(&hdd_context_lock);
-			return;
+		if (!context->response.data) {
+			hdd_err("memory allocation failed");
+			context->status = -ENOMEM;
+		} else {
+			qdf_mem_copy(context->response.data,
+				     encrypt_decrypt_rsp_params->data,
+				     encrypt_decrypt_rsp_params->data_length);
 		}
-		qdf_mem_copy(context->response.data,
-			encrypt_decrypt_rsp_params->data,
-			encrypt_decrypt_rsp_params->data_length);
+	} else {
+		/* make sure we don't have a rogue pointer */
+		context->response.data = NULL;
 	}
 
-	/*
-	 * Indicate to calling thread that
-	 * response data is available
-	 */
-	context->magic = 0;
-
-	complete(&context->completion);
-
-	spin_unlock(&hdd_context_lock);
-
-
+	hdd_request_complete(request);
+	hdd_request_put(request);
 	EXIT();
 }
 
 
 /**
- * hdd_encrypt_decrypt_msg_cb () - sends encrypt/decrypt data to user space
+ * hdd_post_encrypt_decrypt_msg_rsp () - send encrypt/decrypt data to user space
  * @encrypt_decrypt_rsp_params: encrypt/decrypt response parameters
  *
  * Return: none
@@ -317,7 +303,7 @@ static int hdd_fill_encrypt_decrypt_params(struct encrypt_decrypt_req_params
 				encrypt_decrypt_params->data_len);
 
 		if (encrypt_decrypt_params->data == NULL) {
-			hdd_err("cdf_mem_alloc failed for data");
+			hdd_err("memory allocation failed");
 			return -ENOMEM;
 		}
 
@@ -334,6 +320,14 @@ static int hdd_fill_encrypt_decrypt_params(struct encrypt_decrypt_req_params
 	return 0;
 }
 
+static void hdd_encrypt_decrypt_context_dealloc(void *priv)
+{
+	struct hdd_encrypt_decrypt_msg_context *context = priv;
+
+	qdf_mem_free(context->request.data);
+	qdf_mem_free(context->response.data);
+}
+
 /**
  * hdd_encrypt_decrypt_msg () - process encrypt/decrypt message
  * @adapter : adapter context
@@ -344,89 +338,69 @@ static int hdd_fill_encrypt_decrypt_params(struct encrypt_decrypt_req_params
  Return: 0 on success, negative errno on failure
  */
 static int hdd_encrypt_decrypt_msg(hdd_adapter_t *adapter,
-						hdd_context_t *hdd_ctx,
-						const void *data,
-						int data_len)
+				   hdd_context_t *hdd_ctx,
+				   const void *data,
+				   int data_len)
 {
-	struct encrypt_decrypt_req_params encrypt_decrypt_params = {0};
 	QDF_STATUS qdf_status;
 	int ret;
+	void *cookie;
+	struct hdd_request *request;
 	struct hdd_encrypt_decrypt_msg_context *context;
-	unsigned long rc;
+	static const struct hdd_request_params params = {
+		.priv_size = sizeof(*context),
+		.timeout_ms = WLAN_WAIT_TIME_ENCRYPT_DECRYPT,
+		.dealloc = hdd_encrypt_decrypt_context_dealloc,
+	};
+
+	request = hdd_request_alloc(&params);
+	if (!request) {
+		hdd_err("Request allocation failure");
+		return -ENOMEM;
+	}
+	context = hdd_request_priv(request);
 
-	ret = hdd_fill_encrypt_decrypt_params(&encrypt_decrypt_params,
-				adapter, data, data_len);
+	ret = hdd_fill_encrypt_decrypt_params(&context->request, adapter,
+					      data, data_len);
 	if (ret)
-		return ret;
-
-	spin_lock(&hdd_context_lock);
-	context = &encrypt_decrypt_msg_context;
-	context->magic = ENCRYPT_DECRYPT_CONTEXT_MAGIC;
-	INIT_COMPLETION(context->completion);
-	spin_unlock(&hdd_context_lock);
+		goto cleanup;
 
+	cookie = hdd_request_cookie(request);
 	qdf_status = sme_encrypt_decrypt_msg(hdd_ctx->hHal,
-					     &encrypt_decrypt_params,
+					     &context->request,
 					     hdd_encrypt_decrypt_msg_cb,
-					     hdd_ctx);
+					     cookie);
 
-	qdf_mem_free(encrypt_decrypt_params.data);
 
 	if (!QDF_IS_STATUS_SUCCESS(qdf_status)) {
 		hdd_err("Unable to post encrypt/decrypt message");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto cleanup;
 	}
 
-	rc = wait_for_completion_timeout(&context->completion,
-			msecs_to_jiffies(WLAN_WAIT_TIME_ENCRYPT_DECRYPT));
-
-	spin_lock(&hdd_context_lock);
-	if (!rc && (context->magic ==
-			ENCRYPT_DECRYPT_CONTEXT_MAGIC)) {
+	ret = hdd_request_wait_for_response(request);
+	if (ret) {
 		hdd_err("Target response timed out");
-		context->magic = 0;
-		spin_unlock(&hdd_context_lock);
-		return -ETIMEDOUT;
+		goto cleanup;
+	}
+
+	ret = context->status;
+	if (ret) {
+		hdd_err("Target response processing failed");
+		goto cleanup;
 	}
 
-	spin_unlock(&hdd_context_lock);
-	ret = hdd_post_encrypt_decrypt_msg_rsp(hdd_ctx,
-				&encrypt_decrypt_msg_context.response);
+	ret = hdd_post_encrypt_decrypt_msg_rsp(hdd_ctx, &context->response);
 	if (ret)
 		hdd_err("Failed to post encrypt/decrypt message response");
 
-	qdf_mem_free(encrypt_decrypt_msg_context.response.data);
+cleanup:
+	hdd_request_put(request);
 
 	EXIT();
 	return ret;
 }
 
-/**
- * hdd_encrypt_decrypt_init () - exposes encrypt/decrypt initialization
- * functionality
- * @hdd_ctx: hdd context
- *
- Return: 0 on success, negative errno on failure
- */
-int hdd_encrypt_decrypt_init(hdd_context_t *hdd_ctx)
-{
-	init_completion(&encrypt_decrypt_msg_context.completion);
-
-	return 0;
-}
-
-/**
- * hdd_encrypt_decrypt_deinit () - exposes encrypt/decrypt deinitialization
- * functionality
- * @hdd_ctx: hdd context
- *
- Return: 0 on success, negative errno on failure
- */
-int hdd_encrypt_decrypt_deinit(hdd_context_t *hdd_ctx)
-{
-	return 0;
-}
-
 /**
  * __wlan_hdd_cfg80211_encrypt_decrypt_msg () - Encrypt/Decrypt msg
  * @wiphy: Pointer to wireless phy

+ 1 - 30
core/hdd/src/wlan_hdd_disa.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2017 The Linux Foundation. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -22,35 +22,6 @@
 #include "wlan_hdd_main.h"
 #include "sir_api.h"
 
-#ifdef WLAN_FEATURE_DISA
-/**
- * hdd_encrypt_decrypt_init () - exposes encrypt/decrypt initialization
- * functionality
- * @hdd_ctx: hdd context
- *
- Return: 0 on success, negative errno on failure
- */
-int hdd_encrypt_decrypt_init(hdd_context_t *hdd_ctx);
-
-/**
- * hdd_encrypt_decrypt_deinit () - exposes encrypt/decrypt deinitialization
- * functionality
- * @hdd_ctx: hdd context
- *
- Return: 0 on success, negative errno on failure
- */
-int hdd_encrypt_decrypt_deinit(hdd_context_t *hdd_ctx);
-#else
-static inline int hdd_encrypt_decrypt_init(hdd_context_t *hdd_ctx)
-{
-	return -ENOTSUPP;
-}
-static inline int hdd_encrypt_decrypt_deinit(hdd_context_t *hdd_ctx)
-{
-	return -ENOTSUPP;
-}
-#endif
-
 #ifdef WLAN_FEATURE_DISA
 /**
  * wlan_hdd_cfg80211_encrypt_decrypt_msg () - Encrypt/Decrypt msg

+ 0 - 2
core/hdd/src/wlan_hdd_main.c

@@ -7994,7 +7994,6 @@ static int hdd_features_init(hdd_context_t *hdd_ctx, hdd_adapter_t *adapter)
 		hdd_err("Error setting txlimit in sme: %d", status);
 
 	hdd_tsf_init(hdd_ctx);
-	hdd_encrypt_decrypt_init(hdd_ctx);
 
 	ret = hdd_register_cb(hdd_ctx);
 	if (ret) {
@@ -8112,7 +8111,6 @@ static int hdd_deconfigure_cds(hdd_context_t *hdd_ctx)
 	ENTER();
 	/* De-register the SME callbacks */
 	hdd_deregister_cb(hdd_ctx);
-	hdd_encrypt_decrypt_deinit(hdd_ctx);
 
 	/* De-init Policy Manager */
 	if (!QDF_IS_STATUS_SUCCESS(cds_deinit_policy_mgr())) {