2015-07-31 03:17:43 +08:00
/*
IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support
Currently the driver doesn't support completion vectors. These
are used to indicate which sets of CQs should be grouped together
into the same vector. A vector is a CQ processing thread that
runs on a specific CPU.
If an application has several CQs bound to different completion
vectors, and each completion vector runs on different CPUs, then
the completion queue workload is balanced. This helps scale as more
nodes are used.
Implement CQ completion vector support using a global workqueue
where a CQ entry is queued to the CPU corresponding to the CQ's
completion vector. Since the workqueue is global, it's guaranteed
to always be there when queueing CQ entries; Therefore, the RCU
locking for cq->rdi->worker in the hot path is superfluous.
Each completion vector is assigned to a different CPU. The number of
completion vectors available is computed by taking the number of
online, physical CPUs from the local NUMA node and subtracting the
CPUs used for kernel receive queues and the general interrupt.
Special use cases:
* If there are no CPUs left for completion vectors, the same CPU
for the general interrupt is used; Therefore, there would only
be one completion vector available.
* For multi-HFI systems, the number of completion vectors available
for each device is the total number of completion vectors in
the local NUMA node divided by the number of devices in the same
NUMA node. If there's a division remainder, the first device to
get initialized gets an extra completion vector.
Upon a CQ creation, an invalid completion vector could be specified.
Handle it as follows:
* If the completion vector is less than 0, set it to 0.
* Set the completion vector to the result of the passed completion
vector moded with the number of device completion vectors
available.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Sebastian Sanchez <sebastian.sanchez@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2018-05-02 21:43:55 +08:00
* Copyright ( c ) 2015 - 2018 Intel Corporation .
2015-07-31 03:17:43 +08:00
*
* This file is provided under a dual BSD / GPLv2 license . When using or
* redistributing this file , you may do so under either license .
*
* GPL LICENSE SUMMARY
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but
* WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* General Public License for more details .
*
* BSD LICENSE
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
*
* - Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* - Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in
* the documentation and / or other materials provided with the
* distribution .
* - Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL ,
* SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT
* LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
* ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
*
*/
# include <linux/pci.h>
# include <linux/netdevice.h>
# include <linux/vmalloc.h>
# include <linux/delay.h>
2019-02-09 04:41:29 +08:00
# include <linux/xarray.h>
2015-07-31 03:17:43 +08:00
# include <linux/module.h>
# include <linux/printk.h>
# include <linux/hrtimer.h>
2017-05-04 20:15:15 +08:00
# include <linux/bitmap.h>
2019-03-06 07:42:58 +08:00
# include <linux/numa.h>
2016-01-20 06:41:33 +08:00
# include <rdma/rdma_vt.h>
2015-07-31 03:17:43 +08:00
# include "hfi.h"
# include "device.h"
# include "common.h"
2015-11-07 09:06:56 +08:00
# include "trace.h"
2015-07-31 03:17:43 +08:00
# include "mad.h"
# include "sdma.h"
# include "debugfs.h"
# include "verbs.h"
staging/rdma/hfi1: Add support for enabling/disabling PCIe ASPM
hfi1 HW has a high PCIe ASPM L1 exit latency and also advertises an
acceptable latency less than actual ASPM latencies. Additional
mechanisms than those provided by BIOS/OS are therefore required to
enable/disable ASPM for hfi1 to provide acceptable power/performance
trade offs. This patch adds this support.
By means of a module parameter ASPM can be either (a) always enabled
(power save mode) (b) always disabled (performance mode) (c)
enabled/disabled dynamically. The dynamic mode implements two
heuristics to alleviate possible problems with high ASPM L1 exit
latency. ASPM is normally enabled but is disabled if (a) there are any
active user space PSM contexts, or (b) for verbs, ASPM is disabled as
interrupt activity for a context starts to increase.
A few more points about the verbs implementation. In order to reduce
lock/cache contention between multiple verbs contexts, some processing
is done at the context layer before contending for device layer
locks. ASPM is disabled when two interrupts for a context happen
within 1 millisec. A timer is scheduled which will re-enable ASPM
after 1 second should the interrupt activity cease. Normally, every
interrupt, or interrupt-pair should push the timer out
further. However, since this might increase the processing load per
interrupt, pushing the timer out is postponed for half a second. If
after half a second we get two interrupts within 1 millisec the timer
is pushed out by another second.
Finally, the kernel ASPM API is not used in this patch. This is
because this patch does several non-standard things as SW workarounds
for HW issues. As mentioned above, it enables ASPM even when advertised
actual latencies are greater than acceptable latencies. Also, whereas
the kernel API only allows drivers to disable ASPM from driver probe,
this patch enables/disables ASPM directly from interrupt context. Due
to these reasons the kernel ASPM API was not used.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Reviewed-by: Dean Luick <dean.luick@intel.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2016-02-04 06:33:06 +08:00
# include "aspm.h"
2016-07-25 22:52:36 +08:00
# include "affinity.h"
2017-04-13 11:29:28 +08:00
# include "vnic.h"
2017-06-10 07:00:12 +08:00
# include "exp_rcv.h"
2015-07-31 03:17:43 +08:00
# undef pr_fmt
# define pr_fmt(fmt) DRIVER_NAME ": " fmt
/*
* min buffers we want to have per context , after driver
*/
# define HFI1_MIN_USER_CTXT_BUFCNT 7
# define HFI1_MIN_HDRQ_EGRBUF_CNT 2
2016-02-04 06:34:32 +08:00
# define HFI1_MAX_HDRQ_EGRBUF_CNT 16352
2015-07-31 03:17:43 +08:00
# define HFI1_MIN_EAGER_BUFFER_SIZE (4 * 1024) /* 4KB */
# define HFI1_MAX_EAGER_BUFFER_SIZE (256 * 1024) /* 256KB */
2018-08-16 14:03:46 +08:00
# define NUM_IB_PORTS 1
2015-07-31 03:17:43 +08:00
/*
* Number of user receive contexts we are configured to use ( to allow for more
* pio buffers per ctxt , etc . ) Zero means use one user context per CPU .
*/
2015-12-11 21:44:48 +08:00
int num_user_contexts = - 1 ;
2018-05-01 20:35:43 +08:00
module_param_named ( num_user_contexts , num_user_contexts , int , 0444 ) ;
2015-07-31 03:17:43 +08:00
MODULE_PARM_DESC (
2018-05-01 20:35:43 +08:00
num_user_contexts , " Set max number of user contexts to use (default: -1 will use the real (non-HT) CPU count) " ) ;
2015-07-31 03:17:43 +08:00
2016-01-12 07:30:54 +08:00
uint krcvqs [ RXE_NUM_DATA_VL ] ;
2015-07-31 03:17:43 +08:00
int krcvqsset ;
2016-01-12 07:30:54 +08:00
module_param_array ( krcvqs , uint , & krcvqsset , S_IRUGO ) ;
2015-11-11 13:35:19 +08:00
MODULE_PARM_DESC ( krcvqs , " Array of the number of non-control kernel receive queues by VL " ) ;
2015-07-31 03:17:43 +08:00
/* computed based on above array */
2016-08-31 22:24:40 +08:00
unsigned long n_krcvqs ;
2015-07-31 03:17:43 +08:00
static unsigned hfi1_rcvarr_split = 25 ;
module_param_named ( rcvarr_split , hfi1_rcvarr_split , uint , S_IRUGO ) ;
MODULE_PARM_DESC ( rcvarr_split , " Percent of context's RcvArray entries used for Eager buffers " ) ;
2017-05-04 20:14:22 +08:00
static uint eager_buffer_size = ( 8 < < 20 ) ; /* 8MB */
2015-07-31 03:17:43 +08:00
module_param ( eager_buffer_size , uint , S_IRUGO ) ;
2017-05-04 20:14:22 +08:00
MODULE_PARM_DESC ( eager_buffer_size , " Size of the eager buffers, default: 8MB " ) ;
2015-07-31 03:17:43 +08:00
static uint rcvhdrcnt = 2048 ; /* 2x the max eager buffer count */
module_param_named ( rcvhdrcnt , rcvhdrcnt , uint , S_IRUGO ) ;
MODULE_PARM_DESC ( rcvhdrcnt , " Receive header queue count (default 2048) " ) ;
static uint hfi1_hdrq_entsize = 32 ;
2018-06-05 02:44:11 +08:00
module_param_named ( hdrq_entsize , hfi1_hdrq_entsize , uint , 0444 ) ;
MODULE_PARM_DESC ( hdrq_entsize , " Size of header queue entries: 2 - 8B, 16 - 64B, 32 - 128B (default) " ) ;
2015-07-31 03:17:43 +08:00
unsigned int user_credit_return_threshold = 33 ; /* default is 33% */
module_param ( user_credit_return_threshold , uint , S_IRUGO ) ;
2015-12-18 08:24:14 +08:00
MODULE_PARM_DESC ( user_credit_return_threshold , " Credit return threshold for user send contexts, return when unreturned credits passes this many blocks (in percent of allocated blocks, 0 is off) " ) ;
2015-07-31 03:17:43 +08:00
2017-05-04 20:14:39 +08:00
static inline u64 encode_rcv_header_entry_size ( u16 size ) ;
2015-07-31 03:17:43 +08:00
2019-02-09 04:41:29 +08:00
DEFINE_XARRAY_FLAGS ( hfi1_dev_table , XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ ) ;
2015-07-31 03:17:43 +08:00
2017-08-05 04:52:38 +08:00
static int hfi1_create_kctxt ( struct hfi1_devdata * dd ,
struct hfi1_pportdata * ppd )
2015-07-31 03:17:43 +08:00
{
2017-08-05 04:52:38 +08:00
struct hfi1_ctxtdata * rcd ;
2015-07-31 03:17:43 +08:00
int ret ;
2015-11-11 13:35:19 +08:00
/* Control context has to be always 0 */
BUILD_BUG_ON ( HFI1_CTRL_CTXT ! = 0 ) ;
2017-08-05 04:52:38 +08:00
ret = hfi1_create_ctxtdata ( ppd , dd - > node , & rcd ) ;
if ( ret < 0 ) {
dd_dev_err ( dd , " Kernel receive context allocation failed \n " ) ;
return ret ;
}
/*
* Set up the kernel context flags here and now because they use
* default values for all receive side memories . User contexts will
* be handled as they are created .
*/
rcd - > flags = HFI1_CAP_KGET ( MULTI_PKT_EGR ) |
HFI1_CAP_KGET ( NODROP_RHQ_FULL ) |
HFI1_CAP_KGET ( NODROP_EGR_FULL ) |
HFI1_CAP_KGET ( DMA_RTAIL ) ;
/* Control context must use DMA_RTAIL */
if ( rcd - > ctxt = = HFI1_CTRL_CTXT )
rcd - > flags | = HFI1_CAP_DMA_RTAIL ;
rcd - > seq_cnt = 1 ;
rcd - > sc = sc_alloc ( dd , SC_ACK , rcd - > rcvhdrqentsize , dd - > node ) ;
if ( ! rcd - > sc ) {
dd_dev_err ( dd , " Kernel send context allocation failed \n " ) ;
return - ENOMEM ;
}
hfi1_init_ctxt ( rcd - > sc ) ;
return 0 ;
}
/*
* Create the receive context array and one or more kernel contexts
*/
int hfi1_create_kctxts ( struct hfi1_devdata * dd )
{
u16 i ;
int ret ;
2018-02-02 04:37:30 +08:00
dd - > rcd = kcalloc_node ( dd - > num_rcv_contexts , sizeof ( * dd - > rcd ) ,
2016-02-04 06:33:58 +08:00
GFP_KERNEL , dd - > node ) ;
2015-10-13 05:28:36 +08:00
if ( ! dd - > rcd )
2017-08-05 04:52:38 +08:00
return - ENOMEM ;
2015-07-31 03:17:43 +08:00
2017-04-13 11:29:29 +08:00
for ( i = 0 ; i < dd - > first_dyn_alloc_ctxt ; + + i ) {
2017-08-05 04:52:38 +08:00
ret = hfi1_create_kctxt ( dd , dd - > pport ) ;
if ( ret )
goto bail ;
2015-07-31 03:17:43 +08:00
}
return 0 ;
2017-08-05 04:52:38 +08:00
bail :
2017-06-10 07:00:19 +08:00
for ( i = 0 ; dd - > rcd & & i < dd - > first_dyn_alloc_ctxt ; + + i )
2017-08-05 04:52:44 +08:00
hfi1_free_ctxt ( dd - > rcd [ i ] ) ;
2017-06-10 07:00:19 +08:00
/* All the contexts should be freed, free the array */
2015-07-31 03:17:43 +08:00
kfree ( dd - > rcd ) ;
dd - > rcd = NULL ;
return ret ;
}
2017-06-10 07:00:19 +08:00
/*
2017-08-05 04:52:44 +08:00
* Helper routines for the receive context reference count ( rcd and uctxt ) .
2017-06-10 07:00:19 +08:00
*/
static void hfi1_rcd_init ( struct hfi1_ctxtdata * rcd )
{
kref_init ( & rcd - > kref ) ;
}
2017-08-05 04:52:38 +08:00
/**
* hfi1_rcd_free - When reference is zero clean up .
* @ kref : pointer to an initialized rcd data structure
*
*/
2017-06-10 07:00:19 +08:00
static void hfi1_rcd_free ( struct kref * kref )
{
2017-08-05 04:52:44 +08:00
unsigned long flags ;
2017-06-10 07:00:19 +08:00
struct hfi1_ctxtdata * rcd =
container_of ( kref , struct hfi1_ctxtdata , kref ) ;
2017-08-05 04:52:44 +08:00
spin_lock_irqsave ( & rcd - > dd - > uctxt_lock , flags ) ;
rcd - > dd - > rcd [ rcd - > ctxt ] = NULL ;
spin_unlock_irqrestore ( & rcd - > dd - > uctxt_lock , flags ) ;
2019-02-27 00:45:35 +08:00
hfi1_free_ctxtdata ( rcd - > dd , rcd ) ;
2017-06-10 07:00:19 +08:00
kfree ( rcd ) ;
}
2017-08-05 04:52:38 +08:00
/**
* hfi1_rcd_put - decrement reference for rcd
* @ rcd : pointer to an initialized rcd data structure
*
* Use this to put a reference after the init .
*/
2017-06-10 07:00:19 +08:00
int hfi1_rcd_put ( struct hfi1_ctxtdata * rcd )
{
if ( rcd )
return kref_put ( & rcd - > kref , hfi1_rcd_free ) ;
return 0 ;
}
2017-08-05 04:52:38 +08:00
/**
* hfi1_rcd_get - increment reference for rcd
* @ rcd : pointer to an initialized rcd data structure
*
* Use this to get a reference after the init .
2019-02-27 00:45:35 +08:00
*
* Return : reflect kref_get_unless_zero ( ) , which returns non - zero on
* increment , otherwise 0.
2017-08-05 04:52:38 +08:00
*/
2019-02-27 00:45:35 +08:00
int hfi1_rcd_get ( struct hfi1_ctxtdata * rcd )
2017-06-10 07:00:19 +08:00
{
2019-02-27 00:45:35 +08:00
return kref_get_unless_zero ( & rcd - > kref ) ;
2017-06-10 07:00:19 +08:00
}
2017-08-05 04:52:38 +08:00
/**
* allocate_rcd_index - allocate an rcd index from the rcd array
* @ dd : pointer to a valid devdata structure
* @ rcd : rcd data structure to assign
* @ index : pointer to index that is allocated
*
* Find an empty index in the rcd array , and assign the given rcd to it .
* If the array is full , we are EBUSY .
*
*/
2017-08-05 04:52:44 +08:00
static int allocate_rcd_index ( struct hfi1_devdata * dd ,
2017-08-05 04:52:38 +08:00
struct hfi1_ctxtdata * rcd , u16 * index )
{
unsigned long flags ;
u16 ctxt ;
spin_lock_irqsave ( & dd - > uctxt_lock , flags ) ;
for ( ctxt = 0 ; ctxt < dd - > num_rcv_contexts ; ctxt + + )
if ( ! dd - > rcd [ ctxt ] )
break ;
if ( ctxt < dd - > num_rcv_contexts ) {
rcd - > ctxt = ctxt ;
dd - > rcd [ ctxt ] = rcd ;
hfi1_rcd_init ( rcd ) ;
}
spin_unlock_irqrestore ( & dd - > uctxt_lock , flags ) ;
if ( ctxt > = dd - > num_rcv_contexts )
return - EBUSY ;
* index = ctxt ;
return 0 ;
}
2017-09-26 22:01:16 +08:00
/**
* hfi1_rcd_get_by_index_safe - validate the ctxt index before accessing the
* array
* @ dd : pointer to a valid devdata structure
* @ ctxt : the index of an possilbe rcd
*
* This is a wrapper for hfi1_rcd_get_by_index ( ) to validate that the given
* ctxt index is valid .
*
* The caller is responsible for making the _put ( ) .
*
*/
struct hfi1_ctxtdata * hfi1_rcd_get_by_index_safe ( struct hfi1_devdata * dd ,
u16 ctxt )
{
if ( ctxt < dd - > num_rcv_contexts )
return hfi1_rcd_get_by_index ( dd , ctxt ) ;
return NULL ;
}
2017-08-05 04:52:44 +08:00
/**
* hfi1_rcd_get_by_index
* @ dd : pointer to a valid devdata structure
* @ ctxt : the index of an possilbe rcd
*
* We need to protect access to the rcd array . If access is needed to
* one or more index , get the protecting spinlock and then increment the
* kref .
*
* The caller is responsible for making the _put ( ) .
*
*/
struct hfi1_ctxtdata * hfi1_rcd_get_by_index ( struct hfi1_devdata * dd , u16 ctxt )
{
unsigned long flags ;
struct hfi1_ctxtdata * rcd = NULL ;
spin_lock_irqsave ( & dd - > uctxt_lock , flags ) ;
if ( dd - > rcd [ ctxt ] ) {
rcd = dd - > rcd [ ctxt ] ;
2019-02-27 00:45:35 +08:00
if ( ! hfi1_rcd_get ( rcd ) )
rcd = NULL ;
2017-08-05 04:52:44 +08:00
}
spin_unlock_irqrestore ( & dd - > uctxt_lock , flags ) ;
return rcd ;
}
2015-07-31 03:17:43 +08:00
/*
2017-08-05 04:52:44 +08:00
* Common code for user and kernel context create and setup .
* NOTE : the initial kref is done here ( hf1_rcd_init ( ) ) .
2015-07-31 03:17:43 +08:00
*/
2017-08-05 04:52:38 +08:00
int hfi1_create_ctxtdata ( struct hfi1_pportdata * ppd , int numa ,
struct hfi1_ctxtdata * * context )
2015-07-31 03:17:43 +08:00
{
struct hfi1_devdata * dd = ppd - > dd ;
struct hfi1_ctxtdata * rcd ;
unsigned kctxt_ngroups = 0 ;
u32 base ;
if ( dd - > rcv_entries . nctxt_extra >
2017-04-13 11:29:29 +08:00
dd - > num_rcv_contexts - dd - > first_dyn_alloc_ctxt )
2015-07-31 03:17:43 +08:00
kctxt_ngroups = ( dd - > rcv_entries . nctxt_extra -
2017-04-13 11:29:29 +08:00
( dd - > num_rcv_contexts - dd - > first_dyn_alloc_ctxt ) ) ;
2016-10-17 19:19:41 +08:00
rcd = kzalloc_node ( sizeof ( * rcd ) , GFP_KERNEL , numa ) ;
2015-07-31 03:17:43 +08:00
if ( rcd ) {
u32 rcvtids , max_entries ;
2017-08-05 04:52:38 +08:00
u16 ctxt ;
int ret ;
2015-07-31 03:17:43 +08:00
2017-08-05 04:52:38 +08:00
ret = allocate_rcd_index ( dd , rcd , & ctxt ) ;
if ( ret ) {
* context = NULL ;
kfree ( rcd ) ;
return ret ;
}
2015-07-31 03:17:43 +08:00
INIT_LIST_HEAD ( & rcd - > qp_wait_list ) ;
2018-05-16 09:31:09 +08:00
hfi1_exp_tid_group_init ( rcd ) ;
2015-07-31 03:17:43 +08:00
rcd - > ppd = ppd ;
rcd - > dd = dd ;
2016-02-04 06:33:40 +08:00
rcd - > numa_id = numa ;
2015-07-31 03:17:43 +08:00
rcd - > rcv_array_groups = dd - > rcv_entries . ngroups ;
2018-06-05 02:43:29 +08:00
rcd - > rhf_rcv_function_map = normal_rhf_rcv_functions ;
2015-07-31 03:17:43 +08:00
2018-06-05 02:43:54 +08:00
mutex_init ( & rcd - > exp_mutex ) ;
2019-02-06 06:13:13 +08:00
spin_lock_init ( & rcd - > exp_lock ) ;
INIT_LIST_HEAD ( & rcd - > flow_queue . queue_head ) ;
2019-01-24 11:30:07 +08:00
INIT_LIST_HEAD ( & rcd - > rarr_queue . queue_head ) ;
2015-07-31 03:17:43 +08:00
2017-08-05 04:52:44 +08:00
hfi1_cdbg ( PROC , " setting up context %u \n " , rcd - > ctxt ) ;
2015-07-31 03:17:43 +08:00
/*
* Calculate the context ' s RcvArray entry starting point .
* We do this here because we have to take into account all
* the RcvArray entries that previous context would have
2017-04-13 11:29:29 +08:00
* taken and we have to account for any extra groups assigned
* to the static ( kernel ) or dynamic ( vnic / user ) contexts .
2015-07-31 03:17:43 +08:00
*/
2017-04-13 11:29:29 +08:00
if ( ctxt < dd - > first_dyn_alloc_ctxt ) {
2015-07-31 03:17:43 +08:00
if ( ctxt < kctxt_ngroups ) {
base = ctxt * ( dd - > rcv_entries . ngroups + 1 ) ;
rcd - > rcv_array_groups + + ;
2017-04-10 01:17:18 +08:00
} else {
2015-07-31 03:17:43 +08:00
base = kctxt_ngroups +
( ctxt * dd - > rcv_entries . ngroups ) ;
2017-04-10 01:17:18 +08:00
}
2015-07-31 03:17:43 +08:00
} else {
2017-04-13 11:29:29 +08:00
u16 ct = ctxt - dd - > first_dyn_alloc_ctxt ;
2015-07-31 03:17:43 +08:00
base = ( ( dd - > n_krcv_queues * dd - > rcv_entries . ngroups ) +
kctxt_ngroups ) ;
if ( ct < dd - > rcv_entries . nctxt_extra ) {
base + = ct * ( dd - > rcv_entries . ngroups + 1 ) ;
rcd - > rcv_array_groups + + ;
2017-04-10 01:17:18 +08:00
} else {
2015-07-31 03:17:43 +08:00
base + = dd - > rcv_entries . nctxt_extra +
( ct * dd - > rcv_entries . ngroups ) ;
2017-04-10 01:17:18 +08:00
}
2015-07-31 03:17:43 +08:00
}
rcd - > eager_base = base * dd - > rcv_entries . group_size ;
rcd - > rcvhdrq_cnt = rcvhdrcnt ;
rcd - > rcvhdrqentsize = hfi1_hdrq_entsize ;
2018-06-05 02:43:37 +08:00
rcd - > rhf_offset =
rcd - > rcvhdrqentsize - sizeof ( u64 ) / sizeof ( u32 ) ;
2015-07-31 03:17:43 +08:00
/*
* Simple Eager buffer allocation : we have already pre - allocated
* the number of RcvArray entry groups . Each ctxtdata structure
* holds the number of groups for that context .
*
* To follow CSR requirements and maintain cacheline alignment ,
* make sure all sizes and bases are multiples of group_size .
*
* The expected entry count is what is left after assigning
* eager .
*/
max_entries = rcd - > rcv_array_groups *
dd - > rcv_entries . group_size ;
rcvtids = ( ( max_entries * hfi1_rcvarr_split ) / 100 ) ;
rcd - > egrbufs . count = round_down ( rcvtids ,
dd - > rcv_entries . group_size ) ;
if ( rcd - > egrbufs . count > MAX_EAGER_ENTRIES ) {
dd_dev_err ( dd , " ctxt%u: requested too many RcvArray entries. \n " ,
rcd - > ctxt ) ;
rcd - > egrbufs . count = MAX_EAGER_ENTRIES ;
}
2015-11-07 09:06:56 +08:00
hfi1_cdbg ( PROC ,
" ctxt%u: max Eager buffer RcvArray entries: %u \n " ,
rcd - > ctxt , rcd - > egrbufs . count ) ;
2015-07-31 03:17:43 +08:00
/*
* Allocate array that will hold the eager buffer accounting
* data .
* This will allocate the maximum possible buffer count based
* on the value of the RcvArray split parameter .
* The resulting value will be rounded down to the closest
* multiple of dd - > rcv_entries . group_size .
*/
2018-02-02 04:37:30 +08:00
rcd - > egrbufs . buffers =
kcalloc_node ( rcd - > egrbufs . count ,
sizeof ( * rcd - > egrbufs . buffers ) ,
GFP_KERNEL , numa ) ;
2015-07-31 03:17:43 +08:00
if ( ! rcd - > egrbufs . buffers )
goto bail ;
2018-02-02 04:37:30 +08:00
rcd - > egrbufs . rcvtids =
kcalloc_node ( rcd - > egrbufs . count ,
sizeof ( * rcd - > egrbufs . rcvtids ) ,
GFP_KERNEL , numa ) ;
2015-07-31 03:17:43 +08:00
if ( ! rcd - > egrbufs . rcvtids )
goto bail ;
rcd - > egrbufs . size = eager_buffer_size ;
/*
* The size of the buffers programmed into the RcvArray
* entries needs to be big enough to handle the highest
* MTU supported .
*/
if ( rcd - > egrbufs . size < hfi1_max_mtu ) {
rcd - > egrbufs . size = __roundup_pow_of_two ( hfi1_max_mtu ) ;
2015-11-07 09:06:56 +08:00
hfi1_cdbg ( PROC ,
2019-03-28 07:50:50 +08:00
" ctxt%u: eager bufs size too small. Adjusting to %u \n " ,
2015-07-31 03:17:43 +08:00
rcd - > ctxt , rcd - > egrbufs . size ) ;
}
rcd - > egrbufs . rcvtid_size = HFI1_MAX_EAGER_BUFFER_SIZE ;
2017-04-13 11:29:29 +08:00
/* Applicable only for statically created kernel contexts */
if ( ctxt < dd - > first_dyn_alloc_ctxt ) {
2017-02-08 21:26:37 +08:00
rcd - > opstats = kzalloc_node ( sizeof ( * rcd - > opstats ) ,
GFP_KERNEL , numa ) ;
2015-10-13 05:28:36 +08:00
if ( ! rcd - > opstats )
2015-07-31 03:17:43 +08:00
goto bail ;
2019-02-06 06:13:13 +08:00
/* Initialize TID flow generations for the context */
hfi1_kern_init_ctxt_generations ( rcd ) ;
2015-07-31 03:17:43 +08:00
}
2017-06-10 07:00:19 +08:00
2017-08-05 04:52:38 +08:00
* context = rcd ;
return 0 ;
2015-07-31 03:17:43 +08:00
}
2017-08-05 04:52:38 +08:00
2015-07-31 03:17:43 +08:00
bail :
2017-08-05 04:52:38 +08:00
* context = NULL ;
2017-08-05 04:52:44 +08:00
hfi1_free_ctxt ( rcd ) ;
2017-08-05 04:52:38 +08:00
return - ENOMEM ;
}
/**
* hfi1_free_ctxt
* @ rcd : pointer to an initialized rcd data structure
*
2017-08-05 04:52:44 +08:00
* This wrapper is the free function that matches hfi1_create_ctxtdata ( ) .
* When a context is done being used ( kernel or user ) , this function is called
* for the " final " put to match the kref init from hf1i_create_ctxtdata ( ) .
* Other users of the context do a get / put sequence to make sure that the
* structure isn ' t removed while in use .
2017-08-05 04:52:38 +08:00
*/
2017-08-05 04:52:44 +08:00
void hfi1_free_ctxt ( struct hfi1_ctxtdata * rcd )
2017-08-05 04:52:38 +08:00
{
2017-08-05 04:52:44 +08:00
hfi1_rcd_put ( rcd ) ;
2015-07-31 03:17:43 +08:00
}
/*
* Convert a receive header entry size that to the encoding used in the CSR .
*
* Return a zero if the given size is invalid .
*/
static inline u64 encode_rcv_header_entry_size ( u16 size )
{
/* there are only 3 valid receive header entry sizes */
if ( size = = 2 )
return 1 ;
if ( size = = 16 )
return 2 ;
else if ( size = = 32 )
return 4 ;
return 0 ; /* invalid */
}
/*
* Select the largest ccti value over all SLs to determine the intra -
* packet gap for the link .
*
* called with cca_timer_lock held ( to protect access to cca_timer
* array ) , and rcu_read_lock ( ) ( to protect access to cc_state ) .
*/
void set_link_ipg ( struct hfi1_pportdata * ppd )
{
struct hfi1_devdata * dd = ppd - > dd ;
struct cc_state * cc_state ;
int i ;
u16 cce , ccti_limit , max_ccti = 0 ;
u16 shift , mult ;
u64 src ;
u32 current_egress_rate ; /* Mbits /sec */
2024-06-12 13:13:20 +08:00
u64 max_pkt_time ;
2015-07-31 03:17:43 +08:00
/*
* max_pkt_time is the maximum packet egress time in units
* of the fabric clock period 1 / ( 805 MHz ) .
*/
cc_state = get_cc_state ( ppd ) ;
2016-02-15 12:19:49 +08:00
if ( ! cc_state )
2015-07-31 03:17:43 +08:00
/*
* This should _never_ happen - rcu_read_lock ( ) is held ,
* and set_link_ipg ( ) should not be called if cc_state
* is NULL .
*/
return ;
for ( i = 0 ; i < OPA_MAX_SLS ; i + + ) {
u16 ccti = ppd - > cca_timer [ i ] . ccti ;
if ( ccti > max_ccti )
max_ccti = ccti ;
}
ccti_limit = cc_state - > cct . ccti_limit ;
if ( max_ccti > ccti_limit )
max_ccti = ccti_limit ;
cce = cc_state - > cct . entries [ max_ccti ] . entry ;
shift = ( cce & 0xc000 ) > > 14 ;
mult = ( cce & 0x3fff ) ;
current_egress_rate = active_egress_rate ( ppd ) ;
max_pkt_time = egress_cycles ( ppd - > ibmaxlen , current_egress_rate ) ;
src = ( max_pkt_time > > shift ) * mult ;
src & = SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SMASK ;
src < < = SEND_STATIC_RATE_CONTROL_CSR_SRC_RELOAD_SHIFT ;
write_csr ( dd , SEND_STATIC_RATE_CONTROL , src ) ;
}
static enum hrtimer_restart cca_timer_fn ( struct hrtimer * t )
{
struct cca_timer * cca_timer ;
struct hfi1_pportdata * ppd ;
int sl ;
2016-04-14 23:31:53 +08:00
u16 ccti_timer , ccti_min ;
2015-07-31 03:17:43 +08:00
struct cc_state * cc_state ;
2015-10-26 22:28:43 +08:00
unsigned long flags ;
2016-04-14 23:31:53 +08:00
enum hrtimer_restart ret = HRTIMER_NORESTART ;
2015-07-31 03:17:43 +08:00
cca_timer = container_of ( t , struct cca_timer , hrtimer ) ;
ppd = cca_timer - > ppd ;
sl = cca_timer - > sl ;
rcu_read_lock ( ) ;
cc_state = get_cc_state ( ppd ) ;
2016-02-15 12:19:49 +08:00
if ( ! cc_state ) {
2015-07-31 03:17:43 +08:00
rcu_read_unlock ( ) ;
return HRTIMER_NORESTART ;
}
/*
* 1 ) decrement ccti for SL
* 2 ) calculate IPG for link ( set_link_ipg ( ) )
* 3 ) restart timer , unless ccti is at min value
*/
ccti_min = cc_state - > cong_setting . entries [ sl ] . ccti_min ;
ccti_timer = cc_state - > cong_setting . entries [ sl ] . ccti_timer ;
2015-10-26 22:28:43 +08:00
spin_lock_irqsave ( & ppd - > cca_timer_lock , flags ) ;
2015-07-31 03:17:43 +08:00
2016-04-14 23:31:53 +08:00
if ( cca_timer - > ccti > ccti_min ) {
2015-07-31 03:17:43 +08:00
cca_timer - > ccti - - ;
set_link_ipg ( ppd ) ;
}
2016-04-14 23:31:53 +08:00
if ( cca_timer - > ccti > ccti_min ) {
2015-07-31 03:17:43 +08:00
unsigned long nsec = 1024 * ccti_timer ;
/* ccti_timer is in units of 1.024 usec */
hrtimer_forward_now ( t , ns_to_ktime ( nsec ) ) ;
2016-04-14 23:31:53 +08:00
ret = HRTIMER_RESTART ;
2015-07-31 03:17:43 +08:00
}
2016-04-14 23:31:53 +08:00
spin_unlock_irqrestore ( & ppd - > cca_timer_lock , flags ) ;
rcu_read_unlock ( ) ;
return ret ;
2015-07-31 03:17:43 +08:00
}
/*
* Common code for initializing the physical port structure .
*/
void hfi1_init_pportdata ( struct pci_dev * pdev , struct hfi1_pportdata * ppd ,
struct hfi1_devdata * dd , u8 hw_pidx , u8 port )
{
2016-07-26 04:39:14 +08:00
int i ;
2015-07-31 03:17:43 +08:00
uint default_pkey_idx ;
2016-07-26 04:39:14 +08:00
struct cc_state * cc_state ;
2015-07-31 03:17:43 +08:00
ppd - > dd = dd ;
ppd - > hw_pidx = hw_pidx ;
ppd - > port = port ; /* IB port number, not index */
2018-02-02 02:52:28 +08:00
ppd - > prev_link_width = LINK_WIDTH_DEFAULT ;
/*
* There are C_VL_COUNT number of PortVLXmitWait counters .
* Adding 1 to C_VL_COUNT to include the PortXmitWait counter .
*/
for ( i = 0 ; i < C_VL_COUNT + 1 ; i + + ) {
ppd - > port_vl_xmit_wait_last [ i ] = 0 ;
ppd - > vl_xmit_flit_cnt [ i ] = 0 ;
}
2015-07-31 03:17:43 +08:00
default_pkey_idx = 1 ;
ppd - > pkeys [ default_pkey_idx ] = DEFAULT_P_KEY ;
2017-04-10 01:16:59 +08:00
ppd - > part_enforce | = HFI1_PART_ENFORCE_IN ;
2024-06-12 13:13:20 +08:00
ppd - > pkeys [ 0 ] = 0x8001 ;
2015-07-31 03:17:43 +08:00
INIT_WORK ( & ppd - > link_vc_work , handle_verify_cap ) ;
INIT_WORK ( & ppd - > link_up_work , handle_link_up ) ;
INIT_WORK ( & ppd - > link_down_work , handle_link_down ) ;
INIT_WORK ( & ppd - > freeze_work , handle_freeze ) ;
INIT_WORK ( & ppd - > link_downgrade_work , handle_link_downgrade ) ;
INIT_WORK ( & ppd - > sma_message_work , handle_sma_message ) ;
INIT_WORK ( & ppd - > link_bounce_work , handle_link_bounce ) ;
2016-08-31 22:24:33 +08:00
INIT_DELAYED_WORK ( & ppd - > start_link_work , handle_start_link ) ;
2016-01-12 07:32:21 +08:00
INIT_WORK ( & ppd - > linkstate_active_work , receive_interrupt_work ) ;
2016-02-04 06:31:14 +08:00
INIT_WORK ( & ppd - > qsfp_info . qsfp_work , qsfp_event ) ;
2015-07-31 03:17:43 +08:00
mutex_init ( & ppd - > hls_lock ) ;
spin_lock_init ( & ppd - > qsfp_info . qsfp_lock ) ;
2016-02-04 06:31:14 +08:00
ppd - > qsfp_info . ppd = ppd ;
2015-07-31 03:17:43 +08:00
ppd - > sm_trap_qp = 0x0 ;
ppd - > sa_qp = 0x1 ;
ppd - > hfi1_wq = NULL ;
spin_lock_init ( & ppd - > cca_timer_lock ) ;
for ( i = 0 ; i < OPA_MAX_SLS ; i + + ) {
hrtimer_init ( & ppd - > cca_timer [ i ] . hrtimer , CLOCK_MONOTONIC ,
HRTIMER_MODE_REL ) ;
ppd - > cca_timer [ i ] . ppd = ppd ;
ppd - > cca_timer [ i ] . sl = i ;
ppd - > cca_timer [ i ] . ccti = 0 ;
ppd - > cca_timer [ i ] . hrtimer . function = cca_timer_fn ;
}
ppd - > cc_max_table_entries = IB_CC_TABLE_CAP_DEFAULT ;
spin_lock_init ( & ppd - > cc_state_lock ) ;
spin_lock_init ( & ppd - > cc_log_lock ) ;
2016-07-26 04:39:14 +08:00
cc_state = kzalloc ( sizeof ( * cc_state ) , GFP_KERNEL ) ;
RCU_INIT_POINTER ( ppd - > cc_state , cc_state ) ;
if ( ! cc_state )
2015-07-31 03:17:43 +08:00
goto bail ;
return ;
bail :
2018-08-16 14:03:46 +08:00
dd_dev_err ( dd , " Congestion Control Agent disabled for port %d \n " , port ) ;
2015-07-31 03:17:43 +08:00
}
/*
* Do initialization for device that is only needed on
* first detect , not on resets .
*/
static int loadtime_init ( struct hfi1_devdata * dd )
{
return 0 ;
}
/**
* init_after_reset - re - initialize after a reset
* @ dd : the hfi1_ib device
*
* sanity check at least some of the values after reset , and
* ensure no receive or transmit ( explicitly , in case reset
* failed
*/
static int init_after_reset ( struct hfi1_devdata * dd )
{
int i ;
2017-08-05 04:52:44 +08:00
struct hfi1_ctxtdata * rcd ;
2015-07-31 03:17:43 +08:00
/*
* Ensure chip does no sends or receives , tail updates , or
* pioavail updates while we re - initialize . This is mostly
* for the driver data structures , not chip registers .
*/
2017-08-05 04:52:44 +08:00
for ( i = 0 ; i < dd - > num_rcv_contexts ; i + + ) {
rcd = hfi1_rcd_get_by_index ( dd , i ) ;
2015-07-31 03:17:43 +08:00
hfi1_rcvctrl ( dd , HFI1_RCVCTRL_CTXT_DIS |
2017-07-24 22:46:06 +08:00
HFI1_RCVCTRL_INTRAVAIL_DIS |
2017-08-05 04:52:44 +08:00
HFI1_RCVCTRL_TAILUPD_DIS , rcd ) ;
hfi1_rcd_put ( rcd ) ;
}
2015-07-31 03:17:43 +08:00
pio_send_control ( dd , PSC_GLOBAL_DISABLE ) ;
for ( i = 0 ; i < dd - > num_send_contexts ; i + + )
sc_disable ( dd - > send_contexts [ i ] . sc ) ;
return 0 ;
}
static void enable_chip ( struct hfi1_devdata * dd )
{
2017-08-05 04:52:44 +08:00
struct hfi1_ctxtdata * rcd ;
2015-07-31 03:17:43 +08:00
u32 rcvmask ;
2017-07-24 22:45:55 +08:00
u16 i ;
2015-07-31 03:17:43 +08:00
/* enable PIO send */
pio_send_control ( dd , PSC_GLOBAL_ENABLE ) ;
/*
* Enable kernel ctxts ' receive and receive interrupt .
* Other ctxts done as user opens and initializes them .
*/
2017-04-13 11:29:29 +08:00
for ( i = 0 ; i < dd - > first_dyn_alloc_ctxt ; + + i ) {
2017-08-05 04:52:44 +08:00
rcd = hfi1_rcd_get_by_index ( dd , i ) ;
if ( ! rcd )
continue ;
2016-02-04 06:32:49 +08:00
rcvmask = HFI1_RCVCTRL_CTXT_ENB | HFI1_RCVCTRL_INTRAVAIL_ENB ;
2017-08-05 04:52:44 +08:00
rcvmask | = HFI1_CAP_KGET_MASK ( rcd - > flags , DMA_RTAIL ) ?
2015-07-31 03:17:43 +08:00
HFI1_RCVCTRL_TAILUPD_ENB : HFI1_RCVCTRL_TAILUPD_DIS ;
2017-08-05 04:52:44 +08:00
if ( ! HFI1_CAP_KGET_MASK ( rcd - > flags , MULTI_PKT_EGR ) )
2015-07-31 03:17:43 +08:00
rcvmask | = HFI1_RCVCTRL_ONE_PKT_EGR_ENB ;
2017-08-05 04:52:44 +08:00
if ( HFI1_CAP_KGET_MASK ( rcd - > flags , NODROP_RHQ_FULL ) )
2015-07-31 03:17:43 +08:00
rcvmask | = HFI1_RCVCTRL_NO_RHQ_DROP_ENB ;
2017-08-05 04:52:44 +08:00
if ( HFI1_CAP_KGET_MASK ( rcd - > flags , NODROP_EGR_FULL ) )
2015-07-31 03:17:43 +08:00
rcvmask | = HFI1_RCVCTRL_NO_EGR_DROP_ENB ;
2019-02-06 06:13:13 +08:00
if ( HFI1_CAP_IS_KSET ( TID_RDMA ) )
rcvmask | = HFI1_RCVCTRL_TIDFLOW_ENB ;
2017-08-05 04:52:44 +08:00
hfi1_rcvctrl ( dd , rcvmask , rcd ) ;
sc_enable ( rcd - > sc ) ;
hfi1_rcd_put ( rcd ) ;
2015-07-31 03:17:43 +08:00
}
}
/**
* create_workqueues - create per port workqueues
* @ dd : the hfi1_ib device
*/
static int create_workqueues ( struct hfi1_devdata * dd )
{
int pidx ;
struct hfi1_pportdata * ppd ;
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
if ( ! ppd - > hfi1_wq ) {
ppd - > hfi1_wq =
2015-11-10 08:13:58 +08:00
alloc_workqueue (
" hfi%d_%d " ,
2019-03-19 00:55:09 +08:00
WQ_SYSFS | WQ_HIGHPRI | WQ_CPU_INTENSIVE |
WQ_MEM_RECLAIM ,
2017-05-04 20:14:10 +08:00
HFI1_MAX_ACTIVE_WORKQUEUE_ENTRIES ,
2015-11-10 08:13:58 +08:00
dd - > unit , pidx ) ;
2015-07-31 03:17:43 +08:00
if ( ! ppd - > hfi1_wq )
goto wq_error ;
}
2017-07-29 23:43:49 +08:00
if ( ! ppd - > link_wq ) {
/*
* Make the link workqueue single - threaded to enforce
* serialization .
*/
ppd - > link_wq =
alloc_workqueue (
" hfi_link_%d_%d " ,
WQ_SYSFS | WQ_MEM_RECLAIM | WQ_UNBOUND ,
1 , /* max_active */
dd - > unit , pidx ) ;
if ( ! ppd - > link_wq )
goto wq_error ;
}
2015-07-31 03:17:43 +08:00
}
return 0 ;
wq_error :
2015-11-10 08:13:58 +08:00
pr_err ( " alloc_workqueue failed for port %d \n " , pidx + 1 ) ;
2015-07-31 03:17:43 +08:00
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
if ( ppd - > hfi1_wq ) {
destroy_workqueue ( ppd - > hfi1_wq ) ;
ppd - > hfi1_wq = NULL ;
}
2017-07-29 23:43:49 +08:00
if ( ppd - > link_wq ) {
destroy_workqueue ( ppd - > link_wq ) ;
ppd - > link_wq = NULL ;
}
2015-07-31 03:17:43 +08:00
}
return - ENOMEM ;
}
2024-06-11 20:26:44 +08:00
/**
* destroy_workqueues - destroy per port workqueues
* @ dd : the hfi1_ib device
*/
static void destroy_workqueues ( struct hfi1_devdata * dd )
{
int pidx ;
struct hfi1_pportdata * ppd ;
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
if ( ppd - > hfi1_wq ) {
destroy_workqueue ( ppd - > hfi1_wq ) ;
ppd - > hfi1_wq = NULL ;
}
if ( ppd - > link_wq ) {
destroy_workqueue ( ppd - > link_wq ) ;
ppd - > link_wq = NULL ;
}
}
}
2018-08-16 14:04:22 +08:00
/**
* enable_general_intr ( ) - Enable the IRQs that will be handled by the
* general interrupt handler .
* @ dd : valid devdata
*
*/
static void enable_general_intr ( struct hfi1_devdata * dd )
{
set_intr_bits ( dd , CCE_ERR_INT , MISC_ERR_INT , true ) ;
set_intr_bits ( dd , PIO_ERR_INT , TXE_ERR_INT , true ) ;
set_intr_bits ( dd , IS_SENDCTXT_ERR_START , IS_SENDCTXT_ERR_END , true ) ;
set_intr_bits ( dd , PBC_INT , GPIO_ASSERT_INT , true ) ;
set_intr_bits ( dd , TCRIT_INT , TCRIT_INT , true ) ;
set_intr_bits ( dd , IS_DC_START , IS_DC_END , true ) ;
set_intr_bits ( dd , IS_SENDCREDIT_START , IS_SENDCREDIT_END , true ) ;
}
2015-07-31 03:17:43 +08:00
/**
* hfi1_init - do the actual initialization sequence on the chip
* @ dd : the hfi1_ib device
* @ reinit : re - initializing , so don ' t allocate new memory
*
* Do the actual initialization sequence on the chip . This is done
* both from the init routine called from the PCI infrastructure , and
* when we reset the chip , or detect that it was reset internally ,
* or it ' s administratively re - enabled .
*
* Memory allocation here and in called routines is only done in
* the first case ( reinit = = 0 ) . We have to be careful , because even
* without memory allocation , we need to re - write all the chip registers
* TIDs , etc . after the reset or enable has completed .
*/
int hfi1_init ( struct hfi1_devdata * dd , int reinit )
{
int ret = 0 , pidx , lastfail = 0 ;
2017-07-24 22:45:55 +08:00
unsigned long len ;
u16 i ;
2015-07-31 03:17:43 +08:00
struct hfi1_ctxtdata * rcd ;
struct hfi1_pportdata * ppd ;
/* Set up send low level handlers */
dd - > process_pio_send = hfi1_verbs_send_pio ;
dd - > process_dma_send = hfi1_verbs_send_dma ;
dd - > pio_inline_send = pio_copy ;
2017-04-13 11:29:30 +08:00
dd - > process_vnic_dma_send = hfi1_vnic_send_dma ;
2015-07-31 03:17:43 +08:00
2015-11-17 10:59:29 +08:00
if ( is_ax ( dd ) ) {
2015-07-31 03:17:43 +08:00
atomic_set ( & dd - > drop_packet , DROP_PACKET_ON ) ;
dd - > do_drop = 1 ;
} else {
atomic_set ( & dd - > drop_packet , DROP_PACKET_OFF ) ;
dd - > do_drop = 0 ;
}
/* make sure the link is not "up" */
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
ppd - > linkup = 0 ;
}
if ( reinit )
ret = init_after_reset ( dd ) ;
else
ret = loadtime_init ( dd ) ;
if ( ret )
goto done ;
2015-11-10 08:18:20 +08:00
/* allocate dummy tail memory for all receive contexts */
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
dd - > rcvhdrtail_dummy_kvaddr = dma_alloc_coherent ( & dd - > pcidev - > dev ,
sizeof ( u64 ) ,
& dd - > rcvhdrtail_dummy_dma ,
GFP_KERNEL ) ;
2015-11-10 08:18:20 +08:00
if ( ! dd - > rcvhdrtail_dummy_kvaddr ) {
dd_dev_err ( dd , " cannot allocate dummy tail memory \n " ) ;
ret = - ENOMEM ;
goto done ;
}
2015-07-31 03:17:43 +08:00
/* dd->rcd can be NULL if early initialization failed */
2017-04-13 11:29:29 +08:00
for ( i = 0 ; dd - > rcd & & i < dd - > first_dyn_alloc_ctxt ; + + i ) {
2015-07-31 03:17:43 +08:00
/*
* Set up the ( kernel ) rcvhdr queue and egr TIDs . If doing
* re - init , the simplest way to handle this is to free
* existing , and re - allocate .
* Need to re - create rest of ctxt 0 ctxtdata as well .
*/
2017-08-05 04:52:44 +08:00
rcd = hfi1_rcd_get_by_index ( dd , i ) ;
2015-07-31 03:17:43 +08:00
if ( ! rcd )
continue ;
rcd - > do_interrupt = & handle_receive_interrupt ;
lastfail = hfi1_create_rcvhdrq ( dd , rcd ) ;
if ( ! lastfail )
lastfail = hfi1_setup_eagerbufs ( rcd ) ;
2019-01-24 11:20:42 +08:00
if ( ! lastfail )
lastfail = hfi1_kern_exp_rcv_init ( rcd , reinit ) ;
2016-05-13 01:24:00 +08:00
if ( lastfail ) {
2015-07-31 03:17:43 +08:00
dd_dev_err ( dd ,
2016-02-15 12:21:52 +08:00
" failed to allocate kernel ctxt's rcvhdrq and/or egr bufs \n " ) ;
2016-05-13 01:24:00 +08:00
ret = lastfail ;
}
2018-08-16 14:04:22 +08:00
/* enable IRQ */
2017-08-05 04:52:44 +08:00
hfi1_rcd_put ( rcd ) ;
2015-07-31 03:17:43 +08:00
}
/* Allocate enough memory for user event notification. */
2018-06-21 00:43:06 +08:00
len = PAGE_ALIGN ( chip_rcv_contexts ( dd ) * HFI1_MAX_SHARED_CTXTS *
2016-03-05 01:00:43 +08:00
sizeof ( * dd - > events ) ) ;
2015-07-31 03:17:43 +08:00
dd - > events = vmalloc_user ( len ) ;
if ( ! dd - > events )
dd_dev_err ( dd , " Failed to allocate user events page \n " ) ;
/*
* Allocate a page for device and port status .
* Page will be shared amongst all user processes .
*/
dd - > status = vmalloc_user ( PAGE_SIZE ) ;
if ( ! dd - > status )
dd_dev_err ( dd , " Failed to allocate dev status page \n " ) ;
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
if ( dd - > status )
/* Currently, we only have one port */
ppd - > statusp = & dd - > status - > port ;
set_mtu ( ppd ) ;
}
/* enable chip even if we have an error, so we can debug cause */
enable_chip ( dd ) ;
done :
/*
* Set status even if port serdes is not initialized
* so that diags will work .
*/
if ( dd - > status )
dd - > status - > dev | = HFI1_STATUS_CHIP_PRESENT |
HFI1_STATUS_INITTED ;
if ( ! ret ) {
/* enable all interrupts from the chip */
2018-08-16 14:04:22 +08:00
enable_general_intr ( dd ) ;
init_qsfp_int ( dd ) ;
2015-07-31 03:17:43 +08:00
/* chip is OK for user apps; mark it as initialized */
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
2016-02-15 12:21:43 +08:00
/*
* start the serdes - must be after interrupts are
* enabled so we are notified when the link goes up
2015-07-31 03:17:43 +08:00
*/
lastfail = bringup_serdes ( ppd ) ;
if ( lastfail )
dd_dev_info ( dd ,
2016-02-15 12:21:52 +08:00
" Failed to bring up port %u \n " ,
ppd - > port ) ;
2015-07-31 03:17:43 +08:00
/*
* Set status even if port serdes is not initialized
* so that diags will work .
*/
if ( ppd - > statusp )
* ppd - > statusp | = HFI1_STATUS_CHIP_PRESENT |
HFI1_STATUS_INITTED ;
if ( ! ppd - > link_speed_enabled )
continue ;
}
}
/* if ret is non-zero, we probably should do some cleanup here... */
return ret ;
}
struct hfi1_devdata * hfi1_lookup ( int unit )
{
2019-02-09 04:41:29 +08:00
return xa_load ( & hfi1_dev_table , unit ) ;
2015-07-31 03:17:43 +08:00
}
/*
* Stop the timers during unit shutdown , or after an error late
* in initialization .
*/
static void stop_timers ( struct hfi1_devdata * dd )
{
struct hfi1_pportdata * ppd ;
int pidx ;
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
2017-10-17 06:51:54 +08:00
if ( ppd - > led_override_timer . function ) {
2015-07-31 03:17:43 +08:00
del_timer_sync ( & ppd - > led_override_timer ) ;
atomic_set ( & ppd - > led_override_timer_active , 0 ) ;
}
}
}
/**
* shutdown_device - shut down a device
* @ dd : the hfi1_ib device
*
* This is called to make the device quiet when we are about to
* unload the driver , and also when the device is administratively
* disabled . It does not free any data structures .
* Everything it does has to be setup again by hfi1_init ( dd , 1 )
*/
static void shutdown_device ( struct hfi1_devdata * dd )
{
struct hfi1_pportdata * ppd ;
2017-08-05 04:52:44 +08:00
struct hfi1_ctxtdata * rcd ;
2015-07-31 03:17:43 +08:00
unsigned pidx ;
int i ;
2018-05-02 21:43:15 +08:00
if ( dd - > flags & HFI1_SHUTDOWN )
return ;
dd - > flags | = HFI1_SHUTDOWN ;
2015-07-31 03:17:43 +08:00
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
ppd - > linkup = 0 ;
if ( ppd - > statusp )
* ppd - > statusp & = ~ ( HFI1_STATUS_IB_CONF |
HFI1_STATUS_IB_READY ) ;
}
dd - > flags & = ~ HFI1_INITTED ;
2018-08-16 14:04:22 +08:00
/* mask and clean up interrupts */
set_intr_bits ( dd , IS_FIRST_SOURCE , IS_LAST_SOURCE , false ) ;
2018-08-16 14:04:04 +08:00
msix_clean_up_interrupts ( dd ) ;
2015-07-31 03:17:43 +08:00
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
2017-08-05 04:52:44 +08:00
for ( i = 0 ; i < dd - > num_rcv_contexts ; i + + ) {
rcd = hfi1_rcd_get_by_index ( dd , i ) ;
2015-07-31 03:17:43 +08:00
hfi1_rcvctrl ( dd , HFI1_RCVCTRL_TAILUPD_DIS |
2017-07-24 22:46:06 +08:00
HFI1_RCVCTRL_CTXT_DIS |
HFI1_RCVCTRL_INTRAVAIL_DIS |
HFI1_RCVCTRL_PKEY_DIS |
2017-08-05 04:52:44 +08:00
HFI1_RCVCTRL_ONE_PKT_EGR_DIS , rcd ) ;
hfi1_rcd_put ( rcd ) ;
}
2015-07-31 03:17:43 +08:00
/*
* Gracefully stop all sends allowing any in progress to
* trickle out first .
*/
for ( i = 0 ; i < dd - > num_send_contexts ; i + + )
sc_flush ( dd - > send_contexts [ i ] . sc ) ;
}
/*
* Enough for anything that ' s going to trickle out to have actually
* done so .
*/
udelay ( 20 ) ;
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
ppd = dd - > pport + pidx ;
/* disable all contexts */
for ( i = 0 ; i < dd - > num_send_contexts ; i + + )
sc_disable ( dd - > send_contexts [ i ] . sc ) ;
/* disable the send device */
pio_send_control ( dd , PSC_GLOBAL_DISABLE ) ;
2016-02-04 06:35:57 +08:00
shutdown_led_override ( ppd ) ;
2015-07-31 03:17:43 +08:00
/*
* Clear SerdesEnable .
* We can ' t count on interrupts since we are stopping .
*/
hfi1_quiet_serdes ( ppd ) ;
2024-06-11 20:26:44 +08:00
if ( ppd - > hfi1_wq )
flush_workqueue ( ppd - > hfi1_wq ) ;
if ( ppd - > link_wq )
flush_workqueue ( ppd - > link_wq ) ;
2015-07-31 03:17:43 +08:00
}
sdma_exit ( dd ) ;
}
/**
* hfi1_free_ctxtdata - free a context ' s allocated data
* @ dd : the hfi1_ib device
* @ rcd : the ctxtdata structure
*
* free up any allocated data for a context
* It should never change any chip state , or global driver state .
*/
void hfi1_free_ctxtdata ( struct hfi1_devdata * dd , struct hfi1_ctxtdata * rcd )
{
2017-06-10 07:00:19 +08:00
u32 e ;
2015-07-31 03:17:43 +08:00
if ( ! rcd )
return ;
if ( rcd - > rcvhdrq ) {
2018-06-21 00:42:31 +08:00
dma_free_coherent ( & dd - > pcidev - > dev , rcvhdrq_size ( rcd ) ,
2016-09-06 19:35:54 +08:00
rcd - > rcvhdrq , rcd - > rcvhdrq_dma ) ;
2015-07-31 03:17:43 +08:00
rcd - > rcvhdrq = NULL ;
if ( rcd - > rcvhdrtail_kvaddr ) {
dma_free_coherent ( & dd - > pcidev - > dev , PAGE_SIZE ,
( void * ) rcd - > rcvhdrtail_kvaddr ,
2016-09-06 19:35:54 +08:00
rcd - > rcvhdrqtailaddr_dma ) ;
2015-07-31 03:17:43 +08:00
rcd - > rcvhdrtail_kvaddr = NULL ;
}
}
/* all the RcvArray entries should have been cleared by now */
kfree ( rcd - > egrbufs . rcvtids ) ;
2017-06-10 07:00:19 +08:00
rcd - > egrbufs . rcvtids = NULL ;
2015-07-31 03:17:43 +08:00
for ( e = 0 ; e < rcd - > egrbufs . alloced ; e + + ) {
2024-06-12 13:13:20 +08:00
if ( rcd - > egrbufs . buffers [ e ] . addr )
2015-07-31 03:17:43 +08:00
dma_free_coherent ( & dd - > pcidev - > dev ,
rcd - > egrbufs . buffers [ e ] . len ,
rcd - > egrbufs . buffers [ e ] . addr ,
2016-09-06 19:35:54 +08:00
rcd - > egrbufs . buffers [ e ] . dma ) ;
2015-07-31 03:17:43 +08:00
}
kfree ( rcd - > egrbufs . buffers ) ;
2017-06-10 07:00:19 +08:00
rcd - > egrbufs . alloced = 0 ;
rcd - > egrbufs . buffers = NULL ;
2015-07-31 03:17:43 +08:00
sc_free ( rcd - > sc ) ;
2017-06-10 07:00:19 +08:00
rcd - > sc = NULL ;
2015-07-31 03:17:43 +08:00
vfree ( rcd - > subctxt_uregbase ) ;
vfree ( rcd - > subctxt_rcvegrbuf ) ;
vfree ( rcd - > subctxt_rcvhdr_base ) ;
kfree ( rcd - > opstats ) ;
2017-06-10 07:00:19 +08:00
rcd - > subctxt_uregbase = NULL ;
rcd - > subctxt_rcvegrbuf = NULL ;
rcd - > subctxt_rcvhdr_base = NULL ;
rcd - > opstats = NULL ;
2015-07-31 03:17:43 +08:00
}
2016-03-06 00:49:45 +08:00
/*
* Release our hold on the shared asic data . If we are the last one ,
2016-07-07 05:28:52 +08:00
* return the structure to be finalized outside the lock . Must be
2019-02-09 04:41:29 +08:00
* holding hfi1_dev_table lock .
2016-03-06 00:49:45 +08:00
*/
2016-07-07 05:28:52 +08:00
static struct hfi1_asic_data * release_asic_data ( struct hfi1_devdata * dd )
2016-03-06 00:49:45 +08:00
{
2016-07-07 05:28:52 +08:00
struct hfi1_asic_data * ad ;
2016-03-06 00:49:45 +08:00
int other ;
if ( ! dd - > asic_data )
2016-07-07 05:28:52 +08:00
return NULL ;
2016-03-06 00:49:45 +08:00
dd - > asic_data - > dds [ dd - > hfi1_id ] = NULL ;
other = dd - > hfi1_id ? 0 : 1 ;
2016-07-07 05:28:52 +08:00
ad = dd - > asic_data ;
2016-03-06 00:49:45 +08:00
dd - > asic_data = NULL ;
2016-07-07 05:28:52 +08:00
/* return NULL if the other dd still has a link */
return ad - > dds [ other ] ? NULL : ad ;
}
static void finalize_asic_data ( struct hfi1_devdata * dd ,
struct hfi1_asic_data * ad )
{
clean_up_i2c ( dd , ad ) ;
kfree ( ad ) ;
2016-03-06 00:49:45 +08:00
}
2018-05-01 20:36:06 +08:00
/**
* hfi1_clean_devdata - cleans up per - unit data structure
* @ dd : pointer to a valid devdata structure
*
* It cleans up all data structures set up by
* by hfi1_alloc_devdata ( ) .
*/
static void hfi1_clean_devdata ( struct hfi1_devdata * dd )
2015-07-31 03:17:43 +08:00
{
2016-07-07 05:28:52 +08:00
struct hfi1_asic_data * ad ;
2015-07-31 03:17:43 +08:00
unsigned long flags ;
2019-02-09 04:41:29 +08:00
xa_lock_irqsave ( & hfi1_dev_table , flags ) ;
__xa_erase ( & hfi1_dev_table , dd - > unit ) ;
2016-07-07 05:28:52 +08:00
ad = release_asic_data ( dd ) ;
2019-02-09 04:41:29 +08:00
xa_unlock_irqrestore ( & hfi1_dev_table , flags ) ;
2018-05-01 20:36:06 +08:00
finalize_asic_data ( dd , ad ) ;
2016-02-10 06:29:13 +08:00
free_platform_config ( dd ) ;
2015-07-31 03:17:43 +08:00
rcu_barrier ( ) ; /* wait for rcu callbacks to complete */
free_percpu ( dd - > int_counter ) ;
free_percpu ( dd - > rcv_limit ) ;
2016-02-04 06:34:07 +08:00
free_percpu ( dd - > send_schedule ) ;
2017-10-23 21:06:08 +08:00
free_percpu ( dd - > tx_opstats ) ;
2018-05-01 20:36:06 +08:00
dd - > int_counter = NULL ;
dd - > rcv_limit = NULL ;
dd - > send_schedule = NULL ;
dd - > tx_opstats = NULL ;
IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support
Currently the driver doesn't support completion vectors. These
are used to indicate which sets of CQs should be grouped together
into the same vector. A vector is a CQ processing thread that
runs on a specific CPU.
If an application has several CQs bound to different completion
vectors, and each completion vector runs on different CPUs, then
the completion queue workload is balanced. This helps scale as more
nodes are used.
Implement CQ completion vector support using a global workqueue
where a CQ entry is queued to the CPU corresponding to the CQ's
completion vector. Since the workqueue is global, it's guaranteed
to always be there when queueing CQ entries; Therefore, the RCU
locking for cq->rdi->worker in the hot path is superfluous.
Each completion vector is assigned to a different CPU. The number of
completion vectors available is computed by taking the number of
online, physical CPUs from the local NUMA node and subtracting the
CPUs used for kernel receive queues and the general interrupt.
Special use cases:
* If there are no CPUs left for completion vectors, the same CPU
for the general interrupt is used; Therefore, there would only
be one completion vector available.
* For multi-HFI systems, the number of completion vectors available
for each device is the total number of completion vectors in
the local NUMA node divided by the number of devices in the same
NUMA node. If there's a division remainder, the first device to
get initialized gets an extra completion vector.
Upon a CQ creation, an invalid completion vector could be specified.
Handle it as follows:
* If the completion vector is less than 0, set it to 0.
* Set the completion vector to the result of the passed completion
vector moded with the number of device completion vectors
available.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Sebastian Sanchez <sebastian.sanchez@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2018-05-02 21:43:55 +08:00
kfree ( dd - > comp_vect ) ;
dd - > comp_vect = NULL ;
2018-02-02 02:43:50 +08:00
sdma_clean ( dd , dd - > num_sdma ) ;
2016-04-20 21:05:24 +08:00
rvt_dealloc_device ( & dd - > verbs_dev . rdi ) ;
2015-07-31 03:17:43 +08:00
}
2018-05-01 20:36:06 +08:00
static void __hfi1_free_devdata ( struct kobject * kobj )
{
struct hfi1_devdata * dd =
container_of ( kobj , struct hfi1_devdata , kobj ) ;
hfi1_clean_devdata ( dd ) ;
}
2016-05-19 20:26:44 +08:00
static struct kobj_type hfi1_devdata_type = {
. release = __hfi1_free_devdata ,
} ;
void hfi1_free_devdata ( struct hfi1_devdata * dd )
{
kobject_put ( & dd - > kobj ) ;
}
2018-08-16 14:03:46 +08:00
/**
* hfi1_alloc_devdata - Allocate our primary per - unit data structure .
* @ pdev : Valid PCI device
* @ extra : How many bytes to alloc past the default
*
* Must be done via verbs allocator , because the verbs cleanup process
* both does cleanup and free of the data structure .
2015-07-31 03:17:43 +08:00
* " extra " is for chip - specific data .
*/
2018-08-16 14:03:46 +08:00
static struct hfi1_devdata * hfi1_alloc_devdata ( struct pci_dev * pdev ,
size_t extra )
2015-07-31 03:17:43 +08:00
{
struct hfi1_devdata * dd ;
2016-01-20 06:44:06 +08:00
int ret , nports ;
2015-07-31 03:17:43 +08:00
2016-01-20 06:44:06 +08:00
/* extra is * number of ports */
nports = extra / sizeof ( struct hfi1_pportdata ) ;
2015-07-31 03:17:43 +08:00
2016-01-20 06:44:06 +08:00
dd = ( struct hfi1_devdata * ) rvt_alloc_device ( sizeof ( * dd ) + extra ,
nports ) ;
2015-07-31 03:17:43 +08:00
if ( ! dd )
return ERR_PTR ( - ENOMEM ) ;
2016-01-20 06:44:06 +08:00
dd - > num_pports = nports ;
2015-07-31 03:17:43 +08:00
dd - > pport = ( struct hfi1_pportdata * ) ( dd + 1 ) ;
2018-05-01 20:35:58 +08:00
dd - > pcidev = pdev ;
pci_set_drvdata ( pdev , dd ) ;
2019-03-06 07:42:58 +08:00
dd - > node = NUMA_NO_NODE ;
2015-07-31 03:17:43 +08:00
2019-02-09 04:41:29 +08:00
ret = xa_alloc_irq ( & hfi1_dev_table , & dd - > unit , dd , xa_limit_32b ,
GFP_KERNEL ) ;
2015-07-31 03:17:43 +08:00
if ( ret < 0 ) {
2018-08-16 14:03:46 +08:00
dev_err ( & pdev - > dev ,
" Could not allocate unit ID: error %d \n " , - ret ) ;
2015-07-31 03:17:43 +08:00
goto bail ;
}
2017-12-19 11:56:37 +08:00
rvt_set_ibdev_name ( & dd - > verbs_dev . rdi , " %s_%d " , class_name ( ) , dd - > unit ) ;
2015-07-31 03:17:43 +08:00
/*
* Initialize all locks for the device . This needs to be as early as
* possible so locks are usable .
*/
spin_lock_init ( & dd - > sc_lock ) ;
spin_lock_init ( & dd - > sendctrl_lock ) ;
spin_lock_init ( & dd - > rcvctrl_lock ) ;
spin_lock_init ( & dd - > uctxt_lock ) ;
spin_lock_init ( & dd - > hfi1_diag_trans_lock ) ;
spin_lock_init ( & dd - > sc_init_lock ) ;
spin_lock_init ( & dd - > dc8051_memlock ) ;
seqlock_init ( & dd - > sc2vl_lock ) ;
spin_lock_init ( & dd - > sde_map_lock ) ;
2016-02-15 04:46:10 +08:00
spin_lock_init ( & dd - > pio_map_lock ) ;
2017-04-29 01:40:02 +08:00
mutex_init ( & dd - > dc8051_lock ) ;
2015-07-31 03:17:43 +08:00
init_waitqueue_head ( & dd - > event_queue ) ;
2018-08-16 14:04:22 +08:00
spin_lock_init ( & dd - > irq_src_lock ) ;
2015-07-31 03:17:43 +08:00
dd - > int_counter = alloc_percpu ( u64 ) ;
if ( ! dd - > int_counter ) {
ret = - ENOMEM ;
goto bail ;
}
dd - > rcv_limit = alloc_percpu ( u64 ) ;
if ( ! dd - > rcv_limit ) {
ret = - ENOMEM ;
goto bail ;
}
2016-02-04 06:34:07 +08:00
dd - > send_schedule = alloc_percpu ( u64 ) ;
if ( ! dd - > send_schedule ) {
ret = - ENOMEM ;
goto bail ;
}
2017-10-23 21:06:08 +08:00
dd - > tx_opstats = alloc_percpu ( struct hfi1_opcode_stats_perctx ) ;
if ( ! dd - > tx_opstats ) {
ret = - ENOMEM ;
goto bail ;
}
IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support
Currently the driver doesn't support completion vectors. These
are used to indicate which sets of CQs should be grouped together
into the same vector. A vector is a CQ processing thread that
runs on a specific CPU.
If an application has several CQs bound to different completion
vectors, and each completion vector runs on different CPUs, then
the completion queue workload is balanced. This helps scale as more
nodes are used.
Implement CQ completion vector support using a global workqueue
where a CQ entry is queued to the CPU corresponding to the CQ's
completion vector. Since the workqueue is global, it's guaranteed
to always be there when queueing CQ entries; Therefore, the RCU
locking for cq->rdi->worker in the hot path is superfluous.
Each completion vector is assigned to a different CPU. The number of
completion vectors available is computed by taking the number of
online, physical CPUs from the local NUMA node and subtracting the
CPUs used for kernel receive queues and the general interrupt.
Special use cases:
* If there are no CPUs left for completion vectors, the same CPU
for the general interrupt is used; Therefore, there would only
be one completion vector available.
* For multi-HFI systems, the number of completion vectors available
for each device is the total number of completion vectors in
the local NUMA node divided by the number of devices in the same
NUMA node. If there's a division remainder, the first device to
get initialized gets an extra completion vector.
Upon a CQ creation, an invalid completion vector could be specified.
Handle it as follows:
* If the completion vector is less than 0, set it to 0.
* Set the completion vector to the result of the passed completion
vector moded with the number of device completion vectors
available.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Sebastian Sanchez <sebastian.sanchez@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2018-05-02 21:43:55 +08:00
dd - > comp_vect = kzalloc ( sizeof ( * dd - > comp_vect ) , GFP_KERNEL ) ;
if ( ! dd - > comp_vect ) {
ret = - ENOMEM ;
goto bail ;
}
2016-05-19 20:26:44 +08:00
kobject_init ( & dd - > kobj , & hfi1_devdata_type ) ;
2015-07-31 03:17:43 +08:00
return dd ;
bail :
2018-05-01 20:36:06 +08:00
hfi1_clean_devdata ( dd ) ;
2015-07-31 03:17:43 +08:00
return ERR_PTR ( ret ) ;
}
/*
* Called from freeze mode handlers , and from PCI error
* reporting code . Should be paranoid about state of
* system and data structures .
*/
void hfi1_disable_after_error ( struct hfi1_devdata * dd )
{
if ( dd - > flags & HFI1_INITTED ) {
u32 pidx ;
dd - > flags & = ~ HFI1_INITTED ;
if ( dd - > pport )
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
struct hfi1_pportdata * ppd ;
ppd = dd - > pport + pidx ;
if ( dd - > flags & HFI1_PRESENT )
set_link_state ( ppd , HLS_DN_DISABLE ) ;
if ( ppd - > statusp )
* ppd - > statusp & = ~ HFI1_STATUS_IB_READY ;
}
}
/*
* Mark as having had an error for driver , and also
* for / sys and status word mapped to user programs .
* This marks unit as not usable , until reset .
*/
if ( dd - > status )
dd - > status - > dev | = HFI1_STATUS_HWERROR ;
}
static void remove_one ( struct pci_dev * ) ;
static int init_one ( struct pci_dev * , const struct pci_device_id * ) ;
2018-05-02 21:43:15 +08:00
static void shutdown_one ( struct pci_dev * ) ;
2015-07-31 03:17:43 +08:00
# define DRIVER_LOAD_MSG "Intel " DRIVER_NAME " loaded: "
# define PFX DRIVER_NAME ": "
2016-07-25 22:54:48 +08:00
const struct pci_device_id hfi1_pci_tbl [ ] = {
2015-07-31 03:17:43 +08:00
{ PCI_DEVICE ( PCI_VENDOR_ID_INTEL , PCI_DEVICE_ID_INTEL0 ) } ,
{ PCI_DEVICE ( PCI_VENDOR_ID_INTEL , PCI_DEVICE_ID_INTEL1 ) } ,
{ 0 , }
} ;
MODULE_DEVICE_TABLE ( pci , hfi1_pci_tbl ) ;
static struct pci_driver hfi1_pci_driver = {
. name = DRIVER_NAME ,
. probe = init_one ,
. remove = remove_one ,
2018-05-02 21:43:15 +08:00
. shutdown = shutdown_one ,
2015-07-31 03:17:43 +08:00
. id_table = hfi1_pci_tbl ,
. err_handler = & hfi1_pci_err_handler ,
} ;
static void __init compute_krcvqs ( void )
{
int i ;
for ( i = 0 ; i < krcvqsset ; i + + )
n_krcvqs + = krcvqs [ i ] ;
}
/*
* Do all the generic driver unit - and chip - independent memory
* allocation and initialization .
*/
static int __init hfi1_mod_init ( void )
{
int ret ;
ret = dev_init ( ) ;
if ( ret )
goto bail ;
2016-07-25 22:54:48 +08:00
ret = node_affinity_init ( ) ;
if ( ret )
goto bail ;
2016-07-25 22:52:36 +08:00
2015-07-31 03:17:43 +08:00
/* validate max MTU before any devices start */
if ( ! valid_opa_max_mtu ( hfi1_max_mtu ) ) {
pr_err ( " Invalid max_mtu 0x%x, using 0x%x instead \n " ,
hfi1_max_mtu , HFI1_DEFAULT_MAX_MTU ) ;
hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU ;
}
/* valid CUs run from 1-128 in powers of 2 */
if ( hfi1_cu > 128 | | ! is_power_of_2 ( hfi1_cu ) )
hfi1_cu = 1 ;
/* valid credit return threshold is 0-100, variable is unsigned */
if ( user_credit_return_threshold > 100 )
user_credit_return_threshold = 100 ;
compute_krcvqs ( ) ;
2016-02-15 12:21:43 +08:00
/*
* sanitize receive interrupt count , time must wait until after
* the hardware type is known
*/
2015-07-31 03:17:43 +08:00
if ( rcv_intr_count > RCV_HDR_HEAD_COUNTER_MASK )
rcv_intr_count = RCV_HDR_HEAD_COUNTER_MASK ;
/* reject invalid combinations */
if ( rcv_intr_count = = 0 & & rcv_intr_timeout = = 0 ) {
pr_err ( " Invalid mode: both receive interrupt count and available timeout are zero - setting interrupt count to 1 \n " ) ;
rcv_intr_count = 1 ;
}
if ( rcv_intr_count > 1 & & rcv_intr_timeout = = 0 ) {
/*
* Avoid indefinite packet delivery by requiring a timeout
* if count is > 1.
*/
pr_err ( " Invalid mode: receive interrupt count greater than 1 and available timeout is zero - setting available timeout to 1 \n " ) ;
rcv_intr_timeout = 1 ;
}
if ( rcv_intr_dynamic & & ! ( rcv_intr_count > 1 & & rcv_intr_timeout > 0 ) ) {
/*
* The dynamic algorithm expects a non - zero timeout
* and a count > 1.
*/
pr_err ( " Invalid mode: dynamic receive interrupt mitigation with invalid count and timeout - turning dynamic off \n " ) ;
rcv_intr_dynamic = 0 ;
}
/* sanitize link CRC options */
link_crc_mask & = SUPPORTED_CRCS ;
2019-01-24 11:21:11 +08:00
ret = opfn_init ( ) ;
if ( ret < 0 ) {
pr_err ( " Failed to allocate opfn_wq " ) ;
goto bail_dev ;
}
2015-07-31 03:17:43 +08:00
/*
* These must be called before the driver is registered with
* the PCI subsystem .
*/
hfi1_dbg_init ( ) ;
ret = pci_register_driver ( & hfi1_pci_driver ) ;
if ( ret < 0 ) {
pr_err ( " Unable to register driver: error %d \n " , - ret ) ;
goto bail_dev ;
}
goto bail ; /* all OK */
bail_dev :
hfi1_dbg_exit ( ) ;
dev_cleanup ( ) ;
bail :
return ret ;
}
module_init ( hfi1_mod_init ) ;
/*
* Do the non - unit driver cleanup , memory free , etc . at unload .
*/
static void __exit hfi1_mod_cleanup ( void )
{
pci_unregister_driver ( & hfi1_pci_driver ) ;
2019-01-24 11:21:11 +08:00
opfn_exit ( ) ;
IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support
Currently the driver doesn't support completion vectors. These
are used to indicate which sets of CQs should be grouped together
into the same vector. A vector is a CQ processing thread that
runs on a specific CPU.
If an application has several CQs bound to different completion
vectors, and each completion vector runs on different CPUs, then
the completion queue workload is balanced. This helps scale as more
nodes are used.
Implement CQ completion vector support using a global workqueue
where a CQ entry is queued to the CPU corresponding to the CQ's
completion vector. Since the workqueue is global, it's guaranteed
to always be there when queueing CQ entries; Therefore, the RCU
locking for cq->rdi->worker in the hot path is superfluous.
Each completion vector is assigned to a different CPU. The number of
completion vectors available is computed by taking the number of
online, physical CPUs from the local NUMA node and subtracting the
CPUs used for kernel receive queues and the general interrupt.
Special use cases:
* If there are no CPUs left for completion vectors, the same CPU
for the general interrupt is used; Therefore, there would only
be one completion vector available.
* For multi-HFI systems, the number of completion vectors available
for each device is the total number of completion vectors in
the local NUMA node divided by the number of devices in the same
NUMA node. If there's a division remainder, the first device to
get initialized gets an extra completion vector.
Upon a CQ creation, an invalid completion vector could be specified.
Handle it as follows:
* If the completion vector is less than 0, set it to 0.
* Set the completion vector to the result of the passed completion
vector moded with the number of device completion vectors
available.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Sebastian Sanchez <sebastian.sanchez@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2018-05-02 21:43:55 +08:00
node_affinity_destroy_all ( ) ;
2015-07-31 03:17:43 +08:00
hfi1_dbg_exit ( ) ;
2019-02-09 04:41:29 +08:00
WARN_ON ( ! xa_empty ( & hfi1_dev_table ) ) ;
2015-07-31 03:17:43 +08:00
dispose_firmware ( ) ; /* asymmetric with obtain_firmware() */
dev_cleanup ( ) ;
}
module_exit ( hfi1_mod_cleanup ) ;
/* this can only be called after a successful initialization */
static void cleanup_device_data ( struct hfi1_devdata * dd )
{
int ctxt ;
int pidx ;
/* users can't do anything more with chip */
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
struct hfi1_pportdata * ppd = & dd - > pport [ pidx ] ;
struct cc_state * cc_state ;
int i ;
if ( ppd - > statusp )
* ppd - > statusp & = ~ HFI1_STATUS_CHIP_PRESENT ;
for ( i = 0 ; i < OPA_MAX_SLS ; i + + )
hrtimer_cancel ( & ppd - > cca_timer [ i ] . hrtimer ) ;
spin_lock ( & ppd - > cc_state_lock ) ;
2016-07-26 04:39:14 +08:00
cc_state = get_cc_state_protected ( ppd ) ;
2016-05-01 20:35:31 +08:00
RCU_INIT_POINTER ( ppd - > cc_state , NULL ) ;
2015-07-31 03:17:43 +08:00
spin_unlock ( & ppd - > cc_state_lock ) ;
if ( cc_state )
2016-08-10 11:14:04 +08:00
kfree_rcu ( cc_state , rcu ) ;
2015-07-31 03:17:43 +08:00
}
free_credit_return ( dd ) ;
2015-11-10 08:18:20 +08:00
if ( dd - > rcvhdrtail_dummy_kvaddr ) {
dma_free_coherent ( & dd - > pcidev - > dev , sizeof ( u64 ) ,
( void * ) dd - > rcvhdrtail_dummy_kvaddr ,
2016-09-06 19:35:54 +08:00
dd - > rcvhdrtail_dummy_dma ) ;
2016-05-28 13:01:20 +08:00
dd - > rcvhdrtail_dummy_kvaddr = NULL ;
2015-11-10 08:18:20 +08:00
}
2017-08-05 04:52:44 +08:00
/*
* Free any resources still in use ( usually just kernel contexts )
* at unload ; we do for ctxtcnt , because that ' s what we allocate .
*/
for ( ctxt = 0 ; dd - > rcd & & ctxt < dd - > num_rcv_contexts ; ctxt + + ) {
struct hfi1_ctxtdata * rcd = dd - > rcd [ ctxt ] ;
2015-07-31 03:17:43 +08:00
if ( rcd ) {
2019-01-24 11:30:07 +08:00
hfi1_free_ctxt_rcv_groups ( rcd ) ;
2017-08-05 04:52:44 +08:00
hfi1_free_ctxt ( rcd ) ;
2015-07-31 03:17:43 +08:00
}
}
2017-08-05 04:52:44 +08:00
kfree ( dd - > rcd ) ;
dd - > rcd = NULL ;
2016-02-15 04:46:10 +08:00
free_pio_map ( dd ) ;
2015-07-31 03:17:43 +08:00
/* must follow rcv context free - need to remove rcv's hooks */
for ( ctxt = 0 ; ctxt < dd - > num_send_contexts ; ctxt + + )
sc_free ( dd - > send_contexts [ ctxt ] . sc ) ;
dd - > num_send_contexts = 0 ;
kfree ( dd - > send_contexts ) ;
dd - > send_contexts = NULL ;
2016-02-27 05:33:33 +08:00
kfree ( dd - > hw_to_sw ) ;
dd - > hw_to_sw = NULL ;
2015-07-31 03:17:43 +08:00
kfree ( dd - > boardname ) ;
vfree ( dd - > events ) ;
vfree ( dd - > status ) ;
}
/*
* Clean up on unit shutdown , or error during unit load after
* successful initialization .
*/
static void postinit_cleanup ( struct hfi1_devdata * dd )
{
hfi1_start_cleanup ( dd ) ;
IB/{hfi1, rdmavt, qib}: Implement CQ completion vector support
Currently the driver doesn't support completion vectors. These
are used to indicate which sets of CQs should be grouped together
into the same vector. A vector is a CQ processing thread that
runs on a specific CPU.
If an application has several CQs bound to different completion
vectors, and each completion vector runs on different CPUs, then
the completion queue workload is balanced. This helps scale as more
nodes are used.
Implement CQ completion vector support using a global workqueue
where a CQ entry is queued to the CPU corresponding to the CQ's
completion vector. Since the workqueue is global, it's guaranteed
to always be there when queueing CQ entries; Therefore, the RCU
locking for cq->rdi->worker in the hot path is superfluous.
Each completion vector is assigned to a different CPU. The number of
completion vectors available is computed by taking the number of
online, physical CPUs from the local NUMA node and subtracting the
CPUs used for kernel receive queues and the general interrupt.
Special use cases:
* If there are no CPUs left for completion vectors, the same CPU
for the general interrupt is used; Therefore, there would only
be one completion vector available.
* For multi-HFI systems, the number of completion vectors available
for each device is the total number of completion vectors in
the local NUMA node divided by the number of devices in the same
NUMA node. If there's a division remainder, the first device to
get initialized gets an extra completion vector.
Upon a CQ creation, an invalid completion vector could be specified.
Handle it as follows:
* If the completion vector is less than 0, set it to 0.
* Set the completion vector to the result of the passed completion
vector moded with the number of device completion vectors
available.
Reviewed-by: Mike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: Sebastian Sanchez <sebastian.sanchez@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
2018-05-02 21:43:55 +08:00
hfi1_comp_vectors_clean_up ( dd ) ;
hfi1_dev_affinity_clean_up ( dd ) ;
2015-07-31 03:17:43 +08:00
hfi1_pcie_ddcleanup ( dd ) ;
hfi1_pcie_cleanup ( dd - > pcidev ) ;
cleanup_device_data ( dd ) ;
hfi1_free_devdata ( dd ) ;
}
2018-08-16 14:03:46 +08:00
static int init_validate_rcvhdrcnt ( struct hfi1_devdata * dd , uint thecnt )
2016-10-26 04:12:11 +08:00
{
if ( thecnt < = HFI1_MIN_HDRQ_EGRBUF_CNT ) {
2018-08-16 14:03:46 +08:00
dd_dev_err ( dd , " Receive header queue count too small \n " ) ;
2016-10-26 04:12:11 +08:00
return - EINVAL ;
}
if ( thecnt > HFI1_MAX_HDRQ_EGRBUF_CNT ) {
2018-08-16 14:03:46 +08:00
dd_dev_err ( dd ,
" Receive header queue count cannot be greater than %u \n " ,
HFI1_MAX_HDRQ_EGRBUF_CNT ) ;
2016-10-26 04:12:11 +08:00
return - EINVAL ;
}
if ( thecnt % HDRQ_INCREMENT ) {
2018-08-16 14:03:46 +08:00
dd_dev_err ( dd , " Receive header queue count %d must be divisible by %lu \n " ,
thecnt , HDRQ_INCREMENT ) ;
2016-10-26 04:12:11 +08:00
return - EINVAL ;
}
return 0 ;
}
2015-07-31 03:17:43 +08:00
static int init_one ( struct pci_dev * pdev , const struct pci_device_id * ent )
{
int ret = 0 , j , pidx , initfail ;
2016-10-17 19:19:24 +08:00
struct hfi1_devdata * dd ;
2015-12-02 04:38:20 +08:00
struct hfi1_pportdata * ppd ;
2015-07-31 03:17:43 +08:00
/* First, lock the non-writable module parameters */
HFI1_CAP_LOCK ( ) ;
2017-03-21 08:25:29 +08:00
/* Validate dev ids */
if ( ! ( ent - > device = = PCI_DEVICE_ID_INTEL0 | |
ent - > device = = PCI_DEVICE_ID_INTEL1 ) ) {
2018-08-16 14:03:46 +08:00
dev_err ( & pdev - > dev , " Failing on unknown Intel deviceid 0x%x \n " ,
ent - > device ) ;
2017-03-21 08:25:29 +08:00
ret = - ENODEV ;
goto bail ;
}
2018-08-16 14:03:46 +08:00
/* Allocate the dd so we can get to work */
dd = hfi1_alloc_devdata ( pdev , NUM_IB_PORTS *
sizeof ( struct hfi1_pportdata ) ) ;
if ( IS_ERR ( dd ) ) {
ret = PTR_ERR ( dd ) ;
goto bail ;
}
2015-07-31 03:17:43 +08:00
/* Validate some global module parameters */
2018-08-16 14:03:46 +08:00
ret = init_validate_rcvhdrcnt ( dd , rcvhdrcnt ) ;
2016-10-26 04:12:11 +08:00
if ( ret )
2016-02-04 06:34:32 +08:00
goto bail ;
2016-10-26 04:12:11 +08:00
2015-07-31 03:17:43 +08:00
/* use the encoding function as a sanitization check */
if ( ! encode_rcv_header_entry_size ( hfi1_hdrq_entsize ) ) {
2018-08-16 14:03:46 +08:00
dd_dev_err ( dd , " Invalid HdrQ Entry size %u \n " ,
hfi1_hdrq_entsize ) ;
2015-12-11 05:02:49 +08:00
ret = - EINVAL ;
2015-07-31 03:17:43 +08:00
goto bail ;
}
/* The receive eager buffer size must be set before the receive
* contexts are created .
*
* Set the eager buffer size . Validate that it falls in a range
* allowed by the hardware - all powers of 2 between the min and
* max . The maximum valid MTU is within the eager buffer range
* so we do not need to cap the max_mtu by an eager buffer size
* setting .
*/
if ( eager_buffer_size ) {
if ( ! is_power_of_2 ( eager_buffer_size ) )
eager_buffer_size =
roundup_pow_of_two ( eager_buffer_size ) ;
eager_buffer_size =
clamp_val ( eager_buffer_size ,
MIN_EAGER_BUFFER * 8 ,
MAX_EAGER_BUFFER_TOTAL ) ;
2018-08-16 14:03:46 +08:00
dd_dev_info ( dd , " Eager buffer size %u \n " ,
eager_buffer_size ) ;
2015-07-31 03:17:43 +08:00
} else {
2018-08-16 14:03:46 +08:00
dd_dev_err ( dd , " Invalid Eager buffer size of 0 \n " ) ;
2015-07-31 03:17:43 +08:00
ret = - EINVAL ;
goto bail ;
}
/* restrict value of hfi1_rcvarr_split */
hfi1_rcvarr_split = clamp_val ( hfi1_rcvarr_split , 0 , 100 ) ;
2018-08-16 14:03:46 +08:00
ret = hfi1_pcie_init ( dd ) ;
2015-07-31 03:17:43 +08:00
if ( ret )
goto bail ;
2016-10-17 19:19:24 +08:00
/*
* Do device - specific initialization , function table setup , dd
* allocation , etc .
*/
2018-08-16 14:03:46 +08:00
ret = hfi1_init_dd ( dd ) ;
if ( ret )
2015-07-31 03:17:43 +08:00
goto clean_bail ; /* error already printed */
ret = create_workqueues ( dd ) ;
if ( ret )
goto clean_bail ;
/* do the generic initialization */
initfail = hfi1_init ( dd , 0 ) ;
2017-04-13 11:29:28 +08:00
/* setup vnic */
hfi1_vnic_setup ( dd ) ;
2015-07-31 03:17:43 +08:00
ret = hfi1_register_ib_device ( dd ) ;
/*
* Now ready for use . this should be cleared whenever we
* detect a reset , or initiate one . If earlier failure ,
* we still create devices , so diags , etc . can be used
* to determine cause of problem .
*/
2016-02-19 03:12:25 +08:00
if ( ! initfail & & ! ret ) {
2015-07-31 03:17:43 +08:00
dd - > flags | = HFI1_INITTED ;
2016-02-19 03:12:25 +08:00
/* create debufs files after init and ib register */
hfi1_dbg_ibdev_init ( & dd - > verbs_dev ) ;
}
2015-07-31 03:17:43 +08:00
j = hfi1_device_create ( dd ) ;
if ( j )
dd_dev_err ( dd , " Failed to create /dev devices: %d \n " , - j ) ;
if ( initfail | | ret ) {
2018-08-16 14:04:04 +08:00
msix_clean_up_interrupts ( dd ) ;
2015-07-31 03:17:43 +08:00
stop_timers ( dd ) ;
flush_workqueue ( ib_wq ) ;
2015-12-02 04:38:20 +08:00
for ( pidx = 0 ; pidx < dd - > num_pports ; + + pidx ) {
2015-07-31 03:17:43 +08:00
hfi1_quiet_serdes ( dd - > pport + pidx ) ;
2015-12-02 04:38:20 +08:00
ppd = dd - > pport + pidx ;
if ( ppd - > hfi1_wq ) {
destroy_workqueue ( ppd - > hfi1_wq ) ;
ppd - > hfi1_wq = NULL ;
}
2017-07-29 23:43:49 +08:00
if ( ppd - > link_wq ) {
destroy_workqueue ( ppd - > link_wq ) ;
ppd - > link_wq = NULL ;
}
2015-12-02 04:38:20 +08:00
}
2015-07-31 03:17:43 +08:00
if ( ! j )
hfi1_device_remove ( dd ) ;
if ( ! ret )
hfi1_unregister_ib_device ( dd ) ;
2017-04-13 11:29:29 +08:00
hfi1_vnic_cleanup ( dd ) ;
2015-07-31 03:17:43 +08:00
postinit_cleanup ( dd ) ;
if ( initfail )
ret = initfail ;
goto bail ; /* everything already cleaned */
}
sdma_start ( dd ) ;
return 0 ;
clean_bail :
hfi1_pcie_cleanup ( pdev ) ;
bail :
return ret ;
}
2016-10-25 23:57:55 +08:00
static void wait_for_clients ( struct hfi1_devdata * dd )
{
/*
* Remove the device init value and complete the device if there is
* no clients or wait for active clients to finish .
*/
if ( atomic_dec_and_test ( & dd - > user_refcount ) )
complete ( & dd - > user_comp ) ;
wait_for_completion ( & dd - > user_comp ) ;
}
2015-07-31 03:17:43 +08:00
static void remove_one ( struct pci_dev * pdev )
{
struct hfi1_devdata * dd = pci_get_drvdata ( pdev ) ;
2016-02-19 03:12:25 +08:00
/* close debugfs files before ib unregister */
hfi1_dbg_ibdev_exit ( & dd - > verbs_dev ) ;
2016-10-25 23:57:55 +08:00
/* remove the /dev hfi1 interface */
hfi1_device_remove ( dd ) ;
/* wait for existing user space clients to finish */
wait_for_clients ( dd ) ;
2015-07-31 03:17:43 +08:00
/* unregister from IB core */
hfi1_unregister_ib_device ( dd ) ;
2017-04-13 11:29:28 +08:00
/* cleanup vnic */
hfi1_vnic_cleanup ( dd ) ;
2015-07-31 03:17:43 +08:00
/*
* Disable the IB link , disable interrupts on the device ,
* clear dma engines , etc .
*/
shutdown_device ( dd ) ;
2024-06-11 20:26:44 +08:00
destroy_workqueues ( dd ) ;
2015-07-31 03:17:43 +08:00
stop_timers ( dd ) ;
/* wait until all of our (qsfp) queue_work() calls complete */
flush_workqueue ( ib_wq ) ;
postinit_cleanup ( dd ) ;
}
2018-05-02 21:43:15 +08:00
static void shutdown_one ( struct pci_dev * pdev )
{
struct hfi1_devdata * dd = pci_get_drvdata ( pdev ) ;
shutdown_device ( dd ) ;
}
2015-07-31 03:17:43 +08:00
/**
* hfi1_create_rcvhdrq - create a receive header queue
* @ dd : the hfi1_ib device
* @ rcd : the context data
*
* This must be contiguous memory ( from an i / o perspective ) , and must be
* DMA ' able ( which means for some systems , it will go through an IOMMU ,
* or be forced into a low address range ) .
*/
int hfi1_create_rcvhdrq ( struct hfi1_devdata * dd , struct hfi1_ctxtdata * rcd )
{
unsigned amt ;
u64 reg ;
if ( ! rcd - > rcvhdrq ) {
gfp_t gfp_flags ;
2018-06-21 00:42:31 +08:00
amt = rcvhdrq_size ( rcd ) ;
2015-07-31 03:17:43 +08:00
2017-11-06 22:38:52 +08:00
if ( rcd - > ctxt < dd - > first_dyn_alloc_ctxt | | rcd - > is_vnic )
2017-04-13 11:29:29 +08:00
gfp_flags = GFP_KERNEL ;
else
gfp_flags = GFP_USER ;
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
rcd - > rcvhdrq = dma_alloc_coherent ( & dd - > pcidev - > dev , amt ,
& rcd - > rcvhdrq_dma ,
gfp_flags | __GFP_COMP ) ;
2015-07-31 03:17:43 +08:00
if ( ! rcd - > rcvhdrq ) {
dd_dev_err ( dd ,
2016-02-15 12:21:52 +08:00
" attempt to allocate %d bytes for ctxt %u rcvhdrq failed \n " ,
amt , rcd - > ctxt ) ;
2015-07-31 03:17:43 +08:00
goto bail ;
}
2018-06-01 02:30:09 +08:00
if ( HFI1_CAP_KGET_MASK ( rcd - > flags , DMA_RTAIL ) | |
HFI1_CAP_UGET_MASK ( rcd - > flags , DMA_RTAIL ) ) {
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
rcd - > rcvhdrtail_kvaddr = dma_alloc_coherent ( & dd - > pcidev - > dev ,
PAGE_SIZE ,
& rcd - > rcvhdrqtailaddr_dma ,
gfp_flags ) ;
2015-07-31 03:17:43 +08:00
if ( ! rcd - > rcvhdrtail_kvaddr )
goto bail_free ;
}
}
/*
* These values are per - context :
* RcvHdrCnt
* RcvHdrEntSize
* RcvHdrSize
*/
reg = ( ( u64 ) ( rcd - > rcvhdrq_cnt > > HDRQ_SIZE_SHIFT )
& RCV_HDR_CNT_CNT_MASK )
< < RCV_HDR_CNT_CNT_SHIFT ;
write_kctxt_csr ( dd , rcd - > ctxt , RCV_HDR_CNT , reg ) ;
reg = ( encode_rcv_header_entry_size ( rcd - > rcvhdrqentsize )
& RCV_HDR_ENT_SIZE_ENT_SIZE_MASK )
< < RCV_HDR_ENT_SIZE_ENT_SIZE_SHIFT ;
write_kctxt_csr ( dd , rcd - > ctxt , RCV_HDR_ENT_SIZE , reg ) ;
2018-06-05 02:43:46 +08:00
reg = ( ( u64 ) DEFAULT_RCVHDRSIZE & RCV_HDR_SIZE_HDR_SIZE_MASK )
2015-07-31 03:17:43 +08:00
< < RCV_HDR_SIZE_HDR_SIZE_SHIFT ;
write_kctxt_csr ( dd , rcd - > ctxt , RCV_HDR_SIZE , reg ) ;
2015-11-10 08:18:20 +08:00
/*
* Program dummy tail address for every receive context
* before enabling any receive context
*/
write_kctxt_csr ( dd , rcd - > ctxt , RCV_HDR_TAIL_ADDR ,
2016-09-06 19:35:54 +08:00
dd - > rcvhdrtail_dummy_dma ) ;
2015-11-10 08:18:20 +08:00
2015-07-31 03:17:43 +08:00
return 0 ;
bail_free :
dd_dev_err ( dd ,
2016-02-15 12:21:52 +08:00
" attempt to allocate 1 page for ctxt %u rcvhdrqtailaddr failed \n " ,
rcd - > ctxt ) ;
2015-07-31 03:17:43 +08:00
dma_free_coherent ( & dd - > pcidev - > dev , amt , rcd - > rcvhdrq ,
2016-09-06 19:35:54 +08:00
rcd - > rcvhdrq_dma ) ;
2015-07-31 03:17:43 +08:00
rcd - > rcvhdrq = NULL ;
bail :
return - ENOMEM ;
}
/**
* allocate eager buffers , both kernel and user contexts .
* @ rcd : the context we are setting up .
*
* Allocate the eager TID buffers and program them into hip .
* They are no longer completely contiguous , we do multiple allocation
* calls . Otherwise we get the OOM code involved , by asking for too
* much per call , with disastrous results on some kernels .
*/
int hfi1_setup_eagerbufs ( struct hfi1_ctxtdata * rcd )
{
struct hfi1_devdata * dd = rcd - > dd ;
2018-06-21 00:43:14 +08:00
u32 max_entries , egrtop , alloced_bytes = 0 ;
2015-07-31 03:17:43 +08:00
gfp_t gfp_flags ;
2018-06-21 00:43:14 +08:00
u16 order , idx = 0 ;
2015-07-31 03:17:43 +08:00
int ret = 0 ;
u16 round_mtu = roundup_pow_of_two ( hfi1_max_mtu ) ;
/*
* GFP_USER , but without GFP_FS , so buffer cache can be
* coalesced ( we hope ) ; otherwise , even at order 4 ,
* heavy filesystem activity makes these fail , and we can
* use compound pages .
*/
2015-11-07 08:28:28 +08:00
gfp_flags = __GFP_RECLAIM | __GFP_IO | __GFP_COMP ;
2015-07-31 03:17:43 +08:00
/*
* The minimum size of the eager buffers is a groups of MTU - sized
* buffers .
* The global eager_buffer_size parameter is checked against the
* theoretical lower limit of the value . Here , we check against the
* MTU .
*/
if ( rcd - > egrbufs . size < ( round_mtu * dd - > rcv_entries . group_size ) )
rcd - > egrbufs . size = round_mtu * dd - > rcv_entries . group_size ;
/*
* If using one - pkt - per - egr - buffer , lower the eager buffer
* size to the max MTU ( page - aligned ) .
*/
if ( ! HFI1_CAP_KGET_MASK ( rcd - > flags , MULTI_PKT_EGR ) )
rcd - > egrbufs . rcvtid_size = round_mtu ;
/*
* Eager buffers sizes of 1 MB or less require smaller TID sizes
* to satisfy the " multiple of 8 RcvArray entries " requirement .
*/
if ( rcd - > egrbufs . size < = ( 1 < < 20 ) )
rcd - > egrbufs . rcvtid_size = max ( ( unsigned long ) round_mtu ,
rounddown_pow_of_two ( rcd - > egrbufs . size / 8 ) ) ;
while ( alloced_bytes < rcd - > egrbufs . size & &
rcd - > egrbufs . alloced < rcd - > egrbufs . count ) {
rcd - > egrbufs . buffers [ idx ] . addr =
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 16:23:09 +08:00
dma_alloc_coherent ( & dd - > pcidev - > dev ,
rcd - > egrbufs . rcvtid_size ,
& rcd - > egrbufs . buffers [ idx ] . dma ,
gfp_flags ) ;
2015-07-31 03:17:43 +08:00
if ( rcd - > egrbufs . buffers [ idx ] . addr ) {
rcd - > egrbufs . buffers [ idx ] . len =
rcd - > egrbufs . rcvtid_size ;
rcd - > egrbufs . rcvtids [ rcd - > egrbufs . alloced ] . addr =
rcd - > egrbufs . buffers [ idx ] . addr ;
2016-09-06 19:35:54 +08:00
rcd - > egrbufs . rcvtids [ rcd - > egrbufs . alloced ] . dma =
rcd - > egrbufs . buffers [ idx ] . dma ;
2015-07-31 03:17:43 +08:00
rcd - > egrbufs . alloced + + ;
alloced_bytes + = rcd - > egrbufs . rcvtid_size ;
idx + + ;
} else {
u32 new_size , i , j ;
u64 offset = 0 ;
/*
* Fail the eager buffer allocation if :
* - we are already using the lowest acceptable size
* - we are using one - pkt - per - egr - buffer ( this implies
* that we are accepting only one size )
*/
if ( rcd - > egrbufs . rcvtid_size = = round_mtu | |
! HFI1_CAP_KGET_MASK ( rcd - > flags , MULTI_PKT_EGR ) ) {
dd_dev_err ( dd , " ctxt%u: Failed to allocate eager buffers \n " ,
2016-02-15 12:21:52 +08:00
rcd - > ctxt ) ;
2017-05-04 20:14:28 +08:00
ret = - ENOMEM ;
2015-07-31 03:17:43 +08:00
goto bail_rcvegrbuf_phys ;
}
new_size = rcd - > egrbufs . rcvtid_size / 2 ;
/*
* If the first attempt to allocate memory failed , don ' t
* fail everything but continue with the next lower
* size .
*/
if ( idx = = 0 ) {
rcd - > egrbufs . rcvtid_size = new_size ;
continue ;
}
/*
* Re - partition already allocated buffers to a smaller
* size .
*/
rcd - > egrbufs . alloced = 0 ;
for ( i = 0 , j = 0 , offset = 0 ; j < idx ; i + + ) {
if ( i > = rcd - > egrbufs . count )
break ;
2016-09-06 19:35:54 +08:00
rcd - > egrbufs . rcvtids [ i ] . dma =
rcd - > egrbufs . buffers [ j ] . dma + offset ;
2015-07-31 03:17:43 +08:00
rcd - > egrbufs . rcvtids [ i ] . addr =
rcd - > egrbufs . buffers [ j ] . addr + offset ;
rcd - > egrbufs . alloced + + ;
2016-09-06 19:35:54 +08:00
if ( ( rcd - > egrbufs . buffers [ j ] . dma + offset +
2015-07-31 03:17:43 +08:00
new_size ) = =
2016-09-06 19:35:54 +08:00
( rcd - > egrbufs . buffers [ j ] . dma +
2015-07-31 03:17:43 +08:00
rcd - > egrbufs . buffers [ j ] . len ) ) {
j + + ;
offset = 0 ;
2016-02-15 12:22:00 +08:00
} else {
2015-07-31 03:17:43 +08:00
offset + = new_size ;
2016-02-15 12:22:00 +08:00
}
2015-07-31 03:17:43 +08:00
}
rcd - > egrbufs . rcvtid_size = new_size ;
}
}
rcd - > egrbufs . numbufs = idx ;
rcd - > egrbufs . size = alloced_bytes ;
2015-11-07 09:06:56 +08:00
hfi1_cdbg ( PROC ,
2019-03-28 07:50:50 +08:00
" ctxt%u: Alloced %u rcv tid entries @ %uKB, total %uKB \n " ,
2016-07-26 04:39:33 +08:00
rcd - > ctxt , rcd - > egrbufs . alloced ,
rcd - > egrbufs . rcvtid_size / 1024 , rcd - > egrbufs . size / 1024 ) ;
2015-11-07 09:06:56 +08:00
2015-07-31 03:17:43 +08:00
/*
* Set the contexts rcv array head update threshold to the closest
* power of 2 ( so we can use a mask instead of modulo ) below half
* the allocated entries .
*/
rcd - > egrbufs . threshold =
rounddown_pow_of_two ( rcd - > egrbufs . alloced / 2 ) ;
/*
* Compute the expected RcvArray entry base . This is done after
* allocating the eager buffers in order to maximize the
* expected RcvArray entries for the context .
*/
max_entries = rcd - > rcv_array_groups * dd - > rcv_entries . group_size ;
egrtop = roundup ( rcd - > egrbufs . alloced , dd - > rcv_entries . group_size ) ;
rcd - > expected_count = max_entries - egrtop ;
if ( rcd - > expected_count > MAX_TID_PAIR_ENTRIES * 2 )
rcd - > expected_count = MAX_TID_PAIR_ENTRIES * 2 ;
rcd - > expected_base = rcd - > eager_base + egrtop ;
2015-11-07 09:06:56 +08:00
hfi1_cdbg ( PROC , " ctxt%u: eager:%u, exp:%u, egrbase:%u, expbase:%u \n " ,
rcd - > ctxt , rcd - > egrbufs . alloced , rcd - > expected_count ,
rcd - > eager_base , rcd - > expected_base ) ;
2015-07-31 03:17:43 +08:00
if ( ! hfi1_rcvbuf_validate ( rcd - > egrbufs . rcvtid_size , PT_EAGER , & order ) ) {
2015-11-07 09:06:56 +08:00
hfi1_cdbg ( PROC ,
" ctxt%u: current Eager buffer size is invalid %u \n " ,
rcd - > ctxt , rcd - > egrbufs . rcvtid_size ) ;
2015-07-31 03:17:43 +08:00
ret = - EINVAL ;
2017-05-04 20:15:21 +08:00
goto bail_rcvegrbuf_phys ;
2015-07-31 03:17:43 +08:00
}
for ( idx = 0 ; idx < rcd - > egrbufs . alloced ; idx + + ) {
hfi1_put_tid ( dd , rcd - > eager_base + idx , PT_EAGER ,
2016-09-06 19:35:54 +08:00
rcd - > egrbufs . rcvtids [ idx ] . dma , order ) ;
2015-07-31 03:17:43 +08:00
cond_resched ( ) ;
}
2017-05-04 20:15:21 +08:00
return 0 ;
2015-07-31 03:17:43 +08:00
bail_rcvegrbuf_phys :
for ( idx = 0 ; idx < rcd - > egrbufs . alloced & &
2016-02-15 12:21:52 +08:00
rcd - > egrbufs . buffers [ idx ] . addr ;
2015-07-31 03:17:43 +08:00
idx + + ) {
dma_free_coherent ( & dd - > pcidev - > dev ,
rcd - > egrbufs . buffers [ idx ] . len ,
rcd - > egrbufs . buffers [ idx ] . addr ,
2016-09-06 19:35:54 +08:00
rcd - > egrbufs . buffers [ idx ] . dma ) ;
2015-07-31 03:17:43 +08:00
rcd - > egrbufs . buffers [ idx ] . addr = NULL ;
2016-09-06 19:35:54 +08:00
rcd - > egrbufs . buffers [ idx ] . dma = 0 ;
2015-07-31 03:17:43 +08:00
rcd - > egrbufs . buffers [ idx ] . len = 0 ;
}
2017-05-04 20:15:21 +08:00
2015-07-31 03:17:43 +08:00
return ret ;
}