Skip to content

Commit

Permalink
Advertise the MPI Message Version that's contained in the IOCFacts me…
Browse files Browse the repository at this point in the history
…ssage

in the sysctl block for the driver.  mpsutil/mprutil needs this so it can
know how big of a buffer to allocate when requesting the IOCFacts from the
controller.  This eliminates the kernel console messages about wrong
allocation sizes.

Reported by:	imp
  • Loading branch information
Scott Long authored and Scott Long committed Feb 7, 2020
1 parent b041593 commit 69e85eb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
14 changes: 12 additions & 2 deletions sys/dev/mpr/mpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ mpr_iocfacts_allocate(struct mpr_softc *sc, uint8_t attaching)
sc->facts->FWVersion.Struct.Unit,
sc->facts->FWVersion.Struct.Dev);

snprintf(sc->msg_version, sizeof(sc->msg_version), "%d.%d",
(sc->facts->MsgVersion & MPI2_IOCFACTS_MSGVERSION_MAJOR_MASK) >>
MPI2_IOCFACTS_MSGVERSION_MAJOR_SHIFT,
(sc->facts->MsgVersion & MPI2_IOCFACTS_MSGVERSION_MINOR_MASK) >>
MPI2_IOCFACTS_MSGVERSION_MINOR_SHIFT);

mpr_dprint(sc, MPR_INFO, "Firmware: %s, Driver: %s\n", sc->fw_version,
MPR_DRIVER_VERSION);
mpr_dprint(sc, MPR_INFO,
Expand Down Expand Up @@ -1833,13 +1839,17 @@ mpr_setup_sysctl(struct mpr_softc *sc)
"Total number of event frames allocated");

SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "firmware_version", CTLFLAG_RW, sc->fw_version,
OID_AUTO, "firmware_version", CTLFLAG_RD, sc->fw_version,
strlen(sc->fw_version), "firmware version");

SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "driver_version", CTLFLAG_RW, MPR_DRIVER_VERSION,
OID_AUTO, "driver_version", CTLFLAG_RD, MPR_DRIVER_VERSION,
strlen(MPR_DRIVER_VERSION), "driver version");

SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "msg_version", CTLFLAG_RD, sc->msg_version,
strlen(sc->msg_version), "message interface version");

SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "io_cmds_active", CTLFLAG_RD,
&sc->io_cmds_active, 0, "number of currently active commands");
Expand Down
1 change: 1 addition & 0 deletions sys/dev/mpr/mprvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ struct mpr_softc {
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
char fw_version[16];
char msg_version[8];
struct mpr_command *commands;
struct mpr_chain *chains;
struct mpr_prp_page *prps;
Expand Down
14 changes: 12 additions & 2 deletions sys/dev/mps/mps.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ mps_iocfacts_allocate(struct mps_softc *sc, uint8_t attaching)
sc->facts->FWVersion.Struct.Unit,
sc->facts->FWVersion.Struct.Dev);

snprintf(sc->msg_version, sizeof(sc->msg_version), "%d.%d",
(sc->facts->MsgVersion & MPI2_IOCFACTS_MSGVERSION_MAJOR_MASK) >>
MPI2_IOCFACTS_MSGVERSION_MAJOR_SHIFT,
(sc->facts->MsgVersion & MPI2_IOCFACTS_MSGVERSION_MINOR_MASK) >>
MPI2_IOCFACTS_MSGVERSION_MINOR_SHIFT);

mps_dprint(sc, MPS_INFO, "Firmware: %s, Driver: %s\n", sc->fw_version,
MPS_DRIVER_VERSION);
mps_dprint(sc, MPS_INFO, "IOCCapabilities: %b\n",
Expand Down Expand Up @@ -1742,13 +1748,17 @@ mps_setup_sysctl(struct mps_softc *sc)
"Total number of event frames allocated");

SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "firmware_version", CTLFLAG_RW, sc->fw_version,
OID_AUTO, "firmware_version", CTLFLAG_RD, sc->fw_version,
strlen(sc->fw_version), "firmware version");

SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "driver_version", CTLFLAG_RW, MPS_DRIVER_VERSION,
OID_AUTO, "driver_version", CTLFLAG_RD, MPS_DRIVER_VERSION,
strlen(MPS_DRIVER_VERSION), "driver version");

SYSCTL_ADD_STRING(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "msg_version", CTLFLAG_RD, sc->msg_version,
strlen(sc->msg_version), "message interface version");

SYSCTL_ADD_INT(sysctl_ctx, SYSCTL_CHILDREN(sysctl_tree),
OID_AUTO, "io_cmds_active", CTLFLAG_RD,
&sc->io_cmds_active, 0, "number of currently active commands");
Expand Down
1 change: 1 addition & 0 deletions sys/dev/mps/mpsvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ struct mps_softc {
struct sysctl_ctx_list sysctl_ctx;
struct sysctl_oid *sysctl_tree;
char fw_version[16];
char msg_version[8];
struct mps_command *commands;
struct mps_chain *chains;
struct callout periodic;
Expand Down
21 changes: 17 additions & 4 deletions usr.sbin/mpsutil/mps_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,23 +724,36 @@ mps_get_iocfacts(int fd)
{
MPI2_IOC_FACTS_REPLY *facts;
MPI2_IOC_FACTS_REQUEST req;
char msgver[8], sysctlname[128];
size_t len, factslen;
int error;

facts = malloc(sizeof(MPI2_IOC_FACTS_REPLY));
snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%d.msg_version",
is_mps ? "mps" : "mpr", mps_unit);

factslen = sizeof(MPI2_IOC_FACTS_REPLY);
len = sizeof(msgver);
error = sysctlbyname(sysctlname, msgver, &len, NULL, 0);
if (error == 0) {
if (strncmp(msgver, "2.6", sizeof(msgver)) == 0)
factslen += 4;
}

facts = malloc(factslen);
if (facts == NULL) {
errno = ENOMEM;
return (NULL);
}

bzero(&req, sizeof(MPI2_IOC_FACTS_REQUEST));
bzero(&req, factslen);
req.Function = MPI2_FUNCTION_IOC_FACTS;

#if 1
error = mps_pass_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST),
facts, sizeof(MPI2_IOC_FACTS_REPLY), NULL, 0, NULL, 0, 10);
facts, factslen, NULL, 0, NULL, 0, 10);
#else
error = mps_user_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST),
facts, sizeof(MPI2_IOC_FACTS_REPLY), NULL, 0, 0);
facts, factslen, NULL, 0, 0);
#endif
if (error) {
free(facts);
Expand Down

0 comments on commit 69e85eb

Please sign in to comment.