]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/infiniband/sw/rxe/rxe_verbs.c
IB/rxe: Initialize ib_ah_attr during query_ah
[karo-tx-linux.git] / drivers / infiniband / sw / rxe / rxe_verbs.c
1 /*
2  * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
3  * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
4  *
5  * This software is available to you under a choice of one of two
6  * licenses.  You may choose to be licensed under the terms of the GNU
7  * General Public License (GPL) Version 2, available from the file
8  * COPYING in the main directory of this source tree, or the
9  * OpenIB.org BSD license below:
10  *
11  *     Redistribution and use in source and binary forms, with or
12  *     without modification, are permitted provided that the following
13  *     conditions are met:
14  *
15  *      - Redistributions of source code must retain the above
16  *        copyright notice, this list of conditions and the following
17  *        disclaimer.
18  *
19  *      - Redistributions in binary form must reproduce the above
20  *        copyright notice, this list of conditions and the following
21  *        disclaimer in the documentation and/or other materials
22  *        provided with the distribution.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31  * SOFTWARE.
32  */
33
34 #include <linux/dma-mapping.h>
35 #include <net/addrconf.h>
36 #include "rxe.h"
37 #include "rxe_loc.h"
38 #include "rxe_queue.h"
39 #include "rxe_hw_counters.h"
40
41 static int rxe_query_device(struct ib_device *dev,
42                             struct ib_device_attr *attr,
43                             struct ib_udata *uhw)
44 {
45         struct rxe_dev *rxe = to_rdev(dev);
46
47         if (uhw->inlen || uhw->outlen)
48                 return -EINVAL;
49
50         *attr = rxe->attr;
51         return 0;
52 }
53
54 static void rxe_eth_speed_to_ib_speed(int speed, u8 *active_speed,
55                                       u8 *active_width)
56 {
57         if (speed <= 1000) {
58                 *active_width = IB_WIDTH_1X;
59                 *active_speed = IB_SPEED_SDR;
60         } else if (speed <= 10000) {
61                 *active_width = IB_WIDTH_1X;
62                 *active_speed = IB_SPEED_FDR10;
63         } else if (speed <= 20000) {
64                 *active_width = IB_WIDTH_4X;
65                 *active_speed = IB_SPEED_DDR;
66         } else if (speed <= 30000) {
67                 *active_width = IB_WIDTH_4X;
68                 *active_speed = IB_SPEED_QDR;
69         } else if (speed <= 40000) {
70                 *active_width = IB_WIDTH_4X;
71                 *active_speed = IB_SPEED_FDR10;
72         } else {
73                 *active_width = IB_WIDTH_4X;
74                 *active_speed = IB_SPEED_EDR;
75         }
76 }
77
78 static int rxe_query_port(struct ib_device *dev,
79                           u8 port_num, struct ib_port_attr *attr)
80 {
81         struct rxe_dev *rxe = to_rdev(dev);
82         struct rxe_port *port;
83         u32 speed;
84
85         if (unlikely(port_num != 1)) {
86                 pr_warn("invalid port_number %d\n", port_num);
87                 goto err1;
88         }
89
90         port = &rxe->port;
91
92         /* *attr being zeroed by the caller, avoid zeroing it here */
93         *attr = port->attr;
94
95         mutex_lock(&rxe->usdev_lock);
96         if (rxe->ndev->ethtool_ops->get_link_ksettings) {
97                 struct ethtool_link_ksettings ks;
98
99                 rxe->ndev->ethtool_ops->get_link_ksettings(rxe->ndev, &ks);
100                 speed = ks.base.speed;
101         } else if (rxe->ndev->ethtool_ops->get_settings) {
102                 struct ethtool_cmd cmd;
103
104                 rxe->ndev->ethtool_ops->get_settings(rxe->ndev, &cmd);
105                 speed = cmd.speed;
106         } else {
107                 pr_warn("%s speed is unknown, defaulting to 1000\n",
108                         rxe->ndev->name);
109                 speed = 1000;
110         }
111         rxe_eth_speed_to_ib_speed(speed, &attr->active_speed,
112                                   &attr->active_width);
113         mutex_unlock(&rxe->usdev_lock);
114
115         return 0;
116
117 err1:
118         return -EINVAL;
119 }
120
121 static int rxe_query_gid(struct ib_device *device,
122                          u8 port_num, int index, union ib_gid *gid)
123 {
124         int ret;
125
126         if (index > RXE_PORT_GID_TBL_LEN)
127                 return -EINVAL;
128
129         ret = ib_get_cached_gid(device, port_num, index, gid, NULL);
130         if (ret == -EAGAIN) {
131                 memcpy(gid, &zgid, sizeof(*gid));
132                 return 0;
133         }
134
135         return ret;
136 }
137
138 static int rxe_add_gid(struct ib_device *device, u8 port_num, unsigned int
139                        index, const union ib_gid *gid,
140                        const struct ib_gid_attr *attr, void **context)
141 {
142         if (index >= RXE_PORT_GID_TBL_LEN)
143                 return -EINVAL;
144         return 0;
145 }
146
147 static int rxe_del_gid(struct ib_device *device, u8 port_num, unsigned int
148                        index, void **context)
149 {
150         if (index >= RXE_PORT_GID_TBL_LEN)
151                 return -EINVAL;
152         return 0;
153 }
154
155 static struct net_device *rxe_get_netdev(struct ib_device *device,
156                                          u8 port_num)
157 {
158         struct rxe_dev *rxe = to_rdev(device);
159
160         if (rxe->ndev) {
161                 dev_hold(rxe->ndev);
162                 return rxe->ndev;
163         }
164
165         return NULL;
166 }
167
168 static int rxe_query_pkey(struct ib_device *device,
169                           u8 port_num, u16 index, u16 *pkey)
170 {
171         struct rxe_dev *rxe = to_rdev(device);
172         struct rxe_port *port;
173
174         if (unlikely(port_num != 1)) {
175                 dev_warn(device->dev.parent, "invalid port_num = %d\n",
176                          port_num);
177                 goto err1;
178         }
179
180         port = &rxe->port;
181
182         if (unlikely(index >= port->attr.pkey_tbl_len)) {
183                 dev_warn(device->dev.parent, "invalid index = %d\n",
184                          index);
185                 goto err1;
186         }
187
188         *pkey = port->pkey_tbl[index];
189         return 0;
190
191 err1:
192         return -EINVAL;
193 }
194
195 static int rxe_modify_device(struct ib_device *dev,
196                              int mask, struct ib_device_modify *attr)
197 {
198         struct rxe_dev *rxe = to_rdev(dev);
199
200         if (mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
201                 rxe->attr.sys_image_guid = cpu_to_be64(attr->sys_image_guid);
202
203         if (mask & IB_DEVICE_MODIFY_NODE_DESC) {
204                 memcpy(rxe->ib_dev.node_desc,
205                        attr->node_desc, sizeof(rxe->ib_dev.node_desc));
206         }
207
208         return 0;
209 }
210
211 static int rxe_modify_port(struct ib_device *dev,
212                            u8 port_num, int mask, struct ib_port_modify *attr)
213 {
214         struct rxe_dev *rxe = to_rdev(dev);
215         struct rxe_port *port;
216
217         if (unlikely(port_num != 1)) {
218                 pr_warn("invalid port_num = %d\n", port_num);
219                 goto err1;
220         }
221
222         port = &rxe->port;
223
224         port->attr.port_cap_flags |= attr->set_port_cap_mask;
225         port->attr.port_cap_flags &= ~attr->clr_port_cap_mask;
226
227         if (mask & IB_PORT_RESET_QKEY_CNTR)
228                 port->attr.qkey_viol_cntr = 0;
229
230         return 0;
231
232 err1:
233         return -EINVAL;
234 }
235
236 static enum rdma_link_layer rxe_get_link_layer(struct ib_device *dev,
237                                                u8 port_num)
238 {
239         struct rxe_dev *rxe = to_rdev(dev);
240
241         return rxe_link_layer(rxe, port_num);
242 }
243
244 static struct ib_ucontext *rxe_alloc_ucontext(struct ib_device *dev,
245                                               struct ib_udata *udata)
246 {
247         struct rxe_dev *rxe = to_rdev(dev);
248         struct rxe_ucontext *uc;
249
250         uc = rxe_alloc(&rxe->uc_pool);
251         return uc ? &uc->ibuc : ERR_PTR(-ENOMEM);
252 }
253
254 static int rxe_dealloc_ucontext(struct ib_ucontext *ibuc)
255 {
256         struct rxe_ucontext *uc = to_ruc(ibuc);
257
258         rxe_drop_ref(uc);
259         return 0;
260 }
261
262 static int rxe_port_immutable(struct ib_device *dev, u8 port_num,
263                               struct ib_port_immutable *immutable)
264 {
265         int err;
266         struct ib_port_attr attr;
267
268         immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
269
270         err = ib_query_port(dev, port_num, &attr);
271         if (err)
272                 return err;
273
274         immutable->pkey_tbl_len = attr.pkey_tbl_len;
275         immutable->gid_tbl_len = attr.gid_tbl_len;
276         immutable->max_mad_size = IB_MGMT_MAD_SIZE;
277
278         return 0;
279 }
280
281 static struct ib_pd *rxe_alloc_pd(struct ib_device *dev,
282                                   struct ib_ucontext *context,
283                                   struct ib_udata *udata)
284 {
285         struct rxe_dev *rxe = to_rdev(dev);
286         struct rxe_pd *pd;
287
288         pd = rxe_alloc(&rxe->pd_pool);
289         return pd ? &pd->ibpd : ERR_PTR(-ENOMEM);
290 }
291
292 static int rxe_dealloc_pd(struct ib_pd *ibpd)
293 {
294         struct rxe_pd *pd = to_rpd(ibpd);
295
296         rxe_drop_ref(pd);
297         return 0;
298 }
299
300 static int rxe_init_av(struct rxe_dev *rxe, struct ib_ah_attr *attr,
301                        struct rxe_av *av)
302 {
303         int err;
304         union ib_gid sgid;
305         struct ib_gid_attr sgid_attr;
306
307         err = ib_get_cached_gid(&rxe->ib_dev, attr->port_num,
308                                 attr->grh.sgid_index, &sgid,
309                                 &sgid_attr);
310         if (err) {
311                 pr_err("Failed to query sgid. err = %d\n", err);
312                 return err;
313         }
314
315         err = rxe_av_from_attr(rxe, attr->port_num, av, attr);
316         if (!err)
317                 err = rxe_av_fill_ip_info(rxe, av, attr, &sgid_attr, &sgid);
318
319         if (sgid_attr.ndev)
320                 dev_put(sgid_attr.ndev);
321         return err;
322 }
323
324 static struct ib_ah *rxe_create_ah(struct ib_pd *ibpd, struct ib_ah_attr *attr,
325                                    struct ib_udata *udata)
326
327 {
328         int err;
329         struct rxe_dev *rxe = to_rdev(ibpd->device);
330         struct rxe_pd *pd = to_rpd(ibpd);
331         struct rxe_ah *ah;
332
333         err = rxe_av_chk_attr(rxe, attr);
334         if (err)
335                 goto err1;
336
337         ah = rxe_alloc(&rxe->ah_pool);
338         if (!ah) {
339                 err = -ENOMEM;
340                 goto err1;
341         }
342
343         rxe_add_ref(pd);
344         ah->pd = pd;
345
346         err = rxe_init_av(rxe, attr, &ah->av);
347         if (err)
348                 goto err2;
349
350         return &ah->ibah;
351
352 err2:
353         rxe_drop_ref(pd);
354         rxe_drop_ref(ah);
355 err1:
356         return ERR_PTR(err);
357 }
358
359 static int rxe_modify_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
360 {
361         int err;
362         struct rxe_dev *rxe = to_rdev(ibah->device);
363         struct rxe_ah *ah = to_rah(ibah);
364
365         err = rxe_av_chk_attr(rxe, attr);
366         if (err)
367                 return err;
368
369         err = rxe_init_av(rxe, attr, &ah->av);
370         if (err)
371                 return err;
372
373         return 0;
374 }
375
376 static int rxe_query_ah(struct ib_ah *ibah, struct ib_ah_attr *attr)
377 {
378         struct rxe_dev *rxe = to_rdev(ibah->device);
379         struct rxe_ah *ah = to_rah(ibah);
380
381         memset(attr, 0, sizeof(*attr));
382         rxe_av_to_attr(rxe, &ah->av, attr);
383         return 0;
384 }
385
386 static int rxe_destroy_ah(struct ib_ah *ibah)
387 {
388         struct rxe_ah *ah = to_rah(ibah);
389
390         rxe_drop_ref(ah->pd);
391         rxe_drop_ref(ah);
392         return 0;
393 }
394
395 static int post_one_recv(struct rxe_rq *rq, struct ib_recv_wr *ibwr)
396 {
397         int err;
398         int i;
399         u32 length;
400         struct rxe_recv_wqe *recv_wqe;
401         int num_sge = ibwr->num_sge;
402
403         if (unlikely(queue_full(rq->queue))) {
404                 err = -ENOMEM;
405                 goto err1;
406         }
407
408         if (unlikely(num_sge > rq->max_sge)) {
409                 err = -EINVAL;
410                 goto err1;
411         }
412
413         length = 0;
414         for (i = 0; i < num_sge; i++)
415                 length += ibwr->sg_list[i].length;
416
417         recv_wqe = producer_addr(rq->queue);
418         recv_wqe->wr_id = ibwr->wr_id;
419         recv_wqe->num_sge = num_sge;
420
421         memcpy(recv_wqe->dma.sge, ibwr->sg_list,
422                num_sge * sizeof(struct ib_sge));
423
424         recv_wqe->dma.length            = length;
425         recv_wqe->dma.resid             = length;
426         recv_wqe->dma.num_sge           = num_sge;
427         recv_wqe->dma.cur_sge           = 0;
428         recv_wqe->dma.sge_offset        = 0;
429
430         /* make sure all changes to the work queue are written before we
431          * update the producer pointer
432          */
433         smp_wmb();
434
435         advance_producer(rq->queue);
436         return 0;
437
438 err1:
439         return err;
440 }
441
442 static struct ib_srq *rxe_create_srq(struct ib_pd *ibpd,
443                                      struct ib_srq_init_attr *init,
444                                      struct ib_udata *udata)
445 {
446         int err;
447         struct rxe_dev *rxe = to_rdev(ibpd->device);
448         struct rxe_pd *pd = to_rpd(ibpd);
449         struct rxe_srq *srq;
450         struct ib_ucontext *context = udata ? ibpd->uobject->context : NULL;
451
452         err = rxe_srq_chk_attr(rxe, NULL, &init->attr, IB_SRQ_INIT_MASK);
453         if (err)
454                 goto err1;
455
456         srq = rxe_alloc(&rxe->srq_pool);
457         if (!srq) {
458                 err = -ENOMEM;
459                 goto err1;
460         }
461
462         rxe_add_index(srq);
463         rxe_add_ref(pd);
464         srq->pd = pd;
465
466         err = rxe_srq_from_init(rxe, srq, init, context, udata);
467         if (err)
468                 goto err2;
469
470         return &srq->ibsrq;
471
472 err2:
473         rxe_drop_ref(pd);
474         rxe_drop_index(srq);
475         rxe_drop_ref(srq);
476 err1:
477         return ERR_PTR(err);
478 }
479
480 static int rxe_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
481                           enum ib_srq_attr_mask mask,
482                           struct ib_udata *udata)
483 {
484         int err;
485         struct rxe_srq *srq = to_rsrq(ibsrq);
486         struct rxe_dev *rxe = to_rdev(ibsrq->device);
487
488         err = rxe_srq_chk_attr(rxe, srq, attr, mask);
489         if (err)
490                 goto err1;
491
492         err = rxe_srq_from_attr(rxe, srq, attr, mask, udata);
493         if (err)
494                 goto err1;
495
496         return 0;
497
498 err1:
499         return err;
500 }
501
502 static int rxe_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr)
503 {
504         struct rxe_srq *srq = to_rsrq(ibsrq);
505
506         if (srq->error)
507                 return -EINVAL;
508
509         attr->max_wr = srq->rq.queue->buf->index_mask;
510         attr->max_sge = srq->rq.max_sge;
511         attr->srq_limit = srq->limit;
512         return 0;
513 }
514
515 static int rxe_destroy_srq(struct ib_srq *ibsrq)
516 {
517         struct rxe_srq *srq = to_rsrq(ibsrq);
518
519         if (srq->rq.queue)
520                 rxe_queue_cleanup(srq->rq.queue);
521
522         rxe_drop_ref(srq->pd);
523         rxe_drop_index(srq);
524         rxe_drop_ref(srq);
525
526         return 0;
527 }
528
529 static int rxe_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
530                              struct ib_recv_wr **bad_wr)
531 {
532         int err = 0;
533         unsigned long flags;
534         struct rxe_srq *srq = to_rsrq(ibsrq);
535
536         spin_lock_irqsave(&srq->rq.producer_lock, flags);
537
538         while (wr) {
539                 err = post_one_recv(&srq->rq, wr);
540                 if (unlikely(err))
541                         break;
542                 wr = wr->next;
543         }
544
545         spin_unlock_irqrestore(&srq->rq.producer_lock, flags);
546
547         if (err)
548                 *bad_wr = wr;
549
550         return err;
551 }
552
553 static struct ib_qp *rxe_create_qp(struct ib_pd *ibpd,
554                                    struct ib_qp_init_attr *init,
555                                    struct ib_udata *udata)
556 {
557         int err;
558         struct rxe_dev *rxe = to_rdev(ibpd->device);
559         struct rxe_pd *pd = to_rpd(ibpd);
560         struct rxe_qp *qp;
561
562         err = rxe_qp_chk_init(rxe, init);
563         if (err)
564                 goto err1;
565
566         qp = rxe_alloc(&rxe->qp_pool);
567         if (!qp) {
568                 err = -ENOMEM;
569                 goto err1;
570         }
571
572         if (udata) {
573                 if (udata->inlen) {
574                         err = -EINVAL;
575                         goto err2;
576                 }
577                 qp->is_user = 1;
578         }
579
580         rxe_add_index(qp);
581
582         err = rxe_qp_from_init(rxe, qp, pd, init, udata, ibpd);
583         if (err)
584                 goto err3;
585
586         return &qp->ibqp;
587
588 err3:
589         rxe_drop_index(qp);
590 err2:
591         rxe_drop_ref(qp);
592 err1:
593         return ERR_PTR(err);
594 }
595
596 static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
597                          int mask, struct ib_udata *udata)
598 {
599         int err;
600         struct rxe_dev *rxe = to_rdev(ibqp->device);
601         struct rxe_qp *qp = to_rqp(ibqp);
602
603         err = rxe_qp_chk_attr(rxe, qp, attr, mask);
604         if (err)
605                 goto err1;
606
607         err = rxe_qp_from_attr(qp, attr, mask, udata);
608         if (err)
609                 goto err1;
610
611         return 0;
612
613 err1:
614         return err;
615 }
616
617 static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
618                         int mask, struct ib_qp_init_attr *init)
619 {
620         struct rxe_qp *qp = to_rqp(ibqp);
621
622         rxe_qp_to_init(qp, init);
623         rxe_qp_to_attr(qp, attr, mask);
624
625         return 0;
626 }
627
628 static int rxe_destroy_qp(struct ib_qp *ibqp)
629 {
630         struct rxe_qp *qp = to_rqp(ibqp);
631
632         rxe_qp_destroy(qp);
633         rxe_drop_index(qp);
634         rxe_drop_ref(qp);
635         return 0;
636 }
637
638 static int validate_send_wr(struct rxe_qp *qp, struct ib_send_wr *ibwr,
639                             unsigned int mask, unsigned int length)
640 {
641         int num_sge = ibwr->num_sge;
642         struct rxe_sq *sq = &qp->sq;
643
644         if (unlikely(num_sge > sq->max_sge))
645                 goto err1;
646
647         if (unlikely(mask & WR_ATOMIC_MASK)) {
648                 if (length < 8)
649                         goto err1;
650
651                 if (atomic_wr(ibwr)->remote_addr & 0x7)
652                         goto err1;
653         }
654
655         if (unlikely((ibwr->send_flags & IB_SEND_INLINE) &&
656                      (length > sq->max_inline)))
657                 goto err1;
658
659         return 0;
660
661 err1:
662         return -EINVAL;
663 }
664
665 static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr,
666                          struct ib_send_wr *ibwr)
667 {
668         wr->wr_id = ibwr->wr_id;
669         wr->num_sge = ibwr->num_sge;
670         wr->opcode = ibwr->opcode;
671         wr->send_flags = ibwr->send_flags;
672
673         if (qp_type(qp) == IB_QPT_UD ||
674             qp_type(qp) == IB_QPT_SMI ||
675             qp_type(qp) == IB_QPT_GSI) {
676                 wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn;
677                 wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey;
678                 if (qp_type(qp) == IB_QPT_GSI)
679                         wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index;
680                 if (wr->opcode == IB_WR_SEND_WITH_IMM)
681                         wr->ex.imm_data = ibwr->ex.imm_data;
682         } else {
683                 switch (wr->opcode) {
684                 case IB_WR_RDMA_WRITE_WITH_IMM:
685                         wr->ex.imm_data = ibwr->ex.imm_data;
686                 case IB_WR_RDMA_READ:
687                 case IB_WR_RDMA_WRITE:
688                         wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr;
689                         wr->wr.rdma.rkey        = rdma_wr(ibwr)->rkey;
690                         break;
691                 case IB_WR_SEND_WITH_IMM:
692                         wr->ex.imm_data = ibwr->ex.imm_data;
693                         break;
694                 case IB_WR_SEND_WITH_INV:
695                         wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey;
696                         break;
697                 case IB_WR_ATOMIC_CMP_AND_SWP:
698                 case IB_WR_ATOMIC_FETCH_AND_ADD:
699                         wr->wr.atomic.remote_addr =
700                                 atomic_wr(ibwr)->remote_addr;
701                         wr->wr.atomic.compare_add =
702                                 atomic_wr(ibwr)->compare_add;
703                         wr->wr.atomic.swap = atomic_wr(ibwr)->swap;
704                         wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey;
705                         break;
706                 case IB_WR_LOCAL_INV:
707                         wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey;
708                 break;
709                 case IB_WR_REG_MR:
710                         wr->wr.reg.mr = reg_wr(ibwr)->mr;
711                         wr->wr.reg.key = reg_wr(ibwr)->key;
712                         wr->wr.reg.access = reg_wr(ibwr)->access;
713                 break;
714                 default:
715                         break;
716                 }
717         }
718 }
719
720 static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,
721                          unsigned int mask, unsigned int length,
722                          struct rxe_send_wqe *wqe)
723 {
724         int num_sge = ibwr->num_sge;
725         struct ib_sge *sge;
726         int i;
727         u8 *p;
728
729         init_send_wr(qp, &wqe->wr, ibwr);
730
731         if (qp_type(qp) == IB_QPT_UD ||
732             qp_type(qp) == IB_QPT_SMI ||
733             qp_type(qp) == IB_QPT_GSI)
734                 memcpy(&wqe->av, &to_rah(ud_wr(ibwr)->ah)->av, sizeof(wqe->av));
735
736         if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) {
737                 p = wqe->dma.inline_data;
738
739                 sge = ibwr->sg_list;
740                 for (i = 0; i < num_sge; i++, sge++) {
741                         if (qp->is_user && copy_from_user(p, (__user void *)
742                                             (uintptr_t)sge->addr, sge->length))
743                                 return -EFAULT;
744
745                         else if (!qp->is_user)
746                                 memcpy(p, (void *)(uintptr_t)sge->addr,
747                                        sge->length);
748
749                         p += sge->length;
750                 }
751         } else if (mask & WR_REG_MASK) {
752                 wqe->mask = mask;
753                 wqe->state = wqe_state_posted;
754                 return 0;
755         } else
756                 memcpy(wqe->dma.sge, ibwr->sg_list,
757                        num_sge * sizeof(struct ib_sge));
758
759         wqe->iova               = (mask & WR_ATOMIC_MASK) ?
760                                         atomic_wr(ibwr)->remote_addr :
761                                         rdma_wr(ibwr)->remote_addr;
762         wqe->mask               = mask;
763         wqe->dma.length         = length;
764         wqe->dma.resid          = length;
765         wqe->dma.num_sge        = num_sge;
766         wqe->dma.cur_sge        = 0;
767         wqe->dma.sge_offset     = 0;
768         wqe->state              = wqe_state_posted;
769         wqe->ssn                = atomic_add_return(1, &qp->ssn);
770
771         return 0;
772 }
773
774 static int post_one_send(struct rxe_qp *qp, struct ib_send_wr *ibwr,
775                          unsigned int mask, u32 length)
776 {
777         int err;
778         struct rxe_sq *sq = &qp->sq;
779         struct rxe_send_wqe *send_wqe;
780         unsigned long flags;
781
782         err = validate_send_wr(qp, ibwr, mask, length);
783         if (err)
784                 return err;
785
786         spin_lock_irqsave(&qp->sq.sq_lock, flags);
787
788         if (unlikely(queue_full(sq->queue))) {
789                 err = -ENOMEM;
790                 goto err1;
791         }
792
793         send_wqe = producer_addr(sq->queue);
794
795         err = init_send_wqe(qp, ibwr, mask, length, send_wqe);
796         if (unlikely(err))
797                 goto err1;
798
799         /*
800          * make sure all changes to the work queue are
801          * written before we update the producer pointer
802          */
803         smp_wmb();
804
805         advance_producer(sq->queue);
806         spin_unlock_irqrestore(&qp->sq.sq_lock, flags);
807
808         return 0;
809
810 err1:
811         spin_unlock_irqrestore(&qp->sq.sq_lock, flags);
812         return err;
813 }
814
815 static int rxe_post_send_kernel(struct rxe_qp *qp, struct ib_send_wr *wr,
816                                 struct ib_send_wr **bad_wr)
817 {
818         int err = 0;
819         unsigned int mask;
820         unsigned int length = 0;
821         int i;
822         int must_sched;
823
824         while (wr) {
825                 mask = wr_opcode_mask(wr->opcode, qp);
826                 if (unlikely(!mask)) {
827                         err = -EINVAL;
828                         *bad_wr = wr;
829                         break;
830                 }
831
832                 if (unlikely((wr->send_flags & IB_SEND_INLINE) &&
833                              !(mask & WR_INLINE_MASK))) {
834                         err = -EINVAL;
835                         *bad_wr = wr;
836                         break;
837                 }
838
839                 length = 0;
840                 for (i = 0; i < wr->num_sge; i++)
841                         length += wr->sg_list[i].length;
842
843                 err = post_one_send(qp, wr, mask, length);
844
845                 if (err) {
846                         *bad_wr = wr;
847                         break;
848                 }
849                 wr = wr->next;
850         }
851
852         /*
853          * Must sched in case of GSI QP because ib_send_mad() hold irq lock,
854          * and the requester call ip_local_out_sk() that takes spin_lock_bh.
855          */
856         must_sched = (qp_type(qp) == IB_QPT_GSI) ||
857                         (queue_count(qp->sq.queue) > 1);
858
859         rxe_run_task(&qp->req.task, must_sched);
860
861         return err;
862 }
863
864 static int rxe_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
865                          struct ib_send_wr **bad_wr)
866 {
867         struct rxe_qp *qp = to_rqp(ibqp);
868
869         if (unlikely(!qp->valid)) {
870                 *bad_wr = wr;
871                 return -EINVAL;
872         }
873
874         if (unlikely(qp->req.state < QP_STATE_READY)) {
875                 *bad_wr = wr;
876                 return -EINVAL;
877         }
878
879         if (qp->is_user) {
880                 /* Utilize process context to do protocol processing */
881                 rxe_run_task(&qp->req.task, 0);
882                 return 0;
883         } else
884                 return rxe_post_send_kernel(qp, wr, bad_wr);
885 }
886
887 static int rxe_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
888                          struct ib_recv_wr **bad_wr)
889 {
890         int err = 0;
891         struct rxe_qp *qp = to_rqp(ibqp);
892         struct rxe_rq *rq = &qp->rq;
893         unsigned long flags;
894
895         if (unlikely((qp_state(qp) < IB_QPS_INIT) || !qp->valid)) {
896                 *bad_wr = wr;
897                 err = -EINVAL;
898                 goto err1;
899         }
900
901         if (unlikely(qp->srq)) {
902                 *bad_wr = wr;
903                 err = -EINVAL;
904                 goto err1;
905         }
906
907         spin_lock_irqsave(&rq->producer_lock, flags);
908
909         while (wr) {
910                 err = post_one_recv(rq, wr);
911                 if (unlikely(err)) {
912                         *bad_wr = wr;
913                         break;
914                 }
915                 wr = wr->next;
916         }
917
918         spin_unlock_irqrestore(&rq->producer_lock, flags);
919
920 err1:
921         return err;
922 }
923
924 static struct ib_cq *rxe_create_cq(struct ib_device *dev,
925                                    const struct ib_cq_init_attr *attr,
926                                    struct ib_ucontext *context,
927                                    struct ib_udata *udata)
928 {
929         int err;
930         struct rxe_dev *rxe = to_rdev(dev);
931         struct rxe_cq *cq;
932
933         if (attr->flags)
934                 return ERR_PTR(-EINVAL);
935
936         err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector, udata);
937         if (err)
938                 goto err1;
939
940         cq = rxe_alloc(&rxe->cq_pool);
941         if (!cq) {
942                 err = -ENOMEM;
943                 goto err1;
944         }
945
946         err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector,
947                                context, udata);
948         if (err)
949                 goto err2;
950
951         return &cq->ibcq;
952
953 err2:
954         rxe_drop_ref(cq);
955 err1:
956         return ERR_PTR(err);
957 }
958
959 static int rxe_destroy_cq(struct ib_cq *ibcq)
960 {
961         struct rxe_cq *cq = to_rcq(ibcq);
962
963         rxe_drop_ref(cq);
964         return 0;
965 }
966
967 static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
968 {
969         int err;
970         struct rxe_cq *cq = to_rcq(ibcq);
971         struct rxe_dev *rxe = to_rdev(ibcq->device);
972
973         err = rxe_cq_chk_attr(rxe, cq, cqe, 0, udata);
974         if (err)
975                 goto err1;
976
977         err = rxe_cq_resize_queue(cq, cqe, udata);
978         if (err)
979                 goto err1;
980
981         return 0;
982
983 err1:
984         return err;
985 }
986
987 static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
988 {
989         int i;
990         struct rxe_cq *cq = to_rcq(ibcq);
991         struct rxe_cqe *cqe;
992         unsigned long flags;
993
994         spin_lock_irqsave(&cq->cq_lock, flags);
995         for (i = 0; i < num_entries; i++) {
996                 cqe = queue_head(cq->queue);
997                 if (!cqe)
998                         break;
999
1000                 memcpy(wc++, &cqe->ibwc, sizeof(*wc));
1001                 advance_consumer(cq->queue);
1002         }
1003         spin_unlock_irqrestore(&cq->cq_lock, flags);
1004
1005         return i;
1006 }
1007
1008 static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt)
1009 {
1010         struct rxe_cq *cq = to_rcq(ibcq);
1011         int count = queue_count(cq->queue);
1012
1013         return (count > wc_cnt) ? wc_cnt : count;
1014 }
1015
1016 static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
1017 {
1018         struct rxe_cq *cq = to_rcq(ibcq);
1019         unsigned long irq_flags;
1020         int ret = 0;
1021
1022         spin_lock_irqsave(&cq->cq_lock, irq_flags);
1023         if (cq->notify != IB_CQ_NEXT_COMP)
1024                 cq->notify = flags & IB_CQ_SOLICITED_MASK;
1025
1026         if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !queue_empty(cq->queue))
1027                 ret = 1;
1028
1029         spin_unlock_irqrestore(&cq->cq_lock, irq_flags);
1030
1031         return ret;
1032 }
1033
1034 static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access)
1035 {
1036         struct rxe_dev *rxe = to_rdev(ibpd->device);
1037         struct rxe_pd *pd = to_rpd(ibpd);
1038         struct rxe_mem *mr;
1039         int err;
1040
1041         mr = rxe_alloc(&rxe->mr_pool);
1042         if (!mr) {
1043                 err = -ENOMEM;
1044                 goto err1;
1045         }
1046
1047         rxe_add_index(mr);
1048
1049         rxe_add_ref(pd);
1050
1051         err = rxe_mem_init_dma(rxe, pd, access, mr);
1052         if (err)
1053                 goto err2;
1054
1055         return &mr->ibmr;
1056
1057 err2:
1058         rxe_drop_ref(pd);
1059         rxe_drop_index(mr);
1060         rxe_drop_ref(mr);
1061 err1:
1062         return ERR_PTR(err);
1063 }
1064
1065 static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd,
1066                                      u64 start,
1067                                      u64 length,
1068                                      u64 iova,
1069                                      int access, struct ib_udata *udata)
1070 {
1071         int err;
1072         struct rxe_dev *rxe = to_rdev(ibpd->device);
1073         struct rxe_pd *pd = to_rpd(ibpd);
1074         struct rxe_mem *mr;
1075
1076         mr = rxe_alloc(&rxe->mr_pool);
1077         if (!mr) {
1078                 err = -ENOMEM;
1079                 goto err2;
1080         }
1081
1082         rxe_add_index(mr);
1083
1084         rxe_add_ref(pd);
1085
1086         err = rxe_mem_init_user(rxe, pd, start, length, iova,
1087                                 access, udata, mr);
1088         if (err)
1089                 goto err3;
1090
1091         return &mr->ibmr;
1092
1093 err3:
1094         rxe_drop_ref(pd);
1095         rxe_drop_index(mr);
1096         rxe_drop_ref(mr);
1097 err2:
1098         return ERR_PTR(err);
1099 }
1100
1101 static int rxe_dereg_mr(struct ib_mr *ibmr)
1102 {
1103         struct rxe_mem *mr = to_rmr(ibmr);
1104
1105         mr->state = RXE_MEM_STATE_ZOMBIE;
1106         rxe_drop_ref(mr->pd);
1107         rxe_drop_index(mr);
1108         rxe_drop_ref(mr);
1109         return 0;
1110 }
1111
1112 static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd,
1113                                   enum ib_mr_type mr_type,
1114                                   u32 max_num_sg)
1115 {
1116         struct rxe_dev *rxe = to_rdev(ibpd->device);
1117         struct rxe_pd *pd = to_rpd(ibpd);
1118         struct rxe_mem *mr;
1119         int err;
1120
1121         if (mr_type != IB_MR_TYPE_MEM_REG)
1122                 return ERR_PTR(-EINVAL);
1123
1124         mr = rxe_alloc(&rxe->mr_pool);
1125         if (!mr) {
1126                 err = -ENOMEM;
1127                 goto err1;
1128         }
1129
1130         rxe_add_index(mr);
1131
1132         rxe_add_ref(pd);
1133
1134         err = rxe_mem_init_fast(rxe, pd, max_num_sg, mr);
1135         if (err)
1136                 goto err2;
1137
1138         return &mr->ibmr;
1139
1140 err2:
1141         rxe_drop_ref(pd);
1142         rxe_drop_index(mr);
1143         rxe_drop_ref(mr);
1144 err1:
1145         return ERR_PTR(err);
1146 }
1147
1148 static int rxe_set_page(struct ib_mr *ibmr, u64 addr)
1149 {
1150         struct rxe_mem *mr = to_rmr(ibmr);
1151         struct rxe_map *map;
1152         struct rxe_phys_buf *buf;
1153
1154         if (unlikely(mr->nbuf == mr->num_buf))
1155                 return -ENOMEM;
1156
1157         map = mr->map[mr->nbuf / RXE_BUF_PER_MAP];
1158         buf = &map->buf[mr->nbuf % RXE_BUF_PER_MAP];
1159
1160         buf->addr = addr;
1161         buf->size = ibmr->page_size;
1162         mr->nbuf++;
1163
1164         return 0;
1165 }
1166
1167 static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg,
1168                          int sg_nents, unsigned int *sg_offset)
1169 {
1170         struct rxe_mem *mr = to_rmr(ibmr);
1171         int n;
1172
1173         mr->nbuf = 0;
1174
1175         n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page);
1176
1177         mr->va = ibmr->iova;
1178         mr->iova = ibmr->iova;
1179         mr->length = ibmr->length;
1180         mr->page_shift = ilog2(ibmr->page_size);
1181         mr->page_mask = ibmr->page_size - 1;
1182         mr->offset = mr->iova & mr->page_mask;
1183
1184         return n;
1185 }
1186
1187 static int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
1188 {
1189         int err;
1190         struct rxe_dev *rxe = to_rdev(ibqp->device);
1191         struct rxe_qp *qp = to_rqp(ibqp);
1192         struct rxe_mc_grp *grp;
1193
1194         /* takes a ref on grp if successful */
1195         err = rxe_mcast_get_grp(rxe, mgid, &grp);
1196         if (err)
1197                 return err;
1198
1199         err = rxe_mcast_add_grp_elem(rxe, qp, grp);
1200
1201         rxe_drop_ref(grp);
1202         return err;
1203 }
1204
1205 static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
1206 {
1207         struct rxe_dev *rxe = to_rdev(ibqp->device);
1208         struct rxe_qp *qp = to_rqp(ibqp);
1209
1210         return rxe_mcast_drop_grp_elem(rxe, qp, mgid);
1211 }
1212
1213 static ssize_t rxe_show_parent(struct device *device,
1214                                struct device_attribute *attr, char *buf)
1215 {
1216         struct rxe_dev *rxe = container_of(device, struct rxe_dev,
1217                                            ib_dev.dev);
1218
1219         return snprintf(buf, 16, "%s\n", rxe_parent_name(rxe, 1));
1220 }
1221
1222 static DEVICE_ATTR(parent, S_IRUGO, rxe_show_parent, NULL);
1223
1224 static struct device_attribute *rxe_dev_attributes[] = {
1225         &dev_attr_parent,
1226 };
1227
1228 int rxe_register_device(struct rxe_dev *rxe)
1229 {
1230         int err;
1231         int i;
1232         struct ib_device *dev = &rxe->ib_dev;
1233
1234         strlcpy(dev->name, "rxe%d", IB_DEVICE_NAME_MAX);
1235         strlcpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
1236
1237         dev->owner = THIS_MODULE;
1238         dev->node_type = RDMA_NODE_IB_CA;
1239         dev->phys_port_cnt = 1;
1240         dev->num_comp_vectors = RXE_NUM_COMP_VECTORS;
1241         dev->dev.parent = rxe_dma_device(rxe);
1242         dev->local_dma_lkey = 0;
1243         addrconf_addr_eui48((unsigned char *)&dev->node_guid,
1244                             rxe->ndev->dev_addr);
1245         dev->dev.dma_ops = &dma_virt_ops;
1246
1247         dev->uverbs_abi_ver = RXE_UVERBS_ABI_VERSION;
1248         dev->uverbs_cmd_mask = BIT_ULL(IB_USER_VERBS_CMD_GET_CONTEXT)
1249             | BIT_ULL(IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)
1250             | BIT_ULL(IB_USER_VERBS_CMD_QUERY_DEVICE)
1251             | BIT_ULL(IB_USER_VERBS_CMD_QUERY_PORT)
1252             | BIT_ULL(IB_USER_VERBS_CMD_ALLOC_PD)
1253             | BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_PD)
1254             | BIT_ULL(IB_USER_VERBS_CMD_CREATE_SRQ)
1255             | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_SRQ)
1256             | BIT_ULL(IB_USER_VERBS_CMD_QUERY_SRQ)
1257             | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_SRQ)
1258             | BIT_ULL(IB_USER_VERBS_CMD_POST_SRQ_RECV)
1259             | BIT_ULL(IB_USER_VERBS_CMD_CREATE_QP)
1260             | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_QP)
1261             | BIT_ULL(IB_USER_VERBS_CMD_QUERY_QP)
1262             | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_QP)
1263             | BIT_ULL(IB_USER_VERBS_CMD_POST_SEND)
1264             | BIT_ULL(IB_USER_VERBS_CMD_POST_RECV)
1265             | BIT_ULL(IB_USER_VERBS_CMD_CREATE_CQ)
1266             | BIT_ULL(IB_USER_VERBS_CMD_RESIZE_CQ)
1267             | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_CQ)
1268             | BIT_ULL(IB_USER_VERBS_CMD_POLL_CQ)
1269             | BIT_ULL(IB_USER_VERBS_CMD_PEEK_CQ)
1270             | BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ)
1271             | BIT_ULL(IB_USER_VERBS_CMD_REG_MR)
1272             | BIT_ULL(IB_USER_VERBS_CMD_DEREG_MR)
1273             | BIT_ULL(IB_USER_VERBS_CMD_CREATE_AH)
1274             | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_AH)
1275             | BIT_ULL(IB_USER_VERBS_CMD_QUERY_AH)
1276             | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_AH)
1277             | BIT_ULL(IB_USER_VERBS_CMD_ATTACH_MCAST)
1278             | BIT_ULL(IB_USER_VERBS_CMD_DETACH_MCAST)
1279             ;
1280
1281         dev->query_device = rxe_query_device;
1282         dev->modify_device = rxe_modify_device;
1283         dev->query_port = rxe_query_port;
1284         dev->modify_port = rxe_modify_port;
1285         dev->get_link_layer = rxe_get_link_layer;
1286         dev->query_gid = rxe_query_gid;
1287         dev->get_netdev = rxe_get_netdev;
1288         dev->add_gid = rxe_add_gid;
1289         dev->del_gid = rxe_del_gid;
1290         dev->query_pkey = rxe_query_pkey;
1291         dev->alloc_ucontext = rxe_alloc_ucontext;
1292         dev->dealloc_ucontext = rxe_dealloc_ucontext;
1293         dev->mmap = rxe_mmap;
1294         dev->get_port_immutable = rxe_port_immutable;
1295         dev->alloc_pd = rxe_alloc_pd;
1296         dev->dealloc_pd = rxe_dealloc_pd;
1297         dev->create_ah = rxe_create_ah;
1298         dev->modify_ah = rxe_modify_ah;
1299         dev->query_ah = rxe_query_ah;
1300         dev->destroy_ah = rxe_destroy_ah;
1301         dev->create_srq = rxe_create_srq;
1302         dev->modify_srq = rxe_modify_srq;
1303         dev->query_srq = rxe_query_srq;
1304         dev->destroy_srq = rxe_destroy_srq;
1305         dev->post_srq_recv = rxe_post_srq_recv;
1306         dev->create_qp = rxe_create_qp;
1307         dev->modify_qp = rxe_modify_qp;
1308         dev->query_qp = rxe_query_qp;
1309         dev->destroy_qp = rxe_destroy_qp;
1310         dev->post_send = rxe_post_send;
1311         dev->post_recv = rxe_post_recv;
1312         dev->create_cq = rxe_create_cq;
1313         dev->destroy_cq = rxe_destroy_cq;
1314         dev->resize_cq = rxe_resize_cq;
1315         dev->poll_cq = rxe_poll_cq;
1316         dev->peek_cq = rxe_peek_cq;
1317         dev->req_notify_cq = rxe_req_notify_cq;
1318         dev->get_dma_mr = rxe_get_dma_mr;
1319         dev->reg_user_mr = rxe_reg_user_mr;
1320         dev->dereg_mr = rxe_dereg_mr;
1321         dev->alloc_mr = rxe_alloc_mr;
1322         dev->map_mr_sg = rxe_map_mr_sg;
1323         dev->attach_mcast = rxe_attach_mcast;
1324         dev->detach_mcast = rxe_detach_mcast;
1325         dev->get_hw_stats = rxe_ib_get_hw_stats;
1326         dev->alloc_hw_stats = rxe_ib_alloc_hw_stats;
1327
1328         rxe->tfm = crypto_alloc_shash("crc32", 0, 0);
1329         if (IS_ERR(rxe->tfm)) {
1330                 pr_err("failed to allocate crc algorithm err:%ld\n",
1331                        PTR_ERR(rxe->tfm));
1332                 return PTR_ERR(rxe->tfm);
1333         }
1334
1335         err = ib_register_device(dev, NULL);
1336         if (err) {
1337                 pr_warn("rxe_register_device failed, err = %d\n", err);
1338                 goto err1;
1339         }
1340
1341         for (i = 0; i < ARRAY_SIZE(rxe_dev_attributes); ++i) {
1342                 err = device_create_file(&dev->dev, rxe_dev_attributes[i]);
1343                 if (err) {
1344                         pr_warn("device_create_file failed, i = %d, err = %d\n",
1345                                 i, err);
1346                         goto err2;
1347                 }
1348         }
1349
1350         return 0;
1351
1352 err2:
1353         ib_unregister_device(dev);
1354 err1:
1355         crypto_free_shash(rxe->tfm);
1356
1357         return err;
1358 }
1359
1360 int rxe_unregister_device(struct rxe_dev *rxe)
1361 {
1362         int i;
1363         struct ib_device *dev = &rxe->ib_dev;
1364
1365         for (i = 0; i < ARRAY_SIZE(rxe_dev_attributes); ++i)
1366                 device_remove_file(&dev->dev, rxe_dev_attributes[i]);
1367
1368         ib_unregister_device(dev);
1369
1370         return 0;
1371 }