2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2013-2016 Qlogic Corporation
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
33 * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
39 #define QL8_SEMLOCK_TIMEOUT 1000/* QLA8020 Semaphore Lock Timeout 10ms */
43 * Inline functions for hardware semaphores
48 * Function: Locks one of the semaphore registers (semaphore 2,3,5 & 7)
49 * If the id_reg is valid, then id_val is written into it.
50 * This is for debugging purpose
51 * Returns: 0 on success; otherwise its failed.
54 qla_sem_lock(qla_host_t *ha, uint32_t sem_reg, uint32_t id_reg, uint32_t id_val)
56 int count = QL8_SEMLOCK_TIMEOUT;
59 if ((READ_REG32(ha, sem_reg) & BIT_0))
65 qla_mdelay(__func__, 10);
68 WRITE_REG32(ha, id_reg, id_val);
74 * Name: qla_sem_unlock
75 * Function: Unlocks the semaphore registers (semaphore 2,3,5 & 7)
76 * previously locked by qla_sem_lock()
79 qla_sem_unlock(qla_host_t *ha, uint32_t sem_reg)
81 READ_REG32(ha, sem_reg);
85 qla_get_ifq_snd_maxlen(qla_host_t *ha)
87 return(((NUM_TX_DESCRIPTORS * 4) - 1));
90 static __inline uint32_t
91 qla_get_optics(qla_host_t *ha)
95 link_speed = READ_REG32(ha, Q8_LINK_SPEED_0);
96 if (ha->pci_func == 0)
97 link_speed = link_speed & 0xFF;
99 link_speed = (link_speed >> 8) & 0xFF;
101 switch (link_speed) {
103 link_speed = IFM_100_FX;
107 link_speed = IFM_1000_SX;
111 if ((ha->hw.module_type == 0x4) ||
112 (ha->hw.module_type == 0x5) ||
113 (ha->hw.module_type == 0x6))
114 link_speed = (IFM_10G_TWINAX);
116 link_speed = (IFM_10G_LR | IFM_10G_SR);
123 static __inline uint8_t *
124 qla_get_mac_addr(qla_host_t *ha)
126 return (ha->hw.mac_addr);
130 qla_set_hw_rcv_desc(qla_host_t *ha, uint32_t r_idx, uint32_t index,
131 uint32_t handle, bus_addr_t paddr, uint32_t buf_size)
133 volatile q80_recv_desc_t *rcv_desc;
135 rcv_desc = (q80_recv_desc_t *)ha->hw.dma_buf.rds_ring[r_idx].dma_b;
139 rcv_desc->handle = (uint16_t)handle;
140 rcv_desc->buf_size = buf_size;
141 rcv_desc->buf_addr = paddr;
147 qla_init_hw_rcv_descriptors(qla_host_t *ha)
151 for (i = 0; i < ha->hw.num_rds_rings; i++)
152 bzero((void *)ha->hw.dma_buf.rds_ring[i].dma_b,
153 (sizeof(q80_recv_desc_t) * NUM_RX_DESCRIPTORS));
156 #define QLA_LOCK_DEFAULT_MS_TIMEOUT 3000
158 #ifndef QLA_LOCK_NO_SLEEP
159 #define QLA_LOCK_NO_SLEEP 0
163 qla_lock(qla_host_t *ha, const char *str, uint32_t timeout_ms,
169 mtx_lock(&ha->hw_lock);
171 if (ha->qla_detach_active || ha->offline) {
172 mtx_unlock(&ha->hw_lock);
176 if (!ha->hw_lock_held) {
177 ha->hw_lock_held = 1;
180 mtx_unlock(&ha->hw_lock);
183 mtx_unlock(&ha->hw_lock);
185 if (--timeout_ms == 0) {
186 ha->hw_lock_failed++;
192 qla_mdelay(__func__, 1);
196 // if (!ha->enable_error_recovery)
197 // device_printf(ha->pci_dev, "%s: %s ret = %d\n", __func__,
204 qla_unlock(qla_host_t *ha, const char *str)
206 mtx_lock(&ha->hw_lock);
207 ha->hw_lock_held = 0;
208 ha->qla_unlock = str;
209 mtx_unlock(&ha->hw_lock);
211 // if (!ha->enable_error_recovery)
212 // device_printf(ha->pci_dev, "%s: %s\n", __func__, str);
217 #endif /* #ifndef _QL_INLINE_H_ */