From 8c04ce53f4f75f5e836c9a09cbbef10d2447af5b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 25 Oct 2016 20:50:34 +0000 Subject: [PATCH] ib_srpt: Port to Linux kernel v4.9 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7018 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 14 ++++++++++++++ srpt/src/ib_srpt.c | 10 +++++++++- srpt/src/ib_srpt.h | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 98b21fd60..8bb03ea6c 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -25,6 +25,7 @@ #include /* kmalloc() */ #include /* sync_page_range() */ #include /* struct scsi_cmnd */ +#include /* */ @@ -512,6 +513,19 @@ typedef void (*rcu_callback_t)(struct rcu_head *); __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) #endif +/* */ +/* commit ed082d36 */ +#ifndef ib_alloc_pd +static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) +{ + return ib_alloc_pd(device); +} +#define ib_alloc_pd(device, flags) \ + ({ \ + (void)(flags), ib_alloc_pd_backport(device); \ + }) +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) && \ diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 608395170..f6bae1923 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -4346,18 +4346,22 @@ static void srpt_add_one(struct ib_device *device) sdev->dev_attr = device->attrs; #endif - sdev->pd = ib_alloc_pd(device); + sdev->pd = ib_alloc_pd(device, 0); if (IS_ERR(sdev->pd)) { pr_err("ib_alloc_pd() failed: %ld\n", PTR_ERR(sdev->pd)); goto free_dev; } +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) sdev->mr = ib_get_dma_mr(sdev->pd, IB_ACCESS_LOCAL_WRITE); if (IS_ERR(sdev->mr)) { pr_err("ib_get_dma_mr() failed: %ld\n", PTR_ERR(sdev->mr)); goto err_pd; } sdev->lkey = sdev->mr->lkey; +#else + sdev->lkey = sdev->pd->local_dma_lkey; +#endif sdev->srq_size = min(max(srpt_srq_size, MIN_SRPT_SRQ_SIZE), sdev->dev_attr.max_srq_wr); @@ -4481,8 +4485,10 @@ err_ring: if (sdev->use_srq) ib_destroy_srq(sdev->srq); err_mr: +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) ib_dereg_mr(sdev->mr); err_pd: +#endif ib_dealloc_pd(sdev->pd); free_dev: kfree(sdev); @@ -4554,7 +4560,9 @@ static void srpt_remove_one(struct ib_device *device, void *client_data) if (sdev->use_srq) ib_destroy_srq(sdev->srq); +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) ib_dereg_mr(sdev->mr); +#endif ib_dealloc_pd(sdev->pd); kfree(sdev); diff --git a/srpt/src/ib_srpt.h b/srpt/src/ib_srpt.h index 03c0d5528..b410dd69e 100644 --- a/srpt/src/ib_srpt.h +++ b/srpt/src/ib_srpt.h @@ -457,7 +457,9 @@ struct srpt_port { struct srpt_device { struct ib_device *device; struct ib_pd *pd; +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 9, 0) struct ib_mr *mr; +#endif struct ib_srq *srq; struct ib_cm_id *cm_id; struct ib_device_attr dev_attr;