cma.c (ac0053fd51d2bac09a7d4b4a59f6dac863bd4373) cma.c (5d7220e8dc24feed4bbd66667b7696906a147ac4)
1/*
2 * Copyright (c) 2005 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
4 * Copyright (c) 1999-2005, Mellanox Technologies, Inc. All rights reserved.
5 * Copyright (c) 2005-2006 Intel Corporation. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU

--- 65 unchanged lines hidden (view full) ---

74static LIST_HEAD(dev_list);
75static LIST_HEAD(listen_any_list);
76static DEFINE_MUTEX(lock);
77static struct workqueue_struct *cma_wq;
78static DEFINE_IDR(sdp_ps);
79static DEFINE_IDR(tcp_ps);
80static DEFINE_IDR(udp_ps);
81static DEFINE_IDR(ipoib_ps);
1/*
2 * Copyright (c) 2005 Voltaire Inc. All rights reserved.
3 * Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved.
4 * Copyright (c) 1999-2005, Mellanox Technologies, Inc. All rights reserved.
5 * Copyright (c) 2005-2006 Intel Corporation. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU

--- 65 unchanged lines hidden (view full) ---

74static LIST_HEAD(dev_list);
75static LIST_HEAD(listen_any_list);
76static DEFINE_MUTEX(lock);
77static struct workqueue_struct *cma_wq;
78static DEFINE_IDR(sdp_ps);
79static DEFINE_IDR(tcp_ps);
80static DEFINE_IDR(udp_ps);
81static DEFINE_IDR(ipoib_ps);
82static int next_port;
83
84struct cma_device {
85 struct list_head list;
86 struct ib_device *device;
87 struct completion comp;
88 atomic_t refcount;
89 struct list_head id_list;
90};

--- 1874 unchanged lines hidden (view full) ---

1965 idr_remove(ps, port);
1966err1:
1967 kfree(bind_list);
1968 return ret;
1969}
1970
1971static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)
1972{
82
83struct cma_device {
84 struct list_head list;
85 struct ib_device *device;
86 struct completion comp;
87 atomic_t refcount;
88 struct list_head id_list;
89};

--- 1874 unchanged lines hidden (view full) ---

1964 idr_remove(ps, port);
1965err1:
1966 kfree(bind_list);
1967 return ret;
1968}
1969
1970static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)
1971{
1973 struct rdma_bind_list *bind_list;
1974 int port, ret, low, high;
1972 static unsigned int last_used_port;
1973 int low, high, remaining;
1974 unsigned int rover;
1975
1975
1976 bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL);
1977 if (!bind_list)
1978 return -ENOMEM;
1979
1980retry:
1981 /* FIXME: add proper port randomization per like inet_csk_get_port */
1982 do {
1983 ret = idr_get_new_above(ps, bind_list, next_port, &port);
1984 } while ((ret == -EAGAIN) && idr_pre_get(ps, GFP_KERNEL));
1985
1986 if (ret)
1987 goto err1;
1988
1989 inet_get_local_port_range(&low, &high);
1976 inet_get_local_port_range(&low, &high);
1990 if (port > high) {
1991 if (next_port != low) {
1992 idr_remove(ps, port);
1993 next_port = low;
1994 goto retry;
1995 }
1996 ret = -EADDRNOTAVAIL;
1997 goto err2;
1977 remaining = (high - low) + 1;
1978 rover = net_random() % remaining + low;
1979retry:
1980 if (last_used_port != rover &&
1981 !idr_find(ps, (unsigned short) rover)) {
1982 int ret = cma_alloc_port(ps, id_priv, rover);
1983 /*
1984 * Remember previously used port number in order to avoid
1985 * re-using same port immediately after it is closed.
1986 */
1987 if (!ret)
1988 last_used_port = rover;
1989 if (ret != -EADDRNOTAVAIL)
1990 return ret;
1998 }
1991 }
1999
2000 if (port == high)
2001 next_port = low;
2002 else
2003 next_port = port + 1;
2004
2005 bind_list->ps = ps;
2006 bind_list->port = (unsigned short) port;
2007 cma_bind_port(bind_list, id_priv);
2008 return 0;
2009err2:
2010 idr_remove(ps, port);
2011err1:
2012 kfree(bind_list);
2013 return ret;
1992 if (--remaining) {
1993 rover++;
1994 if ((rover < low) || (rover > high))
1995 rover = low;
1996 goto retry;
1997 }
1998 return -EADDRNOTAVAIL;
2014}
2015
2016static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv)
2017{
2018 struct rdma_id_private *cur_id;
2019 struct sockaddr_in *sin, *cur_sin;
2020 struct rdma_bind_list *bind_list;
2021 struct hlist_node *node;

--- 968 unchanged lines hidden (view full) ---

2990 mutex_unlock(&lock);
2991
2992 cma_process_remove(cma_dev);
2993 kfree(cma_dev);
2994}
2995
2996static int __init cma_init(void)
2997{
1999}
2000
2001static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv)
2002{
2003 struct rdma_id_private *cur_id;
2004 struct sockaddr_in *sin, *cur_sin;
2005 struct rdma_bind_list *bind_list;
2006 struct hlist_node *node;

--- 968 unchanged lines hidden (view full) ---

2975 mutex_unlock(&lock);
2976
2977 cma_process_remove(cma_dev);
2978 kfree(cma_dev);
2979}
2980
2981static int __init cma_init(void)
2982{
2998 int ret, low, high, remaining;
2983 int ret;
2999
2984
3000 get_random_bytes(&next_port, sizeof next_port);
3001 inet_get_local_port_range(&low, &high);
3002 remaining = (high - low) + 1;
3003 next_port = ((unsigned int) next_port % remaining) + low;
3004
3005 cma_wq = create_singlethread_workqueue("rdma_cm");
3006 if (!cma_wq)
3007 return -ENOMEM;
3008
3009 ib_sa_register_client(&sa_client);
3010 rdma_addr_register_client(&addr_client);
3011 register_netdevice_notifier(&cma_nb);
3012

--- 28 unchanged lines hidden ---
2985 cma_wq = create_singlethread_workqueue("rdma_cm");
2986 if (!cma_wq)
2987 return -ENOMEM;
2988
2989 ib_sa_register_client(&sa_client);
2990 rdma_addr_register_client(&addr_client);
2991 register_netdevice_notifier(&cma_nb);
2992

--- 28 unchanged lines hidden ---