18c2ecf20Sopenharmony_ci/********************************************************************** 28c2ecf20Sopenharmony_ci * Author: Cavium, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Contact: support@cavium.com 58c2ecf20Sopenharmony_ci * Please include "LiquidIO" in the subject. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2016 Cavium, Inc. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This file is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License, Version 2, as 118c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but 148c2ecf20Sopenharmony_ci * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty 158c2ecf20Sopenharmony_ci * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or 168c2ecf20Sopenharmony_ci * NONINFRINGEMENT. See the GNU General Public License for more details. 178c2ecf20Sopenharmony_ci ***********************************************************************/ 188c2ecf20Sopenharmony_ci/*! \file octeon_device.h 198c2ecf20Sopenharmony_ci * \brief Host Driver: This file defines the octeon device structure. 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#ifndef _OCTEON_DEVICE_H_ 238c2ecf20Sopenharmony_ci#define _OCTEON_DEVICE_H_ 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 268c2ecf20Sopenharmony_ci#include <net/devlink.h> 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/** PCI VendorId Device Id */ 298c2ecf20Sopenharmony_ci#define OCTEON_CN68XX_PCIID 0x91177d 308c2ecf20Sopenharmony_ci#define OCTEON_CN66XX_PCIID 0x92177d 318c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_PCIID_PF 0x9702177d 328c2ecf20Sopenharmony_ci/** Driver identifies chips by these Ids, created by clubbing together 338c2ecf20Sopenharmony_ci * DeviceId+RevisionId; Where Revision Id is not used to distinguish 348c2ecf20Sopenharmony_ci * between chips, a value of 0 is used for revision id. 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_ci#define OCTEON_CN68XX 0x0091 378c2ecf20Sopenharmony_ci#define OCTEON_CN66XX 0x0092 388c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_PF_VID 0x9702 398c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_VF_VID 0x9712 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/**RevisionId for the chips */ 428c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_REV_1_0 0x00 438c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_REV_1_1 0x01 448c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_REV_2_0 0x80 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/**SubsystemId for the chips */ 478c2ecf20Sopenharmony_ci#define OCTEON_CN2350_10GB_SUBSYS_ID_1 0X3177d 488c2ecf20Sopenharmony_ci#define OCTEON_CN2350_10GB_SUBSYS_ID_2 0X4177d 498c2ecf20Sopenharmony_ci#define OCTEON_CN2360_10GB_SUBSYS_ID 0X5177d 508c2ecf20Sopenharmony_ci#define OCTEON_CN2350_25GB_SUBSYS_ID 0X7177d 518c2ecf20Sopenharmony_ci#define OCTEON_CN2360_25GB_SUBSYS_ID 0X6177d 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/** Endian-swap modes supported by Octeon. */ 548c2ecf20Sopenharmony_cienum octeon_pci_swap_mode { 558c2ecf20Sopenharmony_ci OCTEON_PCI_PASSTHROUGH = 0, 568c2ecf20Sopenharmony_ci OCTEON_PCI_64BIT_SWAP = 1, 578c2ecf20Sopenharmony_ci OCTEON_PCI_32BIT_BYTE_SWAP = 2, 588c2ecf20Sopenharmony_ci OCTEON_PCI_32BIT_LW_SWAP = 3 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cienum lio_fw_state { 628c2ecf20Sopenharmony_ci FW_IS_PRELOADED = 0, 638c2ecf20Sopenharmony_ci FW_NEEDS_TO_BE_LOADED = 1, 648c2ecf20Sopenharmony_ci FW_IS_BEING_LOADED = 2, 658c2ecf20Sopenharmony_ci FW_HAS_BEEN_LOADED = 3, 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cienum { 698c2ecf20Sopenharmony_ci OCTEON_CONFIG_TYPE_DEFAULT = 0, 708c2ecf20Sopenharmony_ci NUM_OCTEON_CONFS, 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define OCTEON_INPUT_INTR (1) 748c2ecf20Sopenharmony_ci#define OCTEON_OUTPUT_INTR (2) 758c2ecf20Sopenharmony_ci#define OCTEON_MBOX_INTR (4) 768c2ecf20Sopenharmony_ci#define OCTEON_ALL_INTR 0xff 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/*--------------- PCI BAR1 index registers -------------*/ 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* BAR1 Mask */ 818c2ecf20Sopenharmony_ci#define PCI_BAR1_ENABLE_CA 1 828c2ecf20Sopenharmony_ci#define PCI_BAR1_ENDIAN_MODE OCTEON_PCI_64BIT_SWAP 838c2ecf20Sopenharmony_ci#define PCI_BAR1_ENTRY_VALID 1 848c2ecf20Sopenharmony_ci#define PCI_BAR1_MASK ((PCI_BAR1_ENABLE_CA << 3) \ 858c2ecf20Sopenharmony_ci | (PCI_BAR1_ENDIAN_MODE << 1) \ 868c2ecf20Sopenharmony_ci | PCI_BAR1_ENTRY_VALID) 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/** Octeon Device state. 898c2ecf20Sopenharmony_ci * Each octeon device goes through each of these states 908c2ecf20Sopenharmony_ci * as it is initialized. 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_ci#define OCT_DEV_BEGIN_STATE 0x0 938c2ecf20Sopenharmony_ci#define OCT_DEV_PCI_ENABLE_DONE 0x1 948c2ecf20Sopenharmony_ci#define OCT_DEV_PCI_MAP_DONE 0x2 958c2ecf20Sopenharmony_ci#define OCT_DEV_DISPATCH_INIT_DONE 0x3 968c2ecf20Sopenharmony_ci#define OCT_DEV_INSTR_QUEUE_INIT_DONE 0x4 978c2ecf20Sopenharmony_ci#define OCT_DEV_SC_BUFF_POOL_INIT_DONE 0x5 988c2ecf20Sopenharmony_ci#define OCT_DEV_RESP_LIST_INIT_DONE 0x6 998c2ecf20Sopenharmony_ci#define OCT_DEV_DROQ_INIT_DONE 0x7 1008c2ecf20Sopenharmony_ci#define OCT_DEV_MBOX_SETUP_DONE 0x8 1018c2ecf20Sopenharmony_ci#define OCT_DEV_MSIX_ALLOC_VECTOR_DONE 0x9 1028c2ecf20Sopenharmony_ci#define OCT_DEV_INTR_SET_DONE 0xa 1038c2ecf20Sopenharmony_ci#define OCT_DEV_IO_QUEUES_DONE 0xb 1048c2ecf20Sopenharmony_ci#define OCT_DEV_CONSOLE_INIT_DONE 0xc 1058c2ecf20Sopenharmony_ci#define OCT_DEV_HOST_OK 0xd 1068c2ecf20Sopenharmony_ci#define OCT_DEV_CORE_OK 0xe 1078c2ecf20Sopenharmony_ci#define OCT_DEV_RUNNING 0xf 1088c2ecf20Sopenharmony_ci#define OCT_DEV_IN_RESET 0x10 1098c2ecf20Sopenharmony_ci#define OCT_DEV_STATE_INVALID 0x11 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci#define OCT_DEV_STATES OCT_DEV_STATE_INVALID 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/** Octeon Device interrupts 1148c2ecf20Sopenharmony_ci * These interrupt bits are set in int_status filed of 1158c2ecf20Sopenharmony_ci * octeon_device structure 1168c2ecf20Sopenharmony_ci */ 1178c2ecf20Sopenharmony_ci#define OCT_DEV_INTR_DMA0_FORCE 0x01 1188c2ecf20Sopenharmony_ci#define OCT_DEV_INTR_DMA1_FORCE 0x02 1198c2ecf20Sopenharmony_ci#define OCT_DEV_INTR_PKT_DATA 0x04 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define LIO_RESET_SECS (3) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/*---------------------------DISPATCH LIST-------------------------------*/ 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/** The dispatch list entry. 1268c2ecf20Sopenharmony_ci * The driver keeps a record of functions registered for each 1278c2ecf20Sopenharmony_ci * response header opcode in this structure. Since the opcode is 1288c2ecf20Sopenharmony_ci * hashed to index into the driver's list, more than one opcode 1298c2ecf20Sopenharmony_ci * can hash to the same entry, in which case the list field points 1308c2ecf20Sopenharmony_ci * to a linked list with the other entries. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_cistruct octeon_dispatch { 1338c2ecf20Sopenharmony_ci /** List head for this entry */ 1348c2ecf20Sopenharmony_ci struct list_head list; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci /** The opcode for which the dispatch function & arg should be used */ 1378c2ecf20Sopenharmony_ci u16 opcode; 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci /** The function to be called for a packet received by the driver */ 1408c2ecf20Sopenharmony_ci octeon_dispatch_fn_t dispatch_fn; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci /* The application specified argument to be passed to the above 1438c2ecf20Sopenharmony_ci * function along with the received packet 1448c2ecf20Sopenharmony_ci */ 1458c2ecf20Sopenharmony_ci void *arg; 1468c2ecf20Sopenharmony_ci}; 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/** The dispatch list structure. */ 1498c2ecf20Sopenharmony_cistruct octeon_dispatch_list { 1508c2ecf20Sopenharmony_ci /** access to dispatch list must be atomic */ 1518c2ecf20Sopenharmony_ci spinlock_t lock; 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci /** Count of dispatch functions currently registered */ 1548c2ecf20Sopenharmony_ci u32 count; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci /** The list of dispatch functions */ 1578c2ecf20Sopenharmony_ci struct octeon_dispatch *dlist; 1588c2ecf20Sopenharmony_ci}; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/*----------------------- THE OCTEON DEVICE ---------------------------*/ 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci#define OCT_MEM_REGIONS 3 1638c2ecf20Sopenharmony_ci/** PCI address space mapping information. 1648c2ecf20Sopenharmony_ci * Each of the 3 address spaces given by BAR0, BAR2 and BAR4 of 1658c2ecf20Sopenharmony_ci * Octeon gets mapped to different physical address spaces in 1668c2ecf20Sopenharmony_ci * the kernel. 1678c2ecf20Sopenharmony_ci */ 1688c2ecf20Sopenharmony_cistruct octeon_mmio { 1698c2ecf20Sopenharmony_ci /** PCI address to which the BAR is mapped. */ 1708c2ecf20Sopenharmony_ci u64 start; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci /** Length of this PCI address space. */ 1738c2ecf20Sopenharmony_ci u32 len; 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci /** Length that has been mapped to phys. address space. */ 1768c2ecf20Sopenharmony_ci u32 mapped_len; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci /** The physical address to which the PCI address space is mapped. */ 1798c2ecf20Sopenharmony_ci u8 __iomem *hw_addr; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci /** Flag indicating the mapping was successful. */ 1828c2ecf20Sopenharmony_ci u32 done; 1838c2ecf20Sopenharmony_ci}; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci#define MAX_OCTEON_MAPS 32 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_cistruct octeon_io_enable { 1888c2ecf20Sopenharmony_ci u64 iq; 1898c2ecf20Sopenharmony_ci u64 oq; 1908c2ecf20Sopenharmony_ci u64 iq64B; 1918c2ecf20Sopenharmony_ci}; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistruct octeon_reg_list { 1948c2ecf20Sopenharmony_ci u32 __iomem *pci_win_wr_addr_hi; 1958c2ecf20Sopenharmony_ci u32 __iomem *pci_win_wr_addr_lo; 1968c2ecf20Sopenharmony_ci u64 __iomem *pci_win_wr_addr; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci u32 __iomem *pci_win_rd_addr_hi; 1998c2ecf20Sopenharmony_ci u32 __iomem *pci_win_rd_addr_lo; 2008c2ecf20Sopenharmony_ci u64 __iomem *pci_win_rd_addr; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci u32 __iomem *pci_win_wr_data_hi; 2038c2ecf20Sopenharmony_ci u32 __iomem *pci_win_wr_data_lo; 2048c2ecf20Sopenharmony_ci u64 __iomem *pci_win_wr_data; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci u32 __iomem *pci_win_rd_data_hi; 2078c2ecf20Sopenharmony_ci u32 __iomem *pci_win_rd_data_lo; 2088c2ecf20Sopenharmony_ci u64 __iomem *pci_win_rd_data; 2098c2ecf20Sopenharmony_ci}; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci#define OCTEON_CONSOLE_MAX_READ_BYTES 512 2128c2ecf20Sopenharmony_citypedef int (*octeon_console_print_fn)(struct octeon_device *oct, 2138c2ecf20Sopenharmony_ci u32 num, char *pre, char *suf); 2148c2ecf20Sopenharmony_cistruct octeon_console { 2158c2ecf20Sopenharmony_ci u32 active; 2168c2ecf20Sopenharmony_ci u32 waiting; 2178c2ecf20Sopenharmony_ci u64 addr; 2188c2ecf20Sopenharmony_ci u32 buffer_size; 2198c2ecf20Sopenharmony_ci u64 input_base_addr; 2208c2ecf20Sopenharmony_ci u64 output_base_addr; 2218c2ecf20Sopenharmony_ci octeon_console_print_fn print; 2228c2ecf20Sopenharmony_ci char leftover[OCTEON_CONSOLE_MAX_READ_BYTES]; 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_cistruct octeon_board_info { 2268c2ecf20Sopenharmony_ci char name[OCT_BOARD_NAME]; 2278c2ecf20Sopenharmony_ci char serial_number[OCT_SERIAL_LEN]; 2288c2ecf20Sopenharmony_ci u64 major; 2298c2ecf20Sopenharmony_ci u64 minor; 2308c2ecf20Sopenharmony_ci}; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_cistruct octeon_fn_list { 2338c2ecf20Sopenharmony_ci void (*setup_iq_regs)(struct octeon_device *, u32); 2348c2ecf20Sopenharmony_ci void (*setup_oq_regs)(struct octeon_device *, u32); 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci irqreturn_t (*process_interrupt_regs)(void *); 2378c2ecf20Sopenharmony_ci u64 (*msix_interrupt_handler)(void *); 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci int (*setup_mbox)(struct octeon_device *); 2408c2ecf20Sopenharmony_ci int (*free_mbox)(struct octeon_device *); 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci int (*soft_reset)(struct octeon_device *); 2438c2ecf20Sopenharmony_ci int (*setup_device_regs)(struct octeon_device *); 2448c2ecf20Sopenharmony_ci void (*bar1_idx_setup)(struct octeon_device *, u64, u32, int); 2458c2ecf20Sopenharmony_ci void (*bar1_idx_write)(struct octeon_device *, u32, u32); 2468c2ecf20Sopenharmony_ci u32 (*bar1_idx_read)(struct octeon_device *, u32); 2478c2ecf20Sopenharmony_ci u32 (*update_iq_read_idx)(struct octeon_instr_queue *); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci void (*enable_oq_pkt_time_intr)(struct octeon_device *, u32); 2508c2ecf20Sopenharmony_ci void (*disable_oq_pkt_time_intr)(struct octeon_device *, u32); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci void (*enable_interrupt)(struct octeon_device *, u8); 2538c2ecf20Sopenharmony_ci void (*disable_interrupt)(struct octeon_device *, u8); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci int (*enable_io_queues)(struct octeon_device *); 2568c2ecf20Sopenharmony_ci void (*disable_io_queues)(struct octeon_device *); 2578c2ecf20Sopenharmony_ci}; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* Must be multiple of 8, changing breaks ABI */ 2608c2ecf20Sopenharmony_ci#define CVMX_BOOTMEM_NAME_LEN 128 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci/* Structure for named memory blocks 2638c2ecf20Sopenharmony_ci * Number of descriptors 2648c2ecf20Sopenharmony_ci * available can be changed without affecting compatibility, 2658c2ecf20Sopenharmony_ci * but name length changes require a bump in the bootmem 2668c2ecf20Sopenharmony_ci * descriptor version 2678c2ecf20Sopenharmony_ci * Note: This structure must be naturally 64 bit aligned, as a single 2688c2ecf20Sopenharmony_ci * memory image will be used by both 32 and 64 bit programs. 2698c2ecf20Sopenharmony_ci */ 2708c2ecf20Sopenharmony_cistruct cvmx_bootmem_named_block_desc { 2718c2ecf20Sopenharmony_ci /** Base address of named block */ 2728c2ecf20Sopenharmony_ci u64 base_addr; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci /** Size actually allocated for named block */ 2758c2ecf20Sopenharmony_ci u64 size; 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci /** name of named block */ 2788c2ecf20Sopenharmony_ci char name[CVMX_BOOTMEM_NAME_LEN]; 2798c2ecf20Sopenharmony_ci}; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_cistruct oct_fw_info { 2828c2ecf20Sopenharmony_ci u32 max_nic_ports; /** max nic ports for the device */ 2838c2ecf20Sopenharmony_ci u32 num_gmx_ports; /** num gmx ports */ 2848c2ecf20Sopenharmony_ci u64 app_cap_flags; /** firmware cap flags */ 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci /** The core application is running in this mode. 2878c2ecf20Sopenharmony_ci * See octeon-drv-opcodes.h for values. 2888c2ecf20Sopenharmony_ci */ 2898c2ecf20Sopenharmony_ci u32 app_mode; 2908c2ecf20Sopenharmony_ci char liquidio_firmware_version[32]; 2918c2ecf20Sopenharmony_ci /* Fields extracted from legacy string 'liquidio_firmware_version' */ 2928c2ecf20Sopenharmony_ci struct { 2938c2ecf20Sopenharmony_ci u8 maj; 2948c2ecf20Sopenharmony_ci u8 min; 2958c2ecf20Sopenharmony_ci u8 rev; 2968c2ecf20Sopenharmony_ci } ver; 2978c2ecf20Sopenharmony_ci}; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci#define OCT_FW_VER(maj, min, rev) \ 3008c2ecf20Sopenharmony_ci (((u32)(maj) << 16) | ((u32)(min) << 8) | ((u32)(rev))) 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci/* wrappers around work structs */ 3038c2ecf20Sopenharmony_cistruct cavium_wk { 3048c2ecf20Sopenharmony_ci struct delayed_work work; 3058c2ecf20Sopenharmony_ci void *ctxptr; 3068c2ecf20Sopenharmony_ci u64 ctxul; 3078c2ecf20Sopenharmony_ci}; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistruct cavium_wq { 3108c2ecf20Sopenharmony_ci struct workqueue_struct *wq; 3118c2ecf20Sopenharmony_ci struct cavium_wk wk; 3128c2ecf20Sopenharmony_ci}; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistruct octdev_props { 3158c2ecf20Sopenharmony_ci /* Each interface in the Octeon device has a network 3168c2ecf20Sopenharmony_ci * device pointer (used for OS specific calls). 3178c2ecf20Sopenharmony_ci */ 3188c2ecf20Sopenharmony_ci int rx_on; 3198c2ecf20Sopenharmony_ci int fec; 3208c2ecf20Sopenharmony_ci int fec_boot; 3218c2ecf20Sopenharmony_ci int napi_enabled; 3228c2ecf20Sopenharmony_ci int gmxport; 3238c2ecf20Sopenharmony_ci struct net_device *netdev; 3248c2ecf20Sopenharmony_ci}; 3258c2ecf20Sopenharmony_ci 3268c2ecf20Sopenharmony_ci#define LIO_FLAG_MSIX_ENABLED 0x1 3278c2ecf20Sopenharmony_ci#define MSIX_PO_INT 0x1 3288c2ecf20Sopenharmony_ci#define MSIX_PI_INT 0x2 3298c2ecf20Sopenharmony_ci#define MSIX_MBOX_INT 0x4 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_cistruct octeon_pf_vf_hs_word { 3328c2ecf20Sopenharmony_ci#ifdef __LITTLE_ENDIAN_BITFIELD 3338c2ecf20Sopenharmony_ci /** PKIND value assigned for the DPI interface */ 3348c2ecf20Sopenharmony_ci u64 pkind : 8; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /** OCTEON core clock multiplier */ 3378c2ecf20Sopenharmony_ci u64 core_tics_per_us : 16; 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci /** OCTEON coprocessor clock multiplier */ 3408c2ecf20Sopenharmony_ci u64 coproc_tics_per_us : 16; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci /** app that currently running on OCTEON */ 3438c2ecf20Sopenharmony_ci u64 app_mode : 8; 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci /** RESERVED */ 3468c2ecf20Sopenharmony_ci u64 reserved : 16; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci#else 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci /** RESERVED */ 3518c2ecf20Sopenharmony_ci u64 reserved : 16; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci /** app that currently running on OCTEON */ 3548c2ecf20Sopenharmony_ci u64 app_mode : 8; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci /** OCTEON coprocessor clock multiplier */ 3578c2ecf20Sopenharmony_ci u64 coproc_tics_per_us : 16; 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci /** OCTEON core clock multiplier */ 3608c2ecf20Sopenharmony_ci u64 core_tics_per_us : 16; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci /** PKIND value assigned for the DPI interface */ 3638c2ecf20Sopenharmony_ci u64 pkind : 8; 3648c2ecf20Sopenharmony_ci#endif 3658c2ecf20Sopenharmony_ci}; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_cistruct octeon_sriov_info { 3688c2ecf20Sopenharmony_ci /* Number of rings assigned to VF */ 3698c2ecf20Sopenharmony_ci u32 rings_per_vf; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci /** Max Number of VF devices that can be enabled. This variable can 3728c2ecf20Sopenharmony_ci * specified during load time or it will be derived after allocating 3738c2ecf20Sopenharmony_ci * PF queues. When max_vfs is derived then each VF will get one queue 3748c2ecf20Sopenharmony_ci **/ 3758c2ecf20Sopenharmony_ci u32 max_vfs; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci /** Number of VF devices enabled using sysfs. */ 3788c2ecf20Sopenharmony_ci u32 num_vfs_alloced; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci /* Actual rings left for PF device */ 3818c2ecf20Sopenharmony_ci u32 num_pf_rings; 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci /* SRN of PF usable IO queues */ 3848c2ecf20Sopenharmony_ci u32 pf_srn; 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci /* total pf rings */ 3878c2ecf20Sopenharmony_ci u32 trs; 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci u32 sriov_enabled; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci struct lio_trusted_vf trusted_vf; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci /*lookup table that maps DPI ring number to VF pci_dev struct pointer*/ 3948c2ecf20Sopenharmony_ci struct pci_dev *dpiring_to_vfpcidev_lut[MAX_POSSIBLE_VFS]; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci u64 vf_macaddr[MAX_POSSIBLE_VFS]; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci u16 vf_vlantci[MAX_POSSIBLE_VFS]; 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci int vf_linkstate[MAX_POSSIBLE_VFS]; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci bool vf_spoofchk[MAX_POSSIBLE_VFS]; 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci u64 vf_drv_loaded_mask; 4058c2ecf20Sopenharmony_ci}; 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_cistruct octeon_ioq_vector { 4088c2ecf20Sopenharmony_ci struct octeon_device *oct_dev; 4098c2ecf20Sopenharmony_ci int iq_index; 4108c2ecf20Sopenharmony_ci int droq_index; 4118c2ecf20Sopenharmony_ci int vector; 4128c2ecf20Sopenharmony_ci struct octeon_mbox *mbox; 4138c2ecf20Sopenharmony_ci struct cpumask affinity_mask; 4148c2ecf20Sopenharmony_ci u32 ioq_num; 4158c2ecf20Sopenharmony_ci}; 4168c2ecf20Sopenharmony_ci 4178c2ecf20Sopenharmony_cistruct lio_vf_rep_list { 4188c2ecf20Sopenharmony_ci int num_vfs; 4198c2ecf20Sopenharmony_ci struct net_device *ndev[CN23XX_MAX_VFS_PER_PF]; 4208c2ecf20Sopenharmony_ci}; 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_cistruct lio_devlink_priv { 4238c2ecf20Sopenharmony_ci struct octeon_device *oct; 4248c2ecf20Sopenharmony_ci}; 4258c2ecf20Sopenharmony_ci 4268c2ecf20Sopenharmony_ci/** The Octeon device. 4278c2ecf20Sopenharmony_ci * Each Octeon device has this structure to represent all its 4288c2ecf20Sopenharmony_ci * components. 4298c2ecf20Sopenharmony_ci */ 4308c2ecf20Sopenharmony_cistruct octeon_device { 4318c2ecf20Sopenharmony_ci /** Lock for PCI window configuration accesses */ 4328c2ecf20Sopenharmony_ci spinlock_t pci_win_lock; 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci /** Lock for memory accesses */ 4358c2ecf20Sopenharmony_ci spinlock_t mem_access_lock; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci /** PCI device pointer */ 4388c2ecf20Sopenharmony_ci struct pci_dev *pci_dev; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci /** Chip specific information. */ 4418c2ecf20Sopenharmony_ci void *chip; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci /** Number of interfaces detected in this octeon device. */ 4448c2ecf20Sopenharmony_ci u32 ifcount; 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci struct octdev_props props[MAX_OCTEON_LINKS]; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci /** Octeon Chip type. */ 4498c2ecf20Sopenharmony_ci u16 chip_id; 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci u16 rev_id; 4528c2ecf20Sopenharmony_ci 4538c2ecf20Sopenharmony_ci u32 subsystem_id; 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci u16 pf_num; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci u16 vf_num; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci /** This device's id - set by the driver. */ 4608c2ecf20Sopenharmony_ci u32 octeon_id; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci /** This device's PCIe port used for traffic. */ 4638c2ecf20Sopenharmony_ci u16 pcie_port; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci u16 flags; 4668c2ecf20Sopenharmony_ci#define LIO_FLAG_MSI_ENABLED (u32)(1 << 1) 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci /** The state of this device */ 4698c2ecf20Sopenharmony_ci atomic_t status; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci /** memory mapped io range */ 4728c2ecf20Sopenharmony_ci struct octeon_mmio mmio[OCT_MEM_REGIONS]; 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci struct octeon_reg_list reg_list; 4758c2ecf20Sopenharmony_ci 4768c2ecf20Sopenharmony_ci struct octeon_fn_list fn_list; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci struct octeon_board_info boardinfo; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci u32 num_iqs; 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci /* The pool containing pre allocated buffers used for soft commands */ 4838c2ecf20Sopenharmony_ci struct octeon_sc_buffer_pool sc_buf_pool; 4848c2ecf20Sopenharmony_ci 4858c2ecf20Sopenharmony_ci /** The input instruction queues */ 4868c2ecf20Sopenharmony_ci struct octeon_instr_queue *instr_queue 4878c2ecf20Sopenharmony_ci [MAX_POSSIBLE_OCTEON_INSTR_QUEUES]; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci /** The doubly-linked list of instruction response */ 4908c2ecf20Sopenharmony_ci struct octeon_response_list response_list[MAX_RESPONSE_LISTS]; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci u32 num_oqs; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci /** The DROQ output queues */ 4958c2ecf20Sopenharmony_ci struct octeon_droq *droq[MAX_POSSIBLE_OCTEON_OUTPUT_QUEUES]; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci struct octeon_io_enable io_qmask; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci /** List of dispatch functions */ 5008c2ecf20Sopenharmony_ci struct octeon_dispatch_list dispatch; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci u32 int_status; 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_ci u64 droq_intr; 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci /** Physical location of the cvmx_bootmem_desc_t in octeon memory */ 5078c2ecf20Sopenharmony_ci u64 bootmem_desc_addr; 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci /** Placeholder memory for named blocks. 5108c2ecf20Sopenharmony_ci * Assumes single-threaded access 5118c2ecf20Sopenharmony_ci */ 5128c2ecf20Sopenharmony_ci struct cvmx_bootmem_named_block_desc bootmem_named_block_desc; 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci /** Address of consoles descriptor */ 5158c2ecf20Sopenharmony_ci u64 console_desc_addr; 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci /** Number of consoles available. 0 means they are inaccessible */ 5188c2ecf20Sopenharmony_ci u32 num_consoles; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci /* Console caches */ 5218c2ecf20Sopenharmony_ci struct octeon_console console[MAX_OCTEON_MAPS]; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci /* Console named block info */ 5248c2ecf20Sopenharmony_ci struct { 5258c2ecf20Sopenharmony_ci u64 dram_region_base; 5268c2ecf20Sopenharmony_ci int bar1_index; 5278c2ecf20Sopenharmony_ci } console_nb_info; 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_ci /* Coprocessor clock rate. */ 5308c2ecf20Sopenharmony_ci u64 coproc_clock_rate; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci /** The core application is running in this mode. See liquidio_common.h 5338c2ecf20Sopenharmony_ci * for values. 5348c2ecf20Sopenharmony_ci */ 5358c2ecf20Sopenharmony_ci u32 app_mode; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci struct oct_fw_info fw_info; 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci /** The name given to this device. */ 5408c2ecf20Sopenharmony_ci char device_name[32]; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci /** Application Context */ 5438c2ecf20Sopenharmony_ci void *app_ctx; 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci struct cavium_wq dma_comp_wq; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci /** Lock for dma response list */ 5488c2ecf20Sopenharmony_ci spinlock_t cmd_resp_wqlock; 5498c2ecf20Sopenharmony_ci u32 cmd_resp_state; 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci struct cavium_wq check_db_wq[MAX_POSSIBLE_OCTEON_INSTR_QUEUES]; 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci struct cavium_wk nic_poll_work; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci struct cavium_wk console_poll_work[MAX_OCTEON_MAPS]; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci void *priv; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci int num_msix_irqs; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci void *msix_entries; 5628c2ecf20Sopenharmony_ci 5638c2ecf20Sopenharmony_ci /* when requesting IRQs, the names are stored here */ 5648c2ecf20Sopenharmony_ci void *irq_name_storage; 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci struct octeon_sriov_info sriov_info; 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_ci struct octeon_pf_vf_hs_word pfvf_hsword; 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci int msix_on; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci /** Mail Box details of each octeon queue. */ 5738c2ecf20Sopenharmony_ci struct octeon_mbox *mbox[MAX_POSSIBLE_VFS]; 5748c2ecf20Sopenharmony_ci 5758c2ecf20Sopenharmony_ci /** IOq information of it's corresponding MSI-X interrupt. */ 5768c2ecf20Sopenharmony_ci struct octeon_ioq_vector *ioq_vector; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci int rx_pause; 5798c2ecf20Sopenharmony_ci int tx_pause; 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_ci struct oct_link_stats link_stats; /*stastics from firmware*/ 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci /* private flags to control driver-specific features through ethtool */ 5848c2ecf20Sopenharmony_ci u32 priv_flags; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci void *watchdog_task; 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci u32 rx_coalesce_usecs; 5898c2ecf20Sopenharmony_ci u32 rx_max_coalesced_frames; 5908c2ecf20Sopenharmony_ci u32 tx_max_coalesced_frames; 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci bool cores_crashed; 5938c2ecf20Sopenharmony_ci 5948c2ecf20Sopenharmony_ci struct { 5958c2ecf20Sopenharmony_ci int bus; 5968c2ecf20Sopenharmony_ci int dev; 5978c2ecf20Sopenharmony_ci int func; 5988c2ecf20Sopenharmony_ci } loc; 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci atomic_t *adapter_refcount; /* reference count of adapter */ 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci atomic_t *adapter_fw_state; /* per-adapter, lio_fw_state */ 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci bool ptp_enable; 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci struct lio_vf_rep_list vf_rep_list; 6078c2ecf20Sopenharmony_ci struct devlink *devlink; 6088c2ecf20Sopenharmony_ci enum devlink_eswitch_mode eswitch_mode; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci /* for 25G NIC speed change */ 6118c2ecf20Sopenharmony_ci u8 speed_boot; 6128c2ecf20Sopenharmony_ci u8 speed_setting; 6138c2ecf20Sopenharmony_ci u8 no_speed_setting; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci u32 vfstats_poll; 6168c2ecf20Sopenharmony_ci#define LIO_VFSTATS_POLL 10 6178c2ecf20Sopenharmony_ci}; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci#define OCT_DRV_ONLINE 1 6208c2ecf20Sopenharmony_ci#define OCT_DRV_OFFLINE 2 6218c2ecf20Sopenharmony_ci#define OCTEON_CN6XXX(oct) ({ \ 6228c2ecf20Sopenharmony_ci typeof(oct) _oct = (oct); \ 6238c2ecf20Sopenharmony_ci ((_oct->chip_id == OCTEON_CN66XX) || \ 6248c2ecf20Sopenharmony_ci (_oct->chip_id == OCTEON_CN68XX)); }) 6258c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_PF(oct) ((oct)->chip_id == OCTEON_CN23XX_PF_VID) 6268c2ecf20Sopenharmony_ci#define OCTEON_CN23XX_VF(oct) ((oct)->chip_id == OCTEON_CN23XX_VF_VID) 6278c2ecf20Sopenharmony_ci#define CHIP_CONF(oct, TYPE) \ 6288c2ecf20Sopenharmony_ci (((struct octeon_ ## TYPE *)((oct)->chip))->conf) 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci#define MAX_IO_PENDING_PKT_COUNT 100 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci/*------------------ Function Prototypes ----------------------*/ 6338c2ecf20Sopenharmony_ci 6348c2ecf20Sopenharmony_ci/** Initialize device list memory */ 6358c2ecf20Sopenharmony_civoid octeon_init_device_list(int conf_type); 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci/** Free memory for Input and Output queue structures for a octeon device */ 6388c2ecf20Sopenharmony_civoid octeon_free_device_mem(struct octeon_device *oct); 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci/* Look up a free entry in the octeon_device table and allocate resources 6418c2ecf20Sopenharmony_ci * for the octeon_device structure for an octeon device. Called at init 6428c2ecf20Sopenharmony_ci * time. 6438c2ecf20Sopenharmony_ci */ 6448c2ecf20Sopenharmony_cistruct octeon_device *octeon_allocate_device(u32 pci_id, 6458c2ecf20Sopenharmony_ci u32 priv_size); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci/** Register a device's bus location at initialization time. 6488c2ecf20Sopenharmony_ci * @param octeon_dev - pointer to the octeon device structure. 6498c2ecf20Sopenharmony_ci * @param bus - PCIe bus # 6508c2ecf20Sopenharmony_ci * @param dev - PCIe device # 6518c2ecf20Sopenharmony_ci * @param func - PCIe function # 6528c2ecf20Sopenharmony_ci * @param is_pf - TRUE for PF, FALSE for VF 6538c2ecf20Sopenharmony_ci * @return reference count of device's adapter 6548c2ecf20Sopenharmony_ci */ 6558c2ecf20Sopenharmony_ciint octeon_register_device(struct octeon_device *oct, 6568c2ecf20Sopenharmony_ci int bus, int dev, int func, int is_pf); 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci/** Deregister a device at de-initialization time. 6598c2ecf20Sopenharmony_ci * @param octeon_dev - pointer to the octeon device structure. 6608c2ecf20Sopenharmony_ci * @return reference count of device's adapter 6618c2ecf20Sopenharmony_ci */ 6628c2ecf20Sopenharmony_ciint octeon_deregister_device(struct octeon_device *oct); 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci/** Initialize the driver's dispatch list which is a mix of a hash table 6658c2ecf20Sopenharmony_ci * and a linked list. This is done at driver load time. 6668c2ecf20Sopenharmony_ci * @param octeon_dev - pointer to the octeon device structure. 6678c2ecf20Sopenharmony_ci * @return 0 on success, else -ve error value 6688c2ecf20Sopenharmony_ci */ 6698c2ecf20Sopenharmony_ciint octeon_init_dispatch_list(struct octeon_device *octeon_dev); 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci/** Delete the driver's dispatch list and all registered entries. 6728c2ecf20Sopenharmony_ci * This is done at driver unload time. 6738c2ecf20Sopenharmony_ci * @param octeon_dev - pointer to the octeon device structure. 6748c2ecf20Sopenharmony_ci */ 6758c2ecf20Sopenharmony_civoid octeon_delete_dispatch_list(struct octeon_device *octeon_dev); 6768c2ecf20Sopenharmony_ci 6778c2ecf20Sopenharmony_ci/** Initialize the core device fields with the info returned by the FW. 6788c2ecf20Sopenharmony_ci * @param recv_info - Receive info structure 6798c2ecf20Sopenharmony_ci * @param buf - Receive buffer 6808c2ecf20Sopenharmony_ci */ 6818c2ecf20Sopenharmony_ciint octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf); 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci/** Gets the dispatch function registered to receive packets with a 6848c2ecf20Sopenharmony_ci * given opcode/subcode. 6858c2ecf20Sopenharmony_ci * @param octeon_dev - the octeon device pointer. 6868c2ecf20Sopenharmony_ci * @param opcode - the opcode for which the dispatch function 6878c2ecf20Sopenharmony_ci * is to checked. 6888c2ecf20Sopenharmony_ci * @param subcode - the subcode for which the dispatch function 6898c2ecf20Sopenharmony_ci * is to checked. 6908c2ecf20Sopenharmony_ci * 6918c2ecf20Sopenharmony_ci * @return Success: octeon_dispatch_fn_t (dispatch function pointer) 6928c2ecf20Sopenharmony_ci * @return Failure: NULL 6938c2ecf20Sopenharmony_ci * 6948c2ecf20Sopenharmony_ci * Looks up the dispatch list to get the dispatch function for a 6958c2ecf20Sopenharmony_ci * given opcode. 6968c2ecf20Sopenharmony_ci */ 6978c2ecf20Sopenharmony_ciocteon_dispatch_fn_t 6988c2ecf20Sopenharmony_ciocteon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode, 6998c2ecf20Sopenharmony_ci u16 subcode); 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci/** Get the octeon device pointer. 7028c2ecf20Sopenharmony_ci * @param octeon_id - The id for which the octeon device pointer is required. 7038c2ecf20Sopenharmony_ci * @return Success: Octeon device pointer. 7048c2ecf20Sopenharmony_ci * @return Failure: NULL. 7058c2ecf20Sopenharmony_ci */ 7068c2ecf20Sopenharmony_cistruct octeon_device *lio_get_device(u32 octeon_id); 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_ci/** Get the octeon id assigned to the octeon device passed as argument. 7098c2ecf20Sopenharmony_ci * This function is exported to other modules. 7108c2ecf20Sopenharmony_ci * @param dev - octeon device pointer passed as a void *. 7118c2ecf20Sopenharmony_ci * @return octeon device id 7128c2ecf20Sopenharmony_ci */ 7138c2ecf20Sopenharmony_ciint lio_get_device_id(void *dev); 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci/** Read windowed register. 7168c2ecf20Sopenharmony_ci * @param oct - pointer to the Octeon device. 7178c2ecf20Sopenharmony_ci * @param addr - Address of the register to read. 7188c2ecf20Sopenharmony_ci * 7198c2ecf20Sopenharmony_ci * This routine is called to read from the indirectly accessed 7208c2ecf20Sopenharmony_ci * Octeon registers that are visible through a PCI BAR0 mapped window 7218c2ecf20Sopenharmony_ci * register. 7228c2ecf20Sopenharmony_ci * @return - 64 bit value read from the register. 7238c2ecf20Sopenharmony_ci */ 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ciu64 lio_pci_readq(struct octeon_device *oct, u64 addr); 7268c2ecf20Sopenharmony_ci 7278c2ecf20Sopenharmony_ci/** Write windowed register. 7288c2ecf20Sopenharmony_ci * @param oct - pointer to the Octeon device. 7298c2ecf20Sopenharmony_ci * @param val - Value to write 7308c2ecf20Sopenharmony_ci * @param addr - Address of the register to write 7318c2ecf20Sopenharmony_ci * 7328c2ecf20Sopenharmony_ci * This routine is called to write to the indirectly accessed 7338c2ecf20Sopenharmony_ci * Octeon registers that are visible through a PCI BAR0 mapped window 7348c2ecf20Sopenharmony_ci * register. 7358c2ecf20Sopenharmony_ci * @return Nothing. 7368c2ecf20Sopenharmony_ci */ 7378c2ecf20Sopenharmony_civoid lio_pci_writeq(struct octeon_device *oct, u64 val, u64 addr); 7388c2ecf20Sopenharmony_ci 7398c2ecf20Sopenharmony_ci/* Routines for reading and writing CSRs */ 7408c2ecf20Sopenharmony_ci#define octeon_write_csr(oct_dev, reg_off, value) \ 7418c2ecf20Sopenharmony_ci writel(value, (oct_dev)->mmio[0].hw_addr + (reg_off)) 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci#define octeon_write_csr64(oct_dev, reg_off, val64) \ 7448c2ecf20Sopenharmony_ci writeq(val64, (oct_dev)->mmio[0].hw_addr + (reg_off)) 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci#define octeon_read_csr(oct_dev, reg_off) \ 7478c2ecf20Sopenharmony_ci readl((oct_dev)->mmio[0].hw_addr + (reg_off)) 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci#define octeon_read_csr64(oct_dev, reg_off) \ 7508c2ecf20Sopenharmony_ci readq((oct_dev)->mmio[0].hw_addr + (reg_off)) 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci/** 7538c2ecf20Sopenharmony_ci * Checks if memory access is okay 7548c2ecf20Sopenharmony_ci * 7558c2ecf20Sopenharmony_ci * @param oct which octeon to send to 7568c2ecf20Sopenharmony_ci * @return Zero on success, negative on failure. 7578c2ecf20Sopenharmony_ci */ 7588c2ecf20Sopenharmony_ciint octeon_mem_access_ok(struct octeon_device *oct); 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci/** 7618c2ecf20Sopenharmony_ci * Waits for DDR initialization. 7628c2ecf20Sopenharmony_ci * 7638c2ecf20Sopenharmony_ci * @param oct which octeon to send to 7648c2ecf20Sopenharmony_ci * @param timeout_in_ms pointer to how long to wait until DDR is initialized 7658c2ecf20Sopenharmony_ci * in ms. 7668c2ecf20Sopenharmony_ci * If contents are 0, it waits until contents are non-zero 7678c2ecf20Sopenharmony_ci * before starting to check. 7688c2ecf20Sopenharmony_ci * @return Zero on success, negative on failure. 7698c2ecf20Sopenharmony_ci */ 7708c2ecf20Sopenharmony_ciint octeon_wait_for_ddr_init(struct octeon_device *oct, 7718c2ecf20Sopenharmony_ci u32 *timeout_in_ms); 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci/** 7748c2ecf20Sopenharmony_ci * Wait for u-boot to boot and be waiting for a command. 7758c2ecf20Sopenharmony_ci * 7768c2ecf20Sopenharmony_ci * @param wait_time_hundredths 7778c2ecf20Sopenharmony_ci * Maximum time to wait 7788c2ecf20Sopenharmony_ci * 7798c2ecf20Sopenharmony_ci * @return Zero on success, negative on failure. 7808c2ecf20Sopenharmony_ci */ 7818c2ecf20Sopenharmony_ciint octeon_wait_for_bootloader(struct octeon_device *oct, 7828c2ecf20Sopenharmony_ci u32 wait_time_hundredths); 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci/** 7858c2ecf20Sopenharmony_ci * Initialize console access 7868c2ecf20Sopenharmony_ci * 7878c2ecf20Sopenharmony_ci * @param oct which octeon initialize 7888c2ecf20Sopenharmony_ci * @return Zero on success, negative on failure. 7898c2ecf20Sopenharmony_ci */ 7908c2ecf20Sopenharmony_ciint octeon_init_consoles(struct octeon_device *oct); 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci/** 7938c2ecf20Sopenharmony_ci * Adds access to a console to the device. 7948c2ecf20Sopenharmony_ci * 7958c2ecf20Sopenharmony_ci * @param oct: which octeon to add to 7968c2ecf20Sopenharmony_ci * @param console_num: which console 7978c2ecf20Sopenharmony_ci * @param dbg_enb: ptr to debug enablement string, one of: 7988c2ecf20Sopenharmony_ci * * NULL for no debug output (i.e. disabled) 7998c2ecf20Sopenharmony_ci * * empty string enables debug output (via default method) 8008c2ecf20Sopenharmony_ci * * specific string to enable debug console output 8018c2ecf20Sopenharmony_ci * 8028c2ecf20Sopenharmony_ci * @return Zero on success, negative on failure. 8038c2ecf20Sopenharmony_ci */ 8048c2ecf20Sopenharmony_ciint octeon_add_console(struct octeon_device *oct, u32 console_num, 8058c2ecf20Sopenharmony_ci char *dbg_enb); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci/** write or read from a console */ 8088c2ecf20Sopenharmony_ciint octeon_console_write(struct octeon_device *oct, u32 console_num, 8098c2ecf20Sopenharmony_ci char *buffer, u32 write_request_size, u32 flags); 8108c2ecf20Sopenharmony_ciint octeon_console_write_avail(struct octeon_device *oct, u32 console_num); 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ciint octeon_console_read_avail(struct octeon_device *oct, u32 console_num); 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci/** Removes all attached consoles. */ 8158c2ecf20Sopenharmony_civoid octeon_remove_consoles(struct octeon_device *oct); 8168c2ecf20Sopenharmony_ci 8178c2ecf20Sopenharmony_ci/** 8188c2ecf20Sopenharmony_ci * Send a string to u-boot on console 0 as a command. 8198c2ecf20Sopenharmony_ci * 8208c2ecf20Sopenharmony_ci * @param oct which octeon to send to 8218c2ecf20Sopenharmony_ci * @param cmd_str String to send 8228c2ecf20Sopenharmony_ci * @param wait_hundredths Time to wait for u-boot to accept the command. 8238c2ecf20Sopenharmony_ci * 8248c2ecf20Sopenharmony_ci * @return Zero on success, negative on failure. 8258c2ecf20Sopenharmony_ci */ 8268c2ecf20Sopenharmony_ciint octeon_console_send_cmd(struct octeon_device *oct, char *cmd_str, 8278c2ecf20Sopenharmony_ci u32 wait_hundredths); 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci/** Parses, validates, and downloads firmware, then boots associated cores. 8308c2ecf20Sopenharmony_ci * @param oct which octeon to download firmware to 8318c2ecf20Sopenharmony_ci * @param data - The complete firmware file image 8328c2ecf20Sopenharmony_ci * @param size - The size of the data 8338c2ecf20Sopenharmony_ci * 8348c2ecf20Sopenharmony_ci * @return 0 if success. 8358c2ecf20Sopenharmony_ci * -EINVAL if file is incompatible or badly formatted. 8368c2ecf20Sopenharmony_ci * -ENODEV if no handler was found for the application type or an 8378c2ecf20Sopenharmony_ci * invalid octeon id was passed. 8388c2ecf20Sopenharmony_ci */ 8398c2ecf20Sopenharmony_ciint octeon_download_firmware(struct octeon_device *oct, const u8 *data, 8408c2ecf20Sopenharmony_ci size_t size); 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_cichar *lio_get_state_string(atomic_t *state_ptr); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci/** Sets up instruction queues for the device 8458c2ecf20Sopenharmony_ci * @param oct which octeon to setup 8468c2ecf20Sopenharmony_ci * 8478c2ecf20Sopenharmony_ci * @return 0 if success. 1 if fails 8488c2ecf20Sopenharmony_ci */ 8498c2ecf20Sopenharmony_ciint octeon_setup_instr_queues(struct octeon_device *oct); 8508c2ecf20Sopenharmony_ci 8518c2ecf20Sopenharmony_ci/** Sets up output queues for the device 8528c2ecf20Sopenharmony_ci * @param oct which octeon to setup 8538c2ecf20Sopenharmony_ci * 8548c2ecf20Sopenharmony_ci * @return 0 if success. 1 if fails 8558c2ecf20Sopenharmony_ci */ 8568c2ecf20Sopenharmony_ciint octeon_setup_output_queues(struct octeon_device *oct); 8578c2ecf20Sopenharmony_ci 8588c2ecf20Sopenharmony_ciint octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no); 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_ciint octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no); 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci/** Turns off the input and output queues for the device 8638c2ecf20Sopenharmony_ci * @param oct which octeon to disable 8648c2ecf20Sopenharmony_ci */ 8658c2ecf20Sopenharmony_ciint octeon_set_io_queues_off(struct octeon_device *oct); 8668c2ecf20Sopenharmony_ci 8678c2ecf20Sopenharmony_ci/** Turns on or off the given output queue for the device 8688c2ecf20Sopenharmony_ci * @param oct which octeon to change 8698c2ecf20Sopenharmony_ci * @param q_no which queue 8708c2ecf20Sopenharmony_ci * @param enable 1 to enable, 0 to disable 8718c2ecf20Sopenharmony_ci */ 8728c2ecf20Sopenharmony_civoid octeon_set_droq_pkt_op(struct octeon_device *oct, u32 q_no, u32 enable); 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci/** Retrieve the config for the device 8758c2ecf20Sopenharmony_ci * @param oct which octeon 8768c2ecf20Sopenharmony_ci * @param card_type type of card 8778c2ecf20Sopenharmony_ci * 8788c2ecf20Sopenharmony_ci * @returns pointer to configuration 8798c2ecf20Sopenharmony_ci */ 8808c2ecf20Sopenharmony_civoid *oct_get_config_info(struct octeon_device *oct, u16 card_type); 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_ci/** Gets the octeon device configuration 8838c2ecf20Sopenharmony_ci * @return - pointer to the octeon configuration struture 8848c2ecf20Sopenharmony_ci */ 8858c2ecf20Sopenharmony_cistruct octeon_config *octeon_get_conf(struct octeon_device *oct); 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_civoid octeon_free_ioq_vector(struct octeon_device *oct); 8888c2ecf20Sopenharmony_ciint octeon_allocate_ioq_vector(struct octeon_device *oct, u32 num_ioqs); 8898c2ecf20Sopenharmony_civoid lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ci/* LiquidIO driver pivate flags */ 8928c2ecf20Sopenharmony_cienum { 8938c2ecf20Sopenharmony_ci OCT_PRIV_FLAG_TX_BYTES = 0, /* Tx interrupts by pending byte count */ 8948c2ecf20Sopenharmony_ci}; 8958c2ecf20Sopenharmony_ci 8968c2ecf20Sopenharmony_ci#define OCT_PRIV_FLAG_DEFAULT 0x0 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_cistatic inline u32 lio_get_priv_flag(struct octeon_device *octdev, u32 flag) 8998c2ecf20Sopenharmony_ci{ 9008c2ecf20Sopenharmony_ci return !!(octdev->priv_flags & (0x1 << flag)); 9018c2ecf20Sopenharmony_ci} 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_cistatic inline void lio_set_priv_flag(struct octeon_device *octdev, 9048c2ecf20Sopenharmony_ci u32 flag, u32 val) 9058c2ecf20Sopenharmony_ci{ 9068c2ecf20Sopenharmony_ci if (val) 9078c2ecf20Sopenharmony_ci octdev->priv_flags |= (0x1 << flag); 9088c2ecf20Sopenharmony_ci else 9098c2ecf20Sopenharmony_ci octdev->priv_flags &= ~(0x1 << flag); 9108c2ecf20Sopenharmony_ci} 9118c2ecf20Sopenharmony_ci#endif 912