0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
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
0029 #define OCTEON_CN68XX_PCIID 0x91177d
0030 #define OCTEON_CN66XX_PCIID 0x92177d
0031 #define OCTEON_CN23XX_PCIID_PF 0x9702177d
0032
0033
0034
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
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
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
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
0079
0080
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
0089
0090
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
0114
0115
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
0124
0125
0126
0127
0128
0129
0130
0131
0132 struct octeon_dispatch {
0133
0134 struct list_head list;
0135
0136
0137 u16 opcode;
0138
0139
0140 octeon_dispatch_fn_t dispatch_fn;
0141
0142
0143
0144
0145 void *arg;
0146 };
0147
0148
0149 struct octeon_dispatch_list {
0150
0151 spinlock_t lock;
0152
0153
0154 u32 count;
0155
0156
0157 struct octeon_dispatch *dlist;
0158 };
0159
0160
0161
0162 #define OCT_MEM_REGIONS 3
0163
0164
0165
0166
0167
0168 struct octeon_mmio {
0169
0170 u64 start;
0171
0172
0173 u32 len;
0174
0175
0176 u32 mapped_len;
0177
0178
0179 u8 __iomem *hw_addr;
0180
0181
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
0260 #define CVMX_BOOTMEM_NAME_LEN 128
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270 struct cvmx_bootmem_named_block_desc {
0271
0272 u64 base_addr;
0273
0274
0275 u64 size;
0276
0277
0278 char name[CVMX_BOOTMEM_NAME_LEN];
0279 };
0280
0281 struct oct_fw_info {
0282 u32 max_nic_ports;
0283 u32 num_gmx_ports;
0284 u64 app_cap_flags;
0285
0286
0287
0288
0289 u32 app_mode;
0290 char liquidio_firmware_version[32];
0291
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
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
0316
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
0334 u64 pkind : 8;
0335
0336
0337 u64 core_tics_per_us : 16;
0338
0339
0340 u64 coproc_tics_per_us : 16;
0341
0342
0343 u64 app_mode : 8;
0344
0345
0346 u64 reserved : 16;
0347
0348 #else
0349
0350
0351 u64 reserved : 16;
0352
0353
0354 u64 app_mode : 8;
0355
0356
0357 u64 coproc_tics_per_us : 16;
0358
0359
0360 u64 core_tics_per_us : 16;
0361
0362
0363 u64 pkind : 8;
0364 #endif
0365 };
0366
0367 struct octeon_sriov_info {
0368
0369 u32 rings_per_vf;
0370
0371
0372
0373
0374
0375 u32 max_vfs;
0376
0377
0378 u32 num_vfs_alloced;
0379
0380
0381 u32 num_pf_rings;
0382
0383
0384 u32 pf_srn;
0385
0386
0387 u32 trs;
0388
0389 u32 sriov_enabled;
0390
0391 struct lio_trusted_vf trusted_vf;
0392
0393
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
0427
0428
0429
0430 struct octeon_device {
0431
0432 spinlock_t pci_win_lock;
0433
0434
0435 spinlock_t mem_access_lock;
0436
0437
0438 struct pci_dev *pci_dev;
0439
0440
0441 void *chip;
0442
0443
0444 u32 ifcount;
0445
0446 struct octdev_props props[MAX_OCTEON_LINKS];
0447
0448
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
0460 u32 octeon_id;
0461
0462
0463 u16 pcie_port;
0464
0465 u16 flags;
0466 #define LIO_FLAG_MSI_ENABLED (u32)(1 << 1)
0467
0468
0469 atomic_t status;
0470
0471
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
0483 struct octeon_sc_buffer_pool sc_buf_pool;
0484
0485
0486 struct octeon_instr_queue *instr_queue
0487 [MAX_POSSIBLE_OCTEON_INSTR_QUEUES];
0488
0489
0490 struct octeon_response_list response_list[MAX_RESPONSE_LISTS];
0491
0492 u32 num_oqs;
0493
0494
0495 struct octeon_droq *droq[MAX_POSSIBLE_OCTEON_OUTPUT_QUEUES];
0496
0497 struct octeon_io_enable io_qmask;
0498
0499
0500 struct octeon_dispatch_list dispatch;
0501
0502 u32 int_status;
0503
0504 u64 droq_intr;
0505
0506
0507 u64 bootmem_desc_addr;
0508
0509
0510
0511
0512 struct cvmx_bootmem_named_block_desc bootmem_named_block_desc;
0513
0514
0515 u64 console_desc_addr;
0516
0517
0518 u32 num_consoles;
0519
0520
0521 struct octeon_console console[MAX_OCTEON_MAPS];
0522
0523
0524 struct {
0525 u64 dram_region_base;
0526 int bar1_index;
0527 } console_nb_info;
0528
0529
0530 u64 coproc_clock_rate;
0531
0532
0533
0534
0535 u32 app_mode;
0536
0537 struct oct_fw_info fw_info;
0538
0539
0540 char device_name[32];
0541
0542
0543 void *app_ctx;
0544
0545 struct cavium_wq dma_comp_wq;
0546
0547
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
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
0573 struct octeon_mbox *mbox[MAX_POSSIBLE_VFS];
0574
0575
0576 struct octeon_ioq_vector *ioq_vector;
0577
0578 int rx_pause;
0579 int tx_pause;
0580
0581 struct oct_link_stats link_stats;
0582
0583
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;
0601
0602 atomic_t *adapter_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
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
0633
0634
0635 void octeon_init_device_list(int conf_type);
0636
0637
0638 void octeon_free_device_mem(struct octeon_device *oct);
0639
0640
0641
0642
0643
0644 struct octeon_device *octeon_allocate_device(u32 pci_id,
0645 u32 priv_size);
0646
0647
0648
0649
0650
0651
0652
0653
0654
0655 int octeon_register_device(struct octeon_device *oct,
0656 int bus, int dev, int func, int is_pf);
0657
0658
0659
0660
0661
0662 int octeon_deregister_device(struct octeon_device *oct);
0663
0664
0665
0666
0667
0668
0669 int octeon_init_dispatch_list(struct octeon_device *octeon_dev);
0670
0671
0672
0673
0674
0675 void octeon_delete_dispatch_list(struct octeon_device *octeon_dev);
0676
0677
0678
0679
0680
0681 int octeon_core_drv_init(struct octeon_recv_info *recv_info, void *buf);
0682
0683
0684
0685
0686
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697 octeon_dispatch_fn_t
0698 octeon_get_dispatch(struct octeon_device *octeon_dev, u16 opcode,
0699 u16 subcode);
0700
0701
0702
0703
0704
0705
0706 struct octeon_device *lio_get_device(u32 octeon_id);
0707
0708
0709
0710
0711
0712
0713 int lio_get_device_id(void *dev);
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725 u64 lio_pci_readq(struct octeon_device *oct, u64 addr);
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737 void lio_pci_writeq(struct octeon_device *oct, u64 val, u64 addr);
0738
0739
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
0754
0755
0756
0757
0758 int octeon_mem_access_ok(struct octeon_device *oct);
0759
0760
0761
0762
0763
0764
0765
0766
0767
0768
0769
0770 int octeon_wait_for_ddr_init(struct octeon_device *oct,
0771 u32 *timeout_in_ms);
0772
0773
0774
0775
0776
0777
0778
0779
0780
0781 int octeon_wait_for_bootloader(struct octeon_device *oct,
0782 u32 wait_time_hundredths);
0783
0784
0785
0786
0787
0788
0789
0790 int octeon_init_consoles(struct octeon_device *oct);
0791
0792
0793
0794
0795
0796
0797
0798
0799
0800
0801
0802
0803
0804 int octeon_add_console(struct octeon_device *oct, u32 console_num,
0805 char *dbg_enb);
0806
0807
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
0815 void octeon_remove_consoles(struct octeon_device *oct);
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826 int octeon_console_send_cmd(struct octeon_device *oct, char *cmd_str,
0827 u32 wait_hundredths);
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
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
0845
0846
0847
0848
0849 int octeon_setup_instr_queues(struct octeon_device *oct);
0850
0851
0852
0853
0854
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
0863
0864
0865 int octeon_set_io_queues_off(struct octeon_device *oct);
0866
0867
0868
0869
0870
0871
0872 void octeon_set_droq_pkt_op(struct octeon_device *oct, u32 q_no, u32 enable);
0873
0874
0875
0876
0877
0878
0879
0880 void *oct_get_config_info(struct octeon_device *oct, u16 card_type);
0881
0882
0883
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
0892 enum {
0893 OCT_PRIV_FLAG_TX_BYTES = 0,
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