1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
|
/*
* Copyright (c) 2004, 2005 Intel Corporation. All rights reserved.
* Copyright (c) 2004 Topspin Corporation. All rights reserved.
* Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved.
* Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
* Copyright (c) 2005 Network Appliance, Inc. All rights reserved.
* Copyright (c) 2016 Chelsio Communications. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* OpenIB.org BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/
#include "opt_inet.h"
#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/idr.h>
#include <linux/interrupt.h>
#include <linux/rbtree.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/string.h>
#include <netinet/tcp.h>
#include <sys/mutex.h>
#include <rdma/rdma_cm.h>
#include <rdma/iw_cm.h>
#include <rdma/ib_addr.h>
#include "iwcm.h"
MODULE_AUTHOR("Tom Tucker");
MODULE_DESCRIPTION("iWARP CM");
MODULE_LICENSE("Dual BSD/GPL");
static struct workqueue_struct *iwcm_wq;
struct iwcm_work {
struct work_struct work;
struct iwcm_id_private *cm_id;
struct list_head list;
struct iw_cm_event event;
struct list_head free_list;
};
struct iwcm_listen_work {
struct work_struct work;
struct iw_cm_id *cm_id;
};
static LIST_HEAD(listen_port_list);
static DEFINE_MUTEX(listen_port_mutex);
struct listen_port_info {
struct list_head list;
uint16_t port_num;
uint32_t refcnt;
};
static int32_t
add_port_to_listenlist(uint16_t port)
{
struct listen_port_info *port_info;
int err = 0;
mutex_lock(&listen_port_mutex);
list_for_each_entry(port_info, &listen_port_list, list)
if (port_info->port_num == port)
goto found_port;
port_info = kmalloc(sizeof(*port_info), GFP_KERNEL);
if (!port_info) {
err = -ENOMEM;
mutex_unlock(&listen_port_mutex);
goto out;
}
port_info->port_num = port;
port_info->refcnt = 0;
list_add(&port_info->list, &listen_port_list);
found_port:
++(port_info->refcnt);
mutex_unlock(&listen_port_mutex);
return port_info->refcnt;
out:
return err;
}
static int32_t
rem_port_from_listenlist(uint16_t port)
{
struct listen_port_info *port_info;
int ret, found_port = 0;
mutex_lock(&listen_port_mutex);
list_for_each_entry(port_info, &listen_port_list, list)
if (port_info->port_num == port) {
found_port = 1;
break;
}
if (found_port) {
--(port_info->refcnt);
ret = port_info->refcnt;
if (port_info->refcnt == 0) {
/* Remove this entry from the list as there are no
* more listeners for this port_num.
*/
list_del(&port_info->list);
kfree(port_info);
}
} else {
ret = -EINVAL;
}
mutex_unlock(&listen_port_mutex);
return ret;
}
/*
* The following services provide a mechanism for pre-allocating iwcm_work
* elements. The design pre-allocates them based on the cm_id type:
* LISTENING IDS: Get enough elements preallocated to handle the
* listen backlog.
* ACTIVE IDS: 4: CONNECT_REPLY, ESTABLISHED, DISCONNECT, CLOSE
* PASSIVE IDS: 3: ESTABLISHED, DISCONNECT, CLOSE
*
* Allocating them in connect and listen avoids having to deal
* with allocation failures on the event upcall from the provider (which
* is called in the interrupt context).
*
* One exception is when creating the cm_id for incoming connection requests.
* There are two cases:
* 1) in the event upcall, cm_event_handler(), for a listening cm_id. If
* the backlog is exceeded, then no more connection request events will
* be processed. cm_event_handler() returns -ENOMEM in this case. Its up
* to the provider to reject the connection request.
* 2) in the connection request workqueue handler, cm_conn_req_handler().
* If work elements cannot be allocated for the new connect request cm_id,
* then IWCM will call the provider reject method. This is ok since
* cm_conn_req_handler() runs in the workqueue thread context.
*/
static struct iwcm_work *get_work(struct iwcm_id_private *cm_id_priv)
{
struct iwcm_work *work;
if (list_empty(&cm_id_priv->work_free_list))
return NULL;
work = list_entry(cm_id_priv->work_free_list.next, struct iwcm_work,
free_list);
list_del_init(&work->free_list);
return work;
}
static void put_work(struct iwcm_work *work)
{
list_add(&work->free_list, &work->cm_id->work_free_list);
}
static void dealloc_work_entries(struct iwcm_id_private *cm_id_priv)
{
struct list_head *e, *tmp;
list_for_each_safe(e, tmp, &cm_id_priv->work_free_list)
kfree(list_entry(e, struct iwcm_work, free_list));
}
static int alloc_work_entries(struct iwcm_id_private *cm_id_priv, int count)
{
struct iwcm_work *work;
BUG_ON(!list_empty(&cm_id_priv->work_free_list));
while (count--) {
work = kmalloc(sizeof(struct iwcm_work), GFP_KERNEL);
if (!work) {
dealloc_work_entries(cm_id_priv);
return -ENOMEM;
}
work->cm_id = cm_id_priv;
INIT_LIST_HEAD(&work->list);
put_work(work);
}
return 0;
}
/*
* Save private data from incoming connection requests to
* iw_cm_event, so the low level driver doesn't have to. Adjust
* the event ptr to point to the local copy.
*/
static int copy_private_data(struct iw_cm_event *event)
{
void *p;
p = kmemdup(event->private_data, event->private_data_len, GFP_ATOMIC);
if (!p)
return -ENOMEM;
event->private_data = p;
return 0;
}
static void free_cm_id(struct iwcm_id_private *cm_id_priv)
{
dealloc_work_entries(cm_id_priv);
kfree(cm_id_priv);
}
/*
* Release a reference on cm_id. If the last reference is being
* released, enable the waiting thread (in iw_destroy_cm_id) to
* get woken up, and return 1 if a thread is already waiting.
*/
static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv)
{
BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
if (atomic_dec_and_test(&cm_id_priv->refcount)) {
BUG_ON(!list_empty(&cm_id_priv->work_list));
complete(&cm_id_priv->destroy_comp);
return 1;
}
return 0;
}
static void add_ref(struct iw_cm_id *cm_id)
{
struct iwcm_id_private *cm_id_priv;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
atomic_inc(&cm_id_priv->refcount);
}
static void rem_ref(struct iw_cm_id *cm_id)
{
struct iwcm_id_private *cm_id_priv;
int cb_destroy;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
/*
* Test bit before deref in case the cm_id gets freed on another
* thread.
*/
cb_destroy = test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
if (iwcm_deref_id(cm_id_priv) && cb_destroy) {
BUG_ON(!list_empty(&cm_id_priv->work_list));
free_cm_id(cm_id_priv);
}
}
static int cm_event_handler(struct iw_cm_id *cm_id, struct iw_cm_event *event);
struct iw_cm_id *iw_create_cm_id(struct ib_device *device,
struct socket *so,
iw_cm_handler cm_handler,
void *context)
{
struct iwcm_id_private *cm_id_priv;
cm_id_priv = kzalloc(sizeof(*cm_id_priv), GFP_KERNEL);
if (!cm_id_priv)
return ERR_PTR(-ENOMEM);
cm_id_priv->state = IW_CM_STATE_IDLE;
cm_id_priv->id.device = device;
cm_id_priv->id.cm_handler = cm_handler;
cm_id_priv->id.context = context;
cm_id_priv->id.event_handler = cm_event_handler;
cm_id_priv->id.add_ref = add_ref;
cm_id_priv->id.rem_ref = rem_ref;
cm_id_priv->id.so = so;
spin_lock_init(&cm_id_priv->lock);
atomic_set(&cm_id_priv->refcount, 1);
init_waitqueue_head(&cm_id_priv->connect_wait);
init_completion(&cm_id_priv->destroy_comp);
INIT_LIST_HEAD(&cm_id_priv->work_list);
INIT_LIST_HEAD(&cm_id_priv->work_free_list);
return &cm_id_priv->id;
}
EXPORT_SYMBOL(iw_create_cm_id);
static int iwcm_modify_qp_err(struct ib_qp *qp)
{
struct ib_qp_attr qp_attr;
if (!qp)
return -EINVAL;
qp_attr.qp_state = IB_QPS_ERR;
return ib_modify_qp(qp, &qp_attr, IB_QP_STATE);
}
/*
* This is really the RDMAC CLOSING state. It is most similar to the
* IB SQD QP state.
*/
static int iwcm_modify_qp_sqd(struct ib_qp *qp)
{
struct ib_qp_attr qp_attr;
BUG_ON(qp == NULL);
qp_attr.qp_state = IB_QPS_SQD;
return ib_modify_qp(qp, &qp_attr, IB_QP_STATE);
}
/*
* CM_ID <-- CLOSING
*
* Block if a passive or active connection is currently being processed. Then
* process the event as follows:
* - If we are ESTABLISHED, move to CLOSING and modify the QP state
* based on the abrupt flag
* - If the connection is already in the CLOSING or IDLE state, the peer is
* disconnecting concurrently with us and we've already seen the
* DISCONNECT event -- ignore the request and return 0
* - Disconnect on a listening endpoint returns -EINVAL
*/
int iw_cm_disconnect(struct iw_cm_id *cm_id, int abrupt)
{
struct iwcm_id_private *cm_id_priv;
unsigned long flags;
int ret = 0;
struct ib_qp *qp = NULL;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
/* Wait if we're currently in a connect or accept downcall */
wait_event(cm_id_priv->connect_wait,
!test_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags));
spin_lock_irqsave(&cm_id_priv->lock, flags);
switch (cm_id_priv->state) {
case IW_CM_STATE_ESTABLISHED:
cm_id_priv->state = IW_CM_STATE_CLOSING;
/* QP could be <nul> for user-mode client */
if (cm_id_priv->qp)
qp = cm_id_priv->qp;
else
ret = -EINVAL;
break;
case IW_CM_STATE_LISTEN:
ret = -EINVAL;
break;
case IW_CM_STATE_CLOSING:
/* remote peer closed first */
case IW_CM_STATE_IDLE:
/* accept or connect returned !0 */
break;
case IW_CM_STATE_CONN_RECV:
/*
* App called disconnect before/without calling accept after
* connect_request event delivered.
*/
break;
case IW_CM_STATE_CONN_SENT:
/* Can only get here if wait above fails */
default:
BUG();
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
if (qp) {
if (abrupt)
ret = iwcm_modify_qp_err(qp);
else
ret = iwcm_modify_qp_sqd(qp);
/*
* If both sides are disconnecting the QP could
* already be in ERR or SQD states
*/
ret = 0;
}
return ret;
}
EXPORT_SYMBOL(iw_cm_disconnect);
static struct socket *
dequeue_socket(struct socket *head)
{
struct socket *so;
struct sockaddr_in *remote;
ACCEPT_LOCK();
so = TAILQ_FIRST(&head->so_comp);
if (!so) {
ACCEPT_UNLOCK();
return NULL;
}
SOCK_LOCK(so);
/*
* Before changing the flags on the socket, we have to bump the
* reference count. Otherwise, if the protocol calls sofree(),
* the socket will be released due to a zero refcount.
*/
soref(so);
TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--;
so->so_qstate &= ~SQ_COMP;
so->so_head = NULL;
so->so_state |= SS_NBIO;
SOCK_UNLOCK(so);
ACCEPT_UNLOCK();
soaccept(so, (struct sockaddr **)&remote);
free(remote, M_SONAME);
return so;
}
static void
iw_so_event_handler(struct work_struct *_work)
{
#ifdef INET
struct iwcm_listen_work *work = container_of(_work,
struct iwcm_listen_work, work);
struct iw_cm_id *listen_cm_id = work->cm_id;
struct iwcm_id_private *cm_id_priv;
struct iw_cm_id *real_cm_id;
struct sockaddr_in *local;
struct socket *so;
cm_id_priv = container_of(listen_cm_id, struct iwcm_id_private, id);
if (cm_id_priv->state != IW_CM_STATE_LISTEN) {
kfree(work);
return;
}
/* Dequeue & process all new 'so' connection requests for this cmid */
while ((so = dequeue_socket(work->cm_id->so)) != NULL) {
if (rdma_cma_any_addr((struct sockaddr *)
&listen_cm_id->local_addr)) {
in_getsockaddr(so, (struct sockaddr **)&local);
if (rdma_find_cmid_laddr(local, ARPHRD_ETHER,
(void **) &real_cm_id)) {
free(local, M_SONAME);
goto err;
}
free(local, M_SONAME);
real_cm_id->device->iwcm->newconn(real_cm_id, so);
} else {
listen_cm_id->device->iwcm->newconn(listen_cm_id, so);
}
}
err:
kfree(work);
#endif
return;
}
static int
iw_so_upcall(struct socket *parent_so, void *arg, int waitflag)
{
struct iwcm_listen_work *work;
struct socket *so;
struct iw_cm_id *cm_id = arg;
/* check whether iw_so_event_handler() already dequeued this 'so' */
so = TAILQ_FIRST(&parent_so->so_comp);
if (!so)
return SU_OK;
work = kzalloc(sizeof(*work), M_NOWAIT);
if (!work)
return -ENOMEM;
work->cm_id = cm_id;
INIT_WORK(&work->work, iw_so_event_handler);
queue_work(iwcm_wq, &work->work);
return SU_OK;
}
static void
iw_init_sock(struct iw_cm_id *cm_id)
{
struct sockopt sopt;
struct socket *so = cm_id->so;
int on = 1;
SOCK_LOCK(so);
soupcall_set(so, SO_RCV, iw_so_upcall, cm_id);
so->so_state |= SS_NBIO;
SOCK_UNLOCK(so);
sopt.sopt_dir = SOPT_SET;
sopt.sopt_level = IPPROTO_TCP;
sopt.sopt_name = TCP_NODELAY;
sopt.sopt_val = (caddr_t)&on;
sopt.sopt_valsize = sizeof(on);
sopt.sopt_td = NULL;
sosetopt(so, &sopt);
}
static int
iw_close_socket(struct iw_cm_id *cm_id, int close)
{
struct socket *so = cm_id->so;
int rc;
SOCK_LOCK(so);
soupcall_clear(so, SO_RCV);
SOCK_UNLOCK(so);
if (close)
rc = soclose(so);
else
rc = soshutdown(so, SHUT_WR | SHUT_RD);
cm_id->so = NULL;
return rc;
}
static int
iw_create_listen(struct iw_cm_id *cm_id, int backlog)
{
int rc;
iw_init_sock(cm_id);
rc = solisten(cm_id->so, backlog, curthread);
if (rc != 0)
iw_close_socket(cm_id, 0);
return rc;
}
static int
iw_destroy_listen(struct iw_cm_id *cm_id)
{
int rc;
rc = iw_close_socket(cm_id, 0);
return rc;
}
/*
* CM_ID <-- DESTROYING
*
* Clean up all resources associated with the connection and release
* the initial reference taken by iw_create_cm_id.
*/
static void destroy_cm_id(struct iw_cm_id *cm_id)
{
struct iwcm_id_private *cm_id_priv;
unsigned long flags;
int ret = 0, refcnt;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
/*
* Wait if we're currently in a connect or accept downcall. A
* listening endpoint should never block here.
*/
wait_event(cm_id_priv->connect_wait,
!test_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags));
spin_lock_irqsave(&cm_id_priv->lock, flags);
switch (cm_id_priv->state) {
case IW_CM_STATE_LISTEN:
cm_id_priv->state = IW_CM_STATE_DESTROYING;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
if (rdma_cma_any_addr((struct sockaddr *)&cm_id->local_addr)) {
refcnt =
rem_port_from_listenlist(cm_id->local_addr.sin_port);
if (refcnt == 0)
ret = iw_destroy_listen(cm_id);
cm_id->device->iwcm->destroy_listen_ep(cm_id);
} else {
ret = iw_destroy_listen(cm_id);
cm_id->device->iwcm->destroy_listen_ep(cm_id);
}
spin_lock_irqsave(&cm_id_priv->lock, flags);
break;
case IW_CM_STATE_ESTABLISHED:
cm_id_priv->state = IW_CM_STATE_DESTROYING;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
/* Abrupt close of the connection */
(void)iwcm_modify_qp_err(cm_id_priv->qp);
spin_lock_irqsave(&cm_id_priv->lock, flags);
break;
case IW_CM_STATE_IDLE:
case IW_CM_STATE_CLOSING:
cm_id_priv->state = IW_CM_STATE_DESTROYING;
break;
case IW_CM_STATE_CONN_RECV:
/*
* App called destroy before/without calling accept after
* receiving connection request event notification or
* returned non zero from the event callback function.
* In either case, must tell the provider to reject.
*/
cm_id_priv->state = IW_CM_STATE_DESTROYING;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
cm_id->device->iwcm->reject(cm_id, NULL, 0);
spin_lock_irqsave(&cm_id_priv->lock, flags);
break;
case IW_CM_STATE_CONN_SENT:
case IW_CM_STATE_DESTROYING:
default:
BUG();
break;
}
if (cm_id_priv->qp) {
cm_id_priv->id.device->iwcm->rem_ref(cm_id_priv->qp);
cm_id_priv->qp = NULL;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
(void)iwcm_deref_id(cm_id_priv);
}
/*
* This function is only called by the application thread and cannot
* be called by the event thread. The function will wait for all
* references to be released on the cm_id and then kfree the cm_id
* object.
*/
void iw_destroy_cm_id(struct iw_cm_id *cm_id)
{
struct iwcm_id_private *cm_id_priv;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
BUG_ON(test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags));
destroy_cm_id(cm_id);
wait_for_completion(&cm_id_priv->destroy_comp);
free_cm_id(cm_id_priv);
}
EXPORT_SYMBOL(iw_destroy_cm_id);
/*
* CM_ID <-- LISTEN
*
* Start listening for connect requests. Generates one CONNECT_REQUEST
* event for each inbound connect request.
*/
int iw_cm_listen(struct iw_cm_id *cm_id, int backlog)
{
struct iwcm_id_private *cm_id_priv;
unsigned long flags;
int ret, refcnt;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
ret = alloc_work_entries(cm_id_priv, backlog);
if (ret)
return ret;
spin_lock_irqsave(&cm_id_priv->lock, flags);
switch (cm_id_priv->state) {
case IW_CM_STATE_IDLE:
cm_id_priv->state = IW_CM_STATE_LISTEN;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
if (rdma_cma_any_addr((struct sockaddr *)&cm_id->local_addr)) {
refcnt =
add_port_to_listenlist(cm_id->local_addr.sin_port);
if (refcnt == 1) {
ret = iw_create_listen(cm_id, backlog);
} else if (refcnt <= 0) {
ret = -EINVAL;
} else {
/* if refcnt > 1, a socket listener created
* already. And we need not create socket
* listener on other rdma devices/listen cm_id's
* due to TOE. That is when a socket listener is
* created with INADDR_ANY all registered TOE
* devices will get a call to start
* hardware listeners.
*/
}
} else {
ret = iw_create_listen(cm_id, backlog);
}
if (!ret)
cm_id->device->iwcm->create_listen_ep(cm_id, backlog);
else
cm_id_priv->state = IW_CM_STATE_IDLE;
spin_lock_irqsave(&cm_id_priv->lock, flags);
break;
default:
ret = -EINVAL;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
return ret;
}
EXPORT_SYMBOL(iw_cm_listen);
/*
* CM_ID <-- IDLE
*
* Rejects an inbound connection request. No events are generated.
*/
int iw_cm_reject(struct iw_cm_id *cm_id,
const void *private_data,
u8 private_data_len)
{
struct iwcm_id_private *cm_id_priv;
unsigned long flags;
int ret;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
set_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->state != IW_CM_STATE_CONN_RECV) {
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
return -EINVAL;
}
cm_id_priv->state = IW_CM_STATE_IDLE;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = cm_id->device->iwcm->reject(cm_id, private_data,
private_data_len);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
return ret;
}
EXPORT_SYMBOL(iw_cm_reject);
/*
* CM_ID <-- ESTABLISHED
*
* Accepts an inbound connection request and generates an ESTABLISHED
* event. Callers of iw_cm_disconnect and iw_destroy_cm_id will block
* until the ESTABLISHED event is received from the provider.
*/
int iw_cm_accept(struct iw_cm_id *cm_id,
struct iw_cm_conn_param *iw_param)
{
struct iwcm_id_private *cm_id_priv;
struct ib_qp *qp;
unsigned long flags;
int ret;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
set_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->state != IW_CM_STATE_CONN_RECV) {
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
return -EINVAL;
}
/* Get the ib_qp given the QPN */
qp = cm_id->device->iwcm->get_qp(cm_id->device, iw_param->qpn);
if (!qp) {
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
return -EINVAL;
}
cm_id->device->iwcm->add_ref(qp);
cm_id_priv->qp = qp;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = cm_id->device->iwcm->accept(cm_id, iw_param);
if (ret) {
/* An error on accept precludes provider events */
BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV);
cm_id_priv->state = IW_CM_STATE_IDLE;
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->qp) {
cm_id->device->iwcm->rem_ref(qp);
cm_id_priv->qp = NULL;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
}
return ret;
}
EXPORT_SYMBOL(iw_cm_accept);
/*
* Active Side: CM_ID <-- CONN_SENT
*
* If successful, results in the generation of a CONNECT_REPLY
* event. iw_cm_disconnect and iw_cm_destroy will block until the
* CONNECT_REPLY event is received from the provider.
*/
int iw_cm_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
{
struct iwcm_id_private *cm_id_priv;
int ret;
unsigned long flags;
struct ib_qp *qp;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
ret = alloc_work_entries(cm_id_priv, 4);
if (ret)
return ret;
set_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->state != IW_CM_STATE_IDLE) {
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
return -EINVAL;
}
/* Get the ib_qp given the QPN */
qp = cm_id->device->iwcm->get_qp(cm_id->device, iw_param->qpn);
if (!qp) {
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
return -EINVAL;
}
cm_id->device->iwcm->add_ref(qp);
cm_id_priv->qp = qp;
cm_id_priv->state = IW_CM_STATE_CONN_SENT;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = cm_id->device->iwcm->connect(cm_id, iw_param);
if (ret) {
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->qp) {
cm_id->device->iwcm->rem_ref(qp);
cm_id_priv->qp = NULL;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_SENT);
cm_id_priv->state = IW_CM_STATE_IDLE;
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
wake_up_all(&cm_id_priv->connect_wait);
}
return ret;
}
EXPORT_SYMBOL(iw_cm_connect);
/*
* Passive Side: new CM_ID <-- CONN_RECV
*
* Handles an inbound connect request. The function creates a new
* iw_cm_id to represent the new connection and inherits the client
* callback function and other attributes from the listening parent.
*
* The work item contains a pointer to the listen_cm_id and the event. The
* listen_cm_id contains the client cm_handler, context and
* device. These are copied when the device is cloned. The event
* contains the new four tuple.
*
* An error on the child should not affect the parent, so this
* function does not return a value.
*/
static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
struct iw_cm_event *iw_event)
{
unsigned long flags;
struct iw_cm_id *cm_id;
struct iwcm_id_private *cm_id_priv;
int ret;
/*
* The provider should never generate a connection request
* event with a bad status.
*/
BUG_ON(iw_event->status);
cm_id = iw_create_cm_id(listen_id_priv->id.device,
iw_event->so,
listen_id_priv->id.cm_handler,
listen_id_priv->id.context);
/* If the cm_id could not be created, ignore the request */
if (IS_ERR(cm_id))
goto out;
cm_id->provider_data = iw_event->provider_data;
cm_id->local_addr = iw_event->local_addr;
cm_id->remote_addr = iw_event->remote_addr;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
cm_id_priv->state = IW_CM_STATE_CONN_RECV;
/*
* We could be destroying the listening id. If so, ignore this
* upcall.
*/
spin_lock_irqsave(&listen_id_priv->lock, flags);
if (listen_id_priv->state != IW_CM_STATE_LISTEN) {
spin_unlock_irqrestore(&listen_id_priv->lock, flags);
iw_cm_reject(cm_id, NULL, 0);
iw_destroy_cm_id(cm_id);
goto out;
}
spin_unlock_irqrestore(&listen_id_priv->lock, flags);
ret = alloc_work_entries(cm_id_priv, 3);
if (ret) {
iw_cm_reject(cm_id, NULL, 0);
iw_destroy_cm_id(cm_id);
goto out;
}
/* Call the client CM handler */
ret = cm_id->cm_handler(cm_id, iw_event);
if (ret) {
iw_cm_reject(cm_id, NULL, 0);
set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
destroy_cm_id(cm_id);
if (atomic_read(&cm_id_priv->refcount)==0)
free_cm_id(cm_id_priv);
}
out:
if (iw_event->private_data_len)
kfree(iw_event->private_data);
}
/*
* Passive Side: CM_ID <-- ESTABLISHED
*
* The provider generated an ESTABLISHED event which means that
* the MPA negotion has completed successfully and we are now in MPA
* FPDU mode.
*
* This event can only be received in the CONN_RECV state. If the
* remote peer closed, the ESTABLISHED event would be received followed
* by the CLOSE event. If the app closes, it will block until we wake
* it up after processing this event.
*/
static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
{
unsigned long flags;
int ret;
spin_lock_irqsave(&cm_id_priv->lock, flags);
/*
* We clear the CONNECT_WAIT bit here to allow the callback
* function to call iw_cm_disconnect. Calling iw_destroy_cm_id
* from a callback handler is not allowed.
*/
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV);
cm_id_priv->state = IW_CM_STATE_ESTABLISHED;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event);
wake_up_all(&cm_id_priv->connect_wait);
return ret;
}
/*
* Active Side: CM_ID <-- ESTABLISHED
*
* The app has called connect and is waiting for the established event to
* post it's requests to the server. This event will wake up anyone
* blocked in iw_cm_disconnect or iw_destroy_id.
*/
static int cm_conn_rep_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
{
unsigned long flags;
int ret;
spin_lock_irqsave(&cm_id_priv->lock, flags);
/*
* Clear the connect wait bit so a callback function calling
* iw_cm_disconnect will not wait and deadlock this thread
*/
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_SENT);
if (iw_event->status == 0) {
cm_id_priv->id.local_addr = iw_event->local_addr;
cm_id_priv->id.remote_addr = iw_event->remote_addr;
cm_id_priv->state = IW_CM_STATE_ESTABLISHED;
} else {
/* REJECTED or RESET */
cm_id_priv->id.device->iwcm->rem_ref(cm_id_priv->qp);
cm_id_priv->qp = NULL;
cm_id_priv->state = IW_CM_STATE_IDLE;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event);
if (iw_event->private_data_len)
kfree(iw_event->private_data);
/* Wake up waiters on connect complete */
wake_up_all(&cm_id_priv->connect_wait);
return ret;
}
/*
* CM_ID <-- CLOSING
*
* If in the ESTABLISHED state, move to CLOSING.
*/
static void cm_disconnect_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
{
unsigned long flags;
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->state == IW_CM_STATE_ESTABLISHED)
cm_id_priv->state = IW_CM_STATE_CLOSING;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
}
/*
* CM_ID <-- IDLE
*
* If in the ESTBLISHED or CLOSING states, the QP will have have been
* moved by the provider to the ERR state. Disassociate the CM_ID from
* the QP, move to IDLE, and remove the 'connected' reference.
*
* If in some other state, the cm_id was destroyed asynchronously.
* This is the last reference that will result in waking up
* the app thread blocked in iw_destroy_cm_id.
*/
static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
{
unsigned long flags;
int ret = 0;
spin_lock_irqsave(&cm_id_priv->lock, flags);
if (cm_id_priv->qp) {
cm_id_priv->id.device->iwcm->rem_ref(cm_id_priv->qp);
cm_id_priv->qp = NULL;
}
switch (cm_id_priv->state) {
case IW_CM_STATE_ESTABLISHED:
case IW_CM_STATE_CLOSING:
cm_id_priv->state = IW_CM_STATE_IDLE;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event);
spin_lock_irqsave(&cm_id_priv->lock, flags);
break;
case IW_CM_STATE_DESTROYING:
break;
default:
BUG();
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
return ret;
}
static int process_event(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
{
int ret = 0;
switch (iw_event->event) {
case IW_CM_EVENT_CONNECT_REQUEST:
cm_conn_req_handler(cm_id_priv, iw_event);
break;
case IW_CM_EVENT_CONNECT_REPLY:
ret = cm_conn_rep_handler(cm_id_priv, iw_event);
break;
case IW_CM_EVENT_ESTABLISHED:
ret = cm_conn_est_handler(cm_id_priv, iw_event);
break;
case IW_CM_EVENT_DISCONNECT:
cm_disconnect_handler(cm_id_priv, iw_event);
break;
case IW_CM_EVENT_CLOSE:
ret = cm_close_handler(cm_id_priv, iw_event);
break;
default:
BUG();
}
return ret;
}
/*
* Process events on the work_list for the cm_id. If the callback
* function requests that the cm_id be deleted, a flag is set in the
* cm_id flags to indicate that when the last reference is
* removed, the cm_id is to be destroyed. This is necessary to
* distinguish between an object that will be destroyed by the app
* thread asleep on the destroy_comp list vs. an object destroyed
* here synchronously when the last reference is removed.
*/
static void cm_work_handler(struct work_struct *_work)
{
struct iwcm_work *work = container_of(_work, struct iwcm_work, work);
struct iw_cm_event levent;
struct iwcm_id_private *cm_id_priv = work->cm_id;
unsigned long flags;
int empty;
int ret = 0;
int destroy_id;
spin_lock_irqsave(&cm_id_priv->lock, flags);
empty = list_empty(&cm_id_priv->work_list);
while (!empty) {
work = list_entry(cm_id_priv->work_list.next,
struct iwcm_work, list);
list_del_init(&work->list);
empty = list_empty(&cm_id_priv->work_list);
levent = work->event;
put_work(work);
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
ret = process_event(cm_id_priv, &levent);
if (ret) {
set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
destroy_cm_id(&cm_id_priv->id);
}
BUG_ON(atomic_read(&cm_id_priv->refcount)==0);
destroy_id = test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags);
if (iwcm_deref_id(cm_id_priv)) {
if (destroy_id) {
BUG_ON(!list_empty(&cm_id_priv->work_list));
free_cm_id(cm_id_priv);
}
return;
}
if (empty)
return;
spin_lock_irqsave(&cm_id_priv->lock, flags);
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
}
/*
* This function is called on interrupt context. Schedule events on
* the iwcm_wq thread to allow callback functions to downcall into
* the CM and/or block. Events are queued to a per-CM_ID
* work_list. If this is the first event on the work_list, the work
* element is also queued on the iwcm_wq thread.
*
* Each event holds a reference on the cm_id. Until the last posted
* event has been delivered and processed, the cm_id cannot be
* deleted.
*
* Returns:
* 0 - the event was handled.
* -ENOMEM - the event was not handled due to lack of resources.
*/
static int cm_event_handler(struct iw_cm_id *cm_id,
struct iw_cm_event *iw_event)
{
struct iwcm_work *work;
struct iwcm_id_private *cm_id_priv;
unsigned long flags;
int ret = 0;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
spin_lock_irqsave(&cm_id_priv->lock, flags);
work = get_work(cm_id_priv);
if (!work) {
ret = -ENOMEM;
goto out;
}
INIT_WORK(&work->work, cm_work_handler);
work->cm_id = cm_id_priv;
work->event = *iw_event;
if ((work->event.event == IW_CM_EVENT_CONNECT_REQUEST ||
work->event.event == IW_CM_EVENT_CONNECT_REPLY) &&
work->event.private_data_len) {
ret = copy_private_data(&work->event);
if (ret) {
put_work(work);
goto out;
}
}
atomic_inc(&cm_id_priv->refcount);
if (list_empty(&cm_id_priv->work_list)) {
list_add_tail(&work->list, &cm_id_priv->work_list);
queue_work(iwcm_wq, &work->work);
} else
list_add_tail(&work->list, &cm_id_priv->work_list);
out:
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
return ret;
}
static int iwcm_init_qp_init_attr(struct iwcm_id_private *cm_id_priv,
struct ib_qp_attr *qp_attr,
int *qp_attr_mask)
{
unsigned long flags;
int ret;
spin_lock_irqsave(&cm_id_priv->lock, flags);
switch (cm_id_priv->state) {
case IW_CM_STATE_IDLE:
case IW_CM_STATE_CONN_SENT:
case IW_CM_STATE_CONN_RECV:
case IW_CM_STATE_ESTABLISHED:
*qp_attr_mask = IB_QP_STATE | IB_QP_ACCESS_FLAGS;
qp_attr->qp_access_flags = IB_ACCESS_REMOTE_WRITE|
IB_ACCESS_REMOTE_READ;
ret = 0;
break;
default:
ret = -EINVAL;
break;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
return ret;
}
static int iwcm_init_qp_rts_attr(struct iwcm_id_private *cm_id_priv,
struct ib_qp_attr *qp_attr,
int *qp_attr_mask)
{
unsigned long flags;
int ret;
spin_lock_irqsave(&cm_id_priv->lock, flags);
switch (cm_id_priv->state) {
case IW_CM_STATE_IDLE:
case IW_CM_STATE_CONN_SENT:
case IW_CM_STATE_CONN_RECV:
case IW_CM_STATE_ESTABLISHED:
*qp_attr_mask = 0;
ret = 0;
break;
default:
ret = -EINVAL;
break;
}
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
return ret;
}
int iw_cm_init_qp_attr(struct iw_cm_id *cm_id,
struct ib_qp_attr *qp_attr,
int *qp_attr_mask)
{
struct iwcm_id_private *cm_id_priv;
int ret;
cm_id_priv = container_of(cm_id, struct iwcm_id_private, id);
switch (qp_attr->qp_state) {
case IB_QPS_INIT:
case IB_QPS_RTR:
ret = iwcm_init_qp_init_attr(cm_id_priv,
qp_attr, qp_attr_mask);
break;
case IB_QPS_RTS:
ret = iwcm_init_qp_rts_attr(cm_id_priv,
qp_attr, qp_attr_mask);
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
EXPORT_SYMBOL(iw_cm_init_qp_attr);
static int __init iw_cm_init(void)
{
iwcm_wq = create_singlethread_workqueue("iw_cm_wq");
if (!iwcm_wq)
return -ENOMEM;
return 0;
}
static void __exit iw_cm_cleanup(void)
{
destroy_workqueue(iwcm_wq);
}
module_init(iw_cm_init);
module_exit(iw_cm_cleanup);
|