static struct ib_mad_send_buf *get_sa_msg(struct sa_db_port *port, struct update_info *update) { struct ib_ah_attr ah_attr; struct ib_mad_send_buf *msg; msg = ib_create_send_mad(port->agent, 1, 0, 0, IB_MGMT_SA_HDR, IB_MGMT_SA_DATA, GFP_KERNEL); if (IS_ERR(msg)) return NULL; memset(&ah_attr, 0, sizeof ah_attr); ah_attr.dlid = port->sm_lid; ah_attr.sl = port->sm_sl; ah_attr.port_num = port->port_num; msg->ah = ib_create_ah(port->agent->qp->pd, &ah_attr); if (IS_ERR(msg->ah)) { ib_free_send_mad(msg); return NULL; } msg->timeout_ms = retry_timer; msg->retries = 0; msg->context[0] = port; msg->context[1] = update; return msg; }
static void update_sm_ah(struct mthca_dev *dev, u8 port_num, u16 lid, u8 sl) { struct ib_ah *new_ah; struct ib_ah_attr ah_attr; unsigned long flags; if (!dev->send_agent[port_num - 1][0]) return; memset(&ah_attr, 0, sizeof ah_attr); ah_attr.dlid = lid; ah_attr.sl = sl; ah_attr.port_num = port_num; new_ah = ib_create_ah(dev->send_agent[port_num - 1][0]->qp->pd, &ah_attr); if (IS_ERR(new_ah)) return; spin_lock_irqsave(&dev->sm_lock, flags); if (dev->sm_ah[port_num - 1]) ib_destroy_ah(dev->sm_ah[port_num - 1]); dev->sm_ah[port_num - 1] = new_ah; spin_unlock_irqrestore(&dev->sm_lock, flags); }
static void verbs_path_rec_completion (int status, struct ib_sa_path_rec *resp, void *context) { struct ib_ah_attr av; int ret; printk (KERN_INFO "path_rec_completion called. Status = %d\n", status); if (!status) { if (!ib_init_ah_from_path (ib_dev, 1, resp, &av)) { printk (KERN_INFO "ah: flags = %d, dlid = %d, port = %d\n", (int)av.ah_flags, (int)av.dlid, (int)av.port_num); ah = ib_create_ah (pd, &av); if (IS_ERR (ah)) { ret = PTR_ERR (ah); printk (KERN_INFO "ib_create_ah failed: %d\n", ret); return; } path = *resp; have_path = 1; } } }
ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, const char __user *buf, int in_len, int out_len) { struct ib_uverbs_create_ah cmd; struct ib_uverbs_create_ah_resp resp; struct ib_uobject *uobj; struct ib_pd *pd; struct ib_ah *ah; struct ib_ah_attr attr; int ret; if (out_len < sizeof resp) return -ENOSPC; if (copy_from_user(&cmd, buf, sizeof cmd)) return -EFAULT; uobj = kmalloc(sizeof *uobj, GFP_KERNEL); if (!uobj) return -ENOMEM; mutex_lock(&ib_uverbs_idr_mutex); pd = idr_find(&ib_uverbs_pd_idr, cmd.pd_handle); if (!pd || pd->uobject->context != file->ucontext) { ret = -EINVAL; goto err_up; } uobj->user_handle = cmd.user_handle; uobj->context = file->ucontext; attr.dlid = cmd.attr.dlid; attr.sl = cmd.attr.sl; attr.src_path_bits = cmd.attr.src_path_bits; attr.static_rate = cmd.attr.static_rate; attr.ah_flags = cmd.attr.is_global ? IB_AH_GRH : 0; attr.port_num = cmd.attr.port_num; attr.grh.flow_label = cmd.attr.grh.flow_label; attr.grh.sgid_index = cmd.attr.grh.sgid_index; attr.grh.hop_limit = cmd.attr.grh.hop_limit; attr.grh.traffic_class = cmd.attr.grh.traffic_class; memcpy(attr.grh.dgid.raw, cmd.attr.grh.dgid, 16); ah = ib_create_ah(pd, &attr); if (IS_ERR(ah)) { ret = PTR_ERR(ah); goto err_up; } ah->uobject = uobj; retry: if (!idr_pre_get(&ib_uverbs_ah_idr, GFP_KERNEL)) { ret = -ENOMEM; goto err_destroy; } ret = idr_get_new(&ib_uverbs_ah_idr, ah, &uobj->id); if (ret == -EAGAIN) goto retry; if (ret) goto err_destroy; resp.ah_handle = uobj->id; if (copy_to_user((void __user *) (unsigned long) cmd.response, &resp, sizeof resp)) { ret = -EFAULT; goto err_idr; } mutex_lock(&file->mutex); list_add_tail(&uobj->list, &file->ucontext->ah_list); mutex_unlock(&file->mutex); mutex_unlock(&ib_uverbs_idr_mutex); return in_len; err_idr: idr_remove(&ib_uverbs_ah_idr, uobj->id); err_destroy: ib_destroy_ah(ah); err_up: mutex_unlock(&ib_uverbs_idr_mutex); kfree(uobj); return ret; }