Lines Matching full:file
9 * General Public License (GPL) Version 2, available from the file
81 * device special file is opened, we take a reference on the
174 static int hdr_size(struct ib_umad_file *file) in hdr_size() argument
176 return file->use_pkey_index ? sizeof(struct ib_user_mad_hdr) : in hdr_size()
180 /* caller must hold file->mutex */
181 static struct ib_mad_agent *__get_agent(struct ib_umad_file *file, int id) in __get_agent() argument
183 return file->agents_dead ? NULL : file->agent[id]; in __get_agent()
186 static int queue_packet(struct ib_umad_file *file, struct ib_mad_agent *agent, in queue_packet() argument
191 mutex_lock(&file->mutex); in queue_packet()
194 atomic_read(&file->recv_list_size) > MAX_UMAD_RECV_LIST_SIZE) in queue_packet()
200 if (agent == __get_agent(file, packet->mad.hdr.id)) { in queue_packet()
201 list_add_tail(&packet->list, &file->recv_list); in queue_packet()
202 atomic_inc(&file->recv_list_size); in queue_packet()
203 wake_up_interruptible(&file->recv_wait); in queue_packet()
208 mutex_unlock(&file->mutex); in queue_packet()
213 static void dequeue_send(struct ib_umad_file *file, in dequeue_send() argument
216 spin_lock_irq(&file->send_lock); in dequeue_send()
218 spin_unlock_irq(&file->send_lock); in dequeue_send()
224 struct ib_umad_file *file = agent->context; in send_handler() local
227 dequeue_send(file, packet); in send_handler()
234 if (!queue_packet(file, agent, packet, false)) in send_handler()
244 struct ib_umad_file *file = agent->context; in recv_handler() local
258 packet->mad.hdr.length = hdr_size(file) + mad_recv_wc->mad_len; in recv_handler()
294 if (queue_packet(file, agent, packet, true)) in recv_handler()
304 static ssize_t copy_recv_mad(struct ib_umad_file *file, char __user *buf, in copy_recv_mad() argument
316 count < hdr_size(file) + packet->length) || in copy_recv_mad()
318 count < hdr_size(file) + seg_size)) in copy_recv_mad()
321 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_recv_mad()
324 buf += hdr_size(file); in copy_recv_mad()
334 if (count < hdr_size(file) + packet->length) { in copy_recv_mad()
355 trace_ib_umad_read_recv(file, &packet->mad.hdr, &recv_buf->mad->mad_hdr); in copy_recv_mad()
357 return hdr_size(file) + packet->length; in copy_recv_mad()
360 static ssize_t copy_send_mad(struct ib_umad_file *file, char __user *buf, in copy_send_mad() argument
363 ssize_t size = hdr_size(file) + packet->length; in copy_send_mad()
368 if (copy_to_user(buf, &packet->mad, hdr_size(file))) in copy_send_mad()
371 buf += hdr_size(file); in copy_send_mad()
376 trace_ib_umad_read_send(file, &packet->mad.hdr, in copy_send_mad()
382 static ssize_t ib_umad_read(struct file *filp, char __user *buf, in ib_umad_read()
385 struct ib_umad_file *file = filp->private_data; in ib_umad_read() local
389 if (count < hdr_size(file)) in ib_umad_read()
392 mutex_lock(&file->mutex); in ib_umad_read()
394 if (file->agents_dead) { in ib_umad_read()
395 mutex_unlock(&file->mutex); in ib_umad_read()
399 while (list_empty(&file->recv_list)) { in ib_umad_read()
400 mutex_unlock(&file->mutex); in ib_umad_read()
405 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
406 !list_empty(&file->recv_list))) in ib_umad_read()
409 mutex_lock(&file->mutex); in ib_umad_read()
412 if (file->agents_dead) { in ib_umad_read()
413 mutex_unlock(&file->mutex); in ib_umad_read()
417 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
419 atomic_dec(&file->recv_list_size); in ib_umad_read()
421 mutex_unlock(&file->mutex); in ib_umad_read()
424 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
426 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
430 mutex_lock(&file->mutex); in ib_umad_read()
431 list_add(&packet->list, &file->recv_list); in ib_umad_read()
432 atomic_inc(&file->recv_list_size); in ib_umad_read()
433 mutex_unlock(&file->mutex); in ib_umad_read()
474 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
481 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
507 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
510 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
520 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
527 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
537 buf += hdr_size(file); in ib_umad_write()
544 mutex_lock(&file->mutex); in ib_umad_write()
546 trace_ib_umad_write(file, &packet->mad.hdr, in ib_umad_write()
549 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
557 file->port->port_num); in ib_umad_write()
561 rdma_ah_set_port_num(&ah_attr, file->port->port_num); in ib_umad_write()
591 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
638 spin_lock_irq(&file->send_lock); in ib_umad_write()
639 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
640 spin_unlock_irq(&file->send_lock); in ib_umad_write()
642 spin_lock_irq(&file->send_lock); in ib_umad_write()
643 ret = is_duplicate(file, packet); in ib_umad_write()
645 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
646 spin_unlock_irq(&file->send_lock); in ib_umad_write()
657 mutex_unlock(&file->mutex); in ib_umad_write()
661 dequeue_send(file, packet); in ib_umad_write()
667 mutex_unlock(&file->mutex); in ib_umad_write()
673 static __poll_t ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
675 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
680 mutex_lock(&file->mutex); in ib_umad_poll()
681 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
683 if (!list_empty(&file->recv_list)) in ib_umad_poll()
685 if (file->agents_dead) in ib_umad_poll()
687 mutex_unlock(&file->mutex); in ib_umad_poll()
692 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
701 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
702 mutex_lock(&file->mutex); in ib_umad_reg_agent()
704 if (!file->port->ib_dev) { in ib_umad_reg_agent()
705 dev_notice(&file->port->dev, "%s: invalid device\n", __func__); in ib_umad_reg_agent()
716 dev_notice(&file->port->dev, in ib_umad_reg_agent()
724 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
727 dev_notice(&file->port->dev, "%s: Max Agents (%u) reached\n", __func__, in ib_umad_reg_agent()
752 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
756 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
769 if (!file->already_used) { in ib_umad_reg_agent()
770 file->already_used = 1; in ib_umad_reg_agent()
771 if (!file->use_pkey_index) { in ib_umad_reg_agent()
772 dev_warn(&file->port->dev, in ib_umad_reg_agent()
775 dev_warn(&file->port->dev, in ib_umad_reg_agent()
780 file->agent[agent_id] = agent; in ib_umad_reg_agent()
784 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
789 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
794 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
802 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
803 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
805 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
806 dev_notice(&file->port->dev, "%s: invalid device\n", __func__); in ib_umad_reg_agent2()
817 dev_notice(&file->port->dev, "%s: invalid QPN %u specified\n", in ib_umad_reg_agent2()
824 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
838 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
841 dev_notice(&file->port->dev, "%s: Max Agents (%u) reached\n", __func__, in ib_umad_reg_agent2()
852 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
865 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
869 send_handler, recv_handler, file, in ib_umad_reg_agent2()
884 if (!file->already_used) { in ib_umad_reg_agent2()
885 file->already_used = 1; in ib_umad_reg_agent2()
886 file->use_pkey_index = 1; in ib_umad_reg_agent2()
889 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
893 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
898 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
904 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
915 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
916 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
919 if (!__get_agent(file, id)) { in ib_umad_unreg_agent()
924 agent = file->agent[id]; in ib_umad_unreg_agent()
925 file->agent[id] = NULL; in ib_umad_unreg_agent()
928 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
933 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
938 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
942 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
943 if (file->already_used) in ib_umad_enable_pkey()
946 file->use_pkey_index = 1; in ib_umad_enable_pkey()
947 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
952 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
970 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
992 * everything else is purely local to the file being created, so
995 * file structure being operated on;
997 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
1000 struct ib_umad_file *file; in ib_umad_open() local
1017 file = kzalloc(sizeof(*file), GFP_KERNEL); in ib_umad_open()
1018 if (!file) { in ib_umad_open()
1023 mutex_init(&file->mutex); in ib_umad_open()
1024 spin_lock_init(&file->send_lock); in ib_umad_open()
1025 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
1026 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
1027 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
1029 file->port = port; in ib_umad_open()
1030 filp->private_data = file; in ib_umad_open()
1032 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
1040 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
1042 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
1047 mutex_lock(&file->port->file_mutex); in ib_umad_close()
1048 mutex_lock(&file->mutex); in ib_umad_close()
1050 already_dead = file->agents_dead; in ib_umad_close()
1051 file->agents_dead = 1; in ib_umad_close()
1053 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
1059 list_del(&file->port_list); in ib_umad_close()
1061 mutex_unlock(&file->mutex); in ib_umad_close()
1065 if (file->agent[i]) in ib_umad_close()
1066 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
1068 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
1069 mutex_destroy(&file->mutex); in ib_umad_close()
1070 kfree(file); in ib_umad_close()
1087 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1130 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1347 struct ib_umad_file *file; in ib_umad_kill_port() local
1359 /* Mark ib_dev NULL and block ioctl or other file ops to progress in ib_umad_kill_port()
1364 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1365 mutex_lock(&file->mutex); in ib_umad_kill_port()
1366 file->agents_dead = 1; in ib_umad_kill_port()
1367 wake_up_interruptible(&file->recv_wait); in ib_umad_kill_port()
1368 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1371 if (file->agent[id]) in ib_umad_kill_port()
1372 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()