Print this page
5255 uts shouldn't open-code ISP2


  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * hermon_rsrc.c
  28  *    Hermon Resource Management Routines
  29  *
  30  *    Implements all the routines necessary for setup, teardown, and
  31  *    alloc/free of all Hermon resources, including those that are managed
  32  *    by Hermon hardware or which live in Hermon's direct attached DDR memory.
  33  */
  34 

  35 #include <sys/types.h>
  36 #include <sys/conf.h>
  37 #include <sys/ddi.h>
  38 #include <sys/sunddi.h>
  39 #include <sys/modctl.h>
  40 #include <sys/vmem.h>
  41 #include <sys/bitmap.h>
  42 
  43 #include <sys/ib/adapters/hermon/hermon.h>
  44 
  45 int hermon_rsrc_verbose = 0;
  46 
  47 /*
  48  * The following routines are used for initializing and destroying
  49  * the resource pools used by the Hermon resource allocation routines.
  50  * They consist of four classes of object:
  51  *
  52  * Mailboxes:  The "In" and "Out" mailbox types are used by the Hermon
  53  *    command interface routines.  Mailboxes are used to pass information
  54  *    back and forth to the Hermon firmware.  Either type of mailbox may


2649         mrhdl = (hermon_mrhdl_t)mr;
2650 
2651         mutex_destroy(&mrhdl->mr_lock);
2652 }
2653 
2654 
2655 /*
2656  * hermon_rsrc_mcg_entry_get_size()
2657  */
2658 static int
2659 hermon_rsrc_mcg_entry_get_size(hermon_state_t *state, uint_t *mcg_size_shift)
2660 {
2661         uint_t  num_qp_per_mcg, max_qp_per_mcg, log2;
2662 
2663         /*
2664          * Round the configured number of QP per MCG to next larger
2665          * power-of-2 size and update.
2666          */
2667         num_qp_per_mcg = state->hs_cfg_profile->cp_num_qp_per_mcg + 8;
2668         log2 = highbit(num_qp_per_mcg);
2669         if ((num_qp_per_mcg & (num_qp_per_mcg - 1)) == 0) {
2670                 log2 = log2 - 1;
2671         }
2672         state->hs_cfg_profile->cp_num_qp_per_mcg = (1 << log2) - 8;
2673 
2674         /* Now make sure number of QP per MCG makes sense */
2675         num_qp_per_mcg = state->hs_cfg_profile->cp_num_qp_per_mcg;
2676         max_qp_per_mcg = (1 << state->hs_devlim.log_max_qp_mcg);
2677         if (num_qp_per_mcg > max_qp_per_mcg) {
2678                 return (DDI_FAILURE);
2679         }
2680 
2681         /* Return the (shift) size of an individual MCG HW entry */
2682         *mcg_size_shift = log2 + 2;
2683 
2684         return (DDI_SUCCESS);
2685 }


  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 
  26 /*
  27  * hermon_rsrc.c
  28  *    Hermon Resource Management Routines
  29  *
  30  *    Implements all the routines necessary for setup, teardown, and
  31  *    alloc/free of all Hermon resources, including those that are managed
  32  *    by Hermon hardware or which live in Hermon's direct attached DDR memory.
  33  */
  34 
  35 #include <sys/sysmacros.h>
  36 #include <sys/types.h>
  37 #include <sys/conf.h>
  38 #include <sys/ddi.h>
  39 #include <sys/sunddi.h>
  40 #include <sys/modctl.h>
  41 #include <sys/vmem.h>
  42 #include <sys/bitmap.h>
  43 
  44 #include <sys/ib/adapters/hermon/hermon.h>
  45 
  46 int hermon_rsrc_verbose = 0;
  47 
  48 /*
  49  * The following routines are used for initializing and destroying
  50  * the resource pools used by the Hermon resource allocation routines.
  51  * They consist of four classes of object:
  52  *
  53  * Mailboxes:  The "In" and "Out" mailbox types are used by the Hermon
  54  *    command interface routines.  Mailboxes are used to pass information
  55  *    back and forth to the Hermon firmware.  Either type of mailbox may


2650         mrhdl = (hermon_mrhdl_t)mr;
2651 
2652         mutex_destroy(&mrhdl->mr_lock);
2653 }
2654 
2655 
2656 /*
2657  * hermon_rsrc_mcg_entry_get_size()
2658  */
2659 static int
2660 hermon_rsrc_mcg_entry_get_size(hermon_state_t *state, uint_t *mcg_size_shift)
2661 {
2662         uint_t  num_qp_per_mcg, max_qp_per_mcg, log2;
2663 
2664         /*
2665          * Round the configured number of QP per MCG to next larger
2666          * power-of-2 size and update.
2667          */
2668         num_qp_per_mcg = state->hs_cfg_profile->cp_num_qp_per_mcg + 8;
2669         log2 = highbit(num_qp_per_mcg);
2670         if (ISP2(num_qp_per_mcg)) {
2671                 log2 = log2 - 1;
2672         }
2673         state->hs_cfg_profile->cp_num_qp_per_mcg = (1 << log2) - 8;
2674 
2675         /* Now make sure number of QP per MCG makes sense */
2676         num_qp_per_mcg = state->hs_cfg_profile->cp_num_qp_per_mcg;
2677         max_qp_per_mcg = (1 << state->hs_devlim.log_max_qp_mcg);
2678         if (num_qp_per_mcg > max_qp_per_mcg) {
2679                 return (DDI_FAILURE);
2680         }
2681 
2682         /* Return the (shift) size of an individual MCG HW entry */
2683         *mcg_size_shift = log2 + 2;
2684 
2685         return (DDI_SUCCESS);
2686 }