gdth.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:166k
- (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock))
- continue;
- }
- if (firsttime) {
- if (gdth_test_busy(hanum)) { /* controller busy ? */
- TRACE(("gdth_next() controller %d busy !n",hanum));
- if (!gdth_polling) {
- GDTH_UNLOCK_HA(ha, flags);
- return;
- }
- while (gdth_test_busy(hanum))
- gdth_delay(1);
- }
- firsttime = FALSE;
- }
- #if LINUX_VERSION_CODE >= 0x010300
- if (nscp->done != gdth_scsi_done || nscp->cmnd[0] != 0xff)
- #endif
- {
- if (nscp->SCp.phase == -1) {
- nscp->SCp.phase = CACHESERVICE; /* default: cache svc. */
- if (nscp->cmnd[0] == TEST_UNIT_READY) {
- TRACE2(("TEST_UNIT_READY Bus %d Id %d LUN %dn",
- b, t, nscp->lun));
- /* TEST_UNIT_READY -> set scan mode */
- if ((ha->scan_mode & 0x0f) == 0) {
- if (b == 0 && t == 0 && nscp->lun == 0) {
- ha->scan_mode |= 1;
- TRACE2(("Scan mode: 0x%xn", ha->scan_mode));
- }
- } else if ((ha->scan_mode & 0x0f) == 1) {
- if (b == 0 && ((t == 0 && nscp->lun == 1) ||
- (t == 1 && nscp->lun == 0))) {
- nscp->SCp.sent_command = GDT_SCAN_START;
- nscp->SCp.phase = ((ha->scan_mode & 0x10 ? 1:0) << 8)
- | SCSIRAWSERVICE;
- ha->scan_mode = 0x12;
- TRACE2(("Scan mode: 0x%x (SCAN_START)n",
- ha->scan_mode));
- } else {
- ha->scan_mode &= 0x10;
- TRACE2(("Scan mode: 0x%xn", ha->scan_mode));
- }
- } else if (ha->scan_mode == 0x12) {
- if (b == ha->bus_cnt && t == ha->tid_cnt-1) {
- nscp->SCp.phase = SCSIRAWSERVICE;
- nscp->SCp.sent_command = GDT_SCAN_END;
- ha->scan_mode &= 0x10;
- TRACE2(("Scan mode: 0x%x (SCAN_END)n",
- ha->scan_mode));
- }
- }
- }
- if (b == ha->virt_bus && nscp->cmnd[0] != INQUIRY &&
- nscp->cmnd[0] != READ_CAPACITY && nscp->cmnd[0] != MODE_SENSE &&
- (ha->hdr[t].cluster_type & CLUSTER_DRIVE)) {
- /* always GDT_CLUST_INFO! */
- nscp->SCp.sent_command = GDT_CLUST_INFO;
- }
- }
- }
- if (nscp->SCp.sent_command != -1) {
- if ((nscp->SCp.phase & 0xff) == CACHESERVICE) {
- if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
- this_cmd = FALSE;
- next_cmd = FALSE;
- } else if ((nscp->SCp.phase & 0xff) == SCSIRAWSERVICE) {
- if (!(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
- this_cmd = FALSE;
- next_cmd = FALSE;
- } else {
- memset((char*)nscp->sense_buffer,0,16);
- nscp->sense_buffer[0] = 0x70;
- nscp->sense_buffer[2] = NOT_READY;
- nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
- if (!nscp->SCp.have_data_in)
- nscp->SCp.have_data_in++;
- else {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- }
- } else
- #if LINUX_VERSION_CODE >= 0x010300
- if (nscp->done == gdth_scsi_done && nscp->cmnd[0] == 0xff) {
- if (!(cmd_index=gdth_special_cmd(hanum,nscp)))
- this_cmd = FALSE;
- next_cmd = FALSE;
- } else
- #endif
- if (b != ha->virt_bus) {
- if (ha->raw[BUS_L2P(ha,b)].io_cnt[t] >= GDTH_MAX_RAW ||
- !(cmd_index=gdth_fill_raw_cmd(hanum,nscp,BUS_L2P(ha,b))))
- this_cmd = FALSE;
- else
- ha->raw[BUS_L2P(ha,b)].io_cnt[t]++;
- } else if (t >= MAX_HDRIVES || !ha->hdr[t].present || nscp->lun != 0) {
- TRACE2(("Command 0x%x to bus %d id %d lun %d -> IGNOREn",
- nscp->cmnd[0], b, t, nscp->lun));
- nscp->result = DID_BAD_TARGET << 16;
- if (!nscp->SCp.have_data_in)
- nscp->SCp.have_data_in++;
- else {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- } else {
- switch (nscp->cmnd[0]) {
- case TEST_UNIT_READY:
- case INQUIRY:
- case REQUEST_SENSE:
- case READ_CAPACITY:
- case VERIFY:
- case START_STOP:
- case MODE_SENSE:
- TRACE(("cache cmd %x/%x/%x/%x/%x/%xn",nscp->cmnd[0],
- nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
- nscp->cmnd[4],nscp->cmnd[5]));
- if (ha->hdr[t].media_changed && nscp->cmnd[0] != INQUIRY) {
- /* return UNIT_ATTENTION */
- TRACE2(("cmd 0x%x target %d: UNIT_ATTENTIONn",
- nscp->cmnd[0], t));
- ha->hdr[t].media_changed = FALSE;
- memset((char*)nscp->sense_buffer,0,16);
- nscp->sense_buffer[0] = 0x70;
- nscp->sense_buffer[2] = UNIT_ATTENTION;
- nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
- if (!nscp->SCp.have_data_in)
- nscp->SCp.have_data_in++;
- else {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- } else if (gdth_internal_cache_cmd(hanum,nscp)) {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- break;
- case ALLOW_MEDIUM_REMOVAL:
- TRACE(("cache cmd %x/%x/%x/%x/%x/%xn",nscp->cmnd[0],
- nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
- nscp->cmnd[4],nscp->cmnd[5]));
- if ( (nscp->cmnd[4]&1) && !(ha->hdr[t].devtype&1) ) {
- TRACE(("Prevent r. nonremov. drive->do nothingn"));
- nscp->result = DID_OK << 16;
- nscp->sense_buffer[0] = 0;
- if (!nscp->SCp.have_data_in)
- nscp->SCp.have_data_in++;
- else {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- } else {
- nscp->cmnd[3] = (ha->hdr[t].devtype&1) ? 1:0;
- TRACE(("Prevent/allow r. %d rem. drive %dn",
- nscp->cmnd[4],nscp->cmnd[3]));
- if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
- this_cmd = FALSE;
- }
- break;
-
- case RESERVE:
- case RELEASE:
- TRACE2(("cache cmd %sn",nscp->cmnd[0] == RESERVE ?
- "RESERVE" : "RELEASE"));
- if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
- this_cmd = FALSE;
- break;
-
- case READ_6:
- case WRITE_6:
- case READ_10:
- case WRITE_10:
- if (ha->hdr[t].media_changed) {
- /* return UNIT_ATTENTION */
- TRACE2(("cmd 0x%x target %d: UNIT_ATTENTIONn",
- nscp->cmnd[0], t));
- ha->hdr[t].media_changed = FALSE;
- memset((char*)nscp->sense_buffer,0,16);
- nscp->sense_buffer[0] = 0x70;
- nscp->sense_buffer[2] = UNIT_ATTENTION;
- nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
- if (!nscp->SCp.have_data_in)
- nscp->SCp.have_data_in++;
- else {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- } else if (!(cmd_index=gdth_fill_cache_cmd(hanum,nscp,t)))
- this_cmd = FALSE;
- break;
- default:
- TRACE2(("cache cmd %x/%x/%x/%x/%x/%x unknownn",nscp->cmnd[0],
- nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
- nscp->cmnd[4],nscp->cmnd[5]));
- printk("GDT: Unknown SCSI command 0x%x to cache service !n",
- nscp->cmnd[0]);
- nscp->result = DID_ABORT << 16;
- if (!nscp->SCp.have_data_in)
- nscp->SCp.have_data_in++;
- else {
- GDTH_UNLOCK_HA(ha,flags);
- /* io_request_lock already active ! */
- nscp->scsi_done(nscp);
- GDTH_LOCK_HA(ha,flags);
- }
- break;
- }
- }
- if (!this_cmd)
- break;
- if (nscp == ha->req_first)
- ha->req_first = pscp = (Scsi_Cmnd *)nscp->SCp.ptr;
- else
- pscp->SCp.ptr = nscp->SCp.ptr;
- if (!next_cmd)
- break;
- }
- if (ha->cmd_cnt > 0) {
- gdth_release_event(hanum);
- }
- GDTH_UNLOCK_HA(ha, flags);
- if (gdth_polling && ha->cmd_cnt > 0) {
- if (!gdth_wait(hanum,cmd_index,POLL_TIMEOUT))
- printk("GDT: Controller %d: Command %d timed out !n",
- hanum,cmd_index);
- }
- }
-
- static void gdth_copy_internal_data(Scsi_Cmnd *scp,char *buffer,ushort count)
- {
- ushort cpcount,i;
- ushort cpsum,cpnow;
- struct scatterlist *sl;
- cpcount = count<=(ushort)scp->bufflen ? count:(ushort)scp->bufflen;
- if (scp->use_sg) {
- sl = (struct scatterlist *)scp->request_buffer;
- for (i=0,cpsum=0; i<scp->use_sg; ++i,++sl) {
- cpnow = (ushort)sl->length;
- TRACE(("copy_internal() now %d sum %d count %d %dn",
- cpnow,cpsum,cpcount,(ushort)scp->bufflen));
- if (cpsum+cpnow > cpcount)
- cpnow = cpcount - cpsum;
- cpsum += cpnow;
- memcpy((char*)sl->address,buffer,cpnow);
- if (cpsum == cpcount)
- break;
- buffer += cpnow;
- }
- } else {
- TRACE(("copy_internal() count %dn",cpcount));
- memcpy((char*)scp->request_buffer,buffer,cpcount);
- }
- }
- static int gdth_internal_cache_cmd(int hanum,Scsi_Cmnd *scp)
- {
- register gdth_ha_str *ha;
- unchar t;
- gdth_inq_data inq;
- gdth_rdcap_data rdc;
- gdth_sense_data sd;
- gdth_modep_data mpd;
- ha = HADATA(gdth_ctr_tab[hanum]);
- t = scp->target;
- TRACE(("gdth_internal_cache_cmd() cmd 0x%x hdrive %dn",
- scp->cmnd[0],t));
- switch (scp->cmnd[0]) {
- case TEST_UNIT_READY:
- case VERIFY:
- case START_STOP:
- TRACE2(("Test/Verify/Start hdrive %dn",t));
- break;
- case INQUIRY:
- TRACE2(("Inquiry hdrive %d devtype %dn",
- t,ha->hdr[t].devtype));
- inq.type_qual = (ha->hdr[t].devtype&4) ? TYPE_ROM:TYPE_DISK;
- /* you can here set all disks to removable, if you want to do
- a flush using the ALLOW_MEDIUM_REMOVAL command */
- inq.modif_rmb = 0x00;
- if ((ha->hdr[t].devtype & 1) ||
- (ha->hdr[t].cluster_type & CLUSTER_DRIVE))
- inq.modif_rmb = 0x80;
- inq.version = 2;
- inq.resp_aenc = 2;
- inq.add_length= 32;
- if (ha->oem_id == OEM_ID_INTEL)
- strcpy(inq.vendor,"Intel ");
- else
- strcpy(inq.vendor,"ICP ");
- sprintf(inq.product,"Host Drive #%02d",t);
- strcpy(inq.revision," ");
- gdth_copy_internal_data(scp,(char*)&inq,sizeof(gdth_inq_data));
- break;
- case REQUEST_SENSE:
- TRACE2(("Request sense hdrive %dn",t));
- sd.errorcode = 0x70;
- sd.segno = 0x00;
- sd.key = NO_SENSE;
- sd.info = 0;
- sd.add_length= 0;
- gdth_copy_internal_data(scp,(char*)&sd,sizeof(gdth_sense_data));
- break;
- case MODE_SENSE:
- TRACE2(("Mode sense hdrive %dn",t));
- memset((char*)&mpd,0,sizeof(gdth_modep_data));
- mpd.hd.data_length = sizeof(gdth_modep_data);
- mpd.hd.dev_par = (ha->hdr[t].devtype&2) ? 0x80:0;
- mpd.hd.bd_length = sizeof(mpd.bd);
- mpd.bd.block_length[0] = (SECTOR_SIZE & 0x00ff0000) >> 16;
- mpd.bd.block_length[1] = (SECTOR_SIZE & 0x0000ff00) >> 8;
- mpd.bd.block_length[2] = (SECTOR_SIZE & 0x000000ff);
- gdth_copy_internal_data(scp,(char*)&mpd,sizeof(gdth_modep_data));
- break;
- case READ_CAPACITY:
- TRACE2(("Read capacity hdrive %dn",t));
- rdc.last_block_no = ntohl(ha->hdr[t].size-1);
- rdc.block_length = ntohl(SECTOR_SIZE);
- gdth_copy_internal_data(scp,(char*)&rdc,sizeof(gdth_rdcap_data));
- break;
- default:
- TRACE2(("Internal cache cmd 0x%x unknownn",scp->cmnd[0]));
- break;
- }
- scp->result = DID_OK << 16;
- scp->sense_buffer[0] = 0;
- if (!scp->SCp.have_data_in)
- scp->SCp.have_data_in++;
- else
- return 1;
- return 0;
- }
-
- static int gdth_fill_cache_cmd(int hanum,Scsi_Cmnd *scp,ushort hdrive)
- {
- register gdth_ha_str *ha;
- register gdth_cmd_str *cmdp;
- struct scatterlist *sl;
- ushort i, cnt;
- ulong32 no;
- int cmd_index, read_write;
- ha = HADATA(gdth_ctr_tab[hanum]);
- cmdp = ha->pccb;
- TRACE(("gdth_fill_cache_cmd() cmd 0x%x cmdsize %d hdrive %dn",
- scp->cmnd[0],scp->cmd_len,hdrive));
- if (ha->type==GDT_EISA && ha->cmd_cnt>0)
- return 0;
- cmdp->Service = CACHESERVICE;
- cmdp->RequestBuffer = scp;
- /* search free command index */
- if (!(cmd_index=gdth_get_cmd_index(hanum))) {
- TRACE(("GDT: No free command index foundn"));
- return 0;
- }
- /* if it's the first command, set command semaphore */
- if (ha->cmd_cnt == 0)
- gdth_set_sema0(hanum);
- /* fill command */
- read_write = FALSE;
- if (scp->SCp.sent_command != -1)
- cmdp->OpCode = scp->SCp.sent_command; /* special cache cmd. */
- else if (scp->cmnd[0] == RESERVE)
- cmdp->OpCode = GDT_RESERVE_DRV;
- else if (scp->cmnd[0] == RELEASE)
- cmdp->OpCode = GDT_RELEASE_DRV;
- else if (scp->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
- if (scp->cmnd[4] & 1) /* prevent ? */
- cmdp->OpCode = GDT_MOUNT;
- else if (scp->cmnd[3] & 1) /* removable drive ? */
- cmdp->OpCode = GDT_UNMOUNT;
- else
- cmdp->OpCode = GDT_FLUSH;
- } else if (scp->cmnd[0] == WRITE_6 || scp->cmnd[0] == WRITE_10) {
- read_write = TRUE;
- if (gdth_write_through || ((ha->hdr[hdrive].rw_attribs & 1) &&
- (ha->cache_feat & GDT_WR_THROUGH)))
- cmdp->OpCode = GDT_WRITE_THR;
- else
- cmdp->OpCode = GDT_WRITE;
- } else {
- read_write = TRUE;
- cmdp->OpCode = GDT_READ;
- }
-
- cmdp->BoardNode = LOCALBOARD;
- cmdp->u.cache.DeviceNo = hdrive;
- cmdp->u.cache.BlockNo = 1;
- cmdp->u.cache.sg_canz = 0;
- if (read_write) {
- if (scp->cmd_len != 6) {
- memcpy(&no, &scp->cmnd[2], sizeof(ulong32));
- cmdp->u.cache.BlockNo = ntohl(no);
- memcpy(&cnt, &scp->cmnd[7], sizeof(ushort));
- cmdp->u.cache.BlockCnt = (ulong32)ntohs(cnt);
- } else {
- memcpy(&no, &scp->cmnd[0], sizeof(ulong32));
- cmdp->u.cache.BlockNo = ntohl(no) & 0x001fffffUL;
- cmdp->u.cache.BlockCnt= scp->cmnd[4]==0 ? 0x100 : scp->cmnd[4];
- }
- if (scp->use_sg) {
- cmdp->u.cache.DestAddr= 0xffffffff;
- sl = (struct scatterlist *)scp->request_buffer;
- for (i=0; i<scp->use_sg; ++i,++sl) {
- cmdp->u.cache.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
- cmdp->u.cache.sg_lst[i].sg_len = (ulong32)sl->length;
- }
- cmdp->u.cache.sg_canz = (ulong32)i;
- #ifdef GDTH_STATISTICS
- if (max_sg < (ulong32)i) {
- max_sg = (ulong32)i;
- TRACE3(("GDT: max_sg = %dn",i));
- }
- #endif
- if (i<GDTH_MAXSG)
- cmdp->u.cache.sg_lst[i].sg_len = 0;
- } else {
- if (ha->cache_feat & SCATTER_GATHER) {
- cmdp->u.cache.DestAddr = 0xffffffff;
- cmdp->u.cache.sg_canz = 1;
- cmdp->u.cache.sg_lst[0].sg_ptr =
- virt_to_bus(scp->request_buffer);
- cmdp->u.cache.sg_lst[0].sg_len = scp->request_bufflen;
- cmdp->u.cache.sg_lst[1].sg_len = 0;
- } else {
- cmdp->u.cache.DestAddr = virt_to_bus(scp->request_buffer);
- cmdp->u.cache.sg_canz= 0;
- }
- }
- }
- TRACE(("cache cmd: addr. %x sganz %x sgptr0 %x sglen0 %xn",
- cmdp->u.cache.DestAddr,cmdp->u.cache.sg_canz,
- cmdp->u.cache.sg_lst[0].sg_ptr,
- cmdp->u.cache.sg_lst[0].sg_len));
- TRACE(("cache cmd: cmd %d blockno. %d, blockcnt %dn",
- cmdp->OpCode,cmdp->u.cache.BlockNo,cmdp->u.cache.BlockCnt));
- /* evaluate command size, check space */
- ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) +
- (ushort)cmdp->u.cache.sg_canz * sizeof(gdth_sg_str);
- if (ha->cmd_len & 3)
- ha->cmd_len += (4 - (ha->cmd_len & 3));
- if (ha->cmd_cnt > 0) {
- if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
- ha->ic_all_size) {
- TRACE2(("gdth_fill_cache() DPMEM overflown"));
- ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
- return 0;
- }
- }
- /* copy command */
- gdth_copy_command(hanum);
- return cmd_index;
- }
- static int gdth_fill_raw_cmd(int hanum,Scsi_Cmnd *scp,unchar b)
- {
- register gdth_ha_str *ha;
- register gdth_cmd_str *cmdp;
- struct scatterlist *sl;
- ushort i;
- int cmd_index;
- unchar t,l;
- ha = HADATA(gdth_ctr_tab[hanum]);
- t = scp->target;
- l = scp->lun;
- cmdp = ha->pccb;
- TRACE(("gdth_fill_raw_cmd() cmd 0x%x bus %d ID %d LUN %dn",
- scp->cmnd[0],b,t,l));
- if (ha->type==GDT_EISA && ha->cmd_cnt>0)
- return 0;
- cmdp->Service = SCSIRAWSERVICE;
- cmdp->RequestBuffer = scp;
- /* search free command index */
- if (!(cmd_index=gdth_get_cmd_index(hanum))) {
- TRACE(("GDT: No free command index foundn"));
- return 0;
- }
- /* if it's the first command, set command semaphore */
- if (ha->cmd_cnt == 0)
- gdth_set_sema0(hanum);
- /* fill command */
- if (scp->SCp.sent_command != -1) {
- cmdp->OpCode = scp->SCp.sent_command; /* special raw cmd. */
- cmdp->BoardNode = LOCALBOARD;
- cmdp->u.raw.direction = (scp->SCp.phase >> 8);
- TRACE2(("special raw cmd 0x%x param 0x%xn",
- cmdp->OpCode, cmdp->u.raw.direction));
- /* evaluate command size */
- ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst);
- } else {
- cmdp->OpCode = GDT_WRITE; /* always */
- cmdp->BoardNode = LOCALBOARD;
- cmdp->u.raw.reserved = 0;
- cmdp->u.raw.mdisc_time = 0;
- cmdp->u.raw.mcon_time = 0;
- cmdp->u.raw.clen = scp->cmd_len;
- cmdp->u.raw.target = t;
- cmdp->u.raw.lun = l;
- cmdp->u.raw.bus = b;
- cmdp->u.raw.priority = 0;
- cmdp->u.raw.link_p = 0;
- cmdp->u.raw.sdlen = scp->request_bufflen;
- cmdp->u.raw.sense_len = 16;
- cmdp->u.raw.sense_data = virt_to_bus(scp->sense_buffer);
- cmdp->u.raw.direction =
- gdth_direction_tab[scp->cmnd[0]]==DOU ? GDTH_DATA_OUT:GDTH_DATA_IN;
- memcpy(cmdp->u.raw.cmd,scp->cmnd,12);
- if (scp->use_sg) {
- cmdp->u.raw.sdata = 0xffffffff;
- sl = (struct scatterlist *)scp->request_buffer;
- for (i=0; i<scp->use_sg; ++i,++sl) {
- cmdp->u.raw.sg_lst[i].sg_ptr = virt_to_bus(sl->address);
- cmdp->u.raw.sg_lst[i].sg_len = (ulong32)sl->length;
- }
- cmdp->u.raw.sg_ranz = (ulong32)i;
- #ifdef GDTH_STATISTICS
- if (max_sg < (ulong32)i) {
- max_sg = (ulong32)i;
- TRACE3(("GDT: max_sg = %dn",i));
- }
- #endif
- if (i<GDTH_MAXSG)
- cmdp->u.raw.sg_lst[i].sg_len = 0;
- } else {
- if (ha->raw_feat & SCATTER_GATHER) {
- cmdp->u.raw.sdata = 0xffffffff;
- cmdp->u.raw.sg_ranz= 1;
- cmdp->u.raw.sg_lst[0].sg_ptr = virt_to_bus(scp->request_buffer);
- cmdp->u.raw.sg_lst[0].sg_len = scp->request_bufflen;
- cmdp->u.raw.sg_lst[1].sg_len = 0;
- } else {
- cmdp->u.raw.sdata = virt_to_bus(scp->request_buffer);
- cmdp->u.raw.sg_ranz= 0;
- }
- }
- TRACE(("raw cmd: addr. %x sganz %x sgptr0 %x sglen0 %xn",
- cmdp->u.raw.sdata,cmdp->u.raw.sg_ranz,
- cmdp->u.raw.sg_lst[0].sg_ptr,
- cmdp->u.raw.sg_lst[0].sg_len));
- /* evaluate command size */
- ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) +
- (ushort)cmdp->u.raw.sg_ranz * sizeof(gdth_sg_str);
- }
- /* check space */
- if (ha->cmd_len & 3)
- ha->cmd_len += (4 - (ha->cmd_len & 3));
- if (ha->cmd_cnt > 0) {
- if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
- ha->ic_all_size) {
- TRACE2(("gdth_fill_raw() DPMEM overflown"));
- ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
- return 0;
- }
- }
- /* copy command */
- gdth_copy_command(hanum);
- return cmd_index;
- }
- static int gdth_special_cmd(int hanum,Scsi_Cmnd *scp)
- {
- register gdth_ha_str *ha;
- register gdth_cmd_str *cmdp;
- int cmd_index;
- ha = HADATA(gdth_ctr_tab[hanum]);
- cmdp= ha->pccb;
- TRACE2(("gdth_special_cmd(): "));
- if (ha->type==GDT_EISA && ha->cmd_cnt>0)
- return 0;
- memcpy( cmdp, scp->request_buffer, sizeof(gdth_cmd_str));
- cmdp->RequestBuffer = scp;
- /* search free command index */
- if (!(cmd_index=gdth_get_cmd_index(hanum))) {
- TRACE(("GDT: No free command index foundn"));
- return 0;
- }
- /* if it's the first command, set command semaphore */
- if (ha->cmd_cnt == 0)
- gdth_set_sema0(hanum);
- /* evaluate command size, check space */
- if (cmdp->OpCode == GDT_IOCTL) {
- TRACE2(("IOCTLn"));
- ha->cmd_len =
- GDTOFFSOF(gdth_cmd_str,u.ioctl.p_param) + sizeof(ulong32);
- } else if (cmdp->Service == CACHESERVICE) {
- TRACE2(("cache command %dn",cmdp->OpCode));
- ha->cmd_len =
- GDTOFFSOF(gdth_cmd_str,u.cache.sg_lst) + sizeof(gdth_sg_str);
- } else if (cmdp->Service == SCSIRAWSERVICE) {
- TRACE2(("raw command %d/%dn",cmdp->OpCode,cmdp->u.raw.cmd[0]));
- ha->cmd_len =
- GDTOFFSOF(gdth_cmd_str,u.raw.sg_lst) + sizeof(gdth_sg_str);
- }
- if (ha->cmd_len & 3)
- ha->cmd_len += (4 - (ha->cmd_len & 3));
- if (ha->cmd_cnt > 0) {
- if ((ha->cmd_offs_dpmem + ha->cmd_len + DPMEM_COMMAND_OFFSET) >
- ha->ic_all_size) {
- TRACE2(("gdth_special_cmd() DPMEM overflown"));
- ha->cmd_tab[cmd_index-2].cmnd = UNUSED_CMND;
- return 0;
- }
- }
- /* copy command */
- gdth_copy_command(hanum);
- return cmd_index;
- }
- /* Controller event handling functions */
- static gdth_evt_str *gdth_store_event(gdth_ha_str *ha, ushort source,
- ushort idx, gdth_evt_data *evt)
- {
- gdth_evt_str *e;
- struct timeval tv;
- /* no GDTH_LOCK_HA() ! */
- TRACE2(("gdth_store_event() source %d idx %dn", source, idx));
- if (source == 0) /* no source -> no event */
- return 0;
- if (ebuffer[elastidx].event_source == source &&
- ebuffer[elastidx].event_idx == idx &&
- ((evt->size != 0 && ebuffer[elastidx].event_data.size != 0 &&
- !memcmp((char *)&ebuffer[elastidx].event_data.eu,
- (char *)&evt->eu, evt->size)) ||
- (evt->size == 0 && ebuffer[elastidx].event_data.size == 0 &&
- !strcmp((char *)&ebuffer[elastidx].event_data.event_string,
- (char *)&evt->event_string)))) {
- e = &ebuffer[elastidx];
- do_gettimeofday(&tv);
- e->last_stamp = tv.tv_sec;
- ++e->same_count;
- } else {
- if (ebuffer[elastidx].event_source != 0) { /* entry not free ? */
- ++elastidx;
- if (elastidx == MAX_EVENTS)
- elastidx = 0;
- if (elastidx == eoldidx) { /* reached mark ? */
- ++eoldidx;
- if (eoldidx == MAX_EVENTS)
- eoldidx = 0;
- }
- }
- e = &ebuffer[elastidx];
- e->event_source = source;
- e->event_idx = idx;
- do_gettimeofday(&tv);
- e->first_stamp = e->last_stamp = tv.tv_sec;
- e->same_count = 1;
- e->event_data = *evt;
- e->application = 0;
- }
- return e;
- }
- static int gdth_read_event(gdth_ha_str *ha, int handle, gdth_evt_str *estr)
- {
- gdth_evt_str *e;
- int eindex;
- ulong flags;
- TRACE2(("gdth_read_event() handle %dn", handle));
- GDTH_LOCK_HA(ha, flags);
- if (handle == -1)
- eindex = eoldidx;
- else
- eindex = handle;
- estr->event_source = 0;
- if (eindex >= MAX_EVENTS) {
- GDTH_UNLOCK_HA(ha, flags);
- return eindex;
- }
- e = &ebuffer[eindex];
- if (e->event_source != 0) {
- if (eindex != elastidx) {
- if (++eindex == MAX_EVENTS)
- eindex = 0;
- } else {
- eindex = -1;
- }
- memcpy(estr, e, sizeof(gdth_evt_str));
- }
- GDTH_UNLOCK_HA(ha, flags);
- return eindex;
- }
- static void gdth_readapp_event(gdth_ha_str *ha,
- unchar application, gdth_evt_str *estr)
- {
- gdth_evt_str *e;
- int eindex;
- ulong flags;
- unchar found = FALSE;
- TRACE2(("gdth_readapp_event() app. %dn", application));
- GDTH_LOCK_HA(ha, flags);
- eindex = eoldidx;
- for (;;) {
- e = &ebuffer[eindex];
- if (e->event_source == 0)
- break;
- if ((e->application & application) == 0) {
- e->application |= application;
- found = TRUE;
- break;
- }
- if (eindex == elastidx)
- break;
- if (++eindex == MAX_EVENTS)
- eindex = 0;
- }
- if (found)
- memcpy(estr, e, sizeof(gdth_evt_str));
- else
- estr->event_source = 0;
- GDTH_UNLOCK_HA(ha, flags);
- }
- static void gdth_clear_events()
- {
- TRACE(("gdth_clear_events()"));
- eoldidx = elastidx = 0;
- ebuffer[0].event_source = 0;
- }
- /* SCSI interface functions */
- #if LINUX_VERSION_CODE >= 0x010346
- static void gdth_interrupt(int irq,void *dev_id,struct pt_regs *regs)
- #else
- static void gdth_interrupt(int irq,struct pt_regs *regs)
- #endif
- {
- register gdth_ha_str *ha;
- gdt6m_dpram_str *dp6m_ptr;
- gdt6_dpram_str *dp6_ptr;
- gdt2_dpram_str *dp2_ptr;
- Scsi_Cmnd *scp;
- int hanum, rval, i;
- unchar IStatus;
- ushort Service;
- ulong flags = 0;
- TRACE(("gdth_interrupt() IRQ %dn",irq));
- /* if polling and not from gdth_wait() -> return */
- if (gdth_polling) {
- if (!gdth_from_wait) {
- return;
- }
- }
- if (!gdth_polling)
- GDTH_LOCK_HA((gdth_ha_str *)dev_id,flags);
- wait_index = 0;
- /* search controller */
- if ((hanum = gdth_get_status(&IStatus,irq)) == -1) {
- /* spurious interrupt */
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- return;
- }
- #ifdef GDTH_STATISTICS
- ++act_ints;
- #endif
-
- ha = HADATA(gdth_ctr_tab[hanum]);
- if (ha->type == GDT_EISA) {
- if (IStatus & 0x80) { /* error flag */
- IStatus &= ~0x80;
- ha->status = inw(ha->bmic + MAILBOXREG+8);
- TRACE2(("gdth_interrupt() error %d/%dn",IStatus,ha->status));
- } else /* no error */
- ha->status = S_OK;
- ha->info = inl(ha->bmic + MAILBOXREG+12);
- ha->service = inw(ha->bmic + MAILBOXREG+10);
- ha->info2 = inl(ha->bmic + MAILBOXREG+4);
- outb(0xff, ha->bmic + EDOORREG); /* acknowledge interrupt */
- outb(0x00, ha->bmic + SEMA1REG); /* reset status semaphore */
- } else if (ha->type == GDT_ISA) {
- dp2_ptr = (gdt2_dpram_str *)ha->brd;
- if (IStatus & 0x80) { /* error flag */
- IStatus &= ~0x80;
- ha->status = gdth_readw(&dp2_ptr->u.ic.Status);
- TRACE2(("gdth_interrupt() error %d/%dn",IStatus,ha->status));
- } else /* no error */
- ha->status = S_OK;
- ha->info = gdth_readl(&dp2_ptr->u.ic.Info[0]);
- ha->service = gdth_readw(&dp2_ptr->u.ic.Service);
- ha->info2 = gdth_readl(&dp2_ptr->u.ic.Info[1]);
- gdth_writeb(0xff, &dp2_ptr->io.irqdel); /* acknowledge interrupt */
- gdth_writeb(0, &dp2_ptr->u.ic.Cmd_Index); /* reset command index */
- gdth_writeb(0, &dp2_ptr->io.Sema1); /* reset status semaphore */
- } else if (ha->type == GDT_PCI) {
- dp6_ptr = (gdt6_dpram_str *)ha->brd;
- if (IStatus & 0x80) { /* error flag */
- IStatus &= ~0x80;
- ha->status = gdth_readw(&dp6_ptr->u.ic.Status);
- TRACE2(("gdth_interrupt() error %d/%dn",IStatus,ha->status));
- } else /* no error */
- ha->status = S_OK;
- ha->info = gdth_readl(&dp6_ptr->u.ic.Info[0]);
- ha->service = gdth_readw(&dp6_ptr->u.ic.Service);
- ha->info2 = gdth_readl(&dp6_ptr->u.ic.Info[1]);
- gdth_writeb(0xff, &dp6_ptr->io.irqdel); /* acknowledge interrupt */
- gdth_writeb(0, &dp6_ptr->u.ic.Cmd_Index); /* reset command index */
- gdth_writeb(0, &dp6_ptr->io.Sema1); /* reset status semaphore */
- } else if (ha->type == GDT_PCINEW) {
- if (IStatus & 0x80) { /* error flag */
- IStatus &= ~0x80;
- ha->status = inw(PTR2USHORT(&ha->plx->status));
- TRACE2(("gdth_interrupt() error %d/%dn",IStatus,ha->status));
- } else
- ha->status = S_OK;
- ha->info = inl(PTR2USHORT(&ha->plx->info[0]));
- ha->service = inw(PTR2USHORT(&ha->plx->service));
- ha->info2 = inl(PTR2USHORT(&ha->plx->info[1]));
- outb(0xff, PTR2USHORT(&ha->plx->edoor_reg));
- outb(0x00, PTR2USHORT(&ha->plx->sema1_reg));
- } else if (ha->type == GDT_PCIMPR) {
- dp6m_ptr = (gdt6m_dpram_str *)ha->brd;
- if (IStatus & 0x80) { /* error flag */
- IStatus &= ~0x80;
- ha->status = gdth_readw(&dp6m_ptr->i960r.status);
- TRACE2(("gdth_interrupt() error %d/%dn",IStatus,ha->status));
- } else /* no error */
- ha->status = S_OK;
- ha->info = gdth_readl(&dp6m_ptr->i960r.info[0]);
- ha->service = gdth_readw(&dp6m_ptr->i960r.service);
- ha->info2 = gdth_readl(&dp6m_ptr->i960r.info[1]);
- /* event string */
- if (IStatus == ASYNCINDEX) {
- if (ha->service != SCREENSERVICE &&
- (ha->fw_vers & 0xff) >= 0x1a) {
- ha->dvr.severity =
- gdth_readb(&((gdt6m_dpram_str *)ha->brd)->i960r.severity);
- for (i = 0; i < 256; ++i) {
- ha->dvr.event_string[i] = gdth_readb
- (&((gdt6m_dpram_str *)ha->brd)->i960r.evt_str[i]);
- if (ha->dvr.event_string[i] == 0)
- break;
- }
- }
- }
- gdth_writeb(0xff, &dp6m_ptr->i960r.edoor_reg);
- gdth_writeb(0, &dp6m_ptr->i960r.sema1_reg);
- } else {
- TRACE2(("gdth_interrupt() unknown controller typen"));
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- return;
- }
- TRACE(("gdth_interrupt() index %d stat %d info %dn",
- IStatus,ha->status,ha->info));
- if (gdth_from_wait) {
- wait_hanum = hanum;
- wait_index = (int)IStatus;
- }
- if (IStatus == ASYNCINDEX) {
- TRACE2(("gdth_interrupt() async. eventn"));
- gdth_async_event(hanum);
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- gdth_next(hanum);
- return;
- }
- if (IStatus == SPEZINDEX) {
- TRACE2(("Service unknown or not initialized !n"));
- ha->dvr.size = sizeof(ha->dvr.eu.driver);
- ha->dvr.eu.driver.ionode = hanum;
- gdth_store_event(ha, ES_DRIVER, 4, &ha->dvr);
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- return;
- }
- scp = ha->cmd_tab[IStatus-2].cmnd;
- Service = ha->cmd_tab[IStatus-2].service;
- ha->cmd_tab[IStatus-2].cmnd = UNUSED_CMND;
- if (scp == UNUSED_CMND) {
- TRACE2(("gdth_interrupt() index to unused command (%d)n",IStatus));
- ha->dvr.size = sizeof(ha->dvr.eu.driver);
- ha->dvr.eu.driver.ionode = hanum;
- ha->dvr.eu.driver.index = IStatus;
- gdth_store_event(ha, ES_DRIVER, 1, &ha->dvr);
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- return;
- }
- if (scp == INTERNAL_CMND) {
- TRACE(("gdth_interrupt() answer to internal commandn"));
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- return;
- }
- TRACE(("gdth_interrupt() sync. statusn"));
- rval = gdth_sync_event(hanum,Service,IStatus,scp);
- if (!gdth_polling)
- GDTH_UNLOCK_HA((gdth_ha_str *)dev_id,flags);
- if (rval == 2) {
- gdth_putq(hanum,scp,scp->SCp.this_residual);
- } else if (rval == 1) {
- GDTH_LOCK_SCSI_DONE(flags);
- scp->scsi_done(scp);
- GDTH_UNLOCK_SCSI_DONE(flags);
- }
- gdth_next(hanum);
- }
- static int gdth_sync_event(int hanum,int service,unchar index,Scsi_Cmnd *scp)
- {
- register gdth_ha_str *ha;
- gdth_msg_str *msg;
- gdth_cmd_str *cmdp;
- unchar b;
- ha = HADATA(gdth_ctr_tab[hanum]);
- cmdp = ha->pccb;
- TRACE(("gdth_sync_event() serv %d status %dn",
- service,ha->status));
- if (service == SCREENSERVICE) {
- msg = (gdth_msg_str *)ha->pscratch;
- ha->scratch_busy = FALSE;
- TRACE(("len: %d, answer: %d, ext: %d, alen: %dn",
- msg->msg_len,msg->msg_answer,msg->msg_ext,msg->msg_alen));
- if (msg->msg_len)
- if (!(msg->msg_answer && msg->msg_ext)) {
- msg->msg_text[msg->msg_len] = '';
- printk("%s",msg->msg_text);
- }
- if (msg->msg_ext && !msg->msg_answer) {
- while (gdth_test_busy(hanum))
- gdth_delay(0);
- cmdp->Service = SCREENSERVICE;
- cmdp->RequestBuffer = SCREEN_CMND;
- gdth_get_cmd_index(hanum);
- gdth_set_sema0(hanum);
- cmdp->OpCode = GDT_READ;
- cmdp->BoardNode = LOCALBOARD;
- cmdp->u.screen.reserved = 0;
- cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
- cmdp->u.screen.su.msg.msg_addr = virt_to_bus(msg);
- ha->scratch_busy = TRUE;
- ha->cmd_offs_dpmem = 0;
- ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
- + sizeof(ulong32);
- ha->cmd_cnt = 0;
- gdth_copy_command(hanum);
- gdth_release_event(hanum);
- return 0;
- }
- if (msg->msg_answer && msg->msg_alen) {
- /* default answers (getchar() not possible) */
- if (msg->msg_alen == 1) {
- msg->msg_alen = 0;
- msg->msg_len = 1;
- msg->msg_text[0] = 0;
- } else {
- msg->msg_alen -= 2;
- msg->msg_len = 2;
- msg->msg_text[0] = 1;
- msg->msg_text[1] = 0;
- }
- msg->msg_ext = 0;
- msg->msg_answer = 0;
- while (gdth_test_busy(hanum))
- gdth_delay(0);
- cmdp->Service = SCREENSERVICE;
- cmdp->RequestBuffer = SCREEN_CMND;
- gdth_get_cmd_index(hanum);
- gdth_set_sema0(hanum);
- cmdp->OpCode = GDT_WRITE;
- cmdp->BoardNode = LOCALBOARD;
- cmdp->u.screen.reserved = 0;
- cmdp->u.screen.su.msg.msg_handle= msg->msg_handle;
- cmdp->u.screen.su.msg.msg_addr = virt_to_bus(msg);
- ha->scratch_busy = TRUE;
- ha->cmd_offs_dpmem = 0;
- ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
- + sizeof(ulong32);
- ha->cmd_cnt = 0;
- gdth_copy_command(hanum);
- gdth_release_event(hanum);
- return 0;
- }
- printk("n");
- } else {
- b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
- if (scp->SCp.sent_command == -1 && b != ha->virt_bus) {
- ha->raw[BUS_L2P(ha,b)].io_cnt[scp->target]--;
- }
- /* cache or raw service */
- if (ha->status == S_OK) {
- scp->SCp.Status = S_OK;
- scp->SCp.Message = ha->info;
- if (scp->SCp.sent_command != -1) {
- TRACE2(("gdth_sync_event(): special cmd 0x%x OKn",
- scp->SCp.sent_command));
- /* special commands GDT_CLUST_INFO/GDT_MOUNT ? */
- if (scp->SCp.sent_command == GDT_CLUST_INFO) {
- ha->hdr[scp->target].cluster_type = (unchar)ha->info;
- if (!(ha->hdr[scp->target].cluster_type &
- CLUSTER_MOUNTED)) {
- /* NOT MOUNTED -> MOUNT */
- scp->SCp.sent_command = GDT_MOUNT;
- if (ha->hdr[scp->target].cluster_type &
- CLUSTER_RESERVED) {
- /* cluster drive RESERVED (on the other node) */
- scp->SCp.phase = -2; /* reservation conflict */
- }
- } else {
- scp->SCp.sent_command = -1;
- }
- } else {
- if (scp->SCp.sent_command == GDT_MOUNT) {
- ha->hdr[scp->target].cluster_type |= CLUSTER_MOUNTED;
- ha->hdr[scp->target].media_changed = TRUE;
- } else if (scp->SCp.sent_command == GDT_UNMOUNT) {
- ha->hdr[scp->target].cluster_type &= ~CLUSTER_MOUNTED;
- ha->hdr[scp->target].media_changed = TRUE;
- }
- scp->SCp.sent_command = -1;
- }
- /* retry */
- scp->SCp.this_residual = HIGH_PRI;
- return 2;
- } else {
- /* RESERVE/RELEASE ? */
- if (scp->cmnd[0] == RESERVE) {
- ha->hdr[scp->target].cluster_type |= CLUSTER_RESERVED;
- } else if (scp->cmnd[0] == RELEASE) {
- ha->hdr[scp->target].cluster_type &= ~CLUSTER_RESERVED;
- }
- scp->result = DID_OK << 16;
- scp->sense_buffer[0] = 0;
- }
- } else if (ha->status == S_BSY) {
- TRACE2(("Controller busy -> retry !n"));
- scp->SCp.Status = S_BSY;
- scp->SCp.Message = ha->info;
- if (scp->SCp.sent_command == GDT_MOUNT)
- scp->SCp.sent_command = GDT_CLUST_INFO;
- /* retry */
- return 2;
- } else {
- scp->SCp.Status = ha->status;
- scp->SCp.Message = ha->info;
- if (scp->SCp.sent_command != -1) {
- TRACE2(("gdth_sync_event(): special cmd 0x%x error 0x%xn",
- scp->SCp.sent_command, ha->status));
- if (scp->SCp.sent_command == GDT_SCAN_START ||
- scp->SCp.sent_command == GDT_SCAN_END) {
- scp->SCp.sent_command = -1;
- /* retry */
- scp->SCp.this_residual = HIGH_PRI;
- return 2;
- }
- memset((char*)scp->sense_buffer,0,16);
- scp->sense_buffer[0] = 0x70;
- scp->sense_buffer[2] = NOT_READY;
- scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
- } else if (service == CACHESERVICE) {
- if (ha->status == S_CACHE_UNKNOWN &&
- (ha->hdr[scp->target].cluster_type &
- CLUSTER_RESERVE_STATE) == CLUSTER_RESERVE_STATE) {
- /* bus reset -> force GDT_CLUST_INFO */
- ha->hdr[scp->target].cluster_type &= ~CLUSTER_RESERVED;
- }
- memset((char*)scp->sense_buffer,0,16);
- scp->sense_buffer[0] = 0x70;
- scp->sense_buffer[2] = NOT_READY;
- scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
- #if LINUX_VERSION_CODE >= 0x010300
- if (scp->done != gdth_scsi_done)
- #endif
- {
- ha->dvr.size = sizeof(ha->dvr.eu.sync);
- ha->dvr.eu.sync.ionode = hanum;
- ha->dvr.eu.sync.service = service;
- ha->dvr.eu.sync.status = ha->status;
- ha->dvr.eu.sync.info = ha->info;
- ha->dvr.eu.sync.hostdrive = scp->target;
- if (ha->status >= 0x8000)
- gdth_store_event(ha, ES_SYNC, 0, &ha->dvr);
- else
- gdth_store_event(ha, ES_SYNC, service, &ha->dvr);
- }
- } else {
- /* sense buffer filled from controller firmware (DMA) */
- if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
- scp->result = DID_BAD_TARGET << 16;
- } else {
- scp->result = (DID_OK << 16) | ha->info;
- }
- }
- }
- if (!scp->SCp.have_data_in)
- scp->SCp.have_data_in++;
- else
- return 1;
- }
- return 0;
- }
- static char *async_cache_tab[] = {
- /* 0*/ "110002020204020604"
- "GDT HA %u, service %u, async. status %u/%lu unknown",
- /* 1*/ "110002020204020604"
- "GDT HA %u, service %u, async. status %u/%lu unknown",
- /* 2*/ "0500020604"
- "GDT HA %u, Host Drive %lu not ready",
- /* 3*/ "0500020604"
- "GDT HA %u, Host Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
- /* 4*/ "0500020604"
- "GDT HA %u, mirror update on Host Drive %lu failed",
- /* 5*/ "0500020604"
- "GDT HA %u, Mirror Drive %lu failed",
- /* 6*/ "0500020604"
- "GDT HA %u, Mirror Drive %lu: REASSIGN not successful and/or data error on reassigned blocks. Drive may crash in the future and should be replaced",
- /* 7*/ "0500020604"
- "GDT HA %u, Host Drive %lu write protected",
- /* 8*/ "0500020604"
- "GDT HA %u, media changed in Host Drive %lu",
- /* 9*/ "0500020604"
- "GDT HA %u, Host Drive %lu is offline",
- /*10*/ "0500020604"
- "GDT HA %u, media change of Mirror Drive %lu",
- /*11*/ "0500020604"
- "GDT HA %u, Mirror Drive %lu is write protected",
- /*12*/ "0500020604"
- "GDT HA %u, general error on Host Drive %lu. Please check the devices of this drive!",
- /*13*/ "07000206021002"
- "GDT HA %u, Array Drive %u: Cache Drive %u failed",
- /*14*/ "0500020602"
- "GDT HA %u, Array Drive %u: FAIL state entered",
- /*15*/ "0500020602"
- "GDT HA %u, Array Drive %u: error",
- /*16*/ "07000206021002"
- "GDT HA %u, Array Drive %u: failed drive replaced by Cache Drive %u",
- /*17*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity build failed",
- /*18*/ "0500020602"
- "GDT HA %u, Array Drive %u: drive rebuild failed",
- /*19*/ "0500021002"
- "GDT HA %u, Test of Hot Fix %u failed",
- /*20*/ "0500020602"
- "GDT HA %u, Array Drive %u: drive build finished successfully",
- /*21*/ "0500020602"
- "GDT HA %u, Array Drive %u: drive rebuild finished successfully",
- /*22*/ "07000206021002"
- "GDT HA %u, Array Drive %u: Hot Fix %u activated",
- /*23*/ "0500020602"
- "GDT HA %u, Host Drive %u: processing of i/o aborted due to serious drive error",
- /*24*/ "0500021002"
- "GDT HA %u, mirror update on Cache Drive %u completed",
- /*25*/ "0500021002"
- "GDT HA %u, mirror update on Cache Drive %lu failed",
- /*26*/ "0500020602"
- "GDT HA %u, Array Drive %u: drive rebuild started",
- /*27*/ "0500021201"
- "GDT HA %u, Fault bus %u: SHELF OK detected",
- /*28*/ "0500021201"
- "GDT HA %u, Fault bus %u: SHELF not OK detected",
- /*29*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug started",
- /*30*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: new disk detected",
- /*31*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: old disk detected",
- /*32*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: plugging an active disk is illegal",
- /*33*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: illegal device detected",
- /*34*/ "110002120113010604"
- "GDT HA %u, Fault bus %u, ID %u: insufficient disk capacity (%lu MB required)",
- /*35*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: disk write protected",
- /*36*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: disk not available",
- /*37*/ "07000212010604"
- "GDT HA %u, Fault bus %u: swap detected (%lu)",
- /*38*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug finished successfully",
- /*39*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted due to user Hot Plug",
- /*40*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug aborted",
- /*41*/ "07000212011301"
- "GDT HA %u, Fault bus %u, ID %u: Auto Hot Plug for Hot Fix started",
- /*42*/ "0500020602"
- "GDT HA %u, Array Drive %u: drive build started",
- /*43*/ "030002"
- "GDT HA %u, DRAM parity error detected",
- /*44*/ "0500020602"
- "GDT HA %u, Mirror Drive %u: update started",
- /*45*/ "07000206021002"
- "GDT HA %u, Mirror Drive %u: Hot Fix %u activated",
- /*46*/ "0500020602"
- "GDT HA %u, Array Drive %u: no matching Pool Hot Fix Drive available",
- /*47*/ "0500020602"
- "GDT HA %u, Array Drive %u: Pool Hot Fix Drive available",
- /*48*/ "0500020602"
- "GDT HA %u, Mirror Drive %u: no matching Pool Hot Fix Drive available",
- /*49*/ "0500020602"
- "GDT HA %u, Mirror Drive %u: Pool Hot Fix Drive available",
- /*50*/ "07000212011301"
- "GDT HA %u, SCSI bus %u, ID %u: IGNORE_WIDE_RESIDUE message received",
- /*51*/ "0500020602"
- "GDT HA %u, Array Drive %u: expand started",
- /*52*/ "0500020602"
- "GDT HA %u, Array Drive %u: expand finished successfully",
- /*53*/ "0500020602"
- "GDT HA %u, Array Drive %u: expand failed",
- /*54*/ "030002"
- "GDT HA %u, CPU temperature critical",
- /*55*/ "030002"
- "GDT HA %u, CPU temperature OK",
- /*56*/ "0500020604"
- "GDT HA %u, Host drive %lu created",
- /*57*/ "0500020602"
- "GDT HA %u, Array Drive %u: expand restarted",
- /*58*/ "0500020602"
- "GDT HA %u, Array Drive %u: expand stopped",
- /*59*/ "0500021002"
- "GDT HA %u, Mirror Drive %u: drive build quited",
- /*60*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity build quited",
- /*61*/ "0500020602"
- "GDT HA %u, Array Drive %u: drive rebuild quited",
- /*62*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity verify started",
- /*63*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity verify done",
- /*64*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity verify failed",
- /*65*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity error detected",
- /*66*/ "0500020602"
- "GDT HA %u, Array Drive %u: parity verify quited",
- /*67*/ "0500020602"
- "GDT HA %u, Host Drive %u reserved",
- /*68*/ "0500020602"
- "GDT HA %u, Host Drive %u mounted and released",
- /*69*/ "0500020602"
- "GDT HA %u, Host Drive %u released",
- /*70*/ "030002"
- "GDT HA %u, DRAM error detected and corrected with ECC",
- /*71*/ "030002"
- "GDT HA %u, Uncorrectable DRAM error detected with ECC",
- /*72*/ "110002120113011401"
- "GDT HA %u, SCSI bus %u, ID %u, LUN %u: reassigning block",
- /*73*/ "0500020602"
- "GDT HA %u, Host drive %u resetted locally",
- /*74*/ "0500020602"
- "GDT HA %u, Host drive %u resetted remotely",
- /*75*/ "030002"
- "GDT HA %u, async. status 75 unknown",
- };
- static int gdth_async_event(int hanum)
- {
- gdth_ha_str *ha;
- gdth_msg_str *msg;
- gdth_cmd_str *cmdp;
- int cmd_index;
- ha = HADATA(gdth_ctr_tab[hanum]);
- cmdp= ha->pccb;
- msg = (gdth_msg_str *)ha->pscratch;
- TRACE2(("gdth_async_event() ha %d serv %dn",
- hanum,ha->service));
- if (ha->service == SCREENSERVICE) {
- if (ha->status == MSG_REQUEST) {
- while (gdth_test_busy(hanum))
- gdth_delay(0);
- cmdp->Service = SCREENSERVICE;
- cmdp->RequestBuffer = SCREEN_CMND;
- cmd_index = gdth_get_cmd_index(hanum);
- gdth_set_sema0(hanum);
- cmdp->OpCode = GDT_READ;
- cmdp->BoardNode = LOCALBOARD;
- cmdp->u.screen.reserved = 0;
- cmdp->u.screen.su.msg.msg_handle= MSG_INV_HANDLE;
- cmdp->u.screen.su.msg.msg_addr = virt_to_bus(msg);
- ha->scratch_busy = TRUE;
- ha->cmd_offs_dpmem = 0;
- ha->cmd_len = GDTOFFSOF(gdth_cmd_str,u.screen.su.msg.msg_addr)
- + sizeof(ulong32);
- ha->cmd_cnt = 0;
- gdth_copy_command(hanum);
- if (ha->type == GDT_EISA)
- printk("[EISA slot %d] ",(ushort)ha->brd_phys);
- else if (ha->type == GDT_ISA)
- printk("[DPMEM 0x%4X] ",(ushort)ha->brd_phys);
- else
- printk("[PCI %d/%d] ",(ushort)(ha->brd_phys>>8),
- (ushort)((ha->brd_phys>>3)&0x1f));
- gdth_release_event(hanum);
- }
- } else {
- if (ha->type == GDT_PCIMPR &&
- (ha->fw_vers & 0xff) >= 0x1a) {
- ha->dvr.size = 0;
- ha->dvr.eu.async.ionode = hanum;
- ha->dvr.eu.async.status = ha->status;
- /* severity and event_string already set! */
- } else {
- ha->dvr.size = sizeof(ha->dvr.eu.async);
- ha->dvr.eu.async.ionode = hanum;
- ha->dvr.eu.async.service = ha->service;
- ha->dvr.eu.async.status = ha->status;
- ha->dvr.eu.async.info = ha->info;
- *(ulong32 *)ha->dvr.eu.async.scsi_coord = ha->info2;
- }
- gdth_store_event( ha, ES_ASYNC, ha->service, &ha->dvr );
- gdth_log_event( &ha->dvr, NULL );
-
- /* new host drive from expand? */
- if (ha->service == CACHESERVICE && ha->status == 56) {
- TRACE2(("gdth_async_event(): new host drive %d createdn",
- (ushort)ha->info));
- /* gdth_analyse_hdrive(hanum, (ushort)ha->info); */
- }
- }
- return 1;
- }
- static void gdth_log_event(gdth_evt_data *dvr, char *buffer)
- {
- gdth_stackframe stack;
- char *f = NULL;
- int i,j;
- TRACE2(("gdth_log_event()n"));
- if (dvr->size == 0) {
- if (buffer == NULL) {
- printk("Adapter %d: %sn",dvr->eu.async.ionode,dvr->event_string);
- } else {
- sprintf(buffer,"Adapter %d: %sn",
- dvr->eu.async.ionode,dvr->event_string);
- }
- } else if (dvr->eu.async.service == CACHESERVICE &&
- INDEX_OK(dvr->eu.async.status, async_cache_tab)) {
- TRACE2(("GDT: Async. event cache service, event no.: %dn",
- dvr->eu.async.status));
-
- f = async_cache_tab[dvr->eu.async.status];
-
- /* i: parameter to push, j: stack element to fill */
- for (j=0,i=1; i < f[0]; i+=2) {
- switch (f[i+1]) {
- case 4:
- stack.b[j++] = *(ulong32*)&dvr->eu.stream[(int)f[i]];
- break;
- case 2:
- stack.b[j++] = *(ushort*)&dvr->eu.stream[(int)f[i]];
- break;
- case 1:
- stack.b[j++] = *(unchar*)&dvr->eu.stream[(int)f[i]];
- break;
- default:
- break;
- }
- }
-
- if (buffer == NULL) {
- printk(&f[(int)f[0]],stack);
- printk("n");
- } else {
- sprintf(buffer,&f[(int)f[0]],stack);
- }
- } else {
- if (buffer == NULL) {
- printk("GDT HA %u, Unknown async. event service %d event no. %dn",
- dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
- } else {
- sprintf(buffer,"GDT HA %u, Unknown async. event service %d event no. %d",
- dvr->eu.async.ionode,dvr->eu.async.service,dvr->eu.async.status);
- }
- }
- }
- #ifdef GDTH_STATISTICS
- void gdth_timeout(ulong data)
- {
- ulong32 i;
- Scsi_Cmnd *nscp;
- gdth_ha_str *ha;
- ulong flags;
- int hanum = 0;
- ha = HADATA(gdth_ctr_tab[hanum]);
- GDTH_LOCK_HA(ha, flags);
- for (act_stats=0,i=0; i<GDTH_MAXCMDS; ++i)
- if (ha->cmd_tab[i].cmnd != UNUSED_CMND)
- ++act_stats;
- for (act_rq=0,nscp=ha->req_first; nscp; nscp=(Scsi_Cmnd*)nscp->SCp.ptr)
- ++act_rq;
- TRACE2(("gdth_to(): ints %d, ios %d, act_stats %d, act_rq %dn",
- act_ints, act_ios, act_stats, act_rq));
- act_ints = act_ios = 0;
- gdth_timer.expires = jiffies + 30 * HZ;
- add_timer(&gdth_timer);
- GDTH_UNLOCK_HA(ha, flags);
- }
- #endif
- GDTH_INITFUNC(void, internal_setup(char *str,int *ints))
- {
- int i, argc;
- char *cur_str, *argv;
- TRACE2(("internal_setup() str %s ints[0] %dn",
- str ? str:"NULL", ints ? ints[0]:0));
- /* read irq[] from ints[] */
- if (ints) {
- argc = ints[0];
- if (argc > 0) {
- if (argc > MAXHA)
- argc = MAXHA;
- for (i = 0; i < argc; ++i)
- irq[i] = ints[i+1];
- }
- }
- /* analyse string */
- argv = str;
- while (argv && (cur_str = strchr(argv, ':'))) {
- int val = 0, c = *++cur_str;
-
- if (c == 'n' || c == 'N')
- val = 0;
- else if (c == 'y' || c == 'Y')
- val = 1;
- else
- val = (int)simple_strtoul(cur_str, NULL, 0);
- if (!strncmp(argv, "disable:", 8))
- disable = val;
- else if (!strncmp(argv, "reserve_mode:", 13))
- reserve_mode = val;
- else if (!strncmp(argv, "reverse_scan:", 13))
- reverse_scan = val;
- else if (!strncmp(argv, "hdr_channel:", 12))
- hdr_channel = val;
- else if (!strncmp(argv, "max_ids:", 8))
- max_ids = val;
- else if (!strncmp(argv, "rescan:", 7))
- rescan = val;
- else if (!strncmp(argv, "virt_ctr:", 9))
- virt_ctr = val;
- else if (!strncmp(argv, "shared_access:", 14))
- shared_access = val;
- else if (!strncmp(argv, "reserve_list:", 13)) {
- reserve_list[0] = val;
- for (i = 1; i < MAX_RES_ARGS; i++) {
- cur_str = strchr(cur_str, ',');
- if (!cur_str)
- break;
- if (!isdigit((int)*++cur_str)) {
- --cur_str;
- break;
- }
- reserve_list[i] =
- (int)simple_strtoul(cur_str, NULL, 0);
- }
- if (!cur_str)
- break;
- argv = ++cur_str;
- continue;
- }
- if ((argv = strchr(argv, ',')))
- ++argv;
- }
- }
- GDTH_INITFUNC(int, option_setup(char *str))
- {
- int ints[MAXHA];
- char *cur = str;
- int i = 1;
- TRACE2(("option_setup() str %sn", str ? str:"NULL"));
- while (cur && isdigit(*cur) && i <= MAXHA) {
- ints[i++] = simple_strtoul(cur, NULL, 0);
- if ((cur = strchr(cur, ',')) != NULL) cur++;
- }
- ints[0] = i - 1;
- internal_setup(cur, ints);
- return 1;
- }
- GDTH_INITFUNC(int, gdth_detect(Scsi_Host_Template *shtp))
- {
- struct Scsi_Host *shp;
- gdth_ha_str *ha;
- ulong32 isa_bios;
- ushort eisa_slot;
- int i,hanum,cnt,ctr;
- unchar b;
-
-
- #ifdef DEBUG_GDTH
- printk("GDT: This driver contains debugging information !! Trace level = %dn",
- DebugState);
- printk(" Destination of debugging information: ");
- #ifdef __SERIAL__
- #ifdef __COM2__
- printk("Serial port COM2n");
- #else
- printk("Serial port COM1n");
- #endif
- #else
- printk("Consolen");
- #endif
- gdth_delay(3000);
- #endif
- TRACE(("gdth_detect()n"));
- if (disable) {
- printk("GDT: Controller driver disabled from command line !n");
- return 0;
- }
- /* initializations */
- gdth_polling = TRUE; b = 0;
- gdth_clear_events();
- /* scanning for controllers, at first: ISA controller */
- for (isa_bios=0xc8000UL; isa_bios<=0xd8000UL; isa_bios+=0x8000UL) {
- if (gdth_ctr_count >= MAXHA)
- break;
- if (gdth_search_isa(isa_bios)) { /* controller found */
- shp = scsi_register(shtp,sizeof(gdth_ext_str));
- ha = HADATA(shp);
- if (!gdth_init_isa(isa_bios,ha)) {
- scsi_unregister(shp);
- continue;
- }
- #ifdef __ia64__
- break;
- #else
- /* controller found and initialized */
- printk("Configuring GDT-ISA HA at BIOS 0x%05X IRQ %u DRQ %un",
- isa_bios,ha->irq,ha->drq);
- #if LINUX_VERSION_CODE >= 0x010346
- if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha))
- #else
- if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth"))
- #endif
- {
- printk("GDT-ISA: Unable to allocate IRQn");
- scsi_unregister(shp);
- continue;
- }
- if (request_dma(ha->drq,"gdth")) {
- printk("GDT-ISA: Unable to allocate DMA channeln");
- #if LINUX_VERSION_CODE >= 0x010346
- free_irq(ha->irq,ha);
- #else
- free_irq(ha->irq);
- #endif
- scsi_unregister(shp);
- continue;
- }
- set_dma_mode(ha->drq,DMA_MODE_CASCADE);
- enable_dma(ha->drq);
- shp->unchecked_isa_dma = 1;
- shp->irq = ha->irq;
- shp->dma_channel = ha->drq;
- hanum = gdth_ctr_count;
- gdth_ctr_tab[gdth_ctr_count++] = shp;
- gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
- NUMDATA(shp)->hanum = (ushort)hanum;
- NUMDATA(shp)->busnum= 0;
- ha->pccb = CMDDATA(shp);
- #if LINUX_VERSION_CODE >= 0x020322
- ha->pscratch = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA,
- GDTH_SCRATCH_ORD);
- #else
- ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
- #endif
- ha->scratch_busy = FALSE;
- ha->req_first = NULL;
- ha->tid_cnt = MAX_HDRIVES;
- if (max_ids > 0 && max_ids < ha->tid_cnt)
- ha->tid_cnt = max_ids;
- for (i=0; i<GDTH_MAXCMDS; ++i)
- ha->cmd_tab[i].cmnd = UNUSED_CMND;
- ha->scan_mode = rescan ? 0x10 : 0;
- if (ha->pscratch == NULL || !gdth_search_drives(hanum)) {
- printk("GDT-ISA: Error during device scann");
- --gdth_ctr_count;
- --gdth_ctr_vcount;
- if (ha->pscratch != NULL)
- #if LINUX_VERSION_CODE >= 0x020322
- free_pages((unsigned long)ha->pscratch, GDTH_SCRATCH_ORD);
- #else
- scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
- #endif
- #if LINUX_VERSION_CODE >= 0x010346
- free_irq(ha->irq,ha);
- #else
- free_irq(ha->irq);
- #endif
- scsi_unregister(shp);
- continue;
- }
- if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
- hdr_channel = ha->bus_cnt;
- ha->virt_bus = hdr_channel;
- #if LINUX_VERSION_CODE >= 0x020000
- shp->max_id = ha->tid_cnt;
- shp->max_lun = MAXLUN;
- shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
- if (virt_ctr)
- #endif
- {
- virt_ctr = 1;
- /* register addit. SCSI channels as virtual controllers */
- for (b = 1; b < ha->bus_cnt + 1; ++b) {
- shp = scsi_register(shtp,sizeof(gdth_num_str));
- shp->unchecked_isa_dma = 1;
- shp->irq = ha->irq;
- shp->dma_channel = ha->drq;
- gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
- NUMDATA(shp)->hanum = (ushort)hanum;
- NUMDATA(shp)->busnum = b;
- }
- }
- GDTH_INIT_LOCK_HA(ha);
- gdth_enable_int(hanum);
- #endif /* !__ia64__ */
- }
- }
- /* scanning for EISA controllers */
- for (eisa_slot=0x1000; eisa_slot<=0x8000; eisa_slot+=0x1000) {
- if (gdth_ctr_count >= MAXHA)
- break;
- if (gdth_search_eisa(eisa_slot)) { /* controller found */
- shp = scsi_register(shtp,sizeof(gdth_ext_str));
- ha = HADATA(shp);
- if (!gdth_init_eisa(eisa_slot,ha)) {
- scsi_unregister(shp);
- continue;
- }
- /* controller found and initialized */
- printk("Configuring GDT-EISA HA at Slot %d IRQ %un",
- eisa_slot>>12,ha->irq);
- #if LINUX_VERSION_CODE >= 0x010346
- if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth",ha))
- #else
- if (request_irq(ha->irq,gdth_interrupt,SA_INTERRUPT,"gdth"))
- #endif
- {
- printk("GDT-EISA: Unable to allocate IRQn");
- scsi_unregister(shp);
- continue;
- }
- shp->unchecked_isa_dma = 0;
- shp->irq = ha->irq;
- shp->dma_channel = 0xff;
- hanum = gdth_ctr_count;
- gdth_ctr_tab[gdth_ctr_count++] = shp;
- gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
- NUMDATA(shp)->hanum = (ushort)hanum;
- NUMDATA(shp)->busnum= 0;
- TRACE2(("EISA detect Bus 0: hanum %dn",
- NUMDATA(shp)->hanum));
- ha->pccb = CMDDATA(shp);
- #if LINUX_VERSION_CODE >= 0x020322
- ha->pscratch = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA,
- GDTH_SCRATCH_ORD);
- #else
- ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
- #endif
- ha->scratch_busy = FALSE;
- ha->req_first = NULL;
- ha->tid_cnt = MAX_HDRIVES;
- if (max_ids > 0 && max_ids < ha->tid_cnt)
- ha->tid_cnt = max_ids;
- for (i=0; i<GDTH_MAXCMDS; ++i)
- ha->cmd_tab[i].cmnd = UNUSED_CMND;
- ha->scan_mode = rescan ? 0x10 : 0;
- if (ha->pscratch == NULL || !gdth_search_drives(hanum)) {
- printk("GDT-EISA: Error during device scann");
- --gdth_ctr_count;
- --gdth_ctr_vcount;
- if (ha->pscratch != NULL)
- #if LINUX_VERSION_CODE >= 0x020322
- free_pages((unsigned long)ha->pscratch, GDTH_SCRATCH_ORD);
- #else
- scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
- #endif
- #if LINUX_VERSION_CODE >= 0x010346
- free_irq(ha->irq,ha);
- #else
- free_irq(ha->irq);
- #endif
- scsi_unregister(shp);
- continue;
- }
- if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
- hdr_channel = ha->bus_cnt;
- ha->virt_bus = hdr_channel;
- #if LINUX_VERSION_CODE >= 0x020000
- shp->max_id = ha->tid_cnt;
- shp->max_lun = MAXLUN;
- shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
- if (virt_ctr)
- #endif
- {
- virt_ctr = 1;
- /* register addit. SCSI channels as virtual controllers */
- for (b = 1; b < ha->bus_cnt + 1; ++b) {
- shp = scsi_register(shtp,sizeof(gdth_num_str));
- shp->unchecked_isa_dma = 0;
- shp->irq = ha->irq;
- shp->dma_channel = 0xff;
- gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
- NUMDATA(shp)->hanum = (ushort)hanum;
- NUMDATA(shp)->busnum = b;
- }
- }
- GDTH_INIT_LOCK_HA(ha);
- gdth_enable_int(hanum);
- }
- }
- /* scanning for PCI controllers */
- #if LINUX_VERSION_CODE >= 0x2015C
- if (pci_present())
- #else
- if (pcibios_present())
- #endif
- {
- gdth_pci_str pcistr[MAXHA];
- cnt = gdth_search_pci(pcistr);
- gdth_sort_pci(pcistr,cnt);
- for (ctr = 0; ctr < cnt; ++ctr) {
- if (gdth_ctr_count >= MAXHA)
- break;
- shp = scsi_register(shtp,sizeof(gdth_ext_str));
- ha = HADATA(shp);
- if (!gdth_init_pci(&pcistr[ctr],ha)) {
- scsi_unregister(shp);
- continue;
- }
- /* controller found and initialized */
- printk("Configuring GDT-PCI HA at %d/%d IRQ %un",
- pcistr[ctr].bus,PCI_SLOT(pcistr[ctr].device_fn),ha->irq);
- #if LINUX_VERSION_CODE >= 0x010346
- if (request_irq(ha->irq, gdth_interrupt,
- SA_INTERRUPT|SA_SHIRQ, "gdth", ha))
- #else
- if (request_irq(ha->irq, gdth_interrupt,
- SA_INTERRUPT|SA_SHIRQ, "gdth"))
- #endif
- {
- printk("GDT-PCI: Unable to allocate IRQn");
- scsi_unregister(shp);
- continue;
- }
- shp->unchecked_isa_dma = 0;
- shp->irq = ha->irq;
- shp->dma_channel = 0xff;
- hanum = gdth_ctr_count;
- gdth_ctr_tab[gdth_ctr_count++] = shp;
- gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
- NUMDATA(shp)->hanum = (ushort)hanum;
- NUMDATA(shp)->busnum= 0;
- ha->pccb = CMDDATA(shp);
- #if LINUX_VERSION_CODE >= 0x020322
- ha->pscratch = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA,
- GDTH_SCRATCH_ORD);
- #else
- ha->pscratch = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
- #endif
- ha->scratch_busy = FALSE;
- ha->req_first = NULL;
- ha->tid_cnt = pcistr[ctr].device_id >= 0x200 ? MAXID : MAX_HDRIVES;
- if (max_ids > 0 && max_ids < ha->tid_cnt)
- ha->tid_cnt = max_ids;
- for (i=0; i<GDTH_MAXCMDS; ++i)
- ha->cmd_tab[i].cmnd = UNUSED_CMND;
- ha->scan_mode = rescan ? 0x10 : 0;
- if (ha->pscratch == NULL || !gdth_search_drives(hanum)) {
- printk("GDT-PCI: Error during device scann");
- --gdth_ctr_count;
- --gdth_ctr_vcount;
- if (ha->pscratch != NULL)
- #if LINUX_VERSION_CODE >= 0x020322
- free_pages((unsigned long)ha->pscratch, GDTH_SCRATCH_ORD);
- #else
- scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
- #endif
- #if LINUX_VERSION_CODE >= 0x010346
- free_irq(ha->irq,ha);
- #else
- free_irq(ha->irq);
- #endif
- scsi_unregister(shp);
- continue;
- }
- if (hdr_channel < 0 || hdr_channel > ha->bus_cnt)
- hdr_channel = ha->bus_cnt;
- ha->virt_bus = hdr_channel;
- #if LINUX_VERSION_CODE >= 0x020000
- shp->max_id = ha->tid_cnt;
- shp->max_lun = MAXLUN;
- shp->max_channel = virt_ctr ? 0 : ha->bus_cnt;
- if (virt_ctr)
- #endif
- {
- virt_ctr = 1;
- /* register addit. SCSI channels as virtual controllers */
- for (b = 1; b < ha->bus_cnt + 1; ++b) {
- shp = scsi_register(shtp,sizeof(gdth_num_str));
- shp->unchecked_isa_dma = 0;
- shp->irq = ha->irq;
- shp->dma_channel = 0xff;
- gdth_ctr_vtab[gdth_ctr_vcount++] = shp;
- NUMDATA(shp)->hanum = (ushort)hanum;
- NUMDATA(shp)->busnum = b;
- }
- }
- GDTH_INIT_LOCK_HA(ha);
- gdth_enable_int(hanum);
- }
- }
- TRACE2(("gdth_detect() %d controller detectedn",gdth_ctr_count));
- if (gdth_ctr_count > 0) {
- #ifdef GDTH_STATISTICS
- TRACE2(("gdth_detect(): Initializing timer !n"));
- init_timer(&gdth_timer);
- gdth_timer.expires = jiffies + HZ;
- gdth_timer.data = 0L;
- gdth_timer.function = gdth_timeout;
- add_timer(&gdth_timer);
- #endif
- #if LINUX_VERSION_CODE >= 0x020100
- register_reboot_notifier(&gdth_notifier);
- #endif
- }
- gdth_polling = FALSE;
- return gdth_ctr_vcount;
- }
- int gdth_release(struct Scsi_Host *shp)
- {
- int hanum;
- gdth_ha_str *ha;
- TRACE2(("gdth_release()n"));
- if (NUMDATA(shp)->busnum == 0) {
- hanum = NUMDATA(shp)->hanum;
- ha = HADATA(gdth_ctr_tab[hanum]);
- #if LINUX_VERSION_CODE >= 0x010300
- gdth_flush(hanum);
- #endif
- if (shp->irq) {
- #if LINUX_VERSION_CODE >= 0x010346
- free_irq(shp->irq,ha);
- #else
- free_irq(shp->irq);
- #endif
- }
- #ifndef __ia64__
- if (shp->dma_channel != 0xff) {
- free_dma(shp->dma_channel);
- }
- #endif
- #if LINUX_VERSION_CODE >= 0x020322
- free_pages((unsigned long)ha->pscratch, GDTH_SCRATCH_ORD);
- #else
- scsi_init_free((void *)ha->pscratch, GDTH_SCRATCH);
- #endif
- gdth_ctr_released++;
- TRACE2(("gdth_release(): HA %d of %dn",
- gdth_ctr_released, gdth_ctr_count));
- if (gdth_ctr_released == gdth_ctr_count) {
- #ifdef GDTH_STATISTICS
- del_timer(&gdth_timer);
- #endif
- #if LINUX_VERSION_CODE >= 0x020100
- unregister_reboot_notifier(&gdth_notifier);
- #endif
- }
- }
- scsi_unregister(shp);
- return 0;
- }
-
- static const char *gdth_ctr_name(int hanum)
- {
- gdth_ha_str *ha;
- TRACE2(("gdth_ctr_name()n"));
- ha = HADATA(gdth_ctr_tab[hanum]);
- if (ha->type == GDT_EISA) {
- switch (ha->stype) {
- case GDT3_ID:
- return("GDT3000/3020");
- case GDT3A_ID:
- return("GDT3000A/3020A/3050A");
- case GDT3B_ID:
- return("GDT3000B/3010A");
- }
- } else if (ha->type == GDT_ISA) {
- return("GDT2000/2020");
- } else if (ha->type == GDT_PCI) {
- switch (ha->stype) {
- case PCI_DEVICE_ID_VORTEX_GDT60x0:
- return("GDT6000/6020/6050");
- case PCI_DEVICE_ID_VORTEX_GDT6000B:
- return("GDT6000B/6010");
- }
- }
- /* new controllers (GDT_PCINEW, GDT_PCIMPR, ..) use board_info IOCTL! */
- return("");
- }
- const char *gdth_info(struct Scsi_Host *shp)
- {
- int hanum;
- gdth_ha_str *ha;
- TRACE2(("gdth_info()n"));
- hanum = NUMDATA(shp)->hanum;
- ha = HADATA(gdth_ctr_tab[hanum]);
- return ((const char *)ha->binfo.type_string);
- }
- /* old error handling */
- int gdth_abort(Scsi_Cmnd *scp)
- {
- TRACE2(("gdth_abort() reason %dn",scp->abort_reason));
- return SCSI_ABORT_SNOOZE;
- }
- #if LINUX_VERSION_CODE >= 0x010346
- int gdth_reset(Scsi_Cmnd *scp, unsigned int reset_flags)
- #else
- int gdth_reset(Scsi_Cmnd *scp)
- #endif
- {
- TRACE2(("gdth_reset()n"));
- return SCSI_RESET_PUNT;
- }
- #if LINUX_VERSION_CODE >= 0x02015F
- /* new error handling */
- int gdth_eh_abort(Scsi_Cmnd *scp)
- {
- TRACE2(("gdth_eh_abort()n"));
- return FAILED;
- }
- int gdth_eh_device_reset(Scsi_Cmnd *scp)
- {
- TRACE2(("gdth_eh_device_reset()n"));
- return FAILED;
- }
- int gdth_eh_bus_reset(Scsi_Cmnd *scp)
- {
- int i, hanum;
- gdth_ha_str *ha;
- ulong flags;
- Scsi_Cmnd *cmnd;
- unchar b;
- TRACE2(("gdth_eh_bus_reset()n"));
- hanum = NUMDATA(scp->host)->hanum;
- b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
- ha = HADATA(gdth_ctr_tab[hanum]);
- /* clear command tab */
- GDTH_LOCK_HA(ha, flags);
- for (i = 0; i < GDTH_MAXCMDS; ++i) {
- cmnd = ha->cmd_tab[i].cmnd;
- if (!SPECIAL_SCP(cmnd) && cmnd->channel == b)
- ha->cmd_tab[i].cmnd = UNUSED_CMND;
- }
- GDTH_UNLOCK_HA(ha, flags);
- if (b == ha->virt_bus) {
- /* host drives */
- for (i = 0; i < MAX_HDRIVES; ++i) {
- if (ha->hdr[i].present) {
- GDTH_LOCK_HA(ha, flags);
- gdth_polling = TRUE;
- while (gdth_test_busy(hanum))
- gdth_delay(0);
- if (gdth_internal_cmd(hanum, CACHESERVICE,
- GDT_CLUST_RESET, i, 0, 0))
- ha->hdr[i].cluster_type &= ~CLUSTER_RESERVED;
- gdth_polling = FALSE;
- GDTH_UNLOCK_HA(ha, flags);
- }
- }
- } else {
- /* raw devices */
- GDTH_LOCK_HA(ha, flags);
- for (i = 0; i < MAXID; ++i)
- ha->raw[BUS_L2P(ha,b)].io_cnt[i] = 0;
- gdth_polling = TRUE;
- while (gdth_test_busy(hanum))
- gdth_delay(0);
- gdth_internal_cmd(hanum, SCSIRAWSERVICE, GDT_RESET_BUS,
- BUS_L2P(ha,b), 0, 0);
- gdth_polling = FALSE;
- GDTH_UNLOCK_HA(ha, flags);
- }
- return SUCCESS;
- }
- int gdth_eh_host_reset(Scsi_Cmnd *scp)
- {
- TRACE2(("gdth_eh_host_reset()n"));
- return FAILED;
- }
- #endif
- #if LINUX_VERSION_CODE >= 0x010300
- int gdth_bios_param(Disk *disk,kdev_t dev,int *ip)
- #else
- int gdth_bios_param(Disk *disk,int dev,int *ip)
- #endif
- {
- unchar b, t;
- int hanum;
- gdth_ha_str *ha;
- hanum = NUMDATA(disk->device->host)->hanum;
- b = virt_ctr ? NUMDATA(disk->device->host)->busnum : disk->device->channel;
- t = disk->device->id;
- TRACE2(("gdth_bios_param() ha %d bus %d target %dn", hanum, b, t));
- ha = HADATA(gdth_ctr_tab[hanum]);
- if (b != ha->virt_bus || ha->hdr[t].heads == 0) {
- /* raw device or host drive without mapping information */
- TRACE2(("Evaluate mappingn"));
- gdth_eval_mapping(disk->capacity,&ip[2],&ip[0],&ip[1]);
- } else {
- ip[0] = ha->hdr[t].heads;
- ip[1] = ha->hdr[t].secs;
- ip[2] = disk->capacity / ip[0] / ip[1];
- }
- TRACE2(("gdth_bios_param(): %d heads, %d secs, %d cylsn",
- ip[0],ip[1],ip[2]));
- return 0;
- }
- int gdth_queuecommand(Scsi_Cmnd *scp,void (*done)(Scsi_Cmnd *))
- {
- int hanum;
- int priority;
- TRACE(("gdth_queuecommand() cmd 0x%x id %d lun %dn",
- scp->cmnd[0],scp->target,scp->lun));
-
- scp->scsi_done = (void *)done;
- scp->SCp.have_data_in = 1;
- scp->SCp.phase = -1;
- scp->SCp.sent_command = -1;
- hanum = NUMDATA(scp->host)->hanum;
- #ifdef GDTH_STATISTICS
- ++act_ios;
- #endif
- priority = DEFAULT_PRI;
- #if LINUX_VERSION_CODE >= 0x010300
- if (scp->done == gdth_scsi_done)
- priority = scp->SCp.this_residual;
- #endif
- gdth_update_timeout(hanum, scp, scp->timeout_per_command * 6);
- gdth_putq( hanum, scp, priority );
- gdth_next( hanum );
- return 0;
- }
- #if LINUX_VERSION_CODE >= 0x010300
- /* flush routine */
- static void gdth_flush(int hanum)
- {
- int i;
- gdth_ha_str *ha;
- gdth_cmd_str gdtcmd;
- #if LINUX_VERSION_CODE >= 0x020322
- Scsi_Cmnd *scp;
- Scsi_Device *sdev;
- #else
- Scsi_Cmnd scp;
- Scsi_Device sdev;
- #endif
- char cmnd[MAX_COMMAND_SIZE];
- memset(cmnd, 0xff, MAX_COMMAND_SIZE);
- TRACE2(("gdth_flush() hanum %dn",hanum));
- ha = HADATA(gdth_ctr_tab[hanum]);
- #if LINUX_VERSION_CODE >= 0x020322
- sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
- scp = scsi_allocate_device(sdev, 1, FALSE);
- scp->cmd_len = 12;
- scp->use_sg = 0;
- #else
- memset(&sdev,0,sizeof(Scsi_Device));
- memset(&scp, 0,sizeof(Scsi_Cmnd));
- sdev.host = scp.host = gdth_ctr_tab[hanum];
- sdev.id = scp.target = sdev.host->this_id;
- scp.device = &sdev;
- #endif
- for (i = 0; i < MAX_HDRIVES; ++i) {
- if (ha->hdr[i].present) {
- gdtcmd.BoardNode = LOCALBOARD;
- gdtcmd.Service = CACHESERVICE;
- gdtcmd.OpCode = GDT_FLUSH;
- gdtcmd.u.cache.DeviceNo = i;
- gdtcmd.u.cache.BlockNo = 1;
- gdtcmd.u.cache.sg_canz = 0;
- TRACE2(("gdth_flush(): flush ha %d drive %dn", hanum, i));
- #if LINUX_VERSION_CODE >= 0x020322
- gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
- #else
- gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
- #endif
- }
- }
- #if LINUX_VERSION_CODE >= 0x020322
- scsi_release_command(scp);
- scsi_free_host_dev(sdev);
- #endif
- }
- /* shutdown routine */
- #if LINUX_VERSION_CODE >= 0x020100
- static int gdth_halt(struct notifier_block *nb, ulong event, void *buf)
- #else
- void gdth_halt(void)
- #endif
- {
- int hanum;
- #ifndef __alpha__
- gdth_cmd_str gdtcmd;
- #if LINUX_VERSION_CODE >= 0x020322
- Scsi_Cmnd *scp;
- Scsi_Device *sdev;
- #else
- Scsi_Cmnd scp;
- Scsi_Device sdev;
- #endif
- char cmnd[MAX_COMMAND_SIZE];
- #endif
- #if LINUX_VERSION_CODE >= 0x020100
- TRACE2(("gdth_halt() event %dn",(int)event));
- if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
- return NOTIFY_DONE;
- #else
- TRACE2(("gdth_halt()n"));
- if (halt_called) {
- TRACE2(("already calledn"));
- return;
- }
- halt_called = TRUE;
- #endif
- printk("GDT: Flushing all host drives .. ");
- for (hanum = 0; hanum < gdth_ctr_count; ++hanum) {
- gdth_flush(hanum);
- #ifndef __alpha__
- /* controller reset */
- memset(cmnd, 0xff, MAX_COMMAND_SIZE);
- #if LINUX_VERSION_CODE >= 0x020322
- sdev = scsi_get_host_dev(gdth_ctr_tab[hanum]);
- scp = scsi_allocate_device(sdev, 1, FALSE);
- scp->cmd_len = 12;
- scp->use_sg = 0;
- #else
- memset(&sdev,0,sizeof(Scsi_Device));
- memset(&scp, 0,sizeof(Scsi_Cmnd));
- sdev.host = scp.host = gdth_ctr_tab[hanum];
- sdev.id = scp.target = sdev.host->this_id;
- scp.device = &sdev;
- #endif
- gdtcmd.BoardNode = LOCALBOARD;
- gdtcmd.Service = CACHESERVICE;
- gdtcmd.OpCode = GDT_RESET;
- TRACE2(("gdth_halt(): reset controller %dn", hanum));
- #if LINUX_VERSION_CODE >= 0x020322
- gdth_do_cmd(scp, &gdtcmd, cmnd, 10);
- scsi_release_command(scp);
- scsi_free_host_dev(sdev);
- #else
- gdth_do_cmd(&scp, &gdtcmd, cmnd, 10);
- #endif
- #endif
- }
- printk("Done.n");
- #ifdef GDTH_STATISTICS
- del_timer(&gdth_timer);
- #endif
- #if LINUX_VERSION_CODE >= 0x020100
- #if LINUX_VERSION_CODE < 0x020322
- unregister_reboot_notifier(&gdth_notifier);
- #endif
- return NOTIFY_OK;
- #endif
- }
- #endif
- #if LINUX_VERSION_CODE < 0x020400 && !defined(MODULE)
- GDTH_INITFUNC(void, gdth_setup(char *str,int *ints))
- {
- TRACE2(("gdth_setup() str %s ints[0] %dn",
- str ? str:"NULL", ints ? ints[0]:0));
- internal_setup(str, ints);
- }
- #else
- static Scsi_Host_Template driver_template = GDTH;
- #include "scsi_module.c"
- #ifndef MODULE
- __setup("gdth=", option_setup);
- #endif
- #endif