@@ -27,12 +27,11 @@ struct hsr_node {
27
27
struct list_head mac_list ;
28
28
unsigned char MacAddressA [ETH_ALEN ];
29
29
unsigned char MacAddressB [ETH_ALEN ];
30
- enum hsr_dev_idx AddrB_if ;/* The local slave through which AddrB
31
- * frames are received from this node
32
- */
33
- unsigned long time_in [HSR_MAX_SLAVE ];
34
- bool time_in_stale [HSR_MAX_SLAVE ];
35
- u16 seq_out [HSR_MAX_DEV ];
30
+ /* Local slave through which AddrB frames are received from this node */
31
+ enum hsr_port_type AddrB_port ;
32
+ unsigned long time_in [HSR_PT_PORTS ];
33
+ bool time_in_stale [HSR_PT_PORTS ];
34
+ u16 seq_out [HSR_PT_PORTS ];
36
35
struct rcu_head rcu_head ;
37
36
};
38
37
@@ -154,18 +153,18 @@ int hsr_create_self_node(struct list_head *self_node_db,
154
153
* We also need to detect if the sender's SlaveA and SlaveB cables have been
155
154
* swapped.
156
155
*/
157
- struct hsr_node * hsr_merge_node (struct hsr_priv * hsr ,
158
- struct hsr_node * node ,
159
- struct sk_buff * skb ,
160
- enum hsr_dev_idx dev_idx )
156
+ struct hsr_node * hsr_merge_node (struct hsr_node * node , struct sk_buff * skb ,
157
+ struct hsr_port * port )
161
158
{
159
+ struct hsr_priv * hsr ;
162
160
struct hsr_sup_payload * hsr_sp ;
163
161
struct hsr_ethhdr_sp * hsr_ethsup ;
164
162
int i ;
165
163
unsigned long now ;
166
164
167
165
hsr_ethsup = (struct hsr_ethhdr_sp * ) skb_mac_header (skb );
168
166
hsr_sp = (struct hsr_sup_payload * ) skb -> data ;
167
+ hsr = port -> hsr ;
169
168
170
169
if (node && !ether_addr_equal (node -> MacAddressA , hsr_sp -> MacAddressA )) {
171
170
/* Node has changed its AddrA, frame was received from SlaveB */
@@ -174,16 +173,16 @@ struct hsr_node *hsr_merge_node(struct hsr_priv *hsr,
174
173
node = NULL ;
175
174
}
176
175
177
- if (node && (dev_idx == node -> AddrB_if ) &&
176
+ if (node && (port -> type == node -> AddrB_port ) &&
178
177
!ether_addr_equal (node -> MacAddressB , hsr_ethsup -> ethhdr .h_source )) {
179
178
/* Cables have been swapped */
180
179
list_del_rcu (& node -> mac_list );
181
180
kfree_rcu (node , rcu_head );
182
181
node = NULL ;
183
182
}
184
183
185
- if (node && (dev_idx != node -> AddrB_if ) &&
186
- (node -> AddrB_if != HSR_DEV_NONE ) &&
184
+ if (node && (port -> type != node -> AddrB_port ) &&
185
+ (node -> AddrB_port != HSR_PT_NONE ) &&
187
186
!ether_addr_equal (node -> MacAddressA , hsr_ethsup -> ethhdr .h_source )) {
188
187
/* Cables have been swapped */
189
188
list_del_rcu (& node -> mac_list );
@@ -200,7 +199,7 @@ struct hsr_node *hsr_merge_node(struct hsr_priv *hsr,
200
199
* address. Node is PICS_SUBS capable; merge its AddrB.
201
200
*/
202
201
ether_addr_copy (node -> MacAddressB , hsr_ethsup -> ethhdr .h_source );
203
- node -> AddrB_if = dev_idx ;
202
+ node -> AddrB_port = port -> type ;
204
203
return node ;
205
204
}
206
205
@@ -211,17 +210,15 @@ struct hsr_node *hsr_merge_node(struct hsr_priv *hsr,
211
210
ether_addr_copy (node -> MacAddressA , hsr_sp -> MacAddressA );
212
211
ether_addr_copy (node -> MacAddressB , hsr_ethsup -> ethhdr .h_source );
213
212
if (!ether_addr_equal (hsr_sp -> MacAddressA , hsr_ethsup -> ethhdr .h_source ))
214
- node -> AddrB_if = dev_idx ;
215
- else
216
- node -> AddrB_if = HSR_DEV_NONE ;
213
+ node -> AddrB_port = port -> type ;
217
214
218
215
/* We are only interested in time diffs here, so use current jiffies
219
216
* as initialization. (0 could trigger an spurious ring error warning).
220
217
*/
221
218
now = jiffies ;
222
- for (i = 0 ; i < HSR_MAX_SLAVE ; i ++ )
219
+ for (i = 0 ; i < HSR_PT_PORTS ; i ++ )
223
220
node -> time_in [i ] = now ;
224
- for (i = 0 ; i < HSR_MAX_DEV ; i ++ )
221
+ for (i = 0 ; i < HSR_PT_PORTS ; i ++ )
225
222
node -> seq_out [i ] = ntohs (hsr_ethsup -> hsr_sup .sequence_nr ) - 1 ;
226
223
227
224
list_add_tail_rcu (& node -> mac_list , & hsr -> node_db );
@@ -265,13 +262,13 @@ void hsr_addr_subst_source(struct hsr_priv *hsr, struct sk_buff *skb)
265
262
* which "side" the different interfaces are.
266
263
*/
267
264
void hsr_addr_subst_dest (struct hsr_priv * hsr , struct ethhdr * ethhdr ,
268
- enum hsr_dev_idx dev_idx )
265
+ struct hsr_port * port )
269
266
{
270
267
struct hsr_node * node ;
271
268
272
269
rcu_read_lock ();
273
270
node = find_node_by_AddrA (& hsr -> node_db , ethhdr -> h_dest );
274
- if (node && (node -> AddrB_if == dev_idx ))
271
+ if (node && (node -> AddrB_port == port -> type ))
275
272
ether_addr_copy (ethhdr -> h_dest , node -> MacAddressB );
276
273
rcu_read_unlock ();
277
274
}
@@ -295,14 +292,10 @@ static bool seq_nr_after(u16 a, u16 b)
295
292
#define seq_nr_before_or_eq (a , b ) (!seq_nr_after((a), (b)))
296
293
297
294
298
- void hsr_register_frame_in (struct hsr_node * node , enum hsr_dev_idx dev_idx )
295
+ void hsr_register_frame_in (struct hsr_node * node , struct hsr_port * port )
299
296
{
300
- if ((dev_idx < 0 ) || (dev_idx >= HSR_MAX_SLAVE )) {
301
- WARN_ONCE (1 , "%s: Invalid dev_idx (%d)\n" , __func__ , dev_idx );
302
- return ;
303
- }
304
- node -> time_in [dev_idx ] = jiffies ;
305
- node -> time_in_stale [dev_idx ] = false;
297
+ node -> time_in [port -> type ] = jiffies ;
298
+ node -> time_in_stale [port -> type ] = false;
306
299
}
307
300
308
301
@@ -314,52 +307,45 @@ void hsr_register_frame_in(struct hsr_node *node, enum hsr_dev_idx dev_idx)
314
307
* 0 otherwise, or
315
308
* negative error code on error
316
309
*/
317
- int hsr_register_frame_out (struct hsr_node * node , enum hsr_dev_idx dev_idx ,
310
+ int hsr_register_frame_out (struct hsr_node * node , struct hsr_port * port ,
318
311
struct sk_buff * skb )
319
312
{
320
313
struct hsr_ethhdr * hsr_ethhdr ;
321
314
u16 sequence_nr ;
322
315
323
- if ((dev_idx < 0 ) || (dev_idx >= HSR_MAX_DEV )) {
324
- WARN_ONCE (1 , "%s: Invalid dev_idx (%d)\n" , __func__ , dev_idx );
325
- return - EINVAL ;
326
- }
327
316
if (!skb_mac_header_was_set (skb )) {
328
317
WARN_ONCE (1 , "%s: Mac header not set\n" , __func__ );
329
318
return - EINVAL ;
330
319
}
331
320
hsr_ethhdr = (struct hsr_ethhdr * ) skb_mac_header (skb );
332
321
333
322
sequence_nr = ntohs (hsr_ethhdr -> hsr_tag .sequence_nr );
334
- if (seq_nr_before_or_eq (sequence_nr , node -> seq_out [dev_idx ]))
323
+ if (seq_nr_before_or_eq (sequence_nr , node -> seq_out [port -> type ]))
335
324
return 1 ;
336
325
337
- node -> seq_out [dev_idx ] = sequence_nr ;
326
+ node -> seq_out [port -> type ] = sequence_nr ;
338
327
return 0 ;
339
328
}
340
329
341
330
342
-
343
- static bool is_late ( struct hsr_node * node , enum hsr_dev_idx dev_idx )
331
+ static struct hsr_port * get_late_port ( struct hsr_priv * hsr ,
332
+ struct hsr_node * node )
344
333
{
345
- enum hsr_dev_idx other ;
346
-
347
- if (node -> time_in_stale [dev_idx ])
348
- return true;
349
-
350
- if (dev_idx == HSR_DEV_SLAVE_A )
351
- other = HSR_DEV_SLAVE_B ;
352
- else
353
- other = HSR_DEV_SLAVE_A ;
354
-
355
- if (node -> time_in_stale [other ])
356
- return false;
334
+ if (node -> time_in_stale [HSR_PT_SLAVE_A ])
335
+ return hsr_port_get_hsr (hsr , HSR_PT_SLAVE_A );
336
+ if (node -> time_in_stale [HSR_PT_SLAVE_B ])
337
+ return hsr_port_get_hsr (hsr , HSR_PT_SLAVE_B );
338
+
339
+ if (time_after (node -> time_in [HSR_PT_SLAVE_B ],
340
+ node -> time_in [HSR_PT_SLAVE_A ] +
341
+ msecs_to_jiffies (MAX_SLAVE_DIFF )))
342
+ return hsr_port_get_hsr (hsr , HSR_PT_SLAVE_A );
343
+ if (time_after (node -> time_in [HSR_PT_SLAVE_A ],
344
+ node -> time_in [HSR_PT_SLAVE_B ] +
345
+ msecs_to_jiffies (MAX_SLAVE_DIFF )))
346
+ return hsr_port_get_hsr (hsr , HSR_PT_SLAVE_B );
357
347
358
- if (time_after (node -> time_in [other ], node -> time_in [dev_idx ] +
359
- msecs_to_jiffies (MAX_SLAVE_DIFF )))
360
- return true;
361
-
362
- return false;
348
+ return NULL ;
363
349
}
364
350
365
351
@@ -370,6 +356,7 @@ void hsr_prune_nodes(unsigned long data)
370
356
{
371
357
struct hsr_priv * hsr ;
372
358
struct hsr_node * node ;
359
+ struct hsr_port * port ;
373
360
unsigned long timestamp ;
374
361
unsigned long time_a , time_b ;
375
362
@@ -378,35 +365,33 @@ void hsr_prune_nodes(unsigned long data)
378
365
rcu_read_lock ();
379
366
list_for_each_entry_rcu (node , & hsr -> node_db , mac_list ) {
380
367
/* Shorthand */
381
- time_a = node -> time_in [HSR_DEV_SLAVE_A ];
382
- time_b = node -> time_in [HSR_DEV_SLAVE_B ];
368
+ time_a = node -> time_in [HSR_PT_SLAVE_A ];
369
+ time_b = node -> time_in [HSR_PT_SLAVE_B ];
383
370
384
371
/* Check for timestamps old enough to risk wrap-around */
385
372
if (time_after (jiffies , time_a + MAX_JIFFY_OFFSET /2 ))
386
- node -> time_in_stale [HSR_DEV_SLAVE_A ] = true;
373
+ node -> time_in_stale [HSR_PT_SLAVE_A ] = true;
387
374
if (time_after (jiffies , time_b + MAX_JIFFY_OFFSET /2 ))
388
- node -> time_in_stale [HSR_DEV_SLAVE_B ] = true;
375
+ node -> time_in_stale [HSR_PT_SLAVE_B ] = true;
389
376
390
377
/* Get age of newest frame from node.
391
378
* At least one time_in is OK here; nodes get pruned long
392
379
* before both time_ins can get stale
393
380
*/
394
381
timestamp = time_a ;
395
- if (node -> time_in_stale [HSR_DEV_SLAVE_A ] ||
396
- (!node -> time_in_stale [HSR_DEV_SLAVE_B ] &&
382
+ if (node -> time_in_stale [HSR_PT_SLAVE_A ] ||
383
+ (!node -> time_in_stale [HSR_PT_SLAVE_B ] &&
397
384
time_after (time_b , time_a )))
398
385
timestamp = time_b ;
399
386
400
387
/* Warn of ring error only as long as we get frames at all */
401
388
if (time_is_after_jiffies (timestamp +
402
389
msecs_to_jiffies (1.5 * MAX_SLAVE_DIFF ))) {
403
-
404
- if (is_late (node , HSR_DEV_SLAVE_A ))
405
- hsr_nl_ringerror (hsr , node -> MacAddressA ,
406
- HSR_DEV_SLAVE_A );
407
- else if (is_late (node , HSR_DEV_SLAVE_B ))
408
- hsr_nl_ringerror (hsr , node -> MacAddressA ,
409
- HSR_DEV_SLAVE_B );
390
+ rcu_read_lock ();
391
+ port = get_late_port (hsr , node );
392
+ if (port != NULL )
393
+ hsr_nl_ringerror (hsr , node -> MacAddressA , port );
394
+ rcu_read_unlock ();
410
395
}
411
396
412
397
/* Prune old entries */
@@ -455,7 +440,7 @@ int hsr_get_node_data(struct hsr_priv *hsr,
455
440
u16 * if2_seq )
456
441
{
457
442
struct hsr_node * node ;
458
- struct net_device * slave ;
443
+ struct hsr_port * port ;
459
444
unsigned long tdiff ;
460
445
461
446
@@ -468,8 +453,8 @@ int hsr_get_node_data(struct hsr_priv *hsr,
468
453
469
454
ether_addr_copy (addr_b , node -> MacAddressB );
470
455
471
- tdiff = jiffies - node -> time_in [HSR_DEV_SLAVE_A ];
472
- if (node -> time_in_stale [HSR_DEV_SLAVE_A ])
456
+ tdiff = jiffies - node -> time_in [HSR_PT_SLAVE_A ];
457
+ if (node -> time_in_stale [HSR_PT_SLAVE_A ])
473
458
* if1_age = INT_MAX ;
474
459
#if HZ <= MSEC_PER_SEC
475
460
else if (tdiff > msecs_to_jiffies (INT_MAX ))
@@ -478,8 +463,8 @@ int hsr_get_node_data(struct hsr_priv *hsr,
478
463
else
479
464
* if1_age = jiffies_to_msecs (tdiff );
480
465
481
- tdiff = jiffies - node -> time_in [HSR_DEV_SLAVE_B ];
482
- if (node -> time_in_stale [HSR_DEV_SLAVE_B ])
466
+ tdiff = jiffies - node -> time_in [HSR_PT_SLAVE_B ];
467
+ if (node -> time_in_stale [HSR_PT_SLAVE_B ])
483
468
* if2_age = INT_MAX ;
484
469
#if HZ <= MSEC_PER_SEC
485
470
else if (tdiff > msecs_to_jiffies (INT_MAX ))
@@ -489,14 +474,15 @@ int hsr_get_node_data(struct hsr_priv *hsr,
489
474
* if2_age = jiffies_to_msecs (tdiff );
490
475
491
476
/* Present sequence numbers as if they were incoming on interface */
492
- * if1_seq = node -> seq_out [HSR_DEV_SLAVE_B ];
493
- * if2_seq = node -> seq_out [HSR_DEV_SLAVE_A ];
477
+ * if1_seq = node -> seq_out [HSR_PT_SLAVE_B ];
478
+ * if2_seq = node -> seq_out [HSR_PT_SLAVE_A ];
494
479
495
- slave = hsr -> slave [ node -> AddrB_if ];
496
- if (( node -> AddrB_if != HSR_DEV_NONE ) && slave )
497
- * addr_b_ifindex = slave -> ifindex ;
498
- else
480
+ if ( node -> AddrB_port != HSR_PT_NONE ) {
481
+ port = hsr_port_get_hsr ( hsr , node -> AddrB_port );
482
+ * addr_b_ifindex = port -> dev -> ifindex ;
483
+ } else {
499
484
* addr_b_ifindex = -1 ;
485
+ }
500
486
501
487
rcu_read_unlock ();
502
488
0 commit comments