Lines Matching refs:file
158 static int hdr_size(struct ib_umad_file *file) in hdr_size() argument
160 return file->use_pkey_index ? sizeof (struct ib_user_mad_hdr) : in hdr_size()
165 static struct ib_mad_agent *__get_agent(struct ib_umad_file *file, int id) in __get_agent() argument
167 return file->agents_dead ? NULL : file->agent[id]; in __get_agent()
170 static int queue_packet(struct ib_umad_file *file, in queue_packet() argument
176 mutex_lock(&file->mutex); in queue_packet()
181 if (agent == __get_agent(file, packet->mad.hdr.id)) { in queue_packet()
182 list_add_tail(&packet->list, &file->recv_list); in queue_packet()
183 wake_up_interruptible(&file->recv_wait); in queue_packet()
188 mutex_unlock(&file->mutex); in queue_packet()
193 static void dequeue_send(struct ib_umad_file *file, in dequeue_send() argument
196 spin_lock_irq(&file->send_lock); in dequeue_send()
198 spin_unlock_irq(&file->send_lock); in dequeue_send()
204 struct ib_umad_file *file = agent->context; in send_handler() local
207 dequeue_send(file, packet); in send_handler()
214 if (!queue_packet(file, agent, packet)) in send_handler()
224 struct ib_umad_file *file = agent->context; in recv_handler() local
238 packet->mad.hdr.length = hdr_size(file) + mad_recv_wc->mad_len; in recv_handler()
274 if (queue_packet(file, agent, packet)) in recv_handler()
284 static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf, in copy_recv_mad() argument
296 count < hdr_size(file) + packet->length) || in copy_recv_mad()
298 count < hdr_size(file) + seg_size)) in copy_recv_mad()
301 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_recv_mad()
304 buf += hdr_size(file); in copy_recv_mad()
314 if (count < hdr_size(file) + packet->length) { in copy_recv_mad()
334 return hdr_size(file) + packet->length; in copy_recv_mad()
337 static ssize_t copy_send_mad(struct ib_umad_file *file, char __user *buf, in copy_send_mad() argument
340 ssize_t size = hdr_size(file) + packet->length; in copy_send_mad()
345 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_send_mad()
348 buf += hdr_size(file); in copy_send_mad()
356 static ssize_t ib_umad_read(struct file *filp, char __user *buf, in ib_umad_read()
359 struct ib_umad_file *file = filp->private_data; in ib_umad_read() local
363 if (count < hdr_size(file)) in ib_umad_read()
366 mutex_lock(&file->mutex); in ib_umad_read()
368 while (list_empty(&file->recv_list)) { in ib_umad_read()
369 mutex_unlock(&file->mutex); in ib_umad_read()
374 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
375 !list_empty(&file->recv_list))) in ib_umad_read()
378 mutex_lock(&file->mutex); in ib_umad_read()
381 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
384 mutex_unlock(&file->mutex); in ib_umad_read()
387 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
389 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
393 mutex_lock(&file->mutex); in ib_umad_read()
394 list_add(&packet->list, &file->recv_list); in ib_umad_read()
395 mutex_unlock(&file->mutex); in ib_umad_read()
436 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
443 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
469 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
472 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
482 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
489 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
499 buf += hdr_size(file); in ib_umad_write()
506 mutex_lock(&file->mutex); in ib_umad_write()
508 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
516 file->port->port_num); in ib_umad_write()
520 rdma_ah_set_port_num(&ah_attr, file->port->port_num); in ib_umad_write()
550 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
597 spin_lock_irq(&file->send_lock); in ib_umad_write()
598 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
599 spin_unlock_irq(&file->send_lock); in ib_umad_write()
601 spin_lock_irq(&file->send_lock); in ib_umad_write()
602 ret = is_duplicate(file, packet); in ib_umad_write()
604 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
605 spin_unlock_irq(&file->send_lock); in ib_umad_write()
616 mutex_unlock(&file->mutex); in ib_umad_write()
620 dequeue_send(file, packet); in ib_umad_write()
626 mutex_unlock(&file->mutex); in ib_umad_write()
632 static __poll_t ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
634 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
639 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
641 if (!list_empty(&file->recv_list)) in ib_umad_poll()
647 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
656 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
657 mutex_lock(&file->mutex); in ib_umad_reg_agent()
659 if (!file->port->ib_dev) { in ib_umad_reg_agent()
660 dev_notice(file->port->dev, in ib_umad_reg_agent()
672 dev_notice(file->port->dev, in ib_umad_reg_agent()
680 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
683 dev_notice(file->port->dev, in ib_umad_reg_agent()
708 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
712 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
725 if (!file->already_used) { in ib_umad_reg_agent()
726 file->already_used = 1; in ib_umad_reg_agent()
727 if (!file->use_pkey_index) { in ib_umad_reg_agent()
728 dev_warn(file->port->dev, in ib_umad_reg_agent()
731 dev_warn(file->port->dev, in ib_umad_reg_agent()
736 file->agent[agent_id] = agent; in ib_umad_reg_agent()
740 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
745 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
750 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
758 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
759 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
761 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
762 dev_notice(file->port->dev, in ib_umad_reg_agent2()
774 dev_notice(file->port->dev, in ib_umad_reg_agent2()
782 dev_notice(file->port->dev, in ib_umad_reg_agent2()
796 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
799 dev_notice(file->port->dev, in ib_umad_reg_agent2()
811 dev_notice(file->port->dev, in ib_umad_reg_agent2()
824 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
828 send_handler, recv_handler, file, in ib_umad_reg_agent2()
843 if (!file->already_used) { in ib_umad_reg_agent2()
844 file->already_used = 1; in ib_umad_reg_agent2()
845 file->use_pkey_index = 1; in ib_umad_reg_agent2()
848 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
852 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
857 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
863 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
872 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
873 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
875 if (id >= IB_UMAD_MAX_AGENTS || !__get_agent(file, id)) { in ib_umad_unreg_agent()
880 agent = file->agent[id]; in ib_umad_unreg_agent()
881 file->agent[id] = NULL; in ib_umad_unreg_agent()
884 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
889 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
894 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
898 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
899 if (file->already_used) in ib_umad_enable_pkey()
902 file->use_pkey_index = 1; in ib_umad_enable_pkey()
903 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
908 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
926 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
953 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
956 struct ib_umad_file *file; in ib_umad_open() local
967 file = kzalloc(sizeof *file, GFP_KERNEL); in ib_umad_open()
968 if (!file) in ib_umad_open()
971 mutex_init(&file->mutex); in ib_umad_open()
972 spin_lock_init(&file->send_lock); in ib_umad_open()
973 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
974 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
975 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
977 file->port = port; in ib_umad_open()
978 filp->private_data = file; in ib_umad_open()
980 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
984 list_del(&file->port_list); in ib_umad_open()
985 kfree(file); in ib_umad_open()
996 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
998 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
999 struct ib_umad_device *dev = file->port->umad_dev; in ib_umad_close()
1004 mutex_lock(&file->port->file_mutex); in ib_umad_close()
1005 mutex_lock(&file->mutex); in ib_umad_close()
1007 already_dead = file->agents_dead; in ib_umad_close()
1008 file->agents_dead = 1; in ib_umad_close()
1010 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
1016 list_del(&file->port_list); in ib_umad_close()
1018 mutex_unlock(&file->mutex); in ib_umad_close()
1022 if (file->agent[i]) in ib_umad_close()
1023 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
1025 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
1027 kfree(file); in ib_umad_close()
1047 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1094 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1237 struct ib_umad_file *file; in ib_umad_kill_port() local
1253 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1254 mutex_lock(&file->mutex); in ib_umad_kill_port()
1255 file->agents_dead = 1; in ib_umad_kill_port()
1256 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1259 if (file->agent[id]) in ib_umad_kill_port()
1260 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()