Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

Pull more rdma updates from Doug Ledford:
"This is the second group of code for the 4.7 merge window. It looks
large, but only in one sense. I'll get to that in a minute. The list
of changes here breaks down as follows:

- Dynamic counter infrastructure in the IB drivers

This is a sysfs based code to allow free form access to the
hardware counters RDMA devices might support so drivers don't need
to code this up repeatedly themselves

- SendOnlyFullMember multicast support

- IB router support

- A couple misc fixes

- The big item on the list: hfi1 driver updates, plus moving the hfi1
driver out of staging

There was a group of 15 patches in the hfi1 list that I thought I had
in the first pull request but they weren't. So that added to the
length of the hfi1 section here.

As far as these go, everything but the hfi1 is pretty straight
forward.

The hfi1 is, if you recall, the driver that Al had complaints about
how it used the write/writev interfaces in an overloaded fashion. The
write portion of their interface behaved like the write handler in the
IB stack proper and did bi-directional communications. The writev
interface, on the other hand, only accepts SDMA request structures.
The completions for those structures are sent back via an entirely
different event mechanism.

With the security patch, we put security checks on the write
interface, however, we also knew they would be going away soon. Now,
we've converted the write handler in the hfi1 driver to use ioctls
from the IB reserved magic area for its bidirectional communications.
With that change, Intel has addressed all of the items originally on
their TODO when they went into staging (as well as many items added to
the list later).

As such, I moved them out, and since they were the last item in the
staging/rdma directory, and I don't have immediate plans to use the
staging area again, I removed the staging/rdma area.

Because of the move out of staging, as well as a series of 5 patches
in the hfi1 driver that removed code people thought should be done in
a different way and was optional to begin with (a snoop debug
interface, an eeprom driver for an eeprom connected directory to their
hfi1 chip and not via an i2c bus, and a few other things like that),
the line count, especially the removal count, is high"

* tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma: (56 commits)
staging/rdma: Remove the entire rdma subdirectory of staging
IB/core: Make device counter infrastructure dynamic
IB/hfi1: Fix pio map initialization
IB/hfi1: Correct 8051 link parameter settings
IB/hfi1: Update pkey table properly after link down or FM start
IB/rdamvt: Fix rdmavt s_ack_queue sizing
IB/rdmavt: Max atomic value should be a u8
IB/hfi1: Fix hard lockup due to not using save/restore spin lock
IB/hfi1: Add tracing support for send with invalidate opcode
IB/hfi1, qib: Add ieth to the packet header definitions
IB/hfi1: Move driver out of staging
IB/hfi1: Do not free hfi1 cdev parent structure early
IB/hfi1: Add trace message in user IOCTL handling
IB/hfi1: Remove write(), use ioctl() for user cmds
IB/hfi1: Add ioctl() interface for user commands
IB/hfi1: Remove unused user command
IB/hfi1: Remove snoop/diag interface
IB/hfi1: Remove EPROM functionality from data device
IB/hfi1: Remove UI char device
IB/hfi1: Remove multiple device cdev
...

+1992 -3406
+12
Documentation/infiniband/sysfs.txt
··· 56 56 ports/1/pkeys/10 contains the value at index 10 in port 1's P_Key 57 57 table. 58 58 59 + There is an optional "hw_counters" subdirectory that may be under either 60 + the parent device or the port subdirectories or both. If present, 61 + there are a list of counters provided by the hardware. They may match 62 + some of the counters in the counters directory, but they often include 63 + many other counters. In addition to the various counters, there will 64 + be a file named "lifespan" that configures how frequently the core 65 + should update the counters when they are being accessed (counters are 66 + not updated if they are not being accessed). The lifespan is in milli- 67 + seconds and defaults to 10 unless set to something else by the driver. 68 + Users may echo a value between 0 - 10000 to the lifespan file to set 69 + the length of time between updates in milliseconds. 70 + 59 71 MTHCA 60 72 61 73 The Mellanox HCA driver also creates the files:
+7 -7
MAINTAINERS
··· 5308 5308 F: include/linux/cciss_ioctl.h 5309 5309 F: include/uapi/linux/cciss_ioctl.h 5310 5310 5311 + HFI1 DRIVER 5312 + M: Mike Marciniszyn <mike.marciniszyn@intel.com> 5313 + M: Dennis Dalessandro <dennis.dalessandro@intel.com> 5314 + L: linux-rdma@vger.kernel.org 5315 + S: Supported 5316 + F: drivers/infiniband/hw/hfi1 5317 + 5311 5318 HFS FILESYSTEM 5312 5319 L: linux-fsdevel@vger.kernel.org 5313 5320 S: Orphan ··· 5844 5837 S: Supported 5845 5838 F: Documentation/infiniband/ 5846 5839 F: drivers/infiniband/ 5847 - F: drivers/staging/rdma/ 5848 5840 F: include/uapi/linux/if_infiniband.h 5849 5841 F: include/uapi/rdma/ 5850 5842 F: include/rdma/ ··· 10925 10919 M: Arnaud Patard <arnaud.patard@rtp-net.org> 10926 10920 S: Odd Fixes 10927 10921 F: drivers/staging/xgifb/ 10928 - 10929 - HFI1 DRIVER 10930 - M: Mike Marciniszyn <infinipath@intel.com> 10931 - L: linux-rdma@vger.kernel.org 10932 - S: Supported 10933 - F: drivers/staging/rdma/hfi1 10934 10922 10935 10923 STARFIRE/DURALAN NETWORK DRIVER 10936 10924 M: Ion Badulescu <ionut@badula.org>
+2
drivers/infiniband/Kconfig
··· 85 85 86 86 source "drivers/infiniband/sw/rdmavt/Kconfig" 87 87 88 + source "drivers/infiniband/hw/hfi1/Kconfig" 89 + 88 90 endif # INFINIBAND
+3 -9
drivers/infiniband/core/Makefile
··· 1 1 infiniband-$(CONFIG_INFINIBAND_ADDR_TRANS) := rdma_cm.o 2 2 user_access-$(CONFIG_INFINIBAND_ADDR_TRANS) := rdma_ucm.o 3 3 4 - obj-$(CONFIG_INFINIBAND) += ib_core.o ib_mad.o ib_sa.o \ 5 - ib_cm.o iw_cm.o ib_addr.o \ 4 + obj-$(CONFIG_INFINIBAND) += ib_core.o ib_cm.o iw_cm.o \ 6 5 $(infiniband-y) 7 6 obj-$(CONFIG_INFINIBAND_USER_MAD) += ib_umad.o 8 7 obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o \ ··· 9 10 10 11 ib_core-y := packer.o ud_header.o verbs.o cq.o rw.o sysfs.o \ 11 12 device.o fmr_pool.o cache.o netlink.o \ 12 - roce_gid_mgmt.o mr_pool.o 13 + roce_gid_mgmt.o mr_pool.o addr.o sa_query.o \ 14 + multicast.o mad.o smi.o agent.o mad_rmpp.o 13 15 ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o 14 16 ib_core-$(CONFIG_INFINIBAND_ON_DEMAND_PAGING) += umem_odp.o umem_rbtree.o 15 - 16 - ib_mad-y := mad.o smi.o agent.o mad_rmpp.o 17 - 18 - ib_sa-y := sa_query.o multicast.o 19 17 20 18 ib_cm-y := cm.o 21 19 ··· 23 27 rdma_cm-$(CONFIG_INFINIBAND_ADDR_TRANS_CONFIGFS) += cma_configfs.o 24 28 25 29 rdma_ucm-y := ucma.o 26 - 27 - ib_addr-y := addr.o 28 30 29 31 ib_umad-y := user_mad.o 30 32
+194 -32
drivers/infiniband/core/addr.c
··· 46 46 #include <net/ip6_route.h> 47 47 #include <rdma/ib_addr.h> 48 48 #include <rdma/ib.h> 49 + #include <rdma/rdma_netlink.h> 50 + #include <net/netlink.h> 49 51 50 - MODULE_AUTHOR("Sean Hefty"); 51 - MODULE_DESCRIPTION("IB Address Translation"); 52 - MODULE_LICENSE("Dual BSD/GPL"); 52 + #include "core_priv.h" 53 53 54 54 struct addr_req { 55 55 struct list_head list; ··· 62 62 struct rdma_dev_addr *addr, void *context); 63 63 unsigned long timeout; 64 64 int status; 65 + u32 seq; 65 66 }; 67 + 68 + static atomic_t ib_nl_addr_request_seq = ATOMIC_INIT(0); 66 69 67 70 static void process_req(struct work_struct *work); 68 71 ··· 73 70 static LIST_HEAD(req_list); 74 71 static DECLARE_DELAYED_WORK(work, process_req); 75 72 static struct workqueue_struct *addr_wq; 73 + 74 + static const struct nla_policy ib_nl_addr_policy[LS_NLA_TYPE_MAX] = { 75 + [LS_NLA_TYPE_DGID] = {.type = NLA_BINARY, 76 + .len = sizeof(struct rdma_nla_ls_gid)}, 77 + }; 78 + 79 + static inline bool ib_nl_is_good_ip_resp(const struct nlmsghdr *nlh) 80 + { 81 + struct nlattr *tb[LS_NLA_TYPE_MAX] = {}; 82 + int ret; 83 + 84 + if (nlh->nlmsg_flags & RDMA_NL_LS_F_ERR) 85 + return false; 86 + 87 + ret = nla_parse(tb, LS_NLA_TYPE_MAX - 1, nlmsg_data(nlh), 88 + nlmsg_len(nlh), ib_nl_addr_policy); 89 + if (ret) 90 + return false; 91 + 92 + return true; 93 + } 94 + 95 + static void ib_nl_process_good_ip_rsep(const struct nlmsghdr *nlh) 96 + { 97 + const struct nlattr *head, *curr; 98 + union ib_gid gid; 99 + struct addr_req *req; 100 + int len, rem; 101 + int found = 0; 102 + 103 + head = (const struct nlattr *)nlmsg_data(nlh); 104 + len = nlmsg_len(nlh); 105 + 106 + nla_for_each_attr(curr, head, len, rem) { 107 + if (curr->nla_type == LS_NLA_TYPE_DGID) 108 + memcpy(&gid, nla_data(curr), nla_len(curr)); 109 + } 110 + 111 + mutex_lock(&lock); 112 + list_for_each_entry(req, &req_list, list) { 113 + if (nlh->nlmsg_seq != req->seq) 114 + continue; 115 + /* We set the DGID part, the rest was set earlier */ 116 + rdma_addr_set_dgid(req->addr, &gid); 117 + req->status = 0; 118 + found = 1; 119 + break; 120 + } 121 + mutex_unlock(&lock); 122 + 123 + if (!found) 124 + pr_info("Couldn't find request waiting for DGID: %pI6\n", 125 + &gid); 126 + } 127 + 128 + int ib_nl_handle_ip_res_resp(struct sk_buff *skb, 129 + struct netlink_callback *cb) 130 + { 131 + const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh; 132 + 133 + if ((nlh->nlmsg_flags & NLM_F_REQUEST) || 134 + !(NETLINK_CB(skb).sk) || 135 + !netlink_capable(skb, CAP_NET_ADMIN)) 136 + return -EPERM; 137 + 138 + if (ib_nl_is_good_ip_resp(nlh)) 139 + ib_nl_process_good_ip_rsep(nlh); 140 + 141 + return skb->len; 142 + } 143 + 144 + static int ib_nl_ip_send_msg(struct rdma_dev_addr *dev_addr, 145 + const void *daddr, 146 + u32 seq, u16 family) 147 + { 148 + struct sk_buff *skb = NULL; 149 + struct nlmsghdr *nlh; 150 + struct rdma_ls_ip_resolve_header *header; 151 + void *data; 152 + size_t size; 153 + int attrtype; 154 + int len; 155 + 156 + if (family == AF_INET) { 157 + size = sizeof(struct in_addr); 158 + attrtype = RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_IPV4; 159 + } else { 160 + size = sizeof(struct in6_addr); 161 + attrtype = RDMA_NLA_F_MANDATORY | LS_NLA_TYPE_IPV6; 162 + } 163 + 164 + len = nla_total_size(sizeof(size)); 165 + len += NLMSG_ALIGN(sizeof(*header)); 166 + 167 + skb = nlmsg_new(len, GFP_KERNEL); 168 + if (!skb) 169 + return -ENOMEM; 170 + 171 + data = ibnl_put_msg(skb, &nlh, seq, 0, RDMA_NL_LS, 172 + RDMA_NL_LS_OP_IP_RESOLVE, NLM_F_REQUEST); 173 + if (!data) { 174 + nlmsg_free(skb); 175 + return -ENODATA; 176 + } 177 + 178 + /* Construct the family header first */ 179 + header = (struct rdma_ls_ip_resolve_header *) 180 + skb_put(skb, NLMSG_ALIGN(sizeof(*header))); 181 + header->ifindex = dev_addr->bound_dev_if; 182 + nla_put(skb, attrtype, size, daddr); 183 + 184 + /* Repair the nlmsg header length */ 185 + nlmsg_end(skb, nlh); 186 + ibnl_multicast(skb, nlh, RDMA_NL_GROUP_LS, GFP_KERNEL); 187 + 188 + /* Make the request retry, so when we get the response from userspace 189 + * we will have something. 190 + */ 191 + return -ENODATA; 192 + } 76 193 77 194 int rdma_addr_size(struct sockaddr *addr) 78 195 { ··· 322 199 mutex_unlock(&lock); 323 200 } 324 201 202 + static int ib_nl_fetch_ha(struct dst_entry *dst, struct rdma_dev_addr *dev_addr, 203 + const void *daddr, u32 seq, u16 family) 204 + { 205 + if (ibnl_chk_listeners(RDMA_NL_GROUP_LS)) 206 + return -EADDRNOTAVAIL; 207 + 208 + /* We fill in what we can, the response will fill the rest */ 209 + rdma_copy_addr(dev_addr, dst->dev, NULL); 210 + return ib_nl_ip_send_msg(dev_addr, daddr, seq, family); 211 + } 212 + 325 213 static int dst_fetch_ha(struct dst_entry *dst, struct rdma_dev_addr *dev_addr, 326 214 const void *daddr) 327 215 { ··· 355 221 neigh_release(n); 356 222 357 223 return ret; 224 + } 225 + 226 + static bool has_gateway(struct dst_entry *dst, sa_family_t family) 227 + { 228 + struct rtable *rt; 229 + struct rt6_info *rt6; 230 + 231 + if (family == AF_INET) { 232 + rt = container_of(dst, struct rtable, dst); 233 + return rt->rt_uses_gateway; 234 + } 235 + 236 + rt6 = container_of(dst, struct rt6_info, dst); 237 + return rt6->rt6i_flags & RTF_GATEWAY; 238 + } 239 + 240 + static int fetch_ha(struct dst_entry *dst, struct rdma_dev_addr *dev_addr, 241 + const struct sockaddr *dst_in, u32 seq) 242 + { 243 + const struct sockaddr_in *dst_in4 = 244 + (const struct sockaddr_in *)dst_in; 245 + const struct sockaddr_in6 *dst_in6 = 246 + (const struct sockaddr_in6 *)dst_in; 247 + const void *daddr = (dst_in->sa_family == AF_INET) ? 248 + (const void *)&dst_in4->sin_addr.s_addr : 249 + (const void *)&dst_in6->sin6_addr; 250 + sa_family_t family = dst_in->sa_family; 251 + 252 + /* Gateway + ARPHRD_INFINIBAND -> IB router */ 253 + if (has_gateway(dst, family) && dst->dev->type == ARPHRD_INFINIBAND) 254 + return ib_nl_fetch_ha(dst, dev_addr, daddr, seq, family); 255 + else 256 + return dst_fetch_ha(dst, dev_addr, daddr); 358 257 } 359 258 360 259 static int addr4_resolve(struct sockaddr_in *src_in, ··· 413 246 src_in->sin_family = AF_INET; 414 247 src_in->sin_addr.s_addr = fl4.saddr; 415 248 416 - /* If there's a gateway, we're definitely in RoCE v2 (as RoCE v1 isn't 417 - * routable) and we could set the network type accordingly. 249 + /* If there's a gateway and type of device not ARPHRD_INFINIBAND, we're 250 + * definitely in RoCE v2 (as RoCE v1 isn't routable) set the network 251 + * type accordingly. 418 252 */ 419 - if (rt->rt_uses_gateway) 253 + if (rt->rt_uses_gateway && rt->dst.dev->type != ARPHRD_INFINIBAND) 420 254 addr->network = RDMA_NETWORK_IPV4; 421 255 422 256 addr->hoplimit = ip4_dst_hoplimit(&rt->dst); ··· 459 291 src_in->sin6_addr = fl6.saddr; 460 292 } 461 293 462 - /* If there's a gateway, we're definitely in RoCE v2 (as RoCE v1 isn't 463 - * routable) and we could set the network type accordingly. 294 + /* If there's a gateway and type of device not ARPHRD_INFINIBAND, we're 295 + * definitely in RoCE v2 (as RoCE v1 isn't routable) set the network 296 + * type accordingly. 464 297 */ 465 - if (rt->rt6i_flags & RTF_GATEWAY) 298 + if (rt->rt6i_flags & RTF_GATEWAY && 299 + ip6_dst_idev(dst)->dev->type != ARPHRD_INFINIBAND) 466 300 addr->network = RDMA_NETWORK_IPV6; 467 301 468 302 addr->hoplimit = ip6_dst_hoplimit(dst); ··· 487 317 488 318 static int addr_resolve_neigh(struct dst_entry *dst, 489 319 const struct sockaddr *dst_in, 490 - struct rdma_dev_addr *addr) 320 + struct rdma_dev_addr *addr, 321 + u32 seq) 491 322 { 492 323 if (dst->dev->flags & IFF_LOOPBACK) { 493 324 int ret; ··· 502 331 } 503 332 504 333 /* If the device doesn't do ARP internally */ 505 - if (!(dst->dev->flags & IFF_NOARP)) { 506 - const struct sockaddr_in *dst_in4 = 507 - (const struct sockaddr_in *)dst_in; 508 - const struct sockaddr_in6 *dst_in6 = 509 - (const struct sockaddr_in6 *)dst_in; 510 - 511 - return dst_fetch_ha(dst, addr, 512 - dst_in->sa_family == AF_INET ? 513 - (const void *)&dst_in4->sin_addr.s_addr : 514 - (const void *)&dst_in6->sin6_addr); 515 - } 334 + if (!(dst->dev->flags & IFF_NOARP)) 335 + return fetch_ha(dst, addr, dst_in, seq); 516 336 517 337 return rdma_copy_addr(addr, dst->dev, NULL); 518 338 } ··· 511 349 static int addr_resolve(struct sockaddr *src_in, 512 350 const struct sockaddr *dst_in, 513 351 struct rdma_dev_addr *addr, 514 - bool resolve_neigh) 352 + bool resolve_neigh, 353 + u32 seq) 515 354 { 516 355 struct net_device *ndev; 517 356 struct dst_entry *dst; ··· 529 366 return ret; 530 367 531 368 if (resolve_neigh) 532 - ret = addr_resolve_neigh(&rt->dst, dst_in, addr); 369 + ret = addr_resolve_neigh(&rt->dst, dst_in, addr, seq); 533 370 534 371 ndev = rt->dst.dev; 535 372 dev_hold(ndev); ··· 546 383 return ret; 547 384 548 385 if (resolve_neigh) 549 - ret = addr_resolve_neigh(dst, dst_in, addr); 386 + ret = addr_resolve_neigh(dst, dst_in, addr, seq); 550 387 551 388 ndev = dst->dev; 552 389 dev_hold(ndev); ··· 575 412 src_in = (struct sockaddr *) &req->src_addr; 576 413 dst_in = (struct sockaddr *) &req->dst_addr; 577 414 req->status = addr_resolve(src_in, dst_in, req->addr, 578 - true); 415 + true, req->seq); 579 416 if (req->status && time_after_eq(jiffies, req->timeout)) 580 417 req->status = -ETIMEDOUT; 581 418 else if (req->status == -ENODATA) ··· 634 471 req->context = context; 635 472 req->client = client; 636 473 atomic_inc(&client->refcount); 474 + req->seq = (u32)atomic_inc_return(&ib_nl_addr_request_seq); 637 475 638 - req->status = addr_resolve(src_in, dst_in, addr, true); 476 + req->status = addr_resolve(src_in, dst_in, addr, true, req->seq); 639 477 switch (req->status) { 640 478 case 0: 641 479 req->timeout = jiffies; ··· 674 510 src_in->sa_family = dst_addr->sa_family; 675 511 } 676 512 677 - return addr_resolve(src_in, dst_addr, addr, false); 513 + return addr_resolve(src_in, dst_addr, addr, false, 0); 678 514 } 679 515 EXPORT_SYMBOL(rdma_resolve_ip_route); 680 516 ··· 798 634 .notifier_call = netevent_callback 799 635 }; 800 636 801 - static int __init addr_init(void) 637 + int addr_init(void) 802 638 { 803 639 addr_wq = create_singlethread_workqueue("ib_addr"); 804 640 if (!addr_wq) ··· 806 642 807 643 register_netevent_notifier(&nb); 808 644 rdma_addr_register_client(&self); 645 + 809 646 return 0; 810 647 } 811 648 812 - static void __exit addr_cleanup(void) 649 + void addr_cleanup(void) 813 650 { 814 651 rdma_addr_unregister_client(&self); 815 652 unregister_netevent_notifier(&nb); 816 653 destroy_workqueue(addr_wq); 817 654 } 818 - 819 - module_init(addr_init); 820 - module_exit(addr_cleanup);
+16
drivers/infiniband/core/core_priv.h
··· 137 137 return _upper == upper; 138 138 } 139 139 140 + int addr_init(void); 141 + void addr_cleanup(void); 142 + 143 + int ib_mad_init(void); 144 + void ib_mad_cleanup(void); 145 + 146 + int ib_sa_init(void); 147 + void ib_sa_cleanup(void); 148 + 149 + int ib_nl_handle_resolve_resp(struct sk_buff *skb, 150 + struct netlink_callback *cb); 151 + int ib_nl_handle_set_timeout(struct sk_buff *skb, 152 + struct netlink_callback *cb); 153 + int ib_nl_handle_ip_res_resp(struct sk_buff *skb, 154 + struct netlink_callback *cb); 155 + 140 156 #endif /* _CORE_PRIV_H */
+58
drivers/infiniband/core/device.c
··· 955 955 } 956 956 EXPORT_SYMBOL(ib_get_net_dev_by_params); 957 957 958 + static struct ibnl_client_cbs ibnl_ls_cb_table[] = { 959 + [RDMA_NL_LS_OP_RESOLVE] = { 960 + .dump = ib_nl_handle_resolve_resp, 961 + .module = THIS_MODULE }, 962 + [RDMA_NL_LS_OP_SET_TIMEOUT] = { 963 + .dump = ib_nl_handle_set_timeout, 964 + .module = THIS_MODULE }, 965 + [RDMA_NL_LS_OP_IP_RESOLVE] = { 966 + .dump = ib_nl_handle_ip_res_resp, 967 + .module = THIS_MODULE }, 968 + }; 969 + 970 + static int ib_add_ibnl_clients(void) 971 + { 972 + return ibnl_add_client(RDMA_NL_LS, ARRAY_SIZE(ibnl_ls_cb_table), 973 + ibnl_ls_cb_table); 974 + } 975 + 976 + static void ib_remove_ibnl_clients(void) 977 + { 978 + ibnl_remove_client(RDMA_NL_LS); 979 + } 980 + 958 981 static int __init ib_core_init(void) 959 982 { 960 983 int ret; ··· 1006 983 goto err_sysfs; 1007 984 } 1008 985 986 + ret = addr_init(); 987 + if (ret) { 988 + pr_warn("Could't init IB address resolution\n"); 989 + goto err_ibnl; 990 + } 991 + 992 + ret = ib_mad_init(); 993 + if (ret) { 994 + pr_warn("Couldn't init IB MAD\n"); 995 + goto err_addr; 996 + } 997 + 998 + ret = ib_sa_init(); 999 + if (ret) { 1000 + pr_warn("Couldn't init SA\n"); 1001 + goto err_mad; 1002 + } 1003 + 1004 + if (ib_add_ibnl_clients()) { 1005 + pr_warn("Couldn't register ibnl clients\n"); 1006 + goto err_sa; 1007 + } 1008 + 1009 1009 ib_cache_setup(); 1010 1010 1011 1011 return 0; 1012 1012 1013 + err_sa: 1014 + ib_sa_cleanup(); 1015 + err_mad: 1016 + ib_mad_cleanup(); 1017 + err_addr: 1018 + addr_cleanup(); 1019 + err_ibnl: 1020 + ibnl_cleanup(); 1013 1021 err_sysfs: 1014 1022 class_unregister(&ib_class); 1015 1023 err_comp: ··· 1053 999 static void __exit ib_core_cleanup(void) 1054 1000 { 1055 1001 ib_cache_cleanup(); 1002 + ib_remove_ibnl_clients(); 1003 + ib_sa_cleanup(); 1004 + ib_mad_cleanup(); 1005 + addr_cleanup(); 1056 1006 ibnl_cleanup(); 1057 1007 class_unregister(&ib_class); 1058 1008 destroy_workqueue(ib_comp_wq);
+3 -10
drivers/infiniband/core/mad.c
··· 47 47 #include "smi.h" 48 48 #include "opa_smi.h" 49 49 #include "agent.h" 50 - 51 - MODULE_LICENSE("Dual BSD/GPL"); 52 - MODULE_DESCRIPTION("kernel IB MAD API"); 53 - MODULE_AUTHOR("Hal Rosenstock"); 54 - MODULE_AUTHOR("Sean Hefty"); 50 + #include "core_priv.h" 55 51 56 52 static int mad_sendq_size = IB_MAD_QP_SEND_SIZE; 57 53 static int mad_recvq_size = IB_MAD_QP_RECV_SIZE; ··· 3312 3316 .remove = ib_mad_remove_device 3313 3317 }; 3314 3318 3315 - static int __init ib_mad_init_module(void) 3319 + int ib_mad_init(void) 3316 3320 { 3317 3321 mad_recvq_size = min(mad_recvq_size, IB_MAD_QP_MAX_SIZE); 3318 3322 mad_recvq_size = max(mad_recvq_size, IB_MAD_QP_MIN_SIZE); ··· 3330 3334 return 0; 3331 3335 } 3332 3336 3333 - static void __exit ib_mad_cleanup_module(void) 3337 + void ib_mad_cleanup(void) 3334 3338 { 3335 3339 ib_unregister_client(&mad_client); 3336 3340 } 3337 - 3338 - module_init(ib_mad_init_module); 3339 - module_exit(ib_mad_cleanup_module);
+18 -5
drivers/infiniband/core/multicast.c
··· 93 93 94 94 struct mcast_member; 95 95 96 + /* 97 + * There are 4 types of join states: 98 + * FullMember, NonMember, SendOnlyNonMember, SendOnlyFullMember. 99 + */ 100 + enum { 101 + FULLMEMBER_JOIN, 102 + NONMEMBER_JOIN, 103 + SENDONLY_NONMEBER_JOIN, 104 + SENDONLY_FULLMEMBER_JOIN, 105 + NUM_JOIN_MEMBERSHIP_TYPES, 106 + }; 107 + 96 108 struct mcast_group { 97 109 struct ib_sa_mcmember_rec rec; 98 110 struct rb_node node; ··· 114 102 struct list_head pending_list; 115 103 struct list_head active_list; 116 104 struct mcast_member *last_join; 117 - int members[3]; 105 + int members[NUM_JOIN_MEMBERSHIP_TYPES]; 118 106 atomic_t refcount; 119 107 enum mcast_group_state state; 120 108 struct ib_sa_query *query; ··· 232 220 } 233 221 234 222 /* 235 - * A multicast group has three types of members: full member, non member, and 236 - * send only member. We need to keep track of the number of members of each 223 + * A multicast group has four types of members: full member, non member, 224 + * sendonly non member and sendonly full member. 225 + * We need to keep track of the number of members of each 237 226 * type based on their join state. Adjust the number of members the belong to 238 227 * the specified join states. 239 228 */ ··· 242 229 { 243 230 int i; 244 231 245 - for (i = 0; i < 3; i++, join_state >>= 1) 232 + for (i = 0; i < NUM_JOIN_MEMBERSHIP_TYPES; i++, join_state >>= 1) 246 233 if (join_state & 0x1) 247 234 group->members[i] += inc; 248 235 } ··· 258 245 u8 leave_state = 0; 259 246 int i; 260 247 261 - for (i = 0; i < 3; i++) 248 + for (i = 0; i < NUM_JOIN_MEMBERSHIP_TYPES; i++) 262 249 if (!group->members[i]) 263 250 leave_state |= (0x1 << i); 264 251
+180 -31
drivers/infiniband/core/sa_query.c
··· 53 53 #include "sa.h" 54 54 #include "core_priv.h" 55 55 56 - MODULE_AUTHOR("Roland Dreier"); 57 - MODULE_DESCRIPTION("InfiniBand subnet administration query support"); 58 - MODULE_LICENSE("Dual BSD/GPL"); 59 - 60 56 #define IB_SA_LOCAL_SVC_TIMEOUT_MIN 100 61 57 #define IB_SA_LOCAL_SVC_TIMEOUT_DEFAULT 2000 62 58 #define IB_SA_LOCAL_SVC_TIMEOUT_MAX 200000 ··· 111 115 112 116 struct ib_sa_guidinfo_query { 113 117 void (*callback)(int, struct ib_sa_guidinfo_rec *, void *); 118 + void *context; 119 + struct ib_sa_query sa_query; 120 + }; 121 + 122 + struct ib_sa_classport_info_query { 123 + void (*callback)(int, struct ib_class_port_info *, void *); 114 124 void *context; 115 125 struct ib_sa_query sa_query; 116 126 }; ··· 392 390 .offset_words = 40, 393 391 .offset_bits = 0, 394 392 .size_bits = 2*64 }, 393 + }; 394 + 395 + #define CLASSPORTINFO_REC_FIELD(field) \ 396 + .struct_offset_bytes = offsetof(struct ib_class_port_info, field), \ 397 + .struct_size_bytes = sizeof((struct ib_class_port_info *)0)->field, \ 398 + .field_name = "ib_class_port_info:" #field 399 + 400 + static const struct ib_field classport_info_rec_table[] = { 401 + { CLASSPORTINFO_REC_FIELD(base_version), 402 + .offset_words = 0, 403 + .offset_bits = 0, 404 + .size_bits = 8 }, 405 + { CLASSPORTINFO_REC_FIELD(class_version), 406 + .offset_words = 0, 407 + .offset_bits = 8, 408 + .size_bits = 8 }, 409 + { CLASSPORTINFO_REC_FIELD(capability_mask), 410 + .offset_words = 0, 411 + .offset_bits = 16, 412 + .size_bits = 16 }, 413 + { CLASSPORTINFO_REC_FIELD(cap_mask2_resp_time), 414 + .offset_words = 1, 415 + .offset_bits = 0, 416 + .size_bits = 32 }, 417 + { CLASSPORTINFO_REC_FIELD(redirect_gid), 418 + .offset_words = 2, 419 + .offset_bits = 0, 420 + .size_bits = 128 }, 421 + { CLASSPORTINFO_REC_FIELD(redirect_tcslfl), 422 + .offset_words = 6, 423 + .offset_bits = 0, 424 + .size_bits = 32 }, 425 + { CLASSPORTINFO_REC_FIELD(redirect_lid), 426 + .offset_words = 7, 427 + .offset_bits = 0, 428 + .size_bits = 16 }, 429 + { CLASSPORTINFO_REC_FIELD(redirect_pkey), 430 + .offset_words = 7, 431 + .offset_bits = 16, 432 + .size_bits = 16 }, 433 + 434 + { CLASSPORTINFO_REC_FIELD(redirect_qp), 435 + .offset_words = 8, 436 + .offset_bits = 0, 437 + .size_bits = 32 }, 438 + { CLASSPORTINFO_REC_FIELD(redirect_qkey), 439 + .offset_words = 9, 440 + .offset_bits = 0, 441 + .size_bits = 32 }, 442 + 443 + { CLASSPORTINFO_REC_FIELD(trap_gid), 444 + .offset_words = 10, 445 + .offset_bits = 0, 446 + .size_bits = 128 }, 447 + { CLASSPORTINFO_REC_FIELD(trap_tcslfl), 448 + .offset_words = 14, 449 + .offset_bits = 0, 450 + .size_bits = 32 }, 451 + 452 + { CLASSPORTINFO_REC_FIELD(trap_lid), 453 + .offset_words = 15, 454 + .offset_bits = 0, 455 + .size_bits = 16 }, 456 + { CLASSPORTINFO_REC_FIELD(trap_pkey), 457 + .offset_words = 15, 458 + .offset_bits = 16, 459 + .size_bits = 16 }, 460 + 461 + { CLASSPORTINFO_REC_FIELD(trap_hlqp), 462 + .offset_words = 16, 463 + .offset_bits = 0, 464 + .size_bits = 32 }, 465 + { CLASSPORTINFO_REC_FIELD(trap_qkey), 466 + .offset_words = 17, 467 + .offset_bits = 0, 468 + .size_bits = 32 }, 395 469 }; 396 470 397 471 #define GUIDINFO_REC_FIELD(field) \ ··· 783 705 spin_unlock_irqrestore(&ib_nl_request_lock, flags); 784 706 } 785 707 786 - static int ib_nl_handle_set_timeout(struct sk_buff *skb, 787 - struct netlink_callback *cb) 708 + int ib_nl_handle_set_timeout(struct sk_buff *skb, 709 + struct netlink_callback *cb) 788 710 { 789 711 const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh; 790 712 int timeout, delta, abs_delta; ··· 860 782 return 1; 861 783 } 862 784 863 - static int ib_nl_handle_resolve_resp(struct sk_buff *skb, 864 - struct netlink_callback *cb) 785 + int ib_nl_handle_resolve_resp(struct sk_buff *skb, 786 + struct netlink_callback *cb) 865 787 { 866 788 const struct nlmsghdr *nlh = (struct nlmsghdr *)cb->nlh; 867 789 unsigned long flags; ··· 915 837 resp_out: 916 838 return skb->len; 917 839 } 918 - 919 - static struct ibnl_client_cbs ib_sa_cb_table[] = { 920 - [RDMA_NL_LS_OP_RESOLVE] = { 921 - .dump = ib_nl_handle_resolve_resp, 922 - .module = THIS_MODULE }, 923 - [RDMA_NL_LS_OP_SET_TIMEOUT] = { 924 - .dump = ib_nl_handle_set_timeout, 925 - .module = THIS_MODULE }, 926 - }; 927 840 928 841 static void free_sm_ah(struct kref *kref) 929 842 { ··· 1714 1645 } 1715 1646 EXPORT_SYMBOL(ib_sa_guid_info_rec_query); 1716 1647 1648 + /* Support get SA ClassPortInfo */ 1649 + static void ib_sa_classport_info_rec_callback(struct ib_sa_query *sa_query, 1650 + int status, 1651 + struct ib_sa_mad *mad) 1652 + { 1653 + struct ib_sa_classport_info_query *query = 1654 + container_of(sa_query, struct ib_sa_classport_info_query, sa_query); 1655 + 1656 + if (mad) { 1657 + struct ib_class_port_info rec; 1658 + 1659 + ib_unpack(classport_info_rec_table, 1660 + ARRAY_SIZE(classport_info_rec_table), 1661 + mad->data, &rec); 1662 + query->callback(status, &rec, query->context); 1663 + } else { 1664 + query->callback(status, NULL, query->context); 1665 + } 1666 + } 1667 + 1668 + static void ib_sa_portclass_info_rec_release(struct ib_sa_query *sa_query) 1669 + { 1670 + kfree(container_of(sa_query, struct ib_sa_classport_info_query, 1671 + sa_query)); 1672 + } 1673 + 1674 + int ib_sa_classport_info_rec_query(struct ib_sa_client *client, 1675 + struct ib_device *device, u8 port_num, 1676 + int timeout_ms, gfp_t gfp_mask, 1677 + void (*callback)(int status, 1678 + struct ib_class_port_info *resp, 1679 + void *context), 1680 + void *context, 1681 + struct ib_sa_query **sa_query) 1682 + { 1683 + struct ib_sa_classport_info_query *query; 1684 + struct ib_sa_device *sa_dev = ib_get_client_data(device, &sa_client); 1685 + struct ib_sa_port *port; 1686 + struct ib_mad_agent *agent; 1687 + struct ib_sa_mad *mad; 1688 + int ret; 1689 + 1690 + if (!sa_dev) 1691 + return -ENODEV; 1692 + 1693 + port = &sa_dev->port[port_num - sa_dev->start_port]; 1694 + agent = port->agent; 1695 + 1696 + query = kzalloc(sizeof(*query), gfp_mask); 1697 + if (!query) 1698 + return -ENOMEM; 1699 + 1700 + query->sa_query.port = port; 1701 + ret = alloc_mad(&query->sa_query, gfp_mask); 1702 + if (ret) 1703 + goto err1; 1704 + 1705 + ib_sa_client_get(client); 1706 + query->sa_query.client = client; 1707 + query->callback = callback; 1708 + query->context = context; 1709 + 1710 + mad = query->sa_query.mad_buf->mad; 1711 + init_mad(mad, agent); 1712 + 1713 + query->sa_query.callback = callback ? ib_sa_classport_info_rec_callback : NULL; 1714 + 1715 + query->sa_query.release = ib_sa_portclass_info_rec_release; 1716 + /* support GET only */ 1717 + mad->mad_hdr.method = IB_MGMT_METHOD_GET; 1718 + mad->mad_hdr.attr_id = cpu_to_be16(IB_SA_ATTR_CLASS_PORTINFO); 1719 + mad->sa_hdr.comp_mask = 0; 1720 + *sa_query = &query->sa_query; 1721 + 1722 + ret = send_mad(&query->sa_query, timeout_ms, gfp_mask); 1723 + if (ret < 0) 1724 + goto err2; 1725 + 1726 + return ret; 1727 + 1728 + err2: 1729 + *sa_query = NULL; 1730 + ib_sa_client_put(query->sa_query.client); 1731 + free_mad(&query->sa_query); 1732 + 1733 + err1: 1734 + kfree(query); 1735 + return ret; 1736 + } 1737 + EXPORT_SYMBOL(ib_sa_classport_info_rec_query); 1738 + 1717 1739 static void send_handler(struct ib_mad_agent *agent, 1718 1740 struct ib_mad_send_wc *mad_send_wc) 1719 1741 { ··· 1954 1794 kfree(sa_dev); 1955 1795 } 1956 1796 1957 - static int __init ib_sa_init(void) 1797 + int ib_sa_init(void) 1958 1798 { 1959 1799 int ret; 1960 1800 ··· 1980 1820 goto err3; 1981 1821 } 1982 1822 1983 - if (ibnl_add_client(RDMA_NL_LS, ARRAY_SIZE(ib_sa_cb_table), 1984 - ib_sa_cb_table)) { 1985 - pr_err("Failed to add netlink callback\n"); 1986 - ret = -EINVAL; 1987 - goto err4; 1988 - } 1989 1823 INIT_DELAYED_WORK(&ib_nl_timed_work, ib_nl_request_timeout); 1990 1824 1991 1825 return 0; 1992 - err4: 1993 - destroy_workqueue(ib_nl_wq); 1826 + 1994 1827 err3: 1995 1828 mcast_cleanup(); 1996 1829 err2: ··· 1992 1839 return ret; 1993 1840 } 1994 1841 1995 - static void __exit ib_sa_cleanup(void) 1842 + void ib_sa_cleanup(void) 1996 1843 { 1997 - ibnl_remove_client(RDMA_NL_LS); 1998 1844 cancel_delayed_work(&ib_nl_timed_work); 1999 1845 flush_workqueue(ib_nl_wq); 2000 1846 destroy_workqueue(ib_nl_wq); ··· 2001 1849 ib_unregister_client(&sa_client); 2002 1850 idr_destroy(&query_idr); 2003 1851 } 2004 - 2005 - module_init(ib_sa_init); 2006 - module_exit(ib_sa_cleanup);
+242 -124
drivers/infiniband/core/sysfs.c
··· 56 56 struct gid_attr_group *gid_attr_group; 57 57 struct attribute_group gid_group; 58 58 struct attribute_group pkey_group; 59 - u8 port_num; 60 59 struct attribute_group *pma_table; 60 + struct attribute_group *hw_stats_ag; 61 + struct rdma_hw_stats *hw_stats; 62 + u8 port_num; 61 63 }; 62 64 63 65 struct port_attribute { ··· 80 78 char name[8]; 81 79 int index; 82 80 __be16 attr_id; 81 + }; 82 + 83 + struct hw_stats_attribute { 84 + struct attribute attr; 85 + ssize_t (*show)(struct kobject *kobj, 86 + struct attribute *attr, char *buf); 87 + ssize_t (*store)(struct kobject *kobj, 88 + struct attribute *attr, 89 + const char *buf, 90 + size_t count); 91 + int index; 92 + u8 port_num; 83 93 }; 84 94 85 95 static ssize_t port_attr_show(struct kobject *kobj, ··· 747 733 return &pma_group; 748 734 } 749 735 736 + static int update_hw_stats(struct ib_device *dev, struct rdma_hw_stats *stats, 737 + u8 port_num, int index) 738 + { 739 + int ret; 740 + 741 + if (time_is_after_eq_jiffies(stats->timestamp + stats->lifespan)) 742 + return 0; 743 + ret = dev->get_hw_stats(dev, stats, port_num, index); 744 + if (ret < 0) 745 + return ret; 746 + if (ret == stats->num_counters) 747 + stats->timestamp = jiffies; 748 + 749 + return 0; 750 + } 751 + 752 + static ssize_t print_hw_stat(struct rdma_hw_stats *stats, int index, char *buf) 753 + { 754 + return sprintf(buf, "%llu\n", stats->value[index]); 755 + } 756 + 757 + static ssize_t show_hw_stats(struct kobject *kobj, struct attribute *attr, 758 + char *buf) 759 + { 760 + struct ib_device *dev; 761 + struct ib_port *port; 762 + struct hw_stats_attribute *hsa; 763 + struct rdma_hw_stats *stats; 764 + int ret; 765 + 766 + hsa = container_of(attr, struct hw_stats_attribute, attr); 767 + if (!hsa->port_num) { 768 + dev = container_of((struct device *)kobj, 769 + struct ib_device, dev); 770 + stats = dev->hw_stats; 771 + } else { 772 + port = container_of(kobj, struct ib_port, kobj); 773 + dev = port->ibdev; 774 + stats = port->hw_stats; 775 + } 776 + ret = update_hw_stats(dev, stats, hsa->port_num, hsa->index); 777 + if (ret) 778 + return ret; 779 + return print_hw_stat(stats, hsa->index, buf); 780 + } 781 + 782 + static ssize_t show_stats_lifespan(struct kobject *kobj, 783 + struct attribute *attr, 784 + char *buf) 785 + { 786 + struct hw_stats_attribute *hsa; 787 + int msecs; 788 + 789 + hsa = container_of(attr, struct hw_stats_attribute, attr); 790 + if (!hsa->port_num) { 791 + struct ib_device *dev = container_of((struct device *)kobj, 792 + struct ib_device, dev); 793 + msecs = jiffies_to_msecs(dev->hw_stats->lifespan); 794 + } else { 795 + struct ib_port *p = container_of(kobj, struct ib_port, kobj); 796 + msecs = jiffies_to_msecs(p->hw_stats->lifespan); 797 + } 798 + return sprintf(buf, "%d\n", msecs); 799 + } 800 + 801 + static ssize_t set_stats_lifespan(struct kobject *kobj, 802 + struct attribute *attr, 803 + const char *buf, size_t count) 804 + { 805 + struct hw_stats_attribute *hsa; 806 + int msecs; 807 + int jiffies; 808 + int ret; 809 + 810 + ret = kstrtoint(buf, 10, &msecs); 811 + if (ret) 812 + return ret; 813 + if (msecs < 0 || msecs > 10000) 814 + return -EINVAL; 815 + jiffies = msecs_to_jiffies(msecs); 816 + hsa = container_of(attr, struct hw_stats_attribute, attr); 817 + if (!hsa->port_num) { 818 + struct ib_device *dev = container_of((struct device *)kobj, 819 + struct ib_device, dev); 820 + dev->hw_stats->lifespan = jiffies; 821 + } else { 822 + struct ib_port *p = container_of(kobj, struct ib_port, kobj); 823 + p->hw_stats->lifespan = jiffies; 824 + } 825 + return count; 826 + } 827 + 828 + static void free_hsag(struct kobject *kobj, struct attribute_group *attr_group) 829 + { 830 + struct attribute **attr; 831 + 832 + sysfs_remove_group(kobj, attr_group); 833 + 834 + for (attr = attr_group->attrs; *attr; attr++) 835 + kfree(*attr); 836 + kfree(attr_group); 837 + } 838 + 839 + static struct attribute *alloc_hsa(int index, u8 port_num, const char *name) 840 + { 841 + struct hw_stats_attribute *hsa; 842 + 843 + hsa = kmalloc(sizeof(*hsa), GFP_KERNEL); 844 + if (!hsa) 845 + return NULL; 846 + 847 + hsa->attr.name = (char *)name; 848 + hsa->attr.mode = S_IRUGO; 849 + hsa->show = show_hw_stats; 850 + hsa->store = NULL; 851 + hsa->index = index; 852 + hsa->port_num = port_num; 853 + 854 + return &hsa->attr; 855 + } 856 + 857 + static struct attribute *alloc_hsa_lifespan(char *name, u8 port_num) 858 + { 859 + struct hw_stats_attribute *hsa; 860 + 861 + hsa = kmalloc(sizeof(*hsa), GFP_KERNEL); 862 + if (!hsa) 863 + return NULL; 864 + 865 + hsa->attr.name = name; 866 + hsa->attr.mode = S_IWUSR | S_IRUGO; 867 + hsa->show = show_stats_lifespan; 868 + hsa->store = set_stats_lifespan; 869 + hsa->index = 0; 870 + hsa->port_num = port_num; 871 + 872 + return &hsa->attr; 873 + } 874 + 875 + static void setup_hw_stats(struct ib_device *device, struct ib_port *port, 876 + u8 port_num) 877 + { 878 + struct attribute_group *hsag = NULL; 879 + struct rdma_hw_stats *stats; 880 + int i = 0, ret; 881 + 882 + stats = device->alloc_hw_stats(device, port_num); 883 + 884 + if (!stats) 885 + return; 886 + 887 + if (!stats->names || stats->num_counters <= 0) 888 + goto err; 889 + 890 + hsag = kzalloc(sizeof(*hsag) + 891 + // 1 extra for the lifespan config entry 892 + sizeof(void *) * (stats->num_counters + 1), 893 + GFP_KERNEL); 894 + if (!hsag) 895 + return; 896 + 897 + ret = device->get_hw_stats(device, stats, port_num, 898 + stats->num_counters); 899 + if (ret != stats->num_counters) 900 + goto err; 901 + 902 + stats->timestamp = jiffies; 903 + 904 + hsag->name = "hw_counters"; 905 + hsag->attrs = (void *)hsag + sizeof(*hsag); 906 + 907 + for (i = 0; i < stats->num_counters; i++) { 908 + hsag->attrs[i] = alloc_hsa(i, port_num, stats->names[i]); 909 + if (!hsag->attrs[i]) 910 + goto err; 911 + } 912 + 913 + /* treat an error here as non-fatal */ 914 + hsag->attrs[i] = alloc_hsa_lifespan("lifespan", port_num); 915 + 916 + if (port) { 917 + struct kobject *kobj = &port->kobj; 918 + ret = sysfs_create_group(kobj, hsag); 919 + if (ret) 920 + goto err; 921 + port->hw_stats_ag = hsag; 922 + port->hw_stats = stats; 923 + } else { 924 + struct kobject *kobj = &device->dev.kobj; 925 + ret = sysfs_create_group(kobj, hsag); 926 + if (ret) 927 + goto err; 928 + device->hw_stats_ag = hsag; 929 + device->hw_stats = stats; 930 + } 931 + 932 + return; 933 + 934 + err: 935 + kfree(stats); 936 + for (; i >= 0; i--) 937 + kfree(hsag->attrs[i]); 938 + kfree(hsag); 939 + return; 940 + } 941 + 750 942 static int add_port(struct ib_device *device, int port_num, 751 943 int (*port_callback)(struct ib_device *, 752 944 u8, struct kobject *)) ··· 1054 834 if (ret) 1055 835 goto err_remove_pkey; 1056 836 } 837 + 838 + /* 839 + * If port == 0, it means we have only one port and the parent 840 + * device, not this port device, should be the holder of the 841 + * hw_counters 842 + */ 843 + if (device->alloc_hw_stats && port_num) 844 + setup_hw_stats(device, p, port_num); 1057 845 1058 846 list_add_tail(&p->kobj.entry, &device->port_list); 1059 847 ··· 1200 972 &dev_attr_node_desc 1201 973 }; 1202 974 1203 - /* Show a given an attribute in the statistics group */ 1204 - static ssize_t show_protocol_stat(const struct device *device, 1205 - struct device_attribute *attr, char *buf, 1206 - unsigned offset) 1207 - { 1208 - struct ib_device *dev = container_of(device, struct ib_device, dev); 1209 - union rdma_protocol_stats stats; 1210 - ssize_t ret; 1211 - 1212 - ret = dev->get_protocol_stats(dev, &stats); 1213 - if (ret) 1214 - return ret; 1215 - 1216 - return sprintf(buf, "%llu\n", 1217 - (unsigned long long) ((u64 *) &stats)[offset]); 1218 - } 1219 - 1220 - /* generate a read-only iwarp statistics attribute */ 1221 - #define IW_STATS_ENTRY(name) \ 1222 - static ssize_t show_##name(struct device *device, \ 1223 - struct device_attribute *attr, char *buf) \ 1224 - { \ 1225 - return show_protocol_stat(device, attr, buf, \ 1226 - offsetof(struct iw_protocol_stats, name) / \ 1227 - sizeof (u64)); \ 1228 - } \ 1229 - static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) 1230 - 1231 - IW_STATS_ENTRY(ipInReceives); 1232 - IW_STATS_ENTRY(ipInHdrErrors); 1233 - IW_STATS_ENTRY(ipInTooBigErrors); 1234 - IW_STATS_ENTRY(ipInNoRoutes); 1235 - IW_STATS_ENTRY(ipInAddrErrors); 1236 - IW_STATS_ENTRY(ipInUnknownProtos); 1237 - IW_STATS_ENTRY(ipInTruncatedPkts); 1238 - IW_STATS_ENTRY(ipInDiscards); 1239 - IW_STATS_ENTRY(ipInDelivers); 1240 - IW_STATS_ENTRY(ipOutForwDatagrams); 1241 - IW_STATS_ENTRY(ipOutRequests); 1242 - IW_STATS_ENTRY(ipOutDiscards); 1243 - IW_STATS_ENTRY(ipOutNoRoutes); 1244 - IW_STATS_ENTRY(ipReasmTimeout); 1245 - IW_STATS_ENTRY(ipReasmReqds); 1246 - IW_STATS_ENTRY(ipReasmOKs); 1247 - IW_STATS_ENTRY(ipReasmFails); 1248 - IW_STATS_ENTRY(ipFragOKs); 1249 - IW_STATS_ENTRY(ipFragFails); 1250 - IW_STATS_ENTRY(ipFragCreates); 1251 - IW_STATS_ENTRY(ipInMcastPkts); 1252 - IW_STATS_ENTRY(ipOutMcastPkts); 1253 - IW_STATS_ENTRY(ipInBcastPkts); 1254 - IW_STATS_ENTRY(ipOutBcastPkts); 1255 - IW_STATS_ENTRY(tcpRtoAlgorithm); 1256 - IW_STATS_ENTRY(tcpRtoMin); 1257 - IW_STATS_ENTRY(tcpRtoMax); 1258 - IW_STATS_ENTRY(tcpMaxConn); 1259 - IW_STATS_ENTRY(tcpActiveOpens); 1260 - IW_STATS_ENTRY(tcpPassiveOpens); 1261 - IW_STATS_ENTRY(tcpAttemptFails); 1262 - IW_STATS_ENTRY(tcpEstabResets); 1263 - IW_STATS_ENTRY(tcpCurrEstab); 1264 - IW_STATS_ENTRY(tcpInSegs); 1265 - IW_STATS_ENTRY(tcpOutSegs); 1266 - IW_STATS_ENTRY(tcpRetransSegs); 1267 - IW_STATS_ENTRY(tcpInErrs); 1268 - IW_STATS_ENTRY(tcpOutRsts); 1269 - 1270 - static struct attribute *iw_proto_stats_attrs[] = { 1271 - &dev_attr_ipInReceives.attr, 1272 - &dev_attr_ipInHdrErrors.attr, 1273 - &dev_attr_ipInTooBigErrors.attr, 1274 - &dev_attr_ipInNoRoutes.attr, 1275 - &dev_attr_ipInAddrErrors.attr, 1276 - &dev_attr_ipInUnknownProtos.attr, 1277 - &dev_attr_ipInTruncatedPkts.attr, 1278 - &dev_attr_ipInDiscards.attr, 1279 - &dev_attr_ipInDelivers.attr, 1280 - &dev_attr_ipOutForwDatagrams.attr, 1281 - &dev_attr_ipOutRequests.attr, 1282 - &dev_attr_ipOutDiscards.attr, 1283 - &dev_attr_ipOutNoRoutes.attr, 1284 - &dev_attr_ipReasmTimeout.attr, 1285 - &dev_attr_ipReasmReqds.attr, 1286 - &dev_attr_ipReasmOKs.attr, 1287 - &dev_attr_ipReasmFails.attr, 1288 - &dev_attr_ipFragOKs.attr, 1289 - &dev_attr_ipFragFails.attr, 1290 - &dev_attr_ipFragCreates.attr, 1291 - &dev_attr_ipInMcastPkts.attr, 1292 - &dev_attr_ipOutMcastPkts.attr, 1293 - &dev_attr_ipInBcastPkts.attr, 1294 - &dev_attr_ipOutBcastPkts.attr, 1295 - &dev_attr_tcpRtoAlgorithm.attr, 1296 - &dev_attr_tcpRtoMin.attr, 1297 - &dev_attr_tcpRtoMax.attr, 1298 - &dev_attr_tcpMaxConn.attr, 1299 - &dev_attr_tcpActiveOpens.attr, 1300 - &dev_attr_tcpPassiveOpens.attr, 1301 - &dev_attr_tcpAttemptFails.attr, 1302 - &dev_attr_tcpEstabResets.attr, 1303 - &dev_attr_tcpCurrEstab.attr, 1304 - &dev_attr_tcpInSegs.attr, 1305 - &dev_attr_tcpOutSegs.attr, 1306 - &dev_attr_tcpRetransSegs.attr, 1307 - &dev_attr_tcpInErrs.attr, 1308 - &dev_attr_tcpOutRsts.attr, 1309 - NULL 1310 - }; 1311 - 1312 - static struct attribute_group iw_stats_group = { 1313 - .name = "proto_stats", 1314 - .attrs = iw_proto_stats_attrs, 1315 - }; 1316 - 1317 975 static void free_port_list_attributes(struct ib_device *device) 1318 976 { 1319 977 struct kobject *p, *t; ··· 1207 1093 list_for_each_entry_safe(p, t, &device->port_list, entry) { 1208 1094 struct ib_port *port = container_of(p, struct ib_port, kobj); 1209 1095 list_del(&p->entry); 1096 + if (port->hw_stats) { 1097 + kfree(port->hw_stats); 1098 + free_hsag(&port->kobj, port->hw_stats_ag); 1099 + } 1210 1100 sysfs_remove_group(p, port->pma_table); 1211 1101 sysfs_remove_group(p, &port->pkey_group); 1212 1102 sysfs_remove_group(p, &port->gid_group); ··· 1267 1149 } 1268 1150 } 1269 1151 1270 - if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) { 1271 - ret = sysfs_create_group(&class_dev->kobj, &iw_stats_group); 1272 - if (ret) 1273 - goto err_put; 1274 - } 1152 + if (device->alloc_hw_stats) 1153 + setup_hw_stats(device, NULL, 0); 1275 1154 1276 1155 return 0; 1277 1156 ··· 1284 1169 1285 1170 void ib_device_unregister_sysfs(struct ib_device *device) 1286 1171 { 1287 - /* Hold kobject until ib_dealloc_device() */ 1288 - struct kobject *kobj_dev = kobject_get(&device->dev.kobj); 1289 1172 int i; 1290 1173 1291 - if (device->node_type == RDMA_NODE_RNIC && device->get_protocol_stats) 1292 - sysfs_remove_group(kobj_dev, &iw_stats_group); 1174 + /* Hold kobject until ib_dealloc_device() */ 1175 + kobject_get(&device->dev.kobj); 1293 1176 1294 1177 free_port_list_attributes(device); 1178 + 1179 + if (device->hw_stats) { 1180 + kfree(device->hw_stats); 1181 + free_hsag(&device->dev.kobj, device->hw_stats_ag); 1182 + } 1295 1183 1296 1184 for (i = 0; i < ARRAY_SIZE(ib_class_attributes); ++i) 1297 1185 device_remove_file(&device->dev, ib_class_attributes[i]);
+1
drivers/infiniband/hw/Makefile
··· 8 8 obj-$(CONFIG_INFINIBAND_NES) += nes/ 9 9 obj-$(CONFIG_INFINIBAND_OCRDMA) += ocrdma/ 10 10 obj-$(CONFIG_INFINIBAND_USNIC) += usnic/ 11 + obj-$(CONFIG_INFINIBAND_HFI1) += hfi1/
+1 -1
drivers/infiniband/hw/cxgb3/cxio_hal.c
··· 327 327 kfree(cq->sw_queue); 328 328 dma_free_coherent(&(rdev_p->rnic_info.pdev->dev), 329 329 (1UL << (cq->size_log2)) 330 - * sizeof(struct t3_cqe), cq->queue, 330 + * sizeof(struct t3_cqe) + 1, cq->queue, 331 331 dma_unmap_addr(cq, mapping)); 332 332 cxio_hal_put_cqid(rdev_p->rscp, cq->cqid); 333 333 return err;
+104 -43
drivers/infiniband/hw/cxgb3/iwch_provider.c
··· 1218 1218 iwch_dev->rdev.rnic_info.pdev->device); 1219 1219 } 1220 1220 1221 - static int iwch_get_mib(struct ib_device *ibdev, 1222 - union rdma_protocol_stats *stats) 1221 + enum counters { 1222 + IPINRECEIVES, 1223 + IPINHDRERRORS, 1224 + IPINADDRERRORS, 1225 + IPINUNKNOWNPROTOS, 1226 + IPINDISCARDS, 1227 + IPINDELIVERS, 1228 + IPOUTREQUESTS, 1229 + IPOUTDISCARDS, 1230 + IPOUTNOROUTES, 1231 + IPREASMTIMEOUT, 1232 + IPREASMREQDS, 1233 + IPREASMOKS, 1234 + IPREASMFAILS, 1235 + TCPACTIVEOPENS, 1236 + TCPPASSIVEOPENS, 1237 + TCPATTEMPTFAILS, 1238 + TCPESTABRESETS, 1239 + TCPCURRESTAB, 1240 + TCPINSEGS, 1241 + TCPOUTSEGS, 1242 + TCPRETRANSSEGS, 1243 + TCPINERRS, 1244 + TCPOUTRSTS, 1245 + TCPRTOMIN, 1246 + TCPRTOMAX, 1247 + NR_COUNTERS 1248 + }; 1249 + 1250 + static const char * const names[] = { 1251 + [IPINRECEIVES] = "ipInReceives", 1252 + [IPINHDRERRORS] = "ipInHdrErrors", 1253 + [IPINADDRERRORS] = "ipInAddrErrors", 1254 + [IPINUNKNOWNPROTOS] = "ipInUnknownProtos", 1255 + [IPINDISCARDS] = "ipInDiscards", 1256 + [IPINDELIVERS] = "ipInDelivers", 1257 + [IPOUTREQUESTS] = "ipOutRequests", 1258 + [IPOUTDISCARDS] = "ipOutDiscards", 1259 + [IPOUTNOROUTES] = "ipOutNoRoutes", 1260 + [IPREASMTIMEOUT] = "ipReasmTimeout", 1261 + [IPREASMREQDS] = "ipReasmReqds", 1262 + [IPREASMOKS] = "ipReasmOKs", 1263 + [IPREASMFAILS] = "ipReasmFails", 1264 + [TCPACTIVEOPENS] = "tcpActiveOpens", 1265 + [TCPPASSIVEOPENS] = "tcpPassiveOpens", 1266 + [TCPATTEMPTFAILS] = "tcpAttemptFails", 1267 + [TCPESTABRESETS] = "tcpEstabResets", 1268 + [TCPCURRESTAB] = "tcpCurrEstab", 1269 + [TCPINSEGS] = "tcpInSegs", 1270 + [TCPOUTSEGS] = "tcpOutSegs", 1271 + [TCPRETRANSSEGS] = "tcpRetransSegs", 1272 + [TCPINERRS] = "tcpInErrs", 1273 + [TCPOUTRSTS] = "tcpOutRsts", 1274 + [TCPRTOMIN] = "tcpRtoMin", 1275 + [TCPRTOMAX] = "tcpRtoMax", 1276 + }; 1277 + 1278 + static struct rdma_hw_stats *iwch_alloc_stats(struct ib_device *ibdev, 1279 + u8 port_num) 1280 + { 1281 + BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS); 1282 + 1283 + /* Our driver only supports device level stats */ 1284 + if (port_num != 0) 1285 + return NULL; 1286 + 1287 + return rdma_alloc_hw_stats_struct(names, NR_COUNTERS, 1288 + RDMA_HW_STATS_DEFAULT_LIFESPAN); 1289 + } 1290 + 1291 + static int iwch_get_mib(struct ib_device *ibdev, struct rdma_hw_stats *stats, 1292 + u8 port, int index) 1223 1293 { 1224 1294 struct iwch_dev *dev; 1225 1295 struct tp_mib_stats m; 1226 1296 int ret; 1297 + 1298 + if (port != 0 || !stats) 1299 + return -ENOSYS; 1227 1300 1228 1301 PDBG("%s ibdev %p\n", __func__, ibdev); 1229 1302 dev = to_iwch_dev(ibdev); ··· 1304 1231 if (ret) 1305 1232 return -ENOSYS; 1306 1233 1307 - memset(stats, 0, sizeof *stats); 1308 - stats->iw.ipInReceives = ((u64) m.ipInReceive_hi << 32) + 1309 - m.ipInReceive_lo; 1310 - stats->iw.ipInHdrErrors = ((u64) m.ipInHdrErrors_hi << 32) + 1311 - m.ipInHdrErrors_lo; 1312 - stats->iw.ipInAddrErrors = ((u64) m.ipInAddrErrors_hi << 32) + 1313 - m.ipInAddrErrors_lo; 1314 - stats->iw.ipInUnknownProtos = ((u64) m.ipInUnknownProtos_hi << 32) + 1315 - m.ipInUnknownProtos_lo; 1316 - stats->iw.ipInDiscards = ((u64) m.ipInDiscards_hi << 32) + 1317 - m.ipInDiscards_lo; 1318 - stats->iw.ipInDelivers = ((u64) m.ipInDelivers_hi << 32) + 1319 - m.ipInDelivers_lo; 1320 - stats->iw.ipOutRequests = ((u64) m.ipOutRequests_hi << 32) + 1321 - m.ipOutRequests_lo; 1322 - stats->iw.ipOutDiscards = ((u64) m.ipOutDiscards_hi << 32) + 1323 - m.ipOutDiscards_lo; 1324 - stats->iw.ipOutNoRoutes = ((u64) m.ipOutNoRoutes_hi << 32) + 1325 - m.ipOutNoRoutes_lo; 1326 - stats->iw.ipReasmTimeout = (u64) m.ipReasmTimeout; 1327 - stats->iw.ipReasmReqds = (u64) m.ipReasmReqds; 1328 - stats->iw.ipReasmOKs = (u64) m.ipReasmOKs; 1329 - stats->iw.ipReasmFails = (u64) m.ipReasmFails; 1330 - stats->iw.tcpActiveOpens = (u64) m.tcpActiveOpens; 1331 - stats->iw.tcpPassiveOpens = (u64) m.tcpPassiveOpens; 1332 - stats->iw.tcpAttemptFails = (u64) m.tcpAttemptFails; 1333 - stats->iw.tcpEstabResets = (u64) m.tcpEstabResets; 1334 - stats->iw.tcpOutRsts = (u64) m.tcpOutRsts; 1335 - stats->iw.tcpCurrEstab = (u64) m.tcpCurrEstab; 1336 - stats->iw.tcpInSegs = ((u64) m.tcpInSegs_hi << 32) + 1337 - m.tcpInSegs_lo; 1338 - stats->iw.tcpOutSegs = ((u64) m.tcpOutSegs_hi << 32) + 1339 - m.tcpOutSegs_lo; 1340 - stats->iw.tcpRetransSegs = ((u64) m.tcpRetransSeg_hi << 32) + 1341 - m.tcpRetransSeg_lo; 1342 - stats->iw.tcpInErrs = ((u64) m.tcpInErrs_hi << 32) + 1343 - m.tcpInErrs_lo; 1344 - stats->iw.tcpRtoMin = (u64) m.tcpRtoMin; 1345 - stats->iw.tcpRtoMax = (u64) m.tcpRtoMax; 1346 - return 0; 1234 + stats->value[IPINRECEIVES] = ((u64)m.ipInReceive_hi << 32) + m.ipInReceive_lo; 1235 + stats->value[IPINHDRERRORS] = ((u64)m.ipInHdrErrors_hi << 32) + m.ipInHdrErrors_lo; 1236 + stats->value[IPINADDRERRORS] = ((u64)m.ipInAddrErrors_hi << 32) + m.ipInAddrErrors_lo; 1237 + stats->value[IPINUNKNOWNPROTOS] = ((u64)m.ipInUnknownProtos_hi << 32) + m.ipInUnknownProtos_lo; 1238 + stats->value[IPINDISCARDS] = ((u64)m.ipInDiscards_hi << 32) + m.ipInDiscards_lo; 1239 + stats->value[IPINDELIVERS] = ((u64)m.ipInDelivers_hi << 32) + m.ipInDelivers_lo; 1240 + stats->value[IPOUTREQUESTS] = ((u64)m.ipOutRequests_hi << 32) + m.ipOutRequests_lo; 1241 + stats->value[IPOUTDISCARDS] = ((u64)m.ipOutDiscards_hi << 32) + m.ipOutDiscards_lo; 1242 + stats->value[IPOUTNOROUTES] = ((u64)m.ipOutNoRoutes_hi << 32) + m.ipOutNoRoutes_lo; 1243 + stats->value[IPREASMTIMEOUT] = m.ipReasmTimeout; 1244 + stats->value[IPREASMREQDS] = m.ipReasmReqds; 1245 + stats->value[IPREASMOKS] = m.ipReasmOKs; 1246 + stats->value[IPREASMFAILS] = m.ipReasmFails; 1247 + stats->value[TCPACTIVEOPENS] = m.tcpActiveOpens; 1248 + stats->value[TCPPASSIVEOPENS] = m.tcpPassiveOpens; 1249 + stats->value[TCPATTEMPTFAILS] = m.tcpAttemptFails; 1250 + stats->value[TCPESTABRESETS] = m.tcpEstabResets; 1251 + stats->value[TCPCURRESTAB] = m.tcpOutRsts; 1252 + stats->value[TCPINSEGS] = m.tcpCurrEstab; 1253 + stats->value[TCPOUTSEGS] = ((u64)m.tcpInSegs_hi << 32) + m.tcpInSegs_lo; 1254 + stats->value[TCPRETRANSSEGS] = ((u64)m.tcpOutSegs_hi << 32) + m.tcpOutSegs_lo; 1255 + stats->value[TCPINERRS] = ((u64)m.tcpRetransSeg_hi << 32) + m.tcpRetransSeg_lo, 1256 + stats->value[TCPOUTRSTS] = ((u64)m.tcpInErrs_hi << 32) + m.tcpInErrs_lo; 1257 + stats->value[TCPRTOMIN] = m.tcpRtoMin; 1258 + stats->value[TCPRTOMAX] = m.tcpRtoMax; 1259 + 1260 + return stats->num_counters; 1347 1261 } 1348 1262 1349 1263 static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); ··· 1433 1373 dev->ibdev.req_notify_cq = iwch_arm_cq; 1434 1374 dev->ibdev.post_send = iwch_post_send; 1435 1375 dev->ibdev.post_recv = iwch_post_receive; 1436 - dev->ibdev.get_protocol_stats = iwch_get_mib; 1376 + dev->ibdev.alloc_hw_stats = iwch_alloc_stats; 1377 + dev->ibdev.get_hw_stats = iwch_get_mib; 1437 1378 dev->ibdev.uverbs_abi_ver = IWCH_UVERBS_ABI_VERSION; 1438 1379 dev->ibdev.get_port_immutable = iwch_port_immutable; 1439 1380
+48 -8
drivers/infiniband/hw/cxgb4/provider.c
··· 446 446 c4iw_dev->rdev.lldi.pdev->device); 447 447 } 448 448 449 + enum counters { 450 + IP4INSEGS, 451 + IP4OUTSEGS, 452 + IP4RETRANSSEGS, 453 + IP4OUTRSTS, 454 + IP6INSEGS, 455 + IP6OUTSEGS, 456 + IP6RETRANSSEGS, 457 + IP6OUTRSTS, 458 + NR_COUNTERS 459 + }; 460 + 461 + static const char * const names[] = { 462 + [IP4INSEGS] = "ip4InSegs", 463 + [IP4OUTSEGS] = "ip4OutSegs", 464 + [IP4RETRANSSEGS] = "ip4RetransSegs", 465 + [IP4OUTRSTS] = "ip4OutRsts", 466 + [IP6INSEGS] = "ip6InSegs", 467 + [IP6OUTSEGS] = "ip6OutSegs", 468 + [IP6RETRANSSEGS] = "ip6RetransSegs", 469 + [IP6OUTRSTS] = "ip6OutRsts" 470 + }; 471 + 472 + static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev, 473 + u8 port_num) 474 + { 475 + BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS); 476 + 477 + if (port_num != 0) 478 + return NULL; 479 + 480 + return rdma_alloc_hw_stats_struct(names, NR_COUNTERS, 481 + RDMA_HW_STATS_DEFAULT_LIFESPAN); 482 + } 483 + 449 484 static int c4iw_get_mib(struct ib_device *ibdev, 450 - union rdma_protocol_stats *stats) 485 + struct rdma_hw_stats *stats, 486 + u8 port, int index) 451 487 { 452 488 struct tp_tcp_stats v4, v6; 453 489 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev); 454 490 455 491 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6); 456 - memset(stats, 0, sizeof *stats); 457 - stats->iw.tcpInSegs = v4.tcp_in_segs + v6.tcp_in_segs; 458 - stats->iw.tcpOutSegs = v4.tcp_out_segs + v6.tcp_out_segs; 459 - stats->iw.tcpRetransSegs = v4.tcp_retrans_segs + v6.tcp_retrans_segs; 460 - stats->iw.tcpOutRsts = v4.tcp_out_rsts + v6.tcp_out_rsts; 492 + stats->value[IP4INSEGS] = v4.tcp_in_segs; 493 + stats->value[IP4OUTSEGS] = v4.tcp_out_segs; 494 + stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs; 495 + stats->value[IP4OUTRSTS] = v4.tcp_out_rsts; 496 + stats->value[IP6INSEGS] = v6.tcp_in_segs; 497 + stats->value[IP6OUTSEGS] = v6.tcp_out_segs; 498 + stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs; 499 + stats->value[IP6OUTRSTS] = v6.tcp_out_rsts; 461 500 462 - return 0; 501 + return stats->num_counters; 463 502 } 464 503 465 504 static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); ··· 601 562 dev->ibdev.req_notify_cq = c4iw_arm_cq; 602 563 dev->ibdev.post_send = c4iw_post_send; 603 564 dev->ibdev.post_recv = c4iw_post_receive; 604 - dev->ibdev.get_protocol_stats = c4iw_get_mib; 565 + dev->ibdev.alloc_hw_stats = c4iw_alloc_stats; 566 + dev->ibdev.get_hw_stats = c4iw_get_mib; 605 567 dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION; 606 568 dev->ibdev.get_port_immutable = c4iw_port_immutable; 607 569 dev->ibdev.drain_sq = c4iw_drain_sq;
+60
drivers/infiniband/hw/hfi1/device.h
··· 1 + #ifndef _HFI1_DEVICE_H 2 + #define _HFI1_DEVICE_H 3 + /* 4 + * Copyright(c) 2015, 2016 Intel Corporation. 5 + * 6 + * This file is provided under a dual BSD/GPLv2 license. When using or 7 + * redistributing this file, you may do so under either license. 8 + * 9 + * GPL LICENSE SUMMARY 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of version 2 of the GNU General Public License as 13 + * published by the Free Software Foundation. 14 + * 15 + * This program is distributed in the hope that it will be useful, but 16 + * WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 + * General Public License for more details. 19 + * 20 + * BSD LICENSE 21 + * 22 + * Redistribution and use in source and binary forms, with or without 23 + * modification, are permitted provided that the following conditions 24 + * are met: 25 + * 26 + * - Redistributions of source code must retain the above copyright 27 + * notice, this list of conditions and the following disclaimer. 28 + * - Redistributions in binary form must reproduce the above copyright 29 + * notice, this list of conditions and the following disclaimer in 30 + * the documentation and/or other materials provided with the 31 + * distribution. 32 + * - Neither the name of Intel Corporation nor the names of its 33 + * contributors may be used to endorse or promote products derived 34 + * from this software without specific prior written permission. 35 + * 36 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 37 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 39 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 40 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 43 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 44 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 45 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 46 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 47 + * 48 + */ 49 + 50 + int hfi1_cdev_init(int minor, const char *name, 51 + const struct file_operations *fops, 52 + struct cdev *cdev, struct device **devp, 53 + bool user_accessible, 54 + struct kobject *parent); 55 + void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp); 56 + const char *class_name(void); 57 + int __init dev_init(void); 58 + void dev_cleanup(void); 59 + 60 + #endif /* _HFI1_DEVICE_H */
+108 -35
drivers/infiniband/hw/i40iw/i40iw_verbs.c
··· 2361 2361 return 0; 2362 2362 } 2363 2363 2364 + static const char * const i40iw_hw_stat_names[] = { 2365 + // 32bit names 2366 + [I40IW_HW_STAT_INDEX_IP4RXDISCARD] = "ip4InDiscards", 2367 + [I40IW_HW_STAT_INDEX_IP4RXTRUNC] = "ip4InTruncatedPkts", 2368 + [I40IW_HW_STAT_INDEX_IP4TXNOROUTE] = "ip4OutNoRoutes", 2369 + [I40IW_HW_STAT_INDEX_IP6RXDISCARD] = "ip6InDiscards", 2370 + [I40IW_HW_STAT_INDEX_IP6RXTRUNC] = "ip6InTruncatedPkts", 2371 + [I40IW_HW_STAT_INDEX_IP6TXNOROUTE] = "ip6OutNoRoutes", 2372 + [I40IW_HW_STAT_INDEX_TCPRTXSEG] = "tcpRetransSegs", 2373 + [I40IW_HW_STAT_INDEX_TCPRXOPTERR] = "tcpInOptErrors", 2374 + [I40IW_HW_STAT_INDEX_TCPRXPROTOERR] = "tcpInProtoErrors", 2375 + // 64bit names 2376 + [I40IW_HW_STAT_INDEX_IP4RXOCTS + I40IW_HW_STAT_INDEX_MAX_32] = 2377 + "ip4InOctets", 2378 + [I40IW_HW_STAT_INDEX_IP4RXPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2379 + "ip4InPkts", 2380 + [I40IW_HW_STAT_INDEX_IP4RXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] = 2381 + "ip4InReasmRqd", 2382 + [I40IW_HW_STAT_INDEX_IP4RXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2383 + "ip4InMcastPkts", 2384 + [I40IW_HW_STAT_INDEX_IP4TXOCTS + I40IW_HW_STAT_INDEX_MAX_32] = 2385 + "ip4OutOctets", 2386 + [I40IW_HW_STAT_INDEX_IP4TXPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2387 + "ip4OutPkts", 2388 + [I40IW_HW_STAT_INDEX_IP4TXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] = 2389 + "ip4OutSegRqd", 2390 + [I40IW_HW_STAT_INDEX_IP4TXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2391 + "ip4OutMcastPkts", 2392 + [I40IW_HW_STAT_INDEX_IP6RXOCTS + I40IW_HW_STAT_INDEX_MAX_32] = 2393 + "ip6InOctets", 2394 + [I40IW_HW_STAT_INDEX_IP6RXPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2395 + "ip6InPkts", 2396 + [I40IW_HW_STAT_INDEX_IP6RXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] = 2397 + "ip6InReasmRqd", 2398 + [I40IW_HW_STAT_INDEX_IP6RXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2399 + "ip6InMcastPkts", 2400 + [I40IW_HW_STAT_INDEX_IP6TXOCTS + I40IW_HW_STAT_INDEX_MAX_32] = 2401 + "ip6OutOctets", 2402 + [I40IW_HW_STAT_INDEX_IP6TXPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2403 + "ip6OutPkts", 2404 + [I40IW_HW_STAT_INDEX_IP6TXFRAGS + I40IW_HW_STAT_INDEX_MAX_32] = 2405 + "ip6OutSegRqd", 2406 + [I40IW_HW_STAT_INDEX_IP6TXMCPKTS + I40IW_HW_STAT_INDEX_MAX_32] = 2407 + "ip6OutMcastPkts", 2408 + [I40IW_HW_STAT_INDEX_TCPRXSEGS + I40IW_HW_STAT_INDEX_MAX_32] = 2409 + "tcpInSegs", 2410 + [I40IW_HW_STAT_INDEX_TCPTXSEG + I40IW_HW_STAT_INDEX_MAX_32] = 2411 + "tcpOutSegs", 2412 + [I40IW_HW_STAT_INDEX_RDMARXRDS + I40IW_HW_STAT_INDEX_MAX_32] = 2413 + "iwInRdmaReads", 2414 + [I40IW_HW_STAT_INDEX_RDMARXSNDS + I40IW_HW_STAT_INDEX_MAX_32] = 2415 + "iwInRdmaSends", 2416 + [I40IW_HW_STAT_INDEX_RDMARXWRS + I40IW_HW_STAT_INDEX_MAX_32] = 2417 + "iwInRdmaWrites", 2418 + [I40IW_HW_STAT_INDEX_RDMATXRDS + I40IW_HW_STAT_INDEX_MAX_32] = 2419 + "iwOutRdmaReads", 2420 + [I40IW_HW_STAT_INDEX_RDMATXSNDS + I40IW_HW_STAT_INDEX_MAX_32] = 2421 + "iwOutRdmaSends", 2422 + [I40IW_HW_STAT_INDEX_RDMATXWRS + I40IW_HW_STAT_INDEX_MAX_32] = 2423 + "iwOutRdmaWrites", 2424 + [I40IW_HW_STAT_INDEX_RDMAVBND + I40IW_HW_STAT_INDEX_MAX_32] = 2425 + "iwRdmaBnd", 2426 + [I40IW_HW_STAT_INDEX_RDMAVINV + I40IW_HW_STAT_INDEX_MAX_32] = 2427 + "iwRdmaInv" 2428 + }; 2429 + 2364 2430 /** 2365 - * i40iw_get_protocol_stats - Populates the rdma_stats structure 2366 - * @ibdev: ib dev struct 2367 - * @stats: iw protocol stats struct 2431 + * i40iw_alloc_hw_stats - Allocate a hw stats structure 2432 + * @ibdev: device pointer from stack 2433 + * @port_num: port number 2368 2434 */ 2369 - static int i40iw_get_protocol_stats(struct ib_device *ibdev, 2370 - union rdma_protocol_stats *stats) 2435 + static struct rdma_hw_stats *i40iw_alloc_hw_stats(struct ib_device *ibdev, 2436 + u8 port_num) 2437 + { 2438 + struct i40iw_device *iwdev = to_iwdev(ibdev); 2439 + struct i40iw_sc_dev *dev = &iwdev->sc_dev; 2440 + int num_counters = I40IW_HW_STAT_INDEX_MAX_32 + 2441 + I40IW_HW_STAT_INDEX_MAX_64; 2442 + unsigned long lifespan = RDMA_HW_STATS_DEFAULT_LIFESPAN; 2443 + 2444 + BUILD_BUG_ON(ARRAY_SIZE(i40iw_hw_stat_names) != 2445 + (I40IW_HW_STAT_INDEX_MAX_32 + 2446 + I40IW_HW_STAT_INDEX_MAX_64)); 2447 + 2448 + /* 2449 + * PFs get the default update lifespan, but VFs only update once 2450 + * per second 2451 + */ 2452 + if (!dev->is_pf) 2453 + lifespan = 1000; 2454 + return rdma_alloc_hw_stats_struct(i40iw_hw_stat_names, num_counters, 2455 + lifespan); 2456 + } 2457 + 2458 + /** 2459 + * i40iw_get_hw_stats - Populates the rdma_hw_stats structure 2460 + * @ibdev: device pointer from stack 2461 + * @stats: stats pointer from stack 2462 + * @port_num: port number 2463 + * @index: which hw counter the stack is requesting we update 2464 + */ 2465 + static int i40iw_get_hw_stats(struct ib_device *ibdev, 2466 + struct rdma_hw_stats *stats, 2467 + u8 port_num, int index) 2371 2468 { 2372 2469 struct i40iw_device *iwdev = to_iwdev(ibdev); 2373 2470 struct i40iw_sc_dev *dev = &iwdev->sc_dev; 2374 2471 struct i40iw_dev_pestat *devstat = &dev->dev_pestat; 2375 2472 struct i40iw_dev_hw_stats *hw_stats = &devstat->hw_stats; 2376 - struct timespec curr_time; 2377 - static struct timespec last_rd_time = {0, 0}; 2378 2473 unsigned long flags; 2379 - 2380 - curr_time = current_kernel_time(); 2381 - memset(stats, 0, sizeof(*stats)); 2382 2474 2383 2475 if (dev->is_pf) { 2384 2476 spin_lock_irqsave(&devstat->stats_lock, flags); ··· 2478 2386 &devstat->hw_stats); 2479 2387 spin_unlock_irqrestore(&devstat->stats_lock, flags); 2480 2388 } else { 2481 - if (((u64)curr_time.tv_sec - (u64)last_rd_time.tv_sec) > 1) 2482 - if (i40iw_vchnl_vf_get_pe_stats(dev, &devstat->hw_stats)) 2483 - return -ENOSYS; 2389 + if (i40iw_vchnl_vf_get_pe_stats(dev, &devstat->hw_stats)) 2390 + return -ENOSYS; 2484 2391 } 2485 2392 2486 - stats->iw.ipInReceives = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4RXPKTS] + 2487 - hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6RXPKTS]; 2488 - stats->iw.ipInTruncatedPkts = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP4RXTRUNC] + 2489 - hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP6RXTRUNC]; 2490 - stats->iw.ipInDiscards = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP4RXDISCARD] + 2491 - hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP6RXDISCARD]; 2492 - stats->iw.ipOutNoRoutes = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP4TXNOROUTE] + 2493 - hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_IP6TXNOROUTE]; 2494 - stats->iw.ipReasmReqds = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4RXFRAGS] + 2495 - hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6RXFRAGS]; 2496 - stats->iw.ipFragCreates = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4TXFRAGS] + 2497 - hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6TXFRAGS]; 2498 - stats->iw.ipInMcastPkts = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4RXMCPKTS] + 2499 - hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6RXMCPKTS]; 2500 - stats->iw.ipOutMcastPkts = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP4TXMCPKTS] + 2501 - hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_IP6TXMCPKTS]; 2502 - stats->iw.tcpOutSegs = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_TCPTXSEG]; 2503 - stats->iw.tcpInSegs = hw_stats->stat_value_64[I40IW_HW_STAT_INDEX_TCPRXSEGS]; 2504 - stats->iw.tcpRetransSegs = hw_stats->stat_value_32[I40IW_HW_STAT_INDEX_TCPRTXSEG]; 2393 + memcpy(&stats->value[0], &hw_stats, sizeof(*hw_stats)); 2505 2394 2506 - last_rd_time = curr_time; 2507 - return 0; 2395 + return stats->num_counters; 2508 2396 } 2509 2397 2510 2398 /** ··· 2623 2551 iwibdev->ibdev.get_dma_mr = i40iw_get_dma_mr; 2624 2552 iwibdev->ibdev.reg_user_mr = i40iw_reg_user_mr; 2625 2553 iwibdev->ibdev.dereg_mr = i40iw_dereg_mr; 2626 - iwibdev->ibdev.get_protocol_stats = i40iw_get_protocol_stats; 2554 + iwibdev->ibdev.alloc_hw_stats = i40iw_alloc_hw_stats; 2555 + iwibdev->ibdev.get_hw_stats = i40iw_get_hw_stats; 2627 2556 iwibdev->ibdev.query_device = i40iw_query_device; 2628 2557 iwibdev->ibdev.create_ah = i40iw_create_ah; 2629 2558 iwibdev->ibdev.destroy_ah = i40iw_destroy_ah;
-15
drivers/infiniband/hw/qib/qib_iba7322.c
··· 1308 1308 SYM_LSB(IntMask, fldname##17IntMask)), \ 1309 1309 .msg = #fldname "_C", .sz = sizeof(#fldname "_C") } 1310 1310 1311 - static const struct qib_hwerror_msgs qib_7322_intr_msgs[] = { 1312 - INTR_AUTO_P(SDmaInt), 1313 - INTR_AUTO_P(SDmaProgressInt), 1314 - INTR_AUTO_P(SDmaIdleInt), 1315 - INTR_AUTO_P(SDmaCleanupDone), 1316 - INTR_AUTO_C(RcvUrg), 1317 - INTR_AUTO_P(ErrInt), 1318 - INTR_AUTO(ErrInt), /* non-port-specific errs */ 1319 - INTR_AUTO(AssertGPIOInt), 1320 - INTR_AUTO_P(SendDoneInt), 1321 - INTR_AUTO(SendBufAvailInt), 1322 - INTR_AUTO_C(RcvAvail), 1323 - { .mask = 0, .sz = 0 } 1324 - }; 1325 - 1326 1311 #define TXSYMPTOM_AUTO_P(fldname) \ 1327 1312 { .mask = SYM_MASK(SendHdrErrSymptom_0, fldname), \ 1328 1313 .msg = #fldname, .sz = sizeof(#fldname) }
+4 -2
drivers/infiniband/hw/qib/qib_mad.c
··· 1172 1172 * Set the most significant bit of CM2 to indicate support for 1173 1173 * congestion statistics 1174 1174 */ 1175 - p->reserved[0] = dd->psxmitwait_supported << 7; 1175 + ib_set_cpi_capmask2(p, 1176 + dd->psxmitwait_supported << 1177 + (31 - IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE)); 1176 1178 /* 1177 1179 * Expected response time is 4.096 usec. * 2^18 == 1.073741824 sec. 1178 1180 */ 1179 - p->resp_time_value = 18; 1181 + ib_set_cpi_resp_time(p, 18); 1180 1182 1181 1183 return reply((struct ib_smp *) pmp); 1182 1184 }
+1
drivers/infiniband/hw/qib/qib_verbs.h
··· 159 159 } at; 160 160 __be32 imm_data; 161 161 __be32 aeth; 162 + __be32 ieth; 162 163 struct ib_atomic_eth atomic_eth; 163 164 } u; 164 165 } __packed;
+1
drivers/infiniband/sw/rdmavt/cq.c
··· 525 525 return PTR_ERR(task); 526 526 } 527 527 528 + set_user_nice(task, MIN_NICE); 528 529 cpu = cpumask_first(cpumask_of_node(rdi->dparms.node)); 529 530 kthread_bind(task, cpu); 530 531 wake_up_process(task);
+3 -1
drivers/infiniband/sw/rdmavt/mr.c
··· 124 124 int count) 125 125 { 126 126 int m, i = 0; 127 + struct rvt_dev_info *dev = ib_to_rvt(pd->device); 127 128 128 129 mr->mapsz = 0; 129 130 m = (count + RVT_SEGSZ - 1) / RVT_SEGSZ; 130 131 for (; i < m; i++) { 131 - mr->map[i] = kzalloc(sizeof(*mr->map[0]), GFP_KERNEL); 132 + mr->map[i] = kzalloc_node(sizeof(*mr->map[0]), GFP_KERNEL, 133 + dev->dparms.node); 132 134 if (!mr->map[i]) { 133 135 rvt_deinit_mregion(mr); 134 136 return -ENOMEM;
+24 -6
drivers/infiniband/sw/rdmavt/qp.c
··· 397 397 static void rvt_clear_mr_refs(struct rvt_qp *qp, int clr_sends) 398 398 { 399 399 unsigned n; 400 + struct rvt_dev_info *rdi = ib_to_rvt(qp->ibqp.device); 400 401 401 402 if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) 402 403 rvt_put_ss(&qp->s_rdma_read_sge); ··· 432 431 if (qp->ibqp.qp_type != IB_QPT_RC) 433 432 return; 434 433 435 - for (n = 0; n < ARRAY_SIZE(qp->s_ack_queue); n++) { 434 + for (n = 0; n < rvt_max_atomic(rdi); n++) { 436 435 struct rvt_ack_entry *e = &qp->s_ack_queue[n]; 437 436 438 437 if (e->opcode == IB_OPCODE_RC_RDMA_READ_REQUEST && ··· 570 569 qp->s_ssn = 1; 571 570 qp->s_lsn = 0; 572 571 qp->s_mig_state = IB_MIG_MIGRATED; 573 - memset(qp->s_ack_queue, 0, sizeof(qp->s_ack_queue)); 572 + if (qp->s_ack_queue) 573 + memset( 574 + qp->s_ack_queue, 575 + 0, 576 + rvt_max_atomic(rdi) * 577 + sizeof(*qp->s_ack_queue)); 574 578 qp->r_head_ack_queue = 0; 575 579 qp->s_tail_ack_queue = 0; 576 580 qp->s_num_rd_atomic = 0; ··· 659 653 if (gfp == GFP_NOIO) 660 654 swq = __vmalloc( 661 655 (init_attr->cap.max_send_wr + 1) * sz, 662 - gfp, PAGE_KERNEL); 656 + gfp | __GFP_ZERO, PAGE_KERNEL); 663 657 else 664 - swq = vmalloc_node( 658 + swq = vzalloc_node( 665 659 (init_attr->cap.max_send_wr + 1) * sz, 666 660 rdi->dparms.node); 667 661 if (!swq) ··· 683 677 goto bail_swq; 684 678 685 679 RCU_INIT_POINTER(qp->next, NULL); 680 + if (init_attr->qp_type == IB_QPT_RC) { 681 + qp->s_ack_queue = 682 + kzalloc_node( 683 + sizeof(*qp->s_ack_queue) * 684 + rvt_max_atomic(rdi), 685 + gfp, 686 + rdi->dparms.node); 687 + if (!qp->s_ack_queue) 688 + goto bail_qp; 689 + } 686 690 687 691 /* 688 692 * Driver needs to set up it's private QP structure and do any ··· 720 704 qp->r_rq.wq = __vmalloc( 721 705 sizeof(struct rvt_rwq) + 722 706 qp->r_rq.size * sz, 723 - gfp, PAGE_KERNEL); 707 + gfp | __GFP_ZERO, PAGE_KERNEL); 724 708 else 725 - qp->r_rq.wq = vmalloc_node( 709 + qp->r_rq.wq = vzalloc_node( 726 710 sizeof(struct rvt_rwq) + 727 711 qp->r_rq.size * sz, 728 712 rdi->dparms.node); ··· 873 857 rdi->driver_f.qp_priv_free(rdi, qp); 874 858 875 859 bail_qp: 860 + kfree(qp->s_ack_queue); 876 861 kfree(qp); 877 862 878 863 bail_swq: ··· 1301 1284 vfree(qp->r_rq.wq); 1302 1285 vfree(qp->s_wq); 1303 1286 rdi->driver_f.qp_priv_free(rdi, qp); 1287 + kfree(qp->s_ack_queue); 1304 1288 kfree(qp); 1305 1289 return 0; 1306 1290 }
+4
drivers/infiniband/ulp/ipoib/ipoib.h
··· 92 92 IPOIB_FLAG_UMCAST = 10, 93 93 IPOIB_STOP_NEIGH_GC = 11, 94 94 IPOIB_NEIGH_TBL_FLUSH = 12, 95 + IPOIB_FLAG_DEV_ADDR_SET = 13, 96 + IPOIB_FLAG_DEV_ADDR_CTRL = 14, 95 97 96 98 IPOIB_MAX_BACKOFF_SECONDS = 16, 97 99 ··· 394 392 struct ipoib_ethtool_st ethtool; 395 393 struct timer_list poll_timer; 396 394 unsigned max_send_sge; 395 + bool sm_fullmember_sendonly_support; 397 396 }; 398 397 399 398 struct ipoib_ah { ··· 479 476 480 477 void ipoib_mark_paths_invalid(struct net_device *dev); 481 478 void ipoib_flush_paths(struct net_device *dev); 479 + int ipoib_check_sm_sendonly_fullmember_support(struct ipoib_dev_priv *priv); 482 480 struct ipoib_dev_priv *ipoib_intf_alloc(const char *format); 483 481 484 482 int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
+107 -2
drivers/infiniband/ulp/ipoib/ipoib_ib.c
··· 997 997 return 0; 998 998 } 999 999 1000 + /* 1001 + * returns true if the device address of the ipoib interface has changed and the 1002 + * new address is a valid one (i.e in the gid table), return false otherwise. 1003 + */ 1004 + static bool ipoib_dev_addr_changed_valid(struct ipoib_dev_priv *priv) 1005 + { 1006 + union ib_gid search_gid; 1007 + union ib_gid gid0; 1008 + union ib_gid *netdev_gid; 1009 + int err; 1010 + u16 index; 1011 + u8 port; 1012 + bool ret = false; 1013 + 1014 + netdev_gid = (union ib_gid *)(priv->dev->dev_addr + 4); 1015 + if (ib_query_gid(priv->ca, priv->port, 0, &gid0, NULL)) 1016 + return false; 1017 + 1018 + netif_addr_lock(priv->dev); 1019 + 1020 + /* The subnet prefix may have changed, update it now so we won't have 1021 + * to do it later 1022 + */ 1023 + priv->local_gid.global.subnet_prefix = gid0.global.subnet_prefix; 1024 + netdev_gid->global.subnet_prefix = gid0.global.subnet_prefix; 1025 + search_gid.global.subnet_prefix = gid0.global.subnet_prefix; 1026 + 1027 + search_gid.global.interface_id = priv->local_gid.global.interface_id; 1028 + 1029 + netif_addr_unlock(priv->dev); 1030 + 1031 + err = ib_find_gid(priv->ca, &search_gid, IB_GID_TYPE_IB, 1032 + priv->dev, &port, &index); 1033 + 1034 + netif_addr_lock(priv->dev); 1035 + 1036 + if (search_gid.global.interface_id != 1037 + priv->local_gid.global.interface_id) 1038 + /* There was a change while we were looking up the gid, bail 1039 + * here and let the next work sort this out 1040 + */ 1041 + goto out; 1042 + 1043 + /* The next section of code needs some background: 1044 + * Per IB spec the port GUID can't change if the HCA is powered on. 1045 + * port GUID is the basis for GID at index 0 which is the basis for 1046 + * the default device address of a ipoib interface. 1047 + * 1048 + * so it seems the flow should be: 1049 + * if user_changed_dev_addr && gid in gid tbl 1050 + * set bit dev_addr_set 1051 + * return true 1052 + * else 1053 + * return false 1054 + * 1055 + * The issue is that there are devices that don't follow the spec, 1056 + * they change the port GUID when the HCA is powered, so in order 1057 + * not to break userspace applications, We need to check if the 1058 + * user wanted to control the device address and we assume that 1059 + * if he sets the device address back to be based on GID index 0, 1060 + * he no longer wishs to control it. 1061 + * 1062 + * If the user doesn't control the the device address, 1063 + * IPOIB_FLAG_DEV_ADDR_SET is set and ib_find_gid failed it means 1064 + * the port GUID has changed and GID at index 0 has changed 1065 + * so we need to change priv->local_gid and priv->dev->dev_addr 1066 + * to reflect the new GID. 1067 + */ 1068 + if (!test_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags)) { 1069 + if (!err && port == priv->port) { 1070 + set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags); 1071 + if (index == 0) 1072 + clear_bit(IPOIB_FLAG_DEV_ADDR_CTRL, 1073 + &priv->flags); 1074 + else 1075 + set_bit(IPOIB_FLAG_DEV_ADDR_CTRL, &priv->flags); 1076 + ret = true; 1077 + } else { 1078 + ret = false; 1079 + } 1080 + } else { 1081 + if (!err && port == priv->port) { 1082 + ret = true; 1083 + } else { 1084 + if (!test_bit(IPOIB_FLAG_DEV_ADDR_CTRL, &priv->flags)) { 1085 + memcpy(&priv->local_gid, &gid0, 1086 + sizeof(priv->local_gid)); 1087 + memcpy(priv->dev->dev_addr + 4, &gid0, 1088 + sizeof(priv->local_gid)); 1089 + ret = true; 1090 + } 1091 + } 1092 + } 1093 + 1094 + out: 1095 + netif_addr_unlock(priv->dev); 1096 + 1097 + return ret; 1098 + } 1099 + 1000 1100 static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv, 1001 1101 enum ipoib_flush_level level, 1002 1102 int nesting) ··· 1118 1018 1119 1019 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) && 1120 1020 level != IPOIB_FLUSH_HEAVY) { 1021 + /* Make sure the dev_addr is set even if not flushing */ 1022 + if (level == IPOIB_FLUSH_LIGHT) 1023 + ipoib_dev_addr_changed_valid(priv); 1121 1024 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n"); 1122 1025 return; 1123 1026 } ··· 1132 1029 update_parent_pkey(priv); 1133 1030 else 1134 1031 update_child_pkey(priv); 1135 - } 1032 + } else if (level == IPOIB_FLUSH_LIGHT) 1033 + ipoib_dev_addr_changed_valid(priv); 1136 1034 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_ADMIN_UP not set.\n"); 1137 1035 return; 1138 1036 } ··· 1185 1081 if (test_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags)) { 1186 1082 if (level >= IPOIB_FLUSH_NORMAL) 1187 1083 ipoib_ib_dev_up(dev); 1188 - ipoib_mcast_restart_task(&priv->restart_task); 1084 + if (ipoib_dev_addr_changed_valid(priv)) 1085 + ipoib_mcast_restart_task(&priv->restart_task); 1189 1086 } 1190 1087 } 1191 1088
+140
drivers/infiniband/ulp/ipoib/ipoib_main.c
··· 99 99 struct ib_device *dev, u8 port, u16 pkey, 100 100 const union ib_gid *gid, const struct sockaddr *addr, 101 101 void *client_data); 102 + static int ipoib_set_mac(struct net_device *dev, void *addr); 102 103 103 104 static struct ib_client ipoib_client = { 104 105 .name = "ipoib", ··· 117 116 netif_carrier_off(dev); 118 117 119 118 set_bit(IPOIB_FLAG_ADMIN_UP, &priv->flags); 119 + 120 + priv->sm_fullmember_sendonly_support = false; 120 121 121 122 if (ipoib_ib_dev_open(dev)) { 122 123 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) ··· 630 627 } 631 628 632 629 spin_unlock_irq(&priv->lock); 630 + } 631 + 632 + struct classport_info_context { 633 + struct ipoib_dev_priv *priv; 634 + struct completion done; 635 + struct ib_sa_query *sa_query; 636 + }; 637 + 638 + static void classport_info_query_cb(int status, struct ib_class_port_info *rec, 639 + void *context) 640 + { 641 + struct classport_info_context *cb_ctx = context; 642 + struct ipoib_dev_priv *priv; 643 + 644 + WARN_ON(!context); 645 + 646 + priv = cb_ctx->priv; 647 + 648 + if (status || !rec) { 649 + pr_debug("device: %s failed query classport_info status: %d\n", 650 + priv->dev->name, status); 651 + /* keeps the default, will try next mcast_restart */ 652 + priv->sm_fullmember_sendonly_support = false; 653 + goto out; 654 + } 655 + 656 + if (ib_get_cpi_capmask2(rec) & 657 + IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT) { 658 + pr_debug("device: %s enabled fullmember-sendonly for sendonly MCG\n", 659 + priv->dev->name); 660 + priv->sm_fullmember_sendonly_support = true; 661 + } else { 662 + pr_debug("device: %s disabled fullmember-sendonly for sendonly MCG\n", 663 + priv->dev->name); 664 + priv->sm_fullmember_sendonly_support = false; 665 + } 666 + 667 + out: 668 + complete(&cb_ctx->done); 669 + } 670 + 671 + int ipoib_check_sm_sendonly_fullmember_support(struct ipoib_dev_priv *priv) 672 + { 673 + struct classport_info_context *callback_context; 674 + int ret; 675 + 676 + callback_context = kmalloc(sizeof(*callback_context), GFP_KERNEL); 677 + if (!callback_context) 678 + return -ENOMEM; 679 + 680 + callback_context->priv = priv; 681 + init_completion(&callback_context->done); 682 + 683 + ret = ib_sa_classport_info_rec_query(&ipoib_sa_client, 684 + priv->ca, priv->port, 3000, 685 + GFP_KERNEL, 686 + classport_info_query_cb, 687 + callback_context, 688 + &callback_context->sa_query); 689 + if (ret < 0) { 690 + pr_info("%s failed to send ib_sa_classport_info query, ret: %d\n", 691 + priv->dev->name, ret); 692 + kfree(callback_context); 693 + return ret; 694 + } 695 + 696 + /* waiting for the callback to finish before returnning */ 697 + wait_for_completion(&callback_context->done); 698 + kfree(callback_context); 699 + 700 + return ret; 633 701 } 634 702 635 703 void ipoib_flush_paths(struct net_device *dev) ··· 1723 1649 .ndo_get_vf_config = ipoib_get_vf_config, 1724 1650 .ndo_get_vf_stats = ipoib_get_vf_stats, 1725 1651 .ndo_set_vf_guid = ipoib_set_vf_guid, 1652 + .ndo_set_mac_address = ipoib_set_mac, 1726 1653 }; 1727 1654 1728 1655 static const struct net_device_ops ipoib_netdev_ops_vf = { ··· 1844 1769 int ipoib_add_umcast_attr(struct net_device *dev) 1845 1770 { 1846 1771 return device_create_file(&dev->dev, &dev_attr_umcast); 1772 + } 1773 + 1774 + static void set_base_guid(struct ipoib_dev_priv *priv, union ib_gid *gid) 1775 + { 1776 + struct ipoib_dev_priv *child_priv; 1777 + struct net_device *netdev = priv->dev; 1778 + 1779 + netif_addr_lock(netdev); 1780 + 1781 + memcpy(&priv->local_gid.global.interface_id, 1782 + &gid->global.interface_id, 1783 + sizeof(gid->global.interface_id)); 1784 + memcpy(netdev->dev_addr + 4, &priv->local_gid, sizeof(priv->local_gid)); 1785 + clear_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags); 1786 + 1787 + netif_addr_unlock(netdev); 1788 + 1789 + if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { 1790 + down_read(&priv->vlan_rwsem); 1791 + list_for_each_entry(child_priv, &priv->child_intfs, list) 1792 + set_base_guid(child_priv, gid); 1793 + up_read(&priv->vlan_rwsem); 1794 + } 1795 + } 1796 + 1797 + static int ipoib_check_lladdr(struct net_device *dev, 1798 + struct sockaddr_storage *ss) 1799 + { 1800 + union ib_gid *gid = (union ib_gid *)(ss->__data + 4); 1801 + int ret = 0; 1802 + 1803 + netif_addr_lock(dev); 1804 + 1805 + /* Make sure the QPN, reserved and subnet prefix match the current 1806 + * lladdr, it also makes sure the lladdr is unicast. 1807 + */ 1808 + if (memcmp(dev->dev_addr, ss->__data, 1809 + 4 + sizeof(gid->global.subnet_prefix)) || 1810 + gid->global.interface_id == 0) 1811 + ret = -EINVAL; 1812 + 1813 + netif_addr_unlock(dev); 1814 + 1815 + return ret; 1816 + } 1817 + 1818 + static int ipoib_set_mac(struct net_device *dev, void *addr) 1819 + { 1820 + struct ipoib_dev_priv *priv = netdev_priv(dev); 1821 + struct sockaddr_storage *ss = addr; 1822 + int ret; 1823 + 1824 + if (!(dev->priv_flags & IFF_LIVE_ADDR_CHANGE) && netif_running(dev)) 1825 + return -EBUSY; 1826 + 1827 + ret = ipoib_check_lladdr(dev, ss); 1828 + if (ret) 1829 + return ret; 1830 + 1831 + set_base_guid(priv, (union ib_gid *)(ss->__data + 4)); 1832 + 1833 + queue_work(ipoib_workqueue, &priv->flush_light); 1834 + 1835 + return 0; 1847 1836 } 1848 1837 1849 1838 static ssize_t create_child(struct device *dev, ··· 2033 1894 goto device_init_failed; 2034 1895 } else 2035 1896 memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); 1897 + set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags); 2036 1898 2037 1899 result = ipoib_dev_init(priv->dev, hca, port); 2038 1900 if (result < 0) {
+31 -17
drivers/infiniband/ulp/ipoib/ipoib_multicast.c
··· 64 64 unsigned int send_only; 65 65 }; 66 66 67 + /* join state that allows creating mcg with sendonly member request */ 68 + #define SENDONLY_FULLMEMBER_JOIN 8 69 + 67 70 /* 68 71 * This should be called with the priv->lock held 69 72 */ ··· 329 326 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, 330 327 carrier_on_task); 331 328 struct ib_port_attr attr; 329 + int ret; 332 330 333 331 if (ib_query_port(priv->ca, priv->port, &attr) || 334 332 attr.state != IB_PORT_ACTIVE) { 335 333 ipoib_dbg(priv, "Keeping carrier off until IB port is active\n"); 336 334 return; 337 335 } 336 + /* 337 + * Check if can send sendonly MCG's with sendonly-fullmember join state. 338 + * It done here after the successfully join to the broadcast group, 339 + * because the broadcast group must always be joined first and is always 340 + * re-joined if the SM changes substantially. 341 + */ 342 + ret = ipoib_check_sm_sendonly_fullmember_support(priv); 343 + if (ret < 0) 344 + pr_debug("%s failed query sm support for sendonly-fullmember (ret: %d)\n", 345 + priv->dev->name, ret); 338 346 339 347 /* 340 348 * Take rtnl_lock to avoid racing with ipoib_stop() and ··· 529 515 rec.hop_limit = priv->broadcast->mcmember.hop_limit; 530 516 531 517 /* 532 - * Send-only IB Multicast joins do not work at the core 533 - * IB layer yet, so we can't use them here. However, 534 - * we are emulating an Ethernet multicast send, which 535 - * does not require a multicast subscription and will 536 - * still send properly. The most appropriate thing to 518 + * Send-only IB Multicast joins work at the core IB layer but 519 + * require specific SM support. 520 + * We can use such joins here only if the current SM supports that feature. 521 + * However, if not, we emulate an Ethernet multicast send, 522 + * which does not require a multicast subscription and will 523 + * still send properly. The most appropriate thing to 537 524 * do is to create the group if it doesn't exist as that 538 525 * most closely emulates the behavior, from a user space 539 - * application perspecitive, of Ethernet multicast 540 - * operation. For now, we do a full join, maybe later 541 - * when the core IB layers support send only joins we 542 - * will use them. 526 + * application perspective, of Ethernet multicast operation. 543 527 */ 544 - #if 0 545 - if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) 546 - rec.join_state = 4; 547 - #endif 528 + if (test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags) && 529 + priv->sm_fullmember_sendonly_support) 530 + /* SM supports sendonly-fullmember, otherwise fallback to full-member */ 531 + rec.join_state = SENDONLY_FULLMEMBER_JOIN; 548 532 } 549 533 spin_unlock_irq(&priv->lock); 550 534 ··· 582 570 return; 583 571 } 584 572 priv->local_lid = port_attr.lid; 573 + netif_addr_lock(dev); 585 574 586 - if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid, NULL)) 587 - ipoib_warn(priv, "ib_query_gid() failed\n"); 588 - else 589 - memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); 575 + if (!test_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags)) { 576 + netif_addr_unlock(dev); 577 + return; 578 + } 579 + netif_addr_unlock(dev); 590 580 591 581 spin_lock_irq(&priv->lock); 592 582 if (!test_bit(IPOIB_FLAG_OPER_UP, &priv->flags))
+3
drivers/infiniband/ulp/ipoib/ipoib_verbs.c
··· 307 307 queue_work(ipoib_workqueue, &priv->flush_normal); 308 308 } else if (record->event == IB_EVENT_PKEY_CHANGE) { 309 309 queue_work(ipoib_workqueue, &priv->flush_heavy); 310 + } else if (record->event == IB_EVENT_GID_CHANGE && 311 + !test_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags)) { 312 + queue_work(ipoib_workqueue, &priv->flush_light); 310 313 } 311 314 }
+2
drivers/infiniband/ulp/ipoib/ipoib_vlan.c
··· 68 68 priv->pkey = pkey; 69 69 70 70 memcpy(priv->dev->dev_addr, ppriv->dev->dev_addr, INFINIBAND_ALEN); 71 + memcpy(&priv->local_gid, &ppriv->local_gid, sizeof(priv->local_gid)); 72 + set_bit(IPOIB_FLAG_DEV_ADDR_SET, &priv->flags); 71 73 priv->dev->broadcast[8] = pkey >> 8; 72 74 priv->dev->broadcast[9] = pkey & 0xff; 73 75
+1 -1
drivers/infiniband/ulp/srpt/ib_srpt.c
··· 254 254 memset(cif, 0, sizeof(*cif)); 255 255 cif->base_version = 1; 256 256 cif->class_version = 1; 257 - cif->resp_time_value = 20; 258 257 258 + ib_set_cpi_resp_time(cif, 20); 259 259 mad->mad_hdr.status = 0; 260 260 } 261 261
-2
drivers/staging/Kconfig
··· 66 66 67 67 source "drivers/staging/media/Kconfig" 68 68 69 - source "drivers/staging/rdma/Kconfig" 70 - 71 69 source "drivers/staging/android/Kconfig" 72 70 73 71 source "drivers/staging/board/Kconfig"
-1
drivers/staging/Makefile
··· 23 23 obj-$(CONFIG_USB_EMXX) += emxx_udc/ 24 24 obj-$(CONFIG_SPEAKUP) += speakup/ 25 25 obj-$(CONFIG_MFD_NVEC) += nvec/ 26 - obj-$(CONFIG_STAGING_RDMA) += rdma/ 27 26 obj-$(CONFIG_ANDROID) += android/ 28 27 obj-$(CONFIG_STAGING_BOARD) += board/ 29 28 obj-$(CONFIG_LTE_GDM724X) += gdm724x/
-27
drivers/staging/rdma/Kconfig
··· 1 - menuconfig STAGING_RDMA 2 - tristate "RDMA staging drivers" 3 - depends on INFINIBAND 4 - depends on PCI || BROKEN 5 - depends on HAS_IOMEM 6 - depends on NET 7 - depends on INET 8 - default n 9 - ---help--- 10 - This option allows you to select a number of RDMA drivers that 11 - fall into one of two categories: deprecated drivers being held 12 - here before finally being removed or new drivers that still need 13 - some work before being moved to the normal RDMA driver area. 14 - 15 - If you wish to work on these drivers, to help improve them, or 16 - to report problems you have with them, please use the 17 - linux-rdma@vger.kernel.org mailing list. 18 - 19 - If in doubt, say N here. 20 - 21 - 22 - # Please keep entries in alphabetic order 23 - if STAGING_RDMA 24 - 25 - source "drivers/staging/rdma/hfi1/Kconfig" 26 - 27 - endif
-2
drivers/staging/rdma/Makefile
··· 1 - # Entries for RDMA_STAGING tree 2 - obj-$(CONFIG_INFINIBAND_HFI1) += hfi1/
drivers/staging/rdma/hfi1/Kconfig drivers/infiniband/hw/hfi1/Kconfig
+1 -1
drivers/staging/rdma/hfi1/Makefile drivers/infiniband/hw/hfi1/Makefile
··· 7 7 # 8 8 obj-$(CONFIG_INFINIBAND_HFI1) += hfi1.o 9 9 10 - hfi1-y := affinity.o chip.o device.o diag.o driver.o efivar.o \ 10 + hfi1-y := affinity.o chip.o device.o driver.o efivar.o \ 11 11 eprom.o file_ops.o firmware.o \ 12 12 init.o intr.o mad.o mmu_rb.o pcie.o pio.o pio_copy.o platform.o \ 13 13 qp.o qsfp.o rc.o ruc.o sdma.o sysfs.o trace.o twsi.o \
-6
drivers/staging/rdma/hfi1/TODO
··· 1 - July, 2015 2 - 3 - - Remove unneeded file entries in sysfs 4 - - Remove software processing of IB protocol and place in library for use 5 - by qib, ipath (if still present), hfi1, and eventually soft-roce 6 - - Replace incorrect uAPI
drivers/staging/rdma/hfi1/affinity.c drivers/infiniband/hw/hfi1/affinity.c
drivers/staging/rdma/hfi1/affinity.h drivers/infiniband/hw/hfi1/affinity.h
drivers/staging/rdma/hfi1/aspm.h drivers/infiniband/hw/hfi1/aspm.h
+30 -11
drivers/staging/rdma/hfi1/chip.c drivers/infiniband/hw/hfi1/chip.c
··· 1037 1037 static void dc_start(struct hfi1_devdata *); 1038 1038 static int qos_rmt_entries(struct hfi1_devdata *dd, unsigned int *mp, 1039 1039 unsigned int *np); 1040 + static void remove_full_mgmt_pkey(struct hfi1_pportdata *ppd); 1040 1041 1041 1042 /* 1042 1043 * Error interrupt table entry. This is used as input to the interrupt ··· 6106 6105 } 6107 6106 6108 6107 /* this access is valid only when the link is up */ 6109 - if ((ppd->host_link_state & HLS_UP) == 0) { 6108 + if (ppd->host_link_state & HLS_DOWN) { 6110 6109 dd_dev_info(dd, "%s: link state %s not up\n", 6111 6110 __func__, link_state_name(ppd->host_link_state)); 6112 6111 ret = -EBUSY; ··· 6962 6961 } 6963 6962 6964 6963 reset_neighbor_info(ppd); 6964 + if (ppd->mgmt_allowed) 6965 + remove_full_mgmt_pkey(ppd); 6965 6966 6966 6967 /* disable the port */ 6967 6968 clear_rcvctrl(ppd->dd, RCV_CTRL_RCV_PORT_ENABLE_SMASK); ··· 7069 7066 dd_dev_warn(dd, "%s pkey[2] already set to 0x%x, resetting it to 0x%x\n", 7070 7067 __func__, ppd->pkeys[2], FULL_MGMT_P_KEY); 7071 7068 ppd->pkeys[2] = FULL_MGMT_P_KEY; 7069 + (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0); 7070 + } 7071 + 7072 + static void remove_full_mgmt_pkey(struct hfi1_pportdata *ppd) 7073 + { 7074 + ppd->pkeys[2] = 0; 7072 7075 (void)hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_PKEYS, 0); 7073 7076 } 7074 7077 ··· 7438 7429 retry: 7439 7430 mutex_lock(&ppd->hls_lock); 7440 7431 /* only apply if the link is up */ 7441 - if (!(ppd->host_link_state & HLS_UP)) { 7432 + if (ppd->host_link_state & HLS_DOWN) { 7442 7433 /* still going up..wait and retry */ 7443 7434 if (ppd->host_link_state & HLS_GOING_UP) { 7444 7435 if (++tries < 1000) { ··· 9221 9212 9222 9213 /* Reset the QSFP */ 9223 9214 mask = (u64)QSFP_HFI0_RESET_N; 9224 - qsfp_mask = read_csr(dd, dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE); 9225 - qsfp_mask |= mask; 9226 - write_csr(dd, dd->hfi1_id ? ASIC_QSFP2_OE : ASIC_QSFP1_OE, qsfp_mask); 9227 9215 9228 9216 qsfp_mask = read_csr(dd, 9229 9217 dd->hfi1_id ? ASIC_QSFP2_OUT : ASIC_QSFP1_OUT); ··· 9257 9251 (qsfp_interrupt_status[0] & QSFP_LOW_TEMP_WARNING)) 9258 9252 dd_dev_info(dd, "%s: QSFP cable temperature too low\n", 9259 9253 __func__); 9254 + 9255 + /* 9256 + * The remaining alarms/warnings don't matter if the link is down. 9257 + */ 9258 + if (ppd->host_link_state & HLS_DOWN) 9259 + return 0; 9260 9260 9261 9261 if ((qsfp_interrupt_status[1] & QSFP_HIGH_VCC_ALARM) || 9262 9262 (qsfp_interrupt_status[1] & QSFP_HIGH_VCC_WARNING)) ··· 9358 9346 return; 9359 9347 9360 9348 /* 9361 - * Turn DC back on after cables has been 9362 - * re-inserted. Up until now, the DC has been in 9363 - * reset to save power. 9349 + * Turn DC back on after cable has been re-inserted. Up until 9350 + * now, the DC has been in reset to save power. 9364 9351 */ 9365 9352 dc_start(dd); 9366 9353 ··· 9491 9480 return ret; 9492 9481 } 9493 9482 9494 - /* tune the SERDES to a ballpark setting for 9483 + get_port_type(ppd); 9484 + if (ppd->port_type == PORT_TYPE_QSFP) { 9485 + set_qsfp_int_n(ppd, 0); 9486 + wait_for_qsfp_init(ppd); 9487 + set_qsfp_int_n(ppd, 1); 9488 + } 9489 + 9490 + /* 9491 + * Tune the SerDes to a ballpark setting for 9495 9492 * optimal signal and bit error rate 9496 9493 * Needs to be done before starting the link 9497 9494 */ ··· 10093 10074 */ 10094 10075 u32 driver_logical_state(struct hfi1_pportdata *ppd) 10095 10076 { 10096 - if (ppd->host_link_state && !(ppd->host_link_state & HLS_UP)) 10077 + if (ppd->host_link_state && (ppd->host_link_state & HLS_DOWN)) 10097 10078 return IB_PORT_DOWN; 10098 10079 10099 10080 switch (ppd->host_link_state & HLS_UP) { ··· 14597 14578 (reason), (ret)) 14598 14579 14599 14580 /* 14600 - * Initialize the Avago Thermal sensor. 14581 + * Initialize the thermal sensor. 14601 14582 * 14602 14583 * After initialization, enable polling of thermal sensor through 14603 14584 * SBus interface. In order for this to work, the SBus Master
+6
drivers/staging/rdma/hfi1/chip.h drivers/infiniband/hw/hfi1/chip.h
··· 398 398 /* Lane ID for general configuration registers */ 399 399 #define GENERAL_CONFIG 4 400 400 401 + /* LINK_TUNING_PARAMETERS fields */ 402 + #define TUNING_METHOD_SHIFT 24 403 + 404 + /* LINK_OPTIMIZATION_SETTINGS fields */ 405 + #define ENABLE_EXT_DEV_CONFIG_SHIFT 24 406 + 401 407 /* LOAD_DATA 8051 command shifts and fields */ 402 408 #define LOAD_DATA_FIELD_ID_SHIFT 40 403 409 #define LOAD_DATA_FIELD_ID_MASK 0xfull
drivers/staging/rdma/hfi1/chip_registers.h drivers/infiniband/hw/hfi1/chip_registers.h
+4 -1
drivers/staging/rdma/hfi1/common.h drivers/infiniband/hw/hfi1/common.h
··· 178 178 HFI1_CAP_PKEY_CHECK | \ 179 179 HFI1_CAP_NO_INTEGRITY) 180 180 181 - #define HFI1_USER_SWVERSION ((HFI1_USER_SWMAJOR << 16) | HFI1_USER_SWMINOR) 181 + #define HFI1_USER_SWVERSION ((HFI1_USER_SWMAJOR << HFI1_SWMAJOR_SHIFT) | \ 182 + HFI1_USER_SWMINOR) 182 183 183 184 #ifndef HFI1_KERN_TYPE 184 185 #define HFI1_KERN_TYPE 0 ··· 349 348 #define HFI1_BECN_SHIFT 30 350 349 #define HFI1_BECN_MASK 1 351 350 #define HFI1_BECN_SMASK BIT(HFI1_BECN_SHIFT) 351 + 352 + #define HFI1_PSM_IOC_BASE_SEQ 0x0 352 353 353 354 static inline __u64 rhf_to_cpu(const __le32 *rbuf) 354 355 {
drivers/staging/rdma/hfi1/debugfs.c drivers/infiniband/hw/hfi1/debugfs.c
drivers/staging/rdma/hfi1/debugfs.h drivers/infiniband/hw/hfi1/debugfs.h
+10 -8
drivers/staging/rdma/hfi1/device.c drivers/infiniband/hw/hfi1/device.c
··· 60 60 int hfi1_cdev_init(int minor, const char *name, 61 61 const struct file_operations *fops, 62 62 struct cdev *cdev, struct device **devp, 63 - bool user_accessible) 63 + bool user_accessible, 64 + struct kobject *parent) 64 65 { 65 66 const dev_t dev = MKDEV(MAJOR(hfi1_dev), minor); 66 67 struct device *device = NULL; ··· 69 68 70 69 cdev_init(cdev, fops); 71 70 cdev->owner = THIS_MODULE; 71 + cdev->kobj.parent = parent; 72 72 kobject_set_name(&cdev->kobj, name); 73 73 74 74 ret = cdev_add(cdev, dev, 1); ··· 84 82 else 85 83 device = device_create(class, NULL, dev, NULL, "%s", name); 86 84 87 - if (!IS_ERR(device)) 88 - goto done; 89 - ret = PTR_ERR(device); 90 - device = NULL; 91 - pr_err("Could not create device for minor %d, %s (err %d)\n", 92 - minor, name, -ret); 93 - cdev_del(cdev); 85 + if (IS_ERR(device)) { 86 + ret = PTR_ERR(device); 87 + device = NULL; 88 + pr_err("Could not create device for minor %d, %s (err %d)\n", 89 + minor, name, -ret); 90 + cdev_del(cdev); 91 + } 94 92 done: 95 93 *devp = device; 96 94 return ret;
+54 -11
drivers/staging/rdma/hfi1/device.h drivers/infiniband/hw/hfi1/eprom.c
··· 1 - #ifndef _HFI1_DEVICE_H 2 - #define _HFI1_DEVICE_H 3 1 /* 4 2 * Copyright(c) 2015, 2016 Intel Corporation. 5 3 * ··· 44 46 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 47 * 46 48 */ 49 + #include <linux/delay.h> 50 + #include "hfi.h" 51 + #include "common.h" 52 + #include "eprom.h" 47 53 48 - int hfi1_cdev_init(int minor, const char *name, 49 - const struct file_operations *fops, 50 - struct cdev *cdev, struct device **devp, 51 - bool user_accessible); 52 - void hfi1_cdev_cleanup(struct cdev *cdev, struct device **devp); 53 - const char *class_name(void); 54 - int __init dev_init(void); 55 - void dev_cleanup(void); 54 + #define CMD_SHIFT 24 55 + #define CMD_RELEASE_POWERDOWN_NOID ((0xab << CMD_SHIFT)) 56 56 57 - #endif /* _HFI1_DEVICE_H */ 57 + /* controller interface speeds */ 58 + #define EP_SPEED_FULL 0x2 /* full speed */ 59 + 60 + /* 61 + * How long to wait for the EPROM to become available, in ms. 62 + * The spec 32 Mb EPROM takes around 40s to erase then write. 63 + * Double it for safety. 64 + */ 65 + #define EPROM_TIMEOUT 80000 /* ms */ 66 + /* 67 + * Initialize the EPROM handler. 68 + */ 69 + int eprom_init(struct hfi1_devdata *dd) 70 + { 71 + int ret = 0; 72 + 73 + /* only the discrete chip has an EPROM */ 74 + if (dd->pcidev->device != PCI_DEVICE_ID_INTEL0) 75 + return 0; 76 + 77 + /* 78 + * It is OK if both HFIs reset the EPROM as long as they don't 79 + * do it at the same time. 80 + */ 81 + ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT); 82 + if (ret) { 83 + dd_dev_err(dd, 84 + "%s: unable to acquire EPROM resource, no EPROM support\n", 85 + __func__); 86 + goto done_asic; 87 + } 88 + 89 + /* reset EPROM to be sure it is in a good state */ 90 + 91 + /* set reset */ 92 + write_csr(dd, ASIC_EEP_CTL_STAT, ASIC_EEP_CTL_STAT_EP_RESET_SMASK); 93 + /* clear reset, set speed */ 94 + write_csr(dd, ASIC_EEP_CTL_STAT, 95 + EP_SPEED_FULL << ASIC_EEP_CTL_STAT_RATE_SPI_SHIFT); 96 + 97 + /* wake the device with command "release powerdown NoID" */ 98 + write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_RELEASE_POWERDOWN_NOID); 99 + 100 + dd->eprom_available = true; 101 + release_chip_resource(dd, CR_EPROM); 102 + done_asic: 103 + return ret; 104 + }
-1925
drivers/staging/rdma/hfi1/diag.c
··· 1 - /* 2 - * Copyright(c) 2015, 2016 Intel Corporation. 3 - * 4 - * This file is provided under a dual BSD/GPLv2 license. When using or 5 - * redistributing this file, you may do so under either license. 6 - * 7 - * GPL LICENSE SUMMARY 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of version 2 of the GNU General Public License as 11 - * published by the Free Software Foundation. 12 - * 13 - * This program is distributed in the hope that it will be useful, but 14 - * WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 - * General Public License for more details. 17 - * 18 - * BSD LICENSE 19 - * 20 - * Redistribution and use in source and binary forms, with or without 21 - * modification, are permitted provided that the following conditions 22 - * are met: 23 - * 24 - * - Redistributions of source code must retain the above copyright 25 - * notice, this list of conditions and the following disclaimer. 26 - * - Redistributions in binary form must reproduce the above copyright 27 - * notice, this list of conditions and the following disclaimer in 28 - * the documentation and/or other materials provided with the 29 - * distribution. 30 - * - Neither the name of Intel Corporation nor the names of its 31 - * contributors may be used to endorse or promote products derived 32 - * from this software without specific prior written permission. 33 - * 34 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 35 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 37 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 38 - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 41 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 - * 46 - */ 47 - 48 - /* 49 - * This file contains support for diagnostic functions. It is accessed by 50 - * opening the hfi1_diag device, normally minor number 129. Diagnostic use 51 - * of the chip may render the chip or board unusable until the driver 52 - * is unloaded, or in some cases, until the system is rebooted. 53 - * 54 - * Accesses to the chip through this interface are not similar to going 55 - * through the /sys/bus/pci resource mmap interface. 56 - */ 57 - 58 - #include <linux/io.h> 59 - #include <linux/pci.h> 60 - #include <linux/poll.h> 61 - #include <linux/vmalloc.h> 62 - #include <linux/export.h> 63 - #include <linux/fs.h> 64 - #include <linux/uaccess.h> 65 - #include <linux/module.h> 66 - #include <rdma/ib_smi.h> 67 - #include "hfi.h" 68 - #include "device.h" 69 - #include "common.h" 70 - #include "verbs_txreq.h" 71 - #include "trace.h" 72 - 73 - #undef pr_fmt 74 - #define pr_fmt(fmt) DRIVER_NAME ": " fmt 75 - #define snoop_dbg(fmt, ...) \ 76 - hfi1_cdbg(SNOOP, fmt, ##__VA_ARGS__) 77 - 78 - /* Snoop option mask */ 79 - #define SNOOP_DROP_SEND BIT(0) 80 - #define SNOOP_USE_METADATA BIT(1) 81 - #define SNOOP_SET_VL0TOVL15 BIT(2) 82 - 83 - static u8 snoop_flags; 84 - 85 - /* 86 - * Extract packet length from LRH header. 87 - * This is in Dwords so multiply by 4 to get size in bytes 88 - */ 89 - #define HFI1_GET_PKT_LEN(x) (((be16_to_cpu((x)->lrh[2]) & 0xFFF)) << 2) 90 - 91 - enum hfi1_filter_status { 92 - HFI1_FILTER_HIT, 93 - HFI1_FILTER_ERR, 94 - HFI1_FILTER_MISS 95 - }; 96 - 97 - /* snoop processing functions */ 98 - rhf_rcv_function_ptr snoop_rhf_rcv_functions[8] = { 99 - [RHF_RCV_TYPE_EXPECTED] = snoop_recv_handler, 100 - [RHF_RCV_TYPE_EAGER] = snoop_recv_handler, 101 - [RHF_RCV_TYPE_IB] = snoop_recv_handler, 102 - [RHF_RCV_TYPE_ERROR] = snoop_recv_handler, 103 - [RHF_RCV_TYPE_BYPASS] = snoop_recv_handler, 104 - [RHF_RCV_TYPE_INVALID5] = process_receive_invalid, 105 - [RHF_RCV_TYPE_INVALID6] = process_receive_invalid, 106 - [RHF_RCV_TYPE_INVALID7] = process_receive_invalid 107 - }; 108 - 109 - /* Snoop packet structure */ 110 - struct snoop_packet { 111 - struct list_head list; 112 - u32 total_len; 113 - u8 data[]; 114 - }; 115 - 116 - /* Do not make these an enum or it will blow up the capture_md */ 117 - #define PKT_DIR_EGRESS 0x0 118 - #define PKT_DIR_INGRESS 0x1 119 - 120 - /* Packet capture metadata returned to the user with the packet. */ 121 - struct capture_md { 122 - u8 port; 123 - u8 dir; 124 - u8 reserved[6]; 125 - union { 126 - u64 pbc; 127 - u64 rhf; 128 - } u; 129 - }; 130 - 131 - static atomic_t diagpkt_count = ATOMIC_INIT(0); 132 - static struct cdev diagpkt_cdev; 133 - static struct device *diagpkt_device; 134 - 135 - static ssize_t diagpkt_write(struct file *fp, const char __user *data, 136 - size_t count, loff_t *off); 137 - 138 - static const struct file_operations diagpkt_file_ops = { 139 - .owner = THIS_MODULE, 140 - .write = diagpkt_write, 141 - .llseek = noop_llseek, 142 - }; 143 - 144 - /* 145 - * This is used for communication with user space for snoop extended IOCTLs 146 - */ 147 - struct hfi1_link_info { 148 - __be64 node_guid; 149 - u8 port_mode; 150 - u8 port_state; 151 - u16 link_speed_active; 152 - u16 link_width_active; 153 - u16 vl15_init; 154 - u8 port_number; 155 - /* 156 - * Add padding to make this a full IB SMP payload. Note: changing the 157 - * size of this structure will make the IOCTLs created with _IOWR 158 - * change. 159 - * Be sure to run tests on all IOCTLs when making changes to this 160 - * structure. 161 - */ 162 - u8 res[47]; 163 - }; 164 - 165 - /* 166 - * This starts our ioctl sequence numbers *way* off from the ones 167 - * defined in ib_core. 168 - */ 169 - #define SNOOP_CAPTURE_VERSION 0x1 170 - 171 - #define IB_IOCTL_MAGIC 0x1b /* See Documentation/ioctl-number.txt */ 172 - #define HFI1_SNOOP_IOC_MAGIC IB_IOCTL_MAGIC 173 - #define HFI1_SNOOP_IOC_BASE_SEQ 0x80 174 - 175 - #define HFI1_SNOOP_IOCGETLINKSTATE \ 176 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ) 177 - #define HFI1_SNOOP_IOCSETLINKSTATE \ 178 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 1) 179 - #define HFI1_SNOOP_IOCCLEARQUEUE \ 180 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 2) 181 - #define HFI1_SNOOP_IOCCLEARFILTER \ 182 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 3) 183 - #define HFI1_SNOOP_IOCSETFILTER \ 184 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 4) 185 - #define HFI1_SNOOP_IOCGETVERSION \ 186 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 5) 187 - #define HFI1_SNOOP_IOCSET_OPTS \ 188 - _IO(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 6) 189 - 190 - /* 191 - * These offsets +6/+7 could change, but these are already known and used 192 - * IOCTL numbers so don't change them without a good reason. 193 - */ 194 - #define HFI1_SNOOP_IOCGETLINKSTATE_EXTRA \ 195 - _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 6, \ 196 - struct hfi1_link_info) 197 - #define HFI1_SNOOP_IOCSETLINKSTATE_EXTRA \ 198 - _IOWR(HFI1_SNOOP_IOC_MAGIC, HFI1_SNOOP_IOC_BASE_SEQ + 7, \ 199 - struct hfi1_link_info) 200 - 201 - static int hfi1_snoop_open(struct inode *in, struct file *fp); 202 - static ssize_t hfi1_snoop_read(struct file *fp, char __user *data, 203 - size_t pkt_len, loff_t *off); 204 - static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data, 205 - size_t count, loff_t *off); 206 - static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); 207 - static unsigned int hfi1_snoop_poll(struct file *fp, 208 - struct poll_table_struct *wait); 209 - static int hfi1_snoop_release(struct inode *in, struct file *fp); 210 - 211 - struct hfi1_packet_filter_command { 212 - int opcode; 213 - int length; 214 - void *value_ptr; 215 - }; 216 - 217 - /* Can't re-use PKT_DIR_*GRESS here because 0 means no packets for this */ 218 - #define HFI1_SNOOP_INGRESS 0x1 219 - #define HFI1_SNOOP_EGRESS 0x2 220 - 221 - enum hfi1_packet_filter_opcodes { 222 - FILTER_BY_LID, 223 - FILTER_BY_DLID, 224 - FILTER_BY_MAD_MGMT_CLASS, 225 - FILTER_BY_QP_NUMBER, 226 - FILTER_BY_PKT_TYPE, 227 - FILTER_BY_SERVICE_LEVEL, 228 - FILTER_BY_PKEY, 229 - FILTER_BY_DIRECTION, 230 - }; 231 - 232 - static const struct file_operations snoop_file_ops = { 233 - .owner = THIS_MODULE, 234 - .open = hfi1_snoop_open, 235 - .read = hfi1_snoop_read, 236 - .unlocked_ioctl = hfi1_ioctl, 237 - .poll = hfi1_snoop_poll, 238 - .write = hfi1_snoop_write, 239 - .release = hfi1_snoop_release 240 - }; 241 - 242 - struct hfi1_filter_array { 243 - int (*filter)(void *, void *, void *); 244 - }; 245 - 246 - static int hfi1_filter_lid(void *ibhdr, void *packet_data, void *value); 247 - static int hfi1_filter_dlid(void *ibhdr, void *packet_data, void *value); 248 - static int hfi1_filter_mad_mgmt_class(void *ibhdr, void *packet_data, 249 - void *value); 250 - static int hfi1_filter_qp_number(void *ibhdr, void *packet_data, void *value); 251 - static int hfi1_filter_ibpacket_type(void *ibhdr, void *packet_data, 252 - void *value); 253 - static int hfi1_filter_ib_service_level(void *ibhdr, void *packet_data, 254 - void *value); 255 - static int hfi1_filter_ib_pkey(void *ibhdr, void *packet_data, void *value); 256 - static int hfi1_filter_direction(void *ibhdr, void *packet_data, void *value); 257 - 258 - static const struct hfi1_filter_array hfi1_filters[] = { 259 - { hfi1_filter_lid }, 260 - { hfi1_filter_dlid }, 261 - { hfi1_filter_mad_mgmt_class }, 262 - { hfi1_filter_qp_number }, 263 - { hfi1_filter_ibpacket_type }, 264 - { hfi1_filter_ib_service_level }, 265 - { hfi1_filter_ib_pkey }, 266 - { hfi1_filter_direction }, 267 - }; 268 - 269 - #define HFI1_MAX_FILTERS ARRAY_SIZE(hfi1_filters) 270 - #define HFI1_DIAG_MINOR_BASE 129 271 - 272 - static int hfi1_snoop_add(struct hfi1_devdata *dd, const char *name); 273 - 274 - int hfi1_diag_add(struct hfi1_devdata *dd) 275 - { 276 - char name[16]; 277 - int ret = 0; 278 - 279 - snprintf(name, sizeof(name), "%s_diagpkt%d", class_name(), 280 - dd->unit); 281 - /* 282 - * Do this for each device as opposed to the normal diagpkt 283 - * interface which is one per host 284 - */ 285 - ret = hfi1_snoop_add(dd, name); 286 - if (ret) 287 - dd_dev_err(dd, "Unable to init snoop/capture device"); 288 - 289 - snprintf(name, sizeof(name), "%s_diagpkt", class_name()); 290 - if (atomic_inc_return(&diagpkt_count) == 1) { 291 - ret = hfi1_cdev_init(HFI1_DIAGPKT_MINOR, name, 292 - &diagpkt_file_ops, &diagpkt_cdev, 293 - &diagpkt_device, false); 294 - } 295 - 296 - return ret; 297 - } 298 - 299 - /* this must be called w/ dd->snoop_in_lock held */ 300 - static void drain_snoop_list(struct list_head *queue) 301 - { 302 - struct list_head *pos, *q; 303 - struct snoop_packet *packet; 304 - 305 - list_for_each_safe(pos, q, queue) { 306 - packet = list_entry(pos, struct snoop_packet, list); 307 - list_del(pos); 308 - kfree(packet); 309 - } 310 - } 311 - 312 - static void hfi1_snoop_remove(struct hfi1_devdata *dd) 313 - { 314 - unsigned long flags = 0; 315 - 316 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 317 - drain_snoop_list(&dd->hfi1_snoop.queue); 318 - hfi1_cdev_cleanup(&dd->hfi1_snoop.cdev, &dd->hfi1_snoop.class_dev); 319 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 320 - } 321 - 322 - void hfi1_diag_remove(struct hfi1_devdata *dd) 323 - { 324 - hfi1_snoop_remove(dd); 325 - if (atomic_dec_and_test(&diagpkt_count)) 326 - hfi1_cdev_cleanup(&diagpkt_cdev, &diagpkt_device); 327 - hfi1_cdev_cleanup(&dd->diag_cdev, &dd->diag_device); 328 - } 329 - 330 - /* 331 - * Allocated structure shared between the credit return mechanism and 332 - * diagpkt_send(). 333 - */ 334 - struct diagpkt_wait { 335 - struct completion credits_returned; 336 - int code; 337 - atomic_t count; 338 - }; 339 - 340 - /* 341 - * When each side is finished with the structure, they call this. 342 - * The last user frees the structure. 343 - */ 344 - static void put_diagpkt_wait(struct diagpkt_wait *wait) 345 - { 346 - if (atomic_dec_and_test(&wait->count)) 347 - kfree(wait); 348 - } 349 - 350 - /* 351 - * Callback from the credit return code. Set the complete, which 352 - * will let diapkt_send() continue. 353 - */ 354 - static void diagpkt_complete(void *arg, int code) 355 - { 356 - struct diagpkt_wait *wait = (struct diagpkt_wait *)arg; 357 - 358 - wait->code = code; 359 - complete(&wait->credits_returned); 360 - put_diagpkt_wait(wait); /* finished with the structure */ 361 - } 362 - 363 - /** 364 - * diagpkt_send - send a packet 365 - * @dp: diag packet descriptor 366 - */ 367 - static ssize_t diagpkt_send(struct diag_pkt *dp) 368 - { 369 - struct hfi1_devdata *dd; 370 - struct send_context *sc; 371 - struct pio_buf *pbuf; 372 - u32 *tmpbuf = NULL; 373 - ssize_t ret = 0; 374 - u32 pkt_len, total_len; 375 - pio_release_cb credit_cb = NULL; 376 - void *credit_arg = NULL; 377 - struct diagpkt_wait *wait = NULL; 378 - int trycount = 0; 379 - 380 - dd = hfi1_lookup(dp->unit); 381 - if (!dd || !(dd->flags & HFI1_PRESENT) || !dd->kregbase) { 382 - ret = -ENODEV; 383 - goto bail; 384 - } 385 - if (!(dd->flags & HFI1_INITTED)) { 386 - /* no hardware, freeze, etc. */ 387 - ret = -ENODEV; 388 - goto bail; 389 - } 390 - 391 - if (dp->version != _DIAG_PKT_VERS) { 392 - dd_dev_err(dd, "Invalid version %u for diagpkt_write\n", 393 - dp->version); 394 - ret = -EINVAL; 395 - goto bail; 396 - } 397 - 398 - /* send count must be an exact number of dwords */ 399 - if (dp->len & 3) { 400 - ret = -EINVAL; 401 - goto bail; 402 - } 403 - 404 - /* there is only port 1 */ 405 - if (dp->port != 1) { 406 - ret = -EINVAL; 407 - goto bail; 408 - } 409 - 410 - /* need a valid context */ 411 - if (dp->sw_index >= dd->num_send_contexts) { 412 - ret = -EINVAL; 413 - goto bail; 414 - } 415 - /* can only use kernel contexts */ 416 - if (dd->send_contexts[dp->sw_index].type != SC_KERNEL && 417 - dd->send_contexts[dp->sw_index].type != SC_VL15) { 418 - ret = -EINVAL; 419 - goto bail; 420 - } 421 - /* must be allocated */ 422 - sc = dd->send_contexts[dp->sw_index].sc; 423 - if (!sc) { 424 - ret = -EINVAL; 425 - goto bail; 426 - } 427 - /* must be enabled */ 428 - if (!(sc->flags & SCF_ENABLED)) { 429 - ret = -EINVAL; 430 - goto bail; 431 - } 432 - 433 - /* allocate a buffer and copy the data in */ 434 - tmpbuf = vmalloc(dp->len); 435 - if (!tmpbuf) { 436 - ret = -ENOMEM; 437 - goto bail; 438 - } 439 - 440 - if (copy_from_user(tmpbuf, 441 - (const void __user *)(unsigned long)dp->data, 442 - dp->len)) { 443 - ret = -EFAULT; 444 - goto bail; 445 - } 446 - 447 - /* 448 - * pkt_len is how much data we have to write, includes header and data. 449 - * total_len is length of the packet in Dwords plus the PBC should not 450 - * include the CRC. 451 - */ 452 - pkt_len = dp->len >> 2; 453 - total_len = pkt_len + 2; /* PBC + packet */ 454 - 455 - /* if 0, fill in a default */ 456 - if (dp->pbc == 0) { 457 - struct hfi1_pportdata *ppd = dd->pport; 458 - 459 - hfi1_cdbg(PKT, "Generating PBC"); 460 - dp->pbc = create_pbc(ppd, 0, 0, 0, total_len); 461 - } else { 462 - hfi1_cdbg(PKT, "Using passed in PBC"); 463 - } 464 - 465 - hfi1_cdbg(PKT, "Egress PBC content is 0x%llx", dp->pbc); 466 - 467 - /* 468 - * The caller wants to wait until the packet is sent and to 469 - * check for errors. The best we can do is wait until 470 - * the buffer credits are returned and check if any packet 471 - * error has occurred. If there are any late errors, this 472 - * could miss it. If there are other senders who generate 473 - * an error, this may find it. However, in general, it 474 - * should catch most. 475 - */ 476 - if (dp->flags & F_DIAGPKT_WAIT) { 477 - /* always force a credit return */ 478 - dp->pbc |= PBC_CREDIT_RETURN; 479 - /* turn on credit return interrupts */ 480 - sc_add_credit_return_intr(sc); 481 - wait = kmalloc(sizeof(*wait), GFP_KERNEL); 482 - if (!wait) { 483 - ret = -ENOMEM; 484 - goto bail; 485 - } 486 - init_completion(&wait->credits_returned); 487 - atomic_set(&wait->count, 2); 488 - wait->code = PRC_OK; 489 - 490 - credit_cb = diagpkt_complete; 491 - credit_arg = wait; 492 - } 493 - 494 - retry: 495 - pbuf = sc_buffer_alloc(sc, total_len, credit_cb, credit_arg); 496 - if (!pbuf) { 497 - if (trycount == 0) { 498 - /* force a credit return and try again */ 499 - sc_return_credits(sc); 500 - trycount = 1; 501 - goto retry; 502 - } 503 - /* 504 - * No send buffer means no credit callback. Undo 505 - * the wait set-up that was done above. We free wait 506 - * because the callback will never be called. 507 - */ 508 - if (dp->flags & F_DIAGPKT_WAIT) { 509 - sc_del_credit_return_intr(sc); 510 - kfree(wait); 511 - wait = NULL; 512 - } 513 - ret = -ENOSPC; 514 - goto bail; 515 - } 516 - 517 - pio_copy(dd, pbuf, dp->pbc, tmpbuf, pkt_len); 518 - /* no flush needed as the HW knows the packet size */ 519 - 520 - ret = sizeof(*dp); 521 - 522 - if (dp->flags & F_DIAGPKT_WAIT) { 523 - /* wait for credit return */ 524 - ret = wait_for_completion_interruptible( 525 - &wait->credits_returned); 526 - /* 527 - * If the wait returns an error, the wait was interrupted, 528 - * e.g. with a ^C in the user program. The callback is 529 - * still pending. This is OK as the wait structure is 530 - * kmalloc'ed and the structure will free itself when 531 - * all users are done with it. 532 - * 533 - * A context disable occurs on a send context restart, so 534 - * include that in the list of errors below to check for. 535 - * NOTE: PRC_FILL_ERR is at best informational and cannot 536 - * be depended on. 537 - */ 538 - if (!ret && (((wait->code & PRC_STATUS_ERR) || 539 - (wait->code & PRC_FILL_ERR) || 540 - (wait->code & PRC_SC_DISABLE)))) 541 - ret = -EIO; 542 - 543 - put_diagpkt_wait(wait); /* finished with the structure */ 544 - sc_del_credit_return_intr(sc); 545 - } 546 - 547 - bail: 548 - vfree(tmpbuf); 549 - return ret; 550 - } 551 - 552 - static ssize_t diagpkt_write(struct file *fp, const char __user *data, 553 - size_t count, loff_t *off) 554 - { 555 - struct hfi1_devdata *dd; 556 - struct send_context *sc; 557 - u8 vl; 558 - 559 - struct diag_pkt dp; 560 - 561 - if (count != sizeof(dp)) 562 - return -EINVAL; 563 - 564 - if (copy_from_user(&dp, data, sizeof(dp))) 565 - return -EFAULT; 566 - 567 - /* 568 - * The Send Context is derived from the PbcVL value 569 - * if PBC is populated 570 - */ 571 - if (dp.pbc) { 572 - dd = hfi1_lookup(dp.unit); 573 - if (!dd) 574 - return -ENODEV; 575 - vl = (dp.pbc >> PBC_VL_SHIFT) & PBC_VL_MASK; 576 - sc = dd->vld[vl].sc; 577 - if (sc) { 578 - dp.sw_index = sc->sw_index; 579 - hfi1_cdbg( 580 - PKT, 581 - "Packet sent over VL %d via Send Context %u(%u)", 582 - vl, sc->sw_index, sc->hw_context); 583 - } 584 - } 585 - 586 - return diagpkt_send(&dp); 587 - } 588 - 589 - static int hfi1_snoop_add(struct hfi1_devdata *dd, const char *name) 590 - { 591 - int ret = 0; 592 - 593 - dd->hfi1_snoop.mode_flag = 0; 594 - spin_lock_init(&dd->hfi1_snoop.snoop_lock); 595 - INIT_LIST_HEAD(&dd->hfi1_snoop.queue); 596 - init_waitqueue_head(&dd->hfi1_snoop.waitq); 597 - 598 - ret = hfi1_cdev_init(HFI1_SNOOP_CAPTURE_BASE + dd->unit, name, 599 - &snoop_file_ops, 600 - &dd->hfi1_snoop.cdev, &dd->hfi1_snoop.class_dev, 601 - false); 602 - 603 - if (ret) { 604 - dd_dev_err(dd, "Couldn't create %s device: %d", name, ret); 605 - hfi1_cdev_cleanup(&dd->hfi1_snoop.cdev, 606 - &dd->hfi1_snoop.class_dev); 607 - } 608 - 609 - return ret; 610 - } 611 - 612 - static struct hfi1_devdata *hfi1_dd_from_sc_inode(struct inode *in) 613 - { 614 - int unit = iminor(in) - HFI1_SNOOP_CAPTURE_BASE; 615 - struct hfi1_devdata *dd; 616 - 617 - dd = hfi1_lookup(unit); 618 - return dd; 619 - } 620 - 621 - /* clear or restore send context integrity checks */ 622 - static void adjust_integrity_checks(struct hfi1_devdata *dd) 623 - { 624 - struct send_context *sc; 625 - unsigned long sc_flags; 626 - int i; 627 - 628 - spin_lock_irqsave(&dd->sc_lock, sc_flags); 629 - for (i = 0; i < dd->num_send_contexts; i++) { 630 - int enable; 631 - 632 - sc = dd->send_contexts[i].sc; 633 - 634 - if (!sc) 635 - continue; /* not allocated */ 636 - 637 - enable = likely(!HFI1_CAP_IS_KSET(NO_INTEGRITY)) && 638 - dd->hfi1_snoop.mode_flag != HFI1_PORT_SNOOP_MODE; 639 - 640 - set_pio_integrity(sc); 641 - 642 - if (enable) /* take HFI_CAP_* flags into account */ 643 - hfi1_init_ctxt(sc); 644 - } 645 - spin_unlock_irqrestore(&dd->sc_lock, sc_flags); 646 - } 647 - 648 - static int hfi1_snoop_open(struct inode *in, struct file *fp) 649 - { 650 - int ret; 651 - int mode_flag = 0; 652 - unsigned long flags = 0; 653 - struct hfi1_devdata *dd; 654 - struct list_head *queue; 655 - 656 - mutex_lock(&hfi1_mutex); 657 - 658 - dd = hfi1_dd_from_sc_inode(in); 659 - if (!dd) { 660 - ret = -ENODEV; 661 - goto bail; 662 - } 663 - 664 - /* 665 - * File mode determines snoop or capture. Some existing user 666 - * applications expect the capture device to be able to be opened RDWR 667 - * because they expect a dedicated capture device. For this reason we 668 - * support a module param to force capture mode even if the file open 669 - * mode matches snoop. 670 - */ 671 - if ((fp->f_flags & O_ACCMODE) == O_RDONLY) { 672 - snoop_dbg("Capture Enabled"); 673 - mode_flag = HFI1_PORT_CAPTURE_MODE; 674 - } else if ((fp->f_flags & O_ACCMODE) == O_RDWR) { 675 - snoop_dbg("Snoop Enabled"); 676 - mode_flag = HFI1_PORT_SNOOP_MODE; 677 - } else { 678 - snoop_dbg("Invalid"); 679 - ret = -EINVAL; 680 - goto bail; 681 - } 682 - queue = &dd->hfi1_snoop.queue; 683 - 684 - /* 685 - * We are not supporting snoop and capture at the same time. 686 - */ 687 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 688 - if (dd->hfi1_snoop.mode_flag) { 689 - ret = -EBUSY; 690 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 691 - goto bail; 692 - } 693 - 694 - dd->hfi1_snoop.mode_flag = mode_flag; 695 - drain_snoop_list(queue); 696 - 697 - dd->hfi1_snoop.filter_callback = NULL; 698 - dd->hfi1_snoop.filter_value = NULL; 699 - 700 - /* 701 - * Send side packet integrity checks are not helpful when snooping so 702 - * disable and re-enable when we stop snooping. 703 - */ 704 - if (mode_flag == HFI1_PORT_SNOOP_MODE) { 705 - /* clear after snoop mode is on */ 706 - adjust_integrity_checks(dd); /* clear */ 707 - 708 - /* 709 - * We also do not want to be doing the DLID LMC check for 710 - * ingressed packets. 711 - */ 712 - dd->hfi1_snoop.dcc_cfg = read_csr(dd, DCC_CFG_PORT_CONFIG1); 713 - write_csr(dd, DCC_CFG_PORT_CONFIG1, 714 - (dd->hfi1_snoop.dcc_cfg >> 32) << 32); 715 - } 716 - 717 - /* 718 - * As soon as we set these function pointers the recv and send handlers 719 - * are active. This is a race condition so we must make sure to drain 720 - * the queue and init filter values above. Technically we should add 721 - * locking here but all that will happen is on recv a packet will get 722 - * allocated and get stuck on the snoop_lock before getting added to the 723 - * queue. Same goes for send. 724 - */ 725 - dd->rhf_rcv_function_map = snoop_rhf_rcv_functions; 726 - dd->process_pio_send = snoop_send_pio_handler; 727 - dd->process_dma_send = snoop_send_pio_handler; 728 - dd->pio_inline_send = snoop_inline_pio_send; 729 - 730 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 731 - ret = 0; 732 - 733 - bail: 734 - mutex_unlock(&hfi1_mutex); 735 - 736 - return ret; 737 - } 738 - 739 - static int hfi1_snoop_release(struct inode *in, struct file *fp) 740 - { 741 - unsigned long flags = 0; 742 - struct hfi1_devdata *dd; 743 - int mode_flag; 744 - 745 - dd = hfi1_dd_from_sc_inode(in); 746 - if (!dd) 747 - return -ENODEV; 748 - 749 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 750 - 751 - /* clear the snoop mode before re-adjusting send context CSRs */ 752 - mode_flag = dd->hfi1_snoop.mode_flag; 753 - dd->hfi1_snoop.mode_flag = 0; 754 - 755 - /* 756 - * Drain the queue and clear the filters we are done with it. Don't 757 - * forget to restore the packet integrity checks 758 - */ 759 - drain_snoop_list(&dd->hfi1_snoop.queue); 760 - if (mode_flag == HFI1_PORT_SNOOP_MODE) { 761 - /* restore after snoop mode is clear */ 762 - adjust_integrity_checks(dd); /* restore */ 763 - 764 - /* 765 - * Also should probably reset the DCC_CONFIG1 register for DLID 766 - * checking on incoming packets again. Use the value saved when 767 - * opening the snoop device. 768 - */ 769 - write_csr(dd, DCC_CFG_PORT_CONFIG1, dd->hfi1_snoop.dcc_cfg); 770 - } 771 - 772 - dd->hfi1_snoop.filter_callback = NULL; 773 - kfree(dd->hfi1_snoop.filter_value); 774 - dd->hfi1_snoop.filter_value = NULL; 775 - 776 - /* 777 - * User is done snooping and capturing, return control to the normal 778 - * handler. Re-enable SDMA handling. 779 - */ 780 - dd->rhf_rcv_function_map = dd->normal_rhf_rcv_functions; 781 - dd->process_pio_send = hfi1_verbs_send_pio; 782 - dd->process_dma_send = hfi1_verbs_send_dma; 783 - dd->pio_inline_send = pio_copy; 784 - 785 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 786 - 787 - snoop_dbg("snoop/capture device released"); 788 - 789 - return 0; 790 - } 791 - 792 - static unsigned int hfi1_snoop_poll(struct file *fp, 793 - struct poll_table_struct *wait) 794 - { 795 - int ret = 0; 796 - unsigned long flags = 0; 797 - 798 - struct hfi1_devdata *dd; 799 - 800 - dd = hfi1_dd_from_sc_inode(fp->f_inode); 801 - if (!dd) 802 - return -ENODEV; 803 - 804 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 805 - 806 - poll_wait(fp, &dd->hfi1_snoop.waitq, wait); 807 - if (!list_empty(&dd->hfi1_snoop.queue)) 808 - ret |= POLLIN | POLLRDNORM; 809 - 810 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 811 - return ret; 812 - } 813 - 814 - static ssize_t hfi1_snoop_write(struct file *fp, const char __user *data, 815 - size_t count, loff_t *off) 816 - { 817 - struct diag_pkt dpkt; 818 - struct hfi1_devdata *dd; 819 - size_t ret; 820 - u8 byte_two, sl, sc5, sc4, vl, byte_one; 821 - struct send_context *sc; 822 - u32 len; 823 - u64 pbc; 824 - struct hfi1_ibport *ibp; 825 - struct hfi1_pportdata *ppd; 826 - 827 - dd = hfi1_dd_from_sc_inode(fp->f_inode); 828 - if (!dd) 829 - return -ENODEV; 830 - 831 - ppd = dd->pport; 832 - snoop_dbg("received %lu bytes from user", count); 833 - 834 - memset(&dpkt, 0, sizeof(struct diag_pkt)); 835 - dpkt.version = _DIAG_PKT_VERS; 836 - dpkt.unit = dd->unit; 837 - dpkt.port = 1; 838 - 839 - if (likely(!(snoop_flags & SNOOP_USE_METADATA))) { 840 - /* 841 - * We need to generate the PBC and not let diagpkt_send do it, 842 - * to do this we need the VL and the length in dwords. 843 - * The VL can be determined by using the SL and looking up the 844 - * SC. Then the SC can be converted into VL. The exception to 845 - * this is those packets which are from an SMI queue pair. 846 - * Since we can't detect anything about the QP here we have to 847 - * rely on the SC. If its 0xF then we assume its SMI and 848 - * do not look at the SL. 849 - */ 850 - if (copy_from_user(&byte_one, data, 1)) 851 - return -EINVAL; 852 - 853 - if (copy_from_user(&byte_two, data + 1, 1)) 854 - return -EINVAL; 855 - 856 - sc4 = (byte_one >> 4) & 0xf; 857 - if (sc4 == 0xF) { 858 - snoop_dbg("Detected VL15 packet ignoring SL in packet"); 859 - vl = sc4; 860 - } else { 861 - sl = (byte_two >> 4) & 0xf; 862 - ibp = to_iport(&dd->verbs_dev.rdi.ibdev, 1); 863 - sc5 = ibp->sl_to_sc[sl]; 864 - vl = sc_to_vlt(dd, sc5); 865 - if (vl != sc4) { 866 - snoop_dbg("VL %d does not match SC %d of packet", 867 - vl, sc4); 868 - return -EINVAL; 869 - } 870 - } 871 - 872 - sc = dd->vld[vl].sc; /* Look up the context based on VL */ 873 - if (sc) { 874 - dpkt.sw_index = sc->sw_index; 875 - snoop_dbg("Sending on context %u(%u)", sc->sw_index, 876 - sc->hw_context); 877 - } else { 878 - snoop_dbg("Could not find context for vl %d", vl); 879 - return -EINVAL; 880 - } 881 - 882 - len = (count >> 2) + 2; /* Add in PBC */ 883 - pbc = create_pbc(ppd, 0, 0, vl, len); 884 - } else { 885 - if (copy_from_user(&pbc, data, sizeof(pbc))) 886 - return -EINVAL; 887 - vl = (pbc >> PBC_VL_SHIFT) & PBC_VL_MASK; 888 - sc = dd->vld[vl].sc; /* Look up the context based on VL */ 889 - if (sc) { 890 - dpkt.sw_index = sc->sw_index; 891 - } else { 892 - snoop_dbg("Could not find context for vl %d", vl); 893 - return -EINVAL; 894 - } 895 - data += sizeof(pbc); 896 - count -= sizeof(pbc); 897 - } 898 - dpkt.len = count; 899 - dpkt.data = (unsigned long)data; 900 - 901 - snoop_dbg("PBC: vl=0x%llx Length=0x%llx", 902 - (pbc >> 12) & 0xf, 903 - (pbc & 0xfff)); 904 - 905 - dpkt.pbc = pbc; 906 - ret = diagpkt_send(&dpkt); 907 - /* 908 - * diagpkt_send only returns number of bytes in the diagpkt so patch 909 - * that up here before returning. 910 - */ 911 - if (ret == sizeof(dpkt)) 912 - return count; 913 - 914 - return ret; 915 - } 916 - 917 - static ssize_t hfi1_snoop_read(struct file *fp, char __user *data, 918 - size_t pkt_len, loff_t *off) 919 - { 920 - ssize_t ret = 0; 921 - unsigned long flags = 0; 922 - struct snoop_packet *packet = NULL; 923 - struct hfi1_devdata *dd; 924 - 925 - dd = hfi1_dd_from_sc_inode(fp->f_inode); 926 - if (!dd) 927 - return -ENODEV; 928 - 929 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 930 - 931 - while (list_empty(&dd->hfi1_snoop.queue)) { 932 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 933 - 934 - if (fp->f_flags & O_NONBLOCK) 935 - return -EAGAIN; 936 - 937 - if (wait_event_interruptible( 938 - dd->hfi1_snoop.waitq, 939 - !list_empty(&dd->hfi1_snoop.queue))) 940 - return -EINTR; 941 - 942 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 943 - } 944 - 945 - if (!list_empty(&dd->hfi1_snoop.queue)) { 946 - packet = list_entry(dd->hfi1_snoop.queue.next, 947 - struct snoop_packet, list); 948 - list_del(&packet->list); 949 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 950 - if (pkt_len >= packet->total_len) { 951 - if (copy_to_user(data, packet->data, 952 - packet->total_len)) 953 - ret = -EFAULT; 954 - else 955 - ret = packet->total_len; 956 - } else { 957 - ret = -EINVAL; 958 - } 959 - 960 - kfree(packet); 961 - } else { 962 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 963 - } 964 - 965 - return ret; 966 - } 967 - 968 - /** 969 - * hfi1_assign_snoop_link_credits -- Set up credits for VL15 and others 970 - * @ppd : ptr to hfi1 port data 971 - * @value : options from user space 972 - * 973 - * Assumes the rest of the CM credit registers are zero from a 974 - * previous global or credit reset. 975 - * Leave shared count at zero for both global and all vls. 976 - * In snoop mode ideally we don't use shared credits 977 - * Reserve 8.5k for VL15 978 - * If total credits less than 8.5kbytes return error. 979 - * Divide the rest of the credits across VL0 to VL7 and if 980 - * each of these levels has less than 34 credits (at least 2048 + 128 bytes) 981 - * return with an error. 982 - * The credit registers will be reset to zero on link negotiation or link up 983 - * so this function should be activated from user space only if the port has 984 - * gone past link negotiation and link up. 985 - * 986 - * Return -- 0 if successful else error condition 987 - * 988 - */ 989 - static long hfi1_assign_snoop_link_credits(struct hfi1_pportdata *ppd, 990 - int value) 991 - { 992 - #define OPA_MIN_PER_VL_CREDITS 34 /* 2048 + 128 bytes */ 993 - struct buffer_control t; 994 - int i; 995 - struct hfi1_devdata *dd = ppd->dd; 996 - u16 total_credits = (value >> 16) & 0xffff; 997 - u16 vl15_credits = dd->vl15_init / 2; 998 - u16 per_vl_credits; 999 - __be16 be_per_vl_credits; 1000 - 1001 - if (!(ppd->host_link_state & HLS_UP)) 1002 - goto err_exit; 1003 - if (total_credits < vl15_credits) 1004 - goto err_exit; 1005 - 1006 - per_vl_credits = (total_credits - vl15_credits) / TXE_NUM_DATA_VL; 1007 - 1008 - if (per_vl_credits < OPA_MIN_PER_VL_CREDITS) 1009 - goto err_exit; 1010 - 1011 - memset(&t, 0, sizeof(t)); 1012 - be_per_vl_credits = cpu_to_be16(per_vl_credits); 1013 - 1014 - for (i = 0; i < TXE_NUM_DATA_VL; i++) 1015 - t.vl[i].dedicated = be_per_vl_credits; 1016 - 1017 - t.vl[15].dedicated = cpu_to_be16(vl15_credits); 1018 - return set_buffer_control(ppd, &t); 1019 - 1020 - err_exit: 1021 - snoop_dbg("port_state = 0x%x, total_credits = %d, vl15_credits = %d", 1022 - ppd->host_link_state, total_credits, vl15_credits); 1023 - 1024 - return -EINVAL; 1025 - } 1026 - 1027 - static long hfi1_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) 1028 - { 1029 - struct hfi1_devdata *dd; 1030 - void *filter_value = NULL; 1031 - long ret = 0; 1032 - int value = 0; 1033 - u8 phys_state = 0; 1034 - u8 link_state = 0; 1035 - u16 dev_state = 0; 1036 - unsigned long flags = 0; 1037 - unsigned long *argp = NULL; 1038 - struct hfi1_packet_filter_command filter_cmd = {0}; 1039 - int mode_flag = 0; 1040 - struct hfi1_pportdata *ppd = NULL; 1041 - unsigned int index; 1042 - struct hfi1_link_info link_info; 1043 - int read_cmd, write_cmd, read_ok, write_ok; 1044 - 1045 - dd = hfi1_dd_from_sc_inode(fp->f_inode); 1046 - if (!dd) 1047 - return -ENODEV; 1048 - 1049 - mode_flag = dd->hfi1_snoop.mode_flag; 1050 - read_cmd = _IOC_DIR(cmd) & _IOC_READ; 1051 - write_cmd = _IOC_DIR(cmd) & _IOC_WRITE; 1052 - write_ok = access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd)); 1053 - read_ok = access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd)); 1054 - 1055 - if ((read_cmd && !write_ok) || (write_cmd && !read_ok)) 1056 - return -EFAULT; 1057 - 1058 - if (!capable(CAP_SYS_ADMIN)) 1059 - return -EPERM; 1060 - 1061 - if ((mode_flag & HFI1_PORT_CAPTURE_MODE) && 1062 - (cmd != HFI1_SNOOP_IOCCLEARQUEUE) && 1063 - (cmd != HFI1_SNOOP_IOCCLEARFILTER) && 1064 - (cmd != HFI1_SNOOP_IOCSETFILTER)) 1065 - /* Capture devices are allowed only 3 operations 1066 - * 1.Clear capture queue 1067 - * 2.Clear capture filter 1068 - * 3.Set capture filter 1069 - * Other are invalid. 1070 - */ 1071 - return -EINVAL; 1072 - 1073 - switch (cmd) { 1074 - case HFI1_SNOOP_IOCSETLINKSTATE_EXTRA: 1075 - memset(&link_info, 0, sizeof(link_info)); 1076 - 1077 - if (copy_from_user(&link_info, 1078 - (struct hfi1_link_info __user *)arg, 1079 - sizeof(link_info))) 1080 - return -EFAULT; 1081 - 1082 - value = link_info.port_state; 1083 - index = link_info.port_number; 1084 - if (index > dd->num_pports - 1) 1085 - return -EINVAL; 1086 - 1087 - ppd = &dd->pport[index]; 1088 - if (!ppd) 1089 - return -EINVAL; 1090 - 1091 - /* What we want to transition to */ 1092 - phys_state = (value >> 4) & 0xF; 1093 - link_state = value & 0xF; 1094 - snoop_dbg("Setting link state 0x%x", value); 1095 - 1096 - switch (link_state) { 1097 - case IB_PORT_NOP: 1098 - if (phys_state == 0) 1099 - break; 1100 - /* fall through */ 1101 - case IB_PORT_DOWN: 1102 - switch (phys_state) { 1103 - case 0: 1104 - dev_state = HLS_DN_DOWNDEF; 1105 - break; 1106 - case 2: 1107 - dev_state = HLS_DN_POLL; 1108 - break; 1109 - case 3: 1110 - dev_state = HLS_DN_DISABLE; 1111 - break; 1112 - default: 1113 - return -EINVAL; 1114 - } 1115 - ret = set_link_state(ppd, dev_state); 1116 - break; 1117 - case IB_PORT_ARMED: 1118 - ret = set_link_state(ppd, HLS_UP_ARMED); 1119 - if (!ret) 1120 - send_idle_sma(dd, SMA_IDLE_ARM); 1121 - break; 1122 - case IB_PORT_ACTIVE: 1123 - ret = set_link_state(ppd, HLS_UP_ACTIVE); 1124 - if (!ret) 1125 - send_idle_sma(dd, SMA_IDLE_ACTIVE); 1126 - break; 1127 - default: 1128 - return -EINVAL; 1129 - } 1130 - 1131 - if (ret) 1132 - break; 1133 - /* fall through */ 1134 - case HFI1_SNOOP_IOCGETLINKSTATE: 1135 - case HFI1_SNOOP_IOCGETLINKSTATE_EXTRA: 1136 - if (cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) { 1137 - memset(&link_info, 0, sizeof(link_info)); 1138 - if (copy_from_user(&link_info, 1139 - (struct hfi1_link_info __user *)arg, 1140 - sizeof(link_info))) 1141 - return -EFAULT; 1142 - index = link_info.port_number; 1143 - } else { 1144 - ret = __get_user(index, (int __user *)arg); 1145 - if (ret != 0) 1146 - break; 1147 - } 1148 - 1149 - if (index > dd->num_pports - 1) 1150 - return -EINVAL; 1151 - 1152 - ppd = &dd->pport[index]; 1153 - if (!ppd) 1154 - return -EINVAL; 1155 - 1156 - value = hfi1_ibphys_portstate(ppd); 1157 - value <<= 4; 1158 - value |= driver_lstate(ppd); 1159 - 1160 - snoop_dbg("Link port | Link State: %d", value); 1161 - 1162 - if ((cmd == HFI1_SNOOP_IOCGETLINKSTATE_EXTRA) || 1163 - (cmd == HFI1_SNOOP_IOCSETLINKSTATE_EXTRA)) { 1164 - link_info.port_state = value; 1165 - link_info.node_guid = cpu_to_be64(ppd->guid); 1166 - link_info.link_speed_active = 1167 - ppd->link_speed_active; 1168 - link_info.link_width_active = 1169 - ppd->link_width_active; 1170 - if (copy_to_user((struct hfi1_link_info __user *)arg, 1171 - &link_info, sizeof(link_info))) 1172 - return -EFAULT; 1173 - } else { 1174 - ret = __put_user(value, (int __user *)arg); 1175 - } 1176 - break; 1177 - 1178 - case HFI1_SNOOP_IOCCLEARQUEUE: 1179 - snoop_dbg("Clearing snoop queue"); 1180 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 1181 - drain_snoop_list(&dd->hfi1_snoop.queue); 1182 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 1183 - break; 1184 - 1185 - case HFI1_SNOOP_IOCCLEARFILTER: 1186 - snoop_dbg("Clearing filter"); 1187 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 1188 - if (dd->hfi1_snoop.filter_callback) { 1189 - /* Drain packets first */ 1190 - drain_snoop_list(&dd->hfi1_snoop.queue); 1191 - dd->hfi1_snoop.filter_callback = NULL; 1192 - } 1193 - kfree(dd->hfi1_snoop.filter_value); 1194 - dd->hfi1_snoop.filter_value = NULL; 1195 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 1196 - break; 1197 - 1198 - case HFI1_SNOOP_IOCSETFILTER: 1199 - snoop_dbg("Setting filter"); 1200 - /* just copy command structure */ 1201 - argp = (unsigned long *)arg; 1202 - if (copy_from_user(&filter_cmd, (void __user *)argp, 1203 - sizeof(filter_cmd))) 1204 - return -EFAULT; 1205 - 1206 - if (filter_cmd.opcode >= HFI1_MAX_FILTERS) { 1207 - pr_alert("Invalid opcode in request\n"); 1208 - return -EINVAL; 1209 - } 1210 - 1211 - snoop_dbg("Opcode %d Len %d Ptr %p", 1212 - filter_cmd.opcode, filter_cmd.length, 1213 - filter_cmd.value_ptr); 1214 - 1215 - filter_value = kcalloc(filter_cmd.length, sizeof(u8), 1216 - GFP_KERNEL); 1217 - if (!filter_value) 1218 - return -ENOMEM; 1219 - 1220 - /* copy remaining data from userspace */ 1221 - if (copy_from_user((u8 *)filter_value, 1222 - (void __user *)filter_cmd.value_ptr, 1223 - filter_cmd.length)) { 1224 - kfree(filter_value); 1225 - return -EFAULT; 1226 - } 1227 - /* Drain packets first */ 1228 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 1229 - drain_snoop_list(&dd->hfi1_snoop.queue); 1230 - dd->hfi1_snoop.filter_callback = 1231 - hfi1_filters[filter_cmd.opcode].filter; 1232 - /* just in case we see back to back sets */ 1233 - kfree(dd->hfi1_snoop.filter_value); 1234 - dd->hfi1_snoop.filter_value = filter_value; 1235 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 1236 - break; 1237 - case HFI1_SNOOP_IOCGETVERSION: 1238 - value = SNOOP_CAPTURE_VERSION; 1239 - snoop_dbg("Getting version: %d", value); 1240 - ret = __put_user(value, (int __user *)arg); 1241 - break; 1242 - case HFI1_SNOOP_IOCSET_OPTS: 1243 - snoop_flags = 0; 1244 - ret = __get_user(value, (int __user *)arg); 1245 - if (ret != 0) 1246 - break; 1247 - 1248 - snoop_dbg("Setting snoop option %d", value); 1249 - if (value & SNOOP_DROP_SEND) 1250 - snoop_flags |= SNOOP_DROP_SEND; 1251 - if (value & SNOOP_USE_METADATA) 1252 - snoop_flags |= SNOOP_USE_METADATA; 1253 - if (value & (SNOOP_SET_VL0TOVL15)) { 1254 - ppd = &dd->pport[0]; /* first port will do */ 1255 - ret = hfi1_assign_snoop_link_credits(ppd, value); 1256 - } 1257 - break; 1258 - default: 1259 - return -ENOTTY; 1260 - } 1261 - 1262 - return ret; 1263 - } 1264 - 1265 - static void snoop_list_add_tail(struct snoop_packet *packet, 1266 - struct hfi1_devdata *dd) 1267 - { 1268 - unsigned long flags = 0; 1269 - 1270 - spin_lock_irqsave(&dd->hfi1_snoop.snoop_lock, flags); 1271 - if (likely((dd->hfi1_snoop.mode_flag & HFI1_PORT_SNOOP_MODE) || 1272 - (dd->hfi1_snoop.mode_flag & HFI1_PORT_CAPTURE_MODE))) { 1273 - list_add_tail(&packet->list, &dd->hfi1_snoop.queue); 1274 - snoop_dbg("Added packet to list"); 1275 - } 1276 - 1277 - /* 1278 - * Technically we can could have closed the snoop device while waiting 1279 - * on the above lock and it is gone now. The snoop mode_flag will 1280 - * prevent us from adding the packet to the queue though. 1281 - */ 1282 - 1283 - spin_unlock_irqrestore(&dd->hfi1_snoop.snoop_lock, flags); 1284 - wake_up_interruptible(&dd->hfi1_snoop.waitq); 1285 - } 1286 - 1287 - static inline int hfi1_filter_check(void *val, const char *msg) 1288 - { 1289 - if (!val) { 1290 - snoop_dbg("Error invalid %s value for filter", msg); 1291 - return HFI1_FILTER_ERR; 1292 - } 1293 - return 0; 1294 - } 1295 - 1296 - static int hfi1_filter_lid(void *ibhdr, void *packet_data, void *value) 1297 - { 1298 - struct hfi1_ib_header *hdr; 1299 - int ret; 1300 - 1301 - ret = hfi1_filter_check(ibhdr, "header"); 1302 - if (ret) 1303 - return ret; 1304 - ret = hfi1_filter_check(value, "user"); 1305 - if (ret) 1306 - return ret; 1307 - hdr = (struct hfi1_ib_header *)ibhdr; 1308 - 1309 - if (*((u16 *)value) == be16_to_cpu(hdr->lrh[3])) /* matches slid */ 1310 - return HFI1_FILTER_HIT; /* matched */ 1311 - 1312 - return HFI1_FILTER_MISS; /* Not matched */ 1313 - } 1314 - 1315 - static int hfi1_filter_dlid(void *ibhdr, void *packet_data, void *value) 1316 - { 1317 - struct hfi1_ib_header *hdr; 1318 - int ret; 1319 - 1320 - ret = hfi1_filter_check(ibhdr, "header"); 1321 - if (ret) 1322 - return ret; 1323 - ret = hfi1_filter_check(value, "user"); 1324 - if (ret) 1325 - return ret; 1326 - 1327 - hdr = (struct hfi1_ib_header *)ibhdr; 1328 - 1329 - if (*((u16 *)value) == be16_to_cpu(hdr->lrh[1])) 1330 - return HFI1_FILTER_HIT; 1331 - 1332 - return HFI1_FILTER_MISS; 1333 - } 1334 - 1335 - /* Not valid for outgoing packets, send handler passes null for data*/ 1336 - static int hfi1_filter_mad_mgmt_class(void *ibhdr, void *packet_data, 1337 - void *value) 1338 - { 1339 - struct hfi1_ib_header *hdr; 1340 - struct hfi1_other_headers *ohdr = NULL; 1341 - struct ib_smp *smp = NULL; 1342 - u32 qpn = 0; 1343 - int ret; 1344 - 1345 - ret = hfi1_filter_check(ibhdr, "header"); 1346 - if (ret) 1347 - return ret; 1348 - ret = hfi1_filter_check(packet_data, "packet_data"); 1349 - if (ret) 1350 - return ret; 1351 - ret = hfi1_filter_check(value, "user"); 1352 - if (ret) 1353 - return ret; 1354 - 1355 - hdr = (struct hfi1_ib_header *)ibhdr; 1356 - 1357 - /* Check for GRH */ 1358 - if ((be16_to_cpu(hdr->lrh[0]) & 3) == HFI1_LRH_BTH) 1359 - ohdr = &hdr->u.oth; /* LRH + BTH + DETH */ 1360 - else 1361 - ohdr = &hdr->u.l.oth; /* LRH + GRH + BTH + DETH */ 1362 - 1363 - qpn = be32_to_cpu(ohdr->bth[1]) & 0x00FFFFFF; 1364 - if (qpn <= 1) { 1365 - smp = (struct ib_smp *)packet_data; 1366 - if (*((u8 *)value) == smp->mgmt_class) 1367 - return HFI1_FILTER_HIT; 1368 - else 1369 - return HFI1_FILTER_MISS; 1370 - } 1371 - return HFI1_FILTER_ERR; 1372 - } 1373 - 1374 - static int hfi1_filter_qp_number(void *ibhdr, void *packet_data, void *value) 1375 - { 1376 - struct hfi1_ib_header *hdr; 1377 - struct hfi1_other_headers *ohdr = NULL; 1378 - int ret; 1379 - 1380 - ret = hfi1_filter_check(ibhdr, "header"); 1381 - if (ret) 1382 - return ret; 1383 - ret = hfi1_filter_check(value, "user"); 1384 - if (ret) 1385 - return ret; 1386 - 1387 - hdr = (struct hfi1_ib_header *)ibhdr; 1388 - 1389 - /* Check for GRH */ 1390 - if ((be16_to_cpu(hdr->lrh[0]) & 3) == HFI1_LRH_BTH) 1391 - ohdr = &hdr->u.oth; /* LRH + BTH + DETH */ 1392 - else 1393 - ohdr = &hdr->u.l.oth; /* LRH + GRH + BTH + DETH */ 1394 - if (*((u32 *)value) == (be32_to_cpu(ohdr->bth[1]) & 0x00FFFFFF)) 1395 - return HFI1_FILTER_HIT; 1396 - 1397 - return HFI1_FILTER_MISS; 1398 - } 1399 - 1400 - static int hfi1_filter_ibpacket_type(void *ibhdr, void *packet_data, 1401 - void *value) 1402 - { 1403 - u32 lnh = 0; 1404 - u8 opcode = 0; 1405 - struct hfi1_ib_header *hdr; 1406 - struct hfi1_other_headers *ohdr = NULL; 1407 - int ret; 1408 - 1409 - ret = hfi1_filter_check(ibhdr, "header"); 1410 - if (ret) 1411 - return ret; 1412 - ret = hfi1_filter_check(value, "user"); 1413 - if (ret) 1414 - return ret; 1415 - 1416 - hdr = (struct hfi1_ib_header *)ibhdr; 1417 - 1418 - lnh = (be16_to_cpu(hdr->lrh[0]) & 3); 1419 - 1420 - if (lnh == HFI1_LRH_BTH) 1421 - ohdr = &hdr->u.oth; 1422 - else if (lnh == HFI1_LRH_GRH) 1423 - ohdr = &hdr->u.l.oth; 1424 - else 1425 - return HFI1_FILTER_ERR; 1426 - 1427 - opcode = be32_to_cpu(ohdr->bth[0]) >> 24; 1428 - 1429 - if (*((u8 *)value) == ((opcode >> 5) & 0x7)) 1430 - return HFI1_FILTER_HIT; 1431 - 1432 - return HFI1_FILTER_MISS; 1433 - } 1434 - 1435 - static int hfi1_filter_ib_service_level(void *ibhdr, void *packet_data, 1436 - void *value) 1437 - { 1438 - struct hfi1_ib_header *hdr; 1439 - int ret; 1440 - 1441 - ret = hfi1_filter_check(ibhdr, "header"); 1442 - if (ret) 1443 - return ret; 1444 - ret = hfi1_filter_check(value, "user"); 1445 - if (ret) 1446 - return ret; 1447 - 1448 - hdr = (struct hfi1_ib_header *)ibhdr; 1449 - 1450 - if ((*((u8 *)value)) == ((be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF)) 1451 - return HFI1_FILTER_HIT; 1452 - 1453 - return HFI1_FILTER_MISS; 1454 - } 1455 - 1456 - static int hfi1_filter_ib_pkey(void *ibhdr, void *packet_data, void *value) 1457 - { 1458 - u32 lnh = 0; 1459 - struct hfi1_ib_header *hdr; 1460 - struct hfi1_other_headers *ohdr = NULL; 1461 - int ret; 1462 - 1463 - ret = hfi1_filter_check(ibhdr, "header"); 1464 - if (ret) 1465 - return ret; 1466 - ret = hfi1_filter_check(value, "user"); 1467 - if (ret) 1468 - return ret; 1469 - 1470 - hdr = (struct hfi1_ib_header *)ibhdr; 1471 - 1472 - lnh = (be16_to_cpu(hdr->lrh[0]) & 3); 1473 - if (lnh == HFI1_LRH_BTH) 1474 - ohdr = &hdr->u.oth; 1475 - else if (lnh == HFI1_LRH_GRH) 1476 - ohdr = &hdr->u.l.oth; 1477 - else 1478 - return HFI1_FILTER_ERR; 1479 - 1480 - /* P_key is 16-bit entity, however top most bit indicates 1481 - * type of membership. 0 for limited and 1 for Full. 1482 - * Limited members cannot accept information from other 1483 - * Limited members, but communication is allowed between 1484 - * every other combination of membership. 1485 - * Hence we'll omit comparing top-most bit while filtering 1486 - */ 1487 - 1488 - if ((*(u16 *)value & 0x7FFF) == 1489 - ((be32_to_cpu(ohdr->bth[0])) & 0x7FFF)) 1490 - return HFI1_FILTER_HIT; 1491 - 1492 - return HFI1_FILTER_MISS; 1493 - } 1494 - 1495 - /* 1496 - * If packet_data is NULL then this is coming from one of the send functions. 1497 - * Thus we know if its an ingressed or egressed packet. 1498 - */ 1499 - static int hfi1_filter_direction(void *ibhdr, void *packet_data, void *value) 1500 - { 1501 - u8 user_dir = *(u8 *)value; 1502 - int ret; 1503 - 1504 - ret = hfi1_filter_check(value, "user"); 1505 - if (ret) 1506 - return ret; 1507 - 1508 - if (packet_data) { 1509 - /* Incoming packet */ 1510 - if (user_dir & HFI1_SNOOP_INGRESS) 1511 - return HFI1_FILTER_HIT; 1512 - } else { 1513 - /* Outgoing packet */ 1514 - if (user_dir & HFI1_SNOOP_EGRESS) 1515 - return HFI1_FILTER_HIT; 1516 - } 1517 - 1518 - return HFI1_FILTER_MISS; 1519 - } 1520 - 1521 - /* 1522 - * Allocate a snoop packet. The structure that is stored in the ring buffer, not 1523 - * to be confused with an hfi packet type. 1524 - */ 1525 - static struct snoop_packet *allocate_snoop_packet(u32 hdr_len, 1526 - u32 data_len, 1527 - u32 md_len) 1528 - { 1529 - struct snoop_packet *packet; 1530 - 1531 - packet = kzalloc(sizeof(*packet) + hdr_len + data_len 1532 - + md_len, 1533 - GFP_ATOMIC | __GFP_NOWARN); 1534 - if (likely(packet)) 1535 - INIT_LIST_HEAD(&packet->list); 1536 - 1537 - return packet; 1538 - } 1539 - 1540 - /* 1541 - * Instead of having snoop and capture code intermixed with the recv functions, 1542 - * both the interrupt handler and hfi1_ib_rcv() we are going to hijack the call 1543 - * and land in here for snoop/capture but if not enabled the call will go 1544 - * through as before. This gives us a single point to constrain all of the snoop 1545 - * snoop recv logic. There is nothing special that needs to happen for bypass 1546 - * packets. This routine should not try to look into the packet. It just copied 1547 - * it. There is no guarantee for filters when it comes to bypass packets as 1548 - * there is no specific support. Bottom line is this routine does now even know 1549 - * what a bypass packet is. 1550 - */ 1551 - int snoop_recv_handler(struct hfi1_packet *packet) 1552 - { 1553 - struct hfi1_pportdata *ppd = packet->rcd->ppd; 1554 - struct hfi1_ib_header *hdr = packet->hdr; 1555 - int header_size = packet->hlen; 1556 - void *data = packet->ebuf; 1557 - u32 tlen = packet->tlen; 1558 - struct snoop_packet *s_packet = NULL; 1559 - int ret; 1560 - int snoop_mode = 0; 1561 - u32 md_len = 0; 1562 - struct capture_md md; 1563 - 1564 - snoop_dbg("PACKET IN: hdr size %d tlen %d data %p", header_size, tlen, 1565 - data); 1566 - 1567 - trace_snoop_capture(ppd->dd, header_size, hdr, tlen - header_size, 1568 - data); 1569 - 1570 - if (!ppd->dd->hfi1_snoop.filter_callback) { 1571 - snoop_dbg("filter not set"); 1572 - ret = HFI1_FILTER_HIT; 1573 - } else { 1574 - ret = ppd->dd->hfi1_snoop.filter_callback(hdr, data, 1575 - ppd->dd->hfi1_snoop.filter_value); 1576 - } 1577 - 1578 - switch (ret) { 1579 - case HFI1_FILTER_ERR: 1580 - snoop_dbg("Error in filter call"); 1581 - break; 1582 - case HFI1_FILTER_MISS: 1583 - snoop_dbg("Filter Miss"); 1584 - break; 1585 - case HFI1_FILTER_HIT: 1586 - 1587 - if (ppd->dd->hfi1_snoop.mode_flag & HFI1_PORT_SNOOP_MODE) 1588 - snoop_mode = 1; 1589 - if ((snoop_mode == 0) || 1590 - unlikely(snoop_flags & SNOOP_USE_METADATA)) 1591 - md_len = sizeof(struct capture_md); 1592 - 1593 - s_packet = allocate_snoop_packet(header_size, 1594 - tlen - header_size, 1595 - md_len); 1596 - 1597 - if (unlikely(!s_packet)) { 1598 - dd_dev_warn_ratelimited(ppd->dd, "Unable to allocate snoop/capture packet\n"); 1599 - break; 1600 - } 1601 - 1602 - if (md_len > 0) { 1603 - memset(&md, 0, sizeof(struct capture_md)); 1604 - md.port = 1; 1605 - md.dir = PKT_DIR_INGRESS; 1606 - md.u.rhf = packet->rhf; 1607 - memcpy(s_packet->data, &md, md_len); 1608 - } 1609 - 1610 - /* We should always have a header */ 1611 - if (hdr) { 1612 - memcpy(s_packet->data + md_len, hdr, header_size); 1613 - } else { 1614 - dd_dev_err(ppd->dd, "Unable to copy header to snoop/capture packet\n"); 1615 - kfree(s_packet); 1616 - break; 1617 - } 1618 - 1619 - /* 1620 - * Packets with no data are possible. If there is no data needed 1621 - * to take care of the last 4 bytes which are normally included 1622 - * with data buffers and are included in tlen. Since we kzalloc 1623 - * the buffer we do not need to set any values but if we decide 1624 - * not to use kzalloc we should zero them. 1625 - */ 1626 - if (data) 1627 - memcpy(s_packet->data + header_size + md_len, data, 1628 - tlen - header_size); 1629 - 1630 - s_packet->total_len = tlen + md_len; 1631 - snoop_list_add_tail(s_packet, ppd->dd); 1632 - 1633 - /* 1634 - * If we are snooping the packet not capturing then throw away 1635 - * after adding to the list. 1636 - */ 1637 - snoop_dbg("Capturing packet"); 1638 - if (ppd->dd->hfi1_snoop.mode_flag & HFI1_PORT_SNOOP_MODE) { 1639 - snoop_dbg("Throwing packet away"); 1640 - /* 1641 - * If we are dropping the packet we still may need to 1642 - * handle the case where error flags are set, this is 1643 - * normally done by the type specific handler but that 1644 - * won't be called in this case. 1645 - */ 1646 - if (unlikely(rhf_err_flags(packet->rhf))) 1647 - handle_eflags(packet); 1648 - 1649 - /* throw the packet on the floor */ 1650 - return RHF_RCV_CONTINUE; 1651 - } 1652 - break; 1653 - default: 1654 - break; 1655 - } 1656 - 1657 - /* 1658 - * We do not care what type of packet came in here - just pass it off 1659 - * to the normal handler. 1660 - */ 1661 - return ppd->dd->normal_rhf_rcv_functions[rhf_rcv_type(packet->rhf)] 1662 - (packet); 1663 - } 1664 - 1665 - /* 1666 - * Handle snooping and capturing packets when sdma is being used. 1667 - */ 1668 - int snoop_send_dma_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps, 1669 - u64 pbc) 1670 - { 1671 - pr_alert("Snooping/Capture of Send DMA Packets Is Not Supported!\n"); 1672 - snoop_dbg("Unsupported Operation"); 1673 - return hfi1_verbs_send_dma(qp, ps, 0); 1674 - } 1675 - 1676 - /* 1677 - * Handle snooping and capturing packets when pio is being used. Does not handle 1678 - * bypass packets. The only way to send a bypass packet currently is to use the 1679 - * diagpkt interface. When that interface is enable snoop/capture is not. 1680 - */ 1681 - int snoop_send_pio_handler(struct rvt_qp *qp, struct hfi1_pkt_state *ps, 1682 - u64 pbc) 1683 - { 1684 - u32 hdrwords = qp->s_hdrwords; 1685 - struct rvt_sge_state *ss = qp->s_cur_sge; 1686 - u32 len = qp->s_cur_size; 1687 - u32 dwords = (len + 3) >> 2; 1688 - u32 plen = hdrwords + dwords + 2; /* includes pbc */ 1689 - struct hfi1_pportdata *ppd = ps->ppd; 1690 - struct snoop_packet *s_packet = NULL; 1691 - u32 *hdr = (u32 *)&ps->s_txreq->phdr.hdr; 1692 - u32 length = 0; 1693 - struct rvt_sge_state temp_ss; 1694 - void *data = NULL; 1695 - void *data_start = NULL; 1696 - int ret; 1697 - int snoop_mode = 0; 1698 - int md_len = 0; 1699 - struct capture_md md; 1700 - u32 vl; 1701 - u32 hdr_len = hdrwords << 2; 1702 - u32 tlen = HFI1_GET_PKT_LEN(&ps->s_txreq->phdr.hdr); 1703 - 1704 - md.u.pbc = 0; 1705 - 1706 - snoop_dbg("PACKET OUT: hdrword %u len %u plen %u dwords %u tlen %u", 1707 - hdrwords, len, plen, dwords, tlen); 1708 - if (ppd->dd->hfi1_snoop.mode_flag & HFI1_PORT_SNOOP_MODE) 1709 - snoop_mode = 1; 1710 - if ((snoop_mode == 0) || 1711 - unlikely(snoop_flags & SNOOP_USE_METADATA)) 1712 - md_len = sizeof(struct capture_md); 1713 - 1714 - /* not using ss->total_len as arg 2 b/c that does not count CRC */ 1715 - s_packet = allocate_snoop_packet(hdr_len, tlen - hdr_len, md_len); 1716 - 1717 - if (unlikely(!s_packet)) { 1718 - dd_dev_warn_ratelimited(ppd->dd, "Unable to allocate snoop/capture packet\n"); 1719 - goto out; 1720 - } 1721 - 1722 - s_packet->total_len = tlen + md_len; 1723 - 1724 - if (md_len > 0) { 1725 - memset(&md, 0, sizeof(struct capture_md)); 1726 - md.port = 1; 1727 - md.dir = PKT_DIR_EGRESS; 1728 - if (likely(pbc == 0)) { 1729 - vl = be16_to_cpu(ps->s_txreq->phdr.hdr.lrh[0]) >> 12; 1730 - md.u.pbc = create_pbc(ppd, 0, qp->s_srate, vl, plen); 1731 - } else { 1732 - md.u.pbc = 0; 1733 - } 1734 - memcpy(s_packet->data, &md, md_len); 1735 - } else { 1736 - md.u.pbc = pbc; 1737 - } 1738 - 1739 - /* Copy header */ 1740 - if (likely(hdr)) { 1741 - memcpy(s_packet->data + md_len, hdr, hdr_len); 1742 - } else { 1743 - dd_dev_err(ppd->dd, 1744 - "Unable to copy header to snoop/capture packet\n"); 1745 - kfree(s_packet); 1746 - goto out; 1747 - } 1748 - 1749 - if (ss) { 1750 - data = s_packet->data + hdr_len + md_len; 1751 - data_start = data; 1752 - 1753 - /* 1754 - * Copy SGE State 1755 - * The update_sge() function below will not modify the 1756 - * individual SGEs in the array. It will make a copy each time 1757 - * and operate on that. So we only need to copy this instance 1758 - * and it won't impact PIO. 1759 - */ 1760 - temp_ss = *ss; 1761 - length = len; 1762 - 1763 - snoop_dbg("Need to copy %d bytes", length); 1764 - while (length) { 1765 - void *addr = temp_ss.sge.vaddr; 1766 - u32 slen = temp_ss.sge.length; 1767 - 1768 - if (slen > length) { 1769 - slen = length; 1770 - snoop_dbg("slen %d > len %d", slen, length); 1771 - } 1772 - snoop_dbg("copy %d to %p", slen, addr); 1773 - memcpy(data, addr, slen); 1774 - update_sge(&temp_ss, slen); 1775 - length -= slen; 1776 - data += slen; 1777 - snoop_dbg("data is now %p bytes left %d", data, length); 1778 - } 1779 - snoop_dbg("Completed SGE copy"); 1780 - } 1781 - 1782 - /* 1783 - * Why do the filter check down here? Because the event tracing has its 1784 - * own filtering and we need to have the walked the SGE list. 1785 - */ 1786 - if (!ppd->dd->hfi1_snoop.filter_callback) { 1787 - snoop_dbg("filter not set\n"); 1788 - ret = HFI1_FILTER_HIT; 1789 - } else { 1790 - ret = ppd->dd->hfi1_snoop.filter_callback( 1791 - &ps->s_txreq->phdr.hdr, 1792 - NULL, 1793 - ppd->dd->hfi1_snoop.filter_value); 1794 - } 1795 - 1796 - switch (ret) { 1797 - case HFI1_FILTER_ERR: 1798 - snoop_dbg("Error in filter call"); 1799 - /* fall through */ 1800 - case HFI1_FILTER_MISS: 1801 - snoop_dbg("Filter Miss"); 1802 - kfree(s_packet); 1803 - break; 1804 - case HFI1_FILTER_HIT: 1805 - snoop_dbg("Capturing packet"); 1806 - snoop_list_add_tail(s_packet, ppd->dd); 1807 - 1808 - if (unlikely((snoop_flags & SNOOP_DROP_SEND) && 1809 - (ppd->dd->hfi1_snoop.mode_flag & 1810 - HFI1_PORT_SNOOP_MODE))) { 1811 - unsigned long flags; 1812 - 1813 - snoop_dbg("Dropping packet"); 1814 - if (qp->s_wqe) { 1815 - spin_lock_irqsave(&qp->s_lock, flags); 1816 - hfi1_send_complete( 1817 - qp, 1818 - qp->s_wqe, 1819 - IB_WC_SUCCESS); 1820 - spin_unlock_irqrestore(&qp->s_lock, flags); 1821 - } else if (qp->ibqp.qp_type == IB_QPT_RC) { 1822 - spin_lock_irqsave(&qp->s_lock, flags); 1823 - hfi1_rc_send_complete(qp, 1824 - &ps->s_txreq->phdr.hdr); 1825 - spin_unlock_irqrestore(&qp->s_lock, flags); 1826 - } 1827 - 1828 - /* 1829 - * If snoop is dropping the packet we need to put the 1830 - * txreq back because no one else will. 1831 - */ 1832 - hfi1_put_txreq(ps->s_txreq); 1833 - return 0; 1834 - } 1835 - break; 1836 - default: 1837 - kfree(s_packet); 1838 - break; 1839 - } 1840 - out: 1841 - return hfi1_verbs_send_pio(qp, ps, md.u.pbc); 1842 - } 1843 - 1844 - /* 1845 - * Callers of this must pass a hfi1_ib_header type for the from ptr. Currently 1846 - * this can be used anywhere, but the intention is for inline ACKs for RC and 1847 - * CCA packets. We don't restrict this usage though. 1848 - */ 1849 - void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf, 1850 - u64 pbc, const void *from, size_t count) 1851 - { 1852 - int snoop_mode = 0; 1853 - int md_len = 0; 1854 - struct capture_md md; 1855 - struct snoop_packet *s_packet = NULL; 1856 - 1857 - /* 1858 - * count is in dwords so we need to convert to bytes. 1859 - * We also need to account for CRC which would be tacked on by hardware. 1860 - */ 1861 - int packet_len = (count << 2) + 4; 1862 - int ret; 1863 - 1864 - snoop_dbg("ACK OUT: len %d", packet_len); 1865 - 1866 - if (!dd->hfi1_snoop.filter_callback) { 1867 - snoop_dbg("filter not set"); 1868 - ret = HFI1_FILTER_HIT; 1869 - } else { 1870 - ret = dd->hfi1_snoop.filter_callback( 1871 - (struct hfi1_ib_header *)from, 1872 - NULL, 1873 - dd->hfi1_snoop.filter_value); 1874 - } 1875 - 1876 - switch (ret) { 1877 - case HFI1_FILTER_ERR: 1878 - snoop_dbg("Error in filter call"); 1879 - /* fall through */ 1880 - case HFI1_FILTER_MISS: 1881 - snoop_dbg("Filter Miss"); 1882 - break; 1883 - case HFI1_FILTER_HIT: 1884 - snoop_dbg("Capturing packet"); 1885 - if (dd->hfi1_snoop.mode_flag & HFI1_PORT_SNOOP_MODE) 1886 - snoop_mode = 1; 1887 - if ((snoop_mode == 0) || 1888 - unlikely(snoop_flags & SNOOP_USE_METADATA)) 1889 - md_len = sizeof(struct capture_md); 1890 - 1891 - s_packet = allocate_snoop_packet(packet_len, 0, md_len); 1892 - 1893 - if (unlikely(!s_packet)) { 1894 - dd_dev_warn_ratelimited(dd, "Unable to allocate snoop/capture packet\n"); 1895 - goto inline_pio_out; 1896 - } 1897 - 1898 - s_packet->total_len = packet_len + md_len; 1899 - 1900 - /* Fill in the metadata for the packet */ 1901 - if (md_len > 0) { 1902 - memset(&md, 0, sizeof(struct capture_md)); 1903 - md.port = 1; 1904 - md.dir = PKT_DIR_EGRESS; 1905 - md.u.pbc = pbc; 1906 - memcpy(s_packet->data, &md, md_len); 1907 - } 1908 - 1909 - /* Add the packet data which is a single buffer */ 1910 - memcpy(s_packet->data + md_len, from, packet_len); 1911 - 1912 - snoop_list_add_tail(s_packet, dd); 1913 - 1914 - if (unlikely((snoop_flags & SNOOP_DROP_SEND) && snoop_mode)) { 1915 - snoop_dbg("Dropping packet"); 1916 - return; 1917 - } 1918 - break; 1919 - default: 1920 - break; 1921 - } 1922 - 1923 - inline_pio_out: 1924 - pio_copy(dd, pbuf, pbc, from, count); 1925 - }
drivers/staging/rdma/hfi1/dma.c drivers/infiniband/hw/hfi1/dma.c
+1 -1
drivers/staging/rdma/hfi1/driver.c drivers/infiniband/hw/hfi1/driver.c
··· 1161 1161 ppd->lmc = lmc; 1162 1162 hfi1_set_ib_cfg(ppd, HFI1_IB_CFG_LIDLMC, 0); 1163 1163 1164 - dd_dev_info(dd, "IB%u:%u got a lid: 0x%x\n", dd->unit, ppd->port, lid); 1164 + dd_dev_info(dd, "port %u: got a lid: 0x%x\n", ppd->port, lid); 1165 1165 1166 1166 return 0; 1167 1167 }
drivers/staging/rdma/hfi1/efivar.c drivers/infiniband/hw/hfi1/efivar.c
drivers/staging/rdma/hfi1/efivar.h drivers/infiniband/hw/hfi1/efivar.h
-471
drivers/staging/rdma/hfi1/eprom.c
··· 1 - /* 2 - * Copyright(c) 2015, 2016 Intel Corporation. 3 - * 4 - * This file is provided under a dual BSD/GPLv2 license. When using or 5 - * redistributing this file, you may do so under either license. 6 - * 7 - * GPL LICENSE SUMMARY 8 - * 9 - * This program is free software; you can redistribute it and/or modify 10 - * it under the terms of version 2 of the GNU General Public License as 11 - * published by the Free Software Foundation. 12 - * 13 - * This program is distributed in the hope that it will be useful, but 14 - * WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 - * General Public License for more details. 17 - * 18 - * BSD LICENSE 19 - * 20 - * Redistribution and use in source and binary forms, with or without 21 - * modification, are permitted provided that the following conditions 22 - * are met: 23 - * 24 - * - Redistributions of source code must retain the above copyright 25 - * notice, this list of conditions and the following disclaimer. 26 - * - Redistributions in binary form must reproduce the above copyright 27 - * notice, this list of conditions and the following disclaimer in 28 - * the documentation and/or other materials provided with the 29 - * distribution. 30 - * - Neither the name of Intel Corporation nor the names of its 31 - * contributors may be used to endorse or promote products derived 32 - * from this software without specific prior written permission. 33 - * 34 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 35 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 37 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 38 - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 39 - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 40 - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 41 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 42 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 43 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 44 - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 45 - * 46 - */ 47 - #include <linux/delay.h> 48 - #include "hfi.h" 49 - #include "common.h" 50 - #include "eprom.h" 51 - 52 - /* 53 - * The EPROM is logically divided into three partitions: 54 - * partition 0: the first 128K, visible from PCI ROM BAR 55 - * partition 1: 4K config file (sector size) 56 - * partition 2: the rest 57 - */ 58 - #define P0_SIZE (128 * 1024) 59 - #define P1_SIZE (4 * 1024) 60 - #define P1_START P0_SIZE 61 - #define P2_START (P0_SIZE + P1_SIZE) 62 - 63 - /* erase sizes supported by the controller */ 64 - #define SIZE_4KB (4 * 1024) 65 - #define MASK_4KB (SIZE_4KB - 1) 66 - 67 - #define SIZE_32KB (32 * 1024) 68 - #define MASK_32KB (SIZE_32KB - 1) 69 - 70 - #define SIZE_64KB (64 * 1024) 71 - #define MASK_64KB (SIZE_64KB - 1) 72 - 73 - /* controller page size, in bytes */ 74 - #define EP_PAGE_SIZE 256 75 - #define EEP_PAGE_MASK (EP_PAGE_SIZE - 1) 76 - 77 - /* controller commands */ 78 - #define CMD_SHIFT 24 79 - #define CMD_NOP (0) 80 - #define CMD_PAGE_PROGRAM(addr) ((0x02 << CMD_SHIFT) | addr) 81 - #define CMD_READ_DATA(addr) ((0x03 << CMD_SHIFT) | addr) 82 - #define CMD_READ_SR1 ((0x05 << CMD_SHIFT)) 83 - #define CMD_WRITE_ENABLE ((0x06 << CMD_SHIFT)) 84 - #define CMD_SECTOR_ERASE_4KB(addr) ((0x20 << CMD_SHIFT) | addr) 85 - #define CMD_SECTOR_ERASE_32KB(addr) ((0x52 << CMD_SHIFT) | addr) 86 - #define CMD_CHIP_ERASE ((0x60 << CMD_SHIFT)) 87 - #define CMD_READ_MANUF_DEV_ID ((0x90 << CMD_SHIFT)) 88 - #define CMD_RELEASE_POWERDOWN_NOID ((0xab << CMD_SHIFT)) 89 - #define CMD_SECTOR_ERASE_64KB(addr) ((0xd8 << CMD_SHIFT) | addr) 90 - 91 - /* controller interface speeds */ 92 - #define EP_SPEED_FULL 0x2 /* full speed */ 93 - 94 - /* controller status register 1 bits */ 95 - #define SR1_BUSY 0x1ull /* the BUSY bit in SR1 */ 96 - 97 - /* sleep length while waiting for controller */ 98 - #define WAIT_SLEEP_US 100 /* must be larger than 5 (see usage) */ 99 - #define COUNT_DELAY_SEC(n) ((n) * (1000000 / WAIT_SLEEP_US)) 100 - 101 - /* GPIO pins */ 102 - #define EPROM_WP_N BIT_ULL(14) /* EPROM write line */ 103 - 104 - /* 105 - * How long to wait for the EPROM to become available, in ms. 106 - * The spec 32 Mb EPROM takes around 40s to erase then write. 107 - * Double it for safety. 108 - */ 109 - #define EPROM_TIMEOUT 80000 /* ms */ 110 - 111 - /* 112 - * Turn on external enable line that allows writing on the flash. 113 - */ 114 - static void write_enable(struct hfi1_devdata *dd) 115 - { 116 - /* raise signal */ 117 - write_csr(dd, ASIC_GPIO_OUT, read_csr(dd, ASIC_GPIO_OUT) | EPROM_WP_N); 118 - /* raise enable */ 119 - write_csr(dd, ASIC_GPIO_OE, read_csr(dd, ASIC_GPIO_OE) | EPROM_WP_N); 120 - } 121 - 122 - /* 123 - * Turn off external enable line that allows writing on the flash. 124 - */ 125 - static void write_disable(struct hfi1_devdata *dd) 126 - { 127 - /* lower signal */ 128 - write_csr(dd, ASIC_GPIO_OUT, read_csr(dd, ASIC_GPIO_OUT) & ~EPROM_WP_N); 129 - /* lower enable */ 130 - write_csr(dd, ASIC_GPIO_OE, read_csr(dd, ASIC_GPIO_OE) & ~EPROM_WP_N); 131 - } 132 - 133 - /* 134 - * Wait for the device to become not busy. Must be called after all 135 - * write or erase operations. 136 - */ 137 - static int wait_for_not_busy(struct hfi1_devdata *dd) 138 - { 139 - unsigned long count = 0; 140 - u64 reg; 141 - int ret = 0; 142 - 143 - /* starts page mode */ 144 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_READ_SR1); 145 - while (1) { 146 - udelay(WAIT_SLEEP_US); 147 - usleep_range(WAIT_SLEEP_US - 5, WAIT_SLEEP_US + 5); 148 - count++; 149 - reg = read_csr(dd, ASIC_EEP_DATA); 150 - if ((reg & SR1_BUSY) == 0) 151 - break; 152 - /* 200s is the largest time for a 128Mb device */ 153 - if (count > COUNT_DELAY_SEC(200)) { 154 - dd_dev_err(dd, "waited too long for SPI FLASH busy to clear - failing\n"); 155 - ret = -ETIMEDOUT; 156 - break; /* break, not goto - must stop page mode */ 157 - } 158 - } 159 - 160 - /* stop page mode with a NOP */ 161 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_NOP); 162 - 163 - return ret; 164 - } 165 - 166 - /* 167 - * Read the device ID from the SPI controller. 168 - */ 169 - static u32 read_device_id(struct hfi1_devdata *dd) 170 - { 171 - /* read the Manufacture Device ID */ 172 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_READ_MANUF_DEV_ID); 173 - return (u32)read_csr(dd, ASIC_EEP_DATA); 174 - } 175 - 176 - /* 177 - * Erase the whole flash. 178 - */ 179 - static int erase_chip(struct hfi1_devdata *dd) 180 - { 181 - int ret; 182 - 183 - write_enable(dd); 184 - 185 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE); 186 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_CHIP_ERASE); 187 - ret = wait_for_not_busy(dd); 188 - 189 - write_disable(dd); 190 - 191 - return ret; 192 - } 193 - 194 - /* 195 - * Erase a range. 196 - */ 197 - static int erase_range(struct hfi1_devdata *dd, u32 start, u32 len) 198 - { 199 - u32 end = start + len; 200 - int ret = 0; 201 - 202 - if (end < start) 203 - return -EINVAL; 204 - 205 - /* check the end points for the minimum erase */ 206 - if ((start & MASK_4KB) || (end & MASK_4KB)) { 207 - dd_dev_err(dd, 208 - "%s: non-aligned range (0x%x,0x%x) for a 4KB erase\n", 209 - __func__, start, end); 210 - return -EINVAL; 211 - } 212 - 213 - write_enable(dd); 214 - 215 - while (start < end) { 216 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE); 217 - /* check in order of largest to smallest */ 218 - if (((start & MASK_64KB) == 0) && (start + SIZE_64KB <= end)) { 219 - write_csr(dd, ASIC_EEP_ADDR_CMD, 220 - CMD_SECTOR_ERASE_64KB(start)); 221 - start += SIZE_64KB; 222 - } else if (((start & MASK_32KB) == 0) && 223 - (start + SIZE_32KB <= end)) { 224 - write_csr(dd, ASIC_EEP_ADDR_CMD, 225 - CMD_SECTOR_ERASE_32KB(start)); 226 - start += SIZE_32KB; 227 - } else { /* 4KB will work */ 228 - write_csr(dd, ASIC_EEP_ADDR_CMD, 229 - CMD_SECTOR_ERASE_4KB(start)); 230 - start += SIZE_4KB; 231 - } 232 - ret = wait_for_not_busy(dd); 233 - if (ret) 234 - goto done; 235 - } 236 - 237 - done: 238 - write_disable(dd); 239 - 240 - return ret; 241 - } 242 - 243 - /* 244 - * Read a 256 byte (64 dword) EPROM page. 245 - * All callers have verified the offset is at a page boundary. 246 - */ 247 - static void read_page(struct hfi1_devdata *dd, u32 offset, u32 *result) 248 - { 249 - int i; 250 - 251 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_READ_DATA(offset)); 252 - for (i = 0; i < EP_PAGE_SIZE / sizeof(u32); i++) 253 - result[i] = (u32)read_csr(dd, ASIC_EEP_DATA); 254 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_NOP); /* close open page */ 255 - } 256 - 257 - /* 258 - * Read length bytes starting at offset. Copy to user address addr. 259 - */ 260 - static int read_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr) 261 - { 262 - u32 offset; 263 - u32 buffer[EP_PAGE_SIZE / sizeof(u32)]; 264 - int ret = 0; 265 - 266 - /* reject anything not on an EPROM page boundary */ 267 - if ((start & EEP_PAGE_MASK) || (len & EEP_PAGE_MASK)) 268 - return -EINVAL; 269 - 270 - for (offset = 0; offset < len; offset += EP_PAGE_SIZE) { 271 - read_page(dd, start + offset, buffer); 272 - if (copy_to_user((void __user *)(addr + offset), 273 - buffer, EP_PAGE_SIZE)) { 274 - ret = -EFAULT; 275 - goto done; 276 - } 277 - } 278 - 279 - done: 280 - return ret; 281 - } 282 - 283 - /* 284 - * Write a 256 byte (64 dword) EPROM page. 285 - * All callers have verified the offset is at a page boundary. 286 - */ 287 - static int write_page(struct hfi1_devdata *dd, u32 offset, u32 *data) 288 - { 289 - int i; 290 - 291 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_WRITE_ENABLE); 292 - write_csr(dd, ASIC_EEP_DATA, data[0]); 293 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_PAGE_PROGRAM(offset)); 294 - for (i = 1; i < EP_PAGE_SIZE / sizeof(u32); i++) 295 - write_csr(dd, ASIC_EEP_DATA, data[i]); 296 - /* will close the open page */ 297 - return wait_for_not_busy(dd); 298 - } 299 - 300 - /* 301 - * Write length bytes starting at offset. Read from user address addr. 302 - */ 303 - static int write_length(struct hfi1_devdata *dd, u32 start, u32 len, u64 addr) 304 - { 305 - u32 offset; 306 - u32 buffer[EP_PAGE_SIZE / sizeof(u32)]; 307 - int ret = 0; 308 - 309 - /* reject anything not on an EPROM page boundary */ 310 - if ((start & EEP_PAGE_MASK) || (len & EEP_PAGE_MASK)) 311 - return -EINVAL; 312 - 313 - write_enable(dd); 314 - 315 - for (offset = 0; offset < len; offset += EP_PAGE_SIZE) { 316 - if (copy_from_user(buffer, (void __user *)(addr + offset), 317 - EP_PAGE_SIZE)) { 318 - ret = -EFAULT; 319 - goto done; 320 - } 321 - ret = write_page(dd, start + offset, buffer); 322 - if (ret) 323 - goto done; 324 - } 325 - 326 - done: 327 - write_disable(dd); 328 - return ret; 329 - } 330 - 331 - /* convert an range composite to a length, in bytes */ 332 - static inline u32 extract_rlen(u32 composite) 333 - { 334 - return (composite & 0xffff) * EP_PAGE_SIZE; 335 - } 336 - 337 - /* convert an range composite to a start, in bytes */ 338 - static inline u32 extract_rstart(u32 composite) 339 - { 340 - return (composite >> 16) * EP_PAGE_SIZE; 341 - } 342 - 343 - /* 344 - * Perform the given operation on the EPROM. Called from user space. The 345 - * user credentials have already been checked. 346 - * 347 - * Return 0 on success, -ERRNO on error 348 - */ 349 - int handle_eprom_command(struct file *fp, const struct hfi1_cmd *cmd) 350 - { 351 - struct hfi1_devdata *dd; 352 - u32 dev_id; 353 - u32 rlen; /* range length */ 354 - u32 rstart; /* range start */ 355 - int i_minor; 356 - int ret = 0; 357 - 358 - /* 359 - * Map the device file to device data using the relative minor. 360 - * The device file minor number is the unit number + 1. 0 is 361 - * the generic device file - reject it. 362 - */ 363 - i_minor = iminor(file_inode(fp)) - HFI1_USER_MINOR_BASE; 364 - if (i_minor <= 0) 365 - return -EINVAL; 366 - dd = hfi1_lookup(i_minor - 1); 367 - if (!dd) { 368 - pr_err("%s: cannot find unit %d!\n", __func__, i_minor); 369 - return -EINVAL; 370 - } 371 - 372 - /* some devices do not have an EPROM */ 373 - if (!dd->eprom_available) 374 - return -EOPNOTSUPP; 375 - 376 - ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT); 377 - if (ret) { 378 - dd_dev_err(dd, "%s: unable to acquire EPROM resource\n", 379 - __func__); 380 - goto done_asic; 381 - } 382 - 383 - dd_dev_info(dd, "%s: cmd: type %d, len 0x%x, addr 0x%016llx\n", 384 - __func__, cmd->type, cmd->len, cmd->addr); 385 - 386 - switch (cmd->type) { 387 - case HFI1_CMD_EP_INFO: 388 - if (cmd->len != sizeof(u32)) { 389 - ret = -ERANGE; 390 - break; 391 - } 392 - dev_id = read_device_id(dd); 393 - /* addr points to a u32 user buffer */ 394 - if (copy_to_user((void __user *)cmd->addr, &dev_id, 395 - sizeof(u32))) 396 - ret = -EFAULT; 397 - break; 398 - 399 - case HFI1_CMD_EP_ERASE_CHIP: 400 - ret = erase_chip(dd); 401 - break; 402 - 403 - case HFI1_CMD_EP_ERASE_RANGE: 404 - rlen = extract_rlen(cmd->len); 405 - rstart = extract_rstart(cmd->len); 406 - ret = erase_range(dd, rstart, rlen); 407 - break; 408 - 409 - case HFI1_CMD_EP_READ_RANGE: 410 - rlen = extract_rlen(cmd->len); 411 - rstart = extract_rstart(cmd->len); 412 - ret = read_length(dd, rstart, rlen, cmd->addr); 413 - break; 414 - 415 - case HFI1_CMD_EP_WRITE_RANGE: 416 - rlen = extract_rlen(cmd->len); 417 - rstart = extract_rstart(cmd->len); 418 - ret = write_length(dd, rstart, rlen, cmd->addr); 419 - break; 420 - 421 - default: 422 - dd_dev_err(dd, "%s: unexpected command %d\n", 423 - __func__, cmd->type); 424 - ret = -EINVAL; 425 - break; 426 - } 427 - 428 - release_chip_resource(dd, CR_EPROM); 429 - done_asic: 430 - return ret; 431 - } 432 - 433 - /* 434 - * Initialize the EPROM handler. 435 - */ 436 - int eprom_init(struct hfi1_devdata *dd) 437 - { 438 - int ret = 0; 439 - 440 - /* only the discrete chip has an EPROM */ 441 - if (dd->pcidev->device != PCI_DEVICE_ID_INTEL0) 442 - return 0; 443 - 444 - /* 445 - * It is OK if both HFIs reset the EPROM as long as they don't 446 - * do it at the same time. 447 - */ 448 - ret = acquire_chip_resource(dd, CR_EPROM, EPROM_TIMEOUT); 449 - if (ret) { 450 - dd_dev_err(dd, 451 - "%s: unable to acquire EPROM resource, no EPROM support\n", 452 - __func__); 453 - goto done_asic; 454 - } 455 - 456 - /* reset EPROM to be sure it is in a good state */ 457 - 458 - /* set reset */ 459 - write_csr(dd, ASIC_EEP_CTL_STAT, ASIC_EEP_CTL_STAT_EP_RESET_SMASK); 460 - /* clear reset, set speed */ 461 - write_csr(dd, ASIC_EEP_CTL_STAT, 462 - EP_SPEED_FULL << ASIC_EEP_CTL_STAT_RATE_SPI_SHIFT); 463 - 464 - /* wake the device with command "release powerdown NoID" */ 465 - write_csr(dd, ASIC_EEP_ADDR_CMD, CMD_RELEASE_POWERDOWN_NOID); 466 - 467 - dd->eprom_available = true; 468 - release_chip_resource(dd, CR_EPROM); 469 - done_asic: 470 - return ret; 471 - }
drivers/staging/rdma/hfi1/eprom.h drivers/infiniband/hw/hfi1/eprom.h
+139 -414
drivers/staging/rdma/hfi1/file_ops.c drivers/infiniband/hw/hfi1/file_ops.c
··· 72 72 */ 73 73 static int hfi1_file_open(struct inode *, struct file *); 74 74 static int hfi1_file_close(struct inode *, struct file *); 75 - static ssize_t hfi1_file_write(struct file *, const char __user *, 76 - size_t, loff_t *); 77 75 static ssize_t hfi1_write_iter(struct kiocb *, struct iov_iter *); 78 76 static unsigned int hfi1_poll(struct file *, struct poll_table_struct *); 79 77 static int hfi1_file_mmap(struct file *, struct vm_area_struct *); ··· 84 86 static int get_base_info(struct file *, void __user *, __u32); 85 87 static int setup_ctxt(struct file *); 86 88 static int setup_subctxt(struct hfi1_ctxtdata *); 87 - static int get_user_context(struct file *, struct hfi1_user_info *, 88 - int, unsigned); 89 + static int get_user_context(struct file *, struct hfi1_user_info *, int); 89 90 static int find_shared_ctxt(struct file *, const struct hfi1_user_info *); 90 91 static int allocate_ctxt(struct file *, struct hfi1_devdata *, 91 92 struct hfi1_user_info *); ··· 94 97 static int set_ctxt_pkey(struct hfi1_ctxtdata *, unsigned, u16); 95 98 static int manage_rcvq(struct hfi1_ctxtdata *, unsigned, int); 96 99 static int vma_fault(struct vm_area_struct *, struct vm_fault *); 100 + static long hfi1_file_ioctl(struct file *fp, unsigned int cmd, 101 + unsigned long arg); 97 102 98 103 static const struct file_operations hfi1_file_ops = { 99 104 .owner = THIS_MODULE, 100 - .write = hfi1_file_write, 101 105 .write_iter = hfi1_write_iter, 102 106 .open = hfi1_file_open, 103 107 .release = hfi1_file_close, 108 + .unlocked_ioctl = hfi1_file_ioctl, 104 109 .poll = hfi1_poll, 105 110 .mmap = hfi1_file_mmap, 106 111 .llseek = noop_llseek, ··· 168 169 169 170 static int hfi1_file_open(struct inode *inode, struct file *fp) 170 171 { 172 + struct hfi1_devdata *dd = container_of(inode->i_cdev, 173 + struct hfi1_devdata, 174 + user_cdev); 175 + 176 + /* Just take a ref now. Not all opens result in a context assign */ 177 + kobject_get(&dd->kobj); 178 + 171 179 /* The real work is performed later in assign_ctxt() */ 172 180 fp->private_data = kzalloc(sizeof(struct hfi1_filedata), GFP_KERNEL); 173 181 if (fp->private_data) /* no cpu affinity by default */ ··· 182 176 return fp->private_data ? 0 : -ENOMEM; 183 177 } 184 178 185 - static ssize_t hfi1_file_write(struct file *fp, const char __user *data, 186 - size_t count, loff_t *offset) 179 + static long hfi1_file_ioctl(struct file *fp, unsigned int cmd, 180 + unsigned long arg) 187 181 { 188 - const struct hfi1_cmd __user *ucmd; 189 182 struct hfi1_filedata *fd = fp->private_data; 190 183 struct hfi1_ctxtdata *uctxt = fd->uctxt; 191 - struct hfi1_cmd cmd; 192 184 struct hfi1_user_info uinfo; 193 185 struct hfi1_tid_info tinfo; 186 + int ret = 0; 194 187 unsigned long addr; 195 - ssize_t consumed = 0, copy = 0, ret = 0; 196 - void *dest = NULL; 197 - __u64 user_val = 0; 198 - int uctxt_required = 1; 199 - int must_be_root = 0; 188 + int uval = 0; 189 + unsigned long ul_uval = 0; 190 + u16 uval16 = 0; 200 191 201 - /* FIXME: This interface cannot continue out of staging */ 202 - if (WARN_ON_ONCE(!ib_safe_file_access(fp))) 203 - return -EACCES; 192 + hfi1_cdbg(IOCTL, "IOCTL recv: 0x%x", cmd); 193 + if (cmd != HFI1_IOCTL_ASSIGN_CTXT && 194 + cmd != HFI1_IOCTL_GET_VERS && 195 + !uctxt) 196 + return -EINVAL; 204 197 205 - if (count < sizeof(cmd)) { 206 - ret = -EINVAL; 207 - goto bail; 208 - } 198 + switch (cmd) { 199 + case HFI1_IOCTL_ASSIGN_CTXT: 200 + if (copy_from_user(&uinfo, 201 + (struct hfi1_user_info __user *)arg, 202 + sizeof(uinfo))) 203 + return -EFAULT; 209 204 210 - ucmd = (const struct hfi1_cmd __user *)data; 211 - if (copy_from_user(&cmd, ucmd, sizeof(cmd))) { 212 - ret = -EFAULT; 213 - goto bail; 214 - } 215 - 216 - consumed = sizeof(cmd); 217 - 218 - switch (cmd.type) { 219 - case HFI1_CMD_ASSIGN_CTXT: 220 - uctxt_required = 0; /* assigned user context not required */ 221 - copy = sizeof(uinfo); 222 - dest = &uinfo; 223 - break; 224 - case HFI1_CMD_SDMA_STATUS_UPD: 225 - case HFI1_CMD_CREDIT_UPD: 226 - copy = 0; 227 - break; 228 - case HFI1_CMD_TID_UPDATE: 229 - case HFI1_CMD_TID_FREE: 230 - case HFI1_CMD_TID_INVAL_READ: 231 - copy = sizeof(tinfo); 232 - dest = &tinfo; 233 - break; 234 - case HFI1_CMD_USER_INFO: 235 - case HFI1_CMD_RECV_CTRL: 236 - case HFI1_CMD_POLL_TYPE: 237 - case HFI1_CMD_ACK_EVENT: 238 - case HFI1_CMD_CTXT_INFO: 239 - case HFI1_CMD_SET_PKEY: 240 - case HFI1_CMD_CTXT_RESET: 241 - copy = 0; 242 - user_val = cmd.addr; 243 - break; 244 - case HFI1_CMD_EP_INFO: 245 - case HFI1_CMD_EP_ERASE_CHIP: 246 - case HFI1_CMD_EP_ERASE_RANGE: 247 - case HFI1_CMD_EP_READ_RANGE: 248 - case HFI1_CMD_EP_WRITE_RANGE: 249 - uctxt_required = 0; /* assigned user context not required */ 250 - must_be_root = 1; /* validate user */ 251 - copy = 0; 252 - break; 253 - default: 254 - ret = -EINVAL; 255 - goto bail; 256 - } 257 - 258 - /* If the command comes with user data, copy it. */ 259 - if (copy) { 260 - if (copy_from_user(dest, (void __user *)cmd.addr, copy)) { 261 - ret = -EFAULT; 262 - goto bail; 263 - } 264 - consumed += copy; 265 - } 266 - 267 - /* 268 - * Make sure there is a uctxt when needed. 269 - */ 270 - if (uctxt_required && !uctxt) { 271 - ret = -EINVAL; 272 - goto bail; 273 - } 274 - 275 - /* only root can do these operations */ 276 - if (must_be_root && !capable(CAP_SYS_ADMIN)) { 277 - ret = -EPERM; 278 - goto bail; 279 - } 280 - 281 - switch (cmd.type) { 282 - case HFI1_CMD_ASSIGN_CTXT: 283 205 ret = assign_ctxt(fp, &uinfo); 284 206 if (ret < 0) 285 - goto bail; 286 - ret = setup_ctxt(fp); 207 + return ret; 208 + setup_ctxt(fp); 287 209 if (ret) 288 - goto bail; 210 + return ret; 289 211 ret = user_init(fp); 290 212 break; 291 - case HFI1_CMD_CTXT_INFO: 292 - ret = get_ctxt_info(fp, (void __user *)(unsigned long) 293 - user_val, cmd.len); 213 + case HFI1_IOCTL_CTXT_INFO: 214 + ret = get_ctxt_info(fp, (void __user *)(unsigned long)arg, 215 + sizeof(struct hfi1_ctxt_info)); 294 216 break; 295 - case HFI1_CMD_USER_INFO: 296 - ret = get_base_info(fp, (void __user *)(unsigned long) 297 - user_val, cmd.len); 217 + case HFI1_IOCTL_USER_INFO: 218 + ret = get_base_info(fp, (void __user *)(unsigned long)arg, 219 + sizeof(struct hfi1_base_info)); 298 220 break; 299 - case HFI1_CMD_SDMA_STATUS_UPD: 300 - break; 301 - case HFI1_CMD_CREDIT_UPD: 221 + case HFI1_IOCTL_CREDIT_UPD: 302 222 if (uctxt && uctxt->sc) 303 223 sc_return_credits(uctxt->sc); 304 224 break; 305 - case HFI1_CMD_TID_UPDATE: 225 + 226 + case HFI1_IOCTL_TID_UPDATE: 227 + if (copy_from_user(&tinfo, 228 + (struct hfi11_tid_info __user *)arg, 229 + sizeof(tinfo))) 230 + return -EFAULT; 231 + 306 232 ret = hfi1_user_exp_rcv_setup(fp, &tinfo); 307 233 if (!ret) { 308 234 /* ··· 243 305 * These fields are adjacent in the structure so 244 306 * we can copy them at the same time. 245 307 */ 246 - addr = (unsigned long)cmd.addr + 247 - offsetof(struct hfi1_tid_info, tidcnt); 308 + addr = arg + offsetof(struct hfi1_tid_info, tidcnt); 248 309 if (copy_to_user((void __user *)addr, &tinfo.tidcnt, 249 310 sizeof(tinfo.tidcnt) + 250 311 sizeof(tinfo.length))) 251 312 ret = -EFAULT; 252 313 } 253 314 break; 254 - case HFI1_CMD_TID_INVAL_READ: 255 - ret = hfi1_user_exp_rcv_invalid(fp, &tinfo); 256 - if (ret) 257 - break; 258 - addr = (unsigned long)cmd.addr + 259 - offsetof(struct hfi1_tid_info, tidcnt); 260 - if (copy_to_user((void __user *)addr, &tinfo.tidcnt, 261 - sizeof(tinfo.tidcnt))) 262 - ret = -EFAULT; 263 - break; 264 - case HFI1_CMD_TID_FREE: 315 + 316 + case HFI1_IOCTL_TID_FREE: 317 + if (copy_from_user(&tinfo, 318 + (struct hfi11_tid_info __user *)arg, 319 + sizeof(tinfo))) 320 + return -EFAULT; 321 + 265 322 ret = hfi1_user_exp_rcv_clear(fp, &tinfo); 266 323 if (ret) 267 324 break; 268 - addr = (unsigned long)cmd.addr + 269 - offsetof(struct hfi1_tid_info, tidcnt); 325 + addr = arg + offsetof(struct hfi1_tid_info, tidcnt); 270 326 if (copy_to_user((void __user *)addr, &tinfo.tidcnt, 271 327 sizeof(tinfo.tidcnt))) 272 328 ret = -EFAULT; 273 329 break; 274 - case HFI1_CMD_RECV_CTRL: 275 - ret = manage_rcvq(uctxt, fd->subctxt, (int)user_val); 330 + 331 + case HFI1_IOCTL_TID_INVAL_READ: 332 + if (copy_from_user(&tinfo, 333 + (struct hfi11_tid_info __user *)arg, 334 + sizeof(tinfo))) 335 + return -EFAULT; 336 + 337 + ret = hfi1_user_exp_rcv_invalid(fp, &tinfo); 338 + if (ret) 339 + break; 340 + addr = arg + offsetof(struct hfi1_tid_info, tidcnt); 341 + if (copy_to_user((void __user *)addr, &tinfo.tidcnt, 342 + sizeof(tinfo.tidcnt))) 343 + ret = -EFAULT; 276 344 break; 277 - case HFI1_CMD_POLL_TYPE: 278 - uctxt->poll_type = (typeof(uctxt->poll_type))user_val; 345 + 346 + case HFI1_IOCTL_RECV_CTRL: 347 + ret = get_user(uval, (int __user *)arg); 348 + if (ret != 0) 349 + return -EFAULT; 350 + ret = manage_rcvq(uctxt, fd->subctxt, uval); 279 351 break; 280 - case HFI1_CMD_ACK_EVENT: 281 - ret = user_event_ack(uctxt, fd->subctxt, user_val); 352 + 353 + case HFI1_IOCTL_POLL_TYPE: 354 + ret = get_user(uval, (int __user *)arg); 355 + if (ret != 0) 356 + return -EFAULT; 357 + uctxt->poll_type = (typeof(uctxt->poll_type))uval; 282 358 break; 283 - case HFI1_CMD_SET_PKEY: 359 + 360 + case HFI1_IOCTL_ACK_EVENT: 361 + ret = get_user(ul_uval, (unsigned long __user *)arg); 362 + if (ret != 0) 363 + return -EFAULT; 364 + ret = user_event_ack(uctxt, fd->subctxt, ul_uval); 365 + break; 366 + 367 + case HFI1_IOCTL_SET_PKEY: 368 + ret = get_user(uval16, (u16 __user *)arg); 369 + if (ret != 0) 370 + return -EFAULT; 284 371 if (HFI1_CAP_IS_USET(PKEY_CHECK)) 285 - ret = set_ctxt_pkey(uctxt, fd->subctxt, user_val); 372 + ret = set_ctxt_pkey(uctxt, fd->subctxt, uval16); 286 373 else 287 - ret = -EPERM; 374 + return -EPERM; 288 375 break; 289 - case HFI1_CMD_CTXT_RESET: { 376 + 377 + case HFI1_IOCTL_CTXT_RESET: { 290 378 struct send_context *sc; 291 379 struct hfi1_devdata *dd; 292 380 293 - if (!uctxt || !uctxt->dd || !uctxt->sc) { 294 - ret = -EINVAL; 295 - break; 296 - } 381 + if (!uctxt || !uctxt->dd || !uctxt->sc) 382 + return -EINVAL; 383 + 297 384 /* 298 385 * There is no protection here. User level has to 299 386 * guarantee that no one will be writing to the send ··· 336 373 wait_event_interruptible_timeout( 337 374 sc->halt_wait, (sc->flags & SCF_HALTED), 338 375 msecs_to_jiffies(SEND_CTXT_HALT_TIMEOUT)); 339 - if (!(sc->flags & SCF_HALTED)) { 340 - ret = -ENOLCK; 341 - break; 342 - } 376 + if (!(sc->flags & SCF_HALTED)) 377 + return -ENOLCK; 378 + 343 379 /* 344 380 * If the send context was halted due to a Freeze, 345 381 * wait until the device has been "unfrozen" before ··· 349 387 dd->event_queue, 350 388 !(ACCESS_ONCE(dd->flags) & HFI1_FROZEN), 351 389 msecs_to_jiffies(SEND_CTXT_HALT_TIMEOUT)); 352 - if (dd->flags & HFI1_FROZEN) { 353 - ret = -ENOLCK; 354 - break; 355 - } 356 - if (dd->flags & HFI1_FORCED_FREEZE) { 390 + if (dd->flags & HFI1_FROZEN) 391 + return -ENOLCK; 392 + 393 + if (dd->flags & HFI1_FORCED_FREEZE) 357 394 /* 358 395 * Don't allow context reset if we are into 359 396 * forced freeze 360 397 */ 361 - ret = -ENODEV; 362 - break; 363 - } 398 + return -ENODEV; 399 + 364 400 sc_disable(sc); 365 401 ret = sc_enable(sc); 366 402 hfi1_rcvctrl(dd, HFI1_RCVCTRL_CTXT_ENB, ··· 370 410 sc_return_credits(sc); 371 411 break; 372 412 } 373 - case HFI1_CMD_EP_INFO: 374 - case HFI1_CMD_EP_ERASE_CHIP: 375 - case HFI1_CMD_EP_ERASE_RANGE: 376 - case HFI1_CMD_EP_READ_RANGE: 377 - case HFI1_CMD_EP_WRITE_RANGE: 378 - ret = handle_eprom_command(fp, &cmd); 413 + 414 + case HFI1_IOCTL_GET_VERS: 415 + uval = HFI1_USER_SWVERSION; 416 + if (put_user(uval, (int __user *)arg)) 417 + return -EFAULT; 379 418 break; 419 + 420 + default: 421 + return -EINVAL; 380 422 } 381 423 382 - if (ret >= 0) 383 - ret = consumed; 384 - bail: 385 424 return ret; 386 425 } 387 426 ··· 697 738 { 698 739 struct hfi1_filedata *fdata = fp->private_data; 699 740 struct hfi1_ctxtdata *uctxt = fdata->uctxt; 700 - struct hfi1_devdata *dd; 741 + struct hfi1_devdata *dd = container_of(inode->i_cdev, 742 + struct hfi1_devdata, 743 + user_cdev); 701 744 unsigned long flags, *ev; 702 745 703 746 fp->private_data = NULL; ··· 708 747 goto done; 709 748 710 749 hfi1_cdbg(PROC, "freeing ctxt %u:%u", uctxt->ctxt, fdata->subctxt); 711 - dd = uctxt->dd; 712 750 mutex_lock(&hfi1_mutex); 713 751 714 752 flush_wc(); ··· 773 813 mutex_unlock(&hfi1_mutex); 774 814 hfi1_free_ctxtdata(dd, uctxt); 775 815 done: 816 + kobject_put(&dd->kobj); 776 817 kfree(fdata); 777 818 return 0; 778 819 } ··· 797 836 static int assign_ctxt(struct file *fp, struct hfi1_user_info *uinfo) 798 837 { 799 838 int i_minor, ret = 0; 800 - unsigned swmajor, swminor, alg = HFI1_ALG_ACROSS; 839 + unsigned int swmajor, swminor; 801 840 802 841 swmajor = uinfo->userversion >> 16; 803 842 if (swmajor != HFI1_USER_SWMAJOR) { ··· 806 845 } 807 846 808 847 swminor = uinfo->userversion & 0xffff; 809 - 810 - if (uinfo->hfi1_alg < HFI1_ALG_COUNT) 811 - alg = uinfo->hfi1_alg; 812 848 813 849 mutex_lock(&hfi1_mutex); 814 850 /* First, lets check if we need to setup a shared context? */ ··· 826 868 */ 827 869 if (!ret) { 828 870 i_minor = iminor(file_inode(fp)) - HFI1_USER_MINOR_BASE; 829 - ret = get_user_context(fp, uinfo, i_minor - 1, alg); 871 + ret = get_user_context(fp, uinfo, i_minor); 830 872 } 831 873 done_unlock: 832 874 mutex_unlock(&hfi1_mutex); ··· 834 876 return ret; 835 877 } 836 878 837 - /* return true if the device available for general use */ 838 - static int usable_device(struct hfi1_devdata *dd) 839 - { 840 - struct hfi1_pportdata *ppd = dd->pport; 841 - 842 - return driver_lstate(ppd) == IB_PORT_ACTIVE; 843 - } 844 - 845 879 static int get_user_context(struct file *fp, struct hfi1_user_info *uinfo, 846 - int devno, unsigned alg) 880 + int devno) 847 881 { 848 882 struct hfi1_devdata *dd = NULL; 849 - int ret = 0, devmax, npresent, nup, dev; 883 + int devmax, npresent, nup; 850 884 851 885 devmax = hfi1_count_units(&npresent, &nup); 852 - if (!npresent) { 853 - ret = -ENXIO; 854 - goto done; 855 - } 856 - if (!nup) { 857 - ret = -ENETDOWN; 858 - goto done; 859 - } 860 - if (devno >= 0) { 861 - dd = hfi1_lookup(devno); 862 - if (!dd) 863 - ret = -ENODEV; 864 - else if (!dd->freectxts) 865 - ret = -EBUSY; 866 - } else { 867 - struct hfi1_devdata *pdd; 886 + if (!npresent) 887 + return -ENXIO; 868 888 869 - if (alg == HFI1_ALG_ACROSS) { 870 - unsigned free = 0U; 889 + if (!nup) 890 + return -ENETDOWN; 871 891 872 - for (dev = 0; dev < devmax; dev++) { 873 - pdd = hfi1_lookup(dev); 874 - if (!pdd) 875 - continue; 876 - if (!usable_device(pdd)) 877 - continue; 878 - if (pdd->freectxts && 879 - pdd->freectxts > free) { 880 - dd = pdd; 881 - free = pdd->freectxts; 882 - } 883 - } 884 - } else { 885 - for (dev = 0; dev < devmax; dev++) { 886 - pdd = hfi1_lookup(dev); 887 - if (!pdd) 888 - continue; 889 - if (!usable_device(pdd)) 890 - continue; 891 - if (pdd->freectxts) { 892 - dd = pdd; 893 - break; 894 - } 895 - } 896 - } 897 - if (!dd) 898 - ret = -EBUSY; 899 - } 900 - done: 901 - return ret ? ret : allocate_ctxt(fp, dd, uinfo); 892 + dd = hfi1_lookup(devno); 893 + if (!dd) 894 + return -ENODEV; 895 + else if (!dd->freectxts) 896 + return -EBUSY; 897 + 898 + return allocate_ctxt(fp, dd, uinfo); 902 899 } 903 900 904 901 static int find_shared_ctxt(struct file *fp, ··· 1459 1546 return ret; 1460 1547 } 1461 1548 1462 - static int ui_open(struct inode *inode, struct file *filp) 1463 - { 1464 - struct hfi1_devdata *dd; 1465 - 1466 - dd = container_of(inode->i_cdev, struct hfi1_devdata, ui_cdev); 1467 - filp->private_data = dd; /* for other methods */ 1468 - return 0; 1469 - } 1470 - 1471 - static int ui_release(struct inode *inode, struct file *filp) 1472 - { 1473 - /* nothing to do */ 1474 - return 0; 1475 - } 1476 - 1477 - static loff_t ui_lseek(struct file *filp, loff_t offset, int whence) 1478 - { 1479 - struct hfi1_devdata *dd = filp->private_data; 1480 - 1481 - return fixed_size_llseek(filp, offset, whence, 1482 - (dd->kregend - dd->kregbase) + DC8051_DATA_MEM_SIZE); 1483 - } 1484 - 1485 - /* NOTE: assumes unsigned long is 8 bytes */ 1486 - static ssize_t ui_read(struct file *filp, char __user *buf, size_t count, 1487 - loff_t *f_pos) 1488 - { 1489 - struct hfi1_devdata *dd = filp->private_data; 1490 - void __iomem *base = dd->kregbase; 1491 - unsigned long total, csr_off, 1492 - barlen = (dd->kregend - dd->kregbase); 1493 - u64 data; 1494 - 1495 - /* only read 8 byte quantities */ 1496 - if ((count % 8) != 0) 1497 - return -EINVAL; 1498 - /* offset must be 8-byte aligned */ 1499 - if ((*f_pos % 8) != 0) 1500 - return -EINVAL; 1501 - /* destination buffer must be 8-byte aligned */ 1502 - if ((unsigned long)buf % 8 != 0) 1503 - return -EINVAL; 1504 - /* must be in range */ 1505 - if (*f_pos + count > (barlen + DC8051_DATA_MEM_SIZE)) 1506 - return -EINVAL; 1507 - /* only set the base if we are not starting past the BAR */ 1508 - if (*f_pos < barlen) 1509 - base += *f_pos; 1510 - csr_off = *f_pos; 1511 - for (total = 0; total < count; total += 8, csr_off += 8) { 1512 - /* accessing LCB CSRs requires more checks */ 1513 - if (is_lcb_offset(csr_off)) { 1514 - if (read_lcb_csr(dd, csr_off, (u64 *)&data)) 1515 - break; /* failed */ 1516 - } 1517 - /* 1518 - * Cannot read ASIC GPIO/QSFP* clear and force CSRs without a 1519 - * false parity error. Avoid the whole issue by not reading 1520 - * them. These registers are defined as having a read value 1521 - * of 0. 1522 - */ 1523 - else if (csr_off == ASIC_GPIO_CLEAR || 1524 - csr_off == ASIC_GPIO_FORCE || 1525 - csr_off == ASIC_QSFP1_CLEAR || 1526 - csr_off == ASIC_QSFP1_FORCE || 1527 - csr_off == ASIC_QSFP2_CLEAR || 1528 - csr_off == ASIC_QSFP2_FORCE) 1529 - data = 0; 1530 - else if (csr_off >= barlen) { 1531 - /* 1532 - * read_8051_data can read more than just 8 bytes at 1533 - * a time. However, folding this into the loop and 1534 - * handling the reads in 8 byte increments allows us 1535 - * to smoothly transition from chip memory to 8051 1536 - * memory. 1537 - */ 1538 - if (read_8051_data(dd, 1539 - (u32)(csr_off - barlen), 1540 - sizeof(data), &data)) 1541 - break; /* failed */ 1542 - } else 1543 - data = readq(base + total); 1544 - if (put_user(data, (unsigned long __user *)(buf + total))) 1545 - break; 1546 - } 1547 - *f_pos += total; 1548 - return total; 1549 - } 1550 - 1551 - /* NOTE: assumes unsigned long is 8 bytes */ 1552 - static ssize_t ui_write(struct file *filp, const char __user *buf, 1553 - size_t count, loff_t *f_pos) 1554 - { 1555 - struct hfi1_devdata *dd = filp->private_data; 1556 - void __iomem *base; 1557 - unsigned long total, data, csr_off; 1558 - int in_lcb; 1559 - 1560 - /* only write 8 byte quantities */ 1561 - if ((count % 8) != 0) 1562 - return -EINVAL; 1563 - /* offset must be 8-byte aligned */ 1564 - if ((*f_pos % 8) != 0) 1565 - return -EINVAL; 1566 - /* source buffer must be 8-byte aligned */ 1567 - if ((unsigned long)buf % 8 != 0) 1568 - return -EINVAL; 1569 - /* must be in range */ 1570 - if (*f_pos + count > dd->kregend - dd->kregbase) 1571 - return -EINVAL; 1572 - 1573 - base = (void __iomem *)dd->kregbase + *f_pos; 1574 - csr_off = *f_pos; 1575 - in_lcb = 0; 1576 - for (total = 0; total < count; total += 8, csr_off += 8) { 1577 - if (get_user(data, (unsigned long __user *)(buf + total))) 1578 - break; 1579 - /* accessing LCB CSRs requires a special procedure */ 1580 - if (is_lcb_offset(csr_off)) { 1581 - if (!in_lcb) { 1582 - int ret = acquire_lcb_access(dd, 1); 1583 - 1584 - if (ret) 1585 - break; 1586 - in_lcb = 1; 1587 - } 1588 - } else { 1589 - if (in_lcb) { 1590 - release_lcb_access(dd, 1); 1591 - in_lcb = 0; 1592 - } 1593 - } 1594 - writeq(data, base + total); 1595 - } 1596 - if (in_lcb) 1597 - release_lcb_access(dd, 1); 1598 - *f_pos += total; 1599 - return total; 1600 - } 1601 - 1602 - static const struct file_operations ui_file_ops = { 1603 - .owner = THIS_MODULE, 1604 - .llseek = ui_lseek, 1605 - .read = ui_read, 1606 - .write = ui_write, 1607 - .open = ui_open, 1608 - .release = ui_release, 1609 - }; 1610 - 1611 - #define UI_OFFSET 192 /* device minor offset for UI devices */ 1612 - static int create_ui = 1; 1613 - 1614 - static struct cdev wildcard_cdev; 1615 - static struct device *wildcard_device; 1616 - 1617 - static atomic_t user_count = ATOMIC_INIT(0); 1618 - 1619 1549 static void user_remove(struct hfi1_devdata *dd) 1620 1550 { 1621 - if (atomic_dec_return(&user_count) == 0) 1622 - hfi1_cdev_cleanup(&wildcard_cdev, &wildcard_device); 1623 1551 1624 1552 hfi1_cdev_cleanup(&dd->user_cdev, &dd->user_device); 1625 - hfi1_cdev_cleanup(&dd->ui_cdev, &dd->ui_device); 1626 1553 } 1627 1554 1628 1555 static int user_add(struct hfi1_devdata *dd) ··· 1470 1717 char name[10]; 1471 1718 int ret; 1472 1719 1473 - if (atomic_inc_return(&user_count) == 1) { 1474 - ret = hfi1_cdev_init(0, class_name(), &hfi1_file_ops, 1475 - &wildcard_cdev, &wildcard_device, 1476 - true); 1477 - if (ret) 1478 - goto done; 1479 - } 1480 - 1481 1720 snprintf(name, sizeof(name), "%s_%d", class_name(), dd->unit); 1482 - ret = hfi1_cdev_init(dd->unit + 1, name, &hfi1_file_ops, 1721 + ret = hfi1_cdev_init(dd->unit, name, &hfi1_file_ops, 1483 1722 &dd->user_cdev, &dd->user_device, 1484 - true); 1723 + true, &dd->kobj); 1485 1724 if (ret) 1486 - goto done; 1725 + user_remove(dd); 1487 1726 1488 - if (create_ui) { 1489 - snprintf(name, sizeof(name), 1490 - "%s_ui%d", class_name(), dd->unit); 1491 - ret = hfi1_cdev_init(dd->unit + UI_OFFSET, name, &ui_file_ops, 1492 - &dd->ui_cdev, &dd->ui_device, 1493 - false); 1494 - if (ret) 1495 - goto done; 1496 - } 1497 - 1498 - return 0; 1499 - done: 1500 - user_remove(dd); 1501 1727 return ret; 1502 1728 } 1503 1729 ··· 1485 1753 */ 1486 1754 int hfi1_device_create(struct hfi1_devdata *dd) 1487 1755 { 1488 - int r, ret; 1489 - 1490 - r = user_add(dd); 1491 - ret = hfi1_diag_add(dd); 1492 - if (r && !ret) 1493 - ret = r; 1494 - return ret; 1756 + return user_add(dd); 1495 1757 } 1496 1758 1497 1759 /* ··· 1495 1769 void hfi1_device_remove(struct hfi1_devdata *dd) 1496 1770 { 1497 1771 user_remove(dd); 1498 - hfi1_diag_remove(dd); 1499 1772 }
drivers/staging/rdma/hfi1/firmware.c drivers/infiniband/hw/hfi1/firmware.c
+4 -3
drivers/staging/rdma/hfi1/hfi.h drivers/infiniband/hw/hfi1/hfi.h
··· 453 453 #define HLS_LINK_COOLDOWN BIT(__HLS_LINK_COOLDOWN_BP) 454 454 455 455 #define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE) 456 + #define HLS_DOWN ~(HLS_UP) 456 457 457 458 /* use this MTU size if none other is given */ 458 459 #define HFI1_DEFAULT_ACTIVE_MTU 10240 ··· 1169 1168 atomic_t aspm_disabled_cnt; 1170 1169 1171 1170 struct hfi1_affinity *affinity; 1171 + struct kobject kobj; 1172 1172 }; 1173 1173 1174 1174 /* 8051 firmware version helper */ ··· 1884 1882 get_unit_name((dd)->unit), ##__VA_ARGS__) 1885 1883 1886 1884 #define hfi1_dev_porterr(dd, port, fmt, ...) \ 1887 - dev_err(&(dd)->pcidev->dev, "%s: IB%u:%u " fmt, \ 1888 - get_unit_name((dd)->unit), (dd)->unit, (port), \ 1889 - ##__VA_ARGS__) 1885 + dev_err(&(dd)->pcidev->dev, "%s: port %u: " fmt, \ 1886 + get_unit_name((dd)->unit), (port), ##__VA_ARGS__) 1890 1887 1891 1888 /* 1892 1889 * this is used for formatting hw error messages...
+17 -5
drivers/staging/rdma/hfi1/init.c drivers/infiniband/hw/hfi1/init.c
··· 732 732 lastfail = hfi1_create_rcvhdrq(dd, rcd); 733 733 if (!lastfail) 734 734 lastfail = hfi1_setup_eagerbufs(rcd); 735 - if (lastfail) 735 + if (lastfail) { 736 736 dd_dev_err(dd, 737 737 "failed to allocate kernel ctxt's rcvhdrq and/or egr bufs\n"); 738 + ret = lastfail; 739 + } 738 740 } 739 - if (lastfail) 740 - ret = lastfail; 741 741 742 742 /* Allocate enough memory for user event notification. */ 743 743 len = PAGE_ALIGN(dd->chip_rcv_contexts * HFI1_MAX_SHARED_CTXTS * ··· 989 989 dd->asic_data = NULL; 990 990 } 991 991 992 - void hfi1_free_devdata(struct hfi1_devdata *dd) 992 + static void __hfi1_free_devdata(struct kobject *kobj) 993 993 { 994 + struct hfi1_devdata *dd = 995 + container_of(kobj, struct hfi1_devdata, kobj); 994 996 unsigned long flags; 995 997 996 998 spin_lock_irqsave(&hfi1_devs_lock, flags); ··· 1007 1005 hfi1_dev_affinity_free(dd); 1008 1006 free_percpu(dd->send_schedule); 1009 1007 rvt_dealloc_device(&dd->verbs_dev.rdi); 1008 + } 1009 + 1010 + static struct kobj_type hfi1_devdata_type = { 1011 + .release = __hfi1_free_devdata, 1012 + }; 1013 + 1014 + void hfi1_free_devdata(struct hfi1_devdata *dd) 1015 + { 1016 + kobject_put(&dd->kobj); 1010 1017 } 1011 1018 1012 1019 /* ··· 1113 1102 &pdev->dev, 1114 1103 "Could not alloc cpulist info, cpu affinity might be wrong\n"); 1115 1104 } 1105 + kobject_init(&dd->kobj, &hfi1_devdata_type); 1116 1106 return dd; 1117 1107 1118 1108 bail: ··· 1312 1300 1313 1301 spin_lock(&ppd->cc_state_lock); 1314 1302 cc_state = get_cc_state(ppd); 1315 - rcu_assign_pointer(ppd->cc_state, NULL); 1303 + RCU_INIT_POINTER(ppd->cc_state, NULL); 1316 1304 spin_unlock(&ppd->cc_state_lock); 1317 1305 1318 1306 if (cc_state)
drivers/staging/rdma/hfi1/intr.c drivers/infiniband/hw/hfi1/intr.c
drivers/staging/rdma/hfi1/iowait.h drivers/infiniband/hw/hfi1/iowait.h
+66 -33
drivers/staging/rdma/hfi1/mad.c drivers/infiniband/hw/hfi1/mad.c
··· 1403 1403 if (key == okey) 1404 1404 continue; 1405 1405 /* 1406 + * Don't update pkeys[2], if an HFI port without MgmtAllowed 1407 + * by neighbor is a switch. 1408 + */ 1409 + if (i == 2 && !ppd->mgmt_allowed && ppd->neighbor_type == 1) 1410 + continue; 1411 + /* 1406 1412 * The SM gives us the complete PKey table. We have 1407 1413 * to ensure that we put the PKeys in the matching 1408 1414 * slots. ··· 3369 3363 return reply((struct ib_mad_hdr *)smp); 3370 3364 } 3371 3365 3366 + /* 3367 + * Apply congestion control information stored in the ppd to the 3368 + * active structure. 3369 + */ 3370 + static void apply_cc_state(struct hfi1_pportdata *ppd) 3371 + { 3372 + struct cc_state *old_cc_state, *new_cc_state; 3373 + 3374 + new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL); 3375 + if (!new_cc_state) 3376 + return; 3377 + 3378 + /* 3379 + * Hold the lock for updating *and* to prevent ppd information 3380 + * from changing during the update. 3381 + */ 3382 + spin_lock(&ppd->cc_state_lock); 3383 + 3384 + old_cc_state = get_cc_state(ppd); 3385 + if (!old_cc_state) { 3386 + /* never active, or shutting down */ 3387 + spin_unlock(&ppd->cc_state_lock); 3388 + kfree(new_cc_state); 3389 + return; 3390 + } 3391 + 3392 + *new_cc_state = *old_cc_state; 3393 + 3394 + new_cc_state->cct.ccti_limit = ppd->total_cct_entry - 1; 3395 + memcpy(new_cc_state->cct.entries, ppd->ccti_entries, 3396 + ppd->total_cct_entry * sizeof(struct ib_cc_table_entry)); 3397 + 3398 + new_cc_state->cong_setting.port_control = IB_CC_CCS_PC_SL_BASED; 3399 + new_cc_state->cong_setting.control_map = ppd->cc_sl_control_map; 3400 + memcpy(new_cc_state->cong_setting.entries, ppd->congestion_entries, 3401 + OPA_MAX_SLS * sizeof(struct opa_congestion_setting_entry)); 3402 + 3403 + rcu_assign_pointer(ppd->cc_state, new_cc_state); 3404 + 3405 + spin_unlock(&ppd->cc_state_lock); 3406 + 3407 + call_rcu(&old_cc_state->rcu, cc_state_reclaim); 3408 + } 3409 + 3372 3410 static int __subn_set_opa_cong_setting(struct opa_smp *smp, u32 am, u8 *data, 3373 3411 struct ib_device *ibdev, u8 port, 3374 3412 u32 *resp_len) ··· 3424 3374 struct opa_congestion_setting_entry_shadow *entries; 3425 3375 int i; 3426 3376 3377 + /* 3378 + * Save details from packet into the ppd. Hold the cc_state_lock so 3379 + * our information is consistent with anyone trying to apply the state. 3380 + */ 3381 + spin_lock(&ppd->cc_state_lock); 3427 3382 ppd->cc_sl_control_map = be32_to_cpu(p->control_map); 3428 3383 3429 3384 entries = ppd->congestion_entries; ··· 3439 3384 p->entries[i].trigger_threshold; 3440 3385 entries[i].ccti_min = p->entries[i].ccti_min; 3441 3386 } 3387 + spin_unlock(&ppd->cc_state_lock); 3388 + 3389 + /* now apply the information */ 3390 + apply_cc_state(ppd); 3442 3391 3443 3392 return __subn_get_opa_cong_setting(smp, am, data, ibdev, port, 3444 3393 resp_len); ··· 3585 3526 int i, j; 3586 3527 u32 sentry, eentry; 3587 3528 u16 ccti_limit; 3588 - struct cc_state *old_cc_state, *new_cc_state; 3589 3529 3590 3530 /* sanity check n_blocks, start_block */ 3591 3531 if (n_blocks == 0 || ··· 3604 3546 return reply((struct ib_mad_hdr *)smp); 3605 3547 } 3606 3548 3607 - new_cc_state = kzalloc(sizeof(*new_cc_state), GFP_KERNEL); 3608 - if (!new_cc_state) 3609 - goto getit; 3610 - 3549 + /* 3550 + * Save details from packet into the ppd. Hold the cc_state_lock so 3551 + * our information is consistent with anyone trying to apply the state. 3552 + */ 3611 3553 spin_lock(&ppd->cc_state_lock); 3612 - 3613 - old_cc_state = get_cc_state(ppd); 3614 - 3615 - if (!old_cc_state) { 3616 - spin_unlock(&ppd->cc_state_lock); 3617 - kfree(new_cc_state); 3618 - return reply((struct ib_mad_hdr *)smp); 3619 - } 3620 - 3621 - *new_cc_state = *old_cc_state; 3622 - 3623 - new_cc_state->cct.ccti_limit = ccti_limit; 3624 - 3625 - entries = ppd->ccti_entries; 3626 3554 ppd->total_cct_entry = ccti_limit + 1; 3627 - 3555 + entries = ppd->ccti_entries; 3628 3556 for (j = 0, i = sentry; i < eentry; j++, i++) 3629 3557 entries[i].entry = be16_to_cpu(p->ccti_entries[j].entry); 3630 - 3631 - memcpy(new_cc_state->cct.entries, entries, 3632 - eentry * sizeof(struct ib_cc_table_entry)); 3633 - 3634 - new_cc_state->cong_setting.port_control = IB_CC_CCS_PC_SL_BASED; 3635 - new_cc_state->cong_setting.control_map = ppd->cc_sl_control_map; 3636 - memcpy(new_cc_state->cong_setting.entries, ppd->congestion_entries, 3637 - OPA_MAX_SLS * sizeof(struct opa_congestion_setting_entry)); 3638 - 3639 - rcu_assign_pointer(ppd->cc_state, new_cc_state); 3640 - 3641 3558 spin_unlock(&ppd->cc_state_lock); 3642 3559 3643 - call_rcu(&old_cc_state->rcu, cc_state_reclaim); 3560 + /* now apply the information */ 3561 + apply_cc_state(ppd); 3644 3562 3645 - getit: 3646 3563 return __subn_get_opa_cc_table(smp, am, data, ibdev, port, resp_len); 3647 3564 } 3648 3565
drivers/staging/rdma/hfi1/mad.h drivers/infiniband/hw/hfi1/mad.h
+11 -11
drivers/staging/rdma/hfi1/mmu_rb.c drivers/infiniband/hw/hfi1/mmu_rb.c
··· 45 45 * 46 46 */ 47 47 #include <linux/list.h> 48 + #include <linux/rculist.h> 48 49 #include <linux/mmu_notifier.h> 49 50 #include <linux/interval_tree_generic.h> 50 51 ··· 98 97 int hfi1_mmu_rb_register(struct rb_root *root, struct mmu_rb_ops *ops) 99 98 { 100 99 struct mmu_rb_handler *handlr; 101 - unsigned long flags; 102 100 103 101 if (!ops->invalidate) 104 102 return -EINVAL; ··· 111 111 INIT_HLIST_NODE(&handlr->mn.hlist); 112 112 spin_lock_init(&handlr->lock); 113 113 handlr->mn.ops = &mn_opts; 114 - spin_lock_irqsave(&mmu_rb_lock, flags); 115 - list_add_tail(&handlr->list, &mmu_rb_handlers); 116 - spin_unlock_irqrestore(&mmu_rb_lock, flags); 114 + spin_lock(&mmu_rb_lock); 115 + list_add_tail_rcu(&handlr->list, &mmu_rb_handlers); 116 + spin_unlock(&mmu_rb_lock); 117 117 118 118 return mmu_notifier_register(&handlr->mn, current->mm); 119 119 } ··· 130 130 if (current->mm) 131 131 mmu_notifier_unregister(&handler->mn, current->mm); 132 132 133 - spin_lock_irqsave(&mmu_rb_lock, flags); 134 - list_del(&handler->list); 135 - spin_unlock_irqrestore(&mmu_rb_lock, flags); 133 + spin_lock(&mmu_rb_lock); 134 + list_del_rcu(&handler->list); 135 + spin_unlock(&mmu_rb_lock); 136 + synchronize_rcu(); 136 137 137 138 spin_lock_irqsave(&handler->lock, flags); 138 139 if (!RB_EMPTY_ROOT(root)) { ··· 272 271 static struct mmu_rb_handler *find_mmu_handler(struct rb_root *root) 273 272 { 274 273 struct mmu_rb_handler *handler; 275 - unsigned long flags; 276 274 277 - spin_lock_irqsave(&mmu_rb_lock, flags); 278 - list_for_each_entry(handler, &mmu_rb_handlers, list) { 275 + rcu_read_lock(); 276 + list_for_each_entry_rcu(handler, &mmu_rb_handlers, list) { 279 277 if (handler->root == root) 280 278 goto unlock; 281 279 } 282 280 handler = NULL; 283 281 unlock: 284 - spin_unlock_irqrestore(&mmu_rb_lock, flags); 282 + rcu_read_unlock(); 285 283 return handler; 286 284 } 287 285
drivers/staging/rdma/hfi1/mmu_rb.h drivers/infiniband/hw/hfi1/mmu_rb.h
drivers/staging/rdma/hfi1/opa_compat.h drivers/infiniband/hw/hfi1/opa_compat.h
drivers/staging/rdma/hfi1/pcie.c drivers/infiniband/hw/hfi1/pcie.c
+1 -2
drivers/staging/rdma/hfi1/pio.c drivers/infiniband/hw/hfi1/pio.c
··· 1835 1835 struct pio_vl_map *oldmap, *newmap; 1836 1836 1837 1837 if (!vl_scontexts) { 1838 - /* send context 0 reserved for VL15 */ 1839 - for (i = 1; i < dd->num_send_contexts; i++) 1838 + for (i = 0; i < dd->num_send_contexts; i++) 1840 1839 if (dd->send_contexts[i].type == SC_KERNEL) 1841 1840 num_kernel_send_contexts++; 1842 1841 /* truncate divide */
+4 -4
drivers/staging/rdma/hfi1/pio.h drivers/infiniband/hw/hfi1/pio.h
··· 49 49 50 50 /* send context types */ 51 51 #define SC_KERNEL 0 52 - #define SC_ACK 1 53 - #define SC_USER 2 54 - #define SC_VL15 3 55 - #define SC_MAX 4 52 + #define SC_VL15 1 53 + #define SC_ACK 2 54 + #define SC_USER 3 /* must be the last one: it may take all left */ 55 + #define SC_MAX 4 /* count of send context types */ 56 56 57 57 /* invalid send context index */ 58 58 #define INVALID_SCI 0xff
drivers/staging/rdma/hfi1/pio_copy.c drivers/infiniband/hw/hfi1/pio_copy.c
+17 -10
drivers/staging/rdma/hfi1/platform.c drivers/infiniband/hw/hfi1/platform.c
··· 87 87 */ 88 88 } 89 89 90 + void get_port_type(struct hfi1_pportdata *ppd) 91 + { 92 + int ret; 93 + 94 + ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0, 95 + PORT_TABLE_PORT_TYPE, &ppd->port_type, 96 + 4); 97 + if (ret) 98 + ppd->port_type = PORT_TYPE_UNKNOWN; 99 + } 100 + 90 101 int set_qsfp_tx(struct hfi1_pportdata *ppd, int on) 91 102 { 92 103 u8 tx_ctrl_byte = on ? 0x0 : 0xF; ··· 540 529 /* Enable external device config if channel is limiting active */ 541 530 read_8051_config(ppd->dd, LINK_OPTIMIZATION_SETTINGS, 542 531 GENERAL_CONFIG, &config_data); 543 - config_data |= limiting_active; 532 + config_data &= ~(0xff << ENABLE_EXT_DEV_CONFIG_SHIFT); 533 + config_data |= ((u32)limiting_active << ENABLE_EXT_DEV_CONFIG_SHIFT); 544 534 ret = load_8051_config(ppd->dd, LINK_OPTIMIZATION_SETTINGS, 545 535 GENERAL_CONFIG, config_data); 546 536 if (ret != HCMD_SUCCESS) ··· 554 542 /* Pass tuning method to 8051 */ 555 543 read_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG, 556 544 &config_data); 557 - config_data |= tuning_method; 545 + config_data &= ~(0xff << TUNING_METHOD_SHIFT); 546 + config_data |= ((u32)tuning_method << TUNING_METHOD_SHIFT); 558 547 ret = load_8051_config(ppd->dd, LINK_TUNING_PARAMETERS, GENERAL_CONFIG, 559 548 config_data); 560 549 if (ret != HCMD_SUCCESS) ··· 577 564 ret = read_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS, 578 565 GENERAL_CONFIG, &config_data); 579 566 /* Clear, then set the external device config field */ 580 - config_data &= ~(0xFF << 24); 581 - config_data |= (external_device_config << 24); 567 + config_data &= ~(u32)0xFF; 568 + config_data |= external_device_config; 582 569 ret = load_8051_config(ppd->dd, DC_HOST_COMM_SETTINGS, 583 570 GENERAL_CONFIG, config_data); 584 571 if (ret != HCMD_SUCCESS) ··· 796 783 ppd->driver_link_ready = 1; 797 784 return; 798 785 } 799 - 800 - ret = get_platform_config_field(ppd->dd, PLATFORM_CONFIG_PORT_TABLE, 0, 801 - PORT_TABLE_PORT_TYPE, &ppd->port_type, 802 - 4); 803 - if (ret) 804 - ppd->port_type = PORT_TYPE_UNKNOWN; 805 786 806 787 switch (ppd->port_type) { 807 788 case PORT_TYPE_DISCONNECTED:
+1
drivers/staging/rdma/hfi1/platform.h drivers/infiniband/hw/hfi1/platform.h
··· 298 298 /* platform.c */ 299 299 void get_platform_config(struct hfi1_devdata *dd); 300 300 void free_platform_config(struct hfi1_devdata *dd); 301 + void get_port_type(struct hfi1_pportdata *ppd); 301 302 int set_qsfp_tx(struct hfi1_pportdata *ppd, int on); 302 303 void tune_serdes(struct hfi1_pportdata *ppd); 303 304
+3 -6
drivers/staging/rdma/hfi1/qp.c drivers/infiniband/hw/hfi1/qp.c
··· 49 49 #include <linux/vmalloc.h> 50 50 #include <linux/hash.h> 51 51 #include <linux/module.h> 52 - #include <linux/random.h> 53 52 #include <linux/seq_file.h> 54 53 #include <rdma/rdma_vt.h> 55 54 #include <rdma/rdmavt_qp.h> ··· 160 161 * This function is what we would push to the core layer if we wanted to be a 161 162 * "first class citizen". Instead we hide this here and rely on Verbs ULPs 162 163 * to blindly pass the MTU enum value from the PathRecord to us. 163 - * 164 - * The actual flag used to determine "8k MTU" will change and is currently 165 - * unknown. 166 164 */ 167 165 static inline int verbs_mtu_enum_to_int(struct ib_device *dev, enum ib_mtu mtu) 168 166 { ··· 512 516 static void iowait_sdma_drained(struct iowait *wait) 513 517 { 514 518 struct rvt_qp *qp = iowait_to_qp(wait); 519 + unsigned long flags; 515 520 516 521 /* 517 522 * This happens when the send engine notes ··· 520 523 * do the flush work until that QP's 521 524 * sdma work has finished. 522 525 */ 523 - spin_lock(&qp->s_lock); 526 + spin_lock_irqsave(&qp->s_lock, flags); 524 527 if (qp->s_flags & RVT_S_WAIT_DMA) { 525 528 qp->s_flags &= ~RVT_S_WAIT_DMA; 526 529 hfi1_schedule_send(qp); 527 530 } 528 - spin_unlock(&qp->s_lock); 531 + spin_unlock_irqrestore(&qp->s_lock, flags); 529 532 } 530 533 531 534 /**
drivers/staging/rdma/hfi1/qp.h drivers/infiniband/hw/hfi1/qp.h
drivers/staging/rdma/hfi1/qsfp.c drivers/infiniband/hw/hfi1/qsfp.c
drivers/staging/rdma/hfi1/qsfp.h drivers/infiniband/hw/hfi1/qsfp.h
drivers/staging/rdma/hfi1/rc.c drivers/infiniband/hw/hfi1/rc.c
drivers/staging/rdma/hfi1/ruc.c drivers/infiniband/hw/hfi1/ruc.c
+3 -1
drivers/staging/rdma/hfi1/sdma.c drivers/infiniband/hw/hfi1/sdma.c
··· 134 134 [sdma_state_s99_running] = "s99_Running", 135 135 }; 136 136 137 + #ifdef CONFIG_SDMA_VERBOSITY 137 138 static const char * const sdma_event_names[] = { 138 139 [sdma_event_e00_go_hw_down] = "e00_GoHwDown", 139 140 [sdma_event_e10_go_hw_start] = "e10_GoHwStart", ··· 151 150 [sdma_event_e85_link_down] = "e85_LinkDown", 152 151 [sdma_event_e90_sw_halted] = "e90_SwHalted", 153 152 }; 153 + #endif 154 154 155 155 static const struct sdma_set_state_action sdma_action_table[] = { 156 156 [sdma_state_s00_hw_down] = { ··· 378 376 sdma_txclean(sde->dd, tx); 379 377 if (complete) 380 378 (*complete)(tx, res); 381 - if (iowait_sdma_dec(wait) && wait) 379 + if (wait && iowait_sdma_dec(wait)) 382 380 iowait_drain_wakeup(wait); 383 381 } 384 382
drivers/staging/rdma/hfi1/sdma.h drivers/infiniband/hw/hfi1/sdma.h
drivers/staging/rdma/hfi1/sdma_txreq.h drivers/infiniband/hw/hfi1/sdma_txreq.h
+2 -2
drivers/staging/rdma/hfi1/sysfs.c drivers/infiniband/hw/hfi1/sysfs.c
··· 721 721 } 722 722 723 723 dd_dev_info(dd, 724 - "IB%u: Congestion Control Agent enabled for port %d\n", 725 - dd->unit, port_num); 724 + "Congestion Control Agent enabled for port %d\n", 725 + port_num); 726 726 727 727 return 0; 728 728
+8
drivers/staging/rdma/hfi1/trace.c drivers/infiniband/hw/hfi1/trace.c
··· 66 66 #define RETH_PRN "reth vaddr 0x%.16llx rkey 0x%.8x dlen 0x%.8x" 67 67 #define AETH_PRN "aeth syn 0x%.2x %s msn 0x%.8x" 68 68 #define DETH_PRN "deth qkey 0x%.8x sqpn 0x%.6x" 69 + #define IETH_PRN "ieth rkey 0x%.8x" 69 70 #define ATOMICACKETH_PRN "origdata %lld" 70 71 #define ATOMICETH_PRN "vaddr 0x%llx rkey 0x%.8x sdata %lld cdata %lld" 71 72 ··· 167 166 be32_to_cpu(eh->ud.deth[0]), 168 167 be32_to_cpu(eh->ud.deth[1]) & RVT_QPN_MASK); 169 168 break; 169 + /* ieth */ 170 + case OP(RC, SEND_LAST_WITH_INVALIDATE): 171 + case OP(RC, SEND_ONLY_WITH_INVALIDATE): 172 + trace_seq_printf(p, IETH_PRN, 173 + be32_to_cpu(eh->ieth)); 174 + break; 170 175 } 171 176 trace_seq_putc(p, 0); 172 177 return ret; ··· 240 233 __hfi1_trace_fn(RCVCTRL); 241 234 __hfi1_trace_fn(TID); 242 235 __hfi1_trace_fn(MMU); 236 + __hfi1_trace_fn(IOCTL);
+4 -1
drivers/staging/rdma/hfi1/trace.h drivers/infiniband/hw/hfi1/trace.h
··· 74 74 75 75 TRACE_EVENT(hfi1_rcvhdr, 76 76 TP_PROTO(struct hfi1_devdata *dd, 77 - u64 eflags, 78 77 u32 ctxt, 78 + u64 eflags, 79 79 u32 etype, 80 80 u32 hlen, 81 81 u32 tlen, ··· 392 392 ib_opcode_name(RC_ATOMIC_ACKNOWLEDGE), \ 393 393 ib_opcode_name(RC_COMPARE_SWAP), \ 394 394 ib_opcode_name(RC_FETCH_ADD), \ 395 + ib_opcode_name(RC_SEND_LAST_WITH_INVALIDATE), \ 396 + ib_opcode_name(RC_SEND_ONLY_WITH_INVALIDATE), \ 395 397 ib_opcode_name(UC_SEND_FIRST), \ 396 398 ib_opcode_name(UC_SEND_MIDDLE), \ 397 399 ib_opcode_name(UC_SEND_LAST), \ ··· 1343 1341 __hfi1_trace_def(RCVCTRL); 1344 1342 __hfi1_trace_def(TID); 1345 1343 __hfi1_trace_def(MMU); 1344 + __hfi1_trace_def(IOCTL); 1346 1345 1347 1346 #define hfi1_cdbg(which, fmt, ...) \ 1348 1347 __hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
drivers/staging/rdma/hfi1/twsi.c drivers/infiniband/hw/hfi1/twsi.c
drivers/staging/rdma/hfi1/twsi.h drivers/infiniband/hw/hfi1/twsi.h
drivers/staging/rdma/hfi1/uc.c drivers/infiniband/hw/hfi1/uc.c
drivers/staging/rdma/hfi1/ud.c drivers/infiniband/hw/hfi1/ud.c
drivers/staging/rdma/hfi1/user_exp_rcv.c drivers/infiniband/hw/hfi1/user_exp_rcv.c
drivers/staging/rdma/hfi1/user_exp_rcv.h drivers/infiniband/hw/hfi1/user_exp_rcv.h
drivers/staging/rdma/hfi1/user_pages.c drivers/infiniband/hw/hfi1/user_pages.c
+10 -8
drivers/staging/rdma/hfi1/user_sdma.c drivers/infiniband/hw/hfi1/user_sdma.c
··· 166 166 167 167 #define SDMA_IOWAIT_TIMEOUT 1000 /* in milliseconds */ 168 168 169 + struct sdma_mmu_node; 170 + 169 171 struct user_sdma_iovec { 170 172 struct list_head list; 171 173 struct iovec iov; ··· 180 178 * which we last left off. 181 179 */ 182 180 u64 offset; 181 + struct sdma_mmu_node *node; 183 182 }; 184 183 185 184 #define SDMA_CACHE_NODE_EVICT BIT(0) ··· 510 507 struct sdma_req_info info; 511 508 struct user_sdma_request *req; 512 509 u8 opcode, sc, vl; 510 + int req_queued = 0; 513 511 514 512 if (iovec[idx].iov_len < sizeof(info) + sizeof(req->hdr)) { 515 513 hfi1_cdbg( ··· 707 703 708 704 set_comp_state(pq, cq, info.comp_idx, QUEUED, 0); 709 705 atomic_inc(&pq->n_reqs); 706 + req_queued = 1; 710 707 /* Send the first N packets in the request to buy us some time */ 711 708 ret = user_sdma_send_pkts(req, pcount); 712 709 if (unlikely(ret < 0 && ret != -EBUSY)) { ··· 752 747 return 0; 753 748 free_req: 754 749 user_sdma_free_request(req, true); 755 - pq_update(pq); 750 + if (req_queued) 751 + pq_update(pq); 756 752 set_comp_state(pq, cq, info.comp_idx, ERROR, req->status); 757 753 return ret; 758 754 } ··· 1159 1153 } 1160 1154 iovec->pages = node->pages; 1161 1155 iovec->npages = npages; 1156 + iovec->node = node; 1162 1157 1163 1158 ret = hfi1_mmu_rb_insert(&req->pq->sdma_rb_root, &node->rb); 1164 1159 if (ret) { ··· 1526 1519 } 1527 1520 if (req->data_iovs) { 1528 1521 struct sdma_mmu_node *node; 1529 - struct mmu_rb_node *mnode; 1530 1522 int i; 1531 1523 1532 1524 for (i = 0; i < req->data_iovs; i++) { 1533 - mnode = hfi1_mmu_rb_search( 1534 - &req->pq->sdma_rb_root, 1535 - (unsigned long)req->iovs[i].iov.iov_base, 1536 - req->iovs[i].iov.iov_len); 1537 - if (!mnode || IS_ERR(mnode)) 1525 + node = req->iovs[i].node; 1526 + if (!node) 1538 1527 continue; 1539 1528 1540 - node = container_of(mnode, struct sdma_mmu_node, rb); 1541 1529 if (unpin) 1542 1530 hfi1_mmu_rb_remove(&req->pq->sdma_rb_root, 1543 1531 &node->rb);
drivers/staging/rdma/hfi1/user_sdma.h drivers/infiniband/hw/hfi1/user_sdma.h
+2 -2
drivers/staging/rdma/hfi1/verbs.c drivers/infiniband/hw/hfi1/verbs.c
··· 52 52 #include <linux/utsname.h> 53 53 #include <linux/rculist.h> 54 54 #include <linux/mm.h> 55 - #include <linux/random.h> 56 55 #include <linux/vmalloc.h> 57 56 58 57 #include "hfi.h" ··· 335 336 [IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE] = 12 + 8 + 4, 336 337 [IB_OPCODE_RC_COMPARE_SWAP] = 12 + 8 + 28, 337 338 [IB_OPCODE_RC_FETCH_ADD] = 12 + 8 + 28, 339 + [IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE] = 12 + 8 + 4, 340 + [IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE] = 12 + 8 + 4, 338 341 /* UC */ 339 342 [IB_OPCODE_UC_SEND_FIRST] = 12 + 8, 340 343 [IB_OPCODE_UC_SEND_MIDDLE] = 12 + 8, ··· 947 946 948 947 dev->n_piowait += !!(flag & RVT_S_WAIT_PIO); 949 948 dev->n_piodrain += !!(flag & RVT_S_WAIT_PIO_DRAIN); 950 - dev->n_piowait++; 951 949 qp->s_flags |= flag; 952 950 was_empty = list_empty(&sc->piowait); 953 951 list_add_tail(&priv->s_iowait.list, &sc->piowait);
+1
drivers/staging/rdma/hfi1/verbs.h drivers/infiniband/hw/hfi1/verbs.h
··· 152 152 } at; 153 153 __be32 imm_data; 154 154 __be32 aeth; 155 + __be32 ieth; 155 156 struct ib_atomic_eth atomic_eth; 156 157 } __packed; 157 158
drivers/staging/rdma/hfi1/verbs_txreq.c drivers/infiniband/hw/hfi1/verbs_txreq.c
drivers/staging/rdma/hfi1/verbs_txreq.h drivers/infiniband/hw/hfi1/verbs_txreq.h
+58 -2
include/rdma/ib_mad.h
··· 239 239 240 240 #define IB_MGMT_CLASSPORTINFO_ATTR_ID cpu_to_be16(0x0001) 241 241 242 + #define IB_CLASS_PORT_INFO_RESP_TIME_MASK 0x1F 243 + #define IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE 5 244 + 242 245 struct ib_class_port_info { 243 246 u8 base_version; 244 247 u8 class_version; 245 248 __be16 capability_mask; 246 - u8 reserved[3]; 247 - u8 resp_time_value; 249 + /* 27 bits for cap_mask2, 5 bits for resp_time */ 250 + __be32 cap_mask2_resp_time; 248 251 u8 redirect_gid[16]; 249 252 __be32 redirect_tcslfl; 250 253 __be16 redirect_lid; ··· 261 258 __be32 trap_hlqp; 262 259 __be32 trap_qkey; 263 260 }; 261 + 262 + /** 263 + * ib_get_cpi_resp_time - Returns the resp_time value from 264 + * cap_mask2_resp_time in ib_class_port_info. 265 + * @cpi: A struct ib_class_port_info mad. 266 + */ 267 + static inline u8 ib_get_cpi_resp_time(struct ib_class_port_info *cpi) 268 + { 269 + return (u8)(be32_to_cpu(cpi->cap_mask2_resp_time) & 270 + IB_CLASS_PORT_INFO_RESP_TIME_MASK); 271 + } 272 + 273 + /** 274 + * ib_set_cpi_resptime - Sets the response time in an 275 + * ib_class_port_info mad. 276 + * @cpi: A struct ib_class_port_info. 277 + * @rtime: The response time to set. 278 + */ 279 + static inline void ib_set_cpi_resp_time(struct ib_class_port_info *cpi, 280 + u8 rtime) 281 + { 282 + cpi->cap_mask2_resp_time = 283 + (cpi->cap_mask2_resp_time & 284 + cpu_to_be32(~IB_CLASS_PORT_INFO_RESP_TIME_MASK)) | 285 + cpu_to_be32(rtime & IB_CLASS_PORT_INFO_RESP_TIME_MASK); 286 + } 287 + 288 + /** 289 + * ib_get_cpi_capmask2 - Returns the capmask2 value from 290 + * cap_mask2_resp_time in ib_class_port_info. 291 + * @cpi: A struct ib_class_port_info mad. 292 + */ 293 + static inline u32 ib_get_cpi_capmask2(struct ib_class_port_info *cpi) 294 + { 295 + return (be32_to_cpu(cpi->cap_mask2_resp_time) >> 296 + IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE); 297 + } 298 + 299 + /** 300 + * ib_set_cpi_capmask2 - Sets the capmask2 in an 301 + * ib_class_port_info mad. 302 + * @cpi: A struct ib_class_port_info. 303 + * @capmask2: The capmask2 to set. 304 + */ 305 + static inline void ib_set_cpi_capmask2(struct ib_class_port_info *cpi, 306 + u32 capmask2) 307 + { 308 + cpi->cap_mask2_resp_time = 309 + (cpi->cap_mask2_resp_time & 310 + cpu_to_be32(IB_CLASS_PORT_INFO_RESP_TIME_MASK)) | 311 + cpu_to_be32(capmask2 << 312 + IB_CLASS_PORT_INFO_RESP_TIME_FIELD_SIZE); 313 + } 264 314 265 315 struct ib_mad_notice_attr { 266 316 u8 generic_type;
+5
include/rdma/ib_pack.h
··· 103 103 IB_OPCODE_ATOMIC_ACKNOWLEDGE = 0x12, 104 104 IB_OPCODE_COMPARE_SWAP = 0x13, 105 105 IB_OPCODE_FETCH_ADD = 0x14, 106 + /* opcode 0x15 is reserved */ 107 + IB_OPCODE_SEND_LAST_WITH_INVALIDATE = 0x16, 108 + IB_OPCODE_SEND_ONLY_WITH_INVALIDATE = 0x17, 106 109 107 110 /* real constants follow -- see comment about above IB_OPCODE() 108 111 macro for more details */ ··· 132 129 IB_OPCODE(RC, ATOMIC_ACKNOWLEDGE), 133 130 IB_OPCODE(RC, COMPARE_SWAP), 134 131 IB_OPCODE(RC, FETCH_ADD), 132 + IB_OPCODE(RC, SEND_LAST_WITH_INVALIDATE), 133 + IB_OPCODE(RC, SEND_ONLY_WITH_INVALIDATE), 135 134 136 135 /* UC */ 137 136 IB_OPCODE(UC, SEND_FIRST),
+12
include/rdma/ib_sa.h
··· 94 94 IB_SA_BEST = 3 95 95 }; 96 96 97 + #define IB_SA_CAP_MASK2_SENDONLY_FULL_MEM_SUPPORT BIT(12) 98 + 97 99 /* 98 100 * Structures for SA records are named "struct ib_sa_xxx_rec." No 99 101 * attempt is made to pack structures to match the physical layout of ··· 440 438 void *context), 441 439 void *context, 442 440 struct ib_sa_query **sa_query); 441 + 442 + /* Support get SA ClassPortInfo */ 443 + int ib_sa_classport_info_rec_query(struct ib_sa_client *client, 444 + struct ib_device *device, u8 port_num, 445 + int timeout_ms, gfp_t gfp_mask, 446 + void (*callback)(int status, 447 + struct ib_class_port_info *resp, 448 + void *context), 449 + void *context, 450 + struct ib_sa_query **sa_query); 443 451 444 452 #endif /* IB_SA_H */
+70 -48
include/rdma/ib_verbs.h
··· 403 403 IB_SPEED_EDR = 32 404 404 }; 405 405 406 - struct ib_protocol_stats { 407 - /* TBD... */ 406 + /** 407 + * struct rdma_hw_stats 408 + * @timestamp - Used by the core code to track when the last update was 409 + * @lifespan - Used by the core code to determine how old the counters 410 + * should be before being updated again. Stored in jiffies, defaults 411 + * to 10 milliseconds, drivers can override the default be specifying 412 + * their own value during their allocation routine. 413 + * @name - Array of pointers to static names used for the counters in 414 + * directory. 415 + * @num_counters - How many hardware counters there are. If name is 416 + * shorter than this number, a kernel oops will result. Driver authors 417 + * are encouraged to leave BUILD_BUG_ON(ARRAY_SIZE(@name) < num_counters) 418 + * in their code to prevent this. 419 + * @value - Array of u64 counters that are accessed by the sysfs code and 420 + * filled in by the drivers get_stats routine 421 + */ 422 + struct rdma_hw_stats { 423 + unsigned long timestamp; 424 + unsigned long lifespan; 425 + const char * const *names; 426 + int num_counters; 427 + u64 value[]; 408 428 }; 409 429 410 - struct iw_protocol_stats { 411 - u64 ipInReceives; 412 - u64 ipInHdrErrors; 413 - u64 ipInTooBigErrors; 414 - u64 ipInNoRoutes; 415 - u64 ipInAddrErrors; 416 - u64 ipInUnknownProtos; 417 - u64 ipInTruncatedPkts; 418 - u64 ipInDiscards; 419 - u64 ipInDelivers; 420 - u64 ipOutForwDatagrams; 421 - u64 ipOutRequests; 422 - u64 ipOutDiscards; 423 - u64 ipOutNoRoutes; 424 - u64 ipReasmTimeout; 425 - u64 ipReasmReqds; 426 - u64 ipReasmOKs; 427 - u64 ipReasmFails; 428 - u64 ipFragOKs; 429 - u64 ipFragFails; 430 - u64 ipFragCreates; 431 - u64 ipInMcastPkts; 432 - u64 ipOutMcastPkts; 433 - u64 ipInBcastPkts; 434 - u64 ipOutBcastPkts; 430 + #define RDMA_HW_STATS_DEFAULT_LIFESPAN 10 431 + /** 432 + * rdma_alloc_hw_stats_struct - Helper function to allocate dynamic struct 433 + * for drivers. 434 + * @names - Array of static const char * 435 + * @num_counters - How many elements in array 436 + * @lifespan - How many milliseconds between updates 437 + */ 438 + static inline struct rdma_hw_stats *rdma_alloc_hw_stats_struct( 439 + const char * const *names, int num_counters, 440 + unsigned long lifespan) 441 + { 442 + struct rdma_hw_stats *stats; 435 443 436 - u64 tcpRtoAlgorithm; 437 - u64 tcpRtoMin; 438 - u64 tcpRtoMax; 439 - u64 tcpMaxConn; 440 - u64 tcpActiveOpens; 441 - u64 tcpPassiveOpens; 442 - u64 tcpAttemptFails; 443 - u64 tcpEstabResets; 444 - u64 tcpCurrEstab; 445 - u64 tcpInSegs; 446 - u64 tcpOutSegs; 447 - u64 tcpRetransSegs; 448 - u64 tcpInErrs; 449 - u64 tcpOutRsts; 450 - }; 444 + stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64), 445 + GFP_KERNEL); 446 + if (!stats) 447 + return NULL; 448 + stats->names = names; 449 + stats->num_counters = num_counters; 450 + stats->lifespan = msecs_to_jiffies(lifespan); 451 451 452 - union rdma_protocol_stats { 453 - struct ib_protocol_stats ib; 454 - struct iw_protocol_stats iw; 455 - }; 452 + return stats; 453 + } 454 + 456 455 457 456 /* Define bits for the various functionality this port needs to be supported by 458 457 * the core. ··· 1706 1707 1707 1708 struct iw_cm_verbs *iwcm; 1708 1709 1709 - int (*get_protocol_stats)(struct ib_device *device, 1710 - union rdma_protocol_stats *stats); 1710 + /** 1711 + * alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the 1712 + * driver initialized data. The struct is kfree()'ed by the sysfs 1713 + * core when the device is removed. A lifespan of -1 in the return 1714 + * struct tells the core to set a default lifespan. 1715 + */ 1716 + struct rdma_hw_stats *(*alloc_hw_stats)(struct ib_device *device, 1717 + u8 port_num); 1718 + /** 1719 + * get_hw_stats - Fill in the counter value(s) in the stats struct. 1720 + * @index - The index in the value array we wish to have updated, or 1721 + * num_counters if we want all stats updated 1722 + * Return codes - 1723 + * < 0 - Error, no counters updated 1724 + * index - Updated the single counter pointed to by index 1725 + * num_counters - Updated all counters (will reset the timestamp 1726 + * and prevent further calls for lifespan milliseconds) 1727 + * Drivers are allowed to update all counters in leiu of just the 1728 + * one given in index at their option 1729 + */ 1730 + int (*get_hw_stats)(struct ib_device *device, 1731 + struct rdma_hw_stats *stats, 1732 + u8 port, int index); 1711 1733 int (*query_device)(struct ib_device *device, 1712 1734 struct ib_device_attr *device_attr, 1713 1735 struct ib_udata *udata); ··· 1946 1926 u8 node_type; 1947 1927 u8 phys_port_cnt; 1948 1928 struct ib_device_attr attrs; 1929 + struct attribute_group *hw_stats_ag; 1930 + struct rdma_hw_stats *hw_stats; 1949 1931 1950 1932 /** 1951 1933 * The following mandatory functions are used only at device
+11 -2
include/rdma/rdma_vt.h
··· 149 149 int qpn_res_end; 150 150 int nports; 151 151 int npkeys; 152 - u8 qos_shift; 153 152 char cq_name[RVT_CQN_MAX]; 154 153 int node; 155 - int max_rdma_atomic; 156 154 int psn_mask; 157 155 int psn_shift; 158 156 int psn_modify_mask; 159 157 u32 core_cap_flags; 160 158 u32 max_mad_size; 159 + u8 qos_shift; 160 + u8 max_rdma_atomic; 161 161 }; 162 162 163 163 /* Protection domain */ ··· 423 423 * All ports have same number of pkeys. 424 424 */ 425 425 return rdi->dparms.npkeys; 426 + } 427 + 428 + /* 429 + * Return the max atomic suitable for determining 430 + * the size of the ack ring buffer in a QP. 431 + */ 432 + static inline unsigned int rvt_max_atomic(struct rvt_dev_info *rdi) 433 + { 434 + return rdi->dparms.max_rdma_atomic + 1; 426 435 } 427 436 428 437 /*
+1 -4
include/rdma/rdmavt_qp.h
··· 211 211 unsigned size; 212 212 }; 213 213 214 - #define RVT_MAX_RDMA_ATOMIC 16 215 - 216 214 /* 217 215 * This structure holds the information that the send tasklet needs 218 216 * to send a RDMA read response or atomic operation. ··· 280 282 atomic_t refcount ____cacheline_aligned_in_smp; 281 283 wait_queue_head_t wait; 282 284 283 - struct rvt_ack_entry s_ack_queue[RVT_MAX_RDMA_ATOMIC + 1] 284 - ____cacheline_aligned_in_smp; 285 + struct rvt_ack_entry *s_ack_queue; 285 286 struct rvt_sge_state s_rdma_read_sge; 286 287 287 288 spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */
+48 -32
include/uapi/rdma/hfi/hfi1_user.h
··· 66 66 * The major version changes when data structures change in an incompatible 67 67 * way. The driver must be the same for initialization to succeed. 68 68 */ 69 - #define HFI1_USER_SWMAJOR 5 69 + #define HFI1_USER_SWMAJOR 6 70 70 71 71 /* 72 72 * Minor version differences are always compatible ··· 75 75 * may not be implemented; the user code must deal with this if it 76 76 * cares, or it must abort after initialization reports the difference. 77 77 */ 78 - #define HFI1_USER_SWMINOR 0 78 + #define HFI1_USER_SWMINOR 1 79 + 80 + /* 81 + * We will encode the major/minor inside a single 32bit version number. 82 + */ 83 + #define HFI1_SWMAJOR_SHIFT 16 79 84 80 85 /* 81 86 * Set of HW and driver capability/feature bits. ··· 112 107 #define HFI1_RCVHDR_ENTSIZE_16 (1UL << 1) 113 108 #define HFI1_RCVDHR_ENTSIZE_32 (1UL << 2) 114 109 115 - /* 116 - * If the unit is specified via open, HFI choice is fixed. If port is 117 - * specified, it's also fixed. Otherwise we try to spread contexts 118 - * across ports and HFIs, using different algorithms. WITHIN is 119 - * the old default, prior to this mechanism. 120 - */ 121 - #define HFI1_ALG_ACROSS 0 /* round robin contexts across HFIs, then 122 - * ports; this is the default */ 123 - #define HFI1_ALG_WITHIN 1 /* use all contexts on an HFI (round robin 124 - * active ports within), then next HFI */ 125 - #define HFI1_ALG_COUNT 2 /* number of algorithm choices */ 126 - 127 - 128 110 /* User commands. */ 129 111 #define HFI1_CMD_ASSIGN_CTXT 1 /* allocate HFI and context */ 130 112 #define HFI1_CMD_CTXT_INFO 2 /* find out what resources we got */ ··· 119 127 #define HFI1_CMD_TID_UPDATE 4 /* update expected TID entries */ 120 128 #define HFI1_CMD_TID_FREE 5 /* free expected TID entries */ 121 129 #define HFI1_CMD_CREDIT_UPD 6 /* force an update of PIO credit */ 122 - #define HFI1_CMD_SDMA_STATUS_UPD 7 /* force update of SDMA status ring */ 123 130 124 131 #define HFI1_CMD_RECV_CTRL 8 /* control receipt of packets */ 125 132 #define HFI1_CMD_POLL_TYPE 9 /* set the kind of polling we want */ ··· 126 135 #define HFI1_CMD_SET_PKEY 11 /* set context's pkey */ 127 136 #define HFI1_CMD_CTXT_RESET 12 /* reset context's HW send context */ 128 137 #define HFI1_CMD_TID_INVAL_READ 13 /* read TID cache invalidations */ 129 - /* separate EPROM commands from normal PSM commands */ 130 - #define HFI1_CMD_EP_INFO 64 /* read EPROM device ID */ 131 - #define HFI1_CMD_EP_ERASE_CHIP 65 /* erase whole EPROM */ 132 - /* range 66-74 no longer used */ 133 - #define HFI1_CMD_EP_ERASE_RANGE 75 /* erase EPROM range */ 134 - #define HFI1_CMD_EP_READ_RANGE 76 /* read EPROM range */ 135 - #define HFI1_CMD_EP_WRITE_RANGE 77 /* write EPROM range */ 138 + #define HFI1_CMD_GET_VERS 14 /* get the version of the user cdev */ 139 + 140 + /* 141 + * User IOCTLs can not go above 128 if they do then see common.h and change the 142 + * base for the snoop ioctl 143 + */ 144 + #define IB_IOCTL_MAGIC 0x1b /* See Documentation/ioctl/ioctl-number.txt */ 145 + 146 + /* 147 + * Make the ioctls occupy the last 0xf0-0xff portion of the IB range 148 + */ 149 + #define __NUM(cmd) (HFI1_CMD_##cmd + 0xe0) 150 + 151 + struct hfi1_cmd; 152 + #define HFI1_IOCTL_ASSIGN_CTXT \ 153 + _IOWR(IB_IOCTL_MAGIC, __NUM(ASSIGN_CTXT), struct hfi1_user_info) 154 + #define HFI1_IOCTL_CTXT_INFO \ 155 + _IOW(IB_IOCTL_MAGIC, __NUM(CTXT_INFO), struct hfi1_ctxt_info) 156 + #define HFI1_IOCTL_USER_INFO \ 157 + _IOW(IB_IOCTL_MAGIC, __NUM(USER_INFO), struct hfi1_base_info) 158 + #define HFI1_IOCTL_TID_UPDATE \ 159 + _IOWR(IB_IOCTL_MAGIC, __NUM(TID_UPDATE), struct hfi1_tid_info) 160 + #define HFI1_IOCTL_TID_FREE \ 161 + _IOWR(IB_IOCTL_MAGIC, __NUM(TID_FREE), struct hfi1_tid_info) 162 + #define HFI1_IOCTL_CREDIT_UPD \ 163 + _IO(IB_IOCTL_MAGIC, __NUM(CREDIT_UPD)) 164 + #define HFI1_IOCTL_RECV_CTRL \ 165 + _IOW(IB_IOCTL_MAGIC, __NUM(RECV_CTRL), int) 166 + #define HFI1_IOCTL_POLL_TYPE \ 167 + _IOW(IB_IOCTL_MAGIC, __NUM(POLL_TYPE), int) 168 + #define HFI1_IOCTL_ACK_EVENT \ 169 + _IOW(IB_IOCTL_MAGIC, __NUM(ACK_EVENT), unsigned long) 170 + #define HFI1_IOCTL_SET_PKEY \ 171 + _IOW(IB_IOCTL_MAGIC, __NUM(SET_PKEY), __u16) 172 + #define HFI1_IOCTL_CTXT_RESET \ 173 + _IO(IB_IOCTL_MAGIC, __NUM(CTXT_RESET)) 174 + #define HFI1_IOCTL_TID_INVAL_READ \ 175 + _IOWR(IB_IOCTL_MAGIC, __NUM(TID_INVAL_READ), struct hfi1_tid_info) 176 + #define HFI1_IOCTL_GET_VERS \ 177 + _IOR(IB_IOCTL_MAGIC, __NUM(GET_VERS), int) 136 178 137 179 #define _HFI1_EVENT_FROZEN_BIT 0 138 180 #define _HFI1_EVENT_LINKDOWN_BIT 1 ··· 223 199 * Should be set to HFI1_USER_SWVERSION. 224 200 */ 225 201 __u32 userversion; 226 - __u16 pad; 227 - /* HFI selection algorithm, if unit has not selected */ 228 - __u16 hfi1_alg; 202 + __u32 pad; 229 203 /* 230 204 * If two or more processes wish to share a context, each process 231 205 * must set the subcontext_cnt and subcontext_id to the same ··· 263 241 __u32 tidcnt; 264 242 /* length of transfer buffer programmed by this request */ 265 243 __u32 length; 266 - }; 267 - 268 - struct hfi1_cmd { 269 - __u32 type; /* command type */ 270 - __u32 len; /* length of struct pointed to by add */ 271 - __u64 addr; /* pointer to user structure */ 272 244 }; 273 245 274 246 enum hfi1_sdma_comp_state {
+10
include/uapi/rdma/rdma_netlink.h
··· 135 135 * Local service operations: 136 136 * RESOLVE - The client requests the local service to resolve a path. 137 137 * SET_TIMEOUT - The local service requests the client to set the timeout. 138 + * IP_RESOLVE - The client requests the local service to resolve an IP to GID. 138 139 */ 139 140 enum { 140 141 RDMA_NL_LS_OP_RESOLVE = 0, 141 142 RDMA_NL_LS_OP_SET_TIMEOUT, 143 + RDMA_NL_LS_OP_IP_RESOLVE, 142 144 RDMA_NL_LS_NUM_OPS 143 145 }; 144 146 ··· 178 176 __u8 path_use; 179 177 }; 180 178 179 + struct rdma_ls_ip_resolve_header { 180 + __u32 ifindex; 181 + }; 182 + 181 183 /* Local service attribute type */ 182 184 #define RDMA_NLA_F_MANDATORY (1 << 13) 183 185 #define RDMA_NLA_TYPE_MASK (~(NLA_F_NESTED | NLA_F_NET_BYTEORDER | \ ··· 199 193 * TCLASS u8 200 194 * PKEY u16 cpu 201 195 * QOS_CLASS u16 cpu 196 + * IPV4 u32 BE 197 + * IPV6 u8[16] BE 202 198 */ 203 199 enum { 204 200 LS_NLA_TYPE_UNSPEC = 0, ··· 212 204 LS_NLA_TYPE_TCLASS, 213 205 LS_NLA_TYPE_PKEY, 214 206 LS_NLA_TYPE_QOS_CLASS, 207 + LS_NLA_TYPE_IPV4, 208 + LS_NLA_TYPE_IPV6, 215 209 LS_NLA_TYPE_MAX 216 210 }; 217 211