diff --git a/sys/cam/cam.c b/sys/cam/cam.c index 0c76d9614f2d..b84132d2fcfd 100644 --- a/sys/cam/cam.c +++ b/sys/cam/cam.c @@ -360,3 +360,28 @@ cam_error_print(struct cam_device *device, union ccb *ccb, } #endif /* _KERNEL/!_KERNEL */ + +/* + * Common calculate geometry fuction + * + * Caller should set ccg->volume_size and block_size. + * The extended parameter should be zero if extended translation + * should not be used. + */ +void +cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended) +{ + uint32_t size_mb, secs_per_cylinder; + + size_mb = ccg->volume_size / ((1024L * 1024L) / ccg->block_size); + if (size_mb > 1024 && extended) { + ccg->heads = 255; + ccg->secs_per_track = 63; + } else { + ccg->heads = 64; + ccg->secs_per_track = 32; + } + secs_per_cylinder = ccg->heads * ccg->secs_per_track; + ccg->cylinders = ccg->volume_size / secs_per_cylinder; + ccg->ccb_h.status = CAM_REQ_CMP; +} diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h index 1df01cef7343..62adfe649546 100644 --- a/sys/cam/cam_ccb.h +++ b/sys/cam/cam_ccb.h @@ -979,6 +979,8 @@ cam_fill_ctio(struct ccb_scsiio *csio, u_int32_t retries, csio->init_id = init_id; } +void cam_calc_geometry(struct ccb_calc_geometry *ccg, int extended); + __END_DECLS #endif /* _CAM_CAM_CCB_H */