1 #include "t4_hw.h" 2 #include "t4_chip_type.h" 3 #include "common.h" 4 5 /* legacy compatibility routines */ 6 int t4_memory_rw(struct adapter *adap, int win, 7 int mtype, u32 maddr, u32 len, 8 void *hbuf, int dir) 9 { 10 return t4_memory_rw_mtype(adap, win, mtype, maddr, len, hbuf, dir); 11 } 12 13 /** 14 * hash_mac_addr - return the hash value of a MAC address 15 * @addr: the 48-bit Ethernet MAC address 16 * 17 * Hashes a MAC address according to the hash function used by hardware 18 * inexact (hash) address matching. The description in the hardware 19 * documentation for the MPS says this: 20 * 21 * The hash function takes the 48 bit MAC address and hashes 22 * it down to six bits. Bit zero of the hash is the XOR of 23 * bits 0, 6 ... 42 of the MAC address. The other hash bits 24 * are computed in a similar fashion ending with bit five of 25 * the hash as the XOR of bits 5, 11 ... 47 of the MAC address. 26 */ 27 int hash_mac_addr(const u8 *addr) 28 { 29 u32 a = ((u32)addr[0] << 16) | ((u32)addr[1] << 8) | addr[2]; 30 u32 b = ((u32)addr[3] << 16) | ((u32)addr[4] << 8) | addr[5]; 31 32 a ^= b; 33 a ^= (a >> 12); 34 a ^= (a >> 6); 35 return a & 0x3f; 36 } 37 38 int t4_wr_mbox_ns(struct adapter *adap, int mbox, const void *cmd, 39 int size, void *rpl) 40 { 41 return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, false); 42 } 43 44 int t4_wr_mbox_timeout(struct adapter *adap, int mbox, 45 const void *cmd, int size, void *rpl, 46 int timeout) 47 { 48 return t4_wr_mbox_meat_timeout(adap, mbox, cmd, size, rpl, true, 49 timeout); 50 } 51 52 unsigned int dack_ticks_to_usec(const struct adapter *adap, 53 unsigned int ticks) 54 { 55 return (ticks << adap->params.tp.dack_re) / core_ticks_per_usec(adap); 56 } 57 58 unsigned int us_to_core_ticks(const struct adapter *adap, 59 unsigned int us) 60 { 61 return (us * adap->params.vpd.cclk) / 1000; 62 } 63 64 int is_offload(const struct adapter *adap) 65 { 66 return adap->params.offload; 67 } 68 69 /* 70 * Given a pointer to a Firmware Mailbox Command Log and a log entry index, 71 * return a pointer to the specified entry. 72 */ 73 struct mbox_cmd *mbox_cmd_log_entry(struct mbox_cmd_log *log, 74 unsigned int entry_idx) 75 { 76 return &((struct mbox_cmd *)&(log)[1])[entry_idx]; 77 } 78 79 int is_t4(enum chip_type chip) 80 { 81 return (CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4); 82 } 83 84 int is_t5(enum chip_type chip) 85 { 86 87 return (CHELSIO_CHIP_VERSION(chip) == CHELSIO_T5); 88 } 89 90 int is_t6(enum chip_type chip) 91 { 92 return (CHELSIO_CHIP_VERSION(chip) == CHELSIO_T6); 93 } 94 95 int is_fpga(enum chip_type chip) 96 { 97 return chip & CHELSIO_CHIP_FPGA; 98 } 99 100 /** 101 * t4_is_inserted_mod_type - is a plugged in Firmware Module Type 102 * @fw_mod_type: the Firmware Mofule Type 103 * 104 * Return whether the Firmware Module Type represents a real Transceiver 105 * Module/Cable Module Type which has been inserted. 106 */ 107 bool t4_is_inserted_mod_type(unsigned int fw_mod_type) 108 { 109 return (fw_mod_type != FW_PORT_MOD_TYPE_NONE && 110 fw_mod_type != FW_PORT_MOD_TYPE_NOTSUPPORTED && 111 fw_mod_type != FW_PORT_MOD_TYPE_UNKNOWN && 112 fw_mod_type != FW_PORT_MOD_TYPE_ERROR); 113 } 114 115 int t4_wr_mbox(struct adapter *adap, int mbox, const void *cmd, 116 int size, void *rpl) 117 { 118 return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, true); 119 } 120 121 unsigned int core_ticks_per_usec(const struct adapter *adap) 122 { 123 return adap->params.vpd.cclk / 1000; 124 } 125