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