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