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"
19 unsigned long qede_log2_align(unsigned long n)
21 unsigned long ret = n ? 1 : 0;
22 unsigned long _n = n >> 1;
35 u32 qede_osal_log2(u32 val)
45 inline void qede_set_bit(u32 nr, unsigned long *addr)
47 __sync_fetch_and_or(addr, (1UL << nr));
50 inline void qede_clr_bit(u32 nr, unsigned long *addr)
52 __sync_fetch_and_and(addr, ~(1UL << nr));
55 inline bool qede_test_bit(u32 nr, unsigned long *addr)
60 res = ((*addr) & (1UL << nr)) != 0;
65 static inline u32 qede_ffz(unsigned long word)
67 unsigned long first_zero;
69 first_zero = __builtin_ffsl(~word);
70 return first_zero ? (first_zero - 1) : OSAL_BITS_PER_UL;
73 inline u32 qede_find_first_zero_bit(unsigned long *addr, u32 limit)
77 OSAL_BUILD_BUG_ON(!limit);
78 nwords = (limit - 1) / OSAL_BITS_PER_UL + 1;
79 for (i = 0; i < nwords; i++)
82 return (i == nwords) ? limit : i * OSAL_BITS_PER_UL + qede_ffz(addr[i]);
85 void qede_vf_fill_driver_data(struct ecore_hwfn *hwfn,
86 __rte_unused struct vf_pf_resc_request *resc_req,
87 struct ecore_vf_acquire_sw_info *vf_sw_info)
89 vf_sw_info->os_type = VFPF_ACQUIRE_OS_LINUX_USERSPACE;
90 vf_sw_info->override_fw_version = 1;
93 void *osal_dma_alloc_coherent(struct ecore_dev *p_dev,
94 dma_addr_t *phys, size_t size)
96 const struct rte_memzone *mz;
97 char mz_name[RTE_MEMZONE_NAMESIZE];
98 uint32_t core_id = rte_lcore_id();
99 unsigned int socket_id;
101 OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
102 snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
103 (unsigned long)rte_get_timer_cycles());
104 if (core_id == (unsigned int)LCORE_ID_ANY)
106 socket_id = rte_lcore_to_socket_id(core_id);
107 mz = rte_memzone_reserve_aligned(mz_name, size,
108 socket_id, 0, RTE_CACHE_LINE_SIZE);
110 DP_ERR(p_dev, "Unable to allocate DMA memory "
111 "of size %zu bytes - %s\n",
112 size, rte_strerror(rte_errno));
116 *phys = mz->phys_addr;
117 DP_VERBOSE(p_dev, ECORE_MSG_PROBE,
118 "size=%zu phys=0x%lx virt=%p on socket=%u\n",
119 mz->len, mz->phys_addr, mz->addr, socket_id);
123 void *osal_dma_alloc_coherent_aligned(struct ecore_dev *p_dev,
124 dma_addr_t *phys, size_t size, int align)
126 const struct rte_memzone *mz;
127 char mz_name[RTE_MEMZONE_NAMESIZE];
128 uint32_t core_id = rte_lcore_id();
129 unsigned int socket_id;
131 OSAL_MEM_ZERO(mz_name, sizeof(*mz_name));
132 snprintf(mz_name, sizeof(mz_name) - 1, "%lx",
133 (unsigned long)rte_get_timer_cycles());
134 if (core_id == (unsigned int)LCORE_ID_ANY)
136 socket_id = rte_lcore_to_socket_id(core_id);
137 mz = rte_memzone_reserve_aligned(mz_name, size, socket_id, 0, align);
139 DP_ERR(p_dev, "Unable to allocate DMA memory "
140 "of size %zu bytes - %s\n",
141 size, rte_strerror(rte_errno));
145 *phys = mz->phys_addr;
146 DP_VERBOSE(p_dev, ECORE_MSG_PROBE,
147 "aligned memory size=%zu phys=0x%lx virt=%p core=%d\n",
148 mz->len, mz->phys_addr, mz->addr, core_id);
152 u32 qede_unzip_data(struct ecore_hwfn *p_hwfn, u32 input_len,
153 u8 *input_buf, u32 max_size, u8 *unzip_buf)
157 p_hwfn->stream->next_in = input_buf;
158 p_hwfn->stream->avail_in = input_len;
159 p_hwfn->stream->next_out = unzip_buf;
160 p_hwfn->stream->avail_out = max_size;
162 rc = inflateInit2(p_hwfn->stream, MAX_WBITS);
166 "zlib init failed, rc = %d\n", rc);
170 rc = inflate(p_hwfn->stream, Z_FINISH);
171 inflateEnd(p_hwfn->stream);
173 if (rc != Z_OK && rc != Z_STREAM_END) {
175 "FW unzip error: %s, rc=%d\n", p_hwfn->stream->msg,
180 return p_hwfn->stream->total_out / 4;