Skip to content

Commit 68bdc63

Browse files
Varun Prakashmartinkpetersen
authored andcommitted
scsi: csiostor: fix incorrect port capabilities
- use be32_to_cpu() instead of ntohs() for 32 bit port capabilities. - add a new function fwcaps32_to_caps16() to convert 32 bit port capabilities to 16 bit port capabilities. Signed-off-by: Varun Prakash <varun@chelsio.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 89809b0 commit 68bdc63

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

drivers/scsi/csiostor/csio_hw.c

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,46 @@ fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16)
16011601
return caps32;
16021602
}
16031603

1604+
/**
1605+
* fwcaps32_to_caps16 - convert 32-bit Port Capabilities to 16-bits
1606+
* @caps32: a 32-bit Port Capabilities value
1607+
*
1608+
* Returns the equivalent 16-bit Port Capabilities value. Note that
1609+
* not all 32-bit Port Capabilities can be represented in the 16-bit
1610+
* Port Capabilities and some fields/values may not make it.
1611+
*/
1612+
fw_port_cap16_t fwcaps32_to_caps16(fw_port_cap32_t caps32)
1613+
{
1614+
fw_port_cap16_t caps16 = 0;
1615+
1616+
#define CAP32_TO_CAP16(__cap) \
1617+
do { \
1618+
if (caps32 & FW_PORT_CAP32_##__cap) \
1619+
caps16 |= FW_PORT_CAP_##__cap; \
1620+
} while (0)
1621+
1622+
CAP32_TO_CAP16(SPEED_100M);
1623+
CAP32_TO_CAP16(SPEED_1G);
1624+
CAP32_TO_CAP16(SPEED_10G);
1625+
CAP32_TO_CAP16(SPEED_25G);
1626+
CAP32_TO_CAP16(SPEED_40G);
1627+
CAP32_TO_CAP16(SPEED_100G);
1628+
CAP32_TO_CAP16(FC_RX);
1629+
CAP32_TO_CAP16(FC_TX);
1630+
CAP32_TO_CAP16(802_3_PAUSE);
1631+
CAP32_TO_CAP16(802_3_ASM_DIR);
1632+
CAP32_TO_CAP16(ANEG);
1633+
CAP32_TO_CAP16(FORCE_PAUSE);
1634+
CAP32_TO_CAP16(MDIAUTO);
1635+
CAP32_TO_CAP16(MDISTRAIGHT);
1636+
CAP32_TO_CAP16(FEC_RS);
1637+
CAP32_TO_CAP16(FEC_BASER_RS);
1638+
1639+
#undef CAP32_TO_CAP16
1640+
1641+
return caps16;
1642+
}
1643+
16041644
/**
16051645
* lstatus_to_fwcap - translate old lstatus to 32-bit Port Capabilities
16061646
* @lstatus: old FW_PORT_ACTION_GET_PORT_INFO lstatus value
@@ -1759,7 +1799,7 @@ csio_enable_ports(struct csio_hw *hw)
17591799
val = 1;
17601800

17611801
csio_mb_params(hw, mbp, CSIO_MB_DEFAULT_TMO,
1762-
hw->pfn, 0, 1, &param, &val, false,
1802+
hw->pfn, 0, 1, &param, &val, true,
17631803
NULL);
17641804

17651805
if (csio_mb_issue(hw, mbp)) {
@@ -1769,16 +1809,9 @@ csio_enable_ports(struct csio_hw *hw)
17691809
return -EINVAL;
17701810
}
17711811

1772-
csio_mb_process_read_params_rsp(hw, mbp, &retval, 1,
1773-
&val);
1774-
if (retval != FW_SUCCESS) {
1775-
csio_err(hw, "FW_PARAMS_CMD(r) port:%d failed: 0x%x\n",
1776-
portid, retval);
1777-
mempool_free(mbp, hw->mb_mempool);
1778-
return -EINVAL;
1779-
}
1780-
1781-
fw_caps = val;
1812+
csio_mb_process_read_params_rsp(hw, mbp, &retval,
1813+
0, NULL);
1814+
fw_caps = retval ? FW_CAPS16 : FW_CAPS32;
17821815
}
17831816

17841817
/* Read PORT information */

drivers/scsi/csiostor/csio_hw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ int csio_handle_intr_status(struct csio_hw *, unsigned int,
639639

640640
fw_port_cap32_t fwcap_to_fwspeed(fw_port_cap32_t acaps);
641641
fw_port_cap32_t fwcaps16_to_caps32(fw_port_cap16_t caps16);
642+
fw_port_cap16_t fwcaps32_to_caps16(fw_port_cap32_t caps32);
642643
fw_port_cap32_t lstatus_to_fwcap(u32 lstatus);
643644

644645
int csio_hw_start(struct csio_hw *);

drivers/scsi/csiostor/csio_mb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ csio_mb_port(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
368368
FW_CMD_LEN16_V(sizeof(*cmdp) / 16));
369369

370370
if (fw_caps == FW_CAPS16)
371-
cmdp->u.l1cfg.rcap = cpu_to_be32(fc);
371+
cmdp->u.l1cfg.rcap = cpu_to_be32(fwcaps32_to_caps16(fc));
372372
else
373373
cmdp->u.l1cfg32.rcap32 = cpu_to_be32(fc);
374374
}
@@ -395,8 +395,8 @@ csio_mb_process_read_port_rsp(struct csio_hw *hw, struct csio_mb *mbp,
395395
*pcaps = fwcaps16_to_caps32(ntohs(rsp->u.info.pcap));
396396
*acaps = fwcaps16_to_caps32(ntohs(rsp->u.info.acap));
397397
} else {
398-
*pcaps = ntohs(rsp->u.info32.pcaps32);
399-
*acaps = ntohs(rsp->u.info32.acaps32);
398+
*pcaps = be32_to_cpu(rsp->u.info32.pcaps32);
399+
*acaps = be32_to_cpu(rsp->u.info32.acaps32);
400400
}
401401
}
402402
}

0 commit comments

Comments
 (0)