qed.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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.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. enum qed_dev_cap {
  105. QED_DEV_CAP_ETH,
  106. };
  107. struct qed_hw_info {
  108. /* PCI personality */
  109. enum qed_pci_personality personality;
  110. /* Resource Allocation scheme results */
  111. u32 resc_start[QED_MAX_RESC];
  112. u32 resc_num[QED_MAX_RESC];
  113. u32 feat_num[QED_MAX_FEATURES];
  114. #define RESC_START(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_start[resc])
  115. #define RESC_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.resc_num[resc])
  116. #define FEAT_NUM(_p_hwfn, resc) ((_p_hwfn)->hw_info.feat_num[resc])
  117. u8 num_tc;
  118. u8 offload_tc;
  119. u8 non_offload_tc;
  120. u32 concrete_fid;
  121. u16 opaque_fid;
  122. u16 ovlan;
  123. u32 part_num[4];
  124. unsigned char hw_mac_addr[ETH_ALEN];
  125. struct qed_igu_info *p_igu_info;
  126. u32 port_mode;
  127. u32 hw_mode;
  128. unsigned long device_capabilities;
  129. };
  130. struct qed_hw_cid_data {
  131. u32 cid;
  132. bool b_cid_allocated;
  133. /* Additional identifiers */
  134. u16 opaque_fid;
  135. u8 vport_id;
  136. };
  137. /* maximun size of read/write commands (HW limit) */
  138. #define DMAE_MAX_RW_SIZE 0x2000
  139. struct qed_dmae_info {
  140. /* Mutex for synchronizing access to functions */
  141. struct mutex mutex;
  142. u8 channel;
  143. dma_addr_t completion_word_phys_addr;
  144. /* The memory location where the DMAE writes the completion
  145. * value when an operation is finished on this context.
  146. */
  147. u32 *p_completion_word;
  148. dma_addr_t intermediate_buffer_phys_addr;
  149. /* An intermediate buffer for DMAE operations that use virtual
  150. * addresses - data is DMA'd to/from this buffer and then
  151. * memcpy'd to/from the virtual address
  152. */
  153. u32 *p_intermediate_buffer;
  154. dma_addr_t dmae_cmd_phys_addr;
  155. struct dmae_cmd *p_dmae_cmd;
  156. };
  157. struct qed_qm_info {
  158. struct init_qm_pq_params *qm_pq_params;
  159. struct init_qm_vport_params *qm_vport_params;
  160. struct init_qm_port_params *qm_port_params;
  161. u16 start_pq;
  162. u8 start_vport;
  163. u8 pure_lb_pq;
  164. u8 offload_pq;
  165. u8 pure_ack_pq;
  166. u8 vf_queues_offset;
  167. u16 num_pqs;
  168. u16 num_vf_pqs;
  169. u8 num_vports;
  170. u8 max_phys_tcs_per_port;
  171. bool pf_rl_en;
  172. bool pf_wfq_en;
  173. bool vport_rl_en;
  174. bool vport_wfq_en;
  175. u8 pf_wfq;
  176. u32 pf_rl;
  177. };
  178. struct storm_stats {
  179. u32 address;
  180. u32 len;
  181. };
  182. struct qed_storm_stats {
  183. struct storm_stats mstats;
  184. struct storm_stats pstats;
  185. struct storm_stats tstats;
  186. struct storm_stats ustats;
  187. };
  188. struct qed_fw_data {
  189. struct fw_ver_info *fw_ver_info;
  190. const u8 *modes_tree_buf;
  191. union init_op *init_ops;
  192. const u32 *arr_data;
  193. u32 init_ops_size;
  194. };
  195. struct qed_simd_fp_handler {
  196. void *token;
  197. void (*func)(void *);
  198. };
  199. struct qed_hwfn {
  200. struct qed_dev *cdev;
  201. u8 my_id; /* ID inside the PF */
  202. #define IS_LEAD_HWFN(edev) (!((edev)->my_id))
  203. u8 rel_pf_id; /* Relative to engine*/
  204. u8 abs_pf_id;
  205. #define QED_PATH_ID(_p_hwfn) ((_p_hwfn)->abs_pf_id & 1)
  206. u8 port_id;
  207. bool b_active;
  208. u32 dp_module;
  209. u8 dp_level;
  210. char name[NAME_SIZE];
  211. bool first_on_engine;
  212. bool hw_init_done;
  213. /* BAR access */
  214. void __iomem *regview;
  215. void __iomem *doorbells;
  216. u64 db_phys_addr;
  217. unsigned long db_size;
  218. /* PTT pool */
  219. struct qed_ptt_pool *p_ptt_pool;
  220. /* HW info */
  221. struct qed_hw_info hw_info;
  222. /* rt_array (for init-tool) */
  223. struct qed_rt_data rt_data;
  224. /* SPQ */
  225. struct qed_spq *p_spq;
  226. /* EQ */
  227. struct qed_eq *p_eq;
  228. /* Consolidate Q*/
  229. struct qed_consq *p_consq;
  230. /* Slow-Path definitions */
  231. struct tasklet_struct *sp_dpc;
  232. bool b_sp_dpc_enabled;
  233. struct qed_ptt *p_main_ptt;
  234. struct qed_ptt *p_dpc_ptt;
  235. struct qed_sb_sp_info *p_sp_sb;
  236. struct qed_sb_attn_info *p_sb_attn;
  237. /* Protocol related */
  238. struct qed_pf_params pf_params;
  239. /* Array of sb_info of all status blocks */
  240. struct qed_sb_info *sbs_info[MAX_SB_PER_PF_MIMD];
  241. u16 num_sbs;
  242. struct qed_cxt_mngr *p_cxt_mngr;
  243. /* Flag indicating whether interrupts are enabled or not*/
  244. bool b_int_enabled;
  245. bool b_int_requested;
  246. /* True if the driver requests for the link */
  247. bool b_drv_link_init;
  248. struct qed_mcp_info *mcp_info;
  249. struct qed_hw_cid_data *p_tx_cids;
  250. struct qed_hw_cid_data *p_rx_cids;
  251. struct qed_dmae_info dmae_info;
  252. /* QM init */
  253. struct qed_qm_info qm_info;
  254. struct qed_storm_stats storm_stats;
  255. /* Buffer for unzipping firmware data */
  256. void *unzip_buf;
  257. struct qed_simd_fp_handler simd_proto_handler[64];
  258. struct z_stream_s *stream;
  259. };
  260. struct pci_params {
  261. int pm_cap;
  262. unsigned long mem_start;
  263. unsigned long mem_end;
  264. unsigned int irq;
  265. u8 pf_num;
  266. };
  267. struct qed_int_param {
  268. u32 int_mode;
  269. u8 num_vectors;
  270. u8 min_msix_cnt; /* for minimal functionality */
  271. };
  272. struct qed_int_params {
  273. struct qed_int_param in;
  274. struct qed_int_param out;
  275. struct msix_entry *msix_table;
  276. bool fp_initialized;
  277. u8 fp_msix_base;
  278. u8 fp_msix_cnt;
  279. };
  280. struct qed_dev {
  281. u32 dp_module;
  282. u8 dp_level;
  283. char name[NAME_SIZE];
  284. u8 type;
  285. #define QED_DEV_TYPE_BB (0 << 0)
  286. #define QED_DEV_TYPE_AH BIT(0)
  287. /* Translate type/revision combo into the proper conditions */
  288. #define QED_IS_BB(dev) ((dev)->type == QED_DEV_TYPE_BB)
  289. #define QED_IS_BB_A0(dev) (QED_IS_BB(dev) && \
  290. CHIP_REV_IS_A0(dev))
  291. #define QED_IS_BB_B0(dev) (QED_IS_BB(dev) && \
  292. CHIP_REV_IS_B0(dev))
  293. #define QED_GET_TYPE(dev) (QED_IS_BB_A0(dev) ? CHIP_BB_A0 : \
  294. QED_IS_BB_B0(dev) ? CHIP_BB_B0 : CHIP_K2)
  295. u16 vendor_id;
  296. u16 device_id;
  297. u16 chip_num;
  298. #define CHIP_NUM_MASK 0xffff
  299. #define CHIP_NUM_SHIFT 16
  300. u16 chip_rev;
  301. #define CHIP_REV_MASK 0xf
  302. #define CHIP_REV_SHIFT 12
  303. #define CHIP_REV_IS_A0(_cdev) (!(_cdev)->chip_rev)
  304. #define CHIP_REV_IS_B0(_cdev) ((_cdev)->chip_rev == 1)
  305. u16 chip_metal;
  306. #define CHIP_METAL_MASK 0xff
  307. #define CHIP_METAL_SHIFT 4
  308. u16 chip_bond_id;
  309. #define CHIP_BOND_ID_MASK 0xf
  310. #define CHIP_BOND_ID_SHIFT 0
  311. u8 num_engines;
  312. u8 num_ports_in_engines;
  313. u8 num_funcs_in_port;
  314. u8 path_id;
  315. enum qed_mf_mode mf_mode;
  316. #define IS_MF_DEFAULT(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_DEFAULT)
  317. #define IS_MF_SI(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_NPAR)
  318. #define IS_MF_SD(_p_hwfn) (((_p_hwfn)->cdev)->mf_mode == QED_MF_OVLAN)
  319. int pcie_width;
  320. int pcie_speed;
  321. u8 ver_str[VER_SIZE];
  322. /* Add MF related configuration */
  323. u8 mcp_rev;
  324. u8 boot_mode;
  325. u8 wol;
  326. u32 int_mode;
  327. enum qed_coalescing_mode int_coalescing_mode;
  328. u8 rx_coalesce_usecs;
  329. u8 tx_coalesce_usecs;
  330. /* Start Bar offset of first hwfn */
  331. void __iomem *regview;
  332. void __iomem *doorbells;
  333. u64 db_phys_addr;
  334. unsigned long db_size;
  335. /* PCI */
  336. u8 cache_shift;
  337. /* Init */
  338. const struct iro *iro_arr;
  339. #define IRO (p_hwfn->cdev->iro_arr)
  340. /* HW functions */
  341. u8 num_hwfns;
  342. struct qed_hwfn hwfns[MAX_HWFNS_PER_DEVICE];
  343. u32 drv_type;
  344. struct qed_eth_stats *reset_stats;
  345. struct qed_fw_data *fw_data;
  346. u32 mcp_nvm_resp;
  347. /* Linux specific here */
  348. struct qede_dev *edev;
  349. struct pci_dev *pdev;
  350. int msg_enable;
  351. struct pci_params pci_params;
  352. struct qed_int_params int_params;
  353. u8 protocol;
  354. #define IS_QED_ETH_IF(cdev) ((cdev)->protocol == QED_PROTOCOL_ETH)
  355. /* Callbacks to protocol driver */
  356. union {
  357. struct qed_common_cb_ops *common;
  358. struct qed_eth_cb_ops *eth;
  359. } protocol_ops;
  360. void *ops_cookie;
  361. const struct firmware *firmware;
  362. };
  363. #define NUM_OF_SBS(dev) MAX_SB_PER_PATH_BB
  364. #define NUM_OF_ENG_PFS(dev) MAX_NUM_PFS_BB
  365. /**
  366. * @brief qed_concrete_to_sw_fid - get the sw function id from
  367. * the concrete value.
  368. *
  369. * @param concrete_fid
  370. *
  371. * @return inline u8
  372. */
  373. static inline u8 qed_concrete_to_sw_fid(struct qed_dev *cdev,
  374. u32 concrete_fid)
  375. {
  376. u8 pfid = GET_FIELD(concrete_fid, PXP_CONCRETE_FID_PFID);
  377. return pfid;
  378. }
  379. #define PURE_LB_TC 8
  380. #define QED_LEADING_HWFN(dev) (&dev->hwfns[0])
  381. /* Other Linux specific common definitions */
  382. #define DP_NAME(cdev) ((cdev)->name)
  383. #define REG_ADDR(cdev, offset) (void __iomem *)((u8 __iomem *)\
  384. (cdev->regview) + \
  385. (offset))
  386. #define REG_RD(cdev, offset) readl(REG_ADDR(cdev, offset))
  387. #define REG_WR(cdev, offset, val) writel((u32)val, REG_ADDR(cdev, offset))
  388. #define REG_WR16(cdev, offset, val) writew((u16)val, REG_ADDR(cdev, offset))
  389. #define DOORBELL(cdev, db_addr, val) \
  390. writel((u32)val, (void __iomem *)((u8 __iomem *)\
  391. (cdev->doorbells) + (db_addr)))
  392. /* Prototypes */
  393. int qed_fill_dev_info(struct qed_dev *cdev,
  394. struct qed_dev_info *dev_info);
  395. void qed_link_update(struct qed_hwfn *hwfn);
  396. u32 qed_unzip_data(struct qed_hwfn *p_hwfn,
  397. u32 input_len, u8 *input_buf,
  398. u32 max_size, u8 *unzip_buf);
  399. int qed_slowpath_irq_req(struct qed_hwfn *hwfn);
  400. #define QED_ETH_INTERFACE_VERSION 300
  401. #endif /* _QED_H */