Greg Kroah-Hartman | ab9953f | 2017-11-14 18:38:04 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2 | /* |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 3 | * Copyright IBM Corp. 2007, 2009 |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 4 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com>, |
| 5 | * Frank Pavlic <fpavlic@de.ibm.com>, |
| 6 | * Thomas Spatzier <tspat@de.ibm.com>, |
| 7 | * Frank Blaschka <frank.blaschka@de.ibm.com> |
| 8 | */ |
| 9 | |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 10 | #define KMSG_COMPONENT "qeth" |
| 11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 12 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | #include <linux/string.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 20 | #include <linux/list.h> |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 21 | #include <linux/hash.h> |
| 22 | #include <linux/hashtable.h> |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 23 | #include <asm/chsc.h> |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 24 | #include <asm/setup.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 25 | #include "qeth_core.h" |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 26 | #include "qeth_l2.h" |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 27 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 28 | static void qeth_bridgeport_query_support(struct qeth_card *card); |
| 29 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 30 | struct qeth_ipa_cmd *cmd); |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 31 | static void qeth_addr_change_event(struct qeth_card *card, |
| 32 | struct qeth_ipa_cmd *cmd); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 33 | static void qeth_l2_vnicc_set_defaults(struct qeth_card *card); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 34 | static void qeth_l2_vnicc_init(struct qeth_card *card); |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 35 | static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, |
| 36 | u32 *timeout); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 37 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 38 | static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 39 | { |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 40 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 41 | |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 42 | if (retcode) |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 43 | QETH_CARD_TEXT_(card, 2, "err%04x", retcode); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 44 | switch (retcode) { |
| 45 | case IPA_RC_SUCCESS: |
| 46 | rc = 0; |
| 47 | break; |
| 48 | case IPA_RC_L2_UNSUPPORTED_CMD: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 49 | rc = -EOPNOTSUPP; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 50 | break; |
| 51 | case IPA_RC_L2_ADDR_TABLE_FULL: |
| 52 | rc = -ENOSPC; |
| 53 | break; |
| 54 | case IPA_RC_L2_DUP_MAC: |
| 55 | case IPA_RC_L2_DUP_LAYER3_MAC: |
Julian Wiedmann | bdb0cc1 | 2020-03-25 10:35:05 +0100 | [diff] [blame] | 56 | rc = -EADDRINUSE; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 57 | break; |
| 58 | case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: |
| 59 | case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: |
Julian Wiedmann | bdb0cc1 | 2020-03-25 10:35:05 +0100 | [diff] [blame] | 60 | rc = -EADDRNOTAVAIL; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 61 | break; |
| 62 | case IPA_RC_L2_MAC_NOT_FOUND: |
| 63 | rc = -ENOENT; |
| 64 | break; |
| 65 | default: |
| 66 | rc = -EIO; |
| 67 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 68 | } |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 69 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 72 | static int qeth_l2_send_setdelmac_cb(struct qeth_card *card, |
| 73 | struct qeth_reply *reply, |
| 74 | unsigned long data) |
| 75 | { |
| 76 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 77 | |
| 78 | return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code); |
| 79 | } |
| 80 | |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 81 | static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, |
| 82 | enum qeth_ipa_cmds ipacmd) |
| 83 | { |
| 84 | struct qeth_ipa_cmd *cmd; |
| 85 | struct qeth_cmd_buffer *iob; |
| 86 | |
| 87 | QETH_CARD_TEXT(card, 2, "L2sdmac"); |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 88 | iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4, |
| 89 | IPA_DATA_SIZEOF(setdelmac)); |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 90 | if (!iob) |
| 91 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 92 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 93 | cmd->data.setdelmac.mac_length = ETH_ALEN; |
| 94 | ether_addr_copy(cmd->data.setdelmac.mac, mac); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 95 | return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL); |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) |
| 99 | { |
| 100 | int rc; |
| 101 | |
| 102 | QETH_CARD_TEXT(card, 2, "L2Setmac"); |
| 103 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); |
| 104 | if (rc == 0) { |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 105 | dev_info(&card->gdev->dev, |
Julian Wiedmann | 654e3d4 | 2019-01-25 15:44:19 +0100 | [diff] [blame] | 106 | "MAC address %pM successfully registered\n", mac); |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 107 | } else { |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 108 | switch (rc) { |
Julian Wiedmann | bdb0cc1 | 2020-03-25 10:35:05 +0100 | [diff] [blame] | 109 | case -EADDRINUSE: |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 110 | dev_warn(&card->gdev->dev, |
| 111 | "MAC address %pM already exists\n", mac); |
| 112 | break; |
Julian Wiedmann | bdb0cc1 | 2020-03-25 10:35:05 +0100 | [diff] [blame] | 113 | case -EADDRNOTAVAIL: |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 114 | dev_warn(&card->gdev->dev, |
| 115 | "MAC address %pM is not authorized\n", mac); |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | return rc; |
| 120 | } |
| 121 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 122 | static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 123 | { |
Vasily Gorbik | 9d0a58f | 2018-06-29 19:45:52 +0200 | [diff] [blame] | 124 | enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ? |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 125 | IPA_CMD_SETGMAC : IPA_CMD_SETVMAC; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 126 | int rc; |
| 127 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 128 | QETH_CARD_TEXT(card, 2, "L2Wmac"); |
| 129 | rc = qeth_l2_send_setdelmac(card, mac, cmd); |
Julian Wiedmann | bdb0cc1 | 2020-03-25 10:35:05 +0100 | [diff] [blame] | 130 | if (rc == -EADDRINUSE) |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 131 | QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n", |
| 132 | CARD_DEVID(card)); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 133 | else if (rc) |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 134 | QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n", |
| 135 | CARD_DEVID(card), rc); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 136 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 139 | static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 140 | { |
Vasily Gorbik | 9d0a58f | 2018-06-29 19:45:52 +0200 | [diff] [blame] | 141 | enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ? |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 142 | IPA_CMD_DELGMAC : IPA_CMD_DELVMAC; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 143 | int rc; |
| 144 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 145 | QETH_CARD_TEXT(card, 2, "L2Rmac"); |
| 146 | rc = qeth_l2_send_setdelmac(card, mac, cmd); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 147 | if (rc) |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 148 | QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n", |
| 149 | CARD_DEVID(card), rc); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 150 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 153 | static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 154 | { |
| 155 | struct qeth_mac *mac; |
| 156 | struct hlist_node *tmp; |
| 157 | int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 158 | |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 159 | hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 160 | hash_del(&mac->hnode); |
| 161 | kfree(mac); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 162 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 165 | static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue, |
| 166 | struct qeth_hdr *hdr, struct sk_buff *skb, |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 167 | int ipv, unsigned int data_len) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 168 | { |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 169 | int cast_type = qeth_get_ether_cast_type(skb); |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 170 | struct vlan_ethhdr *veth = vlan_eth_hdr(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 171 | |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 172 | hdr->hdr.l2.pkt_length = data_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 173 | |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 174 | if (skb_is_gso(skb)) { |
| 175 | hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO; |
| 176 | } else { |
| 177 | hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; |
Julian Wiedmann | eeac0e2 | 2019-08-23 11:48:49 +0200 | [diff] [blame] | 178 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 179 | qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv); |
Julian Wiedmann | fc69660 | 2018-09-17 17:35:55 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 182 | /* set byte byte 3 to casting flags */ |
| 183 | if (cast_type == RTN_MULTICAST) |
| 184 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; |
| 185 | else if (cast_type == RTN_BROADCAST) |
| 186 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; |
| 187 | else |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 188 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 189 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 190 | /* VSWITCH relies on the VLAN |
| 191 | * information to be present in |
| 192 | * the QDIO header */ |
| 193 | if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { |
| 194 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; |
| 195 | hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); |
| 196 | } |
| 197 | } |
| 198 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 199 | static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 200 | { |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 201 | if (retcode) |
| 202 | QETH_CARD_TEXT_(card, 2, "err%04x", retcode); |
| 203 | |
| 204 | switch (retcode) { |
| 205 | case IPA_RC_SUCCESS: |
| 206 | return 0; |
| 207 | case IPA_RC_L2_INVALID_VLAN_ID: |
| 208 | return -EINVAL; |
| 209 | case IPA_RC_L2_DUP_VLAN_ID: |
| 210 | return -EEXIST; |
| 211 | case IPA_RC_L2_VLAN_ID_NOT_FOUND: |
| 212 | return -ENOENT; |
| 213 | case IPA_RC_L2_VLAN_ID_NOT_ALLOWED: |
| 214 | return -EPERM; |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 215 | default: |
| 216 | return -EIO; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, |
| 221 | struct qeth_reply *reply, |
| 222 | unsigned long data) |
| 223 | { |
| 224 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 225 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 226 | QETH_CARD_TEXT(card, 2, "L2sdvcb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 227 | if (cmd->hdr.return_code) { |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 228 | QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n", |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 229 | cmd->data.setdelvlan.vlan_id, |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 230 | CARD_DEVID(card), cmd->hdr.return_code); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 231 | QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 232 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 233 | return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 237 | enum qeth_ipa_cmds ipacmd) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 238 | { |
| 239 | struct qeth_ipa_cmd *cmd; |
| 240 | struct qeth_cmd_buffer *iob; |
| 241 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 242 | QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 243 | iob = qeth_ipa_alloc_cmd(card, ipacmd, QETH_PROT_IPV4, |
| 244 | IPA_DATA_SIZEOF(setdelvlan)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 245 | if (!iob) |
| 246 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 247 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 248 | cmd->data.setdelvlan.vlan_id = i; |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 249 | return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 252 | static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, |
| 253 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 254 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 255 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 256 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 257 | QETH_CARD_TEXT_(card, 4, "aid:%d", vid); |
Ursula Braun | 10651db | 2010-10-01 02:51:13 +0000 | [diff] [blame] | 258 | if (!vid) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 259 | return 0; |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 260 | |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 261 | return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 264 | static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, |
| 265 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 266 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 267 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 268 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 269 | QETH_CARD_TEXT_(card, 4, "kid:%d", vid); |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 270 | if (!vid) |
| 271 | return 0; |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 272 | |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 273 | return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 276 | static void qeth_l2_stop_card(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 277 | { |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 278 | QETH_CARD_TEXT(card, 2, "stopcard"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 279 | |
| 280 | qeth_set_allowed_threads(card, 0, 1); |
Julian Wiedmann | 0f7aedbd | 2019-02-28 18:59:44 +0100 | [diff] [blame] | 281 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 282 | cancel_work_sync(&card->rx_mode_work); |
| 283 | qeth_l2_drain_rx_mode_cache(card); |
| 284 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 285 | if (card->state == CARD_STATE_SOFTSETUP) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 286 | qeth_clear_ipacmd_list(card); |
Julian Wiedmann | 41c47da | 2019-04-17 18:17:28 +0200 | [diff] [blame] | 287 | qeth_drain_output_queues(card); |
Julian Wiedmann | 0e635c2 | 2020-03-10 18:38:03 +0100 | [diff] [blame] | 288 | cancel_delayed_work_sync(&card->buffer_reclaim_work); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 289 | card->state = CARD_STATE_DOWN; |
| 290 | } |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 291 | |
Julian Wiedmann | 8b5026b | 2019-12-23 15:03:21 +0100 | [diff] [blame] | 292 | qeth_qdio_clear_card(card, 0); |
Julian Wiedmann | aa3ad392 | 2020-01-25 16:53:00 +0100 | [diff] [blame] | 293 | qeth_clear_working_pool_list(card); |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 294 | flush_workqueue(card->event_wq); |
Julian Wiedmann | 0d49c06 | 2020-05-06 10:09:41 +0200 | [diff] [blame] | 295 | qeth_flush_local_addrs(card); |
Julian Wiedmann | 0f39930 | 2019-12-18 16:32:27 +0100 | [diff] [blame] | 296 | card->info.promisc_mode = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 299 | static int qeth_l2_request_initial_mac(struct qeth_card *card) |
| 300 | { |
| 301 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 302 | |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 303 | QETH_CARD_TEXT(card, 2, "l2reqmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 304 | |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 305 | if (MACHINE_IS_VM) { |
| 306 | rc = qeth_vm_request_mac(card); |
| 307 | if (!rc) |
| 308 | goto out; |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 309 | QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n", |
| 310 | CARD_DEVID(card), rc); |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 311 | QETH_CARD_TEXT_(card, 2, "err%04x", rc); |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 312 | /* fall back to alternative mechanism: */ |
| 313 | } |
| 314 | |
Julian Wiedmann | b144b99 | 2018-11-08 15:06:15 +0100 | [diff] [blame] | 315 | if (!IS_OSN(card)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 316 | rc = qeth_setadpparms_change_macaddr(card); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 317 | if (!rc) |
Julian Wiedmann | 21b1702 | 2018-04-26 09:42:24 +0200 | [diff] [blame] | 318 | goto out; |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 319 | QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n", |
| 320 | CARD_DEVID(card), rc); |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 321 | QETH_CARD_TEXT_(card, 2, "1err%04x", rc); |
Julian Wiedmann | 21b1702 | 2018-04-26 09:42:24 +0200 | [diff] [blame] | 322 | /* fall back once more: */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 323 | } |
Julian Wiedmann | 21b1702 | 2018-04-26 09:42:24 +0200 | [diff] [blame] | 324 | |
| 325 | /* some devices don't support a custom MAC address: */ |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 326 | if (IS_OSM(card) || IS_OSX(card)) |
Julian Wiedmann | 21b1702 | 2018-04-26 09:42:24 +0200 | [diff] [blame] | 327 | return (rc) ? rc : -EADDRNOTAVAIL; |
| 328 | eth_hw_addr_random(card->dev); |
| 329 | |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 330 | out: |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 331 | QETH_CARD_HEX(card, 2, card->dev->dev_addr, card->dev->addr_len); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
Julian Wiedmann | 654e3d4 | 2019-01-25 15:44:19 +0100 | [diff] [blame] | 335 | static void qeth_l2_register_dev_addr(struct qeth_card *card) |
| 336 | { |
| 337 | if (!is_valid_ether_addr(card->dev->dev_addr)) |
| 338 | qeth_l2_request_initial_mac(card); |
| 339 | |
| 340 | if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr)) |
Julian Wiedmann | 9de1511 | 2020-03-25 10:35:02 +0100 | [diff] [blame] | 341 | card->info.dev_addr_is_registered = 1; |
| 342 | else |
| 343 | card->info.dev_addr_is_registered = 0; |
Julian Wiedmann | 654e3d4 | 2019-01-25 15:44:19 +0100 | [diff] [blame] | 344 | } |
| 345 | |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 346 | static int qeth_l2_validate_addr(struct net_device *dev) |
| 347 | { |
| 348 | struct qeth_card *card = dev->ml_priv; |
| 349 | |
Julian Wiedmann | 9de1511 | 2020-03-25 10:35:02 +0100 | [diff] [blame] | 350 | if (card->info.dev_addr_is_registered) |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 351 | return eth_validate_addr(dev); |
| 352 | |
| 353 | QETH_CARD_TEXT(card, 4, "nomacadr"); |
| 354 | return -EPERM; |
| 355 | } |
| 356 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 357 | static int qeth_l2_set_mac_address(struct net_device *dev, void *p) |
| 358 | { |
| 359 | struct sockaddr *addr = p; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 360 | struct qeth_card *card = dev->ml_priv; |
Julian Wiedmann | bcacfcb | 2018-04-19 12:52:09 +0200 | [diff] [blame] | 361 | u8 old_addr[ETH_ALEN]; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 362 | int rc = 0; |
| 363 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 364 | QETH_CARD_TEXT(card, 3, "setmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 365 | |
Julian Wiedmann | 8024cc9 | 2019-02-15 19:22:31 +0100 | [diff] [blame] | 366 | if (IS_OSM(card) || IS_OSX(card)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 367 | QETH_CARD_TEXT(card, 3, "setmcTYP"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 368 | return -EOPNOTSUPP; |
| 369 | } |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 370 | QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN); |
Julian Wiedmann | bcacfcb | 2018-04-19 12:52:09 +0200 | [diff] [blame] | 371 | if (!is_valid_ether_addr(addr->sa_data)) |
| 372 | return -EADDRNOTAVAIL; |
| 373 | |
Julian Wiedmann | bcacfcb | 2018-04-19 12:52:09 +0200 | [diff] [blame] | 374 | /* don't register the same address twice */ |
| 375 | if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) && |
Julian Wiedmann | 9de1511 | 2020-03-25 10:35:02 +0100 | [diff] [blame] | 376 | card->info.dev_addr_is_registered) |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 377 | return 0; |
Julian Wiedmann | bcacfcb | 2018-04-19 12:52:09 +0200 | [diff] [blame] | 378 | |
| 379 | /* add the new address, switch over, drop the old */ |
| 380 | rc = qeth_l2_send_setmac(card, addr->sa_data); |
| 381 | if (rc) |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 382 | return rc; |
Julian Wiedmann | bcacfcb | 2018-04-19 12:52:09 +0200 | [diff] [blame] | 383 | ether_addr_copy(old_addr, dev->dev_addr); |
| 384 | ether_addr_copy(dev->dev_addr, addr->sa_data); |
| 385 | |
Julian Wiedmann | 9de1511 | 2020-03-25 10:35:02 +0100 | [diff] [blame] | 386 | if (card->info.dev_addr_is_registered) |
Julian Wiedmann | bcacfcb | 2018-04-19 12:52:09 +0200 | [diff] [blame] | 387 | qeth_l2_remove_mac(card, old_addr); |
Julian Wiedmann | 9de1511 | 2020-03-25 10:35:02 +0100 | [diff] [blame] | 388 | card->info.dev_addr_is_registered = 1; |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 389 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 392 | static void qeth_l2_promisc_to_bridge(struct qeth_card *card, bool enable) |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 393 | { |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 394 | int role; |
| 395 | int rc; |
| 396 | |
| 397 | QETH_CARD_TEXT(card, 3, "pmisc2br"); |
| 398 | |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 399 | if (enable) { |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 400 | if (card->options.sbp.reflect_promisc_primary) |
| 401 | role = QETH_SBP_ROLE_PRIMARY; |
| 402 | else |
| 403 | role = QETH_SBP_ROLE_SECONDARY; |
| 404 | } else |
| 405 | role = QETH_SBP_ROLE_NONE; |
| 406 | |
| 407 | rc = qeth_bridgeport_setrole(card, role); |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 408 | QETH_CARD_TEXT_(card, 2, "bpm%c%04x", enable ? '+' : '-', rc); |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 409 | if (!rc) { |
| 410 | card->options.sbp.role = role; |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 411 | card->info.promisc_mode = enable; |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 412 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 413 | } |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 414 | |
| 415 | static void qeth_l2_set_promisc_mode(struct qeth_card *card) |
| 416 | { |
| 417 | bool enable = card->dev->flags & IFF_PROMISC; |
| 418 | |
| 419 | if (card->info.promisc_mode == enable) |
| 420 | return; |
| 421 | |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 422 | if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) { |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 423 | qeth_setadp_promisc_mode(card, enable); |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 424 | } else { |
| 425 | mutex_lock(&card->sbp_lock); |
| 426 | if (card->options.sbp.reflect_promisc) |
| 427 | qeth_l2_promisc_to_bridge(card, enable); |
| 428 | mutex_unlock(&card->sbp_lock); |
| 429 | } |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 432 | /* New MAC address is added to the hash table and marked to be written on card |
| 433 | * only if there is not in the hash table storage already |
| 434 | * |
| 435 | */ |
Julian Wiedmann | 4641b02 | 2017-12-20 20:10:59 +0100 | [diff] [blame] | 436 | static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 437 | { |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 438 | u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2])); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 439 | struct qeth_mac *mac; |
| 440 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 441 | hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) { |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 442 | if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 443 | mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 444 | return; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 449 | if (!mac) |
| 450 | return; |
| 451 | |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 452 | ether_addr_copy(mac->mac_addr, ha->addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 453 | mac->disp_flag = QETH_DISP_ADDR_ADD; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 454 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 455 | hash_add(card->mac_htable, &mac->hnode, mac_hash); |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 456 | } |
| 457 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 458 | static void qeth_l2_rx_mode_work(struct work_struct *work) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 459 | { |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 460 | struct qeth_card *card = container_of(work, struct qeth_card, |
| 461 | rx_mode_work); |
| 462 | struct net_device *dev = card->dev; |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 463 | struct netdev_hw_addr *ha; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 464 | struct qeth_mac *mac; |
| 465 | struct hlist_node *tmp; |
| 466 | int i; |
| 467 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 468 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 469 | QETH_CARD_TEXT(card, 3, "setmulti"); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 470 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 471 | netif_addr_lock_bh(dev); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 472 | netdev_for_each_mc_addr(ha, dev) |
Julian Wiedmann | 4641b02 | 2017-12-20 20:10:59 +0100 | [diff] [blame] | 473 | qeth_l2_add_mac(card, ha); |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 474 | netdev_for_each_uc_addr(ha, dev) |
Julian Wiedmann | 4641b02 | 2017-12-20 20:10:59 +0100 | [diff] [blame] | 475 | qeth_l2_add_mac(card, ha); |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 476 | netif_addr_unlock_bh(dev); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 477 | |
| 478 | hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 479 | switch (mac->disp_flag) { |
| 480 | case QETH_DISP_ADDR_DELETE: |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 481 | qeth_l2_remove_mac(card, mac->mac_addr); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 482 | hash_del(&mac->hnode); |
| 483 | kfree(mac); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 484 | break; |
| 485 | case QETH_DISP_ADDR_ADD: |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 486 | rc = qeth_l2_write_mac(card, mac->mac_addr); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 487 | if (rc) { |
| 488 | hash_del(&mac->hnode); |
| 489 | kfree(mac); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 490 | break; |
| 491 | } |
| 492 | /* fall through */ |
| 493 | default: |
| 494 | /* for next call to set_rx_mode(): */ |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 495 | mac->disp_flag = QETH_DISP_ADDR_DELETE; |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 496 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 497 | } |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 498 | |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 499 | qeth_l2_set_promisc_mode(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 500 | } |
| 501 | |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 502 | static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb, |
| 503 | struct qeth_qdio_out_q *queue) |
| 504 | { |
Julian Wiedmann | b413ff8 | 2020-03-18 13:54:46 +0100 | [diff] [blame] | 505 | gfp_t gfp = GFP_ATOMIC | (skb_pfmemalloc(skb) ? __GFP_MEMALLOC : 0); |
Julian Wiedmann | 69d7ce8 | 2018-09-17 17:36:04 +0200 | [diff] [blame] | 506 | struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data; |
| 507 | addr_t end = (addr_t)(skb->data + sizeof(*hdr)); |
| 508 | addr_t start = (addr_t)skb->data; |
| 509 | unsigned int elements = 0; |
| 510 | unsigned int hd_len = 0; |
| 511 | int rc; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 512 | |
| 513 | if (skb->protocol == htons(ETH_P_IPV6)) |
| 514 | return -EPROTONOSUPPORT; |
| 515 | |
Julian Wiedmann | 69d7ce8 | 2018-09-17 17:36:04 +0200 | [diff] [blame] | 516 | if (qeth_get_elements_for_range(start, end) > 1) { |
| 517 | /* Misaligned HW header, move it to its own buffer element. */ |
Julian Wiedmann | b413ff8 | 2020-03-18 13:54:46 +0100 | [diff] [blame] | 518 | hdr = kmem_cache_alloc(qeth_core_header_cache, gfp); |
Julian Wiedmann | 69d7ce8 | 2018-09-17 17:36:04 +0200 | [diff] [blame] | 519 | if (!hdr) |
| 520 | return -ENOMEM; |
| 521 | hd_len = sizeof(*hdr); |
| 522 | skb_copy_from_linear_data(skb, (char *)hdr, hd_len); |
| 523 | elements++; |
| 524 | } |
| 525 | |
| 526 | elements += qeth_count_elements(skb, hd_len); |
Julian Wiedmann | 4e26c5f | 2019-04-25 18:25:59 +0200 | [diff] [blame] | 527 | if (elements > queue->max_elements) { |
Julian Wiedmann | 69d7ce8 | 2018-09-17 17:36:04 +0200 | [diff] [blame] | 528 | rc = -E2BIG; |
| 529 | goto out; |
| 530 | } |
| 531 | |
| 532 | rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len, |
| 533 | elements); |
| 534 | out: |
| 535 | if (rc && hd_len) |
| 536 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 537 | return rc; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 538 | } |
| 539 | |
Julian Wiedmann | e38db6b | 2017-04-11 16:11:14 +0200 | [diff] [blame] | 540 | static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, |
| 541 | struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 542 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 543 | struct qeth_card *card = dev->ml_priv; |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 544 | u16 txq = skb_get_queue_mapping(skb); |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 545 | struct qeth_qdio_out_q *queue; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 546 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 547 | |
Julian Wiedmann | eeac0e2 | 2019-08-23 11:48:49 +0200 | [diff] [blame] | 548 | if (!skb_is_gso(skb)) |
| 549 | qdisc_skb_cb(skb)->pkt_len = skb->len; |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 550 | if (IS_IQD(card)) |
Julian Wiedmann | 54a5094 | 2019-04-17 18:17:35 +0200 | [diff] [blame] | 551 | txq = qeth_iqd_translate_txq(dev, txq); |
| 552 | queue = card->qdio.out_qs[txq]; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 553 | |
Julian Wiedmann | 5f89eca | 2018-07-19 12:43:58 +0200 | [diff] [blame] | 554 | if (IS_OSN(card)) |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 555 | rc = qeth_l2_xmit_osn(card, skb, queue); |
Julian Wiedmann | 5f89eca | 2018-07-19 12:43:58 +0200 | [diff] [blame] | 556 | else |
Julian Wiedmann | 73dc2da | 2019-04-17 18:17:33 +0200 | [diff] [blame] | 557 | rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb), |
Julian Wiedmann | 58aa249 | 2019-04-25 18:26:00 +0200 | [diff] [blame] | 558 | qeth_l2_fill_header); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 559 | |
Julian Wiedmann | eeac0e2 | 2019-08-23 11:48:49 +0200 | [diff] [blame] | 560 | if (!rc) |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 561 | return NETDEV_TX_OK; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 562 | |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 563 | QETH_TXQ_STAT_INC(queue, tx_dropped); |
Julian Wiedmann | 104b485 | 2019-03-18 16:40:56 +0100 | [diff] [blame] | 564 | kfree_skb(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 565 | return NETDEV_TX_OK; |
| 566 | } |
| 567 | |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 568 | static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb, |
| 569 | struct net_device *sb_dev) |
| 570 | { |
Julian Wiedmann | 73dc2da | 2019-04-17 18:17:33 +0200 | [diff] [blame] | 571 | struct qeth_card *card = dev->ml_priv; |
| 572 | |
| 573 | if (IS_IQD(card)) |
| 574 | return qeth_iqd_select_queue(dev, skb, |
Julian Wiedmann | 58aa249 | 2019-04-25 18:26:00 +0200 | [diff] [blame] | 575 | qeth_get_ether_cast_type(skb), |
Julian Wiedmann | 73dc2da | 2019-04-17 18:17:33 +0200 | [diff] [blame] | 576 | sb_dev); |
Julian Wiedmann | 1c103cf | 2020-03-18 13:54:47 +0100 | [diff] [blame] | 577 | |
| 578 | return IS_VM_NIC(card) ? netdev_pick_tx(dev, skb, sb_dev) : |
| 579 | qeth_get_priority_queue(card, skb); |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 580 | } |
| 581 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 582 | static const struct device_type qeth_l2_devtype = { |
| 583 | .name = "qeth_layer2", |
| 584 | .groups = qeth_l2_attr_groups, |
| 585 | }; |
| 586 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 587 | static int qeth_l2_probe_device(struct ccwgroup_device *gdev) |
| 588 | { |
| 589 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | 9111e78 | 2017-05-10 19:07:51 +0200 | [diff] [blame] | 590 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 591 | |
Julian Wiedmann | fb64de1 | 2020-03-27 11:19:34 +0100 | [diff] [blame] | 592 | if (IS_OSN(card)) |
| 593 | dev_notice(&gdev->dev, "OSN support will be dropped in 2021\n"); |
| 594 | |
Julian Wiedmann | 12b409d | 2019-03-18 16:40:54 +0100 | [diff] [blame] | 595 | qeth_l2_vnicc_set_defaults(card); |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 596 | mutex_init(&card->sbp_lock); |
Julian Wiedmann | 12b409d | 2019-03-18 16:40:54 +0100 | [diff] [blame] | 597 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 598 | if (gdev->dev.type == &qeth_generic_devtype) { |
| 599 | rc = qeth_l2_create_device_attributes(&gdev->dev); |
| 600 | if (rc) |
| 601 | return rc; |
| 602 | } |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 603 | |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 604 | hash_init(card->mac_htable); |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 605 | INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) |
| 610 | { |
| 611 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 612 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 613 | if (cgdev->dev.type == &qeth_generic_devtype) |
| 614 | qeth_l2_remove_device_attributes(&cgdev->dev); |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 615 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 616 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 617 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 618 | if (cgdev->state == CCWGROUP_ONLINE) |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame] | 619 | qeth_set_offline(card, false); |
Julian Wiedmann | c2780c1 | 2019-02-04 17:40:08 +0100 | [diff] [blame] | 620 | |
| 621 | cancel_work_sync(&card->close_dev_work); |
Julian Wiedmann | cd652be | 2020-03-18 13:54:55 +0100 | [diff] [blame] | 622 | if (card->dev->reg_state == NETREG_REGISTERED) |
Julian Wiedmann | 30356d0 | 2018-11-02 19:04:10 +0100 | [diff] [blame] | 623 | unregister_netdev(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 626 | static void qeth_l2_set_rx_mode(struct net_device *dev) |
| 627 | { |
| 628 | struct qeth_card *card = dev->ml_priv; |
| 629 | |
| 630 | schedule_work(&card->rx_mode_work); |
| 631 | } |
| 632 | |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 633 | /** |
| 634 | * qeth_l2_pnso() - perform network subchannel operation |
| 635 | * @card: qeth_card structure pointer |
| 636 | * @cnc: Boolean Change-Notification Control |
| 637 | * @cb: Callback function will be executed for each element |
| 638 | * of the address list |
| 639 | * @priv: Pointer to pass to the callback function. |
| 640 | * |
| 641 | * Collects network information in a network address list and calls the |
| 642 | * callback function for every entry in the list. If "change-notification- |
| 643 | * control" is set, further changes in the address list will be reported |
| 644 | * via the IPA command. |
| 645 | */ |
| 646 | static int qeth_l2_pnso(struct qeth_card *card, int cnc, |
| 647 | void (*cb)(void *priv, struct chsc_pnso_naid_l2 *entry), |
| 648 | void *priv) |
| 649 | { |
| 650 | struct ccw_device *ddev = CARD_DDEV(card); |
| 651 | struct chsc_pnso_area *rr; |
| 652 | u32 prev_instance = 0; |
| 653 | int isfirstblock = 1; |
| 654 | int i, size, elems; |
| 655 | int rc; |
| 656 | |
| 657 | QETH_CARD_TEXT(card, 2, "PNSO"); |
| 658 | rr = (struct chsc_pnso_area *)get_zeroed_page(GFP_KERNEL); |
| 659 | if (rr == NULL) |
| 660 | return -ENOMEM; |
| 661 | do { |
| 662 | /* on the first iteration, naihdr.resume_token will be zero */ |
| 663 | rc = ccw_device_pnso(ddev, rr, rr->naihdr.resume_token, cnc); |
| 664 | if (rc) |
| 665 | continue; |
| 666 | if (cb == NULL) |
| 667 | continue; |
| 668 | |
| 669 | size = rr->naihdr.naids; |
| 670 | if (size != sizeof(struct chsc_pnso_naid_l2)) { |
| 671 | WARN_ON_ONCE(1); |
| 672 | continue; |
| 673 | } |
| 674 | |
| 675 | elems = (rr->response.length - sizeof(struct chsc_header) - |
| 676 | sizeof(struct chsc_pnso_naihdr)) / size; |
| 677 | |
| 678 | if (!isfirstblock && (rr->naihdr.instance != prev_instance)) { |
| 679 | /* Inform the caller that they need to scrap */ |
| 680 | /* the data that was already reported via cb */ |
| 681 | rc = -EAGAIN; |
| 682 | break; |
| 683 | } |
| 684 | isfirstblock = 0; |
| 685 | prev_instance = rr->naihdr.instance; |
| 686 | for (i = 0; i < elems; i++) |
| 687 | (*cb)(priv, &rr->entries[i]); |
| 688 | } while ((rc == -EBUSY) || (!rc && /* list stored */ |
| 689 | /* resume token is non-zero => list incomplete */ |
| 690 | (rr->naihdr.resume_token.t1 || rr->naihdr.resume_token.t2))); |
| 691 | |
| 692 | if (rc) |
| 693 | QETH_CARD_TEXT_(card, 2, "PNrp%04x", rr->response.code); |
| 694 | |
| 695 | free_page((unsigned long)rr); |
| 696 | return rc; |
| 697 | } |
| 698 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 699 | static const struct net_device_ops qeth_l2_netdev_ops = { |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 700 | .ndo_open = qeth_open, |
| 701 | .ndo_stop = qeth_stop, |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 702 | .ndo_get_stats64 = qeth_get_stats64, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 703 | .ndo_start_xmit = qeth_l2_hard_start_xmit, |
Julian Wiedmann | 6d69b1f | 2017-12-01 10:14:50 +0100 | [diff] [blame] | 704 | .ndo_features_check = qeth_features_check, |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 705 | .ndo_select_queue = qeth_l2_select_queue, |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 706 | .ndo_validate_addr = qeth_l2_validate_addr, |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 707 | .ndo_set_rx_mode = qeth_l2_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 708 | .ndo_do_ioctl = qeth_do_ioctl, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 709 | .ndo_set_mac_address = qeth_l2_set_mac_address, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 710 | .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, |
| 711 | .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, |
| 712 | .ndo_tx_timeout = qeth_tx_timeout, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 713 | .ndo_fix_features = qeth_fix_features, |
| 714 | .ndo_set_features = qeth_set_features |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 715 | }; |
| 716 | |
Julian Wiedmann | 8024cc9 | 2019-02-15 19:22:31 +0100 | [diff] [blame] | 717 | static const struct net_device_ops qeth_osn_netdev_ops = { |
| 718 | .ndo_open = qeth_open, |
| 719 | .ndo_stop = qeth_stop, |
| 720 | .ndo_get_stats64 = qeth_get_stats64, |
| 721 | .ndo_start_xmit = qeth_l2_hard_start_xmit, |
| 722 | .ndo_validate_addr = eth_validate_addr, |
| 723 | .ndo_tx_timeout = qeth_tx_timeout, |
| 724 | }; |
| 725 | |
Julian Wiedmann | cd652be | 2020-03-18 13:54:55 +0100 | [diff] [blame] | 726 | static int qeth_l2_setup_netdev(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 727 | { |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 728 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 729 | |
Julian Wiedmann | 8024cc9 | 2019-02-15 19:22:31 +0100 | [diff] [blame] | 730 | if (IS_OSN(card)) { |
| 731 | card->dev->netdev_ops = &qeth_osn_netdev_ops; |
Julian Wiedmann | 25e2c34 | 2017-05-10 19:07:53 +0200 | [diff] [blame] | 732 | card->dev->flags |= IFF_NOARP; |
Julian Wiedmann | 8024cc9 | 2019-02-15 19:22:31 +0100 | [diff] [blame] | 733 | goto add_napi; |
| 734 | } |
| 735 | |
Julian Wiedmann | 1c103cf | 2020-03-18 13:54:47 +0100 | [diff] [blame] | 736 | rc = qeth_setup_netdev(card); |
| 737 | if (rc) |
| 738 | return rc; |
| 739 | |
Julian Wiedmann | 8024cc9 | 2019-02-15 19:22:31 +0100 | [diff] [blame] | 740 | card->dev->needed_headroom = sizeof(struct qeth_hdr); |
| 741 | card->dev->netdev_ops = &qeth_l2_netdev_ops; |
| 742 | card->dev->priv_flags |= IFF_UNICAST_FLT; |
Julian Wiedmann | 9400c53 | 2017-10-18 17:40:20 +0200 | [diff] [blame] | 743 | |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 744 | if (IS_OSM(card)) { |
Julian Wiedmann | 9400c53 | 2017-10-18 17:40:20 +0200 | [diff] [blame] | 745 | card->dev->features |= NETIF_F_VLAN_CHALLENGED; |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 746 | } else { |
| 747 | if (!IS_VM_NIC(card)) |
| 748 | card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Julian Wiedmann | 9400c53 | 2017-10-18 17:40:20 +0200 | [diff] [blame] | 749 | card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Julian Wiedmann | 5fc692a | 2019-01-25 15:44:23 +0100 | [diff] [blame] | 750 | } |
Julian Wiedmann | 0f34294 | 2018-03-09 18:12:54 +0100 | [diff] [blame] | 751 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 752 | if (IS_OSD(card) && !IS_VM_NIC(card)) { |
Julian Wiedmann | 6d69b1f | 2017-12-01 10:14:50 +0100 | [diff] [blame] | 753 | card->dev->features |= NETIF_F_SG; |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 754 | /* OSA 3S and earlier has no RX/TX support */ |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 755 | if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 756 | card->dev->hw_features |= NETIF_F_IP_CSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 757 | card->dev->vlan_features |= NETIF_F_IP_CSUM; |
| 758 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 759 | } |
Kittipon Meesompop | 571f9dd8 | 2018-04-26 09:42:22 +0200 | [diff] [blame] | 760 | if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) { |
| 761 | card->dev->hw_features |= NETIF_F_IPV6_CSUM; |
| 762 | card->dev->vlan_features |= NETIF_F_IPV6_CSUM; |
| 763 | } |
Kittipon Meesompop | d7e6ed9 | 2018-04-26 09:42:23 +0200 | [diff] [blame] | 764 | if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) || |
| 765 | qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) { |
| 766 | card->dev->hw_features |= NETIF_F_RXCSUM; |
| 767 | card->dev->vlan_features |= NETIF_F_RXCSUM; |
| 768 | } |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 769 | if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) { |
| 770 | card->dev->hw_features |= NETIF_F_TSO; |
| 771 | card->dev->vlan_features |= NETIF_F_TSO; |
| 772 | } |
| 773 | if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) { |
| 774 | card->dev->hw_features |= NETIF_F_TSO6; |
| 775 | card->dev->vlan_features |= NETIF_F_TSO6; |
| 776 | } |
| 777 | |
| 778 | if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) { |
| 779 | card->dev->needed_headroom = sizeof(struct qeth_hdr_tso); |
Julian Wiedmann | c619e9a | 2020-05-06 10:09:44 +0200 | [diff] [blame] | 780 | netif_keep_dst(card->dev); |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 781 | netif_set_gso_max_size(card->dev, |
| 782 | PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1)); |
| 783 | } |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 784 | |
Julian Wiedmann | 8024cc9 | 2019-02-15 19:22:31 +0100 | [diff] [blame] | 785 | add_napi: |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 786 | netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); |
Julian Wiedmann | cd652be | 2020-03-18 13:54:55 +0100 | [diff] [blame] | 787 | return register_netdev(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 788 | } |
| 789 | |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 790 | static void qeth_l2_trace_features(struct qeth_card *card) |
| 791 | { |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 792 | /* Set BridgePort features */ |
| 793 | QETH_CARD_TEXT(card, 2, "featuSBP"); |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 794 | QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, |
| 795 | sizeof(card->options.sbp.supported_funcs)); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 796 | /* VNIC Characteristics features */ |
| 797 | QETH_CARD_TEXT(card, 2, "feaVNICC"); |
| 798 | QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars, |
| 799 | sizeof(card->options.vnicc.sup_chars)); |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 800 | } |
| 801 | |
Julian Wiedmann | 8ca769e | 2020-01-25 16:52:59 +0100 | [diff] [blame] | 802 | static void qeth_l2_setup_bridgeport_attrs(struct qeth_card *card) |
| 803 | { |
| 804 | if (!card->options.sbp.reflect_promisc && |
| 805 | card->options.sbp.role != QETH_SBP_ROLE_NONE) { |
| 806 | /* Conditional to avoid spurious error messages */ |
| 807 | qeth_bridgeport_setrole(card, card->options.sbp.role); |
| 808 | /* Let the callback function refresh the stored role value. */ |
| 809 | qeth_bridgeport_query_ports(card, &card->options.sbp.role, |
| 810 | NULL); |
| 811 | } |
| 812 | if (card->options.sbp.hostnotification) { |
| 813 | if (qeth_bridgeport_an_set(card, 1)) |
| 814 | card->options.sbp.hostnotification = 0; |
| 815 | } else { |
| 816 | qeth_bridgeport_an_set(card, 0); |
| 817 | } |
| 818 | } |
| 819 | |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame] | 820 | static int qeth_l2_set_online(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 821 | { |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame] | 822 | struct ccwgroup_device *gdev = card->gdev; |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 823 | struct net_device *dev = card->dev; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 824 | int rc = 0; |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 825 | bool carrier_ok; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 826 | |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 827 | rc = qeth_core_hardsetup_card(card, &carrier_ok); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 828 | if (rc) { |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 829 | QETH_CARD_TEXT_(card, 2, "2err%04x", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 830 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 831 | goto out_remove; |
| 832 | } |
Julian Wiedmann | 654e3d4 | 2019-01-25 15:44:19 +0100 | [diff] [blame] | 833 | |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 834 | mutex_lock(&card->sbp_lock); |
Julian Wiedmann | d7ef489f | 2019-02-28 18:59:37 +0100 | [diff] [blame] | 835 | qeth_bridgeport_query_support(card); |
Julian Wiedmann | 8ca769e | 2020-01-25 16:52:59 +0100 | [diff] [blame] | 836 | if (card->options.sbp.supported_funcs) { |
| 837 | qeth_l2_setup_bridgeport_attrs(card); |
Julian Wiedmann | d7ef489f | 2019-02-28 18:59:37 +0100 | [diff] [blame] | 838 | dev_info(&card->gdev->dev, |
Julian Wiedmann | 8ca769e | 2020-01-25 16:52:59 +0100 | [diff] [blame] | 839 | "The device represents a Bridge Capable Port\n"); |
| 840 | } |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 841 | mutex_unlock(&card->sbp_lock); |
Julian Wiedmann | d7ef489f | 2019-02-28 18:59:37 +0100 | [diff] [blame] | 842 | |
| 843 | qeth_l2_register_dev_addr(card); |
| 844 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 845 | /* for the rx_bcast characteristic, init VNICC after setmac */ |
| 846 | qeth_l2_vnicc_init(card); |
| 847 | |
| 848 | qeth_trace_features(card); |
| 849 | qeth_l2_trace_features(card); |
| 850 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 851 | qeth_print_status_message(card); |
| 852 | |
| 853 | /* softsetup */ |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 854 | QETH_CARD_TEXT(card, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 855 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 856 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 857 | |
| 858 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
Julian Wiedmann | d025da9 | 2018-06-29 19:45:54 +0200 | [diff] [blame] | 859 | |
Julian Wiedmann | cd652be | 2020-03-18 13:54:55 +0100 | [diff] [blame] | 860 | if (dev->reg_state != NETREG_REGISTERED) { |
| 861 | rc = qeth_l2_setup_netdev(card); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 862 | if (rc) |
| 863 | goto out_remove; |
Julian Wiedmann | cd652be | 2020-03-18 13:54:55 +0100 | [diff] [blame] | 864 | |
| 865 | if (carrier_ok) |
| 866 | netif_carrier_on(dev); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 867 | } else { |
| 868 | rtnl_lock(); |
| 869 | if (carrier_ok) |
| 870 | netif_carrier_on(dev); |
| 871 | else |
| 872 | netif_carrier_off(dev); |
| 873 | |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 874 | netif_device_attach(dev); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 875 | qeth_enable_hw_features(dev); |
| 876 | |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 877 | if (card->info.open_when_online) { |
| 878 | card->info.open_when_online = 0; |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 879 | dev_open(dev, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 880 | } |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 881 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 882 | } |
| 883 | /* let user_space know that device is online */ |
| 884 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
| 885 | return 0; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 886 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 887 | out_remove: |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 888 | qeth_l2_stop_card(card); |
Julian Wiedmann | f9e50b0 | 2019-12-05 14:33:04 +0100 | [diff] [blame] | 889 | qeth_stop_channel(&card->data); |
| 890 | qeth_stop_channel(&card->write); |
| 891 | qeth_stop_channel(&card->read); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 892 | qdio_free(CARD_DDEV(card)); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 893 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 894 | } |
| 895 | |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame] | 896 | static void qeth_l2_set_offline(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 897 | { |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 898 | qeth_l2_stop_card(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static int __init qeth_l2_init(void) |
| 902 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 903 | pr_info("register layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | static void __exit qeth_l2_exit(void) |
| 908 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 909 | pr_info("unregister layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 912 | /* Returns zero if the command is successfully "consumed" */ |
| 913 | static int qeth_l2_control_event(struct qeth_card *card, |
| 914 | struct qeth_ipa_cmd *cmd) |
| 915 | { |
| 916 | switch (cmd->hdr.command) { |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 917 | case IPA_CMD_SETBRIDGEPORT_OSA: |
| 918 | case IPA_CMD_SETBRIDGEPORT_IQD: |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 919 | if (cmd->data.sbp.hdr.command_code == |
| 920 | IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { |
| 921 | qeth_bridge_state_change(card, cmd); |
| 922 | return 0; |
| 923 | } else |
| 924 | return 1; |
| 925 | case IPA_CMD_ADDRESS_CHANGE_NOTIF: |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 926 | qeth_addr_change_event(card, cmd); |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 927 | return 0; |
| 928 | default: |
| 929 | return 1; |
| 930 | } |
| 931 | } |
| 932 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 933 | struct qeth_discipline qeth_l2_discipline = { |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 934 | .devtype = &qeth_l2_devtype, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 935 | .setup = qeth_l2_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 936 | .remove = qeth_l2_remove_device, |
| 937 | .set_online = qeth_l2_set_online, |
| 938 | .set_offline = qeth_l2_set_offline, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 939 | .do_ioctl = NULL, |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 940 | .control_event_handler = qeth_l2_control_event, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 941 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 942 | EXPORT_SYMBOL_GPL(qeth_l2_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 943 | |
Julian Wiedmann | 4e2b5aa | 2020-03-27 11:19:33 +0100 | [diff] [blame] | 944 | #ifdef CONFIG_QETH_OSN |
Julian Wiedmann | 0ce37ec | 2019-06-11 18:37:54 +0200 | [diff] [blame] | 945 | static void qeth_osn_assist_cb(struct qeth_card *card, |
Julian Wiedmann | 12fc286 | 2019-08-20 16:46:36 +0200 | [diff] [blame] | 946 | struct qeth_cmd_buffer *iob, |
| 947 | unsigned int data_length) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 948 | { |
Julian Wiedmann | 308946b | 2019-08-20 16:46:39 +0200 | [diff] [blame] | 949 | qeth_notify_cmd(iob, 0); |
Julian Wiedmann | c3b2218 | 2019-06-27 17:01:28 +0200 | [diff] [blame] | 950 | qeth_put_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | int qeth_osn_assist(struct net_device *dev, void *data, int data_len) |
| 954 | { |
| 955 | struct qeth_cmd_buffer *iob; |
| 956 | struct qeth_card *card; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 957 | |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 958 | if (data_len < 0) |
| 959 | return -EINVAL; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 960 | if (!dev) |
| 961 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 962 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 963 | if (!card) |
| 964 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 965 | QETH_CARD_TEXT(card, 2, "osnsdmc"); |
Eugene Crosser | c352125 | 2015-01-16 14:05:47 +0100 | [diff] [blame] | 966 | if (!qeth_card_hw_is_reachable(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 967 | return -ENODEV; |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 968 | |
| 969 | iob = qeth_alloc_cmd(&card->write, IPA_PDU_HEADER_SIZE + data_len, 1, |
| 970 | QETH_IPA_TIMEOUT); |
Julian Wiedmann | 1273a80 | 2019-06-11 18:37:53 +0200 | [diff] [blame] | 971 | if (!iob) |
| 972 | return -ENOMEM; |
| 973 | |
Julian Wiedmann | 7f92316c | 2020-01-25 16:53:02 +0100 | [diff] [blame] | 974 | qeth_prepare_ipa_cmd(card, iob, (u16) data_len, NULL); |
| 975 | |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 976 | memcpy(__ipa_cmd(iob), data, data_len); |
Julian Wiedmann | 0ce37ec | 2019-06-11 18:37:54 +0200 | [diff] [blame] | 977 | iob->callback = qeth_osn_assist_cb; |
| 978 | return qeth_send_ipa_cmd(card, iob, NULL, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 979 | } |
| 980 | EXPORT_SYMBOL(qeth_osn_assist); |
| 981 | |
| 982 | int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, |
| 983 | int (*assist_cb)(struct net_device *, void *), |
| 984 | int (*data_cb)(struct sk_buff *)) |
| 985 | { |
| 986 | struct qeth_card *card; |
Julian Wiedmann | d7d18da | 2018-11-08 15:06:18 +0100 | [diff] [blame] | 987 | char bus_id[16]; |
| 988 | u16 devno; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 989 | |
Julian Wiedmann | d7d18da | 2018-11-08 15:06:18 +0100 | [diff] [blame] | 990 | memcpy(&devno, read_dev_no, 2); |
| 991 | sprintf(bus_id, "0.0.%04x", devno); |
| 992 | card = qeth_get_card_by_busid(bus_id); |
| 993 | if (!card || !IS_OSN(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 994 | return -ENODEV; |
Julian Wiedmann | d7d18da | 2018-11-08 15:06:18 +0100 | [diff] [blame] | 995 | *dev = card->dev; |
| 996 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 997 | QETH_CARD_TEXT(card, 2, "osnreg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 998 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 999 | return -EINVAL; |
| 1000 | card->osn_info.assist_cb = assist_cb; |
| 1001 | card->osn_info.data_cb = data_cb; |
| 1002 | return 0; |
| 1003 | } |
| 1004 | EXPORT_SYMBOL(qeth_osn_register); |
| 1005 | |
| 1006 | void qeth_osn_deregister(struct net_device *dev) |
| 1007 | { |
| 1008 | struct qeth_card *card; |
| 1009 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1010 | if (!dev) |
| 1011 | return; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1012 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1013 | if (!card) |
| 1014 | return; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1015 | QETH_CARD_TEXT(card, 2, "osndereg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1016 | card->osn_info.assist_cb = NULL; |
| 1017 | card->osn_info.data_cb = NULL; |
| 1018 | return; |
| 1019 | } |
| 1020 | EXPORT_SYMBOL(qeth_osn_deregister); |
Julian Wiedmann | 4e2b5aa | 2020-03-27 11:19:33 +0100 | [diff] [blame] | 1021 | #endif |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1022 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1023 | /* SETBRIDGEPORT support, async notifications */ |
| 1024 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1025 | enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; |
| 1026 | |
| 1027 | /** |
| 1028 | * qeth_bridge_emit_host_event() - bridgeport address change notification |
| 1029 | * @card: qeth_card structure pointer, for udev events. |
| 1030 | * @evtype: "normal" register/unregister, or abort, or reset. For abort |
| 1031 | * and reset token and addr_lnid are unused and may be NULL. |
| 1032 | * @code: event bitmask: high order bit 0x80 value 1 means removal of an |
| 1033 | * object, 0 - addition of an object. |
| 1034 | * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. |
| 1035 | * @token: "network token" structure identifying physical address of the port. |
| 1036 | * @addr_lnid: pointer to structure with MAC address and VLAN ID. |
| 1037 | * |
| 1038 | * This function is called when registrations and deregistrations are |
| 1039 | * reported by the hardware, and also when notifications are enabled - |
| 1040 | * for all currently registered addresses. |
| 1041 | */ |
| 1042 | static void qeth_bridge_emit_host_event(struct qeth_card *card, |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1043 | enum qeth_an_event_type evtype, |
| 1044 | u8 code, |
| 1045 | struct net_if_token *token, |
| 1046 | struct mac_addr_lnid *addr_lnid) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1047 | { |
| 1048 | char str[7][32]; |
| 1049 | char *env[8]; |
| 1050 | int i = 0; |
| 1051 | |
| 1052 | switch (evtype) { |
| 1053 | case anev_reg_unreg: |
| 1054 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", |
| 1055 | (code & IPA_ADDR_CHANGE_CODE_REMOVAL) |
| 1056 | ? "deregister" : "register"); |
| 1057 | env[i] = str[i]; i++; |
| 1058 | if (code & IPA_ADDR_CHANGE_CODE_VLANID) { |
| 1059 | snprintf(str[i], sizeof(str[i]), "VLAN=%d", |
| 1060 | addr_lnid->lnid); |
| 1061 | env[i] = str[i]; i++; |
| 1062 | } |
| 1063 | if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { |
Eugene Crosser | 9846e70 | 2015-09-18 16:06:48 +0200 | [diff] [blame] | 1064 | snprintf(str[i], sizeof(str[i]), "MAC=%pM", |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1065 | addr_lnid->mac); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1066 | env[i] = str[i]; i++; |
| 1067 | } |
| 1068 | snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", |
| 1069 | token->cssid, token->ssid, token->devnum); |
| 1070 | env[i] = str[i]; i++; |
| 1071 | snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); |
| 1072 | env[i] = str[i]; i++; |
| 1073 | snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", |
| 1074 | token->chpid); |
| 1075 | env[i] = str[i]; i++; |
| 1076 | snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); |
| 1077 | env[i] = str[i]; i++; |
| 1078 | break; |
| 1079 | case anev_abort: |
| 1080 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); |
| 1081 | env[i] = str[i]; i++; |
| 1082 | break; |
| 1083 | case anev_reset: |
| 1084 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); |
| 1085 | env[i] = str[i]; i++; |
| 1086 | break; |
| 1087 | } |
| 1088 | env[i] = NULL; |
| 1089 | kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); |
| 1090 | } |
| 1091 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1092 | struct qeth_bridge_state_data { |
| 1093 | struct work_struct worker; |
| 1094 | struct qeth_card *card; |
| 1095 | struct qeth_sbp_state_change qports; |
| 1096 | }; |
| 1097 | |
| 1098 | static void qeth_bridge_state_change_worker(struct work_struct *work) |
| 1099 | { |
| 1100 | struct qeth_bridge_state_data *data = |
| 1101 | container_of(work, struct qeth_bridge_state_data, worker); |
| 1102 | /* We are only interested in the first entry - local port */ |
| 1103 | struct qeth_sbp_port_entry *entry = &data->qports.entry[0]; |
| 1104 | char env_locrem[32]; |
| 1105 | char env_role[32]; |
| 1106 | char env_state[32]; |
| 1107 | char *env[] = { |
| 1108 | env_locrem, |
| 1109 | env_role, |
| 1110 | env_state, |
| 1111 | NULL |
| 1112 | }; |
| 1113 | |
| 1114 | /* Role should not change by itself, but if it did, */ |
| 1115 | /* information from the hardware is authoritative. */ |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 1116 | mutex_lock(&data->card->sbp_lock); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1117 | data->card->options.sbp.role = entry->role; |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 1118 | mutex_unlock(&data->card->sbp_lock); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1119 | |
| 1120 | snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); |
| 1121 | snprintf(env_role, sizeof(env_role), "ROLE=%s", |
| 1122 | (entry->role == QETH_SBP_ROLE_NONE) ? "none" : |
| 1123 | (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : |
| 1124 | (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : |
| 1125 | "<INVALID>"); |
| 1126 | snprintf(env_state, sizeof(env_state), "STATE=%s", |
| 1127 | (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : |
| 1128 | (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" : |
| 1129 | (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" : |
| 1130 | "<INVALID>"); |
| 1131 | kobject_uevent_env(&data->card->gdev->dev.kobj, |
| 1132 | KOBJ_CHANGE, env); |
| 1133 | kfree(data); |
| 1134 | } |
| 1135 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1136 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 1137 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1138 | { |
| 1139 | struct qeth_sbp_state_change *qports = |
| 1140 | &cmd->data.sbp.data.state_change; |
| 1141 | struct qeth_bridge_state_data *data; |
| 1142 | int extrasize; |
| 1143 | |
| 1144 | QETH_CARD_TEXT(card, 2, "brstchng"); |
| 1145 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
Thomas Richter | 8a59314 | 2014-10-22 12:18:03 +0200 | [diff] [blame] | 1146 | QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1147 | return; |
| 1148 | } |
| 1149 | extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries; |
| 1150 | data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize, |
| 1151 | GFP_ATOMIC); |
| 1152 | if (!data) { |
| 1153 | QETH_CARD_TEXT(card, 2, "BPSalloc"); |
| 1154 | return; |
| 1155 | } |
| 1156 | INIT_WORK(&data->worker, qeth_bridge_state_change_worker); |
| 1157 | data->card = card; |
| 1158 | memcpy(&data->qports, qports, |
| 1159 | sizeof(struct qeth_sbp_state_change) + extrasize); |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 1160 | queue_work(card->event_wq, &data->worker); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1161 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1162 | |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1163 | struct qeth_addr_change_data { |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1164 | struct work_struct worker; |
| 1165 | struct qeth_card *card; |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1166 | struct qeth_ipacmd_addr_change ac_event; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1167 | }; |
| 1168 | |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1169 | static void qeth_addr_change_event_worker(struct work_struct *work) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1170 | { |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1171 | struct qeth_addr_change_data *data = |
| 1172 | container_of(work, struct qeth_addr_change_data, worker); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1173 | int i; |
| 1174 | |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1175 | QETH_CARD_TEXT(data->card, 4, "adrchgew"); |
| 1176 | if (data->ac_event.lost_event_mask) { |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1177 | dev_info(&data->card->gdev->dev, |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1178 | "Address change notification stopped on %s (%s)\n", |
| 1179 | data->card->dev->name, |
| 1180 | (data->ac_event.lost_event_mask == 0x01) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1181 | ? "Overflow" |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1182 | : (data->ac_event.lost_event_mask == 0x02) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1183 | ? "Bridge port state change" |
| 1184 | : "Unknown reason"); |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 1185 | mutex_lock(&data->card->sbp_lock); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1186 | data->card->options.sbp.hostnotification = 0; |
Julian Wiedmann | c8183f5 | 2019-11-20 14:20:56 +0100 | [diff] [blame] | 1187 | mutex_unlock(&data->card->sbp_lock); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1188 | qeth_bridge_emit_host_event(data->card, anev_abort, |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1189 | 0, NULL, NULL); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1190 | } else |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1191 | for (i = 0; i < data->ac_event.num_entries; i++) { |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1192 | struct qeth_ipacmd_addr_change_entry *entry = |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1193 | &data->ac_event.entry[i]; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1194 | qeth_bridge_emit_host_event(data->card, |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1195 | anev_reg_unreg, |
| 1196 | entry->change_code, |
| 1197 | &entry->token, |
| 1198 | &entry->addr_lnid); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1199 | } |
| 1200 | kfree(data); |
| 1201 | } |
| 1202 | |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1203 | static void qeth_addr_change_event(struct qeth_card *card, |
| 1204 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1205 | { |
| 1206 | struct qeth_ipacmd_addr_change *hostevs = |
| 1207 | &cmd->data.addrchange; |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1208 | struct qeth_addr_change_data *data; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1209 | int extrasize; |
| 1210 | |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1211 | QETH_CARD_TEXT(card, 4, "adrchgev"); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1212 | if (cmd->hdr.return_code != 0x0000) { |
| 1213 | if (cmd->hdr.return_code == 0x0010) { |
| 1214 | if (hostevs->lost_event_mask == 0x00) |
| 1215 | hostevs->lost_event_mask = 0xff; |
| 1216 | } else { |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1217 | QETH_CARD_TEXT_(card, 2, "ACHN%04x", |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1218 | cmd->hdr.return_code); |
| 1219 | return; |
| 1220 | } |
| 1221 | } |
| 1222 | extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * |
| 1223 | hostevs->num_entries; |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1224 | data = kzalloc(sizeof(struct qeth_addr_change_data) + extrasize, |
| 1225 | GFP_ATOMIC); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1226 | if (!data) { |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1227 | QETH_CARD_TEXT(card, 2, "ACNalloc"); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1228 | return; |
| 1229 | } |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1230 | INIT_WORK(&data->worker, qeth_addr_change_event_worker); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1231 | data->card = card; |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1232 | memcpy(&data->ac_event, hostevs, |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1233 | sizeof(struct qeth_ipacmd_addr_change) + extrasize); |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 1234 | queue_work(card->event_wq, &data->worker); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1235 | } |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1236 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1237 | /* SETBRIDGEPORT support; sending commands */ |
| 1238 | |
| 1239 | struct _qeth_sbp_cbctl { |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1240 | union { |
| 1241 | u32 supported; |
| 1242 | struct { |
| 1243 | enum qeth_sbp_roles *role; |
| 1244 | enum qeth_sbp_states *state; |
| 1245 | } qports; |
| 1246 | } data; |
| 1247 | }; |
| 1248 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1249 | static int qeth_bridgeport_makerc(struct qeth_card *card, |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1250 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1251 | { |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1252 | struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp; |
| 1253 | enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code; |
| 1254 | u16 ipa_rc = cmd->hdr.return_code; |
| 1255 | u16 sbp_rc = sbp->hdr.return_code; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1256 | int rc; |
| 1257 | |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1258 | if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS) |
| 1259 | return 0; |
| 1260 | |
| 1261 | if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) || |
| 1262 | (!IS_IQD(card) && ipa_rc == sbp_rc)) { |
| 1263 | switch (sbp_rc) { |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1264 | case IPA_RC_SUCCESS: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1265 | rc = 0; |
| 1266 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1267 | case IPA_RC_L2_UNSUPPORTED_CMD: |
| 1268 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1269 | rc = -EOPNOTSUPP; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1270 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1271 | case IPA_RC_SBP_OSA_NOT_CONFIGURED: |
| 1272 | case IPA_RC_SBP_IQD_NOT_CONFIGURED: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1273 | rc = -ENODEV; /* maybe not the best code here? */ |
| 1274 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1275 | "The device is not configured as a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1276 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1277 | case IPA_RC_SBP_OSA_OS_MISMATCH: |
| 1278 | case IPA_RC_SBP_IQD_OS_MISMATCH: |
Eugene Crosser | 1b05cf6 | 2016-06-16 16:18:51 +0200 | [diff] [blame] | 1279 | rc = -EPERM; |
| 1280 | dev_err(&card->gdev->dev, |
| 1281 | "A Bridge Port is already configured by a different operating system\n"); |
| 1282 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1283 | case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: |
| 1284 | case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1285 | switch (setcmd) { |
| 1286 | case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: |
| 1287 | rc = -EEXIST; |
| 1288 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1289 | "The LAN already has a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1290 | break; |
| 1291 | case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: |
| 1292 | rc = -EBUSY; |
| 1293 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1294 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1295 | break; |
| 1296 | default: |
| 1297 | rc = -EIO; |
| 1298 | } |
| 1299 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1300 | case IPA_RC_SBP_OSA_CURRENT_SECOND: |
| 1301 | case IPA_RC_SBP_IQD_CURRENT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1302 | rc = -EBUSY; |
| 1303 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1304 | "The device is already a secondary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1305 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1306 | case IPA_RC_SBP_OSA_LIMIT_SECOND: |
| 1307 | case IPA_RC_SBP_IQD_LIMIT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1308 | rc = -EEXIST; |
| 1309 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1310 | "The LAN cannot have more secondary Bridge Ports\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1311 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1312 | case IPA_RC_SBP_OSA_CURRENT_PRIMARY: |
| 1313 | case IPA_RC_SBP_IQD_CURRENT_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1314 | rc = -EBUSY; |
| 1315 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1316 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1317 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1318 | case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: |
| 1319 | case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1320 | rc = -EACCES; |
| 1321 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1322 | "The device is not authorized to be a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1323 | break; |
| 1324 | default: |
| 1325 | rc = -EIO; |
| 1326 | } |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1327 | } else { |
| 1328 | switch (ipa_rc) { |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1329 | case IPA_RC_NOTSUPP: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1330 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1331 | break; |
| 1332 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1333 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1334 | break; |
| 1335 | default: |
| 1336 | rc = -EIO; |
| 1337 | } |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1338 | } |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1339 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1340 | if (rc) { |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1341 | QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc); |
| 1342 | QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1343 | } |
| 1344 | return rc; |
| 1345 | } |
| 1346 | |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1347 | static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card, |
| 1348 | enum qeth_ipa_sbp_cmd sbp_cmd, |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1349 | unsigned int data_length) |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1350 | { |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1351 | enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD : |
| 1352 | IPA_CMD_SETBRIDGEPORT_OSA; |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1353 | struct qeth_ipacmd_sbp_hdr *hdr; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1354 | struct qeth_cmd_buffer *iob; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1355 | |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1356 | iob = qeth_ipa_alloc_cmd(card, ipa_cmd, QETH_PROT_NONE, |
| 1357 | data_length + |
| 1358 | offsetof(struct qeth_ipacmd_setbridgeport, |
| 1359 | data)); |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1360 | if (!iob) |
| 1361 | return iob; |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1362 | |
| 1363 | hdr = &__ipa_cmd(iob)->data.sbp.hdr; |
| 1364 | hdr->cmdlength = sizeof(*hdr) + data_length; |
| 1365 | hdr->command_code = sbp_cmd; |
| 1366 | hdr->used_total = 1; |
| 1367 | hdr->seq_no = 1; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1368 | return iob; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1369 | } |
| 1370 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1371 | static int qeth_bridgeport_query_support_cb(struct qeth_card *card, |
| 1372 | struct qeth_reply *reply, unsigned long data) |
| 1373 | { |
| 1374 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1375 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1376 | int rc; |
| 1377 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1378 | QETH_CARD_TEXT(card, 2, "brqsupcb"); |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1379 | rc = qeth_bridgeport_makerc(card, cmd); |
| 1380 | if (rc) |
| 1381 | return rc; |
| 1382 | |
| 1383 | cbctl->data.supported = |
| 1384 | cmd->data.sbp.data.query_cmds_supp.supported_cmds; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1385 | return 0; |
| 1386 | } |
| 1387 | |
| 1388 | /** |
| 1389 | * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. |
| 1390 | * @card: qeth_card structure pointer. |
| 1391 | * |
| 1392 | * Sets bitmask of supported setbridgeport subfunctions in the qeth_card |
| 1393 | * strucutre: card->options.sbp.supported_funcs. |
| 1394 | */ |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1395 | static void qeth_bridgeport_query_support(struct qeth_card *card) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1396 | { |
| 1397 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1398 | struct _qeth_sbp_cbctl cbctl; |
| 1399 | |
| 1400 | QETH_CARD_TEXT(card, 2, "brqsuppo"); |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1401 | iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED, |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1402 | SBP_DATA_SIZEOF(query_cmds_supp)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1403 | if (!iob) |
| 1404 | return; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1405 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1406 | if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1407 | &cbctl)) { |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1408 | card->options.sbp.role = QETH_SBP_ROLE_NONE; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1409 | card->options.sbp.supported_funcs = 0; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1410 | return; |
| 1411 | } |
| 1412 | card->options.sbp.supported_funcs = cbctl.data.supported; |
| 1413 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1414 | |
| 1415 | static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, |
| 1416 | struct qeth_reply *reply, unsigned long data) |
| 1417 | { |
| 1418 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1419 | struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports; |
| 1420 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1421 | int rc; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1422 | |
| 1423 | QETH_CARD_TEXT(card, 2, "brqprtcb"); |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1424 | rc = qeth_bridgeport_makerc(card, cmd); |
| 1425 | if (rc) |
| 1426 | return rc; |
| 1427 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1428 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1429 | QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1430 | return -EINVAL; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1431 | } |
| 1432 | /* first entry contains the state of the local port */ |
| 1433 | if (qports->num_entries > 0) { |
| 1434 | if (cbctl->data.qports.role) |
| 1435 | *cbctl->data.qports.role = qports->entry[0].role; |
| 1436 | if (cbctl->data.qports.state) |
| 1437 | *cbctl->data.qports.state = qports->entry[0].state; |
| 1438 | } |
| 1439 | return 0; |
| 1440 | } |
| 1441 | |
| 1442 | /** |
| 1443 | * qeth_bridgeport_query_ports() - query local bridgeport status. |
| 1444 | * @card: qeth_card structure pointer. |
| 1445 | * @role: Role of the port: 0-none, 1-primary, 2-secondary. |
| 1446 | * @state: State of the port: 0-inactive, 1-standby, 2-active. |
| 1447 | * |
| 1448 | * Returns negative errno-compatible error indication or 0 on success. |
| 1449 | * |
| 1450 | * 'role' and 'state' are not updated in case of hardware operation failure. |
| 1451 | */ |
| 1452 | int qeth_bridgeport_query_ports(struct qeth_card *card, |
| 1453 | enum qeth_sbp_roles *role, enum qeth_sbp_states *state) |
| 1454 | { |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1455 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1456 | struct _qeth_sbp_cbctl cbctl = { |
| 1457 | .data = { |
| 1458 | .qports = { |
| 1459 | .role = role, |
| 1460 | .state = state, |
| 1461 | }, |
| 1462 | }, |
| 1463 | }; |
| 1464 | |
| 1465 | QETH_CARD_TEXT(card, 2, "brqports"); |
| 1466 | if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) |
| 1467 | return -EOPNOTSUPP; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1468 | iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1469 | if (!iob) |
| 1470 | return -ENOMEM; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1471 | |
| 1472 | return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, |
| 1473 | &cbctl); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1474 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1475 | |
| 1476 | static int qeth_bridgeport_set_cb(struct qeth_card *card, |
| 1477 | struct qeth_reply *reply, unsigned long data) |
| 1478 | { |
| 1479 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1480 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1481 | QETH_CARD_TEXT(card, 2, "brsetrcb"); |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1482 | return qeth_bridgeport_makerc(card, cmd); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * qeth_bridgeport_setrole() - Assign primary role to the port. |
| 1487 | * @card: qeth_card structure pointer. |
| 1488 | * @role: Role to assign. |
| 1489 | * |
| 1490 | * Returns negative errno-compatible error indication or 0 on success. |
| 1491 | */ |
| 1492 | int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) |
| 1493 | { |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1494 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1495 | enum qeth_ipa_sbp_cmd setcmd; |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1496 | unsigned int cmdlength = 0; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1497 | |
| 1498 | QETH_CARD_TEXT(card, 2, "brsetrol"); |
| 1499 | switch (role) { |
| 1500 | case QETH_SBP_ROLE_NONE: |
| 1501 | setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1502 | break; |
| 1503 | case QETH_SBP_ROLE_PRIMARY: |
| 1504 | setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1505 | cmdlength = SBP_DATA_SIZEOF(set_primary); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1506 | break; |
| 1507 | case QETH_SBP_ROLE_SECONDARY: |
| 1508 | setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1509 | break; |
| 1510 | default: |
| 1511 | return -EINVAL; |
| 1512 | } |
| 1513 | if (!(card->options.sbp.supported_funcs & setcmd)) |
| 1514 | return -EOPNOTSUPP; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1515 | iob = qeth_sbp_build_cmd(card, setcmd, cmdlength); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1516 | if (!iob) |
| 1517 | return -ENOMEM; |
Julian Wiedmann | 1709ff8 | 2019-02-12 18:33:24 +0100 | [diff] [blame] | 1518 | |
| 1519 | return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1520 | } |
| 1521 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1522 | static void qeth_bridgeport_an_set_cb(void *priv, |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1523 | struct chsc_pnso_naid_l2 *entry) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1524 | { |
| 1525 | struct qeth_card *card = (struct qeth_card *)priv; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1526 | u8 code; |
| 1527 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1528 | code = IPA_ADDR_CHANGE_CODE_MACADDR; |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1529 | if (entry->addr_lnid.lnid < VLAN_N_VID) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1530 | code |= IPA_ADDR_CHANGE_CODE_VLANID; |
| 1531 | qeth_bridge_emit_host_event(card, anev_reg_unreg, code, |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1532 | (struct net_if_token *)&entry->nit, |
| 1533 | (struct mac_addr_lnid *)&entry->addr_lnid); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification |
| 1538 | * @card: qeth_card structure pointer. |
| 1539 | * @enable: 0 - disable, non-zero - enable notifications |
| 1540 | * |
| 1541 | * Returns negative errno-compatible error indication or 0 on success. |
| 1542 | * |
| 1543 | * On enable, emits a series of address notifications udev events for all |
| 1544 | * currently registered hosts. |
| 1545 | */ |
| 1546 | int qeth_bridgeport_an_set(struct qeth_card *card, int enable) |
| 1547 | { |
| 1548 | int rc; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1549 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1550 | if (!card->options.sbp.supported_funcs) |
| 1551 | return -EOPNOTSUPP; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1552 | |
| 1553 | if (enable) { |
| 1554 | qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1555 | rc = qeth_l2_pnso(card, 1, qeth_bridgeport_an_set_cb, card); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1556 | } else |
Alexandra Winter | a0138f5 | 2020-04-16 15:08:41 +0200 | [diff] [blame] | 1557 | rc = qeth_l2_pnso(card, 0, NULL, NULL); |
| 1558 | return rc; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1559 | } |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1560 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1561 | static bool qeth_bridgeport_is_in_use(struct qeth_card *card) |
| 1562 | { |
| 1563 | return (card->options.sbp.role || card->options.sbp.reflect_promisc || |
| 1564 | card->options.sbp.hostnotification); |
| 1565 | } |
| 1566 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1567 | /* VNIC Characteristics support */ |
| 1568 | |
| 1569 | /* handle VNICC IPA command return codes; convert to error codes */ |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1570 | static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc) |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1571 | { |
| 1572 | int rc; |
| 1573 | |
| 1574 | switch (ipa_rc) { |
| 1575 | case IPA_RC_SUCCESS: |
| 1576 | return ipa_rc; |
| 1577 | case IPA_RC_L2_UNSUPPORTED_CMD: |
| 1578 | case IPA_RC_NOTSUPP: |
| 1579 | rc = -EOPNOTSUPP; |
| 1580 | break; |
| 1581 | case IPA_RC_VNICC_OOSEQ: |
| 1582 | rc = -EALREADY; |
| 1583 | break; |
| 1584 | case IPA_RC_VNICC_VNICBP: |
| 1585 | rc = -EBUSY; |
| 1586 | break; |
| 1587 | case IPA_RC_L2_ADDR_TABLE_FULL: |
| 1588 | rc = -ENOSPC; |
| 1589 | break; |
| 1590 | case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: |
| 1591 | rc = -EACCES; |
| 1592 | break; |
| 1593 | default: |
| 1594 | rc = -EIO; |
| 1595 | } |
| 1596 | |
| 1597 | QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc); |
| 1598 | return rc; |
| 1599 | } |
| 1600 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1601 | /* generic VNICC request call back */ |
| 1602 | static int qeth_l2_vnicc_request_cb(struct qeth_card *card, |
| 1603 | struct qeth_reply *reply, |
| 1604 | unsigned long data) |
| 1605 | { |
| 1606 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1607 | struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc; |
Julian Wiedmann | 2744d81 | 2019-08-20 16:46:40 +0200 | [diff] [blame] | 1608 | u32 sub_cmd = cmd->data.vnicc.hdr.sub_command; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1609 | |
| 1610 | QETH_CARD_TEXT(card, 2, "vniccrcb"); |
| 1611 | if (cmd->hdr.return_code) |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1612 | return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1613 | /* return results to caller */ |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1614 | card->options.vnicc.sup_chars = rep->vnicc_cmds.supported; |
| 1615 | card->options.vnicc.cur_chars = rep->vnicc_cmds.enabled; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1616 | |
Julian Wiedmann | 2744d81 | 2019-08-20 16:46:40 +0200 | [diff] [blame] | 1617 | if (sub_cmd == IPA_VNICC_QUERY_CMDS) |
Julian Wiedmann | 49f42f5 | 2020-03-06 09:13:11 +0100 | [diff] [blame] | 1618 | *(u32 *)reply->param = rep->data.query_cmds.sup_cmds; |
Julian Wiedmann | 2744d81 | 2019-08-20 16:46:40 +0200 | [diff] [blame] | 1619 | else if (sub_cmd == IPA_VNICC_GET_TIMEOUT) |
Julian Wiedmann | 49f42f5 | 2020-03-06 09:13:11 +0100 | [diff] [blame] | 1620 | *(u32 *)reply->param = rep->data.getset_timeout.timeout; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1621 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1622 | return 0; |
| 1623 | } |
| 1624 | |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1625 | static struct qeth_cmd_buffer *qeth_l2_vnicc_build_cmd(struct qeth_card *card, |
| 1626 | u32 vnicc_cmd, |
| 1627 | unsigned int data_length) |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1628 | { |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1629 | struct qeth_ipacmd_vnicc_hdr *hdr; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1630 | struct qeth_cmd_buffer *iob; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1631 | |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1632 | iob = qeth_ipa_alloc_cmd(card, IPA_CMD_VNICC, QETH_PROT_NONE, |
| 1633 | data_length + |
| 1634 | offsetof(struct qeth_ipacmd_vnicc, data)); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1635 | if (!iob) |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1636 | return NULL; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1637 | |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1638 | hdr = &__ipa_cmd(iob)->data.vnicc.hdr; |
| 1639 | hdr->data_length = sizeof(*hdr) + data_length; |
| 1640 | hdr->sub_command = vnicc_cmd; |
| 1641 | return iob; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1642 | } |
| 1643 | |
| 1644 | /* VNICC query VNIC characteristics request */ |
| 1645 | static int qeth_l2_vnicc_query_chars(struct qeth_card *card) |
| 1646 | { |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1647 | struct qeth_cmd_buffer *iob; |
| 1648 | |
| 1649 | QETH_CARD_TEXT(card, 2, "vniccqch"); |
| 1650 | iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CHARS, 0); |
| 1651 | if (!iob) |
| 1652 | return -ENOMEM; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1653 | |
Julian Wiedmann | 2744d81 | 2019-08-20 16:46:40 +0200 | [diff] [blame] | 1654 | return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1655 | } |
| 1656 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1657 | /* VNICC query sub commands request */ |
| 1658 | static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char, |
| 1659 | u32 *sup_cmds) |
| 1660 | { |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1661 | struct qeth_cmd_buffer *iob; |
| 1662 | |
| 1663 | QETH_CARD_TEXT(card, 2, "vniccqcm"); |
| 1664 | iob = qeth_l2_vnicc_build_cmd(card, IPA_VNICC_QUERY_CMDS, |
| 1665 | VNICC_DATA_SIZEOF(query_cmds)); |
| 1666 | if (!iob) |
| 1667 | return -ENOMEM; |
| 1668 | |
| 1669 | __ipa_cmd(iob)->data.vnicc.data.query_cmds.vnic_char = vnic_char; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1670 | |
Julian Wiedmann | 49f42f5 | 2020-03-06 09:13:11 +0100 | [diff] [blame] | 1671 | return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, sup_cmds); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | /* VNICC enable/disable characteristic request */ |
| 1675 | static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char, |
| 1676 | u32 cmd) |
| 1677 | { |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1678 | struct qeth_cmd_buffer *iob; |
| 1679 | |
| 1680 | QETH_CARD_TEXT(card, 2, "vniccedc"); |
| 1681 | iob = qeth_l2_vnicc_build_cmd(card, cmd, VNICC_DATA_SIZEOF(set_char)); |
| 1682 | if (!iob) |
| 1683 | return -ENOMEM; |
| 1684 | |
| 1685 | __ipa_cmd(iob)->data.vnicc.data.set_char.vnic_char = vnic_char; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1686 | |
Julian Wiedmann | 2744d81 | 2019-08-20 16:46:40 +0200 | [diff] [blame] | 1687 | return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, NULL); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1690 | /* VNICC get/set timeout for characteristic request */ |
| 1691 | static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc, |
| 1692 | u32 cmd, u32 *timeout) |
| 1693 | { |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1694 | struct qeth_vnicc_getset_timeout *getset_timeout; |
Julian Wiedmann | 2cfb481 | 2019-06-27 17:01:26 +0200 | [diff] [blame] | 1695 | struct qeth_cmd_buffer *iob; |
| 1696 | |
| 1697 | QETH_CARD_TEXT(card, 2, "vniccgst"); |
| 1698 | iob = qeth_l2_vnicc_build_cmd(card, cmd, |
| 1699 | VNICC_DATA_SIZEOF(getset_timeout)); |
| 1700 | if (!iob) |
| 1701 | return -ENOMEM; |
| 1702 | |
| 1703 | getset_timeout = &__ipa_cmd(iob)->data.vnicc.data.getset_timeout; |
| 1704 | getset_timeout->vnic_char = vnicc; |
| 1705 | |
| 1706 | if (cmd == IPA_VNICC_SET_TIMEOUT) |
| 1707 | getset_timeout->timeout = *timeout; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1708 | |
Julian Wiedmann | 49f42f5 | 2020-03-06 09:13:11 +0100 | [diff] [blame] | 1709 | return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, timeout); |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1710 | } |
| 1711 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1712 | /* set current VNICC flag state; called from sysfs store function */ |
| 1713 | int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state) |
| 1714 | { |
| 1715 | int rc = 0; |
| 1716 | u32 cmd; |
| 1717 | |
| 1718 | QETH_CARD_TEXT(card, 2, "vniccsch"); |
| 1719 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1720 | /* check if characteristic and enable/disable are supported */ |
| 1721 | if (!(card->options.vnicc.sup_chars & vnicc) || |
| 1722 | !(card->options.vnicc.set_char_sup & vnicc)) |
| 1723 | return -EOPNOTSUPP; |
| 1724 | |
Alexandra Winter | 6f3846f | 2020-02-20 15:54:54 +0100 | [diff] [blame] | 1725 | if (qeth_bridgeport_is_in_use(card)) |
| 1726 | return -EBUSY; |
| 1727 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1728 | /* set enable/disable command and store wanted characteristic */ |
| 1729 | if (state) { |
| 1730 | cmd = IPA_VNICC_ENABLE; |
| 1731 | card->options.vnicc.wanted_chars |= vnicc; |
| 1732 | } else { |
| 1733 | cmd = IPA_VNICC_DISABLE; |
| 1734 | card->options.vnicc.wanted_chars &= ~vnicc; |
| 1735 | } |
| 1736 | |
| 1737 | /* do we need to do anything? */ |
| 1738 | if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars) |
| 1739 | return rc; |
| 1740 | |
| 1741 | /* if card is not ready, simply stop here */ |
| 1742 | if (!qeth_card_hw_is_reachable(card)) { |
| 1743 | if (state) |
| 1744 | card->options.vnicc.cur_chars |= vnicc; |
| 1745 | else |
| 1746 | card->options.vnicc.cur_chars &= ~vnicc; |
| 1747 | return rc; |
| 1748 | } |
| 1749 | |
| 1750 | rc = qeth_l2_vnicc_set_char(card, vnicc, cmd); |
| 1751 | if (rc) |
| 1752 | card->options.vnicc.wanted_chars = |
| 1753 | card->options.vnicc.cur_chars; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1754 | else { |
| 1755 | /* successful online VNICC change; handle special cases */ |
| 1756 | if (state && vnicc == QETH_VNICC_RX_BCAST) |
| 1757 | card->options.vnicc.rx_bcast_enabled = true; |
| 1758 | if (!state && vnicc == QETH_VNICC_LEARNING) |
| 1759 | qeth_l2_vnicc_recover_timeout(card, vnicc, |
| 1760 | &card->options.vnicc.learning_timeout); |
| 1761 | } |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1762 | |
| 1763 | return rc; |
| 1764 | } |
| 1765 | |
| 1766 | /* get current VNICC flag state; called from sysfs show function */ |
| 1767 | int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state) |
| 1768 | { |
| 1769 | int rc = 0; |
| 1770 | |
| 1771 | QETH_CARD_TEXT(card, 2, "vniccgch"); |
| 1772 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1773 | /* check if characteristic is supported */ |
| 1774 | if (!(card->options.vnicc.sup_chars & vnicc)) |
| 1775 | return -EOPNOTSUPP; |
| 1776 | |
Alexandra Winter | 6f3846f | 2020-02-20 15:54:54 +0100 | [diff] [blame] | 1777 | if (qeth_bridgeport_is_in_use(card)) |
| 1778 | return -EBUSY; |
| 1779 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1780 | /* if card is ready, query current VNICC state */ |
| 1781 | if (qeth_card_hw_is_reachable(card)) |
| 1782 | rc = qeth_l2_vnicc_query_chars(card); |
| 1783 | |
| 1784 | *state = (card->options.vnicc.cur_chars & vnicc) ? true : false; |
| 1785 | return rc; |
| 1786 | } |
| 1787 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1788 | /* set VNICC timeout; called from sysfs store function. Currently, only learning |
| 1789 | * supports timeout |
| 1790 | */ |
| 1791 | int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout) |
| 1792 | { |
| 1793 | int rc = 0; |
| 1794 | |
| 1795 | QETH_CARD_TEXT(card, 2, "vniccsto"); |
| 1796 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1797 | /* check if characteristic and set_timeout are supported */ |
| 1798 | if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || |
| 1799 | !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) |
| 1800 | return -EOPNOTSUPP; |
| 1801 | |
Alexandra Winter | 6f3846f | 2020-02-20 15:54:54 +0100 | [diff] [blame] | 1802 | if (qeth_bridgeport_is_in_use(card)) |
| 1803 | return -EBUSY; |
| 1804 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1805 | /* do we need to do anything? */ |
| 1806 | if (card->options.vnicc.learning_timeout == timeout) |
| 1807 | return rc; |
| 1808 | |
| 1809 | /* if card is not ready, simply store the value internally and return */ |
| 1810 | if (!qeth_card_hw_is_reachable(card)) { |
| 1811 | card->options.vnicc.learning_timeout = timeout; |
| 1812 | return rc; |
| 1813 | } |
| 1814 | |
| 1815 | /* send timeout value to card; if successful, store value internally */ |
| 1816 | rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, |
| 1817 | IPA_VNICC_SET_TIMEOUT, &timeout); |
| 1818 | if (!rc) |
| 1819 | card->options.vnicc.learning_timeout = timeout; |
| 1820 | |
| 1821 | return rc; |
| 1822 | } |
| 1823 | |
| 1824 | /* get current VNICC timeout; called from sysfs show function. Currently, only |
| 1825 | * learning supports timeout |
| 1826 | */ |
| 1827 | int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout) |
| 1828 | { |
| 1829 | int rc = 0; |
| 1830 | |
| 1831 | QETH_CARD_TEXT(card, 2, "vniccgto"); |
| 1832 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1833 | /* check if characteristic and get_timeout are supported */ |
| 1834 | if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || |
| 1835 | !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) |
| 1836 | return -EOPNOTSUPP; |
Alexandra Winter | 6f3846f | 2020-02-20 15:54:54 +0100 | [diff] [blame] | 1837 | |
| 1838 | if (qeth_bridgeport_is_in_use(card)) |
| 1839 | return -EBUSY; |
| 1840 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1841 | /* if card is ready, get timeout. Otherwise, just return stored value */ |
| 1842 | *timeout = card->options.vnicc.learning_timeout; |
| 1843 | if (qeth_card_hw_is_reachable(card)) |
| 1844 | rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, |
| 1845 | IPA_VNICC_GET_TIMEOUT, |
| 1846 | timeout); |
| 1847 | |
| 1848 | return rc; |
| 1849 | } |
| 1850 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1851 | /* check if VNICC is currently enabled */ |
| 1852 | bool qeth_l2_vnicc_is_in_use(struct qeth_card *card) |
| 1853 | { |
Alexandra Winter | e8a66d8 | 2019-12-23 15:03:24 +0100 | [diff] [blame] | 1854 | if (!card->options.vnicc.sup_chars) |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1855 | return false; |
| 1856 | /* default values are only OK if rx_bcast was not enabled by user |
| 1857 | * or the card is offline. |
| 1858 | */ |
| 1859 | if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) { |
| 1860 | if (!card->options.vnicc.rx_bcast_enabled || |
| 1861 | !qeth_card_hw_is_reachable(card)) |
| 1862 | return false; |
| 1863 | } |
| 1864 | return true; |
| 1865 | } |
| 1866 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1867 | /* recover user timeout setting */ |
| 1868 | static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, |
| 1869 | u32 *timeout) |
| 1870 | { |
| 1871 | if (card->options.vnicc.sup_chars & vnicc && |
| 1872 | card->options.vnicc.getset_timeout_sup & vnicc && |
| 1873 | !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT, |
| 1874 | timeout)) |
| 1875 | return false; |
| 1876 | *timeout = QETH_VNICC_DEFAULT_TIMEOUT; |
| 1877 | return true; |
| 1878 | } |
| 1879 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1880 | /* recover user characteristic setting */ |
| 1881 | static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc, |
| 1882 | bool enable) |
| 1883 | { |
| 1884 | u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE; |
| 1885 | |
| 1886 | if (card->options.vnicc.sup_chars & vnicc && |
| 1887 | card->options.vnicc.set_char_sup & vnicc && |
| 1888 | !qeth_l2_vnicc_set_char(card, vnicc, cmd)) |
| 1889 | return false; |
| 1890 | card->options.vnicc.wanted_chars &= ~vnicc; |
| 1891 | card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc; |
| 1892 | return true; |
| 1893 | } |
| 1894 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1895 | /* (re-)initialize VNICC */ |
| 1896 | static void qeth_l2_vnicc_init(struct qeth_card *card) |
| 1897 | { |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1898 | u32 *timeout = &card->options.vnicc.learning_timeout; |
Alexandra Winter | b528965 | 2019-10-08 18:21:06 +0200 | [diff] [blame] | 1899 | bool enable, error = false; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1900 | unsigned int chars_len, i; |
| 1901 | unsigned long chars_tmp; |
| 1902 | u32 sup_cmds, vnicc; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1903 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1904 | QETH_CARD_TEXT(card, 2, "vniccini"); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1905 | /* reset rx_bcast */ |
| 1906 | card->options.vnicc.rx_bcast_enabled = 0; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1907 | /* initial query and storage of VNIC characteristics */ |
| 1908 | if (qeth_l2_vnicc_query_chars(card)) { |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1909 | if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT || |
| 1910 | *timeout != QETH_VNICC_DEFAULT_TIMEOUT) |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1911 | dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); |
| 1912 | /* fail quietly if user didn't change the default config */ |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1913 | card->options.vnicc.sup_chars = 0; |
| 1914 | card->options.vnicc.cur_chars = 0; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1915 | card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; |
| 1916 | return; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1917 | } |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1918 | /* get supported commands for each supported characteristic */ |
| 1919 | chars_tmp = card->options.vnicc.sup_chars; |
| 1920 | chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE; |
| 1921 | for_each_set_bit(i, &chars_tmp, chars_len) { |
| 1922 | vnicc = BIT(i); |
Alexandra Winter | b528965 | 2019-10-08 18:21:06 +0200 | [diff] [blame] | 1923 | if (qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds)) { |
| 1924 | sup_cmds = 0; |
| 1925 | error = true; |
| 1926 | } |
Alexandra Winter | be40a86 | 2019-10-08 18:21:07 +0200 | [diff] [blame] | 1927 | if ((sup_cmds & IPA_VNICC_SET_TIMEOUT) && |
| 1928 | (sup_cmds & IPA_VNICC_GET_TIMEOUT)) |
| 1929 | card->options.vnicc.getset_timeout_sup |= vnicc; |
| 1930 | else |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1931 | card->options.vnicc.getset_timeout_sup &= ~vnicc; |
Alexandra Winter | be40a86 | 2019-10-08 18:21:07 +0200 | [diff] [blame] | 1932 | if ((sup_cmds & IPA_VNICC_ENABLE) && |
| 1933 | (sup_cmds & IPA_VNICC_DISABLE)) |
| 1934 | card->options.vnicc.set_char_sup |= vnicc; |
| 1935 | else |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1936 | card->options.vnicc.set_char_sup &= ~vnicc; |
| 1937 | } |
| 1938 | /* enforce assumed default values and recover settings, if changed */ |
Alexandra Winter | b528965 | 2019-10-08 18:21:06 +0200 | [diff] [blame] | 1939 | error |= qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING, |
| 1940 | timeout); |
Alexandra Winter | d1b9ae1 | 2019-12-23 15:03:25 +0100 | [diff] [blame] | 1941 | /* Change chars, if necessary */ |
| 1942 | chars_tmp = card->options.vnicc.wanted_chars ^ |
| 1943 | card->options.vnicc.cur_chars; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1944 | chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE; |
| 1945 | for_each_set_bit(i, &chars_tmp, chars_len) { |
| 1946 | vnicc = BIT(i); |
| 1947 | enable = card->options.vnicc.wanted_chars & vnicc; |
| 1948 | error |= qeth_l2_vnicc_recover_char(card, vnicc, enable); |
| 1949 | } |
| 1950 | if (error) |
| 1951 | dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); |
| 1952 | } |
| 1953 | |
| 1954 | /* configure default values of VNIC characteristics */ |
| 1955 | static void qeth_l2_vnicc_set_defaults(struct qeth_card *card) |
| 1956 | { |
| 1957 | /* characteristics values */ |
| 1958 | card->options.vnicc.sup_chars = QETH_VNICC_ALL; |
| 1959 | card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1960 | card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1961 | /* supported commands */ |
| 1962 | card->options.vnicc.set_char_sup = QETH_VNICC_ALL; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 1963 | card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 1964 | /* settings wanted by users */ |
| 1965 | card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1966 | } |
| 1967 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1968 | module_init(qeth_l2_init); |
| 1969 | module_exit(qeth_l2_exit); |
| 1970 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 1971 | MODULE_DESCRIPTION("qeth layer 2 discipline"); |
| 1972 | MODULE_LICENSE("GPL"); |