22
22
/**
23
23
* struct virtio_i2c - virtio I2C data
24
24
* @vdev: virtio device for this controller
25
- * @completion: completion of virtio I2C message
26
25
* @adap: I2C adapter for this controller
27
26
* @vq: the virtio virtqueue for communication
28
27
*/
29
28
struct virtio_i2c {
30
29
struct virtio_device * vdev ;
31
- struct completion completion ;
32
30
struct i2c_adapter adap ;
33
31
struct virtqueue * vq ;
34
32
};
35
33
36
34
/**
37
35
* struct virtio_i2c_req - the virtio I2C request structure
36
+ * @completion: completion of virtio I2C message
38
37
* @out_hdr: the OUT header of the virtio I2C message
39
38
* @buf: the buffer into which data is read, or from which it's written
40
39
* @in_hdr: the IN header of the virtio I2C message
41
40
*/
42
41
struct virtio_i2c_req {
42
+ struct completion completion ;
43
43
struct virtio_i2c_out_hdr out_hdr ____cacheline_aligned ;
44
44
uint8_t * buf ____cacheline_aligned ;
45
45
struct virtio_i2c_in_hdr in_hdr ____cacheline_aligned ;
46
46
};
47
47
48
48
static void virtio_i2c_msg_done (struct virtqueue * vq )
49
49
{
50
- struct virtio_i2c * vi = vq -> vdev -> priv ;
50
+ struct virtio_i2c_req * req ;
51
+ unsigned int len ;
51
52
52
- complete (& vi -> completion );
53
+ while ((req = virtqueue_get_buf (vq , & len )))
54
+ complete (& req -> completion );
53
55
}
54
56
55
57
static int virtio_i2c_prepare_reqs (struct virtqueue * vq ,
@@ -62,6 +64,8 @@ static int virtio_i2c_prepare_reqs(struct virtqueue *vq,
62
64
for (i = 0 ; i < num ; i ++ ) {
63
65
int outcnt = 0 , incnt = 0 ;
64
66
67
+ init_completion (& reqs [i ].completion );
68
+
65
69
/*
66
70
* Only 7-bit mode supported for this moment. For the address
67
71
* format, Please check the Virtio I2C Specification.
@@ -106,21 +110,15 @@ static int virtio_i2c_complete_reqs(struct virtqueue *vq,
106
110
struct virtio_i2c_req * reqs ,
107
111
struct i2c_msg * msgs , int num )
108
112
{
109
- struct virtio_i2c_req * req ;
110
113
bool failed = false;
111
- unsigned int len ;
112
114
int i , j = 0 ;
113
115
114
116
for (i = 0 ; i < num ; i ++ ) {
115
- /* Detach the ith request from the vq */
116
- req = virtqueue_get_buf (vq , & len );
117
+ struct virtio_i2c_req * req = & reqs [i ];
117
118
118
- /*
119
- * Condition req == &reqs[i] should always meet since we have
120
- * total num requests in the vq. reqs[i] can never be NULL here.
121
- */
122
- if (!failed && (WARN_ON (req != & reqs [i ]) ||
123
- req -> in_hdr .status != VIRTIO_I2C_MSG_OK ))
119
+ wait_for_completion (& req -> completion );
120
+
121
+ if (!failed && req -> in_hdr .status != VIRTIO_I2C_MSG_OK )
124
122
failed = true;
125
123
126
124
i2c_put_dma_safe_msg_buf (reqs [i ].buf , & msgs [i ], !failed );
@@ -156,12 +154,8 @@ static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
156
154
* remote here to clear the virtqueue, so we can try another set of
157
155
* messages later on.
158
156
*/
159
-
160
- reinit_completion (& vi -> completion );
161
157
virtqueue_kick (vq );
162
158
163
- wait_for_completion (& vi -> completion );
164
-
165
159
count = virtio_i2c_complete_reqs (vq , reqs , msgs , count );
166
160
167
161
err_free :
@@ -210,8 +204,6 @@ static int virtio_i2c_probe(struct virtio_device *vdev)
210
204
vdev -> priv = vi ;
211
205
vi -> vdev = vdev ;
212
206
213
- init_completion (& vi -> completion );
214
-
215
207
ret = virtio_i2c_setup_vqs (vi );
216
208
if (ret )
217
209
return ret ;
0 commit comments