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