aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/firewire
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
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')
-rw-r--r--drivers/firewire/fw-card.c46
-rw-r--r--drivers/firewire/fw-topology.c76
-rw-r--r--drivers/firewire/fw-topology.h15
-rw-r--r--drivers/firewire/fw-transaction.c8
-rw-r--r--drivers/firewire/fw-transaction.h6
5 files changed, 120 insertions, 31 deletions
diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c
index c8b7d695c81d..307c8b851382 100644
--- a/drivers/firewire/fw-card.c
+++ b/drivers/firewire/fw-card.c
@@ -186,14 +186,17 @@ fw_core_remove_descriptor (struct fw_descriptor *desc)
186} 186}
187EXPORT_SYMBOL(fw_core_remove_descriptor); 187EXPORT_SYMBOL(fw_core_remove_descriptor);
188 188
189static const char gap_count_table[] = {
190 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
191};
192
189static void 193static void
190fw_card_irm_work(struct work_struct *work) 194fw_card_irm_work(struct work_struct *work)
191{ 195{
192 struct fw_card *card = 196 struct fw_card *card = container_of(work, struct fw_card, work.work);
193 container_of(work, struct fw_card, work.work);
194 struct fw_device *root; 197 struct fw_device *root;
195 unsigned long flags; 198 unsigned long flags;
196 int new_irm_id, generation; 199 int root_id, new_irm_id, gap_count, generation, do_reset = 0;
197 200
198 /* FIXME: This simple bus management unconditionally picks a 201 /* FIXME: This simple bus management unconditionally picks a
199 * cycle master if the current root can't do it. We need to 202 * cycle master if the current root can't do it. We need to
@@ -206,35 +209,50 @@ fw_card_irm_work(struct work_struct *work)
206 209
207 generation = card->generation; 210 generation = card->generation;
208 root = card->root_node->data; 211 root = card->root_node->data;
212 root_id = card->root_node->node_id;
209 213
210 if (root == NULL) 214 if (root == NULL) {
211 /* Either link_on is false, or we failed to read the 215 /* Either link_on is false, or we failed to read the
212 * config rom. In either case, pick another root. */ 216 * config rom. In either case, pick another root. */
213 new_irm_id = card->local_node->node_id; 217 new_irm_id = card->local_node->node_id;
214 else if (root->state != FW_DEVICE_RUNNING) 218 } else if (root->state != FW_DEVICE_RUNNING) {
215 /* If we haven't probed this device yet, bail out now 219 /* If we haven't probed this device yet, bail out now
216 * and let's try again once that's done. */ 220 * and let's try again once that's done. */
217 new_irm_id = -1; 221 new_irm_id = root_id;
218 else if (root->config_rom[2] & bib_cmc) 222 } else if (root->config_rom[2] & bib_cmc) {
219 /* FIXME: I suppose we should set the cmstr bit in the 223 /* FIXME: I suppose we should set the cmstr bit in the
220 * STATE_CLEAR register of this node, as described in 224 * STATE_CLEAR register of this node, as described in
221 * 1394-1995, 8.4.2.6. Also, send out a force root 225 * 1394-1995, 8.4.2.6. Also, send out a force root
222 * packet for this node. */ 226 * packet for this node. */
223 new_irm_id = -1; 227 new_irm_id = root_id;
224 else 228 } else {
225 /* Current root has an active link layer and we 229 /* Current root has an active link layer and we
226 * successfully read the config rom, but it's not 230 * successfully read the config rom, but it's not
227 * cycle master capable. */ 231 * cycle master capable. */
228 new_irm_id = card->local_node->node_id; 232 new_irm_id = card->local_node->node_id;
233 }
234
235 /* Now figure out what gap count to set. */
236 if (card->topology_type == FW_TOPOLOGY_A &&
237 card->root_node->max_hops < ARRAY_SIZE(gap_count_table))
238 gap_count = gap_count_table[card->root_node->max_hops];
239 else
240 gap_count = 63;
241
242 /* Finally, figure out if we should do a reset or not. If we've
243 * done less that 5 resets with the same physical topology and we
244 * have either a new root or a new gap count setting, let's do it. */
229 245
230 if (card->irm_retries++ > 5) 246 if (card->irm_retries++ < 5 &&
231 new_irm_id = -1; 247 (card->gap_count != gap_count || new_irm_id != root_id))
248 do_reset = 1;
232 249
233 spin_unlock_irqrestore(&card->lock, flags); 250 spin_unlock_irqrestore(&card->lock, flags);
234 251
235 if (new_irm_id > 0) { 252 if (do_reset) {
236 fw_notify("Trying to become root (card %d)\n", card->index); 253 fw_notify("phy config: card %d, new root=%x, gap_count=%d\n",
237 fw_send_force_root(card, new_irm_id, generation); 254 card->index, new_irm_id, gap_count);
255 fw_send_phy_config(card, new_irm_id, generation, gap_count);
238 fw_core_initiate_bus_reset(card, 1); 256 fw_core_initiate_bus_reset(card, 1);
239 } 257 }
240} 258}
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. */
diff --git a/drivers/firewire/fw-topology.h b/drivers/firewire/fw-topology.h
index ab03059a0da1..f2a575e05ae1 100644
--- a/drivers/firewire/fw-topology.h
+++ b/drivers/firewire/fw-topology.h
@@ -23,6 +23,12 @@
23#define __fw_topology_h 23#define __fw_topology_h
24 24
25enum { 25enum {
26 FW_TOPOLOGY_A = 0x01,
27 FW_TOPOLOGY_B = 0x02,
28 FW_TOPOLOGY_MIXED = 0x03,
29};
30
31enum {
26 FW_NODE_CREATED = 0x00, 32 FW_NODE_CREATED = 0x00,
27 FW_NODE_UPDATED = 0x01, 33 FW_NODE_UPDATED = 0x01,
28 FW_NODE_DESTROYED = 0x02, 34 FW_NODE_DESTROYED = 0x02,
@@ -42,10 +48,11 @@ struct fw_node {
42 unsigned link_on : 1; 48 unsigned link_on : 1;
43 unsigned initiated_reset : 1; 49 unsigned initiated_reset : 1;
44 unsigned b_path : 1; 50 unsigned b_path : 1;
45 u8 phy_speed; /* As in the self ID packet. */ 51 u8 phy_speed : 3; /* As in the self ID packet. */
46 u8 max_speed; /* Minimum of all phy-speeds and port speeds on 52 u8 max_speed : 5; /* Minimum of all phy-speeds and port speeds on
47 * the path from the local node to this node. */ 53 * the path from the local node to this node. */
48 54 u8 max_depth : 4; /* Maximum depth to any leaf node */
55 u8 max_hops : 4; /* Max hops in this sub tree */
49 atomic_t ref_count; 56 atomic_t ref_count;
50 57
51 /* For serializing node topology into a list. */ 58 /* For serializing node topology into a list. */
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c
index 439a3e3ee2f0..57ecf95e5271 100644
--- a/drivers/firewire/fw-transaction.c
+++ b/drivers/firewire/fw-transaction.c
@@ -274,11 +274,15 @@ static void send_phy_packet(struct fw_card *card, u32 data, int generation)
274 card->driver->send_request(card, packet); 274 card->driver->send_request(card, packet);
275} 275}
276 276
277void fw_send_force_root(struct fw_card *card, int node_id, int generation) 277void fw_send_phy_config(struct fw_card *card,
278 int node_id, int generation, int gap_count)
278{ 279{
279 u32 q; 280 u32 q;
280 281
281 q = phy_identifier(PHY_PACKET_CONFIG) | phy_config_root_id(node_id); 282 q = phy_identifier(PHY_PACKET_CONFIG) |
283 phy_config_root_id(node_id) |
284 phy_config_gap_count(gap_count);
285
282 send_phy_packet(card, q, generation); 286 send_phy_packet(card, q, generation);
283} 287}
284 288
diff --git a/drivers/firewire/fw-transaction.h b/drivers/firewire/fw-transaction.h
index 22d2871131b1..df652452bdb5 100644
--- a/drivers/firewire/fw-transaction.h
+++ b/drivers/firewire/fw-transaction.h
@@ -259,6 +259,8 @@ struct fw_card {
259 struct fw_node *root_node; 259 struct fw_node *root_node;
260 struct fw_node *irm_node; 260 struct fw_node *irm_node;
261 int color; 261 int color;
262 int gap_count;
263 int topology_type;
262 264
263 int index; 265 int index;
264 266
@@ -386,8 +388,8 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t,
386 388
387void fw_flush_transactions(struct fw_card *card); 389void fw_flush_transactions(struct fw_card *card);
388 390
389void 391void fw_send_phy_config(struct fw_card *card,
390fw_send_force_root(struct fw_card *card, int node_id, int generation); 392 int node_id, int generation, int gap_count);
391 393
392/* Called by the topology code to inform the device code of node 394/* Called by the topology code to inform the device code of node
393 * activity; found, lost, or updated nodes */ 395 * activity; found, lost, or updated nodes */