Commit 4e953a216265f8646360fa909bdc87ea4bf446b3
Committed by
Jens Axboe
1 parent
ee4a7b6874
Exists in
master
and in
39 other branches
drivers/block/umem: trim trailing whitespace
Signed-off-by: Jeff Garzik <jeff@garzik.org>
Showing 2 changed files with 18 additions and 18 deletions Inline Diff
drivers/block/umem.c
1 | /* | 1 | /* |
2 | * mm.c - Micro Memory(tm) PCI memory board block device driver - v2.3 | 2 | * mm.c - Micro Memory(tm) PCI memory board block device driver - v2.3 |
3 | * | 3 | * |
4 | * (C) 2001 San Mehat <nettwerk@valinux.com> | 4 | * (C) 2001 San Mehat <nettwerk@valinux.com> |
5 | * (C) 2001 Johannes Erdfelt <jerdfelt@valinux.com> | 5 | * (C) 2001 Johannes Erdfelt <jerdfelt@valinux.com> |
6 | * (C) 2001 NeilBrown <neilb@cse.unsw.edu.au> | 6 | * (C) 2001 NeilBrown <neilb@cse.unsw.edu.au> |
7 | * | 7 | * |
8 | * This driver for the Micro Memory PCI Memory Module with Battery Backup | 8 | * This driver for the Micro Memory PCI Memory Module with Battery Backup |
9 | * is Copyright Micro Memory Inc 2001-2002. All rights reserved. | 9 | * is Copyright Micro Memory Inc 2001-2002. All rights reserved. |
10 | * | 10 | * |
11 | * This driver is released to the public under the terms of the | 11 | * This driver is released to the public under the terms of the |
12 | * GNU GENERAL PUBLIC LICENSE version 2 | 12 | * GNU GENERAL PUBLIC LICENSE version 2 |
13 | * See the file COPYING for details. | 13 | * See the file COPYING for details. |
14 | * | 14 | * |
15 | * This driver provides a standard block device interface for Micro Memory(tm) | 15 | * This driver provides a standard block device interface for Micro Memory(tm) |
16 | * PCI based RAM boards. | 16 | * PCI based RAM boards. |
17 | * 10/05/01: Phap Nguyen - Rebuilt the driver | 17 | * 10/05/01: Phap Nguyen - Rebuilt the driver |
18 | * 10/22/01: Phap Nguyen - v2.1 Added disk partitioning | 18 | * 10/22/01: Phap Nguyen - v2.1 Added disk partitioning |
19 | * 29oct2001:NeilBrown - Use make_request_fn instead of request_fn | 19 | * 29oct2001:NeilBrown - Use make_request_fn instead of request_fn |
20 | * - use stand disk partitioning (so fdisk works). | 20 | * - use stand disk partitioning (so fdisk works). |
21 | * 08nov2001:NeilBrown - change driver name from "mm" to "umem" | 21 | * 08nov2001:NeilBrown - change driver name from "mm" to "umem" |
22 | * - incorporate into main kernel | 22 | * - incorporate into main kernel |
23 | * 08apr2002:NeilBrown - Move some of interrupt handle to tasklet | 23 | * 08apr2002:NeilBrown - Move some of interrupt handle to tasklet |
24 | * - use spin_lock_bh instead of _irq | 24 | * - use spin_lock_bh instead of _irq |
25 | * - Never block on make_request. queue | 25 | * - Never block on make_request. queue |
26 | * bh's instead. | 26 | * bh's instead. |
27 | * - unregister umem from devfs at mod unload | 27 | * - unregister umem from devfs at mod unload |
28 | * - Change version to 2.3 | 28 | * - Change version to 2.3 |
29 | * 07Nov2001:Phap Nguyen - Select pci read command: 06, 12, 15 (Decimal) | 29 | * 07Nov2001:Phap Nguyen - Select pci read command: 06, 12, 15 (Decimal) |
30 | * 07Jan2002: P. Nguyen - Used PCI Memory Write & Invalidate for DMA | 30 | * 07Jan2002: P. Nguyen - Used PCI Memory Write & Invalidate for DMA |
31 | * 15May2002:NeilBrown - convert to bio for 2.5 | 31 | * 15May2002:NeilBrown - convert to bio for 2.5 |
32 | * 17May2002:NeilBrown - remove init_mem initialisation. Instead detect | 32 | * 17May2002:NeilBrown - remove init_mem initialisation. Instead detect |
33 | * - a sequence of writes that cover the card, and | 33 | * - a sequence of writes that cover the card, and |
34 | * - set initialised bit then. | 34 | * - set initialised bit then. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | //#define DEBUG /* uncomment if you want debugging info (pr_debug) */ | 37 | //#define DEBUG /* uncomment if you want debugging info (pr_debug) */ |
38 | #include <linux/fs.h> | 38 | #include <linux/fs.h> |
39 | #include <linux/bio.h> | 39 | #include <linux/bio.h> |
40 | #include <linux/kernel.h> | 40 | #include <linux/kernel.h> |
41 | #include <linux/mm.h> | 41 | #include <linux/mm.h> |
42 | #include <linux/mman.h> | 42 | #include <linux/mman.h> |
43 | #include <linux/ioctl.h> | 43 | #include <linux/ioctl.h> |
44 | #include <linux/module.h> | 44 | #include <linux/module.h> |
45 | #include <linux/init.h> | 45 | #include <linux/init.h> |
46 | #include <linux/interrupt.h> | 46 | #include <linux/interrupt.h> |
47 | #include <linux/timer.h> | 47 | #include <linux/timer.h> |
48 | #include <linux/pci.h> | 48 | #include <linux/pci.h> |
49 | #include <linux/slab.h> | 49 | #include <linux/slab.h> |
50 | #include <linux/dma-mapping.h> | 50 | #include <linux/dma-mapping.h> |
51 | 51 | ||
52 | #include <linux/fcntl.h> /* O_ACCMODE */ | 52 | #include <linux/fcntl.h> /* O_ACCMODE */ |
53 | #include <linux/hdreg.h> /* HDIO_GETGEO */ | 53 | #include <linux/hdreg.h> /* HDIO_GETGEO */ |
54 | 54 | ||
55 | #include "umem.h" | 55 | #include "umem.h" |
56 | 56 | ||
57 | #include <asm/uaccess.h> | 57 | #include <asm/uaccess.h> |
58 | #include <asm/io.h> | 58 | #include <asm/io.h> |
59 | 59 | ||
60 | #define MM_MAXCARDS 4 | 60 | #define MM_MAXCARDS 4 |
61 | #define MM_RAHEAD 2 /* two sectors */ | 61 | #define MM_RAHEAD 2 /* two sectors */ |
62 | #define MM_BLKSIZE 1024 /* 1k blocks */ | 62 | #define MM_BLKSIZE 1024 /* 1k blocks */ |
63 | #define MM_HARDSECT 512 /* 512-byte hardware sectors */ | 63 | #define MM_HARDSECT 512 /* 512-byte hardware sectors */ |
64 | #define MM_SHIFT 6 /* max 64 partitions on 4 cards */ | 64 | #define MM_SHIFT 6 /* max 64 partitions on 4 cards */ |
65 | 65 | ||
66 | /* | 66 | /* |
67 | * Version Information | 67 | * Version Information |
68 | */ | 68 | */ |
69 | 69 | ||
70 | #define DRIVER_NAME "umem" | 70 | #define DRIVER_NAME "umem" |
71 | #define DRIVER_VERSION "v2.3" | 71 | #define DRIVER_VERSION "v2.3" |
72 | #define DRIVER_AUTHOR "San Mehat, Johannes Erdfelt, NeilBrown" | 72 | #define DRIVER_AUTHOR "San Mehat, Johannes Erdfelt, NeilBrown" |
73 | #define DRIVER_DESC "Micro Memory(tm) PCI memory board block driver" | 73 | #define DRIVER_DESC "Micro Memory(tm) PCI memory board block driver" |
74 | 74 | ||
75 | static int debug; | 75 | static int debug; |
76 | /* #define HW_TRACE(x) writeb(x,cards[0].csr_remap + MEMCTRLSTATUS_MAGIC) */ | 76 | /* #define HW_TRACE(x) writeb(x,cards[0].csr_remap + MEMCTRLSTATUS_MAGIC) */ |
77 | #define HW_TRACE(x) | 77 | #define HW_TRACE(x) |
78 | 78 | ||
79 | #define DEBUG_LED_ON_TRANSFER 0x01 | 79 | #define DEBUG_LED_ON_TRANSFER 0x01 |
80 | #define DEBUG_BATTERY_POLLING 0x02 | 80 | #define DEBUG_BATTERY_POLLING 0x02 |
81 | 81 | ||
82 | module_param(debug, int, 0644); | 82 | module_param(debug, int, 0644); |
83 | MODULE_PARM_DESC(debug, "Debug bitmask"); | 83 | MODULE_PARM_DESC(debug, "Debug bitmask"); |
84 | 84 | ||
85 | static int pci_read_cmd = 0x0C; /* Read Multiple */ | 85 | static int pci_read_cmd = 0x0C; /* Read Multiple */ |
86 | module_param(pci_read_cmd, int, 0); | 86 | module_param(pci_read_cmd, int, 0); |
87 | MODULE_PARM_DESC(pci_read_cmd, "PCI read command"); | 87 | MODULE_PARM_DESC(pci_read_cmd, "PCI read command"); |
88 | 88 | ||
89 | static int pci_write_cmd = 0x0F; /* Write and Invalidate */ | 89 | static int pci_write_cmd = 0x0F; /* Write and Invalidate */ |
90 | module_param(pci_write_cmd, int, 0); | 90 | module_param(pci_write_cmd, int, 0); |
91 | MODULE_PARM_DESC(pci_write_cmd, "PCI write command"); | 91 | MODULE_PARM_DESC(pci_write_cmd, "PCI write command"); |
92 | 92 | ||
93 | static int pci_cmds; | 93 | static int pci_cmds; |
94 | 94 | ||
95 | static int major_nr; | 95 | static int major_nr; |
96 | 96 | ||
97 | #include <linux/blkdev.h> | 97 | #include <linux/blkdev.h> |
98 | #include <linux/blkpg.h> | 98 | #include <linux/blkpg.h> |
99 | 99 | ||
100 | struct cardinfo { | 100 | struct cardinfo { |
101 | struct pci_dev *dev; | 101 | struct pci_dev *dev; |
102 | 102 | ||
103 | unsigned char __iomem *csr_remap; | 103 | unsigned char __iomem *csr_remap; |
104 | unsigned int mm_size; /* size in kbytes */ | 104 | unsigned int mm_size; /* size in kbytes */ |
105 | 105 | ||
106 | unsigned int init_size; /* initial segment, in sectors, | 106 | unsigned int init_size; /* initial segment, in sectors, |
107 | * that we know to | 107 | * that we know to |
108 | * have been written | 108 | * have been written |
109 | */ | 109 | */ |
110 | struct bio *bio, *currentbio, **biotail; | 110 | struct bio *bio, *currentbio, **biotail; |
111 | int current_idx; | 111 | int current_idx; |
112 | sector_t current_sector; | 112 | sector_t current_sector; |
113 | 113 | ||
114 | struct request_queue *queue; | 114 | struct request_queue *queue; |
115 | 115 | ||
116 | struct mm_page { | 116 | struct mm_page { |
117 | dma_addr_t page_dma; | 117 | dma_addr_t page_dma; |
118 | struct mm_dma_desc *desc; | 118 | struct mm_dma_desc *desc; |
119 | int cnt, headcnt; | 119 | int cnt, headcnt; |
120 | struct bio *bio, **biotail; | 120 | struct bio *bio, **biotail; |
121 | int idx; | 121 | int idx; |
122 | } mm_pages[2]; | 122 | } mm_pages[2]; |
123 | #define DESC_PER_PAGE ((PAGE_SIZE*2)/sizeof(struct mm_dma_desc)) | 123 | #define DESC_PER_PAGE ((PAGE_SIZE*2)/sizeof(struct mm_dma_desc)) |
124 | 124 | ||
125 | int Active, Ready; | 125 | int Active, Ready; |
126 | 126 | ||
127 | struct tasklet_struct tasklet; | 127 | struct tasklet_struct tasklet; |
128 | unsigned int dma_status; | 128 | unsigned int dma_status; |
129 | 129 | ||
130 | struct { | 130 | struct { |
131 | int good; | 131 | int good; |
132 | int warned; | 132 | int warned; |
133 | unsigned long last_change; | 133 | unsigned long last_change; |
134 | } battery[2]; | 134 | } battery[2]; |
135 | 135 | ||
136 | spinlock_t lock; | 136 | spinlock_t lock; |
137 | int check_batteries; | 137 | int check_batteries; |
138 | 138 | ||
139 | int flags; | 139 | int flags; |
140 | }; | 140 | }; |
141 | 141 | ||
142 | static struct cardinfo cards[MM_MAXCARDS]; | 142 | static struct cardinfo cards[MM_MAXCARDS]; |
143 | static struct block_device_operations mm_fops; | 143 | static struct block_device_operations mm_fops; |
144 | static struct timer_list battery_timer; | 144 | static struct timer_list battery_timer; |
145 | 145 | ||
146 | static int num_cards = 0; | 146 | static int num_cards = 0; |
147 | 147 | ||
148 | static struct gendisk *mm_gendisk[MM_MAXCARDS]; | 148 | static struct gendisk *mm_gendisk[MM_MAXCARDS]; |
149 | 149 | ||
150 | static void check_batteries(struct cardinfo *card); | 150 | static void check_batteries(struct cardinfo *card); |
151 | 151 | ||
152 | /* | 152 | /* |
153 | ----------------------------------------------------------------------------------- | 153 | ----------------------------------------------------------------------------------- |
154 | -- get_userbit | 154 | -- get_userbit |
155 | ----------------------------------------------------------------------------------- | 155 | ----------------------------------------------------------------------------------- |
156 | */ | 156 | */ |
157 | static int get_userbit(struct cardinfo *card, int bit) | 157 | static int get_userbit(struct cardinfo *card, int bit) |
158 | { | 158 | { |
159 | unsigned char led; | 159 | unsigned char led; |
160 | 160 | ||
161 | led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); | 161 | led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); |
162 | return led & bit; | 162 | return led & bit; |
163 | } | 163 | } |
164 | /* | 164 | /* |
165 | ----------------------------------------------------------------------------------- | 165 | ----------------------------------------------------------------------------------- |
166 | -- set_userbit | 166 | -- set_userbit |
167 | ----------------------------------------------------------------------------------- | 167 | ----------------------------------------------------------------------------------- |
168 | */ | 168 | */ |
169 | static int set_userbit(struct cardinfo *card, int bit, unsigned char state) | 169 | static int set_userbit(struct cardinfo *card, int bit, unsigned char state) |
170 | { | 170 | { |
171 | unsigned char led; | 171 | unsigned char led; |
172 | 172 | ||
173 | led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); | 173 | led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); |
174 | if (state) | 174 | if (state) |
175 | led |= bit; | 175 | led |= bit; |
176 | else | 176 | else |
177 | led &= ~bit; | 177 | led &= ~bit; |
178 | writeb(led, card->csr_remap + MEMCTRLCMD_LEDCTRL); | 178 | writeb(led, card->csr_remap + MEMCTRLCMD_LEDCTRL); |
179 | 179 | ||
180 | return 0; | 180 | return 0; |
181 | } | 181 | } |
182 | /* | 182 | /* |
183 | ----------------------------------------------------------------------------------- | 183 | ----------------------------------------------------------------------------------- |
184 | -- set_led | 184 | -- set_led |
185 | ----------------------------------------------------------------------------------- | 185 | ----------------------------------------------------------------------------------- |
186 | */ | 186 | */ |
187 | /* | 187 | /* |
188 | * NOTE: For the power LED, use the LED_POWER_* macros since they differ | 188 | * NOTE: For the power LED, use the LED_POWER_* macros since they differ |
189 | */ | 189 | */ |
190 | static void set_led(struct cardinfo *card, int shift, unsigned char state) | 190 | static void set_led(struct cardinfo *card, int shift, unsigned char state) |
191 | { | 191 | { |
192 | unsigned char led; | 192 | unsigned char led; |
193 | 193 | ||
194 | led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); | 194 | led = readb(card->csr_remap + MEMCTRLCMD_LEDCTRL); |
195 | if (state == LED_FLIP) | 195 | if (state == LED_FLIP) |
196 | led ^= (1<<shift); | 196 | led ^= (1<<shift); |
197 | else { | 197 | else { |
198 | led &= ~(0x03 << shift); | 198 | led &= ~(0x03 << shift); |
199 | led |= (state << shift); | 199 | led |= (state << shift); |
200 | } | 200 | } |
201 | writeb(led, card->csr_remap + MEMCTRLCMD_LEDCTRL); | 201 | writeb(led, card->csr_remap + MEMCTRLCMD_LEDCTRL); |
202 | 202 | ||
203 | } | 203 | } |
204 | 204 | ||
205 | #ifdef MM_DIAG | 205 | #ifdef MM_DIAG |
206 | /* | 206 | /* |
207 | ----------------------------------------------------------------------------------- | 207 | ----------------------------------------------------------------------------------- |
208 | -- dump_regs | 208 | -- dump_regs |
209 | ----------------------------------------------------------------------------------- | 209 | ----------------------------------------------------------------------------------- |
210 | */ | 210 | */ |
211 | static void dump_regs(struct cardinfo *card) | 211 | static void dump_regs(struct cardinfo *card) |
212 | { | 212 | { |
213 | unsigned char *p; | 213 | unsigned char *p; |
214 | int i, i1; | 214 | int i, i1; |
215 | 215 | ||
216 | p = card->csr_remap; | 216 | p = card->csr_remap; |
217 | for (i = 0; i < 8; i++) { | 217 | for (i = 0; i < 8; i++) { |
218 | printk(KERN_DEBUG "%p ", p); | 218 | printk(KERN_DEBUG "%p ", p); |
219 | 219 | ||
220 | for (i1 = 0; i1 < 16; i1++) | 220 | for (i1 = 0; i1 < 16; i1++) |
221 | printk("%02x ", *p++); | 221 | printk("%02x ", *p++); |
222 | 222 | ||
223 | printk("\n"); | 223 | printk("\n"); |
224 | } | 224 | } |
225 | } | 225 | } |
226 | #endif | 226 | #endif |
227 | /* | 227 | /* |
228 | ----------------------------------------------------------------------------------- | 228 | ----------------------------------------------------------------------------------- |
229 | -- dump_dmastat | 229 | -- dump_dmastat |
230 | ----------------------------------------------------------------------------------- | 230 | ----------------------------------------------------------------------------------- |
231 | */ | 231 | */ |
232 | static void dump_dmastat(struct cardinfo *card, unsigned int dmastat) | 232 | static void dump_dmastat(struct cardinfo *card, unsigned int dmastat) |
233 | { | 233 | { |
234 | dev_printk(KERN_DEBUG, &card->dev->dev, "DMAstat - "); | 234 | dev_printk(KERN_DEBUG, &card->dev->dev, "DMAstat - "); |
235 | if (dmastat & DMASCR_ANY_ERR) | 235 | if (dmastat & DMASCR_ANY_ERR) |
236 | printk("ANY_ERR "); | 236 | printk("ANY_ERR "); |
237 | if (dmastat & DMASCR_MBE_ERR) | 237 | if (dmastat & DMASCR_MBE_ERR) |
238 | printk("MBE_ERR "); | 238 | printk("MBE_ERR "); |
239 | if (dmastat & DMASCR_PARITY_ERR_REP) | 239 | if (dmastat & DMASCR_PARITY_ERR_REP) |
240 | printk("PARITY_ERR_REP "); | 240 | printk("PARITY_ERR_REP "); |
241 | if (dmastat & DMASCR_PARITY_ERR_DET) | 241 | if (dmastat & DMASCR_PARITY_ERR_DET) |
242 | printk("PARITY_ERR_DET "); | 242 | printk("PARITY_ERR_DET "); |
243 | if (dmastat & DMASCR_SYSTEM_ERR_SIG) | 243 | if (dmastat & DMASCR_SYSTEM_ERR_SIG) |
244 | printk("SYSTEM_ERR_SIG "); | 244 | printk("SYSTEM_ERR_SIG "); |
245 | if (dmastat & DMASCR_TARGET_ABT) | 245 | if (dmastat & DMASCR_TARGET_ABT) |
246 | printk("TARGET_ABT "); | 246 | printk("TARGET_ABT "); |
247 | if (dmastat & DMASCR_MASTER_ABT) | 247 | if (dmastat & DMASCR_MASTER_ABT) |
248 | printk("MASTER_ABT "); | 248 | printk("MASTER_ABT "); |
249 | if (dmastat & DMASCR_CHAIN_COMPLETE) | 249 | if (dmastat & DMASCR_CHAIN_COMPLETE) |
250 | printk("CHAIN_COMPLETE "); | 250 | printk("CHAIN_COMPLETE "); |
251 | if (dmastat & DMASCR_DMA_COMPLETE) | 251 | if (dmastat & DMASCR_DMA_COMPLETE) |
252 | printk("DMA_COMPLETE "); | 252 | printk("DMA_COMPLETE "); |
253 | printk("\n"); | 253 | printk("\n"); |
254 | } | 254 | } |
255 | 255 | ||
256 | /* | 256 | /* |
257 | * Theory of request handling | 257 | * Theory of request handling |
258 | * | 258 | * |
259 | * Each bio is assigned to one mm_dma_desc - which may not be enough FIXME | 259 | * Each bio is assigned to one mm_dma_desc - which may not be enough FIXME |
260 | * We have two pages of mm_dma_desc, holding about 64 descriptors | 260 | * We have two pages of mm_dma_desc, holding about 64 descriptors |
261 | * each. These are allocated at init time. | 261 | * each. These are allocated at init time. |
262 | * One page is "Ready" and is either full, or can have request added. | 262 | * One page is "Ready" and is either full, or can have request added. |
263 | * The other page might be "Active", which DMA is happening on it. | 263 | * The other page might be "Active", which DMA is happening on it. |
264 | * | 264 | * |
265 | * Whenever IO on the active page completes, the Ready page is activated | 265 | * Whenever IO on the active page completes, the Ready page is activated |
266 | * and the ex-Active page is clean out and made Ready. | 266 | * and the ex-Active page is clean out and made Ready. |
267 | * Otherwise the Ready page is only activated when it becomes full, or | 267 | * Otherwise the Ready page is only activated when it becomes full, or |
268 | * when mm_unplug_device is called via the unplug_io_fn. | 268 | * when mm_unplug_device is called via the unplug_io_fn. |
269 | * | 269 | * |
270 | * If a request arrives while both pages a full, it is queued, and b_rdev is | 270 | * If a request arrives while both pages a full, it is queued, and b_rdev is |
271 | * overloaded to record whether it was a read or a write. | 271 | * overloaded to record whether it was a read or a write. |
272 | * | 272 | * |
273 | * The interrupt handler only polls the device to clear the interrupt. | 273 | * The interrupt handler only polls the device to clear the interrupt. |
274 | * The processing of the result is done in a tasklet. | 274 | * The processing of the result is done in a tasklet. |
275 | */ | 275 | */ |
276 | 276 | ||
277 | static void mm_start_io(struct cardinfo *card) | 277 | static void mm_start_io(struct cardinfo *card) |
278 | { | 278 | { |
279 | /* we have the lock, we know there is | 279 | /* we have the lock, we know there is |
280 | * no IO active, and we know that card->Active | 280 | * no IO active, and we know that card->Active |
281 | * is set | 281 | * is set |
282 | */ | 282 | */ |
283 | struct mm_dma_desc *desc; | 283 | struct mm_dma_desc *desc; |
284 | struct mm_page *page; | 284 | struct mm_page *page; |
285 | int offset; | 285 | int offset; |
286 | 286 | ||
287 | /* make the last descriptor end the chain */ | 287 | /* make the last descriptor end the chain */ |
288 | page = &card->mm_pages[card->Active]; | 288 | page = &card->mm_pages[card->Active]; |
289 | pr_debug("start_io: %d %d->%d\n", card->Active, page->headcnt, page->cnt-1); | 289 | pr_debug("start_io: %d %d->%d\n", card->Active, page->headcnt, page->cnt-1); |
290 | desc = &page->desc[page->cnt-1]; | 290 | desc = &page->desc[page->cnt-1]; |
291 | 291 | ||
292 | desc->control_bits |= cpu_to_le32(DMASCR_CHAIN_COMP_EN); | 292 | desc->control_bits |= cpu_to_le32(DMASCR_CHAIN_COMP_EN); |
293 | desc->control_bits &= ~cpu_to_le32(DMASCR_CHAIN_EN); | 293 | desc->control_bits &= ~cpu_to_le32(DMASCR_CHAIN_EN); |
294 | desc->sem_control_bits = desc->control_bits; | 294 | desc->sem_control_bits = desc->control_bits; |
295 | 295 | ||
296 | 296 | ||
297 | if (debug & DEBUG_LED_ON_TRANSFER) | 297 | if (debug & DEBUG_LED_ON_TRANSFER) |
298 | set_led(card, LED_REMOVE, LED_ON); | 298 | set_led(card, LED_REMOVE, LED_ON); |
299 | 299 | ||
300 | desc = &page->desc[page->headcnt]; | 300 | desc = &page->desc[page->headcnt]; |
301 | writel(0, card->csr_remap + DMA_PCI_ADDR); | 301 | writel(0, card->csr_remap + DMA_PCI_ADDR); |
302 | writel(0, card->csr_remap + DMA_PCI_ADDR + 4); | 302 | writel(0, card->csr_remap + DMA_PCI_ADDR + 4); |
303 | 303 | ||
304 | writel(0, card->csr_remap + DMA_LOCAL_ADDR); | 304 | writel(0, card->csr_remap + DMA_LOCAL_ADDR); |
305 | writel(0, card->csr_remap + DMA_LOCAL_ADDR + 4); | 305 | writel(0, card->csr_remap + DMA_LOCAL_ADDR + 4); |
306 | 306 | ||
307 | writel(0, card->csr_remap + DMA_TRANSFER_SIZE); | 307 | writel(0, card->csr_remap + DMA_TRANSFER_SIZE); |
308 | writel(0, card->csr_remap + DMA_TRANSFER_SIZE + 4); | 308 | writel(0, card->csr_remap + DMA_TRANSFER_SIZE + 4); |
309 | 309 | ||
310 | writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR); | 310 | writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR); |
311 | writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR + 4); | 311 | writel(0, card->csr_remap + DMA_SEMAPHORE_ADDR + 4); |
312 | 312 | ||
313 | offset = ((char*)desc) - ((char*)page->desc); | 313 | offset = ((char*)desc) - ((char*)page->desc); |
314 | writel(cpu_to_le32((page->page_dma+offset)&0xffffffff), | 314 | writel(cpu_to_le32((page->page_dma+offset)&0xffffffff), |
315 | card->csr_remap + DMA_DESCRIPTOR_ADDR); | 315 | card->csr_remap + DMA_DESCRIPTOR_ADDR); |
316 | /* Force the value to u64 before shifting otherwise >> 32 is undefined C | 316 | /* Force the value to u64 before shifting otherwise >> 32 is undefined C |
317 | * and on some ports will do nothing ! */ | 317 | * and on some ports will do nothing ! */ |
318 | writel(cpu_to_le32(((u64)page->page_dma)>>32), | 318 | writel(cpu_to_le32(((u64)page->page_dma)>>32), |
319 | card->csr_remap + DMA_DESCRIPTOR_ADDR + 4); | 319 | card->csr_remap + DMA_DESCRIPTOR_ADDR + 4); |
320 | 320 | ||
321 | /* Go, go, go */ | 321 | /* Go, go, go */ |
322 | writel(cpu_to_le32(DMASCR_GO | DMASCR_CHAIN_EN | pci_cmds), | 322 | writel(cpu_to_le32(DMASCR_GO | DMASCR_CHAIN_EN | pci_cmds), |
323 | card->csr_remap + DMA_STATUS_CTRL); | 323 | card->csr_remap + DMA_STATUS_CTRL); |
324 | } | 324 | } |
325 | 325 | ||
326 | static int add_bio(struct cardinfo *card); | 326 | static int add_bio(struct cardinfo *card); |
327 | 327 | ||
328 | static void activate(struct cardinfo *card) | 328 | static void activate(struct cardinfo *card) |
329 | { | 329 | { |
330 | /* if No page is Active, and Ready is | 330 | /* if No page is Active, and Ready is |
331 | * not empty, then switch Ready page | 331 | * not empty, then switch Ready page |
332 | * to active and start IO. | 332 | * to active and start IO. |
333 | * Then add any bh's that are available to Ready | 333 | * Then add any bh's that are available to Ready |
334 | */ | 334 | */ |
335 | 335 | ||
336 | do { | 336 | do { |
337 | while (add_bio(card)) | 337 | while (add_bio(card)) |
338 | ; | 338 | ; |
339 | 339 | ||
340 | if (card->Active == -1 && | 340 | if (card->Active == -1 && |
341 | card->mm_pages[card->Ready].cnt > 0) { | 341 | card->mm_pages[card->Ready].cnt > 0) { |
342 | card->Active = card->Ready; | 342 | card->Active = card->Ready; |
343 | card->Ready = 1-card->Ready; | 343 | card->Ready = 1-card->Ready; |
344 | mm_start_io(card); | 344 | mm_start_io(card); |
345 | } | 345 | } |
346 | 346 | ||
347 | } while (card->Active == -1 && add_bio(card)); | 347 | } while (card->Active == -1 && add_bio(card)); |
348 | } | 348 | } |
349 | 349 | ||
350 | static inline void reset_page(struct mm_page *page) | 350 | static inline void reset_page(struct mm_page *page) |
351 | { | 351 | { |
352 | page->cnt = 0; | 352 | page->cnt = 0; |
353 | page->headcnt = 0; | 353 | page->headcnt = 0; |
354 | page->bio = NULL; | 354 | page->bio = NULL; |
355 | page->biotail = & page->bio; | 355 | page->biotail = & page->bio; |
356 | } | 356 | } |
357 | 357 | ||
358 | static void mm_unplug_device(struct request_queue *q) | 358 | static void mm_unplug_device(struct request_queue *q) |
359 | { | 359 | { |
360 | struct cardinfo *card = q->queuedata; | 360 | struct cardinfo *card = q->queuedata; |
361 | unsigned long flags; | 361 | unsigned long flags; |
362 | 362 | ||
363 | spin_lock_irqsave(&card->lock, flags); | 363 | spin_lock_irqsave(&card->lock, flags); |
364 | if (blk_remove_plug(q)) | 364 | if (blk_remove_plug(q)) |
365 | activate(card); | 365 | activate(card); |
366 | spin_unlock_irqrestore(&card->lock, flags); | 366 | spin_unlock_irqrestore(&card->lock, flags); |
367 | } | 367 | } |
368 | 368 | ||
369 | /* | 369 | /* |
370 | * If there is room on Ready page, take | 370 | * If there is room on Ready page, take |
371 | * one bh off list and add it. | 371 | * one bh off list and add it. |
372 | * return 1 if there was room, else 0. | 372 | * return 1 if there was room, else 0. |
373 | */ | 373 | */ |
374 | static int add_bio(struct cardinfo *card) | 374 | static int add_bio(struct cardinfo *card) |
375 | { | 375 | { |
376 | struct mm_page *p; | 376 | struct mm_page *p; |
377 | struct mm_dma_desc *desc; | 377 | struct mm_dma_desc *desc; |
378 | dma_addr_t dma_handle; | 378 | dma_addr_t dma_handle; |
379 | int offset; | 379 | int offset; |
380 | struct bio *bio; | 380 | struct bio *bio; |
381 | struct bio_vec *vec; | 381 | struct bio_vec *vec; |
382 | int idx; | 382 | int idx; |
383 | int rw; | 383 | int rw; |
384 | int len; | 384 | int len; |
385 | 385 | ||
386 | bio = card->currentbio; | 386 | bio = card->currentbio; |
387 | if (!bio && card->bio) { | 387 | if (!bio && card->bio) { |
388 | card->currentbio = card->bio; | 388 | card->currentbio = card->bio; |
389 | card->current_idx = card->bio->bi_idx; | 389 | card->current_idx = card->bio->bi_idx; |
390 | card->current_sector = card->bio->bi_sector; | 390 | card->current_sector = card->bio->bi_sector; |
391 | card->bio = card->bio->bi_next; | 391 | card->bio = card->bio->bi_next; |
392 | if (card->bio == NULL) | 392 | if (card->bio == NULL) |
393 | card->biotail = &card->bio; | 393 | card->biotail = &card->bio; |
394 | card->currentbio->bi_next = NULL; | 394 | card->currentbio->bi_next = NULL; |
395 | return 1; | 395 | return 1; |
396 | } | 396 | } |
397 | if (!bio) | 397 | if (!bio) |
398 | return 0; | 398 | return 0; |
399 | idx = card->current_idx; | 399 | idx = card->current_idx; |
400 | 400 | ||
401 | rw = bio_rw(bio); | 401 | rw = bio_rw(bio); |
402 | if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE) | 402 | if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE) |
403 | return 0; | 403 | return 0; |
404 | 404 | ||
405 | vec = bio_iovec_idx(bio, idx); | 405 | vec = bio_iovec_idx(bio, idx); |
406 | len = vec->bv_len; | 406 | len = vec->bv_len; |
407 | dma_handle = pci_map_page(card->dev, | 407 | dma_handle = pci_map_page(card->dev, |
408 | vec->bv_page, | 408 | vec->bv_page, |
409 | vec->bv_offset, | 409 | vec->bv_offset, |
410 | len, | 410 | len, |
411 | (rw==READ) ? | 411 | (rw==READ) ? |
412 | PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE); | 412 | PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE); |
413 | 413 | ||
414 | p = &card->mm_pages[card->Ready]; | 414 | p = &card->mm_pages[card->Ready]; |
415 | desc = &p->desc[p->cnt]; | 415 | desc = &p->desc[p->cnt]; |
416 | p->cnt++; | 416 | p->cnt++; |
417 | if (p->bio == NULL) | 417 | if (p->bio == NULL) |
418 | p->idx = idx; | 418 | p->idx = idx; |
419 | if ((p->biotail) != &bio->bi_next) { | 419 | if ((p->biotail) != &bio->bi_next) { |
420 | *(p->biotail) = bio; | 420 | *(p->biotail) = bio; |
421 | p->biotail = &(bio->bi_next); | 421 | p->biotail = &(bio->bi_next); |
422 | bio->bi_next = NULL; | 422 | bio->bi_next = NULL; |
423 | } | 423 | } |
424 | 424 | ||
425 | desc->data_dma_handle = dma_handle; | 425 | desc->data_dma_handle = dma_handle; |
426 | 426 | ||
427 | desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle); | 427 | desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle); |
428 | desc->local_addr = cpu_to_le64(card->current_sector << 9); | 428 | desc->local_addr = cpu_to_le64(card->current_sector << 9); |
429 | desc->transfer_size = cpu_to_le32(len); | 429 | desc->transfer_size = cpu_to_le32(len); |
430 | offset = ( ((char*)&desc->sem_control_bits) - ((char*)p->desc)); | 430 | offset = ( ((char*)&desc->sem_control_bits) - ((char*)p->desc)); |
431 | desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset)); | 431 | desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset)); |
432 | desc->zero1 = desc->zero2 = 0; | 432 | desc->zero1 = desc->zero2 = 0; |
433 | offset = ( ((char*)(desc+1)) - ((char*)p->desc)); | 433 | offset = ( ((char*)(desc+1)) - ((char*)p->desc)); |
434 | desc->next_desc_addr = cpu_to_le64(p->page_dma+offset); | 434 | desc->next_desc_addr = cpu_to_le64(p->page_dma+offset); |
435 | desc->control_bits = cpu_to_le32(DMASCR_GO|DMASCR_ERR_INT_EN| | 435 | desc->control_bits = cpu_to_le32(DMASCR_GO|DMASCR_ERR_INT_EN| |
436 | DMASCR_PARITY_INT_EN| | 436 | DMASCR_PARITY_INT_EN| |
437 | DMASCR_CHAIN_EN | | 437 | DMASCR_CHAIN_EN | |
438 | DMASCR_SEM_EN | | 438 | DMASCR_SEM_EN | |
439 | pci_cmds); | 439 | pci_cmds); |
440 | if (rw == WRITE) | 440 | if (rw == WRITE) |
441 | desc->control_bits |= cpu_to_le32(DMASCR_TRANSFER_READ); | 441 | desc->control_bits |= cpu_to_le32(DMASCR_TRANSFER_READ); |
442 | desc->sem_control_bits = desc->control_bits; | 442 | desc->sem_control_bits = desc->control_bits; |
443 | 443 | ||
444 | card->current_sector += (len >> 9); | 444 | card->current_sector += (len >> 9); |
445 | idx++; | 445 | idx++; |
446 | card->current_idx = idx; | 446 | card->current_idx = idx; |
447 | if (idx >= bio->bi_vcnt) | 447 | if (idx >= bio->bi_vcnt) |
448 | card->currentbio = NULL; | 448 | card->currentbio = NULL; |
449 | 449 | ||
450 | return 1; | 450 | return 1; |
451 | } | 451 | } |
452 | 452 | ||
453 | static void process_page(unsigned long data) | 453 | static void process_page(unsigned long data) |
454 | { | 454 | { |
455 | /* check if any of the requests in the page are DMA_COMPLETE, | 455 | /* check if any of the requests in the page are DMA_COMPLETE, |
456 | * and deal with them appropriately. | 456 | * and deal with them appropriately. |
457 | * If we find a descriptor without DMA_COMPLETE in the semaphore, then | 457 | * If we find a descriptor without DMA_COMPLETE in the semaphore, then |
458 | * dma must have hit an error on that descriptor, so use dma_status instead | 458 | * dma must have hit an error on that descriptor, so use dma_status instead |
459 | * and assume that all following descriptors must be re-tried. | 459 | * and assume that all following descriptors must be re-tried. |
460 | */ | 460 | */ |
461 | struct mm_page *page; | 461 | struct mm_page *page; |
462 | struct bio *return_bio=NULL; | 462 | struct bio *return_bio=NULL; |
463 | struct cardinfo *card = (struct cardinfo *)data; | 463 | struct cardinfo *card = (struct cardinfo *)data; |
464 | unsigned int dma_status = card->dma_status; | 464 | unsigned int dma_status = card->dma_status; |
465 | 465 | ||
466 | spin_lock_bh(&card->lock); | 466 | spin_lock_bh(&card->lock); |
467 | if (card->Active < 0) | 467 | if (card->Active < 0) |
468 | goto out_unlock; | 468 | goto out_unlock; |
469 | page = &card->mm_pages[card->Active]; | 469 | page = &card->mm_pages[card->Active]; |
470 | 470 | ||
471 | while (page->headcnt < page->cnt) { | 471 | while (page->headcnt < page->cnt) { |
472 | struct bio *bio = page->bio; | 472 | struct bio *bio = page->bio; |
473 | struct mm_dma_desc *desc = &page->desc[page->headcnt]; | 473 | struct mm_dma_desc *desc = &page->desc[page->headcnt]; |
474 | int control = le32_to_cpu(desc->sem_control_bits); | 474 | int control = le32_to_cpu(desc->sem_control_bits); |
475 | int last=0; | 475 | int last=0; |
476 | int idx; | 476 | int idx; |
477 | 477 | ||
478 | if (!(control & DMASCR_DMA_COMPLETE)) { | 478 | if (!(control & DMASCR_DMA_COMPLETE)) { |
479 | control = dma_status; | 479 | control = dma_status; |
480 | last=1; | 480 | last=1; |
481 | } | 481 | } |
482 | page->headcnt++; | 482 | page->headcnt++; |
483 | idx = page->idx; | 483 | idx = page->idx; |
484 | page->idx++; | 484 | page->idx++; |
485 | if (page->idx >= bio->bi_vcnt) { | 485 | if (page->idx >= bio->bi_vcnt) { |
486 | page->bio = bio->bi_next; | 486 | page->bio = bio->bi_next; |
487 | page->idx = page->bio->bi_idx; | 487 | page->idx = page->bio->bi_idx; |
488 | } | 488 | } |
489 | 489 | ||
490 | pci_unmap_page(card->dev, desc->data_dma_handle, | 490 | pci_unmap_page(card->dev, desc->data_dma_handle, |
491 | bio_iovec_idx(bio,idx)->bv_len, | 491 | bio_iovec_idx(bio,idx)->bv_len, |
492 | (control& DMASCR_TRANSFER_READ) ? | 492 | (control& DMASCR_TRANSFER_READ) ? |
493 | PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); | 493 | PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); |
494 | if (control & DMASCR_HARD_ERROR) { | 494 | if (control & DMASCR_HARD_ERROR) { |
495 | /* error */ | 495 | /* error */ |
496 | clear_bit(BIO_UPTODATE, &bio->bi_flags); | 496 | clear_bit(BIO_UPTODATE, &bio->bi_flags); |
497 | dev_printk(KERN_WARNING, &card->dev->dev, | 497 | dev_printk(KERN_WARNING, &card->dev->dev, |
498 | "I/O error on sector %d/%d\n", | 498 | "I/O error on sector %d/%d\n", |
499 | le32_to_cpu(desc->local_addr)>>9, | 499 | le32_to_cpu(desc->local_addr)>>9, |
500 | le32_to_cpu(desc->transfer_size)); | 500 | le32_to_cpu(desc->transfer_size)); |
501 | dump_dmastat(card, control); | 501 | dump_dmastat(card, control); |
502 | } else if (test_bit(BIO_RW, &bio->bi_rw) && | 502 | } else if (test_bit(BIO_RW, &bio->bi_rw) && |
503 | le32_to_cpu(desc->local_addr)>>9 == card->init_size) { | 503 | le32_to_cpu(desc->local_addr)>>9 == card->init_size) { |
504 | card->init_size += le32_to_cpu(desc->transfer_size)>>9; | 504 | card->init_size += le32_to_cpu(desc->transfer_size)>>9; |
505 | if (card->init_size>>1 >= card->mm_size) { | 505 | if (card->init_size>>1 >= card->mm_size) { |
506 | dev_printk(KERN_INFO, &card->dev->dev, | 506 | dev_printk(KERN_INFO, &card->dev->dev, |
507 | "memory now initialised\n"); | 507 | "memory now initialised\n"); |
508 | set_userbit(card, MEMORY_INITIALIZED, 1); | 508 | set_userbit(card, MEMORY_INITIALIZED, 1); |
509 | } | 509 | } |
510 | } | 510 | } |
511 | if (bio != page->bio) { | 511 | if (bio != page->bio) { |
512 | bio->bi_next = return_bio; | 512 | bio->bi_next = return_bio; |
513 | return_bio = bio; | 513 | return_bio = bio; |
514 | } | 514 | } |
515 | 515 | ||
516 | if (last) break; | 516 | if (last) break; |
517 | } | 517 | } |
518 | 518 | ||
519 | if (debug & DEBUG_LED_ON_TRANSFER) | 519 | if (debug & DEBUG_LED_ON_TRANSFER) |
520 | set_led(card, LED_REMOVE, LED_OFF); | 520 | set_led(card, LED_REMOVE, LED_OFF); |
521 | 521 | ||
522 | if (card->check_batteries) { | 522 | if (card->check_batteries) { |
523 | card->check_batteries = 0; | 523 | card->check_batteries = 0; |
524 | check_batteries(card); | 524 | check_batteries(card); |
525 | } | 525 | } |
526 | if (page->headcnt >= page->cnt) { | 526 | if (page->headcnt >= page->cnt) { |
527 | reset_page(page); | 527 | reset_page(page); |
528 | card->Active = -1; | 528 | card->Active = -1; |
529 | activate(card); | 529 | activate(card); |
530 | } else { | 530 | } else { |
531 | /* haven't finished with this one yet */ | 531 | /* haven't finished with this one yet */ |
532 | pr_debug("do some more\n"); | 532 | pr_debug("do some more\n"); |
533 | mm_start_io(card); | 533 | mm_start_io(card); |
534 | } | 534 | } |
535 | out_unlock: | 535 | out_unlock: |
536 | spin_unlock_bh(&card->lock); | 536 | spin_unlock_bh(&card->lock); |
537 | 537 | ||
538 | while(return_bio) { | 538 | while(return_bio) { |
539 | struct bio *bio = return_bio; | 539 | struct bio *bio = return_bio; |
540 | 540 | ||
541 | return_bio = bio->bi_next; | 541 | return_bio = bio->bi_next; |
542 | bio->bi_next = NULL; | 542 | bio->bi_next = NULL; |
543 | bio_endio(bio, 0); | 543 | bio_endio(bio, 0); |
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||
547 | /* | 547 | /* |
548 | ----------------------------------------------------------------------------------- | 548 | ----------------------------------------------------------------------------------- |
549 | -- mm_make_request | 549 | -- mm_make_request |
550 | ----------------------------------------------------------------------------------- | 550 | ----------------------------------------------------------------------------------- |
551 | */ | 551 | */ |
552 | static int mm_make_request(struct request_queue *q, struct bio *bio) | 552 | static int mm_make_request(struct request_queue *q, struct bio *bio) |
553 | { | 553 | { |
554 | struct cardinfo *card = q->queuedata; | 554 | struct cardinfo *card = q->queuedata; |
555 | pr_debug("mm_make_request %llu %u\n", | 555 | pr_debug("mm_make_request %llu %u\n", |
556 | (unsigned long long)bio->bi_sector, bio->bi_size); | 556 | (unsigned long long)bio->bi_sector, bio->bi_size); |
557 | 557 | ||
558 | spin_lock_irq(&card->lock); | 558 | spin_lock_irq(&card->lock); |
559 | *card->biotail = bio; | 559 | *card->biotail = bio; |
560 | bio->bi_next = NULL; | 560 | bio->bi_next = NULL; |
561 | card->biotail = &bio->bi_next; | 561 | card->biotail = &bio->bi_next; |
562 | blk_plug_device(q); | 562 | blk_plug_device(q); |
563 | spin_unlock_irq(&card->lock); | 563 | spin_unlock_irq(&card->lock); |
564 | 564 | ||
565 | return 0; | 565 | return 0; |
566 | } | 566 | } |
567 | 567 | ||
568 | /* | 568 | /* |
569 | ----------------------------------------------------------------------------------- | 569 | ----------------------------------------------------------------------------------- |
570 | -- mm_interrupt | 570 | -- mm_interrupt |
571 | ----------------------------------------------------------------------------------- | 571 | ----------------------------------------------------------------------------------- |
572 | */ | 572 | */ |
573 | static irqreturn_t mm_interrupt(int irq, void *__card) | 573 | static irqreturn_t mm_interrupt(int irq, void *__card) |
574 | { | 574 | { |
575 | struct cardinfo *card = (struct cardinfo *) __card; | 575 | struct cardinfo *card = (struct cardinfo *) __card; |
576 | unsigned int dma_status; | 576 | unsigned int dma_status; |
577 | unsigned short cfg_status; | 577 | unsigned short cfg_status; |
578 | 578 | ||
579 | HW_TRACE(0x30); | 579 | HW_TRACE(0x30); |
580 | 580 | ||
581 | dma_status = le32_to_cpu(readl(card->csr_remap + DMA_STATUS_CTRL)); | 581 | dma_status = le32_to_cpu(readl(card->csr_remap + DMA_STATUS_CTRL)); |
582 | 582 | ||
583 | if (!(dma_status & (DMASCR_ERROR_MASK | DMASCR_CHAIN_COMPLETE))) { | 583 | if (!(dma_status & (DMASCR_ERROR_MASK | DMASCR_CHAIN_COMPLETE))) { |
584 | /* interrupt wasn't for me ... */ | 584 | /* interrupt wasn't for me ... */ |
585 | return IRQ_NONE; | 585 | return IRQ_NONE; |
586 | } | 586 | } |
587 | 587 | ||
588 | /* clear COMPLETION interrupts */ | 588 | /* clear COMPLETION interrupts */ |
589 | if (card->flags & UM_FLAG_NO_BYTE_STATUS) | 589 | if (card->flags & UM_FLAG_NO_BYTE_STATUS) |
590 | writel(cpu_to_le32(DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE), | 590 | writel(cpu_to_le32(DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE), |
591 | card->csr_remap+ DMA_STATUS_CTRL); | 591 | card->csr_remap+ DMA_STATUS_CTRL); |
592 | else | 592 | else |
593 | writeb((DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE) >> 16, | 593 | writeb((DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE) >> 16, |
594 | card->csr_remap+ DMA_STATUS_CTRL + 2); | 594 | card->csr_remap+ DMA_STATUS_CTRL + 2); |
595 | 595 | ||
596 | /* log errors and clear interrupt status */ | 596 | /* log errors and clear interrupt status */ |
597 | if (dma_status & DMASCR_ANY_ERR) { | 597 | if (dma_status & DMASCR_ANY_ERR) { |
598 | unsigned int data_log1, data_log2; | 598 | unsigned int data_log1, data_log2; |
599 | unsigned int addr_log1, addr_log2; | 599 | unsigned int addr_log1, addr_log2; |
600 | unsigned char stat, count, syndrome, check; | 600 | unsigned char stat, count, syndrome, check; |
601 | 601 | ||
602 | stat = readb(card->csr_remap + MEMCTRLCMD_ERRSTATUS); | 602 | stat = readb(card->csr_remap + MEMCTRLCMD_ERRSTATUS); |
603 | 603 | ||
604 | data_log1 = le32_to_cpu(readl(card->csr_remap + ERROR_DATA_LOG)); | 604 | data_log1 = le32_to_cpu(readl(card->csr_remap + ERROR_DATA_LOG)); |
605 | data_log2 = le32_to_cpu(readl(card->csr_remap + ERROR_DATA_LOG + 4)); | 605 | data_log2 = le32_to_cpu(readl(card->csr_remap + ERROR_DATA_LOG + 4)); |
606 | addr_log1 = le32_to_cpu(readl(card->csr_remap + ERROR_ADDR_LOG)); | 606 | addr_log1 = le32_to_cpu(readl(card->csr_remap + ERROR_ADDR_LOG)); |
607 | addr_log2 = readb(card->csr_remap + ERROR_ADDR_LOG + 4); | 607 | addr_log2 = readb(card->csr_remap + ERROR_ADDR_LOG + 4); |
608 | 608 | ||
609 | count = readb(card->csr_remap + ERROR_COUNT); | 609 | count = readb(card->csr_remap + ERROR_COUNT); |
610 | syndrome = readb(card->csr_remap + ERROR_SYNDROME); | 610 | syndrome = readb(card->csr_remap + ERROR_SYNDROME); |
611 | check = readb(card->csr_remap + ERROR_CHECK); | 611 | check = readb(card->csr_remap + ERROR_CHECK); |
612 | 612 | ||
613 | dump_dmastat(card, dma_status); | 613 | dump_dmastat(card, dma_status); |
614 | 614 | ||
615 | if (stat & 0x01) | 615 | if (stat & 0x01) |
616 | dev_printk(KERN_ERR, &card->dev->dev, | 616 | dev_printk(KERN_ERR, &card->dev->dev, |
617 | "Memory access error detected (err count %d)\n", | 617 | "Memory access error detected (err count %d)\n", |
618 | count); | 618 | count); |
619 | if (stat & 0x02) | 619 | if (stat & 0x02) |
620 | dev_printk(KERN_ERR, &card->dev->dev, | 620 | dev_printk(KERN_ERR, &card->dev->dev, |
621 | "Multi-bit EDC error\n"); | 621 | "Multi-bit EDC error\n"); |
622 | 622 | ||
623 | dev_printk(KERN_ERR, &card->dev->dev, | 623 | dev_printk(KERN_ERR, &card->dev->dev, |
624 | "Fault Address 0x%02x%08x, Fault Data 0x%08x%08x\n", | 624 | "Fault Address 0x%02x%08x, Fault Data 0x%08x%08x\n", |
625 | addr_log2, addr_log1, data_log2, data_log1); | 625 | addr_log2, addr_log1, data_log2, data_log1); |
626 | dev_printk(KERN_ERR, &card->dev->dev, | 626 | dev_printk(KERN_ERR, &card->dev->dev, |
627 | "Fault Check 0x%02x, Fault Syndrome 0x%02x\n", | 627 | "Fault Check 0x%02x, Fault Syndrome 0x%02x\n", |
628 | check, syndrome); | 628 | check, syndrome); |
629 | 629 | ||
630 | writeb(0, card->csr_remap + ERROR_COUNT); | 630 | writeb(0, card->csr_remap + ERROR_COUNT); |
631 | } | 631 | } |
632 | 632 | ||
633 | if (dma_status & DMASCR_PARITY_ERR_REP) { | 633 | if (dma_status & DMASCR_PARITY_ERR_REP) { |
634 | dev_printk(KERN_ERR, &card->dev->dev, | 634 | dev_printk(KERN_ERR, &card->dev->dev, |
635 | "PARITY ERROR REPORTED\n"); | 635 | "PARITY ERROR REPORTED\n"); |
636 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); | 636 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); |
637 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); | 637 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); |
638 | } | 638 | } |
639 | 639 | ||
640 | if (dma_status & DMASCR_PARITY_ERR_DET) { | 640 | if (dma_status & DMASCR_PARITY_ERR_DET) { |
641 | dev_printk(KERN_ERR, &card->dev->dev, | 641 | dev_printk(KERN_ERR, &card->dev->dev, |
642 | "PARITY ERROR DETECTED\n"); | 642 | "PARITY ERROR DETECTED\n"); |
643 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); | 643 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); |
644 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); | 644 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); |
645 | } | 645 | } |
646 | 646 | ||
647 | if (dma_status & DMASCR_SYSTEM_ERR_SIG) { | 647 | if (dma_status & DMASCR_SYSTEM_ERR_SIG) { |
648 | dev_printk(KERN_ERR, &card->dev->dev, "SYSTEM ERROR\n"); | 648 | dev_printk(KERN_ERR, &card->dev->dev, "SYSTEM ERROR\n"); |
649 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); | 649 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); |
650 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); | 650 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); |
651 | } | 651 | } |
652 | 652 | ||
653 | if (dma_status & DMASCR_TARGET_ABT) { | 653 | if (dma_status & DMASCR_TARGET_ABT) { |
654 | dev_printk(KERN_ERR, &card->dev->dev, "TARGET ABORT\n"); | 654 | dev_printk(KERN_ERR, &card->dev->dev, "TARGET ABORT\n"); |
655 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); | 655 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); |
656 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); | 656 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); |
657 | } | 657 | } |
658 | 658 | ||
659 | if (dma_status & DMASCR_MASTER_ABT) { | 659 | if (dma_status & DMASCR_MASTER_ABT) { |
660 | dev_printk(KERN_ERR, &card->dev->dev, "MASTER ABORT\n"); | 660 | dev_printk(KERN_ERR, &card->dev->dev, "MASTER ABORT\n"); |
661 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); | 661 | pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); |
662 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); | 662 | pci_write_config_word(card->dev, PCI_STATUS, cfg_status); |
663 | } | 663 | } |
664 | 664 | ||
665 | /* and process the DMA descriptors */ | 665 | /* and process the DMA descriptors */ |
666 | card->dma_status = dma_status; | 666 | card->dma_status = dma_status; |
667 | tasklet_schedule(&card->tasklet); | 667 | tasklet_schedule(&card->tasklet); |
668 | 668 | ||
669 | HW_TRACE(0x36); | 669 | HW_TRACE(0x36); |
670 | 670 | ||
671 | return IRQ_HANDLED; | 671 | return IRQ_HANDLED; |
672 | } | 672 | } |
673 | /* | 673 | /* |
674 | ----------------------------------------------------------------------------------- | 674 | ----------------------------------------------------------------------------------- |
675 | -- set_fault_to_battery_status | 675 | -- set_fault_to_battery_status |
676 | ----------------------------------------------------------------------------------- | 676 | ----------------------------------------------------------------------------------- |
677 | */ | 677 | */ |
678 | /* | 678 | /* |
679 | * If both batteries are good, no LED | 679 | * If both batteries are good, no LED |
680 | * If either battery has been warned, solid LED | 680 | * If either battery has been warned, solid LED |
681 | * If both batteries are bad, flash the LED quickly | 681 | * If both batteries are bad, flash the LED quickly |
682 | * If either battery is bad, flash the LED semi quickly | 682 | * If either battery is bad, flash the LED semi quickly |
683 | */ | 683 | */ |
684 | static void set_fault_to_battery_status(struct cardinfo *card) | 684 | static void set_fault_to_battery_status(struct cardinfo *card) |
685 | { | 685 | { |
686 | if (card->battery[0].good && card->battery[1].good) | 686 | if (card->battery[0].good && card->battery[1].good) |
687 | set_led(card, LED_FAULT, LED_OFF); | 687 | set_led(card, LED_FAULT, LED_OFF); |
688 | else if (card->battery[0].warned || card->battery[1].warned) | 688 | else if (card->battery[0].warned || card->battery[1].warned) |
689 | set_led(card, LED_FAULT, LED_ON); | 689 | set_led(card, LED_FAULT, LED_ON); |
690 | else if (!card->battery[0].good && !card->battery[1].good) | 690 | else if (!card->battery[0].good && !card->battery[1].good) |
691 | set_led(card, LED_FAULT, LED_FLASH_7_0); | 691 | set_led(card, LED_FAULT, LED_FLASH_7_0); |
692 | else | 692 | else |
693 | set_led(card, LED_FAULT, LED_FLASH_3_5); | 693 | set_led(card, LED_FAULT, LED_FLASH_3_5); |
694 | } | 694 | } |
695 | 695 | ||
696 | static void init_battery_timer(void); | 696 | static void init_battery_timer(void); |
697 | 697 | ||
698 | 698 | ||
699 | /* | 699 | /* |
700 | ----------------------------------------------------------------------------------- | 700 | ----------------------------------------------------------------------------------- |
701 | -- check_battery | 701 | -- check_battery |
702 | ----------------------------------------------------------------------------------- | 702 | ----------------------------------------------------------------------------------- |
703 | */ | 703 | */ |
704 | static int check_battery(struct cardinfo *card, int battery, int status) | 704 | static int check_battery(struct cardinfo *card, int battery, int status) |
705 | { | 705 | { |
706 | if (status != card->battery[battery].good) { | 706 | if (status != card->battery[battery].good) { |
707 | card->battery[battery].good = !card->battery[battery].good; | 707 | card->battery[battery].good = !card->battery[battery].good; |
708 | card->battery[battery].last_change = jiffies; | 708 | card->battery[battery].last_change = jiffies; |
709 | 709 | ||
710 | if (card->battery[battery].good) { | 710 | if (card->battery[battery].good) { |
711 | dev_printk(KERN_ERR, &card->dev->dev, | 711 | dev_printk(KERN_ERR, &card->dev->dev, |
712 | "Battery %d now good\n", battery + 1); | 712 | "Battery %d now good\n", battery + 1); |
713 | card->battery[battery].warned = 0; | 713 | card->battery[battery].warned = 0; |
714 | } else | 714 | } else |
715 | dev_printk(KERN_ERR, &card->dev->dev, | 715 | dev_printk(KERN_ERR, &card->dev->dev, |
716 | "Battery %d now FAILED\n", battery + 1); | 716 | "Battery %d now FAILED\n", battery + 1); |
717 | 717 | ||
718 | return 1; | 718 | return 1; |
719 | } else if (!card->battery[battery].good && | 719 | } else if (!card->battery[battery].good && |
720 | !card->battery[battery].warned && | 720 | !card->battery[battery].warned && |
721 | time_after_eq(jiffies, card->battery[battery].last_change + | 721 | time_after_eq(jiffies, card->battery[battery].last_change + |
722 | (HZ * 60 * 60 * 5))) { | 722 | (HZ * 60 * 60 * 5))) { |
723 | dev_printk(KERN_ERR, &card->dev->dev, | 723 | dev_printk(KERN_ERR, &card->dev->dev, |
724 | "Battery %d still FAILED after 5 hours\n", battery + 1); | 724 | "Battery %d still FAILED after 5 hours\n", battery + 1); |
725 | card->battery[battery].warned = 1; | 725 | card->battery[battery].warned = 1; |
726 | 726 | ||
727 | return 1; | 727 | return 1; |
728 | } | 728 | } |
729 | 729 | ||
730 | return 0; | 730 | return 0; |
731 | } | 731 | } |
732 | /* | 732 | /* |
733 | ----------------------------------------------------------------------------------- | 733 | ----------------------------------------------------------------------------------- |
734 | -- check_batteries | 734 | -- check_batteries |
735 | ----------------------------------------------------------------------------------- | 735 | ----------------------------------------------------------------------------------- |
736 | */ | 736 | */ |
737 | static void check_batteries(struct cardinfo *card) | 737 | static void check_batteries(struct cardinfo *card) |
738 | { | 738 | { |
739 | /* NOTE: this must *never* be called while the card | 739 | /* NOTE: this must *never* be called while the card |
740 | * is doing (bus-to-card) DMA, or you will need the | 740 | * is doing (bus-to-card) DMA, or you will need the |
741 | * reset switch | 741 | * reset switch |
742 | */ | 742 | */ |
743 | unsigned char status; | 743 | unsigned char status; |
744 | int ret1, ret2; | 744 | int ret1, ret2; |
745 | 745 | ||
746 | status = readb(card->csr_remap + MEMCTRLSTATUS_BATTERY); | 746 | status = readb(card->csr_remap + MEMCTRLSTATUS_BATTERY); |
747 | if (debug & DEBUG_BATTERY_POLLING) | 747 | if (debug & DEBUG_BATTERY_POLLING) |
748 | dev_printk(KERN_DEBUG, &card->dev->dev, | 748 | dev_printk(KERN_DEBUG, &card->dev->dev, |
749 | "checking battery status, 1 = %s, 2 = %s\n", | 749 | "checking battery status, 1 = %s, 2 = %s\n", |
750 | (status & BATTERY_1_FAILURE) ? "FAILURE" : "OK", | 750 | (status & BATTERY_1_FAILURE) ? "FAILURE" : "OK", |
751 | (status & BATTERY_2_FAILURE) ? "FAILURE" : "OK"); | 751 | (status & BATTERY_2_FAILURE) ? "FAILURE" : "OK"); |
752 | 752 | ||
753 | ret1 = check_battery(card, 0, !(status & BATTERY_1_FAILURE)); | 753 | ret1 = check_battery(card, 0, !(status & BATTERY_1_FAILURE)); |
754 | ret2 = check_battery(card, 1, !(status & BATTERY_2_FAILURE)); | 754 | ret2 = check_battery(card, 1, !(status & BATTERY_2_FAILURE)); |
755 | 755 | ||
756 | if (ret1 || ret2) | 756 | if (ret1 || ret2) |
757 | set_fault_to_battery_status(card); | 757 | set_fault_to_battery_status(card); |
758 | } | 758 | } |
759 | 759 | ||
760 | static void check_all_batteries(unsigned long ptr) | 760 | static void check_all_batteries(unsigned long ptr) |
761 | { | 761 | { |
762 | int i; | 762 | int i; |
763 | 763 | ||
764 | for (i = 0; i < num_cards; i++) | 764 | for (i = 0; i < num_cards; i++) |
765 | if (!(cards[i].flags & UM_FLAG_NO_BATT)) { | 765 | if (!(cards[i].flags & UM_FLAG_NO_BATT)) { |
766 | struct cardinfo *card = &cards[i]; | 766 | struct cardinfo *card = &cards[i]; |
767 | spin_lock_bh(&card->lock); | 767 | spin_lock_bh(&card->lock); |
768 | if (card->Active >= 0) | 768 | if (card->Active >= 0) |
769 | card->check_batteries = 1; | 769 | card->check_batteries = 1; |
770 | else | 770 | else |
771 | check_batteries(card); | 771 | check_batteries(card); |
772 | spin_unlock_bh(&card->lock); | 772 | spin_unlock_bh(&card->lock); |
773 | } | 773 | } |
774 | 774 | ||
775 | init_battery_timer(); | 775 | init_battery_timer(); |
776 | } | 776 | } |
777 | /* | 777 | /* |
778 | ----------------------------------------------------------------------------------- | 778 | ----------------------------------------------------------------------------------- |
779 | -- init_battery_timer | 779 | -- init_battery_timer |
780 | ----------------------------------------------------------------------------------- | 780 | ----------------------------------------------------------------------------------- |
781 | */ | 781 | */ |
782 | static void init_battery_timer(void) | 782 | static void init_battery_timer(void) |
783 | { | 783 | { |
784 | init_timer(&battery_timer); | 784 | init_timer(&battery_timer); |
785 | battery_timer.function = check_all_batteries; | 785 | battery_timer.function = check_all_batteries; |
786 | battery_timer.expires = jiffies + (HZ * 60); | 786 | battery_timer.expires = jiffies + (HZ * 60); |
787 | add_timer(&battery_timer); | 787 | add_timer(&battery_timer); |
788 | } | 788 | } |
789 | /* | 789 | /* |
790 | ----------------------------------------------------------------------------------- | 790 | ----------------------------------------------------------------------------------- |
791 | -- del_battery_timer | 791 | -- del_battery_timer |
792 | ----------------------------------------------------------------------------------- | 792 | ----------------------------------------------------------------------------------- |
793 | */ | 793 | */ |
794 | static void del_battery_timer(void) | 794 | static void del_battery_timer(void) |
795 | { | 795 | { |
796 | del_timer(&battery_timer); | 796 | del_timer(&battery_timer); |
797 | } | 797 | } |
798 | /* | 798 | /* |
799 | ----------------------------------------------------------------------------------- | 799 | ----------------------------------------------------------------------------------- |
800 | -- mm_revalidate | 800 | -- mm_revalidate |
801 | ----------------------------------------------------------------------------------- | 801 | ----------------------------------------------------------------------------------- |
802 | */ | 802 | */ |
803 | /* | 803 | /* |
804 | * Note no locks taken out here. In a worst case scenario, we could drop | 804 | * Note no locks taken out here. In a worst case scenario, we could drop |
805 | * a chunk of system memory. But that should never happen, since validation | 805 | * a chunk of system memory. But that should never happen, since validation |
806 | * happens at open or mount time, when locks are held. | 806 | * happens at open or mount time, when locks are held. |
807 | * | 807 | * |
808 | * That's crap, since doing that while some partitions are opened | 808 | * That's crap, since doing that while some partitions are opened |
809 | * or mounted will give you really nasty results. | 809 | * or mounted will give you really nasty results. |
810 | */ | 810 | */ |
811 | static int mm_revalidate(struct gendisk *disk) | 811 | static int mm_revalidate(struct gendisk *disk) |
812 | { | 812 | { |
813 | struct cardinfo *card = disk->private_data; | 813 | struct cardinfo *card = disk->private_data; |
814 | set_capacity(disk, card->mm_size << 1); | 814 | set_capacity(disk, card->mm_size << 1); |
815 | return 0; | 815 | return 0; |
816 | } | 816 | } |
817 | 817 | ||
818 | static int mm_getgeo(struct block_device *bdev, struct hd_geometry *geo) | 818 | static int mm_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
819 | { | 819 | { |
820 | struct cardinfo *card = bdev->bd_disk->private_data; | 820 | struct cardinfo *card = bdev->bd_disk->private_data; |
821 | int size = card->mm_size * (1024 / MM_HARDSECT); | 821 | int size = card->mm_size * (1024 / MM_HARDSECT); |
822 | 822 | ||
823 | /* | 823 | /* |
824 | * get geometry: we have to fake one... trim the size to a | 824 | * get geometry: we have to fake one... trim the size to a |
825 | * multiple of 2048 (1M): tell we have 32 sectors, 64 heads, | 825 | * multiple of 2048 (1M): tell we have 32 sectors, 64 heads, |
826 | * whatever cylinders. | 826 | * whatever cylinders. |
827 | */ | 827 | */ |
828 | geo->heads = 64; | 828 | geo->heads = 64; |
829 | geo->sectors = 32; | 829 | geo->sectors = 32; |
830 | geo->cylinders = size / (geo->heads * geo->sectors); | 830 | geo->cylinders = size / (geo->heads * geo->sectors); |
831 | return 0; | 831 | return 0; |
832 | } | 832 | } |
833 | 833 | ||
834 | /* | 834 | /* |
835 | ----------------------------------------------------------------------------------- | 835 | ----------------------------------------------------------------------------------- |
836 | -- mm_check_change | 836 | -- mm_check_change |
837 | ----------------------------------------------------------------------------------- | 837 | ----------------------------------------------------------------------------------- |
838 | Future support for removable devices | 838 | Future support for removable devices |
839 | */ | 839 | */ |
840 | static int mm_check_change(struct gendisk *disk) | 840 | static int mm_check_change(struct gendisk *disk) |
841 | { | 841 | { |
842 | /* struct cardinfo *dev = disk->private_data; */ | 842 | /* struct cardinfo *dev = disk->private_data; */ |
843 | return 0; | 843 | return 0; |
844 | } | 844 | } |
845 | /* | 845 | /* |
846 | ----------------------------------------------------------------------------------- | 846 | ----------------------------------------------------------------------------------- |
847 | -- mm_fops | 847 | -- mm_fops |
848 | ----------------------------------------------------------------------------------- | 848 | ----------------------------------------------------------------------------------- |
849 | */ | 849 | */ |
850 | static struct block_device_operations mm_fops = { | 850 | static struct block_device_operations mm_fops = { |
851 | .owner = THIS_MODULE, | 851 | .owner = THIS_MODULE, |
852 | .getgeo = mm_getgeo, | 852 | .getgeo = mm_getgeo, |
853 | .revalidate_disk= mm_revalidate, | 853 | .revalidate_disk= mm_revalidate, |
854 | .media_changed = mm_check_change, | 854 | .media_changed = mm_check_change, |
855 | }; | 855 | }; |
856 | /* | 856 | /* |
857 | ----------------------------------------------------------------------------------- | 857 | ----------------------------------------------------------------------------------- |
858 | -- mm_pci_probe | 858 | -- mm_pci_probe |
859 | ----------------------------------------------------------------------------------- | 859 | ----------------------------------------------------------------------------------- |
860 | */ | 860 | */ |
861 | static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) | 861 | static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) |
862 | { | 862 | { |
863 | int ret = -ENODEV; | 863 | int ret = -ENODEV; |
864 | struct cardinfo *card = &cards[num_cards]; | 864 | struct cardinfo *card = &cards[num_cards]; |
865 | unsigned char mem_present; | 865 | unsigned char mem_present; |
866 | unsigned char batt_status; | 866 | unsigned char batt_status; |
867 | unsigned int saved_bar, data; | 867 | unsigned int saved_bar, data; |
868 | unsigned long csr_base; | 868 | unsigned long csr_base; |
869 | unsigned long csr_len; | 869 | unsigned long csr_len; |
870 | int magic_number; | 870 | int magic_number; |
871 | static int printed_version; | 871 | static int printed_version; |
872 | 872 | ||
873 | if (!printed_version++) | 873 | if (!printed_version++) |
874 | printk(KERN_INFO DRIVER_VERSION " : " DRIVER_DESC "\n"); | 874 | printk(KERN_INFO DRIVER_VERSION " : " DRIVER_DESC "\n"); |
875 | 875 | ||
876 | ret = pci_enable_device(dev); | 876 | ret = pci_enable_device(dev); |
877 | if (ret) | 877 | if (ret) |
878 | return ret; | 878 | return ret; |
879 | 879 | ||
880 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF8); | 880 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF8); |
881 | pci_set_master(dev); | 881 | pci_set_master(dev); |
882 | 882 | ||
883 | card->dev = dev; | 883 | card->dev = dev; |
884 | 884 | ||
885 | csr_base = pci_resource_start(dev, 0); | 885 | csr_base = pci_resource_start(dev, 0); |
886 | csr_len = pci_resource_len(dev, 0); | 886 | csr_len = pci_resource_len(dev, 0); |
887 | if (!csr_base || !csr_len) | 887 | if (!csr_base || !csr_len) |
888 | return -ENODEV; | 888 | return -ENODEV; |
889 | 889 | ||
890 | dev_printk(KERN_INFO, &dev->dev, | 890 | dev_printk(KERN_INFO, &dev->dev, |
891 | "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n"); | 891 | "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n"); |
892 | 892 | ||
893 | if (pci_set_dma_mask(dev, DMA_64BIT_MASK) && | 893 | if (pci_set_dma_mask(dev, DMA_64BIT_MASK) && |
894 | pci_set_dma_mask(dev, DMA_32BIT_MASK)) { | 894 | pci_set_dma_mask(dev, DMA_32BIT_MASK)) { |
895 | dev_printk(KERN_WARNING, &dev->dev, "NO suitable DMA found\n"); | 895 | dev_printk(KERN_WARNING, &dev->dev, "NO suitable DMA found\n"); |
896 | return -ENOMEM; | 896 | return -ENOMEM; |
897 | } | 897 | } |
898 | 898 | ||
899 | ret = pci_request_regions(dev, DRIVER_NAME); | 899 | ret = pci_request_regions(dev, DRIVER_NAME); |
900 | if (ret) { | 900 | if (ret) { |
901 | dev_printk(KERN_ERR, &card->dev->dev, | 901 | dev_printk(KERN_ERR, &card->dev->dev, |
902 | "Unable to request memory region\n"); | 902 | "Unable to request memory region\n"); |
903 | goto failed_req_csr; | 903 | goto failed_req_csr; |
904 | } | 904 | } |
905 | 905 | ||
906 | card->csr_remap = ioremap_nocache(csr_base, csr_len); | 906 | card->csr_remap = ioremap_nocache(csr_base, csr_len); |
907 | if (!card->csr_remap) { | 907 | if (!card->csr_remap) { |
908 | dev_printk(KERN_ERR, &card->dev->dev, | 908 | dev_printk(KERN_ERR, &card->dev->dev, |
909 | "Unable to remap memory region\n"); | 909 | "Unable to remap memory region\n"); |
910 | ret = -ENOMEM; | 910 | ret = -ENOMEM; |
911 | 911 | ||
912 | goto failed_remap_csr; | 912 | goto failed_remap_csr; |
913 | } | 913 | } |
914 | 914 | ||
915 | dev_printk(KERN_INFO, &card->dev->dev, | 915 | dev_printk(KERN_INFO, &card->dev->dev, |
916 | "CSR 0x%08lx -> 0x%p (0x%lx)\n", | 916 | "CSR 0x%08lx -> 0x%p (0x%lx)\n", |
917 | csr_base, card->csr_remap, csr_len); | 917 | csr_base, card->csr_remap, csr_len); |
918 | 918 | ||
919 | switch(card->dev->device) { | 919 | switch(card->dev->device) { |
920 | case 0x5415: | 920 | case 0x5415: |
921 | card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG; | 921 | card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG; |
922 | magic_number = 0x59; | 922 | magic_number = 0x59; |
923 | break; | 923 | break; |
924 | 924 | ||
925 | case 0x5425: | 925 | case 0x5425: |
926 | card->flags |= UM_FLAG_NO_BYTE_STATUS; | 926 | card->flags |= UM_FLAG_NO_BYTE_STATUS; |
927 | magic_number = 0x5C; | 927 | magic_number = 0x5C; |
928 | break; | 928 | break; |
929 | 929 | ||
930 | case 0x6155: | 930 | case 0x6155: |
931 | card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG | UM_FLAG_NO_BATT; | 931 | card->flags |= UM_FLAG_NO_BYTE_STATUS | UM_FLAG_NO_BATTREG | UM_FLAG_NO_BATT; |
932 | magic_number = 0x99; | 932 | magic_number = 0x99; |
933 | break; | 933 | break; |
934 | 934 | ||
935 | default: | 935 | default: |
936 | magic_number = 0x100; | 936 | magic_number = 0x100; |
937 | break; | 937 | break; |
938 | } | 938 | } |
939 | 939 | ||
940 | if (readb(card->csr_remap + MEMCTRLSTATUS_MAGIC) != magic_number) { | 940 | if (readb(card->csr_remap + MEMCTRLSTATUS_MAGIC) != magic_number) { |
941 | dev_printk(KERN_ERR, &card->dev->dev, "Magic number invalid\n"); | 941 | dev_printk(KERN_ERR, &card->dev->dev, "Magic number invalid\n"); |
942 | ret = -ENOMEM; | 942 | ret = -ENOMEM; |
943 | goto failed_magic; | 943 | goto failed_magic; |
944 | } | 944 | } |
945 | 945 | ||
946 | card->mm_pages[0].desc = pci_alloc_consistent(card->dev, | 946 | card->mm_pages[0].desc = pci_alloc_consistent(card->dev, |
947 | PAGE_SIZE*2, | 947 | PAGE_SIZE*2, |
948 | &card->mm_pages[0].page_dma); | 948 | &card->mm_pages[0].page_dma); |
949 | card->mm_pages[1].desc = pci_alloc_consistent(card->dev, | 949 | card->mm_pages[1].desc = pci_alloc_consistent(card->dev, |
950 | PAGE_SIZE*2, | 950 | PAGE_SIZE*2, |
951 | &card->mm_pages[1].page_dma); | 951 | &card->mm_pages[1].page_dma); |
952 | if (card->mm_pages[0].desc == NULL || | 952 | if (card->mm_pages[0].desc == NULL || |
953 | card->mm_pages[1].desc == NULL) { | 953 | card->mm_pages[1].desc == NULL) { |
954 | dev_printk(KERN_ERR, &card->dev->dev, "alloc failed\n"); | 954 | dev_printk(KERN_ERR, &card->dev->dev, "alloc failed\n"); |
955 | goto failed_alloc; | 955 | goto failed_alloc; |
956 | } | 956 | } |
957 | reset_page(&card->mm_pages[0]); | 957 | reset_page(&card->mm_pages[0]); |
958 | reset_page(&card->mm_pages[1]); | 958 | reset_page(&card->mm_pages[1]); |
959 | card->Ready = 0; /* page 0 is ready */ | 959 | card->Ready = 0; /* page 0 is ready */ |
960 | card->Active = -1; /* no page is active */ | 960 | card->Active = -1; /* no page is active */ |
961 | card->bio = NULL; | 961 | card->bio = NULL; |
962 | card->biotail = &card->bio; | 962 | card->biotail = &card->bio; |
963 | 963 | ||
964 | card->queue = blk_alloc_queue(GFP_KERNEL); | 964 | card->queue = blk_alloc_queue(GFP_KERNEL); |
965 | if (!card->queue) | 965 | if (!card->queue) |
966 | goto failed_alloc; | 966 | goto failed_alloc; |
967 | 967 | ||
968 | blk_queue_make_request(card->queue, mm_make_request); | 968 | blk_queue_make_request(card->queue, mm_make_request); |
969 | card->queue->queuedata = card; | 969 | card->queue->queuedata = card; |
970 | card->queue->unplug_fn = mm_unplug_device; | 970 | card->queue->unplug_fn = mm_unplug_device; |
971 | 971 | ||
972 | tasklet_init(&card->tasklet, process_page, (unsigned long)card); | 972 | tasklet_init(&card->tasklet, process_page, (unsigned long)card); |
973 | 973 | ||
974 | card->check_batteries = 0; | 974 | card->check_batteries = 0; |
975 | 975 | ||
976 | mem_present = readb(card->csr_remap + MEMCTRLSTATUS_MEMORY); | 976 | mem_present = readb(card->csr_remap + MEMCTRLSTATUS_MEMORY); |
977 | switch (mem_present) { | 977 | switch (mem_present) { |
978 | case MEM_128_MB: | 978 | case MEM_128_MB: |
979 | card->mm_size = 1024 * 128; | 979 | card->mm_size = 1024 * 128; |
980 | break; | 980 | break; |
981 | case MEM_256_MB: | 981 | case MEM_256_MB: |
982 | card->mm_size = 1024 * 256; | 982 | card->mm_size = 1024 * 256; |
983 | break; | 983 | break; |
984 | case MEM_512_MB: | 984 | case MEM_512_MB: |
985 | card->mm_size = 1024 * 512; | 985 | card->mm_size = 1024 * 512; |
986 | break; | 986 | break; |
987 | case MEM_1_GB: | 987 | case MEM_1_GB: |
988 | card->mm_size = 1024 * 1024; | 988 | card->mm_size = 1024 * 1024; |
989 | break; | 989 | break; |
990 | case MEM_2_GB: | 990 | case MEM_2_GB: |
991 | card->mm_size = 1024 * 2048; | 991 | card->mm_size = 1024 * 2048; |
992 | break; | 992 | break; |
993 | default: | 993 | default: |
994 | card->mm_size = 0; | 994 | card->mm_size = 0; |
995 | break; | 995 | break; |
996 | } | 996 | } |
997 | 997 | ||
998 | /* Clear the LED's we control */ | 998 | /* Clear the LED's we control */ |
999 | set_led(card, LED_REMOVE, LED_OFF); | 999 | set_led(card, LED_REMOVE, LED_OFF); |
1000 | set_led(card, LED_FAULT, LED_OFF); | 1000 | set_led(card, LED_FAULT, LED_OFF); |
1001 | 1001 | ||
1002 | batt_status = readb(card->csr_remap + MEMCTRLSTATUS_BATTERY); | 1002 | batt_status = readb(card->csr_remap + MEMCTRLSTATUS_BATTERY); |
1003 | 1003 | ||
1004 | card->battery[0].good = !(batt_status & BATTERY_1_FAILURE); | 1004 | card->battery[0].good = !(batt_status & BATTERY_1_FAILURE); |
1005 | card->battery[1].good = !(batt_status & BATTERY_2_FAILURE); | 1005 | card->battery[1].good = !(batt_status & BATTERY_2_FAILURE); |
1006 | card->battery[0].last_change = card->battery[1].last_change = jiffies; | 1006 | card->battery[0].last_change = card->battery[1].last_change = jiffies; |
1007 | 1007 | ||
1008 | if (card->flags & UM_FLAG_NO_BATT) | 1008 | if (card->flags & UM_FLAG_NO_BATT) |
1009 | dev_printk(KERN_INFO, &card->dev->dev, | 1009 | dev_printk(KERN_INFO, &card->dev->dev, |
1010 | "Size %d KB\n", card->mm_size); | 1010 | "Size %d KB\n", card->mm_size); |
1011 | else { | 1011 | else { |
1012 | dev_printk(KERN_INFO, &card->dev->dev, | 1012 | dev_printk(KERN_INFO, &card->dev->dev, |
1013 | "Size %d KB, Battery 1 %s (%s), Battery 2 %s (%s)\n", | 1013 | "Size %d KB, Battery 1 %s (%s), Battery 2 %s (%s)\n", |
1014 | card->mm_size, | 1014 | card->mm_size, |
1015 | (batt_status & BATTERY_1_DISABLED ? "Disabled" : "Enabled"), | 1015 | (batt_status & BATTERY_1_DISABLED ? "Disabled" : "Enabled"), |
1016 | card->battery[0].good ? "OK" : "FAILURE", | 1016 | card->battery[0].good ? "OK" : "FAILURE", |
1017 | (batt_status & BATTERY_2_DISABLED ? "Disabled" : "Enabled"), | 1017 | (batt_status & BATTERY_2_DISABLED ? "Disabled" : "Enabled"), |
1018 | card->battery[1].good ? "OK" : "FAILURE"); | 1018 | card->battery[1].good ? "OK" : "FAILURE"); |
1019 | 1019 | ||
1020 | set_fault_to_battery_status(card); | 1020 | set_fault_to_battery_status(card); |
1021 | } | 1021 | } |
1022 | 1022 | ||
1023 | pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, &saved_bar); | 1023 | pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, &saved_bar); |
1024 | data = 0xffffffff; | 1024 | data = 0xffffffff; |
1025 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, data); | 1025 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, data); |
1026 | pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, &data); | 1026 | pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, &data); |
1027 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, saved_bar); | 1027 | pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, saved_bar); |
1028 | data &= 0xfffffff0; | 1028 | data &= 0xfffffff0; |
1029 | data = ~data; | 1029 | data = ~data; |
1030 | data += 1; | 1030 | data += 1; |
1031 | 1031 | ||
1032 | if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, "pci-umem", card)) { | 1032 | if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, "pci-umem", card)) { |
1033 | dev_printk(KERN_ERR, &card->dev->dev, | 1033 | dev_printk(KERN_ERR, &card->dev->dev, |
1034 | "Unable to allocate IRQ\n"); | 1034 | "Unable to allocate IRQ\n"); |
1035 | ret = -ENODEV; | 1035 | ret = -ENODEV; |
1036 | 1036 | ||
1037 | goto failed_req_irq; | 1037 | goto failed_req_irq; |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | dev_printk(KERN_INFO, &card->dev->dev, | 1040 | dev_printk(KERN_INFO, &card->dev->dev, |
1041 | "Window size %d bytes, IRQ %d\n", data, dev->irq); | 1041 | "Window size %d bytes, IRQ %d\n", data, dev->irq); |
1042 | 1042 | ||
1043 | spin_lock_init(&card->lock); | 1043 | spin_lock_init(&card->lock); |
1044 | 1044 | ||
1045 | pci_set_drvdata(dev, card); | 1045 | pci_set_drvdata(dev, card); |
1046 | 1046 | ||
1047 | if (pci_write_cmd != 0x0F) /* If not Memory Write & Invalidate */ | 1047 | if (pci_write_cmd != 0x0F) /* If not Memory Write & Invalidate */ |
1048 | pci_write_cmd = 0x07; /* then Memory Write command */ | 1048 | pci_write_cmd = 0x07; /* then Memory Write command */ |
1049 | 1049 | ||
1050 | if (pci_write_cmd & 0x08) { /* use Memory Write and Invalidate */ | 1050 | if (pci_write_cmd & 0x08) { /* use Memory Write and Invalidate */ |
1051 | unsigned short cfg_command; | 1051 | unsigned short cfg_command; |
1052 | pci_read_config_word(dev, PCI_COMMAND, &cfg_command); | 1052 | pci_read_config_word(dev, PCI_COMMAND, &cfg_command); |
1053 | cfg_command |= 0x10; /* Memory Write & Invalidate Enable */ | 1053 | cfg_command |= 0x10; /* Memory Write & Invalidate Enable */ |
1054 | pci_write_config_word(dev, PCI_COMMAND, cfg_command); | 1054 | pci_write_config_word(dev, PCI_COMMAND, cfg_command); |
1055 | } | 1055 | } |
1056 | pci_cmds = (pci_read_cmd << 28) | (pci_write_cmd << 24); | 1056 | pci_cmds = (pci_read_cmd << 28) | (pci_write_cmd << 24); |
1057 | 1057 | ||
1058 | num_cards++; | 1058 | num_cards++; |
1059 | 1059 | ||
1060 | if (!get_userbit(card, MEMORY_INITIALIZED)) { | 1060 | if (!get_userbit(card, MEMORY_INITIALIZED)) { |
1061 | dev_printk(KERN_INFO, &card->dev->dev, | 1061 | dev_printk(KERN_INFO, &card->dev->dev, |
1062 | "memory NOT initialized. Consider over-writing whole device.\n"); | 1062 | "memory NOT initialized. Consider over-writing whole device.\n"); |
1063 | card->init_size = 0; | 1063 | card->init_size = 0; |
1064 | } else { | 1064 | } else { |
1065 | dev_printk(KERN_INFO, &card->dev->dev, | 1065 | dev_printk(KERN_INFO, &card->dev->dev, |
1066 | "memory already initialized\n"); | 1066 | "memory already initialized\n"); |
1067 | card->init_size = card->mm_size; | 1067 | card->init_size = card->mm_size; |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | /* Enable ECC */ | 1070 | /* Enable ECC */ |
1071 | writeb(EDC_STORE_CORRECT, card->csr_remap + MEMCTRLCMD_ERRCTRL); | 1071 | writeb(EDC_STORE_CORRECT, card->csr_remap + MEMCTRLCMD_ERRCTRL); |
1072 | 1072 | ||
1073 | return 0; | 1073 | return 0; |
1074 | 1074 | ||
1075 | failed_req_irq: | 1075 | failed_req_irq: |
1076 | failed_alloc: | 1076 | failed_alloc: |
1077 | if (card->mm_pages[0].desc) | 1077 | if (card->mm_pages[0].desc) |
1078 | pci_free_consistent(card->dev, PAGE_SIZE*2, | 1078 | pci_free_consistent(card->dev, PAGE_SIZE*2, |
1079 | card->mm_pages[0].desc, | 1079 | card->mm_pages[0].desc, |
1080 | card->mm_pages[0].page_dma); | 1080 | card->mm_pages[0].page_dma); |
1081 | if (card->mm_pages[1].desc) | 1081 | if (card->mm_pages[1].desc) |
1082 | pci_free_consistent(card->dev, PAGE_SIZE*2, | 1082 | pci_free_consistent(card->dev, PAGE_SIZE*2, |
1083 | card->mm_pages[1].desc, | 1083 | card->mm_pages[1].desc, |
1084 | card->mm_pages[1].page_dma); | 1084 | card->mm_pages[1].page_dma); |
1085 | failed_magic: | 1085 | failed_magic: |
1086 | iounmap(card->csr_remap); | 1086 | iounmap(card->csr_remap); |
1087 | failed_remap_csr: | 1087 | failed_remap_csr: |
1088 | pci_release_regions(dev); | 1088 | pci_release_regions(dev); |
1089 | failed_req_csr: | 1089 | failed_req_csr: |
1090 | 1090 | ||
1091 | return ret; | 1091 | return ret; |
1092 | } | 1092 | } |
1093 | /* | 1093 | /* |
1094 | ----------------------------------------------------------------------------------- | 1094 | ----------------------------------------------------------------------------------- |
1095 | -- mm_pci_remove | 1095 | -- mm_pci_remove |
1096 | ----------------------------------------------------------------------------------- | 1096 | ----------------------------------------------------------------------------------- |
1097 | */ | 1097 | */ |
1098 | static void mm_pci_remove(struct pci_dev *dev) | 1098 | static void mm_pci_remove(struct pci_dev *dev) |
1099 | { | 1099 | { |
1100 | struct cardinfo *card = pci_get_drvdata(dev); | 1100 | struct cardinfo *card = pci_get_drvdata(dev); |
1101 | 1101 | ||
1102 | tasklet_kill(&card->tasklet); | 1102 | tasklet_kill(&card->tasklet); |
1103 | free_irq(dev->irq, card); | 1103 | free_irq(dev->irq, card); |
1104 | iounmap(card->csr_remap); | 1104 | iounmap(card->csr_remap); |
1105 | 1105 | ||
1106 | if (card->mm_pages[0].desc) | 1106 | if (card->mm_pages[0].desc) |
1107 | pci_free_consistent(card->dev, PAGE_SIZE*2, | 1107 | pci_free_consistent(card->dev, PAGE_SIZE*2, |
1108 | card->mm_pages[0].desc, | 1108 | card->mm_pages[0].desc, |
1109 | card->mm_pages[0].page_dma); | 1109 | card->mm_pages[0].page_dma); |
1110 | if (card->mm_pages[1].desc) | 1110 | if (card->mm_pages[1].desc) |
1111 | pci_free_consistent(card->dev, PAGE_SIZE*2, | 1111 | pci_free_consistent(card->dev, PAGE_SIZE*2, |
1112 | card->mm_pages[1].desc, | 1112 | card->mm_pages[1].desc, |
1113 | card->mm_pages[1].page_dma); | 1113 | card->mm_pages[1].page_dma); |
1114 | blk_cleanup_queue(card->queue); | 1114 | blk_cleanup_queue(card->queue); |
1115 | 1115 | ||
1116 | pci_release_regions(dev); | 1116 | pci_release_regions(dev); |
1117 | pci_disable_device(dev); | 1117 | pci_disable_device(dev); |
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | static const struct pci_device_id mm_pci_ids[] = { | 1120 | static const struct pci_device_id mm_pci_ids[] = { |
1121 | {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5415CN)}, | 1121 | {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5415CN)}, |
1122 | {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5425CN)}, | 1122 | {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_5425CN)}, |
1123 | {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_6155)}, | 1123 | {PCI_DEVICE(PCI_VENDOR_ID_MICRO_MEMORY,PCI_DEVICE_ID_MICRO_MEMORY_6155)}, |
1124 | { | 1124 | { |
1125 | .vendor = 0x8086, | 1125 | .vendor = 0x8086, |
1126 | .device = 0xB555, | 1126 | .device = 0xB555, |
1127 | .subvendor= 0x1332, | 1127 | .subvendor= 0x1332, |
1128 | .subdevice= 0x5460, | 1128 | .subdevice= 0x5460, |
1129 | .class = 0x050000, | 1129 | .class = 0x050000, |
1130 | .class_mask= 0, | 1130 | .class_mask= 0, |
1131 | }, { /* end: all zeroes */ } | 1131 | }, { /* end: all zeroes */ } |
1132 | }; | 1132 | }; |
1133 | 1133 | ||
1134 | MODULE_DEVICE_TABLE(pci, mm_pci_ids); | 1134 | MODULE_DEVICE_TABLE(pci, mm_pci_ids); |
1135 | 1135 | ||
1136 | static struct pci_driver mm_pci_driver = { | 1136 | static struct pci_driver mm_pci_driver = { |
1137 | .name = DRIVER_NAME, | 1137 | .name = DRIVER_NAME, |
1138 | .id_table = mm_pci_ids, | 1138 | .id_table = mm_pci_ids, |
1139 | .probe = mm_pci_probe, | 1139 | .probe = mm_pci_probe, |
1140 | .remove = mm_pci_remove, | 1140 | .remove = mm_pci_remove, |
1141 | }; | 1141 | }; |
1142 | 1142 | ||
1143 | /* | 1143 | /* |
1144 | ----------------------------------------------------------------------------------- | 1144 | ----------------------------------------------------------------------------------- |
1145 | -- mm_init | 1145 | -- mm_init |
1146 | ----------------------------------------------------------------------------------- | 1146 | ----------------------------------------------------------------------------------- |
1147 | */ | 1147 | */ |
1148 | 1148 | ||
1149 | static int __init mm_init(void) | 1149 | static int __init mm_init(void) |
1150 | { | 1150 | { |
1151 | int retval, i; | 1151 | int retval, i; |
1152 | int err; | 1152 | int err; |
1153 | 1153 | ||
1154 | retval = pci_register_driver(&mm_pci_driver); | 1154 | retval = pci_register_driver(&mm_pci_driver); |
1155 | if (retval) | 1155 | if (retval) |
1156 | return -ENOMEM; | 1156 | return -ENOMEM; |
1157 | 1157 | ||
1158 | err = major_nr = register_blkdev(0, "umem"); | 1158 | err = major_nr = register_blkdev(0, "umem"); |
1159 | if (err < 0) { | 1159 | if (err < 0) { |
1160 | pci_unregister_driver(&mm_pci_driver); | 1160 | pci_unregister_driver(&mm_pci_driver); |
1161 | return -EIO; | 1161 | return -EIO; |
1162 | } | 1162 | } |
1163 | 1163 | ||
1164 | for (i = 0; i < num_cards; i++) { | 1164 | for (i = 0; i < num_cards; i++) { |
1165 | mm_gendisk[i] = alloc_disk(1 << MM_SHIFT); | 1165 | mm_gendisk[i] = alloc_disk(1 << MM_SHIFT); |
1166 | if (!mm_gendisk[i]) | 1166 | if (!mm_gendisk[i]) |
1167 | goto out; | 1167 | goto out; |
1168 | } | 1168 | } |
1169 | 1169 | ||
1170 | for (i = 0; i < num_cards; i++) { | 1170 | for (i = 0; i < num_cards; i++) { |
1171 | struct gendisk *disk = mm_gendisk[i]; | 1171 | struct gendisk *disk = mm_gendisk[i]; |
1172 | sprintf(disk->disk_name, "umem%c", 'a'+i); | 1172 | sprintf(disk->disk_name, "umem%c", 'a'+i); |
1173 | spin_lock_init(&cards[i].lock); | 1173 | spin_lock_init(&cards[i].lock); |
1174 | disk->major = major_nr; | 1174 | disk->major = major_nr; |
1175 | disk->first_minor = i << MM_SHIFT; | 1175 | disk->first_minor = i << MM_SHIFT; |
1176 | disk->fops = &mm_fops; | 1176 | disk->fops = &mm_fops; |
1177 | disk->private_data = &cards[i]; | 1177 | disk->private_data = &cards[i]; |
1178 | disk->queue = cards[i].queue; | 1178 | disk->queue = cards[i].queue; |
1179 | set_capacity(disk, cards[i].mm_size << 1); | 1179 | set_capacity(disk, cards[i].mm_size << 1); |
1180 | add_disk(disk); | 1180 | add_disk(disk); |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | init_battery_timer(); | 1183 | init_battery_timer(); |
1184 | printk(KERN_INFO "MM: desc_per_page = %ld\n", DESC_PER_PAGE); | 1184 | printk(KERN_INFO "MM: desc_per_page = %ld\n", DESC_PER_PAGE); |
1185 | /* printk("mm_init: Done. 10-19-01 9:00\n"); */ | 1185 | /* printk("mm_init: Done. 10-19-01 9:00\n"); */ |
1186 | return 0; | 1186 | return 0; |
1187 | 1187 | ||
1188 | out: | 1188 | out: |
1189 | pci_unregister_driver(&mm_pci_driver); | 1189 | pci_unregister_driver(&mm_pci_driver); |
1190 | unregister_blkdev(major_nr, "umem"); | 1190 | unregister_blkdev(major_nr, "umem"); |
1191 | while (i--) | 1191 | while (i--) |
1192 | put_disk(mm_gendisk[i]); | 1192 | put_disk(mm_gendisk[i]); |
1193 | return -ENOMEM; | 1193 | return -ENOMEM; |
1194 | } | 1194 | } |
1195 | /* | 1195 | /* |
1196 | ----------------------------------------------------------------------------------- | 1196 | ----------------------------------------------------------------------------------- |
1197 | -- mm_cleanup | 1197 | -- mm_cleanup |
1198 | ----------------------------------------------------------------------------------- | 1198 | ----------------------------------------------------------------------------------- |
1199 | */ | 1199 | */ |
1200 | static void __exit mm_cleanup(void) | 1200 | static void __exit mm_cleanup(void) |
1201 | { | 1201 | { |
1202 | int i; | 1202 | int i; |
1203 | 1203 | ||
1204 | del_battery_timer(); | 1204 | del_battery_timer(); |
1205 | 1205 | ||
1206 | for (i=0; i < num_cards ; i++) { | 1206 | for (i=0; i < num_cards ; i++) { |
1207 | del_gendisk(mm_gendisk[i]); | 1207 | del_gendisk(mm_gendisk[i]); |
1208 | put_disk(mm_gendisk[i]); | 1208 | put_disk(mm_gendisk[i]); |
1209 | } | 1209 | } |
1210 | 1210 | ||
1211 | pci_unregister_driver(&mm_pci_driver); | 1211 | pci_unregister_driver(&mm_pci_driver); |
1212 | 1212 | ||
1213 | unregister_blkdev(major_nr, "umem"); | 1213 | unregister_blkdev(major_nr, "umem"); |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | module_init(mm_init); | 1216 | module_init(mm_init); |
1217 | module_exit(mm_cleanup); | 1217 | module_exit(mm_cleanup); |
1218 | 1218 | ||
1219 | MODULE_AUTHOR(DRIVER_AUTHOR); | 1219 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1220 | MODULE_DESCRIPTION(DRIVER_DESC); | 1220 | MODULE_DESCRIPTION(DRIVER_DESC); |
1221 | MODULE_LICENSE("GPL"); | 1221 | MODULE_LICENSE("GPL"); |
1222 | 1222 |
drivers/block/umem.h
1 | 1 | ||
2 | /* | 2 | /* |
3 | * This file contains defines for the | 3 | * This file contains defines for the |
4 | * Micro Memory MM5415 | 4 | * Micro Memory MM5415 |
5 | * family PCI Memory Module with Battery Backup. | 5 | * family PCI Memory Module with Battery Backup. |
6 | * | 6 | * |
7 | * Copyright Micro Memory INC 2001. All rights reserved. | 7 | * Copyright Micro Memory INC 2001. All rights reserved. |
8 | * Release under the terms of the GNU GENERAL PUBLIC LICENSE version 2. | 8 | * Release under the terms of the GNU GENERAL PUBLIC LICENSE version 2. |
9 | * See the file COPYING. | 9 | * See the file COPYING. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #ifndef _DRIVERS_BLOCK_MM_H | 12 | #ifndef _DRIVERS_BLOCK_MM_H |
13 | #define _DRIVERS_BLOCK_MM_H | 13 | #define _DRIVERS_BLOCK_MM_H |
14 | 14 | ||
15 | 15 | ||
16 | #define IRQ_TIMEOUT (1 * HZ) | 16 | #define IRQ_TIMEOUT (1 * HZ) |
17 | 17 | ||
18 | /* CSR register definition */ | 18 | /* CSR register definition */ |
19 | #define MEMCTRLSTATUS_MAGIC 0x00 | 19 | #define MEMCTRLSTATUS_MAGIC 0x00 |
20 | #define MM_MAGIC_VALUE (unsigned char)0x59 | 20 | #define MM_MAGIC_VALUE (unsigned char)0x59 |
21 | 21 | ||
22 | #define MEMCTRLSTATUS_BATTERY 0x04 | 22 | #define MEMCTRLSTATUS_BATTERY 0x04 |
23 | #define BATTERY_1_DISABLED 0x01 | 23 | #define BATTERY_1_DISABLED 0x01 |
24 | #define BATTERY_1_FAILURE 0x02 | 24 | #define BATTERY_1_FAILURE 0x02 |
25 | #define BATTERY_2_DISABLED 0x04 | 25 | #define BATTERY_2_DISABLED 0x04 |
26 | #define BATTERY_2_FAILURE 0x08 | 26 | #define BATTERY_2_FAILURE 0x08 |
27 | 27 | ||
28 | #define MEMCTRLSTATUS_MEMORY 0x07 | 28 | #define MEMCTRLSTATUS_MEMORY 0x07 |
29 | #define MEM_128_MB 0xfe | 29 | #define MEM_128_MB 0xfe |
30 | #define MEM_256_MB 0xfc | 30 | #define MEM_256_MB 0xfc |
31 | #define MEM_512_MB 0xf8 | 31 | #define MEM_512_MB 0xf8 |
32 | #define MEM_1_GB 0xf0 | 32 | #define MEM_1_GB 0xf0 |
33 | #define MEM_2_GB 0xe0 | 33 | #define MEM_2_GB 0xe0 |
34 | 34 | ||
35 | #define MEMCTRLCMD_LEDCTRL 0x08 | 35 | #define MEMCTRLCMD_LEDCTRL 0x08 |
36 | #define LED_REMOVE 2 | 36 | #define LED_REMOVE 2 |
37 | #define LED_FAULT 4 | 37 | #define LED_FAULT 4 |
38 | #define LED_POWER 6 | 38 | #define LED_POWER 6 |
39 | #define LED_FLIP 255 | 39 | #define LED_FLIP 255 |
40 | #define LED_OFF 0x00 | 40 | #define LED_OFF 0x00 |
41 | #define LED_ON 0x01 | 41 | #define LED_ON 0x01 |
42 | #define LED_FLASH_3_5 0x02 | 42 | #define LED_FLASH_3_5 0x02 |
43 | #define LED_FLASH_7_0 0x03 | 43 | #define LED_FLASH_7_0 0x03 |
44 | #define LED_POWER_ON 0x00 | 44 | #define LED_POWER_ON 0x00 |
45 | #define LED_POWER_OFF 0x01 | 45 | #define LED_POWER_OFF 0x01 |
46 | #define USER_BIT1 0x01 | 46 | #define USER_BIT1 0x01 |
47 | #define USER_BIT2 0x02 | 47 | #define USER_BIT2 0x02 |
48 | 48 | ||
49 | #define MEMORY_INITIALIZED USER_BIT1 | 49 | #define MEMORY_INITIALIZED USER_BIT1 |
50 | 50 | ||
51 | #define MEMCTRLCMD_ERRCTRL 0x0C | 51 | #define MEMCTRLCMD_ERRCTRL 0x0C |
52 | #define EDC_NONE_DEFAULT 0x00 | 52 | #define EDC_NONE_DEFAULT 0x00 |
53 | #define EDC_NONE 0x01 | 53 | #define EDC_NONE 0x01 |
54 | #define EDC_STORE_READ 0x02 | 54 | #define EDC_STORE_READ 0x02 |
55 | #define EDC_STORE_CORRECT 0x03 | 55 | #define EDC_STORE_CORRECT 0x03 |
56 | 56 | ||
57 | #define MEMCTRLCMD_ERRCNT 0x0D | 57 | #define MEMCTRLCMD_ERRCNT 0x0D |
58 | #define MEMCTRLCMD_ERRSTATUS 0x0E | 58 | #define MEMCTRLCMD_ERRSTATUS 0x0E |
59 | 59 | ||
60 | #define ERROR_DATA_LOG 0x20 | 60 | #define ERROR_DATA_LOG 0x20 |
61 | #define ERROR_ADDR_LOG 0x28 | 61 | #define ERROR_ADDR_LOG 0x28 |
62 | #define ERROR_COUNT 0x3D | 62 | #define ERROR_COUNT 0x3D |
63 | #define ERROR_SYNDROME 0x3E | 63 | #define ERROR_SYNDROME 0x3E |
64 | #define ERROR_CHECK 0x3F | 64 | #define ERROR_CHECK 0x3F |
65 | 65 | ||
66 | #define DMA_PCI_ADDR 0x40 | 66 | #define DMA_PCI_ADDR 0x40 |
67 | #define DMA_LOCAL_ADDR 0x48 | 67 | #define DMA_LOCAL_ADDR 0x48 |
68 | #define DMA_TRANSFER_SIZE 0x50 | 68 | #define DMA_TRANSFER_SIZE 0x50 |
69 | #define DMA_DESCRIPTOR_ADDR 0x58 | 69 | #define DMA_DESCRIPTOR_ADDR 0x58 |
70 | #define DMA_SEMAPHORE_ADDR 0x60 | 70 | #define DMA_SEMAPHORE_ADDR 0x60 |
71 | #define DMA_STATUS_CTRL 0x68 | 71 | #define DMA_STATUS_CTRL 0x68 |
72 | #define DMASCR_GO 0x00001 | 72 | #define DMASCR_GO 0x00001 |
73 | #define DMASCR_TRANSFER_READ 0x00002 | 73 | #define DMASCR_TRANSFER_READ 0x00002 |
74 | #define DMASCR_CHAIN_EN 0x00004 | 74 | #define DMASCR_CHAIN_EN 0x00004 |
75 | #define DMASCR_SEM_EN 0x00010 | 75 | #define DMASCR_SEM_EN 0x00010 |
76 | #define DMASCR_DMA_COMP_EN 0x00020 | 76 | #define DMASCR_DMA_COMP_EN 0x00020 |
77 | #define DMASCR_CHAIN_COMP_EN 0x00040 | 77 | #define DMASCR_CHAIN_COMP_EN 0x00040 |
78 | #define DMASCR_ERR_INT_EN 0x00080 | 78 | #define DMASCR_ERR_INT_EN 0x00080 |
79 | #define DMASCR_PARITY_INT_EN 0x00100 | 79 | #define DMASCR_PARITY_INT_EN 0x00100 |
80 | #define DMASCR_ANY_ERR 0x00800 | 80 | #define DMASCR_ANY_ERR 0x00800 |
81 | #define DMASCR_MBE_ERR 0x01000 | 81 | #define DMASCR_MBE_ERR 0x01000 |
82 | #define DMASCR_PARITY_ERR_REP 0x02000 | 82 | #define DMASCR_PARITY_ERR_REP 0x02000 |
83 | #define DMASCR_PARITY_ERR_DET 0x04000 | 83 | #define DMASCR_PARITY_ERR_DET 0x04000 |
84 | #define DMASCR_SYSTEM_ERR_SIG 0x08000 | 84 | #define DMASCR_SYSTEM_ERR_SIG 0x08000 |
85 | #define DMASCR_TARGET_ABT 0x10000 | 85 | #define DMASCR_TARGET_ABT 0x10000 |
86 | #define DMASCR_MASTER_ABT 0x20000 | 86 | #define DMASCR_MASTER_ABT 0x20000 |
87 | #define DMASCR_DMA_COMPLETE 0x40000 | 87 | #define DMASCR_DMA_COMPLETE 0x40000 |
88 | #define DMASCR_CHAIN_COMPLETE 0x80000 | 88 | #define DMASCR_CHAIN_COMPLETE 0x80000 |
89 | 89 | ||
90 | /* | 90 | /* |
91 | 3.SOME PCs HAVE HOST BRIDGES WHICH APPARENTLY DO NOT CORRECTLY HANDLE | 91 | 3.SOME PCs HAVE HOST BRIDGES WHICH APPARENTLY DO NOT CORRECTLY HANDLE |
92 | READ-LINE (0xE) OR READ-MULTIPLE (0xC) PCI COMMAND CODES DURING DMA | 92 | READ-LINE (0xE) OR READ-MULTIPLE (0xC) PCI COMMAND CODES DURING DMA |
93 | TRANSFERS. IN OTHER SYSTEMS THESE COMMAND CODES WILL CAUSE THE HOST BRIDGE | 93 | TRANSFERS. IN OTHER SYSTEMS THESE COMMAND CODES WILL CAUSE THE HOST BRIDGE |
94 | TO ALLOW LONGER BURSTS DURING DMA READ OPERATIONS. THE UPPER FOUR BITS | 94 | TO ALLOW LONGER BURSTS DURING DMA READ OPERATIONS. THE UPPER FOUR BITS |
95 | (31..28) OF THE DMA CSR HAVE BEEN MADE PROGRAMMABLE, SO THAT EITHER A 0x6, | 95 | (31..28) OF THE DMA CSR HAVE BEEN MADE PROGRAMMABLE, SO THAT EITHER A 0x6, |
96 | AN 0xE OR A 0xC CAN BE WRITTEN TO THEM TO SET THE COMMAND CODE USED DURING | 96 | AN 0xE OR A 0xC CAN BE WRITTEN TO THEM TO SET THE COMMAND CODE USED DURING |
97 | DMA READ OPERATIONS. | 97 | DMA READ OPERATIONS. |
98 | */ | 98 | */ |
99 | #define DMASCR_READ 0x60000000 | 99 | #define DMASCR_READ 0x60000000 |
100 | #define DMASCR_READLINE 0xE0000000 | 100 | #define DMASCR_READLINE 0xE0000000 |
101 | #define DMASCR_READMULTI 0xC0000000 | 101 | #define DMASCR_READMULTI 0xC0000000 |
102 | 102 | ||
103 | 103 | ||
104 | #define DMASCR_ERROR_MASK (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR | DMASCR_ANY_ERR) | 104 | #define DMASCR_ERROR_MASK (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR | DMASCR_ANY_ERR) |
105 | #define DMASCR_HARD_ERROR (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR) | 105 | #define DMASCR_HARD_ERROR (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR) |
106 | 106 | ||
107 | #define WINDOWMAP_WINNUM 0x7B | 107 | #define WINDOWMAP_WINNUM 0x7B |
108 | 108 | ||
109 | #define DMA_READ_FROM_HOST 0 | 109 | #define DMA_READ_FROM_HOST 0 |
110 | #define DMA_WRITE_TO_HOST 1 | 110 | #define DMA_WRITE_TO_HOST 1 |
111 | 111 | ||
112 | struct mm_dma_desc { | 112 | struct mm_dma_desc { |
113 | __le64 pci_addr; | 113 | __le64 pci_addr; |
114 | __le64 local_addr; | 114 | __le64 local_addr; |
115 | __le32 transfer_size; | 115 | __le32 transfer_size; |
116 | u32 zero1; | 116 | u32 zero1; |
117 | __le64 next_desc_addr; | 117 | __le64 next_desc_addr; |
118 | __le64 sem_addr; | 118 | __le64 sem_addr; |
119 | __le32 control_bits; | 119 | __le32 control_bits; |
120 | u32 zero2; | 120 | u32 zero2; |
121 | 121 | ||
122 | dma_addr_t data_dma_handle; | 122 | dma_addr_t data_dma_handle; |
123 | 123 | ||
124 | /* Copy of the bits */ | 124 | /* Copy of the bits */ |
125 | __le64 sem_control_bits; | 125 | __le64 sem_control_bits; |
126 | } __attribute__((aligned(8))); | 126 | } __attribute__((aligned(8))); |
127 | 127 | ||
128 | /* bits for card->flags */ | 128 | /* bits for card->flags */ |
129 | #define UM_FLAG_DMA_IN_REGS 1 | 129 | #define UM_FLAG_DMA_IN_REGS 1 |
130 | #define UM_FLAG_NO_BYTE_STATUS 2 | 130 | #define UM_FLAG_NO_BYTE_STATUS 2 |
131 | #define UM_FLAG_NO_BATTREG 4 | 131 | #define UM_FLAG_NO_BATTREG 4 |
132 | #define UM_FLAG_NO_BATT 8 | 132 | #define UM_FLAG_NO_BATT 8 |
133 | #endif | 133 | #endif |
134 | 134 |