summaryrefslogtreecommitdiffstats
path: root/sys/dev/ata
diff options
context:
space:
mode:
authorsos <sos@FreeBSD.org>2005-05-16 13:07:27 +0000
committersos <sos@FreeBSD.org>2005-05-16 13:07:27 +0000
commit05399c3127201bae2332eabeb69a6ab15c2b9490 (patch)
tree6f0fc5c74cd330db252bdb9572d9fd9b43828619 /sys/dev/ata
parentc0de585b6b6e5dcb8df1e814b54bbe8e0d7b2db4 (diff)
downloadFreeBSD-src-05399c3127201bae2332eabeb69a6ab15c2b9490.zip
FreeBSD-src-05399c3127201bae2332eabeb69a6ab15c2b9490.tar.gz
Change the way ioctls are issue to ATA.
The most prominent part is that its now possible to issue ata_requests directly to say acd0, instead of going through the cumbersome /dev/ata device.
Diffstat (limited to 'sys/dev/ata')
-rw-r--r--sys/dev/ata/ata-all.c349
-rw-r--r--sys/dev/ata/ata-all.h161
-rw-r--r--sys/dev/ata/ata-chipset.c98
-rw-r--r--sys/dev/ata/ata-disk.c8
-rw-r--r--sys/dev/ata/ata-lowlevel.c83
-rw-r--r--sys/dev/ata/ata-pci.h10
-rw-r--r--sys/dev/ata/ata-raid.c85
-rw-r--r--sys/dev/ata/atapi-cam.c2
-rw-r--r--sys/dev/ata/atapi-cd.c3
-rw-r--r--sys/dev/ata/atapi-fd.c8
-rw-r--r--sys/dev/ata/atapi-tape.c16
11 files changed, 398 insertions, 425 deletions
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c
index 57534a6..6b70448 100644
--- a/sys/dev/ata/ata-all.c
+++ b/sys/dev/ata/ata-all.c
@@ -53,7 +53,6 @@ __FBSDID("$FreeBSD$");
#include <machine/md_var.h>
#endif
#include <dev/ata/ata-all.h>
-#include <dev/ata/ata-commands.h>
#include <ata_if.h>
/* device structure */
@@ -75,7 +74,7 @@ static void bpack(int8_t *, int8_t *, int);
/* global vars */
MALLOC_DEFINE(M_ATA, "ATA generic", "ATA driver generic layer");
-int (*ata_ioctl_func)(struct ata_cmd *iocmd) = NULL;
+int (*ata_raid_ioctl_func)(u_long cmd, caddr_t data) = NULL;
devclass_t ata_devclass;
uma_zone_t ata_request_zone;
uma_zone_t ata_composite_zone;
@@ -338,100 +337,68 @@ ata_interrupt(void *data)
* device related interfaces
*/
static int
-ata_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
+ata_ioctl(struct cdev *dev, u_long cmd, caddr_t data,
int32_t flag, struct thread *td)
{
- struct ata_cmd *iocmd = (struct ata_cmd *)addr;
- device_t *children, device = NULL;
- struct ata_request *request;
- caddr_t buf;
- int nchildren, i;
- int error = ENOTTY;
-
- if (cmd != IOCATA)
- return ENOTSUP;
- if (iocmd->cmd == ATAGMAXCHANNEL) {
- iocmd->u.maxchan = devclass_get_maxunit(ata_devclass);
- return 0;
- }
- if (iocmd->channel < 0 ||
- iocmd->channel >= devclass_get_maxunit(ata_devclass)) {
- return ENXIO;
- }
- if (!(device = devclass_get_device(ata_devclass, iocmd->channel)))
- return ENXIO;
-
- switch (iocmd->cmd) {
- case ATAGPARM:
- if (!device_get_children(device, &children, &nchildren)) {
- struct ata_channel *ch;
-
- if (!(ch = device_get_softc(device)))
- return ENXIO;
- iocmd->u.param.type[0] =
- ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER);
- iocmd->u.param.type[1] =
- ch->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE);
- for (i = 0; i < nchildren; i++) {
- if (children[i] && device_is_attached(children[i])) {
- struct ata_device *atadev = device_get_softc(children[i]);
+ device_t device, *children;
+ struct ata_ioc_devices *devices = (struct ata_ioc_devices *)data;
+ int *value = (int *)data;
+ int i, nchildren, error = ENOTTY;
+
+ switch (cmd) {
+ case IOCATAGMAXCHANNEL:
+ *value = devclass_get_maxunit(ata_devclass);
+ error = 0;
+ break;
- if (atadev->unit == ATA_MASTER) {
- strcpy(iocmd->u.param.name[0],
- device_get_nameunit(children[i]));
- bcopy(&atadev->param, &iocmd->u.param.params[0],
- sizeof(struct ata_params));
- }
- if (atadev->unit == ATA_SLAVE) {
- strcpy(iocmd->u.param.name[1],
- device_get_nameunit(children[i]));
- bcopy(&atadev->param, &iocmd->u.param.params[1],
- sizeof(struct ata_params));
- }
- }
- }
- free(children, M_TEMP);
- error = 0;
- }
- else
- error = ENXIO;
+ case IOCATAREINIT:
+ if (*value > devclass_get_maxunit(ata_devclass) ||
+ !(device = devclass_get_device(ata_devclass, *value)))
+ return ENXIO;
+ error = ata_reinit(device);
+ ata_start(device);
break;
- case ATAGMODE:
- if (!device_get_children(device, &children, &nchildren)) {
- for (i = 0; i < nchildren; i++) {
- if (children[i] && device_is_attached(children[i])) {
- struct ata_device *atadev = device_get_softc(children[i]);
+ case IOCATAATTACH:
+ if (*value > devclass_get_maxunit(ata_devclass) ||
+ !(device = devclass_get_device(ata_devclass, *value)))
+ return ENXIO;
+ /* XXX SOS should enable channel HW on controller */
+ error = ata_attach(device);
+ break;
- atadev = device_get_softc(children[i]);
- if (atadev->unit == ATA_MASTER)
- iocmd->u.mode.mode[0] = atadev->mode;
- if (atadev->unit == ATA_SLAVE)
- iocmd->u.mode.mode[1] = atadev->mode;
- }
- free(children, M_TEMP);
- }
- error = 0;
- }
- else
- error = ENXIO;
+ case IOCATADETACH:
+ if (*value > devclass_get_maxunit(ata_devclass) ||
+ !(device = devclass_get_device(ata_devclass, *value)))
+ return ENXIO;
+ error = ata_detach(device);
+ /* XXX SOS should disable channel HW on controller */
break;
- case ATASMODE:
+ case IOCATADEVICES:
+ if (devices->channel > devclass_get_maxunit(ata_devclass) ||
+ !(device = devclass_get_device(ata_devclass, devices->channel)))
+ return ENXIO;
+ bzero(devices->name[0], 32);
+ bzero(&devices->params[0], sizeof(struct ata_params));
+ bzero(devices->name[1], 32);
+ bzero(&devices->params[1], sizeof(struct ata_params));
if (!device_get_children(device, &children, &nchildren)) {
for (i = 0; i < nchildren; i++) {
- if (children[i] && device_is_attached(children[i])) {
+ if (children[i] && device_is_attached(children[i])) {
struct ata_device *atadev = device_get_softc(children[i]);
if (atadev->unit == ATA_MASTER) {
- atadev->mode = iocmd->u.mode.mode[0];
- ATA_SETMODE(device, children[i]);
- iocmd->u.mode.mode[0] = atadev->mode;
+ strncpy(devices->name[0],
+ device_get_nameunit(children[i]), 32);
+ bcopy(&atadev->param, &devices->params[0],
+ sizeof(struct ata_params));
}
if (atadev->unit == ATA_SLAVE) {
- atadev->mode = iocmd->u.mode.mode[1];
- ATA_SETMODE(device, children[i]);
- iocmd->u.mode.mode[1] = atadev->mode;
+ strncpy(devices->name[1],
+ device_get_nameunit(children[i]), 32);
+ bcopy(&atadev->param, &devices->params[1],
+ sizeof(struct ata_params));
}
}
}
@@ -439,106 +406,96 @@ ata_ioctl(struct cdev *dev, u_long cmd, caddr_t addr,
error = 0;
}
else
- error = ENXIO;
+ error = ENODEV;
break;
- case ATAREQUEST:
- if (!device_get_children(device, &children, &nchildren)) {
- for (i = 0; i < nchildren; i++) {
- if (children[i] && device_is_attached(children[i])) {
- struct ata_device *atadev = device_get_softc(children[i]);
+ default:
+ if (ata_raid_ioctl_func)
+ error = ata_raid_ioctl_func(cmd, data);
+ }
+ return error;
+}
- if (ATA_DEV(atadev->unit) == iocmd->device) {
- if (!(buf = malloc(iocmd->u.request.count,
- M_ATA, M_NOWAIT))) {
- error = ENOMEM;
- break;
- }
- if (!(request = ata_alloc_request())) {
- error = ENOMEM;
- free(buf, M_ATA);
- break;
- }
- if (iocmd->u.request.flags & ATA_CMD_WRITE) {
- error = copyin(iocmd->u.request.data, buf,
- iocmd->u.request.count);
- if (error) {
- free(buf, M_ATA);
- ata_free_request(request);
- break;
- }
- }
- request->dev = atadev->dev;
- if (iocmd->u.request.flags & ATA_CMD_ATAPI) {
- request->flags = ATA_R_ATAPI;
- bcopy(iocmd->u.request.u.atapi.ccb,
- request->u.atapi.ccb, 16);
- }
- else {
- request->u.ata.command =
- iocmd->u.request.u.ata.command;
- request->u.ata.feature =
- iocmd->u.request.u.ata.feature;
- request->u.ata.lba = iocmd->u.request.u.ata.lba;
- request->u.ata.count = iocmd->u.request.u.ata.count;
- }
- request->timeout = iocmd->u.request.timeout;
- request->data = buf;
- request->bytecount = iocmd->u.request.count;
- request->transfersize = request->bytecount;
- if (iocmd->u.request.flags & ATA_CMD_CONTROL)
- request->flags |= ATA_R_CONTROL;
- if (iocmd->u.request.flags & ATA_CMD_READ)
- request->flags |= ATA_R_READ;
- if (iocmd->u.request.flags & ATA_CMD_WRITE)
- request->flags |= ATA_R_WRITE;
- ata_queue_request(request);
- if (!(request->flags & ATA_R_ATAPI)) {
- iocmd->u.request.u.ata.command =
- request->u.ata.command;
- iocmd->u.request.u.ata.feature =
- request->u.ata.feature;
- iocmd->u.request.u.ata.lba = request->u.ata.lba;
- iocmd->u.request.u.ata.count = request->u.ata.count;
- }
- iocmd->u.request.error = request->result;
- if (iocmd->u.request.flags & ATA_CMD_READ)
- error = copyout(buf, iocmd->u.request.data,
- iocmd->u.request.count);
- else
- error = 0;
- free(buf, M_ATA);
- ata_free_request(request);
- break;
- }
- }
+int
+ata_device_ioctl(device_t dev, u_long cmd, caddr_t data)
+{
+ struct ata_device *atadev = device_get_softc(dev);
+ struct ata_ioc_request *ioc_request = (struct ata_ioc_request *)data;
+ struct ata_params *params = (struct ata_params *)data;
+ int *mode = (int *)data;
+ struct ata_request *request;
+ caddr_t buf;
+ int error;
+
+ switch (cmd) {
+ case IOCATAREQUEST:
+ if (!(buf = malloc(ioc_request->count, M_ATA, M_NOWAIT))) {
+ return ENOMEM;
+ }
+ if (!(request = ata_alloc_request())) {
+ free(buf, M_ATA);
+ return ENOMEM;
+ }
+ if (ioc_request->flags & ATA_CMD_WRITE) {
+ error = copyin(ioc_request->data, buf, ioc_request->count);
+ if (error) {
+ free(buf, M_ATA);
+ ata_free_request(request);
+ return error;
}
- free(children, M_TEMP);
}
+ request->dev = dev;
+ if (ioc_request->flags & ATA_CMD_ATAPI) {
+ request->flags = ATA_R_ATAPI;
+ bcopy(ioc_request->u.atapi.ccb, request->u.atapi.ccb, 16);
+ }
+ else {
+ request->u.ata.command = ioc_request->u.ata.command;
+ request->u.ata.feature = ioc_request->u.ata.feature;
+ request->u.ata.lba = ioc_request->u.ata.lba;
+ request->u.ata.count = ioc_request->u.ata.count;
+ }
+ request->timeout = ioc_request->timeout;
+ request->data = buf;
+ request->bytecount = ioc_request->count;
+ request->transfersize = request->bytecount;
+ if (ioc_request->flags & ATA_CMD_CONTROL)
+ request->flags |= ATA_R_CONTROL;
+ if (ioc_request->flags & ATA_CMD_READ)
+ request->flags |= ATA_R_READ;
+ if (ioc_request->flags & ATA_CMD_WRITE)
+ request->flags |= ATA_R_WRITE;
+ ata_queue_request(request);
+ if (!(request->flags & ATA_R_ATAPI)) {
+ ioc_request->u.ata.command = request->u.ata.command;
+ ioc_request->u.ata.feature = request->u.ata.feature;
+ ioc_request->u.ata.lba = request->u.ata.lba;
+ ioc_request->u.ata.count = request->u.ata.count;
+ }
+ ioc_request->error = request->result;
+ if (ioc_request->flags & ATA_CMD_READ)
+ error = copyout(buf, ioc_request->data, ioc_request->count);
else
- error = ENXIO;
- break;
-
- case ATAREINIT:
- error = ata_reinit(device);
- ata_start(device);
- break;
-
- case ATAATTACH:
- /* XXX SOS should enable channel HW on controller */
- error = ata_attach(device);
- break;
-
- case ATADETACH:
- error = ata_detach(device);
- /* XXX SOS should disable channel HW on controller */
- break;
+ error = 0;
+ free(buf, M_ATA);
+ ata_free_request(request);
+ return error;
+
+ case IOCATAGPARM:
+ bcopy(&atadev->param, params, sizeof(struct ata_params));
+ return 0;
+
+ case IOCATASMODE:
+ atadev->mode = *mode;
+ ATA_SETMODE(device_get_parent(dev), dev);
+ return 0;
+ case IOCATAGMODE:
+ *mode = atadev->mode;
+ return 0;
default:
- if (ata_ioctl_func)
- error = ata_ioctl_func(iocmd);
+ return ENOTTY;
}
- return error;
}
static void
@@ -572,12 +529,7 @@ ata_add_child(device_t parent, struct ata_device *atadev, int unit)
device_t child;
if ((child = device_add_child(parent, NULL, unit))) {
- char buffer[64];
-
device_set_softc(child, atadev);
- sprintf(buffer, "%.40s/%.8s",
- atadev->param.model, atadev->param.revision);
- device_set_desc_copy(child, buffer);
device_quiet(child);
atadev->dev = child;
atadev->max_iosize = DEV_BSIZE;
@@ -623,6 +575,7 @@ ata_getparam(device_t parent, struct ata_device *atadev)
if (!error && (isprint(atadev->param.model[0]) ||
isprint(atadev->param.model[1]))) {
struct ata_params *atacap = &atadev->param;
+ char buffer[64];
#if BYTE_ORDER == BIG_ENDIAN
int16_t *ptr;
@@ -645,6 +598,8 @@ ata_getparam(device_t parent, struct ata_device *atadev)
bpack(atacap->revision, atacap->revision, sizeof(atacap->revision));
btrim(atacap->serial, sizeof(atacap->serial));
bpack(atacap->serial, atacap->serial, sizeof(atacap->serial));
+ sprintf(buffer, "%.40s/%.8s", atacap->model, atacap->revision);
+ device_set_desc_copy(atadev->dev, buffer);
if (bootverbose)
printf("ata%d-%s: pio=%s wdma=%s udma=%s cable=%s wire\n",
ch->unit, atadev->unit == ATA_MASTER ? "master":"slave",
@@ -754,26 +709,26 @@ ata_modify_if_48bit(struct ata_request *request)
request->u.ata.count > 256) &&
atadev->param.support.command2 & ATA_SUPPORT_ADDRESS48) {
- /* translate command into 48bit version */
- switch (command) {
- case ATA_READ:
- command = ATA_READ48; break;
- case ATA_READ_MUL:
- command = ATA_READ_MUL48; break;
- case ATA_READ_DMA:
- command = ATA_READ_DMA48; break;
- case ATA_READ_DMA_QUEUED:
- command = ATA_READ_DMA_QUEUED48; break;
- case ATA_WRITE:
- command = ATA_WRITE48; break;
- case ATA_WRITE_MUL:
- command = ATA_WRITE_MUL48; break;
- case ATA_WRITE_DMA:
- command = ATA_WRITE_DMA48; break;
- case ATA_WRITE_DMA_QUEUED:
- command = ATA_WRITE_DMA_QUEUED48; break;
- case ATA_FLUSHCACHE:
- command = ATA_FLUSHCACHE48; break;
+ /* translate command into 48bit version */
+ switch (command) {
+ case ATA_READ:
+ command = ATA_READ48; break;
+ case ATA_READ_MUL:
+ command = ATA_READ_MUL48; break;
+ case ATA_READ_DMA:
+ command = ATA_READ_DMA48; break;
+ case ATA_READ_DMA_QUEUED:
+ command = ATA_READ_DMA_QUEUED48; break;
+ case ATA_WRITE:
+ command = ATA_WRITE48; break;
+ case ATA_WRITE_MUL:
+ command = ATA_WRITE_MUL48; break;
+ case ATA_WRITE_DMA:
+ command = ATA_WRITE_DMA48; break;
+ case ATA_WRITE_DMA_QUEUED:
+ command = ATA_WRITE_DMA_QUEUED48; break;
+ case ATA_FLUSHCACHE:
+ command = ATA_FLUSHCACHE48; break;
default:
return command;
}
diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h
index 47b9604..396a0fd 100644
--- a/sys/dev/ata/ata-all.h
+++ b/sys/dev/ata/ata-all.h
@@ -163,87 +163,87 @@
#define ATA_SC_IPM_DIS_PARTIAL 0x00000100
#define ATA_SC_IPM_DIS_SLUMBER 0x00000200
-#define ATA_SACTIVE 16
+#define ATA_SACTIVE 16
/* SATA AHCI v1.0 register defines */
-#define ATA_AHCI_CAP 0x00
-#define ATA_AHCI_NPMASK 0x1f
-
-#define ATA_AHCI_GHC 0x04
-#define ATA_AHCI_GHC_AE 0x80000000
-#define ATA_AHCI_GHC_IE 0x00000002
-#define ATA_AHCI_GHC_HR 0x80000001
-
-#define ATA_AHCI_IS 0x08
-#define ATA_AHCI_PI 0x0c
-#define ATA_AHCI_VS 0x10
-
-#define ATA_AHCI_OFFSET 0x80
-
-#define ATA_AHCI_P_CLB 0x100
-#define ATA_AHCI_P_CLBU 0x104
-#define ATA_AHCI_P_FB 0x108
-#define ATA_AHCI_P_FBU 0x10c
-#define ATA_AHCI_P_IS 0x110
-#define ATA_AHCI_P_IE 0x114
-#define ATA_AHCI_P_IX_DHR 0x00000001
-#define ATA_AHCI_P_IX_PS 0x00000002
-#define ATA_AHCI_P_IX_DS 0x00000004
-#define ATA_AHCI_P_IX_SDB 0x00000008
-#define ATA_AHCI_P_IX_UF 0x00000010
-#define ATA_AHCI_P_IX_DP 0x00000020
-#define ATA_AHCI_P_IX_PC 0x00000040
-#define ATA_AHCI_P_IX_DI 0x00000080
-
-#define ATA_AHCI_P_IX_PRC 0x00400000
-#define ATA_AHCI_P_IX_IPM 0x00800000
-#define ATA_AHCI_P_IX_OF 0x01000000
-#define ATA_AHCI_P_IX_INF 0x04000000
-#define ATA_AHCI_P_IX_IF 0x08000000
-#define ATA_AHCI_P_IX_HBD 0x10000000
-#define ATA_AHCI_P_IX_HBF 0x20000000
-#define ATA_AHCI_P_IX_TFE 0x40000000
-#define ATA_AHCI_P_IX_CPD 0x80000000
-
-#define ATA_AHCI_P_CMD 0x118
-#define ATA_AHCI_P_CMD_ST 0x00000001
-#define ATA_AHCI_P_CMD_SUD 0x00000002
-#define ATA_AHCI_P_CMD_POD 0x00000004
-#define ATA_AHCI_P_CMD_CLO 0x00000008
-#define ATA_AHCI_P_CMD_FRE 0x00000010
-#define ATA_AHCI_P_CMD_CCS_MASK 0x00001f00
-#define ATA_AHCI_P_CMD_ISS 0x00002000
-#define ATA_AHCI_P_CMD_FR 0x00004000
-#define ATA_AHCI_P_CMD_CR 0x00008000
-#define ATA_AHCI_P_CMD_CPS 0x00010000
-#define ATA_AHCI_P_CMD_PMA 0x00020000
-#define ATA_AHCI_P_CMD_HPCP 0x00040000
-#define ATA_AHCI_P_CMD_ISP 0x00080000
-#define ATA_AHCI_P_CMD_CPD 0x00100000
-#define ATA_AHCI_P_CMD_ATAPI 0x01000000
-#define ATA_AHCI_P_CMD_DLAE 0x02000000
-#define ATA_AHCI_P_CMD_ALPE 0x04000000
-#define ATA_AHCI_P_CMD_ASP 0x08000000
-#define ATA_AHCI_P_CMD_ICC_MASK 0xf0000000
-#define ATA_AHCI_P_CMD_NOOP 0x00000000
-#define ATA_AHCI_P_CMD_ACTIVE 0x10000000
-#define ATA_AHCI_P_CMD_PARTIAL 0x20000000
-#define ATA_AHCI_P_CMD_SLUMPER 0x60000000
-
-#define ATA_AHCI_P_TFD 0x120
-#define ATA_AHCI_P_SIG 0x124
-#define ATA_AHCI_P_SSTS 0x128
-#define ATA_AHCI_P_SCTL 0x12c
-#define ATA_AHCI_P_SERR 0x130
-#define ATA_AHCI_P_SACT 0x134
-#define ATA_AHCI_P_CI 0x138
-
-#define ATA_AHCI_CL_SIZE 32
-#define ATA_AHCI_CL_OFFSET 0
-#define ATA_AHCI_FB_OFFSET 1024
-#define ATA_AHCI_CT_OFFSET 1024+256
-#define ATA_AHCI_CT_SG_OFFSET 128
-#define ATA_AHCI_CT_SIZE 256
+#define ATA_AHCI_CAP 0x00
+#define ATA_AHCI_NPMASK 0x1f
+
+#define ATA_AHCI_GHC 0x04
+#define ATA_AHCI_GHC_AE 0x80000000
+#define ATA_AHCI_GHC_IE 0x00000002
+#define ATA_AHCI_GHC_HR 0x80000001
+
+#define ATA_AHCI_IS 0x08
+#define ATA_AHCI_PI 0x0c
+#define ATA_AHCI_VS 0x10
+
+#define ATA_AHCI_OFFSET 0x80
+
+#define ATA_AHCI_P_CLB 0x100
+#define ATA_AHCI_P_CLBU 0x104
+#define ATA_AHCI_P_FB 0x108
+#define ATA_AHCI_P_FBU 0x10c
+#define ATA_AHCI_P_IS 0x110
+#define ATA_AHCI_P_IE 0x114
+#define ATA_AHCI_P_IX_DHR 0x00000001
+#define ATA_AHCI_P_IX_PS 0x00000002
+#define ATA_AHCI_P_IX_DS 0x00000004
+#define ATA_AHCI_P_IX_SDB 0x00000008
+#define ATA_AHCI_P_IX_UF 0x00000010
+#define ATA_AHCI_P_IX_DP 0x00000020
+#define ATA_AHCI_P_IX_PC 0x00000040
+#define ATA_AHCI_P_IX_DI 0x00000080
+
+#define ATA_AHCI_P_IX_PRC 0x00400000
+#define ATA_AHCI_P_IX_IPM 0x00800000
+#define ATA_AHCI_P_IX_OF 0x01000000
+#define ATA_AHCI_P_IX_INF 0x04000000
+#define ATA_AHCI_P_IX_IF 0x08000000
+#define ATA_AHCI_P_IX_HBD 0x10000000
+#define ATA_AHCI_P_IX_HBF 0x20000000
+#define ATA_AHCI_P_IX_TFE 0x40000000
+#define ATA_AHCI_P_IX_CPD 0x80000000
+
+#define ATA_AHCI_P_CMD 0x118
+#define ATA_AHCI_P_CMD_ST 0x00000001
+#define ATA_AHCI_P_CMD_SUD 0x00000002
+#define ATA_AHCI_P_CMD_POD 0x00000004
+#define ATA_AHCI_P_CMD_CLO 0x00000008
+#define ATA_AHCI_P_CMD_FRE 0x00000010
+#define ATA_AHCI_P_CMD_CCS_MASK 0x00001f00
+#define ATA_AHCI_P_CMD_ISS 0x00002000
+#define ATA_AHCI_P_CMD_FR 0x00004000
+#define ATA_AHCI_P_CMD_CR 0x00008000
+#define ATA_AHCI_P_CMD_CPS 0x00010000
+#define ATA_AHCI_P_CMD_PMA 0x00020000
+#define ATA_AHCI_P_CMD_HPCP 0x00040000
+#define ATA_AHCI_P_CMD_ISP 0x00080000
+#define ATA_AHCI_P_CMD_CPD 0x00100000
+#define ATA_AHCI_P_CMD_ATAPI 0x01000000
+#define ATA_AHCI_P_CMD_DLAE 0x02000000
+#define ATA_AHCI_P_CMD_ALPE 0x04000000
+#define ATA_AHCI_P_CMD_ASP 0x08000000
+#define ATA_AHCI_P_CMD_ICC_MASK 0xf0000000
+#define ATA_AHCI_P_CMD_NOOP 0x00000000
+#define ATA_AHCI_P_CMD_ACTIVE 0x10000000
+#define ATA_AHCI_P_CMD_PARTIAL 0x20000000
+#define ATA_AHCI_P_CMD_SLUMPER 0x60000000
+
+#define ATA_AHCI_P_TFD 0x120
+#define ATA_AHCI_P_SIG 0x124
+#define ATA_AHCI_P_SSTS 0x128
+#define ATA_AHCI_P_SCTL 0x12c
+#define ATA_AHCI_P_SERR 0x130
+#define ATA_AHCI_P_SACT 0x134
+#define ATA_AHCI_P_CI 0x138
+
+#define ATA_AHCI_CL_SIZE 32
+#define ATA_AHCI_CL_OFFSET 0
+#define ATA_AHCI_FB_OFFSET 1024
+#define ATA_AHCI_CT_OFFSET 1024+256
+#define ATA_AHCI_CT_SG_OFFSET 128
+#define ATA_AHCI_CT_SIZE 256
/* DMA register defines */
#define ATA_DMA_ENTRIES 256
@@ -521,7 +521,7 @@ struct ata_channel {
#define ATA_LED_MASK 0x03
/* externs */
-extern int (*ata_ioctl_func)(struct ata_cmd *iocmd);
+extern int (*ata_raid_ioctl_func)(u_long cmd, caddr_t data);
extern devclass_t ata_devclass;
extern int ata_wc;
@@ -533,6 +533,7 @@ int ata_detach(device_t dev);
int ata_reinit(device_t dev);
int ata_suspend(device_t dev);
int ata_resume(device_t dev);
+int ata_device_ioctl(device_t dev, u_long cmd, caddr_t data);
int ata_identify(device_t dev);
void ata_default_registers(device_t dev);
u_int8_t ata_modify_if_48bit(struct ata_request *request);
diff --git a/sys/dev/ata/ata-chipset.c b/sys/dev/ata/ata-chipset.c
index 03162fe..1c0541c 100644
--- a/sys/dev/ata/ata-chipset.c
+++ b/sys/dev/ata/ata-chipset.c
@@ -250,15 +250,15 @@ ata_sata_connect(struct ata_channel *ch)
if (bootverbose)
device_printf(ch->dev, "SATA connect ready time=%dms\n", timeout * 10);
if (timeout < 1000) {
- if ((ATA_IDX_INB(ch, ATA_CYL_LSB) == ATAPI_MAGIC_LSB) &&
+ if ((ATA_IDX_INB(ch, ATA_CYL_LSB) == ATAPI_MAGIC_LSB) &&
(ATA_IDX_INB(ch, ATA_CYL_MSB) == ATAPI_MAGIC_MSB))
ch->devices = ATA_ATAPI_MASTER;
- else
+ else
ch->devices = ATA_ATA_MASTER;
}
if (bootverbose)
- device_printf(ch->dev, "sata_connect devices=0x%b\n",
- ch->devices, "\20\3ATAPI_MASTER\1ATA_MASTER");
+ device_printf(ch->dev, "sata_connect devices=0x%b\n",
+ ch->devices, "\20\3ATAPI_MASTER\1ATA_MASTER");
return 1;
}
@@ -325,25 +325,25 @@ ata_sata_phy_event(void *context, int dummy)
* AHCI v1.0 compliant SATA chipset support functions
*/
struct ata_ahci_dma_prd {
- u_int64_t dba;
- u_int32_t reserved;
- u_int32_t dbc; /* 0 based */
-#define ATA_AHCI_PRD_MASK 0x003fffff /* max 4MB */
-#define ATA_AHCI_PRD_IPC (1<<31)
+ u_int64_t dba;
+ u_int32_t reserved;
+ u_int32_t dbc; /* 0 based */
+#define ATA_AHCI_PRD_MASK 0x003fffff /* max 4MB */
+#define ATA_AHCI_PRD_IPC (1<<31)
} __packed;
struct ata_ahci_cmd_tab {
- u_int8_t cfis[64];
- u_int8_t acmd[32];
- u_int8_t reserved[32];
- struct ata_ahci_dma_prd prd_tab[16];
+ u_int8_t cfis[64];
+ u_int8_t acmd[32];
+ u_int8_t reserved[32];
+ struct ata_ahci_dma_prd prd_tab[16];
} __packed;
struct ata_ahci_cmd_list {
- u_int16_t cmd_flags;
- u_int16_t prd_length; /* PRD entries */
- u_int32_t bytecount;
- u_int64_t cmd_table_phys; /* 128byte aligned */
+ u_int16_t cmd_flags;
+ u_int16_t prd_length; /* PRD entries */
+ u_int32_t bytecount;
+ u_int64_t cmd_table_phys; /* 128byte aligned */
} __packed;
@@ -376,7 +376,7 @@ ata_ahci_allocate(device_t dev)
ch->hw.begin_transaction = ata_ahci_begin_transaction;
ch->hw.end_transaction = ata_ahci_end_transaction;
- ch->hw.command = NULL; /* not used here */
+ ch->hw.command = NULL; /* not used here */
/* setup the work areas */
ATA_OUTL(ctlr->r_res2, ATA_AHCI_P_CLB + offset,
@@ -409,8 +409,8 @@ ata_ahci_setup_fis(u_int8_t *fis, struct ata_request *request)
int idx = 0;
/* XXX SOS add ATAPI commands support later */
- fis[idx++] = 0x27; /* host to device */
- fis[idx++] = 0x80; /* command FIS (note PM goes here) */
+ fis[idx++] = 0x27; /* host to device */
+ fis[idx++] = 0x80; /* command FIS (note PM goes here) */
fis[idx++] = ata_modify_if_48bit(request);
fis[idx++] = request->u.ata.feature;
@@ -460,13 +460,13 @@ ata_ahci_begin_transaction(struct ata_request *request)
/* if request moves data setup and load SG list */
if (request->flags & (ATA_R_READ | ATA_R_WRITE)) {
- if (ch->dma->load(ch->dev, request->data, request->bytecount,
- request->flags & ATA_R_READ,
+ if (ch->dma->load(ch->dev, request->data, request->bytecount,
+ request->flags & ATA_R_READ,
ctp->prd_tab, &entries)) {
device_printf(request->dev, "setting up DMA failed\n");
request->result = EIO;
return ATA_OP_FINISHED;
- }
+ }
}
/* setup the command list entry */
@@ -475,11 +475,11 @@ ata_ahci_begin_transaction(struct ata_request *request)
clp->prd_length = entries;
clp->cmd_flags = (request->flags & ATA_R_WRITE ? (1<<6) : 0) |
- (request->flags & ATA_R_ATAPI ? (1<<5) : 0) |
- (fis_size / sizeof(u_int32_t));
+ (request->flags & ATA_R_ATAPI ? (1<<5) : 0) |
+ (fis_size / sizeof(u_int32_t));
clp->bytecount = 0;
clp->cmd_table_phys = htole64(ch->dma->work_bus + ATA_AHCI_CT_OFFSET +
- (ATA_AHCI_CT_SIZE * tag));
+ (ATA_AHCI_CT_SIZE * tag));
/* clear eventual ACTIVE bit */
ATA_IDX_OUTL(ch, ATA_SACTIVE, ATA_IDX_INL(ch, ATA_SACTIVE) & (1 << tag));
@@ -516,7 +516,7 @@ ata_ahci_end_transaction(struct ata_request *request)
/* record how much data we actually moved */
clp = (struct ata_ahci_cmd_list *)
- (ch->dma->work + ATA_AHCI_CL_OFFSET + (ATA_AHCI_CL_SIZE * tag));
+ (ch->dma->work + ATA_AHCI_CL_OFFSET + (ATA_AHCI_CL_SIZE * tag));
request->donecount = clp->bytecount;
/* release SG list etc */
@@ -542,11 +542,11 @@ ata_ahci_intr(void *data)
struct ata_connect_task *tp;
int offset = (ch->unit << 7);
- error = ATA_INL(ctlr->r_res2, ATA_AHCI_P_SERR + offset);
- ATA_OUTL(ctlr->r_res2, ATA_AHCI_P_SERR + offset, error);
- status = ATA_INL(ctlr->r_res2, ATA_AHCI_P_IS + offset);
- ATA_OUTL(ctlr->r_res2, ATA_AHCI_P_IS + offset, status);
- issued = ATA_INL(ctlr->r_res2, ATA_AHCI_P_CI + offset);
+ error = ATA_INL(ctlr->r_res2, ATA_AHCI_P_SERR + offset);
+ ATA_OUTL(ctlr->r_res2, ATA_AHCI_P_SERR + offset, error);
+ status = ATA_INL(ctlr->r_res2, ATA_AHCI_P_IS + offset);
+ ATA_OUTL(ctlr->r_res2, ATA_AHCI_P_IS + offset, status);
+ issued = ATA_INL(ctlr->r_res2, ATA_AHCI_P_CI + offset);
/* do we have cold connect surprise */
if (status & ATA_AHCI_P_IX_CPD) {
@@ -554,24 +554,24 @@ ata_ahci_intr(void *data)
status, error, issued);
}
- /* check for and handle connect events */
- if ((status & ATA_AHCI_P_IX_PC) &&
+ /* check for and handle connect events */
+ if ((status & ATA_AHCI_P_IX_PC) &&
(tp = (struct ata_connect_task *)
- malloc(sizeof(struct ata_connect_task),
- M_ATA, M_NOWAIT | M_ZERO))) {
+ malloc(sizeof(struct ata_connect_task),
+ M_ATA, M_NOWAIT | M_ZERO))) {
device_printf(ch->dev, "CONNECT requested\n");
tp->action = ATA_C_ATTACH;
tp->dev = ch->dev;
TASK_INIT(&tp->task, 0, ata_sata_phy_event, tp);
taskqueue_enqueue(taskqueue_thread, &tp->task);
- }
+ }
- /* check for and handle disconnect events */
- if (((status & (ATA_AHCI_P_IX_PRC | ATA_AHCI_P_IX_PC)) ==
+ /* check for and handle disconnect events */
+ if (((status & (ATA_AHCI_P_IX_PRC | ATA_AHCI_P_IX_PC)) ==
ATA_AHCI_P_IX_PRC) &&
(tp = (struct ata_connect_task *)
- malloc(sizeof(struct ata_connect_task),
+ malloc(sizeof(struct ata_connect_task),
M_ATA, M_NOWAIT | M_ZERO))) {
device_printf(ch->dev, "DISCONNECT requested\n");
@@ -579,11 +579,11 @@ ata_ahci_intr(void *data)
tp->dev = ch->dev;
TASK_INIT(&tp->task, 0, ata_sata_phy_event, tp);
taskqueue_enqueue(taskqueue_thread, &tp->task);
- }
+ }
- /* any drive action to take care of ? */
- if (!(issued & (1<<tag)))
- ctlr->interrupt[unit].function(ch);
+ /* any drive action to take care of ? */
+ if (!(issued & (1<<tag)))
+ ctlr->interrupt[unit].function(ch);
}
}
}
@@ -604,7 +604,7 @@ ata_ahci_reset(device_t dev)
cmd & ~(ATA_AHCI_P_CMD_CR | ATA_AHCI_P_CMD_FR |
ATA_AHCI_P_CMD_FRE | ATA_AHCI_P_CMD_ST));
- DELAY(500000); /* XXX SOS this is not entirely wrong */
+ DELAY(500000); /* XXX SOS this is not entirely wrong */
/* spin up device */
ATA_OUTL(ctlr->r_res2, ATA_AHCI_P_CMD + offset, ATA_AHCI_P_CMD_SUD);
@@ -1426,10 +1426,10 @@ ata_intel_chipinit(device_t dev)
&ctlr->r_rid2, RF_ACTIVE))) {
if (bus_teardown_intr(dev, ctlr->r_irq, ctlr->handle) ||
bus_setup_intr(dev, ctlr->r_irq, ATA_INTR_FLAGS,
- ata_ahci_intr, ctlr, &ctlr->handle)) {
- device_printf(dev, "unable to setup interrupt\n");
- return ENXIO;
- }
+ ata_ahci_intr, ctlr, &ctlr->handle)) {
+ device_printf(dev, "unable to setup interrupt\n");
+ return ENXIO;
+ }
/* force all ports active "the legacy way" */
pci_write_config(dev, 0x92, pci_read_config(dev, 0x92, 2) | 0x0f,2);
diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c
index 64ba579..64a4172 100644
--- a/sys/dev/ata/ata-disk.c
+++ b/sys/dev/ata/ata-disk.c
@@ -61,6 +61,7 @@ static void ad_done(struct ata_request *);
static void ad_describe(device_t dev);
static int ad_version(u_int16_t);
static disk_strategy_t ad_strategy;
+static disk_ioctl_t ad_ioctl;
static dumper_t ad_dump;
/* local vars */
@@ -137,6 +138,7 @@ ad_attach(device_t dev)
/* create the disk device */
adp->disk = disk_alloc();
adp->disk->d_strategy = ad_strategy;
+ adp->disk->d_ioctl = ad_ioctl;
adp->disk->d_dump = ad_dump;
adp->disk->d_name = "ad";
adp->disk->d_drv1 = dev;
@@ -283,6 +285,12 @@ ad_done(struct ata_request *request)
}
static int
+ad_ioctl(struct disk *disk, u_long cmd, void *data, int flag, struct thread *td)
+{
+ return ata_device_ioctl(disk->d_drv1, cmd, data);
+}
+
+static int
ad_dump(void *arg, void *virtual, vm_offset_t physical,
off_t offset, size_t length)
{
diff --git a/sys/dev/ata/ata-lowlevel.c b/sys/dev/ata/ata-lowlevel.c
index 0f74bc3..2a40e00 100644
--- a/sys/dev/ata/ata-lowlevel.c
+++ b/sys/dev/ata/ata-lowlevel.c
@@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <machine/bus.h>
#include <sys/rman.h>
#include <dev/ata/ata-all.h>
-#include <dev/ata/ata-commands.h>
#include <dev/ata/ata-pci.h>
#include <ata_if.h>
@@ -667,9 +666,9 @@ ata_generic_command(struct ata_request *request)
ATA_IDX_OUTB(ch, ATA_CONTROL, ATA_A_4BIT);
if (request->flags & ATA_R_ATAPI) {
- int timeout = 5000;
+ int timeout = 5000;
- /* issue packet command to controller */
+ /* issue packet command to controller */
if (request->flags & ATA_R_DMA) {
ATA_IDX_OUTB(ch, ATA_FEATURE, ATA_F_DMA);
ATA_IDX_OUTB(ch, ATA_CYL_LSB, 0);
@@ -683,32 +682,32 @@ ata_generic_command(struct ata_request *request)
ATA_IDX_OUTB(ch, ATA_COMMAND, ATA_PACKET_CMD);
/* command interrupt device ? just return and wait for interrupt */
- if ((atadev->param.config & ATA_DRQ_MASK) == ATA_DRQ_INTR)
+ if ((atadev->param.config & ATA_DRQ_MASK) == ATA_DRQ_INTR)
return 0;
/* wait for ready to write ATAPI command block */
- while (timeout--) {
- int reason = ATA_IDX_INB(ch, ATA_IREASON);
- int status = ATA_IDX_INB(ch, ATA_STATUS);
-
- if (((reason & (ATA_I_CMD | ATA_I_IN)) |
- (status & (ATA_S_DRQ | ATA_S_BUSY))) == ATAPI_P_CMDOUT)
- break;
- DELAY(20);
- }
- if (timeout <= 0) {
- device_printf(request->dev,"timeout waiting for ATAPI ready\n");
- request->result = EIO;
- return -1;
- }
-
- /* this seems to be needed for some (slow) devices */
- DELAY(10);
-
- /* output command block */
- ATA_IDX_OUTSW_STRM(ch, ATA_DATA, (int16_t *)request->u.atapi.ccb,
- (atadev->param.config & ATA_PROTO_MASK) ==
- ATA_PROTO_ATAPI_12 ? 6 : 8);
+ while (timeout--) {
+ int reason = ATA_IDX_INB(ch, ATA_IREASON);
+ int status = ATA_IDX_INB(ch, ATA_STATUS);
+
+ if (((reason & (ATA_I_CMD | ATA_I_IN)) |
+ (status & (ATA_S_DRQ | ATA_S_BUSY))) == ATAPI_P_CMDOUT)
+ break;
+ DELAY(20);
+ }
+ if (timeout <= 0) {
+ device_printf(request->dev,"timeout waiting for ATAPI ready\n");
+ request->result = EIO;
+ return -1;
+ }
+
+ /* this seems to be needed for some (slow) devices */
+ DELAY(10);
+
+ /* output command block */
+ ATA_IDX_OUTSW_STRM(ch, ATA_DATA, (int16_t *)request->u.atapi.ccb,
+ (atadev->param.config & ATA_PROTO_MASK) ==
+ ATA_PROTO_ATAPI_12 ? 6 : 8);
}
else {
u_int8_t command = ata_modify_if_48bit(request);
@@ -726,42 +725,42 @@ ata_generic_command(struct ata_request *request)
ATA_IDX_OUTB(ch, ATA_CYL_MSB, request->u.ata.lba >> 16);
ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_LBA | atadev->unit);
}
- else {
+ else {
command = request->u.ata.command;
ATA_IDX_OUTB(ch, ATA_FEATURE, request->u.ata.feature);
ATA_IDX_OUTB(ch, ATA_COUNT, request->u.ata.count);
if (atadev->flags & ATA_D_USE_CHS) {
- int heads, sectors;
+ int heads, sectors;
- if (atadev->param.atavalid & ATA_FLAG_54_58) {
+ if (atadev->param.atavalid & ATA_FLAG_54_58) {
heads = atadev->param.current_heads;
sectors = atadev->param.current_sectors;
- }
- else {
+ }
+ else {
heads = atadev->param.heads;
sectors = atadev->param.sectors;
- }
- ATA_IDX_OUTB(ch, ATA_SECTOR, (request->u.ata.lba % sectors)+1);
- ATA_IDX_OUTB(ch, ATA_CYL_LSB,
+ }
+ ATA_IDX_OUTB(ch, ATA_SECTOR, (request->u.ata.lba % sectors)+1);
+ ATA_IDX_OUTB(ch, ATA_CYL_LSB,
(request->u.ata.lba / (sectors * heads)));
- ATA_IDX_OUTB(ch, ATA_CYL_MSB,
+ ATA_IDX_OUTB(ch, ATA_CYL_MSB,
(request->u.ata.lba / (sectors * heads)) >> 8);
- ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | atadev->unit |
+ ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | atadev->unit |
(((request->u.ata.lba% (sectors * heads)) /
sectors) & 0xf));
}
else {
- ATA_IDX_OUTB(ch, ATA_SECTOR, request->u.ata.lba);
- ATA_IDX_OUTB(ch, ATA_CYL_LSB, request->u.ata.lba >> 8);
- ATA_IDX_OUTB(ch, ATA_CYL_MSB, request->u.ata.lba >> 16);
- ATA_IDX_OUTB(ch, ATA_DRIVE,
+ ATA_IDX_OUTB(ch, ATA_SECTOR, request->u.ata.lba);
+ ATA_IDX_OUTB(ch, ATA_CYL_LSB, request->u.ata.lba >> 8);
+ ATA_IDX_OUTB(ch, ATA_CYL_MSB, request->u.ata.lba >> 16);
+ ATA_IDX_OUTB(ch, ATA_DRIVE,
ATA_D_IBM | ATA_D_LBA | atadev->unit |
((request->u.ata.lba >> 24) & 0x0f));
}
}
- /* issue command to controller */
- ATA_IDX_OUTB(ch, ATA_COMMAND, command);
+ /* issue command to controller */
+ ATA_IDX_OUTB(ch, ATA_COMMAND, command);
}
return 0;
diff --git a/sys/dev/ata/ata-pci.h b/sys/dev/ata/ata-pci.h
index 5cadc29..f31a449 100644
--- a/sys/dev/ata/ata-pci.h
+++ b/sys/dev/ata/ata-pci.h
@@ -141,11 +141,11 @@ struct ata_connect_task {
#define ATA_I82801FB_S1 0x26518086
#define ATA_I82801FB_R1 0x26528086
#define ATA_I82801FB_M 0x26538086
-#define ATA_I82801GB 0x27df8086
-#define ATA_I82801GB_S1 0x27c08086
-#define ATA_I82801GB_R1 0x27c38086
-#define ATA_I82801GB_AH 0x27c18086
-#define ATA_I82801GB_M 0x27c58086
+#define ATA_I82801GB 0x27df8086
+#define ATA_I82801GB_S1 0x27c08086
+#define ATA_I82801GB_R1 0x27c38086
+#define ATA_I82801GB_AH 0x27c18086
+#define ATA_I82801GB_M 0x27c58086
#define ATA_ITE_ID 0x1283
#define ATA_IT8212F 0x82121283
diff --git a/sys/dev/ata/ata-raid.c b/sys/dev/ata/ata-raid.c
index e2bbf3d..4b2824f 100644
--- a/sys/dev/ata/ata-raid.c
+++ b/sys/dev/ata/ata-raid.c
@@ -58,10 +58,10 @@ __FBSDID("$FreeBSD$");
/* prototypes */
static void ata_raid_done(struct ata_request *request);
static void ata_raid_config_changed(struct ar_softc *rdp, int writeback);
-static int ata_raid_status(int array, struct raid_status *status);
-static int ata_raid_create(struct raid_setup *setup);
+static int ata_raid_status(struct ata_ioc_raid_config *config);
+static int ata_raid_create(struct ata_ioc_raid_config *config);
static int ata_raid_delete(int array);
-static int ata_raid_addspare(int array, int spare);
+static int ata_raid_addspare(struct ata_ioc_raid_config *config);
static int ata_raid_rebuild(int array);
static int ata_raid_read_metadata(device_t subdisk);
static int ata_raid_write_metadata(struct ar_softc *rdp);
@@ -184,29 +184,31 @@ ata_raid_attach(struct ar_softc *rdp, int writeback)
}
static int
-ata_raid_ioctl(struct ata_cmd *iocmd)
+ata_raid_ioctl(u_long cmd, caddr_t data)
{
+ struct ata_ioc_raid_config *config = (struct ata_ioc_raid_config *)data;
+ int *lun = (int *)data;
int error = EOPNOTSUPP;
- switch (iocmd->cmd) {
- case ATARAIDSTATUS:
- error = ata_raid_status(iocmd->channel, &iocmd->u.raid_status);
+ switch (cmd) {
+ case IOCATARAIDSTATUS:
+ error = ata_raid_status(config);
break;
- case ATARAIDCREATE:
- error = ata_raid_create(&iocmd->u.raid_setup);
+ case IOCATARAIDCREATE:
+ error = ata_raid_create(config);
break;
- case ATARAIDDELETE:
- error = ata_raid_delete(iocmd->channel);
+ case IOCATARAIDDELETE:
+ error = ata_raid_delete(*lun);
break;
- case ATARAIDADDSPARE:
- error = ata_raid_addspare(iocmd->channel, iocmd->u.raid_spare.disk);
+ case IOCATARAIDADDSPARE:
+ error = ata_raid_addspare(config);
break;
- case ATARAIDREBUILD:
- error = ata_raid_rebuild(iocmd->channel);
+ case IOCATARAIDREBUILD:
+ error = ata_raid_rebuild(*lun);
break;
}
return error;
@@ -806,30 +808,30 @@ ata_raid_config_changed(struct ar_softc *rdp, int writeback)
}
static int
-ata_raid_status(int array, struct raid_status *status)
+ata_raid_status(struct ata_ioc_raid_config *config)
{
struct ar_softc *rdp;
int i;
- if (!(rdp = ata_raid_arrays[array]))
+ if (!(rdp = ata_raid_arrays[config->lun]))
return ENXIO;
- status->type = rdp->type;
- status->total_disks = rdp->total_disks;
+ config->type = rdp->type;
+ config->total_disks = rdp->total_disks;
for (i = 0; i < rdp->total_disks; i++ ) {
if ((rdp->disks[i].flags & AR_DF_PRESENT) && rdp->disks[i].dev)
- status->disks[i] = device_get_unit(rdp->disks[i].dev);
+ config->disks[i] = device_get_unit(rdp->disks[i].dev);
else
- status->disks[i] = -1;
+ config->disks[i] = -1;
}
- status->interleave = rdp->interleave;
- status->status = rdp->status;
- status->progress = 100 * rdp->rebuild_lba / rdp->total_sectors;
+ config->interleave = rdp->interleave;
+ config->status = rdp->status;
+ config->progress = 100 * rdp->rebuild_lba / rdp->total_sectors;
return 0;
}
static int
-ata_raid_create(struct raid_setup *setup)
+ata_raid_create(struct ata_ioc_raid_config *config)
{
struct ar_softc *rdp;
device_t subdisk;
@@ -849,14 +851,14 @@ ata_raid_create(struct raid_setup *setup)
return ENOMEM;
}
- for (disk = 0; disk < setup->total_disks; disk++) {
+ for (disk = 0; disk < config->total_disks; disk++) {
if ((subdisk = devclass_get_device(ata_raid_sub_devclass,
- setup->disks[disk]))) {
+ config->disks[disk]))) {
struct ata_raid_subdisk *ars = device_get_softc(subdisk);
/* is device already assigned to another array ? */
if (ars->raid) {
- setup->disks[disk] = -1;
+ config->disks[disk] = -1;
free(rdp, M_AR);
return EBUSY;
}
@@ -930,18 +932,18 @@ ata_raid_create(struct raid_setup *setup)
total_disks++;
}
else {
- setup->disks[disk] = -1;
+ config->disks[disk] = -1;
free(rdp, M_AR);
return ENXIO;
}
}
- if (total_disks != setup->total_disks) {
+ if (total_disks != config->total_disks) {
free(rdp, M_AR);
return ENODEV;
}
- switch (setup->type) {
+ switch (config->type) {
case AR_T_JBOD:
case AR_T_SPAN:
case AR_T_RAID0:
@@ -972,13 +974,13 @@ ata_raid_create(struct raid_setup *setup)
free(rdp, M_AR);
return EOPNOTSUPP;
}
- rdp->type = setup->type;
+ rdp->type = config->type;
rdp->lun = array;
if (rdp->type == AR_T_RAID0 || rdp->type == AR_T_RAID01 ||
rdp->type == AR_T_RAID5) {
int bit = 0;
- while (setup->interleave >>= 1)
+ while (config->interleave >>= 1)
bit++;
rdp->interleave = 1 << bit;
}
@@ -1038,9 +1040,9 @@ ata_raid_create(struct raid_setup *setup)
rdp->status |= AR_S_READY;
/* we are committed to this array, grap the subdisks */
- for (disk = 0; disk < setup->total_disks; disk++) {
+ for (disk = 0; disk < config->total_disks; disk++) {
if ((subdisk = devclass_get_device(ata_raid_sub_devclass,
- setup->disks[disk]))) {
+ config->disks[disk]))) {
struct ata_raid_subdisk *ars = device_get_softc(subdisk);
ars->raid = rdp;
@@ -1049,7 +1051,7 @@ ata_raid_create(struct raid_setup *setup)
}
ata_raid_attach(rdp, 1);
ata_raid_arrays[array] = rdp;
- setup->unit = array;
+ config->lun = array;
return 0;
}
@@ -1089,13 +1091,13 @@ ata_raid_delete(int array)
}
static int
-ata_raid_addspare(int array, int spare)
+ata_raid_addspare(struct ata_ioc_raid_config *config)
{
struct ar_softc *rdp;
device_t subdisk;
int disk;
- if (!(rdp = ata_raid_arrays[array]))
+ if (!(rdp = ata_raid_arrays[config->lun]))
return ENXIO;
if (!(rdp->status & AR_S_DEGRADED) || !(rdp->status & AR_S_READY))
return ENXIO;
@@ -1111,7 +1113,8 @@ ata_raid_addspare(int array, int spare)
(AR_DF_PRESENT | AR_DF_ONLINE)) && rdp->disks[disk].dev)
continue;
- if ((subdisk = devclass_get_device(ata_raid_sub_devclass, spare ))){
+ if ((subdisk = devclass_get_device(ata_raid_sub_devclass,
+ config->disks[0] ))) {
struct ata_raid_subdisk *ars = device_get_softc(subdisk);
if (ars->raid)
@@ -3136,7 +3139,7 @@ ata_raid_module_event_handler(module_t mod, int what, void *arg)
ata_raid_print_meta(rdp);
ata_raid_attach(rdp, 0);
}
- ata_ioctl_func = ata_raid_ioctl;
+ ata_raid_ioctl_func = ata_raid_ioctl;
return 0;
case MOD_UNLOAD:
@@ -3152,7 +3155,7 @@ ata_raid_module_event_handler(module_t mod, int what, void *arg)
#if 0
free(ata_raid_arrays, M_AR);
#endif
- ata_ioctl_func = NULL;
+ ata_raid_ioctl_func = NULL;
return 0;
default:
diff --git a/sys/dev/ata/atapi-cam.c b/sys/dev/ata/atapi-cam.c
index c6e2309..3493837 100644
--- a/sys/dev/ata/atapi-cam.c
+++ b/sys/dev/ata/atapi-cam.c
@@ -413,7 +413,7 @@ atapi_action(struct cam_sim *sim, union ccb *ccb)
int tid = ccb_h->target_id;
CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_SUBTRACE, ("dev reset\n"));
- ata_controlcmd(softc->atadev[tid]->dev, ATA_ATAPI_RESET, 0, 0, 0);
+ ata_controlcmd(softc->atadev[tid]->dev, ATA_DEVICE_RESET, 0, 0, 0);
ccb->ccb_h.status = CAM_REQ_CMP;
xpt_done(ccb);
return;
diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c
index 48df3bf..61c0517 100644
--- a/sys/dev/ata/atapi-cd.c
+++ b/sys/dev/ata/atapi-cd.c
@@ -53,7 +53,6 @@ __FBSDID("$FreeBSD$");
#include <geom/geom.h>
#include <dev/ata/ata-all.h>
#include <dev/ata/atapi-cd.h>
-#include <dev/ata/ata-commands.h>
#include <ata_if.h>
/* prototypes */
@@ -676,7 +675,7 @@ acd_geom_ioctl(struct g_provider *pp, u_long cmd, void *addr, int fflag, struct
break;
default:
- error = ENOTTY;
+ error = ata_device_ioctl(dev, cmd, addr);
}
return error;
}
diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c
index 98d4072..00c53ac 100644
--- a/sys/dev/ata/atapi-fd.c
+++ b/sys/dev/ata/atapi-fd.c
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
static disk_open_t afd_open;
static disk_close_t afd_close;
static disk_strategy_t afd_strategy;
+static disk_ioctl_t afd_ioctl;
static int afd_sense(device_t);
static void afd_describe(device_t);
static void afd_done(struct ata_request *);
@@ -103,6 +104,7 @@ afd_attach(device_t dev)
fdp->disk->d_open = afd_open;
fdp->disk->d_close = afd_close;
fdp->disk->d_strategy = afd_strategy;
+ fdp->disk->d_ioctl = afd_ioctl;
fdp->disk->d_name = "afd";
fdp->disk->d_drv1 = dev;
if (ch->dma)
@@ -281,6 +283,12 @@ afd_done(struct ata_request *request)
ata_free_request(request);
}
+static int
+afd_ioctl(struct disk *disk, u_long cmd, void *data, int flag,struct thread *td)
+{
+ return ata_device_ioctl(disk->d_drv1, cmd, data);
+}
+
static int
afd_sense(device_t dev)
{
diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c
index 8ba9e55..b06ce47 100644
--- a/sys/dev/ata/atapi-tape.c
+++ b/sys/dev/ata/atapi-tape.c
@@ -263,7 +263,7 @@ ast_close(struct cdev *cdev, int flags, int fmt, struct thread *td)
}
static int
-ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t addr, int flag, struct thread *td)
+ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t data, int flag, struct thread *td)
{
device_t dev = cdev->si_drv1;
struct ast_softc *stp = device_get_ivars(dev);
@@ -272,7 +272,7 @@ ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t addr, int flag, struct thread *
switch (cmd) {
case MTIOCGET:
{
- struct mtget *g = (struct mtget *) addr;
+ struct mtget *g = (struct mtget *) data;
bzero(g, sizeof(struct mtget));
g->mt_type = 7;
@@ -291,7 +291,7 @@ ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t addr, int flag, struct thread *
case MTIOCTOP:
{
int i;
- struct mtop *mt = (struct mtop *)addr;
+ struct mtop *mt = (struct mtop *)data;
switch ((int16_t) (mt->mt_op)) {
@@ -353,7 +353,7 @@ ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t addr, int flag, struct thread *
if ((error = ast_read_position(dev, 0, &position)))
break;
- *(u_int32_t *)addr = position.tape;
+ *(u_int32_t *)data = position.tape;
}
break;
@@ -363,20 +363,20 @@ ast_ioctl(struct cdev *cdev, u_long cmd, caddr_t addr, int flag, struct thread *
if ((error = ast_read_position(dev, 1, &position)))
break;
- *(u_int32_t *)addr = position.tape;
+ *(u_int32_t *)data = position.tape;
}
break;
case MTIOCSLOCATE:
- error = ast_locate(dev, 0, *(u_int32_t *)addr);
+ error = ast_locate(dev, 0, *(u_int32_t *)data);
break;
case MTIOCHLOCATE:
- error = ast_locate(dev, 1, *(u_int32_t *)addr);
+ error = ast_locate(dev, 1, *(u_int32_t *)data);
break;
default:
- error = ENOTTY;
+ error = ata_device_ioctl(dev, cmd, data);
}
return error;
}
OpenPOWER on IntegriCloud