532 }
533 }
534 mutex_exit(&hermon_userland_rsrc_db.hdl_umapdb_lock);
535 return (reset_status);
536 }
537
538
539 /*
540 * hermon_attach()
541 * Context: Only called from attach() path context
542 */
543 static int
544 hermon_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
545 {
546 hermon_state_t *state;
547 ibc_clnt_hdl_t tmp_ibtfpriv;
548 ibc_status_t ibc_status;
549 int instance;
550 int status;
551
552 #ifdef __lock_lint
553 (void) hermon_quiesce(dip);
554 #endif
555
556 switch (cmd) {
557 case DDI_ATTACH:
558 instance = ddi_get_instance(dip);
559 status = ddi_soft_state_zalloc(hermon_statep, instance);
560 if (status != DDI_SUCCESS) {
561 cmn_err(CE_NOTE, "hermon%d: driver failed to attach: "
562 "attach_ssz_fail", instance);
563 goto fail_attach_nomsg;
564
565 }
566 state = ddi_get_soft_state(hermon_statep, instance);
567 if (state == NULL) {
568 ddi_soft_state_free(hermon_statep, instance);
569 cmn_err(CE_NOTE, "hermon%d: driver failed to attach: "
570 "attach_gss_fail", instance);
571 goto fail_attach_nomsg;
572 }
573
574 /* clear the attach error buffer */
575 HERMON_ATTACH_MSG_INIT(state->hs_attach_buf);
831 /* Add code here for DDI_SUSPEND XXX */
832 return (DDI_FAILURE);
833
834 default:
835 cmn_err(CE_WARN, "hermon_detach: unknown cmd (0x%x)\n", cmd);
836 break;
837 }
838
839 return (DDI_FAILURE);
840 }
841
842 /*
843 * hermon_dma_attr_init()
844 * Context: Can be called from interrupt or base context.
845 */
846
847 /* ARGSUSED */
848 void
849 hermon_dma_attr_init(hermon_state_t *state, ddi_dma_attr_t *dma_attr)
850 {
851 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*dma_attr))
852
853 dma_attr->dma_attr_version = DMA_ATTR_V0;
854 dma_attr->dma_attr_addr_lo = 0;
855 dma_attr->dma_attr_addr_hi = 0xFFFFFFFFFFFFFFFFull;
856 dma_attr->dma_attr_count_max = 0xFFFFFFFFFFFFFFFFull;
857 dma_attr->dma_attr_align = HERMON_PAGESIZE; /* default 4K */
858 dma_attr->dma_attr_burstsizes = 0x3FF;
859 dma_attr->dma_attr_minxfer = 1;
860 dma_attr->dma_attr_maxxfer = 0xFFFFFFFFFFFFFFFFull;
861 dma_attr->dma_attr_seg = 0xFFFFFFFFFFFFFFFFull;
862 dma_attr->dma_attr_sgllen = 0x7FFFFFFF;
863 dma_attr->dma_attr_granular = 1;
864 dma_attr->dma_attr_flags = 0;
865 }
866
867 /*
868 * hermon_dma_alloc()
869 * Context: Can be called from base context.
870 */
871 int
872 hermon_dma_alloc(hermon_state_t *state, hermon_dma_info_t *dma_info,
1033 case HERMON_CQC:
1034 status = HERMON_ICM_ALLOC(HERMON_CMPT_CQC);
1035 if (status != DDI_SUCCESS) {
1036 return (status);
1037 }
1038 num_to_hdl = 1;
1039 break;
1040 case HERMON_EQC:
1041 status = HERMON_ICM_ALLOC(HERMON_CMPT_EQC);
1042 if (status != DDI_SUCCESS) { /* undo icm_alloc's */
1043 return (status);
1044 }
1045 break;
1046 }
1047
1048 /* ensure existence of bitmap and dmainfo, sets "dma_info" */
1049 hermon_bitmap(bitmap, dma_info, icm, index1, num_to_hdl);
1050
1051 /* Set up the DMA handle for allocation and mapping */
1052 dma_info += index2;
1053 _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*dma_info))
1054 dma_info->length = icm->span << icm->log_object_size;
1055 dma_info->icmaddr = icm->icm_baseaddr +
1056 (((index1 << icm->split_shift) +
1057 (index2 << icm->span_shift)) << icm->log_object_size);
1058
1059 /* Allocate memory for the num_to_qp/cq/srq pointers */
1060 if (num_to_hdl)
1061 icm->num_to_hdl[index1][index2] =
1062 kmem_zalloc(HERMON_ICM_SPAN * sizeof (void *), KM_SLEEP);
1063
1064 if (hermon_verbose) {
1065 IBTF_DPRINTF_L2("hermon", "alloc DMA: "
1066 "rsrc (0x%x) index (%x, %x) "
1067 "icm_addr/len (%llx/%x) bitmap %p", type, index1, index2,
1068 (longlong_t)dma_info->icmaddr, dma_info->length, bitmap);
1069 }
1070
1071 /* Allocate and map memory for this span */
1072 status = hermon_dma_alloc(state, dma_info, MAP_ICM);
1073 if (status != DDI_SUCCESS) {
|
532 }
533 }
534 mutex_exit(&hermon_userland_rsrc_db.hdl_umapdb_lock);
535 return (reset_status);
536 }
537
538
539 /*
540 * hermon_attach()
541 * Context: Only called from attach() path context
542 */
543 static int
544 hermon_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
545 {
546 hermon_state_t *state;
547 ibc_clnt_hdl_t tmp_ibtfpriv;
548 ibc_status_t ibc_status;
549 int instance;
550 int status;
551
552 switch (cmd) {
553 case DDI_ATTACH:
554 instance = ddi_get_instance(dip);
555 status = ddi_soft_state_zalloc(hermon_statep, instance);
556 if (status != DDI_SUCCESS) {
557 cmn_err(CE_NOTE, "hermon%d: driver failed to attach: "
558 "attach_ssz_fail", instance);
559 goto fail_attach_nomsg;
560
561 }
562 state = ddi_get_soft_state(hermon_statep, instance);
563 if (state == NULL) {
564 ddi_soft_state_free(hermon_statep, instance);
565 cmn_err(CE_NOTE, "hermon%d: driver failed to attach: "
566 "attach_gss_fail", instance);
567 goto fail_attach_nomsg;
568 }
569
570 /* clear the attach error buffer */
571 HERMON_ATTACH_MSG_INIT(state->hs_attach_buf);
827 /* Add code here for DDI_SUSPEND XXX */
828 return (DDI_FAILURE);
829
830 default:
831 cmn_err(CE_WARN, "hermon_detach: unknown cmd (0x%x)\n", cmd);
832 break;
833 }
834
835 return (DDI_FAILURE);
836 }
837
838 /*
839 * hermon_dma_attr_init()
840 * Context: Can be called from interrupt or base context.
841 */
842
843 /* ARGSUSED */
844 void
845 hermon_dma_attr_init(hermon_state_t *state, ddi_dma_attr_t *dma_attr)
846 {
847 dma_attr->dma_attr_version = DMA_ATTR_V0;
848 dma_attr->dma_attr_addr_lo = 0;
849 dma_attr->dma_attr_addr_hi = 0xFFFFFFFFFFFFFFFFull;
850 dma_attr->dma_attr_count_max = 0xFFFFFFFFFFFFFFFFull;
851 dma_attr->dma_attr_align = HERMON_PAGESIZE; /* default 4K */
852 dma_attr->dma_attr_burstsizes = 0x3FF;
853 dma_attr->dma_attr_minxfer = 1;
854 dma_attr->dma_attr_maxxfer = 0xFFFFFFFFFFFFFFFFull;
855 dma_attr->dma_attr_seg = 0xFFFFFFFFFFFFFFFFull;
856 dma_attr->dma_attr_sgllen = 0x7FFFFFFF;
857 dma_attr->dma_attr_granular = 1;
858 dma_attr->dma_attr_flags = 0;
859 }
860
861 /*
862 * hermon_dma_alloc()
863 * Context: Can be called from base context.
864 */
865 int
866 hermon_dma_alloc(hermon_state_t *state, hermon_dma_info_t *dma_info,
1027 case HERMON_CQC:
1028 status = HERMON_ICM_ALLOC(HERMON_CMPT_CQC);
1029 if (status != DDI_SUCCESS) {
1030 return (status);
1031 }
1032 num_to_hdl = 1;
1033 break;
1034 case HERMON_EQC:
1035 status = HERMON_ICM_ALLOC(HERMON_CMPT_EQC);
1036 if (status != DDI_SUCCESS) { /* undo icm_alloc's */
1037 return (status);
1038 }
1039 break;
1040 }
1041
1042 /* ensure existence of bitmap and dmainfo, sets "dma_info" */
1043 hermon_bitmap(bitmap, dma_info, icm, index1, num_to_hdl);
1044
1045 /* Set up the DMA handle for allocation and mapping */
1046 dma_info += index2;
1047 dma_info->length = icm->span << icm->log_object_size;
1048 dma_info->icmaddr = icm->icm_baseaddr +
1049 (((index1 << icm->split_shift) +
1050 (index2 << icm->span_shift)) << icm->log_object_size);
1051
1052 /* Allocate memory for the num_to_qp/cq/srq pointers */
1053 if (num_to_hdl)
1054 icm->num_to_hdl[index1][index2] =
1055 kmem_zalloc(HERMON_ICM_SPAN * sizeof (void *), KM_SLEEP);
1056
1057 if (hermon_verbose) {
1058 IBTF_DPRINTF_L2("hermon", "alloc DMA: "
1059 "rsrc (0x%x) index (%x, %x) "
1060 "icm_addr/len (%llx/%x) bitmap %p", type, index1, index2,
1061 (longlong_t)dma_info->icmaddr, dma_info->length, bitmap);
1062 }
1063
1064 /* Allocate and map memory for this span */
1065 status = hermon_dma_alloc(state, dma_info, MAP_ICM);
1066 if (status != DDI_SUCCESS) {
|