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