diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2010-06-30 06:16:24 -0400 |
---|---|---|
committer | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2010-07-26 08:27:25 -0400 |
commit | 2dcf78c0eeae3bd07082821557014f25f02ca2e9 (patch) | |
tree | 8ca5c4c7f35c9a9ab07fcd9732124c905e609aa1 /drivers/rapidio/rio.c | |
parent | 6b6322676add0fa2713d0ec89a28390fd4d907f5 (diff) | |
parent | 5109a4597f7e758b8d20694392d0361a0b4c43b1 (diff) |
Merge branch 'imx/for-2.6.36' of git://git.pengutronix.de/git/ukl/linux-2.6 into HEAD
There are some more conflicts than detected by git, namely support for
the newly added cpuimx machines needed to be converted to dynamic device
registration.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Conflicts:
arch/arm/mach-imx/Makefile
arch/arm/mach-imx/devices.c
arch/arm/mach-imx/devices.h
arch/arm/mach-imx/eukrea_mbimx27-baseboard.c
arch/arm/mach-mx2/Kconfig
arch/arm/mach-mx25/Makefile
arch/arm/mach-mx25/devices.c
arch/arm/plat-mxc/include/mach/mx25.h
arch/arm/plat-mxc/include/mach/mxc_nand.h
Diffstat (limited to 'drivers/rapidio/rio.c')
-rw-r--r-- | drivers/rapidio/rio.c | 433 |
1 files changed, 433 insertions, 0 deletions
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c index 6395c780008b..08fa453af974 100644 --- a/drivers/rapidio/rio.c +++ b/drivers/rapidio/rio.c | |||
@@ -5,6 +5,10 @@ | |||
5 | * Copyright 2005 MontaVista Software, Inc. | 5 | * Copyright 2005 MontaVista Software, Inc. |
6 | * Matt Porter <mporter@kernel.crashing.org> | 6 | * Matt Porter <mporter@kernel.crashing.org> |
7 | * | 7 | * |
8 | * Copyright 2009 Integrated Device Technology, Inc. | ||
9 | * Alex Bounine <alexandre.bounine@idt.com> | ||
10 | * - Added Port-Write/Error Management initialization and handling | ||
11 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | 12 | * This program is free software; you can redistribute it and/or modify it |
9 | * under the terms of the GNU General Public License as published by the | 13 | * under the terms of the GNU General Public License as published by the |
10 | * Free Software Foundation; either version 2 of the License, or (at your | 14 | * Free Software Foundation; either version 2 of the License, or (at your |
@@ -333,6 +337,331 @@ int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res) | |||
333 | } | 337 | } |
334 | 338 | ||
335 | /** | 339 | /** |
340 | * rio_request_inb_pwrite - request inbound port-write message service | ||
341 | * @rdev: RIO device to which register inbound port-write callback routine | ||
342 | * @pwcback: Callback routine to execute when port-write is received | ||
343 | * | ||
344 | * Binds a port-write callback function to the RapidIO device. | ||
345 | * Returns 0 if the request has been satisfied. | ||
346 | */ | ||
347 | int rio_request_inb_pwrite(struct rio_dev *rdev, | ||
348 | int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step)) | ||
349 | { | ||
350 | int rc = 0; | ||
351 | |||
352 | spin_lock(&rio_global_list_lock); | ||
353 | if (rdev->pwcback != NULL) | ||
354 | rc = -ENOMEM; | ||
355 | else | ||
356 | rdev->pwcback = pwcback; | ||
357 | |||
358 | spin_unlock(&rio_global_list_lock); | ||
359 | return rc; | ||
360 | } | ||
361 | EXPORT_SYMBOL_GPL(rio_request_inb_pwrite); | ||
362 | |||
363 | /** | ||
364 | * rio_release_inb_pwrite - release inbound port-write message service | ||
365 | * @rdev: RIO device which registered for inbound port-write callback | ||
366 | * | ||
367 | * Removes callback from the rio_dev structure. Returns 0 if the request | ||
368 | * has been satisfied. | ||
369 | */ | ||
370 | int rio_release_inb_pwrite(struct rio_dev *rdev) | ||
371 | { | ||
372 | int rc = -ENOMEM; | ||
373 | |||
374 | spin_lock(&rio_global_list_lock); | ||
375 | if (rdev->pwcback) { | ||
376 | rdev->pwcback = NULL; | ||
377 | rc = 0; | ||
378 | } | ||
379 | |||
380 | spin_unlock(&rio_global_list_lock); | ||
381 | return rc; | ||
382 | } | ||
383 | EXPORT_SYMBOL_GPL(rio_release_inb_pwrite); | ||
384 | |||
385 | /** | ||
386 | * rio_mport_get_physefb - Helper function that returns register offset | ||
387 | * for Physical Layer Extended Features Block. | ||
388 | * @port: Master port to issue transaction | ||
389 | * @local: Indicate a local master port or remote device access | ||
390 | * @destid: Destination ID of the device | ||
391 | * @hopcount: Number of switch hops to the device | ||
392 | */ | ||
393 | u32 | ||
394 | rio_mport_get_physefb(struct rio_mport *port, int local, | ||
395 | u16 destid, u8 hopcount) | ||
396 | { | ||
397 | u32 ext_ftr_ptr; | ||
398 | u32 ftr_header; | ||
399 | |||
400 | ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0); | ||
401 | |||
402 | while (ext_ftr_ptr) { | ||
403 | if (local) | ||
404 | rio_local_read_config_32(port, ext_ftr_ptr, | ||
405 | &ftr_header); | ||
406 | else | ||
407 | rio_mport_read_config_32(port, destid, hopcount, | ||
408 | ext_ftr_ptr, &ftr_header); | ||
409 | |||
410 | ftr_header = RIO_GET_BLOCK_ID(ftr_header); | ||
411 | switch (ftr_header) { | ||
412 | |||
413 | case RIO_EFB_SER_EP_ID_V13P: | ||
414 | case RIO_EFB_SER_EP_REC_ID_V13P: | ||
415 | case RIO_EFB_SER_EP_FREE_ID_V13P: | ||
416 | case RIO_EFB_SER_EP_ID: | ||
417 | case RIO_EFB_SER_EP_REC_ID: | ||
418 | case RIO_EFB_SER_EP_FREE_ID: | ||
419 | case RIO_EFB_SER_EP_FREC_ID: | ||
420 | |||
421 | return ext_ftr_ptr; | ||
422 | |||
423 | default: | ||
424 | break; | ||
425 | } | ||
426 | |||
427 | ext_ftr_ptr = rio_mport_get_efb(port, local, destid, | ||
428 | hopcount, ext_ftr_ptr); | ||
429 | } | ||
430 | |||
431 | return ext_ftr_ptr; | ||
432 | } | ||
433 | |||
434 | /** | ||
435 | * rio_get_comptag - Begin or continue searching for a RIO device by component tag | ||
436 | * @comp_tag: RIO component tag to match | ||
437 | * @from: Previous RIO device found in search, or %NULL for new search | ||
438 | * | ||
439 | * Iterates through the list of known RIO devices. If a RIO device is | ||
440 | * found with a matching @comp_tag, a pointer to its device | ||
441 | * structure is returned. Otherwise, %NULL is returned. A new search | ||
442 | * is initiated by passing %NULL to the @from argument. Otherwise, if | ||
443 | * @from is not %NULL, searches continue from next device on the global | ||
444 | * list. | ||
445 | */ | ||
446 | static struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from) | ||
447 | { | ||
448 | struct list_head *n; | ||
449 | struct rio_dev *rdev; | ||
450 | |||
451 | spin_lock(&rio_global_list_lock); | ||
452 | n = from ? from->global_list.next : rio_devices.next; | ||
453 | |||
454 | while (n && (n != &rio_devices)) { | ||
455 | rdev = rio_dev_g(n); | ||
456 | if (rdev->comp_tag == comp_tag) | ||
457 | goto exit; | ||
458 | n = n->next; | ||
459 | } | ||
460 | rdev = NULL; | ||
461 | exit: | ||
462 | spin_unlock(&rio_global_list_lock); | ||
463 | return rdev; | ||
464 | } | ||
465 | |||
466 | /** | ||
467 | * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port. | ||
468 | * @rdev: Pointer to RIO device control structure | ||
469 | * @pnum: Switch port number to set LOCKOUT bit | ||
470 | * @lock: Operation : set (=1) or clear (=0) | ||
471 | */ | ||
472 | int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock) | ||
473 | { | ||
474 | u8 hopcount = 0xff; | ||
475 | u16 destid = rdev->destid; | ||
476 | u32 regval; | ||
477 | |||
478 | if (rdev->rswitch) { | ||
479 | destid = rdev->rswitch->destid; | ||
480 | hopcount = rdev->rswitch->hopcount; | ||
481 | } | ||
482 | |||
483 | rio_mport_read_config_32(rdev->net->hport, destid, hopcount, | ||
484 | rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum), | ||
485 | ®val); | ||
486 | if (lock) | ||
487 | regval |= RIO_PORT_N_CTL_LOCKOUT; | ||
488 | else | ||
489 | regval &= ~RIO_PORT_N_CTL_LOCKOUT; | ||
490 | |||
491 | rio_mport_write_config_32(rdev->net->hport, destid, hopcount, | ||
492 | rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum), | ||
493 | regval); | ||
494 | return 0; | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * rio_inb_pwrite_handler - process inbound port-write message | ||
499 | * @pw_msg: pointer to inbound port-write message | ||
500 | * | ||
501 | * Processes an inbound port-write message. Returns 0 if the request | ||
502 | * has been satisfied. | ||
503 | */ | ||
504 | int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg) | ||
505 | { | ||
506 | struct rio_dev *rdev; | ||
507 | struct rio_mport *mport; | ||
508 | u8 hopcount; | ||
509 | u16 destid; | ||
510 | u32 err_status; | ||
511 | int rc, portnum; | ||
512 | |||
513 | rdev = rio_get_comptag(pw_msg->em.comptag, NULL); | ||
514 | if (rdev == NULL) { | ||
515 | /* Someting bad here (probably enumeration error) */ | ||
516 | pr_err("RIO: %s No matching device for CTag 0x%08x\n", | ||
517 | __func__, pw_msg->em.comptag); | ||
518 | return -EIO; | ||
519 | } | ||
520 | |||
521 | pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev)); | ||
522 | |||
523 | #ifdef DEBUG_PW | ||
524 | { | ||
525 | u32 i; | ||
526 | for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) { | ||
527 | pr_debug("0x%02x: %08x %08x %08x %08x", | ||
528 | i*4, pw_msg->raw[i], pw_msg->raw[i + 1], | ||
529 | pw_msg->raw[i + 2], pw_msg->raw[i + 3]); | ||
530 | i += 4; | ||
531 | } | ||
532 | pr_debug("\n"); | ||
533 | } | ||
534 | #endif | ||
535 | |||
536 | /* Call an external service function (if such is registered | ||
537 | * for this device). This may be the service for endpoints that send | ||
538 | * device-specific port-write messages. End-point messages expected | ||
539 | * to be handled completely by EP specific device driver. | ||
540 | * For switches rc==0 signals that no standard processing required. | ||
541 | */ | ||
542 | if (rdev->pwcback != NULL) { | ||
543 | rc = rdev->pwcback(rdev, pw_msg, 0); | ||
544 | if (rc == 0) | ||
545 | return 0; | ||
546 | } | ||
547 | |||
548 | /* For End-point devices processing stops here */ | ||
549 | if (!(rdev->pef & RIO_PEF_SWITCH)) | ||
550 | return 0; | ||
551 | |||
552 | if (rdev->phys_efptr == 0) { | ||
553 | pr_err("RIO_PW: Bad switch initialization for %s\n", | ||
554 | rio_name(rdev)); | ||
555 | return 0; | ||
556 | } | ||
557 | |||
558 | mport = rdev->net->hport; | ||
559 | destid = rdev->rswitch->destid; | ||
560 | hopcount = rdev->rswitch->hopcount; | ||
561 | |||
562 | /* | ||
563 | * Process the port-write notification from switch | ||
564 | */ | ||
565 | |||
566 | portnum = pw_msg->em.is_port & 0xFF; | ||
567 | |||
568 | if (rdev->rswitch->em_handle) | ||
569 | rdev->rswitch->em_handle(rdev, portnum); | ||
570 | |||
571 | rio_mport_read_config_32(mport, destid, hopcount, | ||
572 | rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), | ||
573 | &err_status); | ||
574 | pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status); | ||
575 | |||
576 | if (pw_msg->em.errdetect) { | ||
577 | pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n", | ||
578 | portnum, pw_msg->em.errdetect); | ||
579 | /* Clear EM Port N Error Detect CSR */ | ||
580 | rio_mport_write_config_32(mport, destid, hopcount, | ||
581 | rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0); | ||
582 | } | ||
583 | |||
584 | if (pw_msg->em.ltlerrdet) { | ||
585 | pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n", | ||
586 | pw_msg->em.ltlerrdet); | ||
587 | /* Clear EM L/T Layer Error Detect CSR */ | ||
588 | rio_mport_write_config_32(mport, destid, hopcount, | ||
589 | rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0); | ||
590 | } | ||
591 | |||
592 | /* Clear Port Errors */ | ||
593 | rio_mport_write_config_32(mport, destid, hopcount, | ||
594 | rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), | ||
595 | err_status & RIO_PORT_N_ERR_STS_CLR_MASK); | ||
596 | |||
597 | if (rdev->rswitch->port_ok & (1 << portnum)) { | ||
598 | if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) { | ||
599 | rdev->rswitch->port_ok &= ~(1 << portnum); | ||
600 | rio_set_port_lockout(rdev, portnum, 1); | ||
601 | |||
602 | rio_mport_write_config_32(mport, destid, hopcount, | ||
603 | rdev->phys_efptr + | ||
604 | RIO_PORT_N_ACK_STS_CSR(portnum), | ||
605 | RIO_PORT_N_ACK_CLEAR); | ||
606 | |||
607 | /* Schedule Extraction Service */ | ||
608 | pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n", | ||
609 | rio_name(rdev), portnum); | ||
610 | } | ||
611 | } else { | ||
612 | if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) { | ||
613 | rdev->rswitch->port_ok |= (1 << portnum); | ||
614 | rio_set_port_lockout(rdev, portnum, 0); | ||
615 | |||
616 | /* Schedule Insertion Service */ | ||
617 | pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n", | ||
618 | rio_name(rdev), portnum); | ||
619 | } | ||
620 | } | ||
621 | |||
622 | /* Clear Port-Write Pending bit */ | ||
623 | rio_mport_write_config_32(mport, destid, hopcount, | ||
624 | rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), | ||
625 | RIO_PORT_N_ERR_STS_PW_PEND); | ||
626 | |||
627 | return 0; | ||
628 | } | ||
629 | EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler); | ||
630 | |||
631 | /** | ||
632 | * rio_mport_get_efb - get pointer to next extended features block | ||
633 | * @port: Master port to issue transaction | ||
634 | * @local: Indicate a local master port or remote device access | ||
635 | * @destid: Destination ID of the device | ||
636 | * @hopcount: Number of switch hops to the device | ||
637 | * @from: Offset of current Extended Feature block header (if 0 starts | ||
638 | * from ExtFeaturePtr) | ||
639 | */ | ||
640 | u32 | ||
641 | rio_mport_get_efb(struct rio_mport *port, int local, u16 destid, | ||
642 | u8 hopcount, u32 from) | ||
643 | { | ||
644 | u32 reg_val; | ||
645 | |||
646 | if (from == 0) { | ||
647 | if (local) | ||
648 | rio_local_read_config_32(port, RIO_ASM_INFO_CAR, | ||
649 | ®_val); | ||
650 | else | ||
651 | rio_mport_read_config_32(port, destid, hopcount, | ||
652 | RIO_ASM_INFO_CAR, ®_val); | ||
653 | return reg_val & RIO_EXT_FTR_PTR_MASK; | ||
654 | } else { | ||
655 | if (local) | ||
656 | rio_local_read_config_32(port, from, ®_val); | ||
657 | else | ||
658 | rio_mport_read_config_32(port, destid, hopcount, | ||
659 | from, ®_val); | ||
660 | return RIO_GET_BLOCK_ID(reg_val); | ||
661 | } | ||
662 | } | ||
663 | |||
664 | /** | ||
336 | * rio_mport_get_feature - query for devices' extended features | 665 | * rio_mport_get_feature - query for devices' extended features |
337 | * @port: Master port to issue transaction | 666 | * @port: Master port to issue transaction |
338 | * @local: Indicate a local master port or remote device access | 667 | * @local: Indicate a local master port or remote device access |
@@ -451,6 +780,110 @@ struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from) | |||
451 | return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from); | 780 | return rio_get_asm(vid, did, RIO_ANY_ID, RIO_ANY_ID, from); |
452 | } | 781 | } |
453 | 782 | ||
783 | /** | ||
784 | * rio_std_route_add_entry - Add switch route table entry using standard | ||
785 | * registers defined in RIO specification rev.1.3 | ||
786 | * @mport: Master port to issue transaction | ||
787 | * @destid: Destination ID of the device | ||
788 | * @hopcount: Number of switch hops to the device | ||
789 | * @table: routing table ID (global or port-specific) | ||
790 | * @route_destid: destID entry in the RT | ||
791 | * @route_port: destination port for specified destID | ||
792 | */ | ||
793 | int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount, | ||
794 | u16 table, u16 route_destid, u8 route_port) | ||
795 | { | ||
796 | if (table == RIO_GLOBAL_TABLE) { | ||
797 | rio_mport_write_config_32(mport, destid, hopcount, | ||
798 | RIO_STD_RTE_CONF_DESTID_SEL_CSR, | ||
799 | (u32)route_destid); | ||
800 | rio_mport_write_config_32(mport, destid, hopcount, | ||
801 | RIO_STD_RTE_CONF_PORT_SEL_CSR, | ||
802 | (u32)route_port); | ||
803 | } | ||
804 | |||
805 | udelay(10); | ||
806 | return 0; | ||
807 | } | ||
808 | |||
809 | /** | ||
810 | * rio_std_route_get_entry - Read switch route table entry (port number) | ||
811 | * assosiated with specified destID using standard registers defined in RIO | ||
812 | * specification rev.1.3 | ||
813 | * @mport: Master port to issue transaction | ||
814 | * @destid: Destination ID of the device | ||
815 | * @hopcount: Number of switch hops to the device | ||
816 | * @table: routing table ID (global or port-specific) | ||
817 | * @route_destid: destID entry in the RT | ||
818 | * @route_port: returned destination port for specified destID | ||
819 | */ | ||
820 | int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount, | ||
821 | u16 table, u16 route_destid, u8 *route_port) | ||
822 | { | ||
823 | u32 result; | ||
824 | |||
825 | if (table == RIO_GLOBAL_TABLE) { | ||
826 | rio_mport_write_config_32(mport, destid, hopcount, | ||
827 | RIO_STD_RTE_CONF_DESTID_SEL_CSR, route_destid); | ||
828 | rio_mport_read_config_32(mport, destid, hopcount, | ||
829 | RIO_STD_RTE_CONF_PORT_SEL_CSR, &result); | ||
830 | |||
831 | *route_port = (u8)result; | ||
832 | } | ||
833 | |||
834 | return 0; | ||
835 | } | ||
836 | |||
837 | /** | ||
838 | * rio_std_route_clr_table - Clear swotch route table using standard registers | ||
839 | * defined in RIO specification rev.1.3. | ||
840 | * @mport: Master port to issue transaction | ||
841 | * @destid: Destination ID of the device | ||
842 | * @hopcount: Number of switch hops to the device | ||
843 | * @table: routing table ID (global or port-specific) | ||
844 | */ | ||
845 | int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount, | ||
846 | u16 table) | ||
847 | { | ||
848 | u32 max_destid = 0xff; | ||
849 | u32 i, pef, id_inc = 1, ext_cfg = 0; | ||
850 | u32 port_sel = RIO_INVALID_ROUTE; | ||
851 | |||
852 | if (table == RIO_GLOBAL_TABLE) { | ||
853 | rio_mport_read_config_32(mport, destid, hopcount, | ||
854 | RIO_PEF_CAR, &pef); | ||
855 | |||
856 | if (mport->sys_size) { | ||
857 | rio_mport_read_config_32(mport, destid, hopcount, | ||
858 | RIO_SWITCH_RT_LIMIT, | ||
859 | &max_destid); | ||
860 | max_destid &= RIO_RT_MAX_DESTID; | ||
861 | } | ||
862 | |||
863 | if (pef & RIO_PEF_EXT_RT) { | ||
864 | ext_cfg = 0x80000000; | ||
865 | id_inc = 4; | ||
866 | port_sel = (RIO_INVALID_ROUTE << 24) | | ||
867 | (RIO_INVALID_ROUTE << 16) | | ||
868 | (RIO_INVALID_ROUTE << 8) | | ||
869 | RIO_INVALID_ROUTE; | ||
870 | } | ||
871 | |||
872 | for (i = 0; i <= max_destid;) { | ||
873 | rio_mport_write_config_32(mport, destid, hopcount, | ||
874 | RIO_STD_RTE_CONF_DESTID_SEL_CSR, | ||
875 | ext_cfg | i); | ||
876 | rio_mport_write_config_32(mport, destid, hopcount, | ||
877 | RIO_STD_RTE_CONF_PORT_SEL_CSR, | ||
878 | port_sel); | ||
879 | i += id_inc; | ||
880 | } | ||
881 | } | ||
882 | |||
883 | udelay(10); | ||
884 | return 0; | ||
885 | } | ||
886 | |||
454 | static void rio_fixup_device(struct rio_dev *dev) | 887 | static void rio_fixup_device(struct rio_dev *dev) |
455 | { | 888 | { |
456 | } | 889 | } |