Skip to content

Commit 2fb717e

Browse files
Alexandre Bouninetorvalds
authored andcommitted
rapidio/rionet: rework to support multiple RIO master ports
Make RIONET driver multi-net safe/capable by introducing per-net lists of RapidIO network peers. Rework registration of network adapters to support all available RIO master port devices. Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com> Cc: Matt Porter <mporter@kernel.crashing.org> Cc: Li Yang <leoli@freescale.com> Cc: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 005842e commit 2fb717e

1 file changed

Lines changed: 70 additions & 63 deletions

File tree

‎drivers/net/rionet.c‎

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <linux/ethtool.h>
2727

2828
#define DRV_NAME "rionet"
29-
#define DRV_VERSION "0.2"
29+
#define DRV_VERSION "0.3"
3030
#define DRV_AUTHOR "Matt Porter <mporter@kernel.crashing.org>"
3131
#define DRV_DESC "Ethernet over RapidIO"
3232

@@ -47,8 +47,7 @@ MODULE_LICENSE("GPL");
4747

4848
#define RIONET_TX_RING_SIZE CONFIG_RIONET_TX_SIZE
4949
#define RIONET_RX_RING_SIZE CONFIG_RIONET_RX_SIZE
50-
51-
static LIST_HEAD(rionet_peers);
50+
#define RIONET_MAX_NETS 8
5251

5352
struct rionet_private {
5453
struct rio_mport *mport;
@@ -69,17 +68,14 @@ struct rionet_peer {
6968
struct resource *res;
7069
};
7170

72-
static int rionet_check = 0;
73-
static int rionet_capable = 1;
71+
struct rionet_net {
72+
struct net_device *ndev;
73+
struct list_head peers;
74+
struct rio_dev **active;
75+
int nact; /* number of active peers */
76+
};
7477

75-
/*
76-
* This is a fast lookup table for translating TX
77-
* Ethernet packets into a destination RIO device. It
78-
* could be made into a hash table to save memory depending
79-
* on system trade-offs.
80-
*/
81-
static struct rio_dev **rionet_active;
82-
static int nact; /* total number of active rionet peers */
78+
static struct rionet_net nets[RIONET_MAX_NETS];
8379

8480
#define is_rionet_capable(src_ops, dst_ops) \
8581
((src_ops & RIO_SRC_OPS_DATA_MSG) && \
@@ -185,7 +181,7 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
185181
}
186182

187183
if (is_multicast_ether_addr(eth->h_dest))
188-
add_num = nact;
184+
add_num = nets[rnet->mport->id].nact;
189185

190186
if ((rnet->tx_cnt + add_num) > RIONET_TX_RING_SIZE) {
191187
netif_stop_queue(ndev);
@@ -197,19 +193,21 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
197193

198194
if (is_multicast_ether_addr(eth->h_dest)) {
199195
int count = 0;
196+
200197
for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size);
201198
i++)
202-
if (rionet_active[i]) {
199+
if (nets[rnet->mport->id].active[i]) {
203200
rionet_queue_tx_msg(skb, ndev,
204-
rionet_active[i]);
201+
nets[rnet->mport->id].active[i]);
205202
if (count)
206203
atomic_inc(&skb->users);
207204
count++;
208205
}
209206
} else if (RIONET_MAC_MATCH(eth->h_dest)) {
210207
destid = RIONET_GET_DESTID(eth->h_dest);
211-
if (rionet_active[destid])
212-
rionet_queue_tx_msg(skb, ndev, rionet_active[destid]);
208+
if (nets[rnet->mport->id].active[destid])
209+
rionet_queue_tx_msg(skb, ndev,
210+
nets[rnet->mport->id].active[destid]);
213211
}
214212

215213
spin_unlock_irqrestore(&rnet->tx_lock, flags);
@@ -228,19 +226,21 @@ static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u
228226
printk(KERN_INFO "%s: doorbell sid %4.4x tid %4.4x info %4.4x",
229227
DRV_NAME, sid, tid, info);
230228
if (info == RIONET_DOORBELL_JOIN) {
231-
if (!rionet_active[sid]) {
232-
list_for_each_entry(peer, &rionet_peers, node) {
229+
if (!nets[rnet->mport->id].active[sid]) {
230+
list_for_each_entry(peer,
231+
&nets[rnet->mport->id].peers, node) {
233232
if (peer->rdev->destid == sid) {
234-
rionet_active[sid] = peer->rdev;
235-
nact++;
233+
nets[rnet->mport->id].active[sid] =
234+
peer->rdev;
235+
nets[rnet->mport->id].nact++;
236236
}
237237
}
238238
rio_mport_send_doorbell(mport, sid,
239239
RIONET_DOORBELL_JOIN);
240240
}
241241
} else if (info == RIONET_DOORBELL_LEAVE) {
242-
rionet_active[sid] = NULL;
243-
nact--;
242+
nets[rnet->mport->id].active[sid] = NULL;
243+
nets[rnet->mport->id].nact--;
244244
} else {
245245
if (netif_msg_intr(rnet))
246246
printk(KERN_WARNING "%s: unhandled doorbell\n",
@@ -334,7 +334,8 @@ static int rionet_open(struct net_device *ndev)
334334
netif_carrier_on(ndev);
335335
netif_start_queue(ndev);
336336

337-
list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
337+
list_for_each_entry_safe(peer, tmp,
338+
&nets[rnet->mport->id].peers, node) {
338339
if (!(peer->res = rio_request_outb_dbell(peer->rdev,
339340
RIONET_DOORBELL_JOIN,
340341
RIONET_DOORBELL_LEAVE)))
@@ -359,18 +360,19 @@ static int rionet_close(struct net_device *ndev)
359360
int i;
360361

361362
if (netif_msg_ifup(rnet))
362-
printk(KERN_INFO "%s: close\n", DRV_NAME);
363+
printk(KERN_INFO "%s: close %s\n", DRV_NAME, ndev->name);
363364

364365
netif_stop_queue(ndev);
365366
netif_carrier_off(ndev);
366367

367368
for (i = 0; i < RIONET_RX_RING_SIZE; i++)
368369
kfree_skb(rnet->rx_skb[i]);
369370

370-
list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
371-
if (rionet_active[peer->rdev->destid]) {
371+
list_for_each_entry_safe(peer, tmp,
372+
&nets[rnet->mport->id].peers, node) {
373+
if (nets[rnet->mport->id].active[peer->rdev->destid]) {
372374
rio_send_doorbell(peer->rdev, RIONET_DOORBELL_LEAVE);
373-
rionet_active[peer->rdev->destid] = NULL;
375+
nets[rnet->mport->id].active[peer->rdev->destid] = NULL;
374376
}
375377
rio_release_outb_dbell(peer->rdev, peer->res);
376378
}
@@ -386,17 +388,21 @@ static int rionet_close(struct net_device *ndev)
386388
static void rionet_remove(struct rio_dev *rdev)
387389
{
388390
struct net_device *ndev = rio_get_drvdata(rdev);
391+
unsigned char netid = rdev->net->hport->id;
389392
struct rionet_peer *peer, *tmp;
390393

391-
free_pages((unsigned long)rionet_active, get_order(sizeof(void *) *
392-
RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size)));
393394
unregister_netdev(ndev);
394-
free_netdev(ndev);
395395

396-
list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
396+
free_pages((unsigned long)nets[netid].active, get_order(sizeof(void *) *
397+
RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size)));
398+
nets[netid].active = NULL;
399+
400+
list_for_each_entry_safe(peer, tmp, &nets[netid].peers, node) {
397401
list_del(&peer->node);
398402
kfree(peer);
399403
}
404+
405+
free_netdev(ndev);
400406
}
401407

402408
static void rionet_get_drvinfo(struct net_device *ndev,
@@ -448,13 +454,13 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
448454
const size_t rionet_active_bytes = sizeof(void *) *
449455
RIO_MAX_ROUTE_ENTRIES(mport->sys_size);
450456

451-
rionet_active = (struct rio_dev **)__get_free_pages(GFP_KERNEL,
452-
get_order(rionet_active_bytes));
453-
if (!rionet_active) {
457+
nets[mport->id].active = (struct rio_dev **)__get_free_pages(GFP_KERNEL,
458+
get_order(rionet_active_bytes));
459+
if (!nets[mport->id].active) {
454460
rc = -ENOMEM;
455461
goto out;
456462
}
457-
memset((void *)rionet_active, 0, rionet_active_bytes);
463+
memset((void *)nets[mport->id].active, 0, rionet_active_bytes);
458464

459465
/* Set up private area */
460466
rnet = netdev_priv(ndev);
@@ -483,61 +489,62 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
483489
if (rc != 0)
484490
goto out;
485491

486-
printk("%s: %s %s Version %s, MAC %pM\n",
492+
printk(KERN_INFO "%s: %s %s Version %s, MAC %pM, %s\n",
487493
ndev->name,
488494
DRV_NAME,
489495
DRV_DESC,
490496
DRV_VERSION,
491-
ndev->dev_addr);
497+
ndev->dev_addr,
498+
mport->name);
492499

493500
out:
494501
return rc;
495502
}
496503

497-
/*
498-
* XXX Make multi-net safe
499-
*/
504+
static unsigned long net_table[RIONET_MAX_NETS/sizeof(unsigned long) + 1];
505+
500506
static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id)
501507
{
502508
int rc = -ENODEV;
503509
u32 lsrc_ops, ldst_ops;
504510
struct rionet_peer *peer;
505511
struct net_device *ndev = NULL;
512+
unsigned char netid = rdev->net->hport->id;
513+
int oldnet;
506514

507-
/* If local device is not rionet capable, give up quickly */
508-
if (!rionet_capable)
509-
goto out;
515+
if (netid >= RIONET_MAX_NETS)
516+
return rc;
510517

511-
/* Allocate our net_device structure */
512-
ndev = alloc_etherdev(sizeof(struct rionet_private));
513-
if (ndev == NULL) {
514-
rc = -ENOMEM;
515-
goto out;
516-
}
518+
oldnet = test_and_set_bit(netid, net_table);
517519

518520
/*
519521
* First time through, make sure local device is rionet
520-
* capable, setup netdev, and set flags so this is skipped
521-
* on later probes
522+
* capable, setup netdev (will be skipped on later probes)
522523
*/
523-
if (!rionet_check) {
524+
if (!oldnet) {
524525
rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR,
525526
&lsrc_ops);
526527
rio_local_read_config_32(rdev->net->hport, RIO_DST_OPS_CAR,
527528
&ldst_ops);
528529
if (!is_rionet_capable(lsrc_ops, ldst_ops)) {
529530
printk(KERN_ERR
530-
"%s: local device is not network capable\n",
531-
DRV_NAME);
532-
rionet_check = 1;
533-
rionet_capable = 0;
531+
"%s: local device %s is not network capable\n",
532+
DRV_NAME, rdev->net->hport->name);
534533
goto out;
535534
}
536535

536+
/* Allocate our net_device structure */
537+
ndev = alloc_etherdev(sizeof(struct rionet_private));
538+
if (ndev == NULL) {
539+
rc = -ENOMEM;
540+
goto out;
541+
}
542+
nets[netid].ndev = ndev;
537543
rc = rionet_setup_netdev(rdev->net->hport, ndev);
538-
rionet_check = 1;
539-
nact = 0;
540-
}
544+
INIT_LIST_HEAD(&nets[netid].peers);
545+
nets[netid].nact = 0;
546+
} else if (nets[netid].ndev == NULL)
547+
goto out;
541548

542549
/*
543550
* If the remote device has mailbox/doorbell capabilities,
@@ -549,10 +556,10 @@ static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id)
549556
goto out;
550557
}
551558
peer->rdev = rdev;
552-
list_add_tail(&peer->node, &rionet_peers);
559+
list_add_tail(&peer->node, &nets[netid].peers);
553560
}
554561

555-
rio_set_drvdata(rdev, ndev);
562+
rio_set_drvdata(rdev, nets[netid].ndev);
556563

557564
out:
558565
return rc;

0 commit comments

Comments
 (0)