aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDwight Engen <dwight.engen@oracle.com>2014-12-11 12:26:15 -0500
committerDavid S. Miller <davem@davemloft.net>2014-12-11 21:52:45 -0500
commitfe47c3c2623d6914655f507a317a6b881bc7c6a4 (patch)
treeb9e30d272af800b1de1f59c7ebe661bc9ac7eb67
parent31f4888f51afb038f7f8e7e4b3f0a80587c92c9b (diff)
vio: create routines for inc,dec vio dring indexes
Both sunvdc and sunvnet implemented distinct functionality for incrementing and decrementing dring indexes. Create common functions for use by both from the sunvnet versions, which were chosen since they will still work correctly in case a non power of two ring size is used. Signed-off-by: Dwight Engen <dwight.engen@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/sparc/include/asm/vio.h15
-rw-r--r--drivers/block/sunvdc.c6
-rw-r--r--drivers/net/ethernet/sun/sunvnet.c30
3 files changed, 25 insertions, 26 deletions
diff --git a/arch/sparc/include/asm/vio.h b/arch/sparc/include/asm/vio.h
index fb124feb363b..8174f6cdbbbb 100644
--- a/arch/sparc/include/asm/vio.h
+++ b/arch/sparc/include/asm/vio.h
@@ -300,6 +300,21 @@ static inline u32 vio_dring_avail(struct vio_dring_state *dr,
300 ((dr->prod - dr->cons) & (ring_size - 1)) - 1); 300 ((dr->prod - dr->cons) & (ring_size - 1)) - 1);
301} 301}
302 302
303static inline u32 vio_dring_next(struct vio_dring_state *dr, u32 index)
304{
305 if (++index == dr->num_entries)
306 index = 0;
307 return index;
308}
309
310static inline u32 vio_dring_prev(struct vio_dring_state *dr, u32 index)
311{
312 if (index == 0)
313 return dr->num_entries - 1;
314 else
315 return index - 1;
316}
317
303#define VIO_MAX_TYPE_LEN 32 318#define VIO_MAX_TYPE_LEN 32
304#define VIO_MAX_COMPAT_LEN 64 319#define VIO_MAX_COMPAT_LEN 64
305 320
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 089ff9035de6..65cec156cfb4 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -269,7 +269,7 @@ static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
269 269
270 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies); 270 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies);
271 desc->hdr.state = VIO_DESC_FREE; 271 desc->hdr.state = VIO_DESC_FREE;
272 dr->cons = (index + 1) & (VDC_TX_RING_SIZE - 1); 272 dr->cons = vio_dring_next(dr, index);
273 273
274 req = rqe->req; 274 req = rqe->req;
275 if (req == NULL) { 275 if (req == NULL) {
@@ -472,7 +472,7 @@ static int __send_request(struct request *req)
472 printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err); 472 printk(KERN_ERR PFX "vdc_tx_trigger() failure, err=%d\n", err);
473 } else { 473 } else {
474 port->req_id++; 474 port->req_id++;
475 dr->prod = (dr->prod + 1) & (VDC_TX_RING_SIZE - 1); 475 dr->prod = vio_dring_next(dr, dr->prod);
476 } 476 }
477 477
478 return err; 478 return err;
@@ -626,7 +626,7 @@ static int generic_request(struct vdc_port *port, u8 op, void *buf, int len)
626 err = __vdc_tx_trigger(port); 626 err = __vdc_tx_trigger(port);
627 if (err >= 0) { 627 if (err >= 0) {
628 port->req_id++; 628 port->req_id++;
629 dr->prod = (dr->prod + 1) & (VDC_TX_RING_SIZE - 1); 629 dr->prod = vio_dring_next(dr, dr->prod);
630 spin_unlock_irqrestore(&port->vio.lock, flags); 630 spin_unlock_irqrestore(&port->vio.lock, flags);
631 631
632 wait_for_completion(&comp.com); 632 wait_for_completion(&comp.com);
diff --git a/drivers/net/ethernet/sun/sunvnet.c b/drivers/net/ethernet/sun/sunvnet.c
index 90c86cd3be14..45c408ef67d0 100644
--- a/drivers/net/ethernet/sun/sunvnet.c
+++ b/drivers/net/ethernet/sun/sunvnet.c
@@ -466,23 +466,6 @@ static int vnet_send_ack(struct vnet_port *port, struct vio_dring_state *dr,
466 return err; 466 return err;
467} 467}
468 468
469static u32 next_idx(u32 idx, struct vio_dring_state *dr)
470{
471 if (++idx == dr->num_entries)
472 idx = 0;
473 return idx;
474}
475
476static u32 prev_idx(u32 idx, struct vio_dring_state *dr)
477{
478 if (idx == 0)
479 idx = dr->num_entries - 1;
480 else
481 idx--;
482
483 return idx;
484}
485
486static struct vio_net_desc *get_rx_desc(struct vnet_port *port, 469static struct vio_net_desc *get_rx_desc(struct vnet_port *port,
487 struct vio_dring_state *dr, 470 struct vio_dring_state *dr,
488 u32 index) 471 u32 index)
@@ -556,7 +539,8 @@ static int vnet_walk_rx(struct vnet_port *port, struct vio_dring_state *dr,
556 int ack_start = -1, ack_end = -1; 539 int ack_start = -1, ack_end = -1;
557 bool send_ack = true; 540 bool send_ack = true;
558 541
559 end = (end == (u32) -1) ? prev_idx(start, dr) : next_idx(end, dr); 542 end = (end == (u32) -1) ? vio_dring_prev(dr, start)
543 : vio_dring_next(dr, end);
560 544
561 viodbg(DATA, "vnet_walk_rx start[%08x] end[%08x]\n", start, end); 545 viodbg(DATA, "vnet_walk_rx start[%08x] end[%08x]\n", start, end);
562 546
@@ -570,7 +554,7 @@ static int vnet_walk_rx(struct vnet_port *port, struct vio_dring_state *dr,
570 if (ack_start == -1) 554 if (ack_start == -1)
571 ack_start = start; 555 ack_start = start;
572 ack_end = start; 556 ack_end = start;
573 start = next_idx(start, dr); 557 start = vio_dring_next(dr, start);
574 if (ack && start != end) { 558 if (ack && start != end) {
575 err = vnet_send_ack(port, dr, ack_start, ack_end, 559 err = vnet_send_ack(port, dr, ack_start, ack_end,
576 VIO_DRING_ACTIVE); 560 VIO_DRING_ACTIVE);
@@ -584,7 +568,7 @@ static int vnet_walk_rx(struct vnet_port *port, struct vio_dring_state *dr,
584 } 568 }
585 } 569 }
586 if (unlikely(ack_start == -1)) 570 if (unlikely(ack_start == -1))
587 ack_start = ack_end = prev_idx(start, dr); 571 ack_start = ack_end = vio_dring_prev(dr, start);
588 if (send_ack) { 572 if (send_ack) {
589 port->napi_resume = false; 573 port->napi_resume = false;
590 return vnet_send_ack(port, dr, ack_start, ack_end, 574 return vnet_send_ack(port, dr, ack_start, ack_end,
@@ -633,7 +617,7 @@ static int idx_is_pending(struct vio_dring_state *dr, u32 end)
633 found = 1; 617 found = 1;
634 break; 618 break;
635 } 619 }
636 idx = next_idx(idx, dr); 620 idx = vio_dring_next(dr, idx);
637 } 621 }
638 return found; 622 return found;
639} 623}
@@ -663,7 +647,7 @@ static int vnet_ack(struct vnet_port *port, void *msgbuf)
663 /* sync for race conditions with vnet_start_xmit() and tell xmit it 647 /* sync for race conditions with vnet_start_xmit() and tell xmit it
664 * is time to send a trigger. 648 * is time to send a trigger.
665 */ 649 */
666 dr->cons = next_idx(end, dr); 650 dr->cons = vio_dring_next(dr, end);
667 desc = vio_dring_entry(dr, dr->cons); 651 desc = vio_dring_entry(dr, dr->cons);
668 if (desc->hdr.state == VIO_DESC_READY && !port->start_cons) { 652 if (desc->hdr.state == VIO_DESC_READY && !port->start_cons) {
669 /* vnet_start_xmit() just populated this dring but missed 653 /* vnet_start_xmit() just populated this dring but missed
@@ -784,7 +768,7 @@ ldc_ctrl:
784 pkt->tag.stype = VIO_SUBTYPE_INFO; 768 pkt->tag.stype = VIO_SUBTYPE_INFO;
785 pkt->tag.stype_env = VIO_DRING_DATA; 769 pkt->tag.stype_env = VIO_DRING_DATA;
786 pkt->seq = dr->rcv_nxt; 770 pkt->seq = dr->rcv_nxt;
787 pkt->start_idx = next_idx(port->napi_stop_idx, dr); 771 pkt->start_idx = vio_dring_next(dr, port->napi_stop_idx);
788 pkt->end_idx = -1; 772 pkt->end_idx = -1;
789 goto napi_resume; 773 goto napi_resume;
790 } 774 }