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