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 * $FreeBSD$ 300bc7cf6fSBjoern A. Zeeb */ 310bc7cf6fSBjoern A. Zeeb /* 320bc7cf6fSBjoern A. Zeeb * File: qla_inline.h 330bc7cf6fSBjoern A. Zeeb * Author : David C Somayajulu, Qlogic Corporation, Aliso Viejo, CA 92656. 340bc7cf6fSBjoern A. Zeeb */ 350bc7cf6fSBjoern A. Zeeb #ifndef _QLA_INLINE_H_ 360bc7cf6fSBjoern A. Zeeb #define _QLA_INLINE_H_ 370bc7cf6fSBjoern A. Zeeb 380bc7cf6fSBjoern A. Zeeb /* 390bc7cf6fSBjoern A. Zeeb * Function: qla_hw_reset 400bc7cf6fSBjoern A. Zeeb */ 410bc7cf6fSBjoern A. Zeeb static __inline void qla_hw_reset(qla_host_t *ha) 420bc7cf6fSBjoern A. Zeeb { 430bc7cf6fSBjoern A. Zeeb WRITE_OFFSET32(ha, Q8_ASIC_RESET, 0xFFFFFFFF); 440bc7cf6fSBjoern A. Zeeb } 450bc7cf6fSBjoern A. Zeeb 460bc7cf6fSBjoern A. Zeeb #define QL8_SEMLOCK_TIMEOUT 1000/* QLA8020 Semaphore Lock Timeout 10ms */ 470bc7cf6fSBjoern A. Zeeb 480bc7cf6fSBjoern A. Zeeb /* 490bc7cf6fSBjoern A. Zeeb * Inline functions for hardware semaphores 500bc7cf6fSBjoern A. Zeeb */ 510bc7cf6fSBjoern A. Zeeb 520bc7cf6fSBjoern A. Zeeb /* 530bc7cf6fSBjoern A. Zeeb * Name: qla_sem_lock 540bc7cf6fSBjoern A. Zeeb * Function: Locks one of the semaphore registers (semaphore 2,3,5 & 7) 550bc7cf6fSBjoern A. Zeeb * If the id_reg is valid, then id_val is written into it. 560bc7cf6fSBjoern A. Zeeb * This is for debugging purpose 570bc7cf6fSBjoern A. Zeeb * Returns: 0 on success; otherwise its failed. 580bc7cf6fSBjoern A. Zeeb */ 590bc7cf6fSBjoern A. Zeeb static __inline int 600bc7cf6fSBjoern A. Zeeb qla_sem_lock(qla_host_t *ha, uint32_t sem_reg, uint32_t id_reg, uint32_t id_val) 610bc7cf6fSBjoern A. Zeeb { 620bc7cf6fSBjoern A. Zeeb int count = QL8_SEMLOCK_TIMEOUT; 630bc7cf6fSBjoern A. Zeeb 640bc7cf6fSBjoern A. Zeeb while (count) { 650bc7cf6fSBjoern A. Zeeb if ((READ_REG32(ha, sem_reg) & SEM_LOCK_BIT)) 660bc7cf6fSBjoern A. Zeeb break; 670bc7cf6fSBjoern A. Zeeb count--; 680bc7cf6fSBjoern A. Zeeb 690bc7cf6fSBjoern A. Zeeb if (!count) 700bc7cf6fSBjoern A. Zeeb return(-1); 710bc7cf6fSBjoern A. Zeeb qla_mdelay(__func__, 10); 720bc7cf6fSBjoern A. Zeeb } 730bc7cf6fSBjoern A. Zeeb if (id_reg) 740bc7cf6fSBjoern A. Zeeb WRITE_OFFSET32(ha, id_reg, id_val); 750bc7cf6fSBjoern A. Zeeb 760bc7cf6fSBjoern A. Zeeb return(0); 770bc7cf6fSBjoern A. Zeeb } 780bc7cf6fSBjoern A. Zeeb 790bc7cf6fSBjoern A. Zeeb /* 800bc7cf6fSBjoern A. Zeeb * Name: qla_sem_unlock 810bc7cf6fSBjoern A. Zeeb * Function: Unlocks the semaphore registers (semaphore 2,3,5 & 7) 820bc7cf6fSBjoern A. Zeeb * previously locked by qla_sem_lock() 830bc7cf6fSBjoern A. Zeeb */ 840bc7cf6fSBjoern A. Zeeb static __inline void 850bc7cf6fSBjoern A. Zeeb qla_sem_unlock(qla_host_t *ha, uint32_t sem_reg) 860bc7cf6fSBjoern A. Zeeb { 870bc7cf6fSBjoern A. Zeeb READ_REG32(ha, sem_reg); 880bc7cf6fSBjoern A. Zeeb } 890bc7cf6fSBjoern A. Zeeb 900bc7cf6fSBjoern A. Zeeb static __inline int 910bc7cf6fSBjoern A. Zeeb qla_get_ifq_snd_maxlen(qla_host_t *ha) 920bc7cf6fSBjoern A. Zeeb { 930bc7cf6fSBjoern A. Zeeb return((NUM_TX_DESCRIPTORS - 1)); 940bc7cf6fSBjoern A. Zeeb } 950bc7cf6fSBjoern A. Zeeb 960bc7cf6fSBjoern A. Zeeb static __inline uint32_t 970bc7cf6fSBjoern A. Zeeb qla_get_optics(qla_host_t *ha) 980bc7cf6fSBjoern A. Zeeb { 990bc7cf6fSBjoern A. Zeeb uint32_t link_speed; 1000bc7cf6fSBjoern A. Zeeb 1010bc7cf6fSBjoern A. Zeeb link_speed = READ_REG32(ha, Q8_LINK_SPEED_0); 1020bc7cf6fSBjoern A. Zeeb if (ha->pci_func == 0) 1030bc7cf6fSBjoern A. Zeeb link_speed = link_speed & 0xFF; 1040bc7cf6fSBjoern A. Zeeb else 1050bc7cf6fSBjoern A. Zeeb link_speed = (link_speed >> 8) & 0xFF; 1060bc7cf6fSBjoern A. Zeeb 1070bc7cf6fSBjoern A. Zeeb switch (link_speed) { 1080bc7cf6fSBjoern A. Zeeb case 0x1: 1090bc7cf6fSBjoern A. Zeeb link_speed = IFM_100_FX; 1100bc7cf6fSBjoern A. Zeeb break; 1110bc7cf6fSBjoern A. Zeeb 1120bc7cf6fSBjoern A. Zeeb case 0x10: 1130bc7cf6fSBjoern A. Zeeb link_speed = IFM_1000_SX; 1140bc7cf6fSBjoern A. Zeeb break; 1150bc7cf6fSBjoern A. Zeeb 1160bc7cf6fSBjoern A. Zeeb default: 1170bc7cf6fSBjoern A. Zeeb link_speed = (IFM_10G_LR | IFM_10G_SR); 1180bc7cf6fSBjoern A. Zeeb break; 1190bc7cf6fSBjoern A. Zeeb } 1200bc7cf6fSBjoern A. Zeeb 1210bc7cf6fSBjoern A. Zeeb return(link_speed); 1220bc7cf6fSBjoern A. Zeeb } 1230bc7cf6fSBjoern A. Zeeb 1240bc7cf6fSBjoern A. Zeeb static __inline uint8_t * 1250bc7cf6fSBjoern A. Zeeb qla_get_mac_addr(qla_host_t *ha) 1260bc7cf6fSBjoern A. Zeeb { 1270bc7cf6fSBjoern A. Zeeb return (ha->hw.mac_addr); 1280bc7cf6fSBjoern A. Zeeb } 1290bc7cf6fSBjoern A. Zeeb 1300bc7cf6fSBjoern A. Zeeb static __inline void 1310bc7cf6fSBjoern A. Zeeb qla_read_mac_addr(qla_host_t *ha) 1320bc7cf6fSBjoern A. Zeeb { 1330bc7cf6fSBjoern A. Zeeb uint32_t mac_crb_addr; 1340bc7cf6fSBjoern A. Zeeb uint32_t mac_lo; 1350bc7cf6fSBjoern A. Zeeb uint32_t mac_hi; 1360bc7cf6fSBjoern A. Zeeb uint8_t *macp; 1370bc7cf6fSBjoern A. Zeeb 1380bc7cf6fSBjoern A. Zeeb mac_crb_addr = Q8_CRB_MAC_BLOCK_START + 1390bc7cf6fSBjoern A. Zeeb (((ha->pci_func >> 1) * 3) << 2) + ((ha->pci_func & 0x01) << 2); 1400bc7cf6fSBjoern A. Zeeb 1410bc7cf6fSBjoern A. Zeeb mac_lo = READ_REG32(ha, mac_crb_addr); 1420bc7cf6fSBjoern A. Zeeb mac_hi = READ_REG32(ha, (mac_crb_addr + 0x4)); 1430bc7cf6fSBjoern A. Zeeb 1440bc7cf6fSBjoern A. Zeeb if (ha->pci_func & 0x01) { 1450bc7cf6fSBjoern A. Zeeb mac_lo = mac_lo >> 16; 1460bc7cf6fSBjoern A. Zeeb 1470bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_lo; 1480bc7cf6fSBjoern A. Zeeb 1490bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[5] = macp[0]; 1500bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[4] = macp[1]; 1510bc7cf6fSBjoern A. Zeeb 1520bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_hi; 1530bc7cf6fSBjoern A. Zeeb 1540bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[3] = macp[0]; 1550bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[2] = macp[1]; 1560bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[1] = macp[2]; 1570bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[0] = macp[3]; 1580bc7cf6fSBjoern A. Zeeb } else { 1590bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_lo; 1600bc7cf6fSBjoern A. Zeeb 1610bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[5] = macp[0]; 1620bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[4] = macp[1]; 1630bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[3] = macp[2]; 1640bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[2] = macp[3]; 1650bc7cf6fSBjoern A. Zeeb 1660bc7cf6fSBjoern A. Zeeb macp = (uint8_t *)&mac_hi; 1670bc7cf6fSBjoern A. Zeeb 1680bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[1] = macp[0]; 1690bc7cf6fSBjoern A. Zeeb ha->hw.mac_addr[0] = macp[1]; 1700bc7cf6fSBjoern A. Zeeb } 1710bc7cf6fSBjoern A. Zeeb return; 1720bc7cf6fSBjoern A. Zeeb } 1730bc7cf6fSBjoern A. Zeeb 1740bc7cf6fSBjoern A. Zeeb static __inline void 1750bc7cf6fSBjoern A. Zeeb qla_set_hw_rcv_desc(qla_host_t *ha, uint32_t ridx, uint32_t index, 1760bc7cf6fSBjoern A. Zeeb uint32_t handle, bus_addr_t paddr, uint32_t buf_size) 1770bc7cf6fSBjoern A. Zeeb { 1780bc7cf6fSBjoern A. Zeeb q80_recv_desc_t *rcv_desc; 1790bc7cf6fSBjoern A. Zeeb 1800bc7cf6fSBjoern A. Zeeb rcv_desc = (q80_recv_desc_t *)ha->hw.dma_buf.rds_ring[ridx].dma_b; 1810bc7cf6fSBjoern A. Zeeb 1820bc7cf6fSBjoern A. Zeeb rcv_desc += index; 1830bc7cf6fSBjoern A. Zeeb 1840bc7cf6fSBjoern A. Zeeb rcv_desc->handle = (uint16_t)handle; 1850bc7cf6fSBjoern A. Zeeb rcv_desc->buf_size = buf_size; 1860bc7cf6fSBjoern A. Zeeb rcv_desc->buf_addr = paddr; 1870bc7cf6fSBjoern A. Zeeb 1880bc7cf6fSBjoern A. Zeeb return; 1890bc7cf6fSBjoern A. Zeeb } 1900bc7cf6fSBjoern A. Zeeb 1910bc7cf6fSBjoern A. Zeeb static __inline void 1920bc7cf6fSBjoern A. Zeeb qla_init_hw_rcv_descriptors(qla_host_t *ha, uint32_t ridx) 1930bc7cf6fSBjoern A. Zeeb { 1940bc7cf6fSBjoern A. Zeeb if (ridx == RDS_RING_INDEX_NORMAL) 1950bc7cf6fSBjoern A. Zeeb bzero((void *)ha->hw.dma_buf.rds_ring[ridx].dma_b, 1960bc7cf6fSBjoern A. Zeeb (sizeof(q80_recv_desc_t) * NUM_RX_DESCRIPTORS)); 1970bc7cf6fSBjoern A. Zeeb else if (ridx == RDS_RING_INDEX_JUMBO) 1980bc7cf6fSBjoern A. Zeeb bzero((void *)ha->hw.dma_buf.rds_ring[ridx].dma_b, 1990bc7cf6fSBjoern A. Zeeb (sizeof(q80_recv_desc_t) * NUM_RX_JUMBO_DESCRIPTORS)); 2000bc7cf6fSBjoern A. Zeeb else 2010bc7cf6fSBjoern A. Zeeb QL_ASSERT(0, ("%s: invalid rds index [%d]\n", __func__, ridx)); 2020bc7cf6fSBjoern A. Zeeb } 2030bc7cf6fSBjoern A. Zeeb 2040bc7cf6fSBjoern A. Zeeb static __inline void 2050bc7cf6fSBjoern A. Zeeb qla_lock(qla_host_t *ha, const char *str) 2060bc7cf6fSBjoern A. Zeeb { 2070bc7cf6fSBjoern A. Zeeb while (1) { 2080bc7cf6fSBjoern A. Zeeb mtx_lock(&ha->hw_lock); 2090bc7cf6fSBjoern A. Zeeb if (!ha->hw_lock_held) { 2100bc7cf6fSBjoern A. Zeeb ha->hw_lock_held = 1; 2110bc7cf6fSBjoern A. Zeeb ha->qla_lock = str; 2120bc7cf6fSBjoern A. Zeeb mtx_unlock(&ha->hw_lock); 2130bc7cf6fSBjoern A. Zeeb break; 2140bc7cf6fSBjoern A. Zeeb } 2150bc7cf6fSBjoern A. Zeeb mtx_unlock(&ha->hw_lock); 2160bc7cf6fSBjoern A. Zeeb qla_mdelay(__func__, 1); 2170bc7cf6fSBjoern A. Zeeb } 2180bc7cf6fSBjoern A. Zeeb return; 2190bc7cf6fSBjoern A. Zeeb } 2200bc7cf6fSBjoern A. Zeeb 2210bc7cf6fSBjoern A. Zeeb static __inline void 2220bc7cf6fSBjoern A. Zeeb qla_unlock(qla_host_t *ha, const char *str) 2230bc7cf6fSBjoern A. Zeeb { 2240bc7cf6fSBjoern A. Zeeb mtx_lock(&ha->hw_lock); 2250bc7cf6fSBjoern A. Zeeb ha->hw_lock_held = 0; 2260bc7cf6fSBjoern A. Zeeb ha->qla_unlock = str; 2270bc7cf6fSBjoern A. Zeeb mtx_unlock(&ha->hw_lock); 2280bc7cf6fSBjoern A. Zeeb } 2290bc7cf6fSBjoern A. Zeeb 2300bc7cf6fSBjoern A. Zeeb #endif /* #ifndef _QLA_INLINE_H_ */ 231