From nobody Thu Nov 28 21:28:14 2024 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2074.outbound.protection.outlook.com [40.107.21.74]) (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 35B8D184531; Mon, 30 Sep 2024 06:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.74 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727678323; cv=fail; b=bky/xN4YBgcSZPbglWBs98sPrKHcVOAFaZC23Vb5mk6chu4EVu26WvydFkxrnOwMIWT59CHvZsOybseo8qzE6O8+k512qqWV3wH3vCe0MRMYtJiujZAoKz43p3QtZ6OYMEvl+RcjCdNY6mFiZzJ1ZE+uzpr7CAiytSGz3mNoIUY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727678323; c=relaxed/simple; bh=Stk11CME79P58C/yuCkMsfCe7R4kP8JaoRQSJLhe94o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=g6KM6WH+ZYrNXCGTnWb+dCiKCElhDUg+fjiqfz4Vnv92+h6T3MThCqFP1Fp1FSvtVRDNn/VE7CWhwzda7mzSnc6FWr7nHXkx3q7Z7Evt9hXTwqe9asrhb0Sr0tzPPsqUF16PFHlRxb92xuQtXxXNmftVssfUmz5YvD8ZEYh5zTU= 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=Kny7EwRD; arc=fail smtp.client-ip=40.107.21.74 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="Kny7EwRD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=j0WIKssLyX/DFlwNeKooOnqDryqBbqETTwz1K4GN8JGVvpyZA5EyBZw0lItgAMfUg1qmKat8XyFKhZewQpgfGMO53YC3KPr+dN66bsCQwnOgdvKpcyNlkrOTwnGq55BlwH2zB8ThS0yTlwWuKmZVB3Xcrioc+uxPx8XiIfMrqaUpIilm6RfU4lJeNKyrfTDfcX/Bn92yxCDqR0WBq55ePc3HV+JXupdtlNFkzz4kiRVFAC6IJRCiYsddL+3kXUNCMevG9iOqSnpWAaks+0WN86MEEBo5mc2mAmmbrG9/Lxvm9zi+9IiE9Dt7wX0UXoCIgo6QxoYrfXxcVzQ5MZfq/A== 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=f4YNNPfhwd4/ZzLlKqk0YDVcknMvyP5IRy29gUPWCwY=; b=nbXPygoc4aCSgU0+SuhJZPnHA86kAwonqJKAonXRS+EDyB2wOE4u+cx6zhxsvfIk2ldm4EV5cOuDpJVwCNCiky1ezLwSeLjA/8SIlNzcX9zFT5lQ9JpDQaF8AqgBOhbHfQGl5qVHxTbNYB8vqYWhrsqhwWX0Xd2GyncmRunLTORPZ1vPcPQ2Gj6cK0MomGJqtnsDGfttAcPFHSVqEUW2R0WoJ99hHI//T48bqwATI7n/VHMoVVhBuxF9M/MzmOF0BGh2PBMJSaFdl7uCvud+cozwWMrrGGpCeCXp0Y0nX4DVFqRNCMDGFRsr6UkGSjTGGJRD6oLIhoI0hke2ShkkNA== 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=f4YNNPfhwd4/ZzLlKqk0YDVcknMvyP5IRy29gUPWCwY=; b=Kny7EwRDqMEGILMyzNBVb82p05aHEV+vyYj1YmNJhWuOJSRW5EkISBz92olNqBdqFGV5mQ+sul/7JyBmIm6+dfsxtB5SujiaFg9jW9zBSDLioLhgVWitc9tPp3c37BSuLV/2HmsoY5I47h2LnJJZ0HV2meTv1gl+hXZbZQ9IGgHovhWqs+vzz3c8zdBEPhHkkdnbM412l5FSRgK6PJhsrnhIl2BCB55JhW2OVGhZkBK+W6lQZsLEQ3J7OrPqn6uNuSOVK+owecD050UK9n4EuzOzgTaaeDMY4T/nSNRkoMIWYm/vztoGughoAsxqDBr9oMGXwWbQKioxxVQUM+A6Tw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PA4PR04MB9638.eurprd04.prod.outlook.com (2603:10a6:102:273::20) by PAXPR04MB9154.eurprd04.prod.outlook.com (2603:10a6:102:22d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.23; Mon, 30 Sep 2024 06:38:21 +0000 Received: from PA4PR04MB9638.eurprd04.prod.outlook.com ([fe80::f950:3bb6:6848:2257]) by PA4PR04MB9638.eurprd04.prod.outlook.com ([fe80::f950:3bb6:6848:2257%3]) with mapi id 15.20.8005.024; Mon, 30 Sep 2024 06:38:21 +0000 From: David Lin To: linux-wireless@vger.kernel.org Cc: linux-kernel@vger.kernel.org, briannorris@chromium.org, kvalo@kernel.org, francesco@dolcini.it, tsung-hsien.hsieh@nxp.com, s.hauer@pengutronix.de, David Lin Subject: [PATCH v3 17/22] wifi: nxpwifi: add initialization file Date: Mon, 30 Sep 2024 14:36:56 +0800 Message-Id: <20240930063701.2566520-18-yu-hao.lin@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240930063701.2566520-1-yu-hao.lin@nxp.com> References: <20240930063701.2566520-1-yu-hao.lin@nxp.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM8P190CA0001.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:219::6) To PA4PR04MB9638.eurprd04.prod.outlook.com (2603:10a6:102:273::20) 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: PA4PR04MB9638:EE_|PAXPR04MB9154:EE_ X-MS-Office365-Filtering-Correlation-Id: 104237f1-d79e-4f8e-b770-08dce11a79b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|52116014|376014|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?9gtRCIN8Oy2UfQFGz7It+1y0AmBuWBp65L3x9wucoyLUzK5ezP/aFcyJoif5?= =?us-ascii?Q?hA7GZI76CJK7AjBfDjPQlPVtQ+2LGSSb4acWyVGT5/7Gt+4iL7ubH/nr7+2j?= =?us-ascii?Q?NDzEEjebIsq7SRMZr7VQd46WouZGGDton1cqmN0ia7yFyqRcGzNR/GExKVCB?= =?us-ascii?Q?bzIkTs0L41EKz5DzhDQWl3BNE26kG8AdA57vdXflBWcRaT+Gfslx5xOotRlw?= =?us-ascii?Q?uI1R57iaqPn/qK8iclQptOQOTKTc5TKLvzey4I1Rgx7n3n5faCZWomSU1hYU?= =?us-ascii?Q?oEQ3/8nDTTITMkSFjwq6DKTlonldUm5rYP0iP4nmcH9bvcCaY5yd9qJX3EuL?= =?us-ascii?Q?NQDuCTvfCv1UpLLQrlev14g/zmTut8H7sya244eS+F/UCJl4+4JxLc3H+7tQ?= =?us-ascii?Q?2LudZndGiWTubH5DSIjyEyT7YkvY5akEV2jaPC0Wo35rHQq2eTZsqTcAHXK1?= =?us-ascii?Q?E8MqivYqgWjzha5HcpaSem80uueCsBn4/z9Ye1VPrU7JYNN+ESVcX2IkdmDw?= =?us-ascii?Q?0KjA4T0PxZoNzbH1cYZ2uJmtIqc2Tbws4+TugIdFX1ftGiuGDXU6e9RigBzP?= =?us-ascii?Q?fWq2DBBnwAcAFPlohfceVVIE/jHjnhTp9OsdMtcUGJIN+kiaaqUFu8GPyS4e?= =?us-ascii?Q?taMEgFTW56ugqACSBBD3EflhR7ve9UC16x0ESHmdTD5EQhLDK77/5UifNhOy?= =?us-ascii?Q?Ogg9MmuX4rMchy1ZyuPBzZyrQeezvTZqc6qHph9GYNC4z72qZh5rk11eBekD?= =?us-ascii?Q?BpOY1rMEzgLVADzEqNs4SKMVf7umoVrxIeOndySFLpu872zL1sqpW+rz1z7u?= =?us-ascii?Q?vBpN/JZsg0nWmn41KjPSLAhBc+X5gItzdubIM+2BVdCod0D6hDjgRORWXFV3?= =?us-ascii?Q?P5YSAlbRKmCW9ZZbdaMn6k+GVG0uDUhTh5nnozAWp69GEH/UFdUxoTfAB/e6?= =?us-ascii?Q?lr/RyxQVPoQUeVvBro0tVwoWHYUVCFWpNYgsKOSCqb7HXuHo0DCGmmQLd5sF?= =?us-ascii?Q?2JQ/T5WtwGulB3pU2AL7dQKQd+aY1G029cHiiKqWBWxTZwHPCj+HmVfafU2V?= =?us-ascii?Q?jChnnNHwL0Z+KfE3SOk1T3/Tpepzd+faPHUHv9pjH+E0V/JQl/za9eNrE6Jf?= =?us-ascii?Q?q1BQcVBVrYTii0EVGdByDBiNkKILKaTD206xuBTVJzAsxmA51TZr97+Cajk6?= =?us-ascii?Q?n41ogmQVi53RXSRgkm7t4GNLp3toAaM07drHFTKyvjC3Z2EeSnpWL78b+mqR?= =?us-ascii?Q?M1//BhfFA4RUidiqiZnfE9CzI8MdOjWAS0eTAUKMUSqykXlbObHfRmbA7ilQ?= =?us-ascii?Q?HNbqo38mJLagp0HT8zyCwkxZn3XScdPAWAnp0t0l9aJEgTAnShSEKVzKrs+F?= =?us-ascii?Q?npqGpyLfXlKQGIX3cA6yLr58bLT+/lmWDEg0mD6Wycana35oPw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA4PR04MB9638.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(376014)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?8Lzko8kya8EedSCscqTTTsfuGufvxJHcczAnhk9qWfA52HiiymbqhRVV8F85?= =?us-ascii?Q?C43EWhzRkXgsuhb4pD97qj4N0/iOLf0OYr97HA+pINgq8Ij0eFzzA7lRgI73?= =?us-ascii?Q?BPj5+mYEbHoA0RC46gEA7dfaSjcZ9q5Yl4jLMvU77sbwaaIaiIRVH+/sDjFg?= =?us-ascii?Q?gnvX4n/6MZQCxFtwcm97c7ACZPadUjEuLOBXPliFohTArn8LNjL4nkptpDsZ?= =?us-ascii?Q?4crmZnzIbuhBVQ8VuqkmvshvDqe7uKD6Ja1BKQnHLHd4i/3VyT+fO+IekAUA?= =?us-ascii?Q?Nk1O92MNbU6owpPnOsGg/5v7yNVnxd6M5RMNHEZO0J9PfM6sHPNn/7UbLa5u?= =?us-ascii?Q?FCZuGllaolcWdFzO89qQtb5Zfb0MnL2ZKV3NZ88GbzOLmI+u3JxmH+b83XuS?= =?us-ascii?Q?eiGG4psWdi1rSQJevcw8Q8ig8YxMtOxVTB2RzCyyL69n02hAnqcOVmw5nFLj?= =?us-ascii?Q?YmlryksUY3zkTZVi+9EJyFTbx9IB16rs4jnUxJk5LKYkW+evKtZXMhBxCXnC?= =?us-ascii?Q?nQABOAltrUcuuSbIc+wqZVdOrYgW2HroGezxrX9N+4TTho6/R8demoSVsgBM?= =?us-ascii?Q?CLPIvSP1Pf+uTV1kEZobys8nZK6V55doXVZkMZY2WDnES21CR/YeLW0V60qm?= =?us-ascii?Q?YO9jB4qtj+ub3sxfgwnEqMwOY68ueVJFwM09YGApHKYGR1r1tUNrzneAAvx/?= =?us-ascii?Q?wajpUx5Gui/pSvwIdCuA3ixRNGE5A3zXJn8gE93u0HAH3igAuzDuqly431vo?= =?us-ascii?Q?ooctCAh+ltSYJ9RYWhy091LfoQ4ayuTP9I7eKgB5kgfuDp10R31Rp3BqjuH5?= =?us-ascii?Q?b/rEns63AOw0sxYhKyntuQA1m9u8F5ED1u/94pM9u48ks+4pcDWCpeChOBt9?= =?us-ascii?Q?dnzcKvj+SDCQtM+SnV4MzwVtp+Ngectl8NKpg1nbX+gWyAyg/g1eAVX1uucF?= =?us-ascii?Q?y/rM5I98L6/MlgOmDmifLswwT+IX9nWSu9UTcDGF1JkGjMsrV/qnR4XR8Aot?= =?us-ascii?Q?5VShmYiw0ppFZImDwAcAed+J9cr77qGkvOMyGjYi8n70/vSBspt2GgY09hhX?= =?us-ascii?Q?RRhle2xgzH/sWA4QC0YRuJ51hDR0GJQdSUF2hsxGRz5GsCl6/0mVFwMeheYy?= =?us-ascii?Q?FOK2XxpyTfKIiZlOF87jkf2Oy56QzEJkknwdIBbYaC+4VaLwEMJDoTkCcFfU?= =?us-ascii?Q?mElWzNHk3i1CFAhoSrI418Em/vKe5/inohGwziDad0XcEOW244GcdU2BilE+?= =?us-ascii?Q?C+56qJY4q/nulDnn95v0JQF0/ySF2o4MYu484z2lvcqjdfYwDpk+GOl4DVjT?= =?us-ascii?Q?G9rXKFSs22g8oqFlEwp0/pkQxXkHj8IirFnlcUUlfiIw3jFISbekvmwLo49w?= =?us-ascii?Q?Xwv0XFitmT24jZ1Eadj9hwTW7wK3S7RkJ0jc++hFiBBNEzQg44JAhABTSZDd?= =?us-ascii?Q?xCbMpwzLmFeTd6PtSMsXSdgYWvro2dWxUijyzmWoeNq5RLmzfZ4kggN6likb?= =?us-ascii?Q?FvnCv+3rHKIgA3Y0lE43uK7urx2tYXuyVtGcb0vhUVwnLGcayForOg003I6S?= =?us-ascii?Q?LjnTX9WubMQDwIz+opLkkKBpexCo2edKgUQ7OWao?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 104237f1-d79e-4f8e-b770-08dce11a79b0 X-MS-Exchange-CrossTenant-AuthSource: PA4PR04MB9638.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2024 06:38:21.1223 (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: soeQdREblpMY9jWoL96OFFxouNrqye6vZyKWqcZgTm1iqVSIaAtJBuwuC+M+BwvSJRdRjjom6353dPGQe7C/dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9154 Content-Type: text/plain; charset="utf-8" Support initialization functions. Signed-off-by: David Lin --- 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..ba8af096ad76 --- /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 from_timer(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); +} + +/* 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); + list_del(&priv->rx_reorder_tbl_ptr); + 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) +{ + del_timer(&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->main_proc_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); + INIT_LIST_HEAD(&priv->rx_reorder_tbl_ptr); + INIT_LIST_HEAD(&priv->sta_list); + skb_queue_head_init(&priv->bypass_txq); + + spin_lock_init(&priv->tx_ba_stream_tbl_lock); + spin_lock_init(&priv->rx_reorder_tbl_lock); + + 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"); + del_timer_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); + + tasklet_disable(&adapter->rx_task); + + 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); + + 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