aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/hw/cxgb4/cm.c
diff options
context:
space:
mode:
authorDavid Miller <davem@davemloft.net>2011-12-02 11:52:31 -0500
committerDavid S. Miller <davem@davemloft.net>2011-12-05 15:20:20 -0500
commit3786cf189f8b39cac870193368f9ad9f95fff9a4 (patch)
treed7e8b85a1034ded69eec04efde443a31b349d477 /drivers/infiniband/hw/cxgb4/cm.c
parent40e2bb588f7712e4d58191ccc08b716927d9c7d0 (diff)
infiniband: cxgb4: Consolidate 3 copies of the same operation into 1 helper function.
Three pieces of code do the same thing, create a l2t entry and then import this information into the c4iw_ep object. Create a helper function and call it from these 3 locations instead. Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Roland Dreier <roland@purestorage.com>
Diffstat (limited to 'drivers/infiniband/hw/cxgb4/cm.c')
-rw-r--r--drivers/infiniband/hw/cxgb4/cm.c220
1 files changed, 80 insertions, 140 deletions
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index e61c80271f99..0668bb3472d0 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -1556,6 +1556,67 @@ static void get_4tuple(struct cpl_pass_accept_req *req,
1556 return; 1556 return;
1557} 1557}
1558 1558
1559static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1560 struct c4iw_dev *cdev, bool clear_mpa_v1)
1561{
1562 struct neighbour *n;
1563 int err, step;
1564
1565 rcu_read_lock();
1566 n = dst_get_neighbour_noref(dst);
1567 err = -ENODEV;
1568 if (!n)
1569 goto out;
1570 err = -ENOMEM;
1571 if (n->dev->flags & IFF_LOOPBACK) {
1572 struct net_device *pdev;
1573
1574 pdev = ip_dev_find(&init_net, peer_ip);
1575 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1576 n, pdev, 0);
1577 if (!ep->l2t)
1578 goto out;
1579 ep->mtu = pdev->mtu;
1580 ep->tx_chan = cxgb4_port_chan(pdev);
1581 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1582 step = cdev->rdev.lldi.ntxq /
1583 cdev->rdev.lldi.nchan;
1584 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1585 step = cdev->rdev.lldi.nrxq /
1586 cdev->rdev.lldi.nchan;
1587 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1588 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1589 cxgb4_port_idx(pdev) * step];
1590 dev_put(pdev);
1591 } else {
1592 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1593 n, n->dev, 0);
1594 if (!ep->l2t)
1595 goto out;
1596 ep->mtu = dst_mtu(ep->dst);
1597 ep->tx_chan = cxgb4_port_chan(n->dev);
1598 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1599 step = cdev->rdev.lldi.ntxq /
1600 cdev->rdev.lldi.nchan;
1601 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1602 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1603 step = cdev->rdev.lldi.nrxq /
1604 cdev->rdev.lldi.nchan;
1605 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1606 cxgb4_port_idx(n->dev) * step];
1607
1608 if (clear_mpa_v1) {
1609 ep->retry_with_mpa_v1 = 0;
1610 ep->tried_with_mpa_v1 = 0;
1611 }
1612 }
1613 err = 0;
1614out:
1615 rcu_read_unlock();
1616
1617 return err;
1618}
1619
1559static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb) 1620static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1560{ 1621{
1561 struct c4iw_ep *child_ep, *parent_ep; 1622 struct c4iw_ep *child_ep, *parent_ep;
@@ -1563,18 +1624,11 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1563 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid)); 1624 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1564 struct tid_info *t = dev->rdev.lldi.tids; 1625 struct tid_info *t = dev->rdev.lldi.tids;
1565 unsigned int hwtid = GET_TID(req); 1626 unsigned int hwtid = GET_TID(req);
1566 struct neighbour *neigh;
1567 struct dst_entry *dst; 1627 struct dst_entry *dst;
1568 struct l2t_entry *l2t;
1569 struct rtable *rt; 1628 struct rtable *rt;
1570 __be32 local_ip, peer_ip; 1629 __be32 local_ip, peer_ip;
1571 __be16 local_port, peer_port; 1630 __be16 local_port, peer_port;
1572 struct net_device *pdev; 1631 int err;
1573 u32 tx_chan, smac_idx;
1574 u16 rss_qid;
1575 u32 mtu;
1576 int step;
1577 int txq_idx, ctrlq_idx;
1578 1632
1579 parent_ep = lookup_stid(t, stid); 1633 parent_ep = lookup_stid(t, stid);
1580 PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid); 1634 PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
@@ -1596,49 +1650,24 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1596 goto reject; 1650 goto reject;
1597 } 1651 }
1598 dst = &rt->dst; 1652 dst = &rt->dst;
1599 rcu_read_lock(); 1653
1600 neigh = dst_get_neighbour_noref(dst); 1654 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1601 if (neigh->dev->flags & IFF_LOOPBACK) { 1655 if (!child_ep) {
1602 pdev = ip_dev_find(&init_net, peer_ip); 1656 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1603 BUG_ON(!pdev);
1604 l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, pdev, 0);
1605 mtu = pdev->mtu;
1606 tx_chan = cxgb4_port_chan(pdev);
1607 smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1608 step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
1609 txq_idx = cxgb4_port_idx(pdev) * step;
1610 ctrlq_idx = cxgb4_port_idx(pdev);
1611 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
1612 rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step];
1613 dev_put(pdev);
1614 } else {
1615 l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, neigh->dev, 0);
1616 mtu = dst_mtu(dst);
1617 tx_chan = cxgb4_port_chan(neigh->dev);
1618 smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
1619 step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
1620 txq_idx = cxgb4_port_idx(neigh->dev) * step;
1621 ctrlq_idx = cxgb4_port_idx(neigh->dev);
1622 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
1623 rss_qid = dev->rdev.lldi.rxq_ids[
1624 cxgb4_port_idx(neigh->dev) * step];
1625 }
1626 rcu_read_unlock();
1627 if (!l2t) {
1628 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1629 __func__); 1657 __func__);
1630 dst_release(dst); 1658 dst_release(dst);
1631 goto reject; 1659 goto reject;
1632 } 1660 }
1633 1661
1634 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL); 1662 err = import_ep(child_ep, peer_ip, dst, dev, false);
1635 if (!child_ep) { 1663 if (err) {
1636 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n", 1664 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1637 __func__); 1665 __func__);
1638 cxgb4_l2t_release(l2t);
1639 dst_release(dst); 1666 dst_release(dst);
1667 kfree(child_ep);
1640 goto reject; 1668 goto reject;
1641 } 1669 }
1670
1642 state_set(&child_ep->com, CONNECTING); 1671 state_set(&child_ep->com, CONNECTING);
1643 child_ep->com.dev = dev; 1672 child_ep->com.dev = dev;
1644 child_ep->com.cm_id = NULL; 1673 child_ep->com.cm_id = NULL;
@@ -1651,18 +1680,11 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1651 c4iw_get_ep(&parent_ep->com); 1680 c4iw_get_ep(&parent_ep->com);
1652 child_ep->parent_ep = parent_ep; 1681 child_ep->parent_ep = parent_ep;
1653 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid)); 1682 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
1654 child_ep->l2t = l2t;
1655 child_ep->dst = dst; 1683 child_ep->dst = dst;
1656 child_ep->hwtid = hwtid; 1684 child_ep->hwtid = hwtid;
1657 child_ep->tx_chan = tx_chan;
1658 child_ep->smac_idx = smac_idx;
1659 child_ep->rss_qid = rss_qid;
1660 child_ep->mtu = mtu;
1661 child_ep->txq_idx = txq_idx;
1662 child_ep->ctrlq_idx = ctrlq_idx;
1663 1685
1664 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__, 1686 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
1665 tx_chan, smac_idx, rss_qid); 1687 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
1666 1688
1667 init_timer(&child_ep->timer); 1689 init_timer(&child_ep->timer);
1668 cxgb4_insert_tid(t, child_ep, hwtid); 1690 cxgb4_insert_tid(t, child_ep, hwtid);
@@ -1792,11 +1814,8 @@ static int is_neg_adv_abort(unsigned int status)
1792 1814
1793static int c4iw_reconnect(struct c4iw_ep *ep) 1815static int c4iw_reconnect(struct c4iw_ep *ep)
1794{ 1816{
1795 int err = 0;
1796 struct rtable *rt; 1817 struct rtable *rt;
1797 struct net_device *pdev; 1818 int err = 0;
1798 struct neighbour *neigh;
1799 int step;
1800 1819
1801 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id); 1820 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1802 init_timer(&ep->timer); 1821 init_timer(&ep->timer);
@@ -1824,47 +1843,10 @@ static int c4iw_reconnect(struct c4iw_ep *ep)
1824 } 1843 }
1825 ep->dst = &rt->dst; 1844 ep->dst = &rt->dst;
1826 1845
1827 rcu_read_lock(); 1846 err = import_ep(ep, ep->com.cm_id->remote_addr.sin_addr.s_addr,
1828 neigh = dst_get_neighbour_noref(ep->dst); 1847 ep->dst, ep->com.dev, false);
1829 1848 if (err) {
1830 /* get a l2t entry */
1831 if (neigh->dev->flags & IFF_LOOPBACK) {
1832 PDBG("%s LOOPBACK\n", __func__);
1833 pdev = ip_dev_find(&init_net,
1834 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1835 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1836 neigh, pdev, 0);
1837 ep->mtu = pdev->mtu;
1838 ep->tx_chan = cxgb4_port_chan(pdev);
1839 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1840 step = ep->com.dev->rdev.lldi.ntxq /
1841 ep->com.dev->rdev.lldi.nchan;
1842 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1843 step = ep->com.dev->rdev.lldi.nrxq /
1844 ep->com.dev->rdev.lldi.nchan;
1845 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1846 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1847 cxgb4_port_idx(pdev) * step];
1848 dev_put(pdev);
1849 } else {
1850 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1851 neigh, neigh->dev, 0);
1852 ep->mtu = dst_mtu(ep->dst);
1853 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1854 ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
1855 step = ep->com.dev->rdev.lldi.ntxq /
1856 ep->com.dev->rdev.lldi.nchan;
1857 ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
1858 ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
1859 step = ep->com.dev->rdev.lldi.nrxq /
1860 ep->com.dev->rdev.lldi.nchan;
1861 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1862 cxgb4_port_idx(neigh->dev) * step];
1863 }
1864 rcu_read_unlock();
1865 if (!ep->l2t) {
1866 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); 1849 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
1867 err = -ENOMEM;
1868 goto fail4; 1850 goto fail4;
1869 } 1851 }
1870 1852
@@ -2240,13 +2222,10 @@ err:
2240 2222
2241int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) 2223int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2242{ 2224{
2243 int err = 0;
2244 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device); 2225 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2245 struct c4iw_ep *ep; 2226 struct c4iw_ep *ep;
2246 struct rtable *rt; 2227 struct rtable *rt;
2247 struct net_device *pdev; 2228 int err = 0;
2248 struct neighbour *neigh;
2249 int step;
2250 2229
2251 if ((conn_param->ord > c4iw_max_read_depth) || 2230 if ((conn_param->ord > c4iw_max_read_depth) ||
2252 (conn_param->ird > c4iw_max_read_depth)) { 2231 (conn_param->ird > c4iw_max_read_depth)) {
@@ -2307,49 +2286,10 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2307 } 2286 }
2308 ep->dst = &rt->dst; 2287 ep->dst = &rt->dst;
2309 2288
2310 rcu_read_lock(); 2289 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2311 neigh = dst_get_neighbour_noref(ep->dst); 2290 ep->dst, ep->com.dev, true);
2312 2291 if (err) {
2313 /* get a l2t entry */
2314 if (neigh->dev->flags & IFF_LOOPBACK) {
2315 PDBG("%s LOOPBACK\n", __func__);
2316 pdev = ip_dev_find(&init_net,
2317 cm_id->remote_addr.sin_addr.s_addr);
2318 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
2319 neigh, pdev, 0);
2320 ep->mtu = pdev->mtu;
2321 ep->tx_chan = cxgb4_port_chan(pdev);
2322 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
2323 step = ep->com.dev->rdev.lldi.ntxq /
2324 ep->com.dev->rdev.lldi.nchan;
2325 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2326 step = ep->com.dev->rdev.lldi.nrxq /
2327 ep->com.dev->rdev.lldi.nchan;
2328 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2329 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
2330 cxgb4_port_idx(pdev) * step];
2331 dev_put(pdev);
2332 } else {
2333 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
2334 neigh, neigh->dev, 0);
2335 ep->mtu = dst_mtu(ep->dst);
2336 ep->tx_chan = cxgb4_port_chan(neigh->dev);
2337 ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
2338 step = ep->com.dev->rdev.lldi.ntxq /
2339 ep->com.dev->rdev.lldi.nchan;
2340 ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
2341 ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
2342 step = ep->com.dev->rdev.lldi.nrxq /
2343 ep->com.dev->rdev.lldi.nchan;
2344 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
2345 cxgb4_port_idx(neigh->dev) * step];
2346 ep->retry_with_mpa_v1 = 0;
2347 ep->tried_with_mpa_v1 = 0;
2348 }
2349 rcu_read_unlock();
2350 if (!ep->l2t) {
2351 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__); 2292 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2352 err = -ENOMEM;
2353 goto fail4; 2293 goto fail4;
2354 } 2294 }
2355 2295