mrsas(4): Report more correct maximum I/O size.

Subtract one SGE for the case of misaligned address.  Also take into
account maximum number of sectors reported by firmware, that gives
nicer 256KB limit instead of 276KB calculated from the SGE limit.

While there, remove number of I/O size checks, duplicating what is
already checked by CAM and busdma(9).

MFC after:	1 month
Sponsored by:	iXsystems, Inc.
This commit is contained in:
Alexander Motin 2021-07-01 15:28:55 -04:00
parent dd82fd3543
commit fa3d57c256
2 changed files with 7 additions and 40 deletions

View File

@ -1914,15 +1914,16 @@ mrsas_alloc_mem(struct mrsas_softc *sc)
/*
* Allocate parent DMA tag
*/
if (bus_dma_tag_create(NULL, /* parent */
if (bus_dma_tag_create(
bus_get_dma_tag(sc->mrsas_dev), /* parent */
1, /* alignment */
0, /* boundary */
BUS_SPACE_MAXADDR, /* lowaddr */
BUS_SPACE_MAXADDR, /* highaddr */
NULL, NULL, /* filter, filterarg */
maxphys, /* maxsize */
sc->max_num_sge, /* nsegments */
maxphys, /* maxsegsize */
BUS_SPACE_MAXSIZE, /* maxsize */
BUS_SPACE_UNRESTRICTED, /* nsegments */
BUS_SPACE_MAXSIZE, /* maxsegsize */
0, /* flags */
NULL, NULL, /* lockfunc, lockarg */
&sc->mrsas_parent_tag /* tag */
@ -2533,7 +2534,7 @@ mrsas_init_fw(struct mrsas_softc *sc)
sc->ctrl_info->max_strips_per_io;
max_sectors_2 = sc->ctrl_info->max_request_size;
tmp_sectors = min(max_sectors_1, max_sectors_2);
sc->max_sectors_per_req = sc->max_num_sge * MRSAS_PAGE_SIZE / 512;
sc->max_sectors_per_req = (sc->max_num_sge - 1) * MRSAS_PAGE_SIZE / 512;
if (tmp_sectors && (sc->max_sectors_per_req > tmp_sectors))
sc->max_sectors_per_req = tmp_sectors;

View File

@ -369,7 +369,7 @@ mrsas_action(struct cam_sim *sim, union ccb *ccb)
else
ccb->cpi.max_target = MRSAS_MAX_LD_IDS - 1;
#if (__FreeBSD_version > 704000)
ccb->cpi.maxio = sc->max_num_sge * MRSAS_PAGE_SIZE;
ccb->cpi.maxio = sc->max_sectors_per_req * 512;
#endif
ccb->ccb_h.status = CAM_REQ_CMP;
xpt_done(ccb);
@ -513,21 +513,11 @@ mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim,
ccb_h->status = CAM_REQ_INVALID;
goto done;
case CAM_DATA_VADDR:
if (csio->dxfer_len > (sc->max_num_sge * MRSAS_PAGE_SIZE)) {
mrsas_release_mpt_cmd(cmd);
ccb_h->status = CAM_REQ_TOO_BIG;
goto done;
}
cmd->length = csio->dxfer_len;
if (cmd->length)
cmd->data = csio->data_ptr;
break;
case CAM_DATA_BIO:
if (csio->dxfer_len > (sc->max_num_sge * MRSAS_PAGE_SIZE)) {
mrsas_release_mpt_cmd(cmd);
ccb_h->status = CAM_REQ_TOO_BIG;
goto done;
}
cmd->length = csio->dxfer_len;
if (cmd->length)
cmd->data = csio->data_ptr;
@ -539,11 +529,6 @@ mrsas_startio(struct mrsas_softc *sc, struct cam_sim *sim,
#else
if (!(ccb_h->flags & CAM_DATA_PHYS)) { /* Virtual data address */
if (!(ccb_h->flags & CAM_SCATTER_VALID)) {
if (csio->dxfer_len > (sc->max_num_sge * MRSAS_PAGE_SIZE)) {
mrsas_release_mpt_cmd(cmd);
ccb_h->status = CAM_REQ_TOO_BIG;
goto done;
}
cmd->length = csio->dxfer_len;
if (cmd->length)
cmd->data = csio->data_ptr;
@ -867,11 +852,6 @@ mrsas_build_ldio_rw(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
io_request->DataLength = htole32(cmd->length);
if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) {
if (cmd->sge_count > sc->max_num_sge) {
device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds"
"max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge);
return (FAIL);
}
if (sc->is_ventura || sc->is_aero)
io_request->RaidContext.raid_context_g35.numSGE = cmd->sge_count;
else {
@ -1234,11 +1214,6 @@ mrsas_build_ldio_nonrw(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
io_request->DataLength = cmd->length;
if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) {
if (cmd->sge_count > sc->max_num_sge) {
device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds"
"max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge);
return (1);
}
if (sc->is_ventura || sc->is_aero)
io_request->RaidContext.raid_context_g35.numSGE = cmd->sge_count;
else {
@ -1364,11 +1339,6 @@ mrsas_build_syspdio(struct mrsas_softc *sc, struct mrsas_mpt_cmd *cmd,
io_request->DataLength = htole32(cmd->length);
if (mrsas_map_request(sc, cmd, ccb) == SUCCESS) {
if (cmd->sge_count > sc->max_num_sge) {
device_printf(sc->mrsas_dev, "Error: sge_count (0x%x) exceeds"
"max (0x%x) allowed\n", cmd->sge_count, sc->max_num_sge);
return (1);
}
if (sc->is_ventura || sc->is_aero)
io_request->RaidContext.raid_context_g35.numSGE = cmd->sge_count;
else {
@ -1714,10 +1684,6 @@ mrsas_data_load_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
if (cmd->flags & MRSAS_DIR_OUT)
bus_dmamap_sync(cmd->sc->data_tag, cmd->data_dmamap,
BUS_DMASYNC_PREWRITE);
if (nseg > sc->max_num_sge) {
device_printf(sc->mrsas_dev, "SGE count is too large or 0.\n");
return;
}
/* Check for whether PRPs should be built or IEEE SGLs*/
if ((cmd->io_request->IoFlags & MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) &&