permit multiline comments and strings in macros
[bpt/coccinelle.git] / demos / demo_rule9 / nsp_cs.res
1 /*======================================================================
2
3 NinjaSCSI-3 / NinjaSCSI-32Bi PCMCIA SCSI host adapter card driver
4 By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
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 <yokota@netlab.is.tsukuba.ac.jp>");
69 MODULE_DESCRIPTION("WorkBit NinjaSCSI-3 / NinjaSCSI-32Bi(16bit) PCMCIA SCSI host adapter module $Revision: 1.1 $");
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 occures 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 transferd
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 avilable ? */
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 availavle */
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 availavle */
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 synch 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 thru */
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: 1.1 $ 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(struct Scsi_Host *host, char *buffer,
1295 char **start,
1296 off_t offset,
1297 int length,
1298 int inout)
1299 {
1300 int id;
1301 char *pos = buffer;
1302 int thislength;
1303 int speed;
1304 unsigned long flags;
1305 nsp_hw_data *data = &nsp_data;
1306
1307 if (inout) {
1308 return -EINVAL;
1309 }
1310
1311 SPRINTF("NinjaSCSI status\n\n");
1312 SPRINTF("Driver version: $Revision: 1.1 $\n");
1313 SPRINTF("SCSI host No.: %d\n", host->host_no);
1314 SPRINTF("IRQ: %d\n", host->irq);
1315 SPRINTF("IO: 0x%lx-0x%lx\n", host->io_port, host->io_port + host->n_io_port - 1);
1316 SPRINTF("MMIO(virtual address): 0x%lx\n", host->base);
1317 SPRINTF("sg_tablesize: %d\n", host->sg_tablesize);
1318
1319 SPRINTF("burst transfer mode: ");
1320 switch (nsp_burst_mode) {
1321 case BURST_IO8:
1322 SPRINTF("io8");
1323 break;
1324 case BURST_IO32:
1325 SPRINTF("io32");
1326 break;
1327 case BURST_MEM32:
1328 SPRINTF("mem32");
1329 break;
1330 default:
1331 SPRINTF("???");
1332 break;
1333 }
1334 SPRINTF("\n");
1335
1336
1337 spin_lock_irqsave(&(data->Lock), flags);
1338 SPRINTF("CurrentSC: 0x%p\n\n", data->CurrentSC);
1339 spin_unlock_irqrestore(&(data->Lock), flags);
1340
1341 SPRINTF("SDTR status\n");
1342 for(id = 0; id < N_TARGET; id++) {
1343
1344 SPRINTF("id %d: ", id);
1345
1346 if (id == host->this_id) {
1347 SPRINTF("----- NinjaSCSI-3 host adapter\n");
1348 continue;
1349 }
1350
1351 switch(data->Sync[id].SyncNegotiation) {
1352 case SYNC_OK:
1353 SPRINTF(" sync");
1354 break;
1355 case SYNC_NG:
1356 SPRINTF("async");
1357 break;
1358 case SYNC_NOT_YET:
1359 SPRINTF(" none");
1360 break;
1361 default:
1362 SPRINTF("?????");
1363 break;
1364 }
1365
1366 if (data->Sync[id].SyncPeriod != 0) {
1367 speed = 1000000 / (data->Sync[id].SyncPeriod * 4);
1368
1369 SPRINTF(" transfer %d.%dMB/s, offset %d",
1370 speed / 1000,
1371 speed % 1000,
1372 data->Sync[id].SyncOffset
1373 );
1374 }
1375 SPRINTF("\n");
1376 }
1377
1378 thislength = pos - (buffer + offset);
1379
1380 if(thislength < 0) {
1381 *start = 0;
1382 return 0;
1383 }
1384
1385
1386 thislength = MIN(thislength, length);
1387 *start = buffer + offset;
1388
1389 return thislength;
1390 }
1391 #undef SPRINTF
1392
1393
1394 /*static int nsp_eh_strategy(struct Scsi_Host *Shost)
1395 {
1396 return FAILED;
1397 }*/
1398
1399 /*
1400 static int nsp_eh_abort(Scsi_Cmnd *SCpnt)
1401 {
1402 DEBUG(0, "%s: SCpnt=0x%p\n", __FUNCTION__, SCpnt);
1403
1404 return nsp_eh_bus_reset(SCpnt);
1405 }*/
1406
1407 /*
1408 static int nsp_eh_device_reset(Scsi_Cmnd *SCpnt)
1409 {
1410 DEBUG(0, "%s: SCpnt=0x%p\n", __FUNCTION__, SCpnt);
1411
1412 return FAILED;
1413 }*/
1414
1415 static int nsp_eh_bus_reset(Scsi_Cmnd *SCpnt)
1416 {
1417 nsp_hw_data *data = &nsp_data;
1418 unsigned int base = SCpnt->device->host->io_port;
1419 int i;
1420
1421 DEBUG(0, "%s: SCpnt=0x%p base=0x%x\n", __FUNCTION__, SCpnt, base);
1422
1423 nsp_write(base, IRQCONTROL, IRQCONTROL_ALLMASK);
1424
1425 nsp_index_write(base, SCSIBUSCTRL, SCSI_RST);
1426 mdelay(100); /* 100ms */
1427 nsp_index_write(base, SCSIBUSCTRL, 0);
1428 for(i = 0; i < 5; i++) {
1429 nsp_index_read(base, IRQPHASESENCE); /* dummy read */
1430 }
1431
1432 nsp_write(base, IRQCONTROL, IRQCONTROL_ALLCLEAR);
1433
1434 nsphw_init_sync(data);
1435
1436 return SUCCESS;
1437 }
1438
1439 static int nsp_eh_host_reset(Scsi_Cmnd *SCpnt)
1440 {
1441 nsp_hw_data *data = &nsp_data;
1442
1443 DEBUG(0, "%s:\n", __FUNCTION__);
1444
1445 nsphw_init(data);
1446
1447 return SUCCESS;
1448 }
1449
1450
1451 /**********************************************************************
1452 PCMCIA functions
1453 **********************************************************************/
1454
1455 /*======================================================================
1456 nsp_cs_attach() creates an "instance" of the driver, allocating
1457 local data structures for one device. The device is registered
1458 with Card Services.
1459
1460 The dev_link structure is initialized, but we don't actually
1461 configure the card at this point -- we wait until we receive a
1462 card insertion event.
1463 ======================================================================*/
1464 static dev_link_t *nsp_cs_attach(void)
1465 {
1466 scsi_info_t *info;
1467 client_reg_t client_reg;
1468 dev_link_t *link;
1469 int ret, i;
1470
1471 DEBUG(0, "%s:\n", __FUNCTION__);
1472
1473 /* Create new SCSI device */
1474 info = kmalloc(sizeof(*info), GFP_KERNEL);
1475 if (!info) { return NULL; }
1476 memset(info, 0, sizeof(*info));
1477 link = &info->link;
1478 link->priv = info;
1479
1480 /* Initialize the dev_link_t structure */
1481 link->release.function = &nsp_cs_release;
1482 link->release.data = (u_long)link;
1483
1484 /* The io structure describes IO port mapping */
1485 link->io.NumPorts1 = 0x10;
1486 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
1487 link->io.IOAddrLines = 10; /* not used */
1488
1489 /* Interrupt setup */
1490 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
1491 link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
1492 if (irq_list[0] == -1) {
1493 link->irq.IRQInfo2 = irq_mask;
1494 } else {
1495 for (i = 0; i < 4; i++) {
1496 link->irq.IRQInfo2 |= 1 << irq_list[i];
1497 }
1498 }
1499
1500 /* IRQ \e$B$N3NJ]$O$3$3$G\e(B PCMCIA \e$B$N4X?t$rMQ$$$F9T$J$&$N$G\e(B
1501 * host->hostdata \e$B$r\e(B irq.Instance \e$B$KBeF~$G$-$J$$!#\e(B
1502 * host->hostdata \e$B$,;H$($l$PJ#?t$N\e(B NinjaSCSI \e$B$,\e(B
1503 * \e$B;HMQ$G$-$k$N$@$,!#\e(B
1504 */
1505 link->irq.Handler = &nspintr;
1506 link->irq.Instance = &nsp_data;
1507 link->irq.Attributes |= (SA_SHIRQ | SA_SAMPLE_RANDOM);
1508
1509 /* General socket configuration */
1510 link->conf.Attributes = CONF_ENABLE_IRQ;
1511 link->conf.Vcc = 50;
1512 link->conf.IntType = INT_MEMORY_AND_IO;
1513 link->conf.Present = PRESENT_OPTION;
1514
1515
1516 /* Register with Card Services */
1517 link->next = dev_list;
1518 dev_list = link;
1519 client_reg.dev_info = &dev_info;
1520 client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
1521 client_reg.EventMask =
1522 CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
1523 CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
1524 CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME ;
1525 client_reg.event_handler = &nsp_cs_event;
1526 client_reg.Version = 0x0210;
1527 client_reg.event_callback_args.client_data = link;
1528 ret = CardServices(RegisterClient, &link->handle, &client_reg);
1529 if (ret != CS_SUCCESS) {
1530 cs_error(link->handle, RegisterClient, ret);
1531 nsp_cs_detach(link);
1532 return NULL;
1533 }
1534
1535 return link;
1536 } /* nsp_cs_attach */
1537
1538
1539 /*======================================================================
1540 This deletes a driver "instance". The device is de-registered
1541 with Card Services. If it has been released, all local data
1542 structures are freed. Otherwise, the structures will be freed
1543 when the device is released.
1544 ======================================================================*/
1545 static void nsp_cs_detach(dev_link_t *link)
1546 {
1547 dev_link_t **linkp;
1548
1549 DEBUG(0, "%s(0x%p)\n", __FUNCTION__, link);
1550
1551 /* Locate device structure */
1552 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) {
1553 if (*linkp == link) {
1554 break;
1555 }
1556 }
1557 if (*linkp == NULL) {
1558 return;
1559 }
1560
1561 del_timer(&link->release);
1562 if (link->state & DEV_CONFIG) {
1563 nsp_cs_release((u_long)link);
1564 if (link->state & DEV_STALE_CONFIG) {
1565 link->state |= DEV_STALE_LINK;
1566 return;
1567 }
1568 }
1569
1570 /* Break the link with Card Services */
1571 if (link->handle) {
1572 CardServices(DeregisterClient, link->handle);
1573 }
1574
1575 /* Unlink device structure, free bits */
1576 *linkp = link->next;
1577 kfree(link->priv);
1578 link->priv = NULL;
1579
1580 } /* nsp_cs_detach */
1581
1582
1583 /*======================================================================
1584 nsp_cs_config() is scheduled to run after a CARD_INSERTION event
1585 is received, to configure the PCMCIA socket, and to make the
1586 ethernet device available to the system.
1587 ======================================================================*/
1588 #define CS_CHECK(fn, args...) \
1589 while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
1590 #define CFG_CHECK(fn, args...) \
1591 if (CardServices(fn, args) != 0) goto next_entry
1592 /*====================================================================*/
1593
1594 static void nsp_cs_config(dev_link_t *link)
1595 {
1596 client_handle_t handle = link->handle;
1597 scsi_info_t *info = link->priv;
1598 tuple_t tuple;
1599 cisparse_t parse;
1600 int last_ret, last_fn;
1601 u_char tuple_data[64];
1602 config_info_t conf;
1603 win_req_t req;
1604 memreq_t map;
1605 cistpl_cftable_entry_t dflt = { 0 };
1606
1607 struct Scsi_Host *host;
1608 nsp_hw_data *data = &nsp_data;
1609
1610
1611 DEBUG(0, "%s: in\n", __FUNCTION__);
1612
1613 tuple.DesiredTuple = CISTPL_CONFIG;
1614 tuple.Attributes = 0;
1615 tuple.TupleData = tuple_data;
1616 tuple.TupleDataMax = sizeof(tuple_data);
1617 tuple.TupleOffset = 0;
1618 CS_CHECK(GetFirstTuple, handle, &tuple);
1619 CS_CHECK(GetTupleData, handle, &tuple);
1620 CS_CHECK(ParseTuple, handle, &tuple, &parse);
1621 link->conf.ConfigBase = parse.config.base;
1622 link->conf.Present = parse.config.rmask[0];
1623
1624 /* Configure card */
1625 link->state |= DEV_CONFIG;
1626
1627 /* Look up the current Vcc */
1628 CS_CHECK(GetConfigurationInfo, handle, &conf);
1629 link->conf.Vcc = conf.Vcc;
1630
1631 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1632 CS_CHECK(GetFirstTuple, handle, &tuple);
1633 while (1) {
1634 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
1635
1636 CFG_CHECK(GetTupleData, handle, &tuple);
1637 CFG_CHECK(ParseTuple, handle, &tuple, &parse);
1638
1639 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; }
1640 if (cfg->index == 0) { goto next_entry; }
1641 link->conf.ConfigIndex = cfg->index;
1642
1643 /* Does this card need audio output? */
1644 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
1645 link->conf.Attributes |= CONF_ENABLE_SPKR;
1646 link->conf.Status = CCSR_AUDIO_ENA;
1647 }
1648
1649 /* Use power settings for Vcc and Vpp if present */
1650 /* Note that the CIS values need to be rescaled */
1651 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
1652 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000) {
1653 goto next_entry;
1654 }
1655 } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
1656 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000) {
1657 goto next_entry;
1658 }
1659 }
1660
1661 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) {
1662 link->conf.Vpp1 = link->conf.Vpp2 =
1663 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
1664 } else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) {
1665 link->conf.Vpp1 = link->conf.Vpp2 =
1666 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
1667 }
1668
1669 /* Do we need to allocate an interrupt? */
1670 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) {
1671 link->conf.Attributes |= CONF_ENABLE_IRQ;
1672 }
1673
1674 /* IO window settings */
1675 link->io.NumPorts1 = link->io.NumPorts2 = 0;
1676 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
1677 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
1678 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
1679 if (!(io->flags & CISTPL_IO_8BIT))
1680 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
1681 if (!(io->flags & CISTPL_IO_16BIT))
1682 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1683 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
1684 link->io.BasePort1 = io->win[0].base;
1685 link->io.NumPorts1 = io->win[0].len;
1686 if (io->nwin > 1) {
1687 link->io.Attributes2 = link->io.Attributes1;
1688 link->io.BasePort2 = io->win[1].base;
1689 link->io.NumPorts2 = io->win[1].len;
1690 }
1691 /* This reserves IO space but doesn't actually enable it */
1692 CFG_CHECK(RequestIO, link->handle, &link->io);
1693 }
1694
1695 if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
1696 cistpl_mem_t *mem =
1697 (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
1698 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
1699 req.Attributes |= WIN_ENABLE;
1700 req.Base = mem->win[0].host_addr;
1701 req.Size = mem->win[0].len;
1702 if (req.Size < 0x1000)
1703 req.Size = 0x1000;
1704 req.AccessSpeed = 0;
1705 link->win = (window_handle_t)link->handle;
1706 CFG_CHECK(RequestWindow, &link->win, &req);
1707 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
1708 CFG_CHECK(MapMemPage, link->win, &map);
1709
1710 data->MmioAddress = (u_long)ioremap_nocache(req.Base, req.Size);
1711 }
1712 /* If we got this far, we're cool! */
1713 break;
1714
1715 next_entry:
1716 DEBUG(0, "%s: next\n", __FUNCTION__);
1717
1718 if (link->io.NumPorts1)
1719 CardServices(ReleaseIO, link->handle, &link->io);
1720 CS_CHECK(GetNextTuple, handle, &tuple);
1721 }
1722
1723 if (link->conf.Attributes & CONF_ENABLE_IRQ)
1724 CS_CHECK(RequestIRQ, link->handle, &link->irq);
1725 CS_CHECK(RequestConfiguration, handle, &link->conf);
1726
1727 if (free_ports) {
1728 if (link->io.BasePort1)
1729 release_region(link->io.BasePort1, link->io.NumPorts1);
1730 if (link->io.BasePort2)
1731 release_region(link->io.BasePort2, link->io.NumPorts2);
1732 }
1733
1734 /* Set port and IRQ */
1735 data->BaseAddress = link->io.BasePort1;
1736 data->NumAddress = link->io.NumPorts1;
1737 data->IrqNumber = link->irq.AssignedIRQ;
1738
1739 DEBUG(0, "%s: I/O[0x%x+0x%x] IRQ %d\n",
1740 __FUNCTION__, data->BaseAddress, data->NumAddress, data->IrqNumber);
1741
1742 if(nsphw_init(data) == FALSE) {
1743 goto cs_failed;
1744 }
1745
1746 host = __nsp_detect(&nsp_driver_template);
1747 if (!host)
1748 goto cs_failed;
1749
1750 sprintf(info->node.dev_name, "scsi%d", host->host_no);
1751 link->dev = &info->node;
1752 info->host = host;
1753
1754 /* Finally, report what we've done */
1755 printk(KERN_INFO "nsp_cs: index 0x%02x: Vcc %d.%d",
1756 link->conf.ConfigIndex,
1757 link->conf.Vcc/10, link->conf.Vcc%10);
1758 if (link->conf.Vpp1) {
1759 printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
1760 }
1761 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1762 printk(", irq %d", link->irq.AssignedIRQ);
1763 }
1764 if (link->io.NumPorts1) {
1765 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
1766 link->io.BasePort1+link->io.NumPorts1-1);
1767 }
1768 if (link->io.NumPorts2)
1769 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
1770 link->io.BasePort2+link->io.NumPorts2-1);
1771 if (link->win)
1772 printk(", mem 0x%06lx-0x%06lx", req.Base,
1773 req.Base+req.Size-1);
1774 printk("\n");
1775
1776 scsi_add_host(host, NULL);
1777 link->state &= ~DEV_CONFIG_PENDING;
1778 return;
1779
1780 cs_failed:
1781 cs_error(link->handle, last_fn, last_ret);
1782 nsp_cs_release((u_long)link);
1783 return;
1784
1785 } /* nsp_cs_config */
1786 #undef CS_CHECK
1787 #undef CFG_CHECK
1788
1789 /*======================================================================
1790 After a card is removed, nsp_cs_release() will unregister the net
1791 device, and release the PCMCIA configuration. If the device is
1792 still open, this will be postponed until it is closed.
1793 ======================================================================*/
1794 static void nsp_cs_release(u_long arg)
1795 {
1796 dev_link_t *link = (dev_link_t *)arg;
1797 scsi_info_t *info = link->priv;
1798
1799 DEBUG(0, "%s(0x%p)\n", __FUNCTION__, link);
1800
1801 /*
1802 * If the device is currently in use, we won't release until it
1803 * is actually closed.
1804 */
1805 if (link->open) {
1806 DEBUG(1, "nsp_cs: release postponed, '%s' still open\n",
1807 link->dev->dev_name);
1808 link->state |= DEV_STALE_CONFIG;
1809 return;
1810 }
1811
1812 /* Unlink the device chain */
1813 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,2))
1814 scsi_unregister_module(MODULE_SCSI_HA, &nsp_driver_template);
1815 #else
1816 scsi_remove_host(info->host);
1817 scsi_unregister(info->host);
1818 #endif
1819 link->dev = NULL;
1820
1821 if (link->win) {
1822 iounmap((void *)(nsp_data.MmioAddress));
1823 CardServices(ReleaseWindow, link->win);
1824 }
1825 CardServices(ReleaseConfiguration, link->handle);
1826 if (link->io.NumPorts1) {
1827 CardServices(ReleaseIO, link->handle, &link->io);
1828 }
1829 if (link->irq.AssignedIRQ) {
1830 CardServices(ReleaseIRQ, link->handle, &link->irq);
1831 }
1832 link->state &= ~DEV_CONFIG;
1833
1834 if (link->state & DEV_STALE_LINK) {
1835 nsp_cs_detach(link);
1836 }
1837 } /* nsp_cs_release */
1838
1839 /*======================================================================
1840
1841 The card status event handler. Mostly, this schedules other
1842 stuff to run after an event is received. A CARD_REMOVAL event
1843 also sets some flags to discourage the net drivers from trying
1844 to talk to the card any more.
1845
1846 When a CARD_REMOVAL event is received, we immediately set a flag
1847 to block future accesses to this device. All the functions that
1848 actually access the device should check this flag to make sure
1849 the card is still present.
1850
1851 ======================================================================*/
1852 static int nsp_cs_event(event_t event,
1853 int priority,
1854 event_callback_args_t *args)
1855 {
1856 dev_link_t *link = args->client_data;
1857 scsi_info_t *info = link->priv;
1858 Scsi_Cmnd tmp;
1859
1860 DEBUG(1, "%s(0x%06x)\n", __FUNCTION__, event);
1861
1862 switch (event) {
1863 case CS_EVENT_CARD_REMOVAL:
1864 DEBUG(0, " event: remove\n");
1865 link->state &= ~DEV_PRESENT;
1866 if (link->state & DEV_CONFIG) {
1867 ((scsi_info_t *)link->priv)->stop = 1;
1868 mod_timer(&link->release, jiffies + HZ/20);
1869 }
1870 break;
1871
1872 case CS_EVENT_CARD_INSERTION:
1873 DEBUG(0, " event: insert\n");
1874 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
1875 nsp_cs_config(link);
1876 break;
1877
1878 case CS_EVENT_PM_SUSPEND:
1879 link->state |= DEV_SUSPEND;
1880 /* Fall through... */
1881 case CS_EVENT_RESET_PHYSICAL:
1882 /* Mark the device as stopped, to block IO until later */
1883 info->stop = 1;
1884 if (link->state & DEV_CONFIG) {
1885 CardServices(ReleaseConfiguration, link->handle);
1886 }
1887 break;
1888
1889 case CS_EVENT_PM_RESUME:
1890 link->state &= ~DEV_SUSPEND;
1891 /* Fall through... */
1892 case CS_EVENT_CARD_RESET:
1893 DEBUG(0, " event: reset\n");
1894 if (link->state & DEV_CONFIG) {
1895 CardServices(RequestConfiguration, link->handle, &link->conf);
1896 }
1897 info->stop = 0;
1898
1899 tmp.device->host = info->host;
1900 nsp_eh_host_reset(&tmp);
1901 nsp_eh_bus_reset(&tmp);
1902
1903 break;
1904
1905 default:
1906 DEBUG(0, " event: unknown\n");
1907 break;
1908 }
1909 DEBUG(0, "%s: end\n", __FUNCTION__);
1910 return 0;
1911 } /* nsp_cs_event */
1912
1913 static struct pcmcia_driver nsp_driver = {
1914 .owner = THIS_MODULE,
1915 .drv = {
1916 .name = "nsp_cs",
1917 },
1918 .attach = nsp_cs_attach,
1919 .detach = nsp_cs_detach,
1920 };
1921
1922 static int __init nsp_cs_init(void)
1923 {
1924 return pcmcia_register_driver(&nsp_driver);
1925 }
1926
1927
1928 static void __exit nsp_cs_exit(void)
1929 {
1930 pcmcia_unregister_driver(&nsp_driver);
1931
1932 /* XXX: this really needs to move into generic code.. */
1933 while (dev_list != NULL) {
1934 if (dev_list->state & DEV_CONFIG) {
1935 nsp_cs_release((u_long)dev_list);
1936 }
1937 nsp_cs_detach(dev_list);
1938 }
1939 }
1940
1941 module_init(nsp_cs_init)
1942 module_exit(nsp_cs_exit)