cxgb4: Move offload Rx queue allocation to separate function
authorHariprasad Shenai <hariprasad@chelsio.com>
Wed, 4 Mar 2015 12:46:27 +0000 (18:16 +0530)
committerDavid S. Miller <davem@davemloft.net>
Thu, 5 Mar 2015 20:11:52 +0000 (15:11 -0500)
Adds a common function for all Rx queue allocation.

Signed-off-by: Hariprasad Shenai <hariprasad@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

index a22cf932ca3536920798ef50241fd9b43c26857a..836e411669157336437ad7dac817872107fc7130 100644 (file)
@@ -957,6 +957,28 @@ static void enable_rx(struct adapter *adap)
        }
 }
 
+static int alloc_ofld_rxqs(struct adapter *adap, struct sge_ofld_rxq *q,
+                          unsigned int nq, unsigned int per_chan, int msi_idx,
+                          u16 *ids)
+{
+       int i, err;
+
+       for (i = 0; i < nq; i++, q++) {
+               if (msi_idx > 0)
+                       msi_idx++;
+               err = t4_sge_alloc_rxq(adap, &q->rspq, false,
+                                      adap->port[i / per_chan],
+                                      msi_idx, q->fl.size ? &q->fl : NULL,
+                                      uldrx_handler);
+               if (err)
+                       return err;
+               memset(&q->stats, 0, sizeof(q->stats));
+               if (ids)
+                       ids[i] = q->rspq.abs_id;
+       }
+       return 0;
+}
+
 /**
  *     setup_sge_queues - configure SGE Tx/Rx/response queues
  *     @adap: the adapter
@@ -1018,51 +1040,26 @@ freeout:        t4_free_sge_resources(adap);
 
        j = s->ofldqsets / adap->params.nports; /* ofld queues per channel */
        for_each_ofldrxq(s, i) {
-               struct sge_ofld_rxq *q = &s->ofldrxq[i];
-               struct net_device *dev = adap->port[i / j];
-
-               if (msi_idx > 0)
-                       msi_idx++;
-               err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev, msi_idx,
-                                      q->fl.size ? &q->fl : NULL,
-                                      uldrx_handler);
-               if (err)
-                       goto freeout;
-               memset(&q->stats, 0, sizeof(q->stats));
-               s->ofld_rxq[i] = q->rspq.abs_id;
-               err = t4_sge_alloc_ofld_txq(adap, &s->ofldtxq[i], dev,
+               err = t4_sge_alloc_ofld_txq(adap, &s->ofldtxq[i],
+                                           adap->port[i / j],
                                            s->fw_evtq.cntxt_id);
                if (err)
                        goto freeout;
        }
 
-       for_each_rdmarxq(s, i) {
-               struct sge_ofld_rxq *q = &s->rdmarxq[i];
+#define ALLOC_OFLD_RXQS(firstq, nq, per_chan, ids) do { \
+       err = alloc_ofld_rxqs(adap, firstq, nq, per_chan, msi_idx, ids); \
+       if (err) \
+               goto freeout; \
+       if (msi_idx > 0) \
+               msi_idx += nq; \
+} while (0)
 
-               if (msi_idx > 0)
-                       msi_idx++;
-               err = t4_sge_alloc_rxq(adap, &q->rspq, false, adap->port[i],
-                                      msi_idx, q->fl.size ? &q->fl : NULL,
-                                      uldrx_handler);
-               if (err)
-                       goto freeout;
-               memset(&q->stats, 0, sizeof(q->stats));
-               s->rdma_rxq[i] = q->rspq.abs_id;
-       }
+       ALLOC_OFLD_RXQS(s->ofldrxq, s->ofldqsets, j, s->ofld_rxq);
+       ALLOC_OFLD_RXQS(s->rdmarxq, s->rdmaqs, 1, s->rdma_rxq);
+       ALLOC_OFLD_RXQS(s->rdmaciq, s->rdmaciqs, 1, s->rdma_ciq);
 
-       for_each_rdmaciq(s, i) {
-               struct sge_ofld_rxq *q = &s->rdmaciq[i];
-
-               if (msi_idx > 0)
-                       msi_idx++;
-               err = t4_sge_alloc_rxq(adap, &q->rspq, false, adap->port[i],
-                                      msi_idx, q->fl.size ? &q->fl : NULL,
-                                      uldrx_handler);
-               if (err)
-                       goto freeout;
-               memset(&q->stats, 0, sizeof(q->stats));
-               s->rdma_ciq[i] = q->rspq.abs_id;
-       }
+#undef ALLOC_OFLD_RXQS
 
        for_each_port(adap, i) {
                /*