-static int same_destination(struct ib_user_mad_hdr *hdr1,
- struct ib_user_mad_hdr *hdr2)
-{
- if (!hdr1->grh_present && !hdr2->grh_present)
- return (hdr1->lid == hdr2->lid);
-
- if (hdr1->grh_present && hdr2->grh_present)
- return !memcmp(hdr1->gid, hdr2->gid, 16);
-
- return 0;
-}
-
-static int is_duplicate(struct ib_umad_file *file,
- struct ib_umad_packet *packet)
-{
- struct ib_umad_packet *sent_packet;
- struct ib_mad_hdr *sent_hdr, *hdr;
-
- hdr = (struct ib_mad_hdr *) packet->mad.data;
- list_for_each_entry(sent_packet, &file->send_list, list) {
- sent_hdr = (struct ib_mad_hdr *) sent_packet->mad.data;
-
- if ((hdr->tid != sent_hdr->tid) ||
- (hdr->mgmt_class != sent_hdr->mgmt_class))
- continue;
-
- /*
- * No need to be overly clever here. If two new operations have
- * the same TID, reject the second as a duplicate. This is more
- * restrictive than required by the spec.
- */
- if (!ib_response_mad((struct ib_mad *) hdr)) {
- if (!ib_response_mad((struct ib_mad *) sent_hdr))
- return 1;
- continue;
- } else if (!ib_response_mad((struct ib_mad *) sent_hdr))
- continue;
-
- if (same_destination(&packet->mad.hdr, &sent_packet->mad.hdr))
- return 1;
- }
-
- return 0;
-}
-