• Home
  • Raw
  • Download

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()
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
273 count < hdr_size(file) + packet->length) || in copy_recv_mad()
275 count < hdr_size(file) + seg_size)) in copy_recv_mad()
278 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_recv_mad()
281 buf += hdr_size(file); in copy_recv_mad()
291 if (count < hdr_size(file) + packet->length) { in copy_recv_mad()
311 return hdr_size(file) + packet->length; in copy_recv_mad()
314 static ssize_t copy_send_mad(struct ib_umad_file *file, char __user *buf, in copy_send_mad() argument
317 ssize_t size = hdr_size(file) + packet->length; in copy_send_mad()
322 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_send_mad()
325 buf += hdr_size(file); in copy_send_mad()
333 static ssize_t ib_umad_read(struct file *filp, char __user *buf, in ib_umad_read()
336 struct ib_umad_file *file = filp->private_data; in ib_umad_read() local
340 if (count < hdr_size(file)) in ib_umad_read()
343 mutex_lock(&file->mutex); in ib_umad_read()
345 while (list_empty(&file->recv_list)) { in ib_umad_read()
346 mutex_unlock(&file->mutex); in ib_umad_read()
351 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
352 !list_empty(&file->recv_list))) in ib_umad_read()
355 mutex_lock(&file->mutex); in ib_umad_read()
358 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
361 mutex_unlock(&file->mutex); in ib_umad_read()
364 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
366 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
370 mutex_lock(&file->mutex); in ib_umad_read()
371 list_add(&packet->list, &file->recv_list); in ib_umad_read()
372 mutex_unlock(&file->mutex); in ib_umad_read()
413 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
420 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
446 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
449 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
459 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
466 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
476 buf += hdr_size(file); in ib_umad_write()
483 mutex_lock(&file->mutex); in ib_umad_write()
485 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
495 ah_attr.port_num = file->port->port_num; in ib_umad_write()
525 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
572 spin_lock_irq(&file->send_lock); 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()
576 spin_lock_irq(&file->send_lock); in ib_umad_write()
577 ret = is_duplicate(file, packet); in ib_umad_write()
579 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
580 spin_unlock_irq(&file->send_lock); in ib_umad_write()
591 mutex_unlock(&file->mutex); in ib_umad_write()
595 dequeue_send(file, packet); in ib_umad_write()
601 mutex_unlock(&file->mutex); in ib_umad_write()
607 static unsigned int ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
609 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
614 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
616 if (!list_empty(&file->recv_list)) in ib_umad_poll()
622 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
631 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
632 mutex_lock(&file->mutex); in ib_umad_reg_agent()
634 if (!file->port->ib_dev) { in ib_umad_reg_agent()
635 dev_notice(file->port->dev, in ib_umad_reg_agent()
647 dev_notice(file->port->dev, in ib_umad_reg_agent()
655 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
658 dev_notice(file->port->dev, in ib_umad_reg_agent()
683 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
687 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
700 if (!file->already_used) { in ib_umad_reg_agent()
701 file->already_used = 1; in ib_umad_reg_agent()
702 if (!file->use_pkey_index) { in ib_umad_reg_agent()
703 dev_warn(file->port->dev, in ib_umad_reg_agent()
706 dev_warn(file->port->dev, in ib_umad_reg_agent()
711 file->agent[agent_id] = agent; in ib_umad_reg_agent()
715 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
720 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
725 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
733 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
734 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
736 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
737 dev_notice(file->port->dev, in ib_umad_reg_agent2()
749 dev_notice(file->port->dev, in ib_umad_reg_agent2()
757 dev_notice(file->port->dev, in ib_umad_reg_agent2()
771 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
774 dev_notice(file->port->dev, in ib_umad_reg_agent2()
786 dev_notice(file->port->dev, in ib_umad_reg_agent2()
799 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
803 send_handler, recv_handler, file, in ib_umad_reg_agent2()
818 if (!file->already_used) { in ib_umad_reg_agent2()
819 file->already_used = 1; in ib_umad_reg_agent2()
820 file->use_pkey_index = 1; in ib_umad_reg_agent2()
823 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
827 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
832 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
838 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
847 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
848 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
850 if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { in ib_umad_unreg_agent()
855 agent = file->agent[id]; in ib_umad_unreg_agent()
856 file->agent[id] = NULL; in ib_umad_unreg_agent()
859 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
864 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
869 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
873 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
874 if (file->already_used) in ib_umad_enable_pkey()
877 file->use_pkey_index = 1; in ib_umad_enable_pkey()
878 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
883 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
901 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
928 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
931 struct ib_umad_file *file; in ib_umad_open() local
942 file = kzalloc(sizeof *file, GFP_KERNEL); in ib_umad_open()
943 if (!file) in ib_umad_open()
946 mutex_init(&file->mutex); in ib_umad_open()
947 spin_lock_init(&file->send_lock); in ib_umad_open()
948 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
949 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
950 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
952 file->port = port; in ib_umad_open()
953 filp->private_data = file; in ib_umad_open()
955 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
959 list_del(&file->port_list); in ib_umad_open()
960 kfree(file); in ib_umad_open()
971 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
973 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
974 struct ib_umad_device *dev = file->port->umad_dev; in ib_umad_close()
979 mutex_lock(&file->port->file_mutex); in ib_umad_close()
980 mutex_lock(&file->mutex); in ib_umad_close()
982 already_dead = file->agents_dead; in ib_umad_close()
983 file->agents_dead = 1; in ib_umad_close()
985 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
991 list_del(&file->port_list); in ib_umad_close()
993 mutex_unlock(&file->mutex); in ib_umad_close()
997 if (file->agent[i]) in ib_umad_close()
998 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
1000 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
1002 kfree(file); in ib_umad_close()
1022 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1069 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1244 struct ib_umad_file *file; in ib_umad_kill_port() local
1260 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1261 mutex_lock(&file->mutex); in ib_umad_kill_port()
1262 file->agents_dead = 1; in ib_umad_kill_port()
1263 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1266 if (file->agent[id]) in ib_umad_kill_port()
1267 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()