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 | |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 262 | static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb, |
| 263 | int cast_type, unsigned int data_len) |
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; |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 269 | hdr->hdr.l2.pkt_length = data_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 270 | |
| 271 | /* set byte byte 3 to casting flags */ |
| 272 | if (cast_type == RTN_MULTICAST) |
| 273 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; |
| 274 | else if (cast_type == RTN_BROADCAST) |
| 275 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; |
| 276 | else |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 277 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 278 | |
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 | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 679 | static int qeth_l2_xmit_iqd(struct qeth_card *card, struct sk_buff *skb, |
| 680 | struct qeth_qdio_out_q *queue, int cast_type) |
| 681 | { |
| 682 | unsigned int data_offset = ETH_HLEN; |
| 683 | struct qeth_hdr *hdr; |
| 684 | int rc; |
| 685 | |
| 686 | hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC); |
| 687 | if (!hdr) |
| 688 | return -ENOMEM; |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 689 | qeth_l2_fill_header(hdr, skb, cast_type, skb->len); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 690 | skb_copy_from_linear_data(skb, ((char *)hdr) + sizeof(*hdr), |
| 691 | data_offset); |
| 692 | |
| 693 | if (!qeth_get_elements_no(card, skb, 1, data_offset)) { |
| 694 | rc = -E2BIG; |
| 695 | goto out; |
| 696 | } |
| 697 | rc = qeth_do_send_packet_fast(card, queue, skb, hdr, data_offset, |
Julian Wiedmann | f158817 | 2017-08-18 10:19:08 +0200 | [diff] [blame^] | 698 | sizeof(*hdr) + data_offset); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 699 | out: |
| 700 | if (rc) |
| 701 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 702 | return rc; |
| 703 | } |
| 704 | |
| 705 | static int qeth_l2_xmit_osa(struct qeth_card *card, struct sk_buff *skb, |
| 706 | struct qeth_qdio_out_q *queue, int cast_type) |
| 707 | { |
| 708 | unsigned int elements, nr_frags; |
| 709 | struct sk_buff *skb_copy; |
| 710 | struct qeth_hdr *hdr; |
| 711 | int rc; |
| 712 | |
| 713 | /* fix hardware limitation: as long as we do not have sbal |
| 714 | * chaining we can not send long frag lists |
| 715 | */ |
| 716 | if (!qeth_get_elements_no(card, skb, 0, 0)) { |
| 717 | rc = skb_linearize(skb); |
| 718 | |
| 719 | if (card->options.performance_stats) { |
| 720 | if (rc) |
| 721 | card->perf_stats.tx_linfail++; |
| 722 | else |
| 723 | card->perf_stats.tx_lin++; |
| 724 | } |
| 725 | if (rc) |
| 726 | return rc; |
| 727 | } |
| 728 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 729 | |
| 730 | /* create a copy with writeable headroom */ |
| 731 | skb_copy = skb_realloc_headroom(skb, sizeof(struct qeth_hdr)); |
| 732 | if (!skb_copy) |
| 733 | return -ENOMEM; |
| 734 | hdr = skb_push(skb_copy, sizeof(struct qeth_hdr)); |
Julian Wiedmann | ae79fe0 | 2017-08-18 10:19:05 +0200 | [diff] [blame] | 735 | qeth_l2_fill_header(hdr, skb_copy, cast_type, |
| 736 | skb_copy->len - sizeof(*hdr)); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 737 | if (skb_copy->ip_summed == CHECKSUM_PARTIAL) |
| 738 | qeth_l2_hdr_csum(card, hdr, skb_copy); |
| 739 | |
| 740 | elements = qeth_get_elements_no(card, skb_copy, 0, 0); |
| 741 | if (!elements) { |
| 742 | rc = -E2BIG; |
| 743 | goto out; |
| 744 | } |
| 745 | if (qeth_hdr_chk_and_bounce(skb_copy, &hdr, sizeof(*hdr))) { |
| 746 | rc = -EINVAL; |
| 747 | goto out; |
| 748 | } |
Julian Wiedmann | 9c3bfda | 2017-08-18 10:19:07 +0200 | [diff] [blame] | 749 | rc = qeth_do_send_packet(card, queue, skb_copy, hdr, 0, 0, elements); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 750 | out: |
| 751 | if (!rc) { |
| 752 | /* tx success, free dangling original */ |
| 753 | dev_kfree_skb_any(skb); |
| 754 | if (card->options.performance_stats && nr_frags) { |
| 755 | card->perf_stats.sg_skbs_sent++; |
| 756 | /* nr_frags + skb->data */ |
| 757 | card->perf_stats.sg_frags_sent += nr_frags + 1; |
| 758 | } |
| 759 | } else { |
| 760 | /* tx fail, free copy */ |
| 761 | dev_kfree_skb_any(skb_copy); |
| 762 | } |
| 763 | return rc; |
| 764 | } |
| 765 | |
| 766 | static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb, |
| 767 | struct qeth_qdio_out_q *queue) |
| 768 | { |
| 769 | unsigned int elements; |
| 770 | struct qeth_hdr *hdr; |
| 771 | |
| 772 | if (skb->protocol == htons(ETH_P_IPV6)) |
| 773 | return -EPROTONOSUPPORT; |
| 774 | |
| 775 | hdr = (struct qeth_hdr *)skb->data; |
| 776 | elements = qeth_get_elements_no(card, skb, 0, 0); |
| 777 | if (!elements) |
| 778 | return -E2BIG; |
| 779 | if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr))) |
| 780 | return -EINVAL; |
Julian Wiedmann | 9c3bfda | 2017-08-18 10:19:07 +0200 | [diff] [blame] | 781 | return qeth_do_send_packet(card, queue, skb, hdr, 0, 0, elements); |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 782 | } |
| 783 | |
Julian Wiedmann | e38db6b | 2017-04-11 16:11:14 +0200 | [diff] [blame] | 784 | static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb, |
| 785 | struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 786 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 787 | struct qeth_card *card = dev->ml_priv; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 788 | int cast_type = qeth_l2_get_cast_type(card, skb); |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 789 | struct qeth_qdio_out_q *queue; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 790 | int tx_bytes = skb->len; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 791 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 792 | |
Stefan Raspl | 290b834 | 2014-04-28 10:05:08 +0200 | [diff] [blame] | 793 | if (card->qdio.do_prio_queueing || (cast_type && |
| 794 | card->info.is_multicast_different)) |
| 795 | queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb, |
| 796 | qeth_get_ip_version(skb), cast_type)]; |
| 797 | else |
| 798 | queue = card->qdio.out_qs[card->qdio.default_out_queue]; |
| 799 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 800 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 801 | card->stats.tx_carrier_errors++; |
| 802 | goto tx_drop; |
| 803 | } |
| 804 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 805 | if (card->options.performance_stats) { |
| 806 | card->perf_stats.outbound_cnt++; |
| 807 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 808 | } |
| 809 | netif_stop_queue(dev); |
| 810 | |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 811 | switch (card->info.type) { |
| 812 | case QETH_CARD_TYPE_OSN: |
| 813 | rc = qeth_l2_xmit_osn(card, skb, queue); |
| 814 | break; |
| 815 | case QETH_CARD_TYPE_IQD: |
| 816 | rc = qeth_l2_xmit_iqd(card, skb, queue, cast_type); |
| 817 | break; |
| 818 | default: |
| 819 | rc = qeth_l2_xmit_osa(card, skb, queue, cast_type); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 820 | } |
| 821 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 822 | if (!rc) { |
| 823 | card->stats.tx_packets++; |
| 824 | card->stats.tx_bytes += tx_bytes; |
Julian Wiedmann | 7286384 | 2017-08-18 10:19:04 +0200 | [diff] [blame] | 825 | if (card->options.performance_stats) |
| 826 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 827 | card->perf_stats.outbound_start_time; |
| 828 | netif_wake_queue(dev); |
| 829 | return NETDEV_TX_OK; |
| 830 | } else if (rc == -EBUSY) { |
| 831 | return NETDEV_TX_BUSY; |
| 832 | } /* else fall through */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 833 | |
| 834 | tx_drop: |
| 835 | card->stats.tx_dropped++; |
| 836 | card->stats.tx_errors++; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 837 | dev_kfree_skb_any(skb); |
Frank Blaschka | d0ec0f5 | 2008-06-06 12:37:48 +0200 | [diff] [blame] | 838 | netif_wake_queue(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 839 | return NETDEV_TX_OK; |
| 840 | } |
| 841 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 842 | static int __qeth_l2_open(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 843 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 844 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 845 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 846 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 847 | QETH_CARD_TEXT(card, 4, "qethopen"); |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 848 | if (card->state == CARD_STATE_UP) |
| 849 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 850 | if (card->state != CARD_STATE_SOFTSETUP) |
| 851 | return -ENODEV; |
| 852 | |
| 853 | if ((card->info.type != QETH_CARD_TYPE_OSN) && |
| 854 | (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 855 | QETH_CARD_TEXT(card, 4, "nomacadr"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 856 | return -EPERM; |
| 857 | } |
| 858 | card->data.state = CH_STATE_UP; |
| 859 | card->state = CARD_STATE_UP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 860 | netif_start_queue(dev); |
| 861 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 862 | if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) { |
| 863 | napi_enable(&card->napi); |
| 864 | napi_schedule(&card->napi); |
| 865 | } else |
| 866 | rc = -EIO; |
| 867 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 868 | } |
| 869 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 870 | static int qeth_l2_open(struct net_device *dev) |
| 871 | { |
| 872 | struct qeth_card *card = dev->ml_priv; |
| 873 | |
| 874 | QETH_CARD_TEXT(card, 5, "qethope_"); |
| 875 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
| 876 | QETH_CARD_TEXT(card, 3, "openREC"); |
| 877 | return -ERESTARTSYS; |
| 878 | } |
| 879 | return __qeth_l2_open(dev); |
| 880 | } |
| 881 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 882 | static int qeth_l2_stop(struct net_device *dev) |
| 883 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 884 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 885 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 886 | QETH_CARD_TEXT(card, 4, "qethstop"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 887 | netif_tx_disable(dev); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 888 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 889 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 890 | napi_disable(&card->napi); |
| 891 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 895 | static const struct device_type qeth_l2_devtype = { |
| 896 | .name = "qeth_layer2", |
| 897 | .groups = qeth_l2_attr_groups, |
| 898 | }; |
| 899 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 900 | static int qeth_l2_probe_device(struct ccwgroup_device *gdev) |
| 901 | { |
| 902 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | 9111e78 | 2017-05-10 19:07:51 +0200 | [diff] [blame] | 903 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 904 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 905 | if (gdev->dev.type == &qeth_generic_devtype) { |
| 906 | rc = qeth_l2_create_device_attributes(&gdev->dev); |
| 907 | if (rc) |
| 908 | return rc; |
| 909 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 910 | INIT_LIST_HEAD(&card->vid_list); |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 911 | hash_init(card->mac_htable); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 912 | card->options.layer2 = 1; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 913 | card->info.hwtrap = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 914 | return 0; |
| 915 | } |
| 916 | |
| 917 | static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) |
| 918 | { |
| 919 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 920 | |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 921 | if (cgdev->dev.type == &qeth_generic_devtype) |
| 922 | qeth_l2_remove_device_attributes(&cgdev->dev); |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 923 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 924 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 925 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 926 | if (cgdev->state == CCWGROUP_ONLINE) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 927 | qeth_l2_set_offline(cgdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 928 | |
| 929 | if (card->dev) { |
Ursula Braun | 7831b4f | 2016-07-04 14:07:16 +0200 | [diff] [blame] | 930 | netif_napi_del(&card->napi); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 931 | unregister_netdev(card->dev); |
| 932 | card->dev = NULL; |
| 933 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 934 | return; |
| 935 | } |
| 936 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 937 | static const struct ethtool_ops qeth_l2_ethtool_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 938 | .get_link = ethtool_op_get_link, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 939 | .get_strings = qeth_core_get_strings, |
| 940 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 941 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 942 | .get_drvinfo = qeth_core_get_drvinfo, |
Julian Wiedmann | 993e19c | 2017-04-11 16:11:17 +0200 | [diff] [blame] | 943 | .get_link_ksettings = qeth_core_ethtool_get_link_ksettings, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 944 | }; |
| 945 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 946 | static const struct ethtool_ops qeth_l2_osn_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 947 | .get_strings = qeth_core_get_strings, |
| 948 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 949 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 950 | .get_drvinfo = qeth_core_get_drvinfo, |
| 951 | }; |
| 952 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 953 | static const struct net_device_ops qeth_l2_netdev_ops = { |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 954 | .ndo_open = qeth_l2_open, |
| 955 | .ndo_stop = qeth_l2_stop, |
| 956 | .ndo_get_stats = qeth_get_stats, |
| 957 | .ndo_start_xmit = qeth_l2_hard_start_xmit, |
| 958 | .ndo_validate_addr = eth_validate_addr, |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 959 | .ndo_set_rx_mode = qeth_l2_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 960 | .ndo_do_ioctl = qeth_do_ioctl, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 961 | .ndo_set_mac_address = qeth_l2_set_mac_address, |
| 962 | .ndo_change_mtu = qeth_change_mtu, |
| 963 | .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, |
| 964 | .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, |
| 965 | .ndo_tx_timeout = qeth_tx_timeout, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 966 | .ndo_fix_features = qeth_fix_features, |
| 967 | .ndo_set_features = qeth_set_features |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 968 | }; |
| 969 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 970 | static int qeth_l2_setup_netdev(struct qeth_card *card) |
| 971 | { |
| 972 | switch (card->info.type) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 973 | case QETH_CARD_TYPE_IQD: |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 974 | card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN, |
| 975 | ether_setup); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 976 | break; |
| 977 | case QETH_CARD_TYPE_OSN: |
Tom Gundersen | c835a67 | 2014-07-14 16:37:24 +0200 | [diff] [blame] | 978 | card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN, |
| 979 | ether_setup); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 980 | break; |
| 981 | default: |
| 982 | card->dev = alloc_etherdev(0); |
| 983 | } |
| 984 | |
| 985 | if (!card->dev) |
| 986 | return -ENODEV; |
| 987 | |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 988 | card->dev->ml_priv = card; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 989 | card->dev->watchdog_timeo = QETH_TX_TIMEOUT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 990 | card->dev->mtu = card->info.initial_mtu; |
Jarod Wilson | 46b3ef4 | 2016-10-20 13:55:23 -0400 | [diff] [blame] | 991 | card->dev->min_mtu = 64; |
| 992 | card->dev->max_mtu = ETH_MAX_MTU; |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 993 | card->dev->netdev_ops = &qeth_l2_netdev_ops; |
Julian Wiedmann | 25e2c34 | 2017-05-10 19:07:53 +0200 | [diff] [blame] | 994 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 995 | card->dev->ethtool_ops = &qeth_l2_osn_ops; |
| 996 | card->dev->flags |= IFF_NOARP; |
| 997 | } else { |
| 998 | card->dev->ethtool_ops = &qeth_l2_ethtool_ops; |
| 999 | } |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1000 | card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1001 | if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1002 | card->dev->hw_features = NETIF_F_SG; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1003 | card->dev->vlan_features = NETIF_F_SG; |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1004 | /* OSA 3S and earlier has no RX/TX support */ |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1005 | if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1006 | card->dev->hw_features |= NETIF_F_IP_CSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1007 | card->dev->vlan_features |= NETIF_F_IP_CSUM; |
| 1008 | } |
| 1009 | if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1010 | card->dev->hw_features |= NETIF_F_RXCSUM; |
Hans Wippel | 9bdc441 | 2016-06-16 16:19:00 +0200 | [diff] [blame] | 1011 | card->dev->vlan_features |= NETIF_F_RXCSUM; |
| 1012 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1013 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1014 | card->info.broadcast_capable = 1; |
| 1015 | qeth_l2_request_initial_mac(card); |
Eugene Crosser | d52aec9 | 2016-06-16 16:18:55 +0200 | [diff] [blame] | 1016 | card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) * |
| 1017 | PAGE_SIZE; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1018 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 1019 | netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); |
Ursula Braun | e5ebe63 | 2015-12-11 12:27:55 +0100 | [diff] [blame] | 1020 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1021 | return register_netdev(card->dev); |
| 1022 | } |
| 1023 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1024 | static int qeth_l2_start_ipassists(struct qeth_card *card) |
| 1025 | { |
| 1026 | /* configure isolation level */ |
| 1027 | if (qeth_set_access_ctrl_online(card, 0)) |
| 1028 | return -ENODEV; |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1029 | return 0; |
| 1030 | } |
| 1031 | |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1032 | static void qeth_l2_trace_features(struct qeth_card *card) |
| 1033 | { |
| 1034 | QETH_CARD_TEXT(card, 2, "l2featur"); |
| 1035 | QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs, |
| 1036 | sizeof(card->options.sbp.supported_funcs)); |
| 1037 | } |
| 1038 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1039 | static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
| 1040 | { |
| 1041 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1042 | int rc = 0; |
| 1043 | enum qeth_card_states recover_flag; |
| 1044 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1045 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1046 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1047 | QETH_DBF_TEXT(SETUP, 2, "setonlin"); |
| 1048 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1049 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1050 | recover_flag = card->state; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1051 | rc = qeth_core_hardsetup_card(card); |
| 1052 | if (rc) { |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1053 | QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1054 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1055 | goto out_remove; |
| 1056 | } |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1057 | qeth_bridgeport_query_support(card); |
| 1058 | if (card->options.sbp.supported_funcs) |
| 1059 | dev_info(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1060 | "The device represents a Bridge Capable Port\n"); |
Stefan Raspl | 395672e0 | 2012-11-19 02:46:49 +0000 | [diff] [blame] | 1061 | qeth_trace_features(card); |
Julian Wiedmann | 521c10e | 2017-06-06 14:33:45 +0200 | [diff] [blame] | 1062 | qeth_l2_trace_features(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1063 | |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1064 | if (!card->dev && qeth_l2_setup_netdev(card)) { |
| 1065 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1066 | goto out_remove; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1067 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1068 | |
| 1069 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 1070 | qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); |
| 1071 | |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1072 | if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { |
| 1073 | if (card->info.hwtrap && |
| 1074 | qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) |
| 1075 | card->info.hwtrap = 0; |
| 1076 | } else |
| 1077 | card->info.hwtrap = 0; |
| 1078 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1079 | qeth_l2_setup_bridgeport_attrs(card); |
| 1080 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1081 | card->state = CARD_STATE_HARDSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1082 | memset(&card->rx, 0, sizeof(struct qeth_rx)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1083 | qeth_print_status_message(card); |
| 1084 | |
| 1085 | /* softsetup */ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1086 | QETH_DBF_TEXT(SETUP, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1087 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1088 | if ((card->info.type == QETH_CARD_TYPE_OSD) || |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1089 | (card->info.type == QETH_CARD_TYPE_OSX)) { |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1090 | rc = qeth_l2_start_ipassists(card); |
| 1091 | if (rc) |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1092 | goto out_remove; |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1093 | } |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1094 | |
| 1095 | if (card->info.type != QETH_CARD_TYPE_OSN && |
| 1096 | card->info.type != QETH_CARD_TYPE_OSM) |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 1097 | qeth_l2_process_vlans(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1098 | |
| 1099 | netif_tx_disable(card->dev); |
| 1100 | |
| 1101 | rc = qeth_init_qdio_queues(card); |
| 1102 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1103 | QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1104 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1105 | goto out_remove; |
| 1106 | } |
| 1107 | card->state = CARD_STATE_SOFTSETUP; |
Ursula Braun | 2b6203b | 2010-11-26 02:41:19 +0000 | [diff] [blame] | 1108 | if (card->lan_online) |
| 1109 | netif_carrier_on(card->dev); |
| 1110 | else |
| 1111 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1112 | |
| 1113 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1114 | if (recover_flag == CARD_STATE_RECOVER) { |
| 1115 | if (recovery_mode && |
| 1116 | card->info.type != QETH_CARD_TYPE_OSN) { |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 1117 | __qeth_l2_open(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1118 | } else { |
| 1119 | rtnl_lock(); |
| 1120 | dev_open(card->dev); |
| 1121 | rtnl_unlock(); |
| 1122 | } |
| 1123 | /* this also sets saved unicast addresses */ |
Lakhvich Dmitriy | fe5c802 | 2015-10-06 15:12:28 +0200 | [diff] [blame] | 1124 | qeth_l2_set_rx_mode(card->dev); |
Hans Wippel | e830baa | 2016-09-15 14:39:21 +0200 | [diff] [blame] | 1125 | rtnl_lock(); |
| 1126 | qeth_recover_features(card->dev); |
| 1127 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1128 | } |
| 1129 | /* let user_space know that device is online */ |
| 1130 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1131 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1132 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1133 | return 0; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1134 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1135 | out_remove: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1136 | qeth_l2_stop_card(card, 0); |
| 1137 | ccw_device_set_offline(CARD_DDEV(card)); |
| 1138 | ccw_device_set_offline(CARD_WDEV(card)); |
| 1139 | ccw_device_set_offline(CARD_RDEV(card)); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 1140 | qdio_free(CARD_DDEV(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1141 | if (recover_flag == CARD_STATE_RECOVER) |
| 1142 | card->state = CARD_STATE_RECOVER; |
| 1143 | else |
| 1144 | card->state = CARD_STATE_DOWN; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1145 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1146 | mutex_unlock(&card->discipline_mutex); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1147 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | static int qeth_l2_set_online(struct ccwgroup_device *gdev) |
| 1151 | { |
| 1152 | return __qeth_l2_set_online(gdev, 0); |
| 1153 | } |
| 1154 | |
| 1155 | static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev, |
| 1156 | int recovery_mode) |
| 1157 | { |
| 1158 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 1159 | int rc = 0, rc2 = 0, rc3 = 0; |
| 1160 | enum qeth_card_states recover_flag; |
| 1161 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1162 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1163 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1164 | QETH_DBF_TEXT(SETUP, 3, "setoffl"); |
| 1165 | QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1166 | |
| 1167 | if (card->dev && netif_carrier_ok(card->dev)) |
| 1168 | netif_carrier_off(card->dev); |
| 1169 | recover_flag = card->state; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1170 | if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { |
| 1171 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
| 1172 | card->info.hwtrap = 1; |
| 1173 | } |
Ursula Braun | 0f5623c | 2008-10-24 11:16:52 +0200 | [diff] [blame] | 1174 | qeth_l2_stop_card(card, recovery_mode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1175 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 1176 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 1177 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 1178 | if (!rc) |
| 1179 | rc = (rc2) ? rc2 : rc3; |
| 1180 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1181 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 1182 | qdio_free(CARD_DDEV(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1183 | if (recover_flag == CARD_STATE_UP) |
| 1184 | card->state = CARD_STATE_RECOVER; |
| 1185 | /* let user_space know that device is offline */ |
| 1186 | kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1187 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1188 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1189 | return 0; |
| 1190 | } |
| 1191 | |
| 1192 | static int qeth_l2_set_offline(struct ccwgroup_device *cgdev) |
| 1193 | { |
| 1194 | return __qeth_l2_set_offline(cgdev, 0); |
| 1195 | } |
| 1196 | |
| 1197 | static int qeth_l2_recover(void *ptr) |
| 1198 | { |
| 1199 | struct qeth_card *card; |
| 1200 | int rc = 0; |
| 1201 | |
| 1202 | card = (struct qeth_card *) ptr; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1203 | QETH_CARD_TEXT(card, 2, "recover1"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1204 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 1205 | return 0; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1206 | QETH_CARD_TEXT(card, 2, "recover2"); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1207 | dev_warn(&card->gdev->dev, |
| 1208 | "A recovery process has been started for the device\n"); |
Stefan Raspl | 65d8013 | 2013-04-07 22:19:27 +0000 | [diff] [blame] | 1209 | qeth_set_recovery_task(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1210 | __qeth_l2_set_offline(card->gdev, 1); |
| 1211 | rc = __qeth_l2_set_online(card->gdev, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1212 | if (!rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1213 | dev_info(&card->gdev->dev, |
| 1214 | "Device successfully recovered!\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1215 | else { |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1216 | qeth_close_dev(card); |
| 1217 | dev_warn(&card->gdev->dev, "The qeth device driver " |
Stefan Raspl | 2efaf5f | 2012-10-15 19:21:18 +0000 | [diff] [blame] | 1218 | "failed to recover an error on the device\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1219 | } |
Stefan Raspl | 65d8013 | 2013-04-07 22:19:27 +0000 | [diff] [blame] | 1220 | qeth_clear_recovery_task(card); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1221 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 1222 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | static int __init qeth_l2_init(void) |
| 1227 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1228 | pr_info("register layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | static void __exit qeth_l2_exit(void) |
| 1233 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1234 | pr_info("unregister layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1235 | } |
| 1236 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1237 | static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) |
| 1238 | { |
| 1239 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1240 | |
| 1241 | if (card->dev) |
| 1242 | netif_device_detach(card->dev); |
| 1243 | qeth_set_allowed_threads(card, 0, 1); |
| 1244 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 1245 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1246 | return 0; |
| 1247 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1248 | if (card->info.hwtrap) |
| 1249 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1250 | __qeth_l2_set_offline(card->gdev, 1); |
| 1251 | } else |
| 1252 | __qeth_l2_set_offline(card->gdev, 0); |
| 1253 | return 0; |
| 1254 | } |
| 1255 | |
| 1256 | static int qeth_l2_pm_resume(struct ccwgroup_device *gdev) |
| 1257 | { |
| 1258 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1259 | int rc = 0; |
| 1260 | |
| 1261 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1262 | goto out; |
| 1263 | |
| 1264 | if (card->state == CARD_STATE_RECOVER) { |
| 1265 | rc = __qeth_l2_set_online(card->gdev, 1); |
| 1266 | if (rc) { |
Ursula Braun | 869da90 | 2010-03-08 20:36:56 +0000 | [diff] [blame] | 1267 | rtnl_lock(); |
| 1268 | dev_close(card->dev); |
| 1269 | rtnl_unlock(); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1270 | } |
| 1271 | } else |
| 1272 | rc = __qeth_l2_set_online(card->gdev, 0); |
| 1273 | out: |
| 1274 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1275 | if (card->dev) |
| 1276 | netif_device_attach(card->dev); |
| 1277 | if (rc) |
| 1278 | dev_warn(&card->gdev->dev, "The qeth device driver " |
| 1279 | "failed to recover an error on the device\n"); |
| 1280 | return rc; |
| 1281 | } |
| 1282 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1283 | /* Returns zero if the command is successfully "consumed" */ |
| 1284 | static int qeth_l2_control_event(struct qeth_card *card, |
| 1285 | struct qeth_ipa_cmd *cmd) |
| 1286 | { |
| 1287 | switch (cmd->hdr.command) { |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1288 | case IPA_CMD_SETBRIDGEPORT_OSA: |
| 1289 | case IPA_CMD_SETBRIDGEPORT_IQD: |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1290 | if (cmd->data.sbp.hdr.command_code == |
| 1291 | IPA_SBP_BRIDGE_PORT_STATE_CHANGE) { |
| 1292 | qeth_bridge_state_change(card, cmd); |
| 1293 | return 0; |
| 1294 | } else |
| 1295 | return 1; |
| 1296 | case IPA_CMD_ADDRESS_CHANGE_NOTIF: |
| 1297 | qeth_bridge_host_event(card, cmd); |
| 1298 | return 0; |
| 1299 | default: |
| 1300 | return 1; |
| 1301 | } |
| 1302 | } |
| 1303 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1304 | struct qeth_discipline qeth_l2_discipline = { |
Julian Wiedmann | 2d2ebb3 | 2017-05-10 19:07:52 +0200 | [diff] [blame] | 1305 | .devtype = &qeth_l2_devtype, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1306 | .start_poll = qeth_qdio_start_poll, |
| 1307 | .input_handler = (qdio_handler_t *) qeth_qdio_input_handler, |
| 1308 | .output_handler = (qdio_handler_t *) qeth_qdio_output_handler, |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 1309 | .process_rx_buffer = qeth_l2_process_inbound_buffer, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1310 | .recover = qeth_l2_recover, |
| 1311 | .setup = qeth_l2_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1312 | .remove = qeth_l2_remove_device, |
| 1313 | .set_online = qeth_l2_set_online, |
| 1314 | .set_offline = qeth_l2_set_offline, |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1315 | .freeze = qeth_l2_pm_suspend, |
| 1316 | .thaw = qeth_l2_pm_resume, |
| 1317 | .restore = qeth_l2_pm_resume, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 1318 | .do_ioctl = NULL, |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1319 | .control_event_handler = qeth_l2_control_event, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1320 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1321 | EXPORT_SYMBOL_GPL(qeth_l2_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1322 | |
| 1323 | static int qeth_osn_send_control_data(struct qeth_card *card, int len, |
| 1324 | struct qeth_cmd_buffer *iob) |
| 1325 | { |
| 1326 | unsigned long flags; |
| 1327 | int rc = 0; |
| 1328 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1329 | QETH_CARD_TEXT(card, 5, "osndctrd"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1330 | |
| 1331 | wait_event(card->wait_q, |
| 1332 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
| 1333 | qeth_prepare_control_data(card, len, iob); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1334 | QETH_CARD_TEXT(card, 6, "osnoirqp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1335 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1336 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1337 | (addr_t) iob, 0, 0); |
| 1338 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1339 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 1340 | QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1341 | "ccw_device_start rc = %i\n", rc); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1342 | QETH_CARD_TEXT_(card, 2, " err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1343 | qeth_release_buffer(iob->channel, iob); |
| 1344 | atomic_set(&card->write.irq_pending, 0); |
| 1345 | wake_up(&card->wait_q); |
| 1346 | } |
| 1347 | return rc; |
| 1348 | } |
| 1349 | |
| 1350 | static int qeth_osn_send_ipa_cmd(struct qeth_card *card, |
| 1351 | struct qeth_cmd_buffer *iob, int data_len) |
| 1352 | { |
| 1353 | u16 s1, s2; |
| 1354 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1355 | QETH_CARD_TEXT(card, 4, "osndipa"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1356 | |
| 1357 | qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); |
| 1358 | s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); |
| 1359 | s2 = (u16)data_len; |
| 1360 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 1361 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 1362 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 1363 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 1364 | return qeth_osn_send_control_data(card, s1, iob); |
| 1365 | } |
| 1366 | |
| 1367 | int qeth_osn_assist(struct net_device *dev, void *data, int data_len) |
| 1368 | { |
| 1369 | struct qeth_cmd_buffer *iob; |
| 1370 | struct qeth_card *card; |
| 1371 | int rc; |
| 1372 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1373 | if (!dev) |
| 1374 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1375 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1376 | if (!card) |
| 1377 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1378 | QETH_CARD_TEXT(card, 2, "osnsdmc"); |
Eugene Crosser | c352125 | 2015-01-16 14:05:47 +0100 | [diff] [blame] | 1379 | if (!qeth_card_hw_is_reachable(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1380 | return -ENODEV; |
| 1381 | iob = qeth_wait_for_buffer(&card->write); |
| 1382 | memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); |
| 1383 | rc = qeth_osn_send_ipa_cmd(card, iob, data_len); |
| 1384 | return rc; |
| 1385 | } |
| 1386 | EXPORT_SYMBOL(qeth_osn_assist); |
| 1387 | |
| 1388 | int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, |
| 1389 | int (*assist_cb)(struct net_device *, void *), |
| 1390 | int (*data_cb)(struct sk_buff *)) |
| 1391 | { |
| 1392 | struct qeth_card *card; |
| 1393 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1394 | *dev = qeth_l2_netdev_by_devno(read_dev_no); |
| 1395 | if (*dev == NULL) |
| 1396 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1397 | card = (*dev)->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1398 | if (!card) |
| 1399 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1400 | QETH_CARD_TEXT(card, 2, "osnreg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1401 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 1402 | return -EINVAL; |
| 1403 | card->osn_info.assist_cb = assist_cb; |
| 1404 | card->osn_info.data_cb = data_cb; |
| 1405 | return 0; |
| 1406 | } |
| 1407 | EXPORT_SYMBOL(qeth_osn_register); |
| 1408 | |
| 1409 | void qeth_osn_deregister(struct net_device *dev) |
| 1410 | { |
| 1411 | struct qeth_card *card; |
| 1412 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1413 | if (!dev) |
| 1414 | return; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1415 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1416 | if (!card) |
| 1417 | return; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1418 | QETH_CARD_TEXT(card, 2, "osndereg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1419 | card->osn_info.assist_cb = NULL; |
| 1420 | card->osn_info.data_cb = NULL; |
| 1421 | return; |
| 1422 | } |
| 1423 | EXPORT_SYMBOL(qeth_osn_deregister); |
| 1424 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1425 | /* SETBRIDGEPORT support, async notifications */ |
| 1426 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1427 | enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset}; |
| 1428 | |
| 1429 | /** |
| 1430 | * qeth_bridge_emit_host_event() - bridgeport address change notification |
| 1431 | * @card: qeth_card structure pointer, for udev events. |
| 1432 | * @evtype: "normal" register/unregister, or abort, or reset. For abort |
| 1433 | * and reset token and addr_lnid are unused and may be NULL. |
| 1434 | * @code: event bitmask: high order bit 0x80 value 1 means removal of an |
| 1435 | * object, 0 - addition of an object. |
| 1436 | * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC. |
| 1437 | * @token: "network token" structure identifying physical address of the port. |
| 1438 | * @addr_lnid: pointer to structure with MAC address and VLAN ID. |
| 1439 | * |
| 1440 | * This function is called when registrations and deregistrations are |
| 1441 | * reported by the hardware, and also when notifications are enabled - |
| 1442 | * for all currently registered addresses. |
| 1443 | */ |
| 1444 | static void qeth_bridge_emit_host_event(struct qeth_card *card, |
| 1445 | enum qeth_an_event_type evtype, |
| 1446 | u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid) |
| 1447 | { |
| 1448 | char str[7][32]; |
| 1449 | char *env[8]; |
| 1450 | int i = 0; |
| 1451 | |
| 1452 | switch (evtype) { |
| 1453 | case anev_reg_unreg: |
| 1454 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s", |
| 1455 | (code & IPA_ADDR_CHANGE_CODE_REMOVAL) |
| 1456 | ? "deregister" : "register"); |
| 1457 | env[i] = str[i]; i++; |
| 1458 | if (code & IPA_ADDR_CHANGE_CODE_VLANID) { |
| 1459 | snprintf(str[i], sizeof(str[i]), "VLAN=%d", |
| 1460 | addr_lnid->lnid); |
| 1461 | env[i] = str[i]; i++; |
| 1462 | } |
| 1463 | if (code & IPA_ADDR_CHANGE_CODE_MACADDR) { |
Eugene Crosser | 9846e70 | 2015-09-18 16:06:48 +0200 | [diff] [blame] | 1464 | snprintf(str[i], sizeof(str[i]), "MAC=%pM", |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 1465 | addr_lnid->mac); |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1466 | env[i] = str[i]; i++; |
| 1467 | } |
| 1468 | snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x", |
| 1469 | token->cssid, token->ssid, token->devnum); |
| 1470 | env[i] = str[i]; i++; |
| 1471 | snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid); |
| 1472 | env[i] = str[i]; i++; |
| 1473 | snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x", |
| 1474 | token->chpid); |
| 1475 | env[i] = str[i]; i++; |
| 1476 | snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid); |
| 1477 | env[i] = str[i]; i++; |
| 1478 | break; |
| 1479 | case anev_abort: |
| 1480 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort"); |
| 1481 | env[i] = str[i]; i++; |
| 1482 | break; |
| 1483 | case anev_reset: |
| 1484 | snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset"); |
| 1485 | env[i] = str[i]; i++; |
| 1486 | break; |
| 1487 | } |
| 1488 | env[i] = NULL; |
| 1489 | kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env); |
| 1490 | } |
| 1491 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1492 | struct qeth_bridge_state_data { |
| 1493 | struct work_struct worker; |
| 1494 | struct qeth_card *card; |
| 1495 | struct qeth_sbp_state_change qports; |
| 1496 | }; |
| 1497 | |
| 1498 | static void qeth_bridge_state_change_worker(struct work_struct *work) |
| 1499 | { |
| 1500 | struct qeth_bridge_state_data *data = |
| 1501 | container_of(work, struct qeth_bridge_state_data, worker); |
| 1502 | /* We are only interested in the first entry - local port */ |
| 1503 | struct qeth_sbp_port_entry *entry = &data->qports.entry[0]; |
| 1504 | char env_locrem[32]; |
| 1505 | char env_role[32]; |
| 1506 | char env_state[32]; |
| 1507 | char *env[] = { |
| 1508 | env_locrem, |
| 1509 | env_role, |
| 1510 | env_state, |
| 1511 | NULL |
| 1512 | }; |
| 1513 | |
| 1514 | /* Role should not change by itself, but if it did, */ |
| 1515 | /* information from the hardware is authoritative. */ |
| 1516 | mutex_lock(&data->card->conf_mutex); |
| 1517 | data->card->options.sbp.role = entry->role; |
| 1518 | mutex_unlock(&data->card->conf_mutex); |
| 1519 | |
| 1520 | snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange"); |
| 1521 | snprintf(env_role, sizeof(env_role), "ROLE=%s", |
| 1522 | (entry->role == QETH_SBP_ROLE_NONE) ? "none" : |
| 1523 | (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" : |
| 1524 | (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" : |
| 1525 | "<INVALID>"); |
| 1526 | snprintf(env_state, sizeof(env_state), "STATE=%s", |
| 1527 | (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" : |
| 1528 | (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" : |
| 1529 | (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" : |
| 1530 | "<INVALID>"); |
| 1531 | kobject_uevent_env(&data->card->gdev->dev.kobj, |
| 1532 | KOBJ_CHANGE, env); |
| 1533 | kfree(data); |
| 1534 | } |
| 1535 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1536 | static void qeth_bridge_state_change(struct qeth_card *card, |
| 1537 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1538 | { |
| 1539 | struct qeth_sbp_state_change *qports = |
| 1540 | &cmd->data.sbp.data.state_change; |
| 1541 | struct qeth_bridge_state_data *data; |
| 1542 | int extrasize; |
| 1543 | |
| 1544 | QETH_CARD_TEXT(card, 2, "brstchng"); |
| 1545 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
Thomas Richter | 8a59314 | 2014-10-22 12:18:03 +0200 | [diff] [blame] | 1546 | QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1547 | return; |
| 1548 | } |
| 1549 | extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries; |
| 1550 | data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize, |
| 1551 | GFP_ATOMIC); |
| 1552 | if (!data) { |
| 1553 | QETH_CARD_TEXT(card, 2, "BPSalloc"); |
| 1554 | return; |
| 1555 | } |
| 1556 | INIT_WORK(&data->worker, qeth_bridge_state_change_worker); |
| 1557 | data->card = card; |
| 1558 | memcpy(&data->qports, qports, |
| 1559 | sizeof(struct qeth_sbp_state_change) + extrasize); |
| 1560 | queue_work(qeth_wq, &data->worker); |
| 1561 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1562 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1563 | struct qeth_bridge_host_data { |
| 1564 | struct work_struct worker; |
| 1565 | struct qeth_card *card; |
| 1566 | struct qeth_ipacmd_addr_change hostevs; |
| 1567 | }; |
| 1568 | |
| 1569 | static void qeth_bridge_host_event_worker(struct work_struct *work) |
| 1570 | { |
| 1571 | struct qeth_bridge_host_data *data = |
| 1572 | container_of(work, struct qeth_bridge_host_data, worker); |
| 1573 | int i; |
| 1574 | |
| 1575 | if (data->hostevs.lost_event_mask) { |
| 1576 | dev_info(&data->card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1577 | "Address notification from the Bridge Port stopped %s (%s)\n", |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1578 | data->card->dev->name, |
| 1579 | (data->hostevs.lost_event_mask == 0x01) |
| 1580 | ? "Overflow" |
| 1581 | : (data->hostevs.lost_event_mask == 0x02) |
| 1582 | ? "Bridge port state change" |
| 1583 | : "Unknown reason"); |
| 1584 | mutex_lock(&data->card->conf_mutex); |
| 1585 | data->card->options.sbp.hostnotification = 0; |
| 1586 | mutex_unlock(&data->card->conf_mutex); |
| 1587 | qeth_bridge_emit_host_event(data->card, anev_abort, |
| 1588 | 0, NULL, NULL); |
| 1589 | } else |
| 1590 | for (i = 0; i < data->hostevs.num_entries; i++) { |
| 1591 | struct qeth_ipacmd_addr_change_entry *entry = |
| 1592 | &data->hostevs.entry[i]; |
| 1593 | qeth_bridge_emit_host_event(data->card, |
| 1594 | anev_reg_unreg, |
| 1595 | entry->change_code, |
| 1596 | &entry->token, &entry->addr_lnid); |
| 1597 | } |
| 1598 | kfree(data); |
| 1599 | } |
| 1600 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1601 | static void qeth_bridge_host_event(struct qeth_card *card, |
| 1602 | struct qeth_ipa_cmd *cmd) |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1603 | { |
| 1604 | struct qeth_ipacmd_addr_change *hostevs = |
| 1605 | &cmd->data.addrchange; |
| 1606 | struct qeth_bridge_host_data *data; |
| 1607 | int extrasize; |
| 1608 | |
| 1609 | QETH_CARD_TEXT(card, 2, "brhostev"); |
| 1610 | if (cmd->hdr.return_code != 0x0000) { |
| 1611 | if (cmd->hdr.return_code == 0x0010) { |
| 1612 | if (hostevs->lost_event_mask == 0x00) |
| 1613 | hostevs->lost_event_mask = 0xff; |
| 1614 | } else { |
| 1615 | QETH_CARD_TEXT_(card, 2, "BPHe%04x", |
| 1616 | cmd->hdr.return_code); |
| 1617 | return; |
| 1618 | } |
| 1619 | } |
| 1620 | extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) * |
| 1621 | hostevs->num_entries; |
| 1622 | data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize, |
| 1623 | GFP_ATOMIC); |
| 1624 | if (!data) { |
| 1625 | QETH_CARD_TEXT(card, 2, "BPHalloc"); |
| 1626 | return; |
| 1627 | } |
| 1628 | INIT_WORK(&data->worker, qeth_bridge_host_event_worker); |
| 1629 | data->card = card; |
| 1630 | memcpy(&data->hostevs, hostevs, |
| 1631 | sizeof(struct qeth_ipacmd_addr_change) + extrasize); |
| 1632 | queue_work(qeth_wq, &data->worker); |
| 1633 | } |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1634 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1635 | /* SETBRIDGEPORT support; sending commands */ |
| 1636 | |
| 1637 | struct _qeth_sbp_cbctl { |
| 1638 | u16 ipa_rc; |
| 1639 | u16 cmd_rc; |
| 1640 | union { |
| 1641 | u32 supported; |
| 1642 | struct { |
| 1643 | enum qeth_sbp_roles *role; |
| 1644 | enum qeth_sbp_states *state; |
| 1645 | } qports; |
| 1646 | } data; |
| 1647 | }; |
| 1648 | |
| 1649 | /** |
| 1650 | * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes. |
| 1651 | * @card: qeth_card structure pointer, for debug messages. |
| 1652 | * @cbctl: state structure with hardware return codes. |
| 1653 | * @setcmd: IPA command code |
| 1654 | * |
| 1655 | * Returns negative errno-compatible error indication or 0 on success. |
| 1656 | */ |
| 1657 | static int qeth_bridgeport_makerc(struct qeth_card *card, |
| 1658 | struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd) |
| 1659 | { |
| 1660 | int rc; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1661 | int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1662 | |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1663 | if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) || |
| 1664 | (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc))) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1665 | switch (cbctl->cmd_rc) { |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1666 | case IPA_RC_SUCCESS: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1667 | rc = 0; |
| 1668 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1669 | case IPA_RC_L2_UNSUPPORTED_CMD: |
| 1670 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1671 | rc = -EOPNOTSUPP; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1672 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1673 | case IPA_RC_SBP_OSA_NOT_CONFIGURED: |
| 1674 | case IPA_RC_SBP_IQD_NOT_CONFIGURED: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1675 | rc = -ENODEV; /* maybe not the best code here? */ |
| 1676 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1677 | "The device is not configured as a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1678 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1679 | case IPA_RC_SBP_OSA_OS_MISMATCH: |
| 1680 | case IPA_RC_SBP_IQD_OS_MISMATCH: |
Eugene Crosser | 1b05cf6 | 2016-06-16 16:18:51 +0200 | [diff] [blame] | 1681 | rc = -EPERM; |
| 1682 | dev_err(&card->gdev->dev, |
| 1683 | "A Bridge Port is already configured by a different operating system\n"); |
| 1684 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1685 | case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY: |
| 1686 | case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1687 | switch (setcmd) { |
| 1688 | case IPA_SBP_SET_PRIMARY_BRIDGE_PORT: |
| 1689 | rc = -EEXIST; |
| 1690 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1691 | "The LAN already has a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1692 | break; |
| 1693 | case IPA_SBP_SET_SECONDARY_BRIDGE_PORT: |
| 1694 | rc = -EBUSY; |
| 1695 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1696 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1697 | break; |
| 1698 | default: |
| 1699 | rc = -EIO; |
| 1700 | } |
| 1701 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1702 | case IPA_RC_SBP_OSA_CURRENT_SECOND: |
| 1703 | case IPA_RC_SBP_IQD_CURRENT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1704 | rc = -EBUSY; |
| 1705 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1706 | "The device is already a secondary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1707 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1708 | case IPA_RC_SBP_OSA_LIMIT_SECOND: |
| 1709 | case IPA_RC_SBP_IQD_LIMIT_SECOND: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1710 | rc = -EEXIST; |
| 1711 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1712 | "The LAN cannot have more secondary Bridge Ports\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1713 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1714 | case IPA_RC_SBP_OSA_CURRENT_PRIMARY: |
| 1715 | case IPA_RC_SBP_IQD_CURRENT_PRIMARY: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1716 | rc = -EBUSY; |
| 1717 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1718 | "The device is already a primary Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1719 | break; |
Kittipon Meesompop | 2063a5f | 2017-06-20 16:00:31 +0200 | [diff] [blame] | 1720 | case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN: |
| 1721 | case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN: |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1722 | rc = -EACCES; |
| 1723 | dev_err(&card->gdev->dev, |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1724 | "The device is not authorized to be a Bridge Port\n"); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1725 | break; |
| 1726 | default: |
| 1727 | rc = -EIO; |
| 1728 | } |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1729 | else |
| 1730 | switch (cbctl->ipa_rc) { |
| 1731 | case IPA_RC_NOTSUPP: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1732 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1733 | break; |
| 1734 | case IPA_RC_UNSUPPORTED_COMMAND: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1735 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1736 | break; |
| 1737 | default: |
| 1738 | rc = -EIO; |
| 1739 | } |
| 1740 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1741 | if (rc) { |
| 1742 | QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc); |
| 1743 | QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc); |
| 1744 | } |
| 1745 | return rc; |
| 1746 | } |
| 1747 | |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1748 | static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card, |
| 1749 | enum qeth_ipa_sbp_cmd sbp_cmd, |
| 1750 | unsigned int cmd_length) |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1751 | { |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1752 | enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ? |
| 1753 | IPA_CMD_SETBRIDGEPORT_IQD : |
| 1754 | IPA_CMD_SETBRIDGEPORT_OSA; |
| 1755 | struct qeth_cmd_buffer *iob; |
| 1756 | struct qeth_ipa_cmd *cmd; |
| 1757 | |
| 1758 | iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0); |
| 1759 | if (!iob) |
| 1760 | return iob; |
| 1761 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1762 | cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) + |
| 1763 | cmd_length; |
| 1764 | cmd->data.sbp.hdr.command_code = sbp_cmd; |
| 1765 | cmd->data.sbp.hdr.used_total = 1; |
| 1766 | cmd->data.sbp.hdr.seq_no = 1; |
| 1767 | return iob; |
Eugene Crosser | 9c23f4da | 2015-05-18 14:27:56 +0200 | [diff] [blame] | 1768 | } |
| 1769 | |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1770 | static int qeth_bridgeport_query_support_cb(struct qeth_card *card, |
| 1771 | struct qeth_reply *reply, unsigned long data) |
| 1772 | { |
| 1773 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1774 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1775 | QETH_CARD_TEXT(card, 2, "brqsupcb"); |
| 1776 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1777 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1778 | if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) { |
| 1779 | cbctl->data.supported = |
| 1780 | cmd->data.sbp.data.query_cmds_supp.supported_cmds; |
| 1781 | } else { |
| 1782 | cbctl->data.supported = 0; |
| 1783 | } |
| 1784 | return 0; |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * qeth_bridgeport_query_support() - store bitmask of supported subfunctions. |
| 1789 | * @card: qeth_card structure pointer. |
| 1790 | * |
| 1791 | * Sets bitmask of supported setbridgeport subfunctions in the qeth_card |
| 1792 | * strucutre: card->options.sbp.supported_funcs. |
| 1793 | */ |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 1794 | static void qeth_bridgeport_query_support(struct qeth_card *card) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1795 | { |
| 1796 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1797 | struct _qeth_sbp_cbctl cbctl; |
| 1798 | |
| 1799 | QETH_CARD_TEXT(card, 2, "brqsuppo"); |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1800 | iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED, |
| 1801 | sizeof(struct qeth_sbp_query_cmds_supp)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1802 | if (!iob) |
| 1803 | return; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1804 | if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb, |
| 1805 | (void *)&cbctl) || |
| 1806 | qeth_bridgeport_makerc(card, &cbctl, |
| 1807 | IPA_SBP_QUERY_COMMANDS_SUPPORTED)) { |
| 1808 | /* non-zero makerc signifies failure, and produce messages */ |
| 1809 | card->options.sbp.role = QETH_SBP_ROLE_NONE; |
| 1810 | return; |
| 1811 | } |
| 1812 | card->options.sbp.supported_funcs = cbctl.data.supported; |
| 1813 | } |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1814 | |
| 1815 | static int qeth_bridgeport_query_ports_cb(struct qeth_card *card, |
| 1816 | struct qeth_reply *reply, unsigned long data) |
| 1817 | { |
| 1818 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1819 | struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports; |
| 1820 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1821 | |
| 1822 | QETH_CARD_TEXT(card, 2, "brqprtcb"); |
| 1823 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1824 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1825 | if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0)) |
| 1826 | return 0; |
| 1827 | if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) { |
| 1828 | cbctl->cmd_rc = 0xffff; |
| 1829 | QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length); |
| 1830 | return 0; |
| 1831 | } |
| 1832 | /* first entry contains the state of the local port */ |
| 1833 | if (qports->num_entries > 0) { |
| 1834 | if (cbctl->data.qports.role) |
| 1835 | *cbctl->data.qports.role = qports->entry[0].role; |
| 1836 | if (cbctl->data.qports.state) |
| 1837 | *cbctl->data.qports.state = qports->entry[0].state; |
| 1838 | } |
| 1839 | return 0; |
| 1840 | } |
| 1841 | |
| 1842 | /** |
| 1843 | * qeth_bridgeport_query_ports() - query local bridgeport status. |
| 1844 | * @card: qeth_card structure pointer. |
| 1845 | * @role: Role of the port: 0-none, 1-primary, 2-secondary. |
| 1846 | * @state: State of the port: 0-inactive, 1-standby, 2-active. |
| 1847 | * |
| 1848 | * Returns negative errno-compatible error indication or 0 on success. |
| 1849 | * |
| 1850 | * 'role' and 'state' are not updated in case of hardware operation failure. |
| 1851 | */ |
| 1852 | int qeth_bridgeport_query_ports(struct qeth_card *card, |
| 1853 | enum qeth_sbp_roles *role, enum qeth_sbp_states *state) |
| 1854 | { |
| 1855 | int rc = 0; |
| 1856 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1857 | struct _qeth_sbp_cbctl cbctl = { |
| 1858 | .data = { |
| 1859 | .qports = { |
| 1860 | .role = role, |
| 1861 | .state = state, |
| 1862 | }, |
| 1863 | }, |
| 1864 | }; |
| 1865 | |
| 1866 | QETH_CARD_TEXT(card, 2, "brqports"); |
| 1867 | if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS)) |
| 1868 | return -EOPNOTSUPP; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1869 | iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1870 | if (!iob) |
| 1871 | return -ENOMEM; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1872 | rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb, |
| 1873 | (void *)&cbctl); |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1874 | if (rc < 0) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1875 | return rc; |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1876 | return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1877 | } |
| 1878 | EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports); |
| 1879 | |
| 1880 | static int qeth_bridgeport_set_cb(struct qeth_card *card, |
| 1881 | struct qeth_reply *reply, unsigned long data) |
| 1882 | { |
| 1883 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data; |
| 1884 | struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param; |
| 1885 | QETH_CARD_TEXT(card, 2, "brsetrcb"); |
| 1886 | cbctl->ipa_rc = cmd->hdr.return_code; |
| 1887 | cbctl->cmd_rc = cmd->data.sbp.hdr.return_code; |
| 1888 | return 0; |
| 1889 | } |
| 1890 | |
| 1891 | /** |
| 1892 | * qeth_bridgeport_setrole() - Assign primary role to the port. |
| 1893 | * @card: qeth_card structure pointer. |
| 1894 | * @role: Role to assign. |
| 1895 | * |
| 1896 | * Returns negative errno-compatible error indication or 0 on success. |
| 1897 | */ |
| 1898 | int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role) |
| 1899 | { |
| 1900 | int rc = 0; |
| 1901 | int cmdlength; |
| 1902 | struct qeth_cmd_buffer *iob; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1903 | struct _qeth_sbp_cbctl cbctl; |
| 1904 | enum qeth_ipa_sbp_cmd setcmd; |
| 1905 | |
| 1906 | QETH_CARD_TEXT(card, 2, "brsetrol"); |
| 1907 | switch (role) { |
| 1908 | case QETH_SBP_ROLE_NONE: |
| 1909 | setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1910 | cmdlength = sizeof(struct qeth_sbp_reset_role); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1911 | break; |
| 1912 | case QETH_SBP_ROLE_PRIMARY: |
| 1913 | setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1914 | cmdlength = sizeof(struct qeth_sbp_set_primary); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1915 | break; |
| 1916 | case QETH_SBP_ROLE_SECONDARY: |
| 1917 | setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1918 | cmdlength = sizeof(struct qeth_sbp_set_secondary); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1919 | break; |
| 1920 | default: |
| 1921 | return -EINVAL; |
| 1922 | } |
| 1923 | if (!(card->options.sbp.supported_funcs & setcmd)) |
| 1924 | return -EOPNOTSUPP; |
Julian Wiedmann | d65626a | 2017-08-15 17:02:47 +0200 | [diff] [blame] | 1925 | iob = qeth_sbp_build_cmd(card, setcmd, cmdlength); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1926 | if (!iob) |
| 1927 | return -ENOMEM; |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1928 | rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, |
| 1929 | (void *)&cbctl); |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1930 | if (rc < 0) |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1931 | return rc; |
Eugene Crosser | c88394e | 2015-05-18 14:27:53 +0200 | [diff] [blame] | 1932 | return qeth_bridgeport_makerc(card, &cbctl, setcmd); |
Eugene Crosser | b4d72c0 | 2014-01-14 15:54:11 +0100 | [diff] [blame] | 1933 | } |
| 1934 | |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1935 | /** |
| 1936 | * qeth_anset_makerc() - derive "traditional" error from hardware codes. |
| 1937 | * @card: qeth_card structure pointer, for debug messages. |
| 1938 | * |
| 1939 | * Returns negative errno-compatible error indication or 0 on success. |
| 1940 | */ |
| 1941 | static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response) |
| 1942 | { |
| 1943 | int rc; |
| 1944 | |
| 1945 | if (pnso_rc == 0) |
| 1946 | switch (response) { |
| 1947 | case 0x0001: |
| 1948 | rc = 0; |
| 1949 | break; |
| 1950 | case 0x0004: |
| 1951 | case 0x0100: |
| 1952 | case 0x0106: |
Eugene Crosser | ffb9525 | 2015-05-18 14:27:58 +0200 | [diff] [blame] | 1953 | rc = -EOPNOTSUPP; |
Eugene Crosser | 9f48b9d | 2014-01-14 15:54:13 +0100 | [diff] [blame] | 1954 | dev_err(&card->gdev->dev, |
| 1955 | "Setting address notification failed\n"); |
| 1956 | break; |
| 1957 | case 0x0107: |
| 1958 | rc = -EAGAIN; |
| 1959 | break; |
| 1960 | default: |
| 1961 | rc = -EIO; |
| 1962 | } |
| 1963 | else |
| 1964 | rc = -EIO; |
| 1965 | |
| 1966 | if (rc) { |
| 1967 | QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc); |
| 1968 | QETH_CARD_TEXT_(card, 2, "SBPr%04x", response); |
| 1969 | } |
| 1970 | return rc; |
| 1971 | } |
| 1972 | |
| 1973 | static void qeth_bridgeport_an_set_cb(void *priv, |
| 1974 | enum qdio_brinfo_entry_type type, void *entry) |
| 1975 | { |
| 1976 | struct qeth_card *card = (struct qeth_card *)priv; |
| 1977 | struct qdio_brinfo_entry_l2 *l2entry; |
| 1978 | u8 code; |
| 1979 | |
| 1980 | if (type != l2_addr_lnid) { |
| 1981 | WARN_ON_ONCE(1); |
| 1982 | return; |
| 1983 | } |
| 1984 | |
| 1985 | l2entry = (struct qdio_brinfo_entry_l2 *)entry; |
| 1986 | code = IPA_ADDR_CHANGE_CODE_MACADDR; |
| 1987 | if (l2entry->addr_lnid.lnid) |
| 1988 | code |= IPA_ADDR_CHANGE_CODE_VLANID; |
| 1989 | qeth_bridge_emit_host_event(card, anev_reg_unreg, code, |
| 1990 | (struct net_if_token *)&l2entry->nit, |
| 1991 | (struct mac_addr_lnid *)&l2entry->addr_lnid); |
| 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification |
| 1996 | * @card: qeth_card structure pointer. |
| 1997 | * @enable: 0 - disable, non-zero - enable notifications |
| 1998 | * |
| 1999 | * Returns negative errno-compatible error indication or 0 on success. |
| 2000 | * |
| 2001 | * On enable, emits a series of address notifications udev events for all |
| 2002 | * currently registered hosts. |
| 2003 | */ |
| 2004 | int qeth_bridgeport_an_set(struct qeth_card *card, int enable) |
| 2005 | { |
| 2006 | int rc; |
| 2007 | u16 response; |
| 2008 | struct ccw_device *ddev; |
| 2009 | struct subchannel_id schid; |
| 2010 | |
| 2011 | if (!card) |
| 2012 | return -EINVAL; |
| 2013 | if (!card->options.sbp.supported_funcs) |
| 2014 | return -EOPNOTSUPP; |
| 2015 | ddev = CARD_DDEV(card); |
| 2016 | ccw_device_get_schid(ddev, &schid); |
| 2017 | |
| 2018 | if (enable) { |
| 2019 | qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL); |
| 2020 | rc = qdio_pnso_brinfo(schid, 1, &response, |
| 2021 | qeth_bridgeport_an_set_cb, card); |
| 2022 | } else |
| 2023 | rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL); |
| 2024 | return qeth_anset_makerc(card, rc, response); |
| 2025 | } |
| 2026 | EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set); |
| 2027 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2028 | module_init(qeth_l2_init); |
| 2029 | module_exit(qeth_l2_exit); |
| 2030 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 2031 | MODULE_DESCRIPTION("qeth layer 2 discipline"); |
| 2032 | MODULE_LICENSE("GPL"); |