merlin16_pcieg3_field_access.h (8544B)
1 /************************************************************************************** 2 ************************************************************************************** 3 * File Name : merlin16_pcieg3_field_access.h * 4 * Created On : 29/04/2013 * 5 * Created By : Kiran Divakar * 6 * Description : Serdes IP Register and Field access APIs * 7 * Revision : * 8 * * 9 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 10 * 11 * Copyright 2007-2019 Broadcom Inc. All rights reserved. * 12 * No portions of this material may be reproduced in any form without * 13 * the written permission of: * 14 * Broadcom Corporation * 15 * 5300 California Avenue * 16 * Irvine, CA 92617 * 17 * * 18 * All information contained in this document is Broadcom Corporation * 19 * company private proprietary, and trade secret. * 20 */ 21 22 /** @file merlin16_pcieg3_field_access.h 23 * Registers and field access 24 */ 25 26 #ifndef MERLIN16_PCIEG3_API_FIELD_ACCESS_H 27 #define MERLIN16_PCIEG3_API_FIELD_ACCESS_H 28 29 #include "merlin16_pcieg3_ipconfig.h" 30 #include "common/srds_api_err_code.h" 31 #include "merlin16_pcieg3_dependencies.h" 32 33 /* Extract a bitfield from a register value. */ 34 #define extract_field(reg_value,msb,lsb) (((uint16_t)(reg_value) & ((1 << ((msb) + 1)) - 1)) >> (lsb)) 35 36 /** Read a register field as an unsigned value. 37 * @param sa__ is an opaque state vector passed through to device access functions. 38 * @param addr 16-bit register address. 39 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 40 * @param shift_right Number of right shifts to move field to bit0 [shift_right = (15 - msb + shift_right)] 41 * @param *val_p 16-bit unsigned value read from the field 42 * @return Error Code generated by API (returns ERR_CODE_NONE if no errors) 43 */ 44 err_code_t _merlin16_pcieg3_pmd_rdt_field(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, uint16_t *val_p); 45 46 /** Read a register field as an signed value. 47 * @param sa__ is an opaque state vector passed through to device access functions. 48 * @param addr 16-bit register address. 49 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 50 * @param shift_right Number of right shifts to move field to bit0 [shift_right = (15 - msb + lsb)] 51 * @param *val_p 16-bit signed value read from the field 52 * @return Error Code generated by API (returns ERR_CODE_NONE if no errors) 53 */ 54 err_code_t _merlin16_pcieg3_pmd_rdt_field_signed(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, int16_t *val_p); 55 56 57 /*-------------------------------*/ 58 /* Byte Write and Read Functions */ 59 /*-------------------------------*/ 60 61 /** Write a contiguous bit field in a register. 62 * @param sa__ is an opaque state vector passed through to device access functions. 63 * @param addr 16-bit register address. 64 * @param mask 16-bit mask indicating the position of the field with bits of 1s 65 * @param lsb LSB of the field, the width of the field is implied by mask. 66 * @param val 8bit value to write into the field. 67 * @return Error Code generated by API (returns ERR_CODE_NONE if no errors) 68 */ 69 err_code_t _merlin16_pcieg3_pmd_mwr_reg_byte(srds_access_t *sa__, uint16_t addr, uint16_t mask, uint8_t lsb, uint8_t val); 70 71 /** Read a register field as an 8-bit unsigned value. 72 * @param sa__ is an opaque state vector passed through to device access functions. 73 * @param addr 16-bit register address. 74 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 75 * @param shift_right Number of right shifts to move field to bit0 [shift_right = (15 - msb + lsb)] 76 * @param *val_p 8-bit unsigned value read from the field 77 * @return Error Code generated by API (returns ERR_CODE_NONE if no errors) 78 */ 79 err_code_t _merlin16_pcieg3_pmd_rdt_field_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, uint8_t *val_p); 80 81 /** Read a register field as an 8-bit signed value. 82 * @param sa__ is an opaque state vector passed through to device access functions. 83 * @param addr 16-bit register address. 84 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 85 * @param shift_right Number of right shifts to move field to bit0 [shift_right = (15 - msb + lsb)] 86 * @param *val_p 8-bit signed value read from the field 87 * @return Error Code generated by API (returns ERR_CODE_NONE if no errors) 88 */ 89 err_code_t _merlin16_pcieg3_pmd_rdt_field_signed_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, int8_t *val_p); 90 91 92 /***************************************************************************** 93 The following functions are being retained for legacy purposes and 94 for Serdes DVT, characterization backwards compatability 95 */ 96 97 /** Read a register. 98 * @param sa__ is an opaque state vector passed through to device access functions. 99 * @param addr 16-bit register address. 100 * @param err_code_p error code returned through pointer 101 * @return 16-bit value read from the register 102 */ 103 uint16_t _merlin16_pcieg3_pmd_rde_reg(srds_access_t *sa__, uint16_t addr, err_code_t *err_code_p); 104 105 /** Read a register field as an unsigned value. 106 * @param sa__ is an opaque state vector passed through to device access functions. 107 * @param addr 16-bit register address. 108 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 109 * @param shift_right Number of right shifts to move field to bit0 [shift_right = (15 - msb + lsb)] 110 * @param err_code_p error code returned through pointer 111 * @return 16-bit unsigned value read from the field 112 */ 113 uint16_t _merlin16_pcieg3_pmd_rde_field(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p); 114 115 /** Read a register field as a signed value. 116 * @param sa__ is an opaque state vector passed through to device access functions. 117 * @param addr 16-bit register address. 118 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 119 * @param shift_right Number of right shifts with sign extension [shift_right = (15 - msb + lsb)] 120 * @param err_code_p error code returned through pointer 121 * @return 16-bit signed value read from the field 122 */ 123 int16_t _merlin16_pcieg3_pmd_rde_field_signed(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p); 124 125 /** Read a bit field as an unsigned value. 126 * @param sa__ is an opaque state vector passed through to device access functions. 127 * @param addr 16-bit register address. 128 * @param shift_left Number of bits sign_bit should be moved to the left [shift_left = (15 - msb)] 129 * @param shift_right Number of right shifts to move field to bit0 [shift_right = (15 - msb + lsb)] 130 * @param err_code_p error code returned through pointer 131 * @return 8-bit unsigned value read from the field 132 */ 133 uint8_t _merlin16_pcieg3_pmd_rde_field_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p); 134 135 /** Read a bit field as a signed value. 136 * @param sa__ is an opaque state vector passed through to device access functions. 137 * @param addr 16-bit register address. 138 * @param shift_left Number of bits sign bit should be moved to the left [shift_left = (15 - msb)] 139 * @param shift_right Number of right shifts with sign extension [shift_right = (15 - msb + lsb)] 140 * @param err_code_p error code returned through pointer 141 * @return 8-bit signed value read from the field 142 */ 143 int8_t _merlin16_pcieg3_pmd_rde_field_signed_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p); 144 145 #endif /* FIELD_ACCESS_H_ */