Blame view

drivers/ata/sata_promise.c 30 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
  /*
   *  sata_promise.c - Promise SATA
   *
   *  Maintained by:  Jeff Garzik <jgarzik@pobox.com>
5595ddf98   Mikael Pettersson   sata_promise: cle...
5
   *		    Mikael Pettersson <mikpe@it.uu.se>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
8
9
10
   *  		    Please ALWAYS copy linux-ide@vger.kernel.org
   *		    on emails.
   *
   *  Copyright 2003-2004 Red Hat, Inc.
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
   *
af36d7f0d   Jeff Garzik   [libata] license ...
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2, or (at your option)
   *  any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; see the file COPYING.  If not, write to
   *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
   *
   *
   *  libata documentation is available via 'make {ps|pdf}docs',
   *  as Documentation/DocBook/libata.*
   *
   *  Hardware information only available under NDA.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
38
39
40
   *
   */
  
  #include <linux/kernel.h>
  #include <linux/module.h>
  #include <linux/pci.h>
  #include <linux/init.h>
  #include <linux/blkdev.h>
  #include <linux/delay.h>
  #include <linux/interrupt.h>
a9524a76f   Jeff Garzik   [libata] use dev_...
41
  #include <linux/device.h>
95006188c   Mikael Pettersson   sata_promise: ATA...
42
  #include <scsi/scsi.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  #include <scsi/scsi_host.h>
193515d51   Jeff Garzik   [libata] eliminat...
44
  #include <scsi/scsi_cmnd.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
  #include <linux/libata.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
48
  #include "sata_promise.h"
  
  #define DRV_NAME	"sata_promise"
c07a9c499   Mikael Pettersson   sata_promise: fix...
49
  #define DRV_VERSION	"2.12"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
  
  enum {
eca25dca1   Tejun Heo   libata: convert d...
52
  	PDC_MAX_PORTS		= 4,
0d5ff5667   Tejun Heo   libata: convert t...
53
  	PDC_MMIO_BAR		= 3,
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
54
  	PDC_MAX_PRD		= LIBATA_MAX_PRD - 1, /* -1 for ASIC PRD bug workaround */
0d5ff5667   Tejun Heo   libata: convert t...
55

821d22cdc   Mikael Pettersson   sata_promise: mmi...
56
57
58
59
60
61
62
63
64
  	/* host register offsets (from host->iomap[PDC_MMIO_BAR]) */
  	PDC_INT_SEQMASK		= 0x40,	/* Mask of asserted SEQ INTs */
  	PDC_FLASH_CTL		= 0x44, /* Flash control register */
  	PDC_SATA_PLUG_CSR	= 0x6C, /* SATA Plug control/status reg */
  	PDC2_SATA_PLUG_CSR	= 0x60, /* SATAII Plug control/status reg */
  	PDC_TBG_MODE		= 0x41C, /* TBG mode (not SATAII) */
  	PDC_SLEW_CTL		= 0x470, /* slew rate control reg (not SATAII) */
  
  	/* per-port ATA register offsets (from ap->ioaddr.cmd_addr) */
95006188c   Mikael Pettersson   sata_promise: ATA...
65
66
67
68
69
70
71
  	PDC_FEATURE		= 0x04, /* Feature/Error reg (per port) */
  	PDC_SECTOR_COUNT	= 0x08, /* Sector count reg (per port) */
  	PDC_SECTOR_NUMBER	= 0x0C, /* Sector number reg (per port) */
  	PDC_CYLINDER_LOW	= 0x10, /* Cylinder low reg (per port) */
  	PDC_CYLINDER_HIGH	= 0x14, /* Cylinder high reg (per port) */
  	PDC_DEVICE		= 0x18, /* Device/Head reg (per port) */
  	PDC_COMMAND		= 0x1C, /* Command/status reg (per port) */
73fd456b2   Mikael Pettersson   sata_promise: ATA...
72
  	PDC_ALTSTATUS		= 0x38, /* Alternate-status/device-control reg (per port) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  	PDC_PKT_SUBMIT		= 0x40, /* Command packet pointer addr */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
75
  	PDC_GLOBAL_CTL		= 0x48, /* Global control/status (per port) */
  	PDC_CTLSTAT		= 0x60,	/* IDE control and status (per port) */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
76
77
78
  
  	/* per-port SATA register offsets (from ap->ioaddr.scr_addr) */
  	PDC_PHYMODE4		= 0x14,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79

176efb054   Mikael Pettersson   sata_promise: dec...
80
81
82
83
84
85
86
87
88
89
90
91
92
  	/* PDC_GLOBAL_CTL bit definitions */
  	PDC_PH_ERR		= (1 <<  8), /* PCI error while loading packet */
  	PDC_SH_ERR		= (1 <<  9), /* PCI error while loading S/G table */
  	PDC_DH_ERR		= (1 << 10), /* PCI error while loading data */
  	PDC2_HTO_ERR		= (1 << 12), /* host bus timeout */
  	PDC2_ATA_HBA_ERR	= (1 << 13), /* error during SATA DATA FIS transmission */
  	PDC2_ATA_DMA_CNT_ERR	= (1 << 14), /* DMA DATA FIS size differs from S/G count */
  	PDC_OVERRUN_ERR		= (1 << 19), /* S/G byte count larger than HD requires */
  	PDC_UNDERRUN_ERR	= (1 << 20), /* S/G byte count less than HD requires */
  	PDC_DRIVE_ERR		= (1 << 21), /* drive error */
  	PDC_PCI_SYS_ERR		= (1 << 22), /* PCI system error */
  	PDC1_PCI_PARITY_ERR	= (1 << 23), /* PCI parity error (from SATA150 driver) */
  	PDC1_ERR_MASK		= PDC1_PCI_PARITY_ERR,
5796d1c4c   Jeff Garzik   [libata] Address ...
93
94
95
96
97
98
  	PDC2_ERR_MASK		= PDC2_HTO_ERR | PDC2_ATA_HBA_ERR |
  				  PDC2_ATA_DMA_CNT_ERR,
  	PDC_ERR_MASK		= PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR |
  				  PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR |
  				  PDC_DRIVE_ERR | PDC_PCI_SYS_ERR |
  				  PDC1_ERR_MASK | PDC2_ERR_MASK,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
  
  	board_2037x		= 0,	/* FastTrak S150 TX2plus */
eca25dca1   Tejun Heo   libata: convert d...
101
102
103
104
  	board_2037x_pata	= 1,	/* FastTrak S150 TX2plus PATA port */
  	board_20319		= 2,	/* FastTrak S150 TX4 */
  	board_20619		= 3,	/* FastTrak TX4000 */
  	board_2057x		= 4,	/* SATAII150 Tx2plus */
d0e580316   Mikael Pettersson   sata_promise: cle...
105
  	board_2057x_pata	= 5,	/* SATAII150 Tx2plus PATA port */
eca25dca1   Tejun Heo   libata: convert d...
106
  	board_40518		= 6,	/* SATAII150 Tx4 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107

6340f0196   Luke Kosewski   [libata sata_prom...
108
  	PDC_HAS_PATA		= (1 << 1), /* PDC20375/20575 has PATA */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109

95006188c   Mikael Pettersson   sata_promise: ATA...
110
111
112
113
114
115
116
117
118
  	/* Sequence counter control registers bit definitions */
  	PDC_SEQCNTRL_INT_MASK	= (1 << 5), /* Sequence Interrupt Mask */
  
  	/* Feature register values */
  	PDC_FEATURE_ATAPI_PIO	= 0x00, /* ATAPI data xfer by PIO */
  	PDC_FEATURE_ATAPI_DMA	= 0x01, /* ATAPI data xfer by DMA */
  
  	/* Device/Head register values */
  	PDC_DEVICE_SATA		= 0xE0, /* Device/Head value for SATA devices */
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
119
120
121
  	/* PDC_CTLSTAT bit definitions */
  	PDC_DMA_ENABLE		= (1 << 7),
  	PDC_IRQ_DISABLE		= (1 << 10),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
  	PDC_RESET		= (1 << 11), /* HDMA reset */
50630195b   Jeff Garzik   [libata] mark cer...
123

25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
124
  	PDC_COMMON_FLAGS	= ATA_FLAG_NO_LEGACY |
95006188c   Mikael Pettersson   sata_promise: ATA...
125
  				  ATA_FLAG_MMIO |
3d0a59c02   Jeff Garzik   [libata sata_prom...
126
  				  ATA_FLAG_PIO_POLLING,
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
127

eca25dca1   Tejun Heo   libata: convert d...
128
129
130
131
  	/* ap->flags bits */
  	PDC_FLAG_GEN_II		= (1 << 24),
  	PDC_FLAG_SATA_PATA	= (1 << 25), /* supports SATA + PATA */
  	PDC_FLAG_4_PORTS	= (1 << 26), /* 4 ports */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
132
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
134
135
136
  struct pdc_port_priv {
  	u8			*pkt;
  	dma_addr_t		pkt_dma;
  };
da3dbb17a   Tejun Heo   libata: make ->sc...
137
138
  static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val);
  static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val);
7715a6f9c   Mikael Pettersson   sata_promise: oth...
139
  static int pdc_ata_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
eca25dca1   Tejun Heo   libata: convert d...
140
141
  static int pdc_common_port_start(struct ata_port *ap);
  static int pdc_sata_port_start(struct ata_port *ap);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
142
  static void pdc_qc_prep(struct ata_queued_cmd *qc);
057ace5e7   Jeff Garzik   libata: const-ifi...
143
144
  static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
  static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
95006188c   Mikael Pettersson   sata_promise: ATA...
145
  static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
724114a57   Mikael Pettersson   sata_promise: sep...
146
  static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
  static void pdc_irq_clear(struct ata_port *ap);
9363c3825   Tejun Heo   libata: rename SF...
148
  static unsigned int pdc_qc_issue(struct ata_queued_cmd *qc);
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
149
  static void pdc_freeze(struct ata_port *ap);
c07a9c499   Mikael Pettersson   sata_promise: fix...
150
  static void pdc_sata_freeze(struct ata_port *ap);
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
151
  static void pdc_thaw(struct ata_port *ap);
c07a9c499   Mikael Pettersson   sata_promise: fix...
152
  static void pdc_sata_thaw(struct ata_port *ap);
a1efdaba2   Tejun Heo   libata: make rese...
153
  static void pdc_error_handler(struct ata_port *ap);
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
154
  static void pdc_post_internal_cmd(struct ata_queued_cmd *qc);
724114a57   Mikael Pettersson   sata_promise: sep...
155
156
  static int pdc_pata_cable_detect(struct ata_port *ap);
  static int pdc_sata_cable_detect(struct ata_port *ap);
374b18735   Jeff Garzik   [libata] update s...
157

193515d51   Jeff Garzik   [libata] eliminat...
158
  static struct scsi_host_template pdc_ata_sht = {
68d1d07b5   Tejun Heo   libata: implement...
159
  	ATA_BASE_SHT(DRV_NAME),
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
160
  	.sg_tablesize		= PDC_MAX_PRD,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161
  	.dma_boundary		= ATA_DMA_BOUNDARY,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
  };
029cfd6b7   Tejun Heo   libata: implement...
163
164
  static const struct ata_port_operations pdc_common_ops = {
  	.inherits		= &ata_sff_port_ops,
5682ed33a   Tejun Heo   libata: rename SF...
165
166
  	.sff_tf_load		= pdc_tf_load_mmio,
  	.sff_exec_command	= pdc_exec_command_mmio,
95006188c   Mikael Pettersson   sata_promise: ATA...
167
  	.check_atapi_dma	= pdc_check_atapi_dma,
95006188c   Mikael Pettersson   sata_promise: ATA...
168
  	.qc_prep		= pdc_qc_prep,
9363c3825   Tejun Heo   libata: rename SF...
169
  	.qc_issue		= pdc_qc_issue,
5682ed33a   Tejun Heo   libata: rename SF...
170
  	.sff_irq_clear		= pdc_irq_clear,
95006188c   Mikael Pettersson   sata_promise: ATA...
171

029cfd6b7   Tejun Heo   libata: implement...
172
  	.post_internal_cmd	= pdc_post_internal_cmd,
a1efdaba2   Tejun Heo   libata: make rese...
173
  	.error_handler		= pdc_error_handler,
95006188c   Mikael Pettersson   sata_promise: ATA...
174
  };
029cfd6b7   Tejun Heo   libata: implement...
175
176
177
  static struct ata_port_operations pdc_sata_ops = {
  	.inherits		= &pdc_common_ops,
  	.cable_detect		= pdc_sata_cable_detect,
c07a9c499   Mikael Pettersson   sata_promise: fix...
178
179
  	.freeze			= pdc_sata_freeze,
  	.thaw			= pdc_sata_thaw,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
181
  	.scr_read		= pdc_sata_scr_read,
  	.scr_write		= pdc_sata_scr_write,
eca25dca1   Tejun Heo   libata: convert d...
182
  	.port_start		= pdc_sata_port_start,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
  };
029cfd6b7   Tejun Heo   libata: implement...
184
185
186
187
188
  /* First-generation chips need a more restrictive ->check_atapi_dma op */
  static struct ata_port_operations pdc_old_sata_ops = {
  	.inherits		= &pdc_sata_ops,
  	.check_atapi_dma	= pdc_old_sata_check_atapi_dma,
  };
2cba582a4   Jeff Garzik   [libata sata_prom...
189

029cfd6b7   Tejun Heo   libata: implement...
190
191
192
  static struct ata_port_operations pdc_pata_ops = {
  	.inherits		= &pdc_common_ops,
  	.cable_detect		= pdc_pata_cable_detect,
5387373bf   Mikael Pettersson   sata_promise: new...
193
194
  	.freeze			= pdc_freeze,
  	.thaw			= pdc_thaw,
eca25dca1   Tejun Heo   libata: convert d...
195
  	.port_start		= pdc_common_port_start,
2cba582a4   Jeff Garzik   [libata sata_prom...
196
  };
98ac62def   Arjan van de Ven   [PATCH] mark seve...
197
  static const struct ata_port_info pdc_port_info[] = {
5595ddf98   Mikael Pettersson   sata_promise: cle...
198
  	[board_2037x] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199
  	{
eca25dca1   Tejun Heo   libata: convert d...
200
201
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  				  PDC_FLAG_SATA_PATA,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
203
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
204
  		.udma_mask	= ATA_UDMA6,
95006188c   Mikael Pettersson   sata_promise: ATA...
205
  		.port_ops	= &pdc_old_sata_ops,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
206
  	},
5595ddf98   Mikael Pettersson   sata_promise: cle...
207
  	[board_2037x_pata] =
eca25dca1   Tejun Heo   libata: convert d...
208
209
210
211
  	{
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
212
  		.udma_mask	= ATA_UDMA6,
eca25dca1   Tejun Heo   libata: convert d...
213
214
  		.port_ops	= &pdc_pata_ops,
  	},
5595ddf98   Mikael Pettersson   sata_promise: cle...
215
  	[board_20319] =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216
  	{
eca25dca1   Tejun Heo   libata: convert d...
217
218
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  				  PDC_FLAG_4_PORTS,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
221
  		.udma_mask	= ATA_UDMA6,
95006188c   Mikael Pettersson   sata_promise: ATA...
222
  		.port_ops	= &pdc_old_sata_ops,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
  	},
f497ba735   Tobias Lorenz   [libata sata_prom...
224

5595ddf98   Mikael Pettersson   sata_promise: cle...
225
  	[board_20619] =
f497ba735   Tobias Lorenz   [libata sata_prom...
226
  	{
eca25dca1   Tejun Heo   libata: convert d...
227
228
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
  				  PDC_FLAG_4_PORTS,
f497ba735   Tobias Lorenz   [libata sata_prom...
229
230
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
231
  		.udma_mask	= ATA_UDMA6,
2cba582a4   Jeff Garzik   [libata sata_prom...
232
  		.port_ops	= &pdc_pata_ops,
f497ba735   Tobias Lorenz   [libata sata_prom...
233
  	},
5a46fe89a   Yusuf Iskenderoglu   [libata] sata_pro...
234

5595ddf98   Mikael Pettersson   sata_promise: cle...
235
  	[board_2057x] =
6340f0196   Luke Kosewski   [libata sata_prom...
236
  	{
eca25dca1   Tejun Heo   libata: convert d...
237
238
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  				  PDC_FLAG_GEN_II | PDC_FLAG_SATA_PATA,
6340f0196   Luke Kosewski   [libata sata_prom...
239
240
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
241
  		.udma_mask	= ATA_UDMA6,
6340f0196   Luke Kosewski   [libata sata_prom...
242
243
  		.port_ops	= &pdc_sata_ops,
  	},
5595ddf98   Mikael Pettersson   sata_promise: cle...
244
  	[board_2057x_pata] =
eca25dca1   Tejun Heo   libata: convert d...
245
  	{
bb3122359   Jeff Garzik   [libata] sata_pro...
246
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
eca25dca1   Tejun Heo   libata: convert d...
247
248
249
  				  PDC_FLAG_GEN_II,
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
250
  		.udma_mask	= ATA_UDMA6,
eca25dca1   Tejun Heo   libata: convert d...
251
252
  		.port_ops	= &pdc_pata_ops,
  	},
5595ddf98   Mikael Pettersson   sata_promise: cle...
253
  	[board_40518] =
6340f0196   Luke Kosewski   [libata sata_prom...
254
  	{
eca25dca1   Tejun Heo   libata: convert d...
255
256
  		.flags		= PDC_COMMON_FLAGS | ATA_FLAG_SATA |
  				  PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS,
6340f0196   Luke Kosewski   [libata sata_prom...
257
258
  		.pio_mask	= 0x1f, /* pio0-4 */
  		.mwdma_mask	= 0x07, /* mwdma0-2 */
469248abf   Jeff Garzik   [libata] Clean up...
259
  		.udma_mask	= ATA_UDMA6,
6340f0196   Luke Kosewski   [libata sata_prom...
260
261
  		.port_ops	= &pdc_sata_ops,
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262
  };
3b7d697df   Jeff Garzik   [libata] constify...
263
  static const struct pci_device_id pdc_ata_pci_tbl[] = {
54bb3a94b   Jeff Garzik   [libata] Use new ...
264
  	{ PCI_VDEVICE(PROMISE, 0x3371), board_2037x },
54bb3a94b   Jeff Garzik   [libata] Use new ...
265
266
267
  	{ PCI_VDEVICE(PROMISE, 0x3373), board_2037x },
  	{ PCI_VDEVICE(PROMISE, 0x3375), board_2037x },
  	{ PCI_VDEVICE(PROMISE, 0x3376), board_2037x },
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
268
269
  	{ PCI_VDEVICE(PROMISE, 0x3570), board_2057x },
  	{ PCI_VDEVICE(PROMISE, 0x3571), board_2057x },
54bb3a94b   Jeff Garzik   [libata] Use new ...
270
  	{ PCI_VDEVICE(PROMISE, 0x3574), board_2057x },
d324d4627   Mikael Pettersson   [PATCH] sata_prom...
271
  	{ PCI_VDEVICE(PROMISE, 0x3577), board_2057x },
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
272
  	{ PCI_VDEVICE(PROMISE, 0x3d73), board_2057x },
54bb3a94b   Jeff Garzik   [libata] Use new ...
273
  	{ PCI_VDEVICE(PROMISE, 0x3d75), board_2057x },
54bb3a94b   Jeff Garzik   [libata] Use new ...
274
275
276
  
  	{ PCI_VDEVICE(PROMISE, 0x3318), board_20319 },
  	{ PCI_VDEVICE(PROMISE, 0x3319), board_20319 },
7f9992a23   Mikael Pettersson   sata_promise: Fas...
277
278
  	{ PCI_VDEVICE(PROMISE, 0x3515), board_40518 },
  	{ PCI_VDEVICE(PROMISE, 0x3519), board_40518 },
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
279
  	{ PCI_VDEVICE(PROMISE, 0x3d17), board_40518 },
54bb3a94b   Jeff Garzik   [libata] Use new ...
280
281
282
  	{ PCI_VDEVICE(PROMISE, 0x3d18), board_40518 },
  
  	{ PCI_VDEVICE(PROMISE, 0x6629), board_20619 },
f497ba735   Tobias Lorenz   [libata sata_prom...
283

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
  	{ }	/* terminate list */
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
286
287
288
289
290
291
  static struct pci_driver pdc_ata_pci_driver = {
  	.name			= DRV_NAME,
  	.id_table		= pdc_ata_pci_tbl,
  	.probe			= pdc_ata_init_one,
  	.remove			= ata_pci_remove_one,
  };
724114a57   Mikael Pettersson   sata_promise: sep...
292
  static int pdc_common_port_start(struct ata_port *ap)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
  {
cca3974e4   Jeff Garzik   libata: Grand ren...
294
  	struct device *dev = ap->host->dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
296
297
298
299
300
  	struct pdc_port_priv *pp;
  	int rc;
  
  	rc = ata_port_start(ap);
  	if (rc)
  		return rc;
24dc5f33e   Tejun Heo   libata: update li...
301
302
303
  	pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
  	if (!pp)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304

24dc5f33e   Tejun Heo   libata: update li...
305
306
307
  	pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
  	if (!pp->pkt)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
309
  
  	ap->private_data = pp;
724114a57   Mikael Pettersson   sata_promise: sep...
310
311
312
313
314
  	return 0;
  }
  
  static int pdc_sata_port_start(struct ata_port *ap)
  {
724114a57   Mikael Pettersson   sata_promise: sep...
315
316
317
318
319
  	int rc;
  
  	rc = pdc_common_port_start(ap);
  	if (rc)
  		return rc;
599b7202c   Mikael Pettersson   [PATCH] sata_prom...
320
  	/* fix up PHYMODE4 align timing */
eca25dca1   Tejun Heo   libata: convert d...
321
  	if (ap->flags & PDC_FLAG_GEN_II) {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
322
  		void __iomem *sata_mmio = ap->ioaddr.scr_addr;
599b7202c   Mikael Pettersson   [PATCH] sata_prom...
323
  		unsigned int tmp;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
324
  		tmp = readl(sata_mmio + PDC_PHYMODE4);
599b7202c   Mikael Pettersson   [PATCH] sata_prom...
325
  		tmp = (tmp & ~3) | 1;	/* set bits 1:0 = 0:1 */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
326
  		writel(tmp, sata_mmio + PDC_PHYMODE4);
599b7202c   Mikael Pettersson   [PATCH] sata_prom...
327
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
331
  static void pdc_reset_port(struct ata_port *ap)
  {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
332
  	void __iomem *ata_ctlstat_mmio = ap->ioaddr.cmd_addr + PDC_CTLSTAT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
334
335
336
  	unsigned int i;
  	u32 tmp;
  
  	for (i = 11; i > 0; i--) {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
337
  		tmp = readl(ata_ctlstat_mmio);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338
339
340
341
342
343
  		if (tmp & PDC_RESET)
  			break;
  
  		udelay(100);
  
  		tmp |= PDC_RESET;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
344
  		writel(tmp, ata_ctlstat_mmio);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
347
  	}
  
  	tmp &= ~PDC_RESET;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
348
349
  	writel(tmp, ata_ctlstat_mmio);
  	readl(ata_ctlstat_mmio);	/* flush */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
  }
724114a57   Mikael Pettersson   sata_promise: sep...
351
  static int pdc_pata_cable_detect(struct ata_port *ap)
2cba582a4   Jeff Garzik   [libata sata_prom...
352
  {
d3fb4e8dd   Jeff Garzik   [libata sata_prom...
353
  	u8 tmp;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
354
  	void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
d3fb4e8dd   Jeff Garzik   [libata sata_prom...
355

821d22cdc   Mikael Pettersson   sata_promise: mmi...
356
  	tmp = readb(ata_mmio + PDC_CTLSTAT + 3);
724114a57   Mikael Pettersson   sata_promise: sep...
357
358
359
360
361
362
363
  	if (tmp & 0x01)
  		return ATA_CBL_PATA40;
  	return ATA_CBL_PATA80;
  }
  
  static int pdc_sata_cable_detect(struct ata_port *ap)
  {
e2a9752a2   Alan Cox   sata_promise: Swi...
364
  	return ATA_CBL_SATA;
d3fb4e8dd   Jeff Garzik   [libata sata_prom...
365
  }
2cba582a4   Jeff Garzik   [libata sata_prom...
366

da3dbb17a   Tejun Heo   libata: make ->sc...
367
  static int pdc_sata_scr_read(struct ata_port *ap, unsigned int sc_reg, u32 *val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
  {
724114a57   Mikael Pettersson   sata_promise: sep...
369
  	if (sc_reg > SCR_CONTROL)
da3dbb17a   Tejun Heo   libata: make ->sc...
370
371
372
  		return -EINVAL;
  	*val = readl(ap->ioaddr.scr_addr + (sc_reg * 4));
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
373
  }
da3dbb17a   Tejun Heo   libata: make ->sc...
374
  static int pdc_sata_scr_write(struct ata_port *ap, unsigned int sc_reg, u32 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
375
  {
724114a57   Mikael Pettersson   sata_promise: sep...
376
  	if (sc_reg > SCR_CONTROL)
da3dbb17a   Tejun Heo   libata: make ->sc...
377
  		return -EINVAL;
0d5ff5667   Tejun Heo   libata: convert t...
378
  	writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
da3dbb17a   Tejun Heo   libata: make ->sc...
379
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
380
  }
fba6edbd3   Mikael Pettersson   sata_promise: han...
381
  static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
95006188c   Mikael Pettersson   sata_promise: ATA...
382
  {
4113bb6b6   Mikael Pettersson   sata_promise: iss...
383
384
385
386
387
388
  	struct ata_port *ap = qc->ap;
  	dma_addr_t sg_table = ap->prd_dma;
  	unsigned int cdb_len = qc->dev->cdb_len;
  	u8 *cdb = qc->cdb;
  	struct pdc_port_priv *pp = ap->private_data;
  	u8 *buf = pp->pkt;
826cd156d   Al Viro   libata annotations
389
  	__le32 *buf32 = (__le32 *) buf;
46a671430   Tejun Heo   sata_promise: mak...
390
  	unsigned int dev_sel, feature;
95006188c   Mikael Pettersson   sata_promise: ATA...
391
392
393
394
  
  	/* set control bits (byte 0), zero delay seq id (byte 3),
  	 * and seq id (byte 2)
  	 */
fba6edbd3   Mikael Pettersson   sata_promise: han...
395
  	switch (qc->tf.protocol) {
0dc36888d   Tejun Heo   libata: rename AT...
396
  	case ATAPI_PROT_DMA:
fba6edbd3   Mikael Pettersson   sata_promise: han...
397
398
399
400
401
  		if (!(qc->tf.flags & ATA_TFLAG_WRITE))
  			buf32[0] = cpu_to_le32(PDC_PKT_READ);
  		else
  			buf32[0] = 0;
  		break;
0dc36888d   Tejun Heo   libata: rename AT...
402
  	case ATAPI_PROT_NODATA:
fba6edbd3   Mikael Pettersson   sata_promise: han...
403
404
405
406
407
408
  		buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
  		break;
  	default:
  		BUG();
  		break;
  	}
95006188c   Mikael Pettersson   sata_promise: ATA...
409
410
  	buf32[1] = cpu_to_le32(sg_table);	/* S/G table addr */
  	buf32[2] = 0;				/* no next-packet */
4113bb6b6   Mikael Pettersson   sata_promise: iss...
411
  	/* select drive */
46a671430   Tejun Heo   sata_promise: mak...
412
  	if (sata_scr_valid(&ap->link))
4113bb6b6   Mikael Pettersson   sata_promise: iss...
413
  		dev_sel = PDC_DEVICE_SATA;
46a671430   Tejun Heo   sata_promise: mak...
414
415
  	else
  		dev_sel = qc->tf.device;
4113bb6b6   Mikael Pettersson   sata_promise: iss...
416
417
418
419
420
421
  	buf[12] = (1 << 5) | ATA_REG_DEVICE;
  	buf[13] = dev_sel;
  	buf[14] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_CLEAR_BSY;
  	buf[15] = dev_sel; /* once more, waiting for BSY to clear */
  
  	buf[16] = (1 << 5) | ATA_REG_NSECT;
46a671430   Tejun Heo   sata_promise: mak...
422
  	buf[17] = qc->tf.nsect;
4113bb6b6   Mikael Pettersson   sata_promise: iss...
423
  	buf[18] = (1 << 5) | ATA_REG_LBAL;
46a671430   Tejun Heo   sata_promise: mak...
424
  	buf[19] = qc->tf.lbal;
4113bb6b6   Mikael Pettersson   sata_promise: iss...
425
426
  
  	/* set feature and byte counter registers */
0dc36888d   Tejun Heo   libata: rename AT...
427
  	if (qc->tf.protocol != ATAPI_PROT_DMA)
4113bb6b6   Mikael Pettersson   sata_promise: iss...
428
  		feature = PDC_FEATURE_ATAPI_PIO;
46a671430   Tejun Heo   sata_promise: mak...
429
  	else
4113bb6b6   Mikael Pettersson   sata_promise: iss...
430
  		feature = PDC_FEATURE_ATAPI_DMA;
46a671430   Tejun Heo   sata_promise: mak...
431

4113bb6b6   Mikael Pettersson   sata_promise: iss...
432
433
434
  	buf[20] = (1 << 5) | ATA_REG_FEATURE;
  	buf[21] = feature;
  	buf[22] = (1 << 5) | ATA_REG_BYTEL;
46a671430   Tejun Heo   sata_promise: mak...
435
  	buf[23] = qc->tf.lbam;
4113bb6b6   Mikael Pettersson   sata_promise: iss...
436
  	buf[24] = (1 << 5) | ATA_REG_BYTEH;
46a671430   Tejun Heo   sata_promise: mak...
437
  	buf[25] = qc->tf.lbah;
4113bb6b6   Mikael Pettersson   sata_promise: iss...
438
439
440
  
  	/* send ATAPI packet command 0xA0 */
  	buf[26] = (1 << 5) | ATA_REG_CMD;
46a671430   Tejun Heo   sata_promise: mak...
441
  	buf[27] = qc->tf.command;
4113bb6b6   Mikael Pettersson   sata_promise: iss...
442
443
444
445
  
  	/* select drive and check DRQ */
  	buf[28] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_WAIT_DRDY;
  	buf[29] = dev_sel;
95006188c   Mikael Pettersson   sata_promise: ATA...
446
447
  	/* we can represent cdb lengths 2/4/6/8/10/12/14/16 */
  	BUG_ON(cdb_len & ~0x1E);
4113bb6b6   Mikael Pettersson   sata_promise: iss...
448
449
450
  	/* append the CDB as the final part */
  	buf[30] = (((cdb_len >> 1) & 7) << 5) | ATA_REG_DATA | PDC_LAST_REG;
  	memcpy(buf+31, cdb, cdb_len);
95006188c   Mikael Pettersson   sata_promise: ATA...
451
  }
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
  /**
   *	pdc_fill_sg - Fill PCI IDE PRD table
   *	@qc: Metadata associated with taskfile to be transferred
   *
   *	Fill PCI IDE PRD (scatter-gather) table with segments
   *	associated with the current disk command.
   *	Make sure hardware does not choke on it.
   *
   *	LOCKING:
   *	spin_lock_irqsave(host lock)
   *
   */
  static void pdc_fill_sg(struct ata_queued_cmd *qc)
  {
  	struct ata_port *ap = qc->ap;
  	struct scatterlist *sg;
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
468
  	const u32 SG_COUNT_ASIC_BUG = 41*4;
ff2aeb1eb   Tejun Heo   libata: convert t...
469
470
  	unsigned int si, idx;
  	u32 len;
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
471
472
473
  
  	if (!(qc->flags & ATA_QCFLAG_DMAMAP))
  		return;
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
474
  	idx = 0;
ff2aeb1eb   Tejun Heo   libata: convert t...
475
  	for_each_sg(qc->sg, sg, qc->n_elem, si) {
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
476
  		u32 addr, offset;
6903c0f7e   Harvey Harrison   ata: fix sparse w...
477
  		u32 sg_len;
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
  
  		/* determine if physical DMA addr spans 64K boundary.
  		 * Note h/w doesn't support 64-bit, so we unconditionally
  		 * truncate dma_addr_t to u32.
  		 */
  		addr = (u32) sg_dma_address(sg);
  		sg_len = sg_dma_len(sg);
  
  		while (sg_len) {
  			offset = addr & 0xffff;
  			len = sg_len;
  			if ((offset + sg_len) > 0x10000)
  				len = 0x10000 - offset;
  
  			ap->prd[idx].addr = cpu_to_le32(addr);
  			ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff);
  			VPRINTK("PRD[%u] = (0x%X, 0x%X)
  ", idx, addr, len);
  
  			idx++;
  			sg_len -= len;
  			addr += len;
  		}
  	}
ff2aeb1eb   Tejun Heo   libata: convert t...
502
  	len = le32_to_cpu(ap->prd[idx - 1].flags_len);
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
503

ff2aeb1eb   Tejun Heo   libata: convert t...
504
505
  	if (len > SG_COUNT_ASIC_BUG) {
  		u32 addr;
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
506

ff2aeb1eb   Tejun Heo   libata: convert t...
507
508
  		VPRINTK("Splitting last PRD.
  ");
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
509

ff2aeb1eb   Tejun Heo   libata: convert t...
510
511
512
513
  		addr = le32_to_cpu(ap->prd[idx - 1].addr);
  		ap->prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG);
  		VPRINTK("PRD[%u] = (0x%X, 0x%X)
  ", idx - 1, addr, SG_COUNT_ASIC_BUG);
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
514

ff2aeb1eb   Tejun Heo   libata: convert t...
515
516
517
518
519
520
  		addr = addr + len - SG_COUNT_ASIC_BUG;
  		len = SG_COUNT_ASIC_BUG;
  		ap->prd[idx].addr = cpu_to_le32(addr);
  		ap->prd[idx].flags_len = cpu_to_le32(len);
  		VPRINTK("PRD[%u] = (0x%X, 0x%X)
  ", idx, addr, len);
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
521

ff2aeb1eb   Tejun Heo   libata: convert t...
522
  		idx++;
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
523
  	}
ff2aeb1eb   Tejun Heo   libata: convert t...
524
525
  
  	ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
526
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
527
528
529
530
531
532
533
534
535
536
  static void pdc_qc_prep(struct ata_queued_cmd *qc)
  {
  	struct pdc_port_priv *pp = qc->ap->private_data;
  	unsigned int i;
  
  	VPRINTK("ENTER
  ");
  
  	switch (qc->tf.protocol) {
  	case ATA_PROT_DMA:
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
537
  		pdc_fill_sg(qc);
7715a6f9c   Mikael Pettersson   sata_promise: oth...
538
  		/*FALLTHROUGH*/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
539
540
541
  	case ATA_PROT_NODATA:
  		i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
  				   qc->dev->devno, pp->pkt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
542
543
544
545
  		if (qc->tf.flags & ATA_TFLAG_LBA48)
  			i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
  		else
  			i = pdc_prep_lba28(&qc->tf, pp->pkt, i);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
546
547
  		pdc_pkt_footer(&qc->tf, pp->pkt, i);
  		break;
0dc36888d   Tejun Heo   libata: rename AT...
548
  	case ATAPI_PROT_PIO:
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
549
  		pdc_fill_sg(qc);
95006188c   Mikael Pettersson   sata_promise: ATA...
550
  		break;
0dc36888d   Tejun Heo   libata: rename AT...
551
  	case ATAPI_PROT_DMA:
b9ccd4a90   Mikael Pettersson   sata_promise: ASI...
552
  		pdc_fill_sg(qc);
fba6edbd3   Mikael Pettersson   sata_promise: han...
553
  		/*FALLTHROUGH*/
0dc36888d   Tejun Heo   libata: rename AT...
554
  	case ATAPI_PROT_NODATA:
fba6edbd3   Mikael Pettersson   sata_promise: han...
555
  		pdc_atapi_pkt(qc);
95006188c   Mikael Pettersson   sata_promise: ATA...
556
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
557
558
559
560
  	default:
  		break;
  	}
  }
c07a9c499   Mikael Pettersson   sata_promise: fix...
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  static int pdc_is_sataii_tx4(unsigned long flags)
  {
  	const unsigned long mask = PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS;
  	return (flags & mask) == mask;
  }
  
  static unsigned int pdc_port_no_to_ata_no(unsigned int port_no,
  					  int is_sataii_tx4)
  {
  	static const unsigned char sataii_tx4_port_remap[4] = { 3, 1, 0, 2};
  	return is_sataii_tx4 ? sataii_tx4_port_remap[port_no] : port_no;
  }
  
  static unsigned int pdc_sata_nr_ports(const struct ata_port *ap)
  {
  	return (ap->flags & PDC_FLAG_4_PORTS) ? 4 : 2;
  }
  
  static unsigned int pdc_sata_ata_port_to_ata_no(const struct ata_port *ap)
  {
  	const struct ata_host *host = ap->host;
  	unsigned int nr_ports = pdc_sata_nr_ports(ap);
  	unsigned int i;
7715a6f9c   Mikael Pettersson   sata_promise: oth...
584
  	for (i = 0; i < nr_ports && host->ports[i] != ap; ++i)
c07a9c499   Mikael Pettersson   sata_promise: fix...
585
586
587
588
589
590
591
592
593
  		;
  	BUG_ON(i >= nr_ports);
  	return pdc_port_no_to_ata_no(i, pdc_is_sataii_tx4(ap->flags));
  }
  
  static unsigned int pdc_sata_hotplug_offset(const struct ata_port *ap)
  {
  	return (ap->flags & PDC_FLAG_GEN_II) ? PDC2_SATA_PLUG_CSR : PDC_SATA_PLUG_CSR;
  }
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
594
595
  static void pdc_freeze(struct ata_port *ap)
  {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
596
  	void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
597
  	u32 tmp;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
598
  	tmp = readl(ata_mmio + PDC_CTLSTAT);
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
599
600
  	tmp |= PDC_IRQ_DISABLE;
  	tmp &= ~PDC_DMA_ENABLE;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
601
602
  	writel(tmp, ata_mmio + PDC_CTLSTAT);
  	readl(ata_mmio + PDC_CTLSTAT); /* flush */
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
603
  }
c07a9c499   Mikael Pettersson   sata_promise: fix...
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
  static void pdc_sata_freeze(struct ata_port *ap)
  {
  	struct ata_host *host = ap->host;
  	void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  	unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap);
  	unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap);
  	u32 hotplug_status;
  
  	/* Disable hotplug events on this port.
  	 *
  	 * Locking:
  	 * 1) hotplug register accesses must be serialised via host->lock
  	 * 2) ap->lock == &ap->host->lock
  	 * 3) ->freeze() and ->thaw() are called with ap->lock held
  	 */
  	hotplug_status = readl(host_mmio + hotplug_offset);
  	hotplug_status |= 0x11 << (ata_no + 16);
  	writel(hotplug_status, host_mmio + hotplug_offset);
  	readl(host_mmio + hotplug_offset); /* flush */
  
  	pdc_freeze(ap);
  }
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
626
627
  static void pdc_thaw(struct ata_port *ap)
  {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
628
  	void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
629
630
631
  	u32 tmp;
  
  	/* clear IRQ */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
632
  	readl(ata_mmio + PDC_COMMAND);
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
633
634
  
  	/* turn IRQ back on */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
635
  	tmp = readl(ata_mmio + PDC_CTLSTAT);
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
636
  	tmp &= ~PDC_IRQ_DISABLE;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
637
638
  	writel(tmp, ata_mmio + PDC_CTLSTAT);
  	readl(ata_mmio + PDC_CTLSTAT); /* flush */
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
639
  }
c07a9c499   Mikael Pettersson   sata_promise: fix...
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
  static void pdc_sata_thaw(struct ata_port *ap)
  {
  	struct ata_host *host = ap->host;
  	void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
  	unsigned int hotplug_offset = pdc_sata_hotplug_offset(ap);
  	unsigned int ata_no = pdc_sata_ata_port_to_ata_no(ap);
  	u32 hotplug_status;
  
  	pdc_thaw(ap);
  
  	/* Enable hotplug events on this port.
  	 * Locking: see pdc_sata_freeze().
  	 */
  	hotplug_status = readl(host_mmio + hotplug_offset);
  	hotplug_status |= 0x11 << ata_no;
  	hotplug_status &= ~(0x11 << (ata_no + 16));
  	writel(hotplug_status, host_mmio + hotplug_offset);
  	readl(host_mmio + hotplug_offset); /* flush */
  }
a1efdaba2   Tejun Heo   libata: make rese...
659
  static void pdc_error_handler(struct ata_port *ap)
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
660
  {
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
661
662
  	if (!(ap->pflags & ATA_PFLAG_FROZEN))
  		pdc_reset_port(ap);
a1efdaba2   Tejun Heo   libata: make rese...
663
  	ata_std_error_handler(ap);
724114a57   Mikael Pettersson   sata_promise: sep...
664
  }
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
665
666
667
  static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
  {
  	struct ata_port *ap = qc->ap;
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
668
  	/* make DMA engine forget about the failed command */
a51d644af   Tejun Heo   libata: improve A...
669
  	if (qc->flags & ATA_QCFLAG_FAILED)
25b93d81b   Mikael Pettersson   [PATCH] sata_prom...
670
671
  		pdc_reset_port(ap);
  }
176efb054   Mikael Pettersson   sata_promise: dec...
672
673
674
  static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
  			   u32 port_status, u32 err_mask)
  {
9af5c9c97   Tejun Heo   libata-link: intr...
675
  	struct ata_eh_info *ehi = &ap->link.eh_info;
176efb054   Mikael Pettersson   sata_promise: dec...
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
  	unsigned int ac_err_mask = 0;
  
  	ata_ehi_clear_desc(ehi);
  	ata_ehi_push_desc(ehi, "port_status 0x%08x", port_status);
  	port_status &= err_mask;
  
  	if (port_status & PDC_DRIVE_ERR)
  		ac_err_mask |= AC_ERR_DEV;
  	if (port_status & (PDC_OVERRUN_ERR | PDC_UNDERRUN_ERR))
  		ac_err_mask |= AC_ERR_HSM;
  	if (port_status & (PDC2_ATA_HBA_ERR | PDC2_ATA_DMA_CNT_ERR))
  		ac_err_mask |= AC_ERR_ATA_BUS;
  	if (port_status & (PDC_PH_ERR | PDC_SH_ERR | PDC_DH_ERR | PDC2_HTO_ERR
  			   | PDC_PCI_SYS_ERR | PDC1_PCI_PARITY_ERR))
  		ac_err_mask |= AC_ERR_HOST_BUS;
936fd7328   Tejun Heo   libata-link: link...
691
  	if (sata_scr_valid(&ap->link)) {
da3dbb17a   Tejun Heo   libata: make ->sc...
692
693
694
695
696
  		u32 serror;
  
  		pdc_sata_scr_read(ap, SCR_ERROR, &serror);
  		ehi->serror |= serror;
  	}
ce2d3abc2   Mikael Pettersson   sata_promise: fix...
697

176efb054   Mikael Pettersson   sata_promise: dec...
698
  	qc->err_mask |= ac_err_mask;
ce2d3abc2   Mikael Pettersson   sata_promise: fix...
699
700
  
  	pdc_reset_port(ap);
8ffcfd9d0   Mikael Pettersson   sata_promise: fix...
701
702
  
  	ata_port_abort(ap);
176efb054   Mikael Pettersson   sata_promise: dec...
703
  }
7715a6f9c   Mikael Pettersson   sata_promise: oth...
704
705
  static unsigned int pdc_host_intr(struct ata_port *ap,
  				  struct ata_queued_cmd *qc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
706
  {
a22e2eb07   Albert Lee   [PATCH] libata: m...
707
  	unsigned int handled = 0;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
708
  	void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
176efb054   Mikael Pettersson   sata_promise: dec...
709
710
711
  	u32 port_status, err_mask;
  
  	err_mask = PDC_ERR_MASK;
eca25dca1   Tejun Heo   libata: convert d...
712
  	if (ap->flags & PDC_FLAG_GEN_II)
176efb054   Mikael Pettersson   sata_promise: dec...
713
714
715
  		err_mask &= ~PDC1_ERR_MASK;
  	else
  		err_mask &= ~PDC2_ERR_MASK;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
716
  	port_status = readl(ata_mmio + PDC_GLOBAL_CTL);
176efb054   Mikael Pettersson   sata_promise: dec...
717
718
719
  	if (unlikely(port_status & err_mask)) {
  		pdc_error_intr(ap, qc, port_status, err_mask);
  		return 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
720
721
722
723
724
  	}
  
  	switch (qc->tf.protocol) {
  	case ATA_PROT_DMA:
  	case ATA_PROT_NODATA:
0dc36888d   Tejun Heo   libata: rename AT...
725
726
  	case ATAPI_PROT_DMA:
  	case ATAPI_PROT_NODATA:
a22e2eb07   Albert Lee   [PATCH] libata: m...
727
728
  		qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
  		ata_qc_complete(qc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
729
730
  		handled = 1;
  		break;
d0e580316   Mikael Pettersson   sata_promise: cle...
731
  	default:
ee500aabf   Albert Lee   [PATCH] libata: i...
732
733
  		ap->stats.idle_irq++;
  		break;
d0e580316   Mikael Pettersson   sata_promise: cle...
734
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
735

ee500aabf   Albert Lee   [PATCH] libata: i...
736
  	return handled;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737
738
739
740
  }
  
  static void pdc_irq_clear(struct ata_port *ap)
  {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
741
  	void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
742

821d22cdc   Mikael Pettersson   sata_promise: mmi...
743
  	readl(ata_mmio + PDC_COMMAND);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
744
  }
5796d1c4c   Jeff Garzik   [libata] Address ...
745
  static irqreturn_t pdc_interrupt(int irq, void *dev_instance)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
746
  {
cca3974e4   Jeff Garzik   libata: Grand ren...
747
  	struct ata_host *host = dev_instance;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
748
749
750
751
  	struct ata_port *ap;
  	u32 mask = 0;
  	unsigned int i, tmp;
  	unsigned int handled = 0;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
752
  	void __iomem *host_mmio;
a77720ad0   Mikael Pettersson   sata_promise: SAT...
753
754
755
  	unsigned int hotplug_offset, ata_no;
  	u32 hotplug_status;
  	int is_sataii_tx4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
756
757
758
  
  	VPRINTK("ENTER
  ");
0d5ff5667   Tejun Heo   libata: convert t...
759
  	if (!host || !host->iomap[PDC_MMIO_BAR]) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
760
761
762
763
  		VPRINTK("QUICK EXIT
  ");
  		return IRQ_NONE;
  	}
821d22cdc   Mikael Pettersson   sata_promise: mmi...
764
  	host_mmio = host->iomap[PDC_MMIO_BAR];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
765

c07a9c499   Mikael Pettersson   sata_promise: fix...
766
  	spin_lock(&host->lock);
a77720ad0   Mikael Pettersson   sata_promise: SAT...
767
768
769
770
771
  	/* read and clear hotplug flags for all ports */
  	if (host->ports[0]->flags & PDC_FLAG_GEN_II)
  		hotplug_offset = PDC2_SATA_PLUG_CSR;
  	else
  		hotplug_offset = PDC_SATA_PLUG_CSR;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
772
  	hotplug_status = readl(host_mmio + hotplug_offset);
a77720ad0   Mikael Pettersson   sata_promise: SAT...
773
  	if (hotplug_status & 0xff)
821d22cdc   Mikael Pettersson   sata_promise: mmi...
774
  		writel(hotplug_status | 0xff, host_mmio + hotplug_offset);
a77720ad0   Mikael Pettersson   sata_promise: SAT...
775
  	hotplug_status &= 0xff;	/* clear uninteresting bits */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
776
  	/* reading should also clear interrupts */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
777
  	mask = readl(host_mmio + PDC_INT_SEQMASK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
778

a77720ad0   Mikael Pettersson   sata_promise: SAT...
779
  	if (mask == 0xffffffff && hotplug_status == 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
780
781
  		VPRINTK("QUICK EXIT 2
  ");
c07a9c499   Mikael Pettersson   sata_promise: fix...
782
  		goto done_irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
783
  	}
6340f0196   Luke Kosewski   [libata sata_prom...
784

7715a6f9c   Mikael Pettersson   sata_promise: oth...
785
  	mask &= 0xffff;		/* only 16 SEQIDs possible */
a77720ad0   Mikael Pettersson   sata_promise: SAT...
786
  	if (mask == 0 && hotplug_status == 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
787
788
  		VPRINTK("QUICK EXIT 3
  ");
6340f0196   Luke Kosewski   [libata sata_prom...
789
  		goto done_irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
790
  	}
821d22cdc   Mikael Pettersson   sata_promise: mmi...
791
  	writel(mask, host_mmio + PDC_INT_SEQMASK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
792

a77720ad0   Mikael Pettersson   sata_promise: SAT...
793
  	is_sataii_tx4 = pdc_is_sataii_tx4(host->ports[0]->flags);
cca3974e4   Jeff Garzik   libata: Grand ren...
794
  	for (i = 0; i < host->n_ports; i++) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
795
796
  		VPRINTK("port %u
  ", i);
cca3974e4   Jeff Garzik   libata: Grand ren...
797
  		ap = host->ports[i];
a77720ad0   Mikael Pettersson   sata_promise: SAT...
798
799
800
801
802
803
  
  		/* check for a plug or unplug event */
  		ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
  		tmp = hotplug_status & (0x11 << ata_no);
  		if (tmp && ap &&
  		    !(ap->flags & ATA_FLAG_DISABLED)) {
9af5c9c97   Tejun Heo   libata-link: intr...
804
  			struct ata_eh_info *ehi = &ap->link.eh_info;
a77720ad0   Mikael Pettersson   sata_promise: SAT...
805
806
807
808
809
810
811
812
813
  			ata_ehi_clear_desc(ehi);
  			ata_ehi_hotplugged(ehi);
  			ata_ehi_push_desc(ehi, "hotplug_status %#x", tmp);
  			ata_port_freeze(ap);
  			++handled;
  			continue;
  		}
  
  		/* check for a packet interrupt */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
814
  		tmp = mask & (1 << (i + 1));
c13895037   Tejun Heo   [PATCH] fix atapi...
815
  		if (tmp && ap &&
029f5468b   Jeff Garzik   Merge branch 'ups...
816
  		    !(ap->flags & ATA_FLAG_DISABLED)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
817
  			struct ata_queued_cmd *qc;
9af5c9c97   Tejun Heo   libata-link: intr...
818
  			qc = ata_qc_from_tag(ap, ap->link.active_tag);
e50362ecc   Albert Lee   [PATCH] libata: i...
819
  			if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
820
821
822
  				handled += pdc_host_intr(ap, qc);
  		}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
823
824
  	VPRINTK("EXIT
  ");
6340f0196   Luke Kosewski   [libata sata_prom...
825
  done_irq:
cca3974e4   Jeff Garzik   libata: Grand ren...
826
  	spin_unlock(&host->lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
827
828
  	return IRQ_RETVAL(handled);
  }
7715a6f9c   Mikael Pettersson   sata_promise: oth...
829
  static void pdc_packet_start(struct ata_queued_cmd *qc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
830
831
832
  {
  	struct ata_port *ap = qc->ap;
  	struct pdc_port_priv *pp = ap->private_data;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
833
834
  	void __iomem *host_mmio = ap->host->iomap[PDC_MMIO_BAR];
  	void __iomem *ata_mmio = ap->ioaddr.cmd_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
835
836
837
838
839
  	unsigned int port_no = ap->port_no;
  	u8 seq = (u8) (port_no + 1);
  
  	VPRINTK("ENTER, ap %p
  ", ap);
821d22cdc   Mikael Pettersson   sata_promise: mmi...
840
841
  	writel(0x00000001, host_mmio + (seq * 4));
  	readl(host_mmio + (seq * 4));	/* flush */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
842
843
844
  
  	pp->pkt[2] = seq;
  	wmb();			/* flush PRD, pkt writes */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
845
846
  	writel(pp->pkt_dma, ata_mmio + PDC_PKT_SUBMIT);
  	readl(ata_mmio + PDC_PKT_SUBMIT); /* flush */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
847
  }
9363c3825   Tejun Heo   libata: rename SF...
848
  static unsigned int pdc_qc_issue(struct ata_queued_cmd *qc)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
849
850
  {
  	switch (qc->tf.protocol) {
0dc36888d   Tejun Heo   libata: rename AT...
851
  	case ATAPI_PROT_NODATA:
fba6edbd3   Mikael Pettersson   sata_promise: han...
852
853
854
  		if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
  			break;
  		/*FALLTHROUGH*/
51b94d2a5   Tejun Heo   sata_promise: use...
855
856
857
858
  	case ATA_PROT_NODATA:
  		if (qc->tf.flags & ATA_TFLAG_POLLING)
  			break;
  		/*FALLTHROUGH*/
0dc36888d   Tejun Heo   libata: rename AT...
859
  	case ATAPI_PROT_DMA:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
860
  	case ATA_PROT_DMA:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
861
862
  		pdc_packet_start(qc);
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
863
864
865
  	default:
  		break;
  	}
9363c3825   Tejun Heo   libata: rename SF...
866
  	return ata_sff_qc_issue(qc);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
867
  }
057ace5e7   Jeff Garzik   libata: const-ifi...
868
  static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
869
  {
0dc36888d   Tejun Heo   libata: rename AT...
870
  	WARN_ON(tf->protocol == ATA_PROT_DMA || tf->protocol == ATAPI_PROT_DMA);
9363c3825   Tejun Heo   libata: rename SF...
871
  	ata_sff_tf_load(ap, tf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
872
  }
5796d1c4c   Jeff Garzik   [libata] Address ...
873
874
  static void pdc_exec_command_mmio(struct ata_port *ap,
  				  const struct ata_taskfile *tf)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
875
  {
0dc36888d   Tejun Heo   libata: rename AT...
876
  	WARN_ON(tf->protocol == ATA_PROT_DMA || tf->protocol == ATAPI_PROT_DMA);
9363c3825   Tejun Heo   libata: rename SF...
877
  	ata_sff_exec_command(ap, tf);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
878
  }
95006188c   Mikael Pettersson   sata_promise: ATA...
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
  static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
  {
  	u8 *scsicmd = qc->scsicmd->cmnd;
  	int pio = 1; /* atapi dma off by default */
  
  	/* Whitelist commands that may use DMA. */
  	switch (scsicmd[0]) {
  	case WRITE_12:
  	case WRITE_10:
  	case WRITE_6:
  	case READ_12:
  	case READ_10:
  	case READ_6:
  	case 0xad: /* READ_DVD_STRUCTURE */
  	case 0xbe: /* READ_CD */
  		pio = 0;
  	}
  	/* -45150 (FFFF4FA2) to -1 (FFFFFFFF) shall use PIO mode */
  	if (scsicmd[0] == WRITE_10) {
5796d1c4c   Jeff Garzik   [libata] Address ...
898
899
900
901
902
  		unsigned int lba =
  			(scsicmd[2] << 24) |
  			(scsicmd[3] << 16) |
  			(scsicmd[4] << 8) |
  			scsicmd[5];
95006188c   Mikael Pettersson   sata_promise: ATA...
903
904
905
906
907
  		if (lba >= 0xFFFF4FA2)
  			pio = 1;
  	}
  	return pio;
  }
724114a57   Mikael Pettersson   sata_promise: sep...
908
  static int pdc_old_sata_check_atapi_dma(struct ata_queued_cmd *qc)
95006188c   Mikael Pettersson   sata_promise: ATA...
909
  {
95006188c   Mikael Pettersson   sata_promise: ATA...
910
  	/* First generation chips cannot use ATAPI DMA on SATA ports */
724114a57   Mikael Pettersson   sata_promise: sep...
911
  	return 1;
95006188c   Mikael Pettersson   sata_promise: ATA...
912
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
913

eca25dca1   Tejun Heo   libata: convert d...
914
915
  static void pdc_ata_setup_port(struct ata_port *ap,
  			       void __iomem *base, void __iomem *scr_addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
916
  {
eca25dca1   Tejun Heo   libata: convert d...
917
918
919
920
921
922
923
924
925
926
927
928
929
930
  	ap->ioaddr.cmd_addr		= base;
  	ap->ioaddr.data_addr		= base;
  	ap->ioaddr.feature_addr		=
  	ap->ioaddr.error_addr		= base + 0x4;
  	ap->ioaddr.nsect_addr		= base + 0x8;
  	ap->ioaddr.lbal_addr		= base + 0xc;
  	ap->ioaddr.lbam_addr		= base + 0x10;
  	ap->ioaddr.lbah_addr		= base + 0x14;
  	ap->ioaddr.device_addr		= base + 0x18;
  	ap->ioaddr.command_addr		=
  	ap->ioaddr.status_addr		= base + 0x1c;
  	ap->ioaddr.altstatus_addr	=
  	ap->ioaddr.ctl_addr		= base + 0x38;
  	ap->ioaddr.scr_addr		= scr_addr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
931
  }
eca25dca1   Tejun Heo   libata: convert d...
932
  static void pdc_host_init(struct ata_host *host)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
933
  {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
934
  	void __iomem *host_mmio = host->iomap[PDC_MMIO_BAR];
eca25dca1   Tejun Heo   libata: convert d...
935
  	int is_gen2 = host->ports[0]->flags & PDC_FLAG_GEN_II;
d324d4627   Mikael Pettersson   [PATCH] sata_prom...
936
  	int hotplug_offset;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
937
  	u32 tmp;
eca25dca1   Tejun Heo   libata: convert d...
938
  	if (is_gen2)
d324d4627   Mikael Pettersson   [PATCH] sata_prom...
939
940
941
  		hotplug_offset = PDC2_SATA_PLUG_CSR;
  	else
  		hotplug_offset = PDC_SATA_PLUG_CSR;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
942
943
944
945
946
  	/*
  	 * Except for the hotplug stuff, this is voodoo from the
  	 * Promise driver.  Label this entire section
  	 * "TODO: figure out why we do this"
  	 */
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
947
  	/* enable BMR_BURST, maybe change FIFO_SHD to 8 dwords */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
948
  	tmp = readl(host_mmio + PDC_FLASH_CTL);
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
949
  	tmp |= 0x02000;	/* bit 13 (enable bmr burst) */
eca25dca1   Tejun Heo   libata: convert d...
950
  	if (!is_gen2)
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
951
  		tmp |= 0x10000;	/* bit 16 (fifo threshold at 8 dw) */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
952
  	writel(tmp, host_mmio + PDC_FLASH_CTL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
953
954
  
  	/* clear plug/unplug flags for all ports */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
955
956
  	tmp = readl(host_mmio + hotplug_offset);
  	writel(tmp | 0xff, host_mmio + hotplug_offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
957

a77720ad0   Mikael Pettersson   sata_promise: SAT...
958
  	/* unmask plug/unplug ints */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
959
960
  	tmp = readl(host_mmio + hotplug_offset);
  	writel(tmp & ~0xff0000, host_mmio + hotplug_offset);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
961

b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
962
  	/* don't initialise TBG or SLEW on 2nd generation chips */
eca25dca1   Tejun Heo   libata: convert d...
963
  	if (is_gen2)
b2d1eee1e   Mikael Pettersson   [PATCH] sata_prom...
964
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
965
  	/* reduce TBG clock to 133 Mhz. */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
966
  	tmp = readl(host_mmio + PDC_TBG_MODE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
967
968
  	tmp &= ~0x30000; /* clear bit 17, 16*/
  	tmp |= 0x10000;  /* set bit 17:16 = 0:1 */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
969
  	writel(tmp, host_mmio + PDC_TBG_MODE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
970

821d22cdc   Mikael Pettersson   sata_promise: mmi...
971
  	readl(host_mmio + PDC_TBG_MODE);	/* flush */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
972
973
974
  	msleep(10);
  
  	/* adjust slew rate control register. */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
975
  	tmp = readl(host_mmio + PDC_SLEW_CTL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
976
977
  	tmp &= 0xFFFFF03F; /* clear bit 11 ~ 6 */
  	tmp  |= 0x00000900; /* set bit 11-9 = 100b , bit 8-6 = 100 */
821d22cdc   Mikael Pettersson   sata_promise: mmi...
978
  	writel(tmp, host_mmio + PDC_SLEW_CTL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
979
  }
5796d1c4c   Jeff Garzik   [libata] Address ...
980
981
  static int pdc_ata_init_one(struct pci_dev *pdev,
  			    const struct pci_device_id *ent)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
982
983
  {
  	static int printed_version;
eca25dca1   Tejun Heo   libata: convert d...
984
985
986
  	const struct ata_port_info *pi = &pdc_port_info[ent->driver_data];
  	const struct ata_port_info *ppi[PDC_MAX_PORTS];
  	struct ata_host *host;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
987
  	void __iomem *host_mmio;
eca25dca1   Tejun Heo   libata: convert d...
988
  	int n_ports, i, rc;
5ac2fe575   Mikael Pettersson   sata_promise: SAT...
989
  	int is_sataii_tx4;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
990
991
  
  	if (!printed_version++)
a9524a76f   Jeff Garzik   [libata] use dev_...
992
993
  		dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
994

eca25dca1   Tejun Heo   libata: convert d...
995
  	/* enable and acquire resources */
24dc5f33e   Tejun Heo   libata: update li...
996
  	rc = pcim_enable_device(pdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
997
998
  	if (rc)
  		return rc;
0d5ff5667   Tejun Heo   libata: convert t...
999
1000
  	rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
  	if (rc == -EBUSY)
24dc5f33e   Tejun Heo   libata: update li...
1001
  		pcim_pin_device(pdev);
0d5ff5667   Tejun Heo   libata: convert t...
1002
  	if (rc)
24dc5f33e   Tejun Heo   libata: update li...
1003
  		return rc;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
1004
  	host_mmio = pcim_iomap_table(pdev)[PDC_MMIO_BAR];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1005

eca25dca1   Tejun Heo   libata: convert d...
1006
1007
1008
1009
1010
1011
  	/* determine port configuration and setup host */
  	n_ports = 2;
  	if (pi->flags & PDC_FLAG_4_PORTS)
  		n_ports = 4;
  	for (i = 0; i < n_ports; i++)
  		ppi[i] = pi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1012

eca25dca1   Tejun Heo   libata: convert d...
1013
  	if (pi->flags & PDC_FLAG_SATA_PATA) {
821d22cdc   Mikael Pettersson   sata_promise: mmi...
1014
  		u8 tmp = readb(host_mmio + PDC_FLASH_CTL + 1);
d0e580316   Mikael Pettersson   sata_promise: cle...
1015
  		if (!(tmp & 0x80))
eca25dca1   Tejun Heo   libata: convert d...
1016
  			ppi[n_ports++] = pi + 1;
eca25dca1   Tejun Heo   libata: convert d...
1017
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1018

eca25dca1   Tejun Heo   libata: convert d...
1019
1020
1021
1022
  	host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
  	if (!host) {
  		dev_printk(KERN_ERR, &pdev->dev, "failed to allocate host
  ");
24dc5f33e   Tejun Heo   libata: update li...
1023
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1024
  	}
eca25dca1   Tejun Heo   libata: convert d...
1025
  	host->iomap = pcim_iomap_table(pdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1026

d0e580316   Mikael Pettersson   sata_promise: cle...
1027
  	is_sataii_tx4 = pdc_is_sataii_tx4(pi->flags);
5ac2fe575   Mikael Pettersson   sata_promise: SAT...
1028
  	for (i = 0; i < host->n_ports; i++) {
cbcdd8759   Tejun Heo   libata: implement...
1029
  		struct ata_port *ap = host->ports[i];
d0e580316   Mikael Pettersson   sata_promise: cle...
1030
  		unsigned int ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
821d22cdc   Mikael Pettersson   sata_promise: mmi...
1031
  		unsigned int ata_offset = 0x200 + ata_no * 0x80;
cbcdd8759   Tejun Heo   libata: implement...
1032
  		unsigned int scr_offset = 0x400 + ata_no * 0x100;
821d22cdc   Mikael Pettersson   sata_promise: mmi...
1033
  		pdc_ata_setup_port(ap, host_mmio + ata_offset, host_mmio + scr_offset);
cbcdd8759   Tejun Heo   libata: implement...
1034
1035
  
  		ata_port_pbar_desc(ap, PDC_MMIO_BAR, -1, "mmio");
821d22cdc   Mikael Pettersson   sata_promise: mmi...
1036
  		ata_port_pbar_desc(ap, PDC_MMIO_BAR, ata_offset, "ata");
5ac2fe575   Mikael Pettersson   sata_promise: SAT...
1037
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1038
1039
  
  	/* initialize adapter */
eca25dca1   Tejun Heo   libata: convert d...
1040
  	pdc_host_init(host);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1041

eca25dca1   Tejun Heo   libata: convert d...
1042
1043
1044
1045
1046
1047
  	rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
  	if (rc)
  		return rc;
  	rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
  	if (rc)
  		return rc;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1048

eca25dca1   Tejun Heo   libata: convert d...
1049
1050
1051
1052
  	/* start host, request IRQ and attach */
  	pci_set_master(pdev);
  	return ata_host_activate(host, pdev->irq, pdc_interrupt, IRQF_SHARED,
  				 &pdc_ata_sht);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1053
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1054
1055
  static int __init pdc_ata_init(void)
  {
b7887196e   Pavel Roskin   [PATCH] libata: r...
1056
  	return pci_register_driver(&pdc_ata_pci_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1057
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1058
1059
1060
1061
  static void __exit pdc_ata_exit(void)
  {
  	pci_unregister_driver(&pdc_ata_pci_driver);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1062
  MODULE_AUTHOR("Jeff Garzik");
f497ba735   Tobias Lorenz   [libata sata_prom...
1063
  MODULE_DESCRIPTION("Promise ATA TX2/TX4/TX4000 low-level driver");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1064
1065
1066
1067
1068
1069
  MODULE_LICENSE("GPL");
  MODULE_DEVICE_TABLE(pci, pdc_ata_pci_tbl);
  MODULE_VERSION(DRV_VERSION);
  
  module_init(pdc_ata_init);
  module_exit(pdc_ata_exit);