|
@@ -70,7 +70,7 @@ static int scsi_command ( struct scsi_device *scsi,
|
70
|
70
|
}
|
71
|
71
|
|
72
|
72
|
/**
|
73
|
|
- * Read block from SCSI device
|
|
73
|
+ * Read block from SCSI device using READ (10)
|
74
|
74
|
*
|
75
|
75
|
* @v blockdev Block device
|
76
|
76
|
* @v block LBA block number
|
|
@@ -78,8 +78,33 @@ static int scsi_command ( struct scsi_device *scsi,
|
78
|
78
|
* @v buffer Data buffer
|
79
|
79
|
* @ret rc Return status code
|
80
|
80
|
*/
|
81
|
|
-static int scsi_read ( struct block_device *blockdev, uint64_t block,
|
82
|
|
- unsigned long count, userptr_t buffer ) {
|
|
81
|
+static int scsi_read_10 ( struct block_device *blockdev, uint64_t block,
|
|
82
|
+ unsigned long count, userptr_t buffer ) {
|
|
83
|
+ struct scsi_device *scsi = block_to_scsi ( blockdev );
|
|
84
|
+ struct scsi_command command;
|
|
85
|
+ struct scsi_cdb_read_10 *cdb = &command.cdb.read10;
|
|
86
|
+
|
|
87
|
+ /* Issue READ (10) */
|
|
88
|
+ memset ( &command, 0, sizeof ( command ) );
|
|
89
|
+ cdb->opcode = SCSI_OPCODE_READ_10;
|
|
90
|
+ cdb->lba = cpu_to_be32 ( block );
|
|
91
|
+ cdb->len = cpu_to_be16 ( count );
|
|
92
|
+ command.data_in = buffer;
|
|
93
|
+ command.data_in_len = ( count * blockdev->blksize );
|
|
94
|
+ return scsi_command ( scsi, &command );
|
|
95
|
+}
|
|
96
|
+
|
|
97
|
+/**
|
|
98
|
+ * Read block from SCSI device using READ (16)
|
|
99
|
+ *
|
|
100
|
+ * @v blockdev Block device
|
|
101
|
+ * @v block LBA block number
|
|
102
|
+ * @v count Block count
|
|
103
|
+ * @v buffer Data buffer
|
|
104
|
+ * @ret rc Return status code
|
|
105
|
+ */
|
|
106
|
+static int scsi_read_16 ( struct block_device *blockdev, uint64_t block,
|
|
107
|
+ unsigned long count, userptr_t buffer ) {
|
83
|
108
|
struct scsi_device *scsi = block_to_scsi ( blockdev );
|
84
|
109
|
struct scsi_command command;
|
85
|
110
|
struct scsi_cdb_read_16 *cdb = &command.cdb.read16;
|
|
@@ -95,7 +120,7 @@ static int scsi_read ( struct block_device *blockdev, uint64_t block,
|
95
|
120
|
}
|
96
|
121
|
|
97
|
122
|
/**
|
98
|
|
- * Write block to SCSI device
|
|
123
|
+ * Write block to SCSI device using WRITE (10)
|
99
|
124
|
*
|
100
|
125
|
* @v blockdev Block device
|
101
|
126
|
* @v block LBA block number
|
|
@@ -103,8 +128,33 @@ static int scsi_read ( struct block_device *blockdev, uint64_t block,
|
103
|
128
|
* @v buffer Data buffer
|
104
|
129
|
* @ret rc Return status code
|
105
|
130
|
*/
|
106
|
|
-static int scsi_write ( struct block_device *blockdev, uint64_t block,
|
107
|
|
- unsigned long count, userptr_t buffer ) {
|
|
131
|
+static int scsi_write_10 ( struct block_device *blockdev, uint64_t block,
|
|
132
|
+ unsigned long count, userptr_t buffer ) {
|
|
133
|
+ struct scsi_device *scsi = block_to_scsi ( blockdev );
|
|
134
|
+ struct scsi_command command;
|
|
135
|
+ struct scsi_cdb_write_10 *cdb = &command.cdb.write10;
|
|
136
|
+
|
|
137
|
+ /* Issue WRITE (10) */
|
|
138
|
+ memset ( &command, 0, sizeof ( command ) );
|
|
139
|
+ cdb->opcode = SCSI_OPCODE_WRITE_10;
|
|
140
|
+ cdb->lba = cpu_to_be32 ( block );
|
|
141
|
+ cdb->len = cpu_to_be16 ( count );
|
|
142
|
+ command.data_out = buffer;
|
|
143
|
+ command.data_out_len = ( count * blockdev->blksize );
|
|
144
|
+ return scsi_command ( scsi, &command );
|
|
145
|
+}
|
|
146
|
+
|
|
147
|
+/**
|
|
148
|
+ * Write block to SCSI device using WRITE (16)
|
|
149
|
+ *
|
|
150
|
+ * @v blockdev Block device
|
|
151
|
+ * @v block LBA block number
|
|
152
|
+ * @v count Block count
|
|
153
|
+ * @v buffer Data buffer
|
|
154
|
+ * @ret rc Return status code
|
|
155
|
+ */
|
|
156
|
+static int scsi_write_16 ( struct block_device *blockdev, uint64_t block,
|
|
157
|
+ unsigned long count, userptr_t buffer ) {
|
108
|
158
|
struct scsi_device *scsi = block_to_scsi ( blockdev );
|
109
|
159
|
struct scsi_command command;
|
110
|
160
|
struct scsi_cdb_write_16 *cdb = &command.cdb.write16;
|
|
@@ -179,12 +229,17 @@ static int scsi_read_capacity_16 ( struct block_device *blockdev ) {
|
179
|
229
|
}
|
180
|
230
|
|
181
|
231
|
/**
|
182
|
|
- * Read capacity of SCSI device
|
|
232
|
+ * Initialise SCSI device
|
183
|
233
|
*
|
184
|
|
- * @v blockdev Block device
|
|
234
|
+ * @v scsi SCSI device
|
185
|
235
|
* @ret rc Return status code
|
|
236
|
+ *
|
|
237
|
+ * Initialises a SCSI device. The scsi_device::command and
|
|
238
|
+ * scsi_device::lun fields must already be filled in. This function
|
|
239
|
+ * will configure scsi_device::blockdev, including issuing a READ
|
|
240
|
+ * CAPACITY call to determine the block size and total device size.
|
186
|
241
|
*/
|
187
|
|
-static int scsi_read_capacity ( struct block_device *blockdev ) {
|
|
242
|
+int init_scsidev ( struct scsi_device *scsi ) {
|
188
|
243
|
int rc;
|
189
|
244
|
|
190
|
245
|
/* Issue a theoretically extraneous READ CAPACITY (10)
|
|
@@ -192,10 +247,12 @@ static int scsi_read_capacity ( struct block_device *blockdev ) {
|
192
|
247
|
* (power-on occurred)" that some dumb targets insist on
|
193
|
248
|
* sending as an error at start of day.
|
194
|
249
|
*/
|
195
|
|
- scsi_read_capacity_10 ( blockdev );
|
|
250
|
+ scsi_read_capacity_10 ( &scsi->blockdev );
|
196
|
251
|
|
197
|
252
|
/* Try READ CAPACITY (10), which is a mandatory command, first. */
|
198
|
|
- if ( ( rc = scsi_read_capacity_10 ( blockdev ) ) != 0 )
|
|
253
|
+ scsi->blockdev.read = scsi_read_10;
|
|
254
|
+ scsi->blockdev.write = scsi_write_10;
|
|
255
|
+ if ( ( rc = scsi_read_capacity_10 ( &scsi->blockdev ) ) != 0 )
|
199
|
256
|
return rc;
|
200
|
257
|
|
201
|
258
|
/* If capacity range was exceeded (i.e. capacity.lba was
|
|
@@ -203,28 +260,12 @@ static int scsi_read_capacity ( struct block_device *blockdev ) {
|
203
|
260
|
* READ CAPACITY (16) instead. READ CAPACITY (16) is not
|
204
|
261
|
* mandatory, so we can't just use it straight off.
|
205
|
262
|
*/
|
206
|
|
- if ( blockdev->blocks == 0 ) {
|
207
|
|
- if ( ( rc = scsi_read_capacity_16 ( blockdev ) ) != 0 )
|
|
263
|
+ if ( scsi->blockdev.blocks == 0 ) {
|
|
264
|
+ scsi->blockdev.read = scsi_read_16;
|
|
265
|
+ scsi->blockdev.write = scsi_write_16;
|
|
266
|
+ if ( ( rc = scsi_read_capacity_16 ( &scsi->blockdev ) ) != 0 )
|
208
|
267
|
return rc;
|
209
|
268
|
}
|
210
|
269
|
|
211
|
270
|
return 0;
|
212
|
271
|
}
|
213
|
|
-
|
214
|
|
-/**
|
215
|
|
- * Initialise SCSI device
|
216
|
|
- *
|
217
|
|
- * @v scsi SCSI device
|
218
|
|
- * @ret rc Return status code
|
219
|
|
- *
|
220
|
|
- * Initialises a SCSI device. The scsi_device::command and
|
221
|
|
- * scsi_device::lun fields must already be filled in. This function
|
222
|
|
- * will configure scsi_device::blockdev, including issuing a READ
|
223
|
|
- * CAPACITY call to determine the block size and total device size.
|
224
|
|
- */
|
225
|
|
-int init_scsidev ( struct scsi_device *scsi ) {
|
226
|
|
- /** Fill in read and write methods, and get device capacity */
|
227
|
|
- scsi->blockdev.read = scsi_read;
|
228
|
|
- scsi->blockdev.write = scsi_write;
|
229
|
|
- return scsi_read_capacity ( &scsi->blockdev );
|
230
|
|
-}
|