Lines Matching refs:file
151 static int hdr_size(struct ib_umad_file *file) in hdr_size() argument
153 return file->use_pkey_index ? sizeof (struct ib_user_mad_hdr) : in hdr_size()
158 static struct ib_mad_agent *__get_agent(struct ib_umad_file *file, int id) in __get_agent() argument
160 return file->agents_dead ? NULL : file->agent[id]; in __get_agent()
163 static int queue_packet(struct ib_umad_file *file, in queue_packet() argument
169 mutex_lock(&file->mutex); in queue_packet()
174 if (agent == __get_agent(file, packet->mad.hdr.id)) { in queue_packet()
175 list_add_tail(&packet->list, &file->recv_list); in queue_packet()
176 wake_up_interruptible(&file->recv_wait); in queue_packet()
181 mutex_unlock(&file->mutex); in queue_packet()
186 static void dequeue_send(struct ib_umad_file *file, in dequeue_send() argument
189 spin_lock_irq(&file->send_lock); in dequeue_send()
191 spin_unlock_irq(&file->send_lock); in dequeue_send()
197 struct ib_umad_file *file = agent->context; in send_handler() local
200 dequeue_send(file, packet); in send_handler()
207 if (!queue_packet(file, agent, packet)) in send_handler()
216 struct ib_umad_file *file = agent->context; in recv_handler() local
230 packet->mad.hdr.length = hdr_size(file) + mad_recv_wc->mad_len; in recv_handler()
251 if (queue_packet(file, agent, packet)) in recv_handler()
261 static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf, in copy_recv_mad() argument
270 count < hdr_size(file) + packet->length) || in copy_recv_mad()
272 count < hdr_size(file) + sizeof (*recv_buf->mad))) in copy_recv_mad()
275 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_recv_mad()
278 buf += hdr_size(file); in copy_recv_mad()
288 if (count < hdr_size(file) + packet->length) { in copy_recv_mad()
308 return hdr_size(file) + packet->length; in copy_recv_mad()
311 static ssize_t copy_send_mad(struct ib_umad_file *file, char __user *buf, in copy_send_mad() argument
314 ssize_t size = hdr_size(file) + packet->length; in copy_send_mad()
319 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_send_mad()
322 buf += hdr_size(file); in copy_send_mad()
330 static ssize_t ib_umad_read(struct file *filp, char __user *buf, in ib_umad_read()
333 struct ib_umad_file *file = filp->private_data; in ib_umad_read() local
337 if (count < hdr_size(file)) in ib_umad_read()
340 mutex_lock(&file->mutex); in ib_umad_read()
342 while (list_empty(&file->recv_list)) { in ib_umad_read()
343 mutex_unlock(&file->mutex); in ib_umad_read()
348 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
349 !list_empty(&file->recv_list))) in ib_umad_read()
352 mutex_lock(&file->mutex); in ib_umad_read()
355 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
358 mutex_unlock(&file->mutex); in ib_umad_read()
361 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
363 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
367 mutex_lock(&file->mutex); in ib_umad_read()
368 list_add(&packet->list, &file->recv_list); in ib_umad_read()
369 mutex_unlock(&file->mutex); in ib_umad_read()
410 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
417 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
443 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
446 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
455 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
462 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
472 buf += hdr_size(file); in ib_umad_write()
479 mutex_lock(&file->mutex); in ib_umad_write()
481 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
491 ah_attr.port_num = file->port->port_num; in ib_umad_write()
520 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
566 spin_lock_irq(&file->send_lock); in ib_umad_write()
567 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
568 spin_unlock_irq(&file->send_lock); in ib_umad_write()
570 spin_lock_irq(&file->send_lock); in ib_umad_write()
571 ret = is_duplicate(file, packet); in ib_umad_write()
573 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
574 spin_unlock_irq(&file->send_lock); in ib_umad_write()
585 mutex_unlock(&file->mutex); in ib_umad_write()
589 dequeue_send(file, packet); in ib_umad_write()
595 mutex_unlock(&file->mutex); in ib_umad_write()
601 static unsigned int ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
603 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
608 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
610 if (!list_empty(&file->recv_list)) in ib_umad_poll()
616 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
625 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
626 mutex_lock(&file->mutex); in ib_umad_reg_agent()
628 if (!file->port->ib_dev) { in ib_umad_reg_agent()
629 dev_notice(file->port->dev, in ib_umad_reg_agent()
641 dev_notice(file->port->dev, in ib_umad_reg_agent()
649 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
652 dev_notice(file->port->dev, in ib_umad_reg_agent()
677 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
681 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
694 if (!file->already_used) { in ib_umad_reg_agent()
695 file->already_used = 1; in ib_umad_reg_agent()
696 if (!file->use_pkey_index) { in ib_umad_reg_agent()
697 dev_warn(file->port->dev, in ib_umad_reg_agent()
700 dev_warn(file->port->dev, in ib_umad_reg_agent()
705 file->agent[agent_id] = agent; in ib_umad_reg_agent()
709 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
714 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
719 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
727 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
728 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
730 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
731 dev_notice(file->port->dev, in ib_umad_reg_agent2()
743 dev_notice(file->port->dev, in ib_umad_reg_agent2()
751 dev_notice(file->port->dev, in ib_umad_reg_agent2()
765 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
768 dev_notice(file->port->dev, in ib_umad_reg_agent2()
780 dev_notice(file->port->dev, in ib_umad_reg_agent2()
793 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
797 send_handler, recv_handler, file, in ib_umad_reg_agent2()
812 if (!file->already_used) { in ib_umad_reg_agent2()
813 file->already_used = 1; in ib_umad_reg_agent2()
814 file->use_pkey_index = 1; in ib_umad_reg_agent2()
817 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
821 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
826 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
832 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
841 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
842 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
844 if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { in ib_umad_unreg_agent()
849 agent = file->agent[id]; in ib_umad_unreg_agent()
850 file->agent[id] = NULL; in ib_umad_unreg_agent()
853 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
858 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
863 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
867 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
868 if (file->already_used) in ib_umad_enable_pkey()
871 file->use_pkey_index = 1; in ib_umad_enable_pkey()
872 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
877 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
895 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
922 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
925 struct ib_umad_file *file; in ib_umad_open() local
936 file = kzalloc(sizeof *file, GFP_KERNEL); in ib_umad_open()
937 if (!file) in ib_umad_open()
940 mutex_init(&file->mutex); in ib_umad_open()
941 spin_lock_init(&file->send_lock); in ib_umad_open()
942 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
943 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
944 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
946 file->port = port; in ib_umad_open()
947 filp->private_data = file; in ib_umad_open()
949 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
953 list_del(&file->port_list); in ib_umad_open()
954 kfree(file); in ib_umad_open()
965 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
967 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
968 struct ib_umad_device *dev = file->port->umad_dev; in ib_umad_close()
973 mutex_lock(&file->port->file_mutex); in ib_umad_close()
974 mutex_lock(&file->mutex); in ib_umad_close()
976 already_dead = file->agents_dead; in ib_umad_close()
977 file->agents_dead = 1; in ib_umad_close()
979 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
985 list_del(&file->port_list); in ib_umad_close()
987 mutex_unlock(&file->mutex); in ib_umad_close()
991 if (file->agent[i]) in ib_umad_close()
992 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
994 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
996 kfree(file); in ib_umad_close()
1016 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1063 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1238 struct ib_umad_file *file; in ib_umad_kill_port() local
1254 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1255 mutex_lock(&file->mutex); in ib_umad_kill_port()
1256 file->agents_dead = 1; in ib_umad_kill_port()
1257 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1260 if (file->agent[id]) in ib_umad_kill_port()
1261 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()