mirror of
https://github.com/torvalds/linux.git
synced 2024-11-25 05:32:00 +00:00
7d5a7dd5a3
Some of the registers are aligned on a 32bit boundary, causing
alignment faults on 64bit platforms.
Unable to handle kernel paging request at virtual address ffffffc084a1d004
Mem abort info:
ESR = 0x0000000096000061
EC = 0x25: DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
FSC = 0x21: alignment fault
Data abort info:
ISV = 0, ISS = 0x00000061, ISS2 = 0x00000000
CM = 0, WnR = 1, TnD = 0, TagAccess = 0
GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
swapper pgtable: 4k pages, 39-bit VAs, pgdp=0000000046ad6000
[ffffffc084a1d004] pgd=100000013ffff003, p4d=100000013ffff003, pud=100000013ffff003, pmd=0068000020a00711
Internal error: Oops: 0000000096000061 [#1] SMP
Modules linked in: mtk_t7xx(+) qcserial pppoe ppp_async option nft_fib_inet nf_flow_table_inet mt7921u(O) mt7921s(O) mt7921e(O) mt7921_common(O) iwlmvm(O) iwldvm(O) usb_wwan rndis_host qmi_wwan pppox ppp_generic nft_reject_ipv6 nft_reject_ipv4 nft_reject_inet nft_reject nft_redir nft_quota nft_numgen nft_nat nft_masq nft_log nft_limit nft_hash nft_flow_offload nft_fib_ipv6 nft_fib_ipv4 nft_fib nft_ct nft_chain_nat nf_tables nf_nat nf_flow_table nf_conntrack mt7996e(O) mt792x_usb(O) mt792x_lib(O) mt7915e(O) mt76_usb(O) mt76_sdio(O) mt76_connac_lib(O) mt76(O) mac80211(O) iwlwifi(O) huawei_cdc_ncm cfg80211(O) cdc_ncm cdc_ether wwan usbserial usbnet slhc sfp rtc_pcf8563 nfnetlink nf_reject_ipv6 nf_reject_ipv4 nf_log_syslog nf_defrag_ipv6 nf_defrag_ipv4 mt6577_auxadc mdio_i2c libcrc32c compat(O) cdc_wdm cdc_acm at24 crypto_safexcel pwm_fan i2c_gpio i2c_smbus industrialio i2c_algo_bit i2c_mux_reg i2c_mux_pca954x i2c_mux_pca9541 i2c_mux_gpio i2c_mux dummy oid_registry tun sha512_arm64 sha1_ce sha1_generic seqiv
md5 geniv des_generic libdes cbc authencesn authenc leds_gpio xhci_plat_hcd xhci_pci xhci_mtk_hcd xhci_hcd nvme nvme_core gpio_button_hotplug(O) dm_mirror dm_region_hash dm_log dm_crypt dm_mod dax usbcore usb_common ptp aquantia pps_core mii tpm encrypted_keys trusted
CPU: 3 PID: 5266 Comm: kworker/u9:1 Tainted: G O 6.6.22 #0
Hardware name: Bananapi BPI-R4 (DT)
Workqueue: md_hk_wq t7xx_fsm_uninit [mtk_t7xx]
pstate: 804000c5 (Nzcv daIF +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : t7xx_cldma_hw_set_start_addr+0x1c/0x3c [mtk_t7xx]
lr : t7xx_cldma_start+0xac/0x13c [mtk_t7xx]
sp : ffffffc085d63d30
x29: ffffffc085d63d30 x28: 0000000000000000 x27: 0000000000000000
x26: 0000000000000000 x25: ffffff80c804f2c0 x24: ffffff80ca196c05
x23: 0000000000000000 x22: ffffff80c814b9b8 x21: ffffff80c814b128
x20: 0000000000000001 x19: ffffff80c814b080 x18: 0000000000000014
x17: 0000000055c9806b x16: 000000007c5296d0 x15: 000000000f6bca68
x14: 00000000dbdbdce4 x13: 000000001aeaf72a x12: 0000000000000001
x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000000
x8 : ffffff80ca1ef6b4 x7 : ffffff80c814b818 x6 : 0000000000000018
x5 : 0000000000000870 x4 : 0000000000000000 x3 : 0000000000000000
x2 : 000000010a947000 x1 : ffffffc084a1d004 x0 : ffffffc084a1d004
Call trace:
t7xx_cldma_hw_set_start_addr+0x1c/0x3c [mtk_t7xx]
t7xx_fsm_uninit+0x578/0x5ec [mtk_t7xx]
process_one_work+0x154/0x2a0
worker_thread+0x2ac/0x488
kthread+0xe0/0xec
ret_from_fork+0x10/0x20
Code: f9400800 91001000 8b214001 d50332bf (f9000022)
---[ end trace 0000000000000000 ]---
The inclusion of io-64-nonatomic-lo-hi.h indicates that all 64bit
accesses can be replaced by pairs of nonatomic 32bit access. Fix
alignment by forcing all accesses to be 32bit on 64bit platforms.
Link: https://forum.openwrt.org/t/fibocom-fm350-gl-support/142682/72
Fixes: 39d439047f
("net: wwan: t7xx: Add control DMA interface")
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Reviewed-by: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Tested-by: Liviu Dudau <liviu@dudau.co.uk>
Link: https://lore.kernel.org/r/20240322144000.1683822-1-bjorn@mork.no
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
263 lines
6.8 KiB
C
263 lines
6.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2021, MediaTek Inc.
|
|
* Copyright (c) 2021-2022, Intel Corporation.
|
|
*
|
|
* Authors:
|
|
* Haijun Liu <haijun.liu@mediatek.com>
|
|
* Moises Veleta <moises.veleta@intel.com>
|
|
* Sreehari Kancharla <sreehari.kancharla@intel.com>
|
|
*
|
|
* Contributors:
|
|
* Amir Hanania <amir.hanania@intel.com>
|
|
* Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
|
|
* Ricardo Martinez <ricardo.martinez@linux.intel.com>
|
|
*/
|
|
|
|
#include <linux/bits.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/device.h>
|
|
#include <linux/io-64-nonatomic-lo-hi.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/string.h>
|
|
#include <linux/types.h>
|
|
|
|
#include "t7xx_pci.h"
|
|
#include "t7xx_pcie_mac.h"
|
|
#include "t7xx_reg.h"
|
|
|
|
#define T7XX_PCIE_REG_BAR 2
|
|
#define T7XX_PCIE_REG_PORT ATR_SRC_PCI_WIN0
|
|
#define T7XX_PCIE_REG_TABLE_NUM 0
|
|
#define T7XX_PCIE_REG_TRSL_PORT ATR_DST_AXIM_0
|
|
|
|
#define T7XX_PCIE_DEV_DMA_PORT_START ATR_SRC_AXIS_0
|
|
#define T7XX_PCIE_DEV_DMA_PORT_END ATR_SRC_AXIS_2
|
|
#define T7XX_PCIE_DEV_DMA_TABLE_NUM 0
|
|
#define T7XX_PCIE_DEV_DMA_TRSL_ADDR 0
|
|
#define T7XX_PCIE_DEV_DMA_SRC_ADDR 0
|
|
#define T7XX_PCIE_DEV_DMA_TRANSPARENT 1
|
|
#define T7XX_PCIE_DEV_DMA_SIZE 0
|
|
|
|
enum t7xx_atr_src_port {
|
|
ATR_SRC_PCI_WIN0,
|
|
ATR_SRC_PCI_WIN1,
|
|
ATR_SRC_AXIS_0,
|
|
ATR_SRC_AXIS_1,
|
|
ATR_SRC_AXIS_2,
|
|
ATR_SRC_AXIS_3,
|
|
};
|
|
|
|
enum t7xx_atr_dst_port {
|
|
ATR_DST_PCI_TRX,
|
|
ATR_DST_PCI_CONFIG,
|
|
ATR_DST_AXIM_0 = 4,
|
|
ATR_DST_AXIM_1,
|
|
ATR_DST_AXIM_2,
|
|
ATR_DST_AXIM_3,
|
|
};
|
|
|
|
struct t7xx_atr_config {
|
|
u64 src_addr;
|
|
u64 trsl_addr;
|
|
u64 size;
|
|
u32 port;
|
|
u32 table;
|
|
enum t7xx_atr_dst_port trsl_id;
|
|
u32 transparent;
|
|
};
|
|
|
|
static void t7xx_pcie_mac_atr_tables_dis(void __iomem *pbase, enum t7xx_atr_src_port port)
|
|
{
|
|
void __iomem *reg;
|
|
int i, offset;
|
|
|
|
for (i = 0; i < ATR_TABLE_NUM_PER_ATR; i++) {
|
|
offset = ATR_PORT_OFFSET * port + ATR_TABLE_OFFSET * i;
|
|
reg = pbase + ATR_PCIE_WIN0_T0_ATR_PARAM_SRC_ADDR + offset;
|
|
iowrite64_lo_hi(0, reg);
|
|
}
|
|
}
|
|
|
|
static int t7xx_pcie_mac_atr_cfg(struct t7xx_pci_dev *t7xx_dev, struct t7xx_atr_config *cfg)
|
|
{
|
|
struct device *dev = &t7xx_dev->pdev->dev;
|
|
void __iomem *pbase = IREG_BASE(t7xx_dev);
|
|
int atr_size, pos, offset;
|
|
void __iomem *reg;
|
|
u64 value;
|
|
|
|
if (cfg->transparent) {
|
|
/* No address conversion is performed */
|
|
atr_size = ATR_TRANSPARENT_SIZE;
|
|
} else {
|
|
if (cfg->src_addr & (cfg->size - 1)) {
|
|
dev_err(dev, "Source address is not aligned to size\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (cfg->trsl_addr & (cfg->size - 1)) {
|
|
dev_err(dev, "Translation address %llx is not aligned to size %llx\n",
|
|
cfg->trsl_addr, cfg->size - 1);
|
|
return -EINVAL;
|
|
}
|
|
|
|
pos = __ffs64(cfg->size);
|
|
|
|
/* HW calculates the address translation space as 2^(atr_size + 1) */
|
|
atr_size = pos - 1;
|
|
}
|
|
|
|
offset = ATR_PORT_OFFSET * cfg->port + ATR_TABLE_OFFSET * cfg->table;
|
|
|
|
reg = pbase + ATR_PCIE_WIN0_T0_TRSL_ADDR + offset;
|
|
value = cfg->trsl_addr & ATR_PCIE_WIN0_ADDR_ALGMT;
|
|
iowrite64_lo_hi(value, reg);
|
|
|
|
reg = pbase + ATR_PCIE_WIN0_T0_TRSL_PARAM + offset;
|
|
iowrite32(cfg->trsl_id, reg);
|
|
|
|
reg = pbase + ATR_PCIE_WIN0_T0_ATR_PARAM_SRC_ADDR + offset;
|
|
value = (cfg->src_addr & ATR_PCIE_WIN0_ADDR_ALGMT) | (atr_size << 1) | BIT(0);
|
|
iowrite64_lo_hi(value, reg);
|
|
|
|
/* Ensure ATR is set */
|
|
ioread64_lo_hi(reg);
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* t7xx_pcie_mac_atr_init() - Initialize address translation.
|
|
* @t7xx_dev: MTK device.
|
|
*
|
|
* Setup ATR for ports & device.
|
|
*/
|
|
void t7xx_pcie_mac_atr_init(struct t7xx_pci_dev *t7xx_dev)
|
|
{
|
|
struct t7xx_atr_config cfg;
|
|
u32 i;
|
|
|
|
/* Disable for all ports */
|
|
for (i = ATR_SRC_PCI_WIN0; i <= ATR_SRC_AXIS_3; i++)
|
|
t7xx_pcie_mac_atr_tables_dis(IREG_BASE(t7xx_dev), i);
|
|
|
|
memset(&cfg, 0, sizeof(cfg));
|
|
/* Config ATR for RC to access device's register */
|
|
cfg.src_addr = pci_resource_start(t7xx_dev->pdev, T7XX_PCIE_REG_BAR);
|
|
cfg.size = T7XX_PCIE_REG_SIZE_CHIP;
|
|
cfg.trsl_addr = T7XX_PCIE_REG_TRSL_ADDR_CHIP;
|
|
cfg.port = T7XX_PCIE_REG_PORT;
|
|
cfg.table = T7XX_PCIE_REG_TABLE_NUM;
|
|
cfg.trsl_id = T7XX_PCIE_REG_TRSL_PORT;
|
|
t7xx_pcie_mac_atr_tables_dis(IREG_BASE(t7xx_dev), cfg.port);
|
|
t7xx_pcie_mac_atr_cfg(t7xx_dev, &cfg);
|
|
|
|
t7xx_dev->base_addr.pcie_dev_reg_trsl_addr = T7XX_PCIE_REG_TRSL_ADDR_CHIP;
|
|
|
|
/* Config ATR for EP to access RC's memory */
|
|
for (i = T7XX_PCIE_DEV_DMA_PORT_START; i <= T7XX_PCIE_DEV_DMA_PORT_END; i++) {
|
|
cfg.src_addr = T7XX_PCIE_DEV_DMA_SRC_ADDR;
|
|
cfg.size = T7XX_PCIE_DEV_DMA_SIZE;
|
|
cfg.trsl_addr = T7XX_PCIE_DEV_DMA_TRSL_ADDR;
|
|
cfg.port = i;
|
|
cfg.table = T7XX_PCIE_DEV_DMA_TABLE_NUM;
|
|
cfg.trsl_id = ATR_DST_PCI_TRX;
|
|
cfg.transparent = T7XX_PCIE_DEV_DMA_TRANSPARENT;
|
|
t7xx_pcie_mac_atr_tables_dis(IREG_BASE(t7xx_dev), cfg.port);
|
|
t7xx_pcie_mac_atr_cfg(t7xx_dev, &cfg);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* t7xx_pcie_mac_enable_disable_int() - Enable/disable interrupts.
|
|
* @t7xx_dev: MTK device.
|
|
* @enable: Enable/disable.
|
|
*
|
|
* Enable or disable device interrupts.
|
|
*/
|
|
static void t7xx_pcie_mac_enable_disable_int(struct t7xx_pci_dev *t7xx_dev, bool enable)
|
|
{
|
|
u32 value;
|
|
|
|
value = ioread32(IREG_BASE(t7xx_dev) + ISTAT_HST_CTRL);
|
|
|
|
if (enable)
|
|
value &= ~ISTAT_HST_CTRL_DIS;
|
|
else
|
|
value |= ISTAT_HST_CTRL_DIS;
|
|
|
|
iowrite32(value, IREG_BASE(t7xx_dev) + ISTAT_HST_CTRL);
|
|
}
|
|
|
|
void t7xx_pcie_mac_interrupts_en(struct t7xx_pci_dev *t7xx_dev)
|
|
{
|
|
t7xx_pcie_mac_enable_disable_int(t7xx_dev, true);
|
|
}
|
|
|
|
void t7xx_pcie_mac_interrupts_dis(struct t7xx_pci_dev *t7xx_dev)
|
|
{
|
|
t7xx_pcie_mac_enable_disable_int(t7xx_dev, false);
|
|
}
|
|
|
|
/**
|
|
* t7xx_pcie_mac_clear_set_int() - Clear/set interrupt by type.
|
|
* @t7xx_dev: MTK device.
|
|
* @int_type: Interrupt type.
|
|
* @clear: Clear/set.
|
|
*
|
|
* Clear or set device interrupt by type.
|
|
*/
|
|
static void t7xx_pcie_mac_clear_set_int(struct t7xx_pci_dev *t7xx_dev,
|
|
enum t7xx_int int_type, bool clear)
|
|
{
|
|
void __iomem *reg;
|
|
u32 val;
|
|
|
|
if (clear)
|
|
reg = IREG_BASE(t7xx_dev) + IMASK_HOST_MSIX_CLR_GRP0_0;
|
|
else
|
|
reg = IREG_BASE(t7xx_dev) + IMASK_HOST_MSIX_SET_GRP0_0;
|
|
|
|
val = BIT(EXT_INT_START + int_type);
|
|
iowrite32(val, reg);
|
|
}
|
|
|
|
void t7xx_pcie_mac_clear_int(struct t7xx_pci_dev *t7xx_dev, enum t7xx_int int_type)
|
|
{
|
|
t7xx_pcie_mac_clear_set_int(t7xx_dev, int_type, true);
|
|
}
|
|
|
|
void t7xx_pcie_mac_set_int(struct t7xx_pci_dev *t7xx_dev, enum t7xx_int int_type)
|
|
{
|
|
t7xx_pcie_mac_clear_set_int(t7xx_dev, int_type, false);
|
|
}
|
|
|
|
/**
|
|
* t7xx_pcie_mac_clear_int_status() - Clear interrupt status by type.
|
|
* @t7xx_dev: MTK device.
|
|
* @int_type: Interrupt type.
|
|
*
|
|
* Enable or disable device interrupts' status by type.
|
|
*/
|
|
void t7xx_pcie_mac_clear_int_status(struct t7xx_pci_dev *t7xx_dev, enum t7xx_int int_type)
|
|
{
|
|
void __iomem *reg = IREG_BASE(t7xx_dev) + MSIX_ISTAT_HST_GRP0_0;
|
|
u32 val = BIT(EXT_INT_START + int_type);
|
|
|
|
iowrite32(val, reg);
|
|
}
|
|
|
|
/**
|
|
* t7xx_pcie_set_mac_msix_cfg() - Write MSIX control configuration.
|
|
* @t7xx_dev: MTK device.
|
|
* @irq_count: Number of MSIX IRQ vectors.
|
|
*
|
|
* Write IRQ count to device.
|
|
*/
|
|
void t7xx_pcie_set_mac_msix_cfg(struct t7xx_pci_dev *t7xx_dev, unsigned int irq_count)
|
|
{
|
|
u32 val = ffs(irq_count) * 2 - 1;
|
|
|
|
iowrite32(val, IREG_BASE(t7xx_dev) + T7XX_PCIE_CFG_MSIX);
|
|
}
|