Commit 34ed2ebb authored by Alexandre Bounine's avatar Alexandre Bounine Committed by Linus Torvalds

rapidio/rionet: add locking into add/remove device

Add spinlock protection when handling list of connected peers and
ability to handle new peer device addition after the RIONET device was
open.  Before his update RIONET was sending JOIN requests only when it
have been opened, peer devices added later have been missing from this
process.
Signed-off-by: default avatarAlexandre Bounine <alexandre.bounine@idt.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Andre van Herk <andre.van.herk@prodrive-technologies.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dd64f4fe
...@@ -63,6 +63,7 @@ struct rionet_private { ...@@ -63,6 +63,7 @@ struct rionet_private {
spinlock_t lock; spinlock_t lock;
spinlock_t tx_lock; spinlock_t tx_lock;
u32 msg_enable; u32 msg_enable;
bool open;
}; };
struct rionet_peer { struct rionet_peer {
...@@ -74,6 +75,7 @@ struct rionet_peer { ...@@ -74,6 +75,7 @@ struct rionet_peer {
struct rionet_net { struct rionet_net {
struct net_device *ndev; struct net_device *ndev;
struct list_head peers; struct list_head peers;
spinlock_t lock; /* net info access lock */
struct rio_dev **active; struct rio_dev **active;
int nact; /* number of active peers */ int nact; /* number of active peers */
}; };
...@@ -235,26 +237,32 @@ static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u ...@@ -235,26 +237,32 @@ static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u
struct net_device *ndev = dev_id; struct net_device *ndev = dev_id;
struct rionet_private *rnet = netdev_priv(ndev); struct rionet_private *rnet = netdev_priv(ndev);
struct rionet_peer *peer; struct rionet_peer *peer;
unsigned char netid = rnet->mport->id;
if (netif_msg_intr(rnet)) if (netif_msg_intr(rnet))
printk(KERN_INFO "%s: doorbell sid %4.4x tid %4.4x info %4.4x", printk(KERN_INFO "%s: doorbell sid %4.4x tid %4.4x info %4.4x",
DRV_NAME, sid, tid, info); DRV_NAME, sid, tid, info);
if (info == RIONET_DOORBELL_JOIN) { if (info == RIONET_DOORBELL_JOIN) {
if (!nets[rnet->mport->id].active[sid]) { if (!nets[netid].active[sid]) {
list_for_each_entry(peer, spin_lock(&nets[netid].lock);
&nets[rnet->mport->id].peers, node) { list_for_each_entry(peer, &nets[netid].peers, node) {
if (peer->rdev->destid == sid) { if (peer->rdev->destid == sid) {
nets[rnet->mport->id].active[sid] = nets[netid].active[sid] = peer->rdev;
peer->rdev; nets[netid].nact++;
nets[rnet->mport->id].nact++;
} }
} }
spin_unlock(&nets[netid].lock);
rio_mport_send_doorbell(mport, sid, rio_mport_send_doorbell(mport, sid,
RIONET_DOORBELL_JOIN); RIONET_DOORBELL_JOIN);
} }
} else if (info == RIONET_DOORBELL_LEAVE) { } else if (info == RIONET_DOORBELL_LEAVE) {
nets[rnet->mport->id].active[sid] = NULL; spin_lock(&nets[netid].lock);
nets[rnet->mport->id].nact--; if (nets[netid].active[sid]) {
nets[netid].active[sid] = NULL;
nets[netid].nact--;
}
spin_unlock(&nets[netid].lock);
} else { } else {
if (netif_msg_intr(rnet)) if (netif_msg_intr(rnet))
printk(KERN_WARNING "%s: unhandled doorbell\n", printk(KERN_WARNING "%s: unhandled doorbell\n",
...@@ -308,8 +316,10 @@ static void rionet_outb_msg_event(struct rio_mport *mport, void *dev_id, int mbo ...@@ -308,8 +316,10 @@ static void rionet_outb_msg_event(struct rio_mport *mport, void *dev_id, int mbo
static int rionet_open(struct net_device *ndev) static int rionet_open(struct net_device *ndev)
{ {
int i, rc = 0; int i, rc = 0;
struct rionet_peer *peer, *tmp; struct rionet_peer *peer;
struct rionet_private *rnet = netdev_priv(ndev); struct rionet_private *rnet = netdev_priv(ndev);
unsigned char netid = rnet->mport->id;
unsigned long flags;
if (netif_msg_ifup(rnet)) if (netif_msg_ifup(rnet))
printk(KERN_INFO "%s: open\n", DRV_NAME); printk(KERN_INFO "%s: open\n", DRV_NAME);
...@@ -348,20 +358,13 @@ static int rionet_open(struct net_device *ndev) ...@@ -348,20 +358,13 @@ static int rionet_open(struct net_device *ndev)
netif_carrier_on(ndev); netif_carrier_on(ndev);
netif_start_queue(ndev); netif_start_queue(ndev);
list_for_each_entry_safe(peer, tmp, spin_lock_irqsave(&nets[netid].lock, flags);
&nets[rnet->mport->id].peers, node) { list_for_each_entry(peer, &nets[netid].peers, node) {
if (!(peer->res = rio_request_outb_dbell(peer->rdev,
RIONET_DOORBELL_JOIN,
RIONET_DOORBELL_LEAVE)))
{
printk(KERN_ERR "%s: error requesting doorbells\n",
DRV_NAME);
continue;
}
/* Send a join message */ /* Send a join message */
rio_send_doorbell(peer->rdev, RIONET_DOORBELL_JOIN); rio_send_doorbell(peer->rdev, RIONET_DOORBELL_JOIN);
} }
spin_unlock_irqrestore(&nets[netid].lock, flags);
rnet->open = true;
out: out:
return rc; return rc;
...@@ -370,7 +373,9 @@ static int rionet_open(struct net_device *ndev) ...@@ -370,7 +373,9 @@ static int rionet_open(struct net_device *ndev)
static int rionet_close(struct net_device *ndev) static int rionet_close(struct net_device *ndev)
{ {
struct rionet_private *rnet = netdev_priv(ndev); struct rionet_private *rnet = netdev_priv(ndev);
struct rionet_peer *peer, *tmp; struct rionet_peer *peer;
unsigned char netid = rnet->mport->id;
unsigned long flags;
int i; int i;
if (netif_msg_ifup(rnet)) if (netif_msg_ifup(rnet))
...@@ -378,18 +383,21 @@ static int rionet_close(struct net_device *ndev) ...@@ -378,18 +383,21 @@ static int rionet_close(struct net_device *ndev)
netif_stop_queue(ndev); netif_stop_queue(ndev);
netif_carrier_off(ndev); netif_carrier_off(ndev);
rnet->open = false;
for (i = 0; i < RIONET_RX_RING_SIZE; i++) for (i = 0; i < RIONET_RX_RING_SIZE; i++)
kfree_skb(rnet->rx_skb[i]); kfree_skb(rnet->rx_skb[i]);
list_for_each_entry_safe(peer, tmp, spin_lock_irqsave(&nets[netid].lock, flags);
&nets[rnet->mport->id].peers, node) { list_for_each_entry(peer, &nets[netid].peers, node) {
if (nets[rnet->mport->id].active[peer->rdev->destid]) { if (nets[netid].active[peer->rdev->destid]) {
rio_send_doorbell(peer->rdev, RIONET_DOORBELL_LEAVE); rio_send_doorbell(peer->rdev, RIONET_DOORBELL_LEAVE);
nets[rnet->mport->id].active[peer->rdev->destid] = NULL; nets[netid].active[peer->rdev->destid] = NULL;
} }
rio_release_outb_dbell(peer->rdev, peer->res); if (peer->res)
rio_release_outb_dbell(peer->rdev, peer->res);
} }
spin_unlock_irqrestore(&nets[netid].lock, flags);
rio_release_inb_dbell(rnet->mport, RIONET_DOORBELL_JOIN, rio_release_inb_dbell(rnet->mport, RIONET_DOORBELL_JOIN,
RIONET_DOORBELL_LEAVE); RIONET_DOORBELL_LEAVE);
...@@ -403,22 +411,38 @@ static void rionet_remove_dev(struct device *dev, struct subsys_interface *sif) ...@@ -403,22 +411,38 @@ static void rionet_remove_dev(struct device *dev, struct subsys_interface *sif)
{ {
struct rio_dev *rdev = to_rio_dev(dev); struct rio_dev *rdev = to_rio_dev(dev);
unsigned char netid = rdev->net->hport->id; unsigned char netid = rdev->net->hport->id;
struct rionet_peer *peer, *tmp; struct rionet_peer *peer;
int state, found = 0;
unsigned long flags;
if (dev_rionet_capable(rdev)) { if (!dev_rionet_capable(rdev))
list_for_each_entry_safe(peer, tmp, &nets[netid].peers, node) { return;
if (peer->rdev == rdev) {
if (nets[netid].active[rdev->destid]) { spin_lock_irqsave(&nets[netid].lock, flags);
nets[netid].active[rdev->destid] = NULL; list_for_each_entry(peer, &nets[netid].peers, node) {
nets[netid].nact--; if (peer->rdev == rdev) {
list_del(&peer->node);
if (nets[netid].active[rdev->destid]) {
state = atomic_read(&rdev->state);
if (state != RIO_DEVICE_GONE &&
state != RIO_DEVICE_INITIALIZING) {
rio_send_doorbell(rdev,
RIONET_DOORBELL_LEAVE);
} }
nets[netid].active[rdev->destid] = NULL;
list_del(&peer->node); nets[netid].nact--;
kfree(peer);
break;
} }
found = 1;
break;
} }
} }
spin_unlock_irqrestore(&nets[netid].lock, flags);
if (found) {
if (peer->res)
rio_release_outb_dbell(rdev, peer->res);
kfree(peer);
}
} }
static void rionet_get_drvinfo(struct net_device *ndev, static void rionet_get_drvinfo(struct net_device *ndev,
...@@ -492,6 +516,7 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev) ...@@ -492,6 +516,7 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
/* Set up private area */ /* Set up private area */
rnet = netdev_priv(ndev); rnet = netdev_priv(ndev);
rnet->mport = mport; rnet->mport = mport;
rnet->open = false;
/* Set the default MAC address */ /* Set the default MAC address */
device_id = rio_local_get_device_id(mport); device_id = rio_local_get_device_id(mport);
...@@ -514,8 +539,11 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev) ...@@ -514,8 +539,11 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
rnet->msg_enable = RIONET_DEFAULT_MSGLEVEL; rnet->msg_enable = RIONET_DEFAULT_MSGLEVEL;
rc = register_netdev(ndev); rc = register_netdev(ndev);
if (rc != 0) if (rc != 0) {
free_pages((unsigned long)nets[mport->id].active,
get_order(rionet_active_bytes));
goto out; goto out;
}
printk(KERN_INFO "%s: %s %s Version %s, MAC %pM, %s\n", printk(KERN_INFO "%s: %s %s Version %s, MAC %pM, %s\n",
ndev->name, ndev->name,
...@@ -529,8 +557,6 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev) ...@@ -529,8 +557,6 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
return rc; return rc;
} }
static unsigned long net_table[RIONET_MAX_NETS/sizeof(unsigned long) + 1];
static int rionet_add_dev(struct device *dev, struct subsys_interface *sif) static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
{ {
int rc = -ENODEV; int rc = -ENODEV;
...@@ -539,19 +565,16 @@ static int rionet_add_dev(struct device *dev, struct subsys_interface *sif) ...@@ -539,19 +565,16 @@ static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
struct net_device *ndev = NULL; struct net_device *ndev = NULL;
struct rio_dev *rdev = to_rio_dev(dev); struct rio_dev *rdev = to_rio_dev(dev);
unsigned char netid = rdev->net->hport->id; unsigned char netid = rdev->net->hport->id;
int oldnet;
if (netid >= RIONET_MAX_NETS) if (netid >= RIONET_MAX_NETS)
return rc; return rc;
oldnet = test_and_set_bit(netid, net_table);
/* /*
* If first time through this net, make sure local device is rionet * If first time through this net, make sure local device is rionet
* capable and setup netdev (this step will be skipped in later probes * capable and setup netdev (this step will be skipped in later probes
* on the same net). * on the same net).
*/ */
if (!oldnet) { if (!nets[netid].ndev) {
rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR, rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR,
&lsrc_ops); &lsrc_ops);
rio_local_read_config_32(rdev->net->hport, RIO_DST_OPS_CAR, rio_local_read_config_32(rdev->net->hport, RIO_DST_OPS_CAR,
...@@ -569,30 +592,56 @@ static int rionet_add_dev(struct device *dev, struct subsys_interface *sif) ...@@ -569,30 +592,56 @@ static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
nets[netid].ndev = ndev;
rc = rionet_setup_netdev(rdev->net->hport, ndev); rc = rionet_setup_netdev(rdev->net->hport, ndev);
if (rc) { if (rc) {
printk(KERN_ERR "%s: failed to setup netdev (rc=%d)\n", printk(KERN_ERR "%s: failed to setup netdev (rc=%d)\n",
DRV_NAME, rc); DRV_NAME, rc);
free_netdev(ndev);
goto out; goto out;
} }
INIT_LIST_HEAD(&nets[netid].peers); INIT_LIST_HEAD(&nets[netid].peers);
spin_lock_init(&nets[netid].lock);
nets[netid].nact = 0; nets[netid].nact = 0;
} else if (nets[netid].ndev == NULL) nets[netid].ndev = ndev;
goto out; }
/* /*
* If the remote device has mailbox/doorbell capabilities, * If the remote device has mailbox/doorbell capabilities,
* add it to the peer list. * add it to the peer list.
*/ */
if (dev_rionet_capable(rdev)) { if (dev_rionet_capable(rdev)) {
if (!(peer = kmalloc(sizeof(struct rionet_peer), GFP_KERNEL))) { struct rionet_private *rnet;
unsigned long flags;
rnet = netdev_priv(nets[netid].ndev);
peer = kzalloc(sizeof(*peer), GFP_KERNEL);
if (!peer) {
rc = -ENOMEM; rc = -ENOMEM;
goto out; goto out;
} }
peer->rdev = rdev; peer->rdev = rdev;
peer->res = rio_request_outb_dbell(peer->rdev,
RIONET_DOORBELL_JOIN,
RIONET_DOORBELL_LEAVE);
if (!peer->res) {
pr_err("%s: error requesting doorbells\n", DRV_NAME);
kfree(peer);
rc = -ENOMEM;
goto out;
}
spin_lock_irqsave(&nets[netid].lock, flags);
list_add_tail(&peer->node, &nets[netid].peers); list_add_tail(&peer->node, &nets[netid].peers);
spin_unlock_irqrestore(&nets[netid].lock, flags);
pr_debug("%s: %s add peer %s\n",
DRV_NAME, __func__, rio_name(rdev));
/* If netdev is already opened, send join request to new peer */
if (rnet->open)
rio_send_doorbell(peer->rdev, RIONET_DOORBELL_JOIN);
} }
return 0; return 0;
...@@ -603,7 +652,8 @@ static int rionet_add_dev(struct device *dev, struct subsys_interface *sif) ...@@ -603,7 +652,8 @@ static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
static int rionet_shutdown(struct notifier_block *nb, unsigned long code, static int rionet_shutdown(struct notifier_block *nb, unsigned long code,
void *unused) void *unused)
{ {
struct rionet_peer *peer, *tmp; struct rionet_peer *peer;
unsigned long flags;
int i; int i;
pr_debug("%s: %s\n", DRV_NAME, __func__); pr_debug("%s: %s\n", DRV_NAME, __func__);
...@@ -612,13 +662,15 @@ static int rionet_shutdown(struct notifier_block *nb, unsigned long code, ...@@ -612,13 +662,15 @@ static int rionet_shutdown(struct notifier_block *nb, unsigned long code,
if (!nets[i].ndev) if (!nets[i].ndev)
continue; continue;
list_for_each_entry_safe(peer, tmp, &nets[i].peers, node) { spin_lock_irqsave(&nets[i].lock, flags);
list_for_each_entry(peer, &nets[i].peers, node) {
if (nets[i].active[peer->rdev->destid]) { if (nets[i].active[peer->rdev->destid]) {
rio_send_doorbell(peer->rdev, rio_send_doorbell(peer->rdev,
RIONET_DOORBELL_LEAVE); RIONET_DOORBELL_LEAVE);
nets[i].active[peer->rdev->destid] = NULL; nets[i].active[peer->rdev->destid] = NULL;
} }
} }
spin_unlock_irqrestore(&nets[i].lock, flags);
} }
return NOTIFY_DONE; return NOTIFY_DONE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment