diff options
| author | Søren Schmidt <sos@FreeBSD.org> | 2005-04-30 16:22:07 +0000 |
|---|---|---|
| committer | Søren Schmidt <sos@FreeBSD.org> | 2005-04-30 16:22:07 +0000 |
| commit | 0068f98f8841a3a9041998073ea5241904a84658 (patch) | |
| tree | e259973366cf692372899b33dcf524ca0258ebb1 /sys | |
| parent | a4f4bae7f574421dcc5481792e059f4aec3adc01 (diff) | |
Notes
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/dev/ata/ata-all.c | 28 | ||||
| -rw-r--r-- | sys/dev/ata/ata-all.h | 130 | ||||
| -rw-r--r-- | sys/dev/ata/ata-card.c | 4 | ||||
| -rw-r--r-- | sys/dev/ata/ata-cbus.c | 4 | ||||
| -rw-r--r-- | sys/dev/ata/ata-chipset.c | 569 | ||||
| -rw-r--r-- | sys/dev/ata/ata-disk.c | 13 | ||||
| -rw-r--r-- | sys/dev/ata/ata-dma.c | 46 | ||||
| -rw-r--r-- | sys/dev/ata/ata-isa.c | 4 | ||||
| -rw-r--r-- | sys/dev/ata/ata-lowlevel.c | 56 | ||||
| -rw-r--r-- | sys/dev/ata/ata-pci.c | 43 | ||||
| -rw-r--r-- | sys/dev/ata/ata-pci.h | 16 | ||||
| -rw-r--r-- | sys/dev/ata/ata-queue.c | 17 | ||||
| -rw-r--r-- | sys/dev/ata/ata-raid.c | 2 | ||||
| -rw-r--r-- | sys/dev/ata/ata-raid.h | 48 | ||||
| -rw-r--r-- | sys/dev/ata/ata_if.m | 2 | ||||
| -rw-r--r-- | sys/dev/ata/atapi-cam.c | 56 | ||||
| -rw-r--r-- | sys/dev/ata/atapi-cd.c | 73 | ||||
| -rw-r--r-- | sys/dev/ata/atapi-fd.c | 12 | ||||
| -rw-r--r-- | sys/dev/ata/atapi-tape.c | 43 |
19 files changed, 592 insertions, 574 deletions
diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c index 2c7a895c4b1d..0f7ae4582066 100644 --- a/sys/dev/ata/ata-all.c +++ b/sys/dev/ata/ata-all.c @@ -231,7 +231,7 @@ ata_reinit(device_t dev) } /* catch request in ch->running if we havn't already */ - ata_catch_inflight(ch); + ata_catch_inflight(dev); /* we're done release the channel for new work */ mtx_lock(&ch->state_mtx); @@ -659,7 +659,7 @@ ata_getparam(device_t parent, struct ata_device *atadev) ata_umode(&atadev->param) >= ATA_UDMA2) atadev->mode = ATA_DMA_MAX; } - else { + else { if (ata_dma && ch->dma) atadev->mode = ATA_DMA_MAX; } @@ -680,21 +680,21 @@ ata_identify(device_t dev) int master_unit = -1, slave_unit = -1; if (ch->devices & (ATA_ATA_MASTER | ATA_ATAPI_MASTER)) { - if (!(master = malloc(sizeof(struct ata_device), + if (!(master = malloc(sizeof(struct ata_device), M_ATA, M_NOWAIT | M_ZERO))) { device_printf(dev, "out of memory\n"); return ENOMEM; - } - master->unit = ATA_MASTER; + } + master->unit = ATA_MASTER; } if (ch->devices & (ATA_ATA_SLAVE | ATA_ATAPI_SLAVE)) { - if (!(slave = malloc(sizeof(struct ata_device), + if (!(slave = malloc(sizeof(struct ata_device), M_ATA, M_NOWAIT | M_ZERO))) { free(master, M_ATA); device_printf(dev, "out of memory\n"); return ENOMEM; - } - slave->unit = ATA_SLAVE; + } + slave->unit = ATA_SLAVE; } #ifdef ATA_STATIC_ID @@ -729,8 +729,10 @@ ata_identify(device_t dev) } void -ata_default_registers(struct ata_channel *ch) +ata_default_registers(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + /* fill in the defaults from whats setup already */ ch->r_io[ATA_ERROR].res = ch->r_io[ATA_FEATURE].res; ch->r_io[ATA_ERROR].offset = ch->r_io[ATA_FEATURE].offset; @@ -839,8 +841,10 @@ ata_umode(struct ata_params *ap) } int -ata_limit_mode(struct ata_device *atadev, int mode, int maxmode) +ata_limit_mode(device_t dev, int mode, int maxmode) { + struct ata_device *atadev = device_get_softc(dev); + if (maxmode && mode > maxmode) mode = maxmode; @@ -950,8 +954,8 @@ ata_init(void) ata_request_zone = uma_zcreate("ata_request", sizeof(struct ata_request), NULL, NULL, NULL, NULL, 0, 0); ata_composite_zone = uma_zcreate("ata_composite", - sizeof(struct ata_composite), - NULL, NULL, NULL, NULL, 0, 0); + sizeof(struct ata_composite), + NULL, NULL, NULL, NULL, 0, 0); } SYSINIT(ata_register, SI_SUB_DRIVERS, SI_ORDER_SECOND, ata_init, NULL); diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h index eabb23c8eda0..2249cbca8371 100644 --- a/sys/dev/ata/ata-all.h +++ b/sys/dev/ata/ata-all.h @@ -104,64 +104,64 @@ #define ATA_A_HOB 0x80 /* High Order Byte enable */ /* SATA register defines */ -#define ATA_SSTATUS 13 -#define ATA_SS_DET_MASK 0x0000000f -#define ATA_SS_DET_NO_DEVICE 0x00000000 -#define ATA_SS_DET_DEV_PRESENT 0x00000001 -#define ATA_SS_DET_PHY_ONLINE 0x00000003 -#define ATA_SS_DET_PHY_OFFLINE 0x00000004 +#define ATA_SSTATUS 13 +#define ATA_SS_DET_MASK 0x0000000f +#define ATA_SS_DET_NO_DEVICE 0x00000000 +#define ATA_SS_DET_DEV_PRESENT 0x00000001 +#define ATA_SS_DET_PHY_ONLINE 0x00000003 +#define ATA_SS_DET_PHY_OFFLINE 0x00000004 -#define ATA_SS_SPD_MASK 0x000000f0 -#define ATA_SS_SPD_NO_SPEED 0x00000000 -#define ATA_SS_SPD_GEN1 0x00000010 -#define ATA_SS_SPD_GEN2 0x00000020 +#define ATA_SS_SPD_MASK 0x000000f0 +#define ATA_SS_SPD_NO_SPEED 0x00000000 +#define ATA_SS_SPD_GEN1 0x00000010 +#define ATA_SS_SPD_GEN2 0x00000020 -#define ATA_SS_IPM_MASK 0x00000f00 -#define ATA_SS_IPM_NO_DEVICE 0x00000000 -#define ATA_SS_IPM_ACTIVE 0x00000100 -#define ATA_SS_IPM_PARTIAL 0x00000200 -#define ATA_SS_IPM_SLUMBER 0x00000600 +#define ATA_SS_IPM_MASK 0x00000f00 +#define ATA_SS_IPM_NO_DEVICE 0x00000000 +#define ATA_SS_IPM_ACTIVE 0x00000100 +#define ATA_SS_IPM_PARTIAL 0x00000200 +#define ATA_SS_IPM_SLUMBER 0x00000600 -#define ATA_SS_CONWELL_MASK \ +#define ATA_SS_CONWELL_MASK \ (ATA_SS_DET_MASK|ATA_SS_SPD_MASK|ATA_SS_IPM_MASK) -#define ATA_SS_CONWELL_GEN1 \ +#define ATA_SS_CONWELL_GEN1 \ (ATA_SS_DET_PHY_ONLINE|ATA_SS_SPD_GEN1|ATA_SS_IPM_ACTIVE) -#define ATA_SS_CONWELL_GEN2 \ +#define ATA_SS_CONWELL_GEN2 \ (ATA_SS_DET_PHY_ONLINE|ATA_SS_SPD_GEN2|ATA_SS_IPM_ACTIVE) -#define ATA_SERROR 14 -#define ATA_SE_DATA_CORRECTED 0x00000001 -#define ATA_SE_COMM_CORRECTED 0x00000002 -#define ATA_SE_DATA_ERR 0x00000100 -#define ATA_SE_COMM_ERR 0x00000200 -#define ATA_SE_PROT_ERR 0x00000400 -#define ATA_SE_HOST_ERR 0x00000800 -#define ATA_SE_PHY_CHANGED 0x00010000 -#define ATA_SE_PHY_IERROR 0x00020000 -#define ATA_SE_COMM_WAKE 0x00040000 -#define ATA_SE_DECODE_ERR 0x00080000 -#define ATA_SE_PARITY_ERR 0x00100000 -#define ATA_SE_CRC_ERR 0x00200000 -#define ATA_SE_HANDSHAKE_ERR 0x00400000 -#define ATA_SE_LINKSEQ_ERR 0x00800000 -#define ATA_SE_TRANSPORT_ERR 0x01000000 -#define ATA_SE_UNKNOWN_FIS 0x02000000 +#define ATA_SERROR 14 +#define ATA_SE_DATA_CORRECTED 0x00000001 +#define ATA_SE_COMM_CORRECTED 0x00000002 +#define ATA_SE_DATA_ERR 0x00000100 +#define ATA_SE_COMM_ERR 0x00000200 +#define ATA_SE_PROT_ERR 0x00000400 +#define ATA_SE_HOST_ERR 0x00000800 +#define ATA_SE_PHY_CHANGED 0x00010000 +#define ATA_SE_PHY_IERROR 0x00020000 +#define ATA_SE_COMM_WAKE 0x00040000 +#define ATA_SE_DECODE_ERR 0x00080000 +#define ATA_SE_PARITY_ERR 0x00100000 +#define ATA_SE_CRC_ERR 0x00200000 +#define ATA_SE_HANDSHAKE_ERR 0x00400000 +#define ATA_SE_LINKSEQ_ERR 0x00800000 +#define ATA_SE_TRANSPORT_ERR 0x01000000 +#define ATA_SE_UNKNOWN_FIS 0x02000000 -#define ATA_SCONTROL 15 -#define ATA_SC_DET_MASK 0x0000000f -#define ATA_SC_DET_IDLE 0x00000000 -#define ATA_SC_DET_RESET 0x00000001 -#define ATA_SC_DET_DISABLE 0x00000004 +#define ATA_SCONTROL 15 +#define ATA_SC_DET_MASK 0x0000000f +#define ATA_SC_DET_IDLE 0x00000000 +#define ATA_SC_DET_RESET 0x00000001 +#define ATA_SC_DET_DISABLE 0x00000004 -#define ATA_SC_SPD_MASK 0x000000f0 -#define ATA_SC_SPD_NO_SPEED 0x00000000 -#define ATA_SC_SPD_SPEED_GEN1 0x00000010 -#define ATA_SC_SPD_SPEED_GEN2 0x00000020 +#define ATA_SC_SPD_MASK 0x000000f0 +#define ATA_SC_SPD_NO_SPEED 0x00000000 +#define ATA_SC_SPD_SPEED_GEN1 0x00000010 +#define ATA_SC_SPD_SPEED_GEN2 0x00000020 -#define ATA_SC_IPM_MASK 0x00000f00 -#define ATA_SC_IPM_NONE 0x00000000 -#define ATA_SC_IPM_DIS_PARTIAL 0x00000100 -#define ATA_SC_IPM_DIS_SLUMBER 0x00000200 +#define ATA_SC_IPM_MASK 0x00000f00 +#define ATA_SC_IPM_NONE 0x00000000 +#define ATA_SC_IPM_DIS_PARTIAL 0x00000100 +#define ATA_SC_IPM_DIS_SLUMBER 0x00000200 /* DMA register defines */ #define ATA_DMA_ENTRIES 256 @@ -204,7 +204,7 @@ #define ATA_PC98_BANKADDR_RID 9 #define ATA_IRQ_RID 0 #define ATA_DEV(device) ((device == ATA_MASTER) ? 0 : 1) -#define ATA_CFA_MAGIC 0x848A +#define ATA_CFA_MAGIC 0x848A #define ATAPI_MAGIC_LSB 0x14 #define ATAPI_MAGIC_MSB 0xeb #define ATAPI_P_READ (ATA_S_DRQ | ATA_I_IN) @@ -374,20 +374,20 @@ struct ata_dma { #define ATA_DMA_LOADED 0x02 /* DMA tables etc loaded */ #define ATA_DMA_ACTIVE 0x04 /* DMA transfer in progress */ - void (*alloc)(struct ata_channel *ch); - void (*free)(struct ata_channel *ch); + void (*alloc)(device_t); + void (*free)(device_t); void (*setprd)(void *xsc, bus_dma_segment_t *segs, int nsegs, int error); - int (*load)(struct ata_device *atadev, caddr_t data, int32_t count,int dir); - int (*unload)(struct ata_channel *ch); - int (*start)(struct ata_channel *ch); - int (*stop)(struct ata_channel *ch); + int (*load)(device_t, caddr_t data, int32_t count,int dir); + int (*unload)(device_t); + int (*start)(device_t); + int (*stop)(device_t); }; /* structure holding lowlevel functions */ struct ata_lowlevel { int (*begin_transaction)(struct ata_request *request); int (*end_transaction)(struct ata_request *request); - int (*command)(struct ata_device *atadev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); + int (*command)(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); }; /* structure holding resources for an ATA channel */ @@ -451,29 +451,29 @@ int ata_reinit(device_t dev); int ata_suspend(device_t dev); int ata_resume(device_t dev); int ata_identify(device_t dev); -void ata_default_registers(struct ata_channel *ch); +void ata_default_registers(device_t dev); void ata_udelay(int interval); char *ata_mode2str(int mode); int ata_pmode(struct ata_params *ap); int ata_wmode(struct ata_params *ap); int ata_umode(struct ata_params *ap); -int ata_limit_mode(struct ata_device *atadev, int mode, int maxmode); +int ata_limit_mode(device_t dev, int mode, int maxmode); /* ata-queue.c: */ -int ata_controlcmd(struct ata_device *atadev, u_int8_t command, u_int16_t feature, u_int64_t lba, u_int16_t count); -int ata_atapicmd(struct ata_device *atadev, u_int8_t *ccb, caddr_t data, int count, int flags, int timeout); +int ata_controlcmd(device_t dev, u_int8_t command, u_int16_t feature, u_int64_t lba, u_int16_t count); +int ata_atapicmd(device_t dev, u_int8_t *ccb, caddr_t data, int count, int flags, int timeout); void ata_queue_request(struct ata_request *request); void ata_start(device_t dev); void ata_finish(struct ata_request *request); void ata_timeout(struct ata_request *); -void ata_catch_inflight(struct ata_channel *ch); -void ata_fail_requests(struct ata_channel *ch, device_t dev); +void ata_catch_inflight(device_t dev); +void ata_fail_requests(device_t dev); char *ata_cmd2str(struct ata_request *request); /* ata-lowlevel.c: */ -void ata_generic_hw(struct ata_channel *ch); -void ata_generic_reset(struct ata_channel *ch); -int ata_generic_command(struct ata_device *atadev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); +void ata_generic_hw(device_t dev); +void ata_generic_reset(device_t dev); +int ata_generic_command(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); /* macros for alloc/free of struct ata_request */ extern uma_zone_t ata_request_zone; diff --git a/sys/dev/ata/ata-card.c b/sys/dev/ata/ata-card.c index fad131fa6b62..d36014880537 100644 --- a/sys/dev/ata/ata-card.c +++ b/sys/dev/ata/ata-card.c @@ -126,12 +126,12 @@ ata_pccard_probe(device_t dev) ch->r_io[ATA_CONTROL].res = ctlio; ch->r_io[ATA_CONTROL].offset = 0; } - ata_default_registers(ch); + ata_default_registers(dev); /* initialize softc for this channel */ ch->unit = 0; ch->flags |= (ATA_USE_16BIT | ATA_NO_SLAVE); - ata_generic_hw(ch); + ata_generic_hw(dev); return ata_probe(dev); } diff --git a/sys/dev/ata/ata-cbus.c b/sys/dev/ata/ata-cbus.c index 62859cfd22eb..6a4898b03c72 100644 --- a/sys/dev/ata/ata-cbus.c +++ b/sys/dev/ata/ata-cbus.c @@ -278,11 +278,11 @@ ata_cbuschannel_probe(device_t dev) ch->r_io[ATA_CONTROL].res = ctlr->ctlio; ch->r_io[ATA_CONTROL].offset = 0; ch->r_io[ATA_IDX_ADDR].res = ctlr->io; - ata_default_registers(ch); + ata_default_registers(dev); /* initialize softc for this channel */ ch->flags |= ATA_USE_16BIT; - ata_generic_hw(ch); + ata_generic_hw(dev); return ata_probe(dev); } diff --git a/sys/dev/ata/ata-chipset.c b/sys/dev/ata/ata-chipset.c index 6bda58b5268f..ab4b0924d0e9 100644 --- a/sys/dev/ata/ata-chipset.c +++ b/sys/dev/ata/ata-chipset.c @@ -55,76 +55,76 @@ __FBSDID("$FreeBSD$"); /* local prototypes */ static int ata_generic_chipinit(device_t); static void ata_generic_intr(void *); -static void ata_generic_setmode(struct ata_device *, int); +static void ata_generic_setmode(device_t, int); static int ata_acard_chipinit(device_t); static void ata_acard_intr(void *); -static void ata_acard_850_setmode(struct ata_device *, int); -static void ata_acard_86X_setmode(struct ata_device *, int); +static void ata_acard_850_setmode(device_t, int); +static void ata_acard_86X_setmode(device_t, int); static int ata_ali_chipinit(device_t); static int ata_ali_allocate(device_t); -static void ata_ali_setmode(struct ata_device *, int); +static void ata_ali_setmode(device_t, int); static int ata_amd_chipinit(device_t); static int ata_cyrix_chipinit(device_t); -static void ata_cyrix_setmode(struct ata_device *, int); +static void ata_cyrix_setmode(device_t, int); static int ata_cypress_chipinit(device_t); -static void ata_cypress_setmode(struct ata_device *, int); +static void ata_cypress_setmode(device_t, int); static int ata_highpoint_chipinit(device_t); static void ata_highpoint_intr(void *); -static void ata_highpoint_setmode(struct ata_device *, int); -static int ata_highpoint_check_80pin(struct ata_device *, int); +static void ata_highpoint_setmode(device_t, int); +static int ata_highpoint_check_80pin(device_t, int); static int ata_intel_chipinit(device_t); static void ata_intel_intr(void *); -static void ata_intel_reset(struct ata_channel *); -static void ata_intel_old_setmode(struct ata_device *, int); -static void ata_intel_new_setmode(struct ata_device *, int); +static void ata_intel_reset(device_t); +static void ata_intel_old_setmode(device_t, int); +static void ata_intel_new_setmode(device_t, int); static int ata_ite_chipinit(device_t); -static void ata_ite_setmode(struct ata_device *, int); +static void ata_ite_setmode(device_t, int); static int ata_national_chipinit(device_t); -static void ata_national_setmode(struct ata_device *, int); +static void ata_national_setmode(device_t, int); static int ata_nvidia_chipinit(device_t); static int ata_nvidia_allocate(device_t); static void ata_nvidia_intr(void *); -static void ata_nvidia_reset(struct ata_channel *); +static void ata_nvidia_reset(device_t); static int ata_promise_chipinit(device_t); static int ata_promise_mio_allocate(device_t); static void ata_promise_mio_intr(void *); static void ata_promise_sx4_intr(void *); -static void ata_promise_mio_dmainit(struct ata_channel *); -static void ata_promise_mio_reset(struct ata_channel *ch); -static int ata_promise_mio_command(struct ata_device *atadev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); -static int ata_promise_sx4_command(struct ata_device *atadev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); -static int ata_promise_apkt(u_int8_t *bytep, struct ata_device *atadev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); +static void ata_promise_mio_dmainit(device_t); +static void ata_promise_mio_reset(device_t); +static int ata_promise_mio_command(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); +static int ata_promise_sx4_command(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); +static int ata_promise_apkt(u_int8_t *bytep, device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature); static void ata_promise_queue_hpkt(struct ata_pci_controller *ctlr, u_int32_t hpkt); static void ata_promise_next_hpkt(struct ata_pci_controller *ctlr); static void ata_promise_tx2_intr(void *); static void ata_promise_old_intr(void *); -static void ata_promise_new_dmainit(struct ata_channel *); -static void ata_promise_setmode(struct ata_device *, int); +static void ata_promise_new_dmainit(device_t); +static void ata_promise_setmode(device_t, int); static int ata_serverworks_chipinit(device_t); -static void ata_serverworks_setmode(struct ata_device *, int); +static void ata_serverworks_setmode(device_t, int); static int ata_sii_chipinit(device_t); static int ata_sii_allocate(device_t); static void ata_sii_intr(void *); -static void ata_sii_reset(struct ata_channel *); +static void ata_sii_reset(device_t); static void ata_cmd_intr(void *); static void ata_cmd_old_intr(void *); -static void ata_sii_setmode(struct ata_device *, int); -static void ata_cmd_setmode(struct ata_device *, int); +static void ata_sii_setmode(device_t, int); +static void ata_cmd_setmode(device_t, int); static int ata_sis_chipinit(device_t); static int ata_sis_allocate(device_t dev); -static void ata_sis_reset(struct ata_channel *); -static void ata_sis_setmode(struct ata_device *, int); +static void ata_sis_reset(device_t); +static void ata_sis_setmode(device_t, int); static int ata_via_chipinit(device_t); static int ata_via_allocate(device_t dev); -static void ata_via_reset(struct ata_channel *); +static void ata_via_reset(device_t); static void ata_via_southbridge_fixup(device_t); -static void ata_via_family_setmode(struct ata_device *, int); +static void ata_via_family_setmode(device_t, int); static void ata_print_cable(device_t dev, u_int8_t *who); -static int ata_atapi(struct ata_device *atadev); -static int ata_check_80pin(struct ata_device *, int); +static int ata_atapi(device_t); +static int ata_check_80pin(device_t, int); static struct ata_chip_id *ata_find_chip(device_t, struct ata_chip_id *, int); static int ata_setup_interrupt(device_t); -static int ata_serialize(struct ata_channel *, int); +static int ata_serialize(device_t, int); static int ata_mode2idx(int); @@ -158,7 +158,7 @@ ata_generic_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (ch->dma && (ch->dma->flags & ATA_DMA_ACTIVE)) { @@ -175,19 +175,23 @@ ata_generic_intr(void *data) } static void -ata_generic_setmode(struct ata_device *atadev, int mode) +ata_generic_setmode(device_t dev, int mode) { - mode = ata_limit_mode(atadev, mode, ATA_UDMA2); - mode = ata_check_80pin(atadev, mode); - if (!ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) + struct ata_device *atadev = device_get_softc(dev); + + mode = ata_limit_mode(dev, mode, ATA_UDMA2); + mode = ata_check_80pin(dev, mode); + if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) atadev->mode = mode; } /* SATA support functions */ static void -ata_sata_setmode(struct ata_device *atadev, int mode) +ata_sata_setmode(device_t dev, int mode) { + struct ata_device *atadev = device_get_softc(dev); + /* * if we detect that the device isn't a real SATA device we limit * the transfer mode to UDMA5/ATA100. @@ -196,13 +200,13 @@ ata_sata_setmode(struct ata_device *atadev, int mode) */ if (atadev->param.satacapabilities != 0x0000 && atadev->param.satacapabilities != 0xffff) { - if (!ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, - ata_limit_mode(atadev, mode, ATA_UDMA6))) + if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, + ata_limit_mode(dev, mode, ATA_UDMA6))) atadev->mode = ATA_SA150; } else { - mode = ata_limit_mode(atadev, mode, ATA_UDMA5); - if (!ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) + mode = ata_limit_mode(dev, mode, ATA_UDMA5); + if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) atadev->mode = mode; } } @@ -222,9 +226,9 @@ ata_sata_connect(struct ata_channel *ch) ata_udelay(10000); } if (timeout >= 100) { - if (1 | bootverbose) + if (1 | bootverbose) device_printf(ch->dev, "SATA connect status=%08x\n", status); - return 0; + return 0; } /* clear SATA error register */ @@ -234,7 +238,7 @@ ata_sata_connect(struct ata_channel *ch) ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM); DELAY(10); for (timeout = 0; timeout < 3100; timeout++) { - if (ATA_IDX_INB(ch, ATA_STATUS) & ATA_S_BUSY) + if (ATA_IDX_INB(ch, ATA_STATUS) & ATA_S_BUSY) DELAY(10000); else break; @@ -370,7 +374,7 @@ ata_acard_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (ctlr->chip->cfg1 == ATPOLD && @@ -393,22 +397,23 @@ ata_acard_intr(void *data) } static void -ata_acard_850_setmode(struct ata_device *atadev, int mode) +ata_acard_850_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; - mode = ata_limit_mode(atadev, mode, - ata_atapi(atadev) ? ATA_PIO_MAX:ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, + ata_atapi(dev) ? ATA_PIO_MAX : ctlr->chip->max_dma); /* XXX SOS missing WDMA0+1 + PIO modes */ if (mode >= ATA_WDMA2) { - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0,mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -428,25 +433,26 @@ ata_acard_850_setmode(struct ata_device *atadev, int mode) } static void -ata_acard_86X_setmode(struct ata_device *atadev, int mode) +ata_acard_86X_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; - mode = ata_limit_mode(atadev, mode, - ata_atapi(atadev) ? ATA_PIO_MAX:ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, + ata_atapi(dev) ? ATA_PIO_MAX : ctlr->chip->max_dma); - mode = ata_check_80pin(atadev, mode); + mode = ata_check_80pin(dev, mode); /* XXX SOS missing WDMA0+1 + PIO modes */ if (mode >= ATA_WDMA2) { - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0,mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -521,7 +527,7 @@ ata_ali_chipinit(device_t dev) /* enable cable detection and UDMA support on newer chips */ pci_write_config(dev, 0x4b, pci_read_config(dev, 0x4b, 1) | 0x09, 1); ctlr->setmode = ata_ali_setmode; - break; + break; case ALIOLD: /* deactivate the ATAPI FIFO and enable ATAPI UDMA */ @@ -542,7 +548,7 @@ ata_ali_allocate(device_t dev) struct resource *io = NULL, *ctlio = NULL; int unit01 = (ch->unit & 1), unit10 = (ch->unit & 2); int i, rid; - + rid = PCIR_BAR(0) + (unit01 ? 8 : 0); io = bus_alloc_resource_any(parent, SYS_RES_IOPORT, &rid, RF_ACTIVE); if (!io) @@ -554,15 +560,15 @@ ata_ali_allocate(device_t dev) bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io); return ENXIO; } - + for (i = ATA_DATA; i <= ATA_COMMAND; i ++) { - ch->r_io[i].res = io; - ch->r_io[i].offset = i + (unit10 ? 8 : 0); + ch->r_io[i].res = io; + ch->r_io[i].offset = i + (unit10 ? 8 : 0); } ch->r_io[ATA_CONTROL].res = ctlio; ch->r_io[ATA_CONTROL].offset = 2 + (unit10 ? 4 : 0); ch->r_io[ATA_IDX_ADDR].res = io; - ata_default_registers(ch); + ata_default_registers(dev); if (ctlr->r_res1) { for (i = ATA_BMCMD_PORT; i <= ATA_BMDTP_PORT; i++) { ch->r_io[i].res = ctlr->r_res1; @@ -572,46 +578,46 @@ ata_ali_allocate(device_t dev) ch->flags |= ATA_NO_SLAVE; /* XXX SOS PHY handling awkward in ALI chip not supported yet */ - ata_generic_hw(ch); + ata_generic_hw(dev); return 0; } static void -ata_ali_setmode(struct ata_device *atadev, int mode) +ata_ali_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); if (ctlr->chip->cfg2 & ALINEW) { if (mode > ATA_UDMA2 && pci_read_config(gparent, 0x4a, 1) & (1 << ch->unit)) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } } else - mode = ata_check_80pin(atadev, mode); + mode = ata_check_80pin(dev, mode); if (ctlr->chip->cfg2 & ALIOLD) { /* doesn't support ATAPI DMA on write */ ch->flags |= ATA_ATAPI_DMA_RO; if (ch->devices & ATA_ATAPI_MASTER && ch->devices & ATA_ATAPI_SLAVE) { /* doesn't support ATAPI DMA on two ATAPI devices */ - device_printf(atadev->dev, - "two atapi devices on this channel, no DMA\n"); - mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); + device_printf(dev, "two atapi devices on this channel, no DMA\n"); + mode = ata_limit_mode(dev, mode, ATA_PIO_MAX); } } - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -717,9 +723,10 @@ ata_cyrix_chipinit(device_t dev) } static void -ata_cyrix_setmode(struct ata_device *atadev, int mode) +ata_cyrix_setmode(device_t dev, int mode) { - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); u_int32_t piotiming[] = { 0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010 }; @@ -730,12 +737,12 @@ ata_cyrix_setmode(struct ata_device *atadev, int mode) ch->dma->alignment = 16; ch->dma->max_iosize = 126 * DEV_BSIZE; - mode = ata_limit_mode(atadev, mode, ATA_UDMA2); + mode = ata_limit_mode(dev, mode, ATA_UDMA2); - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on Cyrix chip\n", + device_printf(dev, "%ssetting %s on Cyrix chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode)); if (!error) { if (mode >= ATA_UDMA0) { @@ -793,19 +800,20 @@ ata_cypress_chipinit(device_t dev) } static void -ata_cypress_setmode(struct ata_device *atadev, int mode) +ata_cypress_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + device_t gparent = GRANDPARENT(dev); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int error; - mode = ata_limit_mode(atadev, mode, ATA_WDMA2); + mode = ata_limit_mode(dev, mode, ATA_WDMA2); /* XXX missing WDMA0+1 + PIO modes */ if (mode == ATA_WDMA2) { - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0,mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting WDMA2 on Cypress chip\n", + device_printf(dev, "%ssetting WDMA2 on Cypress chip\n", error ? "FAILURE " : ""); if (!error) { pci_write_config(gparent, ch->unit ? 0x4e : 0x4c, 0x2020, 2); @@ -903,7 +911,7 @@ ata_highpoint_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (ch->dma) { @@ -920,11 +928,12 @@ ata_highpoint_intr(void *data) } static void -ata_highpoint_setmode(struct ata_device *atadev, int mode) +ata_highpoint_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; u_int32_t timings33[][4] = { @@ -946,23 +955,23 @@ ata_highpoint_setmode(struct ata_device *atadev, int mode) { 0, 0, 0x1c869c62, 0x12808242 } /* UDMA 6 */ }; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); - if (ctlr->chip->cfg1 == HPT366 && ata_atapi(atadev)) - mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); + if (ctlr->chip->cfg1 == HPT366 && ata_atapi(dev)) + mode = ata_limit_mode(dev, mode, ATA_PIO_MAX); - mode = ata_highpoint_check_80pin(atadev, mode); + mode = ata_highpoint_check_80pin(dev, mode); /* * most if not all HPT chips cant really handle that the device is * running at ATA_UDMA6/ATA133 speed, so we cheat at set the device to * a max of ATA_UDMA5/ATA100 to guard against suboptimal performance */ - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, - ata_limit_mode(atadev, mode, ATA_UDMA5)); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, + ata_limit_mode(dev, mode, ATA_UDMA5)); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on HighPoint chip\n", + device_printf(dev, "%ssetting %s on HighPoint chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode)); if (!error) pci_write_config(gparent, 0x40 + (devno << 2), @@ -971,11 +980,11 @@ ata_highpoint_setmode(struct ata_device *atadev, int mode) } static int -ata_highpoint_check_80pin(struct ata_device *atadev, int mode) +ata_highpoint_check_80pin(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); u_int8_t reg, val, res; if (ctlr->chip->cfg1 == HPT374 && pci_get_function(gparent) == 1) { @@ -992,7 +1001,7 @@ ata_highpoint_check_80pin(struct ata_device *atadev, int mode) pci_write_config(gparent, reg, val, 1); if (mode > ATA_UDMA2 && res) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } return mode; @@ -1008,30 +1017,30 @@ ata_intel_ident(device_t dev) struct ata_pci_controller *ctlr = device_get_softc(dev); struct ata_chip_id *idx; static struct ata_chip_id ids[] = - {{ ATA_I82371FB, 0, 0, 0x00, ATA_WDMA2, "Intel PIIX" }, - { ATA_I82371SB, 0, 0, 0x00, ATA_WDMA2, "Intel PIIX3" }, - { ATA_I82371AB, 0, 0, 0x00, ATA_UDMA2, "Intel PIIX4" }, - { ATA_I82443MX, 0, 0, 0x00, ATA_UDMA2, "Intel PIIX4" }, - { ATA_I82451NX, 0, 0, 0x00, ATA_UDMA2, "Intel PIIX4" }, - { ATA_I82801AB, 0, 0, 0x00, ATA_UDMA2, "Intel ICH0" }, - { ATA_I82801AA, 0, 0, 0x00, ATA_UDMA4, "Intel ICH" }, - { ATA_I82372FB, 0, 0, 0x00, ATA_UDMA4, "Intel ICH" }, - { ATA_I82801BA, 0, 0, 0x00, ATA_UDMA5, "Intel ICH2" }, - { ATA_I82801BA_1, 0, 0, 0x00, ATA_UDMA5, "Intel ICH2" }, - { ATA_I82801CA, 0, 0, 0x00, ATA_UDMA5, "Intel ICH3" }, - { ATA_I82801CA_1, 0, 0, 0x00, ATA_UDMA5, "Intel ICH3" }, - { ATA_I82801DB, 0, 0, 0x00, ATA_UDMA5, "Intel ICH4" }, - { ATA_I82801DB_1, 0, 0, 0x00, ATA_UDMA5, "Intel ICH4" }, - { ATA_I82801EB, 0, 0, 0x00, ATA_UDMA5, "Intel ICH5" }, - { ATA_I82801EB_S1,0, 0, 0x00, ATA_SA150, "Intel ICH5" }, - { ATA_I82801EB_R1,0, 0, 0x00, ATA_SA150, "Intel ICH5" }, - { ATA_I6300ESB, 0, 0, 0x00, ATA_UDMA5, "Intel 6300ESB" }, - { ATA_I6300ESB_S1,0, 0, 0x00, ATA_SA150, "Intel 6300ESB" }, - { ATA_I6300ESB_R1,0, 0, 0x00, ATA_SA150, "Intel 6300ESB" }, - { ATA_I82801FB, 0, 0, 0x00, ATA_UDMA5, "Intel ICH6" }, - { ATA_I82801FB_S1,0, 0, 0x00, ATA_SA150, "Intel ICH6" }, - { ATA_I82801FB_R1,0, 0, 0x00, ATA_SA150, "Intel ICH6" }, - { ATA_I82801FBM, 0, 0, 0x00, ATA_SA150, "Intel ICH6" }, + {{ ATA_I82371FB, 0, 0, 0x00, ATA_WDMA2, "Intel PIIX" }, + { ATA_I82371SB, 0, 0, 0x00, ATA_WDMA2, "Intel PIIX3" }, + { ATA_I82371AB, 0, 0, 0x00, ATA_UDMA2, "Intel PIIX4" }, + { ATA_I82443MX, 0, 0, 0x00, ATA_UDMA2, "Intel PIIX4" }, + { ATA_I82451NX, 0, 0, 0x00, ATA_UDMA2, "Intel PIIX4" }, + { ATA_I82801AB, 0, 0, 0x00, ATA_UDMA2, "Intel ICH0" }, + { ATA_I82801AA, 0, 0, 0x00, ATA_UDMA4, "Intel ICH" }, + { ATA_I82372FB, 0, 0, 0x00, ATA_UDMA4, "Intel ICH" }, + { ATA_I82801BA, 0, 0, 0x00, ATA_UDMA5, "Intel ICH2" }, + { ATA_I82801BA_1, 0, 0, 0x00, ATA_UDMA5, "Intel ICH2" }, + { ATA_I82801CA, 0, 0, 0x00, ATA_UDMA5, "Intel ICH3" }, + { ATA_I82801CA_1, 0, 0, 0x00, ATA_UDMA5, "Intel ICH3" }, + { ATA_I82801DB, 0, 0, 0x00, ATA_UDMA5, "Intel ICH4" }, + { ATA_I82801DB_1, 0, 0, 0x00, ATA_UDMA5, "Intel ICH4" }, + { ATA_I82801EB, 0, 0, 0x00, ATA_UDMA5, "Intel ICH5" }, + { ATA_I82801EB_S1, 0, 0, 0x00, ATA_SA150, "Intel ICH5" }, + { ATA_I82801EB_R1, 0, 0, 0x00, ATA_SA150, "Intel ICH5" }, + { ATA_I6300ESB, 0, 0, 0x00, ATA_UDMA5, "Intel 6300ESB" }, + { ATA_I6300ESB_S1, 0, 0, 0x00, ATA_SA150, "Intel 6300ESB" }, + { ATA_I6300ESB_R1, 0, 0, 0x00, ATA_SA150, "Intel 6300ESB" }, + { ATA_I82801FB, 0, 0, 0x00, ATA_UDMA5, "Intel ICH6" }, + { ATA_I82801FB_S1, 0, 0, 0x00, ATA_SA150, "Intel ICH6" }, + { ATA_I82801FB_R1, 0, 0, 0x00, ATA_SA150, "Intel ICH6" }, + { ATA_I82801FBM, 0, 0, 0x00, ATA_SA150, "Intel ICH6" }, { 0, 0, 0, 0, 0, 0}}; char buffer[64]; @@ -1087,7 +1096,7 @@ ata_intel_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (ch->dma) { @@ -1104,16 +1113,17 @@ ata_intel_intr(void *data) } static void -ata_intel_old_setmode(struct ata_device *atadev, int mode) +ata_intel_old_setmode(device_t dev, int mode) { /* NOT YET */ } static void -ata_intel_reset(struct ata_channel *ch) +ata_intel_reset(device_t dev) { - device_t parent = device_get_parent(ch->dev); + device_t parent = device_get_parent(dev); struct ata_pci_controller *ctlr = device_get_softc(parent); + struct ata_channel *ch = device_get_softc(dev); int mask, timeout; /* ICH6 has 4 SATA ports as master/slave on 2 channels so deal with pairs */ @@ -1142,15 +1152,16 @@ ata_intel_reset(struct ata_channel *ch) break; ata_udelay(10000); } - ata_generic_reset(ch); + ata_generic_reset(dev); } static void -ata_intel_new_setmode(struct ata_device *atadev, int mode) +ata_intel_new_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); u_int32_t reg40 = pci_read_config(gparent, 0x40, 4); u_int8_t reg44 = pci_read_config(gparent, 0x44, 1); @@ -1163,17 +1174,17 @@ ata_intel_new_setmode(struct ata_device *atadev, int mode) u_int8_t timings[] = { 0x00, 0x00, 0x10, 0x21, 0x23, 0x10, 0x21, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x23 }; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); if ( mode > ATA_UDMA2 && !(reg54 & (0x10 << devno))) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (error) @@ -1260,28 +1271,29 @@ ata_ite_chipinit(device_t dev) } static void -ata_ite_setmode(struct ata_device *atadev, int mode) +ata_ite_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + device_t gparent = GRANDPARENT(dev); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; /* correct the mode for what the HW supports */ - mode = ata_limit_mode(atadev, mode, ATA_UDMA6); + mode = ata_limit_mode(dev, mode, ATA_UDMA6); /* check the CBLID bits for 80 conductor cable detection */ if (mode > ATA_UDMA2 && (pci_read_config(gparent, 0x40, 2) & (ch->unit ? (1<<3) : (1<<2)))) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } /* set the wanted mode on the device */ - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%s setting %s on ITE8212F chip\n", + device_printf(dev, "%s setting %s on ITE8212F chip\n", (error) ? "failed" : "success", ata_mode2str(mode)); /* if the device accepted the mode change, setup the HW accordingly */ @@ -1364,10 +1376,11 @@ ata_national_chipinit(device_t dev) } static void -ata_national_setmode(struct ata_device *atadev, int mode) +ata_national_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + device_t gparent = GRANDPARENT(dev); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); u_int32_t piotiming[] = { 0x9172d132, 0x21717121, 0x00803020, 0x20102010, 0x00100010, @@ -1380,12 +1393,12 @@ ata_national_setmode(struct ata_device *atadev, int mode) ch->dma->alignment = 16; ch->dma->max_iosize = 126 * DEV_BSIZE; - mode = ata_limit_mode(atadev, mode, ATA_UDMA2); + mode = ata_limit_mode(dev, mode, ATA_UDMA2); - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%s setting %s on National chip\n", + device_printf(dev, "%s setting %s on National chip\n", (error) ? "failed" : "success", ata_mode2str(mode)); if (!error) { if (mode >= ATA_UDMA0) { @@ -1454,18 +1467,18 @@ ata_nvidia_chipinit(device_t dev) if (ctlr->chip->max_dma >= ATA_SA150) { if (pci_read_config(dev, PCIR_BAR(5), 1) & 1) - ctlr->r_type2 = SYS_RES_IOPORT; + ctlr->r_type2 = SYS_RES_IOPORT; else - ctlr->r_type2 = SYS_RES_MEMORY; - ctlr->r_rid2 = PCIR_BAR(5); - if ((ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2, + ctlr->r_type2 = SYS_RES_MEMORY; + ctlr->r_rid2 = PCIR_BAR(5); + if ((ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2, &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_nvidia_intr, ctlr, &ctlr->handle)) { - device_printf(dev, "unable to setup interrupt\n"); - return ENXIO; - } + ata_nvidia_intr, ctlr, &ctlr->handle)) { + device_printf(dev, "unable to setup interrupt\n"); + return ENXIO; + } pci_write_config(dev, PCIR_COMMAND, pci_read_config(dev, PCIR_COMMAND, 2) & ~0x0400,2); ctlr->allocate = ata_nvidia_allocate; @@ -1565,17 +1578,17 @@ ata_nvidia_intr(void *data) ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, bmstat&~ATA_BMSTAT_ERROR); DELAY(1); } - ctlr->interrupt[unit].function(ch); + ctlr->interrupt[unit].function(ch); } } } } static void -ata_nvidia_reset(struct ata_channel *ch) +ata_nvidia_reset(device_t dev) { - struct ata_pci_controller *ctlr = - device_get_softc(device_get_parent(ch->dev)); + struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); + struct ata_channel *ch = device_get_softc(dev); int offset = ctlr->chip->cfg2 & NV4OFF ? 0x0441 : 0x0011; /* disable PHY state change interrupt */ @@ -1863,7 +1876,7 @@ ata_promise_mio_allocate(device_t dev) ch->r_io[ATA_CONTROL].res = ctlr->r_res2; ch->r_io[ATA_CONTROL].offset = offset + 0x0238 + (ch->unit << 7); ch->r_io[ATA_IDX_ADDR].res = ctlr->r_res2; - ata_default_registers(ch); + ata_default_registers(dev); if ((ctlr->chip->cfg2 & (PRSATA | PRSATA2)) || ((ctlr->chip->cfg2 & (PRCMBO | PRCMBO2)) && ch->unit < 2)) { ch->r_io[ATA_SSTATUS].res = ctlr->r_res2; @@ -1876,7 +1889,7 @@ ata_promise_mio_allocate(device_t dev) } ch->flags |= ATA_USE_16BIT; - ata_generic_hw(ch); + ata_generic_hw(dev); if (offset) ch->hw.command = ata_promise_sx4_command; else @@ -1989,24 +2002,30 @@ ata_promise_sx4_intr(void *data) } static int -ata_promise_mio_dmastart(struct ata_channel *ch) +ata_promise_mio_dmastart(device_t dev) { + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + ch->flags |= ATA_DMA_ACTIVE; return 0; } static int -ata_promise_mio_dmastop(struct ata_channel *ch) +ata_promise_mio_dmastop(device_t dev) { + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + ch->flags &= ~ATA_DMA_ACTIVE; /* get status XXX SOS */ return 0; } static void -ata_promise_mio_dmainit(struct ata_channel *ch) +ata_promise_mio_dmainit(device_t dev) { - ata_dmainit(ch); + struct ata_channel *ch = device_get_softc(dev); + + ata_dmainit(dev); if (ch->dma) { ch->dma->start = ata_promise_mio_dmastart; ch->dma->stop = ata_promise_mio_dmastop; @@ -2014,10 +2033,10 @@ ata_promise_mio_dmainit(struct ata_channel *ch) } static void -ata_promise_mio_reset(struct ata_channel *ch) +ata_promise_mio_reset(device_t dev) { - struct ata_pci_controller *ctlr = - device_get_softc(device_get_parent(ch->dev)); + struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); + struct ata_channel *ch = device_get_softc(dev); struct ata_promise_sx4 *hpktp; switch (ctlr->chip->cfg2) { @@ -2040,7 +2059,7 @@ ata_promise_mio_reset(struct ata_channel *ch) (ATA_INL(ctlr->r_res2, 0xc012c) & ~0x00000f9f)); hpktp->busy = 0; mtx_unlock(&hpktp->mtx); - ata_generic_reset(ch); + ata_generic_reset(dev); break; case PRCMBO: @@ -2068,7 +2087,7 @@ ata_promise_mio_reset(struct ata_channel *ch) ATA_OUTL(ctlr->r_res2, 0x06c, (0x00000011 << ch->unit)); } else - ata_generic_reset(ch); + ata_generic_reset(dev); break; case PRCMBO2: @@ -2106,25 +2125,25 @@ ata_promise_mio_reset(struct ata_channel *ch) ATA_OUTL(ctlr->r_res2, 0x4e8 + (ch->unit << 8), 0x00); } else - ata_generic_reset(ch); + ata_generic_reset(dev); break; } } static int -ata_promise_mio_command(struct ata_device *atadev, u_int8_t command, +ata_promise_mio_command(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature) { - struct ata_pci_controller *ctlr=device_get_softc(GRANDPARENT(atadev->dev)); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); u_int32_t *wordp = (u_int32_t *)ch->dma->work; ATA_OUTL(ctlr->r_res2, (ch->unit + 1) << 2, 0x00000001); switch (command) { default: - return ata_generic_command(atadev, command, lba, count, feature); + return ata_generic_command(dev, command, lba, count, feature); case ATA_READ_DMA: wordp[0] = htole32(0x04 | ((ch->unit + 1) << 16) | (0x00 << 24)); @@ -2136,19 +2155,19 @@ ata_promise_mio_command(struct ata_device *atadev, u_int8_t command, } wordp[1] = htole32(ch->dma->sg_bus); wordp[2] = 0; - ata_promise_apkt((u_int8_t*)wordp, atadev, command, lba, count, feature); + ata_promise_apkt((u_int8_t*)wordp, dev, command, lba, count, feature); ATA_OUTL(ctlr->r_res2, 0x0240 + (ch->unit << 7), ch->dma->work_bus); return 0; } static int -ata_promise_sx4_command(struct ata_device *atadev, u_int8_t command, +ata_promise_sx4_command(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_dma_prdentry *prd = ch->dma->sg; caddr_t window = rman_get_virtual(ctlr->r_res1); u_int32_t *wordp; @@ -2165,7 +2184,7 @@ ata_promise_sx4_command(struct ata_device *atadev, u_int8_t command, case ATA_WRITE: case ATA_WRITE_MUL: ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001); - return ata_generic_command(atadev, command, lba, count, feature); + return ata_generic_command(dev, command, lba, count, feature); case ATA_SETFEATURES: case ATA_FLUSHCACHE: @@ -2176,7 +2195,7 @@ ata_promise_sx4_command(struct ata_device *atadev, u_int8_t command, wordp[0] = htole32(0x08 | ((ch->unit + 1)<<16) | (0x00 << 24)); wordp[1] = 0; wordp[2] = 0; - ata_promise_apkt((u_int8_t *)wordp, atadev, command, lba,count,feature); + ata_promise_apkt((u_int8_t *)wordp, dev, command, lba,count,feature); ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001); ATA_OUTL(ctlr->r_res2, 0x000c0400 + ((ch->unit + 1) << 2), 0x00000001); ATA_OUTL(ctlr->r_res2, 0x000c0240 + (ch->unit << 7), @@ -2223,7 +2242,7 @@ ata_promise_sx4_command(struct ata_device *atadev, u_int8_t command, wordp[0] = htole32(0x10 | ((ch->unit+1)<<16) | ((ch->unit+13)<<24)); wordp[1] = htole32((ch->unit * ATA_PDC_CHN_OFFSET)+ATA_PDC_ASG_OFFSET); wordp[2] = 0; - ata_promise_apkt((u_int8_t *)wordp, atadev, command, lba,count,feature); + ata_promise_apkt((u_int8_t *)wordp, dev, command, lba,count,feature); ATA_OUTL(ctlr->r_res2, 0x000c0484, 0x00000001); if (command == ATA_READ_DMA) { @@ -2243,10 +2262,11 @@ ata_promise_sx4_command(struct ata_device *atadev, u_int8_t command, } static int -ata_promise_apkt(u_int8_t *bytep, struct ata_device *atadev, u_int8_t command, +ata_promise_apkt(u_int8_t *bytep, device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature) { - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int i = 12; bytep[i++] = ATA_PDC_1B | ATA_PDC_WRITE_REG | ATA_PDC_WAIT_NBUSY|ATA_DRIVE; @@ -2360,7 +2380,7 @@ ata_promise_tx2_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b); @@ -2387,7 +2407,7 @@ ata_promise_old_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (ATA_INL(ctlr->r_res1, 0x1c) & (ch->unit ? 0x00004000 : 0x00000400)){ @@ -2406,10 +2426,10 @@ ata_promise_old_intr(void *data) } static int -ata_promise_new_dmastart(struct ata_channel *ch) +ata_promise_new_dmastart(device_t dev) { - struct ata_pci_controller *ctlr = - device_get_softc(device_get_parent(ch->dev)); + struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); if (ch->flags & ATA_48BIT_ACTIVE) { ATA_OUTB(ctlr->r_res1, 0x11, @@ -2429,10 +2449,10 @@ ata_promise_new_dmastart(struct ata_channel *ch) } static int -ata_promise_new_dmastop(struct ata_channel *ch) +ata_promise_new_dmastop(device_t dev) { - struct ata_pci_controller *ctlr = - device_get_softc(device_get_parent(ch->dev)); + struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); int error; if (ch->flags & ATA_48BIT_ACTIVE) { @@ -2449,9 +2469,11 @@ ata_promise_new_dmastop(struct ata_channel *ch) } static void -ata_promise_new_dmainit(struct ata_channel *ch) +ata_promise_new_dmainit(device_t dev) { - ata_dmainit(ch); + struct ata_channel *ch = device_get_softc(dev); + + ata_dmainit(dev); if (ch->dma) { ch->dma->start = ata_promise_new_dmastart; ch->dma->stop = ata_promise_new_dmastop; @@ -2459,11 +2481,12 @@ ata_promise_new_dmainit(struct ata_channel *ch) } static void -ata_promise_setmode(struct ata_device *atadev, int mode) +ata_promise_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; u_int32_t timings33[][2] = { @@ -2484,25 +2507,25 @@ ata_promise_setmode(struct ata_device *atadev, int mode) { 0, 0x004127f3 } /* UDMA 5 */ }; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); switch (ctlr->chip->cfg1) { case PROLD: case PRNEW: if (mode > ATA_UDMA2 && (pci_read_config(gparent, 0x50, 2) & (ch->unit ? 1 << 11 : 1 << 10))) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } - if (ata_atapi(atadev) && mode > ATA_PIO_MAX) - mode = ata_limit_mode(atadev, mode, ATA_PIO_MAX); + if (ata_atapi(dev) && mode > ATA_PIO_MAX) + mode = ata_limit_mode(dev, mode, ATA_PIO_MAX); break; case PRTX: ATA_IDX_OUTB(ch, ATA_BMDEVSPEC_0, 0x0b); if (mode > ATA_UDMA2 && ATA_IDX_INB(ch, ATA_BMDEVSPEC_1) & 0x04) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } break; @@ -2512,16 +2535,16 @@ ata_promise_setmode(struct ata_device *atadev, int mode) (ATA_INL(ctlr->r_res2, (ctlr->chip->cfg2 & PRSX4X ? 0x000c0260 : 0x0260) + (ch->unit << 7)) & 0x01000000)) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } break; } - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -2596,11 +2619,12 @@ ata_serverworks_chipinit(device_t dev) } static void -ata_serverworks_setmode(struct ata_device *atadev, int mode) +ata_serverworks_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int offset = (devno ^ 0x01) << 3; int error; @@ -2608,14 +2632,14 @@ ata_serverworks_setmode(struct ata_device *atadev, int mode) 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; u_int8_t dmatimings[] = { 0x77, 0x21, 0x20 }; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); - mode = ata_check_80pin(atadev, mode); + mode = ata_check_80pin(dev, mode); - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -2781,7 +2805,7 @@ ata_sii_allocate(device_t dev) ch->r_io[ATA_CONTROL].res = ctlr->r_res2; ch->r_io[ATA_CONTROL].offset = 0x8a + (unit01 << 6) + (unit10 << 8); ch->r_io[ATA_IDX_ADDR].res = ctlr->r_res2; - ata_default_registers(ch); + ata_default_registers(dev); ch->r_io[ATA_BMCMD_PORT].res = ctlr->r_res2; ch->r_io[ATA_BMCMD_PORT].offset = 0x00 + (unit01 << 3) + (unit10 << 8); ch->r_io[ATA_BMSTAT_PORT].res = ctlr->r_res2; @@ -2810,7 +2834,7 @@ ata_sii_allocate(device_t dev) ch->dma->max_iosize = 15 * DEV_BSIZE; } - ata_generic_hw(ch); + ata_generic_hw(dev); return 0; } @@ -2840,7 +2864,7 @@ ata_sii_intr(void *data) if ((error & ATA_SE_PHY_CHANGED) && (tp = (struct ata_connect_task *) malloc(sizeof(struct ata_connect_task), - M_ATA, M_NOWAIT | M_ZERO))) { + M_ATA, M_NOWAIT | M_ZERO))) { if ((status & ATA_SS_CONWELL_MASK) == ATA_SS_CONWELL_GEN1) { device_printf(ch->dev, "CONNECT requested\n"); @@ -2882,7 +2906,7 @@ ata_cmd_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (((reg71 = pci_read_config(device_get_parent(ch->dev), 0x71, 1)) & @@ -2911,7 +2935,7 @@ ata_cmd_old_intr(void *data) int unit; /* implement this as a toggle instead to balance load XXX */ - for (unit = 0; unit < 2; unit++) { + for (unit = 0; unit < ctlr->channels; unit++) { if (!(ch = ctlr->interrupt[unit].argument)) continue; if (ch->dma && (ch->dma->flags & ATA_DMA_ACTIVE)) { @@ -2928,10 +2952,10 @@ ata_cmd_old_intr(void *data) } static void -ata_sii_reset(struct ata_channel *ch) +ata_sii_reset(device_t dev) { - struct ata_pci_controller *ctlr = - device_get_softc(device_get_parent(ch->dev)); + struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); + struct ata_channel *ch = device_get_softc(dev); int offset = ((ch->unit & 1) << 7) + ((ch->unit & 2) << 8); /* disable PHY state change interrupt */ @@ -2944,33 +2968,34 @@ ata_sii_reset(struct ata_channel *ch) } static void -ata_sii_setmode(struct ata_device *atadev, int mode) +ata_sii_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int rego = (ch->unit << 4) + (ATA_DEV(atadev->unit) << 1); int mreg = ch->unit ? 0x84 : 0x80; int mask = 0x03 << (ATA_DEV(atadev->unit) << 2); int mval = pci_read_config(gparent, mreg, 1) & ~mask; int error; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); if (ctlr->chip->cfg2 & SIISETCLK) { if (mode > ATA_UDMA2 && (pci_read_config(gparent, 0x79, 1) & (ch->unit ? 0x02 : 0x01))) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } } else - mode = ata_check_80pin(atadev, mode); + mode = ata_check_80pin(dev, mode); - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (error) @@ -3008,22 +3033,23 @@ ata_sii_setmode(struct ata_device *atadev, int mode) } static void -ata_cmd_setmode(struct ata_device *atadev, int mode) +ata_cmd_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); - mode = ata_check_80pin(atadev, mode); + mode = ata_check_80pin(dev, mode); - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -3211,42 +3237,45 @@ ata_sis_allocate(device_t dev) } static void -ata_sis_reset(struct ata_channel *ch) +ata_sis_reset(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + ata_sata_phy_enable(ch); } static void -ata_sis_setmode(struct ata_device *atadev, int mode) +ata_sis_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); int devno = (ch->unit << 1) + ATA_DEV(atadev->unit); int error; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); if (ctlr->chip->cfg1 == SIS133NEW) { if (mode > ATA_UDMA2 && pci_read_config(gparent, ch->unit ? 0x52 : 0x50,2) & 0x8000) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } } else { if (mode > ATA_UDMA2 && pci_read_config(gparent, 0x48, 1)&(ch->unit ? 0x20 : 0x10)) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } } - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -3414,8 +3443,10 @@ ata_via_allocate(device_t dev) } static void -ata_via_reset(struct ata_channel *ch) +ata_via_reset(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + ata_sata_phy_enable(ch); } @@ -3450,11 +3481,12 @@ ata_via_southbridge_fixup(device_t dev) /* common code for VIA, AMD & nVidia */ static void -ata_via_family_setmode(struct ata_device *atadev, int mode) +ata_via_family_setmode(device_t dev, int mode) { - device_t gparent = GRANDPARENT(atadev->dev); + device_t gparent = GRANDPARENT(dev); struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); u_int8_t timings[] = { 0xa8, 0x65, 0x42, 0x22, 0x20, 0x42, 0x22, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }; int modes[][7] = { @@ -3467,17 +3499,17 @@ ata_via_family_setmode(struct ata_device *atadev, int mode) int reg = 0x53 - devno; int error; - mode = ata_limit_mode(atadev, mode, ctlr->chip->max_dma); + mode = ata_limit_mode(dev, mode, ctlr->chip->max_dma); if (ctlr->chip->cfg2 & AMDCABLE) { if (mode > ATA_UDMA2 && !(pci_read_config(gparent, 0x42, 1) & (1 << devno))) { - ata_print_cable(atadev->dev, "controller"); + ata_print_cable(dev, "controller"); mode = ATA_UDMA2; } } else - mode = ata_check_80pin(atadev, mode); + mode = ata_check_80pin(dev, mode); if (ctlr->chip->cfg2 & NVIDIA) reg += 0x10; @@ -3485,10 +3517,10 @@ ata_via_family_setmode(struct ata_device *atadev, int mode) if (ctlr->chip->cfg1 != VIA133) pci_write_config(gparent, reg - 0x08, timings[ata_mode2idx(mode)], 1); - error = ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); if (bootverbose) - device_printf(atadev->dev, "%ssetting %s on %s chip\n", + device_printf(dev, "%ssetting %s on %s chip\n", (error) ? "FAILURE " : "", ata_mode2str(mode), ctlr->chip->text); if (!error) { @@ -3568,10 +3600,10 @@ struct ata_serialize { }; static int -ata_serialize(struct ata_channel *ch, int flags) +ata_serialize(device_t dev, int flags) { - struct ata_pci_controller *ctlr = - device_get_softc(device_get_parent(ch->dev)); + struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); + struct ata_channel *ch = device_get_softc(dev); struct ata_serialize *serial; static int inited = 0; int res; @@ -3627,19 +3659,22 @@ ata_print_cable(device_t dev, u_int8_t *who) } static int -ata_atapi(struct ata_device *atadev) +ata_atapi(device_t dev) { - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); return ((atadev->unit == ATA_MASTER && ch->devices & ATA_ATAPI_MASTER) || (atadev->unit == ATA_SLAVE && ch->devices & ATA_ATAPI_SLAVE)); } static int -ata_check_80pin(struct ata_device *atadev, int mode) +ata_check_80pin(device_t dev, int mode) { + struct ata_device *atadev = device_get_softc(dev); + if (mode > ATA_UDMA2 && !(atadev->param.hwres & ATA_CABLE_ID)) { - ata_print_cable(atadev->dev, "device"); + ata_print_cable(dev, "device"); mode = ATA_UDMA2; } return mode; diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c index 11fe96af9cc9..64ba57904462 100644 --- a/sys/dev/ata/ata-disk.c +++ b/sys/dev/ata/ata-disk.c @@ -158,7 +158,6 @@ ad_attach(device_t dev) static int ad_detach(device_t dev) { - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ad_softc *adp = device_get_ivars(dev); device_t *children; int nchildren, i; @@ -179,7 +178,7 @@ ad_detach(device_t dev) disk_destroy(adp->disk); /* fail requests on the queue and any thats "in flight" for this device */ - ata_fail_requests(ch, dev); + ata_fail_requests(dev); /* dont leave anything behind */ device_set_ivars(dev, NULL); @@ -193,7 +192,7 @@ ad_shutdown(device_t dev) struct ata_device *atadev = device_get_softc(dev); if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) - ata_controlcmd(atadev, ATA_FLUSHCACHE, 0, 0, 0); + ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0); } static int @@ -335,19 +334,19 @@ ad_init(device_t dev) ATA_SETMODE(device_get_parent(dev), dev); /* enable read caching */ - ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_ENAB_RCACHE, 0, 0); + ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_ENAB_RCACHE, 0, 0); /* enable write caching if enabled */ if (ata_wc) - ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_ENAB_WCACHE, 0, 0); + ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_ENAB_WCACHE, 0, 0); else - ata_controlcmd(atadev, ATA_SETFEATURES, ATA_SF_DIS_WCACHE, 0, 0); + ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_DIS_WCACHE, 0, 0); /* use multiple sectors/interrupt if device supports it */ if (ad_version(atadev->param.version_major)) { int secsperint = max(1, min(atadev->param.sectors_intr, 16)); - if (!ata_controlcmd(atadev, ATA_SET_MULTI, 0, 0, secsperint)) + if (!ata_controlcmd(dev, ATA_SET_MULTI, 0, 0, secsperint)) atadev->max_iosize = secsperint * DEV_BSIZE; } else diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c index 825f81820c20..c9a08016026a 100644 --- a/sys/dev/ata/ata-dma.c +++ b/sys/dev/ata/ata-dma.c @@ -47,18 +47,18 @@ __FBSDID("$FreeBSD$"); #include <dev/ata/ata-pci.h> /* prototypes */ -static void ata_dmaalloc(struct ata_channel *); -static void ata_dmafree(struct ata_channel *); +static void ata_dmaalloc(device_t); +static void ata_dmafree(device_t); static void ata_dmasetprd(void *, bus_dma_segment_t *, int, int); -static int ata_dmaload(struct ata_device *, caddr_t, int32_t, int); -static int ata_dmaunload(struct ata_channel *); +static int ata_dmaload(device_t, caddr_t, int32_t, int); +static int ata_dmaunload(device_t); /* local vars */ static MALLOC_DEFINE(M_ATADMA, "ATA DMA", "ATA driver DMA"); /* misc defines */ #define MAXTABSZ PAGE_SIZE -#define MAXWSPCSZ PAGE_SIZE +#define MAXWSPCSZ PAGE_SIZE*2 struct ata_dc_cb_args { bus_addr_t maddr; @@ -66,8 +66,10 @@ struct ata_dc_cb_args { }; void -ata_dmainit(struct ata_channel *ch) +ata_dmainit(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + if ((ch->dma = malloc(sizeof(struct ata_dma), M_ATADMA, M_NOWAIT|M_ZERO))) { ch->dma->alloc = ata_dmaalloc; ch->dma->free = ata_dmafree; @@ -90,8 +92,9 @@ ata_dmasetupc_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error) } static void -ata_dmaalloc(struct ata_channel *ch) +ata_dmaalloc(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); struct ata_dc_cb_args ccba; if (bus_dma_tag_create(NULL, ch->dma->alignment, 0, @@ -128,7 +131,7 @@ ata_dmaalloc(struct ata_channel *ch) if (bus_dmamap_create(ch->dma->data_tag, 0, &ch->dma->data_map)) goto error; - if (bus_dma_tag_create(ch->dma->dmatag, PAGE_SIZE, PAGE_SIZE, + if (bus_dma_tag_create(ch->dma->dmatag, PAGE_SIZE, 64 * 1024, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL, MAXWSPCSZ, 1, MAXWSPCSZ, 0, NULL, NULL, &ch->dma->work_tag)) @@ -148,15 +151,17 @@ ata_dmaalloc(struct ata_channel *ch) return; error: - device_printf(ch->dev, "WARNING - DMA allocation failed, disabling DMA\n"); - ata_dmafree(ch); + device_printf(dev, "WARNING - DMA allocation failed, disabling DMA\n"); + ata_dmafree(dev); free(ch->dma, M_ATADMA); ch->dma = NULL; } static void -ata_dmafree(struct ata_channel *ch) +ata_dmafree(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + if (ch->dma->work_bus) { bus_dmamap_unload(ch->dma->work_tag, ch->dma->work_map); bus_dmamem_free(ch->dma->work_tag, ch->dma->work, ch->dma->work_map); @@ -211,30 +216,26 @@ ata_dmasetprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error) } static int -ata_dmaload(struct ata_device *atadev, caddr_t data, int32_t count, int dir) +ata_dmaload(device_t dev, caddr_t data, int32_t count, int dir) { - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_dmasetprd_args cba; if (ch->dma->flags & ATA_DMA_LOADED) { - device_printf(atadev->dev, - "FAILURE - already active DMA on this device\n"); + device_printf(dev, "FAILURE - already active DMA on this device\n"); return -1; } if (!count) { - device_printf(atadev->dev, - "FAILURE - zero length DMA transfer attempted\n"); + device_printf(dev, "FAILURE - zero length DMA transfer attempted\n"); return -1; } if (((uintptr_t)data & (ch->dma->alignment - 1)) || (count & (ch->dma->alignment - 1))) { - device_printf(atadev->dev, - "FAILURE - non aligned DMA transfer attempted\n"); + device_printf(dev, "FAILURE - non aligned DMA transfer attempted\n"); return -1; } if (count > ch->dma->max_iosize) { - device_printf(atadev->dev, - "FAILURE - oversized DMA transfer attempted %d > %d\n", + device_printf(dev, "FAILURE - oversized DMA transfer attempt %d > %d\n", count, ch->dma->max_iosize); return -1; } @@ -256,8 +257,9 @@ ata_dmaload(struct ata_device *atadev, caddr_t data, int32_t count, int dir) } int -ata_dmaunload(struct ata_channel *ch) +ata_dmaunload(device_t dev) { + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); bus_dmamap_sync(ch->dma->sg_tag, ch->dma->sg_map, BUS_DMASYNC_POSTWRITE); bus_dmamap_sync(ch->dma->data_tag, ch->dma->data_map, diff --git a/sys/dev/ata/ata-isa.c b/sys/dev/ata/ata-isa.c index 802e2764aaaf..2c4312073725 100644 --- a/sys/dev/ata/ata-isa.c +++ b/sys/dev/ata/ata-isa.c @@ -99,12 +99,12 @@ ata_isa_probe(device_t dev) ch->r_io[ATA_CONTROL].res = ctlio; ch->r_io[ATA_CONTROL].offset = 0; ch->r_io[ATA_IDX_ADDR].res = io; - ata_default_registers(ch); + ata_default_registers(dev); /* initialize softc for this channel */ ch->unit = 0; ch->flags |= ATA_USE_16BIT; - ata_generic_hw(ch); + ata_generic_hw(dev); return ata_probe(dev); } diff --git a/sys/dev/ata/ata-lowlevel.c b/sys/dev/ata/ata-lowlevel.c index 7974e3841c7d..a68b28a942b6 100644 --- a/sys/dev/ata/ata-lowlevel.c +++ b/sys/dev/ata/ata-lowlevel.c @@ -59,8 +59,10 @@ static void ata_pio_write(struct ata_request *, int); * low level ATA functions */ void -ata_generic_hw(struct ata_channel *ch) +ata_generic_hw(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + ch->hw.begin_transaction = ata_begin_transaction; ch->hw.end_transaction = ata_end_transaction; ch->hw.command = ata_generic_command; @@ -90,7 +92,7 @@ ata_begin_transaction(struct ata_request *request) int write = (request->flags & ATA_R_WRITE); /* issue command */ - if (ch->hw.command(atadev, request->u.ata.command, + if (ch->hw.command(request->dev, request->u.ata.command, request->u.ata.lba, request->u.ata.count, request->u.ata.feature)) { device_printf(request->dev, "error issueing %s command\n", @@ -127,7 +129,7 @@ ata_begin_transaction(struct ata_request *request) /* ATA DMA data transfer commands */ case ATA_R_DMA: /* check sanity, setup SG list and DMA engine */ - if (ch->dma->load(atadev, request->data, request->bytecount, + if (ch->dma->load(request->dev, request->data, request->bytecount, request->flags & ATA_R_READ)) { device_printf(request->dev, "setting up DMA failed\n"); request->result = EIO; @@ -135,7 +137,7 @@ ata_begin_transaction(struct ata_request *request) } /* issue command */ - if (ch->hw.command(atadev, request->u.ata.command, + if (ch->hw.command(request->dev, request->u.ata.command, request->u.ata.lba, request->u.ata.count, request->u.ata.feature)) { device_printf(request->dev, "error issueing %s command\n", @@ -145,7 +147,7 @@ ata_begin_transaction(struct ata_request *request) } /* start DMA engine */ - if (ch->dma->start(ch)) { + if (ch->dma->start(request->dev)) { device_printf(request->dev, "error starting DMA\n"); request->result = EIO; goto begin_finished; @@ -164,7 +166,7 @@ ata_begin_transaction(struct ata_request *request) } /* start ATAPI operation */ - if (ch->hw.command(atadev, ATA_PACKET_CMD, + if (ch->hw.command(request->dev, ATA_PACKET_CMD, request->transfersize << 8, 0, 0)) { device_printf(request->dev, "error issuing ATA PACKET command\n"); request->result = EIO; @@ -204,6 +206,7 @@ ata_begin_transaction(struct ata_request *request) ATA_PROTO_ATAPI_12 ? 6 : 8); goto begin_continue; + /* ATAPI DMA commands */ case ATA_R_ATAPI|ATA_R_DMA: /* is this just a POLL DSC command ? */ if (request->u.atapi.ccb[0] == ATAPI_POLL_DSC) { @@ -215,7 +218,7 @@ ata_begin_transaction(struct ata_request *request) } /* check sanity, setup SG list and DMA engine */ - if (ch->dma->load(atadev, request->data, request->bytecount, + if (ch->dma->load(request->dev, request->data, request->bytecount, request->flags & ATA_R_READ)) { device_printf(request->dev, "setting up DMA failed\n"); request->result = EIO; @@ -223,7 +226,7 @@ ata_begin_transaction(struct ata_request *request) } /* start ATAPI operation */ - if (ch->hw.command(atadev, ATA_PACKET_CMD, 0, 0, ATA_F_DMA)) { + if (ch->hw.command(request->dev, ATA_PACKET_CMD, 0, 0, ATA_F_DMA)) { device_printf(request->dev, "error issuing ATAPI packet command\n"); request->result = EIO; goto begin_finished; @@ -258,7 +261,7 @@ ata_begin_transaction(struct ata_request *request) ATA_PROTO_ATAPI_12 ? 6 : 8); /* start DMA engine */ - if (ch->dma->start(ch)) { + if (ch->dma->start(request->dev)) { request->result = EIO; goto begin_finished; } @@ -269,7 +272,7 @@ ata_begin_transaction(struct ata_request *request) begin_finished: if (ch->dma && ch->dma->flags & ATA_DMA_LOADED) - ch->dma->unload(ch); + ch->dma->unload(request->dev); return ATA_OP_FINISHED; begin_continue: @@ -318,8 +321,8 @@ ata_end_transaction(struct ata_request *request) (ATA_IDX_INB(ch, ATA_CYL_MSB) << 16)); } else { - request->u.ata.count = ATA_IDX_INB(ch, ATA_COUNT); - request->u.ata.lba = ATA_IDX_INB(ch, ATA_SECTOR) | + request->u.ata.count = ATA_IDX_INB(ch, ATA_COUNT); + request->u.ata.lba = ATA_IDX_INB(ch, ATA_SECTOR) | (ATA_IDX_INB(ch, ATA_CYL_LSB) << 8) | (ATA_IDX_INB(ch, ATA_CYL_MSB) << 16) | ((ATA_IDX_INB(ch, ATA_DRIVE) & 0xf) << 24); @@ -387,7 +390,7 @@ ata_end_transaction(struct ata_request *request) /* stop DMA engine and get status */ if (ch->dma->stop) - request->dmastat = ch->dma->stop(ch); + request->dmastat = ch->dma->stop(request->dev); /* did we get error or data */ if (request->status & ATA_S_ERROR) @@ -398,7 +401,7 @@ ata_end_transaction(struct ata_request *request) request->donecount = request->bytecount; /* release SG list etc */ - ch->dma->unload(ch); + ch->dma->unload(request->dev); /* done with HW */ goto end_finished; @@ -499,7 +502,7 @@ ata_end_transaction(struct ata_request *request) /* stop the engine and get engine status */ if (ch->dma->stop) - request->dmastat = ch->dma->stop(ch); + request->dmastat = ch->dma->stop(request->dev); /* did we get error or data */ if (request->status & (ATA_S_ERROR | ATA_S_DWF)) @@ -510,7 +513,7 @@ ata_end_transaction(struct ata_request *request) request->donecount = request->bytecount; /* release SG list etc */ - ch->dma->unload(ch); + ch->dma->unload(request->dev); /* done with HW */ goto end_finished; @@ -528,8 +531,10 @@ end_continue: /* must be called with ATA channel locked */ void -ata_generic_reset(struct ata_channel *ch) +ata_generic_reset(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); + u_int8_t ostat0 = 0, stat0 = 0, ostat1 = 0, stat1 = 0; u_int8_t err = 0, lsb = 0, msb = 0; int mask = 0, timeout; @@ -555,7 +560,7 @@ ata_generic_reset(struct ata_channel *ch) } if (bootverbose) - device_printf(ch->dev, "reset tp1 mask=%02x ostat0=%02x ostat1=%02x\n", + device_printf(dev, "reset tp1 mask=%02x ostat0=%02x ostat1=%02x\n", mask, ostat0, ostat1); /* if nothing showed up there is no need to get any further */ @@ -583,7 +588,7 @@ ata_generic_reset(struct ata_channel *ch) msb = ATA_IDX_INB(ch, ATA_CYL_MSB); stat0 = ATA_IDX_INB(ch, ATA_STATUS); if (bootverbose) - device_printf(ch->dev, + device_printf(dev, "stat0=0x%02x err=0x%02x lsb=0x%02x msb=0x%02x\n", stat0, err, lsb, msb); if (stat0 == err && lsb == err && msb == err && @@ -613,7 +618,7 @@ ata_generic_reset(struct ata_channel *ch) msb = ATA_IDX_INB(ch, ATA_CYL_MSB); stat1 = ATA_IDX_INB(ch, ATA_STATUS); if (bootverbose) - device_printf(ch->dev, + device_printf(dev, "stat1=0x%02x err=0x%02x lsb=0x%02x msb=0x%02x\n", stat1, err, lsb, msb); if (stat1 == err && lsb == err && msb == err && @@ -654,7 +659,7 @@ ata_generic_reset(struct ata_channel *ch) } if (bootverbose) - device_printf(ch->dev, "reset tp2 stat0=%02x stat1=%02x devices=0x%b\n", + device_printf(dev, "reset tp2 stat0=%02x stat1=%02x devices=0x%b\n", stat0, stat1, ch->devices, "\20\4ATAPI_SLAVE\3ATAPI_MASTER\2ATA_SLAVE\1ATA_MASTER"); } @@ -711,17 +716,18 @@ ata_wait(struct ata_channel *ch, struct ata_device *atadev, u_int8_t mask) } int -ata_generic_command(struct ata_device *atadev, u_int8_t command, +ata_generic_command(device_t dev, u_int8_t command, u_int64_t lba, u_int16_t count, u_int16_t feature) { - struct ata_channel *ch = device_get_softc(device_get_parent(atadev->dev)); + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); /* select device */ ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_D_LBA | atadev->unit); /* ready to issue command ? */ if (ata_wait(ch, atadev, 0) < 0) { - device_printf(atadev->dev, "timeout sending command=%02x\n", command); + device_printf(dev, "timeout sending command=%02x\n", command); return -1; } @@ -753,7 +759,7 @@ ata_generic_command(struct ata_device *atadev, u_int8_t command, case ATA_FLUSHCACHE: command = ATA_FLUSHCACHE48; break; default: - device_printf(atadev->dev,"can't translate cmd to 48bit version\n"); + device_printf(dev,"can't translate cmd to 48bit version\n"); return -1; } ATA_IDX_OUTB(ch, ATA_FEATURE, (feature>>8) & 0xff); diff --git a/sys/dev/ata/ata-pci.c b/sys/dev/ata/ata-pci.c index 8e1a073d3dde..b36c17c39833 100644 --- a/sys/dev/ata/ata-pci.c +++ b/sys/dev/ata/ata-pci.c @@ -60,7 +60,7 @@ static MALLOC_DEFINE(M_ATAPCI, "ATA PCI", "ATA driver PCI"); #define IOMASK 0xfffffffc /* prototypes */ -static void ata_pci_dmainit(struct ata_channel *); +static void ata_pci_dmainit(device_t); int ata_legacy(device_t dev) @@ -404,7 +404,7 @@ ata_pci_allocate(device_t dev) ch->r_io[ATA_CONTROL].res = ctlio; ch->r_io[ATA_CONTROL].offset = ata_legacy(device_get_parent(dev)) ? 0 : 2; ch->r_io[ATA_IDX_ADDR].res = io; - ata_default_registers(ch); + ata_default_registers(dev); if (ctlr->r_res1) { for (i = ATA_BMCMD_PORT; i <= ATA_BMDTP_PORT; i++) { ch->r_io[i].res = ctlr->r_res1; @@ -412,13 +412,15 @@ ata_pci_allocate(device_t dev) } } - ata_generic_hw(ch); + ata_generic_hw(dev); return 0; } static int -ata_pci_dmastart(struct ata_channel *ch) +ata_pci_dmastart(device_t dev) { + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, (ATA_IDX_INB(ch, ATA_BMSTAT_PORT) | (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR))); ATA_IDX_OUTL(ch, ATA_BMDTP_PORT, ch->dma->sg_bus); @@ -431,8 +433,9 @@ ata_pci_dmastart(struct ata_channel *ch) } static int -ata_pci_dmastop(struct ata_channel *ch) +ata_pci_dmastop(device_t dev) { + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); int error; ATA_IDX_OUTB(ch, ATA_BMCMD_PORT, @@ -444,9 +447,11 @@ ata_pci_dmastop(struct ata_channel *ch) } static void -ata_pci_dmainit(struct ata_channel *ch) +ata_pci_dmainit(device_t dev) { - ata_dmainit(ch); + struct ata_channel *ch = device_get_softc(dev); + + ata_dmainit(dev); if (ch->dma) { ch->dma->start = ata_pci_dmastart; ch->dma->stop = ata_pci_dmastop; @@ -518,9 +523,9 @@ ata_pcichannel_attach(device_t dev) int error; if (ctlr->r_res1) - ctlr->dmainit(ch); + ctlr->dmainit(dev); if (ch->dma) - ch->dma->alloc(ch); + ch->dma->alloc(dev); if ((error = ctlr->allocate(dev))) return error; @@ -538,7 +543,7 @@ ata_pcichannel_detach(device_t dev) return error; if (ch->dma) - ch->dma->free(ch); + ch->dma->free(dev); /* free resources for io and ctlio XXX SOS */ @@ -552,7 +557,7 @@ ata_pcichannel_locking(device_t dev, int mode) struct ata_channel *ch = device_get_softc(dev); if (ctlr->locking) - return ctlr->locking(ch, mode); + return ctlr->locking(dev, mode); else return ch->unit; } @@ -565,17 +570,17 @@ ata_pcichannel_reset(device_t dev) /* if DMA functionality present stop it */ if (ch->dma) { - if (ch->dma->stop) - ch->dma->stop(ch); - if (ch->dma->flags & ATA_DMA_LOADED) - ch->dma->unload(ch); + if (ch->dma->flags & ATA_DMA_ACTIVE) + ch->dma->stop(dev); + if (ch->dma->flags & ATA_DMA_LOADED) + ch->dma->unload(dev); } /* reset the controller HW */ if (ctlr->reset) - ctlr->reset(ch); + ctlr->reset(dev); else - ata_generic_reset(ch); + ata_generic_reset(dev); } static void @@ -585,9 +590,9 @@ ata_pcichannel_setmode(device_t parent, device_t dev) struct ata_device *atadev = device_get_softc(dev); int mode = atadev->mode; - ctlr->setmode(atadev, ATA_PIO_MAX); + ctlr->setmode(dev, ATA_PIO_MAX); if (mode >= ATA_DMA) - ctlr->setmode(atadev, mode); + ctlr->setmode(dev, mode); } static device_method_t ata_pcichannel_methods[] = { diff --git a/sys/dev/ata/ata-pci.h b/sys/dev/ata/ata-pci.h index 537b35ac1c02..12821c82cd32 100644 --- a/sys/dev/ata/ata-pci.h +++ b/sys/dev/ata/ata-pci.h @@ -53,10 +53,10 @@ struct ata_pci_controller { int channels; int (*chipinit)(device_t); int (*allocate)(device_t); - int (*locking)(struct ata_channel *, int); - void (*reset)(struct ata_channel *); - void (*dmainit)(struct ata_channel *); - void (*setmode)(struct ata_device *, int); + int (*locking)(device_t, int); + void (*reset)(device_t); + void (*dmainit)(device_t); + void (*setmode)(device_t, int); struct { void (*function)(void *); void *argument; @@ -91,9 +91,9 @@ struct ata_connect_task { #define ATA_ACER_LABS_ID 0x10b9 #define ATA_ALI_5229 0x522910b9 -#define ATA_ALI_5281 0x528110b9 -#define ATA_ALI_5287 0x528710b9 -#define ATA_ALI_5289 0x528910b9 +#define ATA_ALI_5281 0x528110b9 +#define ATA_ALI_5287 0x528710b9 +#define ATA_ALI_5289 0x528910b9 #define ATA_CENATEK_ID 0x16ca #define ATA_CENATEK_ROCKET 0x000116ca @@ -377,4 +377,4 @@ int ata_legacy(device_t); struct ata_chip_id *ata_match_chip(device_t, struct ata_chip_id *); /* global prototypes ata-dma.c */ -void ata_dmainit(struct ata_channel *); +void ata_dmainit(device_t); diff --git a/sys/dev/ata/ata-queue.c b/sys/dev/ata/ata-queue.c index 889a3116fd64..0dce1c05ba1a 100644 --- a/sys/dev/ata/ata-queue.c +++ b/sys/dev/ata/ata-queue.c @@ -107,14 +107,14 @@ ata_queue_request(struct ata_request *request) } int -ata_controlcmd(struct ata_device *atadev, u_int8_t command, u_int16_t feature, +ata_controlcmd(device_t dev, u_int8_t command, u_int16_t feature, u_int64_t lba, u_int16_t count) { struct ata_request *request = ata_alloc_request(); int error = ENOMEM; if (request) { - request->dev = atadev->dev; + request->dev = dev; request->u.ata.command = command; request->u.ata.lba = lba; request->u.ata.count = count; @@ -130,14 +130,15 @@ ata_controlcmd(struct ata_device *atadev, u_int8_t command, u_int16_t feature, } int -ata_atapicmd(struct ata_device *atadev, u_int8_t *ccb, caddr_t data, +ata_atapicmd(device_t dev, u_int8_t *ccb, caddr_t data, int count, int flags, int timeout) { struct ata_request *request = ata_alloc_request(); + struct ata_device *atadev = device_get_softc(dev); int error = ENOMEM; if (request) { - request->dev = atadev->dev; + request->dev = dev; if ((atadev->param.config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) bcopy(ccb, request->u.atapi.ccb, 12); else @@ -466,13 +467,14 @@ ata_timeout(struct ata_request *request) } void -ata_catch_inflight(struct ata_channel *ch) +ata_catch_inflight(device_t dev) { + struct ata_channel *ch = device_get_softc(dev); struct ata_request *request; mtx_lock(&ch->state_mtx); if ((request = ch->running)) - callout_stop(&request->callout); + callout_stop(&request->callout); ch->running = NULL; mtx_unlock(&ch->state_mtx); if (request) { @@ -488,8 +490,9 @@ ata_catch_inflight(struct ata_channel *ch) } void -ata_fail_requests(struct ata_channel *ch, device_t dev) +ata_fail_requests(device_t dev) { + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ata_request *request; /* fail all requests queued on this channel for device dev if !NULL */ diff --git a/sys/dev/ata/ata-raid.c b/sys/dev/ata/ata-raid.c index 986fbf364dc2..845e48fc0f79 100644 --- a/sys/dev/ata/ata-raid.c +++ b/sys/dev/ata/ata-raid.c @@ -119,7 +119,7 @@ ata_raid_attach(struct ar_softc *rdp, int writeback) /* sanitize arrays total_size % (width * interleave) == 0 */ if (rdp->type == AR_T_RAID0 || rdp->type == AR_T_RAID01 || rdp->type == AR_T_RAID5) - rdp->total_sectors = (rdp->total_sectors/(rdp->interleave*rdp->width))* + rdp->total_sectors = (rdp->total_sectors/(rdp->interleave*rdp->width))* (rdp->interleave * rdp->width); rdp->disk = disk_alloc(); rdp->disk->d_strategy = ata_raid_strategy; diff --git a/sys/dev/ata/ata-raid.h b/sys/dev/ata/ata-raid.h index 08ebc70445e5..4f3b67cd4e5f 100644 --- a/sys/dev/ata/ata-raid.h +++ b/sys/dev/ata/ata-raid.h @@ -283,7 +283,7 @@ struct hptv3_raid_conf { struct intel_raid_conf { u_int8_t intel_id[24]; -#define INTEL_MAGIC "Intel Raid ISM Cfg Sig. " +#define INTEL_MAGIC "Intel Raid ISM Cfg Sig. " u_int8_t version[6]; u_int8_t dummy_0[2]; @@ -349,7 +349,7 @@ struct ite_raid_conf { u_int32_t filler_2[5]; u_int16_t filler_3; u_int8_t ite_id[40]; -#define ITE_MAGIC "Integrated Technology Express Inc " +#define ITE_MAGIC "Integrated Technology Express Inc " u_int16_t filler_4; u_int32_t filler_5[6]; @@ -397,7 +397,7 @@ struct ite_raid_conf { struct lsiv2_raid_conf { u_int8_t lsi_id[6]; -#define LSIV2_MAGIC "$XIDE$" +#define LSIV2_MAGIC "$XIDE$" u_int8_t dummy_0; u_int8_t flags; @@ -470,7 +470,7 @@ struct lsiv3_raid_conf { u_int8_t checksum_0; u_int8_t filler_5[512*2]; u_int8_t lsi_id[6]; -#define LSIV3_MAGIC "$_IDE$" +#define LSIV3_MAGIC "$_IDE$" u_int16_t dummy_2; /* 0x33de for OK disk */ u_int16_t version; /* 0x0131 for this version */ @@ -526,11 +526,11 @@ struct lsiv3_raid_conf { struct promise_raid_conf { char promise_id[24]; -#define PR_MAGIC "Promise Technology, Inc." +#define PR_MAGIC "Promise Technology, Inc." u_int32_t dummy_0; u_int64_t magic_0; -#define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \ +#define PR_MAGIC0(x) (((u_int64_t)(x.channel) << 48) | \ ((u_int64_t)(x.device != 0) << 56)) u_int16_t magic_1; u_int32_t magic_2; @@ -644,25 +644,25 @@ struct sii_raid_conf { ( ((struct ad_softc *)device_get_ivars(dev))->total_secs - 1) struct via_raid_conf { - u_int16_t magic; -#define VIA_MAGIC 0xaa55 + u_int16_t magic; +#define VIA_MAGIC 0xaa55 - u_int8_t dummy_0; - u_int8_t type; -#define VIA_T_MASK 0xfe -#define VIA_T_BOOTABLE 0x01 -#define VIA_T_RAID0 0x04 -#define VIA_T_RAID1 0x0c -#define VIA_T_SPAN 0x44 + u_int8_t dummy_0; + u_int8_t type; +#define VIA_T_MASK 0xfe +#define VIA_T_BOOTABLE 0x01 +#define VIA_T_RAID0 0x04 +#define VIA_T_RAID1 0x0c +#define VIA_T_SPAN 0x44 - u_int8_t disk_index; - u_int8_t stripe_layout; -#define VIA_L_MASK 0x07 -#define VIA_L_SHIFT 4 + u_int8_t disk_index; + u_int8_t stripe_layout; +#define VIA_L_MASK 0x07 +#define VIA_L_SHIFT 4 - u_int64_t total_sectors; - u_int32_t disk_id; - u_int32_t disks[8]; - u_int8_t checksum; - u_int8_t filler_1[461]; + u_int64_t total_sectors; + u_int32_t disk_id; + u_int32_t disks[8]; + u_int8_t checksum; + u_int8_t filler_1[461]; } __packed; diff --git a/sys/dev/ata/ata_if.m b/sys/dev/ata/ata_if.m index 5d8608c40b52..248216916282 100644 --- a/sys/dev/ata/ata_if.m +++ b/sys/dev/ata/ata_if.m @@ -63,7 +63,7 @@ CODE { { struct ata_device *atadev = device_get_softc(dev); - atadev->mode = ata_limit_mode(atadev, atadev->mode, ATA_PIO_MAX); + atadev->mode = ata_limit_mode(dev, atadev->mode, ATA_PIO_MAX); } }; METHOD void setmode { diff --git a/sys/dev/ata/atapi-cam.c b/sys/dev/ata/atapi-cam.c index 0ba990062b36..c6e2309ad74c 100644 --- a/sys/dev/ata/atapi-cam.c +++ b/sys/dev/ata/atapi-cam.c @@ -56,34 +56,34 @@ __FBSDID("$FreeBSD$"); /* private data associated with an ATA bus */ struct atapi_xpt_softc { - struct ata_device atapi_cam_dev; /* must be first */ - device_t dev; - device_t parent; - struct ata_channel *ata_ch; - struct cam_path *path; - struct cam_sim *sim; - int flags; -#define BUS_REGISTERED 0x01 -#define RESOURCE_SHORTAGE 0x02 -#define DETACHING 0x04 + struct ata_device atapi_cam_dev; /* must be first */ + device_t dev; + device_t parent; + struct ata_channel *ata_ch; + struct cam_path *path; + struct cam_sim *sim; + int flags; +#define BUS_REGISTERED 0x01 +#define RESOURCE_SHORTAGE 0x02 +#define DETACHING 0x04 TAILQ_HEAD(,atapi_hcb) pending_hcbs; struct ata_device *atadev[2]; - struct mtx state_lock; + struct mtx state_lock; }; /* hardware command descriptor block */ struct atapi_hcb { struct atapi_xpt_softc *softc; - int unit; - int bus; - int target; - int lun; - union ccb *ccb; - int flags; -#define QUEUED 0x0001 + int unit; + int bus; + int target; + int lun; + union ccb *ccb; + int flags; +#define QUEUED 0x0001 #define AUTOSENSE 0x0002 - char *dxfer_alloc; + char *dxfer_alloc; TAILQ_ENTRY(atapi_hcb) chain; }; @@ -118,11 +118,11 @@ static void free_softc(struct atapi_xpt_softc *scp); static MALLOC_DEFINE(M_ATACAM, "ATA CAM transport", "ATA driver CAM-XPT layer"); static device_method_t atapi_cam_methods[] = { - DEVMETHOD(device_identify, atapi_cam_identify), - DEVMETHOD(device_probe, atapi_cam_probe), - DEVMETHOD(device_attach, atapi_cam_attach), - DEVMETHOD(device_detach, atapi_cam_detach), - DEVMETHOD(ata_reinit, atapi_cam_reinit), + DEVMETHOD(device_identify, atapi_cam_identify), + DEVMETHOD(device_probe, atapi_cam_probe), + DEVMETHOD(device_attach, atapi_cam_attach), + DEVMETHOD(device_detach, atapi_cam_detach), + DEVMETHOD(ata_reinit, atapi_cam_reinit), {0, 0} }; @@ -132,7 +132,7 @@ static driver_t atapi_cam_driver = { sizeof(struct atapi_xpt_softc) }; -static devclass_t atapi_cam_devclass; +static devclass_t atapi_cam_devclass; DRIVER_MODULE(atapicam, ata, atapi_cam_driver, atapi_cam_devclass, @@ -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], ATA_ATAPI_RESET, 0, 0, 0); + ata_controlcmd(softc->atadev[tid]->dev, ATA_ATAPI_RESET, 0, 0, 0); ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); return; @@ -472,7 +472,7 @@ atapi_action(struct cam_sim *sim, union ccb *ccb) return; } - if (softc->atadev[tid] == NULL) { + if (softc->atadev[tid] == NULL) { ccb->ccb_h.status = CAM_DEV_NOT_THERE; xpt_done(ccb); mtx_unlock(&softc->state_lock); @@ -586,7 +586,7 @@ atapi_action(struct cam_sim *sim, union ccb *ccb) if ((ccb_h->flags & CAM_DIR_MASK) == CAM_DIR_IN && (len & 1)) { /* ATA always transfers an even number of bytes */ if ((buf = hcb->dxfer_alloc - = malloc(++len, M_ATACAM, M_NOWAIT | M_ZERO)) == NULL) { + = malloc(++len, M_ATACAM, M_NOWAIT | M_ZERO)) == NULL) { printf("cannot allocate ATAPI/CAM buffer\n"); goto action_oom; } diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c index 312bcd3acfa2..673f0e00a6ef 100644 --- a/sys/dev/ata/atapi-cd.c +++ b/sys/dev/ata/atapi-cd.c @@ -149,7 +149,7 @@ acd_shutdown(device_t dev) struct ata_device *atadev = device_get_softc(dev); if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) - ata_controlcmd(atadev, ATA_FLUSHCACHE, 0, 0, 0); + ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0); } static int @@ -192,14 +192,13 @@ acd_geom_attach(void *arg, int flag) static void acd_geom_detach(void *arg, int flag) { - struct ata_channel *ch = device_get_softc(device_get_parent(arg)); struct acd_softc *cdp = device_get_ivars(arg); /* signal geom so we dont get any further requests */ g_wither_geom(cdp->gp, ENXIO); /* fail requests on the queue and any thats "in flight" for this device */ - ata_fail_requests(ch, arg); + ata_fail_requests(arg); /* dont leave anything behind */ device_set_ivars(arg, NULL); @@ -425,7 +424,7 @@ acd_geom_ioctl(struct g_provider *pp, u_long cmd, void *addr, int fflag, struct ccb[1] = args->address_format & CD_MSF_FORMAT; - if ((error = ata_atapicmd(atadev, ccb, (caddr_t)&cdp->subchan, + if ((error = ata_atapicmd(dev, ccb, (caddr_t)&cdp->subchan, sizeof(cdp->subchan), ATA_R_READ, 10))) break; @@ -439,7 +438,7 @@ acd_geom_ioctl(struct g_provider *pp, u_long cmd, void *addr, int fflag, struct if (format == CD_TRACK_INFO) ccb[6] = args->track; - if ((error = ata_atapicmd(atadev, ccb, (caddr_t)&cdp->subchan, + if ((error = ata_atapicmd(dev, ccb, (caddr_t)&cdp->subchan, sizeof(cdp->subchan),ATA_R_READ,10))){ break; } @@ -949,7 +948,7 @@ acd_read_toc(device_t dev) ccb[0] = ATAPI_READ_TOC; ccb[7] = len>>8; ccb[8] = len; - if (ata_atapicmd(atadev, ccb, (caddr_t)&cdp->toc, len, + if (ata_atapicmd(dev, ccb, (caddr_t)&cdp->toc, len, ATA_R_READ | ATA_R_QUIET, 30)) { bzero(&cdp->toc, sizeof(cdp->toc)); return; @@ -965,7 +964,7 @@ acd_read_toc(device_t dev) ccb[0] = ATAPI_READ_TOC; ccb[7] = len>>8; ccb[8] = len; - if (ata_atapicmd(atadev, ccb, (caddr_t)&cdp->toc, len, + if (ata_atapicmd(dev, ccb, (caddr_t)&cdp->toc, len, ATA_R_READ | ATA_R_QUIET, 30)) { bzero(&cdp->toc, sizeof(cdp->toc)); return; @@ -976,7 +975,7 @@ acd_read_toc(device_t dev) acd_set_ioparm(dev); bzero(ccb, sizeof(ccb)); ccb[0] = ATAPI_READ_CAPACITY; - if (ata_atapicmd(atadev, ccb, (caddr_t)sizes, sizeof(sizes), + if (ata_atapicmd(dev, ccb, (caddr_t)sizes, sizeof(sizes), ATA_R_READ | ATA_R_QUIET, 30)) { bzero(&cdp->toc, sizeof(cdp->toc)); return; @@ -1016,14 +1015,13 @@ acd_read_toc(device_t dev) static int acd_play(device_t dev, int start, int end) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16]; bzero(ccb, sizeof(ccb)); ccb[0] = ATAPI_PLAY_MSF; lba2msf(start, &ccb[3], &ccb[4], &ccb[5]); lba2msf(end, &ccb[6], &ccb[7], &ccb[8]); - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 10); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 10); } static int @@ -1048,22 +1046,20 @@ acd_setchan(device_t dev, u_int8_t c0, u_int8_t c1, u_int8_t c2, u_int8_t c3) static int acd_init_writer(device_t dev, int test_write) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16]; bzero(ccb, sizeof(ccb)); ccb[0] = ATAPI_REZERO; - ata_atapicmd(atadev, ccb, NULL, 0, ATA_R_QUIET, 60); + ata_atapicmd(dev, ccb, NULL, 0, ATA_R_QUIET, 60); ccb[0] = ATAPI_SEND_OPC_INFO; ccb[1] = 0x01; - ata_atapicmd(atadev, ccb, NULL, 0, ATA_R_QUIET, 30); + ata_atapicmd(dev, ccb, NULL, 0, ATA_R_QUIET, 30); return 0; } static int acd_fixate(device_t dev, int multisession) { - struct ata_device *atadev = device_get_softc(dev); struct acd_softc *cdp = device_get_ivars(dev); int8_t ccb[16] = { ATAPI_CLOSE_TRACK, 0x01, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -1084,7 +1080,7 @@ acd_fixate(device_t dev, int multisession) if ((error = acd_mode_select(dev, (caddr_t)¶m, param.page_length + 10))) return error; - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 30); if (error) return error; @@ -1189,24 +1185,22 @@ acd_init_track(device_t dev, struct cdr_track *track) static int acd_flush(device_t dev) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_SYNCHRONIZE_CACHE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, ATA_R_QUIET, 60); + return ata_atapicmd(dev, ccb, NULL, 0, ATA_R_QUIET, 60); } static int acd_read_track_info(device_t dev, int32_t lba, struct acd_track_info *info) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_READ_TRACK_INFO, 1, lba>>24, lba>>16, lba>>8, lba, 0, sizeof(*info)>>8, sizeof(*info), 0, 0, 0, 0, 0, 0, 0 }; int error; - if ((error = ata_atapicmd(atadev, ccb, (caddr_t)info, sizeof(*info), + if ((error = ata_atapicmd(dev, ccb, (caddr_t)info, sizeof(*info), ATA_R_READ, 30))) return error; info->track_start_addr = ntohl(info->track_start_addr); @@ -1248,7 +1242,6 @@ acd_get_progress(device_t dev, int *finished) static int acd_send_cue(device_t dev, struct cdr_cuesheet *cuesheet) { - struct ata_device *atadev = device_get_softc(dev); struct acd_softc *cdp = device_get_ivars(dev); struct write_param param; int8_t ccb[16] = { ATAPI_SEND_CUE_SHEET, 0, 0, 0, 0, 0, @@ -1294,7 +1287,7 @@ acd_send_cue(device_t dev, struct cdr_cuesheet *cuesheet) printf("\n%02x", buffer[i]); printf("\n"); #endif - error = ata_atapicmd(atadev, ccb, buffer, cuesheet->len, 0, 30); + error = ata_atapicmd(dev, ccb, buffer, cuesheet->len, 0, 30); } free(buffer, M_ACD); return error; @@ -1303,7 +1296,6 @@ acd_send_cue(device_t dev, struct cdr_cuesheet *cuesheet) static int acd_report_key(device_t dev, struct dvd_authinfo *ai) { - struct ata_device *atadev = device_get_softc(dev); struct dvd_miscauth *d = NULL; u_int32_t lba = 0; int16_t length; @@ -1349,7 +1341,7 @@ acd_report_key(device_t dev, struct dvd_authinfo *ai) d->length = htons(length - 2); } - error = ata_atapicmd(atadev, ccb, (caddr_t)d, length, + error = ata_atapicmd(dev, ccb, (caddr_t)d, length, ai->format == DVD_INVALIDATE_AGID ? 0 : ATA_R_READ,10); if (error) { free(d, M_ACD); @@ -1401,7 +1393,6 @@ acd_report_key(device_t dev, struct dvd_authinfo *ai) static int acd_send_key(device_t dev, struct dvd_authinfo *ai) { - struct ata_device *atadev = device_get_softc(dev); struct dvd_miscauth *d; int16_t length; int8_t ccb[16]; @@ -1439,7 +1430,7 @@ acd_send_key(device_t dev, struct dvd_authinfo *ai) ccb[9] = length & 0xff; ccb[10] = (ai->agid << 6) | ai->format; d->length = htons(length - 2); - error = ata_atapicmd(atadev, ccb, (caddr_t)d, length, 0, 10); + error = ata_atapicmd(dev, ccb, (caddr_t)d, length, 0, 10); free(d, M_ACD); return error; } @@ -1447,7 +1438,6 @@ acd_send_key(device_t dev, struct dvd_authinfo *ai) static int acd_read_structure(device_t dev, struct dvd_struct *s) { - struct ata_device *atadev = device_get_softc(dev); struct dvd_miscauth *d; u_int16_t length; int8_t ccb[16]; @@ -1499,7 +1489,7 @@ acd_read_structure(device_t dev, struct dvd_struct *s) ccb[8] = (length >> 8) & 0xff; ccb[9] = length & 0xff; ccb[10] = s->agid << 6; - error = ata_atapicmd(atadev, ccb, (caddr_t)d, length, ATA_R_READ, 30); + error = ata_atapicmd(dev, ccb, (caddr_t)d, length, ATA_R_READ, 30); if (error) { free(d, M_ACD); return error; @@ -1585,48 +1575,44 @@ acd_blank(device_t dev, int blanktype) 0, 0, 0, 0, 0, 0, 0, 0 }; atadev->flags |= ATA_D_MEDIA_CHANGED; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int acd_prevent_allow(device_t dev, int lock) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_PREVENT_ALLOW, 0, 0, 0, lock, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int acd_start_stop(device_t dev, int start) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_START_STOP, 0, 0, 0, start, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int acd_pause_resume(device_t dev, int pause) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_PAUSE, 0, 0, 0, 0, 0, 0, 0, pause, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int acd_mode_sense(device_t dev, int page, caddr_t pagebuf, int pagesize) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_MODE_SENSE_BIG, 0, page, 0, 0, 0, 0, pagesize>>8, pagesize, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, pagebuf, pagesize, ATA_R_READ, 10); + error = ata_atapicmd(dev, ccb, pagebuf, pagesize, ATA_R_READ, 10); #ifdef ACD_DEBUG atapi_dump("acd: mode sense ", pagebuf, pagesize); #endif @@ -1636,7 +1622,6 @@ acd_mode_sense(device_t dev, int page, caddr_t pagebuf, int pagesize) static int acd_mode_select(device_t dev, caddr_t pagebuf, int pagesize) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_MODE_SELECT_BIG, 0x10, 0, 0, 0, 0, 0, pagesize>>8, pagesize, 0, 0, 0, 0, 0, 0, 0 }; @@ -1644,18 +1629,17 @@ acd_mode_select(device_t dev, caddr_t pagebuf, int pagesize) device_printf(dev, "modeselect pagesize=%d\n", pagesize); atapi_dump("mode select ", pagebuf, pagesize); #endif - return ata_atapicmd(atadev, ccb, pagebuf, pagesize, 0, 30); + return ata_atapicmd(dev, ccb, pagebuf, pagesize, 0, 30); } static int acd_set_speed(device_t dev, int rdspeed, int wrspeed) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_SET_SPEED, 0, rdspeed >> 8, rdspeed, wrspeed >> 8, wrspeed, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 30); if (!error) acd_get_cap(dev); return error; @@ -1685,25 +1669,23 @@ acd_get_cap(device_t dev) static int acd_read_format_caps(device_t dev, struct cdr_format_capacities *caps) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_READ_FORMAT_CAPACITIES, 0, 0, 0, 0, 0, 0, (sizeof(struct cdr_format_capacities) >> 8) & 0xff, sizeof(struct cdr_format_capacities) & 0xff, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, (caddr_t)caps, + return ata_atapicmd(dev, ccb, (caddr_t)caps, sizeof(struct cdr_format_capacities), ATA_R_READ, 30); } static int acd_format(device_t dev, struct cdr_format_params* params) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_FORMAT, 0x11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, (u_int8_t *)params, + error = ata_atapicmd(dev, ccb, (u_int8_t *)params, sizeof(struct cdr_format_params), 0, 30); return error; } @@ -1711,11 +1693,10 @@ acd_format(device_t dev, struct cdr_format_params* params) static int acd_test_ready(device_t dev) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_TEST_UNIT_READY, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static void diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c index 05923835070c..98d407223532 100644 --- a/sys/dev/ata/atapi-fd.c +++ b/sys/dev/ata/atapi-fd.c @@ -117,14 +117,13 @@ afd_attach(device_t dev) static int afd_detach(device_t dev) { - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct afd_softc *fdp = device_get_ivars(dev); /* detroy disk from the system so we dont get any further requests */ disk_destroy(fdp->disk); /* fail requests on the queue and any thats "in flight" for this device */ - ata_fail_requests(ch, dev); + ata_fail_requests(dev); /* dont leave anything behind */ device_set_ivars(dev, NULL); @@ -138,7 +137,7 @@ afd_shutdown(device_t dev) struct ata_device *atadev = device_get_softc(dev); if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) - ata_controlcmd(atadev, ATA_FLUSHCACHE, 0, 0, 0); + ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0); } static int @@ -305,7 +304,7 @@ afd_sense(device_t dev) /* get drive capabilities, some bugridden drives needs this repeated */ for (count = 0 ; count < 5 ; count++) { - if (!ata_atapicmd(atadev, ccb, (caddr_t)&fdp->cap, + if (!ata_atapicmd(dev, ccb, (caddr_t)&fdp->cap, sizeof(struct afd_cappage), ATA_R_READ, 30) && fdp->cap.page_code == ATAPI_REWRITEABLE_CAP_PAGE) { fdp->cap.cylinders = ntohs(fdp->cap.cylinders); @@ -326,17 +325,16 @@ afd_prevent_allow(device_t dev, int lock) if (!strncmp(atadev->param.model, "IOMEGA Clik!", 12)) return 0; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int afd_test_ready(device_t dev) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_TEST_UNIT_READY, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static void diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c index 3297a51068d2..8ba9e55a44bb 100644 --- a/sys/dev/ata/atapi-tape.c +++ b/sys/dev/ata/atapi-tape.c @@ -167,7 +167,6 @@ ast_attach(device_t dev) static int ast_detach(device_t dev) { - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); struct ast_softc *stp = device_get_ivars(dev); /* detroy devices from the system so we dont get any further requests */ @@ -175,7 +174,7 @@ ast_detach(device_t dev) destroy_dev(stp->dev2); /* fail requests on the queue and any thats "in flight" for this device */ - ata_fail_requests(ch, dev); + ata_fail_requests(dev); /* dont leave anything behind */ devstat_remove_entry(stp->stats); @@ -190,7 +189,7 @@ ast_shutdown(device_t dev) struct ata_device *atadev = device_get_softc(dev); if (atadev->param.support.command2 & ATA_SUPPORT_FLUSHCACHE) - ata_controlcmd(atadev, ATA_FLUSHCACHE, 0, 0, 0); + ata_controlcmd(dev, ATA_FLUSHCACHE, 0, 0, 0); } static int @@ -515,29 +514,26 @@ ast_sense(device_t dev) static int ast_mode_sense(device_t dev, int page, void *pagebuf, int pagesize) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_MODE_SENSE, 0x08, page, pagesize>>8, pagesize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, pagebuf, pagesize, ATA_R_READ, 10); + error = ata_atapicmd(dev, ccb, pagebuf, pagesize, ATA_R_READ, 10); return error; } static int ast_mode_select(device_t dev, void *pagebuf, int pagesize) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_MODE_SELECT, 0x10, 0, pagesize>>8, pagesize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, pagebuf, pagesize, 0, 10); + return ata_atapicmd(dev, ccb, pagebuf, pagesize, 0, 10); } static int ast_write_filemark(device_t dev, u_int8_t function) { - struct ata_device *atadev = device_get_softc(dev); struct ast_softc *stp = device_get_ivars(dev); int8_t ccb[16] = { ATAPI_WEOF, 0x01, 0, 0, function, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -553,7 +549,7 @@ ast_write_filemark(device_t dev, u_int8_t function) stp->flags |= F_FM_WRITTEN; } } - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10); if (error) return error; return ast_wait_dsc(dev, 10*60); @@ -562,12 +558,11 @@ ast_write_filemark(device_t dev, u_int8_t function) static int ast_read_position(device_t dev, int hard, struct ast_readposition *position) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_READ_POSITION, (hard ? 0x01 : 0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, (caddr_t)position, + error = ata_atapicmd(dev, ccb, (caddr_t)position, sizeof(struct ast_readposition), ATA_R_READ, 10); position->tape = ntohl(position->tape); position->host = ntohl(position->host); @@ -577,23 +572,21 @@ ast_read_position(device_t dev, int hard, struct ast_readposition *position) static int ast_space(device_t dev, u_int8_t function, int32_t count) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_SPACE, function, count>>16, count>>8, count, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 60*60); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 60*60); } static int ast_locate(device_t dev, int hard, u_int32_t pos) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_LOCATE, 0x01 | (hard ? 0x4 : 0), 0, pos>>24, pos>>16, pos>>8, pos, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10); if (error) return error; return ast_wait_dsc(dev, 60*60); @@ -602,17 +595,15 @@ ast_locate(device_t dev, int hard, u_int32_t pos) static int ast_prevent_allow(device_t dev, int lock) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_PREVENT_ALLOW, 0, 0, 0, lock, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int ast_load_unload(device_t dev, u_int8_t function) { - struct ata_device *atadev = device_get_softc(dev); struct ast_softc *stp = device_get_ivars(dev); int8_t ccb[16] = { ATAPI_START_STOP, 0x01, 0, 0, function, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -620,7 +611,7 @@ ast_load_unload(device_t dev, u_int8_t function) if ((function & ATAPI_SS_EJECT) && !stp->cap.eject) return 0; - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10); if (error) return error; tsleep((caddr_t)&error, PRIBIO, "astlu", 1 * hz); @@ -632,12 +623,11 @@ ast_load_unload(device_t dev, u_int8_t function) static int ast_rewind(device_t dev) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_REZERO, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 10); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 10); if (error) return error; return ast_wait_dsc(dev, 60*60); @@ -646,7 +636,6 @@ ast_rewind(device_t dev) static int ast_erase(device_t dev) { - struct ata_device *atadev = device_get_softc(dev); int8_t ccb[16] = { ATAPI_ERASE, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int error; @@ -654,32 +643,28 @@ ast_erase(device_t dev) if ((error = ast_rewind(dev))) return error; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 60*60); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 60*60); } static int ast_test_ready(device_t dev) { - struct ata_device *atadev = device_get_softc(dev); - int8_t ccb[16] = { ATAPI_TEST_UNIT_READY, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - return ata_atapicmd(atadev, ccb, NULL, 0, 0, 30); + return ata_atapicmd(dev, ccb, NULL, 0, 0, 30); } static int ast_wait_dsc(device_t dev, int timeout) { - struct ata_device *atadev = device_get_softc(dev); - int error = 0; int8_t ccb[16] = { ATAPI_POLL_DSC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; timeout *= hz; while (timeout > 0) { - error = ata_atapicmd(atadev, ccb, NULL, 0, 0, 0); + error = ata_atapicmd(dev, ccb, NULL, 0, 0, 0); if (error != EBUSY) break; tsleep(&error, PRIBIO, "atpwt", hz / 2); |
