Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fsl-rio: Add two ports and rapidio message units support

Usually, freescale rapidio endpoint can support one or two 1x or 4X
LP-Serial link interfaces, and rapidio message transactions can be
implemented by two message units. This adds the support of two
rapidio ports and initializes message unit 0 and message unit 1. And
these ports and message units can work simultaneously.

Signed-off-by: Li Yang <leoli@freescale.com>
Signed-off-by: Jin Qing <b24347@freescale.com>
Signed-off-by: Liu Gang <Gang.Liu@freescale.com>
Acked-by: Alexandre Bounine <alexandre.bounine@idt.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

authored by

Liu Gang and committed by
Kumar Gala
abc3aeae 6ec4bedb

+548 -426
+262 -137
arch/powerpc/sysdev/fsl_rio.c
··· 45 45 #define RIO_PORT1_IECSR 0x10130 46 46 #define RIO_PORT2_IECSR 0x101B0 47 47 48 - #define RIO_ATMU_REGS_OFFSET 0x10c00 49 48 #define RIO_GCCSR 0x13c 50 49 #define RIO_ESCSR 0x158 51 50 #define ESCSR_CLEAR 0x07120204 ··· 73 74 : "b" (addr), "i" (-EFAULT), "0" (err)) 74 75 75 76 void __iomem *rio_regs_win; 77 + void __iomem *rmu_regs_win; 78 + resource_size_t rio_law_start; 79 + 80 + struct fsl_rio_dbell *dbell; 81 + struct fsl_rio_pw *pw; 76 82 77 83 #ifdef CONFIG_E500 78 84 int fsl_rio_mcheck_exception(struct pt_regs *regs) ··· 124 120 { 125 121 struct rio_priv *priv = mport->priv; 126 122 pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index, 127 - offset); 123 + offset); 128 124 *data = in_be32(priv->regs_win + offset); 129 125 130 126 return 0; ··· 177 173 pr_debug 178 174 ("fsl_rio_config_read:" 179 175 " index %d destid %d hopcount %d offset %8.8x len %d\n", 180 - index, destid, hopcount, offset, len); 176 + index, destid, hopcount, offset, len); 181 177 182 178 /* 16MB maintenance window possible */ 183 179 /* allow only aligned access to maintenance registers */ ··· 234 230 u8 *data; 235 231 pr_debug 236 232 ("fsl_rio_config_write:" 237 - "index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n", 238 - index, destid, hopcount, offset, len, val); 233 + " index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n", 234 + index, destid, hopcount, offset, len, val); 239 235 240 236 /* 16MB maintenance windows possible */ 241 237 /* allow only aligned access to maintenance registers */ ··· 264 260 return 0; 265 261 } 266 262 267 - void fsl_rio_port_error_handler(struct rio_mport *port, int offset) 263 + void fsl_rio_port_error_handler(int offset) 268 264 { 269 265 /*XXX: Error recovery is not implemented, we just clear errors */ 270 266 out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0); ··· 335 331 struct rio_mport *port; 336 332 struct rio_priv *priv; 337 333 int rc = 0; 338 - const u32 *dt_range, *cell; 339 - struct resource regs; 334 + const u32 *dt_range, *cell, *port_index; 335 + u32 active_ports = 0; 336 + struct resource regs, rmu_regs; 337 + struct device_node *np, *rmu_node; 340 338 int rlen; 341 339 u32 ccsr; 342 - u64 law_start, law_size; 340 + u64 range_start, range_size; 343 341 int paw, aw, sw; 342 + u32 i; 343 + static int tmp; 344 + struct device_node *rmu_np[MAX_MSG_UNIT_NUM] = {NULL}; 344 345 345 346 if (!dev->dev.of_node) { 346 347 dev_err(&dev->dev, "Device OF-Node is NULL"); 347 - return -EFAULT; 348 + return -ENODEV; 348 349 } 349 350 350 351 rc = of_address_to_resource(dev->dev.of_node, 0, &regs); ··· 362 353 dev->dev.of_node->full_name); 363 354 dev_info(&dev->dev, "Regs: %pR\n", &regs); 364 355 365 - dt_range = of_get_property(dev->dev.of_node, "ranges", &rlen); 366 - if (!dt_range) { 367 - dev_err(&dev->dev, "Can't get %s property 'ranges'\n", 368 - dev->dev.of_node->full_name); 369 - return -EFAULT; 356 + rio_regs_win = ioremap(regs.start, resource_size(&regs)); 357 + if (!rio_regs_win) { 358 + dev_err(&dev->dev, "Unable to map rio register window\n"); 359 + rc = -ENOMEM; 360 + goto err_rio_regs; 370 361 } 371 - 372 - /* Get node address wide */ 373 - cell = of_get_property(dev->dev.of_node, "#address-cells", NULL); 374 - if (cell) 375 - aw = *cell; 376 - else 377 - aw = of_n_addr_cells(dev->dev.of_node); 378 - /* Get node size wide */ 379 - cell = of_get_property(dev->dev.of_node, "#size-cells", NULL); 380 - if (cell) 381 - sw = *cell; 382 - else 383 - sw = of_n_size_cells(dev->dev.of_node); 384 - /* Get parent address wide wide */ 385 - paw = of_n_addr_cells(dev->dev.of_node); 386 - 387 - law_start = of_read_number(dt_range + aw, paw); 388 - law_size = of_read_number(dt_range + aw + paw, sw); 389 - 390 - dev_info(&dev->dev, "LAW start 0x%016llx, size 0x%016llx.\n", 391 - law_start, law_size); 392 362 393 363 ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL); 394 364 if (!ops) { ··· 378 390 ops->lcwrite = fsl_local_config_write; 379 391 ops->cread = fsl_rio_config_read; 380 392 ops->cwrite = fsl_rio_config_write; 393 + ops->dsend = fsl_rio_doorbell_send; 381 394 ops->pwenable = fsl_rio_pw_enable; 395 + ops->open_outb_mbox = fsl_open_outb_mbox; 396 + ops->open_inb_mbox = fsl_open_inb_mbox; 397 + ops->close_outb_mbox = fsl_close_outb_mbox; 398 + ops->close_inb_mbox = fsl_close_inb_mbox; 399 + ops->add_outb_message = fsl_add_outb_message; 400 + ops->add_inb_buffer = fsl_add_inb_buffer; 401 + ops->get_inb_message = fsl_get_inb_message; 382 402 383 - port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL); 384 - if (!port) { 403 + rmu_node = of_parse_phandle(dev->dev.of_node, "fsl,srio-rmu-handle", 0); 404 + if (!rmu_node) 405 + goto err_rmu; 406 + rc = of_address_to_resource(rmu_node, 0, &rmu_regs); 407 + if (rc) { 408 + dev_err(&dev->dev, "Can't get %s property 'reg'\n", 409 + rmu_node->full_name); 410 + goto err_rmu; 411 + } 412 + rmu_regs_win = ioremap(rmu_regs.start, resource_size(&rmu_regs)); 413 + if (!rmu_regs_win) { 414 + dev_err(&dev->dev, "Unable to map rmu register window\n"); 385 415 rc = -ENOMEM; 386 - goto err_port; 416 + goto err_rmu; 387 417 } 388 - port->index = 0; 418 + for_each_compatible_node(np, NULL, "fsl,srio-msg-unit") { 419 + rmu_np[tmp] = np; 420 + tmp++; 421 + } 389 422 390 - priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL); 391 - if (!priv) { 392 - printk(KERN_ERR "Can't alloc memory for 'priv'\n"); 423 + /*set up doobell node*/ 424 + np = of_find_compatible_node(NULL, NULL, "fsl,srio-dbell-unit"); 425 + if (!np) { 426 + rc = -ENODEV; 427 + goto err_dbell; 428 + } 429 + dbell = kzalloc(sizeof(struct fsl_rio_dbell), GFP_KERNEL); 430 + if (!(dbell)) { 431 + dev_err(&dev->dev, "Can't alloc memory for 'fsl_rio_dbell'\n"); 393 432 rc = -ENOMEM; 394 - goto err_priv; 433 + goto err_dbell; 395 434 } 435 + dbell->dev = &dev->dev; 436 + dbell->bellirq = irq_of_parse_and_map(np, 1); 437 + dev_info(&dev->dev, "bellirq: %d\n", dbell->bellirq); 396 438 397 - INIT_LIST_HEAD(&port->dbells); 398 - port->iores.start = law_start; 399 - port->iores.end = law_start + law_size - 1; 400 - port->iores.flags = IORESOURCE_MEM; 401 - port->iores.name = "rio_io_win"; 402 - 403 - if (request_resource(&iomem_resource, &port->iores) < 0) { 404 - dev_err(&dev->dev, "RIO: Error requesting master port region" 405 - " 0x%016llx-0x%016llx\n", 406 - (u64)port->iores.start, (u64)port->iores.end); 407 - rc = -ENOMEM; 408 - goto err_res; 439 + aw = of_n_addr_cells(np); 440 + dt_range = of_get_property(np, "reg", &rlen); 441 + if (!dt_range) { 442 + pr_err("%s: unable to find 'reg' property\n", 443 + np->full_name); 444 + rc = -ENOMEM; 445 + goto err_pw; 409 446 } 447 + range_start = of_read_number(dt_range, aw); 448 + dbell->dbell_regs = (struct rio_dbell_regs *)(rmu_regs_win + 449 + (u32)range_start); 410 450 411 - priv->pwirq = irq_of_parse_and_map(dev->dev.of_node, 0); 412 - dev_info(&dev->dev, "pwirq: %d\n", priv->pwirq); 413 - strcpy(port->name, "RIO0 mport"); 414 - 415 - priv->dev = &dev->dev; 416 - 417 - port->ops = ops; 418 - port->priv = priv; 419 - port->phys_efptr = 0x100; 420 - 421 - priv->regs_win = ioremap(regs.start, resource_size(&regs)); 422 - rio_regs_win = priv->regs_win; 423 - 424 - /* Probe the master port phy type */ 425 - ccsr = in_be32(priv->regs_win + RIO_CCSR); 426 - port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL; 427 - dev_info(&dev->dev, "RapidIO PHY type: %s\n", 428 - (port->phy_type == RIO_PHY_PARALLEL) ? "parallel" : 429 - ((port->phy_type == RIO_PHY_SERIAL) ? "serial" : 430 - "unknown")); 431 - /* Checking the port training status */ 432 - if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) { 433 - dev_err(&dev->dev, "Port is not ready. " 434 - "Try to restart connection...\n"); 435 - switch (port->phy_type) { 436 - case RIO_PHY_SERIAL: 437 - /* Disable ports */ 438 - out_be32(priv->regs_win + RIO_CCSR, 0); 439 - /* Set 1x lane */ 440 - setbits32(priv->regs_win + RIO_CCSR, 0x02000000); 441 - /* Enable ports */ 442 - setbits32(priv->regs_win + RIO_CCSR, 0x00600000); 443 - break; 444 - case RIO_PHY_PARALLEL: 445 - /* Disable ports */ 446 - out_be32(priv->regs_win + RIO_CCSR, 0x22000000); 447 - /* Enable ports */ 448 - out_be32(priv->regs_win + RIO_CCSR, 0x44000000); 449 - break; 450 - } 451 - msleep(100); 452 - if (in_be32((priv->regs_win + RIO_ESCSR)) & 1) { 453 - dev_err(&dev->dev, "Port restart failed.\n"); 454 - rc = -ENOLINK; 455 - goto err; 456 - } 457 - dev_info(&dev->dev, "Port restart success!\n"); 451 + /*set up port write node*/ 452 + np = of_find_compatible_node(NULL, NULL, "fsl,srio-port-write-unit"); 453 + if (!np) { 454 + rc = -ENODEV; 455 + goto err_pw; 458 456 } 459 - fsl_rio_info(&dev->dev, ccsr); 460 - 461 - port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR)) 462 - & RIO_PEF_CTLS) >> 4; 463 - dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n", 464 - port->sys_size ? 65536 : 256); 465 - 466 - if (rio_register_mport(port)) 457 + pw = kzalloc(sizeof(struct fsl_rio_pw), GFP_KERNEL); 458 + if (!(pw)) { 459 + dev_err(&dev->dev, "Can't alloc memory for 'fsl_rio_pw'\n"); 460 + rc = -ENOMEM; 461 + goto err_pw; 462 + } 463 + pw->dev = &dev->dev; 464 + pw->pwirq = irq_of_parse_and_map(np, 0); 465 + dev_info(&dev->dev, "pwirq: %d\n", pw->pwirq); 466 + aw = of_n_addr_cells(np); 467 + dt_range = of_get_property(np, "reg", &rlen); 468 + if (!dt_range) { 469 + pr_err("%s: unable to find 'reg' property\n", 470 + np->full_name); 471 + rc = -ENOMEM; 467 472 goto err; 473 + } 474 + range_start = of_read_number(dt_range, aw); 475 + pw->pw_regs = (struct rio_pw_regs *)(rmu_regs_win + (u32)range_start); 468 476 469 - if (port->host_deviceid >= 0) 470 - out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST | 471 - RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED); 472 - else 473 - out_be32(priv->regs_win + RIO_GCCSR, 0x00000000); 477 + /*set up ports node*/ 478 + for_each_child_of_node(dev->dev.of_node, np) { 479 + port_index = of_get_property(np, "cell-index", NULL); 480 + if (!port_index) { 481 + dev_err(&dev->dev, "Can't get %s property 'cell-index'\n", 482 + np->full_name); 483 + continue; 484 + } 474 485 475 - priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win 476 - + RIO_ATMU_REGS_OFFSET); 477 - priv->maint_atmu_regs = priv->atmu_regs + 1; 486 + dt_range = of_get_property(np, "ranges", &rlen); 487 + if (!dt_range) { 488 + dev_err(&dev->dev, "Can't get %s property 'ranges'\n", 489 + np->full_name); 490 + continue; 491 + } 478 492 479 - /* Set to receive any dist ID for serial RapidIO controller. */ 480 - if (port->phy_type == RIO_PHY_SERIAL) 481 - out_be32((priv->regs_win + RIO_ISR_AACR), RIO_ISR_AACR_AA); 493 + /* Get node address wide */ 494 + cell = of_get_property(np, "#address-cells", NULL); 495 + if (cell) 496 + aw = *cell; 497 + else 498 + aw = of_n_addr_cells(np); 499 + /* Get node size wide */ 500 + cell = of_get_property(np, "#size-cells", NULL); 501 + if (cell) 502 + sw = *cell; 503 + else 504 + sw = of_n_size_cells(np); 505 + /* Get parent address wide wide */ 506 + paw = of_n_addr_cells(np); 507 + range_start = of_read_number(dt_range + aw, paw); 508 + range_size = of_read_number(dt_range + aw + paw, sw); 482 509 483 - /* Configure maintenance transaction window */ 484 - out_be32(&priv->maint_atmu_regs->rowbar, law_start >> 12); 485 - out_be32(&priv->maint_atmu_regs->rowar, 486 - 0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1)); 510 + dev_info(&dev->dev, "%s: LAW start 0x%016llx, size 0x%016llx.\n", 511 + np->full_name, range_start, range_size); 487 512 488 - priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE); 513 + port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL); 514 + if (!port) 515 + continue; 489 516 490 - fsl_rio_setup_rmu(port, dev->dev.of_node); 517 + i = *port_index - 1; 518 + port->index = (unsigned char)i; 491 519 492 - fsl_rio_port_write_init(port); 520 + priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL); 521 + if (!priv) { 522 + dev_err(&dev->dev, "Can't alloc memory for 'priv'\n"); 523 + kfree(port); 524 + continue; 525 + } 526 + 527 + INIT_LIST_HEAD(&port->dbells); 528 + port->iores.start = range_start; 529 + port->iores.end = port->iores.start + range_size - 1; 530 + port->iores.flags = IORESOURCE_MEM; 531 + port->iores.name = "rio_io_win"; 532 + 533 + if (request_resource(&iomem_resource, &port->iores) < 0) { 534 + dev_err(&dev->dev, "RIO: Error requesting master port region" 535 + " 0x%016llx-0x%016llx\n", 536 + (u64)port->iores.start, (u64)port->iores.end); 537 + kfree(priv); 538 + kfree(port); 539 + continue; 540 + } 541 + sprintf(port->name, "RIO mport %d", i); 542 + 543 + priv->dev = &dev->dev; 544 + port->ops = ops; 545 + port->priv = priv; 546 + port->phys_efptr = 0x100; 547 + priv->regs_win = rio_regs_win; 548 + 549 + /* Probe the master port phy type */ 550 + ccsr = in_be32(priv->regs_win + RIO_CCSR + i*0x20); 551 + port->phy_type = (ccsr & 1) ? RIO_PHY_SERIAL : RIO_PHY_PARALLEL; 552 + if (port->phy_type == RIO_PHY_PARALLEL) { 553 + dev_err(&dev->dev, "RIO: Parallel PHY type, unsupported port type!\n"); 554 + release_resource(&port->iores); 555 + kfree(priv); 556 + kfree(port); 557 + continue; 558 + } 559 + dev_info(&dev->dev, "RapidIO PHY type: Serial\n"); 560 + /* Checking the port training status */ 561 + if (in_be32((priv->regs_win + RIO_ESCSR + i*0x20)) & 1) { 562 + dev_err(&dev->dev, "Port %d is not ready. " 563 + "Try to restart connection...\n", i); 564 + /* Disable ports */ 565 + out_be32(priv->regs_win 566 + + RIO_CCSR + i*0x20, 0); 567 + /* Set 1x lane */ 568 + setbits32(priv->regs_win 569 + + RIO_CCSR + i*0x20, 0x02000000); 570 + /* Enable ports */ 571 + setbits32(priv->regs_win 572 + + RIO_CCSR + i*0x20, 0x00600000); 573 + msleep(100); 574 + if (in_be32((priv->regs_win 575 + + RIO_ESCSR + i*0x20)) & 1) { 576 + dev_err(&dev->dev, 577 + "Port %d restart failed.\n", i); 578 + release_resource(&port->iores); 579 + kfree(priv); 580 + kfree(port); 581 + continue; 582 + } 583 + dev_info(&dev->dev, "Port %d restart success!\n", i); 584 + } 585 + fsl_rio_info(&dev->dev, ccsr); 586 + 587 + port->sys_size = (in_be32((priv->regs_win + RIO_PEF_CAR)) 588 + & RIO_PEF_CTLS) >> 4; 589 + dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n", 590 + port->sys_size ? 65536 : 256); 591 + 592 + if (rio_register_mport(port)) { 593 + release_resource(&port->iores); 594 + kfree(priv); 595 + kfree(port); 596 + continue; 597 + } 598 + if (port->host_deviceid >= 0) 599 + out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST | 600 + RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED); 601 + else 602 + out_be32(priv->regs_win + RIO_GCCSR, 603 + RIO_PORT_GEN_MASTER); 604 + 605 + priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win 606 + + ((i == 0) ? RIO_ATMU_REGS_PORT1_OFFSET : 607 + RIO_ATMU_REGS_PORT2_OFFSET)); 608 + 609 + priv->maint_atmu_regs = priv->atmu_regs + 1; 610 + 611 + /* Set to receive any dist ID for serial RapidIO controller. */ 612 + if (port->phy_type == RIO_PHY_SERIAL) 613 + out_be32((priv->regs_win 614 + + RIO_ISR_AACR + i*0x80), RIO_ISR_AACR_AA); 615 + 616 + /* Configure maintenance transaction window */ 617 + out_be32(&priv->maint_atmu_regs->rowbar, 618 + port->iores.start >> 12); 619 + out_be32(&priv->maint_atmu_regs->rowar, 620 + 0x80077000 | (ilog2(RIO_MAINT_WIN_SIZE) - 1)); 621 + 622 + priv->maint_win = ioremap(port->iores.start, 623 + RIO_MAINT_WIN_SIZE); 624 + 625 + rio_law_start = range_start; 626 + 627 + fsl_rio_setup_rmu(port, rmu_np[i]); 628 + 629 + dbell->mport[i] = port; 630 + 631 + active_ports++; 632 + } 633 + 634 + if (!active_ports) { 635 + rc = -ENOLINK; 636 + goto err; 637 + } 638 + 639 + fsl_rio_doorbell_init(dbell); 640 + fsl_rio_port_write_init(pw); 493 641 494 642 return 0; 495 643 err: 496 - iounmap(priv->regs_win); 497 - release_resource(&port->iores); 498 - err_res: 499 - kfree(priv); 500 - err_priv: 501 - kfree(port); 502 - err_port: 644 + kfree(pw); 645 + err_pw: 646 + kfree(dbell); 647 + err_dbell: 648 + iounmap(rmu_regs_win); 649 + err_rmu: 503 650 kfree(ops); 504 651 err_ops: 652 + iounmap(rio_regs_win); 653 + err_rio_regs: 505 654 return rc; 506 655 } 507 656 ··· 654 529 655 530 static const struct of_device_id fsl_of_rio_rpn_ids[] = { 656 531 { 657 - .compatible = "fsl,rapidio-delta", 532 + .compatible = "fsl,srio", 658 533 }, 659 534 {}, 660 535 };
+66 -9
arch/powerpc/sysdev/fsl_rio.h
··· 36 36 #define RIO_MAINT_WIN_SIZE 0x400000 37 37 #define RIO_LTLEDCSR 0x0608 38 38 39 + #define DOORBELL_ROWAR_EN 0x80000000 40 + #define DOORBELL_ROWAR_TFLOWLV 0x08000000 /* highest priority level */ 41 + #define DOORBELL_ROWAR_PCI 0x02000000 /* PCI window */ 42 + #define DOORBELL_ROWAR_NREAD 0x00040000 /* NREAD */ 43 + #define DOORBELL_ROWAR_MAINTRD 0x00070000 /* maintenance read */ 44 + #define DOORBELL_ROWAR_RES 0x00002000 /* wrtpy: reserverd */ 45 + #define DOORBELL_ROWAR_MAINTWD 0x00007000 46 + #define DOORBELL_ROWAR_SIZE 0x0000000b /* window size is 4k */ 47 + 48 + #define RIO_ATMU_REGS_PORT1_OFFSET 0x10c00 49 + #define RIO_ATMU_REGS_PORT2_OFFSET 0x10e00 50 + #define RIO_S_DBELL_REGS_OFFSET 0x13400 51 + #define RIO_S_PW_REGS_OFFSET 0x134e0 52 + #define RIO_ATMU_REGS_DBELL_OFFSET 0x10C40 53 + 54 + #define MAX_MSG_UNIT_NUM 2 55 + #define MAX_PORT_NUM 4 56 + 39 57 struct rio_atmu_regs { 40 58 u32 rowtar; 41 59 u32 rowtear; 42 60 u32 rowbar; 43 - u32 pad2; 61 + u32 pad1; 44 62 u32 rowar; 45 - u32 pad3[3]; 63 + u32 pad2[3]; 64 + }; 65 + 66 + struct rio_dbell_ring { 67 + void *virt; 68 + dma_addr_t phys; 46 69 }; 47 70 48 71 struct rio_port_write_msg { ··· 76 53 u32 discard_count; 77 54 }; 78 55 56 + struct fsl_rio_dbell { 57 + struct rio_mport *mport[MAX_PORT_NUM]; 58 + struct device *dev; 59 + struct rio_dbell_regs __iomem *dbell_regs; 60 + struct rio_dbell_ring dbell_ring; 61 + int bellirq; 62 + }; 63 + 64 + struct fsl_rio_pw { 65 + struct device *dev; 66 + struct rio_pw_regs __iomem *pw_regs; 67 + struct rio_port_write_msg port_write_msg; 68 + int pwirq; 69 + struct work_struct pw_work; 70 + struct kfifo pw_fifo; 71 + spinlock_t pw_fifo_lock; 72 + }; 73 + 79 74 struct rio_priv { 80 75 struct device *dev; 81 76 void __iomem *regs_win; 82 77 struct rio_atmu_regs __iomem *atmu_regs; 83 78 struct rio_atmu_regs __iomem *maint_atmu_regs; 84 79 void __iomem *maint_win; 85 - struct rio_port_write_msg port_write_msg; 86 - int pwirq; 87 - struct work_struct pw_work; 88 - struct kfifo pw_fifo; 89 - spinlock_t pw_fifo_lock; 90 80 void *rmm_handle; /* RapidIO message manager(unit) Handle */ 91 81 }; 92 82 93 83 extern void __iomem *rio_regs_win; 84 + extern void __iomem *rmu_regs_win; 85 + 86 + extern resource_size_t rio_law_start; 87 + 88 + extern struct fsl_rio_dbell *dbell; 89 + extern struct fsl_rio_pw *pw; 94 90 95 91 extern int fsl_rio_setup_rmu(struct rio_mport *mport, 96 92 struct device_node *node); 97 - extern int fsl_rio_port_write_init(struct rio_mport *mport); 93 + extern int fsl_rio_port_write_init(struct fsl_rio_pw *pw); 98 94 extern int fsl_rio_pw_enable(struct rio_mport *mport, int enable); 99 - extern void fsl_rio_port_error_handler(struct rio_mport *port, int offset); 95 + extern void fsl_rio_port_error_handler(int offset); 96 + extern int fsl_rio_doorbell_init(struct fsl_rio_dbell *dbell); 97 + 98 + extern int fsl_rio_doorbell_send(struct rio_mport *mport, 99 + int index, u16 destid, u16 data); 100 + extern int fsl_add_outb_message(struct rio_mport *mport, 101 + struct rio_dev *rdev, 102 + int mbox, void *buffer, size_t len); 103 + extern int fsl_open_outb_mbox(struct rio_mport *mport, 104 + void *dev_id, int mbox, int entries); 105 + extern void fsl_close_outb_mbox(struct rio_mport *mport, int mbox); 106 + extern int fsl_open_inb_mbox(struct rio_mport *mport, 107 + void *dev_id, int mbox, int entries); 108 + extern void fsl_close_inb_mbox(struct rio_mport *mport, int mbox); 109 + extern int fsl_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf); 110 + extern void *fsl_get_inb_message(struct rio_mport *mport, int mbox); 100 111 101 112 #endif
+220 -280
arch/powerpc/sysdev/fsl_rmu.c
··· 36 36 (((struct rio_priv *)(mport->priv))->rmm_handle) 37 37 38 38 /* RapidIO definition irq, which read from OF-tree */ 39 - #define IRQ_RIO_PW(m) (((struct rio_priv *)(m->priv))->pwirq) 40 - #define IRQ_RIO_BELL(m) (((struct fsl_rmu *)(GET_RMM_HANDLE(m)))->bellirq) 39 + #define IRQ_RIO_PW(m) (((struct fsl_rio_pw *)(m))->pwirq) 40 + #define IRQ_RIO_BELL(m) (((struct fsl_rio_dbell *)(m))->bellirq) 41 41 #define IRQ_RIO_TX(m) (((struct fsl_rmu *)(GET_RMM_HANDLE(m)))->txirq) 42 42 #define IRQ_RIO_RX(m) (((struct fsl_rmu *)(GET_RMM_HANDLE(m)))->rxirq) 43 43 ··· 73 73 #define LTLEECSR_ENABLE_ALL 0xFFC000FC 74 74 #define RIO_LTLEECSR 0x060c 75 75 76 - #define RIO_IM0SR 0x13064 77 - #define RIO_IM1SR 0x13164 78 - #define RIO_OM0SR 0x13004 79 - #define RIO_OM1SR 0x13104 80 - 81 - #define RIO_P_MSG_REGS_OFFSET 0x11000 82 - #define RIO_S_MSG_REGS_OFFSET 0x13000 76 + #define RIO_IM0SR 0x64 77 + #define RIO_IM1SR 0x164 78 + #define RIO_OM0SR 0x4 79 + #define RIO_OM1SR 0x104 83 80 84 81 #define RIO_DBELL_WIN_SIZE 0x1000 85 82 ··· 110 113 #define DBELL_INF(x) (*(u16 *)(x + DOORBELL_INFO_OFFSET)) 111 114 112 115 struct rio_msg_regs { 113 - u32 omr; /* 0xD_3000 - Outbound message 0 mode register */ 114 - u32 osr; /* 0xD_3004 - Outbound message 0 status register */ 116 + u32 omr; 117 + u32 osr; 115 118 u32 pad1; 116 - u32 odqdpar; /* 0xD_300C - Outbound message 0 descriptor queue 117 - dequeue pointer address register */ 119 + u32 odqdpar; 118 120 u32 pad2; 119 - u32 osar; /* 0xD_3014 - Outbound message 0 source address 120 - register */ 121 - u32 odpr; /* 0xD_3018 - Outbound message 0 destination port 122 - register */ 123 - u32 odatr; /* 0xD_301C - Outbound message 0 destination attributes 124 - Register*/ 125 - u32 odcr; /* 0xD_3020 - Outbound message 0 double-word count 126 - register */ 121 + u32 osar; 122 + u32 odpr; 123 + u32 odatr; 124 + u32 odcr; 127 125 u32 pad3; 128 - u32 odqepar; /* 0xD_3028 - Outbound message 0 descriptor queue 129 - enqueue pointer address register */ 126 + u32 odqepar; 130 127 u32 pad4[13]; 131 - u32 imr; /* 0xD_3060 - Inbound message 0 mode register */ 132 - u32 isr; /* 0xD_3064 - Inbound message 0 status register */ 128 + u32 imr; 129 + u32 isr; 133 130 u32 pad5; 134 - u32 ifqdpar; /* 0xD_306C - Inbound message 0 frame queue dequeue 135 - pointer address register*/ 131 + u32 ifqdpar; 136 132 u32 pad6; 137 - u32 ifqepar; /* 0xD_3074 - Inbound message 0 frame queue enqueue 138 - pointer address register */ 139 - u32 pad7[226]; 140 - u32 odmr; /* 0xD_3400 - Outbound doorbell mode register */ 141 - u32 odsr; /* 0xD_3404 - Outbound doorbell status register */ 142 - u32 res0[4]; 143 - u32 oddpr; /* 0xD_3418 - Outbound doorbell destination port 144 - register */ 145 - u32 oddatr; /* 0xD_341c - Outbound doorbell destination attributes 146 - register */ 147 - u32 res1[3]; 148 - u32 odretcr; /* 0xD_342C - Outbound doorbell retry error threshold 149 - configuration register */ 150 - u32 res2[12]; 151 - u32 dmr; /* 0xD_3460 - Inbound doorbell mode register */ 152 - u32 dsr; /* 0xD_3464 - Inbound doorbell status register */ 153 - u32 pad8; 154 - u32 dqdpar; /* 0xD_346C - Inbound doorbell queue dequeue Pointer 155 - address register */ 156 - u32 pad9; 157 - u32 dqepar; /* 0xD_3474 - Inbound doorbell Queue enqueue pointer 158 - address register */ 159 - u32 pad10[26]; 160 - u32 pwmr; /* 0xD_34E0 - Inbound port-write mode register */ 161 - u32 pwsr; /* 0xD_34E4 - Inbound port-write status register */ 162 - u32 epwqbar; /* 0xD_34E8 - Extended Port-Write Queue Base Address 163 - register */ 164 - u32 pwqbar; /* 0xD_34EC - Inbound port-write queue base address 165 - register */ 133 + u32 ifqepar; 166 134 }; 167 135 136 + struct rio_dbell_regs { 137 + u32 odmr; 138 + u32 odsr; 139 + u32 pad1[4]; 140 + u32 oddpr; 141 + u32 oddatr; 142 + u32 pad2[3]; 143 + u32 odretcr; 144 + u32 pad3[12]; 145 + u32 dmr; 146 + u32 dsr; 147 + u32 pad4; 148 + u32 dqdpar; 149 + u32 pad5; 150 + u32 dqepar; 151 + }; 152 + 153 + struct rio_pw_regs { 154 + u32 pwmr; 155 + u32 pwsr; 156 + u32 epwqbar; 157 + u32 pwqbar; 158 + }; 159 + 160 + 168 161 struct rio_tx_desc { 169 - u32 res1; 162 + u32 pad1; 170 163 u32 saddr; 171 164 u32 dport; 172 165 u32 dattr; 173 - u32 res2; 174 - u32 res3; 166 + u32 pad2; 167 + u32 pad3; 175 168 u32 dwcnt; 176 - u32 res4; 177 - }; 178 - 179 - struct rio_dbell_ring { 180 - void *virt; 181 - dma_addr_t phys; 169 + u32 pad4; 182 170 }; 183 171 184 172 struct rio_msg_tx_ring { ··· 186 204 }; 187 205 188 206 struct fsl_rmu { 189 - struct rio_atmu_regs __iomem *dbell_atmu_regs; 190 - void __iomem *dbell_win; 191 207 struct rio_msg_regs __iomem *msg_regs; 192 - struct rio_dbell_ring dbell_ring; 193 208 struct rio_msg_tx_ring msg_tx_ring; 194 209 struct rio_msg_rx_ring msg_rx_ring; 195 - int bellirq; 196 210 int txirq; 197 211 int rxirq; 198 212 }; ··· 225 247 if (osr & RIO_MSG_OSR_EOMI) { 226 248 u32 dqp = in_be32(&rmu->msg_regs->odqdpar); 227 249 int slot = (dqp - rmu->msg_tx_ring.phys) >> 5; 228 - port->outb_msg[0].mcback(port, rmu->msg_tx_ring.dev_id, -1, 229 - slot); 230 - 250 + if (port->outb_msg[0].mcback != NULL) { 251 + port->outb_msg[0].mcback(port, rmu->msg_tx_ring.dev_id, 252 + -1, 253 + slot); 254 + } 231 255 /* Ack the end-of-message interrupt */ 232 256 out_be32(&rmu->msg_regs->osr, RIO_MSG_OSR_EOMI); 233 257 } ··· 264 284 /* XXX Need to check/dispatch until queue empty */ 265 285 if (isr & RIO_MSG_ISR_DIQI) { 266 286 /* 267 - * We implement *only* mailbox 0, but can receive messages 268 - * for any mailbox/letter to that mailbox destination. So, 269 - * make the callback with an unknown/invalid mailbox number 270 - * argument. 271 - */ 272 - port->inb_msg[0].mcback(port, rmu->msg_rx_ring.dev_id, -1, -1); 287 + * Can receive messages for any mailbox/letter to that 288 + * mailbox destination. So, make the callback with an 289 + * unknown/invalid mailbox number argument. 290 + */ 291 + if (port->inb_msg[0].mcback != NULL) 292 + port->inb_msg[0].mcback(port, rmu->msg_rx_ring.dev_id, 293 + -1, 294 + -1); 273 295 274 296 /* Ack the queueing interrupt */ 275 297 out_be32(&rmu->msg_regs->isr, RIO_MSG_ISR_DIQI); ··· 293 311 fsl_rio_dbell_handler(int irq, void *dev_instance) 294 312 { 295 313 int dsr; 296 - struct rio_mport *port = (struct rio_mport *)dev_instance; 297 - struct fsl_rmu *rmu = GET_RMM_HANDLE(port); 314 + struct fsl_rio_dbell *fsl_dbell = (struct fsl_rio_dbell *)dev_instance; 315 + int i; 298 316 299 - dsr = in_be32(&rmu->msg_regs->dsr); 317 + dsr = in_be32(&fsl_dbell->dbell_regs->dsr); 300 318 301 319 if (dsr & DOORBELL_DSR_TE) { 302 320 pr_info("RIO: doorbell reception error\n"); 303 - out_be32(&rmu->msg_regs->dsr, DOORBELL_DSR_TE); 321 + out_be32(&fsl_dbell->dbell_regs->dsr, DOORBELL_DSR_TE); 304 322 goto out; 305 323 } 306 324 307 325 if (dsr & DOORBELL_DSR_QFI) { 308 326 pr_info("RIO: doorbell queue full\n"); 309 - out_be32(&rmu->msg_regs->dsr, DOORBELL_DSR_QFI); 327 + out_be32(&fsl_dbell->dbell_regs->dsr, DOORBELL_DSR_QFI); 310 328 } 311 329 312 330 /* XXX Need to check/dispatch until queue empty */ 313 331 if (dsr & DOORBELL_DSR_DIQI) { 314 332 u32 dmsg = 315 - (u32) rmu->dbell_ring.virt + 316 - (in_be32(&rmu->msg_regs->dqdpar) & 0xfff); 333 + (u32) fsl_dbell->dbell_ring.virt + 334 + (in_be32(&fsl_dbell->dbell_regs->dqdpar) & 0xfff); 317 335 struct rio_dbell *dbell; 318 336 int found = 0; 319 337 ··· 322 340 " sid %2.2x tid %2.2x info %4.4x\n", 323 341 DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg)); 324 342 325 - list_for_each_entry(dbell, &port->dbells, node) { 326 - if ((dbell->res->start <= DBELL_INF(dmsg)) && 327 - (dbell->res->end >= DBELL_INF(dmsg))) { 328 - found = 1; 329 - break; 343 + for (i = 0; i < MAX_PORT_NUM; i++) { 344 + if (fsl_dbell->mport[i]) { 345 + list_for_each_entry(dbell, 346 + &fsl_dbell->mport[i]->dbells, node) { 347 + if ((dbell->res->start 348 + <= DBELL_INF(dmsg)) 349 + && (dbell->res->end 350 + >= DBELL_INF(dmsg))) { 351 + found = 1; 352 + break; 353 + } 354 + } 355 + if (found && dbell->dinb) { 356 + dbell->dinb(fsl_dbell->mport[i], 357 + dbell->dev_id, DBELL_SID(dmsg), 358 + DBELL_TID(dmsg), 359 + DBELL_INF(dmsg)); 360 + break; 361 + } 330 362 } 331 363 } 332 - if (found) { 333 - dbell->dinb(port, dbell->dev_id, 334 - DBELL_SID(dmsg), 335 - DBELL_TID(dmsg), DBELL_INF(dmsg)); 336 - } else { 364 + 365 + if (!found) { 337 366 pr_debug 338 367 ("RIO: spurious doorbell," 339 368 " sid %2.2x tid %2.2x info %4.4x\n", 340 369 DBELL_SID(dmsg), DBELL_TID(dmsg), 341 370 DBELL_INF(dmsg)); 342 371 } 343 - setbits32(&rmu->msg_regs->dmr, DOORBELL_DMR_DI); 344 - out_be32(&rmu->msg_regs->dsr, DOORBELL_DSR_DIQI); 372 + setbits32(&fsl_dbell->dbell_regs->dmr, DOORBELL_DMR_DI); 373 + out_be32(&fsl_dbell->dbell_regs->dsr, DOORBELL_DSR_DIQI); 345 374 } 346 375 347 376 out: 348 377 return IRQ_HANDLED; 349 378 } 350 379 351 - void msg_unit_error_handler(struct rio_mport *port) 380 + void msg_unit_error_handler(void) 352 381 { 353 - struct fsl_rmu *rmu = GET_RMM_HANDLE(port); 354 382 355 383 /*XXX: Error recovery is not implemented, we just clear errors */ 356 384 out_be32((u32 *)(rio_regs_win + RIO_LTLEDCSR), 0); 357 385 358 - out_be32((u32 *)(rio_regs_win + RIO_IM0SR), IMSR_CLEAR); 359 - out_be32((u32 *)(rio_regs_win + RIO_IM1SR), IMSR_CLEAR); 360 - out_be32((u32 *)(rio_regs_win + RIO_OM0SR), OMSR_CLEAR); 361 - out_be32((u32 *)(rio_regs_win + RIO_OM1SR), OMSR_CLEAR); 386 + out_be32((u32 *)(rmu_regs_win + RIO_IM0SR), IMSR_CLEAR); 387 + out_be32((u32 *)(rmu_regs_win + RIO_IM1SR), IMSR_CLEAR); 388 + out_be32((u32 *)(rmu_regs_win + RIO_OM0SR), OMSR_CLEAR); 389 + out_be32((u32 *)(rmu_regs_win + RIO_OM1SR), OMSR_CLEAR); 362 390 363 - out_be32(&rmu->msg_regs->odsr, ODSR_CLEAR); 364 - out_be32(&rmu->msg_regs->dsr, IDSR_CLEAR); 391 + out_be32(&dbell->dbell_regs->odsr, ODSR_CLEAR); 392 + out_be32(&dbell->dbell_regs->dsr, IDSR_CLEAR); 365 393 366 - out_be32(&rmu->msg_regs->pwsr, IPWSR_CLEAR); 394 + out_be32(&pw->pw_regs->pwsr, IPWSR_CLEAR); 367 395 } 368 396 369 397 /** ··· 388 396 fsl_rio_port_write_handler(int irq, void *dev_instance) 389 397 { 390 398 u32 ipwmr, ipwsr; 391 - struct rio_mport *port = (struct rio_mport *)dev_instance; 392 - struct rio_priv *priv = port->priv; 393 - struct fsl_rmu *rmu; 399 + struct fsl_rio_pw *pw = (struct fsl_rio_pw *)dev_instance; 394 400 u32 epwisr, tmp; 395 401 396 - rmu = GET_RMM_HANDLE(port); 397 - epwisr = in_be32(priv->regs_win + RIO_EPWISR); 402 + epwisr = in_be32(rio_regs_win + RIO_EPWISR); 398 403 if (!(epwisr & RIO_EPWISR_PW)) 399 404 goto pw_done; 400 405 401 - ipwmr = in_be32(&rmu->msg_regs->pwmr); 402 - ipwsr = in_be32(&rmu->msg_regs->pwsr); 406 + ipwmr = in_be32(&pw->pw_regs->pwmr); 407 + ipwsr = in_be32(&pw->pw_regs->pwsr); 403 408 404 409 #ifdef DEBUG_PW 405 410 pr_debug("PW Int->IPWMR: 0x%08x IPWSR: 0x%08x (", ipwmr, ipwsr); ··· 417 428 /* Save PW message (if there is room in FIFO), 418 429 * otherwise discard it. 419 430 */ 420 - if (kfifo_avail(&priv->pw_fifo) >= RIO_PW_MSG_SIZE) { 421 - priv->port_write_msg.msg_count++; 422 - kfifo_in(&priv->pw_fifo, priv->port_write_msg.virt, 431 + if (kfifo_avail(&pw->pw_fifo) >= RIO_PW_MSG_SIZE) { 432 + pw->port_write_msg.msg_count++; 433 + kfifo_in(&pw->pw_fifo, pw->port_write_msg.virt, 423 434 RIO_PW_MSG_SIZE); 424 435 } else { 425 - priv->port_write_msg.discard_count++; 436 + pw->port_write_msg.discard_count++; 426 437 pr_debug("RIO: ISR Discarded Port-Write Msg(s) (%d)\n", 427 - priv->port_write_msg.discard_count); 438 + pw->port_write_msg.discard_count); 428 439 } 429 440 /* Clear interrupt and issue Clear Queue command. This allows 430 441 * another port-write to be received. 431 442 */ 432 - out_be32(&rmu->msg_regs->pwsr, RIO_IPWSR_QFI); 433 - out_be32(&rmu->msg_regs->pwmr, ipwmr | RIO_IPWMR_CQ); 443 + out_be32(&pw->pw_regs->pwsr, RIO_IPWSR_QFI); 444 + out_be32(&pw->pw_regs->pwmr, ipwmr | RIO_IPWMR_CQ); 434 445 435 - schedule_work(&priv->pw_work); 446 + schedule_work(&pw->pw_work); 436 447 } 437 448 438 449 if ((ipwmr & RIO_IPWMR_EIE) && (ipwsr & RIO_IPWSR_TE)) { 439 - priv->port_write_msg.err_count++; 450 + pw->port_write_msg.err_count++; 440 451 pr_debug("RIO: Port-Write Transaction Err (%d)\n", 441 - priv->port_write_msg.err_count); 452 + pw->port_write_msg.err_count); 442 453 /* Clear Transaction Error: port-write controller should be 443 454 * disabled when clearing this error 444 455 */ 445 - out_be32(&rmu->msg_regs->pwmr, ipwmr & ~RIO_IPWMR_PWE); 446 - out_be32(&rmu->msg_regs->pwsr, RIO_IPWSR_TE); 447 - out_be32(&rmu->msg_regs->pwmr, ipwmr); 456 + out_be32(&pw->pw_regs->pwmr, ipwmr & ~RIO_IPWMR_PWE); 457 + out_be32(&pw->pw_regs->pwsr, RIO_IPWSR_TE); 458 + out_be32(&pw->pw_regs->pwmr, ipwmr); 448 459 } 449 460 450 461 if (ipwsr & RIO_IPWSR_PWD) { 451 - priv->port_write_msg.discard_count++; 462 + pw->port_write_msg.discard_count++; 452 463 pr_debug("RIO: Port Discarded Port-Write Msg(s) (%d)\n", 453 - priv->port_write_msg.discard_count); 454 - out_be32(&rmu->msg_regs->pwsr, RIO_IPWSR_PWD); 464 + pw->port_write_msg.discard_count); 465 + out_be32(&pw->pw_regs->pwsr, RIO_IPWSR_PWD); 455 466 } 456 467 457 468 pw_done: 458 469 if (epwisr & RIO_EPWISR_PINT1) { 459 - tmp = in_be32(priv->regs_win + RIO_LTLEDCSR); 470 + tmp = in_be32(rio_regs_win + RIO_LTLEDCSR); 460 471 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp); 461 - fsl_rio_port_error_handler(port, 0); 472 + fsl_rio_port_error_handler(0); 462 473 } 463 474 464 475 if (epwisr & RIO_EPWISR_PINT2) { 465 - tmp = in_be32(priv->regs_win + RIO_LTLEDCSR); 476 + tmp = in_be32(rio_regs_win + RIO_LTLEDCSR); 466 477 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp); 467 - fsl_rio_port_error_handler(port, 1); 478 + fsl_rio_port_error_handler(1); 468 479 } 469 480 470 481 if (epwisr & RIO_EPWISR_MU) { 471 - tmp = in_be32(priv->regs_win + RIO_LTLEDCSR); 482 + tmp = in_be32(rio_regs_win + RIO_LTLEDCSR); 472 483 pr_debug("RIO_LTLEDCSR = 0x%x\n", tmp); 473 - msg_unit_error_handler(port); 484 + msg_unit_error_handler(); 474 485 } 475 486 476 487 return IRQ_HANDLED; ··· 478 489 479 490 static void fsl_pw_dpc(struct work_struct *work) 480 491 { 481 - struct rio_priv *priv = container_of(work, struct rio_priv, pw_work); 482 - unsigned long flags; 492 + struct fsl_rio_pw *pw = container_of(work, struct fsl_rio_pw, pw_work); 483 493 u32 msg_buffer[RIO_PW_MSG_SIZE/sizeof(u32)]; 484 494 485 495 /* 486 496 * Process port-write messages 487 497 */ 488 - spin_lock_irqsave(&priv->pw_fifo_lock, flags); 489 - while (kfifo_out(&priv->pw_fifo, (unsigned char *)msg_buffer, 490 - RIO_PW_MSG_SIZE)) { 498 + while (kfifo_out_spinlocked(&pw->pw_fifo, (unsigned char *)msg_buffer, 499 + RIO_PW_MSG_SIZE, &pw->pw_fifo_lock)) { 491 500 /* Process one message */ 492 - spin_unlock_irqrestore(&priv->pw_fifo_lock, flags); 493 501 #ifdef DEBUG_PW 494 502 { 495 503 u32 i; ··· 503 517 #endif 504 518 /* Pass the port-write message to RIO core for processing */ 505 519 rio_inb_pwrite_handler((union rio_pw_msg *)msg_buffer); 506 - spin_lock_irqsave(&priv->pw_fifo_lock, flags); 507 520 } 508 - spin_unlock_irqrestore(&priv->pw_fifo_lock, flags); 509 521 } 510 522 511 523 /** 512 524 * fsl_rio_pw_enable - enable/disable port-write interface init 513 525 * @mport: Master port implementing the port write unit 514 - * @enable: 1=enable; 0=disable port-write message handling 526 + * @enable: 1=enable; 0=disable port-write message handling 515 527 */ 516 528 int fsl_rio_pw_enable(struct rio_mport *mport, int enable) 517 529 { 518 - struct fsl_rmu *rmu; 519 530 u32 rval; 520 531 521 - rmu = GET_RMM_HANDLE(mport); 522 - 523 - rval = in_be32(&rmu->msg_regs->pwmr); 532 + rval = in_be32(&pw->pw_regs->pwmr); 524 533 525 534 if (enable) 526 535 rval |= RIO_IPWMR_PWE; 527 536 else 528 537 rval &= ~RIO_IPWMR_PWE; 529 538 530 - out_be32(&rmu->msg_regs->pwmr, rval); 539 + out_be32(&pw->pw_regs->pwmr, rval); 531 540 532 541 return 0; 533 542 } ··· 536 555 * or %-ENOMEM on failure. 537 556 */ 538 557 539 - int fsl_rio_port_write_init(struct rio_mport *mport) 558 + int fsl_rio_port_write_init(struct fsl_rio_pw *pw) 540 559 { 541 - struct rio_priv *priv = mport->priv; 542 - struct fsl_rmu *rmu; 543 560 int rc = 0; 544 561 545 - rmu = GET_RMM_HANDLE(mport); 546 - 547 562 /* Following configurations require a disabled port write controller */ 548 - out_be32(&rmu->msg_regs->pwmr, 549 - in_be32(&rmu->msg_regs->pwmr) & ~RIO_IPWMR_PWE); 563 + out_be32(&pw->pw_regs->pwmr, 564 + in_be32(&pw->pw_regs->pwmr) & ~RIO_IPWMR_PWE); 550 565 551 566 /* Initialize port write */ 552 - priv->port_write_msg.virt = dma_alloc_coherent(priv->dev, 567 + pw->port_write_msg.virt = dma_alloc_coherent(pw->dev, 553 568 RIO_PW_MSG_SIZE, 554 - &priv->port_write_msg.phys, GFP_KERNEL); 555 - if (!priv->port_write_msg.virt) { 569 + &pw->port_write_msg.phys, GFP_KERNEL); 570 + if (!pw->port_write_msg.virt) { 556 571 pr_err("RIO: unable allocate port write queue\n"); 557 572 return -ENOMEM; 558 573 } 559 574 560 - priv->port_write_msg.err_count = 0; 561 - priv->port_write_msg.discard_count = 0; 575 + pw->port_write_msg.err_count = 0; 576 + pw->port_write_msg.discard_count = 0; 562 577 563 578 /* Point dequeue/enqueue pointers at first entry */ 564 - out_be32(&rmu->msg_regs->epwqbar, 0); 565 - out_be32(&rmu->msg_regs->pwqbar, (u32) priv->port_write_msg.phys); 579 + out_be32(&pw->pw_regs->epwqbar, 0); 580 + out_be32(&pw->pw_regs->pwqbar, (u32) pw->port_write_msg.phys); 566 581 567 582 pr_debug("EIPWQBAR: 0x%08x IPWQBAR: 0x%08x\n", 568 - in_be32(&rmu->msg_regs->epwqbar), 569 - in_be32(&rmu->msg_regs->pwqbar)); 583 + in_be32(&pw->pw_regs->epwqbar), 584 + in_be32(&pw->pw_regs->pwqbar)); 570 585 571 586 /* Clear interrupt status IPWSR */ 572 - out_be32(&rmu->msg_regs->pwsr, 587 + out_be32(&pw->pw_regs->pwsr, 573 588 (RIO_IPWSR_TE | RIO_IPWSR_QFI | RIO_IPWSR_PWD)); 574 589 575 590 /* Configure port write contoller for snooping enable all reporting, 576 591 clear queue full */ 577 - out_be32(&rmu->msg_regs->pwmr, 592 + out_be32(&pw->pw_regs->pwmr, 578 593 RIO_IPWMR_SEN | RIO_IPWMR_QFIE | RIO_IPWMR_EIE | RIO_IPWMR_CQ); 579 594 580 595 581 596 /* Hook up port-write handler */ 582 - rc = request_irq(IRQ_RIO_PW(mport), fsl_rio_port_write_handler, 583 - IRQF_SHARED, "port-write", (void *)mport); 597 + rc = request_irq(IRQ_RIO_PW(pw), fsl_rio_port_write_handler, 598 + IRQF_SHARED, "port-write", (void *)pw); 584 599 if (rc < 0) { 585 600 pr_err("MPC85xx RIO: unable to request inbound doorbell irq"); 586 601 goto err_out; ··· 584 607 /* Enable Error Interrupt */ 585 608 out_be32((u32 *)(rio_regs_win + RIO_LTLEECSR), LTLEECSR_ENABLE_ALL); 586 609 587 - INIT_WORK(&priv->pw_work, fsl_pw_dpc); 588 - spin_lock_init(&priv->pw_fifo_lock); 589 - if (kfifo_alloc(&priv->pw_fifo, RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) { 610 + INIT_WORK(&pw->pw_work, fsl_pw_dpc); 611 + spin_lock_init(&pw->pw_fifo_lock); 612 + if (kfifo_alloc(&pw->pw_fifo, RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) { 590 613 pr_err("FIFO allocation failed\n"); 591 614 rc = -ENOMEM; 592 615 goto err_out_irq; 593 616 } 594 617 595 618 pr_debug("IPWMR: 0x%08x IPWSR: 0x%08x\n", 596 - in_be32(&rmu->msg_regs->pwmr), 597 - in_be32(&rmu->msg_regs->pwsr)); 619 + in_be32(&pw->pw_regs->pwmr), 620 + in_be32(&pw->pw_regs->pwsr)); 598 621 599 622 return rc; 600 623 601 624 err_out_irq: 602 - free_irq(IRQ_RIO_PW(mport), (void *)mport); 625 + free_irq(IRQ_RIO_PW(pw), (void *)pw); 603 626 err_out: 604 - dma_free_coherent(priv->dev, RIO_PW_MSG_SIZE, 605 - priv->port_write_msg.virt, 606 - priv->port_write_msg.phys); 627 + dma_free_coherent(pw->dev, RIO_PW_MSG_SIZE, 628 + pw->port_write_msg.virt, 629 + pw->port_write_msg.phys); 607 630 return rc; 608 631 } 609 632 ··· 617 640 * Sends a MPC85xx doorbell message. Returns %0 on success or 618 641 * %-EINVAL on failure. 619 642 */ 620 - static int fsl_rio_doorbell_send(struct rio_mport *mport, 643 + int fsl_rio_doorbell_send(struct rio_mport *mport, 621 644 int index, u16 destid, u16 data) 622 645 { 623 - struct fsl_rmu *rmu = GET_RMM_HANDLE(mport); 624 - 625 646 pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n", 626 647 index, destid, data); 627 - switch (mport->phy_type) { 628 - case RIO_PHY_PARALLEL: 629 - out_be32(&rmu->dbell_atmu_regs->rowtar, destid << 22); 630 - out_be16(rmu->dbell_win, data); 631 - break; 632 - case RIO_PHY_SERIAL: 633 - /* In the serial version silicons, such as MPC8548, MPC8641, 634 - * below operations is must be. 635 - */ 636 - out_be32(&rmu->msg_regs->odmr, 0x00000000); 637 - out_be32(&rmu->msg_regs->odretcr, 0x00000004); 638 - out_be32(&rmu->msg_regs->oddpr, destid << 16); 639 - out_be32(&rmu->msg_regs->oddatr, data); 640 - out_be32(&rmu->msg_regs->odmr, 0x00000001); 641 - break; 642 - } 648 + 649 + /* In the serial version silicons, such as MPC8548, MPC8641, 650 + * below operations is must be. 651 + */ 652 + out_be32(&dbell->dbell_regs->odmr, 0x00000000); 653 + out_be32(&dbell->dbell_regs->odretcr, 0x00000004); 654 + out_be32(&dbell->dbell_regs->oddpr, destid << 16); 655 + out_be32(&dbell->dbell_regs->oddatr, (index << 20) | data); 656 + out_be32(&dbell->dbell_regs->odmr, 0x00000001); 643 657 644 658 return 0; 645 659 } ··· 646 678 * Adds the @buffer message to the MPC85xx outbound message queue. Returns 647 679 * %0 on success or %-EINVAL on failure. 648 680 */ 649 - static int 681 + int 650 682 fsl_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox, 651 683 void *buffer, size_t len) 652 684 { ··· 658 690 659 691 pr_debug("RIO: fsl_add_outb_message(): destid %4.4x mbox %d buffer " \ 660 692 "%8.8x len %8.8x\n", rdev->destid, mbox, (int)buffer, len); 661 - 662 693 if ((len < 8) || (len > RIO_MAX_MSG_SIZE)) { 663 694 ret = -EINVAL; 664 695 goto out; ··· 670 703 memset(rmu->msg_tx_ring.virt_buffer[rmu->msg_tx_ring.tx_slot] 671 704 + len, 0, RIO_MAX_MSG_SIZE - len); 672 705 673 - switch (mport->phy_type) { 674 - case RIO_PHY_PARALLEL: 675 - /* Set mbox field for message */ 676 - desc->dport = mbox & 0x3; 706 + /* Set mbox field for message, and set destid */ 707 + desc->dport = (rdev->destid << 16) | (mbox & 0x3); 677 708 678 - /* Enable EOMI interrupt, set priority, and set destid */ 679 - desc->dattr = 0x28000000 | (rdev->destid << 2); 680 - break; 681 - case RIO_PHY_SERIAL: 682 - /* Set mbox field for message, and set destid */ 683 - desc->dport = (rdev->destid << 16) | (mbox & 0x3); 684 - 685 - /* Enable EOMI interrupt and priority */ 686 - desc->dattr = 0x28000000; 687 - break; 688 - } 709 + /* Enable EOMI interrupt and priority */ 710 + desc->dattr = 0x28000000 | ((mport->index) << 20); 689 711 690 712 /* Set transfer size aligned to next power of 2 (in double words) */ 691 713 desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len); ··· 706 750 * and enables the outbound message unit. Returns %0 on success and 707 751 * %-EINVAL or %-ENOMEM on failure. 708 752 */ 709 - static int 753 + int 710 754 fsl_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries) 711 755 { 712 756 int i, j, rc = 0; ··· 811 855 * Disables the outbound message unit, free all buffers, and 812 856 * frees the outbound message interrupt. 813 857 */ 814 - static void fsl_close_outb_mbox(struct rio_mport *mport, int mbox) 858 + void fsl_close_outb_mbox(struct rio_mport *mport, int mbox) 815 859 { 816 860 struct rio_priv *priv = mport->priv; 817 861 struct fsl_rmu *rmu = GET_RMM_HANDLE(mport); ··· 839 883 * and enables the inbound message unit. Returns %0 on success 840 884 * and %-EINVAL or %-ENOMEM on failure. 841 885 */ 842 - static int 886 + int 843 887 fsl_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries) 844 888 { 845 889 int i, rc = 0; ··· 912 956 * Disables the inbound message unit, free all buffers, and 913 957 * frees the inbound message interrupt. 914 958 */ 915 - static void fsl_close_inb_mbox(struct rio_mport *mport, int mbox) 959 + void fsl_close_inb_mbox(struct rio_mport *mport, int mbox) 916 960 { 917 961 struct rio_priv *priv = mport->priv; 918 962 struct fsl_rmu *rmu = GET_RMM_HANDLE(mport); ··· 922 966 923 967 /* Free ring */ 924 968 dma_free_coherent(priv->dev, rmu->msg_rx_ring.size * RIO_MAX_MSG_SIZE, 925 - rmu->msg_rx_ring.virt, rmu->msg_rx_ring.phys); 969 + rmu->msg_rx_ring.virt, rmu->msg_rx_ring.phys); 926 970 927 971 /* Free interrupt */ 928 972 free_irq(IRQ_RIO_RX(mport), (void *)mport); ··· 937 981 * Adds the @buf buffer to the MPC85xx inbound message queue. Returns 938 982 * %0 on success or %-EINVAL on failure. 939 983 */ 940 - static int fsl_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf) 984 + int fsl_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf) 941 985 { 942 986 int rc = 0; 943 987 struct fsl_rmu *rmu = GET_RMM_HANDLE(mport); ··· 969 1013 * Gets the next available inbound message from the inbound message queue. 970 1014 * A pointer to the message is returned on success or NULL on failure. 971 1015 */ 972 - static void *fsl_get_inb_message(struct rio_mport *mport, int mbox) 1016 + void *fsl_get_inb_message(struct rio_mport *mport, int mbox) 973 1017 { 974 1018 struct fsl_rmu *rmu = GET_RMM_HANDLE(mport); 975 1019 u32 phys_buf, virt_buf; ··· 1014 1058 * ring. Called from fsl_rio_setup(). Returns %0 on success 1015 1059 * or %-ENOMEM on failure. 1016 1060 */ 1017 - static int fsl_rio_doorbell_init(struct rio_mport *mport) 1061 + int fsl_rio_doorbell_init(struct fsl_rio_dbell *dbell) 1018 1062 { 1019 - struct rio_priv *priv = mport->priv; 1020 - struct fsl_rmu *rmu = GET_RMM_HANDLE(mport); 1021 1063 int rc = 0; 1022 1064 1023 - /* Map outbound doorbell window immediately after maintenance window */ 1024 - rmu->dbell_win = ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE, 1025 - RIO_DBELL_WIN_SIZE); 1026 - if (!rmu->dbell_win) { 1027 - printk(KERN_ERR 1028 - "RIO: unable to map outbound doorbell window\n"); 1029 - rc = -ENOMEM; 1030 - goto out; 1031 - } 1032 - 1033 1065 /* Initialize inbound doorbells */ 1034 - rmu->dbell_ring.virt = dma_alloc_coherent(priv->dev, 512 * 1035 - DOORBELL_MESSAGE_SIZE, &rmu->dbell_ring.phys, GFP_KERNEL); 1036 - if (!rmu->dbell_ring.virt) { 1066 + dbell->dbell_ring.virt = dma_alloc_coherent(dbell->dev, 512 * 1067 + DOORBELL_MESSAGE_SIZE, &dbell->dbell_ring.phys, GFP_KERNEL); 1068 + if (!dbell->dbell_ring.virt) { 1037 1069 printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n"); 1038 1070 rc = -ENOMEM; 1039 - iounmap(rmu->dbell_win); 1040 1071 goto out; 1041 1072 } 1042 1073 1043 1074 /* Point dequeue/enqueue pointers at first entry in ring */ 1044 - out_be32(&rmu->msg_regs->dqdpar, (u32) rmu->dbell_ring.phys); 1045 - out_be32(&rmu->msg_regs->dqepar, (u32) rmu->dbell_ring.phys); 1075 + out_be32(&dbell->dbell_regs->dqdpar, (u32) dbell->dbell_ring.phys); 1076 + out_be32(&dbell->dbell_regs->dqepar, (u32) dbell->dbell_ring.phys); 1046 1077 1047 1078 /* Clear interrupt status */ 1048 - out_be32(&rmu->msg_regs->dsr, 0x00000091); 1079 + out_be32(&dbell->dbell_regs->dsr, 0x00000091); 1049 1080 1050 1081 /* Hook up doorbell handler */ 1051 - rc = request_irq(IRQ_RIO_BELL(mport), fsl_rio_dbell_handler, 0, 1052 - "dbell_rx", (void *)mport); 1082 + rc = request_irq(IRQ_RIO_BELL(dbell), fsl_rio_dbell_handler, 0, 1083 + "dbell_rx", (void *)dbell); 1053 1084 if (rc < 0) { 1054 - iounmap(rmu->dbell_win); 1055 - dma_free_coherent(priv->dev, 512 * DOORBELL_MESSAGE_SIZE, 1056 - rmu->dbell_ring.virt, rmu->dbell_ring.phys); 1085 + dma_free_coherent(dbell->dev, 512 * DOORBELL_MESSAGE_SIZE, 1086 + dbell->dbell_ring.virt, dbell->dbell_ring.phys); 1057 1087 printk(KERN_ERR 1058 1088 "MPC85xx RIO: unable to request inbound doorbell irq"); 1059 1089 goto out; 1060 1090 } 1061 1091 1062 1092 /* Configure doorbells for snooping, 512 entries, and enable */ 1063 - out_be32(&rmu->msg_regs->dmr, 0x00108161); 1093 + out_be32(&dbell->dbell_regs->dmr, 0x00108161); 1064 1094 1065 1095 out: 1066 1096 return rc; ··· 1056 1114 { 1057 1115 struct rio_priv *priv; 1058 1116 struct fsl_rmu *rmu; 1059 - struct rio_ops *ops; 1117 + u64 msg_start; 1118 + const u32 *msg_addr; 1119 + int mlen; 1120 + int aw; 1060 1121 1061 - if (!mport || !mport->priv || !node) 1062 - return -1; 1122 + if (!mport || !mport->priv) 1123 + return -EINVAL; 1124 + 1125 + priv = mport->priv; 1126 + 1127 + if (!node) { 1128 + dev_warn(priv->dev, "Can't get %s property 'fsl,rmu'\n", 1129 + priv->dev->of_node->full_name); 1130 + return -EINVAL; 1131 + } 1063 1132 1064 1133 rmu = kzalloc(sizeof(struct fsl_rmu), GFP_KERNEL); 1065 1134 if (!rmu) 1066 1135 return -ENOMEM; 1067 1136 1068 - priv = mport->priv; 1137 + aw = of_n_addr_cells(node); 1138 + msg_addr = of_get_property(node, "reg", &mlen); 1139 + if (!msg_addr) { 1140 + pr_err("%s: unable to find 'reg' property of message-unit\n", 1141 + node->full_name); 1142 + return -ENOMEM; 1143 + } 1144 + msg_start = of_read_number(msg_addr, aw); 1145 + 1146 + rmu->msg_regs = (struct rio_msg_regs *) 1147 + (rmu_regs_win + (u32)msg_start); 1148 + 1149 + rmu->txirq = irq_of_parse_and_map(node, 0); 1150 + rmu->rxirq = irq_of_parse_and_map(node, 1); 1151 + printk(KERN_INFO "%s: txirq: %d, rxirq %d\n", 1152 + node->full_name, rmu->txirq, rmu->rxirq); 1153 + 1069 1154 priv->rmm_handle = rmu; 1070 - rmu->dbell_atmu_regs = priv->atmu_regs + 2; 1071 - rmu->msg_regs = (struct rio_msg_regs *)(priv->regs_win + 1072 - ((mport->phy_type == RIO_PHY_SERIAL) ? 1073 - RIO_S_MSG_REGS_OFFSET : RIO_P_MSG_REGS_OFFSET)); 1074 - 1075 - rmu->bellirq = irq_of_parse_and_map(node, 2); 1076 - rmu->txirq = irq_of_parse_and_map(node, 3); 1077 - rmu->rxirq = irq_of_parse_and_map(node, 4); 1078 - dev_info(priv->dev, "bellirq: %d, txirq: %d, rxirq %d\n", 1079 - rmu->bellirq, rmu->txirq, rmu->rxirq); 1080 - 1081 - ops = mport->ops; 1082 - 1083 - ops->dsend = fsl_rio_doorbell_send; 1084 - ops->open_outb_mbox = fsl_open_outb_mbox; 1085 - ops->open_inb_mbox = fsl_open_inb_mbox; 1086 - ops->close_outb_mbox = fsl_close_outb_mbox; 1087 - ops->close_inb_mbox = fsl_close_inb_mbox; 1088 - ops->add_outb_message = fsl_add_outb_message; 1089 - ops->add_inb_buffer = fsl_add_inb_buffer; 1090 - ops->get_inb_message = fsl_get_inb_message; 1091 1155 1092 1156 rio_init_dbell_res(&mport->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff); 1093 1157 rio_init_mbox_res(&mport->riores[RIO_INB_MBOX_RESOURCE], 0, 0); 1094 1158 rio_init_mbox_res(&mport->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0); 1095 - 1096 - /* Configure outbound doorbell window */ 1097 - out_be32(&rmu->dbell_atmu_regs->rowbar, 1098 - (mport->iores.start + RIO_MAINT_WIN_SIZE) >> 12); 1099 - /* 4k window size */ 1100 - out_be32(&rmu->dbell_atmu_regs->rowar, 0x8004200b); 1101 - 1102 - fsl_rio_doorbell_init(mport); 1103 1159 1104 1160 return 0; 1105 1161 }