Skip to content

Commit 42e27bf

Browse files
Geert Uytterhoevenozbenh
authored andcommitted
ps3flash: Always read chunks of 256 KiB, and cache them
Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 6bd57f2 commit 42e27bf

1 file changed

Lines changed: 17 additions & 30 deletions

File tree

‎drivers/char/ps3flash.c‎

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ struct ps3flash_private {
4141
static struct ps3_storage_device *ps3flash_dev;
4242

4343
static int ps3flash_read_write_sectors(struct ps3_storage_device *dev,
44-
u64 lpar, u64 start_sector, u64 sectors,
45-
int write)
44+
u64 start_sector, int write)
4645
{
47-
u64 res = ps3stor_read_write_sectors(dev, lpar, start_sector, sectors,
46+
struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
47+
u64 res = ps3stor_read_write_sectors(dev, dev->bounce_lpar,
48+
start_sector, priv->chunk_sectors,
4849
write);
4950
if (res) {
5051
dev_err(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
@@ -62,26 +63,20 @@ static int ps3flash_writeback(struct ps3_storage_device *dev)
6263
if (!priv->dirty || priv->tag < 0)
6364
return 0;
6465

65-
res = ps3flash_read_write_sectors(dev, dev->bounce_lpar, priv->tag,
66-
priv->chunk_sectors, 1);
66+
res = ps3flash_read_write_sectors(dev, priv->tag, 1);
6767
if (res)
6868
return res;
6969

7070
priv->dirty = false;
7171
return 0;
7272
}
7373

74-
static int ps3flash_fetch(struct ps3_storage_device *dev, u64 start_sector,
75-
u64 sectors)
74+
static int ps3flash_fetch(struct ps3_storage_device *dev, u64 start_sector)
7675
{
7776
struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
78-
unsigned int tag, offset;
79-
u64 lpar;
8077
int res;
8178

82-
offset = start_sector % priv->chunk_sectors;
83-
tag = start_sector - offset;
84-
if (tag == priv->tag)
79+
if (start_sector == priv->tag)
8580
return 0;
8681

8782
res = ps3flash_writeback(dev);
@@ -90,15 +85,11 @@ static int ps3flash_fetch(struct ps3_storage_device *dev, u64 start_sector,
9085

9186
priv->tag = -1;
9287

93-
lpar = dev->bounce_lpar + offset * dev->blk_size;
94-
res = ps3flash_read_write_sectors(dev, lpar, start_sector, sectors, 0);
88+
res = ps3flash_read_write_sectors(dev, start_sector, 0);
9589
if (res)
9690
return res;
9791

98-
/* We don't bother caching reads smaller than the chunk size */
99-
if (sectors == priv->chunk_sectors)
100-
priv->tag = tag;
101-
92+
priv->tag = start_sector;
10293
return 0;
10394
}
10495

@@ -134,7 +125,7 @@ static ssize_t ps3flash_read(char __user *userbuf, void *kernelbuf,
134125
{
135126
struct ps3_storage_device *dev = ps3flash_dev;
136127
struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
137-
u64 size, start_sector, end_sector, offset, sectors;
128+
u64 size, sector, offset;
138129
int res;
139130
size_t remaining, n;
140131
const void *src;
@@ -154,24 +145,20 @@ static ssize_t ps3flash_read(char __user *userbuf, void *kernelbuf,
154145
count = size - *pos;
155146
}
156147

157-
start_sector = *pos / dev->blk_size;
148+
sector = *pos / dev->bounce_size * priv->chunk_sectors;
158149
offset = *pos % dev->bounce_size;
159-
end_sector = DIV_ROUND_UP(*pos + count, dev->blk_size);
160150

161151
remaining = count;
162152
do {
163-
sectors = min(end_sector - start_sector,
164-
priv->chunk_sectors -
165-
start_sector % priv->chunk_sectors);
153+
n = min_t(u64, remaining, dev->bounce_size - offset);
154+
src = dev->bounce_buf + offset;
166155

167156
mutex_lock(&priv->mutex);
168157

169-
res = ps3flash_fetch(dev, start_sector, sectors);
158+
res = ps3flash_fetch(dev, sector);
170159
if (res)
171160
goto fail;
172161

173-
n = min_t(u64, remaining, dev->bounce_size - offset);
174-
src = dev->bounce_buf + offset;
175162
dev_dbg(&dev->sbd.core,
176163
"%s:%u: copy %lu bytes from 0x%p to U0x%p/K0x%p\n",
177164
__func__, __LINE__, n, src, userbuf, kernelbuf);
@@ -191,7 +178,7 @@ static ssize_t ps3flash_read(char __user *userbuf, void *kernelbuf,
191178

192179
*pos += n;
193180
remaining -= n;
194-
start_sector += sectors;
181+
sector += priv->chunk_sectors;
195182
offset = 0;
196183
} while (remaining > 0);
197184

@@ -233,17 +220,17 @@ static ssize_t ps3flash_write(const char __user *userbuf,
233220
remaining = count;
234221
do {
235222
n = min_t(u64, remaining, dev->bounce_size - offset);
223+
dst = dev->bounce_buf + offset;
236224

237225
mutex_lock(&priv->mutex);
238226

239227
if (n != dev->bounce_size)
240-
res = ps3flash_fetch(dev, sector, priv->chunk_sectors);
228+
res = ps3flash_fetch(dev, sector);
241229
else if (sector != priv->tag)
242230
res = ps3flash_writeback(dev);
243231
if (res)
244232
goto fail;
245233

246-
dst = dev->bounce_buf + offset;
247234
dev_dbg(&dev->sbd.core,
248235
"%s:%u: copy %lu bytes from U0x%p/K0x%p to 0x%p\n",
249236
__func__, __LINE__, n, userbuf, kernelbuf, dst);

0 commit comments

Comments
 (0)