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