11da177e4SLinus Torvalds /*==========================================================================
21da177e4SLinus Torvalds NinjaSCSI-3 message handler
31da177e4SLinus Torvalds By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
41da177e4SLinus Torvalds
51da177e4SLinus Torvalds This software may be used and distributed according to the terms of
61da177e4SLinus Torvalds the GNU General Public License.
71da177e4SLinus Torvalds */
81da177e4SLinus Torvalds
91da177e4SLinus Torvalds /* $Id: nsp_message.c,v 1.6 2003/07/26 14:21:09 elca Exp $ */
101da177e4SLinus Torvalds
nsp_message_in(struct scsi_cmnd * SCpnt)11*0fc82d5eSHenrik Kretzschmar static void nsp_message_in(struct scsi_cmnd *SCpnt)
121da177e4SLinus Torvalds {
131da177e4SLinus Torvalds unsigned int base = SCpnt->device->host->io_port;
141da177e4SLinus Torvalds nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
151da177e4SLinus Torvalds unsigned char data_reg, control_reg;
161da177e4SLinus Torvalds int ret, len;
171da177e4SLinus Torvalds
181da177e4SLinus Torvalds /*
191da177e4SLinus Torvalds * XXX: NSP QUIRK
201da177e4SLinus Torvalds * NSP invoke interrupts only in the case of scsi phase changes,
211da177e4SLinus Torvalds * therefore we should poll the scsi phase here to catch
221da177e4SLinus Torvalds * the next "msg in" if exists (no scsi phase changes).
231da177e4SLinus Torvalds */
241da177e4SLinus Torvalds ret = 16;
251da177e4SLinus Torvalds len = 0;
261da177e4SLinus Torvalds
271da177e4SLinus Torvalds nsp_dbg(NSP_DEBUG_MSGINOCCUR, "msgin loop");
281da177e4SLinus Torvalds do {
291da177e4SLinus Torvalds /* read data */
301da177e4SLinus Torvalds data_reg = nsp_index_read(base, SCSIDATAIN);
311da177e4SLinus Torvalds
321da177e4SLinus Torvalds /* assert ACK */
331da177e4SLinus Torvalds control_reg = nsp_index_read(base, SCSIBUSCTRL);
341da177e4SLinus Torvalds control_reg |= SCSI_ACK;
351da177e4SLinus Torvalds nsp_index_write(base, SCSIBUSCTRL, control_reg);
361da177e4SLinus Torvalds nsp_negate_signal(SCpnt, BUSMON_REQ, "msgin<REQ>");
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds data->MsgBuffer[len] = data_reg; len++;
391da177e4SLinus Torvalds
401da177e4SLinus Torvalds /* deassert ACK */
411da177e4SLinus Torvalds control_reg = nsp_index_read(base, SCSIBUSCTRL);
421da177e4SLinus Torvalds control_reg &= ~SCSI_ACK;
431da177e4SLinus Torvalds nsp_index_write(base, SCSIBUSCTRL, control_reg);
441da177e4SLinus Torvalds
451da177e4SLinus Torvalds /* catch a next signal */
461da177e4SLinus Torvalds ret = nsp_expect_signal(SCpnt, BUSPHASE_MESSAGE_IN, BUSMON_REQ);
471da177e4SLinus Torvalds } while (ret > 0 && MSGBUF_SIZE > len);
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds data->MsgLen = len;
501da177e4SLinus Torvalds
511da177e4SLinus Torvalds }
521da177e4SLinus Torvalds
nsp_message_out(struct scsi_cmnd * SCpnt)53*0fc82d5eSHenrik Kretzschmar static void nsp_message_out(struct scsi_cmnd *SCpnt)
541da177e4SLinus Torvalds {
551da177e4SLinus Torvalds nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
561da177e4SLinus Torvalds int ret = 1;
571da177e4SLinus Torvalds int len = data->MsgLen;
581da177e4SLinus Torvalds
591da177e4SLinus Torvalds /*
601da177e4SLinus Torvalds * XXX: NSP QUIRK
611da177e4SLinus Torvalds * NSP invoke interrupts only in the case of scsi phase changes,
621da177e4SLinus Torvalds * therefore we should poll the scsi phase here to catch
631da177e4SLinus Torvalds * the next "msg out" if exists (no scsi phase changes).
641da177e4SLinus Torvalds */
651da177e4SLinus Torvalds
661da177e4SLinus Torvalds nsp_dbg(NSP_DEBUG_MSGOUTOCCUR, "msgout loop");
671da177e4SLinus Torvalds do {
681da177e4SLinus Torvalds if (nsp_xfer(SCpnt, BUSPHASE_MESSAGE_OUT)) {
691da177e4SLinus Torvalds nsp_msg(KERN_DEBUG, "msgout: xfer short");
701da177e4SLinus Torvalds }
711da177e4SLinus Torvalds
721da177e4SLinus Torvalds /* catch a next signal */
731da177e4SLinus Torvalds ret = nsp_expect_signal(SCpnt, BUSPHASE_MESSAGE_OUT, BUSMON_REQ);
741da177e4SLinus Torvalds } while (ret > 0 && len-- > 0);
751da177e4SLinus Torvalds
761da177e4SLinus Torvalds }
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds /* end */
79