Lines Matching refs:port

92 static void vdc_ldc_reset(struct vdc_port *port);
108 static inline int vdc_version_supported(struct vdc_port *port,
111 return port->vio.ver.major == major && port->vio.ver.minor >= minor;
177 static void vdc_blk_queue_start(struct vdc_port *port)
179 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
185 if (port->disk && vdc_tx_dring_avail(dr) * 100 / VDC_TX_RING_SIZE >= 50)
186 blk_mq_start_stopped_hw_queues(port->disk->queue, true);
202 struct vdc_port *port = to_vdc_port(vio);
204 cancel_delayed_work(&port->ldc_reset_timer_work);
206 vdc_blk_queue_start(port);
209 static int vdc_handle_unknown(struct vdc_port *port, void *arg)
217 ldc_disconnect(port->vio.lp);
224 struct vdc_port *port = to_vdc_port(vio);
235 pkt.vdisk_block_size = port->vdisk_block_size;
236 pkt.max_xfer_size = port->max_xfer_size;
241 return vio_ldc_send(&port->vio, &pkt, sizeof(pkt));
246 struct vdc_port *port = to_vdc_port(vio);
268 if (pkt->vdisk_block_size > port->vdisk_block_size) {
272 port->vdisk_block_size, pkt->vdisk_block_size);
276 port->operations = pkt->operations;
277 port->vdisk_type = pkt->vdisk_type;
278 if (vdc_version_supported(port, 1, 1)) {
279 port->vdisk_size = pkt->vdisk_size;
280 port->vdisk_mtype = pkt->vdisk_mtype;
282 if (pkt->max_xfer_size < port->max_xfer_size)
283 port->max_xfer_size = pkt->max_xfer_size;
284 port->vdisk_block_size = pkt->vdisk_block_size;
286 port->vdisk_phys_blksz = VDC_DEFAULT_BLK_SIZE;
287 if (vdc_version_supported(port, 1, 2))
288 port->vdisk_phys_blksz = pkt->phys_block_size;
298 static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc)
302 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD);
305 static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
309 struct vdc_req_entry *rqe = &port->rq_arr[index];
315 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies);
321 vdc_end_special(port, desc);
329 vdc_blk_queue_start(port);
332 static int vdc_ack(struct vdc_port *port, void *msgbuf)
334 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
342 vdc_end_one(port, dr, pkt->start_idx);
347 static int vdc_nack(struct vdc_port *port, void *msgbuf)
355 struct vdc_port *port = arg;
356 struct vio_driver_state *vio = &port->vio;
364 queue_work(sunvdc_wq, &port->ldc_reset_work);
404 err = vdc_ack(port, &msgbuf);
406 err = vdc_nack(port, &msgbuf);
408 err = vdc_handle_unknown(port, &msgbuf);
412 err = vdc_handle_unknown(port, &msgbuf);
418 vdc_finish(&port->vio, err, WAITING_FOR_ANY);
423 static int __vdc_tx_trigger(struct vdc_port *port)
425 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
431 .sid = vio_send_sid(&port->vio),
443 err = vio_ldc_send(&port->vio, &hdr, sizeof(hdr));
456 vdc_ldc_reset(port);
462 struct vdc_port *port = req->rq_disk->private_data;
463 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
472 if (WARN_ON(port->ring_cookies > MAX_RING_COOKIES))
485 sg_init_table(sg, port->ring_cookies);
494 err = ldc_map_sg(port->vio.lp, sg, nsg,
495 desc->cookies, port->ring_cookies,
502 rqe = &port->rq_arr[dr->prod];
506 desc->req_id = port->req_id;
508 if (port->vdisk_type == VD_DISK_TYPE_DISK) {
514 desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size;
524 err = __vdc_tx_trigger(port);
528 port->req_id++;
538 struct vdc_port *port = hctx->queue->queuedata;
542 dr = &port->vio.drings[VIO_DRIVER_TX_RING];
546 spin_lock_irqsave(&port->vio.lock, flags);
551 if (unlikely(port->drain)) {
552 spin_unlock_irqrestore(&port->vio.lock, flags);
557 spin_unlock_irqrestore(&port->vio.lock, flags);
563 spin_unlock_irqrestore(&port->vio.lock, flags);
567 spin_unlock_irqrestore(&port->vio.lock, flags);
571 static int generic_request(struct vdc_port *port, u8 op, void *buf, int len)
581 if (!(((u64)1 << (u64)op) & port->operations))
653 spin_lock_irqsave(&port->vio.lock, flags);
655 dr = &port->vio.drings[VIO_DRIVER_TX_RING];
662 err = ldc_map_single(port->vio.lp, req_buf, op_len,
663 desc->cookies, port->ring_cookies,
666 spin_unlock_irqrestore(&port->vio.lock, flags);
673 port->vio.cmp = &comp;
676 desc->req_id = port->req_id;
690 err = __vdc_tx_trigger(port);
692 port->req_id++;
694 spin_unlock_irqrestore(&port->vio.lock, flags);
699 port->vio.cmp = NULL;
700 spin_unlock_irqrestore(&port->vio.lock, flags);
711 static int vdc_alloc_tx_ring(struct vdc_port *port)
713 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
719 (sizeof(struct ldc_trans_cookie) * port->ring_cookies);
723 dring = ldc_alloc_exp_dring(port->vio.lp, len,
741 static void vdc_free_tx_ring(struct vdc_port *port)
743 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
746 ldc_free_exp_dring(port->vio.lp, dr->base,
757 static int vdc_port_up(struct vdc_port *port)
764 port->vio.cmp = &comp;
766 vio_port_up(&port->vio);
771 static void vdc_port_down(struct vdc_port *port)
773 ldc_disconnect(port->vio.lp);
774 ldc_unbind(port->vio.lp);
775 vdc_free_tx_ring(port);
776 vio_ldc_free(&port->vio);
785 struct vdc_port *port = q->queuedata;
788 blk_mq_free_tag_set(&port->tag_set);
791 static struct request_queue *init_queue(struct vdc_port *port)
795 q = blk_mq_init_sq_queue(&port->tag_set, &vdc_mq_ops, VDC_TX_RING_SIZE,
800 q->queuedata = port;
804 static int probe_disk(struct vdc_port *port)
810 err = vdc_port_up(port);
817 if (vdc_version_supported(port, 1, 2) && !port->vdisk_phys_blksz)
820 if (vdc_version_supported(port, 1, 1)) {
824 if (port->vdisk_size == -1)
829 err = generic_request(port, VD_OP_GET_DISKGEOM,
836 port->vdisk_size = ((u64)geom.num_cyl *
841 q = init_queue(port);
844 port->vio.name);
850 port->vio.name);
855 port->disk = g;
861 blk_queue_max_segments(q, port->ring_cookies);
862 blk_queue_max_hw_sectors(q, port->max_xfer_size);
864 g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
865 strcpy(g->disk_name, port->disk_name);
869 g->private_data = port;
871 set_capacity(g, port->vdisk_size);
873 if (vdc_version_supported(port, 1, 1)) {
874 switch (port->vdisk_mtype) {
876 pr_info(PFX "Virtual CDROM %s\n", port->disk_name);
883 pr_info(PFX "Virtual DVD %s\n", port->disk_name);
890 pr_info(PFX "Virtual Hard disk %s\n", port->disk_name);
895 blk_queue_physical_block_size(q, port->vdisk_phys_blksz);
899 port->vdisk_size, (port->vdisk_size >> (20 - 9)),
900 port->vio.ver.major, port->vio.ver.minor);
902 device_add_disk(&port->vio.vdev->dev, g, NULL);
952 * by locating all the virtual-device-port nodes associated
980 struct vdc_port *port;
1000 "VIO: Ignoring extra vdisk port %s",
1005 port = kzalloc(sizeof(*port), GFP_KERNEL);
1007 if (!port) {
1013 snprintf(port->disk_name, sizeof(port->disk_name),
1018 snprintf(port->disk_name, sizeof(port->disk_name),
1020 port->vdisk_size = -1;
1027 port->ldc_timeout = ldc_timeout ? *ldc_timeout : 0;
1028 INIT_DELAYED_WORK(&port->ldc_reset_timer_work, vdc_ldc_reset_timer_work);
1029 INIT_WORK(&port->ldc_reset_work, vdc_ldc_reset_work);
1031 err = vio_driver_init(&port->vio, vdev, VDEV_DISK,
1033 &vdc_vio_ops, port->disk_name);
1037 port->vdisk_block_size = VDC_DEFAULT_BLK_SIZE;
1038 port->max_xfer_size = MAX_XFER_SIZE;
1039 port->ring_cookies = MAX_RING_COOKIES;
1041 err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port);
1045 err = vdc_alloc_tx_ring(port);
1049 err = probe_disk(port);
1054 * whether the port has been probed.
1056 dev_set_drvdata(&vdev->dev, port);
1063 vdc_free_tx_ring(port);
1066 vio_ldc_free(&port->vio);
1069 kfree(port);
1078 struct vdc_port *port = dev_get_drvdata(&vdev->dev);
1080 if (port) {
1081 blk_mq_stop_hw_queues(port->disk->queue);
1083 flush_work(&port->ldc_reset_work);
1084 cancel_delayed_work_sync(&port->ldc_reset_timer_work);
1085 del_timer_sync(&port->vio.timer);
1087 del_gendisk(port->disk);
1088 cleanup_queue(port->disk->queue);
1089 put_disk(port->disk);
1090 port->disk = NULL;
1092 vdc_free_tx_ring(port);
1093 vio_ldc_free(&port->vio);
1097 kfree(port);
1102 static void vdc_requeue_inflight(struct vdc_port *port)
1104 struct vio_dring_state *dr = &port->vio.drings[VIO_DRIVER_TX_RING];
1109 struct vdc_req_entry *rqe = &port->rq_arr[idx];
1112 ldc_unmap(port->vio.lp, desc->cookies, desc->ncookies);
1118 vdc_end_special(port, desc);
1127 static void vdc_queue_drain(struct vdc_port *port)
1129 struct request_queue *q = port->disk->queue;
1135 port->drain = 1;
1136 spin_unlock_irq(&port->vio.lock);
1141 spin_lock_irq(&port->vio.lock);
1142 port->drain = 0;
1149 struct vdc_port *port;
1152 port = container_of(work, struct vdc_port, ldc_reset_timer_work.work);
1153 vio = &port->vio;
1156 if (!(port->vio.hs_state & VIO_HS_COMPLETE)) {
1158 port->disk_name, port->ldc_timeout);
1159 vdc_queue_drain(port);
1160 vdc_blk_queue_start(port);
1167 struct vdc_port *port;
1171 port = container_of(work, struct vdc_port, ldc_reset_work);
1172 vio = &port->vio;
1175 vdc_ldc_reset(port);
1179 static void vdc_ldc_reset(struct vdc_port *port)
1183 assert_spin_locked(&port->vio.lock);
1185 pr_warn(PFX "%s ldc link reset\n", port->disk_name);
1186 blk_mq_stop_hw_queues(port->disk->queue);
1187 vdc_requeue_inflight(port);
1188 vdc_port_down(port);
1190 err = vio_ldc_alloc(&port->vio, &vdc_ldc_cfg, port);
1192 pr_err(PFX "%s vio_ldc_alloc:%d\n", port->disk_name, err);
1196 err = vdc_alloc_tx_ring(port);
1198 pr_err(PFX "%s vio_alloc_tx_ring:%d\n", port->disk_name, err);
1202 if (port->ldc_timeout)
1203 mod_delayed_work(system_wq, &port->ldc_reset_timer_work,
1204 round_jiffies(jiffies + HZ * port->ldc_timeout));
1205 mod_timer(&port->vio.timer, round_jiffies(jiffies + HZ));
1209 vio_ldc_free(&port->vio);
1214 .type = "vdc-port",