From c5cbc6fa671024b52f7ba1ac338cd3485955ad64 Mon Sep 17 00:00:00 2001 From: sleybo Date: Wed, 7 Feb 2007 13:33:49 +0000 Subject: [PATCH] [MTHCA] remove the mad cache from MTHCA git-svn-id: svn://openib.tc.cornell.edu/gen1@589 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/hw/mthca/kernel/SOURCES | 1 - trunk/hw/mthca/kernel/hca_data.c | 8 +- trunk/hw/mthca/kernel/hca_data.h | 2 +- trunk/hw/mthca/kernel/hca_smp.c | 635 ------------------------------ trunk/hw/mthca/kernel/hca_verbs.c | 126 +++++- 5 files changed, 119 insertions(+), 653 deletions(-) delete mode 100644 trunk/hw/mthca/kernel/hca_smp.c diff --git a/trunk/hw/mthca/kernel/SOURCES b/trunk/hw/mthca/kernel/SOURCES index ff1e0dae..f3b1a998 100644 --- a/trunk/hw/mthca/kernel/SOURCES +++ b/trunk/hw/mthca/kernel/SOURCES @@ -26,7 +26,6 @@ SOURCES= \ hca_memory.c \ hca_pci.c \ hca_pnp.c \ - hca_smp.c \ hca_verbs.c \ \ mt_cache.c \ diff --git a/trunk/hw/mthca/kernel/hca_data.c b/trunk/hw/mthca/kernel/hca_data.c index f8e5b7a6..5805306e 100644 --- a/trunk/hw/mthca/kernel/hca_data.c +++ b/trunk/hw/mthca/kernel/hca_data.c @@ -176,7 +176,7 @@ mlnx_hobs_remove( IN mlnx_hob_t *hob_p) { cl_async_proc_t *p_async_proc; - mlnx_cache_t *p_cache; + cl_spinlock_acquire( &hob_lock ); @@ -185,9 +185,6 @@ mlnx_hobs_remove( p_async_proc = hob_p->async_proc_mgr_p; hob_p->async_proc_mgr_p = NULL; - p_cache = hob_p->cache; - hob_p->cache = NULL; - hob_p->comp_cb_p = NULL; hob_p->async_cb_p = NULL; hob_p->ca_context = NULL; @@ -201,8 +198,7 @@ mlnx_hobs_remove( cl_free( p_async_proc ); } - if( p_cache ) - cl_free( p_cache ); + HCA_PRINT(TRACE_LEVEL_INFORMATION, HCA_DBG_SHIM,("CL: hobs_remove idx %d \n", (int)(hob_p - mlnx_hob_array))); } diff --git a/trunk/hw/mthca/kernel/hca_data.h b/trunk/hw/mthca/kernel/hca_data.h index 3f181440..ebbeb0f2 100644 --- a/trunk/hw/mthca/kernel/hca_data.h +++ b/trunk/hw/mthca/kernel/hca_data.h @@ -175,7 +175,7 @@ typedef struct _ib_ca { void *cl_device_h; uint32_t index; cl_async_proc_t *async_proc_mgr_p; - mlnx_cache_t *cache; // Cached port attributes. + } mlnx_hob_t; typedef struct HOBUL_t { diff --git a/trunk/hw/mthca/kernel/hca_smp.c b/trunk/hw/mthca/kernel/hca_smp.c deleted file mode 100644 index 6c52d69f..00000000 --- a/trunk/hw/mthca/kernel/hca_smp.c +++ /dev/null @@ -1,635 +0,0 @@ -/* - * Copyright (c) 2005 SilverStorm Technologies. All rights reserved. - * Copyright (c) 2006 Voltaire Corporation. All rights reserved. - * - * This software is available to you under 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. - * - * $Id$ - */ - - -/* - * SMP handling of IB Access Layer VPD for Mellanox MT23108 HCA - */ - - -#include "hca_driver.h" -#if defined(EVENT_TRACING) -#ifdef offsetof -#undef offsetof -#endif -#include "hca_smp.tmh" -#endif -#include "mthca_dev.h" -#include "ib_mad.h" - - -boolean_t -mlnx_cachable_guid_info( - IN const mlnx_cache_t* const p_cache, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - uint32_t idx; - - /* Get the table selector from the attribute */ - idx = cl_ntoh32( p_mad_in->attr_mod ); - - /* - * TODO: Setup the response to fail the MAD instead of sending - * it down to the HCA. - */ - if( idx > 31 ) - return FALSE; - - if( !p_cache->guid_block[idx].valid ) - return FALSE; - - /* - * If a SET, see if the set is identical to the cache, - * in which case it's a no-op. - */ - if( p_mad_in->method == IB_MAD_METHOD_SET ) - { - if( cl_memcmp( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ), - &p_cache->guid_block[idx].tbl, sizeof(ib_guid_info_t) ) ) - { - /* The set is requesting a change. */ - return FALSE; - } - } - - /* Setup the response mad. */ - cl_memcpy( p_mad_out, p_mad_in, MAD_BLOCK_SIZE ); - p_mad_out->method = (IB_MAD_METHOD_RESP_MASK | IB_MAD_METHOD_GET); - if( p_mad_out->mgmt_class == IB_MCLASS_SUBN_DIR ) - p_mad_out->status = IB_SMP_DIRECTION; - else - p_mad_out->status = 0; - - /* Copy the cached data. */ - cl_memcpy( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - &p_cache->guid_block[idx].tbl, sizeof(ib_guid_info_t) ); - - return TRUE; -} - - -boolean_t -mlnx_cachable_pkey_table( - IN const mlnx_cache_t* const p_cache, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - uint16_t idx; - - /* Get the table selector from the attribute */ - idx = ((uint16_t)cl_ntoh32( p_mad_in->attr_mod )); - - /* - * TODO: Setup the response to fail the MAD instead of sending - * it down to the HCA. - */ - if( idx > 2047 ) - return FALSE; - - if( !p_cache->pkey_tbl[idx].valid ) - return FALSE; - - /* - * If a SET, see if the set is identical to the cache, - * in which case it's a no-op. - */ - if( p_mad_in->method == IB_MAD_METHOD_SET ) - { - if( cl_memcmp( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ), - &p_cache->pkey_tbl[idx].tbl, sizeof(ib_pkey_table_info_t) ) ) - { - /* The set is requesting a change. */ - return FALSE; - } - } - - /* Setup the response mad. */ - cl_memcpy( p_mad_out, p_mad_in, MAD_BLOCK_SIZE ); - p_mad_out->method = (IB_MAD_METHOD_RESP_MASK | IB_MAD_METHOD_GET); - if( p_mad_out->mgmt_class == IB_MCLASS_SUBN_DIR ) - p_mad_out->status = IB_SMP_DIRECTION; - else - p_mad_out->status = 0; - - /* Copy the cached data. */ - cl_memcpy( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - &p_cache->pkey_tbl[idx].tbl, sizeof(ib_pkey_table_info_t) ); - - return TRUE; -} - - -boolean_t -mlnx_cachable_sl_vl_table( - IN const mlnx_cache_t* const p_cache, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - if( !p_cache->sl_vl.valid ) - return FALSE; - - /* - * If a SET, see if the set is identical to the cache, - * in which case it's a no-op. - */ - if( p_mad_in->method == IB_MAD_METHOD_SET ) - { - if( cl_memcmp( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ), - &p_cache->sl_vl.tbl, sizeof(ib_slvl_table_t) ) ) - { - /* The set is requesting a change. */ - return FALSE; - } - } - - /* Setup the response mad. */ - cl_memcpy( p_mad_out, p_mad_in, MAD_BLOCK_SIZE ); - p_mad_out->method = (IB_MAD_METHOD_RESP_MASK | IB_MAD_METHOD_GET); - if( p_mad_out->mgmt_class == IB_MCLASS_SUBN_DIR ) - p_mad_out->status = IB_SMP_DIRECTION; - else - p_mad_out->status = 0; - - /* Copy the cached data. */ - cl_memcpy( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - &p_cache->sl_vl.tbl, sizeof(ib_slvl_table_t) ); - - return TRUE; -} - - -boolean_t -mlnx_cachable_vl_arb_table( - IN const mlnx_cache_t* const p_cache, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - uint16_t idx; - - /* Get the table selector from the attribute */ - idx = ((uint16_t)(cl_ntoh32( p_mad_in->attr_mod ) >> 16)) - 1; - - /* - * TODO: Setup the response to fail the MAD instead of sending - * it down to the HCA. - */ - if( idx > 3 ) - return FALSE; - - if( !p_cache->vl_arb[idx].valid ) - return FALSE; - - /* - * If a SET, see if the set is identical to the cache, - * in which case it's a no-op. - */ - if( p_mad_in->method == IB_MAD_METHOD_SET ) - { - if( cl_memcmp( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ), - &p_cache->vl_arb[idx].tbl, sizeof(ib_vl_arb_table_t) ) ) - { - /* The set is requesting a change. */ - return FALSE; - } - } - - /* Setup the response mad. */ - cl_memcpy( p_mad_out, p_mad_in, MAD_BLOCK_SIZE ); - p_mad_out->method = (IB_MAD_METHOD_RESP_MASK | IB_MAD_METHOD_GET); - if( p_mad_out->mgmt_class == IB_MCLASS_SUBN_DIR ) - p_mad_out->status = IB_SMP_DIRECTION; - else - p_mad_out->status = 0; - - /* Copy the cached data. */ - cl_memcpy( ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - &p_cache->vl_arb[idx].tbl, sizeof(ib_vl_arb_table_t) ); - - return TRUE; -} - - -boolean_t -mlnx_cachable_port_info( - IN const mlnx_cache_t* const p_cache, - IN const uint8_t port_num, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - ib_port_info_t *p_port_info; - - UNUSED_PARAM( p_mad_out ); - - if( !p_cache->port_info.valid ) - return FALSE; - - if( p_mad_in->method == IB_MAD_METHOD_GET ) - return FALSE; - - /* - * NOTE: Even though the input MAD is const, we modify it to change - * some parameters to no-ops to compensate for problems in the HCA chip. - */ - p_port_info = - (ib_port_info_t*)ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ); - - /* We can only cache requests for the same port that the SMP came in on. */ - if( p_mad_in->attr_mod != 0 && - cl_ntoh32( p_mad_in->attr_mod ) != port_num ) - { - return FALSE; - } - - /* - * to avoid unnecessary glitches in port state, we translate these - * fields to NOP when there is no change. Note these fields cannot - * change within the hardware without a Set going through here. - */ - if( p_port_info->link_width_enabled == - p_cache->port_info.info.link_width_enabled ) - { - p_port_info->link_width_enabled = 0; - } - if( (p_port_info->state_info2 & 0x0F) == - (p_cache->port_info.info.state_info2 & 0x0F) ) - { - p_port_info->state_info2 &= 0xF0; - } - if( (p_port_info->link_speed & 0x0F) == - (p_cache->port_info.info.link_speed & 0x0F) ) - { - p_port_info->link_speed &= 0xF0; - } - if( (p_port_info->vl_enforce & 0xF0) == - (p_cache->port_info.info.vl_enforce & 0xF0) ) - { - p_port_info->vl_enforce &= 0x0F; - } - - /* - * We modified the input MAD to change things to no-ops, but - * we can't actually fulfill the MAD with cached data. - */ - return FALSE; -} - - -boolean_t -mlnx_cachable_mad( - IN const ib_ca_handle_t h_ca, - IN const uint8_t port_num, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - if( p_mad_in->mgmt_class!= IB_MCLASS_SUBN_DIR && - p_mad_in->mgmt_class != IB_MCLASS_SUBN_LID ) - { - return FALSE; - } - - switch( p_mad_in->attr_id ) - { - case IB_MAD_ATTR_GUID_INFO: - return mlnx_cachable_guid_info( - &h_ca->cache[port_num-1], p_mad_in, p_mad_out ); - - case IB_MAD_ATTR_P_KEY_TABLE: - return mlnx_cachable_pkey_table( - &h_ca->cache[port_num-1], p_mad_in, p_mad_out ); - - case IB_MAD_ATTR_SLVL_TABLE: - return mlnx_cachable_sl_vl_table( - &h_ca->cache[port_num-1], p_mad_in, p_mad_out ); - - case IB_MAD_ATTR_VL_ARBITRATION: - return mlnx_cachable_vl_arb_table( - &h_ca->cache[port_num-1], p_mad_in, p_mad_out ); - - case IB_MAD_ATTR_PORT_INFO: - return mlnx_cachable_port_info( - &h_ca->cache[port_num-1], port_num, p_mad_in, p_mad_out ); - - default: - break; - } - return FALSE; -} - - -void -mlnx_update_guid_info( - IN mlnx_cache_t* const p_cache, - IN const ib_mad_t* const p_mad_out ) -{ - uint32_t idx; - - /* Get the table selector from the attribute */ - idx = cl_ntoh32( p_mad_out->attr_mod ); - - /* - * We only get successful MADs here, so invalid settings - * shouldn't happen. - */ - CL_ASSERT( idx <= 31 ); - - cl_memcpy( &p_cache->guid_block[idx].tbl, - ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - sizeof(ib_guid_info_t) ); - p_cache->guid_block[idx].valid = TRUE; -} - - -void -mlnx_update_pkey_table( - IN mlnx_cache_t* const p_cache, - IN const ib_mad_t* const p_mad_out ) -{ - uint16_t idx; - - /* Get the table selector from the attribute */ - idx = ((uint16_t)cl_ntoh32( p_mad_out->attr_mod )); - - ASSERT( idx <= 2047 ); - - cl_memcpy( &p_cache->pkey_tbl[idx].tbl, - ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - sizeof(ib_pkey_table_info_t) ); - p_cache->pkey_tbl[idx].valid = TRUE; -} - - -void -mlnx_update_sl_vl_table( - IN mlnx_cache_t* const p_cache, - IN const ib_mad_t* const p_mad_out ) -{ - cl_memcpy( &p_cache->sl_vl.tbl, - ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - sizeof(ib_slvl_table_t) ); - p_cache->sl_vl.valid = TRUE; -} - - -void -mlnx_update_vl_arb_table( - IN mlnx_cache_t* const p_cache, - IN const ib_mad_t* const p_mad_out ) -{ - uint16_t idx; - - /* Get the table selector from the attribute */ - idx = ((uint16_t)(cl_ntoh32( p_mad_out->attr_mod ) >> 16)) - 1; - - CL_ASSERT( idx <= 3 ); - - cl_memcpy( &p_cache->vl_arb[idx].tbl, - ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ), - sizeof(ib_vl_arb_table_t) ); - p_cache->vl_arb[idx].valid = TRUE; -} - - -void -mlnx_update_port_info( - IN const mlnx_cache_t* const p_cache, - IN const uint8_t port_num, - IN const ib_mad_t* const p_mad_out ) -{ - UNUSED_PARAM( p_cache ); - - /* We can only cache requests for the same port that the SMP came in on. */ - /* TODO: Add synchronization to support getting data from other ports. */ - if( p_mad_out->attr_mod != 0 && - cl_ntoh32( p_mad_out->attr_mod ) != port_num ) - { - return; - } - - /* TODO: Setup the capabilites mask properly. */ -} - - -void -mlnx_update_cache( - IN const ib_ca_handle_t h_ca, - IN const uint8_t port_num, - IN const ib_mad_t *p_mad_out ) -{ - if( p_mad_out->mgmt_class != IB_MCLASS_SUBN_DIR && - p_mad_out->mgmt_class != IB_MCLASS_SUBN_LID ) - { - return; - } - - /* Any successful response updates the cache. */ - if( p_mad_out->status ) - return; - - - switch( p_mad_out->attr_id ) - { - case IB_MAD_ATTR_GUID_INFO: - mlnx_update_guid_info( - &h_ca->cache[port_num-1], p_mad_out ); - break; - - case IB_MAD_ATTR_P_KEY_TABLE: - mlnx_update_pkey_table( - &h_ca->cache[port_num-1], p_mad_out ); - break; - - case IB_MAD_ATTR_SLVL_TABLE: - mlnx_update_sl_vl_table( - &h_ca->cache[port_num-1], p_mad_out ); - break; - - case IB_MAD_ATTR_VL_ARBITRATION: - mlnx_update_vl_arb_table( - &h_ca->cache[port_num-1], p_mad_out ); - break; - - case IB_MAD_ATTR_PORT_INFO: - mlnx_update_port_info( - &h_ca->cache[port_num-1], port_num, p_mad_out ); - break; - - default: - break; - } - -} - - -/* - * Local MAD Support Verbs. For CAs that do not support - * agents in HW. - */ - -#ifdef WIN_TO_BE_REMOVED -//TODO: seems like non need in that -static void build_smp_wc(u64 wr_id, u16 slid, u16 pkey_index, - u8 port_num, struct _ib_wc *wc) -{ - RtlZeroMemory(wc, sizeof *wc); - wc->wr_id = wr_id; - wc->status = IB_WC_SUCCESS; - wc->wc_type = IB_WC_RECV; - wc->length = sizeof(struct ib_mad) + sizeof(struct ib_grh); - wc->qp_num = IB_QP0; - wc->port_num = port_num; - wc->recv.ud.pkey_index = pkey_index; - wc->recv.ud.remote_qp = IB_QP0; - wc->recv.ud.remote_lid = slid; - wc->recv.ud.remote_sl = 0; - wc->recv.ud.path_bits = 0; -} -#endif - -ib_api_status_t -mlnx_local_mad ( - IN const ib_ca_handle_t h_ca, - IN const uint8_t port_num, - IN const ib_av_attr_t* p_av_attr, - IN const ib_mad_t *p_mad_in, - OUT ib_mad_t *p_mad_out ) -{ - int err; - ib_api_status_t status = IB_SUCCESS; - mlnx_hob_t *hob_p = (mlnx_hob_t *)h_ca; - struct ib_device *ib_dev = IBDEV_FROM_HOB( hob_p ); - //TODO: do we need use flags (IB_MAD_IGNORE_MKEY, IB_MAD_IGNORE_BKEY) ? - int mad_flags = 0; - struct _ib_wc *wc_p = NULL; - //TODO: do we need use grh ? - struct _ib_grh *grh_p = NULL; - - HCA_ENTER(HCA_DBG_MAD); - - // sanity checks - if (port_num > 2) { - status = IB_INVALID_PARAMETER; - goto err_port_num; - } - - if (p_av_attr){ - wc_p = cl_zalloc(sizeof(struct _ib_wc)); - if(!wc_p){ - status = IB_INSUFFICIENT_MEMORY ; - goto err_wc_alloc; - } - //Copy part of the attributes need to fill the mad extended fields in mellanox devices - wc_p->recv.ud.remote_lid = p_av_attr->dlid; - wc_p->recv.ud.remote_sl = p_av_attr->sl; - wc_p->recv.ud.path_bits = p_av_attr->path_bits; - wc_p->recv.ud.recv_opt = p_av_attr->grh_valid?IB_RECV_OPT_GRH_VALID:0; - - if(wc_p->recv.ud.recv_opt &IB_RECV_OPT_GRH_VALID){ - grh_p = cl_zalloc(sizeof(struct _ib_grh)); - if(!grh_p){ - status = IB_INSUFFICIENT_MEMORY ; - goto err_grh_alloc; - } - cl_memcpy(grh_p, &p_av_attr->grh, sizeof(ib_grh_t)); - } - - - } - - HCA_PRINT( TRACE_LEVEL_INFORMATION, HCA_DBG_MAD, - ("MAD: Class %02x, Method %02x, Attr %02x, HopPtr %d, HopCnt %d, \n", - (uint32_t)((ib_smp_t *)p_mad_in)->mgmt_class, - (uint32_t)((ib_smp_t *)p_mad_in)->method, - (uint32_t)((ib_smp_t *)p_mad_in)->attr_id, - (uint32_t)((ib_smp_t *)p_mad_in)->hop_ptr, - (uint32_t)((ib_smp_t *)p_mad_in)->hop_count)); - - - // process mad - if( !mlnx_cachable_mad( h_ca, port_num, p_mad_in, p_mad_out ) ) - { - err = mthca_process_mad(ib_dev, mad_flags, (uint8_t)port_num, - wc_p, grh_p, (struct ib_mad*)p_mad_in, (struct ib_mad*)p_mad_out); - if (!err) { - HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_MAD, - ("MAD failed:\n\tClass 0x%x\n\tMethod 0x%x\n\tAttr 0x%x", - p_mad_in->mgmt_class, p_mad_in->method, p_mad_in->attr_id )); - status = IB_ERROR; - goto err_process_mad; - } - - if( (p_mad_in->mgmt_class == IB_MCLASS_SUBN_DIR || - p_mad_in->mgmt_class == IB_MCLASS_SUBN_LID) && - p_mad_in->attr_id == IB_MAD_ATTR_PORT_INFO ) - { - ib_port_info_t *p_pi_in, *p_pi_out; - - if( p_mad_in->mgmt_class == IB_MCLASS_SUBN_DIR ) - { - p_pi_in = (ib_port_info_t*) - ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ); - p_pi_out = (ib_port_info_t*) - ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ); - } - else - { - p_pi_in = (ib_port_info_t*)(p_mad_in + 1); - p_pi_out = (ib_port_info_t*)(p_mad_out + 1); - } - - /* Work around FW bug 33958 */ - p_pi_out->subnet_timeout &= 0x7F; - if( p_mad_in->method == IB_MAD_METHOD_SET ) - p_pi_out->subnet_timeout |= (p_pi_in->subnet_timeout & 0x80); - } - - mlnx_update_cache( h_ca, port_num, p_mad_out ); - } - - /* Modify direction for Direct MAD */ - if ( p_mad_in->mgmt_class == IB_MCLASS_SUBN_DIR ) - p_mad_out->status |= IB_SMP_DIRECTION; - - -err_process_mad: - if(grh_p) - cl_free(grh_p); -err_grh_alloc: - if(wc_p) - cl_free(wc_p); -err_wc_alloc: -err_port_num: - HCA_PRINT_EXIT(TRACE_LEVEL_ERROR , HCA_DBG_MAD, - ("completes with ERROR status %s\n", IB_GET_ERR_STR(status))); - return status; -} - diff --git a/trunk/hw/mthca/kernel/hca_verbs.c b/trunk/hw/mthca/kernel/hca_verbs.c index 53730b51..5cc8a2ac 100644 --- a/trunk/hw/mthca/kernel/hca_verbs.c +++ b/trunk/hw/mthca/kernel/hca_verbs.c @@ -65,7 +65,6 @@ mlnx_open_ca ( { mlnx_hca_t *p_hca; ib_api_status_t status = IB_NOT_FOUND; - mlnx_cache_t *p_cache; struct ib_device *ib_dev; HCA_ENTER(HCA_DBG_SHIM); @@ -95,14 +94,6 @@ mlnx_open_ca ( goto err_set_cb; } - // MAD cache - p_cache = (mlnx_cache_t*)cl_pzalloc( sizeof(mlnx_cache_t) * 2 ); - if( !p_cache ) { - status = IB_INSUFFICIENT_MEMORY; - goto err_mad_cache; - } - p_hca->hob.cache = p_cache; - //TODO: do we need something for kernel users ? @@ -111,7 +102,7 @@ done: if (ph_ca) *ph_ca = &p_hca->hob; status = IB_SUCCESS; -err_mad_cache: +//err_mad_cache: err_set_cb: HCA_PRINT_EXIT(TRACE_LEVEL_ERROR , HCA_DBG_SHIM, ("completes with ERROR status %s\n", IB_GET_ERR_STR(status))); @@ -1398,6 +1389,121 @@ err_destroy_cq: } +ib_api_status_t +mlnx_local_mad ( + IN const ib_ca_handle_t h_ca, + IN const uint8_t port_num, + IN const ib_av_attr_t* p_av_attr, + IN const ib_mad_t *p_mad_in, + OUT ib_mad_t *p_mad_out ) +{ + int err; + ib_api_status_t status = IB_SUCCESS; + mlnx_hob_t *hob_p = (mlnx_hob_t *)h_ca; + struct ib_device *ib_dev = IBDEV_FROM_HOB( hob_p ); + //TODO: do we need use flags (IB_MAD_IGNORE_MKEY, IB_MAD_IGNORE_BKEY) ? + int mad_flags = 0; + struct _ib_wc *wc_p = NULL; + //TODO: do we need use grh ? + struct _ib_grh *grh_p = NULL; + + HCA_ENTER(HCA_DBG_MAD); + + // sanity checks + if (port_num > 2) { + status = IB_INVALID_PARAMETER; + goto err_port_num; + } + + if (p_av_attr){ + wc_p = cl_zalloc(sizeof(struct _ib_wc)); + if(!wc_p){ + status = IB_INSUFFICIENT_MEMORY ; + goto err_wc_alloc; + } + //Copy part of the attributes need to fill the mad extended fields in mellanox devices + wc_p->recv.ud.remote_lid = p_av_attr->dlid; + wc_p->recv.ud.remote_sl = p_av_attr->sl; + wc_p->recv.ud.path_bits = p_av_attr->path_bits; + wc_p->recv.ud.recv_opt = p_av_attr->grh_valid?IB_RECV_OPT_GRH_VALID:0; + + if(wc_p->recv.ud.recv_opt &IB_RECV_OPT_GRH_VALID){ + grh_p = cl_zalloc(sizeof(struct _ib_grh)); + if(!grh_p){ + status = IB_INSUFFICIENT_MEMORY ; + goto err_grh_alloc; + } + cl_memcpy(grh_p, &p_av_attr->grh, sizeof(ib_grh_t)); + } + + + } + + HCA_PRINT( TRACE_LEVEL_INFORMATION, HCA_DBG_MAD, + ("MAD: Class %02x, Method %02x, Attr %02x, HopPtr %d, HopCnt %d, \n", + (uint32_t)((ib_smp_t *)p_mad_in)->mgmt_class, + (uint32_t)((ib_smp_t *)p_mad_in)->method, + (uint32_t)((ib_smp_t *)p_mad_in)->attr_id, + (uint32_t)((ib_smp_t *)p_mad_in)->hop_ptr, + (uint32_t)((ib_smp_t *)p_mad_in)->hop_count)); + + + // process mad + + err = mthca_process_mad(ib_dev, mad_flags, (uint8_t)port_num, + wc_p, grh_p, (struct ib_mad*)p_mad_in, (struct ib_mad*)p_mad_out); + if (!err) { + HCA_PRINT( TRACE_LEVEL_ERROR, HCA_DBG_MAD, + ("MAD failed:\n\tClass 0x%x\n\tMethod 0x%x\n\tAttr 0x%x", + p_mad_in->mgmt_class, p_mad_in->method, p_mad_in->attr_id )); + status = IB_ERROR; + goto err_process_mad; + } + + if( (p_mad_in->mgmt_class == IB_MCLASS_SUBN_DIR || + p_mad_in->mgmt_class == IB_MCLASS_SUBN_LID) && + p_mad_in->attr_id == IB_MAD_ATTR_PORT_INFO ) + { + ib_port_info_t *p_pi_in, *p_pi_out; + + if( p_mad_in->mgmt_class == IB_MCLASS_SUBN_DIR ) + { + p_pi_in = (ib_port_info_t*) + ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_in ); + p_pi_out = (ib_port_info_t*) + ib_smp_get_payload_ptr( (ib_smp_t*)p_mad_out ); + } + else + { + p_pi_in = (ib_port_info_t*)(p_mad_in + 1); + p_pi_out = (ib_port_info_t*)(p_mad_out + 1); + } + + /* Work around FW bug 33958 */ + p_pi_out->subnet_timeout &= 0x7F; + if( p_mad_in->method == IB_MAD_METHOD_SET ) + p_pi_out->subnet_timeout |= (p_pi_in->subnet_timeout & 0x80); + } + + /* Modify direction for Direct MAD */ + if ( p_mad_in->mgmt_class == IB_MCLASS_SUBN_DIR ) + p_mad_out->status |= IB_SMP_DIRECTION; + + +err_process_mad: + if(grh_p) + cl_free(grh_p); +err_grh_alloc: + if(wc_p) + cl_free(wc_p); +err_wc_alloc: +err_port_num: + HCA_PRINT_EXIT(TRACE_LEVEL_ERROR , HCA_DBG_MAD, + ("completes with ERROR status %s\n", IB_GET_ERR_STR(status))); + return status; +} + + void setup_ci_interface( IN const ib_net64_t ca_guid, -- 2.41.0