From patchwork Mon Feb 26 15:34:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572391 Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EA5612AAE1 for ; Mon, 26 Feb 2024 15:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961704; cv=none; b=f50oM7Ob2xdlBFjbWqNCfjT7gGLzemKpZB7y4OuUz+VeKsn50WaMWftE1nScgD4pcPRqmCmEdqgsv2HiqXJeb/Seoii+3ySIhi0D7yy7UG363X8/2MndIcunHxnYX7uaL4dSOqxDktG9u53Yt5owuY0jZfaDUCDd7NsjDWU7XVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961704; c=relaxed/simple; bh=GlFvrwjbb6i5fHVEEfO5aiU7+RN7gClME9TcKMwfAqM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AbAFTxgdDSv21e1jeTsU8vQ6AY/n4De7Apc4QSU+g8W+rgfsZ4Lw4KKQMOp1OG0InsxsAfN1zw/NpmahoSfp+tEk3MF3gXZ9N4UydBoaxmQr/19YE95HQnFVwlKRpsnVBR/mE8mDBemEeCfBp1FRpQJKb7f3mHM93ptAVV8CrgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hFukQO+r; arc=none smtp.client-ip=209.85.210.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hFukQO+r" Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6e4a803c72aso182151a34.3 for ; Mon, 26 Feb 2024 07:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961702; x=1709566502; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gaC3OFlbo8ouJ+UUjpgzjnVJ3/t7dzxE6gPU2Hm7x1M=; b=hFukQO+rgmK6l1qaPPYe+O+XQXJg/dCbJsyb2oqpEhyGk+/hOpJA9AVJHpLJO8VI1C X/e0aGvO++SU4hWO/39MGkxjhPrvB7OLoQmM6Njc8Kz3CWbNm+7UhYN2ansOmFVWl8Sc 3bbOTAmvn6UNI8PbXjVP7Y6EyXY/nkw9Ahd9q3gY8lIL6TMgeYnj37xm0SdwbMJaaTz3 G5ZXcuqVEX8uZgMudgztnZBUStiJ1ij6sVcmeaN6XvkYO4azw3N65ytBL7PmgNosTt5F YIbdj71Fle8HSe2VujOm7DRBw9yqgPeytrh3chpIxi/yRWVpQfE8NnXDqilA9rZ6NWvv IH+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961702; x=1709566502; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gaC3OFlbo8ouJ+UUjpgzjnVJ3/t7dzxE6gPU2Hm7x1M=; b=Igim6WEg73UcYnzP7k3DAzT0U/SdL//AeFYPFVX28JYPRmtFwn1kn7ALmvQ7MHQ3SV 4gd2Uv/quzdKQQyAhPn3N3PH1D3Bx/bQq9p68QBzno2X9iSEcKPXmt5wlMl7XiDqrQ3P N+31zjhOqraqkspY8HN1ILX55qjmozl8mG49Njw4uHNVrYNQOUPOmUoUrxpmQdC/zFyx X2EqNsBZNybldmeRnXoq5IgpBXWkYadk4kQ4e00HnK7+QIeDqG86DxjEPDdBle8oMsbZ YS55i4MmkRucHhg2/6vBzwONPjiFnwXORo4sAXQZWGye4/D7QZzJKFyl6YI6VZMxhROE sK3g== X-Gm-Message-State: AOJu0YxEw4S7LQKr2veUAGGwoSEvQxQo29qN8oP/jxNiCK5E2zCFx+lQ r092o0aFWK1B/uTw5WRr2dl2IO/rZFa1E/eDxmmw7AQnBPgN5rnKUqHhjuXd X-Google-Smtp-Source: AGHT+IGHgQYsqb/OPpUIWTBw/e/3atb0440xVLlaWRR/LGlyaleCFFeCOKaS501jE/S+RPODncL88w== X-Received: by 2002:a05:6870:514f:b0:21f:828:7a7c with SMTP id z15-20020a056870514f00b0021f08287a7cmr9920314oak.6.1708961702056; Mon, 26 Feb 2024 07:35:02 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:01 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/8] qmi: Use FAM instead of allocating a member Date: Mon, 26 Feb 2024 09:34:20 -0600 Message-ID: <20240226153459.1463304-1-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Instead of allocating a separate buffer inside the request object, use a flexible array member (FAM). This allows the request metadata and data to be allocated within the same memory region. The only downside is that the data buffer is not released once the request has been sent over the socket. Since most requests are quite small, this shouldn't affect performance. --- drivers/qmimodem/qmi.c | 45 ++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 22702b41a77a..652f19fb6cd0 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -129,10 +129,10 @@ struct qmi_result { struct qmi_request { uint16_t tid; uint8_t client; - void *buf; - size_t len; qmi_message_func_t callback; void *user_data; + uint16_t len; + uint8_t data[]; }; struct qmi_notify { @@ -192,22 +192,20 @@ static struct qmi_request *__request_alloc(uint8_t service, struct qmi_request *req; struct qmi_mux_hdr *hdr; struct qmi_message_hdr *msg; - uint16_t headroom; - - req = l_new(struct qmi_request, 1); + uint16_t hdrlen = QMI_MUX_HDR_SIZE; + uint16_t msglen; if (service == QMI_SERVICE_CONTROL) - headroom = QMI_CONTROL_HDR_SIZE; + hdrlen += QMI_CONTROL_HDR_SIZE; else - headroom = QMI_SERVICE_HDR_SIZE; - - req->len = QMI_MUX_HDR_SIZE + headroom + QMI_MESSAGE_HDR_SIZE + length; - - req->buf = l_malloc(req->len); + hdrlen += QMI_SERVICE_HDR_SIZE; + msglen = hdrlen + QMI_MESSAGE_HDR_SIZE + length; + req = l_malloc(sizeof(struct qmi_request) + msglen); + req->len = msglen; req->client = client; - hdr = req->buf; + hdr = (struct qmi_mux_hdr *) req->data; hdr->frame = 0x01; hdr->length = L_CPU_TO_LE16(req->len - 1); @@ -215,14 +213,13 @@ static struct qmi_request *__request_alloc(uint8_t service, hdr->service = service; hdr->client = client; - msg = req->buf + QMI_MUX_HDR_SIZE + headroom; + msg = (struct qmi_message_hdr *) &req->data[hdrlen]; msg->message = L_CPU_TO_LE16(message); msg->length = L_CPU_TO_LE16(length); if (data && length > 0) - memcpy(req->buf + QMI_MUX_HDR_SIZE + headroom + - QMI_MESSAGE_HDR_SIZE, data, length); + memcpy(req->data + hdrlen + QMI_MESSAGE_HDR_SIZE, data, length); req->callback = func; req->user_data = user_data; @@ -234,7 +231,6 @@ static void __request_free(void *data) { struct qmi_request *req = data; - l_free(req->buf); l_free(req); } @@ -637,26 +633,23 @@ static bool can_write_data(struct l_io *io, void *user_data) if (!req) return false; - bytes_written = write(l_io_get_fd(device->io), req->buf, req->len); + bytes_written = write(l_io_get_fd(device->io), req->data, req->len); if (bytes_written < 0) return false; - l_util_hexdump(false, req->buf, bytes_written, + l_util_hexdump(false, req->data, bytes_written, device->debug_func, device->debug_data); - __debug_msg(' ', req->buf, bytes_written, + __debug_msg(' ', req->data, bytes_written, device->debug_func, device->debug_data); - hdr = req->buf; + hdr = (struct qmi_mux_hdr *) req->data; if (hdr->service == QMI_SERVICE_CONTROL) l_queue_push_tail(device->control_queue, req); else l_queue_push_tail(device->service_queue, req); - l_free(req->buf); - req->buf = NULL; - if (l_queue_length(device->req_queue) > 0) return true; @@ -686,12 +679,12 @@ static uint16_t __request_submit(struct qmi_device *device, { struct qmi_mux_hdr *mux; - mux = req->buf; + mux = (struct qmi_mux_hdr *) req->data; if (mux->service == QMI_SERVICE_CONTROL) { struct qmi_control_hdr *hdr; - hdr = req->buf + QMI_MUX_HDR_SIZE; + hdr = (struct qmi_control_hdr *) &req->data[QMI_MUX_HDR_SIZE]; hdr->type = 0x00; hdr->transaction = device->next_control_tid++; if (device->next_control_tid == 0) @@ -700,7 +693,7 @@ static uint16_t __request_submit(struct qmi_device *device, } else { struct qmi_service_hdr *hdr; - hdr = req->buf + QMI_MUX_HDR_SIZE; + hdr = (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE]; hdr->type = 0x00; hdr->transaction = device->next_service_tid++; if (device->next_service_tid < 256) From patchwork Mon Feb 26 15:34:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572392 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2214604CC for ; Mon, 26 Feb 2024 15:35:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961705; cv=none; b=IvM8RbhX0Eijgaz/78ZGvCXR3D7g/2f+DizQXdRWw7JfDNAHoXMxn8y36LWSc4/ykDAco6WH6uhzzzk3tDTA97Kb1cY63+6dovtO1wrR02ea19dRMM4IaHAYv0q8FFLMjFI1vHYb4qvaVQlYdhfvHMRpfycuxdMr0ZauwOA63Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961705; c=relaxed/simple; bh=D+Q5nJzhNKzTJ7AlNe4KyVckn7E3TAUMS9LtrxYEiiI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IIftGGlv2+JWuiVTsNDE0K8z+KIi65ngWUEpNQtvfcai3GHnwZMroEjz19JTsSQ3hmvMr+p55bw+kuRwmqWT447ZJQevMdrmyRPBVtL53Cl1k4i37zCg8KMYJh26D14LHIEy1ypiw9G2s2efLcLZjWtF3WP+8XqV6unR47sbcU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EFlZmTau; arc=none smtp.client-ip=209.85.160.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EFlZmTau" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-21e8a740439so1061241fac.1 for ; Mon, 26 Feb 2024 07:35:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961703; x=1709566503; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=S6aMKdSt4hlpMvvzbH/1eqnngZDBGFEB284Ogg6dR3I=; b=EFlZmTauvKP97sU64itkRDjdCFU8SK7zZxHnSMgYwZl6iC0cwNeDhW9mgw0Ot7uTKz wyJhcra3KluopGk9+Ei2aWcXhhKtxqyBndMCN6qbHTFsrxzSfOOf1ne7lk944mvBmfcv 6LWR3krwDiGhPvaptiKIJkzYddIG8TIjEFAVoDlyQ8gtghnskA7DRjuQD7Qpp7uKX9z5 4E5UTgaJlGQ9OQSqHNH7GkaMzfG34ExsFlq5TLUbUZsTIubNZkOEqsJXP08V47Wg1+UZ 07Y6nKqgOIntaPZixkwPoE4ah+Aid4mJ8gjM3Q7toqy8HVGFS3eEyKZ53fvg2zgMT6yv A2Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961703; x=1709566503; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S6aMKdSt4hlpMvvzbH/1eqnngZDBGFEB284Ogg6dR3I=; b=ceaEIBd6sk7ebE4LCzP/7la/tjkQZoVoXFuYEf4Ru7qT1R5/SBfuhmT+Cd9bdh7Nn0 O4ok+gmRl+gjzxngllTJ4woZ8fVGCBsRvHpwhmTOSLUVPYiuEzT65d1UIIYIztoCjC4e j3snopB0lhcDaw3LR0qk/8RreP/tu5j8l4qiA0BkBriyIEgLwMJN+X0uyRkKbmvv3hyh UDy2PqcNT9wTG6fdgXv1fKzOJ5Lk8IDQgnDTq0FOceqz1IjF/l1w1WhbMVWGWmz/JduT jRcMHwZdcnRW4+0P6E7BHNsJ5C5PUrPmWuBF+nG/KZ0aCeutoxBtvB3fMlkSN0pF10X/ xVaQ== X-Gm-Message-State: AOJu0Yx9bfBs/3ZUeK2jiTwEpyeRMhzJdilliW7hy71ptQ4xwpVIrnBr snj6ZYkfPn3sjAJ5KW7dKM0quzN2QlHzYeFPL97b1dUDtnMinag5S20oZ7gV X-Google-Smtp-Source: AGHT+IHx9aLUb3nkOVVOsznbHJpqxF/53eJVaROIhlqUBuCbRr49sSSVaflwg9iG9V4m6FWgNdFQcQ== X-Received: by 2002:a05:6870:1711:b0:21e:c9eb:e19f with SMTP id h17-20020a056870171100b0021ec9ebe19fmr3266912oae.19.1708961702798; Mon, 26 Feb 2024 07:35:02 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:02 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/8] qmi: Ensure tid is initialized Date: Mon, 26 Feb 2024 09:34:21 -0600 Message-ID: <20240226153459.1463304-2-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When the qmi_request structure is allocated, the tid member is never initialized properly. This is usually okay since the request is submitted afterwards, but it is still better to initialize this member properly. --- drivers/qmimodem/qmi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 652f19fb6cd0..be6f6f7bd601 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -202,6 +202,7 @@ static struct qmi_request *__request_alloc(uint8_t service, msglen = hdrlen + QMI_MESSAGE_HDR_SIZE + length; req = l_malloc(sizeof(struct qmi_request) + msglen); + req->tid = 0; req->len = msglen; req->client = client; From patchwork Mon Feb 26 15:34:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572393 Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4862D12B145 for ; Mon, 26 Feb 2024 15:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961706; cv=none; b=Wnsm82hcK9kpdnQTHJo14seR4uxYANQKL752pk+gb2Zld6wYWsjJ2r/hEvCVTLMlvqBTqnklHuWdL4jey7MB7X1UmN9xQezYecBMhaOempUBEgTIEAswy724O0X2hCbU+VmCRwIfLx5WY8HGY1/dJG4nT9FzZYwPm4ZEP3Jy9wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961706; c=relaxed/simple; bh=bOLefyq4VsPxX2+Fzh2TMs7+zXfBrA3IZKlnTBDZKw0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E6ErrQAKxAb/AYbnBfsQnkxto/lhtQzV3LqtNJb0dyJLXDsvtj7gTmpyKpkPPG5yhcXGuTHtbTeaxzsgWwpjlcbt4fbMzWxdJyYc+ar1woALW8IWSsN2TIJYba716x7/fLou2bjzHo9+SNmNaQ3MMWKvFqdLDGfflMi4VymjajI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=djeRJDkH; arc=none smtp.client-ip=209.85.210.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="djeRJDkH" Received: by mail-ot1-f48.google.com with SMTP id 46e09a7af769-6e49872f576so664109a34.1 for ; Mon, 26 Feb 2024 07:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961704; x=1709566504; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4wXErfSU1dvEl7jqeJK3F4EXaY2fMsk/4RCro+WDqhU=; b=djeRJDkHDqcmlZ5/3EH694iRzRl006cdcmXcOcxnOgQPPmUaasEiv6V14HzNOst3ka F61PXnXtkG+LPz9vVR1GVghBM4aGvIN4iLsJGOga7xv66rnO/HobzBmIWHhW0Rv+V6/r iTArNQIPpUG4/Q1VG/MkJ/LgJQJroVIHEawy6vHTXNNL5ir27q/kUjz5V1E3gaY1oc2s CWJSaLr1ymlRBcUrYvszzJ4GrFNxiWKMmL0pgA9cP0eVJU47dBf1plIjjdw5jH003hvb liaKKFQBVh6NrmbQIJMcGzyFoeb3AuVOaOyxjGuMViRUARsBfHjwUFus7O+LgNjVnKZq ZYNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961704; x=1709566504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4wXErfSU1dvEl7jqeJK3F4EXaY2fMsk/4RCro+WDqhU=; b=HoUtcKfJ4Woh5SoE6pmmEUtJe5wtv89BKtcXSnSmKgKF89ev6kzPmJKdvz5kyA8DgU 0TKfXnM6y+BFY4sPlfVWapGhxG/SbhH0AcKg0X+P2S3BAJQ0UPOdhFF9wnhvO047oN3s sq1MrTPaOYq9m1AWe/E6D0npsWzugHY5uu5Xwj+jsLNsrC9Q3XTYPk2dUM2sjtbUbTM6 J58AbjQLpw27I0wRyncpcMuiTDkfKfewXGB2jYKdZLz/tCICfYiU3SqWThhrB9caXxce eQTyj2vG5a7UorNVH/Vedu/lgUAFgVtdw1nenRkPmMPdhm1bb5m5FnawR/pAhuOe2Q9Y WZAw== X-Gm-Message-State: AOJu0Yxj3wtexqAUwRhFaH1f6A5TMRMmuq6zXgozgdEeeck+Hzu/xyji gDDJg4OEXGxXAZM8I06RQeE3L6D1l536WqG/POOGNBqgOPZ1Oni27mobpqVW X-Google-Smtp-Source: AGHT+IHgbpeQ6GFn92HH4fsN6cQz4lZ4jGCpvRpHMMi7q8mMSgAHasJM7tSb8yAnsVB2Nt8hFihmFw== X-Received: by 2002:a05:6870:b61c:b0:21e:635c:a5b9 with SMTP id cm28-20020a056870b61c00b0021e635ca5b9mr8385758oab.52.1708961703563; Mon, 26 Feb 2024 07:35:03 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:03 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 3/8] qmi: Move and rename QMUX sync logic Date: Mon, 26 Feb 2024 09:34:22 -0600 Message-ID: <20240226153459.1463304-3-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This logic is QMUX only, move it to be spatially near the rest of QMUX specific logic and just above where these functions are used. --- drivers/qmimodem/qmi.c | 58 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index be6f6f7bd601..b08c1642c8c1 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -1079,34 +1079,6 @@ static void discover_data_free(void *user_data) l_free(data); } -static void qmi_device_sync_callback(uint16_t message, uint16_t length, - const void *buffer, void *user_data) -{ - struct discover_data *data = user_data; - - if (data->func) - data->func(data->user_data); - - __qmi_device_discovery_complete(data->device, &data->super); -} - -/* sync will release all previous clients */ -static bool qmi_device_sync(struct qmi_device *device, - struct discover_data *data) -{ - struct qmi_request *req; - - __debug_device(device, "Sending sync to reset QMI"); - - req = __request_alloc(QMI_SERVICE_CONTROL, 0x00, - QMI_CTL_SYNC, NULL, 0, - qmi_device_sync_callback, data); - - __request_submit(device, req); - - return true; -} - int qmi_device_discover(struct qmi_device *device, qmi_discover_func_t func, void *user_data, qmi_destroy_func_t destroy) { @@ -1402,6 +1374,34 @@ static struct qmi_request *find_control_request(struct qmi_device *device, return req; } +static void qmux_sync_callback(uint16_t message, uint16_t length, + const void *buffer, void *user_data) +{ + struct discover_data *data = user_data; + + if (data->func) + data->func(data->user_data); + + __qmi_device_discovery_complete(data->device, &data->super); +} + +/* sync will release all previous clients */ +static bool qmi_device_qmux_sync(struct qmi_device *device, + struct discover_data *data) +{ + struct qmi_request *req; + + __debug_device(device, "Sending sync to reset QMI"); + + req = __request_alloc(QMI_SERVICE_CONTROL, 0x00, + QMI_CTL_SYNC, NULL, 0, + qmux_sync_callback, data); + + __request_submit(device, req); + + return true; +} + static void qmux_discover_callback(uint16_t message, uint16_t length, const void *buffer, void *user_data) { @@ -1479,7 +1479,7 @@ done: /* if the device support the QMI call SYNC over the CTL interface */ if ((qmux->control_major == 1 && qmux->control_minor >= 5) || qmux->control_major > 1) { - qmi_device_sync(data->device, data); + qmi_device_qmux_sync(data->device, data); return; } From patchwork Mon Feb 26 15:34:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572394 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A05512B159 for ; Mon, 26 Feb 2024 15:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961706; cv=none; b=CZPTGYjAjHm2GfXGLYCY4RdYPtlWeGLBP95jiqTMjX6MDNVIWFPOUy1REu+Ztz0M1oAToJ13Dfr8jXhmQCuGQA31L3+XcGfmqtTEtexFVlYPS2uUnA2ZBYk6x7BDzZDggvapoc9JUVXx/XVEHD9ju8wBF1thvaua4ug6ylqxokk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961706; c=relaxed/simple; bh=Xeve0rSnXSK5w8DATuSfL23KzD4CI3qpNud37y1V9/o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xp9RQwGAqbPsoMSZPLqQth9XhJ6n5hILxpUyDJ09U7gc3eVGz9sSMfSJaNrFuipsR0ObMY2CDtOIeAt8SYSXWSvu9r6G38KlTnnh5uN0zSa9hJFumj61Z35Fs/cneEmZ0pBlFQ9u/P7YCAILAuoUO4mNhmxTqT0PccimjcmukKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=miBQSGid; arc=none smtp.client-ip=209.85.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="miBQSGid" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6e2ee49ebaaso1322590a34.0 for ; Mon, 26 Feb 2024 07:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961704; x=1709566504; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DvceYn3Jwwu9U3VaWr3he0ATxff4u7FWrlVaiSexfPk=; b=miBQSGidkdKWb5sEbHkO1idsQW1u+GHB5IEhFgKbcE9jaBp0noqooYMV08ok3Gt496 Gmiz8PVvH8J6Y7cTzhykVo0d1d9QZZOFl3/LXZBBRGWTcDRCE1VYw+CpsKW/sNwgx0Kf ur9IljzZTcWt+5X1FSCZ3DA+3hTsFvaM+YjPZsQcXZ7a/Nt452eF4Xc0AsvGLwBjAm/Z FnvoRgIKT6NibvhjqvFiKXiRSs2ald/zrs6GD2+1ymo8/q72C+1MnxpJC4muirh+IeDc sIvzBMa31OeK9/N+175dZmU2g2a2Z6TUgitjoeSOG5TM1zLdDUKTlJLIyFzmx2Xv6hkq nVuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961704; x=1709566504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DvceYn3Jwwu9U3VaWr3he0ATxff4u7FWrlVaiSexfPk=; b=ViZKU2j7DR+Su05z4Z2goiTiByARFS4GXnV578x6+RVL2FLVaZna6bvNle10oYnoW3 XQ/1hS1cUx+e+CeCWnGOhrpfrkE3jGIiR6wQaEJsd1TLRZfbv3ELAi8fJlec0sJBOS4d pyFXCt/0Eqwk5Ifqv/z5kgoOID2bUVqFgMtgtYMFTwP9fvzsuXsqRNo+mNuDCyRxwscs 7942qoDOpMAAWqY2OQ76iYuXeZSvQlrIXhb2PmJPkaSpKKoOEM1WD+pPwpUs2/xZvVhY FKtmdzIzVRfJiNGsump4BtAFVbP74Jrfb9B6y4xjnR1Qdw25yGRFpIEz/PTiUgH1E4bb MYdg== X-Gm-Message-State: AOJu0YwC7JTpSM/OqyFLawNU6K80D7sVNaNZu74eoQXaBUPy7vHOXABy 1Tjdd/04LyGJ/SJiDTccz1aMHnMl3nfXKySDaT7jgLIRro3KwqkQabMi4D0e X-Google-Smtp-Source: AGHT+IEJ1cqDXE4LcAu+GgnNZgFhIiX/W0kRPuQ1OI7h5cKw+NeJrwN6e94zqVeDdj54pEtKGWGGVA== X-Received: by 2002:a05:6871:7292:b0:220:1870:2a7e with SMTP id mm18-20020a056871729200b0022018702a7emr2581797oac.46.1708961704232; Mon, 26 Feb 2024 07:35:04 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:04 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 4/8] qmi: Introduce __ctl_request_submit Date: Mon, 26 Feb 2024 09:34:23 -0600 Message-ID: <20240226153459.1463304-4-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 __request_submit was handling both CTL and non-CTL requests. Split this function into two, one for submitting CTL requests, and one that handles normal service traffic. This allows CTL requests to be isolated into QMUX specific driver methods that use them. While here, also move next_control_tid member into the QMUX qmi_device subclass. --- drivers/qmimodem/qmi.c | 71 ++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index b08c1642c8c1..9843a9b33e5c 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -77,7 +77,6 @@ struct qmi_device { struct l_queue *control_queue; struct l_queue *service_queue; struct l_queue *discovery_queue; - uint8_t next_control_tid; uint16_t next_service_tid; qmi_debug_func_t debug_func; void *debug_data; @@ -100,6 +99,7 @@ struct qmi_device_qmux { qmi_destroy_func_t shutdown_destroy; struct l_idle *shutdown_idle; unsigned int release_users; + uint8_t next_control_tid; }; struct qmi_service { @@ -678,32 +678,18 @@ static void wakeup_writer(struct qmi_device *device) static uint16_t __request_submit(struct qmi_device *device, struct qmi_request *req) { - struct qmi_mux_hdr *mux; + struct qmi_service_hdr *hdr = + (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE]; - mux = (struct qmi_mux_hdr *) req->data; + hdr->type = 0x00; + hdr->transaction = device->next_service_tid++; - if (mux->service == QMI_SERVICE_CONTROL) { - struct qmi_control_hdr *hdr; + if (device->next_service_tid < 256) + device->next_service_tid = 256; - hdr = (struct qmi_control_hdr *) &req->data[QMI_MUX_HDR_SIZE]; - hdr->type = 0x00; - hdr->transaction = device->next_control_tid++; - if (device->next_control_tid == 0) - device->next_control_tid = 1; - req->tid = hdr->transaction; - } else { - struct qmi_service_hdr *hdr; - - hdr = (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE]; - hdr->type = 0x00; - hdr->transaction = device->next_service_tid++; - if (device->next_service_tid < 256) - device->next_service_tid = 256; - req->tid = hdr->transaction; - } + req->tid = hdr->transaction; l_queue_push_tail(device->req_queue, req); - wakeup_writer(device); return req->tid; @@ -934,7 +920,6 @@ static int qmi_device_init(struct qmi_device *device, int fd, device->service_list = l_hashmap_new(); - device->next_control_tid = 1; device->next_service_tid = 256; device->ops = ops; @@ -1310,6 +1295,26 @@ struct service_create_shared_data { struct l_idle *idle; }; +static uint8_t __ctl_request_submit(struct qmi_device_qmux *qmux, + struct qmi_request *req) +{ + struct qmi_control_hdr *hdr = + (struct qmi_control_hdr *) &req->data[QMI_MUX_HDR_SIZE]; + + hdr->type = 0x00; + hdr->transaction = qmux->next_control_tid++; + + if (qmux->next_control_tid == 0) + qmux->next_control_tid = 1; + + req->tid = hdr->transaction; + + l_queue_push_tail(qmux->super.req_queue, req); + wakeup_writer(&qmux->super); + + return req->tid; +} + static void service_create_shared_reply(struct l_idle *idle, void *user_data) { struct service_create_shared_data *data = user_data; @@ -1386,18 +1391,18 @@ static void qmux_sync_callback(uint16_t message, uint16_t length, } /* sync will release all previous clients */ -static bool qmi_device_qmux_sync(struct qmi_device *device, +static bool qmi_device_qmux_sync(struct qmi_device_qmux *qmux, struct discover_data *data) { struct qmi_request *req; - __debug_device(device, "Sending sync to reset QMI"); + __debug_device(&qmux->super, "Sending sync to reset QMI"); req = __request_alloc(QMI_SERVICE_CONTROL, 0x00, QMI_CTL_SYNC, NULL, 0, qmux_sync_callback, data); - __request_submit(device, req); + __ctl_request_submit(qmux, req); return true; } @@ -1479,7 +1484,7 @@ done: /* if the device support the QMI call SYNC over the CTL interface */ if ((qmux->control_major == 1 && qmux->control_minor >= 5) || qmux->control_major > 1) { - qmi_device_qmux_sync(data->device, data); + qmi_device_qmux_sync(qmux, data); return; } @@ -1516,6 +1521,8 @@ static int qmi_device_qmux_discover(struct qmi_device *device, void *user_data, qmi_destroy_func_t destroy) { + struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super); struct discover_data *data; struct qmi_request *req; @@ -1536,7 +1543,7 @@ static int qmi_device_qmux_discover(struct qmi_device *device, QMI_CTL_GET_VERSION_INFO, NULL, 0, qmux_discover_callback, data); - data->tid = __request_submit(device, req); + data->tid = __ctl_request_submit(qmux, req); data->timeout = l_timeout_create(5, qmux_discover_reply_timeout, data, NULL); @@ -1662,6 +1669,8 @@ static int qmi_device_qmux_client_create(struct qmi_device *device, qmi_create_func_t func, void *user_data, qmi_destroy_func_t destroy) { + struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super); unsigned char client_req[] = { 0x01, 0x01, 0x00, service_type }; struct qmi_request *req; struct qmux_client_create_data *data; @@ -1697,7 +1706,7 @@ static int qmi_device_qmux_client_create(struct qmi_device *device, client_req, sizeof(client_req), qmux_client_create_callback, data); - data->tid = __request_submit(device, req); + data->tid = __ctl_request_submit(qmux, req); data->timeout = l_timeout_create(8, qmux_client_create_reply, data, NULL); @@ -1734,7 +1743,7 @@ static void qmi_device_qmux_client_release(struct qmi_device *device, release_req, sizeof(release_req), qmux_client_release_callback, qmux); - __request_submit(device, req); + __ctl_request_submit(qmux, req); } static void qmux_shutdown_destroy(void *user_data) @@ -1829,6 +1838,8 @@ struct qmi_device *qmi_device_new_qmux(const char *device) return NULL; } + qmux->next_control_tid = 1; + return &qmux->super; } From patchwork Mon Feb 26 15:34:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572395 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 048AF604CC for ; Mon, 26 Feb 2024 15:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961707; cv=none; b=T0U3vtWx2rYi5VCecndNI7JAhpfayqa4DSpK7YC868MrVyQEXMEalaDxB9+s9f+VD/q2UeSlA1vgo3SHf0K/7309Nxajp2PjIpm/CmUbUBQ6vIHfembWhZnBNLTombNMLe5gXSBs0obTAIs4TlYbr0JtnfAQ7Jh1vIRYG5PfVEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961707; c=relaxed/simple; bh=BjQbmdogoCkD9JHW4n9MDQDvcLbZ0losPTQCBQ3r+os=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DJgQjHaoF2jcNt1KFmGkedakvjQ+u+wQXwT+FCnoi/LsWKyxjbXs6cHQ8ThI02lf8kgk5ARz3oWjh+YksxdH+x25qracxOx4JkFGtc/2fz/L0Cj38O9gDJf0wqyazvTPm3NipBFwxF1+hymFWoGMXGpktEyML/zb+OVEg75BBHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Mu+zknbX; arc=none smtp.client-ip=209.85.160.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Mu+zknbX" Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-21fa97a9c53so1371898fac.3 for ; Mon, 26 Feb 2024 07:35:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961705; x=1709566505; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KTiPOC6A8OOZTio+EtQ+HEbW0pT+EHgiuLZy/9I4pBw=; b=Mu+zknbXqPJLAx34rYKuSR6qHpYHpEtZpRypyRhexSIAytz4l0aUR4LVcLuxwUe2Vk vrrgTeg1INg5hLdM0sL7Dt4mmdZhEc+FPlkW5iAgfDTTHPl2TZ6pa/iLgI34E/PHCo4s ytZeu6tg/qbQaLL2c1noUuuF/bZGclrMP5ivi2elqmI411y1LtI0y+Qkw1XbL3k3o+yf tjHV6f0JhMwoyuehAFQodHoLTc5M8TvAulboe1AAPsdlc0g3lE3Lo6H+JeTQEFOZBwEL R+52aVPPv8hMJKBdqtmRSaYvb6osIB3yNZS9rpbwbBEzP0k57ckx6W7O4Zbrm4kqXNaI cRgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961705; x=1709566505; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KTiPOC6A8OOZTio+EtQ+HEbW0pT+EHgiuLZy/9I4pBw=; b=OHXn3wMgmSbGivf/o0bHOfrwDNCy2AhyAB7BCTkfTyT/eWtRk7CGeU4ac0yiPNsteJ suzWs+w47jv4otnG7ZEiqpamys2ceiYvBHjpJp4kS3H71THrqdmGc/eJkP4hczvnxZFU EPgogbR1sPT3PcVYUpf0MnojY/tbgjnT+NLzww3nPCEdzFSJYp/xcpAzYvL/PtgsXpPT /pE6/AFzfdjPuxMv+hrjrhDsbOjnzuBKBEwl9A/XupttkZEUPrhaCdblJkveVgUmFpYl Dvzt9ycrKZkm0+qEzVZq5I8+c9D0PNh1emQw86fdr7ZCs+UenDmr3q67y+7GQ6nmPPML iWlw== X-Gm-Message-State: AOJu0YwD7fPwDmZH14B4ORwJYKd4nxNBI/HqjraSFpAd5+2OHo4D7LXM B2BWwv153fAYuWxYzZcaEmNvoZEuJK+XzORm2h6sAERmIo8x3TTE8aC4YVcF X-Google-Smtp-Source: AGHT+IEAvwdow+QBRUDJS8v/Sz7J2RduGDik8nR044g+lMypbJpDdfH6G0gvKIiNKKGi5bQtWWj0Tg== X-Received: by 2002:a05:6870:831c:b0:21f:9f20:2f58 with SMTP id p28-20020a056870831c00b0021f9f202f58mr8223990oae.24.1708961705008; Mon, 26 Feb 2024 07:35:05 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:04 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 5/8] qmi: Split RX path into QMUX and generic parts Date: Mon, 26 Feb 2024 09:34:24 -0600 Message-ID: <20240226153459.1463304-5-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 handle_packet currently handles both CTL and generic service messages coming from the device. In all cases, QMUX framing is assumed. Split up this function into two, one for parsing and handling the CTL packets, and one for all other service messages. As a result, the reader handler is renamed to received_qmux_data() and set into l_io inside qmi_device_new_qmux() constructor. --- drivers/qmimodem/qmi.c | 211 +++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 101 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 9843a9b33e5c..fbe4640af6c5 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -751,65 +751,30 @@ static void handle_indication(struct qmi_device *device, service_notify(NULL, service, &result); } -static void handle_packet(struct qmi_device *device, - const struct qmi_mux_hdr *hdr, const void *buf) +static void __rx_message(struct qmi_device *device, + uint8_t service_type, uint8_t client_id, + const void *buf) { + const struct qmi_service_hdr *service = buf; + const struct qmi_message_hdr *msg = buf + QMI_SERVICE_HDR_SIZE; + const void *data = buf + QMI_SERVICE_HDR_SIZE + QMI_MESSAGE_HDR_SIZE; struct qmi_request *req; - uint16_t message, length; - const void *data; - - if (hdr->service == QMI_SERVICE_CONTROL) { - const struct qmi_control_hdr *control = buf; - const struct qmi_message_hdr *msg; - unsigned int tid; - - /* Ignore control messages with client identifier */ - if (hdr->client != 0x00) - return; - - msg = buf + QMI_CONTROL_HDR_SIZE; - - message = L_LE16_TO_CPU(msg->message); - length = L_LE16_TO_CPU(msg->length); - - data = buf + QMI_CONTROL_HDR_SIZE + QMI_MESSAGE_HDR_SIZE; - - tid = control->transaction; - - if (control->type == 0x02 && control->transaction == 0x00) { - handle_indication(device, hdr->service, hdr->client, - message, length, data); - return; - } - - req = l_queue_remove_if(device->control_queue, - __request_compare, - L_UINT_TO_PTR(tid)); - } else { - const struct qmi_service_hdr *service = buf; - const struct qmi_message_hdr *msg; - unsigned int tid; - - msg = buf + QMI_SERVICE_HDR_SIZE; - - message = L_LE16_TO_CPU(msg->message); - length = L_LE16_TO_CPU(msg->length); - - data = buf + QMI_SERVICE_HDR_SIZE + QMI_MESSAGE_HDR_SIZE; + unsigned int tid; + uint16_t message; + uint16_t length; - tid = L_LE16_TO_CPU(service->transaction); + message = L_LE16_TO_CPU(msg->message); + length = L_LE16_TO_CPU(msg->length); + tid = L_LE16_TO_CPU(service->transaction); - if (service->type == 0x04) { - handle_indication(device, hdr->service, hdr->client, - message, length, data); - return; - } - - req = l_queue_remove_if(device->service_queue, - __request_compare, - L_UINT_TO_PTR(tid)); + if (service->type == 0x04) { + handle_indication(device, service_type, client_id, + message, length, data); + return; } + req = l_queue_remove_if(device->service_queue, __request_compare, + L_UINT_TO_PTR(tid)); if (!req) return; @@ -819,53 +784,6 @@ static void handle_packet(struct qmi_device *device, __request_free(req); } -static bool received_data(struct l_io *io, void *user_data) -{ - struct qmi_device *device = user_data; - struct qmi_mux_hdr *hdr; - unsigned char buf[2048]; - ssize_t bytes_read; - uint16_t offset; - - bytes_read = read(l_io_get_fd(device->io), buf, sizeof(buf)); - if (bytes_read < 0) - return true; - - l_util_hexdump(true, buf, bytes_read, - device->debug_func, device->debug_data); - - offset = 0; - - while (offset < bytes_read) { - uint16_t len; - - /* Check if QMI mux header fits into packet */ - if (bytes_read - offset < QMI_MUX_HDR_SIZE) - break; - - hdr = (void *) (buf + offset); - - /* Check for fixed frame and flags value */ - if (hdr->frame != 0x01 || hdr->flags != 0x80) - break; - - len = L_LE16_TO_CPU(hdr->length) + 1; - - /* Check that packet size matches frame size */ - if (bytes_read - offset < len) - break; - - __debug_msg(' ', buf + offset, len, - device->debug_func, device->debug_data); - - handle_packet(device, hdr, buf + offset + QMI_MUX_HDR_SIZE); - - offset += len; - } - - return true; -} - static void __qmi_device_discovery_started(struct qmi_device *device, struct discovery *d) { @@ -911,7 +829,6 @@ static int qmi_device_init(struct qmi_device *device, int fd, device->io = l_io_new(fd); l_io_set_close_on_destroy(device->io, true); - l_io_set_read_handler(device->io, received_data, device, NULL); device->req_queue = l_queue_new(); device->control_queue = l_queue_new(); @@ -1285,6 +1202,97 @@ done: return res; } +static void __rx_ctl_message(struct qmi_device_qmux *qmux, + uint8_t service_type, uint8_t client_id, + const void *buf) +{ + const struct qmi_control_hdr *control = buf; + const struct qmi_message_hdr *msg = buf + QMI_CONTROL_HDR_SIZE; + const void *data = buf + QMI_CONTROL_HDR_SIZE + QMI_MESSAGE_HDR_SIZE; + struct qmi_request *req; + uint16_t message; + uint16_t length; + unsigned int tid; + + /* Ignore control messages with client identifier */ + if (client_id != 0x00) + return; + + message = L_LE16_TO_CPU(msg->message); + length = L_LE16_TO_CPU(msg->length); + tid = control->transaction; + + if (control->type == 0x02 && control->transaction == 0x00) { + handle_indication(&qmux->super, service_type, client_id, + message, length, data); + return; + } + + req = l_queue_remove_if(qmux->super.control_queue, __request_compare, + L_UINT_TO_PTR(tid)); + if (!req) + return; + + if (req->callback) + req->callback(message, length, data, req->user_data); + + __request_free(req); +} + +static bool received_qmux_data(struct l_io *io, void *user_data) +{ + struct qmi_device_qmux *qmux = user_data; + struct qmi_mux_hdr *hdr; + unsigned char buf[2048]; + ssize_t bytes_read; + uint16_t offset; + + bytes_read = read(l_io_get_fd(qmux->super.io), buf, sizeof(buf)); + if (bytes_read < 0) + return true; + + l_util_hexdump(true, buf, bytes_read, + qmux->super.debug_func, qmux->super.debug_data); + + offset = 0; + + while (offset < bytes_read) { + uint16_t len; + const void *msg; + + /* Check if QMI mux header fits into packet */ + if (bytes_read - offset < QMI_MUX_HDR_SIZE) + break; + + hdr = (void *) (buf + offset); + + /* Check for fixed frame and flags value */ + if (hdr->frame != 0x01 || hdr->flags != 0x80) + break; + + len = L_LE16_TO_CPU(hdr->length) + 1; + + /* Check that packet size matches frame size */ + if (bytes_read - offset < len) + break; + + __debug_msg(' ', buf + offset, len, + qmux->super.debug_func, qmux->super.debug_data); + + msg = buf + offset + QMI_MUX_HDR_SIZE; + + if (hdr->service == QMI_SERVICE_CONTROL) + __rx_ctl_message(qmux, hdr->service, hdr->client, msg); + else + __rx_message(&qmux->super, + hdr->service, hdr->client, msg); + + offset += len; + } + + return true; +} + struct service_create_shared_data { struct discovery super; struct qmi_service *service; @@ -1839,6 +1847,7 @@ struct qmi_device *qmi_device_new_qmux(const char *device) } qmux->next_control_tid = 1; + l_io_set_read_handler(qmux->super.io, received_qmux_data, qmux, NULL); return &qmux->super; } From patchwork Mon Feb 26 15:34:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572396 Received: from mail-oa1-f41.google.com (mail-oa1-f41.google.com [209.85.160.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C94E712B17B for ; Mon, 26 Feb 2024 15:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961708; cv=none; b=Cgpz7cWQ16Rf+Eb2BzaRCIFKTzg6K3BD7ZoE+qk2EgQxFQexK04bxEbeOPq3+o72IFa65uqSAMu/iaEUiq2//47Vtaw90IKKa68UJde0Vqac5VwdHmDz2dvySO1Eoz1aToIJnQpJ4xJMZAPww37+mSjgZOhWIjDrGywXrLDeY4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961708; c=relaxed/simple; bh=42DhD/l45U1wB+ZMyWe1iMzWQESdF3EbD3zYwsUMslU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iq6jWK60H9WTCBz2gxYXT2XGtmvvFzAz4iTZouMtyw8NVWJRu1dGePTrtzgbeQPJFI/yw/lTM1arByQJLa+AMddBkG875ipu65XUtD0mWcwlRK3kxQ2cLDuVO3JAFy0AZFn/n+cQODS/rqHu9PdtXwbHMavdxLWmeCsCB8fS5yQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ci2xR1Eh; arc=none smtp.client-ip=209.85.160.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ci2xR1Eh" Received: by mail-oa1-f41.google.com with SMTP id 586e51a60fabf-22008177fbeso849683fac.2 for ; Mon, 26 Feb 2024 07:35:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961706; x=1709566506; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2Z3t3MvbjxqwZQVFf1sOMongK0S0FnhpqiL/jI14JTA=; b=Ci2xR1EhyjQUeU2fAt5CuR2FGlQsY0j+5rAkLSB4gD78BaPyui/3iTVf69ppuYUkKp HksCzatYDZSZObyj6GnzLRdQ6HiiT3plEP2k5cAKNF1FMBCFbB9WUSDzFWF9yqpaKvt0 1z9nRvi6FE2dP4xgjRs/GM8duVL8mJ9rmibQDiokzdHlXRkibv1OHIPyHk8aARN2laIZ GNf5v/7oBRTR3nY9ZrweJHUnQ8P8wzBoD5kTJbWCJrRCGWWzQDovroOvLCx29/1vfc9N L1iR6Kq3rVhwOi/3HFCIuItrk99JCl+rcs42TrORE2brXPw/gYlLW/VpHgqJdJO39tOm vuFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961706; x=1709566506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Z3t3MvbjxqwZQVFf1sOMongK0S0FnhpqiL/jI14JTA=; b=BrPZmPrUSgxxrwLeqotRWzy08DI3KoCoFqEl0TlvkQ2Dn5OYh2ZpXaei5/WJsKRSEY zA7ioOULxijKC6aL+99jo0Fy6+YQrUTXAefzTk2M2vhtSoU+x2SuWw3wAtgosndmur5H 5nvqDA4xckxTgX1WdKimCQMCcB/ehqk/WDnAM0YJhm42HoS1t9jUfuOhHfu9Vlv+YlW/ Ia8X2lrQi38a1dVE8Itq2h3UK93rPDMVPRxRk2TuNBAkuN0ibt01SPsS8V4e0ONyZixc FUdX4hWbLF/HjwtUHB2ohuAe/bXgDjoMuiYIrJONLhA09t8ctGkqKnqR8WlDZNOFh/RO RwNg== X-Gm-Message-State: AOJu0YzybF7Pm9Noy3/gJoKcglrc7pWLiBaXwbR21TreL619JoNyDPHZ IhA9xy+jPA8bJRPSCNFk0VRzF7vjTLMqqOKlhgH/QB4ZLVbW+OoA6yNQbYXC X-Google-Smtp-Source: AGHT+IHHK0MFFgVRSFvRBR4oOM3T8403GLOH07f9USvnDtf5rs381P2AwGjloZYRaxA4kViuK52RAQ== X-Received: by 2002:a05:6870:a692:b0:21e:80a1:3155 with SMTP id i18-20020a056870a69200b0021e80a13155mr9247762oam.6.1708961705780; Mon, 26 Feb 2024 07:35:05 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:05 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 6/8] qmi: Introduce write driver method Date: Mon, 26 Feb 2024 09:34:25 -0600 Message-ID: <20240226153459.1463304-6-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce a new write driver method which will abstract away the details of submitting a QMI message to the underlying device / protocol. qmi_device will continue managing the request queue and setup the l_io write handler accordingly. --- drivers/qmimodem/qmi.c | 68 ++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 26 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index fbe4640af6c5..2af1d6463783 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -48,6 +48,15 @@ struct discovery { qmi_destroy_func_t destroy; }; +struct qmi_request { + uint16_t tid; + uint8_t client; + qmi_message_func_t callback; + void *user_data; + uint16_t len; + uint8_t data[]; +}; + struct qmi_version { uint8_t type; uint16_t major; @@ -56,6 +65,7 @@ struct qmi_version { }; struct qmi_device_ops { + int (*write)(struct qmi_device *device, struct qmi_request *req); int (*discover)(struct qmi_device *device, qmi_discover_func_t discover_func, void *user, qmi_destroy_func_t destroy); @@ -126,15 +136,6 @@ struct qmi_result { uint16_t length; }; -struct qmi_request { - uint16_t tid; - uint8_t client; - qmi_message_func_t callback; - void *user_data; - uint16_t len; - uint8_t data[]; -}; - struct qmi_notify { uint16_t id; uint16_t message; @@ -626,30 +627,18 @@ static void __debug_device(struct qmi_device *device, static bool can_write_data(struct l_io *io, void *user_data) { struct qmi_device *device = user_data; - struct qmi_mux_hdr *hdr; struct qmi_request *req; - ssize_t bytes_written; + int r; req = l_queue_pop_head(device->req_queue); if (!req) return false; - bytes_written = write(l_io_get_fd(device->io), req->data, req->len); - if (bytes_written < 0) + r = device->ops->write(device, req); + if (r < 0) { + __request_free(req); return false; - - l_util_hexdump(false, req->data, bytes_written, - device->debug_func, device->debug_data); - - __debug_msg(' ', req->data, bytes_written, - device->debug_func, device->debug_data); - - hdr = (struct qmi_mux_hdr *) req->data; - - if (hdr->service == QMI_SERVICE_CONTROL) - l_queue_push_tail(device->control_queue, req); - else - l_queue_push_tail(device->service_queue, req); + } if (l_queue_length(device->req_queue) > 0) return true; @@ -1202,6 +1191,32 @@ done: return res; } +static int qmi_device_qmux_write(struct qmi_device *device, + struct qmi_request *req) +{ + struct qmi_mux_hdr *hdr; + ssize_t bytes_written; + + bytes_written = write(l_io_get_fd(device->io), req->data, req->len); + if (bytes_written < 0) + return -errno; + + l_util_hexdump(false, req->data, bytes_written, + device->debug_func, device->debug_data); + + __debug_msg(' ', req->data, bytes_written, + device->debug_func, device->debug_data); + + hdr = (struct qmi_mux_hdr *) req->data; + + if (hdr->service == QMI_SERVICE_CONTROL) + l_queue_push_tail(device->control_queue, req); + else + l_queue_push_tail(device->service_queue, req); + + return 0; +} + static void __rx_ctl_message(struct qmi_device_qmux *qmux, uint8_t service_type, uint8_t client_id, const void *buf) @@ -1822,6 +1837,7 @@ static void qmi_device_qmux_destroy(struct qmi_device *device) } static const struct qmi_device_ops qmux_ops = { + .write = qmi_device_qmux_write, .discover = qmi_device_qmux_discover, .client_create = qmi_device_qmux_client_create, .client_release = qmi_device_qmux_client_release, From patchwork Mon Feb 26 15:34:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572397 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9BF312BE96 for ; Mon, 26 Feb 2024 15:35:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961709; cv=none; b=njoa1UBTfw3kByLZm2r9Zm+fWNbJ9M2kpzjRecI6BsBk+i8cLNCt7ohrbGhx4OcZN8paryzAeilkafajaS8sAw9kAwNqMmoijFCMuFt1192Hr1c/gcqYTAS22nqkf59fQ3qSrFdqaAqfxe7s7JQR4e63Qi0oMrK6QwJhCwxISv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961709; c=relaxed/simple; bh=UbSADqgYldh/xATUh77EQyTdLcREq+26WctghklYPXk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ekEyH83QaECc+qmbg9C1MHaTDsrIoxtc7I7PhgWDIyYV3C6VpahjvObHHU5dcnuG28UzAVR9E4yyv057gDbtE/mRoYMshRxiuyBMBDkQGFUE4Gs3GHjPaQFV9IaGSBqyY/t7MzUaVtAZ6iRtAgkuOrbeTzEd1tCr4svIFPO5GTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UM3pp4HU; arc=none smtp.client-ip=209.85.160.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UM3pp4HU" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-21f2f813e3bso1206383fac.0 for ; Mon, 26 Feb 2024 07:35:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961706; x=1709566506; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CapTx0RywUqOfvsfwbDHkXRxcsLss7bEilJRojg6BQc=; b=UM3pp4HUxeB0UkIFXUF0lJNcQtrP7EB7KH2tQXqLatrKwGERb8Cd/x1ancqgIVQiPK HJoXjwAuOsSb4ffpW1AWcf1SIs1hs6lFCKrcURMkWM3cL/DXxgIF8l4mmY0U8Awl8p2S IVFlY+MlFxT+lSvFjRs+phuBOGGSwqRtGeI17/kdE0JZfdCegdYi6nwnVGhUgw0CBzbC JayLIb7Gx0BSno1n/R+5yK6y9PJXwA/r0nccfFCERRjDhEjGpKQ0FfGewa58Tgk7wf6r wjuFp5YEdq0+sYwycYk109RzvASnLMlPFMV2+pgiZy/aAfrIW6+uYl/eKtZcIqlTstrr W23A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961706; x=1709566506; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CapTx0RywUqOfvsfwbDHkXRxcsLss7bEilJRojg6BQc=; b=r7EDmMLQz6JwHE/3tMhrcUsfAbcjTYr9WHRydPd/4T6Mmml06J757SGZcb4ne7fTi7 IjMhMgt39Mle5Mk4Vsoe8FMdOQtA4vFZsCKi2Bo2791iiQZP2dvaSkeT37B9dz5+JjSv NYE9/A0jSGflvccqg6Xvy9eyXj+taTpuISrG9vLiScz/wg8MV1wHJrqa/rWTq4SeI3gD S+ELAmuX6c2Mq4gFLtR9LVrxnLPEtJxZPBsQqW/LW54cRM7kZCRZm25xdTmrOthsoft+ 4PhU3tgxEE0GDs93XWMjed3sTc3tiVIDfC1OXY5Mgs89/YquDSWem+t+l+adYktRH6wW Zr+Q== X-Gm-Message-State: AOJu0Yw5bHeqJHkINZdADq/odETAq+SqJgIAjl+Figh2ayRgtA0aIBU+ UWNqyRQkzET/CirbaCsDY6c/yL9d/KVi7cf7Iml9JLwTHYE8tDxjpU+SpQdW X-Google-Smtp-Source: AGHT+IGJc0aYgGpxRZ4z4n3J10kIA78Im4kyxQmV8tN5forQeLRKWdqen4VASjuMGfOCSOG+0pXi3Q== X-Received: by 2002:a05:6870:4153:b0:21e:6c0d:41c8 with SMTP id r19-20020a056870415300b0021e6c0d41c8mr3500844oad.16.1708961706653; Mon, 26 Feb 2024 07:35:06 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:06 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 7/8] qmi: Move control_queue member to qmux subclass Date: Mon, 26 Feb 2024 09:34:26 -0600 Message-ID: <20240226153459.1463304-7-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 control_queue is only used by the QMUX transport. Move it out from the qmi_device structure into the QMUX specific qmi_device_qmux structure. --- drivers/qmimodem/qmi.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 2af1d6463783..2371f178a4c4 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -84,7 +84,6 @@ struct qmi_device_ops { struct qmi_device { struct l_io *io; struct l_queue *req_queue; - struct l_queue *control_queue; struct l_queue *service_queue; struct l_queue *discovery_queue; uint16_t next_service_tid; @@ -110,6 +109,7 @@ struct qmi_device_qmux { struct l_idle *shutdown_idle; unsigned int release_users; uint8_t next_control_tid; + struct l_queue *control_queue; }; struct qmi_service { @@ -820,7 +820,6 @@ static int qmi_device_init(struct qmi_device *device, int fd, l_io_set_close_on_destroy(device->io, true); device->req_queue = l_queue_new(); - device->control_queue = l_queue_new(); device->service_queue = l_queue_new(); device->discovery_queue = l_queue_new(); @@ -846,7 +845,6 @@ void qmi_device_free(struct qmi_device *device) __debug_device(device, "device %p free", device); - l_queue_destroy(device->control_queue, __request_free); l_queue_destroy(device->service_queue, __request_free); l_queue_destroy(device->req_queue, __request_free); l_queue_destroy(device->discovery_queue, __discovery_free); @@ -1194,6 +1192,8 @@ done: static int qmi_device_qmux_write(struct qmi_device *device, struct qmi_request *req) { + struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super); struct qmi_mux_hdr *hdr; ssize_t bytes_written; @@ -1210,7 +1210,7 @@ static int qmi_device_qmux_write(struct qmi_device *device, hdr = (struct qmi_mux_hdr *) req->data; if (hdr->service == QMI_SERVICE_CONTROL) - l_queue_push_tail(device->control_queue, req); + l_queue_push_tail(qmux->control_queue, req); else l_queue_push_tail(device->service_queue, req); @@ -1243,7 +1243,7 @@ static void __rx_ctl_message(struct qmi_device_qmux *qmux, return; } - req = l_queue_remove_if(qmux->super.control_queue, __request_compare, + req = l_queue_remove_if(qmux->control_queue, __request_compare, L_UINT_TO_PTR(tid)); if (!req) return; @@ -1383,22 +1383,21 @@ static void service_create_shared_data_free(void *user_data) l_free(data); } -static struct qmi_request *find_control_request(struct qmi_device *device, +static struct qmi_request *find_control_request(struct qmi_device_qmux *qmux, uint16_t tid) { - struct qmi_request *req = NULL; - unsigned int _tid = tid; + struct qmi_request *req; - if (_tid != 0) { - req = l_queue_remove_if(device->req_queue, __request_compare, - L_UINT_TO_PTR(_tid)); + if (!tid) + return NULL; - if (!req) - req = l_queue_remove_if(device->control_queue, - __request_compare, - L_UINT_TO_PTR(_tid)); - } + req = l_queue_remove_if(qmux->super.req_queue, + __request_compare, L_UINT_TO_PTR(tid)); + if (req) + return req; + req = l_queue_remove_if(qmux->control_queue, + __request_compare, L_UINT_TO_PTR(tid)); return req; } @@ -1522,13 +1521,15 @@ static void qmux_discover_reply_timeout(struct l_timeout *timeout, { struct discover_data *data = user_data; struct qmi_device *device = data->device; + struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super); struct qmi_request *req; l_timeout_remove(data->timeout); data->timeout = NULL; /* remove request from queues */ - req = find_control_request(device, data->tid); + req = find_control_request(qmux, data->tid); if (data->func) data->func(data->user_data); @@ -1605,6 +1606,8 @@ static void qmux_client_create_reply(struct l_timeout *timeout, void *user_data) { struct qmux_client_create_data *data = user_data; struct qmi_device *device = data->device; + struct qmi_device_qmux *qmux = + l_container_of(device, struct qmi_device_qmux, super); struct qmi_request *req; DBG(""); @@ -1612,7 +1615,7 @@ static void qmux_client_create_reply(struct l_timeout *timeout, void *user_data) service_create_shared_pending_reply(device, data->type, NULL); /* remove request from queues */ - req = find_control_request(device, data->tid); + req = find_control_request(qmux, data->tid); l_timeout_remove(data->timeout); data->timeout = NULL; @@ -1829,6 +1832,8 @@ static void qmi_device_qmux_destroy(struct qmi_device *device) struct qmi_device_qmux *qmux = l_container_of(device, struct qmi_device_qmux, super); + l_queue_destroy(qmux->control_queue, __request_free); + if (qmux->shutdown_idle) l_idle_remove(qmux->shutdown_idle); @@ -1863,6 +1868,7 @@ struct qmi_device *qmi_device_new_qmux(const char *device) } qmux->next_control_tid = 1; + qmux->control_queue = l_queue_new(); l_io_set_read_handler(qmux->super.io, received_qmux_data, qmux, NULL); return &qmux->super; From patchwork Mon Feb 26 15:34:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13572398 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7671212BEAF for ; Mon, 26 Feb 2024 15:35:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961709; cv=none; b=AVxn2om2lzV1rFWB2xpskRm7+y1bLjyezwBM8PgSqFFxV2XVFjHOK24AfNkPcJVHTqEnfGLSqATFcPRWwxwsj7cFA8OA+A/Rn/+fA8mOC7Fc02lCGD1LXZALmT7d60wYLNRVa2GSbLANobwspEHTKfB5Dmax9OPiPUUp/6pH8gs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708961709; c=relaxed/simple; bh=xEZxSXcCD67mBef/SXN0Cvscw/KtOJJZhtPHolxhpdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JrFUqgATkKJ2hAK8y4rj+ahtrrwQDULmW+CJeJGku0J1pk3006F1gDlRJmX7cPRclwQpbK6ekPUlko6obsESTe3wB7WoMIiWPcpI/NrneO7jmxCnrRZLF2J42JXGZlJ21NSQ/WpRunzs+/VuKG7eAwUF9YjzS8Lo8Wu8QuWWdpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fi7PXeTF; arc=none smtp.client-ip=209.85.160.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fi7PXeTF" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-21433afcc53so1784343fac.3 for ; Mon, 26 Feb 2024 07:35:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708961707; x=1709566507; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vQrbnU9xR0agc1lrbNVhSCW3rOMxu0RLrIjSwe2tv4U=; b=fi7PXeTFt29douXuCKb/9kt2+uwdHnYdOKLSg39MZ1zmYyKu+wy8CBP+ftJbA8j/+U L3lMmzu9q05nvDOXD0a2iE1PFWJ5+FkBM5s2oH0y8SspHxihmjhIXUnCShyYWv7KPwxw Azfh7wh9wG60XQudR51kAL1HpVawa6/PQxv4ilGxkia0Ayio3jyzADkZoT8jisCKd8+5 GwGigdYryWW4o+y3CloT6gkGCX/b2CgqThOX0YsdTQGWJ1nKVlW1N/q6+JFuBO4aE2Vp Jk4SR7YTqa5TrUp9+h1eOhsN4MLfobA0BeBFrDAKVme9U/j8YTObHJiy6vuOUdwK61ic KINA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708961707; x=1709566507; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vQrbnU9xR0agc1lrbNVhSCW3rOMxu0RLrIjSwe2tv4U=; b=w5H7pGdDy43Lc1GgeEUqXg/roUErQo0KfxakvDFVfylYHYnB7ChJt8WvCGGF0TPdKt AakNgAhOLtTXwm/dZCLOMc0F7XmhJE9hSFpoYNJtBSUBpGBsWs0exM8vT3gmzWjot2PO m4HwFr00/n4BY2k15S1L8y7CjI9xvHLOKsQtwNax4IoYm9NwmVNB6gdz0f7LYD5PapYc KBYwGvG99tdtqHztivAi8EgGXWGWeuUrVBre1tkNF/HeYN4j/Sy2B3Tkt253cwNbBgHO ufxhN9/ZjqhULqnS3tX07/++XfmprxGzIQ4pspChfHRf74pGn2BXFjk1NJtTRbCJlE6Q Z9jg== X-Gm-Message-State: AOJu0Ywo3UFtRQp9po07jlT9rZ9yRerNsA44Bn98OvdWVDfrBk49s3g5 e4ZCa+9n5hpyXvmQVg9eJlCDvaQ+H0qpxuYGEprpl/P+XYuPa6fGuv5NFHVj X-Google-Smtp-Source: AGHT+IEr+Ewk5xLNQVQ+0PNv7/Y++sNa9U1K7zxpwV+9gjwJXqW/XbHWjkR1eng0S0z7ClmxRADX0Q== X-Received: by 2002:a05:6871:211:b0:21e:877d:78d6 with SMTP id t17-20020a056871021100b0021e877d78d6mr8502665oad.59.1708961707444; Mon, 26 Feb 2024 07:35:07 -0800 (PST) Received: from localhost.localdomain (070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id eg14-20020a056870988e00b002201144306csm567048oab.53.2024.02.26.07.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 07:35:07 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 8/8] qmi: Make sure to set transaction id as LE16 Date: Mon, 26 Feb 2024 09:34:27 -0600 Message-ID: <20240226153459.1463304-8-denkenz@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240226153459.1463304-1-denkenz@gmail.com> References: <20240226153459.1463304-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Transaction identifier for QMI service messages was always read in as LE16 value, however when allocating a request it was set in host byte order. Fix that. --- drivers/qmimodem/qmi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/qmimodem/qmi.c b/drivers/qmimodem/qmi.c index 2371f178a4c4..35751d7ce267 100644 --- a/drivers/qmimodem/qmi.c +++ b/drivers/qmimodem/qmi.c @@ -670,13 +670,13 @@ static uint16_t __request_submit(struct qmi_device *device, struct qmi_service_hdr *hdr = (struct qmi_service_hdr *) &req->data[QMI_MUX_HDR_SIZE]; - hdr->type = 0x00; - hdr->transaction = device->next_service_tid++; + req->tid = device->next_service_tid++; if (device->next_service_tid < 256) device->next_service_tid = 256; - req->tid = hdr->transaction; + hdr->type = 0x00; + hdr->transaction = L_CPU_TO_LE16(req->tid); l_queue_push_tail(device->req_queue, req); wakeup_writer(device);