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