|
@@ -51,55 +51,32 @@ ata_command ( struct ata_device *ata, struct ata_command *command ) {
|
51
|
51
|
}
|
52
|
52
|
|
53
|
53
|
/**
|
54
|
|
- * Read block from / write block to ATA device
|
|
54
|
+ * Read block from ATA device
|
55
|
55
|
*
|
56
|
|
- * @v write Write flag (ATA_FL_WRITE or 0)
|
57
|
56
|
* @v blockdev Block device
|
58
|
57
|
* @v block LBA block number
|
59
|
58
|
* @v count Block count
|
60
|
59
|
* @v buffer Data buffer
|
61
|
60
|
* @ret rc Return status code
|
62
|
61
|
*/
|
63
|
|
-static __attribute__ (( regparm ( 1 ) )) int
|
64
|
|
-ata_rw ( int write, struct block_device *blockdev, uint64_t block,
|
65
|
|
- unsigned long count, userptr_t buffer ) {
|
|
62
|
+static int ata_read ( struct block_device *blockdev, uint64_t block,
|
|
63
|
+ unsigned long count, userptr_t buffer ) {
|
66
|
64
|
struct ata_device *ata = block_to_ata ( blockdev );
|
67
|
65
|
struct ata_command command;
|
68
|
|
- int lba48 = ( ata->flags & ATA_FL_LBA48 );
|
69
|
66
|
|
70
|
67
|
memset ( &command, 0, sizeof ( command ) );
|
71
|
68
|
command.cb.lba.native = block;
|
72
|
69
|
command.cb.count.native = count;
|
73
|
|
- command.cb.device = ( ata->flags | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
|
74
|
|
- command.cb.flags = ( ata->flags | write );
|
75
|
|
- command.cb.cmd_stat = ( write ? ATA_CMD_WRITE : ATA_CMD_READ );
|
76
|
|
- if ( lba48 ) {
|
77
|
|
- command.cb.cmd_stat |= ATA_CMD_EXT;
|
78
|
|
- } else {
|
|
70
|
+ command.cb.device = ( ata->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
|
|
71
|
+ command.cb.lba48 = ata->lba48;
|
|
72
|
+ if ( ! ata->lba48 )
|
79
|
73
|
command.cb.device |= command.cb.lba.bytes.low_prev;
|
80
|
|
- }
|
81
|
|
- command.data = buffer;
|
82
|
|
- command.data_len = ( count * blockdev->blksize );
|
|
74
|
+ command.cb.cmd_stat = ( ata->lba48 ? ATA_CMD_READ_EXT : ATA_CMD_READ );
|
|
75
|
+ command.data_in = buffer;
|
|
76
|
+ command.data_in_len = ( count * blockdev->blksize );
|
83
|
77
|
return ata_command ( ata, &command );
|
84
|
78
|
}
|
85
|
79
|
|
86
|
|
-/**
|
87
|
|
- * Read block from ATA device
|
88
|
|
- *
|
89
|
|
- * @v blockdev Block device
|
90
|
|
- * @v block LBA block number
|
91
|
|
- * @v count Block count
|
92
|
|
- * @v buffer Data buffer
|
93
|
|
- * @ret rc Return status code
|
94
|
|
- */
|
95
|
|
-static int ata_read ( struct block_device *blockdev, uint64_t block,
|
96
|
|
- unsigned long count, userptr_t buffer ) {
|
97
|
|
- /* Pass through to ata_rw(). Since ata_rw is regparm(1), this
|
98
|
|
- * is extremely efficient; just a mov and a jmp.
|
99
|
|
- */
|
100
|
|
- return ata_rw ( 0, blockdev, block, count, buffer );
|
101
|
|
-}
|
102
|
|
-
|
103
|
80
|
/**
|
104
|
81
|
* Write block to ATA device
|
105
|
82
|
*
|
|
@@ -111,10 +88,21 @@ static int ata_read ( struct block_device *blockdev, uint64_t block,
|
111
|
88
|
*/
|
112
|
89
|
static int ata_write ( struct block_device *blockdev, uint64_t block,
|
113
|
90
|
unsigned long count, userptr_t buffer ) {
|
114
|
|
- /* Pass through to ata_rw(). Since ata_rw is regparm(1), this
|
115
|
|
- * is extremely efficient; just a mov and a jmp.
|
116
|
|
- */
|
117
|
|
- return ata_rw ( ATA_FL_WRITE, blockdev, block, count, buffer );
|
|
91
|
+ struct ata_device *ata = block_to_ata ( blockdev );
|
|
92
|
+ struct ata_command command;
|
|
93
|
+
|
|
94
|
+ memset ( &command, 0, sizeof ( command ) );
|
|
95
|
+ command.cb.lba.native = block;
|
|
96
|
+ command.cb.count.native = count;
|
|
97
|
+ command.cb.device = ( ata->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
|
|
98
|
+ command.cb.lba48 = ata->lba48;
|
|
99
|
+ if ( ! ata->lba48 )
|
|
100
|
+ command.cb.device |= command.cb.lba.bytes.low_prev;
|
|
101
|
+ command.cb.cmd_stat = ( ata->lba48 ?
|
|
102
|
+ ATA_CMD_WRITE_EXT : ATA_CMD_WRITE );
|
|
103
|
+ command.data_out = buffer;
|
|
104
|
+ command.data_out_len = ( count * blockdev->blksize );
|
|
105
|
+ return ata_command ( ata, &command );
|
118
|
106
|
}
|
119
|
107
|
|
120
|
108
|
/**
|
|
@@ -131,17 +119,19 @@ static int ata_identify ( struct block_device *blockdev ) {
|
131
|
119
|
|
132
|
120
|
/* Issue IDENTIFY */
|
133
|
121
|
memset ( &command, 0, sizeof ( command ) );
|
134
|
|
- command.cb.device = ( ata->flags | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
|
|
122
|
+ command.cb.count.native = 1; /* n/a according to spec, but at least
|
|
123
|
+ * AoE vblade devices require it. */
|
|
124
|
+ command.cb.device = ( ata->device | ATA_DEV_OBSOLETE | ATA_DEV_LBA );
|
135
|
125
|
command.cb.cmd_stat = ATA_CMD_IDENTIFY;
|
136
|
|
- command.data = virt_to_user ( &identity );
|
137
|
|
- command.data_len = sizeof ( identity );
|
|
126
|
+ command.data_in = virt_to_user ( &identity );
|
|
127
|
+ command.data_in_len = sizeof ( identity );
|
138
|
128
|
if ( ( rc = ata_command ( ata, &command ) ) != 0 )
|
139
|
129
|
return rc;
|
140
|
130
|
|
141
|
131
|
/* Fill in block device parameters */
|
142
|
132
|
blockdev->blksize = ATA_SECTOR_SIZE;
|
143
|
133
|
if ( identity.supports_lba48 & cpu_to_le16 ( ATA_SUPPORTS_LBA48 ) ) {
|
144
|
|
- ata->flags |= ATA_FL_LBA48;
|
|
134
|
+ ata->lba48 = 1;
|
145
|
135
|
blockdev->blocks = le64_to_cpu ( identity.lba48_sectors );
|
146
|
136
|
} else {
|
147
|
137
|
blockdev->blocks = le32_to_cpu ( identity.lba_sectors );
|