qed.h 13 KB

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