]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/net/ethernet/sfc/mcdi.c
sfc: Avoid generating over-length MC_CMD_FLUSH_RX_QUEUES request
[karo-tx-linux.git] / drivers / net / ethernet / sfc / mcdi.c
index 17b6463e459c141c49631f482058ff6f2904f96c..eb85217ce3ab5d979c9c519058fc9e7ef5f9e261 100644 (file)
@@ -22,7 +22,7 @@
  **************************************************************************
  */
 
-#define MCDI_RPC_TIMEOUT       10 /*seconds */
+#define MCDI_RPC_TIMEOUT       (10 * HZ)
 
 #define MCDI_PDU(efx)                                                  \
        (efx_port_num(efx) ? MC_SMEM_P1_PDU_OFST : MC_SMEM_P0_PDU_OFST)
@@ -120,7 +120,7 @@ static void efx_mcdi_copyout(struct efx_nic *efx, u8 *outbuf, size_t outlen)
 static int efx_mcdi_poll(struct efx_nic *efx)
 {
        struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
-       unsigned int time, finish;
+       unsigned long time, finish;
        unsigned int respseq, respcmd, error;
        unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
        unsigned int rc, spins;
@@ -136,7 +136,7 @@ static int efx_mcdi_poll(struct efx_nic *efx)
         * and poll once a jiffy (approximately)
         */
        spins = TICK_USEC;
-       finish = get_seconds() + MCDI_RPC_TIMEOUT;
+       finish = jiffies + MCDI_RPC_TIMEOUT;
 
        while (1) {
                if (spins != 0) {
@@ -146,7 +146,7 @@ static int efx_mcdi_poll(struct efx_nic *efx)
                        schedule_timeout_uninterruptible(1);
                }
 
-               time = get_seconds();
+               time = jiffies;
 
                rmb();
                efx_readd(efx, &reg, pdu);
@@ -158,7 +158,7 @@ static int efx_mcdi_poll(struct efx_nic *efx)
                    EFX_DWORD_FIELD(reg, MCDI_HEADER_RESPONSE))
                        break;
 
-               if (time >= finish)
+               if (time_after(time, finish))
                        return -ETIMEDOUT;
        }
 
@@ -250,7 +250,7 @@ static int efx_mcdi_await_completion(struct efx_nic *efx)
        if (wait_event_timeout(
                    mcdi->wq,
                    atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED,
-                   msecs_to_jiffies(MCDI_RPC_TIMEOUT * 1000)) == 0)
+                   MCDI_RPC_TIMEOUT) == 0)
                return -ETIMEDOUT;
 
        /* Check if efx_mcdi_set_mode() switched us back to polled completions.
@@ -641,9 +641,8 @@ int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
                           u16 *fw_subtype_list, u32 *capabilities)
 {
        uint8_t outbuf[MC_CMD_GET_BOARD_CFG_OUT_LENMIN];
-       size_t outlen;
+       size_t outlen, offset, i;
        int port_num = efx_port_num(efx);
-       int offset;
        int rc;
 
        BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN != 0);
@@ -663,11 +662,16 @@ int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
                : MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0_OFST;
        if (mac_address)
                memcpy(mac_address, outbuf + offset, ETH_ALEN);
-       if (fw_subtype_list)
-               memcpy(fw_subtype_list,
-                      outbuf + MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_OFST,
-                      MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MINNUM *
-                      sizeof(fw_subtype_list[0]));
+       if (fw_subtype_list) {
+               offset = MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_OFST;
+               for (i = 0;
+                    i < MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MINNUM;
+                    i++) {
+                       fw_subtype_list[i] =
+                               le16_to_cpup((__le16 *)(outbuf + offset));
+                       offset += 2;
+               }
+       }
        if (capabilities) {
                if (port_num)
                        *capabilities = MCDI_DWORD(outbuf,
@@ -1164,6 +1168,9 @@ int efx_mcdi_flush_rxqs(struct efx_nic *efx)
        __le32 *qid;
        int rc, count;
 
+       BUILD_BUG_ON(EFX_MAX_CHANNELS >
+                    MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM);
+
        qid = kmalloc(EFX_MAX_CHANNELS * sizeof(*qid), GFP_KERNEL);
        if (qid == NULL)
                return -ENOMEM;