diff options
Diffstat (limited to 'linux/chudisk.c')
| -rw-r--r-- | linux/chudisk.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/linux/chudisk.c b/linux/chudisk.c index 31dd9e5..3d6f79b 100644 --- a/linux/chudisk.c +++ b/linux/chudisk.c @@ -28,8 +28,8 @@ /* module parameters */ /** configurable major number */ -/* by default, reuse the one from Mylex DAC960 PCI RAID controller; sixth controller" */ -static short major = 53; +/* by default, reuse one in the experimental space */ +static short major = 63; /** IO base */ static short io = 0x260; /** skip device proving */ @@ -39,7 +39,7 @@ static int softblk = 1024; /* for blk.h: (needs to be defined before blk.h/lnxabs.h is included) */ #define MAJOR_NR major -#define DEVICE_NAME "CH375" +#define DEVICE_NAME "chud" #define DEVICE_REQUEST do_chudisk_request #define DEVICE_NR(device) (MINOR(device)>>CHUDISK_MINOR_SHIFT) #define DEVICE_ON(device) @@ -48,9 +48,9 @@ static int softblk = 1024; #include "lnxabs.h" #include "ch375lnx.h" +#include <chuver.h> #include <scsi.h> -#define ENABLE_DLOG 0 #if ENABLE_DLOG #define dprintf(args...) printk(KERN_DEBUG args) #else @@ -87,7 +87,7 @@ static struct ch375 chudisk_dev[CHUDISK_MAX_UNITS]; /** main gendisk layer data structure, which handles partioning */ static struct gendisk chudisk_gendisk = { - .major_name = "chud", + .major_name = DEVICE_NAME, .minor_shift = CHUDISK_MINOR_SHIFT, .max_p = CHUDISK_MAX_PARTITIONS, .max_nr = CHUDISK_MAX_UNITS, @@ -148,7 +148,7 @@ static unsigned disk_read_sectors(struct ch375 *dev, uint8_t *buffer, uint32_t l uint8_t result; unsigned total = 0; // Total bytes written - dprintf("disk read buf=%p sector=%lu num=%hu\n", buffer, lba, num); + dprintf("disk read buf=%p sector=%u num=%hu\n", buffer, lba, num); // Initiate read operation ch375_disk_read(dev, lba, num); @@ -197,7 +197,7 @@ static unsigned disk_write_sectors(struct ch375 *dev, uint8_t *buffer, uint32_t uint8_t result; unsigned total = 0; // Total bytes written - dprintf("disk write buf=%p sector=%lu num=%hu\n", buffer, lba, num); + dprintf("disk write buf=%p sector=%u num=%hu\n", buffer, lba, num); // Initiate operation ch375_disk_write(dev, lba, num); @@ -387,7 +387,7 @@ static int chudisk_revalidate(kdev_t devno) blk_size = ntohl(*(uint32_t*)&buffer[4]); sector_cnt = ntohl(*(uint32_t*)&buffer[0]); - dprintf("chudisk: sector size %u num sectors %u\n", blk_size, sector_cnt); + dprintf("chudisk[%d]: sector size %u num sectors %u\n", unit, blk_size, sector_cnt); // TODO Support non-default block_size dev->sec_size = blk_size; @@ -566,7 +566,8 @@ static __init int chudisk_init(void) return -ENXIO; } - printk(KERN_INFO "chudisk: found CH375 v.%x at 0x%hx, using major %d\n", + printk(KERN_INFO "chudisk: v%x.%x, found CH375 v.%x at 0x%hx, using major %d\n", + CHUDISK_VERSION_MAJOR, CHUDISK_VERSION_MINOR, ch375_get_version(dev), dev->io_base, MAJOR_NR); // Set defaults for unit @@ -585,7 +586,8 @@ static __init int chudisk_init(void) blksize_size[MAJOR_NR] = chudisk_blksizes; hardsect_size[MAJOR_NR] = chudisk_hardsectsizes; - chudisk_gendisk.major = major; + // Add ourselves to the genhd linked list + chudisk_gendisk.major = MAJOR_NR; chudisk_gendisk.nr_real = 1; chudisk_gendisk.next = gendisk_head; gendisk_head = &chudisk_gendisk; @@ -597,11 +599,20 @@ static __init int chudisk_init(void) static void chudisk_exit(void) { + struct ch375 *dev = &chudisk_dev[0]; struct gendisk **gdp; + int i; - unregister_blkdev(MAJOR_NR, "chud"); - release_region(io, 2); + // Flush buffers for all minors + for (i = 0; i < CHUDISK_MAX_MINORS; i++) { + kdev_t mdevno = MKDEV(MAJOR_NR, i); + fsync_dev(mdevno); + invalidate_inodes_dev(mdevno); + invalidate_buffers(mdevno); + } + + // Remove from genhd list for(gdp = &gendisk_head; *gdp; gdp = &((*gdp)->next)) { if (*gdp == &chudisk_gendisk) { *gdp = (*gdp)->next; @@ -609,14 +620,23 @@ static void chudisk_exit(void) } } + // Remove from blkdev blk_dev[MAJOR_NR].request_fn = NULL; blk_size[MAJOR_NR] = NULL; blksize_size[MAJOR_NR] = NULL; hardsect_size[MAJOR_NR] = NULL; + unregister_blkdev(MAJOR_NR, "chud"); + + // Turn off the chip + ch375_set_usb_mode(dev, CH375_USB_MODE_HOST_DISABLED); + mdelay(1); + ch375_enter_sleep(dev); + + // And unregister driver + release_region(io, 2); dprintf("chudisk: bye\n"); } - module_init(chudisk_init); module_exit(chudisk_exit); |
