diff options
Diffstat (limited to 'net/smc/smc_core.c')
-rw-r--r-- | net/smc/smc_core.c | 1973 |
1 files changed, 1973 insertions, 0 deletions
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c new file mode 100644 index 000000000..bf485a201 --- /dev/null +++ b/net/smc/smc_core.c | |||
@@ -0,0 +1,1973 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE | ||
4 | * | ||
5 | * Basic Transport Functions exploiting Infiniband API | ||
6 | * | ||
7 | * Copyright IBM Corp. 2016 | ||
8 | * | ||
9 | * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> | ||
10 | */ | ||
11 | |||
12 | #include <linux/socket.h> | ||
13 | #include <linux/if_vlan.h> | ||
14 | #include <linux/random.h> | ||
15 | #include <linux/workqueue.h> | ||
16 | #include <linux/wait.h> | ||
17 | #include <linux/reboot.h> | ||
18 | #include <linux/mutex.h> | ||
19 | #include <net/tcp.h> | ||
20 | #include <net/sock.h> | ||
21 | #include <rdma/ib_verbs.h> | ||
22 | #include <rdma/ib_cache.h> | ||
23 | |||
24 | #include "smc.h" | ||
25 | #include "smc_clc.h" | ||
26 | #include "smc_core.h" | ||
27 | #include "smc_ib.h" | ||
28 | #include "smc_wr.h" | ||
29 | #include "smc_llc.h" | ||
30 | #include "smc_cdc.h" | ||
31 | #include "smc_close.h" | ||
32 | #include "smc_ism.h" | ||
33 | |||
34 | #define SMC_LGR_NUM_INCR 256 | ||
35 | #define SMC_LGR_FREE_DELAY_SERV (600 * HZ) | ||
36 | #define SMC_LGR_FREE_DELAY_CLNT (SMC_LGR_FREE_DELAY_SERV + 10 * HZ) | ||
37 | |||
38 | static struct smc_lgr_list smc_lgr_list = { /* established link groups */ | ||
39 | .lock = __SPIN_LOCK_UNLOCKED(smc_lgr_list.lock), | ||
40 | .list = LIST_HEAD_INIT(smc_lgr_list.list), | ||
41 | .num = 0, | ||
42 | }; | ||
43 | |||
44 | static atomic_t lgr_cnt = ATOMIC_INIT(0); /* number of existing link groups */ | ||
45 | static DECLARE_WAIT_QUEUE_HEAD(lgrs_deleted); | ||
46 | |||
47 | static void smc_buf_free(struct smc_link_group *lgr, bool is_rmb, | ||
48 | struct smc_buf_desc *buf_desc); | ||
49 | static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft); | ||
50 | |||
51 | static void smc_link_down_work(struct work_struct *work); | ||
52 | |||
53 | /* return head of link group list and its lock for a given link group */ | ||
54 | static inline struct list_head *smc_lgr_list_head(struct smc_link_group *lgr, | ||
55 | spinlock_t **lgr_lock) | ||
56 | { | ||
57 | if (lgr->is_smcd) { | ||
58 | *lgr_lock = &lgr->smcd->lgr_lock; | ||
59 | return &lgr->smcd->lgr_list; | ||
60 | } | ||
61 | |||
62 | *lgr_lock = &smc_lgr_list.lock; | ||
63 | return &smc_lgr_list.list; | ||
64 | } | ||
65 | |||
66 | static void smc_lgr_schedule_free_work(struct smc_link_group *lgr) | ||
67 | { | ||
68 | /* client link group creation always follows the server link group | ||
69 | * creation. For client use a somewhat higher removal delay time, | ||
70 | * otherwise there is a risk of out-of-sync link groups. | ||
71 | */ | ||
72 | if (!lgr->freeing) { | ||
73 | mod_delayed_work(system_wq, &lgr->free_work, | ||
74 | (!lgr->is_smcd && lgr->role == SMC_CLNT) ? | ||
75 | SMC_LGR_FREE_DELAY_CLNT : | ||
76 | SMC_LGR_FREE_DELAY_SERV); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | /* Register connection's alert token in our lookup structure. | ||
81 | * To use rbtrees we have to implement our own insert core. | ||
82 | * Requires @conns_lock | ||
83 | * @smc connection to register | ||
84 | * Returns 0 on success, != otherwise. | ||
85 | */ | ||
86 | static void smc_lgr_add_alert_token(struct smc_connection *conn) | ||
87 | { | ||
88 | struct rb_node **link, *parent = NULL; | ||
89 | u32 token = conn->alert_token_local; | ||
90 | |||
91 | link = &conn->lgr->conns_all.rb_node; | ||
92 | while (*link) { | ||
93 | struct smc_connection *cur = rb_entry(*link, | ||
94 | struct smc_connection, alert_node); | ||
95 | |||
96 | parent = *link; | ||
97 | if (cur->alert_token_local > token) | ||
98 | link = &parent->rb_left; | ||
99 | else | ||
100 | link = &parent->rb_right; | ||
101 | } | ||
102 | /* Put the new node there */ | ||
103 | rb_link_node(&conn->alert_node, parent, link); | ||
104 | rb_insert_color(&conn->alert_node, &conn->lgr->conns_all); | ||
105 | } | ||
106 | |||
107 | /* assign an SMC-R link to the connection */ | ||
108 | static int smcr_lgr_conn_assign_link(struct smc_connection *conn, bool first) | ||
109 | { | ||
110 | enum smc_link_state expected = first ? SMC_LNK_ACTIVATING : | ||
111 | SMC_LNK_ACTIVE; | ||
112 | int i, j; | ||
113 | |||
114 | /* do link balancing */ | ||
115 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
116 | struct smc_link *lnk = &conn->lgr->lnk[i]; | ||
117 | |||
118 | if (lnk->state != expected || lnk->link_is_asym) | ||
119 | continue; | ||
120 | if (conn->lgr->role == SMC_CLNT) { | ||
121 | conn->lnk = lnk; /* temporary, SMC server assigns link*/ | ||
122 | break; | ||
123 | } | ||
124 | if (conn->lgr->conns_num % 2) { | ||
125 | for (j = i + 1; j < SMC_LINKS_PER_LGR_MAX; j++) { | ||
126 | struct smc_link *lnk2; | ||
127 | |||
128 | lnk2 = &conn->lgr->lnk[j]; | ||
129 | if (lnk2->state == expected && | ||
130 | !lnk2->link_is_asym) { | ||
131 | conn->lnk = lnk2; | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | if (!conn->lnk) | ||
137 | conn->lnk = lnk; | ||
138 | break; | ||
139 | } | ||
140 | if (!conn->lnk) | ||
141 | return SMC_CLC_DECL_NOACTLINK; | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | /* Register connection in link group by assigning an alert token | ||
146 | * registered in a search tree. | ||
147 | * Requires @conns_lock | ||
148 | * Note that '0' is a reserved value and not assigned. | ||
149 | */ | ||
150 | static int smc_lgr_register_conn(struct smc_connection *conn, bool first) | ||
151 | { | ||
152 | struct smc_sock *smc = container_of(conn, struct smc_sock, conn); | ||
153 | static atomic_t nexttoken = ATOMIC_INIT(0); | ||
154 | int rc; | ||
155 | |||
156 | if (!conn->lgr->is_smcd) { | ||
157 | rc = smcr_lgr_conn_assign_link(conn, first); | ||
158 | if (rc) | ||
159 | return rc; | ||
160 | } | ||
161 | /* find a new alert_token_local value not yet used by some connection | ||
162 | * in this link group | ||
163 | */ | ||
164 | sock_hold(&smc->sk); /* sock_put in smc_lgr_unregister_conn() */ | ||
165 | while (!conn->alert_token_local) { | ||
166 | conn->alert_token_local = atomic_inc_return(&nexttoken); | ||
167 | if (smc_lgr_find_conn(conn->alert_token_local, conn->lgr)) | ||
168 | conn->alert_token_local = 0; | ||
169 | } | ||
170 | smc_lgr_add_alert_token(conn); | ||
171 | conn->lgr->conns_num++; | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | /* Unregister connection and reset the alert token of the given connection< | ||
176 | */ | ||
177 | static void __smc_lgr_unregister_conn(struct smc_connection *conn) | ||
178 | { | ||
179 | struct smc_sock *smc = container_of(conn, struct smc_sock, conn); | ||
180 | struct smc_link_group *lgr = conn->lgr; | ||
181 | |||
182 | rb_erase(&conn->alert_node, &lgr->conns_all); | ||
183 | lgr->conns_num--; | ||
184 | conn->alert_token_local = 0; | ||
185 | sock_put(&smc->sk); /* sock_hold in smc_lgr_register_conn() */ | ||
186 | } | ||
187 | |||
188 | /* Unregister connection from lgr | ||
189 | */ | ||
190 | static void smc_lgr_unregister_conn(struct smc_connection *conn) | ||
191 | { | ||
192 | struct smc_link_group *lgr = conn->lgr; | ||
193 | |||
194 | if (!lgr) | ||
195 | return; | ||
196 | write_lock_bh(&lgr->conns_lock); | ||
197 | if (conn->alert_token_local) { | ||
198 | __smc_lgr_unregister_conn(conn); | ||
199 | } | ||
200 | write_unlock_bh(&lgr->conns_lock); | ||
201 | conn->lgr = NULL; | ||
202 | } | ||
203 | |||
204 | void smc_lgr_cleanup_early(struct smc_connection *conn) | ||
205 | { | ||
206 | struct smc_link_group *lgr = conn->lgr; | ||
207 | spinlock_t *lgr_lock; | ||
208 | |||
209 | if (!lgr) | ||
210 | return; | ||
211 | |||
212 | smc_conn_free(conn); | ||
213 | smc_lgr_list_head(lgr, &lgr_lock); | ||
214 | spin_lock_bh(lgr_lock); | ||
215 | /* do not use this link group for new connections */ | ||
216 | if (!list_empty(&lgr->list)) | ||
217 | list_del_init(&lgr->list); | ||
218 | spin_unlock_bh(lgr_lock); | ||
219 | __smc_lgr_terminate(lgr, true); | ||
220 | } | ||
221 | |||
222 | static void smcr_lgr_link_deactivate_all(struct smc_link_group *lgr) | ||
223 | { | ||
224 | int i; | ||
225 | |||
226 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
227 | struct smc_link *lnk = &lgr->lnk[i]; | ||
228 | |||
229 | if (smc_link_sendable(lnk)) | ||
230 | lnk->state = SMC_LNK_INACTIVE; | ||
231 | } | ||
232 | wake_up_all(&lgr->llc_msg_waiter); | ||
233 | wake_up_all(&lgr->llc_flow_waiter); | ||
234 | } | ||
235 | |||
236 | static void smc_lgr_free(struct smc_link_group *lgr); | ||
237 | |||
238 | static void smc_lgr_free_work(struct work_struct *work) | ||
239 | { | ||
240 | struct smc_link_group *lgr = container_of(to_delayed_work(work), | ||
241 | struct smc_link_group, | ||
242 | free_work); | ||
243 | spinlock_t *lgr_lock; | ||
244 | bool conns; | ||
245 | |||
246 | smc_lgr_list_head(lgr, &lgr_lock); | ||
247 | spin_lock_bh(lgr_lock); | ||
248 | if (lgr->freeing) { | ||
249 | spin_unlock_bh(lgr_lock); | ||
250 | return; | ||
251 | } | ||
252 | read_lock_bh(&lgr->conns_lock); | ||
253 | conns = RB_EMPTY_ROOT(&lgr->conns_all); | ||
254 | read_unlock_bh(&lgr->conns_lock); | ||
255 | if (!conns) { /* number of lgr connections is no longer zero */ | ||
256 | spin_unlock_bh(lgr_lock); | ||
257 | return; | ||
258 | } | ||
259 | list_del_init(&lgr->list); /* remove from smc_lgr_list */ | ||
260 | lgr->freeing = 1; /* this instance does the freeing, no new schedule */ | ||
261 | spin_unlock_bh(lgr_lock); | ||
262 | cancel_delayed_work(&lgr->free_work); | ||
263 | |||
264 | if (!lgr->is_smcd && !lgr->terminating) | ||
265 | smc_llc_send_link_delete_all(lgr, true, | ||
266 | SMC_LLC_DEL_PROG_INIT_TERM); | ||
267 | if (lgr->is_smcd && !lgr->terminating) | ||
268 | smc_ism_signal_shutdown(lgr); | ||
269 | if (!lgr->is_smcd) | ||
270 | smcr_lgr_link_deactivate_all(lgr); | ||
271 | smc_lgr_free(lgr); | ||
272 | } | ||
273 | |||
274 | static void smc_lgr_terminate_work(struct work_struct *work) | ||
275 | { | ||
276 | struct smc_link_group *lgr = container_of(work, struct smc_link_group, | ||
277 | terminate_work); | ||
278 | |||
279 | __smc_lgr_terminate(lgr, true); | ||
280 | } | ||
281 | |||
282 | /* return next unique link id for the lgr */ | ||
283 | static u8 smcr_next_link_id(struct smc_link_group *lgr) | ||
284 | { | ||
285 | u8 link_id; | ||
286 | int i; | ||
287 | |||
288 | while (1) { | ||
289 | again: | ||
290 | link_id = ++lgr->next_link_id; | ||
291 | if (!link_id) /* skip zero as link_id */ | ||
292 | link_id = ++lgr->next_link_id; | ||
293 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
294 | if (smc_link_usable(&lgr->lnk[i]) && | ||
295 | lgr->lnk[i].link_id == link_id) | ||
296 | goto again; | ||
297 | } | ||
298 | break; | ||
299 | } | ||
300 | return link_id; | ||
301 | } | ||
302 | |||
303 | int smcr_link_init(struct smc_link_group *lgr, struct smc_link *lnk, | ||
304 | u8 link_idx, struct smc_init_info *ini) | ||
305 | { | ||
306 | u8 rndvec[3]; | ||
307 | int rc; | ||
308 | |||
309 | get_device(&ini->ib_dev->ibdev->dev); | ||
310 | atomic_inc(&ini->ib_dev->lnk_cnt); | ||
311 | lnk->link_id = smcr_next_link_id(lgr); | ||
312 | lnk->lgr = lgr; | ||
313 | lnk->link_idx = link_idx; | ||
314 | lnk->smcibdev = ini->ib_dev; | ||
315 | lnk->ibport = ini->ib_port; | ||
316 | lnk->path_mtu = ini->ib_dev->pattr[ini->ib_port - 1].active_mtu; | ||
317 | smc_llc_link_set_uid(lnk); | ||
318 | INIT_WORK(&lnk->link_down_wrk, smc_link_down_work); | ||
319 | if (!ini->ib_dev->initialized) { | ||
320 | rc = (int)smc_ib_setup_per_ibdev(ini->ib_dev); | ||
321 | if (rc) | ||
322 | goto out; | ||
323 | } | ||
324 | get_random_bytes(rndvec, sizeof(rndvec)); | ||
325 | lnk->psn_initial = rndvec[0] + (rndvec[1] << 8) + | ||
326 | (rndvec[2] << 16); | ||
327 | rc = smc_ib_determine_gid(lnk->smcibdev, lnk->ibport, | ||
328 | ini->vlan_id, lnk->gid, &lnk->sgid_index); | ||
329 | if (rc) | ||
330 | goto out; | ||
331 | rc = smc_llc_link_init(lnk); | ||
332 | if (rc) | ||
333 | goto out; | ||
334 | rc = smc_wr_alloc_link_mem(lnk); | ||
335 | if (rc) | ||
336 | goto clear_llc_lnk; | ||
337 | rc = smc_ib_create_protection_domain(lnk); | ||
338 | if (rc) | ||
339 | goto free_link_mem; | ||
340 | rc = smc_ib_create_queue_pair(lnk); | ||
341 | if (rc) | ||
342 | goto dealloc_pd; | ||
343 | rc = smc_wr_create_link(lnk); | ||
344 | if (rc) | ||
345 | goto destroy_qp; | ||
346 | lnk->state = SMC_LNK_ACTIVATING; | ||
347 | return 0; | ||
348 | |||
349 | destroy_qp: | ||
350 | smc_ib_destroy_queue_pair(lnk); | ||
351 | dealloc_pd: | ||
352 | smc_ib_dealloc_protection_domain(lnk); | ||
353 | free_link_mem: | ||
354 | smc_wr_free_link_mem(lnk); | ||
355 | clear_llc_lnk: | ||
356 | smc_llc_link_clear(lnk, false); | ||
357 | out: | ||
358 | put_device(&ini->ib_dev->ibdev->dev); | ||
359 | memset(lnk, 0, sizeof(struct smc_link)); | ||
360 | lnk->state = SMC_LNK_UNUSED; | ||
361 | if (!atomic_dec_return(&ini->ib_dev->lnk_cnt)) | ||
362 | wake_up(&ini->ib_dev->lnks_deleted); | ||
363 | return rc; | ||
364 | } | ||
365 | |||
366 | /* create a new SMC link group */ | ||
367 | static int smc_lgr_create(struct smc_sock *smc, struct smc_init_info *ini) | ||
368 | { | ||
369 | struct smc_link_group *lgr; | ||
370 | struct list_head *lgr_list; | ||
371 | struct smc_link *lnk; | ||
372 | spinlock_t *lgr_lock; | ||
373 | u8 link_idx; | ||
374 | int rc = 0; | ||
375 | int i; | ||
376 | |||
377 | if (ini->is_smcd && ini->vlan_id) { | ||
378 | if (smc_ism_get_vlan(ini->ism_dev[ini->ism_selected], | ||
379 | ini->vlan_id)) { | ||
380 | rc = SMC_CLC_DECL_ISMVLANERR; | ||
381 | goto out; | ||
382 | } | ||
383 | } | ||
384 | |||
385 | lgr = kzalloc(sizeof(*lgr), GFP_KERNEL); | ||
386 | if (!lgr) { | ||
387 | rc = SMC_CLC_DECL_MEM; | ||
388 | goto ism_put_vlan; | ||
389 | } | ||
390 | lgr->tx_wq = alloc_workqueue("smc_tx_wq-%*phN", 0, 0, | ||
391 | SMC_LGR_ID_SIZE, &lgr->id); | ||
392 | if (!lgr->tx_wq) { | ||
393 | rc = -ENOMEM; | ||
394 | goto free_lgr; | ||
395 | } | ||
396 | lgr->is_smcd = ini->is_smcd; | ||
397 | lgr->sync_err = 0; | ||
398 | lgr->terminating = 0; | ||
399 | lgr->freeing = 0; | ||
400 | lgr->vlan_id = ini->vlan_id; | ||
401 | mutex_init(&lgr->sndbufs_lock); | ||
402 | mutex_init(&lgr->rmbs_lock); | ||
403 | rwlock_init(&lgr->conns_lock); | ||
404 | for (i = 0; i < SMC_RMBE_SIZES; i++) { | ||
405 | INIT_LIST_HEAD(&lgr->sndbufs[i]); | ||
406 | INIT_LIST_HEAD(&lgr->rmbs[i]); | ||
407 | } | ||
408 | lgr->next_link_id = 0; | ||
409 | smc_lgr_list.num += SMC_LGR_NUM_INCR; | ||
410 | memcpy(&lgr->id, (u8 *)&smc_lgr_list.num, SMC_LGR_ID_SIZE); | ||
411 | INIT_DELAYED_WORK(&lgr->free_work, smc_lgr_free_work); | ||
412 | INIT_WORK(&lgr->terminate_work, smc_lgr_terminate_work); | ||
413 | lgr->conns_all = RB_ROOT; | ||
414 | if (ini->is_smcd) { | ||
415 | /* SMC-D specific settings */ | ||
416 | get_device(&ini->ism_dev[ini->ism_selected]->dev); | ||
417 | lgr->peer_gid = ini->ism_peer_gid[ini->ism_selected]; | ||
418 | lgr->smcd = ini->ism_dev[ini->ism_selected]; | ||
419 | lgr_list = &ini->ism_dev[ini->ism_selected]->lgr_list; | ||
420 | lgr_lock = &lgr->smcd->lgr_lock; | ||
421 | lgr->smc_version = ini->smcd_version; | ||
422 | lgr->peer_shutdown = 0; | ||
423 | atomic_inc(&ini->ism_dev[ini->ism_selected]->lgr_cnt); | ||
424 | } else { | ||
425 | /* SMC-R specific settings */ | ||
426 | lgr->role = smc->listen_smc ? SMC_SERV : SMC_CLNT; | ||
427 | memcpy(lgr->peer_systemid, ini->ib_lcl->id_for_peer, | ||
428 | SMC_SYSTEMID_LEN); | ||
429 | memcpy(lgr->pnet_id, ini->ib_dev->pnetid[ini->ib_port - 1], | ||
430 | SMC_MAX_PNETID_LEN); | ||
431 | smc_llc_lgr_init(lgr, smc); | ||
432 | |||
433 | link_idx = SMC_SINGLE_LINK; | ||
434 | lnk = &lgr->lnk[link_idx]; | ||
435 | rc = smcr_link_init(lgr, lnk, link_idx, ini); | ||
436 | if (rc) | ||
437 | goto free_wq; | ||
438 | lgr_list = &smc_lgr_list.list; | ||
439 | lgr_lock = &smc_lgr_list.lock; | ||
440 | atomic_inc(&lgr_cnt); | ||
441 | } | ||
442 | smc->conn.lgr = lgr; | ||
443 | spin_lock_bh(lgr_lock); | ||
444 | list_add_tail(&lgr->list, lgr_list); | ||
445 | spin_unlock_bh(lgr_lock); | ||
446 | return 0; | ||
447 | |||
448 | free_wq: | ||
449 | destroy_workqueue(lgr->tx_wq); | ||
450 | free_lgr: | ||
451 | kfree(lgr); | ||
452 | ism_put_vlan: | ||
453 | if (ini->is_smcd && ini->vlan_id) | ||
454 | smc_ism_put_vlan(ini->ism_dev[ini->ism_selected], ini->vlan_id); | ||
455 | out: | ||
456 | if (rc < 0) { | ||
457 | if (rc == -ENOMEM) | ||
458 | rc = SMC_CLC_DECL_MEM; | ||
459 | else | ||
460 | rc = SMC_CLC_DECL_INTERR; | ||
461 | } | ||
462 | return rc; | ||
463 | } | ||
464 | |||
465 | static int smc_write_space(struct smc_connection *conn) | ||
466 | { | ||
467 | int buffer_len = conn->peer_rmbe_size; | ||
468 | union smc_host_cursor prod; | ||
469 | union smc_host_cursor cons; | ||
470 | int space; | ||
471 | |||
472 | smc_curs_copy(&prod, &conn->local_tx_ctrl.prod, conn); | ||
473 | smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn); | ||
474 | /* determine rx_buf space */ | ||
475 | space = buffer_len - smc_curs_diff(buffer_len, &cons, &prod); | ||
476 | return space; | ||
477 | } | ||
478 | |||
479 | static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend, | ||
480 | struct smc_wr_buf *wr_buf) | ||
481 | { | ||
482 | struct smc_connection *conn = &smc->conn; | ||
483 | union smc_host_cursor cons, fin; | ||
484 | int rc = 0; | ||
485 | int diff; | ||
486 | |||
487 | smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn); | ||
488 | smc_curs_copy(&fin, &conn->local_tx_ctrl_fin, conn); | ||
489 | /* set prod cursor to old state, enforce tx_rdma_writes() */ | ||
490 | smc_curs_copy(&conn->local_tx_ctrl.prod, &fin, conn); | ||
491 | smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn); | ||
492 | |||
493 | if (smc_curs_comp(conn->peer_rmbe_size, &cons, &fin) < 0) { | ||
494 | /* cons cursor advanced more than fin, and prod was set | ||
495 | * fin above, so now prod is smaller than cons. Fix that. | ||
496 | */ | ||
497 | diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons); | ||
498 | smc_curs_add(conn->sndbuf_desc->len, | ||
499 | &conn->tx_curs_sent, diff); | ||
500 | smc_curs_add(conn->sndbuf_desc->len, | ||
501 | &conn->tx_curs_fin, diff); | ||
502 | |||
503 | smp_mb__before_atomic(); | ||
504 | atomic_add(diff, &conn->sndbuf_space); | ||
505 | smp_mb__after_atomic(); | ||
506 | |||
507 | smc_curs_add(conn->peer_rmbe_size, | ||
508 | &conn->local_tx_ctrl.prod, diff); | ||
509 | smc_curs_add(conn->peer_rmbe_size, | ||
510 | &conn->local_tx_ctrl_fin, diff); | ||
511 | } | ||
512 | /* recalculate, value is used by tx_rdma_writes() */ | ||
513 | atomic_set(&smc->conn.peer_rmbe_space, smc_write_space(conn)); | ||
514 | |||
515 | if (smc->sk.sk_state != SMC_INIT && | ||
516 | smc->sk.sk_state != SMC_CLOSED) { | ||
517 | rc = smcr_cdc_msg_send_validation(conn, pend, wr_buf); | ||
518 | if (!rc) { | ||
519 | queue_delayed_work(conn->lgr->tx_wq, &conn->tx_work, 0); | ||
520 | smc->sk.sk_data_ready(&smc->sk); | ||
521 | } | ||
522 | } else { | ||
523 | smc_wr_tx_put_slot(conn->lnk, | ||
524 | (struct smc_wr_tx_pend_priv *)pend); | ||
525 | } | ||
526 | return rc; | ||
527 | } | ||
528 | |||
529 | struct smc_link *smc_switch_conns(struct smc_link_group *lgr, | ||
530 | struct smc_link *from_lnk, bool is_dev_err) | ||
531 | { | ||
532 | struct smc_link *to_lnk = NULL; | ||
533 | struct smc_cdc_tx_pend *pend; | ||
534 | struct smc_connection *conn; | ||
535 | struct smc_wr_buf *wr_buf; | ||
536 | struct smc_sock *smc; | ||
537 | struct rb_node *node; | ||
538 | int i, rc = 0; | ||
539 | |||
540 | /* link is inactive, wake up tx waiters */ | ||
541 | smc_wr_wakeup_tx_wait(from_lnk); | ||
542 | |||
543 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
544 | if (!smc_link_active(&lgr->lnk[i]) || i == from_lnk->link_idx) | ||
545 | continue; | ||
546 | if (is_dev_err && from_lnk->smcibdev == lgr->lnk[i].smcibdev && | ||
547 | from_lnk->ibport == lgr->lnk[i].ibport) { | ||
548 | continue; | ||
549 | } | ||
550 | to_lnk = &lgr->lnk[i]; | ||
551 | break; | ||
552 | } | ||
553 | if (!to_lnk || !smc_wr_tx_link_hold(to_lnk)) { | ||
554 | smc_lgr_terminate_sched(lgr); | ||
555 | return NULL; | ||
556 | } | ||
557 | again: | ||
558 | read_lock_bh(&lgr->conns_lock); | ||
559 | for (node = rb_first(&lgr->conns_all); node; node = rb_next(node)) { | ||
560 | conn = rb_entry(node, struct smc_connection, alert_node); | ||
561 | if (conn->lnk != from_lnk) | ||
562 | continue; | ||
563 | smc = container_of(conn, struct smc_sock, conn); | ||
564 | /* conn->lnk not yet set in SMC_INIT state */ | ||
565 | if (smc->sk.sk_state == SMC_INIT) | ||
566 | continue; | ||
567 | if (smc->sk.sk_state == SMC_CLOSED || | ||
568 | smc->sk.sk_state == SMC_PEERCLOSEWAIT1 || | ||
569 | smc->sk.sk_state == SMC_PEERCLOSEWAIT2 || | ||
570 | smc->sk.sk_state == SMC_APPFINCLOSEWAIT || | ||
571 | smc->sk.sk_state == SMC_APPCLOSEWAIT1 || | ||
572 | smc->sk.sk_state == SMC_APPCLOSEWAIT2 || | ||
573 | smc->sk.sk_state == SMC_PEERFINCLOSEWAIT || | ||
574 | smc->sk.sk_state == SMC_PEERABORTWAIT || | ||
575 | smc->sk.sk_state == SMC_PROCESSABORT) { | ||
576 | spin_lock_bh(&conn->send_lock); | ||
577 | conn->lnk = to_lnk; | ||
578 | spin_unlock_bh(&conn->send_lock); | ||
579 | continue; | ||
580 | } | ||
581 | sock_hold(&smc->sk); | ||
582 | read_unlock_bh(&lgr->conns_lock); | ||
583 | /* pre-fetch buffer outside of send_lock, might sleep */ | ||
584 | rc = smc_cdc_get_free_slot(conn, to_lnk, &wr_buf, NULL, &pend); | ||
585 | if (rc) | ||
586 | goto err_out; | ||
587 | /* avoid race with smcr_tx_sndbuf_nonempty() */ | ||
588 | spin_lock_bh(&conn->send_lock); | ||
589 | conn->lnk = to_lnk; | ||
590 | rc = smc_switch_cursor(smc, pend, wr_buf); | ||
591 | spin_unlock_bh(&conn->send_lock); | ||
592 | sock_put(&smc->sk); | ||
593 | if (rc) | ||
594 | goto err_out; | ||
595 | goto again; | ||
596 | } | ||
597 | read_unlock_bh(&lgr->conns_lock); | ||
598 | smc_wr_tx_link_put(to_lnk); | ||
599 | return to_lnk; | ||
600 | |||
601 | err_out: | ||
602 | smcr_link_down_cond_sched(to_lnk); | ||
603 | smc_wr_tx_link_put(to_lnk); | ||
604 | return NULL; | ||
605 | } | ||
606 | |||
607 | static void smcr_buf_unuse(struct smc_buf_desc *rmb_desc, | ||
608 | struct smc_link_group *lgr) | ||
609 | { | ||
610 | int rc; | ||
611 | |||
612 | if (rmb_desc->is_conf_rkey && !list_empty(&lgr->list)) { | ||
613 | /* unregister rmb with peer */ | ||
614 | rc = smc_llc_flow_initiate(lgr, SMC_LLC_FLOW_RKEY); | ||
615 | if (!rc) { | ||
616 | /* protect against smc_llc_cli_rkey_exchange() */ | ||
617 | mutex_lock(&lgr->llc_conf_mutex); | ||
618 | smc_llc_do_delete_rkey(lgr, rmb_desc); | ||
619 | rmb_desc->is_conf_rkey = false; | ||
620 | mutex_unlock(&lgr->llc_conf_mutex); | ||
621 | smc_llc_flow_stop(lgr, &lgr->llc_flow_lcl); | ||
622 | } | ||
623 | } | ||
624 | |||
625 | if (rmb_desc->is_reg_err) { | ||
626 | /* buf registration failed, reuse not possible */ | ||
627 | mutex_lock(&lgr->rmbs_lock); | ||
628 | list_del(&rmb_desc->list); | ||
629 | mutex_unlock(&lgr->rmbs_lock); | ||
630 | |||
631 | smc_buf_free(lgr, true, rmb_desc); | ||
632 | } else { | ||
633 | rmb_desc->used = 0; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | static void smc_buf_unuse(struct smc_connection *conn, | ||
638 | struct smc_link_group *lgr) | ||
639 | { | ||
640 | if (conn->sndbuf_desc) | ||
641 | conn->sndbuf_desc->used = 0; | ||
642 | if (conn->rmb_desc && lgr->is_smcd) | ||
643 | conn->rmb_desc->used = 0; | ||
644 | else if (conn->rmb_desc) | ||
645 | smcr_buf_unuse(conn->rmb_desc, lgr); | ||
646 | } | ||
647 | |||
648 | /* remove a finished connection from its link group */ | ||
649 | void smc_conn_free(struct smc_connection *conn) | ||
650 | { | ||
651 | struct smc_link_group *lgr = conn->lgr; | ||
652 | |||
653 | if (!lgr) | ||
654 | return; | ||
655 | if (lgr->is_smcd) { | ||
656 | if (!list_empty(&lgr->list)) | ||
657 | smc_ism_unset_conn(conn); | ||
658 | tasklet_kill(&conn->rx_tsklet); | ||
659 | } else { | ||
660 | smc_cdc_wait_pend_tx_wr(conn); | ||
661 | if (current_work() != &conn->abort_work) | ||
662 | cancel_work_sync(&conn->abort_work); | ||
663 | } | ||
664 | if (!list_empty(&lgr->list)) { | ||
665 | smc_buf_unuse(conn, lgr); /* allow buffer reuse */ | ||
666 | smc_lgr_unregister_conn(conn); | ||
667 | } | ||
668 | |||
669 | if (!lgr->conns_num) | ||
670 | smc_lgr_schedule_free_work(lgr); | ||
671 | } | ||
672 | |||
673 | /* unregister a link from a buf_desc */ | ||
674 | static void smcr_buf_unmap_link(struct smc_buf_desc *buf_desc, bool is_rmb, | ||
675 | struct smc_link *lnk) | ||
676 | { | ||
677 | if (is_rmb) | ||
678 | buf_desc->is_reg_mr[lnk->link_idx] = false; | ||
679 | if (!buf_desc->is_map_ib[lnk->link_idx]) | ||
680 | return; | ||
681 | if (is_rmb) { | ||
682 | if (buf_desc->mr_rx[lnk->link_idx]) { | ||
683 | smc_ib_put_memory_region( | ||
684 | buf_desc->mr_rx[lnk->link_idx]); | ||
685 | buf_desc->mr_rx[lnk->link_idx] = NULL; | ||
686 | } | ||
687 | smc_ib_buf_unmap_sg(lnk, buf_desc, DMA_FROM_DEVICE); | ||
688 | } else { | ||
689 | smc_ib_buf_unmap_sg(lnk, buf_desc, DMA_TO_DEVICE); | ||
690 | } | ||
691 | sg_free_table(&buf_desc->sgt[lnk->link_idx]); | ||
692 | buf_desc->is_map_ib[lnk->link_idx] = false; | ||
693 | } | ||
694 | |||
695 | /* unmap all buffers of lgr for a deleted link */ | ||
696 | static void smcr_buf_unmap_lgr(struct smc_link *lnk) | ||
697 | { | ||
698 | struct smc_link_group *lgr = lnk->lgr; | ||
699 | struct smc_buf_desc *buf_desc, *bf; | ||
700 | int i; | ||
701 | |||
702 | for (i = 0; i < SMC_RMBE_SIZES; i++) { | ||
703 | mutex_lock(&lgr->rmbs_lock); | ||
704 | list_for_each_entry_safe(buf_desc, bf, &lgr->rmbs[i], list) | ||
705 | smcr_buf_unmap_link(buf_desc, true, lnk); | ||
706 | mutex_unlock(&lgr->rmbs_lock); | ||
707 | mutex_lock(&lgr->sndbufs_lock); | ||
708 | list_for_each_entry_safe(buf_desc, bf, &lgr->sndbufs[i], | ||
709 | list) | ||
710 | smcr_buf_unmap_link(buf_desc, false, lnk); | ||
711 | mutex_unlock(&lgr->sndbufs_lock); | ||
712 | } | ||
713 | } | ||
714 | |||
715 | static void smcr_rtoken_clear_link(struct smc_link *lnk) | ||
716 | { | ||
717 | struct smc_link_group *lgr = lnk->lgr; | ||
718 | int i; | ||
719 | |||
720 | for (i = 0; i < SMC_RMBS_PER_LGR_MAX; i++) { | ||
721 | lgr->rtokens[i][lnk->link_idx].rkey = 0; | ||
722 | lgr->rtokens[i][lnk->link_idx].dma_addr = 0; | ||
723 | } | ||
724 | } | ||
725 | |||
726 | /* must be called under lgr->llc_conf_mutex lock */ | ||
727 | void smcr_link_clear(struct smc_link *lnk, bool log) | ||
728 | { | ||
729 | struct smc_ib_device *smcibdev; | ||
730 | |||
731 | if (!lnk->lgr || lnk->state == SMC_LNK_UNUSED) | ||
732 | return; | ||
733 | lnk->peer_qpn = 0; | ||
734 | smc_llc_link_clear(lnk, log); | ||
735 | smcr_buf_unmap_lgr(lnk); | ||
736 | smcr_rtoken_clear_link(lnk); | ||
737 | smc_ib_modify_qp_error(lnk); | ||
738 | smc_wr_free_link(lnk); | ||
739 | smc_ib_destroy_queue_pair(lnk); | ||
740 | smc_ib_dealloc_protection_domain(lnk); | ||
741 | smc_wr_free_link_mem(lnk); | ||
742 | put_device(&lnk->smcibdev->ibdev->dev); | ||
743 | smcibdev = lnk->smcibdev; | ||
744 | memset(lnk, 0, sizeof(struct smc_link)); | ||
745 | lnk->state = SMC_LNK_UNUSED; | ||
746 | if (!atomic_dec_return(&smcibdev->lnk_cnt)) | ||
747 | wake_up(&smcibdev->lnks_deleted); | ||
748 | } | ||
749 | |||
750 | static void smcr_buf_free(struct smc_link_group *lgr, bool is_rmb, | ||
751 | struct smc_buf_desc *buf_desc) | ||
752 | { | ||
753 | int i; | ||
754 | |||
755 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) | ||
756 | smcr_buf_unmap_link(buf_desc, is_rmb, &lgr->lnk[i]); | ||
757 | |||
758 | if (buf_desc->pages) | ||
759 | __free_pages(buf_desc->pages, buf_desc->order); | ||
760 | kfree(buf_desc); | ||
761 | } | ||
762 | |||
763 | static void smcd_buf_free(struct smc_link_group *lgr, bool is_dmb, | ||
764 | struct smc_buf_desc *buf_desc) | ||
765 | { | ||
766 | if (is_dmb) { | ||
767 | /* restore original buf len */ | ||
768 | buf_desc->len += sizeof(struct smcd_cdc_msg); | ||
769 | smc_ism_unregister_dmb(lgr->smcd, buf_desc); | ||
770 | } else { | ||
771 | kfree(buf_desc->cpu_addr); | ||
772 | } | ||
773 | kfree(buf_desc); | ||
774 | } | ||
775 | |||
776 | static void smc_buf_free(struct smc_link_group *lgr, bool is_rmb, | ||
777 | struct smc_buf_desc *buf_desc) | ||
778 | { | ||
779 | if (lgr->is_smcd) | ||
780 | smcd_buf_free(lgr, is_rmb, buf_desc); | ||
781 | else | ||
782 | smcr_buf_free(lgr, is_rmb, buf_desc); | ||
783 | } | ||
784 | |||
785 | static void __smc_lgr_free_bufs(struct smc_link_group *lgr, bool is_rmb) | ||
786 | { | ||
787 | struct smc_buf_desc *buf_desc, *bf_desc; | ||
788 | struct list_head *buf_list; | ||
789 | int i; | ||
790 | |||
791 | for (i = 0; i < SMC_RMBE_SIZES; i++) { | ||
792 | if (is_rmb) | ||
793 | buf_list = &lgr->rmbs[i]; | ||
794 | else | ||
795 | buf_list = &lgr->sndbufs[i]; | ||
796 | list_for_each_entry_safe(buf_desc, bf_desc, buf_list, | ||
797 | list) { | ||
798 | list_del(&buf_desc->list); | ||
799 | smc_buf_free(lgr, is_rmb, buf_desc); | ||
800 | } | ||
801 | } | ||
802 | } | ||
803 | |||
804 | static void smc_lgr_free_bufs(struct smc_link_group *lgr) | ||
805 | { | ||
806 | /* free send buffers */ | ||
807 | __smc_lgr_free_bufs(lgr, false); | ||
808 | /* free rmbs */ | ||
809 | __smc_lgr_free_bufs(lgr, true); | ||
810 | } | ||
811 | |||
812 | /* remove a link group */ | ||
813 | static void smc_lgr_free(struct smc_link_group *lgr) | ||
814 | { | ||
815 | int i; | ||
816 | |||
817 | if (!lgr->is_smcd) { | ||
818 | mutex_lock(&lgr->llc_conf_mutex); | ||
819 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
820 | if (lgr->lnk[i].state != SMC_LNK_UNUSED) | ||
821 | smcr_link_clear(&lgr->lnk[i], false); | ||
822 | } | ||
823 | mutex_unlock(&lgr->llc_conf_mutex); | ||
824 | smc_llc_lgr_clear(lgr); | ||
825 | } | ||
826 | |||
827 | smc_lgr_free_bufs(lgr); | ||
828 | destroy_workqueue(lgr->tx_wq); | ||
829 | if (lgr->is_smcd) { | ||
830 | smc_ism_put_vlan(lgr->smcd, lgr->vlan_id); | ||
831 | put_device(&lgr->smcd->dev); | ||
832 | if (!atomic_dec_return(&lgr->smcd->lgr_cnt)) | ||
833 | wake_up(&lgr->smcd->lgrs_deleted); | ||
834 | } else { | ||
835 | if (!atomic_dec_return(&lgr_cnt)) | ||
836 | wake_up(&lgrs_deleted); | ||
837 | } | ||
838 | kfree(lgr); | ||
839 | } | ||
840 | |||
841 | static void smcd_unregister_all_dmbs(struct smc_link_group *lgr) | ||
842 | { | ||
843 | int i; | ||
844 | |||
845 | for (i = 0; i < SMC_RMBE_SIZES; i++) { | ||
846 | struct smc_buf_desc *buf_desc; | ||
847 | |||
848 | list_for_each_entry(buf_desc, &lgr->rmbs[i], list) { | ||
849 | buf_desc->len += sizeof(struct smcd_cdc_msg); | ||
850 | smc_ism_unregister_dmb(lgr->smcd, buf_desc); | ||
851 | } | ||
852 | } | ||
853 | } | ||
854 | |||
855 | static void smc_sk_wake_ups(struct smc_sock *smc) | ||
856 | { | ||
857 | smc->sk.sk_write_space(&smc->sk); | ||
858 | smc->sk.sk_data_ready(&smc->sk); | ||
859 | smc->sk.sk_state_change(&smc->sk); | ||
860 | } | ||
861 | |||
862 | /* kill a connection */ | ||
863 | static void smc_conn_kill(struct smc_connection *conn, bool soft) | ||
864 | { | ||
865 | struct smc_sock *smc = container_of(conn, struct smc_sock, conn); | ||
866 | |||
867 | if (conn->lgr->is_smcd && conn->lgr->peer_shutdown) | ||
868 | conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1; | ||
869 | else | ||
870 | smc_close_abort(conn); | ||
871 | conn->killed = 1; | ||
872 | smc->sk.sk_err = ECONNABORTED; | ||
873 | smc_sk_wake_ups(smc); | ||
874 | if (conn->lgr->is_smcd) { | ||
875 | smc_ism_unset_conn(conn); | ||
876 | if (soft) | ||
877 | tasklet_kill(&conn->rx_tsklet); | ||
878 | else | ||
879 | tasklet_unlock_wait(&conn->rx_tsklet); | ||
880 | } else { | ||
881 | smc_cdc_wait_pend_tx_wr(conn); | ||
882 | } | ||
883 | smc_lgr_unregister_conn(conn); | ||
884 | smc_close_active_abort(smc); | ||
885 | } | ||
886 | |||
887 | static void smc_lgr_cleanup(struct smc_link_group *lgr) | ||
888 | { | ||
889 | if (lgr->is_smcd) { | ||
890 | smc_ism_signal_shutdown(lgr); | ||
891 | smcd_unregister_all_dmbs(lgr); | ||
892 | } else { | ||
893 | u32 rsn = lgr->llc_termination_rsn; | ||
894 | |||
895 | if (!rsn) | ||
896 | rsn = SMC_LLC_DEL_PROG_INIT_TERM; | ||
897 | smc_llc_send_link_delete_all(lgr, false, rsn); | ||
898 | smcr_lgr_link_deactivate_all(lgr); | ||
899 | } | ||
900 | } | ||
901 | |||
902 | /* terminate link group | ||
903 | * @soft: true if link group shutdown can take its time | ||
904 | * false if immediate link group shutdown is required | ||
905 | */ | ||
906 | static void __smc_lgr_terminate(struct smc_link_group *lgr, bool soft) | ||
907 | { | ||
908 | struct smc_connection *conn; | ||
909 | struct smc_sock *smc; | ||
910 | struct rb_node *node; | ||
911 | |||
912 | if (lgr->terminating) | ||
913 | return; /* lgr already terminating */ | ||
914 | /* cancel free_work sync, will terminate when lgr->freeing is set */ | ||
915 | cancel_delayed_work_sync(&lgr->free_work); | ||
916 | lgr->terminating = 1; | ||
917 | |||
918 | /* kill remaining link group connections */ | ||
919 | read_lock_bh(&lgr->conns_lock); | ||
920 | node = rb_first(&lgr->conns_all); | ||
921 | while (node) { | ||
922 | read_unlock_bh(&lgr->conns_lock); | ||
923 | conn = rb_entry(node, struct smc_connection, alert_node); | ||
924 | smc = container_of(conn, struct smc_sock, conn); | ||
925 | sock_hold(&smc->sk); /* sock_put below */ | ||
926 | lock_sock(&smc->sk); | ||
927 | smc_conn_kill(conn, soft); | ||
928 | release_sock(&smc->sk); | ||
929 | sock_put(&smc->sk); /* sock_hold above */ | ||
930 | read_lock_bh(&lgr->conns_lock); | ||
931 | node = rb_first(&lgr->conns_all); | ||
932 | } | ||
933 | read_unlock_bh(&lgr->conns_lock); | ||
934 | smc_lgr_cleanup(lgr); | ||
935 | smc_lgr_free(lgr); | ||
936 | } | ||
937 | |||
938 | /* unlink link group and schedule termination */ | ||
939 | void smc_lgr_terminate_sched(struct smc_link_group *lgr) | ||
940 | { | ||
941 | spinlock_t *lgr_lock; | ||
942 | |||
943 | smc_lgr_list_head(lgr, &lgr_lock); | ||
944 | spin_lock_bh(lgr_lock); | ||
945 | if (list_empty(&lgr->list) || lgr->terminating || lgr->freeing) { | ||
946 | spin_unlock_bh(lgr_lock); | ||
947 | return; /* lgr already terminating */ | ||
948 | } | ||
949 | list_del_init(&lgr->list); | ||
950 | lgr->freeing = 1; | ||
951 | spin_unlock_bh(lgr_lock); | ||
952 | schedule_work(&lgr->terminate_work); | ||
953 | } | ||
954 | |||
955 | /* Called when peer lgr shutdown (regularly or abnormally) is received */ | ||
956 | void smc_smcd_terminate(struct smcd_dev *dev, u64 peer_gid, unsigned short vlan) | ||
957 | { | ||
958 | struct smc_link_group *lgr, *l; | ||
959 | LIST_HEAD(lgr_free_list); | ||
960 | |||
961 | /* run common cleanup function and build free list */ | ||
962 | spin_lock_bh(&dev->lgr_lock); | ||
963 | list_for_each_entry_safe(lgr, l, &dev->lgr_list, list) { | ||
964 | if ((!peer_gid || lgr->peer_gid == peer_gid) && | ||
965 | (vlan == VLAN_VID_MASK || lgr->vlan_id == vlan)) { | ||
966 | if (peer_gid) /* peer triggered termination */ | ||
967 | lgr->peer_shutdown = 1; | ||
968 | list_move(&lgr->list, &lgr_free_list); | ||
969 | lgr->freeing = 1; | ||
970 | } | ||
971 | } | ||
972 | spin_unlock_bh(&dev->lgr_lock); | ||
973 | |||
974 | /* cancel the regular free workers and actually free lgrs */ | ||
975 | list_for_each_entry_safe(lgr, l, &lgr_free_list, list) { | ||
976 | list_del_init(&lgr->list); | ||
977 | schedule_work(&lgr->terminate_work); | ||
978 | } | ||
979 | } | ||
980 | |||
981 | /* Called when an SMCD device is removed or the smc module is unloaded */ | ||
982 | void smc_smcd_terminate_all(struct smcd_dev *smcd) | ||
983 | { | ||
984 | struct smc_link_group *lgr, *lg; | ||
985 | LIST_HEAD(lgr_free_list); | ||
986 | |||
987 | spin_lock_bh(&smcd->lgr_lock); | ||
988 | list_splice_init(&smcd->lgr_list, &lgr_free_list); | ||
989 | list_for_each_entry(lgr, &lgr_free_list, list) | ||
990 | lgr->freeing = 1; | ||
991 | spin_unlock_bh(&smcd->lgr_lock); | ||
992 | |||
993 | list_for_each_entry_safe(lgr, lg, &lgr_free_list, list) { | ||
994 | list_del_init(&lgr->list); | ||
995 | __smc_lgr_terminate(lgr, false); | ||
996 | } | ||
997 | |||
998 | if (atomic_read(&smcd->lgr_cnt)) | ||
999 | wait_event(smcd->lgrs_deleted, !atomic_read(&smcd->lgr_cnt)); | ||
1000 | } | ||
1001 | |||
1002 | /* Called when an SMCR device is removed or the smc module is unloaded. | ||
1003 | * If smcibdev is given, all SMCR link groups using this device are terminated. | ||
1004 | * If smcibdev is NULL, all SMCR link groups are terminated. | ||
1005 | */ | ||
1006 | void smc_smcr_terminate_all(struct smc_ib_device *smcibdev) | ||
1007 | { | ||
1008 | struct smc_link_group *lgr, *lg; | ||
1009 | LIST_HEAD(lgr_free_list); | ||
1010 | int i; | ||
1011 | |||
1012 | spin_lock_bh(&smc_lgr_list.lock); | ||
1013 | if (!smcibdev) { | ||
1014 | list_splice_init(&smc_lgr_list.list, &lgr_free_list); | ||
1015 | list_for_each_entry(lgr, &lgr_free_list, list) | ||
1016 | lgr->freeing = 1; | ||
1017 | } else { | ||
1018 | list_for_each_entry_safe(lgr, lg, &smc_lgr_list.list, list) { | ||
1019 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
1020 | if (lgr->lnk[i].smcibdev == smcibdev) | ||
1021 | smcr_link_down_cond_sched(&lgr->lnk[i]); | ||
1022 | } | ||
1023 | } | ||
1024 | } | ||
1025 | spin_unlock_bh(&smc_lgr_list.lock); | ||
1026 | |||
1027 | list_for_each_entry_safe(lgr, lg, &lgr_free_list, list) { | ||
1028 | list_del_init(&lgr->list); | ||
1029 | smc_llc_set_termination_rsn(lgr, SMC_LLC_DEL_OP_INIT_TERM); | ||
1030 | __smc_lgr_terminate(lgr, false); | ||
1031 | } | ||
1032 | |||
1033 | if (smcibdev) { | ||
1034 | if (atomic_read(&smcibdev->lnk_cnt)) | ||
1035 | wait_event(smcibdev->lnks_deleted, | ||
1036 | !atomic_read(&smcibdev->lnk_cnt)); | ||
1037 | } else { | ||
1038 | if (atomic_read(&lgr_cnt)) | ||
1039 | wait_event(lgrs_deleted, !atomic_read(&lgr_cnt)); | ||
1040 | } | ||
1041 | } | ||
1042 | |||
1043 | /* set new lgr type and clear all asymmetric link tagging */ | ||
1044 | void smcr_lgr_set_type(struct smc_link_group *lgr, enum smc_lgr_type new_type) | ||
1045 | { | ||
1046 | char *lgr_type = ""; | ||
1047 | int i; | ||
1048 | |||
1049 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) | ||
1050 | if (smc_link_usable(&lgr->lnk[i])) | ||
1051 | lgr->lnk[i].link_is_asym = false; | ||
1052 | if (lgr->type == new_type) | ||
1053 | return; | ||
1054 | lgr->type = new_type; | ||
1055 | |||
1056 | switch (lgr->type) { | ||
1057 | case SMC_LGR_NONE: | ||
1058 | lgr_type = "NONE"; | ||
1059 | break; | ||
1060 | case SMC_LGR_SINGLE: | ||
1061 | lgr_type = "SINGLE"; | ||
1062 | break; | ||
1063 | case SMC_LGR_SYMMETRIC: | ||
1064 | lgr_type = "SYMMETRIC"; | ||
1065 | break; | ||
1066 | case SMC_LGR_ASYMMETRIC_PEER: | ||
1067 | lgr_type = "ASYMMETRIC_PEER"; | ||
1068 | break; | ||
1069 | case SMC_LGR_ASYMMETRIC_LOCAL: | ||
1070 | lgr_type = "ASYMMETRIC_LOCAL"; | ||
1071 | break; | ||
1072 | } | ||
1073 | pr_warn_ratelimited("smc: SMC-R lg %*phN state changed: " | ||
1074 | "%s, pnetid %.16s\n", SMC_LGR_ID_SIZE, &lgr->id, | ||
1075 | lgr_type, lgr->pnet_id); | ||
1076 | } | ||
1077 | |||
1078 | /* set new lgr type and tag a link as asymmetric */ | ||
1079 | void smcr_lgr_set_type_asym(struct smc_link_group *lgr, | ||
1080 | enum smc_lgr_type new_type, int asym_lnk_idx) | ||
1081 | { | ||
1082 | smcr_lgr_set_type(lgr, new_type); | ||
1083 | lgr->lnk[asym_lnk_idx].link_is_asym = true; | ||
1084 | } | ||
1085 | |||
1086 | /* abort connection, abort_work scheduled from tasklet context */ | ||
1087 | static void smc_conn_abort_work(struct work_struct *work) | ||
1088 | { | ||
1089 | struct smc_connection *conn = container_of(work, | ||
1090 | struct smc_connection, | ||
1091 | abort_work); | ||
1092 | struct smc_sock *smc = container_of(conn, struct smc_sock, conn); | ||
1093 | |||
1094 | lock_sock(&smc->sk); | ||
1095 | smc_conn_kill(conn, true); | ||
1096 | release_sock(&smc->sk); | ||
1097 | sock_put(&smc->sk); /* sock_hold done by schedulers of abort_work */ | ||
1098 | } | ||
1099 | |||
1100 | void smcr_port_add(struct smc_ib_device *smcibdev, u8 ibport) | ||
1101 | { | ||
1102 | struct smc_link_group *lgr, *n; | ||
1103 | |||
1104 | list_for_each_entry_safe(lgr, n, &smc_lgr_list.list, list) { | ||
1105 | struct smc_link *link; | ||
1106 | |||
1107 | if (strncmp(smcibdev->pnetid[ibport - 1], lgr->pnet_id, | ||
1108 | SMC_MAX_PNETID_LEN) || | ||
1109 | lgr->type == SMC_LGR_SYMMETRIC || | ||
1110 | lgr->type == SMC_LGR_ASYMMETRIC_PEER) | ||
1111 | continue; | ||
1112 | |||
1113 | /* trigger local add link processing */ | ||
1114 | link = smc_llc_usable_link(lgr); | ||
1115 | if (link) | ||
1116 | smc_llc_add_link_local(link); | ||
1117 | } | ||
1118 | } | ||
1119 | |||
1120 | /* link is down - switch connections to alternate link, | ||
1121 | * must be called under lgr->llc_conf_mutex lock | ||
1122 | */ | ||
1123 | static void smcr_link_down(struct smc_link *lnk) | ||
1124 | { | ||
1125 | struct smc_link_group *lgr = lnk->lgr; | ||
1126 | struct smc_link *to_lnk; | ||
1127 | int del_link_id; | ||
1128 | |||
1129 | if (!lgr || lnk->state == SMC_LNK_UNUSED || list_empty(&lgr->list)) | ||
1130 | return; | ||
1131 | |||
1132 | to_lnk = smc_switch_conns(lgr, lnk, true); | ||
1133 | if (!to_lnk) { /* no backup link available */ | ||
1134 | smcr_link_clear(lnk, true); | ||
1135 | return; | ||
1136 | } | ||
1137 | smcr_lgr_set_type(lgr, SMC_LGR_SINGLE); | ||
1138 | del_link_id = lnk->link_id; | ||
1139 | |||
1140 | if (lgr->role == SMC_SERV) { | ||
1141 | /* trigger local delete link processing */ | ||
1142 | smc_llc_srv_delete_link_local(to_lnk, del_link_id); | ||
1143 | } else { | ||
1144 | if (lgr->llc_flow_lcl.type != SMC_LLC_FLOW_NONE) { | ||
1145 | /* another llc task is ongoing */ | ||
1146 | mutex_unlock(&lgr->llc_conf_mutex); | ||
1147 | wait_event_timeout(lgr->llc_flow_waiter, | ||
1148 | (list_empty(&lgr->list) || | ||
1149 | lgr->llc_flow_lcl.type == SMC_LLC_FLOW_NONE), | ||
1150 | SMC_LLC_WAIT_TIME); | ||
1151 | mutex_lock(&lgr->llc_conf_mutex); | ||
1152 | } | ||
1153 | if (!list_empty(&lgr->list)) { | ||
1154 | smc_llc_send_delete_link(to_lnk, del_link_id, | ||
1155 | SMC_LLC_REQ, true, | ||
1156 | SMC_LLC_DEL_LOST_PATH); | ||
1157 | smcr_link_clear(lnk, true); | ||
1158 | } | ||
1159 | wake_up(&lgr->llc_flow_waiter); /* wake up next waiter */ | ||
1160 | } | ||
1161 | } | ||
1162 | |||
1163 | /* must be called under lgr->llc_conf_mutex lock */ | ||
1164 | void smcr_link_down_cond(struct smc_link *lnk) | ||
1165 | { | ||
1166 | if (smc_link_downing(&lnk->state)) | ||
1167 | smcr_link_down(lnk); | ||
1168 | } | ||
1169 | |||
1170 | /* will get the lgr->llc_conf_mutex lock */ | ||
1171 | void smcr_link_down_cond_sched(struct smc_link *lnk) | ||
1172 | { | ||
1173 | if (smc_link_downing(&lnk->state)) | ||
1174 | schedule_work(&lnk->link_down_wrk); | ||
1175 | } | ||
1176 | |||
1177 | void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport) | ||
1178 | { | ||
1179 | struct smc_link_group *lgr, *n; | ||
1180 | int i; | ||
1181 | |||
1182 | list_for_each_entry_safe(lgr, n, &smc_lgr_list.list, list) { | ||
1183 | if (strncmp(smcibdev->pnetid[ibport - 1], lgr->pnet_id, | ||
1184 | SMC_MAX_PNETID_LEN)) | ||
1185 | continue; /* lgr is not affected */ | ||
1186 | if (list_empty(&lgr->list)) | ||
1187 | continue; | ||
1188 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
1189 | struct smc_link *lnk = &lgr->lnk[i]; | ||
1190 | |||
1191 | if (smc_link_usable(lnk) && | ||
1192 | lnk->smcibdev == smcibdev && lnk->ibport == ibport) | ||
1193 | smcr_link_down_cond_sched(lnk); | ||
1194 | } | ||
1195 | } | ||
1196 | } | ||
1197 | |||
1198 | static void smc_link_down_work(struct work_struct *work) | ||
1199 | { | ||
1200 | struct smc_link *link = container_of(work, struct smc_link, | ||
1201 | link_down_wrk); | ||
1202 | struct smc_link_group *lgr = link->lgr; | ||
1203 | |||
1204 | if (list_empty(&lgr->list)) | ||
1205 | return; | ||
1206 | wake_up_all(&lgr->llc_msg_waiter); | ||
1207 | mutex_lock(&lgr->llc_conf_mutex); | ||
1208 | smcr_link_down(link); | ||
1209 | mutex_unlock(&lgr->llc_conf_mutex); | ||
1210 | } | ||
1211 | |||
1212 | static int smc_vlan_by_tcpsk_walk(struct net_device *lower_dev, | ||
1213 | struct netdev_nested_priv *priv) | ||
1214 | { | ||
1215 | unsigned short *vlan_id = (unsigned short *)priv->data; | ||
1216 | |||
1217 | if (is_vlan_dev(lower_dev)) { | ||
1218 | *vlan_id = vlan_dev_vlan_id(lower_dev); | ||
1219 | return 1; | ||
1220 | } | ||
1221 | |||
1222 | return 0; | ||
1223 | } | ||
1224 | |||
1225 | /* Determine vlan of internal TCP socket. */ | ||
1226 | int smc_vlan_by_tcpsk(struct socket *clcsock, struct smc_init_info *ini) | ||
1227 | { | ||
1228 | struct dst_entry *dst = sk_dst_get(clcsock->sk); | ||
1229 | struct netdev_nested_priv priv; | ||
1230 | struct net_device *ndev; | ||
1231 | int rc = 0; | ||
1232 | |||
1233 | ini->vlan_id = 0; | ||
1234 | if (!dst) { | ||
1235 | rc = -ENOTCONN; | ||
1236 | goto out; | ||
1237 | } | ||
1238 | if (!dst->dev) { | ||
1239 | rc = -ENODEV; | ||
1240 | goto out_rel; | ||
1241 | } | ||
1242 | |||
1243 | ndev = dst->dev; | ||
1244 | if (is_vlan_dev(ndev)) { | ||
1245 | ini->vlan_id = vlan_dev_vlan_id(ndev); | ||
1246 | goto out_rel; | ||
1247 | } | ||
1248 | |||
1249 | priv.data = (void *)&ini->vlan_id; | ||
1250 | rtnl_lock(); | ||
1251 | netdev_walk_all_lower_dev(ndev, smc_vlan_by_tcpsk_walk, &priv); | ||
1252 | rtnl_unlock(); | ||
1253 | |||
1254 | out_rel: | ||
1255 | dst_release(dst); | ||
1256 | out: | ||
1257 | return rc; | ||
1258 | } | ||
1259 | |||
1260 | static bool smcr_lgr_match(struct smc_link_group *lgr, | ||
1261 | struct smc_clc_msg_local *lcl, | ||
1262 | enum smc_lgr_role role, u32 clcqpn) | ||
1263 | { | ||
1264 | int i; | ||
1265 | |||
1266 | if (memcmp(lgr->peer_systemid, lcl->id_for_peer, SMC_SYSTEMID_LEN) || | ||
1267 | lgr->role != role) | ||
1268 | return false; | ||
1269 | |||
1270 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
1271 | if (!smc_link_active(&lgr->lnk[i])) | ||
1272 | continue; | ||
1273 | if ((lgr->role == SMC_SERV || lgr->lnk[i].peer_qpn == clcqpn) && | ||
1274 | !memcmp(lgr->lnk[i].peer_gid, &lcl->gid, SMC_GID_SIZE) && | ||
1275 | !memcmp(lgr->lnk[i].peer_mac, lcl->mac, sizeof(lcl->mac))) | ||
1276 | return true; | ||
1277 | } | ||
1278 | return false; | ||
1279 | } | ||
1280 | |||
1281 | static bool smcd_lgr_match(struct smc_link_group *lgr, | ||
1282 | struct smcd_dev *smcismdev, u64 peer_gid) | ||
1283 | { | ||
1284 | return lgr->peer_gid == peer_gid && lgr->smcd == smcismdev; | ||
1285 | } | ||
1286 | |||
1287 | /* create a new SMC connection (and a new link group if necessary) */ | ||
1288 | int smc_conn_create(struct smc_sock *smc, struct smc_init_info *ini) | ||
1289 | { | ||
1290 | struct smc_connection *conn = &smc->conn; | ||
1291 | struct list_head *lgr_list; | ||
1292 | struct smc_link_group *lgr; | ||
1293 | enum smc_lgr_role role; | ||
1294 | spinlock_t *lgr_lock; | ||
1295 | int rc = 0; | ||
1296 | |||
1297 | lgr_list = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_list : | ||
1298 | &smc_lgr_list.list; | ||
1299 | lgr_lock = ini->is_smcd ? &ini->ism_dev[ini->ism_selected]->lgr_lock : | ||
1300 | &smc_lgr_list.lock; | ||
1301 | ini->first_contact_local = 1; | ||
1302 | role = smc->listen_smc ? SMC_SERV : SMC_CLNT; | ||
1303 | if (role == SMC_CLNT && ini->first_contact_peer) | ||
1304 | /* create new link group as well */ | ||
1305 | goto create; | ||
1306 | |||
1307 | /* determine if an existing link group can be reused */ | ||
1308 | spin_lock_bh(lgr_lock); | ||
1309 | list_for_each_entry(lgr, lgr_list, list) { | ||
1310 | write_lock_bh(&lgr->conns_lock); | ||
1311 | if ((ini->is_smcd ? | ||
1312 | smcd_lgr_match(lgr, ini->ism_dev[ini->ism_selected], | ||
1313 | ini->ism_peer_gid[ini->ism_selected]) : | ||
1314 | smcr_lgr_match(lgr, ini->ib_lcl, role, ini->ib_clcqpn)) && | ||
1315 | !lgr->sync_err && | ||
1316 | (ini->smcd_version == SMC_V2 || | ||
1317 | lgr->vlan_id == ini->vlan_id) && | ||
1318 | (role == SMC_CLNT || ini->is_smcd || | ||
1319 | (lgr->conns_num < SMC_RMBS_PER_LGR_MAX && | ||
1320 | !bitmap_full(lgr->rtokens_used_mask, SMC_RMBS_PER_LGR_MAX)))) { | ||
1321 | /* link group found */ | ||
1322 | ini->first_contact_local = 0; | ||
1323 | conn->lgr = lgr; | ||
1324 | rc = smc_lgr_register_conn(conn, false); | ||
1325 | write_unlock_bh(&lgr->conns_lock); | ||
1326 | if (!rc && delayed_work_pending(&lgr->free_work)) | ||
1327 | cancel_delayed_work(&lgr->free_work); | ||
1328 | break; | ||
1329 | } | ||
1330 | write_unlock_bh(&lgr->conns_lock); | ||
1331 | } | ||
1332 | spin_unlock_bh(lgr_lock); | ||
1333 | if (rc) | ||
1334 | return rc; | ||
1335 | |||
1336 | if (role == SMC_CLNT && !ini->first_contact_peer && | ||
1337 | ini->first_contact_local) { | ||
1338 | /* Server reuses a link group, but Client wants to start | ||
1339 | * a new one | ||
1340 | * send out_of_sync decline, reason synchr. error | ||
1341 | */ | ||
1342 | return SMC_CLC_DECL_SYNCERR; | ||
1343 | } | ||
1344 | |||
1345 | create: | ||
1346 | if (ini->first_contact_local) { | ||
1347 | rc = smc_lgr_create(smc, ini); | ||
1348 | if (rc) | ||
1349 | goto out; | ||
1350 | lgr = conn->lgr; | ||
1351 | write_lock_bh(&lgr->conns_lock); | ||
1352 | rc = smc_lgr_register_conn(conn, true); | ||
1353 | write_unlock_bh(&lgr->conns_lock); | ||
1354 | if (rc) | ||
1355 | goto out; | ||
1356 | } | ||
1357 | conn->local_tx_ctrl.common.type = SMC_CDC_MSG_TYPE; | ||
1358 | conn->local_tx_ctrl.len = SMC_WR_TX_SIZE; | ||
1359 | conn->urg_state = SMC_URG_READ; | ||
1360 | init_waitqueue_head(&conn->cdc_pend_tx_wq); | ||
1361 | INIT_WORK(&smc->conn.abort_work, smc_conn_abort_work); | ||
1362 | if (ini->is_smcd) { | ||
1363 | conn->rx_off = sizeof(struct smcd_cdc_msg); | ||
1364 | smcd_cdc_rx_init(conn); /* init tasklet for this conn */ | ||
1365 | } else { | ||
1366 | conn->rx_off = 0; | ||
1367 | } | ||
1368 | #ifndef KERNEL_HAS_ATOMIC64 | ||
1369 | spin_lock_init(&conn->acurs_lock); | ||
1370 | #endif | ||
1371 | |||
1372 | out: | ||
1373 | return rc; | ||
1374 | } | ||
1375 | |||
1376 | /* convert the RMB size into the compressed notation - minimum 16K. | ||
1377 | * In contrast to plain ilog2, this rounds towards the next power of 2, | ||
1378 | * so the socket application gets at least its desired sndbuf / rcvbuf size. | ||
1379 | */ | ||
1380 | static u8 smc_compress_bufsize(int size) | ||
1381 | { | ||
1382 | u8 compressed; | ||
1383 | |||
1384 | if (size <= SMC_BUF_MIN_SIZE) | ||
1385 | return 0; | ||
1386 | |||
1387 | size = (size - 1) >> 14; | ||
1388 | compressed = ilog2(size) + 1; | ||
1389 | if (compressed >= SMC_RMBE_SIZES) | ||
1390 | compressed = SMC_RMBE_SIZES - 1; | ||
1391 | return compressed; | ||
1392 | } | ||
1393 | |||
1394 | /* convert the RMB size from compressed notation into integer */ | ||
1395 | int smc_uncompress_bufsize(u8 compressed) | ||
1396 | { | ||
1397 | u32 size; | ||
1398 | |||
1399 | size = 0x00000001 << (((int)compressed) + 14); | ||
1400 | return (int)size; | ||
1401 | } | ||
1402 | |||
1403 | /* try to reuse a sndbuf or rmb description slot for a certain | ||
1404 | * buffer size; if not available, return NULL | ||
1405 | */ | ||
1406 | static struct smc_buf_desc *smc_buf_get_slot(int compressed_bufsize, | ||
1407 | struct mutex *lock, | ||
1408 | struct list_head *buf_list) | ||
1409 | { | ||
1410 | struct smc_buf_desc *buf_slot; | ||
1411 | |||
1412 | mutex_lock(lock); | ||
1413 | list_for_each_entry(buf_slot, buf_list, list) { | ||
1414 | if (cmpxchg(&buf_slot->used, 0, 1) == 0) { | ||
1415 | mutex_unlock(lock); | ||
1416 | return buf_slot; | ||
1417 | } | ||
1418 | } | ||
1419 | mutex_unlock(lock); | ||
1420 | return NULL; | ||
1421 | } | ||
1422 | |||
1423 | /* one of the conditions for announcing a receiver's current window size is | ||
1424 | * that it "results in a minimum increase in the window size of 10% of the | ||
1425 | * receive buffer space" [RFC7609] | ||
1426 | */ | ||
1427 | static inline int smc_rmb_wnd_update_limit(int rmbe_size) | ||
1428 | { | ||
1429 | return max_t(int, rmbe_size / 10, SOCK_MIN_SNDBUF / 2); | ||
1430 | } | ||
1431 | |||
1432 | /* map an rmb buf to a link */ | ||
1433 | static int smcr_buf_map_link(struct smc_buf_desc *buf_desc, bool is_rmb, | ||
1434 | struct smc_link *lnk) | ||
1435 | { | ||
1436 | int rc; | ||
1437 | |||
1438 | if (buf_desc->is_map_ib[lnk->link_idx]) | ||
1439 | return 0; | ||
1440 | |||
1441 | rc = sg_alloc_table(&buf_desc->sgt[lnk->link_idx], 1, GFP_KERNEL); | ||
1442 | if (rc) | ||
1443 | return rc; | ||
1444 | sg_set_buf(buf_desc->sgt[lnk->link_idx].sgl, | ||
1445 | buf_desc->cpu_addr, buf_desc->len); | ||
1446 | |||
1447 | /* map sg table to DMA address */ | ||
1448 | rc = smc_ib_buf_map_sg(lnk, buf_desc, | ||
1449 | is_rmb ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | ||
1450 | /* SMC protocol depends on mapping to one DMA address only */ | ||
1451 | if (rc != 1) { | ||
1452 | rc = -EAGAIN; | ||
1453 | goto free_table; | ||
1454 | } | ||
1455 | |||
1456 | /* create a new memory region for the RMB */ | ||
1457 | if (is_rmb) { | ||
1458 | rc = smc_ib_get_memory_region(lnk->roce_pd, | ||
1459 | IB_ACCESS_REMOTE_WRITE | | ||
1460 | IB_ACCESS_LOCAL_WRITE, | ||
1461 | buf_desc, lnk->link_idx); | ||
1462 | if (rc) | ||
1463 | goto buf_unmap; | ||
1464 | smc_ib_sync_sg_for_device(lnk, buf_desc, DMA_FROM_DEVICE); | ||
1465 | } | ||
1466 | buf_desc->is_map_ib[lnk->link_idx] = true; | ||
1467 | return 0; | ||
1468 | |||
1469 | buf_unmap: | ||
1470 | smc_ib_buf_unmap_sg(lnk, buf_desc, | ||
1471 | is_rmb ? DMA_FROM_DEVICE : DMA_TO_DEVICE); | ||
1472 | free_table: | ||
1473 | sg_free_table(&buf_desc->sgt[lnk->link_idx]); | ||
1474 | return rc; | ||
1475 | } | ||
1476 | |||
1477 | /* register a new rmb on IB device, | ||
1478 | * must be called under lgr->llc_conf_mutex lock | ||
1479 | */ | ||
1480 | int smcr_link_reg_rmb(struct smc_link *link, struct smc_buf_desc *rmb_desc) | ||
1481 | { | ||
1482 | if (list_empty(&link->lgr->list)) | ||
1483 | return -ENOLINK; | ||
1484 | if (!rmb_desc->is_reg_mr[link->link_idx]) { | ||
1485 | /* register memory region for new rmb */ | ||
1486 | if (smc_wr_reg_send(link, rmb_desc->mr_rx[link->link_idx])) { | ||
1487 | rmb_desc->is_reg_err = true; | ||
1488 | return -EFAULT; | ||
1489 | } | ||
1490 | rmb_desc->is_reg_mr[link->link_idx] = true; | ||
1491 | } | ||
1492 | return 0; | ||
1493 | } | ||
1494 | |||
1495 | static int _smcr_buf_map_lgr(struct smc_link *lnk, struct mutex *lock, | ||
1496 | struct list_head *lst, bool is_rmb) | ||
1497 | { | ||
1498 | struct smc_buf_desc *buf_desc, *bf; | ||
1499 | int rc = 0; | ||
1500 | |||
1501 | mutex_lock(lock); | ||
1502 | list_for_each_entry_safe(buf_desc, bf, lst, list) { | ||
1503 | if (!buf_desc->used) | ||
1504 | continue; | ||
1505 | rc = smcr_buf_map_link(buf_desc, is_rmb, lnk); | ||
1506 | if (rc) | ||
1507 | goto out; | ||
1508 | } | ||
1509 | out: | ||
1510 | mutex_unlock(lock); | ||
1511 | return rc; | ||
1512 | } | ||
1513 | |||
1514 | /* map all used buffers of lgr for a new link */ | ||
1515 | int smcr_buf_map_lgr(struct smc_link *lnk) | ||
1516 | { | ||
1517 | struct smc_link_group *lgr = lnk->lgr; | ||
1518 | int i, rc = 0; | ||
1519 | |||
1520 | for (i = 0; i < SMC_RMBE_SIZES; i++) { | ||
1521 | rc = _smcr_buf_map_lgr(lnk, &lgr->rmbs_lock, | ||
1522 | &lgr->rmbs[i], true); | ||
1523 | if (rc) | ||
1524 | return rc; | ||
1525 | rc = _smcr_buf_map_lgr(lnk, &lgr->sndbufs_lock, | ||
1526 | &lgr->sndbufs[i], false); | ||
1527 | if (rc) | ||
1528 | return rc; | ||
1529 | } | ||
1530 | return 0; | ||
1531 | } | ||
1532 | |||
1533 | /* register all used buffers of lgr for a new link, | ||
1534 | * must be called under lgr->llc_conf_mutex lock | ||
1535 | */ | ||
1536 | int smcr_buf_reg_lgr(struct smc_link *lnk) | ||
1537 | { | ||
1538 | struct smc_link_group *lgr = lnk->lgr; | ||
1539 | struct smc_buf_desc *buf_desc, *bf; | ||
1540 | int i, rc = 0; | ||
1541 | |||
1542 | mutex_lock(&lgr->rmbs_lock); | ||
1543 | for (i = 0; i < SMC_RMBE_SIZES; i++) { | ||
1544 | list_for_each_entry_safe(buf_desc, bf, &lgr->rmbs[i], list) { | ||
1545 | if (!buf_desc->used) | ||
1546 | continue; | ||
1547 | rc = smcr_link_reg_rmb(lnk, buf_desc); | ||
1548 | if (rc) | ||
1549 | goto out; | ||
1550 | } | ||
1551 | } | ||
1552 | out: | ||
1553 | mutex_unlock(&lgr->rmbs_lock); | ||
1554 | return rc; | ||
1555 | } | ||
1556 | |||
1557 | static struct smc_buf_desc *smcr_new_buf_create(struct smc_link_group *lgr, | ||
1558 | bool is_rmb, int bufsize) | ||
1559 | { | ||
1560 | struct smc_buf_desc *buf_desc; | ||
1561 | |||
1562 | /* try to alloc a new buffer */ | ||
1563 | buf_desc = kzalloc(sizeof(*buf_desc), GFP_KERNEL); | ||
1564 | if (!buf_desc) | ||
1565 | return ERR_PTR(-ENOMEM); | ||
1566 | |||
1567 | buf_desc->order = get_order(bufsize); | ||
1568 | buf_desc->pages = alloc_pages(GFP_KERNEL | __GFP_NOWARN | | ||
1569 | __GFP_NOMEMALLOC | __GFP_COMP | | ||
1570 | __GFP_NORETRY | __GFP_ZERO, | ||
1571 | buf_desc->order); | ||
1572 | if (!buf_desc->pages) { | ||
1573 | kfree(buf_desc); | ||
1574 | return ERR_PTR(-EAGAIN); | ||
1575 | } | ||
1576 | buf_desc->cpu_addr = (void *)page_address(buf_desc->pages); | ||
1577 | buf_desc->len = bufsize; | ||
1578 | return buf_desc; | ||
1579 | } | ||
1580 | |||
1581 | /* map buf_desc on all usable links, | ||
1582 | * unused buffers stay mapped as long as the link is up | ||
1583 | */ | ||
1584 | static int smcr_buf_map_usable_links(struct smc_link_group *lgr, | ||
1585 | struct smc_buf_desc *buf_desc, bool is_rmb) | ||
1586 | { | ||
1587 | int i, rc = 0, cnt = 0; | ||
1588 | |||
1589 | /* protect against parallel link reconfiguration */ | ||
1590 | mutex_lock(&lgr->llc_conf_mutex); | ||
1591 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
1592 | struct smc_link *lnk = &lgr->lnk[i]; | ||
1593 | |||
1594 | if (!smc_link_usable(lnk)) | ||
1595 | continue; | ||
1596 | if (smcr_buf_map_link(buf_desc, is_rmb, lnk)) { | ||
1597 | rc = -ENOMEM; | ||
1598 | goto out; | ||
1599 | } | ||
1600 | cnt++; | ||
1601 | } | ||
1602 | out: | ||
1603 | mutex_unlock(&lgr->llc_conf_mutex); | ||
1604 | if (!rc && !cnt) | ||
1605 | rc = -EINVAL; | ||
1606 | return rc; | ||
1607 | } | ||
1608 | |||
1609 | #define SMCD_DMBE_SIZES 6 /* 0 -> 16KB, 1 -> 32KB, .. 6 -> 1MB */ | ||
1610 | |||
1611 | static struct smc_buf_desc *smcd_new_buf_create(struct smc_link_group *lgr, | ||
1612 | bool is_dmb, int bufsize) | ||
1613 | { | ||
1614 | struct smc_buf_desc *buf_desc; | ||
1615 | int rc; | ||
1616 | |||
1617 | if (smc_compress_bufsize(bufsize) > SMCD_DMBE_SIZES) | ||
1618 | return ERR_PTR(-EAGAIN); | ||
1619 | |||
1620 | /* try to alloc a new DMB */ | ||
1621 | buf_desc = kzalloc(sizeof(*buf_desc), GFP_KERNEL); | ||
1622 | if (!buf_desc) | ||
1623 | return ERR_PTR(-ENOMEM); | ||
1624 | if (is_dmb) { | ||
1625 | rc = smc_ism_register_dmb(lgr, bufsize, buf_desc); | ||
1626 | if (rc) { | ||
1627 | kfree(buf_desc); | ||
1628 | if (rc == -ENOMEM) | ||
1629 | return ERR_PTR(-EAGAIN); | ||
1630 | if (rc == -ENOSPC) | ||
1631 | return ERR_PTR(-ENOSPC); | ||
1632 | return ERR_PTR(-EIO); | ||
1633 | } | ||
1634 | buf_desc->pages = virt_to_page(buf_desc->cpu_addr); | ||
1635 | /* CDC header stored in buf. So, pretend it was smaller */ | ||
1636 | buf_desc->len = bufsize - sizeof(struct smcd_cdc_msg); | ||
1637 | } else { | ||
1638 | buf_desc->cpu_addr = kzalloc(bufsize, GFP_KERNEL | | ||
1639 | __GFP_NOWARN | __GFP_NORETRY | | ||
1640 | __GFP_NOMEMALLOC); | ||
1641 | if (!buf_desc->cpu_addr) { | ||
1642 | kfree(buf_desc); | ||
1643 | return ERR_PTR(-EAGAIN); | ||
1644 | } | ||
1645 | buf_desc->len = bufsize; | ||
1646 | } | ||
1647 | return buf_desc; | ||
1648 | } | ||
1649 | |||
1650 | static int __smc_buf_create(struct smc_sock *smc, bool is_smcd, bool is_rmb) | ||
1651 | { | ||
1652 | struct smc_buf_desc *buf_desc = ERR_PTR(-ENOMEM); | ||
1653 | struct smc_connection *conn = &smc->conn; | ||
1654 | struct smc_link_group *lgr = conn->lgr; | ||
1655 | struct list_head *buf_list; | ||
1656 | int bufsize, bufsize_short; | ||
1657 | struct mutex *lock; /* lock buffer list */ | ||
1658 | int sk_buf_size; | ||
1659 | |||
1660 | if (is_rmb) | ||
1661 | /* use socket recv buffer size (w/o overhead) as start value */ | ||
1662 | sk_buf_size = smc->sk.sk_rcvbuf / 2; | ||
1663 | else | ||
1664 | /* use socket send buffer size (w/o overhead) as start value */ | ||
1665 | sk_buf_size = smc->sk.sk_sndbuf / 2; | ||
1666 | |||
1667 | for (bufsize_short = smc_compress_bufsize(sk_buf_size); | ||
1668 | bufsize_short >= 0; bufsize_short--) { | ||
1669 | |||
1670 | if (is_rmb) { | ||
1671 | lock = &lgr->rmbs_lock; | ||
1672 | buf_list = &lgr->rmbs[bufsize_short]; | ||
1673 | } else { | ||
1674 | lock = &lgr->sndbufs_lock; | ||
1675 | buf_list = &lgr->sndbufs[bufsize_short]; | ||
1676 | } | ||
1677 | bufsize = smc_uncompress_bufsize(bufsize_short); | ||
1678 | if ((1 << get_order(bufsize)) > SG_MAX_SINGLE_ALLOC) | ||
1679 | continue; | ||
1680 | |||
1681 | /* check for reusable slot in the link group */ | ||
1682 | buf_desc = smc_buf_get_slot(bufsize_short, lock, buf_list); | ||
1683 | if (buf_desc) { | ||
1684 | memset(buf_desc->cpu_addr, 0, bufsize); | ||
1685 | break; /* found reusable slot */ | ||
1686 | } | ||
1687 | |||
1688 | if (is_smcd) | ||
1689 | buf_desc = smcd_new_buf_create(lgr, is_rmb, bufsize); | ||
1690 | else | ||
1691 | buf_desc = smcr_new_buf_create(lgr, is_rmb, bufsize); | ||
1692 | |||
1693 | if (PTR_ERR(buf_desc) == -ENOMEM) | ||
1694 | break; | ||
1695 | if (IS_ERR(buf_desc)) | ||
1696 | continue; | ||
1697 | |||
1698 | buf_desc->used = 1; | ||
1699 | mutex_lock(lock); | ||
1700 | list_add(&buf_desc->list, buf_list); | ||
1701 | mutex_unlock(lock); | ||
1702 | break; /* found */ | ||
1703 | } | ||
1704 | |||
1705 | if (IS_ERR(buf_desc)) | ||
1706 | return PTR_ERR(buf_desc); | ||
1707 | |||
1708 | if (!is_smcd) { | ||
1709 | if (smcr_buf_map_usable_links(lgr, buf_desc, is_rmb)) { | ||
1710 | smcr_buf_unuse(buf_desc, lgr); | ||
1711 | return -ENOMEM; | ||
1712 | } | ||
1713 | } | ||
1714 | |||
1715 | if (is_rmb) { | ||
1716 | conn->rmb_desc = buf_desc; | ||
1717 | conn->rmbe_size_short = bufsize_short; | ||
1718 | smc->sk.sk_rcvbuf = bufsize * 2; | ||
1719 | atomic_set(&conn->bytes_to_rcv, 0); | ||
1720 | conn->rmbe_update_limit = | ||
1721 | smc_rmb_wnd_update_limit(buf_desc->len); | ||
1722 | if (is_smcd) | ||
1723 | smc_ism_set_conn(conn); /* map RMB/smcd_dev to conn */ | ||
1724 | } else { | ||
1725 | conn->sndbuf_desc = buf_desc; | ||
1726 | smc->sk.sk_sndbuf = bufsize * 2; | ||
1727 | atomic_set(&conn->sndbuf_space, bufsize); | ||
1728 | } | ||
1729 | return 0; | ||
1730 | } | ||
1731 | |||
1732 | void smc_sndbuf_sync_sg_for_cpu(struct smc_connection *conn) | ||
1733 | { | ||
1734 | if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk)) | ||
1735 | return; | ||
1736 | smc_ib_sync_sg_for_cpu(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE); | ||
1737 | } | ||
1738 | |||
1739 | void smc_sndbuf_sync_sg_for_device(struct smc_connection *conn) | ||
1740 | { | ||
1741 | if (!conn->lgr || conn->lgr->is_smcd || !smc_link_active(conn->lnk)) | ||
1742 | return; | ||
1743 | smc_ib_sync_sg_for_device(conn->lnk, conn->sndbuf_desc, DMA_TO_DEVICE); | ||
1744 | } | ||
1745 | |||
1746 | void smc_rmb_sync_sg_for_cpu(struct smc_connection *conn) | ||
1747 | { | ||
1748 | int i; | ||
1749 | |||
1750 | if (!conn->lgr || conn->lgr->is_smcd) | ||
1751 | return; | ||
1752 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
1753 | if (!smc_link_active(&conn->lgr->lnk[i])) | ||
1754 | continue; | ||
1755 | smc_ib_sync_sg_for_cpu(&conn->lgr->lnk[i], conn->rmb_desc, | ||
1756 | DMA_FROM_DEVICE); | ||
1757 | } | ||
1758 | } | ||
1759 | |||
1760 | void smc_rmb_sync_sg_for_device(struct smc_connection *conn) | ||
1761 | { | ||
1762 | int i; | ||
1763 | |||
1764 | if (!conn->lgr || conn->lgr->is_smcd) | ||
1765 | return; | ||
1766 | for (i = 0; i < SMC_LINKS_PER_LGR_MAX; i++) { | ||
1767 | if (!smc_link_active(&conn->lgr->lnk[i])) | ||
1768 | continue; | ||
1769 | smc_ib_sync_sg_for_device(&conn->lgr->lnk[i], conn->rmb_desc, | ||
1770 | DMA_FROM_DEVICE); | ||
1771 | } | ||
1772 | } | ||
1773 | |||
1774 | /* create the send and receive buffer for an SMC socket; | ||
1775 | * receive buffers are called RMBs; | ||
1776 | * (even though the SMC protocol allows more than one RMB-element per RMB, | ||
1777 | * the Linux implementation uses just one RMB-element per RMB, i.e. uses an | ||
1778 | * extra RMB for every connection in a link group | ||
1779 | */ | ||
1780 | int smc_buf_create(struct smc_sock *smc, bool is_smcd) | ||
1781 | { | ||
1782 | int rc; | ||
1783 | |||
1784 | /* create send buffer */ | ||
1785 | rc = __smc_buf_create(smc, is_smcd, false); | ||
1786 | if (rc) | ||
1787 | return rc; | ||
1788 | /* create rmb */ | ||
1789 | rc = __smc_buf_create(smc, is_smcd, true); | ||
1790 | if (rc) { | ||
1791 | mutex_lock(&smc->conn.lgr->sndbufs_lock); | ||
1792 | list_del(&smc->conn.sndbuf_desc->list); | ||
1793 | mutex_unlock(&smc->conn.lgr->sndbufs_lock); | ||
1794 | smc_buf_free(smc->conn.lgr, false, smc->conn.sndbuf_desc); | ||
1795 | smc->conn.sndbuf_desc = NULL; | ||
1796 | } | ||
1797 | return rc; | ||
1798 | } | ||
1799 | |||
1800 | static inline int smc_rmb_reserve_rtoken_idx(struct smc_link_group *lgr) | ||
1801 | { | ||
1802 | int i; | ||
1803 | |||
1804 | for_each_clear_bit(i, lgr->rtokens_used_mask, SMC_RMBS_PER_LGR_MAX) { | ||
1805 | if (!test_and_set_bit(i, lgr->rtokens_used_mask)) | ||
1806 | return i; | ||
1807 | } | ||
1808 | return -ENOSPC; | ||
1809 | } | ||
1810 | |||
1811 | static int smc_rtoken_find_by_link(struct smc_link_group *lgr, int lnk_idx, | ||
1812 | u32 rkey) | ||
1813 | { | ||
1814 | int i; | ||
1815 | |||
1816 | for (i = 0; i < SMC_RMBS_PER_LGR_MAX; i++) { | ||
1817 | if (test_bit(i, lgr->rtokens_used_mask) && | ||
1818 | lgr->rtokens[i][lnk_idx].rkey == rkey) | ||
1819 | return i; | ||
1820 | } | ||
1821 | return -ENOENT; | ||
1822 | } | ||
1823 | |||
1824 | /* set rtoken for a new link to an existing rmb */ | ||
1825 | void smc_rtoken_set(struct smc_link_group *lgr, int link_idx, int link_idx_new, | ||
1826 | __be32 nw_rkey_known, __be64 nw_vaddr, __be32 nw_rkey) | ||
1827 | { | ||
1828 | int rtok_idx; | ||
1829 | |||
1830 | rtok_idx = smc_rtoken_find_by_link(lgr, link_idx, ntohl(nw_rkey_known)); | ||
1831 | if (rtok_idx == -ENOENT) | ||
1832 | return; | ||
1833 | lgr->rtokens[rtok_idx][link_idx_new].rkey = ntohl(nw_rkey); | ||
1834 | lgr->rtokens[rtok_idx][link_idx_new].dma_addr = be64_to_cpu(nw_vaddr); | ||
1835 | } | ||
1836 | |||
1837 | /* set rtoken for a new link whose link_id is given */ | ||
1838 | void smc_rtoken_set2(struct smc_link_group *lgr, int rtok_idx, int link_id, | ||
1839 | __be64 nw_vaddr, __be32 nw_rkey) | ||
1840 | { | ||
1841 | u64 dma_addr = be64_to_cpu(nw_vaddr); | ||
1842 | u32 rkey = ntohl(nw_rkey); | ||
1843 | bool found = false; | ||
1844 | int link_idx; | ||
1845 | |||
1846 | for (link_idx = 0; link_idx < SMC_LINKS_PER_LGR_MAX; link_idx++) { | ||
1847 | if (lgr->lnk[link_idx].link_id == link_id) { | ||
1848 | found = true; | ||
1849 | break; | ||
1850 | } | ||
1851 | } | ||
1852 | if (!found) | ||
1853 | return; | ||
1854 | lgr->rtokens[rtok_idx][link_idx].rkey = rkey; | ||
1855 | lgr->rtokens[rtok_idx][link_idx].dma_addr = dma_addr; | ||
1856 | } | ||
1857 | |||
1858 | /* add a new rtoken from peer */ | ||
1859 | int smc_rtoken_add(struct smc_link *lnk, __be64 nw_vaddr, __be32 nw_rkey) | ||
1860 | { | ||
1861 | struct smc_link_group *lgr = smc_get_lgr(lnk); | ||
1862 | u64 dma_addr = be64_to_cpu(nw_vaddr); | ||
1863 | u32 rkey = ntohl(nw_rkey); | ||
1864 | int i; | ||
1865 | |||
1866 | for (i = 0; i < SMC_RMBS_PER_LGR_MAX; i++) { | ||
1867 | if (lgr->rtokens[i][lnk->link_idx].rkey == rkey && | ||
1868 | lgr->rtokens[i][lnk->link_idx].dma_addr == dma_addr && | ||
1869 | test_bit(i, lgr->rtokens_used_mask)) { | ||
1870 | /* already in list */ | ||
1871 | return i; | ||
1872 | } | ||
1873 | } | ||
1874 | i = smc_rmb_reserve_rtoken_idx(lgr); | ||
1875 | if (i < 0) | ||
1876 | return i; | ||
1877 | lgr->rtokens[i][lnk->link_idx].rkey = rkey; | ||
1878 | lgr->rtokens[i][lnk->link_idx].dma_addr = dma_addr; | ||
1879 | return i; | ||
1880 | } | ||
1881 | |||
1882 | /* delete an rtoken from all links */ | ||
1883 | int smc_rtoken_delete(struct smc_link *lnk, __be32 nw_rkey) | ||
1884 | { | ||
1885 | struct smc_link_group *lgr = smc_get_lgr(lnk); | ||
1886 | u32 rkey = ntohl(nw_rkey); | ||
1887 | int i, j; | ||
1888 | |||
1889 | for (i = 0; i < SMC_RMBS_PER_LGR_MAX; i++) { | ||
1890 | if (lgr->rtokens[i][lnk->link_idx].rkey == rkey && | ||
1891 | test_bit(i, lgr->rtokens_used_mask)) { | ||
1892 | for (j = 0; j < SMC_LINKS_PER_LGR_MAX; j++) { | ||
1893 | lgr->rtokens[i][j].rkey = 0; | ||
1894 | lgr->rtokens[i][j].dma_addr = 0; | ||
1895 | } | ||
1896 | clear_bit(i, lgr->rtokens_used_mask); | ||
1897 | return 0; | ||
1898 | } | ||
1899 | } | ||
1900 | return -ENOENT; | ||
1901 | } | ||
1902 | |||
1903 | /* save rkey and dma_addr received from peer during clc handshake */ | ||
1904 | int smc_rmb_rtoken_handling(struct smc_connection *conn, | ||
1905 | struct smc_link *lnk, | ||
1906 | struct smc_clc_msg_accept_confirm *clc) | ||
1907 | { | ||
1908 | conn->rtoken_idx = smc_rtoken_add(lnk, clc->r0.rmb_dma_addr, | ||
1909 | clc->r0.rmb_rkey); | ||
1910 | if (conn->rtoken_idx < 0) | ||
1911 | return conn->rtoken_idx; | ||
1912 | return 0; | ||
1913 | } | ||
1914 | |||
1915 | static void smc_core_going_away(void) | ||
1916 | { | ||
1917 | struct smc_ib_device *smcibdev; | ||
1918 | struct smcd_dev *smcd; | ||
1919 | |||
1920 | mutex_lock(&smc_ib_devices.mutex); | ||
1921 | list_for_each_entry(smcibdev, &smc_ib_devices.list, list) { | ||
1922 | int i; | ||
1923 | |||
1924 | for (i = 0; i < SMC_MAX_PORTS; i++) | ||
1925 | set_bit(i, smcibdev->ports_going_away); | ||
1926 | } | ||
1927 | mutex_unlock(&smc_ib_devices.mutex); | ||
1928 | |||
1929 | mutex_lock(&smcd_dev_list.mutex); | ||
1930 | list_for_each_entry(smcd, &smcd_dev_list.list, list) { | ||
1931 | smcd->going_away = 1; | ||
1932 | } | ||
1933 | mutex_unlock(&smcd_dev_list.mutex); | ||
1934 | } | ||
1935 | |||
1936 | /* Clean up all SMC link groups */ | ||
1937 | static void smc_lgrs_shutdown(void) | ||
1938 | { | ||
1939 | struct smcd_dev *smcd; | ||
1940 | |||
1941 | smc_core_going_away(); | ||
1942 | |||
1943 | smc_smcr_terminate_all(NULL); | ||
1944 | |||
1945 | mutex_lock(&smcd_dev_list.mutex); | ||
1946 | list_for_each_entry(smcd, &smcd_dev_list.list, list) | ||
1947 | smc_smcd_terminate_all(smcd); | ||
1948 | mutex_unlock(&smcd_dev_list.mutex); | ||
1949 | } | ||
1950 | |||
1951 | static int smc_core_reboot_event(struct notifier_block *this, | ||
1952 | unsigned long event, void *ptr) | ||
1953 | { | ||
1954 | smc_lgrs_shutdown(); | ||
1955 | smc_ib_unregister_client(); | ||
1956 | return 0; | ||
1957 | } | ||
1958 | |||
1959 | static struct notifier_block smc_reboot_notifier = { | ||
1960 | .notifier_call = smc_core_reboot_event, | ||
1961 | }; | ||
1962 | |||
1963 | int __init smc_core_init(void) | ||
1964 | { | ||
1965 | return register_reboot_notifier(&smc_reboot_notifier); | ||
1966 | } | ||
1967 | |||
1968 | /* Called (from smc_exit) when module is removed */ | ||
1969 | void smc_core_exit(void) | ||
1970 | { | ||
1971 | unregister_reboot_notifier(&smc_reboot_notifier); | ||
1972 | smc_lgrs_shutdown(); | ||
1973 | } | ||