Lines Matching full:file

9  * General Public License (GPL) Version 2, available from the file
79 * device special file is opened, we take a reference on the
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()
172 /* caller must hold file->mutex */
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 while (list_empty(&file->recv_list)) { in ib_umad_read()
383 mutex_unlock(&file->mutex); in ib_umad_read()
388 if (wait_event_interruptible(file->recv_wait, in ib_umad_read()
389 !list_empty(&file->recv_list))) in ib_umad_read()
392 mutex_lock(&file->mutex); in ib_umad_read()
395 packet = list_entry(file->recv_list.next, struct ib_umad_packet, list); in ib_umad_read()
398 mutex_unlock(&file->mutex); in ib_umad_read()
401 ret = copy_recv_mad(file, buf, packet, count); in ib_umad_read()
403 ret = copy_send_mad(file, buf, packet, count); in ib_umad_read()
407 mutex_lock(&file->mutex); in ib_umad_read()
408 list_add(&packet->list, &file->recv_list); in ib_umad_read()
409 mutex_unlock(&file->mutex); in ib_umad_read()
450 static int is_duplicate(struct ib_umad_file *file, in is_duplicate() argument
457 list_for_each_entry(sent_packet, &file->send_list, list) { in is_duplicate()
483 static ssize_t ib_umad_write(struct file *filp, const char __user *buf, in ib_umad_write()
486 struct ib_umad_file *file = filp->private_data; in ib_umad_write() local
496 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) in ib_umad_write()
503 if (copy_from_user(&packet->mad, buf, hdr_size(file))) { in ib_umad_write()
513 buf += hdr_size(file); in ib_umad_write()
520 mutex_lock(&file->mutex); in ib_umad_write()
522 trace_ib_umad_write(file, &packet->mad.hdr, in ib_umad_write()
525 agent = __get_agent(file, packet->mad.hdr.id); in ib_umad_write()
533 file->port->port_num); in ib_umad_write()
537 rdma_ah_set_port_num(&ah_attr, file->port->port_num); in ib_umad_write()
567 data_len = count - hdr_size(file) - hdr_len; in ib_umad_write()
614 spin_lock_irq(&file->send_lock); in ib_umad_write()
615 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
616 spin_unlock_irq(&file->send_lock); in ib_umad_write()
618 spin_lock_irq(&file->send_lock); in ib_umad_write()
619 ret = is_duplicate(file, packet); in ib_umad_write()
621 list_add_tail(&packet->list, &file->send_list); in ib_umad_write()
622 spin_unlock_irq(&file->send_lock); in ib_umad_write()
633 mutex_unlock(&file->mutex); in ib_umad_write()
637 dequeue_send(file, packet); in ib_umad_write()
643 mutex_unlock(&file->mutex); in ib_umad_write()
649 static __poll_t ib_umad_poll(struct file *filp, struct poll_table_struct *wait) in ib_umad_poll()
651 struct ib_umad_file *file = filp->private_data; in ib_umad_poll() local
656 poll_wait(filp, &file->recv_wait, wait); in ib_umad_poll()
658 if (!list_empty(&file->recv_list)) in ib_umad_poll()
664 static int ib_umad_reg_agent(struct ib_umad_file *file, void __user *arg, in ib_umad_reg_agent() argument
673 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent()
674 mutex_lock(&file->mutex); in ib_umad_reg_agent()
676 if (!file->port->ib_dev) { in ib_umad_reg_agent()
677 dev_notice(&file->port->dev, in ib_umad_reg_agent()
689 dev_notice(&file->port->dev, in ib_umad_reg_agent()
697 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent()
700 dev_notice(&file->port->dev, in ib_umad_reg_agent()
725 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent()
729 send_handler, recv_handler, file, 0); in ib_umad_reg_agent()
742 if (!file->already_used) { in ib_umad_reg_agent()
743 file->already_used = 1; in ib_umad_reg_agent()
744 if (!file->use_pkey_index) { in ib_umad_reg_agent()
745 dev_warn(&file->port->dev, in ib_umad_reg_agent()
748 dev_warn(&file->port->dev, in ib_umad_reg_agent()
753 file->agent[agent_id] = agent; in ib_umad_reg_agent()
757 mutex_unlock(&file->mutex); in ib_umad_reg_agent()
762 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent()
767 static int ib_umad_reg_agent2(struct ib_umad_file *file, void __user *arg) in ib_umad_reg_agent2() argument
775 mutex_lock(&file->port->file_mutex); in ib_umad_reg_agent2()
776 mutex_lock(&file->mutex); in ib_umad_reg_agent2()
778 if (!file->port->ib_dev) { in ib_umad_reg_agent2()
779 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
791 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
799 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
813 if (!__get_agent(file, agent_id)) in ib_umad_reg_agent2()
816 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
828 dev_notice(&file->port->dev, in ib_umad_reg_agent2()
841 agent = ib_register_mad_agent(file->port->ib_dev, file->port->port_num, in ib_umad_reg_agent2()
845 send_handler, recv_handler, file, in ib_umad_reg_agent2()
860 if (!file->already_used) { in ib_umad_reg_agent2()
861 file->already_used = 1; in ib_umad_reg_agent2()
862 file->use_pkey_index = 1; in ib_umad_reg_agent2()
865 file->agent[agent_id] = agent; in ib_umad_reg_agent2()
869 mutex_unlock(&file->mutex); in ib_umad_reg_agent2()
874 mutex_unlock(&file->port->file_mutex); in ib_umad_reg_agent2()
880 static int ib_umad_unreg_agent(struct ib_umad_file *file, u32 __user *arg) in ib_umad_unreg_agent() argument
891 mutex_lock(&file->port->file_mutex); in ib_umad_unreg_agent()
892 mutex_lock(&file->mutex); in ib_umad_unreg_agent()
895 if (!__get_agent(file, id)) { in ib_umad_unreg_agent()
900 agent = file->agent[id]; in ib_umad_unreg_agent()
901 file->agent[id] = NULL; in ib_umad_unreg_agent()
904 mutex_unlock(&file->mutex); in ib_umad_unreg_agent()
909 mutex_unlock(&file->port->file_mutex); in ib_umad_unreg_agent()
914 static long ib_umad_enable_pkey(struct ib_umad_file *file) in ib_umad_enable_pkey() argument
918 mutex_lock(&file->mutex); in ib_umad_enable_pkey()
919 if (file->already_used) in ib_umad_enable_pkey()
922 file->use_pkey_index = 1; in ib_umad_enable_pkey()
923 mutex_unlock(&file->mutex); in ib_umad_enable_pkey()
928 static long ib_umad_ioctl(struct file *filp, unsigned int cmd, in ib_umad_ioctl()
946 static long ib_umad_compat_ioctl(struct file *filp, unsigned int cmd, in ib_umad_compat_ioctl()
968 * everything else is purely local to the file being created, so
971 * file structure being operated on;
973 static int ib_umad_open(struct inode *inode, struct file *filp) in ib_umad_open()
976 struct ib_umad_file *file; in ib_umad_open() local
993 file = kzalloc(sizeof(*file), GFP_KERNEL); in ib_umad_open()
994 if (!file) { in ib_umad_open()
999 mutex_init(&file->mutex); in ib_umad_open()
1000 spin_lock_init(&file->send_lock); in ib_umad_open()
1001 INIT_LIST_HEAD(&file->recv_list); in ib_umad_open()
1002 INIT_LIST_HEAD(&file->send_list); in ib_umad_open()
1003 init_waitqueue_head(&file->recv_wait); in ib_umad_open()
1005 file->port = port; in ib_umad_open()
1006 filp->private_data = file; in ib_umad_open()
1008 list_add_tail(&file->port_list, &port->file_list); in ib_umad_open()
1016 static int ib_umad_close(struct inode *inode, struct file *filp) in ib_umad_close()
1018 struct ib_umad_file *file = filp->private_data; in ib_umad_close() local
1023 mutex_lock(&file->port->file_mutex); in ib_umad_close()
1024 mutex_lock(&file->mutex); in ib_umad_close()
1026 already_dead = file->agents_dead; in ib_umad_close()
1027 file->agents_dead = 1; in ib_umad_close()
1029 list_for_each_entry_safe(packet, tmp, &file->recv_list, list) { in ib_umad_close()
1035 list_del(&file->port_list); in ib_umad_close()
1037 mutex_unlock(&file->mutex); in ib_umad_close()
1041 if (file->agent[i]) in ib_umad_close()
1042 ib_unregister_mad_agent(file->agent[i]); in ib_umad_close()
1044 mutex_unlock(&file->port->file_mutex); in ib_umad_close()
1045 mutex_destroy(&file->mutex); in ib_umad_close()
1046 kfree(file); in ib_umad_close()
1064 static int ib_umad_sm_open(struct inode *inode, struct file *filp) in ib_umad_sm_open()
1107 static int ib_umad_sm_close(struct inode *inode, struct file *filp) in ib_umad_sm_close()
1323 struct ib_umad_file *file; in ib_umad_kill_port() local
1331 /* Mark ib_dev NULL and block ioctl or other file ops to progress in ib_umad_kill_port()
1336 list_for_each_entry(file, &port->file_list, port_list) { in ib_umad_kill_port()
1337 mutex_lock(&file->mutex); in ib_umad_kill_port()
1338 file->agents_dead = 1; in ib_umad_kill_port()
1339 mutex_unlock(&file->mutex); in ib_umad_kill_port()
1342 if (file->agent[id]) in ib_umad_kill_port()
1343 ib_unregister_mad_agent(file->agent[id]); in ib_umad_kill_port()