/drivers/staging/octeon/ethernet-tx.c

https://bitbucket.org/cyanogenmod/android_kernel_asus_tf300t · C · 724 lines · 465 code · 67 blank · 192 comment · 91 complexity · e092ad9e41900ee310296b93e31807aa MD5 · raw file

  1. /*********************************************************************
  2. * Author: Cavium Networks
  3. *
  4. * Contact: support@caviumnetworks.com
  5. * This file is part of the OCTEON SDK
  6. *
  7. * Copyright (c) 2003-2010 Cavium Networks
  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. * You should have received a copy of the GNU General Public License
  20. * along with this file; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. * or visit http://www.gnu.org/licenses/.
  23. *
  24. * This file may also be available under a different license from Cavium.
  25. * Contact Cavium Networks for more information
  26. *********************************************************************/
  27. #include <linux/module.h>
  28. #include <linux/kernel.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/init.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/ip.h>
  33. #include <linux/ratelimit.h>
  34. #include <linux/string.h>
  35. #include <net/dst.h>
  36. #ifdef CONFIG_XFRM
  37. #include <linux/xfrm.h>
  38. #include <net/xfrm.h>
  39. #endif /* CONFIG_XFRM */
  40. #include <linux/atomic.h>
  41. #include <asm/octeon/octeon.h>
  42. #include "ethernet-defines.h"
  43. #include "octeon-ethernet.h"
  44. #include "ethernet-tx.h"
  45. #include "ethernet-util.h"
  46. #include "cvmx-wqe.h"
  47. #include "cvmx-fau.h"
  48. #include "cvmx-pip.h"
  49. #include "cvmx-pko.h"
  50. #include "cvmx-helper.h"
  51. #include "cvmx-gmxx-defs.h"
  52. #define CVM_OCT_SKB_CB(skb) ((u64 *)((skb)->cb))
  53. /*
  54. * You can define GET_SKBUFF_QOS() to override how the skbuff output
  55. * function determines which output queue is used. The default
  56. * implementation always uses the base queue for the port. If, for
  57. * example, you wanted to use the skb->priority fieid, define
  58. * GET_SKBUFF_QOS as: #define GET_SKBUFF_QOS(skb) ((skb)->priority)
  59. */
  60. #ifndef GET_SKBUFF_QOS
  61. #define GET_SKBUFF_QOS(skb) 0
  62. #endif
  63. static void cvm_oct_tx_do_cleanup(unsigned long arg);
  64. static DECLARE_TASKLET(cvm_oct_tx_cleanup_tasklet, cvm_oct_tx_do_cleanup, 0);
  65. /* Maximum number of SKBs to try to free per xmit packet. */
  66. #define MAX_SKB_TO_FREE (MAX_OUT_QUEUE_DEPTH * 2)
  67. static inline int32_t cvm_oct_adjust_skb_to_free(int32_t skb_to_free, int fau)
  68. {
  69. int32_t undo;
  70. undo = skb_to_free > 0 ? MAX_SKB_TO_FREE : skb_to_free + MAX_SKB_TO_FREE;
  71. if (undo > 0)
  72. cvmx_fau_atomic_add32(fau, -undo);
  73. skb_to_free = -skb_to_free > MAX_SKB_TO_FREE ? MAX_SKB_TO_FREE : -skb_to_free;
  74. return skb_to_free;
  75. }
  76. static void cvm_oct_kick_tx_poll_watchdog(void)
  77. {
  78. union cvmx_ciu_timx ciu_timx;
  79. ciu_timx.u64 = 0;
  80. ciu_timx.s.one_shot = 1;
  81. ciu_timx.s.len = cvm_oct_tx_poll_interval;
  82. cvmx_write_csr(CVMX_CIU_TIMX(1), ciu_timx.u64);
  83. }
  84. void cvm_oct_free_tx_skbs(struct net_device *dev)
  85. {
  86. int32_t skb_to_free;
  87. int qos, queues_per_port;
  88. int total_freed = 0;
  89. int total_remaining = 0;
  90. unsigned long flags;
  91. struct octeon_ethernet *priv = netdev_priv(dev);
  92. queues_per_port = cvmx_pko_get_num_queues(priv->port);
  93. /* Drain any pending packets in the free list */
  94. for (qos = 0; qos < queues_per_port; qos++) {
  95. if (skb_queue_len(&priv->tx_free_list[qos]) == 0)
  96. continue;
  97. skb_to_free = cvmx_fau_fetch_and_add32(priv->fau+qos*4, MAX_SKB_TO_FREE);
  98. skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, priv->fau+qos*4);
  99. total_freed += skb_to_free;
  100. if (skb_to_free > 0) {
  101. struct sk_buff *to_free_list = NULL;
  102. spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
  103. while (skb_to_free > 0) {
  104. struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]);
  105. t->next = to_free_list;
  106. to_free_list = t;
  107. skb_to_free--;
  108. }
  109. spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
  110. /* Do the actual freeing outside of the lock. */
  111. while (to_free_list) {
  112. struct sk_buff *t = to_free_list;
  113. to_free_list = to_free_list->next;
  114. dev_kfree_skb_any(t);
  115. }
  116. }
  117. total_remaining += skb_queue_len(&priv->tx_free_list[qos]);
  118. }
  119. if (total_freed >= 0 && netif_queue_stopped(dev))
  120. netif_wake_queue(dev);
  121. if (total_remaining)
  122. cvm_oct_kick_tx_poll_watchdog();
  123. }
  124. /**
  125. * cvm_oct_xmit - transmit a packet
  126. * @skb: Packet to send
  127. * @dev: Device info structure
  128. *
  129. * Returns Always returns NETDEV_TX_OK
  130. */
  131. int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
  132. {
  133. cvmx_pko_command_word0_t pko_command;
  134. union cvmx_buf_ptr hw_buffer;
  135. uint64_t old_scratch;
  136. uint64_t old_scratch2;
  137. int qos;
  138. int i;
  139. enum {QUEUE_CORE, QUEUE_HW, QUEUE_DROP} queue_type;
  140. struct octeon_ethernet *priv = netdev_priv(dev);
  141. struct sk_buff *to_free_list;
  142. int32_t skb_to_free;
  143. int32_t buffers_to_free;
  144. u32 total_to_clean;
  145. unsigned long flags;
  146. #if REUSE_SKBUFFS_WITHOUT_FREE
  147. unsigned char *fpa_head;
  148. #endif
  149. /*
  150. * Prefetch the private data structure. It is larger that one
  151. * cache line.
  152. */
  153. prefetch(priv);
  154. /*
  155. * The check on CVMX_PKO_QUEUES_PER_PORT_* is designed to
  156. * completely remove "qos" in the event neither interface
  157. * supports multiple queues per port.
  158. */
  159. if ((CVMX_PKO_QUEUES_PER_PORT_INTERFACE0 > 1) ||
  160. (CVMX_PKO_QUEUES_PER_PORT_INTERFACE1 > 1)) {
  161. qos = GET_SKBUFF_QOS(skb);
  162. if (qos <= 0)
  163. qos = 0;
  164. else if (qos >= cvmx_pko_get_num_queues(priv->port))
  165. qos = 0;
  166. } else
  167. qos = 0;
  168. if (USE_ASYNC_IOBDMA) {
  169. /* Save scratch in case userspace is using it */
  170. CVMX_SYNCIOBDMA;
  171. old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
  172. old_scratch2 = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8);
  173. /*
  174. * Fetch and increment the number of packets to be
  175. * freed.
  176. */
  177. cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH + 8,
  178. FAU_NUM_PACKET_BUFFERS_TO_FREE,
  179. 0);
  180. cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH,
  181. priv->fau + qos * 4,
  182. MAX_SKB_TO_FREE);
  183. }
  184. /*
  185. * We have space for 6 segment pointers, If there will be more
  186. * than that, we must linearize.
  187. */
  188. if (unlikely(skb_shinfo(skb)->nr_frags > 5)) {
  189. if (unlikely(__skb_linearize(skb))) {
  190. queue_type = QUEUE_DROP;
  191. if (USE_ASYNC_IOBDMA) {
  192. /* Get the number of skbuffs in use by the hardware */
  193. CVMX_SYNCIOBDMA;
  194. skb_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
  195. } else {
  196. /* Get the number of skbuffs in use by the hardware */
  197. skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4,
  198. MAX_SKB_TO_FREE);
  199. }
  200. skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, priv->fau + qos * 4);
  201. spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
  202. goto skip_xmit;
  203. }
  204. }
  205. /*
  206. * The CN3XXX series of parts has an errata (GMX-401) which
  207. * causes the GMX block to hang if a collision occurs towards
  208. * the end of a <68 byte packet. As a workaround for this, we
  209. * pad packets to be 68 bytes whenever we are in half duplex
  210. * mode. We don't handle the case of having a small packet but
  211. * no room to add the padding. The kernel should always give
  212. * us at least a cache line
  213. */
  214. if ((skb->len < 64) && OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
  215. union cvmx_gmxx_prtx_cfg gmx_prt_cfg;
  216. int interface = INTERFACE(priv->port);
  217. int index = INDEX(priv->port);
  218. if (interface < 2) {
  219. /* We only need to pad packet in half duplex mode */
  220. gmx_prt_cfg.u64 =
  221. cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
  222. if (gmx_prt_cfg.s.duplex == 0) {
  223. int add_bytes = 64 - skb->len;
  224. if ((skb_tail_pointer(skb) + add_bytes) <=
  225. skb_end_pointer(skb))
  226. memset(__skb_put(skb, add_bytes), 0,
  227. add_bytes);
  228. }
  229. }
  230. }
  231. /* Build the PKO command */
  232. pko_command.u64 = 0;
  233. pko_command.s.n2 = 1; /* Don't pollute L2 with the outgoing packet */
  234. pko_command.s.segs = 1;
  235. pko_command.s.total_bytes = skb->len;
  236. pko_command.s.size0 = CVMX_FAU_OP_SIZE_32;
  237. pko_command.s.subone0 = 1;
  238. pko_command.s.dontfree = 1;
  239. /* Build the PKO buffer pointer */
  240. hw_buffer.u64 = 0;
  241. if (skb_shinfo(skb)->nr_frags == 0) {
  242. hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)skb->data);
  243. hw_buffer.s.pool = 0;
  244. hw_buffer.s.size = skb->len;
  245. } else {
  246. hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)skb->data);
  247. hw_buffer.s.pool = 0;
  248. hw_buffer.s.size = skb_headlen(skb);
  249. CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64;
  250. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  251. struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i;
  252. hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)(page_address(fs->page) + fs->page_offset));
  253. hw_buffer.s.size = fs->size;
  254. CVM_OCT_SKB_CB(skb)[i + 1] = hw_buffer.u64;
  255. }
  256. hw_buffer.s.addr = XKPHYS_TO_PHYS((u64)CVM_OCT_SKB_CB(skb));
  257. hw_buffer.s.size = skb_shinfo(skb)->nr_frags + 1;
  258. pko_command.s.segs = skb_shinfo(skb)->nr_frags + 1;
  259. pko_command.s.gather = 1;
  260. goto dont_put_skbuff_in_hw;
  261. }
  262. /*
  263. * See if we can put this skb in the FPA pool. Any strange
  264. * behavior from the Linux networking stack will most likely
  265. * be caused by a bug in the following code. If some field is
  266. * in use by the network stack and get carried over when a
  267. * buffer is reused, bad thing may happen. If in doubt and
  268. * you dont need the absolute best performance, disable the
  269. * define REUSE_SKBUFFS_WITHOUT_FREE. The reuse of buffers has
  270. * shown a 25% increase in performance under some loads.
  271. */
  272. #if REUSE_SKBUFFS_WITHOUT_FREE
  273. fpa_head = skb->head + 256 - ((unsigned long)skb->head & 0x7f);
  274. if (unlikely(skb->data < fpa_head)) {
  275. /*
  276. * printk("TX buffer beginning can't meet FPA
  277. * alignment constraints\n");
  278. */
  279. goto dont_put_skbuff_in_hw;
  280. }
  281. if (unlikely
  282. ((skb_end_pointer(skb) - fpa_head) < CVMX_FPA_PACKET_POOL_SIZE)) {
  283. /*
  284. printk("TX buffer isn't large enough for the FPA\n");
  285. */
  286. goto dont_put_skbuff_in_hw;
  287. }
  288. if (unlikely(skb_shared(skb))) {
  289. /*
  290. printk("TX buffer sharing data with someone else\n");
  291. */
  292. goto dont_put_skbuff_in_hw;
  293. }
  294. if (unlikely(skb_cloned(skb))) {
  295. /*
  296. printk("TX buffer has been cloned\n");
  297. */
  298. goto dont_put_skbuff_in_hw;
  299. }
  300. if (unlikely(skb_header_cloned(skb))) {
  301. /*
  302. printk("TX buffer header has been cloned\n");
  303. */
  304. goto dont_put_skbuff_in_hw;
  305. }
  306. if (unlikely(skb->destructor)) {
  307. /*
  308. printk("TX buffer has a destructor\n");
  309. */
  310. goto dont_put_skbuff_in_hw;
  311. }
  312. if (unlikely(skb_shinfo(skb)->nr_frags)) {
  313. /*
  314. printk("TX buffer has fragments\n");
  315. */
  316. goto dont_put_skbuff_in_hw;
  317. }
  318. if (unlikely
  319. (skb->truesize !=
  320. sizeof(*skb) + skb_end_pointer(skb) - skb->head)) {
  321. /*
  322. printk("TX buffer truesize has been changed\n");
  323. */
  324. goto dont_put_skbuff_in_hw;
  325. }
  326. /*
  327. * We can use this buffer in the FPA. We don't need the FAU
  328. * update anymore
  329. */
  330. pko_command.s.dontfree = 0;
  331. hw_buffer.s.back = ((unsigned long)skb->data >> 7) - ((unsigned long)fpa_head >> 7);
  332. *(struct sk_buff **)(fpa_head - sizeof(void *)) = skb;
  333. /*
  334. * The skbuff will be reused without ever being freed. We must
  335. * cleanup a bunch of core things.
  336. */
  337. dst_release(skb_dst(skb));
  338. skb_dst_set(skb, NULL);
  339. #ifdef CONFIG_XFRM
  340. secpath_put(skb->sp);
  341. skb->sp = NULL;
  342. #endif
  343. nf_reset(skb);
  344. #ifdef CONFIG_NET_SCHED
  345. skb->tc_index = 0;
  346. #ifdef CONFIG_NET_CLS_ACT
  347. skb->tc_verd = 0;
  348. #endif /* CONFIG_NET_CLS_ACT */
  349. #endif /* CONFIG_NET_SCHED */
  350. #endif /* REUSE_SKBUFFS_WITHOUT_FREE */
  351. dont_put_skbuff_in_hw:
  352. /* Check if we can use the hardware checksumming */
  353. if (USE_HW_TCPUDP_CHECKSUM && (skb->protocol == htons(ETH_P_IP)) &&
  354. (ip_hdr(skb)->version == 4) && (ip_hdr(skb)->ihl == 5) &&
  355. ((ip_hdr(skb)->frag_off == 0) || (ip_hdr(skb)->frag_off == 1 << 14))
  356. && ((ip_hdr(skb)->protocol == IPPROTO_TCP)
  357. || (ip_hdr(skb)->protocol == IPPROTO_UDP))) {
  358. /* Use hardware checksum calc */
  359. pko_command.s.ipoffp1 = sizeof(struct ethhdr) + 1;
  360. }
  361. if (USE_ASYNC_IOBDMA) {
  362. /* Get the number of skbuffs in use by the hardware */
  363. CVMX_SYNCIOBDMA;
  364. skb_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
  365. buffers_to_free = cvmx_scratch_read64(CVMX_SCR_SCRATCH + 8);
  366. } else {
  367. /* Get the number of skbuffs in use by the hardware */
  368. skb_to_free = cvmx_fau_fetch_and_add32(priv->fau + qos * 4,
  369. MAX_SKB_TO_FREE);
  370. buffers_to_free =
  371. cvmx_fau_fetch_and_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, 0);
  372. }
  373. skb_to_free = cvm_oct_adjust_skb_to_free(skb_to_free, priv->fau+qos*4);
  374. /*
  375. * If we're sending faster than the receive can free them then
  376. * don't do the HW free.
  377. */
  378. if ((buffers_to_free < -100) && !pko_command.s.dontfree)
  379. pko_command.s.dontfree = 1;
  380. if (pko_command.s.dontfree) {
  381. queue_type = QUEUE_CORE;
  382. pko_command.s.reg0 = priv->fau+qos*4;
  383. } else {
  384. queue_type = QUEUE_HW;
  385. }
  386. if (USE_ASYNC_IOBDMA)
  387. cvmx_fau_async_fetch_and_add32(CVMX_SCR_SCRATCH, FAU_TOTAL_TX_TO_CLEAN, 1);
  388. spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
  389. /* Drop this packet if we have too many already queued to the HW */
  390. if (unlikely(skb_queue_len(&priv->tx_free_list[qos]) >= MAX_OUT_QUEUE_DEPTH)) {
  391. if (dev->tx_queue_len != 0) {
  392. /* Drop the lock when notifying the core. */
  393. spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
  394. netif_stop_queue(dev);
  395. spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
  396. } else {
  397. /* If not using normal queueing. */
  398. queue_type = QUEUE_DROP;
  399. goto skip_xmit;
  400. }
  401. }
  402. cvmx_pko_send_packet_prepare(priv->port, priv->queue + qos,
  403. CVMX_PKO_LOCK_NONE);
  404. /* Send the packet to the output queue */
  405. if (unlikely(cvmx_pko_send_packet_finish(priv->port,
  406. priv->queue + qos,
  407. pko_command, hw_buffer,
  408. CVMX_PKO_LOCK_NONE))) {
  409. printk_ratelimited("%s: Failed to send the packet\n", dev->name);
  410. queue_type = QUEUE_DROP;
  411. }
  412. skip_xmit:
  413. to_free_list = NULL;
  414. switch (queue_type) {
  415. case QUEUE_DROP:
  416. skb->next = to_free_list;
  417. to_free_list = skb;
  418. priv->stats.tx_dropped++;
  419. break;
  420. case QUEUE_HW:
  421. cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, -1);
  422. break;
  423. case QUEUE_CORE:
  424. __skb_queue_tail(&priv->tx_free_list[qos], skb);
  425. break;
  426. default:
  427. BUG();
  428. }
  429. while (skb_to_free > 0) {
  430. struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]);
  431. t->next = to_free_list;
  432. to_free_list = t;
  433. skb_to_free--;
  434. }
  435. spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
  436. /* Do the actual freeing outside of the lock. */
  437. while (to_free_list) {
  438. struct sk_buff *t = to_free_list;
  439. to_free_list = to_free_list->next;
  440. dev_kfree_skb_any(t);
  441. }
  442. if (USE_ASYNC_IOBDMA) {
  443. CVMX_SYNCIOBDMA;
  444. total_to_clean = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
  445. /* Restore the scratch area */
  446. cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch);
  447. cvmx_scratch_write64(CVMX_SCR_SCRATCH + 8, old_scratch2);
  448. } else {
  449. total_to_clean = cvmx_fau_fetch_and_add32(FAU_TOTAL_TX_TO_CLEAN, 1);
  450. }
  451. if (total_to_clean & 0x3ff) {
  452. /*
  453. * Schedule the cleanup tasklet every 1024 packets for
  454. * the pathological case of high traffic on one port
  455. * delaying clean up of packets on a different port
  456. * that is blocked waiting for the cleanup.
  457. */
  458. tasklet_schedule(&cvm_oct_tx_cleanup_tasklet);
  459. }
  460. cvm_oct_kick_tx_poll_watchdog();
  461. return NETDEV_TX_OK;
  462. }
  463. /**
  464. * cvm_oct_xmit_pow - transmit a packet to the POW
  465. * @skb: Packet to send
  466. * @dev: Device info structure
  467. * Returns Always returns zero
  468. */
  469. int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
  470. {
  471. struct octeon_ethernet *priv = netdev_priv(dev);
  472. void *packet_buffer;
  473. void *copy_location;
  474. /* Get a work queue entry */
  475. cvmx_wqe_t *work = cvmx_fpa_alloc(CVMX_FPA_WQE_POOL);
  476. if (unlikely(work == NULL)) {
  477. printk_ratelimited("%s: Failed to allocate a work "
  478. "queue entry\n", dev->name);
  479. priv->stats.tx_dropped++;
  480. dev_kfree_skb(skb);
  481. return 0;
  482. }
  483. /* Get a packet buffer */
  484. packet_buffer = cvmx_fpa_alloc(CVMX_FPA_PACKET_POOL);
  485. if (unlikely(packet_buffer == NULL)) {
  486. printk_ratelimited("%s: Failed to allocate a packet buffer\n",
  487. dev->name);
  488. cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, DONT_WRITEBACK(1));
  489. priv->stats.tx_dropped++;
  490. dev_kfree_skb(skb);
  491. return 0;
  492. }
  493. /*
  494. * Calculate where we need to copy the data to. We need to
  495. * leave 8 bytes for a next pointer (unused). We also need to
  496. * include any configure skip. Then we need to align the IP
  497. * packet src and dest into the same 64bit word. The below
  498. * calculation may add a little extra, but that doesn't
  499. * hurt.
  500. */
  501. copy_location = packet_buffer + sizeof(uint64_t);
  502. copy_location += ((CVMX_HELPER_FIRST_MBUFF_SKIP + 7) & 0xfff8) + 6;
  503. /*
  504. * We have to copy the packet since whoever processes this
  505. * packet will free it to a hardware pool. We can't use the
  506. * trick of counting outstanding packets like in
  507. * cvm_oct_xmit.
  508. */
  509. memcpy(copy_location, skb->data, skb->len);
  510. /*
  511. * Fill in some of the work queue fields. We may need to add
  512. * more if the software at the other end needs them.
  513. */
  514. work->hw_chksum = skb->csum;
  515. work->len = skb->len;
  516. work->ipprt = priv->port;
  517. work->qos = priv->port & 0x7;
  518. work->grp = pow_send_group;
  519. work->tag_type = CVMX_HELPER_INPUT_TAG_TYPE;
  520. work->tag = pow_send_group; /* FIXME */
  521. /* Default to zero. Sets of zero later are commented out */
  522. work->word2.u64 = 0;
  523. work->word2.s.bufs = 1;
  524. work->packet_ptr.u64 = 0;
  525. work->packet_ptr.s.addr = cvmx_ptr_to_phys(copy_location);
  526. work->packet_ptr.s.pool = CVMX_FPA_PACKET_POOL;
  527. work->packet_ptr.s.size = CVMX_FPA_PACKET_POOL_SIZE;
  528. work->packet_ptr.s.back = (copy_location - packet_buffer) >> 7;
  529. if (skb->protocol == htons(ETH_P_IP)) {
  530. work->word2.s.ip_offset = 14;
  531. #if 0
  532. work->word2.s.vlan_valid = 0; /* FIXME */
  533. work->word2.s.vlan_cfi = 0; /* FIXME */
  534. work->word2.s.vlan_id = 0; /* FIXME */
  535. work->word2.s.dec_ipcomp = 0; /* FIXME */
  536. #endif
  537. work->word2.s.tcp_or_udp =
  538. (ip_hdr(skb)->protocol == IPPROTO_TCP)
  539. || (ip_hdr(skb)->protocol == IPPROTO_UDP);
  540. #if 0
  541. /* FIXME */
  542. work->word2.s.dec_ipsec = 0;
  543. /* We only support IPv4 right now */
  544. work->word2.s.is_v6 = 0;
  545. /* Hardware would set to zero */
  546. work->word2.s.software = 0;
  547. /* No error, packet is internal */
  548. work->word2.s.L4_error = 0;
  549. #endif
  550. work->word2.s.is_frag = !((ip_hdr(skb)->frag_off == 0)
  551. || (ip_hdr(skb)->frag_off ==
  552. 1 << 14));
  553. #if 0
  554. /* Assume Linux is sending a good packet */
  555. work->word2.s.IP_exc = 0;
  556. #endif
  557. work->word2.s.is_bcast = (skb->pkt_type == PACKET_BROADCAST);
  558. work->word2.s.is_mcast = (skb->pkt_type == PACKET_MULTICAST);
  559. #if 0
  560. /* This is an IP packet */
  561. work->word2.s.not_IP = 0;
  562. /* No error, packet is internal */
  563. work->word2.s.rcv_error = 0;
  564. /* No error, packet is internal */
  565. work->word2.s.err_code = 0;
  566. #endif
  567. /*
  568. * When copying the data, include 4 bytes of the
  569. * ethernet header to align the same way hardware
  570. * does.
  571. */
  572. memcpy(work->packet_data, skb->data + 10,
  573. sizeof(work->packet_data));
  574. } else {
  575. #if 0
  576. work->word2.snoip.vlan_valid = 0; /* FIXME */
  577. work->word2.snoip.vlan_cfi = 0; /* FIXME */
  578. work->word2.snoip.vlan_id = 0; /* FIXME */
  579. work->word2.snoip.software = 0; /* Hardware would set to zero */
  580. #endif
  581. work->word2.snoip.is_rarp = skb->protocol == htons(ETH_P_RARP);
  582. work->word2.snoip.is_arp = skb->protocol == htons(ETH_P_ARP);
  583. work->word2.snoip.is_bcast =
  584. (skb->pkt_type == PACKET_BROADCAST);
  585. work->word2.snoip.is_mcast =
  586. (skb->pkt_type == PACKET_MULTICAST);
  587. work->word2.snoip.not_IP = 1; /* IP was done up above */
  588. #if 0
  589. /* No error, packet is internal */
  590. work->word2.snoip.rcv_error = 0;
  591. /* No error, packet is internal */
  592. work->word2.snoip.err_code = 0;
  593. #endif
  594. memcpy(work->packet_data, skb->data, sizeof(work->packet_data));
  595. }
  596. /* Submit the packet to the POW */
  597. cvmx_pow_work_submit(work, work->tag, work->tag_type, work->qos,
  598. work->grp);
  599. priv->stats.tx_packets++;
  600. priv->stats.tx_bytes += skb->len;
  601. dev_kfree_skb(skb);
  602. return 0;
  603. }
  604. /**
  605. * cvm_oct_tx_shutdown_dev - free all skb that are currently queued for TX.
  606. * @dev: Device being shutdown
  607. *
  608. */
  609. void cvm_oct_tx_shutdown_dev(struct net_device *dev)
  610. {
  611. struct octeon_ethernet *priv = netdev_priv(dev);
  612. unsigned long flags;
  613. int qos;
  614. for (qos = 0; qos < 16; qos++) {
  615. spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
  616. while (skb_queue_len(&priv->tx_free_list[qos]))
  617. dev_kfree_skb_any(__skb_dequeue
  618. (&priv->tx_free_list[qos]));
  619. spin_unlock_irqrestore(&priv->tx_free_list[qos].lock, flags);
  620. }
  621. }
  622. static void cvm_oct_tx_do_cleanup(unsigned long arg)
  623. {
  624. int port;
  625. for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) {
  626. if (cvm_oct_device[port]) {
  627. struct net_device *dev = cvm_oct_device[port];
  628. cvm_oct_free_tx_skbs(dev);
  629. }
  630. }
  631. }
  632. static irqreturn_t cvm_oct_tx_cleanup_watchdog(int cpl, void *dev_id)
  633. {
  634. /* Disable the interrupt. */
  635. cvmx_write_csr(CVMX_CIU_TIMX(1), 0);
  636. /* Do the work in the tasklet. */
  637. tasklet_schedule(&cvm_oct_tx_cleanup_tasklet);
  638. return IRQ_HANDLED;
  639. }
  640. void cvm_oct_tx_initialize(void)
  641. {
  642. int i;
  643. /* Disable the interrupt. */
  644. cvmx_write_csr(CVMX_CIU_TIMX(1), 0);
  645. /* Register an IRQ hander for to receive CIU_TIMX(1) interrupts */
  646. i = request_irq(OCTEON_IRQ_TIMER1,
  647. cvm_oct_tx_cleanup_watchdog, 0,
  648. "Ethernet", cvm_oct_device);
  649. if (i)
  650. panic("Could not acquire Ethernet IRQ %d\n", OCTEON_IRQ_TIMER1);
  651. }
  652. void cvm_oct_tx_shutdown(void)
  653. {
  654. /* Free the interrupt handler */
  655. free_irq(OCTEON_IRQ_TIMER1, cvm_oct_device);
  656. }