Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 1 | /* QLogic qed NIC Driver |
| 2 | * Copyright (c) 2015 QLogic Corporation |
| 3 | * |
| 4 | * This software is available under the terms of the GNU General Public License |
| 5 | * (GPL) Version 2, available from the file COPYING in the main directory of |
| 6 | * this source tree. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _QED_H |
| 10 | #define _QED_H |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/io.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/firmware.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/list.h> |
| 18 | #include <linux/mutex.h> |
| 19 | #include <linux/pci.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/workqueue.h> |
| 23 | #include <linux/zlib.h> |
| 24 | #include <linux/hashtable.h> |
| 25 | #include <linux/qed/qed_if.h> |
| 26 | #include "qed_hsi.h" |
| 27 | |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 28 | extern const struct qed_common_ops qed_common_ops_pass; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 29 | #define DRV_MODULE_VERSION "8.4.0.0" |
| 30 | |
| 31 | #define MAX_HWFNS_PER_DEVICE (4) |
| 32 | #define NAME_SIZE 16 |
| 33 | #define VER_SIZE 16 |
| 34 | |
| 35 | /* cau states */ |
| 36 | enum qed_coalescing_mode { |
| 37 | QED_COAL_MODE_DISABLE, |
| 38 | QED_COAL_MODE_ENABLE |
| 39 | }; |
| 40 | |
| 41 | struct qed_eth_cb_ops; |
| 42 | struct qed_dev_info; |
| 43 | |
| 44 | /* helpers */ |
| 45 | static inline u32 qed_db_addr(u32 cid, u32 DEMS) |
| 46 | { |
| 47 | u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) | |
| 48 | FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid); |
| 49 | |
| 50 | return db_addr; |
| 51 | } |
| 52 | |
| 53 | #define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \ |
| 54 | ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \ |
| 55 | ~((1 << (p_hwfn->cdev->cache_shift)) - 1)) |
| 56 | |
| 57 | #define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++) |
| 58 | |
| 59 | #define D_TRINE(val, cond1, cond2, true1, true2, def) \ |
| 60 | (val == (cond1) ? true1 : \ |
| 61 | (val == (cond2) ? true2 : def)) |
| 62 | |
| 63 | /* forward */ |
| 64 | struct qed_ptt_pool; |
| 65 | struct qed_spq; |
| 66 | struct qed_sb_info; |
| 67 | struct qed_sb_attn_info; |
| 68 | struct qed_cxt_mngr; |
| 69 | struct qed_sb_sp_info; |
| 70 | struct qed_mcp_info; |
| 71 | |
| 72 | struct qed_rt_data { |
| 73 | u32 init_val; |
| 74 | bool b_valid; |
| 75 | }; |
| 76 | |
| 77 | /* The PCI personality is not quite synonymous to protocol ID: |
| 78 | * 1. All personalities need CORE connections |
| 79 | * 2. The Ethernet personality may support also the RoCE protocol |
| 80 | */ |
| 81 | enum qed_pci_personality { |
| 82 | QED_PCI_ETH, |
| 83 | QED_PCI_DEFAULT /* default in shmem */ |
| 84 | }; |
| 85 | |
| 86 | /* All VFs are symmetric, all counters are PF + all VFs */ |
| 87 | struct qed_qm_iids { |
| 88 | u32 cids; |
| 89 | u32 vf_cids; |
| 90 | u32 tids; |
| 91 | }; |
| 92 | |
| 93 | enum QED_RESOURCES { |
| 94 | QED_SB, |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 95 | QED_L2_QUEUE, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 96 | QED_VPORT, |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 97 | QED_RSS_ENG, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 98 | QED_PQ, |
| 99 | QED_RL, |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 100 | QED_MAC, |
| 101 | QED_VLAN, |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 102 | QED_ILT, |
| 103 | QED_MAX_RESC, |
| 104 | }; |
| 105 | |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 106 | enum QED_FEATURE { |
| 107 | QED_PF_L2_QUE, |
| 108 | QED_MAX_FEATURES, |
| 109 | }; |
| 110 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 111 | struct qed_hw_info { |
| 112 | /* PCI personality */ |
| 113 | enum qed_pci_personality personality; |
| 114 | |
| 115 | /* Resource Allocation scheme results */ |
| 116 | u32 resc_start[QED_MAX_RESC]; |
| 117 | u32 resc_num[QED_MAX_RESC]; |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 118 | u32 feat_num[QED_MAX_FEATURES]; |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 119 | |
| 120 | #define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc]) |
| 121 | #define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc]) |
| 122 | #define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc]) |
| 123 | |
| 124 | u8 num_tc; |
| 125 | u8 offload_tc; |
| 126 | u8 non_offload_tc; |
| 127 | |
| 128 | u32 concrete_fid; |
| 129 | u16 opaque_fid; |
| 130 | u16 ovlan; |
| 131 | u32 part_num[4]; |
| 132 | |
| 133 | u32 vendor_id; |
| 134 | u32 device_id; |
| 135 | |
| 136 | unsigned char hw_mac_addr[ETH_ALEN]; |
| 137 | |
| 138 | struct qed_igu_info *p_igu_info; |
| 139 | |
| 140 | u32 port_mode; |
| 141 | u32 hw_mode; |
| 142 | }; |
| 143 | |
| 144 | struct qed_hw_cid_data { |
| 145 | u32 cid; |
| 146 | bool b_cid_allocated; |
| 147 | |
| 148 | /* Additional identifiers */ |
| 149 | u16 opaque_fid; |
| 150 | u8 vport_id; |
| 151 | }; |
| 152 | |
| 153 | /* maximun size of read/write commands (HW limit) */ |
| 154 | #define DMAE_MAX_RW_SIZE 0x2000 |
| 155 | |
| 156 | struct qed_dmae_info { |
| 157 | /* Mutex for synchronizing access to functions */ |
| 158 | struct mutex mutex; |
| 159 | |
| 160 | u8 channel; |
| 161 | |
| 162 | dma_addr_t completion_word_phys_addr; |
| 163 | |
| 164 | /* The memory location where the DMAE writes the completion |
| 165 | * value when an operation is finished on this context. |
| 166 | */ |
| 167 | u32 *p_completion_word; |
| 168 | |
| 169 | dma_addr_t intermediate_buffer_phys_addr; |
| 170 | |
| 171 | /* An intermediate buffer for DMAE operations that use virtual |
| 172 | * addresses - data is DMA'd to/from this buffer and then |
| 173 | * memcpy'd to/from the virtual address |
| 174 | */ |
| 175 | u32 *p_intermediate_buffer; |
| 176 | |
| 177 | dma_addr_t dmae_cmd_phys_addr; |
| 178 | struct dmae_cmd *p_dmae_cmd; |
| 179 | }; |
| 180 | |
| 181 | struct qed_qm_info { |
| 182 | struct init_qm_pq_params *qm_pq_params; |
| 183 | struct init_qm_vport_params *qm_vport_params; |
| 184 | struct init_qm_port_params *qm_port_params; |
| 185 | u16 start_pq; |
| 186 | u8 start_vport; |
| 187 | u8 pure_lb_pq; |
| 188 | u8 offload_pq; |
| 189 | u8 pure_ack_pq; |
| 190 | u8 vf_queues_offset; |
| 191 | u16 num_pqs; |
| 192 | u16 num_vf_pqs; |
| 193 | u8 num_vports; |
| 194 | u8 max_phys_tcs_per_port; |
| 195 | bool pf_rl_en; |
| 196 | bool pf_wfq_en; |
| 197 | bool vport_rl_en; |
| 198 | bool vport_wfq_en; |
| 199 | u8 pf_wfq; |
| 200 | u32 pf_rl; |
| 201 | }; |
| 202 | |
| 203 | struct qed_fw_data { |
| 204 | const u8 *modes_tree_buf; |
| 205 | union init_op *init_ops; |
| 206 | const u32 *arr_data; |
| 207 | u32 init_ops_size; |
| 208 | }; |
| 209 | |
| 210 | struct qed_simd_fp_handler { |
| 211 | void *token; |
| 212 | void (*func)(void *); |
| 213 | }; |
| 214 | |
| 215 | struct qed_hwfn { |
| 216 | struct qed_dev *cdev; |
| 217 | u8 my_id; /* ID inside the PF */ |
| 218 | #define IS_LEAD_HWFN(edev) (!((edev)->my_id)) |
| 219 | u8 rel_pf_id; /* Relative to engine*/ |
| 220 | u8 abs_pf_id; |
| 221 | #define QED_PATH_ID(_p_hwfn) ((_p_hwfn)->abs_pf_id & 1) |
| 222 | u8 port_id; |
| 223 | bool b_active; |
| 224 | |
| 225 | u32 dp_module; |
| 226 | u8 dp_level; |
| 227 | char name[NAME_SIZE]; |
| 228 | |
| 229 | bool first_on_engine; |
| 230 | bool hw_init_done; |
| 231 | |
| 232 | /* BAR access */ |
| 233 | void __iomem *regview; |
| 234 | void __iomem *doorbells; |
| 235 | u64 db_phys_addr; |
| 236 | unsigned long db_size; |
| 237 | |
| 238 | /* PTT pool */ |
| 239 | struct qed_ptt_pool *p_ptt_pool; |
| 240 | |
| 241 | /* HW info */ |
| 242 | struct qed_hw_info hw_info; |
| 243 | |
| 244 | /* rt_array (for init-tool) */ |
| 245 | struct qed_rt_data *rt_data; |
| 246 | |
| 247 | /* SPQ */ |
| 248 | struct qed_spq *p_spq; |
| 249 | |
| 250 | /* EQ */ |
| 251 | struct qed_eq *p_eq; |
| 252 | |
| 253 | /* Consolidate Q*/ |
| 254 | struct qed_consq *p_consq; |
| 255 | |
| 256 | /* Slow-Path definitions */ |
| 257 | struct tasklet_struct *sp_dpc; |
| 258 | bool b_sp_dpc_enabled; |
| 259 | |
| 260 | struct qed_ptt *p_main_ptt; |
| 261 | struct qed_ptt *p_dpc_ptt; |
| 262 | |
| 263 | struct qed_sb_sp_info *p_sp_sb; |
| 264 | struct qed_sb_attn_info *p_sb_attn; |
| 265 | |
| 266 | /* Protocol related */ |
| 267 | struct qed_pf_params pf_params; |
| 268 | |
| 269 | /* Array of sb_info of all status blocks */ |
| 270 | struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD]; |
| 271 | u16 num_sbs; |
| 272 | |
| 273 | struct qed_cxt_mngr *p_cxt_mngr; |
| 274 | |
| 275 | /* Flag indicating whether interrupts are enabled or not*/ |
| 276 | bool b_int_enabled; |
| 277 | |
| 278 | struct qed_mcp_info *mcp_info; |
| 279 | |
Yuval Mintz | 25c089d | 2015-10-26 11:02:26 +0200 | [diff] [blame^] | 280 | struct qed_hw_cid_data *p_tx_cids; |
| 281 | struct qed_hw_cid_data *p_rx_cids; |
| 282 | |
Yuval Mintz | fe56b9e | 2015-10-26 11:02:25 +0200 | [diff] [blame] | 283 | struct qed_dmae_info dmae_info; |
| 284 | |
| 285 | /* QM init */ |
| 286 | struct qed_qm_info qm_info; |
| 287 | |
| 288 | /* Buffer for unzipping firmware data */ |
| 289 | void *unzip_buf; |
| 290 | |
| 291 | struct qed_simd_fp_handler simd_proto_handler[64]; |
| 292 | |
| 293 | struct z_stream_s *stream; |
| 294 | }; |
| 295 | |
| 296 | struct pci_params { |
| 297 | int pm_cap; |
| 298 | |
| 299 | unsigned long mem_start; |
| 300 | unsigned long mem_end; |
| 301 | unsigned int irq; |
| 302 | u8 pf_num; |
| 303 | }; |
| 304 | |
| 305 | struct qed_int_param { |
| 306 | u32 int_mode; |
| 307 | u8 num_vectors; |
| 308 | u8 min_msix_cnt; /* for minimal functionality */ |
| 309 | }; |
| 310 | |
| 311 | struct qed_int_params { |
| 312 | struct qed_int_param in; |
| 313 | struct qed_int_param out; |
| 314 | struct msix_entry *msix_table; |
| 315 | bool fp_initialized; |
| 316 | u8 fp_msix_base; |
| 317 | u8 fp_msix_cnt; |
| 318 | }; |
| 319 | |
| 320 | struct qed_dev { |
| 321 | u32 dp_module; |
| 322 | u8 dp_level; |
| 323 | char name[NAME_SIZE]; |
| 324 | |
| 325 | u8 type; |
| 326 | #define QED_DEV_TYPE_BB_A0 (0 << 0) |
| 327 | #define QED_DEV_TYPE_MASK (0x3) |
| 328 | #define QED_DEV_TYPE_SHIFT (0) |
| 329 | |
| 330 | u16 chip_num; |
| 331 | #define CHIP_NUM_MASK 0xffff |
| 332 | #define CHIP_NUM_SHIFT 16 |
| 333 | |
| 334 | u16 chip_rev; |
| 335 | #define CHIP_REV_MASK 0xf |
| 336 | #define CHIP_REV_SHIFT 12 |
| 337 | |
| 338 | u16 chip_metal; |
| 339 | #define CHIP_METAL_MASK 0xff |
| 340 | #define CHIP_METAL_SHIFT 4 |
| 341 | |
| 342 | u16 chip_bond_id; |
| 343 | #define CHIP_BOND_ID_MASK 0xf |
| 344 | #define CHIP_BOND_ID_SHIFT 0 |
| 345 | |
| 346 | u8 num_engines; |
| 347 | u8 num_ports_in_engines; |
| 348 | u8 num_funcs_in_port; |
| 349 | |
| 350 | u8 path_id; |
| 351 | enum mf_mode mf_mode; |
| 352 | #define IS_MF(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode != SF) |
| 353 | #define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == MF_NPAR) |
| 354 | #define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == MF_OVLAN) |
| 355 | |
| 356 | int pcie_width; |
| 357 | int pcie_speed; |
| 358 | u8 ver_str[VER_SIZE]; |
| 359 | |
| 360 | /* Add MF related configuration */ |
| 361 | u8 mcp_rev; |
| 362 | u8 boot_mode; |
| 363 | |
| 364 | u8 wol; |
| 365 | |
| 366 | u32 int_mode; |
| 367 | enum qed_coalescing_mode int_coalescing_mode; |
| 368 | u8 rx_coalesce_usecs; |
| 369 | u8 tx_coalesce_usecs; |
| 370 | |
| 371 | /* Start Bar offset of first hwfn */ |
| 372 | void __iomem *regview; |
| 373 | void __iomem *doorbells; |
| 374 | u64 db_phys_addr; |
| 375 | unsigned long db_size; |
| 376 | |
| 377 | /* PCI */ |
| 378 | u8 cache_shift; |
| 379 | |
| 380 | /* Init */ |
| 381 | const struct iro *iro_arr; |
| 382 | #define IRO (p_hwfn->cdev->iro_arr) |
| 383 | |
| 384 | /* HW functions */ |
| 385 | u8 num_hwfns; |
| 386 | struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE]; |
| 387 | |
| 388 | u32 drv_type; |
| 389 | |
| 390 | struct qed_eth_stats *reset_stats; |
| 391 | struct qed_fw_data *fw_data; |
| 392 | |
| 393 | u32 mcp_nvm_resp; |
| 394 | |
| 395 | /* Linux specific here */ |
| 396 | struct qede_dev *edev; |
| 397 | struct pci_dev *pdev; |
| 398 | int msg_enable; |
| 399 | |
| 400 | struct pci_params pci_params; |
| 401 | |
| 402 | struct qed_int_params int_params; |
| 403 | |
| 404 | u8 protocol; |
| 405 | #define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH) |
| 406 | |
| 407 | const struct firmware *firmware; |
| 408 | }; |
| 409 | |
| 410 | #define QED_GET_TYPE(dev) (((dev)->type & QED_DEV_TYPE_MASK) >> \ |
| 411 | QED_DEV_TYPE_SHIFT) |
| 412 | #define QED_IS_BB_A0(dev) (QED_GET_TYPE(dev) == QED_DEV_TYPE_BB_A0) |
| 413 | #define QED_IS_BB(dev) (QED_IS_BB_A0(dev)) |
| 414 | |
| 415 | #define NUM_OF_SBS(dev) MAX_SB_PER_PATH_BB |
| 416 | #define NUM_OF_ENG_PFS(dev) MAX_NUM_PFS_BB |
| 417 | |
| 418 | /** |
| 419 | * @brief qed_concrete_to_sw_fid - get the sw function id from |
| 420 | * the concrete value. |
| 421 | * |
| 422 | * @param concrete_fid |
| 423 | * |
| 424 | * @return inline u8 |
| 425 | */ |
| 426 | static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev, |
| 427 | u32 concrete_fid) |
| 428 | { |
| 429 | u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID); |
| 430 | |
| 431 | return pfid; |
| 432 | } |
| 433 | |
| 434 | #define PURE_LB_TC 8 |
| 435 | |
| 436 | #define QED_LEADING_HWFN(dev) (&dev->hwfns[0]) |
| 437 | |
| 438 | /* Other Linux specific common definitions */ |
| 439 | #define DP_NAME(cdev) ((cdev)->name) |
| 440 | |
| 441 | #define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\ |
| 442 | (cdev->regview) + \ |
| 443 | (offset)) |
| 444 | |
| 445 | #define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset)) |
| 446 | #define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset)) |
| 447 | #define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset)) |
| 448 | |
| 449 | #define DOORBELL(cdev, db_addr, val) \ |
| 450 | writel((u32)val, (void __iomem *)((u8 __iomem *)\ |
| 451 | (cdev->doorbells) + (db_addr))) |
| 452 | |
| 453 | /* Prototypes */ |
| 454 | int qed_fill_dev_info(struct qed_dev *cdev, |
| 455 | struct qed_dev_info *dev_info); |
| 456 | u32 qed_unzip_data(struct qed_hwfn *p_hwfn, |
| 457 | u32 input_len, u8 *input_buf, |
| 458 | u32 max_size, u8 *unzip_buf); |
| 459 | |
| 460 | #define QED_ETH_INTERFACE_VERSION 300 |
| 461 | |
| 462 | #endif /* _QED_H */ |