qedf_fip.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * QLogic FCoE Offload Driver
  3. * Copyright (c) 2016-2018 Cavium Inc.
  4. *
  5. * This software is available under the terms of the GNU General Public License
  6. * (GPL) Version 2, available from the file COPYING in the main directory of
  7. * this source tree.
  8. */
  9. #include <linux/if_ether.h>
  10. #include <linux/if_vlan.h>
  11. #include "qedf.h"
  12. extern const struct qed_fcoe_ops *qed_ops;
  13. /*
  14. * FIP VLAN functions that will eventually move to libfcoe.
  15. */
  16. void qedf_fcoe_send_vlan_req(struct qedf_ctx *qedf)
  17. {
  18. struct sk_buff *skb;
  19. char *eth_fr;
  20. int fr_len;
  21. struct fip_vlan *vlan;
  22. #define MY_FIP_ALL_FCF_MACS ((__u8[6]) { 1, 0x10, 0x18, 1, 0, 2 })
  23. static u8 my_fcoe_all_fcfs[ETH_ALEN] = MY_FIP_ALL_FCF_MACS;
  24. unsigned long flags = 0;
  25. skb = dev_alloc_skb(sizeof(struct fip_vlan));
  26. if (!skb)
  27. return;
  28. fr_len = sizeof(*vlan);
  29. eth_fr = (char *)skb->data;
  30. vlan = (struct fip_vlan *)eth_fr;
  31. memset(vlan, 0, sizeof(*vlan));
  32. ether_addr_copy(vlan->eth.h_source, qedf->mac);
  33. ether_addr_copy(vlan->eth.h_dest, my_fcoe_all_fcfs);
  34. vlan->eth.h_proto = htons(ETH_P_FIP);
  35. vlan->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
  36. vlan->fip.fip_op = htons(FIP_OP_VLAN);
  37. vlan->fip.fip_subcode = FIP_SC_VL_REQ;
  38. vlan->fip.fip_dl_len = htons(sizeof(vlan->desc) / FIP_BPW);
  39. vlan->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC;
  40. vlan->desc.mac.fd_desc.fip_dlen = sizeof(vlan->desc.mac) / FIP_BPW;
  41. ether_addr_copy(vlan->desc.mac.fd_mac, qedf->mac);
  42. vlan->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME;
  43. vlan->desc.wwnn.fd_desc.fip_dlen = sizeof(vlan->desc.wwnn) / FIP_BPW;
  44. put_unaligned_be64(qedf->lport->wwnn, &vlan->desc.wwnn.fd_wwn);
  45. skb_put(skb, sizeof(*vlan));
  46. skb->protocol = htons(ETH_P_FIP);
  47. skb_reset_mac_header(skb);
  48. skb_reset_network_header(skb);
  49. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Sending FIP VLAN "
  50. "request.");
  51. if (atomic_read(&qedf->link_state) != QEDF_LINK_UP) {
  52. QEDF_WARN(&(qedf->dbg_ctx), "Cannot send vlan request "
  53. "because link is not up.\n");
  54. kfree_skb(skb);
  55. return;
  56. }
  57. set_bit(QED_LL2_XMIT_FLAGS_FIP_DISCOVERY, &flags);
  58. qed_ops->ll2->start_xmit(qedf->cdev, skb, flags);
  59. }
  60. static void qedf_fcoe_process_vlan_resp(struct qedf_ctx *qedf,
  61. struct sk_buff *skb)
  62. {
  63. struct fip_header *fiph;
  64. struct fip_desc *desc;
  65. u16 vid = 0;
  66. ssize_t rlen;
  67. size_t dlen;
  68. fiph = (struct fip_header *)(((void *)skb->data) + 2 * ETH_ALEN + 2);
  69. rlen = ntohs(fiph->fip_dl_len) * 4;
  70. desc = (struct fip_desc *)(fiph + 1);
  71. while (rlen > 0) {
  72. dlen = desc->fip_dlen * FIP_BPW;
  73. switch (desc->fip_dtype) {
  74. case FIP_DT_VLAN:
  75. vid = ntohs(((struct fip_vlan_desc *)desc)->fd_vlan);
  76. break;
  77. }
  78. desc = (struct fip_desc *)((char *)desc + dlen);
  79. rlen -= dlen;
  80. }
  81. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "VLAN response, "
  82. "vid=0x%x.\n", vid);
  83. if (vid > 0 && qedf->vlan_id != vid) {
  84. qedf_set_vlan_id(qedf, vid);
  85. /* Inform waiter that it's ok to call fcoe_ctlr_link up() */
  86. if (!completion_done(&qedf->fipvlan_compl))
  87. complete(&qedf->fipvlan_compl);
  88. }
  89. }
  90. void qedf_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
  91. {
  92. struct qedf_ctx *qedf = container_of(fip, struct qedf_ctx, ctlr);
  93. struct ethhdr *eth_hdr;
  94. struct fip_header *fiph;
  95. u16 op, vlan_tci = 0;
  96. u8 sub;
  97. if (!test_bit(QEDF_LL2_STARTED, &qedf->flags)) {
  98. QEDF_WARN(&(qedf->dbg_ctx), "LL2 not started\n");
  99. kfree_skb(skb);
  100. return;
  101. }
  102. fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
  103. eth_hdr = (struct ethhdr *)skb_mac_header(skb);
  104. op = ntohs(fiph->fip_op);
  105. sub = fiph->fip_subcode;
  106. /*
  107. * Add VLAN tag to non-offload FIP frame based on current stored VLAN
  108. * for FIP/FCoE traffic.
  109. */
  110. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), qedf->vlan_id);
  111. /* Get VLAN ID from skb for printing purposes */
  112. __vlan_hwaccel_get_tag(skb, &vlan_tci);
  113. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, "FIP frame send: "
  114. "dest=%pM op=%x sub=%x vlan=%04x.", eth_hdr->h_dest, op, sub,
  115. vlan_tci);
  116. if (qedf_dump_frames)
  117. print_hex_dump(KERN_WARNING, "fip ", DUMP_PREFIX_OFFSET, 16, 1,
  118. skb->data, skb->len, false);
  119. qed_ops->ll2->start_xmit(qedf->cdev, skb, 0);
  120. }
  121. /* Process incoming FIP frames. */
  122. void qedf_fip_recv(struct qedf_ctx *qedf, struct sk_buff *skb)
  123. {
  124. struct ethhdr *eth_hdr;
  125. struct fip_header *fiph;
  126. struct fip_desc *desc;
  127. struct fip_mac_desc *mp;
  128. struct fip_wwn_desc *wp;
  129. struct fip_vn_desc *vp;
  130. size_t rlen, dlen;
  131. u16 op;
  132. u8 sub;
  133. bool do_reset = false;
  134. eth_hdr = (struct ethhdr *)skb_mac_header(skb);
  135. fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
  136. op = ntohs(fiph->fip_op);
  137. sub = fiph->fip_subcode;
  138. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2, "FIP frame received: "
  139. "skb=%p fiph=%p source=%pM op=%x sub=%x", skb, fiph,
  140. eth_hdr->h_source, op, sub);
  141. if (qedf_dump_frames)
  142. print_hex_dump(KERN_WARNING, "fip ", DUMP_PREFIX_OFFSET, 16, 1,
  143. skb->data, skb->len, false);
  144. /* Handle FIP VLAN resp in the driver */
  145. if (op == FIP_OP_VLAN && sub == FIP_SC_VL_NOTE) {
  146. qedf_fcoe_process_vlan_resp(qedf, skb);
  147. kfree_skb(skb);
  148. } else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) {
  149. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC, "Clear virtual "
  150. "link received.\n");
  151. /* Check that an FCF has been selected by fcoe */
  152. if (qedf->ctlr.sel_fcf == NULL) {
  153. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_DISC,
  154. "Dropping CVL since FCF has not been selected "
  155. "yet.");
  156. kfree_skb(skb);
  157. return;
  158. }
  159. /*
  160. * We need to loop through the CVL descriptors to determine
  161. * if we want to reset the fcoe link
  162. */
  163. rlen = ntohs(fiph->fip_dl_len) * FIP_BPW;
  164. desc = (struct fip_desc *)(fiph + 1);
  165. while (rlen >= sizeof(*desc)) {
  166. dlen = desc->fip_dlen * FIP_BPW;
  167. switch (desc->fip_dtype) {
  168. case FIP_DT_MAC:
  169. mp = (struct fip_mac_desc *)desc;
  170. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2,
  171. "fd_mac=%pM\n", mp->fd_mac);
  172. if (ether_addr_equal(mp->fd_mac,
  173. qedf->ctlr.sel_fcf->fcf_mac))
  174. do_reset = true;
  175. break;
  176. case FIP_DT_NAME:
  177. wp = (struct fip_wwn_desc *)desc;
  178. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2,
  179. "fc_wwpn=%016llx.\n",
  180. get_unaligned_be64(&wp->fd_wwn));
  181. break;
  182. case FIP_DT_VN_ID:
  183. vp = (struct fip_vn_desc *)desc;
  184. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2,
  185. "fd_fc_id=%x.\n", ntoh24(vp->fd_fc_id));
  186. if (ntoh24(vp->fd_fc_id) ==
  187. qedf->lport->port_id)
  188. do_reset = true;
  189. break;
  190. default:
  191. /* Ignore anything else */
  192. break;
  193. }
  194. desc = (struct fip_desc *)((char *)desc + dlen);
  195. rlen -= dlen;
  196. }
  197. QEDF_INFO(&(qedf->dbg_ctx), QEDF_LOG_LL2,
  198. "do_reset=%d.\n", do_reset);
  199. if (do_reset) {
  200. fcoe_ctlr_link_down(&qedf->ctlr);
  201. qedf_wait_for_upload(qedf);
  202. fcoe_ctlr_link_up(&qedf->ctlr);
  203. }
  204. kfree_skb(skb);
  205. } else {
  206. /* Everything else is handled by libfcoe */
  207. __skb_pull(skb, ETH_HLEN);
  208. fcoe_ctlr_recv(&qedf->ctlr, skb);
  209. }
  210. }
  211. u8 *qedf_get_src_mac(struct fc_lport *lport)
  212. {
  213. struct qedf_ctx *qedf = lport_priv(lport);
  214. return qedf->data_src_addr;
  215. }