Back to home page

OSCL-LXR

 
 

    


0001 /**********************************************************************
0002  * Author: Cavium, Inc.
0003  *
0004  * Contact: support@cavium.com
0005  *          Please include "LiquidIO" in the subject.
0006  *
0007  * Copyright (c) 2003-2016 Cavium, Inc.
0008  *
0009  * This file is free software; you can redistribute it and/or modify
0010  * it under the terms of the GNU General Public License, Version 2, as
0011  * published by the Free Software Foundation.
0012  *
0013  * This file is distributed in the hope that it will be useful, but
0014  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
0015  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
0016  * NONINFRINGEMENT.  See the GNU General Public License for more details.
0017  ***********************************************************************/
0018 /*! \file octeon_device.h
0019  *  \brief Host Driver: This file defines the octeon device structure.
0020  */
0021 
0022 #ifndef _OCTEON_DEVICE_H_
0023 #define  _OCTEON_DEVICE_H_
0024 
0025 #include <linux/interrupt.h>
0026 #include <net/devlink.h>
0027 
0028 /** PCI VendorId Device Id */
0029 #define  OCTEON_CN68XX_PCIID          0x91177d
0030 #define  OCTEON_CN66XX_PCIID          0x92177d
0031 #define  OCTEON_CN23XX_PCIID_PF       0x9702177d
0032 /** Driver identifies chips by these Ids, created by clubbing together
0033  *  DeviceId+RevisionId; Where Revision Id is not used to distinguish
0034  *  between chips, a value of 0 is used for revision id.
0035  */
0036 #define  OCTEON_CN68XX                0x0091
0037 #define  OCTEON_CN66XX                0x0092
0038 #define  OCTEON_CN23XX_PF_VID         0x9702
0039 #define  OCTEON_CN23XX_VF_VID         0x9712
0040 
0041 /**RevisionId for the chips */
0042 #define  OCTEON_CN23XX_REV_1_0        0x00
0043 #define  OCTEON_CN23XX_REV_1_1        0x01
0044 #define  OCTEON_CN23XX_REV_2_0        0x80
0045 
0046 /**SubsystemId for the chips */
0047 #define  OCTEON_CN2350_10GB_SUBSYS_ID_1 0X3177d
0048 #define  OCTEON_CN2350_10GB_SUBSYS_ID_2 0X4177d
0049 #define  OCTEON_CN2360_10GB_SUBSYS_ID   0X5177d
0050 #define  OCTEON_CN2350_25GB_SUBSYS_ID   0X7177d
0051 #define  OCTEON_CN2360_25GB_SUBSYS_ID   0X6177d
0052 
0053 /** Endian-swap modes supported by Octeon. */
0054 enum octeon_pci_swap_mode {
0055     OCTEON_PCI_PASSTHROUGH = 0,
0056     OCTEON_PCI_64BIT_SWAP = 1,
0057     OCTEON_PCI_32BIT_BYTE_SWAP = 2,
0058     OCTEON_PCI_32BIT_LW_SWAP = 3
0059 };
0060 
0061 enum lio_fw_state {
0062     FW_IS_PRELOADED = 0,
0063     FW_NEEDS_TO_BE_LOADED = 1,
0064     FW_IS_BEING_LOADED = 2,
0065     FW_HAS_BEEN_LOADED = 3,
0066 };
0067 
0068 enum {
0069     OCTEON_CONFIG_TYPE_DEFAULT = 0,
0070     NUM_OCTEON_CONFS,
0071 };
0072 
0073 #define  OCTEON_INPUT_INTR    (1)
0074 #define  OCTEON_OUTPUT_INTR   (2)
0075 #define  OCTEON_MBOX_INTR     (4)
0076 #define  OCTEON_ALL_INTR      0xff
0077 
0078 /*---------------   PCI BAR1 index registers -------------*/
0079 
0080 /* BAR1 Mask */
0081 #define    PCI_BAR1_ENABLE_CA            1
0082 #define    PCI_BAR1_ENDIAN_MODE          OCTEON_PCI_64BIT_SWAP
0083 #define    PCI_BAR1_ENTRY_VALID          1
0084 #define    PCI_BAR1_MASK                 ((PCI_BAR1_ENABLE_CA << 3)   \
0085                         | (PCI_BAR1_ENDIAN_MODE << 1) \
0086                         | PCI_BAR1_ENTRY_VALID)
0087 
0088 /** Octeon Device state.
0089  *  Each octeon device goes through each of these states
0090  *  as it is initialized.
0091  */
0092 #define    OCT_DEV_BEGIN_STATE            0x0
0093 #define    OCT_DEV_PCI_ENABLE_DONE        0x1
0094 #define    OCT_DEV_PCI_MAP_DONE           0x2
0095 #define    OCT_DEV_DISPATCH_INIT_DONE     0x3
0096 #define    OCT_DEV_INSTR_QUEUE_INIT_DONE  0x4
0097 #define    OCT_DEV_SC_BUFF_POOL_INIT_DONE 0x5
0098 #define    OCT_DEV_RESP_LIST_INIT_DONE    0x6
0099 #define    OCT_DEV_DROQ_INIT_DONE         0x7
0100 #define    OCT_DEV_MBOX_SETUP_DONE        0x8
0101 #define    OCT_DEV_MSIX_ALLOC_VECTOR_DONE 0x9
0102 #define    OCT_DEV_INTR_SET_DONE          0xa
0103 #define    OCT_DEV_IO_QUEUES_DONE         0xb
0104 #define    OCT_DEV_CONSOLE_INIT_DONE      0xc
0105 #define    OCT_DEV_HOST_OK                0xd
0106 #define    OCT_DEV_CORE_OK                0xe
0107 #define    OCT_DEV_RUNNING                0xf
0108 #define    OCT_DEV_IN_RESET               0x10
0109 #define    OCT_DEV_STATE_INVALID          0x11
0110 
0111 #define    OCT_DEV_STATES                 OCT_DEV_STATE_INVALID
0112 
0113 /** Octeon Device interrupts
0114  * These interrupt bits are set in int_status filed of
0115  * octeon_device structure
0116  */
0117 #define    OCT_DEV_INTR_DMA0_FORCE    0x01
0118 #define    OCT_DEV_INTR_DMA1_FORCE    0x02
0119 #define    OCT_DEV_INTR_PKT_DATA      0x04
0120 
0121 #define LIO_RESET_SECS (3)
0122 
0123 /*---------------------------DISPATCH LIST-------------------------------*/
0124 
0125 /** The dispatch list entry.
0126  *  The driver keeps a record of functions registered for each
0127  *  response header opcode in this structure. Since the opcode is
0128  *  hashed to index into the driver's list, more than one opcode
0129  *  can hash to the same entry, in which case the list field points
0130  *  to a linked list with the other entries.
0131  */
0132 struct octeon_dispatch {
0133     /** List head for this entry */
0134     struct list_head list;
0135 
0136     /** The opcode for which the dispatch function & arg should be used */
0137     u16 opcode;
0138 
0139     /** The function to be called for a packet received by the driver */
0140     octeon_dispatch_fn_t dispatch_fn;
0141 
0142     /* The application specified argument to be passed to the above
0143      * function along with the received packet
0144      */
0145     void *arg;
0146 };
0147 
0148 /** The dispatch list structure. */
0149 struct octeon_dispatch_list {
0150     /** access to dispatch list must be atomic */
0151     spinlock_t lock;
0152 
0153     /** Count of dispatch functions currently registered */
0154     u32 count;
0155 
0156     /** The list of dispatch functions */
0157     struct octeon_dispatch *dlist;
0158 };
0159 
0160 /*-----------------------  THE OCTEON DEVICE  ---------------------------*/
0161 
0162 #define OCT_MEM_REGIONS     3
0163 /** PCI address space mapping information.
0164  *  Each of the 3 address spaces given by BAR0, BAR2 and BAR4 of
0165  *  Octeon gets mapped to different physical address spaces in
0166  *  the kernel.
0167  */
0168 struct octeon_mmio {
0169     /** PCI address to which the BAR is mapped. */
0170     u64 start;
0171 
0172     /** Length of this PCI address space. */
0173     u32 len;
0174 
0175     /** Length that has been mapped to phys. address space. */
0176     u32 mapped_len;
0177 
0178     /** The physical address to which the PCI address space is mapped. */
0179     u8 __iomem *hw_addr;
0180 
0181     /** Flag indicating the mapping was successful. */
0182     u32 done;
0183 };
0184 
0185 #define   MAX_OCTEON_MAPS    32
0186 
0187 struct octeon_io_enable {
0188     u64 iq;
0189     u64 oq;
0190     u64 iq64B;
0191 };
0192 
0193 struct octeon_reg_list {
0194     u32 __iomem *pci_win_wr_addr_hi;
0195     u32 __iomem *pci_win_wr_addr_lo;
0196     u64 __iomem *pci_win_wr_addr;
0197 
0198     u32 __iomem *pci_win_rd_addr_hi;
0199     u32 __iomem *pci_win_rd_addr_lo;
0200     u64 __iomem *pci_win_rd_addr;
0201 
0202     u32 __iomem *pci_win_wr_data_hi;
0203     u32 __iomem *pci_win_wr_data_lo;
0204     u64 __iomem *pci_win_wr_data;
0205 
0206     u32 __iomem *pci_win_rd_data_hi;
0207     u32 __iomem *pci_win_rd_data_lo;
0208     u64 __iomem *pci_win_rd_data;
0209 };
0210 
0211 #define OCTEON_CONSOLE_MAX_READ_BYTES 512
0212 typedef int (*octeon_console_print_fn)(struct octeon_device *oct,
0213                        u32 num, char *pre, char *suf);
0214 struct octeon_console {
0215     u32 active;
0216     u32 waiting;
0217     u64 addr;
0218     u32 buffer_size;
0219     u64 input_base_addr;
0220     u64 output_base_addr;
0221     octeon_console_print_fn print;
0222     char leftover[OCTEON_CONSOLE_MAX_READ_BYTES];
0223 };
0224 
0225 struct octeon_board_info {
0226     char name[OCT_BOARD_NAME];
0227     char serial_number[OCT_SERIAL_LEN];
0228     u64 major;
0229     u64 minor;
0230 };
0231 
0232 struct octeon_fn_list {
0233     void (*setup_iq_regs)(struct octeon_device *, u32);
0234     void (*setup_oq_regs)(struct octeon_device *, u32);
0235 
0236     irqreturn_t (*process_interrupt_regs)(void *);
0237     u64 (*msix_interrupt_handler)(void *);
0238 
0239     int (*setup_mbox)(struct octeon_device *);
0240     int (*free_mbox)(struct octeon_device *);
0241 
0242     int (*soft_reset)(struct octeon_device *);
0243     int (*setup_device_regs)(struct octeon_device *);
0244     void (*bar1_idx_setup)(struct octeon_device *, u64, u32, int);
0245     void (*bar1_idx_write)(struct octeon_device *, u32, u32);
0246     u32 (*bar1_idx_read)(struct octeon_device *, u32);
0247     u32 (*update_iq_read_idx)(struct octeon_instr_queue *);
0248 
0249     void (*enable_oq_pkt_time_intr)(struct octeon_device *, u32);
0250     void (*disable_oq_pkt_time_intr)(struct octeon_device *, u32);
0251 
0252     void (*enable_interrupt)(struct octeon_device *, u8);
0253     void (*disable_interrupt)(struct octeon_device *, u8);
0254 
0255     int (*enable_io_queues)(struct octeon_device *);
0256     void (*disable_io_queues)(struct octeon_device *);
0257 };
0258 
0259 /* Must be multiple of 8, changing breaks ABI */
0260 #define CVMX_BOOTMEM_NAME_LEN 128
0261 
0262 /* Structure for named memory blocks
0263  * Number of descriptors
0264  * available can be changed without affecting compatibility,
0265  * but name length changes require a bump in the bootmem
0266  * descriptor version
0267  * Note: This structure must be naturally 64 bit aligned, as a single
0268  * memory image will be used by both 32 and 64 bit programs.
0269  */
0270 struct cvmx_bootmem_named_block_desc {
0271     /** Base address of named block */
0272     u64 base_addr;
0273 
0274     /** Size actually allocated for named block */
0275     u64 size;
0276 
0277     /** name of named block */
0278     char name[CVMX_BOOTMEM_NAME_LEN];
0279 };
0280 
0281 struct oct_fw_info {
0282     u32 max_nic_ports;      /** max nic ports for the device */
0283     u32 num_gmx_ports;      /** num gmx ports */
0284     u64 app_cap_flags;      /** firmware cap flags */
0285 
0286     /** The core application is running in this mode.
0287      * See octeon-drv-opcodes.h for values.
0288      */
0289     u32 app_mode;
0290     char   liquidio_firmware_version[32];
0291     /* Fields extracted from legacy string 'liquidio_firmware_version' */
0292     struct {
0293         u8  maj;
0294         u8  min;
0295         u8  rev;
0296     } ver;
0297 };
0298 
0299 #define OCT_FW_VER(maj, min, rev) \
0300     (((u32)(maj) << 16) | ((u32)(min) << 8) | ((u32)(rev)))
0301 
0302 /* wrappers around work structs */
0303 struct cavium_wk {
0304     struct delayed_work work;
0305     void *ctxptr;
0306     u64 ctxul;
0307 };
0308 
0309 struct cavium_wq {
0310     struct workqueue_struct *wq;
0311     struct cavium_wk wk;
0312 };
0313 
0314 struct octdev_props {
0315     /* Each interface in the Octeon device has a network
0316      * device pointer (used for OS specific calls).
0317      */
0318     int    rx_on;
0319     int    fec;
0320     int    fec_boot;
0321     int    napi_enabled;
0322     int    gmxport;
0323     struct net_device *netdev;
0324 };
0325 
0326 #define LIO_FLAG_MSIX_ENABLED   0x1
0327 #define MSIX_PO_INT     0x1
0328 #define MSIX_PI_INT     0x2
0329 #define MSIX_MBOX_INT       0x4
0330 
0331 struct octeon_pf_vf_hs_word {
0332 #ifdef __LITTLE_ENDIAN_BITFIELD
0333     /** PKIND value assigned for the DPI interface */
0334     u64        pkind : 8;
0335 
0336     /** OCTEON core clock multiplier   */
0337     u64        core_tics_per_us : 16;
0338 
0339     /** OCTEON coprocessor clock multiplier  */
0340     u64        coproc_tics_per_us : 16;
0341 
0342     /** app that currently running on OCTEON  */
0343     u64        app_mode : 8;
0344 
0345     /** RESERVED */
0346     u64 reserved : 16;
0347 
0348 #else
0349 
0350     /** RESERVED */
0351     u64 reserved : 16;
0352 
0353     /** app that currently running on OCTEON  */
0354     u64        app_mode : 8;
0355 
0356     /** OCTEON coprocessor clock multiplier  */
0357     u64        coproc_tics_per_us : 16;
0358 
0359     /** OCTEON core clock multiplier   */
0360     u64        core_tics_per_us : 16;
0361 
0362     /** PKIND value assigned for the DPI interface */
0363     u64        pkind : 8;
0364 #endif
0365 };
0366 
0367 struct octeon_sriov_info {
0368     /* Number of rings assigned to VF */
0369     u32 rings_per_vf;
0370 
0371     /** Max Number of VF devices that can be enabled. This variable can
0372      *  specified during load time or it will be derived after allocating
0373      *  PF queues. When max_vfs is derived then each VF will get one queue
0374      **/
0375     u32 max_vfs;
0376 
0377     /** Number of VF devices enabled using sysfs. */
0378     u32 num_vfs_alloced;
0379 
0380     /* Actual rings left for PF device */
0381     u32 num_pf_rings;
0382 
0383     /* SRN of PF usable IO queues */
0384     u32 pf_srn;
0385 
0386     /* total pf rings */
0387     u32 trs;
0388 
0389     u32 sriov_enabled;
0390 
0391     struct lio_trusted_vf   trusted_vf;
0392 
0393     /*lookup table that maps DPI ring number to VF pci_dev struct pointer*/
0394     struct pci_dev *dpiring_to_vfpcidev_lut[MAX_POSSIBLE_VFS];
0395 
0396     u64 vf_macaddr[MAX_POSSIBLE_VFS];
0397 
0398     u16 vf_vlantci[MAX_POSSIBLE_VFS];
0399 
0400     int vf_linkstate[MAX_POSSIBLE_VFS];
0401 
0402     bool    vf_spoofchk[MAX_POSSIBLE_VFS];
0403 
0404     u64 vf_drv_loaded_mask;
0405 };
0406 
0407 struct octeon_ioq_vector {
0408     struct octeon_device   *oct_dev;
0409     int             iq_index;
0410     int             droq_index;
0411     int         vector;
0412     struct octeon_mbox     *mbox;
0413     struct cpumask      affinity_mask;
0414     u32         ioq_num;
0415 };
0416 
0417 struct lio_vf_rep_list {
0418     int num_vfs;
0419     struct net_device *ndev[CN23XX_MAX_VFS_PER_PF];
0420 };
0421 
0422 struct lio_devlink_priv {
0423     struct octeon_device *oct;
0424 };
0425 
0426 /** The Octeon device.
0427  *  Each Octeon device has this structure to represent all its
0428  *  components.
0429  */
0430 struct octeon_device {
0431     /** Lock for PCI window configuration accesses */
0432     spinlock_t pci_win_lock;
0433 
0434     /** Lock for memory accesses */
0435     spinlock_t mem_access_lock;
0436 
0437     /** PCI device pointer */
0438     struct pci_dev *pci_dev;
0439 
0440     /** Chip specific information. */
0441     void *chip;
0442 
0443     /** Number of interfaces detected in this octeon device. */
0444     u32 ifcount;
0445 
0446     struct octdev_props props[MAX_OCTEON_LINKS];
0447 
0448     /** Octeon Chip type. */
0449     u16 chip_id;
0450 
0451     u16 rev_id;
0452 
0453     u32 subsystem_id;
0454 
0455     u16 pf_num;
0456 
0457     u16 vf_num;
0458 
0459     /** This device's id - set by the driver. */
0460     u32 octeon_id;
0461 
0462     /** This device's PCIe port used for traffic. */
0463     u16 pcie_port;
0464 
0465     u16 flags;
0466 #define LIO_FLAG_MSI_ENABLED                  (u32)(1 << 1)
0467 
0468     /** The state of this device */
0469     atomic_t status;
0470 
0471     /** memory mapped io range */
0472     struct octeon_mmio mmio[OCT_MEM_REGIONS];
0473 
0474     struct octeon_reg_list reg_list;
0475 
0476     struct octeon_fn_list fn_list;
0477 
0478     struct octeon_board_info boardinfo;
0479 
0480     u32 num_iqs;
0481 
0482     /* The pool containing pre allocated buffers used for soft commands */
0483     struct octeon_sc_buffer_pool    sc_buf_pool;
0484 
0485     /** The input instruction queues */
0486     struct octeon_instr_queue *instr_queue
0487         [MAX_POSSIBLE_OCTEON_INSTR_QUEUES];
0488 
0489     /** The doubly-linked list of instruction response */
0490     struct octeon_response_list response_list[MAX_RESPONSE_LISTS];
0491 
0492     u32 num_oqs;
0493 
0494     /** The DROQ output queues  */
0495     struct octeon_droq *droq[MAX_POSSIBLE_OCTEON_OUTPUT_QUEUES];
0496 
0497     struct octeon_io_enable io_qmask;
0498 
0499     /** List of dispatch functions */
0500     struct octeon_dispatch_list dispatch;
0501 
0502     u32 int_status;
0503 
0504     u64 droq_intr;
0505 
0506     /** Physical location of the cvmx_bootmem_desc_t in octeon memory */
0507     u64 bootmem_desc_addr;
0508 
0509     /** Placeholder memory for named blocks.
0510      * Assumes single-threaded access
0511      */
0512     struct cvmx_bootmem_named_block_desc bootmem_named_block_desc;
0513 
0514     /** Address of consoles descriptor */
0515     u64 console_desc_addr;
0516 
0517     /** Number of consoles available. 0 means they are inaccessible */
0518     u32 num_consoles;
0519 
0520     /* Console caches */
0521     struct octeon_console console[MAX_OCTEON_MAPS];
0522 
0523     /* Console named block info */
0524     struct {
0525         u64 dram_region_base;
0526         int bar1_index;
0527     } console_nb_info;
0528 
0529     /* Coprocessor clock rate. */
0530     u64 coproc_clock_rate;
0531 
0532     /** The core application is running in this mode. See liquidio_common.h
0533      * for values.
0534      */
0535     u32 app_mode;
0536 
0537     struct oct_fw_info fw_info;
0538 
0539     /** The name given to this device. */
0540     char device_name[32];
0541 
0542     /** Application Context */
0543     void *app_ctx;
0544 
0545     struct cavium_wq dma_comp_wq;
0546 
0547     /** Lock for dma response list */
0548     spinlock_t cmd_resp_wqlock;
0549     u32 cmd_resp_state;
0550 
0551     struct cavium_wq check_db_wq[MAX_POSSIBLE_OCTEON_INSTR_QUEUES];
0552 
0553     struct cavium_wk nic_poll_work;
0554 
0555     struct cavium_wk console_poll_work[MAX_OCTEON_MAPS];
0556 
0557     void *priv;
0558 
0559     int num_msix_irqs;
0560 
0561     void *msix_entries;
0562 
0563     /* when requesting IRQs, the names are stored here */
0564     void *irq_name_storage;
0565 
0566     struct octeon_sriov_info sriov_info;
0567 
0568     struct octeon_pf_vf_hs_word pfvf_hsword;
0569 
0570     int msix_on;
0571 
0572     /** Mail Box details of each octeon queue. */
0573     struct octeon_mbox  *mbox[MAX_POSSIBLE_VFS];
0574 
0575     /** IOq information of it's corresponding MSI-X interrupt. */
0576     struct octeon_ioq_vector    *ioq_vector;
0577 
0578     int rx_pause;
0579     int tx_pause;
0580 
0581     struct oct_link_stats link_stats; /*stastics from firmware*/
0582 
0583     /* private flags to control driver-specific features through ethtool */
0584     u32 priv_flags;
0585 
0586     void *watchdog_task;
0587 
0588     u32 rx_coalesce_usecs;
0589     u32 rx_max_coalesced_frames;
0590     u32 tx_max_coalesced_frames;
0591 
0592     bool cores_crashed;
0593 
0594     struct {
0595         int bus;
0596         int dev;
0597         int func;
0598     } loc;
0599 
0600     atomic_t *adapter_refcount; /* reference count of adapter */
0601 
0602     atomic_t *adapter_fw_state; /* per-adapter, lio_fw_state */
0603 
0604     bool ptp_enable;
0605 
0606     struct lio_vf_rep_list vf_rep_list;
0607     struct devlink *devlink;
0608     enum devlink_eswitch_mode eswitch_mode;
0609 
0610     /* for 25G NIC speed change */
0611     u8  speed_boot;
0612     u8  speed_setting;
0613     u8  no_speed_setting;
0614 
0615     u32    vfstats_poll;
0616 #define LIO_VFSTATS_POLL 10
0617 };
0618 
0619 #define  OCT_DRV_ONLINE 1
0620 #define  OCT_DRV_OFFLINE 2
0621 #define  OCTEON_CN6XXX(oct) ({                  \
0622                  typeof(oct) _oct = (oct);      \
0623                  ((_oct->chip_id == OCTEON_CN66XX) ||   \
0624                   (_oct->chip_id == OCTEON_CN68XX));    })
0625 #define  OCTEON_CN23XX_PF(oct)        ((oct)->chip_id == OCTEON_CN23XX_PF_VID)
0626 #define  OCTEON_CN23XX_VF(oct)        ((oct)->chip_id == OCTEON_CN23XX_VF_VID)
0627 #define CHIP_CONF(oct, TYPE)             \
0628     (((struct octeon_ ## TYPE  *)((oct)->chip))->conf)
0629 
0630 #define MAX_IO_PENDING_PKT_COUNT 100
0631 
0632 /*------------------ Function Prototypes ----------------------*/
0633 
0634 /** Initialize device list memory */
0635 void octeon_init_device_list(int conf_type);
0636 
0637 /** Free memory for Input and Output queue structures for a octeon device */
0638 void octeon_free_device_mem(struct octeon_device *oct);
0639 
0640 /* Look up a free entry in the octeon_device table and allocate resources
0641  * for the octeon_device structure for an octeon device. Called at init
0642  * time.
0643  */
0644 struct octeon_device *octeon_allocate_device(u32 pci_id,
0645                          u32 priv_size);
0646 
0647 /** Register a device's bus location at initialization time.
0648  *  @param octeon_dev - pointer to the octeon device structure.
0649  *  @param bus        - PCIe bus #
0650  *  @param dev        - PCIe device #
0651  *  @param func       - PCIe function #
0652  *  @param is_pf      - TRUE for PF, FALSE for VF
0653  *  @return reference count of device's adapter
0654  */
0655 int octeon_register_device(struct octeon_device *oct,
0656                int bus, int dev, int func, int is_pf);
0657 
0658 /** Deregister a device at de-initialization time.
0659  *  @param octeon_dev - pointer to the octeon device structure.
0660  *  @return reference count of device's adapter
0661  */
0662 int octeon_deregister_device(struct octeon_device *oct);
0663 
0664 /**  Initialize the driver's dispatch list which is a mix of a hash table
0665  *  and a linked list. This is done at driver load time.
0666  *  @param octeon_dev - pointer to the octeon device structure.
0667  *  @return 0 on success, else -ve error value
0668  */
0669 int octeon_init_dispatch_list(struct octeon_device *octeon_dev);
0670 
0671 /**  Delete the driver's dispatch list and all registered entries.
0672  * This is done at driver unload time.
0673  *  @param octeon_dev - pointer to the octeon device structure.
0674  */
0675 void octeon_delete_dispatch_list(struct octeon_device *octeon_dev);
0676 
0677 /** Initialize the core device fields with the info returned by the FW.
0678  * @param recv_info - Receive info structure
0679  * @param buf       - Receive buffer
0680  */
0681 int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf);
0682 
0683 /** Gets the dispatch function registered to receive packets with a
0684  *  given opcode/subcode.
0685  *  @param  octeon_dev  - the octeon device pointer.
0686  *  @param  opcode      - the opcode for which the dispatch function
0687  *                        is to checked.
0688  *  @param  subcode     - the subcode for which the dispatch function
0689  *                        is to checked.
0690  *
0691  *  @return Success: octeon_dispatch_fn_t (dispatch function pointer)
0692  *  @return Failure: NULL
0693  *
0694  *  Looks up the dispatch list to get the dispatch function for a
0695  *  given opcode.
0696  */
0697 octeon_dispatch_fn_t
0698 octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
0699             u16 subcode);
0700 
0701 /** Get the octeon device pointer.
0702  *  @param octeon_id  - The id for which the octeon device pointer is required.
0703  *  @return Success: Octeon device pointer.
0704  *  @return Failure: NULL.
0705  */
0706 struct octeon_device *lio_get_device(u32 octeon_id);
0707 
0708 /** Get the octeon id assigned to the octeon device passed as argument.
0709  *  This function is exported to other modules.
0710  *  @param dev - octeon device pointer passed as a void *.
0711  *  @return octeon device id
0712  */
0713 int lio_get_device_id(void *dev);
0714 
0715 /** Read windowed register.
0716  *  @param  oct   -  pointer to the Octeon device.
0717  *  @param  addr  -  Address of the register to read.
0718  *
0719  *  This routine is called to read from the indirectly accessed
0720  *  Octeon registers that are visible through a PCI BAR0 mapped window
0721  *  register.
0722  *  @return  - 64 bit value read from the register.
0723  */
0724 
0725 u64 lio_pci_readq(struct octeon_device *oct, u64 addr);
0726 
0727 /** Write windowed register.
0728  *  @param  oct  -  pointer to the Octeon device.
0729  *  @param  val  -  Value to write
0730  *  @param  addr -  Address of the register to write
0731  *
0732  *  This routine is called to write to the indirectly accessed
0733  *  Octeon registers that are visible through a PCI BAR0 mapped window
0734  *  register.
0735  *  @return   Nothing.
0736  */
0737 void lio_pci_writeq(struct octeon_device *oct, u64 val, u64 addr);
0738 
0739 /* Routines for reading and writing CSRs */
0740 #define   octeon_write_csr(oct_dev, reg_off, value) \
0741         writel(value, (oct_dev)->mmio[0].hw_addr + (reg_off))
0742 
0743 #define   octeon_write_csr64(oct_dev, reg_off, val64) \
0744         writeq(val64, (oct_dev)->mmio[0].hw_addr + (reg_off))
0745 
0746 #define   octeon_read_csr(oct_dev, reg_off)         \
0747         readl((oct_dev)->mmio[0].hw_addr + (reg_off))
0748 
0749 #define   octeon_read_csr64(oct_dev, reg_off)         \
0750         readq((oct_dev)->mmio[0].hw_addr + (reg_off))
0751 
0752 /**
0753  * Checks if memory access is okay
0754  *
0755  * @param oct which octeon to send to
0756  * @return Zero on success, negative on failure.
0757  */
0758 int octeon_mem_access_ok(struct octeon_device *oct);
0759 
0760 /**
0761  * Waits for DDR initialization.
0762  *
0763  * @param oct which octeon to send to
0764  * @param timeout_in_ms pointer to how long to wait until DDR is initialized
0765  * in ms.
0766  *                      If contents are 0, it waits until contents are non-zero
0767  *                      before starting to check.
0768  * @return Zero on success, negative on failure.
0769  */
0770 int octeon_wait_for_ddr_init(struct octeon_device *oct,
0771                  u32 *timeout_in_ms);
0772 
0773 /**
0774  * Wait for u-boot to boot and be waiting for a command.
0775  *
0776  * @param wait_time_hundredths
0777  *               Maximum time to wait
0778  *
0779  * @return Zero on success, negative on failure.
0780  */
0781 int octeon_wait_for_bootloader(struct octeon_device *oct,
0782                    u32 wait_time_hundredths);
0783 
0784 /**
0785  * Initialize console access
0786  *
0787  * @param oct which octeon initialize
0788  * @return Zero on success, negative on failure.
0789  */
0790 int octeon_init_consoles(struct octeon_device *oct);
0791 
0792 /**
0793  * Adds access to a console to the device.
0794  *
0795  * @param oct:          which octeon to add to
0796  * @param console_num:  which console
0797  * @param dbg_enb:      ptr to debug enablement string, one of:
0798  *                    * NULL for no debug output (i.e. disabled)
0799  *                    * empty string enables debug output (via default method)
0800  *                    * specific string to enable debug console output
0801  *
0802  * @return Zero on success, negative on failure.
0803  */
0804 int octeon_add_console(struct octeon_device *oct, u32 console_num,
0805                char *dbg_enb);
0806 
0807 /** write or read from a console */
0808 int octeon_console_write(struct octeon_device *oct, u32 console_num,
0809              char *buffer, u32 write_request_size, u32 flags);
0810 int octeon_console_write_avail(struct octeon_device *oct, u32 console_num);
0811 
0812 int octeon_console_read_avail(struct octeon_device *oct, u32 console_num);
0813 
0814 /** Removes all attached consoles. */
0815 void octeon_remove_consoles(struct octeon_device *oct);
0816 
0817 /**
0818  * Send a string to u-boot on console 0 as a command.
0819  *
0820  * @param oct which octeon to send to
0821  * @param cmd_str String to send
0822  * @param wait_hundredths Time to wait for u-boot to accept the command.
0823  *
0824  * @return Zero on success, negative on failure.
0825  */
0826 int octeon_console_send_cmd(struct octeon_device *oct, char *cmd_str,
0827                 u32 wait_hundredths);
0828 
0829 /** Parses, validates, and downloads firmware, then boots associated cores.
0830  *  @param oct which octeon to download firmware to
0831  *  @param data  - The complete firmware file image
0832  *  @param size  - The size of the data
0833  *
0834  *  @return 0 if success.
0835  *         -EINVAL if file is incompatible or badly formatted.
0836  *         -ENODEV if no handler was found for the application type or an
0837  *         invalid octeon id was passed.
0838  */
0839 int octeon_download_firmware(struct octeon_device *oct, const u8 *data,
0840                  size_t size);
0841 
0842 char *lio_get_state_string(atomic_t *state_ptr);
0843 
0844 /** Sets up instruction queues for the device
0845  *  @param oct which octeon to setup
0846  *
0847  *  @return 0 if success. 1 if fails
0848  */
0849 int octeon_setup_instr_queues(struct octeon_device *oct);
0850 
0851 /** Sets up output queues for the device
0852  *  @param oct which octeon to setup
0853  *
0854  *  @return 0 if success. 1 if fails
0855  */
0856 int octeon_setup_output_queues(struct octeon_device *oct);
0857 
0858 int octeon_get_tx_qsize(struct octeon_device *oct, u32 q_no);
0859 
0860 int octeon_get_rx_qsize(struct octeon_device *oct, u32 q_no);
0861 
0862 /** Turns off the input and output queues for the device
0863  *  @param oct which octeon to disable
0864  */
0865 int octeon_set_io_queues_off(struct octeon_device *oct);
0866 
0867 /** Turns on or off the given output queue for the device
0868  *  @param oct which octeon to change
0869  *  @param q_no which queue
0870  *  @param enable 1 to enable, 0 to disable
0871  */
0872 void octeon_set_droq_pkt_op(struct octeon_device *oct, u32 q_no, u32 enable);
0873 
0874 /** Retrieve the config for the device
0875  *  @param oct which octeon
0876  *  @param card_type type of card
0877  *
0878  *  @returns pointer to configuration
0879  */
0880 void *oct_get_config_info(struct octeon_device *oct, u16 card_type);
0881 
0882 /** Gets the octeon device configuration
0883  *  @return - pointer to the octeon configuration struture
0884  */
0885 struct octeon_config *octeon_get_conf(struct octeon_device *oct);
0886 
0887 void octeon_free_ioq_vector(struct octeon_device *oct);
0888 int octeon_allocate_ioq_vector(struct octeon_device  *oct, u32 num_ioqs);
0889 void lio_enable_irq(struct octeon_droq *droq, struct octeon_instr_queue *iq);
0890 
0891 /* LiquidIO driver pivate flags */
0892 enum {
0893     OCT_PRIV_FLAG_TX_BYTES = 0, /* Tx interrupts by pending byte count */
0894 };
0895 
0896 #define OCT_PRIV_FLAG_DEFAULT 0x0
0897 
0898 static inline u32 lio_get_priv_flag(struct octeon_device *octdev, u32 flag)
0899 {
0900     return !!(octdev->priv_flags & (0x1 << flag));
0901 }
0902 
0903 static inline void lio_set_priv_flag(struct octeon_device *octdev,
0904                      u32 flag, u32 val)
0905 {
0906     if (val)
0907         octdev->priv_flags |= (0x1 << flag);
0908     else
0909         octdev->priv_flags &= ~(0x1 << flag);
0910 }
0911 #endif