2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
9 #include <rte_memzone.h>
10 #include <rte_errno.h>
15 #include "ecore_iov_api.h"
16 #include "ecore_mcp_api.h"
17 #include "ecore_l2_api.h"
20 unsigned long qede_log2_align(unsigned long n)
22 unsigned long ret = n ? 1 : 0;
23 unsigned long _n = n >> 1;
36 u32 qede_osal_log2(u32 val)
46 inline void qede_set_bit(u32 nr, unsigned long *addr)
48 __sync_fetch_and_or(addr, (1UL << nr));
51 inline void qede_clr_bit(u32 nr, unsigned long *addr)
53 __sync_fetch_and_and(addr, ~(1UL << nr));
56 inline bool qede_test_bit(u32 nr, unsigned long *addr)
61 res = ((*addr) & (1UL << nr)) != 0;
66 static inline u32 qede_ffb(unsigned long word)
68 unsigned long first_bit;
70 first_bit = __builtin_ffsl(word);
71 return first_bit ? (first_bit - 1) : OSAL_BITS_PER_UL;
74 inline u32 qede_find_first_bit(unsigned long *addr, u32 limit)
78 OSAL_BUILD_BUG_ON(!limit);
79 nwords = (limit - 1) / OSAL_BITS_PER_UL + 1;
80 for (i = 0; i < nwords; i++)
84 return (i == nwords) ? limit : i * OSAL_BITS_PER_UL + qede_ffb(addr[i]);
87 static inline u32 qede_ffz(unsigned long word)
89 unsigned long first_zero;
91 first_zero = __builtin_ffsl(~word);
92 return first_zero ? (first_zero - 1) : OSAL_BITS_PER_UL;
95 inline u32 qede_find_first_zero_bit(unsigned long *addr, u32 limit)
99 OSAL_BUILD_BUG_ON(!limit);
100 nwords = (limit - 1) / OSAL_BITS_PER_UL + 1;
101 for (i = 0; i < nwords && ~(addr[i]) == 0; i++);
102 return (i == nwords) ? limit : i * OSAL_BITS_PER_UL + qede_ffz(addr[i]);
105 void qede_vf_fill_driver_data(struct ecore_hwfn *hwfn,
106 __rte_unused struct vf_pf_resc_request *resc_req,
107 struct ecore_vf_acquire_sw_info *vf_sw_info)
109 vf_sw_info->os_type = VFPF_ACQUIRE_OS_LINUX_USERSPACE;
110 vf_sw_info->override_fw_version = 1;
113 void *osal_dma_alloc_coherent(struct ecore_dev *p_dev,
114 dma_addr_t *phys, size_t size)
116 const struct rte_memzone *mz;
117 char mz_name[RTE_MEMZONE_NAMESIZE];
118 uint32_t core_id = rte_lcore_id();
119 unsigned int socket_id;
121 OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
122 snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
123 (unsigned long)rte_get_timer_cycles());
124 if (core_id == (unsigned int)LCORE_ID_ANY)
126 socket_id = rte_lcore_to_socket_id(core_id);
127 mz = rte_memzone_reserve_aligned(mz_name, size,
128 socket_id, 0, RTE_CACHE_LINE_SIZE);
130 DP_ERR(p_dev, "Unable to allocate DMA memory "
131 "of size %zu bytes - %s\n",
132 size, rte_strerror(rte_errno));
136 *phys = mz->phys_addr;
137 DP_VERBOSE(p_dev, ECORE_MSG_PROBE,
138 "size=%zu phys=0x%" PRIx64 " virt=%p on socket=%u\n",
139 mz->len, mz->phys_addr, mz->addr, socket_id);
143 void *osal_dma_alloc_coherent_aligned(struct ecore_dev *p_dev,
144 dma_addr_t *phys, size_t size, int align)
146 const struct rte_memzone *mz;
147 char mz_name[RTE_MEMZONE_NAMESIZE];
148 uint32_t core_id = rte_lcore_id();
149 unsigned int socket_id;
151 OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
152 snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
153 (unsigned long)rte_get_timer_cycles());
154 if (core_id == (unsigned int)LCORE_ID_ANY)
156 socket_id = rte_lcore_to_socket_id(core_id);
157 mz = rte_memzone_reserve_aligned(mz_name, size, socket_id, 0, align);
159 DP_ERR(p_dev, "Unable to allocate DMA memory "
160 "of size %zu bytes - %s\n",
161 size, rte_strerror(rte_errno));
165 *phys = mz->phys_addr;
166 DP_VERBOSE(p_dev, ECORE_MSG_PROBE,
167 "aligned memory size=%zu phys=0x%" PRIx64 " virt=%p core=%d\n",
168 mz->len, mz->phys_addr, mz->addr, core_id);
172 #ifdef CONFIG_ECORE_ZIPPED_FW
173 u32 qede_unzip_data(struct ecore_hwfn *p_hwfn, u32 input_len,
174 u8 *input_buf, u32 max_size, u8 *unzip_buf)
178 p_hwfn->stream->next_in = input_buf;
179 p_hwfn->stream->avail_in = input_len;
180 p_hwfn->stream->next_out = unzip_buf;
181 p_hwfn->stream->avail_out = max_size;
183 rc = inflateInit2(p_hwfn->stream, MAX_WBITS);
187 "zlib init failed, rc = %d\n", rc);
191 rc = inflate(p_hwfn->stream, Z_FINISH);
192 inflateEnd(p_hwfn->stream);
194 if (rc != Z_OK && rc != Z_STREAM_END) {
196 "FW unzip error: %s, rc=%d\n", p_hwfn->stream->msg,
201 return p_hwfn->stream->total_out / 4;
206 qede_get_mcp_proto_stats(struct ecore_dev *edev,
207 enum ecore_mcp_protocol_type type,
208 union ecore_mcp_protocol_stats *stats)
210 struct ecore_eth_stats lan_stats;
212 if (type == ECORE_MCP_LAN_STATS) {
213 ecore_get_vport_stats(edev, &lan_stats);
214 stats->lan_stats.ucast_rx_pkts = lan_stats.rx_ucast_pkts;
215 stats->lan_stats.ucast_tx_pkts = lan_stats.tx_ucast_pkts;
216 stats->lan_stats.fcs_err = -1;
218 DP_INFO(edev, "Statistics request type %d not supported\n",