License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
// SPDX-License-Identifier: GPL-2.0
2017-01-09 23:55:21 +08:00
/*
* Shared Memory Communications over RDMA ( SMC - R ) and RoCE
*
* Link Layer Control ( LLC )
*
* Copyright IBM Corp . 2016
*
* Author ( s ) : Klaus Wacker < Klaus . Wacker @ de . ibm . com >
* Ursula Braun < ubraun @ linux . vnet . ibm . com >
*/
# include <net/tcp.h>
# include <rdma/ib_verbs.h>
# include "smc.h"
# include "smc_core.h"
# include "smc_clc.h"
# include "smc_llc.h"
2018-03-01 20:51:26 +08:00
# define SMC_LLC_DATA_LEN 40
struct smc_llc_hdr {
struct smc_wr_rx_hdr common ;
u8 length ; /* 44 */
2018-03-01 20:51:32 +08:00
# if defined(__BIG_ENDIAN_BITFIELD)
u8 reserved : 4 ,
add_link_rej_rsn : 4 ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 add_link_rej_rsn : 4 ,
reserved : 4 ;
# endif
2018-03-01 20:51:26 +08:00
u8 flags ;
} ;
2018-03-01 20:51:31 +08:00
# define SMC_LLC_FLAG_NO_RMBE_EYEC 0x03
2018-03-01 20:51:26 +08:00
struct smc_llc_msg_confirm_link { /* type 0x01 */
struct smc_llc_hdr hd ;
u8 sender_mac [ ETH_ALEN ] ;
u8 sender_gid [ SMC_GID_SIZE ] ;
u8 sender_qp_num [ 3 ] ;
u8 link_num ;
u8 link_uid [ SMC_LGR_ID_SIZE ] ;
u8 max_links ;
u8 reserved [ 9 ] ;
} ;
2018-03-01 20:51:32 +08:00
# define SMC_LLC_FLAG_ADD_LNK_REJ 0x40
# define SMC_LLC_REJ_RSN_NO_ALT_PATH 1
# define SMC_LLC_ADD_LNK_MAX_LINKS 2
struct smc_llc_msg_add_link { /* type 0x02 */
struct smc_llc_hdr hd ;
u8 sender_mac [ ETH_ALEN ] ;
u8 reserved2 [ 2 ] ;
u8 sender_gid [ SMC_GID_SIZE ] ;
u8 sender_qp_num [ 3 ] ;
u8 link_num ;
2020-05-01 18:48:04 +08:00
# if defined(__BIG_ENDIAN_BITFIELD)
u8 reserved3 : 4 ,
qp_mtu : 4 ;
# elif defined(__LITTLE_ENDIAN_BITFIELD)
u8 qp_mtu : 4 ,
reserved3 : 4 ;
# endif
2018-03-01 20:51:32 +08:00
u8 initial_psn [ 3 ] ;
u8 reserved [ 8 ] ;
} ;
# define SMC_LLC_FLAG_DEL_LINK_ALL 0x40
# define SMC_LLC_FLAG_DEL_LINK_ORDERLY 0x20
struct smc_llc_msg_del_link { /* type 0x04 */
struct smc_llc_hdr hd ;
u8 link_num ;
__be32 reason ;
u8 reserved [ 35 ] ;
} __packed ; /* format defined in RFC7609 */
2018-03-01 20:51:29 +08:00
struct smc_llc_msg_test_link { /* type 0x07 */
struct smc_llc_hdr hd ;
u8 user_data [ 16 ] ;
u8 reserved [ 24 ] ;
} ;
2018-03-01 20:51:30 +08:00
struct smc_rmb_rtoken {
union {
u8 num_rkeys ; /* first rtoken byte of CONFIRM LINK msg */
/* is actually the num of rtokens, first */
/* rtoken is always for the current link */
u8 link_id ; /* link id of the rtoken */
} ;
__be32 rmb_key ;
__be64 rmb_vaddr ;
} __packed ; /* format defined in RFC7609 */
# define SMC_LLC_RKEYS_PER_MSG 3
struct smc_llc_msg_confirm_rkey { /* type 0x06 */
struct smc_llc_hdr hd ;
struct smc_rmb_rtoken rtoken [ SMC_LLC_RKEYS_PER_MSG ] ;
u8 reserved ;
} ;
# define SMC_LLC_DEL_RKEY_MAX 8
2020-04-30 21:55:48 +08:00
# define SMC_LLC_FLAG_RKEY_RETRY 0x10
2018-03-01 20:51:30 +08:00
# define SMC_LLC_FLAG_RKEY_NEG 0x20
struct smc_llc_msg_delete_rkey { /* type 0x09 */
struct smc_llc_hdr hd ;
u8 num_rkeys ;
u8 err_mask ;
u8 reserved [ 2 ] ;
__be32 rkey [ 8 ] ;
u8 reserved2 [ 4 ] ;
} ;
2018-03-01 20:51:26 +08:00
union smc_llc_msg {
struct smc_llc_msg_confirm_link confirm_link ;
2018-03-01 20:51:32 +08:00
struct smc_llc_msg_add_link add_link ;
struct smc_llc_msg_del_link delete_link ;
2018-03-01 20:51:30 +08:00
struct smc_llc_msg_confirm_rkey confirm_rkey ;
struct smc_llc_msg_delete_rkey delete_rkey ;
2018-03-01 20:51:29 +08:00
struct smc_llc_msg_test_link test_link ;
2018-03-01 20:51:26 +08:00
struct {
struct smc_llc_hdr hdr ;
u8 data [ SMC_LLC_DATA_LEN ] ;
} raw ;
} ;
# define SMC_LLC_FLAG_RESP 0x80
2020-04-29 23:10:46 +08:00
struct smc_llc_qentry {
struct list_head list ;
struct smc_link * link ;
union smc_llc_msg msg ;
} ;
2020-04-30 21:55:38 +08:00
struct smc_llc_qentry * smc_llc_flow_qentry_clr ( struct smc_llc_flow * flow )
{
struct smc_llc_qentry * qentry = flow - > qentry ;
flow - > qentry = NULL ;
return qentry ;
}
void smc_llc_flow_qentry_del ( struct smc_llc_flow * flow )
{
struct smc_llc_qentry * qentry ;
if ( flow - > qentry ) {
qentry = flow - > qentry ;
flow - > qentry = NULL ;
kfree ( qentry ) ;
}
}
static inline void smc_llc_flow_qentry_set ( struct smc_llc_flow * flow ,
struct smc_llc_qentry * qentry )
{
flow - > qentry = qentry ;
}
/* try to start a new llc flow, initiated by an incoming llc msg */
static bool smc_llc_flow_start ( struct smc_llc_flow * flow ,
struct smc_llc_qentry * qentry )
{
struct smc_link_group * lgr = qentry - > link - > lgr ;
spin_lock_bh ( & lgr - > llc_flow_lock ) ;
if ( flow - > type ) {
/* a flow is already active */
if ( ( qentry - > msg . raw . hdr . common . type = = SMC_LLC_ADD_LINK | |
qentry - > msg . raw . hdr . common . type = = SMC_LLC_DELETE_LINK ) & &
! lgr - > delayed_event ) {
lgr - > delayed_event = qentry ;
} else {
/* forget this llc request */
kfree ( qentry ) ;
}
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
return false ;
}
switch ( qentry - > msg . raw . hdr . common . type ) {
case SMC_LLC_ADD_LINK :
flow - > type = SMC_LLC_FLOW_ADD_LINK ;
break ;
case SMC_LLC_DELETE_LINK :
flow - > type = SMC_LLC_FLOW_DEL_LINK ;
break ;
case SMC_LLC_CONFIRM_RKEY :
case SMC_LLC_DELETE_RKEY :
flow - > type = SMC_LLC_FLOW_RKEY ;
break ;
default :
flow - > type = SMC_LLC_FLOW_NONE ;
}
if ( qentry = = lgr - > delayed_event )
lgr - > delayed_event = NULL ;
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
smc_llc_flow_qentry_set ( flow , qentry ) ;
return true ;
}
/* start a new local llc flow, wait till current flow finished */
int smc_llc_flow_initiate ( struct smc_link_group * lgr ,
enum smc_llc_flowtype type )
{
enum smc_llc_flowtype allowed_remote = SMC_LLC_FLOW_NONE ;
int rc ;
/* all flows except confirm_rkey and delete_rkey are exclusive,
* confirm / delete rkey flows can run concurrently ( local and remote )
*/
if ( type = = SMC_LLC_FLOW_RKEY )
allowed_remote = SMC_LLC_FLOW_RKEY ;
again :
if ( list_empty ( & lgr - > list ) )
return - ENODEV ;
spin_lock_bh ( & lgr - > llc_flow_lock ) ;
if ( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_NONE & &
( lgr - > llc_flow_rmt . type = = SMC_LLC_FLOW_NONE | |
lgr - > llc_flow_rmt . type = = allowed_remote ) ) {
lgr - > llc_flow_lcl . type = type ;
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
return 0 ;
}
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
rc = wait_event_interruptible_timeout ( lgr - > llc_waiter ,
( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_NONE & &
( lgr - > llc_flow_rmt . type = = SMC_LLC_FLOW_NONE | |
lgr - > llc_flow_rmt . type = = allowed_remote ) ) ,
SMC_LLC_WAIT_TIME ) ;
if ( ! rc )
return - ETIMEDOUT ;
goto again ;
}
/* finish the current llc flow */
void smc_llc_flow_stop ( struct smc_link_group * lgr , struct smc_llc_flow * flow )
{
spin_lock_bh ( & lgr - > llc_flow_lock ) ;
memset ( flow , 0 , sizeof ( * flow ) ) ;
flow - > type = SMC_LLC_FLOW_NONE ;
spin_unlock_bh ( & lgr - > llc_flow_lock ) ;
if ( ! list_empty ( & lgr - > list ) & & lgr - > delayed_event & &
flow = = & lgr - > llc_flow_lcl )
schedule_work ( & lgr - > llc_event_work ) ;
else
wake_up_interruptible ( & lgr - > llc_waiter ) ;
}
/* lnk is optional and used for early wakeup when link goes down, useful in
* cases where we wait for a response on the link after we sent a request
*/
struct smc_llc_qentry * smc_llc_wait ( struct smc_link_group * lgr ,
struct smc_link * lnk ,
int time_out , u8 exp_msg )
{
struct smc_llc_flow * flow = & lgr - > llc_flow_lcl ;
wait_event_interruptible_timeout ( lgr - > llc_waiter ,
( flow - > qentry | |
( lnk & & ! smc_link_usable ( lnk ) ) | |
list_empty ( & lgr - > list ) ) ,
time_out ) ;
if ( ! flow - > qentry | |
( lnk & & ! smc_link_usable ( lnk ) ) | | list_empty ( & lgr - > list ) ) {
smc_llc_flow_qentry_del ( flow ) ;
goto out ;
}
if ( exp_msg & & flow - > qentry - > msg . raw . hdr . common . type ! = exp_msg ) {
if ( exp_msg = = SMC_LLC_ADD_LINK & &
flow - > qentry - > msg . raw . hdr . common . type = =
SMC_LLC_DELETE_LINK ) {
/* flow_start will delay the unexpected msg */
smc_llc_flow_start ( & lgr - > llc_flow_lcl ,
smc_llc_flow_qentry_clr ( flow ) ) ;
return NULL ;
}
smc_llc_flow_qentry_del ( flow ) ;
}
out :
return flow - > qentry ;
}
2017-01-09 23:55:21 +08:00
/********************************** send *************************************/
struct smc_llc_tx_pend {
} ;
/* handler for send/transmission completion of an LLC msg */
static void smc_llc_tx_handler ( struct smc_wr_tx_pend_priv * pend ,
struct smc_link * link ,
enum ib_wc_status wc_status )
{
/* future work: handle wc_status error for recovery and failover */
}
/**
* smc_llc_add_pending_send ( ) - add LLC control message to pending WQE transmits
* @ link : Pointer to SMC link used for sending LLC control message .
* @ wr_buf : Out variable returning pointer to work request payload buffer .
* @ pend : Out variable returning pointer to private pending WR tracking .
* It ' s the context the transmit complete handler will get .
*
* Reserves and pre - fills an entry for a pending work request send / tx .
* Used by mid - level smc_llc_send_msg ( ) to prepare for later actual send / tx .
* Can sleep due to smc_get_ctrl_buf ( if not in softirq context ) .
*
* Return : 0 on success , otherwise an error value .
*/
static int smc_llc_add_pending_send ( struct smc_link * link ,
struct smc_wr_buf * * wr_buf ,
struct smc_wr_tx_pend_priv * * pend )
{
int rc ;
2019-02-04 20:44:44 +08:00
rc = smc_wr_tx_get_free_slot ( link , smc_llc_tx_handler , wr_buf , NULL ,
pend ) ;
2017-01-09 23:55:21 +08:00
if ( rc < 0 )
return rc ;
BUILD_BUG_ON_MSG (
sizeof ( union smc_llc_msg ) > SMC_WR_BUF_SIZE ,
" must increase SMC_WR_BUF_SIZE to at least sizeof(struct smc_llc_msg) " ) ;
BUILD_BUG_ON_MSG (
sizeof ( union smc_llc_msg ) ! = SMC_WR_TX_SIZE ,
" must adapt SMC_WR_TX_SIZE to sizeof(struct smc_llc_msg); if not all smc_wr upper layer protocols use the same message size any more, must start to set link->wr_tx_sges[i].length on each individual smc_wr_tx_send() " ) ;
BUILD_BUG_ON_MSG (
sizeof ( struct smc_llc_tx_pend ) > SMC_WR_TX_PEND_PRIV_SIZE ,
" must increase SMC_WR_TX_PEND_PRIV_SIZE to at least sizeof(struct smc_llc_tx_pend) " ) ;
return 0 ;
}
/* high-level API to send LLC confirm link */
2018-07-25 22:35:30 +08:00
int smc_llc_send_confirm_link ( struct smc_link * link ,
2017-01-09 23:55:21 +08:00
enum smc_llc_reqresp reqresp )
{
2018-07-23 19:53:10 +08:00
struct smc_link_group * lgr = smc_get_lgr ( link ) ;
2017-01-09 23:55:21 +08:00
struct smc_llc_msg_confirm_link * confllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
return rc ;
confllc = ( struct smc_llc_msg_confirm_link * ) wr_buf ;
memset ( confllc , 0 , sizeof ( * confllc ) ) ;
confllc - > hd . common . type = SMC_LLC_CONFIRM_LINK ;
confllc - > hd . length = sizeof ( struct smc_llc_msg_confirm_link ) ;
2018-03-01 20:51:31 +08:00
confllc - > hd . flags | = SMC_LLC_FLAG_NO_RMBE_EYEC ;
2017-01-09 23:55:21 +08:00
if ( reqresp = = SMC_LLC_RESP )
confllc - > hd . flags | = SMC_LLC_FLAG_RESP ;
2018-07-25 22:35:30 +08:00
memcpy ( confllc - > sender_mac , link - > smcibdev - > mac [ link - > ibport - 1 ] ,
ETH_ALEN ) ;
2018-07-25 22:35:31 +08:00
memcpy ( confllc - > sender_gid , link - > gid , SMC_GID_SIZE ) ;
2017-01-09 23:55:21 +08:00
hton24 ( confllc - > sender_qp_num , link - > roce_qp - > qp_num ) ;
2018-02-28 19:44:08 +08:00
confllc - > link_num = link - > link_id ;
2017-01-09 23:55:21 +08:00
memcpy ( confllc - > link_uid , lgr - > id , SMC_LGR_ID_SIZE ) ;
2018-03-01 20:51:32 +08:00
confllc - > max_links = SMC_LLC_ADD_LNK_MAX_LINKS ; /* enforce peer resp. */
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
return rc ;
}
2018-05-15 23:04:55 +08:00
/* send LLC confirm rkey request */
2020-04-30 21:55:44 +08:00
static int smc_llc_send_confirm_rkey ( struct smc_link * send_link ,
2018-05-15 23:04:55 +08:00
struct smc_buf_desc * rmb_desc )
{
struct smc_llc_msg_confirm_rkey * rkeyllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
2020-04-30 21:55:44 +08:00
struct smc_link * link ;
int i , rc , rtok_ix ;
2018-05-15 23:04:55 +08:00
2020-04-30 21:55:44 +08:00
rc = smc_llc_add_pending_send ( send_link , & wr_buf , & pend ) ;
2018-05-15 23:04:55 +08:00
if ( rc )
return rc ;
rkeyllc = ( struct smc_llc_msg_confirm_rkey * ) wr_buf ;
memset ( rkeyllc , 0 , sizeof ( * rkeyllc ) ) ;
rkeyllc - > hd . common . type = SMC_LLC_CONFIRM_RKEY ;
rkeyllc - > hd . length = sizeof ( struct smc_llc_msg_confirm_rkey ) ;
2020-04-30 21:55:44 +08:00
rtok_ix = 1 ;
for ( i = 0 ; i < SMC_LINKS_PER_LGR_MAX ; i + + ) {
link = & send_link - > lgr - > lnk [ i ] ;
if ( link - > state = = SMC_LNK_ACTIVE & & link ! = send_link ) {
rkeyllc - > rtoken [ rtok_ix ] . link_id = link - > link_id ;
rkeyllc - > rtoken [ rtok_ix ] . rmb_key =
htonl ( rmb_desc - > mr_rx [ link - > link_idx ] - > rkey ) ;
rkeyllc - > rtoken [ rtok_ix ] . rmb_vaddr = cpu_to_be64 (
( u64 ) sg_dma_address (
rmb_desc - > sgt [ link - > link_idx ] . sgl ) ) ;
rtok_ix + + ;
}
}
/* rkey of send_link is in rtoken[0] */
rkeyllc - > rtoken [ 0 ] . num_rkeys = rtok_ix - 1 ;
2018-05-15 23:04:55 +08:00
rkeyllc - > rtoken [ 0 ] . rmb_key =
2020-04-30 21:55:44 +08:00
htonl ( rmb_desc - > mr_rx [ send_link - > link_idx ] - > rkey ) ;
2018-05-15 23:04:55 +08:00
rkeyllc - > rtoken [ 0 ] . rmb_vaddr = cpu_to_be64 (
2020-04-30 21:55:44 +08:00
( u64 ) sg_dma_address ( rmb_desc - > sgt [ send_link - > link_idx ] . sgl ) ) ;
2018-05-15 23:04:55 +08:00
/* send llc message */
2020-04-30 21:55:44 +08:00
rc = smc_wr_tx_send ( send_link , pend ) ;
2018-05-15 23:04:55 +08:00
return rc ;
}
2018-11-22 17:26:42 +08:00
/* send LLC delete rkey request */
static int smc_llc_send_delete_rkey ( struct smc_link * link ,
struct smc_buf_desc * rmb_desc )
{
struct smc_llc_msg_delete_rkey * rkeyllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
return rc ;
rkeyllc = ( struct smc_llc_msg_delete_rkey * ) wr_buf ;
memset ( rkeyllc , 0 , sizeof ( * rkeyllc ) ) ;
rkeyllc - > hd . common . type = SMC_LLC_DELETE_RKEY ;
rkeyllc - > hd . length = sizeof ( struct smc_llc_msg_delete_rkey ) ;
rkeyllc - > num_rkeys = 1 ;
2020-04-29 23:10:40 +08:00
rkeyllc - > rkey [ 0 ] = htonl ( rmb_desc - > mr_rx [ link - > link_idx ] - > rkey ) ;
2018-11-22 17:26:42 +08:00
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
return rc ;
}
2018-03-01 20:51:32 +08:00
/* send ADD LINK request or response */
2018-07-25 22:35:31 +08:00
int smc_llc_send_add_link ( struct smc_link * link , u8 mac [ ] , u8 gid [ ] ,
2020-05-01 18:48:04 +08:00
struct smc_link * link_new ,
2018-03-01 20:51:32 +08:00
enum smc_llc_reqresp reqresp )
{
struct smc_llc_msg_add_link * addllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
return rc ;
addllc = ( struct smc_llc_msg_add_link * ) wr_buf ;
2020-05-01 18:48:04 +08:00
memset ( addllc , 0 , sizeof ( * addllc ) ) ;
addllc - > hd . common . type = SMC_LLC_ADD_LINK ;
addllc - > hd . length = sizeof ( struct smc_llc_msg_add_link ) ;
if ( reqresp = = SMC_LLC_RESP )
addllc - > hd . flags | = SMC_LLC_FLAG_RESP ;
memcpy ( addllc - > sender_mac , mac , ETH_ALEN ) ;
memcpy ( addllc - > sender_gid , gid , SMC_GID_SIZE ) ;
if ( link_new ) {
addllc - > link_num = link_new - > link_id ;
hton24 ( addllc - > sender_qp_num , link_new - > roce_qp - > qp_num ) ;
hton24 ( addllc - > initial_psn , link_new - > psn_initial ) ;
if ( reqresp = = SMC_LLC_REQ )
addllc - > qp_mtu = link_new - > path_mtu ;
else
addllc - > qp_mtu = min ( link_new - > path_mtu ,
link_new - > peer_mtu ) ;
}
2018-03-01 20:51:32 +08:00
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
return rc ;
}
/* send DELETE LINK request or response */
2020-05-01 18:48:04 +08:00
int smc_llc_send_delete_link ( struct smc_link * link , u8 link_del_id ,
enum smc_llc_reqresp reqresp , bool orderly ,
u32 reason )
2018-03-01 20:51:32 +08:00
{
struct smc_llc_msg_del_link * delllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
return rc ;
delllc = ( struct smc_llc_msg_del_link * ) wr_buf ;
2020-05-01 18:48:04 +08:00
memset ( delllc , 0 , sizeof ( * delllc ) ) ;
delllc - > hd . common . type = SMC_LLC_DELETE_LINK ;
delllc - > hd . length = sizeof ( struct smc_llc_msg_del_link ) ;
if ( reqresp = = SMC_LLC_RESP )
delllc - > hd . flags | = SMC_LLC_FLAG_RESP ;
if ( orderly )
delllc - > hd . flags | = SMC_LLC_FLAG_DEL_LINK_ORDERLY ;
if ( link_del_id )
delllc - > link_num = link_del_id ;
else
delllc - > hd . flags | = SMC_LLC_FLAG_DEL_LINK_ALL ;
delllc - > reason = htonl ( reason ) ;
2017-01-09 23:55:21 +08:00
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
return rc ;
}
2018-05-15 23:04:57 +08:00
/* send LLC test link request */
static int smc_llc_send_test_link ( struct smc_link * link , u8 user_data [ 16 ] )
2018-03-01 20:51:29 +08:00
{
struct smc_llc_msg_test_link * testllc ;
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
if ( rc )
return rc ;
testllc = ( struct smc_llc_msg_test_link * ) wr_buf ;
memset ( testllc , 0 , sizeof ( * testllc ) ) ;
testllc - > hd . common . type = SMC_LLC_TEST_LINK ;
testllc - > hd . length = sizeof ( struct smc_llc_msg_test_link ) ;
memcpy ( testllc - > user_data , user_data , sizeof ( testllc - > user_data ) ) ;
/* send llc message */
rc = smc_wr_tx_send ( link , pend ) ;
return rc ;
}
2020-04-29 23:10:46 +08:00
/* schedule an llc send on link, may wait for buffers */
static int smc_llc_send_message ( struct smc_link * link , void * llcbuf )
2018-03-01 20:51:30 +08:00
{
struct smc_wr_tx_pend_priv * pend ;
struct smc_wr_buf * wr_buf ;
int rc ;
2020-04-29 23:10:46 +08:00
if ( ! smc_link_usable ( link ) )
return - ENOLINK ;
rc = smc_llc_add_pending_send ( link , & wr_buf , & pend ) ;
2018-03-01 20:51:30 +08:00
if ( rc )
2020-04-29 23:10:46 +08:00
return rc ;
memcpy ( wr_buf , llcbuf , sizeof ( union smc_llc_msg ) ) ;
return smc_wr_tx_send ( link , pend ) ;
2018-03-01 20:51:30 +08:00
}
2017-01-09 23:55:21 +08:00
/********************************* receive ***********************************/
2018-03-01 20:51:32 +08:00
static void smc_llc_rx_delete_link ( struct smc_link * link ,
struct smc_llc_msg_del_link * llc )
{
2018-07-23 19:53:10 +08:00
struct smc_link_group * lgr = smc_get_lgr ( link ) ;
2018-03-01 20:51:32 +08:00
2020-04-29 23:10:47 +08:00
smc_lgr_forget ( lgr ) ;
if ( lgr - > role = = SMC_SERV ) {
/* client asks to delete this link, send request */
2020-05-01 18:48:04 +08:00
smc_llc_send_delete_link ( link , 0 , SMC_LLC_REQ , true ,
SMC_LLC_DEL_PROG_INIT_TERM ) ;
2018-03-01 20:51:32 +08:00
} else {
2020-04-29 23:10:47 +08:00
/* server requests to delete this link, send response */
2020-05-01 18:48:04 +08:00
smc_llc_send_delete_link ( link , 0 , SMC_LLC_RESP , true ,
SMC_LLC_DEL_PROG_INIT_TERM ) ;
2018-03-01 20:51:32 +08:00
}
2020-04-29 23:10:47 +08:00
smc_lgr_terminate_sched ( lgr ) ;
2018-03-01 20:51:32 +08:00
}
2020-04-30 21:55:48 +08:00
/* process a confirm_rkey request from peer, remote flow */
static void smc_llc_rmt_conf_rkey ( struct smc_link_group * lgr )
2018-03-01 20:51:30 +08:00
{
2020-04-30 21:55:48 +08:00
struct smc_llc_msg_confirm_rkey * llc ;
struct smc_llc_qentry * qentry ;
struct smc_link * link ;
int num_entries ;
int rk_idx ;
int i ;
qentry = lgr - > llc_flow_rmt . qentry ;
llc = & qentry - > msg . confirm_rkey ;
link = qentry - > link ;
num_entries = llc - > rtoken [ 0 ] . num_rkeys ;
/* first rkey entry is for receiving link */
rk_idx = smc_rtoken_add ( link ,
llc - > rtoken [ 0 ] . rmb_vaddr ,
llc - > rtoken [ 0 ] . rmb_key ) ;
if ( rk_idx < 0 )
goto out_err ;
for ( i = 1 ; i < = min_t ( u8 , num_entries , SMC_LLC_RKEYS_PER_MSG - 1 ) ; i + + )
smc_rtoken_set2 ( lgr , rk_idx , llc - > rtoken [ i ] . link_id ,
llc - > rtoken [ i ] . rmb_vaddr ,
llc - > rtoken [ i ] . rmb_key ) ;
/* max links is 3 so there is no need to support conf_rkey_cont msgs */
goto out ;
out_err :
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_NEG ;
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_RETRY ;
out :
2020-04-29 23:10:47 +08:00
llc - > hd . flags | = SMC_LLC_FLAG_RESP ;
2020-04-30 21:55:48 +08:00
smc_llc_send_message ( link , & qentry - > msg ) ;
smc_llc_flow_qentry_del ( & lgr - > llc_flow_rmt ) ;
2018-03-01 20:51:30 +08:00
}
2020-04-30 21:55:49 +08:00
/* process a delete_rkey request from peer, remote flow */
static void smc_llc_rmt_delete_rkey ( struct smc_link_group * lgr )
2018-03-01 20:51:30 +08:00
{
2020-04-30 21:55:49 +08:00
struct smc_llc_msg_delete_rkey * llc ;
struct smc_llc_qentry * qentry ;
struct smc_link * link ;
2018-03-01 20:51:30 +08:00
u8 err_mask = 0 ;
int i , max ;
2020-04-30 21:55:49 +08:00
qentry = lgr - > llc_flow_rmt . qentry ;
llc = & qentry - > msg . delete_rkey ;
link = qentry - > link ;
2020-04-29 23:10:47 +08:00
max = min_t ( u8 , llc - > num_rkeys , SMC_LLC_DEL_RKEY_MAX ) ;
for ( i = 0 ; i < max ; i + + ) {
if ( smc_rtoken_delete ( link , llc - > rkey [ i ] ) )
err_mask | = 1 < < ( SMC_LLC_DEL_RKEY_MAX - 1 - i ) ;
}
if ( err_mask ) {
llc - > hd . flags | = SMC_LLC_FLAG_RKEY_NEG ;
llc - > err_mask = err_mask ;
2018-03-01 20:51:30 +08:00
}
2020-04-30 21:55:49 +08:00
llc - > hd . flags | = SMC_LLC_FLAG_RESP ;
smc_llc_send_message ( link , & qentry - > msg ) ;
smc_llc_flow_qentry_del ( & lgr - > llc_flow_rmt ) ;
}
2020-04-29 23:10:47 +08:00
2020-04-29 23:10:46 +08:00
/* flush the llc event queue */
2020-04-29 23:10:49 +08:00
static void smc_llc_event_flush ( struct smc_link_group * lgr )
2017-01-09 23:55:21 +08:00
{
2020-04-29 23:10:46 +08:00
struct smc_llc_qentry * qentry , * q ;
spin_lock_bh ( & lgr - > llc_event_q_lock ) ;
list_for_each_entry_safe ( qentry , q , & lgr - > llc_event_q , list ) {
list_del_init ( & qentry - > list ) ;
kfree ( qentry ) ;
}
spin_unlock_bh ( & lgr - > llc_event_q_lock ) ;
}
static void smc_llc_event_handler ( struct smc_llc_qentry * qentry )
{
union smc_llc_msg * llc = & qentry - > msg ;
struct smc_link * link = qentry - > link ;
2020-04-30 21:55:43 +08:00
struct smc_link_group * lgr = link - > lgr ;
2017-01-09 23:55:21 +08:00
2020-04-29 23:10:43 +08:00
if ( ! smc_link_usable ( link ) )
2020-04-29 23:10:46 +08:00
goto out ;
2018-03-01 20:51:29 +08:00
switch ( llc - > raw . hdr . common . type ) {
case SMC_LLC_TEST_LINK :
2020-04-30 21:55:46 +08:00
llc - > test_link . hd . flags | = SMC_LLC_FLAG_RESP ;
smc_llc_send_message ( link , llc ) ;
2018-03-01 20:51:29 +08:00
break ;
2018-03-01 20:51:32 +08:00
case SMC_LLC_ADD_LINK :
2020-04-30 21:55:43 +08:00
if ( list_empty ( & lgr - > list ) )
goto out ; /* lgr is terminating */
if ( lgr - > role = = SMC_CLNT ) {
if ( lgr - > llc_flow_lcl . type = = SMC_LLC_FLOW_ADD_LINK ) {
/* a flow is waiting for this message */
smc_llc_flow_qentry_set ( & lgr - > llc_flow_lcl ,
qentry ) ;
wake_up_interruptible ( & lgr - > llc_waiter ) ;
} else if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl ,
qentry ) ) {
/* tbd: schedule_work(&lgr->llc_add_link_work); */
}
} else if ( smc_llc_flow_start ( & lgr - > llc_flow_lcl , qentry ) ) {
/* as smc server, handle client suggestion */
/* tbd: schedule_work(&lgr->llc_add_link_work); */
}
return ;
case SMC_LLC_CONFIRM_LINK :
if ( lgr - > llc_flow_lcl . type ! = SMC_LLC_FLOW_NONE ) {
/* a flow is waiting for this message */
smc_llc_flow_qentry_set ( & lgr - > llc_flow_lcl , qentry ) ;
wake_up_interruptible ( & lgr - > llc_waiter ) ;
return ;
}
2018-03-01 20:51:32 +08:00
break ;
case SMC_LLC_DELETE_LINK :
smc_llc_rx_delete_link ( link , & llc - > delete_link ) ;
break ;
2018-03-01 20:51:30 +08:00
case SMC_LLC_CONFIRM_RKEY :
2020-04-30 21:55:48 +08:00
/* new request from remote, assign to remote flow */
if ( smc_llc_flow_start ( & lgr - > llc_flow_rmt , qentry ) ) {
/* process here, does not wait for more llc msgs */
smc_llc_rmt_conf_rkey ( lgr ) ;
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_rmt ) ;
}
return ;
2018-03-01 20:51:30 +08:00
case SMC_LLC_CONFIRM_RKEY_CONT :
2020-04-30 21:55:50 +08:00
/* not used because max links is 3, and 3 rkeys fit into
* one CONFIRM_RKEY message
*/
2018-03-01 20:51:30 +08:00
break ;
case SMC_LLC_DELETE_RKEY :
2020-04-30 21:55:49 +08:00
/* new request from remote, assign to remote flow */
if ( smc_llc_flow_start ( & lgr - > llc_flow_rmt , qentry ) ) {
/* process here, does not wait for more llc msgs */
smc_llc_rmt_delete_rkey ( lgr ) ;
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_rmt ) ;
}
return ;
2018-03-01 20:51:29 +08:00
}
2020-04-29 23:10:46 +08:00
out :
kfree ( qentry ) ;
}
/* worker to process llc messages on the event queue */
static void smc_llc_event_work ( struct work_struct * work )
{
struct smc_link_group * lgr = container_of ( work , struct smc_link_group ,
llc_event_work ) ;
struct smc_llc_qentry * qentry ;
2020-04-30 21:55:38 +08:00
if ( ! lgr - > llc_flow_lcl . type & & lgr - > delayed_event ) {
if ( smc_link_usable ( lgr - > delayed_event - > link ) ) {
smc_llc_event_handler ( lgr - > delayed_event ) ;
} else {
qentry = lgr - > delayed_event ;
lgr - > delayed_event = NULL ;
kfree ( qentry ) ;
}
}
2020-04-29 23:10:46 +08:00
again :
spin_lock_bh ( & lgr - > llc_event_q_lock ) ;
if ( ! list_empty ( & lgr - > llc_event_q ) ) {
qentry = list_first_entry ( & lgr - > llc_event_q ,
struct smc_llc_qentry , list ) ;
list_del_init ( & qentry - > list ) ;
spin_unlock_bh ( & lgr - > llc_event_q_lock ) ;
smc_llc_event_handler ( qentry ) ;
goto again ;
}
spin_unlock_bh ( & lgr - > llc_event_q_lock ) ;
}
2020-04-29 23:10:47 +08:00
/* process llc responses in tasklet context */
2020-04-30 21:55:39 +08:00
static void smc_llc_rx_response ( struct smc_link * link ,
struct smc_llc_qentry * qentry )
2020-04-29 23:10:47 +08:00
{
2020-04-30 21:55:39 +08:00
u8 llc_type = qentry - > msg . raw . hdr . common . type ;
2020-04-29 23:10:47 +08:00
2020-04-30 21:55:39 +08:00
switch ( llc_type ) {
2020-04-29 23:10:47 +08:00
case SMC_LLC_TEST_LINK :
if ( link - > state = = SMC_LNK_ACTIVE )
complete ( & link - > llc_testlink_resp ) ;
break ;
case SMC_LLC_ADD_LINK :
2020-04-30 21:55:42 +08:00
case SMC_LLC_CONFIRM_LINK :
2020-04-30 21:55:44 +08:00
case SMC_LLC_CONFIRM_RKEY :
2020-04-30 21:55:45 +08:00
case SMC_LLC_DELETE_RKEY :
2020-04-30 21:55:42 +08:00
/* assign responses to the local flow, we requested them */
smc_llc_flow_qentry_set ( & link - > lgr - > llc_flow_lcl , qentry ) ;
wake_up_interruptible ( & link - > lgr - > llc_waiter ) ;
return ;
2020-04-29 23:10:47 +08:00
case SMC_LLC_DELETE_LINK :
if ( link - > lgr - > role = = SMC_SERV )
smc_lgr_schedule_free_work_fast ( link - > lgr ) ;
break ;
case SMC_LLC_CONFIRM_RKEY_CONT :
2020-04-30 21:55:50 +08:00
/* not used because max links is 3 */
2020-04-29 23:10:47 +08:00
break ;
}
2020-04-30 21:55:39 +08:00
kfree ( qentry ) ;
2020-04-29 23:10:47 +08:00
}
2020-04-30 21:55:39 +08:00
static void smc_llc_enqueue ( struct smc_link * link , union smc_llc_msg * llc )
2020-04-29 23:10:46 +08:00
{
struct smc_link_group * lgr = link - > lgr ;
struct smc_llc_qentry * qentry ;
unsigned long flags ;
qentry = kmalloc ( sizeof ( * qentry ) , GFP_ATOMIC ) ;
if ( ! qentry )
return ;
qentry - > link = link ;
INIT_LIST_HEAD ( & qentry - > list ) ;
memcpy ( & qentry - > msg , llc , sizeof ( union smc_llc_msg ) ) ;
2020-04-30 21:55:39 +08:00
/* process responses immediately */
if ( llc - > raw . hdr . flags & SMC_LLC_FLAG_RESP ) {
smc_llc_rx_response ( link , qentry ) ;
return ;
}
/* add requests to event queue */
2020-04-29 23:10:46 +08:00
spin_lock_irqsave ( & lgr - > llc_event_q_lock , flags ) ;
list_add_tail ( & qentry - > list , & lgr - > llc_event_q ) ;
spin_unlock_irqrestore ( & lgr - > llc_event_q_lock , flags ) ;
schedule_work ( & link - > lgr - > llc_event_work ) ;
2017-01-09 23:55:21 +08:00
}
2020-04-30 21:55:39 +08:00
/* copy received msg and add it to the event queue */
static void smc_llc_rx_handler ( struct ib_wc * wc , void * buf )
{
struct smc_link * link = ( struct smc_link * ) wc - > qp - > qp_context ;
union smc_llc_msg * llc = buf ;
if ( wc - > byte_len < sizeof ( * llc ) )
return ; /* short message */
if ( llc - > raw . hdr . length ! = sizeof ( * llc ) )
return ; /* invalid message */
smc_llc_enqueue ( link , llc ) ;
}
2018-05-15 23:04:55 +08:00
/***************************** worker, utils *********************************/
2018-05-02 22:56:44 +08:00
static void smc_llc_testlink_work ( struct work_struct * work )
{
struct smc_link * link = container_of ( to_delayed_work ( work ) ,
struct smc_link , llc_testlink_wrk ) ;
unsigned long next_interval ;
unsigned long expire_time ;
u8 user_data [ 16 ] = { 0 } ;
int rc ;
if ( link - > state ! = SMC_LNK_ACTIVE )
return ; /* don't reschedule worker */
expire_time = link - > wr_rx_tstamp + link - > llc_testlink_time ;
if ( time_is_after_jiffies ( expire_time ) ) {
next_interval = expire_time - jiffies ;
goto out ;
}
reinit_completion ( & link - > llc_testlink_resp ) ;
2018-05-15 23:04:57 +08:00
smc_llc_send_test_link ( link , user_data ) ;
2018-05-02 22:56:44 +08:00
/* receive TEST LINK response over RoCE fabric */
rc = wait_for_completion_interruptible_timeout ( & link - > llc_testlink_resp ,
SMC_LLC_WAIT_TIME ) ;
2020-04-29 23:10:44 +08:00
if ( link - > state ! = SMC_LNK_ACTIVE )
return ; /* link state changed */
2018-05-02 22:56:44 +08:00
if ( rc < = 0 ) {
2020-02-17 23:24:54 +08:00
smc_lgr_terminate_sched ( smc_get_lgr ( link ) ) ;
2018-05-02 22:56:44 +08:00
return ;
}
next_interval = link - > llc_testlink_time ;
out :
2020-04-29 23:10:44 +08:00
schedule_delayed_work ( & link - > llc_testlink_wrk , next_interval ) ;
2018-05-02 22:56:44 +08:00
}
2020-04-29 23:10:49 +08:00
void smc_llc_lgr_init ( struct smc_link_group * lgr , struct smc_sock * smc )
{
struct net * net = sock_net ( smc - > clcsock - > sk ) ;
INIT_WORK ( & lgr - > llc_event_work , smc_llc_event_work ) ;
INIT_LIST_HEAD ( & lgr - > llc_event_q ) ;
spin_lock_init ( & lgr - > llc_event_q_lock ) ;
2020-04-30 21:55:38 +08:00
spin_lock_init ( & lgr - > llc_flow_lock ) ;
init_waitqueue_head ( & lgr - > llc_waiter ) ;
2020-04-29 23:10:49 +08:00
lgr - > llc_testlink_time = net - > ipv4 . sysctl_tcp_keepalive_time ;
}
/* called after lgr was removed from lgr_list */
void smc_llc_lgr_clear ( struct smc_link_group * lgr )
{
smc_llc_event_flush ( lgr ) ;
2020-04-30 21:55:38 +08:00
wake_up_interruptible_all ( & lgr - > llc_waiter ) ;
2020-04-29 23:10:49 +08:00
cancel_work_sync ( & lgr - > llc_event_work ) ;
2020-04-30 21:55:38 +08:00
if ( lgr - > delayed_event ) {
kfree ( lgr - > delayed_event ) ;
lgr - > delayed_event = NULL ;
}
2020-04-29 23:10:49 +08:00
}
2018-05-15 23:04:59 +08:00
int smc_llc_link_init ( struct smc_link * link )
2018-05-02 22:56:44 +08:00
{
init_completion ( & link - > llc_testlink_resp ) ;
INIT_DELAYED_WORK ( & link - > llc_testlink_wrk , smc_llc_testlink_work ) ;
2018-05-15 23:04:59 +08:00
return 0 ;
2018-05-15 23:04:58 +08:00
}
2020-04-29 23:10:49 +08:00
void smc_llc_link_active ( struct smc_link * link )
2018-05-15 23:04:58 +08:00
{
2018-05-02 22:56:44 +08:00
link - > state = SMC_LNK_ACTIVE ;
2020-04-29 23:10:49 +08:00
if ( link - > lgr - > llc_testlink_time ) {
link - > llc_testlink_time = link - > lgr - > llc_testlink_time * HZ ;
2020-04-29 23:10:44 +08:00
schedule_delayed_work ( & link - > llc_testlink_wrk ,
link - > llc_testlink_time ) ;
2018-05-02 22:56:44 +08:00
}
}
/* called in worker context */
2018-05-15 23:04:59 +08:00
void smc_llc_link_clear ( struct smc_link * link )
2018-05-02 22:56:44 +08:00
{
2020-04-29 23:10:45 +08:00
complete ( & link - > llc_testlink_resp ) ;
cancel_delayed_work_sync ( & link - > llc_testlink_wrk ) ;
smc_wr_wakeup_reg_wait ( link ) ;
smc_wr_wakeup_tx_wait ( link ) ;
2018-05-02 22:56:44 +08:00
}
2020-04-30 21:55:44 +08:00
/* register a new rtoken at the remote peer (for all links) */
int smc_llc_do_confirm_rkey ( struct smc_link * send_link ,
2018-05-15 23:04:55 +08:00
struct smc_buf_desc * rmb_desc )
{
2020-04-30 21:55:44 +08:00
struct smc_link_group * lgr = send_link - > lgr ;
struct smc_llc_qentry * qentry = NULL ;
int rc = 0 ;
2018-05-15 23:04:55 +08:00
2020-04-30 21:55:44 +08:00
rc = smc_llc_flow_initiate ( lgr , SMC_LLC_FLOW_RKEY ) ;
2018-11-22 17:26:41 +08:00
if ( rc )
return rc ;
2020-04-30 21:55:44 +08:00
rc = smc_llc_send_confirm_rkey ( send_link , rmb_desc ) ;
if ( rc )
goto out ;
2018-05-15 23:04:55 +08:00
/* receive CONFIRM RKEY response from server over RoCE fabric */
2020-04-30 21:55:44 +08:00
qentry = smc_llc_wait ( lgr , send_link , SMC_LLC_WAIT_TIME ,
SMC_LLC_CONFIRM_RKEY ) ;
if ( ! qentry | | ( qentry - > msg . raw . hdr . flags & SMC_LLC_FLAG_RKEY_NEG ) )
rc = - EFAULT ;
out :
if ( qentry )
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_lcl ) ;
return rc ;
2018-05-15 23:04:55 +08:00
}
2018-11-22 17:26:42 +08:00
/* unregister an rtoken at the remote peer */
2020-04-30 21:55:45 +08:00
int smc_llc_do_delete_rkey ( struct smc_link_group * lgr ,
2018-11-22 17:26:42 +08:00
struct smc_buf_desc * rmb_desc )
{
2020-04-30 21:55:45 +08:00
struct smc_llc_qentry * qentry = NULL ;
struct smc_link * send_link ;
2019-11-14 20:02:47 +08:00
int rc = 0 ;
2018-11-22 17:26:42 +08:00
2020-04-30 21:55:45 +08:00
send_link = smc_llc_usable_link ( lgr ) ;
if ( ! send_link )
return - ENOLINK ;
rc = smc_llc_flow_initiate ( lgr , SMC_LLC_FLOW_RKEY ) ;
if ( rc )
return rc ;
/* protected by llc_flow control */
rc = smc_llc_send_delete_rkey ( send_link , rmb_desc ) ;
2018-11-22 17:26:42 +08:00
if ( rc )
goto out ;
/* receive DELETE RKEY response from server over RoCE fabric */
2020-04-30 21:55:45 +08:00
qentry = smc_llc_wait ( lgr , send_link , SMC_LLC_WAIT_TIME ,
SMC_LLC_DELETE_RKEY ) ;
if ( ! qentry | | ( qentry - > msg . raw . hdr . flags & SMC_LLC_FLAG_RKEY_NEG ) )
2018-11-22 17:26:42 +08:00
rc = - EFAULT ;
out :
2020-04-30 21:55:45 +08:00
if ( qentry )
smc_llc_flow_qentry_del ( & lgr - > llc_flow_lcl ) ;
smc_llc_flow_stop ( lgr , & lgr - > llc_flow_lcl ) ;
2018-11-22 17:26:42 +08:00
return rc ;
}
2020-04-30 21:55:41 +08:00
/* evaluate confirm link request or response */
int smc_llc_eval_conf_link ( struct smc_llc_qentry * qentry ,
enum smc_llc_reqresp type )
{
if ( type = = SMC_LLC_REQ ) /* SMC server assigns link_id */
qentry - > link - > link_id = qentry - > msg . confirm_link . link_num ;
if ( ! ( qentry - > msg . raw . hdr . flags & SMC_LLC_FLAG_NO_RMBE_EYEC ) )
return - ENOTSUPP ;
return 0 ;
}
2017-01-09 23:55:21 +08:00
/***************************** init, exit, misc ******************************/
static struct smc_wr_rx_handler smc_llc_rx_handlers [ ] = {
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_LINK
} ,
2018-03-01 20:51:29 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_TEST_LINK
} ,
2018-03-01 20:51:32 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_ADD_LINK
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_DELETE_LINK
} ,
2018-03-01 20:51:30 +08:00
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_RKEY
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_CONFIRM_RKEY_CONT
} ,
{
. handler = smc_llc_rx_handler ,
. type = SMC_LLC_DELETE_RKEY
} ,
2017-01-09 23:55:21 +08:00
{
. handler = NULL ,
}
} ;
int __init smc_llc_init ( void )
{
struct smc_wr_rx_handler * handler ;
int rc = 0 ;
for ( handler = smc_llc_rx_handlers ; handler - > handler ; handler + + ) {
INIT_HLIST_NODE ( & handler - > list ) ;
rc = smc_wr_rx_register_handler ( handler ) ;
if ( rc )
break ;
}
return rc ;
}