[openib-general] Gen2 OpenSM

shaharf shaharf at voltaire.com
Thu Dec 23 13:48:30 PST 2004


Ok, I will send the relevant function from user_mad file. Please forgive me not to send you a proper patch. I am already at home and I don't want to mess up my Wife's computer ;-)
 
Aha - BTW, what I really meant is that OpenSM can bring up IPoIB (small mistake for me, big progress for the openib...;-). 
 
I will send a proper patch on Sunday.
 
Happy Christmas everybody!

Shahar

_________________________________
 
static int mad_is_solicit(struct ib_mad_hdr *madhdr)
{
        int method = madhdr->method;

        // filter only request methods according to IB spec V1.2 13.4.5 and C13-6
        return (method < IB_MGMT_METHOD_RESP &&
                method != IB_MGMT_METHOD_SEND &&
                method != IB_MGMT_METHOD_TRAP &&
                method != IB_MGMT_METHOD_TRAP_REPRESS);
}


static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
                             size_t count, loff_t *pos)
{
        struct ib_umad_file *file = filp->private_data;
        struct ib_umad_packet *packet;
        struct ib_mad_agent *agent;
        struct ib_ah_attr ah_attr;
        struct ib_sge      gather_list;
        struct ib_send_wr *bad_wr, wr = {
                .opcode      = IB_WR_SEND,
                .sg_list     = &gather_list,
                .num_sge     = 1,
                .send_flags  = IB_SEND_SIGNALED,
        };
        int ret;

        if (count < sizeof (struct ib_user_mad))
                return -EINVAL;

        packet = kmalloc(sizeof *packet, GFP_KERNEL);
        if (!packet)
                return -ENOMEM;

        if (copy_from_user(&packet->mad, buf, sizeof packet->mad)) {
                kfree(packet);
                return -EFAULT;
        }

        if (packet->mad.id < 0 || packet->mad.id >= IB_UMAD_MAX_AGENTS) {
                ret = -EINVAL;
                goto err;
        }

        down_read(&file->agent_mutex);

        agent = file->agent[packet->mad.id];
        if (!agent) {
                ret = -EINVAL;
                goto err_up;
        }

        if (mad_is_solicit((struct ib_mad_hdr *)packet->mad.data)) {
                ((struct ib_mad_hdr *) packet->mad.data)->tid =
                        cpu_to_be64(((u64) agent->hi_tid) << 32 |
                            (be64_to_cpu(((struct ib_mad_hdr *) packet->mad.data)->tid) &
                             0xffffffff));
        }

        memset(&ah_attr, 0, sizeof ah_attr);
        ah_attr.dlid          = be16_to_cpu(packet->mad.lid);
        ah_attr.sl            = packet->mad.sl;
        ah_attr.src_path_bits = packet->mad.path_bits;
        ah_attr.port_num      = file->port->port_num;
        /* XXX handle GRH */

        packet->ah = ib_create_ah(agent->qp->pd, &ah_attr);
        if (IS_ERR(packet->ah)) {
                ret = PTR_ERR(packet->ah);
                goto err_up;
        }

        gather_list.addr = dma_map_single(agent->device->dma_device,
                                          packet->mad.data,
                                          sizeof packet->mad.data,
                                          DMA_TO_DEVICE);
        gather_list.length = sizeof packet->mad.data;
        gather_list.lkey   = file->mr[packet->mad.id]->lkey;
        pci_unmap_addr_set(packet, mapping, gather_list.addr);

        wr.wr.ud.mad_hdr     = (struct ib_mad_hdr *) packet->mad.data;
        wr.wr.ud.ah          = packet->ah;
        wr.wr.ud.remote_qpn  = be32_to_cpu(packet->mad.qpn);
        wr.wr.ud.remote_qkey = be32_to_cpu(packet->mad.qkey);
        wr.wr.ud.timeout_ms  = packet->mad.timeout_ms;

        wr.wr_id            = (unsigned long) packet;

        ret = ib_post_send_mad(agent, &wr, &bad_wr);
        if (ret) {
                dma_unmap_single(agent->device->dma_device,
                                 pci_unmap_addr(packet, mapping),
                                 sizeof packet->mad.data,
                                 DMA_TO_DEVICE);
                goto err_up;
        }

        up_read(&file->agent_mutex);

        return sizeof packet->mad;

err_up:
        up_read(&file->agent_mutex);

err:
        kfree(packet);
        return ret;
}


 
 



More information about the general mailing list