Lines Matching refs:cm_id_priv
92 static struct iwcm_work *get_work(struct iwcm_id_private *cm_id_priv) in get_work() argument
96 if (list_empty(&cm_id_priv->work_free_list)) in get_work()
98 work = list_entry(cm_id_priv->work_free_list.next, struct iwcm_work, in get_work()
109 static void dealloc_work_entries(struct iwcm_id_private *cm_id_priv) in dealloc_work_entries() argument
113 list_for_each_safe(e, tmp, &cm_id_priv->work_free_list) in dealloc_work_entries()
117 static int alloc_work_entries(struct iwcm_id_private *cm_id_priv, int count) in alloc_work_entries() argument
121 BUG_ON(!list_empty(&cm_id_priv->work_free_list)); in alloc_work_entries()
125 dealloc_work_entries(cm_id_priv); in alloc_work_entries()
128 work->cm_id = cm_id_priv; in alloc_work_entries()
151 static void free_cm_id(struct iwcm_id_private *cm_id_priv) in free_cm_id() argument
153 dealloc_work_entries(cm_id_priv); in free_cm_id()
154 kfree(cm_id_priv); in free_cm_id()
162 static int iwcm_deref_id(struct iwcm_id_private *cm_id_priv) in iwcm_deref_id() argument
164 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); in iwcm_deref_id()
165 if (atomic_dec_and_test(&cm_id_priv->refcount)) { in iwcm_deref_id()
166 BUG_ON(!list_empty(&cm_id_priv->work_list)); in iwcm_deref_id()
167 complete(&cm_id_priv->destroy_comp); in iwcm_deref_id()
176 struct iwcm_id_private *cm_id_priv; in add_ref() local
177 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in add_ref()
178 atomic_inc(&cm_id_priv->refcount); in add_ref()
183 struct iwcm_id_private *cm_id_priv; in rem_ref() local
184 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in rem_ref()
185 if (iwcm_deref_id(cm_id_priv) && in rem_ref()
186 test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)) { in rem_ref()
187 BUG_ON(!list_empty(&cm_id_priv->work_list)); in rem_ref()
188 free_cm_id(cm_id_priv); in rem_ref()
198 struct iwcm_id_private *cm_id_priv; in iw_create_cm_id() local
200 cm_id_priv = kzalloc(sizeof(*cm_id_priv), GFP_KERNEL); in iw_create_cm_id()
201 if (!cm_id_priv) in iw_create_cm_id()
204 cm_id_priv->state = IW_CM_STATE_IDLE; in iw_create_cm_id()
205 cm_id_priv->id.device = device; in iw_create_cm_id()
206 cm_id_priv->id.cm_handler = cm_handler; in iw_create_cm_id()
207 cm_id_priv->id.context = context; in iw_create_cm_id()
208 cm_id_priv->id.event_handler = cm_event_handler; in iw_create_cm_id()
209 cm_id_priv->id.add_ref = add_ref; in iw_create_cm_id()
210 cm_id_priv->id.rem_ref = rem_ref; in iw_create_cm_id()
211 spin_lock_init(&cm_id_priv->lock); in iw_create_cm_id()
212 atomic_set(&cm_id_priv->refcount, 1); in iw_create_cm_id()
213 init_waitqueue_head(&cm_id_priv->connect_wait); in iw_create_cm_id()
214 init_completion(&cm_id_priv->destroy_comp); in iw_create_cm_id()
215 INIT_LIST_HEAD(&cm_id_priv->work_list); in iw_create_cm_id()
216 INIT_LIST_HEAD(&cm_id_priv->work_free_list); in iw_create_cm_id()
218 return &cm_id_priv->id; in iw_create_cm_id()
261 struct iwcm_id_private *cm_id_priv; in iw_cm_disconnect() local
266 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_cm_disconnect()
268 wait_event(cm_id_priv->connect_wait, in iw_cm_disconnect()
269 !test_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags)); in iw_cm_disconnect()
271 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_disconnect()
272 switch (cm_id_priv->state) { in iw_cm_disconnect()
274 cm_id_priv->state = IW_CM_STATE_CLOSING; in iw_cm_disconnect()
277 if (cm_id_priv->qp) in iw_cm_disconnect()
278 qp = cm_id_priv->qp; in iw_cm_disconnect()
301 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_disconnect()
328 struct iwcm_id_private *cm_id_priv; in destroy_cm_id() local
332 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in destroy_cm_id()
337 wait_event(cm_id_priv->connect_wait, in destroy_cm_id()
338 !test_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags)); in destroy_cm_id()
340 spin_lock_irqsave(&cm_id_priv->lock, flags); in destroy_cm_id()
341 switch (cm_id_priv->state) { in destroy_cm_id()
343 cm_id_priv->state = IW_CM_STATE_DESTROYING; in destroy_cm_id()
344 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in destroy_cm_id()
347 spin_lock_irqsave(&cm_id_priv->lock, flags); in destroy_cm_id()
350 cm_id_priv->state = IW_CM_STATE_DESTROYING; in destroy_cm_id()
351 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in destroy_cm_id()
353 (void)iwcm_modify_qp_err(cm_id_priv->qp); in destroy_cm_id()
354 spin_lock_irqsave(&cm_id_priv->lock, flags); in destroy_cm_id()
358 cm_id_priv->state = IW_CM_STATE_DESTROYING; in destroy_cm_id()
367 cm_id_priv->state = IW_CM_STATE_DESTROYING; in destroy_cm_id()
368 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in destroy_cm_id()
370 spin_lock_irqsave(&cm_id_priv->lock, flags); in destroy_cm_id()
378 if (cm_id_priv->qp) { in destroy_cm_id()
379 cm_id_priv->id.device->iwcm->rem_ref(cm_id_priv->qp); in destroy_cm_id()
380 cm_id_priv->qp = NULL; in destroy_cm_id()
382 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in destroy_cm_id()
384 (void)iwcm_deref_id(cm_id_priv); in destroy_cm_id()
395 struct iwcm_id_private *cm_id_priv; in iw_destroy_cm_id() local
397 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_destroy_cm_id()
398 BUG_ON(test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags)); in iw_destroy_cm_id()
402 wait_for_completion(&cm_id_priv->destroy_comp); in iw_destroy_cm_id()
404 free_cm_id(cm_id_priv); in iw_destroy_cm_id()
416 struct iwcm_id_private *cm_id_priv; in iw_cm_listen() local
420 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_cm_listen()
422 ret = alloc_work_entries(cm_id_priv, backlog); in iw_cm_listen()
426 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_listen()
427 switch (cm_id_priv->state) { in iw_cm_listen()
429 cm_id_priv->state = IW_CM_STATE_LISTEN; in iw_cm_listen()
430 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_listen()
433 cm_id_priv->state = IW_CM_STATE_IDLE; in iw_cm_listen()
434 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_listen()
439 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_listen()
454 struct iwcm_id_private *cm_id_priv; in iw_cm_reject() local
458 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_cm_reject()
459 set_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_reject()
461 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_reject()
462 if (cm_id_priv->state != IW_CM_STATE_CONN_RECV) { in iw_cm_reject()
463 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_reject()
464 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_reject()
465 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_reject()
468 cm_id_priv->state = IW_CM_STATE_IDLE; in iw_cm_reject()
469 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_reject()
474 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_reject()
475 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_reject()
491 struct iwcm_id_private *cm_id_priv; in iw_cm_accept() local
496 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_cm_accept()
497 set_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_accept()
499 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_accept()
500 if (cm_id_priv->state != IW_CM_STATE_CONN_RECV) { in iw_cm_accept()
501 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_accept()
502 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_accept()
503 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_accept()
509 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_accept()
510 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_accept()
511 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_accept()
515 cm_id_priv->qp = qp; in iw_cm_accept()
516 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_accept()
521 BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV); in iw_cm_accept()
522 cm_id_priv->state = IW_CM_STATE_IDLE; in iw_cm_accept()
523 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_accept()
524 if (cm_id_priv->qp) { in iw_cm_accept()
526 cm_id_priv->qp = NULL; in iw_cm_accept()
528 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_accept()
529 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_accept()
530 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_accept()
546 struct iwcm_id_private *cm_id_priv; in iw_cm_connect() local
551 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_cm_connect()
553 ret = alloc_work_entries(cm_id_priv, 4); in iw_cm_connect()
557 set_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_connect()
558 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_connect()
560 if (cm_id_priv->state != IW_CM_STATE_IDLE) { in iw_cm_connect()
561 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_connect()
562 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_connect()
563 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_connect()
570 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_connect()
571 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_connect()
572 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_connect()
576 cm_id_priv->qp = qp; in iw_cm_connect()
577 cm_id_priv->state = IW_CM_STATE_CONN_SENT; in iw_cm_connect()
578 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_connect()
582 spin_lock_irqsave(&cm_id_priv->lock, flags); in iw_cm_connect()
583 if (cm_id_priv->qp) { in iw_cm_connect()
585 cm_id_priv->qp = NULL; in iw_cm_connect()
587 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iw_cm_connect()
588 BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_SENT); in iw_cm_connect()
589 cm_id_priv->state = IW_CM_STATE_IDLE; in iw_cm_connect()
590 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in iw_cm_connect()
591 wake_up_all(&cm_id_priv->connect_wait); in iw_cm_connect()
618 struct iwcm_id_private *cm_id_priv; in cm_conn_req_handler() local
638 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in cm_conn_req_handler()
639 cm_id_priv->state = IW_CM_STATE_CONN_RECV; in cm_conn_req_handler()
654 ret = alloc_work_entries(cm_id_priv, 3); in cm_conn_req_handler()
665 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags); in cm_conn_req_handler()
667 if (atomic_read(&cm_id_priv->refcount)==0) in cm_conn_req_handler()
668 free_cm_id(cm_id_priv); in cm_conn_req_handler()
688 static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv, in cm_conn_est_handler() argument
694 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_conn_est_handler()
701 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in cm_conn_est_handler()
702 BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV); in cm_conn_est_handler()
703 cm_id_priv->state = IW_CM_STATE_ESTABLISHED; in cm_conn_est_handler()
704 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_conn_est_handler()
705 ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event); in cm_conn_est_handler()
706 wake_up_all(&cm_id_priv->connect_wait); in cm_conn_est_handler()
718 static int cm_conn_rep_handler(struct iwcm_id_private *cm_id_priv, in cm_conn_rep_handler() argument
724 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_conn_rep_handler()
729 clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); in cm_conn_rep_handler()
730 BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_SENT); in cm_conn_rep_handler()
732 cm_id_priv->id.local_addr = iw_event->local_addr; in cm_conn_rep_handler()
733 cm_id_priv->id.remote_addr = iw_event->remote_addr; in cm_conn_rep_handler()
734 cm_id_priv->state = IW_CM_STATE_ESTABLISHED; in cm_conn_rep_handler()
737 cm_id_priv->id.device->iwcm->rem_ref(cm_id_priv->qp); in cm_conn_rep_handler()
738 cm_id_priv->qp = NULL; in cm_conn_rep_handler()
739 cm_id_priv->state = IW_CM_STATE_IDLE; in cm_conn_rep_handler()
741 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_conn_rep_handler()
742 ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event); in cm_conn_rep_handler()
748 wake_up_all(&cm_id_priv->connect_wait); in cm_conn_rep_handler()
758 static void cm_disconnect_handler(struct iwcm_id_private *cm_id_priv, in cm_disconnect_handler() argument
763 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_disconnect_handler()
764 if (cm_id_priv->state == IW_CM_STATE_ESTABLISHED) in cm_disconnect_handler()
765 cm_id_priv->state = IW_CM_STATE_CLOSING; in cm_disconnect_handler()
766 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_disconnect_handler()
780 static int cm_close_handler(struct iwcm_id_private *cm_id_priv, in cm_close_handler() argument
785 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_close_handler()
787 if (cm_id_priv->qp) { in cm_close_handler()
788 cm_id_priv->id.device->iwcm->rem_ref(cm_id_priv->qp); in cm_close_handler()
789 cm_id_priv->qp = NULL; in cm_close_handler()
791 switch (cm_id_priv->state) { in cm_close_handler()
794 cm_id_priv->state = IW_CM_STATE_IDLE; in cm_close_handler()
795 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_close_handler()
796 ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event); in cm_close_handler()
797 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_close_handler()
804 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_close_handler()
809 static int process_event(struct iwcm_id_private *cm_id_priv, in process_event() argument
816 cm_conn_req_handler(cm_id_priv, iw_event); in process_event()
819 ret = cm_conn_rep_handler(cm_id_priv, iw_event); in process_event()
822 ret = cm_conn_est_handler(cm_id_priv, iw_event); in process_event()
825 cm_disconnect_handler(cm_id_priv, iw_event); in process_event()
828 ret = cm_close_handler(cm_id_priv, iw_event); in process_event()
850 struct iwcm_id_private *cm_id_priv = work->cm_id; in cm_work_handler() local
856 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_work_handler()
857 empty = list_empty(&cm_id_priv->work_list); in cm_work_handler()
859 work = list_entry(cm_id_priv->work_list.next, in cm_work_handler()
862 empty = list_empty(&cm_id_priv->work_list); in cm_work_handler()
865 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_work_handler()
867 ret = process_event(cm_id_priv, &levent); in cm_work_handler()
869 set_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags); in cm_work_handler()
870 destroy_cm_id(&cm_id_priv->id); in cm_work_handler()
872 BUG_ON(atomic_read(&cm_id_priv->refcount)==0); in cm_work_handler()
873 destroy_id = test_bit(IWCM_F_CALLBACK_DESTROY, &cm_id_priv->flags); in cm_work_handler()
874 if (iwcm_deref_id(cm_id_priv)) { in cm_work_handler()
876 BUG_ON(!list_empty(&cm_id_priv->work_list)); in cm_work_handler()
877 free_cm_id(cm_id_priv); in cm_work_handler()
883 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_work_handler()
885 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_work_handler()
907 struct iwcm_id_private *cm_id_priv; in cm_event_handler() local
911 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in cm_event_handler()
913 spin_lock_irqsave(&cm_id_priv->lock, flags); in cm_event_handler()
914 work = get_work(cm_id_priv); in cm_event_handler()
921 work->cm_id = cm_id_priv; in cm_event_handler()
934 atomic_inc(&cm_id_priv->refcount); in cm_event_handler()
935 if (list_empty(&cm_id_priv->work_list)) { in cm_event_handler()
936 list_add_tail(&work->list, &cm_id_priv->work_list); in cm_event_handler()
939 list_add_tail(&work->list, &cm_id_priv->work_list); in cm_event_handler()
941 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in cm_event_handler()
945 static int iwcm_init_qp_init_attr(struct iwcm_id_private *cm_id_priv, in iwcm_init_qp_init_attr() argument
952 spin_lock_irqsave(&cm_id_priv->lock, flags); in iwcm_init_qp_init_attr()
953 switch (cm_id_priv->state) { in iwcm_init_qp_init_attr()
967 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iwcm_init_qp_init_attr()
971 static int iwcm_init_qp_rts_attr(struct iwcm_id_private *cm_id_priv, in iwcm_init_qp_rts_attr() argument
978 spin_lock_irqsave(&cm_id_priv->lock, flags); in iwcm_init_qp_rts_attr()
979 switch (cm_id_priv->state) { in iwcm_init_qp_rts_attr()
991 spin_unlock_irqrestore(&cm_id_priv->lock, flags); in iwcm_init_qp_rts_attr()
999 struct iwcm_id_private *cm_id_priv; in iw_cm_init_qp_attr() local
1002 cm_id_priv = container_of(cm_id, struct iwcm_id_private, id); in iw_cm_init_qp_attr()
1006 ret = iwcm_init_qp_init_attr(cm_id_priv, in iw_cm_init_qp_attr()
1010 ret = iwcm_init_qp_rts_attr(cm_id_priv, in iw_cm_init_qp_attr()