NCR5380.c (0e9fdd2b315c0fde535336ea09499a927e415566) NCR5380.c (57f31326518e98ee4cabf9a04efe00ed57c54147)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * NCR 5380 generic driver routines. These should make it *trivial*
4 * to implement 5380 SCSI drivers under Linux with a non-trantor
5 * architecture.
6 *
7 * Note that these routines also work with NR53c400 family chips.
8 *

--- 135 unchanged lines hidden (view full) ---

144{
145 /*
146 * Initialize the Scsi Pointer field so that all of the commands in the
147 * various queues are valid.
148 */
149
150 if (scsi_bufflen(cmd)) {
151 cmd->SCp.buffer = scsi_sglist(cmd);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * NCR 5380 generic driver routines. These should make it *trivial*
4 * to implement 5380 SCSI drivers under Linux with a non-trantor
5 * architecture.
6 *
7 * Note that these routines also work with NR53c400 family chips.
8 *

--- 135 unchanged lines hidden (view full) ---

144{
145 /*
146 * Initialize the Scsi Pointer field so that all of the commands in the
147 * various queues are valid.
148 */
149
150 if (scsi_bufflen(cmd)) {
151 cmd->SCp.buffer = scsi_sglist(cmd);
152 cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
152 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
153 cmd->SCp.this_residual = cmd->SCp.buffer->length;
154 } else {
155 cmd->SCp.buffer = NULL;
153 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
154 cmd->SCp.this_residual = cmd->SCp.buffer->length;
155 } else {
156 cmd->SCp.buffer = NULL;
157 cmd->SCp.buffers_residual = 0;
156 cmd->SCp.ptr = NULL;
157 cmd->SCp.this_residual = 0;
158 }
159
160 cmd->SCp.Status = 0;
161 cmd->SCp.Message = 0;
162}
163
158 cmd->SCp.ptr = NULL;
159 cmd->SCp.this_residual = 0;
160 }
161
162 cmd->SCp.Status = 0;
163 cmd->SCp.Message = 0;
164}
165
164static inline void advance_sg_buffer(struct scsi_cmnd *cmd)
165{
166 struct scatterlist *s = cmd->SCp.buffer;
167
168 if (!cmd->SCp.this_residual && s && !sg_is_last(s)) {
169 cmd->SCp.buffer = sg_next(s);
170 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
171 cmd->SCp.this_residual = cmd->SCp.buffer->length;
172 }
173}
174
175/**
176 * NCR5380_poll_politely2 - wait for two chip register values
177 * @hostdata: host private data
178 * @reg1: 5380 register to poll
179 * @bit1: Bitmask to check
180 * @val1: Expected value
181 * @reg2: Second 5380 register to poll
182 * @bit2: Second bitmask to check

--- 530 unchanged lines hidden (view full) ---

713 requeue_cmd(instance, cmd);
714 }
715 }
716 if (hostdata->connected && !hostdata->dma_len) {
717 dsprintk(NDEBUG_MAIN, instance, "main: performing information transfer\n");
718 NCR5380_information_transfer(instance);
719 done = 0;
720 }
166/**
167 * NCR5380_poll_politely2 - wait for two chip register values
168 * @hostdata: host private data
169 * @reg1: 5380 register to poll
170 * @bit1: Bitmask to check
171 * @val1: Expected value
172 * @reg2: Second 5380 register to poll
173 * @bit2: Second bitmask to check

--- 530 unchanged lines hidden (view full) ---

704 requeue_cmd(instance, cmd);
705 }
706 }
707 if (hostdata->connected && !hostdata->dma_len) {
708 dsprintk(NDEBUG_MAIN, instance, "main: performing information transfer\n");
709 NCR5380_information_transfer(instance);
710 done = 0;
711 }
712 if (!hostdata->connected)
713 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
721 spin_unlock_irq(&hostdata->lock);
722 if (!done)
723 cond_resched();
724 } while (!done);
725}
726
727/*
728 * NCR5380_dma_complete - finish DMA transfer

--- 385 unchanged lines hidden (view full) ---

1114
1115 err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_BSY, SR_BSY,
1116 msecs_to_jiffies(250));
1117
1118 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
1119 spin_lock_irq(&hostdata->lock);
1120 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1121 NCR5380_reselect(instance);
714 spin_unlock_irq(&hostdata->lock);
715 if (!done)
716 cond_resched();
717 } while (!done);
718}
719
720/*
721 * NCR5380_dma_complete - finish DMA transfer

--- 385 unchanged lines hidden (view full) ---

1107
1108 err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_BSY, SR_BSY,
1109 msecs_to_jiffies(250));
1110
1111 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) == (SR_SEL | SR_IO)) {
1112 spin_lock_irq(&hostdata->lock);
1113 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1114 NCR5380_reselect(instance);
1122 if (!hostdata->connected)
1123 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1124 shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n");
1125 goto out;
1126 }
1127
1128 if (err < 0) {
1129 spin_lock_irq(&hostdata->lock);
1130 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1115 shost_printk(KERN_ERR, instance, "reselection after won arbitration?\n");
1116 goto out;
1117 }
1118
1119 if (err < 0) {
1120 spin_lock_irq(&hostdata->lock);
1121 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1131 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1132
1133 /* Can't touch cmd if it has been reclaimed by the scsi ML */
1134 if (!hostdata->selecting)
1135 return false;
1136
1137 cmd->result = DID_BAD_TARGET << 16;
1138 complete_cmd(instance, cmd);
1139 dsprintk(NDEBUG_SELECTION, instance,

--- 21 unchanged lines hidden (view full) ---

1161
1162 /* Wait for start of REQ/ACK handshake */
1163
1164 err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, HZ);
1165 spin_lock_irq(&hostdata->lock);
1166 if (err < 0) {
1167 shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
1168 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1122
1123 /* Can't touch cmd if it has been reclaimed by the scsi ML */
1124 if (!hostdata->selecting)
1125 return false;
1126
1127 cmd->result = DID_BAD_TARGET << 16;
1128 complete_cmd(instance, cmd);
1129 dsprintk(NDEBUG_SELECTION, instance,

--- 21 unchanged lines hidden (view full) ---

1151
1152 /* Wait for start of REQ/ACK handshake */
1153
1154 err = NCR5380_poll_politely(hostdata, STATUS_REG, SR_REQ, SR_REQ, HZ);
1155 spin_lock_irq(&hostdata->lock);
1156 if (err < 0) {
1157 shost_printk(KERN_ERR, instance, "select: REQ timeout\n");
1158 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1169 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1170 goto out;
1171 }
1172 if (!hostdata->selecting) {
1173 do_abort(instance);
1174 return false;
1175 }
1176
1177 dsprintk(NDEBUG_SELECTION, instance, "target %d selected, going into MESSAGE OUT phase.\n",

--- 498 unchanged lines hidden (view full) ---

1676 old_phase = phase;
1677 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
1678 }
1679#ifdef CONFIG_SUN3
1680 if (phase == PHASE_CMDOUT &&
1681 sun3_dma_setup_done != cmd) {
1682 int count;
1683
1159 goto out;
1160 }
1161 if (!hostdata->selecting) {
1162 do_abort(instance);
1163 return false;
1164 }
1165
1166 dsprintk(NDEBUG_SELECTION, instance, "target %d selected, going into MESSAGE OUT phase.\n",

--- 498 unchanged lines hidden (view full) ---

1665 old_phase = phase;
1666 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
1667 }
1668#ifdef CONFIG_SUN3
1669 if (phase == PHASE_CMDOUT &&
1670 sun3_dma_setup_done != cmd) {
1671 int count;
1672
1684 advance_sg_buffer(cmd);
1673 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1674 ++cmd->SCp.buffer;
1675 --cmd->SCp.buffers_residual;
1676 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1677 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
1678 }
1685
1686 count = sun3scsi_dma_xfer_len(hostdata, cmd);
1687
1688 if (count > 0) {
1689 if (rq_data_dir(cmd->request))
1690 sun3scsi_dma_send_setup(hostdata,
1691 cmd->SCp.ptr, count);
1692 else

--- 33 unchanged lines hidden (view full) ---

1726 return;
1727#endif
1728 case PHASE_DATAIN:
1729 /*
1730 * If there is no room left in the current buffer in the
1731 * scatter-gather list, move onto the next one.
1732 */
1733
1679
1680 count = sun3scsi_dma_xfer_len(hostdata, cmd);
1681
1682 if (count > 0) {
1683 if (rq_data_dir(cmd->request))
1684 sun3scsi_dma_send_setup(hostdata,
1685 cmd->SCp.ptr, count);
1686 else

--- 33 unchanged lines hidden (view full) ---

1720 return;
1721#endif
1722 case PHASE_DATAIN:
1723 /*
1724 * If there is no room left in the current buffer in the
1725 * scatter-gather list, move onto the next one.
1726 */
1727
1734 advance_sg_buffer(cmd);
1735 dsprintk(NDEBUG_INFORMATION, instance,
1736 "this residual %d, sg ents %d\n",
1737 cmd->SCp.this_residual,
1738 sg_nents(cmd->SCp.buffer));
1728 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1729 ++cmd->SCp.buffer;
1730 --cmd->SCp.buffers_residual;
1731 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1732 cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
1733 dsprintk(NDEBUG_INFORMATION, instance, "%d bytes and %d buffers left\n",
1734 cmd->SCp.this_residual,
1735 cmd->SCp.buffers_residual);
1736 }
1739
1740 /*
1741 * The preferred transfer method is going to be
1742 * PSEUDO-DMA for systems that are strictly PIO,
1743 * since we can let the hardware do the handshaking.
1744 *
1745 * For this to work, we need to know the transfersize
1746 * ahead of time, since the pseudo-DMA code will sit

--- 74 unchanged lines hidden (view full) ---

1821 }
1822
1823 /*
1824 * Restore phase bits to 0 so an interrupted selection,
1825 * arbitration can resume.
1826 */
1827 NCR5380_write(TARGET_COMMAND_REG, 0);
1828
1737
1738 /*
1739 * The preferred transfer method is going to be
1740 * PSEUDO-DMA for systems that are strictly PIO,
1741 * since we can let the hardware do the handshaking.
1742 *
1743 * For this to work, we need to know the transfersize
1744 * ahead of time, since the pseudo-DMA code will sit

--- 74 unchanged lines hidden (view full) ---

1819 }
1820
1821 /*
1822 * Restore phase bits to 0 so an interrupted selection,
1823 * arbitration can resume.
1824 */
1825 NCR5380_write(TARGET_COMMAND_REG, 0);
1826
1829 /* Enable reselect interrupts */
1830 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1831
1832 maybe_release_dma_irq(instance);
1833 return;
1834 case MESSAGE_REJECT:
1835 /* Accept message by clearing ACK */
1836 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1837 switch (hostdata->last_message) {
1838 case HEAD_OF_QUEUE_TAG:
1839 case ORDERED_QUEUE_TAG:

--- 15 unchanged lines hidden (view full) ---

1855 cmd, scmd_id(cmd), cmd->device->lun);
1856
1857 /*
1858 * Restore phase bits to 0 so an interrupted selection,
1859 * arbitration can resume.
1860 */
1861 NCR5380_write(TARGET_COMMAND_REG, 0);
1862
1827 maybe_release_dma_irq(instance);
1828 return;
1829 case MESSAGE_REJECT:
1830 /* Accept message by clearing ACK */
1831 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1832 switch (hostdata->last_message) {
1833 case HEAD_OF_QUEUE_TAG:
1834 case ORDERED_QUEUE_TAG:

--- 15 unchanged lines hidden (view full) ---

1850 cmd, scmd_id(cmd), cmd->device->lun);
1851
1852 /*
1853 * Restore phase bits to 0 so an interrupted selection,
1854 * arbitration can resume.
1855 */
1856 NCR5380_write(TARGET_COMMAND_REG, 0);
1857
1863 /* Enable reselect interrupts */
1864 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1865#ifdef SUN3_SCSI_VME
1866 dregs->csr |= CSR_DMA_ENABLE;
1867#endif
1868 return;
1869 /*
1870 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
1871 * operation, in violation of the SCSI spec so we can safely
1872 * ignore SAVE/RESTORE pointers calls.

--- 86 unchanged lines hidden (view full) ---

1959 hostdata->last_message = msgout;
1960 NCR5380_transfer_pio(instance, &phase, &len, &data);
1961 if (msgout == ABORT) {
1962 hostdata->connected = NULL;
1963 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
1964 cmd->result = DID_ERROR << 16;
1965 complete_cmd(instance, cmd);
1966 maybe_release_dma_irq(instance);
1858#ifdef SUN3_SCSI_VME
1859 dregs->csr |= CSR_DMA_ENABLE;
1860#endif
1861 return;
1862 /*
1863 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
1864 * operation, in violation of the SCSI spec so we can safely
1865 * ignore SAVE/RESTORE pointers calls.

--- 86 unchanged lines hidden (view full) ---

1952 hostdata->last_message = msgout;
1953 NCR5380_transfer_pio(instance, &phase, &len, &data);
1954 if (msgout == ABORT) {
1955 hostdata->connected = NULL;
1956 hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
1957 cmd->result = DID_ERROR << 16;
1958 complete_cmd(instance, cmd);
1959 maybe_release_dma_irq(instance);
1967 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1968 return;
1969 }
1970 msgout = NOP;
1971 break;
1972 case PHASE_CMDOUT:
1973 len = cmd->cmd_len;
1974 data = cmd->cmnd;
1975 /*

--- 155 unchanged lines hidden (view full) ---

2131 hostdata->busy[target] &= ~(1 << lun);
2132 return;
2133 }
2134
2135#ifdef CONFIG_SUN3
2136 if (sun3_dma_setup_done != tmp) {
2137 int count;
2138
1960 return;
1961 }
1962 msgout = NOP;
1963 break;
1964 case PHASE_CMDOUT:
1965 len = cmd->cmd_len;
1966 data = cmd->cmnd;
1967 /*

--- 155 unchanged lines hidden (view full) ---

2123 hostdata->busy[target] &= ~(1 << lun);
2124 return;
2125 }
2126
2127#ifdef CONFIG_SUN3
2128 if (sun3_dma_setup_done != tmp) {
2129 int count;
2130
2139 advance_sg_buffer(tmp);
2131 if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
2132 ++tmp->SCp.buffer;
2133 --tmp->SCp.buffers_residual;
2134 tmp->SCp.this_residual = tmp->SCp.buffer->length;
2135 tmp->SCp.ptr = sg_virt(tmp->SCp.buffer);
2136 }
2140
2141 count = sun3scsi_dma_xfer_len(hostdata, tmp);
2142
2143 if (count > 0) {
2144 if (rq_data_dir(tmp->request))
2145 sun3scsi_dma_send_setup(hostdata,
2146 tmp->SCp.ptr, count);
2147 else

--- 251 unchanged lines hidden ---
2137
2138 count = sun3scsi_dma_xfer_len(hostdata, tmp);
2139
2140 if (count > 0) {
2141 if (rq_data_dir(tmp->request))
2142 sun3scsi_dma_send_setup(hostdata,
2143 tmp->SCp.ptr, count);
2144 else

--- 251 unchanged lines hidden ---