b62fab53931ca98ad6138a9baf4e2576070d30f9
[openwrt/staging/ansuel.git] /
1 From d8748eda96b47efea833e2a6ea478bb370654f1d Mon Sep 17 00:00:00 2001
2 From: Jonathan Bell <jonathan@raspberrypi.com>
3 Date: Wed, 20 Mar 2024 13:00:30 +0000
4 Subject: [PATCH 0983/1085] drivers: mmc: preallocate a block for SD extension
5 register accesses
6
7 The Performance Extension register is regularly accessed in a hot path
8 to do write cache flushes. Don't invoke kmalloc/kfree for every access,
9 preallocate a 512B buffer for this purpose.
10
11 Also remove an unused alloc in sd_enable_cache().
12
13 Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
14 ---
15 drivers/mmc/core/bus.c | 2 ++
16 drivers/mmc/core/sd.c | 34 +++++++++++-----------------------
17 include/linux/mmc/card.h | 1 +
18 3 files changed, 14 insertions(+), 23 deletions(-)
19
20 --- a/drivers/mmc/core/bus.c
21 +++ b/drivers/mmc/core/bus.c
22 @@ -264,6 +264,8 @@ static void mmc_release_card(struct devi
23
24 sdio_free_common_cis(card);
25
26 + kfree(card->ext_reg_buf);
27 +
28 kfree(card->info);
29
30 kfree(card);
31 --- a/drivers/mmc/core/sd.c
32 +++ b/drivers/mmc/core/sd.c
33 @@ -1025,9 +1025,8 @@ int sd_write_ext_reg(struct mmc_card *ca
34 struct scatterlist sg;
35 u8 *reg_buf;
36
37 - reg_buf = kzalloc(512, GFP_KERNEL);
38 - if (!reg_buf)
39 - return -ENOMEM;
40 + reg_buf = card->ext_reg_buf;
41 + memset(reg_buf, 0, 512);
42
43 mrq.cmd = &cmd;
44 mrq.data = &data;
45 @@ -1059,8 +1058,6 @@ int sd_write_ext_reg(struct mmc_card *ca
46 mmc_set_data_timeout(&data, card);
47 mmc_wait_for_req(host, &mrq);
48
49 - kfree(reg_buf);
50 -
51 /*
52 * Note that, the SD card is allowed to signal busy on DAT0 up to 1s
53 * after the CMD49. Although, let's leave this to be managed by the
54 @@ -1101,9 +1098,7 @@ static int sd_parse_ext_reg_power(struct
55 int err;
56 u8 *reg_buf;
57
58 - reg_buf = kzalloc(512, GFP_KERNEL);
59 - if (!reg_buf)
60 - return -ENOMEM;
61 + reg_buf = card->ext_reg_buf;
62
63 /* Read the extension register for power management function. */
64 err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
65 @@ -1133,7 +1128,6 @@ static int sd_parse_ext_reg_power(struct
66 card->ext_power.offset = offset;
67
68 out:
69 - kfree(reg_buf);
70 return err;
71 }
72
73 @@ -1143,9 +1137,7 @@ static int sd_parse_ext_reg_perf(struct
74 int err;
75 u8 *reg_buf;
76
77 - reg_buf = kzalloc(512, GFP_KERNEL);
78 - if (!reg_buf)
79 - return -ENOMEM;
80 + reg_buf = card->ext_reg_buf;
81
82 err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf);
83 if (err) {
84 @@ -1188,7 +1180,6 @@ static int sd_parse_ext_reg_perf(struct
85 card->ext_perf.offset = offset;
86
87 out:
88 - kfree(reg_buf);
89 return err;
90 }
91
92 @@ -1259,6 +1250,12 @@ static int sd_read_ext_regs(struct mmc_c
93 if (!gen_info_buf)
94 return -ENOMEM;
95
96 + card->ext_reg_buf = kzalloc(512, GFP_KERNEL);
97 + if (!card->ext_reg_buf) {
98 + err = -ENOMEM;
99 + goto out;
100 + }
101 +
102 /*
103 * Read 512 bytes of general info, which is found at function number 0,
104 * at page 0 and with no offset.
105 @@ -1325,9 +1322,7 @@ static int sd_flush_cache(struct mmc_hos
106 if (!sd_cache_enabled(host))
107 return 0;
108
109 - reg_buf = kzalloc(512, GFP_KERNEL);
110 - if (!reg_buf)
111 - return -ENOMEM;
112 + reg_buf = card->ext_reg_buf;
113
114 /*
115 * Set Flush Cache at bit 0 in the performance enhancement register at
116 @@ -1363,21 +1358,15 @@ static int sd_flush_cache(struct mmc_hos
117 if (reg_buf[0] & BIT(0))
118 err = -ETIMEDOUT;
119 out:
120 - kfree(reg_buf);
121 return err;
122 }
123
124 static int sd_enable_cache(struct mmc_card *card)
125 {
126 - u8 *reg_buf;
127 int err;
128
129 card->ext_perf.feature_enabled &= ~SD_EXT_PERF_CACHE;
130
131 - reg_buf = kzalloc(512, GFP_KERNEL);
132 - if (!reg_buf)
133 - return -ENOMEM;
134 -
135 /*
136 * Set Cache Enable at bit 0 in the performance enhancement register at
137 * 260 bytes offset.
138 @@ -1396,7 +1385,6 @@ static int sd_enable_cache(struct mmc_ca
139 card->ext_perf.feature_enabled |= SD_EXT_PERF_CACHE;
140
141 out:
142 - kfree(reg_buf);
143 return err;
144 }
145
146 --- a/include/linux/mmc/card.h
147 +++ b/include/linux/mmc/card.h
148 @@ -320,6 +320,7 @@ struct mmc_card {
149 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
150 struct sd_ext_reg ext_power; /* SD extension reg for PM */
151 struct sd_ext_reg ext_perf; /* SD extension reg for PERF */
152 + u8 *ext_reg_buf; /* 512 byte block for extension register R/W */
153
154 unsigned int sdio_funcs; /* number of SDIO functions */
155 atomic_t sdio_funcs_probed; /* number of probed SDIO funcs */