Lines Matching +full:wr +full:- +full:setup

1 /*-
3 * Copyright (c) 2018-2019 The FreeBSD Foundation
36 * Group. This Simplified Specification is provided on a non-confidential
39 * Association, SD Group, SD-3C LLC or other third parties.
45 * is provided "AS-IS" without any representations or warranties of any
46 * kind. No responsibility is assumed by the SD Group, SD-3C LLC or the SD
48 * right of the SD Group, SD-3C LLC, the SD Card Association or any third
51 * SD Group, SD-3C LLC, the SD Card Association or any third party. Nothing
52 * herein shall be construed as an obligation by the SD Group, the SD-3C LLC
54 * information, know-how or other confidential information to any third party.
121 /* -------------------------------------------------------------------------- */
141 sdiob_rw_direct_sc(struct sdiob_softc *sc, uint8_t fn, uint32_t addr, bool wr,
149 if (sc->ccb == NULL)
150 sc->ccb = xpt_alloc_ccb();
152 memset(sc->ccb, 0, sizeof(*sc->ccb));
153 xpt_setup_ccb(&sc->ccb->ccb_h, sc->periph->path, CAM_PRIORITY_NONE);
154 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_TRACE,
155 ("%s(fn=%d, addr=%#02x, wr=%d, *val=%#02x)\n", __func__,
156 fn, addr, wr, *val));
160 if (wr)
163 cam_fill_mmcio(&sc->ccb->mmcio,
171 /*timeout*/ sc->cardinfo.f[fn].timeout);
172 error = cam_periph_runccb(sc->ccb, sdioerror, CAM_FLAG_NONE, 0, NULL);
174 if (sc->dev != NULL)
175 device_printf(sc->dev,
177 __func__, (wr) ? "write" : "read", addr, error);
179 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_INFO,
181 __func__, (wr) ? "write" : "read", addr, error));
186 /* ccb->mmcio.cmd.error ? */
187 if (wr == false)
188 *val = sc->ccb->mmcio.cmd.resp[0] & 0xff;
194 sdio_rw_direct(device_t dev, uint8_t fn, uint32_t addr, bool wr,
201 cam_periph_lock(sc->periph);
202 error = sdiob_rw_direct_sc(sc, fn, addr, wr, val);
203 cam_periph_unlock(sc->periph);
243 bool wr, uint8_t *buffer, bool incaddr, uint32_t b_count, uint16_t blksz)
249 if (sc->ccb == NULL)
250 sc->ccb = xpt_alloc_ccb();
252 memset(sc->ccb, 0, sizeof(*sc->ccb));
253 xpt_setup_ccb(&sc->ccb->ccb_h, sc->periph->path, CAM_PRIORITY_NONE);
254 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_TRACE,
255 ("%s(fn=%d addr=%#0x wr=%d b_count=%u blksz=%u buf=%p incr=%d)\n",
256 __func__, fn, addr, wr, b_count, blksz, buffer, incaddr));
261 wr ? "wr" : "rd", buffer, incaddr ? "incaddr" : "fifo"));
263 KASSERT((blksz <= sc->cardinfo.f[fn].cur_blksize), ("%s: blksz "
266 sc->cardinfo.f[fn].cur_blksize, sc, fn, addr,
267 wr ? "wr" : "rd", buffer, incaddr ? "incaddr" : "fifo",
301 if (wr) {
311 /* XXX-BZ TODO FIXME. Cancel I/O: CCCR -> ASx */
315 cam_fill_mmcio(&sc->ccb->mmcio,
323 /*timeout*/ sc->cardinfo.f[fn].timeout);
327 sc->ccb->mmcio.cmd.data->flags |= MMC_DATA_MULTI;
331 error = cam_periph_runccb(sc->ccb, sdioerror, CAM_FLAG_NONE, 0, NULL);
333 if (sc->dev != NULL)
334 device_printf(sc->dev,
337 __func__, (wr) ? "write to" : "read from", addr,
341 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_INFO,
344 __func__, (wr) ? "write to" : "read from", addr,
351 /* ccb->mmcio.cmd.error ? */
352 error = sc->ccb->mmcio.cmd.resp[0] & 0xff;
354 if (sc->dev != NULL)
355 device_printf(sc->dev,
358 __func__, (wr) ? "write to" : "read from", addr,
362 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_INFO,
365 __func__, (wr) ? "write to" : "read from", addr,
374 bool wr, uint32_t size, uint8_t *buffer, bool incaddr)
384 while (sc->cardinfo.support_multiblk &&
385 size > 4 && size >= sc->cardinfo.f[fn].cur_blksize) {
386 b_count = size / sc->cardinfo.f[fn].cur_blksize;
389 sc->cardinfo.f[fn].cur_blksize));
397 len = b_count * sc->cardinfo.f[fn].cur_blksize;
398 error = sdiob_rw_extended_cam(sc, fn, addr, wr, buffer, incaddr,
399 b_count, sc->cardinfo.f[fn].cur_blksize);
403 size -= len;
410 len = MIN(size, sc->cardinfo.f[fn].cur_blksize);
412 error = sdiob_rw_extended_cam(sc, fn, addr, wr, buffer, incaddr,
418 size -= len;
428 sdiob_rw_extended(device_t dev, uint8_t fn, uint32_t addr, bool wr,
435 cam_periph_lock(sc->periph);
436 error = sdiob_rw_extended_sc(sc, fn, addr, wr, size, buffer, incaddr);
437 cam_periph_unlock(sc->periph);
457 /* -------------------------------------------------------------------------- */
475 *result = sc->cardinfo.support_multiblk;
481 *result = f->fn;
484 *result = f->class;
487 *result = f->vendor;
490 *result = f->device;
493 *result = f->drvdata;
519 f->drvdata = value;
528 /* -------------------------------------------------------------------------- */
539 device_set_desc(dev, "SDIO CAM-Newbus bridge");
560 for (i = 0; i < sc->cardinfo.num_funcs; i++) {
561 sc->child[i] = device_add_child(dev, NULL, DEVICE_UNIT_ANY);
562 if (sc->child[i] == NULL) {
566 sc->cardinfo.f[i].dev = sc->child[i];
569 device_set_ivars(sc->child[i], &sc->cardinfo.f[i]);
580 for (i = 1; i < sc->cardinfo.num_funcs; i++) {
581 error = device_probe_and_attach(sc->child[i]);
586 sc->child, device_get_nameunit(sc->child[i]),
590 sc->nb_state = NB_STATE_READY;
592 cam_periph_lock(sc->periph);
593 xpt_announce_periph(sc->periph, NULL);
594 cam_periph_unlock(sc->periph);
607 /* -------------------------------------------------------------------------- */
642 /* -------------------------------------------------------------------------- */
691 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_PERIPH,
692 ("%s: parse error: 0-length tuple %#02x\n",
726 sc->cardinfo.f[fn].vendor = v;
729 sc->cardinfo.f[fn].vendor |= (v << 8);
733 sc->cardinfo.f[fn].device = v;
736 sc->cardinfo.f[fn].device |= (v << 8);
760 sc->cardinfo.f[fn].max_blksize = v;
763 sc->cardinfo.f[fn].max_blksize |= (v << 8);
766 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_PERIPH,
806 CAM_DEBUG(sc->ccb->ccb_h.path, CAM_DEBUG_PERIPH,
825 return (-1);
827 memset(&sc->cardinfo, 0, sizeof(sc->cardinfo));
834 sc->cardinfo.num_funcs++;
839 sc->cardinfo.support_multiblk = (val & CCCR_CC_SMB) ? true : false;
842 __func__, fn, sc->cardinfo.f[fn].vendor, sc->cardinfo.f[fn].device,
843 sc->cardinfo.f[fn].max_blksize,
844 sc->cardinfo.support_multiblk ? "yes" : "no");
846 /* mmcp->sdio_func_count contains the number of functions w/o F0. */
847 mmcp = &sc->ccb->ccb_h.path->device->mmc_ident_data;
848 fn_max = MIN(mmcp->sdio_func_count + 1, nitems(sc->cardinfo.f));
874 sc->cardinfo.f[fn].class = (val & 0x0f);
875 if (sc->cardinfo.f[fn].class == 0x0f) {
879 sc->cardinfo.f[fn].class = val;
882 sc->cardinfo.f[fn].fn = fn;
883 sc->cardinfo.f[fn].cur_blksize = sc->cardinfo.f[fn].max_blksize;
884 sc->cardinfo.f[fn].retries = 0;
885 sc->cardinfo.f[fn].timeout = 5000;
889 sc->cardinfo.f[fn].class,
890 sc->cardinfo.f[fn].vendor, sc->cardinfo.f[fn].device,
891 sc->cardinfo.f[fn].max_blksize);
892 if (sc->cardinfo.f[fn].vendor == 0) {
896 sc->cardinfo.num_funcs++;
901 /* -------------------------------------------------------------------------- */
920 pdev = xpt_path_sim_device(sc->periph->path);
923 __func__, sc, sc->periph, sc->periph->sim));
925 if (sc->dev == NULL)
926 sc->dev = BUS_ADD_CHILD(pdev, 0, SDIOB_NAME_S, -1);
927 if (sc->dev == NULL)
929 device_set_softc(sc->dev, sc);
932 * Don't set description here; devclass_add_driver() ->
933 * device_probe_child() -> device_set_driver() will nuke it again.
953 sc->nb_state = NB_STATE_SIM_ADDED;
967 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("%s\n", __func__));
970 if ((periph->flags & CAM_PERIPH_INVALID) != 0) {
975 sc = periph->softc;
976 sc->sdio_state = SDIO_STATE_INITIALIZING;
978 if (sc->ccb == NULL)
979 sc->ccb = xpt_alloc_ccb();
981 memset(sc->ccb, 0, sizeof(*sc->ccb));
982 xpt_setup_ccb(&sc->ccb->ccb_h, periph->path, CAM_PRIORITY_NONE);
991 sc->sdio_state = SDIO_STATE_READY;
993 sc->sdio_state = SDIO_STATE_DEAD;
999 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("%s: num_func %d\n",
1000 __func__, sc->cardinfo.num_funcs));
1009 sc->nb_state = NB_STATE_DEAD;
1021 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("%s: arg %p\n", __func__, arg));
1027 if (xpt_path_sim_device(periph->path) == NULL) {
1028 printf("%s: no device_t for sim %p\n", __func__, periph->sim);
1038 sc->sdio_state = SDIO_STATE_DEAD;
1039 sc->nb_state = NB_STATE_DEAD;
1040 TASK_INIT(&sc->discover_task, 0, sdiobdiscover, periph);
1042 /* Refcount until we are setup. Can't block. */
1049 periph->softc = sc;
1050 sc->periph = periph;
1053 error = taskqueue_enqueue(taskqueue_thread, &sc->discover_task);
1068 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("%s:\n", __func__));
1077 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("%s:\n", __func__));
1086 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("%s: ccb %p\n", __func__, ccb));
1106 if (cgd->protocol != PROTO_MMCSD)
1110 if ((path->device->mmc_ident_data.card_features &