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