| 1 |
/*====================================================================== |
| 2 |
|
| 3 |
NinjaSCSI-3 / NinjaSCSI-32Bi PCMCIA SCSI host adapter card driver |
| 4 |
By: YOKOTA Hiroshi <[email protected]> |
| 5 |
|
| 6 |
Ver.2.8 Support 32bit MMIO mode |
| 7 |
Support Synchronous Data TRansfer (SDTR) mode |
| 8 |
Ver.2.0 Support 32bit PIO mode |
| 9 |
Ver.1.1.2 Fix for scatter list buffer exceeds |
| 10 |
Ver.1.1 Support scatter list |
| 11 |
Ver.0.1 Initial version |
| 12 |
|
| 13 |
This software may be used and distributed according to the terms of |
| 14 |
the GNU General Public License. |
| 15 |
|
| 16 |
======================================================================*/ |
| 17 |
|
| 18 |
/*********************************************************************** |
| 19 |
This driver is for these PCcards. |
| 20 |
|
| 21 |
I-O DATA PCSC-F (Workbit NinjaSCSI-3) |
| 22 |
"WBT", "NinjaSCSI-3", "R1.0" |
| 23 |
I-O DATA CBSC-II (Workbit NinjaSCSI-32Bi in 16bit mode) |
| 24 |
"IO DATA", "CBSC16 ", "1" |
| 25 |
|
| 26 |
***********************************************************************/ |
| 27 |
|
| 28 |
/* */ |
| 29 |
|
| 30 |
#ifdef NSP_KERNEL_2_2 |
| 31 |
#include <pcmcia/config.h> |
| 32 |
#include <pcmcia/k_compat.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
#include <linux/module.h> |
| 36 |
#include <linux/kernel.h> |
| 37 |
#include <linux/init.h> |
| 38 |
#include <linux/sched.h> |
| 39 |
#include <linux/slab.h> |
| 40 |
#include <linux/string.h> |
| 41 |
#include <linux/timer.h> |
| 42 |
#include <linux/ioport.h> |
| 43 |
#include <linux/delay.h> |
| 44 |
#include <linux/interrupt.h> |
| 45 |
#include <linux/module.h> |
| 46 |
#include <linux/major.h> |
| 47 |
#include <linux/blk.h> |
| 48 |
#include <linux/stat.h> |
| 49 |
|
| 50 |
#include <asm/io.h> |
| 51 |
#include <asm/irq.h> |
| 52 |
|
| 53 |
#include "scsi.h" |
| 54 |
#include "hosts.h" |
| 55 |
|
| 56 |
#include <scsi/scsi.h> |
| 57 |
#include <scsi/scsi_ioctl.h> |
| 58 |
|
| 59 |
#include <pcmcia/version.h> |
| 60 |
#include <pcmcia/cs_types.h> |
| 61 |
#include <pcmcia/cs.h> |
| 62 |
#include <pcmcia/cistpl.h> |
| 63 |
#include <pcmcia/cisreg.h> |
| 64 |
#include <pcmcia/ds.h> |
| 65 |
|
| 66 |
#include "nsp_cs.h" |
| 67 |
|
| 68 |
MODULE_AUTHOR("YOKOTA Hiroshi <[email protected]>"); |
| 69 |
MODULE_DESCRIPTION("WorkBit NinjaSCSI-3 / NinjaSCSI-32Bi(16bit) PCMCIA SCSI host adapter module $Revision$"); |
| 70 |
MODULE_SUPPORTED_DEVICE("sd,sr,sg,st"); |
| 71 |
#ifdef MODULE_LICENSE |
| 72 |
MODULE_LICENSE("GPL"); |
| 73 |
#endif |
| 74 |
|
| 75 |
#ifdef PCMCIA_DEBUG |
| 76 |
static int pc_debug = PCMCIA_DEBUG; |
| 77 |
MODULE_PARM(pc_debug, "i"); |
| 78 |
MODULE_PARM_DESC(pc_debug, "set debug level"); |
| 79 |
static char *version = ""; |
| 80 |
#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) |
| 81 |
#else |
| 82 |
#define DEBUG(n, args...) /* */ |
| 83 |
#endif |
| 84 |
|
| 85 |
#include "nsp_io.h" |
| 86 |
|
| 87 |
/*====================================================================*/ |
| 88 |
|
| 89 |
typedef struct scsi_info_t { |
| 90 |
dev_link_t link; |
| 91 |
dev_node_t node; |
| 92 |
struct Scsi_Host *host; |
| 93 |
int stop; |
| 94 |
} scsi_info_t; |
| 95 |
|
| 96 |
|
| 97 |
/*----------------------------------------------------------------*/ |
| 98 |
|
| 99 |
#if (KERNEL_VERSION(2,4,0) > LINUX_VERSION_CODE) |
| 100 |
#define PROC_SCSI_NSP PROC_SCSI_IBMMCA /* bad hack... */ |
| 101 |
static struct proc_dir_entry proc_scsi_nsp = { |
| 102 |
PROC_SCSI_NSP, 6, "nsp_cs", |
| 103 |
S_IFDIR | S_IRUGO | S_IXUGO, 2 |
| 104 |
}; |
| 105 |
#endif |
| 106 |
|
| 107 |
/*====================================================================*/ |
| 108 |
/* Parameters that can be set with 'insmod' */ |
| 109 |
|
| 110 |
static unsigned int irq_mask = 0xffff; |
| 111 |
MODULE_PARM(irq_mask, "i"); |
| 112 |
MODULE_PARM_DESC(irq_mask, "IRQ mask bits (default: 0xffff)"); |
| 113 |
|
| 114 |
static int irq_list[4] = { -1 }; |
| 115 |
MODULE_PARM(irq_list, "1-4i"); |
| 116 |
MODULE_PARM_DESC(irq_list, "Use specified IRQ number. (default: auto select)"); |
| 117 |
|
| 118 |
static int nsp_burst_mode = 2; |
| 119 |
MODULE_PARM(nsp_burst_mode, "i"); |
| 120 |
MODULE_PARM_DESC(nsp_burst_mode, "Burst transfer mode (0=io8, 1=io32, 2=mem32(default))"); |
| 121 |
|
| 122 |
/* Release IO ports after configuration? */ |
| 123 |
static int free_ports = 0; |
| 124 |
MODULE_PARM(free_ports, "i"); |
| 125 |
MODULE_PARM_DESC(free_ports, "Release IO ports after configuration? (default: 0 (=no))"); |
| 126 |
|
| 127 |
/* /usr/src/linux/drivers/scsi/hosts.h */ |
| 128 |
static Scsi_Host_Template nsp_driver_template = { |
| 129 |
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)) |
| 130 |
.proc_name = "nsp_cs", /* kernel 2.4 */ |
| 131 |
#else |
| 132 |
.proc_dir = &proc_scsi_nsp, /* kernel 2.2 */ |
| 133 |
#endif |
| 134 |
.proc_info = nsp_proc_info, |
| 135 |
.name = "WorkBit NinjaSCSI-3/32Bi(16bit)", |
| 136 |
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) |
| 137 |
.detect = nsp_detect, |
| 138 |
.release = nsp_release, |
| 139 |
#endif |
| 140 |
.info = nsp_info, |
| 141 |
.queuecommand = nsp_queuecommand, |
| 142 |
/* .eh_strategy_handler = nsp_eh_strategy,*/ |
| 143 |
/* .eh_abort_handler = nsp_eh_abort,*/ |
| 144 |
/* .eh_device_reset_handler = nsp_eh_device_reset,*/ |
| 145 |
.eh_bus_reset_handler = nsp_eh_bus_reset, |
| 146 |
.eh_host_reset_handler = nsp_eh_host_reset, |
| 147 |
.can_queue = 1, |
| 148 |
.this_id = NSP_INITIATOR_ID, |
| 149 |
.sg_tablesize = SG_ALL, |
| 150 |
.cmd_per_lun = 1, |
| 151 |
.use_clustering = DISABLE_CLUSTERING, |
| 152 |
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,2)) |
| 153 |
.use_new_eh_code = 1, |
| 154 |
#endif |
| 155 |
}; |
| 156 |
|
| 157 |
static dev_link_t *dev_list = NULL; |
| 158 |
static dev_info_t dev_info = {"nsp_cs"}; |
| 159 |
|
| 160 |
static nsp_hw_data nsp_data; |
| 161 |
|
| 162 |
/***********************************************************/ |
| 163 |
|
| 164 |
static int nsp_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) |
| 165 |
{ |
| 166 |
#ifdef PCMCIA_DEBUG |
| 167 |
/*unsigned int host_id = SCpnt->host->this_id;*/ |
| 168 |
/*unsigned int base = SCpnt->host->io_port;*/ |
| 169 |
unsigned char target = SCpnt->target; |
| 170 |
#endif |
| 171 |
nsp_hw_data *data = &nsp_data; |
| 172 |
|
| 173 |
DEBUG(0, "%s: SCpnt=0x%p target=%d lun=%d buff=0x%p bufflen=%d use_sg=%d\n", |
| 174 |
__FUNCTION__, SCpnt, target, SCpnt->lun, SCpnt->request_buffer, SCpnt->request_bufflen, SCpnt->use_sg); |
| 175 |
//DEBUG(0, " before CurrentSC=0x%p\n", data->CurrentSC); |
| 176 |
|
| 177 |
if(data->CurrentSC != NULL) { |
| 178 |
printk(KERN_DEBUG " %s: CurrentSC!=NULL this can't be happen\n", __FUNCTION__); |
| 179 |
data->CurrentSC = NULL; |
| 180 |
SCpnt->result = DID_BAD_TARGET << 16; |
| 181 |
done(SCpnt); |
| 182 |
return -1; |
| 183 |
} |
| 184 |
|
| 185 |
show_command(SCpnt); |
| 186 |
|
| 187 |
SCpnt->scsi_done = done; |
| 188 |
data->CurrentSC = SCpnt; |
| 189 |
|
| 190 |
SCpnt->SCp.Status = CHECK_CONDITION; |
| 191 |
SCpnt->SCp.Message = 0; |
| 192 |
SCpnt->SCp.have_data_in = IO_UNKNOWN; |
| 193 |
SCpnt->SCp.sent_command = 0; |
| 194 |
SCpnt->SCp.phase = PH_UNDETERMINED; |
| 195 |
RESID = SCpnt->request_bufflen; |
| 196 |
|
| 197 |
/* setup scratch area |
| 198 |
SCp.ptr : buffer pointer |
| 199 |
SCp.this_residual : buffer length |
| 200 |
SCp.buffer : next buffer |
| 201 |
SCp.buffers_residual : left buffers in list |
| 202 |
SCp.phase : current state of the command */ |
| 203 |
if (SCpnt->use_sg) { |
| 204 |
SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer; |
| 205 |
SCpnt->SCp.ptr = BUFFER_ADDR; |
| 206 |
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; |
| 207 |
SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1; |
| 208 |
} else { |
| 209 |
SCpnt->SCp.ptr = (char *) SCpnt->request_buffer; |
| 210 |
SCpnt->SCp.this_residual = SCpnt->request_bufflen; |
| 211 |
SCpnt->SCp.buffer = NULL; |
| 212 |
SCpnt->SCp.buffers_residual = 0; |
| 213 |
} |
| 214 |
|
| 215 |
if(nsphw_start_selection(SCpnt, data) == FALSE) { |
| 216 |
DEBUG(0, " selection fail\n"); |
| 217 |
data->CurrentSC = NULL; |
| 218 |
SCpnt->result = DID_NO_CONNECT << 16; |
| 219 |
done(SCpnt); |
| 220 |
return -1; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
//DEBUG(0, "%s: out\n", __FUNCTION__); |
| 225 |
return 0; |
| 226 |
} |
| 227 |
|
| 228 |
/* |
| 229 |
* setup PIO FIFO transfer mode and enable/disable to data out |
| 230 |
*/ |
| 231 |
static void nsp_setup_fifo(nsp_hw_data *data, int enabled) |
| 232 |
{ |
| 233 |
unsigned int base = data->BaseAddress; |
| 234 |
unsigned char transfer_mode_reg; |
| 235 |
|
| 236 |
//DEBUG(0, "%s: enabled=%d\n", __FUNCTION__, enabled); |
| 237 |
|
| 238 |
if (enabled != FALSE) { |
| 239 |
transfer_mode_reg = TRANSFER_GO | BRAIND; |
| 240 |
} else { |
| 241 |
transfer_mode_reg = 0; |
| 242 |
} |
| 243 |
|
| 244 |
transfer_mode_reg |= data->TransferMode; |
| 245 |
|
| 246 |
nsp_index_write(base, TRANSFERMODE, transfer_mode_reg); |
| 247 |
} |
| 248 |
|
| 249 |
static void nsphw_init_sync(nsp_hw_data *data) |
| 250 |
{ |
| 251 |
sync_data tmp_sync = { .SyncNegotiation = SYNC_NOT_YET, |
| 252 |
.SyncPeriod = 0, |
| 253 |
.SyncOffset = 0 |
| 254 |
}; |
| 255 |
int i; |
| 256 |
|
| 257 |
/* setup sync data */ |
| 258 |
for ( i = 0; i < NUMBER(data->Sync); i++ ) { |
| 259 |
data->Sync[i] = tmp_sync; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
/* |
| 264 |
* Initialize Ninja hardware |
| 265 |
*/ |
| 266 |
static int nsphw_init(nsp_hw_data *data) |
| 267 |
{ |
| 268 |
unsigned int base = data->BaseAddress; |
| 269 |
|
| 270 |
DEBUG(0, "%s: in base=0x%x\n", __FUNCTION__, base); |
| 271 |
|
| 272 |
data->ScsiClockDiv = CLOCK_40M | FAST_20; |
| 273 |
data->CurrentSC = NULL; |
| 274 |
data->FifoCount = 0; |
| 275 |
data->TransferMode = MODE_IO8; |
| 276 |
|
| 277 |
nsphw_init_sync(data); |
| 278 |
|
| 279 |
/* block all interrupts */ |
| 280 |
nsp_write(base, IRQCONTROL, IRQCONTROL_ALLMASK); |
| 281 |
|
| 282 |
/* setup SCSI interface */ |
| 283 |
nsp_write(base, IFSELECT, IF_IFSEL); |
| 284 |
|
| 285 |
nsp_index_write(base, SCSIIRQMODE, 0); |
| 286 |
|
| 287 |
nsp_index_write(base, TRANSFERMODE, MODE_IO8); |
| 288 |
nsp_index_write(base, CLOCKDIV, data->ScsiClockDiv); |
| 289 |
|
| 290 |
nsp_index_write(base, PARITYCTRL, 0); |
| 291 |
nsp_index_write(base, POINTERCLR, POINTER_CLEAR | |
| 292 |
ACK_COUNTER_CLEAR | |
| 293 |
REQ_COUNTER_CLEAR | |
| 294 |
HOST_COUNTER_CLEAR); |
| 295 |
|
| 296 |
/* setup fifo asic */ |
| 297 |
nsp_write(base, IFSELECT, IF_REGSEL); |
| 298 |
nsp_index_write(base, TERMPWRCTRL, 0); |
| 299 |
if ((nsp_index_read(base, OTHERCONTROL) & TPWR_SENSE) == 0) { |
| 300 |
printk(KERN_INFO "nsp_cs: terminator power on\n"); |
| 301 |
nsp_index_write(base, TERMPWRCTRL, POWER_ON); |
| 302 |
} |
| 303 |
|
| 304 |
nsp_index_write(base, TIMERCOUNT, 0); |
| 305 |
nsp_index_write(base, TIMERCOUNT, 0); /* requires 2 times!! */ |
| 306 |
|
| 307 |
nsp_index_write(base, SYNCREG, 0); |
| 308 |
nsp_index_write(base, ACKWIDTH, 0); |
| 309 |
|
| 310 |
/* enable interrupts and ack them */ |
| 311 |
nsp_index_write(base, SCSIIRQMODE, SCSI_PHASE_CHANGE_EI | |
| 312 |
RESELECT_EI | |
| 313 |
SCSI_RESET_IRQ_EI ); |
| 314 |
nsp_write(base, IRQCONTROL, IRQCONTROL_ALLCLEAR); |
| 315 |
|
| 316 |
nsp_setup_fifo(data, FALSE); |
| 317 |
|
| 318 |
return TRUE; |
| 319 |
} |
| 320 |
|
| 321 |
/* |
| 322 |
* Start selection phase |
| 323 |
*/ |
| 324 |
static unsigned int nsphw_start_selection(Scsi_Cmnd *SCpnt, |
| 325 |
nsp_hw_data *data) |
| 326 |
{ |
| 327 |
unsigned int host_id = SCpnt->device->host->this_id; |
| 328 |
unsigned int base = SCpnt->device->host->io_port; |
| 329 |
unsigned char target = SCpnt->device->id; |
| 330 |
int time_out; |
| 331 |
unsigned char phase, arbit; |
| 332 |
|
| 333 |
//DEBUG(0, "%s:in\n", __FUNCTION__); |
| 334 |
|
| 335 |
phase = nsp_index_read(base, SCSIBUSMON); |
| 336 |
if(phase != BUSMON_BUS_FREE) { |
| 337 |
//DEBUG(0, " bus busy\n"); |
| 338 |
return FALSE; |
| 339 |
} |
| 340 |
|
| 341 |
/* start arbitration */ |
| 342 |
//DEBUG(0, " start arbit\n"); |
| 343 |
SCpnt->SCp.phase = PH_ARBSTART; |
| 344 |
nsp_index_write(base, SETARBIT, ARBIT_GO); |
| 345 |
|
| 346 |
time_out = 1000; |
| 347 |
do { |
| 348 |
/* XXX: what a stupid chip! */ |
| 349 |
arbit = nsp_index_read(base, ARBITSTATUS); |
| 350 |
//DEBUG(0, " arbit=%d, wait_count=%d\n", arbit, wait_count); |
| 351 |
udelay(1); /* hold 1.2us */ |
| 352 |
} while((arbit & (ARBIT_WIN | ARBIT_FAIL)) == 0 && |
| 353 |
(time_out-- != 0)); |
| 354 |
|
| 355 |
if((arbit & ARBIT_WIN) == 0) { |
| 356 |
//DEBUG(0, " arbit fail\n"); |
| 357 |
nsp_index_write(base, SETARBIT, ARBIT_FLAG_CLEAR); |
| 358 |
return FALSE; |
| 359 |
} |
| 360 |
|
| 361 |
/* assert select line */ |
| 362 |
//DEBUG(0, " assert SEL line\n"); |
| 363 |
SCpnt->SCp.phase = PH_SELSTART; |
| 364 |
udelay(3); |
| 365 |
nsp_index_write(base, SCSIDATALATCH, BIT(host_id) | BIT(target)); |
| 366 |
nsp_index_write(base, SCSIBUSCTRL, SCSI_SEL | SCSI_BSY | SCSI_ATN); |
| 367 |
udelay(3); |
| 368 |
nsp_index_write(base, SCSIBUSCTRL, SCSI_SEL | SCSI_BSY | SCSI_DATAOUT_ENB | SCSI_ATN); |
| 369 |
nsp_index_write(base, SETARBIT, ARBIT_FLAG_CLEAR); |
| 370 |
udelay(3); |
| 371 |
nsp_index_write(base, SCSIBUSCTRL, SCSI_SEL | SCSI_DATAOUT_ENB | SCSI_ATN); |
| 372 |
|
| 373 |
/* check selection timeout */ |
| 374 |
nsp_start_timer(SCpnt, data, 1000/51); |
| 375 |
data->SelectionTimeOut = 1; |
| 376 |
|
| 377 |
return TRUE; |
| 378 |
} |
| 379 |
|
| 380 |
struct nsp_sync_table { |
| 381 |
unsigned int min_period; |
| 382 |
unsigned int max_period; |
| 383 |
unsigned int chip_period; |
| 384 |
unsigned int ack_width; |
| 385 |
}; |
| 386 |
|
| 387 |
static struct nsp_sync_table nsp_sync_table_40M[] = { |
| 388 |
{0x0c,0x0c,0x1,0}, /* 20MB 50ns*/ |
| 389 |
{0x19,0x19,0x3,1}, /* 10MB 100ns*/ |
| 390 |
{0x1a,0x25,0x5,2}, /* 7.5MB 150ns*/ |
| 391 |
{0x26,0x32,0x7,3}, /* 5MB 200ns*/ |
| 392 |
{0x0, 0, 0, 0} |
| 393 |
}; |
| 394 |
|
| 395 |
static struct nsp_sync_table nsp_sync_table_20M[] = { |
| 396 |
{0x19,0x19,0x1,0}, /* 10MB 100ns*/ |
| 397 |
{0x1a,0x25,0x2,0}, /* 7.5MB 150ns*/ |
| 398 |
{0x26,0x32,0x3,1}, /* 5MB 200ns*/ |
| 399 |
{0x0, 0, 0, 0} |
| 400 |
}; |
| 401 |
|
| 402 |
/* |
| 403 |
* setup synchronous data transfer mode |
| 404 |
*/ |
| 405 |
static int nsp_msg(Scsi_Cmnd *SCpnt, nsp_hw_data *data) |
| 406 |
{ |
| 407 |
unsigned char target = SCpnt->device->id; |
| 408 |
// unsigned char lun = SCpnt->lun; |
| 409 |
sync_data *sync = &(data->Sync[target]); |
| 410 |
struct nsp_sync_table *sync_table; |
| 411 |
unsigned int period, offset; |
| 412 |
int i; |
| 413 |
|
| 414 |
|
| 415 |
DEBUG(0, "%s:\n", __FUNCTION__); |
| 416 |
|
| 417 |
period = sync->SyncPeriod; |
| 418 |
offset = sync->SyncOffset; |
| 419 |
|
| 420 |
DEBUG(0, " period=0x%x, offset=0x%x\n", period, offset); |
| 421 |
|
| 422 |
if ((data->ScsiClockDiv & (BIT(0)|BIT(1))) == CLOCK_20M) { |
| 423 |
sync_table = &nsp_sync_table_20M[0]; |
| 424 |
} else { |
| 425 |
sync_table = &nsp_sync_table_40M[0]; |
| 426 |
} |
| 427 |
|
| 428 |
for ( i = 0; sync_table->max_period != 0; i++, sync_table++) { |
| 429 |
if ( period >= sync_table->min_period && |
| 430 |
period <= sync_table->max_period ) { |
| 431 |
break; |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
if (period != 0 && sync_table->max_period == 0) { |
| 436 |
/* |
| 437 |
* No proper period/offset found |
| 438 |
*/ |
| 439 |
DEBUG(0, " no proper period/offset\n"); |
| 440 |
|
| 441 |
sync->SyncPeriod = 0; |
| 442 |
sync->SyncOffset = 0; |
| 443 |
sync->SyncRegister = 0; |
| 444 |
sync->AckWidth = 0; |
| 445 |
|
| 446 |
return FALSE; |
| 447 |
} |
| 448 |
|
| 449 |
sync->SyncRegister = (sync_table->chip_period << SYNCREG_PERIOD_SHIFT) | |
| 450 |
(offset & SYNCREG_OFFSET_MASK); |
| 451 |
sync->AckWidth = sync_table->ack_width; |
| 452 |
|
| 453 |
DEBUG(0, " sync_reg=0x%x, ack_width=0x%x\n", sync->SyncRegister, sync->AckWidth); |
| 454 |
|
| 455 |
return TRUE; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
/* |
| 460 |
* start ninja hardware timer |
| 461 |
*/ |
| 462 |
static void nsp_start_timer(Scsi_Cmnd *SCpnt, nsp_hw_data *data, int time) |
| 463 |
{ |
| 464 |
unsigned int base = SCpnt->device->host->io_port; |
| 465 |
|
| 466 |
//DEBUG(0, "%s: in SCpnt=0x%p, time=%d\n", __FUNCTION__, SCpnt, time); |
| 467 |
data->TimerCount = time; |
| 468 |
nsp_index_write(base, TIMERCOUNT, time); |
| 469 |
} |
| 470 |
|
| 471 |
/* |
| 472 |
* wait for bus phase change |
| 473 |
*/ |
| 474 |
static int nsp_negate_signal(Scsi_Cmnd *SCpnt, unsigned char mask, char *str) |
| 475 |
{ |
| 476 |
unsigned int base = SCpnt->device->host->io_port; |
| 477 |
unsigned char reg; |
| 478 |
int time_out; |
| 479 |
|
| 480 |
//DEBUG(0, "%s:\n", __FUNCTION__); |
| 481 |
|
| 482 |
time_out = 100; |
| 483 |
|
| 484 |
do { |
| 485 |
reg = nsp_index_read(base, SCSIBUSMON); |
| 486 |
if (reg == 0xff) { |
| 487 |
break; |
| 488 |
} |
| 489 |
} while ((time_out-- != 0) && (reg & mask) != 0); |
| 490 |
|
| 491 |
if (time_out == 0) { |
| 492 |
printk(KERN_DEBUG "%s:: %s signal off timeut\n", __FUNCTION__, str); |
| 493 |
} |
| 494 |
|
| 495 |
return 0; |
| 496 |
} |
| 497 |
|
| 498 |
/* |
| 499 |
* expect Ninja Irq |
| 500 |
*/ |
| 501 |
static int nsp_expect_signal(Scsi_Cmnd *SCpnt, |
| 502 |
unsigned char current_phase, |
| 503 |
unsigned char mask) |
| 504 |
{ |
| 505 |
unsigned int base = SCpnt->device->host->io_port; |
| 506 |
int time_out; |
| 507 |
unsigned char phase, i_src; |
| 508 |
|
| 509 |
//DEBUG(0, "%s: current_phase=0x%x, mask=0x%x\n", __FUNCTION__, current_phase, mask); |
| 510 |
|
| 511 |
time_out = 100; |
| 512 |
do { |
| 513 |
phase = nsp_index_read(base, SCSIBUSMON); |
| 514 |
if (phase == 0xff) { |
| 515 |
//DEBUG(0, " ret -1\n"); |
| 516 |
return -1; |
| 517 |
} |
| 518 |
i_src = nsp_read(base, IRQSTATUS); |
| 519 |
if (i_src & IRQSTATUS_SCSI) { |
| 520 |
//DEBUG(0, " ret 0 found scsi signal\n"); |
| 521 |
return 0; |
| 522 |
} |
| 523 |
if ((phase & mask) != 0 && (phase & BUSMON_PHASE_MASK) == current_phase) { |
| 524 |
//DEBUG(0, " ret 1 phase=0x%x\n", phase); |
| 525 |
return 1; |
| 526 |
} |
| 527 |
} while(time_out-- != 0); |
| 528 |
|
| 529 |
//DEBUG(0, "%s: timeout\n", __FUNCTION__); |
| 530 |
return -1; |
| 531 |
} |
| 532 |
|
| 533 |
/* |
| 534 |
* transfer SCSI message |
| 535 |
*/ |
| 536 |
static int nsp_xfer(Scsi_Cmnd *SCpnt, nsp_hw_data *data, int phase) |
| 537 |
{ |
| 538 |
unsigned int base = SCpnt->device->host->io_port; |
| 539 |
char *buf = data->MsgBuffer; |
| 540 |
int len = MIN(MSGBUF_SIZE, data->MsgLen); |
| 541 |
int ptr; |
| 542 |
int ret; |
| 543 |
|
| 544 |
//DEBUG(0, "%s:\n", __FUNCTION__); |
| 545 |
for (ptr = 0; len > 0; len --, ptr ++) { |
| 546 |
|
| 547 |
ret = nsp_expect_signal(SCpnt, phase, BUSMON_REQ); |
| 548 |
if (ret <= 0) { |
| 549 |
DEBUG(0, " xfer quit\n"); |
| 550 |
return 0; |
| 551 |
} |
| 552 |
|
| 553 |
/* if last byte, negate ATN */ |
| 554 |
if (len == 1 && SCpnt->SCp.phase == PH_MSG_OUT) { |
| 555 |
nsp_index_write(base, SCSIBUSCTRL, AUTODIRECTION | ACKENB); |
| 556 |
} |
| 557 |
|
| 558 |
/* read & write message */ |
| 559 |
if (phase & BUSMON_IO) { |
| 560 |
DEBUG(0, " read msg\n"); |
| 561 |
buf[ptr] = nsp_index_read(base, SCSIDATAWITHACK); |
| 562 |
} else { |
| 563 |
DEBUG(0, " write msg\n"); |
| 564 |
nsp_index_write(base, SCSIDATAWITHACK, buf[ptr]); |
| 565 |
} |
| 566 |
nsp_negate_signal(SCpnt, BUSMON_ACK, "xfer<ack>"); |
| 567 |
|
| 568 |
} |
| 569 |
return len; |
| 570 |
} |
| 571 |
|
| 572 |
/* |
| 573 |
* get extra SCSI data from fifo |
| 574 |
*/ |
| 575 |
static int nsp_dataphase_bypass(Scsi_Cmnd *SCpnt, nsp_hw_data *data) |
| 576 |
{ |
| 577 |
unsigned int count; |
| 578 |
|
| 579 |
//DEBUG(0, "%s:\n", __FUNCTION__); |
| 580 |
|
| 581 |
if (SCpnt->SCp.have_data_in != IO_IN) { |
| 582 |
return 0; |
| 583 |
} |
| 584 |
|
| 585 |
count = nsp_fifo_count(SCpnt); |
| 586 |
if (data->FifoCount == count) { |
| 587 |
//DEBUG(0, " not use bypass quirk\n"); |
| 588 |
return 0; |
| 589 |
} |
| 590 |
|
| 591 |
/* |
| 592 |
* XXX: NSP_QUIRK |
| 593 |
* data phase skip only occurs in case of SCSI_LOW_READ |
| 594 |
*/ |
| 595 |
DEBUG(0, " use bypass quirk\n"); |
| 596 |
SCpnt->SCp.phase = PH_DATA; |
| 597 |
nsp_pio_read(SCpnt, data); |
| 598 |
nsp_setup_fifo(data, FALSE); |
| 599 |
|
| 600 |
return 0; |
| 601 |
} |
| 602 |
|
| 603 |
/* |
| 604 |
* accept reselection |
| 605 |
*/ |
| 606 |
static int nsp_reselected(Scsi_Cmnd *SCpnt, nsp_hw_data *data) |
| 607 |
{ |
| 608 |
unsigned int base = SCpnt->device->host->io_port; |
| 609 |
unsigned char reg; |
| 610 |
|
| 611 |
//DEBUG(0, "%s:\n", __FUNCTION__); |
| 612 |
|
| 613 |
nsp_negate_signal(SCpnt, BUSMON_SEL, "reselect<SEL>"); |
| 614 |
|
| 615 |
nsp_nexus(SCpnt, data); |
| 616 |
reg = nsp_index_read(base, SCSIBUSCTRL) & ~(SCSI_BSY | SCSI_ATN); |
| 617 |
nsp_index_write(base, SCSIBUSCTRL, reg); |
| 618 |
nsp_index_write(base, SCSIBUSCTRL, reg | AUTODIRECTION | ACKENB); |
| 619 |
|
| 620 |
return TRUE; |
| 621 |
} |
| 622 |
|
| 623 |
/* |
| 624 |
* count how many data transferred |
| 625 |
*/ |
| 626 |
static int nsp_fifo_count(Scsi_Cmnd *SCpnt) |
| 627 |
{ |
| 628 |
unsigned int base = SCpnt->device->host->io_port; |
| 629 |
unsigned int count; |
| 630 |
unsigned int l, m, h, dummy; |
| 631 |
|
| 632 |
nsp_index_write(base, POINTERCLR, POINTER_CLEAR | ACK_COUNTER); |
| 633 |
|
| 634 |
l = nsp_index_read(base, TRANSFERCOUNT); |
| 635 |
m = nsp_index_read(base, TRANSFERCOUNT); |
| 636 |
h = nsp_index_read(base, TRANSFERCOUNT); |
| 637 |
dummy = nsp_index_read(base, TRANSFERCOUNT); |
| 638 |
|
| 639 |
count = (h << 16) | (m << 8) | (l << 0); |
| 640 |
|
| 641 |
//DEBUG(0, "%s: =0x%x\n", __FUNCTION__, count); |
| 642 |
|
| 643 |
return count; |
| 644 |
} |
| 645 |
|
| 646 |
/* fifo size */ |
| 647 |
#define RFIFO_CRIT 64 |
| 648 |
#define WFIFO_CRIT 64 |
| 649 |
|
| 650 |
/* |
| 651 |
* read data in DATA IN phase |
| 652 |
*/ |
| 653 |
static void nsp_pio_read(Scsi_Cmnd *SCpnt, nsp_hw_data *data) |
| 654 |
{ |
| 655 |
unsigned int base = SCpnt->device->host->io_port; |
| 656 |
unsigned long mmio_base = SCpnt->device->host->base; |
| 657 |
long time_out; |
| 658 |
int ocount, res; |
| 659 |
unsigned char stat, fifo_stat; |
| 660 |
|
| 661 |
ocount = data->FifoCount; |
| 662 |
|
| 663 |
DEBUG(0, "%s: in SCpnt=0x%p resid=%d ocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d\n", |
| 664 |
__FUNCTION__, SCpnt, RESID, ocount, SCpnt->SCp.ptr, SCpnt->SCp.this_residual, SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual); |
| 665 |
|
| 666 |
time_out = 1000; |
| 667 |
|
| 668 |
while ((time_out-- != 0) && |
| 669 |
(SCpnt->SCp.this_residual > 0 || SCpnt->SCp.buffers_residual > 0 ) ) { |
| 670 |
|
| 671 |
stat = nsp_index_read(base, SCSIBUSMON); |
| 672 |
stat &= BUSMON_PHASE_MASK; |
| 673 |
|
| 674 |
|
| 675 |
res = nsp_fifo_count(SCpnt) - ocount; |
| 676 |
//DEBUG(0, " ptr=0x%p this=0x%x ocount=0x%x res=0x%x\n", SCpnt->SCp.ptr, SCpnt->SCp.this_residual, ocount, res); |
| 677 |
if (res == 0) { /* if some data available ? */ |
| 678 |
if (stat == BUSPHASE_DATA_IN) { /* phase changed? */ |
| 679 |
//DEBUG(0, " wait for data this=%d\n", SCpnt->SCp.this_residual); |
| 680 |
continue; |
| 681 |
} else { |
| 682 |
DEBUG(0, " phase changed stat=0x%x\n", stat); |
| 683 |
break; |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
fifo_stat = nsp_read(base, FIFOSTATUS); |
| 688 |
if ((fifo_stat & FIFOSTATUS_FULL_EMPTY) == 0 && |
| 689 |
stat == BUSPHASE_DATA_IN) { |
| 690 |
continue; |
| 691 |
} |
| 692 |
|
| 693 |
res = MIN(res, SCpnt->SCp.this_residual); |
| 694 |
|
| 695 |
switch (data->TransferMode) { |
| 696 |
case MODE_IO32: |
| 697 |
res &= ~(BIT(1)|BIT(0)); /* align 4 */ |
| 698 |
nsp_fifo32_read(base, SCpnt->SCp.ptr, res >> 2); |
| 699 |
break; |
| 700 |
case MODE_IO8: |
| 701 |
nsp_fifo8_read (base, SCpnt->SCp.ptr, res ); |
| 702 |
break; |
| 703 |
|
| 704 |
case MODE_MEM32: |
| 705 |
res &= ~(BIT(1)|BIT(0)); /* align 4 */ |
| 706 |
nsp_mmio_fifo32_read(mmio_base, SCpnt->SCp.ptr, res >> 2); |
| 707 |
break; |
| 708 |
|
| 709 |
default: |
| 710 |
DEBUG(0, "unknown read mode\n"); |
| 711 |
return; |
| 712 |
} |
| 713 |
|
| 714 |
RESID -= res; |
| 715 |
SCpnt->SCp.ptr += res; |
| 716 |
SCpnt->SCp.this_residual -= res; |
| 717 |
ocount += res; |
| 718 |
//DEBUG(0, " ptr=0x%p this_residual=0x%x ocount=0x%x\n", SCpnt->SCp.ptr, SCpnt->SCp.this_residual, ocount); |
| 719 |
|
| 720 |
/* go to next scatter list if available */ |
| 721 |
if (SCpnt->SCp.this_residual == 0 && |
| 722 |
SCpnt->SCp.buffers_residual != 0 ) { |
| 723 |
//DEBUG(0, " scatterlist next timeout=%d\n", time_out); |
| 724 |
SCpnt->SCp.buffers_residual--; |
| 725 |
SCpnt->SCp.buffer++; |
| 726 |
SCpnt->SCp.ptr = BUFFER_ADDR; |
| 727 |
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; |
| 728 |
time_out = 1000; |
| 729 |
|
| 730 |
//DEBUG(0, "page: 0x%p, off: 0x%x\n", SCpnt->SCp.buffer->page, SCpnt->SCp.buffer->offset); |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
data->FifoCount = ocount; |
| 735 |
|
| 736 |
if (time_out == 0) { |
| 737 |
printk(KERN_DEBUG "%s: pio read timeout resid=%d this_residual=%d buffers_residual=%d\n", |
| 738 |
__FUNCTION__, RESID, SCpnt->SCp.this_residual, SCpnt->SCp.buffers_residual); |
| 739 |
} |
| 740 |
DEBUG(0, " read ocount=0x%x\n", ocount); |
| 741 |
} |
| 742 |
|
| 743 |
/* |
| 744 |
* write data in DATA OUT phase |
| 745 |
*/ |
| 746 |
static void nsp_pio_write(Scsi_Cmnd *SCpnt, nsp_hw_data *data) |
| 747 |
{ |
| 748 |
unsigned int base = SCpnt->device->host->io_port; |
| 749 |
unsigned long mmio_base = SCpnt->device->host->base; |
| 750 |
int time_out; |
| 751 |
int ocount, res; |
| 752 |
unsigned char stat; |
| 753 |
|
| 754 |
ocount = data->FifoCount; |
| 755 |
|
| 756 |
DEBUG(0, "%s: in fifocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d resid=0x%x\n", |
| 757 |
__FUNCTION__, data->FifoCount, SCpnt->SCp.ptr, SCpnt->SCp.this_residual, SCpnt->SCp.buffer, SCpnt->SCp.buffers_residual, RESID); |
| 758 |
|
| 759 |
time_out = 1000; |
| 760 |
|
| 761 |
while ((time_out-- != 0) && |
| 762 |
(SCpnt->SCp.this_residual > 0 || SCpnt->SCp.buffers_residual > 0)) { |
| 763 |
stat = nsp_index_read(base, SCSIBUSMON); |
| 764 |
stat &= BUSMON_PHASE_MASK; |
| 765 |
|
| 766 |
if (stat != BUSPHASE_DATA_OUT) { |
| 767 |
res = ocount - nsp_fifo_count(SCpnt); |
| 768 |
|
| 769 |
DEBUG(0, " phase changed stat=0x%x, res=%d\n", stat, res); |
| 770 |
/* Put back pointer */ |
| 771 |
RESID += res; |
| 772 |
SCpnt->SCp.ptr -= res; |
| 773 |
SCpnt->SCp.this_residual += res; |
| 774 |
ocount -= res; |
| 775 |
|
| 776 |
break; |
| 777 |
} |
| 778 |
|
| 779 |
res = ocount - nsp_fifo_count(SCpnt); |
| 780 |
if (res > 0) { /* write all data? */ |
| 781 |
DEBUG(0, " wait for all data out. ocount=0x%x res=%d\n", ocount, res); |
| 782 |
continue; |
| 783 |
} |
| 784 |
|
| 785 |
res = MIN(SCpnt->SCp.this_residual, WFIFO_CRIT); |
| 786 |
|
| 787 |
//DEBUG(0, " ptr=0x%p this=0x%x res=0x%x\n", SCpnt->SCp.ptr, SCpnt->SCp.this_residual, res); |
| 788 |
switch (data->TransferMode) { |
| 789 |
case MODE_IO32: |
| 790 |
res &= ~(BIT(1)|BIT(0)); /* align 4 */ |
| 791 |
nsp_fifo32_write(base, SCpnt->SCp.ptr, res >> 2); |
| 792 |
break; |
| 793 |
case MODE_IO8: |
| 794 |
nsp_fifo8_write (base, SCpnt->SCp.ptr, res ); |
| 795 |
break; |
| 796 |
|
| 797 |
case MODE_MEM32: |
| 798 |
res &= ~(BIT(1)|BIT(0)); /* align 4 */ |
| 799 |
nsp_mmio_fifo32_write(mmio_base, SCpnt->SCp.ptr, res >> 2); |
| 800 |
break; |
| 801 |
|
| 802 |
default: |
| 803 |
DEBUG(0, "unknown write mode\n"); |
| 804 |
break; |
| 805 |
} |
| 806 |
|
| 807 |
RESID -= res; |
| 808 |
SCpnt->SCp.ptr += res; |
| 809 |
SCpnt->SCp.this_residual -= res; |
| 810 |
ocount += res; |
| 811 |
|
| 812 |
/* go to next scatter list if available */ |
| 813 |
if (SCpnt->SCp.this_residual == 0 && |
| 814 |
SCpnt->SCp.buffers_residual != 0 ) { |
| 815 |
//DEBUG(0, " scatterlist next\n"); |
| 816 |
SCpnt->SCp.buffers_residual--; |
| 817 |
SCpnt->SCp.buffer++; |
| 818 |
SCpnt->SCp.ptr = BUFFER_ADDR; |
| 819 |
SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length; |
| 820 |
time_out = 1000; |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
data->FifoCount = ocount; |
| 825 |
|
| 826 |
if (time_out == 0) { |
| 827 |
printk(KERN_DEBUG "%s: pio write timeout resid=0x%x\n", __FUNCTION__, RESID); |
| 828 |
} |
| 829 |
DEBUG(0, " write ocount=0x%x\n", ocount); |
| 830 |
} |
| 831 |
|
| 832 |
#undef RFIFO_CRIT |
| 833 |
#undef WFIFO_CRIT |
| 834 |
|
| 835 |
/* |
| 836 |
* setup synchronous/asynchronous data transfer mode |
| 837 |
*/ |
| 838 |
static int nsp_nexus(Scsi_Cmnd *SCpnt, nsp_hw_data *data) |
| 839 |
{ |
| 840 |
unsigned int base = SCpnt->device->host->io_port; |
| 841 |
unsigned char target = SCpnt->device->id; |
| 842 |
// unsigned char lun = SCpnt->lun; |
| 843 |
sync_data *sync = &(data->Sync[target]); |
| 844 |
|
| 845 |
//DEBUG(0, "%s: in SCpnt=0x%p\n", __FUNCTION__, SCpnt); |
| 846 |
|
| 847 |
/* setup sync transfer registers */ |
| 848 |
nsp_index_write(base, SYNCREG, sync->SyncRegister); |
| 849 |
nsp_index_write(base, ACKWIDTH, sync->AckWidth); |
| 850 |
|
| 851 |
if (SCpnt->use_sg == 0 || |
| 852 |
RESID % 4 != 0 || |
| 853 |
RESID <= PAGE_SIZE ) { |
| 854 |
data->TransferMode = MODE_IO8; |
| 855 |
} else if (nsp_burst_mode == BURST_MEM32) { |
| 856 |
data->TransferMode = MODE_MEM32; |
| 857 |
} else if (nsp_burst_mode == BURST_IO32) { |
| 858 |
data->TransferMode = MODE_IO32; |
| 859 |
} else { |
| 860 |
data->TransferMode = MODE_IO8; |
| 861 |
} |
| 862 |
|
| 863 |
/* setup pdma fifo */ |
| 864 |
nsp_setup_fifo(data, TRUE); |
| 865 |
|
| 866 |
/* clear ack counter */ |
| 867 |
data->FifoCount = 0; |
| 868 |
nsp_index_write(base, POINTERCLR, POINTER_CLEAR | |
| 869 |
ACK_COUNTER_CLEAR | |
| 870 |
REQ_COUNTER_CLEAR | |
| 871 |
HOST_COUNTER_CLEAR); |
| 872 |
|
| 873 |
return 0; |
| 874 |
} |
| 875 |
|
| 876 |
#include "nsp_message.c" |
| 877 |
/* |
| 878 |
* interrupt handler |
| 879 |
*/ |
| 880 |
static void nspintr(int irq, void *dev_id, struct pt_regs *regs) |
| 881 |
{ |
| 882 |
unsigned int base; |
| 883 |
unsigned char i_src, irq_phase, phase; |
| 884 |
Scsi_Cmnd *tmpSC; |
| 885 |
unsigned char target, lun; |
| 886 |
unsigned int *sync_neg; |
| 887 |
int i, tmp; |
| 888 |
nsp_hw_data *data = dev_id; |
| 889 |
|
| 890 |
//printk("&nsp_data=0x%p, dev_id=0x%p\n", &nsp_data, dev_id); |
| 891 |
|
| 892 |
base = data->BaseAddress; |
| 893 |
//DEBUG(0, " base=0x%x\n", base); |
| 894 |
|
| 895 |
/* |
| 896 |
* interrupt check |
| 897 |
*/ |
| 898 |
nsp_write(base, IRQCONTROL, IRQCONTROL_IRQDISABLE); |
| 899 |
i_src = nsp_read(base, IRQSTATUS); |
| 900 |
//DEBUG(0, " i_src=0x%x\n", i_src); |
| 901 |
if ((i_src == 0xff) || ((i_src & IRQSTATUS_MASK) == 0)) { |
| 902 |
nsp_write(base, IRQCONTROL, 0); |
| 903 |
//DEBUG(0, " no irq/shared irq\n"); |
| 904 |
return; |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
/* XXX: IMPORTANT |
| 909 |
* Do not read an irq_phase register if no scsi phase interrupt. |
| 910 |
* Unless, you should lose a scsi phase interrupt. |
| 911 |
*/ |
| 912 |
phase = nsp_index_read(base, SCSIBUSMON); |
| 913 |
if((i_src & IRQSTATUS_SCSI) != 0) { |
| 914 |
irq_phase = nsp_index_read(base, IRQPHASESENCE); |
| 915 |
} else { |
| 916 |
irq_phase = 0; |
| 917 |
} |
| 918 |
|
| 919 |
//DEBUG(0, " irq_phase=0x%x\n", irq_phase); |
| 920 |
|
| 921 |
/* |
| 922 |
* timer interrupt handler (scsi vs timer interrupts) |
| 923 |
*/ |
| 924 |
//DEBUG(0, " timercount=%d\n", data->TimerCount); |
| 925 |
if (data->TimerCount != 0) { |
| 926 |
//DEBUG(0, " stop timer\n"); |
| 927 |
nsp_index_write(base, TIMERCOUNT, 0); |
| 928 |
nsp_index_write(base, TIMERCOUNT, 0); |
| 929 |
data->TimerCount = 0; |
| 930 |
} |
| 931 |
|
| 932 |
if ((i_src & IRQSTATUS_MASK) == IRQSTATUS_TIMER && |
| 933 |
data->SelectionTimeOut == 0) { |
| 934 |
//DEBUG(0, " timer start\n"); |
| 935 |
nsp_write(base, IRQCONTROL, IRQCONTROL_TIMER_CLEAR); |
| 936 |
return; |
| 937 |
} |
| 938 |
|
| 939 |
nsp_write(base, IRQCONTROL, IRQCONTROL_TIMER_CLEAR | IRQCONTROL_FIFO_CLEAR); |
| 940 |
|
| 941 |
if (data->CurrentSC == NULL) { |
| 942 |
printk(KERN_DEBUG "%s: CurrentSC==NULL irq_status=0x%x phase=0x%x irq_phase=0x%x this can't be happen\n", __FUNCTION__, i_src, phase, irq_phase); |
| 943 |
return; |
| 944 |
} else { |
| 945 |
tmpSC = data->CurrentSC; |
| 946 |
target = tmpSC->device->id; |
| 947 |
lun = tmpSC->device->lun; |
| 948 |
sync_neg = &(data->Sync[target].SyncNegotiation); |
| 949 |
} |
| 950 |
|
| 951 |
/* |
| 952 |
* parse hardware SCSI irq reasons register |
| 953 |
*/ |
| 954 |
if ((i_src & IRQSTATUS_SCSI) != 0) { |
| 955 |
if ((irq_phase & SCSI_RESET_IRQ) != 0) { |
| 956 |
printk(KERN_DEBUG " %s: bus reset (power off?)\n", __FUNCTION__); |
| 957 |
*sync_neg = SYNC_NOT_YET; |
| 958 |
data->CurrentSC = NULL; |
| 959 |
tmpSC->result = (DID_RESET << 16) | |
| 960 |
((tmpSC->SCp.Message & 0xff) << 8) | |
| 961 |
((tmpSC->SCp.Status & 0xff) << 0); |
| 962 |
tmpSC->scsi_done(tmpSC); |
| 963 |
return; |
| 964 |
} |
| 965 |
|
| 966 |
if ((irq_phase & RESELECT_IRQ) != 0) { |
| 967 |
DEBUG(0, " reselect\n"); |
| 968 |
nsp_write(base, IRQCONTROL, IRQCONTROL_RESELECT_CLEAR); |
| 969 |
if (nsp_reselected(tmpSC, data) != FALSE) { |
| 970 |
return; |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
if ((irq_phase & (PHASE_CHANGE_IRQ | LATCHED_BUS_FREE)) == 0) { |
| 975 |
return; |
| 976 |
} |
| 977 |
} |
| 978 |
|
| 979 |
//show_phase(tmpSC); |
| 980 |
|
| 981 |
switch(tmpSC->SCp.phase) { |
| 982 |
case PH_SELSTART: |
| 983 |
//*sync_neg = SYNC_NOT_YET; |
| 984 |
if ((phase & BUSMON_BSY) == 0) { |
| 985 |
//DEBUG(0, " selection count=%d\n", data->SelectionTimeOut); |
| 986 |
if (data->SelectionTimeOut >= NSP_SELTIMEOUT) { |
| 987 |
DEBUG(0, " selection time out\n"); |
| 988 |
data->SelectionTimeOut = 0; |
| 989 |
nsp_index_write(base, SCSIBUSCTRL, 0); |
| 990 |
|
| 991 |
data->CurrentSC = NULL; |
| 992 |
tmpSC->result = DID_NO_CONNECT << 16; |
| 993 |
tmpSC->scsi_done(tmpSC); |
| 994 |
|
| 995 |
return; |
| 996 |
} |
| 997 |
data->SelectionTimeOut += 1; |
| 998 |
nsp_start_timer(tmpSC, data, 1000/51); |
| 999 |
return; |
| 1000 |
} |
| 1001 |
|
| 1002 |
/* attention assert */ |
| 1003 |
//DEBUG(0, " attention assert\n"); |
| 1004 |
data->SelectionTimeOut = 0; |
| 1005 |
tmpSC->SCp.phase = PH_SELECTED; |
| 1006 |
nsp_index_write(base, SCSIBUSCTRL, SCSI_ATN); |
| 1007 |
udelay(1); |
| 1008 |
nsp_index_write(base, SCSIBUSCTRL, SCSI_ATN | AUTODIRECTION | ACKENB); |
| 1009 |
return; |
| 1010 |
|
| 1011 |
break; |
| 1012 |
|
| 1013 |
case PH_RESELECT: |
| 1014 |
//DEBUG(0, " phase reselect\n"); |
| 1015 |
//*sync_neg = SYNC_NOT_YET; |
| 1016 |
if ((phase & BUSMON_PHASE_MASK) != BUSPHASE_MESSAGE_IN) { |
| 1017 |
|
| 1018 |
data->CurrentSC = NULL; |
| 1019 |
tmpSC->result = DID_ABORT << 16; |
| 1020 |
tmpSC->scsi_done(tmpSC); |
| 1021 |
return; |
| 1022 |
} |
| 1023 |
/* fall through */ |
| 1024 |
default: |
| 1025 |
if ((i_src & (IRQSTATUS_SCSI | IRQSTATUS_FIFO)) == 0) { |
| 1026 |
return; |
| 1027 |
} |
| 1028 |
break; |
| 1029 |
} |
| 1030 |
|
| 1031 |
/* |
| 1032 |
* SCSI sequencer |
| 1033 |
*/ |
| 1034 |
//DEBUG(0, " start scsi seq\n"); |
| 1035 |
|
| 1036 |
/* normal disconnect */ |
| 1037 |
if (((tmpSC->SCp.phase == PH_MSG_IN) || (tmpSC->SCp.phase == PH_MSG_OUT)) && |
| 1038 |
(irq_phase & LATCHED_BUS_FREE) != 0 ) { |
| 1039 |
DEBUG(0, " normal disconnect i_src=0x%x, phase=0x%x, irq_phase=0x%x\n", i_src, phase, irq_phase); |
| 1040 |
if ((tmpSC->SCp.Message == MSG_COMMAND_COMPLETE)) { /* all command complete and return status */ |
| 1041 |
//*sync_neg = SYNC_NOT_YET; |
| 1042 |
data->CurrentSC = NULL; |
| 1043 |
tmpSC->result = (DID_OK << 16) | |
| 1044 |
((tmpSC->SCp.Message & 0xff) << 8) | |
| 1045 |
((tmpSC->SCp.Status & 0xff) << 0); |
| 1046 |
DEBUG(0, " command complete result=0x%x\n", tmpSC->result); |
| 1047 |
tmpSC->scsi_done(tmpSC); |
| 1048 |
|
| 1049 |
return; |
| 1050 |
} |
| 1051 |
|
| 1052 |
return; |
| 1053 |
} |
| 1054 |
|
| 1055 |
|
| 1056 |
/* check unexpected bus free state */ |
| 1057 |
if (phase == 0) { |
| 1058 |
printk(KERN_DEBUG " %s: unexpected bus free. i_src=0x%x, phase=0x%x, irq_phase=0x%x\n", __FUNCTION__, i_src, phase, irq_phase); |
| 1059 |
|
| 1060 |
*sync_neg = SYNC_NOT_YET; |
| 1061 |
data->CurrentSC = NULL; |
| 1062 |
tmpSC->result = DID_ERROR << 16; |
| 1063 |
tmpSC->scsi_done(tmpSC); |
| 1064 |
return; |
| 1065 |
} |
| 1066 |
|
| 1067 |
switch (phase & BUSMON_PHASE_MASK) { |
| 1068 |
case BUSPHASE_COMMAND: |
| 1069 |
DEBUG(0, " BUSPHASE_COMMAND\n"); |
| 1070 |
if ((phase & BUSMON_REQ) == 0) { |
| 1071 |
DEBUG(0, " REQ == 0\n"); |
| 1072 |
return; |
| 1073 |
} |
| 1074 |
|
| 1075 |
tmpSC->SCp.phase = PH_COMMAND; |
| 1076 |
|
| 1077 |
nsp_nexus(tmpSC, data); |
| 1078 |
|
| 1079 |
/* write scsi command */ |
| 1080 |
DEBUG(0, " cmd_len=%d\n", tmpSC->cmd_len); |
| 1081 |
nsp_index_write(base, COMMANDCTRL, CLEAR_COMMAND_POINTER); |
| 1082 |
for (i = 0; i < tmpSC->cmd_len; i++) { |
| 1083 |
nsp_index_write(base, COMMANDDATA, tmpSC->cmnd[i]); |
| 1084 |
} |
| 1085 |
nsp_index_write(base, COMMANDCTRL, CLEAR_COMMAND_POINTER | AUTO_COMMAND_GO); |
| 1086 |
break; |
| 1087 |
|
| 1088 |
case BUSPHASE_DATA_OUT: |
| 1089 |
DEBUG(0, " BUSPHASE_DATA_OUT\n"); |
| 1090 |
|
| 1091 |
tmpSC->SCp.phase = PH_DATA; |
| 1092 |
tmpSC->SCp.have_data_in = IO_OUT; |
| 1093 |
|
| 1094 |
nsp_pio_write(tmpSC, data); |
| 1095 |
|
| 1096 |
break; |
| 1097 |
|
| 1098 |
case BUSPHASE_DATA_IN: |
| 1099 |
DEBUG(0, " BUSPHASE_DATA_IN\n"); |
| 1100 |
|
| 1101 |
tmpSC->SCp.phase = PH_DATA; |
| 1102 |
tmpSC->SCp.have_data_in = IO_IN; |
| 1103 |
|
| 1104 |
nsp_pio_read(tmpSC, data); |
| 1105 |
|
| 1106 |
break; |
| 1107 |
|
| 1108 |
case BUSPHASE_STATUS: |
| 1109 |
nsp_dataphase_bypass(tmpSC, data); |
| 1110 |
DEBUG(0, " BUSPHASE_STATUS\n"); |
| 1111 |
|
| 1112 |
tmpSC->SCp.phase = PH_STATUS; |
| 1113 |
|
| 1114 |
tmpSC->SCp.Status = nsp_index_read(base, SCSIDATAWITHACK); |
| 1115 |
DEBUG(0, " message=0x%x status=0x%x\n", tmpSC->SCp.Message, tmpSC->SCp.Status); |
| 1116 |
|
| 1117 |
break; |
| 1118 |
|
| 1119 |
case BUSPHASE_MESSAGE_OUT: |
| 1120 |
DEBUG(0, " BUSPHASE_MESSAGE_OUT\n"); |
| 1121 |
if ((phase & BUSMON_REQ) == 0) { |
| 1122 |
goto timer_out; |
| 1123 |
} |
| 1124 |
|
| 1125 |
tmpSC->SCp.phase = PH_MSG_OUT; |
| 1126 |
|
| 1127 |
data->MsgLen = i = 0; |
| 1128 |
data->MsgBuffer[i] = IDENTIFY(TRUE, lun); i++; |
| 1129 |
|
| 1130 |
if (*sync_neg == SYNC_NOT_YET) { |
| 1131 |
data->Sync[target].SyncPeriod = 0; |
| 1132 |
data->Sync[target].SyncOffset = 0; |
| 1133 |
|
| 1134 |
/**/ |
| 1135 |
data->MsgBuffer[i] = MSG_EXTENDED; i++; |
| 1136 |
data->MsgBuffer[i] = 3; i++; |
| 1137 |
data->MsgBuffer[i] = MSG_EXT_SDTR; i++; |
| 1138 |
data->MsgBuffer[i] = 0x0c; i++; |
| 1139 |
data->MsgBuffer[i] = 15; i++; |
| 1140 |
/**/ |
| 1141 |
} |
| 1142 |
data->MsgLen = i; |
| 1143 |
|
| 1144 |
nsp_msg(tmpSC, data); |
| 1145 |
show_message(data); |
| 1146 |
nsp_message_out(tmpSC, data); |
| 1147 |
break; |
| 1148 |
|
| 1149 |
case BUSPHASE_MESSAGE_IN: |
| 1150 |
nsp_dataphase_bypass(tmpSC, data); |
| 1151 |
DEBUG(0, " BUSPHASE_MESSAGE_IN\n"); |
| 1152 |
if ((phase & BUSMON_REQ) == 0) { |
| 1153 |
goto timer_out; |
| 1154 |
} |
| 1155 |
|
| 1156 |
tmpSC->SCp.phase = PH_MSG_IN; |
| 1157 |
nsp_message_in(tmpSC, data); |
| 1158 |
|
| 1159 |
/**/ |
| 1160 |
if (*sync_neg == SYNC_NOT_YET) { |
| 1161 |
//printk("%d,%d\n",target,lun); |
| 1162 |
|
| 1163 |
if (data->MsgLen >= 5 && |
| 1164 |
data->MsgBuffer[0] == MSG_EXTENDED && |
| 1165 |
data->MsgBuffer[1] == 3 && |
| 1166 |
data->MsgBuffer[2] == MSG_EXT_SDTR ) { |
| 1167 |
data->Sync[target].SyncPeriod = data->MsgBuffer[3]; |
| 1168 |
data->Sync[target].SyncOffset = data->MsgBuffer[4]; |
| 1169 |
//printk("sync ok, %d %d\n", data->MsgBuffer[3], data->MsgBuffer[4]); |
| 1170 |
*sync_neg = SYNC_OK; |
| 1171 |
} else { |
| 1172 |
data->Sync[target].SyncPeriod = 0; |
| 1173 |
data->Sync[target].SyncOffset = 0; |
| 1174 |
*sync_neg = SYNC_NG; |
| 1175 |
} |
| 1176 |
nsp_msg(tmpSC, data); |
| 1177 |
} |
| 1178 |
/**/ |
| 1179 |
|
| 1180 |
/* search last messeage byte */ |
| 1181 |
tmp = -1; |
| 1182 |
for (i = 0; i < data->MsgLen; i++) { |
| 1183 |
tmp = data->MsgBuffer[i]; |
| 1184 |
if (data->MsgBuffer[i] == MSG_EXTENDED) { |
| 1185 |
i += (1 + data->MsgBuffer[i+1]); |
| 1186 |
} |
| 1187 |
} |
| 1188 |
tmpSC->SCp.Message = tmp; |
| 1189 |
|
| 1190 |
DEBUG(0, " message=0x%x len=%d\n", tmpSC->SCp.Message, data->MsgLen); |
| 1191 |
show_message(data); |
| 1192 |
|
| 1193 |
break; |
| 1194 |
|
| 1195 |
case BUSPHASE_SELECT: |
| 1196 |
default: |
| 1197 |
DEBUG(0, " BUSPHASE other\n"); |
| 1198 |
|
| 1199 |
break; |
| 1200 |
} |
| 1201 |
|
| 1202 |
//DEBUG(0, "%s: out\n", __FUNCTION__); |
| 1203 |
return; |
| 1204 |
|
| 1205 |
timer_out: |
| 1206 |
nsp_start_timer(tmpSC, data, 1000/102); |
| 1207 |
return; |
| 1208 |
} |
| 1209 |
|
| 1210 |
#ifdef PCMCIA_DEBUG |
| 1211 |
#include "nsp_debug.c" |
| 1212 |
#endif /* DBG_SHOWCOMMAND */ |
| 1213 |
|
| 1214 |
/*----------------------------------------------------------------*/ |
| 1215 |
/* look for ninja3 card and init if found */ |
| 1216 |
/*----------------------------------------------------------------*/ |
| 1217 |
static struct Scsi_Host *__nsp_detect(Scsi_Host_Template *sht) |
| 1218 |
{ |
| 1219 |
struct Scsi_Host *host; /* registered host structure */ |
| 1220 |
nsp_hw_data *data = &nsp_data; |
| 1221 |
|
| 1222 |
DEBUG(0, "%s: this_id=%d\n", __FUNCTION__, sht->this_id); |
| 1223 |
|
| 1224 |
request_region(data->BaseAddress, data->NumAddress, "nsp_cs"); |
| 1225 |
host = scsi_register(sht, 0); |
| 1226 |
if(host == NULL) |
| 1227 |
return NULL; |
| 1228 |
|
| 1229 |
host->unique_id = data->BaseAddress; |
| 1230 |
host->io_port = data->BaseAddress; |
| 1231 |
host->n_io_port = data->NumAddress; |
| 1232 |
host->irq = data->IrqNumber; |
| 1233 |
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)) |
| 1234 |
host->base = data->MmioAddress; /* kernel 2.4 */ |
| 1235 |
#else |
| 1236 |
host->base = (char *)(data->MmioAddress); /* 2.2 */ |
| 1237 |
#endif |
| 1238 |
|
| 1239 |
spin_lock_init(&(data->Lock)); |
| 1240 |
|
| 1241 |
snprintf(data->nspinfo, |
| 1242 |
sizeof(data->nspinfo), |
| 1243 |
"NinjaSCSI-3/32Bi Driver $Revision$ IO:0x%04lx-0x%04lx MMIO(virt addr):0x%04lx IRQ:%02d", |
| 1244 |
host->io_port, host->io_port + host->n_io_port - 1, |
| 1245 |
host->base, |
| 1246 |
host->irq); |
| 1247 |
data->nspinfo[sizeof(data->nspinfo) - 1] = '\0'; |
| 1248 |
sht->name = data->nspinfo; |
| 1249 |
|
| 1250 |
DEBUG(0, "%s: end\n", __FUNCTION__); |
| 1251 |
|
| 1252 |
//MOD_INC_USE_COUNT; |
| 1253 |
|
| 1254 |
return host; |
| 1255 |
} |
| 1256 |
|
| 1257 |
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) |
| 1258 |
static int nsp_detect(Scsi_Host_Template *sht) |
| 1259 |
{ |
| 1260 |
return (__nsp_detect(sht) != NULL); |
| 1261 |
} |
| 1262 |
|
| 1263 |
static int nsp_release(struct Scsi_Host *shpnt) |
| 1264 |
{ |
| 1265 |
//nsp_hw_data *data = &nsp_data; |
| 1266 |
|
| 1267 |
/* PCMCIA Card Service dose same things */ |
| 1268 |
//if (shpnt->irq) { |
| 1269 |
// free_irq(shpnt->irq, data); |
| 1270 |
//} |
| 1271 |
//if (shpnt->io_port) { |
| 1272 |
// release_region(shpnt->io_port, shpnt->n_io_port); |
| 1273 |
//} |
| 1274 |
|
| 1275 |
//MOD_DEC_USE_COUNT; |
| 1276 |
|
| 1277 |
return 0; |
| 1278 |
} |
| 1279 |
#endif |
| 1280 |
|
| 1281 |
/*----------------------------------------------------------------*/ |
| 1282 |
/* return info string */ |
| 1283 |
/*----------------------------------------------------------------*/ |
| 1284 |
static const char *nsp_info(struct Scsi_Host *shpnt) |
| 1285 |
{ |
| 1286 |
nsp_hw_data *data = &nsp_data; |
| 1287 |
|
| 1288 |
return data->nspinfo; |
| 1289 |
} |
| 1290 |
|
| 1291 |
#undef SPRINTF |
| 1292 |
#define SPRINTF(args...) \ |
| 1293 |
do { if(pos < buffer + length) pos += sprintf(pos, ## args); } while(0) |
| 1294 |
static int nsp_proc_info(char *buffer, |
| 1295 |
char **start, |
| 1296 |
off_t offset, |
| 1297 |
int length, |
| 1298 |
int hostno, |
| 1299 |
int inout) |
| 1300 |
{ |
| 1301 |
int id; |
| 1302 |
char *pos = buffer; |
| 1303 |
int thislength; |
| 1304 |
int speed; |
| 1305 |
unsigned long flags; |
| 1306 |
nsp_hw_data *data = &nsp_data; |
| 1307 |
struct Scsi_Host *host = NULL; |
| 1308 |
|
| 1309 |
if (inout) { |
| 1310 |
return -EINVAL; |
| 1311 |
} |
| 1312 |
|
| 1313 |
/* search this HBA host */ |
| 1314 |
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,45)) |
| 1315 |
host = scsi_host_hn_get(hostno); |
| 1316 |
#else |
| 1317 |
for (host=scsi_hostlist; host; host=host->next) { |
| 1318 |
if (host->host_no == hostno) { |
| 1319 |
break; |
| 1320 |
} |
| 1321 |
} |
| 1322 |
#endif |
| 1323 |
if (host == NULL) { |
| 1324 |
return -ESRCH; |
| 1325 |
} |
| 1326 |
|
| 1327 |
SPRINTF("NinjaSCSI status\n\n"); |
| 1328 |
SPRINTF("Driver version: $Revision$\n"); |
| 1329 |
SPRINTF("SCSI host No.: %d\n", hostno); |
| 1330 |
SPRINTF("IRQ: %d\n", host->irq); |
| 1331 |
SPRINTF("IO: 0x%lx-0x%lx\n", host->io_port, host->io_port + host->n_io_port - 1); |
| 1332 |
SPRINTF("MMIO(virtual address): 0x%lx\n", host->base); |
| 1333 |
SPRINTF("sg_tablesize: %d\n", host->sg_tablesize); |
| 1334 |
|
| 1335 |
SPRINTF("burst transfer mode: "); |
| 1336 |
switch (nsp_burst_mode) { |
| 1337 |
case BURST_IO8: |
| 1338 |
SPRINTF("io8"); |
| 1339 |
break; |
| 1340 |
case BURST_IO32: |
| 1341 |
SPRINTF("io32"); |
| 1342 |
break; |
| 1343 |
case BURST_MEM32: |
| 1344 |
SPRINTF("mem32"); |
| 1345 |
break; |
| 1346 |
default: |
| 1347 |
SPRINTF("???"); |
| 1348 |
break; |
| 1349 |
} |
| 1350 |
SPRINTF("\n"); |
| 1351 |
|
| 1352 |
|
| 1353 |
spin_lock_irqsave(&(data->Lock), flags); |
| 1354 |
SPRINTF("CurrentSC: 0x%p\n\n", data->CurrentSC); |
| 1355 |
spin_unlock_irqrestore(&(data->Lock), flags); |
| 1356 |
|
| 1357 |
SPRINTF("SDTR status\n"); |
| 1358 |
for(id = 0; id < N_TARGET; id++) { |
| 1359 |
|
| 1360 |
SPRINTF("id %d: ", id); |
| 1361 |
|
| 1362 |
if (id == host->this_id) { |
| 1363 |
SPRINTF("----- NinjaSCSI-3 host adapter\n"); |
| 1364 |
continue; |
| 1365 |
} |
| 1366 |
|
| 1367 |
switch(data->Sync[id].SyncNegotiation) { |
| 1368 |
case SYNC_OK: |
| 1369 |
SPRINTF(" sync"); |
| 1370 |
break; |
| 1371 |
case SYNC_NG: |
| 1372 |
SPRINTF("async"); |
| 1373 |
break; |
| 1374 |
case SYNC_NOT_YET: |
| 1375 |
SPRINTF(" none"); |
| 1376 |
break; |
| 1377 |
default: |
| 1378 |
SPRINTF("?????"); |
| 1379 |
break; |
| 1380 |
} |
| 1381 |
|
| 1382 |
if (data->Sync[id].SyncPeriod != 0) { |
| 1383 |
speed = 1000000 / (data->Sync[id].SyncPeriod * 4); |
| 1384 |
|
| 1385 |
SPRINTF(" transfer %d.%dMB/s, offset %d", |
| 1386 |
speed / 1000, |
| 1387 |
speed % 1000, |
| 1388 |
data->Sync[id].SyncOffset |
| 1389 |
); |
| 1390 |
} |
| 1391 |
SPRINTF("\n"); |
| 1392 |
} |
| 1393 |
|
| 1394 |
thislength = pos - (buffer + offset); |
| 1395 |
|
| 1396 |
if(thislength < 0) { |
| 1397 |
*start = 0; |
| 1398 |
return 0; |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
thislength = MIN(thislength, length); |
| 1403 |
*start = buffer + offset; |
| 1404 |
|
| 1405 |
return thislength; |
| 1406 |
} |
| 1407 |
#undef SPRINTF |
| 1408 |
|
| 1409 |
|
| 1410 |
/*static int nsp_eh_strategy(struct Scsi_Host *Shost) |
| 1411 |
{ |
| 1412 |
return FAILED; |
| 1413 |
}*/ |
| 1414 |
|
| 1415 |
/* |
| 1416 |
static int nsp_eh_abort(Scsi_Cmnd *SCpnt) |
| 1417 |
{ |
| 1418 |
DEBUG(0, "%s: SCpnt=0x%p\n", __FUNCTION__, SCpnt); |
| 1419 |
|
| 1420 |
return nsp_eh_bus_reset(SCpnt); |
| 1421 |
}*/ |
| 1422 |
|
| 1423 |
/* |
| 1424 |
static int nsp_eh_device_reset(Scsi_Cmnd *SCpnt) |
| 1425 |
{ |
| 1426 |
DEBUG(0, "%s: SCpnt=0x%p\n", __FUNCTION__, SCpnt); |
| 1427 |
|
| 1428 |
return FAILED; |
| 1429 |
}*/ |
| 1430 |
|
| 1431 |
static int nsp_eh_bus_reset(Scsi_Cmnd *SCpnt) |
| 1432 |
{ |
| 1433 |
nsp_hw_data *data = &nsp_data; |
| 1434 |
unsigned int base = SCpnt->device->host->io_port; |
| 1435 |
int i; |
| 1436 |
|
| 1437 |
DEBUG(0, "%s: SCpnt=0x%p base=0x%x\n", __FUNCTION__, SCpnt, base); |
| 1438 |
|
| 1439 |
nsp_write(base, IRQCONTROL, IRQCONTROL_ALLMASK); |
| 1440 |
|
| 1441 |
nsp_index_write(base, SCSIBUSCTRL, SCSI_RST); |
| 1442 |
mdelay(100); /* 100ms */ |
| 1443 |
nsp_index_write(base, SCSIBUSCTRL, 0); |
| 1444 |
for(i = 0; i < 5; i++) { |
| 1445 |
nsp_index_read(base, IRQPHASESENCE); /* dummy read */ |
| 1446 |
} |
| 1447 |
|
| 1448 |
nsp_write(base, IRQCONTROL, IRQCONTROL_ALLCLEAR); |
| 1449 |
|
| 1450 |
nsphw_init_sync(data); |
| 1451 |
|
| 1452 |
return SUCCESS; |
| 1453 |
} |
| 1454 |
|
| 1455 |
static int nsp_eh_host_reset(Scsi_Cmnd *SCpnt) |
| 1456 |
{ |
| 1457 |
nsp_hw_data *data = &nsp_data; |
| 1458 |
|
| 1459 |
DEBUG(0, "%s:\n", __FUNCTION__); |
| 1460 |
|
| 1461 |
nsphw_init(data); |
| 1462 |
|
| 1463 |
return SUCCESS; |
| 1464 |
} |
| 1465 |
|
| 1466 |
|
| 1467 |
/********************************************************************** |
| 1468 |
PCMCIA functions |
| 1469 |
**********************************************************************/ |
| 1470 |
|
| 1471 |
/*====================================================================== |
| 1472 |
nsp_cs_attach() creates an "instance" of the driver, allocating |
| 1473 |
local data structures for one device. The device is registered |
| 1474 |
with Card Services. |
| 1475 |
|
| 1476 |
The dev_link structure is initialized, but we don't actually |
| 1477 |
configure the card at this point -- we wait until we receive a |
| 1478 |
card insertion event. |
| 1479 |
======================================================================*/ |
| 1480 |
static dev_link_t *nsp_cs_attach(void) |
| 1481 |
{ |
| 1482 |
scsi_info_t *info; |
| 1483 |
client_reg_t client_reg; |
| 1484 |
dev_link_t *link; |
| 1485 |
int ret, i; |
| 1486 |
|
| 1487 |
DEBUG(0, "%s:\n", __FUNCTION__); |
| 1488 |
|
| 1489 |
/* Create new SCSI device */ |
| 1490 |
info = kmalloc(sizeof(*info), GFP_KERNEL); |
| 1491 |
if (!info) { return NULL; } |
| 1492 |
memset(info, 0, sizeof(*info)); |
| 1493 |
link = &info->link; |
| 1494 |
link->priv = info; |
| 1495 |
|
| 1496 |
/* Initialize the dev_link_t structure */ |
| 1497 |
link->release.function = &nsp_cs_release; |
| 1498 |
link->release.data = (u_long)link; |
| 1499 |
|
| 1500 |
/* The io structure describes IO port mapping */ |
| 1501 |
link->io.NumPorts1 = 0x10; |
| 1502 |
link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 1503 |
link->io.IOAddrLines = 10; /* not used */ |
| 1504 |
|
| 1505 |
/* Interrupt setup */ |
| 1506 |
link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
| 1507 |
link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID; |
| 1508 |
if (irq_list[0] == -1) { |
| 1509 |
link->irq.IRQInfo2 = irq_mask; |
| 1510 |
} else { |
| 1511 |
for (i = 0; i < 4; i++) { |
| 1512 |
link->irq.IRQInfo2 |= 1 << irq_list[i]; |
| 1513 |
} |
| 1514 |
} |
| 1515 |
|
| 1516 |
/* IRQ の確保はここで PCMCIA の関数を用いて行なう瘢雹ので |
| 1517 |
* host->hostdata を irq.Instance に代入できない。 |
| 1518 |
* host->hostdata が使えれば複数の NinjaSCSI が |
| 1519 |
* 使用できるのだが。 |
| 1520 |
*/ |
| 1521 |
link->irq.Handler = &nspintr; |
| 1522 |
link->irq.Instance = &nsp_data; |
| 1523 |
link->irq.Attributes |= (SA_SHIRQ | SA_SAMPLE_RANDOM); |
| 1524 |
|
| 1525 |
/* General socket configuration */ |
| 1526 |
link->conf.Attributes = CONF_ENABLE_IRQ; |
| 1527 |
link->conf.Vcc = 50; |
| 1528 |
link->conf.IntType = INT_MEMORY_AND_IO; |
| 1529 |
link->conf.Present = PRESENT_OPTION; |
| 1530 |
|
| 1531 |
|
| 1532 |
/* Register with Card Services */ |
| 1533 |
link->next = dev_list; |
| 1534 |
dev_list = link; |
| 1535 |
client_reg.dev_info = &dev_info; |
| 1536 |
client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE; |
| 1537 |
client_reg.EventMask = |
| 1538 |
CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | |
| 1539 |
CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | |
| 1540 |
CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME ; |
| 1541 |
client_reg.event_handler = &nsp_cs_event; |
| 1542 |
client_reg.Version = 0x0210; |
| 1543 |
client_reg.event_callback_args.client_data = link; |
| 1544 |
ret = CardServices(RegisterClient, &link->handle, &client_reg); |
| 1545 |
if (ret != CS_SUCCESS) { |
| 1546 |
cs_error(link->handle, RegisterClient, ret); |
| 1547 |
nsp_cs_detach(link); |
| 1548 |
return NULL; |
| 1549 |
} |
| 1550 |
|
| 1551 |
return link; |
| 1552 |
} /* nsp_cs_attach */ |
| 1553 |
|
| 1554 |
|
| 1555 |
/*====================================================================== |
| 1556 |
This deletes a driver "instance". The device is de-registered |
| 1557 |
with Card Services. If it has been released, all local data |
| 1558 |
structures are freed. Otherwise, the structures will be freed |
| 1559 |
when the device is released. |
| 1560 |
======================================================================*/ |
| 1561 |
static void nsp_cs_detach(dev_link_t *link) |
| 1562 |
{ |
| 1563 |
dev_link_t **linkp; |
| 1564 |
|
| 1565 |
DEBUG(0, "%s(0x%p)\n", __FUNCTION__, link); |
| 1566 |
|
| 1567 |
/* Locate device structure */ |
| 1568 |
for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) { |
| 1569 |
if (*linkp == link) { |
| 1570 |
break; |
| 1571 |
} |
| 1572 |
} |
| 1573 |
if (*linkp == NULL) { |
| 1574 |
return; |
| 1575 |
} |
| 1576 |
|
| 1577 |
del_timer(&link->release); |
| 1578 |
if (link->state & DEV_CONFIG) { |
| 1579 |
nsp_cs_release((u_long)link); |
| 1580 |
if (link->state & DEV_STALE_CONFIG) { |
| 1581 |
link->state |= DEV_STALE_LINK; |
| 1582 |
return; |
| 1583 |
} |
| 1584 |
} |
| 1585 |
|
| 1586 |
/* Break the link with Card Services */ |
| 1587 |
if (link->handle) { |
| 1588 |
CardServices(DeregisterClient, link->handle); |
| 1589 |
} |
| 1590 |
|
| 1591 |
/* Unlink device structure, free bits */ |
| 1592 |
*linkp = link->next; |
| 1593 |
kfree(link->priv); |
| 1594 |
link->priv = NULL; |
| 1595 |
|
| 1596 |
} /* nsp_cs_detach */ |
| 1597 |
|
| 1598 |
|
| 1599 |
/*====================================================================== |
| 1600 |
nsp_cs_config() is scheduled to run after a CARD_INSERTION event |
| 1601 |
is received, to configure the PCMCIA socket, and to make the |
| 1602 |
ethernet device available to the system. |
| 1603 |
======================================================================*/ |
| 1604 |
#define CS_CHECK(fn, args...) \ |
| 1605 |
while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed |
| 1606 |
#define CFG_CHECK(fn, args...) \ |
| 1607 |
if (CardServices(fn, args) != 0) goto next_entry |
| 1608 |
/*====================================================================*/ |
| 1609 |
|
| 1610 |
static void nsp_cs_config(dev_link_t *link) |
| 1611 |
{ |
| 1612 |
client_handle_t handle = link->handle; |
| 1613 |
scsi_info_t *info = link->priv; |
| 1614 |
tuple_t tuple; |
| 1615 |
cisparse_t parse; |
| 1616 |
int last_ret, last_fn; |
| 1617 |
u_char tuple_data[64]; |
| 1618 |
config_info_t conf; |
| 1619 |
win_req_t req; |
| 1620 |
memreq_t map; |
| 1621 |
cistpl_cftable_entry_t dflt = { 0 }; |
| 1622 |
|
| 1623 |
struct Scsi_Host *host; |
| 1624 |
nsp_hw_data *data = &nsp_data; |
| 1625 |
|
| 1626 |
|
| 1627 |
DEBUG(0, "%s: in\n", __FUNCTION__); |
| 1628 |
|
| 1629 |
tuple.DesiredTuple = CISTPL_CONFIG; |
| 1630 |
tuple.Attributes = 0; |
| 1631 |
tuple.TupleData = tuple_data; |
| 1632 |
tuple.TupleDataMax = sizeof(tuple_data); |
| 1633 |
tuple.TupleOffset = 0; |
| 1634 |
CS_CHECK(GetFirstTuple, handle, &tuple); |
| 1635 |
CS_CHECK(GetTupleData, handle, &tuple); |
| 1636 |
CS_CHECK(ParseTuple, handle, &tuple, &parse); |
| 1637 |
link->conf.ConfigBase = parse.config.base; |
| 1638 |
link->conf.Present = parse.config.rmask[0]; |
| 1639 |
|
| 1640 |
/* Configure card */ |
| 1641 |
link->state |= DEV_CONFIG; |
| 1642 |
|
| 1643 |
/* Look up the current Vcc */ |
| 1644 |
CS_CHECK(GetConfigurationInfo, handle, &conf); |
| 1645 |
link->conf.Vcc = conf.Vcc; |
| 1646 |
|
| 1647 |
tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
| 1648 |
CS_CHECK(GetFirstTuple, handle, &tuple); |
| 1649 |
while (1) { |
| 1650 |
cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); |
| 1651 |
|
| 1652 |
CFG_CHECK(GetTupleData, handle, &tuple); |
| 1653 |
CFG_CHECK(ParseTuple, handle, &tuple, &parse); |
| 1654 |
|
| 1655 |
if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; } |
| 1656 |
if (cfg->index == 0) { goto next_entry; } |
| 1657 |
link->conf.ConfigIndex = cfg->index; |
| 1658 |
|
| 1659 |
/* Does this card need audio output? */ |
| 1660 |
if (cfg->flags & CISTPL_CFTABLE_AUDIO) { |
| 1661 |
link->conf.Attributes |= CONF_ENABLE_SPKR; |
| 1662 |
link->conf.Status = CCSR_AUDIO_ENA; |
| 1663 |
} |
| 1664 |
|
| 1665 |
/* Use power settings for Vcc and Vpp if present */ |
| 1666 |
/* Note that the CIS values need to be rescaled */ |
| 1667 |
if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) { |
| 1668 |
if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000) { |
| 1669 |
goto next_entry; |
| 1670 |
} |
| 1671 |
} else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) { |
| 1672 |
if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000) { |
| 1673 |
goto next_entry; |
| 1674 |
} |
| 1675 |
} |
| 1676 |
|
| 1677 |
if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) { |
| 1678 |
link->conf.Vpp1 = link->conf.Vpp2 = |
| 1679 |
cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; |
| 1680 |
} else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) { |
| 1681 |
link->conf.Vpp1 = link->conf.Vpp2 = |
| 1682 |
dflt.vpp1.param[CISTPL_POWER_VNOM]/10000; |
| 1683 |
} |
| 1684 |
|
| 1685 |
/* Do we need to allocate an interrupt? */ |
| 1686 |
if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) { |
| 1687 |
link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 1688 |
} |
| 1689 |
|
| 1690 |
/* IO window settings */ |
| 1691 |
link->io.NumPorts1 = link->io.NumPorts2 = 0; |
| 1692 |
if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 1693 |
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 1694 |
link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 1695 |
if (!(io->flags & CISTPL_IO_8BIT)) |
| 1696 |
link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; |
| 1697 |
if (!(io->flags & CISTPL_IO_16BIT)) |
| 1698 |
link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 1699 |
link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; |
| 1700 |
link->io.BasePort1 = io->win[0].base; |
| 1701 |
link->io.NumPorts1 = io->win[0].len; |
| 1702 |
if (io->nwin > 1) { |
| 1703 |
link->io.Attributes2 = link->io.Attributes1; |
| 1704 |
link->io.BasePort2 = io->win[1].base; |
| 1705 |
link->io.NumPorts2 = io->win[1].len; |
| 1706 |
} |
| 1707 |
/* This reserves IO space but doesn't actually enable it */ |
| 1708 |
CFG_CHECK(RequestIO, link->handle, &link->io); |
| 1709 |
} |
| 1710 |
|
| 1711 |
if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { |
| 1712 |
cistpl_mem_t *mem = |
| 1713 |
(cfg->mem.nwin) ? &cfg->mem : &dflt.mem; |
| 1714 |
req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM; |
| 1715 |
req.Attributes |= WIN_ENABLE; |
| 1716 |
req.Base = mem->win[0].host_addr; |
| 1717 |
req.Size = mem->win[0].len; |
| 1718 |
if (req.Size < 0x1000) |
| 1719 |
req.Size = 0x1000; |
| 1720 |
req.AccessSpeed = 0; |
| 1721 |
link->win = (window_handle_t)link->handle; |
| 1722 |
CFG_CHECK(RequestWindow, &link->win, &req); |
| 1723 |
map.Page = 0; map.CardOffset = mem->win[0].card_addr; |
| 1724 |
CFG_CHECK(MapMemPage, link->win, &map); |
| 1725 |
|
| 1726 |
data->MmioAddress = (u_long)ioremap_nocache(req.Base, req.Size); |
| 1727 |
} |
| 1728 |
/* If we got this far, we're cool! */ |
| 1729 |
break; |
| 1730 |
|
| 1731 |
next_entry: |
| 1732 |
DEBUG(0, "%s: next\n", __FUNCTION__); |
| 1733 |
|
| 1734 |
if (link->io.NumPorts1) |
| 1735 |
CardServices(ReleaseIO, link->handle, &link->io); |
| 1736 |
CS_CHECK(GetNextTuple, handle, &tuple); |
| 1737 |
} |
| 1738 |
|
| 1739 |
if (link->conf.Attributes & CONF_ENABLE_IRQ) |
| 1740 |
CS_CHECK(RequestIRQ, link->handle, &link->irq); |
| 1741 |
CS_CHECK(RequestConfiguration, handle, &link->conf); |
| 1742 |
|
| 1743 |
if (free_ports) { |
| 1744 |
if (link->io.BasePort1) |
| 1745 |
release_region(link->io.BasePort1, link->io.NumPorts1); |
| 1746 |
if (link->io.BasePort2) |
| 1747 |
release_region(link->io.BasePort2, link->io.NumPorts2); |
| 1748 |
} |
| 1749 |
|
| 1750 |
/* Set port and IRQ */ |
| 1751 |
data->BaseAddress = link->io.BasePort1; |
| 1752 |
data->NumAddress = link->io.NumPorts1; |
| 1753 |
data->IrqNumber = link->irq.AssignedIRQ; |
| 1754 |
|
| 1755 |
DEBUG(0, "%s: I/O[0x%x+0x%x] IRQ %d\n", |
| 1756 |
__FUNCTION__, data->BaseAddress, data->NumAddress, data->IrqNumber); |
| 1757 |
|
| 1758 |
if(nsphw_init(data) == FALSE) { |
| 1759 |
goto cs_failed; |
| 1760 |
} |
| 1761 |
|
| 1762 |
host = __nsp_detect(&nsp_driver_template); |
| 1763 |
if (!host) |
| 1764 |
goto cs_failed; |
| 1765 |
|
| 1766 |
sprintf(info->node.dev_name, "scsi%d", host->host_no); |
| 1767 |
link->dev = &info->node; |
| 1768 |
info->host = host; |
| 1769 |
|
| 1770 |
/* Finally, report what we've done */ |
| 1771 |
printk(KERN_INFO "nsp_cs: index 0x%02x: Vcc %d.%d", |
| 1772 |
link->conf.ConfigIndex, |
| 1773 |
link->conf.Vcc/10, link->conf.Vcc%10); |
| 1774 |
if (link->conf.Vpp1) { |
| 1775 |
printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10); |
| 1776 |
} |
| 1777 |
if (link->conf.Attributes & CONF_ENABLE_IRQ) { |
| 1778 |
printk(", irq %d", link->irq.AssignedIRQ); |
| 1779 |
} |
| 1780 |
if (link->io.NumPorts1) { |
| 1781 |
printk(", io 0x%04x-0x%04x", link->io.BasePort1, |
| 1782 |
link->io.BasePort1+link->io.NumPorts1-1); |
| 1783 |
} |
| 1784 |
if (link->io.NumPorts2) |
| 1785 |
printk(" & 0x%04x-0x%04x", link->io.BasePort2, |
| 1786 |
link->io.BasePort2+link->io.NumPorts2-1); |
| 1787 |
if (link->win) |
| 1788 |
printk(", mem 0x%06lx-0x%06lx", req.Base, |
| 1789 |
req.Base+req.Size-1); |
| 1790 |
printk("\n"); |
| 1791 |
|
| 1792 |
scsi_add_host(host, NULL); |
| 1793 |
link->state &= ~DEV_CONFIG_PENDING; |
| 1794 |
return; |
| 1795 |
|
| 1796 |
cs_failed: |
| 1797 |
cs_error(link->handle, last_fn, last_ret); |
| 1798 |
nsp_cs_release((u_long)link); |
| 1799 |
return; |
| 1800 |
|
| 1801 |
} /* nsp_cs_config */ |
| 1802 |
#undef CS_CHECK |
| 1803 |
#undef CFG_CHECK |
| 1804 |
|
| 1805 |
/*====================================================================== |
| 1806 |
After a card is removed, nsp_cs_release() will unregister the net |
| 1807 |
device, and release the PCMCIA configuration. If the device is |
| 1808 |
still open, this will be postponed until it is closed. |
| 1809 |
======================================================================*/ |
| 1810 |
static void nsp_cs_release(u_long arg) |
| 1811 |
{ |
| 1812 |
dev_link_t *link = (dev_link_t *)arg; |
| 1813 |
scsi_info_t *info = link->priv; |
| 1814 |
|
| 1815 |
DEBUG(0, "%s(0x%p)\n", __FUNCTION__, link); |
| 1816 |
|
| 1817 |
/* |
| 1818 |
* If the device is currently in use, we won't release until it |
| 1819 |
* is actually closed. |
| 1820 |
*/ |
| 1821 |
if (link->open) { |
| 1822 |
DEBUG(1, "nsp_cs: release postponed, '%s' still open\n", |
| 1823 |
link->dev->dev_name); |
| 1824 |
link->state |= DEV_STALE_CONFIG; |
| 1825 |
return; |
| 1826 |
} |
| 1827 |
|
| 1828 |
/* Unlink the device chain */ |
| 1829 |
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,2)) |
| 1830 |
scsi_unregister_module(MODULE_SCSI_HA, &nsp_driver_template); |
| 1831 |
#else |
| 1832 |
scsi_remove_host(info->host); |
| 1833 |
scsi_unregister(info->host); |
| 1834 |
#endif |
| 1835 |
link->dev = NULL; |
| 1836 |
|
| 1837 |
if (link->win) { |
| 1838 |
iounmap((void *)(nsp_data.MmioAddress)); |
| 1839 |
CardServices(ReleaseWindow, link->win); |
| 1840 |
} |
| 1841 |
CardServices(ReleaseConfiguration, link->handle); |
| 1842 |
if (link->io.NumPorts1) { |
| 1843 |
CardServices(ReleaseIO, link->handle, &link->io); |
| 1844 |
} |
| 1845 |
if (link->irq.AssignedIRQ) { |
| 1846 |
CardServices(ReleaseIRQ, link->handle, &link->irq); |
| 1847 |
} |
| 1848 |
link->state &= ~DEV_CONFIG; |
| 1849 |
|
| 1850 |
if (link->state & DEV_STALE_LINK) { |
| 1851 |
nsp_cs_detach(link); |
| 1852 |
} |
| 1853 |
} /* nsp_cs_release */ |
| 1854 |
|
| 1855 |
/*====================================================================== |
| 1856 |
|
| 1857 |
The card status event handler. Mostly, this schedules other |
| 1858 |
stuff to run after an event is received. A CARD_REMOVAL event |
| 1859 |
also sets some flags to discourage the net drivers from trying |
| 1860 |
to talk to the card any more. |
| 1861 |
|
| 1862 |
When a CARD_REMOVAL event is received, we immediately set a flag |
| 1863 |
to block future accesses to this device. All the functions that |
| 1864 |
actually access the device should check this flag to make sure |
| 1865 |
the card is still present. |
| 1866 |
|
| 1867 |
======================================================================*/ |
| 1868 |
static int nsp_cs_event(event_t event, |
| 1869 |
int priority, |
| 1870 |
event_callback_args_t *args) |
| 1871 |
{ |
| 1872 |
dev_link_t *link = args->client_data; |
| 1873 |
scsi_info_t *info = link->priv; |
| 1874 |
Scsi_Cmnd tmp; |
| 1875 |
|
| 1876 |
DEBUG(1, "%s(0x%06x)\n", __FUNCTION__, event); |
| 1877 |
|
| 1878 |
switch (event) { |
| 1879 |
case CS_EVENT_CARD_REMOVAL: |
| 1880 |
DEBUG(0, " event: remove\n"); |
| 1881 |
link->state &= ~DEV_PRESENT; |
| 1882 |
if (link->state & DEV_CONFIG) { |
| 1883 |
((scsi_info_t *)link->priv)->stop = 1; |
| 1884 |
mod_timer(&link->release, jiffies + HZ/20); |
| 1885 |
} |
| 1886 |
break; |
| 1887 |
|
| 1888 |
case CS_EVENT_CARD_INSERTION: |
| 1889 |
DEBUG(0, " event: insert\n"); |
| 1890 |
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; |
| 1891 |
nsp_cs_config(link); |
| 1892 |
break; |
| 1893 |
|
| 1894 |
case CS_EVENT_PM_SUSPEND: |
| 1895 |
link->state |= DEV_SUSPEND; |
| 1896 |
/* Fall through... */ |
| 1897 |
case CS_EVENT_RESET_PHYSICAL: |
| 1898 |
/* Mark the device as stopped, to block IO until later */ |
| 1899 |
info->stop = 1; |
| 1900 |
if (link->state & DEV_CONFIG) { |
| 1901 |
CardServices(ReleaseConfiguration, link->handle); |
| 1902 |
} |
| 1903 |
break; |
| 1904 |
|
| 1905 |
case CS_EVENT_PM_RESUME: |
| 1906 |
link->state &= ~DEV_SUSPEND; |
| 1907 |
/* Fall through... */ |
| 1908 |
case CS_EVENT_CARD_RESET: |
| 1909 |
DEBUG(0, " event: reset\n"); |
| 1910 |
if (link->state & DEV_CONFIG) { |
| 1911 |
CardServices(RequestConfiguration, link->handle, &link->conf); |
| 1912 |
} |
| 1913 |
info->stop = 0; |
| 1914 |
|
| 1915 |
tmp.device->host = info->host; |
| 1916 |
nsp_eh_host_reset(&tmp); |
| 1917 |
nsp_eh_bus_reset(&tmp); |
| 1918 |
|
| 1919 |
break; |
| 1920 |
|
| 1921 |
default: |
| 1922 |
DEBUG(0, " event: unknown\n"); |
| 1923 |
break; |
| 1924 |
} |
| 1925 |
DEBUG(0, "%s: end\n", __FUNCTION__); |
| 1926 |
return 0; |
| 1927 |
} /* nsp_cs_event */ |
| 1928 |
|
| 1929 |
static struct pcmcia_driver nsp_driver = { |
| 1930 |
.owner = THIS_MODULE, |
| 1931 |
.drv = { |
| 1932 |
.name = "nsp_cs", |
| 1933 |
}, |
| 1934 |
.attach = nsp_cs_attach, |
| 1935 |
.detach = nsp_cs_detach, |
| 1936 |
}; |
| 1937 |
|
| 1938 |
static int __init nsp_cs_init(void) |
| 1939 |
{ |
| 1940 |
return pcmcia_register_driver(&nsp_driver); |
| 1941 |
} |
| 1942 |
|
| 1943 |
|
| 1944 |
static void __exit nsp_cs_exit(void) |
| 1945 |
{ |
| 1946 |
pcmcia_unregister_driver(&nsp_driver); |
| 1947 |
|
| 1948 |
/* XXX: this really needs to move into generic code.. */ |
| 1949 |
while (dev_list != NULL) { |
| 1950 |
if (dev_list->state & DEV_CONFIG) { |
| 1951 |
nsp_cs_release((u_long)dev_list); |
| 1952 |
} |
| 1953 |
nsp_cs_detach(dev_list); |
| 1954 |
} |
| 1955 |
} |
| 1956 |
|
| 1957 |
module_init(nsp_cs_init) |
| 1958 |
module_exit(nsp_cs_exit) |