Lines Matching refs:file
166 static int hdr_size(struct ib_umad_file *file) in hdr_size() argument
168 return file->use_pkey_index ? sizeof(struct ib_user_mad_hdr) : in hdr_size()
173 static struct ib_mad_agent *__get_agent(struct ib_umad_file *file, int id) in __get_agent() argument
175 return file->agents_dead ? NULL : file->agent[id]; in __get_agent()
178 static int queue_packet(struct ib_umad_file *file, in queue_packet() argument
184 mutex_lock(&file->mutex); in queue_packet()
189 if (agent == __get_agent(file, packet->mad.hdr.id)) { in queue_packet()
190 list_add_tail(&packet->list, &file->recv_list); in queue_packet()
191 wake_up_interruptible(&file->recv_wait); in queue_packet()
196 mutex_unlock(&file->mutex); in queue_packet()
201 static void dequeue_send(struct ib_umad_file *file, in dequeue_send() argument
204 spin_lock_irq(&file->send_lock); in dequeue_send()
206 spin_unlock_irq(&file->send_lock); in dequeue_send()
212 struct ib_umad_file *file = agent->context; in send_handler() local
215 dequeue_send(file, packet); in send_handler()
222 if (!queue_packet(file, agent, packet)) in send_handler()
232 struct ib_umad_file *file = agent->context; in recv_handler() local
246 packet->mad.hdr.length = hdr_size(file) + mad_recv_wc->mad_len; in recv_handler()
282 if (queue_packet(file, agent, packet)) in recv_handler()
292 static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf, in copy_recv_mad() argument
304 count < hdr_size(file) + packet->length) || in copy_recv_mad()
306 count < hdr_size(file) + seg_size)) in copy_recv_mad()
309 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_recv_mad()
312 buf += hdr_size(file); in copy_recv_mad()
322 if (count < hdr_size(file) + packet->length) { in copy_recv_mad()
343 trace_ib_umad_read_recv(file, &packet->mad.hdr, &recv_buf->mad->mad_hdr); in copy_recv_mad()
345 return hdr_size(file) + packet->length; in copy_recv_mad()
348 static ssize_t copy_send_mad(struct ib_umad_file *file, char __user *buf, in copy_send_mad() argument
351 ssize_t size = hdr_size(file) + packet->length; in copy_send_mad()
356 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_send_mad()
359 buf += hdr_size(file); in copy_send_mad()
364 trace_ib_umad_read_send(file, &packet->mad.hdr, in copy_send_mad()
370 static ssize_t ib_umad_read(struct file *filp, char __user *buf, in ib_umad_read()
373 struct ib_umad_file *file = filp->private_data; in ib_umad_read() local
377 if (count < hdr_size(file)) in ib_umad_read()
380 mutex_lock(&file->mutex); in ib_umad_read()
382 if (file->agents_dead) { in ib_umad_read()
383 mutex_unlock(&file->mutex); in ib_umad_read()
387 while (list_empty(&file->recv_list)) { in ib_umad_read()
388 mutex_unlock(&file->mutex); in ib_umad_read()
393 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
394 !list_empty(&file->recv_list))) in ib_umad_read()
397 mutex_lock(&file->mutex); in ib_umad_read()
400 if (file->agents_dead) { in ib_umad_read()
401 mutex_unlock(&file->mutex); in ib_umad_read()
405 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
408 mutex_unlock(&file->mutex); in ib_umad_read()
411 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
413 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
417 mutex_lock(&file->mutex); in ib_umad_read()
418 list_add(&packet->list, &file->recv_list); in ib_umad_read()
419 mutex_unlock(&file->mutex); in ib_umad_read()
460 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
467 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
493 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
496 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
506 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
513 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
523 buf += hdr_size(file); in ib_umad_write()
530 mutex_lock(&file->mutex); in ib_umad_write()
532 trace_ib_umad_write(file, &packet->mad.hdr, in ib_umad_write()
535 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
543 file->port->port_num); in ib_umad_write()
547 rdma_ah_set_port_num(&ah_attr, file->port->port_num); in ib_umad_write()
577 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
624 spin_lock_irq(&file->send_lock); in ib_umad_write()
625 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
626 spin_unlock_irq(&file->send_lock); in ib_umad_write()
628 spin_lock_irq(&file->send_lock); in ib_umad_write()
629 ret = is_duplicate(file, packet); in ib_umad_write()
631 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
632 spin_unlock_irq(&file->send_lock); in ib_umad_write()
643 mutex_unlock(&file->mutex); in ib_umad_write()
647 dequeue_send(file, packet); in ib_umad_write()
653 mutex_unlock(&file->mutex); in ib_umad_write()
659 static __poll_t ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
661 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
666 mutex_lock(&file->mutex); in ib_umad_poll()
667 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
669 if (!list_empty(&file->recv_list)) in ib_umad_poll()
671 if (file->agents_dead) in ib_umad_poll()
673 mutex_unlock(&file->mutex); in ib_umad_poll()
678 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
687 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
688 mutex_lock(&file->mutex); in ib_umad_reg_agent()
690 if (!file->port->ib_dev) { in ib_umad_reg_agent()
691 dev_notice(&file->port->dev, "%s: invalid device\n", __func__); in ib_umad_reg_agent()
702 dev_notice(&file->port->dev, in ib_umad_reg_agent()
710 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
713 dev_notice(&file->port->dev, "%s: Max Agents (%u) reached\n", __func__, in ib_umad_reg_agent()
738 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
742 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
755 if (!file->already_used) { in ib_umad_reg_agent()
756 file->already_used = 1; in ib_umad_reg_agent()
757 if (!file->use_pkey_index) { in ib_umad_reg_agent()
758 dev_warn(&file->port->dev, in ib_umad_reg_agent()
761 dev_warn(&file->port->dev, in ib_umad_reg_agent()
766 file->agent[agent_id] = agent; in ib_umad_reg_agent()
770 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
775 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
780 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
788 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
789 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
791 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
792 dev_notice(&file->port->dev, "%s: invalid device\n", __func__); in ib_umad_reg_agent2()
803 dev_notice(&file->port->dev, "%s: invalid QPN %u specified\n", in ib_umad_reg_agent2()
810 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
824 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
827 dev_notice(&file->port->dev, "%s: Max Agents (%u) reached\n", __func__, in ib_umad_reg_agent2()
838 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
851 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
855 send_handler, recv_handler, file, in ib_umad_reg_agent2()
870 if (!file->already_used) { in ib_umad_reg_agent2()
871 file->already_used = 1; in ib_umad_reg_agent2()
872 file->use_pkey_index = 1; in ib_umad_reg_agent2()
875 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
879 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
884 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
890 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
901 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
902 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
905 if (!__get_agent(file, id)) { in ib_umad_unreg_agent()
910 agent = file->agent[id]; in ib_umad_unreg_agent()
911 file->agent[id] = NULL; in ib_umad_unreg_agent()
914 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
919 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
924 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
928 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
929 if (file->already_used) in ib_umad_enable_pkey()
932 file->use_pkey_index = 1; in ib_umad_enable_pkey()
933 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
938 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
956 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
983 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
986 struct ib_umad_file *file; in ib_umad_open() local
1003 file = kzalloc(sizeof(*file), GFP_KERNEL); in ib_umad_open()
1004 if (!file) { in ib_umad_open()
1009 mutex_init(&file->mutex); in ib_umad_open()
1010 spin_lock_init(&file->send_lock); in ib_umad_open()
1011 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
1012 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
1013 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
1015 file->port = port; in ib_umad_open()
1016 filp->private_data = file; in ib_umad_open()
1018 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
1026 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
1028 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
1033 mutex_lock(&file->port->file_mutex); in ib_umad_close()
1034 mutex_lock(&file->mutex); in ib_umad_close()
1036 already_dead = file->agents_dead; in ib_umad_close()
1037 file->agents_dead = 1; in ib_umad_close()
1039 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
1045 list_del(&file->port_list); in ib_umad_close()
1047 mutex_unlock(&file->mutex); in ib_umad_close()
1051 if (file->agent[i]) in ib_umad_close()
1052 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
1054 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
1055 mutex_destroy(&file->mutex); in ib_umad_close()
1056 kfree(file); in ib_umad_close()
1074 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1117 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1333 struct ib_umad_file *file; in ib_umad_kill_port() local
1346 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1347 mutex_lock(&file->mutex); in ib_umad_kill_port()
1348 file->agents_dead = 1; in ib_umad_kill_port()
1349 wake_up_interruptible(&file->recv_wait); in ib_umad_kill_port()
1350 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1353 if (file->agent[id]) in ib_umad_kill_port()
1354 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()