From nobody Thu Nov 28 21:27:38 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 0B797186614; Mon, 30 Sep 2024 06:38:44 +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=1727678330; cv=fail; b=KB5P5rFvcg8JvappWcO/faIH2lSZoKgJVN/t1+F5TqDMish+iiHSL4nsUagYyxmln1VML8ok7JJsBURhjtERBUx2mW83N/PZggrJz8Telr+0efeAMXLU/9gMdwJplq2K7UxuzUx/ltZgMN0xJUq2TYL0WlOYYSgpi+VCP5tyxeQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727678330; c=relaxed/simple; bh=jRypZywkFgEJFPu8Ra4XaUQVgmsqdNNQEuW9XiUkSpI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RDksJAcdwbufrFIGrIfSsxvljZ/VQz0p/PC+cahjlAxbWd1VHQmGs3v7C+2RyQrLANWIuJc9UZ1g9xWmnM/+2+6Dovvq8ID6wOO48nAFKX2p0U4NI1CnISEPsL5pnCIUd8LBt42cq2nWeisghdoGK/2B1YzG9/TAsFe3gOuuF3g= 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=jTj1Vh5h; 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="jTj1Vh5h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RV+kKAql2M8KU7bKEZQJcXnIFcfaOZZfosMZtaWvKPfpd8eAahm2YQpRyBEyx5pYaRH/KxNqjgmLz1woPg8DGYPYfBH1VaiMr9+RHfUEBXPTCovIUbYspox7nlIjP8zzMaaclmRwYIpGE6qR+hRsAVs1yu4VYyFV2BWW3rjT4gm57Mdp+ElgHDOrx5ecfawR8+PQ7zKgc6RxXBK6qWIOmhbGgWQW0wuVAbzRbaoiSwcIB6aODWh4x+nhklRqoqGGdfVuLthgRvUr887SJQkH0YobAdnJnMNgTgKa/YNlaK5C293SqtOCH3XqqPG/CoHDbp17QdOsUdMcd+FvBZ1zKw== 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=R/CQvkbvfADEuicqSHO5DV+1fL3hetQU6MC7llE1CRQ=; b=mQVVgZ51H2nd8LZz7KR8EUujOuG6zy69M+M1JYP30+On5FlMVvep84qg6zsxx+Zw82O6lZ+PaS+65G6mBtEJ56Hf9pF3wTFaGH4hwDiM6TI8lRcD6/CHTJ50qEL3YrRATtNlWweXp73LW7CKF8jE1aaUXNzjCsBwuYt/P+ONaf3w7kS/pnD80BAxzZeVMrvsl/AkTE/v0GtmyC4Mxo/NOaZi5S8Q0dHzbctA9bwsQeOUD3ZEtT4sTFiD3Ff4iOCf2AyJw2YgBtHgYzIjwxmdweFZzwBbhqOBVQi/ohiETU7qNHgccW98qg7xZmWsCr8HThfTzMfdCoq26p5PGoFiLQ== 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=R/CQvkbvfADEuicqSHO5DV+1fL3hetQU6MC7llE1CRQ=; b=jTj1Vh5hhvWpa0xQ7MEplP6hM2G6FLz4F2uaodqsrKvgy0XFoESxpAJaSYzRxytxNC0YfRNz3aQhcbtq1LrXX9qEGhptcl6OPYW4n2ls3wcR/n7C52kmFYvzhlWFc4fygj2ym0GpmxQHvDHDZzO8OZ2+zWXxbl9j2xHYA/3fImFX4G7ZtXta4jBzULUIXRZi9pJC08gBe++dpI0Vu7bEtMbrNJAWUsW8Qt1WufErzvmvJfYv9I34QpZMfDof+/rujHaZRqKR/nJa+6tA0m5SKOMJFPshgcKQCzB4rEE7FEEi4VXtJBZwAB3eJ06JQ1E3wrIxFvvPWhrGVcG8glhq0Q== 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:28 +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:27 +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 19/22] wifi: nxpwifi: add sdio bus driver files Date: Mon, 30 Sep 2024 14:36:58 +0800 Message-Id: <20240930063701.2566520-20-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: 93c544ee-e297-4717-ced4-08dce11a7db1 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?6o83+032YnZ1G7pL3lc2h7TWtQ6Cnmk/b/I97JV3uw29x4oAYk0jtwaZ5RMY?= =?us-ascii?Q?QDwKDtf/gNxBADO8wa1YChPj8grbfJrJ00/scXVF8UdVPVw5FJyxc8Jln6It?= =?us-ascii?Q?zCRX1qUaamlGCXGoFfWsSAmQ/JjFcGBWBVqVxnAAl2BTtPhGL9Z8vGw5ooE9?= =?us-ascii?Q?3mFAgcALE1r7E1lwYRjbTW2Y44JINTcWd0yVJTTB4quC6gu5JvHMXevQJE1e?= =?us-ascii?Q?ZrNxsZJSqgymaT+49mKw3h2hfyo1yrshL8HAFcgDXWrt8k3KS7btLojuYEEG?= =?us-ascii?Q?HVJ6kZauwktNypF1zC2sUblUz9gVEAxWLNj1yFJ3M+F/LnMU70tuIm6cqN2y?= =?us-ascii?Q?zk3hnU8XiBShHLdUapUVvdaWVIpe/lACQFAp99ykWX1WDvkaN3fMbJjjGZ2O?= =?us-ascii?Q?fFWI7fOUhqsPmBqwjesCAtvZj9R6jaijDj0LdWsKdeN5/veex/TTWFqvqSxz?= =?us-ascii?Q?PgElsEQJJg2x6Vx2AVoDNd6YocvrIiYME0+kTVOPdi+4VMKt8m/ptQtN8W9f?= =?us-ascii?Q?/bnswHoPkuv9T4wfew4Wsd6SUKpF44qp+xZHgpLHtvSVqOMM4d9OKHsvR4w0?= =?us-ascii?Q?ts76+GZZplV2d/lhh4iCGoib8mvdgBnZtDeX0zF0uis4VvS1HHToYRdZxS+g?= =?us-ascii?Q?fDTrc8m5lWIwRXgHNT8JNYE/HZCzePW27SFeVFkWPwF42tjujrSkvxhdoW5W?= =?us-ascii?Q?y7JtPHKu9zsM5OSBj15ZQSAi+NOIq2dbLqFgtK5IWfjj5IyDz0Uuil5ea1zY?= =?us-ascii?Q?G8EdinUoMLBu6+uUwiRLyzizaniL1WKwH9RE8m9+A0F0GZKCcJBfwjMQOulV?= =?us-ascii?Q?YbvCXE7QbClNszCssJEL1F2XHsF2fj6hKOh0uagQrlx5FjcAxQCKryE0aFLe?= =?us-ascii?Q?gGeBJ/K8PnvpUWUfJYO3Rk/Hfk4RQlgbHr9KeybDjCJRuof16WIZkAoXe2jW?= =?us-ascii?Q?C7utUs69NpQV7K5H38FNQJWoZ0bQGfubLAQdBljf5tCWUd1suosfxWtwM/Ss?= =?us-ascii?Q?rIssM1+507QPrdYJK75F+23ozV52QwckgJ4zVnluT0i/L3Xxt8W0kmcFUHyx?= =?us-ascii?Q?8ttaMV39r/gEnJn5L/SWIgot1hLGQ+rGGJrNwUdm5+ZHKOW9tYTy2gov0E/n?= =?us-ascii?Q?XXUbAp7pbjPzBkGaHdvqtKpl8nEacxdSIIDV9FnB9t4VYqDlpWdkSEjojR0D?= =?us-ascii?Q?elDzCOSNJ5quIgn0k2kCJAsTL+Z4BihpkQjEK3TXPbUF2IuyImd6vjWWbfR2?= =?us-ascii?Q?mDkAtnBUHDW2tt3MRte42uKU3SEfM5GldYz0ywwU2n6rVFLV11wosBK2e3Xe?= =?us-ascii?Q?CmUJtaoqWn4Rfr53EfXC8JjHS4hzcmnu01+hBOTwMjk00CSNKo0FTJ7HMpHI?= =?us-ascii?Q?4ITJRRy77/f+CCg2/PZPvizXDKIB89QFq4T0HwDv95CGh1YXow=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?SC7dUpBHMHvyupaZ0SC5WmUbw5fuzfjvnKrrYmH/A5u3vmG4VlBhJcXvSgBU?= =?us-ascii?Q?B7c5V+36/pZ7K2fNW+dNQc1k07AoMI2Rw3QzDNGa9v9MyRB2Hwt06USvQsSR?= =?us-ascii?Q?I1PtxM1ixipsGxF4dGQXQ16TpXWFvltpaeUDfQRXHvYjVFG17ROrdV78FEg6?= =?us-ascii?Q?M3Y21tBfzXmUf/Tl3zh1aGPZw0gZXqfWuo1MldhTzvFmpiy7Yp0MH4Ky6KNz?= =?us-ascii?Q?c/lmSAcmSBbxCz6pWMam1LPqwE49VAM20/G3Vtx2cdu8R/1utOuaH6ePwpgR?= =?us-ascii?Q?WyB7Az1AlcVKVdfkPg36/w7x+H+i7kT4v1gpgHN08wdVfrbqJlxhlMP8u3SA?= =?us-ascii?Q?CT7DBWPNQSfKD3VGeeenaxUqSaJulri8SSPiGpywsCFpwRJsbC3RAC9/4QqJ?= =?us-ascii?Q?vJ+sqU3YncXKnK26Gim6KMoBxSor6PyYlspdsE/88O/Psq1M3EUM+GtN30aT?= =?us-ascii?Q?95hMfwK03QX/DHhOuIr3xyK9vUaDP/u8+1/SctLsXJi7OVKOpbH2nQ7nfyFI?= =?us-ascii?Q?H4c5/azjCMRrzyJ8cLCzZuFxGURo8kUhZriHHkDvxX+Pb/xL0sYwK85Le4pe?= =?us-ascii?Q?gl8Nb6ovd2OPazMmTOBTaRMyXxrlxpCoW0d/QYGG+Jg17qhFiKE8fwd7wU1m?= =?us-ascii?Q?4siawGVX+fbPAoPQBWWsaa9uIRPF5wo+mGTqp9DwVpdTBn9XGhBMHXsj5OdA?= =?us-ascii?Q?3Wm0F7v7/hrhBkqC+JEl3AYZ/kcQ1eNfHpTzPtgO17oNJyctNXIeDID8V3Ct?= =?us-ascii?Q?f2vfW0r3lWItYUS2rnajuutDX+cck0QMSnsPWsYyKDFSEEbp3GRT3l6iejly?= =?us-ascii?Q?cMcMcV/mt1etrai/R4YKTLDvFy/zqyw4fNwG3EpzmcUjFedkhCXgWT4ipwaO?= =?us-ascii?Q?4gsWnk5ROfcqJBOK1bQ6aSHaGe3/2WlgPo80h/4wns/CBzJjbxIWMoPabJEG?= =?us-ascii?Q?0EWsAyqmcvcsex3YaQjq6MqSDnB5huzLPeluwsMXUEE56GKj8/j/eLdtYzRk?= =?us-ascii?Q?ZR0LD7X5KFaPji+d3DNulT95zDcHpLcarEN5SRyNjgbwKkAdvDq5GtVAlQl/?= =?us-ascii?Q?4ab3ux2TxvJOV/ejLrJJ9uuZiQUzkwNyzIQmgEit8GaygYCWcTyHy3dMrkdF?= =?us-ascii?Q?qZKtouxaDgYhLvDqhfGuSd+j2snl5zirRLyVg/wGUHWm2zHAKSmMjP33nRcc?= =?us-ascii?Q?QuvQj6yNBdBuHrQkZ3IFrbSPYP9Uaw5ieuwtmRUJb7eYumgO/BM+foMZLSiL?= =?us-ascii?Q?BINDlNbkRdnCZd9TogVa3Jp1lcvW+c970pxo2Yb4kK67soYXr29zuy/tlpfB?= =?us-ascii?Q?7qJh62I24hKmQLNbmY5AIoFRTNhNZrkYUDVL7Vh+J52k6hp7HAhGyTFJml8g?= =?us-ascii?Q?jmHZWFyqONxr2nislqNKDfMum5gwN5Qy/fKmqd4ONVsYhwN7JlL9/TLOnWZT?= =?us-ascii?Q?ctdniZ6JW2GaaJb0PW4UYYIlsHZDItktGVCtR7c9bhdZTmZ51Lff0Bconkq6?= =?us-ascii?Q?CzrT9FTA7KxBgvj1O4Qxfnok5r52hysON81D+tL1Sgyi8EgaG+R5ogHBcxhn?= =?us-ascii?Q?mGSh34z3hT8d5DKritv//JGKJ0qJczszehRH2cPH?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93c544ee-e297-4717-ced4-08dce11a7db1 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:27.9344 (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: kg8gnzslFib+TgRRLgF4ptFQmiv/zZrdK72RSg0nxQRycqXZ2b0Rf/oxNtHbGps7fYxIyvpw71iA7HOyTvEd/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9154 Content-Type: text/plain; charset="utf-8" Implement SDIO bus driver. This driver will create a working instance on core layer in order to support client and AP modes for supported SDIO NXP WiFi chips. Signed-off-by: David Lin --- drivers/net/wireless/nxp/nxpwifi/sdio.c | 2646 +++++++++++++++++++++++ drivers/net/wireless/nxp/nxpwifi/sdio.h | 340 +++ 2 files changed, 2986 insertions(+) create mode 100644 drivers/net/wireless/nxp/nxpwifi/sdio.c create mode 100644 drivers/net/wireless/nxp/nxpwifi/sdio.h diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.c b/drivers/net/wireless= /nxp/nxpwifi/sdio.c new file mode 100644 index 000000000000..c9c981134393 --- /dev/null +++ b/drivers/net/wireless/nxp/nxpwifi/sdio.c @@ -0,0 +1,2646 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * NXP Wireless LAN device driver: SDIO specific handling + * + * Copyright 2011-2024 NXP + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "cfg.h" +#include "util.h" +#include "fw.h" +#include "main.h" +#include "wmm.h" +#include "11n.h" +#include "sdio.h" + +#define SDIO_VERSION "1.0" + +static void nxpwifi_sdio_work(struct work_struct *work); + +static struct nxpwifi_if_ops sdio_ops; + +static const struct nxpwifi_sdio_card_reg nxpwifi_reg_iw61x =3D { + .start_rd_port =3D 0, + .start_wr_port =3D 0, + .base_0_reg =3D 0xF8, + .base_1_reg =3D 0xF9, + .poll_reg =3D 0x5C, + .host_int_enable =3D UP_LD_HOST_INT_MASK | DN_LD_HOST_INT_MASK | + CMD_PORT_UPLD_INT_MASK | CMD_PORT_DNLD_INT_MASK, + .host_int_rsr_reg =3D 0x4, + .host_int_status_reg =3D 0x0C, + .host_int_mask_reg =3D 0x08, + .host_strap_reg =3D 0xF4, + .host_strap_mask =3D 0x01, + .host_strap_value =3D 0x00, + .status_reg_0 =3D 0xE8, + .status_reg_1 =3D 0xE9, + .sdio_int_mask =3D 0xff, + .data_port_mask =3D 0xffffffff, + .io_port_0_reg =3D 0xE4, + .io_port_1_reg =3D 0xE5, + .io_port_2_reg =3D 0xE6, + .max_mp_regs =3D 196, + .rd_bitmap_l =3D 0x10, + .rd_bitmap_u =3D 0x11, + .rd_bitmap_1l =3D 0x12, + .rd_bitmap_1u =3D 0x13, + .wr_bitmap_l =3D 0x14, + .wr_bitmap_u =3D 0x15, + .wr_bitmap_1l =3D 0x16, + .wr_bitmap_1u =3D 0x17, + .rd_len_p0_l =3D 0x18, + .rd_len_p0_u =3D 0x19, + .card_misc_cfg_reg =3D 0xd8, + .card_cfg_2_1_reg =3D 0xd9, + .cmd_rd_len_0 =3D 0xc0, + .cmd_rd_len_1 =3D 0xc1, + .cmd_rd_len_2 =3D 0xc2, + .cmd_rd_len_3 =3D 0xc3, + .cmd_cfg_0 =3D 0xc4, + .cmd_cfg_1 =3D 0xc5, + .cmd_cfg_2 =3D 0xc6, + .cmd_cfg_3 =3D 0xc7, + .fw_dump_host_ready =3D 0xcc, + .fw_dump_ctrl =3D 0xf9, + .fw_dump_start =3D 0xf1, + .fw_dump_end =3D 0xf8, + .func1_dump_reg_start =3D 0x10, + .func1_dump_reg_end =3D 0x17, + .func1_scratch_reg =3D 0xE8, + .func1_spec_reg_num =3D 13, + .func1_spec_reg_table =3D {0x08, 0x58, 0x5C, 0x5D, 0x60, + 0x61, 0x62, 0x64, 0x65, 0x66, + 0x68, 0x69, 0x6a}, +}; + +static const struct nxpwifi_sdio_device nxpwifi_sdio_iw61x =3D { + .firmware =3D IW61X_SDIO_FW_NAME, + .reg =3D &nxpwifi_reg_iw61x, + .max_ports =3D 32, + .mp_agg_pkt_limit =3D 16, + .tx_buf_size =3D NXPWIFI_TX_DATA_BUF_SIZE_4K, + .mp_tx_agg_buf_size =3D NXPWIFI_MP_AGGR_BSIZE_MAX, + .mp_rx_agg_buf_size =3D NXPWIFI_MP_AGGR_BSIZE_MAX, + .can_dump_fw =3D true, + .fw_dump_enh =3D true, + .can_ext_scan =3D true, +}; + +static struct memory_type_mapping generic_mem_type_map[] =3D { + {"DUMP", NULL, 0, 0xDD}, +}; + +static struct memory_type_mapping mem_type_mapping_tbl[] =3D { + {"ITCM", NULL, 0, 0xF0}, + {"DTCM", NULL, 0, 0xF1}, + {"SQRAM", NULL, 0, 0xF2}, + {"APU", NULL, 0, 0xF3}, + {"CIU", NULL, 0, 0xF4}, + {"ICU", NULL, 0, 0xF5}, + {"MAC", NULL, 0, 0xF6}, + {"EXT7", NULL, 0, 0xF7}, + {"EXT8", NULL, 0, 0xF8}, + {"EXT9", NULL, 0, 0xF9}, + {"EXT10", NULL, 0, 0xFA}, + {"EXT11", NULL, 0, 0xFB}, + {"EXT12", NULL, 0, 0xFC}, + {"EXT13", NULL, 0, 0xFD}, + {"EXTLAST", NULL, 0, 0xFE}, +}; + +static const struct of_device_id nxpwifi_sdio_of_match_table[] __maybe_unu= sed =3D { + { } +}; + +/* This function parse device tree node using mmc subnode devicetree API. + * The device node is saved in card->plt_of_node. + * if the device tree node exist and include interrupts attributes, this + * function will also request platform specific wakeup interrupt. + */ +static int nxpwifi_sdio_probe_of(struct device *dev) +{ + if (!of_match_node(nxpwifi_sdio_of_match_table, dev->of_node)) { + dev_err(dev, "required compatible string missing\n"); + return -EINVAL; + } + + return 0; +} + +/* SDIO probe. + * + * This function probes an nxpwifi device and registers it. It allocates + * the card structure, enables SDIO function number and initiates the + * device registration and initialization procedure by adding a logical + * interface. + */ +static int +nxpwifi_sdio_probe(struct sdio_func *func, const struct sdio_device_id *id) +{ + int ret; + struct sdio_mmc_card *card =3D NULL; + + pr_debug("info: vendor=3D0x%4.04X device=3D0x%4.04X class=3D%d function= =3D%d\n", + func->vendor, func->device, func->class, func->num); + + card =3D devm_kzalloc(&func->dev, sizeof(*card), GFP_KERNEL); + if (!card) + return -ENOMEM; + + init_completion(&card->fw_done); + + card->func =3D func; + + func->card->quirks |=3D MMC_QUIRK_BLKSZ_FOR_BYTE_MODE; + + if (id->driver_data) { + struct nxpwifi_sdio_device *data =3D (void *)id->driver_data; + + card->firmware =3D data->firmware; + card->firmware_sdiouart =3D data->firmware_sdiouart; + card->reg =3D data->reg; + card->max_ports =3D data->max_ports; + card->mp_agg_pkt_limit =3D data->mp_agg_pkt_limit; + card->tx_buf_size =3D data->tx_buf_size; + card->mp_tx_agg_buf_size =3D data->mp_tx_agg_buf_size; + card->mp_rx_agg_buf_size =3D data->mp_rx_agg_buf_size; + card->can_dump_fw =3D data->can_dump_fw; + card->fw_dump_enh =3D data->fw_dump_enh; + card->can_ext_scan =3D data->can_ext_scan; + INIT_WORK(&card->work, nxpwifi_sdio_work); + } + + sdio_claim_host(func); + ret =3D sdio_enable_func(func); + sdio_release_host(func); + + if (ret) { + dev_err(&func->dev, "failed to enable function\n"); + return ret; + } + + /* device tree node parsing and platform specific configuration*/ + if (func->dev.of_node) { + ret =3D nxpwifi_sdio_probe_of(&func->dev); + if (ret) + goto err_disable; + } + + ret =3D nxpwifi_add_card(card, &card->fw_done, &sdio_ops, + NXPWIFI_SDIO, &func->dev); + if (ret) { + dev_err(&func->dev, "add card failed\n"); + goto err_disable; + } + + return 0; + +err_disable: + sdio_claim_host(func); + sdio_disable_func(func); + sdio_release_host(func); + + return ret; +} + +/* SDIO resume. + * + * Kernel needs to suspend all functions separately. Therefore all + * registered functions must have drivers with suspend and resume + * methods. Failing that the kernel simply removes the whole card. + * + * If already not resumed, this function turns on the traffic and + * sends a host sleep cancel request to the firmware. + */ +static int nxpwifi_sdio_resume(struct device *dev) +{ + struct sdio_func *func =3D dev_to_sdio_func(dev); + struct sdio_mmc_card *card; + struct nxpwifi_adapter *adapter; + + card =3D sdio_get_drvdata(func); + if (!card || !card->adapter) { + dev_err(dev, "resume: invalid card or adapter\n"); + return 0; + } + + adapter =3D card->adapter; + + if (!test_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags)) { + nxpwifi_dbg(adapter, WARN, + "device already resumed\n"); + return 0; + } + + clear_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags); + + /* Disable Host Sleep */ + nxpwifi_cancel_hs(nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_STA), + NXPWIFI_SYNC_CMD); + + nxpwifi_disable_wake(adapter); + + return 0; +} + +/* Write data into SDIO card register. Caller claims SDIO device. */ +static int +nxpwifi_write_reg_locked(struct sdio_func *func, u32 reg, u8 data) +{ + int ret; + + sdio_writeb(func, data, reg, &ret); + return ret; +} + +/* This function writes data into SDIO card register. + */ +static int +nxpwifi_write_reg(struct nxpwifi_adapter *adapter, u32 reg, u8 data) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret; + + sdio_claim_host(card->func); + ret =3D nxpwifi_write_reg_locked(card->func, reg, data); + sdio_release_host(card->func); + + return ret; +} + +/* This function reads data from SDIO card register. + */ +static int +nxpwifi_read_reg(struct nxpwifi_adapter *adapter, u32 reg, u8 *data) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret; + u8 val; + + sdio_claim_host(card->func); + val =3D sdio_readb(card->func, reg, &ret); + sdio_release_host(card->func); + + *data =3D val; + + return ret; +} + +/* This function writes multiple data into SDIO card memory. + * + * This does not work in suspended mode. + */ +static int +nxpwifi_write_data_sync(struct nxpwifi_adapter *adapter, + u8 *buffer, u32 pkt_len, u32 port) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret; + u8 blk_mode =3D + (port & NXPWIFI_SDIO_BYTE_MODE_MASK) ? BYTE_MODE : BLOCK_MODE; + u32 blk_size =3D (blk_mode =3D=3D BLOCK_MODE) ? NXPWIFI_SDIO_BLOCK_SIZE := 1; + u32 blk_cnt =3D + (blk_mode =3D=3D + BLOCK_MODE) ? (pkt_len / + NXPWIFI_SDIO_BLOCK_SIZE) : pkt_len; + u32 ioport =3D (port & NXPWIFI_SDIO_IO_PORT_MASK); + + if (test_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags)) { + nxpwifi_dbg(adapter, ERROR, + "%s: not allowed while suspended\n", __func__); + return -EPERM; + } + + sdio_claim_host(card->func); + + ret =3D sdio_writesb(card->func, ioport, buffer, blk_cnt * blk_size); + + sdio_release_host(card->func); + + return ret; +} + +/* This function reads multiple data from SDIO card memory. + */ +static int nxpwifi_read_data_sync(struct nxpwifi_adapter *adapter, u8 *buf= fer, + u32 len, u32 port, u8 claim) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret; + u8 blk_mode =3D (port & NXPWIFI_SDIO_BYTE_MODE_MASK) ? BYTE_MODE + : BLOCK_MODE; + u32 blk_size =3D (blk_mode =3D=3D BLOCK_MODE) ? NXPWIFI_SDIO_BLOCK_SIZE := 1; + u32 blk_cnt =3D (blk_mode =3D=3D BLOCK_MODE) ? (len / NXPWIFI_SDIO_BLOCK_= SIZE) + : len; + u32 ioport =3D (port & NXPWIFI_SDIO_IO_PORT_MASK); + + if (claim) + sdio_claim_host(card->func); + + ret =3D sdio_readsb(card->func, buffer, ioport, blk_cnt * blk_size); + + if (claim) + sdio_release_host(card->func); + + return ret; +} + +/* This function reads the firmware status. + */ +static int +nxpwifi_sdio_read_fw_status(struct nxpwifi_adapter *adapter, u16 *dat) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + u8 fws0, fws1; + int ret; + + ret =3D nxpwifi_read_reg(adapter, reg->status_reg_0, &fws0); + if (ret) + return ret; + + ret =3D nxpwifi_read_reg(adapter, reg->status_reg_1, &fws1); + if (ret) + return ret; + + *dat =3D (u16)((fws1 << 8) | fws0); + return ret; +} + +/* This function checks the firmware status in card. + */ +static int nxpwifi_check_fw_status(struct nxpwifi_adapter *adapter, + u32 poll_num) +{ + int ret =3D 0; + u16 firmware_stat =3D 0; + u32 tries; + + for (tries =3D 0; tries < poll_num; tries++) { + ret =3D nxpwifi_sdio_read_fw_status(adapter, &firmware_stat); + if (ret) + continue; + if (firmware_stat =3D=3D FIRMWARE_READY_SDIO) { + ret =3D 0; + break; + } + + msleep(100); + ret =3D -EPERM; + } + + if (firmware_stat =3D=3D FIRMWARE_READY_SDIO) + /* firmware might pretend to be ready, when it's not. + * Wait a little bit more as a workaround. + */ + msleep(100); + + return ret; +} + +/* This function checks if WLAN is the winner. + */ +static int nxpwifi_check_winner_status(struct nxpwifi_adapter *adapter) +{ + int ret; + u8 winner =3D 0; + struct sdio_mmc_card *card =3D adapter->card; + + ret =3D nxpwifi_read_reg(adapter, card->reg->status_reg_0, &winner); + if (ret) + return ret; + + if (winner) + adapter->winner =3D 0; + else + adapter->winner =3D 1; + + return ret; +} + +/* SDIO remove. + * + * This function removes the interface and frees up the card structure. + */ +static void +nxpwifi_sdio_remove(struct sdio_func *func) +{ + struct sdio_mmc_card *card; + struct nxpwifi_adapter *adapter; + struct nxpwifi_private *priv; + int ret =3D 0; + u16 firmware_stat; + + card =3D sdio_get_drvdata(func); + if (!card) + return; + + wait_for_completion(&card->fw_done); + + adapter =3D card->adapter; + if (!adapter || !adapter->priv_num) + return; + + nxpwifi_dbg(adapter, INFO, "info: SDIO func num=3D%d\n", func->num); + + ret =3D nxpwifi_sdio_read_fw_status(adapter, &firmware_stat); + if (!ret && firmware_stat =3D=3D FIRMWARE_READY_SDIO) { + nxpwifi_deauthenticate_all(adapter); + + priv =3D nxpwifi_get_priv(adapter, NXPWIFI_BSS_ROLE_ANY); + nxpwifi_disable_auto_ds(priv); + nxpwifi_init_shutdown_fw(priv, NXPWIFI_FUNC_SHUTDOWN); + } + + nxpwifi_remove_card(adapter); +} + +/* SDIO suspend. + * + * Kernel needs to suspend all functions separately. Therefore all + * registered functions must have drivers with suspend and resume + * methods. Failing that the kernel simply removes the whole card. + * + * If already not suspended, this function allocates and sends a host + * sleep activate request to the firmware and turns off the traffic. + */ +static int nxpwifi_sdio_suspend(struct device *dev) +{ + struct sdio_func *func =3D dev_to_sdio_func(dev); + struct sdio_mmc_card *card; + struct nxpwifi_adapter *adapter; + mmc_pm_flag_t pm_flag =3D 0; + int ret =3D 0; + + pm_flag =3D sdio_get_host_pm_caps(func); + pr_debug("cmd: %s: suspend: PM flag =3D 0x%x\n", + sdio_func_id(func), pm_flag); + if (!(pm_flag & MMC_PM_KEEP_POWER)) { + dev_err(dev, + "%s: cannot remain alive while host is suspended\n", + sdio_func_id(func)); + return -EPERM; + } + + card =3D sdio_get_drvdata(func); + if (!card) { + dev_err(dev, "suspend: invalid card\n"); + return 0; + } + + /* Might still be loading firmware */ + wait_for_completion(&card->fw_done); + + adapter =3D card->adapter; + if (!adapter) { + dev_err(dev, "adapter is not valid\n"); + return 0; + } + + if (!adapter->is_up) + return -EBUSY; + + nxpwifi_enable_wake(adapter); + + /* Enable the Host Sleep */ + if (!nxpwifi_enable_hs(adapter)) { + nxpwifi_dbg(adapter, ERROR, + "cmd: failed to suspend\n"); + clear_bit(NXPWIFI_IS_HS_ENABLING, &adapter->work_flags); + nxpwifi_disable_wake(adapter); + return -EPERM; + } + + nxpwifi_dbg(adapter, INFO, + "cmd: suspend with MMC_PM_KEEP_POWER\n"); + ret =3D sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER); + + /* Indicate device suspended */ + set_bit(NXPWIFI_IS_SUSPENDED, &adapter->work_flags); + clear_bit(NXPWIFI_IS_HS_ENABLING, &adapter->work_flags); + + return ret; +} + +static void nxpwifi_sdio_coredump(struct device *dev) +{ + struct sdio_func *func =3D dev_to_sdio_func(dev); + struct sdio_mmc_card *card; + + card =3D sdio_get_drvdata(func); + if (!test_and_set_bit(NXPWIFI_IFACE_WORK_DEVICE_DUMP, + &card->work_flags)) + nxpwifi_queue_work(card->adapter, &card->work); +} + +/* WLAN IDs */ +static const struct sdio_device_id nxpwifi_ids[] =3D { + {SDIO_DEVICE(SDIO_VENDOR_ID_NXP, SDIO_DEVICE_ID_NXP_IW61X), + .driver_data =3D (unsigned long)&nxpwifi_sdio_iw61x}, + {}, +}; + +MODULE_DEVICE_TABLE(sdio, nxpwifi_ids); + +static const struct dev_pm_ops nxpwifi_sdio_pm_ops =3D { + .suspend =3D nxpwifi_sdio_suspend, + .resume =3D nxpwifi_sdio_resume, +}; + +static struct sdio_driver nxpwifi_sdio =3D { + .name =3D "nxpwifi_sdio", + .id_table =3D nxpwifi_ids, + .probe =3D nxpwifi_sdio_probe, + .remove =3D nxpwifi_sdio_remove, + .drv =3D { + .owner =3D THIS_MODULE, + .coredump =3D nxpwifi_sdio_coredump, + .pm =3D &nxpwifi_sdio_pm_ops, + } +}; + +/* This function wakes up the card. + * + * A host power up command is written to the card configuration + * register to wake up the card. + */ +static int nxpwifi_pm_wakeup_card(struct nxpwifi_adapter *adapter) +{ + nxpwifi_dbg(adapter, EVENT, + "event: wakeup device...\n"); + + return nxpwifi_write_reg(adapter, CONFIGURATION_REG, HOST_POWER_UP); +} + +/* This function is called after the card has woken up. + * + * The card configuration register is reset. + */ +static int nxpwifi_pm_wakeup_card_complete(struct nxpwifi_adapter *adapter) +{ + nxpwifi_dbg(adapter, EVENT, + "cmd: wakeup device completed\n"); + + return nxpwifi_write_reg(adapter, CONFIGURATION_REG, 0); +} + +static int nxpwifi_sdio_dnld_fw(struct nxpwifi_adapter *adapter, + struct nxpwifi_fw_image *fw) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret; + + sdio_claim_host(card->func); + ret =3D nxpwifi_dnld_fw(adapter, fw); + sdio_release_host(card->func); + + return ret; +} + +/* This function is used to initialize IO ports for the + * chipsets supporting SDIO new mode. + */ +static int nxpwifi_init_sdio_new_mode(struct nxpwifi_adapter *adapter) +{ + u8 reg; + struct sdio_mmc_card *card =3D adapter->card; + int ret; + + adapter->ioport =3D MEM_PORT; + + /* enable sdio new mode */ + ret =3D nxpwifi_read_reg(adapter, card->reg->card_cfg_2_1_reg, ®); + if (ret) + return ret; + ret =3D nxpwifi_write_reg(adapter, card->reg->card_cfg_2_1_reg, + reg | CMD53_NEW_MODE); + if (ret) + return ret; + + /* Configure cmd port and enable reading rx length from the register */ + ret =3D nxpwifi_read_reg(adapter, card->reg->cmd_cfg_0, ®); + if (ret) + return ret; + ret =3D nxpwifi_write_reg(adapter, card->reg->cmd_cfg_0, + reg | CMD_PORT_RD_LEN_EN); + if (ret) + return ret; + + /* Enable Dnld/Upld ready auto reset for cmd port after cmd53 is + * completed + */ + ret =3D nxpwifi_read_reg(adapter, card->reg->cmd_cfg_1, ®); + if (ret) + return ret; + ret =3D nxpwifi_write_reg(adapter, card->reg->cmd_cfg_1, + reg | CMD_PORT_AUTO_EN); + + return ret; +} + +/* This function initializes the IO ports. + * + * The following operations are performed - + * - Read the IO ports (0, 1 and 2) + * - Set host interrupt Reset-To-Read to clear + * - Set auto re-enable interrupt + */ +static int nxpwifi_init_sdio_ioport(struct nxpwifi_adapter *adapter) +{ + u8 reg; + struct sdio_mmc_card *card =3D adapter->card; + int ret; + + ret =3D nxpwifi_init_sdio_new_mode(adapter); + if (ret) + return ret; + + nxpwifi_dbg(adapter, INFO, + "info: SDIO FUNC1 IO port: %#x\n", adapter->ioport); + + /* Set Host interrupt reset to read to clear */ + ret =3D nxpwifi_read_reg(adapter, card->reg->host_int_rsr_reg, ®); + if (ret) + return ret; + ret =3D nxpwifi_write_reg(adapter, card->reg->host_int_rsr_reg, + reg | card->reg->sdio_int_mask); + if (ret) + return ret; + + /* Dnld/Upld ready set to auto reset */ + ret =3D nxpwifi_read_reg(adapter, card->reg->card_misc_cfg_reg, ®); + if (ret) + return ret; + ret =3D nxpwifi_write_reg(adapter, card->reg->card_misc_cfg_reg, + reg | AUTO_RE_ENABLE_INT); + + return ret; +} + +/* This function sends data to the card. + */ +static int nxpwifi_write_data_to_card(struct nxpwifi_adapter *adapter, + u8 *payload, u32 pkt_len, u32 port) +{ + u32 i =3D 0; + int ret; + + do { + ret =3D nxpwifi_write_data_sync(adapter, payload, pkt_len, port); + if (ret) { + i++; + nxpwifi_dbg(adapter, ERROR, + "host_to_card, write iomem\t" + "(%d) failed: %d\n", i, ret); + if (nxpwifi_write_reg(adapter, CONFIGURATION_REG, 0x04)) + nxpwifi_dbg(adapter, ERROR, + "write CFG reg failed\n"); + + if (i > MAX_WRITE_IOMEM_RETRY) + return ret; + } + } while (ret); + + return ret; +} + +/* This function gets the read port. + * + * If control port bit is set in MP read bitmap, the control port + * is returned, otherwise the current read port is returned and + * the value is increased (provided it does not reach the maximum + * limit, in which case it is reset to 1) + */ +static int nxpwifi_get_rd_port(struct nxpwifi_adapter *adapter, u8 *port) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + u32 rd_bitmap =3D card->mp_rd_bitmap; + + nxpwifi_dbg(adapter, DATA, + "data: mp_rd_bitmap=3D0x%08x\n", rd_bitmap); + + if (!(rd_bitmap & reg->data_port_mask)) + return -EINVAL; + + if (!(card->mp_rd_bitmap & (1 << card->curr_rd_port))) + return -EINVAL; + + /* We are now handling the SDIO data ports */ + card->mp_rd_bitmap &=3D (u32)(~(1 << card->curr_rd_port)); + *port =3D card->curr_rd_port; + + if (++card->curr_rd_port =3D=3D card->max_ports) + card->curr_rd_port =3D reg->start_rd_port; + + nxpwifi_dbg(adapter, DATA, + "data: port=3D%d mp_rd_bitmap=3D0x%08x -> 0x%08x\n", + *port, rd_bitmap, card->mp_rd_bitmap); + + return 0; +} + +/* This function gets the write port for data. + * + * The current write port is returned if available and the value is + * increased (provided it does not reach the maximum limit, in which + * case it is reset to 1) + */ +static int nxpwifi_get_wr_port_data(struct nxpwifi_adapter *adapter, u32 *= port) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + u32 wr_bitmap =3D card->mp_wr_bitmap; + + nxpwifi_dbg(adapter, DATA, + "data: mp_wr_bitmap=3D0x%08x\n", wr_bitmap); + + if (!(wr_bitmap & card->mp_data_port_mask)) { + adapter->data_sent =3D true; + return -EBUSY; + } + + if (card->mp_wr_bitmap & (1 << card->curr_wr_port)) { + card->mp_wr_bitmap &=3D (u32)(~(1 << card->curr_wr_port)); + *port =3D card->curr_wr_port; + if (++card->curr_wr_port =3D=3D card->mp_end_port) + card->curr_wr_port =3D reg->start_wr_port; + } else { + adapter->data_sent =3D true; + return -EBUSY; + } + + nxpwifi_dbg(adapter, DATA, + "data: port=3D%d mp_wr_bitmap=3D0x%08x -> 0x%08x\n", + *port, wr_bitmap, card->mp_wr_bitmap); + + return 0; +} + +/* This function polls the card status. + */ +static int +nxpwifi_sdio_poll_card_status(struct nxpwifi_adapter *adapter, u8 bits) +{ + struct sdio_mmc_card *card =3D adapter->card; + u32 tries; + u8 cs; + int ret; + + for (tries =3D 0; tries < MAX_POLL_TRIES; tries++) { + ret =3D nxpwifi_read_reg(adapter, card->reg->poll_reg, &cs); + if (ret) + break; + else if ((cs & bits) =3D=3D bits) + return 0; + + usleep_range(10, 20); + } + + nxpwifi_dbg(adapter, ERROR, + "poll card status failed, tries =3D %d\n", tries); + + return ret; +} + +/* This function disables the host interrupt. + * + * The host interrupt mask is read, the disable bit is reset and + * written back to the card host interrupt mask register. + */ +static void nxpwifi_sdio_disable_host_int(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + struct sdio_func *func =3D card->func; + + sdio_claim_host(func); + nxpwifi_write_reg_locked(func, card->reg->host_int_mask_reg, 0); + sdio_release_irq(func); + sdio_release_host(func); +} + +/* This function reads the interrupt status from card. + */ +static void nxpwifi_interrupt_status(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + u8 sdio_ireg; + unsigned long flags; + + if (nxpwifi_read_data_sync(adapter, card->mp_regs, + card->reg->max_mp_regs, + REG_PORT | NXPWIFI_SDIO_BYTE_MODE_MASK, 0)) { + nxpwifi_dbg(adapter, ERROR, "read mp_regs failed\n"); + return; + } + + sdio_ireg =3D card->mp_regs[card->reg->host_int_status_reg]; + if (sdio_ireg) { + nxpwifi_dbg(adapter, INTR, + "int: sdio_ireg =3D %#x\n", sdio_ireg); + spin_lock_irqsave(&adapter->int_lock, flags); + adapter->int_status |=3D sdio_ireg; + spin_unlock_irqrestore(&adapter->int_lock, flags); + } +} + +/* SDIO interrupt handler. + * + * This function reads the interrupt status from firmware and handles + * the interrupt in current thread (ksdioirqd) right away. + */ +static void +nxpwifi_sdio_interrupt(struct sdio_func *func) +{ + struct nxpwifi_adapter *adapter; + struct sdio_mmc_card *card; + + card =3D sdio_get_drvdata(func); + if (!card || !card->adapter) { + pr_err("int: func=3D%p card=3D%p adapter=3D%p\n", + func, card, card ? card->adapter : NULL); + return; + } + adapter =3D card->adapter; + + if (!adapter->pps_uapsd_mode && adapter->ps_state =3D=3D PS_STATE_SLEEP) + adapter->ps_state =3D PS_STATE_AWAKE; + + nxpwifi_interrupt_status(adapter); + nxpwifi_main_process(adapter); +} + +/* This function enables the host interrupt. + * + * The host interrupt enable mask is written to the card + * host interrupt mask register. + */ +static int nxpwifi_sdio_enable_host_int(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + struct sdio_func *func =3D card->func; + int ret; + + sdio_claim_host(func); + + /* Request the SDIO IRQ */ + ret =3D sdio_claim_irq(func, nxpwifi_sdio_interrupt); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "claim irq failed: ret=3D%d\n", ret); + goto done; + } + + /* Simply write the mask to the register */ + ret =3D nxpwifi_write_reg_locked(func, card->reg->host_int_mask_reg, + card->reg->host_int_enable); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "enable host interrupt failed\n"); + sdio_release_irq(func); + } + +done: + sdio_release_host(func); + return ret; +} + +/* This function gets a data buffer from the card. + */ +static int nxpwifi_sdio_card_to_host(struct nxpwifi_adapter *adapter, + u32 *type, u8 *buffer, + u32 npayload, u32 ioport) +{ + int ret; + u32 nb; + + if (!buffer) { + nxpwifi_dbg(adapter, ERROR, + "%s: buffer is NULL\n", __func__); + return -EINVAL; + } + + ret =3D nxpwifi_read_data_sync(adapter, buffer, npayload, ioport, 1); + + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "%s: read iomem failed: %d\n", __func__, + ret); + return ret; + } + + nb =3D get_unaligned_le16((buffer)); + if (nb > npayload) { + nxpwifi_dbg(adapter, ERROR, + "%s: invalid packet, nb=3D%d npayload=3D%d\n", + __func__, nb, npayload); + return -EINVAL; + } + + *type =3D get_unaligned_le16((buffer + 2)); + + return ret; +} + +/* This function downloads the firmware to the card. + * + * Firmware is downloaded to the card in blocks. Every block download + * is tested for CRC errors, and retried a number of times before + * returning failure. + */ +static int nxpwifi_prog_fw_w_helper(struct nxpwifi_adapter *adapter, + struct nxpwifi_fw_image *fw) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + int ret; + u8 *firmware =3D fw->fw_buf; + u32 firmware_len =3D fw->fw_len; + u32 offset =3D 0; + u8 base0, base1; + u8 *fwbuf; + u16 len =3D 0; + u32 txlen, tx_blocks =3D 0, tries; + u32 i =3D 0; + + if (!firmware_len) { + nxpwifi_dbg(adapter, ERROR, + "firmware image not found! Terminating download\n"); + return -EINVAL; + } + + nxpwifi_dbg(adapter, INFO, + "info: downloading FW image (%d bytes)\n", + firmware_len); + + /* Assume that the allocated buffer is 8-byte aligned */ + fwbuf =3D kzalloc(NXPWIFI_UPLD_SIZE, GFP_KERNEL); + if (!fwbuf) + return -ENOMEM; + + sdio_claim_host(card->func); + + /* Perform firmware data transfer */ + do { + /* The host polls for the DN_LD_CARD_RDY and CARD_IO_READY + * bits + */ + ret =3D nxpwifi_sdio_poll_card_status(adapter, CARD_IO_READY | + DN_LD_CARD_RDY); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "FW download with helper:\t" + "poll status timeout @ %d\n", offset); + goto done; + } + + /* More data? */ + if (offset >=3D firmware_len) + break; + + for (tries =3D 0; tries < MAX_POLL_TRIES; tries++) { + ret =3D nxpwifi_read_reg(adapter, reg->base_0_reg, + &base0); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "dev BASE0 register read failed:\t" + "base0=3D%#04X(%d). Terminating dnld\n", + base0, base0); + goto done; + } + ret =3D nxpwifi_read_reg(adapter, reg->base_1_reg, + &base1); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "dev BASE1 register read failed:\t" + "base1=3D%#04X(%d). Terminating dnld\n", + base1, base1); + goto done; + } + len =3D (u16)(((base1 & 0xff) << 8) | (base0 & 0xff)); + + if (len) + break; + + usleep_range(10, 20); + } + + if (!len) { + break; + } else if (len > NXPWIFI_UPLD_SIZE) { + nxpwifi_dbg(adapter, ERROR, + "FW dnld failed @ %d, invalid length %d\n", + offset, len); + ret =3D -EINVAL; + goto done; + } + + txlen =3D len; + + if (len & BIT(0)) { + i++; + if (i > MAX_WRITE_IOMEM_RETRY) { + nxpwifi_dbg(adapter, ERROR, + "FW dnld failed @ %d, over max retry\n", + offset); + ret =3D -EIO; + goto done; + } + nxpwifi_dbg(adapter, ERROR, + "CRC indicated by the helper:\t" + "len =3D 0x%04X, txlen =3D %d\n", len, txlen); + len &=3D ~BIT(0); + /* Setting this to 0 to resend from same offset */ + txlen =3D 0; + } else { + i =3D 0; + + /* Set blocksize to transfer - checking for last + * block + */ + if (firmware_len - offset < txlen) + txlen =3D firmware_len - offset; + + tx_blocks =3D (txlen + NXPWIFI_SDIO_BLOCK_SIZE - 1) + / NXPWIFI_SDIO_BLOCK_SIZE; + + /* Copy payload to buffer */ + memmove(fwbuf, &firmware[offset], txlen); + } + + ret =3D nxpwifi_write_data_sync(adapter, fwbuf, tx_blocks * + NXPWIFI_SDIO_BLOCK_SIZE, + adapter->ioport); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "FW download, write iomem (%d) failed @ %d\n", + i, offset); + if (nxpwifi_write_reg(adapter, CONFIGURATION_REG, 0x04)) + nxpwifi_dbg(adapter, ERROR, + "write CFG reg failed\n"); + + goto done; + } + + offset +=3D txlen; + } while (true); + + nxpwifi_dbg(adapter, MSG, + "info: FW download over, size %d bytes\n", offset); + + ret =3D 0; +done: + sdio_release_host(card->func); + kfree(fwbuf); + return ret; +} + +/* This function decodes sdio aggregation pkt. + * + * Based on the data block size and pkt_len, + * skb data will be decoded to few packets. + */ +static void nxpwifi_deaggr_sdio_pkt(struct nxpwifi_adapter *adapter, + struct sk_buff *skb) +{ + u32 total_pkt_len, pkt_len; + struct sk_buff *skb_deaggr; + u16 blk_size; + u8 blk_num; + u8 *data; + + data =3D skb->data; + total_pkt_len =3D skb->len; + + while (total_pkt_len >=3D (SDIO_HEADER_OFFSET + adapter->intf_hdr_len)) { + if (total_pkt_len < adapter->sdio_rx_block_size) + break; + blk_num =3D *(data + BLOCK_NUMBER_OFFSET); + blk_size =3D adapter->sdio_rx_block_size * blk_num; + if (blk_size > total_pkt_len) { + nxpwifi_dbg(adapter, ERROR, + "%s: error in blk_size,\t" + "blk_num=3D%d, blk_size=3D%d, total_pkt_len=3D%d\n", + __func__, blk_num, blk_size, total_pkt_len); + break; + } + pkt_len =3D get_unaligned_le16((data + + SDIO_HEADER_OFFSET)); + if ((pkt_len + SDIO_HEADER_OFFSET) > blk_size) { + nxpwifi_dbg(adapter, ERROR, + "%s: error in pkt_len,\t" + "pkt_len=3D%d, blk_size=3D%d\n", + __func__, pkt_len, blk_size); + break; + } + + skb_deaggr =3D nxpwifi_alloc_dma_align_buf(pkt_len, GFP_KERNEL); + if (!skb_deaggr) + break; + skb_put(skb_deaggr, pkt_len); + memcpy(skb_deaggr->data, data + SDIO_HEADER_OFFSET, pkt_len); + skb_pull(skb_deaggr, adapter->intf_hdr_len); + + nxpwifi_handle_rx_packet(adapter, skb_deaggr); + data +=3D blk_size; + total_pkt_len -=3D blk_size; + } +} + +/* This function decodes a received packet. + * + * Based on the type, the packet is treated as either a data, or + * a command response, or an event, and the correct handler + * function is invoked. + */ +static void nxpwifi_decode_rx_packet(struct nxpwifi_adapter *adapter, + struct sk_buff *skb, u32 upld_typ) +{ + u8 *cmd_buf; + u16 pkt_len; + struct nxpwifi_rxinfo *rx_info; + + pkt_len =3D get_unaligned_le16(skb->data); + + if (upld_typ !=3D NXPWIFI_TYPE_AGGR_DATA) { + skb_trim(skb, pkt_len); + skb_pull(skb, adapter->intf_hdr_len); + } + + switch (upld_typ) { + case NXPWIFI_TYPE_AGGR_DATA: + nxpwifi_dbg(adapter, INFO, + "info: --- Rx: Aggr Data packet ---\n"); + rx_info =3D NXPWIFI_SKB_RXCB(skb); + rx_info->buf_type =3D NXPWIFI_TYPE_AGGR_DATA; + skb_queue_tail(&adapter->rx_data_q, skb); + adapter->data_received =3D true; + tasklet_schedule(&adapter->rx_task); + break; + + case NXPWIFI_TYPE_DATA: + nxpwifi_dbg(adapter, DATA, + "info: --- Rx: Data packet ---\n"); + skb_queue_tail(&adapter->rx_data_q, skb); + adapter->data_received =3D true; + tasklet_schedule(&adapter->rx_task); + break; + + case NXPWIFI_TYPE_CMD: + nxpwifi_dbg(adapter, CMD, + "info: --- Rx: Cmd Response ---\n"); + /* take care of curr_cmd =3D NULL case */ + if (!adapter->curr_cmd) { + cmd_buf =3D adapter->upld_buf; + + if (adapter->ps_state =3D=3D PS_STATE_SLEEP_CFM) + nxpwifi_process_sleep_confirm_resp(adapter, + skb->data, + skb->len); + + memcpy(cmd_buf, skb->data, + min_t(u32, NXPWIFI_SIZE_OF_CMD_BUFFER, + skb->len)); + + dev_kfree_skb_any(skb); + } else { + adapter->cmd_resp_received =3D true; + adapter->curr_cmd->resp_skb =3D skb; + } + break; + + case NXPWIFI_TYPE_EVENT: + nxpwifi_dbg(adapter, EVENT, + "info: --- Rx: Event ---\n"); + adapter->event_cause =3D get_unaligned_le32(skb->data); + + if (skb->len > 0 && skb->len < MAX_EVENT_SIZE) + memcpy(adapter->event_body, + skb->data + NXPWIFI_EVENT_HEADER_LEN, + skb->len); + + /* event cause has been saved to adapter->event_cause */ + adapter->event_received =3D true; + adapter->event_skb =3D skb; + + break; + + default: + nxpwifi_dbg(adapter, ERROR, + "unknown upload type %#x\n", upld_typ); + dev_kfree_skb_any(skb); + break; + } +} + +/* This function transfers received packets from card to driver, performing + * aggregation if required. + * + * For data received on control port, or if aggregation is disabled, the + * received buffers are uploaded as separate packets. However, if aggregat= ion + * is enabled and required, the buffers are copied onto an aggregation buf= fer, + * provided there is space left, processed and finally uploaded. + */ +static int nxpwifi_sdio_card_to_host_mp_aggr(struct nxpwifi_adapter *adapt= er, + u16 rx_len, u8 port) +{ + struct sdio_mmc_card *card =3D adapter->card; + s32 f_do_rx_aggr =3D 0; + s32 f_do_rx_cur =3D 0; + s32 f_aggr_cur =3D 0; + s32 f_post_aggr_cur =3D 0; + struct sk_buff *skb_deaggr; + struct sk_buff *skb =3D NULL; + u32 pkt_len, pkt_type, mport, pind; + u8 *curr_ptr; + int ret =3D 0; + + if (!card->mpa_rx.enabled) { + nxpwifi_dbg(adapter, WARN, + "info: %s: rx aggregation disabled\n", + __func__); + + f_do_rx_cur =3D 1; + goto rx_curr_single; + } + + if (card->mp_rd_bitmap & card->reg->data_port_mask) { + /* Some more data RX pending */ + nxpwifi_dbg(adapter, INFO, + "info: %s: not last packet\n", __func__); + + if (MP_RX_AGGR_IN_PROGRESS(card)) { + if (MP_RX_AGGR_BUF_HAS_ROOM(card, rx_len)) { + f_aggr_cur =3D 1; + } else { + /* No room in Aggr buf, do rx aggr now */ + f_do_rx_aggr =3D 1; + f_post_aggr_cur =3D 1; + } + } else { + /* Rx aggr not in progress */ + f_aggr_cur =3D 1; + } + + } else { + /* No more data RX pending */ + nxpwifi_dbg(adapter, INFO, + "info: %s: last packet\n", __func__); + + if (MP_RX_AGGR_IN_PROGRESS(card)) { + f_do_rx_aggr =3D 1; + if (MP_RX_AGGR_BUF_HAS_ROOM(card, rx_len)) + f_aggr_cur =3D 1; + else + /* No room in Aggr buf, do rx aggr now */ + f_do_rx_cur =3D 1; + } else { + f_do_rx_cur =3D 1; + } + } + + if (f_aggr_cur) { + nxpwifi_dbg(adapter, INFO, + "info: current packet aggregation\n"); + /* Curr pkt can be aggregated */ + mp_rx_aggr_setup(card, rx_len, port); + + if (MP_RX_AGGR_PKT_LIMIT_REACHED(card) || + mp_rx_aggr_port_limit_reached(card)) { + nxpwifi_dbg(adapter, INFO, + "info: %s: aggregated packet\t" + "limit reached\n", __func__); + /* No more pkts allowed in Aggr buf, rx it */ + f_do_rx_aggr =3D 1; + } + } + + if (f_do_rx_aggr) { + u32 port_count; + int i; + + /* do aggr RX now */ + nxpwifi_dbg(adapter, DATA, + "info: do_rx_aggr: num of packets: %d\n", + card->mpa_rx.pkt_cnt); + + for (i =3D 0, port_count =3D 0; i < card->max_ports; i++) + if (card->mpa_rx.ports & BIT(i)) + port_count++; + + /* Reading data from "start_port + 0" to "start_port + + * port_count -1", so decrease the count by 1 + */ + port_count--; + mport =3D (adapter->ioport | SDIO_MPA_ADDR_BASE | + (port_count << 8)) + card->mpa_rx.start_port; + + if (card->mpa_rx.pkt_cnt =3D=3D 1) + mport =3D adapter->ioport + card->mpa_rx.start_port; + + ret =3D nxpwifi_read_data_sync(adapter, card->mpa_rx.buf, + card->mpa_rx.buf_len, mport, 1); + if (ret) + goto error; + + curr_ptr =3D card->mpa_rx.buf; + + for (pind =3D 0; pind < card->mpa_rx.pkt_cnt; pind++) { + u32 *len_arr =3D card->mpa_rx.len_arr; + + /* get curr PKT len & type */ + pkt_len =3D get_unaligned_le16(&curr_ptr[0]); + pkt_type =3D get_unaligned_le16(&curr_ptr[2]); + + /* copy pkt to deaggr buf */ + skb_deaggr =3D nxpwifi_alloc_dma_align_buf(len_arr[pind], + GFP_KERNEL); + if (!skb_deaggr) { + nxpwifi_dbg(adapter, ERROR, "skb allocation failure\t" + "drop pkt len=3D%d type=3D%d\n", + pkt_len, pkt_type); + curr_ptr +=3D len_arr[pind]; + continue; + } + + skb_put(skb_deaggr, len_arr[pind]); + + if ((pkt_type =3D=3D NXPWIFI_TYPE_DATA || + (pkt_type =3D=3D NXPWIFI_TYPE_AGGR_DATA && + adapter->sdio_rx_aggr_enable)) && + pkt_len <=3D len_arr[pind]) { + memcpy(skb_deaggr->data, curr_ptr, pkt_len); + + skb_trim(skb_deaggr, pkt_len); + + /* Process de-aggr packet */ + nxpwifi_decode_rx_packet(adapter, skb_deaggr, + pkt_type); + } else { + nxpwifi_dbg(adapter, ERROR, + "drop wrong aggr pkt:\t" + "sdio_single_port_rx_aggr=3D%d\t" + "type=3D%d len=3D%d max_len=3D%d\n", + adapter->sdio_rx_aggr_enable, + pkt_type, pkt_len, len_arr[pind]); + dev_kfree_skb_any(skb_deaggr); + } + curr_ptr +=3D len_arr[pind]; + } + MP_RX_AGGR_BUF_RESET(card); + } + +rx_curr_single: + if (f_do_rx_cur) { + nxpwifi_dbg(adapter, INFO, "info: RX: port: %d, rx_len: %d\n", + port, rx_len); + + skb =3D nxpwifi_alloc_dma_align_buf(rx_len, GFP_KERNEL); + if (!skb) { + nxpwifi_dbg(adapter, ERROR, + "single skb allocated fail,\t" + "drop pkt port=3D%d len=3D%d\n", port, rx_len); + ret =3D nxpwifi_sdio_card_to_host(adapter, &pkt_type, + card->mpa_rx.buf, + rx_len, + adapter->ioport + port); + if (ret) + goto error; + return 0; + } + + skb_put(skb, rx_len); + + ret =3D nxpwifi_sdio_card_to_host(adapter, &pkt_type, + skb->data, skb->len, + adapter->ioport + port); + if (ret) + goto error; + if (!adapter->sdio_rx_aggr_enable && + pkt_type =3D=3D NXPWIFI_TYPE_AGGR_DATA) { + nxpwifi_dbg(adapter, ERROR, "drop wrong pkt type %d\t" + "current SDIO RX Aggr not enabled\n", + pkt_type); + dev_kfree_skb_any(skb); + return 0; + } + + nxpwifi_decode_rx_packet(adapter, skb, pkt_type); + } + if (f_post_aggr_cur) { + nxpwifi_dbg(adapter, INFO, + "info: current packet aggregation\n"); + /* Curr pkt can be aggregated */ + mp_rx_aggr_setup(card, rx_len, port); + } + + return 0; +error: + if (MP_RX_AGGR_IN_PROGRESS(card)) + MP_RX_AGGR_BUF_RESET(card); + + if (f_do_rx_cur && skb) + /* Single transfer pending. Free curr buff also */ + dev_kfree_skb_any(skb); + + return ret; +} + +/* This function checks the current interrupt status. + * + * The following interrupts are checked and handled by this function - + * - Data sent + * - Command sent + * - Packets received + * + * Since the firmware does not generate download ready interrupt if the + * port updated is command port only, command sent interrupt checking + * should be done manually, and for every SDIO interrupt. + * + * In case of Rx packets received, the packets are uploaded from card to + * host and processed accordingly. + */ +static int nxpwifi_process_int_status(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + int ret =3D 0; + u8 sdio_ireg; + struct sk_buff *skb; + u8 port; + u32 len_reg_l, len_reg_u; + u32 rx_blocks; + u16 rx_len; + unsigned long flags; + u32 bitmap; + u8 cr; + + spin_lock_irqsave(&adapter->int_lock, flags); + sdio_ireg =3D adapter->int_status; + adapter->int_status =3D 0; + spin_unlock_irqrestore(&adapter->int_lock, flags); + + if (!sdio_ireg) + return ret; + + if (sdio_ireg & DN_LD_CMD_PORT_HOST_INT_STATUS && adapter->cmd_sent) + adapter->cmd_sent =3D false; + + if (sdio_ireg & UP_LD_CMD_PORT_HOST_INT_STATUS) { + u32 pkt_type; + + /* read the len of control packet */ + rx_len =3D card->mp_regs[reg->cmd_rd_len_1] << 8; + rx_len |=3D (u16)card->mp_regs[reg->cmd_rd_len_0]; + rx_blocks =3D DIV_ROUND_UP(rx_len, NXPWIFI_SDIO_BLOCK_SIZE); + if (rx_len <=3D adapter->intf_hdr_len || + (rx_blocks * NXPWIFI_SDIO_BLOCK_SIZE) > + NXPWIFI_RX_DATA_BUF_SIZE) + return -EINVAL; + rx_len =3D (u16)(rx_blocks * NXPWIFI_SDIO_BLOCK_SIZE); + nxpwifi_dbg(adapter, INFO, "info: rx_len =3D %d\n", rx_len); + + skb =3D nxpwifi_alloc_dma_align_buf(rx_len, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + skb_put(skb, rx_len); + + ret =3D nxpwifi_sdio_card_to_host(adapter, &pkt_type, skb->data, + skb->len, adapter->ioport | + CMD_PORT_SLCT); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "%s: failed to card_to_host", __func__); + dev_kfree_skb_any(skb); + goto term_cmd; + } + + if (pkt_type !=3D NXPWIFI_TYPE_CMD && + pkt_type !=3D NXPWIFI_TYPE_EVENT) + nxpwifi_dbg(adapter, ERROR, + "%s:Received wrong packet on cmd port", + __func__); + + nxpwifi_decode_rx_packet(adapter, skb, pkt_type); + } + + if (sdio_ireg & DN_LD_HOST_INT_STATUS) { + bitmap =3D (u32)card->mp_regs[reg->wr_bitmap_l]; + bitmap |=3D ((u32)card->mp_regs[reg->wr_bitmap_u]) << 8; + bitmap |=3D ((u32)card->mp_regs[reg->wr_bitmap_1l]) << 16; + bitmap |=3D ((u32)card->mp_regs[reg->wr_bitmap_1u]) << 24; + card->mp_wr_bitmap =3D bitmap; + + nxpwifi_dbg(adapter, INTR, + "int: DNLD: wr_bitmap=3D0x%x\n", + card->mp_wr_bitmap); + if (adapter->data_sent && + (card->mp_wr_bitmap & card->mp_data_port_mask)) { + nxpwifi_dbg(adapter, INTR, + "info: <--- Tx DONE Interrupt --->\n"); + adapter->data_sent =3D false; + } + } + + nxpwifi_dbg(adapter, INTR, "info: cmd_sent=3D%d data_sent=3D%d\n", + adapter->cmd_sent, adapter->data_sent); + if (sdio_ireg & UP_LD_HOST_INT_STATUS) { + bitmap =3D (u32)card->mp_regs[reg->rd_bitmap_l]; + bitmap |=3D ((u32)card->mp_regs[reg->rd_bitmap_u]) << 8; + bitmap |=3D ((u32)card->mp_regs[reg->rd_bitmap_1l]) << 16; + bitmap |=3D ((u32)card->mp_regs[reg->rd_bitmap_1u]) << 24; + card->mp_rd_bitmap =3D bitmap; + nxpwifi_dbg(adapter, INTR, + "int: UPLD: rd_bitmap=3D0x%x\n", + card->mp_rd_bitmap); + + while (true) { + ret =3D nxpwifi_get_rd_port(adapter, &port); + if (ret) { + nxpwifi_dbg(adapter, INFO, + "info: no more rd_port available\n"); + break; + } + len_reg_l =3D reg->rd_len_p0_l + (port << 1); + len_reg_u =3D reg->rd_len_p0_u + (port << 1); + rx_len =3D ((u16)card->mp_regs[len_reg_u]) << 8; + rx_len |=3D (u16)card->mp_regs[len_reg_l]; + nxpwifi_dbg(adapter, INFO, + "info: RX: port=3D%d rx_len=3D%u\n", + port, rx_len); + rx_blocks =3D + (rx_len + NXPWIFI_SDIO_BLOCK_SIZE - + 1) / NXPWIFI_SDIO_BLOCK_SIZE; + if (rx_len <=3D adapter->intf_hdr_len || + (card->mpa_rx.enabled && + ((rx_blocks * NXPWIFI_SDIO_BLOCK_SIZE) > + card->mpa_rx.buf_size))) { + nxpwifi_dbg(adapter, ERROR, + "invalid rx_len=3D%d\n", + rx_len); + return -EINVAL; + } + + rx_len =3D (u16)(rx_blocks * NXPWIFI_SDIO_BLOCK_SIZE); + nxpwifi_dbg(adapter, INFO, "info: rx_len =3D %d\n", + rx_len); + + ret =3D nxpwifi_sdio_card_to_host_mp_aggr(adapter, rx_len, + port); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "card_to_host_mpa failed: int status=3D%#x\n", + sdio_ireg); + goto term_cmd; + } + } + } + + return 0; + +term_cmd: + /* terminate cmd */ + if (nxpwifi_read_reg(adapter, CONFIGURATION_REG, &cr)) + nxpwifi_dbg(adapter, ERROR, "read CFG reg failed\n"); + else + nxpwifi_dbg(adapter, INFO, + "info: CFG reg val =3D %d\n", cr); + + if (nxpwifi_write_reg(adapter, CONFIGURATION_REG, (cr | 0x04))) + nxpwifi_dbg(adapter, ERROR, + "write CFG reg failed\n"); + else + nxpwifi_dbg(adapter, INFO, "info: write success\n"); + + if (nxpwifi_read_reg(adapter, CONFIGURATION_REG, &cr)) + nxpwifi_dbg(adapter, ERROR, + "read CFG reg failed\n"); + else + nxpwifi_dbg(adapter, INFO, + "info: CFG reg val =3D%x\n", cr); + + return ret; +} + +/* This function aggregates transmission buffers in driver and downloads + * the aggregated packet to card. + * + * The individual packets are aggregated by copying into an aggregation + * buffer and then downloaded to the card. Previous unsent packets in the + * aggregation buffer are pre-copied first before new packets are added. + * Aggregation is done till there is space left in the aggregation buffer, + * or till new packets are available. + * + * The function will only download the packet to the card when aggregation + * stops, otherwise it will just aggregate the packet in aggregation buffer + * and return. + */ +static int nxpwifi_host_to_card_mp_aggr(struct nxpwifi_adapter *adapter, + u8 *payload, u32 pkt_len, u32 port, + u32 next_pkt_len) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret =3D 0; + s32 f_send_aggr_buf =3D 0; + s32 f_send_cur_buf =3D 0; + s32 f_precopy_cur_buf =3D 0; + s32 f_postcopy_cur_buf =3D 0; + u32 mport; + int index; + + if (!card->mpa_tx.enabled || port =3D=3D CMD_PORT_SLCT) { + nxpwifi_dbg(adapter, WARN, + "info: %s: tx aggregation disabled\n", + __func__); + + f_send_cur_buf =3D 1; + goto tx_curr_single; + } + + if (next_pkt_len) { + /* More pkt in TX queue */ + nxpwifi_dbg(adapter, INFO, + "info: %s: more packets in queue.\n", + __func__); + + if (MP_TX_AGGR_IN_PROGRESS(card)) { + if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) { + f_precopy_cur_buf =3D 1; + + if (!(card->mp_wr_bitmap & + (1 << card->curr_wr_port)) || + !MP_TX_AGGR_BUF_HAS_ROOM + (card, pkt_len + next_pkt_len)) + f_send_aggr_buf =3D 1; + } else { + /* No room in Aggr buf, send it */ + f_send_aggr_buf =3D 1; + + if (!(card->mp_wr_bitmap & + (1 << card->curr_wr_port))) + f_send_cur_buf =3D 1; + else + f_postcopy_cur_buf =3D 1; + } + } else { + if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len) && + (card->mp_wr_bitmap & (1 << card->curr_wr_port))) + f_precopy_cur_buf =3D 1; + else + f_send_cur_buf =3D 1; + } + } else { + /* Last pkt in TX queue */ + nxpwifi_dbg(adapter, INFO, + "info: %s: Last packet in Tx Queue.\n", + __func__); + + if (MP_TX_AGGR_IN_PROGRESS(card)) { + /* some packs in Aggr buf already */ + f_send_aggr_buf =3D 1; + + if (MP_TX_AGGR_BUF_HAS_ROOM(card, pkt_len)) + f_precopy_cur_buf =3D 1; + else + /* No room in Aggr buf, send it */ + f_send_cur_buf =3D 1; + } else { + f_send_cur_buf =3D 1; + } + } + + if (f_precopy_cur_buf) { + nxpwifi_dbg(adapter, DATA, + "data: %s: precopy current buffer\n", + __func__); + MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port); + + if (MP_TX_AGGR_PKT_LIMIT_REACHED(card) || + mp_tx_aggr_port_limit_reached(card)) + /* No more pkts allowed in Aggr buf, send it */ + f_send_aggr_buf =3D 1; + } + + if (f_send_aggr_buf) { + u32 port_count; + int i; + + nxpwifi_dbg(adapter, DATA, + "data: %s: send aggr buffer: %d %d\n", + __func__, card->mpa_tx.start_port, + card->mpa_tx.ports); + + for (i =3D 0, port_count =3D 0; i < card->max_ports; i++) + if (card->mpa_tx.ports & BIT(i)) + port_count++; + + /* Writing data from "start_port + 0" to "start_port + + * port_count -1", so decrease the count by 1 + */ + port_count--; + mport =3D (adapter->ioport | SDIO_MPA_ADDR_BASE | + (port_count << 8)) + card->mpa_tx.start_port; + + if (card->mpa_tx.pkt_cnt =3D=3D 1) + mport =3D adapter->ioport + card->mpa_tx.start_port; + + ret =3D nxpwifi_write_data_to_card(adapter, card->mpa_tx.buf, + card->mpa_tx.buf_len, mport); + + /* Save the last multi port tx aggregation info to debug log */ + index =3D adapter->dbg.last_sdio_mp_index; + index =3D (index + 1) % NXPWIFI_DBG_SDIO_MP_NUM; + adapter->dbg.last_sdio_mp_index =3D index; + adapter->dbg.last_mp_wr_ports[index] =3D mport; + adapter->dbg.last_mp_wr_bitmap[index] =3D card->mp_wr_bitmap; + adapter->dbg.last_mp_wr_len[index] =3D card->mpa_tx.buf_len; + adapter->dbg.last_mp_curr_wr_port[index] =3D card->curr_wr_port; + + MP_TX_AGGR_BUF_RESET(card); + } + +tx_curr_single: + if (f_send_cur_buf) { + nxpwifi_dbg(adapter, DATA, + "data: %s: send current buffer %d\n", + __func__, port); + ret =3D nxpwifi_write_data_to_card(adapter, payload, pkt_len, + adapter->ioport + port); + } + + if (f_postcopy_cur_buf) { + nxpwifi_dbg(adapter, DATA, + "data: %s: postcopy current buffer\n", + __func__); + MP_TX_AGGR_BUF_PUT(card, payload, pkt_len, port); + } + + return ret; +} + +/* This function downloads data from driver to card. + * + * Both commands and data packets are transferred to the card by this + * function. + * + * This function adds the SDIO specific header to the front of the buffer + * before transferring. The header contains the length of the packet and + * the type. The firmware handles the packets based upon this set type. + */ +static int nxpwifi_sdio_host_to_card(struct nxpwifi_adapter *adapter, + u8 type, struct sk_buff *skb, + struct nxpwifi_tx_param *tx_param) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret; + u32 buf_block_len; + u32 blk_size; + u32 port; + u8 *payload =3D (u8 *)skb->data; + u32 pkt_len =3D skb->len; + + /* Allocate buffer and copy payload */ + blk_size =3D NXPWIFI_SDIO_BLOCK_SIZE; + buf_block_len =3D (pkt_len + blk_size - 1) / blk_size; + put_unaligned_le16((u16)pkt_len, payload + 0); + put_unaligned_le16((u16)type, payload + 2); + + /* This is SDIO specific header + * u16 length, + * u16 type (NXPWIFI_TYPE_DATA =3D 0, NXPWIFI_TYPE_CMD =3D 1, + * NXPWIFI_TYPE_EVENT =3D 3) + */ + if (type =3D=3D NXPWIFI_TYPE_DATA) { + ret =3D nxpwifi_get_wr_port_data(adapter, &port); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "%s: no wr_port available\n", + __func__); + return ret; + } + } else { + adapter->cmd_sent =3D true; + + if (pkt_len <=3D adapter->intf_hdr_len || + pkt_len > NXPWIFI_UPLD_SIZE) + nxpwifi_dbg(adapter, ERROR, + "%s: payload=3D%p, nb=3D%d\n", + __func__, payload, pkt_len); + + port =3D CMD_PORT_SLCT; + } + + /* Transfer data to card */ + pkt_len =3D buf_block_len * blk_size; + + if (tx_param) + ret =3D nxpwifi_host_to_card_mp_aggr(adapter, payload, pkt_len, + port, tx_param->next_pkt_len + ); + else + ret =3D nxpwifi_host_to_card_mp_aggr(adapter, payload, pkt_len, + port, 0); + + if (ret) { + if (type =3D=3D NXPWIFI_TYPE_CMD || + type =3D=3D NXPWIFI_TYPE_VDLL) + adapter->cmd_sent =3D false; + if (type =3D=3D NXPWIFI_TYPE_DATA) { + adapter->data_sent =3D false; + /* restore curr_wr_port in error cases */ + card->curr_wr_port =3D port; + card->mp_wr_bitmap |=3D (u32)(1 << card->curr_wr_port); + } + } else { + if (type =3D=3D NXPWIFI_TYPE_DATA) { + if (!(card->mp_wr_bitmap & (1 << card->curr_wr_port))) + adapter->data_sent =3D true; + else + adapter->data_sent =3D false; + } + } + + return ret; +} + +/* This function allocates the MPA Tx and Rx buffers. + */ +static int nxpwifi_alloc_sdio_mpa_buffers(struct nxpwifi_adapter *adapter, + u32 mpa_tx_buf_size, + u32 mpa_rx_buf_size) +{ + struct sdio_mmc_card *card =3D adapter->card; + u32 rx_buf_size; + int ret =3D 0; + + card->mpa_tx.buf =3D kzalloc(mpa_tx_buf_size, GFP_KERNEL); + if (!card->mpa_tx.buf) { + ret =3D -ENOMEM; + goto error; + } + + card->mpa_tx.buf_size =3D mpa_tx_buf_size; + + rx_buf_size =3D max_t(u32, mpa_rx_buf_size, + (u32)SDIO_MAX_AGGR_BUF_SIZE); + card->mpa_rx.buf =3D kzalloc(rx_buf_size, GFP_KERNEL); + if (!card->mpa_rx.buf) { + ret =3D -ENOMEM; + goto error; + } + + card->mpa_rx.buf_size =3D rx_buf_size; + +error: + if (ret) { + kfree(card->mpa_tx.buf); + kfree(card->mpa_rx.buf); + card->mpa_tx.buf_size =3D 0; + card->mpa_rx.buf_size =3D 0; + card->mpa_tx.buf =3D NULL; + card->mpa_rx.buf =3D NULL; + } + + return ret; +} + +/* This function unregisters the SDIO device. + * + * The function is disabled and driver + * data is set to null. + */ +static void +nxpwifi_unregister_dev(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + + if (adapter->card) { + card->adapter =3D NULL; + sdio_claim_host(card->func); + sdio_disable_func(card->func); + sdio_release_host(card->func); + } +} + +/* This function registers the SDIO device. + * + * SDIO IRQ is claimed, block size is set and driver data is initialized. + */ +static int nxpwifi_register_dev(struct nxpwifi_adapter *adapter) +{ + int ret; + struct sdio_mmc_card *card =3D adapter->card; + struct sdio_func *func =3D card->func; + const char *firmware =3D card->firmware; + + /* save adapter pointer in card */ + card->adapter =3D adapter; + adapter->tx_buf_size =3D card->tx_buf_size; + + sdio_claim_host(func); + + /* Set block size */ + ret =3D sdio_set_block_size(card->func, NXPWIFI_SDIO_BLOCK_SIZE); + sdio_release_host(func); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "cannot set SDIO block size\n"); + return ret; + } + + /* Select correct firmware (sdsd or sdiouart) firmware based on the strap= ping + * option + */ + if (card->firmware_sdiouart) { + u8 val; + + nxpwifi_read_reg(adapter, card->reg->host_strap_reg, &val); + if ((val & card->reg->host_strap_mask) =3D=3D card->reg->host_strap_valu= e) + firmware =3D card->firmware_sdiouart; + } + strscpy(adapter->fw_name, firmware, sizeof(adapter->fw_name)); + + if (card->fw_dump_enh) { + adapter->mem_type_mapping_tbl =3D generic_mem_type_map; + adapter->num_mem_types =3D 1; + } else { + adapter->mem_type_mapping_tbl =3D mem_type_mapping_tbl; + adapter->num_mem_types =3D ARRAY_SIZE(mem_type_mapping_tbl); + } + + return 0; +} + +/* This function initializes the SDIO driver. + * + * The following initializations steps are followed - + * - Read the Host interrupt status register to acknowledge + * the first interrupt got from bootloader + * - Disable host interrupt mask register + * - Get SDIO port + * - Initialize SDIO variables in card + * - Allocate MP registers + * - Allocate MPA Tx and Rx buffers + */ +static int nxpwifi_init_sdio(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + int ret; + u8 sdio_ireg; + + sdio_set_drvdata(card->func, card); + + /* Read the host_int_status_reg for ACK the first interrupt got + * from the bootloader. If we don't do this we get a interrupt + * as soon as we register the irq. + */ + nxpwifi_read_reg(adapter, card->reg->host_int_status_reg, &sdio_ireg); + + /* Get SDIO ioport */ + if (nxpwifi_init_sdio_ioport(adapter)) + return -EIO; + + /* Initialize SDIO variables in card */ + card->mp_rd_bitmap =3D 0; + card->mp_wr_bitmap =3D 0; + card->curr_rd_port =3D reg->start_rd_port; + card->curr_wr_port =3D reg->start_wr_port; + + card->mp_data_port_mask =3D reg->data_port_mask; + + card->mpa_tx.buf_len =3D 0; + card->mpa_tx.pkt_cnt =3D 0; + card->mpa_tx.start_port =3D 0; + + card->mpa_tx.enabled =3D 1; + card->mpa_tx.pkt_aggr_limit =3D card->mp_agg_pkt_limit; + + card->mpa_rx.buf_len =3D 0; + card->mpa_rx.pkt_cnt =3D 0; + card->mpa_rx.start_port =3D 0; + + card->mpa_rx.enabled =3D 1; + card->mpa_rx.pkt_aggr_limit =3D card->mp_agg_pkt_limit; + + /* Allocate buffers for SDIO MP-A */ + card->mp_regs =3D kzalloc(reg->max_mp_regs, GFP_KERNEL); + if (!card->mp_regs) + return -ENOMEM; + + card->mpa_rx.len_arr =3D kcalloc(card->mp_agg_pkt_limit, + sizeof(*card->mpa_rx.len_arr), + GFP_KERNEL); + if (!card->mpa_rx.len_arr) { + kfree(card->mp_regs); + return -ENOMEM; + } + + ret =3D nxpwifi_alloc_sdio_mpa_buffers(adapter, + card->mp_tx_agg_buf_size, + card->mp_rx_agg_buf_size); + + /* Allocate 32k MPA Tx/Rx buffers if 64k memory allocation fails */ + if (ret && (card->mp_tx_agg_buf_size =3D=3D NXPWIFI_MP_AGGR_BSIZE_MAX || + card->mp_rx_agg_buf_size =3D=3D NXPWIFI_MP_AGGR_BSIZE_MAX)) { + /* Disable rx single port aggregation */ + adapter->host_disable_sdio_rx_aggr =3D true; + + ret =3D nxpwifi_alloc_sdio_mpa_buffers(adapter, + NXPWIFI_MP_AGGR_BSIZE_32K, + NXPWIFI_MP_AGGR_BSIZE_32K); + if (ret) { + /* Disable multi port aggregation */ + card->mpa_tx.enabled =3D 0; + card->mpa_rx.enabled =3D 0; + } + } + + adapter->ext_scan =3D card->can_ext_scan; + return ret; +} + +/* This function resets the MPA Tx and Rx buffers. + */ +static void nxpwifi_cleanup_mpa_buf(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + + MP_TX_AGGR_BUF_RESET(card); + MP_RX_AGGR_BUF_RESET(card); +} + +/* This function cleans up the allocated card buffers. + * + * The following are freed by this function - + * - MP registers + * - MPA Tx buffer + * - MPA Rx buffer + */ +static void nxpwifi_cleanup_sdio(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + + cancel_work_sync(&card->work); + + kfree(card->mp_regs); + kfree(card->mpa_rx.len_arr); + kfree(card->mpa_tx.buf); + kfree(card->mpa_rx.buf); +} + +/* This function updates the MP end port in card. + */ +static void +nxpwifi_update_mp_end_port(struct nxpwifi_adapter *adapter, u16 port) +{ + struct sdio_mmc_card *card =3D adapter->card; + const struct nxpwifi_sdio_card_reg *reg =3D card->reg; + int i; + + card->mp_end_port =3D port; + + card->mp_data_port_mask =3D reg->data_port_mask; + + if (reg->start_wr_port) { + for (i =3D 1; i <=3D card->max_ports - card->mp_end_port; i++) + card->mp_data_port_mask &=3D + ~(1 << (card->max_ports - i)); + } + + card->curr_wr_port =3D reg->start_wr_port; + + nxpwifi_dbg(adapter, CMD, + "cmd: mp_end_port %d, data port mask 0x%x\n", + port, card->mp_data_port_mask); +} + +static void nxpwifi_sdio_card_reset_work(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + struct sdio_func *func =3D card->func; + int ret; + + /* Prepare the adapter for the reset. */ + nxpwifi_shutdown_sw(adapter); + clear_bit(NXPWIFI_IFACE_WORK_DEVICE_DUMP, &card->work_flags); + clear_bit(NXPWIFI_IFACE_WORK_CARD_RESET, &card->work_flags); + + /* Run a HW reset of the SDIO interface. */ + sdio_claim_host(func); + ret =3D mmc_hw_reset(func->card); + sdio_release_host(func); + + switch (ret) { + case 1: + dev_dbg(&func->dev, "SDIO HW reset asynchronous\n"); + complete_all(adapter->fw_done); + break; + case 0: + ret =3D nxpwifi_reinit_sw(adapter); + if (ret) + dev_err(&func->dev, "reinit failed: %d\n", ret); + break; + default: + dev_err(&func->dev, "SDIO HW reset failed: %d\n", ret); + break; + } +} + +/* This function read/write firmware */ +static enum +rdwr_status nxpwifi_sdio_rdwr_firmware(struct nxpwifi_adapter *adapter, + u8 doneflag) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret, tries; + u8 ctrl_data =3D 0; + + sdio_writeb(card->func, card->reg->fw_dump_host_ready, + card->reg->fw_dump_ctrl, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, "SDIO Write ERR\n"); + return RDWR_STATUS_FAILURE; + } + for (tries =3D 0; tries < MAX_POLL_TRIES; tries++) { + ctrl_data =3D sdio_readb(card->func, card->reg->fw_dump_ctrl, + &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, "SDIO read err\n"); + return RDWR_STATUS_FAILURE; + } + if (ctrl_data =3D=3D FW_DUMP_DONE) + break; + if (doneflag && ctrl_data =3D=3D doneflag) + return RDWR_STATUS_DONE; + if (ctrl_data !=3D card->reg->fw_dump_host_ready) { + nxpwifi_dbg(adapter, WARN, + "The ctrl reg was changed, re-try again\n"); + sdio_writeb(card->func, card->reg->fw_dump_host_ready, + card->reg->fw_dump_ctrl, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, "SDIO write err\n"); + return RDWR_STATUS_FAILURE; + } + } + usleep_range(100, 200); + } + if (ctrl_data =3D=3D card->reg->fw_dump_host_ready) { + nxpwifi_dbg(adapter, ERROR, + "Fail to pull ctrl_data\n"); + return RDWR_STATUS_FAILURE; + } + + return RDWR_STATUS_SUCCESS; +} + +/* This function dump firmware memory to file */ +static void nxpwifi_sdio_fw_dump(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + int ret =3D 0; + unsigned int reg, reg_start, reg_end; + u8 *dbg_ptr, *end_ptr, dump_num, idx, i, read_reg, doneflag =3D 0; + enum rdwr_status stat; + u32 memory_size; + + if (!card->can_dump_fw) + return; + + for (idx =3D 0; idx < ARRAY_SIZE(mem_type_mapping_tbl); idx++) { + struct memory_type_mapping *entry =3D &mem_type_mapping_tbl[idx]; + + if (entry->mem_ptr) { + vfree(entry->mem_ptr); + entry->mem_ptr =3D NULL; + } + entry->mem_size =3D 0; + } + + nxpwifi_pm_wakeup_card(adapter); + sdio_claim_host(card->func); + + nxpwifi_dbg(adapter, MSG, "=3D=3D nxpwifi firmware dump start =3D=3D\n"); + + stat =3D nxpwifi_sdio_rdwr_firmware(adapter, doneflag); + if (stat =3D=3D RDWR_STATUS_FAILURE) + goto done; + + reg =3D card->reg->fw_dump_start; + /* Read the number of the memories which will dump */ + dump_num =3D sdio_readb(card->func, reg, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, "SDIO read memory length err\n"); + goto done; + } + + /* Read the length of every memory which will dump */ + for (idx =3D 0; idx < dump_num; idx++) { + struct memory_type_mapping *entry =3D &mem_type_mapping_tbl[idx]; + + stat =3D nxpwifi_sdio_rdwr_firmware(adapter, doneflag); + if (stat =3D=3D RDWR_STATUS_FAILURE) + goto done; + + memory_size =3D 0; + reg =3D card->reg->fw_dump_start; + for (i =3D 0; i < 4; i++) { + read_reg =3D sdio_readb(card->func, reg, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, "SDIO read err\n"); + goto done; + } + memory_size |=3D (read_reg << i * 8); + reg++; + } + + if (memory_size =3D=3D 0) { + nxpwifi_dbg(adapter, DUMP, "Firmware dump Finished!\n"); + ret =3D nxpwifi_write_reg(adapter, + card->reg->fw_dump_ctrl, + FW_DUMP_READ_DONE); + if (ret) { + nxpwifi_dbg(adapter, ERROR, "SDIO write err\n"); + return; + } + break; + } + + nxpwifi_dbg(adapter, DUMP, + "%s_SIZE=3D0x%x\n", entry->mem_name, memory_size); + entry->mem_ptr =3D vmalloc(memory_size + 1); + entry->mem_size =3D memory_size; + if (!entry->mem_ptr) + goto done; + dbg_ptr =3D entry->mem_ptr; + end_ptr =3D dbg_ptr + memory_size; + + doneflag =3D entry->done_flag; + nxpwifi_dbg(adapter, DUMP, + "Start %s output, please wait...\n", + entry->mem_name); + + do { + stat =3D nxpwifi_sdio_rdwr_firmware(adapter, doneflag); + if (stat =3D=3D RDWR_STATUS_FAILURE) + goto done; + + reg_start =3D card->reg->fw_dump_start; + reg_end =3D card->reg->fw_dump_end; + for (reg =3D reg_start; reg <=3D reg_end; reg++) { + *dbg_ptr =3D sdio_readb(card->func, reg, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "SDIO read err\n"); + goto done; + } + if (dbg_ptr < end_ptr) + dbg_ptr++; + else + nxpwifi_dbg(adapter, ERROR, + "Allocated buf not enough\n"); + } + + if (stat !=3D RDWR_STATUS_DONE) + continue; + + nxpwifi_dbg(adapter, DUMP, "%s done: size=3D0x%tx\n", + entry->mem_name, dbg_ptr - entry->mem_ptr); + break; + } while (1); + } + nxpwifi_dbg(adapter, MSG, "=3D=3D nxpwifi firmware dump end =3D=3D\n"); + +done: + sdio_release_host(card->func); +} + +static void nxpwifi_sdio_generic_fw_dump(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + struct memory_type_mapping *entry =3D &generic_mem_type_map[0]; + unsigned int reg, reg_start, reg_end; + u8 start_flag =3D 0, done_flag =3D 0; + u8 *dbg_ptr, *end_ptr; + enum rdwr_status stat; + int ret =3D -EPERM, tries; + + if (!card->fw_dump_enh) + return; + + if (entry->mem_ptr) { + vfree(entry->mem_ptr); + entry->mem_ptr =3D NULL; + } + entry->mem_size =3D 0; + + nxpwifi_pm_wakeup_card(adapter); + sdio_claim_host(card->func); + + nxpwifi_dbg(adapter, MSG, "=3D=3D nxpwifi firmware dump start =3D=3D\n"); + + stat =3D nxpwifi_sdio_rdwr_firmware(adapter, done_flag); + if (stat =3D=3D RDWR_STATUS_FAILURE) + goto done; + + reg_start =3D card->reg->fw_dump_start; + reg_end =3D card->reg->fw_dump_end; + for (reg =3D reg_start; reg <=3D reg_end; reg++) { + for (tries =3D 0; tries < MAX_POLL_TRIES; tries++) { + start_flag =3D sdio_readb(card->func, reg, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "SDIO read err\n"); + goto done; + } + if (start_flag =3D=3D 0) + break; + if (tries =3D=3D MAX_POLL_TRIES) { + nxpwifi_dbg(adapter, ERROR, + "FW not ready to dump\n"); + ret =3D -EPERM; + goto done; + } + } + usleep_range(100, 200); + } + + entry->mem_ptr =3D vmalloc(0xf0000 + 1); + if (!entry->mem_ptr) { + ret =3D -ENOMEM; + goto done; + } + dbg_ptr =3D entry->mem_ptr; + entry->mem_size =3D 0xf0000; + end_ptr =3D dbg_ptr + entry->mem_size; + + done_flag =3D entry->done_flag; + nxpwifi_dbg(adapter, DUMP, + "Start %s output, please wait...\n", entry->mem_name); + + while (true) { + stat =3D nxpwifi_sdio_rdwr_firmware(adapter, done_flag); + if (stat =3D=3D RDWR_STATUS_FAILURE) + goto done; + for (reg =3D reg_start; reg <=3D reg_end; reg++) { + *dbg_ptr =3D sdio_readb(card->func, reg, &ret); + if (ret) { + nxpwifi_dbg(adapter, ERROR, + "SDIO read err\n"); + goto done; + } + dbg_ptr++; + if (dbg_ptr >=3D end_ptr) { + u8 *tmp_ptr; + + tmp_ptr =3D vmalloc(entry->mem_size + 0x4000 + 1); + if (!tmp_ptr) + goto done; + + memcpy(tmp_ptr, entry->mem_ptr, + entry->mem_size); + vfree(entry->mem_ptr); + entry->mem_ptr =3D tmp_ptr; + tmp_ptr =3D NULL; + dbg_ptr =3D entry->mem_ptr + entry->mem_size; + entry->mem_size +=3D 0x4000; + end_ptr =3D entry->mem_ptr + entry->mem_size; + } + } + if (stat =3D=3D RDWR_STATUS_DONE) { + entry->mem_size =3D dbg_ptr - entry->mem_ptr; + nxpwifi_dbg(adapter, DUMP, "dump %s done size=3D0x%x\n", + entry->mem_name, entry->mem_size); + ret =3D 0; + break; + } + } + nxpwifi_dbg(adapter, MSG, "=3D=3D nxpwifi firmware dump end =3D=3D\n"); + +done: + if (ret) { + nxpwifi_dbg(adapter, ERROR, "firmware dump failed\n"); + if (entry->mem_ptr) { + vfree(entry->mem_ptr); + entry->mem_ptr =3D NULL; + } + entry->mem_size =3D 0; + } + sdio_release_host(card->func); +} + +static void nxpwifi_sdio_device_dump_work(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + + adapter->devdump_data =3D vzalloc(NXPWIFI_FW_DUMP_SIZE); + if (!adapter->devdump_data) + return; + + nxpwifi_drv_info_dump(adapter); + if (card->fw_dump_enh) + nxpwifi_sdio_generic_fw_dump(adapter); + else + nxpwifi_sdio_fw_dump(adapter); + nxpwifi_prepare_fw_dump_info(adapter); + nxpwifi_upload_device_dump(adapter); +} + +static void nxpwifi_sdio_work(struct work_struct *work) +{ + struct sdio_mmc_card *card =3D + container_of(work, struct sdio_mmc_card, work); + + if (test_and_clear_bit(NXPWIFI_IFACE_WORK_DEVICE_DUMP, + &card->work_flags)) + nxpwifi_sdio_device_dump_work(card->adapter); + if (test_and_clear_bit(NXPWIFI_IFACE_WORK_CARD_RESET, + &card->work_flags)) + nxpwifi_sdio_card_reset_work(card->adapter); +} + +/* This function resets the card */ +static void nxpwifi_sdio_card_reset(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + + if (!test_and_set_bit(NXPWIFI_IFACE_WORK_CARD_RESET, &card->work_flags)) + nxpwifi_queue_work(adapter, &card->work); +} + +/* This function dumps FW information */ +static void nxpwifi_sdio_device_dump(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + + if (!test_and_set_bit(NXPWIFI_IFACE_WORK_DEVICE_DUMP, + &card->work_flags)) + nxpwifi_queue_work(adapter, &card->work); +} + +/* Function to dump SDIO function registers and SDIO scratch registers in = case + * of FW crash + */ +static int +nxpwifi_sdio_reg_dump(struct nxpwifi_adapter *adapter, char *drv_buf) +{ + char *p =3D drv_buf; + struct sdio_mmc_card *cardp =3D adapter->card; + int ret =3D 0; + u8 count, func, data, index =3D 0, size =3D 0; + u8 reg, reg_start, reg_end; + char buf[256], *ptr; + + if (!p) + return 0; + + nxpwifi_dbg(adapter, MSG, "SDIO register dump start\n"); + + nxpwifi_pm_wakeup_card(adapter); + + sdio_claim_host(cardp->func); + + for (count =3D 0; count < 5; count++) { + memset(buf, 0, sizeof(buf)); + ptr =3D buf; + + switch (count) { + case 0: + /* Read the registers of SDIO function0 */ + func =3D count; + reg_start =3D 0; + reg_end =3D 9; + break; + case 1: + /* Read the registers of SDIO function1 */ + func =3D count; + reg_start =3D cardp->reg->func1_dump_reg_start; + reg_end =3D cardp->reg->func1_dump_reg_end; + break; + case 2: + index =3D 0; + func =3D 1; + reg_start =3D cardp->reg->func1_spec_reg_table[index++]; + size =3D cardp->reg->func1_spec_reg_num; + reg_end =3D cardp->reg->func1_spec_reg_table[size - 1]; + break; + default: + /* Read the scratch registers of SDIO function1 */ + if (count =3D=3D 4) + mdelay(100); + func =3D 1; + reg_start =3D cardp->reg->func1_scratch_reg; + reg_end =3D reg_start + NXPWIFI_SDIO_SCRATCH_SIZE; + } + + if (count !=3D 2) + ptr +=3D sprintf(ptr, "SDIO Func%d (%#x-%#x): ", + func, reg_start, reg_end); + else + ptr +=3D sprintf(ptr, "SDIO Func%d: ", func); + + for (reg =3D reg_start; reg <=3D reg_end;) { + if (func =3D=3D 0) + data =3D sdio_f0_readb(cardp->func, reg, &ret); + else + data =3D sdio_readb(cardp->func, reg, &ret); + + if (count =3D=3D 2) + ptr +=3D sprintf(ptr, "(%#x) ", reg); + if (!ret) { + ptr +=3D sprintf(ptr, "%02x ", data); + } else { + ptr +=3D sprintf(ptr, "ERR"); + break; + } + + if (count =3D=3D 2 && reg < reg_end) + reg =3D cardp->reg->func1_spec_reg_table[index++]; + else + reg++; + } + + nxpwifi_dbg(adapter, MSG, "%s\n", buf); + p +=3D sprintf(p, "%s\n", buf); + } + + sdio_release_host(cardp->func); + + nxpwifi_dbg(adapter, MSG, "SDIO register dump end\n"); + + return p - drv_buf; +} + +/* sdio device/function initialization, code is extracted + * from init_if handler and register_dev handler. + */ +static void nxpwifi_sdio_up_dev(struct nxpwifi_adapter *adapter) +{ + struct sdio_mmc_card *card =3D adapter->card; + u8 sdio_ireg; + + sdio_claim_host(card->func); + sdio_enable_func(card->func); + sdio_set_block_size(card->func, NXPWIFI_SDIO_BLOCK_SIZE); + sdio_release_host(card->func); + + /* tx_buf_size might be changed to 3584 by firmware during + * data transfer, we will reset to default size. + */ + adapter->tx_buf_size =3D card->tx_buf_size; + + /* Read the host_int_status_reg for ACK the first interrupt got + * from the bootloader. If we don't do this we get a interrupt + * as soon as we register the irq. + */ + nxpwifi_read_reg(adapter, card->reg->host_int_status_reg, &sdio_ireg); + + if (nxpwifi_init_sdio_ioport(adapter)) + dev_err(&card->func->dev, "error enabling SDIO port\n"); +} + +static struct nxpwifi_if_ops sdio_ops =3D { + .init_if =3D nxpwifi_init_sdio, + .cleanup_if =3D nxpwifi_cleanup_sdio, + .check_fw_status =3D nxpwifi_check_fw_status, + .check_winner_status =3D nxpwifi_check_winner_status, + .prog_fw =3D nxpwifi_prog_fw_w_helper, + .register_dev =3D nxpwifi_register_dev, + .unregister_dev =3D nxpwifi_unregister_dev, + .enable_int =3D nxpwifi_sdio_enable_host_int, + .disable_int =3D nxpwifi_sdio_disable_host_int, + .process_int_status =3D nxpwifi_process_int_status, + .host_to_card =3D nxpwifi_sdio_host_to_card, + .wakeup =3D nxpwifi_pm_wakeup_card, + .wakeup_complete =3D nxpwifi_pm_wakeup_card_complete, + + /* SDIO specific */ + .update_mp_end_port =3D nxpwifi_update_mp_end_port, + .cleanup_mpa_buf =3D nxpwifi_cleanup_mpa_buf, + .cmdrsp_complete =3D nxpwifi_sdio_cmdrsp_complete, + .event_complete =3D nxpwifi_sdio_event_complete, + .dnld_fw =3D nxpwifi_sdio_dnld_fw, + .card_reset =3D nxpwifi_sdio_card_reset, + .reg_dump =3D nxpwifi_sdio_reg_dump, + .device_dump =3D nxpwifi_sdio_device_dump, + .deaggr_pkt =3D nxpwifi_deaggr_sdio_pkt, + .up_dev =3D nxpwifi_sdio_up_dev, +}; + +module_sdio_driver(nxpwifi_sdio); + +MODULE_AUTHOR("NXP International Ltd."); +MODULE_DESCRIPTION("NXP WiFi SDIO Driver version " SDIO_VERSION); +MODULE_VERSION(SDIO_VERSION); +MODULE_LICENSE("GPL"); +MODULE_FIRMWARE(IW61X_SDIO_FW_NAME); diff --git a/drivers/net/wireless/nxp/nxpwifi/sdio.h b/drivers/net/wireless= /nxp/nxpwifi/sdio.h new file mode 100644 index 000000000000..de5c884a5b14 --- /dev/null +++ b/drivers/net/wireless/nxp/nxpwifi/sdio.h @@ -0,0 +1,340 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * NXP Wireless LAN device driver: SDIO specific definitions + * + * Copyright 2011-2024 NXP + */ + +#ifndef _NXPWIFI_SDIO_H +#define _NXPWIFI_SDIO_H + +#include "main.h" + +#define IW61X_SDIO_FW_NAME "nxp/sd_w61x_v1.bin.se" + +#define BLOCK_MODE 1 +#define BYTE_MODE 0 + +#define NXPWIFI_SDIO_IO_PORT_MASK 0xfffff + +#define NXPWIFI_SDIO_BYTE_MODE_MASK 0x80000000 + +#define NXPWIFI_MAX_FUNC2_REG_NUM 13 +#define NXPWIFI_SDIO_SCRATCH_SIZE 10 + +#define SDIO_MPA_ADDR_BASE 0x1000 + +#define CMD_PORT_UPLD_INT_MASK (0x1U << 6) +#define CMD_PORT_DNLD_INT_MASK (0x1U << 7) +#define HOST_TERM_CMD53 (0x1U << 2) +#define REG_PORT 0 +#define MEM_PORT 0x10000 + +#define CMD53_NEW_MODE (0x1U << 0) +#define CMD_PORT_RD_LEN_EN (0x1U << 2) +#define CMD_PORT_AUTO_EN (0x1U << 0) +#define CMD_PORT_SLCT 0x8000 +#define UP_LD_CMD_PORT_HOST_INT_STATUS (0x40U) +#define DN_LD_CMD_PORT_HOST_INT_STATUS (0x80U) + +#define NXPWIFI_MP_AGGR_BSIZE_32K (32768) +/* we leave one block of 256 bytes for DMA alignment*/ +#define NXPWIFI_MP_AGGR_BSIZE_MAX (65280) + +/* Misc. Config Register : Auto Re-enable interrupts */ +#define AUTO_RE_ENABLE_INT BIT(4) + +/* Host Control Registers : Configuration */ +#define CONFIGURATION_REG 0x00 +/* Host Control Registers : Host power up */ +#define HOST_POWER_UP (0x1U << 1) + +/* Host Control Registers : Upload host interrupt mask */ +#define UP_LD_HOST_INT_MASK (0x1U) +/* Host Control Registers : Download host interrupt mask */ +#define DN_LD_HOST_INT_MASK (0x2U) + +/* Host Control Registers : Upload host interrupt status */ +#define UP_LD_HOST_INT_STATUS (0x1U) +/* Host Control Registers : Download host interrupt status */ +#define DN_LD_HOST_INT_STATUS (0x2U) + +/* Host Control Registers : Host interrupt status */ +#define CARD_INT_STATUS_REG 0x28 + +/* Card Control Registers : Card I/O ready */ +#define CARD_IO_READY (0x1U << 3) +/* Card Control Registers : Download card ready */ +#define DN_LD_CARD_RDY (0x1U << 0) + +/* Max retry number of CMD53 write */ +#define MAX_WRITE_IOMEM_RETRY 2 + +/* SDIO Tx aggregation in progress ? */ +#define MP_TX_AGGR_IN_PROGRESS(a) ((a)->mpa_tx.pkt_cnt > 0) + +/* SDIO Tx aggregation buffer room for next packet ? */ +#define MP_TX_AGGR_BUF_HAS_ROOM(a, len) ({ \ + typeof(a) (_a) =3D a; \ + (((_a)->mpa_tx.buf_len + (len)) <=3D (_a)->mpa_tx.buf_size); \ + }) + +/* Copy current packet (SDIO Tx aggregation buffer) to SDIO buffer */ +#define MP_TX_AGGR_BUF_PUT(a, payload, pkt_len, port) do { \ + typeof(a) (_a) =3D (a); \ + typeof(pkt_len) (_pkt_len) =3D pkt_len; \ + typeof(port) (_port) =3D port; \ + memmove(&(_a)->mpa_tx.buf[(_a)->mpa_tx.buf_len], \ + payload, (_pkt_len)); \ + (_a)->mpa_tx.buf_len +=3D (_pkt_len); \ + if (!(_a)->mpa_tx.pkt_cnt) \ + (_a)->mpa_tx.start_port =3D (_port); \ + if ((_a)->mpa_tx.start_port <=3D (_port)) \ + (_a)->mpa_tx.ports |=3D (1 << ((_a)->mpa_tx.pkt_cnt)); \ + else \ + (_a)->mpa_tx.ports |=3D (1 << ((_a)->mpa_tx.pkt_cnt + 1 + \ + ((_a)->max_ports - \ + (_a)->mp_end_port))); \ + (_a)->mpa_tx.pkt_cnt++; \ +} while (0) + +/* SDIO Tx aggregation limit ? */ +#define MP_TX_AGGR_PKT_LIMIT_REACHED(a) ({ \ + typeof(a) (_a) =3D a; \ + ((_a)->mpa_tx.pkt_cnt =3D=3D (_a)->mpa_tx.pkt_aggr_limit); \ + }) + +/* Reset SDIO Tx aggregation buffer parameters */ +#define MP_TX_AGGR_BUF_RESET(a) do { \ + typeof(a) (_a) =3D (a); \ + (_a)->mpa_tx.pkt_cnt =3D 0; \ + (_a)->mpa_tx.buf_len =3D 0; \ + (_a)->mpa_tx.ports =3D 0; \ + (_a)->mpa_tx.start_port =3D 0; \ +} while (0) + +/* SDIO Rx aggregation limit ? */ +#define MP_RX_AGGR_PKT_LIMIT_REACHED(a) ({ \ + typeof(a) (_a) =3D a; \ + ((_a)->mpa_rx.pkt_cnt =3D=3D (_a)->mpa_rx.pkt_aggr_limit); \ + }) + +/* SDIO Rx aggregation in progress ? */ +#define MP_RX_AGGR_IN_PROGRESS(a) ((a)->mpa_rx.pkt_cnt > 0) + +/* SDIO Rx aggregation buffer room for next packet ? */ +#define MP_RX_AGGR_BUF_HAS_ROOM(a, rx_len) ({ \ + typeof(a) (_a) =3D a; \ + ((((_a)->mpa_rx.buf_len + (rx_len))) <=3D (_a)->mpa_rx.buf_size); \ + }) + +/* Reset SDIO Rx aggregation buffer parameters */ +#define MP_RX_AGGR_BUF_RESET(a) do { \ + typeof(a) (_a) =3D (a); \ + (_a)->mpa_rx.pkt_cnt =3D 0; \ + (_a)->mpa_rx.buf_len =3D 0; \ + (_a)->mpa_rx.ports =3D 0; \ + (_a)->mpa_rx.start_port =3D 0; \ +} while (0) + +/* data structure for SDIO MPA TX */ +struct nxpwifi_sdio_mpa_tx { + /* multiport tx aggregation buffer pointer */ + u8 *buf; + u32 buf_len; + u32 pkt_cnt; + u32 ports; + u16 start_port; + u8 enabled; + u32 buf_size; + u32 pkt_aggr_limit; +}; + +struct nxpwifi_sdio_mpa_rx { + u8 *buf; + u32 buf_len; + u32 pkt_cnt; + u32 ports; + u16 start_port; + u32 *len_arr; + u8 enabled; + u32 buf_size; + u32 pkt_aggr_limit; +}; + +int nxpwifi_bus_register(void); +void nxpwifi_bus_unregister(void); + +struct nxpwifi_sdio_card_reg { + u8 start_rd_port; + u8 start_wr_port; + u8 base_0_reg; + u8 base_1_reg; + u8 poll_reg; + u8 host_int_enable; + u8 host_int_rsr_reg; + u8 host_int_status_reg; + u8 host_int_mask_reg; + u8 host_strap_reg; + u8 host_strap_mask; + u8 host_strap_value; + u8 status_reg_0; + u8 status_reg_1; + u8 sdio_int_mask; + u32 data_port_mask; + u8 io_port_0_reg; + u8 io_port_1_reg; + u8 io_port_2_reg; + u8 max_mp_regs; + u8 rd_bitmap_l; + u8 rd_bitmap_u; + u8 rd_bitmap_1l; + u8 rd_bitmap_1u; + u8 wr_bitmap_l; + u8 wr_bitmap_u; + u8 wr_bitmap_1l; + u8 wr_bitmap_1u; + u8 rd_len_p0_l; + u8 rd_len_p0_u; + u8 card_misc_cfg_reg; + u8 card_cfg_2_1_reg; + u8 cmd_rd_len_0; + u8 cmd_rd_len_1; + u8 cmd_rd_len_2; + u8 cmd_rd_len_3; + u8 cmd_cfg_0; + u8 cmd_cfg_1; + u8 cmd_cfg_2; + u8 cmd_cfg_3; + u8 fw_dump_host_ready; + u8 fw_dump_ctrl; + u8 fw_dump_start; + u8 fw_dump_end; + u8 func1_dump_reg_start; + u8 func1_dump_reg_end; + u8 func1_scratch_reg; + u8 func1_spec_reg_num; + u8 func1_spec_reg_table[NXPWIFI_MAX_FUNC2_REG_NUM]; +}; + +struct sdio_mmc_card { + struct sdio_func *func; + struct nxpwifi_adapter *adapter; + + struct completion fw_done; + const char *firmware; + const char *firmware_sdiouart; + const struct nxpwifi_sdio_card_reg *reg; + u8 max_ports; + u8 mp_agg_pkt_limit; + u16 tx_buf_size; + u32 mp_tx_agg_buf_size; + u32 mp_rx_agg_buf_size; + + u32 mp_rd_bitmap; + u32 mp_wr_bitmap; + + u16 mp_end_port; + u32 mp_data_port_mask; + + u8 curr_rd_port; + u8 curr_wr_port; + + u8 *mp_regs; + bool can_dump_fw; + bool fw_dump_enh; + bool can_ext_scan; + + struct nxpwifi_sdio_mpa_tx mpa_tx; + struct nxpwifi_sdio_mpa_rx mpa_rx; + + struct work_struct work; + unsigned long work_flags; +}; + +struct nxpwifi_sdio_device { + const char *firmware; + const char *firmware_sdiouart; + const struct nxpwifi_sdio_card_reg *reg; + u8 max_ports; + u8 mp_agg_pkt_limit; + u16 tx_buf_size; + u32 mp_tx_agg_buf_size; + u32 mp_rx_agg_buf_size; + bool can_dump_fw; + bool fw_dump_enh; + bool can_ext_scan; +}; + +/* .cmdrsp_complete handler + */ +static inline int nxpwifi_sdio_cmdrsp_complete(struct nxpwifi_adapter *ada= pter, + struct sk_buff *skb) +{ + dev_kfree_skb_any(skb); + return 0; +} + +/* .event_complete handler + */ +static inline int nxpwifi_sdio_event_complete(struct nxpwifi_adapter *adap= ter, + struct sk_buff *skb) +{ + dev_kfree_skb_any(skb); + return 0; +} + +static inline bool +mp_rx_aggr_port_limit_reached(struct sdio_mmc_card *card) +{ + u8 tmp; + + if (card->curr_rd_port < card->mpa_rx.start_port) { + tmp =3D card->mp_end_port >> 1; + + if (((card->max_ports - card->mpa_rx.start_port) + + card->curr_rd_port) >=3D tmp) + return true; + } + + if ((card->curr_rd_port - card->mpa_rx.start_port) >=3D + (card->mp_end_port >> 1)) + return true; + + return false; +} + +static inline bool +mp_tx_aggr_port_limit_reached(struct sdio_mmc_card *card) +{ + u16 tmp; + + if (card->curr_wr_port < card->mpa_tx.start_port) { + tmp =3D card->mp_end_port >> 1; + + if (((card->max_ports - card->mpa_tx.start_port) + + card->curr_wr_port) >=3D tmp) + return true; + } + + if ((card->curr_wr_port - card->mpa_tx.start_port) >=3D + (card->mp_end_port >> 1)) + return true; + + return false; +} + +/* Prepare to copy current packet from card to SDIO Rx aggregation buffer = */ +static inline void mp_rx_aggr_setup(struct sdio_mmc_card *card, + u16 rx_len, u8 port) +{ + card->mpa_rx.buf_len +=3D rx_len; + + if (!card->mpa_rx.pkt_cnt) + card->mpa_rx.start_port =3D port; + + card->mpa_rx.ports |=3D (1 << port); + card->mpa_rx.len_arr[card->mpa_rx.pkt_cnt] =3D rx_len; + card->mpa_rx.pkt_cnt++; +} +#endif /* _NXPWIFI_SDIO_H */ --=20 2.34.1