49 #include <linux/module.h>
52 #include <linux/ctype.h>
57 #include <linux/pci.h>
58 #include <linux/list.h>
60 #include <linux/slab.h>
63 #include <scsi/scsi.h>
71 #define DC395X_NAME "dc395x"
72 #define DC395X_BANNER "Tekram DC395(U/UW/F), DC315(U) - ASIC TRM-S1040"
73 #define DC395X_VERSION "v2.05, 2004/03/08"
96 #define DBG_FIFO 0x0040
97 #define DBG_PIO 0x0080
112 #define dprintkl(level, format, arg...) \
113 printk(level DC395X_NAME ": " format , ## arg)
123 #define dprintkdbg(type, format, arg...) \
125 if ((type) & (DEBUG_MASK)) \
126 dprintkl(KERN_DEBUG , format , ## arg); \
132 #define debug_enabled(type) ((DEBUG_MASK) & (type))
138 #define dprintkdbg(type, format, arg...) \
140 #define debug_enabled(type) (0)
145 #ifndef PCI_VENDOR_ID_TEKRAM
146 #define PCI_VENDOR_ID_TEKRAM 0x1DE1
148 #ifndef PCI_DEVICE_ID_TEKRAM_TRMS1040
149 #define PCI_DEVICE_ID_TEKRAM_TRMS1040 0x0391
153 #define DC395x_LOCK_IO(dev,flags) spin_lock_irqsave(((struct Scsi_Host *)dev)->host_lock, flags)
154 #define DC395x_UNLOCK_IO(dev,flags) spin_unlock_irqrestore(((struct Scsi_Host *)dev)->host_lock, flags)
156 #define DC395x_read8(acb,address) (u8)(inb(acb->io_port_base + (address)))
157 #define DC395x_read16(acb,address) (u16)(inw(acb->io_port_base + (address)))
158 #define DC395x_read32(acb,address) (u32)(inl(acb->io_port_base + (address)))
159 #define DC395x_write8(acb,address,value) outb((value), acb->io_port_base + (address))
160 #define DC395x_write16(acb,address,value) outw((value), acb->io_port_base + (address))
161 #define DC395x_write32(acb,address,value) outl((value), acb->io_port_base + (address))
164 #define RES_TARGET 0x000000FF
165 #define RES_TARGET_LNX STATUS_MASK
166 #define RES_ENDMSG 0x0000FF00
167 #define RES_DID 0x00FF0000
168 #define RES_DRV 0xFF000000
170 #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
171 #define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)<<1)
173 #define SET_RES_TARGET(who,tgt) { who &= ~RES_TARGET; who |= (int)(tgt); }
174 #define SET_RES_TARGET_LNX(who,tgt) { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; }
175 #define SET_RES_MSG(who,msg) { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; }
176 #define SET_RES_DID(who,did) { who &= ~RES_DID; who |= (int)(did) << 16; }
177 #define SET_RES_DRV(who,drv) { who &= ~RES_DRV; who |= (int)(drv) << 24; }
186 #define SEGMENTX_LEN (sizeof(struct SGentry)*DC395x_MAX_SG_LISTENTRY)
396 static void waiting_timeout(
unsigned long ptr);
402 static u16 current_sync_offset = 0;
404 static void *dc395x_scsi_phase0[] = {
415 static void *dc395x_scsi_phase1[] = {
448 static u8 clock_period[] = { 12, 18, 25, 31, 37, 43, 50, 62 };
449 static u16 clock_speed[] = { 200, 133, 100, 80, 67, 58, 50, 40 };
465 #define CFG_ADAPTER_ID 0
466 #define CFG_MAX_SPEED 1
467 #define CFG_DEV_MODE 2
468 #define CFG_ADAPTER_MODE 3
470 #define CFG_RESET_DELAY 5
479 #define CFG_PARAM_UNSET -1
520 #ifdef CONFIG_SCSI_MULTI_LUN
549 static bool use_safe_settings = 0;
558 MODULE_PARM_DESC(max_speed,
"Maximum bus speed. Default 1 (0-7) Speeds: 0=20, 1=13.3, 2=10, 3=8, 4=6.7, 5=5.8, 6=5, 7=4 Mhz");
577 static void __devinit set_safe_settings(
void)
579 if (use_safe_settings)
601 "setup: AdapterId=%08x MaxSpeed=%08x DevMode=%08x "
602 "AdapterMode=%08x Tags=%08x ResetDelay=%08x\n",
611 if (cfg_data[i].
value < cfg_data[i].
min
612 || cfg_data[i].
value > cfg_data[i].
max)
624 { 1, 3, 5, 10, 16, 30, 60, 120 };
649 while (idx < 7 && eeprom_index_to_delay_map[idx] < delay)
699 unsigned int count = 0;
714 if (list_empty(head))
722 }
else if (i == pos) {
759 struct list_head *head = &acb->srb_free_list;
762 if (!list_empty(head)) {
778 static void srb_waiting_insert(
struct DeviceCtlBlk *dcb,
787 static void srb_waiting_append(
struct DeviceCtlBlk *dcb,
819 static void srb_waiting_remove(
struct DeviceCtlBlk *dcb,
835 static void srb_going_to_waiting_move(
struct DeviceCtlBlk *dcb,
839 "srb_going_to_waiting_move: (0x%p) <%02i-%i> srb=%p\n",
845 static void srb_waiting_to_going_move(
struct DeviceCtlBlk *dcb,
849 "srb_waiting_to_going_move: (0x%p) <%02i-%i> srb=%p\n",
856 static void waiting_set_timer(
struct AdapterCtlBlk *acb,
unsigned long to)
888 if (list_empty(dcb_list_head))
896 if (dcb == acb->dcb_run_robin) {
919 if (list_empty(waiting_list_head) ||
922 pos = dcb_get_next(dcb_list_head, pos);
928 if (!start_scsi(acb, pos, srb))
929 srb_waiting_to_going_move(pos, srb);
931 waiting_set_timer(acb,
HZ/50);
934 }
while (pos != start);
939 static void waiting_timeout(
unsigned long ptr)
944 "waiting_timeout: Queue woken up by timer. acb=%p\n", acb);
946 waiting_process_next(acb);
966 srb_waiting_append(dcb, srb);
967 waiting_process_next(acb);
971 if (!start_scsi(acb, dcb, srb))
972 srb_going_append(dcb, srb);
974 srb_waiting_insert(dcb, srb);
975 waiting_set_timer(acb,
HZ / 50);
1010 "build_srb: [0] len=%d buf=%p use_sg=%d !MAP=%08x\n",
1011 cmd->bufflen, scsi_sglist(cmd), scsi_sg_count(cmd),
1015 u32 reqlen = scsi_bufflen(cmd);
1022 "build_srb: [n] len=%d buf=%p use_sg=%d segs=%d\n",
1023 reqlen, scsi_sglist(cmd), scsi_sg_count(cmd),
1110 dcb = find_dcb(acb, cmd->
device->id, cmd->
device->lun);
1122 srb = srb_get_free(acb);
1133 build_srb(cmd, dcb, srb);
1137 srb_waiting_append(dcb, srb);
1138 waiting_process_next(acb);
1165 #ifdef CONFIG_SCSI_DC395x_TRMS1040_TRADMAP
1174 cylinders = size / (heads * sectors);
1179 cylinders = size / (heads *
sectors);
1196 pci_read_config_word(dev,
PCI_STATUS, &pstat);
1207 "cmnd=0x%02x <%02i-%i>\n",
1209 srb->
cmd->cmnd[0], srb->
cmd->device->id,
1210 srb->
cmd->device->lun);
1211 printk(
" sglist=%p cnt=%i idx=%i len=%zu\n",
1214 printk(
" state=0x%04x status=0x%02x phase=0x%02x (%sconn.)\n",
1219 "signals=0x%02x irqstat=0x%02x sync=0x%02x target=0x%02x "
1220 "rselid=0x%02x ctr=0x%08x irqen=0x%02x config=0x%04x "
1221 "config2=0x%02x cmd=0x%02x selto=0x%02x}\n",
1236 "irqstat=0x%02x irqen=0x%02x cfg=0x%04x tctr=0x%08x "
1237 "ctctr=0x%08x addr=0x%08x:0x%08x}\n",
1249 "pci{status=0x%04x}\n",
1257 static inline void clear_fifo(
struct AdapterCtlBlk *acb,
char *txt)
1259 #if debug_enabled(DBG_FIFO)
1262 if (!(fifocnt & 0x40))
1264 "clear_fifo: (%i bytes) on phase %02x in %s\n",
1265 fifocnt & 0x3f, lines, txt);
1299 static int __dc395x_eh_bus_reset(
struct scsi_cmnd *cmd)
1304 "eh_bus_reset: (0%p) target=<%02i-%i> cmd=%p\n",
1318 reset_scsi_bus(acb);
1331 clear_fifo(acb,
"eh_bus_reset");
1334 set_basic_config(acb);
1336 reset_dev_param(acb);
1340 waiting_process_next(acb);
1345 static int dc395x_eh_bus_reset(
struct scsi_cmnd *cmd)
1349 spin_lock_irq(cmd->
device->host->host_lock);
1350 rc = __dc395x_eh_bus_reset(cmd);
1351 spin_unlock_irq(cmd->
device->host->host_lock);
1361 static int dc395x_eh_abort(
struct scsi_cmnd *cmd)
1374 dcb = find_dcb(acb, cmd->
device->id, cmd->
device->lun);
1382 srb_waiting_remove(dcb, srb);
1383 pci_unmap_srb_sense(acb, srb);
1384 pci_unmap_srb(acb, srb);
1386 srb_free_insert(acb, srb);
1409 "build_sdtr: msgout_buf BUSY (%i: %02x %02x)\n",
1439 "build_wdtr: msgout_buf BUSY (%i: %02x %02x)\n",
1456 void selection_timeout_missed(
unsigned long ptr);
1462 acb->
selto_timer.function = selection_timeout_missed;
1474 void selection_timeout_missed(
unsigned long ptr)
1476 unsigned long flags;
1496 u8 s_stat, scsicommand,
i, identify_message;
1507 if (s_stat & 0x20 ) {
1526 "command while another command (0x%p) is active.",
1544 clear_fifo(acb,
"start_scsi");
1555 identify_message &= 0xBF;
1572 build_wdtr(acb, dcb, srb);
1578 build_sdtr(acb, dcb, srb);
1583 build_wdtr(acb, dcb, srb);
1593 #ifndef DC395x_NO_TAGQ
1595 && (identify_message & 0xC0)) {
1600 && tag_number < dcb->max_command) {
1601 tag_mask = tag_mask << 1;
1606 "Out of tags target=<%02i-%i>)\n",
1607 srb->
cmd, srb->
cmd->device->id,
1608 srb->
cmd->device->lun);
1626 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun,
1636 ptr = (
u8 *)srb->
cmd->cmnd;
1637 for (i = 0; i < srb->
cmd->cmd_len; i++)
1675 #define DC395x_ENABLE_MSGOUT \
1676 DC395x_write16 (acb, TRM_S1040_SCSI_CONTROL, DO_SETATN); \
1677 srb->state |= SRB_MSGOUT
1681 static inline void enable_msgout_abort(
struct AdapterCtlBlk *acb,
1699 static void dc395x_handle_interrupt(
struct AdapterCtlBlk *acb,
1706 unsigned long flags;
1714 if ((scsi_status & 0x2007) == 0x2002)
1716 "COP after COP completed? %04x\n", scsi_status);
1739 scsi_reset_detect(acb);
1746 "Oops: BusService (%04x %02x) w/o ActiveDCB!\n",
1747 scsi_status, scsi_intstatus);
1753 enable_msgout_abort(acb, srb);
1772 dc395x_statev = dc395x_scsi_phase0[phase];
1773 dc395x_statev(acb, srb, &scsi_status);
1781 phase = (
u16)scsi_status & PHASEMASK;
1795 dc395x_statev = dc395x_scsi_phase1[
phase];
1796 dc395x_statev(acb, srb, &scsi_status);
1815 if (scsi_status & SCSIINTERRUPT) {
1817 dc395x_handle_interrupt(acb, scsi_status);
1820 else if (dma_status & 0x20) {
1828 enable_msgout_abort(acb, acb->
active_dcb->active_srb);
1861 clear_fifo(acb,
"msgout_phase1");
1865 "msgout_phase1: (0x%p) Phase unexpected\n",
1903 clear_fifo(acb,
"command_phase1");
1906 ptr = (
u8 *)srb->
cmd->cmnd;
1907 for (i = 0; i < srb->
cmd->cmd_len; i++) {
1933 static void sg_verify_length(
struct ScsiReqBlk *srb)
1939 for (; idx < srb->
sg_count; psge++, idx++)
1943 "Inconsistent SRB S/G lengths (Tot=%i, Count=%i) !!\n",
1960 "sg_update_list: Transferred %i of %i bytes, %i remain\n",
1967 sg_verify_length(srb);
1970 if (xferred >= psge->
length) {
1978 pci_dma_sync_single_for_device(srb->
dcb->
1987 sg_verify_length(srb);
1997 static void sg_subtract_one(
struct ScsiReqBlk *srb)
2011 static void cleanup_after_transfer(
struct AdapterCtlBlk *acb,
2017 clear_fifo(acb,
"cleanup/in");
2024 clear_fifo(acb,
"cleanup/out");
2034 #define DC395x_LASTPIO 4
2041 u16 scsi_status = *pscsi_status;
2042 u32 d_left_counter = 0;
2044 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun);
2059 "DMA{fifocnt=0x%02x fifostat=0x%02x} "
2060 "SCSI{fifocnt=0x%02x cnt=0x%06x status=0x%04x} total=0x%06x\n",
2087 d_left_counter <<= 1;
2090 "SCSI{fifocnt=0x%02x cnt=0x%08x} "
2091 "DMA{fifocnt=0x%04x cnt=0x%02x ctr=0x%08x}\n",
2117 && scsi_bufflen(srb->
cmd) % 2) {
2120 "data_out_phase0: Discard 1 byte (0x%02x)\n",
2133 if (d_left_counter == 0) {
2145 sg_update_list(srb, d_left_counter);
2148 diff && scsi_sg_count(srb->
cmd))
2153 "Work around chip bug (%i)?\n", diff);
2156 sg_update_list(srb, d_left_counter);
2165 cleanup_after_transfer(acb, srb);
2174 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun);
2175 clear_fifo(acb,
"data_out_phase1");
2183 u16 scsi_status = *pscsi_status;
2186 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun);
2203 unsigned int sc,
fc;
2207 "Parity Error\n", srb->
cmd);
2220 "DIP0: Wait for DMA FIFO to flush ...\n");
2227 if (ctr < 6000000 - 1)
2229 "DIP0: Had to wait for DMA ...\n");
2232 "Deadlock in DIP0 waiting for DMA FIFO empty!!\n");
2236 "DMA{fifocnt=0x%02x fifostat=0x%02x}\n",
2243 d_left_counter = sc + ((fc & 0x1f)
2247 "SCSI{fifocnt=0x%02x%s ctr=0x%08x} "
2248 "DMA{fifocnt=0x%02x fifostat=0x%02x ctr=0x%08x} "
2249 "Remain{totxfer=%i scsi_fifo+ctr=%i}\n",
2251 (srb->
dcb->sync_period &
WIDE_SYNC) ?
"words" :
"bytes",
2266 "for remaining %i bytes:",
2276 unsigned long flags = 0;
2277 size_t len = left_io;
2298 sg_subtract_one(srb);
2310 WARN_ON((fc != 0x40) == !d_left_counter);
2312 if (fc == 0x40 && (srb->
dcb->sync_period &
WIDE_SYNC)) {
2350 d_left_counter <<= 1;
2359 if (d_left_counter == 0
2367 }
while (!(TempDMAstatus &
DMAXFERCOMP) && --ctr);
2370 "Deadlock in DataInPhase0 waiting for DMA!!\n");
2383 sg_update_list(srb, d_left_counter);
2388 cleanup_after_transfer(acb, srb);
2397 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun);
2408 "data_io_transfer: (0x%p) <%02i-%i> %c len=%i, sg=(%i/%i)\n",
2409 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun,
2427 "Expect trouble!\n");
2428 dump_register_info(acb, dcb, srb);
2438 if (scsi_sg_count(srb->
cmd)) {
2493 unsigned char *virt, *base =
NULL;
2494 unsigned long flags = 0;
2495 size_t len = left_io;
2512 sg_subtract_one(srb);
2549 if (io_dir & DMACMD_DIR) {
2564 if (io_dir & DMACMD_DIR)
2582 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun);
2596 srb->
cmd, srb->
cmd->device->id, srb->
cmd->device->lun);
2609 if (len < msgbuf[1] + 2)
2611 }
else if (*msgbuf >= 0x20 && *msgbuf <= 0x2f)
2628 srb->
dcb->target_id, srb->
dcb->target_lun);
2638 srb->
cmd, tag, srb);
2642 "msgin_qtag: tag_mask=0x%08x does not reserve tag %i!\n",
2657 srb->
cmd, srb->
dcb->target_id, srb->
dcb->target_lun);
2660 enable_msgout_abort(acb, srb);
2685 static inline void reprogram_regs(
struct AdapterCtlBlk *acb,
2691 set_xfer_rate(acb, dcb);
2708 reprogram_regs(acb, dcb);
2711 build_wdtr(acb, dcb, srb);
2725 "(%02i.%01i MHz) Offset %i\n",
2742 while (bval < 7 && (srb->
msgin_buf[3] > clock_period[bval]
2744 clock_period[bval]))
2746 if (srb->
msgin_buf[3] < clock_period[bval])
2748 "msgin_set_sync: Increase sync nego period to %ins\n",
2749 clock_period[bval] << 2);
2761 "Target %02i: %s Sync: %ins Offset %i (%02i.%01i MB/s)\n",
2762 dcb->
target_id, (fact == 500) ?
"Wide16" :
"",
2780 build_wdtr(acb, dcb, srb);
2788 reprogram_regs(acb, dcb);
2792 static inline void msgin_set_nowide(
struct AdapterCtlBlk *acb,
2802 reprogram_regs(acb, dcb);
2805 build_sdtr(acb, dcb, srb);
2823 "msgin_set_wide: Wide nego initiated <%02i>\n",
2839 "msgin_set_wide: Wide (%i bit) negotiated <%02i>\n",
2841 reprogram_regs(acb, dcb);
2844 build_sdtr(acb, dcb, srb);
2881 msgin_qtag(acb, dcb,
2890 msgin_set_async(acb, srb);
2895 msgin_set_nowide(acb, srb);
2898 enable_msgout_abort(acb, srb);
2906 msgin_set_sync(acb, srb);
2913 msgin_set_wide(acb, srb);
2916 msgin_reject(acb, srb);
2934 "SAVE POINTER rem=%i Ignore\n",
2944 "<%02i-%i> ABORT msg\n",
2948 enable_msgout_abort(acb, srb);
2961 msgin_reject(acb, srb);
2978 clear_fifo(acb,
"msgin_phase1");
3037 clear_fifo(acb,
"disconnectEx");
3046 clear_fifo(acb,
"disconnect");
3050 "disconnect: Unexpected reselection <%02i-%i>\n",
3053 waiting_process_next(acb);
3059 waiting_process_next(acb);
3073 "disconnect: (0x%p) Unexpected\n",
3080 "<%02i-%i> SelTO\n", srb->
cmd,
3089 srb_going_to_waiting_move(dcb, srb);
3091 "disconnect: (0x%p) Retry\n",
3093 waiting_set_timer(acb,
HZ / 20);
3102 " 0x%02x: ACK set! Other controllers?\n",
3106 waiting_process_next(acb);
3115 srb_done(acb, dcb, srb);
3125 u16 rsel_tar_lun_id;
3130 clear_fifo(acb,
"reselect");
3138 "but active_srb == NULL\n");
3145 "Arb lost but Resel win rsel=%i stat=0x%04x\n",
3154 srb_going_to_waiting_move(dcb, srb);
3155 waiting_set_timer(acb,
HZ / 20);
3163 "Got %i!\n", rsel_tar_lun_id);
3164 id = rsel_tar_lun_id & 0xff;
3165 lun = (rsel_tar_lun_id >> 8) & 7;
3166 dcb = find_dcb(acb,
id, lun);
3169 "<%02i-%i>\n",
id, lun);
3177 "disconnection? <%02i-%i>\n",
3191 "reselect: w/o disconnected cmds <%02i-%i>\n",
3196 enable_msgout_abort(acb, srb);
3200 enable_msgout_abort(acb, srb);
3220 static inline u8 tagq_blacklist(
char *
name)
3222 #ifndef DC395x_NO_TAGQ
3225 for (i = 0; i < BADDEVCNT; i++)
3226 if (
memcmp(name, DC395x_baddevname1[i], 28) == 0)
3239 if ((ptr->
Vers & 0x07) >= 2 || (ptr->
RDF & 0x0F) == 2) {
3245 !tagq_blacklist(((
char *)ptr) + 8)) {
3248 dcb->
acb->tag_max_num;
3263 disc_tagq_set(dcb, ptr);
3281 scsi_sg_count(cmd), scsi_bufflen(cmd));
3321 srb->
cmd->device->id, srb->
cmd->device->lun);
3328 pci_unmap_srb_sense(acb, srb);
3339 "ReqSense: NOT_READY cmnd=0x%02x <%02i-%i> stat=%i scan=%i ",
3345 "ReqSense: UNIT_ATTENTION cmnd=0x%02x <%02i-%i> stat=%i scan=%i ",
3351 "ReqSense: ILLEGAL_REQUEST cmnd=0x%02x <%02i-%i> stat=%i scan=%i ",
3357 "ReqSense: MEDIUM_ERROR cmnd=0x%02x <%02i-%i> stat=%i scan=%i ",
3363 "ReqSense: HARDWARE_ERROR cmnd=0x%02x <%02i-%i> stat=%i scan=%i ",
3369 printk(
"sense=0x%02x ASC=0x%02x ASCQ=0x%02x "
3370 "(0x%08x 0x%08x)\n",
3376 printk(
"sense=0x%02x No ASC/ASCQ (0x%08x)\n",
3417 srb_going_to_waiting_move(dcb, srb);
3418 waiting_set_timer(acb,
HZ / 20);
3454 pci_dma_sync_sg_for_cpu(acb->
dev, scsi_sglist(cmd),
3455 scsi_sg_count(cmd), dir);
3462 unsigned char *base =
NULL;
3464 unsigned long flags = 0;
3466 size_t offset = 0, len =
sizeof(
struct ScsiInqData);
3473 && cmd->
cmnd[2] == 0 && scsi_bufflen(cmd) >= 8
3483 add_dev(acb, dcb, ptr);
3496 cmd->
SCp.buffers_residual = 0;
3500 "cmnd=0x%02x Missed %i bytes\n",
3505 srb_going_remove(dcb, srb);
3512 srb_free_insert(acb, srb);
3514 pci_unmap_srb(acb, srb);
3517 waiting_process_next(acb);
3539 result =
MK_RES(0, did_flag, 0, 0);
3540 printk(
"G:%p(%02i-%i) ", p,
3542 srb_going_remove(dcb, srb);
3544 srb_free_insert(acb, srb);
3546 pci_unmap_srb_sense(acb, srb);
3547 pci_unmap_srb(acb, srb);
3556 "How could the ML send cmnds to the Going queue? <%02i-%i>\n",
3560 "tag_mask for <%02i-%i> should be empty, is %08x!\n",
3569 result =
MK_RES(0, did_flag, 0, 0);
3572 srb_waiting_remove(dcb, srb);
3573 srb_free_insert(acb, srb);
3575 pci_unmap_srb_sense(acb, srb);
3576 pci_unmap_srb(acb, srb);
3656 clear_fifo(acb,
"scsi_reset_detect");
3657 set_basic_config(acb);
3665 reset_dev_param(acb);
3666 doing_srb_done(acb,
DID_RESET, NULL, 1);
3670 waiting_process_next(acb);
3708 if (start_scsi(acb, dcb, srb)) {
3710 "request_sense: (0x%p) failed <%02i-%i>\n",
3712 srb_going_to_waiting_move(dcb, srb);
3713 waiting_set_timer(acb,
HZ / 100);
3750 #ifndef DC395x_NO_DISCONNECT
3764 #ifndef DC395x_NO_WIDE
3769 #ifndef DC395x_NO_SYNC
3771 if (!(lun) || current_sync_offset)
3781 "device_alloc: <%02i-%i> copy
from <%02i-%i>\
n",
3783 p->target_id, p->target_lun);
3807 if (list_empty(&acb->dcb_list))
3808 acb->dcb_run_robin = dcb;
3814 acb->dcb_map[dcb->target_id] |= (1 << dcb->target_lun);
3815 acb->children[dcb->target_id][dcb->target_lun] = dcb;
3828 static void adapter_remove_device(
struct AdapterCtlBlk *acb,
3863 static void adapter_remove_and_free_device(
struct AdapterCtlBlk *acb,
3867 dprintkdbg(DBG_1,
"adapter_remove_and_free_device: <%02i-%i> "
3868 "Won't remove because of %i active requests.\n",
3873 adapter_remove_device(acb, dcb);
3884 static void adapter_remove_and_free_all_devices(
struct AdapterCtlBlk* acb)
3888 dprintkdbg(DBG_1,
"adapter_remove_and_free_all_devices: num=%i\n",
3892 adapter_remove_and_free_device(acb, dcb);
3908 dcb = device_alloc(acb, scsi_device->id, scsi_device->lun);
3911 adapter_add_device(acb, dcb);
3923 static void dc395x_slave_destroy(
struct scsi_device *scsi_device)
3928 adapter_remove_and_free_device(acb, dcb);
3958 static void __devinit trms1040_write_cmd(
unsigned long io_port,
u8 cmd,
u8 addr)
3964 for (i = 0; i < 3; i++, cmd <<= 1) {
3970 trms1040_wait_30us(io_port);
3973 trms1040_wait_30us(io_port);
3977 for (i = 0; i < 7; i++, addr <<= 1) {
3983 trms1040_wait_30us(io_port);
3986 trms1040_wait_30us(io_port);
3989 trms1040_wait_30us(io_port);
4003 static void __devinit trms1040_set_data(
unsigned long io_port,
u8 addr,
u8 byte)
4009 trms1040_write_cmd(io_port, 0x05, addr);
4012 for (i = 0; i < 8; i++, byte <<= 1) {
4018 trms1040_wait_30us(io_port);
4020 trms1040_wait_30us(io_port);
4023 trms1040_wait_30us(io_port);
4027 trms1040_wait_30us(io_port);
4030 trms1040_wait_30us(io_port);
4035 trms1040_wait_30us(io_port);
4038 trms1040_wait_30us(io_port);
4057 static void __devinit trms1040_write_all(
struct NvRamType *eeprom,
unsigned long io_port)
4059 u8 *b_eeprom = (
u8 *)eeprom;
4067 trms1040_write_cmd(io_port, 0x04, 0xFF);
4069 trms1040_wait_30us(io_port);
4072 for (addr = 0; addr < 128; addr++, b_eeprom++)
4073 trms1040_set_data(io_port, addr, *b_eeprom);
4076 trms1040_write_cmd(io_port, 0x04, 0x00);
4078 trms1040_wait_30us(io_port);
4097 static u8 __devinit trms1040_get_data(
unsigned long io_port,
u8 addr)
4104 trms1040_write_cmd(io_port, 0x06, addr);
4107 for (i = 0; i < 8; i++) {
4109 trms1040_wait_30us(io_port);
4118 trms1040_wait_30us(io_port);
4135 static void __devinit trms1040_read_all(
struct NvRamType *eeprom,
unsigned long io_port)
4137 u8 *b_eeprom = (
u8 *)eeprom;
4145 for (addr = 0; addr < 128; addr++, b_eeprom++)
4146 *b_eeprom = trms1040_get_data(io_port, addr);
4167 u16 *w_eeprom = (
u16 *)eeprom;
4173 trms1040_read_all(eeprom, io_port);
4176 for (w_addr = 0, w_eeprom = (
u16 *)eeprom; w_addr < 64;
4177 w_addr++, w_eeprom++)
4179 if (cksum != 0x1234) {
4185 "EEProm checksum error: using default values and options.\n");
4199 for (d_addr = 0, d_eeprom = (
u32 *)eeprom->
target;
4200 d_addr < 16; d_addr++, d_eeprom++)
4201 *d_eeprom = 0x00000077;
4203 *d_eeprom++ = 0x04000F07;
4204 *d_eeprom++ = 0x00000015;
4205 for (d_addr = 0; d_addr < 12; d_addr++, d_eeprom++)
4209 set_safe_settings();
4211 eeprom_override(eeprom);
4213 eeprom->
cksum = 0x00;
4214 for (w_addr = 0, cksum = 0, w_eeprom = (
u16 *)eeprom;
4215 w_addr < 63; w_addr++, w_eeprom++)
4218 *w_eeprom = 0x1234 -
cksum;
4219 trms1040_write_all(eeprom, io_port);
4222 set_safe_settings();
4223 eeprom_index_to_delay(eeprom);
4224 eeprom_override(eeprom);
4237 dprintkl(
KERN_INFO,
"Used settings: AdapterID=%02i, Speed=%i(%02i.%01iMHz), dev_mode=0x%02x\n",
4239 eeprom->
target[0].period,
4240 clock_speed[eeprom->
target[0].period] / 10,
4241 clock_speed[eeprom->
target[0].period] % 10,
4250 static void adapter_sg_tables_free(
struct AdapterCtlBlk *acb)
4265 const unsigned mem_needed = (DC395x_MAX_SRB_CNT+1)
4276 dprintkdbg(DBG_1,
"Allocate %i pages for SG tables\n", pages);
4280 adapter_sg_tables_free(acb);
4283 dprintkdbg(DBG_1,
"Allocate %li bytes at %p for SG segments %i\n",
4286 while (i < srbs_per_page && srb_idx < DC395x_MAX_SRB_CNT)
4290 if (i < srbs_per_page)
4291 acb->
srb.segment_x =
4315 ((bval &
WIDESCSI) ?
"(Wide) " :
""));
4318 if (!(bval &
CON68))
4320 if (!(bval &
CON50))
4322 if ((bval & (CON5068 | CON50 | CON68)) ==
4324 printk(
" Oops! (All 3?) ");
4326 printk(
" Termination: ");
4399 srb_free_insert(acb, &acb->
srb_array[i]);
4435 #ifdef CONFIG_SCSI_MULTI_LUN
4510 unsigned long io_port,
u32 io_port_len,
unsigned int irq)
4529 check_eeprom(&acb->
eeprom, io_port);
4530 print_eeprom_settings(&acb->
eeprom);
4533 adapter_init_params(acb);
4536 adapter_print_config(acb);
4538 if (adapter_sg_tables_alloc(acb)) {
4543 adapter_init_chip(acb);
4544 set_basic_config(acb);
4547 "adapter_init: acb=%p, pdcb_map=%p psrb_array=%p "
4548 "size{acb=0x%04x dcb=0x%04x srb=0x%04x}\n",
4558 adapter_sg_tables_free(acb);
4579 reset_scsi_bus(acb);
4596 unsigned long flags;
4605 adapter_uninit_chip(acb);
4606 adapter_remove_and_free_all_devices(acb);
4614 adapter_sg_tables_free(acb);
4619 #define SPRINTF(args...) pos += sprintf(pos, args)
4623 if (YN) SPRINTF(" Yes ");\
4624 else SPRINTF(" No ")
4627 char **start,
off_t offset,
int length,
int inout)
4633 unsigned long flags;
4645 SPRINTF(
"DC395U/UW/F DC315/U %s\n",
4663 (
"Map of attached LUNs: %02x %02x %02x %02x %02x %02x %02x %02x\n",
4668 (
" %02x %02x %02x %02x %02x %02x %02x %02x\n",
4674 (
"Un ID LUN Prty Sync Wide DsCn SndS TagQ nego_period SyncFreq SyncOffs MaxCmd\n");
4679 SPRINTF(
"%02i %02i %02i ", dev, dcb->target_id,
4682 YESNO(dcb->sync_offset);
4687 nego_period = clock_period[dcb->sync_period & 0x07] << 2;
4688 if (dcb->sync_offset)
4689 SPRINTF(
" %03i ns ", nego_period);
4691 SPRINTF(
" (%03i ns)", (dcb->min_nego_period << 2));
4693 if (dcb->sync_offset & 0x0f) {
4694 spd = 1000 / (nego_period);
4695 spd1 = 1000 % (nego_period);
4696 spd1 = (spd1 * 10 + nego_period / 2) / (nego_period);
4697 SPRINTF(
" %2i.%1i M %02i ", spd, spd1,
4698 (dcb->sync_offset & 0x0f));
4703 SPRINTF(
" %02i\n", dcb->max_command);
4708 SPRINTF(
"Waiting queue timer running\n");
4714 if (!list_empty(&dcb->srb_waiting_list))
4715 SPRINTF(
"DCB (%02i-%i): Waiting: %i:",
4716 dcb->target_id, dcb->target_lun,
4717 list_size(&dcb->srb_waiting_list));
4720 if (!list_empty(&dcb->srb_going_list))
4721 SPRINTF(
"\nDCB (%02i-%i): Going : %i:",
4722 dcb->target_id, dcb->target_lun,
4723 list_size(&dcb->srb_going_list));
4726 if (!list_empty(&dcb->srb_waiting_list) || !list_empty(&dcb->srb_going_list))
4731 SPRINTF(
"DCB list for ACB %p:\n", acb);
4738 *start = buffer +
offset;
4741 if (pos - buffer < offset)
4743 else if (pos - buffer - offset < length)
4744 return pos - buffer -
offset;
4753 .proc_info = dc395x_proc_info,
4755 .queuecommand = dc395x_queue_command,
4756 .bios_param = dc395x_bios_param,
4757 .slave_alloc = dc395x_slave_alloc,
4758 .slave_destroy = dc395x_slave_destroy,
4763 .eh_abort_handler = dc395x_eh_abort,
4764 .eh_bus_reset_handler = dc395x_eh_bus_reset,
4773 static void banner_display(
void)
4775 static int banner_done = 0;
4831 if (adapter_init(acb, io_port_base, io_port_len, irq)) {
4839 if (scsi_add_host(scsi_host, &dev->
dev)) {
4843 pci_set_drvdata(dev, scsi_host);
4850 adapter_uninit(acb);
4851 if (scsi_host != NULL)
4866 struct Scsi_Host *scsi_host = pci_get_drvdata(dev);
4872 adapter_uninit(acb);
4875 pci_set_drvdata(dev, NULL);
4893 .id_table = dc395x_pci_table,
4894 .probe = dc395x_init_one,
4904 static int __init dc395x_module_init(
void)
4906 return pci_register_driver(&dc395x_driver);
4913 static void __exit dc395x_module_exit(
void)
4923 MODULE_DESCRIPTION(
"SCSI host adapter driver for Tekram TRM-S1040 based adapters: Tekram DC395 and DC315 series");