2 * linux/drivers/ide/ide-disk.c Version 1.18 Mar 05, 2003
4 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
5 * Copyright (C) 1998-2002 Linux ATA Development
6 * Andre Hedrick <andre@linux-ide.org>
7 * Copyright (C) 2003 Red Hat <alan@redhat.com>
11 * Mostly written by Mark Lord <mlord@pobox.com>
12 * and Gadi Oxman <gadio@netvision.net.il>
13 * and Andre Hedrick <andre@linux-ide.org>
15 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
17 * Version 1.00 move disk only code from ide.c to ide-disk.c
18 * support optional byte-swapping of all data
19 * Version 1.01 fix previous byte-swapping code
20 * Version 1.02 remove ", LBA" from drive identification msgs
21 * Version 1.03 fix display of id->buf_size for big-endian
22 * Version 1.04 add /proc configurable settings and S.M.A.R.T support
23 * Version 1.05 add capacity support for ATA3 >= 8GB
24 * Version 1.06 get boot-up messages to show full cyl count
25 * Version 1.07 disable door-locking if it fails
26 * Version 1.08 fixed CHS/LBA translations for ATA4 > 8GB,
27 * process of adding new ATA4 compliance.
28 * fixed problems in allowing fdisk to see
30 * Version 1.09 added increment of rq->sector in ide_multwrite
31 * added UDMA 3/4 reporting
32 * Version 1.10 request queue changes, Ultra DMA 100
33 * Version 1.11 added 48-bit lba
34 * Version 1.12 adding taskfile io access method
35 * Version 1.13 added standby and flush-cache for notifier
36 * Version 1.14 added acoustic-wcache
37 * Version 1.15 convert all calls to ide_raw_taskfile
38 * since args will return register content.
39 * Version 1.16 added suspend-resume-checkpower
40 * Version 1.17 do flush on standy, do flush on ATA < ATA6
44 #define IDEDISK_VERSION "1.18"
46 #undef REALLY_SLOW_IO /* most systems can safely undef this */
50 #include <linux/config.h>
51 #include <linux/module.h>
52 #include <linux/types.h>
53 #include <linux/string.h>
54 #include <linux/kernel.h>
55 #include <linux/timer.h>
57 #include <linux/interrupt.h>
58 #include <linux/major.h>
59 #include <linux/errno.h>
60 #include <linux/genhd.h>
61 #include <linux/slab.h>
62 #include <linux/delay.h>
66 #include <linux/ide.h>
68 #include <asm/byteorder.h>
70 #include <asm/uaccess.h>
72 #include <asm/div64.h>
75 * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity"
76 * value for this drive (from its reported identification information).
78 * Returns: 1 if lba_capacity looks sensible
81 * It is called only once for each drive.
83 static int lba_capacity_is_ok (struct hd_driveid *id)
85 unsigned long lba_sects, chs_sects, head, tail;
88 * The ATA spec tells large drives to return
89 * C/H/S = 16383/16/63 independent of their size.
90 * Some drives can be jumpered to use 15 heads instead of 16.
91 * Some drives can be jumpered to use 4092 cyls instead of 16383.
93 if ((id->cyls == 16383
94 || (id->cyls == 4092 && id->cur_cyls == 16383)) &&
96 (id->heads == 15 || id->heads == 16) &&
97 (id->lba_capacity >= 16383*63*id->heads))
100 lba_sects = id->lba_capacity;
101 chs_sects = id->cyls * id->heads * id->sectors;
103 /* perform a rough sanity check on lba_sects: within 10% is OK */
104 if ((lba_sects - chs_sects) < chs_sects/10)
107 /* some drives have the word order reversed */
108 head = ((lba_sects >> 16) & 0xffff);
109 tail = (lba_sects & 0xffff);
110 lba_sects = (head | (tail << 16));
111 if ((lba_sects - chs_sects) < chs_sects/10) {
112 id->lba_capacity = lba_sects;
113 return 1; /* lba_capacity is (now) good */
116 return 0; /* lba_capacity value may be bad */
120 * __ide_do_rw_disk() issues READ and WRITE commands to a disk,
121 * using LBA if supported, or CHS otherwise, to address sectors.
123 static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, sector_t block)
125 ide_hwif_t *hwif = HWIF(drive);
126 unsigned int dma = drive->using_dma;
127 u8 lba48 = (drive->addressing == 1) ? 1 : 0;
128 task_ioreg_t command = WIN_NOP;
129 ata_nsector_t nsectors;
131 nsectors.all = (u16) rq->nr_sectors;
133 if (hwif->no_lba48_dma && lba48 && dma) {
134 if (block + rq->nr_sectors > 1ULL << 28)
139 ide_init_sg_cmd(drive, rq);
140 ide_map_sg(drive, rq);
144 hwif->OUTB(drive->ctl, IDE_CONTROL_REG);
146 /* FIXME: SELECT_MASK(drive, 0) ? */
148 if (drive->select.b.lba) {
149 if (drive->addressing == 1) {
150 task_ioreg_t tasklets[10];
152 pr_debug("%s: LBA=0x%012llx\n", drive->name, block);
156 tasklets[2] = nsectors.b.low;
157 tasklets[3] = nsectors.b.high;
158 tasklets[4] = (task_ioreg_t) block;
159 tasklets[5] = (task_ioreg_t) (block>>8);
160 tasklets[6] = (task_ioreg_t) (block>>16);
161 tasklets[7] = (task_ioreg_t) (block>>24);
162 if (sizeof(block) == 4) {
163 tasklets[8] = (task_ioreg_t) 0;
164 tasklets[9] = (task_ioreg_t) 0;
166 tasklets[8] = (task_ioreg_t)((u64)block >> 32);
167 tasklets[9] = (task_ioreg_t)((u64)block >> 40);
170 printk("%s: 0x%02x%02x 0x%02x%02x%02x%02x%02x%02x\n",
171 drive->name, tasklets[3], tasklets[2],
172 tasklets[9], tasklets[8], tasklets[7],
173 tasklets[6], tasklets[5], tasklets[4]);
175 hwif->OUTB(tasklets[1], IDE_FEATURE_REG);
176 hwif->OUTB(tasklets[3], IDE_NSECTOR_REG);
177 hwif->OUTB(tasklets[7], IDE_SECTOR_REG);
178 hwif->OUTB(tasklets[8], IDE_LCYL_REG);
179 hwif->OUTB(tasklets[9], IDE_HCYL_REG);
181 hwif->OUTB(tasklets[0], IDE_FEATURE_REG);
182 hwif->OUTB(tasklets[2], IDE_NSECTOR_REG);
183 hwif->OUTB(tasklets[4], IDE_SECTOR_REG);
184 hwif->OUTB(tasklets[5], IDE_LCYL_REG);
185 hwif->OUTB(tasklets[6], IDE_HCYL_REG);
186 hwif->OUTB(0x00|drive->select.all,IDE_SELECT_REG);
188 hwif->OUTB(0x00, IDE_FEATURE_REG);
189 hwif->OUTB(nsectors.b.low, IDE_NSECTOR_REG);
190 hwif->OUTB(block, IDE_SECTOR_REG);
191 hwif->OUTB(block>>=8, IDE_LCYL_REG);
192 hwif->OUTB(block>>=8, IDE_HCYL_REG);
193 hwif->OUTB(((block>>8)&0x0f)|drive->select.all,IDE_SELECT_REG);
196 unsigned int sect,head,cyl,track;
197 track = (int)block / drive->sect;
198 sect = (int)block % drive->sect + 1;
199 hwif->OUTB(sect, IDE_SECTOR_REG);
200 head = track % drive->head;
201 cyl = track / drive->head;
203 pr_debug("%s: CHS=%u/%u/%u\n", drive->name, cyl, head, sect);
205 hwif->OUTB(0x00, IDE_FEATURE_REG);
206 hwif->OUTB(nsectors.b.low, IDE_NSECTOR_REG);
207 hwif->OUTB(cyl, IDE_LCYL_REG);
208 hwif->OUTB(cyl>>8, IDE_HCYL_REG);
209 hwif->OUTB(head|drive->select.all,IDE_SELECT_REG);
213 if (!hwif->dma_setup(drive)) {
214 if (rq_data_dir(rq)) {
215 command = lba48 ? WIN_WRITEDMA_EXT : WIN_WRITEDMA;
217 command = lba48 ? WIN_WRITE_EXT: WIN_WRITE;
219 command = lba48 ? WIN_READDMA_EXT : WIN_READDMA;
221 command = lba48 ? WIN_READ_EXT: WIN_READ;
223 hwif->dma_exec_cmd(drive, command);
224 hwif->dma_start(drive);
227 /* fallback to PIO */
228 ide_init_sg_cmd(drive, rq);
231 if (rq_data_dir(rq) == READ) {
233 if (drive->mult_count) {
234 hwif->data_phase = TASKFILE_MULTI_IN;
235 command = lba48 ? WIN_MULTREAD_EXT : WIN_MULTREAD;
237 hwif->data_phase = TASKFILE_IN;
238 command = lba48 ? WIN_READ_EXT : WIN_READ;
241 ide_execute_command(drive, command, &task_in_intr, WAIT_CMD, NULL);
244 if (drive->mult_count) {
245 hwif->data_phase = TASKFILE_MULTI_OUT;
246 command = lba48 ? WIN_MULTWRITE_EXT : WIN_MULTWRITE;
248 hwif->data_phase = TASKFILE_OUT;
249 command = lba48 ? WIN_WRITE_EXT : WIN_WRITE;
252 /* FIXME: ->OUTBSYNC ? */
253 hwif->OUTB(command, IDE_COMMAND_REG);
255 return pre_task_out_intr(drive, rq);
260 * 268435455 == 137439 MB or 28bit limit
261 * 320173056 == 163929 MB or 48bit addressing
262 * 1073741822 == 549756 MB or 48bit addressing fake drive
265 static ide_startstop_t ide_do_rw_disk (ide_drive_t *drive, struct request *rq, sector_t block)
267 ide_hwif_t *hwif = HWIF(drive);
269 BUG_ON(drive->blocked);
271 if (!blk_fs_request(rq)) {
272 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
273 ide_end_request(drive, 0, 0);
277 pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n",
278 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
279 block, rq->nr_sectors, (unsigned long)rq->buffer);
282 hwif->rw_disk(drive, rq);
284 return __ide_do_rw_disk(drive, rq, block);
288 * Queries for true maximum capacity of the drive.
289 * Returns maximum LBA address (> 0) of the drive, 0 if failed.
291 static unsigned long idedisk_read_native_max_address(ide_drive_t *drive)
294 unsigned long addr = 0;
296 /* Create IDE/ATA command request structure */
297 memset(&args, 0, sizeof(ide_task_t));
298 args.tfRegister[IDE_SELECT_OFFSET] = 0x40;
299 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_READ_NATIVE_MAX;
300 args.command_type = IDE_DRIVE_TASK_NO_DATA;
301 args.handler = &task_no_data_intr;
302 /* submit command request */
303 ide_raw_taskfile(drive, &args, NULL);
305 /* if OK, compute maximum address value */
306 if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) {
307 addr = ((args.tfRegister[IDE_SELECT_OFFSET] & 0x0f) << 24)
308 | ((args.tfRegister[ IDE_HCYL_OFFSET] ) << 16)
309 | ((args.tfRegister[ IDE_LCYL_OFFSET] ) << 8)
310 | ((args.tfRegister[IDE_SECTOR_OFFSET] ));
311 addr++; /* since the return value is (maxlba - 1), we add 1 */
316 static unsigned long long idedisk_read_native_max_address_ext(ide_drive_t *drive)
319 unsigned long long addr = 0;
321 /* Create IDE/ATA command request structure */
322 memset(&args, 0, sizeof(ide_task_t));
324 args.tfRegister[IDE_SELECT_OFFSET] = 0x40;
325 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_READ_NATIVE_MAX_EXT;
326 args.command_type = IDE_DRIVE_TASK_NO_DATA;
327 args.handler = &task_no_data_intr;
328 /* submit command request */
329 ide_raw_taskfile(drive, &args, NULL);
331 /* if OK, compute maximum address value */
332 if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) {
333 u32 high = (args.hobRegister[IDE_HCYL_OFFSET] << 16) |
334 (args.hobRegister[IDE_LCYL_OFFSET] << 8) |
335 args.hobRegister[IDE_SECTOR_OFFSET];
336 u32 low = ((args.tfRegister[IDE_HCYL_OFFSET])<<16) |
337 ((args.tfRegister[IDE_LCYL_OFFSET])<<8) |
338 (args.tfRegister[IDE_SECTOR_OFFSET]);
339 addr = ((__u64)high << 24) | low;
340 addr++; /* since the return value is (maxlba - 1), we add 1 */
346 * Sets maximum virtual LBA address of the drive.
347 * Returns new maximum virtual LBA address (> 0) or 0 on failure.
349 static unsigned long idedisk_set_max_address(ide_drive_t *drive, unsigned long addr_req)
352 unsigned long addr_set = 0;
355 /* Create IDE/ATA command request structure */
356 memset(&args, 0, sizeof(ide_task_t));
357 args.tfRegister[IDE_SECTOR_OFFSET] = ((addr_req >> 0) & 0xff);
358 args.tfRegister[IDE_LCYL_OFFSET] = ((addr_req >> 8) & 0xff);
359 args.tfRegister[IDE_HCYL_OFFSET] = ((addr_req >> 16) & 0xff);
360 args.tfRegister[IDE_SELECT_OFFSET] = ((addr_req >> 24) & 0x0f) | 0x40;
361 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SET_MAX;
362 args.command_type = IDE_DRIVE_TASK_NO_DATA;
363 args.handler = &task_no_data_intr;
364 /* submit command request */
365 ide_raw_taskfile(drive, &args, NULL);
366 /* if OK, read new maximum address value */
367 if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) {
368 addr_set = ((args.tfRegister[IDE_SELECT_OFFSET] & 0x0f) << 24)
369 | ((args.tfRegister[ IDE_HCYL_OFFSET] ) << 16)
370 | ((args.tfRegister[ IDE_LCYL_OFFSET] ) << 8)
371 | ((args.tfRegister[IDE_SECTOR_OFFSET] ));
377 static unsigned long long idedisk_set_max_address_ext(ide_drive_t *drive, unsigned long long addr_req)
380 unsigned long long addr_set = 0;
383 /* Create IDE/ATA command request structure */
384 memset(&args, 0, sizeof(ide_task_t));
385 args.tfRegister[IDE_SECTOR_OFFSET] = ((addr_req >> 0) & 0xff);
386 args.tfRegister[IDE_LCYL_OFFSET] = ((addr_req >>= 8) & 0xff);
387 args.tfRegister[IDE_HCYL_OFFSET] = ((addr_req >>= 8) & 0xff);
388 args.tfRegister[IDE_SELECT_OFFSET] = 0x40;
389 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SET_MAX_EXT;
390 args.hobRegister[IDE_SECTOR_OFFSET] = (addr_req >>= 8) & 0xff;
391 args.hobRegister[IDE_LCYL_OFFSET] = (addr_req >>= 8) & 0xff;
392 args.hobRegister[IDE_HCYL_OFFSET] = (addr_req >>= 8) & 0xff;
393 args.hobRegister[IDE_SELECT_OFFSET] = 0x40;
394 args.hobRegister[IDE_CONTROL_OFFSET_HOB]= (drive->ctl|0x80);
395 args.command_type = IDE_DRIVE_TASK_NO_DATA;
396 args.handler = &task_no_data_intr;
397 /* submit command request */
398 ide_raw_taskfile(drive, &args, NULL);
399 /* if OK, compute maximum address value */
400 if ((args.tfRegister[IDE_STATUS_OFFSET] & 0x01) == 0) {
401 u32 high = (args.hobRegister[IDE_HCYL_OFFSET] << 16) |
402 (args.hobRegister[IDE_LCYL_OFFSET] << 8) |
403 args.hobRegister[IDE_SECTOR_OFFSET];
404 u32 low = ((args.tfRegister[IDE_HCYL_OFFSET])<<16) |
405 ((args.tfRegister[IDE_LCYL_OFFSET])<<8) |
406 (args.tfRegister[IDE_SECTOR_OFFSET]);
407 addr_set = ((__u64)high << 24) | low;
413 static unsigned long long sectors_to_MB(unsigned long long n)
415 n <<= 9; /* make it bytes */
416 do_div(n, 1000000); /* make it MB */
421 * Bits 10 of command_set_1 and cfs_enable_1 must be equal,
422 * so on non-buggy drives we need test only one.
423 * However, we should also check whether these fields are valid.
425 static inline int idedisk_supports_hpa(const struct hd_driveid *id)
427 return (id->command_set_1 & 0x0400) && (id->cfs_enable_1 & 0x0400);
433 static inline int idedisk_supports_lba48(const struct hd_driveid *id)
435 return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400)
436 && id->lba_capacity_2;
439 static inline void idedisk_check_hpa(ide_drive_t *drive)
441 unsigned long long capacity, set_max;
442 int lba48 = idedisk_supports_lba48(drive->id);
444 capacity = drive->capacity64;
446 set_max = idedisk_read_native_max_address_ext(drive);
448 set_max = idedisk_read_native_max_address(drive);
450 if (set_max <= capacity)
453 printk(KERN_INFO "%s: Host Protected Area detected.\n"
454 "\tcurrent capacity is %llu sectors (%llu MB)\n"
455 "\tnative capacity is %llu sectors (%llu MB)\n",
457 capacity, sectors_to_MB(capacity),
458 set_max, sectors_to_MB(set_max));
461 set_max = idedisk_set_max_address_ext(drive, set_max);
463 set_max = idedisk_set_max_address(drive, set_max);
465 drive->capacity64 = set_max;
466 printk(KERN_INFO "%s: Host Protected Area disabled.\n",
472 * Compute drive->capacity, the full capacity of the drive
473 * Called with drive->id != NULL.
475 * To compute capacity, this uses either of
477 * 1. CHS value set by user (whatever user sets will be trusted)
478 * 2. LBA value from target drive (require new ATA feature)
479 * 3. LBA value from system BIOS (new one is OK, old one may break)
480 * 4. CHS value from system BIOS (traditional style)
482 * in above order (i.e., if value of higher priority is available,
483 * reset will be ignored).
485 static void init_idedisk_capacity (ide_drive_t *drive)
487 struct hd_driveid *id = drive->id;
489 * If this drive supports the Host Protected Area feature set,
490 * then we may need to change our opinion about the drive's capacity.
492 int hpa = idedisk_supports_hpa(id);
494 if (idedisk_supports_lba48(id)) {
495 /* drive speaks 48-bit LBA */
496 drive->select.b.lba = 1;
497 drive->capacity64 = id->lba_capacity_2;
499 idedisk_check_hpa(drive);
500 } else if ((id->capability & 2) && lba_capacity_is_ok(id)) {
501 /* drive speaks 28-bit LBA */
502 drive->select.b.lba = 1;
503 drive->capacity64 = id->lba_capacity;
505 idedisk_check_hpa(drive);
507 /* drive speaks boring old 28-bit CHS */
508 drive->capacity64 = drive->cyl * drive->head * drive->sect;
512 static sector_t idedisk_capacity (ide_drive_t *drive)
514 return drive->capacity64 - drive->sect0;
517 #define IS_PDC4030_DRIVE 0
519 static ide_startstop_t idedisk_special (ide_drive_t *drive)
521 special_t *s = &drive->special;
523 if (s->b.set_geometry) {
524 s->b.set_geometry = 0;
525 if (!IS_PDC4030_DRIVE) {
527 memset(&args, 0, sizeof(ide_task_t));
528 args.tfRegister[IDE_NSECTOR_OFFSET] = drive->sect;
529 args.tfRegister[IDE_SECTOR_OFFSET] = drive->sect;
530 args.tfRegister[IDE_LCYL_OFFSET] = drive->cyl;
531 args.tfRegister[IDE_HCYL_OFFSET] = drive->cyl>>8;
532 args.tfRegister[IDE_SELECT_OFFSET] = ((drive->head-1)|drive->select.all)&0xBF;
533 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SPECIFY;
534 args.command_type = IDE_DRIVE_TASK_NO_DATA;
535 args.handler = &set_geometry_intr;
536 do_rw_taskfile(drive, &args);
538 } else if (s->b.recalibrate) {
539 s->b.recalibrate = 0;
540 if (!IS_PDC4030_DRIVE) {
542 memset(&args, 0, sizeof(ide_task_t));
543 args.tfRegister[IDE_NSECTOR_OFFSET] = drive->sect;
544 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_RESTORE;
545 args.command_type = IDE_DRIVE_TASK_NO_DATA;
546 args.handler = &recal_intr;
547 do_rw_taskfile(drive, &args);
549 } else if (s->b.set_multmode) {
550 s->b.set_multmode = 0;
551 if (drive->mult_req > drive->id->max_multsect)
552 drive->mult_req = drive->id->max_multsect;
553 if (!IS_PDC4030_DRIVE) {
555 memset(&args, 0, sizeof(ide_task_t));
556 args.tfRegister[IDE_NSECTOR_OFFSET] = drive->mult_req;
557 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SETMULT;
558 args.command_type = IDE_DRIVE_TASK_NO_DATA;
559 args.handler = &set_multmode_intr;
560 do_rw_taskfile(drive, &args);
563 int special = s->all;
565 printk(KERN_ERR "%s: bad special flag: 0x%02x\n", drive->name, special);
568 return IS_PDC4030_DRIVE ? ide_stopped : ide_started;
571 static void idedisk_pre_reset (ide_drive_t *drive)
573 int legacy = (drive->id->cfs_enable_2 & 0x0400) ? 0 : 1;
575 drive->special.all = 0;
576 drive->special.b.set_geometry = legacy;
577 drive->special.b.recalibrate = legacy;
578 if (OK_TO_RESET_CONTROLLER)
579 drive->mult_count = 0;
580 if (!drive->keep_settings && !drive->using_dma)
582 if (drive->mult_req != drive->mult_count)
583 drive->special.b.set_multmode = 1;
586 #ifdef CONFIG_PROC_FS
588 static int smart_enable(ide_drive_t *drive)
592 memset(&args, 0, sizeof(ide_task_t));
593 args.tfRegister[IDE_FEATURE_OFFSET] = SMART_ENABLE;
594 args.tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
595 args.tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
596 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SMART;
597 args.command_type = IDE_DRIVE_TASK_NO_DATA;
598 args.handler = &task_no_data_intr;
599 return ide_raw_taskfile(drive, &args, NULL);
602 static int get_smart_values(ide_drive_t *drive, u8 *buf)
606 memset(&args, 0, sizeof(ide_task_t));
607 args.tfRegister[IDE_FEATURE_OFFSET] = SMART_READ_VALUES;
608 args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01;
609 args.tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
610 args.tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
611 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SMART;
612 args.command_type = IDE_DRIVE_TASK_IN;
613 args.data_phase = TASKFILE_IN;
614 args.handler = &task_in_intr;
615 (void) smart_enable(drive);
616 return ide_raw_taskfile(drive, &args, buf);
619 static int get_smart_thresholds(ide_drive_t *drive, u8 *buf)
622 memset(&args, 0, sizeof(ide_task_t));
623 args.tfRegister[IDE_FEATURE_OFFSET] = SMART_READ_THRESHOLDS;
624 args.tfRegister[IDE_NSECTOR_OFFSET] = 0x01;
625 args.tfRegister[IDE_LCYL_OFFSET] = SMART_LCYL_PASS;
626 args.tfRegister[IDE_HCYL_OFFSET] = SMART_HCYL_PASS;
627 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SMART;
628 args.command_type = IDE_DRIVE_TASK_IN;
629 args.data_phase = TASKFILE_IN;
630 args.handler = &task_in_intr;
631 (void) smart_enable(drive);
632 return ide_raw_taskfile(drive, &args, buf);
635 static int proc_idedisk_read_cache
636 (char *page, char **start, off_t off, int count, int *eof, void *data)
638 ide_drive_t *drive = (ide_drive_t *) data;
643 len = sprintf(out,"%i\n", drive->id->buf_size / 2);
645 len = sprintf(out,"(none)\n");
646 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
649 static int proc_idedisk_read_smart_thresholds
650 (char *page, char **start, off_t off, int count, int *eof, void *data)
652 ide_drive_t *drive = (ide_drive_t *)data;
655 if (!get_smart_thresholds(drive, page)) {
656 unsigned short *val = (unsigned short *) page;
657 char *out = ((char *)val) + (SECTOR_WORDS * 4);
660 out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
662 } while (i < (SECTOR_WORDS * 2));
665 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
668 static int proc_idedisk_read_smart_values
669 (char *page, char **start, off_t off, int count, int *eof, void *data)
671 ide_drive_t *drive = (ide_drive_t *)data;
674 if (!get_smart_values(drive, page)) {
675 unsigned short *val = (unsigned short *) page;
676 char *out = ((char *)val) + (SECTOR_WORDS * 4);
679 out += sprintf(out, "%04x%c", le16_to_cpu(*val), (++i & 7) ? ' ' : '\n');
681 } while (i < (SECTOR_WORDS * 2));
684 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
687 static ide_proc_entry_t idedisk_proc[] = {
688 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
689 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
690 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_smart_values, NULL },
691 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_smart_thresholds, NULL },
692 { NULL, 0, NULL, NULL }
697 #define idedisk_proc NULL
699 #endif /* CONFIG_PROC_FS */
701 static int idedisk_issue_flush(request_queue_t *q, struct gendisk *disk,
702 sector_t *error_sector)
704 ide_drive_t *drive = q->queuedata;
711 rq = blk_get_request(q, WRITE, __GFP_WAIT);
713 memset(rq->cmd, 0, sizeof(rq->cmd));
715 if (ide_id_has_flush_cache_ext(drive->id) &&
716 (drive->capacity64 >= (1UL << 28)))
717 rq->cmd[0] = WIN_FLUSH_CACHE_EXT;
719 rq->cmd[0] = WIN_FLUSH_CACHE;
722 rq->flags |= REQ_DRIVE_TASK | REQ_SOFTBARRIER;
723 rq->buffer = rq->cmd;
725 ret = blk_execute_rq(q, disk, rq);
728 * if we failed and caller wants error offset, get it
730 if (ret && error_sector)
731 *error_sector = ide_get_error_location(drive, rq->cmd);
738 * This is tightly woven into the driver->do_special can not touch.
739 * DON'T do it again until a total personality rewrite is committed.
741 static int set_multcount(ide_drive_t *drive, int arg)
745 if (drive->special.b.set_multmode)
747 ide_init_drive_cmd (&rq);
748 rq.flags = REQ_DRIVE_CMD;
749 drive->mult_req = arg;
750 drive->special.b.set_multmode = 1;
751 (void) ide_do_drive_cmd (drive, &rq, ide_wait);
752 return (drive->mult_count == arg) ? 0 : -EIO;
755 static int set_nowerr(ide_drive_t *drive, int arg)
757 if (ide_spin_wait_hwgroup(drive))
760 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
761 spin_unlock_irq(&ide_lock);
765 static int write_cache(ide_drive_t *drive, int arg)
770 if (!ide_id_has_flush_cache(drive->id))
773 memset(&args, 0, sizeof(ide_task_t));
774 args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ?
775 SETFEATURES_EN_WCACHE : SETFEATURES_DIS_WCACHE;
776 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SETFEATURES;
777 args.command_type = IDE_DRIVE_TASK_NO_DATA;
778 args.handler = &task_no_data_intr;
780 err = ide_raw_taskfile(drive, &args, NULL);
788 static int do_idedisk_flushcache (ide_drive_t *drive)
792 memset(&args, 0, sizeof(ide_task_t));
793 if (ide_id_has_flush_cache_ext(drive->id))
794 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE_EXT;
796 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE;
797 args.command_type = IDE_DRIVE_TASK_NO_DATA;
798 args.handler = &task_no_data_intr;
799 return ide_raw_taskfile(drive, &args, NULL);
802 static int set_acoustic (ide_drive_t *drive, int arg)
806 memset(&args, 0, sizeof(ide_task_t));
807 args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ? SETFEATURES_EN_AAM :
809 args.tfRegister[IDE_NSECTOR_OFFSET] = arg;
810 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_SETFEATURES;
811 args.command_type = IDE_DRIVE_TASK_NO_DATA;
812 args.handler = &task_no_data_intr;
813 ide_raw_taskfile(drive, &args, NULL);
814 drive->acoustic = arg;
822 * 2: 48-bit capable doing 28-bit
824 static int set_lba_addressing(ide_drive_t *drive, int arg)
826 drive->addressing = 0;
828 if (HWIF(drive)->no_lba48)
831 if (!idedisk_supports_lba48(drive->id))
833 drive->addressing = arg;
837 static void idedisk_add_settings(ide_drive_t *drive)
839 struct hd_driveid *id = drive->id;
841 ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->bios_cyl, NULL);
842 ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
843 ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
844 ide_add_setting(drive, "address", SETTING_RW, HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, TYPE_INTA, 0, 2, 1, 1, &drive->addressing, set_lba_addressing);
845 ide_add_setting(drive, "bswap", SETTING_READ, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->bswap, NULL);
846 ide_add_setting(drive, "multcount", id ? SETTING_RW : SETTING_READ, HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, TYPE_BYTE, 0, id ? id->max_multsect : 0, 1, 1, &drive->mult_count, set_multcount);
847 ide_add_setting(drive, "nowerr", SETTING_RW, HDIO_GET_NOWERR, HDIO_SET_NOWERR, TYPE_BYTE, 0, 1, 1, 1, &drive->nowerr, set_nowerr);
848 ide_add_setting(drive, "lun", SETTING_RW, -1, -1, TYPE_INT, 0, 7, 1, 1, &drive->lun, NULL);
849 ide_add_setting(drive, "wcache", SETTING_RW, HDIO_GET_WCACHE, HDIO_SET_WCACHE, TYPE_BYTE, 0, 1, 1, 1, &drive->wcache, write_cache);
850 ide_add_setting(drive, "acoustic", SETTING_RW, HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, TYPE_BYTE, 0, 254, 1, 1, &drive->acoustic, set_acoustic);
851 ide_add_setting(drive, "failures", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->failures, NULL);
852 ide_add_setting(drive, "max_failures", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->max_failures, NULL);
856 * Power Management state machine. This one is rather trivial for now,
857 * we should probably add more, like switching back to PIO on suspend
858 * to help some BIOSes, re-do the door locking on resume, etc...
862 idedisk_pm_flush_cache = ide_pm_state_start_suspend,
865 idedisk_pm_idle = ide_pm_state_start_resume,
866 idedisk_pm_restore_dma,
869 static void idedisk_complete_power_step (ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
871 switch (rq->pm->pm_step) {
872 case idedisk_pm_flush_cache: /* Suspend step 1 (flush cache) complete */
873 if (rq->pm->pm_state == 4)
874 rq->pm->pm_step = ide_pm_state_completed;
876 rq->pm->pm_step = idedisk_pm_standby;
878 case idedisk_pm_standby: /* Suspend step 2 (standby) complete */
879 rq->pm->pm_step = ide_pm_state_completed;
881 case idedisk_pm_idle: /* Resume step 1 (idle) complete */
882 rq->pm->pm_step = idedisk_pm_restore_dma;
887 static ide_startstop_t idedisk_start_power_step (ide_drive_t *drive, struct request *rq)
889 ide_task_t *args = rq->special;
891 memset(args, 0, sizeof(*args));
893 switch (rq->pm->pm_step) {
894 case idedisk_pm_flush_cache: /* Suspend step 1 (flush cache) */
895 /* Not supported? Switch to next step now. */
896 if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) {
897 idedisk_complete_power_step(drive, rq, 0, 0);
900 if (ide_id_has_flush_cache_ext(drive->id))
901 args->tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE_EXT;
903 args->tfRegister[IDE_COMMAND_OFFSET] = WIN_FLUSH_CACHE;
904 args->command_type = IDE_DRIVE_TASK_NO_DATA;
905 args->handler = &task_no_data_intr;
906 return do_rw_taskfile(drive, args);
908 case idedisk_pm_standby: /* Suspend step 2 (standby) */
909 args->tfRegister[IDE_COMMAND_OFFSET] = WIN_STANDBYNOW1;
910 args->command_type = IDE_DRIVE_TASK_NO_DATA;
911 args->handler = &task_no_data_intr;
912 return do_rw_taskfile(drive, args);
914 case idedisk_pm_idle: /* Resume step 1 (idle) */
915 args->tfRegister[IDE_COMMAND_OFFSET] = WIN_IDLEIMMEDIATE;
916 args->command_type = IDE_DRIVE_TASK_NO_DATA;
917 args->handler = task_no_data_intr;
918 return do_rw_taskfile(drive, args);
920 case idedisk_pm_restore_dma: /* Resume step 2 (restore DMA) */
922 * Right now, all we do is call hwif->ide_dma_check(drive),
923 * we could be smarter and check for current xfer_speed
924 * in struct drive etc...
925 * Also, this step could be implemented as a generic helper
926 * as most subdrivers will use it
928 if ((drive->id->capability & 1) == 0)
930 if (HWIF(drive)->ide_dma_check == NULL)
932 HWIF(drive)->ide_dma_check(drive);
935 rq->pm->pm_step = ide_pm_state_completed;
939 static void idedisk_setup (ide_drive_t *drive)
941 struct hd_driveid *id = drive->id;
942 unsigned long long capacity;
945 idedisk_add_settings(drive);
947 if (drive->id_read == 0)
951 * CompactFlash cards and their brethern look just like hard drives
952 * to us, but they are removable and don't have a doorlock mechanism.
954 if (drive->removable && !(drive->is_flash)) {
956 * Removable disks (eg. SYQUEST); ignore 'WD' drives
958 if (id->model[0] != 'W' || id->model[1] != 'D') {
959 drive->doorlocking = 1;
963 (void)set_lba_addressing(drive, 1);
965 if (drive->addressing == 1) {
966 ide_hwif_t *hwif = HWIF(drive);
969 if (max_s > hwif->rqsize)
970 max_s = hwif->rqsize;
972 blk_queue_max_sectors(drive->queue, max_s);
975 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, drive->queue->max_sectors / 2);
977 /* Extract geometry if we did not already have one for the drive */
978 if (!drive->cyl || !drive->head || !drive->sect) {
979 drive->cyl = drive->bios_cyl = id->cyls;
980 drive->head = drive->bios_head = id->heads;
981 drive->sect = drive->bios_sect = id->sectors;
984 /* Handle logical geometry translation by the drive */
985 if ((id->field_valid & 1) && id->cur_cyls &&
986 id->cur_heads && (id->cur_heads <= 16) && id->cur_sectors) {
987 drive->cyl = id->cur_cyls;
988 drive->head = id->cur_heads;
989 drive->sect = id->cur_sectors;
992 /* Use physical geometry if what we have still makes no sense */
993 if (drive->head > 16 && id->heads && id->heads <= 16) {
994 drive->cyl = id->cyls;
995 drive->head = id->heads;
996 drive->sect = id->sectors;
999 /* calculate drive capacity, and select LBA if possible */
1000 init_idedisk_capacity (drive);
1002 /* limit drive capacity to 137GB if LBA48 cannot be used */
1003 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) {
1004 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
1005 "%llu sectors (%llu MB)\n",
1006 drive->name, (unsigned long long)drive->capacity64,
1007 sectors_to_MB(drive->capacity64));
1008 drive->capacity64 = 1ULL << 28;
1011 if (drive->hwif->no_lba48_dma && drive->addressing) {
1012 if (drive->capacity64 > 1ULL << 28) {
1013 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode will"
1014 " be used for accessing sectors > %u\n",
1015 drive->name, 1 << 28);
1017 drive->addressing = 0;
1021 * if possible, give fdisk access to more of the drive,
1022 * by correcting bios_cyls:
1024 capacity = idedisk_capacity (drive);
1025 if (!drive->forced_geom) {
1027 if (idedisk_supports_lba48(drive->id)) {
1029 drive->bios_sect = 63;
1030 drive->bios_head = 255;
1033 if (drive->bios_sect && drive->bios_head) {
1034 unsigned int cap0 = capacity; /* truncate to 32 bits */
1035 unsigned int cylsz, cyl;
1037 if (cap0 != capacity)
1038 drive->bios_cyl = 65535;
1040 cylsz = drive->bios_sect * drive->bios_head;
1044 if (cyl > drive->bios_cyl)
1045 drive->bios_cyl = cyl;
1049 printk(KERN_INFO "%s: %llu sectors (%llu MB)",
1050 drive->name, capacity, sectors_to_MB(capacity));
1052 /* Only print cache size when it was specified */
1054 printk (" w/%dKiB Cache", id->buf_size/2);
1056 printk(", CHS=%d/%d/%d",
1057 drive->bios_cyl, drive->bios_head, drive->bios_sect);
1058 if (drive->using_dma)
1059 ide_dma_verbose(drive);
1062 drive->mult_count = 0;
1063 if (id->max_multsect) {
1064 #ifdef CONFIG_IDEDISK_MULTI_MODE
1065 id->multsect = ((id->max_multsect/2) > 1) ? id->max_multsect : 0;
1066 id->multsect_valid = id->multsect ? 1 : 0;
1067 drive->mult_req = id->multsect_valid ? id->max_multsect : INITIAL_MULT_COUNT;
1068 drive->special.b.set_multmode = drive->mult_req ? 1 : 0;
1069 #else /* original, pre IDE-NFG, per request of AC */
1070 drive->mult_req = INITIAL_MULT_COUNT;
1071 if (drive->mult_req > id->max_multsect)
1072 drive->mult_req = id->max_multsect;
1073 if (drive->mult_req || ((id->multsect_valid & 1) && id->multsect))
1074 drive->special.b.set_multmode = 1;
1075 #endif /* CONFIG_IDEDISK_MULTI_MODE */
1077 drive->no_io_32bit = id->dword_io ? 1 : 0;
1079 /* write cache enabled? */
1080 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5)))
1083 write_cache(drive, 1);
1086 * We must avoid issuing commands a drive does not understand
1087 * or we may crash it. We check flush cache is supported. We also
1088 * check we have the LBA48 flush cache if the drive capacity is
1089 * too large. By this time we have trimmed the drive capacity if
1090 * LBA48 is not available so we don't need to recheck that.
1093 if (ide_id_has_flush_cache(id))
1095 if (drive->addressing == 1) {
1096 /* Can't issue the correct flush ? */
1097 if (capacity > (1ULL << 28) && !ide_id_has_flush_cache_ext(id))
1101 printk(KERN_DEBUG "%s: cache flushes %ssupported\n",
1102 drive->name, barrier ? "" : "not ");
1104 blk_queue_ordered(drive->queue, 1);
1105 blk_queue_issue_flush_fn(drive->queue, idedisk_issue_flush);
1109 static void ide_cacheflush_p(ide_drive_t *drive)
1111 if (!drive->wcache || !ide_id_has_flush_cache(drive->id))
1114 if (do_idedisk_flushcache(drive))
1115 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
1118 static int idedisk_cleanup (ide_drive_t *drive)
1120 struct gendisk *g = drive->disk;
1121 ide_cacheflush_p(drive);
1122 if (ide_unregister_subdriver(drive))
1125 drive->devfs_name[0] = '\0';
1130 static int idedisk_attach(ide_drive_t *drive);
1132 static void ide_device_shutdown(struct device *dev)
1134 ide_drive_t *drive = container_of(dev, ide_drive_t, gendev);
1137 /* On Alpha, halt(8) doesn't actually turn the machine off,
1138 it puts you into the sort of firmware monitor. Typically,
1139 it's used to boot another kernel image, so it's not much
1140 different from reboot(8). Therefore, we don't need to
1141 spin down the disk in this case, especially since Alpha
1142 firmware doesn't handle disks in standby mode properly.
1143 On the other hand, it's reasonably safe to turn the power
1144 off when the shutdown process reaches the firmware prompt,
1145 as the firmware initialization takes rather long time -
1146 at least 10 seconds, which should be sufficient for
1147 the disk to expire its write cache. */
1148 if (system_state != SYSTEM_POWER_OFF) {
1150 if (system_state == SYSTEM_RESTART) {
1152 ide_cacheflush_p(drive);
1156 printk("Shutdown: %s\n", drive->name);
1157 dev->bus->suspend(dev, PM_SUSPEND_STANDBY);
1161 * IDE subdriver functions, registered with ide.c
1163 static ide_driver_t idedisk_driver = {
1164 .owner = THIS_MODULE,
1166 .shutdown = ide_device_shutdown,
1169 .version = IDEDISK_VERSION,
1172 .supports_dsc_overlap = 0,
1173 .cleanup = idedisk_cleanup,
1174 .do_request = ide_do_rw_disk,
1175 .pre_reset = idedisk_pre_reset,
1176 .capacity = idedisk_capacity,
1177 .special = idedisk_special,
1178 .proc = idedisk_proc,
1179 .attach = idedisk_attach,
1180 .drives = LIST_HEAD_INIT(idedisk_driver.drives),
1181 .start_power_step = idedisk_start_power_step,
1182 .complete_power_step = idedisk_complete_power_step,
1185 static int idedisk_open(struct inode *inode, struct file *filp)
1187 ide_drive_t *drive = inode->i_bdev->bd_disk->private_data;
1189 if (drive->removable && drive->usage == 1) {
1191 memset(&args, 0, sizeof(ide_task_t));
1192 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK;
1193 args.command_type = IDE_DRIVE_TASK_NO_DATA;
1194 args.handler = &task_no_data_intr;
1195 check_disk_change(inode->i_bdev);
1197 * Ignore the return code from door_lock,
1198 * since the open() has already succeeded,
1199 * and the door_lock is irrelevant at this point.
1201 if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL))
1202 drive->doorlocking = 0;
1207 static int idedisk_release(struct inode *inode, struct file *filp)
1209 ide_drive_t *drive = inode->i_bdev->bd_disk->private_data;
1210 if (drive->usage == 1)
1211 ide_cacheflush_p(drive);
1212 if (drive->removable && drive->usage == 1) {
1214 memset(&args, 0, sizeof(ide_task_t));
1215 args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK;
1216 args.command_type = IDE_DRIVE_TASK_NO_DATA;
1217 args.handler = &task_no_data_intr;
1218 if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL))
1219 drive->doorlocking = 0;
1225 static int idedisk_ioctl(struct inode *inode, struct file *file,
1226 unsigned int cmd, unsigned long arg)
1228 struct block_device *bdev = inode->i_bdev;
1229 return generic_ide_ioctl(file, bdev, cmd, arg);
1232 static int idedisk_media_changed(struct gendisk *disk)
1234 ide_drive_t *drive = disk->private_data;
1236 /* do not scan partitions twice if this is a removable device */
1237 if (drive->attach) {
1241 /* if removable, always assume it was changed */
1242 return drive->removable;
1245 static int idedisk_revalidate_disk(struct gendisk *disk)
1247 ide_drive_t *drive = disk->private_data;
1248 set_capacity(disk, idedisk_capacity(drive));
1252 static struct block_device_operations idedisk_ops = {
1253 .owner = THIS_MODULE,
1254 .open = idedisk_open,
1255 .release = idedisk_release,
1256 .ioctl = idedisk_ioctl,
1257 .media_changed = idedisk_media_changed,
1258 .revalidate_disk= idedisk_revalidate_disk
1261 MODULE_DESCRIPTION("ATA DISK Driver");
1263 static int idedisk_attach(ide_drive_t *drive)
1265 struct gendisk *g = drive->disk;
1267 /* strstr("foo", "") is non-NULL */
1268 if (!strstr("ide-disk", drive->driver_req))
1270 if (!drive->present)
1272 if (drive->media != ide_disk)
1275 if (ide_register_subdriver(drive, &idedisk_driver)) {
1276 printk (KERN_ERR "ide-disk: %s: Failed to register the driver with ide.c\n", drive->name);
1279 DRIVER(drive)->busy++;
1280 idedisk_setup(drive);
1281 if ((!drive->head || drive->head > 16) && !drive->select.b.lba) {
1282 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
1283 drive->name, drive->head);
1287 DRIVER(drive)->busy--;
1288 g->minors = 1 << PARTN_BITS;
1289 strcpy(g->devfs_name, drive->devfs_name);
1290 g->driverfs_dev = &drive->gendev;
1291 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
1292 set_capacity(g, idedisk_capacity(drive));
1293 g->fops = &idedisk_ops;
1300 static void __exit idedisk_exit (void)
1302 ide_unregister_driver(&idedisk_driver);
1305 static int idedisk_init (void)
1307 return ide_register_driver(&idedisk_driver);
1310 module_init(idedisk_init);
1311 module_exit(idedisk_exit);
1312 MODULE_LICENSE("GPL");