11/*
22 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
33 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4+ * Copyright (c) 2005 Cisco Systems, Inc. All rights reserved.
45 *
56 * This software is available to you under a choice of one of two
67 * licenses. You may choose to be licensed under the terms of the GNU
@@ -742,6 +743,7 @@ static int mthca_alloc_cq_buf(struct mthca_dev *dev, int size,
742743}
743744
744745int mthca_init_cq (struct mthca_dev * dev , int nent ,
746+ struct mthca_ucontext * ctx , u32 pdn ,
745747 struct mthca_cq * cq )
746748{
747749 int size = nent * MTHCA_CQ_ENTRY_SIZE ;
@@ -753,30 +755,33 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
753755
754756 might_sleep ();
755757
756- cq -> ibcq .cqe = nent - 1 ;
758+ cq -> ibcq .cqe = nent - 1 ;
759+ cq -> is_kernel = !ctx ;
757760
758761 cq -> cqn = mthca_alloc (& dev -> cq_table .alloc );
759762 if (cq -> cqn == -1 )
760763 return - ENOMEM ;
761764
762765 if (mthca_is_memfree (dev )) {
763- cq -> arm_sn = 1 ;
764-
765766 err = mthca_table_get (dev , dev -> cq_table .table , cq -> cqn );
766767 if (err )
767768 goto err_out ;
768769
769- err = - ENOMEM ;
770+ if (cq -> is_kernel ) {
771+ cq -> arm_sn = 1 ;
772+
773+ err = - ENOMEM ;
770774
771- cq -> set_ci_db_index = mthca_alloc_db (dev , MTHCA_DB_TYPE_CQ_SET_CI ,
772- cq -> cqn , & cq -> set_ci_db );
773- if (cq -> set_ci_db_index < 0 )
774- goto err_out_icm ;
775+ cq -> set_ci_db_index = mthca_alloc_db (dev , MTHCA_DB_TYPE_CQ_SET_CI ,
776+ cq -> cqn , & cq -> set_ci_db );
777+ if (cq -> set_ci_db_index < 0 )
778+ goto err_out_icm ;
775779
776- cq -> arm_db_index = mthca_alloc_db (dev , MTHCA_DB_TYPE_CQ_ARM ,
777- cq -> cqn , & cq -> arm_db );
778- if (cq -> arm_db_index < 0 )
779- goto err_out_ci ;
780+ cq -> arm_db_index = mthca_alloc_db (dev , MTHCA_DB_TYPE_CQ_ARM ,
781+ cq -> cqn , & cq -> arm_db );
782+ if (cq -> arm_db_index < 0 )
783+ goto err_out_ci ;
784+ }
780785 }
781786
782787 mailbox = mthca_alloc_mailbox (dev , GFP_KERNEL );
@@ -785,12 +790,14 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
785790
786791 cq_context = mailbox -> buf ;
787792
788- err = mthca_alloc_cq_buf (dev , size , cq );
789- if (err )
790- goto err_out_mailbox ;
793+ if (cq -> is_kernel ) {
794+ err = mthca_alloc_cq_buf (dev , size , cq );
795+ if (err )
796+ goto err_out_mailbox ;
791797
792- for (i = 0 ; i < nent ; ++ i )
793- set_cqe_hw (get_cqe (cq , i ));
798+ for (i = 0 ; i < nent ; ++ i )
799+ set_cqe_hw (get_cqe (cq , i ));
800+ }
794801
795802 spin_lock_init (& cq -> lock );
796803 atomic_set (& cq -> refcount , 1 );
@@ -801,11 +808,14 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
801808 MTHCA_CQ_STATE_DISARMED |
802809 MTHCA_CQ_FLAG_TR );
803810 cq_context -> start = cpu_to_be64 (0 );
804- cq_context -> logsize_usrpage = cpu_to_be32 ((ffs (nent ) - 1 ) << 24 |
805- dev -> driver_uar .index );
811+ cq_context -> logsize_usrpage = cpu_to_be32 ((ffs (nent ) - 1 ) << 24 );
812+ if (ctx )
813+ cq_context -> logsize_usrpage |= cpu_to_be32 (ctx -> uar .index );
814+ else
815+ cq_context -> logsize_usrpage |= cpu_to_be32 (dev -> driver_uar .index );
806816 cq_context -> error_eqn = cpu_to_be32 (dev -> eq_table .eq [MTHCA_EQ_ASYNC ].eqn );
807817 cq_context -> comp_eqn = cpu_to_be32 (dev -> eq_table .eq [MTHCA_EQ_COMP ].eqn );
808- cq_context -> pd = cpu_to_be32 (dev -> driver_pd . pd_num );
818+ cq_context -> pd = cpu_to_be32 (pdn );
809819 cq_context -> lkey = cpu_to_be32 (cq -> mr .ibmr .lkey );
810820 cq_context -> cqn = cpu_to_be32 (cq -> cqn );
811821
@@ -843,18 +853,20 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
843853 return 0 ;
844854
845855err_out_free_mr :
846- mthca_free_mr (dev , & cq -> mr );
847- mthca_free_cq_buf (dev , cq );
856+ if (cq -> is_kernel ) {
857+ mthca_free_mr (dev , & cq -> mr );
858+ mthca_free_cq_buf (dev , cq );
859+ }
848860
849861err_out_mailbox :
850862 mthca_free_mailbox (dev , mailbox );
851863
852864err_out_arm :
853- if (mthca_is_memfree (dev ))
865+ if (cq -> is_kernel && mthca_is_memfree (dev ))
854866 mthca_free_db (dev , MTHCA_DB_TYPE_CQ_ARM , cq -> arm_db_index );
855867
856868err_out_ci :
857- if (mthca_is_memfree (dev ))
869+ if (cq -> is_kernel && mthca_is_memfree (dev ))
858870 mthca_free_db (dev , MTHCA_DB_TYPE_CQ_SET_CI , cq -> set_ci_db_index );
859871
860872err_out_icm :
@@ -892,7 +904,8 @@ void mthca_free_cq(struct mthca_dev *dev,
892904 int j ;
893905
894906 printk (KERN_ERR "context for CQN %x (cons index %x, next sw %d)\n" ,
895- cq -> cqn , cq -> cons_index , !!next_cqe_sw (cq ));
907+ cq -> cqn , cq -> cons_index ,
908+ cq -> is_kernel ? !!next_cqe_sw (cq ) : 0 );
896909 for (j = 0 ; j < 16 ; ++ j )
897910 printk (KERN_ERR "[%2x] %08x\n" , j * 4 , be32_to_cpu (ctx [j ]));
898911 }
@@ -910,12 +923,13 @@ void mthca_free_cq(struct mthca_dev *dev,
910923 atomic_dec (& cq -> refcount );
911924 wait_event (cq -> wait , !atomic_read (& cq -> refcount ));
912925
913- mthca_free_mr (dev , & cq -> mr );
914- mthca_free_cq_buf (dev , cq );
915-
916- if (mthca_is_memfree (dev )) {
917- mthca_free_db (dev , MTHCA_DB_TYPE_CQ_ARM , cq -> arm_db_index );
918- mthca_free_db (dev , MTHCA_DB_TYPE_CQ_SET_CI , cq -> set_ci_db_index );
926+ if (cq -> is_kernel ) {
927+ mthca_free_mr (dev , & cq -> mr );
928+ mthca_free_cq_buf (dev , cq );
929+ if (mthca_is_memfree (dev )) {
930+ mthca_free_db (dev , MTHCA_DB_TYPE_CQ_ARM , cq -> arm_db_index );
931+ mthca_free_db (dev , MTHCA_DB_TYPE_CQ_SET_CI , cq -> set_ci_db_index );
932+ }
919933 }
920934
921935 mthca_table_put (dev , dev -> cq_table .table , cq -> cqn );
0 commit comments