2019-04-27 01:12:23 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-01-16 08:12:50 +08:00
|
|
|
/*
|
|
|
|
* Keystone NetCP Core driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Texas Instruments Incorporated
|
|
|
|
* Authors: Sandeep Nair <sandeep_n@ti.com>
|
|
|
|
* Sandeep Paulraj <s-paulraj@ti.com>
|
|
|
|
* Cyril Chemparathy <cyril@ti.com>
|
|
|
|
* Santosh Shilimkar <santosh.shilimkar@ti.com>
|
|
|
|
* Murali Karicheri <m-karicheri2@ti.com>
|
|
|
|
* Wingman Kwok <w-kwok2@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_net.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/if_vlan.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/soc/ti/knav_qmss.h>
|
|
|
|
#include <linux/soc/ti/knav_dma.h>
|
|
|
|
|
|
|
|
#include "netcp.h"
|
|
|
|
|
|
|
|
#define NETCP_SOP_OFFSET (NET_IP_ALIGN + NET_SKB_PAD)
|
|
|
|
#define NETCP_NAPI_WEIGHT 64
|
|
|
|
#define NETCP_TX_TIMEOUT (5 * HZ)
|
2015-08-05 04:56:53 +08:00
|
|
|
#define NETCP_PACKET_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN)
|
2015-01-16 08:12:50 +08:00
|
|
|
#define NETCP_MIN_PACKET_SIZE ETH_ZLEN
|
|
|
|
#define NETCP_MAX_MCAST_ADDR 16
|
|
|
|
|
|
|
|
#define NETCP_EFUSE_REG_INDEX 0
|
|
|
|
|
|
|
|
#define NETCP_MOD_PROBE_SKIPPED 1
|
|
|
|
#define NETCP_MOD_PROBE_FAILED 2
|
|
|
|
|
|
|
|
#define NETCP_DEBUG (NETIF_MSG_HW | NETIF_MSG_WOL | \
|
|
|
|
NETIF_MSG_DRV | NETIF_MSG_LINK | \
|
|
|
|
NETIF_MSG_IFUP | NETIF_MSG_INTR | \
|
|
|
|
NETIF_MSG_PROBE | NETIF_MSG_TIMER | \
|
|
|
|
NETIF_MSG_IFDOWN | NETIF_MSG_RX_ERR | \
|
|
|
|
NETIF_MSG_TX_ERR | NETIF_MSG_TX_DONE | \
|
|
|
|
NETIF_MSG_PKTDATA | NETIF_MSG_TX_QUEUED | \
|
|
|
|
NETIF_MSG_RX_STATUS)
|
|
|
|
|
2015-07-29 04:01:11 +08:00
|
|
|
#define NETCP_EFUSE_ADDR_SWAP 2
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
#define knav_queue_get_id(q) knav_queue_device_control(q, \
|
|
|
|
KNAV_QUEUE_GET_ID, (unsigned long)NULL)
|
|
|
|
|
|
|
|
#define knav_queue_enable_notify(q) knav_queue_device_control(q, \
|
|
|
|
KNAV_QUEUE_ENABLE_NOTIFY, \
|
|
|
|
(unsigned long)NULL)
|
|
|
|
|
|
|
|
#define knav_queue_disable_notify(q) knav_queue_device_control(q, \
|
|
|
|
KNAV_QUEUE_DISABLE_NOTIFY, \
|
|
|
|
(unsigned long)NULL)
|
|
|
|
|
|
|
|
#define knav_queue_get_count(q) knav_queue_device_control(q, \
|
|
|
|
KNAV_QUEUE_GET_COUNT, (unsigned long)NULL)
|
|
|
|
|
|
|
|
#define for_each_netcp_module(module) \
|
|
|
|
list_for_each_entry(module, &netcp_modules, module_list)
|
|
|
|
|
|
|
|
#define for_each_netcp_device_module(netcp_device, inst_modpriv) \
|
|
|
|
list_for_each_entry(inst_modpriv, \
|
|
|
|
&((netcp_device)->modpriv_head), inst_list)
|
|
|
|
|
|
|
|
#define for_each_module(netcp, intf_modpriv) \
|
|
|
|
list_for_each_entry(intf_modpriv, &netcp->module_head, intf_list)
|
|
|
|
|
|
|
|
/* Module management structures */
|
|
|
|
struct netcp_device {
|
|
|
|
struct list_head device_list;
|
|
|
|
struct list_head interface_head;
|
|
|
|
struct list_head modpriv_head;
|
|
|
|
struct device *device;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct netcp_inst_modpriv {
|
|
|
|
struct netcp_device *netcp_device;
|
|
|
|
struct netcp_module *netcp_module;
|
|
|
|
struct list_head inst_list;
|
|
|
|
void *module_priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct netcp_intf_modpriv {
|
|
|
|
struct netcp_intf *netcp_priv;
|
|
|
|
struct netcp_module *netcp_module;
|
|
|
|
struct list_head intf_list;
|
|
|
|
void *module_priv;
|
|
|
|
};
|
|
|
|
|
2016-12-09 06:21:56 +08:00
|
|
|
struct netcp_tx_cb {
|
|
|
|
void *ts_context;
|
|
|
|
void (*txtstamp)(void *context, struct sk_buff *skb);
|
|
|
|
};
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
static LIST_HEAD(netcp_devices);
|
|
|
|
static LIST_HEAD(netcp_modules);
|
|
|
|
static DEFINE_MUTEX(netcp_modules_lock);
|
|
|
|
|
|
|
|
static int netcp_debug_level = -1;
|
|
|
|
module_param(netcp_debug_level, int, 0);
|
|
|
|
MODULE_PARM_DESC(netcp_debug_level, "Netcp debug level (NETIF_MSG bits) (0=none,...,16=all)");
|
|
|
|
|
|
|
|
/* Helper functions - Get/Set */
|
2015-12-08 23:32:27 +08:00
|
|
|
static void get_pkt_info(dma_addr_t *buff, u32 *buff_len, dma_addr_t *ndesc,
|
2015-01-16 08:12:50 +08:00
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
2015-12-08 23:32:27 +08:00
|
|
|
*buff_len = le32_to_cpu(desc->buff_len);
|
|
|
|
*buff = le32_to_cpu(desc->buff);
|
|
|
|
*ndesc = le32_to_cpu(desc->next_desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2017-01-07 04:37:39 +08:00
|
|
|
static void get_desc_info(u32 *desc_info, u32 *pkt_info,
|
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
|
|
|
*desc_info = le32_to_cpu(desc->desc_info);
|
|
|
|
*pkt_info = le32_to_cpu(desc->packet_info);
|
|
|
|
}
|
|
|
|
|
2016-02-20 01:58:44 +08:00
|
|
|
static u32 get_sw_data(int index, struct knav_dma_desc *desc)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
2016-02-20 01:58:43 +08:00
|
|
|
/* No Endian conversion needed as this data is untouched by hw */
|
2016-02-20 01:58:44 +08:00
|
|
|
return desc->sw_data[index];
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 01:58:44 +08:00
|
|
|
/* use these macros to get sw data */
|
|
|
|
#define GET_SW_DATA0(desc) get_sw_data(0, desc)
|
|
|
|
#define GET_SW_DATA1(desc) get_sw_data(1, desc)
|
|
|
|
#define GET_SW_DATA2(desc) get_sw_data(2, desc)
|
|
|
|
#define GET_SW_DATA3(desc) get_sw_data(3, desc)
|
2015-12-08 23:32:27 +08:00
|
|
|
|
|
|
|
static void get_org_pkt_info(dma_addr_t *buff, u32 *buff_len,
|
2015-01-16 08:12:50 +08:00
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
2015-12-08 23:32:27 +08:00
|
|
|
*buff = le32_to_cpu(desc->orig_buff);
|
|
|
|
*buff_len = le32_to_cpu(desc->orig_len);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2015-12-08 23:32:27 +08:00
|
|
|
static void get_words(dma_addr_t *words, int num_words, __le32 *desc)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_words; i++)
|
2015-12-08 23:32:27 +08:00
|
|
|
words[i] = le32_to_cpu(desc[i]);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2015-12-08 23:32:27 +08:00
|
|
|
static void set_pkt_info(dma_addr_t buff, u32 buff_len, u32 ndesc,
|
2015-01-16 08:12:50 +08:00
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
2015-12-08 23:32:27 +08:00
|
|
|
desc->buff_len = cpu_to_le32(buff_len);
|
|
|
|
desc->buff = cpu_to_le32(buff);
|
|
|
|
desc->next_desc = cpu_to_le32(ndesc);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void set_desc_info(u32 desc_info, u32 pkt_info,
|
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
2015-12-08 23:32:27 +08:00
|
|
|
desc->desc_info = cpu_to_le32(desc_info);
|
|
|
|
desc->packet_info = cpu_to_le32(pkt_info);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 01:58:44 +08:00
|
|
|
static void set_sw_data(int index, u32 data, struct knav_dma_desc *desc)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
2016-02-20 01:58:43 +08:00
|
|
|
/* No Endian conversion needed as this data is untouched by hw */
|
2016-02-20 01:58:44 +08:00
|
|
|
desc->sw_data[index] = data;
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2016-02-20 01:58:44 +08:00
|
|
|
/* use these macros to set sw data */
|
|
|
|
#define SET_SW_DATA0(data, desc) set_sw_data(0, data, desc)
|
|
|
|
#define SET_SW_DATA1(data, desc) set_sw_data(1, data, desc)
|
|
|
|
#define SET_SW_DATA2(data, desc) set_sw_data(2, data, desc)
|
|
|
|
#define SET_SW_DATA3(data, desc) set_sw_data(3, data, desc)
|
|
|
|
|
2015-12-08 23:32:27 +08:00
|
|
|
static void set_org_pkt_info(dma_addr_t buff, u32 buff_len,
|
2015-01-16 08:12:50 +08:00
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
2015-12-08 23:32:27 +08:00
|
|
|
desc->orig_buff = cpu_to_le32(buff);
|
|
|
|
desc->orig_len = cpu_to_le32(buff_len);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
2015-12-08 23:32:27 +08:00
|
|
|
static void set_words(u32 *words, int num_words, __le32 *desc)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_words; i++)
|
2015-12-08 23:32:27 +08:00
|
|
|
desc[i] = cpu_to_le32(words[i]);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the e-fuse value as 32 bit values to be endian independent */
|
2015-07-29 04:01:11 +08:00
|
|
|
static int emac_arch_get_mac_addr(char *x, void __iomem *efuse_mac, u32 swap)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
|
|
|
unsigned int addr0, addr1;
|
|
|
|
|
|
|
|
addr1 = readl(efuse_mac + 4);
|
|
|
|
addr0 = readl(efuse_mac);
|
|
|
|
|
2015-07-29 04:01:11 +08:00
|
|
|
switch (swap) {
|
|
|
|
case NETCP_EFUSE_ADDR_SWAP:
|
|
|
|
addr0 = addr1;
|
|
|
|
addr1 = readl(efuse_mac);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
x[0] = (addr1 & 0x0000ff00) >> 8;
|
|
|
|
x[1] = addr1 & 0x000000ff;
|
|
|
|
x[2] = (addr0 & 0xff000000) >> 24;
|
|
|
|
x[3] = (addr0 & 0x00ff0000) >> 16;
|
|
|
|
x[4] = (addr0 & 0x0000ff00) >> 8;
|
|
|
|
x[5] = addr0 & 0x000000ff;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Module management routines */
|
|
|
|
static int netcp_register_interface(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = register_netdev(netcp->ndev);
|
|
|
|
if (!ret)
|
|
|
|
netcp->netdev_registered = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_module_probe(struct netcp_device *netcp_device,
|
|
|
|
struct netcp_module *module)
|
|
|
|
{
|
|
|
|
struct device *dev = netcp_device->device;
|
|
|
|
struct device_node *devices, *interface, *node = dev->of_node;
|
|
|
|
struct device_node *child;
|
|
|
|
struct netcp_inst_modpriv *inst_modpriv;
|
|
|
|
struct netcp_intf *netcp_intf;
|
|
|
|
struct netcp_module *tmp;
|
|
|
|
bool primary_module_registered = false;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Find this module in the sub-tree for this device */
|
|
|
|
devices = of_get_child_by_name(node, "netcp-devices");
|
|
|
|
if (!devices) {
|
|
|
|
dev_err(dev, "could not find netcp-devices node\n");
|
|
|
|
return NETCP_MOD_PROBE_SKIPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_available_child_of_node(devices, child) {
|
2018-08-28 23:44:30 +08:00
|
|
|
const char *name;
|
|
|
|
char node_name[32];
|
2015-01-16 08:12:50 +08:00
|
|
|
|
2019-02-19 04:10:51 +08:00
|
|
|
if (of_property_read_string(child, "label", &name) < 0) {
|
2018-08-28 23:44:30 +08:00
|
|
|
snprintf(node_name, sizeof(node_name), "%pOFn", child);
|
|
|
|
name = node_name;
|
|
|
|
}
|
2015-01-16 08:12:50 +08:00
|
|
|
if (!strcasecmp(module->name, name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
of_node_put(devices);
|
|
|
|
/* If module not used for this device, skip it */
|
|
|
|
if (!child) {
|
|
|
|
dev_warn(dev, "module(%s) not used for device\n", module->name);
|
|
|
|
return NETCP_MOD_PROBE_SKIPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
inst_modpriv = devm_kzalloc(dev, sizeof(*inst_modpriv), GFP_KERNEL);
|
|
|
|
if (!inst_modpriv) {
|
|
|
|
of_node_put(child);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
inst_modpriv->netcp_device = netcp_device;
|
|
|
|
inst_modpriv->netcp_module = module;
|
|
|
|
list_add_tail(&inst_modpriv->inst_list, &netcp_device->modpriv_head);
|
|
|
|
|
|
|
|
ret = module->probe(netcp_device, dev, child,
|
|
|
|
&inst_modpriv->module_priv);
|
|
|
|
of_node_put(child);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Probe of module(%s) failed with %d\n",
|
|
|
|
module->name, ret);
|
|
|
|
list_del(&inst_modpriv->inst_list);
|
|
|
|
devm_kfree(dev, inst_modpriv);
|
|
|
|
return NETCP_MOD_PROBE_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach modules only if the primary module is probed */
|
|
|
|
for_each_netcp_module(tmp) {
|
|
|
|
if (tmp->primary)
|
|
|
|
primary_module_registered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!primary_module_registered)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Attach module to interfaces */
|
|
|
|
list_for_each_entry(netcp_intf, &netcp_device->interface_head,
|
|
|
|
interface_list) {
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
|
|
|
|
intf_modpriv = devm_kzalloc(dev, sizeof(*intf_modpriv),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!intf_modpriv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
interface = of_parse_phandle(netcp_intf->node_interface,
|
|
|
|
module->name, 0);
|
|
|
|
|
2015-09-24 01:37:09 +08:00
|
|
|
if (!interface) {
|
|
|
|
devm_kfree(dev, intf_modpriv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
intf_modpriv->netcp_priv = netcp_intf;
|
|
|
|
intf_modpriv->netcp_module = module;
|
|
|
|
list_add_tail(&intf_modpriv->intf_list,
|
|
|
|
&netcp_intf->module_head);
|
|
|
|
|
|
|
|
ret = module->attach(inst_modpriv->module_priv,
|
|
|
|
netcp_intf->ndev, interface,
|
|
|
|
&intf_modpriv->module_priv);
|
|
|
|
of_node_put(interface);
|
|
|
|
if (ret) {
|
|
|
|
dev_dbg(dev, "Attach of module %s declined with %d\n",
|
|
|
|
module->name, ret);
|
|
|
|
list_del(&intf_modpriv->intf_list);
|
|
|
|
devm_kfree(dev, intf_modpriv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2015-09-24 01:37:07 +08:00
|
|
|
|
|
|
|
/* Now register the interface with netdev */
|
|
|
|
list_for_each_entry(netcp_intf,
|
|
|
|
&netcp_device->interface_head,
|
|
|
|
interface_list) {
|
|
|
|
/* If interface not registered then register now */
|
|
|
|
if (!netcp_intf->netdev_registered) {
|
|
|
|
ret = netcp_register_interface(netcp_intf);
|
|
|
|
if (ret)
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
2015-01-16 08:12:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int netcp_register_module(struct netcp_module *module)
|
|
|
|
{
|
|
|
|
struct netcp_device *netcp_device;
|
|
|
|
struct netcp_module *tmp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!module->name) {
|
|
|
|
WARN(1, "error registering netcp module: no name\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!module->probe) {
|
|
|
|
WARN(1, "error registering netcp module: no probe\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_lock(&netcp_modules_lock);
|
|
|
|
|
|
|
|
for_each_netcp_module(tmp) {
|
|
|
|
if (!strcasecmp(tmp->name, module->name)) {
|
|
|
|
mutex_unlock(&netcp_modules_lock);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
list_add_tail(&module->module_list, &netcp_modules);
|
|
|
|
|
|
|
|
list_for_each_entry(netcp_device, &netcp_devices, device_list) {
|
|
|
|
ret = netcp_module_probe(netcp_device, module);
|
|
|
|
if (ret < 0)
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
mutex_unlock(&netcp_modules_lock);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
mutex_unlock(&netcp_modules_lock);
|
|
|
|
netcp_unregister_module(module);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_register_module);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
static void netcp_release_module(struct netcp_device *netcp_device,
|
|
|
|
struct netcp_module *module)
|
|
|
|
{
|
|
|
|
struct netcp_inst_modpriv *inst_modpriv, *inst_tmp;
|
|
|
|
struct netcp_intf *netcp_intf, *netcp_tmp;
|
|
|
|
struct device *dev = netcp_device->device;
|
|
|
|
|
|
|
|
/* Release the module from each interface */
|
|
|
|
list_for_each_entry_safe(netcp_intf, netcp_tmp,
|
|
|
|
&netcp_device->interface_head,
|
|
|
|
interface_list) {
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv, *intf_tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(intf_modpriv, intf_tmp,
|
|
|
|
&netcp_intf->module_head,
|
|
|
|
intf_list) {
|
|
|
|
if (intf_modpriv->netcp_module == module) {
|
|
|
|
module->release(intf_modpriv->module_priv);
|
|
|
|
list_del(&intf_modpriv->intf_list);
|
|
|
|
devm_kfree(dev, intf_modpriv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the module from each instance */
|
|
|
|
list_for_each_entry_safe(inst_modpriv, inst_tmp,
|
|
|
|
&netcp_device->modpriv_head, inst_list) {
|
|
|
|
if (inst_modpriv->netcp_module == module) {
|
|
|
|
module->remove(netcp_device,
|
|
|
|
inst_modpriv->module_priv);
|
|
|
|
list_del(&inst_modpriv->inst_list);
|
|
|
|
devm_kfree(dev, inst_modpriv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void netcp_unregister_module(struct netcp_module *module)
|
|
|
|
{
|
|
|
|
struct netcp_device *netcp_device;
|
|
|
|
struct netcp_module *module_tmp;
|
|
|
|
|
|
|
|
mutex_lock(&netcp_modules_lock);
|
|
|
|
|
|
|
|
list_for_each_entry(netcp_device, &netcp_devices, device_list) {
|
|
|
|
netcp_release_module(netcp_device, module);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the module from the module list */
|
|
|
|
for_each_netcp_module(module_tmp) {
|
|
|
|
if (module == module_tmp) {
|
|
|
|
list_del(&module->module_list);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&netcp_modules_lock);
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_unregister_module);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
void *netcp_module_get_intf_data(struct netcp_module *module,
|
|
|
|
struct netcp_intf *intf)
|
|
|
|
{
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
|
|
|
|
list_for_each_entry(intf_modpriv, &intf->module_head, intf_list)
|
|
|
|
if (intf_modpriv->netcp_module == module)
|
|
|
|
return intf_modpriv->module_priv;
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_module_get_intf_data);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* Module TX and RX Hook management */
|
|
|
|
struct netcp_hook_list {
|
|
|
|
struct list_head list;
|
|
|
|
netcp_hook_rtn *hook_rtn;
|
|
|
|
void *hook_data;
|
|
|
|
int order;
|
|
|
|
};
|
|
|
|
|
|
|
|
int netcp_register_txhook(struct netcp_intf *netcp_priv, int order,
|
|
|
|
netcp_hook_rtn *hook_rtn, void *hook_data)
|
|
|
|
{
|
|
|
|
struct netcp_hook_list *entry;
|
|
|
|
struct netcp_hook_list *next;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL);
|
|
|
|
if (!entry)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
entry->hook_rtn = hook_rtn;
|
|
|
|
entry->hook_data = hook_data;
|
|
|
|
entry->order = order;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&netcp_priv->lock, flags);
|
|
|
|
list_for_each_entry(next, &netcp_priv->txhook_list_head, list) {
|
|
|
|
if (next->order > order)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__list_add(&entry->list, next->list.prev, &next->list);
|
|
|
|
spin_unlock_irqrestore(&netcp_priv->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_register_txhook);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
int netcp_unregister_txhook(struct netcp_intf *netcp_priv, int order,
|
|
|
|
netcp_hook_rtn *hook_rtn, void *hook_data)
|
|
|
|
{
|
|
|
|
struct netcp_hook_list *next, *n;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&netcp_priv->lock, flags);
|
|
|
|
list_for_each_entry_safe(next, n, &netcp_priv->txhook_list_head, list) {
|
|
|
|
if ((next->order == order) &&
|
|
|
|
(next->hook_rtn == hook_rtn) &&
|
|
|
|
(next->hook_data == hook_data)) {
|
|
|
|
list_del(&next->list);
|
|
|
|
spin_unlock_irqrestore(&netcp_priv->lock, flags);
|
|
|
|
devm_kfree(netcp_priv->dev, next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&netcp_priv->lock, flags);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_unregister_txhook);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
int netcp_register_rxhook(struct netcp_intf *netcp_priv, int order,
|
|
|
|
netcp_hook_rtn *hook_rtn, void *hook_data)
|
|
|
|
{
|
|
|
|
struct netcp_hook_list *entry;
|
|
|
|
struct netcp_hook_list *next;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
entry = devm_kzalloc(netcp_priv->dev, sizeof(*entry), GFP_KERNEL);
|
|
|
|
if (!entry)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
entry->hook_rtn = hook_rtn;
|
|
|
|
entry->hook_data = hook_data;
|
|
|
|
entry->order = order;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&netcp_priv->lock, flags);
|
|
|
|
list_for_each_entry(next, &netcp_priv->rxhook_list_head, list) {
|
|
|
|
if (next->order > order)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
__list_add(&entry->list, next->list.prev, &next->list);
|
|
|
|
spin_unlock_irqrestore(&netcp_priv->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-09 06:21:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_register_rxhook);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
int netcp_unregister_rxhook(struct netcp_intf *netcp_priv, int order,
|
|
|
|
netcp_hook_rtn *hook_rtn, void *hook_data)
|
|
|
|
{
|
|
|
|
struct netcp_hook_list *next, *n;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&netcp_priv->lock, flags);
|
|
|
|
list_for_each_entry_safe(next, n, &netcp_priv->rxhook_list_head, list) {
|
|
|
|
if ((next->order == order) &&
|
|
|
|
(next->hook_rtn == hook_rtn) &&
|
|
|
|
(next->hook_data == hook_data)) {
|
|
|
|
list_del(&next->list);
|
|
|
|
spin_unlock_irqrestore(&netcp_priv->lock, flags);
|
|
|
|
devm_kfree(netcp_priv->dev, next);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&netcp_priv->lock, flags);
|
|
|
|
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
2016-12-09 06:21:56 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_unregister_rxhook);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
static void netcp_frag_free(bool is_frag, void *ptr)
|
|
|
|
{
|
|
|
|
if (is_frag)
|
2015-05-07 12:12:08 +08:00
|
|
|
skb_free_frag(ptr);
|
2015-01-16 08:12:50 +08:00
|
|
|
else
|
|
|
|
kfree(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_free_rx_desc_chain(struct netcp_intf *netcp,
|
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
|
|
|
struct knav_dma_desc *ndesc;
|
|
|
|
dma_addr_t dma_desc, dma_buf;
|
|
|
|
unsigned int buf_len, dma_sz = sizeof(*ndesc);
|
|
|
|
void *buf_ptr;
|
2015-12-18 22:18:08 +08:00
|
|
|
u32 tmp;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
get_words(&dma_desc, 1, &desc->next_desc);
|
|
|
|
|
|
|
|
while (dma_desc) {
|
|
|
|
ndesc = knav_pool_desc_unmap(netcp->rx_pool, dma_desc, dma_sz);
|
|
|
|
if (unlikely(!ndesc)) {
|
|
|
|
dev_err(netcp->ndev_dev, "failed to unmap Rx desc\n");
|
|
|
|
break;
|
|
|
|
}
|
2015-12-18 22:18:08 +08:00
|
|
|
get_pkt_info(&dma_buf, &tmp, &dma_desc, ndesc);
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are retrieving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
|
|
|
buf_ptr = (void *)GET_SW_DATA0(ndesc);
|
|
|
|
buf_len = (int)GET_SW_DATA1(desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
dma_unmap_page(netcp->dev, dma_buf, PAGE_SIZE, DMA_FROM_DEVICE);
|
|
|
|
__free_page(buf_ptr);
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
|
|
|
}
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are retrieving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
|
|
|
buf_ptr = (void *)GET_SW_DATA0(desc);
|
|
|
|
buf_len = (int)GET_SW_DATA1(desc);
|
2015-12-08 23:32:27 +08:00
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
if (buf_ptr)
|
|
|
|
netcp_frag_free(buf_len <= PAGE_SIZE, buf_ptr);
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_empty_rx_queue(struct netcp_intf *netcp)
|
|
|
|
{
|
2017-01-07 04:37:41 +08:00
|
|
|
struct netcp_stats *rx_stats = &netcp->stats;
|
2015-01-16 08:12:50 +08:00
|
|
|
struct knav_dma_desc *desc;
|
|
|
|
unsigned int dma_sz;
|
|
|
|
dma_addr_t dma;
|
|
|
|
|
|
|
|
for (; ;) {
|
|
|
|
dma = knav_queue_pop(netcp->rx_queue, &dma_sz);
|
|
|
|
if (!dma)
|
|
|
|
break;
|
|
|
|
|
|
|
|
desc = knav_pool_desc_unmap(netcp->rx_pool, dma, dma_sz);
|
|
|
|
if (unlikely(!desc)) {
|
|
|
|
dev_err(netcp->ndev_dev, "%s: failed to unmap Rx desc\n",
|
|
|
|
__func__);
|
2017-01-07 04:37:41 +08:00
|
|
|
rx_stats->rx_errors++;
|
2015-01-16 08:12:50 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
netcp_free_rx_desc_chain(netcp, desc);
|
2017-01-07 04:37:41 +08:00
|
|
|
rx_stats->rx_dropped++;
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_process_one_rx_packet(struct netcp_intf *netcp)
|
|
|
|
{
|
2017-01-07 04:37:41 +08:00
|
|
|
struct netcp_stats *rx_stats = &netcp->stats;
|
2015-01-16 08:12:50 +08:00
|
|
|
unsigned int dma_sz, buf_len, org_buf_len;
|
|
|
|
struct knav_dma_desc *desc, *ndesc;
|
|
|
|
unsigned int pkt_sz = 0, accum_sz;
|
|
|
|
struct netcp_hook_list *rx_hook;
|
|
|
|
dma_addr_t dma_desc, dma_buff;
|
|
|
|
struct netcp_packet p_info;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
void *org_buf_ptr;
|
2017-01-07 04:37:39 +08:00
|
|
|
u32 tmp;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
dma_desc = knav_queue_pop(netcp->rx_queue, &dma_sz);
|
|
|
|
if (!dma_desc)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
desc = knav_pool_desc_unmap(netcp->rx_pool, dma_desc, dma_sz);
|
|
|
|
if (unlikely(!desc)) {
|
|
|
|
dev_err(netcp->ndev_dev, "failed to unmap Rx desc\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_pkt_info(&dma_buff, &buf_len, &dma_desc, desc);
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are retrieving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
|
|
|
org_buf_ptr = (void *)GET_SW_DATA0(desc);
|
|
|
|
org_buf_len = (int)GET_SW_DATA1(desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
if (unlikely(!org_buf_ptr)) {
|
|
|
|
dev_err(netcp->ndev_dev, "NULL bufptr in desc\n");
|
|
|
|
goto free_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt_sz &= KNAV_DMA_DESC_PKT_LEN_MASK;
|
|
|
|
accum_sz = buf_len;
|
|
|
|
dma_unmap_single(netcp->dev, dma_buff, buf_len, DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
/* Build a new sk_buff for the primary buffer */
|
|
|
|
skb = build_skb(org_buf_ptr, org_buf_len);
|
|
|
|
if (unlikely(!skb)) {
|
|
|
|
dev_err(netcp->ndev_dev, "build_skb() failed\n");
|
|
|
|
goto free_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update data, tail and len */
|
|
|
|
skb_reserve(skb, NETCP_SOP_OFFSET);
|
|
|
|
__skb_put(skb, buf_len);
|
|
|
|
|
|
|
|
/* Fill in the page fragment list */
|
|
|
|
while (dma_desc) {
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
ndesc = knav_pool_desc_unmap(netcp->rx_pool, dma_desc, dma_sz);
|
|
|
|
if (unlikely(!ndesc)) {
|
|
|
|
dev_err(netcp->ndev_dev, "failed to unmap Rx desc\n");
|
|
|
|
goto free_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_pkt_info(&dma_buff, &buf_len, &dma_desc, ndesc);
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are retrieving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
2018-01-17 04:16:01 +08:00
|
|
|
page = (struct page *)GET_SW_DATA0(ndesc);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
if (likely(dma_buff && buf_len && page)) {
|
|
|
|
dma_unmap_page(netcp->dev, dma_buff, PAGE_SIZE,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
} else {
|
2015-12-08 23:32:27 +08:00
|
|
|
dev_err(netcp->ndev_dev, "Bad Rx desc dma_buff(%pad), len(%d), page(%p)\n",
|
|
|
|
&dma_buff, buf_len, page);
|
2015-01-16 08:12:50 +08:00
|
|
|
goto free_desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
|
|
|
|
offset_in_page(dma_buff), buf_len, PAGE_SIZE);
|
|
|
|
accum_sz += buf_len;
|
|
|
|
|
|
|
|
/* Free the descriptor */
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, ndesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for packet len and warn */
|
|
|
|
if (unlikely(pkt_sz != accum_sz))
|
|
|
|
dev_dbg(netcp->ndev_dev, "mismatch in packet size(%d) & sum of fragments(%d)\n",
|
|
|
|
pkt_sz, accum_sz);
|
|
|
|
|
2017-01-07 04:37:43 +08:00
|
|
|
/* Newer version of the Ethernet switch can trim the Ethernet FCS
|
|
|
|
* from the packet and is indicated in hw_cap. So trim it only for
|
|
|
|
* older h/w
|
|
|
|
*/
|
|
|
|
if (!(netcp->hw_cap & ETH_SW_CAN_REMOVE_ETH_FCS))
|
|
|
|
__pskb_trim(skb, skb->len - ETH_FCS_LEN);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* Call each of the RX hooks */
|
|
|
|
p_info.skb = skb;
|
2016-12-09 06:21:56 +08:00
|
|
|
skb->dev = netcp->ndev;
|
2015-01-16 08:12:50 +08:00
|
|
|
p_info.rxtstamp_complete = false;
|
2017-01-07 04:37:39 +08:00
|
|
|
get_desc_info(&tmp, &p_info.eflags, desc);
|
|
|
|
p_info.epib = desc->epib;
|
|
|
|
p_info.psdata = (u32 __force *)desc->psdata;
|
|
|
|
p_info.eflags = ((p_info.eflags >> KNAV_DMA_DESC_EFLAGS_SHIFT) &
|
|
|
|
KNAV_DMA_DESC_EFLAGS_MASK);
|
2015-01-16 08:12:50 +08:00
|
|
|
list_for_each_entry(rx_hook, &netcp->rxhook_list_head, list) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = rx_hook->hook_rtn(rx_hook->order, rx_hook->hook_data,
|
|
|
|
&p_info);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
dev_err(netcp->ndev_dev, "RX hook %d failed: %d\n",
|
|
|
|
rx_hook->order, ret);
|
2017-01-07 04:37:39 +08:00
|
|
|
/* Free the primary descriptor */
|
2017-01-07 04:37:41 +08:00
|
|
|
rx_stats->rx_dropped++;
|
2017-01-07 04:37:39 +08:00
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-01-07 04:37:39 +08:00
|
|
|
/* Free the primary descriptor */
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
2017-01-07 04:37:41 +08:00
|
|
|
u64_stats_update_begin(&rx_stats->syncp_rx);
|
|
|
|
rx_stats->rx_packets++;
|
|
|
|
rx_stats->rx_bytes += skb->len;
|
|
|
|
u64_stats_update_end(&rx_stats->syncp_rx);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* push skb up the stack */
|
|
|
|
skb->protocol = eth_type_trans(skb, netcp->ndev);
|
|
|
|
netif_receive_skb(skb);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
free_desc:
|
|
|
|
netcp_free_rx_desc_chain(netcp, desc);
|
2017-01-07 04:37:41 +08:00
|
|
|
rx_stats->rx_errors++;
|
2015-01-16 08:12:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_process_rx_packets(struct netcp_intf *netcp,
|
|
|
|
unsigned int budget)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; (i < budget) && !netcp_process_one_rx_packet(netcp); i++)
|
|
|
|
;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release descriptors and attached buffers from Rx FDQ */
|
|
|
|
static void netcp_free_rx_buf(struct netcp_intf *netcp, int fdq)
|
|
|
|
{
|
|
|
|
struct knav_dma_desc *desc;
|
|
|
|
unsigned int buf_len, dma_sz;
|
|
|
|
dma_addr_t dma;
|
|
|
|
void *buf_ptr;
|
|
|
|
|
|
|
|
/* Allocate descriptor */
|
|
|
|
while ((dma = knav_queue_pop(netcp->rx_fdq[fdq], &dma_sz))) {
|
|
|
|
desc = knav_pool_desc_unmap(netcp->rx_pool, dma, dma_sz);
|
|
|
|
if (unlikely(!desc)) {
|
|
|
|
dev_err(netcp->ndev_dev, "failed to unmap Rx desc\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_org_pkt_info(&dma, &buf_len, desc);
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are retrieving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
|
|
|
buf_ptr = (void *)GET_SW_DATA0(desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
if (unlikely(!dma)) {
|
|
|
|
dev_err(netcp->ndev_dev, "NULL orig_buff in desc\n");
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(!buf_ptr)) {
|
|
|
|
dev_err(netcp->ndev_dev, "NULL bufptr in desc\n");
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fdq == 0) {
|
|
|
|
dma_unmap_single(netcp->dev, dma, buf_len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
netcp_frag_free((buf_len <= PAGE_SIZE), buf_ptr);
|
|
|
|
} else {
|
|
|
|
dma_unmap_page(netcp->dev, dma, buf_len,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
__free_page(buf_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_rxpool_free(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < KNAV_DMA_FDQ_PER_CHAN &&
|
|
|
|
!IS_ERR_OR_NULL(netcp->rx_fdq[i]); i++)
|
|
|
|
netcp_free_rx_buf(netcp, i);
|
|
|
|
|
|
|
|
if (knav_pool_count(netcp->rx_pool) != netcp->rx_pool_size)
|
|
|
|
dev_err(netcp->ndev_dev, "Lost Rx (%d) descriptors\n",
|
|
|
|
netcp->rx_pool_size - knav_pool_count(netcp->rx_pool));
|
|
|
|
|
|
|
|
knav_pool_destroy(netcp->rx_pool);
|
|
|
|
netcp->rx_pool = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-24 01:37:08 +08:00
|
|
|
static int netcp_allocate_rx_buf(struct netcp_intf *netcp, int fdq)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
|
|
|
struct knav_dma_desc *hwdesc;
|
|
|
|
unsigned int buf_len, dma_sz;
|
|
|
|
u32 desc_info, pkt_info;
|
|
|
|
struct page *page;
|
|
|
|
dma_addr_t dma;
|
|
|
|
void *bufptr;
|
2016-02-20 01:58:43 +08:00
|
|
|
u32 sw_data[2];
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* Allocate descriptor */
|
|
|
|
hwdesc = knav_pool_desc_get(netcp->rx_pool);
|
|
|
|
if (IS_ERR_OR_NULL(hwdesc)) {
|
|
|
|
dev_dbg(netcp->ndev_dev, "out of rx pool desc\n");
|
2015-09-24 01:37:08 +08:00
|
|
|
return -ENOMEM;
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (likely(fdq == 0)) {
|
|
|
|
unsigned int primary_buf_len;
|
|
|
|
/* Allocate a primary receive queue entry */
|
2015-08-05 04:56:53 +08:00
|
|
|
buf_len = NETCP_PACKET_SIZE + NETCP_SOP_OFFSET;
|
2015-01-16 08:12:50 +08:00
|
|
|
primary_buf_len = SKB_DATA_ALIGN(buf_len) +
|
|
|
|
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
|
|
|
|
|
2015-08-05 04:56:53 +08:00
|
|
|
bufptr = netdev_alloc_frag(primary_buf_len);
|
2016-02-20 01:58:43 +08:00
|
|
|
sw_data[1] = primary_buf_len;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
if (unlikely(!bufptr)) {
|
2015-08-05 04:56:53 +08:00
|
|
|
dev_warn_ratelimited(netcp->ndev_dev,
|
|
|
|
"Primary RX buffer alloc failed\n");
|
2015-01-16 08:12:50 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
dma = dma_map_single(netcp->dev, bufptr, buf_len,
|
|
|
|
DMA_TO_DEVICE);
|
2015-08-05 04:56:53 +08:00
|
|
|
if (unlikely(dma_mapping_error(netcp->dev, dma)))
|
|
|
|
goto fail;
|
|
|
|
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are saving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
2016-02-20 01:58:43 +08:00
|
|
|
sw_data[0] = (u32)bufptr;
|
2015-01-16 08:12:50 +08:00
|
|
|
} else {
|
|
|
|
/* Allocate a secondary receive queue entry */
|
2017-11-16 09:38:03 +08:00
|
|
|
page = alloc_page(GFP_ATOMIC | GFP_DMA);
|
2015-01-16 08:12:50 +08:00
|
|
|
if (unlikely(!page)) {
|
|
|
|
dev_warn_ratelimited(netcp->ndev_dev, "Secondary page alloc failed\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
buf_len = PAGE_SIZE;
|
|
|
|
dma = dma_map_page(netcp->dev, page, 0, buf_len, DMA_TO_DEVICE);
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are saving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
2016-02-20 01:58:43 +08:00
|
|
|
sw_data[0] = (u32)page;
|
|
|
|
sw_data[1] = 0;
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
desc_info = KNAV_DMA_DESC_PS_INFO_IN_DESC;
|
|
|
|
desc_info |= buf_len & KNAV_DMA_DESC_PKT_LEN_MASK;
|
|
|
|
pkt_info = KNAV_DMA_DESC_HAS_EPIB;
|
|
|
|
pkt_info |= KNAV_DMA_NUM_PS_WORDS << KNAV_DMA_DESC_PSLEN_SHIFT;
|
|
|
|
pkt_info |= (netcp->rx_queue_id & KNAV_DMA_DESC_RETQ_MASK) <<
|
|
|
|
KNAV_DMA_DESC_RETQ_SHIFT;
|
|
|
|
set_org_pkt_info(dma, buf_len, hwdesc);
|
2016-02-20 01:58:44 +08:00
|
|
|
SET_SW_DATA0(sw_data[0], hwdesc);
|
|
|
|
SET_SW_DATA1(sw_data[1], hwdesc);
|
2015-01-16 08:12:50 +08:00
|
|
|
set_desc_info(desc_info, pkt_info, hwdesc);
|
|
|
|
|
|
|
|
/* Push to FDQs */
|
|
|
|
knav_pool_desc_map(netcp->rx_pool, hwdesc, sizeof(*hwdesc), &dma,
|
|
|
|
&dma_sz);
|
|
|
|
knav_queue_push(netcp->rx_fdq[fdq], dma, sizeof(*hwdesc), 0);
|
2015-09-24 01:37:08 +08:00
|
|
|
return 0;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
knav_pool_desc_put(netcp->rx_pool, hwdesc);
|
2015-09-24 01:37:08 +08:00
|
|
|
return -ENOMEM;
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Refill Rx FDQ with descriptors & attached buffers */
|
|
|
|
static void netcp_rxpool_refill(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
u32 fdq_deficit[KNAV_DMA_FDQ_PER_CHAN] = {0};
|
2015-09-24 01:37:08 +08:00
|
|
|
int i, ret = 0;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* Calculate the FDQ deficit and refill */
|
|
|
|
for (i = 0; i < KNAV_DMA_FDQ_PER_CHAN && netcp->rx_fdq[i]; i++) {
|
|
|
|
fdq_deficit[i] = netcp->rx_queue_depths[i] -
|
|
|
|
knav_queue_get_count(netcp->rx_fdq[i]);
|
|
|
|
|
2015-09-24 01:37:08 +08:00
|
|
|
while (fdq_deficit[i]-- && !ret)
|
|
|
|
ret = netcp_allocate_rx_buf(netcp, i);
|
2015-01-16 08:12:50 +08:00
|
|
|
} /* end for fdqs */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NAPI poll */
|
|
|
|
static int netcp_rx_poll(struct napi_struct *napi, int budget)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = container_of(napi, struct netcp_intf,
|
|
|
|
rx_napi);
|
|
|
|
unsigned int packets;
|
|
|
|
|
|
|
|
packets = netcp_process_rx_packets(netcp, budget);
|
|
|
|
|
2015-09-24 01:37:10 +08:00
|
|
|
netcp_rxpool_refill(netcp);
|
2015-01-16 08:12:50 +08:00
|
|
|
if (packets < budget) {
|
2017-01-31 00:22:01 +08:00
|
|
|
napi_complete_done(&netcp->rx_napi, packets);
|
2015-01-16 08:12:50 +08:00
|
|
|
knav_queue_enable_notify(netcp->rx_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_rx_notify(void *arg)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = arg;
|
|
|
|
|
|
|
|
knav_queue_disable_notify(netcp->rx_queue);
|
|
|
|
napi_schedule(&netcp->rx_napi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_free_tx_desc_chain(struct netcp_intf *netcp,
|
|
|
|
struct knav_dma_desc *desc,
|
|
|
|
unsigned int desc_sz)
|
|
|
|
{
|
|
|
|
struct knav_dma_desc *ndesc = desc;
|
|
|
|
dma_addr_t dma_desc, dma_buf;
|
|
|
|
unsigned int buf_len;
|
|
|
|
|
|
|
|
while (ndesc) {
|
|
|
|
get_pkt_info(&dma_buf, &buf_len, &dma_desc, ndesc);
|
|
|
|
|
|
|
|
if (dma_buf && buf_len)
|
|
|
|
dma_unmap_single(netcp->dev, dma_buf, buf_len,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
else
|
2015-12-08 23:32:27 +08:00
|
|
|
dev_warn(netcp->ndev_dev, "bad Tx desc buf(%pad), len(%d)\n",
|
|
|
|
&dma_buf, buf_len);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
knav_pool_desc_put(netcp->tx_pool, ndesc);
|
|
|
|
ndesc = NULL;
|
|
|
|
if (dma_desc) {
|
|
|
|
ndesc = knav_pool_desc_unmap(netcp->tx_pool, dma_desc,
|
|
|
|
desc_sz);
|
|
|
|
if (!ndesc)
|
|
|
|
dev_err(netcp->ndev_dev, "failed to unmap Tx desc\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_process_tx_compl_packets(struct netcp_intf *netcp,
|
|
|
|
unsigned int budget)
|
|
|
|
{
|
2017-01-07 04:37:41 +08:00
|
|
|
struct netcp_stats *tx_stats = &netcp->stats;
|
2015-01-16 08:12:50 +08:00
|
|
|
struct knav_dma_desc *desc;
|
2016-12-09 06:21:56 +08:00
|
|
|
struct netcp_tx_cb *tx_cb;
|
2015-01-16 08:12:50 +08:00
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned int dma_sz;
|
|
|
|
dma_addr_t dma;
|
|
|
|
int pkts = 0;
|
|
|
|
|
|
|
|
while (budget--) {
|
|
|
|
dma = knav_queue_pop(netcp->tx_compl_q, &dma_sz);
|
|
|
|
if (!dma)
|
|
|
|
break;
|
|
|
|
desc = knav_pool_desc_unmap(netcp->tx_pool, dma, dma_sz);
|
|
|
|
if (unlikely(!desc)) {
|
|
|
|
dev_err(netcp->ndev_dev, "failed to unmap Tx desc\n");
|
2017-01-07 04:37:41 +08:00
|
|
|
tx_stats->tx_errors++;
|
2015-01-16 08:12:50 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are retrieving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
|
|
|
skb = (struct sk_buff *)GET_SW_DATA0(desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
netcp_free_tx_desc_chain(netcp, desc, dma_sz);
|
|
|
|
if (!skb) {
|
|
|
|
dev_err(netcp->ndev_dev, "No skb in Tx desc\n");
|
2017-01-07 04:37:41 +08:00
|
|
|
tx_stats->tx_errors++;
|
2015-01-16 08:12:50 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:21:56 +08:00
|
|
|
tx_cb = (struct netcp_tx_cb *)skb->cb;
|
|
|
|
if (tx_cb->txtstamp)
|
|
|
|
tx_cb->txtstamp(tx_cb->ts_context, skb);
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
if (netif_subqueue_stopped(netcp->ndev, skb) &&
|
|
|
|
netif_running(netcp->ndev) &&
|
|
|
|
(knav_pool_count(netcp->tx_pool) >
|
|
|
|
netcp->tx_resume_threshold)) {
|
|
|
|
u16 subqueue = skb_get_queue_mapping(skb);
|
|
|
|
|
|
|
|
netif_wake_subqueue(netcp->ndev, subqueue);
|
|
|
|
}
|
|
|
|
|
2017-01-07 04:37:41 +08:00
|
|
|
u64_stats_update_begin(&tx_stats->syncp_tx);
|
|
|
|
tx_stats->tx_packets++;
|
|
|
|
tx_stats->tx_bytes += skb->len;
|
|
|
|
u64_stats_update_end(&tx_stats->syncp_tx);
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_kfree_skb(skb);
|
|
|
|
pkts++;
|
|
|
|
}
|
|
|
|
return pkts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_tx_poll(struct napi_struct *napi, int budget)
|
|
|
|
{
|
|
|
|
int packets;
|
|
|
|
struct netcp_intf *netcp = container_of(napi, struct netcp_intf,
|
|
|
|
tx_napi);
|
|
|
|
|
|
|
|
packets = netcp_process_tx_compl_packets(netcp, budget);
|
|
|
|
if (packets < budget) {
|
|
|
|
napi_complete(&netcp->tx_napi);
|
|
|
|
knav_queue_enable_notify(netcp->tx_compl_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
return packets;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_tx_notify(void *arg)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = arg;
|
|
|
|
|
|
|
|
knav_queue_disable_notify(netcp->tx_compl_q);
|
|
|
|
napi_schedule(&netcp->tx_napi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct knav_dma_desc*
|
|
|
|
netcp_tx_map_skb(struct sk_buff *skb, struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
struct knav_dma_desc *desc, *ndesc, *pdesc;
|
|
|
|
unsigned int pkt_len = skb_headlen(skb);
|
|
|
|
struct device *dev = netcp->dev;
|
|
|
|
dma_addr_t dma_addr;
|
|
|
|
unsigned int dma_sz;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Map the linear buffer */
|
|
|
|
dma_addr = dma_map_single(dev, skb->data, pkt_len, DMA_TO_DEVICE);
|
2015-08-05 04:56:53 +08:00
|
|
|
if (unlikely(dma_mapping_error(dev, dma_addr))) {
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_err(netcp->ndev_dev, "Failed to map skb buffer\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = knav_pool_desc_get(netcp->tx_pool);
|
2015-08-12 18:29:42 +08:00
|
|
|
if (IS_ERR_OR_NULL(desc)) {
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_err(netcp->ndev_dev, "out of TX desc\n");
|
|
|
|
dma_unmap_single(dev, dma_addr, pkt_len, DMA_TO_DEVICE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_pkt_info(dma_addr, pkt_len, 0, desc);
|
|
|
|
if (skb_is_nonlinear(skb)) {
|
|
|
|
prefetchw(skb_shinfo(skb));
|
|
|
|
} else {
|
|
|
|
desc->next_desc = 0;
|
|
|
|
goto upd_pkt_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdesc = desc;
|
|
|
|
|
|
|
|
/* Handle the case where skb is fragmented in pages */
|
|
|
|
for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
|
|
|
|
skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
|
|
|
|
struct page *page = skb_frag_page(frag);
|
2019-07-30 22:40:33 +08:00
|
|
|
u32 page_offset = skb_frag_off(frag);
|
2015-01-16 08:12:50 +08:00
|
|
|
u32 buf_len = skb_frag_size(frag);
|
|
|
|
dma_addr_t desc_dma;
|
2015-12-08 23:32:27 +08:00
|
|
|
u32 desc_dma_32;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
dma_addr = dma_map_page(dev, page, page_offset, buf_len,
|
|
|
|
DMA_TO_DEVICE);
|
|
|
|
if (unlikely(!dma_addr)) {
|
|
|
|
dev_err(netcp->ndev_dev, "Failed to map skb page\n");
|
|
|
|
goto free_descs;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndesc = knav_pool_desc_get(netcp->tx_pool);
|
2015-08-12 18:29:42 +08:00
|
|
|
if (IS_ERR_OR_NULL(ndesc)) {
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_err(netcp->ndev_dev, "out of TX desc for frags\n");
|
|
|
|
dma_unmap_page(dev, dma_addr, buf_len, DMA_TO_DEVICE);
|
|
|
|
goto free_descs;
|
|
|
|
}
|
|
|
|
|
2015-12-08 23:32:27 +08:00
|
|
|
desc_dma = knav_pool_desc_virt_to_dma(netcp->tx_pool, ndesc);
|
2015-01-16 08:12:50 +08:00
|
|
|
set_pkt_info(dma_addr, buf_len, 0, ndesc);
|
2015-12-08 23:32:27 +08:00
|
|
|
desc_dma_32 = (u32)desc_dma;
|
|
|
|
set_words(&desc_dma_32, 1, &pdesc->next_desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
pkt_len += buf_len;
|
|
|
|
if (pdesc != desc)
|
|
|
|
knav_pool_desc_map(netcp->tx_pool, pdesc,
|
|
|
|
sizeof(*pdesc), &desc_dma, &dma_sz);
|
|
|
|
pdesc = ndesc;
|
|
|
|
}
|
|
|
|
if (pdesc != desc)
|
|
|
|
knav_pool_desc_map(netcp->tx_pool, pdesc, sizeof(*pdesc),
|
|
|
|
&dma_addr, &dma_sz);
|
|
|
|
|
|
|
|
/* frag list based linkage is not supported for now. */
|
|
|
|
if (skb_shinfo(skb)->frag_list) {
|
|
|
|
dev_err_ratelimited(netcp->ndev_dev, "NETIF_F_FRAGLIST not supported\n");
|
|
|
|
goto free_descs;
|
|
|
|
}
|
|
|
|
|
|
|
|
upd_pkt_len:
|
|
|
|
WARN_ON(pkt_len != skb->len);
|
|
|
|
|
|
|
|
pkt_len &= KNAV_DMA_DESC_PKT_LEN_MASK;
|
|
|
|
set_words(&pkt_len, 1, &desc->desc_info);
|
|
|
|
return desc;
|
|
|
|
|
|
|
|
free_descs:
|
|
|
|
netcp_free_tx_desc_chain(netcp, desc, sizeof(*desc));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_tx_submit_skb(struct netcp_intf *netcp,
|
|
|
|
struct sk_buff *skb,
|
|
|
|
struct knav_dma_desc *desc)
|
|
|
|
{
|
|
|
|
struct netcp_tx_pipe *tx_pipe = NULL;
|
|
|
|
struct netcp_hook_list *tx_hook;
|
|
|
|
struct netcp_packet p_info;
|
2016-12-09 06:21:56 +08:00
|
|
|
struct netcp_tx_cb *tx_cb;
|
2015-01-16 08:12:50 +08:00
|
|
|
unsigned int dma_sz;
|
|
|
|
dma_addr_t dma;
|
2015-03-21 04:11:21 +08:00
|
|
|
u32 tmp = 0;
|
2015-01-16 08:12:50 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
p_info.netcp = netcp;
|
|
|
|
p_info.skb = skb;
|
|
|
|
p_info.tx_pipe = NULL;
|
|
|
|
p_info.psdata_len = 0;
|
|
|
|
p_info.ts_context = NULL;
|
2016-12-09 06:21:56 +08:00
|
|
|
p_info.txtstamp = NULL;
|
2015-01-16 08:12:50 +08:00
|
|
|
p_info.epib = desc->epib;
|
2015-12-08 23:32:59 +08:00
|
|
|
p_info.psdata = (u32 __force *)desc->psdata;
|
|
|
|
memset(p_info.epib, 0, KNAV_DMA_NUM_EPIB_WORDS * sizeof(__le32));
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* Find out where to inject the packet for transmission */
|
|
|
|
list_for_each_entry(tx_hook, &netcp->txhook_list_head, list) {
|
|
|
|
ret = tx_hook->hook_rtn(tx_hook->order, tx_hook->hook_data,
|
|
|
|
&p_info);
|
|
|
|
if (unlikely(ret != 0)) {
|
|
|
|
dev_err(netcp->ndev_dev, "TX hook %d rejected the packet with reason(%d)\n",
|
|
|
|
tx_hook->order, ret);
|
|
|
|
ret = (ret < 0) ? ret : NETDEV_TX_OK;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure some TX hook claimed the packet */
|
|
|
|
tx_pipe = p_info.tx_pipe;
|
|
|
|
if (!tx_pipe) {
|
|
|
|
dev_err(netcp->ndev_dev, "No TX hook claimed the packet!\n");
|
|
|
|
ret = -ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:21:56 +08:00
|
|
|
tx_cb = (struct netcp_tx_cb *)skb->cb;
|
|
|
|
tx_cb->ts_context = p_info.ts_context;
|
|
|
|
tx_cb->txtstamp = p_info.txtstamp;
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
/* update descriptor */
|
|
|
|
if (p_info.psdata_len) {
|
2015-12-08 23:32:59 +08:00
|
|
|
/* psdata points to both native-endian and device-endian data */
|
|
|
|
__le32 *psdata = (void __force *)p_info.psdata;
|
2015-01-16 08:12:50 +08:00
|
|
|
|
2017-01-07 04:37:40 +08:00
|
|
|
set_words((u32 *)psdata +
|
|
|
|
(KNAV_DMA_NUM_PS_WORDS - p_info.psdata_len),
|
|
|
|
p_info.psdata_len, psdata);
|
2015-03-21 04:11:21 +08:00
|
|
|
tmp |= (p_info.psdata_len & KNAV_DMA_DESC_PSLEN_MASK) <<
|
2015-01-16 08:12:50 +08:00
|
|
|
KNAV_DMA_DESC_PSLEN_SHIFT;
|
|
|
|
}
|
|
|
|
|
2015-03-21 04:11:21 +08:00
|
|
|
tmp |= KNAV_DMA_DESC_HAS_EPIB |
|
2015-01-16 08:12:50 +08:00
|
|
|
((netcp->tx_compl_qid & KNAV_DMA_DESC_RETQ_MASK) <<
|
2015-03-21 04:11:21 +08:00
|
|
|
KNAV_DMA_DESC_RETQ_SHIFT);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
2015-03-21 04:11:21 +08:00
|
|
|
if (!(tx_pipe->flags & SWITCH_TO_PORT_IN_TAGINFO)) {
|
|
|
|
tmp |= ((tx_pipe->switch_to_port & KNAV_DMA_DESC_PSFLAG_MASK) <<
|
|
|
|
KNAV_DMA_DESC_PSFLAG_SHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_words(&tmp, 1, &desc->packet_info);
|
2016-02-20 01:58:44 +08:00
|
|
|
/* warning!!!! We are saving the virtual ptr in the sw_data
|
|
|
|
* field as a 32bit value. Will not work on 64bit machines
|
|
|
|
*/
|
|
|
|
SET_SW_DATA0((u32)skb, desc);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
2015-03-21 04:11:21 +08:00
|
|
|
if (tx_pipe->flags & SWITCH_TO_PORT_IN_TAGINFO) {
|
|
|
|
tmp = tx_pipe->switch_to_port;
|
2015-12-08 23:32:27 +08:00
|
|
|
set_words(&tmp, 1, &desc->tag_info);
|
2015-03-21 04:11:21 +08:00
|
|
|
}
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
/* submit packet descriptor */
|
|
|
|
ret = knav_pool_desc_map(netcp->tx_pool, desc, sizeof(*desc), &dma,
|
|
|
|
&dma_sz);
|
|
|
|
if (unlikely(ret)) {
|
|
|
|
dev_err(netcp->ndev_dev, "%s() failed to map desc\n", __func__);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
skb_tx_timestamp(skb);
|
|
|
|
knav_queue_push(tx_pipe->dma_queue, dma, dma_sz, 0);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Submit the packet */
|
|
|
|
static int netcp_ndo_start_xmit(struct sk_buff *skb, struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
2017-01-07 04:37:41 +08:00
|
|
|
struct netcp_stats *tx_stats = &netcp->stats;
|
2015-01-16 08:12:50 +08:00
|
|
|
int subqueue = skb_get_queue_mapping(skb);
|
|
|
|
struct knav_dma_desc *desc;
|
|
|
|
int desc_count, ret = 0;
|
|
|
|
|
|
|
|
if (unlikely(skb->len <= 0)) {
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(skb->len < NETCP_MIN_PACKET_SIZE)) {
|
|
|
|
ret = skb_padto(skb, NETCP_MIN_PACKET_SIZE);
|
|
|
|
if (ret < 0) {
|
|
|
|
/* If we get here, the skb has already been dropped */
|
|
|
|
dev_warn(netcp->ndev_dev, "padding failed (%d), packet dropped\n",
|
|
|
|
ret);
|
2017-01-07 04:37:41 +08:00
|
|
|
tx_stats->tx_dropped++;
|
2015-01-16 08:12:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
skb->len = NETCP_MIN_PACKET_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = netcp_tx_map_skb(skb, netcp);
|
|
|
|
if (unlikely(!desc)) {
|
|
|
|
netif_stop_subqueue(ndev, subqueue);
|
|
|
|
ret = -ENOBUFS;
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = netcp_tx_submit_skb(netcp, skb, desc);
|
|
|
|
if (ret)
|
|
|
|
goto drop;
|
|
|
|
|
|
|
|
/* Check Tx pool count & stop subqueue if needed */
|
|
|
|
desc_count = knav_pool_count(netcp->tx_pool);
|
|
|
|
if (desc_count < netcp->tx_pause_threshold) {
|
|
|
|
dev_dbg(netcp->ndev_dev, "pausing tx, count(%d)\n", desc_count);
|
|
|
|
netif_stop_subqueue(ndev, subqueue);
|
|
|
|
}
|
|
|
|
return NETDEV_TX_OK;
|
|
|
|
|
|
|
|
drop:
|
2017-01-07 04:37:41 +08:00
|
|
|
tx_stats->tx_dropped++;
|
2015-01-16 08:12:50 +08:00
|
|
|
if (desc)
|
|
|
|
netcp_free_tx_desc_chain(netcp, desc, sizeof(*desc));
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int netcp_txpipe_close(struct netcp_tx_pipe *tx_pipe)
|
|
|
|
{
|
|
|
|
if (tx_pipe->dma_channel) {
|
|
|
|
knav_dma_close_channel(tx_pipe->dma_channel);
|
|
|
|
tx_pipe->dma_channel = NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_txpipe_close);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
int netcp_txpipe_open(struct netcp_tx_pipe *tx_pipe)
|
|
|
|
{
|
|
|
|
struct device *dev = tx_pipe->netcp_device->device;
|
|
|
|
struct knav_dma_cfg config;
|
|
|
|
int ret = 0;
|
|
|
|
u8 name[16];
|
|
|
|
|
|
|
|
memset(&config, 0, sizeof(config));
|
|
|
|
config.direction = DMA_MEM_TO_DEV;
|
|
|
|
config.u.tx.filt_einfo = false;
|
|
|
|
config.u.tx.filt_pswords = false;
|
|
|
|
config.u.tx.priority = DMA_PRIO_MED_L;
|
|
|
|
|
|
|
|
tx_pipe->dma_channel = knav_dma_open_channel(dev,
|
|
|
|
tx_pipe->dma_chan_name, &config);
|
2017-05-11 01:28:05 +08:00
|
|
|
if (IS_ERR(tx_pipe->dma_channel)) {
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_err(dev, "failed opening tx chan(%s)\n",
|
|
|
|
tx_pipe->dma_chan_name);
|
2017-05-11 01:28:05 +08:00
|
|
|
ret = PTR_ERR(tx_pipe->dma_channel);
|
2015-01-16 08:12:50 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "tx-pipe-%s", dev_name(dev));
|
|
|
|
tx_pipe->dma_queue = knav_queue_open(name, tx_pipe->dma_queue_id,
|
|
|
|
KNAV_QUEUE_SHARED);
|
|
|
|
if (IS_ERR(tx_pipe->dma_queue)) {
|
2021-05-08 13:38:22 +08:00
|
|
|
dev_err(dev, "Could not open DMA queue for channel \"%s\": %pe\n",
|
|
|
|
name, tx_pipe->dma_queue);
|
2015-01-16 08:12:50 +08:00
|
|
|
ret = PTR_ERR(tx_pipe->dma_queue);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(dev, "opened tx pipe %s\n", name);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (!IS_ERR_OR_NULL(tx_pipe->dma_channel))
|
|
|
|
knav_dma_close_channel(tx_pipe->dma_channel);
|
|
|
|
tx_pipe->dma_channel = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_txpipe_open);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
int netcp_txpipe_init(struct netcp_tx_pipe *tx_pipe,
|
|
|
|
struct netcp_device *netcp_device,
|
|
|
|
const char *dma_chan_name, unsigned int dma_queue_id)
|
|
|
|
{
|
|
|
|
memset(tx_pipe, 0, sizeof(*tx_pipe));
|
|
|
|
tx_pipe->netcp_device = netcp_device;
|
|
|
|
tx_pipe->dma_chan_name = dma_chan_name;
|
|
|
|
tx_pipe->dma_queue_id = dma_queue_id;
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-30 07:15:51 +08:00
|
|
|
EXPORT_SYMBOL_GPL(netcp_txpipe_init);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
static struct netcp_addr *netcp_addr_find(struct netcp_intf *netcp,
|
|
|
|
const u8 *addr,
|
|
|
|
enum netcp_addr_type type)
|
|
|
|
{
|
|
|
|
struct netcp_addr *naddr;
|
|
|
|
|
|
|
|
list_for_each_entry(naddr, &netcp->addr_list, node) {
|
|
|
|
if (naddr->type != type)
|
|
|
|
continue;
|
|
|
|
if (addr && memcmp(addr, naddr->addr, ETH_ALEN))
|
|
|
|
continue;
|
|
|
|
return naddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct netcp_addr *netcp_addr_add(struct netcp_intf *netcp,
|
|
|
|
const u8 *addr,
|
|
|
|
enum netcp_addr_type type)
|
|
|
|
{
|
|
|
|
struct netcp_addr *naddr;
|
|
|
|
|
|
|
|
naddr = devm_kmalloc(netcp->dev, sizeof(*naddr), GFP_ATOMIC);
|
|
|
|
if (!naddr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
naddr->type = type;
|
|
|
|
naddr->flags = 0;
|
|
|
|
naddr->netcp = netcp;
|
|
|
|
if (addr)
|
|
|
|
ether_addr_copy(naddr->addr, addr);
|
|
|
|
else
|
2015-03-03 11:54:47 +08:00
|
|
|
eth_zero_addr(naddr->addr);
|
2015-01-16 08:12:50 +08:00
|
|
|
list_add_tail(&naddr->node, &netcp->addr_list);
|
|
|
|
|
|
|
|
return naddr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_addr_del(struct netcp_intf *netcp, struct netcp_addr *naddr)
|
|
|
|
{
|
|
|
|
list_del(&naddr->node);
|
|
|
|
devm_kfree(netcp->dev, naddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_addr_clear_mark(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
struct netcp_addr *naddr;
|
|
|
|
|
|
|
|
list_for_each_entry(naddr, &netcp->addr_list, node)
|
|
|
|
naddr->flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_addr_add_mark(struct netcp_intf *netcp, const u8 *addr,
|
|
|
|
enum netcp_addr_type type)
|
|
|
|
{
|
|
|
|
struct netcp_addr *naddr;
|
|
|
|
|
|
|
|
naddr = netcp_addr_find(netcp, addr, type);
|
|
|
|
if (naddr) {
|
|
|
|
naddr->flags |= ADDR_VALID;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
naddr = netcp_addr_add(netcp, addr, type);
|
|
|
|
if (!WARN_ON(!naddr))
|
|
|
|
naddr->flags |= ADDR_NEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_addr_sweep_del(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
struct netcp_addr *naddr, *tmp;
|
|
|
|
struct netcp_intf_modpriv *priv;
|
|
|
|
struct netcp_module *module;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(naddr, tmp, &netcp->addr_list, node) {
|
|
|
|
if (naddr->flags & (ADDR_VALID | ADDR_NEW))
|
|
|
|
continue;
|
|
|
|
dev_dbg(netcp->ndev_dev, "deleting address %pM, type %x\n",
|
|
|
|
naddr->addr, naddr->type);
|
|
|
|
for_each_module(netcp, priv) {
|
|
|
|
module = priv->netcp_module;
|
|
|
|
if (!module->del_addr)
|
|
|
|
continue;
|
|
|
|
error = module->del_addr(priv->module_priv,
|
|
|
|
naddr);
|
|
|
|
WARN_ON(error);
|
|
|
|
}
|
|
|
|
netcp_addr_del(netcp, naddr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_addr_sweep_add(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
struct netcp_addr *naddr, *tmp;
|
|
|
|
struct netcp_intf_modpriv *priv;
|
|
|
|
struct netcp_module *module;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(naddr, tmp, &netcp->addr_list, node) {
|
|
|
|
if (!(naddr->flags & ADDR_NEW))
|
|
|
|
continue;
|
|
|
|
dev_dbg(netcp->ndev_dev, "adding address %pM, type %x\n",
|
|
|
|
naddr->addr, naddr->type);
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
for_each_module(netcp, priv) {
|
|
|
|
module = priv->netcp_module;
|
|
|
|
if (!module->add_addr)
|
|
|
|
continue;
|
|
|
|
error = module->add_addr(priv->module_priv, naddr);
|
|
|
|
WARN_ON(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 05:30:41 +08:00
|
|
|
static int netcp_set_promiscuous(struct netcp_intf *netcp, bool promisc)
|
|
|
|
{
|
|
|
|
struct netcp_intf_modpriv *priv;
|
|
|
|
struct netcp_module *module;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
for_each_module(netcp, priv) {
|
|
|
|
module = priv->netcp_module;
|
|
|
|
if (!module->set_rx_mode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
error = module->set_rx_mode(priv->module_priv, promisc);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
static void netcp_set_rx_mode(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netdev_hw_addr *ndev_addr;
|
|
|
|
bool promisc;
|
|
|
|
|
|
|
|
promisc = (ndev->flags & IFF_PROMISC ||
|
|
|
|
ndev->flags & IFF_ALLMULTI ||
|
|
|
|
netdev_mc_count(ndev) > NETCP_MAX_MCAST_ADDR);
|
|
|
|
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
spin_lock(&netcp->lock);
|
2015-01-16 08:12:50 +08:00
|
|
|
/* first clear all marks */
|
|
|
|
netcp_addr_clear_mark(netcp);
|
|
|
|
|
|
|
|
/* next add new entries, mark existing ones */
|
|
|
|
netcp_addr_add_mark(netcp, ndev->broadcast, ADDR_BCAST);
|
|
|
|
for_each_dev_addr(ndev, ndev_addr)
|
|
|
|
netcp_addr_add_mark(netcp, ndev_addr->addr, ADDR_DEV);
|
|
|
|
netdev_for_each_uc_addr(ndev_addr, ndev)
|
|
|
|
netcp_addr_add_mark(netcp, ndev_addr->addr, ADDR_UCAST);
|
|
|
|
netdev_for_each_mc_addr(ndev_addr, ndev)
|
|
|
|
netcp_addr_add_mark(netcp, ndev_addr->addr, ADDR_MCAST);
|
|
|
|
|
|
|
|
if (promisc)
|
|
|
|
netcp_addr_add_mark(netcp, NULL, ADDR_ANY);
|
|
|
|
|
|
|
|
/* finally sweep and callout into modules */
|
|
|
|
netcp_addr_sweep_del(netcp);
|
|
|
|
netcp_addr_sweep_add(netcp);
|
2018-04-18 05:30:41 +08:00
|
|
|
netcp_set_promiscuous(netcp, promisc);
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
spin_unlock(&netcp->lock);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_free_navigator_resources(struct netcp_intf *netcp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (netcp->rx_channel) {
|
|
|
|
knav_dma_close_channel(netcp->rx_channel);
|
|
|
|
netcp->rx_channel = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IS_ERR_OR_NULL(netcp->rx_pool))
|
|
|
|
netcp_rxpool_free(netcp);
|
|
|
|
|
|
|
|
if (!IS_ERR_OR_NULL(netcp->rx_queue)) {
|
|
|
|
knav_queue_close(netcp->rx_queue);
|
|
|
|
netcp->rx_queue = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < KNAV_DMA_FDQ_PER_CHAN &&
|
|
|
|
!IS_ERR_OR_NULL(netcp->rx_fdq[i]) ; ++i) {
|
|
|
|
knav_queue_close(netcp->rx_fdq[i]);
|
|
|
|
netcp->rx_fdq[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IS_ERR_OR_NULL(netcp->tx_compl_q)) {
|
|
|
|
knav_queue_close(netcp->tx_compl_q);
|
|
|
|
netcp->tx_compl_q = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IS_ERR_OR_NULL(netcp->tx_pool)) {
|
|
|
|
knav_pool_destroy(netcp->tx_pool);
|
|
|
|
netcp->tx_pool = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_setup_navigator_resources(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct knav_queue_notify_config notify_cfg;
|
|
|
|
struct knav_dma_cfg config;
|
|
|
|
u32 last_fdq = 0;
|
|
|
|
u8 name[16];
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Create Rx/Tx descriptor pools */
|
|
|
|
snprintf(name, sizeof(name), "rx-pool-%s", ndev->name);
|
|
|
|
netcp->rx_pool = knav_pool_create(name, netcp->rx_pool_size,
|
|
|
|
netcp->rx_pool_region_id);
|
|
|
|
if (IS_ERR_OR_NULL(netcp->rx_pool)) {
|
|
|
|
dev_err(netcp->ndev_dev, "Couldn't create rx pool\n");
|
|
|
|
ret = PTR_ERR(netcp->rx_pool);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "tx-pool-%s", ndev->name);
|
|
|
|
netcp->tx_pool = knav_pool_create(name, netcp->tx_pool_size,
|
|
|
|
netcp->tx_pool_region_id);
|
|
|
|
if (IS_ERR_OR_NULL(netcp->tx_pool)) {
|
|
|
|
dev_err(netcp->ndev_dev, "Couldn't create tx pool\n");
|
|
|
|
ret = PTR_ERR(netcp->tx_pool);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* open Tx completion queue */
|
|
|
|
snprintf(name, sizeof(name), "tx-compl-%s", ndev->name);
|
|
|
|
netcp->tx_compl_q = knav_queue_open(name, netcp->tx_compl_qid, 0);
|
2016-11-16 18:43:33 +08:00
|
|
|
if (IS_ERR(netcp->tx_compl_q)) {
|
2015-01-16 08:12:50 +08:00
|
|
|
ret = PTR_ERR(netcp->tx_compl_q);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
netcp->tx_compl_qid = knav_queue_get_id(netcp->tx_compl_q);
|
|
|
|
|
|
|
|
/* Set notification for Tx completion */
|
|
|
|
notify_cfg.fn = netcp_tx_notify;
|
|
|
|
notify_cfg.fn_arg = netcp;
|
|
|
|
ret = knav_queue_device_control(netcp->tx_compl_q,
|
|
|
|
KNAV_QUEUE_SET_NOTIFIER,
|
|
|
|
(unsigned long)¬ify_cfg);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
knav_queue_disable_notify(netcp->tx_compl_q);
|
|
|
|
|
|
|
|
/* open Rx completion queue */
|
|
|
|
snprintf(name, sizeof(name), "rx-compl-%s", ndev->name);
|
|
|
|
netcp->rx_queue = knav_queue_open(name, netcp->rx_queue_id, 0);
|
2016-11-16 18:43:33 +08:00
|
|
|
if (IS_ERR(netcp->rx_queue)) {
|
2015-01-16 08:12:50 +08:00
|
|
|
ret = PTR_ERR(netcp->rx_queue);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
netcp->rx_queue_id = knav_queue_get_id(netcp->rx_queue);
|
|
|
|
|
|
|
|
/* Set notification for Rx completion */
|
|
|
|
notify_cfg.fn = netcp_rx_notify;
|
|
|
|
notify_cfg.fn_arg = netcp;
|
|
|
|
ret = knav_queue_device_control(netcp->rx_queue,
|
|
|
|
KNAV_QUEUE_SET_NOTIFIER,
|
|
|
|
(unsigned long)¬ify_cfg);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
knav_queue_disable_notify(netcp->rx_queue);
|
|
|
|
|
|
|
|
/* open Rx FDQs */
|
2015-08-05 04:56:53 +08:00
|
|
|
for (i = 0; i < KNAV_DMA_FDQ_PER_CHAN && netcp->rx_queue_depths[i];
|
|
|
|
++i) {
|
2015-01-16 08:12:50 +08:00
|
|
|
snprintf(name, sizeof(name), "rx-fdq-%s-%d", ndev->name, i);
|
|
|
|
netcp->rx_fdq[i] = knav_queue_open(name, KNAV_QUEUE_GP, 0);
|
2016-11-16 18:43:33 +08:00
|
|
|
if (IS_ERR(netcp->rx_fdq[i])) {
|
2015-01-16 08:12:50 +08:00
|
|
|
ret = PTR_ERR(netcp->rx_fdq[i]);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&config, 0, sizeof(config));
|
|
|
|
config.direction = DMA_DEV_TO_MEM;
|
|
|
|
config.u.rx.einfo_present = true;
|
|
|
|
config.u.rx.psinfo_present = true;
|
|
|
|
config.u.rx.err_mode = DMA_DROP;
|
|
|
|
config.u.rx.desc_type = DMA_DESC_HOST;
|
|
|
|
config.u.rx.psinfo_at_sop = false;
|
|
|
|
config.u.rx.sop_offset = NETCP_SOP_OFFSET;
|
|
|
|
config.u.rx.dst_q = netcp->rx_queue_id;
|
|
|
|
config.u.rx.thresh = DMA_THRESH_NONE;
|
|
|
|
|
|
|
|
for (i = 0; i < KNAV_DMA_FDQ_PER_CHAN; ++i) {
|
|
|
|
if (netcp->rx_fdq[i])
|
|
|
|
last_fdq = knav_queue_get_id(netcp->rx_fdq[i]);
|
|
|
|
config.u.rx.fdq[i] = last_fdq;
|
|
|
|
}
|
|
|
|
|
|
|
|
netcp->rx_channel = knav_dma_open_channel(netcp->netcp_device->device,
|
|
|
|
netcp->dma_chan_name, &config);
|
2017-05-11 01:28:05 +08:00
|
|
|
if (IS_ERR(netcp->rx_channel)) {
|
2015-01-16 08:12:50 +08:00
|
|
|
dev_err(netcp->ndev_dev, "failed opening rx chan(%s\n",
|
|
|
|
netcp->dma_chan_name);
|
2017-05-11 01:28:05 +08:00
|
|
|
ret = PTR_ERR(netcp->rx_channel);
|
2015-01-16 08:12:50 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(netcp->ndev_dev, "opened RX channel: %p\n", netcp->rx_channel);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
netcp_free_navigator_resources(netcp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the device */
|
|
|
|
static int netcp_ndo_open(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
struct netcp_module *module;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
netif_carrier_off(ndev);
|
|
|
|
ret = netcp_setup_navigator_resources(ndev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(netcp->ndev_dev, "Failed to setup navigator resources\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_module(netcp, intf_modpriv) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
if (module->open) {
|
|
|
|
ret = module->open(intf_modpriv->module_priv, ndev);
|
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(netcp->ndev_dev, "module open failed\n");
|
|
|
|
goto fail_open;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
napi_enable(&netcp->rx_napi);
|
|
|
|
napi_enable(&netcp->tx_napi);
|
|
|
|
knav_queue_enable_notify(netcp->tx_compl_q);
|
|
|
|
knav_queue_enable_notify(netcp->rx_queue);
|
2015-07-17 03:32:14 +08:00
|
|
|
netcp_rxpool_refill(netcp);
|
2015-01-16 08:12:50 +08:00
|
|
|
netif_tx_wake_all_queues(ndev);
|
|
|
|
dev_dbg(netcp->ndev_dev, "netcp device %s opened\n", ndev->name);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_open:
|
|
|
|
for_each_module(netcp, intf_modpriv) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
if (module->close)
|
|
|
|
module->close(intf_modpriv->module_priv, ndev);
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
netcp_free_navigator_resources(netcp);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the device */
|
|
|
|
static int netcp_ndo_stop(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
struct netcp_module *module;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
netif_tx_stop_all_queues(ndev);
|
|
|
|
netif_carrier_off(ndev);
|
|
|
|
netcp_addr_clear_mark(netcp);
|
|
|
|
netcp_addr_sweep_del(netcp);
|
|
|
|
knav_queue_disable_notify(netcp->rx_queue);
|
|
|
|
knav_queue_disable_notify(netcp->tx_compl_q);
|
|
|
|
napi_disable(&netcp->rx_napi);
|
|
|
|
napi_disable(&netcp->tx_napi);
|
|
|
|
|
|
|
|
for_each_module(netcp, intf_modpriv) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
if (module->close) {
|
|
|
|
err = module->close(intf_modpriv->module_priv, ndev);
|
|
|
|
if (err != 0)
|
|
|
|
dev_err(netcp->ndev_dev, "Close failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recycle Rx descriptors from completion queue */
|
|
|
|
netcp_empty_rx_queue(netcp);
|
|
|
|
|
|
|
|
/* Recycle Tx descriptors from completion queue */
|
|
|
|
netcp_process_tx_compl_packets(netcp, netcp->tx_pool_size);
|
|
|
|
|
|
|
|
if (knav_pool_count(netcp->tx_pool) != netcp->tx_pool_size)
|
|
|
|
dev_err(netcp->ndev_dev, "Lost (%d) Tx descs\n",
|
|
|
|
netcp->tx_pool_size - knav_pool_count(netcp->tx_pool));
|
|
|
|
|
|
|
|
netcp_free_navigator_resources(netcp);
|
|
|
|
dev_dbg(netcp->ndev_dev, "netcp device %s stopped\n", ndev->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_ndo_ioctl(struct net_device *ndev,
|
|
|
|
struct ifreq *req, int cmd)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
struct netcp_module *module;
|
|
|
|
int ret = -1, err = -EOPNOTSUPP;
|
|
|
|
|
|
|
|
if (!netif_running(ndev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for_each_module(netcp, intf_modpriv) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
if (!module->ioctl)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = module->ioctl(intf_modpriv->module_priv, req, cmd);
|
|
|
|
if ((err < 0) && (err != -EOPNOTSUPP)) {
|
|
|
|
ret = err;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (err == 0)
|
|
|
|
ret = err;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
return (ret == 0) ? 0 : err;
|
|
|
|
}
|
|
|
|
|
netdev: pass the stuck queue to the timeout handler
This allows incrementing the correct timeout statistic without any mess.
Down the road, devices can learn to reset just the specific queue.
The patch was generated with the following script:
use strict;
use warnings;
our $^I = '.bak';
my @work = (
["arch/m68k/emu/nfeth.c", "nfeth_tx_timeout"],
["arch/um/drivers/net_kern.c", "uml_net_tx_timeout"],
["arch/um/drivers/vector_kern.c", "vector_net_tx_timeout"],
["arch/xtensa/platforms/iss/network.c", "iss_net_tx_timeout"],
["drivers/char/pcmcia/synclink_cs.c", "hdlcdev_tx_timeout"],
["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"],
["drivers/infiniband/ulp/ipoib/ipoib_main.c", "ipoib_timeout"],
["drivers/message/fusion/mptlan.c", "mpt_lan_tx_timeout"],
["drivers/misc/sgi-xp/xpnet.c", "xpnet_dev_tx_timeout"],
["drivers/net/appletalk/cops.c", "cops_timeout"],
["drivers/net/arcnet/arcdevice.h", "arcnet_timeout"],
["drivers/net/arcnet/arcnet.c", "arcnet_timeout"],
["drivers/net/arcnet/com20020.c", "arcnet_timeout"],
["drivers/net/ethernet/3com/3c509.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c515.c", "corkscrew_timeout"],
["drivers/net/ethernet/3com/3c574_cs.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c589_cs.c", "el3_tx_timeout"],
["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"],
["drivers/net/ethernet/3com/3c59x.c", "vortex_tx_timeout"],
["drivers/net/ethernet/3com/typhoon.c", "typhoon_tx_timeout"],
["drivers/net/ethernet/8390/8390.h", "ei_tx_timeout"],
["drivers/net/ethernet/8390/8390.h", "eip_tx_timeout"],
["drivers/net/ethernet/8390/8390.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/8390p.c", "eip_tx_timeout"],
["drivers/net/ethernet/8390/ax88796.c", "ax_ei_tx_timeout"],
["drivers/net/ethernet/8390/axnet_cs.c", "axnet_tx_timeout"],
["drivers/net/ethernet/8390/etherh.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/hydra.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/mac8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/mcf8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/lib8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/8390/ne2k-pci.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/pcnet_cs.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/smc-ultra.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/wd.c", "ei_tx_timeout"],
["drivers/net/ethernet/8390/zorro8390.c", "__ei_tx_timeout"],
["drivers/net/ethernet/adaptec/starfire.c", "tx_timeout"],
["drivers/net/ethernet/agere/et131x.c", "et131x_tx_timeout"],
["drivers/net/ethernet/allwinner/sun4i-emac.c", "emac_timeout"],
["drivers/net/ethernet/alteon/acenic.c", "ace_watchdog"],
["drivers/net/ethernet/amazon/ena/ena_netdev.c", "ena_tx_timeout"],
["drivers/net/ethernet/amd/7990.h", "lance_tx_timeout"],
["drivers/net/ethernet/amd/7990.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/a2065.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/am79c961a.c", "am79c961_timeout"],
["drivers/net/ethernet/amd/amd8111e.c", "amd8111e_tx_timeout"],
["drivers/net/ethernet/amd/ariadne.c", "ariadne_tx_timeout"],
["drivers/net/ethernet/amd/atarilance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/au1000_eth.c", "au1000_tx_timeout"],
["drivers/net/ethernet/amd/declance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/lance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/mvme147.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/ni65.c", "ni65_timeout"],
["drivers/net/ethernet/amd/nmclan_cs.c", "mace_tx_timeout"],
["drivers/net/ethernet/amd/pcnet32.c", "pcnet32_tx_timeout"],
["drivers/net/ethernet/amd/sunlance.c", "lance_tx_timeout"],
["drivers/net/ethernet/amd/xgbe/xgbe-drv.c", "xgbe_tx_timeout"],
["drivers/net/ethernet/apm/xgene-v2/main.c", "xge_timeout"],
["drivers/net/ethernet/apm/xgene/xgene_enet_main.c", "xgene_enet_timeout"],
["drivers/net/ethernet/apple/macmace.c", "mace_tx_timeout"],
["drivers/net/ethernet/atheros/ag71xx.c", "ag71xx_tx_timeout"],
["drivers/net/ethernet/atheros/alx/main.c", "alx_tx_timeout"],
["drivers/net/ethernet/atheros/atl1c/atl1c_main.c", "atl1c_tx_timeout"],
["drivers/net/ethernet/atheros/atl1e/atl1e_main.c", "atl1e_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl.c", "atlx_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl1.c", "atlx_tx_timeout"],
["drivers/net/ethernet/atheros/atlx/atl2.c", "atl2_tx_timeout"],
["drivers/net/ethernet/broadcom/b44.c", "b44_tx_timeout"],
["drivers/net/ethernet/broadcom/bcmsysport.c", "bcm_sysport_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2.c", "bnx2_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c", "bnx2x_tx_timeout"],
["drivers/net/ethernet/broadcom/bnxt/bnxt.c", "bnxt_tx_timeout"],
["drivers/net/ethernet/broadcom/genet/bcmgenet.c", "bcmgenet_timeout"],
["drivers/net/ethernet/broadcom/sb1250-mac.c", "sbmac_tx_timeout"],
["drivers/net/ethernet/broadcom/tg3.c", "tg3_tx_timeout"],
["drivers/net/ethernet/calxeda/xgmac.c", "xgmac_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_main.c", "liquidio_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_vf_main.c", "liquidio_tx_timeout"],
["drivers/net/ethernet/cavium/liquidio/lio_vf_rep.c", "lio_vf_rep_tx_timeout"],
["drivers/net/ethernet/cavium/thunder/nicvf_main.c", "nicvf_tx_timeout"],
["drivers/net/ethernet/cirrus/cs89x0.c", "net_timeout"],
["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"],
["drivers/net/ethernet/cisco/enic/enic_main.c", "enic_tx_timeout"],
["drivers/net/ethernet/cortina/gemini.c", "gmac_tx_timeout"],
["drivers/net/ethernet/davicom/dm9000.c", "dm9000_timeout"],
["drivers/net/ethernet/dec/tulip/de2104x.c", "de_tx_timeout"],
["drivers/net/ethernet/dec/tulip/tulip_core.c", "tulip_tx_timeout"],
["drivers/net/ethernet/dec/tulip/winbond-840.c", "tx_timeout"],
["drivers/net/ethernet/dlink/dl2k.c", "rio_tx_timeout"],
["drivers/net/ethernet/dlink/sundance.c", "tx_timeout"],
["drivers/net/ethernet/emulex/benet/be_main.c", "be_tx_timeout"],
["drivers/net/ethernet/ethoc.c", "ethoc_tx_timeout"],
["drivers/net/ethernet/faraday/ftgmac100.c", "ftgmac100_tx_timeout"],
["drivers/net/ethernet/fealnx.c", "fealnx_tx_timeout"],
["drivers/net/ethernet/freescale/dpaa/dpaa_eth.c", "dpaa_tx_timeout"],
["drivers/net/ethernet/freescale/fec_main.c", "fec_timeout"],
["drivers/net/ethernet/freescale/fec_mpc52xx.c", "mpc52xx_fec_tx_timeout"],
["drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c", "fs_timeout"],
["drivers/net/ethernet/freescale/gianfar.c", "gfar_timeout"],
["drivers/net/ethernet/freescale/ucc_geth.c", "ucc_geth_timeout"],
["drivers/net/ethernet/fujitsu/fmvj18x_cs.c", "fjn_tx_timeout"],
["drivers/net/ethernet/google/gve/gve_main.c", "gve_tx_timeout"],
["drivers/net/ethernet/hisilicon/hip04_eth.c", "hip04_timeout"],
["drivers/net/ethernet/hisilicon/hix5hd2_gmac.c", "hix5hd2_net_timeout"],
["drivers/net/ethernet/hisilicon/hns/hns_enet.c", "hns_nic_net_timeout"],
["drivers/net/ethernet/hisilicon/hns3/hns3_enet.c", "hns3_nic_net_timeout"],
["drivers/net/ethernet/huawei/hinic/hinic_main.c", "hinic_tx_timeout"],
["drivers/net/ethernet/i825xx/82596.c", "i596_tx_timeout"],
["drivers/net/ethernet/i825xx/ether1.c", "ether1_timeout"],
["drivers/net/ethernet/i825xx/lib82596.c", "i596_tx_timeout"],
["drivers/net/ethernet/i825xx/sun3_82586.c", "sun3_82586_timeout"],
["drivers/net/ethernet/ibm/ehea/ehea_main.c", "ehea_tx_watchdog"],
["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"],
["drivers/net/ethernet/ibm/emac/core.c", "emac_tx_timeout"],
["drivers/net/ethernet/ibm/ibmvnic.c", "ibmvnic_tx_timeout"],
["drivers/net/ethernet/intel/e100.c", "e100_tx_timeout"],
["drivers/net/ethernet/intel/e1000/e1000_main.c", "e1000_tx_timeout"],
["drivers/net/ethernet/intel/e1000e/netdev.c", "e1000_tx_timeout"],
["drivers/net/ethernet/intel/fm10k/fm10k_netdev.c", "fm10k_tx_timeout"],
["drivers/net/ethernet/intel/i40e/i40e_main.c", "i40e_tx_timeout"],
["drivers/net/ethernet/intel/iavf/iavf_main.c", "iavf_tx_timeout"],
["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"],
["drivers/net/ethernet/intel/ice/ice_main.c", "ice_tx_timeout"],
["drivers/net/ethernet/intel/igb/igb_main.c", "igb_tx_timeout"],
["drivers/net/ethernet/intel/igbvf/netdev.c", "igbvf_tx_timeout"],
["drivers/net/ethernet/intel/ixgb/ixgb_main.c", "ixgb_tx_timeout"],
["drivers/net/ethernet/intel/ixgbe/ixgbe_debugfs.c", "adapter->netdev->netdev_ops->ndo_tx_timeout(adapter->netdev);"],
["drivers/net/ethernet/intel/ixgbe/ixgbe_main.c", "ixgbe_tx_timeout"],
["drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c", "ixgbevf_tx_timeout"],
["drivers/net/ethernet/jme.c", "jme_tx_timeout"],
["drivers/net/ethernet/korina.c", "korina_tx_timeout"],
["drivers/net/ethernet/lantiq_etop.c", "ltq_etop_tx_timeout"],
["drivers/net/ethernet/marvell/mv643xx_eth.c", "mv643xx_eth_tx_timeout"],
["drivers/net/ethernet/marvell/pxa168_eth.c", "pxa168_eth_tx_timeout"],
["drivers/net/ethernet/marvell/skge.c", "skge_tx_timeout"],
["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"],
["drivers/net/ethernet/marvell/sky2.c", "sky2_tx_timeout"],
["drivers/net/ethernet/mediatek/mtk_eth_soc.c", "mtk_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx4/en_netdev.c", "mlx4_en_tx_timeout"],
["drivers/net/ethernet/mellanox/mlx5/core/en_main.c", "mlx5e_tx_timeout"],
["drivers/net/ethernet/micrel/ks8842.c", "ks8842_tx_timeout"],
["drivers/net/ethernet/micrel/ksz884x.c", "netdev_tx_timeout"],
["drivers/net/ethernet/microchip/enc28j60.c", "enc28j60_tx_timeout"],
["drivers/net/ethernet/microchip/encx24j600.c", "encx24j600_tx_timeout"],
["drivers/net/ethernet/natsemi/sonic.h", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/sonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/jazzsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/macsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/natsemi/natsemi.c", "ns_tx_timeout"],
["drivers/net/ethernet/natsemi/ns83820.c", "ns83820_tx_timeout"],
["drivers/net/ethernet/natsemi/xtsonic.c", "sonic_tx_timeout"],
["drivers/net/ethernet/neterion/s2io.h", "s2io_tx_watchdog"],
["drivers/net/ethernet/neterion/s2io.c", "s2io_tx_watchdog"],
["drivers/net/ethernet/neterion/vxge/vxge-main.c", "vxge_tx_watchdog"],
["drivers/net/ethernet/netronome/nfp/nfp_net_common.c", "nfp_net_tx_timeout"],
["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"],
["drivers/net/ethernet/nvidia/forcedeth.c", "nv_tx_timeout"],
["drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c", "pch_gbe_tx_timeout"],
["drivers/net/ethernet/packetengines/hamachi.c", "hamachi_tx_timeout"],
["drivers/net/ethernet/packetengines/yellowfin.c", "yellowfin_tx_timeout"],
["drivers/net/ethernet/pensando/ionic/ionic_lif.c", "ionic_tx_timeout"],
["drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c", "netxen_tx_timeout"],
["drivers/net/ethernet/qlogic/qla3xxx.c", "ql3xxx_tx_timeout"],
["drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c", "qlcnic_tx_timeout"],
["drivers/net/ethernet/qualcomm/emac/emac.c", "emac_tx_timeout"],
["drivers/net/ethernet/qualcomm/qca_spi.c", "qcaspi_netdev_tx_timeout"],
["drivers/net/ethernet/qualcomm/qca_uart.c", "qcauart_netdev_tx_timeout"],
["drivers/net/ethernet/rdc/r6040.c", "r6040_tx_timeout"],
["drivers/net/ethernet/realtek/8139cp.c", "cp_tx_timeout"],
["drivers/net/ethernet/realtek/8139too.c", "rtl8139_tx_timeout"],
["drivers/net/ethernet/realtek/atp.c", "tx_timeout"],
["drivers/net/ethernet/realtek/r8169_main.c", "rtl8169_tx_timeout"],
["drivers/net/ethernet/renesas/ravb_main.c", "ravb_tx_timeout"],
["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"],
["drivers/net/ethernet/renesas/sh_eth.c", "sh_eth_tx_timeout"],
["drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c", "sxgbe_tx_timeout"],
["drivers/net/ethernet/seeq/ether3.c", "ether3_timeout"],
["drivers/net/ethernet/seeq/sgiseeq.c", "timeout"],
["drivers/net/ethernet/sfc/efx.c", "efx_watchdog"],
["drivers/net/ethernet/sfc/falcon/efx.c", "ef4_watchdog"],
["drivers/net/ethernet/sgi/ioc3-eth.c", "ioc3_timeout"],
["drivers/net/ethernet/sgi/meth.c", "meth_tx_timeout"],
["drivers/net/ethernet/silan/sc92031.c", "sc92031_tx_timeout"],
["drivers/net/ethernet/sis/sis190.c", "sis190_tx_timeout"],
["drivers/net/ethernet/sis/sis900.c", "sis900_tx_timeout"],
["drivers/net/ethernet/smsc/epic100.c", "epic_tx_timeout"],
["drivers/net/ethernet/smsc/smc911x.c", "smc911x_timeout"],
["drivers/net/ethernet/smsc/smc9194.c", "smc_timeout"],
["drivers/net/ethernet/smsc/smc91c92_cs.c", "smc_tx_timeout"],
["drivers/net/ethernet/smsc/smc91x.c", "smc_timeout"],
["drivers/net/ethernet/stmicro/stmmac/stmmac_main.c", "stmmac_tx_timeout"],
["drivers/net/ethernet/sun/cassini.c", "cas_tx_timeout"],
["drivers/net/ethernet/sun/ldmvsw.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/niu.c", "niu_tx_timeout"],
["drivers/net/ethernet/sun/sunbmac.c", "bigmac_tx_timeout"],
["drivers/net/ethernet/sun/sungem.c", "gem_tx_timeout"],
["drivers/net/ethernet/sun/sunhme.c", "happy_meal_tx_timeout"],
["drivers/net/ethernet/sun/sunqe.c", "qe_tx_timeout"],
["drivers/net/ethernet/sun/sunvnet.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/sunvnet_common.c", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/sun/sunvnet_common.h", "sunvnet_tx_timeout_common"],
["drivers/net/ethernet/synopsys/dwc-xlgmac-net.c", "xlgmac_tx_timeout"],
["drivers/net/ethernet/ti/cpmac.c", "cpmac_tx_timeout"],
["drivers/net/ethernet/ti/cpsw.c", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/cpsw_priv.c", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/cpsw_priv.h", "cpsw_ndo_tx_timeout"],
["drivers/net/ethernet/ti/davinci_emac.c", "emac_dev_tx_timeout"],
["drivers/net/ethernet/ti/netcp_core.c", "netcp_ndo_tx_timeout"],
["drivers/net/ethernet/ti/tlan.c", "tlan_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_net.h", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_net.c", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/ps3_gelic_wireless.c", "gelic_net_tx_timeout"],
["drivers/net/ethernet/toshiba/spider_net.c", "spider_net_tx_timeout"],
["drivers/net/ethernet/toshiba/tc35815.c", "tc35815_tx_timeout"],
["drivers/net/ethernet/via/via-rhine.c", "rhine_tx_timeout"],
["drivers/net/ethernet/wiznet/w5100.c", "w5100_tx_timeout"],
["drivers/net/ethernet/wiznet/w5300.c", "w5300_tx_timeout"],
["drivers/net/ethernet/xilinx/xilinx_emaclite.c", "xemaclite_tx_timeout"],
["drivers/net/ethernet/xircom/xirc2ps_cs.c", "xirc_tx_timeout"],
["drivers/net/fjes/fjes_main.c", "fjes_tx_retry"],
["drivers/net/slip/slip.c", "sl_tx_timeout"],
["include/linux/usb/usbnet.h", "usbnet_tx_timeout"],
["drivers/net/usb/aqc111.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/asix_devices.c", "usbnet_tx_timeout"],
["drivers/net/usb/ax88172a.c", "usbnet_tx_timeout"],
["drivers/net/usb/ax88179_178a.c", "usbnet_tx_timeout"],
["drivers/net/usb/catc.c", "catc_tx_timeout"],
["drivers/net/usb/cdc_mbim.c", "usbnet_tx_timeout"],
["drivers/net/usb/cdc_ncm.c", "usbnet_tx_timeout"],
["drivers/net/usb/dm9601.c", "usbnet_tx_timeout"],
["drivers/net/usb/hso.c", "hso_net_tx_timeout"],
["drivers/net/usb/int51x1.c", "usbnet_tx_timeout"],
["drivers/net/usb/ipheth.c", "ipheth_tx_timeout"],
["drivers/net/usb/kaweth.c", "kaweth_tx_timeout"],
["drivers/net/usb/lan78xx.c", "lan78xx_tx_timeout"],
["drivers/net/usb/mcs7830.c", "usbnet_tx_timeout"],
["drivers/net/usb/pegasus.c", "pegasus_tx_timeout"],
["drivers/net/usb/qmi_wwan.c", "usbnet_tx_timeout"],
["drivers/net/usb/r8152.c", "rtl8152_tx_timeout"],
["drivers/net/usb/rndis_host.c", "usbnet_tx_timeout"],
["drivers/net/usb/rtl8150.c", "rtl8150_tx_timeout"],
["drivers/net/usb/sierra_net.c", "usbnet_tx_timeout"],
["drivers/net/usb/smsc75xx.c", "usbnet_tx_timeout"],
["drivers/net/usb/smsc95xx.c", "usbnet_tx_timeout"],
["drivers/net/usb/sr9700.c", "usbnet_tx_timeout"],
["drivers/net/usb/sr9800.c", "usbnet_tx_timeout"],
["drivers/net/usb/usbnet.c", "usbnet_tx_timeout"],
["drivers/net/vmxnet3/vmxnet3_drv.c", "vmxnet3_tx_timeout"],
["drivers/net/wan/cosa.c", "cosa_net_timeout"],
["drivers/net/wan/farsync.c", "fst_tx_timeout"],
["drivers/net/wan/fsl_ucc_hdlc.c", "uhdlc_tx_timeout"],
["drivers/net/wan/lmc/lmc_main.c", "lmc_driver_timeout"],
["drivers/net/wan/x25_asy.c", "x25_asy_timeout"],
["drivers/net/wimax/i2400m/netdev.c", "i2400m_tx_timeout"],
["drivers/net/wireless/intel/ipw2x00/ipw2100.c", "ipw2100_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/hostap/hostap_main.c", "prism2_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/main.c", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/orinoco_usb.c", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/orinoco/orinoco.h", "orinoco_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_dev.c", "islpci_eth_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_eth.c", "islpci_eth_tx_timeout"],
["drivers/net/wireless/intersil/prism54/islpci_eth.h", "islpci_eth_tx_timeout"],
["drivers/net/wireless/marvell/mwifiex/main.c", "mwifiex_tx_timeout"],
["drivers/net/wireless/quantenna/qtnfmac/core.c", "qtnf_netdev_tx_timeout"],
["drivers/net/wireless/quantenna/qtnfmac/core.h", "qtnf_netdev_tx_timeout"],
["drivers/net/wireless/rndis_wlan.c", "usbnet_tx_timeout"],
["drivers/net/wireless/wl3501_cs.c", "wl3501_tx_timeout"],
["drivers/net/wireless/zydas/zd1201.c", "zd1201_tx_timeout"],
["drivers/s390/net/qeth_core.h", "qeth_tx_timeout"],
["drivers/s390/net/qeth_core_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l2_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"],
["drivers/s390/net/qeth_l3_main.c", "qeth_tx_timeout"],
["drivers/staging/ks7010/ks_wlan_net.c", "ks_wlan_tx_timeout"],
["drivers/staging/qlge/qlge_main.c", "qlge_tx_timeout"],
["drivers/staging/rtl8192e/rtl8192e/rtl_core.c", "_rtl92e_tx_timeout"],
["drivers/staging/rtl8192u/r8192U_core.c", "tx_timeout"],
["drivers/staging/unisys/visornic/visornic_main.c", "visornic_xmit_timeout"],
["drivers/staging/wlan-ng/p80211netdev.c", "p80211knetdev_tx_timeout"],
["drivers/tty/n_gsm.c", "gsm_mux_net_tx_timeout"],
["drivers/tty/synclink.c", "hdlcdev_tx_timeout"],
["drivers/tty/synclink_gt.c", "hdlcdev_tx_timeout"],
["drivers/tty/synclinkmp.c", "hdlcdev_tx_timeout"],
["net/atm/lec.c", "lec_tx_timeout"],
["net/bluetooth/bnep/netdev.c", "bnep_net_timeout"]
);
for my $p (@work) {
my @pair = @$p;
my $file = $pair[0];
my $func = $pair[1];
print STDERR $file , ": ", $func,"\n";
our @ARGV = ($file);
while (<ARGV>) {
if (m/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/) {
print STDERR "found $1+$2 in $file\n";
}
if (s/($func\s*\(struct\s+net_device\s+\*[A-Za-z_]?[A-Za-z-0-9_]*)(\))/$1, unsigned int txqueue$2/) {
print STDERR "$func found in $file\n";
}
print;
}
}
where the list of files and functions is simply from:
git grep ndo_tx_timeout, with manual addition of headers
in the rare cases where the function is from a header,
then manually changing the few places which actually
call ndo_tx_timeout.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Heiner Kallweit <hkallweit1@gmail.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: Shannon Nelson <snelson@pensando.io>
Reviewed-by: Martin Habets <mhabets@solarflare.com>
changes from v9:
fixup a forward declaration
changes from v9:
more leftovers from v3 change
changes from v8:
fix up a missing direct call to timeout
rebased on net-next
changes from v7:
fixup leftovers from v3 change
changes from v6:
fix typo in rtl driver
changes from v5:
add missing files (allow any net device argument name)
changes from v4:
add a missing driver header
changes from v3:
change queue # to unsigned
Changes from v2:
added headers
Changes from v1:
Fix errors found by kbuild:
generalize the pattern a bit, to pick up
a couple of instances missed by the previous
version.
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-12-10 22:23:51 +08:00
|
|
|
static void netcp_ndo_tx_timeout(struct net_device *ndev, unsigned int txqueue)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
unsigned int descs = knav_pool_count(netcp->tx_pool);
|
|
|
|
|
|
|
|
dev_err(netcp->ndev_dev, "transmit timed out tx descs(%d)\n", descs);
|
|
|
|
netcp_process_tx_compl_packets(netcp, netcp->tx_pool_size);
|
2016-05-03 22:33:13 +08:00
|
|
|
netif_trans_update(ndev);
|
2015-01-16 08:12:50 +08:00
|
|
|
netif_tx_wake_all_queues(ndev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
struct netcp_module *module;
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
unsigned long flags;
|
2015-01-16 08:12:50 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
dev_dbg(netcp->ndev_dev, "adding rx vlan id: %d\n", vid);
|
|
|
|
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
spin_lock_irqsave(&netcp->lock, flags);
|
2015-01-16 08:12:50 +08:00
|
|
|
for_each_module(netcp, intf_modpriv) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
if ((module->add_vid) && (vid != 0)) {
|
|
|
|
err = module->add_vid(intf_modpriv->module_priv, vid);
|
|
|
|
if (err != 0) {
|
|
|
|
dev_err(netcp->ndev_dev, "Could not add vlan id = %d\n",
|
|
|
|
vid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
spin_unlock_irqrestore(&netcp->lock, flags);
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vid)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv;
|
|
|
|
struct netcp_module *module;
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
unsigned long flags;
|
2015-01-16 08:12:50 +08:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
dev_dbg(netcp->ndev_dev, "removing rx vlan id: %d\n", vid);
|
|
|
|
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
spin_lock_irqsave(&netcp->lock, flags);
|
2015-01-16 08:12:50 +08:00
|
|
|
for_each_module(netcp, intf_modpriv) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
if (module->del_vid) {
|
|
|
|
err = module->del_vid(intf_modpriv->module_priv, vid);
|
|
|
|
if (err != 0) {
|
|
|
|
dev_err(netcp->ndev_dev, "Could not delete vlan id = %d\n",
|
|
|
|
vid);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
net: netcp: fix deadlock reported by lockup detector
A deadlock trace is seen in netcp driver with lockup detector enabled.
The trace log is provided below for reference. This patch fixes the
bug by removing the usage of netcp_modules_lock within ndo_ops functions.
ndo_{open/close/ioctl)() is already called with rtnl_lock held. So there
is no need to hold another mutex for serialization across processes on
multiple cores. So remove use of netcp_modules_lock mutex from these
ndo ops functions.
ndo_set_rx_mode() shouldn't be using a mutex as it is called from atomic
context. In the case of ndo_set_rx_mode(), there can be call to this API
without rtnl_lock held from an atomic context. As the underlying modules
are expected to add address to a hardware table, it is to be protected
across concurrent updates and hence a spin lock is used to synchronize
the access. Same with ndo_vlan_rx_add_vid() & ndo_vlan_rx_kill_vid().
Probably the netcp_modules_lock is used to protect the module not being
removed as part of rmmod. Currently this is not fully implemented and
assumes the interface is brought down before doing rmmod of modules.
The support for rmmmod while interface is up is expected in a future
patch set when additional modules such as pa, qos are added. For now
all of the tests such as if up/down, reboot, iperf works fine with this
patch applied.
Deadlock trace seen with lockup detector enabled is shown below for
reference.
[ 16.863014] ======================================================
[ 16.869183] [ INFO: possible circular locking dependency detected ]
[ 16.875441] 4.1.6-01265-gfb1e101 #1 Tainted: G W
[ 16.881176] -------------------------------------------------------
[ 16.887432] ifconfig/1662 is trying to acquire lock:
[ 16.892386] (netcp_modules_lock){+.+.+.}, at: [<c03e8110>]
netcp_ndo_open+0x168/0x518
[ 16.900321]
[ 16.900321] but task is already holding lock:
[ 16.906144] (rtnl_mutex){+.+.+.}, at: [<c053a418>] devinet_ioctl+0xf8/0x7e4
[ 16.913206]
[ 16.913206] which lock already depends on the new lock.
[ 16.913206]
[ 16.921372]
[ 16.921372] the existing dependency chain (in reverse order) is:
[ 16.928844]
-> #1 (rtnl_mutex){+.+.+.}:
[ 16.932865] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.938521] [<c04c5758>] register_netdev+0xc/0x24
[ 16.943831] [<c03e65c0>] netcp_module_probe+0x214/0x2ec
[ 16.949660] [<c03e8a54>] netcp_register_module+0xd4/0x140
[ 16.955663] [<c089654c>] keystone_gbe_init+0x10/0x28
[ 16.961233] [<c000977c>] do_one_initcall+0xb8/0x1f8
[ 16.966714] [<c0867e04>] kernel_init_freeable+0x148/0x1e8
[ 16.972720] [<c05f9994>] kernel_init+0xc/0xe8
[ 16.977682] [<c0010038>] ret_from_fork+0x14/0x3c
[ 16.982905]
-> #0 (netcp_modules_lock){+.+.+.}:
[ 16.987619] [<c006eab0>] lock_acquire+0x118/0x320
[ 16.992928] [<c06023f0>] mutex_lock_nested+0x68/0x4a8
[ 16.998582] [<c03e8110>] netcp_ndo_open+0x168/0x518
[ 17.004064] [<c04c48f0>] __dev_open+0xa8/0x10c
[ 17.009112] [<c04c4b74>] __dev_change_flags+0x94/0x144
[ 17.014853] [<c04c4c3c>] dev_change_flags+0x18/0x48
[ 17.020334] [<c053a9fc>] devinet_ioctl+0x6dc/0x7e4
[ 17.025729] [<c04a59ec>] sock_ioctl+0x1d0/0x2a8
[ 17.030865] [<c0142844>] do_vfs_ioctl+0x41c/0x688
[ 17.036173] [<c0142ae4>] SyS_ioctl+0x34/0x5c
[ 17.041046] [<c000ff60>] ret_fast_syscall+0x0/0x54
[ 17.046441]
[ 17.046441] other info that might help us debug this:
[ 17.046441]
[ 17.054434] Possible unsafe locking scenario:
[ 17.054434]
[ 17.060343] CPU0 CPU1
[ 17.064862] ---- ----
[ 17.069381] lock(rtnl_mutex);
[ 17.072522] lock(netcp_modules_lock);
[ 17.078875] lock(rtnl_mutex);
[ 17.084532] lock(netcp_modules_lock);
[ 17.088366]
[ 17.088366] *** DEADLOCK ***
[ 17.088366]
[ 17.094279] 1 lock held by ifconfig/1662:
[ 17.098278] #0: (rtnl_mutex){+.+.+.}, at: [<c053a418>]
devinet_ioctl+0xf8/0x7e4
[ 17.105774]
[ 17.105774] stack backtrace:
[ 17.110124] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.118637] Hardware name: Keystone
[ 17.122123] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.129862] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.137079] [<c05ff450>] (dump_stack) from [<c0068e34>]
(print_circular_bug+0x210/0x330)
[ 17.145161] [<c0068e34>] (print_circular_bug) from [<c006ab7c>]
(validate_chain.isra.35+0xf98/0x13ac)
[ 17.154372] [<c006ab7c>] (validate_chain.isra.35) from [<c006da60>]
(__lock_acquire+0x52c/0xcc0)
[ 17.163149] [<c006da60>] (__lock_acquire) from [<c006eab0>]
(lock_acquire+0x118/0x320)
[ 17.171058] [<c006eab0>] (lock_acquire) from [<c06023f0>]
(mutex_lock_nested+0x68/0x4a8)
[ 17.179140] [<c06023f0>] (mutex_lock_nested) from [<c03e8110>]
(netcp_ndo_open+0x168/0x518)
[ 17.187484] [<c03e8110>] (netcp_ndo_open) from [<c04c48f0>]
(__dev_open+0xa8/0x10c)
[ 17.195133] [<c04c48f0>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.203129] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.211560] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.219729] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.227378] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.234939] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.242242] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.258855] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 17.271282] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 17.279712] in_atomic(): 1, irqs_disabled(): 0, pid: 1662, name: ifconfig
[ 17.286500] INFO: lockdep is turned off.
[ 17.290413] Preemption disabled at:[< (null)>] (null)
[ 17.295728]
[ 17.297214] CPU: 1 PID: 1662 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 17.305735] Hardware name: Keystone
[ 17.309223] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 17.316970] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 17.324194] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 17.332112] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 17.340724] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 17.348982] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 17.356724] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 17.364729] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 17.373166] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 17.381344] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 17.388994] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 17.396563] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 17.403873] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 17.413772] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
udhcpc (v1.20.2) started
Sending discover...
[ 18.690666] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
Sending discover...
[ 22.250972] netcp-1.0 2620110.netcp eth0: Link is Up - 1Gbps/Full - flow
control off
[ 22.258721] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 22.265458] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 22.273896] in_atomic(): 1, irqs_disabled(): 0, pid: 342, name: kworker/1:1
[ 22.280854] INFO: lockdep is turned off.
[ 22.284767] Preemption disabled at:[< (null)>] (null)
[ 22.290074]
[ 22.291568] CPU: 1 PID: 342 Comm: kworker/1:1 Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 22.300255] Hardware name: Keystone
[ 22.303750] Workqueue: ipv6_addrconf addrconf_dad_work
[ 22.308895] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 22.316643] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 22.323867] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 22.331786] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 22.340394] [<c03e9840>] (netcp_set_rx_mode) from [<c04c9d18>]
(__dev_mc_add+0x54/0x68)
[ 22.348401] [<c04c9d18>] (__dev_mc_add) from [<c05ab358>]
(igmp6_group_added+0x168/0x1b4)
[ 22.356580] [<c05ab358>] (igmp6_group_added) from [<c05ad2cc>]
(ipv6_dev_mc_inc+0x4f0/0x5a8)
[ 22.365019] [<c05ad2cc>] (ipv6_dev_mc_inc) from [<c058f0d0>]
(addrconf_dad_work+0x21c/0x33c)
[ 22.373460] [<c058f0d0>] (addrconf_dad_work) from [<c0042850>]
(process_one_work+0x214/0x8d0)
[ 22.381986] [<c0042850>] (process_one_work) from [<c0042f54>]
(worker_thread+0x48/0x4bc)
[ 22.390071] [<c0042f54>] (worker_thread) from [<c004868c>]
(kthread+0xf0/0x108)
[ 22.397381] [<c004868c>] (kthread) from [<c0010038>]
Trace related to incorrect usage of mutex inside ndo_set_rx_mode
[ 24.086066] BUG: sleeping function called from invalid context at
kernel/locking/mutex.c:616
[ 24.094506] in_atomic(): 1, irqs_disabled(): 0, pid: 1682, name: ifconfig
[ 24.101291] INFO: lockdep is turned off.
[ 24.105203] Preemption disabled at:[< (null)>] (null)
[ 24.110511]
[ 24.112005] CPU: 2 PID: 1682 Comm: ifconfig Tainted: G W
4.1.6-01265-gfb1e101 #1
[ 24.120518] Hardware name: Keystone
[ 24.124018] [<c00178e4>] (unwind_backtrace) from [<c0013cbc>]
(show_stack+0x10/0x14)
[ 24.131772] [<c0013cbc>] (show_stack) from [<c05ff450>]
(dump_stack+0x84/0xc4)
[ 24.138989] [<c05ff450>] (dump_stack) from [<c06023b0>]
(mutex_lock_nested+0x28/0x4a8)
[ 24.146908] [<c06023b0>] (mutex_lock_nested) from [<c03e9840>]
(netcp_set_rx_mode+0x160/0x210)
[ 24.155523] [<c03e9840>] (netcp_set_rx_mode) from [<c04c483c>]
(dev_set_rx_mode+0x1c/0x28)
[ 24.163787] [<c04c483c>] (dev_set_rx_mode) from [<c04c490c>]
(__dev_open+0xc4/0x10c)
[ 24.171531] [<c04c490c>] (__dev_open) from [<c04c4b74>]
(__dev_change_flags+0x94/0x144)
[ 24.179528] [<c04c4b74>] (__dev_change_flags) from [<c04c4c3c>]
(dev_change_flags+0x18/0x48)
[ 24.187966] [<c04c4c3c>] (dev_change_flags) from [<c053a9fc>]
(devinet_ioctl+0x6dc/0x7e4)
[ 24.196145] [<c053a9fc>] (devinet_ioctl) from [<c04a59ec>]
(sock_ioctl+0x1d0/0x2a8)
[ 24.203803] [<c04a59ec>] (sock_ioctl) from [<c0142844>]
(do_vfs_ioctl+0x41c/0x688)
[ 24.211373] [<c0142844>] (do_vfs_ioctl) from [<c0142ae4>]
(SyS_ioctl+0x34/0x5c)
[ 24.218676] [<c0142ae4>] (SyS_ioctl) from [<c000ff60>]
(ret_fast_syscall+0x0/0x54)
[ 24.227156] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-09-24 01:37:11 +08:00
|
|
|
spin_unlock_irqrestore(&netcp->lock, flags);
|
2015-01-16 08:12:50 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2017-08-07 16:15:17 +08:00
|
|
|
static int netcp_setup_tc(struct net_device *dev, enum tc_setup_type type,
|
2017-08-07 16:15:32 +08:00
|
|
|
void *type_data)
|
2015-01-16 08:12:50 +08:00
|
|
|
{
|
2017-08-07 16:15:32 +08:00
|
|
|
struct tc_mqprio_qopt *mqprio = type_data;
|
2017-03-16 01:39:25 +08:00
|
|
|
u8 num_tc;
|
2015-01-16 08:12:50 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* setup tc must be called under rtnl lock */
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
2017-11-06 14:23:42 +08:00
|
|
|
if (type != TC_SETUP_QDISC_MQPRIO)
|
2017-08-07 16:15:31 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-02-17 13:16:15 +08:00
|
|
|
|
2017-08-07 16:15:32 +08:00
|
|
|
mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
|
|
|
|
num_tc = mqprio->num_tc;
|
2017-03-16 01:39:25 +08:00
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
/* Sanity-check the number of traffic classes requested */
|
|
|
|
if ((dev->real_num_tx_queues <= 1) ||
|
2017-03-16 01:39:25 +08:00
|
|
|
(dev->real_num_tx_queues < num_tc))
|
2015-01-16 08:12:50 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Configure traffic class to queue mappings */
|
2017-03-16 01:39:25 +08:00
|
|
|
if (num_tc) {
|
|
|
|
netdev_set_num_tc(dev, num_tc);
|
|
|
|
for (i = 0; i < num_tc; i++)
|
2015-01-16 08:12:50 +08:00
|
|
|
netdev_set_tc_queue(dev, i, 1, i);
|
|
|
|
} else {
|
|
|
|
netdev_reset_tc(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-11 11:33:29 +08:00
|
|
|
static void
|
2017-01-07 04:37:41 +08:00
|
|
|
netcp_get_stats(struct net_device *ndev, struct rtnl_link_stats64 *stats)
|
|
|
|
{
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_stats *p = &netcp->stats;
|
|
|
|
u64 rxpackets, rxbytes, txpackets, txbytes;
|
|
|
|
unsigned int start;
|
|
|
|
|
|
|
|
do {
|
|
|
|
start = u64_stats_fetch_begin_irq(&p->syncp_rx);
|
|
|
|
rxpackets = p->rx_packets;
|
|
|
|
rxbytes = p->rx_bytes;
|
|
|
|
} while (u64_stats_fetch_retry_irq(&p->syncp_rx, start));
|
|
|
|
|
|
|
|
do {
|
|
|
|
start = u64_stats_fetch_begin_irq(&p->syncp_tx);
|
|
|
|
txpackets = p->tx_packets;
|
|
|
|
txbytes = p->tx_bytes;
|
|
|
|
} while (u64_stats_fetch_retry_irq(&p->syncp_tx, start));
|
|
|
|
|
|
|
|
stats->rx_packets = rxpackets;
|
|
|
|
stats->rx_bytes = rxbytes;
|
|
|
|
stats->tx_packets = txpackets;
|
|
|
|
stats->tx_bytes = txbytes;
|
|
|
|
|
|
|
|
/* The following are stored as 32 bit */
|
|
|
|
stats->rx_errors = p->rx_errors;
|
|
|
|
stats->rx_dropped = p->rx_dropped;
|
|
|
|
stats->tx_dropped = p->tx_dropped;
|
|
|
|
}
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
static const struct net_device_ops netcp_netdev_ops = {
|
|
|
|
.ndo_open = netcp_ndo_open,
|
|
|
|
.ndo_stop = netcp_ndo_stop,
|
|
|
|
.ndo_start_xmit = netcp_ndo_start_xmit,
|
|
|
|
.ndo_set_rx_mode = netcp_set_rx_mode,
|
2021-07-27 21:45:13 +08:00
|
|
|
.ndo_eth_ioctl = netcp_ndo_ioctl,
|
2017-01-07 04:37:41 +08:00
|
|
|
.ndo_get_stats64 = netcp_get_stats,
|
2015-01-16 08:12:50 +08:00
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
|
|
|
.ndo_validate_addr = eth_validate_addr,
|
|
|
|
.ndo_vlan_rx_add_vid = netcp_rx_add_vid,
|
|
|
|
.ndo_vlan_rx_kill_vid = netcp_rx_kill_vid,
|
|
|
|
.ndo_tx_timeout = netcp_ndo_tx_timeout,
|
2018-07-10 00:19:54 +08:00
|
|
|
.ndo_select_queue = dev_pick_tx_zero,
|
2015-01-16 08:12:50 +08:00
|
|
|
.ndo_setup_tc = netcp_setup_tc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int netcp_create_interface(struct netcp_device *netcp_device,
|
|
|
|
struct device_node *node_interface)
|
|
|
|
{
|
|
|
|
struct device *dev = netcp_device->device;
|
|
|
|
struct device_node *node = dev->of_node;
|
|
|
|
struct netcp_intf *netcp;
|
|
|
|
struct net_device *ndev;
|
|
|
|
resource_size_t size;
|
|
|
|
struct resource res;
|
|
|
|
void __iomem *efuse = NULL;
|
|
|
|
u32 efuse_mac = 0;
|
|
|
|
u8 efuse_mac_addr[6];
|
|
|
|
u32 temp[2];
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ndev = alloc_etherdev_mqs(sizeof(*netcp), 1, 1);
|
|
|
|
if (!ndev) {
|
|
|
|
dev_err(dev, "Error allocating netdev\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ndev->features |= NETIF_F_SG;
|
|
|
|
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
|
|
|
|
ndev->hw_features = ndev->features;
|
|
|
|
ndev->vlan_features |= NETIF_F_SG;
|
|
|
|
|
ethernet: use core min/max MTU checking
et131x: min_mtu 64, max_mtu 9216
altera_tse: min_mtu 64, max_mtu 1500
amd8111e: min_mtu 60, max_mtu 9000
bnad: min_mtu 46, max_mtu 9000
macb: min_mtu 68, max_mtu 1500 or 10240 depending on hardware capability
xgmac: min_mtu 46, max_mtu 9000
cxgb2: min_mtu 68, max_mtu 9582 (pm3393) or 9600 (vsc7326)
enic: min_mtu 68, max_mtu 9000
gianfar: min_mtu 50, max_mu 9586
hns_enet: min_mtu 68, max_mtu 9578 (v1) or 9706 (v2)
ksz884x: min_mtu 60, max_mtu 1894
myri10ge: min_mtu 68, max_mtu 9000
natsemi: min_mtu 64, max_mtu 2024
nfp: min_mtu 68, max_mtu hardware-specific
forcedeth: min_mtu 64, max_mtu 1500 or 9100, depending on hardware
pch_gbe: min_mtu 46, max_mtu 10300
pasemi_mac: min_mtu 64, max_mtu 9000
qcaspi: min_mtu 46, max_mtu 1500
- remove qcaspi_netdev_change_mtu as it is now redundant
rocker: min_mtu 68, max_mtu 9000
sxgbe: min_mtu 68, max_mtu 9000
stmmac: min_mtu 46, max_mtu depends on hardware
tehuti: min_mtu 60, max_mtu 16384
- driver had no max mtu checking, but product docs say 16k jumbo packets
are supported by the hardware
netcp: min_mtu 68, max_mtu 9486
- remove netcp_ndo_change_mtu as it is now redundant
via-velocity: min_mtu 64, max_mtu 9000
octeon: min_mtu 46, max_mtu 65370
CC: netdev@vger.kernel.org
CC: Mark Einon <mark.einon@gmail.com>
CC: Vince Bridgers <vbridger@opensource.altera.com>
CC: Rasesh Mody <rasesh.mody@qlogic.com>
CC: Nicolas Ferre <nicolas.ferre@atmel.com>
CC: Santosh Raspatur <santosh@chelsio.com>
CC: Hariprasad S <hariprasad@chelsio.com>
CC: Christian Benvenuti <benve@cisco.com>
CC: Sujith Sankar <ssujith@cisco.com>
CC: Govindarajulu Varadarajan <_govind@gmx.com>
CC: Neel Patel <neepatel@cisco.com>
CC: Claudiu Manoil <claudiu.manoil@freescale.com>
CC: Yisen Zhuang <yisen.zhuang@huawei.com>
CC: Salil Mehta <salil.mehta@huawei.com>
CC: Hyong-Youb Kim <hykim@myri.com>
CC: Jakub Kicinski <jakub.kicinski@netronome.com>
CC: Olof Johansson <olof@lixom.net>
CC: Jiri Pirko <jiri@resnulli.us>
CC: Byungho An <bh74.an@samsung.com>
CC: Girish K S <ks.giri@samsung.com>
CC: Vipul Pandya <vipul.pandya@samsung.com>
CC: Giuseppe Cavallaro <peppe.cavallaro@st.com>
CC: Alexandre Torgue <alexandre.torgue@st.com>
CC: Andy Gospodarek <andy@greyhouse.net>
CC: Wingman Kwok <w-kwok2@ti.com>
CC: Murali Karicheri <m-karicheri2@ti.com>
CC: Francois Romieu <romieu@fr.zoreil.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-10-18 03:54:17 +08:00
|
|
|
/* MTU range: 68 - 9486 */
|
|
|
|
ndev->min_mtu = ETH_MIN_MTU;
|
|
|
|
ndev->max_mtu = NETCP_MAX_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
netcp = netdev_priv(ndev);
|
|
|
|
spin_lock_init(&netcp->lock);
|
|
|
|
INIT_LIST_HEAD(&netcp->module_head);
|
|
|
|
INIT_LIST_HEAD(&netcp->txhook_list_head);
|
|
|
|
INIT_LIST_HEAD(&netcp->rxhook_list_head);
|
|
|
|
INIT_LIST_HEAD(&netcp->addr_list);
|
2017-01-07 04:37:41 +08:00
|
|
|
u64_stats_init(&netcp->stats.syncp_rx);
|
|
|
|
u64_stats_init(&netcp->stats.syncp_tx);
|
2015-01-16 08:12:50 +08:00
|
|
|
netcp->netcp_device = netcp_device;
|
|
|
|
netcp->dev = netcp_device->device;
|
|
|
|
netcp->ndev = ndev;
|
|
|
|
netcp->ndev_dev = &ndev->dev;
|
|
|
|
netcp->msg_enable = netif_msg_init(netcp_debug_level, NETCP_DEBUG);
|
|
|
|
netcp->tx_pause_threshold = MAX_SKB_FRAGS;
|
|
|
|
netcp->tx_resume_threshold = netcp->tx_pause_threshold;
|
|
|
|
netcp->node_interface = node_interface;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(node_interface, "efuse-mac", &efuse_mac);
|
|
|
|
if (efuse_mac) {
|
|
|
|
if (of_address_to_resource(node, NETCP_EFUSE_REG_INDEX, &res)) {
|
|
|
|
dev_err(dev, "could not find efuse-mac reg resource\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
size = resource_size(&res);
|
|
|
|
|
|
|
|
if (!devm_request_mem_region(dev, res.start, size,
|
|
|
|
dev_name(dev))) {
|
|
|
|
dev_err(dev, "could not reserve resource\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2020-01-06 16:43:50 +08:00
|
|
|
efuse = devm_ioremap(dev, res.start, size);
|
2015-01-16 08:12:50 +08:00
|
|
|
if (!efuse) {
|
|
|
|
dev_err(dev, "could not map resource\n");
|
|
|
|
devm_release_mem_region(dev, res.start, size);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:01:11 +08:00
|
|
|
emac_arch_get_mac_addr(efuse_mac_addr, efuse, efuse_mac);
|
2015-01-16 08:12:50 +08:00
|
|
|
if (is_valid_ether_addr(efuse_mac_addr))
|
|
|
|
ether_addr_copy(ndev->dev_addr, efuse_mac_addr);
|
|
|
|
else
|
2018-06-23 01:51:00 +08:00
|
|
|
eth_random_addr(ndev->dev_addr);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
devm_iounmap(dev, efuse);
|
|
|
|
devm_release_mem_region(dev, res.start, size);
|
|
|
|
} else {
|
of: net: pass the dst buffer to of_get_mac_address()
of_get_mac_address() returns a "const void*" pointer to a MAC address.
Lately, support to fetch the MAC address by an NVMEM provider was added.
But this will only work with platform devices. It will not work with
PCI devices (e.g. of an integrated root complex) and esp. not with DSA
ports.
There is an of_* variant of the nvmem binding which works without
devices. The returned data of a nvmem_cell_read() has to be freed after
use. On the other hand the return of_get_mac_address() points to some
static data without a lifetime. The trick for now, was to allocate a
device resource managed buffer which is then returned. This will only
work if we have an actual device.
Change it, so that the caller of of_get_mac_address() has to supply a
buffer where the MAC address is written to. Unfortunately, this will
touch all drivers which use the of_get_mac_address().
Usually the code looks like:
const char *addr;
addr = of_get_mac_address(np);
if (!IS_ERR(addr))
ether_addr_copy(ndev->dev_addr, addr);
This can then be simply rewritten as:
of_get_mac_address(np, ndev->dev_addr);
Sometimes is_valid_ether_addr() is used to test the MAC address.
of_get_mac_address() already makes sure, it just returns a valid MAC
address. Thus we can just test its return code. But we have to be
careful if there are still other sources for the MAC address before the
of_get_mac_address(). In this case we have to keep the
is_valid_ether_addr() call.
The following coccinelle patch was used to convert common cases to the
new style. Afterwards, I've manually gone over the drivers and fixed the
return code variable: either used a new one or if one was already
available use that. Mansour Moufid, thanks for that coccinelle patch!
<spml>
@a@
identifier x;
expression y, z;
@@
- x = of_get_mac_address(y);
+ x = of_get_mac_address(y, z);
<...
- ether_addr_copy(z, x);
...>
@@
identifier a.x;
@@
- if (<+... x ...+>) {}
@@
identifier a.x;
@@
if (<+... x ...+>) {
...
}
- else {}
@@
identifier a.x;
expression e;
@@
- if (<+... x ...+>@e)
- {}
- else
+ if (!(e))
{...}
@@
expression x, y, z;
@@
- x = of_get_mac_address(y, z);
+ of_get_mac_address(y, z);
... when != x
</spml>
All drivers, except drivers/net/ethernet/aeroflex/greth.c, were
compile-time tested.
Suggested-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Michael Walle <michael@walle.cc>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
2021-04-13 01:47:17 +08:00
|
|
|
ret = of_get_mac_address(node_interface, ndev->dev_addr);
|
|
|
|
if (ret)
|
2018-06-23 01:51:00 +08:00
|
|
|
eth_random_addr(ndev->dev_addr);
|
2015-01-16 08:12:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_property_read_string(node_interface, "rx-channel",
|
|
|
|
&netcp->dma_chan_name);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "missing \"rx-channel\" parameter\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_property_read_u32(node_interface, "rx-queue",
|
|
|
|
&netcp->rx_queue_id);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_warn(dev, "missing \"rx-queue\" parameter\n");
|
|
|
|
netcp->rx_queue_id = KNAV_QUEUE_QPEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_property_read_u32_array(node_interface, "rx-queue-depth",
|
|
|
|
netcp->rx_queue_depths,
|
|
|
|
KNAV_DMA_FDQ_PER_CHAN);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "missing \"rx-queue-depth\" parameter\n");
|
|
|
|
netcp->rx_queue_depths[0] = 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_property_read_u32_array(node_interface, "rx-pool", temp, 2);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "missing \"rx-pool\" parameter\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
netcp->rx_pool_size = temp[0];
|
|
|
|
netcp->rx_pool_region_id = temp[1];
|
|
|
|
|
|
|
|
ret = of_property_read_u32_array(node_interface, "tx-pool", temp, 2);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "missing \"tx-pool\" parameter\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
netcp->tx_pool_size = temp[0];
|
|
|
|
netcp->tx_pool_region_id = temp[1];
|
|
|
|
|
|
|
|
if (netcp->tx_pool_size < MAX_SKB_FRAGS) {
|
|
|
|
dev_err(dev, "tx-pool size too small, must be atleast(%ld)\n",
|
|
|
|
MAX_SKB_FRAGS);
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = of_property_read_u32(node_interface, "tx-completion-queue",
|
|
|
|
&netcp->tx_compl_qid);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_warn(dev, "missing \"tx-completion-queue\" parameter\n");
|
|
|
|
netcp->tx_compl_qid = KNAV_QUEUE_QPEND;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NAPI register */
|
|
|
|
netif_napi_add(ndev, &netcp->rx_napi, netcp_rx_poll, NETCP_NAPI_WEIGHT);
|
2015-11-18 22:31:00 +08:00
|
|
|
netif_tx_napi_add(ndev, &netcp->tx_napi, netcp_tx_poll, NETCP_NAPI_WEIGHT);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
/* Register the network device */
|
|
|
|
ndev->dev_id = 0;
|
|
|
|
ndev->watchdog_timeo = NETCP_TX_TIMEOUT;
|
|
|
|
ndev->netdev_ops = &netcp_netdev_ops;
|
|
|
|
SET_NETDEV_DEV(ndev, dev);
|
|
|
|
|
|
|
|
list_add_tail(&netcp->interface_list, &netcp_device->interface_head);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
quit:
|
|
|
|
free_netdev(ndev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netcp_delete_interface(struct netcp_device *netcp_device,
|
|
|
|
struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct netcp_intf_modpriv *intf_modpriv, *tmp;
|
|
|
|
struct netcp_intf *netcp = netdev_priv(ndev);
|
|
|
|
struct netcp_module *module;
|
|
|
|
|
|
|
|
dev_dbg(netcp_device->device, "Removing interface \"%s\"\n",
|
|
|
|
ndev->name);
|
|
|
|
|
|
|
|
/* Notify each of the modules that the interface is going away */
|
|
|
|
list_for_each_entry_safe(intf_modpriv, tmp, &netcp->module_head,
|
|
|
|
intf_list) {
|
|
|
|
module = intf_modpriv->netcp_module;
|
|
|
|
dev_dbg(netcp_device->device, "Releasing module \"%s\"\n",
|
|
|
|
module->name);
|
|
|
|
if (module->release)
|
|
|
|
module->release(intf_modpriv->module_priv);
|
|
|
|
list_del(&intf_modpriv->intf_list);
|
|
|
|
}
|
|
|
|
WARN(!list_empty(&netcp->module_head), "%s interface module list is not empty!\n",
|
|
|
|
ndev->name);
|
|
|
|
|
|
|
|
list_del(&netcp->interface_list);
|
|
|
|
|
|
|
|
of_node_put(netcp->node_interface);
|
|
|
|
unregister_netdev(ndev);
|
|
|
|
free_netdev(ndev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device_node *node = pdev->dev.of_node;
|
|
|
|
struct netcp_intf *netcp_intf, *netcp_tmp;
|
|
|
|
struct device_node *child, *interfaces;
|
|
|
|
struct netcp_device *netcp_device;
|
|
|
|
struct device *dev = &pdev->dev;
|
2018-04-18 05:30:39 +08:00
|
|
|
struct netcp_module *module;
|
2015-01-16 08:12:50 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-04-18 05:30:40 +08:00
|
|
|
if (!knav_dma_device_ready() ||
|
|
|
|
!knav_qmss_device_ready())
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
if (!node) {
|
|
|
|
dev_err(dev, "could not find device info\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new NETCP device instance */
|
|
|
|
netcp_device = devm_kzalloc(dev, sizeof(*netcp_device), GFP_KERNEL);
|
|
|
|
if (!netcp_device)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
ret = pm_runtime_get_sync(&pdev->dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "Failed to enable NETCP power-domain\n");
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the NETCP device instance */
|
|
|
|
INIT_LIST_HEAD(&netcp_device->interface_head);
|
|
|
|
INIT_LIST_HEAD(&netcp_device->modpriv_head);
|
|
|
|
netcp_device->device = dev;
|
|
|
|
platform_set_drvdata(pdev, netcp_device);
|
|
|
|
|
|
|
|
/* create interfaces */
|
|
|
|
interfaces = of_get_child_by_name(node, "netcp-interfaces");
|
|
|
|
if (!interfaces) {
|
|
|
|
dev_err(dev, "could not find netcp-interfaces node\n");
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto probe_quit;
|
|
|
|
}
|
|
|
|
|
|
|
|
for_each_available_child_of_node(interfaces, child) {
|
|
|
|
ret = netcp_create_interface(netcp_device, child);
|
|
|
|
if (ret) {
|
2018-08-28 23:44:30 +08:00
|
|
|
dev_err(dev, "could not create interface(%pOFn)\n",
|
|
|
|
child);
|
2015-01-16 08:12:50 +08:00
|
|
|
goto probe_quit_interface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-22 22:40:17 +08:00
|
|
|
of_node_put(interfaces);
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
/* Add the device instance to the list */
|
|
|
|
list_add_tail(&netcp_device->device_list, &netcp_devices);
|
|
|
|
|
2018-04-18 05:30:39 +08:00
|
|
|
/* Probe & attach any modules already registered */
|
|
|
|
mutex_lock(&netcp_modules_lock);
|
|
|
|
for_each_netcp_module(module) {
|
|
|
|
ret = netcp_module_probe(netcp_device, module);
|
|
|
|
if (ret < 0)
|
|
|
|
dev_err(dev, "module(%s) probe failed\n", module->name);
|
|
|
|
}
|
|
|
|
mutex_unlock(&netcp_modules_lock);
|
2015-01-16 08:12:50 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
probe_quit_interface:
|
|
|
|
list_for_each_entry_safe(netcp_intf, netcp_tmp,
|
|
|
|
&netcp_device->interface_head,
|
|
|
|
interface_list) {
|
|
|
|
netcp_delete_interface(netcp_device, netcp_intf->ndev);
|
|
|
|
}
|
|
|
|
|
2016-10-22 22:40:17 +08:00
|
|
|
of_node_put(interfaces);
|
|
|
|
|
2015-01-16 08:12:50 +08:00
|
|
|
probe_quit:
|
|
|
|
pm_runtime_put_sync(&pdev->dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int netcp_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct netcp_device *netcp_device = platform_get_drvdata(pdev);
|
2015-07-29 06:20:12 +08:00
|
|
|
struct netcp_intf *netcp_intf, *netcp_tmp;
|
2015-01-16 08:12:50 +08:00
|
|
|
struct netcp_inst_modpriv *inst_modpriv, *tmp;
|
|
|
|
struct netcp_module *module;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(inst_modpriv, tmp, &netcp_device->modpriv_head,
|
|
|
|
inst_list) {
|
|
|
|
module = inst_modpriv->netcp_module;
|
|
|
|
dev_dbg(&pdev->dev, "Removing module \"%s\"\n", module->name);
|
|
|
|
module->remove(netcp_device, inst_modpriv->module_priv);
|
|
|
|
list_del(&inst_modpriv->inst_list);
|
|
|
|
}
|
|
|
|
|
2015-07-29 06:20:12 +08:00
|
|
|
/* now that all modules are removed, clean up the interfaces */
|
|
|
|
list_for_each_entry_safe(netcp_intf, netcp_tmp,
|
|
|
|
&netcp_device->interface_head,
|
|
|
|
interface_list) {
|
|
|
|
netcp_delete_interface(netcp_device, netcp_intf->ndev);
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN(!list_empty(&netcp_device->interface_head),
|
|
|
|
"%s interface list not empty!\n", pdev->name);
|
2015-01-16 08:12:50 +08:00
|
|
|
|
|
|
|
pm_runtime_put_sync(&pdev->dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-18 02:37:32 +08:00
|
|
|
static const struct of_device_id of_match[] = {
|
2015-01-16 08:12:50 +08:00
|
|
|
{ .compatible = "ti,netcp-1.0", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, of_match);
|
|
|
|
|
|
|
|
static struct platform_driver netcp_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "netcp-1.0",
|
|
|
|
.of_match_table = of_match,
|
|
|
|
},
|
|
|
|
.probe = netcp_probe,
|
|
|
|
.remove = netcp_remove,
|
|
|
|
};
|
|
|
|
module_platform_driver(netcp_driver);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("TI NETCP driver for Keystone SOCs");
|
|
|
|
MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com");
|