18c2ecf20Sopenharmony_ci/*========================================================================== 28c2ecf20Sopenharmony_ci NinjaSCSI-3 message handler 38c2ecf20Sopenharmony_ci By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp> 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci This software may be used and distributed according to the terms of 68c2ecf20Sopenharmony_ci the GNU General Public License. 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* $Id: nsp_message.c,v 1.6 2003/07/26 14:21:09 elca Exp $ */ 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_cistatic void nsp_message_in(struct scsi_cmnd *SCpnt) 128c2ecf20Sopenharmony_ci{ 138c2ecf20Sopenharmony_ci unsigned int base = SCpnt->device->host->io_port; 148c2ecf20Sopenharmony_ci nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata; 158c2ecf20Sopenharmony_ci unsigned char data_reg, control_reg; 168c2ecf20Sopenharmony_ci int ret, len; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci /* 198c2ecf20Sopenharmony_ci * XXX: NSP QUIRK 208c2ecf20Sopenharmony_ci * NSP invoke interrupts only in the case of scsi phase changes, 218c2ecf20Sopenharmony_ci * therefore we should poll the scsi phase here to catch 228c2ecf20Sopenharmony_ci * the next "msg in" if exists (no scsi phase changes). 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci ret = 16; 258c2ecf20Sopenharmony_ci len = 0; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci nsp_dbg(NSP_DEBUG_MSGINOCCUR, "msgin loop"); 288c2ecf20Sopenharmony_ci do { 298c2ecf20Sopenharmony_ci /* read data */ 308c2ecf20Sopenharmony_ci data_reg = nsp_index_read(base, SCSIDATAIN); 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci /* assert ACK */ 338c2ecf20Sopenharmony_ci control_reg = nsp_index_read(base, SCSIBUSCTRL); 348c2ecf20Sopenharmony_ci control_reg |= SCSI_ACK; 358c2ecf20Sopenharmony_ci nsp_index_write(base, SCSIBUSCTRL, control_reg); 368c2ecf20Sopenharmony_ci nsp_negate_signal(SCpnt, BUSMON_REQ, "msgin<REQ>"); 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci data->MsgBuffer[len] = data_reg; len++; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci /* deassert ACK */ 418c2ecf20Sopenharmony_ci control_reg = nsp_index_read(base, SCSIBUSCTRL); 428c2ecf20Sopenharmony_ci control_reg &= ~SCSI_ACK; 438c2ecf20Sopenharmony_ci nsp_index_write(base, SCSIBUSCTRL, control_reg); 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci /* catch a next signal */ 468c2ecf20Sopenharmony_ci ret = nsp_expect_signal(SCpnt, BUSPHASE_MESSAGE_IN, BUSMON_REQ); 478c2ecf20Sopenharmony_ci } while (ret > 0 && MSGBUF_SIZE > len); 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci data->MsgLen = len; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistatic void nsp_message_out(struct scsi_cmnd *SCpnt) 548c2ecf20Sopenharmony_ci{ 558c2ecf20Sopenharmony_ci nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata; 568c2ecf20Sopenharmony_ci int ret = 1; 578c2ecf20Sopenharmony_ci int len = data->MsgLen; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* 608c2ecf20Sopenharmony_ci * XXX: NSP QUIRK 618c2ecf20Sopenharmony_ci * NSP invoke interrupts only in the case of scsi phase changes, 628c2ecf20Sopenharmony_ci * therefore we should poll the scsi phase here to catch 638c2ecf20Sopenharmony_ci * the next "msg out" if exists (no scsi phase changes). 648c2ecf20Sopenharmony_ci */ 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci nsp_dbg(NSP_DEBUG_MSGOUTOCCUR, "msgout loop"); 678c2ecf20Sopenharmony_ci do { 688c2ecf20Sopenharmony_ci if (nsp_xfer(SCpnt, BUSPHASE_MESSAGE_OUT)) { 698c2ecf20Sopenharmony_ci nsp_msg(KERN_DEBUG, "msgout: xfer short"); 708c2ecf20Sopenharmony_ci } 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci /* catch a next signal */ 738c2ecf20Sopenharmony_ci ret = nsp_expect_signal(SCpnt, BUSPHASE_MESSAGE_OUT, BUSMON_REQ); 748c2ecf20Sopenharmony_ci } while (ret > 0 && len-- > 0); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* end */ 79