qed_ll2.c 66.4 KB
Newer Older
Y
Yuval Mintz 已提交
1
/* QLogic qed NIC Driver
M
Mintz, Yuval 已提交
2
 * Copyright (c) 2015-2017  QLogic Corporation
Y
Yuval Mintz 已提交
3
 *
M
Mintz, Yuval 已提交
4 5 6 7 8
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
Y
Yuval Mintz 已提交
9
 *
M
Mintz, Yuval 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and /or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
Y
Yuval Mintz 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
 */

#include <linux/types.h>
#include <asm/byteorder.h>
#include <linux/dma-mapping.h>
#include <linux/if_vlan.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/stddef.h>
#include <linux/workqueue.h>
#include <net/ipv6.h>
#include <linux/bitops.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/io.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/qed/qed_ll2_if.h>
#include "qed.h"
#include "qed_cxt.h"
#include "qed_dev_api.h"
#include "qed_hsi.h"
#include "qed_hw.h"
#include "qed_int.h"
#include "qed_ll2.h"
#include "qed_mcp.h"
61
#include "qed_ooo.h"
Y
Yuval Mintz 已提交
62 63
#include "qed_reg_addr.h"
#include "qed_sp.h"
64
#include "qed_rdma.h"
Y
Yuval Mintz 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

#define QED_LL2_RX_REGISTERED(ll2)	((ll2)->rx_queue.b_cb_registred)
#define QED_LL2_TX_REGISTERED(ll2)	((ll2)->tx_queue.b_cb_registred)

#define QED_LL2_TX_SIZE (256)
#define QED_LL2_RX_SIZE (4096)

struct qed_cb_ll2_info {
	int rx_cnt;
	u32 rx_size;
	u8 handle;

	/* Lock protecting LL2 buffer lists in sleepless context */
	spinlock_t lock;
	struct list_head list;

	const struct qed_ll2_cb_ops *cbs;
	void *cb_cookie;
};

struct qed_ll2_buffer {
	struct list_head list;
	void *data;
	dma_addr_t phys_addr;
};

M
Michal Kalderon 已提交
91
static void qed_ll2b_complete_tx_packet(void *cxt,
Y
Yuval Mintz 已提交
92 93 94 95 96 97
					u8 connection_handle,
					void *cookie,
					dma_addr_t first_frag_addr,
					bool b_last_fragment,
					bool b_last_packet)
{
M
Michal Kalderon 已提交
98
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	struct qed_dev *cdev = p_hwfn->cdev;
	struct sk_buff *skb = cookie;

	/* All we need to do is release the mapping */
	dma_unmap_single(&p_hwfn->cdev->pdev->dev, first_frag_addr,
			 skb_headlen(skb), DMA_TO_DEVICE);

	if (cdev->ll2->cbs && cdev->ll2->cbs->tx_cb)
		cdev->ll2->cbs->tx_cb(cdev->ll2->cb_cookie, skb,
				      b_last_fragment);

	dev_kfree_skb_any(skb);
}

static int qed_ll2_alloc_buffer(struct qed_dev *cdev,
				u8 **data, dma_addr_t *phys_addr)
{
	*data = kmalloc(cdev->ll2->rx_size, GFP_ATOMIC);
	if (!(*data)) {
		DP_INFO(cdev, "Failed to allocate LL2 buffer data\n");
		return -ENOMEM;
	}

	*phys_addr = dma_map_single(&cdev->pdev->dev,
				    ((*data) + NET_SKB_PAD),
				    cdev->ll2->rx_size, DMA_FROM_DEVICE);
	if (dma_mapping_error(&cdev->pdev->dev, *phys_addr)) {
		DP_INFO(cdev, "Failed to map LL2 buffer data\n");
		kfree((*data));
		return -ENOMEM;
	}

	return 0;
}

static int qed_ll2_dealloc_buffer(struct qed_dev *cdev,
				 struct qed_ll2_buffer *buffer)
{
	spin_lock_bh(&cdev->ll2->lock);

	dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
			 cdev->ll2->rx_size, DMA_FROM_DEVICE);
	kfree(buffer->data);
	list_del(&buffer->list);

	cdev->ll2->rx_cnt--;
	if (!cdev->ll2->rx_cnt)
		DP_INFO(cdev, "All LL2 entries were removed\n");

	spin_unlock_bh(&cdev->ll2->lock);

	return 0;
}

static void qed_ll2_kill_buffers(struct qed_dev *cdev)
{
	struct qed_ll2_buffer *buffer, *tmp_buffer;

	list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list)
		qed_ll2_dealloc_buffer(cdev, buffer);
}

M
Michal Kalderon 已提交
161
void qed_ll2b_complete_rx_packet(void *cxt, struct qed_ll2_comp_rx_data *data)
Y
Yuval Mintz 已提交
162
{
M
Michal Kalderon 已提交
163
	struct qed_hwfn *p_hwfn = cxt;
M
Mintz, Yuval 已提交
164
	struct qed_ll2_buffer *buffer = data->cookie;
Y
Yuval Mintz 已提交
165 166 167 168 169 170 171 172 173 174
	struct qed_dev *cdev = p_hwfn->cdev;
	dma_addr_t new_phys_addr;
	struct sk_buff *skb;
	bool reuse = false;
	int rc = -EINVAL;
	u8 *new_data;

	DP_VERBOSE(p_hwfn,
		   (NETIF_MSG_RX_STATUS | QED_MSG_STORAGE | NETIF_MSG_PKTDATA),
		   "Got an LL2 Rx completion: [Buffer at phys 0x%llx, offset 0x%02x] Length 0x%04x Parse_flags 0x%04x vlan 0x%04x Opaque data [0x%08x:0x%08x]\n",
M
Mintz, Yuval 已提交
175 176 177 178 179
		   (u64)data->rx_buf_addr,
		   data->u.placement_offset,
		   data->length.packet_length,
		   data->parse_flags,
		   data->vlan, data->opaque_data_0, data->opaque_data_1);
Y
Yuval Mintz 已提交
180 181 182 183

	if ((cdev->dp_module & NETIF_MSG_PKTDATA) && buffer->data) {
		print_hex_dump(KERN_INFO, "",
			       DUMP_PREFIX_OFFSET, 16, 1,
M
Mintz, Yuval 已提交
184
			       buffer->data, data->length.packet_length, false);
Y
Yuval Mintz 已提交
185 186 187
	}

	/* Determine if data is valid */
M
Mintz, Yuval 已提交
188
	if (data->length.packet_length < ETH_HLEN)
Y
Yuval Mintz 已提交
189 190 191 192 193 194 195 196 197 198
		reuse = true;

	/* Allocate a replacement for buffer; Reuse upon failure */
	if (!reuse)
		rc = qed_ll2_alloc_buffer(p_hwfn->cdev, &new_data,
					  &new_phys_addr);

	/* If need to reuse or there's no replacement buffer, repost this */
	if (rc)
		goto out_post;
199 200
	dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
			 cdev->ll2->rx_size, DMA_FROM_DEVICE);
Y
Yuval Mintz 已提交
201 202 203 204 205 206 207

	skb = build_skb(buffer->data, 0);
	if (!skb) {
		rc = -ENOMEM;
		goto out_post;
	}

M
Mintz, Yuval 已提交
208 209 210
	data->u.placement_offset += NET_SKB_PAD;
	skb_reserve(skb, data->u.placement_offset);
	skb_put(skb, data->length.packet_length);
Y
Yuval Mintz 已提交
211 212 213 214 215 216 217 218 219 220
	skb_checksum_none_assert(skb);

	/* Get parital ethernet information instead of eth_type_trans(),
	 * Since we don't have an associated net_device.
	 */
	skb_reset_mac_header(skb);
	skb->protocol = eth_hdr(skb)->h_proto;

	/* Pass SKB onward */
	if (cdev->ll2->cbs && cdev->ll2->cbs->rx_cb) {
M
Mintz, Yuval 已提交
221 222 223
		if (data->vlan)
			__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
					       data->vlan);
Y
Yuval Mintz 已提交
224
		cdev->ll2->cbs->rx_cb(cdev->ll2->cb_cookie, skb,
M
Mintz, Yuval 已提交
225 226
				      data->opaque_data_0,
				      data->opaque_data_1);
Y
Yuval Mintz 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
	}

	/* Update Buffer information and update FW producer */
	buffer->data = new_data;
	buffer->phys_addr = new_phys_addr;

out_post:
	rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev), cdev->ll2->handle,
				    buffer->phys_addr, 0,  buffer, 1);

	if (rc)
		qed_ll2_dealloc_buffer(cdev, buffer);
}

static struct qed_ll2_info *__qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn,
						    u8 connection_handle,
						    bool b_lock,
						    bool b_only_active)
{
	struct qed_ll2_info *p_ll2_conn, *p_ret = NULL;

	if (connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS)
		return NULL;

	if (!p_hwfn->p_ll2_info)
		return NULL;

	p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle];

	if (b_only_active) {
		if (b_lock)
			mutex_lock(&p_ll2_conn->mutex);
		if (p_ll2_conn->b_active)
			p_ret = p_ll2_conn;
		if (b_lock)
			mutex_unlock(&p_ll2_conn->mutex);
	} else {
		p_ret = p_ll2_conn;
	}

	return p_ret;
}

static struct qed_ll2_info *qed_ll2_handle_sanity(struct qed_hwfn *p_hwfn,
						  u8 connection_handle)
{
	return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, true);
}

static struct qed_ll2_info *qed_ll2_handle_sanity_lock(struct qed_hwfn *p_hwfn,
						       u8 connection_handle)
{
	return __qed_ll2_handle_sanity(p_hwfn, connection_handle, true, true);
}

static struct qed_ll2_info *qed_ll2_handle_sanity_inactive(struct qed_hwfn
							   *p_hwfn,
							   u8 connection_handle)
{
	return __qed_ll2_handle_sanity(p_hwfn, connection_handle, false, false);
}

static void qed_ll2_txq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
{
	bool b_last_packet = false, b_last_frag = false;
	struct qed_ll2_tx_packet *p_pkt = NULL;
	struct qed_ll2_info *p_ll2_conn;
	struct qed_ll2_tx_queue *p_tx;
R
Ram Amrani 已提交
295
	dma_addr_t tx_frag;
Y
Yuval Mintz 已提交
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

	p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
	if (!p_ll2_conn)
		return;

	p_tx = &p_ll2_conn->tx_queue;

	while (!list_empty(&p_tx->active_descq)) {
		p_pkt = list_first_entry(&p_tx->active_descq,
					 struct qed_ll2_tx_packet, list_entry);
		if (!p_pkt)
			break;

		list_del(&p_pkt->list_entry);
		b_last_packet = list_empty(&p_tx->active_descq);
		list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
312
		if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) {
313
			struct qed_ooo_buffer *p_buffer;
Y
Yuval Mintz 已提交
314

315 316 317 318 319 320 321 322 323
			p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
			qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
						p_buffer);
		} else {
			p_tx->cur_completing_packet = *p_pkt;
			p_tx->cur_completing_bd_idx = 1;
			b_last_frag =
				p_tx->cur_completing_bd_idx == p_pkt->bd_used;
			tx_frag = p_pkt->bds_set[0].tx_frag;
M
Michal Kalderon 已提交
324 325 326 327 328 329
			p_ll2_conn->cbs.tx_release_cb(p_ll2_conn->cbs.cookie,
						      p_ll2_conn->my_id,
						      p_pkt->cookie,
						      tx_frag,
						      b_last_frag,
						      b_last_packet);
330
		}
Y
Yuval Mintz 已提交
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
	}
}

static int qed_ll2_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
{
	struct qed_ll2_info *p_ll2_conn = p_cookie;
	struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
	u16 new_idx = 0, num_bds = 0, num_bds_in_packet = 0;
	struct qed_ll2_tx_packet *p_pkt;
	bool b_last_frag = false;
	unsigned long flags;
	int rc = -EINVAL;

	spin_lock_irqsave(&p_tx->lock, flags);
	if (p_tx->b_completing_packet) {
		rc = -EBUSY;
		goto out;
	}

	new_idx = le16_to_cpu(*p_tx->p_fw_cons);
	num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);
	while (num_bds) {
		if (list_empty(&p_tx->active_descq))
			goto out;

		p_pkt = list_first_entry(&p_tx->active_descq,
					 struct qed_ll2_tx_packet, list_entry);
		if (!p_pkt)
			goto out;

		p_tx->b_completing_packet = true;
		p_tx->cur_completing_packet = *p_pkt;
		num_bds_in_packet = p_pkt->bd_used;
		list_del(&p_pkt->list_entry);

		if (num_bds < num_bds_in_packet) {
			DP_NOTICE(p_hwfn,
				  "Rest of BDs does not cover whole packet\n");
			goto out;
		}

		num_bds -= num_bds_in_packet;
		p_tx->bds_idx += num_bds_in_packet;
		while (num_bds_in_packet--)
			qed_chain_consume(&p_tx->txq_chain);

		p_tx->cur_completing_bd_idx = 1;
		b_last_frag = p_tx->cur_completing_bd_idx == p_pkt->bd_used;
		list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);

		spin_unlock_irqrestore(&p_tx->lock, flags);
M
Michal Kalderon 已提交
382 383 384 385 386 387 388

		p_ll2_conn->cbs.tx_comp_cb(p_ll2_conn->cbs.cookie,
					   p_ll2_conn->my_id,
					   p_pkt->cookie,
					   p_pkt->bds_set[0].tx_frag,
					   b_last_frag, !num_bds);

Y
Yuval Mintz 已提交
389 390 391 392 393 394 395 396 397 398
		spin_lock_irqsave(&p_tx->lock, flags);
	}

	p_tx->b_completing_packet = false;
	rc = 0;
out:
	spin_unlock_irqrestore(&p_tx->lock, flags);
	return rc;
}

M
Michal Kalderon 已提交
399 400 401
static void qed_ll2_rxq_parse_gsi(struct qed_hwfn *p_hwfn,
				  union core_rx_cqe_union *p_cqe,
				  struct qed_ll2_comp_rx_data *data)
R
Ram Amrani 已提交
402
{
M
Michal Kalderon 已提交
403 404 405 406 407 408
	data->parse_flags = le16_to_cpu(p_cqe->rx_cqe_gsi.parse_flags.flags);
	data->length.data_length = le16_to_cpu(p_cqe->rx_cqe_gsi.data_length);
	data->vlan = le16_to_cpu(p_cqe->rx_cqe_gsi.vlan);
	data->opaque_data_0 = le32_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrhi);
	data->opaque_data_1 = le16_to_cpu(p_cqe->rx_cqe_gsi.src_mac_addrlo);
	data->u.data_length_error = p_cqe->rx_cqe_gsi.data_length_error;
R
Ram Amrani 已提交
409 410
}

M
Mintz, Yuval 已提交
411 412 413 414 415
static void qed_ll2_rxq_parse_reg(struct qed_hwfn *p_hwfn,
				  union core_rx_cqe_union *p_cqe,
				  struct qed_ll2_comp_rx_data *data)
{
	data->parse_flags = le16_to_cpu(p_cqe->rx_cqe_fp.parse_flags.flags);
416
	data->err_flags = le16_to_cpu(p_cqe->rx_cqe_fp.err_flags.flags);
M
Mintz, Yuval 已提交
417 418 419 420 421 422 423 424 425 426 427 428 429
	data->length.packet_length =
	    le16_to_cpu(p_cqe->rx_cqe_fp.packet_length);
	data->vlan = le16_to_cpu(p_cqe->rx_cqe_fp.vlan);
	data->opaque_data_0 = le32_to_cpu(p_cqe->rx_cqe_fp.opaque_data.data[0]);
	data->opaque_data_1 = le32_to_cpu(p_cqe->rx_cqe_fp.opaque_data.data[1]);
	data->u.placement_offset = p_cqe->rx_cqe_fp.placement_offset;
}

static int
qed_ll2_rxq_handle_completion(struct qed_hwfn *p_hwfn,
			      struct qed_ll2_info *p_ll2_conn,
			      union core_rx_cqe_union *p_cqe,
			      unsigned long *p_lock_flags, bool b_last_cqe)
Y
Yuval Mintz 已提交
430 431 432
{
	struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
	struct qed_ll2_rx_packet *p_pkt = NULL;
M
Mintz, Yuval 已提交
433
	struct qed_ll2_comp_rx_data data;
Y
Yuval Mintz 已提交
434 435 436 437 438 439

	if (!list_empty(&p_rx->active_descq))
		p_pkt = list_first_entry(&p_rx->active_descq,
					 struct qed_ll2_rx_packet, list_entry);
	if (!p_pkt) {
		DP_NOTICE(p_hwfn,
M
Mintz, Yuval 已提交
440
			  "[%d] LL2 Rx completion but active_descq is empty\n",
441
			  p_ll2_conn->input.conn_type);
M
Mintz, Yuval 已提交
442

Y
Yuval Mintz 已提交
443 444 445 446
		return -EIO;
	}
	list_del(&p_pkt->list_entry);

M
Michal Kalderon 已提交
447 448 449 450
	if (p_cqe->rx_cqe_sp.type == CORE_RX_CQE_TYPE_REGULAR)
		qed_ll2_rxq_parse_reg(p_hwfn, p_cqe, &data);
	else
		qed_ll2_rxq_parse_gsi(p_hwfn, p_cqe, &data);
Y
Yuval Mintz 已提交
451 452 453
	if (qed_chain_consume(&p_rx->rxq_chain) != p_pkt->rxq_bd)
		DP_NOTICE(p_hwfn,
			  "Mismatch between active_descq and the LL2 Rx chain\n");
M
Mintz, Yuval 已提交
454

Y
Yuval Mintz 已提交
455 456
	list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);

M
Mintz, Yuval 已提交
457 458 459 460 461
	data.connection_handle = p_ll2_conn->my_id;
	data.cookie = p_pkt->cookie;
	data.rx_buf_addr = p_pkt->rx_buf_addr;
	data.b_last_packet = b_last_cqe;

R
Ram Amrani 已提交
462
	spin_unlock_irqrestore(&p_rx->lock, *p_lock_flags);
M
Michal Kalderon 已提交
463 464
	p_ll2_conn->cbs.rx_comp_cb(p_ll2_conn->cbs.cookie, &data);

R
Ram Amrani 已提交
465
	spin_lock_irqsave(&p_rx->lock, *p_lock_flags);
Y
Yuval Mintz 已提交
466 467 468 469 470 471

	return 0;
}

static int qed_ll2_rxq_completion(struct qed_hwfn *p_hwfn, void *cookie)
{
472
	struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)cookie;
Y
Yuval Mintz 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485
	struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
	union core_rx_cqe_union *cqe = NULL;
	u16 cq_new_idx = 0, cq_old_idx = 0;
	unsigned long flags = 0;
	int rc = 0;

	spin_lock_irqsave(&p_rx->lock, flags);
	cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons);
	cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);

	while (cq_new_idx != cq_old_idx) {
		bool b_last_cqe = (cq_new_idx == cq_old_idx);

486 487 488
		cqe =
		    (union core_rx_cqe_union *)
		    qed_chain_consume(&p_rx->rcq_chain);
Y
Yuval Mintz 已提交
489 490 491 492 493 494 495 496 497 498 499 500
		cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);

		DP_VERBOSE(p_hwfn,
			   QED_MSG_LL2,
			   "LL2 [sw. cons %04x, fw. at %04x] - Got Packet of type %02x\n",
			   cq_old_idx, cq_new_idx, cqe->rx_cqe_sp.type);

		switch (cqe->rx_cqe_sp.type) {
		case CORE_RX_CQE_TYPE_SLOW_PATH:
			DP_NOTICE(p_hwfn, "LL2 - unexpected Rx CQE slowpath\n");
			rc = -EINVAL;
			break;
R
Ram Amrani 已提交
501
		case CORE_RX_CQE_TYPE_GSI_OFFLOAD:
Y
Yuval Mintz 已提交
502
		case CORE_RX_CQE_TYPE_REGULAR:
M
Mintz, Yuval 已提交
503 504 505
			rc = qed_ll2_rxq_handle_completion(p_hwfn, p_ll2_conn,
							   cqe, &flags,
							   b_last_cqe);
Y
Yuval Mintz 已提交
506 507 508 509 510 511 512 513 514 515
			break;
		default:
			rc = -EIO;
		}
	}

	spin_unlock_irqrestore(&p_rx->lock, flags);
	return rc;
}

516
static void qed_ll2_rxq_flush(struct qed_hwfn *p_hwfn, u8 connection_handle)
Y
Yuval Mintz 已提交
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
{
	struct qed_ll2_info *p_ll2_conn = NULL;
	struct qed_ll2_rx_packet *p_pkt = NULL;
	struct qed_ll2_rx_queue *p_rx;

	p_ll2_conn = qed_ll2_handle_sanity_inactive(p_hwfn, connection_handle);
	if (!p_ll2_conn)
		return;

	p_rx = &p_ll2_conn->rx_queue;

	while (!list_empty(&p_rx->active_descq)) {
		p_pkt = list_first_entry(&p_rx->active_descq,
					 struct qed_ll2_rx_packet, list_entry);
		if (!p_pkt)
			break;

534
		list_move_tail(&p_pkt->list_entry, &p_rx->free_descq);
Y
Yuval Mintz 已提交
535

536
		if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO) {
537 538 539 540 541 542
			struct qed_ooo_buffer *p_buffer;

			p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
			qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
						p_buffer);
		} else {
543 544 545
			dma_addr_t rx_buf_addr = p_pkt->rx_buf_addr;
			void *cookie = p_pkt->cookie;
			bool b_last;
546 547

			b_last = list_empty(&p_rx->active_descq);
548 549 550 551
			p_ll2_conn->cbs.rx_release_cb(p_ll2_conn->cbs.cookie,
						      p_ll2_conn->my_id,
						      cookie,
						      rx_buf_addr, b_last);
552 553 554 555 556 557 558 559 560
		}
	}
}

static u8 qed_ll2_convert_rx_parse_to_tx_flags(u16 parse_flags)
{
	u8 bd_flags = 0;

	if (GET_FIELD(parse_flags, PARSING_AND_ERR_FLAGS_TAG8021QEXIST))
M
Mintz, Yuval 已提交
561
		SET_FIELD(bd_flags, CORE_TX_BD_DATA_VLAN_INSERTION, 1);
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704

	return bd_flags;
}

static int qed_ll2_lb_rxq_handler(struct qed_hwfn *p_hwfn,
				  struct qed_ll2_info *p_ll2_conn)
{
	struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
	u16 packet_length = 0, parse_flags = 0, vlan = 0;
	struct qed_ll2_rx_packet *p_pkt = NULL;
	u32 num_ooo_add_to_peninsula = 0, cid;
	union core_rx_cqe_union *cqe = NULL;
	u16 cq_new_idx = 0, cq_old_idx = 0;
	struct qed_ooo_buffer *p_buffer;
	struct ooo_opaque *iscsi_ooo;
	u8 placement_offset = 0;
	u8 cqe_type;

	cq_new_idx = le16_to_cpu(*p_rx->p_fw_cons);
	cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
	if (cq_new_idx == cq_old_idx)
		return 0;

	while (cq_new_idx != cq_old_idx) {
		struct core_rx_fast_path_cqe *p_cqe_fp;

		cqe = qed_chain_consume(&p_rx->rcq_chain);
		cq_old_idx = qed_chain_get_cons_idx(&p_rx->rcq_chain);
		cqe_type = cqe->rx_cqe_sp.type;

		if (cqe_type != CORE_RX_CQE_TYPE_REGULAR) {
			DP_NOTICE(p_hwfn,
				  "Got a non-regular LB LL2 completion [type 0x%02x]\n",
				  cqe_type);
			return -EINVAL;
		}
		p_cqe_fp = &cqe->rx_cqe_fp;

		placement_offset = p_cqe_fp->placement_offset;
		parse_flags = le16_to_cpu(p_cqe_fp->parse_flags.flags);
		packet_length = le16_to_cpu(p_cqe_fp->packet_length);
		vlan = le16_to_cpu(p_cqe_fp->vlan);
		iscsi_ooo = (struct ooo_opaque *)&p_cqe_fp->opaque_data;
		qed_ooo_save_history_entry(p_hwfn, p_hwfn->p_ooo_info,
					   iscsi_ooo);
		cid = le32_to_cpu(iscsi_ooo->cid);

		/* Process delete isle first */
		if (iscsi_ooo->drop_size)
			qed_ooo_delete_isles(p_hwfn, p_hwfn->p_ooo_info, cid,
					     iscsi_ooo->drop_isle,
					     iscsi_ooo->drop_size);

		if (iscsi_ooo->ooo_opcode == TCP_EVENT_NOP)
			continue;

		/* Now process create/add/join isles */
		if (list_empty(&p_rx->active_descq)) {
			DP_NOTICE(p_hwfn,
				  "LL2 OOO RX chain has no submitted buffers\n"
				  );
			return -EIO;
		}

		p_pkt = list_first_entry(&p_rx->active_descq,
					 struct qed_ll2_rx_packet, list_entry);

		if ((iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_NEW_ISLE) ||
		    (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_RIGHT) ||
		    (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_ISLE_LEFT) ||
		    (iscsi_ooo->ooo_opcode == TCP_EVENT_ADD_PEN) ||
		    (iscsi_ooo->ooo_opcode == TCP_EVENT_JOIN)) {
			if (!p_pkt) {
				DP_NOTICE(p_hwfn,
					  "LL2 OOO RX packet is not valid\n");
				return -EIO;
			}
			list_del(&p_pkt->list_entry);
			p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
			p_buffer->packet_length = packet_length;
			p_buffer->parse_flags = parse_flags;
			p_buffer->vlan = vlan;
			p_buffer->placement_offset = placement_offset;
			qed_chain_consume(&p_rx->rxq_chain);
			list_add_tail(&p_pkt->list_entry, &p_rx->free_descq);

			switch (iscsi_ooo->ooo_opcode) {
			case TCP_EVENT_ADD_NEW_ISLE:
				qed_ooo_add_new_isle(p_hwfn,
						     p_hwfn->p_ooo_info,
						     cid,
						     iscsi_ooo->ooo_isle,
						     p_buffer);
				break;
			case TCP_EVENT_ADD_ISLE_RIGHT:
				qed_ooo_add_new_buffer(p_hwfn,
						       p_hwfn->p_ooo_info,
						       cid,
						       iscsi_ooo->ooo_isle,
						       p_buffer,
						       QED_OOO_RIGHT_BUF);
				break;
			case TCP_EVENT_ADD_ISLE_LEFT:
				qed_ooo_add_new_buffer(p_hwfn,
						       p_hwfn->p_ooo_info,
						       cid,
						       iscsi_ooo->ooo_isle,
						       p_buffer,
						       QED_OOO_LEFT_BUF);
				break;
			case TCP_EVENT_JOIN:
				qed_ooo_add_new_buffer(p_hwfn,
						       p_hwfn->p_ooo_info,
						       cid,
						       iscsi_ooo->ooo_isle +
						       1,
						       p_buffer,
						       QED_OOO_LEFT_BUF);
				qed_ooo_join_isles(p_hwfn,
						   p_hwfn->p_ooo_info,
						   cid, iscsi_ooo->ooo_isle);
				break;
			case TCP_EVENT_ADD_PEN:
				num_ooo_add_to_peninsula++;
				qed_ooo_put_ready_buffer(p_hwfn,
							 p_hwfn->p_ooo_info,
							 p_buffer, true);
				break;
			}
		} else {
			DP_NOTICE(p_hwfn,
				  "Unexpected event (%d) TX OOO completion\n",
				  iscsi_ooo->ooo_opcode);
		}
	}

	return 0;
}

static void
qed_ooo_submit_tx_buffers(struct qed_hwfn *p_hwfn,
			  struct qed_ll2_info *p_ll2_conn)
{
705
	struct qed_ll2_tx_pkt_info tx_pkt;
706 707 708 709 710
	struct qed_ooo_buffer *p_buffer;
	u16 l4_hdr_offset_w;
	dma_addr_t first_frag;
	u16 parse_flags;
	u8 bd_flags;
711
	int rc;
712 713 714 715 716 717 718 719 720 721 722

	/* Submit Tx buffers here */
	while ((p_buffer = qed_ooo_get_ready_buffer(p_hwfn,
						    p_hwfn->p_ooo_info))) {
		l4_hdr_offset_w = 0;
		bd_flags = 0;

		first_frag = p_buffer->rx_buffer_phys_addr +
			     p_buffer->placement_offset;
		parse_flags = p_buffer->parse_flags;
		bd_flags = qed_ll2_convert_rx_parse_to_tx_flags(parse_flags);
M
Mintz, Yuval 已提交
723 724
		SET_FIELD(bd_flags, CORE_TX_BD_DATA_FORCE_VLAN_MODE, 1);
		SET_FIELD(bd_flags, CORE_TX_BD_DATA_L4_PROTOCOL, 1);
725

726 727 728 729 730
		memset(&tx_pkt, 0, sizeof(tx_pkt));
		tx_pkt.num_of_bds = 1;
		tx_pkt.vlan = p_buffer->vlan;
		tx_pkt.bd_flags = bd_flags;
		tx_pkt.l4_hdr_offset_w = l4_hdr_offset_w;
731
		tx_pkt.tx_dest = p_ll2_conn->tx_dest;
732 733 734 735 736 737
		tx_pkt.first_frag = first_frag;
		tx_pkt.first_frag_len = p_buffer->packet_length;
		tx_pkt.cookie = p_buffer;

		rc = qed_ll2_prepare_tx_packet(p_hwfn, p_ll2_conn->my_id,
					       &tx_pkt, true);
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
		if (rc) {
			qed_ooo_put_ready_buffer(p_hwfn, p_hwfn->p_ooo_info,
						 p_buffer, false);
			break;
		}
	}
}

static void
qed_ooo_submit_rx_buffers(struct qed_hwfn *p_hwfn,
			  struct qed_ll2_info *p_ll2_conn)
{
	struct qed_ooo_buffer *p_buffer;
	int rc;

	while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn,
						   p_hwfn->p_ooo_info))) {
		rc = qed_ll2_post_rx_buffer(p_hwfn,
					    p_ll2_conn->my_id,
					    p_buffer->rx_buffer_phys_addr,
					    0, p_buffer, true);
		if (rc) {
			qed_ooo_put_free_buffer(p_hwfn,
						p_hwfn->p_ooo_info, p_buffer);
			break;
		}
	}
}

static int qed_ll2_lb_rxq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
{
	struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
	int rc;

	rc = qed_ll2_lb_rxq_handler(p_hwfn, p_ll2_conn);
	if (rc)
		return rc;

	qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn);
	qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn);

	return 0;
}

static int qed_ll2_lb_txq_completion(struct qed_hwfn *p_hwfn, void *p_cookie)
{
	struct qed_ll2_info *p_ll2_conn = (struct qed_ll2_info *)p_cookie;
	struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
	struct qed_ll2_tx_packet *p_pkt = NULL;
	struct qed_ooo_buffer *p_buffer;
	bool b_dont_submit_rx = false;
	u16 new_idx = 0, num_bds = 0;
	int rc;

	new_idx = le16_to_cpu(*p_tx->p_fw_cons);
	num_bds = ((s16)new_idx - (s16)p_tx->bds_idx);

	if (!num_bds)
		return 0;

	while (num_bds) {
		if (list_empty(&p_tx->active_descq))
			return -EINVAL;

		p_pkt = list_first_entry(&p_tx->active_descq,
					 struct qed_ll2_tx_packet, list_entry);
		if (!p_pkt)
			return -EINVAL;

		if (p_pkt->bd_used != 1) {
			DP_NOTICE(p_hwfn,
				  "Unexpectedly many BDs(%d) in TX OOO completion\n",
				  p_pkt->bd_used);
			return -EINVAL;
		}

		list_del(&p_pkt->list_entry);

		num_bds--;
		p_tx->bds_idx++;
		qed_chain_consume(&p_tx->txq_chain);

		p_buffer = (struct qed_ooo_buffer *)p_pkt->cookie;
		list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);

		if (b_dont_submit_rx) {
			qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info,
						p_buffer);
			continue;
		}

		rc = qed_ll2_post_rx_buffer(p_hwfn, p_ll2_conn->my_id,
					    p_buffer->rx_buffer_phys_addr, 0,
					    p_buffer, true);
		if (rc != 0) {
			qed_ooo_put_free_buffer(p_hwfn,
						p_hwfn->p_ooo_info, p_buffer);
			b_dont_submit_rx = true;
		}
	}

	qed_ooo_submit_tx_buffers(p_hwfn, p_ll2_conn);

	return 0;
}

static void qed_ll2_stop_ooo(struct qed_dev *cdev)
{
	struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
	u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;

	DP_VERBOSE(cdev, QED_MSG_STORAGE, "Stopping LL2 OOO queue [%02x]\n",
		   *handle);

	qed_ll2_terminate_connection(hwfn, *handle);
	qed_ll2_release_connection(hwfn, *handle);
	*handle = QED_LL2_UNUSED_HANDLE;
}

Y
Yuval Mintz 已提交
857 858 859 860
static int qed_sp_ll2_rx_queue_start(struct qed_hwfn *p_hwfn,
				     struct qed_ll2_info *p_ll2_conn,
				     u8 action_on_error)
{
861
	enum qed_ll2_conn_type conn_type = p_ll2_conn->input.conn_type;
Y
Yuval Mintz 已提交
862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
	struct qed_ll2_rx_queue *p_rx = &p_ll2_conn->rx_queue;
	struct core_rx_start_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
	struct qed_sp_init_data init_data;
	u16 cqe_pbl_size;
	int rc = 0;

	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = p_ll2_conn->cid;
	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 CORE_RAMROD_RX_QUEUE_START,
				 PROTOCOLID_CORE, &init_data);
	if (rc)
		return rc;

	p_ramrod = &p_ent->ramrod.core_rx_queue_start;

	p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn));
	p_ramrod->sb_index = p_rx->rx_sb_index;
	p_ramrod->complete_event_flg = 1;

887 888
	p_ramrod->mtu = cpu_to_le16(p_ll2_conn->input.mtu);
	DMA_REGPAIR_LE(p_ramrod->bd_base, p_rx->rxq_chain.p_phys_addr);
Y
Yuval Mintz 已提交
889 890 891 892 893
	cqe_pbl_size = (u16)qed_chain_get_page_cnt(&p_rx->rcq_chain);
	p_ramrod->num_of_pbl_pages = cpu_to_le16(cqe_pbl_size);
	DMA_REGPAIR_LE(p_ramrod->cqe_pbl_addr,
		       qed_chain_get_pbl_phys(&p_rx->rcq_chain));

894 895
	p_ramrod->drop_ttl0_flg = p_ll2_conn->input.rx_drop_ttl0_flg;
	p_ramrod->inner_vlan_removal_en = p_ll2_conn->input.rx_vlan_removal_en;
Y
Yuval Mintz 已提交
896
	p_ramrod->queue_id = p_ll2_conn->queue_id;
897
	p_ramrod->main_func_queue = p_ll2_conn->main_func_queue ? 1 : 0;
Y
Yuval Mintz 已提交
898 899

	if ((IS_MF_DEFAULT(p_hwfn) || IS_MF_SI(p_hwfn)) &&
900 901
	    p_ramrod->main_func_queue && (conn_type != QED_LL2_TYPE_ROCE) &&
	    (conn_type != QED_LL2_TYPE_IWARP)) {
Y
Yuval Mintz 已提交
902 903 904 905 906 907 908 909
		p_ramrod->mf_si_bcast_accept_all = 1;
		p_ramrod->mf_si_mcast_accept_all = 1;
	} else {
		p_ramrod->mf_si_bcast_accept_all = 0;
		p_ramrod->mf_si_mcast_accept_all = 0;
	}

	p_ramrod->action_on_error.error_type = action_on_error;
910
	p_ramrod->gsi_offload_flag = p_ll2_conn->input.gsi_enable;
Y
Yuval Mintz 已提交
911 912 913 914 915 916
	return qed_spq_post(p_hwfn, p_ent, NULL);
}

static int qed_sp_ll2_tx_queue_start(struct qed_hwfn *p_hwfn,
				     struct qed_ll2_info *p_ll2_conn)
{
917
	enum qed_ll2_conn_type conn_type = p_ll2_conn->input.conn_type;
Y
Yuval Mintz 已提交
918 919 920 921 922 923 924 925 926 927
	struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
	struct core_tx_start_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
	struct qed_sp_init_data init_data;
	u16 pq_id = 0, pbl_size;
	int rc = -EINVAL;

	if (!QED_LL2_TX_REGISTERED(p_ll2_conn))
		return 0;

928
	if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO)
929 930 931 932
		p_ll2_conn->tx_stats_en = 0;
	else
		p_ll2_conn->tx_stats_en = 1;

Y
Yuval Mintz 已提交
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = p_ll2_conn->cid;
	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 CORE_RAMROD_TX_QUEUE_START,
				 PROTOCOLID_CORE, &init_data);
	if (rc)
		return rc;

	p_ramrod = &p_ent->ramrod.core_tx_queue_start;

	p_ramrod->sb_id = cpu_to_le16(qed_int_get_sp_sb_id(p_hwfn));
	p_ramrod->sb_index = p_tx->tx_sb_index;
949
	p_ramrod->mtu = cpu_to_le16(p_ll2_conn->input.mtu);
Y
Yuval Mintz 已提交
950 951 952 953 954 955 956 957
	p_ramrod->stats_en = p_ll2_conn->tx_stats_en;
	p_ramrod->stats_id = p_ll2_conn->tx_stats_id;

	DMA_REGPAIR_LE(p_ramrod->pbl_base_addr,
		       qed_chain_get_pbl_phys(&p_tx->txq_chain));
	pbl_size = qed_chain_get_page_cnt(&p_tx->txq_chain);
	p_ramrod->pbl_size = cpu_to_le16(pbl_size);

958
	switch (p_ll2_conn->input.tx_tc) {
959
	case PURE_LB_TC:
A
Ariel Elior 已提交
960 961
		pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB);
		break;
962
	case PKT_LB_TC:
A
Ariel Elior 已提交
963
		pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OOO);
964
		break;
A
Ariel Elior 已提交
965 966 967 968 969
	default:
		pq_id = qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_OFLD);
		break;
	}

Y
Yuval Mintz 已提交
970 971 972
	p_ramrod->qm_pq_id = cpu_to_le16(pq_id);

	switch (conn_type) {
973 974 975
	case QED_LL2_TYPE_FCOE:
		p_ramrod->conn_type = PROTOCOLID_FCOE;
		break;
Y
Yuval Mintz 已提交
976 977 978 979 980 981
	case QED_LL2_TYPE_ISCSI:
		p_ramrod->conn_type = PROTOCOLID_ISCSI;
		break;
	case QED_LL2_TYPE_ROCE:
		p_ramrod->conn_type = PROTOCOLID_ROCE;
		break;
982 983 984 985 986 987 988 989 990
	case QED_LL2_TYPE_IWARP:
		p_ramrod->conn_type = PROTOCOLID_IWARP;
		break;
	case QED_LL2_TYPE_OOO:
		if (p_hwfn->hw_info.personality == QED_PCI_ISCSI)
			p_ramrod->conn_type = PROTOCOLID_ISCSI;
		else
			p_ramrod->conn_type = PROTOCOLID_IWARP;
		break;
Y
Yuval Mintz 已提交
991 992 993 994 995
	default:
		p_ramrod->conn_type = PROTOCOLID_ETH;
		DP_NOTICE(p_hwfn, "Unknown connection type: %d\n", conn_type);
	}

996 997
	p_ramrod->gsi_offload_flag = p_ll2_conn->input.gsi_enable;

Y
Yuval Mintz 已提交
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
	return qed_spq_post(p_hwfn, p_ent, NULL);
}

static int qed_sp_ll2_rx_queue_stop(struct qed_hwfn *p_hwfn,
				    struct qed_ll2_info *p_ll2_conn)
{
	struct core_rx_stop_ramrod_data *p_ramrod = NULL;
	struct qed_spq_entry *p_ent = NULL;
	struct qed_sp_init_data init_data;
	int rc = -EINVAL;

	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = p_ll2_conn->cid;
	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 CORE_RAMROD_RX_QUEUE_STOP,
				 PROTOCOLID_CORE, &init_data);
	if (rc)
		return rc;

	p_ramrod = &p_ent->ramrod.core_rx_queue_stop;

	p_ramrod->complete_event_flg = 1;
	p_ramrod->queue_id = p_ll2_conn->queue_id;

	return qed_spq_post(p_hwfn, p_ent, NULL);
}

static int qed_sp_ll2_tx_queue_stop(struct qed_hwfn *p_hwfn,
				    struct qed_ll2_info *p_ll2_conn)
{
	struct qed_spq_entry *p_ent = NULL;
	struct qed_sp_init_data init_data;
	int rc = -EINVAL;

	/* Get SPQ entry */
	memset(&init_data, 0, sizeof(init_data));
	init_data.cid = p_ll2_conn->cid;
	init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
	init_data.comp_mode = QED_SPQ_MODE_EBLOCK;

	rc = qed_sp_init_request(p_hwfn, &p_ent,
				 CORE_RAMROD_TX_QUEUE_STOP,
				 PROTOCOLID_CORE, &init_data);
	if (rc)
		return rc;

	return qed_spq_post(p_hwfn, p_ent, NULL);
}

static int
qed_ll2_acquire_connection_rx(struct qed_hwfn *p_hwfn,
1053
			      struct qed_ll2_info *p_ll2_info)
Y
Yuval Mintz 已提交
1054 1055 1056 1057 1058
{
	struct qed_ll2_rx_packet *p_descq;
	u32 capacity;
	int rc = 0;

1059
	if (!p_ll2_info->input.rx_num_desc)
Y
Yuval Mintz 已提交
1060 1061 1062 1063 1064 1065
		goto out;

	rc = qed_chain_alloc(p_hwfn->cdev,
			     QED_CHAIN_USE_TO_CONSUME_PRODUCE,
			     QED_CHAIN_MODE_NEXT_PTR,
			     QED_CHAIN_CNT_TYPE_U16,
1066
			     p_ll2_info->input.rx_num_desc,
Y
Yuval Mintz 已提交
1067
			     sizeof(struct core_rx_bd),
1068
			     &p_ll2_info->rx_queue.rxq_chain, NULL);
Y
Yuval Mintz 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
	if (rc) {
		DP_NOTICE(p_hwfn, "Failed to allocate ll2 rxq chain\n");
		goto out;
	}

	capacity = qed_chain_get_capacity(&p_ll2_info->rx_queue.rxq_chain);
	p_descq = kcalloc(capacity, sizeof(struct qed_ll2_rx_packet),
			  GFP_KERNEL);
	if (!p_descq) {
		rc = -ENOMEM;
		DP_NOTICE(p_hwfn, "Failed to allocate ll2 Rx desc\n");
		goto out;
	}
	p_ll2_info->rx_queue.descq_array = p_descq;

	rc = qed_chain_alloc(p_hwfn->cdev,
			     QED_CHAIN_USE_TO_CONSUME_PRODUCE,
			     QED_CHAIN_MODE_PBL,
			     QED_CHAIN_CNT_TYPE_U16,
1088
			     p_ll2_info->input.rx_num_desc,
Y
Yuval Mintz 已提交
1089
			     sizeof(struct core_rx_fast_path_cqe),
1090
			     &p_ll2_info->rx_queue.rcq_chain, NULL);
Y
Yuval Mintz 已提交
1091 1092 1093 1094 1095 1096 1097
	if (rc) {
		DP_NOTICE(p_hwfn, "Failed to allocate ll2 rcq chain\n");
		goto out;
	}

	DP_VERBOSE(p_hwfn, QED_MSG_LL2,
		   "Allocated LL2 Rxq [Type %08x] with 0x%08x buffers\n",
1098
		   p_ll2_info->input.conn_type, p_ll2_info->input.rx_num_desc);
Y
Yuval Mintz 已提交
1099 1100 1101 1102 1103 1104

out:
	return rc;
}

static int qed_ll2_acquire_connection_tx(struct qed_hwfn *p_hwfn,
1105
					 struct qed_ll2_info *p_ll2_info)
Y
Yuval Mintz 已提交
1106 1107
{
	struct qed_ll2_tx_packet *p_descq;
1108
	u32 desc_size;
Y
Yuval Mintz 已提交
1109 1110 1111
	u32 capacity;
	int rc = 0;

1112
	if (!p_ll2_info->input.tx_num_desc)
Y
Yuval Mintz 已提交
1113 1114 1115 1116 1117 1118
		goto out;

	rc = qed_chain_alloc(p_hwfn->cdev,
			     QED_CHAIN_USE_TO_CONSUME_PRODUCE,
			     QED_CHAIN_MODE_PBL,
			     QED_CHAIN_CNT_TYPE_U16,
1119
			     p_ll2_info->input.tx_num_desc,
Y
Yuval Mintz 已提交
1120
			     sizeof(struct core_tx_bd),
1121
			     &p_ll2_info->tx_queue.txq_chain, NULL);
Y
Yuval Mintz 已提交
1122 1123 1124 1125
	if (rc)
		goto out;

	capacity = qed_chain_get_capacity(&p_ll2_info->tx_queue.txq_chain);
1126 1127 1128 1129 1130 1131
	/* First element is part of the packet, rest are flexibly added */
	desc_size = (sizeof(*p_descq) +
		     (p_ll2_info->input.tx_max_bds_per_packet - 1) *
		     sizeof(p_descq->bds_set));

	p_descq = kcalloc(capacity, desc_size, GFP_KERNEL);
Y
Yuval Mintz 已提交
1132 1133 1134 1135
	if (!p_descq) {
		rc = -ENOMEM;
		goto out;
	}
1136
	p_ll2_info->tx_queue.descq_mem = p_descq;
Y
Yuval Mintz 已提交
1137 1138 1139

	DP_VERBOSE(p_hwfn, QED_MSG_LL2,
		   "Allocated LL2 Txq [Type %08x] with 0x%08x buffers\n",
1140
		   p_ll2_info->input.conn_type, p_ll2_info->input.tx_num_desc);
Y
Yuval Mintz 已提交
1141 1142 1143 1144 1145

out:
	if (rc)
		DP_NOTICE(p_hwfn,
			  "Can't allocate memory for Tx LL2 with 0x%08x buffers\n",
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158
			  p_ll2_info->input.tx_num_desc);
	return rc;
}

static int
qed_ll2_acquire_connection_ooo(struct qed_hwfn *p_hwfn,
			       struct qed_ll2_info *p_ll2_info, u16 mtu)
{
	struct qed_ooo_buffer *p_buf = NULL;
	void *p_virt;
	u16 buf_idx;
	int rc = 0;

1159
	if (p_ll2_info->input.conn_type != QED_LL2_TYPE_OOO)
1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
		return rc;

	/* Correct number of requested OOO buffers if needed */
	if (!p_ll2_info->input.rx_num_ooo_buffers) {
		u16 num_desc = p_ll2_info->input.rx_num_desc;

		if (!num_desc)
			return -EINVAL;
		p_ll2_info->input.rx_num_ooo_buffers = num_desc * 2;
	}

	for (buf_idx = 0; buf_idx < p_ll2_info->input.rx_num_ooo_buffers;
	     buf_idx++) {
		p_buf = kzalloc(sizeof(*p_buf), GFP_KERNEL);
		if (!p_buf) {
			rc = -ENOMEM;
			goto out;
		}

		p_buf->rx_buffer_size = mtu + 26 + ETH_CACHE_LINE_SIZE;
		p_buf->rx_buffer_size = (p_buf->rx_buffer_size +
					 ETH_CACHE_LINE_SIZE - 1) &
					~(ETH_CACHE_LINE_SIZE - 1);
		p_virt = dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
					    p_buf->rx_buffer_size,
					    &p_buf->rx_buffer_phys_addr,
					    GFP_KERNEL);
		if (!p_virt) {
			kfree(p_buf);
			rc = -ENOMEM;
			goto out;
		}

		p_buf->rx_buffer_virt_addr = p_virt;
		qed_ooo_put_free_buffer(p_hwfn, p_hwfn->p_ooo_info, p_buf);
	}

	DP_VERBOSE(p_hwfn, QED_MSG_LL2,
		   "Allocated [%04x] LL2 OOO buffers [each of size 0x%08x]\n",
		   p_ll2_info->input.rx_num_ooo_buffers, p_buf->rx_buffer_size);

out:
Y
Yuval Mintz 已提交
1202 1203 1204
	return rc;
}

M
Michal Kalderon 已提交
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
static int
qed_ll2_set_cbs(struct qed_ll2_info *p_ll2_info, const struct qed_ll2_cbs *cbs)
{
	if (!cbs || (!cbs->rx_comp_cb ||
		     !cbs->rx_release_cb ||
		     !cbs->tx_comp_cb || !cbs->tx_release_cb || !cbs->cookie))
		return -EINVAL;

	p_ll2_info->cbs.rx_comp_cb = cbs->rx_comp_cb;
	p_ll2_info->cbs.rx_release_cb = cbs->rx_release_cb;
	p_ll2_info->cbs.tx_comp_cb = cbs->tx_comp_cb;
	p_ll2_info->cbs.tx_release_cb = cbs->tx_release_cb;
	p_ll2_info->cbs.cookie = cbs->cookie;

	return 0;
}

1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
static enum core_error_handle
qed_ll2_get_error_choice(enum qed_ll2_error_handle err)
{
	switch (err) {
	case QED_LL2_DROP_PACKET:
		return LL2_DROP_PACKET;
	case QED_LL2_DO_NOTHING:
		return LL2_DO_NOTHING;
	case QED_LL2_ASSERT:
		return LL2_ASSERT;
	default:
		return LL2_DO_NOTHING;
	}
}

M
Michal Kalderon 已提交
1237
int qed_ll2_acquire_connection(void *cxt, struct qed_ll2_acquire_data *data)
Y
Yuval Mintz 已提交
1238
{
M
Michal Kalderon 已提交
1239
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1240 1241
	qed_int_comp_cb_t comp_rx_cb, comp_tx_cb;
	struct qed_ll2_info *p_ll2_info = NULL;
1242
	u8 i, *p_tx_max;
Y
Yuval Mintz 已提交
1243 1244
	int rc;

1245
	if (!data->p_connection_handle || !p_hwfn->p_ll2_info)
Y
Yuval Mintz 已提交
1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
		return -EINVAL;

	/* Find a free connection to be used */
	for (i = 0; (i < QED_MAX_NUM_OF_LL2_CONNECTIONS); i++) {
		mutex_lock(&p_hwfn->p_ll2_info[i].mutex);
		if (p_hwfn->p_ll2_info[i].b_active) {
			mutex_unlock(&p_hwfn->p_ll2_info[i].mutex);
			continue;
		}

		p_hwfn->p_ll2_info[i].b_active = true;
		p_ll2_info = &p_hwfn->p_ll2_info[i];
		mutex_unlock(&p_hwfn->p_ll2_info[i].mutex);
		break;
	}
	if (!p_ll2_info)
		return -EBUSY;

1264
	memcpy(&p_ll2_info->input, &data->input, sizeof(p_ll2_info->input));
Y
Yuval Mintz 已提交
1265

1266 1267
	p_ll2_info->tx_dest = (data->input.tx_dest == QED_LL2_TX_DEST_NW) ?
			      CORE_TX_DEST_NW : CORE_TX_DEST_LB;
1268 1269 1270 1271 1272
	if (data->input.conn_type == QED_LL2_TYPE_OOO ||
	    data->input.secondary_queue)
		p_ll2_info->main_func_queue = false;
	else
		p_ll2_info->main_func_queue = true;
1273 1274 1275 1276 1277 1278 1279 1280

	/* Correct maximum number of Tx BDs */
	p_tx_max = &p_ll2_info->input.tx_max_bds_per_packet;
	if (*p_tx_max == 0)
		*p_tx_max = CORE_LL2_TX_MAX_BDS_PER_PACKET;
	else
		*p_tx_max = min_t(u8, *p_tx_max,
				  CORE_LL2_TX_MAX_BDS_PER_PACKET);
M
Michal Kalderon 已提交
1281 1282 1283 1284 1285 1286 1287

	rc = qed_ll2_set_cbs(p_ll2_info, data->cbs);
	if (rc) {
		DP_NOTICE(p_hwfn, "Invalid callback functions\n");
		goto q_allocate_fail;
	}

1288
	rc = qed_ll2_acquire_connection_rx(p_hwfn, p_ll2_info);
Y
Yuval Mintz 已提交
1289 1290 1291
	if (rc)
		goto q_allocate_fail;

1292
	rc = qed_ll2_acquire_connection_tx(p_hwfn, p_ll2_info);
Y
Yuval Mintz 已提交
1293 1294 1295
	if (rc)
		goto q_allocate_fail;

1296
	rc = qed_ll2_acquire_connection_ooo(p_hwfn, p_ll2_info,
1297
					    data->input.mtu);
1298 1299 1300
	if (rc)
		goto q_allocate_fail;

Y
Yuval Mintz 已提交
1301
	/* Register callbacks for the Rx/Tx queues */
1302
	if (data->input.conn_type == QED_LL2_TYPE_OOO) {
1303 1304 1305 1306 1307 1308
		comp_rx_cb = qed_ll2_lb_rxq_completion;
		comp_tx_cb = qed_ll2_lb_txq_completion;
	} else {
		comp_rx_cb = qed_ll2_rxq_completion;
		comp_tx_cb = qed_ll2_txq_completion;
	}
Y
Yuval Mintz 已提交
1309

1310
	if (data->input.rx_num_desc) {
Y
Yuval Mintz 已提交
1311 1312 1313 1314 1315 1316 1317
		qed_int_register_cb(p_hwfn, comp_rx_cb,
				    &p_hwfn->p_ll2_info[i],
				    &p_ll2_info->rx_queue.rx_sb_index,
				    &p_ll2_info->rx_queue.p_fw_cons);
		p_ll2_info->rx_queue.b_cb_registred = true;
	}

1318
	if (data->input.tx_num_desc) {
Y
Yuval Mintz 已提交
1319 1320 1321 1322 1323 1324 1325 1326
		qed_int_register_cb(p_hwfn,
				    comp_tx_cb,
				    &p_hwfn->p_ll2_info[i],
				    &p_ll2_info->tx_queue.tx_sb_index,
				    &p_ll2_info->tx_queue.p_fw_cons);
		p_ll2_info->tx_queue.b_cb_registred = true;
	}

1327
	*data->p_connection_handle = i;
Y
Yuval Mintz 已提交
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
	return rc;

q_allocate_fail:
	qed_ll2_release_connection(p_hwfn, i);
	return -ENOMEM;
}

static int qed_ll2_establish_connection_rx(struct qed_hwfn *p_hwfn,
					   struct qed_ll2_info *p_ll2_conn)
{
1338 1339
	enum qed_ll2_error_handle error_input;
	enum core_error_handle error_mode;
Y
Yuval Mintz 已提交
1340 1341 1342 1343 1344 1345
	u8 action_on_error = 0;

	if (!QED_LL2_RX_REGISTERED(p_ll2_conn))
		return 0;

	DIRECT_REG_WR(p_ll2_conn->rx_queue.set_prod_addr, 0x0);
1346 1347
	error_input = p_ll2_conn->input.ai_err_packet_too_big;
	error_mode = qed_ll2_get_error_choice(error_input);
Y
Yuval Mintz 已提交
1348
	SET_FIELD(action_on_error,
1349 1350 1351 1352
		  CORE_RX_ACTION_ON_ERROR_PACKET_TOO_BIG, error_mode);
	error_input = p_ll2_conn->input.ai_err_no_buf;
	error_mode = qed_ll2_get_error_choice(error_input);
	SET_FIELD(action_on_error, CORE_RX_ACTION_ON_ERROR_NO_BUFF, error_mode);
Y
Yuval Mintz 已提交
1353 1354 1355 1356

	return qed_sp_ll2_rx_queue_start(p_hwfn, p_ll2_conn, action_on_error);
}

M
Mintz, Yuval 已提交
1357 1358 1359 1360
static void
qed_ll2_establish_connection_ooo(struct qed_hwfn *p_hwfn,
				 struct qed_ll2_info *p_ll2_conn)
{
1361
	if (p_ll2_conn->input.conn_type != QED_LL2_TYPE_OOO)
M
Mintz, Yuval 已提交
1362 1363 1364 1365 1366
		return;

	qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
	qed_ooo_submit_rx_buffers(p_hwfn, p_ll2_conn);
}
M
Michal Kalderon 已提交
1367 1368

int qed_ll2_establish_connection(void *cxt, u8 connection_handle)
Y
Yuval Mintz 已提交
1369
{
M
Michal Kalderon 已提交
1370
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1371
	struct qed_ll2_info *p_ll2_conn;
1372
	struct qed_ll2_tx_packet *p_pkt;
Y
Yuval Mintz 已提交
1373 1374
	struct qed_ll2_rx_queue *p_rx;
	struct qed_ll2_tx_queue *p_tx;
1375
	struct qed_ptt *p_ptt;
Y
Yuval Mintz 已提交
1376 1377
	int rc = -EINVAL;
	u32 i, capacity;
1378
	u32 desc_size;
Y
Yuval Mintz 已提交
1379 1380
	u8 qid;

1381 1382 1383 1384
	p_ptt = qed_ptt_acquire(p_hwfn);
	if (!p_ptt)
		return -EAGAIN;

Y
Yuval Mintz 已提交
1385
	p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle);
1386 1387 1388 1389 1390
	if (!p_ll2_conn) {
		rc = -EINVAL;
		goto out;
	}

Y
Yuval Mintz 已提交
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
	p_rx = &p_ll2_conn->rx_queue;
	p_tx = &p_ll2_conn->tx_queue;

	qed_chain_reset(&p_rx->rxq_chain);
	qed_chain_reset(&p_rx->rcq_chain);
	INIT_LIST_HEAD(&p_rx->active_descq);
	INIT_LIST_HEAD(&p_rx->free_descq);
	INIT_LIST_HEAD(&p_rx->posting_descq);
	spin_lock_init(&p_rx->lock);
	capacity = qed_chain_get_capacity(&p_rx->rxq_chain);
	for (i = 0; i < capacity; i++)
		list_add_tail(&p_rx->descq_array[i].list_entry,
			      &p_rx->free_descq);
	*p_rx->p_fw_cons = 0;

	qed_chain_reset(&p_tx->txq_chain);
	INIT_LIST_HEAD(&p_tx->active_descq);
	INIT_LIST_HEAD(&p_tx->free_descq);
	INIT_LIST_HEAD(&p_tx->sending_descq);
	spin_lock_init(&p_tx->lock);
	capacity = qed_chain_get_capacity(&p_tx->txq_chain);
1412 1413 1414 1415 1416 1417 1418 1419 1420
	/* First element is part of the packet, rest are flexibly added */
	desc_size = (sizeof(*p_pkt) +
		     (p_ll2_conn->input.tx_max_bds_per_packet - 1) *
		     sizeof(p_pkt->bds_set));

	for (i = 0; i < capacity; i++) {
		p_pkt = p_tx->descq_mem + desc_size * i;
		list_add_tail(&p_pkt->list_entry, &p_tx->free_descq);
	}
Y
Yuval Mintz 已提交
1421 1422 1423 1424 1425 1426 1427 1428
	p_tx->cur_completing_bd_idx = 0;
	p_tx->bds_idx = 0;
	p_tx->b_completing_packet = false;
	p_tx->cur_send_packet = NULL;
	p_tx->cur_send_frag_num = 0;
	p_tx->cur_completing_frag_num = 0;
	*p_tx->p_fw_cons = 0;

1429 1430 1431
	rc = qed_cxt_acquire_cid(p_hwfn, PROTOCOLID_CORE, &p_ll2_conn->cid);
	if (rc)
		goto out;
Y
Yuval Mintz 已提交
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444

	qid = p_hwfn->hw_info.resc_start[QED_LL2_QUEUE] + connection_handle;
	p_ll2_conn->queue_id = qid;
	p_ll2_conn->tx_stats_id = qid;
	p_rx->set_prod_addr = (u8 __iomem *)p_hwfn->regview +
					    GTT_BAR0_MAP_REG_TSDM_RAM +
					    TSTORM_LL2_RX_PRODS_OFFSET(qid);
	p_tx->doorbell_addr = (u8 __iomem *)p_hwfn->doorbells +
					    qed_db_addr(p_ll2_conn->cid,
							DQ_DEMS_LEGACY);

	rc = qed_ll2_establish_connection_rx(p_hwfn, p_ll2_conn);
	if (rc)
1445
		goto out;
Y
Yuval Mintz 已提交
1446 1447 1448

	rc = qed_sp_ll2_tx_queue_start(p_hwfn, p_ll2_conn);
	if (rc)
1449
		goto out;
Y
Yuval Mintz 已提交
1450

1451
	if (!QED_IS_RDMA_PERSONALITY(p_hwfn))
1452
		qed_wr(p_hwfn, p_ptt, PRS_REG_USE_LIGHT_L2, 1);
Y
Yuval Mintz 已提交
1453

1454 1455
	qed_ll2_establish_connection_ooo(p_hwfn, p_ll2_conn);

1456
	if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) {
1457
		qed_llh_add_protocol_filter(p_hwfn, p_ptt,
1458 1459
					    0x8906, 0,
					    QED_LLH_FILTER_ETHERTYPE);
1460
		qed_llh_add_protocol_filter(p_hwfn, p_ptt,
1461 1462 1463 1464
					    0x8914, 0,
					    QED_LLH_FILTER_ETHERTYPE);
	}

1465 1466
out:
	qed_ptt_release(p_hwfn, p_ptt);
Y
Yuval Mintz 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
	return rc;
}

static void qed_ll2_post_rx_buffer_notify_fw(struct qed_hwfn *p_hwfn,
					     struct qed_ll2_rx_queue *p_rx,
					     struct qed_ll2_rx_packet *p_curp)
{
	struct qed_ll2_rx_packet *p_posting_packet = NULL;
	struct core_ll2_rx_prod rx_prod = { 0, 0, 0 };
	bool b_notify_fw = false;
	u16 bd_prod, cq_prod;

	/* This handles the flushing of already posted buffers */
	while (!list_empty(&p_rx->posting_descq)) {
		p_posting_packet = list_first_entry(&p_rx->posting_descq,
						    struct qed_ll2_rx_packet,
						    list_entry);
1484 1485
		list_move_tail(&p_posting_packet->list_entry,
			       &p_rx->active_descq);
Y
Yuval Mintz 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
		b_notify_fw = true;
	}

	/* This handles the supplied packet [if there is one] */
	if (p_curp) {
		list_add_tail(&p_curp->list_entry, &p_rx->active_descq);
		b_notify_fw = true;
	}

	if (!b_notify_fw)
		return;

	bd_prod = qed_chain_get_prod_idx(&p_rx->rxq_chain);
	cq_prod = qed_chain_get_prod_idx(&p_rx->rcq_chain);
	rx_prod.bd_prod = cpu_to_le16(bd_prod);
	rx_prod.cqe_prod = cpu_to_le16(cq_prod);
	DIRECT_REG_WR(p_rx->set_prod_addr, *((u32 *)&rx_prod));
}

M
Michal Kalderon 已提交
1505
int qed_ll2_post_rx_buffer(void *cxt,
Y
Yuval Mintz 已提交
1506 1507 1508 1509
			   u8 connection_handle,
			   dma_addr_t addr,
			   u16 buf_len, void *cookie, u8 notify_fw)
{
M
Michal Kalderon 已提交
1510
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
	struct core_rx_bd_with_buff_len *p_curb = NULL;
	struct qed_ll2_rx_packet *p_curp = NULL;
	struct qed_ll2_info *p_ll2_conn;
	struct qed_ll2_rx_queue *p_rx;
	unsigned long flags;
	void *p_data;
	int rc = 0;

	p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
	if (!p_ll2_conn)
		return -EINVAL;
	p_rx = &p_ll2_conn->rx_queue;

	spin_lock_irqsave(&p_rx->lock, flags);
	if (!list_empty(&p_rx->free_descq))
		p_curp = list_first_entry(&p_rx->free_descq,
					  struct qed_ll2_rx_packet, list_entry);
	if (p_curp) {
		if (qed_chain_get_elem_left(&p_rx->rxq_chain) &&
		    qed_chain_get_elem_left(&p_rx->rcq_chain)) {
			p_data = qed_chain_produce(&p_rx->rxq_chain);
			p_curb = (struct core_rx_bd_with_buff_len *)p_data;
			qed_chain_produce(&p_rx->rcq_chain);
		}
	}

	/* If we're lacking entires, let's try to flush buffers to FW */
	if (!p_curp || !p_curb) {
		rc = -EBUSY;
		p_curp = NULL;
		goto out_notify;
	}

	/* We have an Rx packet we can fill */
	DMA_REGPAIR_LE(p_curb->addr, addr);
	p_curb->buff_length = cpu_to_le16(buf_len);
	p_curp->rx_buf_addr = addr;
	p_curp->cookie = cookie;
	p_curp->rxq_bd = p_curb;
	p_curp->buf_length = buf_len;
	list_del(&p_curp->list_entry);

	/* Check if we only want to enqueue this packet without informing FW */
	if (!notify_fw) {
		list_add_tail(&p_curp->list_entry, &p_rx->posting_descq);
		goto out;
	}

out_notify:
	qed_ll2_post_rx_buffer_notify_fw(p_hwfn, p_rx, p_curp);
out:
	spin_unlock_irqrestore(&p_rx->lock, flags);
	return rc;
}

static void qed_ll2_prepare_tx_packet_set(struct qed_hwfn *p_hwfn,
					  struct qed_ll2_tx_queue *p_tx,
					  struct qed_ll2_tx_packet *p_curp,
1569
					  struct qed_ll2_tx_pkt_info *pkt,
Y
Yuval Mintz 已提交
1570 1571 1572
					  u8 notify_fw)
{
	list_del(&p_curp->list_entry);
1573 1574
	p_curp->cookie = pkt->cookie;
	p_curp->bd_used = pkt->num_of_bds;
Y
Yuval Mintz 已提交
1575 1576 1577 1578
	p_curp->notify_fw = notify_fw;
	p_tx->cur_send_packet = p_curp;
	p_tx->cur_send_frag_num = 0;

1579 1580
	p_curp->bds_set[p_tx->cur_send_frag_num].tx_frag = pkt->first_frag;
	p_curp->bds_set[p_tx->cur_send_frag_num].frag_len = pkt->first_frag_len;
Y
Yuval Mintz 已提交
1581 1582 1583
	p_tx->cur_send_frag_num++;
}

M
Mintz, Yuval 已提交
1584 1585 1586 1587
static void
qed_ll2_prepare_tx_packet_set_bd(struct qed_hwfn *p_hwfn,
				 struct qed_ll2_info *p_ll2,
				 struct qed_ll2_tx_packet *p_curp,
1588
				 struct qed_ll2_tx_pkt_info *pkt)
Y
Yuval Mintz 已提交
1589 1590 1591 1592
{
	struct qed_chain *p_tx_chain = &p_ll2->tx_queue.txq_chain;
	u16 prod_idx = qed_chain_get_prod_idx(p_tx_chain);
	struct core_tx_bd *start_bd = NULL;
1593 1594
	enum core_roce_flavor_type roce_flavor;
	enum core_tx_dest tx_dest;
M
Mintz, Yuval 已提交
1595
	u16 bd_data = 0, frag_idx;
Y
Yuval Mintz 已提交
1596

1597 1598 1599 1600 1601 1602
	roce_flavor = (pkt->qed_roce_flavor == QED_LL2_ROCE) ? CORE_ROCE
							     : CORE_RROCE;

	tx_dest = (pkt->tx_dest == QED_LL2_TX_DEST_NW) ? CORE_TX_DEST_NW
						       : CORE_TX_DEST_LB;

Y
Yuval Mintz 已提交
1603
	start_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain);
1604
	start_bd->nw_vlan_or_lb_echo = cpu_to_le16(pkt->vlan);
Y
Yuval Mintz 已提交
1605
	SET_FIELD(start_bd->bitfield1, CORE_TX_BD_L4_HDR_OFFSET_W,
1606
		  cpu_to_le16(pkt->l4_hdr_offset_w));
Y
Yuval Mintz 已提交
1607
	SET_FIELD(start_bd->bitfield1, CORE_TX_BD_TX_DST, tx_dest);
1608
	bd_data |= pkt->bd_flags;
M
Mintz, Yuval 已提交
1609
	SET_FIELD(bd_data, CORE_TX_BD_DATA_START_BD, 0x1);
1610
	SET_FIELD(bd_data, CORE_TX_BD_DATA_NBDS, pkt->num_of_bds);
M
Mintz, Yuval 已提交
1611 1612
	SET_FIELD(bd_data, CORE_TX_BD_DATA_ROCE_FLAV, roce_flavor);
	start_bd->bd_data.as_bitfield = cpu_to_le16(bd_data);
1613 1614
	DMA_REGPAIR_LE(start_bd->addr, pkt->first_frag);
	start_bd->nbytes = cpu_to_le16(pkt->first_frag_len);
Y
Yuval Mintz 已提交
1615 1616 1617 1618 1619 1620

	DP_VERBOSE(p_hwfn,
		   (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
		   "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Tx Producer at [0x%04x] - set with a %04x bytes %02x BDs buffer at %08x:%08x\n",
		   p_ll2->queue_id,
		   p_ll2->cid,
1621
		   p_ll2->input.conn_type,
Y
Yuval Mintz 已提交
1622
		   prod_idx,
1623 1624
		   pkt->first_frag_len,
		   pkt->num_of_bds,
Y
Yuval Mintz 已提交
1625 1626 1627
		   le32_to_cpu(start_bd->addr.hi),
		   le32_to_cpu(start_bd->addr.lo));

1628
	if (p_ll2->tx_queue.cur_send_frag_num == pkt->num_of_bds)
Y
Yuval Mintz 已提交
1629 1630 1631 1632
		return;

	/* Need to provide the packet with additional BDs for frags */
	for (frag_idx = p_ll2->tx_queue.cur_send_frag_num;
1633
	     frag_idx < pkt->num_of_bds; frag_idx++) {
Y
Yuval Mintz 已提交
1634 1635 1636
		struct core_tx_bd **p_bd = &p_curp->bds_set[frag_idx].txq_bd;

		*p_bd = (struct core_tx_bd *)qed_chain_produce(p_tx_chain);
M
Mintz, Yuval 已提交
1637
		(*p_bd)->bd_data.as_bitfield = 0;
Y
Yuval Mintz 已提交
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
		(*p_bd)->bitfield1 = 0;
		p_curp->bds_set[frag_idx].tx_frag = 0;
		p_curp->bds_set[frag_idx].frag_len = 0;
	}
}

/* This should be called while the Txq spinlock is being held */
static void qed_ll2_tx_packet_notify(struct qed_hwfn *p_hwfn,
				     struct qed_ll2_info *p_ll2_conn)
{
	bool b_notify = p_ll2_conn->tx_queue.cur_send_packet->notify_fw;
	struct qed_ll2_tx_queue *p_tx = &p_ll2_conn->tx_queue;
	struct qed_ll2_tx_packet *p_pkt = NULL;
	struct core_db_data db_msg = { 0, 0, 0 };
	u16 bd_prod;

	/* If there are missing BDs, don't do anything now */
	if (p_ll2_conn->tx_queue.cur_send_frag_num !=
	    p_ll2_conn->tx_queue.cur_send_packet->bd_used)
		return;

	/* Push the current packet to the list and clean after it */
	list_add_tail(&p_ll2_conn->tx_queue.cur_send_packet->list_entry,
		      &p_ll2_conn->tx_queue.sending_descq);
	p_ll2_conn->tx_queue.cur_send_packet = NULL;
	p_ll2_conn->tx_queue.cur_send_frag_num = 0;

	/* Notify FW of packet only if requested to */
	if (!b_notify)
		return;

	bd_prod = qed_chain_get_prod_idx(&p_ll2_conn->tx_queue.txq_chain);

	while (!list_empty(&p_tx->sending_descq)) {
		p_pkt = list_first_entry(&p_tx->sending_descq,
					 struct qed_ll2_tx_packet, list_entry);
		if (!p_pkt)
			break;

1677
		list_move_tail(&p_pkt->list_entry, &p_tx->active_descq);
Y
Yuval Mintz 已提交
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695
	}

	SET_FIELD(db_msg.params, CORE_DB_DATA_DEST, DB_DEST_XCM);
	SET_FIELD(db_msg.params, CORE_DB_DATA_AGG_CMD, DB_AGG_CMD_SET);
	SET_FIELD(db_msg.params, CORE_DB_DATA_AGG_VAL_SEL,
		  DQ_XCM_CORE_TX_BD_PROD_CMD);
	db_msg.agg_flags = DQ_XCM_CORE_DQ_CF_CMD;
	db_msg.spq_prod = cpu_to_le16(bd_prod);

	/* Make sure the BDs data is updated before ringing the doorbell */
	wmb();

	DIRECT_REG_WR(p_tx->doorbell_addr, *((u32 *)&db_msg));

	DP_VERBOSE(p_hwfn,
		   (NETIF_MSG_TX_QUEUED | QED_MSG_LL2),
		   "LL2 [q 0x%02x cid 0x%08x type 0x%08x] Doorbelled [producer 0x%04x]\n",
		   p_ll2_conn->queue_id,
1696 1697
		   p_ll2_conn->cid,
		   p_ll2_conn->input.conn_type, db_msg.spq_prod);
Y
Yuval Mintz 已提交
1698 1699
}

M
Michal Kalderon 已提交
1700
int qed_ll2_prepare_tx_packet(void *cxt,
Y
Yuval Mintz 已提交
1701
			      u8 connection_handle,
1702 1703
			      struct qed_ll2_tx_pkt_info *pkt,
			      bool notify_fw)
Y
Yuval Mintz 已提交
1704
{
M
Michal Kalderon 已提交
1705
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
	struct qed_ll2_tx_packet *p_curp = NULL;
	struct qed_ll2_info *p_ll2_conn = NULL;
	struct qed_ll2_tx_queue *p_tx;
	struct qed_chain *p_tx_chain;
	unsigned long flags;
	int rc = 0;

	p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
	if (!p_ll2_conn)
		return -EINVAL;
	p_tx = &p_ll2_conn->tx_queue;
	p_tx_chain = &p_tx->txq_chain;

1719
	if (pkt->num_of_bds > p_ll2_conn->input.tx_max_bds_per_packet)
Y
Yuval Mintz 已提交
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731
		return -EIO;

	spin_lock_irqsave(&p_tx->lock, flags);
	if (p_tx->cur_send_packet) {
		rc = -EEXIST;
		goto out;
	}

	/* Get entry, but only if we have tx elements for it */
	if (!list_empty(&p_tx->free_descq))
		p_curp = list_first_entry(&p_tx->free_descq,
					  struct qed_ll2_tx_packet, list_entry);
1732
	if (p_curp && qed_chain_get_elem_left(p_tx_chain) < pkt->num_of_bds)
Y
Yuval Mintz 已提交
1733 1734 1735 1736 1737 1738 1739 1740
		p_curp = NULL;

	if (!p_curp) {
		rc = -EBUSY;
		goto out;
	}

	/* Prepare packet and BD, and perhaps send a doorbell to FW */
1741 1742 1743
	qed_ll2_prepare_tx_packet_set(p_hwfn, p_tx, p_curp, pkt, notify_fw);

	qed_ll2_prepare_tx_packet_set_bd(p_hwfn, p_ll2_conn, p_curp, pkt);
Y
Yuval Mintz 已提交
1744 1745 1746 1747 1748 1749 1750 1751

	qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn);

out:
	spin_unlock_irqrestore(&p_tx->lock, flags);
	return rc;
}

M
Michal Kalderon 已提交
1752
int qed_ll2_set_fragment_of_tx_packet(void *cxt,
Y
Yuval Mintz 已提交
1753 1754 1755 1756
				      u8 connection_handle,
				      dma_addr_t addr, u16 nbytes)
{
	struct qed_ll2_tx_packet *p_cur_send_packet = NULL;
M
Michal Kalderon 已提交
1757
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791
	struct qed_ll2_info *p_ll2_conn = NULL;
	u16 cur_send_frag_num = 0;
	struct core_tx_bd *p_bd;
	unsigned long flags;

	p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
	if (!p_ll2_conn)
		return -EINVAL;

	if (!p_ll2_conn->tx_queue.cur_send_packet)
		return -EINVAL;

	p_cur_send_packet = p_ll2_conn->tx_queue.cur_send_packet;
	cur_send_frag_num = p_ll2_conn->tx_queue.cur_send_frag_num;

	if (cur_send_frag_num >= p_cur_send_packet->bd_used)
		return -EINVAL;

	/* Fill the BD information, and possibly notify FW */
	p_bd = p_cur_send_packet->bds_set[cur_send_frag_num].txq_bd;
	DMA_REGPAIR_LE(p_bd->addr, addr);
	p_bd->nbytes = cpu_to_le16(nbytes);
	p_cur_send_packet->bds_set[cur_send_frag_num].tx_frag = addr;
	p_cur_send_packet->bds_set[cur_send_frag_num].frag_len = nbytes;

	p_ll2_conn->tx_queue.cur_send_frag_num++;

	spin_lock_irqsave(&p_ll2_conn->tx_queue.lock, flags);
	qed_ll2_tx_packet_notify(p_hwfn, p_ll2_conn);
	spin_unlock_irqrestore(&p_ll2_conn->tx_queue.lock, flags);

	return 0;
}

M
Michal Kalderon 已提交
1792
int qed_ll2_terminate_connection(void *cxt, u8 connection_handle)
Y
Yuval Mintz 已提交
1793
{
M
Michal Kalderon 已提交
1794
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1795 1796
	struct qed_ll2_info *p_ll2_conn = NULL;
	int rc = -EINVAL;
1797 1798 1799 1800 1801
	struct qed_ptt *p_ptt;

	p_ptt = qed_ptt_acquire(p_hwfn);
	if (!p_ptt)
		return -EAGAIN;
Y
Yuval Mintz 已提交
1802 1803

	p_ll2_conn = qed_ll2_handle_sanity_lock(p_hwfn, connection_handle);
1804 1805 1806 1807
	if (!p_ll2_conn) {
		rc = -EINVAL;
		goto out;
	}
Y
Yuval Mintz 已提交
1808 1809 1810 1811 1812

	/* Stop Tx & Rx of connection, if needed */
	if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
		rc = qed_sp_ll2_tx_queue_stop(p_hwfn, p_ll2_conn);
		if (rc)
1813
			goto out;
Y
Yuval Mintz 已提交
1814 1815 1816 1817 1818 1819
		qed_ll2_txq_flush(p_hwfn, connection_handle);
	}

	if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
		rc = qed_sp_ll2_rx_queue_stop(p_hwfn, p_ll2_conn);
		if (rc)
1820
			goto out;
Y
Yuval Mintz 已提交
1821 1822 1823
		qed_ll2_rxq_flush(p_hwfn, connection_handle);
	}

1824
	if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_OOO)
1825 1826
		qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);

1827
	if (p_ll2_conn->input.conn_type == QED_LL2_TYPE_FCOE) {
1828
		qed_llh_remove_protocol_filter(p_hwfn, p_ptt,
1829 1830
					       0x8906, 0,
					       QED_LLH_FILTER_ETHERTYPE);
1831
		qed_llh_remove_protocol_filter(p_hwfn, p_ptt,
1832 1833 1834 1835
					       0x8914, 0,
					       QED_LLH_FILTER_ETHERTYPE);
	}

1836 1837
out:
	qed_ptt_release(p_hwfn, p_ptt);
Y
Yuval Mintz 已提交
1838 1839 1840
	return rc;
}

M
Mintz, Yuval 已提交
1841 1842 1843 1844 1845
static void qed_ll2_release_connection_ooo(struct qed_hwfn *p_hwfn,
					   struct qed_ll2_info *p_ll2_conn)
{
	struct qed_ooo_buffer *p_buffer;

1846
	if (p_ll2_conn->input.conn_type != QED_LL2_TYPE_OOO)
M
Mintz, Yuval 已提交
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
		return;

	qed_ooo_release_all_isles(p_hwfn, p_hwfn->p_ooo_info);
	while ((p_buffer = qed_ooo_get_free_buffer(p_hwfn,
						   p_hwfn->p_ooo_info))) {
		dma_free_coherent(&p_hwfn->cdev->pdev->dev,
				  p_buffer->rx_buffer_size,
				  p_buffer->rx_buffer_virt_addr,
				  p_buffer->rx_buffer_phys_addr);
		kfree(p_buffer);
	}
}
M
Michal Kalderon 已提交
1859 1860

void qed_ll2_release_connection(void *cxt, u8 connection_handle)
Y
Yuval Mintz 已提交
1861
{
M
Michal Kalderon 已提交
1862
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878
	struct qed_ll2_info *p_ll2_conn = NULL;

	p_ll2_conn = qed_ll2_handle_sanity(p_hwfn, connection_handle);
	if (!p_ll2_conn)
		return;

	if (QED_LL2_RX_REGISTERED(p_ll2_conn)) {
		p_ll2_conn->rx_queue.b_cb_registred = false;
		qed_int_unregister_cb(p_hwfn, p_ll2_conn->rx_queue.rx_sb_index);
	}

	if (QED_LL2_TX_REGISTERED(p_ll2_conn)) {
		p_ll2_conn->tx_queue.b_cb_registred = false;
		qed_int_unregister_cb(p_hwfn, p_ll2_conn->tx_queue.tx_sb_index);
	}

1879
	kfree(p_ll2_conn->tx_queue.descq_mem);
Y
Yuval Mintz 已提交
1880 1881 1882 1883 1884 1885 1886 1887
	qed_chain_free(p_hwfn->cdev, &p_ll2_conn->tx_queue.txq_chain);

	kfree(p_ll2_conn->rx_queue.descq_array);
	qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rxq_chain);
	qed_chain_free(p_hwfn->cdev, &p_ll2_conn->rx_queue.rcq_chain);

	qed_cxt_release_cid(p_hwfn, p_ll2_conn->cid);

1888 1889
	qed_ll2_release_connection_ooo(p_hwfn, p_ll2_conn);

Y
Yuval Mintz 已提交
1890 1891 1892 1893 1894
	mutex_lock(&p_ll2_conn->mutex);
	p_ll2_conn->b_active = false;
	mutex_unlock(&p_ll2_conn->mutex);
}

T
Tomer Tayar 已提交
1895
int qed_ll2_alloc(struct qed_hwfn *p_hwfn)
Y
Yuval Mintz 已提交
1896 1897 1898 1899 1900 1901 1902 1903 1904
{
	struct qed_ll2_info *p_ll2_connections;
	u8 i;

	/* Allocate LL2's set struct */
	p_ll2_connections = kcalloc(QED_MAX_NUM_OF_LL2_CONNECTIONS,
				    sizeof(struct qed_ll2_info), GFP_KERNEL);
	if (!p_ll2_connections) {
		DP_NOTICE(p_hwfn, "Failed to allocate `struct qed_ll2'\n");
T
Tomer Tayar 已提交
1905
		return -ENOMEM;
Y
Yuval Mintz 已提交
1906 1907 1908 1909 1910
	}

	for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++)
		p_ll2_connections[i].my_id = i;

T
Tomer Tayar 已提交
1911 1912
	p_hwfn->p_ll2_info = p_ll2_connections;
	return 0;
Y
Yuval Mintz 已提交
1913 1914
}

T
Tomer Tayar 已提交
1915
void qed_ll2_setup(struct qed_hwfn *p_hwfn)
Y
Yuval Mintz 已提交
1916 1917 1918 1919
{
	int i;

	for (i = 0; i < QED_MAX_NUM_OF_LL2_CONNECTIONS; i++)
T
Tomer Tayar 已提交
1920
		mutex_init(&p_hwfn->p_ll2_info[i].mutex);
Y
Yuval Mintz 已提交
1921 1922
}

T
Tomer Tayar 已提交
1923
void qed_ll2_free(struct qed_hwfn *p_hwfn)
Y
Yuval Mintz 已提交
1924
{
T
Tomer Tayar 已提交
1925 1926 1927 1928 1929
	if (!p_hwfn->p_ll2_info)
		return;

	kfree(p_hwfn->p_ll2_info);
	p_hwfn->p_ll2_info = NULL;
Y
Yuval Mintz 已提交
1930 1931
}

M
Mintz, Yuval 已提交
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
static void _qed_ll2_get_port_stats(struct qed_hwfn *p_hwfn,
				    struct qed_ptt *p_ptt,
				    struct qed_ll2_stats *p_stats)
{
	struct core_ll2_port_stats port_stats;

	memset(&port_stats, 0, sizeof(port_stats));
	qed_memcpy_from(p_hwfn, p_ptt, &port_stats,
			BAR0_MAP_REG_TSDM_RAM +
			TSTORM_LL2_PORT_STAT_OFFSET(MFW_PORT(p_hwfn)),
			sizeof(port_stats));

	p_stats->gsi_invalid_hdr = HILO_64_REGPAIR(port_stats.gsi_invalid_hdr);
	p_stats->gsi_invalid_pkt_length =
	    HILO_64_REGPAIR(port_stats.gsi_invalid_pkt_length);
	p_stats->gsi_unsupported_pkt_typ =
	    HILO_64_REGPAIR(port_stats.gsi_unsupported_pkt_typ);
	p_stats->gsi_crcchksm_error =
	    HILO_64_REGPAIR(port_stats.gsi_crcchksm_error);
}

Y
Yuval Mintz 已提交
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
static void _qed_ll2_get_tstats(struct qed_hwfn *p_hwfn,
				struct qed_ptt *p_ptt,
				struct qed_ll2_info *p_ll2_conn,
				struct qed_ll2_stats *p_stats)
{
	struct core_ll2_tstorm_per_queue_stat tstats;
	u8 qid = p_ll2_conn->queue_id;
	u32 tstats_addr;

	memset(&tstats, 0, sizeof(tstats));
	tstats_addr = BAR0_MAP_REG_TSDM_RAM +
		      CORE_LL2_TSTORM_PER_QUEUE_STAT_OFFSET(qid);
	qed_memcpy_from(p_hwfn, p_ptt, &tstats, tstats_addr, sizeof(tstats));

	p_stats->packet_too_big_discard =
			HILO_64_REGPAIR(tstats.packet_too_big_discard);
	p_stats->no_buff_discard = HILO_64_REGPAIR(tstats.no_buff_discard);
}

static void _qed_ll2_get_ustats(struct qed_hwfn *p_hwfn,
				struct qed_ptt *p_ptt,
				struct qed_ll2_info *p_ll2_conn,
				struct qed_ll2_stats *p_stats)
{
	struct core_ll2_ustorm_per_queue_stat ustats;
	u8 qid = p_ll2_conn->queue_id;
	u32 ustats_addr;

	memset(&ustats, 0, sizeof(ustats));
	ustats_addr = BAR0_MAP_REG_USDM_RAM +
		      CORE_LL2_USTORM_PER_QUEUE_STAT_OFFSET(qid);
	qed_memcpy_from(p_hwfn, p_ptt, &ustats, ustats_addr, sizeof(ustats));

	p_stats->rcv_ucast_bytes = HILO_64_REGPAIR(ustats.rcv_ucast_bytes);
	p_stats->rcv_mcast_bytes = HILO_64_REGPAIR(ustats.rcv_mcast_bytes);
	p_stats->rcv_bcast_bytes = HILO_64_REGPAIR(ustats.rcv_bcast_bytes);
	p_stats->rcv_ucast_pkts = HILO_64_REGPAIR(ustats.rcv_ucast_pkts);
	p_stats->rcv_mcast_pkts = HILO_64_REGPAIR(ustats.rcv_mcast_pkts);
	p_stats->rcv_bcast_pkts = HILO_64_REGPAIR(ustats.rcv_bcast_pkts);
}

static void _qed_ll2_get_pstats(struct qed_hwfn *p_hwfn,
				struct qed_ptt *p_ptt,
				struct qed_ll2_info *p_ll2_conn,
				struct qed_ll2_stats *p_stats)
{
	struct core_ll2_pstorm_per_queue_stat pstats;
	u8 stats_id = p_ll2_conn->tx_stats_id;
	u32 pstats_addr;

	memset(&pstats, 0, sizeof(pstats));
	pstats_addr = BAR0_MAP_REG_PSDM_RAM +
		      CORE_LL2_PSTORM_PER_QUEUE_STAT_OFFSET(stats_id);
	qed_memcpy_from(p_hwfn, p_ptt, &pstats, pstats_addr, sizeof(pstats));

	p_stats->sent_ucast_bytes = HILO_64_REGPAIR(pstats.sent_ucast_bytes);
	p_stats->sent_mcast_bytes = HILO_64_REGPAIR(pstats.sent_mcast_bytes);
	p_stats->sent_bcast_bytes = HILO_64_REGPAIR(pstats.sent_bcast_bytes);
	p_stats->sent_ucast_pkts = HILO_64_REGPAIR(pstats.sent_ucast_pkts);
	p_stats->sent_mcast_pkts = HILO_64_REGPAIR(pstats.sent_mcast_pkts);
	p_stats->sent_bcast_pkts = HILO_64_REGPAIR(pstats.sent_bcast_pkts);
}

M
Michal Kalderon 已提交
2016
int qed_ll2_get_stats(void *cxt,
Y
Yuval Mintz 已提交
2017 2018
		      u8 connection_handle, struct qed_ll2_stats *p_stats)
{
M
Michal Kalderon 已提交
2019
	struct qed_hwfn *p_hwfn = cxt;
Y
Yuval Mintz 已提交
2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036
	struct qed_ll2_info *p_ll2_conn = NULL;
	struct qed_ptt *p_ptt;

	memset(p_stats, 0, sizeof(*p_stats));

	if ((connection_handle >= QED_MAX_NUM_OF_LL2_CONNECTIONS) ||
	    !p_hwfn->p_ll2_info)
		return -EINVAL;

	p_ll2_conn = &p_hwfn->p_ll2_info[connection_handle];

	p_ptt = qed_ptt_acquire(p_hwfn);
	if (!p_ptt) {
		DP_ERR(p_hwfn, "Failed to acquire ptt\n");
		return -EINVAL;
	}

M
Mintz, Yuval 已提交
2037 2038
	if (p_ll2_conn->input.gsi_enable)
		_qed_ll2_get_port_stats(p_hwfn, p_ptt, p_stats);
Y
Yuval Mintz 已提交
2039 2040 2041 2042 2043 2044 2045 2046 2047
	_qed_ll2_get_tstats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
	_qed_ll2_get_ustats(p_hwfn, p_ptt, p_ll2_conn, p_stats);
	if (p_ll2_conn->tx_stats_en)
		_qed_ll2_get_pstats(p_hwfn, p_ptt, p_ll2_conn, p_stats);

	qed_ptt_release(p_hwfn, p_ptt);
	return 0;
}

M
Michal Kalderon 已提交
2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058
static void qed_ll2b_release_rx_packet(void *cxt,
				       u8 connection_handle,
				       void *cookie,
				       dma_addr_t rx_buf_addr,
				       bool b_last_packet)
{
	struct qed_hwfn *p_hwfn = cxt;

	qed_ll2_dealloc_buffer(p_hwfn->cdev, cookie);
}

Y
Yuval Mintz 已提交
2059 2060 2061 2062 2063 2064 2065 2066
static void qed_ll2_register_cb_ops(struct qed_dev *cdev,
				    const struct qed_ll2_cb_ops *ops,
				    void *cookie)
{
	cdev->ll2->cbs = ops;
	cdev->ll2->cb_cookie = cookie;
}

M
Michal Kalderon 已提交
2067 2068 2069 2070 2071 2072 2073
struct qed_ll2_cbs ll2_cbs = {
	.rx_comp_cb = &qed_ll2b_complete_rx_packet,
	.rx_release_cb = &qed_ll2b_release_rx_packet,
	.tx_comp_cb = &qed_ll2b_complete_tx_packet,
	.tx_release_cb = &qed_ll2b_complete_tx_packet,
};

2074 2075 2076 2077
static void qed_ll2_set_conn_data(struct qed_dev *cdev,
				  struct qed_ll2_acquire_data *data,
				  struct qed_ll2_params *params,
				  enum qed_ll2_conn_type conn_type,
M
Michal Kalderon 已提交
2078
				  u8 *handle, bool lb)
2079 2080 2081 2082 2083 2084 2085 2086 2087 2088
{
	memset(data, 0, sizeof(*data));

	data->input.conn_type = conn_type;
	data->input.mtu = params->mtu;
	data->input.rx_num_desc = QED_LL2_RX_SIZE;
	data->input.rx_drop_ttl0_flg = params->drop_ttl0_packets;
	data->input.rx_vlan_removal_en = params->rx_vlan_stripping;
	data->input.tx_num_desc = QED_LL2_TX_SIZE;
	data->p_connection_handle = handle;
M
Michal Kalderon 已提交
2089 2090 2091
	data->cbs = &ll2_cbs;
	ll2_cbs.cookie = QED_LEADING_HWFN(cdev);

2092
	if (lb) {
2093
		data->input.tx_tc = PKT_LB_TC;
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109
		data->input.tx_dest = QED_LL2_TX_DEST_LB;
	} else {
		data->input.tx_tc = 0;
		data->input.tx_dest = QED_LL2_TX_DEST_NW;
	}
}

static int qed_ll2_start_ooo(struct qed_dev *cdev,
			     struct qed_ll2_params *params)
{
	struct qed_hwfn *hwfn = QED_LEADING_HWFN(cdev);
	u8 *handle = &hwfn->pf_params.iscsi_pf_params.ll2_ooo_queue_id;
	struct qed_ll2_acquire_data data;
	int rc;

	qed_ll2_set_conn_data(cdev, &data, params,
2110
			      QED_LL2_TYPE_OOO, handle, true);
2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132

	rc = qed_ll2_acquire_connection(hwfn, &data);
	if (rc) {
		DP_INFO(cdev, "Failed to acquire LL2 OOO connection\n");
		goto out;
	}

	rc = qed_ll2_establish_connection(hwfn, *handle);
	if (rc) {
		DP_INFO(cdev, "Failed to establist LL2 OOO connection\n");
		goto fail;
	}

	return 0;

fail:
	qed_ll2_release_connection(hwfn, *handle);
out:
	*handle = QED_LL2_UNUSED_HANDLE;
	return rc;
}

Y
Yuval Mintz 已提交
2133 2134
static int qed_ll2_start(struct qed_dev *cdev, struct qed_ll2_params *params)
{
2135
	struct qed_ll2_buffer *buffer, *tmp_buffer;
Y
Yuval Mintz 已提交
2136
	enum qed_ll2_conn_type conn_type;
2137
	struct qed_ll2_acquire_data data;
Y
Yuval Mintz 已提交
2138 2139
	struct qed_ptt *p_ptt;
	int rc, i;
M
Michal Kalderon 已提交
2140

Y
Yuval Mintz 已提交
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168

	/* Initialize LL2 locks & lists */
	INIT_LIST_HEAD(&cdev->ll2->list);
	spin_lock_init(&cdev->ll2->lock);
	cdev->ll2->rx_size = NET_SKB_PAD + ETH_HLEN +
			     L1_CACHE_BYTES + params->mtu;

	/*Allocate memory for LL2 */
	DP_INFO(cdev, "Allocating LL2 buffers of size %08x bytes\n",
		cdev->ll2->rx_size);
	for (i = 0; i < QED_LL2_RX_SIZE; i++) {
		buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
		if (!buffer) {
			DP_INFO(cdev, "Failed to allocate LL2 buffers\n");
			goto fail;
		}

		rc = qed_ll2_alloc_buffer(cdev, (u8 **)&buffer->data,
					  &buffer->phys_addr);
		if (rc) {
			kfree(buffer);
			goto fail;
		}

		list_add_tail(&buffer->list, &cdev->ll2->list);
	}

	switch (QED_LEADING_HWFN(cdev)->hw_info.personality) {
2169 2170 2171
	case QED_PCI_FCOE:
		conn_type = QED_LL2_TYPE_FCOE;
		break;
Y
Yuval Mintz 已提交
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181
	case QED_PCI_ISCSI:
		conn_type = QED_LL2_TYPE_ISCSI;
		break;
	case QED_PCI_ETH_ROCE:
		conn_type = QED_LL2_TYPE_ROCE;
		break;
	default:
		conn_type = QED_LL2_TYPE_TEST;
	}

2182
	qed_ll2_set_conn_data(cdev, &data, params, conn_type,
M
Michal Kalderon 已提交
2183
			      &cdev->ll2->handle, false);
Y
Yuval Mintz 已提交
2184

2185
	rc = qed_ll2_acquire_connection(QED_LEADING_HWFN(cdev), &data);
Y
Yuval Mintz 已提交
2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199
	if (rc) {
		DP_INFO(cdev, "Failed to acquire LL2 connection\n");
		goto fail;
	}

	rc = qed_ll2_establish_connection(QED_LEADING_HWFN(cdev),
					  cdev->ll2->handle);
	if (rc) {
		DP_INFO(cdev, "Failed to establish LL2 connection\n");
		goto release_fail;
	}

	/* Post all Rx buffers to FW */
	spin_lock_bh(&cdev->ll2->lock);
2200
	list_for_each_entry_safe(buffer, tmp_buffer, &cdev->ll2->list, list) {
Y
Yuval Mintz 已提交
2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227
		rc = qed_ll2_post_rx_buffer(QED_LEADING_HWFN(cdev),
					    cdev->ll2->handle,
					    buffer->phys_addr, 0, buffer, 1);
		if (rc) {
			DP_INFO(cdev,
				"Failed to post an Rx buffer; Deleting it\n");
			dma_unmap_single(&cdev->pdev->dev, buffer->phys_addr,
					 cdev->ll2->rx_size, DMA_FROM_DEVICE);
			kfree(buffer->data);
			list_del(&buffer->list);
			kfree(buffer);
		} else {
			cdev->ll2->rx_cnt++;
		}
	}
	spin_unlock_bh(&cdev->ll2->lock);

	if (!cdev->ll2->rx_cnt) {
		DP_INFO(cdev, "Failed passing even a single Rx buffer\n");
		goto release_terminate;
	}

	if (!is_valid_ether_addr(params->ll2_mac_address)) {
		DP_INFO(cdev, "Invalid Ethernet address\n");
		goto release_terminate;
	}

2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238
	if (cdev->hwfns[0].hw_info.personality == QED_PCI_ISCSI &&
	    cdev->hwfns[0].pf_params.iscsi_pf_params.ooo_enable) {
		DP_VERBOSE(cdev, QED_MSG_STORAGE, "Starting OOO LL2 queue\n");
		rc = qed_ll2_start_ooo(cdev, params);
		if (rc) {
			DP_INFO(cdev,
				"Failed to initialize the OOO LL2 queue\n");
			goto release_terminate;
		}
	}

Y
Yuval Mintz 已提交
2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286
	p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
	if (!p_ptt) {
		DP_INFO(cdev, "Failed to acquire PTT\n");
		goto release_terminate;
	}

	rc = qed_llh_add_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
				    params->ll2_mac_address);
	qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
	if (rc) {
		DP_ERR(cdev, "Failed to allocate LLH filter\n");
		goto release_terminate_all;
	}

	ether_addr_copy(cdev->ll2_mac_address, params->ll2_mac_address);
	return 0;

release_terminate_all:

release_terminate:
	qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
release_fail:
	qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
fail:
	qed_ll2_kill_buffers(cdev);
	cdev->ll2->handle = QED_LL2_UNUSED_HANDLE;
	return -EINVAL;
}

static int qed_ll2_stop(struct qed_dev *cdev)
{
	struct qed_ptt *p_ptt;
	int rc;

	if (cdev->ll2->handle == QED_LL2_UNUSED_HANDLE)
		return 0;

	p_ptt = qed_ptt_acquire(QED_LEADING_HWFN(cdev));
	if (!p_ptt) {
		DP_INFO(cdev, "Failed to acquire PTT\n");
		goto fail;
	}

	qed_llh_remove_mac_filter(QED_LEADING_HWFN(cdev), p_ptt,
				  cdev->ll2_mac_address);
	qed_ptt_release(QED_LEADING_HWFN(cdev), p_ptt);
	eth_zero_addr(cdev->ll2_mac_address);

2287 2288 2289 2290
	if (cdev->hwfns[0].hw_info.personality == QED_PCI_ISCSI &&
	    cdev->hwfns[0].pf_params.iscsi_pf_params.ooo_enable)
		qed_ll2_stop_ooo(cdev);

Y
Yuval Mintz 已提交
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307
	rc = qed_ll2_terminate_connection(QED_LEADING_HWFN(cdev),
					  cdev->ll2->handle);
	if (rc)
		DP_INFO(cdev, "Failed to terminate LL2 connection\n");

	qed_ll2_kill_buffers(cdev);

	qed_ll2_release_connection(QED_LEADING_HWFN(cdev), cdev->ll2->handle);
	cdev->ll2->handle = QED_LL2_UNUSED_HANDLE;

	return rc;
fail:
	return -EINVAL;
}

static int qed_ll2_start_xmit(struct qed_dev *cdev, struct sk_buff *skb)
{
2308
	struct qed_ll2_tx_pkt_info pkt;
Y
Yuval Mintz 已提交
2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
	const skb_frag_t *frag;
	int rc = -EINVAL, i;
	dma_addr_t mapping;
	u16 vlan = 0;
	u8 flags = 0;

	if (unlikely(skb->ip_summed != CHECKSUM_NONE)) {
		DP_INFO(cdev, "Cannot transmit a checksumed packet\n");
		return -EINVAL;
	}

	if (1 + skb_shinfo(skb)->nr_frags > CORE_LL2_TX_MAX_BDS_PER_PACKET) {
		DP_ERR(cdev, "Cannot transmit a packet with %d fragments\n",
		       1 + skb_shinfo(skb)->nr_frags);
		return -EINVAL;
	}

	mapping = dma_map_single(&cdev->pdev->dev, skb->data,
				 skb->len, DMA_TO_DEVICE);
	if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) {
		DP_NOTICE(cdev, "SKB mapping failed\n");
		return -EINVAL;
	}

	/* Request HW to calculate IP csum */
	if (!((vlan_get_protocol(skb) == htons(ETH_P_IPV6)) &&
	      ipv6_hdr(skb)->nexthdr == NEXTHDR_IPV6))
M
Mintz, Yuval 已提交
2336
		flags |= BIT(CORE_TX_BD_DATA_IP_CSUM_SHIFT);
Y
Yuval Mintz 已提交
2337 2338 2339

	if (skb_vlan_tag_present(skb)) {
		vlan = skb_vlan_tag_get(skb);
M
Mintz, Yuval 已提交
2340
		flags |= BIT(CORE_TX_BD_DATA_VLAN_INSERTION_SHIFT);
Y
Yuval Mintz 已提交
2341 2342
	}

2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
	memset(&pkt, 0, sizeof(pkt));
	pkt.num_of_bds = 1 + skb_shinfo(skb)->nr_frags;
	pkt.vlan = vlan;
	pkt.bd_flags = flags;
	pkt.tx_dest = QED_LL2_TX_DEST_NW;
	pkt.first_frag = mapping;
	pkt.first_frag_len = skb->len;
	pkt.cookie = skb;

	rc = qed_ll2_prepare_tx_packet(&cdev->hwfns[0], cdev->ll2->handle,
				       &pkt, 1);
Y
Yuval Mintz 已提交
2354 2355 2356 2357 2358
	if (rc)
		goto err;

	for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
		frag = &skb_shinfo(skb)->frags[i];
2359 2360 2361 2362 2363 2364 2365 2366

		mapping = skb_frag_dma_map(&cdev->pdev->dev, frag, 0,
					   skb_frag_size(frag), DMA_TO_DEVICE);

		if (unlikely(dma_mapping_error(&cdev->pdev->dev, mapping))) {
			DP_NOTICE(cdev,
				  "Unable to map frag - dropping packet\n");
			goto err;
Y
Yuval Mintz 已提交
2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417
		}

		rc = qed_ll2_set_fragment_of_tx_packet(QED_LEADING_HWFN(cdev),
						       cdev->ll2->handle,
						       mapping,
						       skb_frag_size(frag));

		/* if failed not much to do here, partial packet has been posted
		 * we can't free memory, will need to wait for completion.
		 */
		if (rc)
			goto err2;
	}

	return 0;

err:
	dma_unmap_single(&cdev->pdev->dev, mapping, skb->len, DMA_TO_DEVICE);

err2:
	return rc;
}

static int qed_ll2_stats(struct qed_dev *cdev, struct qed_ll2_stats *stats)
{
	if (!cdev->ll2)
		return -EINVAL;

	return qed_ll2_get_stats(QED_LEADING_HWFN(cdev),
				 cdev->ll2->handle, stats);
}

const struct qed_ll2_ops qed_ll2_ops_pass = {
	.start = &qed_ll2_start,
	.stop = &qed_ll2_stop,
	.start_xmit = &qed_ll2_start_xmit,
	.register_cb_ops = &qed_ll2_register_cb_ops,
	.get_stats = &qed_ll2_stats,
};

int qed_ll2_alloc_if(struct qed_dev *cdev)
{
	cdev->ll2 = kzalloc(sizeof(*cdev->ll2), GFP_KERNEL);
	return cdev->ll2 ? 0 : -ENOMEM;
}

void qed_ll2_dealloc_if(struct qed_dev *cdev)
{
	kfree(cdev->ll2);
	cdev->ll2 = NULL;
}