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