octeon_nic.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. u32 status;
  54. u16 *response_code;
  55. struct completion *completion;
  56. };
  57. #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
  58. /** Structure of data information passed by the NIC module to the OSI
  59. * layer when forwarding data to Octeon device software.
  60. */
  61. struct octnic_data_pkt {
  62. /** Pointer to information maintained by NIC module for this packet. The
  63. * OSI layer passes this as-is to the driver.
  64. */
  65. void *buf;
  66. /** Type of buffer passed in "buf" above. */
  67. u32 reqtype;
  68. /** Total data bytes to be transferred in this command. */
  69. u32 datasize;
  70. /** Command to be passed to the Octeon device software. */
  71. union octeon_instr_64B cmd;
  72. /** Input queue to use to send this command. */
  73. u32 q_no;
  74. };
  75. /** Structure passed by NIC module to OSI layer to prepare a command to send
  76. * network data to Octeon.
  77. */
  78. union octnic_cmd_setup {
  79. struct {
  80. u32 iq_no:8;
  81. u32 gather:1;
  82. u32 timestamp:1;
  83. u32 ip_csum:1;
  84. u32 transport_csum:1;
  85. u32 tnl_csum:1;
  86. u32 rsvd:19;
  87. union {
  88. u32 datasize;
  89. u32 gatherptrs;
  90. } u;
  91. } s;
  92. u64 u64;
  93. };
  94. static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no)
  95. {
  96. return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending)
  97. >= (oct->instr_queue[q_no]->max_count - 2));
  98. }
  99. static inline void
  100. octnet_prepare_pci_cmd_o2(struct octeon_device *oct,
  101. union octeon_instr_64B *cmd,
  102. union octnic_cmd_setup *setup, u32 tag)
  103. {
  104. struct octeon_instr_ih2 *ih2;
  105. struct octeon_instr_irh *irh;
  106. union octnic_packet_params packet_params;
  107. int port;
  108. memset(cmd, 0, sizeof(union octeon_instr_64B));
  109. ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2;
  110. /* assume that rflag is cleared so therefore front data will only have
  111. * irh and ossp[0], ossp[1] for a total of 32 bytes
  112. */
  113. ih2->fsz = LIO_PCICMD_O2;
  114. ih2->tagtype = ORDERED_TAG;
  115. ih2->grp = DEFAULT_POW_GRP;
  116. port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
  117. if (tag)
  118. ih2->tag = tag;
  119. else
  120. ih2->tag = LIO_DATA(port);
  121. ih2->raw = 1;
  122. ih2->qos = (port & 3) + 4; /* map qos based on interface */
  123. if (!setup->s.gather) {
  124. ih2->dlengsz = setup->s.u.datasize;
  125. } else {
  126. ih2->gather = 1;
  127. ih2->dlengsz = setup->s.u.gatherptrs;
  128. }
  129. irh = (struct octeon_instr_irh *)&cmd->cmd2.irh;
  130. irh->opcode = OPCODE_NIC;
  131. irh->subcode = OPCODE_NIC_NW_DATA;
  132. packet_params.u32 = 0;
  133. packet_params.s.ip_csum = setup->s.ip_csum;
  134. packet_params.s.transport_csum = setup->s.transport_csum;
  135. packet_params.s.tnl_csum = setup->s.tnl_csum;
  136. packet_params.s.tsflag = setup->s.timestamp;
  137. irh->ossp = packet_params.u32;
  138. }
  139. static inline void
  140. octnet_prepare_pci_cmd_o3(struct octeon_device *oct,
  141. union octeon_instr_64B *cmd,
  142. union octnic_cmd_setup *setup, u32 tag)
  143. {
  144. struct octeon_instr_irh *irh;
  145. struct octeon_instr_ih3 *ih3;
  146. struct octeon_instr_pki_ih3 *pki_ih3;
  147. union octnic_packet_params packet_params;
  148. int port;
  149. memset(cmd, 0, sizeof(union octeon_instr_64B));
  150. ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
  151. pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
  152. /* assume that rflag is cleared so therefore front data will only have
  153. * irh and ossp[1] and ossp[2] for a total of 24 bytes
  154. */
  155. ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
  156. /*PKI IH*/
  157. ih3->fsz = LIO_PCICMD_O3;
  158. if (!setup->s.gather) {
  159. ih3->dlengsz = setup->s.u.datasize;
  160. } else {
  161. ih3->gather = 1;
  162. ih3->dlengsz = setup->s.u.gatherptrs;
  163. }
  164. pki_ih3->w = 1;
  165. pki_ih3->raw = 1;
  166. pki_ih3->utag = 1;
  167. pki_ih3->utt = 1;
  168. pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
  169. port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
  170. if (tag)
  171. pki_ih3->tag = tag;
  172. else
  173. pki_ih3->tag = LIO_DATA(port);
  174. pki_ih3->tagtype = ORDERED_TAG;
  175. pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
  176. pki_ih3->pm = 0x7; /*0x7 - meant for Parse nothing, uninterpreted*/
  177. pki_ih3->sl = 8; /* sl will be sizeof(pki_ih3)*/
  178. irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
  179. irh->opcode = OPCODE_NIC;
  180. irh->subcode = OPCODE_NIC_NW_DATA;
  181. packet_params.u32 = 0;
  182. packet_params.s.ip_csum = setup->s.ip_csum;
  183. packet_params.s.transport_csum = setup->s.transport_csum;
  184. packet_params.s.tnl_csum = setup->s.tnl_csum;
  185. packet_params.s.tsflag = setup->s.timestamp;
  186. irh->ossp = packet_params.u32;
  187. }
  188. /** Utility function to prepare a 64B NIC instruction based on a setup command
  189. * @param cmd - pointer to instruction to be filled in.
  190. * @param setup - pointer to the setup structure
  191. * @param q_no - which queue for back pressure
  192. *
  193. * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
  194. */
  195. static inline void
  196. octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd,
  197. union octnic_cmd_setup *setup, u32 tag)
  198. {
  199. if (OCTEON_CN6XXX(oct))
  200. octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag);
  201. else
  202. octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag);
  203. }
  204. /** Allocate and a soft command with space for a response immediately following
  205. * the commnad.
  206. * @param oct - octeon device pointer
  207. * @param cmd - pointer to the command structure, pre-filled for everything
  208. * except the response.
  209. * @param rdatasize - size in bytes of the response.
  210. *
  211. * @returns pointer to allocated buffer with command copied into it, and
  212. * response space immediately following.
  213. */
  214. void *
  215. octeon_alloc_soft_command_resp(struct octeon_device *oct,
  216. union octeon_instr_64B *cmd,
  217. u32 rdatasize);
  218. /** Send a NIC data packet to the device
  219. * @param oct - octeon device pointer
  220. * @param ndata - control structure with queueing, and buffer information
  221. *
  222. * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
  223. * queue should be stopped, and IQ_SEND_OK if it sent okay.
  224. */
  225. int octnet_send_nic_data_pkt(struct octeon_device *oct,
  226. struct octnic_data_pkt *ndata,
  227. int xmit_more);
  228. /** Send a NIC control packet to the device
  229. * @param oct - octeon device pointer
  230. * @param nctrl - control structure with command, timout, and callback info
  231. * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
  232. * queue should be stopped, and IQ_SEND_OK if it sent okay.
  233. */
  234. int
  235. octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
  236. struct octnic_ctrl_pkt *nctrl);
  237. #endif