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