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