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