Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus-2' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

Pull more rdma updates from Doug Ledford:
"This merge window was the first where Huawei had to try and coordinate
their patches between their net driver and their new roce driver
(similar to mlx4 and mlx5).

They didn't do horribly, but there were some issues (and we knew that
because they simply didn't know what to do in the beginning). As a
result, I had a set of patches that depended on some patches that
normally would have come to you via Dave's tree. Those patches have
been on netdev@ for a while, so I got Dave to give me his approval to
send them to you. As such, the other 29 patches I had behind them are
also now ready to go.

This catches the hns and hns-roce drivers up to current, and for
future patches we are working with them to get them up to speed on how
to do joint driver development so that they don't have these sorts of
cross tree dependency issues again. BTW, Dave gave me permission to
add his Acked-by: to the patches against the net tree, but I've had
this branch through 0day (but not linux-next since it was off by
itself) and I didn't want to rebase the series just to add Dave's ack
for the 8 patches in the net area.

Updates to the hns drivers:

- Small patch set for hns net driver that the roce patches depend on

- Various fixes to the hns-roce driver

- Add connection manager support to the hns-roce driver"

* tag 'for-linus-2' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma: (36 commits)
IB/hns: Fix for removal of redundant code
IB/hns: Delete the redundant lines in hns_roce_v1_m_qp()
IB/hns: Fix the bug when platform_get_resource() exec fail
IB/hns: Update the rq head when modify qp state
IB/hns: Cq has not been freed
IB/hns: Validate mtu when modified qp
IB/hns: Some items of qpc need to take user param
IB/hns: The Ack timeout need a lower limit value
IB/hns: Return bad wr while post send failed
IB/hns: Fix bug of memory leakage for registering user mr
IB/hns: Modify the init of iboe lock
IB/hns: Optimize code of aeq and ceq interrupt handle and fix the bug of qpn
IB/hns: Delete the sqp_start from the structure hns_roce_caps
IB/hns: Fix bug of clear hem
IB/hns: Remove unused parameter named qp_type
IB/hns: Simplify function of pd alloc and qp alloc
IB/hns: Fix bug of using uninit refcount and free
IB/hns: Remove parameters of resize cq
IB/hns: Remove unused parameters in some functions
IB/hns: Add node_guid definition to the bindings document
...

+504 -368
+2
Documentation/devicetree/bindings/infiniband/hisilicon-hns-roce.txt
··· 14 14 representing a ethernet device. 15 15 - dsaf-handle: phandle, specifies a reference to a node 16 16 representing a dsaf device. 17 + - node_guid: a number that uniquely identifies a device or component 17 18 - #address-cells: must be 2 18 19 - #size-cells: must be 2 19 20 Optional properties: ··· 33 32 dma-coherent; 34 33 eth-handle = <&eth2 &eth3 &eth4 &eth5 &eth6 &eth7>; 35 34 dsaf-handle = <&soc0_dsa>; 35 + node-guid = [00 9A CD 00 00 01 02 03]; 36 36 #address-cells = <2>; 37 37 #size-cells = <2>; 38 38 interrupt-parent = <&mbigen_dsa>;
+15 -8
drivers/infiniband/hw/hns/hns_roce_cq.c
··· 83 83 static int hns_roce_cq_alloc(struct hns_roce_dev *hr_dev, int nent, 84 84 struct hns_roce_mtt *hr_mtt, 85 85 struct hns_roce_uar *hr_uar, 86 - struct hns_roce_cq *hr_cq, int vector, 87 - int collapsed) 86 + struct hns_roce_cq *hr_cq, int vector) 88 87 { 89 88 struct hns_roce_cmd_mailbox *mailbox = NULL; 90 89 struct hns_roce_cq_table *cq_table = NULL; ··· 152 153 hr_cq->cons_index = 0; 153 154 hr_cq->uar = hr_uar; 154 155 156 + atomic_set(&hr_cq->refcount, 1); 157 + init_completion(&hr_cq->free); 158 + 155 159 return 0; 156 160 157 161 err_radix: ··· 193 191 194 192 /* Waiting interrupt process procedure carried out */ 195 193 synchronize_irq(hr_dev->eq_table.eq[hr_cq->vector].irq); 194 + 195 + /* wait for all interrupt processed */ 196 + if (atomic_dec_and_test(&hr_cq->refcount)) 197 + complete(&hr_cq->free); 198 + wait_for_completion(&hr_cq->free); 196 199 197 200 spin_lock_irq(&cq_table->lock); 198 201 radix_tree_delete(&cq_table->tree, hr_cq->cqn); ··· 307 300 308 301 cq_entries = roundup_pow_of_two((unsigned int)cq_entries); 309 302 hr_cq->ib_cq.cqe = cq_entries - 1; 310 - mutex_init(&hr_cq->resize_mutex); 311 303 spin_lock_init(&hr_cq->lock); 312 - hr_cq->hr_resize_buf = NULL; 313 - hr_cq->resize_umem = NULL; 314 304 315 305 if (context) { 316 306 if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd))) { ··· 342 338 } 343 339 344 340 /* Allocate cq index, fill cq_context */ 345 - ret = hns_roce_cq_alloc(hr_dev, cq_entries, &hr_cq->hr_buf.hr_mtt, 346 - uar, hr_cq, vector, 0); 341 + ret = hns_roce_cq_alloc(hr_dev, cq_entries, &hr_cq->hr_buf.hr_mtt, uar, 342 + hr_cq, vector); 347 343 if (ret) { 348 344 dev_err(dev, "Creat CQ .Failed to cq_alloc.\n"); 349 345 goto err_mtt; ··· 357 353 if (context) { 358 354 if (ib_copy_to_udata(udata, &hr_cq->cqn, sizeof(u64))) { 359 355 ret = -EFAULT; 360 - goto err_mtt; 356 + goto err_cqc; 361 357 } 362 358 } 363 359 364 360 return &hr_cq->ib_cq; 361 + 362 + err_cqc: 363 + hns_roce_free_cq(hr_dev, hr_cq); 365 364 366 365 err_mtt: 367 366 hns_roce_mtt_cleanup(hr_dev, &hr_cq->hr_buf.hr_mtt);
+6 -12
drivers/infiniband/hw/hns/hns_roce_device.h
··· 62 62 #define HNS_ROCE_AEQE_OF_VEC_NUM 1 63 63 64 64 /* 4G/4K = 1M */ 65 - #define HNS_ROCE_SL_SHIFT 29 65 + #define HNS_ROCE_SL_SHIFT 28 66 66 #define HNS_ROCE_TCLASS_SHIFT 20 67 67 #define HNS_ROCE_FLOW_LABLE_MASK 0xfffff 68 68 ··· 74 74 #define MR_TYPE_DMA 0x03 75 75 76 76 #define PKEY_ID 0xffff 77 + #define GUID_LEN 8 77 78 #define NODE_DESC_SIZE 64 79 + #define DB_REG_OFFSET 0x1000 78 80 79 81 #define SERV_TYPE_RC 0 80 82 #define SERV_TYPE_RD 1 ··· 284 282 struct hns_roce_mtt hr_mtt; 285 283 }; 286 284 287 - struct hns_roce_cq_resize { 288 - struct hns_roce_cq_buf hr_buf; 289 - int cqe; 290 - }; 291 - 292 285 struct hns_roce_cq { 293 286 struct ib_cq ib_cq; 294 287 struct hns_roce_cq_buf hr_buf; 295 - /* pointer to store information after resize*/ 296 - struct hns_roce_cq_resize *hr_resize_buf; 297 288 spinlock_t lock; 298 - struct mutex resize_mutex; 299 289 struct ib_umem *umem; 300 - struct ib_umem *resize_umem; 301 290 void (*comp)(struct hns_roce_cq *); 302 291 void (*event)(struct hns_roce_cq *, enum hns_roce_event); 303 292 ··· 401 408 u32 buff_size; 402 409 struct mutex mutex; 403 410 u8 port; 411 + u8 phy_port; 404 412 u8 sl; 405 413 u8 resp_depth; 406 414 u8 state; ··· 465 471 u32 max_rq_desc_sz; /* 64 */ 466 472 int max_qp_init_rdma; 467 473 int max_qp_dest_rdma; 468 - int sqp_start; 469 474 int num_cqs; 470 475 int max_cqes; 471 476 int reserved_cqs; ··· 505 512 void (*write_cqc)(struct hns_roce_dev *hr_dev, 506 513 struct hns_roce_cq *hr_cq, void *mb_buf, u64 *mtts, 507 514 dma_addr_t dma_handle, int nent, u32 vector); 515 + int (*clear_hem)(struct hns_roce_dev *hr_dev, 516 + struct hns_roce_hem_table *table, int obj); 508 517 int (*query_qp)(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, 509 518 int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr); 510 519 int (*modify_qp)(struct ib_qp *ibqp, const struct ib_qp_attr *attr, ··· 528 533 struct hns_roce_uar priv_uar; 529 534 const char *irq_names[HNS_ROCE_MAX_IRQ_NUM]; 530 535 spinlock_t sm_lock; 531 - spinlock_t cq_db_lock; 532 536 spinlock_t bt_cmd_lock; 533 537 struct hns_roce_ib_iboe iboe; 534 538
+71 -75
drivers/infiniband/hw/hns/hns_roce_eq.c
··· 66 66 { 67 67 struct device *dev = &hr_dev->pdev->dev; 68 68 69 - qpn = roce_get_field(aeqe->event.qp_event.qp, 70 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 71 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S); 72 69 dev_warn(dev, "Local Work Queue Catastrophic Error.\n"); 73 70 switch (roce_get_field(aeqe->asyn, HNS_ROCE_AEQE_U32_4_EVENT_SUB_TYPE_M, 74 71 HNS_ROCE_AEQE_U32_4_EVENT_SUB_TYPE_S)) { ··· 93 96 default: 94 97 break; 95 98 } 96 - 97 - hns_roce_qp_event(hr_dev, roce_get_field(aeqe->event.qp_event.qp, 98 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 99 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S), 100 - roce_get_field(aeqe->asyn, 101 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 102 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)); 103 99 } 104 100 105 101 static void hns_roce_local_wq_access_err_handle(struct hns_roce_dev *hr_dev, ··· 101 111 { 102 112 struct device *dev = &hr_dev->pdev->dev; 103 113 104 - qpn = roce_get_field(aeqe->event.qp_event.qp, 105 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 106 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S); 107 114 dev_warn(dev, "Local Access Violation Work Queue Error.\n"); 108 115 switch (roce_get_field(aeqe->asyn, HNS_ROCE_AEQE_U32_4_EVENT_SUB_TYPE_M, 109 116 HNS_ROCE_AEQE_U32_4_EVENT_SUB_TYPE_S)) { ··· 128 141 default: 129 142 break; 130 143 } 144 + } 131 145 132 - hns_roce_qp_event(hr_dev, roce_get_field(aeqe->event.qp_event.qp, 133 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 134 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S), 135 - roce_get_field(aeqe->asyn, 136 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 137 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)); 146 + static void hns_roce_qp_err_handle(struct hns_roce_dev *hr_dev, 147 + struct hns_roce_aeqe *aeqe, 148 + int event_type) 149 + { 150 + struct device *dev = &hr_dev->pdev->dev; 151 + int phy_port; 152 + int qpn; 153 + 154 + qpn = roce_get_field(aeqe->event.qp_event.qp, 155 + HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 156 + HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S); 157 + phy_port = roce_get_field(aeqe->event.qp_event.qp, 158 + HNS_ROCE_AEQE_EVENT_QP_EVENT_PORT_NUM_M, 159 + HNS_ROCE_AEQE_EVENT_QP_EVENT_PORT_NUM_S); 160 + if (qpn <= 1) 161 + qpn = HNS_ROCE_MAX_PORTS * qpn + phy_port; 162 + 163 + switch (event_type) { 164 + case HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR: 165 + dev_warn(dev, "Invalid Req Local Work Queue Error.\n" 166 + "QP %d, phy_port %d.\n", qpn, phy_port); 167 + break; 168 + case HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR: 169 + hns_roce_wq_catas_err_handle(hr_dev, aeqe, qpn); 170 + break; 171 + case HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR: 172 + hns_roce_local_wq_access_err_handle(hr_dev, aeqe, qpn); 173 + break; 174 + default: 175 + break; 176 + } 177 + 178 + hns_roce_qp_event(hr_dev, qpn, event_type); 179 + } 180 + 181 + static void hns_roce_cq_err_handle(struct hns_roce_dev *hr_dev, 182 + struct hns_roce_aeqe *aeqe, 183 + int event_type) 184 + { 185 + struct device *dev = &hr_dev->pdev->dev; 186 + u32 cqn; 187 + 188 + cqn = le32_to_cpu(roce_get_field(aeqe->event.cq_event.cq, 189 + HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M, 190 + HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)); 191 + 192 + switch (event_type) { 193 + case HNS_ROCE_EVENT_TYPE_CQ_ACCESS_ERROR: 194 + dev_warn(dev, "CQ 0x%x access err.\n", cqn); 195 + break; 196 + case HNS_ROCE_EVENT_TYPE_CQ_OVERFLOW: 197 + dev_warn(dev, "CQ 0x%x overflow\n", cqn); 198 + break; 199 + case HNS_ROCE_EVENT_TYPE_CQ_ID_INVALID: 200 + dev_warn(dev, "CQ 0x%x ID invalid.\n", cqn); 201 + break; 202 + default: 203 + break; 204 + } 205 + 206 + hns_roce_cq_event(hr_dev, cqn, event_type); 138 207 } 139 208 140 209 static void hns_roce_db_overflow_handle(struct hns_roce_dev *hr_dev, ··· 228 185 struct device *dev = &hr_dev->pdev->dev; 229 186 struct hns_roce_aeqe *aeqe; 230 187 int aeqes_found = 0; 231 - int qpn = 0; 188 + int event_type; 232 189 233 190 while ((aeqe = next_aeqe_sw(eq))) { 234 191 dev_dbg(dev, "aeqe = %p, aeqe->asyn.event_type = 0x%lx\n", aeqe, ··· 238 195 /* Memory barrier */ 239 196 rmb(); 240 197 241 - switch (roce_get_field(aeqe->asyn, 242 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 243 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)) { 198 + event_type = roce_get_field(aeqe->asyn, 199 + HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 200 + HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S); 201 + switch (event_type) { 244 202 case HNS_ROCE_EVENT_TYPE_PATH_MIG: 245 203 dev_warn(dev, "PATH MIG not supported\n"); 246 204 break; ··· 255 211 dev_warn(dev, "PATH MIG failed\n"); 256 212 break; 257 213 case HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR: 258 - dev_warn(dev, "qpn = 0x%lx\n", 259 - roce_get_field(aeqe->event.qp_event.qp, 260 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 261 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S)); 262 - hns_roce_qp_event(hr_dev, 263 - roce_get_field(aeqe->event.qp_event.qp, 264 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M, 265 - HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S), 266 - roce_get_field(aeqe->asyn, 267 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 268 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)); 269 - break; 270 214 case HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR: 271 - hns_roce_wq_catas_err_handle(hr_dev, aeqe, qpn); 272 - break; 273 215 case HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR: 274 - hns_roce_local_wq_access_err_handle(hr_dev, aeqe, qpn); 216 + hns_roce_qp_err_handle(hr_dev, aeqe, event_type); 275 217 break; 276 218 case HNS_ROCE_EVENT_TYPE_SRQ_LIMIT_REACH: 277 219 case HNS_ROCE_EVENT_TYPE_SRQ_CATAS_ERROR: ··· 265 235 dev_warn(dev, "SRQ not support!\n"); 266 236 break; 267 237 case HNS_ROCE_EVENT_TYPE_CQ_ACCESS_ERROR: 268 - dev_warn(dev, "CQ 0x%lx access err.\n", 269 - roce_get_field(aeqe->event.cq_event.cq, 270 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M, 271 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)); 272 - hns_roce_cq_event(hr_dev, 273 - le32_to_cpu(roce_get_field(aeqe->event.cq_event.cq, 274 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M, 275 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)), 276 - roce_get_field(aeqe->asyn, 277 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 278 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)); 279 - break; 280 238 case HNS_ROCE_EVENT_TYPE_CQ_OVERFLOW: 281 - dev_warn(dev, "CQ 0x%lx overflow\n", 282 - roce_get_field(aeqe->event.cq_event.cq, 283 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M, 284 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)); 285 - hns_roce_cq_event(hr_dev, 286 - le32_to_cpu(roce_get_field(aeqe->event.cq_event.cq, 287 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M, 288 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)), 289 - roce_get_field(aeqe->asyn, 290 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 291 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)); 292 - break; 293 239 case HNS_ROCE_EVENT_TYPE_CQ_ID_INVALID: 294 - dev_warn(dev, "CQ ID invalid.\n"); 295 - hns_roce_cq_event(hr_dev, 296 - le32_to_cpu(roce_get_field(aeqe->event.cq_event.cq, 297 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M, 298 - HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)), 299 - roce_get_field(aeqe->asyn, 300 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 301 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S)); 240 + hns_roce_cq_err_handle(hr_dev, aeqe, event_type); 302 241 break; 303 242 case HNS_ROCE_EVENT_TYPE_PORT_CHANGE: 304 243 dev_warn(dev, "port change.\n"); ··· 289 290 HNS_ROCE_AEQE_EVENT_CE_EVENT_CEQE_CEQN_S)); 290 291 break; 291 292 default: 292 - dev_warn(dev, "Unhandled event 0x%lx on EQ %d at index %u\n", 293 - roce_get_field(aeqe->asyn, 294 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_M, 295 - HNS_ROCE_AEQE_U32_4_EVENT_TYPE_S), 296 - eq->eqn, eq->cons_index); 293 + dev_warn(dev, "Unhandled event %d on EQ %d at index %u\n", 294 + event_type, eq->eqn, eq->cons_index); 297 295 break; 298 296 }; 299 297
+4
drivers/infiniband/hw/hns/hns_roce_eq.h
··· 107 107 #define HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_M \ 108 108 (((1UL << 24) - 1) << HNS_ROCE_AEQE_EVENT_QP_EVENT_QP_QPN_S) 109 109 110 + #define HNS_ROCE_AEQE_EVENT_QP_EVENT_PORT_NUM_S 25 111 + #define HNS_ROCE_AEQE_EVENT_QP_EVENT_PORT_NUM_M \ 112 + (((1UL << 3) - 1) << HNS_ROCE_AEQE_EVENT_QP_EVENT_PORT_NUM_S) 113 + 110 114 #define HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S 0 111 115 #define HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_M \ 112 116 (((1UL << 16) - 1) << HNS_ROCE_AEQE_EVENT_CQ_EVENT_CQ_CQN_S)
+2 -74
drivers/infiniband/hw/hns/hns_roce_hem.c
··· 36 36 #include "hns_roce_hem.h" 37 37 #include "hns_roce_common.h" 38 38 39 - #define HW_SYNC_TIMEOUT_MSECS 500 40 - #define HW_SYNC_SLEEP_TIME_INTERVAL 20 41 - 42 39 #define HNS_ROCE_HEM_ALLOC_SIZE (1 << 17) 43 40 #define HNS_ROCE_TABLE_CHUNK_SIZE (1 << 17) 44 41 45 42 #define DMA_ADDR_T_SHIFT 12 46 - #define BT_CMD_SYNC_SHIFT 31 47 43 #define BT_BA_SHIFT 32 48 44 49 45 struct hns_roce_hem *hns_roce_alloc_hem(struct hns_roce_dev *hr_dev, int npages, ··· 209 213 return ret; 210 214 } 211 215 212 - static int hns_roce_clear_hem(struct hns_roce_dev *hr_dev, 213 - struct hns_roce_hem_table *table, 214 - unsigned long obj) 215 - { 216 - struct device *dev = &hr_dev->pdev->dev; 217 - unsigned long end = 0; 218 - unsigned long flags; 219 - void __iomem *bt_cmd; 220 - uint32_t bt_cmd_val[2]; 221 - u32 bt_cmd_h_val = 0; 222 - int ret = 0; 223 - 224 - switch (table->type) { 225 - case HEM_TYPE_QPC: 226 - roce_set_field(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 227 - ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_QPC); 228 - break; 229 - case HEM_TYPE_MTPT: 230 - roce_set_field(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 231 - ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, 232 - HEM_TYPE_MTPT); 233 - break; 234 - case HEM_TYPE_CQC: 235 - roce_set_field(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 236 - ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_CQC); 237 - break; 238 - case HEM_TYPE_SRQC: 239 - roce_set_field(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 240 - ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, 241 - HEM_TYPE_SRQC); 242 - break; 243 - default: 244 - return ret; 245 - } 246 - roce_set_field(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_M, 247 - ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_S, obj); 248 - roce_set_bit(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_S, 0); 249 - roce_set_bit(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_HW_SYNS_S, 1); 250 - roce_set_field(bt_cmd_h_val, ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_M, 251 - ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_S, 0); 252 - 253 - spin_lock_irqsave(&hr_dev->bt_cmd_lock, flags); 254 - 255 - bt_cmd = hr_dev->reg_base + ROCEE_BT_CMD_H_REG; 256 - 257 - end = msecs_to_jiffies(HW_SYNC_TIMEOUT_MSECS) + jiffies; 258 - while (1) { 259 - if (readl(bt_cmd) >> BT_CMD_SYNC_SHIFT) { 260 - if (!(time_before(jiffies, end))) { 261 - dev_err(dev, "Write bt_cmd err,hw_sync is not zero.\n"); 262 - spin_unlock_irqrestore(&hr_dev->bt_cmd_lock, 263 - flags); 264 - return -EBUSY; 265 - } 266 - } else { 267 - break; 268 - } 269 - msleep(HW_SYNC_SLEEP_TIME_INTERVAL); 270 - } 271 - 272 - bt_cmd_val[0] = 0; 273 - bt_cmd_val[1] = bt_cmd_h_val; 274 - hns_roce_write64_k(bt_cmd_val, hr_dev->reg_base + ROCEE_BT_CMD_L_REG); 275 - spin_unlock_irqrestore(&hr_dev->bt_cmd_lock, flags); 276 - 277 - return ret; 278 - } 279 - 280 216 int hns_roce_table_get(struct hns_roce_dev *hr_dev, 281 217 struct hns_roce_hem_table *table, unsigned long obj) 282 218 { ··· 261 333 262 334 if (--table->hem[i]->refcount == 0) { 263 335 /* Clear HEM base address */ 264 - if (hns_roce_clear_hem(hr_dev, table, obj)) 336 + if (hr_dev->hw->clear_hem(hr_dev, table, obj)) 265 337 dev_warn(dev, "Clear HEM base address failed.\n"); 266 338 267 339 hns_roce_free_hem(hr_dev, table->hem[i]); ··· 384 456 385 457 for (i = 0; i < table->num_hem; ++i) 386 458 if (table->hem[i]) { 387 - if (hns_roce_clear_hem(hr_dev, table, 459 + if (hr_dev->hw->clear_hem(hr_dev, table, 388 460 i * HNS_ROCE_TABLE_CHUNK_SIZE / table->obj_size)) 389 461 dev_err(dev, "Clear HEM base address failed.\n"); 390 462
+4
drivers/infiniband/hw/hns/hns_roce_hem.h
··· 34 34 #ifndef _HNS_ROCE_HEM_H 35 35 #define _HNS_ROCE_HEM_H 36 36 37 + #define HW_SYNC_TIMEOUT_MSECS 500 38 + #define HW_SYNC_SLEEP_TIME_INTERVAL 20 39 + #define BT_CMD_SYNC_SHIFT 31 40 + 37 41 enum { 38 42 /* MAP HEM(Hardware Entry Memory) */ 39 43 HEM_TYPE_QPC = 0,
+206 -85
drivers/infiniband/hw/hns/hns_roce_hw_v1.c
··· 73 73 u32 ind = 0; 74 74 int ret = 0; 75 75 76 - spin_lock_irqsave(&qp->sq.lock, flags); 76 + if (unlikely(ibqp->qp_type != IB_QPT_GSI && 77 + ibqp->qp_type != IB_QPT_RC)) { 78 + dev_err(dev, "un-supported QP type\n"); 79 + *bad_wr = NULL; 80 + return -EOPNOTSUPP; 81 + } 77 82 83 + spin_lock_irqsave(&qp->sq.lock, flags); 78 84 ind = qp->sq_next_wqe; 79 85 for (nreq = 0; wr; ++nreq, wr = wr->next) { 80 86 if (hns_roce_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) { ··· 168 162 roce_set_field(ud_sq_wqe->u32_36, 169 163 UD_SEND_WQE_U32_36_SGID_INDEX_M, 170 164 UD_SEND_WQE_U32_36_SGID_INDEX_S, 171 - hns_get_gid_index(hr_dev, qp->port, 165 + hns_get_gid_index(hr_dev, qp->phy_port, 172 166 ah->av.gid_index)); 173 167 174 168 roce_set_field(ud_sq_wqe->u32_40, ··· 211 205 (wr->send_flags & IB_SEND_FENCE ? 212 206 (cpu_to_le32(HNS_ROCE_WQE_FENCE)) : 0); 213 207 214 - wqe = (struct hns_roce_wqe_ctrl_seg *)wqe + 215 - sizeof(struct hns_roce_wqe_ctrl_seg); 208 + wqe += sizeof(struct hns_roce_wqe_ctrl_seg); 216 209 217 210 switch (wr->opcode) { 218 211 case IB_WR_RDMA_READ: ··· 240 235 break; 241 236 } 242 237 ctrl->flag |= cpu_to_le32(ps_opcode); 243 - wqe = (struct hns_roce_wqe_raddr_seg *)wqe + 244 - sizeof(struct hns_roce_wqe_raddr_seg); 238 + wqe += sizeof(struct hns_roce_wqe_raddr_seg); 245 239 246 240 dseg = wqe; 247 241 if (wr->send_flags & IB_SEND_INLINE && wr->num_sge) { ··· 257 253 memcpy(wqe, ((void *) (uintptr_t) 258 254 wr->sg_list[i].addr), 259 255 wr->sg_list[i].length); 260 - wqe = (struct hns_roce_wqe_raddr_seg *) 261 - wqe + wr->sg_list[i].length; 256 + wqe += wr->sg_list[i].length; 262 257 } 263 258 ctrl->flag |= HNS_ROCE_WQE_INLINE; 264 259 } else { ··· 269 266 HNS_ROCE_WQE_SGE_NUM_BIT); 270 267 } 271 268 ind++; 272 - } else { 273 - dev_dbg(dev, "unSupported QP type\n"); 274 - break; 275 269 } 276 270 } 277 271 ··· 285 285 SQ_DOORBELL_U32_4_SQ_HEAD_S, 286 286 (qp->sq.head & ((qp->sq.wqe_cnt << 1) - 1))); 287 287 roce_set_field(sq_db.u32_4, SQ_DOORBELL_U32_4_PORT_M, 288 - SQ_DOORBELL_U32_4_PORT_S, qp->port); 288 + SQ_DOORBELL_U32_4_PORT_S, qp->phy_port); 289 289 roce_set_field(sq_db.u32_8, SQ_DOORBELL_U32_8_QPN_M, 290 290 SQ_DOORBELL_U32_8_QPN_S, qp->doorbell_qpn); 291 291 roce_set_bit(sq_db.u32_8, SQ_DOORBELL_HW_SYNC_S, 1); ··· 365 365 /* SW update GSI rq header */ 366 366 reg_val = roce_read(to_hr_dev(ibqp->device), 367 367 ROCEE_QP1C_CFG3_0_REG + 368 - QP1C_CFGN_OFFSET * hr_qp->port); 368 + QP1C_CFGN_OFFSET * hr_qp->phy_port); 369 369 roce_set_field(reg_val, 370 370 ROCEE_QP1C_CFG3_0_ROCEE_QP1C_RQ_HEAD_M, 371 371 ROCEE_QP1C_CFG3_0_ROCEE_QP1C_RQ_HEAD_S, 372 372 hr_qp->rq.head); 373 373 roce_write(to_hr_dev(ibqp->device), 374 374 ROCEE_QP1C_CFG3_0_REG + 375 - QP1C_CFGN_OFFSET * hr_qp->port, reg_val); 375 + QP1C_CFGN_OFFSET * hr_qp->phy_port, reg_val); 376 376 } else { 377 377 rq_db.u32_4 = 0; 378 378 rq_db.u32_8 = 0; ··· 789 789 } 790 790 } 791 791 792 + static int hns_roce_bt_init(struct hns_roce_dev *hr_dev) 793 + { 794 + struct device *dev = &hr_dev->pdev->dev; 795 + struct hns_roce_v1_priv *priv; 796 + int ret; 797 + 798 + priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv; 799 + 800 + priv->bt_table.qpc_buf.buf = dma_alloc_coherent(dev, 801 + HNS_ROCE_BT_RSV_BUF_SIZE, &priv->bt_table.qpc_buf.map, 802 + GFP_KERNEL); 803 + if (!priv->bt_table.qpc_buf.buf) 804 + return -ENOMEM; 805 + 806 + priv->bt_table.mtpt_buf.buf = dma_alloc_coherent(dev, 807 + HNS_ROCE_BT_RSV_BUF_SIZE, &priv->bt_table.mtpt_buf.map, 808 + GFP_KERNEL); 809 + if (!priv->bt_table.mtpt_buf.buf) { 810 + ret = -ENOMEM; 811 + goto err_failed_alloc_mtpt_buf; 812 + } 813 + 814 + priv->bt_table.cqc_buf.buf = dma_alloc_coherent(dev, 815 + HNS_ROCE_BT_RSV_BUF_SIZE, &priv->bt_table.cqc_buf.map, 816 + GFP_KERNEL); 817 + if (!priv->bt_table.cqc_buf.buf) { 818 + ret = -ENOMEM; 819 + goto err_failed_alloc_cqc_buf; 820 + } 821 + 822 + return 0; 823 + 824 + err_failed_alloc_cqc_buf: 825 + dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE, 826 + priv->bt_table.mtpt_buf.buf, priv->bt_table.mtpt_buf.map); 827 + 828 + err_failed_alloc_mtpt_buf: 829 + dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE, 830 + priv->bt_table.qpc_buf.buf, priv->bt_table.qpc_buf.map); 831 + 832 + return ret; 833 + } 834 + 835 + static void hns_roce_bt_free(struct hns_roce_dev *hr_dev) 836 + { 837 + struct device *dev = &hr_dev->pdev->dev; 838 + struct hns_roce_v1_priv *priv; 839 + 840 + priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv; 841 + 842 + dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE, 843 + priv->bt_table.cqc_buf.buf, priv->bt_table.cqc_buf.map); 844 + 845 + dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE, 846 + priv->bt_table.mtpt_buf.buf, priv->bt_table.mtpt_buf.map); 847 + 848 + dma_free_coherent(dev, HNS_ROCE_BT_RSV_BUF_SIZE, 849 + priv->bt_table.qpc_buf.buf, priv->bt_table.qpc_buf.map); 850 + } 851 + 792 852 /** 793 853 * hns_roce_v1_reset - reset RoCE 794 854 * @hr_dev: RoCE device struct pointer ··· 939 879 caps->mtt_entry_sz = HNS_ROCE_V1_MTT_ENTRY_SIZE; 940 880 caps->cq_entry_sz = HNS_ROCE_V1_CQE_ENTRY_SIZE; 941 881 caps->page_size_cap = HNS_ROCE_V1_PAGE_SIZE_SUPPORT; 942 - caps->sqp_start = 0; 943 882 caps->reserved_lkey = 0; 944 883 caps->reserved_pds = 0; 945 884 caps->reserved_mrws = 1; ··· 1003 944 1004 945 hns_roce_port_enable(hr_dev, HNS_ROCE_PORT_UP); 1005 946 947 + ret = hns_roce_bt_init(hr_dev); 948 + if (ret) { 949 + dev_err(dev, "bt init failed!\n"); 950 + goto error_failed_bt_init; 951 + } 952 + 1006 953 return 0; 954 + 955 + error_failed_bt_init: 956 + hns_roce_port_enable(hr_dev, HNS_ROCE_PORT_DOWN); 957 + hns_roce_raq_free(hr_dev); 1007 958 1008 959 error_failed_raq_init: 1009 960 hns_roce_db_free(hr_dev); ··· 1022 953 1023 954 void hns_roce_v1_exit(struct hns_roce_dev *hr_dev) 1024 955 { 956 + hns_roce_bt_free(hr_dev); 1025 957 hns_roce_port_enable(hr_dev, HNS_ROCE_PORT_DOWN); 1026 958 hns_roce_raq_free(hr_dev); 1027 959 hns_roce_db_free(hr_dev); ··· 1262 1192 return get_sw_cqe(hr_cq, hr_cq->cons_index); 1263 1193 } 1264 1194 1265 - void hns_roce_v1_cq_set_ci(struct hns_roce_cq *hr_cq, u32 cons_index, 1266 - spinlock_t *doorbell_lock) 1267 - 1195 + void hns_roce_v1_cq_set_ci(struct hns_roce_cq *hr_cq, u32 cons_index) 1268 1196 { 1269 1197 u32 doorbell[2]; 1270 1198 ··· 1322 1254 */ 1323 1255 wmb(); 1324 1256 1325 - hns_roce_v1_cq_set_ci(hr_cq, hr_cq->cons_index, 1326 - &to_hr_dev(hr_cq->ib_cq.device)->cq_db_lock); 1257 + hns_roce_v1_cq_set_ci(hr_cq, hr_cq->cons_index); 1327 1258 } 1328 1259 } 1329 1260 ··· 1552 1485 /* SQ conrespond to CQE */ 1553 1486 sq_wqe = get_send_wqe(*cur_qp, roce_get_field(cqe->cqe_byte_4, 1554 1487 CQE_BYTE_4_WQE_INDEX_M, 1555 - CQE_BYTE_4_WQE_INDEX_S)); 1488 + CQE_BYTE_4_WQE_INDEX_S)& 1489 + ((*cur_qp)->sq.wqe_cnt-1)); 1556 1490 switch (sq_wqe->flag & HNS_ROCE_WQE_OPCODE_MASK) { 1557 1491 case HNS_ROCE_WQE_OPCODE_SEND: 1558 1492 wc->opcode = IB_WC_SEND; ··· 1659 1591 break; 1660 1592 } 1661 1593 1662 - if (npolled) { 1663 - hns_roce_v1_cq_set_ci(hr_cq, hr_cq->cons_index, 1664 - &to_hr_dev(ibcq->device)->cq_db_lock); 1665 - } 1594 + if (npolled) 1595 + hns_roce_v1_cq_set_ci(hr_cq, hr_cq->cons_index); 1666 1596 1667 1597 spin_unlock_irqrestore(&hr_cq->lock, flags); 1668 1598 ··· 1668 1602 return npolled; 1669 1603 else 1670 1604 return ret; 1605 + } 1606 + 1607 + int hns_roce_v1_clear_hem(struct hns_roce_dev *hr_dev, 1608 + struct hns_roce_hem_table *table, int obj) 1609 + { 1610 + struct device *dev = &hr_dev->pdev->dev; 1611 + struct hns_roce_v1_priv *priv; 1612 + unsigned long end = 0, flags = 0; 1613 + uint32_t bt_cmd_val[2] = {0}; 1614 + void __iomem *bt_cmd; 1615 + u64 bt_ba = 0; 1616 + 1617 + priv = (struct hns_roce_v1_priv *)hr_dev->hw->priv; 1618 + 1619 + switch (table->type) { 1620 + case HEM_TYPE_QPC: 1621 + roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 1622 + ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_QPC); 1623 + bt_ba = priv->bt_table.qpc_buf.map >> 12; 1624 + break; 1625 + case HEM_TYPE_MTPT: 1626 + roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 1627 + ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_MTPT); 1628 + bt_ba = priv->bt_table.mtpt_buf.map >> 12; 1629 + break; 1630 + case HEM_TYPE_CQC: 1631 + roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_M, 1632 + ROCEE_BT_CMD_H_ROCEE_BT_CMD_MDF_S, HEM_TYPE_CQC); 1633 + bt_ba = priv->bt_table.cqc_buf.map >> 12; 1634 + break; 1635 + case HEM_TYPE_SRQC: 1636 + dev_dbg(dev, "HEM_TYPE_SRQC not support.\n"); 1637 + return -EINVAL; 1638 + default: 1639 + return 0; 1640 + } 1641 + roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_M, 1642 + ROCEE_BT_CMD_H_ROCEE_BT_CMD_IN_MDF_S, obj); 1643 + roce_set_bit(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_S, 0); 1644 + roce_set_bit(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_HW_SYNS_S, 1); 1645 + 1646 + spin_lock_irqsave(&hr_dev->bt_cmd_lock, flags); 1647 + 1648 + bt_cmd = hr_dev->reg_base + ROCEE_BT_CMD_H_REG; 1649 + 1650 + end = msecs_to_jiffies(HW_SYNC_TIMEOUT_MSECS) + jiffies; 1651 + while (1) { 1652 + if (readl(bt_cmd) >> BT_CMD_SYNC_SHIFT) { 1653 + if (!(time_before(jiffies, end))) { 1654 + dev_err(dev, "Write bt_cmd err,hw_sync is not zero.\n"); 1655 + spin_unlock_irqrestore(&hr_dev->bt_cmd_lock, 1656 + flags); 1657 + return -EBUSY; 1658 + } 1659 + } else { 1660 + break; 1661 + } 1662 + msleep(HW_SYNC_SLEEP_TIME_INTERVAL); 1663 + } 1664 + 1665 + bt_cmd_val[0] = (uint32_t)bt_ba; 1666 + roce_set_field(bt_cmd_val[1], ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_M, 1667 + ROCEE_BT_CMD_H_ROCEE_BT_CMD_BA_H_S, bt_ba >> 32); 1668 + hns_roce_write64_k(bt_cmd_val, hr_dev->reg_base + ROCEE_BT_CMD_L_REG); 1669 + 1670 + spin_unlock_irqrestore(&hr_dev->bt_cmd_lock, flags); 1671 + 1672 + return 0; 1671 1673 } 1672 1674 1673 1675 static int hns_roce_v1_qp_modify(struct hns_roce_dev *hr_dev, ··· 1867 1733 roce_set_field(context->qp1c_bytes_16, QP1C_BYTES_16_RQ_HEAD_M, 1868 1734 QP1C_BYTES_16_RQ_HEAD_S, hr_qp->rq.head); 1869 1735 roce_set_field(context->qp1c_bytes_16, QP1C_BYTES_16_PORT_NUM_M, 1870 - QP1C_BYTES_16_PORT_NUM_S, hr_qp->port); 1736 + QP1C_BYTES_16_PORT_NUM_S, hr_qp->phy_port); 1871 1737 roce_set_bit(context->qp1c_bytes_16, 1872 1738 QP1C_BYTES_16_SIGNALING_TYPE_S, 1873 - hr_qp->sq_signal_bits); 1874 - roce_set_bit(context->qp1c_bytes_16, 1875 - QP1C_BYTES_16_LOCAL_ENABLE_E2E_CREDIT_S, 1876 1739 hr_qp->sq_signal_bits); 1877 1740 roce_set_bit(context->qp1c_bytes_16, QP1C_BYTES_16_RQ_BA_FLG_S, 1878 1741 1); ··· 1915 1784 1916 1785 /* Copy context to QP1C register */ 1917 1786 addr = (u32 *)(hr_dev->reg_base + ROCEE_QP1C_CFG0_0_REG + 1918 - hr_qp->port * sizeof(*context)); 1787 + hr_qp->phy_port * sizeof(*context)); 1919 1788 1920 1789 writel(context->qp1c_bytes_4, addr); 1921 1790 writel(context->sq_rq_bt_l, addr + 1); ··· 1926 1795 writel(context->qp1c_bytes_28, addr + 6); 1927 1796 writel(context->qp1c_bytes_32, addr + 7); 1928 1797 writel(context->cur_sq_wqe_ba_l, addr + 8); 1798 + writel(context->qp1c_bytes_40, addr + 9); 1929 1799 } 1930 1800 1931 1801 /* Modify QP1C status */ 1932 1802 reg_val = roce_read(hr_dev, ROCEE_QP1C_CFG0_0_REG + 1933 - hr_qp->port * sizeof(*context)); 1803 + hr_qp->phy_port * sizeof(*context)); 1934 1804 roce_set_field(reg_val, ROCEE_QP1C_CFG0_0_ROCEE_QP1C_QP_ST_M, 1935 1805 ROCEE_QP1C_CFG0_0_ROCEE_QP1C_QP_ST_S, new_state); 1936 1806 roce_write(hr_dev, ROCEE_QP1C_CFG0_0_REG + 1937 - hr_qp->port * sizeof(*context), reg_val); 1807 + hr_qp->phy_port * sizeof(*context), reg_val); 1938 1808 1939 1809 hr_qp->state = new_state; 1940 1810 if (new_state == IB_QPS_RESET) { ··· 1968 1836 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp); 1969 1837 struct device *dev = &hr_dev->pdev->dev; 1970 1838 struct hns_roce_qp_context *context; 1971 - struct hns_roce_rq_db rq_db; 1972 1839 dma_addr_t dma_handle_2 = 0; 1973 1840 dma_addr_t dma_handle = 0; 1974 1841 uint32_t doorbell[2] = {0}; 1975 1842 int rq_pa_start = 0; 1976 - u32 reg_val = 0; 1977 1843 u64 *mtts_2 = NULL; 1978 1844 int ret = -EINVAL; 1979 1845 u64 *mtts = NULL; ··· 2249 2119 2250 2120 roce_set_field(context->qpc_bytes_68, 2251 2121 QP_CONTEXT_QPC_BYTES_68_RQ_HEAD_M, 2252 - QP_CONTEXT_QPC_BYTES_68_RQ_HEAD_S, 0); 2122 + QP_CONTEXT_QPC_BYTES_68_RQ_HEAD_S, 2123 + hr_qp->rq.head); 2253 2124 roce_set_field(context->qpc_bytes_68, 2254 2125 QP_CONTEXT_QPC_BYTES_68_RQ_CUR_INDEX_M, 2255 2126 QP_CONTEXT_QPC_BYTES_68_RQ_CUR_INDEX_S, 0); ··· 2317 2186 roce_set_field(context->qpc_bytes_156, 2318 2187 QP_CONTEXT_QPC_BYTES_156_PORT_NUM_M, 2319 2188 QP_CONTEXT_QPC_BYTES_156_PORT_NUM_S, 2320 - hr_qp->port); 2189 + hr_qp->phy_port); 2321 2190 roce_set_field(context->qpc_bytes_156, 2322 2191 QP_CONTEXT_QPC_BYTES_156_SL_M, 2323 2192 QP_CONTEXT_QPC_BYTES_156_SL_S, attr->ah_attr.sl); ··· 2388 2257 roce_set_bit(context->qpc_bytes_140, 2389 2258 QP_CONTEXT_QPC_BYTES_140_RNR_RETRY_FLG_S, 0); 2390 2259 2391 - roce_set_field(context->qpc_bytes_144, 2392 - QP_CONTEXT_QPC_BYTES_144_QP_STATE_M, 2393 - QP_CONTEXT_QPC_BYTES_144_QP_STATE_S, 2394 - attr->qp_state); 2395 - 2396 2260 roce_set_field(context->qpc_bytes_148, 2397 2261 QP_CONTEXT_QPC_BYTES_148_CHECK_FLAG_M, 2398 2262 QP_CONTEXT_QPC_BYTES_148_CHECK_FLAG_S, 0); 2399 2263 roce_set_field(context->qpc_bytes_148, 2400 2264 QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_M, 2401 - QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_S, 0); 2265 + QP_CONTEXT_QPC_BYTES_148_RETRY_COUNT_S, 2266 + attr->retry_cnt); 2402 2267 roce_set_field(context->qpc_bytes_148, 2403 2268 QP_CONTEXT_QPC_BYTES_148_RNR_RETRY_COUNT_M, 2404 - QP_CONTEXT_QPC_BYTES_148_RNR_RETRY_COUNT_S, 0); 2269 + QP_CONTEXT_QPC_BYTES_148_RNR_RETRY_COUNT_S, 2270 + attr->rnr_retry); 2405 2271 roce_set_field(context->qpc_bytes_148, 2406 2272 QP_CONTEXT_QPC_BYTES_148_LSN_M, 2407 2273 QP_CONTEXT_QPC_BYTES_148_LSN_S, 0x100); ··· 2409 2281 QP_CONTEXT_QPC_BYTES_156_RETRY_COUNT_INIT_M, 2410 2282 QP_CONTEXT_QPC_BYTES_156_RETRY_COUNT_INIT_S, 2411 2283 attr->retry_cnt); 2412 - roce_set_field(context->qpc_bytes_156, 2413 - QP_CONTEXT_QPC_BYTES_156_ACK_TIMEOUT_M, 2414 - QP_CONTEXT_QPC_BYTES_156_ACK_TIMEOUT_S, 2415 - attr->timeout); 2284 + if (attr->timeout < 0x12) { 2285 + dev_info(dev, "ack timeout value(0x%x) must bigger than 0x12.\n", 2286 + attr->timeout); 2287 + roce_set_field(context->qpc_bytes_156, 2288 + QP_CONTEXT_QPC_BYTES_156_ACK_TIMEOUT_M, 2289 + QP_CONTEXT_QPC_BYTES_156_ACK_TIMEOUT_S, 2290 + 0x12); 2291 + } else { 2292 + roce_set_field(context->qpc_bytes_156, 2293 + QP_CONTEXT_QPC_BYTES_156_ACK_TIMEOUT_M, 2294 + QP_CONTEXT_QPC_BYTES_156_ACK_TIMEOUT_S, 2295 + attr->timeout); 2296 + } 2416 2297 roce_set_field(context->qpc_bytes_156, 2417 2298 QP_CONTEXT_QPC_BYTES_156_RNR_RETRY_COUNT_INIT_M, 2418 2299 QP_CONTEXT_QPC_BYTES_156_RNR_RETRY_COUNT_INIT_S, ··· 2429 2292 roce_set_field(context->qpc_bytes_156, 2430 2293 QP_CONTEXT_QPC_BYTES_156_PORT_NUM_M, 2431 2294 QP_CONTEXT_QPC_BYTES_156_PORT_NUM_S, 2432 - hr_qp->port); 2295 + hr_qp->phy_port); 2433 2296 roce_set_field(context->qpc_bytes_156, 2434 2297 QP_CONTEXT_QPC_BYTES_156_SL_M, 2435 2298 QP_CONTEXT_QPC_BYTES_156_SL_S, attr->ah_attr.sl); ··· 2494 2357 QP_CONTEXT_QPC_BYTES_188_TX_RETRY_CUR_INDEX_M, 2495 2358 QP_CONTEXT_QPC_BYTES_188_TX_RETRY_CUR_INDEX_S, 2496 2359 0); 2497 - } else if ((cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) || 2360 + } else if (!((cur_state == IB_QPS_INIT && new_state == IB_QPS_RESET) || 2498 2361 (cur_state == IB_QPS_INIT && new_state == IB_QPS_ERR) || 2499 2362 (cur_state == IB_QPS_RTR && new_state == IB_QPS_RESET) || 2500 2363 (cur_state == IB_QPS_RTR && new_state == IB_QPS_ERR) || 2501 2364 (cur_state == IB_QPS_RTS && new_state == IB_QPS_RESET) || 2502 2365 (cur_state == IB_QPS_RTS && new_state == IB_QPS_ERR) || 2503 2366 (cur_state == IB_QPS_ERR && new_state == IB_QPS_RESET) || 2504 - (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR)) { 2505 - roce_set_field(context->qpc_bytes_144, 2506 - QP_CONTEXT_QPC_BYTES_144_QP_STATE_M, 2507 - QP_CONTEXT_QPC_BYTES_144_QP_STATE_S, 2508 - attr->qp_state); 2509 - 2510 - } else { 2511 - dev_err(dev, "not support this modify\n"); 2367 + (cur_state == IB_QPS_ERR && new_state == IB_QPS_ERR))) { 2368 + dev_err(dev, "not support this status migration\n"); 2512 2369 goto out; 2513 2370 } 2514 2371 ··· 2528 2397 if (cur_state == IB_QPS_INIT && new_state == IB_QPS_INIT) { 2529 2398 /* Memory barrier */ 2530 2399 wmb(); 2531 - if (hr_qp->ibqp.qp_type == IB_QPT_GSI) { 2532 - /* SW update GSI rq header */ 2533 - reg_val = roce_read(hr_dev, ROCEE_QP1C_CFG3_0_REG + 2534 - QP1C_CFGN_OFFSET * hr_qp->port); 2535 - roce_set_field(reg_val, 2536 - ROCEE_QP1C_CFG3_0_ROCEE_QP1C_RQ_HEAD_M, 2537 - ROCEE_QP1C_CFG3_0_ROCEE_QP1C_RQ_HEAD_S, 2538 - hr_qp->rq.head); 2539 - roce_write(hr_dev, ROCEE_QP1C_CFG3_0_REG + 2540 - QP1C_CFGN_OFFSET * hr_qp->port, reg_val); 2541 - } else { 2542 - rq_db.u32_4 = 0; 2543 - rq_db.u32_8 = 0; 2544 2400 2545 - roce_set_field(rq_db.u32_4, RQ_DOORBELL_U32_4_RQ_HEAD_M, 2546 - RQ_DOORBELL_U32_4_RQ_HEAD_S, 2547 - hr_qp->rq.head); 2548 - roce_set_field(rq_db.u32_8, RQ_DOORBELL_U32_8_QPN_M, 2549 - RQ_DOORBELL_U32_8_QPN_S, hr_qp->qpn); 2550 - roce_set_field(rq_db.u32_8, RQ_DOORBELL_U32_8_CMD_M, 2551 - RQ_DOORBELL_U32_8_CMD_S, 1); 2552 - roce_set_bit(rq_db.u32_8, RQ_DOORBELL_U32_8_HW_SYNC_S, 2553 - 1); 2401 + roce_set_field(doorbell[0], RQ_DOORBELL_U32_4_RQ_HEAD_M, 2402 + RQ_DOORBELL_U32_4_RQ_HEAD_S, hr_qp->rq.head); 2403 + roce_set_field(doorbell[1], RQ_DOORBELL_U32_8_QPN_M, 2404 + RQ_DOORBELL_U32_8_QPN_S, hr_qp->qpn); 2405 + roce_set_field(doorbell[1], RQ_DOORBELL_U32_8_CMD_M, 2406 + RQ_DOORBELL_U32_8_CMD_S, 1); 2407 + roce_set_bit(doorbell[1], RQ_DOORBELL_U32_8_HW_SYNC_S, 1); 2554 2408 2555 - doorbell[0] = rq_db.u32_4; 2556 - doorbell[1] = rq_db.u32_8; 2557 - 2558 - hns_roce_write64_k(doorbell, hr_qp->rq.db_reg_l); 2409 + if (ibqp->uobject) { 2410 + hr_qp->rq.db_reg_l = hr_dev->reg_base + 2411 + ROCEE_DB_OTHERS_L_0_REG + 2412 + DB_REG_OFFSET * hr_dev->priv_uar.index; 2559 2413 } 2414 + 2415 + hns_roce_write64_k(doorbell, hr_qp->rq.db_reg_l); 2560 2416 } 2561 2417 2562 2418 hr_qp->state = new_state; 2563 2419 2564 2420 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) 2565 2421 hr_qp->resp_depth = attr->max_dest_rd_atomic; 2566 - if (attr_mask & IB_QP_PORT) 2567 - hr_qp->port = (attr->port_num - 1); 2422 + if (attr_mask & IB_QP_PORT) { 2423 + hr_qp->port = attr->port_num - 1; 2424 + hr_qp->phy_port = hr_dev->iboe.phy_port[hr_qp->port]; 2425 + } 2568 2426 2569 2427 if (new_state == IB_QPS_RESET && !ibqp->uobject) { 2570 2428 hns_roce_v1_cq_clean(to_hr_cq(ibqp->recv_cq), hr_qp->qpn, ··· 2909 2789 .set_mtu = hns_roce_v1_set_mtu, 2910 2790 .write_mtpt = hns_roce_v1_write_mtpt, 2911 2791 .write_cqc = hns_roce_v1_write_cqc, 2792 + .clear_hem = hns_roce_v1_clear_hem, 2912 2793 .modify_qp = hns_roce_v1_modify_qp, 2913 2794 .query_qp = hns_roce_v1_query_qp, 2914 2795 .destroy_qp = hns_roce_v1_destroy_qp,
+9
drivers/infiniband/hw/hns/hns_roce_hw_v1.h
··· 102 102 #define HNS_ROCE_V1_EXT_ODB_ALFUL \ 103 103 (HNS_ROCE_V1_EXT_ODB_DEPTH - HNS_ROCE_V1_DB_RSVD) 104 104 105 + #define HNS_ROCE_BT_RSV_BUF_SIZE (1 << 17) 106 + 105 107 #define HNS_ROCE_ODB_POLL_MODE 0 106 108 107 109 #define HNS_ROCE_SDB_NORMAL_MODE 0 ··· 973 971 struct hns_roce_ext_db *ext_db; 974 972 }; 975 973 974 + struct hns_roce_bt_table { 975 + struct hns_roce_buf_list qpc_buf; 976 + struct hns_roce_buf_list mtpt_buf; 977 + struct hns_roce_buf_list cqc_buf; 978 + }; 979 + 976 980 struct hns_roce_v1_priv { 977 981 struct hns_roce_db_table db_table; 978 982 struct hns_roce_raq_table raq_table; 983 + struct hns_roce_bt_table bt_table; 979 984 }; 980 985 981 986 int hns_dsaf_roce_reset(struct fwnode_handle *dsaf_fwnode, bool dereset);
+31 -5
drivers/infiniband/hw/hns/hns_roce_main.c
··· 355 355 props->max_qp = hr_dev->caps.num_qps; 356 356 props->max_qp_wr = hr_dev->caps.max_wqes; 357 357 props->device_cap_flags = IB_DEVICE_PORT_ACTIVE_EVENT | 358 - IB_DEVICE_RC_RNR_NAK_GEN | 359 - IB_DEVICE_LOCAL_DMA_LKEY; 358 + IB_DEVICE_RC_RNR_NAK_GEN; 360 359 props->max_sge = hr_dev->caps.max_sq_sg; 361 360 props->max_sge_rd = 1; 362 361 props->max_cq = hr_dev->caps.num_cqs; ··· 369 370 props->local_ca_ack_delay = hr_dev->caps.local_ca_ack_delay; 370 371 371 372 return 0; 373 + } 374 + 375 + static struct net_device *hns_roce_get_netdev(struct ib_device *ib_dev, 376 + u8 port_num) 377 + { 378 + struct hns_roce_dev *hr_dev = to_hr_dev(ib_dev); 379 + struct net_device *ndev; 380 + 381 + if (port_num < 1 || port_num > hr_dev->caps.num_ports) 382 + return NULL; 383 + 384 + rcu_read_lock(); 385 + 386 + ndev = hr_dev->iboe.netdevs[port_num - 1]; 387 + if (ndev) 388 + dev_hold(ndev); 389 + 390 + rcu_read_unlock(); 391 + return ndev; 372 392 } 373 393 374 394 static int hns_roce_query_port(struct ib_device *ib_dev, u8 port_num, ··· 602 584 struct device *dev = &hr_dev->pdev->dev; 603 585 604 586 iboe = &hr_dev->iboe; 587 + spin_lock_init(&iboe->lock); 605 588 606 589 ib_dev = &hr_dev->ib_dev; 607 590 strlcpy(ib_dev->name, "hisi_%d", IB_DEVICE_NAME_MAX); ··· 637 618 ib_dev->query_port = hns_roce_query_port; 638 619 ib_dev->modify_port = hns_roce_modify_port; 639 620 ib_dev->get_link_layer = hns_roce_get_link_layer; 621 + ib_dev->get_netdev = hns_roce_get_netdev; 640 622 ib_dev->query_gid = hns_roce_query_gid; 641 623 ib_dev->query_pkey = hns_roce_query_pkey; 642 624 ib_dev->alloc_ucontext = hns_roce_alloc_ucontext; ··· 686 666 dev_err(dev, "roce_setup_mtu_gids failed!\n"); 687 667 goto error_failed_setup_mtu_gids; 688 668 } 689 - 690 - spin_lock_init(&iboe->lock); 691 669 692 670 iboe->nb.notifier_call = hns_roce_netdev_event; 693 671 ret = register_netdevice_notifier(&iboe->nb); ··· 794 776 hr_dev->reg_base = devm_ioremap_resource(dev, res); 795 777 if (IS_ERR(hr_dev->reg_base)) 796 778 return PTR_ERR(hr_dev->reg_base); 779 + 780 + /* read the node_guid of IB device from the DT or ACPI */ 781 + ret = device_property_read_u8_array(dev, "node-guid", 782 + (u8 *)&hr_dev->ib_dev.node_guid, 783 + GUID_LEN); 784 + if (ret) { 785 + dev_err(dev, "couldn't get node_guid from DT or ACPI!\n"); 786 + return ret; 787 + } 797 788 798 789 /* get the RoCE associated ethernet ports or netdevices */ 799 790 for (i = 0; i < HNS_ROCE_MAX_PORTS; i++) { ··· 950 923 struct device *dev = &hr_dev->pdev->dev; 951 924 952 925 spin_lock_init(&hr_dev->sm_lock); 953 - spin_lock_init(&hr_dev->cq_db_lock); 954 926 spin_lock_init(&hr_dev->bt_cmd_lock); 955 927 956 928 ret = hns_roce_init_uar_table(hr_dev);
+3
drivers/infiniband/hw/hns/hns_roce_mr.c
··· 564 564 if (mr->umem->page_size != HNS_ROCE_HEM_PAGE_SIZE) { 565 565 dev_err(dev, "Just support 4K page size but is 0x%x now!\n", 566 566 mr->umem->page_size); 567 + ret = -EINVAL; 568 + goto err_umem; 567 569 } 568 570 569 571 if (n > HNS_ROCE_MAX_MTPT_PBL_NUM) { 570 572 dev_err(dev, " MR len %lld err. MR is limited to 4G at most!\n", 571 573 length); 574 + ret = -EINVAL; 572 575 goto err_umem; 573 576 } 574 577
+8 -14
drivers/infiniband/hw/hns/hns_roce_pd.c
··· 35 35 36 36 static int hns_roce_pd_alloc(struct hns_roce_dev *hr_dev, unsigned long *pdn) 37 37 { 38 - struct device *dev = &hr_dev->pdev->dev; 39 - unsigned long pd_number; 40 - int ret = 0; 41 - 42 - ret = hns_roce_bitmap_alloc(&hr_dev->pd_bitmap, &pd_number); 43 - if (ret == -1) { 44 - dev_err(dev, "alloc pdn from pdbitmap failed\n"); 45 - return -ENOMEM; 46 - } 47 - 48 - *pdn = pd_number; 49 - 50 - return 0; 38 + return hns_roce_bitmap_alloc(&hr_dev->pd_bitmap, pdn); 51 39 } 52 40 53 41 static void hns_roce_pd_free(struct hns_roce_dev *hr_dev, unsigned long pdn) ··· 105 117 if (ret == -1) 106 118 return -ENOMEM; 107 119 108 - uar->index = (uar->index - 1) % hr_dev->caps.phy_num_uars + 1; 120 + if (uar->index > 0) 121 + uar->index = (uar->index - 1) % 122 + (hr_dev->caps.phy_num_uars - 1) + 1; 109 123 110 124 res = platform_get_resource(hr_dev->pdev, IORESOURCE_MEM, 0); 125 + if (!res) { 126 + dev_err(&hr_dev->pdev->dev, "memory resource not found!\n"); 127 + return -EINVAL; 128 + } 111 129 uar->pfn = ((res->start) >> PAGE_SHIFT) + uar->index; 112 130 113 131 return 0;
+25 -42
drivers/infiniband/hw/hns/hns_roce_qp.c
··· 32 32 */ 33 33 34 34 #include <linux/platform_device.h> 35 + #include <rdma/ib_addr.h> 35 36 #include <rdma/ib_umem.h> 36 37 #include "hns_roce_common.h" 37 38 #include "hns_roce_device.h" 38 39 #include "hns_roce_hem.h" 39 40 #include "hns_roce_user.h" 40 41 41 - #define DB_REG_OFFSET 0x1000 42 - #define SQP_NUM 12 42 + #define SQP_NUM (2 * HNS_ROCE_MAX_PORTS) 43 43 44 44 void hns_roce_qp_event(struct hns_roce_dev *hr_dev, u32 qpn, int event_type) 45 45 { ··· 113 113 int align, unsigned long *base) 114 114 { 115 115 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table; 116 - int ret = 0; 117 - unsigned long qpn; 118 116 119 - ret = hns_roce_bitmap_alloc_range(&qp_table->bitmap, cnt, align, &qpn); 120 - if (ret == -1) 121 - return -ENOMEM; 122 - 123 - *base = qpn; 124 - 125 - return 0; 117 + return hns_roce_bitmap_alloc_range(&qp_table->bitmap, cnt, align, base); 126 118 } 127 119 128 120 enum hns_roce_qp_state to_hns_roce_state(enum ib_qp_state state) ··· 247 255 { 248 256 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table; 249 257 250 - if (base_qpn < (hr_dev->caps.sqp_start + 2 * hr_dev->caps.num_ports)) 258 + if (base_qpn < SQP_NUM) 251 259 return; 252 260 253 261 hns_roce_bitmap_free_range(&qp_table->bitmap, base_qpn, cnt); ··· 337 345 338 346 static int hns_roce_set_kernel_sq_size(struct hns_roce_dev *hr_dev, 339 347 struct ib_qp_cap *cap, 340 - enum ib_qp_type type, 341 348 struct hns_roce_qp *hr_qp) 342 349 { 343 350 struct device *dev = &hr_dev->pdev->dev; 344 351 u32 max_cnt; 345 - (void)type; 346 352 347 353 if (cap->max_send_wr > hr_dev->caps.max_wqes || 348 354 cap->max_send_sge > hr_dev->caps.max_sq_sg || ··· 466 476 467 477 /* Set SQ size */ 468 478 ret = hns_roce_set_kernel_sq_size(hr_dev, &init_attr->cap, 469 - init_attr->qp_type, hr_qp); 479 + hr_qp); 470 480 if (ret) { 471 481 dev_err(dev, "hns_roce_set_kernel_sq_size error!\n"); 472 482 goto err_out; ··· 607 617 return ERR_PTR(-ENOMEM); 608 618 609 619 hr_qp = &hr_sqp->hr_qp; 620 + hr_qp->port = init_attr->port_num - 1; 621 + hr_qp->phy_port = hr_dev->iboe.phy_port[hr_qp->port]; 622 + hr_qp->ibqp.qp_num = HNS_ROCE_MAX_PORTS + 623 + hr_dev->iboe.phy_port[hr_qp->port]; 610 624 611 625 ret = hns_roce_create_qp_common(hr_dev, pd, init_attr, udata, 612 - hr_dev->caps.sqp_start + 613 - hr_dev->caps.num_ports + 614 - init_attr->port_num - 1, hr_qp); 626 + hr_qp->ibqp.qp_num, hr_qp); 615 627 if (ret) { 616 628 dev_err(dev, "Create GSI QP failed!\n"); 617 629 kfree(hr_sqp); 618 630 return ERR_PTR(ret); 619 631 } 620 632 621 - hr_qp->port = (init_attr->port_num - 1); 622 - hr_qp->ibqp.qp_num = hr_dev->caps.sqp_start + 623 - hr_dev->caps.num_ports + 624 - init_attr->port_num - 1; 625 633 break; 626 634 } 627 635 default:{ ··· 658 670 struct device *dev = &hr_dev->pdev->dev; 659 671 int ret = -EINVAL; 660 672 int p; 673 + enum ib_mtu active_mtu; 661 674 662 675 mutex_lock(&hr_qp->mutex); 663 676 ··· 685 696 if (attr->pkey_index >= hr_dev->caps.pkey_table_len[p]) { 686 697 dev_err(dev, "attr pkey_index invalid.attr->pkey_index=%d\n", 687 698 attr->pkey_index); 699 + goto out; 700 + } 701 + } 702 + 703 + if (attr_mask & IB_QP_PATH_MTU) { 704 + p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port; 705 + active_mtu = iboe_get_mtu(hr_dev->iboe.netdevs[p]->mtu); 706 + 707 + if (attr->path_mtu > IB_MTU_2048 || 708 + attr->path_mtu < IB_MTU_256 || 709 + attr->path_mtu > active_mtu) { 710 + dev_err(dev, "attr path_mtu(%d)invalid while modify qp", 711 + attr->path_mtu); 688 712 goto out; 689 713 } 690 714 } ··· 784 782 785 783 void *get_recv_wqe(struct hns_roce_qp *hr_qp, int n) 786 784 { 787 - struct ib_qp *ibqp = &hr_qp->ibqp; 788 - struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device); 789 - 790 - if ((n < 0) || (n > hr_qp->rq.wqe_cnt)) { 791 - dev_err(&hr_dev->pdev->dev, "rq wqe index:%d,rq wqe cnt:%d\r\n", 792 - n, hr_qp->rq.wqe_cnt); 793 - return NULL; 794 - } 795 - 796 785 return get_wqe(hr_qp, hr_qp->rq.offset + (n << hr_qp->rq.wqe_shift)); 797 786 } 798 787 799 788 void *get_send_wqe(struct hns_roce_qp *hr_qp, int n) 800 789 { 801 - struct ib_qp *ibqp = &hr_qp->ibqp; 802 - struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device); 803 - 804 - if ((n < 0) || (n > hr_qp->sq.wqe_cnt)) { 805 - dev_err(&hr_dev->pdev->dev, "sq wqe index:%d,sq wqe cnt:%d\r\n", 806 - n, hr_qp->sq.wqe_cnt); 807 - return NULL; 808 - } 809 - 810 790 return get_wqe(hr_qp, hr_qp->sq.offset + (n << hr_qp->sq.wqe_shift)); 811 791 } 812 792 ··· 821 837 822 838 /* A port include two SQP, six port total 12 */ 823 839 ret = hns_roce_bitmap_init(&qp_table->bitmap, hr_dev->caps.num_qps, 824 - hr_dev->caps.num_qps - 1, 825 - hr_dev->caps.sqp_start + SQP_NUM, 840 + hr_dev->caps.num_qps - 1, SQP_NUM, 826 841 reserved_from_top); 827 842 if (ret) { 828 843 dev_err(&hr_dev->pdev->dev, "qp bitmap init failed!error=%d\n",
+6 -5
drivers/net/ethernet/hisilicon/hns/hns_ae_adapt.c
··· 207 207 int ret; 208 208 char *mac_addr = (char *)addr; 209 209 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 210 + u8 port_num; 210 211 211 212 assert(mac_cb); 212 213 ··· 222 221 return ret; 223 222 } 224 223 225 - ret = hns_mac_set_multi(mac_cb, DSAF_BASE_INNER_PORT_NUM, 226 - mac_addr, true); 224 + ret = hns_mac_get_inner_port_num(mac_cb, handle->vf_id, &port_num); 225 + if (ret) 226 + return ret; 227 + 228 + ret = hns_mac_set_multi(mac_cb, port_num, mac_addr, true); 227 229 if (ret) 228 230 dev_err(handle->owner_dev, 229 231 "mac add mul_mac:%pM port%d fail, ret = %#x!\n", ··· 681 677 default: 682 678 ret = -EINVAL; 683 679 } 684 - 685 - if (!ret) 686 - hns_dsaf_set_inner_lb(mac_cb->dsaf_dev, mac_cb->mac_id, en); 687 680 688 681 return ret; 689 682 }
+10 -3
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c
··· 141 141 *@port_num:port number 142 142 * 143 143 */ 144 - static int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb, 145 - u8 vmid, u8 *port_num) 144 + int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb, u8 vmid, u8 *port_num) 146 145 { 146 + int q_num_per_vf, vf_num_per_port; 147 + int vm_queue_id; 147 148 u8 tmp_port; 148 149 149 150 if (mac_cb->dsaf_dev->dsaf_mode <= DSAF_MODE_ENABLE) { ··· 175 174 return -EINVAL; 176 175 } 177 176 177 + q_num_per_vf = mac_cb->dsaf_dev->rcb_common[0]->max_q_per_vf; 178 + vf_num_per_port = mac_cb->dsaf_dev->rcb_common[0]->max_vfn; 179 + 180 + vm_queue_id = vmid * q_num_per_vf + 181 + vf_num_per_port * q_num_per_vf * mac_cb->mac_id; 182 + 178 183 switch (mac_cb->dsaf_dev->dsaf_mode) { 179 184 case DSAF_MODE_ENABLE_FIX: 180 185 tmp_port = 0; ··· 200 193 case DSAF_MODE_DISABLE_6PORT_2VM: 201 194 case DSAF_MODE_DISABLE_6PORT_4VM: 202 195 case DSAF_MODE_DISABLE_6PORT_16VM: 203 - tmp_port = vmid; 196 + tmp_port = vm_queue_id; 204 197 break; 205 198 default: 206 199 dev_err(mac_cb->dev, "dsaf mode invalid, %s mac%d!\n",
+2
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.h
··· 461 461 int hns_cpld_led_set_id(struct hns_mac_cb *mac_cb, 462 462 enum hnae_led_state status); 463 463 void hns_mac_set_promisc(struct hns_mac_cb *mac_cb, u8 en); 464 + int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb, 465 + u8 vmid, u8 *port_num); 464 466 465 467 #endif /* _HNS_DSAF_MAC_H */
-10
drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
··· 760 760 DSAF_CFG_MIX_MODE_S, !!en); 761 761 } 762 762 763 - void hns_dsaf_set_inner_lb(struct dsaf_device *dsaf_dev, u32 mac_id, u32 en) 764 - { 765 - if (AE_IS_VER1(dsaf_dev->dsaf_ver) || 766 - dsaf_dev->mac_cb[mac_id]->mac_type == HNAE_PORT_DEBUG) 767 - return; 768 - 769 - dsaf_set_dev_bit(dsaf_dev, DSAFV2_SERDES_LBK_0_REG + 4 * mac_id, 770 - DSAFV2_SERDES_LBK_EN_B, !!en); 771 - } 772 - 773 763 /** 774 764 * hns_dsaf_tbl_stat_en - tbl 775 765 * @dsaf_id: dsa fabric id
-1
drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.h
··· 466 466 u32 *en); 467 467 int hns_dsaf_set_rx_mac_pause_en(struct dsaf_device *dsaf_dev, int mac_id, 468 468 u32 en); 469 - void hns_dsaf_set_inner_lb(struct dsaf_device *dsaf_dev, u32 mac_id, u32 en); 470 469 471 470 #endif /* __HNS_DSAF_MAIN_H__ */
+16
drivers/net/ethernet/hisilicon/hns/hns_dsaf_rcb.c
··· 543 543 "error: coalesce_usecs setting supports 0~1023us\n"); 544 544 return -EINVAL; 545 545 } 546 + 547 + if (!AE_IS_VER1(rcb_common->dsaf_dev->dsaf_ver)) { 548 + if (timeout == 0) 549 + /* set timeout to 0, Disable gap time */ 550 + dsaf_set_reg_field(rcb_common->io_base, 551 + RCB_INT_GAP_TIME_REG + port_idx * 4, 552 + PPE_INT_GAPTIME_M, PPE_INT_GAPTIME_B, 553 + 0); 554 + else 555 + /* set timeout non 0, restore gap time to 1 */ 556 + dsaf_set_reg_field(rcb_common->io_base, 557 + RCB_INT_GAP_TIME_REG + port_idx * 4, 558 + PPE_INT_GAPTIME_M, PPE_INT_GAPTIME_B, 559 + 1); 560 + } 561 + 546 562 hns_rcb_set_port_timeout(rcb_common, port_idx, timeout); 547 563 return 0; 548 564 }
+4
drivers/net/ethernet/hisilicon/hns/hns_dsaf_reg.h
··· 417 417 #define RCB_CFG_OVERTIME_REG 0x9300 418 418 #define RCB_CFG_PKTLINE_INT_NUM_REG 0x9304 419 419 #define RCB_CFG_OVERTIME_INT_NUM_REG 0x9308 420 + #define RCB_INT_GAP_TIME_REG 0x9400 420 421 #define RCB_PORT_CFG_OVERTIME_REG 0x9430 421 422 422 423 #define RCB_RING_RX_RING_BASEADDR_L_REG 0x00000 ··· 898 897 899 898 #define PPE_CNT_CLR_CE_B 0 900 899 #define PPE_CNT_CLR_SNAP_EN_B 1 900 + 901 + #define PPE_INT_GAPTIME_B 0 902 + #define PPE_INT_GAPTIME_M 0x3ff 901 903 902 904 #define PPE_COMMON_CNT_CLR_CE_B 0 903 905 #define PPE_COMMON_CNT_CLR_SNAP_EN_B 1
+73 -34
drivers/net/ethernet/hisilicon/hns/hns_enet.c
··· 574 574 struct sk_buff *skb; 575 575 struct hnae_desc *desc; 576 576 struct hnae_desc_cb *desc_cb; 577 - struct ethhdr *eh; 578 577 unsigned char *va; 579 578 int bnum, length, i; 580 579 int pull_len; ··· 599 600 ring->stats.sw_err_cnt++; 600 601 return -ENOMEM; 601 602 } 602 - skb_reset_mac_header(skb); 603 603 604 604 prefetchw(skb->data); 605 605 length = le16_to_cpu(desc->rx.pkt_len); ··· 680 682 return -EFAULT; 681 683 } 682 684 683 - /* filter out multicast pkt with the same src mac as this port */ 684 - eh = eth_hdr(skb); 685 - if (unlikely(is_multicast_ether_addr(eh->h_dest) && 686 - ether_addr_equal(ndev->dev_addr, eh->h_source))) { 687 - dev_kfree_skb_any(skb); 688 - return -EFAULT; 689 - } 690 - 691 685 ring->stats.rx_pkts++; 692 686 ring->stats.rx_bytes += skb->len; 693 687 ··· 737 747 ndev->last_rx = jiffies; 738 748 } 739 749 750 + static int hns_desc_unused(struct hnae_ring *ring) 751 + { 752 + int ntc = ring->next_to_clean; 753 + int ntu = ring->next_to_use; 754 + 755 + return ((ntc >= ntu) ? 0 : ring->desc_num) + ntc - ntu; 756 + } 757 + 740 758 static int hns_nic_rx_poll_one(struct hns_nic_ring_data *ring_data, 741 759 int budget, void *v) 742 760 { 743 761 struct hnae_ring *ring = ring_data->ring; 744 762 struct sk_buff *skb; 745 - int num, bnum, ex_num; 763 + int num, bnum; 746 764 #define RCB_NOF_ALLOC_RX_BUFF_ONCE 16 747 765 int recv_pkts, recv_bds, clean_count, err; 766 + int unused_count = hns_desc_unused(ring); 748 767 749 768 num = readl_relaxed(ring->io_base + RCB_REG_FBDNUM); 750 769 rmb(); /* make sure num taken effect before the other data is touched */ 751 770 752 771 recv_pkts = 0, recv_bds = 0, clean_count = 0; 753 - recv: 772 + num -= unused_count; 773 + 754 774 while (recv_pkts < budget && recv_bds < num) { 755 775 /* reuse or realloc buffers */ 756 - if (clean_count >= RCB_NOF_ALLOC_RX_BUFF_ONCE) { 757 - hns_nic_alloc_rx_buffers(ring_data, clean_count); 776 + if (clean_count + unused_count >= RCB_NOF_ALLOC_RX_BUFF_ONCE) { 777 + hns_nic_alloc_rx_buffers(ring_data, 778 + clean_count + unused_count); 758 779 clean_count = 0; 780 + unused_count = hns_desc_unused(ring); 759 781 } 760 782 761 783 /* poll one pkt */ ··· 788 786 recv_pkts++; 789 787 } 790 788 791 - /* make all data has been write before submit */ 792 - if (recv_pkts < budget) { 793 - ex_num = readl_relaxed(ring->io_base + RCB_REG_FBDNUM); 794 - 795 - if (ex_num > clean_count) { 796 - num += ex_num - clean_count; 797 - rmb(); /*complete read rx ring bd number*/ 798 - goto recv; 799 - } 800 - } 801 - 802 789 out: 803 790 /* make all data has been write before submit */ 804 - if (clean_count > 0) 805 - hns_nic_alloc_rx_buffers(ring_data, clean_count); 791 + if (clean_count + unused_count > 0) 792 + hns_nic_alloc_rx_buffers(ring_data, 793 + clean_count + unused_count); 806 794 807 795 return recv_pkts; 808 796 } ··· 801 809 { 802 810 struct hnae_ring *ring = ring_data->ring; 803 811 int num = 0; 812 + 813 + ring_data->ring->q->handle->dev->ops->toggle_ring_irq(ring, 0); 804 814 805 815 /* for hardware bug fixed */ 806 816 num = readl_relaxed(ring->io_base + RCB_REG_FBDNUM); ··· 813 819 814 820 napi_schedule(&ring_data->napi); 815 821 } 822 + } 823 + 824 + static void hns_nic_rx_fini_pro_v2(struct hns_nic_ring_data *ring_data) 825 + { 826 + struct hnae_ring *ring = ring_data->ring; 827 + int num = 0; 828 + 829 + num = readl_relaxed(ring->io_base + RCB_REG_FBDNUM); 830 + 831 + if (num == 0) 832 + ring_data->ring->q->handle->dev->ops->toggle_ring_irq( 833 + ring, 0); 834 + else 835 + napi_schedule(&ring_data->napi); 816 836 } 817 837 818 838 static inline void hns_nic_reclaim_one_desc(struct hnae_ring *ring, ··· 930 922 static void hns_nic_tx_fini_pro(struct hns_nic_ring_data *ring_data) 931 923 { 932 924 struct hnae_ring *ring = ring_data->ring; 933 - int head = readl_relaxed(ring->io_base + RCB_REG_HEAD); 925 + int head; 926 + 927 + ring_data->ring->q->handle->dev->ops->toggle_ring_irq(ring, 0); 928 + 929 + head = readl_relaxed(ring->io_base + RCB_REG_HEAD); 934 930 935 931 if (head != ring->next_to_clean) { 936 932 ring_data->ring->q->handle->dev->ops->toggle_ring_irq( ··· 942 930 943 931 napi_schedule(&ring_data->napi); 944 932 } 933 + } 934 + 935 + static void hns_nic_tx_fini_pro_v2(struct hns_nic_ring_data *ring_data) 936 + { 937 + struct hnae_ring *ring = ring_data->ring; 938 + int head = readl_relaxed(ring->io_base + RCB_REG_HEAD); 939 + 940 + if (head == ring->next_to_clean) 941 + ring_data->ring->q->handle->dev->ops->toggle_ring_irq( 942 + ring, 0); 943 + else 944 + napi_schedule(&ring_data->napi); 945 945 } 946 946 947 947 static void hns_nic_tx_clr_all_bufs(struct hns_nic_ring_data *ring_data) ··· 987 963 988 964 if (clean_complete >= 0 && clean_complete < budget) { 989 965 napi_complete(napi); 990 - ring_data->ring->q->handle->dev->ops->toggle_ring_irq( 991 - ring_data->ring, 0); 992 - if (ring_data->fini_process) 993 - ring_data->fini_process(ring_data); 966 + ring_data->fini_process(ring_data); 994 967 return 0; 995 968 } 996 969 ··· 1583 1562 return stats; 1584 1563 } 1585 1564 1565 + static u16 1566 + hns_nic_select_queue(struct net_device *ndev, struct sk_buff *skb, 1567 + void *accel_priv, select_queue_fallback_t fallback) 1568 + { 1569 + struct ethhdr *eth_hdr = (struct ethhdr *)skb->data; 1570 + struct hns_nic_priv *priv = netdev_priv(ndev); 1571 + 1572 + /* fix hardware broadcast/multicast packets queue loopback */ 1573 + if (!AE_IS_VER1(priv->enet_ver) && 1574 + is_multicast_ether_addr(eth_hdr->h_dest)) 1575 + return 0; 1576 + else 1577 + return fallback(ndev, skb); 1578 + } 1579 + 1586 1580 static const struct net_device_ops hns_nic_netdev_ops = { 1587 1581 .ndo_open = hns_nic_net_open, 1588 1582 .ndo_stop = hns_nic_net_stop, ··· 1613 1577 .ndo_poll_controller = hns_nic_poll_controller, 1614 1578 #endif 1615 1579 .ndo_set_rx_mode = hns_nic_set_rx_mode, 1580 + .ndo_select_queue = hns_nic_select_queue, 1616 1581 }; 1617 1582 1618 1583 static void hns_nic_update_link_status(struct net_device *netdev) ··· 1775 1738 rd->queue_index = i; 1776 1739 rd->ring = &h->qs[i]->tx_ring; 1777 1740 rd->poll_one = hns_nic_tx_poll_one; 1778 - rd->fini_process = is_ver1 ? hns_nic_tx_fini_pro : NULL; 1741 + rd->fini_process = is_ver1 ? hns_nic_tx_fini_pro : 1742 + hns_nic_tx_fini_pro_v2; 1779 1743 1780 1744 netif_napi_add(priv->netdev, &rd->napi, 1781 1745 hns_nic_common_poll, NIC_TX_CLEAN_MAX_NUM); ··· 1788 1750 rd->ring = &h->qs[i - h->q_num]->rx_ring; 1789 1751 rd->poll_one = hns_nic_rx_poll_one; 1790 1752 rd->ex_process = hns_nic_rx_up_pro; 1791 - rd->fini_process = is_ver1 ? hns_nic_rx_fini_pro : NULL; 1753 + rd->fini_process = is_ver1 ? hns_nic_rx_fini_pro : 1754 + hns_nic_rx_fini_pro_v2; 1792 1755 1793 1756 netif_napi_add(priv->netdev, &rd->napi, 1794 1757 hns_nic_common_poll, NIC_RX_CLEAN_MAX_NUM);
+7
drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
··· 352 352 break; 353 353 } 354 354 355 + if (!ret) { 356 + if (loop == MAC_LOOP_NONE) 357 + h->dev->ops->set_promisc_mode( 358 + h, ndev->flags & IFF_PROMISC); 359 + else 360 + h->dev->ops->set_promisc_mode(h, 1); 361 + } 355 362 return ret; 356 363 } 357 364