From nobody Wed Jan 26 07:28:41 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 20A541974DBD; Wed, 26 Jan 2022 07:28:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JkFhB0S3dz4pZv; Wed, 26 Jan 2022 07:28:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643182122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GwlMS2W5+ahMEBhRmDavBhwzCM/1lhvIBLfjwzl141c=; b=jFqZq77gWs+BYhtSzaTiK4jMS4CDLVP8zKpXd05BTQwEXCiziZ0eQspsw0nlL8bbpqUdV2 JA+0hkZlejORhh5EylX5x6BoPH1IINQCLojFPqxJeQxOWOcOqTBbSz2YDzDiOGfQXu3mtj 3b/hBzVJF4ywBYB41jwCCT7mx+S/2q5nthD5k2PgXH0bKYCy20/UmR2uSCLLY2/QVAesjt 6UnN/O9E+Id+mA88bRiNREVYOIl3LChqGkXOFmNxKfm3EJrWc/pnCHJZptSSayK5jOUdYA groEsuDCNMLivVAizy1CX1q4MASbKLAHjEHt28OlHRS8h+R9Cg3ljPJPkKXe0Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DF9C7192D8; Wed, 26 Jan 2022 07:28:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20Q7Sf4Y047956; Wed, 26 Jan 2022 07:28:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20Q7SfGd047955; Wed, 26 Jan 2022 07:28:41 GMT (envelope-from git) Date: Wed, 26 Jan 2022 07:28:41 GMT Message-Id: <202201260728.20Q7SfGd047955@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: 79c3478e76c3 - stable/13 - mmc_da: implement d_dump method, sddadump List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 79c3478e76c3bcea0879e799d81a8ac1d2b553e6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1643182122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GwlMS2W5+ahMEBhRmDavBhwzCM/1lhvIBLfjwzl141c=; b=SqL4yG8w2/ig50HLb4DwQ/JpRcPplJv0a1fKFLn0zCg5oI9AUnQ3H1r36mudDfwpFIVTpP AnSjG5qPvWbty7phXyHo62mDlV0VRrcYbVwB4n3p2l2pQKPukCtTflt1DXHQbxeHlboUw3 bs4rXdqZ1j1/QYv97Vyj/axY4aNzk4FHUtgy0y5XTmnf3EYepuC1Rt/VDWnlwVxNihuARJ YirbhLbV8lVXSTyi23SGRD9xIwClGwv6l0+dCZflEkht3D8lcXuqXfcDrsg32df5xZh/8S Yyx2WDvh0a44Ox3Vq7xgJ27RvNbP6m70CsZz/zX5h9Y5ybaS19O648lQHKCnig== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1643182122; a=rsa-sha256; cv=none; b=MNpiET7subyfXaiUVyE03nOlPiw83xIHTpqbcsqtlDwpzy/bsntEvOUD99+BP+rWA8clwu xjbViXaEKfCpaOBXK0dIbQSJhj4P1Fh+lCwwBq/YTZI5Pz0Gto7nDbhYtiMQum8yxARiNn tGlJ2WRHWfJsvs9PBdAnBgbTwTKV6ERNpNSfBIguiiIvEpwadfo9LZh+Q6BSCBXdNbnugV npqeUlhFElx5wcEd8zjw1GH0ixIdU15er16gzvQSyaqdJOVcj2zqpXlv2+2moxcAsVYH4U uOevPloThw/12/lmjW4LORT8zEa0CBOZDGgN3fe/2fXlhzt/zSsB1tcYJUSTqw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=79c3478e76c3bcea0879e799d81a8ac1d2b553e6 commit 79c3478e76c3bcea0879e799d81a8ac1d2b553e6 Author: Andriy Gapon AuthorDate: 2022-01-12 07:01:29 +0000 Commit: Andriy Gapon CommitDate: 2022-01-26 07:27:21 +0000 mmc_da: implement d_dump method, sddadump sddadump has been derived from sddastart. mmc_sim interface has grown a new method, cam_poll, to support polled operation. mmc_sim code has been changed to provide a sim_poll hook only if the controller implements the new method. The hooks is implemented in terms of the new mmc_sim_cam_poll method. Additionally, in-progress CCB-s now have CAM_REQ_INPROG status to satisfy xpt_pollwait(). mmc_sim_cam_poll method has been implemented in dwmmc host controller. Relnotes: perhaps (cherry picked from commit 44682688f038edbf34591b25ce36412a7f2d6d07) --- sys/cam/mmc/mmc_da.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++ sys/cam/mmc/mmc_sim.c | 20 +++++++------ sys/cam/mmc/mmc_sim_if.m | 4 +++ sys/dev/mmc/host/dwmmc.c | 15 ++++++++++ 4 files changed, 103 insertions(+), 9 deletions(-) diff --git a/sys/cam/mmc/mmc_da.c b/sys/cam/mmc/mmc_da.c index 0aeea57eee26..272721f5ef34 100644 --- a/sys/cam/mmc/mmc_da.c +++ b/sys/cam/mmc/mmc_da.c @@ -164,6 +164,7 @@ static const char *mmc_errmsg[] = #define ccb_bp ppriv_ptr1 static disk_strategy_t sddastrategy; +static dumper_t sddadump; static periph_init_t sddainit; static void sddaasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg); @@ -1563,6 +1564,8 @@ sdda_add_part(struct cam_periph *periph, u_int type, const char *name, part->disk->d_open = sddaopen; part->disk->d_close = sddaclose; part->disk->d_strategy = sddastrategy; + if (cam_sim_pollable(periph->sim)) + part->disk->d_dump = sddadump; part->disk->d_getattr = sddagetattr; part->disk->d_gone = sddadiskgonecb; part->disk->d_name = part->name; @@ -1998,4 +2001,74 @@ sddaerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) { return(cam_periph_error(ccb, cam_flags, sense_flags)); } + +static int +sddadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, + size_t length) +{ + struct ccb_mmcio mmcio; + struct disk *dp; + struct sdda_part *part; + struct sdda_softc *softc; + struct cam_periph *periph; + struct mmc_params *mmcp; + uint16_t count; + uint16_t opcode; + int error; + + dp = arg; + part = dp->d_drv1; + softc = part->sc; + periph = softc->periph; + mmcp = &periph->path->device->mmc_ident_data; + + if (softc->state != SDDA_STATE_NORMAL) + return (ENXIO); + + count = length / 512; + if (count == 0) + return (0); + + if (softc->part[softc->part_curr] != part) + return (EIO); /* TODO implement polled partition switch */ + + memset(&mmcio, 0, sizeof(mmcio)); + xpt_setup_ccb(&mmcio.ccb_h, periph->path, CAM_PRIORITY_NORMAL); /* XXX needed? */ + + mmcio.ccb_h.func_code = XPT_MMC_IO; + mmcio.ccb_h.flags = CAM_DIR_OUT; + mmcio.ccb_h.retry_count = 0; + mmcio.ccb_h.timeout = 15 * 1000; + + if (count > 1) + opcode = MMC_WRITE_MULTIPLE_BLOCK; + else + opcode = MMC_WRITE_BLOCK; + mmcio.cmd.opcode = opcode; + mmcio.cmd.arg = offset / 512; + if (!(mmcp->card_features & CARD_FEATURE_SDHC)) + mmcio.cmd.arg <<= 9; + + mmcio.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + mmcio.cmd.data = softc->mmcdata; + memset(mmcio.cmd.data, 0, sizeof(struct mmc_data)); + mmcio.cmd.data->data = virtual; + mmcio.cmd.data->len = 512 * count; + mmcio.cmd.data->flags = MMC_DATA_WRITE; + + /* Direct h/w to issue CMD12 upon completion */ + if (count > 1) { + mmcio.cmd.data->flags |= MMC_DATA_MULTI; + mmcio.stop.opcode = MMC_STOP_TRANSMISSION; + mmcio.stop.flags = MMC_RSP_R1B | MMC_CMD_AC; + mmcio.stop.arg = 0; + } + + error = cam_periph_runccb((union ccb *)&mmcio, cam_periph_error, + 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL); + if (error != 0) + printf("Aborting dump due to I/O error.\n"); + return (error); +} + #endif /* _KERNEL */ diff --git a/sys/cam/mmc/mmc_sim.c b/sys/cam/mmc/mmc_sim.c index 461cb7625a1f..4e845be68e8b 100644 --- a/sys/cam/mmc/mmc_sim.c +++ b/sys/cam/mmc/mmc_sim.c @@ -46,8 +46,10 @@ __FBSDID("$FreeBSD$"); static void mmc_cam_default_poll(struct cam_sim *sim) { + struct mmc_sim *mmc_sim; - return; + mmc_sim = cam_sim_softc(sim); + MMC_SIM_CAM_POLL(mmc_sim->dev); } static void @@ -97,12 +99,6 @@ mmc_cam_sim_default_action(struct cam_sim *sim, union ccb *ccb) mmc_sim = cam_sim_softc(sim); - if (mmc_sim == NULL) { - ccb->ccb_h.status = CAM_SEL_TIMEOUT; - xpt_done(ccb); - return; - } - mtx_assert(&mmc_sim->mtx, MA_OWNED); if (mmc_sim->ccb != NULL) { @@ -172,7 +168,6 @@ mmc_cam_sim_default_action(struct cam_sim *sim, union ccb *ccb) break; case XPT_MMC_IO: { - ccb->ccb_h.status = CAM_REQ_INVALID; rv = MMC_SIM_CAM_REQUEST(mmc_sim->dev, ccb); if (rv != 0) ccb->ccb_h.status = CAM_SIM_QUEUED; @@ -191,6 +186,8 @@ mmc_cam_sim_default_action(struct cam_sim *sim, union ccb *ccb) int mmc_cam_sim_alloc(device_t dev, const char *name, struct mmc_sim *mmc_sim) { + kobjop_desc_t kobj_desc; + kobj_method_t *kobj_method; mmc_sim->dev = dev; @@ -200,8 +197,13 @@ mmc_cam_sim_alloc(device_t dev, const char *name, struct mmc_sim *mmc_sim) snprintf(mmc_sim->name, sizeof(mmc_sim->name), "%s_sim", name); mtx_init(&mmc_sim->mtx, mmc_sim->name, NULL, MTX_DEF); + + /* Provide sim_poll hook only if the device has the poll method. */ + kobj_desc = &mmc_sim_cam_poll_desc; + kobj_method = kobj_lookup_method(((kobj_t)dev)->ops->cls, NULL, + kobj_desc); mmc_sim->sim = cam_sim_alloc_dev(mmc_cam_sim_default_action, - mmc_cam_default_poll, + kobj_method == &kobj_desc->deflt ? NULL : mmc_cam_default_poll, mmc_sim->name, mmc_sim, dev, &mmc_sim->mtx, 1, 1, mmc_sim->devq); diff --git a/sys/cam/mmc/mmc_sim_if.m b/sys/cam/mmc/mmc_sim_if.m index f1b88fc05ef5..f7d3f4df5ebb 100644 --- a/sys/cam/mmc/mmc_sim_if.m +++ b/sys/cam/mmc/mmc_sim_if.m @@ -52,3 +52,7 @@ METHOD int cam_request { device_t dev; union ccb *ccb; }; + +METHOD void cam_poll { + device_t dev; +}; diff --git a/sys/dev/mmc/host/dwmmc.c b/sys/dev/mmc/host/dwmmc.c index f12a03e1c7aa..f0cd8c1b4378 100644 --- a/sys/dev/mmc/host/dwmmc.c +++ b/sys/dev/mmc/host/dwmmc.c @@ -38,12 +38,14 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -459,6 +461,9 @@ dwmmc_handle_card_present(struct dwmmc_softc *sc, bool is_present) { bool was_present; + if (dumping || SCHEDULER_STOPPED()) + return; + was_present = sc->child != NULL; if (!was_present && is_present) { @@ -1535,6 +1540,15 @@ dwmmc_cam_request(device_t dev, union ccb *ccb) return (0); } + +static void +dwmmc_cam_poll(device_t dev) +{ + struct dwmmc_softc *sc; + + sc = device_get_softc(dev); + dwmmc_intr(sc); +} #endif /* MMCCAM */ static device_method_t dwmmc_methods[] = { @@ -1556,6 +1570,7 @@ static device_method_t dwmmc_methods[] = { DEVMETHOD(mmc_sim_get_tran_settings, dwmmc_get_tran_settings), DEVMETHOD(mmc_sim_set_tran_settings, dwmmc_set_tran_settings), DEVMETHOD(mmc_sim_cam_request, dwmmc_cam_request), + DEVMETHOD(mmc_sim_cam_poll, dwmmc_cam_poll), DEVMETHOD(bus_add_child, bus_generic_add_child), #endif