From patchwork Thu Nov 23 10:41:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arend van Spriel X-Patchwork-Id: 10072621 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE2F1602DC for ; Thu, 23 Nov 2017 10:41:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE5A229F76 for ; Thu, 23 Nov 2017 10:41:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2D0F29F79; Thu, 23 Nov 2017 10:41:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C15C29F76 for ; Thu, 23 Nov 2017 10:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752556AbdKWKl1 (ORCPT ); Thu, 23 Nov 2017 05:41:27 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:43706 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752495AbdKWKlZ (ORCPT ); Thu, 23 Nov 2017 05:41:25 -0500 Received: by mail-qt0-f193.google.com with SMTP id w10so15396953qtb.10 for ; Thu, 23 Nov 2017 02:41:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=2Etj5muRRhAnsZgiOCJ2Q1V6nIpMJUNXS6Gg7h9gGR0=; b=KFj8K4V5tanZ1O3Px3oMoifGiTt05IMlcmz6+nJcXItAin+OM4bNi2iNNTu/PPN8G1 Vu/7pTVqDdqgblFcoewplKMnFpGtn5X15mvKBEsI913HrLI3M0r0EpNFatXDW6inpAf8 rbdqYcNkkHNpolyR+I1BrZMLlIqSLTQf16VeA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=2Etj5muRRhAnsZgiOCJ2Q1V6nIpMJUNXS6Gg7h9gGR0=; b=MTCJLu2iOikbu4XBecQXlpXLtTP0io0/hyXoVm/M/BK2u9GYzNSXEMrVCaCHEzWUWm o15T6/eAh4jRGaBg7Oo/Yvn2Wpadoh38mZa9nHvTGfMPQCiKQX09uVMx3vxcdFPNHaIl RKKAkD600uT/0B8C46djNS+8gTNB4Pvd/qvQ/G6JWYTuSR3qbvsvxeYfNEo6Y2jG565z UJHU/pCBXVf+FwhMal6SYC0HQyGEuC0kF60Lzv8hC3mBQa9MFEns0f93HvMeSzRX0Kfx fyyMnVzJyq9EBkFqmEwTCMENUDjVqYGmeM0e8SQLC2eabyQ+1i65jz47ayJRs0Q87wIM hNJg== X-Gm-Message-State: AJaThX6z2Owu5md2uKaNf7+rkV2K9Y6ih0kic4nV28BnF86IVa08DPBm EFBOye2louuY/GnzArvJgfQcrg== X-Google-Smtp-Source: AGs4zMYovH3gIavoR0gzyne6mqHa4VLfGN5C7AWpMaVP/pbv639McfHOGXMlHJg1ptjPbL9iOgHAQQ== X-Received: by 10.200.44.187 with SMTP id 56mr38654878qtw.238.1511433684447; Thu, 23 Nov 2017 02:41:24 -0800 (PST) Received: from [10.176.68.125] ([192.19.248.250]) by smtp.gmail.com with ESMTPSA id 33sm8841001qts.76.2017.11.23.02.41.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 02:41:23 -0800 (PST) Subject: Re: [PATCH] brcmfmac: transfer firmware error to Linux error code in fwil To: Wright Feng , franky.lin@broadcom.com, hante.meuleman@broadcom.com, kvalo@codeaurora.org, chi-hsien.lin@cypress.com References: <1511341876-10198-1-git-send-email-wright.feng@cypress.com> Cc: linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com From: Arend van Spriel Message-ID: <5A16A5D2.8020600@broadcom.com> Date: Thu, 23 Nov 2017 11:41:22 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: <1511341876-10198-1-git-send-email-wright.feng@cypress.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 11/22/2017 10:11 AM, Wright Feng wrote: > fil_cmd_data_set and fil_cmd_data_get return proprietary error code > when getting error from firmware layer. The vendor tools or utilities > that uses libnl may stuck in some commands when wl is down. > For example, issue "scan" command after issuing "down" command, the > "scan" command will be the blocking call and stuck as no response from > libnl. It is caused by that firmware returns BCME_NOTUP(-4) when wl > is down, but the -4 is -EINTR in Linux kernel, so libnl catches the > error and not passes to upper layer. > Because of that, the fwil should return Linux error code instead of > the proprietary error code, and the tools or utilities should get the > real firmware error code by command "bcmerror" or "bcmerrorstr" after > receiving the error from libnl. Hi Wright, I recall you had a discussion (on the wireless list?) with Franky about this, but I did not chime in at that time. I am not a proponent for mapping our firmware errors to linux errors. It is tempting to do so because there is clear overlap for some, but still it is quirky and has no value in my opinion. This issue was already addressed in the past although not specifically for fixing the -EINTR case. I did some digging in the git history. Here was my original change: commit 9c6476668025e76a8365be783f2649fe3259b91c Author: Arend van Spriel Date: Tue Oct 28 14:56:09 2014 +0100 brcmfmac: do not use firmware error code in driver Passing the firmware error codes up the driver may be mapped to linux error numbers which may impact proper fault analysis. So better pass up a generic failure code, ie. -EBADE and only show firmware error code in FIL debug message. Reviewed-by: Franky (Zhenhui) Lin Reviewed-by: Hante Meuleman Reviewed-by: Daniel (Deognyoun) Kim Reviewed-by: Pieter-Paul Giesberts Signed-off-by: Arend van Spriel Signed-off-by: John W. Linville The idea here was to have a single error code and have a debug message showing the firmware error string. This single error code could be used by vendor tools (not really an upstream concern) to query the driver for the firmware error code through a vendor specific command. Now what happened is that Hante while inspecting logs with only error messages observed -EBADE and wanted to know firmware error. So he made the following patch a year later: commit 21000b3f3da45a5a33de3815f3c2b3584102960e Author: Hante Meuleman Date: Wed Nov 25 11:32:38 2015 +0100 brcmfmac: Return actual error by fwil. FWIL is always mapping back errors to EBADE. This is not very conventient when trying to understand problems by reading logs. Some callers print the error code, but that is quite useless when the exact error code is not returned. It also makes it impossible to differentiate based on error code. This patch changes the return of EBADE into the actual error code. Reviewed-by: Arend Van Spriel Reviewed-by: Franky (Zhenhui) Lin Reviewed-by: Pieter-Paul Giesberts Signed-off-by: Hante Meuleman Signed-off-by: Arend van Spriel Signed-off-by: Kalle Valo However, the consequence of this was that we ended up returning firmware error codes into the kernel domain and user-space. Below the change I came up with. Let me know what you think. Regards, Arend ---8<-------------------------------------------------------- commit e340892a4bb5a74248b19504bb972497d38a4a03 Author: Arend van Spriel Date: Thu Nov 23 11:13:41 2017 +0100 brcmfmac: separate firmware errors from i/o errors When using the firmware api it can fail simply because firmware does not like the request or it fails due to issues in the host interface. Currently, there is only a single error code which is confusing. So adding a parameter to pass the firmware error separately and in case of a firmware error always return -EBADE to user-space. Reviewed-by: Hante Meuleman Reviewed-by: Pieter-Paul Giesberts Reviewed-by: Franky Lin Signed-off-by: Arend van Spriel static inline int brcmf_proto_tx_queue_data(struct brcmf_pub *drvr, int ifidx, diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c index 9f2d0b0..353ed28 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcdc.c @@ -165,7 +165,7 @@ static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) static int brcmf_proto_bcdc_query_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd, - void *buf, uint len) + void *buf, uint len, int *fwerr) { struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; @@ -175,6 +175,7 @@ static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len); + *fwerr = 0; ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, false); if (ret < 0) { brcmf_err("brcmf_proto_bcdc_msg failed w/status %d\n", @@ -211,17 +212,18 @@ static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) memcpy(buf, info, len); } + ret = 0; + /* Check the ERROR flag */ if (flags & BCDC_DCMD_ERROR) - ret = le32_to_cpu(msg->status); - + *fwerr = le32_to_cpu(msg->status); done: return ret; } static int brcmf_proto_bcdc_set_dcmd(struct brcmf_pub *drvr, int ifidx, uint cmd, - void *buf, uint len) + void *buf, uint len, int *fwerr) { struct brcmf_bcdc *bcdc = (struct brcmf_bcdc *)drvr->proto->pd; struct brcmf_proto_bcdc_dcmd *msg = &bcdc->msg; @@ -230,6 +232,7 @@ static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) brcmf_dbg(BCDC, "Enter, cmd %d len %d\n", cmd, len); + *fwerr = 0; ret = brcmf_proto_bcdc_msg(drvr, ifidx, cmd, buf, len, true); if (ret < 0) goto done; @@ -251,7 +254,7 @@ static int brcmf_proto_bcdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len) /* Check the ERROR flag */ if (flags & BCDC_DCMD_ERROR) - ret = le32_to_cpu(msg->status); + *fwerr = le32_to_cpu(msg->status); done: return ret; diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c index f6a2df9..688f256 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwil.c @@ -107,7 +107,7 @@ static const char *brcmf_fil_get_errstr(u32 err) brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set) { struct brcmf_pub *drvr = ifp->drvr; - s32 err; + s32 err, fwerr; if (drvr->bus_if->state != BRCMF_BUS_UP) { brcmf_err("bus is down. we have nothing to do.\n"); @@ -117,16 +117,17 @@ static const char *brcmf_fil_get_errstr(u32 err) if (data != NULL) len = min_t(uint, len, BRCMF_DCMD_MAXLEN); if (set) - err = brcmf_proto_set_dcmd(drvr, ifp->ifidx, cmd, data, len); + err = brcmf_proto_set_dcmd(drvr, ifp->ifidx, cmd, + data, len, &fwerr); else - err = brcmf_proto_query_dcmd(drvr, ifp->ifidx, cmd, data, len); - - if (err >= 0) - return 0; - - brcmf_dbg(FIL, "Failed: %s (%d)\n", - brcmf_fil_get_errstr((u32)(-err)), err); + err = brcmf_proto_query_dcmd(drvr, ifp->ifidx, cmd, + data, len, &fwerr); + if (fwerr < 0) { + brcmf_dbg(FIL, "Firmware error: %s (%d)\n", + brcmf_fil_get_errstr((u32)(-fwerr)), fwerr); + err = -EBADE; + } return err; } diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index d2c834c..e212a79 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -477,7 +477,7 @@ static void brcmf_msgbuf_ioctl_resp_wake(struct brcmf_msgbuf *msgbuf) static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx, - uint cmd, void *buf, uint len) + uint cmd, void *buf, uint len, int *fwerr) { struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; struct sk_buff *skb = NULL; @@ -485,6 +485,7 @@ static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx, int err; brcmf_dbg(MSGBUF, "ifidx=%d, cmd=%d, len=%d\n", ifidx, cmd, len); + *fwerr = 0; msgbuf->ctl_completed = false; err = brcmf_msgbuf_tx_ioctl(drvr, ifidx, cmd, buf, len); if (err) @@ -508,14 +509,15 @@ static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx, } brcmu_pkt_buf_free_skb(skb); - return msgbuf->ioctl_resp_status; + *fwerr = msgbuf->ioctl_resp_status; + return 0; } static int brcmf_msgbuf_set_dcmd(struct brcmf_pub *drvr, int ifidx, - uint cmd, void *buf, uint len) + uint cmd, void *buf, uint len, int *fwerr) { - return brcmf_msgbuf_query_dcmd(drvr, ifidx, cmd, buf, len); + return brcmf_msgbuf_query_dcmd(drvr, ifidx, cmd, buf, len, fwerr); } diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.h index 2404f8a..8a8e08f 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.h +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/proto.h @@ -30,9 +30,9 @@ struct brcmf_proto { int (*hdrpull)(struct brcmf_pub *drvr, bool do_fws, struct sk_buff *skb, struct brcmf_if **ifp); int (*query_dcmd)(struct brcmf_pub *drvr, int ifidx, uint cmd, - void *buf, uint len); + void *buf, uint len, int *fwerr); int (*set_dcmd)(struct brcmf_pub *drvr, int ifidx, uint cmd, void *buf, - uint len); + uint len, int *fwerr); int (*tx_queue_data)(struct brcmf_pub *drvr, int ifidx, struct sk_buff *skb); int (*txdata)(struct brcmf_pub *drvr, int ifidx, u8 offset, @@ -71,14 +71,16 @@ static inline int brcmf_proto_hdrpull(struct brcmf_pub *drvr, bool do_fws, return drvr->proto->hdrpull(drvr, do_fws, skb, ifp); } static inline int brcmf_proto_query_dcmd(struct brcmf_pub *drvr, int ifidx, - uint cmd, void *buf, uint len) + uint cmd, void *buf, uint len, + int *fwerr) { - return drvr->proto->query_dcmd(drvr, ifidx, cmd, buf, len); + return drvr->proto->query_dcmd(drvr, ifidx, cmd, buf, len,fwerr); } static inline int brcmf_proto_set_dcmd(struct brcmf_pub *drvr, int ifidx, - uint cmd, void *buf, uint len) + uint cmd, void *buf, uint len, + int *fwerr) { - return drvr->proto->set_dcmd(drvr, ifidx, cmd, buf, len); + return drvr->proto->set_dcmd(drvr, ifidx, cmd, buf, len, fwerr); }