diff options
Diffstat (limited to 'drivers/rapidio/rio-scan.c')
-rw-r--r-- | drivers/rapidio/rio-scan.c | 166 |
1 files changed, 130 insertions, 36 deletions
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c index cbf0d5f4fba8..74633cc6b2eb 100644 --- a/drivers/rapidio/rio-scan.c +++ b/drivers/rapidio/rio-scan.c | |||
@@ -4,6 +4,10 @@ | |||
4 | * Copyright 2005 MontaVista Software, Inc. | 4 | * Copyright 2005 MontaVista Software, Inc. |
5 | * Matt Porter <mporter@kernel.crashing.org> | 5 | * Matt Porter <mporter@kernel.crashing.org> |
6 | * | 6 | * |
7 | * Copyright 2009 Integrated Device Technology, Inc. | ||
8 | * Alex Bounine <alexandre.bounine@idt.com> | ||
9 | * - Added Port-Write/Error Management initialization and handling | ||
10 | * | ||
7 | * This program is free software; you can redistribute it and/or modify it | 11 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU General Public License as published by the | 12 | * under the terms of the GNU General Public License as published by the |
9 | * Free Software Foundation; either version 2 of the License, or (at your | 13 | * Free Software Foundation; either version 2 of the License, or (at your |
@@ -31,15 +35,16 @@ | |||
31 | LIST_HEAD(rio_devices); | 35 | LIST_HEAD(rio_devices); |
32 | static LIST_HEAD(rio_switches); | 36 | static LIST_HEAD(rio_switches); |
33 | 37 | ||
34 | #define RIO_ENUM_CMPL_MAGIC 0xdeadbeef | ||
35 | |||
36 | static void rio_enum_timeout(unsigned long); | 38 | static void rio_enum_timeout(unsigned long); |
37 | 39 | ||
40 | static void rio_init_em(struct rio_dev *rdev); | ||
41 | |||
38 | DEFINE_SPINLOCK(rio_global_list_lock); | 42 | DEFINE_SPINLOCK(rio_global_list_lock); |
39 | 43 | ||
40 | static int next_destid = 0; | 44 | static int next_destid = 0; |
41 | static int next_switchid = 0; | 45 | static int next_switchid = 0; |
42 | static int next_net = 0; | 46 | static int next_net = 0; |
47 | static int next_comptag; | ||
43 | 48 | ||
44 | static struct timer_list rio_enum_timer = | 49 | static struct timer_list rio_enum_timer = |
45 | TIMER_INITIALIZER(rio_enum_timeout, 0, 0); | 50 | TIMER_INITIALIZER(rio_enum_timeout, 0, 0); |
@@ -52,13 +57,6 @@ static int rio_mport_phys_table[] = { | |||
52 | -1, | 57 | -1, |
53 | }; | 58 | }; |
54 | 59 | ||
55 | static int rio_sport_phys_table[] = { | ||
56 | RIO_EFB_PAR_EP_FREE_ID, | ||
57 | RIO_EFB_SER_EP_FREE_ID, | ||
58 | RIO_EFB_SER_EP_FREC_ID, | ||
59 | -1, | ||
60 | }; | ||
61 | |||
62 | /** | 60 | /** |
63 | * rio_get_device_id - Get the base/extended device id for a device | 61 | * rio_get_device_id - Get the base/extended device id for a device |
64 | * @port: RIO master port | 62 | * @port: RIO master port |
@@ -119,12 +117,26 @@ static int rio_clear_locks(struct rio_mport *port) | |||
119 | u32 result; | 117 | u32 result; |
120 | int ret = 0; | 118 | int ret = 0; |
121 | 119 | ||
122 | /* Write component tag CSR magic complete value */ | 120 | /* Assign component tag to all devices */ |
123 | rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR, | 121 | next_comptag = 1; |
124 | RIO_ENUM_CMPL_MAGIC); | 122 | rio_local_write_config_32(port, RIO_COMPONENT_TAG_CSR, next_comptag++); |
125 | list_for_each_entry(rdev, &rio_devices, global_list) | 123 | |
126 | rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR, | 124 | list_for_each_entry(rdev, &rio_devices, global_list) { |
127 | RIO_ENUM_CMPL_MAGIC); | 125 | /* Mark device as discovered */ |
126 | rio_read_config_32(rdev, | ||
127 | rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR, | ||
128 | &result); | ||
129 | rio_write_config_32(rdev, | ||
130 | rdev->phys_efptr + RIO_PORT_GEN_CTL_CSR, | ||
131 | result | RIO_PORT_GEN_DISCOVERED); | ||
132 | |||
133 | rio_write_config_32(rdev, RIO_COMPONENT_TAG_CSR, next_comptag); | ||
134 | rdev->comp_tag = next_comptag++; | ||
135 | if (next_comptag >= 0x10000) { | ||
136 | pr_err("RIO: Component Tag Counter Overflow\n"); | ||
137 | break; | ||
138 | } | ||
139 | } | ||
128 | 140 | ||
129 | /* Release host device id locks */ | 141 | /* Release host device id locks */ |
130 | rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, | 142 | rio_local_write_config_32(port, RIO_HOST_DID_LOCK_CSR, |
@@ -267,6 +279,30 @@ static void rio_route_set_ops(struct rio_dev *rdev) | |||
267 | } | 279 | } |
268 | 280 | ||
269 | /** | 281 | /** |
282 | * rio_em_set_ops- Sets Error Managment operations for a particular vendor switch | ||
283 | * @rdev: RIO device | ||
284 | * | ||
285 | * Searches the RIO EM ops table for known switch types. If the vid | ||
286 | * and did match a switch table entry, then set the em_init() and | ||
287 | * em_handle() ops to the table entry values. | ||
288 | */ | ||
289 | static void rio_em_set_ops(struct rio_dev *rdev) | ||
290 | { | ||
291 | struct rio_em_ops *cur = __start_rio_em_ops; | ||
292 | struct rio_em_ops *end = __end_rio_em_ops; | ||
293 | |||
294 | while (cur < end) { | ||
295 | if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) { | ||
296 | pr_debug("RIO: adding EM ops for %s\n", rio_name(rdev)); | ||
297 | rdev->rswitch->em_init = cur->init_hook; | ||
298 | rdev->rswitch->em_handle = cur->handler_hook; | ||
299 | break; | ||
300 | } | ||
301 | cur++; | ||
302 | } | ||
303 | } | ||
304 | |||
305 | /** | ||
270 | * rio_add_device- Adds a RIO device to the device model | 306 | * rio_add_device- Adds a RIO device to the device model |
271 | * @rdev: RIO device | 307 | * @rdev: RIO device |
272 | * | 308 | * |
@@ -336,8 +372,14 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net, | |||
336 | rdev->asm_rev = result >> 16; | 372 | rdev->asm_rev = result >> 16; |
337 | rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR, | 373 | rio_mport_read_config_32(port, destid, hopcount, RIO_PEF_CAR, |
338 | &rdev->pef); | 374 | &rdev->pef); |
339 | if (rdev->pef & RIO_PEF_EXT_FEATURES) | 375 | if (rdev->pef & RIO_PEF_EXT_FEATURES) { |
340 | rdev->efptr = result & 0xffff; | 376 | rdev->efptr = result & 0xffff; |
377 | rdev->phys_efptr = rio_mport_get_physefb(port, 0, destid, | ||
378 | hopcount); | ||
379 | |||
380 | rdev->em_efptr = rio_mport_get_feature(port, 0, destid, | ||
381 | hopcount, RIO_EFB_ERR_MGMNT); | ||
382 | } | ||
341 | 383 | ||
342 | rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR, | 384 | rio_mport_read_config_32(port, destid, hopcount, RIO_SRC_OPS_CAR, |
343 | &rdev->src_ops); | 385 | &rdev->src_ops); |
@@ -366,6 +408,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net, | |||
366 | rswitch->switchid = next_switchid; | 408 | rswitch->switchid = next_switchid; |
367 | rswitch->hopcount = hopcount; | 409 | rswitch->hopcount = hopcount; |
368 | rswitch->destid = destid; | 410 | rswitch->destid = destid; |
411 | rswitch->port_ok = 0; | ||
369 | rswitch->route_table = kzalloc(sizeof(u8)* | 412 | rswitch->route_table = kzalloc(sizeof(u8)* |
370 | RIO_MAX_ROUTE_ENTRIES(port->sys_size), | 413 | RIO_MAX_ROUTE_ENTRIES(port->sys_size), |
371 | GFP_KERNEL); | 414 | GFP_KERNEL); |
@@ -379,6 +422,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net, | |||
379 | dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, | 422 | dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, |
380 | rdev->rswitch->switchid); | 423 | rdev->rswitch->switchid); |
381 | rio_route_set_ops(rdev); | 424 | rio_route_set_ops(rdev); |
425 | rio_em_set_ops(rdev); | ||
382 | 426 | ||
383 | if (do_enum && rdev->rswitch->clr_table) | 427 | if (do_enum && rdev->rswitch->clr_table) |
384 | rdev->rswitch->clr_table(port, destid, hopcount, | 428 | rdev->rswitch->clr_table(port, destid, hopcount, |
@@ -429,23 +473,29 @@ cleanup: | |||
429 | * | 473 | * |
430 | * Reads the port error status CSR for a particular switch port to | 474 | * Reads the port error status CSR for a particular switch port to |
431 | * determine if the port has an active link. Returns | 475 | * determine if the port has an active link. Returns |
432 | * %PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is | 476 | * %RIO_PORT_N_ERR_STS_PORT_OK if the port is active or %0 if it is |
433 | * inactive. | 477 | * inactive. |
434 | */ | 478 | */ |
435 | static int | 479 | static int |
436 | rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport) | 480 | rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport) |
437 | { | 481 | { |
438 | u32 result; | 482 | u32 result = 0; |
439 | u32 ext_ftr_ptr; | 483 | u32 ext_ftr_ptr; |
440 | 484 | ||
441 | int *entry = rio_sport_phys_table; | 485 | ext_ftr_ptr = rio_mport_get_efb(port, 0, destid, hopcount, 0); |
442 | |||
443 | do { | ||
444 | if ((ext_ftr_ptr = | ||
445 | rio_mport_get_feature(port, 0, destid, hopcount, *entry))) | ||
446 | 486 | ||
487 | while (ext_ftr_ptr) { | ||
488 | rio_mport_read_config_32(port, destid, hopcount, | ||
489 | ext_ftr_ptr, &result); | ||
490 | result = RIO_GET_BLOCK_ID(result); | ||
491 | if ((result == RIO_EFB_SER_EP_FREE_ID) || | ||
492 | (result == RIO_EFB_SER_EP_FREE_ID_V13P) || | ||
493 | (result == RIO_EFB_SER_EP_FREC_ID)) | ||
447 | break; | 494 | break; |
448 | } while (*++entry >= 0); | 495 | |
496 | ext_ftr_ptr = rio_mport_get_efb(port, 0, destid, hopcount, | ||
497 | ext_ftr_ptr); | ||
498 | } | ||
449 | 499 | ||
450 | if (ext_ftr_ptr) | 500 | if (ext_ftr_ptr) |
451 | rio_mport_read_config_32(port, destid, hopcount, | 501 | rio_mport_read_config_32(port, destid, hopcount, |
@@ -453,7 +503,7 @@ rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport) | |||
453 | RIO_PORT_N_ERR_STS_CSR(sport), | 503 | RIO_PORT_N_ERR_STS_CSR(sport), |
454 | &result); | 504 | &result); |
455 | 505 | ||
456 | return (result & PORT_N_ERR_STS_PORT_OK); | 506 | return result & RIO_PORT_N_ERR_STS_PORT_OK; |
457 | } | 507 | } |
458 | 508 | ||
459 | /** | 509 | /** |
@@ -762,8 +812,10 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, | |||
762 | rio_name(rdev), rdev->vid, rdev->did, num_ports); | 812 | rio_name(rdev), rdev->vid, rdev->did, num_ports); |
763 | sw_destid = next_destid; | 813 | sw_destid = next_destid; |
764 | for (port_num = 0; port_num < num_ports; port_num++) { | 814 | for (port_num = 0; port_num < num_ports; port_num++) { |
765 | if (sw_inport == port_num) | 815 | if (sw_inport == port_num) { |
816 | rdev->rswitch->port_ok |= (1 << port_num); | ||
766 | continue; | 817 | continue; |
818 | } | ||
767 | 819 | ||
768 | cur_destid = next_destid; | 820 | cur_destid = next_destid; |
769 | 821 | ||
@@ -773,6 +825,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, | |||
773 | pr_debug( | 825 | pr_debug( |
774 | "RIO: scanning device on port %d\n", | 826 | "RIO: scanning device on port %d\n", |
775 | port_num); | 827 | port_num); |
828 | rdev->rswitch->port_ok |= (1 << port_num); | ||
776 | rio_route_add_entry(port, rdev->rswitch, | 829 | rio_route_add_entry(port, rdev->rswitch, |
777 | RIO_GLOBAL_TABLE, | 830 | RIO_GLOBAL_TABLE, |
778 | RIO_ANY_DESTID(port->sys_size), | 831 | RIO_ANY_DESTID(port->sys_size), |
@@ -797,9 +850,28 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, | |||
797 | port_num; | 850 | port_num; |
798 | } | 851 | } |
799 | } | 852 | } |
853 | } else { | ||
854 | /* If switch supports Error Management, | ||
855 | * set PORT_LOCKOUT bit for unused port | ||
856 | */ | ||
857 | if (rdev->em_efptr) | ||
858 | rio_set_port_lockout(rdev, port_num, 1); | ||
859 | |||
860 | rdev->rswitch->port_ok &= ~(1 << port_num); | ||
800 | } | 861 | } |
801 | } | 862 | } |
802 | 863 | ||
864 | /* Direct Port-write messages to the enumeratiing host */ | ||
865 | if ((rdev->src_ops & RIO_SRC_OPS_PORT_WRITE) && | ||
866 | (rdev->em_efptr)) { | ||
867 | rio_write_config_32(rdev, | ||
868 | rdev->em_efptr + RIO_EM_PW_TGT_DEVID, | ||
869 | (port->host_deviceid << 16) | | ||
870 | (port->sys_size << 15)); | ||
871 | } | ||
872 | |||
873 | rio_init_em(rdev); | ||
874 | |||
803 | /* Check for empty switch */ | 875 | /* Check for empty switch */ |
804 | if (next_destid == sw_destid) { | 876 | if (next_destid == sw_destid) { |
805 | next_destid++; | 877 | next_destid++; |
@@ -819,21 +891,16 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, | |||
819 | * rio_enum_complete- Tests if enumeration of a network is complete | 891 | * rio_enum_complete- Tests if enumeration of a network is complete |
820 | * @port: Master port to send transaction | 892 | * @port: Master port to send transaction |
821 | * | 893 | * |
822 | * Tests the Component Tag CSR for presence of the magic enumeration | 894 | * Tests the Component Tag CSR for non-zero value (enumeration |
823 | * complete flag. Return %1 if enumeration is complete or %0 if | 895 | * complete flag). Return %1 if enumeration is complete or %0 if |
824 | * enumeration is incomplete. | 896 | * enumeration is incomplete. |
825 | */ | 897 | */ |
826 | static int rio_enum_complete(struct rio_mport *port) | 898 | static int rio_enum_complete(struct rio_mport *port) |
827 | { | 899 | { |
828 | u32 tag_csr; | 900 | u32 tag_csr; |
829 | int ret = 0; | ||
830 | 901 | ||
831 | rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr); | 902 | rio_local_read_config_32(port, RIO_COMPONENT_TAG_CSR, &tag_csr); |
832 | 903 | return (tag_csr & 0xffff) ? 1 : 0; | |
833 | if (tag_csr == RIO_ENUM_CMPL_MAGIC) | ||
834 | ret = 1; | ||
835 | |||
836 | return ret; | ||
837 | } | 904 | } |
838 | 905 | ||
839 | /** | 906 | /** |
@@ -915,7 +982,7 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid, | |||
915 | * | 982 | * |
916 | * Reads the port error status CSR for the master port to | 983 | * Reads the port error status CSR for the master port to |
917 | * determine if the port has an active link. Returns | 984 | * determine if the port has an active link. Returns |
918 | * %PORT_N_ERR_STS_PORT_OK if the master port is active | 985 | * %RIO_PORT_N_ERR_STS_PORT_OK if the master port is active |
919 | * or %0 if it is inactive. | 986 | * or %0 if it is inactive. |
920 | */ | 987 | */ |
921 | static int rio_mport_is_active(struct rio_mport *port) | 988 | static int rio_mport_is_active(struct rio_mport *port) |
@@ -936,7 +1003,7 @@ static int rio_mport_is_active(struct rio_mport *port) | |||
936 | RIO_PORT_N_ERR_STS_CSR(port->index), | 1003 | RIO_PORT_N_ERR_STS_CSR(port->index), |
937 | &result); | 1004 | &result); |
938 | 1005 | ||
939 | return (result & PORT_N_ERR_STS_PORT_OK); | 1006 | return result & RIO_PORT_N_ERR_STS_PORT_OK; |
940 | } | 1007 | } |
941 | 1008 | ||
942 | /** | 1009 | /** |
@@ -1008,6 +1075,32 @@ static void rio_update_route_tables(struct rio_mport *port) | |||
1008 | } | 1075 | } |
1009 | 1076 | ||
1010 | /** | 1077 | /** |
1078 | * rio_init_em - Initializes RIO Error Management (for switches) | ||
1079 | * @port: Master port associated with the RIO network | ||
1080 | * | ||
1081 | * For each enumerated switch, call device-specific error management | ||
1082 | * initialization routine (if supplied by the switch driver). | ||
1083 | */ | ||
1084 | static void rio_init_em(struct rio_dev *rdev) | ||
1085 | { | ||
1086 | if (rio_is_switch(rdev) && (rdev->em_efptr) && | ||
1087 | (rdev->rswitch->em_init)) { | ||
1088 | rdev->rswitch->em_init(rdev); | ||
1089 | } | ||
1090 | } | ||
1091 | |||
1092 | /** | ||
1093 | * rio_pw_enable - Enables/disables port-write handling by a master port | ||
1094 | * @port: Master port associated with port-write handling | ||
1095 | * @enable: 1=enable, 0=disable | ||
1096 | */ | ||
1097 | static void rio_pw_enable(struct rio_mport *port, int enable) | ||
1098 | { | ||
1099 | if (port->ops->pwenable) | ||
1100 | port->ops->pwenable(port, enable); | ||
1101 | } | ||
1102 | |||
1103 | /** | ||
1011 | * rio_enum_mport- Start enumeration through a master port | 1104 | * rio_enum_mport- Start enumeration through a master port |
1012 | * @mport: Master port to send transactions | 1105 | * @mport: Master port to send transactions |
1013 | * | 1106 | * |
@@ -1050,6 +1143,7 @@ int __devinit rio_enum_mport(struct rio_mport *mport) | |||
1050 | } | 1143 | } |
1051 | rio_update_route_tables(mport); | 1144 | rio_update_route_tables(mport); |
1052 | rio_clear_locks(mport); | 1145 | rio_clear_locks(mport); |
1146 | rio_pw_enable(mport, 1); | ||
1053 | } else { | 1147 | } else { |
1054 | printk(KERN_INFO "RIO: master port %d link inactive\n", | 1148 | printk(KERN_INFO "RIO: master port %d link inactive\n", |
1055 | mport->id); | 1149 | mport->id); |