]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/enic/vnic_rq.c
enic: Bug Fix: Handle surprise hardware removals
[net-next-2.6.git] / drivers / net / enic / vnic_rq.c
index e186efaf9da1fc0c5d552fdb90aac7885b553a86..061a26fbbbfb566b4284dc6874df5d5602d1ad7a 100644 (file)
@@ -37,23 +37,23 @@ static int vnic_rq_alloc_bufs(struct vnic_rq *rq)
        vdev = rq->vdev;
 
        for (i = 0; i < blks; i++) {
-               rq->bufs[i] = kzalloc(VNIC_RQ_BUF_BLK_SZ, GFP_ATOMIC);
+               rq->bufs[i] = kzalloc(VNIC_RQ_BUF_BLK_SZ(count), GFP_ATOMIC);
                if (!rq->bufs[i]) {
-                       printk(KERN_ERR "Failed to alloc rq_bufs\n");
+                       pr_err("Failed to alloc rq_bufs\n");
                        return -ENOMEM;
                }
        }
 
        for (i = 0; i < blks; i++) {
                buf = rq->bufs[i];
-               for (j = 0; j < VNIC_RQ_BUF_BLK_ENTRIES; j++) {
-                       buf->index = i * VNIC_RQ_BUF_BLK_ENTRIES + j;
+               for (j = 0; j < VNIC_RQ_BUF_BLK_ENTRIES(count); j++) {
+                       buf->index = i * VNIC_RQ_BUF_BLK_ENTRIES(count) + j;
                        buf->desc = (u8 *)rq->ring.descs +
                                rq->ring.desc_size * buf->index;
                        if (buf->index + 1 == count) {
                                buf->next = rq->bufs[0];
                                break;
-                       } else if (j + 1 == VNIC_RQ_BUF_BLK_ENTRIES) {
+                       } else if (j + 1 == VNIC_RQ_BUF_BLK_ENTRIES(count)) {
                                buf->next = rq->bufs[i + 1];
                        } else {
                                buf->next = buf + 1;
@@ -94,7 +94,7 @@ int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
 
        rq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_RQ, index);
        if (!rq->ctrl) {
-               printk(KERN_ERR "Failed to hook RQ[%d] resource\n", index);
+               pr_err("Failed to hook RQ[%d] resource\n", index);
                return -EINVAL;
        }
 
@@ -119,10 +119,11 @@ void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
        unsigned int error_interrupt_offset)
 {
        u64 paddr;
+       unsigned int count = rq->ring.desc_count;
 
        paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET;
        writeq(paddr, &rq->ctrl->ring_base);
-       iowrite32(rq->ring.desc_count, &rq->ctrl->ring_size);
+       iowrite32(count, &rq->ctrl->ring_size);
        iowrite32(cq_index, &rq->ctrl->cq_index);
        iowrite32(error_interrupt_enable, &rq->ctrl->error_interrupt_enable);
        iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset);
@@ -132,8 +133,8 @@ void vnic_rq_init_start(struct vnic_rq *rq, unsigned int cq_index,
        iowrite32(posted_index, &rq->ctrl->posted_index);
 
        rq->to_use = rq->to_clean =
-               &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES]
-                       [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES];
+               &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES(count)]
+                       [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES(count)];
 }
 
 void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
@@ -145,6 +146,11 @@ void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
        /* Use current fetch_index as the ring starting point */
        fetch_index = ioread32(&rq->ctrl->fetch_index);
 
+       if (fetch_index == 0xFFFFFFFF) { /* check for hardware gone  */
+               /* Hardware surprise removal: reset fetch_index */
+               fetch_index = 0;
+       }
+
        vnic_rq_init_start(rq, cq_index,
                fetch_index, fetch_index,
                error_interrupt_enable,
@@ -168,13 +174,13 @@ int vnic_rq_disable(struct vnic_rq *rq)
        iowrite32(0, &rq->ctrl->enable);
 
        /* Wait for HW to ACK disable request */
-       for (wait = 0; wait < 100; wait++) {
+       for (wait = 0; wait < 1000; wait++) {
                if (!(ioread32(&rq->ctrl->running)))
                        return 0;
-               udelay(1);
+               udelay(10);
        }
 
-       printk(KERN_ERR "Failed to disable RQ[%d]\n", rq->index);
+       pr_err("Failed to disable RQ[%d]\n", rq->index);
 
        return -ETIMEDOUT;
 }
@@ -184,8 +190,7 @@ void vnic_rq_clean(struct vnic_rq *rq,
 {
        struct vnic_rq_buf *buf;
        u32 fetch_index;
-
-       BUG_ON(ioread32(&rq->ctrl->enable));
+       unsigned int count = rq->ring.desc_count;
 
        buf = rq->to_clean;
 
@@ -199,9 +204,15 @@ void vnic_rq_clean(struct vnic_rq *rq,
 
        /* Use current fetch_index as the ring starting point */
        fetch_index = ioread32(&rq->ctrl->fetch_index);
+
+       if (fetch_index == 0xFFFFFFFF) { /* check for hardware gone  */
+               /* Hardware surprise removal: reset fetch_index */
+               fetch_index = 0;
+       }
+
        rq->to_use = rq->to_clean =
-               &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES]
-                       [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES];
+               &rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES(count)]
+                       [fetch_index % VNIC_RQ_BUF_BLK_ENTRIES(count)];
        iowrite32(fetch_index, &rq->ctrl->posted_index);
 
        vnic_dev_clear_desc_ring(&rq->ring);