]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
net/smc: add function to get link group from link
authorStefan Raspl <raspl@linux.ibm.com>
Mon, 23 Jul 2018 11:53:10 +0000 (13:53 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 Jul 2018 17:57:14 +0000 (10:57 -0700)
Replace a frequently used construct with a more readable variant,
reducing the code. Also might come handy when we start to support
more than a single per link group.

Signed-off-by: Stefan Raspl <raspl@linux.ibm.com>
Signed-off-by: Ursula Braun <ubraun@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/smc/smc_cdc.c
net/smc/smc_core.h
net/smc/smc_ib.c
net/smc/smc_llc.c
net/smc/smc_wr.c

index f3a1497953ee791402d4a36c2e7511d720470c46..a7af2289cdff9804392850cf55b3c76451aeb653 100644 (file)
@@ -365,7 +365,7 @@ static void smc_cdc_rx_handler(struct ib_wc *wc, void *buf)
                return; /* invalid message */
 
        /* lookup connection */
-       lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
+       lgr = smc_get_lgr(link);
        read_lock_bh(&lgr->conns_lock);
        conn = smc_lgr_find_conn(ntohl(cdc->token), lgr);
        read_unlock_bh(&lgr->conns_lock);
index 8b47e0168fc3d56518707bb8d38debe470665902..8807865483bbd311a4653967112d22d32b631bf4 100644 (file)
@@ -266,4 +266,9 @@ int smc_conn_create(struct smc_sock *smc, bool is_smcd, int srv_first_contact,
                    u64 peer_gid);
 void smcd_conn_free(struct smc_connection *conn);
 void smc_core_exit(void);
+
+static inline struct smc_link_group *smc_get_lgr(struct smc_link *link)
+{
+       return container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
+}
 #endif
index 36de2fd76170be0774d547268c8350be8804b8bb..4706ab7092a9e9e2de2df15219d6056422eadb3c 100644 (file)
@@ -112,8 +112,7 @@ int smc_ib_modify_qp_reset(struct smc_link *lnk)
 
 int smc_ib_ready_link(struct smc_link *lnk)
 {
-       struct smc_link_group *lgr =
-               container_of(lnk, struct smc_link_group, lnk[0]);
+       struct smc_link_group *lgr = smc_get_lgr(lnk);
        int rc = 0;
 
        rc = smc_ib_modify_qp_init(lnk);
index 5800a6b43d830018ffc91a4272190508e8c9f233..b7944aa1ffc33f177e243703d733882f80a61055 100644 (file)
@@ -186,8 +186,7 @@ int smc_llc_send_confirm_link(struct smc_link *link, u8 mac[],
                              union ib_gid *gid,
                              enum smc_llc_reqresp reqresp)
 {
-       struct smc_link_group *lgr = container_of(link, struct smc_link_group,
-                                                 lnk[SMC_SINGLE_LINK]);
+       struct smc_link_group *lgr = smc_get_lgr(link);
        struct smc_llc_msg_confirm_link *confllc;
        struct smc_wr_tx_pend_priv *pend;
        struct smc_wr_buf *wr_buf;
@@ -381,11 +380,9 @@ static int smc_llc_send_message(struct smc_link *link, void *llcbuf, int llclen)
 static void smc_llc_rx_confirm_link(struct smc_link *link,
                                    struct smc_llc_msg_confirm_link *llc)
 {
-       struct smc_link_group *lgr;
+       struct smc_link_group *lgr = smc_get_lgr(link);
        int conf_rc;
 
-       lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
-
        /* RMBE eyecatchers are not supported */
        if (llc->hd.flags & SMC_LLC_FLAG_NO_RMBE_EYEC)
                conf_rc = 0;
@@ -411,8 +408,7 @@ static void smc_llc_rx_confirm_link(struct smc_link *link,
 static void smc_llc_rx_add_link(struct smc_link *link,
                                struct smc_llc_msg_add_link *llc)
 {
-       struct smc_link_group *lgr = container_of(link, struct smc_link_group,
-                                                 lnk[SMC_SINGLE_LINK]);
+       struct smc_link_group *lgr = smc_get_lgr(link);
 
        if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
                if (link->state == SMC_LNK_ACTIVATING)
@@ -442,8 +438,7 @@ static void smc_llc_rx_add_link(struct smc_link *link,
 static void smc_llc_rx_delete_link(struct smc_link *link,
                                   struct smc_llc_msg_del_link *llc)
 {
-       struct smc_link_group *lgr = container_of(link, struct smc_link_group,
-                                                 lnk[SMC_SINGLE_LINK]);
+       struct smc_link_group *lgr = smc_get_lgr(link);
 
        if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
                if (lgr->role == SMC_SERV)
@@ -476,17 +471,14 @@ static void smc_llc_rx_test_link(struct smc_link *link,
 static void smc_llc_rx_confirm_rkey(struct smc_link *link,
                                    struct smc_llc_msg_confirm_rkey *llc)
 {
-       struct smc_link_group *lgr;
        int rc;
 
-       lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
-
        if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
                link->llc_confirm_rkey_rc = llc->hd.flags &
                                            SMC_LLC_FLAG_RKEY_NEG;
                complete(&link->llc_confirm_rkey);
        } else {
-               rc = smc_rtoken_add(lgr,
+               rc = smc_rtoken_add(smc_get_lgr(link),
                                    llc->rtoken[0].rmb_vaddr,
                                    llc->rtoken[0].rmb_key);
 
@@ -514,18 +506,15 @@ static void smc_llc_rx_confirm_rkey_cont(struct smc_link *link,
 static void smc_llc_rx_delete_rkey(struct smc_link *link,
                                   struct smc_llc_msg_delete_rkey *llc)
 {
-       struct smc_link_group *lgr;
        u8 err_mask = 0;
        int i, max;
 
-       lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
-
        if (llc->hd.flags & SMC_LLC_FLAG_RESP) {
                /* unused as long as we don't send this type of msg */
        } else {
                max = min_t(u8, llc->num_rkeys, SMC_LLC_DEL_RKEY_MAX);
                for (i = 0; i < max; i++) {
-                       if (smc_rtoken_delete(lgr, llc->rkey[i]))
+                       if (smc_rtoken_delete(smc_get_lgr(link), llc->rkey[i]))
                                err_mask |= 1 << (SMC_LLC_DEL_RKEY_MAX - 1 - i);
                }
 
@@ -583,12 +572,10 @@ 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;
-       struct smc_link_group *lgr;
        unsigned long expire_time;
        u8 user_data[16] = { 0 };
        int rc;
 
-       lgr = container_of(link, struct smc_link_group, lnk[SMC_SINGLE_LINK]);
        if (link->state != SMC_LNK_ACTIVE)
                return;         /* don't reschedule worker */
        expire_time = link->wr_rx_tstamp + link->llc_testlink_time;
@@ -602,7 +589,7 @@ static void smc_llc_testlink_work(struct work_struct *work)
        rc = wait_for_completion_interruptible_timeout(&link->llc_testlink_resp,
                                                       SMC_LLC_WAIT_TIME);
        if (rc <= 0) {
-               smc_lgr_terminate(lgr);
+               smc_lgr_terminate(smc_get_lgr(link));
                return;
        }
        next_interval = link->llc_testlink_time;
@@ -613,8 +600,7 @@ out:
 
 int smc_llc_link_init(struct smc_link *link)
 {
-       struct smc_link_group *lgr = container_of(link, struct smc_link_group,
-                                                 lnk[SMC_SINGLE_LINK]);
+       struct smc_link_group *lgr = smc_get_lgr(link);
        link->llc_wq = alloc_ordered_workqueue("llc_wq-%x:%x)", WQ_MEM_RECLAIM,
                                               *((u32 *)lgr->id),
                                               link->link_id);
index dbd2605d19627b0f91731767f3d0d8e0c166f454..b6df69756bef6967616f6acaa4def86ad79e8fac 100644 (file)
@@ -92,8 +92,6 @@ static inline void smc_wr_tx_process_cqe(struct ib_wc *wc)
        if (!test_and_clear_bit(pnd_snd_idx, link->wr_tx_mask))
                return;
        if (wc->status) {
-               struct smc_link_group *lgr;
-
                for_each_set_bit(i, link->wr_tx_mask, link->wr_tx_cnt) {
                        /* clear full struct smc_wr_tx_pend including .priv */
                        memset(&link->wr_tx_pends[i], 0,
@@ -103,9 +101,7 @@ static inline void smc_wr_tx_process_cqe(struct ib_wc *wc)
                        clear_bit(i, link->wr_tx_mask);
                }
                /* terminate connections of this link group abnormally */
-               lgr = container_of(link, struct smc_link_group,
-                                  lnk[SMC_SINGLE_LINK]);
-               smc_lgr_terminate(lgr);
+               smc_lgr_terminate(smc_get_lgr(link));
        }
        if (pnd_snd.handler)
                pnd_snd.handler(&pnd_snd.priv, link, wc->status);
@@ -188,8 +184,7 @@ int smc_wr_tx_get_free_slot(struct smc_link *link,
        } else {
                struct smc_link_group *lgr;
 
-               lgr = container_of(link, struct smc_link_group,
-                                  lnk[SMC_SINGLE_LINK]);
+               lgr = smc_get_lgr(link);
                rc = wait_event_timeout(
                        link->wr_tx_wait,
                        list_empty(&lgr->list) || /* lgr terminated */
@@ -250,12 +245,8 @@ int smc_wr_tx_send(struct smc_link *link, struct smc_wr_tx_pend_priv *priv)
        rc = ib_post_send(link->roce_qp, &link->wr_tx_ibs[pend->idx],
                          &failed_wr);
        if (rc) {
-               struct smc_link_group *lgr =
-                       container_of(link, struct smc_link_group,
-                                    lnk[SMC_SINGLE_LINK]);
-
                smc_wr_tx_put_slot(link, priv);
-               smc_lgr_terminate(lgr);
+               smc_lgr_terminate(smc_get_lgr(link));
        }
        return rc;
 }
@@ -283,11 +274,7 @@ int smc_wr_reg_send(struct smc_link *link, struct ib_mr *mr)
                                              SMC_WR_REG_MR_WAIT_TIME);
        if (!rc) {
                /* timeout - terminate connections */
-               struct smc_link_group *lgr;
-
-               lgr = container_of(link, struct smc_link_group,
-                                  lnk[SMC_SINGLE_LINK]);
-               smc_lgr_terminate(lgr);
+               smc_lgr_terminate(smc_get_lgr(link));
                return -EPIPE;
        }
        if (rc == -ERESTARTSYS)
@@ -380,8 +367,6 @@ static inline void smc_wr_rx_process_cqes(struct ib_wc wc[], int num)
                        smc_wr_rx_demultiplex(&wc[i]);
                        smc_wr_rx_post(link); /* refill WR RX */
                } else {
-                       struct smc_link_group *lgr;
-
                        /* handle status errors */
                        switch (wc[i].status) {
                        case IB_WC_RETRY_EXC_ERR:
@@ -390,9 +375,7 @@ static inline void smc_wr_rx_process_cqes(struct ib_wc wc[], int num)
                                /* terminate connections of this link group
                                 * abnormally
                                 */
-                               lgr = container_of(link, struct smc_link_group,
-                                                  lnk[SMC_SINGLE_LINK]);
-                               smc_lgr_terminate(lgr);
+                               smc_lgr_terminate(smc_get_lgr(link));
                                break;
                        default:
                                smc_wr_rx_post(link); /* refill WR RX */