From patchwork Tue Oct 29 11:45:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 3612 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 4A1283F380 for ; Tue, 29 Oct 2024 12:46:36 +0100 (CET) Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2fb6261384asf37674041fa.0 for ; Tue, 29 Oct 2024 04:46:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730202395; cv=pass; d=google.com; s=arc-20240605; b=JLtIlaCc+PAHPIUOsNHowtlW2rIXKQ5+CVOSxbxo19kTT1JnRfW9bVVHz95kAkY2Gs w87+0QS5EiBUtW+nML31tYE3mq76FqLf+i9Bn/lZIraX3HiFmpiWgcftRSsle8wukqQK 8UyJc6DdPu7CHetrCgZ4sC+WNNRWwX8LLa3Vg5AEUY+4Yh2IigOUnO6yTHNwEtMYbl++ JIGP/R9262/Nn538Rf8yyUVmW2JGOU/n0A+ddu3TV2BPB3ECJf2Oukn52oXmIF5v7EEt WbrIlddObBJxtuopQz05TH0vx2nbARRY0sxbsnJ6W56oJZEdj1n1eBR5GvYqAIprV8XX eyvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=+57Jq/zn+TLooGg2zBbludOM6jzDu3c47Jh7HKSONj8=; fh=rSGpMMEUipcgQPL8rn69J7kvyLCORf0Bg+Q3TbJibC4=; b=htL2aYdMaR40PVxJNYCATddoWAlA2dWsqLvvVgeh9WEFRUbIFHW9xPQe7QEU0jxAiq U3/xdoEbOZWO9hHi0u5ykkqLJv+ro5RdNfbBQYMDze2193Yn+yuS8cf+nCECqIkEa6z7 o4CnFrjtSkNrDVvzv9wrVLXPrILTRapRFAj3Kh/dQ+q1ha93a/F3L83ZrcjNwi1KjFC7 KKwMI5K76LoOCVBZ81ggVXxiRUalK9d3zLE/EYEb+xjuweq5gXbImMKbMSdjMf4qWFUu tA2a5PkLtBUwI+go0ArhmaAB5gezOkhnx1kgRowyyOU/uKKWD4qTY0CX4vvIsruLEozn enmQ==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ewM15Hv+; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1730202395; x=1730807195; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=+57Jq/zn+TLooGg2zBbludOM6jzDu3c47Jh7HKSONj8=; b=i6C6RmrSHZI5HfU9XxAlAKXdTtkMxDgMP8Co3toiby4D6pvnbN80Y8zOPv6hrcxKrD RwdvpHiyc498lcX5KA9qiq1L8nnWMhWgYzcHD4lgQNsNbMUVv9cHa04hJg9IBNnjD9/S pqg4Or452QrCUC38t9H2Y9UZ4MoVfir8ynUGw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730202395; x=1730807195; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+57Jq/zn+TLooGg2zBbludOM6jzDu3c47Jh7HKSONj8=; b=Yn53xdEpz9uNTw2EE3y3o4j4d98G6al2vko+KFLcaOf32mBGQWN4gDYk8LISUAkLBK 8f6Tx3qVyxgOkYn7FJbJE1ghmBiEXJnsrxIbPOSHobxbGK/GPPd89SOdMfklS6MtV1sG nM6fi7TUIEMLM/JZdwoSLJ9gALm6PxjaUMNjdv/NymK0TLqTgTB0b1e9k7Pv8N4DqZqh uo4v9W1yfxHgQ+4RPA4XiKtPMw30qSSV655Dq1TfmjaiOm65DpuVTvnNgXuvyQ5V631r W4K9WrpNk2aGKTmvmk9CWYsUopx4LQBNIxDyyjtmyGBdpopgVUbyVkhBAh6Lb4HsAE40 Wzng== X-Forwarded-Encrypted: i=2; AJvYcCUm3o9Oh01bRxvcF99B3eB94fm28AQb+9Jj6gKmSx3us2aX+LQU6J/0ugjB9M94dYP3cg0+sNXCPoctxZA8@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0Yz9x7zkX3Dqm0vAZQElIatih9V6drBBnJuKCbg1sRSJGay2Owt3 vsLa1LkciQMZV3wfRMiY+4NWKdP1JiB4VLTZGZNVhmogwBNOR9IvFaTk+JSgHP5//Q== X-Google-Smtp-Source: AGHT+IF3RIkyirmuq56eW7pxZUkTikvipQBbyFOSzxYTJr1UpEbGz4mATo6fwDEZd1/ewTU6o+vNBQ== X-Received: by 2002:a2e:74f:0:b0:2fb:382e:410b with SMTP id 38308e7fff4ca-2fcbe0526a1mr43450731fa.32.1730202395385; Tue, 29 Oct 2024 04:46:35 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a50:8712:0:b0:5cb:def3:f877 with SMTP id 4fb4d7f45d1cf-5cbdef3fd4bls74417a12.1.-pod-prod-01-eu; Tue, 29 Oct 2024 04:46:34 -0700 (PDT) X-Received: by 2002:a17:907:7f14:b0:a9a:6284:91ef with SMTP id a640c23a62f3a-a9de5c94537mr963823766b.2.1730202393740; Tue, 29 Oct 2024 04:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1730202393; cv=none; d=google.com; s=arc-20240605; b=Zy3hhDR8o3GEdtZw+FG/lmw9V82F6Lj0b7HMWbL23VNKI+5IZZtv2U4Pjkfg6yK17V KFCuJhfblYhpc/dAHG73+m3gNPJL+HnF5tVwTUIw5BWT6Y2WaTKjJczJNkYo0EFKpJGI oaHTp5ush+pStuIDLs2DRIGQvErDmJXxK/ewYCPOOB3x7VKHiewxCobr5knyAe5gKDmP lgVopM4F283vq8bi1wkMZKrkuNtgdkQcXRITVCT72BIIwRJdA1W1rTYRKwLvSs5Imi0N CIF68Eqsw0UEpTYnHje2t6DpUzgV5xHgVJJwgSK3/W9EX0c/hJFBUUBQQ0GbWDAAWNWS Gz2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Nbw+NGEXr7m2rV0cbMmuavLOG9IUHHd4c12xVVX95f4=; fh=ljoFiwPup6gC9YG4NMWOEWNdgUd1CKjWIIwpUvYy39c=; b=jpNDrrDhOhbu39iehLi1r6DDQG5LolAQcYSzXdrf5OaGQZqeSH1RuKFuQ5vznLKYzr fNiEvE+Fpkhwtpxr4rPBo6YMVfKRmG/8663/nTv9g0OSwWNwyKQSRUyCsvWF7iyI2uIS J+929ArefXMbXyZMvdQ/9k1xVVAPJ4N6kmuJV0Hva9NOGszP3Q0mCi+tqd8VKjcVD4eW RfxERBX3XttniDEh/GNcgYlnAAEBdBnaS2b2ScOcaj5NFS8qAIelU/ydh1ddPk8AljPP LCGByDG/n/Qvnu9V0at5JzuG1amypJRdSWEmUT4xgxORrFAX4gGkutq9mZS6No+C/stG WPZQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ewM15Hv+; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id a640c23a62f3a-a9b1f028910sor377557266b.7.2024.10.29.04.46.33 for (Google Transport Security); Tue, 29 Oct 2024 04:46:33 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a05:6402:3787:b0:5c8:95ce:8cc2 with SMTP id 4fb4d7f45d1cf-5cbbf8b20c8mr8968166a12.16.1730202393242; Tue, 29 Oct 2024 04:46:33 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.. ([2.196.41.207]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cbb6297a09sm3869301a12.21.2024.10.29.04.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 04:46:32 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: linux-amarula@amarulasolutions.com, Dario Binacchi , Marc Kleine-Budde , Vincent Mailhol , linux-can@vger.kernel.org Subject: [RFC PATCH v3 3/6] can: dev: add helpers to setup an error frame Date: Tue, 29 Oct 2024 12:45:27 +0100 Message-ID: <20241029114622.2989827-4-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241029114622.2989827-1-dario.binacchi@amarulasolutions.com> References: <20241029114622.2989827-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ewM15Hv+; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , These helpers can prevent errors and code duplication when setting up a CAN error frame. Signed-off-by: Dario Binacchi --- Changes in v3: - Drop the check of "cf" parameter not NULL Changes in v2: - Replace macros with static inline functions - Update the commit message include/linux/can/dev.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h index 0977656b366d..da85c44808d5 100644 --- a/include/linux/can/dev.h +++ b/include/linux/can/dev.h @@ -168,6 +168,43 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *s return can_dropped_invalid_skb(dev, skb); } +static inline void can_frame_error_init(struct can_frame *cf) +{ + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; +} + +static inline void can_frame_set_err_bit0(struct can_frame *cf) +{ + cf->data[2] |= CAN_ERR_PROT_BIT0; +} + +static inline void can_frame_set_err_bit1(struct can_frame *cf) +{ + cf->data[2] |= CAN_ERR_PROT_BIT1; +} + +static inline void can_frame_set_err_ack(struct can_frame *cf) +{ + cf->can_id |= CAN_ERR_ACK; + cf->data[3] = CAN_ERR_PROT_LOC_ACK; +} + +static inline void can_frame_set_err_crc(struct can_frame *cf) +{ + cf->data[2] |= CAN_ERR_PROT_BIT; + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; +} + +static inline void can_frame_set_err_form(struct can_frame *cf) +{ + cf->data[2] |= CAN_ERR_PROT_FORM; +} + +static inline void can_frame_set_err_stuff(struct can_frame *cf) +{ + cf->data[2] |= CAN_ERR_PROT_STUFF; +} + void can_setup(struct net_device *dev); struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,