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