2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
11 #include <rte_memzone.h>
12 #include <rte_errno.h>
17 #include "ecore_iov_api.h"
18 #include "ecore_mcp_api.h"
19 #include "ecore_l2_api.h"
22 unsigned long qede_log2_align(unsigned long n)
24 unsigned long ret = n ? 1 : 0;
25 unsigned long _n = n >> 1;
38 u32 qede_osal_log2(u32 val)
48 inline void qede_set_bit(u32 nr, unsigned long *addr)
50 __sync_fetch_and_or(addr, (1UL << nr));
53 inline void qede_clr_bit(u32 nr, unsigned long *addr)
55 __sync_fetch_and_and(addr, ~(1UL << nr));
58 inline bool qede_test_bit(u32 nr, unsigned long *addr)
63 res = ((*addr) & (1UL << nr)) != 0;
68 static inline u32 qede_ffb(unsigned long word)
70 unsigned long first_bit;
72 first_bit = __builtin_ffsl(word);
73 return first_bit ? (first_bit - 1) : OSAL_BITS_PER_UL;
76 inline u32 qede_find_first_bit(unsigned long *addr, u32 limit)
80 OSAL_BUILD_BUG_ON(!limit);
81 nwords = (limit - 1) / OSAL_BITS_PER_UL + 1;
82 for (i = 0; i < nwords; i++)
86 return (i == nwords) ? limit : i * OSAL_BITS_PER_UL + qede_ffb(addr[i]);
89 static inline u32 qede_ffz(unsigned long word)
91 unsigned long first_zero;
93 first_zero = __builtin_ffsl(~word);
94 return first_zero ? (first_zero - 1) : OSAL_BITS_PER_UL;
97 inline u32 qede_find_first_zero_bit(unsigned long *addr, u32 limit)
101 OSAL_BUILD_BUG_ON(!limit);
102 nwords = (limit - 1) / OSAL_BITS_PER_UL + 1;
103 for (i = 0; i < nwords; i++)
106 return (i == nwords) ? limit : i * OSAL_BITS_PER_UL + qede_ffz(addr[i]);
109 void qede_vf_fill_driver_data(struct ecore_hwfn *hwfn,
110 __rte_unused struct vf_pf_resc_request *resc_req,
111 struct ecore_vf_acquire_sw_info *vf_sw_info)
113 vf_sw_info->os_type = VFPF_ACQUIRE_OS_LINUX_USERSPACE;
114 vf_sw_info->override_fw_version = 1;
117 void *osal_dma_alloc_coherent(struct ecore_dev *p_dev,
118 dma_addr_t *phys, size_t size)
120 const struct rte_memzone *mz;
121 char mz_name[RTE_MEMZONE_NAMESIZE];
122 uint32_t core_id = rte_lcore_id();
123 unsigned int socket_id;
125 OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
126 snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
127 (unsigned long)rte_get_timer_cycles());
128 if (core_id == (unsigned int)LCORE_ID_ANY)
130 socket_id = rte_lcore_to_socket_id(core_id);
131 mz = rte_memzone_reserve_aligned(mz_name, size,
132 socket_id, 0, RTE_CACHE_LINE_SIZE);
134 DP_ERR(p_dev, "Unable to allocate DMA memory "
135 "of size %zu bytes - %s\n",
136 size, rte_strerror(rte_errno));
140 *phys = mz->phys_addr;
141 DP_VERBOSE(p_dev, ECORE_MSG_PROBE,
142 "size=%zu phys=0x%" PRIx64 " virt=%p on socket=%u\n",
143 mz->len, mz->phys_addr, mz->addr, socket_id);
147 void *osal_dma_alloc_coherent_aligned(struct ecore_dev *p_dev,
148 dma_addr_t *phys, size_t size, int align)
150 const struct rte_memzone *mz;
151 char mz_name[RTE_MEMZONE_NAMESIZE];
152 uint32_t core_id = rte_lcore_id();
153 unsigned int socket_id;
155 OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
156 snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
157 (unsigned long)rte_get_timer_cycles());
158 if (core_id == (unsigned int)LCORE_ID_ANY)
160 socket_id = rte_lcore_to_socket_id(core_id);
161 mz = rte_memzone_reserve_aligned(mz_name, size, socket_id, 0, align);
163 DP_ERR(p_dev, "Unable to allocate DMA memory "
164 "of size %zu bytes - %s\n",
165 size, rte_strerror(rte_errno));
169 *phys = mz->phys_addr;
170 DP_VERBOSE(p_dev, ECORE_MSG_PROBE,
171 "aligned memory size=%zu phys=0x%" PRIx64 " virt=%p core=%d\n",
172 mz->len, mz->phys_addr, mz->addr, core_id);
176 #ifdef CONFIG_ECORE_ZIPPED_FW
177 u32 qede_unzip_data(struct ecore_hwfn *p_hwfn, u32 input_len,
178 u8 *input_buf, u32 max_size, u8 *unzip_buf)
182 p_hwfn->stream->next_in = input_buf;
183 p_hwfn->stream->avail_in = input_len;
184 p_hwfn->stream->next_out = unzip_buf;
185 p_hwfn->stream->avail_out = max_size;
187 rc = inflateInit2(p_hwfn->stream, MAX_WBITS);
191 "zlib init failed, rc = %d\n", rc);
195 rc = inflate(p_hwfn->stream, Z_FINISH);
196 inflateEnd(p_hwfn->stream);
198 if (rc != Z_OK && rc != Z_STREAM_END) {
200 "FW unzip error: %s, rc=%d\n", p_hwfn->stream->msg,
205 return p_hwfn->stream->total_out / 4;
210 qede_get_mcp_proto_stats(struct ecore_dev *edev,
211 enum ecore_mcp_protocol_type type,
212 union ecore_mcp_protocol_stats *stats)
214 struct ecore_eth_stats lan_stats;
216 if (type == ECORE_MCP_LAN_STATS) {
217 ecore_get_vport_stats(edev, &lan_stats);
218 stats->lan_stats.ucast_rx_pkts = lan_stats.rx_ucast_pkts;
219 stats->lan_stats.ucast_tx_pkts = lan_stats.tx_ucast_pkts;
220 stats->lan_stats.fcs_err = -1;
222 DP_INFO(edev, "Statistics request type %d not supported\n",