s390/qeth: dynamically allocate diag cmds
authorJulian Wiedmann <jwi@linux.ibm.com>
Thu, 27 Jun 2019 15:01:25 +0000 (17:01 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Jun 2019 17:18:23 +0000 (10:18 -0700)
Add a new wrapper that allocates DIAG cmds of the right size, and fills
in the common fields.

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/s390/net/qeth_core.h
drivers/s390/net/qeth_core_main.c
drivers/s390/net/qeth_core_mpc.h
drivers/s390/net/qeth_l3_main.c

index 258756d..b99fe6b 100644 (file)
@@ -1008,6 +1008,9 @@ struct qeth_cmd_buffer *qeth_get_setassparms_cmd(struct qeth_card *card,
                                                 u16 cmd_code,
                                                 unsigned int data_length,
                                                 enum qeth_prot_versions prot);
+struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
+                                         enum qeth_diags_cmds sub_cmd,
+                                         unsigned int data_length);
 
 struct sk_buff *qeth_core_get_next_skb(struct qeth_card *,
                struct qeth_qdio_buffer *, struct qdio_buffer_element **, int *,
index 696aba5..2207489 100644 (file)
@@ -3037,6 +3037,25 @@ int qeth_query_switch_attributes(struct qeth_card *card,
                                qeth_query_switch_attributes_cb, sw_info);
 }
 
+struct qeth_cmd_buffer *qeth_get_diag_cmd(struct qeth_card *card,
+                                         enum qeth_diags_cmds sub_cmd,
+                                         unsigned int data_length)
+{
+       struct qeth_ipacmd_diagass *cmd;
+       struct qeth_cmd_buffer *iob;
+
+       iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SET_DIAG_ASS, QETH_PROT_NONE,
+                                DIAG_HDR_LEN + data_length);
+       if (!iob)
+               return NULL;
+
+       cmd = &__ipa_cmd(iob)->data.diagass;
+       cmd->subcmd_len = DIAG_SUB_HDR_LEN + data_length;
+       cmd->subcmd = sub_cmd;
+       return iob;
+}
+EXPORT_SYMBOL_GPL(qeth_get_diag_cmd);
+
 static int qeth_query_setdiagass_cb(struct qeth_card *card,
                struct qeth_reply *reply, unsigned long data)
 {
@@ -3055,15 +3074,11 @@ static int qeth_query_setdiagass_cb(struct qeth_card *card,
 static int qeth_query_setdiagass(struct qeth_card *card)
 {
        struct qeth_cmd_buffer *iob;
-       struct qeth_ipa_cmd    *cmd;
 
        QETH_CARD_TEXT(card, 2, "qdiagass");
-       iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
+       iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_QUERY, 0);
        if (!iob)
                return -ENOMEM;
-       cmd = __ipa_cmd(iob);
-       cmd->data.diagass.subcmd_len = 16;
-       cmd->data.diagass.subcmd = QETH_DIAGS_CMD_QUERY;
        return qeth_send_ipa_cmd(card, iob, qeth_query_setdiagass_cb, NULL);
 }
 
@@ -3111,12 +3126,10 @@ int qeth_hw_trap(struct qeth_card *card, enum qeth_diags_trap_action action)
        struct qeth_ipa_cmd *cmd;
 
        QETH_CARD_TEXT(card, 2, "diagtrap");
-       iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
+       iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRAP, 64);
        if (!iob)
                return -ENOMEM;
        cmd = __ipa_cmd(iob);
-       cmd->data.diagass.subcmd_len = 80;
-       cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRAP;
        cmd->data.diagass.type = 1;
        cmd->data.diagass.action = action;
        switch (action) {
index 46f0385..5cec877 100644 (file)
@@ -599,6 +599,11 @@ struct qeth_ipacmd_diagass {
        __u8   cdata[64];
 } __attribute__ ((packed));
 
+#define DIAG_HDR_LEN           offsetofend(struct qeth_ipacmd_diagass, ext)
+#define DIAG_SUB_HDR_LEN       (offsetofend(struct qeth_ipacmd_diagass, ext) -\
+                                offsetof(struct qeth_ipacmd_diagass, \
+                                         subcmd_len))
+
 /* VNIC Characteristics IPA Command: *****************************************/
 /* IPA commands/sub commands for VNICC */
 #define IPA_VNICC_QUERY_CHARS          0x00000000L
index ff4d514..2e10f5b 100644 (file)
@@ -1107,12 +1107,10 @@ qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
 
        QETH_CARD_TEXT(card, 2, "diagtrac");
 
-       iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0);
+       iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRACE, 0);
        if (!iob)
                return -ENOMEM;
        cmd = __ipa_cmd(iob);
-       cmd->data.diagass.subcmd_len = 16;
-       cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE;
        cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
        cmd->data.diagass.action = diags_cmd;
        return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);