octeon_nic.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /**********************************************************************
  2. * Author: Cavium, Inc.
  3. *
  4. * Contact: support@cavium.com
  5. * Please include "LiquidIO" in the subject.
  6. *
  7. * Copyright (c) 2003-2016 Cavium, Inc.
  8. *
  9. * This file is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License, Version 2, as
  11. * published by the Free Software Foundation.
  12. *
  13. * This file is distributed in the hope that it will be useful, but
  14. * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
  16. * NONINFRINGEMENT. See the GNU General Public License for more
  17. * details.
  18. **********************************************************************/
  19. /*! \file octeon_nic.h
  20. * \brief Host NIC Driver: Routine to send network data &
  21. * control packet to Octeon.
  22. */
  23. #ifndef __OCTEON_NIC_H__
  24. #define __OCTEON_NIC_H__
  25. /* Maximum number of 8-byte words can be sent in a NIC control message.
  26. */
  27. #define MAX_NCTRL_UDD 32
  28. typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *);
  29. /* Structure of control information passed by the NIC module to the OSI
  30. * layer when sending control commands to Octeon device software.
  31. */
  32. struct octnic_ctrl_pkt {
  33. /** Command to be passed to the Octeon device software. */
  34. union octnet_cmd ncmd;
  35. /** Send buffer */
  36. void *data;
  37. u64 dmadata;
  38. /** Response buffer */
  39. void *rdata;
  40. u64 dmardata;
  41. /** Additional data that may be needed by some commands. */
  42. u64 udd[MAX_NCTRL_UDD];
  43. /** Input queue to use to send this command. */
  44. u64 iq_no;
  45. /** Time to wait for Octeon software to respond to this control command.
  46. * If wait_time is 0, OSI assumes no response is expected.
  47. */
  48. size_t wait_time;
  49. /** The network device that issued the control command. */
  50. u64 netpndev;
  51. /** Callback function called when the command has been fetched */
  52. octnic_ctrl_pkt_cb_fn_t cb_fn;
  53. };
  54. #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
  55. /** Structure of data information passed by the NIC module to the OSI
  56. * layer when forwarding data to Octeon device software.
  57. */
  58. struct octnic_data_pkt {
  59. /** Pointer to information maintained by NIC module for this packet. The
  60. * OSI layer passes this as-is to the driver.
  61. */
  62. void *buf;
  63. /** Type of buffer passed in "buf" above. */
  64. u32 reqtype;
  65. /** Total data bytes to be transferred in this command. */
  66. u32 datasize;
  67. /** Command to be passed to the Octeon device software. */
  68. union octeon_instr_64B cmd;
  69. /** Input queue to use to send this command. */
  70. u32 q_no;
  71. };
  72. /** Structure passed by NIC module to OSI layer to prepare a command to send
  73. * network data to Octeon.
  74. */
  75. union octnic_cmd_setup {
  76. struct {
  77. u32 iq_no:8;
  78. u32 gather:1;
  79. u32 timestamp:1;
  80. u32 ip_csum:1;
  81. u32 transport_csum:1;
  82. u32 tnl_csum:1;
  83. u32 rsvd:19;
  84. union {
  85. u32 datasize;
  86. u32 gatherptrs;
  87. } u;
  88. } s;
  89. u64 u64;
  90. };
  91. static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no)
  92. {
  93. return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending)
  94. >= (oct->instr_queue[q_no]->max_count - 2));
  95. }
  96. static inline void
  97. octnet_prepare_pci_cmd_o2(struct octeon_device *oct,
  98. union octeon_instr_64B *cmd,
  99. union octnic_cmd_setup *setup, u32 tag)
  100. {
  101. struct octeon_instr_ih2 *ih2;
  102. struct octeon_instr_irh *irh;
  103. union octnic_packet_params packet_params;
  104. int port;
  105. memset(cmd, 0, sizeof(union octeon_instr_64B));
  106. ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2;
  107. /* assume that rflag is cleared so therefore front data will only have
  108. * irh and ossp[0], ossp[1] for a total of 32 bytes
  109. */
  110. ih2->fsz = LIO_PCICMD_O2;
  111. ih2->tagtype = ORDERED_TAG;
  112. ih2->grp = DEFAULT_POW_GRP;
  113. port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
  114. if (tag)
  115. ih2->tag = tag;
  116. else
  117. ih2->tag = LIO_DATA(port);
  118. ih2->raw = 1;
  119. ih2->qos = (port & 3) + 4; /* map qos based on interface */
  120. if (!setup->s.gather) {
  121. ih2->dlengsz = setup->s.u.datasize;
  122. } else {
  123. ih2->gather = 1;
  124. ih2->dlengsz = setup->s.u.gatherptrs;
  125. }
  126. irh = (struct octeon_instr_irh *)&cmd->cmd2.irh;
  127. irh->opcode = OPCODE_NIC;
  128. irh->subcode = OPCODE_NIC_NW_DATA;
  129. packet_params.u32 = 0;
  130. packet_params.s.ip_csum = setup->s.ip_csum;
  131. packet_params.s.transport_csum = setup->s.transport_csum;
  132. packet_params.s.tnl_csum = setup->s.tnl_csum;
  133. packet_params.s.tsflag = setup->s.timestamp;
  134. irh->ossp = packet_params.u32;
  135. }
  136. static inline void
  137. octnet_prepare_pci_cmd_o3(struct octeon_device *oct,
  138. union octeon_instr_64B *cmd,
  139. union octnic_cmd_setup *setup, u32 tag)
  140. {
  141. struct octeon_instr_irh *irh;
  142. struct octeon_instr_ih3 *ih3;
  143. struct octeon_instr_pki_ih3 *pki_ih3;
  144. union octnic_packet_params packet_params;
  145. int port;
  146. memset(cmd, 0, sizeof(union octeon_instr_64B));
  147. ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
  148. pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
  149. /* assume that rflag is cleared so therefore front data will only have
  150. * irh and ossp[1] and ossp[2] for a total of 24 bytes
  151. */
  152. ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
  153. /*PKI IH*/
  154. ih3->fsz = LIO_PCICMD_O3;
  155. if (!setup->s.gather) {
  156. ih3->dlengsz = setup->s.u.datasize;
  157. } else {
  158. ih3->gather = 1;
  159. ih3->dlengsz = setup->s.u.gatherptrs;
  160. }
  161. pki_ih3->w = 1;
  162. pki_ih3->raw = 1;
  163. pki_ih3->utag = 1;
  164. pki_ih3->utt = 1;
  165. pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
  166. port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
  167. if (tag)
  168. pki_ih3->tag = tag;
  169. else
  170. pki_ih3->tag = LIO_DATA(port);
  171. pki_ih3->tagtype = ORDERED_TAG;
  172. pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
  173. pki_ih3->pm = 0x7; /*0x7 - meant for Parse nothing, uninterpreted*/
  174. pki_ih3->sl = 8; /* sl will be sizeof(pki_ih3)*/
  175. irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
  176. irh->opcode = OPCODE_NIC;
  177. irh->subcode = OPCODE_NIC_NW_DATA;
  178. packet_params.u32 = 0;
  179. packet_params.s.ip_csum = setup->s.ip_csum;
  180. packet_params.s.transport_csum = setup->s.transport_csum;
  181. packet_params.s.tnl_csum = setup->s.tnl_csum;
  182. packet_params.s.tsflag = setup->s.timestamp;
  183. irh->ossp = packet_params.u32;
  184. }
  185. /** Utility function to prepare a 64B NIC instruction based on a setup command
  186. * @param cmd - pointer to instruction to be filled in.
  187. * @param setup - pointer to the setup structure
  188. * @param q_no - which queue for back pressure
  189. *
  190. * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
  191. */
  192. static inline void
  193. octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd,
  194. union octnic_cmd_setup *setup, u32 tag)
  195. {
  196. if (OCTEON_CN6XXX(oct))
  197. octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag);
  198. else
  199. octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag);
  200. }
  201. /** Allocate and a soft command with space for a response immediately following
  202. * the commnad.
  203. * @param oct - octeon device pointer
  204. * @param cmd - pointer to the command structure, pre-filled for everything
  205. * except the response.
  206. * @param rdatasize - size in bytes of the response.
  207. *
  208. * @returns pointer to allocated buffer with command copied into it, and
  209. * response space immediately following.
  210. */
  211. void *
  212. octeon_alloc_soft_command_resp(struct octeon_device *oct,
  213. union octeon_instr_64B *cmd,
  214. u32 rdatasize);
  215. /** Send a NIC data packet to the device
  216. * @param oct - octeon device pointer
  217. * @param ndata - control structure with queueing, and buffer information
  218. *
  219. * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
  220. * queue should be stopped, and IQ_SEND_OK if it sent okay.
  221. */
  222. int octnet_send_nic_data_pkt(struct octeon_device *oct,
  223. struct octnic_data_pkt *ndata);
  224. /** Send a NIC control packet to the device
  225. * @param oct - octeon device pointer
  226. * @param nctrl - control structure with command, timout, and callback info
  227. * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
  228. * queue should be stopped, and IQ_SEND_OK if it sent okay.
  229. */
  230. int
  231. octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
  232. struct octnic_ctrl_pkt *nctrl);
  233. #endif