Lines Matching +full:sc +full:- +full:partitions
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2015-2017 Ilya Bakulin <kibab@FreeBSD.org> All rights reserved.
106 struct sdda_softc *sc;
132 char card_sn_string[16];/* Formatted serial # for disk->d_ident */
141 /* MMC partitions support */
236 return periph->path->device->mmc_ident_data.card_rca;
241 * Look at both CAM-level errors and on MMC protocol errors.
248 KASSERT(ccb->ccb_h.func_code == XPT_MMC_IO,
249 ("ccb %p: cannot handle non-XPT_MMC_IO errors, got func_code=%d",
250 ccb, ccb->ccb_h.func_code));
252 /* CAM-level error should always correspond to MMC-level error */
253 if (((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) &&
254 (ccb->mmcio.cmd.error != MMC_ERR_NONE))
257 if (ccb->mmcio.cmd.error != MMC_ERR_NONE) {
258 xpt_print_path(ccb->ccb_h.path);
260 ccb->mmcio.cmd.opcode,
261 ccb->mmcio.cmd.error,
262 mmc_errmsg[ccb->mmcio.cmd.error]);
264 return (ccb->mmcio.cmd.error);
270 const int i = (bit_len / 32) - (start / 32) - 1;
274 retval |= bits[i - 1] << (32 - shift);
275 return (retval & ((1llu << size) - 1));
286 csd->csd_structure = v = mmc_get_bits(raw_csd, 128, 126, 2);
291 csd->tacc = (exp[e] * mant[m] + 9) / 10;
292 csd->nsac = mmc_get_bits(raw_csd, 128, 104, 8) * 100;
295 csd->tran_speed = exp[e] * 10000 * mant[m];
296 csd->ccc = mmc_get_bits(raw_csd, 128, 84, 12);
297 csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 128, 80, 4);
298 csd->read_bl_partial = mmc_get_bits(raw_csd, 128, 79, 1);
299 csd->write_blk_misalign = mmc_get_bits(raw_csd, 128, 78, 1);
300 csd->read_blk_misalign = mmc_get_bits(raw_csd, 128, 77, 1);
301 csd->dsr_imp = mmc_get_bits(raw_csd, 128, 76, 1);
302 csd->erase_blk_en = mmc_get_bits(raw_csd, 128, 46, 1);
303 csd->erase_sector = mmc_get_bits(raw_csd, 128, 39, 7) + 1;
304 csd->wp_grp_size = mmc_get_bits(raw_csd, 128, 32, 7);
305 csd->wp_grp_enable = mmc_get_bits(raw_csd, 128, 31, 1);
306 csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 128, 26, 3);
307 csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 128, 22, 4);
308 csd->write_bl_partial = mmc_get_bits(raw_csd, 128, 21, 1);
311 csd->vdd_r_curr_min = cur_min[mmc_get_bits(raw_csd, 128, 59, 3)];
312 csd->vdd_r_curr_max = cur_max[mmc_get_bits(raw_csd, 128, 56, 3)];
313 csd->vdd_w_curr_min = cur_min[mmc_get_bits(raw_csd, 128, 53, 3)];
314 csd->vdd_w_curr_max = cur_max[mmc_get_bits(raw_csd, 128, 50, 3)];
317 csd->capacity = ((1 + m) << (e + 2)) * csd->read_bl_len;
319 csd->capacity = ((uint64_t)mmc_get_bits(raw_csd, 128, 48, 22) + 1) *
332 csd->csd_structure = mmc_get_bits(raw_csd, 128, 126, 2);
333 csd->spec_vers = mmc_get_bits(raw_csd, 128, 122, 4);
336 csd->tacc = exp[e] * mant[m] + 9 / 10;
337 csd->nsac = mmc_get_bits(raw_csd, 128, 104, 8) * 100;
340 csd->tran_speed = exp[e] * 10000 * mant[m];
341 csd->ccc = mmc_get_bits(raw_csd, 128, 84, 12);
342 csd->read_bl_len = 1 << mmc_get_bits(raw_csd, 128, 80, 4);
343 csd->read_bl_partial = mmc_get_bits(raw_csd, 128, 79, 1);
344 csd->write_blk_misalign = mmc_get_bits(raw_csd, 128, 78, 1);
345 csd->read_blk_misalign = mmc_get_bits(raw_csd, 128, 77, 1);
346 csd->dsr_imp = mmc_get_bits(raw_csd, 128, 76, 1);
347 csd->vdd_r_curr_min = cur_min[mmc_get_bits(raw_csd, 128, 59, 3)];
348 csd->vdd_r_curr_max = cur_max[mmc_get_bits(raw_csd, 128, 56, 3)];
349 csd->vdd_w_curr_min = cur_min[mmc_get_bits(raw_csd, 128, 53, 3)];
350 csd->vdd_w_curr_max = cur_max[mmc_get_bits(raw_csd, 128, 50, 3)];
353 csd->capacity = ((1 + m) << (e + 2)) * csd->read_bl_len;
354 csd->erase_blk_en = 0;
355 csd->erase_sector = (mmc_get_bits(raw_csd, 128, 42, 5) + 1) *
357 csd->wp_grp_size = mmc_get_bits(raw_csd, 128, 32, 5);
358 csd->wp_grp_enable = mmc_get_bits(raw_csd, 128, 31, 1);
359 csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 128, 26, 3);
360 csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 128, 22, 4);
361 csd->write_bl_partial = mmc_get_bits(raw_csd, 128, 21, 1);
371 cid->mid = mmc_get_bits(raw_cid, 128, 120, 8);
372 cid->oid = mmc_get_bits(raw_cid, 128, 104, 16);
374 cid->pnm[i] = mmc_get_bits(raw_cid, 128, 96 - i * 8, 8);
375 cid->pnm[5] = 0;
376 cid->prv = mmc_get_bits(raw_cid, 128, 56, 8);
377 cid->psn = mmc_get_bits(raw_cid, 128, 24, 32);
378 cid->mdt_year = mmc_get_bits(raw_cid, 128, 12, 8) + 2000;
379 cid->mdt_month = mmc_get_bits(raw_cid, 128, 8, 4);
389 cid->mid = mmc_get_bits(raw_cid, 128, 120, 8);
390 cid->oid = mmc_get_bits(raw_cid, 128, 104, 8);
392 cid->pnm[i] = mmc_get_bits(raw_cid, 128, 96 - i * 8, 8);
393 cid->pnm[6] = 0;
394 cid->prv = mmc_get_bits(raw_cid, 128, 48, 8);
395 cid->psn = mmc_get_bits(raw_cid, 128, 16, 32);
396 cid->mdt_month = mmc_get_bits(raw_cid, 128, 12, 4);
397 cid->mdt_year = mmc_get_bits(raw_cid, 128, 8, 4) + 1997;
401 mmc_format_card_id_string(struct sdda_softc *sc, struct mmc_params *mmcp)
411 * 22.5MHz/4bit/128-block
414 * use as the disk->d_ident string.
423 c1 = (sc->cid.oid >> 8) & 0x0ff;
424 c2 = sc->cid.oid & 0x0ff;
428 snprintf(oidstr, sizeof(oidstr), "0x%04x", sc->cid.oid);
429 snprintf(sc->card_sn_string, sizeof(sc->card_sn_string),
430 "%08X", sc->cid.psn);
431 snprintf(sc->card_id_string, sizeof(sc->card_id_string),
433 mmcp->card_features & CARD_FEATURE_MMC ? "MMC" : "SD",
434 mmcp->card_features & CARD_FEATURE_SDHC ? "HC" : "",
435 sc->cid.pnm, sc->cid.prv >> 4, sc->cid.prv & 0x0f,
436 sc->cid.psn, sc->cid.mdt_month, sc->cid.mdt_year,
437 sc->cid.mid, oidstr);
448 part = (struct sdda_part *)dp->d_drv1;
449 softc = part->sc;
450 periph = softc->periph;
462 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddaopen\n"));
464 part->flags |= SDDA_FLAG_OPEN;
478 part = (struct sdda_part *)dp->d_drv1;
479 softc = part->sc;
480 periph = softc->periph;
481 part->flags &= ~SDDA_FLAG_OPEN;
485 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddaclose\n"));
487 while (softc->refcount != 0)
488 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "sddaclose", 1);
497 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
504 bp = bioq_first(&softc->part[softc->part_curr]->bio_queue);
507 if ((part = softc->part[i]) != NULL &&
508 (bp = bioq_first(&softc->part[i]->bio_queue)) != NULL)
529 part = (struct sdda_part *)bp->bio_disk->d_drv1;
530 softc = part->sc;
531 periph = softc->periph;
535 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddastrategy(%p)\n", bp));
540 if ((periph->flags & CAM_PERIPH_INVALID) != 0) {
549 bioq_disksort(&part->bio_queue, bp);
587 part = (struct sdda_part *)dp->d_drv1;
588 periph = part->sc->periph;
589 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddadiskgonecb\n"));
600 softc = (struct sdda_softc *)periph->softc;
602 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddaoninvalidate\n"));
605 * De-register any async callbacks.
607 xpt_register_async(0, sddaasync, periph, periph->path);
614 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("bioq_flush start\n"));
616 if ((part = softc->part[i]) != NULL) {
617 bioq_flush(&part->bio_queue, NULL, ENXIO);
618 disk_gone(part->disk);
621 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("bioq_flush end\n"));
631 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddacleanup\n"));
632 softc = (struct sdda_softc *)periph->softc;
637 if ((part = softc->part[i]) != NULL) {
638 disk_destroy(part->disk);
640 softc->part[i] = NULL;
667 if (cgd->protocol != PROTO_MMCSD)
670 if (!(path->device->mmc_ident_data.card_features & CARD_FEATURE_MEMORY)) {
696 xpt_setup_ccb(&cgd.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
713 softc = periph->softc;
715 if ((part = softc->part[i]) != NULL) {
716 disk_attr_changed(part->disk, "GEOM::physpath",
738 part = (struct sdda_part *)bp->bio_disk->d_drv1;
739 softc = part->sc;
740 periph = softc->periph;
742 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
743 periph->path);
746 bp->bio_completed = bp->bio_length;
756 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddaregister\n"));
771 softc->state = SDDA_STATE_INIT;
772 softc->mmcdata =
774 if (softc->mmcdata == NULL) {
780 periph->softc = softc;
781 softc->periph = periph;
784 TASK_INIT(&softc->start_init_task, 0, sdda_start_init_task, periph);
785 taskqueue_enqueue(taskqueue_thread, &softc->start_init_task);
796 memset(&ccb->mmcio.cmd, 0, sizeof(struct mmc_command));
797 memset(&ccb->mmcio.stop, 0, sizeof(struct mmc_command));
798 cam_fill_mmcio(&ccb->mmcio,
812 if (!(ccb->mmcio.cmd.resp[0] & R1_APP_CMD))
817 if (cmd->data != NULL) {
818 ccb->mmcio.cmd.data = cmd->data;
819 if (cmd->data->flags & MMC_DATA_READ)
821 if (cmd->data->flags & MMC_DATA_WRITE)
825 cam_fill_mmcio(&ccb->mmcio,
829 /*mmc_opcode*/ cmd->opcode,
830 /*mmc_arg*/ cmd->arg,
831 /*mmc_flags*/ cmd->flags,
832 /*mmc_data*/ cmd->data,
839 memcpy(cmd->resp, ccb->mmcio.cmd.resp, sizeof(cmd->resp));
840 cmd->error = ccb->mmcio.cmd.error;
883 cam_fill_mmcio(&ccb->mmcio,
911 scr->sda_vsn = mmc_get_bits(raw_scr, 64, 56, 4);
912 scr->bus_widths = mmc_get_bits(raw_scr, 64, 48, 4);
924 cam_fill_mmcio(&ccb->mmcio,
941 cam_fill_mmcio(&ccb->mmcio,
970 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
972 return (softc->csd.spec_vers);
977 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
979 return (softc->mediasize);
985 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
988 return (softc->raw_ext_csd[EXT_CSD_GEN_CMD6_TIME] * 10);
1006 arg = mode << 31; /* 0 - check, 1 - set */
1011 cam_fill_mmcio(&ccb->mmcio,
1034 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
1035 struct mmc_params *mmcp = &periph->path->device->mmc_ident_data;
1037 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE,
1049 if (mmcp->card_features & CARD_FEATURE_MMC) {
1051 EXT_CSD_HS_TIMING, value, softc->cmd6_time);
1056 /* Set high-speed timing on the host */
1058 cts = &ccb->cts.proto_specific.mmc;
1059 ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1060 ccb->ccb_h.flags = CAM_DIR_NONE;
1061 ccb->ccb_h.retry_count = 0;
1062 ccb->ccb_h.timeout = 100;
1063 ccb->ccb_h.cbfcnp = NULL;
1064 cts->ios.timing = timing;
1065 cts->ios_valid = MMC_BT;
1077 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sdda_start_init_task\n"));
1079 xpt_setup_ccb(&new_ccb->ccb_h, periph->path,
1092 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
1093 struct mmc_params *mmcp = &periph->path->device->mmc_ident_data;
1096 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sdda_set_bus_width\n"));
1099 if (mmcp->card_features & CARD_FEATURE_MMC) {
1115 EXT_CSD_BUS_WIDTH, value, softc->cmd6_time);
1127 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Error %d when setting bus width on the card\n", err));
1132 cts = &ccb->cts.proto_specific.mmc;
1133 ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1134 ccb->ccb_h.flags = CAM_DIR_NONE;
1135 ccb->ccb_h.retry_count = 0;
1136 ccb->ccb_h.timeout = 100;
1137 ccb->ccb_h.cbfcnp = NULL;
1138 cts->ios.bus_width = width;
1139 cts->ios_valid = MMC_BW;
1172 return ("1-bit");
1174 return ("4-bit");
1176 return ("8-bit");
1187 cts = &ccb->cts.proto_specific.mmc;
1189 ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1190 ccb->ccb_h.flags = CAM_DIR_NONE;
1191 ccb->ccb_h.retry_count = 0;
1192 ccb->ccb_h.timeout = 100;
1193 ccb->ccb_h.cbfcnp = NULL;
1196 if (ccb->ccb_h.status != CAM_REQ_CMP)
1198 return (cts->host_caps);
1206 cts = &ccb->cts.proto_specific.mmc;
1209 ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1210 ccb->ccb_h.flags = CAM_DIR_NONE;
1211 ccb->ccb_h.retry_count = 0;
1212 ccb->ccb_h.timeout = 100;
1213 ccb->ccb_h.cbfcnp = NULL;
1216 if (ccb->ccb_h.status != CAM_REQ_CMP)
1218 KASSERT(cts->host_max_data != 0, ("host_max_data == 0?!"));
1219 return (cts->host_max_data);
1233 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sdda_start_init\n"));
1235 if ((periph->flags & CAM_PERIPH_INVALID) != 0) {
1240 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
1241 struct mmc_params *mmcp = &periph->path->device->mmc_ident_data;
1242 struct cam_ed *device = periph->path->device;
1244 if (mmcp->card_features & CARD_FEATURE_MMC) {
1245 mmc_decode_csd_mmc(mmcp->card_csd, &softc->csd);
1246 mmc_decode_cid_mmc(mmcp->card_cid, &softc->cid);
1249 (uint8_t *)&softc->raw_ext_csd,
1250 sizeof(softc->raw_ext_csd));
1252 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1258 mmc_decode_csd_sd(mmcp->card_csd, &softc->csd);
1259 mmc_decode_cid_sd(mmcp->card_cid, &softc->cid);
1262 softc->sector_count = softc->csd.capacity / MMC_SECTOR_SIZE;
1263 softc->mediasize = softc->csd.capacity;
1264 softc->cmd6_time = mmc_get_cmd6_timeout(periph);
1268 sec_count = softc->raw_ext_csd[EXT_CSD_SEC_CNT] +
1269 (softc->raw_ext_csd[EXT_CSD_SEC_CNT + 1] << 8) +
1270 (softc->raw_ext_csd[EXT_CSD_SEC_CNT + 2] << 16) +
1271 (softc->raw_ext_csd[EXT_CSD_SEC_CNT + 3] << 24);
1273 softc->sector_count = sec_count;
1274 softc->mediasize = softc->sector_count * MMC_SECTOR_SIZE;
1276 mmcp->card_features |= CARD_FEATURE_SDHC;
1279 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1281 softc->mediasize,
1282 softc->sector_count));
1286 device->serial_num_len = strlen(softc->card_sn_string);
1287 device->serial_num = (uint8_t *)malloc((device->serial_num_len + 1),
1289 strlcpy(device->serial_num, softc->card_sn_string, device->serial_num_len + 1);
1291 device->device_id_len = strlen(softc->card_id_string);
1292 device->device_id = (uint8_t *)malloc((device->device_id_len + 1),
1294 strlcpy(device->device_id, softc->card_id_string, device->device_id_len + 1);
1296 strlcpy(mmcp->model, softc->card_id_string, sizeof(mmcp->model));
1299 cts = &start_ccb->cts.proto_specific.mmc;
1302 start_ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1303 start_ccb->ccb_h.flags = CAM_DIR_NONE;
1304 start_ccb->ccb_h.retry_count = 0;
1305 start_ccb->ccb_h.timeout = 100;
1306 start_ccb->ccb_h.cbfcnp = NULL;
1309 if (start_ccb->ccb_h.status != CAM_REQ_CMP)
1311 host_f_max = cts->host_f_max;
1312 host_caps = cts->host_caps;
1313 if (cts->ios.bus_width != bus_width_1)
1314 panic("Bus width in ios is not 1-bit");
1316 /* Now check if the card supports High-speed */
1317 softc->card_f_max = softc->csd.tran_speed;
1321 if (mmcp->card_features & CARD_FEATURE_SD20) {
1326 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Cannot get SCR\n"));
1329 mmc_app_decode_scr(rawscr, &softc->scr);
1331 if ((softc->scr.sda_vsn >= 1) && (softc->csd.ccc & (1<<10))) {
1335 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Card supports HS\n"));
1336 softc->card_f_max = SD_HS_MAX;
1345 * attempt to blindly re-select them, we get timeout
1352 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Not trying the switch\n"));
1357 if (mmcp->card_features & CARD_FEATURE_MMC && mmc_get_spec_vers(periph) >= 4) {
1358 card_type = softc->raw_ext_csd[EXT_CSD_CARD_TYPE];
1360 softc->card_f_max = MMC_TYPE_HS_52_MAX;
1362 softc->card_f_max = MMC_TYPE_HS_26_MAX;
1365 setbit(&softc->timings, bus_timing_mmc_ddr52);
1366 setbit(&softc->vccq_120, bus_timing_mmc_ddr52);
1367 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Card supports DDR52 at 1.2V\n"));
1371 setbit(&softc->timings, bus_timing_mmc_ddr52);
1372 setbit(&softc->vccq_180, bus_timing_mmc_ddr52);
1373 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Card supports DDR52 at 1.8V\n"));
1377 setbit(&softc->timings, bus_timing_mmc_hs200);
1378 setbit(&softc->vccq_120, bus_timing_mmc_hs200);
1379 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Card supports HS200 at 1.2V\n"));
1383 setbit(&softc->timings, bus_timing_mmc_hs200);
1384 setbit(&softc->vccq_180, bus_timing_mmc_hs200);
1385 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Card supports HS200 at 1.8V\n"));
1391 f_max = min(host_f_max, softc->card_f_max);
1392 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH, ("Set SD freq to %d MHz (min out of host f=%d MHz and card f=%d MHz)\n", f_max / 1000000, host_f_max / 1000000, softc->card_f_max / 1000000));
1394 /* Enable high-speed timing on the card */
1398 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("Cannot switch card to high-speed mode"));
1402 /* If possible, set lower-level signaling */
1405 for (timing = bus_timing_mmc_ddr52; timing > bus_timing_normal; timing--) {
1406 if (isset(&softc->vccq_120, timing)) {
1408 start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1409 start_ccb->ccb_h.flags = CAM_DIR_NONE;
1410 start_ccb->ccb_h.retry_count = 0;
1411 start_ccb->ccb_h.timeout = 100;
1412 start_ccb->ccb_h.cbfcnp = NULL;
1413 cts->ios.vccq = vccq_120;
1414 cts->ios_valid = MMC_VCCQ;
1417 } else if (isset(&softc->vccq_180, timing)) {
1419 start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1420 start_ccb->ccb_h.flags = CAM_DIR_NONE;
1421 start_ccb->ccb_h.retry_count = 0;
1422 start_ccb->ccb_h.timeout = 100;
1423 start_ccb->ccb_h.cbfcnp = NULL;
1424 cts->ios.vccq = vccq_180;
1425 cts->ios_valid = MMC_VCCQ;
1430 start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1431 start_ccb->ccb_h.flags = CAM_DIR_NONE;
1432 start_ccb->ccb_h.retry_count = 0;
1433 start_ccb->ccb_h.timeout = 100;
1434 start_ccb->ccb_h.cbfcnp = NULL;
1435 cts->ios.vccq = vccq_330;
1436 cts->ios_valid = MMC_VCCQ;
1443 start_ccb->ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1444 start_ccb->ccb_h.flags = CAM_DIR_NONE;
1445 start_ccb->ccb_h.retry_count = 0;
1446 start_ccb->ccb_h.timeout = 100;
1447 start_ccb->ccb_h.cbfcnp = NULL;
1448 cts->ios.clock = f_max;
1449 cts->ios_valid = MMC_CLK;
1458 if (mmcp->card_features & CARD_FEATURE_SD20 &&
1459 softc->scr.bus_widths & SD_SCR_BUS_WIDTH_4)
1465 /* TODO: figure out bus width for MMC; use 8-bit for now (to test on BBB) */
1466 if (mmcp->card_features & CARD_FEATURE_MMC)
1470 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1477 softc->state = SDDA_STATE_NORMAL;
1480 /* MMC partitions support */
1481 if (mmcp->card_features & CARD_FEATURE_MMC && mmc_get_spec_vers(periph) >= 4) {
1483 } else if (mmcp->card_features & CARD_FEATURE_MEMORY) {
1486 periph->unit_number,
1490 softc->part_curr = 0;
1494 xpt_announce_periph(periph, softc->card_id_string);
1502 AC_ADVINFO_CHANGED, sddaasync, periph, periph->path);
1509 struct sdda_softc *sc = (struct sdda_softc *)periph->softc;
1513 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1517 ro ? "(read-only)" : ""));
1519 part = sc->part[type] = malloc(sizeof(*part), M_DEVBUF,
1526 part->cnt = cnt;
1527 part->type = type;
1528 part->ro = ro;
1529 part->sc = sc;
1530 snprintf(part->name, sizeof(part->name), name, "sdda", periph->unit_number);
1536 * tools from sysutils/mmc-utils.
1540 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1541 ("Don't know what to do with RPMB partitions yet\n"));
1545 bioq_init(&part->bio_queue);
1548 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
1558 part->disk = disk_alloc();
1559 part->disk->d_rotation_rate = DISK_RR_NON_ROTATING;
1560 part->disk->d_devstat = devstat_new_entry(part->name,
1566 part->disk->d_open = sddaopen;
1567 part->disk->d_close = sddaclose;
1568 part->disk->d_strategy = sddastrategy;
1569 if (cam_sim_pollable(periph->sim))
1570 part->disk->d_dump = sddadump;
1571 part->disk->d_getattr = sddagetattr;
1572 part->disk->d_gone = sddadiskgonecb;
1573 part->disk->d_name = part->name;
1574 part->disk->d_drv1 = part;
1575 part->disk->d_maxsize =
1578 part->disk->d_unit = cnt;
1579 part->disk->d_flags = 0;
1580 strlcpy(part->disk->d_descr, sc->card_id_string,
1581 MIN(sizeof(part->disk->d_descr), sizeof(sc->card_id_string)));
1582 strlcpy(part->disk->d_ident, sc->card_sn_string,
1583 MIN(sizeof(part->disk->d_ident), sizeof(sc->card_sn_string)));
1584 part->disk->d_hba_vendor = cpi.hba_vendor;
1585 part->disk->d_hba_device = cpi.hba_device;
1586 part->disk->d_hba_subvendor = cpi.hba_subvendor;
1587 part->disk->d_hba_subdevice = cpi.hba_subdevice;
1588 snprintf(part->disk->d_attachment, sizeof(part->disk->d_attachment),
1591 part->disk->d_sectorsize = mmc_get_sector_size(periph);
1592 part->disk->d_mediasize = media_size;
1593 part->disk->d_stripesize = 0;
1594 part->disk->d_fwsectors = 0;
1595 part->disk->d_fwheads = 0;
1599 snprintf(cname, sizeof(cname), name, "mmcsd", periph->unit_number);
1600 disk_add_alias(part->disk, cname);
1609 xpt_print(periph->path, "%s: lost periph during "
1614 disk_create(part->disk, DISK_VERSION);
1622 * For MMC cards, process EXT_CSD and add partitions that are supported by
1628 struct sdda_softc *sc = (struct sdda_softc *)periph->softc;
1629 struct mmc_params *mmcp = &periph->path->device->mmc_ident_data;
1636 ext_csd = sc->raw_ext_csd;
1639 * Enhanced user data area and general purpose partitions are only
1646 * Ignore user-creatable enhanced user data area and general purpose
1647 * partitions partitions as long as partitioning hasn't been finished.
1658 * the disk for the corresponding user data area as re-tasting is
1674 sc->enh_size = size;
1675 sc->enh_base = (ext_csd[EXT_CSD_ENH_START_ADDR] +
1679 ((mmcp->card_features & CARD_FEATURE_SDHC) ? 1: MMC_SECTOR_SIZE);
1681 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1687 * data area in case partitions are supported.
1691 periph->unit_number, mmc_get_media_size(periph), ro);
1692 sc->part_curr = EXT_CSD_PART_CONFIG_ACC_DEFAULT;
1698 if (sc->enh_size != 0) {
1699 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1701 sc->enh_base, sc->enh_size));
1708 sc->part_time = max(ext_csd[EXT_CSD_PART_SWITCH_TO] * 10 * 1000,
1711 /* Add boot partitions, which are of a fixed multiple of 128 KB. */
1734 * Add general purpose partitions, which are of a multiple of high
1756 * partitions and send it to h/w, and upon completion resume processing
1764 struct sdda_softc *sc = (struct sdda_softc *)periph->softc;
1768 sc->part_requested = part;
1770 value = (sc->raw_ext_csd[EXT_CSD_PART_CONFIG] &
1774 EXT_CSD_PART_CONFIG, value, sc->part_time);
1775 start_ccb->ccb_h.cbfcnp = sddadone;
1777 sc->outstanding_cmds++;
1788 struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
1790 struct mmc_params *mmcp = &periph->path->device->mmc_ident_data;
1793 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("sddastart\n"));
1795 if (softc->state != SDDA_STATE_NORMAL) {
1796 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("device is not in SDDA_STATE_NORMAL yet\n"));
1802 part_index = softc->part_curr;
1803 part = softc->part[softc->part_curr];
1804 bp = bioq_first(&part->bio_queue);
1807 if ((part = softc->part[part_index]) != NULL &&
1808 (bp = bioq_first(&softc->part[part_index]->bio_queue)) != NULL)
1816 if (part_index != softc->part_curr) {
1817 CAM_DEBUG(periph->path, CAM_DEBUG_PERIPH,
1818 ("Partition %d -> %d\n", softc->part_curr, part_index));
1822 * RPMB partitions. So we pause re-tuning along with triggering
1823 * it up-front to decrease the likelihood of re-tuning becoming
1826 * after an access in order to allow for re-tuning to take place
1830 softc->state = SDDA_STATE_PART_SWITCH;
1835 bioq_remove(&part->bio_queue, bp);
1837 switch (bp->bio_cmd) {
1839 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("BIO_WRITE\n"));
1840 part->flags |= SDDA_FLAG_DIRTY;
1845 uint64_t blockno = bp->bio_pblkno;
1846 uint16_t count = bp->bio_bcount / MMC_SECTOR_SIZE;
1849 if (bp->bio_cmd == BIO_READ)
1850 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("BIO_READ\n"));
1851 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
1855 if (bp->bio_cmd == BIO_READ) {
1867 start_ccb->ccb_h.func_code = XPT_MMC_IO;
1868 start_ccb->ccb_h.flags = (bp->bio_cmd == BIO_READ ? CAM_DIR_IN : CAM_DIR_OUT);
1869 start_ccb->ccb_h.retry_count = 0;
1870 start_ccb->ccb_h.timeout = 15 * 1000;
1871 start_ccb->ccb_h.cbfcnp = sddadone;
1873 mmcio = &start_ccb->mmcio;
1874 mmcio->cmd.opcode = opcode;
1875 mmcio->cmd.arg = blockno;
1876 if (!(mmcp->card_features & CARD_FEATURE_SDHC))
1877 mmcio->cmd.arg <<= 9;
1879 mmcio->cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
1880 mmcio->cmd.data = softc->mmcdata;
1881 memset(mmcio->cmd.data, 0, sizeof(struct mmc_data));
1882 mmcio->cmd.data->data = bp->bio_data;
1883 mmcio->cmd.data->len = MMC_SECTOR_SIZE * count;
1884 mmcio->cmd.data->flags = (bp->bio_cmd == BIO_READ ? MMC_DATA_READ : MMC_DATA_WRITE);
1887 mmcio->cmd.data->flags |= MMC_DATA_MULTI;
1888 mmcio->stop.opcode = MMC_STOP_TRANSMISSION;
1889 mmcio->stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
1890 mmcio->stop.arg = 0;
1896 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("BIO_FLUSH\n"));
1900 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("BIO_DELETE\n"));
1908 start_ccb->ccb_h.ccb_bp = bp;
1909 softc->outstanding_cmds++;
1910 softc->refcount++;
1929 softc = (struct sdda_softc *)periph->softc;
1930 mmcio = &done_ccb->mmcio;
1931 path = done_ccb->ccb_h.path;
1934 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1936 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1944 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
1949 card_status = mmcio->cmd.resp[0];
1955 /* Process result of switching MMC partitions */
1956 if (softc->state == SDDA_STATE_PART_SWITCH) {
1959 softc->part_requested));
1960 softc->outstanding_cmds--;
1962 softc->state = SDDA_STATE_NORMAL;
1970 softc->raw_ext_csd[EXT_CSD_PART_CONFIG] =
1971 (softc->raw_ext_csd[EXT_CSD_PART_CONFIG] &
1972 ~EXT_CSD_PART_CONFIG_ACC_MASK) | softc->part_requested;
1974 softc->part_curr = softc->part_requested;
1982 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
1983 bp->bio_error = error;
1985 bp->bio_resid = bp->bio_bcount;
1986 bp->bio_flags |= BIO_ERROR;
1989 bp->bio_resid = 0;
1990 if (bp->bio_resid > 0)
1991 bp->bio_flags |= BIO_ERROR;
1994 softc->outstanding_cmds--;
1999 KASSERT(softc->refcount >= 1, ("sddadone softc %p refcount %d", softc, softc->refcount));
2000 softc->refcount--;
2024 part = dp->d_drv1;
2025 softc = part->sc;
2026 periph = softc->periph;
2027 mmcp = &periph->path->device->mmc_ident_data;
2029 if (softc->state != SDDA_STATE_NORMAL)
2036 if (softc->part[softc->part_curr] != part)
2040 xpt_setup_ccb(&mmcio.ccb_h, periph->path, CAM_PRIORITY_NORMAL); /* XXX needed? */
2053 if (!(mmcp->card_features & CARD_FEATURE_SDHC))
2057 mmcio.cmd.data = softc->mmcdata;
2059 mmcio.cmd.data->data = virtual;
2060 mmcio.cmd.data->len = MMC_SECTOR_SIZE * count;
2061 mmcio.cmd.data->flags = MMC_DATA_WRITE;
2065 mmcio.cmd.data->flags |= MMC_DATA_MULTI;