Lines Matching refs:file

150 static int hdr_size(struct ib_umad_file *file)  in hdr_size()  argument
152 return file->use_pkey_index ? sizeof (struct ib_user_mad_hdr) : in hdr_size()
157 static struct ib_mad_agent *__get_agent(struct ib_umad_file *file, int id) in __get_agent() argument
159 return file->agents_dead ? NULL : file->agent[id]; in __get_agent()
162 static int queue_packet(struct ib_umad_file *file, in queue_packet() argument
168 mutex_lock(&file->mutex); in queue_packet()
173 if (agent == __get_agent(file, packet->mad.hdr.id)) { in queue_packet()
174 list_add_tail(&packet->list, &file->recv_list); in queue_packet()
175 wake_up_interruptible(&file->recv_wait); in queue_packet()
180 mutex_unlock(&file->mutex); in queue_packet()
185 static void dequeue_send(struct ib_umad_file *file, in dequeue_send() argument
188 spin_lock_irq(&file->send_lock); in dequeue_send()
190 spin_unlock_irq(&file->send_lock); in dequeue_send()
196 struct ib_umad_file *file = agent->context; in send_handler() local
199 dequeue_send(file, packet); in send_handler()
206 if (!queue_packet(file, agent, packet)) in send_handler()
215 struct ib_umad_file *file = agent->context; in recv_handler() local
229 packet->mad.hdr.length = hdr_size(file) + mad_recv_wc->mad_len; in recv_handler()
250 if (queue_packet(file, agent, packet)) in recv_handler()
260 static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf, in copy_recv_mad() argument
272 count < hdr_size(file) + packet->length) || in copy_recv_mad()
274 count < hdr_size(file) + seg_size)) in copy_recv_mad()
277 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_recv_mad()
280 buf += hdr_size(file); in copy_recv_mad()
290 if (count < hdr_size(file) + packet->length) { in copy_recv_mad()
310 return hdr_size(file) + packet->length; in copy_recv_mad()
313 static ssize_t copy_send_mad(struct ib_umad_file *file, char __user *buf, in copy_send_mad() argument
316 ssize_t size = hdr_size(file) + packet->length; in copy_send_mad()
321 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_send_mad()
324 buf += hdr_size(file); in copy_send_mad()
332 static ssize_t ib_umad_read(struct file *filp, char __user *buf, in ib_umad_read()
335 struct ib_umad_file *file = filp->private_data; in ib_umad_read() local
339 if (count < hdr_size(file)) in ib_umad_read()
342 mutex_lock(&file->mutex); in ib_umad_read()
344 while (list_empty(&file->recv_list)) { in ib_umad_read()
345 mutex_unlock(&file->mutex); in ib_umad_read()
350 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
351 !list_empty(&file->recv_list))) in ib_umad_read()
354 mutex_lock(&file->mutex); in ib_umad_read()
357 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
360 mutex_unlock(&file->mutex); in ib_umad_read()
363 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
365 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
369 mutex_lock(&file->mutex); in ib_umad_read()
370 list_add(&packet->list, &file->recv_list); in ib_umad_read()
371 mutex_unlock(&file->mutex); in ib_umad_read()
412 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
419 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
445 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
448 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
458 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
465 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
475 buf += hdr_size(file); in ib_umad_write()
482 mutex_lock(&file->mutex); in ib_umad_write()
484 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
494 ah_attr.port_num = file->port->port_num; in ib_umad_write()
524 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
571 spin_lock_irq(&file->send_lock); in ib_umad_write()
572 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
573 spin_unlock_irq(&file->send_lock); in ib_umad_write()
575 spin_lock_irq(&file->send_lock); in ib_umad_write()
576 ret = is_duplicate(file, packet); in ib_umad_write()
578 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
579 spin_unlock_irq(&file->send_lock); in ib_umad_write()
590 mutex_unlock(&file->mutex); in ib_umad_write()
594 dequeue_send(file, packet); in ib_umad_write()
600 mutex_unlock(&file->mutex); in ib_umad_write()
606 static unsigned int ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
608 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
613 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
615 if (!list_empty(&file->recv_list)) in ib_umad_poll()
621 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
630 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
631 mutex_lock(&file->mutex); in ib_umad_reg_agent()
633 if (!file->port->ib_dev) { in ib_umad_reg_agent()
634 dev_notice(file->port->dev, in ib_umad_reg_agent()
646 dev_notice(file->port->dev, in ib_umad_reg_agent()
654 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
657 dev_notice(file->port->dev, in ib_umad_reg_agent()
682 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
686 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
699 if (!file->already_used) { in ib_umad_reg_agent()
700 file->already_used = 1; in ib_umad_reg_agent()
701 if (!file->use_pkey_index) { in ib_umad_reg_agent()
702 dev_warn(file->port->dev, in ib_umad_reg_agent()
705 dev_warn(file->port->dev, in ib_umad_reg_agent()
710 file->agent[agent_id] = agent; in ib_umad_reg_agent()
714 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
719 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
724 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
732 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
733 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
735 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
736 dev_notice(file->port->dev, in ib_umad_reg_agent2()
748 dev_notice(file->port->dev, in ib_umad_reg_agent2()
756 dev_notice(file->port->dev, in ib_umad_reg_agent2()
770 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
773 dev_notice(file->port->dev, in ib_umad_reg_agent2()
785 dev_notice(file->port->dev, in ib_umad_reg_agent2()
798 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
802 send_handler, recv_handler, file, in ib_umad_reg_agent2()
817 if (!file->already_used) { in ib_umad_reg_agent2()
818 file->already_used = 1; in ib_umad_reg_agent2()
819 file->use_pkey_index = 1; in ib_umad_reg_agent2()
822 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
826 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
831 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
837 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
846 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
847 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
849 if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { in ib_umad_unreg_agent()
854 agent = file->agent[id]; in ib_umad_unreg_agent()
855 file->agent[id] = NULL; in ib_umad_unreg_agent()
858 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
863 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
868 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
872 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
873 if (file->already_used) in ib_umad_enable_pkey()
876 file->use_pkey_index = 1; in ib_umad_enable_pkey()
877 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
882 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
900 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
927 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
930 struct ib_umad_file *file; in ib_umad_open() local
941 file = kzalloc(sizeof *file, GFP_KERNEL); in ib_umad_open()
942 if (!file) in ib_umad_open()
945 mutex_init(&file->mutex); in ib_umad_open()
946 spin_lock_init(&file->send_lock); in ib_umad_open()
947 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
948 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
949 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
951 file->port = port; in ib_umad_open()
952 filp->private_data = file; in ib_umad_open()
954 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
958 list_del(&file->port_list); in ib_umad_open()
959 kfree(file); in ib_umad_open()
970 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
972 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
973 struct ib_umad_device *dev = file->port->umad_dev; in ib_umad_close()
978 mutex_lock(&file->port->file_mutex); in ib_umad_close()
979 mutex_lock(&file->mutex); in ib_umad_close()
981 already_dead = file->agents_dead; in ib_umad_close()
982 file->agents_dead = 1; in ib_umad_close()
984 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
990 list_del(&file->port_list); in ib_umad_close()
992 mutex_unlock(&file->mutex); in ib_umad_close()
996 if (file->agent[i]) in ib_umad_close()
997 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
999 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
1001 kfree(file); in ib_umad_close()
1021 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1068 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1243 struct ib_umad_file *file; in ib_umad_kill_port() local
1259 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1260 mutex_lock(&file->mutex); in ib_umad_kill_port()
1261 file->agents_dead = 1; in ib_umad_kill_port()
1262 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1265 if (file->agent[id]) in ib_umad_kill_port()
1266 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()