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