qeth_l2_main.c 35 KB

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