0001
0002
0003 #ifndef IRDMA_MAIN_H
0004 #define IRDMA_MAIN_H
0005
0006 #include <linux/ip.h>
0007 #include <linux/tcp.h>
0008 #include <linux/if_vlan.h>
0009 #include <net/addrconf.h>
0010 #include <net/netevent.h>
0011 #include <net/tcp.h>
0012 #include <net/ip6_route.h>
0013 #include <net/flow.h>
0014 #include <net/secure_seq.h>
0015 #include <linux/netdevice.h>
0016 #include <linux/etherdevice.h>
0017 #include <linux/inetdevice.h>
0018 #include <linux/spinlock.h>
0019 #include <linux/kernel.h>
0020 #include <linux/delay.h>
0021 #include <linux/pci.h>
0022 #include <linux/dma-mapping.h>
0023 #include <linux/workqueue.h>
0024 #include <linux/slab.h>
0025 #include <linux/io.h>
0026 #include <linux/crc32c.h>
0027 #include <linux/kthread.h>
0028 #ifndef CONFIG_64BIT
0029 #include <linux/io-64-nonatomic-lo-hi.h>
0030 #endif
0031 #include <linux/auxiliary_bus.h>
0032 #include <linux/net/intel/iidc.h>
0033 #include <crypto/hash.h>
0034 #include <rdma/ib_smi.h>
0035 #include <rdma/ib_verbs.h>
0036 #include <rdma/ib_pack.h>
0037 #include <rdma/rdma_cm.h>
0038 #include <rdma/iw_cm.h>
0039 #include <rdma/ib_user_verbs.h>
0040 #include <rdma/ib_umem.h>
0041 #include <rdma/ib_cache.h>
0042 #include <rdma/uverbs_ioctl.h>
0043 #include "osdep.h"
0044 #include "defs.h"
0045 #include "hmc.h"
0046 #include "type.h"
0047 #include "ws.h"
0048 #include "protos.h"
0049 #include "pble.h"
0050 #include "cm.h"
0051 #include <rdma/irdma-abi.h>
0052 #include "verbs.h"
0053 #include "user.h"
0054 #include "puda.h"
0055
0056 extern struct auxiliary_driver i40iw_auxiliary_drv;
0057
0058 #define IRDMA_FW_VER_DEFAULT 2
0059 #define IRDMA_HW_VER 2
0060
0061 #define IRDMA_ARP_ADD 1
0062 #define IRDMA_ARP_DELETE 2
0063 #define IRDMA_ARP_RESOLVE 3
0064
0065 #define IRDMA_MACIP_ADD 1
0066 #define IRDMA_MACIP_DELETE 2
0067
0068 #define IW_CCQ_SIZE (IRDMA_CQP_SW_SQSIZE_2048 + 1)
0069 #define IW_CEQ_SIZE 2048
0070 #define IW_AEQ_SIZE 2048
0071
0072 #define RX_BUF_SIZE (1536 + 8)
0073 #define IW_REG0_SIZE (4 * 1024)
0074 #define IW_TX_TIMEOUT (6 * HZ)
0075 #define IW_FIRST_QPN 1
0076
0077 #define IW_SW_CONTEXT_ALIGN 1024
0078
0079 #define MAX_DPC_ITERATIONS 128
0080
0081 #define IRDMA_EVENT_TIMEOUT 50000
0082 #define IRDMA_VCHNL_EVENT_TIMEOUT 100000
0083 #define IRDMA_RST_TIMEOUT_HZ 4
0084
0085 #define IRDMA_NO_QSET 0xffff
0086
0087 #define IW_CFG_FPM_QP_COUNT 32768
0088 #define IRDMA_MAX_PAGES_PER_FMR 262144
0089 #define IRDMA_MIN_PAGES_PER_FMR 1
0090 #define IRDMA_CQP_COMPL_RQ_WQE_FLUSHED 2
0091 #define IRDMA_CQP_COMPL_SQ_WQE_FLUSHED 3
0092
0093 #define IRDMA_Q_TYPE_PE_AEQ 0x80
0094 #define IRDMA_Q_INVALID_IDX 0xffff
0095 #define IRDMA_REM_ENDPOINT_TRK_QPID 3
0096
0097 #define IRDMA_DRV_OPT_ENA_MPA_VER_0 0x00000001
0098 #define IRDMA_DRV_OPT_DISABLE_MPA_CRC 0x00000002
0099 #define IRDMA_DRV_OPT_DISABLE_FIRST_WRITE 0x00000004
0100 #define IRDMA_DRV_OPT_DISABLE_INTF 0x00000008
0101 #define IRDMA_DRV_OPT_ENA_MSI 0x00000010
0102 #define IRDMA_DRV_OPT_DUAL_LOGICAL_PORT 0x00000020
0103 #define IRDMA_DRV_OPT_NO_INLINE_DATA 0x00000080
0104 #define IRDMA_DRV_OPT_DISABLE_INT_MOD 0x00000100
0105 #define IRDMA_DRV_OPT_DISABLE_VIRT_WQ 0x00000200
0106 #define IRDMA_DRV_OPT_ENA_PAU 0x00000400
0107 #define IRDMA_DRV_OPT_MCAST_LOGPORT_MAP 0x00000800
0108
0109 #define IW_HMC_OBJ_TYPE_NUM ARRAY_SIZE(iw_hmc_obj_types)
0110 #define IRDMA_ROCE_CWND_DEFAULT 0x400
0111 #define IRDMA_ROCE_ACKCREDS_DEFAULT 0x1E
0112
0113 #define IRDMA_FLUSH_SQ BIT(0)
0114 #define IRDMA_FLUSH_RQ BIT(1)
0115 #define IRDMA_REFLUSH BIT(2)
0116 #define IRDMA_FLUSH_WAIT BIT(3)
0117
0118 enum init_completion_state {
0119 INVALID_STATE = 0,
0120 INITIAL_STATE,
0121 CQP_CREATED,
0122 HMC_OBJS_CREATED,
0123 HW_RSRC_INITIALIZED,
0124 CCQ_CREATED,
0125 CEQ0_CREATED,
0126 ILQ_CREATED,
0127 IEQ_CREATED,
0128 CEQS_CREATED,
0129 PBLE_CHUNK_MEM,
0130 AEQ_CREATED,
0131 IP_ADDR_REGISTERED,
0132 };
0133
0134 struct irdma_rsrc_limits {
0135 u32 qplimit;
0136 u32 mrlimit;
0137 u32 cqlimit;
0138 };
0139
0140 struct irdma_cqp_err_info {
0141 u16 maj;
0142 u16 min;
0143 const char *desc;
0144 };
0145
0146 struct irdma_cqp_compl_info {
0147 u32 op_ret_val;
0148 u16 maj_err_code;
0149 u16 min_err_code;
0150 bool error;
0151 u8 op_code;
0152 };
0153
0154 struct irdma_cqp_request {
0155 struct cqp_cmds_info info;
0156 wait_queue_head_t waitq;
0157 struct list_head list;
0158 refcount_t refcnt;
0159 void (*callback_fcn)(struct irdma_cqp_request *cqp_request);
0160 void *param;
0161 struct irdma_cqp_compl_info compl_info;
0162 bool waiting:1;
0163 bool request_done:1;
0164 bool dynamic:1;
0165 };
0166
0167 struct irdma_cqp {
0168 struct irdma_sc_cqp sc_cqp;
0169 spinlock_t req_lock;
0170 spinlock_t compl_lock;
0171 wait_queue_head_t waitq;
0172 wait_queue_head_t remove_wq;
0173 struct irdma_dma_mem sq;
0174 struct irdma_dma_mem host_ctx;
0175 u64 *scratch_array;
0176 struct irdma_cqp_request *cqp_requests;
0177 struct list_head cqp_avail_reqs;
0178 struct list_head cqp_pending_reqs;
0179 };
0180
0181 struct irdma_ccq {
0182 struct irdma_sc_cq sc_cq;
0183 struct irdma_dma_mem mem_cq;
0184 struct irdma_dma_mem shadow_area;
0185 };
0186
0187 struct irdma_ceq {
0188 struct irdma_sc_ceq sc_ceq;
0189 struct irdma_dma_mem mem;
0190 u32 irq;
0191 u32 msix_idx;
0192 struct irdma_pci_f *rf;
0193 struct tasklet_struct dpc_tasklet;
0194 spinlock_t ce_lock;
0195 };
0196
0197 struct irdma_aeq {
0198 struct irdma_sc_aeq sc_aeq;
0199 struct irdma_dma_mem mem;
0200 struct irdma_pble_alloc palloc;
0201 bool virtual_map;
0202 };
0203
0204 struct irdma_arp_entry {
0205 u32 ip_addr[4];
0206 u8 mac_addr[ETH_ALEN];
0207 };
0208
0209 struct irdma_msix_vector {
0210 u32 idx;
0211 u32 irq;
0212 u32 cpu_affinity;
0213 u32 ceq_id;
0214 cpumask_t mask;
0215 };
0216
0217 struct irdma_mc_table_info {
0218 u32 mgn;
0219 u32 dest_ip[4];
0220 bool lan_fwd:1;
0221 bool ipv4_valid:1;
0222 };
0223
0224 struct mc_table_list {
0225 struct list_head list;
0226 struct irdma_mc_table_info mc_info;
0227 struct irdma_mcast_grp_info mc_grp_ctx;
0228 };
0229
0230 struct irdma_qv_info {
0231 u32 v_idx;
0232 u16 ceq_idx;
0233 u16 aeq_idx;
0234 u8 itr_idx;
0235 };
0236
0237 struct irdma_qvlist_info {
0238 u32 num_vectors;
0239 struct irdma_qv_info qv_info[1];
0240 };
0241
0242 struct irdma_gen_ops {
0243 void (*request_reset)(struct irdma_pci_f *rf);
0244 int (*register_qset)(struct irdma_sc_vsi *vsi,
0245 struct irdma_ws_node *tc_node);
0246 void (*unregister_qset)(struct irdma_sc_vsi *vsi,
0247 struct irdma_ws_node *tc_node);
0248 };
0249
0250 struct irdma_pci_f {
0251 bool reset:1;
0252 bool rsrc_created:1;
0253 bool msix_shared:1;
0254 u8 rsrc_profile;
0255 u8 *hmc_info_mem;
0256 u8 *mem_rsrc;
0257 u8 rdma_ver;
0258 u8 rst_to;
0259 u8 pf_id;
0260 enum irdma_protocol_used protocol_used;
0261 u32 sd_type;
0262 u32 msix_count;
0263 u32 max_mr;
0264 u32 max_qp;
0265 u32 max_cq;
0266 u32 max_ah;
0267 u32 next_ah;
0268 u32 max_mcg;
0269 u32 next_mcg;
0270 u32 max_pd;
0271 u32 next_qp;
0272 u32 next_cq;
0273 u32 next_pd;
0274 u32 max_mr_size;
0275 u32 max_cqe;
0276 u32 mr_stagmask;
0277 u32 used_pds;
0278 u32 used_cqs;
0279 u32 used_mrs;
0280 u32 used_qps;
0281 u32 arp_table_size;
0282 u32 next_arp_index;
0283 u32 ceqs_count;
0284 u32 next_ws_node_id;
0285 u32 max_ws_node_id;
0286 u32 limits_sel;
0287 unsigned long *allocated_ws_nodes;
0288 unsigned long *allocated_qps;
0289 unsigned long *allocated_cqs;
0290 unsigned long *allocated_mrs;
0291 unsigned long *allocated_pds;
0292 unsigned long *allocated_mcgs;
0293 unsigned long *allocated_ahs;
0294 unsigned long *allocated_arps;
0295 enum init_completion_state init_state;
0296 struct irdma_sc_dev sc_dev;
0297 struct pci_dev *pcidev;
0298 void *cdev;
0299 struct irdma_hw hw;
0300 struct irdma_cqp cqp;
0301 struct irdma_ccq ccq;
0302 struct irdma_aeq aeq;
0303 struct irdma_ceq *ceqlist;
0304 struct irdma_hmc_pble_rsrc *pble_rsrc;
0305 struct irdma_arp_entry *arp_table;
0306 spinlock_t arp_lock;
0307 spinlock_t rsrc_lock;
0308 spinlock_t qptable_lock;
0309 struct irdma_qp **qp_table;
0310 spinlock_t qh_list_lock;
0311 struct mc_table_list mc_qht_list;
0312 struct irdma_msix_vector *iw_msixtbl;
0313 struct irdma_qvlist_info *iw_qvlist;
0314 struct tasklet_struct dpc_tasklet;
0315 struct msix_entry *msix_entries;
0316 struct irdma_dma_mem obj_mem;
0317 struct irdma_dma_mem obj_next;
0318 atomic_t vchnl_msgs;
0319 wait_queue_head_t vchnl_waitq;
0320 struct workqueue_struct *cqp_cmpl_wq;
0321 struct work_struct cqp_cmpl_work;
0322 struct irdma_sc_vsi default_vsi;
0323 void *back_fcn;
0324 struct irdma_gen_ops gen_ops;
0325 struct irdma_device *iwdev;
0326 };
0327
0328 struct irdma_device {
0329 struct ib_device ibdev;
0330 struct irdma_pci_f *rf;
0331 struct net_device *netdev;
0332 struct workqueue_struct *cleanup_wq;
0333 struct irdma_sc_vsi vsi;
0334 struct irdma_cm_core cm_core;
0335 DECLARE_HASHTABLE(ah_hash_tbl, 8);
0336 struct mutex ah_tbl_lock;
0337 u32 roce_cwnd;
0338 u32 roce_ackcreds;
0339 u32 vendor_id;
0340 u32 vendor_part_id;
0341 u32 push_mode;
0342 u32 rcv_wnd;
0343 u16 mac_ip_table_idx;
0344 u16 vsi_num;
0345 u8 rcv_wscale;
0346 u8 iw_status;
0347 bool roce_mode:1;
0348 bool roce_dcqcn_en:1;
0349 bool dcb_vlan_mode:1;
0350 bool iw_ooo:1;
0351 enum init_completion_state init_state;
0352
0353 wait_queue_head_t suspend_wq;
0354 };
0355
0356 static inline struct irdma_device *to_iwdev(struct ib_device *ibdev)
0357 {
0358 return container_of(ibdev, struct irdma_device, ibdev);
0359 }
0360
0361 static inline struct irdma_ucontext *to_ucontext(struct ib_ucontext *ibucontext)
0362 {
0363 return container_of(ibucontext, struct irdma_ucontext, ibucontext);
0364 }
0365
0366 static inline struct irdma_user_mmap_entry *
0367 to_irdma_mmap_entry(struct rdma_user_mmap_entry *rdma_entry)
0368 {
0369 return container_of(rdma_entry, struct irdma_user_mmap_entry,
0370 rdma_entry);
0371 }
0372
0373 static inline struct irdma_pd *to_iwpd(struct ib_pd *ibpd)
0374 {
0375 return container_of(ibpd, struct irdma_pd, ibpd);
0376 }
0377
0378 static inline struct irdma_ah *to_iwah(struct ib_ah *ibah)
0379 {
0380 return container_of(ibah, struct irdma_ah, ibah);
0381 }
0382
0383 static inline struct irdma_mr *to_iwmr(struct ib_mr *ibmr)
0384 {
0385 return container_of(ibmr, struct irdma_mr, ibmr);
0386 }
0387
0388 static inline struct irdma_mr *to_iwmw(struct ib_mw *ibmw)
0389 {
0390 return container_of(ibmw, struct irdma_mr, ibmw);
0391 }
0392
0393 static inline struct irdma_cq *to_iwcq(struct ib_cq *ibcq)
0394 {
0395 return container_of(ibcq, struct irdma_cq, ibcq);
0396 }
0397
0398 static inline struct irdma_qp *to_iwqp(struct ib_qp *ibqp)
0399 {
0400 return container_of(ibqp, struct irdma_qp, ibqp);
0401 }
0402
0403 static inline struct irdma_pci_f *dev_to_rf(struct irdma_sc_dev *dev)
0404 {
0405 return container_of(dev, struct irdma_pci_f, sc_dev);
0406 }
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416 static inline int irdma_alloc_rsrc(struct irdma_pci_f *rf,
0417 unsigned long *rsrc_array, u32 max_rsrc,
0418 u32 *req_rsrc_num, u32 *next)
0419 {
0420 u32 rsrc_num;
0421 unsigned long flags;
0422
0423 spin_lock_irqsave(&rf->rsrc_lock, flags);
0424 rsrc_num = find_next_zero_bit(rsrc_array, max_rsrc, *next);
0425 if (rsrc_num >= max_rsrc) {
0426 rsrc_num = find_first_zero_bit(rsrc_array, max_rsrc);
0427 if (rsrc_num >= max_rsrc) {
0428 spin_unlock_irqrestore(&rf->rsrc_lock, flags);
0429 ibdev_dbg(&rf->iwdev->ibdev,
0430 "ERR: resource [%d] allocation failed\n",
0431 rsrc_num);
0432 return -EOVERFLOW;
0433 }
0434 }
0435 __set_bit(rsrc_num, rsrc_array);
0436 *next = rsrc_num + 1;
0437 if (*next == max_rsrc)
0438 *next = 0;
0439 *req_rsrc_num = rsrc_num;
0440 spin_unlock_irqrestore(&rf->rsrc_lock, flags);
0441
0442 return 0;
0443 }
0444
0445
0446
0447
0448
0449
0450
0451 static inline void irdma_free_rsrc(struct irdma_pci_f *rf,
0452 unsigned long *rsrc_array, u32 rsrc_num)
0453 {
0454 unsigned long flags;
0455
0456 spin_lock_irqsave(&rf->rsrc_lock, flags);
0457 __clear_bit(rsrc_num, rsrc_array);
0458 spin_unlock_irqrestore(&rf->rsrc_lock, flags);
0459 }
0460
0461 int irdma_ctrl_init_hw(struct irdma_pci_f *rf);
0462 void irdma_ctrl_deinit_hw(struct irdma_pci_f *rf);
0463 int irdma_rt_init_hw(struct irdma_device *iwdev,
0464 struct irdma_l2params *l2params);
0465 void irdma_rt_deinit_hw(struct irdma_device *iwdev);
0466 void irdma_qp_add_ref(struct ib_qp *ibqp);
0467 void irdma_qp_rem_ref(struct ib_qp *ibqp);
0468 void irdma_free_lsmm_rsrc(struct irdma_qp *iwqp);
0469 struct ib_qp *irdma_get_qp(struct ib_device *ibdev, int qpn);
0470 void irdma_flush_wqes(struct irdma_qp *iwqp, u32 flush_mask);
0471 void irdma_manage_arp_cache(struct irdma_pci_f *rf,
0472 const unsigned char *mac_addr,
0473 u32 *ip_addr, bool ipv4, u32 action);
0474 struct irdma_apbvt_entry *irdma_add_apbvt(struct irdma_device *iwdev, u16 port);
0475 void irdma_del_apbvt(struct irdma_device *iwdev,
0476 struct irdma_apbvt_entry *entry);
0477 struct irdma_cqp_request *irdma_alloc_and_get_cqp_request(struct irdma_cqp *cqp,
0478 bool wait);
0479 void irdma_free_cqp_request(struct irdma_cqp *cqp,
0480 struct irdma_cqp_request *cqp_request);
0481 void irdma_put_cqp_request(struct irdma_cqp *cqp,
0482 struct irdma_cqp_request *cqp_request);
0483 int irdma_alloc_local_mac_entry(struct irdma_pci_f *rf, u16 *mac_tbl_idx);
0484 int irdma_add_local_mac_entry(struct irdma_pci_f *rf, const u8 *mac_addr, u16 idx);
0485 void irdma_del_local_mac_entry(struct irdma_pci_f *rf, u16 idx);
0486
0487 u32 irdma_initialize_hw_rsrc(struct irdma_pci_f *rf);
0488 void irdma_port_ibevent(struct irdma_device *iwdev);
0489 void irdma_cm_disconn(struct irdma_qp *qp);
0490
0491 bool irdma_cqp_crit_err(struct irdma_sc_dev *dev, u8 cqp_cmd,
0492 u16 maj_err_code, u16 min_err_code);
0493 int irdma_handle_cqp_op(struct irdma_pci_f *rf,
0494 struct irdma_cqp_request *cqp_request);
0495
0496 int irdma_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
0497 struct ib_udata *udata);
0498 int irdma_modify_qp_roce(struct ib_qp *ibqp, struct ib_qp_attr *attr,
0499 int attr_mask, struct ib_udata *udata);
0500 void irdma_cq_wq_destroy(struct irdma_pci_f *rf, struct irdma_sc_cq *cq);
0501
0502 void irdma_cleanup_pending_cqp_op(struct irdma_pci_f *rf);
0503 int irdma_hw_modify_qp(struct irdma_device *iwdev, struct irdma_qp *iwqp,
0504 struct irdma_modify_qp_info *info, bool wait);
0505 int irdma_qp_suspend_resume(struct irdma_sc_qp *qp, bool suspend);
0506 int irdma_manage_qhash(struct irdma_device *iwdev, struct irdma_cm_info *cminfo,
0507 enum irdma_quad_entry_type etype,
0508 enum irdma_quad_hash_manage_type mtype, void *cmnode,
0509 bool wait);
0510 void irdma_receive_ilq(struct irdma_sc_vsi *vsi, struct irdma_puda_buf *rbuf);
0511 void irdma_free_sqbuf(struct irdma_sc_vsi *vsi, void *bufp);
0512 void irdma_free_qp_rsrc(struct irdma_qp *iwqp);
0513 int irdma_setup_cm_core(struct irdma_device *iwdev, u8 ver);
0514 void irdma_cleanup_cm_core(struct irdma_cm_core *cm_core);
0515 void irdma_next_iw_state(struct irdma_qp *iwqp, u8 state, u8 del_hash, u8 term,
0516 u8 term_len);
0517 int irdma_send_syn(struct irdma_cm_node *cm_node, u32 sendack);
0518 int irdma_send_reset(struct irdma_cm_node *cm_node);
0519 struct irdma_cm_node *irdma_find_node(struct irdma_cm_core *cm_core,
0520 u16 rem_port, u32 *rem_addr, u16 loc_port,
0521 u32 *loc_addr, u16 vlan_id);
0522 int irdma_hw_flush_wqes(struct irdma_pci_f *rf, struct irdma_sc_qp *qp,
0523 struct irdma_qp_flush_info *info, bool wait);
0524 void irdma_gen_ae(struct irdma_pci_f *rf, struct irdma_sc_qp *qp,
0525 struct irdma_gen_ae_info *info, bool wait);
0526 void irdma_copy_ip_ntohl(u32 *dst, __be32 *src);
0527 void irdma_copy_ip_htonl(__be32 *dst, u32 *src);
0528 u16 irdma_get_vlan_ipv4(u32 *addr);
0529 struct net_device *irdma_netdev_vlan_ipv6(u32 *addr, u16 *vlan_id, u8 *mac);
0530 struct ib_mr *irdma_reg_phys_mr(struct ib_pd *ib_pd, u64 addr, u64 size,
0531 int acc, u64 *iova_start);
0532 int irdma_upload_qp_context(struct irdma_qp *iwqp, bool freeze, bool raw);
0533 void irdma_cqp_ce_handler(struct irdma_pci_f *rf, struct irdma_sc_cq *cq);
0534 int irdma_ah_cqp_op(struct irdma_pci_f *rf, struct irdma_sc_ah *sc_ah, u8 cmd,
0535 bool wait,
0536 void (*callback_fcn)(struct irdma_cqp_request *cqp_request),
0537 void *cb_param);
0538 void irdma_gsi_ud_qp_ah_cb(struct irdma_cqp_request *cqp_request);
0539 bool irdma_cq_empty(struct irdma_cq *iwcq);
0540 int irdma_inetaddr_event(struct notifier_block *notifier, unsigned long event,
0541 void *ptr);
0542 int irdma_inet6addr_event(struct notifier_block *notifier, unsigned long event,
0543 void *ptr);
0544 int irdma_net_event(struct notifier_block *notifier, unsigned long event,
0545 void *ptr);
0546 int irdma_netdevice_event(struct notifier_block *notifier, unsigned long event,
0547 void *ptr);
0548 void irdma_add_ip(struct irdma_device *iwdev);
0549 void cqp_compl_worker(struct work_struct *work);
0550 #endif