aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband')
-rw-r--r--drivers/infiniband/core/agent.c29
-rw-r--r--drivers/infiniband/core/cma.c313
-rw-r--r--drivers/infiniband/core/iwcm.c4
-rw-r--r--drivers/infiniband/core/mad.c27
-rw-r--r--drivers/infiniband/core/multicast.c23
-rw-r--r--drivers/infiniband/core/sa_query.c30
-rw-r--r--drivers/infiniband/core/sysfs.c15
-rw-r--r--drivers/infiniband/core/ucma.c92
-rw-r--r--drivers/infiniband/core/ud_header.c140
-rw-r--r--drivers/infiniband/core/user_mad.c2
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c2
-rw-r--r--drivers/infiniband/core/verbs.c16
-rw-r--r--drivers/infiniband/hw/amso1100/Kbuild4
-rw-r--r--drivers/infiniband/hw/amso1100/c2_intr.c4
-rw-r--r--drivers/infiniband/hw/cxgb3/Makefile6
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_hal.c1
-rw-r--r--drivers/infiniband/hw/cxgb3/cxio_wr.h16
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_cm.c4
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_ev.c17
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.c24
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_qp.c25
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_user.h8
-rw-r--r--drivers/infiniband/hw/cxgb4/Makefile2
-rw-r--r--drivers/infiniband/hw/ehca/ehca_mrmw.c6
-rw-r--r--drivers/infiniband/hw/ipath/Makefile2
-rw-r--r--drivers/infiniband/hw/mlx4/ah.c163
-rw-r--r--drivers/infiniband/hw/mlx4/mad.c32
-rw-r--r--drivers/infiniband/hw/mlx4/main.c553
-rw-r--r--drivers/infiniband/hw/mlx4/mlx4_ib.h32
-rw-r--r--drivers/infiniband/hw/mlx4/mr.c2
-rw-r--r--drivers/infiniband/hw/mlx4/qp.c195
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c2
-rw-r--r--drivers/infiniband/hw/nes/nes_cm.c3
-rw-r--r--drivers/infiniband/hw/nes/nes_nic.c1
-rw-r--r--drivers/infiniband/hw/nes/nes_verbs.c16
-rw-r--r--drivers/infiniband/hw/qib/qib.h2
-rw-r--r--drivers/infiniband/hw/qib/qib_file_ops.c4
-rw-r--r--drivers/infiniband/hw/qib/qib_init.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_pcie.c8
-rw-r--r--drivers/infiniband/hw/qib/qib_rc.c5
-rw-r--r--drivers/infiniband/hw/qib/qib_uc.c6
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c14
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c3
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c236
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h21
45 files changed, 1770 insertions, 341 deletions
diff --git a/drivers/infiniband/core/agent.c b/drivers/infiniband/core/agent.c
index ae7c2880e624..91916a8d5de4 100644
--- a/drivers/infiniband/core/agent.c
+++ b/drivers/infiniband/core/agent.c
@@ -59,8 +59,8 @@ __ib_get_agent_port(struct ib_device *device, int port_num)
59 struct ib_agent_port_private *entry; 59 struct ib_agent_port_private *entry;
60 60
61 list_for_each_entry(entry, &ib_agent_port_list, port_list) { 61 list_for_each_entry(entry, &ib_agent_port_list, port_list) {
62 if (entry->agent[0]->device == device && 62 if (entry->agent[1]->device == device &&
63 entry->agent[0]->port_num == port_num) 63 entry->agent[1]->port_num == port_num)
64 return entry; 64 return entry;
65 } 65 }
66 return NULL; 66 return NULL;
@@ -155,14 +155,16 @@ int ib_agent_port_open(struct ib_device *device, int port_num)
155 goto error1; 155 goto error1;
156 } 156 }
157 157
158 /* Obtain send only MAD agent for SMI QP */ 158 if (rdma_port_get_link_layer(device, port_num) == IB_LINK_LAYER_INFINIBAND) {
159 port_priv->agent[0] = ib_register_mad_agent(device, port_num, 159 /* Obtain send only MAD agent for SMI QP */
160 IB_QPT_SMI, NULL, 0, 160 port_priv->agent[0] = ib_register_mad_agent(device, port_num,
161 &agent_send_handler, 161 IB_QPT_SMI, NULL, 0,
162 NULL, NULL); 162 &agent_send_handler,
163 if (IS_ERR(port_priv->agent[0])) { 163 NULL, NULL);
164 ret = PTR_ERR(port_priv->agent[0]); 164 if (IS_ERR(port_priv->agent[0])) {
165 goto error2; 165 ret = PTR_ERR(port_priv->agent[0]);
166 goto error2;
167 }
166 } 168 }
167 169
168 /* Obtain send only MAD agent for GSI QP */ 170 /* Obtain send only MAD agent for GSI QP */
@@ -182,7 +184,8 @@ int ib_agent_port_open(struct ib_device *device, int port_num)
182 return 0; 184 return 0;
183 185
184error3: 186error3:
185 ib_unregister_mad_agent(port_priv->agent[0]); 187 if (port_priv->agent[0])
188 ib_unregister_mad_agent(port_priv->agent[0]);
186error2: 189error2:
187 kfree(port_priv); 190 kfree(port_priv);
188error1: 191error1:
@@ -205,7 +208,9 @@ int ib_agent_port_close(struct ib_device *device, int port_num)
205 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags); 208 spin_unlock_irqrestore(&ib_agent_port_list_lock, flags);
206 209
207 ib_unregister_mad_agent(port_priv->agent[1]); 210 ib_unregister_mad_agent(port_priv->agent[1]);
208 ib_unregister_mad_agent(port_priv->agent[0]); 211 if (port_priv->agent[0])
212 ib_unregister_mad_agent(port_priv->agent[0]);
213
209 kfree(port_priv); 214 kfree(port_priv);
210 return 0; 215 return 0;
211} 216}
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index b930b8110a63..6884da24fde1 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -59,6 +59,7 @@ MODULE_LICENSE("Dual BSD/GPL");
59#define CMA_CM_RESPONSE_TIMEOUT 20 59#define CMA_CM_RESPONSE_TIMEOUT 20
60#define CMA_MAX_CM_RETRIES 15 60#define CMA_MAX_CM_RETRIES 15
61#define CMA_CM_MRA_SETTING (IB_CM_MRA_FLAG_DELAY | 24) 61#define CMA_CM_MRA_SETTING (IB_CM_MRA_FLAG_DELAY | 24)
62#define CMA_IBOE_PACKET_LIFETIME 18
62 63
63static void cma_add_one(struct ib_device *device); 64static void cma_add_one(struct ib_device *device);
64static void cma_remove_one(struct ib_device *device); 65static void cma_remove_one(struct ib_device *device);
@@ -157,6 +158,7 @@ struct cma_multicast {
157 struct list_head list; 158 struct list_head list;
158 void *context; 159 void *context;
159 struct sockaddr_storage addr; 160 struct sockaddr_storage addr;
161 struct kref mcref;
160}; 162};
161 163
162struct cma_work { 164struct cma_work {
@@ -173,6 +175,12 @@ struct cma_ndev_work {
173 struct rdma_cm_event event; 175 struct rdma_cm_event event;
174}; 176};
175 177
178struct iboe_mcast_work {
179 struct work_struct work;
180 struct rdma_id_private *id;
181 struct cma_multicast *mc;
182};
183
176union cma_ip_addr { 184union cma_ip_addr {
177 struct in6_addr ip6; 185 struct in6_addr ip6;
178 struct { 186 struct {
@@ -281,6 +289,8 @@ static void cma_attach_to_dev(struct rdma_id_private *id_priv,
281 atomic_inc(&cma_dev->refcount); 289 atomic_inc(&cma_dev->refcount);
282 id_priv->cma_dev = cma_dev; 290 id_priv->cma_dev = cma_dev;
283 id_priv->id.device = cma_dev->device; 291 id_priv->id.device = cma_dev->device;
292 id_priv->id.route.addr.dev_addr.transport =
293 rdma_node_get_transport(cma_dev->device->node_type);
284 list_add_tail(&id_priv->list, &cma_dev->id_list); 294 list_add_tail(&id_priv->list, &cma_dev->id_list);
285} 295}
286 296
@@ -290,6 +300,14 @@ static inline void cma_deref_dev(struct cma_device *cma_dev)
290 complete(&cma_dev->comp); 300 complete(&cma_dev->comp);
291} 301}
292 302
303static inline void release_mc(struct kref *kref)
304{
305 struct cma_multicast *mc = container_of(kref, struct cma_multicast, mcref);
306
307 kfree(mc->multicast.ib);
308 kfree(mc);
309}
310
293static void cma_detach_from_dev(struct rdma_id_private *id_priv) 311static void cma_detach_from_dev(struct rdma_id_private *id_priv)
294{ 312{
295 list_del(&id_priv->list); 313 list_del(&id_priv->list);
@@ -323,22 +341,63 @@ static int cma_set_qkey(struct rdma_id_private *id_priv)
323 return ret; 341 return ret;
324} 342}
325 343
344static int find_gid_port(struct ib_device *device, union ib_gid *gid, u8 port_num)
345{
346 int i;
347 int err;
348 struct ib_port_attr props;
349 union ib_gid tmp;
350
351 err = ib_query_port(device, port_num, &props);
352 if (err)
353 return 1;
354
355 for (i = 0; i < props.gid_tbl_len; ++i) {
356 err = ib_query_gid(device, port_num, i, &tmp);
357 if (err)
358 return 1;
359 if (!memcmp(&tmp, gid, sizeof tmp))
360 return 0;
361 }
362
363 return -EAGAIN;
364}
365
326static int cma_acquire_dev(struct rdma_id_private *id_priv) 366static int cma_acquire_dev(struct rdma_id_private *id_priv)
327{ 367{
328 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; 368 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
329 struct cma_device *cma_dev; 369 struct cma_device *cma_dev;
330 union ib_gid gid; 370 union ib_gid gid, iboe_gid;
331 int ret = -ENODEV; 371 int ret = -ENODEV;
372 u8 port;
373 enum rdma_link_layer dev_ll = dev_addr->dev_type == ARPHRD_INFINIBAND ?
374 IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
332 375
333 rdma_addr_get_sgid(dev_addr, &gid); 376 iboe_addr_get_sgid(dev_addr, &iboe_gid);
377 memcpy(&gid, dev_addr->src_dev_addr +
378 rdma_addr_gid_offset(dev_addr), sizeof gid);
334 list_for_each_entry(cma_dev, &dev_list, list) { 379 list_for_each_entry(cma_dev, &dev_list, list) {
335 ret = ib_find_cached_gid(cma_dev->device, &gid, 380 for (port = 1; port <= cma_dev->device->phys_port_cnt; ++port) {
336 &id_priv->id.port_num, NULL); 381 if (rdma_port_get_link_layer(cma_dev->device, port) == dev_ll) {
337 if (!ret) { 382 if (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB &&
338 cma_attach_to_dev(id_priv, cma_dev); 383 rdma_port_get_link_layer(cma_dev->device, port) == IB_LINK_LAYER_ETHERNET)
339 break; 384 ret = find_gid_port(cma_dev->device, &iboe_gid, port);
385 else
386 ret = find_gid_port(cma_dev->device, &gid, port);
387
388 if (!ret) {
389 id_priv->id.port_num = port;
390 goto out;
391 } else if (ret == 1)
392 break;
393 }
340 } 394 }
341 } 395 }
396
397out:
398 if (!ret)
399 cma_attach_to_dev(id_priv, cma_dev);
400
342 return ret; 401 return ret;
343} 402}
344 403
@@ -556,10 +615,16 @@ static int cma_ib_init_qp_attr(struct rdma_id_private *id_priv,
556{ 615{
557 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr; 616 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
558 int ret; 617 int ret;
618 u16 pkey;
619
620 if (rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num) ==
621 IB_LINK_LAYER_INFINIBAND)
622 pkey = ib_addr_get_pkey(dev_addr);
623 else
624 pkey = 0xffff;
559 625
560 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num, 626 ret = ib_find_cached_pkey(id_priv->id.device, id_priv->id.port_num,
561 ib_addr_get_pkey(dev_addr), 627 pkey, &qp_attr->pkey_index);
562 &qp_attr->pkey_index);
563 if (ret) 628 if (ret)
564 return ret; 629 return ret;
565 630
@@ -737,8 +802,8 @@ static inline int cma_user_data_offset(enum rdma_port_space ps)
737 802
738static void cma_cancel_route(struct rdma_id_private *id_priv) 803static void cma_cancel_route(struct rdma_id_private *id_priv)
739{ 804{
740 switch (rdma_node_get_transport(id_priv->id.device->node_type)) { 805 switch (rdma_port_get_link_layer(id_priv->id.device, id_priv->id.port_num)) {
741 case RDMA_TRANSPORT_IB: 806 case IB_LINK_LAYER_INFINIBAND:
742 if (id_priv->query) 807 if (id_priv->query)
743 ib_sa_cancel_query(id_priv->query_id, id_priv->query); 808 ib_sa_cancel_query(id_priv->query_id, id_priv->query);
744 break; 809 break;
@@ -816,8 +881,17 @@ static void cma_leave_mc_groups(struct rdma_id_private *id_priv)
816 mc = container_of(id_priv->mc_list.next, 881 mc = container_of(id_priv->mc_list.next,
817 struct cma_multicast, list); 882 struct cma_multicast, list);
818 list_del(&mc->list); 883 list_del(&mc->list);
819 ib_sa_free_multicast(mc->multicast.ib); 884 switch (rdma_port_get_link_layer(id_priv->cma_dev->device, id_priv->id.port_num)) {
820 kfree(mc); 885 case IB_LINK_LAYER_INFINIBAND:
886 ib_sa_free_multicast(mc->multicast.ib);
887 kfree(mc);
888 break;
889 case IB_LINK_LAYER_ETHERNET:
890 kref_put(&mc->mcref, release_mc);
891 break;
892 default:
893 break;
894 }
821 } 895 }
822} 896}
823 897
@@ -833,7 +907,7 @@ void rdma_destroy_id(struct rdma_cm_id *id)
833 mutex_lock(&lock); 907 mutex_lock(&lock);
834 if (id_priv->cma_dev) { 908 if (id_priv->cma_dev) {
835 mutex_unlock(&lock); 909 mutex_unlock(&lock);
836 switch (rdma_node_get_transport(id->device->node_type)) { 910 switch (rdma_node_get_transport(id_priv->id.device->node_type)) {
837 case RDMA_TRANSPORT_IB: 911 case RDMA_TRANSPORT_IB:
838 if (id_priv->cm_id.ib && !IS_ERR(id_priv->cm_id.ib)) 912 if (id_priv->cm_id.ib && !IS_ERR(id_priv->cm_id.ib))
839 ib_destroy_cm_id(id_priv->cm_id.ib); 913 ib_destroy_cm_id(id_priv->cm_id.ib);
@@ -1708,6 +1782,81 @@ static int cma_resolve_iw_route(struct rdma_id_private *id_priv, int timeout_ms)
1708 return 0; 1782 return 0;
1709} 1783}
1710 1784
1785static int cma_resolve_iboe_route(struct rdma_id_private *id_priv)
1786{
1787 struct rdma_route *route = &id_priv->id.route;
1788 struct rdma_addr *addr = &route->addr;
1789 struct cma_work *work;
1790 int ret;
1791 struct sockaddr_in *src_addr = (struct sockaddr_in *)&route->addr.src_addr;
1792 struct sockaddr_in *dst_addr = (struct sockaddr_in *)&route->addr.dst_addr;
1793 struct net_device *ndev = NULL;
1794 u16 vid;
1795
1796 if (src_addr->sin_family != dst_addr->sin_family)
1797 return -EINVAL;
1798
1799 work = kzalloc(sizeof *work, GFP_KERNEL);
1800 if (!work)
1801 return -ENOMEM;
1802
1803 work->id = id_priv;
1804 INIT_WORK(&work->work, cma_work_handler);
1805
1806 route->path_rec = kzalloc(sizeof *route->path_rec, GFP_KERNEL);
1807 if (!route->path_rec) {
1808 ret = -ENOMEM;
1809 goto err1;
1810 }
1811
1812 route->num_paths = 1;
1813
1814 if (addr->dev_addr.bound_dev_if)
1815 ndev = dev_get_by_index(&init_net, addr->dev_addr.bound_dev_if);
1816 if (!ndev) {
1817 ret = -ENODEV;
1818 goto err2;
1819 }
1820
1821 vid = rdma_vlan_dev_vlan_id(ndev);
1822
1823 iboe_mac_vlan_to_ll(&route->path_rec->sgid, addr->dev_addr.src_dev_addr, vid);
1824 iboe_mac_vlan_to_ll(&route->path_rec->dgid, addr->dev_addr.dst_dev_addr, vid);
1825
1826 route->path_rec->hop_limit = 1;
1827 route->path_rec->reversible = 1;
1828 route->path_rec->pkey = cpu_to_be16(0xffff);
1829 route->path_rec->mtu_selector = IB_SA_EQ;
1830 route->path_rec->sl = id_priv->tos >> 5;
1831
1832 route->path_rec->mtu = iboe_get_mtu(ndev->mtu);
1833 route->path_rec->rate_selector = IB_SA_EQ;
1834 route->path_rec->rate = iboe_get_rate(ndev);
1835 dev_put(ndev);
1836 route->path_rec->packet_life_time_selector = IB_SA_EQ;
1837 route->path_rec->packet_life_time = CMA_IBOE_PACKET_LIFETIME;
1838 if (!route->path_rec->mtu) {
1839 ret = -EINVAL;
1840 goto err2;
1841 }
1842
1843 work->old_state = CMA_ROUTE_QUERY;
1844 work->new_state = CMA_ROUTE_RESOLVED;
1845 work->event.event = RDMA_CM_EVENT_ROUTE_RESOLVED;
1846 work->event.status = 0;
1847
1848 queue_work(cma_wq, &work->work);
1849
1850 return 0;
1851
1852err2:
1853 kfree(route->path_rec);
1854 route->path_rec = NULL;
1855err1:
1856 kfree(work);
1857 return ret;
1858}
1859
1711int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms) 1860int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms)
1712{ 1861{
1713 struct rdma_id_private *id_priv; 1862 struct rdma_id_private *id_priv;
@@ -1720,7 +1869,16 @@ int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms)
1720 atomic_inc(&id_priv->refcount); 1869 atomic_inc(&id_priv->refcount);
1721 switch (rdma_node_get_transport(id->device->node_type)) { 1870 switch (rdma_node_get_transport(id->device->node_type)) {
1722 case RDMA_TRANSPORT_IB: 1871 case RDMA_TRANSPORT_IB:
1723 ret = cma_resolve_ib_route(id_priv, timeout_ms); 1872 switch (rdma_port_get_link_layer(id->device, id->port_num)) {
1873 case IB_LINK_LAYER_INFINIBAND:
1874 ret = cma_resolve_ib_route(id_priv, timeout_ms);
1875 break;
1876 case IB_LINK_LAYER_ETHERNET:
1877 ret = cma_resolve_iboe_route(id_priv);
1878 break;
1879 default:
1880 ret = -ENOSYS;
1881 }
1724 break; 1882 break;
1725 case RDMA_TRANSPORT_IWARP: 1883 case RDMA_TRANSPORT_IWARP:
1726 ret = cma_resolve_iw_route(id_priv, timeout_ms); 1884 ret = cma_resolve_iw_route(id_priv, timeout_ms);
@@ -1773,7 +1931,7 @@ port_found:
1773 goto out; 1931 goto out;
1774 1932
1775 id_priv->id.route.addr.dev_addr.dev_type = 1933 id_priv->id.route.addr.dev_addr.dev_type =
1776 (rdma_node_get_transport(cma_dev->device->node_type) == RDMA_TRANSPORT_IB) ? 1934 (rdma_port_get_link_layer(cma_dev->device, p) == IB_LINK_LAYER_INFINIBAND) ?
1777 ARPHRD_INFINIBAND : ARPHRD_ETHER; 1935 ARPHRD_INFINIBAND : ARPHRD_ETHER;
1778 1936
1779 rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid); 1937 rdma_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid);
@@ -2758,6 +2916,102 @@ static int cma_join_ib_multicast(struct rdma_id_private *id_priv,
2758 return 0; 2916 return 0;
2759} 2917}
2760 2918
2919static void iboe_mcast_work_handler(struct work_struct *work)
2920{
2921 struct iboe_mcast_work *mw = container_of(work, struct iboe_mcast_work, work);
2922 struct cma_multicast *mc = mw->mc;
2923 struct ib_sa_multicast *m = mc->multicast.ib;
2924
2925 mc->multicast.ib->context = mc;
2926 cma_ib_mc_handler(0, m);
2927 kref_put(&mc->mcref, release_mc);
2928 kfree(mw);
2929}
2930
2931static void cma_iboe_set_mgid(struct sockaddr *addr, union ib_gid *mgid)
2932{
2933 struct sockaddr_in *sin = (struct sockaddr_in *)addr;
2934 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)addr;
2935
2936 if (cma_any_addr(addr)) {
2937 memset(mgid, 0, sizeof *mgid);
2938 } else if (addr->sa_family == AF_INET6) {
2939 memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
2940 } else {
2941 mgid->raw[0] = 0xff;
2942 mgid->raw[1] = 0x0e;
2943 mgid->raw[2] = 0;
2944 mgid->raw[3] = 0;
2945 mgid->raw[4] = 0;
2946 mgid->raw[5] = 0;
2947 mgid->raw[6] = 0;
2948 mgid->raw[7] = 0;
2949 mgid->raw[8] = 0;
2950 mgid->raw[9] = 0;
2951 mgid->raw[10] = 0xff;
2952 mgid->raw[11] = 0xff;
2953 *(__be32 *)(&mgid->raw[12]) = sin->sin_addr.s_addr;
2954 }
2955}
2956
2957static int cma_iboe_join_multicast(struct rdma_id_private *id_priv,
2958 struct cma_multicast *mc)
2959{
2960 struct iboe_mcast_work *work;
2961 struct rdma_dev_addr *dev_addr = &id_priv->id.route.addr.dev_addr;
2962 int err;
2963 struct sockaddr *addr = (struct sockaddr *)&mc->addr;
2964 struct net_device *ndev = NULL;
2965
2966 if (cma_zero_addr((struct sockaddr *)&mc->addr))
2967 return -EINVAL;
2968
2969 work = kzalloc(sizeof *work, GFP_KERNEL);
2970 if (!work)
2971 return -ENOMEM;
2972
2973 mc->multicast.ib = kzalloc(sizeof(struct ib_sa_multicast), GFP_KERNEL);
2974 if (!mc->multicast.ib) {
2975 err = -ENOMEM;
2976 goto out1;
2977 }
2978
2979 cma_iboe_set_mgid(addr, &mc->multicast.ib->rec.mgid);
2980
2981 mc->multicast.ib->rec.pkey = cpu_to_be16(0xffff);
2982 if (id_priv->id.ps == RDMA_PS_UDP)
2983 mc->multicast.ib->rec.qkey = cpu_to_be32(RDMA_UDP_QKEY);
2984
2985 if (dev_addr->bound_dev_if)
2986 ndev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
2987 if (!ndev) {
2988 err = -ENODEV;
2989 goto out2;
2990 }
2991 mc->multicast.ib->rec.rate = iboe_get_rate(ndev);
2992 mc->multicast.ib->rec.hop_limit = 1;
2993 mc->multicast.ib->rec.mtu = iboe_get_mtu(ndev->mtu);
2994 dev_put(ndev);
2995 if (!mc->multicast.ib->rec.mtu) {
2996 err = -EINVAL;
2997 goto out2;
2998 }
2999 iboe_addr_get_sgid(dev_addr, &mc->multicast.ib->rec.port_gid);
3000 work->id = id_priv;
3001 work->mc = mc;
3002 INIT_WORK(&work->work, iboe_mcast_work_handler);
3003 kref_get(&mc->mcref);
3004 queue_work(cma_wq, &work->work);
3005
3006 return 0;
3007
3008out2:
3009 kfree(mc->multicast.ib);
3010out1:
3011 kfree(work);
3012 return err;
3013}
3014
2761int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, 3015int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
2762 void *context) 3016 void *context)
2763{ 3017{
@@ -2784,7 +3038,17 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
2784 3038
2785 switch (rdma_node_get_transport(id->device->node_type)) { 3039 switch (rdma_node_get_transport(id->device->node_type)) {
2786 case RDMA_TRANSPORT_IB: 3040 case RDMA_TRANSPORT_IB:
2787 ret = cma_join_ib_multicast(id_priv, mc); 3041 switch (rdma_port_get_link_layer(id->device, id->port_num)) {
3042 case IB_LINK_LAYER_INFINIBAND:
3043 ret = cma_join_ib_multicast(id_priv, mc);
3044 break;
3045 case IB_LINK_LAYER_ETHERNET:
3046 kref_init(&mc->mcref);
3047 ret = cma_iboe_join_multicast(id_priv, mc);
3048 break;
3049 default:
3050 ret = -EINVAL;
3051 }
2788 break; 3052 break;
2789 default: 3053 default:
2790 ret = -ENOSYS; 3054 ret = -ENOSYS;
@@ -2817,8 +3081,19 @@ void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
2817 ib_detach_mcast(id->qp, 3081 ib_detach_mcast(id->qp,
2818 &mc->multicast.ib->rec.mgid, 3082 &mc->multicast.ib->rec.mgid,
2819 mc->multicast.ib->rec.mlid); 3083 mc->multicast.ib->rec.mlid);
2820 ib_sa_free_multicast(mc->multicast.ib); 3084 if (rdma_node_get_transport(id_priv->cma_dev->device->node_type) == RDMA_TRANSPORT_IB) {
2821 kfree(mc); 3085 switch (rdma_port_get_link_layer(id->device, id->port_num)) {
3086 case IB_LINK_LAYER_INFINIBAND:
3087 ib_sa_free_multicast(mc->multicast.ib);
3088 kfree(mc);
3089 break;
3090 case IB_LINK_LAYER_ETHERNET:
3091 kref_put(&mc->mcref, release_mc);
3092 break;
3093 default:
3094 break;
3095 }
3096 }
2822 return; 3097 return;
2823 } 3098 }
2824 } 3099 }
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index bfead5bc25f6..2a1e9ae134b4 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -506,6 +506,8 @@ int iw_cm_accept(struct iw_cm_id *cm_id,
506 qp = cm_id->device->iwcm->get_qp(cm_id->device, iw_param->qpn); 506 qp = cm_id->device->iwcm->get_qp(cm_id->device, iw_param->qpn);
507 if (!qp) { 507 if (!qp) {
508 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 508 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
509 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
510 wake_up_all(&cm_id_priv->connect_wait);
509 return -EINVAL; 511 return -EINVAL;
510 } 512 }
511 cm_id->device->iwcm->add_ref(qp); 513 cm_id->device->iwcm->add_ref(qp);
@@ -565,6 +567,8 @@ int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
565 qp = cm_id->device->iwcm->get_qp(cm_id->device, iw_param->qpn); 567 qp = cm_id->device->iwcm->get_qp(cm_id->device, iw_param->qpn);
566 if (!qp) { 568 if (!qp) {
567 spin_unlock_irqrestore(&cm_id_priv->lock, flags); 569 spin_unlock_irqrestore(&cm_id_priv->lock, flags);
570 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
571 wake_up_all(&cm_id_priv->connect_wait);
568 return -EINVAL; 572 return -EINVAL;
569 } 573 }
570 cm_id->device->iwcm->add_ref(qp); 574 cm_id->device->iwcm->add_ref(qp);
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index ef1304f151dc..822cfdcd9f78 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -2598,6 +2598,9 @@ static void cleanup_recv_queue(struct ib_mad_qp_info *qp_info)
2598 struct ib_mad_private *recv; 2598 struct ib_mad_private *recv;
2599 struct ib_mad_list_head *mad_list; 2599 struct ib_mad_list_head *mad_list;
2600 2600
2601 if (!qp_info->qp)
2602 return;
2603
2601 while (!list_empty(&qp_info->recv_queue.list)) { 2604 while (!list_empty(&qp_info->recv_queue.list)) {
2602 2605
2603 mad_list = list_entry(qp_info->recv_queue.list.next, 2606 mad_list = list_entry(qp_info->recv_queue.list.next,
@@ -2639,6 +2642,9 @@ static int ib_mad_port_start(struct ib_mad_port_private *port_priv)
2639 2642
2640 for (i = 0; i < IB_MAD_QPS_CORE; i++) { 2643 for (i = 0; i < IB_MAD_QPS_CORE; i++) {
2641 qp = port_priv->qp_info[i].qp; 2644 qp = port_priv->qp_info[i].qp;
2645 if (!qp)
2646 continue;
2647
2642 /* 2648 /*
2643 * PKey index for QP1 is irrelevant but 2649 * PKey index for QP1 is irrelevant but
2644 * one is needed for the Reset to Init transition 2650 * one is needed for the Reset to Init transition
@@ -2680,6 +2686,9 @@ static int ib_mad_port_start(struct ib_mad_port_private *port_priv)
2680 } 2686 }
2681 2687
2682 for (i = 0; i < IB_MAD_QPS_CORE; i++) { 2688 for (i = 0; i < IB_MAD_QPS_CORE; i++) {
2689 if (!port_priv->qp_info[i].qp)
2690 continue;
2691
2683 ret = ib_mad_post_receive_mads(&port_priv->qp_info[i], NULL); 2692 ret = ib_mad_post_receive_mads(&port_priv->qp_info[i], NULL);
2684 if (ret) { 2693 if (ret) {
2685 printk(KERN_ERR PFX "Couldn't post receive WRs\n"); 2694 printk(KERN_ERR PFX "Couldn't post receive WRs\n");
@@ -2758,6 +2767,9 @@ error:
2758 2767
2759static void destroy_mad_qp(struct ib_mad_qp_info *qp_info) 2768static void destroy_mad_qp(struct ib_mad_qp_info *qp_info)
2760{ 2769{
2770 if (!qp_info->qp)
2771 return;
2772
2761 ib_destroy_qp(qp_info->qp); 2773 ib_destroy_qp(qp_info->qp);
2762 kfree(qp_info->snoop_table); 2774 kfree(qp_info->snoop_table);
2763} 2775}
@@ -2773,6 +2785,7 @@ static int ib_mad_port_open(struct ib_device *device,
2773 struct ib_mad_port_private *port_priv; 2785 struct ib_mad_port_private *port_priv;
2774 unsigned long flags; 2786 unsigned long flags;
2775 char name[sizeof "ib_mad123"]; 2787 char name[sizeof "ib_mad123"];
2788 int has_smi;
2776 2789
2777 /* Create new device info */ 2790 /* Create new device info */
2778 port_priv = kzalloc(sizeof *port_priv, GFP_KERNEL); 2791 port_priv = kzalloc(sizeof *port_priv, GFP_KERNEL);
@@ -2788,7 +2801,11 @@ static int ib_mad_port_open(struct ib_device *device,
2788 init_mad_qp(port_priv, &port_priv->qp_info[0]); 2801 init_mad_qp(port_priv, &port_priv->qp_info[0]);
2789 init_mad_qp(port_priv, &port_priv->qp_info[1]); 2802 init_mad_qp(port_priv, &port_priv->qp_info[1]);
2790 2803
2791 cq_size = (mad_sendq_size + mad_recvq_size) * 2; 2804 cq_size = mad_sendq_size + mad_recvq_size;
2805 has_smi = rdma_port_get_link_layer(device, port_num) == IB_LINK_LAYER_INFINIBAND;
2806 if (has_smi)
2807 cq_size *= 2;
2808
2792 port_priv->cq = ib_create_cq(port_priv->device, 2809 port_priv->cq = ib_create_cq(port_priv->device,
2793 ib_mad_thread_completion_handler, 2810 ib_mad_thread_completion_handler,
2794 NULL, port_priv, cq_size, 0); 2811 NULL, port_priv, cq_size, 0);
@@ -2812,9 +2829,11 @@ static int ib_mad_port_open(struct ib_device *device,
2812 goto error5; 2829 goto error5;
2813 } 2830 }
2814 2831
2815 ret = create_mad_qp(&port_priv->qp_info[0], IB_QPT_SMI); 2832 if (has_smi) {
2816 if (ret) 2833 ret = create_mad_qp(&port_priv->qp_info[0], IB_QPT_SMI);
2817 goto error6; 2834 if (ret)
2835 goto error6;
2836 }
2818 ret = create_mad_qp(&port_priv->qp_info[1], IB_QPT_GSI); 2837 ret = create_mad_qp(&port_priv->qp_info[1], IB_QPT_GSI);
2819 if (ret) 2838 if (ret)
2820 goto error7; 2839 goto error7;
diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
index a519801dcfb7..68b4162fd9d2 100644
--- a/drivers/infiniband/core/multicast.c
+++ b/drivers/infiniband/core/multicast.c
@@ -774,6 +774,10 @@ static void mcast_event_handler(struct ib_event_handler *handler,
774 int index; 774 int index;
775 775
776 dev = container_of(handler, struct mcast_device, event_handler); 776 dev = container_of(handler, struct mcast_device, event_handler);
777 if (rdma_port_get_link_layer(dev->device, event->element.port_num) !=
778 IB_LINK_LAYER_INFINIBAND)
779 return;
780
777 index = event->element.port_num - dev->start_port; 781 index = event->element.port_num - dev->start_port;
778 782
779 switch (event->event) { 783 switch (event->event) {
@@ -796,6 +800,7 @@ static void mcast_add_one(struct ib_device *device)
796 struct mcast_device *dev; 800 struct mcast_device *dev;
797 struct mcast_port *port; 801 struct mcast_port *port;
798 int i; 802 int i;
803 int count = 0;
799 804
800 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) 805 if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB)
801 return; 806 return;
@@ -813,6 +818,9 @@ static void mcast_add_one(struct ib_device *device)
813 } 818 }
814 819
815 for (i = 0; i <= dev->end_port - dev->start_port; i++) { 820 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
821 if (rdma_port_get_link_layer(device, dev->start_port + i) !=
822 IB_LINK_LAYER_INFINIBAND)
823 continue;
816 port = &dev->port[i]; 824 port = &dev->port[i];
817 port->dev = dev; 825 port->dev = dev;
818 port->port_num = dev->start_port + i; 826 port->port_num = dev->start_port + i;
@@ -820,6 +828,12 @@ static void mcast_add_one(struct ib_device *device)
820 port->table = RB_ROOT; 828 port->table = RB_ROOT;
821 init_completion(&port->comp); 829 init_completion(&port->comp);
822 atomic_set(&port->refcount, 1); 830 atomic_set(&port->refcount, 1);
831 ++count;
832 }
833
834 if (!count) {
835 kfree(dev);
836 return;
823 } 837 }
824 838
825 dev->device = device; 839 dev->device = device;
@@ -843,9 +857,12 @@ static void mcast_remove_one(struct ib_device *device)
843 flush_workqueue(mcast_wq); 857 flush_workqueue(mcast_wq);
844 858
845 for (i = 0; i <= dev->end_port - dev->start_port; i++) { 859 for (i = 0; i <= dev->end_port - dev->start_port; i++) {
846 port = &dev->port[i]; 860 if (rdma_port_get_link_layer(device, dev->start_port + i) ==
847 deref_port(port); 861 IB_LINK_LAYER_INFINIBAND) {
848 wait_for_completion(&port->comp); 862 port = &dev->port[i];
863 deref_port(port);
864 wait_for_completion(&port->comp);
865 }
849 } 866 }
850 867
851 kfree(dev); 868 kfree(dev);
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 7e1ffd8ccd5c..91a660310b7c 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -416,6 +416,9 @@ static void ib_sa_event(struct ib_event_handler *handler, struct ib_event *event
416 struct ib_sa_port *port = 416 struct ib_sa_port *port =
417 &sa_dev->port[event->element.port_num - sa_dev->start_port]; 417 &sa_dev->port[event->element.port_num - sa_dev->start_port];
418 418
419 if (rdma_port_get_link_layer(handler->device, port->port_num) != IB_LINK_LAYER_INFINIBAND)
420 return;
421
419 spin_lock_irqsave(&port->ah_lock, flags); 422 spin_lock_irqsave(&port->ah_lock, flags);
420 if (port->sm_ah) 423 if (port->sm_ah)
421 kref_put(&port->sm_ah->ref, free_sm_ah); 424 kref_put(&port->sm_ah->ref, free_sm_ah);
@@ -493,6 +496,7 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
493{ 496{
494 int ret; 497 int ret;
495 u16 gid_index; 498 u16 gid_index;
499 int force_grh;
496 500
497 memset(ah_attr, 0, sizeof *ah_attr); 501 memset(ah_attr, 0, sizeof *ah_attr);
498 ah_attr->dlid = be16_to_cpu(rec->dlid); 502 ah_attr->dlid = be16_to_cpu(rec->dlid);
@@ -502,7 +506,9 @@ int ib_init_ah_from_path(struct ib_device *device, u8 port_num,
502 ah_attr->port_num = port_num; 506 ah_attr->port_num = port_num;
503 ah_attr->static_rate = rec->rate; 507 ah_attr->static_rate = rec->rate;
504 508
505 if (rec->hop_limit > 1) { 509 force_grh = rdma_port_get_link_layer(device, port_num) == IB_LINK_LAYER_ETHERNET;
510
511 if (rec->hop_limit > 1 || force_grh) {
506 ah_attr->ah_flags = IB_AH_GRH; 512 ah_attr->ah_flags = IB_AH_GRH;
507 ah_attr->grh.dgid = rec->dgid; 513 ah_attr->grh.dgid = rec->dgid;
508 514
@@ -1007,7 +1013,7 @@ static void ib_sa_add_one(struct ib_device *device)
1007 e = device->phys_port_cnt; 1013 e = device->phys_port_cnt;
1008 } 1014 }
1009 1015
1010 sa_dev = kmalloc(sizeof *sa_dev + 1016 sa_dev = kzalloc(sizeof *sa_dev +
1011 (e - s + 1) * sizeof (struct ib_sa_port), 1017 (e - s + 1) * sizeof (struct ib_sa_port),
1012 GFP_KERNEL); 1018 GFP_KERNEL);
1013 if (!sa_dev) 1019 if (!sa_dev)
@@ -1017,9 +1023,12 @@ static void ib_sa_add_one(struct ib_device *device)
1017 sa_dev->end_port = e; 1023 sa_dev->end_port = e;
1018 1024
1019 for (i = 0; i <= e - s; ++i) { 1025 for (i = 0; i <= e - s; ++i) {
1026 spin_lock_init(&sa_dev->port[i].ah_lock);
1027 if (rdma_port_get_link_layer(device, i + 1) != IB_LINK_LAYER_INFINIBAND)
1028 continue;
1029
1020 sa_dev->port[i].sm_ah = NULL; 1030 sa_dev->port[i].sm_ah = NULL;
1021 sa_dev->port[i].port_num = i + s; 1031 sa_dev->port[i].port_num = i + s;
1022 spin_lock_init(&sa_dev->port[i].ah_lock);
1023 1032
1024 sa_dev->port[i].agent = 1033 sa_dev->port[i].agent =
1025 ib_register_mad_agent(device, i + s, IB_QPT_GSI, 1034 ib_register_mad_agent(device, i + s, IB_QPT_GSI,
@@ -1045,13 +1054,15 @@ static void ib_sa_add_one(struct ib_device *device)
1045 goto err; 1054 goto err;
1046 1055
1047 for (i = 0; i <= e - s; ++i) 1056 for (i = 0; i <= e - s; ++i)
1048 update_sm_ah(&sa_dev->port[i].update_task); 1057 if (rdma_port_get_link_layer(device, i + 1) == IB_LINK_LAYER_INFINIBAND)
1058 update_sm_ah(&sa_dev->port[i].update_task);
1049 1059
1050 return; 1060 return;
1051 1061
1052err: 1062err:
1053 while (--i >= 0) 1063 while (--i >= 0)
1054 ib_unregister_mad_agent(sa_dev->port[i].agent); 1064 if (rdma_port_get_link_layer(device, i + 1) == IB_LINK_LAYER_INFINIBAND)
1065 ib_unregister_mad_agent(sa_dev->port[i].agent);
1055 1066
1056 kfree(sa_dev); 1067 kfree(sa_dev);
1057 1068
@@ -1071,9 +1082,12 @@ static void ib_sa_remove_one(struct ib_device *device)
1071 flush_scheduled_work(); 1082 flush_scheduled_work();
1072 1083
1073 for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) { 1084 for (i = 0; i <= sa_dev->end_port - sa_dev->start_port; ++i) {
1074 ib_unregister_mad_agent(sa_dev->port[i].agent); 1085 if (rdma_port_get_link_layer(device, i + 1) == IB_LINK_LAYER_INFINIBAND) {
1075 if (sa_dev->port[i].sm_ah) 1086 ib_unregister_mad_agent(sa_dev->port[i].agent);
1076 kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah); 1087 if (sa_dev->port[i].sm_ah)
1088 kref_put(&sa_dev->port[i].sm_ah->ref, free_sm_ah);
1089 }
1090
1077 } 1091 }
1078 1092
1079 kfree(sa_dev); 1093 kfree(sa_dev);
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 3627300e2a10..9ab5df72df7b 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -222,6 +222,19 @@ static ssize_t phys_state_show(struct ib_port *p, struct port_attribute *unused,
222 } 222 }
223} 223}
224 224
225static ssize_t link_layer_show(struct ib_port *p, struct port_attribute *unused,
226 char *buf)
227{
228 switch (rdma_port_get_link_layer(p->ibdev, p->port_num)) {
229 case IB_LINK_LAYER_INFINIBAND:
230 return sprintf(buf, "%s\n", "InfiniBand");
231 case IB_LINK_LAYER_ETHERNET:
232 return sprintf(buf, "%s\n", "Ethernet");
233 default:
234 return sprintf(buf, "%s\n", "Unknown");
235 }
236}
237
225static PORT_ATTR_RO(state); 238static PORT_ATTR_RO(state);
226static PORT_ATTR_RO(lid); 239static PORT_ATTR_RO(lid);
227static PORT_ATTR_RO(lid_mask_count); 240static PORT_ATTR_RO(lid_mask_count);
@@ -230,6 +243,7 @@ static PORT_ATTR_RO(sm_sl);
230static PORT_ATTR_RO(cap_mask); 243static PORT_ATTR_RO(cap_mask);
231static PORT_ATTR_RO(rate); 244static PORT_ATTR_RO(rate);
232static PORT_ATTR_RO(phys_state); 245static PORT_ATTR_RO(phys_state);
246static PORT_ATTR_RO(link_layer);
233 247
234static struct attribute *port_default_attrs[] = { 248static struct attribute *port_default_attrs[] = {
235 &port_attr_state.attr, 249 &port_attr_state.attr,
@@ -240,6 +254,7 @@ static struct attribute *port_default_attrs[] = {
240 &port_attr_cap_mask.attr, 254 &port_attr_cap_mask.attr,
241 &port_attr_rate.attr, 255 &port_attr_rate.attr,
242 &port_attr_phys_state.attr, 256 &port_attr_phys_state.attr,
257 &port_attr_link_layer.attr,
243 NULL 258 NULL
244}; 259};
245 260
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index ac7edc24165c..ca12acf38379 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -40,6 +40,7 @@
40#include <linux/in6.h> 40#include <linux/in6.h>
41#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/sysctl.h>
43 44
44#include <rdma/rdma_user_cm.h> 45#include <rdma/rdma_user_cm.h>
45#include <rdma/ib_marshall.h> 46#include <rdma/ib_marshall.h>
@@ -50,8 +51,24 @@ MODULE_AUTHOR("Sean Hefty");
50MODULE_DESCRIPTION("RDMA Userspace Connection Manager Access"); 51MODULE_DESCRIPTION("RDMA Userspace Connection Manager Access");
51MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
52 53
53enum { 54static unsigned int max_backlog = 1024;
54 UCMA_MAX_BACKLOG = 128 55
56static struct ctl_table_header *ucma_ctl_table_hdr;
57static ctl_table ucma_ctl_table[] = {
58 {
59 .procname = "max_backlog",
60 .data = &max_backlog,
61 .maxlen = sizeof max_backlog,
62 .mode = 0644,
63 .proc_handler = proc_dointvec,
64 },
65 { }
66};
67
68static struct ctl_path ucma_ctl_path[] = {
69 { .procname = "net" },
70 { .procname = "rdma_ucm" },
71 { }
55}; 72};
56 73
57struct ucma_file { 74struct ucma_file {
@@ -583,6 +600,42 @@ static void ucma_copy_ib_route(struct rdma_ucm_query_route_resp *resp,
583 } 600 }
584} 601}
585 602
603static void ucma_copy_iboe_route(struct rdma_ucm_query_route_resp *resp,
604 struct rdma_route *route)
605{
606 struct rdma_dev_addr *dev_addr;
607 struct net_device *dev;
608 u16 vid = 0;
609
610 resp->num_paths = route->num_paths;
611 switch (route->num_paths) {
612 case 0:
613 dev_addr = &route->addr.dev_addr;
614 dev = dev_get_by_index(&init_net, dev_addr->bound_dev_if);
615 if (dev) {
616 vid = rdma_vlan_dev_vlan_id(dev);
617 dev_put(dev);
618 }
619
620 iboe_mac_vlan_to_ll((union ib_gid *) &resp->ib_route[0].dgid,
621 dev_addr->dst_dev_addr, vid);
622 iboe_addr_get_sgid(dev_addr,
623 (union ib_gid *) &resp->ib_route[0].sgid);
624 resp->ib_route[0].pkey = cpu_to_be16(0xffff);
625 break;
626 case 2:
627 ib_copy_path_rec_to_user(&resp->ib_route[1],
628 &route->path_rec[1]);
629 /* fall through */
630 case 1:
631 ib_copy_path_rec_to_user(&resp->ib_route[0],
632 &route->path_rec[0]);
633 break;
634 default:
635 break;
636 }
637}
638
586static ssize_t ucma_query_route(struct ucma_file *file, 639static ssize_t ucma_query_route(struct ucma_file *file,
587 const char __user *inbuf, 640 const char __user *inbuf,
588 int in_len, int out_len) 641 int in_len, int out_len)
@@ -617,12 +670,17 @@ static ssize_t ucma_query_route(struct ucma_file *file,
617 670
618 resp.node_guid = (__force __u64) ctx->cm_id->device->node_guid; 671 resp.node_guid = (__force __u64) ctx->cm_id->device->node_guid;
619 resp.port_num = ctx->cm_id->port_num; 672 resp.port_num = ctx->cm_id->port_num;
620 switch (rdma_node_get_transport(ctx->cm_id->device->node_type)) { 673 if (rdma_node_get_transport(ctx->cm_id->device->node_type) == RDMA_TRANSPORT_IB) {
621 case RDMA_TRANSPORT_IB: 674 switch (rdma_port_get_link_layer(ctx->cm_id->device, ctx->cm_id->port_num)) {
622 ucma_copy_ib_route(&resp, &ctx->cm_id->route); 675 case IB_LINK_LAYER_INFINIBAND:
623 break; 676 ucma_copy_ib_route(&resp, &ctx->cm_id->route);
624 default: 677 break;
625 break; 678 case IB_LINK_LAYER_ETHERNET:
679 ucma_copy_iboe_route(&resp, &ctx->cm_id->route);
680 break;
681 default:
682 break;
683 }
626 } 684 }
627 685
628out: 686out:
@@ -686,8 +744,8 @@ static ssize_t ucma_listen(struct ucma_file *file, const char __user *inbuf,
686 if (IS_ERR(ctx)) 744 if (IS_ERR(ctx))
687 return PTR_ERR(ctx); 745 return PTR_ERR(ctx);
688 746
689 ctx->backlog = cmd.backlog > 0 && cmd.backlog < UCMA_MAX_BACKLOG ? 747 ctx->backlog = cmd.backlog > 0 && cmd.backlog < max_backlog ?
690 cmd.backlog : UCMA_MAX_BACKLOG; 748 cmd.backlog : max_backlog;
691 ret = rdma_listen(ctx->cm_id, ctx->backlog); 749 ret = rdma_listen(ctx->cm_id, ctx->backlog);
692 ucma_put_ctx(ctx); 750 ucma_put_ctx(ctx);
693 return ret; 751 return ret;
@@ -1279,16 +1337,26 @@ static int __init ucma_init(void)
1279 ret = device_create_file(ucma_misc.this_device, &dev_attr_abi_version); 1337 ret = device_create_file(ucma_misc.this_device, &dev_attr_abi_version);
1280 if (ret) { 1338 if (ret) {
1281 printk(KERN_ERR "rdma_ucm: couldn't create abi_version attr\n"); 1339 printk(KERN_ERR "rdma_ucm: couldn't create abi_version attr\n");
1282 goto err; 1340 goto err1;
1341 }
1342
1343 ucma_ctl_table_hdr = register_sysctl_paths(ucma_ctl_path, ucma_ctl_table);
1344 if (!ucma_ctl_table_hdr) {
1345 printk(KERN_ERR "rdma_ucm: couldn't register sysctl paths\n");
1346 ret = -ENOMEM;
1347 goto err2;
1283 } 1348 }
1284 return 0; 1349 return 0;
1285err: 1350err2:
1351 device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
1352err1:
1286 misc_deregister(&ucma_misc); 1353 misc_deregister(&ucma_misc);
1287 return ret; 1354 return ret;
1288} 1355}
1289 1356
1290static void __exit ucma_cleanup(void) 1357static void __exit ucma_cleanup(void)
1291{ 1358{
1359 unregister_sysctl_table(ucma_ctl_table_hdr);
1292 device_remove_file(ucma_misc.this_device, &dev_attr_abi_version); 1360 device_remove_file(ucma_misc.this_device, &dev_attr_abi_version);
1293 misc_deregister(&ucma_misc); 1361 misc_deregister(&ucma_misc);
1294 idr_destroy(&ctx_idr); 1362 idr_destroy(&ctx_idr);
diff --git a/drivers/infiniband/core/ud_header.c b/drivers/infiniband/core/ud_header.c
index 650b501eb142..bb7e19280821 100644
--- a/drivers/infiniband/core/ud_header.c
+++ b/drivers/infiniband/core/ud_header.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/string.h> 35#include <linux/string.h>
36#include <linux/if_ether.h>
36 37
37#include <rdma/ib_pack.h> 38#include <rdma/ib_pack.h>
38 39
@@ -80,6 +81,40 @@ static const struct ib_field lrh_table[] = {
80 .size_bits = 16 } 81 .size_bits = 16 }
81}; 82};
82 83
84static const struct ib_field eth_table[] = {
85 { STRUCT_FIELD(eth, dmac_h),
86 .offset_words = 0,
87 .offset_bits = 0,
88 .size_bits = 32 },
89 { STRUCT_FIELD(eth, dmac_l),
90 .offset_words = 1,
91 .offset_bits = 0,
92 .size_bits = 16 },
93 { STRUCT_FIELD(eth, smac_h),
94 .offset_words = 1,
95 .offset_bits = 16,
96 .size_bits = 16 },
97 { STRUCT_FIELD(eth, smac_l),
98 .offset_words = 2,
99 .offset_bits = 0,
100 .size_bits = 32 },
101 { STRUCT_FIELD(eth, type),
102 .offset_words = 3,
103 .offset_bits = 0,
104 .size_bits = 16 }
105};
106
107static const struct ib_field vlan_table[] = {
108 { STRUCT_FIELD(vlan, tag),
109 .offset_words = 0,
110 .offset_bits = 0,
111 .size_bits = 16 },
112 { STRUCT_FIELD(vlan, type),
113 .offset_words = 0,
114 .offset_bits = 16,
115 .size_bits = 16 }
116};
117
83static const struct ib_field grh_table[] = { 118static const struct ib_field grh_table[] = {
84 { STRUCT_FIELD(grh, ip_version), 119 { STRUCT_FIELD(grh, ip_version),
85 .offset_words = 0, 120 .offset_words = 0,
@@ -180,38 +215,43 @@ static const struct ib_field deth_table[] = {
180/** 215/**
181 * ib_ud_header_init - Initialize UD header structure 216 * ib_ud_header_init - Initialize UD header structure
182 * @payload_bytes:Length of packet payload 217 * @payload_bytes:Length of packet payload
218 * @lrh_present: specify if LRH is present
219 * @eth_present: specify if Eth header is present
220 * @vlan_present: packet is tagged vlan
183 * @grh_present:GRH flag (if non-zero, GRH will be included) 221 * @grh_present:GRH flag (if non-zero, GRH will be included)
184 * @immediate_present: specify if immediate data should be used 222 * @immediate_present: specify if immediate data is present
185 * @header:Structure to initialize 223 * @header:Structure to initialize
186 *
187 * ib_ud_header_init() initializes the lrh.link_version, lrh.link_next_header,
188 * lrh.packet_length, grh.ip_version, grh.payload_length,
189 * grh.next_header, bth.opcode, bth.pad_count and
190 * bth.transport_header_version fields of a &struct ib_ud_header given
191 * the payload length and whether a GRH will be included.
192 */ 224 */
193void ib_ud_header_init(int payload_bytes, 225void ib_ud_header_init(int payload_bytes,
226 int lrh_present,
227 int eth_present,
228 int vlan_present,
194 int grh_present, 229 int grh_present,
195 int immediate_present, 230 int immediate_present,
196 struct ib_ud_header *header) 231 struct ib_ud_header *header)
197{ 232{
198 u16 packet_length;
199
200 memset(header, 0, sizeof *header); 233 memset(header, 0, sizeof *header);
201 234
202 header->lrh.link_version = 0; 235 if (lrh_present) {
203 header->lrh.link_next_header = 236 u16 packet_length;
204 grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL; 237
205 packet_length = (IB_LRH_BYTES + 238 header->lrh.link_version = 0;
206 IB_BTH_BYTES + 239 header->lrh.link_next_header =
207 IB_DETH_BYTES + 240 grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL;
208 payload_bytes + 241 packet_length = (IB_LRH_BYTES +
209 4 + /* ICRC */ 242 IB_BTH_BYTES +
210 3) / 4; /* round up */ 243 IB_DETH_BYTES +
211 244 (grh_present ? IB_GRH_BYTES : 0) +
212 header->grh_present = grh_present; 245 payload_bytes +
246 4 + /* ICRC */
247 3) / 4; /* round up */
248 header->lrh.packet_length = cpu_to_be16(packet_length);
249 }
250
251 if (vlan_present)
252 header->eth.type = cpu_to_be16(ETH_P_8021Q);
253
213 if (grh_present) { 254 if (grh_present) {
214 packet_length += IB_GRH_BYTES / 4;
215 header->grh.ip_version = 6; 255 header->grh.ip_version = 6;
216 header->grh.payload_length = 256 header->grh.payload_length =
217 cpu_to_be16((IB_BTH_BYTES + 257 cpu_to_be16((IB_BTH_BYTES +
@@ -222,19 +262,52 @@ void ib_ud_header_init(int payload_bytes,
222 header->grh.next_header = 0x1b; 262 header->grh.next_header = 0x1b;
223 } 263 }
224 264
225 header->lrh.packet_length = cpu_to_be16(packet_length);
226
227 header->immediate_present = immediate_present;
228 if (immediate_present) 265 if (immediate_present)
229 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE; 266 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
230 else 267 else
231 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY; 268 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY;
232 header->bth.pad_count = (4 - payload_bytes) & 3; 269 header->bth.pad_count = (4 - payload_bytes) & 3;
233 header->bth.transport_header_version = 0; 270 header->bth.transport_header_version = 0;
271
272 header->lrh_present = lrh_present;
273 header->eth_present = eth_present;
274 header->vlan_present = vlan_present;
275 header->grh_present = grh_present;
276 header->immediate_present = immediate_present;
234} 277}
235EXPORT_SYMBOL(ib_ud_header_init); 278EXPORT_SYMBOL(ib_ud_header_init);
236 279
237/** 280/**
281 * ib_lrh_header_pack - Pack LRH header struct into wire format
282 * @lrh:unpacked LRH header struct
283 * @buf:Buffer to pack into
284 *
285 * ib_lrh_header_pack() packs the LRH header structure @lrh into
286 * wire format in the buffer @buf.
287 */
288int ib_lrh_header_pack(struct ib_unpacked_lrh *lrh, void *buf)
289{
290 ib_pack(lrh_table, ARRAY_SIZE(lrh_table), lrh, buf);
291 return 0;
292}
293EXPORT_SYMBOL(ib_lrh_header_pack);
294
295/**
296 * ib_lrh_header_unpack - Unpack LRH structure from wire format
297 * @lrh:unpacked LRH header struct
298 * @buf:Buffer to pack into
299 *
300 * ib_lrh_header_unpack() unpacks the LRH header structure from
301 * wire format (in buf) into @lrh.
302 */
303int ib_lrh_header_unpack(void *buf, struct ib_unpacked_lrh *lrh)
304{
305 ib_unpack(lrh_table, ARRAY_SIZE(lrh_table), buf, lrh);
306 return 0;
307}
308EXPORT_SYMBOL(ib_lrh_header_unpack);
309
310/**
238 * ib_ud_header_pack - Pack UD header struct into wire format 311 * ib_ud_header_pack - Pack UD header struct into wire format
239 * @header:UD header struct 312 * @header:UD header struct
240 * @buf:Buffer to pack into 313 * @buf:Buffer to pack into
@@ -247,10 +320,21 @@ int ib_ud_header_pack(struct ib_ud_header *header,
247{ 320{
248 int len = 0; 321 int len = 0;
249 322
250 ib_pack(lrh_table, ARRAY_SIZE(lrh_table), 323 if (header->lrh_present) {
251 &header->lrh, buf); 324 ib_pack(lrh_table, ARRAY_SIZE(lrh_table),
252 len += IB_LRH_BYTES; 325 &header->lrh, buf + len);
253 326 len += IB_LRH_BYTES;
327 }
328 if (header->eth_present) {
329 ib_pack(eth_table, ARRAY_SIZE(eth_table),
330 &header->eth, buf + len);
331 len += IB_ETH_BYTES;
332 }
333 if (header->vlan_present) {
334 ib_pack(vlan_table, ARRAY_SIZE(vlan_table),
335 &header->vlan, buf + len);
336 len += IB_VLAN_BYTES;
337 }
254 if (header->grh_present) { 338 if (header->grh_present) {
255 ib_pack(grh_table, ARRAY_SIZE(grh_table), 339 ib_pack(grh_table, ARRAY_SIZE(grh_table),
256 &header->grh, buf + len); 340 &header->grh, buf + len);
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 5fa856909511..cd1996d0ad08 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -1022,7 +1022,7 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
1022 1022
1023 port->ib_dev = device; 1023 port->ib_dev = device;
1024 port->port_num = port_num; 1024 port->port_num = port_num;
1025 init_MUTEX(&port->sm_sem); 1025 sema_init(&port->sm_sem, 1);
1026 mutex_init(&port->file_mutex); 1026 mutex_init(&port->file_mutex);
1027 INIT_LIST_HEAD(&port->file_list); 1027 INIT_LIST_HEAD(&port->file_list);
1028 1028
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index 6fcfbeb24a23..b342248aec05 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -460,6 +460,8 @@ ssize_t ib_uverbs_query_port(struct ib_uverbs_file *file,
460 resp.active_width = attr.active_width; 460 resp.active_width = attr.active_width;
461 resp.active_speed = attr.active_speed; 461 resp.active_speed = attr.active_speed;
462 resp.phys_state = attr.phys_state; 462 resp.phys_state = attr.phys_state;
463 resp.link_layer = rdma_port_get_link_layer(file->device->ib_dev,
464 cmd.port_num);
463 465
464 if (copy_to_user((void __user *) (unsigned long) cmd.response, 466 if (copy_to_user((void __user *) (unsigned long) cmd.response,
465 &resp, sizeof resp)) 467 &resp, sizeof resp))
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index e0fa22238715..af7a8b08b2e9 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -94,6 +94,22 @@ rdma_node_get_transport(enum rdma_node_type node_type)
94} 94}
95EXPORT_SYMBOL(rdma_node_get_transport); 95EXPORT_SYMBOL(rdma_node_get_transport);
96 96
97enum rdma_link_layer rdma_port_get_link_layer(struct ib_device *device, u8 port_num)
98{
99 if (device->get_link_layer)
100 return device->get_link_layer(device, port_num);
101
102 switch (rdma_node_get_transport(device->node_type)) {
103 case RDMA_TRANSPORT_IB:
104 return IB_LINK_LAYER_INFINIBAND;
105 case RDMA_TRANSPORT_IWARP:
106 return IB_LINK_LAYER_ETHERNET;
107 default:
108 return IB_LINK_LAYER_UNSPECIFIED;
109 }
110}
111EXPORT_SYMBOL(rdma_port_get_link_layer);
112
97/* Protection domains */ 113/* Protection domains */
98 114
99struct ib_pd *ib_alloc_pd(struct ib_device *device) 115struct ib_pd *ib_alloc_pd(struct ib_device *device)
diff --git a/drivers/infiniband/hw/amso1100/Kbuild b/drivers/infiniband/hw/amso1100/Kbuild
index 06964c4af849..950dfabcd89d 100644
--- a/drivers/infiniband/hw/amso1100/Kbuild
+++ b/drivers/infiniband/hw/amso1100/Kbuild
@@ -1,6 +1,4 @@
1ifdef CONFIG_INFINIBAND_AMSO1100_DEBUG 1ccflags-$(CONFIG_INFINIBAND_AMSO1100_DEBUG) := -DDEBUG
2EXTRA_CFLAGS += -DDEBUG
3endif
4 2
5obj-$(CONFIG_INFINIBAND_AMSO1100) += iw_c2.o 3obj-$(CONFIG_INFINIBAND_AMSO1100) += iw_c2.o
6 4
diff --git a/drivers/infiniband/hw/amso1100/c2_intr.c b/drivers/infiniband/hw/amso1100/c2_intr.c
index 3b5095470cb3..0ebe4e806b86 100644
--- a/drivers/infiniband/hw/amso1100/c2_intr.c
+++ b/drivers/infiniband/hw/amso1100/c2_intr.c
@@ -62,8 +62,8 @@ void c2_rnic_interrupt(struct c2_dev *c2dev)
62static void handle_mq(struct c2_dev *c2dev, u32 mq_index) 62static void handle_mq(struct c2_dev *c2dev, u32 mq_index)
63{ 63{
64 if (c2dev->qptr_array[mq_index] == NULL) { 64 if (c2dev->qptr_array[mq_index] == NULL) {
65 pr_debug(KERN_INFO "handle_mq: stray activity for mq_index=%d\n", 65 pr_debug("handle_mq: stray activity for mq_index=%d\n",
66 mq_index); 66 mq_index);
67 return; 67 return;
68 } 68 }
69 69
diff --git a/drivers/infiniband/hw/cxgb3/Makefile b/drivers/infiniband/hw/cxgb3/Makefile
index 7e7b5a66f042..621619c794e5 100644
--- a/drivers/infiniband/hw/cxgb3/Makefile
+++ b/drivers/infiniband/hw/cxgb3/Makefile
@@ -1,10 +1,8 @@
1EXTRA_CFLAGS += -Idrivers/net/cxgb3 1ccflags-y := -Idrivers/net/cxgb3
2 2
3obj-$(CONFIG_INFINIBAND_CXGB3) += iw_cxgb3.o 3obj-$(CONFIG_INFINIBAND_CXGB3) += iw_cxgb3.o
4 4
5iw_cxgb3-y := iwch_cm.o iwch_ev.o iwch_cq.o iwch_qp.o iwch_mem.o \ 5iw_cxgb3-y := iwch_cm.o iwch_ev.o iwch_cq.o iwch_qp.o iwch_mem.o \
6 iwch_provider.o iwch.o cxio_hal.o cxio_resource.o 6 iwch_provider.o iwch.o cxio_hal.o cxio_resource.o
7 7
8ifdef CONFIG_INFINIBAND_CXGB3_DEBUG 8ccflags-$(CONFIG_INFINIBAND_CXGB3_DEBUG) += -DDEBUG
9EXTRA_CFLAGS += -DDEBUG
10endif
diff --git a/drivers/infiniband/hw/cxgb3/cxio_hal.c b/drivers/infiniband/hw/cxgb3/cxio_hal.c
index 005b7b52bc1e..09dda0b8740e 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_hal.c
+++ b/drivers/infiniband/hw/cxgb3/cxio_hal.c
@@ -160,6 +160,7 @@ int cxio_create_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq, int kernel)
160 struct rdma_cq_setup setup; 160 struct rdma_cq_setup setup;
161 int size = (1UL << (cq->size_log2)) * sizeof(struct t3_cqe); 161 int size = (1UL << (cq->size_log2)) * sizeof(struct t3_cqe);
162 162
163 size += 1; /* one extra page for storing cq-in-err state */
163 cq->cqid = cxio_hal_get_cqid(rdev_p->rscp); 164 cq->cqid = cxio_hal_get_cqid(rdev_p->rscp);
164 if (!cq->cqid) 165 if (!cq->cqid)
165 return -ENOMEM; 166 return -ENOMEM;
diff --git a/drivers/infiniband/hw/cxgb3/cxio_wr.h b/drivers/infiniband/hw/cxgb3/cxio_wr.h
index e5ddb63e7d23..4bb997aa39d0 100644
--- a/drivers/infiniband/hw/cxgb3/cxio_wr.h
+++ b/drivers/infiniband/hw/cxgb3/cxio_wr.h
@@ -728,6 +728,22 @@ struct t3_cq {
728#define CQ_VLD_ENTRY(ptr,size_log2,cqe) (Q_GENBIT(ptr,size_log2) == \ 728#define CQ_VLD_ENTRY(ptr,size_log2,cqe) (Q_GENBIT(ptr,size_log2) == \
729 CQE_GENBIT(*cqe)) 729 CQE_GENBIT(*cqe))
730 730
731struct t3_cq_status_page {
732 u32 cq_err;
733};
734
735static inline int cxio_cq_in_error(struct t3_cq *cq)
736{
737 return ((struct t3_cq_status_page *)
738 &cq->queue[1 << cq->size_log2])->cq_err;
739}
740
741static inline void cxio_set_cq_in_error(struct t3_cq *cq)
742{
743 ((struct t3_cq_status_page *)
744 &cq->queue[1 << cq->size_log2])->cq_err = 1;
745}
746
731static inline void cxio_set_wq_in_error(struct t3_wq *wq) 747static inline void cxio_set_wq_in_error(struct t3_wq *wq)
732{ 748{
733 wq->queue->wq_in_err.err |= 1; 749 wq->queue->wq_in_err.err |= 1;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_cm.c b/drivers/infiniband/hw/cxgb3/iwch_cm.c
index 13c88871dc3b..d02dcc6e5963 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_cm.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_cm.c
@@ -1093,8 +1093,8 @@ static int tx_ack(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1093 PDBG("%s ep %p credits %u\n", __func__, ep, credits); 1093 PDBG("%s ep %p credits %u\n", __func__, ep, credits);
1094 1094
1095 if (credits == 0) { 1095 if (credits == 0) {
1096 PDBG(KERN_ERR "%s 0 credit ack ep %p state %u\n", 1096 PDBG("%s 0 credit ack ep %p state %u\n",
1097 __func__, ep, state_read(&ep->com)); 1097 __func__, ep, state_read(&ep->com));
1098 return CPL_RET_BUF_DONE; 1098 return CPL_RET_BUF_DONE;
1099 } 1099 }
1100 1100
diff --git a/drivers/infiniband/hw/cxgb3/iwch_ev.c b/drivers/infiniband/hw/cxgb3/iwch_ev.c
index 6afc89e7572c..71e0d845da3d 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_ev.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_ev.c
@@ -76,6 +76,14 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
76 atomic_inc(&qhp->refcnt); 76 atomic_inc(&qhp->refcnt);
77 spin_unlock(&rnicp->lock); 77 spin_unlock(&rnicp->lock);
78 78
79 if (qhp->attr.state == IWCH_QP_STATE_RTS) {
80 attrs.next_state = IWCH_QP_STATE_TERMINATE;
81 iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE,
82 &attrs, 1);
83 if (send_term)
84 iwch_post_terminate(qhp, rsp_msg);
85 }
86
79 event.event = ib_event; 87 event.event = ib_event;
80 event.device = chp->ibcq.device; 88 event.device = chp->ibcq.device;
81 if (ib_event == IB_EVENT_CQ_ERR) 89 if (ib_event == IB_EVENT_CQ_ERR)
@@ -86,13 +94,7 @@ static void post_qp_event(struct iwch_dev *rnicp, struct iwch_cq *chp,
86 if (qhp->ibqp.event_handler) 94 if (qhp->ibqp.event_handler)
87 (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context); 95 (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
88 96
89 if (qhp->attr.state == IWCH_QP_STATE_RTS) { 97 (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
90 attrs.next_state = IWCH_QP_STATE_TERMINATE;
91 iwch_modify_qp(qhp->rhp, qhp, IWCH_QP_ATTR_NEXT_STATE,
92 &attrs, 1);
93 if (send_term)
94 iwch_post_terminate(qhp, rsp_msg);
95 }
96 98
97 if (atomic_dec_and_test(&qhp->refcnt)) 99 if (atomic_dec_and_test(&qhp->refcnt))
98 wake_up(&qhp->wait); 100 wake_up(&qhp->wait);
@@ -179,7 +181,6 @@ void iwch_ev_dispatch(struct cxio_rdev *rdev_p, struct sk_buff *skb)
179 case TPT_ERR_BOUND: 181 case TPT_ERR_BOUND:
180 case TPT_ERR_INVALIDATE_SHARED_MR: 182 case TPT_ERR_INVALIDATE_SHARED_MR:
181 case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND: 183 case TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND:
182 (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
183 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1); 184 post_qp_event(rnicp, chp, rsp_msg, IB_EVENT_QP_ACCESS_ERR, 1);
184 break; 185 break;
185 186
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index fca0b4b747e4..2e2741307af4 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -154,6 +154,8 @@ static struct ib_cq *iwch_create_cq(struct ib_device *ibdev, int entries, int ve
154 struct iwch_create_cq_resp uresp; 154 struct iwch_create_cq_resp uresp;
155 struct iwch_create_cq_req ureq; 155 struct iwch_create_cq_req ureq;
156 struct iwch_ucontext *ucontext = NULL; 156 struct iwch_ucontext *ucontext = NULL;
157 static int warned;
158 size_t resplen;
157 159
158 PDBG("%s ib_dev %p entries %d\n", __func__, ibdev, entries); 160 PDBG("%s ib_dev %p entries %d\n", __func__, ibdev, entries);
159 rhp = to_iwch_dev(ibdev); 161 rhp = to_iwch_dev(ibdev);
@@ -217,15 +219,26 @@ static struct ib_cq *iwch_create_cq(struct ib_device *ibdev, int entries, int ve
217 uresp.key = ucontext->key; 219 uresp.key = ucontext->key;
218 ucontext->key += PAGE_SIZE; 220 ucontext->key += PAGE_SIZE;
219 spin_unlock(&ucontext->mmap_lock); 221 spin_unlock(&ucontext->mmap_lock);
220 if (ib_copy_to_udata(udata, &uresp, sizeof (uresp))) { 222 mm->key = uresp.key;
223 mm->addr = virt_to_phys(chp->cq.queue);
224 if (udata->outlen < sizeof uresp) {
225 if (!warned++)
226 printk(KERN_WARNING MOD "Warning - "
227 "downlevel libcxgb3 (non-fatal).\n");
228 mm->len = PAGE_ALIGN((1UL << uresp.size_log2) *
229 sizeof(struct t3_cqe));
230 resplen = sizeof(struct iwch_create_cq_resp_v0);
231 } else {
232 mm->len = PAGE_ALIGN(((1UL << uresp.size_log2) + 1) *
233 sizeof(struct t3_cqe));
234 uresp.memsize = mm->len;
235 resplen = sizeof uresp;
236 }
237 if (ib_copy_to_udata(udata, &uresp, resplen)) {
221 kfree(mm); 238 kfree(mm);
222 iwch_destroy_cq(&chp->ibcq); 239 iwch_destroy_cq(&chp->ibcq);
223 return ERR_PTR(-EFAULT); 240 return ERR_PTR(-EFAULT);
224 } 241 }
225 mm->key = uresp.key;
226 mm->addr = virt_to_phys(chp->cq.queue);
227 mm->len = PAGE_ALIGN((1UL << uresp.size_log2) *
228 sizeof (struct t3_cqe));
229 insert_mmap(ucontext, mm); 242 insert_mmap(ucontext, mm);
230 } 243 }
231 PDBG("created cqid 0x%0x chp %p size 0x%0x, dma_addr 0x%0llx\n", 244 PDBG("created cqid 0x%0x chp %p size 0x%0x, dma_addr 0x%0llx\n",
@@ -1414,6 +1427,7 @@ int iwch_register_device(struct iwch_dev *dev)
1414 dev->ibdev.post_send = iwch_post_send; 1427 dev->ibdev.post_send = iwch_post_send;
1415 dev->ibdev.post_recv = iwch_post_receive; 1428 dev->ibdev.post_recv = iwch_post_receive;
1416 dev->ibdev.get_protocol_stats = iwch_get_mib; 1429 dev->ibdev.get_protocol_stats = iwch_get_mib;
1430 dev->ibdev.uverbs_abi_ver = IWCH_UVERBS_ABI_VERSION;
1417 1431
1418 dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL); 1432 dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
1419 if (!dev->ibdev.iwcm) 1433 if (!dev->ibdev.iwcm)
diff --git a/drivers/infiniband/hw/cxgb3/iwch_qp.c b/drivers/infiniband/hw/cxgb3/iwch_qp.c
index c64d27bf2c15..0993137181d7 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_qp.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_qp.c
@@ -802,14 +802,12 @@ int iwch_post_terminate(struct iwch_qp *qhp, struct respQ_msg_t *rsp_msg)
802/* 802/*
803 * Assumes qhp lock is held. 803 * Assumes qhp lock is held.
804 */ 804 */
805static void __flush_qp(struct iwch_qp *qhp, unsigned long *flag) 805static void __flush_qp(struct iwch_qp *qhp, struct iwch_cq *rchp,
806 struct iwch_cq *schp, unsigned long *flag)
806{ 807{
807 struct iwch_cq *rchp, *schp;
808 int count; 808 int count;
809 int flushed; 809 int flushed;
810 810
811 rchp = get_chp(qhp->rhp, qhp->attr.rcq);
812 schp = get_chp(qhp->rhp, qhp->attr.scq);
813 811
814 PDBG("%s qhp %p rchp %p schp %p\n", __func__, qhp, rchp, schp); 812 PDBG("%s qhp %p rchp %p schp %p\n", __func__, qhp, rchp, schp);
815 /* take a ref on the qhp since we must release the lock */ 813 /* take a ref on the qhp since we must release the lock */
@@ -847,10 +845,23 @@ static void __flush_qp(struct iwch_qp *qhp, unsigned long *flag)
847 845
848static void flush_qp(struct iwch_qp *qhp, unsigned long *flag) 846static void flush_qp(struct iwch_qp *qhp, unsigned long *flag)
849{ 847{
850 if (qhp->ibqp.uobject) 848 struct iwch_cq *rchp, *schp;
849
850 rchp = get_chp(qhp->rhp, qhp->attr.rcq);
851 schp = get_chp(qhp->rhp, qhp->attr.scq);
852
853 if (qhp->ibqp.uobject) {
851 cxio_set_wq_in_error(&qhp->wq); 854 cxio_set_wq_in_error(&qhp->wq);
852 else 855 cxio_set_cq_in_error(&rchp->cq);
853 __flush_qp(qhp, flag); 856 (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
857 if (schp != rchp) {
858 cxio_set_cq_in_error(&schp->cq);
859 (*schp->ibcq.comp_handler)(&schp->ibcq,
860 schp->ibcq.cq_context);
861 }
862 return;
863 }
864 __flush_qp(qhp, rchp, schp, flag);
854} 865}
855 866
856 867
diff --git a/drivers/infiniband/hw/cxgb3/iwch_user.h b/drivers/infiniband/hw/cxgb3/iwch_user.h
index cb7086f558c1..a277c31fcaf7 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_user.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_user.h
@@ -45,10 +45,18 @@ struct iwch_create_cq_req {
45 __u64 user_rptr_addr; 45 __u64 user_rptr_addr;
46}; 46};
47 47
48struct iwch_create_cq_resp_v0 {
49 __u64 key;
50 __u32 cqid;
51 __u32 size_log2;
52};
53
48struct iwch_create_cq_resp { 54struct iwch_create_cq_resp {
49 __u64 key; 55 __u64 key;
50 __u32 cqid; 56 __u32 cqid;
51 __u32 size_log2; 57 __u32 size_log2;
58 __u32 memsize;
59 __u32 reserved;
52}; 60};
53 61
54struct iwch_create_qp_resp { 62struct iwch_create_qp_resp {
diff --git a/drivers/infiniband/hw/cxgb4/Makefile b/drivers/infiniband/hw/cxgb4/Makefile
index e31a499f0172..cd20b1342aec 100644
--- a/drivers/infiniband/hw/cxgb4/Makefile
+++ b/drivers/infiniband/hw/cxgb4/Makefile
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS += -Idrivers/net/cxgb4 1ccflags-y := -Idrivers/net/cxgb4
2 2
3obj-$(CONFIG_INFINIBAND_CXGB4) += iw_cxgb4.o 3obj-$(CONFIG_INFINIBAND_CXGB4) += iw_cxgb4.o
4 4
diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c
index 53f4cd4fc19a..43cae84005f0 100644
--- a/drivers/infiniband/hw/ehca/ehca_mrmw.c
+++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c
@@ -171,7 +171,7 @@ struct ib_mr *ehca_get_dma_mr(struct ib_pd *pd, int mr_access_flags)
171 } 171 }
172 172
173 ret = ehca_reg_maxmr(shca, e_maxmr, 173 ret = ehca_reg_maxmr(shca, e_maxmr,
174 (void *)ehca_map_vaddr((void *)KERNELBASE), 174 (void *)ehca_map_vaddr((void *)(KERNELBASE + PHYSICAL_START)),
175 mr_access_flags, e_pd, 175 mr_access_flags, e_pd,
176 &e_maxmr->ib.ib_mr.lkey, 176 &e_maxmr->ib.ib_mr.lkey,
177 &e_maxmr->ib.ib_mr.rkey); 177 &e_maxmr->ib.ib_mr.rkey);
@@ -1636,7 +1636,7 @@ int ehca_reg_internal_maxmr(
1636 1636
1637 /* register internal max-MR on HCA */ 1637 /* register internal max-MR on HCA */
1638 size_maxmr = ehca_mr_len; 1638 size_maxmr = ehca_mr_len;
1639 iova_start = (u64 *)ehca_map_vaddr((void *)KERNELBASE); 1639 iova_start = (u64 *)ehca_map_vaddr((void *)(KERNELBASE + PHYSICAL_START));
1640 ib_pbuf.addr = 0; 1640 ib_pbuf.addr = 0;
1641 ib_pbuf.size = size_maxmr; 1641 ib_pbuf.size = size_maxmr;
1642 num_kpages = NUM_CHUNKS(((u64)iova_start % PAGE_SIZE) + size_maxmr, 1642 num_kpages = NUM_CHUNKS(((u64)iova_start % PAGE_SIZE) + size_maxmr,
@@ -2209,7 +2209,7 @@ int ehca_mr_is_maxmr(u64 size,
2209{ 2209{
2210 /* a MR is treated as max-MR only if it fits following: */ 2210 /* a MR is treated as max-MR only if it fits following: */
2211 if ((size == ehca_mr_len) && 2211 if ((size == ehca_mr_len) &&
2212 (iova_start == (void *)ehca_map_vaddr((void *)KERNELBASE))) { 2212 (iova_start == (void *)ehca_map_vaddr((void *)(KERNELBASE + PHYSICAL_START)))) {
2213 ehca_gen_dbg("this is a max-MR"); 2213 ehca_gen_dbg("this is a max-MR");
2214 return 1; 2214 return 1;
2215 } else 2215 } else
diff --git a/drivers/infiniband/hw/ipath/Makefile b/drivers/infiniband/hw/ipath/Makefile
index fa3df82681df..4496f2820c92 100644
--- a/drivers/infiniband/hw/ipath/Makefile
+++ b/drivers/infiniband/hw/ipath/Makefile
@@ -1,4 +1,4 @@
1EXTRA_CFLAGS += -DIPATH_IDSTR='"QLogic kernel.org driver"' \ 1ccflags-y := -DIPATH_IDSTR='"QLogic kernel.org driver"' \
2 -DIPATH_KERN_TYPE=0 2 -DIPATH_KERN_TYPE=0
3 3
4obj-$(CONFIG_INFINIBAND_IPATH) += ib_ipath.o 4obj-$(CONFIG_INFINIBAND_IPATH) += ib_ipath.o
diff --git a/drivers/infiniband/hw/mlx4/ah.c b/drivers/infiniband/hw/mlx4/ah.c
index 11a236f8d884..4b8f9c49397e 100644
--- a/drivers/infiniband/hw/mlx4/ah.c
+++ b/drivers/infiniband/hw/mlx4/ah.c
@@ -30,66 +30,163 @@
30 * SOFTWARE. 30 * SOFTWARE.
31 */ 31 */
32 32
33#include <rdma/ib_addr.h>
34#include <rdma/ib_cache.h>
35
33#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/inet.h>
38#include <linux/string.h>
34 39
35#include "mlx4_ib.h" 40#include "mlx4_ib.h"
36 41
37struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr) 42int mlx4_ib_resolve_grh(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah_attr,
43 u8 *mac, int *is_mcast, u8 port)
38{ 44{
39 struct mlx4_dev *dev = to_mdev(pd->device)->dev; 45 struct in6_addr in6;
40 struct mlx4_ib_ah *ah;
41 46
42 ah = kmalloc(sizeof *ah, GFP_ATOMIC); 47 *is_mcast = 0;
43 if (!ah)
44 return ERR_PTR(-ENOMEM);
45 48
46 memset(&ah->av, 0, sizeof ah->av); 49 memcpy(&in6, ah_attr->grh.dgid.raw, sizeof in6);
50 if (rdma_link_local_addr(&in6))
51 rdma_get_ll_mac(&in6, mac);
52 else if (rdma_is_multicast_addr(&in6)) {
53 rdma_get_mcast_mac(&in6, mac);
54 *is_mcast = 1;
55 } else
56 return -EINVAL;
47 57
48 ah->av.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24)); 58 return 0;
49 ah->av.g_slid = ah_attr->src_path_bits; 59}
50 ah->av.dlid = cpu_to_be16(ah_attr->dlid); 60
51 if (ah_attr->static_rate) { 61static struct ib_ah *create_ib_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr,
52 ah->av.stat_rate = ah_attr->static_rate + MLX4_STAT_RATE_OFFSET; 62 struct mlx4_ib_ah *ah)
53 while (ah->av.stat_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET && 63{
54 !(1 << ah->av.stat_rate & dev->caps.stat_rate_support)) 64 struct mlx4_dev *dev = to_mdev(pd->device)->dev;
55 --ah->av.stat_rate; 65
56 } 66 ah->av.ib.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24));
57 ah->av.sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28); 67 ah->av.ib.g_slid = ah_attr->src_path_bits;
58 if (ah_attr->ah_flags & IB_AH_GRH) { 68 if (ah_attr->ah_flags & IB_AH_GRH) {
59 ah->av.g_slid |= 0x80; 69 ah->av.ib.g_slid |= 0x80;
60 ah->av.gid_index = ah_attr->grh.sgid_index; 70 ah->av.ib.gid_index = ah_attr->grh.sgid_index;
61 ah->av.hop_limit = ah_attr->grh.hop_limit; 71 ah->av.ib.hop_limit = ah_attr->grh.hop_limit;
62 ah->av.sl_tclass_flowlabel |= 72 ah->av.ib.sl_tclass_flowlabel |=
63 cpu_to_be32((ah_attr->grh.traffic_class << 20) | 73 cpu_to_be32((ah_attr->grh.traffic_class << 20) |
64 ah_attr->grh.flow_label); 74 ah_attr->grh.flow_label);
65 memcpy(ah->av.dgid, ah_attr->grh.dgid.raw, 16); 75 memcpy(ah->av.ib.dgid, ah_attr->grh.dgid.raw, 16);
76 }
77
78 ah->av.ib.dlid = cpu_to_be16(ah_attr->dlid);
79 if (ah_attr->static_rate) {
80 ah->av.ib.stat_rate = ah_attr->static_rate + MLX4_STAT_RATE_OFFSET;
81 while (ah->av.ib.stat_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET &&
82 !(1 << ah->av.ib.stat_rate & dev->caps.stat_rate_support))
83 --ah->av.ib.stat_rate;
66 } 84 }
85 ah->av.ib.sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28);
67 86
68 return &ah->ibah; 87 return &ah->ibah;
69} 88}
70 89
90static struct ib_ah *create_iboe_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr,
91 struct mlx4_ib_ah *ah)
92{
93 struct mlx4_ib_dev *ibdev = to_mdev(pd->device);
94 struct mlx4_dev *dev = ibdev->dev;
95 union ib_gid sgid;
96 u8 mac[6];
97 int err;
98 int is_mcast;
99 u16 vlan_tag;
100
101 err = mlx4_ib_resolve_grh(ibdev, ah_attr, mac, &is_mcast, ah_attr->port_num);
102 if (err)
103 return ERR_PTR(err);
104
105 memcpy(ah->av.eth.mac, mac, 6);
106 err = ib_get_cached_gid(pd->device, ah_attr->port_num, ah_attr->grh.sgid_index, &sgid);
107 if (err)
108 return ERR_PTR(err);
109 vlan_tag = rdma_get_vlan_id(&sgid);
110 if (vlan_tag < 0x1000)
111 vlan_tag |= (ah_attr->sl & 7) << 13;
112 ah->av.eth.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24));
113 ah->av.eth.gid_index = ah_attr->grh.sgid_index;
114 ah->av.eth.vlan = cpu_to_be16(vlan_tag);
115 if (ah_attr->static_rate) {
116 ah->av.eth.stat_rate = ah_attr->static_rate + MLX4_STAT_RATE_OFFSET;
117 while (ah->av.eth.stat_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET &&
118 !(1 << ah->av.eth.stat_rate & dev->caps.stat_rate_support))
119 --ah->av.eth.stat_rate;
120 }
121
122 /*
123 * HW requires multicast LID so we just choose one.
124 */
125 if (is_mcast)
126 ah->av.ib.dlid = cpu_to_be16(0xc000);
127
128 memcpy(ah->av.eth.dgid, ah_attr->grh.dgid.raw, 16);
129 ah->av.eth.sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28);
130
131 return &ah->ibah;
132}
133
134struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
135{
136 struct mlx4_ib_ah *ah;
137 struct ib_ah *ret;
138
139 ah = kzalloc(sizeof *ah, GFP_ATOMIC);
140 if (!ah)
141 return ERR_PTR(-ENOMEM);
142
143 if (rdma_port_get_link_layer(pd->device, ah_attr->port_num) == IB_LINK_LAYER_ETHERNET) {
144 if (!(ah_attr->ah_flags & IB_AH_GRH)) {
145 ret = ERR_PTR(-EINVAL);
146 } else {
147 /*
148 * TBD: need to handle the case when we get
149 * called in an atomic context and there we
150 * might sleep. We don't expect this
151 * currently since we're working with link
152 * local addresses which we can translate
153 * without going to sleep.
154 */
155 ret = create_iboe_ah(pd, ah_attr, ah);
156 }
157
158 if (IS_ERR(ret))
159 kfree(ah);
160
161 return ret;
162 } else
163 return create_ib_ah(pd, ah_attr, ah); /* never fails */
164}
165
71int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr) 166int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
72{ 167{
73 struct mlx4_ib_ah *ah = to_mah(ibah); 168 struct mlx4_ib_ah *ah = to_mah(ibah);
169 enum rdma_link_layer ll;
74 170
75 memset(ah_attr, 0, sizeof *ah_attr); 171 memset(ah_attr, 0, sizeof *ah_attr);
76 ah_attr->dlid = be16_to_cpu(ah->av.dlid); 172 ah_attr->sl = be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 28;
77 ah_attr->sl = be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 28; 173 ah_attr->port_num = be32_to_cpu(ah->av.ib.port_pd) >> 24;
78 ah_attr->port_num = be32_to_cpu(ah->av.port_pd) >> 24; 174 ll = rdma_port_get_link_layer(ibah->device, ah_attr->port_num);
79 if (ah->av.stat_rate) 175 ah_attr->dlid = ll == IB_LINK_LAYER_INFINIBAND ? be16_to_cpu(ah->av.ib.dlid) : 0;
80 ah_attr->static_rate = ah->av.stat_rate - MLX4_STAT_RATE_OFFSET; 176 if (ah->av.ib.stat_rate)
81 ah_attr->src_path_bits = ah->av.g_slid & 0x7F; 177 ah_attr->static_rate = ah->av.ib.stat_rate - MLX4_STAT_RATE_OFFSET;
178 ah_attr->src_path_bits = ah->av.ib.g_slid & 0x7F;
82 179
83 if (mlx4_ib_ah_grh_present(ah)) { 180 if (mlx4_ib_ah_grh_present(ah)) {
84 ah_attr->ah_flags = IB_AH_GRH; 181 ah_attr->ah_flags = IB_AH_GRH;
85 182
86 ah_attr->grh.traffic_class = 183 ah_attr->grh.traffic_class =
87 be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 20; 184 be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 20;
88 ah_attr->grh.flow_label = 185 ah_attr->grh.flow_label =
89 be32_to_cpu(ah->av.sl_tclass_flowlabel) & 0xfffff; 186 be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) & 0xfffff;
90 ah_attr->grh.hop_limit = ah->av.hop_limit; 187 ah_attr->grh.hop_limit = ah->av.ib.hop_limit;
91 ah_attr->grh.sgid_index = ah->av.gid_index; 188 ah_attr->grh.sgid_index = ah->av.ib.gid_index;
92 memcpy(ah_attr->grh.dgid.raw, ah->av.dgid, 16); 189 memcpy(ah_attr->grh.dgid.raw, ah->av.ib.dgid, 16);
93 } 190 }
94 191
95 return 0; 192 return 0;
diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
index f38d5b118927..c9a8dd63b9e2 100644
--- a/drivers/infiniband/hw/mlx4/mad.c
+++ b/drivers/infiniband/hw/mlx4/mad.c
@@ -311,19 +311,25 @@ int mlx4_ib_mad_init(struct mlx4_ib_dev *dev)
311 struct ib_mad_agent *agent; 311 struct ib_mad_agent *agent;
312 int p, q; 312 int p, q;
313 int ret; 313 int ret;
314 enum rdma_link_layer ll;
314 315
315 for (p = 0; p < dev->num_ports; ++p) 316 for (p = 0; p < dev->num_ports; ++p) {
317 ll = rdma_port_get_link_layer(&dev->ib_dev, p + 1);
316 for (q = 0; q <= 1; ++q) { 318 for (q = 0; q <= 1; ++q) {
317 agent = ib_register_mad_agent(&dev->ib_dev, p + 1, 319 if (ll == IB_LINK_LAYER_INFINIBAND) {
318 q ? IB_QPT_GSI : IB_QPT_SMI, 320 agent = ib_register_mad_agent(&dev->ib_dev, p + 1,
319 NULL, 0, send_handler, 321 q ? IB_QPT_GSI : IB_QPT_SMI,
320 NULL, NULL); 322 NULL, 0, send_handler,
321 if (IS_ERR(agent)) { 323 NULL, NULL);
322 ret = PTR_ERR(agent); 324 if (IS_ERR(agent)) {
323 goto err; 325 ret = PTR_ERR(agent);
324 } 326 goto err;
325 dev->send_agent[p][q] = agent; 327 }
328 dev->send_agent[p][q] = agent;
329 } else
330 dev->send_agent[p][q] = NULL;
326 } 331 }
332 }
327 333
328 return 0; 334 return 0;
329 335
@@ -344,8 +350,10 @@ void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev)
344 for (p = 0; p < dev->num_ports; ++p) { 350 for (p = 0; p < dev->num_ports; ++p) {
345 for (q = 0; q <= 1; ++q) { 351 for (q = 0; q <= 1; ++q) {
346 agent = dev->send_agent[p][q]; 352 agent = dev->send_agent[p][q];
347 dev->send_agent[p][q] = NULL; 353 if (agent) {
348 ib_unregister_mad_agent(agent); 354 dev->send_agent[p][q] = NULL;
355 ib_unregister_mad_agent(agent);
356 }
349 } 357 }
350 358
351 if (dev->sm_ah[p]) 359 if (dev->sm_ah[p])
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
index 4e94e360e43b..bf3e20cd0298 100644
--- a/drivers/infiniband/hw/mlx4/main.c
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -35,9 +35,14 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/errno.h> 37#include <linux/errno.h>
38#include <linux/netdevice.h>
39#include <linux/inetdevice.h>
40#include <linux/rtnetlink.h>
41#include <linux/if_vlan.h>
38 42
39#include <rdma/ib_smi.h> 43#include <rdma/ib_smi.h>
40#include <rdma/ib_user_verbs.h> 44#include <rdma/ib_user_verbs.h>
45#include <rdma/ib_addr.h>
41 46
42#include <linux/mlx4/driver.h> 47#include <linux/mlx4/driver.h>
43#include <linux/mlx4/cmd.h> 48#include <linux/mlx4/cmd.h>
@@ -58,6 +63,15 @@ static const char mlx4_ib_version[] =
58 DRV_NAME ": Mellanox ConnectX InfiniBand driver v" 63 DRV_NAME ": Mellanox ConnectX InfiniBand driver v"
59 DRV_VERSION " (" DRV_RELDATE ")\n"; 64 DRV_VERSION " (" DRV_RELDATE ")\n";
60 65
66struct update_gid_work {
67 struct work_struct work;
68 union ib_gid gids[128];
69 struct mlx4_ib_dev *dev;
70 int port;
71};
72
73static struct workqueue_struct *wq;
74
61static void init_query_mad(struct ib_smp *mad) 75static void init_query_mad(struct ib_smp *mad)
62{ 76{
63 mad->base_version = 1; 77 mad->base_version = 1;
@@ -66,6 +80,8 @@ static void init_query_mad(struct ib_smp *mad)
66 mad->method = IB_MGMT_METHOD_GET; 80 mad->method = IB_MGMT_METHOD_GET;
67} 81}
68 82
83static union ib_gid zgid;
84
69static int mlx4_ib_query_device(struct ib_device *ibdev, 85static int mlx4_ib_query_device(struct ib_device *ibdev,
70 struct ib_device_attr *props) 86 struct ib_device_attr *props)
71{ 87{
@@ -135,7 +151,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
135 props->max_srq = dev->dev->caps.num_srqs - dev->dev->caps.reserved_srqs; 151 props->max_srq = dev->dev->caps.num_srqs - dev->dev->caps.reserved_srqs;
136 props->max_srq_wr = dev->dev->caps.max_srq_wqes - 1; 152 props->max_srq_wr = dev->dev->caps.max_srq_wqes - 1;
137 props->max_srq_sge = dev->dev->caps.max_srq_sge; 153 props->max_srq_sge = dev->dev->caps.max_srq_sge;
138 props->max_fast_reg_page_list_len = PAGE_SIZE / sizeof (u64); 154 props->max_fast_reg_page_list_len = MLX4_MAX_FAST_REG_PAGES;
139 props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay; 155 props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay;
140 props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ? 156 props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ?
141 IB_ATOMIC_HCA : IB_ATOMIC_NONE; 157 IB_ATOMIC_HCA : IB_ATOMIC_NONE;
@@ -154,28 +170,19 @@ out:
154 return err; 170 return err;
155} 171}
156 172
157static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port, 173static enum rdma_link_layer
158 struct ib_port_attr *props) 174mlx4_ib_port_link_layer(struct ib_device *device, u8 port_num)
159{ 175{
160 struct ib_smp *in_mad = NULL; 176 struct mlx4_dev *dev = to_mdev(device)->dev;
161 struct ib_smp *out_mad = NULL;
162 int err = -ENOMEM;
163
164 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
165 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
166 if (!in_mad || !out_mad)
167 goto out;
168
169 memset(props, 0, sizeof *props);
170
171 init_query_mad(in_mad);
172 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
173 in_mad->attr_mod = cpu_to_be32(port);
174 177
175 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad); 178 return dev->caps.port_mask & (1 << (port_num - 1)) ?
176 if (err) 179 IB_LINK_LAYER_INFINIBAND : IB_LINK_LAYER_ETHERNET;
177 goto out; 180}
178 181
182static int ib_link_query_port(struct ib_device *ibdev, u8 port,
183 struct ib_port_attr *props,
184 struct ib_smp *out_mad)
185{
179 props->lid = be16_to_cpup((__be16 *) (out_mad->data + 16)); 186 props->lid = be16_to_cpup((__be16 *) (out_mad->data + 16));
180 props->lmc = out_mad->data[34] & 0x7; 187 props->lmc = out_mad->data[34] & 0x7;
181 props->sm_lid = be16_to_cpup((__be16 *) (out_mad->data + 18)); 188 props->sm_lid = be16_to_cpup((__be16 *) (out_mad->data + 18));
@@ -196,6 +203,80 @@ static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
196 props->max_vl_num = out_mad->data[37] >> 4; 203 props->max_vl_num = out_mad->data[37] >> 4;
197 props->init_type_reply = out_mad->data[41] >> 4; 204 props->init_type_reply = out_mad->data[41] >> 4;
198 205
206 return 0;
207}
208
209static u8 state_to_phys_state(enum ib_port_state state)
210{
211 return state == IB_PORT_ACTIVE ? 5 : 3;
212}
213
214static int eth_link_query_port(struct ib_device *ibdev, u8 port,
215 struct ib_port_attr *props,
216 struct ib_smp *out_mad)
217{
218 struct mlx4_ib_iboe *iboe = &to_mdev(ibdev)->iboe;
219 struct net_device *ndev;
220 enum ib_mtu tmp;
221
222 props->active_width = IB_WIDTH_4X;
223 props->active_speed = 4;
224 props->port_cap_flags = IB_PORT_CM_SUP;
225 props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len[port];
226 props->max_msg_sz = to_mdev(ibdev)->dev->caps.max_msg_sz;
227 props->pkey_tbl_len = 1;
228 props->bad_pkey_cntr = be16_to_cpup((__be16 *) (out_mad->data + 46));
229 props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48));
230 props->max_mtu = IB_MTU_2048;
231 props->subnet_timeout = 0;
232 props->max_vl_num = out_mad->data[37] >> 4;
233 props->init_type_reply = 0;
234 props->state = IB_PORT_DOWN;
235 props->phys_state = state_to_phys_state(props->state);
236 props->active_mtu = IB_MTU_256;
237 spin_lock(&iboe->lock);
238 ndev = iboe->netdevs[port - 1];
239 if (!ndev)
240 goto out;
241
242 tmp = iboe_get_mtu(ndev->mtu);
243 props->active_mtu = tmp ? min(props->max_mtu, tmp) : IB_MTU_256;
244
245 props->state = netif_running(ndev) && netif_oper_up(ndev) ?
246 IB_PORT_ACTIVE : IB_PORT_DOWN;
247 props->phys_state = state_to_phys_state(props->state);
248
249out:
250 spin_unlock(&iboe->lock);
251 return 0;
252}
253
254static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
255 struct ib_port_attr *props)
256{
257 struct ib_smp *in_mad = NULL;
258 struct ib_smp *out_mad = NULL;
259 int err = -ENOMEM;
260
261 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
262 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
263 if (!in_mad || !out_mad)
264 goto out;
265
266 memset(props, 0, sizeof *props);
267
268 init_query_mad(in_mad);
269 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
270 in_mad->attr_mod = cpu_to_be32(port);
271
272 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
273 if (err)
274 goto out;
275
276 err = mlx4_ib_port_link_layer(ibdev, port) == IB_LINK_LAYER_INFINIBAND ?
277 ib_link_query_port(ibdev, port, props, out_mad) :
278 eth_link_query_port(ibdev, port, props, out_mad);
279
199out: 280out:
200 kfree(in_mad); 281 kfree(in_mad);
201 kfree(out_mad); 282 kfree(out_mad);
@@ -203,8 +284,8 @@ out:
203 return err; 284 return err;
204} 285}
205 286
206static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index, 287static int __mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
207 union ib_gid *gid) 288 union ib_gid *gid)
208{ 289{
209 struct ib_smp *in_mad = NULL; 290 struct ib_smp *in_mad = NULL;
210 struct ib_smp *out_mad = NULL; 291 struct ib_smp *out_mad = NULL;
@@ -241,6 +322,25 @@ out:
241 return err; 322 return err;
242} 323}
243 324
325static int iboe_query_gid(struct ib_device *ibdev, u8 port, int index,
326 union ib_gid *gid)
327{
328 struct mlx4_ib_dev *dev = to_mdev(ibdev);
329
330 *gid = dev->iboe.gid_table[port - 1][index];
331
332 return 0;
333}
334
335static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
336 union ib_gid *gid)
337{
338 if (rdma_port_get_link_layer(ibdev, port) == IB_LINK_LAYER_INFINIBAND)
339 return __mlx4_ib_query_gid(ibdev, port, index, gid);
340 else
341 return iboe_query_gid(ibdev, port, index, gid);
342}
343
244static int mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, 344static int mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
245 u16 *pkey) 345 u16 *pkey)
246{ 346{
@@ -272,14 +372,32 @@ out:
272static int mlx4_ib_modify_device(struct ib_device *ibdev, int mask, 372static int mlx4_ib_modify_device(struct ib_device *ibdev, int mask,
273 struct ib_device_modify *props) 373 struct ib_device_modify *props)
274{ 374{
375 struct mlx4_cmd_mailbox *mailbox;
376
275 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC) 377 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
276 return -EOPNOTSUPP; 378 return -EOPNOTSUPP;
277 379
278 if (mask & IB_DEVICE_MODIFY_NODE_DESC) { 380 if (!(mask & IB_DEVICE_MODIFY_NODE_DESC))
279 spin_lock(&to_mdev(ibdev)->sm_lock); 381 return 0;
280 memcpy(ibdev->node_desc, props->node_desc, 64); 382
281 spin_unlock(&to_mdev(ibdev)->sm_lock); 383 spin_lock(&to_mdev(ibdev)->sm_lock);
282 } 384 memcpy(ibdev->node_desc, props->node_desc, 64);
385 spin_unlock(&to_mdev(ibdev)->sm_lock);
386
387 /*
388 * If possible, pass node desc to FW, so it can generate
389 * a 144 trap. If cmd fails, just ignore.
390 */
391 mailbox = mlx4_alloc_cmd_mailbox(to_mdev(ibdev)->dev);
392 if (IS_ERR(mailbox))
393 return 0;
394
395 memset(mailbox->buf, 0, 256);
396 memcpy(mailbox->buf, props->node_desc, 64);
397 mlx4_cmd(to_mdev(ibdev)->dev, mailbox->dma, 1, 0,
398 MLX4_CMD_SET_NODE, MLX4_CMD_TIME_CLASS_A);
399
400 mlx4_free_cmd_mailbox(to_mdev(ibdev)->dev, mailbox);
283 401
284 return 0; 402 return 0;
285} 403}
@@ -289,6 +407,7 @@ static int mlx4_SET_PORT(struct mlx4_ib_dev *dev, u8 port, int reset_qkey_viols,
289{ 407{
290 struct mlx4_cmd_mailbox *mailbox; 408 struct mlx4_cmd_mailbox *mailbox;
291 int err; 409 int err;
410 u8 is_eth = dev->dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH;
292 411
293 mailbox = mlx4_alloc_cmd_mailbox(dev->dev); 412 mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
294 if (IS_ERR(mailbox)) 413 if (IS_ERR(mailbox))
@@ -304,7 +423,7 @@ static int mlx4_SET_PORT(struct mlx4_ib_dev *dev, u8 port, int reset_qkey_viols,
304 ((__be32 *) mailbox->buf)[1] = cpu_to_be32(cap_mask); 423 ((__be32 *) mailbox->buf)[1] = cpu_to_be32(cap_mask);
305 } 424 }
306 425
307 err = mlx4_cmd(dev->dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT, 426 err = mlx4_cmd(dev->dev, mailbox->dma, port, is_eth, MLX4_CMD_SET_PORT,
308 MLX4_CMD_TIME_CLASS_B); 427 MLX4_CMD_TIME_CLASS_B);
309 428
310 mlx4_free_cmd_mailbox(dev->dev, mailbox); 429 mlx4_free_cmd_mailbox(dev->dev, mailbox);
@@ -447,18 +566,132 @@ static int mlx4_ib_dealloc_pd(struct ib_pd *pd)
447 return 0; 566 return 0;
448} 567}
449 568
569static int add_gid_entry(struct ib_qp *ibqp, union ib_gid *gid)
570{
571 struct mlx4_ib_qp *mqp = to_mqp(ibqp);
572 struct mlx4_ib_dev *mdev = to_mdev(ibqp->device);
573 struct mlx4_ib_gid_entry *ge;
574
575 ge = kzalloc(sizeof *ge, GFP_KERNEL);
576 if (!ge)
577 return -ENOMEM;
578
579 ge->gid = *gid;
580 if (mlx4_ib_add_mc(mdev, mqp, gid)) {
581 ge->port = mqp->port;
582 ge->added = 1;
583 }
584
585 mutex_lock(&mqp->mutex);
586 list_add_tail(&ge->list, &mqp->gid_list);
587 mutex_unlock(&mqp->mutex);
588
589 return 0;
590}
591
592int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
593 union ib_gid *gid)
594{
595 u8 mac[6];
596 struct net_device *ndev;
597 int ret = 0;
598
599 if (!mqp->port)
600 return 0;
601
602 spin_lock(&mdev->iboe.lock);
603 ndev = mdev->iboe.netdevs[mqp->port - 1];
604 if (ndev)
605 dev_hold(ndev);
606 spin_unlock(&mdev->iboe.lock);
607
608 if (ndev) {
609 rdma_get_mcast_mac((struct in6_addr *)gid, mac);
610 rtnl_lock();
611 dev_mc_add(mdev->iboe.netdevs[mqp->port - 1], mac);
612 ret = 1;
613 rtnl_unlock();
614 dev_put(ndev);
615 }
616
617 return ret;
618}
619
450static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 620static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
451{ 621{
452 return mlx4_multicast_attach(to_mdev(ibqp->device)->dev, 622 int err;
453 &to_mqp(ibqp)->mqp, gid->raw, 623 struct mlx4_ib_dev *mdev = to_mdev(ibqp->device);
454 !!(to_mqp(ibqp)->flags & 624 struct mlx4_ib_qp *mqp = to_mqp(ibqp);
455 MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK)); 625
626 err = mlx4_multicast_attach(mdev->dev, &mqp->mqp, gid->raw, !!(mqp->flags &
627 MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK));
628 if (err)
629 return err;
630
631 err = add_gid_entry(ibqp, gid);
632 if (err)
633 goto err_add;
634
635 return 0;
636
637err_add:
638 mlx4_multicast_detach(mdev->dev, &mqp->mqp, gid->raw);
639 return err;
640}
641
642static struct mlx4_ib_gid_entry *find_gid_entry(struct mlx4_ib_qp *qp, u8 *raw)
643{
644 struct mlx4_ib_gid_entry *ge;
645 struct mlx4_ib_gid_entry *tmp;
646 struct mlx4_ib_gid_entry *ret = NULL;
647
648 list_for_each_entry_safe(ge, tmp, &qp->gid_list, list) {
649 if (!memcmp(raw, ge->gid.raw, 16)) {
650 ret = ge;
651 break;
652 }
653 }
654
655 return ret;
456} 656}
457 657
458static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) 658static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
459{ 659{
460 return mlx4_multicast_detach(to_mdev(ibqp->device)->dev, 660 int err;
461 &to_mqp(ibqp)->mqp, gid->raw); 661 struct mlx4_ib_dev *mdev = to_mdev(ibqp->device);
662 struct mlx4_ib_qp *mqp = to_mqp(ibqp);
663 u8 mac[6];
664 struct net_device *ndev;
665 struct mlx4_ib_gid_entry *ge;
666
667 err = mlx4_multicast_detach(mdev->dev,
668 &mqp->mqp, gid->raw);
669 if (err)
670 return err;
671
672 mutex_lock(&mqp->mutex);
673 ge = find_gid_entry(mqp, gid->raw);
674 if (ge) {
675 spin_lock(&mdev->iboe.lock);
676 ndev = ge->added ? mdev->iboe.netdevs[ge->port - 1] : NULL;
677 if (ndev)
678 dev_hold(ndev);
679 spin_unlock(&mdev->iboe.lock);
680 rdma_get_mcast_mac((struct in6_addr *)gid, mac);
681 if (ndev) {
682 rtnl_lock();
683 dev_mc_del(mdev->iboe.netdevs[ge->port - 1], mac);
684 rtnl_unlock();
685 dev_put(ndev);
686 }
687 list_del(&ge->list);
688 kfree(ge);
689 } else
690 printk(KERN_WARNING "could not find mgid entry\n");
691
692 mutex_unlock(&mqp->mutex);
693
694 return 0;
462} 695}
463 696
464static int init_node_data(struct mlx4_ib_dev *dev) 697static int init_node_data(struct mlx4_ib_dev *dev)
@@ -543,15 +776,215 @@ static struct device_attribute *mlx4_class_attributes[] = {
543 &dev_attr_board_id 776 &dev_attr_board_id
544}; 777};
545 778
779static void mlx4_addrconf_ifid_eui48(u8 *eui, u16 vlan_id, struct net_device *dev)
780{
781 memcpy(eui, dev->dev_addr, 3);
782 memcpy(eui + 5, dev->dev_addr + 3, 3);
783 if (vlan_id < 0x1000) {
784 eui[3] = vlan_id >> 8;
785 eui[4] = vlan_id & 0xff;
786 } else {
787 eui[3] = 0xff;
788 eui[4] = 0xfe;
789 }
790 eui[0] ^= 2;
791}
792
793static void update_gids_task(struct work_struct *work)
794{
795 struct update_gid_work *gw = container_of(work, struct update_gid_work, work);
796 struct mlx4_cmd_mailbox *mailbox;
797 union ib_gid *gids;
798 int err;
799 struct mlx4_dev *dev = gw->dev->dev;
800 struct ib_event event;
801
802 mailbox = mlx4_alloc_cmd_mailbox(dev);
803 if (IS_ERR(mailbox)) {
804 printk(KERN_WARNING "update gid table failed %ld\n", PTR_ERR(mailbox));
805 return;
806 }
807
808 gids = mailbox->buf;
809 memcpy(gids, gw->gids, sizeof gw->gids);
810
811 err = mlx4_cmd(dev, mailbox->dma, MLX4_SET_PORT_GID_TABLE << 8 | gw->port,
812 1, MLX4_CMD_SET_PORT, MLX4_CMD_TIME_CLASS_B);
813 if (err)
814 printk(KERN_WARNING "set port command failed\n");
815 else {
816 memcpy(gw->dev->iboe.gid_table[gw->port - 1], gw->gids, sizeof gw->gids);
817 event.device = &gw->dev->ib_dev;
818 event.element.port_num = gw->port;
819 event.event = IB_EVENT_LID_CHANGE;
820 ib_dispatch_event(&event);
821 }
822
823 mlx4_free_cmd_mailbox(dev, mailbox);
824 kfree(gw);
825}
826
827static int update_ipv6_gids(struct mlx4_ib_dev *dev, int port, int clear)
828{
829 struct net_device *ndev = dev->iboe.netdevs[port - 1];
830 struct update_gid_work *work;
831 struct net_device *tmp;
832 int i;
833 u8 *hits;
834 int ret;
835 union ib_gid gid;
836 int free;
837 int found;
838 int need_update = 0;
839 u16 vid;
840
841 work = kzalloc(sizeof *work, GFP_ATOMIC);
842 if (!work)
843 return -ENOMEM;
844
845 hits = kzalloc(128, GFP_ATOMIC);
846 if (!hits) {
847 ret = -ENOMEM;
848 goto out;
849 }
850
851 read_lock(&dev_base_lock);
852 for_each_netdev(&init_net, tmp) {
853 if (ndev && (tmp == ndev || rdma_vlan_dev_real_dev(tmp) == ndev)) {
854 gid.global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
855 vid = rdma_vlan_dev_vlan_id(tmp);
856 mlx4_addrconf_ifid_eui48(&gid.raw[8], vid, ndev);
857 found = 0;
858 free = -1;
859 for (i = 0; i < 128; ++i) {
860 if (free < 0 &&
861 !memcmp(&dev->iboe.gid_table[port - 1][i], &zgid, sizeof zgid))
862 free = i;
863 if (!memcmp(&dev->iboe.gid_table[port - 1][i], &gid, sizeof gid)) {
864 hits[i] = 1;
865 found = 1;
866 break;
867 }
868 }
869
870 if (!found) {
871 if (tmp == ndev &&
872 (memcmp(&dev->iboe.gid_table[port - 1][0],
873 &gid, sizeof gid) ||
874 !memcmp(&dev->iboe.gid_table[port - 1][0],
875 &zgid, sizeof gid))) {
876 dev->iboe.gid_table[port - 1][0] = gid;
877 ++need_update;
878 hits[0] = 1;
879 } else if (free >= 0) {
880 dev->iboe.gid_table[port - 1][free] = gid;
881 hits[free] = 1;
882 ++need_update;
883 }
884 }
885 }
886 }
887 read_unlock(&dev_base_lock);
888
889 for (i = 0; i < 128; ++i)
890 if (!hits[i]) {
891 if (memcmp(&dev->iboe.gid_table[port - 1][i], &zgid, sizeof zgid))
892 ++need_update;
893 dev->iboe.gid_table[port - 1][i] = zgid;
894 }
895
896 if (need_update) {
897 memcpy(work->gids, dev->iboe.gid_table[port - 1], sizeof work->gids);
898 INIT_WORK(&work->work, update_gids_task);
899 work->port = port;
900 work->dev = dev;
901 queue_work(wq, &work->work);
902 } else
903 kfree(work);
904
905 kfree(hits);
906 return 0;
907
908out:
909 kfree(work);
910 return ret;
911}
912
913static void handle_en_event(struct mlx4_ib_dev *dev, int port, unsigned long event)
914{
915 switch (event) {
916 case NETDEV_UP:
917 case NETDEV_CHANGEADDR:
918 update_ipv6_gids(dev, port, 0);
919 break;
920
921 case NETDEV_DOWN:
922 update_ipv6_gids(dev, port, 1);
923 dev->iboe.netdevs[port - 1] = NULL;
924 }
925}
926
927static void netdev_added(struct mlx4_ib_dev *dev, int port)
928{
929 update_ipv6_gids(dev, port, 0);
930}
931
932static void netdev_removed(struct mlx4_ib_dev *dev, int port)
933{
934 update_ipv6_gids(dev, port, 1);
935}
936
937static int mlx4_ib_netdev_event(struct notifier_block *this, unsigned long event,
938 void *ptr)
939{
940 struct net_device *dev = ptr;
941 struct mlx4_ib_dev *ibdev;
942 struct net_device *oldnd;
943 struct mlx4_ib_iboe *iboe;
944 int port;
945
946 if (!net_eq(dev_net(dev), &init_net))
947 return NOTIFY_DONE;
948
949 ibdev = container_of(this, struct mlx4_ib_dev, iboe.nb);
950 iboe = &ibdev->iboe;
951
952 spin_lock(&iboe->lock);
953 mlx4_foreach_ib_transport_port(port, ibdev->dev) {
954 oldnd = iboe->netdevs[port - 1];
955 iboe->netdevs[port - 1] =
956 mlx4_get_protocol_dev(ibdev->dev, MLX4_PROTOCOL_EN, port);
957 if (oldnd != iboe->netdevs[port - 1]) {
958 if (iboe->netdevs[port - 1])
959 netdev_added(ibdev, port);
960 else
961 netdev_removed(ibdev, port);
962 }
963 }
964
965 if (dev == iboe->netdevs[0] ||
966 (iboe->netdevs[0] && rdma_vlan_dev_real_dev(dev) == iboe->netdevs[0]))
967 handle_en_event(ibdev, 1, event);
968 else if (dev == iboe->netdevs[1]
969 || (iboe->netdevs[1] && rdma_vlan_dev_real_dev(dev) == iboe->netdevs[1]))
970 handle_en_event(ibdev, 2, event);
971
972 spin_unlock(&iboe->lock);
973
974 return NOTIFY_DONE;
975}
976
546static void *mlx4_ib_add(struct mlx4_dev *dev) 977static void *mlx4_ib_add(struct mlx4_dev *dev)
547{ 978{
548 struct mlx4_ib_dev *ibdev; 979 struct mlx4_ib_dev *ibdev;
549 int num_ports = 0; 980 int num_ports = 0;
550 int i; 981 int i;
982 int err;
983 struct mlx4_ib_iboe *iboe;
551 984
552 printk_once(KERN_INFO "%s", mlx4_ib_version); 985 printk_once(KERN_INFO "%s", mlx4_ib_version);
553 986
554 mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB) 987 mlx4_foreach_ib_transport_port(i, dev)
555 num_ports++; 988 num_ports++;
556 989
557 /* No point in registering a device with no ports... */ 990 /* No point in registering a device with no ports... */
@@ -564,6 +997,8 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
564 return NULL; 997 return NULL;
565 } 998 }
566 999
1000 iboe = &ibdev->iboe;
1001
567 if (mlx4_pd_alloc(dev, &ibdev->priv_pdn)) 1002 if (mlx4_pd_alloc(dev, &ibdev->priv_pdn))
568 goto err_dealloc; 1003 goto err_dealloc;
569 1004
@@ -612,6 +1047,7 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
612 1047
613 ibdev->ib_dev.query_device = mlx4_ib_query_device; 1048 ibdev->ib_dev.query_device = mlx4_ib_query_device;
614 ibdev->ib_dev.query_port = mlx4_ib_query_port; 1049 ibdev->ib_dev.query_port = mlx4_ib_query_port;
1050 ibdev->ib_dev.get_link_layer = mlx4_ib_port_link_layer;
615 ibdev->ib_dev.query_gid = mlx4_ib_query_gid; 1051 ibdev->ib_dev.query_gid = mlx4_ib_query_gid;
616 ibdev->ib_dev.query_pkey = mlx4_ib_query_pkey; 1052 ibdev->ib_dev.query_pkey = mlx4_ib_query_pkey;
617 ibdev->ib_dev.modify_device = mlx4_ib_modify_device; 1053 ibdev->ib_dev.modify_device = mlx4_ib_modify_device;
@@ -656,6 +1092,8 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
656 ibdev->ib_dev.unmap_fmr = mlx4_ib_unmap_fmr; 1092 ibdev->ib_dev.unmap_fmr = mlx4_ib_unmap_fmr;
657 ibdev->ib_dev.dealloc_fmr = mlx4_ib_fmr_dealloc; 1093 ibdev->ib_dev.dealloc_fmr = mlx4_ib_fmr_dealloc;
658 1094
1095 spin_lock_init(&iboe->lock);
1096
659 if (init_node_data(ibdev)) 1097 if (init_node_data(ibdev))
660 goto err_map; 1098 goto err_map;
661 1099
@@ -668,16 +1106,28 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
668 if (mlx4_ib_mad_init(ibdev)) 1106 if (mlx4_ib_mad_init(ibdev))
669 goto err_reg; 1107 goto err_reg;
670 1108
1109 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE && !iboe->nb.notifier_call) {
1110 iboe->nb.notifier_call = mlx4_ib_netdev_event;
1111 err = register_netdevice_notifier(&iboe->nb);
1112 if (err)
1113 goto err_reg;
1114 }
1115
671 for (i = 0; i < ARRAY_SIZE(mlx4_class_attributes); ++i) { 1116 for (i = 0; i < ARRAY_SIZE(mlx4_class_attributes); ++i) {
672 if (device_create_file(&ibdev->ib_dev.dev, 1117 if (device_create_file(&ibdev->ib_dev.dev,
673 mlx4_class_attributes[i])) 1118 mlx4_class_attributes[i]))
674 goto err_reg; 1119 goto err_notif;
675 } 1120 }
676 1121
677 ibdev->ib_active = true; 1122 ibdev->ib_active = true;
678 1123
679 return ibdev; 1124 return ibdev;
680 1125
1126err_notif:
1127 if (unregister_netdevice_notifier(&ibdev->iboe.nb))
1128 printk(KERN_WARNING "failure unregistering notifier\n");
1129 flush_workqueue(wq);
1130
681err_reg: 1131err_reg:
682 ib_unregister_device(&ibdev->ib_dev); 1132 ib_unregister_device(&ibdev->ib_dev);
683 1133
@@ -703,11 +1153,16 @@ static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
703 1153
704 mlx4_ib_mad_cleanup(ibdev); 1154 mlx4_ib_mad_cleanup(ibdev);
705 ib_unregister_device(&ibdev->ib_dev); 1155 ib_unregister_device(&ibdev->ib_dev);
1156 if (ibdev->iboe.nb.notifier_call) {
1157 if (unregister_netdevice_notifier(&ibdev->iboe.nb))
1158 printk(KERN_WARNING "failure unregistering notifier\n");
1159 ibdev->iboe.nb.notifier_call = NULL;
1160 }
1161 iounmap(ibdev->uar_map);
706 1162
707 for (p = 1; p <= ibdev->num_ports; ++p) 1163 mlx4_foreach_port(p, dev, MLX4_PORT_TYPE_IB)
708 mlx4_CLOSE_PORT(dev, p); 1164 mlx4_CLOSE_PORT(dev, p);
709 1165
710 iounmap(ibdev->uar_map);
711 mlx4_uar_free(dev, &ibdev->priv_uar); 1166 mlx4_uar_free(dev, &ibdev->priv_uar);
712 mlx4_pd_free(dev, ibdev->priv_pdn); 1167 mlx4_pd_free(dev, ibdev->priv_pdn);
713 ib_dealloc_device(&ibdev->ib_dev); 1168 ib_dealloc_device(&ibdev->ib_dev);
@@ -747,19 +1202,33 @@ static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
747} 1202}
748 1203
749static struct mlx4_interface mlx4_ib_interface = { 1204static struct mlx4_interface mlx4_ib_interface = {
750 .add = mlx4_ib_add, 1205 .add = mlx4_ib_add,
751 .remove = mlx4_ib_remove, 1206 .remove = mlx4_ib_remove,
752 .event = mlx4_ib_event 1207 .event = mlx4_ib_event,
1208 .protocol = MLX4_PROTOCOL_IB
753}; 1209};
754 1210
755static int __init mlx4_ib_init(void) 1211static int __init mlx4_ib_init(void)
756{ 1212{
757 return mlx4_register_interface(&mlx4_ib_interface); 1213 int err;
1214
1215 wq = create_singlethread_workqueue("mlx4_ib");
1216 if (!wq)
1217 return -ENOMEM;
1218
1219 err = mlx4_register_interface(&mlx4_ib_interface);
1220 if (err) {
1221 destroy_workqueue(wq);
1222 return err;
1223 }
1224
1225 return 0;
758} 1226}
759 1227
760static void __exit mlx4_ib_cleanup(void) 1228static void __exit mlx4_ib_cleanup(void)
761{ 1229{
762 mlx4_unregister_interface(&mlx4_ib_interface); 1230 mlx4_unregister_interface(&mlx4_ib_interface);
1231 destroy_workqueue(wq);
763} 1232}
764 1233
765module_init(mlx4_ib_init); 1234module_init(mlx4_ib_init);
diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
index 3486d7675e56..2a322f21049f 100644
--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
@@ -112,6 +112,13 @@ enum mlx4_ib_qp_flags {
112 MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 1, 112 MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = 1 << 1,
113}; 113};
114 114
115struct mlx4_ib_gid_entry {
116 struct list_head list;
117 union ib_gid gid;
118 int added;
119 u8 port;
120};
121
115struct mlx4_ib_qp { 122struct mlx4_ib_qp {
116 struct ib_qp ibqp; 123 struct ib_qp ibqp;
117 struct mlx4_qp mqp; 124 struct mlx4_qp mqp;
@@ -138,6 +145,8 @@ struct mlx4_ib_qp {
138 u8 resp_depth; 145 u8 resp_depth;
139 u8 sq_no_prefetch; 146 u8 sq_no_prefetch;
140 u8 state; 147 u8 state;
148 int mlx_type;
149 struct list_head gid_list;
141}; 150};
142 151
143struct mlx4_ib_srq { 152struct mlx4_ib_srq {
@@ -157,7 +166,14 @@ struct mlx4_ib_srq {
157 166
158struct mlx4_ib_ah { 167struct mlx4_ib_ah {
159 struct ib_ah ibah; 168 struct ib_ah ibah;
160 struct mlx4_av av; 169 union mlx4_ext_av av;
170};
171
172struct mlx4_ib_iboe {
173 spinlock_t lock;
174 struct net_device *netdevs[MLX4_MAX_PORTS];
175 struct notifier_block nb;
176 union ib_gid gid_table[MLX4_MAX_PORTS][128];
161}; 177};
162 178
163struct mlx4_ib_dev { 179struct mlx4_ib_dev {
@@ -176,6 +192,7 @@ struct mlx4_ib_dev {
176 192
177 struct mutex cap_mask_mutex; 193 struct mutex cap_mask_mutex;
178 bool ib_active; 194 bool ib_active;
195 struct mlx4_ib_iboe iboe;
179}; 196};
180 197
181static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev) 198static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev)
@@ -314,9 +331,20 @@ int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, int npages,
314int mlx4_ib_unmap_fmr(struct list_head *fmr_list); 331int mlx4_ib_unmap_fmr(struct list_head *fmr_list);
315int mlx4_ib_fmr_dealloc(struct ib_fmr *fmr); 332int mlx4_ib_fmr_dealloc(struct ib_fmr *fmr);
316 333
334int mlx4_ib_resolve_grh(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah_attr,
335 u8 *mac, int *is_mcast, u8 port);
336
317static inline int mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah) 337static inline int mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah)
318{ 338{
319 return !!(ah->av.g_slid & 0x80); 339 u8 port = be32_to_cpu(ah->av.ib.port_pd) >> 24 & 3;
340
341 if (rdma_port_get_link_layer(ah->ibah.device, port) == IB_LINK_LAYER_ETHERNET)
342 return 1;
343
344 return !!(ah->av.ib.g_slid & 0x80);
320} 345}
321 346
347int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
348 union ib_gid *gid);
349
322#endif /* MLX4_IB_H */ 350#endif /* MLX4_IB_H */
diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c
index 1d27b9a8e2d6..dca55b19a6f1 100644
--- a/drivers/infiniband/hw/mlx4/mr.c
+++ b/drivers/infiniband/hw/mlx4/mr.c
@@ -226,7 +226,7 @@ struct ib_fast_reg_page_list *mlx4_ib_alloc_fast_reg_page_list(struct ib_device
226 struct mlx4_ib_fast_reg_page_list *mfrpl; 226 struct mlx4_ib_fast_reg_page_list *mfrpl;
227 int size = page_list_len * sizeof (u64); 227 int size = page_list_len * sizeof (u64);
228 228
229 if (size > PAGE_SIZE) 229 if (page_list_len > MLX4_MAX_FAST_REG_PAGES)
230 return ERR_PTR(-EINVAL); 230 return ERR_PTR(-EINVAL);
231 231
232 mfrpl = kmalloc(sizeof *mfrpl, GFP_KERNEL); 232 mfrpl = kmalloc(sizeof *mfrpl, GFP_KERNEL);
diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index 6a60827b2301..9a7794ac34c1 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -33,9 +33,11 @@
33 33
34#include <linux/log2.h> 34#include <linux/log2.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/netdevice.h>
36 37
37#include <rdma/ib_cache.h> 38#include <rdma/ib_cache.h>
38#include <rdma/ib_pack.h> 39#include <rdma/ib_pack.h>
40#include <rdma/ib_addr.h>
39 41
40#include <linux/mlx4/qp.h> 42#include <linux/mlx4/qp.h>
41 43
@@ -48,17 +50,26 @@ enum {
48 50
49enum { 51enum {
50 MLX4_IB_DEFAULT_SCHED_QUEUE = 0x83, 52 MLX4_IB_DEFAULT_SCHED_QUEUE = 0x83,
51 MLX4_IB_DEFAULT_QP0_SCHED_QUEUE = 0x3f 53 MLX4_IB_DEFAULT_QP0_SCHED_QUEUE = 0x3f,
54 MLX4_IB_LINK_TYPE_IB = 0,
55 MLX4_IB_LINK_TYPE_ETH = 1
52}; 56};
53 57
54enum { 58enum {
55 /* 59 /*
56 * Largest possible UD header: send with GRH and immediate data. 60 * Largest possible UD header: send with GRH and immediate
61 * data plus 18 bytes for an Ethernet header with VLAN/802.1Q
62 * tag. (LRH would only use 8 bytes, so Ethernet is the
63 * biggest case)
57 */ 64 */
58 MLX4_IB_UD_HEADER_SIZE = 72, 65 MLX4_IB_UD_HEADER_SIZE = 82,
59 MLX4_IB_LSO_HEADER_SPARE = 128, 66 MLX4_IB_LSO_HEADER_SPARE = 128,
60}; 67};
61 68
69enum {
70 MLX4_IB_IBOE_ETHERTYPE = 0x8915
71};
72
62struct mlx4_ib_sqp { 73struct mlx4_ib_sqp {
63 struct mlx4_ib_qp qp; 74 struct mlx4_ib_qp qp;
64 int pkey_index; 75 int pkey_index;
@@ -462,6 +473,7 @@ static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
462 mutex_init(&qp->mutex); 473 mutex_init(&qp->mutex);
463 spin_lock_init(&qp->sq.lock); 474 spin_lock_init(&qp->sq.lock);
464 spin_lock_init(&qp->rq.lock); 475 spin_lock_init(&qp->rq.lock);
476 INIT_LIST_HEAD(&qp->gid_list);
465 477
466 qp->state = IB_QPS_RESET; 478 qp->state = IB_QPS_RESET;
467 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) 479 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
@@ -649,6 +661,16 @@ static void mlx4_ib_unlock_cqs(struct mlx4_ib_cq *send_cq, struct mlx4_ib_cq *re
649 } 661 }
650} 662}
651 663
664static void del_gid_entries(struct mlx4_ib_qp *qp)
665{
666 struct mlx4_ib_gid_entry *ge, *tmp;
667
668 list_for_each_entry_safe(ge, tmp, &qp->gid_list, list) {
669 list_del(&ge->list);
670 kfree(ge);
671 }
672}
673
652static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp, 674static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
653 int is_user) 675 int is_user)
654{ 676{
@@ -695,6 +717,8 @@ static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
695 if (!qp->ibqp.srq) 717 if (!qp->ibqp.srq)
696 mlx4_db_free(dev->dev, &qp->db); 718 mlx4_db_free(dev->dev, &qp->db);
697 } 719 }
720
721 del_gid_entries(qp);
698} 722}
699 723
700struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd, 724struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
@@ -852,6 +876,14 @@ static void mlx4_set_sched(struct mlx4_qp_path *path, u8 port)
852static int mlx4_set_path(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah, 876static int mlx4_set_path(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah,
853 struct mlx4_qp_path *path, u8 port) 877 struct mlx4_qp_path *path, u8 port)
854{ 878{
879 int err;
880 int is_eth = rdma_port_get_link_layer(&dev->ib_dev, port) ==
881 IB_LINK_LAYER_ETHERNET;
882 u8 mac[6];
883 int is_mcast;
884 u16 vlan_tag;
885 int vidx;
886
855 path->grh_mylmc = ah->src_path_bits & 0x7f; 887 path->grh_mylmc = ah->src_path_bits & 0x7f;
856 path->rlid = cpu_to_be16(ah->dlid); 888 path->rlid = cpu_to_be16(ah->dlid);
857 if (ah->static_rate) { 889 if (ah->static_rate) {
@@ -879,12 +911,49 @@ static int mlx4_set_path(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah,
879 memcpy(path->rgid, ah->grh.dgid.raw, 16); 911 memcpy(path->rgid, ah->grh.dgid.raw, 16);
880 } 912 }
881 913
882 path->sched_queue = MLX4_IB_DEFAULT_SCHED_QUEUE | 914 if (is_eth) {
883 ((port - 1) << 6) | ((ah->sl & 0xf) << 2); 915 path->sched_queue = MLX4_IB_DEFAULT_SCHED_QUEUE |
916 ((port - 1) << 6) | ((ah->sl & 7) << 3) | ((ah->sl & 8) >> 1);
917
918 if (!(ah->ah_flags & IB_AH_GRH))
919 return -1;
920
921 err = mlx4_ib_resolve_grh(dev, ah, mac, &is_mcast, port);
922 if (err)
923 return err;
924
925 memcpy(path->dmac, mac, 6);
926 path->ackto = MLX4_IB_LINK_TYPE_ETH;
927 /* use index 0 into MAC table for IBoE */
928 path->grh_mylmc &= 0x80;
929
930 vlan_tag = rdma_get_vlan_id(&dev->iboe.gid_table[port - 1][ah->grh.sgid_index]);
931 if (vlan_tag < 0x1000) {
932 if (mlx4_find_cached_vlan(dev->dev, port, vlan_tag, &vidx))
933 return -ENOENT;
934
935 path->vlan_index = vidx;
936 path->fl = 1 << 6;
937 }
938 } else
939 path->sched_queue = MLX4_IB_DEFAULT_SCHED_QUEUE |
940 ((port - 1) << 6) | ((ah->sl & 0xf) << 2);
884 941
885 return 0; 942 return 0;
886} 943}
887 944
945static void update_mcg_macs(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp)
946{
947 struct mlx4_ib_gid_entry *ge, *tmp;
948
949 list_for_each_entry_safe(ge, tmp, &qp->gid_list, list) {
950 if (!ge->added && mlx4_ib_add_mc(dev, qp, &ge->gid)) {
951 ge->added = 1;
952 ge->port = qp->port;
953 }
954 }
955}
956
888static int __mlx4_ib_modify_qp(struct ib_qp *ibqp, 957static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
889 const struct ib_qp_attr *attr, int attr_mask, 958 const struct ib_qp_attr *attr, int attr_mask,
890 enum ib_qp_state cur_state, enum ib_qp_state new_state) 959 enum ib_qp_state cur_state, enum ib_qp_state new_state)
@@ -980,7 +1049,7 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
980 } 1049 }
981 1050
982 if (attr_mask & IB_QP_TIMEOUT) { 1051 if (attr_mask & IB_QP_TIMEOUT) {
983 context->pri_path.ackto = attr->timeout << 3; 1052 context->pri_path.ackto |= attr->timeout << 3;
984 optpar |= MLX4_QP_OPTPAR_ACK_TIMEOUT; 1053 optpar |= MLX4_QP_OPTPAR_ACK_TIMEOUT;
985 } 1054 }
986 1055
@@ -1118,8 +1187,10 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
1118 qp->atomic_rd_en = attr->qp_access_flags; 1187 qp->atomic_rd_en = attr->qp_access_flags;
1119 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) 1188 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
1120 qp->resp_depth = attr->max_dest_rd_atomic; 1189 qp->resp_depth = attr->max_dest_rd_atomic;
1121 if (attr_mask & IB_QP_PORT) 1190 if (attr_mask & IB_QP_PORT) {
1122 qp->port = attr->port_num; 1191 qp->port = attr->port_num;
1192 update_mcg_macs(dev, qp);
1193 }
1123 if (attr_mask & IB_QP_ALT_PATH) 1194 if (attr_mask & IB_QP_ALT_PATH)
1124 qp->alt_port = attr->alt_port_num; 1195 qp->alt_port = attr->alt_port_num;
1125 1196
@@ -1221,40 +1292,59 @@ static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_send_wr *wr,
1221 struct mlx4_wqe_mlx_seg *mlx = wqe; 1292 struct mlx4_wqe_mlx_seg *mlx = wqe;
1222 struct mlx4_wqe_inline_seg *inl = wqe + sizeof *mlx; 1293 struct mlx4_wqe_inline_seg *inl = wqe + sizeof *mlx;
1223 struct mlx4_ib_ah *ah = to_mah(wr->wr.ud.ah); 1294 struct mlx4_ib_ah *ah = to_mah(wr->wr.ud.ah);
1295 union ib_gid sgid;
1224 u16 pkey; 1296 u16 pkey;
1225 int send_size; 1297 int send_size;
1226 int header_size; 1298 int header_size;
1227 int spc; 1299 int spc;
1228 int i; 1300 int i;
1301 int is_eth;
1302 int is_vlan = 0;
1303 int is_grh;
1304 u16 vlan;
1229 1305
1230 send_size = 0; 1306 send_size = 0;
1231 for (i = 0; i < wr->num_sge; ++i) 1307 for (i = 0; i < wr->num_sge; ++i)
1232 send_size += wr->sg_list[i].length; 1308 send_size += wr->sg_list[i].length;
1233 1309
1234 ib_ud_header_init(send_size, mlx4_ib_ah_grh_present(ah), 0, &sqp->ud_header); 1310 is_eth = rdma_port_get_link_layer(sqp->qp.ibqp.device, sqp->qp.port) == IB_LINK_LAYER_ETHERNET;
1311 is_grh = mlx4_ib_ah_grh_present(ah);
1312 if (is_eth) {
1313 ib_get_cached_gid(ib_dev, be32_to_cpu(ah->av.ib.port_pd) >> 24,
1314 ah->av.ib.gid_index, &sgid);
1315 vlan = rdma_get_vlan_id(&sgid);
1316 is_vlan = vlan < 0x1000;
1317 }
1318 ib_ud_header_init(send_size, !is_eth, is_eth, is_vlan, is_grh, 0, &sqp->ud_header);
1319
1320 if (!is_eth) {
1321 sqp->ud_header.lrh.service_level =
1322 be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 28;
1323 sqp->ud_header.lrh.destination_lid = ah->av.ib.dlid;
1324 sqp->ud_header.lrh.source_lid = cpu_to_be16(ah->av.ib.g_slid & 0x7f);
1325 }
1235 1326
1236 sqp->ud_header.lrh.service_level = 1327 if (is_grh) {
1237 be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 28;
1238 sqp->ud_header.lrh.destination_lid = ah->av.dlid;
1239 sqp->ud_header.lrh.source_lid = cpu_to_be16(ah->av.g_slid & 0x7f);
1240 if (mlx4_ib_ah_grh_present(ah)) {
1241 sqp->ud_header.grh.traffic_class = 1328 sqp->ud_header.grh.traffic_class =
1242 (be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 20) & 0xff; 1329 (be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 20) & 0xff;
1243 sqp->ud_header.grh.flow_label = 1330 sqp->ud_header.grh.flow_label =
1244 ah->av.sl_tclass_flowlabel & cpu_to_be32(0xfffff); 1331 ah->av.ib.sl_tclass_flowlabel & cpu_to_be32(0xfffff);
1245 sqp->ud_header.grh.hop_limit = ah->av.hop_limit; 1332 sqp->ud_header.grh.hop_limit = ah->av.ib.hop_limit;
1246 ib_get_cached_gid(ib_dev, be32_to_cpu(ah->av.port_pd) >> 24, 1333 ib_get_cached_gid(ib_dev, be32_to_cpu(ah->av.ib.port_pd) >> 24,
1247 ah->av.gid_index, &sqp->ud_header.grh.source_gid); 1334 ah->av.ib.gid_index, &sqp->ud_header.grh.source_gid);
1248 memcpy(sqp->ud_header.grh.destination_gid.raw, 1335 memcpy(sqp->ud_header.grh.destination_gid.raw,
1249 ah->av.dgid, 16); 1336 ah->av.ib.dgid, 16);
1250 } 1337 }
1251 1338
1252 mlx->flags &= cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE); 1339 mlx->flags &= cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE);
1253 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MLX4_WQE_MLX_VL15 : 0) | 1340
1254 (sqp->ud_header.lrh.destination_lid == 1341 if (!is_eth) {
1255 IB_LID_PERMISSIVE ? MLX4_WQE_MLX_SLR : 0) | 1342 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MLX4_WQE_MLX_VL15 : 0) |
1256 (sqp->ud_header.lrh.service_level << 8)); 1343 (sqp->ud_header.lrh.destination_lid ==
1257 mlx->rlid = sqp->ud_header.lrh.destination_lid; 1344 IB_LID_PERMISSIVE ? MLX4_WQE_MLX_SLR : 0) |
1345 (sqp->ud_header.lrh.service_level << 8));
1346 mlx->rlid = sqp->ud_header.lrh.destination_lid;
1347 }
1258 1348
1259 switch (wr->opcode) { 1349 switch (wr->opcode) {
1260 case IB_WR_SEND: 1350 case IB_WR_SEND:
@@ -1270,9 +1360,29 @@ static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_send_wr *wr,
1270 return -EINVAL; 1360 return -EINVAL;
1271 } 1361 }
1272 1362
1273 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0; 1363 if (is_eth) {
1274 if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE) 1364 u8 *smac;
1275 sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE; 1365
1366 memcpy(sqp->ud_header.eth.dmac_h, ah->av.eth.mac, 6);
1367 /* FIXME: cache smac value? */
1368 smac = to_mdev(sqp->qp.ibqp.device)->iboe.netdevs[sqp->qp.port - 1]->dev_addr;
1369 memcpy(sqp->ud_header.eth.smac_h, smac, 6);
1370 if (!memcmp(sqp->ud_header.eth.smac_h, sqp->ud_header.eth.dmac_h, 6))
1371 mlx->flags |= cpu_to_be32(MLX4_WQE_CTRL_FORCE_LOOPBACK);
1372 if (!is_vlan) {
1373 sqp->ud_header.eth.type = cpu_to_be16(MLX4_IB_IBOE_ETHERTYPE);
1374 } else {
1375 u16 pcp;
1376
1377 sqp->ud_header.vlan.type = cpu_to_be16(MLX4_IB_IBOE_ETHERTYPE);
1378 pcp = (be32_to_cpu(ah->av.ib.sl_tclass_flowlabel) >> 27 & 3) << 13;
1379 sqp->ud_header.vlan.tag = cpu_to_be16(vlan | pcp);
1380 }
1381 } else {
1382 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;
1383 if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE)
1384 sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;
1385 }
1276 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED); 1386 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);
1277 if (!sqp->qp.ibqp.qp_num) 1387 if (!sqp->qp.ibqp.qp_num)
1278 ib_get_cached_pkey(ib_dev, sqp->qp.port, sqp->pkey_index, &pkey); 1388 ib_get_cached_pkey(ib_dev, sqp->qp.port, sqp->pkey_index, &pkey);
@@ -1429,11 +1539,14 @@ static void set_masked_atomic_seg(struct mlx4_wqe_masked_atomic_seg *aseg,
1429} 1539}
1430 1540
1431static void set_datagram_seg(struct mlx4_wqe_datagram_seg *dseg, 1541static void set_datagram_seg(struct mlx4_wqe_datagram_seg *dseg,
1432 struct ib_send_wr *wr) 1542 struct ib_send_wr *wr, __be16 *vlan)
1433{ 1543{
1434 memcpy(dseg->av, &to_mah(wr->wr.ud.ah)->av, sizeof (struct mlx4_av)); 1544 memcpy(dseg->av, &to_mah(wr->wr.ud.ah)->av, sizeof (struct mlx4_av));
1435 dseg->dqpn = cpu_to_be32(wr->wr.ud.remote_qpn); 1545 dseg->dqpn = cpu_to_be32(wr->wr.ud.remote_qpn);
1436 dseg->qkey = cpu_to_be32(wr->wr.ud.remote_qkey); 1546 dseg->qkey = cpu_to_be32(wr->wr.ud.remote_qkey);
1547 dseg->vlan = to_mah(wr->wr.ud.ah)->av.eth.vlan;
1548 memcpy(dseg->mac, to_mah(wr->wr.ud.ah)->av.eth.mac, 6);
1549 *vlan = dseg->vlan;
1437} 1550}
1438 1551
1439static void set_mlx_icrc_seg(void *dseg) 1552static void set_mlx_icrc_seg(void *dseg)
@@ -1536,6 +1649,7 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1536 __be32 uninitialized_var(lso_hdr_sz); 1649 __be32 uninitialized_var(lso_hdr_sz);
1537 __be32 blh; 1650 __be32 blh;
1538 int i; 1651 int i;
1652 __be16 vlan = cpu_to_be16(0xffff);
1539 1653
1540 spin_lock_irqsave(&qp->sq.lock, flags); 1654 spin_lock_irqsave(&qp->sq.lock, flags);
1541 1655
@@ -1639,7 +1753,7 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1639 break; 1753 break;
1640 1754
1641 case IB_QPT_UD: 1755 case IB_QPT_UD:
1642 set_datagram_seg(wqe, wr); 1756 set_datagram_seg(wqe, wr, &vlan);
1643 wqe += sizeof (struct mlx4_wqe_datagram_seg); 1757 wqe += sizeof (struct mlx4_wqe_datagram_seg);
1644 size += sizeof (struct mlx4_wqe_datagram_seg) / 16; 1758 size += sizeof (struct mlx4_wqe_datagram_seg) / 16;
1645 1759
@@ -1717,6 +1831,11 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1717 ctrl->owner_opcode = mlx4_ib_opcode[wr->opcode] | 1831 ctrl->owner_opcode = mlx4_ib_opcode[wr->opcode] |
1718 (ind & qp->sq.wqe_cnt ? cpu_to_be32(1 << 31) : 0) | blh; 1832 (ind & qp->sq.wqe_cnt ? cpu_to_be32(1 << 31) : 0) | blh;
1719 1833
1834 if (be16_to_cpu(vlan) < 0x1000) {
1835 ctrl->ins_vlan = 1 << 6;
1836 ctrl->vlan_tag = vlan;
1837 }
1838
1720 stamp = ind + qp->sq_spare_wqes; 1839 stamp = ind + qp->sq_spare_wqes;
1721 ind += DIV_ROUND_UP(size * 16, 1U << qp->sq.wqe_shift); 1840 ind += DIV_ROUND_UP(size * 16, 1U << qp->sq.wqe_shift);
1722 1841
@@ -1866,17 +1985,27 @@ static int to_ib_qp_access_flags(int mlx4_flags)
1866 return ib_flags; 1985 return ib_flags;
1867} 1986}
1868 1987
1869static void to_ib_ah_attr(struct mlx4_dev *dev, struct ib_ah_attr *ib_ah_attr, 1988static void to_ib_ah_attr(struct mlx4_ib_dev *ibdev, struct ib_ah_attr *ib_ah_attr,
1870 struct mlx4_qp_path *path) 1989 struct mlx4_qp_path *path)
1871{ 1990{
1991 struct mlx4_dev *dev = ibdev->dev;
1992 int is_eth;
1993
1872 memset(ib_ah_attr, 0, sizeof *ib_ah_attr); 1994 memset(ib_ah_attr, 0, sizeof *ib_ah_attr);
1873 ib_ah_attr->port_num = path->sched_queue & 0x40 ? 2 : 1; 1995 ib_ah_attr->port_num = path->sched_queue & 0x40 ? 2 : 1;
1874 1996
1875 if (ib_ah_attr->port_num == 0 || ib_ah_attr->port_num > dev->caps.num_ports) 1997 if (ib_ah_attr->port_num == 0 || ib_ah_attr->port_num > dev->caps.num_ports)
1876 return; 1998 return;
1877 1999
2000 is_eth = rdma_port_get_link_layer(&ibdev->ib_dev, ib_ah_attr->port_num) ==
2001 IB_LINK_LAYER_ETHERNET;
2002 if (is_eth)
2003 ib_ah_attr->sl = ((path->sched_queue >> 3) & 0x7) |
2004 ((path->sched_queue & 4) << 1);
2005 else
2006 ib_ah_attr->sl = (path->sched_queue >> 2) & 0xf;
2007
1878 ib_ah_attr->dlid = be16_to_cpu(path->rlid); 2008 ib_ah_attr->dlid = be16_to_cpu(path->rlid);
1879 ib_ah_attr->sl = (path->sched_queue >> 2) & 0xf;
1880 ib_ah_attr->src_path_bits = path->grh_mylmc & 0x7f; 2009 ib_ah_attr->src_path_bits = path->grh_mylmc & 0x7f;
1881 ib_ah_attr->static_rate = path->static_rate ? path->static_rate - 5 : 0; 2010 ib_ah_attr->static_rate = path->static_rate ? path->static_rate - 5 : 0;
1882 ib_ah_attr->ah_flags = (path->grh_mylmc & (1 << 7)) ? IB_AH_GRH : 0; 2011 ib_ah_attr->ah_flags = (path->grh_mylmc & (1 << 7)) ? IB_AH_GRH : 0;
@@ -1929,8 +2058,8 @@ int mlx4_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr
1929 to_ib_qp_access_flags(be32_to_cpu(context.params2)); 2058 to_ib_qp_access_flags(be32_to_cpu(context.params2));
1930 2059
1931 if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC) { 2060 if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC) {
1932 to_ib_ah_attr(dev->dev, &qp_attr->ah_attr, &context.pri_path); 2061 to_ib_ah_attr(dev, &qp_attr->ah_attr, &context.pri_path);
1933 to_ib_ah_attr(dev->dev, &qp_attr->alt_ah_attr, &context.alt_path); 2062 to_ib_ah_attr(dev, &qp_attr->alt_ah_attr, &context.alt_path);
1934 qp_attr->alt_pkey_index = context.alt_path.pkey_index & 0x7f; 2063 qp_attr->alt_pkey_index = context.alt_path.pkey_index & 0x7f;
1935 qp_attr->alt_port_num = qp_attr->alt_ah_attr.port_num; 2064 qp_attr->alt_port_num = qp_attr->alt_ah_attr.port_num;
1936 } 2065 }
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index d2d172e6289c..a34c9d38e822 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -1493,7 +1493,7 @@ static int build_mlx_header(struct mthca_dev *dev, struct mthca_sqp *sqp,
1493 int err; 1493 int err;
1494 u16 pkey; 1494 u16 pkey;
1495 1495
1496 ib_ud_header_init(256, /* assume a MAD */ 1496 ib_ud_header_init(256, /* assume a MAD */ 1, 0, 0,
1497 mthca_ah_grh_present(to_mah(wr->wr.ud.ah)), 0, 1497 mthca_ah_grh_present(to_mah(wr->wr.ud.ah)), 0,
1498 &sqp->ud_header); 1498 &sqp->ud_header);
1499 1499
diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
index 61e0efd4ccfb..5c8d34cb6a23 100644
--- a/drivers/infiniband/hw/nes/nes_cm.c
+++ b/drivers/infiniband/hw/nes/nes_cm.c
@@ -1424,7 +1424,6 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1424{ 1424{
1425 1425
1426 int reset = 0; /* whether to send reset in case of err.. */ 1426 int reset = 0; /* whether to send reset in case of err.. */
1427 int passive_state;
1428 atomic_inc(&cm_resets_recvd); 1427 atomic_inc(&cm_resets_recvd);
1429 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u." 1428 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
1430 " refcnt=%d\n", cm_node, cm_node->state, 1429 " refcnt=%d\n", cm_node, cm_node->state,
@@ -1439,7 +1438,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
1439 active_open_err(cm_node, skb, reset); 1438 active_open_err(cm_node, skb, reset);
1440 break; 1439 break;
1441 case NES_CM_STATE_MPAREQ_RCVD: 1440 case NES_CM_STATE_MPAREQ_RCVD:
1442 passive_state = atomic_add_return(1, &cm_node->passive_state); 1441 atomic_inc(&cm_node->passive_state);
1443 dev_kfree_skb_any(skb); 1442 dev_kfree_skb_any(skb);
1444 break; 1443 break;
1445 case NES_CM_STATE_ESTABLISHED: 1444 case NES_CM_STATE_ESTABLISHED:
diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
index 10560c796fd6..3892e2c0e95a 100644
--- a/drivers/infiniband/hw/nes/nes_nic.c
+++ b/drivers/infiniband/hw/nes/nes_nic.c
@@ -271,6 +271,7 @@ static int nes_netdev_stop(struct net_device *netdev)
271 271
272 if (netif_msg_ifdown(nesvnic)) 272 if (netif_msg_ifdown(nesvnic))
273 printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name); 273 printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
274 netif_carrier_off(netdev);
274 275
275 /* Disable network packets */ 276 /* Disable network packets */
276 napi_disable(&nesvnic->napi); 277 napi_disable(&nesvnic->napi);
diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
index 9046e6675686..2374efbdda6b 100644
--- a/drivers/infiniband/hw/nes/nes_verbs.c
+++ b/drivers/infiniband/hw/nes/nes_verbs.c
@@ -476,9 +476,9 @@ static struct ib_fast_reg_page_list *nes_alloc_fast_reg_page_list(
476 } 476 }
477 nes_debug(NES_DBG_MR, "nes_alloc_fast_reg_pbl: nes_frpl = %p, " 477 nes_debug(NES_DBG_MR, "nes_alloc_fast_reg_pbl: nes_frpl = %p, "
478 "ibfrpl = %p, ibfrpl.page_list = %p, pbl.kva = %p, " 478 "ibfrpl = %p, ibfrpl.page_list = %p, pbl.kva = %p, "
479 "pbl.paddr= %p\n", pnesfrpl, &pnesfrpl->ibfrpl, 479 "pbl.paddr = %llx\n", pnesfrpl, &pnesfrpl->ibfrpl,
480 pnesfrpl->ibfrpl.page_list, pnesfrpl->nes_wqe_pbl.kva, 480 pnesfrpl->ibfrpl.page_list, pnesfrpl->nes_wqe_pbl.kva,
481 (void *)pnesfrpl->nes_wqe_pbl.paddr); 481 (unsigned long long) pnesfrpl->nes_wqe_pbl.paddr);
482 482
483 return pifrpl; 483 return pifrpl;
484} 484}
@@ -584,7 +584,9 @@ static int nes_query_port(struct ib_device *ibdev, u8 port, struct ib_port_attr
584 props->lmc = 0; 584 props->lmc = 0;
585 props->sm_lid = 0; 585 props->sm_lid = 0;
586 props->sm_sl = 0; 586 props->sm_sl = 0;
587 if (nesvnic->linkup) 587 if (netif_queue_stopped(netdev))
588 props->state = IB_PORT_DOWN;
589 else if (nesvnic->linkup)
588 props->state = IB_PORT_ACTIVE; 590 props->state = IB_PORT_ACTIVE;
589 else 591 else
590 props->state = IB_PORT_DOWN; 592 props->state = IB_PORT_DOWN;
@@ -3483,13 +3485,13 @@ static int nes_post_send(struct ib_qp *ibqp, struct ib_send_wr *ib_wr,
3483 for (i = 0; i < ib_wr->wr.fast_reg.page_list_len; i++) 3485 for (i = 0; i < ib_wr->wr.fast_reg.page_list_len; i++)
3484 dst_page_list[i] = cpu_to_le64(src_page_list[i]); 3486 dst_page_list[i] = cpu_to_le64(src_page_list[i]);
3485 3487
3486 nes_debug(NES_DBG_IW_TX, "SQ_FMR: iova_start: %p, " 3488 nes_debug(NES_DBG_IW_TX, "SQ_FMR: iova_start: %llx, "
3487 "length: %d, rkey: %0x, pgl_paddr: %p, " 3489 "length: %d, rkey: %0x, pgl_paddr: %llx, "
3488 "page_list_len: %u, wqe_misc: %x\n", 3490 "page_list_len: %u, wqe_misc: %x\n",
3489 (void *)ib_wr->wr.fast_reg.iova_start, 3491 (unsigned long long) ib_wr->wr.fast_reg.iova_start,
3490 ib_wr->wr.fast_reg.length, 3492 ib_wr->wr.fast_reg.length,
3491 ib_wr->wr.fast_reg.rkey, 3493 ib_wr->wr.fast_reg.rkey,
3492 (void *)pnesfrpl->nes_wqe_pbl.paddr, 3494 (unsigned long long) pnesfrpl->nes_wqe_pbl.paddr,
3493 ib_wr->wr.fast_reg.page_list_len, 3495 ib_wr->wr.fast_reg.page_list_len,
3494 wqe_misc); 3496 wqe_misc);
3495 break; 3497 break;
diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
index 61de0654820e..64c9e7d02d4a 100644
--- a/drivers/infiniband/hw/qib/qib.h
+++ b/drivers/infiniband/hw/qib/qib.h
@@ -1406,7 +1406,7 @@ extern struct mutex qib_mutex;
1406 */ 1406 */
1407#define qib_early_err(dev, fmt, ...) \ 1407#define qib_early_err(dev, fmt, ...) \
1408 do { \ 1408 do { \
1409 dev_info(dev, KERN_ERR QIB_DRV_NAME ": " fmt, ##__VA_ARGS__); \ 1409 dev_err(dev, fmt, ##__VA_ARGS__); \
1410 } while (0) 1410 } while (0)
1411 1411
1412#define qib_dev_err(dd, fmt, ...) \ 1412#define qib_dev_err(dd, fmt, ...) \
diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c
index 6b11645edf35..cef5d676120a 100644
--- a/drivers/infiniband/hw/qib/qib_file_ops.c
+++ b/drivers/infiniband/hw/qib/qib_file_ops.c
@@ -1722,7 +1722,7 @@ static int qib_close(struct inode *in, struct file *fp)
1722 1722
1723 mutex_lock(&qib_mutex); 1723 mutex_lock(&qib_mutex);
1724 1724
1725 fd = (struct qib_filedata *) fp->private_data; 1725 fd = fp->private_data;
1726 fp->private_data = NULL; 1726 fp->private_data = NULL;
1727 rcd = fd->rcd; 1727 rcd = fd->rcd;
1728 if (!rcd) { 1728 if (!rcd) {
@@ -1808,7 +1808,7 @@ static int qib_ctxt_info(struct file *fp, struct qib_ctxt_info __user *uinfo)
1808 struct qib_ctxtdata *rcd = ctxt_fp(fp); 1808 struct qib_ctxtdata *rcd = ctxt_fp(fp);
1809 struct qib_filedata *fd; 1809 struct qib_filedata *fd;
1810 1810
1811 fd = (struct qib_filedata *) fp->private_data; 1811 fd = fp->private_data;
1812 1812
1813 info.num_active = qib_count_active_units(); 1813 info.num_active = qib_count_active_units();
1814 info.unit = rcd->dd->unit; 1814 info.unit = rcd->dd->unit;
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index f1d16d3a01f6..f3b503936043 100644
--- a/drivers/infiniband/hw/qib/qib_init.c
+++ b/drivers/infiniband/hw/qib/qib_init.c
@@ -1243,6 +1243,7 @@ static int __devinit qib_init_one(struct pci_dev *pdev,
1243 qib_early_err(&pdev->dev, "QLogic PCIE device 0x%x cannot " 1243 qib_early_err(&pdev->dev, "QLogic PCIE device 0x%x cannot "
1244 "work if CONFIG_PCI_MSI is not enabled\n", 1244 "work if CONFIG_PCI_MSI is not enabled\n",
1245 ent->device); 1245 ent->device);
1246 dd = ERR_PTR(-ENODEV);
1246#endif 1247#endif
1247 break; 1248 break;
1248 1249
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c b/drivers/infiniband/hw/qib/qib_pcie.c
index 7fa6e5592630..48b6674cbc49 100644
--- a/drivers/infiniband/hw/qib/qib_pcie.c
+++ b/drivers/infiniband/hw/qib/qib_pcie.c
@@ -103,16 +103,20 @@ int qib_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent)
103 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 103 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
104 } else 104 } else
105 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); 105 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
106 if (ret) 106 if (ret) {
107 qib_early_err(&pdev->dev, 107 qib_early_err(&pdev->dev,
108 "Unable to set DMA consistent mask: %d\n", ret); 108 "Unable to set DMA consistent mask: %d\n", ret);
109 goto bail;
110 }
109 111
110 pci_set_master(pdev); 112 pci_set_master(pdev);
111 ret = pci_enable_pcie_error_reporting(pdev); 113 ret = pci_enable_pcie_error_reporting(pdev);
112 if (ret) 114 if (ret) {
113 qib_early_err(&pdev->dev, 115 qib_early_err(&pdev->dev,
114 "Unable to enable pcie error reporting: %d\n", 116 "Unable to enable pcie error reporting: %d\n",
115 ret); 117 ret);
118 ret = 0;
119 }
116 goto done; 120 goto done;
117 121
118bail: 122bail:
diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
index a0931119bd78..955fb7157793 100644
--- a/drivers/infiniband/hw/qib/qib_rc.c
+++ b/drivers/infiniband/hw/qib/qib_rc.c
@@ -2068,7 +2068,10 @@ send_last:
2068 goto nack_op_err; 2068 goto nack_op_err;
2069 if (!ret) 2069 if (!ret)
2070 goto rnr_nak; 2070 goto rnr_nak;
2071 goto send_last_imm; 2071 wc.ex.imm_data = ohdr->u.rc.imm_data;
2072 hdrsize += 4;
2073 wc.wc_flags = IB_WC_WITH_IMM;
2074 goto send_last;
2072 2075
2073 case OP(RDMA_READ_REQUEST): { 2076 case OP(RDMA_READ_REQUEST): {
2074 struct qib_ack_entry *e; 2077 struct qib_ack_entry *e;
diff --git a/drivers/infiniband/hw/qib/qib_uc.c b/drivers/infiniband/hw/qib/qib_uc.c
index b9c8b6346c1b..32ccf3c824ca 100644
--- a/drivers/infiniband/hw/qib/qib_uc.c
+++ b/drivers/infiniband/hw/qib/qib_uc.c
@@ -457,8 +457,10 @@ rdma_first:
457 } 457 }
458 if (opcode == OP(RDMA_WRITE_ONLY)) 458 if (opcode == OP(RDMA_WRITE_ONLY))
459 goto rdma_last; 459 goto rdma_last;
460 else if (opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE)) 460 else if (opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE)) {
461 wc.ex.imm_data = ohdr->u.rc.imm_data;
461 goto rdma_last_imm; 462 goto rdma_last_imm;
463 }
462 /* FALLTHROUGH */ 464 /* FALLTHROUGH */
463 case OP(RDMA_WRITE_MIDDLE): 465 case OP(RDMA_WRITE_MIDDLE):
464 /* Check for invalid length PMTU or posted rwqe len. */ 466 /* Check for invalid length PMTU or posted rwqe len. */
@@ -471,8 +473,8 @@ rdma_first:
471 break; 473 break;
472 474
473 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE): 475 case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
474rdma_last_imm:
475 wc.ex.imm_data = ohdr->u.imm_data; 476 wc.ex.imm_data = ohdr->u.imm_data;
477rdma_last_imm:
476 hdrsize += 4; 478 hdrsize += 4;
477 wc.wc_flags = IB_WC_WITH_IMM; 479 wc.wc_flags = IB_WC_WITH_IMM;
478 480
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index ec6b4fbe25e4..dfa71903d6e4 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -223,6 +223,7 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
223 unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV; 223 unsigned int wr_id = wc->wr_id & ~IPOIB_OP_RECV;
224 struct sk_buff *skb; 224 struct sk_buff *skb;
225 u64 mapping[IPOIB_UD_RX_SG]; 225 u64 mapping[IPOIB_UD_RX_SG];
226 union ib_gid *dgid;
226 227
227 ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n", 228 ipoib_dbg_data(priv, "recv completion: id %d, status: %d\n",
228 wr_id, wc->status); 229 wr_id, wc->status);
@@ -271,6 +272,16 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
271 ipoib_ud_dma_unmap_rx(priv, mapping); 272 ipoib_ud_dma_unmap_rx(priv, mapping);
272 ipoib_ud_skb_put_frags(priv, skb, wc->byte_len); 273 ipoib_ud_skb_put_frags(priv, skb, wc->byte_len);
273 274
275 /* First byte of dgid signals multicast when 0xff */
276 dgid = &((struct ib_grh *)skb->data)->dgid;
277
278 if (!(wc->wc_flags & IB_WC_GRH) || dgid->raw[0] != 0xff)
279 skb->pkt_type = PACKET_HOST;
280 else if (memcmp(dgid, dev->broadcast + 4, sizeof(union ib_gid)) == 0)
281 skb->pkt_type = PACKET_BROADCAST;
282 else
283 skb->pkt_type = PACKET_MULTICAST;
284
274 skb_pull(skb, IB_GRH_BYTES); 285 skb_pull(skb, IB_GRH_BYTES);
275 286
276 skb->protocol = ((struct ipoib_header *) skb->data)->proto; 287 skb->protocol = ((struct ipoib_header *) skb->data)->proto;
@@ -281,9 +292,6 @@ static void ipoib_ib_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
281 dev->stats.rx_bytes += skb->len; 292 dev->stats.rx_bytes += skb->len;
282 293
283 skb->dev = dev; 294 skb->dev = dev;
284 /* XXX get correct PACKET_ type here */
285 skb->pkt_type = PACKET_HOST;
286
287 if (test_bit(IPOIB_FLAG_CSUM, &priv->flags) && likely(wc->csum_ok)) 295 if (test_bit(IPOIB_FLAG_CSUM, &priv->flags) && likely(wc->csum_ok))
288 skb->ip_summed = CHECKSUM_UNNECESSARY; 296 skb->ip_summed = CHECKSUM_UNNECESSARY;
289 297
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index b4b22576f12a..4f258c88c1b4 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -1240,6 +1240,7 @@ static struct net_device *ipoib_add_port(const char *format,
1240 goto alloc_mem_failed; 1240 goto alloc_mem_failed;
1241 1241
1242 SET_NETDEV_DEV(priv->dev, hca->dma_device); 1242 SET_NETDEV_DEV(priv->dev, hca->dma_device);
1243 priv->dev->dev_id = port - 1;
1243 1244
1244 if (!ib_query_port(hca, port, &attr)) 1245 if (!ib_query_port(hca, port, &attr))
1245 priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu); 1246 priv->max_ib_mtu = ib_mtu_enum_to_int(attr.max_mtu);
@@ -1362,6 +1363,8 @@ static void ipoib_add_one(struct ib_device *device)
1362 } 1363 }
1363 1364
1364 for (p = s; p <= e; ++p) { 1365 for (p = s; p <= e; ++p) {
1366 if (rdma_port_get_link_layer(device, p) != IB_LINK_LAYER_INFINIBAND)
1367 continue;
1365 dev = ipoib_add_port("ib%d", device, p); 1368 dev = ipoib_add_port("ib%d", device, p);
1366 if (!IS_ERR(dev)) { 1369 if (!IS_ERR(dev)) {
1367 priv = netdev_priv(dev); 1370 priv = netdev_priv(dev);
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 7f8f16bad753..cfc1d65c4577 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -291,7 +291,7 @@ static void srp_free_target_ib(struct srp_target_port *target)
291 291
292 for (i = 0; i < SRP_RQ_SIZE; ++i) 292 for (i = 0; i < SRP_RQ_SIZE; ++i)
293 srp_free_iu(target->srp_host, target->rx_ring[i]); 293 srp_free_iu(target->srp_host, target->rx_ring[i]);
294 for (i = 0; i < SRP_SQ_SIZE + 1; ++i) 294 for (i = 0; i < SRP_SQ_SIZE; ++i)
295 srp_free_iu(target->srp_host, target->tx_ring[i]); 295 srp_free_iu(target->srp_host, target->tx_ring[i]);
296} 296}
297 297
@@ -811,6 +811,75 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target,
811 return len; 811 return len;
812} 812}
813 813
814/*
815 * Must be called with target->scsi_host->host_lock held to protect
816 * req_lim and tx_head. Lock cannot be dropped between call here and
817 * call to __srp_post_send().
818 *
819 * Note:
820 * An upper limit for the number of allocated information units for each
821 * request type is:
822 * - SRP_IU_CMD: SRP_CMD_SQ_SIZE, since the SCSI mid-layer never queues
823 * more than Scsi_Host.can_queue requests.
824 * - SRP_IU_TSK_MGMT: SRP_TSK_MGMT_SQ_SIZE.
825 * - SRP_IU_RSP: 1, since a conforming SRP target never sends more than
826 * one unanswered SRP request to an initiator.
827 */
828static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target,
829 enum srp_iu_type iu_type)
830{
831 s32 rsv = (iu_type == SRP_IU_TSK_MGMT) ? 0 : SRP_TSK_MGMT_SQ_SIZE;
832 struct srp_iu *iu;
833
834 srp_send_completion(target->send_cq, target);
835
836 if (target->tx_head - target->tx_tail >= SRP_SQ_SIZE)
837 return NULL;
838
839 /* Initiator responses to target requests do not consume credits */
840 if (target->req_lim <= rsv && iu_type != SRP_IU_RSP) {
841 ++target->zero_req_lim;
842 return NULL;
843 }
844
845 iu = target->tx_ring[target->tx_head & SRP_SQ_MASK];
846 iu->type = iu_type;
847 return iu;
848}
849
850/*
851 * Must be called with target->scsi_host->host_lock held to protect
852 * req_lim and tx_head.
853 */
854static int __srp_post_send(struct srp_target_port *target,
855 struct srp_iu *iu, int len)
856{
857 struct ib_sge list;
858 struct ib_send_wr wr, *bad_wr;
859 int ret = 0;
860
861 list.addr = iu->dma;
862 list.length = len;
863 list.lkey = target->srp_host->srp_dev->mr->lkey;
864
865 wr.next = NULL;
866 wr.wr_id = target->tx_head & SRP_SQ_MASK;
867 wr.sg_list = &list;
868 wr.num_sge = 1;
869 wr.opcode = IB_WR_SEND;
870 wr.send_flags = IB_SEND_SIGNALED;
871
872 ret = ib_post_send(target->qp, &wr, &bad_wr);
873
874 if (!ret) {
875 ++target->tx_head;
876 if (iu->type != SRP_IU_RSP)
877 --target->req_lim;
878 }
879
880 return ret;
881}
882
814static int srp_post_recv(struct srp_target_port *target) 883static int srp_post_recv(struct srp_target_port *target)
815{ 884{
816 unsigned long flags; 885 unsigned long flags;
@@ -822,7 +891,7 @@ static int srp_post_recv(struct srp_target_port *target)
822 891
823 spin_lock_irqsave(target->scsi_host->host_lock, flags); 892 spin_lock_irqsave(target->scsi_host->host_lock, flags);
824 893
825 next = target->rx_head & (SRP_RQ_SIZE - 1); 894 next = target->rx_head & SRP_RQ_MASK;
826 wr.wr_id = next; 895 wr.wr_id = next;
827 iu = target->rx_ring[next]; 896 iu = target->rx_ring[next];
828 897
@@ -896,6 +965,71 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp)
896 spin_unlock_irqrestore(target->scsi_host->host_lock, flags); 965 spin_unlock_irqrestore(target->scsi_host->host_lock, flags);
897} 966}
898 967
968static int srp_response_common(struct srp_target_port *target, s32 req_delta,
969 void *rsp, int len)
970{
971 struct ib_device *dev;
972 unsigned long flags;
973 struct srp_iu *iu;
974 int err = 1;
975
976 dev = target->srp_host->srp_dev->dev;
977
978 spin_lock_irqsave(target->scsi_host->host_lock, flags);
979 target->req_lim += req_delta;
980
981 iu = __srp_get_tx_iu(target, SRP_IU_RSP);
982 if (!iu) {
983 shost_printk(KERN_ERR, target->scsi_host, PFX
984 "no IU available to send response\n");
985 goto out;
986 }
987
988 ib_dma_sync_single_for_cpu(dev, iu->dma, len, DMA_TO_DEVICE);
989 memcpy(iu->buf, rsp, len);
990 ib_dma_sync_single_for_device(dev, iu->dma, len, DMA_TO_DEVICE);
991
992 err = __srp_post_send(target, iu, len);
993 if (err)
994 shost_printk(KERN_ERR, target->scsi_host, PFX
995 "unable to post response: %d\n", err);
996
997out:
998 spin_unlock_irqrestore(target->scsi_host->host_lock, flags);
999 return err;
1000}
1001
1002static void srp_process_cred_req(struct srp_target_port *target,
1003 struct srp_cred_req *req)
1004{
1005 struct srp_cred_rsp rsp = {
1006 .opcode = SRP_CRED_RSP,
1007 .tag = req->tag,
1008 };
1009 s32 delta = be32_to_cpu(req->req_lim_delta);
1010
1011 if (srp_response_common(target, delta, &rsp, sizeof rsp))
1012 shost_printk(KERN_ERR, target->scsi_host, PFX
1013 "problems processing SRP_CRED_REQ\n");
1014}
1015
1016static void srp_process_aer_req(struct srp_target_port *target,
1017 struct srp_aer_req *req)
1018{
1019 struct srp_aer_rsp rsp = {
1020 .opcode = SRP_AER_RSP,
1021 .tag = req->tag,
1022 };
1023 s32 delta = be32_to_cpu(req->req_lim_delta);
1024
1025 shost_printk(KERN_ERR, target->scsi_host, PFX
1026 "ignoring AER for LUN %llu\n", be64_to_cpu(req->lun));
1027
1028 if (srp_response_common(target, delta, &rsp, sizeof rsp))
1029 shost_printk(KERN_ERR, target->scsi_host, PFX
1030 "problems processing SRP_AER_REQ\n");
1031}
1032
899static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc) 1033static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
900{ 1034{
901 struct ib_device *dev; 1035 struct ib_device *dev;
@@ -923,6 +1057,14 @@ static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
923 srp_process_rsp(target, iu->buf); 1057 srp_process_rsp(target, iu->buf);
924 break; 1058 break;
925 1059
1060 case SRP_CRED_REQ:
1061 srp_process_cred_req(target, iu->buf);
1062 break;
1063
1064 case SRP_AER_REQ:
1065 srp_process_aer_req(target, iu->buf);
1066 break;
1067
926 case SRP_T_LOGOUT: 1068 case SRP_T_LOGOUT:
927 /* XXX Handle target logout */ 1069 /* XXX Handle target logout */
928 shost_printk(KERN_WARNING, target->scsi_host, 1070 shost_printk(KERN_WARNING, target->scsi_host,
@@ -981,61 +1123,6 @@ static void srp_send_completion(struct ib_cq *cq, void *target_ptr)
981 } 1123 }
982} 1124}
983 1125
984/*
985 * Must be called with target->scsi_host->host_lock held to protect
986 * req_lim and tx_head. Lock cannot be dropped between call here and
987 * call to __srp_post_send().
988 */
989static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target,
990 enum srp_request_type req_type)
991{
992 s32 min = (req_type == SRP_REQ_TASK_MGMT) ? 1 : 2;
993
994 srp_send_completion(target->send_cq, target);
995
996 if (target->tx_head - target->tx_tail >= SRP_SQ_SIZE)
997 return NULL;
998
999 if (target->req_lim < min) {
1000 ++target->zero_req_lim;
1001 return NULL;
1002 }
1003
1004 return target->tx_ring[target->tx_head & SRP_SQ_SIZE];
1005}
1006
1007/*
1008 * Must be called with target->scsi_host->host_lock held to protect
1009 * req_lim and tx_head.
1010 */
1011static int __srp_post_send(struct srp_target_port *target,
1012 struct srp_iu *iu, int len)
1013{
1014 struct ib_sge list;
1015 struct ib_send_wr wr, *bad_wr;
1016 int ret = 0;
1017
1018 list.addr = iu->dma;
1019 list.length = len;
1020 list.lkey = target->srp_host->srp_dev->mr->lkey;
1021
1022 wr.next = NULL;
1023 wr.wr_id = target->tx_head & SRP_SQ_SIZE;
1024 wr.sg_list = &list;
1025 wr.num_sge = 1;
1026 wr.opcode = IB_WR_SEND;
1027 wr.send_flags = IB_SEND_SIGNALED;
1028
1029 ret = ib_post_send(target->qp, &wr, &bad_wr);
1030
1031 if (!ret) {
1032 ++target->tx_head;
1033 --target->req_lim;
1034 }
1035
1036 return ret;
1037}
1038
1039static int srp_queuecommand(struct scsi_cmnd *scmnd, 1126static int srp_queuecommand(struct scsi_cmnd *scmnd,
1040 void (*done)(struct scsi_cmnd *)) 1127 void (*done)(struct scsi_cmnd *))
1041{ 1128{
@@ -1056,7 +1143,7 @@ static int srp_queuecommand(struct scsi_cmnd *scmnd,
1056 return 0; 1143 return 0;
1057 } 1144 }
1058 1145
1059 iu = __srp_get_tx_iu(target, SRP_REQ_NORMAL); 1146 iu = __srp_get_tx_iu(target, SRP_IU_CMD);
1060 if (!iu) 1147 if (!iu)
1061 goto err; 1148 goto err;
1062 1149
@@ -1064,7 +1151,7 @@ static int srp_queuecommand(struct scsi_cmnd *scmnd,
1064 ib_dma_sync_single_for_cpu(dev, iu->dma, srp_max_iu_len, 1151 ib_dma_sync_single_for_cpu(dev, iu->dma, srp_max_iu_len,
1065 DMA_TO_DEVICE); 1152 DMA_TO_DEVICE);
1066 1153
1067 req = list_entry(target->free_reqs.next, struct srp_request, list); 1154 req = list_first_entry(&target->free_reqs, struct srp_request, list);
1068 1155
1069 scmnd->scsi_done = done; 1156 scmnd->scsi_done = done;
1070 scmnd->result = 0; 1157 scmnd->result = 0;
@@ -1121,7 +1208,7 @@ static int srp_alloc_iu_bufs(struct srp_target_port *target)
1121 goto err; 1208 goto err;
1122 } 1209 }
1123 1210
1124 for (i = 0; i < SRP_SQ_SIZE + 1; ++i) { 1211 for (i = 0; i < SRP_SQ_SIZE; ++i) {
1125 target->tx_ring[i] = srp_alloc_iu(target->srp_host, 1212 target->tx_ring[i] = srp_alloc_iu(target->srp_host,
1126 srp_max_iu_len, 1213 srp_max_iu_len,
1127 GFP_KERNEL, DMA_TO_DEVICE); 1214 GFP_KERNEL, DMA_TO_DEVICE);
@@ -1137,7 +1224,7 @@ err:
1137 target->rx_ring[i] = NULL; 1224 target->rx_ring[i] = NULL;
1138 } 1225 }
1139 1226
1140 for (i = 0; i < SRP_SQ_SIZE + 1; ++i) { 1227 for (i = 0; i < SRP_SQ_SIZE; ++i) {
1141 srp_free_iu(target->srp_host, target->tx_ring[i]); 1228 srp_free_iu(target->srp_host, target->tx_ring[i]);
1142 target->tx_ring[i] = NULL; 1229 target->tx_ring[i] = NULL;
1143 } 1230 }
@@ -1252,8 +1339,13 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
1252 target->max_ti_iu_len = be32_to_cpu(rsp->max_ti_iu_len); 1339 target->max_ti_iu_len = be32_to_cpu(rsp->max_ti_iu_len);
1253 target->req_lim = be32_to_cpu(rsp->req_lim_delta); 1340 target->req_lim = be32_to_cpu(rsp->req_lim_delta);
1254 1341
1255 target->scsi_host->can_queue = min(target->req_lim, 1342 /*
1256 target->scsi_host->can_queue); 1343 * Reserve credits for task management so we don't
1344 * bounce requests back to the SCSI mid-layer.
1345 */
1346 target->scsi_host->can_queue
1347 = min(target->req_lim - SRP_TSK_MGMT_SQ_SIZE,
1348 target->scsi_host->can_queue);
1257 } else { 1349 } else {
1258 shost_printk(KERN_WARNING, target->scsi_host, 1350 shost_printk(KERN_WARNING, target->scsi_host,
1259 PFX "Unhandled RSP opcode %#x\n", opcode); 1351 PFX "Unhandled RSP opcode %#x\n", opcode);
@@ -1350,6 +1442,7 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
1350static int srp_send_tsk_mgmt(struct srp_target_port *target, 1442static int srp_send_tsk_mgmt(struct srp_target_port *target,
1351 struct srp_request *req, u8 func) 1443 struct srp_request *req, u8 func)
1352{ 1444{
1445 struct ib_device *dev = target->srp_host->srp_dev->dev;
1353 struct srp_iu *iu; 1446 struct srp_iu *iu;
1354 struct srp_tsk_mgmt *tsk_mgmt; 1447 struct srp_tsk_mgmt *tsk_mgmt;
1355 1448
@@ -1363,10 +1456,12 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
1363 1456
1364 init_completion(&req->done); 1457 init_completion(&req->done);
1365 1458
1366 iu = __srp_get_tx_iu(target, SRP_REQ_TASK_MGMT); 1459 iu = __srp_get_tx_iu(target, SRP_IU_TSK_MGMT);
1367 if (!iu) 1460 if (!iu)
1368 goto out; 1461 goto out;
1369 1462
1463 ib_dma_sync_single_for_cpu(dev, iu->dma, sizeof *tsk_mgmt,
1464 DMA_TO_DEVICE);
1370 tsk_mgmt = iu->buf; 1465 tsk_mgmt = iu->buf;
1371 memset(tsk_mgmt, 0, sizeof *tsk_mgmt); 1466 memset(tsk_mgmt, 0, sizeof *tsk_mgmt);
1372 1467
@@ -1376,6 +1471,8 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
1376 tsk_mgmt->tsk_mgmt_func = func; 1471 tsk_mgmt->tsk_mgmt_func = func;
1377 tsk_mgmt->task_tag = req->index; 1472 tsk_mgmt->task_tag = req->index;
1378 1473
1474 ib_dma_sync_single_for_device(dev, iu->dma, sizeof *tsk_mgmt,
1475 DMA_TO_DEVICE);
1379 if (__srp_post_send(target, iu, sizeof *tsk_mgmt)) 1476 if (__srp_post_send(target, iu, sizeof *tsk_mgmt))
1380 goto out; 1477 goto out;
1381 1478
@@ -1626,9 +1723,9 @@ static struct scsi_host_template srp_template = {
1626 .eh_abort_handler = srp_abort, 1723 .eh_abort_handler = srp_abort,
1627 .eh_device_reset_handler = srp_reset_device, 1724 .eh_device_reset_handler = srp_reset_device,
1628 .eh_host_reset_handler = srp_reset_host, 1725 .eh_host_reset_handler = srp_reset_host,
1629 .can_queue = SRP_SQ_SIZE, 1726 .can_queue = SRP_CMD_SQ_SIZE,
1630 .this_id = -1, 1727 .this_id = -1,
1631 .cmd_per_lun = SRP_SQ_SIZE, 1728 .cmd_per_lun = SRP_CMD_SQ_SIZE,
1632 .use_clustering = ENABLE_CLUSTERING, 1729 .use_clustering = ENABLE_CLUSTERING,
1633 .shost_attrs = srp_host_attrs 1730 .shost_attrs = srp_host_attrs
1634}; 1731};
@@ -1813,7 +1910,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
1813 printk(KERN_WARNING PFX "bad max cmd_per_lun parameter '%s'\n", p); 1910 printk(KERN_WARNING PFX "bad max cmd_per_lun parameter '%s'\n", p);
1814 goto out; 1911 goto out;
1815 } 1912 }
1816 target->scsi_host->cmd_per_lun = min(token, SRP_SQ_SIZE); 1913 target->scsi_host->cmd_per_lun = min(token, SRP_CMD_SQ_SIZE);
1817 break; 1914 break;
1818 1915
1819 case SRP_OPT_IO_CLASS: 1916 case SRP_OPT_IO_CLASS:
@@ -1891,7 +1988,7 @@ static ssize_t srp_create_target(struct device *dev,
1891 1988
1892 INIT_LIST_HEAD(&target->free_reqs); 1989 INIT_LIST_HEAD(&target->free_reqs);
1893 INIT_LIST_HEAD(&target->req_queue); 1990 INIT_LIST_HEAD(&target->req_queue);
1894 for (i = 0; i < SRP_SQ_SIZE; ++i) { 1991 for (i = 0; i < SRP_CMD_SQ_SIZE; ++i) {
1895 target->req_ring[i].index = i; 1992 target->req_ring[i].index = i;
1896 list_add_tail(&target->req_ring[i].list, &target->free_reqs); 1993 list_add_tail(&target->req_ring[i].list, &target->free_reqs);
1897 } 1994 }
@@ -2159,6 +2256,9 @@ static int __init srp_init_module(void)
2159{ 2256{
2160 int ret; 2257 int ret;
2161 2258
2259 BUILD_BUG_ON_NOT_POWER_OF_2(SRP_SQ_SIZE);
2260 BUILD_BUG_ON_NOT_POWER_OF_2(SRP_RQ_SIZE);
2261
2162 if (srp_sg_tablesize > 255) { 2262 if (srp_sg_tablesize > 255) {
2163 printk(KERN_WARNING PFX "Clamping srp_sg_tablesize to 255\n"); 2263 printk(KERN_WARNING PFX "Clamping srp_sg_tablesize to 255\n");
2164 srp_sg_tablesize = 255; 2264 srp_sg_tablesize = 255;
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index 5a80eac6fdaa..ed0dce9e479f 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -59,7 +59,14 @@ enum {
59 59
60 SRP_RQ_SHIFT = 6, 60 SRP_RQ_SHIFT = 6,
61 SRP_RQ_SIZE = 1 << SRP_RQ_SHIFT, 61 SRP_RQ_SIZE = 1 << SRP_RQ_SHIFT,
62 SRP_SQ_SIZE = SRP_RQ_SIZE - 1, 62 SRP_RQ_MASK = SRP_RQ_SIZE - 1,
63
64 SRP_SQ_SIZE = SRP_RQ_SIZE,
65 SRP_SQ_MASK = SRP_SQ_SIZE - 1,
66 SRP_RSP_SQ_SIZE = 1,
67 SRP_REQ_SQ_SIZE = SRP_SQ_SIZE - SRP_RSP_SQ_SIZE,
68 SRP_TSK_MGMT_SQ_SIZE = 1,
69 SRP_CMD_SQ_SIZE = SRP_REQ_SQ_SIZE - SRP_TSK_MGMT_SQ_SIZE,
63 70
64 SRP_TAG_TSK_MGMT = 1 << (SRP_RQ_SHIFT + 1), 71 SRP_TAG_TSK_MGMT = 1 << (SRP_RQ_SHIFT + 1),
65 72
@@ -75,9 +82,10 @@ enum srp_target_state {
75 SRP_TARGET_REMOVED 82 SRP_TARGET_REMOVED
76}; 83};
77 84
78enum srp_request_type { 85enum srp_iu_type {
79 SRP_REQ_NORMAL, 86 SRP_IU_CMD,
80 SRP_REQ_TASK_MGMT, 87 SRP_IU_TSK_MGMT,
88 SRP_IU_RSP,
81}; 89};
82 90
83struct srp_device { 91struct srp_device {
@@ -144,11 +152,11 @@ struct srp_target_port {
144 152
145 unsigned tx_head; 153 unsigned tx_head;
146 unsigned tx_tail; 154 unsigned tx_tail;
147 struct srp_iu *tx_ring[SRP_SQ_SIZE + 1]; 155 struct srp_iu *tx_ring[SRP_SQ_SIZE];
148 156
149 struct list_head free_reqs; 157 struct list_head free_reqs;
150 struct list_head req_queue; 158 struct list_head req_queue;
151 struct srp_request req_ring[SRP_SQ_SIZE]; 159 struct srp_request req_ring[SRP_CMD_SQ_SIZE];
152 160
153 struct work_struct work; 161 struct work_struct work;
154 162
@@ -164,6 +172,7 @@ struct srp_iu {
164 void *buf; 172 void *buf;
165 size_t size; 173 size_t size;
166 enum dma_data_direction direction; 174 enum dma_data_direction direction;
175 enum srp_iu_type type;
167}; 176};
168 177
169#endif /* IB_SRP_H */ 178#endif /* IB_SRP_H */