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