blob: 0e6721d8f282d6f50a006c1f21d266eacf1ad316 [file] [log] [blame]
developer99c20a72023-08-18 17:03:34 +08001From fdc88d572be3bc32ec03d11126b598039d90f9d2 Mon Sep 17 00:00:00 2001
2From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Tue, 15 Aug 2023 17:28:30 +0800
4Subject: [PATCH] wifi: mt76: mt7915: rework mmio access flow
5
6Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
7Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
8---
9 mt7915/mmio.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-----
10 mt7915/mt7915.h | 1 +
11 2 files changed, 45 insertions(+), 5 deletions(-)
12
13diff --git a/mt7915/mmio.c b/mt7915/mmio.c
14index fc7ace63..55096616 100644
15--- a/mt7915/mmio.c
16+++ b/mt7915/mmio.c
17@@ -490,6 +490,11 @@ static u32 __mt7915_reg_addr(struct mt7915_dev *dev, u32 addr)
18 return dev->reg.map[i].maps + ofs;
19 }
20
21+ return 0;
22+}
23+
24+static u32 __mt7915_reg_remap_addr(struct mt7915_dev *dev, u32 addr)
25+{
26 if ((addr >= MT_INFRA_BASE && addr < MT_WFSYS0_PHY_START) ||
27 (addr >= MT_WFSYS0_PHY_START && addr < MT_WFSYS1_PHY_START) ||
28 (addr >= MT_WFSYS1_PHY_START && addr <= MT_WFSYS1_PHY_END))
29@@ -513,32 +518,65 @@ void mt7915_memcpy_fromio(struct mt7915_dev *dev, void *buf, u32 offset,
30 size_t len)
31 {
32 u32 addr = __mt7915_reg_addr(dev, offset);
33+ unsigned long flags;
34
35- memcpy_fromio(buf, dev->mt76.mmio.regs + addr, len);
36+ if (addr) {
37+ memcpy_fromio(buf, dev->mt76.mmio.regs + addr, len);
38+ return;
39+ }
40+
41+ spin_lock_irqsave(&dev->reg_lock, flags);
42+ memcpy_fromio(buf, dev->mt76.mmio.regs +
43+ __mt7915_reg_remap_addr(dev, offset), len);
44+ spin_unlock_irqrestore(&dev->reg_lock, flags);
45 }
46
47 static u32 mt7915_rr(struct mt76_dev *mdev, u32 offset)
48 {
49 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
50- u32 addr = __mt7915_reg_addr(dev, offset);
51+ u32 addr = __mt7915_reg_addr(dev, offset), val;
52+ unsigned long flags;
53
54- return dev->bus_ops->rr(mdev, addr);
55+ if (addr)
56+ return dev->bus_ops->rr(mdev, addr);
57+
58+ spin_lock_irqsave(&dev->reg_lock, flags);
59+ val = dev->bus_ops->rr(mdev, __mt7915_reg_remap_addr(dev, offset));
60+ spin_unlock_irqrestore(&dev->reg_lock, flags);
61+
62+ return val;
63 }
64
65 static void mt7915_wr(struct mt76_dev *mdev, u32 offset, u32 val)
66 {
67 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
68 u32 addr = __mt7915_reg_addr(dev, offset);
69+ unsigned long flags;
70
71- dev->bus_ops->wr(mdev, addr, val);
72+ if (addr) {
73+ dev->bus_ops->wr(mdev, addr, val);
74+ return;
75+ }
76+
77+ spin_lock_irqsave(&dev->reg_lock, flags);
78+ dev->bus_ops->wr(mdev, __mt7915_reg_remap_addr(dev, offset), val);
79+ spin_unlock_irqrestore(&dev->reg_lock, flags);
80 }
81
82 static u32 mt7915_rmw(struct mt76_dev *mdev, u32 offset, u32 mask, u32 val)
83 {
84 struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
85 u32 addr = __mt7915_reg_addr(dev, offset);
86+ unsigned long flags;
87+
88+ if (addr)
89+ return dev->bus_ops->rmw(mdev, addr, mask, val);
90+
91+ spin_lock_irqsave(&dev->reg_lock, flags);
92+ val = dev->bus_ops->rmw(mdev, __mt7915_reg_remap_addr(dev, offset), mask, val);
93+ spin_unlock_irqrestore(&dev->reg_lock, flags);
94
95- return dev->bus_ops->rmw(mdev, addr, mask, val);
96+ return val;
97 }
98
99 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
100@@ -813,6 +851,7 @@ static int mt7915_mmio_init(struct mt76_dev *mdev,
101
102 dev = container_of(mdev, struct mt7915_dev, mt76);
103 mt76_mmio_init(&dev->mt76, mem_base);
104+ spin_lock_init(&dev->reg_lock);
105
106 switch (device_id) {
107 case 0x7915:
108diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
109index f0809291..24d8da28 100644
110--- a/mt7915/mt7915.h
111+++ b/mt7915/mt7915.h
112@@ -292,6 +292,7 @@ struct mt7915_dev {
113
114 struct list_head sta_rc_list;
115 struct list_head twt_list;
116+ spinlock_t reg_lock;
117
118 u32 hw_pattern;
119
120--
1212.18.0
122