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