aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorArvid Brodin <arvid.brodin@alten.se>2014-07-04 17:34:38 -0400
committerDavid S. Miller <davem@davemloft.net>2014-07-08 14:35:30 -0400
commit70ebe4a47185db15f3c55be9611a1a971237870b (patch)
tree53e0ba561d76df8ff281db8211f8e6d4792478cb /net
parentb8125404c242a6336eacaa54047b27cfd3fee68e (diff)
net/hsr: Better variable names and update of contact info.
Signed-off-by: Arvid Brodin <arvid.brodin@alten.se> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/hsr/hsr_device.c207
-rw-r--r--net/hsr/hsr_device.h6
-rw-r--r--net/hsr/hsr_framereg.c108
-rw-r--r--net/hsr/hsr_framereg.h36
-rw-r--r--net/hsr/hsr_main.c170
-rw-r--r--net/hsr/hsr_main.h20
-rw-r--r--net/hsr/hsr_netlink.c54
-rw-r--r--net/hsr/hsr_netlink.h8
8 files changed, 304 insertions, 305 deletions
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index e5302b7f7ca9..4dc2a4207ee2 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,7 +6,7 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 10 *
11 * This file contains device methods for creating, using and destroying 11 * This file contains device methods for creating, using and destroying
12 * virtual HSR devices. 12 * virtual HSR devices.
@@ -71,49 +71,49 @@ void hsr_set_carrier(struct net_device *hsr_dev, struct net_device *slave1,
71 71
72void hsr_check_announce(struct net_device *hsr_dev, int old_operstate) 72void hsr_check_announce(struct net_device *hsr_dev, int old_operstate)
73{ 73{
74 struct hsr_priv *hsr_priv; 74 struct hsr_priv *hsr;
75 75
76 hsr_priv = netdev_priv(hsr_dev); 76 hsr = netdev_priv(hsr_dev);
77 77
78 if ((hsr_dev->operstate == IF_OPER_UP) && (old_operstate != IF_OPER_UP)) { 78 if ((hsr_dev->operstate == IF_OPER_UP) && (old_operstate != IF_OPER_UP)) {
79 /* Went up */ 79 /* Went up */
80 hsr_priv->announce_count = 0; 80 hsr->announce_count = 0;
81 hsr_priv->announce_timer.expires = jiffies + 81 hsr->announce_timer.expires = jiffies +
82 msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL); 82 msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL);
83 add_timer(&hsr_priv->announce_timer); 83 add_timer(&hsr->announce_timer);
84 } 84 }
85 85
86 if ((hsr_dev->operstate != IF_OPER_UP) && (old_operstate == IF_OPER_UP)) 86 if ((hsr_dev->operstate != IF_OPER_UP) && (old_operstate == IF_OPER_UP))
87 /* Went down */ 87 /* Went down */
88 del_timer(&hsr_priv->announce_timer); 88 del_timer(&hsr->announce_timer);
89} 89}
90 90
91 91
92int hsr_get_max_mtu(struct hsr_priv *hsr_priv) 92int hsr_get_max_mtu(struct hsr_priv *hsr)
93{ 93{
94 int mtu_max; 94 int mtu_max;
95 95
96 if (hsr_priv->slave[0] && hsr_priv->slave[1]) 96 if (hsr->slave[0] && hsr->slave[1])
97 mtu_max = min(hsr_priv->slave[0]->mtu, hsr_priv->slave[1]->mtu); 97 mtu_max = min(hsr->slave[0]->mtu, hsr->slave[1]->mtu);
98 else if (hsr_priv->slave[0]) 98 else if (hsr->slave[0])
99 mtu_max = hsr_priv->slave[0]->mtu; 99 mtu_max = hsr->slave[0]->mtu;
100 else if (hsr_priv->slave[1]) 100 else if (hsr->slave[1])
101 mtu_max = hsr_priv->slave[1]->mtu; 101 mtu_max = hsr->slave[1]->mtu;
102 else 102 else
103 mtu_max = HSR_TAGLEN; 103 mtu_max = HSR_HLEN;
104 104
105 return mtu_max - HSR_TAGLEN; 105 return mtu_max - HSR_HLEN;
106} 106}
107 107
108static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu) 108static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu)
109{ 109{
110 struct hsr_priv *hsr_priv; 110 struct hsr_priv *hsr;
111 111
112 hsr_priv = netdev_priv(dev); 112 hsr = netdev_priv(dev);
113 113
114 if (new_mtu > hsr_get_max_mtu(hsr_priv)) { 114 if (new_mtu > hsr_get_max_mtu(hsr)) {
115 netdev_info(hsr_priv->dev, "A HSR master's MTU cannot be greater than the smallest MTU of its slaves minus the HSR Tag length (%d octets).\n", 115 netdev_info(hsr->dev, "A HSR master's MTU cannot be greater than the smallest MTU of its slaves minus the HSR Tag length (%d octets).\n",
116 HSR_TAGLEN); 116 HSR_HLEN);
117 return -EINVAL; 117 return -EINVAL;
118 } 118 }
119 119
@@ -124,19 +124,19 @@ static int hsr_dev_change_mtu(struct net_device *dev, int new_mtu)
124 124
125static int hsr_dev_open(struct net_device *dev) 125static int hsr_dev_open(struct net_device *dev)
126{ 126{
127 struct hsr_priv *hsr_priv; 127 struct hsr_priv *hsr;
128 int i; 128 int i;
129 char *slave_name; 129 char *slave_name;
130 130
131 hsr_priv = netdev_priv(dev); 131 hsr = netdev_priv(dev);
132 132
133 for (i = 0; i < HSR_MAX_SLAVE; i++) { 133 for (i = 0; i < HSR_MAX_SLAVE; i++) {
134 if (hsr_priv->slave[i]) 134 if (hsr->slave[i])
135 slave_name = hsr_priv->slave[i]->name; 135 slave_name = hsr->slave[i]->name;
136 else 136 else
137 slave_name = "null"; 137 slave_name = "null";
138 138
139 if (!is_slave_up(hsr_priv->slave[i])) 139 if (!is_slave_up(hsr->slave[i]))
140 netdev_warn(dev, "Slave %c (%s) is not up; please bring it up to get a working HSR network\n", 140 netdev_warn(dev, "Slave %c (%s) is not up; please bring it up to get a working HSR network\n",
141 'A' + i, slave_name); 141 'A' + i, slave_name);
142 } 142 }
@@ -156,7 +156,7 @@ static int hsr_dev_close(struct net_device *dev)
156} 156}
157 157
158 158
159static void hsr_fill_tag(struct hsr_ethhdr *hsr_ethhdr, struct hsr_priv *hsr_priv) 159static void hsr_fill_tag(struct hsr_ethhdr *hsr_ethhdr, struct hsr_priv *hsr)
160{ 160{
161 unsigned long irqflags; 161 unsigned long irqflags;
162 162
@@ -185,26 +185,26 @@ static void hsr_fill_tag(struct hsr_ethhdr *hsr_ethhdr, struct hsr_priv *hsr_pri
185 */ 185 */
186 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, 0); 186 set_hsr_tag_LSDU_size(&hsr_ethhdr->hsr_tag, 0);
187 187
188 spin_lock_irqsave(&hsr_priv->seqnr_lock, irqflags); 188 spin_lock_irqsave(&hsr->seqnr_lock, irqflags);
189 hsr_ethhdr->hsr_tag.sequence_nr = htons(hsr_priv->sequence_nr); 189 hsr_ethhdr->hsr_tag.sequence_nr = htons(hsr->sequence_nr);
190 hsr_priv->sequence_nr++; 190 hsr->sequence_nr++;
191 spin_unlock_irqrestore(&hsr_priv->seqnr_lock, irqflags); 191 spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags);
192 192
193 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto; 193 hsr_ethhdr->hsr_tag.encap_proto = hsr_ethhdr->ethhdr.h_proto;
194 194
195 hsr_ethhdr->ethhdr.h_proto = htons(ETH_P_PRP); 195 hsr_ethhdr->ethhdr.h_proto = htons(ETH_P_PRP);
196} 196}
197 197
198static int slave_xmit(struct sk_buff *skb, struct hsr_priv *hsr_priv, 198static int slave_xmit(struct sk_buff *skb, struct hsr_priv *hsr,
199 enum hsr_dev_idx dev_idx) 199 enum hsr_dev_idx dev_idx)
200{ 200{
201 struct hsr_ethhdr *hsr_ethhdr; 201 struct hsr_ethhdr *hsr_ethhdr;
202 202
203 hsr_ethhdr = (struct hsr_ethhdr *) skb->data; 203 hsr_ethhdr = (struct hsr_ethhdr *) skb->data;
204 204
205 skb->dev = hsr_priv->slave[dev_idx]; 205 skb->dev = hsr->slave[dev_idx];
206 206
207 hsr_addr_subst_dest(hsr_priv, &hsr_ethhdr->ethhdr, dev_idx); 207 hsr_addr_subst_dest(hsr, &hsr_ethhdr->ethhdr, dev_idx);
208 208
209 /* Address substitution (IEC62439-3 pp 26, 50): replace mac 209 /* Address substitution (IEC62439-3 pp 26, 50): replace mac
210 * address of outgoing frame with that of the outgoing slave's. 210 * address of outgoing frame with that of the outgoing slave's.
@@ -217,36 +217,36 @@ static int slave_xmit(struct sk_buff *skb, struct hsr_priv *hsr_priv,
217 217
218static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev) 218static int hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
219{ 219{
220 struct hsr_priv *hsr_priv; 220 struct hsr_priv *hsr;
221 struct hsr_ethhdr *hsr_ethhdr; 221 struct hsr_ethhdr *hsr_ethhdr;
222 struct sk_buff *skb2; 222 struct sk_buff *skb2;
223 int res1, res2; 223 int res1, res2;
224 224
225 hsr_priv = netdev_priv(dev); 225 hsr = netdev_priv(dev);
226 hsr_ethhdr = (struct hsr_ethhdr *) skb->data; 226 hsr_ethhdr = (struct hsr_ethhdr *) skb->data;
227 227
228 if ((skb->protocol != htons(ETH_P_PRP)) || 228 if ((skb->protocol != htons(ETH_P_PRP)) ||
229 (hsr_ethhdr->ethhdr.h_proto != htons(ETH_P_PRP))) { 229 (hsr_ethhdr->ethhdr.h_proto != htons(ETH_P_PRP))) {
230 hsr_fill_tag(hsr_ethhdr, hsr_priv); 230 hsr_fill_tag(hsr_ethhdr, hsr);
231 skb->protocol = htons(ETH_P_PRP); 231 skb->protocol = htons(ETH_P_PRP);
232 } 232 }
233 233
234 skb2 = pskb_copy(skb, GFP_ATOMIC); 234 skb2 = pskb_copy(skb, GFP_ATOMIC);
235 235
236 res1 = NET_XMIT_DROP; 236 res1 = NET_XMIT_DROP;
237 if (likely(hsr_priv->slave[HSR_DEV_SLAVE_A])) 237 if (likely(hsr->slave[HSR_DEV_SLAVE_A]))
238 res1 = slave_xmit(skb, hsr_priv, HSR_DEV_SLAVE_A); 238 res1 = slave_xmit(skb, hsr, HSR_DEV_SLAVE_A);
239 239
240 res2 = NET_XMIT_DROP; 240 res2 = NET_XMIT_DROP;
241 if (likely(skb2 && hsr_priv->slave[HSR_DEV_SLAVE_B])) 241 if (likely(skb2 && hsr->slave[HSR_DEV_SLAVE_B]))
242 res2 = slave_xmit(skb2, hsr_priv, HSR_DEV_SLAVE_B); 242 res2 = slave_xmit(skb2, hsr, HSR_DEV_SLAVE_B);
243 243
244 if (likely(res1 == NET_XMIT_SUCCESS || res1 == NET_XMIT_CN || 244 if (likely(res1 == NET_XMIT_SUCCESS || res1 == NET_XMIT_CN ||
245 res2 == NET_XMIT_SUCCESS || res2 == NET_XMIT_CN)) { 245 res2 == NET_XMIT_SUCCESS || res2 == NET_XMIT_CN)) {
246 hsr_priv->dev->stats.tx_packets++; 246 hsr->dev->stats.tx_packets++;
247 hsr_priv->dev->stats.tx_bytes += skb->len; 247 hsr->dev->stats.tx_bytes += skb->len;
248 } else { 248 } else {
249 hsr_priv->dev->stats.tx_dropped++; 249 hsr->dev->stats.tx_dropped++;
250 } 250 }
251 251
252 return NETDEV_TX_OK; 252 return NETDEV_TX_OK;
@@ -262,21 +262,21 @@ static int hsr_header_create(struct sk_buff *skb, struct net_device *dev,
262 /* Make room for the HSR tag now. We will fill it in later (in 262 /* Make room for the HSR tag now. We will fill it in later (in
263 * hsr_dev_xmit) 263 * hsr_dev_xmit)
264 */ 264 */
265 if (skb_headroom(skb) < HSR_TAGLEN + ETH_HLEN) 265 if (skb_headroom(skb) < HSR_HLEN + ETH_HLEN)
266 return -ENOBUFS; 266 return -ENOBUFS;
267 skb_push(skb, HSR_TAGLEN); 267 skb_push(skb, HSR_HLEN);
268 268
269 /* To allow VLAN/HSR combos we should probably use 269 /* To allow VLAN/HSR combos we should probably use
270 * res = dev_hard_header(skb, dev, type, daddr, saddr, len + HSR_TAGLEN); 270 * res = dev_hard_header(skb, dev, type, daddr, saddr, len + HSR_HLEN);
271 * here instead. It would require other changes too, though - e.g. 271 * here instead. It would require other changes too, though - e.g.
272 * separate headers for each slave etc... 272 * separate headers for each slave etc...
273 */ 273 */
274 res = eth_header(skb, dev, type, daddr, saddr, len + HSR_TAGLEN); 274 res = eth_header(skb, dev, type, daddr, saddr, len + HSR_HLEN);
275 if (res <= 0) 275 if (res <= 0)
276 return res; 276 return res;
277 skb_reset_mac_header(skb); 277 skb_reset_mac_header(skb);
278 278
279 return res + HSR_TAGLEN; 279 return res + HSR_HLEN;
280} 280}
281 281
282 282
@@ -291,7 +291,7 @@ static const struct header_ops hsr_header_ops = {
291 */ 291 */
292static int hsr_pad(int size) 292static int hsr_pad(int size)
293{ 293{
294 const int min_size = ETH_ZLEN - HSR_TAGLEN - ETH_HLEN; 294 const int min_size = ETH_ZLEN - HSR_HLEN - ETH_HLEN;
295 295
296 if (size >= min_size) 296 if (size >= min_size)
297 return size; 297 return size;
@@ -300,7 +300,7 @@ static int hsr_pad(int size)
300 300
301static void send_hsr_supervision_frame(struct net_device *hsr_dev, u8 type) 301static void send_hsr_supervision_frame(struct net_device *hsr_dev, u8 type)
302{ 302{
303 struct hsr_priv *hsr_priv; 303 struct hsr_priv *hsr;
304 struct sk_buff *skb; 304 struct sk_buff *skb;
305 int hlen, tlen; 305 int hlen, tlen;
306 struct hsr_sup_tag *hsr_stag; 306 struct hsr_sup_tag *hsr_stag;
@@ -315,7 +315,7 @@ static void send_hsr_supervision_frame(struct net_device *hsr_dev, u8 type)
315 if (skb == NULL) 315 if (skb == NULL)
316 return; 316 return;
317 317
318 hsr_priv = netdev_priv(hsr_dev); 318 hsr = netdev_priv(hsr_dev);
319 319
320 skb_reserve(skb, hlen); 320 skb_reserve(skb, hlen);
321 321
@@ -324,7 +324,7 @@ static void send_hsr_supervision_frame(struct net_device *hsr_dev, u8 type)
324 skb->priority = TC_PRIO_CONTROL; 324 skb->priority = TC_PRIO_CONTROL;
325 325
326 if (dev_hard_header(skb, skb->dev, ETH_P_PRP, 326 if (dev_hard_header(skb, skb->dev, ETH_P_PRP,
327 hsr_priv->sup_multicast_addr, 327 hsr->sup_multicast_addr,
328 skb->dev->dev_addr, skb->len) < 0) 328 skb->dev->dev_addr, skb->len) < 0)
329 goto out; 329 goto out;
330 330
@@ -334,10 +334,10 @@ static void send_hsr_supervision_frame(struct net_device *hsr_dev, u8 type)
334 set_hsr_stag_path(hsr_stag, 0xf); 334 set_hsr_stag_path(hsr_stag, 0xf);
335 set_hsr_stag_HSR_Ver(hsr_stag, 0); 335 set_hsr_stag_HSR_Ver(hsr_stag, 0);
336 336
337 spin_lock_irqsave(&hsr_priv->seqnr_lock, irqflags); 337 spin_lock_irqsave(&hsr->seqnr_lock, irqflags);
338 hsr_stag->sequence_nr = htons(hsr_priv->sequence_nr); 338 hsr_stag->sequence_nr = htons(hsr->sequence_nr);
339 hsr_priv->sequence_nr++; 339 hsr->sequence_nr++;
340 spin_unlock_irqrestore(&hsr_priv->seqnr_lock, irqflags); 340 spin_unlock_irqrestore(&hsr->seqnr_lock, irqflags);
341 341
342 hsr_stag->HSR_TLV_Type = type; 342 hsr_stag->HSR_TLV_Type = type;
343 hsr_stag->HSR_TLV_Length = 12; 343 hsr_stag->HSR_TLV_Length = 12;
@@ -360,48 +360,48 @@ out:
360 */ 360 */
361static void hsr_announce(unsigned long data) 361static void hsr_announce(unsigned long data)
362{ 362{
363 struct hsr_priv *hsr_priv; 363 struct hsr_priv *hsr;
364 364
365 hsr_priv = (struct hsr_priv *) data; 365 hsr = (struct hsr_priv *) data;
366 366
367 if (hsr_priv->announce_count < 3) { 367 if (hsr->announce_count < 3) {
368 send_hsr_supervision_frame(hsr_priv->dev, HSR_TLV_ANNOUNCE); 368 send_hsr_supervision_frame(hsr->dev, HSR_TLV_ANNOUNCE);
369 hsr_priv->announce_count++; 369 hsr->announce_count++;
370 } else { 370 } else {
371 send_hsr_supervision_frame(hsr_priv->dev, HSR_TLV_LIFE_CHECK); 371 send_hsr_supervision_frame(hsr->dev, HSR_TLV_LIFE_CHECK);
372 } 372 }
373 373
374 if (hsr_priv->announce_count < 3) 374 if (hsr->announce_count < 3)
375 hsr_priv->announce_timer.expires = jiffies + 375 hsr->announce_timer.expires = jiffies +
376 msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL); 376 msecs_to_jiffies(HSR_ANNOUNCE_INTERVAL);
377 else 377 else
378 hsr_priv->announce_timer.expires = jiffies + 378 hsr->announce_timer.expires = jiffies +
379 msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL); 379 msecs_to_jiffies(HSR_LIFE_CHECK_INTERVAL);
380 380
381 if (is_admin_up(hsr_priv->dev)) 381 if (is_admin_up(hsr->dev))
382 add_timer(&hsr_priv->announce_timer); 382 add_timer(&hsr->announce_timer);
383} 383}
384 384
385 385
386static void restore_slaves(struct net_device *hsr_dev) 386static void restore_slaves(struct net_device *hsr_dev)
387{ 387{
388 struct hsr_priv *hsr_priv; 388 struct hsr_priv *hsr;
389 int i; 389 int i;
390 int res; 390 int res;
391 391
392 hsr_priv = netdev_priv(hsr_dev); 392 hsr = netdev_priv(hsr_dev);
393 393
394 rtnl_lock(); 394 rtnl_lock();
395 395
396 /* Restore promiscuity */ 396 /* Restore promiscuity */
397 for (i = 0; i < HSR_MAX_SLAVE; i++) { 397 for (i = 0; i < HSR_MAX_SLAVE; i++) {
398 if (!hsr_priv->slave[i]) 398 if (!hsr->slave[i])
399 continue; 399 continue;
400 res = dev_set_promiscuity(hsr_priv->slave[i], -1); 400 res = dev_set_promiscuity(hsr->slave[i], -1);
401 if (res) 401 if (res)
402 netdev_info(hsr_dev, 402 netdev_info(hsr_dev,
403 "Cannot restore slave promiscuity (%s, %d)\n", 403 "Cannot restore slave promiscuity (%s, %d)\n",
404 hsr_priv->slave[i]->name, res); 404 hsr->slave[i]->name, res);
405 } 405 }
406 406
407 rtnl_unlock(); 407 rtnl_unlock();
@@ -409,10 +409,10 @@ static void restore_slaves(struct net_device *hsr_dev)
409 409
410static void reclaim_hsr_dev(struct rcu_head *rh) 410static void reclaim_hsr_dev(struct rcu_head *rh)
411{ 411{
412 struct hsr_priv *hsr_priv; 412 struct hsr_priv *hsr;
413 413
414 hsr_priv = container_of(rh, struct hsr_priv, rcu_head); 414 hsr = container_of(rh, struct hsr_priv, rcu_head);
415 free_netdev(hsr_priv->dev); 415 free_netdev(hsr->dev);
416} 416}
417 417
418 418
@@ -421,14 +421,14 @@ static void reclaim_hsr_dev(struct rcu_head *rh)
421 */ 421 */
422static void hsr_dev_destroy(struct net_device *hsr_dev) 422static void hsr_dev_destroy(struct net_device *hsr_dev)
423{ 423{
424 struct hsr_priv *hsr_priv; 424 struct hsr_priv *hsr;
425 425
426 hsr_priv = netdev_priv(hsr_dev); 426 hsr = netdev_priv(hsr_dev);
427 427
428 del_timer(&hsr_priv->announce_timer); 428 del_timer(&hsr->announce_timer);
429 unregister_hsr_master(hsr_priv); /* calls list_del_rcu on hsr_priv */ 429 unregister_hsr_master(hsr); /* calls list_del_rcu on hsr */
430 restore_slaves(hsr_dev); 430 restore_slaves(hsr_dev);
431 call_rcu(&hsr_priv->rcu_head, reclaim_hsr_dev); /* reclaim hsr_priv */ 431 call_rcu(&hsr->rcu_head, reclaim_hsr_dev); /* reclaim hsr */
432} 432}
433 433
434static const struct net_device_ops hsr_device_ops = { 434static const struct net_device_ops hsr_device_ops = {
@@ -500,27 +500,27 @@ static const unsigned char def_multicast_addr[ETH_ALEN] __aligned(2) = {
500int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2], 500int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
501 unsigned char multicast_spec) 501 unsigned char multicast_spec)
502{ 502{
503 struct hsr_priv *hsr_priv; 503 struct hsr_priv *hsr;
504 int i; 504 int i;
505 int res; 505 int res;
506 506
507 hsr_priv = netdev_priv(hsr_dev); 507 hsr = netdev_priv(hsr_dev);
508 hsr_priv->dev = hsr_dev; 508 hsr->dev = hsr_dev;
509 INIT_LIST_HEAD(&hsr_priv->node_db); 509 INIT_LIST_HEAD(&hsr->node_db);
510 INIT_LIST_HEAD(&hsr_priv->self_node_db); 510 INIT_LIST_HEAD(&hsr->self_node_db);
511 for (i = 0; i < HSR_MAX_SLAVE; i++) 511 for (i = 0; i < HSR_MAX_SLAVE; i++)
512 hsr_priv->slave[i] = slave[i]; 512 hsr->slave[i] = slave[i];
513 513
514 spin_lock_init(&hsr_priv->seqnr_lock); 514 spin_lock_init(&hsr->seqnr_lock);
515 /* Overflow soon to find bugs easier: */ 515 /* Overflow soon to find bugs easier: */
516 hsr_priv->sequence_nr = USHRT_MAX - 1024; 516 hsr->sequence_nr = USHRT_MAX - 1024;
517 517
518 init_timer(&hsr_priv->announce_timer); 518 init_timer(&hsr->announce_timer);
519 hsr_priv->announce_timer.function = hsr_announce; 519 hsr->announce_timer.function = hsr_announce;
520 hsr_priv->announce_timer.data = (unsigned long) hsr_priv; 520 hsr->announce_timer.data = (unsigned long) hsr;
521 521
522 ether_addr_copy(hsr_priv->sup_multicast_addr, def_multicast_addr); 522 ether_addr_copy(hsr->sup_multicast_addr, def_multicast_addr);
523 hsr_priv->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec; 523 hsr->sup_multicast_addr[ETH_ALEN - 1] = multicast_spec;
524 524
525/* FIXME: should I modify the value of these? 525/* FIXME: should I modify the value of these?
526 * 526 *
@@ -547,20 +547,20 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
547 hsr_dev->features |= NETIF_F_VLAN_CHALLENGED; 547 hsr_dev->features |= NETIF_F_VLAN_CHALLENGED;
548 548
549 /* Set hsr_dev's MAC address to that of mac_slave1 */ 549 /* Set hsr_dev's MAC address to that of mac_slave1 */
550 ether_addr_copy(hsr_dev->dev_addr, hsr_priv->slave[0]->dev_addr); 550 ether_addr_copy(hsr_dev->dev_addr, hsr->slave[0]->dev_addr);
551 551
552 /* Set required header length */ 552 /* Set required header length */
553 for (i = 0; i < HSR_MAX_SLAVE; i++) { 553 for (i = 0; i < HSR_MAX_SLAVE; i++) {
554 if (slave[i]->hard_header_len + HSR_TAGLEN > 554 if (slave[i]->hard_header_len + HSR_HLEN >
555 hsr_dev->hard_header_len) 555 hsr_dev->hard_header_len)
556 hsr_dev->hard_header_len = 556 hsr_dev->hard_header_len =
557 slave[i]->hard_header_len + HSR_TAGLEN; 557 slave[i]->hard_header_len + HSR_HLEN;
558 } 558 }
559 559
560 /* MTU */ 560 /* MTU */
561 for (i = 0; i < HSR_MAX_SLAVE; i++) 561 for (i = 0; i < HSR_MAX_SLAVE; i++)
562 if (slave[i]->mtu - HSR_TAGLEN < hsr_dev->mtu) 562 if (slave[i]->mtu - HSR_HLEN < hsr_dev->mtu)
563 hsr_dev->mtu = slave[i]->mtu - HSR_TAGLEN; 563 hsr_dev->mtu = slave[i]->mtu - HSR_HLEN;
564 564
565 /* Make sure the 1st call to netif_carrier_on() gets through */ 565 /* Make sure the 1st call to netif_carrier_on() gets through */
566 netif_carrier_off(hsr_dev); 566 netif_carrier_off(hsr_dev);
@@ -576,9 +576,8 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
576 } 576 }
577 577
578 /* Make sure we recognize frames from ourselves in hsr_rcv() */ 578 /* Make sure we recognize frames from ourselves in hsr_rcv() */
579 res = hsr_create_self_node(&hsr_priv->self_node_db, 579 res = hsr_create_self_node(&hsr->self_node_db, hsr_dev->dev_addr,
580 hsr_dev->dev_addr, 580 hsr->slave[1]->dev_addr);
581 hsr_priv->slave[1]->dev_addr);
582 if (res < 0) 581 if (res < 0)
583 goto fail; 582 goto fail;
584 583
@@ -586,7 +585,7 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
586 if (res) 585 if (res)
587 goto fail; 586 goto fail;
588 587
589 register_hsr_master(hsr_priv); 588 register_hsr_master(hsr);
590 589
591 return 0; 590 return 0;
592 591
diff --git a/net/hsr/hsr_device.h b/net/hsr/hsr_device.h
index 2c7148e73914..feb744f90f3d 100644
--- a/net/hsr/hsr_device.h
+++ b/net/hsr/hsr_device.h
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,7 +6,7 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 10 */
11 11
12#ifndef __HSR_DEVICE_H 12#ifndef __HSR_DEVICE_H
@@ -24,6 +24,6 @@ void hsr_set_carrier(struct net_device *hsr_dev, struct net_device *slave1,
24 struct net_device *slave2); 24 struct net_device *slave2);
25void hsr_check_announce(struct net_device *hsr_dev, int old_operstate); 25void hsr_check_announce(struct net_device *hsr_dev, int old_operstate);
26bool is_hsr_master(struct net_device *dev); 26bool is_hsr_master(struct net_device *dev);
27int hsr_get_max_mtu(struct hsr_priv *hsr_priv); 27int hsr_get_max_mtu(struct hsr_priv *hsr);
28 28
29#endif /* __HSR_DEVICE_H */ 29#endif /* __HSR_DEVICE_H */
diff --git a/net/hsr/hsr_framereg.c b/net/hsr/hsr_framereg.c
index 83e58449366a..b419edbd7012 100644
--- a/net/hsr/hsr_framereg.c
+++ b/net/hsr/hsr_framereg.c
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,7 +6,7 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 10 *
11 * The HSR spec says never to forward the same frame twice on the same 11 * The HSR spec says never to forward the same frame twice on the same
12 * interface. A frame is identified by its source MAC address and its HSR 12 * interface. A frame is identified by its source MAC address and its HSR
@@ -23,17 +23,17 @@
23#include "hsr_netlink.h" 23#include "hsr_netlink.h"
24 24
25 25
26struct node_entry { 26struct hsr_node {
27 struct list_head mac_list; 27 struct list_head mac_list;
28 unsigned char MacAddressA[ETH_ALEN]; 28 unsigned char MacAddressA[ETH_ALEN];
29 unsigned char MacAddressB[ETH_ALEN]; 29 unsigned char MacAddressB[ETH_ALEN];
30 enum hsr_dev_idx AddrB_if; /* The local slave through which AddrB 30 enum hsr_dev_idx AddrB_if;/* The local slave through which AddrB
31 * frames are received from this node 31 * frames are received from this node
32 */ 32 */
33 unsigned long time_in[HSR_MAX_SLAVE]; 33 unsigned long time_in[HSR_MAX_SLAVE];
34 bool time_in_stale[HSR_MAX_SLAVE]; 34 bool time_in_stale[HSR_MAX_SLAVE];
35 u16 seq_out[HSR_MAX_DEV]; 35 u16 seq_out[HSR_MAX_DEV];
36 struct rcu_head rcu_head; 36 struct rcu_head rcu_head;
37}; 37};
38 38
39/* TODO: use hash lists for mac addresses (linux/jhash.h)? */ 39/* TODO: use hash lists for mac addresses (linux/jhash.h)? */
@@ -42,10 +42,10 @@ struct node_entry {
42 42
43/* Search for mac entry. Caller must hold rcu read lock. 43/* Search for mac entry. Caller must hold rcu read lock.
44 */ 44 */
45static struct node_entry *find_node_by_AddrA(struct list_head *node_db, 45static struct hsr_node *find_node_by_AddrA(struct list_head *node_db,
46 const unsigned char addr[ETH_ALEN]) 46 const unsigned char addr[ETH_ALEN])
47{ 47{
48 struct node_entry *node; 48 struct hsr_node *node;
49 49
50 list_for_each_entry_rcu(node, node_db, mac_list) { 50 list_for_each_entry_rcu(node, node_db, mac_list) {
51 if (ether_addr_equal(node->MacAddressA, addr)) 51 if (ether_addr_equal(node->MacAddressA, addr))
@@ -58,10 +58,10 @@ static struct node_entry *find_node_by_AddrA(struct list_head *node_db,
58 58
59/* Search for mac entry. Caller must hold rcu read lock. 59/* Search for mac entry. Caller must hold rcu read lock.
60 */ 60 */
61static struct node_entry *find_node_by_AddrB(struct list_head *node_db, 61static struct hsr_node *find_node_by_AddrB(struct list_head *node_db,
62 const unsigned char addr[ETH_ALEN]) 62 const unsigned char addr[ETH_ALEN])
63{ 63{
64 struct node_entry *node; 64 struct hsr_node *node;
65 65
66 list_for_each_entry_rcu(node, node_db, mac_list) { 66 list_for_each_entry_rcu(node, node_db, mac_list) {
67 if (ether_addr_equal(node->MacAddressB, addr)) 67 if (ether_addr_equal(node->MacAddressB, addr))
@@ -74,9 +74,9 @@ static struct node_entry *find_node_by_AddrB(struct list_head *node_db,
74 74
75/* Search for mac entry. Caller must hold rcu read lock. 75/* Search for mac entry. Caller must hold rcu read lock.
76 */ 76 */
77struct node_entry *hsr_find_node(struct list_head *node_db, struct sk_buff *skb) 77struct hsr_node *hsr_find_node(struct list_head *node_db, struct sk_buff *skb)
78{ 78{
79 struct node_entry *node; 79 struct hsr_node *node;
80 struct ethhdr *ethhdr; 80 struct ethhdr *ethhdr;
81 81
82 if (!skb_mac_header_was_set(skb)) 82 if (!skb_mac_header_was_set(skb))
@@ -102,7 +102,7 @@ int hsr_create_self_node(struct list_head *self_node_db,
102 unsigned char addr_a[ETH_ALEN], 102 unsigned char addr_a[ETH_ALEN],
103 unsigned char addr_b[ETH_ALEN]) 103 unsigned char addr_b[ETH_ALEN])
104{ 104{
105 struct node_entry *node, *oldnode; 105 struct hsr_node *node, *oldnode;
106 106
107 node = kmalloc(sizeof(*node), GFP_KERNEL); 107 node = kmalloc(sizeof(*node), GFP_KERNEL);
108 if (!node) 108 if (!node)
@@ -113,7 +113,7 @@ int hsr_create_self_node(struct list_head *self_node_db,
113 113
114 rcu_read_lock(); 114 rcu_read_lock();
115 oldnode = list_first_or_null_rcu(self_node_db, 115 oldnode = list_first_or_null_rcu(self_node_db,
116 struct node_entry, mac_list); 116 struct hsr_node, mac_list);
117 if (oldnode) { 117 if (oldnode) {
118 list_replace_rcu(&oldnode->mac_list, &node->mac_list); 118 list_replace_rcu(&oldnode->mac_list, &node->mac_list);
119 rcu_read_unlock(); 119 rcu_read_unlock();
@@ -154,10 +154,10 @@ int hsr_create_self_node(struct list_head *self_node_db,
154 * We also need to detect if the sender's SlaveA and SlaveB cables have been 154 * We also need to detect if the sender's SlaveA and SlaveB cables have been
155 * swapped. 155 * swapped.
156 */ 156 */
157struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv, 157struct hsr_node *hsr_merge_node(struct hsr_priv *hsr,
158 struct node_entry *node, 158 struct hsr_node *node,
159 struct sk_buff *skb, 159 struct sk_buff *skb,
160 enum hsr_dev_idx dev_idx) 160 enum hsr_dev_idx dev_idx)
161{ 161{
162 struct hsr_sup_payload *hsr_sp; 162 struct hsr_sup_payload *hsr_sp;
163 struct hsr_ethhdr_sp *hsr_ethsup; 163 struct hsr_ethhdr_sp *hsr_ethsup;
@@ -194,7 +194,7 @@ struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
194 if (node) 194 if (node)
195 return node; 195 return node;
196 196
197 node = find_node_by_AddrA(&hsr_priv->node_db, hsr_sp->MacAddressA); 197 node = find_node_by_AddrA(&hsr->node_db, hsr_sp->MacAddressA);
198 if (node) { 198 if (node) {
199 /* Node is known, but frame was received from an unknown 199 /* Node is known, but frame was received from an unknown
200 * address. Node is PICS_SUBS capable; merge its AddrB. 200 * address. Node is PICS_SUBS capable; merge its AddrB.
@@ -224,7 +224,7 @@ struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
224 for (i = 0; i < HSR_MAX_DEV; i++) 224 for (i = 0; i < HSR_MAX_DEV; i++)
225 node->seq_out[i] = ntohs(hsr_ethsup->hsr_sup.sequence_nr) - 1; 225 node->seq_out[i] = ntohs(hsr_ethsup->hsr_sup.sequence_nr) - 1;
226 226
227 list_add_tail_rcu(&node->mac_list, &hsr_priv->node_db); 227 list_add_tail_rcu(&node->mac_list, &hsr->node_db);
228 228
229 return node; 229 return node;
230} 230}
@@ -236,10 +236,10 @@ struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv,
236 * address with that node's "official" address (MacAddressA) so that upper 236 * address with that node's "official" address (MacAddressA) so that upper
237 * layers recognize where it came from. 237 * layers recognize where it came from.
238 */ 238 */
239void hsr_addr_subst_source(struct hsr_priv *hsr_priv, struct sk_buff *skb) 239void hsr_addr_subst_source(struct hsr_priv *hsr, struct sk_buff *skb)
240{ 240{
241 struct ethhdr *ethhdr; 241 struct ethhdr *ethhdr;
242 struct node_entry *node; 242 struct hsr_node *node;
243 243
244 if (!skb_mac_header_was_set(skb)) { 244 if (!skb_mac_header_was_set(skb)) {
245 WARN_ONCE(1, "%s: Mac header not set\n", __func__); 245 WARN_ONCE(1, "%s: Mac header not set\n", __func__);
@@ -248,7 +248,7 @@ void hsr_addr_subst_source(struct hsr_priv *hsr_priv, struct sk_buff *skb)
248 ethhdr = (struct ethhdr *) skb_mac_header(skb); 248 ethhdr = (struct ethhdr *) skb_mac_header(skb);
249 249
250 rcu_read_lock(); 250 rcu_read_lock();
251 node = find_node_by_AddrB(&hsr_priv->node_db, ethhdr->h_source); 251 node = find_node_by_AddrB(&hsr->node_db, ethhdr->h_source);
252 if (node) 252 if (node)
253 ether_addr_copy(ethhdr->h_source, node->MacAddressA); 253 ether_addr_copy(ethhdr->h_source, node->MacAddressA);
254 rcu_read_unlock(); 254 rcu_read_unlock();
@@ -264,13 +264,13 @@ void hsr_addr_subst_source(struct hsr_priv *hsr_priv, struct sk_buff *skb)
264 * This is needed to keep the packets flowing through switches that learn on 264 * This is needed to keep the packets flowing through switches that learn on
265 * which "side" the different interfaces are. 265 * which "side" the different interfaces are.
266 */ 266 */
267void hsr_addr_subst_dest(struct hsr_priv *hsr_priv, struct ethhdr *ethhdr, 267void hsr_addr_subst_dest(struct hsr_priv *hsr, struct ethhdr *ethhdr,
268 enum hsr_dev_idx dev_idx) 268 enum hsr_dev_idx dev_idx)
269{ 269{
270 struct node_entry *node; 270 struct hsr_node *node;
271 271
272 rcu_read_lock(); 272 rcu_read_lock();
273 node = find_node_by_AddrA(&hsr_priv->node_db, ethhdr->h_dest); 273 node = find_node_by_AddrA(&hsr->node_db, ethhdr->h_dest);
274 if (node && (node->AddrB_if == dev_idx)) 274 if (node && (node->AddrB_if == dev_idx))
275 ether_addr_copy(ethhdr->h_dest, node->MacAddressB); 275 ether_addr_copy(ethhdr->h_dest, node->MacAddressB);
276 rcu_read_unlock(); 276 rcu_read_unlock();
@@ -295,7 +295,7 @@ static bool seq_nr_after(u16 a, u16 b)
295#define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b))) 295#define seq_nr_before_or_eq(a, b) (!seq_nr_after((a), (b)))
296 296
297 297
298void hsr_register_frame_in(struct node_entry *node, enum hsr_dev_idx dev_idx) 298void hsr_register_frame_in(struct hsr_node *node, enum hsr_dev_idx dev_idx)
299{ 299{
300 if ((dev_idx < 0) || (dev_idx >= HSR_MAX_SLAVE)) { 300 if ((dev_idx < 0) || (dev_idx >= HSR_MAX_SLAVE)) {
301 WARN_ONCE(1, "%s: Invalid dev_idx (%d)\n", __func__, dev_idx); 301 WARN_ONCE(1, "%s: Invalid dev_idx (%d)\n", __func__, dev_idx);
@@ -314,7 +314,7 @@ void hsr_register_frame_in(struct node_entry *node, enum hsr_dev_idx dev_idx)
314 * 0 otherwise, or 314 * 0 otherwise, or
315 * negative error code on error 315 * negative error code on error
316 */ 316 */
317int hsr_register_frame_out(struct node_entry *node, enum hsr_dev_idx dev_idx, 317int hsr_register_frame_out(struct hsr_node *node, enum hsr_dev_idx dev_idx,
318 struct sk_buff *skb) 318 struct sk_buff *skb)
319{ 319{
320 struct hsr_ethhdr *hsr_ethhdr; 320 struct hsr_ethhdr *hsr_ethhdr;
@@ -340,7 +340,7 @@ int hsr_register_frame_out(struct node_entry *node, enum hsr_dev_idx dev_idx,
340 340
341 341
342 342
343static bool is_late(struct node_entry *node, enum hsr_dev_idx dev_idx) 343static bool is_late(struct hsr_node *node, enum hsr_dev_idx dev_idx)
344{ 344{
345 enum hsr_dev_idx other; 345 enum hsr_dev_idx other;
346 346
@@ -366,14 +366,14 @@ static bool is_late(struct node_entry *node, enum hsr_dev_idx dev_idx)
366/* Remove stale sequence_nr records. Called by timer every 366/* Remove stale sequence_nr records. Called by timer every
367 * HSR_LIFE_CHECK_INTERVAL (two seconds or so). 367 * HSR_LIFE_CHECK_INTERVAL (two seconds or so).
368 */ 368 */
369void hsr_prune_nodes(struct hsr_priv *hsr_priv) 369void hsr_prune_nodes(struct hsr_priv *hsr)
370{ 370{
371 struct node_entry *node; 371 struct hsr_node *node;
372 unsigned long timestamp; 372 unsigned long timestamp;
373 unsigned long time_a, time_b; 373 unsigned long time_a, time_b;
374 374
375 rcu_read_lock(); 375 rcu_read_lock();
376 list_for_each_entry_rcu(node, &hsr_priv->node_db, mac_list) { 376 list_for_each_entry_rcu(node, &hsr->node_db, mac_list) {
377 /* Shorthand */ 377 /* Shorthand */
378 time_a = node->time_in[HSR_DEV_SLAVE_A]; 378 time_a = node->time_in[HSR_DEV_SLAVE_A];
379 time_b = node->time_in[HSR_DEV_SLAVE_B]; 379 time_b = node->time_in[HSR_DEV_SLAVE_B];
@@ -399,17 +399,17 @@ void hsr_prune_nodes(struct hsr_priv *hsr_priv)
399 msecs_to_jiffies(1.5*MAX_SLAVE_DIFF))) { 399 msecs_to_jiffies(1.5*MAX_SLAVE_DIFF))) {
400 400
401 if (is_late(node, HSR_DEV_SLAVE_A)) 401 if (is_late(node, HSR_DEV_SLAVE_A))
402 hsr_nl_ringerror(hsr_priv, node->MacAddressA, 402 hsr_nl_ringerror(hsr, node->MacAddressA,
403 HSR_DEV_SLAVE_A); 403 HSR_DEV_SLAVE_A);
404 else if (is_late(node, HSR_DEV_SLAVE_B)) 404 else if (is_late(node, HSR_DEV_SLAVE_B))
405 hsr_nl_ringerror(hsr_priv, node->MacAddressA, 405 hsr_nl_ringerror(hsr, node->MacAddressA,
406 HSR_DEV_SLAVE_B); 406 HSR_DEV_SLAVE_B);
407 } 407 }
408 408
409 /* Prune old entries */ 409 /* Prune old entries */
410 if (time_is_before_jiffies(timestamp + 410 if (time_is_before_jiffies(timestamp +
411 msecs_to_jiffies(HSR_NODE_FORGET_TIME))) { 411 msecs_to_jiffies(HSR_NODE_FORGET_TIME))) {
412 hsr_nl_nodedown(hsr_priv, node->MacAddressA); 412 hsr_nl_nodedown(hsr, node->MacAddressA);
413 list_del_rcu(&node->mac_list); 413 list_del_rcu(&node->mac_list);
414 /* Note that we need to free this entry later: */ 414 /* Note that we need to free this entry later: */
415 kfree_rcu(node, rcu_head); 415 kfree_rcu(node, rcu_head);
@@ -419,21 +419,21 @@ void hsr_prune_nodes(struct hsr_priv *hsr_priv)
419} 419}
420 420
421 421
422void *hsr_get_next_node(struct hsr_priv *hsr_priv, void *_pos, 422void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
423 unsigned char addr[ETH_ALEN]) 423 unsigned char addr[ETH_ALEN])
424{ 424{
425 struct node_entry *node; 425 struct hsr_node *node;
426 426
427 if (!_pos) { 427 if (!_pos) {
428 node = list_first_or_null_rcu(&hsr_priv->node_db, 428 node = list_first_or_null_rcu(&hsr->node_db,
429 struct node_entry, mac_list); 429 struct hsr_node, mac_list);
430 if (node) 430 if (node)
431 ether_addr_copy(addr, node->MacAddressA); 431 ether_addr_copy(addr, node->MacAddressA);
432 return node; 432 return node;
433 } 433 }
434 434
435 node = _pos; 435 node = _pos;
436 list_for_each_entry_continue_rcu(node, &hsr_priv->node_db, mac_list) { 436 list_for_each_entry_continue_rcu(node, &hsr->node_db, mac_list) {
437 ether_addr_copy(addr, node->MacAddressA); 437 ether_addr_copy(addr, node->MacAddressA);
438 return node; 438 return node;
439 } 439 }
@@ -442,7 +442,7 @@ void *hsr_get_next_node(struct hsr_priv *hsr_priv, void *_pos,
442} 442}
443 443
444 444
445int hsr_get_node_data(struct hsr_priv *hsr_priv, 445int hsr_get_node_data(struct hsr_priv *hsr,
446 const unsigned char *addr, 446 const unsigned char *addr,
447 unsigned char addr_b[ETH_ALEN], 447 unsigned char addr_b[ETH_ALEN],
448 unsigned int *addr_b_ifindex, 448 unsigned int *addr_b_ifindex,
@@ -451,12 +451,12 @@ int hsr_get_node_data(struct hsr_priv *hsr_priv,
451 int *if2_age, 451 int *if2_age,
452 u16 *if2_seq) 452 u16 *if2_seq)
453{ 453{
454 struct node_entry *node; 454 struct hsr_node *node;
455 unsigned long tdiff; 455 unsigned long tdiff;
456 456
457 457
458 rcu_read_lock(); 458 rcu_read_lock();
459 node = find_node_by_AddrA(&hsr_priv->node_db, addr); 459 node = find_node_by_AddrA(&hsr->node_db, addr);
460 if (!node) { 460 if (!node) {
461 rcu_read_unlock(); 461 rcu_read_unlock();
462 return -ENOENT; /* No such entry */ 462 return -ENOENT; /* No such entry */
@@ -488,8 +488,8 @@ int hsr_get_node_data(struct hsr_priv *hsr_priv,
488 *if1_seq = node->seq_out[HSR_DEV_SLAVE_B]; 488 *if1_seq = node->seq_out[HSR_DEV_SLAVE_B];
489 *if2_seq = node->seq_out[HSR_DEV_SLAVE_A]; 489 *if2_seq = node->seq_out[HSR_DEV_SLAVE_A];
490 490
491 if ((node->AddrB_if != HSR_DEV_NONE) && hsr_priv->slave[node->AddrB_if]) 491 if ((node->AddrB_if != HSR_DEV_NONE) && hsr->slave[node->AddrB_if])
492 *addr_b_ifindex = hsr_priv->slave[node->AddrB_if]->ifindex; 492 *addr_b_ifindex = hsr->slave[node->AddrB_if]->ifindex;
493 else 493 else
494 *addr_b_ifindex = -1; 494 *addr_b_ifindex = -1;
495 495
diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index e6c4022030ad..3675139df379 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,42 +6,42 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 10 */
11 11
12#ifndef _HSR_FRAMEREG_H 12#ifndef __HSR_FRAMEREG_H
13#define _HSR_FRAMEREG_H 13#define __HSR_FRAMEREG_H
14 14
15#include "hsr_main.h" 15#include "hsr_main.h"
16 16
17struct node_entry; 17struct hsr_node;
18 18
19struct node_entry *hsr_find_node(struct list_head *node_db, struct sk_buff *skb); 19struct hsr_node *hsr_find_node(struct list_head *node_db, struct sk_buff *skb);
20 20
21struct node_entry *hsr_merge_node(struct hsr_priv *hsr_priv, 21struct hsr_node *hsr_merge_node(struct hsr_priv *hsr,
22 struct node_entry *node, 22 struct hsr_node *node,
23 struct sk_buff *skb, 23 struct sk_buff *skb,
24 enum hsr_dev_idx dev_idx); 24 enum hsr_dev_idx dev_idx);
25 25
26void hsr_addr_subst_source(struct hsr_priv *hsr_priv, struct sk_buff *skb); 26void hsr_addr_subst_source(struct hsr_priv *hsr, struct sk_buff *skb);
27void hsr_addr_subst_dest(struct hsr_priv *hsr_priv, struct ethhdr *ethhdr, 27void hsr_addr_subst_dest(struct hsr_priv *hsr, struct ethhdr *ethhdr,
28 enum hsr_dev_idx dev_idx); 28 enum hsr_dev_idx dev_idx);
29 29
30void hsr_register_frame_in(struct node_entry *node, enum hsr_dev_idx dev_idx); 30void hsr_register_frame_in(struct hsr_node *node, enum hsr_dev_idx dev_idx);
31 31
32int hsr_register_frame_out(struct node_entry *node, enum hsr_dev_idx dev_idx, 32int hsr_register_frame_out(struct hsr_node *node, enum hsr_dev_idx dev_idx,
33 struct sk_buff *skb); 33 struct sk_buff *skb);
34 34
35void hsr_prune_nodes(struct hsr_priv *hsr_priv); 35void hsr_prune_nodes(struct hsr_priv *hsr);
36 36
37int hsr_create_self_node(struct list_head *self_node_db, 37int hsr_create_self_node(struct list_head *self_node_db,
38 unsigned char addr_a[ETH_ALEN], 38 unsigned char addr_a[ETH_ALEN],
39 unsigned char addr_b[ETH_ALEN]); 39 unsigned char addr_b[ETH_ALEN]);
40 40
41void *hsr_get_next_node(struct hsr_priv *hsr_priv, void *_pos, 41void *hsr_get_next_node(struct hsr_priv *hsr, void *_pos,
42 unsigned char addr[ETH_ALEN]); 42 unsigned char addr[ETH_ALEN]);
43 43
44int hsr_get_node_data(struct hsr_priv *hsr_priv, 44int hsr_get_node_data(struct hsr_priv *hsr,
45 const unsigned char *addr, 45 const unsigned char *addr,
46 unsigned char addr_b[ETH_ALEN], 46 unsigned char addr_b[ETH_ALEN],
47 unsigned int *addr_b_ifindex, 47 unsigned int *addr_b_ifindex,
@@ -50,4 +50,4 @@ int hsr_get_node_data(struct hsr_priv *hsr_priv,
50 int *if2_age, 50 int *if2_age,
51 u16 *if2_seq); 51 u16 *if2_seq);
52 52
53#endif /* _HSR_FRAMEREG_H */ 53#endif /* __HSR_FRAMEREG_H */
diff --git a/net/hsr/hsr_main.c b/net/hsr/hsr_main.c
index 3fee5218a691..99b8fc4eca6c 100644
--- a/net/hsr/hsr_main.c
+++ b/net/hsr/hsr_main.c
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,7 +6,7 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 10 *
11 * In addition to routines for registering and unregistering HSR support, this 11 * In addition to routines for registering and unregistering HSR support, this
12 * file also contains the receive routine that handles all incoming frames with 12 * file also contains the receive routine that handles all incoming frames with
@@ -26,30 +26,30 @@
26/* List of all registered virtual HSR devices */ 26/* List of all registered virtual HSR devices */
27static LIST_HEAD(hsr_list); 27static LIST_HEAD(hsr_list);
28 28
29void register_hsr_master(struct hsr_priv *hsr_priv) 29void register_hsr_master(struct hsr_priv *hsr)
30{ 30{
31 list_add_tail_rcu(&hsr_priv->hsr_list, &hsr_list); 31 list_add_tail_rcu(&hsr->hsr_list, &hsr_list);
32} 32}
33 33
34void unregister_hsr_master(struct hsr_priv *hsr_priv) 34void unregister_hsr_master(struct hsr_priv *hsr)
35{ 35{
36 struct hsr_priv *hsr_priv_it; 36 struct hsr_priv *hsr_it;
37 37
38 list_for_each_entry(hsr_priv_it, &hsr_list, hsr_list) 38 list_for_each_entry(hsr_it, &hsr_list, hsr_list)
39 if (hsr_priv_it == hsr_priv) { 39 if (hsr_it == hsr) {
40 list_del_rcu(&hsr_priv_it->hsr_list); 40 list_del_rcu(&hsr_it->hsr_list);
41 return; 41 return;
42 } 42 }
43} 43}
44 44
45bool is_hsr_slave(struct net_device *dev) 45bool is_hsr_slave(struct net_device *dev)
46{ 46{
47 struct hsr_priv *hsr_priv_it; 47 struct hsr_priv *hsr_it;
48 48
49 list_for_each_entry_rcu(hsr_priv_it, &hsr_list, hsr_list) { 49 list_for_each_entry_rcu(hsr_it, &hsr_list, hsr_list) {
50 if (dev == hsr_priv_it->slave[0]) 50 if (dev == hsr_it->slave[0])
51 return true; 51 return true;
52 if (dev == hsr_priv_it->slave[1]) 52 if (dev == hsr_it->slave[1])
53 return true; 53 return true;
54 } 54 }
55 55
@@ -62,14 +62,14 @@ bool is_hsr_slave(struct net_device *dev)
62 */ 62 */
63static struct hsr_priv *get_hsr_master(struct net_device *dev) 63static struct hsr_priv *get_hsr_master(struct net_device *dev)
64{ 64{
65 struct hsr_priv *hsr_priv; 65 struct hsr_priv *hsr;
66 66
67 rcu_read_lock(); 67 rcu_read_lock();
68 list_for_each_entry_rcu(hsr_priv, &hsr_list, hsr_list) 68 list_for_each_entry_rcu(hsr, &hsr_list, hsr_list)
69 if ((dev == hsr_priv->slave[0]) || 69 if ((dev == hsr->slave[0]) ||
70 (dev == hsr_priv->slave[1])) { 70 (dev == hsr->slave[1])) {
71 rcu_read_unlock(); 71 rcu_read_unlock();
72 return hsr_priv; 72 return hsr;
73 } 73 }
74 74
75 rcu_read_unlock(); 75 rcu_read_unlock();
@@ -80,13 +80,13 @@ static struct hsr_priv *get_hsr_master(struct net_device *dev)
80/* If dev is a HSR slave device, return the other slave device. Return NULL 80/* If dev is a HSR slave device, return the other slave device. Return NULL
81 * otherwise. 81 * otherwise.
82 */ 82 */
83static struct net_device *get_other_slave(struct hsr_priv *hsr_priv, 83static struct net_device *get_other_slave(struct hsr_priv *hsr,
84 struct net_device *dev) 84 struct net_device *dev)
85{ 85{
86 if (dev == hsr_priv->slave[0]) 86 if (dev == hsr->slave[0])
87 return hsr_priv->slave[1]; 87 return hsr->slave[1];
88 if (dev == hsr_priv->slave[1]) 88 if (dev == hsr->slave[1])
89 return hsr_priv->slave[0]; 89 return hsr->slave[0];
90 90
91 return NULL; 91 return NULL;
92} 92}
@@ -96,7 +96,7 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
96 void *ptr) 96 void *ptr)
97{ 97{
98 struct net_device *slave, *other_slave; 98 struct net_device *slave, *other_slave;
99 struct hsr_priv *hsr_priv; 99 struct hsr_priv *hsr;
100 int old_operstate; 100 int old_operstate;
101 int mtu_max; 101 int mtu_max;
102 int res; 102 int res;
@@ -104,68 +104,68 @@ static int hsr_netdev_notify(struct notifier_block *nb, unsigned long event,
104 104
105 dev = netdev_notifier_info_to_dev(ptr); 105 dev = netdev_notifier_info_to_dev(ptr);
106 106
107 hsr_priv = get_hsr_master(dev); 107 hsr = get_hsr_master(dev);
108 if (hsr_priv) { 108 if (hsr) {
109 /* dev is a slave device */ 109 /* dev is a slave device */
110 slave = dev; 110 slave = dev;
111 other_slave = get_other_slave(hsr_priv, slave); 111 other_slave = get_other_slave(hsr, slave);
112 } else { 112 } else {
113 if (!is_hsr_master(dev)) 113 if (!is_hsr_master(dev))
114 return NOTIFY_DONE; 114 return NOTIFY_DONE;
115 hsr_priv = netdev_priv(dev); 115 hsr = netdev_priv(dev);
116 slave = hsr_priv->slave[0]; 116 slave = hsr->slave[0];
117 other_slave = hsr_priv->slave[1]; 117 other_slave = hsr->slave[1];
118 } 118 }
119 119
120 switch (event) { 120 switch (event) {
121 case NETDEV_UP: /* Administrative state DOWN */ 121 case NETDEV_UP: /* Administrative state DOWN */
122 case NETDEV_DOWN: /* Administrative state UP */ 122 case NETDEV_DOWN: /* Administrative state UP */
123 case NETDEV_CHANGE: /* Link (carrier) state changes */ 123 case NETDEV_CHANGE: /* Link (carrier) state changes */
124 old_operstate = hsr_priv->dev->operstate; 124 old_operstate = hsr->dev->operstate;
125 hsr_set_carrier(hsr_priv->dev, slave, other_slave); 125 hsr_set_carrier(hsr->dev, slave, other_slave);
126 /* netif_stacked_transfer_operstate() cannot be used here since 126 /* netif_stacked_transfer_operstate() cannot be used here since
127 * it doesn't set IF_OPER_LOWERLAYERDOWN (?) 127 * it doesn't set IF_OPER_LOWERLAYERDOWN (?)
128 */ 128 */
129 hsr_set_operstate(hsr_priv->dev, slave, other_slave); 129 hsr_set_operstate(hsr->dev, slave, other_slave);
130 hsr_check_announce(hsr_priv->dev, old_operstate); 130 hsr_check_announce(hsr->dev, old_operstate);
131 break; 131 break;
132 case NETDEV_CHANGEADDR: 132 case NETDEV_CHANGEADDR:
133 133
134 /* This should not happen since there's no ndo_set_mac_address() 134 /* This should not happen since there's no ndo_set_mac_address()
135 * for HSR devices - i.e. not supported. 135 * for HSR devices - i.e. not supported.
136 */ 136 */
137 if (dev == hsr_priv->dev) 137 if (dev == hsr->dev)
138 break; 138 break;
139 139
140 if (dev == hsr_priv->slave[0]) 140 if (dev == hsr->slave[0])
141 ether_addr_copy(hsr_priv->dev->dev_addr, 141 ether_addr_copy(hsr->dev->dev_addr,
142 hsr_priv->slave[0]->dev_addr); 142 hsr->slave[0]->dev_addr);
143 143
144 /* Make sure we recognize frames from ourselves in hsr_rcv() */ 144 /* Make sure we recognize frames from ourselves in hsr_rcv() */
145 res = hsr_create_self_node(&hsr_priv->self_node_db, 145 res = hsr_create_self_node(&hsr->self_node_db,
146 hsr_priv->dev->dev_addr, 146 hsr->dev->dev_addr,
147 hsr_priv->slave[1] ? 147 hsr->slave[1] ?
148 hsr_priv->slave[1]->dev_addr : 148 hsr->slave[1]->dev_addr :
149 hsr_priv->dev->dev_addr); 149 hsr->dev->dev_addr);
150 if (res) 150 if (res)
151 netdev_warn(hsr_priv->dev, 151 netdev_warn(hsr->dev,
152 "Could not update HSR node address.\n"); 152 "Could not update HSR node address.\n");
153 153
154 if (dev == hsr_priv->slave[0]) 154 if (dev == hsr->slave[0])
155 call_netdevice_notifiers(NETDEV_CHANGEADDR, hsr_priv->dev); 155 call_netdevice_notifiers(NETDEV_CHANGEADDR, hsr->dev);
156 break; 156 break;
157 case NETDEV_CHANGEMTU: 157 case NETDEV_CHANGEMTU:
158 if (dev == hsr_priv->dev) 158 if (dev == hsr->dev)
159 break; /* Handled in ndo_change_mtu() */ 159 break; /* Handled in ndo_change_mtu() */
160 mtu_max = hsr_get_max_mtu(hsr_priv); 160 mtu_max = hsr_get_max_mtu(hsr);
161 if (hsr_priv->dev->mtu > mtu_max) 161 if (hsr->dev->mtu > mtu_max)
162 dev_set_mtu(hsr_priv->dev, mtu_max); 162 dev_set_mtu(hsr->dev, mtu_max);
163 break; 163 break;
164 case NETDEV_UNREGISTER: 164 case NETDEV_UNREGISTER:
165 if (dev == hsr_priv->slave[0]) 165 if (dev == hsr->slave[0])
166 hsr_priv->slave[0] = NULL; 166 hsr->slave[0] = NULL;
167 if (dev == hsr_priv->slave[1]) 167 if (dev == hsr->slave[1])
168 hsr_priv->slave[1] = NULL; 168 hsr->slave[1] = NULL;
169 169
170 /* There should really be a way to set a new slave device... */ 170 /* There should really be a way to set a new slave device... */
171 171
@@ -185,11 +185,11 @@ static struct timer_list prune_timer;
185 185
186static void prune_nodes_all(unsigned long data) 186static void prune_nodes_all(unsigned long data)
187{ 187{
188 struct hsr_priv *hsr_priv; 188 struct hsr_priv *hsr;
189 189
190 rcu_read_lock(); 190 rcu_read_lock();
191 list_for_each_entry_rcu(hsr_priv, &hsr_list, hsr_list) 191 list_for_each_entry_rcu(hsr, &hsr_list, hsr_list)
192 hsr_prune_nodes(hsr_priv); 192 hsr_prune_nodes(hsr);
193 rcu_read_unlock(); 193 rcu_read_unlock();
194 194
195 prune_timer.expires = jiffies + msecs_to_jiffies(PRUNE_PERIOD); 195 prune_timer.expires = jiffies + msecs_to_jiffies(PRUNE_PERIOD);
@@ -207,12 +207,12 @@ static struct sk_buff *hsr_pull_tag(struct sk_buff *skb)
207 goto err_free; 207 goto err_free;
208 skb = skb2; 208 skb = skb2;
209 209
210 if (unlikely(!pskb_may_pull(skb, HSR_TAGLEN))) 210 if (unlikely(!pskb_may_pull(skb, HSR_HLEN)))
211 goto err_free; 211 goto err_free;
212 212
213 hsr_tag = (struct hsr_tag *) skb->data; 213 hsr_tag = (struct hsr_tag *) skb->data;
214 skb->protocol = hsr_tag->encap_proto; 214 skb->protocol = hsr_tag->encap_proto;
215 skb_pull(skb, HSR_TAGLEN); 215 skb_pull(skb, HSR_HLEN);
216 216
217 return skb; 217 return skb;
218 218
@@ -237,12 +237,12 @@ err_free:
237 * 3) Allow different MAC addresses for the two slave interfaces, using the 237 * 3) Allow different MAC addresses for the two slave interfaces, using the
238 * MacAddressA field. 238 * MacAddressA field.
239 */ 239 */
240static bool is_supervision_frame(struct hsr_priv *hsr_priv, struct sk_buff *skb) 240static bool is_supervision_frame(struct hsr_priv *hsr, struct sk_buff *skb)
241{ 241{
242 struct hsr_sup_tag *hsr_stag; 242 struct hsr_sup_tag *hsr_stag;
243 243
244 if (!ether_addr_equal(eth_hdr(skb)->h_dest, 244 if (!ether_addr_equal(eth_hdr(skb)->h_dest,
245 hsr_priv->sup_multicast_addr)) 245 hsr->sup_multicast_addr))
246 return false; 246 return false;
247 247
248 hsr_stag = (struct hsr_sup_tag *) skb->data; 248 hsr_stag = (struct hsr_sup_tag *) skb->data;
@@ -263,25 +263,25 @@ static bool is_supervision_frame(struct hsr_priv *hsr_priv, struct sk_buff *skb)
263static int hsr_rcv(struct sk_buff *skb, struct net_device *dev, 263static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
264 struct packet_type *pt, struct net_device *orig_dev) 264 struct packet_type *pt, struct net_device *orig_dev)
265{ 265{
266 struct hsr_priv *hsr_priv; 266 struct hsr_priv *hsr;
267 struct net_device *other_slave; 267 struct net_device *other_slave;
268 struct node_entry *node; 268 struct hsr_node *node;
269 bool deliver_to_self; 269 bool deliver_to_self;
270 struct sk_buff *skb_deliver; 270 struct sk_buff *skb_deliver;
271 enum hsr_dev_idx dev_in_idx, dev_other_idx; 271 enum hsr_dev_idx dev_in_idx, dev_other_idx;
272 bool dup_out; 272 bool dup_out;
273 int ret; 273 int ret;
274 274
275 hsr_priv = get_hsr_master(dev); 275 hsr = get_hsr_master(dev);
276 276
277 if (!hsr_priv) { 277 if (!hsr) {
278 /* Non-HSR-slave device 'dev' is connected to a HSR network */ 278 /* Non-HSR-slave device 'dev' is connected to a HSR network */
279 kfree_skb(skb); 279 kfree_skb(skb);
280 dev->stats.rx_errors++; 280 dev->stats.rx_errors++;
281 return NET_RX_SUCCESS; 281 return NET_RX_SUCCESS;
282 } 282 }
283 283
284 if (dev == hsr_priv->slave[0]) { 284 if (dev == hsr->slave[0]) {
285 dev_in_idx = HSR_DEV_SLAVE_A; 285 dev_in_idx = HSR_DEV_SLAVE_A;
286 dev_other_idx = HSR_DEV_SLAVE_B; 286 dev_other_idx = HSR_DEV_SLAVE_B;
287 } else { 287 } else {
@@ -289,7 +289,7 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
289 dev_other_idx = HSR_DEV_SLAVE_A; 289 dev_other_idx = HSR_DEV_SLAVE_A;
290 } 290 }
291 291
292 node = hsr_find_node(&hsr_priv->self_node_db, skb); 292 node = hsr_find_node(&hsr->self_node_db, skb);
293 if (node) { 293 if (node) {
294 /* Always kill frames sent by ourselves */ 294 /* Always kill frames sent by ourselves */
295 kfree_skb(skb); 295 kfree_skb(skb);
@@ -303,22 +303,22 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
303 (skb->pkt_type == PACKET_BROADCAST)) 303 (skb->pkt_type == PACKET_BROADCAST))
304 deliver_to_self = true; 304 deliver_to_self = true;
305 else if (ether_addr_equal(eth_hdr(skb)->h_dest, 305 else if (ether_addr_equal(eth_hdr(skb)->h_dest,
306 hsr_priv->dev->dev_addr)) { 306 hsr->dev->dev_addr)) {
307 skb->pkt_type = PACKET_HOST; 307 skb->pkt_type = PACKET_HOST;
308 deliver_to_self = true; 308 deliver_to_self = true;
309 } 309 }
310 310
311 311
312 rcu_read_lock(); /* node_db */ 312 rcu_read_lock(); /* node_db */
313 node = hsr_find_node(&hsr_priv->node_db, skb); 313 node = hsr_find_node(&hsr->node_db, skb);
314 314
315 if (is_supervision_frame(hsr_priv, skb)) { 315 if (is_supervision_frame(hsr, skb)) {
316 skb_pull(skb, sizeof(struct hsr_sup_tag)); 316 skb_pull(skb, sizeof(struct hsr_sup_tag));
317 node = hsr_merge_node(hsr_priv, node, skb, dev_in_idx); 317 node = hsr_merge_node(hsr, node, skb, dev_in_idx);
318 if (!node) { 318 if (!node) {
319 rcu_read_unlock(); /* node_db */ 319 rcu_read_unlock(); /* node_db */
320 kfree_skb(skb); 320 kfree_skb(skb);
321 hsr_priv->dev->stats.rx_dropped++; 321 hsr->dev->stats.rx_dropped++;
322 return NET_RX_DROP; 322 return NET_RX_DROP;
323 } 323 }
324 skb_push(skb, sizeof(struct hsr_sup_tag)); 324 skb_push(skb, sizeof(struct hsr_sup_tag));
@@ -345,7 +345,7 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
345 345
346 /* Forward this frame? */ 346 /* Forward this frame? */
347 if (!dup_out && (skb->pkt_type != PACKET_HOST)) 347 if (!dup_out && (skb->pkt_type != PACKET_HOST))
348 other_slave = get_other_slave(hsr_priv, dev); 348 other_slave = get_other_slave(hsr, dev);
349 else 349 else
350 other_slave = NULL; 350 other_slave = NULL;
351 351
@@ -368,7 +368,7 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
368 skb_deliver = pskb_copy(skb, GFP_ATOMIC); 368 skb_deliver = pskb_copy(skb, GFP_ATOMIC);
369 if (!skb_deliver) { 369 if (!skb_deliver) {
370 deliver_to_self = false; 370 deliver_to_self = false;
371 hsr_priv->dev->stats.rx_dropped++; 371 hsr->dev->stats.rx_dropped++;
372 } 372 }
373 } 373 }
374 374
@@ -377,7 +377,7 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
377 377
378 skb_deliver = hsr_pull_tag(skb_deliver); 378 skb_deliver = hsr_pull_tag(skb_deliver);
379 if (!skb_deliver) { 379 if (!skb_deliver) {
380 hsr_priv->dev->stats.rx_dropped++; 380 hsr->dev->stats.rx_dropped++;
381 goto forward; 381 goto forward;
382 } 382 }
383#if !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) 383#if !defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
@@ -386,7 +386,7 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
386 * tag. In practice, this removes/overwrites the HSR tag in 386 * tag. In practice, this removes/overwrites the HSR tag in
387 * the header and restores a "standard" packet. 387 * the header and restores a "standard" packet.
388 */ 388 */
389 memmove(skb_deliver->data - HSR_TAGLEN, skb_deliver->data, 389 memmove(skb_deliver->data - HSR_HLEN, skb_deliver->data,
390 skb_headlen(skb_deliver)); 390 skb_headlen(skb_deliver));
391 391
392 /* Adjust skb members so they correspond with the move above. 392 /* Adjust skb members so they correspond with the move above.
@@ -397,20 +397,20 @@ static int hsr_rcv(struct sk_buff *skb, struct net_device *dev,
397 * the mac header nor the head. So we only need to adjust data 397 * the mac header nor the head. So we only need to adjust data
398 * and tail: 398 * and tail:
399 */ 399 */
400 skb_deliver->data -= HSR_TAGLEN; 400 skb_deliver->data -= HSR_HLEN;
401 skb_deliver->tail -= HSR_TAGLEN; 401 skb_deliver->tail -= HSR_HLEN;
402#endif 402#endif
403 skb_deliver->dev = hsr_priv->dev; 403 skb_deliver->dev = hsr->dev;
404 hsr_addr_subst_source(hsr_priv, skb_deliver); 404 hsr_addr_subst_source(hsr, skb_deliver);
405 multicast_frame = (skb_deliver->pkt_type == PACKET_MULTICAST); 405 multicast_frame = (skb_deliver->pkt_type == PACKET_MULTICAST);
406 ret = netif_rx(skb_deliver); 406 ret = netif_rx(skb_deliver);
407 if (ret == NET_RX_DROP) { 407 if (ret == NET_RX_DROP) {
408 hsr_priv->dev->stats.rx_dropped++; 408 hsr->dev->stats.rx_dropped++;
409 } else { 409 } else {
410 hsr_priv->dev->stats.rx_packets++; 410 hsr->dev->stats.rx_packets++;
411 hsr_priv->dev->stats.rx_bytes += skb->len; 411 hsr->dev->stats.rx_bytes += skb->len;
412 if (multicast_frame) 412 if (multicast_frame)
413 hsr_priv->dev->stats.multicast++; 413 hsr->dev->stats.multicast++;
414 } 414 }
415 } 415 }
416 416
@@ -439,7 +439,7 @@ static int __init hsr_init(void)
439{ 439{
440 int res; 440 int res;
441 441
442 BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_TAGLEN); 442 BUILD_BUG_ON(sizeof(struct hsr_tag) != HSR_HLEN);
443 443
444 dev_add_pack(&hsr_pt); 444 dev_add_pack(&hsr_pt);
445 445
diff --git a/net/hsr/hsr_main.h b/net/hsr/hsr_main.h
index 56fe060c0ab1..360a49af0c1b 100644
--- a/net/hsr/hsr_main.h
+++ b/net/hsr/hsr_main.h
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,11 +6,11 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 10 */
11 11
12#ifndef _HSR_PRIVATE_H 12#ifndef __HSR_PRIVATE_H
13#define _HSR_PRIVATE_H 13#define __HSR_PRIVATE_H
14 14
15#include <linux/netdevice.h> 15#include <linux/netdevice.h>
16#include <linux/list.h> 16#include <linux/list.h>
@@ -46,16 +46,16 @@
46 * path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest, 46 * path, LSDU_size, sequence Nr }. But we let eth_header() create { h_dest,
47 * h_source, h_proto = 0x88FB }, and add { path, LSDU_size, sequence Nr, 47 * h_source, h_proto = 0x88FB }, and add { path, LSDU_size, sequence Nr,
48 * encapsulated protocol } instead. 48 * encapsulated protocol } instead.
49 *
50 * Field names as defined in the IEC:2010 standard for HSR.
49 */ 51 */
50#define HSR_TAGLEN 6
51
52/* Field names below as defined in the IEC:2010 standard for HSR. */
53struct hsr_tag { 52struct hsr_tag {
54 __be16 path_and_LSDU_size; 53 __be16 path_and_LSDU_size;
55 __be16 sequence_nr; 54 __be16 sequence_nr;
56 __be16 encap_proto; 55 __be16 encap_proto;
57} __packed; 56} __packed;
58 57
58#define HSR_HLEN 6
59 59
60/* The helper functions below assumes that 'path' occupies the 4 most 60/* The helper functions below assumes that 'path' occupies the 4 most
61 * significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or 61 * significant bits of the 16-bit field shared by 'path' and 'LSDU_size' (or
@@ -159,8 +159,8 @@ struct hsr_priv {
159 unsigned char sup_multicast_addr[ETH_ALEN]; 159 unsigned char sup_multicast_addr[ETH_ALEN];
160}; 160};
161 161
162void register_hsr_master(struct hsr_priv *hsr_priv); 162void register_hsr_master(struct hsr_priv *hsr);
163void unregister_hsr_master(struct hsr_priv *hsr_priv); 163void unregister_hsr_master(struct hsr_priv *hsr);
164bool is_hsr_slave(struct net_device *dev); 164bool is_hsr_slave(struct net_device *dev);
165 165
166#endif /* _HSR_PRIVATE_H */ 166#endif /* __HSR_PRIVATE_H */
diff --git a/net/hsr/hsr_netlink.c b/net/hsr/hsr_netlink.c
index 01a5261ac7a5..bea250ec3586 100644
--- a/net/hsr/hsr_netlink.c
+++ b/net/hsr/hsr_netlink.c
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,7 +6,7 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 * 10 *
11 * Routines for handling Netlink messages for HSR. 11 * Routines for handling Netlink messages for HSR.
12 */ 12 */
@@ -63,21 +63,21 @@ static int hsr_newlink(struct net *src_net, struct net_device *dev,
63 63
64static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) 64static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
65{ 65{
66 struct hsr_priv *hsr_priv; 66 struct hsr_priv *hsr;
67 67
68 hsr_priv = netdev_priv(dev); 68 hsr = netdev_priv(dev);
69 69
70 if (hsr_priv->slave[0]) 70 if (hsr->slave[0])
71 if (nla_put_u32(skb, IFLA_HSR_SLAVE1, hsr_priv->slave[0]->ifindex)) 71 if (nla_put_u32(skb, IFLA_HSR_SLAVE1, hsr->slave[0]->ifindex))
72 goto nla_put_failure; 72 goto nla_put_failure;
73 73
74 if (hsr_priv->slave[1]) 74 if (hsr->slave[1])
75 if (nla_put_u32(skb, IFLA_HSR_SLAVE2, hsr_priv->slave[1]->ifindex)) 75 if (nla_put_u32(skb, IFLA_HSR_SLAVE2, hsr->slave[1]->ifindex))
76 goto nla_put_failure; 76 goto nla_put_failure;
77 77
78 if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN, 78 if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN,
79 hsr_priv->sup_multicast_addr) || 79 hsr->sup_multicast_addr) ||
80 nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr_priv->sequence_nr)) 80 nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
81 goto nla_put_failure; 81 goto nla_put_failure;
82 82
83 return 0; 83 return 0;
@@ -128,7 +128,7 @@ static const struct genl_multicast_group hsr_mcgrps[] = {
128 * over one of the slave interfaces. This would indicate an open network ring 128 * over one of the slave interfaces. This would indicate an open network ring
129 * (i.e. a link has failed somewhere). 129 * (i.e. a link has failed somewhere).
130 */ 130 */
131void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN], 131void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
132 enum hsr_dev_idx dev_idx) 132 enum hsr_dev_idx dev_idx)
133{ 133{
134 struct sk_buff *skb; 134 struct sk_buff *skb;
@@ -148,8 +148,8 @@ void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN],
148 if (res < 0) 148 if (res < 0)
149 goto nla_put_failure; 149 goto nla_put_failure;
150 150
151 if (hsr_priv->slave[dev_idx]) 151 if (hsr->slave[dev_idx])
152 ifindex = hsr_priv->slave[dev_idx]->ifindex; 152 ifindex = hsr->slave[dev_idx]->ifindex;
153 else 153 else
154 ifindex = -1; 154 ifindex = -1;
155 res = nla_put_u32(skb, HSR_A_IFINDEX, ifindex); 155 res = nla_put_u32(skb, HSR_A_IFINDEX, ifindex);
@@ -165,13 +165,13 @@ nla_put_failure:
165 kfree_skb(skb); 165 kfree_skb(skb);
166 166
167fail: 167fail:
168 netdev_warn(hsr_priv->dev, "Could not send HSR ring error message\n"); 168 netdev_warn(hsr->dev, "Could not send HSR ring error message\n");
169} 169}
170 170
171/* This is called when we haven't heard from the node with MAC address addr for 171/* This is called when we haven't heard from the node with MAC address addr for
172 * some time (just before the node is removed from the node table/list). 172 * some time (just before the node is removed from the node table/list).
173 */ 173 */
174void hsr_nl_nodedown(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN]) 174void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN])
175{ 175{
176 struct sk_buff *skb; 176 struct sk_buff *skb;
177 void *msg_head; 177 void *msg_head;
@@ -199,7 +199,7 @@ nla_put_failure:
199 kfree_skb(skb); 199 kfree_skb(skb);
200 200
201fail: 201fail:
202 netdev_warn(hsr_priv->dev, "Could not send HSR node down\n"); 202 netdev_warn(hsr->dev, "Could not send HSR node down\n");
203} 203}
204 204
205 205
@@ -220,7 +220,7 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
220 /* For sending */ 220 /* For sending */
221 struct sk_buff *skb_out; 221 struct sk_buff *skb_out;
222 void *msg_head; 222 void *msg_head;
223 struct hsr_priv *hsr_priv; 223 struct hsr_priv *hsr;
224 unsigned char hsr_node_addr_b[ETH_ALEN]; 224 unsigned char hsr_node_addr_b[ETH_ALEN];
225 int hsr_node_if1_age; 225 int hsr_node_if1_age;
226 u16 hsr_node_if1_seq; 226 u16 hsr_node_if1_seq;
@@ -267,8 +267,8 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
267 if (res < 0) 267 if (res < 0)
268 goto nla_put_failure; 268 goto nla_put_failure;
269 269
270 hsr_priv = netdev_priv(hsr_dev); 270 hsr = netdev_priv(hsr_dev);
271 res = hsr_get_node_data(hsr_priv, 271 res = hsr_get_node_data(hsr,
272 (unsigned char *) nla_data(info->attrs[HSR_A_NODE_ADDR]), 272 (unsigned char *) nla_data(info->attrs[HSR_A_NODE_ADDR]),
273 hsr_node_addr_b, 273 hsr_node_addr_b,
274 &addr_b_ifindex, 274 &addr_b_ifindex,
@@ -301,9 +301,9 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
301 res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq); 301 res = nla_put_u16(skb_out, HSR_A_IF1_SEQ, hsr_node_if1_seq);
302 if (res < 0) 302 if (res < 0)
303 goto nla_put_failure; 303 goto nla_put_failure;
304 if (hsr_priv->slave[0]) 304 if (hsr->slave[0])
305 res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX, 305 res = nla_put_u32(skb_out, HSR_A_IF1_IFINDEX,
306 hsr_priv->slave[0]->ifindex); 306 hsr->slave[0]->ifindex);
307 if (res < 0) 307 if (res < 0)
308 goto nla_put_failure; 308 goto nla_put_failure;
309 309
@@ -313,9 +313,9 @@ static int hsr_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
313 res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq); 313 res = nla_put_u16(skb_out, HSR_A_IF2_SEQ, hsr_node_if2_seq);
314 if (res < 0) 314 if (res < 0)
315 goto nla_put_failure; 315 goto nla_put_failure;
316 if (hsr_priv->slave[1]) 316 if (hsr->slave[1])
317 res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX, 317 res = nla_put_u32(skb_out, HSR_A_IF2_IFINDEX,
318 hsr_priv->slave[1]->ifindex); 318 hsr->slave[1]->ifindex);
319 319
320 genlmsg_end(skb_out, msg_head); 320 genlmsg_end(skb_out, msg_head);
321 genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid); 321 genlmsg_unicast(genl_info_net(info), skb_out, info->snd_portid);
@@ -345,7 +345,7 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
345 /* For sending */ 345 /* For sending */
346 struct sk_buff *skb_out; 346 struct sk_buff *skb_out;
347 void *msg_head; 347 void *msg_head;
348 struct hsr_priv *hsr_priv; 348 struct hsr_priv *hsr;
349 void *pos; 349 void *pos;
350 unsigned char addr[ETH_ALEN]; 350 unsigned char addr[ETH_ALEN];
351 int res; 351 int res;
@@ -385,17 +385,17 @@ static int hsr_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
385 if (res < 0) 385 if (res < 0)
386 goto nla_put_failure; 386 goto nla_put_failure;
387 387
388 hsr_priv = netdev_priv(hsr_dev); 388 hsr = netdev_priv(hsr_dev);
389 389
390 rcu_read_lock(); 390 rcu_read_lock();
391 pos = hsr_get_next_node(hsr_priv, NULL, addr); 391 pos = hsr_get_next_node(hsr, NULL, addr);
392 while (pos) { 392 while (pos) {
393 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr); 393 res = nla_put(skb_out, HSR_A_NODE_ADDR, ETH_ALEN, addr);
394 if (res < 0) { 394 if (res < 0) {
395 rcu_read_unlock(); 395 rcu_read_unlock();
396 goto nla_put_failure; 396 goto nla_put_failure;
397 } 397 }
398 pos = hsr_get_next_node(hsr_priv, pos, addr); 398 pos = hsr_get_next_node(hsr, pos, addr);
399 } 399 }
400 rcu_read_unlock(); 400 rcu_read_unlock();
401 401
diff --git a/net/hsr/hsr_netlink.h b/net/hsr/hsr_netlink.h
index d4579dcc3c7d..3047f9cea5f5 100644
--- a/net/hsr/hsr_netlink.h
+++ b/net/hsr/hsr_netlink.h
@@ -1,4 +1,4 @@
1/* Copyright 2011-2013 Autronica Fire and Security AS 1/* Copyright 2011-2014 Autronica Fire and Security AS
2 * 2 *
3 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
@@ -6,7 +6,7 @@
6 * any later version. 6 * any later version.
7 * 7 *
8 * Author(s): 8 * Author(s):
9 * 2011-2013 Arvid Brodin, arvid.brodin@xdin.com 9 * 2011-2014 Arvid Brodin, arvid.brodin@alten.se
10 */ 10 */
11 11
12#ifndef __HSR_NETLINK_H 12#ifndef __HSR_NETLINK_H
@@ -21,9 +21,9 @@ struct hsr_priv;
21int __init hsr_netlink_init(void); 21int __init hsr_netlink_init(void);
22void __exit hsr_netlink_exit(void); 22void __exit hsr_netlink_exit(void);
23 23
24void hsr_nl_ringerror(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN], 24void hsr_nl_ringerror(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN],
25 int dev_idx); 25 int dev_idx);
26void hsr_nl_nodedown(struct hsr_priv *hsr_priv, unsigned char addr[ETH_ALEN]); 26void hsr_nl_nodedown(struct hsr_priv *hsr, unsigned char addr[ETH_ALEN]);
27void hsr_nl_framedrop(int dropcount, int dev_idx); 27void hsr_nl_framedrop(int dropcount, int dev_idx);
28void hsr_nl_linkdown(int dev_idx); 28void hsr_nl_linkdown(int dev_idx);
29 29