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" |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 24 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 25 | static int qeth_l2_set_offline(struct ccwgroup_device *); |
| 26 | static int qeth_l2_stop(struct net_device *); |
| 27 | static int qeth_l2_send_delmac(struct qeth_card *, __u8 *); |
| 28 | static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *, |
| 29 | enum qeth_ipa_cmds, |
| 30 | int (*reply_cb) (struct qeth_card *, |
| 31 | struct qeth_reply*, |
| 32 | unsigned long)); |
| 33 | static void qeth_l2_set_multicast_list(struct net_device *); |
| 34 | static int qeth_l2_recover(void *); |
| 35 | |
| 36 | static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 37 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 38 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 39 | struct mii_ioctl_data *mii_data; |
| 40 | int rc = 0; |
| 41 | |
| 42 | if (!card) |
| 43 | return -ENODEV; |
| 44 | |
| 45 | if ((card->state != CARD_STATE_UP) && |
| 46 | (card->state != CARD_STATE_SOFTSETUP)) |
| 47 | return -ENODEV; |
| 48 | |
| 49 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 50 | return -EPERM; |
| 51 | |
| 52 | switch (cmd) { |
| 53 | case SIOC_QETH_ADP_SET_SNMP_CONTROL: |
| 54 | rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data); |
| 55 | break; |
| 56 | case SIOC_QETH_GET_CARD_TYPE: |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 57 | if ((card->info.type == QETH_CARD_TYPE_OSD || |
| 58 | card->info.type == QETH_CARD_TYPE_OSM || |
| 59 | card->info.type == QETH_CARD_TYPE_OSX) && |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 60 | !card->info.guestlan) |
| 61 | return 1; |
| 62 | return 0; |
| 63 | break; |
| 64 | case SIOCGMIIPHY: |
| 65 | mii_data = if_mii(rq); |
| 66 | mii_data->phy_id = 0; |
| 67 | break; |
| 68 | case SIOCGMIIREG: |
| 69 | mii_data = if_mii(rq); |
| 70 | if (mii_data->phy_id != 0) |
| 71 | rc = -EINVAL; |
| 72 | else |
| 73 | mii_data->val_out = qeth_mdio_read(dev, |
| 74 | mii_data->phy_id, mii_data->reg_num); |
| 75 | break; |
Frank Blaschka | c3ab96f | 2012-02-08 00:19:49 +0000 | [diff] [blame] | 76 | case SIOC_QETH_QUERY_OAT: |
| 77 | rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data); |
| 78 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 79 | default: |
| 80 | rc = -EOPNOTSUPP; |
| 81 | } |
| 82 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 83 | QETH_CARD_TEXT_(card, 2, "ioce%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 84 | return rc; |
| 85 | } |
| 86 | |
| 87 | static int qeth_l2_verify_dev(struct net_device *dev) |
| 88 | { |
| 89 | struct qeth_card *card; |
| 90 | unsigned long flags; |
| 91 | int rc = 0; |
| 92 | |
| 93 | read_lock_irqsave(&qeth_core_card_list.rwlock, flags); |
| 94 | list_for_each_entry(card, &qeth_core_card_list.list, list) { |
| 95 | if (card->dev == dev) { |
| 96 | rc = QETH_REAL_CARD; |
| 97 | break; |
| 98 | } |
| 99 | } |
| 100 | read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); |
| 101 | |
| 102 | return rc; |
| 103 | } |
| 104 | |
| 105 | static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no) |
| 106 | { |
| 107 | struct qeth_card *card; |
| 108 | struct net_device *ndev; |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 109 | __u16 temp_dev_no; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 110 | unsigned long flags; |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 111 | struct ccw_dev_id read_devid; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 112 | |
| 113 | ndev = NULL; |
| 114 | memcpy(&temp_dev_no, read_dev_no, 2); |
| 115 | read_lock_irqsave(&qeth_core_card_list.rwlock, flags); |
| 116 | list_for_each_entry(card, &qeth_core_card_list.list, list) { |
Cornelia Huck | f06f6f3 | 2008-06-06 12:37:45 +0200 | [diff] [blame] | 117 | ccw_device_get_id(CARD_RDEV(card), &read_devid); |
| 118 | if (read_devid.devno == temp_dev_no) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 119 | ndev = card->dev; |
| 120 | break; |
| 121 | } |
| 122 | } |
| 123 | read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); |
| 124 | return ndev; |
| 125 | } |
| 126 | |
| 127 | static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card, |
| 128 | struct qeth_reply *reply, |
| 129 | unsigned long data) |
| 130 | { |
| 131 | struct qeth_ipa_cmd *cmd; |
| 132 | __u8 *mac; |
| 133 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 134 | QETH_CARD_TEXT(card, 2, "L2Sgmacb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 135 | cmd = (struct qeth_ipa_cmd *) data; |
| 136 | mac = &cmd->data.setdelmac.mac[0]; |
| 137 | /* MAC already registered, needed in couple/uncouple case */ |
Ursula Braun | 0666eb06 | 2009-05-19 21:38:39 +0000 | [diff] [blame] | 138 | if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) { |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 139 | QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n", |
| 140 | mac, QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 141 | cmd->hdr.return_code = 0; |
| 142 | } |
| 143 | if (cmd->hdr.return_code) |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 144 | QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n", |
| 145 | mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac) |
| 150 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 151 | QETH_CARD_TEXT(card, 2, "L2Sgmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 152 | return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC, |
| 153 | qeth_l2_send_setgroupmac_cb); |
| 154 | } |
| 155 | |
| 156 | static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card, |
| 157 | struct qeth_reply *reply, |
| 158 | unsigned long data) |
| 159 | { |
| 160 | struct qeth_ipa_cmd *cmd; |
| 161 | __u8 *mac; |
| 162 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 163 | QETH_CARD_TEXT(card, 2, "L2Dgmacb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 164 | cmd = (struct qeth_ipa_cmd *) data; |
| 165 | mac = &cmd->data.setdelmac.mac[0]; |
| 166 | if (cmd->hdr.return_code) |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 167 | QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n", |
| 168 | mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac) |
| 173 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 174 | QETH_CARD_TEXT(card, 2, "L2Dgmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 175 | return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC, |
| 176 | qeth_l2_send_delgroupmac_cb); |
| 177 | } |
| 178 | |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 179 | 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] | 180 | { |
| 181 | struct qeth_mc_mac *mc; |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 182 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 183 | |
| 184 | mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC); |
| 185 | |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 186 | if (!mc) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 187 | return; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 188 | |
| 189 | memcpy(mc->mc_addr, mac, OSA_ADDR_LEN); |
| 190 | mc->mc_addrlen = OSA_ADDR_LEN; |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 191 | mc->is_vmac = vmac; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 192 | |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 193 | if (vmac) { |
| 194 | rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC, |
| 195 | NULL); |
| 196 | } else { |
| 197 | rc = qeth_l2_send_setgroupmac(card, mac); |
| 198 | } |
| 199 | |
| 200 | if (!rc) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 201 | list_add_tail(&mc->list, &card->mc_list); |
| 202 | else |
| 203 | kfree(mc); |
| 204 | } |
| 205 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 206 | 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] | 207 | { |
| 208 | struct qeth_mc_mac *mc, *tmp; |
| 209 | |
| 210 | spin_lock_bh(&card->mclock); |
| 211 | list_for_each_entry_safe(mc, tmp, &card->mc_list, list) { |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 212 | if (del) { |
| 213 | if (mc->is_vmac) |
| 214 | qeth_l2_send_setdelmac(card, mc->mc_addr, |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 215 | IPA_CMD_DELVMAC, NULL); |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 216 | else |
| 217 | qeth_l2_send_delgroupmac(card, mc->mc_addr); |
| 218 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 219 | list_del(&mc->list); |
| 220 | kfree(mc); |
| 221 | } |
| 222 | spin_unlock_bh(&card->mclock); |
| 223 | } |
| 224 | |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 225 | static inline int qeth_l2_get_cast_type(struct qeth_card *card, |
| 226 | struct sk_buff *skb) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 227 | { |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 228 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 229 | return RTN_UNSPEC; |
| 230 | if (is_broadcast_ether_addr(skb->data)) |
| 231 | return RTN_BROADCAST; |
| 232 | if (is_multicast_ether_addr(skb->data)) |
| 233 | return RTN_MULTICAST; |
| 234 | return RTN_UNSPEC; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
| 238 | struct sk_buff *skb, int ipv, int cast_type) |
| 239 | { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 240 | struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 241 | |
| 242 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 243 | hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2; |
| 244 | |
| 245 | /* set byte byte 3 to casting flags */ |
| 246 | if (cast_type == RTN_MULTICAST) |
| 247 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST; |
| 248 | else if (cast_type == RTN_BROADCAST) |
| 249 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST; |
| 250 | else |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 251 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 252 | |
| 253 | hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE; |
| 254 | /* VSWITCH relies on the VLAN |
| 255 | * information to be present in |
| 256 | * the QDIO header */ |
| 257 | if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { |
| 258 | hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN; |
| 259 | hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card, |
| 264 | struct qeth_reply *reply, unsigned long data) |
| 265 | { |
| 266 | struct qeth_ipa_cmd *cmd; |
| 267 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 268 | QETH_CARD_TEXT(card, 2, "L2sdvcb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 269 | cmd = (struct qeth_ipa_cmd *) data; |
| 270 | if (cmd->hdr.return_code) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 271 | 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] | 272 | "Continuing\n", cmd->data.setdelvlan.vlan_id, |
| 273 | QETH_CARD_IFNAME(card), cmd->hdr.return_code); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 274 | QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command); |
| 275 | QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i, |
| 281 | enum qeth_ipa_cmds ipacmd) |
| 282 | { |
| 283 | struct qeth_ipa_cmd *cmd; |
| 284 | struct qeth_cmd_buffer *iob; |
| 285 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 286 | QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 287 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 288 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 289 | cmd->data.setdelvlan.vlan_id = i; |
| 290 | return qeth_send_ipa_cmd(card, iob, |
| 291 | qeth_l2_send_setdelvlan_cb, NULL); |
| 292 | } |
| 293 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 294 | static void qeth_l2_process_vlans(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 295 | { |
| 296 | struct qeth_vlan_vid *id; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 297 | QETH_CARD_TEXT(card, 3, "L2prcvln"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 298 | spin_lock_bh(&card->vlanlock); |
| 299 | list_for_each_entry(id, &card->vid_list, list) { |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 300 | qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 301 | } |
| 302 | spin_unlock_bh(&card->vlanlock); |
| 303 | } |
| 304 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 305 | static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 306 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 307 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 308 | struct qeth_vlan_vid *id; |
| 309 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 310 | QETH_CARD_TEXT_(card, 4, "aid:%d", vid); |
Ursula Braun | 10651db | 2010-10-01 02:51:13 +0000 | [diff] [blame] | 311 | if (!vid) |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 312 | return 0; |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 313 | if (card->info.type == QETH_CARD_TYPE_OSM) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 314 | QETH_CARD_TEXT(card, 3, "aidOSM"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 315 | return 0; |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 316 | } |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 317 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 318 | QETH_CARD_TEXT(card, 3, "aidREC"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 319 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 320 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 321 | id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC); |
| 322 | if (id) { |
| 323 | id->vid = vid; |
| 324 | qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN); |
| 325 | spin_lock_bh(&card->vlanlock); |
| 326 | list_add_tail(&id->list, &card->vid_list); |
| 327 | spin_unlock_bh(&card->vlanlock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 328 | } else { |
| 329 | return -ENOMEM; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 330 | } |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 331 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 334 | static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 335 | { |
| 336 | struct qeth_vlan_vid *id, *tmpid = NULL; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 337 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 338 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 339 | QETH_CARD_TEXT_(card, 4, "kid:%d", vid); |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 340 | if (card->info.type == QETH_CARD_TYPE_OSM) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 341 | QETH_CARD_TEXT(card, 3, "kidOSM"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 342 | return 0; |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 343 | } |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 344 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 345 | QETH_CARD_TEXT(card, 3, "kidREC"); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 346 | return 0; |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 347 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 348 | spin_lock_bh(&card->vlanlock); |
| 349 | list_for_each_entry(id, &card->vid_list, list) { |
| 350 | if (id->vid == vid) { |
| 351 | list_del(&id->list); |
| 352 | tmpid = id; |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | spin_unlock_bh(&card->vlanlock); |
| 357 | if (tmpid) { |
| 358 | qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN); |
| 359 | kfree(tmpid); |
| 360 | } |
| 361 | qeth_l2_set_multicast_list(card->dev); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 362 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode) |
| 366 | { |
| 367 | int rc = 0; |
| 368 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 369 | QETH_DBF_TEXT(SETUP , 2, "stopcard"); |
| 370 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 371 | |
| 372 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 373 | if (card->read.state == CH_STATE_UP && |
| 374 | card->write.state == CH_STATE_UP && |
| 375 | (card->state == CARD_STATE_UP)) { |
| 376 | if (recovery_mode && |
| 377 | card->info.type != QETH_CARD_TYPE_OSN) { |
| 378 | qeth_l2_stop(card->dev); |
| 379 | } else { |
| 380 | rtnl_lock(); |
| 381 | dev_close(card->dev); |
| 382 | rtnl_unlock(); |
| 383 | } |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 384 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 385 | card->state = CARD_STATE_SOFTSETUP; |
| 386 | } |
| 387 | if (card->state == CARD_STATE_SOFTSETUP) { |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 388 | qeth_l2_del_all_mc(card, 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 389 | qeth_clear_ipacmd_list(card); |
| 390 | card->state = CARD_STATE_HARDSETUP; |
| 391 | } |
| 392 | if (card->state == CARD_STATE_HARDSETUP) { |
| 393 | qeth_qdio_clear_card(card, 0); |
| 394 | qeth_clear_qdio_buffers(card); |
| 395 | qeth_clear_working_pool_list(card); |
| 396 | card->state = CARD_STATE_DOWN; |
| 397 | } |
| 398 | if (card->state == CARD_STATE_DOWN) { |
| 399 | qeth_clear_cmd_buffers(&card->read); |
| 400 | qeth_clear_cmd_buffers(&card->write); |
| 401 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 402 | return rc; |
| 403 | } |
| 404 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 405 | static int qeth_l2_process_inbound_buffer(struct qeth_card *card, |
| 406 | int budget, int *done) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 407 | { |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 408 | int work_done = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 409 | struct sk_buff *skb; |
| 410 | struct qeth_hdr *hdr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 411 | unsigned int len; |
| 412 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 413 | *done = 0; |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 414 | WARN_ON_ONCE(!budget); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 415 | while (budget) { |
| 416 | skb = qeth_core_get_next_skb(card, |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 417 | &card->qdio.in_q->bufs[card->rx.b_index], |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 418 | &card->rx.b_element, &card->rx.e_offset, &hdr); |
| 419 | if (!skb) { |
| 420 | *done = 1; |
| 421 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 422 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 423 | skb->dev = card->dev; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 424 | switch (hdr->hdr.l2.id) { |
| 425 | case QETH_HEADER_TYPE_LAYER2: |
| 426 | skb->pkt_type = PACKET_HOST; |
| 427 | skb->protocol = eth_type_trans(skb, skb->dev); |
Frank Blaschka | c5e631a | 2011-05-12 18:45:01 +0000 | [diff] [blame] | 428 | skb->ip_summed = CHECKSUM_NONE; |
Ursula Braun | 1288372 | 2008-04-01 10:26:56 +0200 | [diff] [blame] | 429 | if (skb->protocol == htons(ETH_P_802_2)) |
| 430 | *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 431 | len = skb->len; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 432 | netif_receive_skb(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 433 | break; |
| 434 | case QETH_HEADER_TYPE_OSN: |
Ursula Braun | 2d488c2 | 2008-10-24 11:16:55 +0200 | [diff] [blame] | 435 | if (card->info.type == QETH_CARD_TYPE_OSN) { |
| 436 | skb_push(skb, sizeof(struct qeth_hdr)); |
| 437 | skb_copy_to_linear_data(skb, hdr, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 438 | sizeof(struct qeth_hdr)); |
Ursula Braun | 2d488c2 | 2008-10-24 11:16:55 +0200 | [diff] [blame] | 439 | len = skb->len; |
| 440 | card->osn_info.data_cb(skb); |
| 441 | break; |
| 442 | } |
| 443 | /* else unknown */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 444 | default: |
| 445 | dev_kfree_skb_any(skb); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 446 | QETH_CARD_TEXT(card, 3, "inbunkno"); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 447 | QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 448 | continue; |
| 449 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 450 | work_done++; |
| 451 | budget--; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 452 | card->stats.rx_packets++; |
| 453 | card->stats.rx_bytes += len; |
| 454 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 455 | return work_done; |
| 456 | } |
| 457 | |
| 458 | static int qeth_l2_poll(struct napi_struct *napi, int budget) |
| 459 | { |
| 460 | struct qeth_card *card = container_of(napi, struct qeth_card, napi); |
| 461 | int work_done = 0; |
| 462 | struct qeth_qdio_buffer *buffer; |
| 463 | int done; |
| 464 | int new_budget = budget; |
| 465 | |
| 466 | if (card->options.performance_stats) { |
| 467 | card->perf_stats.inbound_cnt++; |
| 468 | card->perf_stats.inbound_start_time = qeth_get_micros(); |
| 469 | } |
| 470 | |
| 471 | while (1) { |
| 472 | if (!card->rx.b_count) { |
| 473 | card->rx.qdio_err = 0; |
| 474 | card->rx.b_count = qdio_get_next_buffers( |
| 475 | card->data.ccwdev, 0, &card->rx.b_index, |
| 476 | &card->rx.qdio_err); |
| 477 | if (card->rx.b_count <= 0) { |
| 478 | card->rx.b_count = 0; |
| 479 | break; |
| 480 | } |
| 481 | card->rx.b_element = |
| 482 | &card->qdio.in_q->bufs[card->rx.b_index] |
| 483 | .buffer->element[0]; |
| 484 | card->rx.e_offset = 0; |
| 485 | } |
| 486 | |
| 487 | while (card->rx.b_count) { |
| 488 | buffer = &card->qdio.in_q->bufs[card->rx.b_index]; |
| 489 | if (!(card->rx.qdio_err && |
| 490 | qeth_check_qdio_errors(card, buffer->buffer, |
| 491 | card->rx.qdio_err, "qinerr"))) |
| 492 | work_done += qeth_l2_process_inbound_buffer( |
| 493 | card, new_budget, &done); |
| 494 | else |
| 495 | done = 1; |
| 496 | |
| 497 | if (done) { |
| 498 | if (card->options.performance_stats) |
| 499 | card->perf_stats.bufs_rec++; |
| 500 | qeth_put_buffer_pool_entry(card, |
| 501 | buffer->pool_entry); |
| 502 | qeth_queue_input_buffer(card, card->rx.b_index); |
| 503 | card->rx.b_count--; |
| 504 | if (card->rx.b_count) { |
| 505 | card->rx.b_index = |
| 506 | (card->rx.b_index + 1) % |
| 507 | QDIO_MAX_BUFFERS_PER_Q; |
| 508 | card->rx.b_element = |
| 509 | &card->qdio.in_q |
| 510 | ->bufs[card->rx.b_index] |
| 511 | .buffer->element[0]; |
| 512 | card->rx.e_offset = 0; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | if (work_done >= budget) |
| 517 | goto out; |
| 518 | else |
| 519 | new_budget = budget - work_done; |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | napi_complete(napi); |
| 524 | if (qdio_start_irq(card->data.ccwdev, 0)) |
| 525 | napi_schedule(&card->napi); |
| 526 | out: |
| 527 | if (card->options.performance_stats) |
| 528 | card->perf_stats.inbound_time += qeth_get_micros() - |
| 529 | card->perf_stats.inbound_start_time; |
| 530 | return work_done; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac, |
| 534 | enum qeth_ipa_cmds ipacmd, |
| 535 | int (*reply_cb) (struct qeth_card *, |
| 536 | struct qeth_reply*, |
| 537 | unsigned long)) |
| 538 | { |
| 539 | struct qeth_ipa_cmd *cmd; |
| 540 | struct qeth_cmd_buffer *iob; |
| 541 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 542 | QETH_CARD_TEXT(card, 2, "L2sdmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 543 | iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4); |
| 544 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 545 | cmd->data.setdelmac.mac_length = OSA_ADDR_LEN; |
| 546 | memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN); |
| 547 | return qeth_send_ipa_cmd(card, iob, reply_cb, NULL); |
| 548 | } |
| 549 | |
| 550 | static int qeth_l2_send_setmac_cb(struct qeth_card *card, |
| 551 | struct qeth_reply *reply, |
| 552 | unsigned long data) |
| 553 | { |
| 554 | struct qeth_ipa_cmd *cmd; |
| 555 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 556 | QETH_CARD_TEXT(card, 2, "L2Smaccb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 557 | cmd = (struct qeth_ipa_cmd *) data; |
| 558 | if (cmd->hdr.return_code) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 559 | QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 560 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
Ursula Braun | 0666eb06 | 2009-05-19 21:38:39 +0000 | [diff] [blame] | 561 | switch (cmd->hdr.return_code) { |
| 562 | case IPA_RC_L2_DUP_MAC: |
| 563 | case IPA_RC_L2_DUP_LAYER3_MAC: |
| 564 | dev_warn(&card->gdev->dev, |
H Hartley Sweeten | d998ab0 | 2009-12-29 20:05:37 -0800 | [diff] [blame] | 565 | "MAC address %pM already exists\n", |
Ursula Braun | 221c17f | 2011-02-02 06:04:31 +0000 | [diff] [blame] | 566 | cmd->data.setdelmac.mac); |
Ursula Braun | 0666eb06 | 2009-05-19 21:38:39 +0000 | [diff] [blame] | 567 | break; |
| 568 | case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP: |
| 569 | case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP: |
| 570 | dev_warn(&card->gdev->dev, |
H Hartley Sweeten | d998ab0 | 2009-12-29 20:05:37 -0800 | [diff] [blame] | 571 | "MAC address %pM is not authorized\n", |
Ursula Braun | 221c17f | 2011-02-02 06:04:31 +0000 | [diff] [blame] | 572 | cmd->data.setdelmac.mac); |
Ursula Braun | 0666eb06 | 2009-05-19 21:38:39 +0000 | [diff] [blame] | 573 | break; |
| 574 | default: |
| 575 | break; |
| 576 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 577 | } else { |
| 578 | card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED; |
| 579 | memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac, |
| 580 | OSA_ADDR_LEN); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 581 | dev_info(&card->gdev->dev, |
H Hartley Sweeten | d998ab0 | 2009-12-29 20:05:37 -0800 | [diff] [blame] | 582 | "MAC address %pM successfully registered on device %s\n", |
| 583 | card->dev->dev_addr, card->dev->name); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 584 | } |
| 585 | return 0; |
| 586 | } |
| 587 | |
| 588 | static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac) |
| 589 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 590 | QETH_CARD_TEXT(card, 2, "L2Setmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 591 | return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC, |
| 592 | qeth_l2_send_setmac_cb); |
| 593 | } |
| 594 | |
| 595 | static int qeth_l2_send_delmac_cb(struct qeth_card *card, |
| 596 | struct qeth_reply *reply, |
| 597 | unsigned long data) |
| 598 | { |
| 599 | struct qeth_ipa_cmd *cmd; |
| 600 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 601 | QETH_CARD_TEXT(card, 2, "L2Dmaccb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 602 | cmd = (struct qeth_ipa_cmd *) data; |
| 603 | if (cmd->hdr.return_code) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 604 | QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 605 | return 0; |
| 606 | } |
| 607 | card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac) |
| 613 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 614 | QETH_CARD_TEXT(card, 2, "L2Delmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 615 | if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)) |
| 616 | return 0; |
| 617 | return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC, |
| 618 | qeth_l2_send_delmac_cb); |
| 619 | } |
| 620 | |
| 621 | static int qeth_l2_request_initial_mac(struct qeth_card *card) |
| 622 | { |
| 623 | int rc = 0; |
| 624 | char vendor_pre[] = {0x02, 0x00, 0x00}; |
| 625 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 626 | QETH_DBF_TEXT(SETUP, 2, "doL2init"); |
| 627 | QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 628 | |
Stefan Raspl | a134884 | 2012-11-12 23:05:16 +0000 | [diff] [blame] | 629 | if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) { |
| 630 | rc = qeth_query_setadapterparms(card); |
| 631 | if (rc) { |
| 632 | QETH_DBF_MESSAGE(2, "could not query adapter " |
| 633 | "parameters on device %s: x%x\n", |
| 634 | CARD_BUS_ID(card), rc); |
| 635 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 638 | if (card->info.type == QETH_CARD_TYPE_IQD || |
| 639 | card->info.type == QETH_CARD_TYPE_OSM || |
| 640 | card->info.type == QETH_CARD_TYPE_OSX || |
| 641 | card->info.guestlan) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 642 | rc = qeth_setadpparms_change_macaddr(card); |
| 643 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 644 | QETH_DBF_MESSAGE(2, "couldn't get MAC address on " |
| 645 | "device %s: x%x\n", CARD_BUS_ID(card), rc); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 646 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 647 | return rc; |
| 648 | } |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 649 | QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 650 | } else { |
Joe Perches | 1833611 | 2012-07-12 22:33:10 -0700 | [diff] [blame] | 651 | eth_random_addr(card->dev->dev_addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 652 | memcpy(card->dev->dev_addr, vendor_pre, 3); |
| 653 | } |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static int qeth_l2_set_mac_address(struct net_device *dev, void *p) |
| 658 | { |
| 659 | struct sockaddr *addr = p; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 660 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 661 | int rc = 0; |
| 662 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 663 | QETH_CARD_TEXT(card, 3, "setmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 664 | |
| 665 | if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 666 | QETH_CARD_TEXT(card, 3, "setmcINV"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 667 | return -EOPNOTSUPP; |
| 668 | } |
| 669 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 670 | if (card->info.type == QETH_CARD_TYPE_OSN || |
| 671 | card->info.type == QETH_CARD_TYPE_OSM || |
| 672 | card->info.type == QETH_CARD_TYPE_OSX) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 673 | QETH_CARD_TEXT(card, 3, "setmcTYP"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 674 | return -EOPNOTSUPP; |
| 675 | } |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 676 | QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 677 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 678 | QETH_CARD_TEXT(card, 3, "setmcREC"); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 679 | return -ERESTARTSYS; |
| 680 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 681 | rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]); |
Ursula Braun | 7702745 | 2012-11-12 23:05:17 +0000 | [diff] [blame] | 682 | if (!rc || (rc == IPA_RC_L2_MAC_NOT_FOUND)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 683 | rc = qeth_l2_send_setmac(card, addr->sa_data); |
Ursula Braun | e0a8114 | 2012-03-07 02:06:28 +0000 | [diff] [blame] | 684 | return rc ? -EINVAL : 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | static void qeth_l2_set_multicast_list(struct net_device *dev) |
| 688 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 689 | struct qeth_card *card = dev->ml_priv; |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 690 | struct netdev_hw_addr *ha; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 691 | |
| 692 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 693 | return ; |
| 694 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 695 | QETH_CARD_TEXT(card, 3, "setmulti"); |
Ursula Braun | 8e98ac4 | 2009-03-24 20:57:18 +0000 | [diff] [blame] | 696 | if (qeth_threads_running(card, QETH_RECOVER_THREAD) && |
| 697 | (card->state != CARD_STATE_UP)) |
| 698 | return; |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 699 | qeth_l2_del_all_mc(card, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 700 | spin_lock_bh(&card->mclock); |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 701 | netdev_for_each_mc_addr(ha, dev) |
| 702 | qeth_l2_add_mc(card, ha->addr, 0); |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 703 | |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 704 | netdev_for_each_uc_addr(ha, dev) |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 705 | qeth_l2_add_mc(card, ha->addr, 1); |
Frank Blaschka | 7db2266 | 2008-08-15 08:02:59 +0200 | [diff] [blame] | 706 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 707 | spin_unlock_bh(&card->mclock); |
| 708 | if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 709 | return; |
| 710 | qeth_setadp_promisc_mode(card); |
| 711 | } |
| 712 | |
| 713 | static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 714 | { |
| 715 | int rc; |
| 716 | struct qeth_hdr *hdr = NULL; |
| 717 | int elements = 0; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 718 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 719 | struct sk_buff *new_skb = skb; |
| 720 | int ipv = qeth_get_ip_version(skb); |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 721 | int cast_type = qeth_l2_get_cast_type(card, skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 722 | struct qeth_qdio_out_q *queue = card->qdio.out_qs |
| 723 | [qeth_get_priority_queue(card, skb, ipv, cast_type)]; |
| 724 | int tx_bytes = skb->len; |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 725 | int data_offset = -1; |
| 726 | int elements_needed = 0; |
| 727 | int hd_len = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 728 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 729 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 730 | card->stats.tx_carrier_errors++; |
| 731 | goto tx_drop; |
| 732 | } |
| 733 | |
| 734 | if ((card->info.type == QETH_CARD_TYPE_OSN) && |
| 735 | (skb->protocol == htons(ETH_P_IPV6))) |
| 736 | goto tx_drop; |
| 737 | |
| 738 | if (card->options.performance_stats) { |
| 739 | card->perf_stats.outbound_cnt++; |
| 740 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 741 | } |
| 742 | netif_stop_queue(dev); |
| 743 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 744 | if (card->info.type == QETH_CARD_TYPE_OSN) |
| 745 | hdr = (struct qeth_hdr *)skb->data; |
| 746 | else { |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 747 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 748 | new_skb = skb; |
| 749 | data_offset = ETH_HLEN; |
| 750 | hd_len = ETH_HLEN; |
| 751 | hdr = kmem_cache_alloc(qeth_core_header_cache, |
| 752 | GFP_ATOMIC); |
| 753 | if (!hdr) |
| 754 | goto tx_drop; |
| 755 | elements_needed++; |
| 756 | skb_reset_mac_header(new_skb); |
| 757 | qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type); |
| 758 | hdr->hdr.l2.pkt_length = new_skb->len; |
| 759 | memcpy(((char *)hdr) + sizeof(struct qeth_hdr), |
| 760 | skb_mac_header(new_skb), ETH_HLEN); |
| 761 | } else { |
| 762 | /* create a clone with writeable headroom */ |
| 763 | new_skb = skb_realloc_headroom(skb, |
Frank Blaschka | f90b744 | 2008-04-24 10:15:24 +0200 | [diff] [blame] | 764 | sizeof(struct qeth_hdr)); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 765 | if (!new_skb) |
| 766 | goto tx_drop; |
| 767 | hdr = (struct qeth_hdr *)skb_push(new_skb, |
| 768 | sizeof(struct qeth_hdr)); |
| 769 | skb_set_mac_header(new_skb, sizeof(struct qeth_hdr)); |
| 770 | qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type); |
| 771 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 772 | } |
| 773 | |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 774 | elements = qeth_get_elements_no(card, (void *)hdr, new_skb, |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 775 | elements_needed); |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 776 | if (!elements) { |
| 777 | if (data_offset >= 0) |
| 778 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 779 | goto tx_drop; |
Frank Blaschka | f61a0d0 | 2009-03-24 20:57:15 +0000 | [diff] [blame] | 780 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 781 | |
Frank Blaschka | 51aa165 | 2010-06-21 22:57:10 +0000 | [diff] [blame] | 782 | if (card->info.type != QETH_CARD_TYPE_IQD) { |
| 783 | if (qeth_hdr_chk_and_bounce(new_skb, |
| 784 | sizeof(struct qeth_hdr_layer2))) |
| 785 | goto tx_drop; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 786 | rc = qeth_do_send_packet(card, queue, new_skb, hdr, |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 787 | elements); |
Frank Blaschka | 51aa165 | 2010-06-21 22:57:10 +0000 | [diff] [blame] | 788 | } else |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 789 | rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr, |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 790 | elements, data_offset, hd_len); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 791 | if (!rc) { |
| 792 | card->stats.tx_packets++; |
| 793 | card->stats.tx_bytes += tx_bytes; |
| 794 | if (new_skb != skb) |
| 795 | dev_kfree_skb_any(skb); |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 796 | rc = NETDEV_TX_OK; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 797 | } else { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 798 | if (data_offset >= 0) |
| 799 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 800 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 801 | if (rc == -EBUSY) { |
| 802 | if (new_skb != skb) |
| 803 | dev_kfree_skb_any(new_skb); |
| 804 | return NETDEV_TX_BUSY; |
| 805 | } else |
| 806 | goto tx_drop; |
| 807 | } |
| 808 | |
| 809 | netif_wake_queue(dev); |
| 810 | if (card->options.performance_stats) |
| 811 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 812 | card->perf_stats.outbound_start_time; |
| 813 | return rc; |
| 814 | |
| 815 | tx_drop: |
| 816 | card->stats.tx_dropped++; |
| 817 | card->stats.tx_errors++; |
| 818 | if ((new_skb != skb) && new_skb) |
| 819 | dev_kfree_skb_any(new_skb); |
| 820 | dev_kfree_skb_any(skb); |
Frank Blaschka | d0ec0f5 | 2008-06-06 12:37:48 +0200 | [diff] [blame] | 821 | netif_wake_queue(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 822 | return NETDEV_TX_OK; |
| 823 | } |
| 824 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 825 | static int __qeth_l2_open(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 826 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 827 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 828 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 829 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 830 | QETH_CARD_TEXT(card, 4, "qethopen"); |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 831 | if (card->state == CARD_STATE_UP) |
| 832 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 833 | if (card->state != CARD_STATE_SOFTSETUP) |
| 834 | return -ENODEV; |
| 835 | |
| 836 | if ((card->info.type != QETH_CARD_TYPE_OSN) && |
| 837 | (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 838 | QETH_CARD_TEXT(card, 4, "nomacadr"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 839 | return -EPERM; |
| 840 | } |
| 841 | card->data.state = CH_STATE_UP; |
| 842 | card->state = CARD_STATE_UP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 843 | netif_start_queue(dev); |
| 844 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 845 | if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) { |
| 846 | napi_enable(&card->napi); |
| 847 | napi_schedule(&card->napi); |
| 848 | } else |
| 849 | rc = -EIO; |
| 850 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 853 | static int qeth_l2_open(struct net_device *dev) |
| 854 | { |
| 855 | struct qeth_card *card = dev->ml_priv; |
| 856 | |
| 857 | QETH_CARD_TEXT(card, 5, "qethope_"); |
| 858 | if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) { |
| 859 | QETH_CARD_TEXT(card, 3, "openREC"); |
| 860 | return -ERESTARTSYS; |
| 861 | } |
| 862 | return __qeth_l2_open(dev); |
| 863 | } |
| 864 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 865 | static int qeth_l2_stop(struct net_device *dev) |
| 866 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 867 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 868 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 869 | QETH_CARD_TEXT(card, 4, "qethstop"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 870 | netif_tx_disable(dev); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 871 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 872 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 873 | napi_disable(&card->napi); |
| 874 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | static int qeth_l2_probe_device(struct ccwgroup_device *gdev) |
| 879 | { |
| 880 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 881 | |
| 882 | INIT_LIST_HEAD(&card->vid_list); |
| 883 | INIT_LIST_HEAD(&card->mc_list); |
| 884 | card->options.layer2 = 1; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 885 | card->info.hwtrap = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 886 | return 0; |
| 887 | } |
| 888 | |
| 889 | static void qeth_l2_remove_device(struct ccwgroup_device *cgdev) |
| 890 | { |
| 891 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 892 | |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 893 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 894 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 895 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 896 | if (cgdev->state == CCWGROUP_ONLINE) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 897 | qeth_l2_set_offline(cgdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 898 | |
| 899 | if (card->dev) { |
| 900 | unregister_netdev(card->dev); |
| 901 | card->dev = NULL; |
| 902 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 903 | return; |
| 904 | } |
| 905 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 906 | static const struct ethtool_ops qeth_l2_ethtool_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 907 | .get_link = ethtool_op_get_link, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 908 | .get_strings = qeth_core_get_strings, |
| 909 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 910 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 911 | .get_drvinfo = qeth_core_get_drvinfo, |
Frank Blaschka | 3f9975a | 2008-04-24 10:15:23 +0200 | [diff] [blame] | 912 | .get_settings = qeth_core_ethtool_get_settings, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 913 | }; |
| 914 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 915 | static const struct ethtool_ops qeth_l2_osn_ops = { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 916 | .get_strings = qeth_core_get_strings, |
| 917 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
Ben Hutchings | df8b4ec | 2009-10-01 11:24:32 +0000 | [diff] [blame] | 918 | .get_sset_count = qeth_core_get_sset_count, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 919 | .get_drvinfo = qeth_core_get_drvinfo, |
| 920 | }; |
| 921 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 922 | static const struct net_device_ops qeth_l2_netdev_ops = { |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 923 | .ndo_open = qeth_l2_open, |
| 924 | .ndo_stop = qeth_l2_stop, |
| 925 | .ndo_get_stats = qeth_get_stats, |
| 926 | .ndo_start_xmit = qeth_l2_hard_start_xmit, |
| 927 | .ndo_validate_addr = eth_validate_addr, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 928 | .ndo_set_rx_mode = qeth_l2_set_multicast_list, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 929 | .ndo_do_ioctl = qeth_l2_do_ioctl, |
| 930 | .ndo_set_mac_address = qeth_l2_set_mac_address, |
| 931 | .ndo_change_mtu = qeth_change_mtu, |
| 932 | .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid, |
| 933 | .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid, |
| 934 | .ndo_tx_timeout = qeth_tx_timeout, |
| 935 | }; |
| 936 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 937 | static int qeth_l2_setup_netdev(struct qeth_card *card) |
| 938 | { |
| 939 | switch (card->info.type) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 940 | case QETH_CARD_TYPE_IQD: |
| 941 | card->dev = alloc_netdev(0, "hsi%d", ether_setup); |
| 942 | break; |
| 943 | case QETH_CARD_TYPE_OSN: |
| 944 | card->dev = alloc_netdev(0, "osn%d", ether_setup); |
| 945 | card->dev->flags |= IFF_NOARP; |
| 946 | break; |
| 947 | default: |
| 948 | card->dev = alloc_etherdev(0); |
| 949 | } |
| 950 | |
| 951 | if (!card->dev) |
| 952 | return -ENODEV; |
| 953 | |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 954 | card->dev->ml_priv = card; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 955 | card->dev->watchdog_timeo = QETH_TX_TIMEOUT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 956 | card->dev->mtu = card->info.initial_mtu; |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 957 | card->dev->netdev_ops = &qeth_l2_netdev_ops; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 958 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 959 | SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops); |
| 960 | else |
| 961 | SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops); |
| 962 | card->dev->features |= NETIF_F_HW_VLAN_FILTER; |
| 963 | card->info.broadcast_capable = 1; |
| 964 | qeth_l2_request_initial_mac(card); |
| 965 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 966 | 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] | 967 | return register_netdev(card->dev); |
| 968 | } |
| 969 | |
| 970 | static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
| 971 | { |
| 972 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 973 | int rc = 0; |
| 974 | enum qeth_card_states recover_flag; |
| 975 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 976 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 977 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 978 | QETH_DBF_TEXT(SETUP, 2, "setonlin"); |
| 979 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 980 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 981 | recover_flag = card->state; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 982 | rc = qeth_core_hardsetup_card(card); |
| 983 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 984 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 985 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 986 | goto out_remove; |
| 987 | } |
Stefan Raspl | 395672e0 | 2012-11-19 02:46:49 +0000 | [diff] [blame] | 988 | qeth_trace_features(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 989 | |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 990 | if (!card->dev && qeth_l2_setup_netdev(card)) { |
| 991 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 992 | goto out_remove; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 993 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 994 | |
| 995 | if (card->info.type != QETH_CARD_TYPE_OSN) |
| 996 | qeth_l2_send_setmac(card, &card->dev->dev_addr[0]); |
| 997 | |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 998 | if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { |
| 999 | if (card->info.hwtrap && |
| 1000 | qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) |
| 1001 | card->info.hwtrap = 0; |
| 1002 | } else |
| 1003 | card->info.hwtrap = 0; |
| 1004 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1005 | card->state = CARD_STATE_HARDSETUP; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1006 | memset(&card->rx, 0, sizeof(struct qeth_rx)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1007 | qeth_print_status_message(card); |
| 1008 | |
| 1009 | /* softsetup */ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1010 | QETH_DBF_TEXT(SETUP, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1011 | |
| 1012 | rc = qeth_send_startlan(card); |
| 1013 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1014 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1015 | if (rc == 0xe080) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1016 | dev_warn(&card->gdev->dev, |
| 1017 | "The LAN is offline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1018 | card->lan_online = 0; |
Ursula Braun | 2b6203b | 2010-11-26 02:41:19 +0000 | [diff] [blame] | 1019 | goto contin; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1020 | } |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1021 | rc = -ENODEV; |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 1022 | goto out_remove; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1023 | } else |
| 1024 | card->lan_online = 1; |
| 1025 | |
Ursula Braun | 2b6203b | 2010-11-26 02:41:19 +0000 | [diff] [blame] | 1026 | contin: |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1027 | if ((card->info.type == QETH_CARD_TYPE_OSD) || |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1028 | (card->info.type == QETH_CARD_TYPE_OSX)) { |
Einar Lueck | d64ecc2 | 2009-11-12 00:11:41 +0000 | [diff] [blame] | 1029 | /* configure isolation level */ |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1030 | rc = qeth_set_access_ctrl_online(card, 0); |
| 1031 | if (rc) { |
| 1032 | rc = -ENODEV; |
| 1033 | goto out_remove; |
| 1034 | } |
| 1035 | } |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 1036 | |
| 1037 | if (card->info.type != QETH_CARD_TYPE_OSN && |
| 1038 | card->info.type != QETH_CARD_TYPE_OSM) |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 1039 | qeth_l2_process_vlans(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1040 | |
| 1041 | netif_tx_disable(card->dev); |
| 1042 | |
| 1043 | rc = qeth_init_qdio_queues(card); |
| 1044 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1045 | QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1046 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1047 | goto out_remove; |
| 1048 | } |
| 1049 | card->state = CARD_STATE_SOFTSETUP; |
Ursula Braun | 2b6203b | 2010-11-26 02:41:19 +0000 | [diff] [blame] | 1050 | if (card->lan_online) |
| 1051 | netif_carrier_on(card->dev); |
| 1052 | else |
| 1053 | netif_carrier_off(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1054 | |
| 1055 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1056 | if (recover_flag == CARD_STATE_RECOVER) { |
| 1057 | if (recovery_mode && |
| 1058 | card->info.type != QETH_CARD_TYPE_OSN) { |
Ursula Braun | 3942344 | 2011-01-12 20:42:24 +0000 | [diff] [blame] | 1059 | __qeth_l2_open(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1060 | } else { |
| 1061 | rtnl_lock(); |
| 1062 | dev_open(card->dev); |
| 1063 | rtnl_unlock(); |
| 1064 | } |
| 1065 | /* this also sets saved unicast addresses */ |
| 1066 | qeth_l2_set_multicast_list(card->dev); |
| 1067 | } |
| 1068 | /* let user_space know that device is online */ |
| 1069 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1070 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1071 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1072 | return 0; |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1073 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1074 | out_remove: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1075 | qeth_l2_stop_card(card, 0); |
| 1076 | ccw_device_set_offline(CARD_DDEV(card)); |
| 1077 | ccw_device_set_offline(CARD_WDEV(card)); |
| 1078 | ccw_device_set_offline(CARD_RDEV(card)); |
| 1079 | if (recover_flag == CARD_STATE_RECOVER) |
| 1080 | card->state = CARD_STATE_RECOVER; |
| 1081 | else |
| 1082 | card->state = CARD_STATE_DOWN; |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1083 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1084 | mutex_unlock(&card->discipline_mutex); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 1085 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | static int qeth_l2_set_online(struct ccwgroup_device *gdev) |
| 1089 | { |
| 1090 | return __qeth_l2_set_online(gdev, 0); |
| 1091 | } |
| 1092 | |
| 1093 | static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev, |
| 1094 | int recovery_mode) |
| 1095 | { |
| 1096 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 1097 | int rc = 0, rc2 = 0, rc3 = 0; |
| 1098 | enum qeth_card_states recover_flag; |
| 1099 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1100 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1101 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1102 | QETH_DBF_TEXT(SETUP, 3, "setoffl"); |
| 1103 | QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1104 | |
| 1105 | if (card->dev && netif_carrier_ok(card->dev)) |
| 1106 | netif_carrier_off(card->dev); |
| 1107 | recover_flag = card->state; |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1108 | if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { |
| 1109 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
| 1110 | card->info.hwtrap = 1; |
| 1111 | } |
Ursula Braun | 0f5623c | 2008-10-24 11:16:52 +0200 | [diff] [blame] | 1112 | qeth_l2_stop_card(card, recovery_mode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1113 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 1114 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 1115 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 1116 | if (!rc) |
| 1117 | rc = (rc2) ? rc2 : rc3; |
| 1118 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1119 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1120 | if (recover_flag == CARD_STATE_UP) |
| 1121 | card->state = CARD_STATE_RECOVER; |
| 1122 | /* let user_space know that device is offline */ |
| 1123 | kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 1124 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 1125 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | static int qeth_l2_set_offline(struct ccwgroup_device *cgdev) |
| 1130 | { |
| 1131 | return __qeth_l2_set_offline(cgdev, 0); |
| 1132 | } |
| 1133 | |
| 1134 | static int qeth_l2_recover(void *ptr) |
| 1135 | { |
| 1136 | struct qeth_card *card; |
| 1137 | int rc = 0; |
| 1138 | |
| 1139 | card = (struct qeth_card *) ptr; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1140 | QETH_CARD_TEXT(card, 2, "recover1"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1141 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 1142 | return 0; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1143 | QETH_CARD_TEXT(card, 2, "recover2"); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1144 | dev_warn(&card->gdev->dev, |
| 1145 | "A recovery process has been started for the device\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1146 | __qeth_l2_set_offline(card->gdev, 1); |
| 1147 | rc = __qeth_l2_set_online(card->gdev, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1148 | if (!rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1149 | dev_info(&card->gdev->dev, |
| 1150 | "Device successfully recovered!\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1151 | else { |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 1152 | qeth_close_dev(card); |
| 1153 | dev_warn(&card->gdev->dev, "The qeth device driver " |
Stefan Raspl | 2efaf5f | 2012-10-15 19:21:18 +0000 | [diff] [blame] | 1154 | "failed to recover an error on the device\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 1155 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1156 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 1157 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | static int __init qeth_l2_init(void) |
| 1162 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1163 | pr_info("register layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static void __exit qeth_l2_exit(void) |
| 1168 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 1169 | pr_info("unregister layer 2 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | static void qeth_l2_shutdown(struct ccwgroup_device *gdev) |
| 1173 | { |
| 1174 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | f78ac2b | 2011-12-19 22:56:33 +0000 | [diff] [blame] | 1175 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1176 | if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap) |
| 1177 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1178 | qeth_qdio_clear_card(card, 0); |
| 1179 | qeth_clear_qdio_buffers(card); |
| 1180 | } |
| 1181 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1182 | static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev) |
| 1183 | { |
| 1184 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1185 | |
| 1186 | if (card->dev) |
| 1187 | netif_device_detach(card->dev); |
| 1188 | qeth_set_allowed_threads(card, 0, 1); |
| 1189 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 1190 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1191 | return 0; |
| 1192 | if (card->state == CARD_STATE_UP) { |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 1193 | if (card->info.hwtrap) |
| 1194 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1195 | __qeth_l2_set_offline(card->gdev, 1); |
| 1196 | } else |
| 1197 | __qeth_l2_set_offline(card->gdev, 0); |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | static int qeth_l2_pm_resume(struct ccwgroup_device *gdev) |
| 1202 | { |
| 1203 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 1204 | int rc = 0; |
| 1205 | |
| 1206 | if (gdev->state == CCWGROUP_OFFLINE) |
| 1207 | goto out; |
| 1208 | |
| 1209 | if (card->state == CARD_STATE_RECOVER) { |
| 1210 | rc = __qeth_l2_set_online(card->gdev, 1); |
| 1211 | if (rc) { |
Ursula Braun | 869da90 | 2010-03-08 20:36:56 +0000 | [diff] [blame] | 1212 | rtnl_lock(); |
| 1213 | dev_close(card->dev); |
| 1214 | rtnl_unlock(); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1215 | } |
| 1216 | } else |
| 1217 | rc = __qeth_l2_set_online(card->gdev, 0); |
| 1218 | out: |
| 1219 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
| 1220 | if (card->dev) |
| 1221 | netif_device_attach(card->dev); |
| 1222 | if (rc) |
| 1223 | dev_warn(&card->gdev->dev, "The qeth device driver " |
| 1224 | "failed to recover an error on the device\n"); |
| 1225 | return rc; |
| 1226 | } |
| 1227 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1228 | struct qeth_discipline qeth_l2_discipline = { |
| 1229 | .start_poll = qeth_qdio_start_poll, |
| 1230 | .input_handler = (qdio_handler_t *) qeth_qdio_input_handler, |
| 1231 | .output_handler = (qdio_handler_t *) qeth_qdio_output_handler, |
| 1232 | .recover = qeth_l2_recover, |
| 1233 | .setup = qeth_l2_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1234 | .remove = qeth_l2_remove_device, |
| 1235 | .set_online = qeth_l2_set_online, |
| 1236 | .set_offline = qeth_l2_set_offline, |
| 1237 | .shutdown = qeth_l2_shutdown, |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 1238 | .freeze = qeth_l2_pm_suspend, |
| 1239 | .thaw = qeth_l2_pm_resume, |
| 1240 | .restore = qeth_l2_pm_resume, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1241 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 1242 | EXPORT_SYMBOL_GPL(qeth_l2_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1243 | |
| 1244 | static int qeth_osn_send_control_data(struct qeth_card *card, int len, |
| 1245 | struct qeth_cmd_buffer *iob) |
| 1246 | { |
| 1247 | unsigned long flags; |
| 1248 | int rc = 0; |
| 1249 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1250 | QETH_CARD_TEXT(card, 5, "osndctrd"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1251 | |
| 1252 | wait_event(card->wait_q, |
| 1253 | atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0); |
| 1254 | qeth_prepare_control_data(card, len, iob); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1255 | QETH_CARD_TEXT(card, 6, "osnoirqp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1256 | spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1257 | rc = ccw_device_start(card->write.ccwdev, &card->write.ccw, |
| 1258 | (addr_t) iob, 0, 0); |
| 1259 | spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags); |
| 1260 | if (rc) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 1261 | QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: " |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1262 | "ccw_device_start rc = %i\n", rc); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1263 | QETH_CARD_TEXT_(card, 2, " err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1264 | qeth_release_buffer(iob->channel, iob); |
| 1265 | atomic_set(&card->write.irq_pending, 0); |
| 1266 | wake_up(&card->wait_q); |
| 1267 | } |
| 1268 | return rc; |
| 1269 | } |
| 1270 | |
| 1271 | static int qeth_osn_send_ipa_cmd(struct qeth_card *card, |
| 1272 | struct qeth_cmd_buffer *iob, int data_len) |
| 1273 | { |
| 1274 | u16 s1, s2; |
| 1275 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1276 | QETH_CARD_TEXT(card, 4, "osndipa"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1277 | |
| 1278 | qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2); |
| 1279 | s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len); |
| 1280 | s2 = (u16)data_len; |
| 1281 | memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2); |
| 1282 | memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2); |
| 1283 | memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2); |
| 1284 | memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2); |
| 1285 | return qeth_osn_send_control_data(card, s1, iob); |
| 1286 | } |
| 1287 | |
| 1288 | int qeth_osn_assist(struct net_device *dev, void *data, int data_len) |
| 1289 | { |
| 1290 | struct qeth_cmd_buffer *iob; |
| 1291 | struct qeth_card *card; |
| 1292 | int rc; |
| 1293 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1294 | if (!dev) |
| 1295 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1296 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1297 | if (!card) |
| 1298 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1299 | QETH_CARD_TEXT(card, 2, "osnsdmc"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1300 | if ((card->state != CARD_STATE_UP) && |
| 1301 | (card->state != CARD_STATE_SOFTSETUP)) |
| 1302 | return -ENODEV; |
| 1303 | iob = qeth_wait_for_buffer(&card->write); |
| 1304 | memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len); |
| 1305 | rc = qeth_osn_send_ipa_cmd(card, iob, data_len); |
| 1306 | return rc; |
| 1307 | } |
| 1308 | EXPORT_SYMBOL(qeth_osn_assist); |
| 1309 | |
| 1310 | int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev, |
| 1311 | int (*assist_cb)(struct net_device *, void *), |
| 1312 | int (*data_cb)(struct sk_buff *)) |
| 1313 | { |
| 1314 | struct qeth_card *card; |
| 1315 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1316 | *dev = qeth_l2_netdev_by_devno(read_dev_no); |
| 1317 | if (*dev == NULL) |
| 1318 | return -ENODEV; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1319 | card = (*dev)->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1320 | if (!card) |
| 1321 | return -ENODEV; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1322 | QETH_CARD_TEXT(card, 2, "osnreg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1323 | if ((assist_cb == NULL) || (data_cb == NULL)) |
| 1324 | return -EINVAL; |
| 1325 | card->osn_info.assist_cb = assist_cb; |
| 1326 | card->osn_info.data_cb = data_cb; |
| 1327 | return 0; |
| 1328 | } |
| 1329 | EXPORT_SYMBOL(qeth_osn_register); |
| 1330 | |
| 1331 | void qeth_osn_deregister(struct net_device *dev) |
| 1332 | { |
| 1333 | struct qeth_card *card; |
| 1334 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1335 | if (!dev) |
| 1336 | return; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1337 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1338 | if (!card) |
| 1339 | return; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1340 | QETH_CARD_TEXT(card, 2, "osndereg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1341 | card->osn_info.assist_cb = NULL; |
| 1342 | card->osn_info.data_cb = NULL; |
| 1343 | return; |
| 1344 | } |
| 1345 | EXPORT_SYMBOL(qeth_osn_deregister); |
| 1346 | |
| 1347 | module_init(qeth_l2_init); |
| 1348 | module_exit(qeth_l2_exit); |
| 1349 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 1350 | MODULE_DESCRIPTION("qeth layer 2 discipline"); |
| 1351 | MODULE_LICENSE("GPL"); |