From owner-svn-src-all@FreeBSD.ORG Wed Oct 15 13:40:38 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E3A27C6D; Wed, 15 Oct 2014 13:40:37 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id CB30592B; Wed, 15 Oct 2014 13:40:37 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9FDebDL049819; Wed, 15 Oct 2014 13:40:37 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9FDeUFQ049767; Wed, 15 Oct 2014 13:40:30 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201410151340.s9FDeUFQ049767@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 15 Oct 2014 13:40:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273135 - in head/sys: contrib/rdma/krping dev/cxgbe/iw_cxgbe ofed/drivers/infiniband/core ofed/drivers/infiniband/hw/mlx4 ofed/drivers/infiniband/hw/mthca ofed/drivers/infiniband/ulp/i... X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Oct 2014 13:40:38 -0000 Author: hselasky Date: Wed Oct 15 13:40:29 2014 New Revision: 273135 URL: https://svnweb.freebsd.org/changeset/base/273135 Log: Update the OFED Linux compatibility layer and Mellanox hardware driver(s): - Properly name an inclusion guard - Fix compile warnings regarding unsigned enums - Add two new sysctl nodes - Remove all empty linux header files - Make an error printout more verbose - Use "mod_delayed_work()" instead of cancelling and starting a timeout. - Implement more Linux scatterlist functions. MFC after: 3 days Sponsored by: Mellanox Technologies Deleted: head/sys/ofed/drivers/net/mlx4/en_frag.c head/sys/ofed/drivers/net/mlx4/en_params.c head/sys/ofed/drivers/net/mlx4/xrcd.c head/sys/ofed/include/asm/page.h head/sys/ofed/include/linux/ethtool.h head/sys/ofed/include/linux/inet.h head/sys/ofed/include/linux/mount.h Modified: head/sys/contrib/rdma/krping/krping.c head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h head/sys/ofed/drivers/infiniband/core/addr.c head/sys/ofed/drivers/infiniband/core/agent.c head/sys/ofed/drivers/infiniband/core/ucm.c head/sys/ofed/drivers/infiniband/core/uverbs_main.c head/sys/ofed/drivers/infiniband/hw/mlx4/ah.c head/sys/ofed/drivers/infiniband/hw/mthca/mthca_config_reg.h head/sys/ofed/drivers/infiniband/hw/mthca/mthca_memfree.c head/sys/ofed/drivers/infiniband/hw/mthca/mthca_uar.c head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_verbs.c head/sys/ofed/drivers/net/mlx4/Makefile head/sys/ofed/drivers/net/mlx4/en_ethtool.c head/sys/ofed/drivers/net/mlx4/en_netdev.c head/sys/ofed/drivers/net/mlx4/en_selftest.c head/sys/ofed/drivers/net/mlx4/en_tx.c head/sys/ofed/drivers/net/mlx4/pd.c head/sys/ofed/include/linux/completion.h head/sys/ofed/include/linux/etherdevice.h head/sys/ofed/include/linux/linux_compat.c head/sys/ofed/include/linux/mlx4/device.h head/sys/ofed/include/linux/mlx4/driver.h head/sys/ofed/include/linux/netdevice.h head/sys/ofed/include/linux/scatterlist.h head/sys/ofed/include/linux/vmalloc.h head/sys/ofed/include/rdma/ib_addr.h head/sys/ofed/include/rdma/ib_smi.h head/sys/ofed/include/rdma/ib_user_cm.h Modified: head/sys/contrib/rdma/krping/krping.c ============================================================================== --- head/sys/contrib/rdma/krping/krping.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/contrib/rdma/krping/krping.c Wed Oct 15 13:40:29 2014 (r273135) @@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include Modified: head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h ============================================================================== --- head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/dev/cxgbe/iw_cxgbe/iw_cxgbe.h Wed Oct 15 13:40:29 2014 (r273135) @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include Modified: head/sys/ofed/drivers/infiniband/core/addr.c ============================================================================== --- head/sys/ofed/drivers/infiniband/core/addr.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/core/addr.c Wed Oct 15 13:40:29 2014 (r273135) @@ -35,10 +35,15 @@ #include #include +#include #include +#include +#include #include #include #include +#include + MODULE_AUTHOR("Sean Hefty"); MODULE_DESCRIPTION("IB Address Translation"); @@ -189,13 +194,11 @@ static void set_timeout(unsigned long ti { unsigned long delay; - cancel_delayed_work(&work); - delay = time - jiffies; if ((long)delay <= 0) delay = 1; - queue_delayed_work(addr_wq, &work, delay); + mod_delayed_work(addr_wq, &work, delay); } static void queue_req(struct addr_req *req) @@ -620,7 +623,7 @@ static struct notifier_block nb = { .notifier_call = netevent_callback }; -static int addr_init(void) +static int __init addr_init(void) { INIT_DELAYED_WORK(&work, process_req); addr_wq = create_singlethread_workqueue("ib_addr"); @@ -631,7 +634,7 @@ static int addr_init(void) return 0; } -static void addr_cleanup(void) +static void __exit addr_cleanup(void) { unregister_netevent_notifier(&nb); destroy_workqueue(addr_wq); Modified: head/sys/ofed/drivers/infiniband/core/agent.c ============================================================================== --- head/sys/ofed/drivers/infiniband/core/agent.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/core/agent.c Wed Oct 15 13:40:29 2014 (r273135) @@ -101,7 +101,8 @@ void agent_send_response(struct ib_mad * agent = port_priv->agent[qpn]; ah = ib_create_ah_from_wc(agent->qp->pd, wc, grh, port_num); if (IS_ERR(ah)) { - printk(KERN_ERR SPFX "ib_create_ah_from_wc error\n"); + printk(KERN_ERR SPFX "ib_create_ah_from_wc error %ld\n", + PTR_ERR(ah)); return; } Modified: head/sys/ofed/drivers/infiniband/core/ucm.c ============================================================================== --- head/sys/ofed/drivers/infiniband/core/ucm.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/core/ucm.c Wed Oct 15 13:40:29 2014 (r273135) @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include Modified: head/sys/ofed/drivers/infiniband/core/uverbs_main.c ============================================================================== --- head/sys/ofed/drivers/infiniband/core/uverbs_main.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/core/uverbs_main.c Wed Oct 15 13:40:29 2014 (r273135) @@ -40,7 +40,6 @@ #include #include #include -#include #include #include Modified: head/sys/ofed/drivers/infiniband/hw/mlx4/ah.c ============================================================================== --- head/sys/ofed/drivers/infiniband/hw/mlx4/ah.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/hw/mlx4/ah.c Wed Oct 15 13:40:29 2014 (r273135) @@ -38,7 +38,6 @@ #include #include -#include #include #include "mlx4_ib.h" Modified: head/sys/ofed/drivers/infiniband/hw/mthca/mthca_config_reg.h ============================================================================== --- head/sys/ofed/drivers/infiniband/hw/mthca/mthca_config_reg.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/hw/mthca/mthca_config_reg.h Wed Oct 15 13:40:29 2014 (r273135) @@ -34,7 +34,7 @@ #ifndef MTHCA_CONFIG_REG_H #define MTHCA_CONFIG_REG_H -#include +#include #define MTHCA_HCR_BASE 0x80680 #define MTHCA_HCR_SIZE 0x0001c Modified: head/sys/ofed/drivers/infiniband/hw/mthca/mthca_memfree.c ============================================================================== --- head/sys/ofed/drivers/infiniband/hw/mthca/mthca_memfree.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/hw/mthca/mthca_memfree.c Wed Oct 15 13:40:29 2014 (r273135) @@ -36,7 +36,7 @@ #include #include -#include +#include #include "mthca_memfree.h" #include "mthca_dev.h" Modified: head/sys/ofed/drivers/infiniband/hw/mthca/mthca_uar.c ============================================================================== --- head/sys/ofed/drivers/infiniband/hw/mthca/mthca_uar.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/hw/mthca/mthca_uar.c Wed Oct 15 13:40:29 2014 (r273135) @@ -30,7 +30,7 @@ * SOFTWARE. */ -#include /* PAGE_SHIFT */ +#include #include "mthca_dev.h" #include "mthca_memfree.h" Modified: head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c ============================================================================== --- head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_ethtool.c Wed Oct 15 13:40:29 2014 (r273135) @@ -31,7 +31,6 @@ */ #include -#include #include #include "ipoib.h" Modified: head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_verbs.c ============================================================================== --- head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_verbs.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/infiniband/ulp/ipoib/ipoib_verbs.c Wed Oct 15 13:40:29 2014 (r273135) @@ -32,7 +32,6 @@ */ #include "ipoib.h" -#include int ipoib_mcast_attach(struct ipoib_dev_priv *priv, u16 mlid, union ib_gid *mgid, int set_qkey) { Modified: head/sys/ofed/drivers/net/mlx4/Makefile ============================================================================== --- head/sys/ofed/drivers/net/mlx4/Makefile Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/net/mlx4/Makefile Wed Oct 15 13:40:29 2014 (r273135) @@ -31,4 +31,3 @@ opt_inet6.h: .include CFLAGS+= -Wno-cast-qual -Wno-pointer-arith ${GCC_MS_EXTENSIONS} - Modified: head/sys/ofed/drivers/net/mlx4/en_ethtool.c ============================================================================== --- head/sys/ofed/drivers/net/mlx4/en_ethtool.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/net/mlx4/en_ethtool.c Wed Oct 15 13:40:29 2014 (r273135) @@ -32,7 +32,6 @@ */ #include -#include #include #include #include Modified: head/sys/ofed/drivers/net/mlx4/en_netdev.c ============================================================================== --- head/sys/ofed/drivers/net/mlx4/en_netdev.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/net/mlx4/en_netdev.c Wed Oct 15 13:40:29 2014 (r273135) @@ -2335,9 +2335,11 @@ static void mlx4_en_sysctl_conf(struct m struct sysctl_oid_list *node_list; struct sysctl_oid *coal; struct sysctl_oid_list *coal_list; + const char *pnameunit; dev = priv->dev; ctx = &priv->conf_ctx; + pnameunit = device_get_nameunit(priv->mdev->pdev->dev.bsddev); sysctl_ctx_init(ctx); priv->sysctl = SYSCTL_ADD_NODE(ctx, SYSCTL_STATIC_CHILDREN(_hw), @@ -2350,10 +2352,10 @@ static void mlx4_en_sysctl_conf(struct m CTLFLAG_RW, &priv->msg_enable, 0, "Driver message enable bitfield"); SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "rx_rings", - CTLTYPE_INT | CTLFLAG_RD, &priv->rx_ring_num, 0, + CTLFLAG_RD, &priv->rx_ring_num, 0, "Number of receive rings"); SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "tx_rings", - CTLTYPE_INT | CTLFLAG_RD, &priv->tx_ring_num, 0, + CTLFLAG_RD, &priv->tx_ring_num, 0, "Number of transmit rings"); SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "rx_size", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, @@ -2367,6 +2369,12 @@ static void mlx4_en_sysctl_conf(struct m SYSCTL_ADD_PROC(ctx, node_list, OID_AUTO, "rx_ppp", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, priv, 0, mlx4_en_set_rx_ppp, "I", "RX Per-priority pause"); + SYSCTL_ADD_UINT(ctx, node_list, OID_AUTO, "port_num", + CTLFLAG_RD, &priv->port, 0, + "Port Number"); + SYSCTL_ADD_STRING(ctx, node_list, OID_AUTO, "device_name", + CTLFLAG_RD, __DECONST(void *, pnameunit), 0, + "PCI device name"); /* Add coalescer configuration. */ coal = SYSCTL_ADD_NODE(ctx, node_list, OID_AUTO, Modified: head/sys/ofed/drivers/net/mlx4/en_selftest.c ============================================================================== --- head/sys/ofed/drivers/net/mlx4/en_selftest.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/net/mlx4/en_selftest.c Wed Oct 15 13:40:29 2014 (r273135) @@ -32,7 +32,6 @@ */ #include -#include #include #include #include Modified: head/sys/ofed/drivers/net/mlx4/en_tx.c ============================================================================== --- head/sys/ofed/drivers/net/mlx4/en_tx.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/net/mlx4/en_tx.c Wed Oct 15 13:40:29 2014 (r273135) @@ -31,7 +31,7 @@ * */ -#include +#include #include #include #include Modified: head/sys/ofed/drivers/net/mlx4/pd.c ============================================================================== --- head/sys/ofed/drivers/net/mlx4/pd.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/drivers/net/mlx4/pd.c Wed Oct 15 13:40:29 2014 (r273135) @@ -35,7 +35,7 @@ #include #include -#include +#include #include "mlx4.h" #include "icm.h" Modified: head/sys/ofed/include/linux/completion.h ============================================================================== --- head/sys/ofed/include/linux/completion.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/completion.h Wed Oct 15 13:40:29 2014 (r273135) @@ -27,8 +27,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _FBSD_COMPLETION_H_ -#define _FBSD_COMPLETION_H_ +#ifndef _LINUX_COMPLETION_H_ +#define _LINUX_COMPLETION_H_ #include Modified: head/sys/ofed/include/linux/etherdevice.h ============================================================================== --- head/sys/ofed/include/linux/etherdevice.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/etherdevice.h Wed Oct 15 13:40:29 2014 (r273135) @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. * Modified: head/sys/ofed/include/linux/linux_compat.c ============================================================================== --- head/sys/ofed/include/linux/linux_compat.c Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/linux_compat.c Wed Oct 15 13:40:29 2014 (r273135) @@ -588,15 +588,15 @@ struct fileops linuxfileops = { .fo_read = linux_file_read, .fo_write = invfo_rdwr, .fo_truncate = invfo_truncate, - .fo_ioctl = linux_file_ioctl, - .fo_poll = linux_file_poll, .fo_kqfilter = invfo_kqfilter, .fo_stat = linux_file_stat, + .fo_fill_kinfo = linux_file_fill_kinfo, + .fo_poll = linux_file_poll, .fo_close = linux_file_close, + .fo_ioctl = linux_file_ioctl, .fo_chmod = invfo_chmod, .fo_chown = invfo_chown, .fo_sendfile = invfo_sendfile, - .fo_fill_kinfo = linux_file_fill_kinfo, }; /* Modified: head/sys/ofed/include/linux/mlx4/device.h ============================================================================== --- head/sys/ofed/include/linux/mlx4/device.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/mlx4/device.h Wed Oct 15 13:40:29 2014 (r273135) @@ -1036,6 +1036,7 @@ enum mlx4_net_trans_rule_id { MLX4_NET_TRANS_RULE_ID_TCP, MLX4_NET_TRANS_RULE_ID_UDP, MLX4_NET_TRANS_RULE_NUM, /* should be last */ + MLX4_NET_TRANS_RULE_DUMMY = -1, /* force enum to be signed */ }; extern const u16 __sw_id_hw[]; @@ -1058,6 +1059,7 @@ enum mlx4_net_trans_promisc_mode { MLX4_FS_UC_SNIFFER, MLX4_FS_MC_SNIFFER, MLX4_FS_MODE_NUM, /* should be last */ + MLX4_FS_MODE_DUMMY = -1, /* force enum to be signed */ }; struct mlx4_spec_eth { Modified: head/sys/ofed/include/linux/mlx4/driver.h ============================================================================== --- head/sys/ofed/include/linux/mlx4/driver.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/mlx4/driver.h Wed Oct 15 13:40:29 2014 (r273135) @@ -121,7 +121,7 @@ void *mlx4_get_protocol_dev(struct mlx4_ #ifndef ETH_ALEN #define ETH_ALEN 6 #endif -static inline u64 mlx4_mac_to_u64(u8 *addr) +static inline u64 mlx4_mac_to_u64(const u8 *addr) { u64 mac = 0; int i; Modified: head/sys/ofed/include/linux/netdevice.h ============================================================================== --- head/sys/ofed/include/linux/netdevice.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/netdevice.h Wed Oct 15 13:40:29 2014 (r273135) @@ -40,7 +40,6 @@ #include #include -#include #include #include #include Modified: head/sys/ofed/include/linux/scatterlist.h ============================================================================== --- head/sys/ofed/include/linux/scatterlist.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/scatterlist.h Wed Oct 15 13:40:29 2014 (r273135) @@ -31,6 +31,21 @@ #define _LINUX_SCATTERLIST_H_ #include +#include + +/* + * SG table design. + * + * If flags bit 0 is set, then the sg field contains a pointer to the next sg + * table list. Otherwise the next entry is at sg + 1, can be determined using + * the sg_is_chain() function. + * + * If flags bit 1 is set, then this sg entry is the last element in a list, + * can be determined using the sg_is_last() function. + * + * See sg_next(). + * + */ struct scatterlist { union { @@ -49,6 +64,12 @@ struct sg_table { unsigned int orig_nents; /* original size of list */ }; +/* + * Maximum number of entries that will be allocated in one piece, if + * a list larger than this is required then chaining will be utilized. + */ +#define SG_MAX_SINGLE_ALLOC (PAGE_SIZE / sizeof(struct scatterlist)) + #define sg_dma_address(sg) (sg)->address #define sg_dma_len(sg) (sg)->length #define sg_page(sg) (sg)->sl_un.page @@ -99,6 +120,212 @@ sg_phys(struct scatterlist *sg) return sg_page(sg)->phys_addr + sg->offset; } +/** + * sg_chain - Chain two sglists together + * @prv: First scatterlist + * @prv_nents: Number of entries in prv + * @sgl: Second scatterlist + * + * Description: + * Links @prv@ and @sgl@ together, to form a longer scatterlist. + * + **/ +static inline void +sg_chain(struct scatterlist *prv, unsigned int prv_nents, + struct scatterlist *sgl) +{ +/* + * offset and length are unused for chain entry. Clear them. + */ + struct scatterlist *sg = &prv[prv_nents - 1]; + + sg->offset = 0; + sg->length = 0; + + /* + * Indicate a link pointer, and set the link to the second list. + */ + sg->flags = SG_CHAIN; + sg->sl_un.sg = sgl; +} + +/** + * sg_mark_end - Mark the end of the scatterlist + * @sg: SG entryScatterlist + * + * Description: + * Marks the passed in sg entry as the termination point for the sg + * table. A call to sg_next() on this entry will return NULL. + * + **/ +static inline void sg_mark_end(struct scatterlist *sg) +{ + sg->flags = SG_END; +} + +/** + * __sg_free_table - Free a previously mapped sg table + * @table: The sg table header to use + * @max_ents: The maximum number of entries per single scatterlist + * + * Description: + * Free an sg table previously allocated and setup with + * __sg_alloc_table(). The @max_ents value must be identical to + * that previously used with __sg_alloc_table(). + * + **/ +static inline void +__sg_free_table(struct sg_table *table, unsigned int max_ents) +{ + struct scatterlist *sgl, *next; + + if (unlikely(!table->sgl)) + return; + + sgl = table->sgl; + while (table->orig_nents) { + unsigned int alloc_size = table->orig_nents; + unsigned int sg_size; + + /* + * If we have more than max_ents segments left, + * then assign 'next' to the sg table after the current one. + * sg_size is then one less than alloc size, since the last + * element is the chain pointer. + */ + if (alloc_size > max_ents) { + next = sgl[max_ents - 1].sl_un.sg; + alloc_size = max_ents; + sg_size = alloc_size - 1; + } else { + sg_size = alloc_size; + next = NULL; + } + + table->orig_nents -= sg_size; + kfree(sgl); + sgl = next; + } + + table->sgl = NULL; +} + +/** + * sg_free_table - Free a previously allocated sg table + * @table: The mapped sg table header + * + **/ +static inline void +sg_free_table(struct sg_table *table) +{ + __sg_free_table(table, SG_MAX_SINGLE_ALLOC); +} + +/** + * __sg_alloc_table - Allocate and initialize an sg table with given allocator + * @table: The sg table header to use + * @nents: Number of entries in sg list + * @max_ents: The maximum number of entries the allocator returns per call + * @gfp_mask: GFP allocation mask + * + * Description: + * This function returns a @table @nents long. The allocator is + * defined to return scatterlist chunks of maximum size @max_ents. + * Thus if @nents is bigger than @max_ents, the scatterlists will be + * chained in units of @max_ents. + * + * Notes: + * If this function returns non-0 (eg failure), the caller must call + * __sg_free_table() to cleanup any leftover allocations. + * + **/ +static inline int +__sg_alloc_table(struct sg_table *table, unsigned int nents, + unsigned int max_ents, gfp_t gfp_mask) +{ + struct scatterlist *sg, *prv; + unsigned int left; + + memset(table, 0, sizeof(*table)); + + if (nents == 0) + return -EINVAL; + left = nents; + prv = NULL; + do { + unsigned int sg_size, alloc_size = left; + + if (alloc_size > max_ents) { + alloc_size = max_ents; + sg_size = alloc_size - 1; + } else + sg_size = alloc_size; + + left -= sg_size; + + sg = kmalloc(alloc_size * sizeof(struct scatterlist), gfp_mask); + if (unlikely(!sg)) { + /* + * Adjust entry count to reflect that the last + * entry of the previous table won't be used for + * linkage. Without this, sg_kfree() may get + * confused. + */ + if (prv) + table->nents = ++table->orig_nents; + + return -ENOMEM; + } + + sg_init_table(sg, alloc_size); + table->nents = table->orig_nents += sg_size; + + /* + * If this is the first mapping, assign the sg table header. + * If this is not the first mapping, chain previous part. + */ + if (prv) + sg_chain(prv, max_ents, sg); + else + table->sgl = sg; + + /* + * If no more entries after this one, mark the end + */ + if (!left) + sg_mark_end(&sg[sg_size - 1]); + + prv = sg; + } while (left); + + return 0; +} + +/** + * sg_alloc_table - Allocate and initialize an sg table + * @table: The sg table header to use + * @nents: Number of entries in sg list + * @gfp_mask: GFP allocation mask + * + * Description: + * Allocate and initialize an sg table. If @nents@ is larger than + * SG_MAX_SINGLE_ALLOC a chained sg table will be setup. + * + **/ + +static inline int +sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask) +{ + int ret; + + ret = __sg_alloc_table(table, nents, SG_MAX_SINGLE_ALLOC, + gfp_mask); + if (unlikely(ret)) + __sg_free_table(table, SG_MAX_SINGLE_ALLOC); + + return ret; +} + #define for_each_sg(sglist, sg, sgmax, _itr) \ for (_itr = 0, sg = (sglist); _itr < (sgmax); _itr++, sg = sg_next(sg)) Modified: head/sys/ofed/include/linux/vmalloc.h ============================================================================== --- head/sys/ofed/include/linux/vmalloc.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/linux/vmalloc.h Wed Oct 15 13:40:29 2014 (r273135) @@ -30,7 +30,7 @@ #ifndef _LINUX_VMALLOC_H_ #define _LINUX_VMALLOC_H_ -#include +#include #define VM_MAP 0x0000 #define PAGE_KERNEL 0x0000 Modified: head/sys/ofed/include/rdma/ib_addr.h ============================================================================== --- head/sys/ofed/include/rdma/ib_addr.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/rdma/ib_addr.h Wed Oct 15 13:40:29 2014 (r273135) @@ -41,7 +41,6 @@ #include #include #include -#include #include struct rdma_addr_client { Modified: head/sys/ofed/include/rdma/ib_smi.h ============================================================================== --- head/sys/ofed/include/rdma/ib_smi.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/rdma/ib_smi.h Wed Oct 15 13:40:29 2014 (r273135) @@ -38,6 +38,7 @@ #define IB_SMI_H #include +#include #define IB_SMP_DATA_SIZE 64 #define IB_SMP_MAX_PATH_HOPS 64 Modified: head/sys/ofed/include/rdma/ib_user_cm.h ============================================================================== --- head/sys/ofed/include/rdma/ib_user_cm.h Wed Oct 15 13:39:00 2014 (r273134) +++ head/sys/ofed/include/rdma/ib_user_cm.h Wed Oct 15 13:40:29 2014 (r273135) @@ -34,6 +34,7 @@ #ifndef IB_USER_CM_H #define IB_USER_CM_H +#include #include #define IB_USER_CM_ABI_VERSION 5