| @@ -53,17 +53,26 @@ · 52 unmodified lines |
| 53 | 53 | #include "eprom.h" |
| 54 | 54 | |
| 55 | 55 | /* |
| 56 | | − * The EPROM is logically divided into two partitions: |
| 56 | + * The EPROM is logically divided into three partitions: |
| 57 | 57 | * 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 |
| 59 | 60 | */ |
| 60 | 61 | #define P0_SIZE (128 * 1024) |
| 62 | +#define P1_SIZE (4 * 1024) |
| 61 | 63 | #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) |
| 62 | 69 | |
| 63 | | −/* largest erase size supported by the controller */ |
| 64 | 70 | #define SIZE_32KB (32 * 1024) |
| 65 | 71 | #define MASK_32KB (SIZE_32KB - 1) |
| 66 | 72 | |
| 73 | +#define SIZE_64KB (64 * 1024) |
| 74 | +#define MASK_64KB (SIZE_64KB - 1) |
| 75 | + |
| 67 | 76 | /* controller page size, in bytes */ |
| 68 | 77 | #define EP_PAGE_SIZE 256 |
| 69 | 78 | #define EEP_PAGE_MASK (EP_PAGE_SIZE - 1) |
| @@ -75,10 +84,12 @@ · 5 unmodified lines |
| 75 | 84 | #define CMD_READ_DATA(addr) ((0x03 << CMD_SHIFT) | addr) |
| 76 | 85 | #define CMD_READ_SR1 ((0x05 << CMD_SHIFT)) |
| 77 | 86 | #define CMD_WRITE_ENABLE ((0x06 << CMD_SHIFT)) |
| 87 | +#define CMD_SECTOR_ERASE_4KB(addr) ((0x20 << CMD_SHIFT) | addr) |
| 78 | 88 | #define CMD_SECTOR_ERASE_32KB(addr) ((0x52 << CMD_SHIFT) | addr) |
| 79 | 89 | #define CMD_CHIP_ERASE ((0x60 << CMD_SHIFT)) |
| 80 | 90 | #define CMD_READ_MANUF_DEV_ID ((0x90 << CMD_SHIFT)) |
| 81 | 91 | #define CMD_RELEASE_POWERDOWN_NOID ((0xab << CMD_SHIFT)) |
| 92 | +#define CMD_SECTOR_ERASE_64KB(addr) ((0xd8 << CMD_SHIFT) | addr) |
| 82 | 93 | |
| 83 | 94 | /* controller interface speeds */ |
| 84 | 95 | #define EP_SPEED_FULL 0x2 /* full speed */ |
| @@ -188,28 +199,43 @@ static int erase_chip(struct hfi1_devdata *dd) · 103 unmodified lines |
| 188 | 199 | } |
| 189 | 200 | |
| 190 | 201 | /* |
| 191 | | − * Erase a range using the 32KB erase command. |
| 202 | + * Erase a range. |
| 192 | 203 | */ |
| 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) |
| 194 | 205 | { |
| 206 | + u32 end = start + len; |
| 195 | 207 | int ret = 0; |
| 196 | 208 | |
| 197 | 209 | if (end < start) |
| 198 | 210 | return -EINVAL; |
| 199 | 211 | |
| 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)) { |
| 201 | 214 | 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", |
| 203 | 216 | __func__, start, end); |
| 204 | 217 | return -EINVAL; |
| 205 | 218 | } |
| 206 | 219 | |
| 207 | 220 | write_enable(dd); |
| 208 | 221 | |
| 209 | | − for (; start < end; start += SIZE_32KB) { |
| 222 | + while (start < end) { |
| 210 | 223 | 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 | + } |
| 213 | 239 | ret = wait_for_not_busy(dd); |
| 214 | 240 | if (ret) |
| 215 | 241 | goto done; |
| @@ -309,6 +335,18 @@ done: · 93 unmodified lines |
| 309 | 335 | return ret; |
| 310 | 336 | } |
| 311 | 337 | |
| 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 | + |
| 312 | 350 | /* |
| 313 | 351 | * Perform the given operation on the EPROM. Called from user space. The |
| 314 | 352 | * user credentials have already been checked. |
| @@ -319,6 +357,8 @@ int handle_eprom_command(const struct hfi1_cmd *cmd) · 4 unmodified lines |
| 319 | 357 | { |
| 320 | 358 | struct hfi1_devdata *dd; |
| 321 | 359 | u32 dev_id; |
| 360 | + u32 rlen; /* range length */ |
| 361 | + u32 rstart; /* range start */ |
| 322 | 362 | int ret = 0; |
| 323 | 363 | |
| 324 | 364 | /* |
| @@ -364,54 +404,29 @@ int handle_eprom_command(const struct hfi1_cmd *cmd) · 39 unmodified lines |
| 364 | 404 | sizeof(u32))) |
| 365 | 405 | ret = -EFAULT; |
| 366 | 406 | break; |
| 407 | + |
| 367 | 408 | case HFI1_CMD_EP_ERASE_CHIP: |
| 368 | 409 | ret = erase_chip(dd); |
| 369 | 410 | 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); |
| 399 | 416 | 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); |
| 406 | 422 | 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); |
| 414 | 428 | break; |
| 429 | + |
| 415 | 430 | default: |
| 416 | 431 | dd_dev_err(dd, "%s: unexpected command %d\n", |
| 417 | 432 | __func__, cmd->type); |