caif: Bugfixes in CAIF netdevice for close and flow control
Changes: o Bugfix: Flow control was causing the device to be destroyed. o Bugfix: Handle CAIF channel connect failures. o If the underlying link layer is gone the net-device is no longer removed, but closed. Signed-off-by: Sjur Braendeland <sjur.brandeland@stericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
bece7b2398
Коммит
8391c4aab1
|
@ -22,10 +22,10 @@
|
||||||
#include <net/caif/cfpkt.h>
|
#include <net/caif/cfpkt.h>
|
||||||
#include <net/caif/caif_dev.h>
|
#include <net/caif/caif_dev.h>
|
||||||
|
|
||||||
#define CAIF_CONNECT_TIMEOUT 30
|
/* GPRS PDP connection has MTU to 1500 */
|
||||||
#define SIZE_MTU 1500
|
#define SIZE_MTU 1500
|
||||||
#define SIZE_MTU_MAX 4080
|
/* 5 sec. connect timeout */
|
||||||
#define SIZE_MTU_MIN 68
|
#define CONNECT_TIMEOUT (5 * HZ)
|
||||||
#define CAIF_NET_DEFAULT_QUEUE_LEN 500
|
#define CAIF_NET_DEFAULT_QUEUE_LEN 500
|
||||||
|
|
||||||
#undef pr_debug
|
#undef pr_debug
|
||||||
|
@ -37,6 +37,13 @@ static LIST_HEAD(chnl_net_list);
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_ALIAS_RTNL_LINK("caif");
|
MODULE_ALIAS_RTNL_LINK("caif");
|
||||||
|
|
||||||
|
enum caif_states {
|
||||||
|
CAIF_CONNECTED = 1,
|
||||||
|
CAIF_CONNECTING,
|
||||||
|
CAIF_DISCONNECTED,
|
||||||
|
CAIF_SHUTDOWN
|
||||||
|
};
|
||||||
|
|
||||||
struct chnl_net {
|
struct chnl_net {
|
||||||
struct cflayer chnl;
|
struct cflayer chnl;
|
||||||
struct net_device_stats stats;
|
struct net_device_stats stats;
|
||||||
|
@ -47,7 +54,7 @@ struct chnl_net {
|
||||||
wait_queue_head_t netmgmt_wq;
|
wait_queue_head_t netmgmt_wq;
|
||||||
/* Flow status to remember and control the transmission. */
|
/* Flow status to remember and control the transmission. */
|
||||||
bool flowenabled;
|
bool flowenabled;
|
||||||
bool pending_close;
|
enum caif_states state;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void robust_list_del(struct list_head *delete_node)
|
static void robust_list_del(struct list_head *delete_node)
|
||||||
|
@ -58,15 +65,16 @@ static void robust_list_del(struct list_head *delete_node)
|
||||||
list_for_each_safe(list_node, n, &chnl_net_list) {
|
list_for_each_safe(list_node, n, &chnl_net_list) {
|
||||||
if (list_node == delete_node) {
|
if (list_node == delete_node) {
|
||||||
list_del(list_node);
|
list_del(list_node);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
WARN_ON(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
|
static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
|
||||||
{
|
{
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
struct chnl_net *priv = NULL;
|
struct chnl_net *priv = container_of(layr, struct chnl_net, chnl);
|
||||||
int pktlen;
|
int pktlen;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
@ -91,7 +99,6 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
|
||||||
else
|
else
|
||||||
skb->ip_summed = CHECKSUM_NONE;
|
skb->ip_summed = CHECKSUM_NONE;
|
||||||
|
|
||||||
/* FIXME: Drivers should call this in tasklet context. */
|
|
||||||
if (in_interrupt())
|
if (in_interrupt())
|
||||||
netif_rx(skb);
|
netif_rx(skb);
|
||||||
else
|
else
|
||||||
|
@ -117,14 +124,16 @@ static void close_work(struct work_struct *work)
|
||||||
struct chnl_net *dev = NULL;
|
struct chnl_net *dev = NULL;
|
||||||
struct list_head *list_node;
|
struct list_head *list_node;
|
||||||
struct list_head *_tmp;
|
struct list_head *_tmp;
|
||||||
|
/* May be called with or without RTNL lock held */
|
||||||
|
int islocked = rtnl_is_locked();
|
||||||
|
if (!islocked)
|
||||||
rtnl_lock();
|
rtnl_lock();
|
||||||
list_for_each_safe(list_node, _tmp, &chnl_net_list) {
|
list_for_each_safe(list_node, _tmp, &chnl_net_list) {
|
||||||
dev = list_entry(list_node, struct chnl_net, list_field);
|
dev = list_entry(list_node, struct chnl_net, list_field);
|
||||||
if (!dev->pending_close)
|
if (dev->state == CAIF_SHUTDOWN)
|
||||||
continue;
|
dev_close(dev->netdev);
|
||||||
list_del(list_node);
|
|
||||||
delete_device(dev);
|
|
||||||
}
|
}
|
||||||
|
if (!islocked)
|
||||||
rtnl_unlock();
|
rtnl_unlock();
|
||||||
}
|
}
|
||||||
static DECLARE_WORK(close_worker, close_work);
|
static DECLARE_WORK(close_worker, close_work);
|
||||||
|
@ -132,8 +141,8 @@ static DECLARE_WORK(close_worker, close_work);
|
||||||
static void chnl_flowctrl_cb(struct cflayer *layr, enum caif_ctrlcmd flow,
|
static void chnl_flowctrl_cb(struct cflayer *layr, enum caif_ctrlcmd flow,
|
||||||
int phyid)
|
int phyid)
|
||||||
{
|
{
|
||||||
struct chnl_net *priv;
|
struct chnl_net *priv = container_of(layr, struct chnl_net, chnl);
|
||||||
pr_debug("CAIF: %s(): NET flowctrl func called flow: %s.\n",
|
pr_debug("CAIF: %s(): NET flowctrl func called flow: %s\n",
|
||||||
__func__,
|
__func__,
|
||||||
flow == CAIF_CTRLCMD_FLOW_ON_IND ? "ON" :
|
flow == CAIF_CTRLCMD_FLOW_ON_IND ? "ON" :
|
||||||
flow == CAIF_CTRLCMD_INIT_RSP ? "INIT" :
|
flow == CAIF_CTRLCMD_INIT_RSP ? "INIT" :
|
||||||
|
@ -143,21 +152,31 @@ static void chnl_flowctrl_cb(struct cflayer *layr, enum caif_ctrlcmd flow,
|
||||||
flow == CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND ?
|
flow == CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND ?
|
||||||
"REMOTE_SHUTDOWN" : "UKNOWN CTRL COMMAND");
|
"REMOTE_SHUTDOWN" : "UKNOWN CTRL COMMAND");
|
||||||
|
|
||||||
priv = container_of(layr, struct chnl_net, chnl);
|
|
||||||
|
|
||||||
switch (flow) {
|
switch (flow) {
|
||||||
case CAIF_CTRLCMD_FLOW_OFF_IND:
|
case CAIF_CTRLCMD_FLOW_OFF_IND:
|
||||||
case CAIF_CTRLCMD_DEINIT_RSP:
|
|
||||||
case CAIF_CTRLCMD_INIT_FAIL_RSP:
|
|
||||||
case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
|
|
||||||
priv->flowenabled = false;
|
priv->flowenabled = false;
|
||||||
|
netif_stop_queue(priv->netdev);
|
||||||
|
break;
|
||||||
|
case CAIF_CTRLCMD_DEINIT_RSP:
|
||||||
|
priv->state = CAIF_DISCONNECTED;
|
||||||
|
break;
|
||||||
|
case CAIF_CTRLCMD_INIT_FAIL_RSP:
|
||||||
|
priv->state = CAIF_DISCONNECTED;
|
||||||
|
wake_up_interruptible(&priv->netmgmt_wq);
|
||||||
|
break;
|
||||||
|
case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
|
||||||
|
priv->state = CAIF_SHUTDOWN;
|
||||||
netif_tx_disable(priv->netdev);
|
netif_tx_disable(priv->netdev);
|
||||||
pr_warning("CAIF: %s(): done\n", __func__);
|
|
||||||
priv->pending_close = 1;
|
|
||||||
schedule_work(&close_worker);
|
schedule_work(&close_worker);
|
||||||
break;
|
break;
|
||||||
case CAIF_CTRLCMD_FLOW_ON_IND:
|
case CAIF_CTRLCMD_FLOW_ON_IND:
|
||||||
|
priv->flowenabled = true;
|
||||||
|
netif_wake_queue(priv->netdev);
|
||||||
|
break;
|
||||||
case CAIF_CTRLCMD_INIT_RSP:
|
case CAIF_CTRLCMD_INIT_RSP:
|
||||||
|
priv->state = CAIF_CONNECTED;
|
||||||
priv->flowenabled = true;
|
priv->flowenabled = true;
|
||||||
netif_wake_queue(priv->netdev);
|
netif_wake_queue(priv->netdev);
|
||||||
wake_up_interruptible(&priv->netmgmt_wq);
|
wake_up_interruptible(&priv->netmgmt_wq);
|
||||||
|
@ -194,9 +213,6 @@ static int chnl_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||||
|
|
||||||
pkt = cfpkt_fromnative(CAIF_DIR_OUT, (void *) skb);
|
pkt = cfpkt_fromnative(CAIF_DIR_OUT, (void *) skb);
|
||||||
|
|
||||||
pr_debug("CAIF: %s(): transmit inst %s %d,%p\n",
|
|
||||||
__func__, dev->name, priv->chnl.dn->id, &priv->chnl.dn);
|
|
||||||
|
|
||||||
/* Send the packet down the stack. */
|
/* Send the packet down the stack. */
|
||||||
result = priv->chnl.dn->transmit(priv->chnl.dn, pkt);
|
result = priv->chnl.dn->transmit(priv->chnl.dn, pkt);
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -217,61 +233,59 @@ static int chnl_net_open(struct net_device *dev)
|
||||||
struct chnl_net *priv = NULL;
|
struct chnl_net *priv = NULL;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
ASSERT_RTNL();
|
ASSERT_RTNL();
|
||||||
|
|
||||||
priv = netdev_priv(dev);
|
priv = netdev_priv(dev);
|
||||||
pr_debug("CAIF: %s(): dev name: %s\n", __func__, priv->name);
|
|
||||||
|
|
||||||
if (!priv) {
|
if (!priv) {
|
||||||
pr_debug("CAIF: %s(): chnl_net_open: no priv\n", __func__);
|
pr_debug("CAIF: %s(): chnl_net_open: no priv\n", __func__);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (priv->state != CAIF_CONNECTING) {
|
||||||
|
priv->state = CAIF_CONNECTING;
|
||||||
result = caif_connect_client(&priv->conn_req, &priv->chnl);
|
result = caif_connect_client(&priv->conn_req, &priv->chnl);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
|
priv->state = CAIF_DISCONNECTED;
|
||||||
pr_debug("CAIF: %s(): err: "
|
pr_debug("CAIF: %s(): err: "
|
||||||
"Unable to register and open device, Err:%d\n",
|
"Unable to register and open device,"
|
||||||
|
" Err:%d\n",
|
||||||
__func__,
|
__func__,
|
||||||
result);
|
result);
|
||||||
return -ENODEV;
|
return result;
|
||||||
}
|
}
|
||||||
result = wait_event_interruptible(priv->netmgmt_wq, priv->flowenabled);
|
}
|
||||||
|
|
||||||
|
result = wait_event_interruptible_timeout(priv->netmgmt_wq,
|
||||||
|
priv->state != CAIF_CONNECTING,
|
||||||
|
CONNECT_TIMEOUT);
|
||||||
|
|
||||||
if (result == -ERESTARTSYS) {
|
if (result == -ERESTARTSYS) {
|
||||||
pr_debug("CAIF: %s(): wait_event_interruptible"
|
pr_debug("CAIF: %s(): wait_event_interruptible"
|
||||||
" woken by a signal\n", __func__);
|
" woken by a signal\n", __func__);
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
} else
|
}
|
||||||
pr_debug("CAIF: %s(): Flow on recieved\n", __func__);
|
if (result == 0) {
|
||||||
|
pr_debug("CAIF: %s(): connect timeout\n", __func__);
|
||||||
|
caif_disconnect_client(&priv->chnl);
|
||||||
|
priv->state = CAIF_DISCONNECTED;
|
||||||
|
pr_debug("CAIF: %s(): state disconnected\n", __func__);
|
||||||
|
return -ETIMEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priv->state != CAIF_CONNECTED) {
|
||||||
|
pr_debug("CAIF: %s(): connect failed\n", __func__);
|
||||||
|
return -ECONNREFUSED;
|
||||||
|
}
|
||||||
|
pr_debug("CAIF: %s(): CAIF Netdevice connected\n", __func__);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chnl_net_stop(struct net_device *dev)
|
static int chnl_net_stop(struct net_device *dev)
|
||||||
{
|
{
|
||||||
struct chnl_net *priv;
|
struct chnl_net *priv;
|
||||||
int result = -1;
|
|
||||||
ASSERT_RTNL();
|
ASSERT_RTNL();
|
||||||
priv = netdev_priv(dev);
|
priv = netdev_priv(dev);
|
||||||
|
priv->state = CAIF_DISCONNECTED;
|
||||||
result = caif_disconnect_client(&priv->chnl);
|
caif_disconnect_client(&priv->chnl);
|
||||||
if (result != 0) {
|
|
||||||
pr_debug("CAIF: %s(): chnl_net_stop: err: "
|
|
||||||
"Unable to STOP device, Err:%d\n",
|
|
||||||
__func__, result);
|
|
||||||
return -EBUSY;
|
|
||||||
}
|
|
||||||
result = wait_event_interruptible(priv->netmgmt_wq,
|
|
||||||
!priv->flowenabled);
|
|
||||||
|
|
||||||
if (result == -ERESTARTSYS) {
|
|
||||||
pr_debug("CAIF: %s(): wait_event_interruptible woken by"
|
|
||||||
" signal, signal_pending(current) = %d\n",
|
|
||||||
__func__,
|
|
||||||
signal_pending(current));
|
|
||||||
} else {
|
|
||||||
pr_debug("CAIF: %s(): disconnect received\n", __func__);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,6 +391,8 @@ static int ipcaif_newlink(struct net *src_net, struct net_device *dev,
|
||||||
ASSERT_RTNL();
|
ASSERT_RTNL();
|
||||||
caifdev = netdev_priv(dev);
|
caifdev = netdev_priv(dev);
|
||||||
caif_netlink_parms(data, &caifdev->conn_req);
|
caif_netlink_parms(data, &caifdev->conn_req);
|
||||||
|
dev_net_set(caifdev->netdev, src_net);
|
||||||
|
|
||||||
ret = register_netdevice(dev);
|
ret = register_netdevice(dev);
|
||||||
if (ret)
|
if (ret)
|
||||||
pr_warning("CAIF: %s(): device rtml registration failed\n",
|
pr_warning("CAIF: %s(): device rtml registration failed\n",
|
||||||
|
|
Загрузка…
Ссылка в новой задаче