Skip to content

Commit cd371e0

Browse files
Dean Luickgregkh
authored andcommitted
staging/rdma/hfi1: Adjust EPROM partitions, add EPROM commands
Add a new EPROM partition, adjusting partition placement. Add EPROM range commands as a supserset of the partition commands. Remove old partition commands. Enhance EPROM erase, creating a range function and using the largest erase (sub) commands when possible. Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com> Signed-off-by: Dean Luick <dean.luick@intel.com> Signed-off-by: Jubin John <jubin.john@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5d9157a commit cd371e0

3 files changed

Lines changed: 77 additions & 70 deletions

File tree

‎drivers/staging/rdma/hfi1/eprom.c‎

Lines changed: 67 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,26 @@
5353
#include "eprom.h"
5454

5555
/*
56-
* The EPROM is logically divided into two partitions:
56+
* The EPROM is logically divided into three partitions:
5757
* partition 0: the first 128K, visible from PCI ROM BAR
58-
* partition 1: the rest
58+
* partition 1: 4K config file (sector size)
59+
* partition 2: the rest
5960
*/
6061
#define P0_SIZE (128 * 1024)
62+
#define P1_SIZE (4 * 1024)
6163
#define P1_START P0_SIZE
64+
#define P2_START (P0_SIZE + P1_SIZE)
65+
66+
/* erase sizes supported by the controller */
67+
#define SIZE_4KB (4 * 1024)
68+
#define MASK_4KB (SIZE_4KB - 1)
6269

63-
/* largest erase size supported by the controller */
6470
#define SIZE_32KB (32 * 1024)
6571
#define MASK_32KB (SIZE_32KB - 1)
6672

73+
#define SIZE_64KB (64 * 1024)
74+
#define MASK_64KB (SIZE_64KB - 1)
75+
6776
/* controller page size, in bytes */
6877
#define EP_PAGE_SIZE 256
6978
#define EEP_PAGE_MASK (EP_PAGE_SIZE - 1)
@@ -75,10 +84,12 @@
7584
#define CMD_READ_DATA(addr) ((0x03 << CMD_SHIFT) | addr)
7685
#define CMD_READ_SR1 ((0x05 << CMD_SHIFT))
7786
#define CMD_WRITE_ENABLE ((0x06 << CMD_SHIFT))
87+
#define CMD_SECTOR_ERASE_4KB(addr) ((0x20 << CMD_SHIFT) | addr)
7888
#define CMD_SECTOR_ERASE_32KB(addr) ((0x52 << CMD_SHIFT) | addr)
7989
#define CMD_CHIP_ERASE ((0x60 << CMD_SHIFT))
8090
#define CMD_READ_MANUF_DEV_ID ((0x90 << CMD_SHIFT))
8191
#define CMD_RELEASE_POWERDOWN_NOID ((0xab << CMD_SHIFT))
92+
#define CMD_SECTOR_ERASE_64KB(addr) ((0xd8 << CMD_SHIFT) | addr)
8293

8394
/* controller interface speeds */
8495
#define EP_SPEED_FULL 0x2 /* full speed */
@@ -188,28 +199,43 @@ static int erase_chip(struct hfi1_devdata *dd)
188199
}
189200

190201
/*
191-
* Erase a range using the 32KB erase command.
202+
* Erase a range.
192203
*/
193-
static int erase_32kb_range(struct hfi1_devdata *dd, u32 start, u32 end)
204+
static int erase_range(struct hfi1_devdata *dd, u32 start, u32 len)
194205
{
206+
u32 end = start + len;
195207
int ret = 0;
196208

197209
if (end < start)
198210
return -EINVAL;
199211

200-
if ((start & MASK_32KB) || (end & MASK_32KB)) {
212+
/* check the end points for the minimum erase */
213+
if ((start & MASK_4KB) || (end & MASK_4KB)) {
201214
dd_dev_err(dd,
202-
"%s: non-aligned range (0x%x,0x%x) for a 32KB erase\n",
215+
"%s: non-aligned range (0x%x,0x%x) for a 4KB erase\n",
203216
__func__, start, end);
204217
return -EINVAL;
205218
}
206219

207220
write_enable(dd);
208221

209-
for (; start < end; start += SIZE_32KB) {
222+
while (start < end) {
210223
write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE);
211-
write_csr(dd, ASIC_EEP_ADDR_CMD,
212-
CMD_SECTOR_ERASE_32KB(start));
224+
/* check in order of largest to smallest */
225+
if (((start & MASK_64KB) == 0) && (start + SIZE_64KB <= end)) {
226+
write_csr(dd, ASIC_EEP_ADDR_CMD,
227+
CMD_SECTOR_ERASE_64KB(start));
228+
start += SIZE_64KB;
229+
} else if (((start & MASK_32KB) == 0) &&
230+
(start + SIZE_32KB <= end)) {
231+
write_csr(dd, ASIC_EEP_ADDR_CMD,
232+
CMD_SECTOR_ERASE_32KB(start));
233+
start += SIZE_32KB;
234+
} else { /* 4KB will work */
235+
write_csr(dd, ASIC_EEP_ADDR_CMD,
236+
CMD_SECTOR_ERASE_4KB(start));
237+
start += SIZE_4KB;
238+
}
213239
ret = wait_for_not_busy(dd);
214240
if (ret)
215241
goto done;
@@ -309,6 +335,18 @@ static int write_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr)
309335
return ret;
310336
}
311337

338+
/* convert an range composite to a length, in bytes */
339+
static inline u32 extract_rlen(u32 composite)
340+
{
341+
return (composite & 0xffff) * EP_PAGE_SIZE;
342+
}
343+
344+
/* convert an range composite to a start, in bytes */
345+
static inline u32 extract_rstart(u32 composite)
346+
{
347+
return (composite >> 16) * EP_PAGE_SIZE;
348+
}
349+
312350
/*
313351
* Perform the given operation on the EPROM. Called from user space. The
314352
* user credentials have already been checked.
@@ -319,6 +357,8 @@ int handle_eprom_command(const struct hfi1_cmd *cmd)
319357
{
320358
struct hfi1_devdata *dd;
321359
u32 dev_id;
360+
u32 rlen; /* range length */
361+
u32 rstart; /* range start */
322362
int ret = 0;
323363

324364
/*
@@ -364,54 +404,29 @@ int handle_eprom_command(const struct hfi1_cmd *cmd)
364404
sizeof(u32)))
365405
ret = -EFAULT;
366406
break;
407+
367408
case HFI1_CMD_EP_ERASE_CHIP:
368409
ret = erase_chip(dd);
369410
break;
370-
case HFI1_CMD_EP_ERASE_P0:
371-
if (cmd->len != P0_SIZE) {
372-
ret = -ERANGE;
373-
break;
374-
}
375-
ret = erase_32kb_range(dd, 0, cmd->len);
376-
break;
377-
case HFI1_CMD_EP_ERASE_P1:
378-
/* check for overflow */
379-
if (P1_START + cmd->len > ASIC_EEP_ADDR_CMD_EP_ADDR_MASK) {
380-
ret = -ERANGE;
381-
break;
382-
}
383-
ret = erase_32kb_range(dd, P1_START, P1_START + cmd->len);
384-
break;
385-
case HFI1_CMD_EP_READ_P0:
386-
if (cmd->len != P0_SIZE) {
387-
ret = -ERANGE;
388-
break;
389-
}
390-
ret = read_length(dd, 0, cmd->len, cmd->addr);
391-
break;
392-
case HFI1_CMD_EP_READ_P1:
393-
/* check for overflow */
394-
if (P1_START + cmd->len > ASIC_EEP_ADDR_CMD_EP_ADDR_MASK) {
395-
ret = -ERANGE;
396-
break;
397-
}
398-
ret = read_length(dd, P1_START, cmd->len, cmd->addr);
411+
412+
case HFI1_CMD_EP_ERASE_RANGE:
413+
rlen = extract_rlen(cmd->len);
414+
rstart = extract_rstart(cmd->len);
415+
ret = erase_range(dd, rstart, rlen);
399416
break;
400-
case HFI1_CMD_EP_WRITE_P0:
401-
if (cmd->len > P0_SIZE) {
402-
ret = -ERANGE;
403-
break;
404-
}
405-
ret = write_length(dd, 0, cmd->len, cmd->addr);
417+
418+
case HFI1_CMD_EP_READ_RANGE:
419+
rlen = extract_rlen(cmd->len);
420+
rstart = extract_rstart(cmd->len);
421+
ret = read_length(dd, rstart, rlen, cmd->addr);
406422
break;
407-
case HFI1_CMD_EP_WRITE_P1:
408-
/* check for overflow */
409-
if (P1_START + cmd->len > ASIC_EEP_ADDR_CMD_EP_ADDR_MASK) {
410-
ret = -ERANGE;
411-
break;
412-
}
413-
ret = write_length(dd, P1_START, cmd->len, cmd->addr);
423+
424+
case HFI1_CMD_EP_WRITE_RANGE:
425+
rlen = extract_rlen(cmd->len);
426+
rstart = extract_rstart(cmd->len);
427+
ret = write_length(dd, rstart, rlen, cmd->addr);
414428
break;
429+
415430
default:
416431
dd_dev_err(dd, "%s: unexpected command %d\n",
417432
__func__, cmd->type);

‎drivers/staging/rdma/hfi1/file_ops.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,9 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
234234
break;
235235
case HFI1_CMD_EP_INFO:
236236
case HFI1_CMD_EP_ERASE_CHIP:
237-
case HFI1_CMD_EP_ERASE_P0:
238-
case HFI1_CMD_EP_ERASE_P1:
239-
case HFI1_CMD_EP_READ_P0:
240-
case HFI1_CMD_EP_READ_P1:
241-
case HFI1_CMD_EP_WRITE_P0:
242-
case HFI1_CMD_EP_WRITE_P1:
237+
case HFI1_CMD_EP_ERASE_RANGE:
238+
case HFI1_CMD_EP_READ_RANGE:
239+
case HFI1_CMD_EP_WRITE_RANGE:
243240
uctxt_required = 0; /* assigned user context not required */
244241
must_be_root = 1; /* validate user */
245242
copy = 0;
@@ -393,12 +390,9 @@ static ssize_t hfi1_file_write(struct file *fp, const char __user *data,
393390
}
394391
case HFI1_CMD_EP_INFO:
395392
case HFI1_CMD_EP_ERASE_CHIP:
396-
case HFI1_CMD_EP_ERASE_P0:
397-
case HFI1_CMD_EP_ERASE_P1:
398-
case HFI1_CMD_EP_READ_P0:
399-
case HFI1_CMD_EP_READ_P1:
400-
case HFI1_CMD_EP_WRITE_P0:
401-
case HFI1_CMD_EP_WRITE_P1:
393+
case HFI1_CMD_EP_ERASE_RANGE:
394+
case HFI1_CMD_EP_READ_RANGE:
395+
case HFI1_CMD_EP_WRITE_RANGE:
402396
ret = handle_eprom_command(&cmd);
403397
break;
404398
}

‎include/uapi/rdma/hfi/hfi1_user.h‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,10 @@
137137
/* separate EPROM commands from normal PSM commands */
138138
#define HFI1_CMD_EP_INFO 64 /* read EPROM device ID */
139139
#define HFI1_CMD_EP_ERASE_CHIP 65 /* erase whole EPROM */
140-
#define HFI1_CMD_EP_ERASE_P0 66 /* erase EPROM partition 0 */
141-
#define HFI1_CMD_EP_ERASE_P1 67 /* erase EPROM partition 1 */
142-
#define HFI1_CMD_EP_READ_P0 68 /* read EPROM partition 0 */
143-
#define HFI1_CMD_EP_READ_P1 69 /* read EPROM partition 1 */
144-
#define HFI1_CMD_EP_WRITE_P0 70 /* write EPROM partition 0 */
145-
#define HFI1_CMD_EP_WRITE_P1 71 /* write EPROM partition 1 */
140+
/* range 66-74 no longer used */
141+
#define HFI1_CMD_EP_ERASE_RANGE 75 /* erase EPROM range */
142+
#define HFI1_CMD_EP_READ_RANGE 76 /* read EPROM range */
143+
#define HFI1_CMD_EP_WRITE_RANGE 77 /* write EPROM range */
146144

147145
#define _HFI1_EVENT_FROZEN_BIT 0
148146
#define _HFI1_EVENT_LINKDOWN_BIT 1

0 commit comments

Comments
 (0)