iPXE
hermon.h
Go to the documentation of this file.
00001 #ifndef _HERMON_H
00002 #define _HERMON_H
00003 
00004 /** @file
00005  *
00006  * Mellanox Hermon Infiniband HCA driver
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER );
00011 
00012 #include <stdint.h>
00013 #include <ipxe/uaccess.h>
00014 #include <ipxe/ib_packet.h>
00015 #include <ipxe/bofm.h>
00016 #include <ipxe/nvsvpd.h>
00017 #include <ipxe/nvo.h>
00018 #include "mlx_bitops.h"
00019 #include "MT25408_PRM.h"
00020 
00021 /*
00022  * Hardware constants
00023  *
00024  */
00025 
00026 /* Ports in existence */
00027 #define HERMON_MAX_PORTS                2
00028 #define HERMON_PORT_BASE                1
00029 
00030 /* PCI BARs */
00031 #define HERMON_PCI_CONFIG_BAR           PCI_BASE_ADDRESS_0
00032 #define HERMON_PCI_CONFIG_BAR_SIZE      0x100000
00033 #define HERMON_PCI_UAR_BAR              PCI_BASE_ADDRESS_2
00034 
00035 /* Device reset */
00036 #define HERMON_RESET_OFFSET             0x0f0010
00037 #define HERMON_RESET_MAGIC              0x01000000UL
00038 #define HERMON_RESET_WAIT_TIME_MS       1000
00039 
00040 /* Work queue entry and completion queue entry opcodes */
00041 #define HERMON_OPCODE_NOP               0x00
00042 #define HERMON_OPCODE_SEND              0x0a
00043 #define HERMON_OPCODE_RECV_ERROR        0xfe
00044 #define HERMON_OPCODE_SEND_ERROR        0xff
00045 
00046 /* HCA command register opcodes */
00047 #define HERMON_HCR_QUERY_DEV_CAP        0x0003
00048 #define HERMON_HCR_QUERY_FW             0x0004
00049 #define HERMON_HCR_INIT_HCA             0x0007
00050 #define HERMON_HCR_CLOSE_HCA            0x0008
00051 #define HERMON_HCR_INIT_PORT            0x0009
00052 #define HERMON_HCR_CLOSE_PORT           0x000a
00053 #define HERMON_HCR_SET_PORT             0x000c
00054 #define HERMON_HCR_SW2HW_MPT            0x000d
00055 #define HERMON_HCR_WRITE_MTT            0x0011
00056 #define HERMON_HCR_MAP_EQ               0x0012
00057 #define HERMON_HCR_SW2HW_EQ             0x0013
00058 #define HERMON_HCR_HW2SW_EQ             0x0014
00059 #define HERMON_HCR_QUERY_EQ             0x0015
00060 #define HERMON_HCR_SW2HW_CQ             0x0016
00061 #define HERMON_HCR_HW2SW_CQ             0x0017
00062 #define HERMON_HCR_QUERY_CQ             0x0018
00063 #define HERMON_HCR_RST2INIT_QP          0x0019
00064 #define HERMON_HCR_INIT2RTR_QP          0x001a
00065 #define HERMON_HCR_RTR2RTS_QP           0x001b
00066 #define HERMON_HCR_RTS2RTS_QP           0x001c
00067 #define HERMON_HCR_2RST_QP              0x0021
00068 #define HERMON_HCR_QUERY_QP             0x0022
00069 #define HERMON_HCR_CONF_SPECIAL_QP      0x0023
00070 #define HERMON_HCR_MAD_IFC              0x0024
00071 #define HERMON_HCR_READ_MCG             0x0025
00072 #define HERMON_HCR_WRITE_MCG            0x0026
00073 #define HERMON_HCR_MGID_HASH            0x0027
00074 #define HERMON_HCR_MOD_STAT_CFG         0x0034
00075 #define HERMON_HCR_QUERY_PORT           0x0043
00076 #define HERMON_HCR_SENSE_PORT           0x004d
00077 #define HERMON_HCR_RUN_FW               0x0ff6
00078 #define HERMON_HCR_DISABLE_LAM          0x0ff7
00079 #define HERMON_HCR_ENABLE_LAM           0x0ff8
00080 #define HERMON_HCR_UNMAP_ICM            0x0ff9
00081 #define HERMON_HCR_MAP_ICM              0x0ffa
00082 #define HERMON_HCR_UNMAP_ICM_AUX        0x0ffb
00083 #define HERMON_HCR_MAP_ICM_AUX          0x0ffc
00084 #define HERMON_HCR_SET_ICM_SIZE         0x0ffd
00085 #define HERMON_HCR_UNMAP_FA             0x0ffe
00086 #define HERMON_HCR_MAP_FA               0x0fff
00087 
00088 /* Service types */
00089 #define HERMON_ST_RC                    0x00
00090 #define HERMON_ST_UD                    0x03
00091 #define HERMON_ST_MLX                   0x07
00092 
00093 /* Port types */
00094 #define HERMON_PORT_TYPE_UNKNOWN        0
00095 #define HERMON_PORT_TYPE_IB             1
00096 #define HERMON_PORT_TYPE_ETH            2
00097 
00098 /* MTUs */
00099 #define HERMON_MTU_2048                 0x04
00100 #define HERMON_MTU_ETH                  0x07
00101 
00102 #define HERMON_INVALID_LKEY             0x00000100UL
00103 
00104 #define HERMON_PAGE_SIZE                ( ( size_t ) 4096 )
00105 
00106 #define HERMON_DB_POST_SND_OFFSET       0x14
00107 #define HERMON_DB_EQ_OFFSET(_eqn)       \
00108         ( 0x800 + HERMON_PAGE_SIZE * ( (_eqn) / 4 ) + 0x08 * ( (_eqn) % 4 ) )
00109 
00110 #define HERMON_QP_OPT_PARAM_PM_STATE    0x00000400UL
00111 #define HERMON_QP_OPT_PARAM_QKEY        0x00000020UL
00112 #define HERMON_QP_OPT_PARAM_ALT_PATH    0x00000001UL
00113 
00114 #define HERMON_MAP_EQ                   ( 0UL << 31 )
00115 #define HERMON_UNMAP_EQ                 ( 1UL << 31 )
00116 
00117 #define HERMON_SET_PORT_GENERAL_PARAM   0x0000
00118 #define HERMON_SET_PORT_RECEIVE_QP      0x0100
00119 #define HERMON_SET_PORT_MAC_TABLE       0x0200
00120 #define HERMON_SET_PORT_VLAN_TABLE      0x0300
00121 #define HERMON_SET_PORT_PRIORITY_TABLE  0x0400
00122 #define HERMON_SET_PORT_GID_TABLE       0x0500
00123 
00124 #define HERMON_EV_PORT_STATE_CHANGE     0x09
00125 
00126 #define HERMON_SCHED_QP0                0x3f
00127 #define HERMON_SCHED_DEFAULT            0x83
00128 
00129 #define HERMON_LOG_MULTICAST_HASH_SIZE  7
00130 
00131 #define HERMON_PM_STATE_ARMED           0x00
00132 #define HERMON_PM_STATE_REARM           0x01
00133 #define HERMON_PM_STATE_MIGRATED        0x03
00134 
00135 #define HERMON_RETRY_MAX                0x07
00136 
00137 #define HERMON_MOD_STAT_CFG_SET         0x01
00138 #define HERMON_MOD_STAT_CFG_QUERY       0x03
00139 
00140 #define HERMON_VPD_FIELD( port ) \
00141         PCI_VPD_FIELD ( PCI_VPD_TAG_RW, 'V', ( '5' + (port) - 1 ) )
00142 
00143 /*
00144  * Datatypes that seem to be missing from the autogenerated documentation
00145  *
00146  */
00147 struct hermonprm_mgm_hash_st {
00148         pseudo_bit_t reserved0[0x00020];
00149 /* -------------- */
00150         pseudo_bit_t hash[0x00010];
00151         pseudo_bit_t reserved1[0x00010];
00152 } __attribute__ (( packed ));
00153 
00154 struct hermonprm_mcg_entry_st {
00155         struct hermonprm_mcg_hdr_st hdr;
00156         struct hermonprm_mcg_qp_dw_st qp[8];
00157 } __attribute__ (( packed ));
00158 
00159 struct hermonprm_cq_db_record_st {
00160         pseudo_bit_t update_ci[0x00018];
00161         pseudo_bit_t reserved0[0x00008];
00162 /* -------------- */
00163         pseudo_bit_t arm_ci[0x00018];
00164         pseudo_bit_t cmd[0x00003];
00165         pseudo_bit_t reserved1[0x00001];
00166         pseudo_bit_t cmd_sn[0x00002];
00167         pseudo_bit_t reserved2[0x00002];
00168 } __attribute__ (( packed ));
00169 
00170 struct hermonprm_send_db_register_st {
00171         pseudo_bit_t reserved[0x00008];
00172         pseudo_bit_t qn[0x00018];
00173 } __attribute__ (( packed ));
00174 
00175 struct hermonprm_event_db_register_st {
00176         pseudo_bit_t ci[0x00018];
00177         pseudo_bit_t reserver[0x00007];
00178         pseudo_bit_t a[0x00001];
00179 } __attribute__ (( packed ));
00180 
00181 struct hermonprm_scalar_parameter_st {
00182         pseudo_bit_t value_hi[0x00020];
00183 /* -------------- */
00184         pseudo_bit_t value[0x00020];
00185 } __attribute__ (( packed ));
00186 
00187 struct hermonprm_event_mask_st {
00188         pseudo_bit_t reserved0[0x00020];
00189 /* -------------- */
00190         pseudo_bit_t completion[0x00001];
00191         pseudo_bit_t path_migration_succeeded[0x00001];
00192         pseudo_bit_t communication_established[0x00001];
00193         pseudo_bit_t send_queue_drained[0x00001];
00194         pseudo_bit_t cq_error[0x00001];
00195         pseudo_bit_t wq_catastrophe[0x00001];
00196         pseudo_bit_t qpc_catastrophe[0x00001];
00197         pseudo_bit_t path_migration_failed[0x00001];
00198         pseudo_bit_t internal_error[0x00001];
00199         pseudo_bit_t port_state_change[0x00001];
00200         pseudo_bit_t command_done[0x00001];
00201         pseudo_bit_t fexch_error[0x00001];
00202         pseudo_bit_t reserved1[0x00004];
00203         pseudo_bit_t wq_invalid_request[0x00001];
00204         pseudo_bit_t wq_access_violation[0x00001];
00205         pseudo_bit_t srq_catastrophe[0x00001];
00206         pseudo_bit_t srq_last_wqe[0x00001];
00207         pseudo_bit_t srq_rq_limit[0x00001];
00208         pseudo_bit_t gpio[0x00001];
00209         pseudo_bit_t clientreregister[0x00001];
00210         pseudo_bit_t reserved2[0x00009];
00211 } __attribute__ (( packed ));
00212 
00213 struct hermonprm_port_state_change_event_st {
00214         pseudo_bit_t reserved[0x00020];
00215 /* -------------- */
00216         struct hermonprm_port_state_change_st data;
00217 } __attribute__ (( packed ));
00218 
00219 struct hermonprm_sense_port_st {
00220         pseudo_bit_t reserved0[0x00020];
00221 /* -------------- */
00222         pseudo_bit_t port_type[0x00002];
00223         pseudo_bit_t reserved1[0x0001e];
00224 } __attribute__ (( packed ));
00225 
00226 struct hermonprm_set_port_ib_st {
00227         pseudo_bit_t rqk[0x00001];
00228         pseudo_bit_t rcm[0x00001];
00229         pseudo_bit_t reserved0[0x00002];
00230         pseudo_bit_t vl_cap[0x00004];
00231         pseudo_bit_t reserved1[0x00004];
00232         pseudo_bit_t mtu_cap[0x00004];
00233         pseudo_bit_t g0[0x00001];
00234         pseudo_bit_t ng[0x00001];
00235         pseudo_bit_t sig[0x00001];
00236         pseudo_bit_t mg[0x00001];
00237         pseudo_bit_t mp[0x00001];
00238         pseudo_bit_t mvc[0x00001];
00239         pseudo_bit_t mmc[0x00001];
00240         pseudo_bit_t reserved2[0x00004];
00241         pseudo_bit_t lws[0x00001];
00242         pseudo_bit_t lss[0x00001];
00243         pseudo_bit_t reserved3[0x00003];
00244 /* -------------- */
00245         pseudo_bit_t capability_mask[0x00020];
00246 /* -------------- */
00247         pseudo_bit_t system_image_guid_h[0x00020];
00248 /* -------------- */
00249         pseudo_bit_t system_image_guid_l[0x00020];
00250 /* -------------- */
00251         pseudo_bit_t guid0_h[0x00020];
00252 /* -------------- */
00253         pseudo_bit_t guid0_l[0x00020];
00254 /* -------------- */
00255         pseudo_bit_t node_guid_h[0x00020];
00256 /* -------------- */
00257         pseudo_bit_t node_guid_l[0x00020];
00258 /* -------------- */
00259         pseudo_bit_t egress_sniff_qpn[0x00018];
00260         pseudo_bit_t egress_sniff_mode[0x00002];
00261         pseudo_bit_t reserved4[0x00006];
00262 /* -------------- */
00263         pseudo_bit_t ingress_sniff_qpn[0x00018];
00264         pseudo_bit_t ingress_sniff_mode[0x00002];
00265         pseudo_bit_t reserved5[0x00006];
00266 /* -------------- */
00267         pseudo_bit_t max_gid[0x00010];
00268         pseudo_bit_t max_pkey[0x00010];
00269 /* -------------- */
00270         pseudo_bit_t reserved6[0x00020];
00271 /* -------------- */
00272         pseudo_bit_t reserved7[0x00020];
00273 /* -------------- */
00274         pseudo_bit_t reserved8[0x00020];
00275 /* -------------- */
00276         pseudo_bit_t reserved9[0x00020];
00277 /* -------------- */
00278         pseudo_bit_t reserved10[0x00020];
00279 /* -------------- */
00280         pseudo_bit_t reserved11[0x00020];
00281 /* -------------- */
00282         pseudo_bit_t reserved12[0x00020];
00283 /* -------------- */
00284         pseudo_bit_t reserved13[0x00020];
00285 /* -------------- */
00286         pseudo_bit_t reserved14[0x00020];
00287 /* -------------- */
00288         pseudo_bit_t reserved15[0x00020];
00289 /* -------------- */
00290         pseudo_bit_t reserved16[0x00020];
00291 /* -------------- */
00292         pseudo_bit_t reserved17[0x00020];
00293 /* -------------- */
00294         pseudo_bit_t reserved18[0x00020];
00295 /* -------------- */
00296         pseudo_bit_t reserved19[0x00020];
00297 /* -------------- */
00298         pseudo_bit_t reserved20[0x00020];
00299 /* -------------- */
00300         pseudo_bit_t reserved21[0x00020];
00301 /* -------------- */
00302         pseudo_bit_t reserved22[0x00020];
00303 /* -------------- */
00304         pseudo_bit_t link_width_supported[0x00004];
00305         pseudo_bit_t link_speed_supported[0x00004];
00306         pseudo_bit_t reserved23[0x00018];
00307 /* -------------- */
00308 } __attribute__ (( packed ));
00309 
00310 struct hermonprm_query_port_cap_st {
00311         pseudo_bit_t eth_mtu[0x00010];
00312         pseudo_bit_t ib_mtu[0x00004];
00313         pseudo_bit_t reserved0[0x00004];
00314         pseudo_bit_t ib[0x00001];
00315         pseudo_bit_t eth[0x00001];
00316         pseudo_bit_t reserved1[0x00005];
00317         pseudo_bit_t link_state[0x00001];
00318 /* -------------- */
00319         pseudo_bit_t log_max_pkey[0x00004];
00320         pseudo_bit_t log_max_gid[0x00004];
00321         pseudo_bit_t ib_port_width[0x00004];
00322         pseudo_bit_t reserved2[0x00004];
00323         pseudo_bit_t eth_link_speed[0x00004];
00324         pseudo_bit_t reserved3[0x00004];
00325         pseudo_bit_t ib_link_speed[0x00004];
00326         pseudo_bit_t reserved4[0x00004];
00327 /* -------------- */
00328         pseudo_bit_t max_vl_ib[0x00004];
00329         pseudo_bit_t reserved5[0x00004];
00330         pseudo_bit_t log_max_mac[0x00004];
00331         pseudo_bit_t log_max_vlan[0x00004];
00332         pseudo_bit_t reserved6[0x00010];
00333 /* -------------- */
00334         pseudo_bit_t reserved7[0x00020];
00335 /* -------------- */
00336         pseudo_bit_t mac_47_32[0x00010];
00337         pseudo_bit_t reserved8[0x00010];
00338 /* -------------- */
00339         pseudo_bit_t mac_31_0[0x00020];
00340 /* -------------- */
00341         pseudo_bit_t vendor_oui[0x00018];
00342         pseudo_bit_t transceiver_type[0x00008];
00343 /* -------------- */
00344         pseudo_bit_t reserved9[0x00010];
00345         pseudo_bit_t wavelength[0x00010];
00346 /* -------------- */
00347         pseudo_bit_t transceiver_code_hi[0x00020];
00348 /* -------------- */
00349         pseudo_bit_t transceiver_code_lo[0x00020];
00350 /* -------------- */
00351         pseudo_bit_t reserved10[0x000c0];
00352 } __attribute__ (( packed ));
00353 
00354 struct hermonprm_set_port_general_context_st {
00355         pseudo_bit_t v_mtu[0x00001];
00356         pseudo_bit_t v_pprx[0x00001];
00357         pseudo_bit_t v_pptx[0x00001];
00358         pseudo_bit_t reserved0[0x0001d];
00359 /* -------------- */
00360         pseudo_bit_t mtu[0x00010];
00361         pseudo_bit_t reserved1[0x00010];
00362 /* -------------- */
00363         pseudo_bit_t reserved2[0x00010];
00364         pseudo_bit_t pfctx[0x00008];
00365         pseudo_bit_t reserved3[0x00007];
00366         pseudo_bit_t pptx[0x00001];
00367 /* -------------- */
00368         pseudo_bit_t reserved4[0x00010];
00369         pseudo_bit_t pfcrx[0x00008];
00370         pseudo_bit_t reserved5[0x00007];
00371         pseudo_bit_t pprx[0x00001];
00372 /* -------------- */
00373 } __attribute__ (( packed ));
00374 
00375 struct hermonprm_set_port_rqp_calc_st {
00376         pseudo_bit_t base_qpn[0x00018];
00377         pseudo_bit_t reserved0[0x00008];
00378 /* -------------- */
00379         pseudo_bit_t n_p[0x00002];
00380         pseudo_bit_t reserved1[0x00006];
00381         pseudo_bit_t n_v[0x00003];
00382         pseudo_bit_t reserved2[0x00005];
00383         pseudo_bit_t n_m[0x00004];
00384         pseudo_bit_t reserved3[0x0000c];
00385 /* -------------- */
00386         pseudo_bit_t mac_miss_index[0x00008];
00387         pseudo_bit_t reserved4[0x00018];
00388 /* -------------- */
00389         pseudo_bit_t vlan_miss_index[0x00007];
00390         pseudo_bit_t reserved5[0x00008];
00391         pseudo_bit_t intra_miss[0x00001];
00392         pseudo_bit_t no_vlan_index[0x00007];
00393         pseudo_bit_t reserved6[0x00008];
00394         pseudo_bit_t intra_no_vlan[0x00001];
00395 /* -------------- */
00396         pseudo_bit_t no_vlan_prio[0x00003];
00397         pseudo_bit_t reserved7[0x0001d];
00398 /* -------------- */
00399         pseudo_bit_t promisc_qpn[0x00018];
00400         pseudo_bit_t reserved8[0x00007];
00401         pseudo_bit_t en_uc_promisc[0x00001];
00402 /* -------------- */
00403         pseudo_bit_t def_mcast_qpn[0x00018];
00404         pseudo_bit_t reserved9[0x00005];
00405         pseudo_bit_t mc_by_vlan[0x00001];
00406         pseudo_bit_t mc_promisc_mode[0x00002];
00407 /* -------------- */
00408         pseudo_bit_t reserved10[0x00020];
00409 /* -------------- */
00410 } __attribute__ (( packed ));
00411 
00412 struct hermonprm_set_port_mac_table_st {
00413         pseudo_bit_t mac_h[0x00010];
00414         pseudo_bit_t reserved0[0x0000f];
00415         pseudo_bit_t v[0x00001];
00416 /* -------------- */
00417         pseudo_bit_t mac_l[0x00020];
00418 /* -------------- */
00419 } __attribute__ (( packed ));
00420 
00421 struct hermonprm_set_port_vlan_st {
00422         pseudo_bit_t vlan_id[0x0000c];
00423         pseudo_bit_t reserved0[0x00012];
00424         pseudo_bit_t intra[0x00001];
00425         pseudo_bit_t v[0x00001];
00426 /* -------------- */
00427 } __attribute__ (( packed ));
00428 
00429 struct hermonprm_mod_stat_cfg_input_mod_st {
00430         pseudo_bit_t offset[0x00008];
00431         pseudo_bit_t portnum[0x00008];
00432         pseudo_bit_t xnum[0x00004];
00433         pseudo_bit_t linkspeed[0x00003];
00434         pseudo_bit_t autoneg[0x00001];
00435         pseudo_bit_t reserved[0x00004];
00436         pseudo_bit_t setup_mode[0x00004];
00437 } __attribute__ (( packed ));
00438 
00439 /*
00440  * Wrapper structures for hardware datatypes
00441  *
00442  */
00443 
00444 struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_context );
00445 struct MLX_DECLARE_STRUCT ( hermonprm_completion_queue_entry );
00446 struct MLX_DECLARE_STRUCT ( hermonprm_completion_with_error );
00447 struct MLX_DECLARE_STRUCT ( hermonprm_cq_db_record );
00448 struct MLX_DECLARE_STRUCT ( hermonprm_eqc );
00449 struct MLX_DECLARE_STRUCT ( hermonprm_event_db_register );
00450 struct MLX_DECLARE_STRUCT ( hermonprm_event_mask );
00451 struct MLX_DECLARE_STRUCT ( hermonprm_event_queue_entry );
00452 struct MLX_DECLARE_STRUCT ( hermonprm_hca_command_register );
00453 struct MLX_DECLARE_STRUCT ( hermonprm_init_hca );
00454 struct MLX_DECLARE_STRUCT ( hermonprm_mad_ifc );
00455 struct MLX_DECLARE_STRUCT ( hermonprm_mcg_entry );
00456 struct MLX_DECLARE_STRUCT ( hermonprm_mgm_hash );
00457 struct MLX_DECLARE_STRUCT ( hermonprm_mod_stat_cfg );
00458 struct MLX_DECLARE_STRUCT ( hermonprm_mod_stat_cfg_input_mod );
00459 struct MLX_DECLARE_STRUCT ( hermonprm_mpt );
00460 struct MLX_DECLARE_STRUCT ( hermonprm_mtt );
00461 struct MLX_DECLARE_STRUCT ( hermonprm_port_state_change_event );
00462 struct MLX_DECLARE_STRUCT ( hermonprm_qp_db_record );
00463 struct MLX_DECLARE_STRUCT ( hermonprm_qp_ee_state_transitions );
00464 struct MLX_DECLARE_STRUCT ( hermonprm_query_dev_cap );
00465 struct MLX_DECLARE_STRUCT ( hermonprm_query_fw );
00466 struct MLX_DECLARE_STRUCT ( hermonprm_query_port_cap );
00467 struct MLX_DECLARE_STRUCT ( hermonprm_queue_pair_ee_context_entry );
00468 struct MLX_DECLARE_STRUCT ( hermonprm_scalar_parameter );
00469 struct MLX_DECLARE_STRUCT ( hermonprm_sense_port );
00470 struct MLX_DECLARE_STRUCT ( hermonprm_send_db_register );
00471 struct MLX_DECLARE_STRUCT ( hermonprm_set_port_ib );
00472 struct MLX_DECLARE_STRUCT ( hermonprm_set_port_general_context );
00473 struct MLX_DECLARE_STRUCT ( hermonprm_set_port_mac_table );
00474 struct MLX_DECLARE_STRUCT ( hermonprm_set_port_rqp_calc );
00475 struct MLX_DECLARE_STRUCT ( hermonprm_set_port_vlan );
00476 struct MLX_DECLARE_STRUCT ( hermonprm_ud_address_vector );
00477 struct MLX_DECLARE_STRUCT ( hermonprm_virtual_physical_mapping );
00478 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ctrl_mlx );
00479 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ctrl_send );
00480 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_data_ptr );
00481 struct MLX_DECLARE_STRUCT ( hermonprm_wqe_segment_ud );
00482 
00483 /*
00484  * Composite hardware datatypes
00485  *
00486  */
00487 
00488 struct hermonprm_write_mtt {
00489         struct hermonprm_scalar_parameter mtt_base_addr;
00490         struct hermonprm_scalar_parameter reserved;
00491         struct hermonprm_mtt mtt;
00492 } __attribute__ (( packed ));
00493 
00494 #define HERMON_MAX_GATHER 2
00495 
00496 struct hermonprm_ud_send_wqe {
00497         struct hermonprm_wqe_segment_ctrl_send ctrl;
00498         struct hermonprm_wqe_segment_ud ud;
00499         struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
00500 } __attribute__ (( packed ));
00501 
00502 struct hermonprm_mlx_send_wqe {
00503         struct hermonprm_wqe_segment_ctrl_mlx ctrl;
00504         struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
00505         uint8_t headers[IB_MAX_HEADER_SIZE];
00506 } __attribute__ (( packed ));
00507 
00508 struct hermonprm_rc_send_wqe {
00509         struct hermonprm_wqe_segment_ctrl_send ctrl;
00510         struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
00511 } __attribute__ (( packed ));
00512 
00513 struct hermonprm_eth_send_wqe {
00514         struct hermonprm_wqe_segment_ctrl_send ctrl;
00515         struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
00516 } __attribute__ (( packed ));
00517 
00518 #define HERMON_MAX_SCATTER 2
00519 
00520 struct hermonprm_recv_wqe {
00521         struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_SCATTER];
00522 } __attribute__ (( packed ));
00523 
00524 union hermonprm_completion_entry {
00525         struct hermonprm_completion_queue_entry normal;
00526         struct hermonprm_completion_with_error error;
00527 } __attribute__ (( packed ));
00528 
00529 union hermonprm_event_entry {
00530         struct hermonprm_event_queue_entry generic;
00531         struct hermonprm_port_state_change_event port_state_change;
00532 } __attribute__ (( packed ));
00533 
00534 union hermonprm_doorbell_register {
00535         struct hermonprm_send_db_register send;
00536         struct hermonprm_event_db_register event;
00537         uint32_t dword[1];
00538 } __attribute__ (( packed ));
00539 
00540 union hermonprm_mad {
00541         struct hermonprm_mad_ifc ifc;
00542         union ib_mad mad;
00543 } __attribute__ (( packed ));
00544 
00545 union hermonprm_set_port {
00546         struct hermonprm_set_port_ib ib;
00547         struct hermonprm_set_port_general_context general;
00548         struct hermonprm_set_port_rqp_calc rqp_calc;
00549         struct hermonprm_set_port_mac_table mac_table[128];
00550         struct hermonprm_set_port_vlan vlan;
00551 } __attribute__ (( packed ));
00552 
00553 /*
00554  * iPXE-specific definitions
00555  *
00556  */
00557 
00558 /** Hermon device capabilitiess */
00559 struct hermon_dev_cap {
00560         /** CMPT entry size */
00561         size_t cmpt_entry_size;
00562         /** Number of reserved QPs */
00563         unsigned int reserved_qps;
00564         /** QP context entry size */
00565         size_t qpc_entry_size;
00566         /** Alternate path context entry size */
00567         size_t altc_entry_size;
00568         /** Auxiliary context entry size */
00569         size_t auxc_entry_size;
00570         /** Number of reserved SRQs */
00571         unsigned int reserved_srqs;
00572         /** SRQ context entry size */
00573         size_t srqc_entry_size;
00574         /** Number of reserved CQs */
00575         unsigned int reserved_cqs;
00576         /** CQ context entry size */
00577         size_t cqc_entry_size;
00578         /** Number of reserved EQs */
00579         unsigned int reserved_eqs;
00580         /** EQ context entry size */
00581         size_t eqc_entry_size;
00582         /** Number of reserved MTTs */
00583         unsigned int reserved_mtts;
00584         /** MTT entry size */
00585         size_t mtt_entry_size;
00586         /** Number of reserved MRWs */
00587         unsigned int reserved_mrws;
00588         /** DMPT entry size */
00589         size_t dmpt_entry_size;
00590         /** Number of reserved UARs */
00591         unsigned int reserved_uars;
00592         /** Number of ports */
00593         unsigned int num_ports;
00594         /** Dual-port different protocol */
00595         int dpdp;
00596 };
00597 
00598 /** Number of cMPT entries of each type */
00599 #define HERMON_CMPT_MAX_ENTRIES ( 1 << 24 )
00600 
00601 /** Hermon ICM memory map entry */
00602 struct hermon_icm_map {
00603         /** Offset (virtual address within ICM) */
00604         uint64_t offset;
00605         /** Length */
00606         size_t len;
00607 };
00608 
00609 /** Discontiguous regions within Hermon ICM */
00610 enum hermon_icm_map_regions {
00611         HERMON_ICM_QP_CMPT = 0,
00612         HERMON_ICM_SRQ_CMPT,
00613         HERMON_ICM_CQ_CMPT,
00614         HERMON_ICM_EQ_CMPT,
00615         HERMON_ICM_OTHER,
00616         HERMON_ICM_NUM_REGIONS
00617 };
00618 
00619 /** UAR page for doorbell accesses
00620  *
00621  * Pages 0-127 are reserved for event queue doorbells only, so we use
00622  * page 128.
00623  */
00624 #define HERMON_UAR_NON_EQ_PAGE  128
00625 
00626 /** Maximum number of allocatable MTT entries
00627  *
00628  * This is a policy decision, not a device limit.
00629  */
00630 #define HERMON_MAX_MTTS         64
00631 
00632 /** A Hermon MTT descriptor */
00633 struct hermon_mtt {
00634         /** MTT offset */
00635         unsigned int mtt_offset;
00636         /** Number of pages */
00637         unsigned int num_pages;
00638         /** MTT base address */
00639         unsigned int mtt_base_addr;
00640         /** Offset within page */
00641         unsigned int page_offset;
00642 };
00643 
00644 /** Alignment of Hermon send work queue entries */
00645 #define HERMON_SEND_WQE_ALIGN 128
00646 
00647 /** A Hermon send work queue entry */
00648 union hermon_send_wqe {
00649         struct hermonprm_wqe_segment_ctrl_send ctrl;
00650         struct hermonprm_ud_send_wqe ud;
00651         struct hermonprm_mlx_send_wqe mlx;
00652         struct hermonprm_rc_send_wqe rc;
00653         struct hermonprm_eth_send_wqe eth;
00654         uint8_t force_align[HERMON_SEND_WQE_ALIGN];
00655 } __attribute__ (( packed ));
00656 
00657 /** A Hermon send work queue */
00658 struct hermon_send_work_queue {
00659         /** Number of work queue entries, including headroom
00660          *
00661          * Hermon requires us to leave unused space within the send
00662          * WQ, so we create a send WQ with more entries than are
00663          * requested in the create_qp() call.
00664          */
00665         unsigned int num_wqes;
00666         /** Work queue entries */
00667         union hermon_send_wqe *wqe;
00668         /** Size of work queue */
00669         size_t wqe_size;
00670         /** Doorbell register */
00671         void *doorbell;
00672 };
00673 
00674 /** Alignment of Hermon receive work queue entries */
00675 #define HERMON_RECV_WQE_ALIGN 16
00676 
00677 /** A Hermon receive work queue entry */
00678 union hermon_recv_wqe {
00679         struct hermonprm_recv_wqe recv;
00680         uint8_t force_align[HERMON_RECV_WQE_ALIGN];
00681 } __attribute__ (( packed ));
00682 
00683 /** A Hermon receive work queue */
00684 struct hermon_recv_work_queue {
00685         /** Work queue entries */
00686         union hermon_recv_wqe *wqe;
00687         /** Size of work queue */
00688         size_t wqe_size;
00689         /** GRH buffers (if applicable) */
00690         struct ib_global_route_header *grh;
00691         /** Size of GRH buffers */
00692         size_t grh_size;
00693         /** Doorbell record */
00694         struct hermonprm_qp_db_record *doorbell;
00695 };
00696 
00697 /** Number of special queue pairs */
00698 #define HERMON_NUM_SPECIAL_QPS 8
00699 
00700 /** Number of queue pairs reserved for the "special QP" block
00701  *
00702  * The special QPs must be within a contiguous block aligned on its
00703  * own size.
00704  */
00705 #define HERMON_RSVD_SPECIAL_QPS ( ( HERMON_NUM_SPECIAL_QPS << 1 ) - 1 )
00706 
00707 /** Maximum number of allocatable queue pairs
00708  *
00709  * This is a policy decision, not a device limit.
00710  */
00711 #define HERMON_MAX_QPS          8
00712 
00713 /** Queue pair number randomisation mask */
00714 #define HERMON_QPN_RANDOM_MASK 0xfff000
00715 
00716 /** Hermon queue pair state */
00717 enum hermon_queue_pair_state {
00718         HERMON_QP_ST_RST = 0,
00719         HERMON_QP_ST_INIT,
00720         HERMON_QP_ST_RTR,
00721         HERMON_QP_ST_RTS,
00722 };
00723 
00724 /** A Hermon queue pair */
00725 struct hermon_queue_pair {
00726         /** Work queue buffer */
00727         void *wqe;
00728         /** Size of work queue buffer */
00729         size_t wqe_size;
00730         /** MTT descriptor */
00731         struct hermon_mtt mtt;
00732         /** Send work queue */
00733         struct hermon_send_work_queue send;
00734         /** Receive work queue */
00735         struct hermon_recv_work_queue recv;
00736         /** Queue state */
00737         enum hermon_queue_pair_state state;
00738 };
00739 
00740 /** Maximum number of allocatable completion queues
00741  *
00742  * This is a policy decision, not a device limit.
00743  */
00744 #define HERMON_MAX_CQS          8
00745 
00746 /** A Hermon completion queue */
00747 struct hermon_completion_queue {
00748         /** Completion queue entries */
00749         union hermonprm_completion_entry *cqe;
00750         /** Size of completion queue */
00751         size_t cqe_size;
00752         /** MTT descriptor */
00753         struct hermon_mtt mtt;
00754         /** Doorbell record */
00755         struct hermonprm_cq_db_record *doorbell;
00756 };
00757 
00758 /** Maximum number of allocatable event queues
00759  *
00760  * This is a policy decision, not a device limit.
00761  */
00762 #define HERMON_MAX_EQS          8
00763 
00764 /** A Hermon event queue */
00765 struct hermon_event_queue {
00766         /** Event queue entries */
00767         union hermonprm_event_entry *eqe;
00768         /** Size of event queue */
00769         size_t eqe_size;
00770         /** MTT descriptor */
00771         struct hermon_mtt mtt;
00772         /** Event queue number */
00773         unsigned long eqn;
00774         /** Next event queue entry index */
00775         unsigned long next_idx;
00776         /** Doorbell register */
00777         void *doorbell;
00778 };
00779 
00780 /** Number of event queue entries
00781  *
00782  * This is a policy decision.
00783  */
00784 #define HERMON_NUM_EQES         8
00785 
00786 /** A Hermon resource bitmask */
00787 typedef uint32_t hermon_bitmask_t;
00788 
00789 /** Size of a hermon resource bitmask */
00790 #define HERMON_BITMASK_SIZE(max_entries)                                     \
00791         ( ( (max_entries) + ( 8 * sizeof ( hermon_bitmask_t ) ) - 1 ) /      \
00792           ( 8 * sizeof ( hermon_bitmask_t ) ) )
00793 
00794 struct hermon;
00795 struct hermon_port;
00796 
00797 /** A Hermon port type */
00798 struct hermon_port_type {
00799         /** Register port
00800          *
00801          * @v hermon            Hermon device
00802          * @v port              Hermon port
00803          * @ret rc              Return status code
00804          */
00805         int ( * register_dev ) ( struct hermon *hermon,
00806                                  struct hermon_port *port );
00807         /** Port state changed
00808          *
00809          * @v hermon            Hermon device
00810          * @v port              Hermon port
00811          * @v link_up           Link is up
00812          */
00813         void ( * state_change ) ( struct hermon *hermon,
00814                                   struct hermon_port *port,
00815                                   int link_up );
00816         /** Unregister port
00817          *
00818          * @v hermon            Hermon device
00819          * @v port              Hermon port
00820          */
00821         void ( * unregister_dev ) ( struct hermon *hermon,
00822                                     struct hermon_port *port );
00823 };
00824 
00825 /** A Hermon port */
00826 struct hermon_port {
00827         /** Infiniband device */
00828         struct ib_device *ibdev;
00829         /** Network device */
00830         struct net_device *netdev;
00831         /** Ethernet completion queue */
00832         struct ib_completion_queue *eth_cq;
00833         /** Ethernet queue pair */
00834         struct ib_queue_pair *eth_qp;
00835         /** Port type */
00836         struct hermon_port_type *type;
00837         /** Non-volatile option storage */
00838         struct nvo_block nvo;
00839 };
00840 
00841 /** A Hermon device */
00842 struct hermon {
00843         /** PCI device */
00844         struct pci_device *pci;
00845         /** PCI configuration registers */
00846         void *config;
00847         /** PCI user Access Region */
00848         void *uar;
00849 
00850         /** Command toggle */
00851         unsigned int toggle;
00852         /** Command input mailbox */
00853         void *mailbox_in;
00854         /** Command output mailbox */
00855         void *mailbox_out;
00856 
00857         /** Device open request counter */
00858         unsigned int open_count;
00859 
00860         /** Firmware size */
00861         size_t firmware_len;
00862         /** Firmware area in external memory
00863          *
00864          * This is allocated when first needed, and freed only on
00865          * final teardown, in order to avoid memory map changes at
00866          * runtime.
00867          */
00868         userptr_t firmware_area;
00869         /** ICM map */
00870         struct hermon_icm_map icm_map[HERMON_ICM_NUM_REGIONS];
00871         /** ICM size */
00872         size_t icm_len;
00873         /** ICM AUX size */
00874         size_t icm_aux_len;
00875         /** ICM area
00876          *
00877          * This is allocated when first needed, and freed only on
00878          * final teardown, in order to avoid memory map changes at
00879          * runtime.
00880          */
00881         userptr_t icm;
00882 
00883         /** Event queue */
00884         struct hermon_event_queue eq;
00885         /** Unrestricted LKey
00886          *
00887          * Used to get unrestricted memory access.
00888          */
00889         unsigned long lkey;
00890 
00891         /** Completion queue in-use bitmask */
00892         hermon_bitmask_t cq_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_CQS ) ];
00893         /** Queue pair in-use bitmask */
00894         hermon_bitmask_t qp_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_QPS ) ];
00895         /** MTT entry in-use bitmask */
00896         hermon_bitmask_t mtt_inuse[ HERMON_BITMASK_SIZE ( HERMON_MAX_MTTS ) ];
00897 
00898         /** Device capabilities */
00899         struct hermon_dev_cap cap;
00900         /** Special QPN base */
00901         unsigned long special_qpn_base;
00902         /** QPN base */
00903         unsigned long qpn_base;
00904 
00905         /** Non-volatile storage in PCI VPD */
00906         struct nvs_vpd_device nvsvpd;
00907 
00908         /** Ports */
00909         struct hermon_port port[HERMON_MAX_PORTS];
00910 
00911         /** BOFM device */
00912         struct bofm_device bofm;
00913 };
00914 
00915 /** Global protection domain */
00916 #define HERMON_GLOBAL_PD                0x123456
00917 
00918 /** Memory key prefix */
00919 #define HERMON_MKEY_PREFIX              0x77000000UL
00920 
00921 /*
00922  * HCA commands
00923  *
00924  */
00925 
00926 #define HERMON_HCR_BASE                 0x80680
00927 #define HERMON_HCR_REG(x)               ( HERMON_HCR_BASE + 4 * (x) )
00928 #define HERMON_HCR_MAX_WAIT_MS          2000
00929 #define HERMON_MBOX_ALIGN               4096
00930 #define HERMON_MBOX_SIZE                1024
00931 
00932 /* HCA command is split into
00933  *
00934  * bits  11:0   Opcode
00935  * bit     12   Input uses mailbox
00936  * bit     13   Output uses mailbox
00937  * bits 22:14   Input parameter length (in dwords)
00938  * bits 31:23   Output parameter length (in dwords)
00939  *
00940  * Encoding the information in this way allows us to cut out several
00941  * parameters to the hermon_command() call.
00942  */
00943 #define HERMON_HCR_IN_MBOX              0x00001000UL
00944 #define HERMON_HCR_OUT_MBOX             0x00002000UL
00945 #define HERMON_HCR_OPCODE( _command )   ( (_command) & 0xfff )
00946 #define HERMON_HCR_IN_LEN( _command )   ( ( (_command) >> 12 ) & 0x7fc )
00947 #define HERMON_HCR_OUT_LEN( _command )  ( ( (_command) >> 21 ) & 0x7fc )
00948 
00949 /** Build HCR command from component parts */
00950 #define HERMON_HCR_INOUT_CMD( _opcode, _in_mbox, _in_len,                    \
00951                              _out_mbox, _out_len )                           \
00952         ( (_opcode) |                                                        \
00953           ( (_in_mbox) ? HERMON_HCR_IN_MBOX : 0 ) |                          \
00954           ( ( (_in_len) / 4 ) << 14 ) |                                      \
00955           ( (_out_mbox) ? HERMON_HCR_OUT_MBOX : 0 ) |                        \
00956           ( ( (_out_len) / 4 ) << 23 ) )
00957 
00958 #define HERMON_HCR_IN_CMD( _opcode, _in_mbox, _in_len )                      \
00959         HERMON_HCR_INOUT_CMD ( _opcode, _in_mbox, _in_len, 0, 0 )
00960 
00961 #define HERMON_HCR_OUT_CMD( _opcode, _out_mbox, _out_len )                   \
00962         HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, _out_mbox, _out_len )
00963 
00964 #define HERMON_HCR_VOID_CMD( _opcode )                                       \
00965         HERMON_HCR_INOUT_CMD ( _opcode, 0, 0, 0, 0 )
00966 
00967 #endif /* _HERMON_H */