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 20 /*! \file octeon_nic.h 21 * \brief Host NIC Driver: Routine to send network data & 22 * control packet to Octeon. 23 */ 24 25 #ifndef __OCTEON_NIC_H__ 26 #define __OCTEON_NIC_H__ 27 28 /* Maximum number of 8-byte words can be sent in a NIC control message. 29 */ 30 #define MAX_NCTRL_UDD 32 31 32 typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *); 33 34 /* Structure of control information passed by the NIC module to the OSI 35 * layer when sending control commands to Octeon device software. 36 */ 37 struct octnic_ctrl_pkt { 38 /** Command to be passed to the Octeon device software. */ 39 union octnet_cmd ncmd; 40 41 /** Send buffer */ 42 void *data; 43 u64 dmadata; 44 45 /** Response buffer */ 46 void *rdata; 47 u64 dmardata; 48 49 /** Additional data that may be needed by some commands. */ 50 u64 udd[MAX_NCTRL_UDD]; 51 52 /** Input queue to use to send this command. */ 53 u64 iq_no; 54 55 /** Time to wait for Octeon software to respond to this control command. 56 * If wait_time is 0, OSI assumes no response is expected. 57 */ 58 size_t wait_time; 59 60 /** The network device that issued the control command. */ 61 u64 netpndev; 62 63 /** Callback function called when the command has been fetched */ 64 octnic_ctrl_pkt_cb_fn_t cb_fn; 65 }; 66 67 #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd)) 68 69 /** Structure of data information passed by the NIC module to the OSI 70 * layer when forwarding data to Octeon device software. 71 */ 72 struct octnic_data_pkt { 73 /** Pointer to information maintained by NIC module for this packet. The 74 * OSI layer passes this as-is to the driver. 75 */ 76 void *buf; 77 78 /** Type of buffer passed in "buf" above. */ 79 u32 reqtype; 80 81 /** Total data bytes to be transferred in this command. */ 82 u32 datasize; 83 84 /** Command to be passed to the Octeon device software. */ 85 union octeon_instr_64B cmd; 86 87 /** Input queue to use to send this command. */ 88 u32 q_no; 89 90 }; 91 92 /** Structure passed by NIC module to OSI layer to prepare a command to send 93 * network data to Octeon. 94 */ 95 union octnic_cmd_setup { 96 struct { 97 u32 iq_no:8; 98 u32 gather:1; 99 u32 timestamp:1; 100 u32 ip_csum:1; 101 u32 transport_csum:1; 102 u32 tnl_csum:1; 103 u32 rsvd:19; 104 105 union { 106 u32 datasize; 107 u32 gatherptrs; 108 } u; 109 } s; 110 111 u64 u64; 112 113 }; 114 115 static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no) 116 { 117 return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending) 118 >= (oct->instr_queue[q_no]->max_count - 2)); 119 } 120 121 static inline void 122 octnet_prepare_pci_cmd_o2(struct octeon_device *oct, 123 union octeon_instr_64B *cmd, 124 union octnic_cmd_setup *setup, u32 tag) 125 { 126 struct octeon_instr_ih2 *ih2; 127 struct octeon_instr_irh *irh; 128 union octnic_packet_params packet_params; 129 int port; 130 131 memset(cmd, 0, sizeof(union octeon_instr_64B)); 132 133 ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2; 134 135 /* assume that rflag is cleared so therefore front data will only have 136 * irh and ossp[0], ossp[1] for a total of 32 bytes 137 */ 138 ih2->fsz = LIO_PCICMD_O2; 139 140 ih2->tagtype = ORDERED_TAG; 141 ih2->grp = DEFAULT_POW_GRP; 142 143 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port; 144 145 if (tag) 146 ih2->tag = tag; 147 else 148 ih2->tag = LIO_DATA(port); 149 150 ih2->raw = 1; 151 ih2->qos = (port & 3) + 4; /* map qos based on interface */ 152 153 if (!setup->s.gather) { 154 ih2->dlengsz = setup->s.u.datasize; 155 } else { 156 ih2->gather = 1; 157 ih2->dlengsz = setup->s.u.gatherptrs; 158 } 159 160 irh = (struct octeon_instr_irh *)&cmd->cmd2.irh; 161 162 irh->opcode = OPCODE_NIC; 163 irh->subcode = OPCODE_NIC_NW_DATA; 164 165 packet_params.u32 = 0; 166 167 packet_params.s.ip_csum = setup->s.ip_csum; 168 packet_params.s.transport_csum = setup->s.transport_csum; 169 packet_params.s.tnl_csum = setup->s.tnl_csum; 170 packet_params.s.tsflag = setup->s.timestamp; 171 172 irh->ossp = packet_params.u32; 173 } 174 175 static inline void 176 octnet_prepare_pci_cmd_o3(struct octeon_device *oct, 177 union octeon_instr_64B *cmd, 178 union octnic_cmd_setup *setup, u32 tag) 179 { 180 struct octeon_instr_irh *irh; 181 struct octeon_instr_ih3 *ih3; 182 struct octeon_instr_pki_ih3 *pki_ih3; 183 union octnic_packet_params packet_params; 184 int port; 185 186 memset(cmd, 0, sizeof(union octeon_instr_64B)); 187 188 ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3; 189 pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3; 190 191 /* assume that rflag is cleared so therefore front data will only have 192 * irh and ossp[1] and ossp[2] for a total of 24 bytes 193 */ 194 ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind; 195 /*PKI IH*/ 196 ih3->fsz = LIO_PCICMD_O3; 197 198 if (!setup->s.gather) { 199 ih3->dlengsz = setup->s.u.datasize; 200 } else { 201 ih3->gather = 1; 202 ih3->dlengsz = setup->s.u.gatherptrs; 203 } 204 205 pki_ih3->w = 1; 206 pki_ih3->raw = 1; 207 pki_ih3->utag = 1; 208 pki_ih3->utt = 1; 209 pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg; 210 211 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port; 212 213 if (tag) 214 pki_ih3->tag = tag; 215 else 216 pki_ih3->tag = LIO_DATA(port); 217 218 pki_ih3->tagtype = ORDERED_TAG; 219 pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg; 220 pki_ih3->pm = 0x7; /*0x7 - meant for Parse nothing, uninterpreted*/ 221 pki_ih3->sl = 8; /* sl will be sizeof(pki_ih3)*/ 222 223 irh = (struct octeon_instr_irh *)&cmd->cmd3.irh; 224 225 irh->opcode = OPCODE_NIC; 226 irh->subcode = OPCODE_NIC_NW_DATA; 227 228 packet_params.u32 = 0; 229 230 packet_params.s.ip_csum = setup->s.ip_csum; 231 packet_params.s.transport_csum = setup->s.transport_csum; 232 packet_params.s.tnl_csum = setup->s.tnl_csum; 233 packet_params.s.tsflag = setup->s.timestamp; 234 235 irh->ossp = packet_params.u32; 236 } 237 238 /** Utility function to prepare a 64B NIC instruction based on a setup command 239 * @param cmd - pointer to instruction to be filled in. 240 * @param setup - pointer to the setup structure 241 * @param q_no - which queue for back pressure 242 * 243 * Assumes the cmd instruction is pre-allocated, but no fields are filled in. 244 */ 245 static inline void 246 octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd, 247 union octnic_cmd_setup *setup, u32 tag) 248 { 249 if (OCTEON_CN6XXX(oct)) 250 octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag); 251 else 252 octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag); 253 } 254 255 /** Allocate and a soft command with space for a response immediately following 256 * the commnad. 257 * @param oct - octeon device pointer 258 * @param cmd - pointer to the command structure, pre-filled for everything 259 * except the response. 260 * @param rdatasize - size in bytes of the response. 261 * 262 * @returns pointer to allocated buffer with command copied into it, and 263 * response space immediately following. 264 */ 265 void * 266 octeon_alloc_soft_command_resp(struct octeon_device *oct, 267 union octeon_instr_64B *cmd, 268 u32 rdatasize); 269 270 /** Send a NIC data packet to the device 271 * @param oct - octeon device pointer 272 * @param ndata - control structure with queueing, and buffer information 273 * 274 * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the 275 * queue should be stopped, and IQ_SEND_OK if it sent okay. 276 */ 277 int octnet_send_nic_data_pkt(struct octeon_device *oct, 278 struct octnic_data_pkt *ndata); 279 280 /** Send a NIC control packet to the device 281 * @param oct - octeon device pointer 282 * @param nctrl - control structure with command, timout, and callback info 283 * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the 284 * queue should be stopped, and IQ_SEND_OK if it sent okay. 285 */ 286 int 287 octnet_send_nic_ctrl_pkt(struct octeon_device *oct, 288 struct octnic_ctrl_pkt *nctrl); 289 290 #endif 291