From patchwork Thu Sep 19 13:52:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 11152437 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC98214ED for ; Thu, 19 Sep 2019 13:54:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B748F21D7E for ; Thu, 19 Sep 2019 13:54:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=silabs.onmicrosoft.com header.i=@silabs.onmicrosoft.com header.b="P+7At+4I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390644AbfISNxs (ORCPT ); Thu, 19 Sep 2019 09:53:48 -0400 Received: from mail-eopbgr700060.outbound.protection.outlook.com ([40.107.70.60]:34912 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2403818AbfISNws (ORCPT ); Thu, 19 Sep 2019 09:52:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mYYZwUEEYnFt7bWEs8RdgbwIeTC75eXLilQuzfem7NLNVm4n98XaLEDd52lojqsx0KYpLYTYPsR45SDxeE9TCMQvRsN0m9fjBBX+UYBQD+l8ThVleH+uhFeccq5s7uSbWs/VAkuXXZPbJEmjMlO6p5D/S7pX3rK8yKMWLePVjfNAO8L7R9W02jMb8CPBQz9dkGSaH/X8fOmrxFiiHmEHA+dm9NJxCQDrqEoh22+/nGUSTcQgCaknvMCbqB7lbtfT3j5qxBERTtrkUHY/K2QCpRYQQJK6n1xiL9Iu4G08i0nDG8YWd45PA99CBZmaYz5SV6V0GGbjBVZ/FVHG5+un2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mjdyvvRksTlhVIpIRffIMgZsQ42ACLLqlz1hRapUSeA=; b=Un0GqvXerhRHLEiqRZ432Q45BJautOY9Ht7Rq0vX3Ji/dh9hoqpyXRMQluYb1yQbm91HC/HjbnnIvUsCiScIwBpIo4AAxdW/7jnv8VOjn/lQnmE1Wr9gkUGcMFtRaYqs5t2OFxow8Fl4jCShSkWwoQ4ti/OcSxc8ookli2+6EnbHHMPpsQgXECHwRa5MqTbSQfbUJ6XBXaHPObjBmWlLrFEQcpyShvQ7anBIyqrK1/Cd66OubAIWfgKLsKES7cefeoRKSf/md9jh6Cpfs3s8LLWY/uSW5PNjqmw8vQ0n4wuKuN6gdW2u5JanzwEhxMKx0shinJYeFQUkxHBtz6NS1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mjdyvvRksTlhVIpIRffIMgZsQ42ACLLqlz1hRapUSeA=; b=P+7At+4IRDwNM3Up3Z/LohYvqdMkv+pCkA32YEWoKFd3XjtC1BWj+LZSmSbY5bR98VVtalkhPGIISL9Fe5YzzCtKQKn/cYuEPOtXK/BIEjpehPqn0ULhhOcMeu5HmFKoZnP+y+HmCaEShXfDja+WiweWHc6fb8axPC1CBsgLwIg= Received: from MN2PR11MB4063.namprd11.prod.outlook.com (20.179.149.217) by MN2PR11MB4400.namprd11.prod.outlook.com (52.135.37.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2263.20; Thu, 19 Sep 2019 13:52:36 +0000 Received: from MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::45dc:e073:4446:4bf8]) by MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::45dc:e073:4446:4bf8%3]) with mapi id 15.20.2263.023; Thu, 19 Sep 2019 13:52:36 +0000 From: Jerome Pouiller To: "devel@driverdev.osuosl.org" , "linux-wireless@vger.kernel.org" CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , David Le Goff , Jerome Pouiller Subject: [PATCH v2 09/20] staging: wfx: add support for start-up indication Thread-Topic: [PATCH v2 09/20] staging: wfx: add support for start-up indication Thread-Index: AQHVbvF9RjprTXKT9Uub+N9phOnkGA== Date: Thu, 19 Sep 2019 13:52:35 +0000 Message-ID: <20190919135220.30663-10-Jerome.Pouiller@silabs.com> References: <20190919135220.30663-1-Jerome.Pouiller@silabs.com> In-Reply-To: <20190919135220.30663-1-Jerome.Pouiller@silabs.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jerome.Pouiller@silabs.com; x-originating-ip: [37.71.187.125] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 60845c54-bdeb-43ed-ef77-08d73d08a0ae x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:MN2PR11MB4400; x-ms-traffictypediagnostic: MN2PR11MB4400: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3631; x-forefront-prvs: 016572D96D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(1496009)(376002)(39850400004)(136003)(366004)(396003)(346002)(189003)(199004)(3846002)(76176011)(8676002)(76116006)(476003)(25786009)(2616005)(6116002)(54906003)(71190400001)(6436002)(102836004)(6486002)(36756003)(186003)(71200400001)(26005)(305945005)(6512007)(99286004)(6506007)(91956017)(7736002)(446003)(8936002)(256004)(81156014)(14444005)(2906002)(66066001)(107886003)(4326008)(86362001)(14454004)(478600001)(64756008)(81166006)(2501003)(486006)(66574012)(316002)(66946007)(66446008)(66556008)(5660300002)(11346002)(66476007)(1076003)(110136005);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR11MB4400;H:MN2PR11MB4063.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: silabs.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: aAOMYeQs7Pp3hCH31W8DlQZDxjvBu4DmhkHhzASAygNUfKJI2Ysns9npWI9NaSNPvqLcgpFh4qEyseGEBySL1sliRQIpZ0k0ix1Vd6gCp/3o2OoL0SWZ9p2IAOvYziBDDdMiHxzFtKLw+o3V24K8TpjkTUTH2+JmadB3nRoA3cw0q5O2r7xYt/NIoUiYJ91zD8mS8BUo3c9e2m6a8fv7VratGYM3pFx12WESVzH3/N2BoE4kj6LuJzk7isG8PRS0gr/eqaOGVrSumSYDrp6ZZYO1JL6vgzjAoawauJ5TTzd8b6B+HSyC2b8xDdP0bMaDz8JPWxe8zieL6x4Gdiql7u3wlARN6CaqSeg73iOBpThwP0jrWw+akMoNCWsSU8bEyRWxLi5+UvMOAgGjNBkc90lS8Q00PhOGSydWmsvX+88= Content-ID: <9DD8E17401FF02479613053E25390A42@namprd11.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60845c54-bdeb-43ed-ef77-08d73d08a0ae X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2019 13:52:35.0832 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: h5kSgAvMXMcYjj2Bzwg0nCnKfqSW5ohIUdtqumHoII0viZVpmWk8BUrMpDfua6OOTsap6tZbj1ONzBUZl32X7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4400 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Jérôme Pouiller Once firmware is loaded, it send a first indication to host. This indication signalize that host can start to communicate with firmware. In add, it contains information about chip and firmware (MAC addresses, firmware version, etc...). Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/Makefile | 1 + drivers/staging/wfx/bh.c | 4 ++- drivers/staging/wfx/hif_rx.c | 57 ++++++++++++++++++++++++++++++++++++ drivers/staging/wfx/hif_rx.h | 18 ++++++++++++ drivers/staging/wfx/main.c | 45 ++++++++++++++++++++++++++++ drivers/staging/wfx/wfx.h | 5 ++++ 6 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/wfx/hif_rx.c create mode 100644 drivers/staging/wfx/hif_rx.h diff --git a/drivers/staging/wfx/Makefile b/drivers/staging/wfx/Makefile index 1abd3115f11d..35670b86c64f 100644 --- a/drivers/staging/wfx/Makefile +++ b/drivers/staging/wfx/Makefile @@ -7,6 +7,7 @@ wfx-y := \ bh.o \ hwio.o \ fwio.o \ + hif_rx.o \ main.o \ debug.o wfx-$(CONFIG_SPI) += bus_spi.o diff --git a/drivers/staging/wfx/bh.c b/drivers/staging/wfx/bh.c index 76afecdf579d..c40da3f1f25d 100644 --- a/drivers/staging/wfx/bh.c +++ b/drivers/staging/wfx/bh.c @@ -12,6 +12,7 @@ #include "wfx.h" #include "hwio.h" #include "traces.h" +#include "hif_rx.h" #include "hif_api_cmd.h" static void device_wakeup(struct wfx_dev *wdev) @@ -107,7 +108,8 @@ static int rx_helper(struct wfx_dev *wdev, size_t read_len, int *is_cnf) } skb_put(skb, hif->len); - dev_kfree_skb(skb); /* FIXME: handle received data */ + // wfx_handle_rx takes care on SKB livetime + wfx_handle_rx(wdev, skb); return piggyback; diff --git a/drivers/staging/wfx/hif_rx.c b/drivers/staging/wfx/hif_rx.c new file mode 100644 index 000000000000..5c207e6d4348 --- /dev/null +++ b/drivers/staging/wfx/hif_rx.c @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Implementation of chip-to-host event (aka indications) of WFxxx Split Mac + * (WSM) API. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include + +#include "hif_rx.h" +#include "wfx.h" +#include "hif_api_cmd.h" + +static int hif_startup_indication(struct wfx_dev *wdev, struct hif_msg *hif, void *buf) +{ + struct hif_ind_startup *body = buf; + + if (body->status || body->firmware_type > 4) { + dev_err(wdev->dev, "received invalid startup indication"); + return -EINVAL; + } + memcpy(&wdev->hw_caps, body, sizeof(struct hif_ind_startup)); + le32_to_cpus(&wdev->hw_caps.status); + le16_to_cpus(&wdev->hw_caps.hardware_id); + le16_to_cpus(&wdev->hw_caps.num_inp_ch_bufs); + le16_to_cpus(&wdev->hw_caps.size_inp_ch_buf); + + complete(&wdev->firmware_ready); + return 0; +} + +static const struct { + int msg_id; + int (*handler)(struct wfx_dev *wdev, struct hif_msg *hif, void *buf); +} hif_handlers[] = { + { HIF_IND_ID_STARTUP, hif_startup_indication }, +}; + +void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb) +{ + int i; + struct hif_msg *hif = (struct hif_msg *) skb->data; + int hif_id = hif->id; + + for (i = 0; i < ARRAY_SIZE(hif_handlers); i++) { + if (hif_handlers[i].msg_id == hif_id) { + if (hif_handlers[i].handler) + hif_handlers[i].handler(wdev, hif, hif->body); + goto free; + } + } + dev_err(wdev->dev, "unsupported HIF ID %02x\n", hif_id); +free: + dev_kfree_skb(skb); +} diff --git a/drivers/staging/wfx/hif_rx.h b/drivers/staging/wfx/hif_rx.h new file mode 100644 index 000000000000..f07c10c8c6bd --- /dev/null +++ b/drivers/staging/wfx/hif_rx.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Implementation of chip-to-host event (aka indications) of WFxxx Split Mac + * (WSM) API. + * + * Copyright (c) 2017-2019, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + * Copyright (C) 2010, ST-Ericsson SA + */ +#ifndef WFX_HIF_RX_H +#define WFX_HIF_RX_H + +struct wfx_dev; +struct sk_buff; + +void wfx_handle_rx(struct wfx_dev *wdev, struct sk_buff *skb); + +#endif diff --git a/drivers/staging/wfx/main.c b/drivers/staging/wfx/main.c index f0bea053a0d9..5e7e7225f068 100644 --- a/drivers/staging/wfx/main.c +++ b/drivers/staging/wfx/main.c @@ -12,6 +12,7 @@ */ #include #include +#include #include #include #include @@ -87,6 +88,9 @@ struct wfx_dev *wfx_init_common(struct device *dev, wdev->hwbus_ops = hwbus_ops; wdev->hwbus_priv = hwbus_priv; memcpy(&wdev->pdata, pdata, sizeof(*pdata)); + + init_completion(&wdev->firmware_ready); + return wdev; } @@ -96,7 +100,9 @@ void wfx_free_common(struct wfx_dev *wdev) int wfx_probe(struct wfx_dev *wdev) { + int i; int err; + const void *macaddr; wfx_bh_register(wdev); @@ -104,6 +110,45 @@ int wfx_probe(struct wfx_dev *wdev) if (err) goto err1; + err = wait_for_completion_interruptible_timeout(&wdev->firmware_ready, 10 * HZ); + if (err <= 0) { + if (err == 0) { + dev_err(wdev->dev, "timeout while waiting for startup indication. IRQ configuration error?\n"); + err = -ETIMEDOUT; + } else if (err == -ERESTARTSYS) { + dev_info(wdev->dev, "probe interrupted by user\n"); + } + goto err1; + } + + // FIXME: fill wiphy::hw_version + dev_info(wdev->dev, "started firmware %d.%d.%d \"%s\" (API: %d.%d, keyset: %02X, caps: 0x%.8X)\n", + wdev->hw_caps.firmware_major, wdev->hw_caps.firmware_minor, + wdev->hw_caps.firmware_build, wdev->hw_caps.firmware_label, + wdev->hw_caps.api_version_major, wdev->hw_caps.api_version_minor, + wdev->keyset, *((u32 *) &wdev->hw_caps.capabilities)); + + if (wfx_api_older_than(wdev, 1, 0)) { + dev_err(wdev->dev, "unsupported firmware API version (expect 1 while firmware returns %d)\n", + wdev->hw_caps.api_version_major); + err = -ENOTSUPP; + goto err1; + } + + for (i = 0; i < ARRAY_SIZE(wdev->addresses); i++) { + eth_zero_addr(wdev->addresses[i].addr); + macaddr = of_get_mac_address(wdev->dev->of_node); + if (macaddr) { + ether_addr_copy(wdev->addresses[i].addr, macaddr); + wdev->addresses[i].addr[ETH_ALEN - 1] += i; + } + ether_addr_copy(wdev->addresses[i].addr, wdev->hw_caps.mac_addr[i]); + if (!is_valid_ether_addr(wdev->addresses[i].addr)) { + dev_warn(wdev->dev, "using random MAC address\n"); + eth_random_addr(wdev->addresses[i].addr); + } + dev_info(wdev->dev, "MAC address %d: %pM\n", i, wdev->addresses[i].addr); + } return 0; diff --git a/drivers/staging/wfx/wfx.h b/drivers/staging/wfx/wfx.h index 4f28938fa3a6..f5f9a337d828 100644 --- a/drivers/staging/wfx/wfx.h +++ b/drivers/staging/wfx/wfx.h @@ -10,6 +10,9 @@ #ifndef WFX_H #define WFX_H +#include +#include + #include "bh.h" #include "main.h" #include "hif_api_general.h" @@ -19,10 +22,12 @@ struct hwbus_ops; struct wfx_dev { struct wfx_platform_data pdata; struct device *dev; + struct mac_address addresses[2]; const struct hwbus_ops *hwbus_ops; void *hwbus_priv; u8 keyset; + struct completion firmware_ready; struct hif_ind_startup hw_caps; struct wfx_hif hif; };