Commit 542d0f60 authored by David S. Miller's avatar David S. Miller

Merge tag 'linux-can-fixes-for-5.5-20200102' of...

Merge tag 'linux-can-fixes-for-5.5-20200102' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can

Marc Kleine-Budde says:

====================
pull-request: can 2020-01-02

this is a pull request of 9 patches for net/master.

The first 5 patches target all the tcan4x5x driver. The first 3 patches
of them are by Dan Murphy and Sean Nyekjaer and improve the device
initialization (power on, reset and get device out of standby before
register access). The next patch is by Dan Murphy and disables the INH
pin device-state if the GPIO is unavailable. The last patch for the
tcan4x5x driver is by Gustavo A. R. Silva and fixes an inconsistent
PTR_ERR check in the tcan4x5x_parse_config() function.

The next patch is by Oliver Hartkopp and targets the generic CAN device
infrastructure. It ensures that an initialized headroom in outgoing CAN
sk_buffs (e.g. if injected by AF_PACKET).

The last 2 patches are by Johan Hovold and fix the kvaser_usb and gs_usb
drivers by always using the current alternate setting not blindly the
first one.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c72a0bc0 2d77bd61
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
#define TCAN4X5X_MODE_NORMAL BIT(7) #define TCAN4X5X_MODE_NORMAL BIT(7)
#define TCAN4X5X_DISABLE_WAKE_MSK (BIT(31) | BIT(30)) #define TCAN4X5X_DISABLE_WAKE_MSK (BIT(31) | BIT(30))
#define TCAN4X5X_DISABLE_INH_MSK BIT(9)
#define TCAN4X5X_SW_RESET BIT(2) #define TCAN4X5X_SW_RESET BIT(2)
...@@ -166,6 +167,28 @@ static void tcan4x5x_check_wake(struct tcan4x5x_priv *priv) ...@@ -166,6 +167,28 @@ static void tcan4x5x_check_wake(struct tcan4x5x_priv *priv)
} }
} }
static int tcan4x5x_reset(struct tcan4x5x_priv *priv)
{
int ret = 0;
if (priv->reset_gpio) {
gpiod_set_value(priv->reset_gpio, 1);
/* tpulse_width minimum 30us */
usleep_range(30, 100);
gpiod_set_value(priv->reset_gpio, 0);
} else {
ret = regmap_write(priv->regmap, TCAN4X5X_CONFIG,
TCAN4X5X_SW_RESET);
if (ret)
return ret;
}
usleep_range(700, 1000);
return ret;
}
static int regmap_spi_gather_write(void *context, const void *reg, static int regmap_spi_gather_write(void *context, const void *reg,
size_t reg_len, const void *val, size_t reg_len, const void *val,
size_t val_len) size_t val_len)
...@@ -348,14 +371,23 @@ static int tcan4x5x_disable_wake(struct m_can_classdev *cdev) ...@@ -348,14 +371,23 @@ static int tcan4x5x_disable_wake(struct m_can_classdev *cdev)
TCAN4X5X_DISABLE_WAKE_MSK, 0x00); TCAN4X5X_DISABLE_WAKE_MSK, 0x00);
} }
static int tcan4x5x_disable_state(struct m_can_classdev *cdev)
{
struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
return regmap_update_bits(tcan4x5x->regmap, TCAN4X5X_CONFIG,
TCAN4X5X_DISABLE_INH_MSK, 0x01);
}
static int tcan4x5x_parse_config(struct m_can_classdev *cdev) static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
{ {
struct tcan4x5x_priv *tcan4x5x = cdev->device_data; struct tcan4x5x_priv *tcan4x5x = cdev->device_data;
int ret;
tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake", tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake",
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
if (IS_ERR(tcan4x5x->device_wake_gpio)) { if (IS_ERR(tcan4x5x->device_wake_gpio)) {
if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER) if (PTR_ERR(tcan4x5x->device_wake_gpio) == -EPROBE_DEFER)
return -EPROBE_DEFER; return -EPROBE_DEFER;
tcan4x5x_disable_wake(cdev); tcan4x5x_disable_wake(cdev);
...@@ -366,18 +398,17 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev) ...@@ -366,18 +398,17 @@ static int tcan4x5x_parse_config(struct m_can_classdev *cdev)
if (IS_ERR(tcan4x5x->reset_gpio)) if (IS_ERR(tcan4x5x->reset_gpio))
tcan4x5x->reset_gpio = NULL; tcan4x5x->reset_gpio = NULL;
usleep_range(700, 1000); ret = tcan4x5x_reset(tcan4x5x);
if (ret)
return ret;
tcan4x5x->device_state_gpio = devm_gpiod_get_optional(cdev->dev, tcan4x5x->device_state_gpio = devm_gpiod_get_optional(cdev->dev,
"device-state", "device-state",
GPIOD_IN); GPIOD_IN);
if (IS_ERR(tcan4x5x->device_state_gpio)) if (IS_ERR(tcan4x5x->device_state_gpio)) {
tcan4x5x->device_state_gpio = NULL; tcan4x5x->device_state_gpio = NULL;
tcan4x5x_disable_state(cdev);
tcan4x5x->power = devm_regulator_get_optional(cdev->dev, }
"vsup");
if (PTR_ERR(tcan4x5x->power) == -EPROBE_DEFER)
return -EPROBE_DEFER;
return 0; return 0;
} }
...@@ -412,6 +443,12 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -412,6 +443,12 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
priv->power = devm_regulator_get_optional(&spi->dev, "vsup");
if (PTR_ERR(priv->power) == -EPROBE_DEFER)
return -EPROBE_DEFER;
else
priv->power = NULL;
mcan_class->device_data = priv; mcan_class->device_data = priv;
m_can_class_get_clocks(mcan_class); m_can_class_get_clocks(mcan_class);
...@@ -451,11 +488,17 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -451,11 +488,17 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus, priv->regmap = devm_regmap_init(&spi->dev, &tcan4x5x_bus,
&spi->dev, &tcan4x5x_regmap); &spi->dev, &tcan4x5x_regmap);
ret = tcan4x5x_parse_config(mcan_class); ret = tcan4x5x_power_enable(priv->power, 1);
if (ret) if (ret)
goto out_clk; goto out_clk;
tcan4x5x_power_enable(priv->power, 1); ret = tcan4x5x_parse_config(mcan_class);
if (ret)
goto out_power;
ret = tcan4x5x_init(mcan_class);
if (ret)
goto out_power;
ret = m_can_class_register(mcan_class); ret = m_can_class_register(mcan_class);
if (ret) if (ret)
......
...@@ -381,13 +381,12 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota) ...@@ -381,13 +381,12 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota)
struct net_device *dev = napi->dev; struct net_device *dev = napi->dev;
struct mscan_regs __iomem *regs = priv->reg_base; struct mscan_regs __iomem *regs = priv->reg_base;
struct net_device_stats *stats = &dev->stats; struct net_device_stats *stats = &dev->stats;
int npackets = 0; int work_done = 0;
int ret = 1;
struct sk_buff *skb; struct sk_buff *skb;
struct can_frame *frame; struct can_frame *frame;
u8 canrflg; u8 canrflg;
while (npackets < quota) { while (work_done < quota) {
canrflg = in_8(&regs->canrflg); canrflg = in_8(&regs->canrflg);
if (!(canrflg & (MSCAN_RXF | MSCAN_ERR_IF))) if (!(canrflg & (MSCAN_RXF | MSCAN_ERR_IF)))
break; break;
...@@ -408,18 +407,18 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota) ...@@ -408,18 +407,18 @@ static int mscan_rx_poll(struct napi_struct *napi, int quota)
stats->rx_packets++; stats->rx_packets++;
stats->rx_bytes += frame->can_dlc; stats->rx_bytes += frame->can_dlc;
npackets++; work_done++;
netif_receive_skb(skb); netif_receive_skb(skb);
} }
if (!(in_8(&regs->canrflg) & (MSCAN_RXF | MSCAN_ERR_IF))) { if (work_done < quota) {
napi_complete(&priv->napi); if (likely(napi_complete_done(&priv->napi, work_done))) {
clear_bit(F_RX_PROGRESS, &priv->flags); clear_bit(F_RX_PROGRESS, &priv->flags);
if (priv->can.state < CAN_STATE_BUS_OFF) if (priv->can.state < CAN_STATE_BUS_OFF)
out_8(&regs->canrier, priv->shadow_canrier); out_8(&regs->canrier, priv->shadow_canrier);
ret = 0; }
} }
return ret; return work_done;
} }
static irqreturn_t mscan_isr(int irq, void *dev_id) static irqreturn_t mscan_isr(int irq, void *dev_id)
......
...@@ -918,7 +918,7 @@ static int gs_usb_probe(struct usb_interface *intf, ...@@ -918,7 +918,7 @@ static int gs_usb_probe(struct usb_interface *intf,
GS_USB_BREQ_HOST_FORMAT, GS_USB_BREQ_HOST_FORMAT,
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1, 1,
intf->altsetting[0].desc.bInterfaceNumber, intf->cur_altsetting->desc.bInterfaceNumber,
hconf, hconf,
sizeof(*hconf), sizeof(*hconf),
1000); 1000);
...@@ -941,7 +941,7 @@ static int gs_usb_probe(struct usb_interface *intf, ...@@ -941,7 +941,7 @@ static int gs_usb_probe(struct usb_interface *intf,
GS_USB_BREQ_DEVICE_CONFIG, GS_USB_BREQ_DEVICE_CONFIG,
USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1, 1,
intf->altsetting[0].desc.bInterfaceNumber, intf->cur_altsetting->desc.bInterfaceNumber,
dconf, dconf,
sizeof(*dconf), sizeof(*dconf),
1000); 1000);
......
...@@ -1590,7 +1590,7 @@ static int kvaser_usb_hydra_setup_endpoints(struct kvaser_usb *dev) ...@@ -1590,7 +1590,7 @@ static int kvaser_usb_hydra_setup_endpoints(struct kvaser_usb *dev)
struct usb_endpoint_descriptor *ep; struct usb_endpoint_descriptor *ep;
int i; int i;
iface_desc = &dev->intf->altsetting[0]; iface_desc = dev->intf->cur_altsetting;
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
ep = &iface_desc->endpoint[i].desc; ep = &iface_desc->endpoint[i].desc;
......
...@@ -1310,7 +1310,7 @@ static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev) ...@@ -1310,7 +1310,7 @@ static int kvaser_usb_leaf_setup_endpoints(struct kvaser_usb *dev)
struct usb_endpoint_descriptor *endpoint; struct usb_endpoint_descriptor *endpoint;
int i; int i;
iface_desc = &dev->intf->altsetting[0]; iface_desc = dev->intf->cur_altsetting;
for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
endpoint = &iface_desc->endpoint[i].desc; endpoint = &iface_desc->endpoint[i].desc;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/can/error.h> #include <linux/can/error.h>
#include <linux/can/led.h> #include <linux/can/led.h>
#include <linux/can/netlink.h> #include <linux/can/netlink.h>
#include <linux/can/skb.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
/* /*
...@@ -91,6 +92,36 @@ struct can_priv { ...@@ -91,6 +92,36 @@ struct can_priv {
#define get_can_dlc(i) (min_t(__u8, (i), CAN_MAX_DLC)) #define get_can_dlc(i) (min_t(__u8, (i), CAN_MAX_DLC))
#define get_canfd_dlc(i) (min_t(__u8, (i), CANFD_MAX_DLC)) #define get_canfd_dlc(i) (min_t(__u8, (i), CANFD_MAX_DLC))
/* Check for outgoing skbs that have not been created by the CAN subsystem */
static inline bool can_skb_headroom_valid(struct net_device *dev,
struct sk_buff *skb)
{
/* af_packet creates a headroom of HH_DATA_MOD bytes which is fine */
if (WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct can_skb_priv)))
return false;
/* af_packet does not apply CAN skb specific settings */
if (skb->ip_summed == CHECKSUM_NONE) {
/* init headroom */
can_skb_prv(skb)->ifindex = dev->ifindex;
can_skb_prv(skb)->skbcnt = 0;
skb->ip_summed = CHECKSUM_UNNECESSARY;
/* preform proper loopback on capable devices */
if (dev->flags & IFF_ECHO)
skb->pkt_type = PACKET_LOOPBACK;
else
skb->pkt_type = PACKET_HOST;
skb_reset_mac_header(skb);
skb_reset_network_header(skb);
skb_reset_transport_header(skb);
}
return true;
}
/* Drop a given socketbuffer if it does not contain a valid CAN frame. */ /* Drop a given socketbuffer if it does not contain a valid CAN frame. */
static inline bool can_dropped_invalid_skb(struct net_device *dev, static inline bool can_dropped_invalid_skb(struct net_device *dev,
struct sk_buff *skb) struct sk_buff *skb)
...@@ -108,6 +139,9 @@ static inline bool can_dropped_invalid_skb(struct net_device *dev, ...@@ -108,6 +139,9 @@ static inline bool can_dropped_invalid_skb(struct net_device *dev,
} else } else
goto inval_skb; goto inval_skb;
if (!can_skb_headroom_valid(dev, skb))
goto inval_skb;
return false; return false;
inval_skb: inval_skb:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment