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> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 20 | #include <linux/ip.h> |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 21 | #include <linux/list.h> |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 22 | #include <linux/hash.h> |
| 23 | #include <linux/hashtable.h> |
| 24 | #include <linux/string.h> |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 25 | #include <asm/setup.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 26 | #include "qeth_core.h" |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 27 | #include "qeth_l2.h" |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 28 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 29 | static int qeth_l2_set_offline(struct ccwgroup_device *); |
| 30 | static int qeth_l2_stop(struct net_device *); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 31 | static void qeth_l2_set_rx_mode(struct net_device *); |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 32 | static void qeth_bridgeport_query_support(struct qeth_card *card); |
| 33 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 34 | struct qeth_ipa_cmd *cmd); |
| 35 | static void qeth_bridge_host_event(struct qeth_card *card, |
| 36 | struct qeth_ipa_cmd *cmd); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 37 | static void qeth_l2_vnicc_set_defaults(struct qeth_card *card); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 38 | static void qeth_l2_vnicc_init(struct qeth_card *card); |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 39 | static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, |
| 40 | u32 *timeout); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 41 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 42 | static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no) |
| 43 | { |
| 44 | struct qeth_card *card; |
| 45 | struct net_device *ndev; |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 46 | __u16 temp_dev_no; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 47 | unsigned long flags; |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 48 | struct ccw_dev_id read_devid; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 49 | |
| 50 | ndev = NULL; |
| 51 | memcpy(&temp_dev_no, read_dev_no, 2); |
| 52 | read_lock_irqsave(&qeth_core_card_list.rwlock, flags); |
| 53 | list_for_each_entry(card, &qeth_core_card_list.list, list) { |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 54 | ccw_device_get_id(CARD_RDEV(card), &read_devid); |
| 55 | if (read_devid.devno == temp_dev_no) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 56 | ndev = card->dev; |
| 57 | break; |
| 58 | } |
| 59 | } |
| 60 | read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); |
| 61 | return ndev; |
| 62 | } |
| 63 | |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 64 | static int qeth_setdelmac_makerc(struct qeth_card *card, int retcode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 65 | { |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 66 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 67 | |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 68 | if (retcode) |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 69 | QETH_CARD_TEXT_(card, 2, "err%04x", retcode); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 70 | switch (retcode) { |
| 71 | case IPA_RC_SUCCESS: |
| 72 | rc = 0; |
| 73 | break; |
| 74 | case IPA_RC_L2_UNSUPPORTED_CMD: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 75 | rc = -EOPNOTSUPP; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 76 | break; |
| 77 | case IPA_RC_L2_ADDR_TABLE_FULL: |
| 78 | rc = -ENOSPC; |
| 79 | break; |
| 80 | case IPA_RC_L2_DUP_MAC: |
| 81 | case IPA_RC_L2_DUP_LAYER3_MAC: |
| 82 | rc = -EEXIST; |
| 83 | break; |
| 84 | case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: |
| 85 | case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: |
| 86 | rc = -EPERM; |
| 87 | break; |
| 88 | case IPA_RC_L2_MAC_NOT_FOUND: |
| 89 | rc = -ENOENT; |
| 90 | break; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 91 | case -ENOMEM: |
| 92 | rc = -ENOMEM; |
| 93 | break; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 94 | default: |
| 95 | rc = -EIO; |
| 96 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 97 | } |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 98 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 99 | } |
| 100 | |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 101 | static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, |
| 102 | enum qeth_ipa_cmds ipacmd) |
| 103 | { |
| 104 | struct qeth_ipa_cmd *cmd; |
| 105 | struct qeth_cmd_buffer *iob; |
| 106 | |
| 107 | QETH_CARD_TEXT(card, 2, "L2sdmac"); |
| 108 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 109 | if (!iob) |
| 110 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 111 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 112 | cmd->data.setdelmac.mac_length = ETH_ALEN; |
| 113 | ether_addr_copy(cmd->data.setdelmac.mac, mac); |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 114 | return qeth_setdelmac_makerc(card, qeth_send_ipa_cmd(card, iob, |
| 115 | NULL, NULL)); |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) |
| 119 | { |
| 120 | int rc; |
| 121 | |
| 122 | QETH_CARD_TEXT(card, 2, "L2Setmac"); |
| 123 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); |
| 124 | if (rc == 0) { |
| 125 | card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 126 | ether_addr_copy(card->dev->dev_addr, mac); |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 127 | dev_info(&card->gdev->dev, |
| 128 | "MAC address %pM successfully registered on device %s\n", |
| 129 | card->dev->dev_addr, card->dev->name); |
| 130 | } else { |
| 131 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
| 132 | switch (rc) { |
| 133 | case -EEXIST: |
| 134 | dev_warn(&card->gdev->dev, |
| 135 | "MAC address %pM already exists\n", mac); |
| 136 | break; |
| 137 | case -EPERM: |
| 138 | dev_warn(&card->gdev->dev, |
| 139 | "MAC address %pM is not authorized\n", mac); |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | return rc; |
| 144 | } |
| 145 | |
| 146 | static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac) |
| 147 | { |
| 148 | int rc; |
| 149 | |
| 150 | QETH_CARD_TEXT(card, 2, "L2Delmac"); |
| 151 | if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) |
| 152 | return 0; |
| 153 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC); |
| 154 | if (rc == 0) |
| 155 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
| 156 | return rc; |
| 157 | } |
| 158 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 159 | static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 160 | { |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 161 | enum qeth_ipa_cmds cmd = is_multicast_ether_addr_64bits(mac) ? |
| 162 | IPA_CMD_SETGMAC : IPA_CMD_SETVMAC; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 163 | int rc; |
| 164 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 165 | QETH_CARD_TEXT(card, 2, "L2Wmac"); |
| 166 | rc = qeth_l2_send_setdelmac(card, mac, cmd); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 167 | if (rc == -EEXIST) |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 168 | QETH_DBF_MESSAGE(2, "MAC %pM already registered on %s\n", |
| 169 | mac, QETH_CARD_IFNAME(card)); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 170 | else if (rc) |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 171 | QETH_DBF_MESSAGE(2, "Failed to register MAC %pM on %s: %d\n", |
| 172 | mac, QETH_CARD_IFNAME(card), rc); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 173 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 176 | static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 177 | { |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 178 | enum qeth_ipa_cmds cmd = is_multicast_ether_addr_64bits(mac) ? |
| 179 | IPA_CMD_DELGMAC : IPA_CMD_DELVMAC; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 180 | int rc; |
| 181 | |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 182 | QETH_CARD_TEXT(card, 2, "L2Rmac"); |
| 183 | rc = qeth_l2_send_setdelmac(card, mac, cmd); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 184 | if (rc) |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 185 | QETH_DBF_MESSAGE(2, "Failed to delete MAC %pM on %s: %d\n", |
| 186 | mac, QETH_CARD_IFNAME(card), rc); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 187 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 188 | } |
| 189 | |
Julian Wiedmann | c07cbf2 | 2017-01-12 15:48:37 +0100 | [diff] [blame] | 190 | static void qeth_l2_del_all_macs(struct qeth_card *card) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 191 | { |
| 192 | struct qeth_mac *mac; |
| 193 | struct hlist_node *tmp; |
| 194 | int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 195 | |
| 196 | spin_lock_bh(&card->mclock); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 197 | hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 198 | hash_del(&mac->hnode); |
| 199 | kfree(mac); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 200 | } |
| 201 | spin_unlock_bh(&card->mclock); |
| 202 | } |
| 203 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 204 | static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 205 | { |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 206 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 207 | return RTN_UNSPEC; |
| 208 | if (is_broadcast_ether_addr(skb->data)) |
| 209 | return RTN_BROADCAST; |
| 210 | if (is_multicast_ether_addr(skb->data)) |
| 211 | return RTN_MULTICAST; |
| 212 | return RTN_UNSPEC; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 215 | static void qeth_l2_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr, |
| 216 | struct sk_buff *skb) |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 217 | { |
| 218 | struct iphdr *iph = ip_hdr(skb); |
| 219 | |
| 220 | /* tcph->check contains already the pseudo hdr checksum |
| 221 | * so just set the header flags |
| 222 | */ |
| 223 | if (iph->protocol == IPPROTO_UDP) |
| 224 | hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP; |
| 225 | hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ | |
| 226 | QETH_HDR_EXT_CSUM_HDR_REQ; |
| 227 | iph->check = 0; |
| 228 | if (card->options.performance_stats) |
| 229 | card->perf_stats.tx_csum++; |
| 230 | } |
| 231 | |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 232 | static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb, |
| 233 | int cast_type, unsigned int data_len) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 234 | { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 235 | struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 236 | |
| 237 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 238 | hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 239 | hdr->hdr.l2.pkt_length = data_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 240 | |
| 241 | /* set byte byte 3 to casting flags */ |
| 242 | if (cast_type == RTN_MULTICAST) |
| 243 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; |
| 244 | else if (cast_type == RTN_BROADCAST) |
| 245 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; |
| 246 | else |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 247 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 248 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 249 | /* VSWITCH relies on the VLAN |
| 250 | * information to be present in |
| 251 | * the QDIO header */ |
| 252 | if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { |
| 253 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; |
| 254 | hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); |
| 255 | } |
| 256 | } |
| 257 | |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 258 | static int qeth_setdelvlan_makerc(struct qeth_card *card, int retcode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 259 | { |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 260 | if (retcode) |
| 261 | QETH_CARD_TEXT_(card, 2, "err%04x", retcode); |
| 262 | |
| 263 | switch (retcode) { |
| 264 | case IPA_RC_SUCCESS: |
| 265 | return 0; |
| 266 | case IPA_RC_L2_INVALID_VLAN_ID: |
| 267 | return -EINVAL; |
| 268 | case IPA_RC_L2_DUP_VLAN_ID: |
| 269 | return -EEXIST; |
| 270 | case IPA_RC_L2_VLAN_ID_NOT_FOUND: |
| 271 | return -ENOENT; |
| 272 | case IPA_RC_L2_VLAN_ID_NOT_ALLOWED: |
| 273 | return -EPERM; |
| 274 | case -ENOMEM: |
| 275 | return -ENOMEM; |
| 276 | default: |
| 277 | return -EIO; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, |
| 282 | struct qeth_reply *reply, |
| 283 | unsigned long data) |
| 284 | { |
| 285 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 286 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 287 | QETH_CARD_TEXT(card, 2, "L2sdvcb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 288 | if (cmd->hdr.return_code) { |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 289 | QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x.\n", |
| 290 | cmd->data.setdelvlan.vlan_id, |
| 291 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 292 | QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); |
| 293 | QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 294 | } |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 299 | enum qeth_ipa_cmds ipacmd) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 300 | { |
| 301 | struct qeth_ipa_cmd *cmd; |
| 302 | struct qeth_cmd_buffer *iob; |
| 303 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 304 | QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 305 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 306 | if (!iob) |
| 307 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 308 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 309 | cmd->data.setdelvlan.vlan_id = i; |
Julian Wiedmann | 2aa4867 | 2017-09-18 21:18:20 +0200 | [diff] [blame] | 310 | return qeth_setdelvlan_makerc(card, qeth_send_ipa_cmd(card, iob, |
| 311 | qeth_l2_send_setdelvlan_cb, NULL)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 312 | } |
| 313 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 314 | static void qeth_l2_process_vlans(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 315 | { |
| 316 | struct qeth_vlan_vid *id; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 317 | QETH_CARD_TEXT(card, 3, "L2prcvln"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 318 | spin_lock_bh(&card->vlanlock); |
| 319 | list_for_each_entry(id, &card->vid_list, list) { |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 320 | qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 321 | } |
| 322 | spin_unlock_bh(&card->vlanlock); |
| 323 | } |
| 324 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 325 | static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, |
| 326 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 327 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 328 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 329 | struct qeth_vlan_vid *id; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 330 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 331 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 332 | QETH_CARD_TEXT_(card, 4, "aid:%d", vid); |
Ursula Braun | 10651db | 2010-10-01 02:51:13 +0000 | [diff] [blame] | 333 | if (!vid) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 334 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 335 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 336 | QETH_CARD_TEXT(card, 3, "aidREC"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 337 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 338 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 339 | id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC); |
| 340 | if (id) { |
| 341 | id->vid = vid; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 342 | rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); |
| 343 | if (rc) { |
| 344 | kfree(id); |
| 345 | return rc; |
| 346 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 347 | spin_lock_bh(&card->vlanlock); |
| 348 | list_add_tail(&id->list, &card->vid_list); |
| 349 | spin_unlock_bh(&card->vlanlock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 350 | } else { |
| 351 | return -ENOMEM; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 352 | } |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 353 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 356 | static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, |
| 357 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 358 | { |
| 359 | struct qeth_vlan_vid *id, *tmpid = NULL; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 360 | struct qeth_card *card = dev->ml_priv; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 361 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 362 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 363 | QETH_CARD_TEXT_(card, 4, "kid:%d", vid); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 364 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 365 | QETH_CARD_TEXT(card, 3, "kidREC"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 366 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 367 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 368 | spin_lock_bh(&card->vlanlock); |
| 369 | list_for_each_entry(id, &card->vid_list, list) { |
| 370 | if (id->vid == vid) { |
| 371 | list_del(&id->list); |
| 372 | tmpid = id; |
| 373 | break; |
| 374 | } |
| 375 | } |
| 376 | spin_unlock_bh(&card->vlanlock); |
| 377 | if (tmpid) { |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 378 | rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 379 | kfree(tmpid); |
| 380 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 381 | qeth_l2_set_rx_mode(card->dev); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 382 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Peter Senna Tschudin | b2f4de8 | 2015-08-04 17:11:47 +0200 | [diff] [blame] | 385 | static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 386 | { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 387 | QETH_DBF_TEXT(SETUP , 2, "stopcard"); |
| 388 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 389 | |
| 390 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 391 | if (card->read.state == CH_STATE_UP && |
| 392 | card->write.state == CH_STATE_UP && |
| 393 | (card->state == CARD_STATE_UP)) { |
| 394 | if (recovery_mode && |
| 395 | card->info.type != QETH_CARD_TYPE_OSN) { |
| 396 | qeth_l2_stop(card->dev); |
| 397 | } else { |
| 398 | rtnl_lock(); |
| 399 | dev_close(card->dev); |
| 400 | rtnl_unlock(); |
| 401 | } |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 402 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 403 | card->state = CARD_STATE_SOFTSETUP; |
| 404 | } |
| 405 | if (card->state == CARD_STATE_SOFTSETUP) { |
Julian Wiedmann | c07cbf2 | 2017-01-12 15:48:37 +0100 | [diff] [blame] | 406 | qeth_l2_del_all_macs(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 407 | qeth_clear_ipacmd_list(card); |
| 408 | card->state = CARD_STATE_HARDSETUP; |
| 409 | } |
| 410 | if (card->state == CARD_STATE_HARDSETUP) { |
| 411 | qeth_qdio_clear_card(card, 0); |
| 412 | qeth_clear_qdio_buffers(card); |
| 413 | qeth_clear_working_pool_list(card); |
| 414 | card->state = CARD_STATE_DOWN; |
| 415 | } |
| 416 | if (card->state == CARD_STATE_DOWN) { |
| 417 | qeth_clear_cmd_buffers(&card->read); |
| 418 | qeth_clear_cmd_buffers(&card->write); |
| 419 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 422 | static int qeth_l2_process_inbound_buffer(struct qeth_card *card, |
| 423 | int budget, int *done) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 424 | { |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 425 | int work_done = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 426 | struct sk_buff *skb; |
| 427 | struct qeth_hdr *hdr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 428 | unsigned int len; |
| 429 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 430 | *done = 0; |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 431 | WARN_ON_ONCE(!budget); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 432 | while (budget) { |
| 433 | skb = qeth_core_get_next_skb(card, |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 434 | &card->qdio.in_q->bufs[card->rx.b_index], |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 435 | &card->rx.b_element, &card->rx.e_offset, &hdr); |
| 436 | if (!skb) { |
| 437 | *done = 1; |
| 438 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 439 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 440 | switch (hdr->hdr.l2.id) { |
| 441 | case QETH_HEADER_TYPE_LAYER2: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 442 | skb->protocol = eth_type_trans(skb, skb->dev); |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 443 | if ((card->dev->features & NETIF_F_RXCSUM) |
| 444 | && ((hdr->hdr.l2.flags[1] & |
| 445 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 446 | QETH_HDR_EXT_CSUM_TRANSP_REQ)) == |
| 447 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 448 | QETH_HDR_EXT_CSUM_TRANSP_REQ))) |
| 449 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 450 | else |
| 451 | skb->ip_summed = CHECKSUM_NONE; |
Ursula Braun | 1288372 | 2008-04-01 10:26:56 +0200 | [diff] [blame] | 452 | if (skb->protocol == htons(ETH_P_802_2)) |
| 453 | *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 454 | len = skb->len; |
Thomas Richter | 9abfa8cb | 2015-10-06 15:12:27 +0200 | [diff] [blame] | 455 | napi_gro_receive(&card->napi, skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 456 | break; |
| 457 | case QETH_HEADER_TYPE_OSN: |
Ursula Braun | 2d488c2 | 2008-10-24 11:16:55 +0200 | [diff] [blame] | 458 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 459 | skb_push(skb, sizeof(struct qeth_hdr)); |
| 460 | skb_copy_to_linear_data(skb, hdr, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 461 | sizeof(struct qeth_hdr)); |
Ursula Braun | 2d488c2 | 2008-10-24 11:16:55 +0200 | [diff] [blame] | 462 | len = skb->len; |
| 463 | card->osn_info.data_cb(skb); |
| 464 | break; |
| 465 | } |
| 466 | /* else unknown */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 467 | default: |
| 468 | dev_kfree_skb_any(skb); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 469 | QETH_CARD_TEXT(card, 3, "inbunkno"); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 470 | QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 471 | continue; |
| 472 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 473 | work_done++; |
| 474 | budget--; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 475 | card->stats.rx_packets++; |
| 476 | card->stats.rx_bytes += len; |
| 477 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 478 | return work_done; |
| 479 | } |
| 480 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 481 | static int qeth_l2_request_initial_mac(struct qeth_card *card) |
| 482 | { |
| 483 | int rc = 0; |
| 484 | char vendor_pre[] = {0x02, 0x00, 0x00}; |
| 485 | |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 486 | QETH_DBF_TEXT(SETUP, 2, "l2reqmac"); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 487 | QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 488 | |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 489 | if (MACHINE_IS_VM) { |
| 490 | rc = qeth_vm_request_mac(card); |
| 491 | if (!rc) |
| 492 | goto out; |
| 493 | QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n", |
| 494 | CARD_BUS_ID(card), rc); |
| 495 | QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc); |
| 496 | /* fall back to alternative mechanism: */ |
| 497 | } |
| 498 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 499 | if (card->info.type == QETH_CARD_TYPE_IQD || |
| 500 | card->info.type == QETH_CARD_TYPE_OSM || |
| 501 | card->info.type == QETH_CARD_TYPE_OSX || |
| 502 | card->info.guestlan) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 503 | rc = qeth_setadpparms_change_macaddr(card); |
| 504 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 505 | QETH_DBF_MESSAGE(2, "couldn't get MAC address on " |
| 506 | "device %s: x%x\n", CARD_BUS_ID(card), rc); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 507 | QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 508 | return rc; |
| 509 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 510 | } else { |
Joe Perches | 1833611 | 2012-07-12 22:33:10 -0700 | [diff] [blame] | 511 | eth_random_addr(card->dev->dev_addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 512 | memcpy(card->dev->dev_addr, vendor_pre, 3); |
| 513 | } |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 514 | out: |
| 515 | 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] | 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | static int qeth_l2_set_mac_address(struct net_device *dev, void *p) |
| 520 | { |
| 521 | struct sockaddr *addr = p; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 522 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 523 | int rc = 0; |
| 524 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 525 | QETH_CARD_TEXT(card, 3, "setmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 526 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 527 | if (card->info.type == QETH_CARD_TYPE_OSN || |
| 528 | card->info.type == QETH_CARD_TYPE_OSM || |
| 529 | card->info.type == QETH_CARD_TYPE_OSX) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 530 | QETH_CARD_TEXT(card, 3, "setmcTYP"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 531 | return -EOPNOTSUPP; |
| 532 | } |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 533 | QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 534 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 535 | QETH_CARD_TEXT(card, 3, "setmcREC"); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 536 | return -ERESTARTSYS; |
| 537 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 538 | rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 539 | if (!rc || (rc == -ENOENT)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 540 | rc = qeth_l2_send_setmac(card, addr->sa_data); |
Ursula Braun | e0a8114 | 2012-03-07 02:06:28 +0000 | [diff] [blame] | 541 | return rc ? -EINVAL : 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 544 | static void qeth_promisc_to_bridge(struct qeth_card *card) |
| 545 | { |
| 546 | struct net_device *dev = card->dev; |
| 547 | enum qeth_ipa_promisc_modes promisc_mode; |
| 548 | int role; |
| 549 | int rc; |
| 550 | |
| 551 | QETH_CARD_TEXT(card, 3, "pmisc2br"); |
| 552 | |
| 553 | if (!card->options.sbp.reflect_promisc) |
| 554 | return; |
| 555 | promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON |
| 556 | : SET_PROMISC_MODE_OFF; |
| 557 | if (promisc_mode == card->info.promisc_mode) |
| 558 | return; |
| 559 | |
| 560 | if (promisc_mode == SET_PROMISC_MODE_ON) { |
| 561 | if (card->options.sbp.reflect_promisc_primary) |
| 562 | role = QETH_SBP_ROLE_PRIMARY; |
| 563 | else |
| 564 | role = QETH_SBP_ROLE_SECONDARY; |
| 565 | } else |
| 566 | role = QETH_SBP_ROLE_NONE; |
| 567 | |
| 568 | rc = qeth_bridgeport_setrole(card, role); |
| 569 | QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x", |
| 570 | (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc); |
| 571 | if (!rc) { |
| 572 | card->options.sbp.role = role; |
| 573 | card->info.promisc_mode = promisc_mode; |
| 574 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 575 | |
| 576 | } |
| 577 | /* New MAC address is added to the hash table and marked to be written on card |
| 578 | * only if there is not in the hash table storage already |
| 579 | * |
| 580 | */ |
Julian Wiedmann | 4641b02 | 2017-12-20 20:10:59 +0100 | [diff] [blame] | 581 | 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] | 582 | { |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 583 | u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2])); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 584 | struct qeth_mac *mac; |
| 585 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 586 | hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) { |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 587 | if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 588 | mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 589 | return; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 594 | if (!mac) |
| 595 | return; |
| 596 | |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 597 | ether_addr_copy(mac->mac_addr, ha->addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 598 | mac->disp_flag = QETH_DISP_ADDR_ADD; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 599 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame] | 600 | hash_add(card->mac_htable, &mac->hnode, mac_hash); |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 601 | } |
| 602 | |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 603 | static void qeth_l2_set_rx_mode(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 604 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 605 | struct qeth_card *card = dev->ml_priv; |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 606 | struct netdev_hw_addr *ha; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 607 | struct qeth_mac *mac; |
| 608 | struct hlist_node *tmp; |
| 609 | int i; |
| 610 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 611 | |
| 612 | if (card->info.type == QETH_CARD_TYPE_OSN) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 613 | return; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 614 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 615 | QETH_CARD_TEXT(card, 3, "setmulti"); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 616 | if (qeth_threads_running(card, QETH_RECOVER_THREAD) && |
| 617 | (card->state != CARD_STATE_UP)) |
| 618 | return; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 619 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 620 | spin_lock_bh(&card->mclock); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 621 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 622 | netdev_for_each_mc_addr(ha, dev) |
Julian Wiedmann | 4641b02 | 2017-12-20 20:10:59 +0100 | [diff] [blame] | 623 | qeth_l2_add_mac(card, ha); |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 624 | netdev_for_each_uc_addr(ha, dev) |
Julian Wiedmann | 4641b02 | 2017-12-20 20:10:59 +0100 | [diff] [blame] | 625 | qeth_l2_add_mac(card, ha); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 626 | |
| 627 | hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 628 | switch (mac->disp_flag) { |
| 629 | case QETH_DISP_ADDR_DELETE: |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 630 | qeth_l2_remove_mac(card, mac->mac_addr); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 631 | hash_del(&mac->hnode); |
| 632 | kfree(mac); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 633 | break; |
| 634 | case QETH_DISP_ADDR_ADD: |
Julian Wiedmann | 8174aa8 | 2017-12-20 20:11:00 +0100 | [diff] [blame] | 635 | rc = qeth_l2_write_mac(card, mac->mac_addr); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 636 | if (rc) { |
| 637 | hash_del(&mac->hnode); |
| 638 | kfree(mac); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 639 | break; |
| 640 | } |
| 641 | /* fall through */ |
| 642 | default: |
| 643 | /* for next call to set_rx_mode(): */ |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 644 | mac->disp_flag = QETH_DISP_ADDR_DELETE; |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 645 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 646 | } |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 647 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 648 | spin_unlock_bh(&card->mclock); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 649 | |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 650 | if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 651 | qeth_setadp_promisc_mode(card); |
| 652 | else |
| 653 | qeth_promisc_to_bridge(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 656 | static int qeth_l2_xmit_iqd(struct qeth_card *card, struct sk_buff *skb, |
| 657 | struct qeth_qdio_out_q *queue, int cast_type) |
| 658 | { |
| 659 | unsigned int data_offset = ETH_HLEN; |
| 660 | struct qeth_hdr *hdr; |
| 661 | int rc; |
| 662 | |
| 663 | hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC); |
| 664 | if (!hdr) |
| 665 | return -ENOMEM; |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 666 | qeth_l2_fill_header(hdr, skb, cast_type, skb->len); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 667 | skb_copy_from_linear_data(skb, ((char *)hdr) + sizeof(*hdr), |
| 668 | data_offset); |
| 669 | |
| 670 | if (!qeth_get_elements_no(card, skb, 1, data_offset)) { |
| 671 | rc = -E2BIG; |
| 672 | goto out; |
| 673 | } |
Julian Wiedmann | 7c2e9ba | 2017-09-18 21:18:18 +0200 | [diff] [blame] | 674 | rc = qeth_do_send_packet_fast(queue, skb, hdr, data_offset, |
Julian Wiedmann | f158817 | 2017-08-18 10:19:08 +0200 | [diff] [blame] | 675 | sizeof(*hdr) + data_offset); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 676 | out: |
| 677 | if (rc) |
| 678 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 679 | return rc; |
| 680 | } |
| 681 | |
| 682 | static int qeth_l2_xmit_osa(struct qeth_card *card, struct sk_buff *skb, |
| 683 | struct qeth_qdio_out_q *queue, int cast_type) |
| 684 | { |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 685 | int push_len = sizeof(struct qeth_hdr); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 686 | unsigned int elements, nr_frags; |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 687 | unsigned int hdr_elements = 0; |
| 688 | struct qeth_hdr *hdr = NULL; |
| 689 | unsigned int hd_len = 0; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 690 | int rc; |
| 691 | |
| 692 | /* fix hardware limitation: as long as we do not have sbal |
| 693 | * chaining we can not send long frag lists |
| 694 | */ |
| 695 | if (!qeth_get_elements_no(card, skb, 0, 0)) { |
| 696 | rc = skb_linearize(skb); |
| 697 | |
| 698 | if (card->options.performance_stats) { |
| 699 | if (rc) |
| 700 | card->perf_stats.tx_linfail++; |
| 701 | else |
| 702 | card->perf_stats.tx_lin++; |
| 703 | } |
| 704 | if (rc) |
| 705 | return rc; |
| 706 | } |
| 707 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 708 | |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 709 | rc = skb_cow_head(skb, push_len); |
| 710 | if (rc) |
| 711 | return rc; |
| 712 | push_len = qeth_push_hdr(skb, &hdr, push_len); |
| 713 | if (push_len < 0) |
| 714 | return push_len; |
| 715 | if (!push_len) { |
| 716 | /* hdr was allocated from cache */ |
| 717 | hd_len = sizeof(*hdr); |
| 718 | hdr_elements = 1; |
| 719 | } |
| 720 | qeth_l2_fill_header(hdr, skb, cast_type, skb->len - push_len); |
| 721 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 722 | qeth_l2_hdr_csum(card, hdr, skb); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 723 | |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 724 | elements = qeth_get_elements_no(card, skb, hdr_elements, 0); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 725 | if (!elements) { |
| 726 | rc = -E2BIG; |
| 727 | goto out; |
| 728 | } |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 729 | elements += hdr_elements; |
| 730 | |
| 731 | /* TODO: remove the skb_orphan() once TX completion is fast enough */ |
| 732 | skb_orphan(skb); |
| 733 | rc = qeth_do_send_packet(card, queue, skb, hdr, 0, hd_len, elements); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 734 | out: |
| 735 | if (!rc) { |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 736 | if (card->options.performance_stats && nr_frags) { |
| 737 | card->perf_stats.sg_skbs_sent++; |
| 738 | /* nr_frags + skb->data */ |
| 739 | card->perf_stats.sg_frags_sent += nr_frags + 1; |
| 740 | } |
| 741 | } else { |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 742 | if (hd_len) |
| 743 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 744 | if (rc == -EBUSY) |
| 745 | /* roll back to ETH header */ |
| 746 | skb_pull(skb, push_len); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 747 | } |
| 748 | return rc; |
| 749 | } |
| 750 | |
| 751 | static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb, |
| 752 | struct qeth_qdio_out_q *queue) |
| 753 | { |
| 754 | unsigned int elements; |
| 755 | struct qeth_hdr *hdr; |
| 756 | |
| 757 | if (skb->protocol == htons(ETH_P_IPV6)) |
| 758 | return -EPROTONOSUPPORT; |
| 759 | |
| 760 | hdr = (struct qeth_hdr *)skb->data; |
| 761 | elements = qeth_get_elements_no(card, skb, 0, 0); |
| 762 | if (!elements) |
| 763 | return -E2BIG; |
| 764 | if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr))) |
| 765 | return -EINVAL; |
Julian Wiedmann | 9c3bfda | 2017-08-18 10:19:07 +0200 | [diff] [blame] | 766 | return qeth_do_send_packet(card, queue, skb, hdr, 0, 0, elements); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 767 | } |
| 768 | |
Julian Wiedmann | e38db6b | 2017-04-11 16:11:14 +0200 | [diff] [blame] | 769 | static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, |
| 770 | struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 771 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 772 | struct qeth_card *card = dev->ml_priv; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 773 | int cast_type = qeth_l2_get_cast_type(card, skb); |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 774 | struct qeth_qdio_out_q *queue; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 775 | int tx_bytes = skb->len; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 776 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 777 | |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 778 | if (card->qdio.do_prio_queueing || (cast_type && |
| 779 | card->info.is_multicast_different)) |
| 780 | queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb, |
| 781 | qeth_get_ip_version(skb), cast_type)]; |
| 782 | else |
| 783 | queue = card->qdio.out_qs[card->qdio.default_out_queue]; |
| 784 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 785 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 786 | card->stats.tx_carrier_errors++; |
| 787 | goto tx_drop; |
| 788 | } |
| 789 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 790 | if (card->options.performance_stats) { |
| 791 | card->perf_stats.outbound_cnt++; |
| 792 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 793 | } |
| 794 | netif_stop_queue(dev); |
| 795 | |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 796 | switch (card->info.type) { |
| 797 | case QETH_CARD_TYPE_OSN: |
| 798 | rc = qeth_l2_xmit_osn(card, skb, queue); |
| 799 | break; |
| 800 | case QETH_CARD_TYPE_IQD: |
| 801 | rc = qeth_l2_xmit_iqd(card, skb, queue, cast_type); |
| 802 | break; |
| 803 | default: |
| 804 | rc = qeth_l2_xmit_osa(card, skb, queue, cast_type); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 805 | } |
| 806 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 807 | if (!rc) { |
| 808 | card->stats.tx_packets++; |
| 809 | card->stats.tx_bytes += tx_bytes; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 810 | if (card->options.performance_stats) |
| 811 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 812 | card->perf_stats.outbound_start_time; |
| 813 | netif_wake_queue(dev); |
| 814 | return NETDEV_TX_OK; |
| 815 | } else if (rc == -EBUSY) { |
| 816 | return NETDEV_TX_BUSY; |
| 817 | } /* else fall through */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 818 | |
| 819 | tx_drop: |
| 820 | card->stats.tx_dropped++; |
| 821 | card->stats.tx_errors++; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 822 | dev_kfree_skb_any(skb); |
Frank Blaschka | d0ec0f5 | 2008-06-06 12:37:48 +0200 | [diff] [blame] | 823 | netif_wake_queue(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 824 | return NETDEV_TX_OK; |
| 825 | } |
| 826 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 827 | static int __qeth_l2_open(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 828 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 829 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 830 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 831 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 832 | QETH_CARD_TEXT(card, 4, "qethopen"); |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 833 | if (card->state == CARD_STATE_UP) |
| 834 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 835 | if (card->state != CARD_STATE_SOFTSETUP) |
| 836 | return -ENODEV; |
| 837 | |
| 838 | if ((card->info.type != QETH_CARD_TYPE_OSN) && |
| 839 | (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 840 | QETH_CARD_TEXT(card, 4, "nomacadr"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 841 | return -EPERM; |
| 842 | } |
| 843 | card->data.state = CH_STATE_UP; |
| 844 | card->state = CARD_STATE_UP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 845 | netif_start_queue(dev); |
| 846 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 847 | if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) { |
| 848 | napi_enable(&card->napi); |
| 849 | napi_schedule(&card->napi); |
| 850 | } else |
| 851 | rc = -EIO; |
| 852 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 853 | } |
| 854 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 855 | static int qeth_l2_open(struct net_device *dev) |
| 856 | { |
| 857 | struct qeth_card *card = dev->ml_priv; |
| 858 | |
| 859 | QETH_CARD_TEXT(card, 5, "qethope_"); |
| 860 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
| 861 | QETH_CARD_TEXT(card, 3, "openREC"); |
| 862 | return -ERESTARTSYS; |
| 863 | } |
| 864 | return __qeth_l2_open(dev); |
| 865 | } |
| 866 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 867 | static int qeth_l2_stop(struct net_device *dev) |
| 868 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 869 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 870 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 871 | QETH_CARD_TEXT(card, 4, "qethstop"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 872 | netif_tx_disable(dev); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 873 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 874 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 875 | napi_disable(&card->napi); |
| 876 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 877 | return 0; |
| 878 | } |
| 879 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 880 | static const struct device_type qeth_l2_devtype = { |
| 881 | .name = "qeth_layer2", |
| 882 | .groups = qeth_l2_attr_groups, |
| 883 | }; |
| 884 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 885 | static int qeth_l2_probe_device(struct ccwgroup_device *gdev) |
| 886 | { |
| 887 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | 9111e78 | 2017-05-10 19:07:51 +0200 | [diff] [blame] | 888 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 889 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 890 | if (gdev->dev.type == &qeth_generic_devtype) { |
| 891 | rc = qeth_l2_create_device_attributes(&gdev->dev); |
| 892 | if (rc) |
| 893 | return rc; |
| 894 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 895 | INIT_LIST_HEAD(&card->vid_list); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 896 | hash_init(card->mac_htable); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 897 | card->options.layer2 = 1; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 898 | card->info.hwtrap = 0; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 899 | qeth_l2_vnicc_set_defaults(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) |
| 904 | { |
| 905 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 906 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 907 | if (cgdev->dev.type == &qeth_generic_devtype) |
| 908 | qeth_l2_remove_device_attributes(&cgdev->dev); |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 909 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 910 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 911 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 912 | if (cgdev->state == CCWGROUP_ONLINE) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 913 | qeth_l2_set_offline(cgdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 914 | |
| 915 | if (card->dev) { |
| 916 | unregister_netdev(card->dev); |
Julian Wiedmann | 6be6873 | 2018-03-20 07:59:12 +0100 | [diff] [blame] | 917 | free_netdev(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 918 | card->dev = NULL; |
| 919 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 920 | return; |
| 921 | } |
| 922 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 923 | static const struct ethtool_ops qeth_l2_ethtool_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 924 | .get_link = ethtool_op_get_link, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 925 | .get_strings = qeth_core_get_strings, |
| 926 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 927 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 928 | .get_drvinfo = qeth_core_get_drvinfo, |
Julian Wiedmann | 993e19c | 2017-04-11 16:11:17 +0200 | [diff] [blame] | 929 | .get_link_ksettings = qeth_core_ethtool_get_link_ksettings, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 930 | }; |
| 931 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 932 | static const struct ethtool_ops qeth_l2_osn_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 933 | .get_strings = qeth_core_get_strings, |
| 934 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 935 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 936 | .get_drvinfo = qeth_core_get_drvinfo, |
| 937 | }; |
| 938 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 939 | static const struct net_device_ops qeth_l2_netdev_ops = { |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 940 | .ndo_open = qeth_l2_open, |
| 941 | .ndo_stop = qeth_l2_stop, |
| 942 | .ndo_get_stats = qeth_get_stats, |
| 943 | .ndo_start_xmit = qeth_l2_hard_start_xmit, |
Julian Wiedmann | 6d69b1f | 2017-12-01 10:14:50 +0100 | [diff] [blame] | 944 | .ndo_features_check = qeth_features_check, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 945 | .ndo_validate_addr = eth_validate_addr, |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 946 | .ndo_set_rx_mode = qeth_l2_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 947 | .ndo_do_ioctl = qeth_do_ioctl, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 948 | .ndo_set_mac_address = qeth_l2_set_mac_address, |
| 949 | .ndo_change_mtu = qeth_change_mtu, |
| 950 | .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, |
| 951 | .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, |
| 952 | .ndo_tx_timeout = qeth_tx_timeout, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 953 | .ndo_fix_features = qeth_fix_features, |
| 954 | .ndo_set_features = qeth_set_features |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 955 | }; |
| 956 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 957 | static int qeth_l2_setup_netdev(struct qeth_card *card) |
| 958 | { |
| 959 | switch (card->info.type) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 960 | case QETH_CARD_TYPE_IQD: |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 961 | card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN, |
| 962 | ether_setup); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 963 | break; |
| 964 | case QETH_CARD_TYPE_OSN: |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 965 | card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN, |
| 966 | ether_setup); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 967 | break; |
| 968 | default: |
| 969 | card->dev = alloc_etherdev(0); |
| 970 | } |
| 971 | |
| 972 | if (!card->dev) |
| 973 | return -ENODEV; |
| 974 | |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 975 | card->dev->ml_priv = card; |
Julian Wiedmann | d3aacac | 2018-03-09 18:12:55 +0100 | [diff] [blame] | 976 | card->dev->priv_flags |= IFF_UNICAST_FLT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 977 | card->dev->watchdog_timeo = QETH_TX_TIMEOUT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 978 | card->dev->mtu = card->info.initial_mtu; |
Jarod Wilson | 46b3ef4 | 2016-10-20 13:55:23 -0400 | [diff] [blame] | 979 | card->dev->min_mtu = 64; |
| 980 | card->dev->max_mtu = ETH_MAX_MTU; |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 981 | card->dev->netdev_ops = &qeth_l2_netdev_ops; |
Julian Wiedmann | 25e2c34 | 2017-05-10 19:07:53 +0200 | [diff] [blame] | 982 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 983 | card->dev->ethtool_ops = &qeth_l2_osn_ops; |
| 984 | card->dev->flags |= IFF_NOARP; |
| 985 | } else { |
| 986 | card->dev->ethtool_ops = &qeth_l2_ethtool_ops; |
| 987 | } |
Julian Wiedmann | 9400c53 | 2017-10-18 17:40:20 +0200 | [diff] [blame] | 988 | |
| 989 | if (card->info.type == QETH_CARD_TYPE_OSM) |
| 990 | card->dev->features |= NETIF_F_VLAN_CHALLENGED; |
| 991 | else |
| 992 | card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Julian Wiedmann | 0f34294 | 2018-03-09 18:12:54 +0100 | [diff] [blame] | 993 | |
| 994 | if (card->info.type != QETH_CARD_TYPE_OSN && |
| 995 | card->info.type != QETH_CARD_TYPE_IQD) { |
| 996 | card->dev->priv_flags &= ~IFF_TX_SKB_SHARING; |
| 997 | card->dev->needed_headroom = sizeof(struct qeth_hdr); |
| 998 | card->dev->hw_features |= NETIF_F_SG; |
| 999 | card->dev->vlan_features |= NETIF_F_SG; |
| 1000 | } |
| 1001 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1002 | if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) { |
Julian Wiedmann | 6d69b1f | 2017-12-01 10:14:50 +0100 | [diff] [blame] | 1003 | card->dev->features |= NETIF_F_SG; |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1004 | /* OSA 3S and earlier has no RX/TX support */ |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1005 | if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1006 | card->dev->hw_features |= NETIF_F_IP_CSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1007 | card->dev->vlan_features |= NETIF_F_IP_CSUM; |
| 1008 | } |
| 1009 | if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1010 | card->dev->hw_features |= NETIF_F_RXCSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1011 | card->dev->vlan_features |= NETIF_F_RXCSUM; |
| 1012 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1013 | } |
Julian Wiedmann | 0d6f02d | 2017-08-18 10:19:10 +0200 | [diff] [blame] | 1014 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1015 | card->info.broadcast_capable = 1; |
| 1016 | qeth_l2_request_initial_mac(card); |
| 1017 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 1018 | netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); |
Ursula Braun | e5ebe63 | 2015-12-11 12:27:55 +0100 | [diff] [blame] | 1019 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1020 | return register_netdev(card->dev); |
| 1021 | } |
| 1022 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1023 | static int qeth_l2_start_ipassists(struct qeth_card *card) |
| 1024 | { |
| 1025 | /* configure isolation level */ |
| 1026 | if (qeth_set_access_ctrl_online(card, 0)) |
| 1027 | return -ENODEV; |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1028 | return 0; |
| 1029 | } |
| 1030 | |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1031 | static void qeth_l2_trace_features(struct qeth_card *card) |
| 1032 | { |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1033 | /* Set BridgePort features */ |
| 1034 | QETH_CARD_TEXT(card, 2, "featuSBP"); |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1035 | QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, |
| 1036 | sizeof(card->options.sbp.supported_funcs)); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1037 | /* VNIC Characteristics features */ |
| 1038 | QETH_CARD_TEXT(card, 2, "feaVNICC"); |
| 1039 | QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars, |
| 1040 | sizeof(card->options.vnicc.sup_chars)); |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1041 | } |
| 1042 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1043 | static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
| 1044 | { |
| 1045 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1046 | int rc = 0; |
| 1047 | enum qeth_card_states recover_flag; |
| 1048 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1049 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1050 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1051 | QETH_DBF_TEXT(SETUP, 2, "setonlin"); |
| 1052 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1053 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1054 | recover_flag = card->state; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1055 | rc = qeth_core_hardsetup_card(card); |
| 1056 | if (rc) { |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1057 | QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1058 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1059 | goto out_remove; |
| 1060 | } |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1061 | qeth_bridgeport_query_support(card); |
| 1062 | if (card->options.sbp.supported_funcs) |
| 1063 | dev_info(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1064 | "The device represents a Bridge Capable Port\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1065 | |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1066 | if (!card->dev && qeth_l2_setup_netdev(card)) { |
| 1067 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1068 | goto out_remove; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1069 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1070 | |
| 1071 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 1072 | qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); |
| 1073 | |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1074 | if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { |
| 1075 | if (card->info.hwtrap && |
| 1076 | qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) |
| 1077 | card->info.hwtrap = 0; |
| 1078 | } else |
| 1079 | card->info.hwtrap = 0; |
| 1080 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 1081 | /* for the rx_bcast characteristic, init VNICC after setmac */ |
| 1082 | qeth_l2_vnicc_init(card); |
| 1083 | |
| 1084 | qeth_trace_features(card); |
| 1085 | qeth_l2_trace_features(card); |
| 1086 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1087 | qeth_l2_setup_bridgeport_attrs(card); |
| 1088 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1089 | card->state = CARD_STATE_HARDSETUP; |
| 1090 | qeth_print_status_message(card); |
| 1091 | |
| 1092 | /* softsetup */ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1093 | QETH_DBF_TEXT(SETUP, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1094 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1095 | if ((card->info.type == QETH_CARD_TYPE_OSD) || |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1096 | (card->info.type == QETH_CARD_TYPE_OSX)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1097 | rc = qeth_l2_start_ipassists(card); |
| 1098 | if (rc) |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1099 | goto out_remove; |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1100 | } |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1101 | |
Julian Wiedmann | 9400c53 | 2017-10-18 17:40:20 +0200 | [diff] [blame] | 1102 | if (card->info.type != QETH_CARD_TYPE_OSN) |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 1103 | qeth_l2_process_vlans(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1104 | |
| 1105 | netif_tx_disable(card->dev); |
| 1106 | |
| 1107 | rc = qeth_init_qdio_queues(card); |
| 1108 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1109 | QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1110 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1111 | goto out_remove; |
| 1112 | } |
| 1113 | card->state = CARD_STATE_SOFTSETUP; |
Ursula Braun | 2b6203b | 2010-11-26 02:41:19 +0000 | [diff] [blame] | 1114 | if (card->lan_online) |
| 1115 | netif_carrier_on(card->dev); |
| 1116 | else |
| 1117 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1118 | |
| 1119 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1120 | if (recover_flag == CARD_STATE_RECOVER) { |
| 1121 | if (recovery_mode && |
| 1122 | card->info.type != QETH_CARD_TYPE_OSN) { |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 1123 | __qeth_l2_open(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1124 | } else { |
| 1125 | rtnl_lock(); |
| 1126 | dev_open(card->dev); |
| 1127 | rtnl_unlock(); |
| 1128 | } |
| 1129 | /* this also sets saved unicast addresses */ |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 1130 | qeth_l2_set_rx_mode(card->dev); |
Hans Wippel | e830baa | 2016-09-15 14:39:21 +0200 | [diff] [blame] | 1131 | rtnl_lock(); |
| 1132 | qeth_recover_features(card->dev); |
| 1133 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1134 | } |
| 1135 | /* let user_space know that device is online */ |
| 1136 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1137 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1138 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1139 | return 0; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1140 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1141 | out_remove: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1142 | qeth_l2_stop_card(card, 0); |
| 1143 | ccw_device_set_offline(CARD_DDEV(card)); |
| 1144 | ccw_device_set_offline(CARD_WDEV(card)); |
| 1145 | ccw_device_set_offline(CARD_RDEV(card)); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 1146 | qdio_free(CARD_DDEV(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1147 | if (recover_flag == CARD_STATE_RECOVER) |
| 1148 | card->state = CARD_STATE_RECOVER; |
| 1149 | else |
| 1150 | card->state = CARD_STATE_DOWN; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1151 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1152 | mutex_unlock(&card->discipline_mutex); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1153 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | static int qeth_l2_set_online(struct ccwgroup_device *gdev) |
| 1157 | { |
| 1158 | return __qeth_l2_set_online(gdev, 0); |
| 1159 | } |
| 1160 | |
| 1161 | static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev, |
| 1162 | int recovery_mode) |
| 1163 | { |
| 1164 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 1165 | int rc = 0, rc2 = 0, rc3 = 0; |
| 1166 | enum qeth_card_states recover_flag; |
| 1167 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1168 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1169 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1170 | QETH_DBF_TEXT(SETUP, 3, "setoffl"); |
| 1171 | QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1172 | |
| 1173 | if (card->dev && netif_carrier_ok(card->dev)) |
| 1174 | netif_carrier_off(card->dev); |
| 1175 | recover_flag = card->state; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1176 | if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { |
| 1177 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
| 1178 | card->info.hwtrap = 1; |
| 1179 | } |
Ursula Braun | 0f5623c | 2008-10-24 11:16:52 +0200 | [diff] [blame] | 1180 | qeth_l2_stop_card(card, recovery_mode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1181 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 1182 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 1183 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 1184 | if (!rc) |
| 1185 | rc = (rc2) ? rc2 : rc3; |
| 1186 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1187 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 1188 | qdio_free(CARD_DDEV(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1189 | if (recover_flag == CARD_STATE_UP) |
| 1190 | card->state = CARD_STATE_RECOVER; |
| 1191 | /* let user_space know that device is offline */ |
| 1192 | kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1193 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1194 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | static int qeth_l2_set_offline(struct ccwgroup_device *cgdev) |
| 1199 | { |
| 1200 | return __qeth_l2_set_offline(cgdev, 0); |
| 1201 | } |
| 1202 | |
| 1203 | static int qeth_l2_recover(void *ptr) |
| 1204 | { |
| 1205 | struct qeth_card *card; |
| 1206 | int rc = 0; |
| 1207 | |
| 1208 | card = (struct qeth_card *) ptr; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1209 | QETH_CARD_TEXT(card, 2, "recover1"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1210 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 1211 | return 0; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1212 | QETH_CARD_TEXT(card, 2, "recover2"); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1213 | dev_warn(&card->gdev->dev, |
| 1214 | "A recovery process has been started for the device\n"); |
Stefan Raspl | 65d8013 | 2013-04-07 22:19:27 +0000 | [diff] [blame] | 1215 | qeth_set_recovery_task(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1216 | __qeth_l2_set_offline(card->gdev, 1); |
| 1217 | rc = __qeth_l2_set_online(card->gdev, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1218 | if (!rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1219 | dev_info(&card->gdev->dev, |
| 1220 | "Device successfully recovered!\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1221 | else { |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1222 | qeth_close_dev(card); |
| 1223 | dev_warn(&card->gdev->dev, "The qeth device driver " |
Stefan Raspl | 2efaf5f | 2012-10-15 19:21:18 +0000 | [diff] [blame] | 1224 | "failed to recover an error on the device\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1225 | } |
Stefan Raspl | 65d8013 | 2013-04-07 22:19:27 +0000 | [diff] [blame] | 1226 | qeth_clear_recovery_task(card); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1227 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 1228 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | static int __init qeth_l2_init(void) |
| 1233 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1234 | pr_info("register layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1235 | return 0; |
| 1236 | } |
| 1237 | |
| 1238 | static void __exit qeth_l2_exit(void) |
| 1239 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1240 | pr_info("unregister layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1241 | } |
| 1242 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1243 | static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) |
| 1244 | { |
| 1245 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1246 | |
| 1247 | if (card->dev) |
| 1248 | netif_device_detach(card->dev); |
| 1249 | qeth_set_allowed_threads(card, 0, 1); |
| 1250 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 1251 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1252 | return 0; |
| 1253 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1254 | if (card->info.hwtrap) |
| 1255 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1256 | __qeth_l2_set_offline(card->gdev, 1); |
| 1257 | } else |
| 1258 | __qeth_l2_set_offline(card->gdev, 0); |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
| 1262 | static int qeth_l2_pm_resume(struct ccwgroup_device *gdev) |
| 1263 | { |
| 1264 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1265 | int rc = 0; |
| 1266 | |
| 1267 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1268 | goto out; |
| 1269 | |
| 1270 | if (card->state == CARD_STATE_RECOVER) { |
| 1271 | rc = __qeth_l2_set_online(card->gdev, 1); |
| 1272 | if (rc) { |
Ursula Braun | 869da90 | 2010-03-08 20:36:56 +0000 | [diff] [blame] | 1273 | rtnl_lock(); |
| 1274 | dev_close(card->dev); |
| 1275 | rtnl_unlock(); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1276 | } |
| 1277 | } else |
| 1278 | rc = __qeth_l2_set_online(card->gdev, 0); |
| 1279 | out: |
| 1280 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1281 | if (card->dev) |
| 1282 | netif_device_attach(card->dev); |
| 1283 | if (rc) |
| 1284 | dev_warn(&card->gdev->dev, "The qeth device driver " |
| 1285 | "failed to recover an error on the device\n"); |
| 1286 | return rc; |
| 1287 | } |
| 1288 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1289 | /* Returns zero if the command is successfully "consumed" */ |
| 1290 | static int qeth_l2_control_event(struct qeth_card *card, |
| 1291 | struct qeth_ipa_cmd *cmd) |
| 1292 | { |
| 1293 | switch (cmd->hdr.command) { |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1294 | case IPA_CMD_SETBRIDGEPORT_OSA: |
| 1295 | case IPA_CMD_SETBRIDGEPORT_IQD: |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1296 | if (cmd->data.sbp.hdr.command_code == |
| 1297 | IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { |
| 1298 | qeth_bridge_state_change(card, cmd); |
| 1299 | return 0; |
| 1300 | } else |
| 1301 | return 1; |
| 1302 | case IPA_CMD_ADDRESS_CHANGE_NOTIF: |
| 1303 | qeth_bridge_host_event(card, cmd); |
| 1304 | return 0; |
| 1305 | default: |
| 1306 | return 1; |
| 1307 | } |
| 1308 | } |
| 1309 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1310 | struct qeth_discipline qeth_l2_discipline = { |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 1311 | .devtype = &qeth_l2_devtype, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1312 | .start_poll = qeth_qdio_start_poll, |
| 1313 | .input_handler = (qdio_handler_t *) qeth_qdio_input_handler, |
| 1314 | .output_handler = (qdio_handler_t *) qeth_qdio_output_handler, |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 1315 | .process_rx_buffer = qeth_l2_process_inbound_buffer, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1316 | .recover = qeth_l2_recover, |
| 1317 | .setup = qeth_l2_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1318 | .remove = qeth_l2_remove_device, |
| 1319 | .set_online = qeth_l2_set_online, |
| 1320 | .set_offline = qeth_l2_set_offline, |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1321 | .freeze = qeth_l2_pm_suspend, |
| 1322 | .thaw = qeth_l2_pm_resume, |
| 1323 | .restore = qeth_l2_pm_resume, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 1324 | .do_ioctl = NULL, |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1325 | .control_event_handler = qeth_l2_control_event, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1326 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1327 | EXPORT_SYMBOL_GPL(qeth_l2_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1328 | |
| 1329 | static int qeth_osn_send_control_data(struct qeth_card *card, int len, |
| 1330 | struct qeth_cmd_buffer *iob) |
| 1331 | { |
| 1332 | unsigned long flags; |
| 1333 | int rc = 0; |
| 1334 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1335 | QETH_CARD_TEXT(card, 5, "osndctrd"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1336 | |
| 1337 | wait_event(card->wait_q, |
| 1338 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
| 1339 | qeth_prepare_control_data(card, len, iob); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1340 | QETH_CARD_TEXT(card, 6, "osnoirqp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1341 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1342 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1343 | (addr_t) iob, 0, 0); |
| 1344 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1345 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 1346 | QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1347 | "ccw_device_start rc = %i\n", rc); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1348 | QETH_CARD_TEXT_(card, 2, " err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1349 | qeth_release_buffer(iob->channel, iob); |
| 1350 | atomic_set(&card->write.irq_pending, 0); |
| 1351 | wake_up(&card->wait_q); |
| 1352 | } |
| 1353 | return rc; |
| 1354 | } |
| 1355 | |
| 1356 | static int qeth_osn_send_ipa_cmd(struct qeth_card *card, |
| 1357 | struct qeth_cmd_buffer *iob, int data_len) |
| 1358 | { |
| 1359 | u16 s1, s2; |
| 1360 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1361 | QETH_CARD_TEXT(card, 4, "osndipa"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1362 | |
| 1363 | qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); |
| 1364 | s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); |
| 1365 | s2 = (u16)data_len; |
| 1366 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 1367 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 1368 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 1369 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 1370 | return qeth_osn_send_control_data(card, s1, iob); |
| 1371 | } |
| 1372 | |
| 1373 | int qeth_osn_assist(struct net_device *dev, void *data, int data_len) |
| 1374 | { |
| 1375 | struct qeth_cmd_buffer *iob; |
| 1376 | struct qeth_card *card; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1377 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1378 | if (!dev) |
| 1379 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1380 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1381 | if (!card) |
| 1382 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1383 | QETH_CARD_TEXT(card, 2, "osnsdmc"); |
Eugene Crosser | c352125 | 2015-01-16 14:05:47 +0100 | [diff] [blame] | 1384 | if (!qeth_card_hw_is_reachable(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1385 | return -ENODEV; |
| 1386 | iob = qeth_wait_for_buffer(&card->write); |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1387 | memcpy(__ipa_cmd(iob), data, data_len); |
| 1388 | return qeth_osn_send_ipa_cmd(card, iob, data_len); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1389 | } |
| 1390 | EXPORT_SYMBOL(qeth_osn_assist); |
| 1391 | |
| 1392 | int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, |
| 1393 | int (*assist_cb)(struct net_device *, void *), |
| 1394 | int (*data_cb)(struct sk_buff *)) |
| 1395 | { |
| 1396 | struct qeth_card *card; |
| 1397 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1398 | *dev = qeth_l2_netdev_by_devno(read_dev_no); |
| 1399 | if (*dev == NULL) |
| 1400 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1401 | card = (*dev)->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1402 | if (!card) |
| 1403 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1404 | QETH_CARD_TEXT(card, 2, "osnreg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1405 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 1406 | return -EINVAL; |
| 1407 | card->osn_info.assist_cb = assist_cb; |
| 1408 | card->osn_info.data_cb = data_cb; |
| 1409 | return 0; |
| 1410 | } |
| 1411 | EXPORT_SYMBOL(qeth_osn_register); |
| 1412 | |
| 1413 | void qeth_osn_deregister(struct net_device *dev) |
| 1414 | { |
| 1415 | struct qeth_card *card; |
| 1416 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1417 | if (!dev) |
| 1418 | return; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1419 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1420 | if (!card) |
| 1421 | return; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1422 | QETH_CARD_TEXT(card, 2, "osndereg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1423 | card->osn_info.assist_cb = NULL; |
| 1424 | card->osn_info.data_cb = NULL; |
| 1425 | return; |
| 1426 | } |
| 1427 | EXPORT_SYMBOL(qeth_osn_deregister); |
| 1428 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1429 | /* SETBRIDGEPORT support, async notifications */ |
| 1430 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1431 | enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; |
| 1432 | |
| 1433 | /** |
| 1434 | * qeth_bridge_emit_host_event() - bridgeport address change notification |
| 1435 | * @card: qeth_card structure pointer, for udev events. |
| 1436 | * @evtype: "normal" register/unregister, or abort, or reset. For abort |
| 1437 | * and reset token and addr_lnid are unused and may be NULL. |
| 1438 | * @code: event bitmask: high order bit 0x80 value 1 means removal of an |
| 1439 | * object, 0 - addition of an object. |
| 1440 | * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. |
| 1441 | * @token: "network token" structure identifying physical address of the port. |
| 1442 | * @addr_lnid: pointer to structure with MAC address and VLAN ID. |
| 1443 | * |
| 1444 | * This function is called when registrations and deregistrations are |
| 1445 | * reported by the hardware, and also when notifications are enabled - |
| 1446 | * for all currently registered addresses. |
| 1447 | */ |
| 1448 | static void qeth_bridge_emit_host_event(struct qeth_card *card, |
| 1449 | enum qeth_an_event_type evtype, |
| 1450 | u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid) |
| 1451 | { |
| 1452 | char str[7][32]; |
| 1453 | char *env[8]; |
| 1454 | int i = 0; |
| 1455 | |
| 1456 | switch (evtype) { |
| 1457 | case anev_reg_unreg: |
| 1458 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", |
| 1459 | (code & IPA_ADDR_CHANGE_CODE_REMOVAL) |
| 1460 | ? "deregister" : "register"); |
| 1461 | env[i] = str[i]; i++; |
| 1462 | if (code & IPA_ADDR_CHANGE_CODE_VLANID) { |
| 1463 | snprintf(str[i], sizeof(str[i]), "VLAN=%d", |
| 1464 | addr_lnid->lnid); |
| 1465 | env[i] = str[i]; i++; |
| 1466 | } |
| 1467 | if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { |
Eugene Crosser | 9846e70 | 2015-09-18 16:06:48 +0200 | [diff] [blame] | 1468 | snprintf(str[i], sizeof(str[i]), "MAC=%pM", |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1469 | addr_lnid->mac); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1470 | env[i] = str[i]; i++; |
| 1471 | } |
| 1472 | snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", |
| 1473 | token->cssid, token->ssid, token->devnum); |
| 1474 | env[i] = str[i]; i++; |
| 1475 | snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); |
| 1476 | env[i] = str[i]; i++; |
| 1477 | snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", |
| 1478 | token->chpid); |
| 1479 | env[i] = str[i]; i++; |
| 1480 | snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); |
| 1481 | env[i] = str[i]; i++; |
| 1482 | break; |
| 1483 | case anev_abort: |
| 1484 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); |
| 1485 | env[i] = str[i]; i++; |
| 1486 | break; |
| 1487 | case anev_reset: |
| 1488 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); |
| 1489 | env[i] = str[i]; i++; |
| 1490 | break; |
| 1491 | } |
| 1492 | env[i] = NULL; |
| 1493 | kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); |
| 1494 | } |
| 1495 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1496 | struct qeth_bridge_state_data { |
| 1497 | struct work_struct worker; |
| 1498 | struct qeth_card *card; |
| 1499 | struct qeth_sbp_state_change qports; |
| 1500 | }; |
| 1501 | |
| 1502 | static void qeth_bridge_state_change_worker(struct work_struct *work) |
| 1503 | { |
| 1504 | struct qeth_bridge_state_data *data = |
| 1505 | container_of(work, struct qeth_bridge_state_data, worker); |
| 1506 | /* We are only interested in the first entry - local port */ |
| 1507 | struct qeth_sbp_port_entry *entry = &data->qports.entry[0]; |
| 1508 | char env_locrem[32]; |
| 1509 | char env_role[32]; |
| 1510 | char env_state[32]; |
| 1511 | char *env[] = { |
| 1512 | env_locrem, |
| 1513 | env_role, |
| 1514 | env_state, |
| 1515 | NULL |
| 1516 | }; |
| 1517 | |
| 1518 | /* Role should not change by itself, but if it did, */ |
| 1519 | /* information from the hardware is authoritative. */ |
| 1520 | mutex_lock(&data->card->conf_mutex); |
| 1521 | data->card->options.sbp.role = entry->role; |
| 1522 | mutex_unlock(&data->card->conf_mutex); |
| 1523 | |
| 1524 | snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); |
| 1525 | snprintf(env_role, sizeof(env_role), "ROLE=%s", |
| 1526 | (entry->role == QETH_SBP_ROLE_NONE) ? "none" : |
| 1527 | (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : |
| 1528 | (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : |
| 1529 | "<INVALID>"); |
| 1530 | snprintf(env_state, sizeof(env_state), "STATE=%s", |
| 1531 | (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : |
| 1532 | (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" : |
| 1533 | (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" : |
| 1534 | "<INVALID>"); |
| 1535 | kobject_uevent_env(&data->card->gdev->dev.kobj, |
| 1536 | KOBJ_CHANGE, env); |
| 1537 | kfree(data); |
| 1538 | } |
| 1539 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1540 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 1541 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1542 | { |
| 1543 | struct qeth_sbp_state_change *qports = |
| 1544 | &cmd->data.sbp.data.state_change; |
| 1545 | struct qeth_bridge_state_data *data; |
| 1546 | int extrasize; |
| 1547 | |
| 1548 | QETH_CARD_TEXT(card, 2, "brstchng"); |
| 1549 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
Thomas Richter | 8a59314 | 2014-10-22 12:18:03 +0200 | [diff] [blame] | 1550 | QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1551 | return; |
| 1552 | } |
| 1553 | extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries; |
| 1554 | data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize, |
| 1555 | GFP_ATOMIC); |
| 1556 | if (!data) { |
| 1557 | QETH_CARD_TEXT(card, 2, "BPSalloc"); |
| 1558 | return; |
| 1559 | } |
| 1560 | INIT_WORK(&data->worker, qeth_bridge_state_change_worker); |
| 1561 | data->card = card; |
| 1562 | memcpy(&data->qports, qports, |
| 1563 | sizeof(struct qeth_sbp_state_change) + extrasize); |
| 1564 | queue_work(qeth_wq, &data->worker); |
| 1565 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1566 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1567 | struct qeth_bridge_host_data { |
| 1568 | struct work_struct worker; |
| 1569 | struct qeth_card *card; |
| 1570 | struct qeth_ipacmd_addr_change hostevs; |
| 1571 | }; |
| 1572 | |
| 1573 | static void qeth_bridge_host_event_worker(struct work_struct *work) |
| 1574 | { |
| 1575 | struct qeth_bridge_host_data *data = |
| 1576 | container_of(work, struct qeth_bridge_host_data, worker); |
| 1577 | int i; |
| 1578 | |
| 1579 | if (data->hostevs.lost_event_mask) { |
| 1580 | dev_info(&data->card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1581 | "Address notification from the Bridge Port stopped %s (%s)\n", |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1582 | data->card->dev->name, |
| 1583 | (data->hostevs.lost_event_mask == 0x01) |
| 1584 | ? "Overflow" |
| 1585 | : (data->hostevs.lost_event_mask == 0x02) |
| 1586 | ? "Bridge port state change" |
| 1587 | : "Unknown reason"); |
| 1588 | mutex_lock(&data->card->conf_mutex); |
| 1589 | data->card->options.sbp.hostnotification = 0; |
| 1590 | mutex_unlock(&data->card->conf_mutex); |
| 1591 | qeth_bridge_emit_host_event(data->card, anev_abort, |
| 1592 | 0, NULL, NULL); |
| 1593 | } else |
| 1594 | for (i = 0; i < data->hostevs.num_entries; i++) { |
| 1595 | struct qeth_ipacmd_addr_change_entry *entry = |
| 1596 | &data->hostevs.entry[i]; |
| 1597 | qeth_bridge_emit_host_event(data->card, |
| 1598 | anev_reg_unreg, |
| 1599 | entry->change_code, |
| 1600 | &entry->token, &entry->addr_lnid); |
| 1601 | } |
| 1602 | kfree(data); |
| 1603 | } |
| 1604 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1605 | static void qeth_bridge_host_event(struct qeth_card *card, |
| 1606 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1607 | { |
| 1608 | struct qeth_ipacmd_addr_change *hostevs = |
| 1609 | &cmd->data.addrchange; |
| 1610 | struct qeth_bridge_host_data *data; |
| 1611 | int extrasize; |
| 1612 | |
| 1613 | QETH_CARD_TEXT(card, 2, "brhostev"); |
| 1614 | if (cmd->hdr.return_code != 0x0000) { |
| 1615 | if (cmd->hdr.return_code == 0x0010) { |
| 1616 | if (hostevs->lost_event_mask == 0x00) |
| 1617 | hostevs->lost_event_mask = 0xff; |
| 1618 | } else { |
| 1619 | QETH_CARD_TEXT_(card, 2, "BPHe%04x", |
| 1620 | cmd->hdr.return_code); |
| 1621 | return; |
| 1622 | } |
| 1623 | } |
| 1624 | extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * |
| 1625 | hostevs->num_entries; |
| 1626 | data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize, |
| 1627 | GFP_ATOMIC); |
| 1628 | if (!data) { |
| 1629 | QETH_CARD_TEXT(card, 2, "BPHalloc"); |
| 1630 | return; |
| 1631 | } |
| 1632 | INIT_WORK(&data->worker, qeth_bridge_host_event_worker); |
| 1633 | data->card = card; |
| 1634 | memcpy(&data->hostevs, hostevs, |
| 1635 | sizeof(struct qeth_ipacmd_addr_change) + extrasize); |
| 1636 | queue_work(qeth_wq, &data->worker); |
| 1637 | } |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1638 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1639 | /* SETBRIDGEPORT support; sending commands */ |
| 1640 | |
| 1641 | struct _qeth_sbp_cbctl { |
| 1642 | u16 ipa_rc; |
| 1643 | u16 cmd_rc; |
| 1644 | union { |
| 1645 | u32 supported; |
| 1646 | struct { |
| 1647 | enum qeth_sbp_roles *role; |
| 1648 | enum qeth_sbp_states *state; |
| 1649 | } qports; |
| 1650 | } data; |
| 1651 | }; |
| 1652 | |
| 1653 | /** |
| 1654 | * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes. |
| 1655 | * @card: qeth_card structure pointer, for debug messages. |
| 1656 | * @cbctl: state structure with hardware return codes. |
| 1657 | * @setcmd: IPA command code |
| 1658 | * |
| 1659 | * Returns negative errno-compatible error indication or 0 on success. |
| 1660 | */ |
| 1661 | static int qeth_bridgeport_makerc(struct qeth_card *card, |
| 1662 | struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd) |
| 1663 | { |
| 1664 | int rc; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1665 | int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1666 | |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1667 | if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) || |
| 1668 | (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc))) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1669 | switch (cbctl->cmd_rc) { |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1670 | case IPA_RC_SUCCESS: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1671 | rc = 0; |
| 1672 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1673 | case IPA_RC_L2_UNSUPPORTED_CMD: |
| 1674 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1675 | rc = -EOPNOTSUPP; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1676 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1677 | case IPA_RC_SBP_OSA_NOT_CONFIGURED: |
| 1678 | case IPA_RC_SBP_IQD_NOT_CONFIGURED: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1679 | rc = -ENODEV; /* maybe not the best code here? */ |
| 1680 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1681 | "The device is not configured as a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1682 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1683 | case IPA_RC_SBP_OSA_OS_MISMATCH: |
| 1684 | case IPA_RC_SBP_IQD_OS_MISMATCH: |
Eugene Crosser | 1b05cf6 | 2016-06-16 16:18:51 +0200 | [diff] [blame] | 1685 | rc = -EPERM; |
| 1686 | dev_err(&card->gdev->dev, |
| 1687 | "A Bridge Port is already configured by a different operating system\n"); |
| 1688 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1689 | case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: |
| 1690 | case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1691 | switch (setcmd) { |
| 1692 | case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: |
| 1693 | rc = -EEXIST; |
| 1694 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1695 | "The LAN already has a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1696 | break; |
| 1697 | case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: |
| 1698 | rc = -EBUSY; |
| 1699 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1700 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1701 | break; |
| 1702 | default: |
| 1703 | rc = -EIO; |
| 1704 | } |
| 1705 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1706 | case IPA_RC_SBP_OSA_CURRENT_SECOND: |
| 1707 | case IPA_RC_SBP_IQD_CURRENT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1708 | rc = -EBUSY; |
| 1709 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1710 | "The device is already a secondary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1711 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1712 | case IPA_RC_SBP_OSA_LIMIT_SECOND: |
| 1713 | case IPA_RC_SBP_IQD_LIMIT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1714 | rc = -EEXIST; |
| 1715 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1716 | "The LAN cannot have more secondary Bridge Ports\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1717 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1718 | case IPA_RC_SBP_OSA_CURRENT_PRIMARY: |
| 1719 | case IPA_RC_SBP_IQD_CURRENT_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1720 | rc = -EBUSY; |
| 1721 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1722 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1723 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1724 | case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: |
| 1725 | case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1726 | rc = -EACCES; |
| 1727 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1728 | "The device is not authorized to be a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1729 | break; |
| 1730 | default: |
| 1731 | rc = -EIO; |
| 1732 | } |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1733 | else |
| 1734 | switch (cbctl->ipa_rc) { |
| 1735 | case IPA_RC_NOTSUPP: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1736 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1737 | break; |
| 1738 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1739 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1740 | break; |
| 1741 | default: |
| 1742 | rc = -EIO; |
| 1743 | } |
| 1744 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1745 | if (rc) { |
| 1746 | QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc); |
| 1747 | QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc); |
| 1748 | } |
| 1749 | return rc; |
| 1750 | } |
| 1751 | |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1752 | static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card, |
| 1753 | enum qeth_ipa_sbp_cmd sbp_cmd, |
| 1754 | unsigned int cmd_length) |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1755 | { |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1756 | enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ? |
| 1757 | IPA_CMD_SETBRIDGEPORT_IQD : |
| 1758 | IPA_CMD_SETBRIDGEPORT_OSA; |
| 1759 | struct qeth_cmd_buffer *iob; |
| 1760 | struct qeth_ipa_cmd *cmd; |
| 1761 | |
| 1762 | iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0); |
| 1763 | if (!iob) |
| 1764 | return iob; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1765 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1766 | cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + |
| 1767 | cmd_length; |
| 1768 | cmd->data.sbp.hdr.command_code = sbp_cmd; |
| 1769 | cmd->data.sbp.hdr.used_total = 1; |
| 1770 | cmd->data.sbp.hdr.seq_no = 1; |
| 1771 | return iob; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1772 | } |
| 1773 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1774 | static int qeth_bridgeport_query_support_cb(struct qeth_card *card, |
| 1775 | struct qeth_reply *reply, unsigned long data) |
| 1776 | { |
| 1777 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1778 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1779 | QETH_CARD_TEXT(card, 2, "brqsupcb"); |
| 1780 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1781 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1782 | if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) { |
| 1783 | cbctl->data.supported = |
| 1784 | cmd->data.sbp.data.query_cmds_supp.supported_cmds; |
| 1785 | } else { |
| 1786 | cbctl->data.supported = 0; |
| 1787 | } |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
| 1791 | /** |
| 1792 | * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. |
| 1793 | * @card: qeth_card structure pointer. |
| 1794 | * |
| 1795 | * Sets bitmask of supported setbridgeport subfunctions in the qeth_card |
| 1796 | * strucutre: card->options.sbp.supported_funcs. |
| 1797 | */ |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1798 | static void qeth_bridgeport_query_support(struct qeth_card *card) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1799 | { |
| 1800 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1801 | struct _qeth_sbp_cbctl cbctl; |
| 1802 | |
| 1803 | QETH_CARD_TEXT(card, 2, "brqsuppo"); |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1804 | iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED, |
| 1805 | sizeof(struct qeth_sbp_query_cmds_supp)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1806 | if (!iob) |
| 1807 | return; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1808 | if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, |
| 1809 | (void *)&cbctl) || |
| 1810 | qeth_bridgeport_makerc(card, &cbctl, |
| 1811 | IPA_SBP_QUERY_COMMANDS_SUPPORTED)) { |
| 1812 | /* non-zero makerc signifies failure, and produce messages */ |
| 1813 | card->options.sbp.role = QETH_SBP_ROLE_NONE; |
| 1814 | return; |
| 1815 | } |
| 1816 | card->options.sbp.supported_funcs = cbctl.data.supported; |
| 1817 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1818 | |
| 1819 | static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, |
| 1820 | struct qeth_reply *reply, unsigned long data) |
| 1821 | { |
| 1822 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1823 | struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports; |
| 1824 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1825 | |
| 1826 | QETH_CARD_TEXT(card, 2, "brqprtcb"); |
| 1827 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1828 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1829 | if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0)) |
| 1830 | return 0; |
| 1831 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
| 1832 | cbctl->cmd_rc = 0xffff; |
| 1833 | QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); |
| 1834 | return 0; |
| 1835 | } |
| 1836 | /* first entry contains the state of the local port */ |
| 1837 | if (qports->num_entries > 0) { |
| 1838 | if (cbctl->data.qports.role) |
| 1839 | *cbctl->data.qports.role = qports->entry[0].role; |
| 1840 | if (cbctl->data.qports.state) |
| 1841 | *cbctl->data.qports.state = qports->entry[0].state; |
| 1842 | } |
| 1843 | return 0; |
| 1844 | } |
| 1845 | |
| 1846 | /** |
| 1847 | * qeth_bridgeport_query_ports() - query local bridgeport status. |
| 1848 | * @card: qeth_card structure pointer. |
| 1849 | * @role: Role of the port: 0-none, 1-primary, 2-secondary. |
| 1850 | * @state: State of the port: 0-inactive, 1-standby, 2-active. |
| 1851 | * |
| 1852 | * Returns negative errno-compatible error indication or 0 on success. |
| 1853 | * |
| 1854 | * 'role' and 'state' are not updated in case of hardware operation failure. |
| 1855 | */ |
| 1856 | int qeth_bridgeport_query_ports(struct qeth_card *card, |
| 1857 | enum qeth_sbp_roles *role, enum qeth_sbp_states *state) |
| 1858 | { |
| 1859 | int rc = 0; |
| 1860 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1861 | struct _qeth_sbp_cbctl cbctl = { |
| 1862 | .data = { |
| 1863 | .qports = { |
| 1864 | .role = role, |
| 1865 | .state = state, |
| 1866 | }, |
| 1867 | }, |
| 1868 | }; |
| 1869 | |
| 1870 | QETH_CARD_TEXT(card, 2, "brqports"); |
| 1871 | if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) |
| 1872 | return -EOPNOTSUPP; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1873 | iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1874 | if (!iob) |
| 1875 | return -ENOMEM; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1876 | rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, |
| 1877 | (void *)&cbctl); |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1878 | if (rc < 0) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1879 | return rc; |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1880 | return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1881 | } |
| 1882 | EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports); |
| 1883 | |
| 1884 | static int qeth_bridgeport_set_cb(struct qeth_card *card, |
| 1885 | struct qeth_reply *reply, unsigned long data) |
| 1886 | { |
| 1887 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; |
| 1888 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1889 | QETH_CARD_TEXT(card, 2, "brsetrcb"); |
| 1890 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1891 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1892 | return 0; |
| 1893 | } |
| 1894 | |
| 1895 | /** |
| 1896 | * qeth_bridgeport_setrole() - Assign primary role to the port. |
| 1897 | * @card: qeth_card structure pointer. |
| 1898 | * @role: Role to assign. |
| 1899 | * |
| 1900 | * Returns negative errno-compatible error indication or 0 on success. |
| 1901 | */ |
| 1902 | int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) |
| 1903 | { |
| 1904 | int rc = 0; |
| 1905 | int cmdlength; |
| 1906 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1907 | struct _qeth_sbp_cbctl cbctl; |
| 1908 | enum qeth_ipa_sbp_cmd setcmd; |
| 1909 | |
| 1910 | QETH_CARD_TEXT(card, 2, "brsetrol"); |
| 1911 | switch (role) { |
| 1912 | case QETH_SBP_ROLE_NONE: |
| 1913 | setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1914 | cmdlength = sizeof(struct qeth_sbp_reset_role); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1915 | break; |
| 1916 | case QETH_SBP_ROLE_PRIMARY: |
| 1917 | setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1918 | cmdlength = sizeof(struct qeth_sbp_set_primary); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1919 | break; |
| 1920 | case QETH_SBP_ROLE_SECONDARY: |
| 1921 | setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1922 | cmdlength = sizeof(struct qeth_sbp_set_secondary); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1923 | break; |
| 1924 | default: |
| 1925 | return -EINVAL; |
| 1926 | } |
| 1927 | if (!(card->options.sbp.supported_funcs & setcmd)) |
| 1928 | return -EOPNOTSUPP; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1929 | iob = qeth_sbp_build_cmd(card, setcmd, cmdlength); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1930 | if (!iob) |
| 1931 | return -ENOMEM; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1932 | rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, |
| 1933 | (void *)&cbctl); |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1934 | if (rc < 0) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1935 | return rc; |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1936 | return qeth_bridgeport_makerc(card, &cbctl, setcmd); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1937 | } |
| 1938 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1939 | /** |
| 1940 | * qeth_anset_makerc() - derive "traditional" error from hardware codes. |
| 1941 | * @card: qeth_card structure pointer, for debug messages. |
| 1942 | * |
| 1943 | * Returns negative errno-compatible error indication or 0 on success. |
| 1944 | */ |
| 1945 | static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response) |
| 1946 | { |
| 1947 | int rc; |
| 1948 | |
| 1949 | if (pnso_rc == 0) |
| 1950 | switch (response) { |
| 1951 | case 0x0001: |
| 1952 | rc = 0; |
| 1953 | break; |
| 1954 | case 0x0004: |
| 1955 | case 0x0100: |
| 1956 | case 0x0106: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1957 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1958 | dev_err(&card->gdev->dev, |
| 1959 | "Setting address notification failed\n"); |
| 1960 | break; |
| 1961 | case 0x0107: |
| 1962 | rc = -EAGAIN; |
| 1963 | break; |
| 1964 | default: |
| 1965 | rc = -EIO; |
| 1966 | } |
| 1967 | else |
| 1968 | rc = -EIO; |
| 1969 | |
| 1970 | if (rc) { |
| 1971 | QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc); |
| 1972 | QETH_CARD_TEXT_(card, 2, "SBPr%04x", response); |
| 1973 | } |
| 1974 | return rc; |
| 1975 | } |
| 1976 | |
| 1977 | static void qeth_bridgeport_an_set_cb(void *priv, |
| 1978 | enum qdio_brinfo_entry_type type, void *entry) |
| 1979 | { |
| 1980 | struct qeth_card *card = (struct qeth_card *)priv; |
| 1981 | struct qdio_brinfo_entry_l2 *l2entry; |
| 1982 | u8 code; |
| 1983 | |
| 1984 | if (type != l2_addr_lnid) { |
| 1985 | WARN_ON_ONCE(1); |
| 1986 | return; |
| 1987 | } |
| 1988 | |
| 1989 | l2entry = (struct qdio_brinfo_entry_l2 *)entry; |
| 1990 | code = IPA_ADDR_CHANGE_CODE_MACADDR; |
| 1991 | if (l2entry->addr_lnid.lnid) |
| 1992 | code |= IPA_ADDR_CHANGE_CODE_VLANID; |
| 1993 | qeth_bridge_emit_host_event(card, anev_reg_unreg, code, |
| 1994 | (struct net_if_token *)&l2entry->nit, |
| 1995 | (struct mac_addr_lnid *)&l2entry->addr_lnid); |
| 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification |
| 2000 | * @card: qeth_card structure pointer. |
| 2001 | * @enable: 0 - disable, non-zero - enable notifications |
| 2002 | * |
| 2003 | * Returns negative errno-compatible error indication or 0 on success. |
| 2004 | * |
| 2005 | * On enable, emits a series of address notifications udev events for all |
| 2006 | * currently registered hosts. |
| 2007 | */ |
| 2008 | int qeth_bridgeport_an_set(struct qeth_card *card, int enable) |
| 2009 | { |
| 2010 | int rc; |
| 2011 | u16 response; |
| 2012 | struct ccw_device *ddev; |
| 2013 | struct subchannel_id schid; |
| 2014 | |
| 2015 | if (!card) |
| 2016 | return -EINVAL; |
| 2017 | if (!card->options.sbp.supported_funcs) |
| 2018 | return -EOPNOTSUPP; |
| 2019 | ddev = CARD_DDEV(card); |
| 2020 | ccw_device_get_schid(ddev, &schid); |
| 2021 | |
| 2022 | if (enable) { |
| 2023 | qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); |
| 2024 | rc = qdio_pnso_brinfo(schid, 1, &response, |
| 2025 | qeth_bridgeport_an_set_cb, card); |
| 2026 | } else |
| 2027 | rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL); |
| 2028 | return qeth_anset_makerc(card, rc, response); |
| 2029 | } |
| 2030 | EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set); |
| 2031 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2032 | static bool qeth_bridgeport_is_in_use(struct qeth_card *card) |
| 2033 | { |
| 2034 | return (card->options.sbp.role || card->options.sbp.reflect_promisc || |
| 2035 | card->options.sbp.hostnotification); |
| 2036 | } |
| 2037 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2038 | /* VNIC Characteristics support */ |
| 2039 | |
| 2040 | /* handle VNICC IPA command return codes; convert to error codes */ |
| 2041 | static int qeth_l2_vnicc_makerc(struct qeth_card *card, int ipa_rc) |
| 2042 | { |
| 2043 | int rc; |
| 2044 | |
| 2045 | switch (ipa_rc) { |
| 2046 | case IPA_RC_SUCCESS: |
| 2047 | return ipa_rc; |
| 2048 | case IPA_RC_L2_UNSUPPORTED_CMD: |
| 2049 | case IPA_RC_NOTSUPP: |
| 2050 | rc = -EOPNOTSUPP; |
| 2051 | break; |
| 2052 | case IPA_RC_VNICC_OOSEQ: |
| 2053 | rc = -EALREADY; |
| 2054 | break; |
| 2055 | case IPA_RC_VNICC_VNICBP: |
| 2056 | rc = -EBUSY; |
| 2057 | break; |
| 2058 | case IPA_RC_L2_ADDR_TABLE_FULL: |
| 2059 | rc = -ENOSPC; |
| 2060 | break; |
| 2061 | case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: |
| 2062 | rc = -EACCES; |
| 2063 | break; |
| 2064 | default: |
| 2065 | rc = -EIO; |
| 2066 | } |
| 2067 | |
| 2068 | QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc); |
| 2069 | return rc; |
| 2070 | } |
| 2071 | |
| 2072 | /* generic VNICC request call back control */ |
| 2073 | struct _qeth_l2_vnicc_request_cbctl { |
| 2074 | u32 sub_cmd; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2075 | struct { |
| 2076 | u32 vnic_char; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2077 | u32 timeout; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2078 | } param; |
| 2079 | struct { |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2080 | union{ |
| 2081 | u32 *sup_cmds; |
| 2082 | u32 *timeout; |
| 2083 | }; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2084 | } result; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2085 | }; |
| 2086 | |
| 2087 | /* generic VNICC request call back */ |
| 2088 | static int qeth_l2_vnicc_request_cb(struct qeth_card *card, |
| 2089 | struct qeth_reply *reply, |
| 2090 | unsigned long data) |
| 2091 | { |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2092 | struct _qeth_l2_vnicc_request_cbctl *cbctl = |
| 2093 | (struct _qeth_l2_vnicc_request_cbctl *) reply->param; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2094 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 2095 | struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc; |
| 2096 | |
| 2097 | QETH_CARD_TEXT(card, 2, "vniccrcb"); |
| 2098 | if (cmd->hdr.return_code) |
| 2099 | return 0; |
| 2100 | /* return results to caller */ |
| 2101 | card->options.vnicc.sup_chars = rep->hdr.sup; |
| 2102 | card->options.vnicc.cur_chars = rep->hdr.cur; |
| 2103 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2104 | if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS) |
| 2105 | *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds; |
| 2106 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2107 | if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT) |
| 2108 | *cbctl->result.timeout = rep->getset_timeout.timeout; |
| 2109 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2110 | return 0; |
| 2111 | } |
| 2112 | |
| 2113 | /* generic VNICC request */ |
| 2114 | static int qeth_l2_vnicc_request(struct qeth_card *card, |
| 2115 | struct _qeth_l2_vnicc_request_cbctl *cbctl) |
| 2116 | { |
| 2117 | struct qeth_ipacmd_vnicc *req; |
| 2118 | struct qeth_cmd_buffer *iob; |
| 2119 | struct qeth_ipa_cmd *cmd; |
| 2120 | int rc; |
| 2121 | |
| 2122 | QETH_CARD_TEXT(card, 2, "vniccreq"); |
| 2123 | |
| 2124 | /* get new buffer for request */ |
| 2125 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0); |
| 2126 | if (!iob) |
| 2127 | return -ENOMEM; |
| 2128 | |
| 2129 | /* create header for request */ |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 2130 | cmd = __ipa_cmd(iob); |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2131 | req = &cmd->data.vnicc; |
| 2132 | |
| 2133 | /* create sub command header for request */ |
| 2134 | req->sub_hdr.data_length = sizeof(req->sub_hdr); |
| 2135 | req->sub_hdr.sub_command = cbctl->sub_cmd; |
| 2136 | |
| 2137 | /* create sub command specific request fields */ |
| 2138 | switch (cbctl->sub_cmd) { |
| 2139 | case IPA_VNICC_QUERY_CHARS: |
| 2140 | break; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2141 | case IPA_VNICC_QUERY_CMDS: |
| 2142 | req->sub_hdr.data_length += sizeof(req->query_cmds); |
| 2143 | req->query_cmds.vnic_char = cbctl->param.vnic_char; |
| 2144 | break; |
| 2145 | case IPA_VNICC_ENABLE: |
| 2146 | case IPA_VNICC_DISABLE: |
| 2147 | req->sub_hdr.data_length += sizeof(req->set_char); |
| 2148 | req->set_char.vnic_char = cbctl->param.vnic_char; |
| 2149 | break; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2150 | case IPA_VNICC_SET_TIMEOUT: |
| 2151 | req->getset_timeout.timeout = cbctl->param.timeout; |
| 2152 | /* fallthrough */ |
| 2153 | case IPA_VNICC_GET_TIMEOUT: |
| 2154 | req->sub_hdr.data_length += sizeof(req->getset_timeout); |
| 2155 | req->getset_timeout.vnic_char = cbctl->param.vnic_char; |
| 2156 | break; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2157 | default: |
| 2158 | qeth_release_buffer(iob->channel, iob); |
| 2159 | return -EOPNOTSUPP; |
| 2160 | } |
| 2161 | |
| 2162 | /* send request */ |
| 2163 | rc = qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, |
| 2164 | (void *) cbctl); |
| 2165 | |
| 2166 | return qeth_l2_vnicc_makerc(card, rc); |
| 2167 | } |
| 2168 | |
| 2169 | /* VNICC query VNIC characteristics request */ |
| 2170 | static int qeth_l2_vnicc_query_chars(struct qeth_card *card) |
| 2171 | { |
| 2172 | struct _qeth_l2_vnicc_request_cbctl cbctl; |
| 2173 | |
| 2174 | /* prepare callback control */ |
| 2175 | cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS; |
| 2176 | |
| 2177 | QETH_CARD_TEXT(card, 2, "vniccqch"); |
| 2178 | return qeth_l2_vnicc_request(card, &cbctl); |
| 2179 | } |
| 2180 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2181 | /* VNICC query sub commands request */ |
| 2182 | static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char, |
| 2183 | u32 *sup_cmds) |
| 2184 | { |
| 2185 | struct _qeth_l2_vnicc_request_cbctl cbctl; |
| 2186 | |
| 2187 | /* prepare callback control */ |
| 2188 | cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS; |
| 2189 | cbctl.param.vnic_char = vnic_char; |
| 2190 | cbctl.result.sup_cmds = sup_cmds; |
| 2191 | |
| 2192 | QETH_CARD_TEXT(card, 2, "vniccqcm"); |
| 2193 | return qeth_l2_vnicc_request(card, &cbctl); |
| 2194 | } |
| 2195 | |
| 2196 | /* VNICC enable/disable characteristic request */ |
| 2197 | static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char, |
| 2198 | u32 cmd) |
| 2199 | { |
| 2200 | struct _qeth_l2_vnicc_request_cbctl cbctl; |
| 2201 | |
| 2202 | /* prepare callback control */ |
| 2203 | cbctl.sub_cmd = cmd; |
| 2204 | cbctl.param.vnic_char = vnic_char; |
| 2205 | |
| 2206 | QETH_CARD_TEXT(card, 2, "vniccedc"); |
| 2207 | return qeth_l2_vnicc_request(card, &cbctl); |
| 2208 | } |
| 2209 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2210 | /* VNICC get/set timeout for characteristic request */ |
| 2211 | static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc, |
| 2212 | u32 cmd, u32 *timeout) |
| 2213 | { |
| 2214 | struct _qeth_l2_vnicc_request_cbctl cbctl; |
| 2215 | |
| 2216 | /* prepare callback control */ |
| 2217 | cbctl.sub_cmd = cmd; |
| 2218 | cbctl.param.vnic_char = vnicc; |
| 2219 | if (cmd == IPA_VNICC_SET_TIMEOUT) |
| 2220 | cbctl.param.timeout = *timeout; |
| 2221 | if (cmd == IPA_VNICC_GET_TIMEOUT) |
| 2222 | cbctl.result.timeout = timeout; |
| 2223 | |
| 2224 | QETH_CARD_TEXT(card, 2, "vniccgst"); |
| 2225 | return qeth_l2_vnicc_request(card, &cbctl); |
| 2226 | } |
| 2227 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2228 | /* set current VNICC flag state; called from sysfs store function */ |
| 2229 | int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state) |
| 2230 | { |
| 2231 | int rc = 0; |
| 2232 | u32 cmd; |
| 2233 | |
| 2234 | QETH_CARD_TEXT(card, 2, "vniccsch"); |
| 2235 | |
| 2236 | /* do not change anything if BridgePort is enabled */ |
| 2237 | if (qeth_bridgeport_is_in_use(card)) |
| 2238 | return -EBUSY; |
| 2239 | |
| 2240 | /* check if characteristic and enable/disable are supported */ |
| 2241 | if (!(card->options.vnicc.sup_chars & vnicc) || |
| 2242 | !(card->options.vnicc.set_char_sup & vnicc)) |
| 2243 | return -EOPNOTSUPP; |
| 2244 | |
| 2245 | /* set enable/disable command and store wanted characteristic */ |
| 2246 | if (state) { |
| 2247 | cmd = IPA_VNICC_ENABLE; |
| 2248 | card->options.vnicc.wanted_chars |= vnicc; |
| 2249 | } else { |
| 2250 | cmd = IPA_VNICC_DISABLE; |
| 2251 | card->options.vnicc.wanted_chars &= ~vnicc; |
| 2252 | } |
| 2253 | |
| 2254 | /* do we need to do anything? */ |
| 2255 | if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars) |
| 2256 | return rc; |
| 2257 | |
| 2258 | /* if card is not ready, simply stop here */ |
| 2259 | if (!qeth_card_hw_is_reachable(card)) { |
| 2260 | if (state) |
| 2261 | card->options.vnicc.cur_chars |= vnicc; |
| 2262 | else |
| 2263 | card->options.vnicc.cur_chars &= ~vnicc; |
| 2264 | return rc; |
| 2265 | } |
| 2266 | |
| 2267 | rc = qeth_l2_vnicc_set_char(card, vnicc, cmd); |
| 2268 | if (rc) |
| 2269 | card->options.vnicc.wanted_chars = |
| 2270 | card->options.vnicc.cur_chars; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2271 | else { |
| 2272 | /* successful online VNICC change; handle special cases */ |
| 2273 | if (state && vnicc == QETH_VNICC_RX_BCAST) |
| 2274 | card->options.vnicc.rx_bcast_enabled = true; |
| 2275 | if (!state && vnicc == QETH_VNICC_LEARNING) |
| 2276 | qeth_l2_vnicc_recover_timeout(card, vnicc, |
| 2277 | &card->options.vnicc.learning_timeout); |
| 2278 | } |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2279 | |
| 2280 | return rc; |
| 2281 | } |
| 2282 | |
| 2283 | /* get current VNICC flag state; called from sysfs show function */ |
| 2284 | int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state) |
| 2285 | { |
| 2286 | int rc = 0; |
| 2287 | |
| 2288 | QETH_CARD_TEXT(card, 2, "vniccgch"); |
| 2289 | |
| 2290 | /* do not get anything if BridgePort is enabled */ |
| 2291 | if (qeth_bridgeport_is_in_use(card)) |
| 2292 | return -EBUSY; |
| 2293 | |
| 2294 | /* check if characteristic is supported */ |
| 2295 | if (!(card->options.vnicc.sup_chars & vnicc)) |
| 2296 | return -EOPNOTSUPP; |
| 2297 | |
| 2298 | /* if card is ready, query current VNICC state */ |
| 2299 | if (qeth_card_hw_is_reachable(card)) |
| 2300 | rc = qeth_l2_vnicc_query_chars(card); |
| 2301 | |
| 2302 | *state = (card->options.vnicc.cur_chars & vnicc) ? true : false; |
| 2303 | return rc; |
| 2304 | } |
| 2305 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2306 | /* set VNICC timeout; called from sysfs store function. Currently, only learning |
| 2307 | * supports timeout |
| 2308 | */ |
| 2309 | int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout) |
| 2310 | { |
| 2311 | int rc = 0; |
| 2312 | |
| 2313 | QETH_CARD_TEXT(card, 2, "vniccsto"); |
| 2314 | |
| 2315 | /* do not change anything if BridgePort is enabled */ |
| 2316 | if (qeth_bridgeport_is_in_use(card)) |
| 2317 | return -EBUSY; |
| 2318 | |
| 2319 | /* check if characteristic and set_timeout are supported */ |
| 2320 | if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || |
| 2321 | !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) |
| 2322 | return -EOPNOTSUPP; |
| 2323 | |
| 2324 | /* do we need to do anything? */ |
| 2325 | if (card->options.vnicc.learning_timeout == timeout) |
| 2326 | return rc; |
| 2327 | |
| 2328 | /* if card is not ready, simply store the value internally and return */ |
| 2329 | if (!qeth_card_hw_is_reachable(card)) { |
| 2330 | card->options.vnicc.learning_timeout = timeout; |
| 2331 | return rc; |
| 2332 | } |
| 2333 | |
| 2334 | /* send timeout value to card; if successful, store value internally */ |
| 2335 | rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, |
| 2336 | IPA_VNICC_SET_TIMEOUT, &timeout); |
| 2337 | if (!rc) |
| 2338 | card->options.vnicc.learning_timeout = timeout; |
| 2339 | |
| 2340 | return rc; |
| 2341 | } |
| 2342 | |
| 2343 | /* get current VNICC timeout; called from sysfs show function. Currently, only |
| 2344 | * learning supports timeout |
| 2345 | */ |
| 2346 | int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout) |
| 2347 | { |
| 2348 | int rc = 0; |
| 2349 | |
| 2350 | QETH_CARD_TEXT(card, 2, "vniccgto"); |
| 2351 | |
| 2352 | /* do not get anything if BridgePort is enabled */ |
| 2353 | if (qeth_bridgeport_is_in_use(card)) |
| 2354 | return -EBUSY; |
| 2355 | |
| 2356 | /* check if characteristic and get_timeout are supported */ |
| 2357 | if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) || |
| 2358 | !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING)) |
| 2359 | return -EOPNOTSUPP; |
| 2360 | /* if card is ready, get timeout. Otherwise, just return stored value */ |
| 2361 | *timeout = card->options.vnicc.learning_timeout; |
| 2362 | if (qeth_card_hw_is_reachable(card)) |
| 2363 | rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING, |
| 2364 | IPA_VNICC_GET_TIMEOUT, |
| 2365 | timeout); |
| 2366 | |
| 2367 | return rc; |
| 2368 | } |
| 2369 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2370 | /* check if VNICC is currently enabled */ |
| 2371 | bool qeth_l2_vnicc_is_in_use(struct qeth_card *card) |
| 2372 | { |
| 2373 | /* if everything is turned off, VNICC is not active */ |
| 2374 | if (!card->options.vnicc.cur_chars) |
| 2375 | return false; |
| 2376 | /* default values are only OK if rx_bcast was not enabled by user |
| 2377 | * or the card is offline. |
| 2378 | */ |
| 2379 | if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) { |
| 2380 | if (!card->options.vnicc.rx_bcast_enabled || |
| 2381 | !qeth_card_hw_is_reachable(card)) |
| 2382 | return false; |
| 2383 | } |
| 2384 | return true; |
| 2385 | } |
| 2386 | |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2387 | /* recover user timeout setting */ |
| 2388 | static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc, |
| 2389 | u32 *timeout) |
| 2390 | { |
| 2391 | if (card->options.vnicc.sup_chars & vnicc && |
| 2392 | card->options.vnicc.getset_timeout_sup & vnicc && |
| 2393 | !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT, |
| 2394 | timeout)) |
| 2395 | return false; |
| 2396 | *timeout = QETH_VNICC_DEFAULT_TIMEOUT; |
| 2397 | return true; |
| 2398 | } |
| 2399 | |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2400 | /* recover user characteristic setting */ |
| 2401 | static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc, |
| 2402 | bool enable) |
| 2403 | { |
| 2404 | u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE; |
| 2405 | |
| 2406 | if (card->options.vnicc.sup_chars & vnicc && |
| 2407 | card->options.vnicc.set_char_sup & vnicc && |
| 2408 | !qeth_l2_vnicc_set_char(card, vnicc, cmd)) |
| 2409 | return false; |
| 2410 | card->options.vnicc.wanted_chars &= ~vnicc; |
| 2411 | card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc; |
| 2412 | return true; |
| 2413 | } |
| 2414 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2415 | /* (re-)initialize VNICC */ |
| 2416 | static void qeth_l2_vnicc_init(struct qeth_card *card) |
| 2417 | { |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2418 | u32 *timeout = &card->options.vnicc.learning_timeout; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2419 | unsigned int chars_len, i; |
| 2420 | unsigned long chars_tmp; |
| 2421 | u32 sup_cmds, vnicc; |
| 2422 | bool enable, error; |
| 2423 | |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2424 | QETH_CARD_TEXT(card, 2, "vniccini"); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2425 | /* reset rx_bcast */ |
| 2426 | card->options.vnicc.rx_bcast_enabled = 0; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2427 | /* initial query and storage of VNIC characteristics */ |
| 2428 | if (qeth_l2_vnicc_query_chars(card)) { |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2429 | if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT || |
| 2430 | *timeout != QETH_VNICC_DEFAULT_TIMEOUT) |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2431 | dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); |
| 2432 | /* fail quietly if user didn't change the default config */ |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2433 | card->options.vnicc.sup_chars = 0; |
| 2434 | card->options.vnicc.cur_chars = 0; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2435 | card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; |
| 2436 | return; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2437 | } |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2438 | /* get supported commands for each supported characteristic */ |
| 2439 | chars_tmp = card->options.vnicc.sup_chars; |
| 2440 | chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE; |
| 2441 | for_each_set_bit(i, &chars_tmp, chars_len) { |
| 2442 | vnicc = BIT(i); |
| 2443 | qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds); |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2444 | if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) || |
| 2445 | !(sup_cmds & IPA_VNICC_GET_TIMEOUT)) |
| 2446 | card->options.vnicc.getset_timeout_sup &= ~vnicc; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2447 | if (!(sup_cmds & IPA_VNICC_ENABLE) || |
| 2448 | !(sup_cmds & IPA_VNICC_DISABLE)) |
| 2449 | card->options.vnicc.set_char_sup &= ~vnicc; |
| 2450 | } |
| 2451 | /* enforce assumed default values and recover settings, if changed */ |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2452 | error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING, |
| 2453 | timeout); |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2454 | chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT; |
| 2455 | chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE; |
| 2456 | chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE; |
| 2457 | for_each_set_bit(i, &chars_tmp, chars_len) { |
| 2458 | vnicc = BIT(i); |
| 2459 | enable = card->options.vnicc.wanted_chars & vnicc; |
| 2460 | error |= qeth_l2_vnicc_recover_char(card, vnicc, enable); |
| 2461 | } |
| 2462 | if (error) |
| 2463 | dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n"); |
| 2464 | } |
| 2465 | |
| 2466 | /* configure default values of VNIC characteristics */ |
| 2467 | static void qeth_l2_vnicc_set_defaults(struct qeth_card *card) |
| 2468 | { |
| 2469 | /* characteristics values */ |
| 2470 | card->options.vnicc.sup_chars = QETH_VNICC_ALL; |
| 2471 | card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2472 | card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2473 | /* supported commands */ |
| 2474 | card->options.vnicc.set_char_sup = QETH_VNICC_ALL; |
Hans Wippel | 349d13d | 2017-09-18 21:18:16 +0200 | [diff] [blame] | 2475 | card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING; |
Hans Wippel | caa1f0b | 2017-09-18 21:18:15 +0200 | [diff] [blame] | 2476 | /* settings wanted by users */ |
| 2477 | card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT; |
Hans Wippel | a45b3fa | 2017-09-18 21:18:14 +0200 | [diff] [blame] | 2478 | } |
| 2479 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2480 | module_init(qeth_l2_init); |
| 2481 | module_exit(qeth_l2_exit); |
| 2482 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 2483 | MODULE_DESCRIPTION("qeth layer 2 discipline"); |
| 2484 | MODULE_LICENSE("GPL"); |