aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/net/can/at91_can.c2
-rw-r--r--drivers/net/can/dev.c32
-rw-r--r--drivers/net/can/sja1000/sja1000.c3
-rw-r--r--drivers/net/can/sja1000/sja1000.h2
-rw-r--r--drivers/net/can/ti_hecc.c6
-rw-r--r--drivers/net/can/usb/ems_usb.c4
-rw-r--r--include/linux/can/dev.h16
7 files changed, 42 insertions, 23 deletions
diff --git a/drivers/net/can/at91_can.c b/drivers/net/can/at91_can.c
index f67ae285a35a..b13fd9114130 100644
--- a/drivers/net/can/at91_can.c
+++ b/drivers/net/can/at91_can.c
@@ -1087,7 +1087,7 @@ static int __init at91_can_probe(struct platform_device *pdev)
1087 goto exit_release; 1087 goto exit_release;
1088 } 1088 }
1089 1089
1090 dev = alloc_candev(sizeof(struct at91_priv)); 1090 dev = alloc_candev(sizeof(struct at91_priv), AT91_MB_TX_NUM);
1091 if (!dev) { 1091 if (!dev) {
1092 err = -ENOMEM; 1092 err = -ENOMEM;
1093 goto exit_iounmap; 1093 goto exit_iounmap;
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index f0b9a1e1db46..39b99f57c265 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -245,7 +245,7 @@ static void can_flush_echo_skb(struct net_device *dev)
245 struct net_device_stats *stats = &dev->stats; 245 struct net_device_stats *stats = &dev->stats;
246 int i; 246 int i;
247 247
248 for (i = 0; i < CAN_ECHO_SKB_MAX; i++) { 248 for (i = 0; i < priv->echo_skb_max; i++) {
249 if (priv->echo_skb[i]) { 249 if (priv->echo_skb[i]) {
250 kfree_skb(priv->echo_skb[i]); 250 kfree_skb(priv->echo_skb[i]);
251 priv->echo_skb[i] = NULL; 251 priv->echo_skb[i] = NULL;
@@ -262,10 +262,13 @@ static void can_flush_echo_skb(struct net_device *dev)
262 * of the device driver. The driver must protect access to 262 * of the device driver. The driver must protect access to
263 * priv->echo_skb, if necessary. 263 * priv->echo_skb, if necessary.
264 */ 264 */
265void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, int idx) 265void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
266 unsigned int idx)
266{ 267{
267 struct can_priv *priv = netdev_priv(dev); 268 struct can_priv *priv = netdev_priv(dev);
268 269
270 BUG_ON(idx >= priv->echo_skb_max);
271
269 /* check flag whether this packet has to be looped back */ 272 /* check flag whether this packet has to be looped back */
270 if (!(dev->flags & IFF_ECHO) || skb->pkt_type != PACKET_LOOPBACK) { 273 if (!(dev->flags & IFF_ECHO) || skb->pkt_type != PACKET_LOOPBACK) {
271 kfree_skb(skb); 274 kfree_skb(skb);
@@ -311,10 +314,12 @@ EXPORT_SYMBOL_GPL(can_put_echo_skb);
311 * is handled in the device driver. The driver must protect 314 * is handled in the device driver. The driver must protect
312 * access to priv->echo_skb, if necessary. 315 * access to priv->echo_skb, if necessary.
313 */ 316 */
314void can_get_echo_skb(struct net_device *dev, int idx) 317void can_get_echo_skb(struct net_device *dev, unsigned int idx)
315{ 318{
316 struct can_priv *priv = netdev_priv(dev); 319 struct can_priv *priv = netdev_priv(dev);
317 320
321 BUG_ON(idx >= priv->echo_skb_max);
322
318 if (priv->echo_skb[idx]) { 323 if (priv->echo_skb[idx]) {
319 netif_rx(priv->echo_skb[idx]); 324 netif_rx(priv->echo_skb[idx]);
320 priv->echo_skb[idx] = NULL; 325 priv->echo_skb[idx] = NULL;
@@ -327,10 +332,12 @@ EXPORT_SYMBOL_GPL(can_get_echo_skb);
327 * 332 *
328 * The function is typically called when TX failed. 333 * The function is typically called when TX failed.
329 */ 334 */
330void can_free_echo_skb(struct net_device *dev, int idx) 335void can_free_echo_skb(struct net_device *dev, unsigned int idx)
331{ 336{
332 struct can_priv *priv = netdev_priv(dev); 337 struct can_priv *priv = netdev_priv(dev);
333 338
339 BUG_ON(idx >= priv->echo_skb_max);
340
334 if (priv->echo_skb[idx]) { 341 if (priv->echo_skb[idx]) {
335 kfree_skb(priv->echo_skb[idx]); 342 kfree_skb(priv->echo_skb[idx]);
336 priv->echo_skb[idx] = NULL; 343 priv->echo_skb[idx] = NULL;
@@ -445,17 +452,30 @@ static void can_setup(struct net_device *dev)
445/* 452/*
446 * Allocate and setup space for the CAN network device 453 * Allocate and setup space for the CAN network device
447 */ 454 */
448struct net_device *alloc_candev(int sizeof_priv) 455struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max)
449{ 456{
450 struct net_device *dev; 457 struct net_device *dev;
451 struct can_priv *priv; 458 struct can_priv *priv;
459 int size;
452 460
453 dev = alloc_netdev(sizeof_priv, "can%d", can_setup); 461 if (echo_skb_max)
462 size = ALIGN(sizeof_priv, sizeof(struct sk_buff *)) +
463 echo_skb_max * sizeof(struct sk_buff *);
464 else
465 size = sizeof_priv;
466
467 dev = alloc_netdev(size, "can%d", can_setup);
454 if (!dev) 468 if (!dev)
455 return NULL; 469 return NULL;
456 470
457 priv = netdev_priv(dev); 471 priv = netdev_priv(dev);
458 472
473 if (echo_skb_max) {
474 priv->echo_skb_max = echo_skb_max;
475 priv->echo_skb = (void *)priv +
476 ALIGN(sizeof_priv, sizeof(struct sk_buff *));
477 }
478
459 priv->state = CAN_STATE_STOPPED; 479 priv->state = CAN_STATE_STOPPED;
460 480
461 init_timer(&priv->restart_timer); 481 init_timer(&priv->restart_timer);
diff --git a/drivers/net/can/sja1000/sja1000.c b/drivers/net/can/sja1000/sja1000.c
index 16d2ecd2a3b7..96d8be4253f8 100644
--- a/drivers/net/can/sja1000/sja1000.c
+++ b/drivers/net/can/sja1000/sja1000.c
@@ -565,7 +565,8 @@ struct net_device *alloc_sja1000dev(int sizeof_priv)
565 struct net_device *dev; 565 struct net_device *dev;
566 struct sja1000_priv *priv; 566 struct sja1000_priv *priv;
567 567
568 dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv); 568 dev = alloc_candev(sizeof(struct sja1000_priv) + sizeof_priv,
569 SJA1000_ECHO_SKB_MAX);
569 if (!dev) 570 if (!dev)
570 return NULL; 571 return NULL;
571 572
diff --git a/drivers/net/can/sja1000/sja1000.h b/drivers/net/can/sja1000/sja1000.h
index 302d2c763ad7..97a622b9302f 100644
--- a/drivers/net/can/sja1000/sja1000.h
+++ b/drivers/net/can/sja1000/sja1000.h
@@ -50,6 +50,8 @@
50#include <linux/can/dev.h> 50#include <linux/can/dev.h>
51#include <linux/can/platform/sja1000.h> 51#include <linux/can/platform/sja1000.h>
52 52
53#define SJA1000_ECHO_SKB_MAX 1 /* the SJA1000 has one TX buffer object */
54
53#define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */ 55#define SJA1000_MAX_IRQ 20 /* max. number of interrupts handled in ISR */
54 56
55/* SJA1000 registers - manual section 6.4 (Pelican Mode) */ 57/* SJA1000 registers - manual section 6.4 (Pelican Mode) */
diff --git a/drivers/net/can/ti_hecc.c b/drivers/net/can/ti_hecc.c
index 814e6c5c6386..23a7128e4eb7 100644
--- a/drivers/net/can/ti_hecc.c
+++ b/drivers/net/can/ti_hecc.c
@@ -74,10 +74,6 @@ MODULE_VERSION(HECC_MODULE_VERSION);
74#define HECC_MB_TX_SHIFT 2 /* as per table above */ 74#define HECC_MB_TX_SHIFT 2 /* as per table above */
75#define HECC_MAX_TX_MBOX BIT(HECC_MB_TX_SHIFT) 75#define HECC_MAX_TX_MBOX BIT(HECC_MB_TX_SHIFT)
76 76
77#if (HECC_MAX_TX_MBOX > CAN_ECHO_SKB_MAX)
78#error "HECC: MAX TX mailboxes should be equal or less than CAN_ECHO_SKB_MAX"
79#endif
80
81#define HECC_TX_PRIO_SHIFT (HECC_MB_TX_SHIFT) 77#define HECC_TX_PRIO_SHIFT (HECC_MB_TX_SHIFT)
82#define HECC_TX_PRIO_MASK (MAX_TX_PRIO << HECC_MB_TX_SHIFT) 78#define HECC_TX_PRIO_MASK (MAX_TX_PRIO << HECC_MB_TX_SHIFT)
83#define HECC_TX_MB_MASK (HECC_MAX_TX_MBOX - 1) 79#define HECC_TX_MB_MASK (HECC_MAX_TX_MBOX - 1)
@@ -902,7 +898,7 @@ static int ti_hecc_probe(struct platform_device *pdev)
902 goto probe_exit_free_region; 898 goto probe_exit_free_region;
903 } 899 }
904 900
905 ndev = alloc_candev(sizeof(struct ti_hecc_priv)); 901 ndev = alloc_candev(sizeof(struct ti_hecc_priv), HECC_MAX_TX_MBOX);
906 if (!ndev) { 902 if (!ndev) {
907 dev_err(&pdev->dev, "alloc_candev failed\n"); 903 dev_err(&pdev->dev, "alloc_candev failed\n");
908 err = -ENOMEM; 904 err = -ENOMEM;
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 9012e0abc626..a65f56a9cd3d 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -232,7 +232,7 @@ MODULE_DEVICE_TABLE(usb, ems_usb_table);
232#define INTR_IN_BUFFER_SIZE 4 232#define INTR_IN_BUFFER_SIZE 4
233 233
234#define MAX_RX_URBS 10 234#define MAX_RX_URBS 10
235#define MAX_TX_URBS CAN_ECHO_SKB_MAX 235#define MAX_TX_URBS 10
236 236
237struct ems_usb; 237struct ems_usb;
238 238
@@ -1012,7 +1012,7 @@ static int ems_usb_probe(struct usb_interface *intf,
1012 struct ems_usb *dev; 1012 struct ems_usb *dev;
1013 int i, err = -ENOMEM; 1013 int i, err = -ENOMEM;
1014 1014
1015 netdev = alloc_candev(sizeof(struct ems_usb)); 1015 netdev = alloc_candev(sizeof(struct ems_usb), MAX_TX_URBS);
1016 if (!netdev) { 1016 if (!netdev) {
1017 dev_err(netdev->dev.parent, "Couldn't alloc candev\n"); 1017 dev_err(netdev->dev.parent, "Couldn't alloc candev\n");
1018 return -ENOMEM; 1018 return -ENOMEM;
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 5824b20b5fcb..1d3f7f00e3af 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -29,8 +29,6 @@ enum can_mode {
29/* 29/*
30 * CAN common private data 30 * CAN common private data
31 */ 31 */
32#define CAN_ECHO_SKB_MAX 4
33
34struct can_priv { 32struct can_priv {
35 struct can_device_stats can_stats; 33 struct can_device_stats can_stats;
36 34
@@ -44,15 +42,16 @@ struct can_priv {
44 int restart_ms; 42 int restart_ms;
45 struct timer_list restart_timer; 43 struct timer_list restart_timer;
46 44
47 struct sk_buff *echo_skb[CAN_ECHO_SKB_MAX];
48
49 int (*do_set_bittiming)(struct net_device *dev); 45 int (*do_set_bittiming)(struct net_device *dev);
50 int (*do_set_mode)(struct net_device *dev, enum can_mode mode); 46 int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
51 int (*do_get_state)(const struct net_device *dev, 47 int (*do_get_state)(const struct net_device *dev,
52 enum can_state *state); 48 enum can_state *state);
49
50 unsigned int echo_skb_max;
51 struct sk_buff **echo_skb;
53}; 52};
54 53
55struct net_device *alloc_candev(int sizeof_priv); 54struct net_device *alloc_candev(int sizeof_priv, unsigned int echo_skb_max);
56void free_candev(struct net_device *dev); 55void free_candev(struct net_device *dev);
57 56
58int open_candev(struct net_device *dev); 57int open_candev(struct net_device *dev);
@@ -64,8 +63,9 @@ void unregister_candev(struct net_device *dev);
64int can_restart_now(struct net_device *dev); 63int can_restart_now(struct net_device *dev);
65void can_bus_off(struct net_device *dev); 64void can_bus_off(struct net_device *dev);
66 65
67void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, int idx); 66void can_put_echo_skb(struct sk_buff *skb, struct net_device *dev,
68void can_get_echo_skb(struct net_device *dev, int idx); 67 unsigned int idx);
69void can_free_echo_skb(struct net_device *dev, int idx); 68void can_get_echo_skb(struct net_device *dev, unsigned int idx);
69void can_free_echo_skb(struct net_device *dev, unsigned int idx);
70 70
71#endif /* CAN_DEV_H */ 71#endif /* CAN_DEV_H */