qed.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. #ifndef _QED_H
  9. #define _QED_H
  10. #include <linux/types.h>
  11. #include <linux/io.h>
  12. #include <linux/delay.h>
  13. #include <linux/firmware.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/list.h>
  16. #include <linux/mutex.h>
  17. #include <linux/pci.h>
  18. #include <linux/slab.h>
  19. #include <linux/string.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/zlib.h>
  22. #include <linux/hashtable.h>
  23. #include <linux/qed/qed_if.h>
  24. #include "qed_debug.h"
  25. #include "qed_hsi.h"
  26. extern const struct qed_common_ops qed_common_ops_pass;
  27. #define DRV_MODULE_VERSION "8.10.9.20"
  28. #define MAX_HWFNS_PER_DEVICE (4)
  29. #define NAME_SIZE 16
  30. #define VER_SIZE 16
  31. #define QED_WFQ_UNIT 100
  32. /* cau states */
  33. enum qed_coalescing_mode {
  34. QED_COAL_MODE_DISABLE,
  35. QED_COAL_MODE_ENABLE
  36. };
  37. struct qed_eth_cb_ops;
  38. struct qed_dev_info;
  39. union qed_mcp_protocol_stats;
  40. enum qed_mcp_protocol_type;
  41. /* helpers */
  42. static inline u32 qed_db_addr(u32 cid, u32 DEMS)
  43. {
  44. u32 db_addr = FIELD_VALUE(DB_LEGACY_ADDR_DEMS, DEMS) |
  45. FIELD_VALUE(DB_LEGACY_ADDR_ICID, cid);
  46. return db_addr;
  47. }
  48. #define ALIGNED_TYPE_SIZE(type_name, p_hwfn) \
  49. ((sizeof(type_name) + (u32)(1 << (p_hwfn->cdev->cache_shift)) - 1) & \
  50. ~((1 << (p_hwfn->cdev->cache_shift)) - 1))
  51. #define for_each_hwfn(cdev, i) for (i = 0; i < cdev->num_hwfns; i++)
  52. #define D_TRINE(val, cond1, cond2, true1, true2, def) \
  53. (val == (cond1) ? true1 : \
  54. (val == (cond2) ? true2 : def))
  55. /* forward */
  56. struct qed_ptt_pool;
  57. struct qed_spq;
  58. struct qed_sb_info;
  59. struct qed_sb_attn_info;
  60. struct qed_cxt_mngr;
  61. struct qed_sb_sp_info;
  62. struct qed_mcp_info;
  63. struct qed_rt_data {
  64. u32 *init_val;
  65. bool *b_valid;
  66. };
  67. enum qed_tunn_mode {
  68. QED_MODE_L2GENEVE_TUNN,
  69. QED_MODE_IPGENEVE_TUNN,
  70. QED_MODE_L2GRE_TUNN,
  71. QED_MODE_IPGRE_TUNN,
  72. QED_MODE_VXLAN_TUNN,
  73. };
  74. enum qed_tunn_clss {
  75. QED_TUNN_CLSS_MAC_VLAN,
  76. QED_TUNN_CLSS_MAC_VNI,
  77. QED_TUNN_CLSS_INNER_MAC_VLAN,
  78. QED_TUNN_CLSS_INNER_MAC_VNI,
  79. MAX_QED_TUNN_CLSS,
  80. };
  81. struct qed_tunn_start_params {
  82. unsigned long tunn_mode;
  83. u16 vxlan_udp_port;
  84. u16 geneve_udp_port;
  85. u8 update_vxlan_udp_port;
  86. u8 update_geneve_udp_port;
  87. u8 tunn_clss_vxlan;
  88. u8 tunn_clss_l2geneve;
  89. u8 tunn_clss_ipgeneve;
  90. u8 tunn_clss_l2gre;
  91. u8 tunn_clss_ipgre;
  92. };
  93. struct qed_tunn_update_params {
  94. unsigned long tunn_mode_update_mask;
  95. unsigned long tunn_mode;
  96. u16 vxlan_udp_port;
  97. u16 geneve_udp_port;
  98. u8 update_rx_pf_clss;
  99. u8 update_tx_pf_clss;
  100. u8 update_vxlan_udp_port;
  101. u8 update_geneve_udp_port;
  102. u8 tunn_clss_vxlan;
  103. u8 tunn_clss_l2geneve;
  104. u8 tunn_clss_ipgeneve;
  105. u8 tunn_clss_l2gre;
  106. u8 tunn_clss_ipgre;
  107. };
  108. /* The PCI personality is not quite synonymous to protocol ID:
  109. * 1. All personalities need CORE connections
  110. * 2. The Ethernet personality may support also the RoCE protocol
  111. */
  112. enum qed_pci_personality {
  113. QED_PCI_ETH,
  114. QED_PCI_ISCSI,
  115. QED_PCI_ETH_ROCE,
  116. QED_PCI_DEFAULT /* default in shmem */
  117. };
  118. /* All VFs are symmetric, all counters are PF + all VFs */
  119. struct qed_qm_iids {
  120. u32 cids;
  121. u32 vf_cids;
  122. u32 tids;
  123. };
  124. enum QED_RESOURCES {
  125. QED_SB,
  126. QED_L2_QUEUE,
  127. QED_VPORT,
  128. QED_RSS_ENG,
  129. QED_PQ,
  130. QED_RL,
  131. QED_MAC,
  132. QED_VLAN,
  133. QED_ILT,
  134. QED_MAX_RESC,
  135. };
  136. enum QED_FEATURE {
  137. QED_PF_L2_QUE,
  138. QED_VF,
  139. QED_MAX_FEATURES,
  140. };
  141. enum QED_PORT_MODE {
  142. QED_PORT_MODE_DE_2X40G,
  143. QED_PORT_MODE_DE_2X50G,
  144. QED_PORT_MODE_DE_1X100G,
  145. QED_PORT_MODE_DE_4X10G_F,
  146. QED_PORT_MODE_DE_4X10G_E,
  147. QED_PORT_MODE_DE_4X20G,
  148. QED_PORT_MODE_DE_1X40G,
  149. QED_PORT_MODE_DE_2X25G,
  150. QED_PORT_MODE_DE_1X25G
  151. };
  152. enum qed_dev_cap {
  153. QED_DEV_CAP_ETH,
  154. QED_DEV_CAP_ISCSI,
  155. QED_DEV_CAP_ROCE,
  156. };
  157. struct qed_hw_info {
  158. /* PCI personality */
  159. enum qed_pci_personality personality;
  160. /* Resource Allocation scheme results */
  161. u32 resc_start[QED_MAX_RESC];
  162. u32 resc_num[QED_MAX_RESC];
  163. u32 feat_num[QED_MAX_FEATURES];
  164. #define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
  165. #define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
  166. #define RESC_END(_p_hwfn, resc) (RESC_START(_p_hwfn, resc) + \
  167. RESC_NUM(_p_hwfn, resc))
  168. #define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
  169. u8 num_tc;
  170. u8 offload_tc;
  171. u8 non_offload_tc;
  172. u32 concrete_fid;
  173. u16 opaque_fid;
  174. u16 ovlan;
  175. u32 part_num[4];
  176. unsigned char hw_mac_addr[ETH_ALEN];
  177. struct qed_igu_info *p_igu_info;
  178. u32 port_mode;
  179. u32 hw_mode;
  180. unsigned long device_capabilities;
  181. };
  182. struct qed_hw_cid_data {
  183. u32 cid;
  184. bool b_cid_allocated;
  185. /* Additional identifiers */
  186. u16 opaque_fid;
  187. u8 vport_id;
  188. };
  189. /* maximun size of read/write commands (HW limit) */
  190. #define DMAE_MAX_RW_SIZE 0x2000
  191. struct qed_dmae_info {
  192. /* Mutex for synchronizing access to functions */
  193. struct mutex mutex;
  194. u8 channel;
  195. dma_addr_t completion_word_phys_addr;
  196. /* The memory location where the DMAE writes the completion
  197. * value when an operation is finished on this context.
  198. */
  199. u32 *p_completion_word;
  200. dma_addr_t intermediate_buffer_phys_addr;
  201. /* An intermediate buffer for DMAE operations that use virtual
  202. * addresses - data is DMA'd to/from this buffer and then
  203. * memcpy'd to/from the virtual address
  204. */
  205. u32 *p_intermediate_buffer;
  206. dma_addr_t dmae_cmd_phys_addr;
  207. struct dmae_cmd *p_dmae_cmd;
  208. };
  209. struct qed_wfq_data {
  210. /* when feature is configured for at least 1 vport */
  211. u32 min_speed;
  212. bool configured;
  213. };
  214. struct qed_qm_info {
  215. struct init_qm_pq_params *qm_pq_params;
  216. struct init_qm_vport_params *qm_vport_params;
  217. struct init_qm_port_params *qm_port_params;
  218. u16 start_pq;
  219. u8 start_vport;
  220. u8 pure_lb_pq;
  221. u8 offload_pq;
  222. u8 pure_ack_pq;
  223. u8 ooo_pq;
  224. u8 vf_queues_offset;
  225. u16 num_pqs;
  226. u16 num_vf_pqs;
  227. u8 num_vports;
  228. u8 max_phys_tcs_per_port;
  229. bool pf_rl_en;
  230. bool pf_wfq_en;
  231. bool vport_rl_en;
  232. bool vport_wfq_en;
  233. u8 pf_wfq;
  234. u32 pf_rl;
  235. struct qed_wfq_data *wfq_data;
  236. u8 num_pf_rls;
  237. };
  238. struct storm_stats {
  239. u32 address;
  240. u32 len;
  241. };
  242. struct qed_storm_stats {
  243. struct storm_stats mstats;
  244. struct storm_stats pstats;
  245. struct storm_stats tstats;
  246. struct storm_stats ustats;
  247. };
  248. struct qed_fw_data {
  249. struct fw_ver_info *fw_ver_info;
  250. const u8 *modes_tree_buf;
  251. union init_op *init_ops;
  252. const u32 *arr_data;
  253. u32 init_ops_size;
  254. };
  255. struct qed_simd_fp_handler {
  256. void *token;
  257. void (*func)(void *);
  258. };
  259. struct qed_hwfn {
  260. struct qed_dev *cdev;
  261. u8 my_id; /* ID inside the PF */
  262. #define IS_LEAD_HWFN(edev) (!((edev)->my_id))
  263. u8 rel_pf_id; /* Relative to engine*/
  264. u8 abs_pf_id;
  265. #define QED_PATH_ID(_p_hwfn) ((_p_hwfn)->abs_pf_id & 1)
  266. u8 port_id;
  267. bool b_active;
  268. u32 dp_module;
  269. u8 dp_level;
  270. char name[NAME_SIZE];
  271. bool first_on_engine;
  272. bool hw_init_done;
  273. u8 num_funcs_on_engine;
  274. u8 enabled_func_idx;
  275. /* BAR access */
  276. void __iomem *regview;
  277. void __iomem *doorbells;
  278. u64 db_phys_addr;
  279. unsigned long db_size;
  280. /* PTT pool */
  281. struct qed_ptt_pool *p_ptt_pool;
  282. /* HW info */
  283. struct qed_hw_info hw_info;
  284. /* rt_array (for init-tool) */
  285. struct qed_rt_data rt_data;
  286. /* SPQ */
  287. struct qed_spq *p_spq;
  288. /* EQ */
  289. struct qed_eq *p_eq;
  290. /* Consolidate Q*/
  291. struct qed_consq *p_consq;
  292. /* Slow-Path definitions */
  293. struct tasklet_struct *sp_dpc;
  294. bool b_sp_dpc_enabled;
  295. struct qed_ptt *p_main_ptt;
  296. struct qed_ptt *p_dpc_ptt;
  297. struct qed_sb_sp_info *p_sp_sb;
  298. struct qed_sb_attn_info *p_sb_attn;
  299. /* Protocol related */
  300. struct qed_pf_params pf_params;
  301. bool b_rdma_enabled_in_prs;
  302. u32 rdma_prs_search_reg;
  303. /* Array of sb_info of all status blocks */
  304. struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
  305. u16 num_sbs;
  306. struct qed_cxt_mngr *p_cxt_mngr;
  307. /* Flag indicating whether interrupts are enabled or not*/
  308. bool b_int_enabled;
  309. bool b_int_requested;
  310. /* True if the driver requests for the link */
  311. bool b_drv_link_init;
  312. struct qed_vf_iov *vf_iov_info;
  313. struct qed_pf_iov *pf_iov_info;
  314. struct qed_mcp_info *mcp_info;
  315. struct qed_dcbx_info *p_dcbx_info;
  316. struct qed_hw_cid_data *p_tx_cids;
  317. struct qed_hw_cid_data *p_rx_cids;
  318. struct qed_dmae_info dmae_info;
  319. /* QM init */
  320. struct qed_qm_info qm_info;
  321. struct qed_storm_stats storm_stats;
  322. /* Buffer for unzipping firmware data */
  323. void *unzip_buf;
  324. struct dbg_tools_data dbg_info;
  325. struct qed_simd_fp_handler simd_proto_handler[64];
  326. #ifdef CONFIG_QED_SRIOV
  327. struct workqueue_struct *iov_wq;
  328. struct delayed_work iov_task;
  329. unsigned long iov_task_flags;
  330. #endif
  331. struct z_stream_s *stream;
  332. };
  333. struct pci_params {
  334. int pm_cap;
  335. unsigned long mem_start;
  336. unsigned long mem_end;
  337. unsigned int irq;
  338. u8 pf_num;
  339. };
  340. struct qed_int_param {
  341. u32 int_mode;
  342. u8 num_vectors;
  343. u8 min_msix_cnt; /* for minimal functionality */
  344. };
  345. struct qed_int_params {
  346. struct qed_int_param in;
  347. struct qed_int_param out;
  348. struct msix_entry *msix_table;
  349. bool fp_initialized;
  350. u8 fp_msix_base;
  351. u8 fp_msix_cnt;
  352. };
  353. struct qed_dbg_feature {
  354. struct dentry *dentry;
  355. u8 *dump_buf;
  356. u32 buf_size;
  357. u32 dumped_dwords;
  358. };
  359. struct qed_dbg_params {
  360. struct qed_dbg_feature features[DBG_FEATURE_NUM];
  361. u8 engine_for_debug;
  362. bool print_data;
  363. };
  364. struct qed_dev {
  365. u32 dp_module;
  366. u8 dp_level;
  367. char name[NAME_SIZE];
  368. u8 type;
  369. #define QED_DEV_TYPE_BB (0 << 0)
  370. #define QED_DEV_TYPE_AH BIT(0)
  371. /* Translate type/revision combo into the proper conditions */
  372. #define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
  373. #define QED_IS_BB_A0(dev) (QED_IS_BB(dev) && \
  374. CHIP_REV_IS_A0(dev))
  375. #define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
  376. CHIP_REV_IS_B0(dev))
  377. #define QED_IS_AH(dev) ((dev)->type == QED_DEV_TYPE_AH)
  378. #define QED_IS_K2(dev) QED_IS_AH(dev)
  379. #define QED_GET_TYPE(dev) (QED_IS_BB_A0(dev) ? CHIP_BB_A0 : \
  380. QED_IS_BB_B0(dev) ? CHIP_BB_B0 : CHIP_K2)
  381. u16 vendor_id;
  382. u16 device_id;
  383. u16 chip_num;
  384. #define CHIP_NUM_MASK 0xffff
  385. #define CHIP_NUM_SHIFT 16
  386. u16 chip_rev;
  387. #define CHIP_REV_MASK 0xf
  388. #define CHIP_REV_SHIFT 12
  389. #define CHIP_REV_IS_A0(_cdev) (!(_cdev)->chip_rev)
  390. #define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
  391. u16 chip_metal;
  392. #define CHIP_METAL_MASK 0xff
  393. #define CHIP_METAL_SHIFT 4
  394. u16 chip_bond_id;
  395. #define CHIP_BOND_ID_MASK 0xf
  396. #define CHIP_BOND_ID_SHIFT 0
  397. u8 num_engines;
  398. u8 num_ports_in_engines;
  399. u8 num_funcs_in_port;
  400. u8 path_id;
  401. enum qed_mf_mode mf_mode;
  402. #define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
  403. #define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
  404. #define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
  405. int pcie_width;
  406. int pcie_speed;
  407. u8 ver_str[VER_SIZE];
  408. /* Add MF related configuration */
  409. u8 mcp_rev;
  410. u8 boot_mode;
  411. u8 wol;
  412. u32 int_mode;
  413. enum qed_coalescing_mode int_coalescing_mode;
  414. u16 rx_coalesce_usecs;
  415. u16 tx_coalesce_usecs;
  416. /* Start Bar offset of first hwfn */
  417. void __iomem *regview;
  418. void __iomem *doorbells;
  419. u64 db_phys_addr;
  420. unsigned long db_size;
  421. /* PCI */
  422. u8 cache_shift;
  423. /* Init */
  424. const struct iro *iro_arr;
  425. #define IRO (p_hwfn->cdev->iro_arr)
  426. /* HW functions */
  427. u8 num_hwfns;
  428. struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
  429. /* SRIOV */
  430. struct qed_hw_sriov_info *p_iov_info;
  431. #define IS_QED_SRIOV(cdev) (!!(cdev)->p_iov_info)
  432. unsigned long tunn_mode;
  433. bool b_is_vf;
  434. u32 drv_type;
  435. struct qed_eth_stats *reset_stats;
  436. struct qed_fw_data *fw_data;
  437. u32 mcp_nvm_resp;
  438. /* Linux specific here */
  439. struct qede_dev *edev;
  440. struct pci_dev *pdev;
  441. int msg_enable;
  442. struct pci_params pci_params;
  443. struct qed_int_params int_params;
  444. u8 protocol;
  445. #define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
  446. /* Callbacks to protocol driver */
  447. union {
  448. struct qed_common_cb_ops *common;
  449. struct qed_eth_cb_ops *eth;
  450. } protocol_ops;
  451. void *ops_cookie;
  452. struct qed_dbg_params dbg_params;
  453. const struct firmware *firmware;
  454. };
  455. #define NUM_OF_VFS(dev) MAX_NUM_VFS_BB
  456. #define NUM_OF_L2_QUEUES(dev) MAX_NUM_L2_QUEUES_BB
  457. #define NUM_OF_SBS(dev) MAX_SB_PER_PATH_BB
  458. #define NUM_OF_ENG_PFS(dev) MAX_NUM_PFS_BB
  459. /**
  460. * @brief qed_concrete_to_sw_fid - get the sw function id from
  461. * the concrete value.
  462. *
  463. * @param concrete_fid
  464. *
  465. * @return inline u8
  466. */
  467. static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
  468. u32 concrete_fid)
  469. {
  470. u8 vfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_VFID);
  471. u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
  472. u8 vf_valid = GET_FIELD(concrete_fid,
  473. PXP_CONCRETE_FID_VFVALID);
  474. u8 sw_fid;
  475. if (vf_valid)
  476. sw_fid = vfid + MAX_NUM_PFS;
  477. else
  478. sw_fid = pfid;
  479. return sw_fid;
  480. }
  481. #define PURE_LB_TC 8
  482. #define OOO_LB_TC 9
  483. int qed_configure_vport_wfq(struct qed_dev *cdev, u16 vp_id, u32 rate);
  484. void qed_configure_vp_wfq_on_link_change(struct qed_dev *cdev, u32 min_pf_rate);
  485. void qed_clean_wfq_db(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  486. #define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
  487. /* Other Linux specific common definitions */
  488. #define DP_NAME(cdev) ((cdev)->name)
  489. #define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
  490. (cdev->regview) + \
  491. (offset))
  492. #define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
  493. #define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
  494. #define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
  495. #define DOORBELL(cdev, db_addr, val) \
  496. writel((u32)val, (void __iomem *)((u8 __iomem *)\
  497. (cdev->doorbells) + (db_addr)))
  498. /* Prototypes */
  499. int qed_fill_dev_info(struct qed_dev *cdev,
  500. struct qed_dev_info *dev_info);
  501. void qed_link_update(struct qed_hwfn *hwfn);
  502. u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
  503. u32 input_len, u8 *input_buf,
  504. u32 max_size, u8 *unzip_buf);
  505. void qed_get_protocol_stats(struct qed_dev *cdev,
  506. enum qed_mcp_protocol_type type,
  507. union qed_mcp_protocol_stats *stats);
  508. int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
  509. #endif /* _QED_H */