1718cf2ccSPedro F. Giffuni /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4088fc971SDavid C Somayajulu * Copyright (c) 2011-2013 Qlogic Corporation
50bc7cf6fSBjoern A. Zeeb * All rights reserved.
60bc7cf6fSBjoern A. Zeeb *
70bc7cf6fSBjoern A. Zeeb * Redistribution and use in source and binary forms, with or without
80bc7cf6fSBjoern A. Zeeb * modification, are permitted provided that the following conditions
90bc7cf6fSBjoern A. Zeeb * are met:
100bc7cf6fSBjoern A. Zeeb *
110bc7cf6fSBjoern A. Zeeb * 1. Redistributions of source code must retain the above copyright
120bc7cf6fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer.
130bc7cf6fSBjoern A. Zeeb * 2. Redistributions in binary form must reproduce the above copyright
140bc7cf6fSBjoern A. Zeeb * notice, this list of conditions and the following disclaimer in the
150bc7cf6fSBjoern A. Zeeb * documentation and/or other materials provided with the distribution.
160bc7cf6fSBjoern A. Zeeb *
170bc7cf6fSBjoern A. Zeeb * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
180bc7cf6fSBjoern A. Zeeb * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190bc7cf6fSBjoern A. Zeeb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200bc7cf6fSBjoern A. Zeeb * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
210bc7cf6fSBjoern A. Zeeb * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
220bc7cf6fSBjoern A. Zeeb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
230bc7cf6fSBjoern A. Zeeb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
240bc7cf6fSBjoern A. Zeeb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
250bc7cf6fSBjoern A. Zeeb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
260bc7cf6fSBjoern A. Zeeb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
270bc7cf6fSBjoern A. Zeeb * POSSIBILITY OF SUCH DAMAGE.
280bc7cf6fSBjoern A. Zeeb */
290bc7cf6fSBjoern A. Zeeb /*
300bc7cf6fSBjoern A. Zeeb * File: qla_inline.h
310bc7cf6fSBjoern A. Zeeb * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656.
320bc7cf6fSBjoern A. Zeeb */
330bc7cf6fSBjoern A. Zeeb #ifndef _QLA_INLINE_H_
340bc7cf6fSBjoern A. Zeeb #define _QLA_INLINE_H_
350bc7cf6fSBjoern A. Zeeb
360bc7cf6fSBjoern A. Zeeb /*
370bc7cf6fSBjoern A. Zeeb * Function: qla_hw_reset
380bc7cf6fSBjoern A. Zeeb */
qla_hw_reset(qla_host_t * ha)390bc7cf6fSBjoern A. Zeeb static __inline void qla_hw_reset(qla_host_t *ha)
400bc7cf6fSBjoern A. Zeeb {
410bc7cf6fSBjoern A. Zeeb WRITE_OFFSET32(ha, Q8_ASIC_RESET, 0xFFFFFFFF);
420bc7cf6fSBjoern A. Zeeb }
430bc7cf6fSBjoern A. Zeeb
440bc7cf6fSBjoern A. Zeeb #define QL8_SEMLOCK_TIMEOUT 1000/* QLA8020 Semaphore Lock Timeout 10ms */
450bc7cf6fSBjoern A. Zeeb
460bc7cf6fSBjoern A. Zeeb /*
470bc7cf6fSBjoern A. Zeeb * Inline functions for hardware semaphores
480bc7cf6fSBjoern A. Zeeb */
490bc7cf6fSBjoern A. Zeeb
500bc7cf6fSBjoern A. Zeeb /*
510bc7cf6fSBjoern A. Zeeb * Name: qla_sem_lock
520bc7cf6fSBjoern A. Zeeb * Function: Locks one of the semaphore registers (semaphore 2,3,5 & 7)
530bc7cf6fSBjoern A. Zeeb * If the id_reg is valid, then id_val is written into it.
540bc7cf6fSBjoern A. Zeeb * This is for debugging purpose
550bc7cf6fSBjoern A. Zeeb * Returns: 0 on success; otherwise its failed.
560bc7cf6fSBjoern A. Zeeb */
570bc7cf6fSBjoern A. Zeeb static __inline int
qla_sem_lock(qla_host_t * ha,uint32_t sem_reg,uint32_t id_reg,uint32_t id_val)580bc7cf6fSBjoern A. Zeeb qla_sem_lock(qla_host_t *ha, uint32_t sem_reg, uint32_t id_reg, uint32_t id_val)
590bc7cf6fSBjoern A. Zeeb {
600bc7cf6fSBjoern A. Zeeb int count = QL8_SEMLOCK_TIMEOUT;
610bc7cf6fSBjoern A. Zeeb
620bc7cf6fSBjoern A. Zeeb while (count) {
630bc7cf6fSBjoern A. Zeeb if ((READ_REG32(ha, sem_reg) & SEM_LOCK_BIT))
640bc7cf6fSBjoern A. Zeeb break;
650bc7cf6fSBjoern A. Zeeb count--;
660bc7cf6fSBjoern A. Zeeb
670bc7cf6fSBjoern A. Zeeb if (!count)
680bc7cf6fSBjoern A. Zeeb return(-1);
690bc7cf6fSBjoern A. Zeeb qla_mdelay(__func__, 10);
700bc7cf6fSBjoern A. Zeeb }
710bc7cf6fSBjoern A. Zeeb if (id_reg)
720bc7cf6fSBjoern A. Zeeb WRITE_OFFSET32(ha, id_reg, id_val);
730bc7cf6fSBjoern A. Zeeb
740bc7cf6fSBjoern A. Zeeb return(0);
750bc7cf6fSBjoern A. Zeeb }
760bc7cf6fSBjoern A. Zeeb
770bc7cf6fSBjoern A. Zeeb /*
780bc7cf6fSBjoern A. Zeeb * Name: qla_sem_unlock
790bc7cf6fSBjoern A. Zeeb * Function: Unlocks the semaphore registers (semaphore 2,3,5 & 7)
800bc7cf6fSBjoern A. Zeeb * previously locked by qla_sem_lock()
810bc7cf6fSBjoern A. Zeeb */
820bc7cf6fSBjoern A. Zeeb static __inline void
qla_sem_unlock(qla_host_t * ha,uint32_t sem_reg)830bc7cf6fSBjoern A. Zeeb qla_sem_unlock(qla_host_t *ha, uint32_t sem_reg)
840bc7cf6fSBjoern A. Zeeb {
850bc7cf6fSBjoern A. Zeeb READ_REG32(ha, sem_reg);
860bc7cf6fSBjoern A. Zeeb }
870bc7cf6fSBjoern A. Zeeb
880bc7cf6fSBjoern A. Zeeb static __inline int
qla_get_ifq_snd_maxlen(qla_host_t * ha)890bc7cf6fSBjoern A. Zeeb qla_get_ifq_snd_maxlen(qla_host_t *ha)
900bc7cf6fSBjoern A. Zeeb {
910bc7cf6fSBjoern A. Zeeb return((NUM_TX_DESCRIPTORS - 1));
920bc7cf6fSBjoern A. Zeeb }
930bc7cf6fSBjoern A. Zeeb
940bc7cf6fSBjoern A. Zeeb static __inline uint32_t
qla_get_optics(qla_host_t * ha)950bc7cf6fSBjoern A. Zeeb qla_get_optics(qla_host_t *ha)
960bc7cf6fSBjoern A. Zeeb {
970bc7cf6fSBjoern A. Zeeb uint32_t link_speed;
980bc7cf6fSBjoern A. Zeeb
990bc7cf6fSBjoern A. Zeeb link_speed = READ_REG32(ha, Q8_LINK_SPEED_0);
1000bc7cf6fSBjoern A. Zeeb if (ha->pci_func == 0)
1010bc7cf6fSBjoern A. Zeeb link_speed = link_speed & 0xFF;
1020bc7cf6fSBjoern A. Zeeb else
1030bc7cf6fSBjoern A. Zeeb link_speed = (link_speed >> 8) & 0xFF;
1040bc7cf6fSBjoern A. Zeeb
1050bc7cf6fSBjoern A. Zeeb switch (link_speed) {
1060bc7cf6fSBjoern A. Zeeb case 0x1:
1070bc7cf6fSBjoern A. Zeeb link_speed = IFM_100_FX;
1080bc7cf6fSBjoern A. Zeeb break;
1090bc7cf6fSBjoern A. Zeeb
1100bc7cf6fSBjoern A. Zeeb case 0x10:
1110bc7cf6fSBjoern A. Zeeb link_speed = IFM_1000_SX;
1120bc7cf6fSBjoern A. Zeeb break;
1130bc7cf6fSBjoern A. Zeeb
1140bc7cf6fSBjoern A. Zeeb default:
1150bc7cf6fSBjoern A. Zeeb link_speed = (IFM_10G_LR | IFM_10G_SR);
1160bc7cf6fSBjoern A. Zeeb break;
1170bc7cf6fSBjoern A. Zeeb }
1180bc7cf6fSBjoern A. Zeeb
1190bc7cf6fSBjoern A. Zeeb return(link_speed);
1200bc7cf6fSBjoern A. Zeeb }
1210bc7cf6fSBjoern A. Zeeb
1220bc7cf6fSBjoern A. Zeeb static __inline uint8_t *
qla_get_mac_addr(qla_host_t * ha)1230bc7cf6fSBjoern A. Zeeb qla_get_mac_addr(qla_host_t *ha)
1240bc7cf6fSBjoern A. Zeeb {
1250bc7cf6fSBjoern A. Zeeb return (ha->hw.mac_addr);
1260bc7cf6fSBjoern A. Zeeb }
1270bc7cf6fSBjoern A. Zeeb
1280bc7cf6fSBjoern A. Zeeb static __inline void
qla_read_mac_addr(qla_host_t * ha)1290bc7cf6fSBjoern A. Zeeb qla_read_mac_addr(qla_host_t *ha)
1300bc7cf6fSBjoern A. Zeeb {
1310bc7cf6fSBjoern A. Zeeb uint32_t mac_crb_addr;
1320bc7cf6fSBjoern A. Zeeb uint32_t mac_lo;
1330bc7cf6fSBjoern A. Zeeb uint32_t mac_hi;
1340bc7cf6fSBjoern A. Zeeb uint8_t *macp;
1350bc7cf6fSBjoern A. Zeeb
1360bc7cf6fSBjoern A. Zeeb mac_crb_addr = Q8_CRB_MAC_BLOCK_START +
1370bc7cf6fSBjoern A. Zeeb (((ha->pci_func >> 1) * 3) << 2) + ((ha->pci_func & 0x01) << 2);
1380bc7cf6fSBjoern A. Zeeb
1390bc7cf6fSBjoern A. Zeeb mac_lo = READ_REG32(ha, mac_crb_addr);
1400bc7cf6fSBjoern A. Zeeb mac_hi = READ_REG32(ha, (mac_crb_addr + 0x4));
1410bc7cf6fSBjoern A. Zeeb
1420bc7cf6fSBjoern A. Zeeb if (ha->pci_func & 0x01) {
1430bc7cf6fSBjoern A. Zeeb mac_lo = mac_lo >> 16;
1440bc7cf6fSBjoern A. Zeeb
1450bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_lo;
1460bc7cf6fSBjoern A. Zeeb
1470bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[5] = macp[0];
1480bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[4] = macp[1];
1490bc7cf6fSBjoern A. Zeeb
1500bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_hi;
1510bc7cf6fSBjoern A. Zeeb
1520bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[3] = macp[0];
1530bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[2] = macp[1];
1540bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[1] = macp[2];
1550bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[0] = macp[3];
1560bc7cf6fSBjoern A. Zeeb } else {
1570bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_lo;
1580bc7cf6fSBjoern A. Zeeb
1590bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[5] = macp[0];
1600bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[4] = macp[1];
1610bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[3] = macp[2];
1620bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[2] = macp[3];
1630bc7cf6fSBjoern A. Zeeb
1640bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_hi;
1650bc7cf6fSBjoern A. Zeeb
1660bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[1] = macp[0];
1670bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[0] = macp[1];
1680bc7cf6fSBjoern A. Zeeb }
1690bc7cf6fSBjoern A. Zeeb return;
1700bc7cf6fSBjoern A. Zeeb }
1710bc7cf6fSBjoern A. Zeeb
1720bc7cf6fSBjoern A. Zeeb static __inline void
qla_set_hw_rcv_desc(qla_host_t * ha,uint32_t ridx,uint32_t index,uint32_t handle,bus_addr_t paddr,uint32_t buf_size)1730bc7cf6fSBjoern A. Zeeb qla_set_hw_rcv_desc(qla_host_t *ha, uint32_t ridx, uint32_t index,
1740bc7cf6fSBjoern A. Zeeb uint32_t handle, bus_addr_t paddr, uint32_t buf_size)
1750bc7cf6fSBjoern A. Zeeb {
1760bc7cf6fSBjoern A. Zeeb q80_recv_desc_t *rcv_desc;
1770bc7cf6fSBjoern A. Zeeb
1780bc7cf6fSBjoern A. Zeeb rcv_desc = (q80_recv_desc_t *)ha->hw.dma_buf.rds_ring[ridx].dma_b;
1790bc7cf6fSBjoern A. Zeeb
1800bc7cf6fSBjoern A. Zeeb rcv_desc += index;
1810bc7cf6fSBjoern A. Zeeb
1820bc7cf6fSBjoern A. Zeeb rcv_desc->handle = (uint16_t)handle;
1830bc7cf6fSBjoern A. Zeeb rcv_desc->buf_size = buf_size;
1840bc7cf6fSBjoern A. Zeeb rcv_desc->buf_addr = paddr;
1850bc7cf6fSBjoern A. Zeeb
1860bc7cf6fSBjoern A. Zeeb return;
1870bc7cf6fSBjoern A. Zeeb }
1880bc7cf6fSBjoern A. Zeeb
1890bc7cf6fSBjoern A. Zeeb static __inline void
qla_init_hw_rcv_descriptors(qla_host_t * ha,uint32_t ridx)1900bc7cf6fSBjoern A. Zeeb qla_init_hw_rcv_descriptors(qla_host_t *ha, uint32_t ridx)
1910bc7cf6fSBjoern A. Zeeb {
1920bc7cf6fSBjoern A. Zeeb if (ridx == RDS_RING_INDEX_NORMAL)
1930bc7cf6fSBjoern A. Zeeb bzero((void *)ha->hw.dma_buf.rds_ring[ridx].dma_b,
1940bc7cf6fSBjoern A. Zeeb (sizeof(q80_recv_desc_t) * NUM_RX_DESCRIPTORS));
1950bc7cf6fSBjoern A. Zeeb else if (ridx == RDS_RING_INDEX_JUMBO)
1960bc7cf6fSBjoern A. Zeeb bzero((void *)ha->hw.dma_buf.rds_ring[ridx].dma_b,
1970bc7cf6fSBjoern A. Zeeb (sizeof(q80_recv_desc_t) * NUM_RX_JUMBO_DESCRIPTORS));
1980bc7cf6fSBjoern A. Zeeb else
1990bc7cf6fSBjoern A. Zeeb QL_ASSERT(0, ("%s: invalid rds index [%d]\n", __func__, ridx));
2000bc7cf6fSBjoern A. Zeeb }
2010bc7cf6fSBjoern A. Zeeb
2020bc7cf6fSBjoern A. Zeeb static __inline void
qla_lock(qla_host_t * ha,const char * str)2030bc7cf6fSBjoern A. Zeeb qla_lock(qla_host_t *ha, const char *str)
2040bc7cf6fSBjoern A. Zeeb {
2050bc7cf6fSBjoern A. Zeeb while (1) {
2060bc7cf6fSBjoern A. Zeeb mtx_lock(&ha->hw_lock);
2070bc7cf6fSBjoern A. Zeeb if (!ha->hw_lock_held) {
2080bc7cf6fSBjoern A. Zeeb ha->hw_lock_held = 1;
2090bc7cf6fSBjoern A. Zeeb ha->qla_lock = str;
2100bc7cf6fSBjoern A. Zeeb mtx_unlock(&ha->hw_lock);
2110bc7cf6fSBjoern A. Zeeb break;
2120bc7cf6fSBjoern A. Zeeb }
2130bc7cf6fSBjoern A. Zeeb mtx_unlock(&ha->hw_lock);
2140bc7cf6fSBjoern A. Zeeb qla_mdelay(__func__, 1);
2150bc7cf6fSBjoern A. Zeeb }
2160bc7cf6fSBjoern A. Zeeb return;
2170bc7cf6fSBjoern A. Zeeb }
2180bc7cf6fSBjoern A. Zeeb
2190bc7cf6fSBjoern A. Zeeb static __inline void
qla_unlock(qla_host_t * ha,const char * str)2200bc7cf6fSBjoern A. Zeeb qla_unlock(qla_host_t *ha, const char *str)
2210bc7cf6fSBjoern A. Zeeb {
2220bc7cf6fSBjoern A. Zeeb mtx_lock(&ha->hw_lock);
2230bc7cf6fSBjoern A. Zeeb ha->hw_lock_held = 0;
2240bc7cf6fSBjoern A. Zeeb ha->qla_unlock = str;
2250bc7cf6fSBjoern A. Zeeb mtx_unlock(&ha->hw_lock);
2260bc7cf6fSBjoern A. Zeeb }
2270bc7cf6fSBjoern A. Zeeb
2280bc7cf6fSBjoern A. Zeeb #endif /* #ifndef _QLA_INLINE_H_ */
229