aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire/fw-topology.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@localhost.localdomain>2007-01-26 00:37:50 -0500
committerStefan Richter <stefanr@s5r6.in-berlin.de>2007-03-09 16:02:44 -0500
commit83db801ce8c644edee49f4364c7ebdfef1657762 (patch)
tree8180198c618d78ce7b774951ffa4e1a6d553a7e1 /drivers/firewire/fw-topology.c
parentcfb01381f4ffcd05aefe76c74911ba6bc996e8ba (diff)
firewire: Implement gap count optimization.
Signed-off-by: Kristian Høgsberg <krh@redhat.com> Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/firewire/fw-topology.c')
-rw-r--r--drivers/firewire/fw-topology.c76
1 files changed, 67 insertions, 9 deletions
diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/fw-topology.c
index 684d87d99775..d3131e7d52fa 100644
--- a/drivers/firewire/fw-topology.c
+++ b/drivers/firewire/fw-topology.c
@@ -113,6 +113,44 @@ static struct fw_node *fw_node_create(u32 sid, int port_count, int color)
113 return node; 113 return node;
114} 114}
115 115
116/* Compute the maximum hop count for this node and it's children. The
117 * maximum hop count is the maximum number of connections between any
118 * two nodes in the subtree rooted at this node. We need this for
119 * setting the gap count. As we build the tree bottom up in
120 * build_tree() below, this is fairly easy to do: for each node we
121 * maintain the max hop count and the max depth, ie the number of hops
122 * to the furthest leaf. Computing the max hop count breaks down into
123 * two cases: either the path goes through this node, in which case
124 * the hop count is the sum of the two biggest child depths plus 2.
125 * Or it could be the case that the max hop path is entirely
126 * containted in a child tree, in which case the max hop count is just
127 * the max hop count of this child.
128 */
129static void update_hop_count(struct fw_node *node)
130{
131 int depths[2] = { -1, -1 };
132 int max_child_hops = 0;
133 int i;
134
135 for (i = 0; i < node->port_count; i++) {
136 if (node->ports[i].node == NULL)
137 continue;
138
139 if (node->ports[i].node->max_hops > max_child_hops)
140 max_child_hops = node->ports[i].node->max_hops;
141
142 if (node->ports[i].node->max_depth > depths[0]) {
143 depths[1] = depths[0];
144 depths[0] = node->ports[i].node->max_depth;
145 } else if (node->ports[i].node->max_depth > depths[1])
146 depths[1] = node->ports[i].node->max_depth;
147 }
148
149 node->max_depth = depths[0] + 1;
150 node->max_hops = max(max_child_hops, depths[0] + depths[1] + 2);
151}
152
153
116/** 154/**
117 * build_tree - Build the tree representation of the topology 155 * build_tree - Build the tree representation of the topology
118 * @self_ids: array of self IDs to create the tree from 156 * @self_ids: array of self IDs to create the tree from
@@ -131,6 +169,7 @@ static struct fw_node *build_tree(struct fw_card *card)
131 struct list_head stack, *h; 169 struct list_head stack, *h;
132 u32 *sid, *next_sid, *end, q; 170 u32 *sid, *next_sid, *end, q;
133 int i, port_count, child_port_count, phy_id, parent_count, stack_depth; 171 int i, port_count, child_port_count, phy_id, parent_count, stack_depth;
172 int gap_count, topology_type;
134 173
135 local_node = NULL; 174 local_node = NULL;
136 node = NULL; 175 node = NULL;
@@ -140,6 +179,8 @@ static struct fw_node *build_tree(struct fw_card *card)
140 end = sid + card->self_id_count; 179 end = sid + card->self_id_count;
141 phy_id = 0; 180 phy_id = 0;
142 card->irm_node = NULL; 181 card->irm_node = NULL;
182 gap_count = self_id_gap_count(*sid);
183 topology_type = 0;
143 184
144 while (sid < end) { 185 while (sid < end) {
145 next_sid = count_ports(sid, &port_count, &child_port_count); 186 next_sid = count_ports(sid, &port_count, &child_port_count);
@@ -179,6 +220,11 @@ static struct fw_node *build_tree(struct fw_card *card)
179 if (self_id_contender(q)) 220 if (self_id_contender(q))
180 card->irm_node = node; 221 card->irm_node = node;
181 222
223 if (node->phy_speed == SCODE_BETA)
224 topology_type |= FW_TOPOLOGY_B;
225 else
226 topology_type |= FW_TOPOLOGY_A;
227
182 parent_count = 0; 228 parent_count = 0;
183 229
184 for (i = 0; i < port_count; i++) { 230 for (i = 0; i < port_count; i++) {
@@ -223,11 +269,21 @@ static struct fw_node *build_tree(struct fw_card *card)
223 list_add_tail(&node->link, &stack); 269 list_add_tail(&node->link, &stack);
224 stack_depth += 1 - child_port_count; 270 stack_depth += 1 - child_port_count;
225 271
272 /* If all PHYs does not report the same gap count
273 * setting, we fall back to 63 which will force a gap
274 * count reconfiguration and a reset. */
275 if (self_id_gap_count(q) != gap_count)
276 gap_count = 63;
277
278 update_hop_count(node);
279
226 sid = next_sid; 280 sid = next_sid;
227 phy_id++; 281 phy_id++;
228 } 282 }
229 283
230 card->root_node = node; 284 card->root_node = node;
285 card->gap_count = gap_count;
286 card->topology_type = topology_type;
231 287
232 return local_node; 288 return local_node;
233} 289}
@@ -286,7 +342,8 @@ report_found_node(struct fw_card *card,
286 int b_path = (node->phy_speed == SCODE_BETA); 342 int b_path = (node->phy_speed == SCODE_BETA);
287 343
288 if (parent != NULL) { 344 if (parent != NULL) {
289 node->max_speed = min(parent->max_speed, node->phy_speed); 345 node->max_speed = min((u8)parent->max_speed,
346 (u8)node->phy_speed);
290 node->b_path = parent->b_path && b_path; 347 node->b_path = parent->b_path && b_path;
291 } else { 348 } else {
292 node->max_speed = node->phy_speed; 349 node->max_speed = node->phy_speed;
@@ -329,7 +386,7 @@ static void move_tree(struct fw_node *node0, struct fw_node *node1, int port)
329 * as we go. 386 * as we go.
330 */ 387 */
331static void 388static void
332update_tree(struct fw_card *card, struct fw_node *root, int *changed) 389update_tree(struct fw_card *card, struct fw_node *root)
333{ 390{
334 struct list_head list0, list1; 391 struct list_head list0, list1;
335 struct fw_node *node0, *node1; 392 struct fw_node *node0, *node1;
@@ -342,7 +399,6 @@ update_tree(struct fw_card *card, struct fw_node *root, int *changed)
342 399
343 node0 = fw_node(list0.next); 400 node0 = fw_node(list0.next);
344 node1 = fw_node(list1.next); 401 node1 = fw_node(list1.next);
345 *changed = 0;
346 402
347 while (&node0->link != &list0) { 403 while (&node0->link != &list0) {
348 404
@@ -358,6 +414,7 @@ update_tree(struct fw_card *card, struct fw_node *root, int *changed)
358 node0->color = card->color; 414 node0->color = card->color;
359 node0->link_on = node1->link_on; 415 node0->link_on = node1->link_on;
360 node0->initiated_reset = node1->initiated_reset; 416 node0->initiated_reset = node1->initiated_reset;
417 node0->max_hops = node1->max_hops;
361 node1->color = card->color; 418 node1->color = card->color;
362 fw_node_event(card, node0, event); 419 fw_node_event(card, node0, event);
363 420
@@ -386,7 +443,6 @@ update_tree(struct fw_card *card, struct fw_node *root, int *changed)
386 for_each_fw_node(card, node0->ports[i].node, 443 for_each_fw_node(card, node0->ports[i].node,
387 report_lost_node); 444 report_lost_node);
388 node0->ports[i].node = NULL; 445 node0->ports[i].node = NULL;
389 *changed = 1;
390 } else if (node1->ports[i].node) { 446 } else if (node1->ports[i].node) {
391 /* One or more node were connected to 447 /* One or more node were connected to
392 * this port. Move the new nodes into 448 * this port. Move the new nodes into
@@ -395,7 +451,6 @@ update_tree(struct fw_card *card, struct fw_node *root, int *changed)
395 move_tree(node0, node1, i); 451 move_tree(node0, node1, i);
396 for_each_fw_node(card, node0->ports[i].node, 452 for_each_fw_node(card, node0->ports[i].node,
397 report_found_node); 453 report_found_node);
398 *changed = 1;
399 } 454 }
400 } 455 }
401 456
@@ -411,12 +466,17 @@ fw_core_handle_bus_reset(struct fw_card *card,
411{ 466{
412 struct fw_node *local_node; 467 struct fw_node *local_node;
413 unsigned long flags; 468 unsigned long flags;
414 int changed;
415 469
416 fw_flush_transactions(card); 470 fw_flush_transactions(card);
417 471
418 spin_lock_irqsave(&card->lock, flags); 472 spin_lock_irqsave(&card->lock, flags);
419 473
474 /* If the new topology has a different self_id_count the topology
475 * changed, either nodes were added or removed. In that case we
476 * reset the IRM reset counter. */
477 if (card->self_id_count != self_id_count)
478 card->irm_retries = 0;
479
420 card->node_id = node_id; 480 card->node_id = node_id;
421 card->self_id_count = self_id_count; 481 card->self_id_count = self_id_count;
422 card->generation = generation; 482 card->generation = generation;
@@ -433,9 +493,7 @@ fw_core_handle_bus_reset(struct fw_card *card,
433 card->local_node = local_node; 493 card->local_node = local_node;
434 for_each_fw_node(card, local_node, report_found_node); 494 for_each_fw_node(card, local_node, report_found_node);
435 } else { 495 } else {
436 update_tree(card, local_node, &changed); 496 update_tree(card, local_node);
437 if (changed)
438 card->irm_retries = 0;
439 } 497 }
440 498
441 /* If we're not the root node, we may have to do some IRM work. */ 499 /* If we're not the root node, we may have to do some IRM work. */