From patchwork Thu Sep 7 06:03:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 111854 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp356727qge; Wed, 6 Sep 2017 23:03:43 -0700 (PDT) X-Received: by 10.98.197.134 with SMTP id j128mr1579916pfg.113.1504764223767; Wed, 06 Sep 2017 23:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504764223; cv=none; d=google.com; s=arc-20160816; b=prrgYFFqJbYP3m/fgo0Al2NMEXmIHHAKvNL1V9rNPkTCIGiZlcMP2U/0Po4pOZUG9S zlUm4KBAi8+qamYdRbEtjxb/naQkTl38SqhiXCVy7vaVJ3ptwLmoxN3Jbt4+mr5AxQHa HqKDeszMnIPeU//233r0QyhgM5FF08dcBYUUl2W+XWUH5pGBD2WBhqsF0xwRmnPHdr61 pQXdnm/K6v8tGG4cEZtGNSpQbIMkPKzul2lcsU2Se7DazwUg1tL4SA3STPjHMFIuPEO8 HP7BMXqDE4cd9EThO+KsOM6CCnwonejwsPtwB2Aj8qUqtw1dqUsZsBgOaKUiti0ffoG8 5oQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=dI2k/tqzGnaNo/4By4SKI1P74utywY87tvsHIZjuhuk=; b=B4r42xdAx5UjHVQR8S7L1Be/zIjDFVzsfGcR/PJtPCqH8+t3/h65B4l8I11aEC4x5p ml6OHPbzYELCiRdZuX7rn+5Mk23KF2Mrzu5cUvs9057OmicABXoqGa1eqnevlJcquslS cPx4KhsGz7+tgLLjYynKlh6WlHjZHlLMIvQhcHDLYAr1qxkzyuB9skyVtMh8ElsGu6m/ +TFy3TfyEOx6A4kwbvNN9r5BjHnZhca40AXLJid+NA6i1gUgiE/dg12W40lbLbx85sbz m3vebAlNZle2ZNAtI4qnis7l60ZSXsBzvlql2BahsCAr8ThBGcDKWS5ukxqZf8wqyl4a q6BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Iw8e+e/6; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 6si1311369pfg.75.2017.09.06.23.03.43; Wed, 06 Sep 2017 23:03:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Iw8e+e/6; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754020AbdIGGDk (ORCPT + 9 others); Thu, 7 Sep 2017 02:03:40 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:38653 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753312AbdIGGDh (ORCPT ); Thu, 7 Sep 2017 02:03:37 -0400 Received: by mail-pg0-f44.google.com with SMTP id v66so19132095pgb.5 for ; Wed, 06 Sep 2017 23:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ao85+WvXshKJdz1ShpFblPR3SPuwyblUXhsXJgp55nM=; b=Iw8e+e/6g9CpqRcQBS1uOF8BlUyxHGb15UXYIf7KN9UxSqr1wWZoRR9eoMdywMHry+ N1c2JwFSAJhLc4i/29eeSzv1vRDY1AcPp7WxP2nBvDEgeQ/Y3CFCF/6O5COkMwrYZyb+ q7Fo5WhsdGU77dJbkR+eXJtwfejC8xlYlPWiw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ao85+WvXshKJdz1ShpFblPR3SPuwyblUXhsXJgp55nM=; b=gRCyBmQCEfuUqyxv4WgR1YHKAKhZZSWaoGVXoMj6UsGEGJjAzqlRWo0Y24Sygxnp9T 9dGXzqhnyfa0c/wbOunFFmlrLJ/6NzZmgMzicdXs8cpNaRGZc7obhV1BwRuyexqRv1sj 0P5r1UkznBxC2PMkI0Skt4NlfXxNl62TcE+epE/tY/wMWicW+IYQvwv2iPPHzI67rX59 EL0K6/3VtzdICdcUCqWtTcr9M3/SELpriCY44HzpWh0upeUpfiGv1GDJ4vURr/RGINsJ wCfmOz/5E7ajWQR4BGGtVUNHNhY7HSNFhg1gTFG+sbd7WOphdbG0jqYuM8FEPa2yRp8N HYOw== X-Gm-Message-State: AHPjjUixBqDlvj0r9ZSxc1zqfMAERKsxbYHC3d0AbH8JQKN/jZRPxJhZ KB3GyqnzQAitU2CS X-Google-Smtp-Source: ADKCNb7D/5twRCDho5/n6D5EH9fOAdlw2MVn0wdCrrLsUDmgO26oY1DCyI9ddq1G+gKyINDKOebuFQ== X-Received: by 10.99.122.29 with SMTP id v29mr1603935pgc.434.1504764217151; Wed, 06 Sep 2017 23:03:37 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id s1sm2186650pfk.27.2017.09.06.23.03.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 23:03:36 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Chris Lew Subject: [PATCH 3/7] net: qrtr: Add control packet definition to uapi Date: Wed, 6 Sep 2017 23:03:25 -0700 Message-Id: <20170907060329.32402-4-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170907060329.32402-1-bjorn.andersson@linaro.org> References: <20170907060329.32402-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The QMUX protocol specification defines structure of the special control packet messages being sent between handlers of the control port. Add these to the uapi header, as this structure and the associated types are shared between the kernel and all userspace handlers of control messages. Signed-off-by: Bjorn Andersson --- include/uapi/linux/qrtr.h | 32 ++++++++++++++++++++++++++++++++ net/qrtr/qrtr.c | 12 ------------ 2 files changed, 32 insertions(+), 12 deletions(-) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h index 63e8803e4d90..179af64846e0 100644 --- a/include/uapi/linux/qrtr.h +++ b/include/uapi/linux/qrtr.h @@ -13,4 +13,36 @@ struct sockaddr_qrtr { __u32 sq_port; }; +enum qrtr_pkt_type { + QRTR_TYPE_DATA = 1, + QRTR_TYPE_HELLO = 2, + QRTR_TYPE_BYE = 3, + QRTR_TYPE_NEW_SERVER = 4, + QRTR_TYPE_DEL_SERVER = 5, + QRTR_TYPE_DEL_CLIENT = 6, + QRTR_TYPE_RESUME_TX = 7, + QRTR_TYPE_EXIT = 8, + QRTR_TYPE_PING = 9, + QRTR_TYPE_NEW_LOOKUP = 10, + QRTR_TYPE_DEL_LOOKUP = 11, +}; + +struct qrtr_ctrl_pkt { + __le32 cmd; + + union { + struct { + __le32 service; + __le32 instance; + __le32 node; + __le32 port; + } server; + + struct { + __le32 node; + __le32 port; + } client; + }; +} __packed; + #endif /* _LINUX_QRTR_H */ diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index 0d7d3968414e..fac7cd6ea445 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -26,18 +26,6 @@ #define QRTR_MIN_EPH_SOCKET 0x4000 #define QRTR_MAX_EPH_SOCKET 0x7fff -enum qrtr_pkt_type { - QRTR_TYPE_DATA = 1, - QRTR_TYPE_HELLO = 2, - QRTR_TYPE_BYE = 3, - QRTR_TYPE_NEW_SERVER = 4, - QRTR_TYPE_DEL_SERVER = 5, - QRTR_TYPE_DEL_CLIENT = 6, - QRTR_TYPE_RESUME_TX = 7, - QRTR_TYPE_EXIT = 8, - QRTR_TYPE_PING = 9, -}; - /** * struct qrtr_hdr - (I|R)PCrouter packet header * @version: protocol version From patchwork Thu Sep 7 06:03:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 111857 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp356814qge; Wed, 6 Sep 2017 23:03:49 -0700 (PDT) X-Received: by 10.84.199.170 with SMTP id r39mr1739781pld.375.1504764229874; Wed, 06 Sep 2017 23:03:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504764229; cv=none; d=google.com; s=arc-20160816; b=nYqOcnw543v3mClRbNpTwGJEwlD+j8tL6IjdX+C8HZyo6t8s9V73KC/fHaVf67di2d YP00MVIhYx4xmF4l64iovPnqf13Fa8gdtesXRChc//elUWP1ZPBRzjuJqhs6yWqSsJUf KRXWvOQnX5Lr68eolic9UadM0O9scPZFOGt3MdL/3Ui3dwgCl+Ai3ofHSl2tsQu4Ye8P h4PUfbVeDvhy8iL+Hi4HGCCFsRbDFg0CYSbQq/vMrPoI7YP09/7GTsgD45EPzV0CajWz 2OU5ubtBqebP54TT5qA7RvWeUvIVOZB+09EXuux36d0myjtCcFqf6aoFjz77eKj6Z1xf pe+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=OuhzMTUyBShHvS8ACS2oYao7f+YaJMi9tGA5Wu9smCY=; b=lrPQU442bDCRNymH4OpCNXLr9iP1K82q2seezX+NYsHzgI5KMIC5PENZHIpdDmJZ5S 5HZXlnlH1+CwOpfz0UP8XDMiUv5N5GCwko4ASamwr+dB+9V2GR+KV1+wO2OVKIygY/am k1iwMpR0phSN1CbBft9exHV4qNfYO1+IZMDnPuNmtDvMQ08nQWyFdW1rEiW3YDNXB9it fyDL2W/300e7/4wktbQRiCXglGqDlc7Z1+ndtOkJBIzl6fP25uAe2PB7vsFEhxHqy9g9 ZP36rR/UZ1uNaGuP7d3thSDpaSX6mc0vJZZfu3i6NJgLCHYmFxQUCXUcloQZbznHDsM4 hN2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZLqHiDoa; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u189si1293523pgb.161.2017.09.06.23.03.49; Wed, 06 Sep 2017 23:03:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZLqHiDoa; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754180AbdIGGDs (ORCPT + 9 others); Thu, 7 Sep 2017 02:03:48 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:35006 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753977AbdIGGDj (ORCPT ); Thu, 7 Sep 2017 02:03:39 -0400 Received: by mail-pf0-f174.google.com with SMTP id g13so16323853pfm.2 for ; Wed, 06 Sep 2017 23:03:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rs/TiD4LBFiJxoXhLbhCH3XjxaQMD7w8zxJrxXtvSJk=; b=ZLqHiDoa88DpL7en593+HSJ4klyQ4aH0270I2Ze1XSY3lvL4tLIyrwHSKjf/Qhrl49 soFryww6GrUOeiMiaGY4tdIgTp6bO6JJh8YT4/ngSrYXkM4C7KHRyT7cUu5Dsm3z5nd3 LeEKpQd14HvEYKXzc4QO0TLW7IkXHX21iDUxE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rs/TiD4LBFiJxoXhLbhCH3XjxaQMD7w8zxJrxXtvSJk=; b=JcqQMohF5R290YqWS5xUcuFIjz+3AI284XBLnXXckjDO71nyq3DK7n3/bV8Pa9tweE sK+Tk3dg+NqPe3L2miltXzGuvSu3cpDsnO5sA1UMvooOxfDijpXNusmS9As4IG/Hp5hc 0rsMnTuViFwzVMYUQ/l593M1vWk4+Xz2PE7kNfvoHRFjV8HRgZbkP7bMRd/lIgWuxa8M UwbXmQCpDB07F195qDgUGG1E1Cgii3637euAoHb86/v1x8B2m4PZ0w8DDDNZL8ex2Nk/ HzXGgDa/Gi5aCRitmjBCqjCFjY9vBj1yb6DMaxR/P5mcG+gv9M8Rip/Gz9f7egGQyQ3f uuiA== X-Gm-Message-State: AHPjjUjXn0QyEI5sox84DWzq/7OKpZHnXePEt9hXjB2pbzWO2BQjlGLl kvgoJG/y3wPQveGUuoCiXQ== X-Google-Smtp-Source: ADKCNb4mh2FHs8TagQ8T/n65yexwepNOZLXpD3v0pYwyTEuh0LBslo4mFJbwS8qSIj1mMjNW3oZfhA== X-Received: by 10.98.223.88 with SMTP id u85mr1589805pfg.219.1504764218280; Wed, 06 Sep 2017 23:03:38 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id s1sm2186650pfk.27.2017.09.06.23.03.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 23:03:37 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Chris Lew Subject: [PATCH 4/7] net: qrtr: Pass source and destination to enqueue functions Date: Wed, 6 Sep 2017 23:03:26 -0700 Message-Id: <20170907060329.32402-5-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170907060329.32402-1-bjorn.andersson@linaro.org> References: <20170907060329.32402-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Defer writing the message header to the skb until its time to enqueue the packet. As the receive path is reworked to decode the message header as it's received from the transport and only pass around the payload in the skb this change means that we do not have to fill out the full message header just to decode it immediately in qrtr_local_enqueue(). In the future this change also makes it possible to prepend message headers based on the version of each link. Signed-off-by: Bjorn Andersson --- net/qrtr/qrtr.c | 120 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 69 insertions(+), 51 deletions(-) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index fac7cd6ea445..bcec2432b833 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -97,8 +97,12 @@ struct qrtr_node { struct list_head item; }; -static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb); -static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb); +static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to); +static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to); /* Release node resources and free the node. * @@ -136,10 +140,27 @@ static void qrtr_node_release(struct qrtr_node *node) } /* Pass an outgoing packet socket buffer to the endpoint driver. */ -static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb) +static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to) { + struct qrtr_hdr *hdr; + size_t len = skb->len; int rc = -ENODEV; + hdr = skb_push(skb, QRTR_HDR_SIZE); + hdr->version = cpu_to_le32(QRTR_PROTO_VER); + hdr->type = cpu_to_le32(type); + hdr->src_node_id = cpu_to_le32(from->sq_node); + hdr->src_port_id = cpu_to_le32(from->sq_port); + hdr->dst_node_id = cpu_to_le32(to->sq_node); + hdr->dst_port_id = cpu_to_le32(to->sq_port); + + hdr->size = cpu_to_le32(len); + hdr->confirm_rx = 0; + + skb_put_padto(skb, ALIGN(len, 4)); + mutex_lock(&node->ep_lock); if (node->ep) rc = node->ep->xmit(node->ep, skb); @@ -237,23 +258,13 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_post); static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, u32 src_node, u32 dst_node) { - struct qrtr_hdr *hdr; struct sk_buff *skb; skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL); if (!skb) return NULL; - skb_reset_transport_header(skb); - hdr = skb_put(skb, QRTR_HDR_SIZE); - hdr->version = cpu_to_le32(QRTR_PROTO_VER); - hdr->type = cpu_to_le32(type); - hdr->src_node_id = cpu_to_le32(src_node); - hdr->src_port_id = cpu_to_le32(QRTR_PORT_CTRL); - hdr->confirm_rx = cpu_to_le32(0); - hdr->size = cpu_to_le32(pkt_len); - hdr->dst_node_id = cpu_to_le32(dst_node); - hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL); + skb_reserve(skb, QRTR_HDR_SIZE); return skb; } @@ -326,6 +337,8 @@ static void qrtr_port_put(struct qrtr_sock *ipc); static void qrtr_node_rx_work(struct work_struct *work) { struct qrtr_node *node = container_of(work, struct qrtr_node, work); + struct sockaddr_qrtr dst; + struct sockaddr_qrtr src; struct sk_buff *skb; while ((skb = skb_dequeue(&node->rx_queue)) != NULL) { @@ -341,6 +354,11 @@ static void qrtr_node_rx_work(struct work_struct *work) dst_port = le32_to_cpu(phdr->dst_port_id); confirm = !!phdr->confirm_rx; + src.sq_node = src_node; + src.sq_port = le32_to_cpu(phdr->src_port_id); + dst.sq_node = dst_node; + dst.sq_port = dst_port; + qrtr_node_assign(node, src_node); ipc = qrtr_port_lookup(dst_port); @@ -357,7 +375,9 @@ static void qrtr_node_rx_work(struct work_struct *work) skb = qrtr_alloc_resume_tx(dst_node, node->nid, dst_port); if (!skb) break; - if (qrtr_node_enqueue(node, skb)) + + if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, + &dst, &src)) break; } } @@ -407,6 +427,8 @@ EXPORT_SYMBOL_GPL(qrtr_endpoint_register); void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) { struct qrtr_node *node = ep->node; + struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL}; + struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL}; struct sk_buff *skb; mutex_lock(&node->ep_lock); @@ -416,7 +438,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) /* Notify the local controller about the event */ skb = qrtr_alloc_local_bye(node->nid); if (skb) - qrtr_local_enqueue(NULL, skb); + qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); qrtr_node_release(node); ep->node = NULL; @@ -454,11 +476,17 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) { struct sk_buff *skb; int port = ipc->us.sq_port; + struct sockaddr_qrtr to; + + to.sq_family = AF_QIPCRTR; + to.sq_node = QRTR_NODE_BCAST; + to.sq_port = QRTR_PORT_CTRL; skb = qrtr_alloc_del_client(&ipc->us); if (skb) { skb_set_owner_w(skb, &ipc->sk); - qrtr_bcast_enqueue(NULL, skb); + qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, + &to); } if (port == QRTR_PORT_CTRL) @@ -606,19 +634,25 @@ static int qrtr_bind(struct socket *sock, struct sockaddr *saddr, int len) } /* Queue packet to local peer socket. */ -static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb) +static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to) { - const struct qrtr_hdr *phdr; struct qrtr_sock *ipc; + struct qrtr_hdr *phdr; - phdr = (const struct qrtr_hdr *)skb_transport_header(skb); - - ipc = qrtr_port_lookup(le32_to_cpu(phdr->dst_port_id)); + ipc = qrtr_port_lookup(to->sq_port); if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ kfree_skb(skb); return -ENODEV; } + phdr = skb_push(skb, QRTR_HDR_SIZE); + skb_reset_transport_header(skb); + + phdr->src_node_id = cpu_to_le32(from->sq_node); + phdr->src_port_id = cpu_to_le32(from->sq_port); + if (sock_queue_rcv_skb(&ipc->sk, skb)) { qrtr_port_put(ipc); kfree_skb(skb); @@ -631,7 +665,9 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb) } /* Queue packet for broadcast. */ -static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb) +static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + int type, struct sockaddr_qrtr *from, + struct sockaddr_qrtr *to) { struct sk_buff *skbn; @@ -641,11 +677,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb) if (!skbn) break; skb_set_owner_w(skbn, skb->sk); - qrtr_node_enqueue(node, skbn); + qrtr_node_enqueue(node, skbn, type, from, to); } mutex_unlock(&qrtr_node_lock); - qrtr_local_enqueue(node, skb); + qrtr_local_enqueue(node, skb, type, from, to); return 0; } @@ -653,13 +689,14 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb) static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); - int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *); + int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int, + struct sockaddr_qrtr *, struct sockaddr_qrtr *); struct qrtr_sock *ipc = qrtr_sk(sock->sk); struct sock *sk = sock->sk; struct qrtr_node *node; - struct qrtr_hdr *hdr; struct sk_buff *skb; size_t plen; + u32 type = QRTR_TYPE_DATA; int rc; if (msg->msg_flags & ~(MSG_DONTWAIT)) @@ -713,32 +750,14 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) if (!skb) goto out_node; - skb_reset_transport_header(skb); - skb_put(skb, len + QRTR_HDR_SIZE); - - hdr = (struct qrtr_hdr *)skb_transport_header(skb); - hdr->version = cpu_to_le32(QRTR_PROTO_VER); - hdr->src_node_id = cpu_to_le32(ipc->us.sq_node); - hdr->src_port_id = cpu_to_le32(ipc->us.sq_port); - hdr->confirm_rx = cpu_to_le32(0); - hdr->size = cpu_to_le32(len); - hdr->dst_node_id = cpu_to_le32(addr->sq_node); - hdr->dst_port_id = cpu_to_le32(addr->sq_port); + skb_reserve(skb, QRTR_HDR_SIZE); - rc = skb_copy_datagram_from_iter(skb, QRTR_HDR_SIZE, - &msg->msg_iter, len); + rc = memcpy_from_msg(skb_put(skb, len), msg, len); if (rc) { kfree_skb(skb); goto out_node; } - if (plen != len) { - rc = skb_pad(skb, plen - len); - if (rc) - goto out_node; - skb_put(skb, plen - len); - } - if (ipc->us.sq_port == QRTR_PORT_CTRL) { if (len < 4) { rc = -EINVAL; @@ -747,12 +766,11 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) } /* control messages already require the type as 'command' */ - skb_copy_bits(skb, QRTR_HDR_SIZE, &hdr->type, 4); - } else { - hdr->type = cpu_to_le32(QRTR_TYPE_DATA); + skb_copy_bits(skb, 0, &type, 4); + type = le32_to_cpu(type); } - rc = enqueue_fn(node, skb); + rc = enqueue_fn(node, skb, type, &ipc->us, addr); if (rc >= 0) rc = len; From patchwork Thu Sep 7 06:03:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 111856 Delivered-To: patch@linaro.org Received: by 10.140.94.239 with SMTP id g102csp356765qge; Wed, 6 Sep 2017 23:03:46 -0700 (PDT) X-Received: by 10.99.100.4 with SMTP id y4mr1594890pgb.147.1504764226669; Wed, 06 Sep 2017 23:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504764226; cv=none; d=google.com; s=arc-20160816; b=CwN5o7NG6j4Y054rJQRZXMWakv+jKgfYJtUpKSMzj8hNYtUU6Y4lq0+qnaHQnaI8uG IxlD4s+cs4dk6LUAeAZxANbB8/1GONj6km4rvyX2YP2m+iiVSSObMNOECXEJnaRWlQMP N1AwW2SzsxAOmVEV5LOSEAMXpBToYZRaCQADLgIRdl+3/ZGD1ookUis5pDKfcYRFNXTA xTfYY5N50KjWCaypmQF5Wgxveq29QiitdC66sAnjL0WkgnrD1IJRFI0dDWFlBzpMpeiP K6eAvr4ohXOQEVDFujY2IywljKPqjlGGOMcVp+0gnip0Q28wQD8nEbSIqpKSviqvo8FQ 3/+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=M5LNnd2dxJDJRxZCLUuOEe3ps2Ag9SoXuQay1gipq6w=; b=y512+J5b3gUP+T2Aw3BEV50NiqysJyPxESFYSrj5vcupYSMMzlrkXc/mfNwpnxOHBy zThgjmJsy/btXFEus4wPwEXMkjrQBeHFy4bcvFHViZzigt3g9MQ7clGzOfyCnru/gYcF mbZcgzj2BGw8CIYLgAwSk9H39DfFV3+iQRJCxEx1pltDUMdWH2LAbZKf7sBeNK6LuPM6 vT690Mq1KeJ84LgGWLpL7FQafjgGUBkPRFQwiYk6rpWiBkuMUvdDO3Tv+UR8npuo0rDz s7JsbjxFGHPclRbamlMVRBpI4tyvuuXkrC6SkBJT5pov5gDSH7BVTailwKwXq+XjBJFr zIUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KL99S8ED; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u189si1293523pgb.161.2017.09.06.23.03.46; Wed, 06 Sep 2017 23:03:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KL99S8ED; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754024AbdIGGDl (ORCPT + 9 others); Thu, 7 Sep 2017 02:03:41 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:34607 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754018AbdIGGDk (ORCPT ); Thu, 7 Sep 2017 02:03:40 -0400 Received: by mail-pg0-f54.google.com with SMTP id q68so3394527pgq.1 for ; Wed, 06 Sep 2017 23:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PArY59lIP4ZSAJXU+tDGGdjXKm4RhjsqdGDEnt3VAhk=; b=KL99S8EDl1wGZcF2OyCFdwc2e/S0mkD5wCfsVIAO39HeZbz+Zmw3MKIiGLidJl9gKi VwuOs44McIZ2t8ZoweBpVDtWzMv4hFtxHa1D3MUExFLXgw/MWvspHx7id5HOfN4S+rrZ y3I2XTSqk1zKG1rUN6lQDqF87zbN4gZYCRpkA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PArY59lIP4ZSAJXU+tDGGdjXKm4RhjsqdGDEnt3VAhk=; b=NcsnwIr4Tmaolu5MSEsDl8qgcoo8MclE5YeaYRvBXX4ejCSYsGLQShQ/XxVW/iwHt4 ppX5F4Kq8m0pOiJ6i1EouTfQ9n0u5y0RyrCAQv5iLGAEureppnEUnWNKKrOaeconvLc2 f+e9zwt53sidy8mm472dGFTn0TTISqeAzIbKfkByLTvVstqmW6VYftnfXJltqtaOTSEq b+cTLjShElatK1r784sBfIi2TObLIoj3q9KbpZUnKpLHy7noZm7Aa6mcqdY0K2sLTNua ehRDIl3/f9IOpPtPFp4AvTamRHBLKffv0LqV8w+kmkyIfQKf/GcdZF8w3V8tkbmLN88E +5pw== X-Gm-Message-State: AHPjjUhJhmc+JYwqz7/WFqV4+VuwCuLfKjL3X5K87Mt1iBMjeVwaHN4G qanYC5K6BATIVP5g X-Google-Smtp-Source: ADKCNb4i8uxLGBJJrW12oYYHdKO5pUZNkOFquw/cyaFOLRuWBPAxHBVWXR20Yvw3/gRF2mWxGkggPQ== X-Received: by 10.98.208.69 with SMTP id p66mr1665105pfg.6.1504764219466; Wed, 06 Sep 2017 23:03:39 -0700 (PDT) Received: from localhost.localdomain (ip68-111-217-79.sd.sd.cox.net. [68.111.217.79]) by smtp.gmail.com with ESMTPSA id s1sm2186650pfk.27.2017.09.06.23.03.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2017 23:03:38 -0700 (PDT) From: Bjorn Andersson To: "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Chris Lew Subject: [PATCH 5/7] net: qrtr: Clean up control packet handling Date: Wed, 6 Sep 2017 23:03:27 -0700 Message-Id: <20170907060329.32402-6-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170907060329.32402-1-bjorn.andersson@linaro.org> References: <20170907060329.32402-1-bjorn.andersson@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org As the message header generation is deferred the internal functions for generating control packets can be simplified. This patch modifies qrtr_alloc_ctrl_packet() to, in addition to the sk_buff, return a reference to a struct qrtr_ctrl_pkt, which clarifies and simplifies the helpers to the point that these functions can be folded back into the callers. Signed-off-by: Bjorn Andersson --- net/qrtr/qrtr.c | 93 ++++++++++++++++++--------------------------------------- 1 file changed, 29 insertions(+), 64 deletions(-) -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/qrtr/qrtr.c b/net/qrtr/qrtr.c index bcec2432b833..f28ecd7d735b 100644 --- a/net/qrtr/qrtr.c +++ b/net/qrtr/qrtr.c @@ -255,9 +255,18 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) } EXPORT_SYMBOL_GPL(qrtr_endpoint_post); -static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, - u32 src_node, u32 dst_node) +/** + * qrtr_alloc_ctrl_packet() - allocate control packet skb + * @pkt: reference to qrtr_ctrl_pkt pointer + * + * Returns newly allocated sk_buff, or NULL on failure + * + * This function allocates a sk_buff large enough to carry a qrtr_ctrl_pkt and + * on success returns a reference to the control packet in @pkt. + */ +static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt) { + const int pkt_len = sizeof(struct qrtr_ctrl_pkt); struct sk_buff *skb; skb = alloc_skb(QRTR_HDR_SIZE + pkt_len, GFP_KERNEL); @@ -265,64 +274,7 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(u32 type, size_t pkt_len, return NULL; skb_reserve(skb, QRTR_HDR_SIZE); - - return skb; -} - -/* Allocate and construct a resume-tx packet. */ -static struct sk_buff *qrtr_alloc_resume_tx(u32 src_node, - u32 dst_node, u32 port) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_RESUME_TX, pkt_len, - src_node, dst_node); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_RESUME_TX); - buf[1] = cpu_to_le32(src_node); - buf[2] = cpu_to_le32(port); - - return skb; -} - -/* Allocate and construct a BYE message to signal remote termination */ -static struct sk_buff *qrtr_alloc_local_bye(u32 src_node) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_BYE, pkt_len, - src_node, qrtr_local_nid); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_BYE); - - return skb; -} - -static struct sk_buff *qrtr_alloc_del_client(struct sockaddr_qrtr *sq) -{ - const int pkt_len = 20; - struct sk_buff *skb; - __le32 *buf; - - skb = qrtr_alloc_ctrl_packet(QRTR_TYPE_DEL_CLIENT, pkt_len, - sq->sq_node, QRTR_NODE_BCAST); - if (!skb) - return NULL; - - buf = skb_put_zero(skb, pkt_len); - buf[0] = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); - buf[1] = cpu_to_le32(sq->sq_node); - buf[2] = cpu_to_le32(sq->sq_port); + *pkt = skb_put_zero(skb, pkt_len); return skb; } @@ -337,6 +289,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc); static void qrtr_node_rx_work(struct work_struct *work) { struct qrtr_node *node = container_of(work, struct qrtr_node, work); + struct qrtr_ctrl_pkt *pkt; struct sockaddr_qrtr dst; struct sockaddr_qrtr src; struct sk_buff *skb; @@ -372,10 +325,14 @@ static void qrtr_node_rx_work(struct work_struct *work) } if (confirm) { - skb = qrtr_alloc_resume_tx(dst_node, node->nid, dst_port); + skb = qrtr_alloc_ctrl_packet(&pkt); if (!skb) break; + pkt->cmd = cpu_to_le32(QRTR_TYPE_RESUME_TX); + pkt->client.node = cpu_to_le32(dst.sq_node); + pkt->client.port = cpu_to_le32(dst.sq_port); + if (qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &dst, &src)) break; @@ -429,6 +386,7 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) struct qrtr_node *node = ep->node; struct sockaddr_qrtr src = {AF_QIPCRTR, node->nid, QRTR_PORT_CTRL}; struct sockaddr_qrtr dst = {AF_QIPCRTR, qrtr_local_nid, QRTR_PORT_CTRL}; + struct qrtr_ctrl_pkt *pkt; struct sk_buff *skb; mutex_lock(&node->ep_lock); @@ -436,9 +394,11 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) mutex_unlock(&node->ep_lock); /* Notify the local controller about the event */ - skb = qrtr_alloc_local_bye(node->nid); - if (skb) + skb = qrtr_alloc_ctrl_packet(&pkt); + if (skb) { + pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE); qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); + } qrtr_node_release(node); ep->node = NULL; @@ -474,6 +434,7 @@ static void qrtr_port_put(struct qrtr_sock *ipc) /* Remove port assignment. */ static void qrtr_port_remove(struct qrtr_sock *ipc) { + struct qrtr_ctrl_pkt *pkt; struct sk_buff *skb; int port = ipc->us.sq_port; struct sockaddr_qrtr to; @@ -482,8 +443,12 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) to.sq_node = QRTR_NODE_BCAST; to.sq_port = QRTR_PORT_CTRL; - skb = qrtr_alloc_del_client(&ipc->us); + skb = qrtr_alloc_ctrl_packet(&pkt); if (skb) { + pkt->cmd = cpu_to_le32(QRTR_TYPE_DEL_CLIENT); + pkt->client.node = cpu_to_le32(ipc->us.sq_node); + pkt->client.port = cpu_to_le32(ipc->us.sq_port); + skb_set_owner_w(skb, &ipc->sk); qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, &to);