qed.h 11 KB

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