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