--- linux/kernel/blk_drv/hd.c 2018/04/24 18:02:28 1.1.1.2 +++ linux/kernel/blk_drv/hd.c 2018/04/24 18:03:22 1.1.1.3 @@ -35,9 +35,10 @@ inb_p(0x71); \ #define MAX_HD 2 static void recal_intr(void); +static void bad_rw_intr(void); -static int recalibrate = 1; -static int reset = 1; +static int recalibrate = 0; +static int reset = 0; /* * This struct defines the HD's and their types. @@ -58,6 +59,8 @@ static struct hd_struct { long nr_sects; } hd[5*MAX_HD]={{0,0},}; +static int hd_sizes[5*MAX_HD] = {0, }; + #define port_read(port,buf,nr) \ __asm__("cld;rep;insw"::"d" (port),"D" (buf),"c" (nr):"cx","di") @@ -151,16 +154,20 @@ int sys_setup(void * BIOS) } brelse(bh); } + for (i=0 ; i<5*MAX_HD ; i++) + hd_sizes[i] = hd[i].nr_sects>>1 ; + blk_size[MAJOR_NR] = hd_sizes; if (NR_HD) printk("Partition table%s ok.\n\r",(NR_HD>1)?"s":""); rd_load(); + init_swapping(); mount_root(); return (0); } static int controller_ready(void) { - int retries=10000; + int retries = 100000; while (--retries && (inb_p(HD_STATUS)&0xc0)!=0x40); return (retries); @@ -187,7 +194,7 @@ static void hd_out(unsigned int drive,un panic("Trying to write bad sector"); if (!controller_ready()) panic("HD controller not ready"); - do_hd = intr_addr; + SET_INTR(intr_addr); outb_p(hd_info[drive].ctl,HD_CMD); port=HD_DATA; outb_p(hd_info[drive].wpcom>>2,++port); @@ -202,14 +209,14 @@ static void hd_out(unsigned int drive,un static int drive_busy(void) { unsigned int i; + unsigned char c; - for (i = 0; i < 10000; i++) - if (READY_STAT == (inb_p(HD_STATUS) & (BUSY_STAT|READY_STAT))) - break; - i = inb(HD_STATUS); - i &= BUSY_STAT | READY_STAT | SEEK_STAT; - if (i == READY_STAT | SEEK_STAT) - return(0); + for (i = 0; i < 50000; i++) { + c = inb_p(HD_STATUS); + c &= (BUSY_STAT | READY_STAT | SEEK_STAT); + if (c == (READY_STAT | SEEK_STAT)) + return 0; + } printk("HD controller times out\n\r"); return(1); } @@ -219,7 +226,7 @@ static void reset_controller(void) int i; outb(4,HD_CMD); - for(i = 0; i < 100; i++) nop(); + for(i = 0; i < 1000; i++) nop(); outb(hd_info[0].ctl & 0x0f ,HD_CMD); if (drive_busy()) printk("HD-controller still busy\n\r"); @@ -227,16 +234,33 @@ static void reset_controller(void) printk("HD-controller reset failed: %02x\n\r",i); } -static void reset_hd(int nr) +static void reset_hd(void) { - reset_controller(); - hd_out(nr,hd_info[nr].sect,hd_info[nr].sect,hd_info[nr].head-1, - hd_info[nr].cyl,WIN_SPECIFY,&recal_intr); + static int i; + +repeat: + if (reset) { + reset = 0; + i = -1; + reset_controller(); + } else if (win_result()) { + bad_rw_intr(); + if (reset) + goto repeat; + } + i++; + if (i < NR_HD) { + hd_out(i,hd_info[i].sect,hd_info[i].sect,hd_info[i].head-1, + hd_info[i].cyl,WIN_SPECIFY,&reset_hd); + } else + do_hd_request(); } void unexpected_hd_interrupt(void) { printk("Unexpected HD interrupt\n\r"); + reset = 1; + do_hd_request(); } static void bad_rw_intr(void) @@ -259,7 +283,7 @@ static void read_intr(void) CURRENT->buffer += 512; CURRENT->sector++; if (--CURRENT->nr_sectors) { - do_hd = &read_intr; + SET_INTR(&read_intr); return; } end_request(1); @@ -276,7 +300,7 @@ static void write_intr(void) if (--CURRENT->nr_sectors) { CURRENT->sector++; CURRENT->buffer += 512; - do_hd = &write_intr; + SET_INTR(&write_intr); port_write(HD_DATA,CURRENT->buffer,256); return; } @@ -291,6 +315,18 @@ static void recal_intr(void) do_hd_request(); } +void hd_times_out(void) +{ + if (!CURRENT) + return; + printk("HD timeout"); + if (++CURRENT->errors >= MAX_ERRORS) + end_request(0); + SET_INTR(NULL); + reset = 1; + do_hd_request(); +} + void do_hd_request(void) { int i,r; @@ -314,9 +350,8 @@ void do_hd_request(void) sec++; nsect = CURRENT->nr_sectors; if (reset) { - reset = 0; recalibrate = 1; - reset_hd(CURRENT_DEV); + reset_hd(); return; } if (recalibrate) { @@ -327,7 +362,7 @@ void do_hd_request(void) } if (CURRENT->cmd == WRITE) { hd_out(dev,nsect,sec,head,cyl,WIN_WRITE,&write_intr); - for(i=0 ; i<3000 && !(r=inb_p(HD_STATUS)&DRQ_STAT) ; i++) + for(i=0 ; i<10000 && !(r=inb_p(HD_STATUS)&DRQ_STAT) ; i++) /* nothing */ ; if (!r) { bad_rw_intr();