From nobody Fri Dec 19 14:36:07 2025 Received: from DU2PR03CU002.outbound.protection.outlook.com (mail-northeuropeazon11011031.outbound.protection.outlook.com [52.101.65.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A169310655; Wed, 5 Nov 2025 10:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.31 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762339806; cv=fail; b=UVKjRvWRkFhAy8w22UmskJelUbNUMQGMEjZyD2fjFycxLju29/DDpFlXPvrS2UCoauSfVMPUbTAC8dNAyh4T5OXxOOvtilkEPZirTzvg1raVb4a+tWE0M+beLuyW1z06mhm0WA6EmvmUMYGun64lXy6jOUhGJEyEZ1MZq+vkUvk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762339806; c=relaxed/simple; bh=zryv+5+SHEX0J8QT2KejgCRubi9iujp72JpNIQB/+4E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=jATZ7EhOGmwoG1A7suUl4z8lnGNG+U0RLxwBYH/T3lrwwEFn5BX4OdSHvXTnD6JJYksrmsN9LJ2OiZGAF+E33Gjm+6pQUeqZ0xQ3mtl2OXJS/Ks7kHhjOI6s+a3KhNMeBanL6R7RAWsOl7zyX9XK2SPFc/gZnhAz4ha2E6YQfCA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=YetYL+F2; arc=fail smtp.client-ip=52.101.65.31 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="YetYL+F2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KyA/HDfcdloJV7sk1CLOc6uP5iR0UerBGBFc77GA1tpwtbn+Zbq6sv1KwKR8EW5vkRG3vmEkrAuRVi7cTzyUsOhNQfTZReMoPU2XGytJJdmLgnRBqzRXE7Z8KTamOO1/LuQf1iIR9Y2ZG74BCP21aQrOnlxVgq3bFGo0YYoNim6FRv74M/sdOiaMLc+NtTtc3v56+Mon7qW7scVQ76R2gE4axA6M6mYbS+maS+ZDoraOmUsDMwDS19JGy88Uyf9DpF8I53ZicqMDChofC5bcvBqySpPCOsHn27YJQtSwDMq45cC8sKZGCrjRklO8Qo1XsuTQvyS1VNaMe4sLXDMOoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mX2a1NmZ3AIVcLhL12m9pV6XaH5oBPWgF6JGy+cwQcA=; b=ZEyVdcKXR6xCtmJaqcQjlQp4L64gP/oKph1m6bX8rRTHImvF/11qpCMvRQDPdcAMDn4e6j+RRLlKmGnslODl86LUpB4KRDiGJg8hu2buRP1r+FF0FHYLMqgtnZsvFu4u/qzbn9qq5uCDCVzuxMXHZEIVicjh33A7HyvYjTL3zO4Rl5YrjdJ2bHvE/6pldQTKaeWrXs9tTLQ3Ipiiz/GZ1MdAKDU3+jGQetzwjzhzpwFc21romZaRdPp0L56e41dy7Hm6pv0kC+TkNeNAGsMwn0HheDfHErIu84Qh3MaGP2aBERhkefuj6L6IJoyQsAie6JAg/Novml9FOF+WVd5ogQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mX2a1NmZ3AIVcLhL12m9pV6XaH5oBPWgF6JGy+cwQcA=; b=YetYL+F2r94fx8qnRKLV7bbUf9un8t1y8mie5pSdu5HuO9wXKOXThu62mRtNsWA4hBGNmRSSf3LygheH1ETKpXgcuk/1WN0JM7Jdy+GdcC2mDfutgUi41wqp2VnLEe1cCgY28jLZ5GW0th0XwnrXIFFhXlzQLXxbvefCx0SYiG/bVmsuW/7lq69TG/pxZxrOlvMfVbKWt8ZC/2WhVL0HQo9xwPbMrEdAKfBA7H06AhfPNdpk/2SBDi5mn6KSVABANtM8ZQtlqKUT2+q6F1YqlG8s5aKDYqVWjFe1LEr5adEHmtBdsY4NSdAVwqfaPFQEHVssodrKyGd33SGX5x3Xsg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DBBPR04MB7740.eurprd04.prod.outlook.com (2603:10a6:10:1ee::23) by PA1PR04MB10770.eurprd04.prod.outlook.com (2603:10a6:102:492::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9298.9; Wed, 5 Nov 2025 10:49:52 +0000 Received: from DBBPR04MB7740.eurprd04.prod.outlook.com ([fe80::7a71:369b:fb82:59d7]) by DBBPR04MB7740.eurprd04.prod.outlook.com ([fe80::7a71:369b:fb82:59d7%2]) with mapi id 15.20.9275.015; Wed, 5 Nov 2025 10:49:52 +0000 From: Jeff Chen To: linux-wireless@vger.kernel.org Cc: linux-kernel@vger.kernel.org, briannorris@chromium.org, johannes@sipsolutions.net, francesco@dolcini.it, tsung-hsien.hsieh@nxp.com, s.hauer@pengutronix.de, Jeff Chen Subject: [PATCH v6 17/22] wifi: nxpwifi: add driver initialization and shutdown support Date: Wed, 5 Nov 2025 18:47:39 +0800 Message-Id: <20251105104744.2401992-18-jeff.chen_1@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251105104744.2401992-1-jeff.chen_1@nxp.com> References: <20251105104744.2401992-1-jeff.chen_1@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM8P189CA0018.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:218::23) To DBBPR04MB7740.eurprd04.prod.outlook.com (2603:10a6:10:1ee::23) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBBPR04MB7740:EE_|PA1PR04MB10770:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ed8b745-1534-4a36-40c4-08de1c590c51 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|366016|1800799024|19092799006|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?MPPuAKxdoY/0gVkiVnz2FvK5hYfuBjYEUpfx2Sr05gzDsRmRzVhOc1rSP19+?= =?us-ascii?Q?5Xo8vSZK5MdyTzQQBg/4NM9GTiHszSKouhdvZ3ahVx5/QdaInqnoXnskxl8x?= =?us-ascii?Q?7YaVv2ym6GMlQMNIMCVs/+qpr3a6JD5Uze7RSykTLHtiWtNceMdovpyh8mHL?= =?us-ascii?Q?q1g0c3sdda7TinKyAOOhNIy0PqPY3xsR+dwZTTcR9/NBhquF0qf8XERmI/Ig?= =?us-ascii?Q?2hGXIq1KuKrfMAvL3cTqtD7BKNCypz3aOX6fOL+in1O0hgzrmIgdqncQeilt?= =?us-ascii?Q?bd/BrMvvIXmRG+tHG5hgzap9mrp7H3hJSkiZu8N8wZ6H34UQ1WjCcgBnYLPT?= =?us-ascii?Q?aaHaMfyH/x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aEM28?= =?us-ascii?Q?uCelz8w0vYm34qBYtqzRMq8Dq4uYFJw5U7V+bst1Hs53KtKLGF7ZN/QR6LUb?= =?us-ascii?Q?76tVQ8E2ZbdsWV4yA8WNIuINJ8jU5E1+jbZg7bkqqaiapGuc2mh3DeZF2xtP?= =?us-ascii?Q?RKWWutZGLbJek/GoAwczLfxBE5aTT54Xq23OV6skIVeG7dgg2+hREBeVP367?= =?us-ascii?Q?BLILvLJmoCB+wAmvEqnVtfB9gfXVECuwaCJZ1NEw+tpX/UMNTW6SLrKMRll8?= =?us-ascii?Q?6+Lbjsrugi6oG6nJaPnHOymiAodKjiLfdN1P?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DBBPR04MB7740.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(366016)(1800799024)(19092799006)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?RL91Xh0rPj21mS6LNSppyg6N1vtzX9ahcAJFIz0nSBc6rx52JJorMWJXmOEt?= =?us-ascii?Q?a/0N4QGGiK1eOroZowwcupUaQxe2DEJqn8IKOCu7Kej9r0JBaCU7FZcNTxFF?= =?us-ascii?Q?47pnRHAwEMObGuUNjJfo0utyC0D4piFQNwRLYPwgCDaMiZZ0U+qQ+7BdPy70?= =?us-ascii?Q?mpVPBVOU/hNr5xFAe1arG1WFTCcqM0IuZ+5W25yUsul8cAtqgq4HxC2z/GM5?= =?us-ascii?Q?2NnD5XULlzxDcaUDe7Hl1iaEqoP8X37UOqjkw/ZCqA2EgSgw/2Xn7URJcri2?= =?us-ascii?Q?9b+DNPYKjgvr7GN/zFTelWt4SeGVuq5k9GlEkuntqhn5lEJ+3jigxLIlSfuv?= =?us-ascii?Q?RSkelNTjPZ3D0XrpAGntZ752Xq9a28ojD5gS8Ax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gb1SFvgBxev3hBkDM1+hnjdrQsYRTA+LHrZW0tObrf8Hy1RDYsKsOOF?= =?us-ascii?Q?yYr1P9Epfx/PgUVO96i2S+f0a4ZbA2pYn5hfyZvKKJLmIzMKbEeS+fIkyzho?= =?us-ascii?Q?RpbXSKduYaHFd4RMk91jxwMn0rK8xxap6es0TXLj07d1NWDdG3mJzVVPEW8t?= =?us-ascii?Q?0I0hJ1ZoaKvciQTzhvX4v6AxImlfipmZ+1HwqUqsW7PMGmXavK9PCChw+f97?= =?us-ascii?Q?uEsufJayC3rxqmowUSl71KNhJe9e0nzPIiKadwa2sLXeq9KSEwHJonk9Mff/?= =?us-ascii?Q?4Qg1szL6oHusi7U7U9hhzvCr5JjRJgWwEye516Zv?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ed8b745-1534-4a36-40c4-08de1c590c51 X-MS-Exchange-CrossTenant-AuthSource: DBBPR04MB7740.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Nov 2025 10:49:52.0895 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uBiYTHfIjX4Ex2hXYGOJzIxGEN8NcJc21muxUceLWwPmgDj1R+Xlz5hsOq+wwZxL0y9tMvE0TrWxJlVXOlY/aw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA1PR04MB10770 Content-Type: text/plain; charset="utf-8" This patch introduces the initialization and shutdown logic for the nxpwifi driver, including setup of adapter and private structures, firmware download,and resource cleanup. Key features: - Initializes adapter and private structures with default values - Allocates and initializes command buffers, queues, and timers - Sets up BSS priority tables for multi-interface coordination - Implements firmware download and initialization sequence - Provides shutdown and cleanup routines for safe driver removal - Adds helpers for managing netdev queues and synchronization primitives These foundational components are essential for bringing up the driver and ensuring proper resource management across its lifecycle. Signed-off-by: Jeff Chen --- drivers/net/wireless/nxp/nxpwifi/init.c | 680 ++++++++++++++++++++++++ 1 file changed, 680 insertions(+) create mode 100644 drivers/net/wireless/nxp/nxpwifi/init.c diff --git a/drivers/net/wireless/nxp/nxpwifi/init.c b/drivers/net/wireless= /nxp/nxpwifi/init.c new file mode 100644 index 000000000000..7a47f585a1d9 --- /dev/null +++ b/drivers/net/wireless/nxp/nxpwifi/init.c @@ -0,0 +1,680 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * NXP Wireless LAN device driver: HW/FW Initialization + * + * Copyright 2011-2024 NXP + */ + +#include "cfg.h" +#include "util.h" +#include "fw.h" +#include "main.h" +#include "cmdevt.h" +#include "wmm.h" +#include "11n.h" + +/* This function adds a BSS priority table to the table list. + * + * The function allocates a new BSS priority table node and adds it to + * the end of BSS priority table list, kept in driver memory. + */ +static int nxpwifi_add_bss_prio_tbl(struct nxpwifi_private *priv) +{ + struct nxpwifi_adapter *adapter =3D priv->adapter; + struct nxpwifi_bss_prio_node *bss_prio; + struct nxpwifi_bss_prio_tbl *tbl =3D adapter->bss_prio_tbl; + + bss_prio =3D kzalloc(sizeof(*bss_prio), GFP_KERNEL); + if (!bss_prio) + return -ENOMEM; + + bss_prio->priv =3D priv; + INIT_LIST_HEAD(&bss_prio->list); + + spin_lock_bh(&tbl[priv->bss_priority].bss_prio_lock); + list_add_tail(&bss_prio->list, &tbl[priv->bss_priority].bss_prio_head); + spin_unlock_bh(&tbl[priv->bss_priority].bss_prio_lock); + + return 0; +} + +static void wakeup_timer_fn(struct timer_list *t) +{ + struct nxpwifi_adapter *adapter =3D timer_container_of(adapter, t, wakeup= _timer); + + nxpwifi_dbg(adapter, ERROR, "Firmware wakeup failed\n"); + adapter->hw_status =3D NXPWIFI_HW_STATUS_RESET; + nxpwifi_cancel_all_pending_cmd(adapter); + + if (adapter->if_ops.card_reset) + adapter->if_ops.card_reset(adapter); +} + +/* This function initializes the private structure and sets default + * values to the members. + * + * Additionally, it also initializes all the locks and sets up all the + * lists. + */ +int nxpwifi_init_priv(struct nxpwifi_private *priv) +{ + u32 i; + + priv->media_connected =3D false; + eth_broadcast_addr(priv->curr_addr); + priv->port_open =3D false; + priv->usb_port =3D NXPWIFI_USB_EP_DATA; + priv->pkt_tx_ctrl =3D 0; + priv->bss_mode =3D NL80211_IFTYPE_UNSPECIFIED; + priv->data_rate =3D 0; /* Initially indicate the rate as auto */ + priv->is_data_rate_auto =3D true; + priv->bcn_avg_factor =3D DEFAULT_BCN_AVG_FACTOR; + priv->data_avg_factor =3D DEFAULT_DATA_AVG_FACTOR; + + priv->auth_flag =3D 0; + priv->auth_alg =3D WLAN_AUTH_NONE; + + priv->sec_info.wep_enabled =3D 0; + priv->sec_info.authentication_mode =3D NL80211_AUTHTYPE_OPEN_SYSTEM; + priv->sec_info.encryption_mode =3D 0; + for (i =3D 0; i < ARRAY_SIZE(priv->wep_key); i++) + memset(&priv->wep_key[i], 0, sizeof(struct nxpwifi_wep_key)); + priv->wep_key_curr_index =3D 0; + priv->curr_pkt_filter =3D HOST_ACT_MAC_DYNAMIC_BW_ENABLE | + HOST_ACT_MAC_RX_ON | HOST_ACT_MAC_TX_ON | + HOST_ACT_MAC_ETHERNETII_ENABLE; + + priv->beacon_period =3D 100; /* beacon interval */ + priv->attempted_bss_desc =3D NULL; + memset(&priv->curr_bss_params, 0, sizeof(priv->curr_bss_params)); + priv->listen_interval =3D NXPWIFI_DEFAULT_LISTEN_INTERVAL; + + memset(&priv->prev_ssid, 0, sizeof(priv->prev_ssid)); + memset(&priv->prev_bssid, 0, sizeof(priv->prev_bssid)); + memset(&priv->assoc_rsp_buf, 0, sizeof(priv->assoc_rsp_buf)); + priv->assoc_rsp_size =3D 0; + priv->atim_window =3D 0; + priv->tx_power_level =3D 0; + priv->max_tx_power_level =3D 0; + priv->min_tx_power_level =3D 0; + priv->tx_ant =3D 0; + priv->rx_ant =3D 0; + priv->tx_rate =3D 0; + priv->rxpd_htinfo =3D 0; + priv->rxpd_rate =3D 0; + priv->rate_bitmap =3D 0; + priv->data_rssi_last =3D 0; + priv->data_rssi_avg =3D 0; + priv->data_nf_avg =3D 0; + priv->data_nf_last =3D 0; + priv->bcn_rssi_last =3D 0; + priv->bcn_rssi_avg =3D 0; + priv->bcn_nf_avg =3D 0; + priv->bcn_nf_last =3D 0; + memset(&priv->wpa_ie, 0, sizeof(priv->wpa_ie)); + memset(&priv->aes_key, 0, sizeof(priv->aes_key)); + priv->wpa_ie_len =3D 0; + priv->wpa_is_gtk_set =3D false; + + memset(&priv->assoc_tlv_buf, 0, sizeof(priv->assoc_tlv_buf)); + priv->assoc_tlv_buf_len =3D 0; + memset(&priv->wps, 0, sizeof(priv->wps)); + memset(&priv->gen_ie_buf, 0, sizeof(priv->gen_ie_buf)); + priv->gen_ie_buf_len =3D 0; + memset(priv->vs_ie, 0, sizeof(priv->vs_ie)); + + priv->wmm_required =3D true; + priv->wmm_enabled =3D false; + priv->wmm_qosinfo =3D 0; + priv->curr_bcn_buf =3D NULL; + priv->curr_bcn_size =3D 0; + priv->wps_ie =3D NULL; + priv->wps_ie_len =3D 0; + priv->ap_11n_enabled =3D 0; + memset(&priv->roc_cfg, 0, sizeof(priv->roc_cfg)); + + priv->scan_block =3D false; + + priv->csa_chan =3D 0; + priv->csa_expire_time =3D 0; + priv->del_list_idx =3D 0; + priv->hs2_enabled =3D false; + memcpy(priv->tos_to_tid_inv, tos_to_tid_inv, MAX_NUM_TID); + + nxpwifi_init_11h_params(priv); + + return nxpwifi_add_bss_prio_tbl(priv); +} + +/* This function allocates buffers for members of the adapter + * structure. + * + * The memory allocated includes scan table, command buffers, and + * sleep confirm command buffer. In addition, the queues are + * also initialized. + */ +static int nxpwifi_allocate_adapter(struct nxpwifi_adapter *adapter) +{ + int ret; + + /* Allocate command buffer */ + ret =3D nxpwifi_alloc_cmd_buffer(adapter); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "%s: failed to alloc cmd buffer\n", + __func__); + return ret; + } + + adapter->sleep_cfm =3D + dev_alloc_skb(sizeof(struct nxpwifi_opt_sleep_confirm) + + INTF_HEADER_LEN); + + if (!adapter->sleep_cfm) { + nxpwifi_dbg(adapter, ERROR, + "%s: failed to alloc sleep cfm\t" + " cmd buffer\n", __func__); + return -ENOMEM; + } + skb_reserve(adapter->sleep_cfm, INTF_HEADER_LEN); + + return 0; +} + +/* This function initializes the adapter structure and sets default + * values to the members of adapter. + * + * This also initializes the WMM related parameters in the driver private + * structures. + */ +static void nxpwifi_init_adapter(struct nxpwifi_adapter *adapter) +{ + struct nxpwifi_opt_sleep_confirm *sleep_cfm_buf =3D NULL; + + skb_put(adapter->sleep_cfm, sizeof(struct nxpwifi_opt_sleep_confirm)); + + adapter->cmd_sent =3D false; + adapter->data_sent =3D true; + + adapter->intf_hdr_len =3D INTF_HEADER_LEN; + + adapter->cmd_resp_received =3D false; + adapter->event_received =3D false; + adapter->data_received =3D false; + adapter->assoc_resp_received =3D false; + adapter->priv_link_lost =3D NULL; + adapter->host_mlme_link_lost =3D false; + + clear_bit(NXPWIFI_SURPRISE_REMOVED, &adapter->work_flags); + + adapter->hw_status =3D NXPWIFI_HW_STATUS_INITIALIZING; + + adapter->ps_mode =3D NXPWIFI_802_11_POWER_MODE_CAM; + adapter->ps_state =3D PS_STATE_AWAKE; + adapter->need_to_wakeup =3D false; + + adapter->scan_mode =3D HOST_BSS_MODE_ANY; + adapter->specific_scan_time =3D NXPWIFI_SPECIFIC_SCAN_CHAN_TIME; + adapter->active_scan_time =3D NXPWIFI_ACTIVE_SCAN_CHAN_TIME; + adapter->passive_scan_time =3D NXPWIFI_PASSIVE_SCAN_CHAN_TIME; + adapter->scan_chan_gap_time =3D NXPWIFI_DEF_SCAN_CHAN_GAP_TIME; + + adapter->scan_probes =3D 1; + + adapter->multiple_dtim =3D 1; + + /* default value in firmware will be used */ + adapter->local_listen_interval =3D 0; + + adapter->is_deep_sleep =3D false; + + adapter->delay_null_pkt =3D false; + adapter->delay_to_ps =3D 1000; + adapter->enhanced_ps_mode =3D PS_MODE_AUTO; + + /* Disable NULL Pkg generation by default */ + adapter->gen_null_pkt =3D false; + /* Disable pps/uapsd mode by default */ + adapter->pps_uapsd_mode =3D false; + adapter->pm_wakeup_card_req =3D false; + + adapter->pm_wakeup_fw_try =3D false; + + adapter->curr_tx_buf_size =3D NXPWIFI_TX_DATA_BUF_SIZE_2K; + + clear_bit(NXPWIFI_IS_HS_CONFIGURED, &adapter->work_flags); + adapter->hs_cfg.conditions =3D cpu_to_le32(HS_CFG_COND_DEF); + adapter->hs_cfg.gpio =3D HS_CFG_GPIO_DEF; + adapter->hs_cfg.gap =3D HS_CFG_GAP_DEF; + adapter->hs_activated =3D false; + + memset(adapter->event_body, 0, sizeof(adapter->event_body)); + adapter->hw_dot_11n_dev_cap =3D 0; + adapter->hw_dev_mcs_support =3D 0; + adapter->sec_chan_offset =3D 0; + + nxpwifi_wmm_init(adapter); + atomic_set(&adapter->tx_hw_pending, 0); + + sleep_cfm_buf =3D (struct nxpwifi_opt_sleep_confirm *) + adapter->sleep_cfm->data; + memset(sleep_cfm_buf, 0, adapter->sleep_cfm->len); + sleep_cfm_buf->command =3D cpu_to_le16(HOST_CMD_802_11_PS_MODE_ENH); + sleep_cfm_buf->size =3D cpu_to_le16(adapter->sleep_cfm->len); + sleep_cfm_buf->result =3D 0; + sleep_cfm_buf->action =3D cpu_to_le16(SLEEP_CONFIRM); + sleep_cfm_buf->resp_ctrl =3D cpu_to_le16(RESP_NEEDED); + + memset(&adapter->sleep_period, 0, sizeof(adapter->sleep_period)); + adapter->tx_lock_flag =3D false; + adapter->null_pkt_interval =3D 0; + adapter->fw_bands =3D 0; + adapter->fw_release_number =3D 0; + adapter->fw_cap_info =3D 0; + memset(&adapter->upld_buf, 0, sizeof(adapter->upld_buf)); + adapter->event_cause =3D 0; + adapter->region_code =3D 0; + adapter->bcn_miss_time_out =3D DEFAULT_BCN_MISS_TIMEOUT; + memset(&adapter->arp_filter, 0, sizeof(adapter->arp_filter)); + adapter->arp_filter_size =3D 0; + adapter->max_mgmt_ie_index =3D MAX_MGMT_IE_INDEX; + adapter->key_api_major_ver =3D 0; + adapter->key_api_minor_ver =3D 0; + eth_broadcast_addr(adapter->perm_addr); + adapter->iface_limit.sta_intf =3D NXPWIFI_MAX_STA_NUM; + adapter->iface_limit.uap_intf =3D NXPWIFI_MAX_UAP_NUM; + adapter->active_scan_triggered =3D false; + timer_setup(&adapter->wakeup_timer, wakeup_timer_fn, 0); + adapter->devdump_len =3D 0; + memset(&adapter->vdll_ctrl, 0, sizeof(adapter->vdll_ctrl)); + adapter->vdll_ctrl.skb =3D dev_alloc_skb(NXPWIFI_SIZE_OF_CMD_BUFFER); + atomic_set(&adapter->iface_changing, 0); +} + +/* This function sets trans_start per tx_queue + */ +void nxpwifi_set_trans_start(struct net_device *dev) +{ + int i; + + for (i =3D 0; i < dev->num_tx_queues; i++) + txq_trans_cond_update(netdev_get_tx_queue(dev, i)); + + netif_trans_update(dev); +} + +/* This function wakes up all queues in net_device + */ +void nxpwifi_wake_up_net_dev_queue(struct net_device *netdev, + struct nxpwifi_adapter *adapter) +{ + spin_lock_bh(&adapter->queue_lock); + netif_tx_wake_all_queues(netdev); + spin_unlock_bh(&adapter->queue_lock); +} + +/* This function stops all queues in net_device + */ +void nxpwifi_stop_net_dev_queue(struct net_device *netdev, + struct nxpwifi_adapter *adapter) +{ + spin_lock_bh(&adapter->queue_lock); + netif_tx_stop_all_queues(netdev); + spin_unlock_bh(&adapter->queue_lock); +} + +/* This function invalidates the list heads. + */ +static void nxpwifi_invalidate_lists(struct nxpwifi_adapter *adapter) +{ + struct nxpwifi_private *priv; + s32 i, j; + + list_del(&adapter->cmd_free_q); + list_del(&adapter->cmd_pending_q); + list_del(&adapter->scan_pending_q); + + for (i =3D 0; i < adapter->priv_num; i++) + list_del(&adapter->bss_prio_tbl[i].bss_prio_head); + + for (i =3D 0; i < adapter->priv_num; i++) { + priv =3D adapter->priv[i]; + for (j =3D 0; j < MAX_NUM_TID; ++j) { + list_del(&priv->wmm.tid_tbl_ptr[j].ra_list); + list_del(&priv->tx_ba_stream_tbl_ptr[j]); + list_del(&priv->rx_reorder_tbl_ptr[j]); + } + list_del(&priv->sta_list); + } +} + +/* This function performs cleanup for adapter structure. + * + * The cleanup is done recursively, by canceling all pending + * commands, freeing the member buffers previously allocated + * (command buffers, scan table buffer, sleep confirm command + * buffer), stopping the timers and calling the cleanup routines + * for every interface. + */ +static void +nxpwifi_adapter_cleanup(struct nxpwifi_adapter *adapter) +{ + timer_delete(&adapter->wakeup_timer); + nxpwifi_cancel_all_pending_cmd(adapter); + wake_up_interruptible(&adapter->cmd_wait_q.wait); + wake_up_interruptible(&adapter->hs_activate_wait_q); + if (adapter->vdll_ctrl.vdll_mem) { + vfree(adapter->vdll_ctrl.vdll_mem); + adapter->vdll_ctrl.vdll_mem =3D NULL; + adapter->vdll_ctrl.vdll_len =3D 0; + } + if (adapter->vdll_ctrl.skb) { + dev_kfree_skb_any(adapter->vdll_ctrl.skb); + adapter->vdll_ctrl.skb =3D NULL; + } +} + +void nxpwifi_free_cmd_buffers(struct nxpwifi_adapter *adapter) +{ + nxpwifi_invalidate_lists(adapter); + + /* Free command buffer */ + nxpwifi_dbg(adapter, INFO, "info: free cmd buffer\n"); + nxpwifi_free_cmd_buffer(adapter); + + if (adapter->sleep_cfm) + dev_kfree_skb_any(adapter->sleep_cfm); +} + +/* This function intializes the lock variables and + * the list heads. + */ +void nxpwifi_init_lock_list(struct nxpwifi_adapter *adapter) +{ + struct nxpwifi_private *priv; + s32 i, j; + + spin_lock_init(&adapter->int_lock); + spin_lock_init(&adapter->nxpwifi_cmd_lock); + spin_lock_init(&adapter->queue_lock); + for (i =3D 0; i < adapter->priv_num; i++) { + priv =3D adapter->priv[i]; + spin_lock_init(&priv->wmm.ra_list_spinlock); + spin_lock_init(&priv->curr_bcn_buf_lock); + spin_lock_init(&priv->sta_list_spinlock); + } + + /* Initialize cmd_free_q */ + INIT_LIST_HEAD(&adapter->cmd_free_q); + /* Initialize cmd_pending_q */ + INIT_LIST_HEAD(&adapter->cmd_pending_q); + /* Initialize scan_pending_q */ + INIT_LIST_HEAD(&adapter->scan_pending_q); + + spin_lock_init(&adapter->cmd_free_q_lock); + spin_lock_init(&adapter->cmd_pending_q_lock); + spin_lock_init(&adapter->scan_pending_q_lock); + + skb_queue_head_init(&adapter->rx_mlme_q); + skb_queue_head_init(&adapter->rx_data_q); + skb_queue_head_init(&adapter->tx_data_q); + + for (i =3D 0; i < adapter->priv_num; ++i) { + INIT_LIST_HEAD(&adapter->bss_prio_tbl[i].bss_prio_head); + spin_lock_init(&adapter->bss_prio_tbl[i].bss_prio_lock); + } + + for (i =3D 0; i < adapter->priv_num; i++) { + priv =3D adapter->priv[i]; + for (j =3D 0; j < MAX_NUM_TID; ++j) { + INIT_LIST_HEAD(&priv->wmm.tid_tbl_ptr[j].ra_list); + INIT_LIST_HEAD(&priv->tx_ba_stream_tbl_ptr[j]); + INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr[j]); + spin_lock_init(&priv->tx_ba_stream_tbl_lock[j]); + spin_lock_init(&priv->rx_reorder_tbl_lock[j]); + } + INIT_LIST_HEAD(&priv->sta_list); + skb_queue_head_init(&priv->bypass_txq); + + spin_lock_init(&priv->ack_status_lock); + idr_init(&priv->ack_status_frames); + } +} + +/* This function initializes the firmware. + * + * The following operations are performed sequentially - + * - Allocate adapter structure + * - Initialize the adapter structure + * - Initialize the private structure + * - Add BSS priority tables to the adapter structure + * - For each interface, send the init commands to firmware + * - Send the first command in command pending queue, if available + */ +int nxpwifi_init_fw(struct nxpwifi_adapter *adapter) +{ + int ret; + struct nxpwifi_private *priv; + u8 i; + bool first_sta =3D true; + int is_cmd_pend_q_empty; + + adapter->hw_status =3D NXPWIFI_HW_STATUS_INITIALIZING; + + /* Allocate memory for member of adapter structure */ + ret =3D nxpwifi_allocate_adapter(adapter); + if (ret) + return ret; + + /* Initialize adapter structure */ + nxpwifi_init_adapter(adapter); + + for (i =3D 0; i < adapter->priv_num; i++) { + priv =3D adapter->priv[i]; + + /* Initialize private structure */ + ret =3D nxpwifi_init_priv(priv); + if (ret) + return ret; + } + + for (i =3D 0; i < adapter->priv_num; i++) { + ret =3D nxpwifi_sta_init_cmd(adapter->priv[i], + first_sta, true); + if (ret && ret !=3D -EINPROGRESS) + return ret; + + first_sta =3D false; + } + + spin_lock_bh(&adapter->cmd_pending_q_lock); + is_cmd_pend_q_empty =3D list_empty(&adapter->cmd_pending_q); + spin_unlock_bh(&adapter->cmd_pending_q_lock); + if (!is_cmd_pend_q_empty) + /* Send the first command in queue and return */ + nxpwifi_main_process(adapter); + else + adapter->hw_status =3D NXPWIFI_HW_STATUS_READY; + + return ret; +} + +/* This function deletes the BSS priority tables. + * + * The function traverses through all the allocated BSS priority nodes + * in every BSS priority table and frees them. + */ +static void nxpwifi_delete_bss_prio_tbl(struct nxpwifi_private *priv) +{ + int i; + struct nxpwifi_adapter *adapter =3D priv->adapter; + struct nxpwifi_bss_prio_node *bssprio_node, *tmp_node; + struct list_head *head; + spinlock_t *lock; /* bss priority lock */ + + for (i =3D 0; i < adapter->priv_num; ++i) { + head =3D &adapter->bss_prio_tbl[i].bss_prio_head; + lock =3D &adapter->bss_prio_tbl[i].bss_prio_lock; + nxpwifi_dbg(adapter, INFO, + "info: delete BSS priority table,\t" + "bss_type =3D %d, bss_num =3D %d, i =3D %d,\t" + "head =3D %p\n", + priv->bss_type, priv->bss_num, i, head); + + { + spin_lock_bh(lock); + list_for_each_entry_safe(bssprio_node, tmp_node, head, + list) { + if (bssprio_node->priv =3D=3D priv) { + nxpwifi_dbg(adapter, INFO, + "info: Delete\t" + "node %p, next =3D %p\n", + bssprio_node, tmp_node); + list_del(&bssprio_node->list); + kfree(bssprio_node); + } + } + spin_unlock_bh(lock); + } + } +} + +/* This function frees the private structure, including cleans + * up the TX and RX queues and frees the BSS priority tables. + */ +void nxpwifi_free_priv(struct nxpwifi_private *priv) +{ + nxpwifi_clean_txrx(priv); + nxpwifi_delete_bss_prio_tbl(priv); + nxpwifi_free_curr_bcn(priv); +} + +/* This function is used to shutdown the driver. + * + * The following operations are performed sequentially - + * - Check if already shut down + * - Make sure the main process has stopped + * - Clean up the Tx and Rx queues + * - Delete BSS priority tables + * - Free the adapter + * - Notify completion + */ +void +nxpwifi_shutdown_drv(struct nxpwifi_adapter *adapter) +{ + struct nxpwifi_private *priv; + s32 i; + struct sk_buff *skb; + + /* nxpwifi already shutdown */ + if (adapter->hw_status =3D=3D NXPWIFI_HW_STATUS_NOT_READY) + return; + + /* cancel current command */ + if (adapter->curr_cmd) { + nxpwifi_dbg(adapter, WARN, + "curr_cmd is still in processing\n"); + timer_delete_sync(&adapter->cmd_timer); + nxpwifi_recycle_cmd_node(adapter, adapter->curr_cmd); + adapter->curr_cmd =3D NULL; + } + + /* shut down nxpwifi */ + nxpwifi_dbg(adapter, MSG, + "info: shutdown nxpwifi...\n"); + + /* Clean up Tx/Rx queues and delete BSS priority table */ + for (i =3D 0; i < adapter->priv_num; i++) { + priv =3D adapter->priv[i]; + + nxpwifi_abort_cac(priv); + nxpwifi_free_priv(priv); + } + + atomic_set(&adapter->tx_queued, 0); + while ((skb =3D skb_dequeue(&adapter->tx_data_q))) + nxpwifi_write_data_complete(adapter, skb, 0, 0); + + while ((skb =3D skb_dequeue(&adapter->rx_mlme_q))) + dev_kfree_skb_any(skb); + + while ((skb =3D skb_dequeue(&adapter->rx_data_q))) { + struct nxpwifi_rxinfo *rx_info =3D NXPWIFI_SKB_RXCB(skb); + + atomic_dec(&adapter->rx_pending); + priv =3D adapter->priv[rx_info->bss_num]; + if (priv) + priv->stats.rx_dropped++; + + dev_kfree_skb_any(skb); + } + + nxpwifi_adapter_cleanup(adapter); + + adapter->hw_status =3D NXPWIFI_HW_STATUS_NOT_READY; +} + +/* This function downloads the firmware to the card. + * + * The actual download is preceded by two sanity checks - + * - Check if firmware is already running + * - Check if the interface is the winner to download the firmware + * + * ...and followed by another - + * - Check if the firmware is downloaded successfully + * + * After download is successfully completed, the host interrupts are enabl= ed. + */ +int nxpwifi_dnld_fw(struct nxpwifi_adapter *adapter, + struct nxpwifi_fw_image *pmfw) +{ + int ret; + u32 poll_num =3D 1; + + /* check if firmware is already running */ + ret =3D adapter->if_ops.check_fw_status(adapter, poll_num); + if (!ret) { + nxpwifi_dbg(adapter, MSG, + "WLAN FW already running! Skip FW dnld\n"); + return 0; + } + + /* check if we are the winner for downloading FW */ + if (adapter->if_ops.check_winner_status) { + adapter->winner =3D 0; + ret =3D adapter->if_ops.check_winner_status(adapter); + + poll_num =3D MAX_FIRMWARE_POLL_TRIES; + if (ret) { + nxpwifi_dbg(adapter, MSG, + "WLAN read winner status failed!\n"); + return ret; + } + + if (!adapter->winner) { + nxpwifi_dbg(adapter, MSG, + "WLAN is not the winner! Skip FW dnld\n"); + goto poll_fw; + } + } + + if (pmfw) { + /* Download firmware with helper */ + ret =3D adapter->if_ops.prog_fw(adapter, pmfw); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "prog_fw failed ret=3D%#x\n", ret); + return ret; + } + } + +poll_fw: + /* Check if the firmware is downloaded successfully or not */ + ret =3D adapter->if_ops.check_fw_status(adapter, poll_num); + if (ret) + nxpwifi_dbg(adapter, ERROR, + "FW failed to be active in time\n"); + + return ret; +} +EXPORT_SYMBOL_GPL(nxpwifi_dnld_fw); --=20 2.34.1