diff options
author | Thor Thayer <thor.thayer@linux.intel.com> | 2019-08-19 16:48:08 -0400 |
---|---|---|
committer | Moritz Fischer <mdf@kernel.org> | 2019-08-24 14:38:29 -0400 |
commit | e58915179f3f4a839ea3b9aeae1c1e13e98e33b1 (patch) | |
tree | 591f35bb204eda94683f9d359ecde4ddf51d7948 | |
parent | d2083d040a95b923a217377dd51c27d57eecf5e6 (diff) |
fpga: altera-cvp: Add Stratix10 (V2) Support
Add Stratix10 specific functions that use a credit mechanism
to throttle data to the CvP FIFOs. Add a private structure
with function pointers for V1 vs V2 functions.
Signed-off-by: Thor Thayer <thor.thayer@linux.intel.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
-rw-r--r-- | drivers/fpga/Kconfig | 6 | ||||
-rw-r--r-- | drivers/fpga/altera-cvp.c | 187 |
2 files changed, 176 insertions, 17 deletions
diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig index 474f304ec109..f50956ec1300 100644 --- a/drivers/fpga/Kconfig +++ b/drivers/fpga/Kconfig | |||
@@ -45,11 +45,11 @@ config FPGA_MGR_ALTERA_PS_SPI | |||
45 | using the passive serial interface over SPI. | 45 | using the passive serial interface over SPI. |
46 | 46 | ||
47 | config FPGA_MGR_ALTERA_CVP | 47 | config FPGA_MGR_ALTERA_CVP |
48 | tristate "Altera Arria-V/Cyclone-V/Stratix-V CvP FPGA Manager" | 48 | tristate "Altera CvP FPGA Manager" |
49 | depends on PCI | 49 | depends on PCI |
50 | help | 50 | help |
51 | FPGA manager driver support for Arria-V, Cyclone-V, Stratix-V | 51 | FPGA manager driver support for Arria-V, Cyclone-V, Stratix-V, |
52 | and Arria 10 Altera FPGAs using the CvP interface over PCIe. | 52 | Arria 10 and Stratix10 Altera FPGAs using the CvP interface over PCIe. |
53 | 53 | ||
54 | config FPGA_MGR_ZYNQ_FPGA | 54 | config FPGA_MGR_ZYNQ_FPGA |
55 | tristate "Xilinx Zynq FPGA" | 55 | tristate "Xilinx Zynq FPGA" |
diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c index 3b8386fd32e7..4e0edb60bfba 100644 --- a/drivers/fpga/altera-cvp.c +++ b/drivers/fpga/altera-cvp.c | |||
@@ -43,16 +43,34 @@ | |||
43 | #define VSE_CVP_PROG_CTRL 0x2c /* 32bit */ | 43 | #define VSE_CVP_PROG_CTRL 0x2c /* 32bit */ |
44 | #define VSE_CVP_PROG_CTRL_CONFIG BIT(0) | 44 | #define VSE_CVP_PROG_CTRL_CONFIG BIT(0) |
45 | #define VSE_CVP_PROG_CTRL_START_XFER BIT(1) | 45 | #define VSE_CVP_PROG_CTRL_START_XFER BIT(1) |
46 | #define VSE_CVP_PROG_CTRL_MASK GENMASK(1, 0) | ||
46 | 47 | ||
47 | #define VSE_UNCOR_ERR_STATUS 0x34 /* 32bit */ | 48 | #define VSE_UNCOR_ERR_STATUS 0x34 /* 32bit */ |
48 | #define VSE_UNCOR_ERR_CVP_CFG_ERR BIT(5) /* CVP_CONFIG_ERROR_LATCHED */ | 49 | #define VSE_UNCOR_ERR_CVP_CFG_ERR BIT(5) /* CVP_CONFIG_ERROR_LATCHED */ |
49 | 50 | ||
51 | #define V1_VSEC_OFFSET 0x200 /* Vendor Specific Offset V1 */ | ||
52 | /* V2 Defines */ | ||
53 | #define VSE_CVP_TX_CREDITS 0x49 /* 8bit */ | ||
54 | |||
55 | #define V2_CREDIT_TIMEOUT_US 20000 | ||
56 | #define V2_CHECK_CREDIT_US 10 | ||
57 | #define V2_POLL_TIMEOUT_US 1000000 | ||
58 | #define V2_USER_TIMEOUT_US 500000 | ||
59 | |||
60 | #define V1_POLL_TIMEOUT_US 10 | ||
61 | |||
50 | #define DRV_NAME "altera-cvp" | 62 | #define DRV_NAME "altera-cvp" |
51 | #define ALTERA_CVP_MGR_NAME "Altera CvP FPGA Manager" | 63 | #define ALTERA_CVP_MGR_NAME "Altera CvP FPGA Manager" |
52 | 64 | ||
65 | /* Write block sizes */ | ||
66 | #define ALTERA_CVP_V1_SIZE 4 | ||
67 | #define ALTERA_CVP_V2_SIZE 4096 | ||
68 | |||
53 | /* Optional CvP config error status check for debugging */ | 69 | /* Optional CvP config error status check for debugging */ |
54 | static bool altera_cvp_chkcfg; | 70 | static bool altera_cvp_chkcfg; |
55 | 71 | ||
72 | struct cvp_priv; | ||
73 | |||
56 | struct altera_cvp_conf { | 74 | struct altera_cvp_conf { |
57 | struct fpga_manager *mgr; | 75 | struct fpga_manager *mgr; |
58 | struct pci_dev *pci_dev; | 76 | struct pci_dev *pci_dev; |
@@ -61,9 +79,27 @@ struct altera_cvp_conf { | |||
61 | u32 data); | 79 | u32 data); |
62 | char mgr_name[64]; | 80 | char mgr_name[64]; |
63 | u8 numclks; | 81 | u8 numclks; |
82 | u32 sent_packets; | ||
64 | u32 vsec_offset; | 83 | u32 vsec_offset; |
84 | const struct cvp_priv *priv; | ||
65 | }; | 85 | }; |
66 | 86 | ||
87 | struct cvp_priv { | ||
88 | void (*switch_clk)(struct altera_cvp_conf *conf); | ||
89 | int (*clear_state)(struct altera_cvp_conf *conf); | ||
90 | int (*wait_credit)(struct fpga_manager *mgr, u32 blocks); | ||
91 | size_t block_size; | ||
92 | int poll_time_us; | ||
93 | int user_time_us; | ||
94 | }; | ||
95 | |||
96 | static int altera_read_config_byte(struct altera_cvp_conf *conf, | ||
97 | int where, u8 *val) | ||
98 | { | ||
99 | return pci_read_config_byte(conf->pci_dev, conf->vsec_offset + where, | ||
100 | val); | ||
101 | } | ||
102 | |||
67 | static int altera_read_config_dword(struct altera_cvp_conf *conf, | 103 | static int altera_read_config_dword(struct altera_cvp_conf *conf, |
68 | int where, u32 *val) | 104 | int where, u32 *val) |
69 | { | 105 | { |
@@ -159,6 +195,73 @@ static int altera_cvp_chk_error(struct fpga_manager *mgr, size_t bytes) | |||
159 | return 0; | 195 | return 0; |
160 | } | 196 | } |
161 | 197 | ||
198 | /* | ||
199 | * CvP Version2 Functions | ||
200 | * Recent Intel FPGAs use a credit mechanism to throttle incoming | ||
201 | * bitstreams and a different method of clearing the state. | ||
202 | */ | ||
203 | |||
204 | static int altera_cvp_v2_clear_state(struct altera_cvp_conf *conf) | ||
205 | { | ||
206 | u32 val; | ||
207 | int ret; | ||
208 | |||
209 | /* Clear the START_XFER and CVP_CONFIG bits */ | ||
210 | ret = altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); | ||
211 | if (ret) { | ||
212 | dev_err(&conf->pci_dev->dev, | ||
213 | "Error reading CVP Program Control Register\n"); | ||
214 | return ret; | ||
215 | } | ||
216 | |||
217 | val &= ~VSE_CVP_PROG_CTRL_MASK; | ||
218 | ret = altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val); | ||
219 | if (ret) { | ||
220 | dev_err(&conf->pci_dev->dev, | ||
221 | "Error writing CVP Program Control Register\n"); | ||
222 | return ret; | ||
223 | } | ||
224 | |||
225 | return altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, 0, | ||
226 | conf->priv->poll_time_us); | ||
227 | } | ||
228 | |||
229 | static int altera_cvp_v2_wait_for_credit(struct fpga_manager *mgr, | ||
230 | u32 blocks) | ||
231 | { | ||
232 | u32 timeout = V2_CREDIT_TIMEOUT_US / V2_CHECK_CREDIT_US; | ||
233 | struct altera_cvp_conf *conf = mgr->priv; | ||
234 | int ret; | ||
235 | u8 val; | ||
236 | |||
237 | do { | ||
238 | ret = altera_read_config_byte(conf, VSE_CVP_TX_CREDITS, &val); | ||
239 | if (ret) { | ||
240 | dev_err(&conf->pci_dev->dev, | ||
241 | "Error reading CVP Credit Register\n"); | ||
242 | return ret; | ||
243 | } | ||
244 | |||
245 | /* Return if there is space in FIFO */ | ||
246 | if (val - (u8)conf->sent_packets) | ||
247 | return 0; | ||
248 | |||
249 | ret = altera_cvp_chk_error(mgr, blocks * ALTERA_CVP_V2_SIZE); | ||
250 | if (ret) { | ||
251 | dev_err(&conf->pci_dev->dev, | ||
252 | "CE Bit error credit reg[0x%x]:sent[0x%x]\n", | ||
253 | val, conf->sent_packets); | ||
254 | return -EAGAIN; | ||
255 | } | ||
256 | |||
257 | /* Limit the check credit byte traffic */ | ||
258 | usleep_range(V2_CHECK_CREDIT_US, V2_CHECK_CREDIT_US + 1); | ||
259 | } while (timeout--); | ||
260 | |||
261 | dev_err(&conf->pci_dev->dev, "Timeout waiting for credit\n"); | ||
262 | return -ETIMEDOUT; | ||
263 | } | ||
264 | |||
162 | static int altera_cvp_send_block(struct altera_cvp_conf *conf, | 265 | static int altera_cvp_send_block(struct altera_cvp_conf *conf, |
163 | const u32 *data, size_t len) | 266 | const u32 *data, size_t len) |
164 | { | 267 | { |
@@ -200,10 +303,12 @@ static int altera_cvp_teardown(struct fpga_manager *mgr, | |||
200 | * - set CVP_NUMCLKS to 1 and then issue CVP_DUMMY_WR dummy | 303 | * - set CVP_NUMCLKS to 1 and then issue CVP_DUMMY_WR dummy |
201 | * writes to the HIP | 304 | * writes to the HIP |
202 | */ | 305 | */ |
203 | altera_cvp_dummy_write(conf); /* from CVP clock to internal clock */ | 306 | if (conf->priv->switch_clk) |
307 | conf->priv->switch_clk(conf); | ||
204 | 308 | ||
205 | /* STEP 15 - poll CVP_CONFIG_READY bit for 0 with 10us timeout */ | 309 | /* STEP 15 - poll CVP_CONFIG_READY bit for 0 with 10us timeout */ |
206 | ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, 0, 10); | 310 | ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, 0, |
311 | conf->priv->poll_time_us); | ||
207 | if (ret) | 312 | if (ret) |
208 | dev_err(&mgr->dev, "CFG_RDY == 0 timeout\n"); | 313 | dev_err(&mgr->dev, "CFG_RDY == 0 timeout\n"); |
209 | 314 | ||
@@ -265,7 +370,18 @@ static int altera_cvp_write_init(struct fpga_manager *mgr, | |||
265 | * STEP 3 | 370 | * STEP 3 |
266 | * - set CVP_NUMCLKS to 1 and issue CVP_DUMMY_WR dummy writes to the HIP | 371 | * - set CVP_NUMCLKS to 1 and issue CVP_DUMMY_WR dummy writes to the HIP |
267 | */ | 372 | */ |
268 | altera_cvp_dummy_write(conf); | 373 | if (conf->priv->switch_clk) |
374 | conf->priv->switch_clk(conf); | ||
375 | |||
376 | if (conf->priv->clear_state) { | ||
377 | ret = conf->priv->clear_state(conf); | ||
378 | if (ret) { | ||
379 | dev_err(&mgr->dev, "Problem clearing out state\n"); | ||
380 | return ret; | ||
381 | } | ||
382 | } | ||
383 | |||
384 | conf->sent_packets = 0; | ||
269 | 385 | ||
270 | /* STEP 4 - set CVP_CONFIG bit */ | 386 | /* STEP 4 - set CVP_CONFIG bit */ |
271 | altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); | 387 | altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); |
@@ -273,9 +389,10 @@ static int altera_cvp_write_init(struct fpga_manager *mgr, | |||
273 | val |= VSE_CVP_PROG_CTRL_CONFIG; | 389 | val |= VSE_CVP_PROG_CTRL_CONFIG; |
274 | altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val); | 390 | altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val); |
275 | 391 | ||
276 | /* STEP 5 - poll CVP_CONFIG READY for 1 with 10us timeout */ | 392 | /* STEP 5 - poll CVP_CONFIG READY for 1 with timeout */ |
277 | ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, | 393 | ret = altera_cvp_wait_status(conf, VSE_CVP_STATUS_CFG_RDY, |
278 | VSE_CVP_STATUS_CFG_RDY, 10); | 394 | VSE_CVP_STATUS_CFG_RDY, |
395 | conf->priv->poll_time_us); | ||
279 | if (ret) { | 396 | if (ret) { |
280 | dev_warn(&mgr->dev, "CFG_RDY == 1 timeout\n"); | 397 | dev_warn(&mgr->dev, "CFG_RDY == 1 timeout\n"); |
281 | return ret; | 398 | return ret; |
@@ -285,7 +402,16 @@ static int altera_cvp_write_init(struct fpga_manager *mgr, | |||
285 | * STEP 6 | 402 | * STEP 6 |
286 | * - set CVP_NUMCLKS to 1 and issue CVP_DUMMY_WR dummy writes to the HIP | 403 | * - set CVP_NUMCLKS to 1 and issue CVP_DUMMY_WR dummy writes to the HIP |
287 | */ | 404 | */ |
288 | altera_cvp_dummy_write(conf); | 405 | if (conf->priv->switch_clk) |
406 | conf->priv->switch_clk(conf); | ||
407 | |||
408 | if (altera_cvp_chkcfg) { | ||
409 | ret = altera_cvp_chk_error(mgr, 0); | ||
410 | if (ret) { | ||
411 | dev_warn(&mgr->dev, "CFG_RDY == 1 timeout\n"); | ||
412 | return ret; | ||
413 | } | ||
414 | } | ||
289 | 415 | ||
290 | /* STEP 7 - set START_XFER */ | 416 | /* STEP 7 - set START_XFER */ |
291 | altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); | 417 | altera_read_config_dword(conf, VSE_CVP_PROG_CTRL, &val); |
@@ -293,11 +419,12 @@ static int altera_cvp_write_init(struct fpga_manager *mgr, | |||
293 | altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val); | 419 | altera_write_config_dword(conf, VSE_CVP_PROG_CTRL, val); |
294 | 420 | ||
295 | /* STEP 8 - start transfer (set CVP_NUMCLKS for bitstream) */ | 421 | /* STEP 8 - start transfer (set CVP_NUMCLKS for bitstream) */ |
296 | altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val); | 422 | if (conf->priv->switch_clk) { |
297 | val &= ~VSE_CVP_MODE_CTRL_NUMCLKS_MASK; | 423 | altera_read_config_dword(conf, VSE_CVP_MODE_CTRL, &val); |
298 | val |= conf->numclks << VSE_CVP_MODE_CTRL_NUMCLKS_OFF; | 424 | val &= ~VSE_CVP_MODE_CTRL_NUMCLKS_MASK; |
299 | altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val); | 425 | val |= conf->numclks << VSE_CVP_MODE_CTRL_NUMCLKS_OFF; |
300 | 426 | altera_write_config_dword(conf, VSE_CVP_MODE_CTRL, val); | |
427 | } | ||
301 | return 0; | 428 | return 0; |
302 | } | 429 | } |
303 | 430 | ||
@@ -315,11 +442,22 @@ static int altera_cvp_write(struct fpga_manager *mgr, const char *buf, | |||
315 | done = 0; | 442 | done = 0; |
316 | 443 | ||
317 | while (remaining) { | 444 | while (remaining) { |
318 | len = min(sizeof(u32), remaining); | 445 | /* Use credit throttling if available */ |
446 | if (conf->priv->wait_credit) { | ||
447 | status = conf->priv->wait_credit(mgr, done); | ||
448 | if (status) { | ||
449 | dev_err(&conf->pci_dev->dev, | ||
450 | "Wait Credit ERR: 0x%x\n", status); | ||
451 | return status; | ||
452 | } | ||
453 | } | ||
454 | |||
455 | len = min(conf->priv->block_size, remaining); | ||
319 | altera_cvp_send_block(conf, data, len); | 456 | altera_cvp_send_block(conf, data, len); |
320 | data++; | 457 | data += len / sizeof(u32); |
321 | done += len; | 458 | done += len; |
322 | remaining -= len; | 459 | remaining -= len; |
460 | conf->sent_packets++; | ||
323 | 461 | ||
324 | /* | 462 | /* |
325 | * STEP 10 (optional) and STEP 11 | 463 | * STEP 10 (optional) and STEP 11 |
@@ -369,7 +507,8 @@ static int altera_cvp_write_complete(struct fpga_manager *mgr, | |||
369 | 507 | ||
370 | /* STEP 18 - poll PLD_CLK_IN_USE and USER_MODE bits */ | 508 | /* STEP 18 - poll PLD_CLK_IN_USE and USER_MODE bits */ |
371 | mask = VSE_CVP_STATUS_PLD_CLK_IN_USE | VSE_CVP_STATUS_USERMODE; | 509 | mask = VSE_CVP_STATUS_PLD_CLK_IN_USE | VSE_CVP_STATUS_USERMODE; |
372 | ret = altera_cvp_wait_status(conf, mask, mask, TIMEOUT_US); | 510 | ret = altera_cvp_wait_status(conf, mask, mask, |
511 | conf->priv->user_time_us); | ||
373 | if (ret) | 512 | if (ret) |
374 | dev_err(&mgr->dev, "PLD_CLK_IN_USE|USERMODE timeout\n"); | 513 | dev_err(&mgr->dev, "PLD_CLK_IN_USE|USERMODE timeout\n"); |
375 | 514 | ||
@@ -383,6 +522,21 @@ static const struct fpga_manager_ops altera_cvp_ops = { | |||
383 | .write_complete = altera_cvp_write_complete, | 522 | .write_complete = altera_cvp_write_complete, |
384 | }; | 523 | }; |
385 | 524 | ||
525 | static const struct cvp_priv cvp_priv_v1 = { | ||
526 | .switch_clk = altera_cvp_dummy_write, | ||
527 | .block_size = ALTERA_CVP_V1_SIZE, | ||
528 | .poll_time_us = V1_POLL_TIMEOUT_US, | ||
529 | .user_time_us = TIMEOUT_US, | ||
530 | }; | ||
531 | |||
532 | static const struct cvp_priv cvp_priv_v2 = { | ||
533 | .clear_state = altera_cvp_v2_clear_state, | ||
534 | .wait_credit = altera_cvp_v2_wait_for_credit, | ||
535 | .block_size = ALTERA_CVP_V2_SIZE, | ||
536 | .poll_time_us = V2_POLL_TIMEOUT_US, | ||
537 | .user_time_us = V2_USER_TIMEOUT_US, | ||
538 | }; | ||
539 | |||
386 | static ssize_t chkcfg_show(struct device_driver *dev, char *buf) | 540 | static ssize_t chkcfg_show(struct device_driver *dev, char *buf) |
387 | { | 541 | { |
388 | return snprintf(buf, 3, "%d\n", altera_cvp_chkcfg); | 542 | return snprintf(buf, 3, "%d\n", altera_cvp_chkcfg); |
@@ -484,6 +638,11 @@ static int altera_cvp_probe(struct pci_dev *pdev, | |||
484 | conf->pci_dev = pdev; | 638 | conf->pci_dev = pdev; |
485 | conf->write_data = altera_cvp_write_data_iomem; | 639 | conf->write_data = altera_cvp_write_data_iomem; |
486 | 640 | ||
641 | if (conf->vsec_offset == V1_VSEC_OFFSET) | ||
642 | conf->priv = &cvp_priv_v1; | ||
643 | else | ||
644 | conf->priv = &cvp_priv_v2; | ||
645 | |||
487 | conf->map = pci_iomap(pdev, CVP_BAR, 0); | 646 | conf->map = pci_iomap(pdev, CVP_BAR, 0); |
488 | if (!conf->map) { | 647 | if (!conf->map) { |
489 | dev_warn(&pdev->dev, "Mapping CVP BAR failed\n"); | 648 | dev_warn(&pdev->dev, "Mapping CVP BAR failed\n"); |