Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1 | /* |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2007, 2009 |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3 | * Author(s): Utz Bacher <utz.bacher@de.ibm.com>, |
| 4 | * Frank Pavlic <fpavlic@de.ibm.com>, |
| 5 | * Thomas Spatzier <tspat@de.ibm.com>, |
| 6 | * Frank Blaschka <frank.blaschka@de.ibm.com> |
| 7 | */ |
| 8 | |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 9 | #define KMSG_COMPONENT "qeth" |
| 10 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 11 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/moduleparam.h> |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 19 | #include <linux/ip.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> |
| 23 | #include <linux/string.h> |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 24 | #include <asm/setup.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 25 | #include "qeth_core.h" |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 26 | #include "qeth_l2.h" |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 27 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 28 | static int qeth_l2_set_offline(struct ccwgroup_device *); |
| 29 | static int qeth_l2_stop(struct net_device *); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 30 | static void qeth_l2_set_rx_mode(struct net_device *); |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 31 | static void qeth_bridgeport_query_support(struct qeth_card *card); |
| 32 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 33 | struct qeth_ipa_cmd *cmd); |
| 34 | static void qeth_bridge_host_event(struct qeth_card *card, |
| 35 | struct qeth_ipa_cmd *cmd); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 36 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 37 | static int qeth_l2_verify_dev(struct net_device *dev) |
| 38 | { |
| 39 | struct qeth_card *card; |
| 40 | unsigned long flags; |
| 41 | int rc = 0; |
| 42 | |
| 43 | read_lock_irqsave(&qeth_core_card_list.rwlock, flags); |
| 44 | list_for_each_entry(card, &qeth_core_card_list.list, list) { |
| 45 | if (card->dev == dev) { |
| 46 | rc = QETH_REAL_CARD; |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); |
| 51 | |
| 52 | return rc; |
| 53 | } |
| 54 | |
| 55 | static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no) |
| 56 | { |
| 57 | struct qeth_card *card; |
| 58 | struct net_device *ndev; |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 59 | __u16 temp_dev_no; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 60 | unsigned long flags; |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 61 | struct ccw_dev_id read_devid; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 62 | |
| 63 | ndev = NULL; |
| 64 | memcpy(&temp_dev_no, read_dev_no, 2); |
| 65 | read_lock_irqsave(&qeth_core_card_list.rwlock, flags); |
| 66 | list_for_each_entry(card, &qeth_core_card_list.list, list) { |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 67 | ccw_device_get_id(CARD_RDEV(card), &read_devid); |
| 68 | if (read_devid.devno == temp_dev_no) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 69 | ndev = card->dev; |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); |
| 74 | return ndev; |
| 75 | } |
| 76 | |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 77 | static int qeth_setdel_makerc(struct qeth_card *card, int retcode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 78 | { |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 79 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 80 | |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 81 | if (retcode) |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 82 | QETH_CARD_TEXT_(card, 2, "err%04x", retcode); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 83 | switch (retcode) { |
| 84 | case IPA_RC_SUCCESS: |
| 85 | rc = 0; |
| 86 | break; |
| 87 | case IPA_RC_L2_UNSUPPORTED_CMD: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 88 | rc = -EOPNOTSUPP; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 89 | break; |
| 90 | case IPA_RC_L2_ADDR_TABLE_FULL: |
| 91 | rc = -ENOSPC; |
| 92 | break; |
| 93 | case IPA_RC_L2_DUP_MAC: |
| 94 | case IPA_RC_L2_DUP_LAYER3_MAC: |
| 95 | rc = -EEXIST; |
| 96 | break; |
| 97 | case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: |
| 98 | case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: |
| 99 | rc = -EPERM; |
| 100 | break; |
| 101 | case IPA_RC_L2_MAC_NOT_FOUND: |
| 102 | rc = -ENOENT; |
| 103 | break; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 104 | case -ENOMEM: |
| 105 | rc = -ENOMEM; |
| 106 | break; |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 107 | default: |
| 108 | rc = -EIO; |
| 109 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 110 | } |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 111 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Julian Wiedmann | ac988d7 | 2017-01-12 15:48:41 +0100 | [diff] [blame] | 114 | static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, |
| 115 | enum qeth_ipa_cmds ipacmd) |
| 116 | { |
| 117 | struct qeth_ipa_cmd *cmd; |
| 118 | struct qeth_cmd_buffer *iob; |
| 119 | |
| 120 | QETH_CARD_TEXT(card, 2, "L2sdmac"); |
| 121 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 122 | if (!iob) |
| 123 | return -ENOMEM; |
| 124 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 125 | cmd->data.setdelmac.mac_length = OSA_ADDR_LEN; |
| 126 | memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN); |
| 127 | return qeth_setdel_makerc(card, qeth_send_ipa_cmd(card, iob, |
| 128 | NULL, NULL)); |
| 129 | } |
| 130 | |
| 131 | static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) |
| 132 | { |
| 133 | int rc; |
| 134 | |
| 135 | QETH_CARD_TEXT(card, 2, "L2Setmac"); |
| 136 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC); |
| 137 | if (rc == 0) { |
| 138 | card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; |
| 139 | memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN); |
| 140 | dev_info(&card->gdev->dev, |
| 141 | "MAC address %pM successfully registered on device %s\n", |
| 142 | card->dev->dev_addr, card->dev->name); |
| 143 | } else { |
| 144 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
| 145 | switch (rc) { |
| 146 | case -EEXIST: |
| 147 | dev_warn(&card->gdev->dev, |
| 148 | "MAC address %pM already exists\n", mac); |
| 149 | break; |
| 150 | case -EPERM: |
| 151 | dev_warn(&card->gdev->dev, |
| 152 | "MAC address %pM is not authorized\n", mac); |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | return rc; |
| 157 | } |
| 158 | |
| 159 | static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac) |
| 160 | { |
| 161 | int rc; |
| 162 | |
| 163 | QETH_CARD_TEXT(card, 2, "L2Delmac"); |
| 164 | if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) |
| 165 | return 0; |
| 166 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC); |
| 167 | if (rc == 0) |
| 168 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
| 169 | return rc; |
| 170 | } |
| 171 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 172 | static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac) |
| 173 | { |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 174 | int rc; |
| 175 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 176 | QETH_CARD_TEXT(card, 2, "L2Sgmac"); |
Julian Wiedmann | 754e0b8 | 2017-01-12 15:48:39 +0100 | [diff] [blame] | 177 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 178 | if (rc == -EEXIST) |
| 179 | QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n", |
| 180 | mac, QETH_CARD_IFNAME(card)); |
| 181 | else if (rc) |
| 182 | QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n", |
| 183 | mac, QETH_CARD_IFNAME(card), rc); |
| 184 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac) |
| 188 | { |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 189 | int rc; |
| 190 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 191 | QETH_CARD_TEXT(card, 2, "L2Dgmac"); |
Julian Wiedmann | 754e0b8 | 2017-01-12 15:48:39 +0100 | [diff] [blame] | 192 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 193 | if (rc) |
| 194 | QETH_DBF_MESSAGE(2, |
| 195 | "Could not delete group MAC %pM on %s: %d\n", |
| 196 | mac, QETH_CARD_IFNAME(card), rc); |
| 197 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 200 | static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 201 | { |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 202 | if (mac->is_uc) { |
Julian Wiedmann | 979d792 | 2017-01-12 15:48:40 +0100 | [diff] [blame] | 203 | return qeth_l2_send_setdelmac(card, mac->mac_addr, |
Julian Wiedmann | 754e0b8 | 2017-01-12 15:48:39 +0100 | [diff] [blame] | 204 | IPA_CMD_SETVMAC); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 205 | } else { |
Julian Wiedmann | 979d792 | 2017-01-12 15:48:40 +0100 | [diff] [blame] | 206 | return qeth_l2_send_setgroupmac(card, mac->mac_addr); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 207 | } |
Julian Wiedmann | 979d792 | 2017-01-12 15:48:40 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static int qeth_l2_remove_mac(struct qeth_card *card, struct qeth_mac *mac) |
| 211 | { |
| 212 | if (mac->is_uc) { |
| 213 | return qeth_l2_send_setdelmac(card, mac->mac_addr, |
| 214 | IPA_CMD_DELVMAC); |
| 215 | } else { |
| 216 | return qeth_l2_send_delgroupmac(card, mac->mac_addr); |
| 217 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Julian Wiedmann | c07cbf2 | 2017-01-12 15:48:37 +0100 | [diff] [blame] | 220 | static void qeth_l2_del_all_macs(struct qeth_card *card) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 221 | { |
| 222 | struct qeth_mac *mac; |
| 223 | struct hlist_node *tmp; |
| 224 | int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 225 | |
| 226 | spin_lock_bh(&card->mclock); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 227 | hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 228 | hash_del(&mac->hnode); |
| 229 | kfree(mac); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 230 | } |
| 231 | spin_unlock_bh(&card->mclock); |
| 232 | } |
| 233 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame^] | 234 | 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] | 235 | { |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 236 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 237 | return RTN_UNSPEC; |
| 238 | if (is_broadcast_ether_addr(skb->data)) |
| 239 | return RTN_BROADCAST; |
| 240 | if (is_multicast_ether_addr(skb->data)) |
| 241 | return RTN_MULTICAST; |
| 242 | return RTN_UNSPEC; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame^] | 245 | static void qeth_l2_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr, |
| 246 | struct sk_buff *skb) |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 247 | { |
| 248 | struct iphdr *iph = ip_hdr(skb); |
| 249 | |
| 250 | /* tcph->check contains already the pseudo hdr checksum |
| 251 | * so just set the header flags |
| 252 | */ |
| 253 | if (iph->protocol == IPPROTO_UDP) |
| 254 | hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP; |
| 255 | hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ | |
| 256 | QETH_HDR_EXT_CSUM_HDR_REQ; |
| 257 | iph->check = 0; |
| 258 | if (card->options.performance_stats) |
| 259 | card->perf_stats.tx_csum++; |
| 260 | } |
| 261 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 262 | static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
Stefan Raspl | 4393407 | 2014-03-19 07:58:01 +0100 | [diff] [blame] | 263 | struct sk_buff *skb, int cast_type) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 264 | { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 265 | struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 266 | |
| 267 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 268 | hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; |
| 269 | |
| 270 | /* set byte byte 3 to casting flags */ |
| 271 | if (cast_type == RTN_MULTICAST) |
| 272 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; |
| 273 | else if (cast_type == RTN_BROADCAST) |
| 274 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; |
| 275 | else |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 276 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 277 | |
Julian Wiedmann | 2aedd56 | 2017-04-11 16:11:15 +0200 | [diff] [blame] | 278 | hdr->hdr.l2.pkt_length = skb->len - sizeof(struct qeth_hdr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 279 | /* VSWITCH relies on the VLAN |
| 280 | * information to be present in |
| 281 | * the QDIO header */ |
| 282 | if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { |
| 283 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; |
| 284 | hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, |
| 289 | struct qeth_reply *reply, unsigned long data) |
| 290 | { |
| 291 | struct qeth_ipa_cmd *cmd; |
| 292 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 293 | QETH_CARD_TEXT(card, 2, "L2sdvcb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 294 | cmd = (struct qeth_ipa_cmd *) data; |
| 295 | if (cmd->hdr.return_code) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 296 | QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. " |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 297 | "Continuing\n", cmd->data.setdelvlan.vlan_id, |
| 298 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 299 | QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); |
| 300 | QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 301 | } |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, |
| 306 | enum qeth_ipa_cmds ipacmd) |
| 307 | { |
| 308 | struct qeth_ipa_cmd *cmd; |
| 309 | struct qeth_cmd_buffer *iob; |
| 310 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 311 | QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 312 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 313 | if (!iob) |
| 314 | return -ENOMEM; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 315 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 316 | cmd->data.setdelvlan.vlan_id = i; |
| 317 | return qeth_send_ipa_cmd(card, iob, |
| 318 | qeth_l2_send_setdelvlan_cb, NULL); |
| 319 | } |
| 320 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 321 | static void qeth_l2_process_vlans(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 322 | { |
| 323 | struct qeth_vlan_vid *id; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 324 | QETH_CARD_TEXT(card, 3, "L2prcvln"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 325 | spin_lock_bh(&card->vlanlock); |
| 326 | list_for_each_entry(id, &card->vid_list, list) { |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 327 | qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 328 | } |
| 329 | spin_unlock_bh(&card->vlanlock); |
| 330 | } |
| 331 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 332 | static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, |
| 333 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 334 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 335 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 336 | struct qeth_vlan_vid *id; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 337 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 338 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 339 | QETH_CARD_TEXT_(card, 4, "aid:%d", vid); |
Ursula Braun | 10651db | 2010-10-01 02:51:13 +0000 | [diff] [blame] | 340 | if (!vid) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 341 | return 0; |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 342 | if (card->info.type == QETH_CARD_TYPE_OSM) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 343 | QETH_CARD_TEXT(card, 3, "aidOSM"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 344 | return 0; |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 345 | } |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 346 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 347 | QETH_CARD_TEXT(card, 3, "aidREC"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 348 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 349 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 350 | id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC); |
| 351 | if (id) { |
| 352 | id->vid = vid; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 353 | rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); |
| 354 | if (rc) { |
| 355 | kfree(id); |
| 356 | return rc; |
| 357 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 358 | spin_lock_bh(&card->vlanlock); |
| 359 | list_add_tail(&id->list, &card->vid_list); |
| 360 | spin_unlock_bh(&card->vlanlock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 361 | } else { |
| 362 | return -ENOMEM; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 363 | } |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 364 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 367 | static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, |
| 368 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 369 | { |
| 370 | struct qeth_vlan_vid *id, *tmpid = NULL; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 371 | struct qeth_card *card = dev->ml_priv; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 372 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 373 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 374 | QETH_CARD_TEXT_(card, 4, "kid:%d", vid); |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 375 | if (card->info.type == QETH_CARD_TYPE_OSM) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 376 | QETH_CARD_TEXT(card, 3, "kidOSM"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 377 | return 0; |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 378 | } |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 379 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 380 | QETH_CARD_TEXT(card, 3, "kidREC"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 381 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 382 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 383 | spin_lock_bh(&card->vlanlock); |
| 384 | list_for_each_entry(id, &card->vid_list, list) { |
| 385 | if (id->vid == vid) { |
| 386 | list_del(&id->list); |
| 387 | tmpid = id; |
| 388 | break; |
| 389 | } |
| 390 | } |
| 391 | spin_unlock_bh(&card->vlanlock); |
| 392 | if (tmpid) { |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 393 | rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 394 | kfree(tmpid); |
| 395 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 396 | qeth_l2_set_rx_mode(card->dev); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 397 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Peter Senna Tschudin | b2f4de8 | 2015-08-04 17:11:47 +0200 | [diff] [blame] | 400 | 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] | 401 | { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 402 | QETH_DBF_TEXT(SETUP , 2, "stopcard"); |
| 403 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 404 | |
| 405 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 406 | if (card->read.state == CH_STATE_UP && |
| 407 | card->write.state == CH_STATE_UP && |
| 408 | (card->state == CARD_STATE_UP)) { |
| 409 | if (recovery_mode && |
| 410 | card->info.type != QETH_CARD_TYPE_OSN) { |
| 411 | qeth_l2_stop(card->dev); |
| 412 | } else { |
| 413 | rtnl_lock(); |
| 414 | dev_close(card->dev); |
| 415 | rtnl_unlock(); |
| 416 | } |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 417 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 418 | card->state = CARD_STATE_SOFTSETUP; |
| 419 | } |
| 420 | if (card->state == CARD_STATE_SOFTSETUP) { |
Julian Wiedmann | c07cbf2 | 2017-01-12 15:48:37 +0100 | [diff] [blame] | 421 | qeth_l2_del_all_macs(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 422 | qeth_clear_ipacmd_list(card); |
| 423 | card->state = CARD_STATE_HARDSETUP; |
| 424 | } |
| 425 | if (card->state == CARD_STATE_HARDSETUP) { |
| 426 | qeth_qdio_clear_card(card, 0); |
| 427 | qeth_clear_qdio_buffers(card); |
| 428 | qeth_clear_working_pool_list(card); |
| 429 | card->state = CARD_STATE_DOWN; |
| 430 | } |
| 431 | if (card->state == CARD_STATE_DOWN) { |
| 432 | qeth_clear_cmd_buffers(&card->read); |
| 433 | qeth_clear_cmd_buffers(&card->write); |
| 434 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 435 | } |
| 436 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 437 | static int qeth_l2_process_inbound_buffer(struct qeth_card *card, |
| 438 | int budget, int *done) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 439 | { |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 440 | int work_done = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 441 | struct sk_buff *skb; |
| 442 | struct qeth_hdr *hdr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 443 | unsigned int len; |
| 444 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 445 | *done = 0; |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 446 | WARN_ON_ONCE(!budget); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 447 | while (budget) { |
| 448 | skb = qeth_core_get_next_skb(card, |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 449 | &card->qdio.in_q->bufs[card->rx.b_index], |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 450 | &card->rx.b_element, &card->rx.e_offset, &hdr); |
| 451 | if (!skb) { |
| 452 | *done = 1; |
| 453 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 454 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 455 | skb->dev = card->dev; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 456 | switch (hdr->hdr.l2.id) { |
| 457 | case QETH_HEADER_TYPE_LAYER2: |
| 458 | skb->pkt_type = PACKET_HOST; |
| 459 | skb->protocol = eth_type_trans(skb, skb->dev); |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 460 | if ((card->dev->features & NETIF_F_RXCSUM) |
| 461 | && ((hdr->hdr.l2.flags[1] & |
| 462 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 463 | QETH_HDR_EXT_CSUM_TRANSP_REQ)) == |
| 464 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 465 | QETH_HDR_EXT_CSUM_TRANSP_REQ))) |
| 466 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 467 | else |
| 468 | skb->ip_summed = CHECKSUM_NONE; |
Ursula Braun | 1288372 | 2008-04-01 10:26:56 +0200 | [diff] [blame] | 469 | if (skb->protocol == htons(ETH_P_802_2)) |
| 470 | *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 471 | len = skb->len; |
Thomas Richter | 9abfa8c | 2015-10-06 15:12:27 +0200 | [diff] [blame] | 472 | napi_gro_receive(&card->napi, skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 473 | break; |
| 474 | case QETH_HEADER_TYPE_OSN: |
Ursula Braun | 2d488c2 | 2008-10-24 11:16:55 +0200 | [diff] [blame] | 475 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 476 | skb_push(skb, sizeof(struct qeth_hdr)); |
| 477 | skb_copy_to_linear_data(skb, hdr, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 478 | sizeof(struct qeth_hdr)); |
Ursula Braun | 2d488c2 | 2008-10-24 11:16:55 +0200 | [diff] [blame] | 479 | len = skb->len; |
| 480 | card->osn_info.data_cb(skb); |
| 481 | break; |
| 482 | } |
| 483 | /* else unknown */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 484 | default: |
| 485 | dev_kfree_skb_any(skb); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 486 | QETH_CARD_TEXT(card, 3, "inbunkno"); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 487 | QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 488 | continue; |
| 489 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 490 | work_done++; |
| 491 | budget--; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 492 | card->stats.rx_packets++; |
| 493 | card->stats.rx_bytes += len; |
| 494 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 495 | return work_done; |
| 496 | } |
| 497 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 498 | static int qeth_l2_request_initial_mac(struct qeth_card *card) |
| 499 | { |
| 500 | int rc = 0; |
| 501 | char vendor_pre[] = {0x02, 0x00, 0x00}; |
| 502 | |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 503 | QETH_DBF_TEXT(SETUP, 2, "l2reqmac"); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 504 | QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 505 | |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 506 | if (MACHINE_IS_VM) { |
| 507 | rc = qeth_vm_request_mac(card); |
| 508 | if (!rc) |
| 509 | goto out; |
| 510 | QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n", |
| 511 | CARD_BUS_ID(card), rc); |
| 512 | QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc); |
| 513 | /* fall back to alternative mechanism: */ |
| 514 | } |
| 515 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 516 | if (card->info.type == QETH_CARD_TYPE_IQD || |
| 517 | card->info.type == QETH_CARD_TYPE_OSM || |
| 518 | card->info.type == QETH_CARD_TYPE_OSX || |
| 519 | card->info.guestlan) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 520 | rc = qeth_setadpparms_change_macaddr(card); |
| 521 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 522 | QETH_DBF_MESSAGE(2, "couldn't get MAC address on " |
| 523 | "device %s: x%x\n", CARD_BUS_ID(card), rc); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 524 | QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 525 | return rc; |
| 526 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 527 | } else { |
Joe Perches | 1833611 | 2012-07-12 22:33:10 -0700 | [diff] [blame] | 528 | eth_random_addr(card->dev->dev_addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 529 | memcpy(card->dev->dev_addr, vendor_pre, 3); |
| 530 | } |
Julian Wiedmann | ec61bd2 | 2017-06-20 16:00:34 +0200 | [diff] [blame] | 531 | out: |
| 532 | 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] | 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static int qeth_l2_set_mac_address(struct net_device *dev, void *p) |
| 537 | { |
| 538 | struct sockaddr *addr = p; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 539 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 540 | int rc = 0; |
| 541 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 542 | QETH_CARD_TEXT(card, 3, "setmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 543 | |
| 544 | if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 545 | QETH_CARD_TEXT(card, 3, "setmcINV"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 546 | return -EOPNOTSUPP; |
| 547 | } |
| 548 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 549 | if (card->info.type == QETH_CARD_TYPE_OSN || |
| 550 | card->info.type == QETH_CARD_TYPE_OSM || |
| 551 | card->info.type == QETH_CARD_TYPE_OSX) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 552 | QETH_CARD_TEXT(card, 3, "setmcTYP"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 553 | return -EOPNOTSUPP; |
| 554 | } |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 555 | QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 556 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 557 | QETH_CARD_TEXT(card, 3, "setmcREC"); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 558 | return -ERESTARTSYS; |
| 559 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 560 | rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]); |
Eugene Crosser | efbbc1d | 2015-01-21 13:39:09 +0100 | [diff] [blame] | 561 | if (!rc || (rc == -ENOENT)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 562 | rc = qeth_l2_send_setmac(card, addr->sa_data); |
Ursula Braun | e0a8114 | 2012-03-07 02:06:28 +0000 | [diff] [blame] | 563 | return rc ? -EINVAL : 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 564 | } |
| 565 | |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 566 | static void qeth_promisc_to_bridge(struct qeth_card *card) |
| 567 | { |
| 568 | struct net_device *dev = card->dev; |
| 569 | enum qeth_ipa_promisc_modes promisc_mode; |
| 570 | int role; |
| 571 | int rc; |
| 572 | |
| 573 | QETH_CARD_TEXT(card, 3, "pmisc2br"); |
| 574 | |
| 575 | if (!card->options.sbp.reflect_promisc) |
| 576 | return; |
| 577 | promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON |
| 578 | : SET_PROMISC_MODE_OFF; |
| 579 | if (promisc_mode == card->info.promisc_mode) |
| 580 | return; |
| 581 | |
| 582 | if (promisc_mode == SET_PROMISC_MODE_ON) { |
| 583 | if (card->options.sbp.reflect_promisc_primary) |
| 584 | role = QETH_SBP_ROLE_PRIMARY; |
| 585 | else |
| 586 | role = QETH_SBP_ROLE_SECONDARY; |
| 587 | } else |
| 588 | role = QETH_SBP_ROLE_NONE; |
| 589 | |
| 590 | rc = qeth_bridgeport_setrole(card, role); |
| 591 | QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x", |
| 592 | (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc); |
| 593 | if (!rc) { |
| 594 | card->options.sbp.role = role; |
| 595 | card->info.promisc_mode = promisc_mode; |
| 596 | } |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 597 | |
| 598 | } |
| 599 | /* New MAC address is added to the hash table and marked to be written on card |
| 600 | * only if there is not in the hash table storage already |
| 601 | * |
| 602 | */ |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame^] | 603 | static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha, |
| 604 | u8 is_uc) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 605 | { |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame^] | 606 | u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2])); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 607 | struct qeth_mac *mac; |
| 608 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame^] | 609 | hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) { |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 610 | if (is_uc == mac->is_uc && |
| 611 | !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 612 | mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 613 | return; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC); |
| 618 | |
| 619 | if (!mac) |
| 620 | return; |
| 621 | |
| 622 | memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN); |
| 623 | mac->is_uc = is_uc; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 624 | mac->disp_flag = QETH_DISP_ADDR_ADD; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 625 | |
Julian Wiedmann | cef6ff22 | 2017-08-15 17:02:46 +0200 | [diff] [blame^] | 626 | hash_add(card->mac_htable, &mac->hnode, mac_hash); |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 627 | } |
| 628 | |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 629 | static void qeth_l2_set_rx_mode(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 630 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 631 | struct qeth_card *card = dev->ml_priv; |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 632 | struct netdev_hw_addr *ha; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 633 | struct qeth_mac *mac; |
| 634 | struct hlist_node *tmp; |
| 635 | int i; |
| 636 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 637 | |
| 638 | if (card->info.type == QETH_CARD_TYPE_OSN) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 639 | return; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 640 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 641 | QETH_CARD_TEXT(card, 3, "setmulti"); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 642 | if (qeth_threads_running(card, QETH_RECOVER_THREAD) && |
| 643 | (card->state != CARD_STATE_UP)) |
| 644 | return; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 645 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 646 | spin_lock_bh(&card->mclock); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 647 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 648 | netdev_for_each_mc_addr(ha, dev) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 649 | qeth_l2_add_mac(card, ha, 0); |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 650 | |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 651 | netdev_for_each_uc_addr(ha, dev) |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 652 | qeth_l2_add_mac(card, ha, 1); |
| 653 | |
| 654 | hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 655 | if (mac->disp_flag == QETH_DISP_ADDR_DELETE) { |
Julian Wiedmann | 979d792 | 2017-01-12 15:48:40 +0100 | [diff] [blame] | 656 | qeth_l2_remove_mac(card, mac); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 657 | hash_del(&mac->hnode); |
| 658 | kfree(mac); |
| 659 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 660 | } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) { |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 661 | rc = qeth_l2_write_mac(card, mac); |
| 662 | if (rc) { |
| 663 | hash_del(&mac->hnode); |
| 664 | kfree(mac); |
| 665 | } else |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 666 | mac->disp_flag = QETH_DISP_ADDR_DELETE; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 667 | } else |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 668 | mac->disp_flag = QETH_DISP_ADDR_DELETE; |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 669 | } |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 670 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 671 | spin_unlock_bh(&card->mclock); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 672 | |
Eugene Crosser | 0db587b | 2015-05-18 14:27:55 +0200 | [diff] [blame] | 673 | if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 674 | qeth_setadp_promisc_mode(card); |
| 675 | else |
| 676 | qeth_promisc_to_bridge(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Julian Wiedmann | e38db6b | 2017-04-11 16:11:14 +0200 | [diff] [blame] | 679 | static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, |
| 680 | struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 681 | { |
| 682 | int rc; |
| 683 | struct qeth_hdr *hdr = NULL; |
| 684 | int elements = 0; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 685 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 686 | struct sk_buff *new_skb = skb; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 687 | int cast_type = qeth_l2_get_cast_type(card, skb); |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 688 | struct qeth_qdio_out_q *queue; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 689 | int tx_bytes = skb->len; |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 690 | int data_offset = -1; |
| 691 | int elements_needed = 0; |
| 692 | int hd_len = 0; |
Julian Wiedmann | 886e197 | 2017-08-15 17:02:39 +0200 | [diff] [blame] | 693 | unsigned int nr_frags; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 694 | |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 695 | if (card->qdio.do_prio_queueing || (cast_type && |
| 696 | card->info.is_multicast_different)) |
| 697 | queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb, |
| 698 | qeth_get_ip_version(skb), cast_type)]; |
| 699 | else |
| 700 | queue = card->qdio.out_qs[card->qdio.default_out_queue]; |
| 701 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 702 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 703 | card->stats.tx_carrier_errors++; |
| 704 | goto tx_drop; |
| 705 | } |
| 706 | |
| 707 | if ((card->info.type == QETH_CARD_TYPE_OSN) && |
| 708 | (skb->protocol == htons(ETH_P_IPV6))) |
| 709 | goto tx_drop; |
| 710 | |
| 711 | if (card->options.performance_stats) { |
| 712 | card->perf_stats.outbound_cnt++; |
| 713 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 714 | } |
| 715 | netif_stop_queue(dev); |
| 716 | |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 717 | /* fix hardware limitation: as long as we do not have sbal |
| 718 | * chaining we can not send long frag lists |
| 719 | */ |
| 720 | if ((card->info.type != QETH_CARD_TYPE_IQD) && |
Julian Wiedmann | 7d969d2 | 2017-03-23 14:55:08 +0100 | [diff] [blame] | 721 | !qeth_get_elements_no(card, new_skb, 0, 0)) { |
Eugene Crosser | 6059c90 | 2016-06-16 16:18:57 +0200 | [diff] [blame] | 722 | int lin_rc = skb_linearize(new_skb); |
| 723 | |
| 724 | if (card->options.performance_stats) { |
| 725 | if (lin_rc) |
| 726 | card->perf_stats.tx_linfail++; |
| 727 | else |
| 728 | card->perf_stats.tx_lin++; |
| 729 | } |
| 730 | if (lin_rc) |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 731 | goto tx_drop; |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 732 | } |
Julian Wiedmann | 886e197 | 2017-08-15 17:02:39 +0200 | [diff] [blame] | 733 | nr_frags = skb_shinfo(new_skb)->nr_frags; |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 734 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 735 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 736 | hdr = (struct qeth_hdr *)skb->data; |
| 737 | else { |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 738 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 739 | new_skb = skb; |
| 740 | data_offset = ETH_HLEN; |
| 741 | hd_len = ETH_HLEN; |
| 742 | hdr = kmem_cache_alloc(qeth_core_header_cache, |
| 743 | GFP_ATOMIC); |
| 744 | if (!hdr) |
| 745 | goto tx_drop; |
| 746 | elements_needed++; |
Stefan Raspl | 4393407 | 2014-03-19 07:58:01 +0100 | [diff] [blame] | 747 | qeth_l2_fill_header(card, hdr, new_skb, cast_type); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 748 | hdr->hdr.l2.pkt_length = new_skb->len; |
Julian Wiedmann | f8eb493 | 2017-08-15 17:02:45 +0200 | [diff] [blame] | 749 | skb_copy_from_linear_data(new_skb, |
| 750 | ((char *)hdr) + sizeof(*hdr), |
| 751 | ETH_HLEN); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 752 | } else { |
| 753 | /* create a clone with writeable headroom */ |
| 754 | new_skb = skb_realloc_headroom(skb, |
Frank Blaschka | f90b744 | 2008-04-24 10:15:24 +0200 | [diff] [blame] | 755 | sizeof(struct qeth_hdr)); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 756 | if (!new_skb) |
| 757 | goto tx_drop; |
Johannes Berg | d58ff35 | 2017-06-16 14:29:23 +0200 | [diff] [blame] | 758 | hdr = skb_push(new_skb, sizeof(struct qeth_hdr)); |
Stefan Raspl | 4393407 | 2014-03-19 07:58:01 +0100 | [diff] [blame] | 759 | qeth_l2_fill_header(card, hdr, new_skb, cast_type); |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 760 | if (new_skb->ip_summed == CHECKSUM_PARTIAL) |
| 761 | qeth_l2_hdr_csum(card, hdr, new_skb); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 762 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Julian Wiedmann | 7d969d2 | 2017-03-23 14:55:08 +0100 | [diff] [blame] | 765 | elements = qeth_get_elements_no(card, new_skb, elements_needed, |
| 766 | (data_offset > 0) ? data_offset : 0); |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 767 | if (!elements) { |
| 768 | if (data_offset >= 0) |
| 769 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 770 | goto tx_drop; |
Frank Blaschka | f61a0d0 | 2009-03-24 20:57:15 +0000 | [diff] [blame] | 771 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 772 | |
Frank Blaschka | 51aa165 | 2010-06-21 22:57:10 +0000 | [diff] [blame] | 773 | if (card->info.type != QETH_CARD_TYPE_IQD) { |
Stefan Raspl | d4ae1f5 | 2013-04-22 01:12:29 +0000 | [diff] [blame] | 774 | if (qeth_hdr_chk_and_bounce(new_skb, &hdr, |
Frank Blaschka | 51aa165 | 2010-06-21 22:57:10 +0000 | [diff] [blame] | 775 | sizeof(struct qeth_hdr_layer2))) |
| 776 | goto tx_drop; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 777 | rc = qeth_do_send_packet(card, queue, new_skb, hdr, |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 778 | elements); |
Frank Blaschka | 51aa165 | 2010-06-21 22:57:10 +0000 | [diff] [blame] | 779 | } else |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 780 | rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr, |
Julian Wiedmann | 4e8d7e6 | 2017-04-11 16:11:13 +0200 | [diff] [blame] | 781 | data_offset, hd_len); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 782 | if (!rc) { |
| 783 | card->stats.tx_packets++; |
| 784 | card->stats.tx_bytes += tx_bytes; |
Julian Wiedmann | 886e197 | 2017-08-15 17:02:39 +0200 | [diff] [blame] | 785 | if (card->options.performance_stats && nr_frags) { |
| 786 | card->perf_stats.sg_skbs_sent++; |
| 787 | /* nr_frags + skb->data */ |
| 788 | card->perf_stats.sg_frags_sent += nr_frags + 1; |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 789 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 790 | if (new_skb != skb) |
| 791 | dev_kfree_skb_any(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 792 | rc = NETDEV_TX_OK; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 793 | } else { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 794 | if (data_offset >= 0) |
| 795 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 796 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 797 | if (rc == -EBUSY) { |
| 798 | if (new_skb != skb) |
| 799 | dev_kfree_skb_any(new_skb); |
| 800 | return NETDEV_TX_BUSY; |
| 801 | } else |
| 802 | goto tx_drop; |
| 803 | } |
| 804 | |
| 805 | netif_wake_queue(dev); |
| 806 | if (card->options.performance_stats) |
| 807 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 808 | card->perf_stats.outbound_start_time; |
| 809 | return rc; |
| 810 | |
| 811 | tx_drop: |
| 812 | card->stats.tx_dropped++; |
| 813 | card->stats.tx_errors++; |
| 814 | if ((new_skb != skb) && new_skb) |
| 815 | dev_kfree_skb_any(new_skb); |
| 816 | dev_kfree_skb_any(skb); |
Frank Blaschka | d0ec0f5 | 2008-06-06 12:37:48 +0200 | [diff] [blame] | 817 | netif_wake_queue(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 818 | return NETDEV_TX_OK; |
| 819 | } |
| 820 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 821 | static int __qeth_l2_open(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 822 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 823 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 824 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 825 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 826 | QETH_CARD_TEXT(card, 4, "qethopen"); |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 827 | if (card->state == CARD_STATE_UP) |
| 828 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 829 | if (card->state != CARD_STATE_SOFTSETUP) |
| 830 | return -ENODEV; |
| 831 | |
| 832 | if ((card->info.type != QETH_CARD_TYPE_OSN) && |
| 833 | (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 834 | QETH_CARD_TEXT(card, 4, "nomacadr"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 835 | return -EPERM; |
| 836 | } |
| 837 | card->data.state = CH_STATE_UP; |
| 838 | card->state = CARD_STATE_UP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 839 | netif_start_queue(dev); |
| 840 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 841 | if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) { |
| 842 | napi_enable(&card->napi); |
| 843 | napi_schedule(&card->napi); |
| 844 | } else |
| 845 | rc = -EIO; |
| 846 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 847 | } |
| 848 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 849 | static int qeth_l2_open(struct net_device *dev) |
| 850 | { |
| 851 | struct qeth_card *card = dev->ml_priv; |
| 852 | |
| 853 | QETH_CARD_TEXT(card, 5, "qethope_"); |
| 854 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
| 855 | QETH_CARD_TEXT(card, 3, "openREC"); |
| 856 | return -ERESTARTSYS; |
| 857 | } |
| 858 | return __qeth_l2_open(dev); |
| 859 | } |
| 860 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 861 | static int qeth_l2_stop(struct net_device *dev) |
| 862 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 863 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 864 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 865 | QETH_CARD_TEXT(card, 4, "qethstop"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 866 | netif_tx_disable(dev); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 867 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 868 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 869 | napi_disable(&card->napi); |
| 870 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 874 | static const struct device_type qeth_l2_devtype = { |
| 875 | .name = "qeth_layer2", |
| 876 | .groups = qeth_l2_attr_groups, |
| 877 | }; |
| 878 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 879 | static int qeth_l2_probe_device(struct ccwgroup_device *gdev) |
| 880 | { |
| 881 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | 9111e78 | 2017-05-10 19:07:51 +0200 | [diff] [blame] | 882 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 883 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 884 | if (gdev->dev.type == &qeth_generic_devtype) { |
| 885 | rc = qeth_l2_create_device_attributes(&gdev->dev); |
| 886 | if (rc) |
| 887 | return rc; |
| 888 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 889 | INIT_LIST_HEAD(&card->vid_list); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 890 | hash_init(card->mac_htable); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 891 | card->options.layer2 = 1; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 892 | card->info.hwtrap = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) |
| 897 | { |
| 898 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 899 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 900 | if (cgdev->dev.type == &qeth_generic_devtype) |
| 901 | qeth_l2_remove_device_attributes(&cgdev->dev); |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 902 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 903 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 904 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 905 | if (cgdev->state == CCWGROUP_ONLINE) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 906 | qeth_l2_set_offline(cgdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 907 | |
| 908 | if (card->dev) { |
Ursula Braun | 7831b4f | 2016-07-04 14:07:16 +0200 | [diff] [blame] | 909 | netif_napi_del(&card->napi); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 910 | unregister_netdev(card->dev); |
| 911 | card->dev = NULL; |
| 912 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 916 | static const struct ethtool_ops qeth_l2_ethtool_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 917 | .get_link = ethtool_op_get_link, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 918 | .get_strings = qeth_core_get_strings, |
| 919 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 920 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 921 | .get_drvinfo = qeth_core_get_drvinfo, |
Julian Wiedmann | 993e19c | 2017-04-11 16:11:17 +0200 | [diff] [blame] | 922 | .get_link_ksettings = qeth_core_ethtool_get_link_ksettings, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 923 | }; |
| 924 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 925 | static const struct ethtool_ops qeth_l2_osn_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 926 | .get_strings = qeth_core_get_strings, |
| 927 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 928 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 929 | .get_drvinfo = qeth_core_get_drvinfo, |
| 930 | }; |
| 931 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 932 | static const struct net_device_ops qeth_l2_netdev_ops = { |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 933 | .ndo_open = qeth_l2_open, |
| 934 | .ndo_stop = qeth_l2_stop, |
| 935 | .ndo_get_stats = qeth_get_stats, |
| 936 | .ndo_start_xmit = qeth_l2_hard_start_xmit, |
| 937 | .ndo_validate_addr = eth_validate_addr, |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 938 | .ndo_set_rx_mode = qeth_l2_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 939 | .ndo_do_ioctl = qeth_do_ioctl, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 940 | .ndo_set_mac_address = qeth_l2_set_mac_address, |
| 941 | .ndo_change_mtu = qeth_change_mtu, |
| 942 | .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, |
| 943 | .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, |
| 944 | .ndo_tx_timeout = qeth_tx_timeout, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 945 | .ndo_fix_features = qeth_fix_features, |
| 946 | .ndo_set_features = qeth_set_features |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 947 | }; |
| 948 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 949 | static int qeth_l2_setup_netdev(struct qeth_card *card) |
| 950 | { |
| 951 | switch (card->info.type) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 952 | case QETH_CARD_TYPE_IQD: |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 953 | card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN, |
| 954 | ether_setup); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 955 | break; |
| 956 | case QETH_CARD_TYPE_OSN: |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 957 | card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN, |
| 958 | ether_setup); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 959 | break; |
| 960 | default: |
| 961 | card->dev = alloc_etherdev(0); |
| 962 | } |
| 963 | |
| 964 | if (!card->dev) |
| 965 | return -ENODEV; |
| 966 | |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 967 | card->dev->ml_priv = card; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 968 | card->dev->watchdog_timeo = QETH_TX_TIMEOUT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 969 | card->dev->mtu = card->info.initial_mtu; |
Jarod Wilson | 46b3ef4 | 2016-10-20 13:55:23 -0400 | [diff] [blame] | 970 | card->dev->min_mtu = 64; |
| 971 | card->dev->max_mtu = ETH_MAX_MTU; |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 972 | card->dev->netdev_ops = &qeth_l2_netdev_ops; |
Julian Wiedmann | 25e2c34 | 2017-05-10 19:07:53 +0200 | [diff] [blame] | 973 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 974 | card->dev->ethtool_ops = &qeth_l2_osn_ops; |
| 975 | card->dev->flags |= IFF_NOARP; |
| 976 | } else { |
| 977 | card->dev->ethtool_ops = &qeth_l2_ethtool_ops; |
| 978 | } |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 979 | card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 980 | if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 981 | card->dev->hw_features = NETIF_F_SG; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 982 | card->dev->vlan_features = NETIF_F_SG; |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 983 | /* OSA 3S and earlier has no RX/TX support */ |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 984 | if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 985 | card->dev->hw_features |= NETIF_F_IP_CSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 986 | card->dev->vlan_features |= NETIF_F_IP_CSUM; |
| 987 | } |
| 988 | if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 989 | card->dev->hw_features |= NETIF_F_RXCSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 990 | card->dev->vlan_features |= NETIF_F_RXCSUM; |
| 991 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 992 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 993 | card->info.broadcast_capable = 1; |
| 994 | qeth_l2_request_initial_mac(card); |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 995 | card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) * |
| 996 | PAGE_SIZE; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 997 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 998 | netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); |
Ursula Braun | e5ebe63 | 2015-12-11 12:27:55 +0100 | [diff] [blame] | 999 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1000 | return register_netdev(card->dev); |
| 1001 | } |
| 1002 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1003 | static int qeth_l2_start_ipassists(struct qeth_card *card) |
| 1004 | { |
| 1005 | /* configure isolation level */ |
| 1006 | if (qeth_set_access_ctrl_online(card, 0)) |
| 1007 | return -ENODEV; |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1008 | return 0; |
| 1009 | } |
| 1010 | |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1011 | static void qeth_l2_trace_features(struct qeth_card *card) |
| 1012 | { |
| 1013 | QETH_CARD_TEXT(card, 2, "l2featur"); |
| 1014 | QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, |
| 1015 | sizeof(card->options.sbp.supported_funcs)); |
| 1016 | } |
| 1017 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1018 | static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
| 1019 | { |
| 1020 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1021 | int rc = 0; |
| 1022 | enum qeth_card_states recover_flag; |
| 1023 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1024 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1025 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1026 | QETH_DBF_TEXT(SETUP, 2, "setonlin"); |
| 1027 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1028 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1029 | recover_flag = card->state; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1030 | rc = qeth_core_hardsetup_card(card); |
| 1031 | if (rc) { |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1032 | QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1033 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1034 | goto out_remove; |
| 1035 | } |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1036 | qeth_bridgeport_query_support(card); |
| 1037 | if (card->options.sbp.supported_funcs) |
| 1038 | dev_info(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1039 | "The device represents a Bridge Capable Port\n"); |
Stefan Raspl | 395672e0 | 2012-11-19 02:46:49 +0000 | [diff] [blame] | 1040 | qeth_trace_features(card); |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1041 | qeth_l2_trace_features(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1042 | |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1043 | if (!card->dev && qeth_l2_setup_netdev(card)) { |
| 1044 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1045 | goto out_remove; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1046 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1047 | |
| 1048 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 1049 | qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); |
| 1050 | |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1051 | if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { |
| 1052 | if (card->info.hwtrap && |
| 1053 | qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) |
| 1054 | card->info.hwtrap = 0; |
| 1055 | } else |
| 1056 | card->info.hwtrap = 0; |
| 1057 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1058 | qeth_l2_setup_bridgeport_attrs(card); |
| 1059 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1060 | card->state = CARD_STATE_HARDSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1061 | memset(&card->rx, 0, sizeof(struct qeth_rx)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1062 | qeth_print_status_message(card); |
| 1063 | |
| 1064 | /* softsetup */ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1065 | QETH_DBF_TEXT(SETUP, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1066 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1067 | if ((card->info.type == QETH_CARD_TYPE_OSD) || |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1068 | (card->info.type == QETH_CARD_TYPE_OSX)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1069 | rc = qeth_l2_start_ipassists(card); |
| 1070 | if (rc) |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1071 | goto out_remove; |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1072 | } |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1073 | |
| 1074 | if (card->info.type != QETH_CARD_TYPE_OSN && |
| 1075 | card->info.type != QETH_CARD_TYPE_OSM) |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 1076 | qeth_l2_process_vlans(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1077 | |
| 1078 | netif_tx_disable(card->dev); |
| 1079 | |
| 1080 | rc = qeth_init_qdio_queues(card); |
| 1081 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1082 | QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1083 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1084 | goto out_remove; |
| 1085 | } |
| 1086 | card->state = CARD_STATE_SOFTSETUP; |
Ursula Braun | 2b6203b | 2010-11-26 02:41:19 +0000 | [diff] [blame] | 1087 | if (card->lan_online) |
| 1088 | netif_carrier_on(card->dev); |
| 1089 | else |
| 1090 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1091 | |
| 1092 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1093 | if (recover_flag == CARD_STATE_RECOVER) { |
| 1094 | if (recovery_mode && |
| 1095 | card->info.type != QETH_CARD_TYPE_OSN) { |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 1096 | __qeth_l2_open(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1097 | } else { |
| 1098 | rtnl_lock(); |
| 1099 | dev_open(card->dev); |
| 1100 | rtnl_unlock(); |
| 1101 | } |
| 1102 | /* this also sets saved unicast addresses */ |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 1103 | qeth_l2_set_rx_mode(card->dev); |
Hans Wippel | e830baa | 2016-09-15 14:39:21 +0200 | [diff] [blame] | 1104 | rtnl_lock(); |
| 1105 | qeth_recover_features(card->dev); |
| 1106 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1107 | } |
| 1108 | /* let user_space know that device is online */ |
| 1109 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1110 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1111 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1112 | return 0; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1113 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1114 | out_remove: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1115 | qeth_l2_stop_card(card, 0); |
| 1116 | ccw_device_set_offline(CARD_DDEV(card)); |
| 1117 | ccw_device_set_offline(CARD_WDEV(card)); |
| 1118 | ccw_device_set_offline(CARD_RDEV(card)); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 1119 | qdio_free(CARD_DDEV(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1120 | if (recover_flag == CARD_STATE_RECOVER) |
| 1121 | card->state = CARD_STATE_RECOVER; |
| 1122 | else |
| 1123 | card->state = CARD_STATE_DOWN; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1124 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1125 | mutex_unlock(&card->discipline_mutex); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1126 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static int qeth_l2_set_online(struct ccwgroup_device *gdev) |
| 1130 | { |
| 1131 | return __qeth_l2_set_online(gdev, 0); |
| 1132 | } |
| 1133 | |
| 1134 | static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev, |
| 1135 | int recovery_mode) |
| 1136 | { |
| 1137 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 1138 | int rc = 0, rc2 = 0, rc3 = 0; |
| 1139 | enum qeth_card_states recover_flag; |
| 1140 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1141 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1142 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1143 | QETH_DBF_TEXT(SETUP, 3, "setoffl"); |
| 1144 | QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1145 | |
| 1146 | if (card->dev && netif_carrier_ok(card->dev)) |
| 1147 | netif_carrier_off(card->dev); |
| 1148 | recover_flag = card->state; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1149 | if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { |
| 1150 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
| 1151 | card->info.hwtrap = 1; |
| 1152 | } |
Ursula Braun | 0f5623c | 2008-10-24 11:16:52 +0200 | [diff] [blame] | 1153 | qeth_l2_stop_card(card, recovery_mode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1154 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 1155 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 1156 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 1157 | if (!rc) |
| 1158 | rc = (rc2) ? rc2 : rc3; |
| 1159 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1160 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 1161 | qdio_free(CARD_DDEV(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1162 | if (recover_flag == CARD_STATE_UP) |
| 1163 | card->state = CARD_STATE_RECOVER; |
| 1164 | /* let user_space know that device is offline */ |
| 1165 | kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1166 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1167 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static int qeth_l2_set_offline(struct ccwgroup_device *cgdev) |
| 1172 | { |
| 1173 | return __qeth_l2_set_offline(cgdev, 0); |
| 1174 | } |
| 1175 | |
| 1176 | static int qeth_l2_recover(void *ptr) |
| 1177 | { |
| 1178 | struct qeth_card *card; |
| 1179 | int rc = 0; |
| 1180 | |
| 1181 | card = (struct qeth_card *) ptr; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1182 | QETH_CARD_TEXT(card, 2, "recover1"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1183 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 1184 | return 0; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1185 | QETH_CARD_TEXT(card, 2, "recover2"); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1186 | dev_warn(&card->gdev->dev, |
| 1187 | "A recovery process has been started for the device\n"); |
Stefan Raspl | 65d8013 | 2013-04-07 22:19:27 +0000 | [diff] [blame] | 1188 | qeth_set_recovery_task(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1189 | __qeth_l2_set_offline(card->gdev, 1); |
| 1190 | rc = __qeth_l2_set_online(card->gdev, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1191 | if (!rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1192 | dev_info(&card->gdev->dev, |
| 1193 | "Device successfully recovered!\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1194 | else { |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1195 | qeth_close_dev(card); |
| 1196 | dev_warn(&card->gdev->dev, "The qeth device driver " |
Stefan Raspl | 2efaf5f | 2012-10-15 19:21:18 +0000 | [diff] [blame] | 1197 | "failed to recover an error on the device\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1198 | } |
Stefan Raspl | 65d8013 | 2013-04-07 22:19:27 +0000 | [diff] [blame] | 1199 | qeth_clear_recovery_task(card); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1200 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 1201 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1202 | return 0; |
| 1203 | } |
| 1204 | |
| 1205 | static int __init qeth_l2_init(void) |
| 1206 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1207 | pr_info("register layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1208 | return 0; |
| 1209 | } |
| 1210 | |
| 1211 | static void __exit qeth_l2_exit(void) |
| 1212 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1213 | pr_info("unregister layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1214 | } |
| 1215 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1216 | static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) |
| 1217 | { |
| 1218 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1219 | |
| 1220 | if (card->dev) |
| 1221 | netif_device_detach(card->dev); |
| 1222 | qeth_set_allowed_threads(card, 0, 1); |
| 1223 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 1224 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1225 | return 0; |
| 1226 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1227 | if (card->info.hwtrap) |
| 1228 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1229 | __qeth_l2_set_offline(card->gdev, 1); |
| 1230 | } else |
| 1231 | __qeth_l2_set_offline(card->gdev, 0); |
| 1232 | return 0; |
| 1233 | } |
| 1234 | |
| 1235 | static int qeth_l2_pm_resume(struct ccwgroup_device *gdev) |
| 1236 | { |
| 1237 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1238 | int rc = 0; |
| 1239 | |
| 1240 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1241 | goto out; |
| 1242 | |
| 1243 | if (card->state == CARD_STATE_RECOVER) { |
| 1244 | rc = __qeth_l2_set_online(card->gdev, 1); |
| 1245 | if (rc) { |
Ursula Braun | 869da90 | 2010-03-08 20:36:56 +0000 | [diff] [blame] | 1246 | rtnl_lock(); |
| 1247 | dev_close(card->dev); |
| 1248 | rtnl_unlock(); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1249 | } |
| 1250 | } else |
| 1251 | rc = __qeth_l2_set_online(card->gdev, 0); |
| 1252 | out: |
| 1253 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1254 | if (card->dev) |
| 1255 | netif_device_attach(card->dev); |
| 1256 | if (rc) |
| 1257 | dev_warn(&card->gdev->dev, "The qeth device driver " |
| 1258 | "failed to recover an error on the device\n"); |
| 1259 | return rc; |
| 1260 | } |
| 1261 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1262 | /* Returns zero if the command is successfully "consumed" */ |
| 1263 | static int qeth_l2_control_event(struct qeth_card *card, |
| 1264 | struct qeth_ipa_cmd *cmd) |
| 1265 | { |
| 1266 | switch (cmd->hdr.command) { |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1267 | case IPA_CMD_SETBRIDGEPORT_OSA: |
| 1268 | case IPA_CMD_SETBRIDGEPORT_IQD: |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1269 | if (cmd->data.sbp.hdr.command_code == |
| 1270 | IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { |
| 1271 | qeth_bridge_state_change(card, cmd); |
| 1272 | return 0; |
| 1273 | } else |
| 1274 | return 1; |
| 1275 | case IPA_CMD_ADDRESS_CHANGE_NOTIF: |
| 1276 | qeth_bridge_host_event(card, cmd); |
| 1277 | return 0; |
| 1278 | default: |
| 1279 | return 1; |
| 1280 | } |
| 1281 | } |
| 1282 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1283 | struct qeth_discipline qeth_l2_discipline = { |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 1284 | .devtype = &qeth_l2_devtype, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1285 | .start_poll = qeth_qdio_start_poll, |
| 1286 | .input_handler = (qdio_handler_t *) qeth_qdio_input_handler, |
| 1287 | .output_handler = (qdio_handler_t *) qeth_qdio_output_handler, |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 1288 | .process_rx_buffer = qeth_l2_process_inbound_buffer, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1289 | .recover = qeth_l2_recover, |
| 1290 | .setup = qeth_l2_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1291 | .remove = qeth_l2_remove_device, |
| 1292 | .set_online = qeth_l2_set_online, |
| 1293 | .set_offline = qeth_l2_set_offline, |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1294 | .freeze = qeth_l2_pm_suspend, |
| 1295 | .thaw = qeth_l2_pm_resume, |
| 1296 | .restore = qeth_l2_pm_resume, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 1297 | .do_ioctl = NULL, |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1298 | .control_event_handler = qeth_l2_control_event, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1299 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1300 | EXPORT_SYMBOL_GPL(qeth_l2_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1301 | |
| 1302 | static int qeth_osn_send_control_data(struct qeth_card *card, int len, |
| 1303 | struct qeth_cmd_buffer *iob) |
| 1304 | { |
| 1305 | unsigned long flags; |
| 1306 | int rc = 0; |
| 1307 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1308 | QETH_CARD_TEXT(card, 5, "osndctrd"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1309 | |
| 1310 | wait_event(card->wait_q, |
| 1311 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
| 1312 | qeth_prepare_control_data(card, len, iob); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1313 | QETH_CARD_TEXT(card, 6, "osnoirqp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1314 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1315 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1316 | (addr_t) iob, 0, 0); |
| 1317 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1318 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 1319 | QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1320 | "ccw_device_start rc = %i\n", rc); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1321 | QETH_CARD_TEXT_(card, 2, " err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1322 | qeth_release_buffer(iob->channel, iob); |
| 1323 | atomic_set(&card->write.irq_pending, 0); |
| 1324 | wake_up(&card->wait_q); |
| 1325 | } |
| 1326 | return rc; |
| 1327 | } |
| 1328 | |
| 1329 | static int qeth_osn_send_ipa_cmd(struct qeth_card *card, |
| 1330 | struct qeth_cmd_buffer *iob, int data_len) |
| 1331 | { |
| 1332 | u16 s1, s2; |
| 1333 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1334 | QETH_CARD_TEXT(card, 4, "osndipa"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1335 | |
| 1336 | qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); |
| 1337 | s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); |
| 1338 | s2 = (u16)data_len; |
| 1339 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 1340 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 1341 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 1342 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 1343 | return qeth_osn_send_control_data(card, s1, iob); |
| 1344 | } |
| 1345 | |
| 1346 | int qeth_osn_assist(struct net_device *dev, void *data, int data_len) |
| 1347 | { |
| 1348 | struct qeth_cmd_buffer *iob; |
| 1349 | struct qeth_card *card; |
| 1350 | int rc; |
| 1351 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1352 | if (!dev) |
| 1353 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1354 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1355 | if (!card) |
| 1356 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1357 | QETH_CARD_TEXT(card, 2, "osnsdmc"); |
Eugene Crosser | c352125 | 2015-01-16 14:05:47 +0100 | [diff] [blame] | 1358 | if (!qeth_card_hw_is_reachable(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1359 | return -ENODEV; |
| 1360 | iob = qeth_wait_for_buffer(&card->write); |
| 1361 | memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); |
| 1362 | rc = qeth_osn_send_ipa_cmd(card, iob, data_len); |
| 1363 | return rc; |
| 1364 | } |
| 1365 | EXPORT_SYMBOL(qeth_osn_assist); |
| 1366 | |
| 1367 | int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, |
| 1368 | int (*assist_cb)(struct net_device *, void *), |
| 1369 | int (*data_cb)(struct sk_buff *)) |
| 1370 | { |
| 1371 | struct qeth_card *card; |
| 1372 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1373 | *dev = qeth_l2_netdev_by_devno(read_dev_no); |
| 1374 | if (*dev == NULL) |
| 1375 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1376 | card = (*dev)->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1377 | if (!card) |
| 1378 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1379 | QETH_CARD_TEXT(card, 2, "osnreg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1380 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 1381 | return -EINVAL; |
| 1382 | card->osn_info.assist_cb = assist_cb; |
| 1383 | card->osn_info.data_cb = data_cb; |
| 1384 | return 0; |
| 1385 | } |
| 1386 | EXPORT_SYMBOL(qeth_osn_register); |
| 1387 | |
| 1388 | void qeth_osn_deregister(struct net_device *dev) |
| 1389 | { |
| 1390 | struct qeth_card *card; |
| 1391 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1392 | if (!dev) |
| 1393 | return; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1394 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1395 | if (!card) |
| 1396 | return; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1397 | QETH_CARD_TEXT(card, 2, "osndereg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1398 | card->osn_info.assist_cb = NULL; |
| 1399 | card->osn_info.data_cb = NULL; |
| 1400 | return; |
| 1401 | } |
| 1402 | EXPORT_SYMBOL(qeth_osn_deregister); |
| 1403 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1404 | /* SETBRIDGEPORT support, async notifications */ |
| 1405 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1406 | enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; |
| 1407 | |
| 1408 | /** |
| 1409 | * qeth_bridge_emit_host_event() - bridgeport address change notification |
| 1410 | * @card: qeth_card structure pointer, for udev events. |
| 1411 | * @evtype: "normal" register/unregister, or abort, or reset. For abort |
| 1412 | * and reset token and addr_lnid are unused and may be NULL. |
| 1413 | * @code: event bitmask: high order bit 0x80 value 1 means removal of an |
| 1414 | * object, 0 - addition of an object. |
| 1415 | * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. |
| 1416 | * @token: "network token" structure identifying physical address of the port. |
| 1417 | * @addr_lnid: pointer to structure with MAC address and VLAN ID. |
| 1418 | * |
| 1419 | * This function is called when registrations and deregistrations are |
| 1420 | * reported by the hardware, and also when notifications are enabled - |
| 1421 | * for all currently registered addresses. |
| 1422 | */ |
| 1423 | static void qeth_bridge_emit_host_event(struct qeth_card *card, |
| 1424 | enum qeth_an_event_type evtype, |
| 1425 | u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid) |
| 1426 | { |
| 1427 | char str[7][32]; |
| 1428 | char *env[8]; |
| 1429 | int i = 0; |
| 1430 | |
| 1431 | switch (evtype) { |
| 1432 | case anev_reg_unreg: |
| 1433 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", |
| 1434 | (code & IPA_ADDR_CHANGE_CODE_REMOVAL) |
| 1435 | ? "deregister" : "register"); |
| 1436 | env[i] = str[i]; i++; |
| 1437 | if (code & IPA_ADDR_CHANGE_CODE_VLANID) { |
| 1438 | snprintf(str[i], sizeof(str[i]), "VLAN=%d", |
| 1439 | addr_lnid->lnid); |
| 1440 | env[i] = str[i]; i++; |
| 1441 | } |
| 1442 | if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { |
Eugene Crosser | 9846e70 | 2015-09-18 16:06:48 +0200 | [diff] [blame] | 1443 | snprintf(str[i], sizeof(str[i]), "MAC=%pM", |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1444 | addr_lnid->mac); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1445 | env[i] = str[i]; i++; |
| 1446 | } |
| 1447 | snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", |
| 1448 | token->cssid, token->ssid, token->devnum); |
| 1449 | env[i] = str[i]; i++; |
| 1450 | snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); |
| 1451 | env[i] = str[i]; i++; |
| 1452 | snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", |
| 1453 | token->chpid); |
| 1454 | env[i] = str[i]; i++; |
| 1455 | snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); |
| 1456 | env[i] = str[i]; i++; |
| 1457 | break; |
| 1458 | case anev_abort: |
| 1459 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); |
| 1460 | env[i] = str[i]; i++; |
| 1461 | break; |
| 1462 | case anev_reset: |
| 1463 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); |
| 1464 | env[i] = str[i]; i++; |
| 1465 | break; |
| 1466 | } |
| 1467 | env[i] = NULL; |
| 1468 | kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); |
| 1469 | } |
| 1470 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1471 | struct qeth_bridge_state_data { |
| 1472 | struct work_struct worker; |
| 1473 | struct qeth_card *card; |
| 1474 | struct qeth_sbp_state_change qports; |
| 1475 | }; |
| 1476 | |
| 1477 | static void qeth_bridge_state_change_worker(struct work_struct *work) |
| 1478 | { |
| 1479 | struct qeth_bridge_state_data *data = |
| 1480 | container_of(work, struct qeth_bridge_state_data, worker); |
| 1481 | /* We are only interested in the first entry - local port */ |
| 1482 | struct qeth_sbp_port_entry *entry = &data->qports.entry[0]; |
| 1483 | char env_locrem[32]; |
| 1484 | char env_role[32]; |
| 1485 | char env_state[32]; |
| 1486 | char *env[] = { |
| 1487 | env_locrem, |
| 1488 | env_role, |
| 1489 | env_state, |
| 1490 | NULL |
| 1491 | }; |
| 1492 | |
| 1493 | /* Role should not change by itself, but if it did, */ |
| 1494 | /* information from the hardware is authoritative. */ |
| 1495 | mutex_lock(&data->card->conf_mutex); |
| 1496 | data->card->options.sbp.role = entry->role; |
| 1497 | mutex_unlock(&data->card->conf_mutex); |
| 1498 | |
| 1499 | snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); |
| 1500 | snprintf(env_role, sizeof(env_role), "ROLE=%s", |
| 1501 | (entry->role == QETH_SBP_ROLE_NONE) ? "none" : |
| 1502 | (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : |
| 1503 | (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : |
| 1504 | "<INVALID>"); |
| 1505 | snprintf(env_state, sizeof(env_state), "STATE=%s", |
| 1506 | (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : |
| 1507 | (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" : |
| 1508 | (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" : |
| 1509 | "<INVALID>"); |
| 1510 | kobject_uevent_env(&data->card->gdev->dev.kobj, |
| 1511 | KOBJ_CHANGE, env); |
| 1512 | kfree(data); |
| 1513 | } |
| 1514 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1515 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 1516 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1517 | { |
| 1518 | struct qeth_sbp_state_change *qports = |
| 1519 | &cmd->data.sbp.data.state_change; |
| 1520 | struct qeth_bridge_state_data *data; |
| 1521 | int extrasize; |
| 1522 | |
| 1523 | QETH_CARD_TEXT(card, 2, "brstchng"); |
| 1524 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
Thomas Richter | 8a59314 | 2014-10-22 12:18:03 +0200 | [diff] [blame] | 1525 | QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1526 | return; |
| 1527 | } |
| 1528 | extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries; |
| 1529 | data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize, |
| 1530 | GFP_ATOMIC); |
| 1531 | if (!data) { |
| 1532 | QETH_CARD_TEXT(card, 2, "BPSalloc"); |
| 1533 | return; |
| 1534 | } |
| 1535 | INIT_WORK(&data->worker, qeth_bridge_state_change_worker); |
| 1536 | data->card = card; |
| 1537 | memcpy(&data->qports, qports, |
| 1538 | sizeof(struct qeth_sbp_state_change) + extrasize); |
| 1539 | queue_work(qeth_wq, &data->worker); |
| 1540 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1541 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1542 | struct qeth_bridge_host_data { |
| 1543 | struct work_struct worker; |
| 1544 | struct qeth_card *card; |
| 1545 | struct qeth_ipacmd_addr_change hostevs; |
| 1546 | }; |
| 1547 | |
| 1548 | static void qeth_bridge_host_event_worker(struct work_struct *work) |
| 1549 | { |
| 1550 | struct qeth_bridge_host_data *data = |
| 1551 | container_of(work, struct qeth_bridge_host_data, worker); |
| 1552 | int i; |
| 1553 | |
| 1554 | if (data->hostevs.lost_event_mask) { |
| 1555 | dev_info(&data->card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1556 | "Address notification from the Bridge Port stopped %s (%s)\n", |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1557 | data->card->dev->name, |
| 1558 | (data->hostevs.lost_event_mask == 0x01) |
| 1559 | ? "Overflow" |
| 1560 | : (data->hostevs.lost_event_mask == 0x02) |
| 1561 | ? "Bridge port state change" |
| 1562 | : "Unknown reason"); |
| 1563 | mutex_lock(&data->card->conf_mutex); |
| 1564 | data->card->options.sbp.hostnotification = 0; |
| 1565 | mutex_unlock(&data->card->conf_mutex); |
| 1566 | qeth_bridge_emit_host_event(data->card, anev_abort, |
| 1567 | 0, NULL, NULL); |
| 1568 | } else |
| 1569 | for (i = 0; i < data->hostevs.num_entries; i++) { |
| 1570 | struct qeth_ipacmd_addr_change_entry *entry = |
| 1571 | &data->hostevs.entry[i]; |
| 1572 | qeth_bridge_emit_host_event(data->card, |
| 1573 | anev_reg_unreg, |
| 1574 | entry->change_code, |
| 1575 | &entry->token, &entry->addr_lnid); |
| 1576 | } |
| 1577 | kfree(data); |
| 1578 | } |
| 1579 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1580 | static void qeth_bridge_host_event(struct qeth_card *card, |
| 1581 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1582 | { |
| 1583 | struct qeth_ipacmd_addr_change *hostevs = |
| 1584 | &cmd->data.addrchange; |
| 1585 | struct qeth_bridge_host_data *data; |
| 1586 | int extrasize; |
| 1587 | |
| 1588 | QETH_CARD_TEXT(card, 2, "brhostev"); |
| 1589 | if (cmd->hdr.return_code != 0x0000) { |
| 1590 | if (cmd->hdr.return_code == 0x0010) { |
| 1591 | if (hostevs->lost_event_mask == 0x00) |
| 1592 | hostevs->lost_event_mask = 0xff; |
| 1593 | } else { |
| 1594 | QETH_CARD_TEXT_(card, 2, "BPHe%04x", |
| 1595 | cmd->hdr.return_code); |
| 1596 | return; |
| 1597 | } |
| 1598 | } |
| 1599 | extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * |
| 1600 | hostevs->num_entries; |
| 1601 | data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize, |
| 1602 | GFP_ATOMIC); |
| 1603 | if (!data) { |
| 1604 | QETH_CARD_TEXT(card, 2, "BPHalloc"); |
| 1605 | return; |
| 1606 | } |
| 1607 | INIT_WORK(&data->worker, qeth_bridge_host_event_worker); |
| 1608 | data->card = card; |
| 1609 | memcpy(&data->hostevs, hostevs, |
| 1610 | sizeof(struct qeth_ipacmd_addr_change) + extrasize); |
| 1611 | queue_work(qeth_wq, &data->worker); |
| 1612 | } |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1613 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1614 | /* SETBRIDGEPORT support; sending commands */ |
| 1615 | |
| 1616 | struct _qeth_sbp_cbctl { |
| 1617 | u16 ipa_rc; |
| 1618 | u16 cmd_rc; |
| 1619 | union { |
| 1620 | u32 supported; |
| 1621 | struct { |
| 1622 | enum qeth_sbp_roles *role; |
| 1623 | enum qeth_sbp_states *state; |
| 1624 | } qports; |
| 1625 | } data; |
| 1626 | }; |
| 1627 | |
| 1628 | /** |
| 1629 | * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes. |
| 1630 | * @card: qeth_card structure pointer, for debug messages. |
| 1631 | * @cbctl: state structure with hardware return codes. |
| 1632 | * @setcmd: IPA command code |
| 1633 | * |
| 1634 | * Returns negative errno-compatible error indication or 0 on success. |
| 1635 | */ |
| 1636 | static int qeth_bridgeport_makerc(struct qeth_card *card, |
| 1637 | struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd) |
| 1638 | { |
| 1639 | int rc; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1640 | int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1641 | |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1642 | if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) || |
| 1643 | (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc))) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1644 | switch (cbctl->cmd_rc) { |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1645 | case IPA_RC_SUCCESS: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1646 | rc = 0; |
| 1647 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1648 | case IPA_RC_L2_UNSUPPORTED_CMD: |
| 1649 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1650 | rc = -EOPNOTSUPP; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1651 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1652 | case IPA_RC_SBP_OSA_NOT_CONFIGURED: |
| 1653 | case IPA_RC_SBP_IQD_NOT_CONFIGURED: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1654 | rc = -ENODEV; /* maybe not the best code here? */ |
| 1655 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1656 | "The device is not configured as a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1657 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1658 | case IPA_RC_SBP_OSA_OS_MISMATCH: |
| 1659 | case IPA_RC_SBP_IQD_OS_MISMATCH: |
Eugene Crosser | 1b05cf6 | 2016-06-16 16:18:51 +0200 | [diff] [blame] | 1660 | rc = -EPERM; |
| 1661 | dev_err(&card->gdev->dev, |
| 1662 | "A Bridge Port is already configured by a different operating system\n"); |
| 1663 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1664 | case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: |
| 1665 | case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1666 | switch (setcmd) { |
| 1667 | case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: |
| 1668 | rc = -EEXIST; |
| 1669 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1670 | "The LAN already has a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1671 | break; |
| 1672 | case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: |
| 1673 | rc = -EBUSY; |
| 1674 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1675 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1676 | break; |
| 1677 | default: |
| 1678 | rc = -EIO; |
| 1679 | } |
| 1680 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1681 | case IPA_RC_SBP_OSA_CURRENT_SECOND: |
| 1682 | case IPA_RC_SBP_IQD_CURRENT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1683 | rc = -EBUSY; |
| 1684 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1685 | "The device is already a secondary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1686 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1687 | case IPA_RC_SBP_OSA_LIMIT_SECOND: |
| 1688 | case IPA_RC_SBP_IQD_LIMIT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1689 | rc = -EEXIST; |
| 1690 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1691 | "The LAN cannot have more secondary Bridge Ports\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1692 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1693 | case IPA_RC_SBP_OSA_CURRENT_PRIMARY: |
| 1694 | case IPA_RC_SBP_IQD_CURRENT_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1695 | rc = -EBUSY; |
| 1696 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1697 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1698 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1699 | case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: |
| 1700 | case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1701 | rc = -EACCES; |
| 1702 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1703 | "The device is not authorized to be a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1704 | break; |
| 1705 | default: |
| 1706 | rc = -EIO; |
| 1707 | } |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1708 | else |
| 1709 | switch (cbctl->ipa_rc) { |
| 1710 | case IPA_RC_NOTSUPP: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1711 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1712 | break; |
| 1713 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1714 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1715 | break; |
| 1716 | default: |
| 1717 | rc = -EIO; |
| 1718 | } |
| 1719 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1720 | if (rc) { |
| 1721 | QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc); |
| 1722 | QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc); |
| 1723 | } |
| 1724 | return rc; |
| 1725 | } |
| 1726 | |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1727 | static inline int ipa_cmd_sbp(struct qeth_card *card) |
| 1728 | { |
| 1729 | return (card->info.type == QETH_CARD_TYPE_IQD) ? |
| 1730 | IPA_CMD_SETBRIDGEPORT_IQD : |
| 1731 | IPA_CMD_SETBRIDGEPORT_OSA; |
| 1732 | } |
| 1733 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1734 | static int qeth_bridgeport_query_support_cb(struct qeth_card *card, |
| 1735 | struct qeth_reply *reply, unsigned long data) |
| 1736 | { |
| 1737 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1738 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1739 | QETH_CARD_TEXT(card, 2, "brqsupcb"); |
| 1740 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1741 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1742 | if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) { |
| 1743 | cbctl->data.supported = |
| 1744 | cmd->data.sbp.data.query_cmds_supp.supported_cmds; |
| 1745 | } else { |
| 1746 | cbctl->data.supported = 0; |
| 1747 | } |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | /** |
| 1752 | * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. |
| 1753 | * @card: qeth_card structure pointer. |
| 1754 | * |
| 1755 | * Sets bitmask of supported setbridgeport subfunctions in the qeth_card |
| 1756 | * strucutre: card->options.sbp.supported_funcs. |
| 1757 | */ |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1758 | static void qeth_bridgeport_query_support(struct qeth_card *card) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1759 | { |
| 1760 | struct qeth_cmd_buffer *iob; |
| 1761 | struct qeth_ipa_cmd *cmd; |
| 1762 | struct _qeth_sbp_cbctl cbctl; |
| 1763 | |
| 1764 | QETH_CARD_TEXT(card, 2, "brqsuppo"); |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1765 | iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1766 | if (!iob) |
| 1767 | return; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1768 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1769 | cmd->data.sbp.hdr.cmdlength = |
| 1770 | sizeof(struct qeth_ipacmd_sbp_hdr) + |
| 1771 | sizeof(struct qeth_sbp_query_cmds_supp); |
| 1772 | cmd->data.sbp.hdr.command_code = |
| 1773 | IPA_SBP_QUERY_COMMANDS_SUPPORTED; |
| 1774 | cmd->data.sbp.hdr.used_total = 1; |
| 1775 | cmd->data.sbp.hdr.seq_no = 1; |
| 1776 | if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, |
| 1777 | (void *)&cbctl) || |
| 1778 | qeth_bridgeport_makerc(card, &cbctl, |
| 1779 | IPA_SBP_QUERY_COMMANDS_SUPPORTED)) { |
| 1780 | /* non-zero makerc signifies failure, and produce messages */ |
| 1781 | card->options.sbp.role = QETH_SBP_ROLE_NONE; |
| 1782 | return; |
| 1783 | } |
| 1784 | card->options.sbp.supported_funcs = cbctl.data.supported; |
| 1785 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1786 | |
| 1787 | static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, |
| 1788 | struct qeth_reply *reply, unsigned long data) |
| 1789 | { |
| 1790 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1791 | struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports; |
| 1792 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1793 | |
| 1794 | QETH_CARD_TEXT(card, 2, "brqprtcb"); |
| 1795 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1796 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1797 | if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0)) |
| 1798 | return 0; |
| 1799 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
| 1800 | cbctl->cmd_rc = 0xffff; |
| 1801 | QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); |
| 1802 | return 0; |
| 1803 | } |
| 1804 | /* first entry contains the state of the local port */ |
| 1805 | if (qports->num_entries > 0) { |
| 1806 | if (cbctl->data.qports.role) |
| 1807 | *cbctl->data.qports.role = qports->entry[0].role; |
| 1808 | if (cbctl->data.qports.state) |
| 1809 | *cbctl->data.qports.state = qports->entry[0].state; |
| 1810 | } |
| 1811 | return 0; |
| 1812 | } |
| 1813 | |
| 1814 | /** |
| 1815 | * qeth_bridgeport_query_ports() - query local bridgeport status. |
| 1816 | * @card: qeth_card structure pointer. |
| 1817 | * @role: Role of the port: 0-none, 1-primary, 2-secondary. |
| 1818 | * @state: State of the port: 0-inactive, 1-standby, 2-active. |
| 1819 | * |
| 1820 | * Returns negative errno-compatible error indication or 0 on success. |
| 1821 | * |
| 1822 | * 'role' and 'state' are not updated in case of hardware operation failure. |
| 1823 | */ |
| 1824 | int qeth_bridgeport_query_ports(struct qeth_card *card, |
| 1825 | enum qeth_sbp_roles *role, enum qeth_sbp_states *state) |
| 1826 | { |
| 1827 | int rc = 0; |
| 1828 | struct qeth_cmd_buffer *iob; |
| 1829 | struct qeth_ipa_cmd *cmd; |
| 1830 | struct _qeth_sbp_cbctl cbctl = { |
| 1831 | .data = { |
| 1832 | .qports = { |
| 1833 | .role = role, |
| 1834 | .state = state, |
| 1835 | }, |
| 1836 | }, |
| 1837 | }; |
| 1838 | |
| 1839 | QETH_CARD_TEXT(card, 2, "brqports"); |
| 1840 | if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) |
| 1841 | return -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1842 | iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1843 | if (!iob) |
| 1844 | return -ENOMEM; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1845 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1846 | cmd->data.sbp.hdr.cmdlength = |
| 1847 | sizeof(struct qeth_ipacmd_sbp_hdr); |
| 1848 | cmd->data.sbp.hdr.command_code = |
| 1849 | IPA_SBP_QUERY_BRIDGE_PORTS; |
| 1850 | cmd->data.sbp.hdr.used_total = 1; |
| 1851 | cmd->data.sbp.hdr.seq_no = 1; |
| 1852 | rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, |
| 1853 | (void *)&cbctl); |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1854 | if (rc < 0) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1855 | return rc; |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1856 | return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1857 | } |
| 1858 | EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports); |
| 1859 | |
| 1860 | static int qeth_bridgeport_set_cb(struct qeth_card *card, |
| 1861 | struct qeth_reply *reply, unsigned long data) |
| 1862 | { |
| 1863 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; |
| 1864 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1865 | QETH_CARD_TEXT(card, 2, "brsetrcb"); |
| 1866 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1867 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * qeth_bridgeport_setrole() - Assign primary role to the port. |
| 1873 | * @card: qeth_card structure pointer. |
| 1874 | * @role: Role to assign. |
| 1875 | * |
| 1876 | * Returns negative errno-compatible error indication or 0 on success. |
| 1877 | */ |
| 1878 | int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) |
| 1879 | { |
| 1880 | int rc = 0; |
| 1881 | int cmdlength; |
| 1882 | struct qeth_cmd_buffer *iob; |
| 1883 | struct qeth_ipa_cmd *cmd; |
| 1884 | struct _qeth_sbp_cbctl cbctl; |
| 1885 | enum qeth_ipa_sbp_cmd setcmd; |
| 1886 | |
| 1887 | QETH_CARD_TEXT(card, 2, "brsetrol"); |
| 1888 | switch (role) { |
| 1889 | case QETH_SBP_ROLE_NONE: |
| 1890 | setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; |
| 1891 | cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + |
| 1892 | sizeof(struct qeth_sbp_reset_role); |
| 1893 | break; |
| 1894 | case QETH_SBP_ROLE_PRIMARY: |
| 1895 | setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; |
| 1896 | cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + |
| 1897 | sizeof(struct qeth_sbp_set_primary); |
| 1898 | break; |
| 1899 | case QETH_SBP_ROLE_SECONDARY: |
| 1900 | setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; |
| 1901 | cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + |
| 1902 | sizeof(struct qeth_sbp_set_secondary); |
| 1903 | break; |
| 1904 | default: |
| 1905 | return -EINVAL; |
| 1906 | } |
| 1907 | if (!(card->options.sbp.supported_funcs & setcmd)) |
| 1908 | return -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1909 | iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1910 | if (!iob) |
| 1911 | return -ENOMEM; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1912 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1913 | cmd->data.sbp.hdr.cmdlength = cmdlength; |
| 1914 | cmd->data.sbp.hdr.command_code = setcmd; |
| 1915 | cmd->data.sbp.hdr.used_total = 1; |
| 1916 | cmd->data.sbp.hdr.seq_no = 1; |
| 1917 | rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, |
| 1918 | (void *)&cbctl); |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1919 | if (rc < 0) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1920 | return rc; |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1921 | return qeth_bridgeport_makerc(card, &cbctl, setcmd); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1922 | } |
| 1923 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1924 | /** |
| 1925 | * qeth_anset_makerc() - derive "traditional" error from hardware codes. |
| 1926 | * @card: qeth_card structure pointer, for debug messages. |
| 1927 | * |
| 1928 | * Returns negative errno-compatible error indication or 0 on success. |
| 1929 | */ |
| 1930 | static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response) |
| 1931 | { |
| 1932 | int rc; |
| 1933 | |
| 1934 | if (pnso_rc == 0) |
| 1935 | switch (response) { |
| 1936 | case 0x0001: |
| 1937 | rc = 0; |
| 1938 | break; |
| 1939 | case 0x0004: |
| 1940 | case 0x0100: |
| 1941 | case 0x0106: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1942 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1943 | dev_err(&card->gdev->dev, |
| 1944 | "Setting address notification failed\n"); |
| 1945 | break; |
| 1946 | case 0x0107: |
| 1947 | rc = -EAGAIN; |
| 1948 | break; |
| 1949 | default: |
| 1950 | rc = -EIO; |
| 1951 | } |
| 1952 | else |
| 1953 | rc = -EIO; |
| 1954 | |
| 1955 | if (rc) { |
| 1956 | QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc); |
| 1957 | QETH_CARD_TEXT_(card, 2, "SBPr%04x", response); |
| 1958 | } |
| 1959 | return rc; |
| 1960 | } |
| 1961 | |
| 1962 | static void qeth_bridgeport_an_set_cb(void *priv, |
| 1963 | enum qdio_brinfo_entry_type type, void *entry) |
| 1964 | { |
| 1965 | struct qeth_card *card = (struct qeth_card *)priv; |
| 1966 | struct qdio_brinfo_entry_l2 *l2entry; |
| 1967 | u8 code; |
| 1968 | |
| 1969 | if (type != l2_addr_lnid) { |
| 1970 | WARN_ON_ONCE(1); |
| 1971 | return; |
| 1972 | } |
| 1973 | |
| 1974 | l2entry = (struct qdio_brinfo_entry_l2 *)entry; |
| 1975 | code = IPA_ADDR_CHANGE_CODE_MACADDR; |
| 1976 | if (l2entry->addr_lnid.lnid) |
| 1977 | code |= IPA_ADDR_CHANGE_CODE_VLANID; |
| 1978 | qeth_bridge_emit_host_event(card, anev_reg_unreg, code, |
| 1979 | (struct net_if_token *)&l2entry->nit, |
| 1980 | (struct mac_addr_lnid *)&l2entry->addr_lnid); |
| 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification |
| 1985 | * @card: qeth_card structure pointer. |
| 1986 | * @enable: 0 - disable, non-zero - enable notifications |
| 1987 | * |
| 1988 | * Returns negative errno-compatible error indication or 0 on success. |
| 1989 | * |
| 1990 | * On enable, emits a series of address notifications udev events for all |
| 1991 | * currently registered hosts. |
| 1992 | */ |
| 1993 | int qeth_bridgeport_an_set(struct qeth_card *card, int enable) |
| 1994 | { |
| 1995 | int rc; |
| 1996 | u16 response; |
| 1997 | struct ccw_device *ddev; |
| 1998 | struct subchannel_id schid; |
| 1999 | |
| 2000 | if (!card) |
| 2001 | return -EINVAL; |
| 2002 | if (!card->options.sbp.supported_funcs) |
| 2003 | return -EOPNOTSUPP; |
| 2004 | ddev = CARD_DDEV(card); |
| 2005 | ccw_device_get_schid(ddev, &schid); |
| 2006 | |
| 2007 | if (enable) { |
| 2008 | qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); |
| 2009 | rc = qdio_pnso_brinfo(schid, 1, &response, |
| 2010 | qeth_bridgeport_an_set_cb, card); |
| 2011 | } else |
| 2012 | rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL); |
| 2013 | return qeth_anset_makerc(card, rc, response); |
| 2014 | } |
| 2015 | EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set); |
| 2016 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2017 | module_init(qeth_l2_init); |
| 2018 | module_exit(qeth_l2_exit); |
| 2019 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 2020 | MODULE_DESCRIPTION("qeth layer 2 discipline"); |
| 2021 | MODULE_LICENSE("GPL"); |