From owner-p4-projects@FreeBSD.ORG Thu Nov 16 23:46:23 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id BED5516A407; Thu, 16 Nov 2006 23:46:23 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7BB2B16A40F for ; Thu, 16 Nov 2006 23:46:23 +0000 (UTC) (envelope-from mjacob@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id D9F7743D55 for ; Thu, 16 Nov 2006 23:46:22 +0000 (GMT) (envelope-from mjacob@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id kAGNkMA3031271 for ; Thu, 16 Nov 2006 23:46:22 GMT (envelope-from mjacob@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id kAGNkMR8031268 for perforce@freebsd.org; Thu, 16 Nov 2006 23:46:22 GMT (envelope-from mjacob@freebsd.org) Date: Thu, 16 Nov 2006 23:46:22 GMT Message-Id: <200611162346.kAGNkMR8031268@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to mjacob@freebsd.org using -f From: Matt Jacob To: Perforce Change Reviews Cc: Subject: PERFORCE change 110138 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Nov 2006 23:46:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=110138 Change 110138 by mjacob@newisp on 2006/11/16 23:45:44 Finally fix local command responses to set residual correctly. This allows us to play nicely on SANs when we have target mode enabled in f/w but have neither the scsi_targbh enabled or scsi_targ with a target enabled. Affected files ... .. //depot/projects/newisp/dev/mpt/mpt_cam.c#11 edit Differences ... ==== //depot/projects/newisp/dev/mpt/mpt_cam.c#11 (text+ko) ==== @@ -3144,14 +3144,16 @@ * XXX: FC cards report MAX_DEVICES of 512- but we * XXX: seem to hang when going higher than 255. */ - if (cpi->max_target > 255) + if (cpi->max_target > 255) { cpi->max_target = 255; + } /* * XXX: VMware ESX reports > 16 devices and then dies * XXX: when we probe. */ - if (mpt->is_spi && cpi->max_target > 15) + if (mpt->is_spi && cpi->max_target > 15) { cpi->max_target = 15; + } cpi->max_lun = 7; cpi->initiator_id = mpt->mpt_ini_id; @@ -3166,8 +3168,7 @@ */ if (mpt->is_fc) { cpi->hba_misc = PIM_NOBUSRESET; - cpi->base_transfer_speed = - mpt->mpt_fcport_speed * 100000; + cpi->base_transfer_speed = 100000; cpi->hba_inquiry = PI_TAG_ABLE; cpi->transport = XPORT_FC; cpi->transport_version = 0; @@ -4151,12 +4152,16 @@ bus_addr_t pptr; request_t *req; - if (length == 0) { + /* + * We enter with resid set to the data load for the command. + */ + tgt = MPT_TGT_STATE(mpt, cmd_req); + if (length == 0 || tgt->resid == 0) { + tgt->resid = 0; mpt_scsi_tgt_status(mpt, NULL, cmd_req, 0, NULL); return; } - tgt = MPT_TGT_STATE(mpt, cmd_req); if ((req = mpt_get_request(mpt, FALSE)) == NULL) { mpt_prt(mpt, "out of resources- dropping local response\n"); return; @@ -4208,7 +4213,7 @@ tgt->ccb = NULL; tgt->req = req; - tgt->resid = 0; + tgt->resid -= length; tgt->bytes_xfered = length; #ifdef WE_TRUST_AUTO_GOOD_STATUS tgt->state = TGT_STATE_MOVING_DATA_AND_STATUS; @@ -4514,6 +4519,13 @@ static void mpt_scsi_tgt_atio(struct mpt_softc *mpt, request_t *req, uint32_t reply_desc) { + static uint8_t null_iqd[SHORT_INQUIRY_LENGTH] = { + 0x7f, 0x00, 0x02, 0x02, 0x20, 0x00, 0x00, 0x32, + 'F', 'R', 'E', 'E', 'B', 'S', 'D', ' ', + 'L', 'S', 'I', '-', 'L', 'O', 'G', 'I', + 'C', ' ', 'N', 'U', 'L', 'D', 'E', 'V', + '0', '0', '0', '1' + }; struct ccb_accept_tio *atiop; lun_id_t lun; int tag_action = 0; @@ -4660,11 +4672,8 @@ * REPORT LUNS gets illegal command. * All other commands get 'no such device'. */ - uint8_t *sp, cond, buf[MPT_SENSE_SIZE]; - - mpt_prt(mpt, "CMD 0x%x to unmanaged lun %u\n", - cdbp[0], lun); + size_t len; memset(buf, 0, MPT_SENSE_SIZE); cond = SCSI_STATUS_CHECK_COND; @@ -4677,31 +4686,38 @@ switch (cdbp[0]) { case INQUIRY: { - static uint8_t iqd[8] = { - 0x7f, 0x0, 0x4, 0x12, 0x0 - }; if (cdbp[1] != 0) { buf[12] = 0x26; buf[13] = 0x01; break; } - mpt_prt(mpt, "local inquiry\n"); + len = min(tgt->resid, cdbp[4]); + len = min(len, sizeof (null_iqd)); + mpt_lprt(mpt, MPT_PRT_DEBUG, + "local inquiry %ld bytes\n", len); mpt_scsi_tgt_local(mpt, req, lun, 1, - iqd, sizeof (iqd)); + null_iqd, len); return; } case REQUEST_SENSE: { buf[2] = 0x0; - mpt_prt(mpt, "local request sense\n"); + len = min(tgt->resid, cdbp[4]); + len = min(len, sizeof (buf)); + mpt_lprt(mpt, MPT_PRT_DEBUG, + "local reqsense %ld bytes\n", len); mpt_scsi_tgt_local(mpt, req, lun, 1, - buf, sizeof (buf)); + buf, len); return; } case REPORT_LUNS: + mpt_lprt(mpt, MPT_PRT_DEBUG, "REPORT LUNS\n"); buf[12] = 0x26; - break; + return; default: + mpt_lprt(mpt, MPT_PRT_DEBUG, + "CMD 0x%x to unmanaged lun %u\n", + cdbp[0], lun); buf[12] = 0x25; break; }