mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-09 07:23:14 +00:00
4c9258dd26
Save eight bytes of holes on x86-64 architectures by reordering struct can_priv members. Before: $ pahole -C can_priv drivers/net/can/dev/dev.o struct can_priv { struct net_device * dev; /* 0 8 */ struct can_device_stats can_stats; /* 8 24 */ struct can_bittiming bittiming; /* 32 32 */ /* --- cacheline 1 boundary (64 bytes) --- */ struct can_bittiming data_bittiming; /* 64 32 */ const struct can_bittiming_const * bittiming_const; /* 96 8 */ const struct can_bittiming_const * data_bittiming_const; /* 104 8 */ struct can_tdc tdc; /* 112 12 */ /* XXX 4 bytes hole, try to pack */ /* --- cacheline 2 boundary (128 bytes) --- */ const struct can_tdc_const * tdc_const; /* 128 8 */ const u16 * termination_const; /* 136 8 */ unsigned int termination_const_cnt; /* 144 4 */ u16 termination; /* 148 2 */ /* XXX 2 bytes hole, try to pack */ const u32 * bitrate_const; /* 152 8 */ unsigned int bitrate_const_cnt; /* 160 4 */ /* XXX 4 bytes hole, try to pack */ const u32 * data_bitrate_const; /* 168 8 */ unsigned int data_bitrate_const_cnt; /* 176 4 */ u32 bitrate_max; /* 180 4 */ struct can_clock clock; /* 184 4 */ enum can_state state; /* 188 4 */ /* --- cacheline 3 boundary (192 bytes) --- */ u32 ctrlmode; /* 192 4 */ u32 ctrlmode_supported; /* 196 4 */ u32 ctrlmode_static; /* 200 4 */ int restart_ms; /* 204 4 */ struct delayed_work restart_work; /* 208 168 */ /* XXX last struct has 4 bytes of padding */ /* --- cacheline 5 boundary (320 bytes) was 56 bytes ago --- */ int (*do_set_bittiming)(struct net_device *); /* 376 8 */ /* --- cacheline 6 boundary (384 bytes) --- */ int (*do_set_data_bittiming)(struct net_device *); /* 384 8 */ int (*do_set_mode)(struct net_device *, enum can_mode); /* 392 8 */ int (*do_set_termination)(struct net_device *, u16); /* 400 8 */ int (*do_get_state)(const struct net_device *, enum can_state *); /* 408 8 */ int (*do_get_berr_counter)(const struct net_device *, struct can_berr_counter *); /* 416 8 */ unsigned int echo_skb_max; /* 424 4 */ /* XXX 4 bytes hole, try to pack */ struct sk_buff * * echo_skb; /* 432 8 */ /* size: 440, cachelines: 7, members: 31 */ /* sum members: 426, holes: 4, sum holes: 14 */ /* paddings: 1, sum paddings: 4 */ /* last cacheline: 56 bytes */ }; After: $ pahole -C can_priv drivers/net/can/dev/dev.o struct can_priv { struct net_device * dev; /* 0 8 */ struct can_device_stats can_stats; /* 8 24 */ const struct can_bittiming_const * bittiming_const; /* 32 8 */ const struct can_bittiming_const * data_bittiming_const; /* 40 8 */ struct can_bittiming bittiming; /* 48 32 */ /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */ struct can_bittiming data_bittiming; /* 80 32 */ const struct can_tdc_const * tdc_const; /* 112 8 */ struct can_tdc tdc; /* 120 12 */ /* --- cacheline 2 boundary (128 bytes) was 4 bytes ago --- */ unsigned int bitrate_const_cnt; /* 132 4 */ const u32 * bitrate_const; /* 136 8 */ const u32 * data_bitrate_const; /* 144 8 */ unsigned int data_bitrate_const_cnt; /* 152 4 */ u32 bitrate_max; /* 156 4 */ struct can_clock clock; /* 160 4 */ unsigned int termination_const_cnt; /* 164 4 */ const u16 * termination_const; /* 168 8 */ u16 termination; /* 176 2 */ /* XXX 2 bytes hole, try to pack */ enum can_state state; /* 180 4 */ u32 ctrlmode; /* 184 4 */ u32 ctrlmode_supported; /* 188 4 */ /* --- cacheline 3 boundary (192 bytes) --- */ u32 ctrlmode_static; /* 192 4 */ int restart_ms; /* 196 4 */ struct delayed_work restart_work; /* 200 168 */ /* XXX last struct has 4 bytes of padding */ /* --- cacheline 5 boundary (320 bytes) was 48 bytes ago --- */ int (*do_set_bittiming)(struct net_device *); /* 368 8 */ int (*do_set_data_bittiming)(struct net_device *); /* 376 8 */ /* --- cacheline 6 boundary (384 bytes) --- */ int (*do_set_mode)(struct net_device *, enum can_mode); /* 384 8 */ int (*do_set_termination)(struct net_device *, u16); /* 392 8 */ int (*do_get_state)(const struct net_device *, enum can_state *); /* 400 8 */ int (*do_get_berr_counter)(const struct net_device *, struct can_berr_counter *); /* 408 8 */ unsigned int echo_skb_max; /* 416 4 */ /* XXX 4 bytes hole, try to pack */ struct sk_buff * * echo_skb; /* 424 8 */ /* size: 432, cachelines: 7, members: 31 */ /* sum members: 426, holes: 2, sum holes: 6 */ /* paddings: 1, sum paddings: 4 */ /* last cacheline: 48 bytes */ }; Link: https://lore.kernel.org/r/20210224002008.4158-3-mailhol.vincent@wanadoo.fr Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
145 lines
4.0 KiB
C
145 lines
4.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* linux/can/dev.h
|
|
*
|
|
* Definitions for the CAN network device driver interface
|
|
*
|
|
* Copyright (C) 2006 Andrey Volkov <avolkov@varma-el.com>
|
|
* Varma Electronics Oy
|
|
*
|
|
* Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
|
|
*
|
|
*/
|
|
|
|
#ifndef _CAN_DEV_H
|
|
#define _CAN_DEV_H
|
|
|
|
#include <linux/can.h>
|
|
#include <linux/can/bittiming.h>
|
|
#include <linux/can/error.h>
|
|
#include <linux/can/led.h>
|
|
#include <linux/can/length.h>
|
|
#include <linux/can/netlink.h>
|
|
#include <linux/can/skb.h>
|
|
#include <linux/netdevice.h>
|
|
|
|
/*
|
|
* CAN mode
|
|
*/
|
|
enum can_mode {
|
|
CAN_MODE_STOP = 0,
|
|
CAN_MODE_START,
|
|
CAN_MODE_SLEEP
|
|
};
|
|
|
|
/*
|
|
* CAN common private data
|
|
*/
|
|
struct can_priv {
|
|
struct net_device *dev;
|
|
struct can_device_stats can_stats;
|
|
|
|
const struct can_bittiming_const *bittiming_const,
|
|
*data_bittiming_const;
|
|
struct can_bittiming bittiming, data_bittiming;
|
|
const struct can_tdc_const *tdc_const;
|
|
struct can_tdc tdc;
|
|
|
|
unsigned int bitrate_const_cnt;
|
|
const u32 *bitrate_const;
|
|
const u32 *data_bitrate_const;
|
|
unsigned int data_bitrate_const_cnt;
|
|
u32 bitrate_max;
|
|
struct can_clock clock;
|
|
|
|
unsigned int termination_const_cnt;
|
|
const u16 *termination_const;
|
|
u16 termination;
|
|
|
|
enum can_state state;
|
|
|
|
/* CAN controller features - see include/uapi/linux/can/netlink.h */
|
|
u32 ctrlmode; /* current options setting */
|
|
u32 ctrlmode_supported; /* options that can be modified by netlink */
|
|
u32 ctrlmode_static; /* static enabled options for driver/hardware */
|
|
|
|
int restart_ms;
|
|
struct delayed_work restart_work;
|
|
|
|
int (*do_set_bittiming)(struct net_device *dev);
|
|
int (*do_set_data_bittiming)(struct net_device *dev);
|
|
int (*do_set_mode)(struct net_device *dev, enum can_mode mode);
|
|
int (*do_set_termination)(struct net_device *dev, u16 term);
|
|
int (*do_get_state)(const struct net_device *dev,
|
|
enum can_state *state);
|
|
int (*do_get_berr_counter)(const struct net_device *dev,
|
|
struct can_berr_counter *bec);
|
|
|
|
unsigned int echo_skb_max;
|
|
struct sk_buff **echo_skb;
|
|
|
|
#ifdef CONFIG_CAN_LEDS
|
|
struct led_trigger *tx_led_trig;
|
|
char tx_led_trig_name[CAN_LED_NAME_SZ];
|
|
struct led_trigger *rx_led_trig;
|
|
char rx_led_trig_name[CAN_LED_NAME_SZ];
|
|
struct led_trigger *rxtx_led_trig;
|
|
char rxtx_led_trig_name[CAN_LED_NAME_SZ];
|
|
#endif
|
|
};
|
|
|
|
|
|
/* helper to define static CAN controller features at device creation time */
|
|
static inline void can_set_static_ctrlmode(struct net_device *dev,
|
|
u32 static_mode)
|
|
{
|
|
struct can_priv *priv = netdev_priv(dev);
|
|
|
|
/* alloc_candev() succeeded => netdev_priv() is valid at this point */
|
|
priv->ctrlmode = static_mode;
|
|
priv->ctrlmode_static = static_mode;
|
|
|
|
/* override MTU which was set by default in can_setup()? */
|
|
if (static_mode & CAN_CTRLMODE_FD)
|
|
dev->mtu = CANFD_MTU;
|
|
}
|
|
|
|
void can_setup(struct net_device *dev);
|
|
|
|
struct net_device *alloc_candev_mqs(int sizeof_priv, unsigned int echo_skb_max,
|
|
unsigned int txqs, unsigned int rxqs);
|
|
#define alloc_candev(sizeof_priv, echo_skb_max) \
|
|
alloc_candev_mqs(sizeof_priv, echo_skb_max, 1, 1)
|
|
#define alloc_candev_mq(sizeof_priv, echo_skb_max, count) \
|
|
alloc_candev_mqs(sizeof_priv, echo_skb_max, count, count)
|
|
void free_candev(struct net_device *dev);
|
|
|
|
/* a candev safe wrapper around netdev_priv */
|
|
struct can_priv *safe_candev_priv(struct net_device *dev);
|
|
|
|
int open_candev(struct net_device *dev);
|
|
void close_candev(struct net_device *dev);
|
|
int can_change_mtu(struct net_device *dev, int new_mtu);
|
|
|
|
int register_candev(struct net_device *dev);
|
|
void unregister_candev(struct net_device *dev);
|
|
|
|
int can_restart_now(struct net_device *dev);
|
|
void can_bus_off(struct net_device *dev);
|
|
|
|
const char *can_get_state_str(const enum can_state state);
|
|
void can_change_state(struct net_device *dev, struct can_frame *cf,
|
|
enum can_state tx_state, enum can_state rx_state);
|
|
|
|
#ifdef CONFIG_OF
|
|
void of_can_transceiver(struct net_device *dev);
|
|
#else
|
|
static inline void of_can_transceiver(struct net_device *dev) { }
|
|
#endif
|
|
|
|
extern struct rtnl_link_ops can_link_ops;
|
|
int can_netlink_register(void);
|
|
void can_netlink_unregister(void);
|
|
|
|
#endif /* !_CAN_DEV_H */
|