All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonas Bonn <jonas@southpole.se>
To: ofono@ofono.org
Subject: [RFC PATCH 03/30] qmi: unify common request header setup
Date: Wed, 28 Mar 2018 20:59:49 +0200	[thread overview]
Message-ID: <20180328190016.28509-4-jonas@southpole.se> (raw)
In-Reply-To: <20180328190016.28509-1-jonas@southpole.se>

[-- Attachment #1: Type: text/plain, Size: 5047 bytes --]

The service and control requests differ slightly in their headers, but
this difference is minor enough that we can handle it in a common
request allocation routine.  This patch unifies the header setup for the
two request types.
---
 drivers/qmimodem/qmi.c | 62 ++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 35 deletions(-)

diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c
index 4a3929ba..0c95dd18 100644
--- a/drivers/qmimodem/qmi.c
+++ b/drivers/qmimodem/qmi.c
@@ -159,7 +159,8 @@ void qmi_free(void *ptr)
 	free(ptr);
 }
 
-static struct qmi_request *__request_alloc(uint8_t service,
+static struct qmi_request *__request_alloc(struct qmi_device* device,
+				uint8_t service,
 				uint8_t client, uint16_t message,
 				const void *data,
 				uint16_t length, qmi_message_func_t func,
@@ -211,6 +212,23 @@ static struct qmi_request *__request_alloc(uint8_t service,
 
 	*head = req->buf + QMI_MUX_HDR_SIZE;
 
+	if (service == QMI_SERVICE_CONTROL) {
+		struct qmi_control_hdr* hdr;
+
+		hdr = req->buf + QMI_MUX_HDR_SIZE;
+		hdr->type = 0x00;
+		hdr->transaction = device->next_control_tid++;
+		if (device->next_control_tid == 0)
+			device->next_control_tid = 1;
+	} else {
+		struct qmi_service_hdr* hdr;
+		hdr = req->buf + QMI_MUX_HDR_SIZE;
+		hdr->type = 0x00;
+		hdr->transaction = device->next_service_tid++;
+		if (device->next_service_tid < 256)
+			device->next_service_tid = 256;
+	}
+
 	return req;
 }
 
@@ -967,6 +985,9 @@ struct qmi_device *qmi_device_new(int fd)
 	device->service_list = g_hash_table_new_full(g_direct_hash,
 					g_direct_equal, NULL, service_destroy);
 
+	device->next_control_tid = 1;
+	device->next_service_tid = 256;
+
 	return device;
 }
 
@@ -1256,7 +1277,7 @@ bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
 		return true;
 	}
 
-	req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
+	req = __request_alloc(device, QMI_SERVICE_CONTROL, 0x00,
 			QMI_CTL_GET_VERSION_INFO,
 			NULL, 0, discover_callback, data, (void **) &hdr);
 	if (!req) {
@@ -1264,11 +1285,6 @@ bool qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func,
 		return false;
 	}
 
-	if (device->next_control_tid < 1)
-		device->next_control_tid = 1;
-
-	hdr->type = 0x00;
-	hdr->transaction = device->next_control_tid++;
 	data->tid = hdr->transaction;
 
 	__request_submit(device, req, hdr->transaction);
@@ -1287,7 +1303,7 @@ static void release_client(struct qmi_device *device,
 	struct qmi_request *req;
 	struct qmi_control_hdr *hdr;
 
-	req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
+	req = __request_alloc(device, QMI_SERVICE_CONTROL, 0x00,
 			QMI_CTL_RELEASE_CLIENT_ID,
 			release_req, sizeof(release_req),
 			func, user_data, (void **) &hdr);
@@ -1296,12 +1312,6 @@ static void release_client(struct qmi_device *device,
 		return;
 	}
 
-	if (device->next_control_tid < 1)
-		device->next_control_tid = 1;
-
-	hdr->type = 0x00;
-	hdr->transaction = device->next_control_tid++;
-
 	__request_submit(device, req, hdr->transaction);
 }
 
@@ -1392,17 +1402,11 @@ bool qmi_device_sync(struct qmi_device *device,
 	func_data->func = func;
 	func_data->user_data = user_data;
 
-	req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
+	req = __request_alloc(device, QMI_SERVICE_CONTROL, 0x00,
 			QMI_CTL_SYNC,
 			NULL, 0,
 			qmi_device_sync_callback, func_data, (void **) &hdr);
 
-	if (device->next_control_tid < 1)
-		device->next_control_tid = 1;
-
-	hdr->type = 0x00;
-	hdr->transaction = device->next_control_tid++;
-
 	__request_submit(device, req, hdr->transaction);
 
 	return true;
@@ -2018,7 +2022,7 @@ static void service_create_discover(uint8_t count,
 		}
 	}
 
-	req = __request_alloc(QMI_SERVICE_CONTROL, 0x00,
+	req = __request_alloc(device, QMI_SERVICE_CONTROL, 0x00,
 			QMI_CTL_GET_CLIENT_ID,
 			client_req, sizeof(client_req),
 			service_create_callback, data, (void **) &hdr);
@@ -2032,12 +2036,6 @@ static void service_create_discover(uint8_t count,
 		return;
 	}
 
-	if (device->next_control_tid < 1)
-		device->next_control_tid = 1;
-
-	hdr->type = 0x00;
-	hdr->transaction = device->next_control_tid++;
-
 	__request_submit(device, req, hdr->transaction);
 }
 
@@ -2314,7 +2312,7 @@ uint16_t qmi_service_send(struct qmi_service *service,
 	data->user_data = user_data;
 	data->destroy = destroy;
 
-	req = __request_alloc(service->type, service->client_id,
+	req = __request_alloc(device, service->type, service->client_id,
 				message,
 				param ? param->data : NULL,
 				param ? param->length : 0,
@@ -2327,12 +2325,6 @@ uint16_t qmi_service_send(struct qmi_service *service,
 		return 0;
 	}
 
-	if (device->next_service_tid < 256)
-		device->next_service_tid = 256;
-
-	hdr->type = 0x00;
-	hdr->transaction = device->next_service_tid++;
-
 	__request_submit(device, req, hdr->transaction);
 
 	return hdr->transaction;
-- 
2.15.1


  parent reply	other threads:[~2018-03-28 18:59 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 18:59 [RFC PATCH 00/30] QMI rework Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 01/30] qmi: remove unused fields of service_send_data Jonas Bonn
2018-03-28 19:53   ` Denis Kenzior
2018-03-28 21:09     ` Jonas Bonn
2018-03-28 21:18       ` Denis Kenzior
2018-03-29 10:46     ` Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 02/30] qmi: remove headroom parameter from req_alloc Jonas Bonn
2018-03-28 18:59 ` Jonas Bonn [this message]
2018-03-28 18:59 ` [RFC PATCH 04/30] qmi: request_alloc has no meaningful failure path Jonas Bonn
2018-03-28 19:59   ` Denis Kenzior
2018-03-28 20:51     ` Jonas Bonn
2018-03-28 21:12       ` Denis Kenzior
2018-03-28 18:59 ` [RFC PATCH 05/30] qmi: push request_submit into request_alloc Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 06/30] qmi: rename request_alloc to request_submit Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 07/30] qmi: figure out request id without accessing header Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 08/30] qmi: make qmi_service_send return result Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 09/30] qmi: drop 'head' pointer from request_submit Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 10/30] qmi: remove unused qmi_service_cancel Jonas Bonn
2018-03-28 21:07   ` Denis Kenzior
2018-03-28 18:59 ` [RFC PATCH 11/30] qmi: remove unused qmi_service_unregister Jonas Bonn
2018-03-28 18:59 ` [RFC PATCH 12/30] qmi: replace GQueues for requests Jonas Bonn
2018-03-28 20:16   ` Denis Kenzior
2018-03-28 21:06     ` Jonas Bonn
2018-03-28 21:24       ` Denis Kenzior
2018-03-28 18:59 ` [RFC PATCH 13/30] qmi: assume version_list is up to date Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 14/30] qmi: absorb service_create_discover into service_create Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 15/30] qmi: drop discovery_queue Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 16/30] qmi: make services always shared Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 17/30] qmi: switch service_list to list_head type Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 18/30] qmi: switch notify_list " Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 19/30] qmi: drop unused struct field Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 20/30] qmi: reference version_info from device in services Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 21/30] qmi: make version_list private Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 22/30] qmi: move client_id to qmi_version Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 23/30] qmi: use standard endian macros Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 24/30] qmi: convert version_list to struct list head Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 25/30] qmi: move service device to service_info Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 26/30] qmi: make all services unique instances backed by common description Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 27/30] qmi: drop qmi_service_ref function Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 28/30] qmi: rename qmi_service_create/unref to open/close Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 29/30] qmi: pass service directly to request_submit Jonas Bonn
2018-03-28 19:00 ` [RFC PATCH 30/30] qmi: add requests to service queue Jonas Bonn
2018-03-28 21:51 ` [RFC PATCH 00/30] QMI rework Denis Kenzior
2018-03-29 10:31   ` Jonas Bonn
2018-03-29 15:55     ` Denis Kenzior
2018-03-29 16:43       ` Jonas Bonn
2018-03-29 18:08         ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180328190016.28509-4-jonas@southpole.se \
    --to=jonas@southpole.se \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.