FreeBSD kernel CAM code
mmc_xpt.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2013,2014 Ilya Bakulin <ilya@bakulin.de>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include <sys/param.h>
33#include <sys/bus.h>
34#include <sys/endian.h>
35#include <sys/systm.h>
36#include <sys/types.h>
37#include <sys/malloc.h>
38#include <sys/kernel.h>
39#include <sys/time.h>
40#include <sys/conf.h>
41#include <sys/fcntl.h>
42#include <sys/interrupt.h>
43#include <sys/sbuf.h>
44
45#include <sys/lock.h>
46#include <sys/mutex.h>
47#include <sys/sysctl.h>
48#include <sys/condvar.h>
49
50#include <cam/cam.h>
51#include <cam/cam_ccb.h>
52#include <cam/cam_queue.h>
53#include <cam/cam_periph.h>
54#include <cam/cam_sim.h>
55#include <cam/cam_xpt.h>
56#include <cam/cam_xpt_sim.h>
57#include <cam/cam_xpt_periph.h>
59#include <cam/cam_debug.h>
60
61#include <cam/mmc/mmc.h>
62#include <cam/mmc/mmc_bus.h>
63
64#include <machine/stdarg.h> /* for xpt_print below */
65#include <machine/_inttypes.h> /* for PRIu64 */
66#include "opt_cam.h"
67
68FEATURE(mmccam, "CAM-based MMC/SD/SDIO stack");
69
70static struct cam_ed * mmc_alloc_device(struct cam_eb *bus,
71 struct cam_et *target, lun_id_t lun_id);
72static void mmc_dev_async(u_int32_t async_code, struct cam_eb *bus,
73 struct cam_et *target, struct cam_ed *device, void *async_arg);
74static void mmc_action(union ccb *start_ccb);
75static void mmc_dev_advinfo(union ccb *start_ccb);
76static void mmc_announce_periph(struct cam_periph *periph);
77static void mmc_scan_lun(struct cam_periph *periph,
78 struct cam_path *path, cam_flags flags, union ccb *ccb);
79
80/* mmcprobe methods */
81static cam_status mmcprobe_register(struct cam_periph *periph, void *arg);
82static void mmcprobe_start(struct cam_periph *periph, union ccb *start_ccb);
83static void mmcprobe_cleanup(struct cam_periph *periph);
84static void mmcprobe_done(struct cam_periph *periph, union ccb *done_ccb);
85
86static void mmc_proto_announce(struct cam_ed *device);
87static void mmc_proto_denounce(struct cam_ed *device);
88static void mmc_proto_debug_out(union ccb *ccb);
89
90typedef enum {
112
113static char *probe_action_text[] = {
114 "PROBE_RESET",
115 "PROBE_IDENTIFY",
116 "PROBE_POWER_OFF",
117 "PROBE_GET_HOST_OCR",
118 "PROBE_RESET_BUS",
119 "PROBE_SET_ID_FREQ",
120 "PROBE_SET_CS",
121 "PROBE_GO_IDLE_STATE",
122 "PROBE_SDIO_RESET",
123 "PROBE_SEND_IF_COND",
124 "PROBE_SDIO_INIT",
125 "PROBE_MMC_INIT",
126 "PROBE_SEND_APP_OP_COND",
127 "PROBE_GET_CID",
128 "PROBE_GET_CSD",
129 "PROBE_SEND_RELATIVE_ADDR",
130 "PROBE_MMC_SET_RELATIVE_ADDR",
131 "PROBE_SELECT_CARD",
132 "PROBE_DONE",
133 "PROBE_INVALID"
134};
135
136#define PROBE_SET_ACTION(softc, newaction) \
137do { \
138 char **text; \
139 text = probe_action_text; \
140 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
141 ("Probe %s to %s\n", text[(softc)->action], \
142 text[(newaction)])); \
143 (softc)->action = (newaction); \
144} while(0)
145
148 .action = mmc_action,
149 .async = mmc_dev_async,
150 .announce = mmc_announce_periph,
151};
152
153#define MMC_XPT_XPORT(x, X) \
154 static struct xpt_xport mmc_xport_ ## x = { \
155 .xport = XPORT_ ## X, \
156 .name = #x, \
157 .ops = &mmc_xport_ops, \
158 }; \
159 CAM_XPT_XPORT(mmc_xport_ ## x);
160
161MMC_XPT_XPORT(mmc, MMCSD);
162
165 .denounce = mmc_proto_denounce,
166 .debug_out = mmc_proto_debug_out,
167};
168
169static struct xpt_proto mmc_proto = {
171 .name = "mmcsd",
172 .ops = &mmc_proto_ops,
173};
175
176typedef struct {
179 uint32_t host_ocr;
180 uint32_t flags;
181#define PROBE_FLAG_ACMD_SENT 0x1 /* CMD55 is sent, card expects ACMD */
182#define PROBE_FLAG_HOST_CAN_DO_18V 0x2 /* Host can do 1.8V signaling */
183 uint8_t acmd41_count; /* how many times ACMD41 has been issued */
186
187/* XPort functions -- an interface to CAM at periph side */
188
189static struct cam_ed *
191{
192 struct cam_ed *device;
193
194 device = xpt_alloc_device(bus, target, lun_id);
195 if (device == NULL)
196 return (NULL);
197
198 device->quirk = NULL;
199 device->mintags = 0;
200 device->maxtags = 0;
201 bzero(&device->inq_data, sizeof(device->inq_data));
202 device->inq_flags = 0;
203 device->queue_flags = 0;
204 device->serial_num = NULL;
205 device->serial_num_len = 0;
206 return (device);
207}
208
209static void
210mmc_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
211 struct cam_ed *device, void *async_arg)
212{
213
214 /*
215 * We only need to handle events for real devices.
216 */
218 || device->lun_id == CAM_LUN_WILDCARD)
219 return;
220
221 if (async_code == AC_LOST_DEVICE &&
222 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
223 device->flags |= CAM_DEV_UNCONFIGURED;
224 xpt_release_device(device);
225 }
226}
227
228/* Taken from nvme_scan_lun, thanks to bsdimp@ */
229static void
230mmc_scan_lun(struct cam_periph *periph, struct cam_path *path,
231 cam_flags flags, union ccb *request_ccb)
232{
233 struct ccb_pathinq cpi;
234 cam_status status;
235 struct cam_periph *old_periph;
236 int lock;
237
238 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("mmc_scan_lun\n"));
239
240 xpt_path_inq(&cpi, path);
241
242 if (cpi.ccb_h.status != CAM_REQ_CMP) {
243 if (request_ccb != NULL) {
244 request_ccb->ccb_h.status = cpi.ccb_h.status;
245 xpt_done(request_ccb);
246 }
247 return;
248 }
249
251 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("mmd_scan_lun ignoring bus\n"));
252 request_ccb->ccb_h.status = CAM_REQ_CMP; /* XXX signal error ? */
253 xpt_done(request_ccb);
254 return;
255 }
256
257 lock = (xpt_path_owned(path) == 0);
258 if (lock)
260
261 if ((old_periph = cam_periph_find(path, "mmcprobe")) != NULL) {
262 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
263// mmcprobe_softc *softc;
264// softc = (mmcprobe_softc *)old_periph->softc;
265// Not sure if we need request ccb queue for mmc
266// TAILQ_INSERT_TAIL(&softc->request_ccbs,
267// &request_ccb->ccb_h, periph_links.tqe);
268// softc->restart = 1;
270 ("Got scan request, but mmcprobe already exists\n"));
271 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
272 xpt_done(request_ccb);
273 } else {
274 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
275 xpt_done(request_ccb);
276 }
277 } else {
279 (" Set up the mmcprobe device...\n"));
280
281 status = cam_periph_alloc(mmcprobe_register, NULL,
284 "mmcprobe",
286 path, NULL, 0,
287 request_ccb);
288 if (status != CAM_REQ_CMP) {
289 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
290 "returned an error, can't continue probe\n");
291 }
292 request_ccb->ccb_h.status = status;
293 xpt_done(request_ccb);
294 }
295
296 if (lock)
298}
299
300static void
301mmc_action(union ccb *start_ccb)
302{
304 ("mmc_action! func_code=%x, action %s\n", start_ccb->ccb_h.func_code,
305 xpt_action_name(start_ccb->ccb_h.func_code)));
306 switch (start_ccb->ccb_h.func_code) {
307 case XPT_SCAN_BUS:
308 /* FALLTHROUGH */
309 case XPT_SCAN_TGT:
310 /* FALLTHROUGH */
311 case XPT_SCAN_LUN:
313 ("XPT_SCAN_{BUS,TGT,LUN}\n"));
314 mmc_scan_lun(start_ccb->ccb_h.path->periph,
315 start_ccb->ccb_h.path, start_ccb->crcn.flags,
316 start_ccb);
317 break;
318
319 case XPT_DEV_ADVINFO:
320 {
321 mmc_dev_advinfo(start_ccb);
322 break;
323 }
324
325 default:
326 xpt_action_default(start_ccb);
327 break;
328 }
329}
330
331static void
332mmc_dev_advinfo(union ccb *start_ccb)
333{
334 struct cam_ed *device;
335 struct ccb_dev_advinfo *cdai;
336 off_t amt;
337
338 xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
339 start_ccb->ccb_h.status = CAM_REQ_INVALID;
340 device = start_ccb->ccb_h.path->device;
341 cdai = &start_ccb->cdai;
343 ("%s: request %x\n", __func__, cdai->buftype));
344
345 /* We don't support writing any data */
346 if (cdai->flags & CDAI_FLAG_STORE)
347 panic("Attempt to store data?!");
348
349 switch(cdai->buftype) {
351 cdai->provsiz = device->device_id_len;
352 if (device->device_id_len == 0)
353 break;
354 amt = MIN(cdai->provsiz, cdai->bufsiz);
355 memcpy(cdai->buf, device->device_id, amt);
356 break;
358 cdai->provsiz = device->serial_num_len;
359 if (device->serial_num_len == 0)
360 break;
361 amt = MIN(cdai->provsiz, cdai->bufsiz);
362 memcpy(cdai->buf, device->serial_num, amt);
363 break;
364 case CDAI_TYPE_PHYS_PATH: /* pass(4) wants this */
365 cdai->provsiz = 0;
366 break;
368 cdai->provsiz = sizeof(struct mmc_params);
369 amt = MIN(cdai->provsiz, cdai->bufsiz);
370 memcpy(cdai->buf, &device->mmc_ident_data, amt);
371 break;
372 default:
373 panic("Unknown buftype");
374 return;
375 }
376 start_ccb->ccb_h.status = CAM_REQ_CMP;
377}
378
379static void
381{
382 struct ccb_pathinq cpi;
383 struct ccb_trans_settings cts;
384 struct cam_path *path = periph->path;
385
386 cam_periph_assert(periph, MA_OWNED);
387
388 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("mmc_announce_periph"));
389
390 memset(&cts, 0, sizeof(cts));
392 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
394 xpt_action((union ccb*)&cts);
395 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
396 return;
397 xpt_path_inq(&cpi, periph->path);
399 ("XPT info: CLK %04d, ...\n", cts.proto_specific.mmc.ios.clock));
400}
401
402void
404{
405 union ccb *ccb;
406 uint32_t pathid;
407
408 pathid = cam_sim_path(sim);
409 ccb = xpt_alloc_ccb();
410
411 /*
412 * We create a rescan request for BUS:0:0, since the card
413 * will be at lun 0.
414 */
415 if (xpt_create_path(&ccb->ccb_h.path, NULL, pathid,
416 /* target */ 0, /* lun */ 0) != CAM_REQ_CMP) {
418 return;
419 }
420
421 KASSERT(xpt_path_sim_device(ccb->ccb_h.path) != NULL,
422 ("%s(%s): device is not initialized on sim's path",
423 __func__, cam_sim_name(sim)));
425}
426
427/* This func is called per attached device :-( */
428static void
429mmc_print_ident(struct mmc_params *ident_data, struct sbuf *sb)
430{
431 bool space = false;
432
433 sbuf_printf(sb, "Relative addr: %08x\n", ident_data->card_rca);
434 sbuf_printf(sb, "Card features: <");
435 if (ident_data->card_features & CARD_FEATURE_MMC) {
436 sbuf_printf(sb, "MMC");
437 space = true;
438 }
439 if (ident_data->card_features & CARD_FEATURE_MEMORY) {
440 sbuf_printf(sb, "%sMemory", space ? " " : "");
441 space = true;
442 }
443 if (ident_data->card_features & CARD_FEATURE_SDHC) {
444 sbuf_printf(sb, "%sHigh-Capacity", space ? " " : "");
445 space = true;
446 }
447 if (ident_data->card_features & CARD_FEATURE_SD20) {
448 sbuf_printf(sb, "%sSD2.0-Conditions", space ? " " : "");
449 space = true;
450 }
451 if (ident_data->card_features & CARD_FEATURE_SDIO) {
452 sbuf_printf(sb, "%sSDIO", space ? " " : "");
453 space = true;
454 }
455 if (ident_data->card_features & CARD_FEATURE_18V) {
456 sbuf_printf(sb, "%s1.8-Signaling", space ? " " : "");
457 }
458 sbuf_printf(sb, ">\n");
459
460 if (ident_data->card_features & CARD_FEATURE_MEMORY)
461 sbuf_printf(sb, "Card memory OCR: %08x\n",
462 ident_data->card_ocr);
463
464 if (ident_data->card_features & CARD_FEATURE_SDIO) {
465 sbuf_printf(sb, "Card IO OCR: %08x\n", ident_data->io_ocr);
466 sbuf_printf(sb, "Number of functions: %u\n",
467 ident_data->sdio_func_count);
468 }
469
470 sbuf_finish(sb);
471 printf("%s", sbuf_data(sb));
472 sbuf_clear(sb);
473}
474
475static void
477{
478 struct sbuf sb;
479 char buffer[256];
480
481 sbuf_new(&sb, buffer, sizeof(buffer), SBUF_FIXEDLEN);
482 mmc_print_ident(&device->mmc_ident_data, &sb);
483 sbuf_finish(&sb);
484 sbuf_putbuf(&sb);
485}
486
487static void
489{
490
491 mmc_proto_announce(device);
492}
493
494static void
496{
498 return;
499
501 CAM_DEBUG_CDB,("mmc_proto_debug_out\n"));
502}
503
505
507{
508 probe_periph_init, "mmcprobe",
509 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
511};
512
514
515#define CARD_ID_FREQUENCY 400000 /* Spec requires 400kHz max during ID phase. */
516
517static void
519{
520}
521
522static cam_status
523mmcprobe_register(struct cam_periph *periph, void *arg)
524{
525 mmcprobe_softc *softc;
526 union ccb *request_ccb; /* CCB representing the probe request */
527 int status;
528
529 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("mmcprobe_register\n"));
530
531 request_ccb = (union ccb *)arg;
532 if (request_ccb == NULL) {
533 printf("mmcprobe_register: no probe CCB, "
534 "can't register device\n");
535 return(CAM_REQ_CMP_ERR);
536 }
537
538 softc = (mmcprobe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
539
540 if (softc == NULL) {
541 printf("proberegister: Unable to probe new device. "
542 "Unable to allocate softc\n");
543 return(CAM_REQ_CMP_ERR);
544 }
545
546 softc->flags = 0;
547 softc->acmd41_count = 0;
548 periph->softc = softc;
549 softc->periph = periph;
550 softc->action = PROBE_INVALID;
551 softc->restart = 0;
552 status = cam_periph_acquire(periph);
553
554 memset(&periph->path->device->mmc_ident_data, 0, sizeof(struct mmc_params));
555 if (status != 0) {
556 printf("proberegister: cam_periph_acquire failed (status=%d)\n",
557 status);
558 return (CAM_REQ_CMP_ERR);
559 }
560 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
561
562 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
564 else
566
567 /* This will kick the ball */
569
570 return(CAM_REQ_CMP);
571}
572
573static int
575{
576 int i;
577
578 for (i = MMC_OCR_MAX_VOLTAGE_SHIFT;
579 i >= MMC_OCR_MIN_VOLTAGE_SHIFT; i--)
580 if (ocr & (1 << i))
581 return (i);
582 return (-1);
583}
584
585static inline void
586init_standard_ccb(union ccb *ccb, uint32_t cmd)
587{
588 ccb->ccb_h.func_code = cmd;
590 ccb->ccb_h.retry_count = 0;
591 ccb->ccb_h.timeout = 15 * 1000;
593}
594
595static void
596mmcprobe_start(struct cam_periph *periph, union ccb *start_ccb)
597{
598 mmcprobe_softc *softc;
599 struct cam_path *path;
600 struct ccb_mmcio *mmcio;
602
603 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("mmcprobe_start\n"));
604 softc = (mmcprobe_softc *)periph->softc;
605 path = start_ccb->ccb_h.path;
606 mmcio = &start_ccb->mmcio;
607 cts = &start_ccb->cts.proto_specific.mmc;
608 struct mmc_params *mmcp = &path->device->mmc_ident_data;
609
610 memset(&mmcio->cmd, 0, sizeof(struct mmc_command));
611
612 if (softc->restart) {
613 softc->restart = 0;
614 if (path->device->flags & CAM_DEV_UNCONFIGURED)
615 softc->action = PROBE_RESET;
616 else
617 softc->action = PROBE_IDENTIFY;
618 }
619
620 /* Here is the place where the identify fun begins */
621 switch (softc->action) {
622 case PROBE_RESET:
623 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("Start with PROBE_RESET\n"));
624 /* FALLTHROUGH */
625 case PROBE_IDENTIFY:
626 xpt_path_inq(&start_ccb->cpi, periph->path);
627 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("Start with PROBE_IDENTIFY\n"));
629 break;
630
631 case PROBE_POWER_OFF:
632 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("power off the card\n"));
634 cts->ios.power_mode = power_off;
636 break;
637
639 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("get the host ocr\n"));
641 break;
642
643 case PROBE_RESET_BUS:
644 {
645 uint32_t host_caps = cts->host_caps;
648 uint32_t hv = mmc_highest_voltage(softc->host_ocr);
649 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("reseting the bus\n"));
651 cts->ios.vdd = hv;
652 cts->ios.bus_mode = opendrain;
653 cts->ios.chip_select = cs_dontcare;
654 cts->ios.power_mode = power_up;
655 cts->ios.bus_width = bus_width_1;
656 cts->ios.clock = 0;
659 break;
660 }
661
663 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("setting the ID freq\n"));
665 cts->ios.power_mode = power_on;
666 cts->ios.clock = CARD_ID_FREQUENCY;
667 cts->ios.timing = bus_timing_normal;
669 break;
670
671 case PROBE_SET_CS:
672 /* Begin mmc_idle_cards() */
674 cts->ios.chip_select = cs_high;
676 break;
677
679 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("Send first XPT_MMC_IO\n"));
680 init_standard_ccb(start_ccb, XPT_MMC_IO);
681 mmcio->cmd.opcode = MMC_GO_IDLE_STATE; /* CMD 0 */
682 mmcio->cmd.arg = 0;
683 mmcio->cmd.flags = MMC_RSP_NONE | MMC_CMD_BC;
684 mmcio->cmd.data = NULL;
685 mmcio->stop.opcode = 0;
686
687 /* XXX Reset I/O portion as well */
688 break;
689
690 case PROBE_SDIO_RESET:
692 ("Start with PROBE_SDIO_RESET\n"));
693 uint32_t mmc_arg = SD_IO_RW_ADR(SD_IO_CCCR_CTL)
694 | SD_IO_RW_DAT(CCCR_CTL_RES) | SD_IO_RW_WR | SD_IO_RW_RAW;
695 cam_fill_mmcio(&start_ccb->mmcio,
696 /*retries*/ 0,
697 /*cbfcnp*/ mmcprobe_done,
698 /*flags*/ CAM_DIR_NONE,
699 /*mmc_opcode*/ SD_IO_RW_DIRECT,
700 /*mmc_arg*/ mmc_arg,
701 /*mmc_flags*/ MMC_RSP_R5 | MMC_CMD_AC,
702 /*mmc_data*/ NULL,
703 /*timeout*/ 1000);
704 break;
707 ("Start with PROBE_SEND_IF_COND\n"));
708 init_standard_ccb(start_ccb, XPT_MMC_IO);
709 mmcio->cmd.opcode = SD_SEND_IF_COND; /* CMD 8 */
710 mmcio->cmd.arg = (1 << 8) + 0xAA;
711 mmcio->cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR;
712 mmcio->stop.opcode = 0;
713 break;
714
715 case PROBE_SDIO_INIT:
717 ("Start with PROBE_SDIO_INIT\n"));
718 init_standard_ccb(start_ccb, XPT_MMC_IO);
719 mmcio->cmd.opcode = IO_SEND_OP_COND; /* CMD 5 */
720 mmcio->cmd.arg = mmcp->io_ocr;
721 mmcio->cmd.flags = MMC_RSP_R4;
722 mmcio->stop.opcode = 0;
723 break;
724
725 case PROBE_MMC_INIT:
727 ("Start with PROBE_MMC_INIT\n"));
728 init_standard_ccb(start_ccb, XPT_MMC_IO);
729 mmcio->cmd.opcode = MMC_SEND_OP_COND; /* CMD 1 */
730 mmcio->cmd.arg = MMC_OCR_CCS | mmcp->card_ocr; /* CCS + ocr */;
731 mmcio->cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
732 mmcio->stop.opcode = 0;
733 break;
734
736 init_standard_ccb(start_ccb, XPT_MMC_IO);
737 if (softc->flags & PROBE_FLAG_ACMD_SENT) {
738 mmcio->cmd.opcode = ACMD_SD_SEND_OP_COND; /* CMD 41 */
739 /*
740 * We set CCS bit because we do support SDHC cards.
741 * XXX: Don't set CCS if no response to CMD8.
742 */
743 uint32_t cmd_arg = MMC_OCR_CCS | mmcp->card_ocr; /* CCS + ocr */
744 if (softc->acmd41_count < 10 && mmcp->card_ocr != 0 )
745 cmd_arg |= MMC_OCR_S18R;
746 mmcio->cmd.arg = cmd_arg;
747 mmcio->cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR;
748 softc->acmd41_count++;
749 } else {
750 mmcio->cmd.opcode = MMC_APP_CMD; /* CMD 55 */
751 mmcio->cmd.arg = 0; /* rca << 16 */
752 mmcio->cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
753 }
754 mmcio->stop.opcode = 0;
755 break;
756
757 case PROBE_GET_CID: /* XXX move to mmc_da */
758 init_standard_ccb(start_ccb, XPT_MMC_IO);
759 mmcio->cmd.opcode = MMC_ALL_SEND_CID;
760 mmcio->cmd.arg = 0;
761 mmcio->cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
762 mmcio->stop.opcode = 0;
763 break;
765 init_standard_ccb(start_ccb, XPT_MMC_IO);
766 mmcio->cmd.opcode = SD_SEND_RELATIVE_ADDR;
767 mmcio->cmd.arg = 0;
768 mmcio->cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
769 mmcio->stop.opcode = 0;
770 break;
772 init_standard_ccb(start_ccb, XPT_MMC_IO);
773 mmcio->cmd.opcode = MMC_SET_RELATIVE_ADDR;
774 mmcio->cmd.arg = MMC_PROPOSED_RCA << 16;
775 mmcio->cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
776 mmcio->stop.opcode = 0;
777 break;
779 init_standard_ccb(start_ccb, XPT_MMC_IO);
780 mmcio->cmd.opcode = MMC_SELECT_CARD;
781 mmcio->cmd.arg = (uint32_t)path->device->mmc_ident_data.card_rca << 16;
782 mmcio->cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
783 mmcio->stop.opcode = 0;
784 break;
785 case PROBE_GET_CSD: /* XXX move to mmc_da */
786 init_standard_ccb(start_ccb, XPT_MMC_IO);
787 mmcio->cmd.opcode = MMC_SEND_CSD;
788 mmcio->cmd.arg = (uint32_t)path->device->mmc_ident_data.card_rca << 16;
789 mmcio->cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
790 mmcio->stop.opcode = 0;
791 break;
792 case PROBE_DONE:
793 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("Start with PROBE_DONE\n"));
795 cts->ios.bus_mode = pushpull;
797 xpt_action(start_ccb);
798 return;
799 /* NOTREACHED */
800 break;
801 case PROBE_INVALID:
802 break;
803 default:
804 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("probestart: invalid action state 0x%x\n", softc->action));
805 panic("default: case in mmc_probe_start()");
806 }
807
808 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
809 xpt_action(start_ccb);
810}
811
812static void mmcprobe_cleanup(struct cam_periph *periph)
813{
814 free(periph->softc, M_CAMXPT);
815}
816
817static void
818mmcprobe_done(struct cam_periph *periph, union ccb *done_ccb)
819{
820 mmcprobe_softc *softc;
821 struct cam_path *path;
822
823 int err;
824 struct ccb_mmcio *mmcio;
825 u_int32_t priority;
826
827 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("mmcprobe_done\n"));
828 softc = (mmcprobe_softc *)periph->softc;
829 path = done_ccb->ccb_h.path;
830 priority = done_ccb->ccb_h.pinfo.priority;
831
832 switch (softc->action) {
833 case PROBE_RESET:
834 /* FALLTHROUGH */
835 case PROBE_IDENTIFY:
836 {
837 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_RESET\n"));
839 break;
840 }
841 case PROBE_POWER_OFF:
842 {
843 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_POWER_OFF\n"));
845 break;
846 }
848 {
850 cts = &done_ccb->cts.proto_specific.mmc;
851 softc->host_ocr = cts->host_ocr;
852 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_GET_HOST_OCR (Got OCR=%x\n", softc->host_ocr));
854 break;
855 }
856 case PROBE_RESET_BUS:
857 {
858 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_RESET_BUS\n"));
860 break;
861 }
863 {
864 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_SET_ID_FREQ\n"));
866 break;
867 }
868 case PROBE_SET_CS:
869 {
870 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_SET_CS\n"));
872 break;
873 }
875 {
876 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("done with PROBE_GO_IDLE_STATE\n"));
877 mmcio = &done_ccb->mmcio;
878 err = mmcio->cmd.error;
879
880 if (err != MMC_ERR_NONE) {
882 ("GO_IDLE_STATE failed with error %d\n",
883 err));
884
885 /* There was a device there, but now it's gone... */
886 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
888 ("Device lost!\n"));
889
890 xpt_async(AC_LOST_DEVICE, path, NULL);
891 }
893 break;
894 }
895 path->device->protocol = PROTO_MMCSD;
897 break;
898 }
900 {
901 mmcio = &done_ccb->mmcio;
902 err = mmcio->cmd.error;
903 struct mmc_params *mmcp = &path->device->mmc_ident_data;
904
905 if (err != MMC_ERR_NONE || mmcio->cmd.resp[0] != 0x1AA) {
907 ("IF_COND: error %d, pattern %08x\n",
908 err, mmcio->cmd.resp[0]));
909 } else {
912 ("SD 2.0 interface conditions: OK\n"));
913 }
915 break;
916 }
917 case PROBE_SDIO_RESET:
918 {
919 mmcio = &done_ccb->mmcio;
920 err = mmcio->cmd.error;
921
923 ("SDIO_RESET: error %d, CCCR CTL register: %08x\n",
924 err, mmcio->cmd.resp[0]));
926 break;
927 }
928 case PROBE_SDIO_INIT:
929 {
930 mmcio = &done_ccb->mmcio;
931 err = mmcio->cmd.error;
932 struct mmc_params *mmcp = &path->device->mmc_ident_data;
933
935 ("SDIO_INIT: error %d, %08x %08x %08x %08x\n",
936 err, mmcio->cmd.resp[0],
937 mmcio->cmd.resp[1],
938 mmcio->cmd.resp[2],
939 mmcio->cmd.resp[3]));
940
941 /*
942 * Error here means that this card is not SDIO,
943 * so proceed with memory init as if nothing has happened
944 */
945 if (err != MMC_ERR_NONE) {
947 break;
948 }
950 uint32_t ioifcond = mmcio->cmd.resp[0];
951 uint32_t io_ocr = ioifcond & R4_IO_OCR_MASK;
952
953 mmcp->sdio_func_count = R4_IO_NUM_FUNCTIONS(ioifcond);
955 ("SDIO card: %d functions\n", mmcp->sdio_func_count));
956 if (io_ocr == 0) {
958 ("SDIO OCR invalid, retrying\n"));
959 break; /* Retry */
960 }
961
962 if (io_ocr != 0 && mmcp->io_ocr == 0) {
963 mmcp->io_ocr = io_ocr;
964 break; /* Retry, this time with non-0 OCR */
965 }
967 ("SDIO OCR: %08x\n", mmcp->io_ocr));
968
969 if (ioifcond & R4_IO_MEM_PRESENT) {
970 /* Combo card -- proceed to memory initialization */
972 } else {
973 /* No memory portion -- get RCA and select card */
975 }
976 break;
977 }
978 case PROBE_MMC_INIT:
979 {
980 mmcio = &done_ccb->mmcio;
981 err = mmcio->cmd.error;
982 struct mmc_params *mmcp = &path->device->mmc_ident_data;
983
984 if (err != MMC_ERR_NONE) {
986 ("MMC_INIT: error %d, resp %08x\n",
987 err, mmcio->cmd.resp[0]));
989 break;
990 }
992 ("MMC card, OCR %08x\n", mmcio->cmd.resp[0]));
993
994 if (mmcp->card_ocr == 0) {
995 /* We haven't sent the OCR to the card yet -- do it */
996 mmcp->card_ocr = mmcio->cmd.resp[0];
998 ("-> sending OCR to card\n"));
999 break;
1000 }
1001
1002 if (!(mmcio->cmd.resp[0] & MMC_OCR_CARD_BUSY)) {
1004 ("Card is still powering up\n"));
1005 break;
1006 }
1007
1010 break;
1011 }
1013 {
1014 mmcio = &done_ccb->mmcio;
1015 err = mmcio->cmd.error;
1016
1017 if (err != MMC_ERR_NONE) {
1019 ("APP_OP_COND: error %d, resp %08x\n",
1020 err, mmcio->cmd.resp[0]));
1022 break;
1023 }
1024
1025 if (!(softc->flags & PROBE_FLAG_ACMD_SENT)) {
1026 /* Don't change the state */
1027 softc->flags |= PROBE_FLAG_ACMD_SENT;
1028 break;
1029 }
1030
1031 softc->flags &= ~PROBE_FLAG_ACMD_SENT;
1032 if ((mmcio->cmd.resp[0] & MMC_OCR_CARD_BUSY) ||
1033 (mmcio->cmd.arg & MMC_OCR_VOLTAGE) == 0) {
1034 struct mmc_params *mmcp = &path->device->mmc_ident_data;
1036 ("Card OCR: %08x\n", mmcio->cmd.resp[0]));
1037 if (mmcp->card_ocr == 0) {
1038 mmcp->card_ocr = mmcio->cmd.resp[0];
1039 /* Now when we know OCR that we want -- send it to card */
1041 ("-> sending OCR to card\n"));
1042 } else {
1043 /* We already know the OCR and despite of that we
1044 * are processing the answer to ACMD41 -> move on
1045 */
1047 }
1048 /* Getting an answer to ACMD41 means the card has memory */
1050
1051 /* Standard capacity vs High Capacity memory card */
1052 if (mmcio->cmd.resp[0] & MMC_OCR_CCS) {
1054 ("Card is SDHC\n"));
1056 }
1057
1058 /* Whether the card supports 1.8V signaling */
1059 if (mmcio->cmd.resp[0] & MMC_OCR_S18A) {
1061 ("Card supports 1.8V signaling\n"));
1063 if (softc->flags & PROBE_FLAG_HOST_CAN_DO_18V) {
1065 ("Host supports 1.8V signaling. Switch voltage!\n"));
1067 done_ccb->ccb_h.flags = CAM_DIR_NONE;
1068 done_ccb->ccb_h.retry_count = 0;
1069 done_ccb->ccb_h.timeout = 100;
1070 done_ccb->ccb_h.cbfcnp = NULL;
1071 done_ccb->cts.proto_specific.mmc.ios.vccq = vccq_180;
1073 xpt_action(done_ccb);
1074 }
1075 }
1076 } else {
1078 ("Card not ready: %08x\n", mmcio->cmd.resp[0]));
1079 /* Send CMD55+ACMD41 once again */
1081 }
1082
1083 break;
1084 }
1085 case PROBE_GET_CID: /* XXX move to mmc_da */
1086 {
1087 mmcio = &done_ccb->mmcio;
1088 err = mmcio->cmd.error;
1089
1090 if (err != MMC_ERR_NONE) {
1092 ("PROBE_GET_CID: error %d\n", err));
1094 break;
1095 }
1096
1097 struct mmc_params *mmcp = &path->device->mmc_ident_data;
1098 memcpy(mmcp->card_cid, mmcio->cmd.resp, 4 * sizeof(uint32_t));
1100 ("CID %08x%08x%08x%08x\n",
1101 mmcp->card_cid[0],
1102 mmcp->card_cid[1],
1103 mmcp->card_cid[2],
1104 mmcp->card_cid[3]));
1105 if (mmcp->card_features & CARD_FEATURE_MMC)
1107 else
1109 break;
1110 }
1112 mmcio = &done_ccb->mmcio;
1113 err = mmcio->cmd.error;
1114 struct mmc_params *mmcp = &path->device->mmc_ident_data;
1115 uint16_t rca = mmcio->cmd.resp[0] >> 16;
1117 ("Card published RCA: %u\n", rca));
1118 path->device->mmc_ident_data.card_rca = rca;
1119 if (err != MMC_ERR_NONE) {
1121 ("PROBE_SEND_RELATIVE_ADDR: error %d\n", err));
1123 break;
1124 }
1125
1126 /* If memory is present, get CSD, otherwise select card */
1129 else
1131 break;
1132 }
1134 mmcio = &done_ccb->mmcio;
1135 err = mmcio->cmd.error;
1136 if (err != MMC_ERR_NONE) {
1138 ("PROBE_MMC_SET_RELATIVE_ADDR: error %d\n", err));
1140 break;
1141 }
1144 break;
1145 case PROBE_GET_CSD: {
1146 mmcio = &done_ccb->mmcio;
1147 err = mmcio->cmd.error;
1148
1149 if (err != MMC_ERR_NONE) {
1151 ("PROBE_GET_CSD: error %d\n", err));
1153 break;
1154 }
1155
1156 struct mmc_params *mmcp = &path->device->mmc_ident_data;
1157 memcpy(mmcp->card_csd, mmcio->cmd.resp, 4 * sizeof(uint32_t));
1159 ("CSD %08x%08x%08x%08x\n",
1160 mmcp->card_csd[0],
1161 mmcp->card_csd[1],
1162 mmcp->card_csd[2],
1163 mmcp->card_csd[3]));
1165 break;
1166 }
1167 case PROBE_SELECT_CARD: {
1168 mmcio = &done_ccb->mmcio;
1169 err = mmcio->cmd.error;
1170 if (err != MMC_ERR_NONE) {
1172 ("PROBE_SEND_RELATIVE_ADDR: error %d\n", err));
1174 break;
1175 }
1176
1178 break;
1179 }
1180 default:
1182 ("mmcprobe_done: invalid action state 0x%x\n", softc->action));
1183 panic("default: case in mmc_probe_done()");
1184 }
1185
1186 if (softc->action == PROBE_INVALID &&
1187 (path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1188 xpt_async(AC_LOST_DEVICE, path, NULL);
1189 }
1190
1191 if (softc->action != PROBE_INVALID)
1192 xpt_schedule(periph, priority);
1193 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1194 int frozen = cam_release_devq(path, 0, 0, 0, FALSE);
1196 ("mmcprobe_done: remaining freeze count %d\n", frozen));
1197
1198 if (softc->action == PROBE_DONE) {
1199 /* Notify the system that the device is found! */
1200 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1201 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1203 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1204 xpt_action(done_ccb);
1205 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1206 }
1207 }
1208 xpt_release_ccb(done_ccb);
1209 if (softc->action == PROBE_DONE || softc->action == PROBE_INVALID) {
1210 cam_periph_invalidate(periph);
1212 }
1213}
1214
1215void
1216mmc_path_inq(struct ccb_pathinq *cpi, const char *hba,
1217 const struct cam_sim *sim, size_t maxio)
1218{
1219
1220 cpi->version_num = 1;
1221 cpi->hba_inquiry = 0;
1222 cpi->target_sprt = 0;
1224 cpi->hba_eng_cnt = 0;
1225 cpi->max_target = 0;
1226 cpi->max_lun = 0;
1227 cpi->initiator_id = 1;
1228 cpi->maxio = maxio;
1229 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
1230 strncpy(cpi->hba_vid, hba, HBA_IDLEN);
1231 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
1232 cpi->unit_number = cam_sim_unit(sim);
1233 cpi->bus_id = cam_sim_bus(sim);
1234 cpi->protocol = PROTO_MMCSD;
1236 cpi->transport = XPORT_MMCSD;
1237 cpi->transport_version = 1;
1238
1239 cpi->base_transfer_speed = 100; /* XXX WTF? */
1240
1241 cpi->ccb_h.status = CAM_REQ_CMP;
1242}
#define CAM_TARGET_WILDCARD
Definition: cam.h:48
cam_flags
Definition: cam.h:115
#define CAM_LUN_WILDCARD
Definition: cam.h:49
#define CAM_PRIORITY_NORMAL
Definition: cam.h:92
#define CAM_PRIORITY_XPT
Definition: cam.h:89
cam_status
Definition: cam.h:132
@ CAM_REQ_INVALID
Definition: cam.h:152
@ CAM_REQ_CMP
Definition: cam.h:137
@ CAM_REQ_CMP_ERR
Definition: cam.h:146
@ CAM_STATUS_MASK
Definition: cam.h:302
u_int64_t lun_id_t
Definition: cam.h:44
@ AC_FOUND_DEVICE
Definition: cam_ccb.h:874
@ AC_LOST_DEVICE
Definition: cam_ccb.h:873
#define CDAI_FLAG_STORE
Definition: cam_ccb.h:1312
@ PROTO_MMCSD
Definition: cam_ccb.h:285
@ CTS_TYPE_CURRENT_SETTINGS
Definition: cam_ccb.h:945
@ PIM_NOBUSRESET
Definition: cam_ccb.h:622
@ PIM_SEQSCAN
Definition: cam_ccb.h:624
#define MMC_VCCQ
Definition: cam_ccb.h:1065
#define MMC_BM
Definition: cam_ccb.h:1064
@ XPORT_MMCSD
Definition: cam_ccb.h:302
static __inline void cam_fill_mmcio(struct ccb_mmcio *mmcio, uint32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint32_t flags, uint32_t mmc_opcode, uint32_t mmc_arg, uint32_t mmc_flags, struct mmc_data *mmc_d, uint32_t timeout)
Definition: cam_ccb.h:1479
#define MMC_CAP_SIGNALING_180
Definition: cam_ccb.h:1094
@ CAM_DIR_NONE
Definition: cam_ccb.h:81
@ CAM_DEV_QFREEZE
Definition: cam_ccb.h:92
@ CAM_DIR_OUT
Definition: cam_ccb.h:80
#define CDAI_TYPE_MMC_PARAMS
Definition: cam_ccb.h:1322
#define MMC_CS
Definition: cam_ccb.h:1060
#define MMC_BW
Definition: cam_ccb.h:1061
@ XPT_DEV_ADVINFO
Definition: cam_ccb.h:166
@ XPT_GET_TRAN_SETTINGS
Definition: cam_ccb.h:183
@ XPT_SCAN_TGT
Definition: cam_ccb.h:223
@ XPT_SCAN_BUS
Definition: cam_ccb.h:155
@ XPT_MMC_GET_TRAN_SETTINGS
Definition: cam_ccb.h:257
@ XPT_MMC_IO
Definition: cam_ccb.h:220
@ XPT_SET_TRAN_SETTINGS
Definition: cam_ccb.h:188
@ XPT_SCAN_LUN
Definition: cam_ccb.h:180
@ XPT_MMC_SET_TRAN_SETTINGS
Definition: cam_ccb.h:256
@ XPT_GDEV_TYPE
Definition: cam_ccb.h:143
#define MMC_VDD
Definition: cam_ccb.h:1059
#define MMC_BT
Definition: cam_ccb.h:1063
#define CDAI_TYPE_SERIAL_NUM
Definition: cam_ccb.h:1316
#define HBA_IDLEN
Definition: cam_ccb.h:53
#define CDAI_TYPE_PHYS_PATH
Definition: cam_ccb.h:1317
#define SIM_IDLEN
Definition: cam_ccb.h:52
#define MMC_PM
Definition: cam_ccb.h:1062
#define DEV_IDLEN
Definition: cam_ccb.h:54
#define MMC_CLK
Definition: cam_ccb.h:1058
#define CDAI_TYPE_SCSI_DEVID
Definition: cam_ccb.h:1315
@ CAM_DEBUG_TRACE
Definition: cam_debug.h:41
@ CAM_DEBUG_PROBE
Definition: cam_debug.h:46
@ CAM_DEBUG_CDB
Definition: cam_debug.h:43
@ CAM_DEBUG_INFO
Definition: cam_debug.h:40
#define CAM_DEBUG(path, flag, printfargs)
Definition: cam_debug.h:93
void cam_periph_release_locked(struct cam_periph *periph)
Definition: cam_periph.c:453
struct cam_periph * cam_periph_find(struct cam_path *path, char *name)
Definition: cam_periph.c:340
u_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, u_int32_t openings, u_int32_t arg, int getcount_only)
Definition: cam_periph.c:1342
int cam_periph_acquire(struct cam_periph *periph)
Definition: cam_periph.c:413
void cam_periph_invalidate(struct cam_periph *periph)
Definition: cam_periph.c:655
cam_status cam_periph_alloc(periph_ctor_t *periph_ctor, periph_oninv_t *periph_oninvalidate, periph_dtor_t *periph_dtor, periph_start_t *periph_start, char *name, cam_periph_type type, struct cam_path *path, ac_callback_t *ac_callback, ac_code code, void *arg)
Definition: cam_periph.c:197
#define CAM_PERIPH_INVALID
Definition: cam_periph.h:133
#define cam_periph_assert(periph, what)
Definition: cam_periph.h:230
#define CAM_PERIPH_DRV_EARLY
Definition: cam_periph.h:99
@ CAM_PERIPH_BIO
Definition: cam_periph.h:104
void() periph_init_t(void)
Definition: cam_periph.h:85
static __inline u_int32_t cam_sim_path(const struct cam_sim *sim)
Definition: cam_sim.h:109
static __inline u_int32_t cam_sim_unit(const struct cam_sim *sim)
Definition: cam_sim.h:127
static __inline u_int32_t cam_sim_bus(const struct cam_sim *sim)
Definition: cam_sim.h:133
static __inline const char * cam_sim_name(const struct cam_sim *sim)
Definition: cam_sim.h:115
void xpt_acquire_device(struct cam_ed *device)
Definition: cam_xpt.c:4897
union ccb * xpt_alloc_ccb(void)
Definition: cam_xpt.c:4612
void xpt_schedule(struct cam_periph *periph, u_int32_t new_priority)
Definition: cam_xpt.c:3243
cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3527
void xpt_release_device(struct cam_ed *device)
Definition: cam_xpt.c:4907
void xpt_print(struct cam_path *path, const char *fmt,...)
Definition: cam_xpt.c:3814
void xpt_rescan(union ccb *ccb)
Definition: cam_xpt.c:840
void xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
Definition: cam_xpt.c:4350
void xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
Definition: cam_xpt.c:3520
void xpt_action(union ccb *start_ccb)
Definition: cam_xpt.c:2601
void xpt_done(union ccb *done_ccb)
Definition: cam_xpt.c:4562
lun_id_t xpt_path_lun_id(struct cam_path *path)
Definition: cam_xpt.c:3895
void xpt_action_default(union ccb *start_ccb)
Definition: cam_xpt.c:2613
void xpt_release_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:3924
struct cam_ed * xpt_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
Definition: cam_xpt.c:4840
const char * xpt_action_name(uint32_t action)
Definition: cam_xpt.c:5608
device_t xpt_path_sim_device(const struct cam_path *path)
Return the device_t associated with the path.
Definition: cam_xpt.c:5551
void xpt_free_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:4630
#define xpt_path_unlock(path)
Definition: cam_xpt.h:129
#define xpt_path_owned(path)
Definition: cam_xpt.h:131
#define xpt_path_lock(path)
Definition: cam_xpt.h:128
#define xpt_path_assert(path, what)
Definition: cam_xpt.h:130
static void xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
Definition: cam_xpt.h:156
#define CAM_DEV_UNCONFIGURED
#define CARD_FEATURE_SDHC
Definition: mmc.h:88
#define CARD_FEATURE_MEMORY
Definition: mmc.h:87
#define CARD_FEATURE_SD20
Definition: mmc.h:90
#define CARD_FEATURE_18V
Definition: mmc.h:92
#define CARD_FEATURE_SDIO
Definition: mmc.h:89
#define MMC_PROPOSED_RCA
Definition: mmc.h:104
#define CARD_FEATURE_MMC
Definition: mmc.h:91
union ccb * ccb
Definition: mmc_sim_if.m:53
struct ccb_trans_settings_mmc * cts
Definition: mmc_sim_if.m:43
void mmc_path_inq(struct ccb_pathinq *cpi, const char *hba, const struct cam_sim *sim, size_t maxio)
Definition: mmc_xpt.c:1216
static void mmc_action(union ccb *start_ccb)
Definition: mmc_xpt.c:301
CAM_XPT_PROTO(mmc_proto)
static void mmc_print_ident(struct mmc_params *ident_data, struct sbuf *sb)
Definition: mmc_xpt.c:429
static char * probe_action_text[]
Definition: mmc_xpt.c:113
static void mmc_proto_denounce(struct cam_ed *device)
Definition: mmc_xpt.c:488
static void mmc_scan_lun(struct cam_periph *periph, struct cam_path *path, cam_flags flags, union ccb *ccb)
Definition: mmc_xpt.c:230
static int mmc_highest_voltage(uint32_t ocr)
Definition: mmc_xpt.c:574
static struct cam_ed * mmc_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
Definition: mmc_xpt.c:190
static void mmcprobe_done(struct cam_periph *periph, union ccb *done_ccb)
Definition: mmc_xpt.c:818
probe_action
Definition: mmc_xpt.c:90
@ PROBE_POWER_OFF
Definition: mmc_xpt.c:93
@ PROBE_MMC_INIT
Definition: mmc_xpt.c:102
@ PROBE_GET_HOST_OCR
Definition: mmc_xpt.c:94
@ PROBE_GET_CSD
Definition: mmc_xpt.c:105
@ PROBE_SDIO_RESET
Definition: mmc_xpt.c:99
@ PROBE_IDENTIFY
Definition: mmc_xpt.c:92
@ PROBE_SEND_IF_COND
Definition: mmc_xpt.c:100
@ PROBE_GET_CID
Definition: mmc_xpt.c:104
@ PROBE_SELECT_CARD
Definition: mmc_xpt.c:108
@ PROBE_GO_IDLE_STATE
Definition: mmc_xpt.c:98
@ PROBE_SDIO_INIT
Definition: mmc_xpt.c:101
@ PROBE_SEND_APP_OP_COND
Definition: mmc_xpt.c:103
@ PROBE_RESET_BUS
Definition: mmc_xpt.c:95
@ PROBE_SET_CS
Definition: mmc_xpt.c:97
@ PROBE_DONE
Definition: mmc_xpt.c:109
@ PROBE_MMC_SET_RELATIVE_ADDR
Definition: mmc_xpt.c:107
@ PROBE_SEND_RELATIVE_ADDR
Definition: mmc_xpt.c:106
@ PROBE_RESET
Definition: mmc_xpt.c:91
@ PROBE_INVALID
Definition: mmc_xpt.c:110
@ PROBE_SET_ID_FREQ
Definition: mmc_xpt.c:96
#define MMC_XPT_XPORT(x, X)
Definition: mmc_xpt.c:153
#define CARD_ID_FREQUENCY
Definition: mmc_xpt.c:515
static void init_standard_ccb(union ccb *ccb, uint32_t cmd)
Definition: mmc_xpt.c:586
static void mmc_proto_debug_out(union ccb *ccb)
Definition: mmc_xpt.c:495
PERIPHDRIVER_DECLARE(mmcprobe, probe_driver)
static struct xpt_proto_ops mmc_proto_ops
Definition: mmc_xpt.c:163
static periph_init_t probe_periph_init
Definition: mmc_xpt.c:504
static struct periph_driver probe_driver
Definition: mmc_xpt.c:506
__FBSDID("$FreeBSD$")
void mmccam_start_discovery(struct cam_sim *sim)
Definition: mmc_xpt.c:403
static void mmcprobe_start(struct cam_periph *periph, union ccb *start_ccb)
Definition: mmc_xpt.c:596
static cam_status mmcprobe_register(struct cam_periph *periph, void *arg)
Definition: mmc_xpt.c:523
#define PROBE_FLAG_HOST_CAN_DO_18V
Definition: mmc_xpt.c:182
static void mmc_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg)
Definition: mmc_xpt.c:210
static void mmc_dev_advinfo(union ccb *start_ccb)
Definition: mmc_xpt.c:332
static void mmc_announce_periph(struct cam_periph *periph)
Definition: mmc_xpt.c:380
static void mmcprobe_cleanup(struct cam_periph *periph)
Definition: mmc_xpt.c:812
static struct xpt_xport_ops mmc_xport_ops
Definition: mmc_xpt.c:146
#define PROBE_FLAG_ACMD_SENT
Definition: mmc_xpt.c:181
FEATURE(mmccam, "CAM-based MMC/SD/SDIO stack")
#define PROBE_SET_ACTION(softc, newaction)
Definition: mmc_xpt.c:136
static void mmc_proto_announce(struct cam_ed *device)
Definition: mmc_xpt.c:476
static struct xpt_proto mmc_proto
Definition: mmc_xpt.c:169
#define SCSI_REV_0
Definition: scsi_all.h:2220
u_int maxtags
u_int8_t queue_flags
u_int8_t * serial_num
u_int mintags
struct cam_et * target
u_int8_t serial_num_len
lun_id_t lun_id
u_int8_t inq_flags
struct mmc_params mmc_ident_data
uint8_t * device_id
void * quirk
cam_proto protocol
uint32_t device_id_len
u_int32_t flags
struct scsi_inquiry_data inq_data
target_id_t target_id
struct cam_ed * device
struct cam_periph * periph
void * softc
Definition: cam_periph.h:125
struct cam_path * path
Definition: cam_periph.h:124
u_int32_t flags
Definition: cam_periph.h:129
u_int32_t priority
Definition: cam.h:86
uint32_t buftype
Definition: cam_ccb.h:1313
uint8_t * buf
Definition: cam_ccb.h:1326
uint32_t flags
Definition: cam_ccb.h:1310
u_int32_t flags
Definition: cam_ccb.h:368
struct cam_path * path
Definition: cam_ccb.h:364
cam_pinfo pinfo
Definition: cam_ccb.h:349
xpt_opcode func_code
Definition: cam_ccb.h:362
u_int32_t timeout
Definition: cam_ccb.h:373
u_int32_t status
Definition: cam_ccb.h:363
u_int16_t retry_count
Definition: cam_ccb.h:354
void(* cbfcnp)(struct cam_periph *, union ccb *)
Definition: cam_ccb.h:360
struct mmc_command stop
Definition: cam_ccb.h:814
struct mmc_command cmd
Definition: cam_ccb.h:813
cam_proto protocol
Definition: cam_ccb.h:680
u_int16_t hba_eng_cnt
Definition: cam_ccb.h:666
u_int8_t version_num
Definition: cam_ccb.h:662
u_int32_t max_target
Definition: cam_ccb.h:669
u_int32_t unit_number
Definition: cam_ccb.h:677
u_int protocol_version
Definition: cam_ccb.h:681
char hba_vid[HBA_IDLEN]
Definition: cam_ccb.h:675
char dev_name[DEV_IDLEN]
Definition: cam_ccb.h:676
u_int32_t hba_misc
Definition: cam_ccb.h:665
u_int8_t hba_inquiry
Definition: cam_ccb.h:663
char sim_vid[SIM_IDLEN]
Definition: cam_ccb.h:674
u_int16_t target_sprt
Definition: cam_ccb.h:664
struct ccb_hdr ccb_h
Definition: cam_ccb.h:661
u_int32_t max_lun
Definition: cam_ccb.h:670
u_int32_t base_transfer_speed
Definition: cam_ccb.h:679
cam_xport transport
Definition: cam_ccb.h:682
target_id_t initiator_id
Definition: cam_ccb.h:673
u_int maxio
Definition: cam_ccb.h:691
u_int transport_version
Definition: cam_ccb.h:683
u_int32_t bus_id
Definition: cam_ccb.h:678
cam_flags flags
Definition: cam_ccb.h:1191
struct mmc_ios ios
Definition: cam_ccb.h:1057
struct ccb_trans_settings_mmc mmc
Definition: cam_ccb.h:1117
union ccb_trans_settings::@3 proto_specific
Definition: mmc.h:66
uint32_t card_ocr
Definition: mmc.h:70
uint32_t card_csd[4]
Definition: mmc.h:80
uint8_t sdio_func_count
Definition: mmc.h:94
uint32_t io_ocr
Definition: mmc.h:73
uint32_t card_features
Definition: mmc.h:86
uint16_t card_rca
Definition: mmc.h:83
uint32_t card_cid[4]
Definition: mmc.h:76
uint8_t acmd41_count
Definition: mmc_xpt.c:183
uint32_t host_ocr
Definition: mmc_xpt.c:179
probe_action action
Definition: mmc_xpt.c:177
struct cam_periph * periph
Definition: mmc_xpt.c:184
uint32_t flags
Definition: mmc_xpt.c:180
xpt_proto_announce_func announce
cam_proto proto
xpt_alloc_device_func alloc_device
Definition: cam_ccb.h:1345
struct ccb_trans_settings cts
Definition: cam_ccb.h:1357
struct ccb_mmcio mmcio
Definition: cam_ccb.h:1380
struct ccb_dev_advinfo cdai
Definition: cam_ccb.h:1377
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1346
struct ccb_rescan crcn
Definition: cam_ccb.h:1374
struct ccb_pathinq cpi
Definition: cam_ccb.h:1350