2 * This file is part of the Chelsio FCoE driver for Linux.
4 * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <linux/kernel.h>
36 #include <linux/delay.h>
37 #include <linux/slab.h>
38 #include <linux/utsname.h>
39 #include <scsi/scsi_device.h>
40 #include <scsi/scsi_transport_fc.h>
41 #include <asm/unaligned.h>
42 #include <scsi/fc/fc_els.h>
43 #include <scsi/fc/fc_fs.h>
44 #include <scsi/fc/fc_gs.h>
45 #include <scsi/fc/fc_ms.h>
49 #include "csio_lnode.h"
50 #include "csio_rnode.h"
52 int csio_fcoe_rnodes
= 1024;
53 int csio_fdmi_enable
= 1;
55 #define PORT_ID_PTR(_x) ((uint8_t *)(&_x) + 1)
57 /* Lnode SM declarations */
58 static void csio_lns_uninit(struct csio_lnode
*, enum csio_ln_ev
);
59 static void csio_lns_online(struct csio_lnode
*, enum csio_ln_ev
);
60 static void csio_lns_ready(struct csio_lnode
*, enum csio_ln_ev
);
61 static void csio_lns_offline(struct csio_lnode
*, enum csio_ln_ev
);
63 static int csio_ln_mgmt_submit_req(struct csio_ioreq
*,
64 void (*io_cbfn
) (struct csio_hw
*, struct csio_ioreq
*),
65 enum fcoe_cmn_type
, struct csio_dma_buf
*, uint32_t);
67 /* LN event mapping */
68 static enum csio_ln_ev fwevt_to_lnevt
[] = {
69 CSIO_LNE_NONE
, /* None */
70 CSIO_LNE_NONE
, /* PLOGI_ACC_RCVD */
71 CSIO_LNE_NONE
, /* PLOGI_RJT_RCVD */
72 CSIO_LNE_NONE
, /* PLOGI_RCVD */
73 CSIO_LNE_NONE
, /* PLOGO_RCVD */
74 CSIO_LNE_NONE
, /* PRLI_ACC_RCVD */
75 CSIO_LNE_NONE
, /* PRLI_RJT_RCVD */
76 CSIO_LNE_NONE
, /* PRLI_RCVD */
77 CSIO_LNE_NONE
, /* PRLO_RCVD */
78 CSIO_LNE_NONE
, /* NPORT_ID_CHGD */
79 CSIO_LNE_LOGO
, /* FLOGO_RCVD */
80 CSIO_LNE_LOGO
, /* CLR_VIRT_LNK_RCVD */
81 CSIO_LNE_FAB_INIT_DONE
,/* FLOGI_ACC_RCVD */
82 CSIO_LNE_NONE
, /* FLOGI_RJT_RCVD */
83 CSIO_LNE_FAB_INIT_DONE
,/* FDISC_ACC_RCVD */
84 CSIO_LNE_NONE
, /* FDISC_RJT_RCVD */
85 CSIO_LNE_NONE
, /* FLOGI_TMO_MAX_RETRY */
86 CSIO_LNE_NONE
, /* IMPL_LOGO_ADISC_ACC */
87 CSIO_LNE_NONE
, /* IMPL_LOGO_ADISC_RJT */
88 CSIO_LNE_NONE
, /* IMPL_LOGO_ADISC_CNFLT */
89 CSIO_LNE_NONE
, /* PRLI_TMO */
90 CSIO_LNE_NONE
, /* ADISC_TMO */
91 CSIO_LNE_NONE
, /* RSCN_DEV_LOST */
92 CSIO_LNE_NONE
, /* SCR_ACC_RCVD */
93 CSIO_LNE_NONE
, /* ADISC_RJT_RCVD */
94 CSIO_LNE_NONE
, /* LOGO_SNT */
95 CSIO_LNE_NONE
, /* PROTO_ERR_IMPL_LOGO */
98 #define CSIO_FWE_TO_LNE(_evt) ((_evt > PROTO_ERR_IMPL_LOGO) ? \
100 fwevt_to_lnevt[_evt])
102 #define csio_ct_rsp(cp) (((struct fc_ct_hdr *)cp)->ct_cmd)
103 #define csio_ct_reason(cp) (((struct fc_ct_hdr *)cp)->ct_reason)
104 #define csio_ct_expl(cp) (((struct fc_ct_hdr *)cp)->ct_explan)
105 #define csio_ct_get_pld(cp) ((void *)(((uint8_t *)cp) + FC_CT_HDR_LEN))
108 * csio_ln_match_by_portid - lookup lnode using given portid.
112 * If found, returns lnode matching given portid otherwise returns NULL.
114 static struct csio_lnode
*
115 csio_ln_lookup_by_portid(struct csio_hw
*hw
, uint8_t portid
)
117 struct csio_lnode
*ln
;
118 struct list_head
*tmp
;
120 /* Match siblings lnode with portid */
121 list_for_each(tmp
, &hw
->sln_head
) {
122 ln
= (struct csio_lnode
*) tmp
;
123 if (ln
->portid
== portid
)
131 * csio_ln_lookup_by_vnpi - Lookup lnode using given vnp id.
134 * Returns - If found, returns lnode matching given vnp id
135 * otherwise returns NULL.
137 static struct csio_lnode
*
138 csio_ln_lookup_by_vnpi(struct csio_hw
*hw
, uint32_t vnp_id
)
140 struct list_head
*tmp1
, *tmp2
;
141 struct csio_lnode
*sln
= NULL
, *cln
= NULL
;
143 if (list_empty(&hw
->sln_head
)) {
144 CSIO_INC_STATS(hw
, n_lnlkup_miss
);
147 /* Traverse sibling lnodes */
148 list_for_each(tmp1
, &hw
->sln_head
) {
149 sln
= (struct csio_lnode
*) tmp1
;
151 /* Match sibling lnode */
152 if (sln
->vnp_flowid
== vnp_id
)
155 if (list_empty(&sln
->cln_head
))
158 /* Traverse children lnodes */
159 list_for_each(tmp2
, &sln
->cln_head
) {
160 cln
= (struct csio_lnode
*) tmp2
;
162 if (cln
->vnp_flowid
== vnp_id
)
166 CSIO_INC_STATS(hw
, n_lnlkup_miss
);
171 * csio_lnode_lookup_by_wwpn - Lookup lnode using given wwpn.
175 * If found, returns lnode matching given wwpn, returns NULL otherwise.
178 csio_lnode_lookup_by_wwpn(struct csio_hw
*hw
, uint8_t *wwpn
)
180 struct list_head
*tmp1
, *tmp2
;
181 struct csio_lnode
*sln
= NULL
, *cln
= NULL
;
183 if (list_empty(&hw
->sln_head
)) {
184 CSIO_INC_STATS(hw
, n_lnlkup_miss
);
187 /* Traverse sibling lnodes */
188 list_for_each(tmp1
, &hw
->sln_head
) {
189 sln
= (struct csio_lnode
*) tmp1
;
191 /* Match sibling lnode */
192 if (!memcmp(csio_ln_wwpn(sln
), wwpn
, 8))
195 if (list_empty(&sln
->cln_head
))
198 /* Traverse children lnodes */
199 list_for_each(tmp2
, &sln
->cln_head
) {
200 cln
= (struct csio_lnode
*) tmp2
;
202 if (!memcmp(csio_ln_wwpn(cln
), wwpn
, 8))
211 csio_fill_ct_iu(void *buf
, uint8_t type
, uint8_t sub_type
, uint16_t op
)
213 struct fc_ct_hdr
*cmd
= (struct fc_ct_hdr
*)buf
;
214 cmd
->ct_rev
= FC_CT_REV
;
215 cmd
->ct_fs_type
= type
;
216 cmd
->ct_fs_subtype
= sub_type
;
217 cmd
->ct_cmd
= htons(op
);
221 csio_hostname(uint8_t *buf
, size_t buf_len
)
223 if (snprintf(buf
, buf_len
, "%s", init_utsname()->nodename
) > 0)
229 csio_osname(uint8_t *buf
, size_t buf_len
)
231 if (snprintf(buf
, buf_len
, "%s %s %s",
232 init_utsname()->sysname
,
233 init_utsname()->release
,
234 init_utsname()->version
) > 0)
241 csio_append_attrib(uint8_t **ptr
, uint16_t type
, void *val
, size_t val_len
)
244 struct fc_fdmi_attr_entry
*ae
= (struct fc_fdmi_attr_entry
*)*ptr
;
246 if (WARN_ON(val_len
> U16_MAX
))
251 ae
->type
= htons(type
);
252 len
+= 4; /* includes attribute type and length */
253 len
= (len
+ 3) & ~3; /* should be multiple of 4 bytes */
254 ae
->len
= htons(len
);
255 memcpy(ae
->value
, val
, val_len
);
257 memset(ae
->value
+ val_len
, 0, len
- val_len
);
262 * csio_ln_fdmi_done - FDMI registeration completion
264 * @fdmi_req: fdmi request
267 csio_ln_fdmi_done(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
270 struct csio_lnode
*ln
= fdmi_req
->lnode
;
272 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
273 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rpa cmd\n",
274 fdmi_req
->wr_status
);
275 CSIO_INC_STATS(ln
, n_fdmi_err
);
278 cmd
= fdmi_req
->dma_buf
.vaddr
;
279 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
280 csio_ln_dbg(ln
, "fdmi rpa cmd rejected reason %x expl %x\n",
281 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
286 * csio_ln_fdmi_rhba_cbfn - RHBA completion
288 * @fdmi_req: fdmi request
291 csio_ln_fdmi_rhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
298 uint32_t numattrs
= 0;
299 struct csio_lnode
*ln
= fdmi_req
->lnode
;
300 struct fs_fdmi_attrs
*attrib_blk
;
301 struct fc_fdmi_port_name
*port_name
;
305 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
306 csio_ln_dbg(ln
, "WR error:%x in processing fdmi rhba cmd\n",
307 fdmi_req
->wr_status
);
308 CSIO_INC_STATS(ln
, n_fdmi_err
);
311 cmd
= fdmi_req
->dma_buf
.vaddr
;
312 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
313 csio_ln_dbg(ln
, "fdmi rhba cmd rejected reason %x expl %x\n",
314 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
317 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
318 CSIO_INC_STATS(ln
, n_fdmi_err
);
322 /* Prepare CT hdr for RPA cmd */
323 memset(cmd
, 0, FC_CT_HDR_LEN
);
324 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RPA
);
326 /* Prepare RPA payload */
327 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
328 port_name
= (struct fc_fdmi_port_name
*)pld
;
329 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
330 pld
+= sizeof(*port_name
);
332 /* Start appending Port attributes */
333 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
334 attrib_blk
->numattrs
= 0;
335 len
+= sizeof(attrib_blk
->numattrs
);
336 pld
+= sizeof(attrib_blk
->numattrs
);
339 memset(fc4_type
, 0, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
342 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_FC4TYPES
,
343 fc4_type
, FC_FDMI_PORT_ATTR_FC4TYPES_LEN
);
345 val
= htonl(FC_PORTSPEED_1GBIT
| FC_PORTSPEED_10GBIT
);
346 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_SUPPORTEDSPEED
,
348 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN
);
351 if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_1G
)
352 val
= htonl(FC_PORTSPEED_1GBIT
);
353 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP_SPEED_10G
)
354 val
= htonl(FC_PORTSPEED_10GBIT
);
355 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP32_SPEED_25G
)
356 val
= htonl(FC_PORTSPEED_25GBIT
);
357 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP32_SPEED_40G
)
358 val
= htonl(FC_PORTSPEED_40GBIT
);
359 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP32_SPEED_50G
)
360 val
= htonl(FC_PORTSPEED_50GBIT
);
361 else if (hw
->pport
[ln
->portid
].link_speed
== FW_PORT_CAP32_SPEED_100G
)
362 val
= htonl(FC_PORTSPEED_100GBIT
);
364 val
= htonl(CSIO_HBA_PORTSPEED_UNKNOWN
);
365 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED
,
366 &val
, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN
);
369 mfs
= ln
->ln_sparm
.csp
.sp_bb_data
;
370 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_MAXFRAMESIZE
,
374 strcpy(buf
, "csiostor");
375 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_OSDEVICENAME
, buf
,
379 if (!csio_hostname(buf
, sizeof(buf
))) {
380 csio_append_attrib(&pld
, FC_FDMI_PORT_ATTR_HOSTNAME
,
384 attrib_blk
->numattrs
= htonl(numattrs
);
385 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
387 /* Submit FDMI RPA request */
388 spin_lock_irq(&hw
->lock
);
389 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_done
,
390 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
391 CSIO_INC_STATS(ln
, n_fdmi_err
);
392 csio_ln_dbg(ln
, "Failed to issue fdmi rpa req\n");
394 spin_unlock_irq(&hw
->lock
);
398 * csio_ln_fdmi_dprt_cbfn - DPRT completion
400 * @fdmi_req: fdmi request
403 csio_ln_fdmi_dprt_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
408 uint32_t numattrs
= 0;
409 __be32 maxpayload
= htonl(65536);
410 struct fc_fdmi_hba_identifier
*hbaid
;
411 struct csio_lnode
*ln
= fdmi_req
->lnode
;
412 struct fc_fdmi_rpl
*reg_pl
;
413 struct fs_fdmi_attrs
*attrib_blk
;
416 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
417 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dprt cmd\n",
418 fdmi_req
->wr_status
);
419 CSIO_INC_STATS(ln
, n_fdmi_err
);
422 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
423 CSIO_INC_STATS(ln
, n_fdmi_err
);
426 cmd
= fdmi_req
->dma_buf
.vaddr
;
427 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
428 csio_ln_dbg(ln
, "fdmi dprt cmd rejected reason %x expl %x\n",
429 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
432 /* Prepare CT hdr for RHBA cmd */
433 memset(cmd
, 0, FC_CT_HDR_LEN
);
434 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_RHBA
);
437 /* Prepare RHBA payload */
438 pld
= (uint8_t *)csio_ct_get_pld(cmd
);
439 hbaid
= (struct fc_fdmi_hba_identifier
*)pld
;
440 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8); /* HBA identifer */
441 pld
+= sizeof(*hbaid
);
443 /* Register one port per hba */
444 reg_pl
= (struct fc_fdmi_rpl
*)pld
;
445 reg_pl
->numport
= htonl(1);
446 memcpy(®_pl
->port
[0].portname
, csio_ln_wwpn(ln
), 8);
447 pld
+= sizeof(*reg_pl
);
449 /* Start appending HBA attributes hba */
450 attrib_blk
= (struct fs_fdmi_attrs
*)pld
;
451 attrib_blk
->numattrs
= 0;
452 len
+= sizeof(attrib_blk
->numattrs
);
453 pld
+= sizeof(attrib_blk
->numattrs
);
455 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_NODENAME
, csio_ln_wwnn(ln
),
456 FC_FDMI_HBA_ATTR_NODENAME_LEN
);
459 memset(buf
, 0, sizeof(buf
));
461 strcpy(buf
, "Chelsio Communications");
462 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MANUFACTURER
, buf
,
465 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_SERIALNUMBER
,
466 hw
->vpd
.sn
, sizeof(hw
->vpd
.sn
));
468 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODEL
, hw
->vpd
.id
,
471 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MODELDESCRIPTION
,
472 hw
->model_desc
, strlen(hw
->model_desc
));
474 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_HARDWAREVERSION
,
475 hw
->hw_ver
, sizeof(hw
->hw_ver
));
477 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_FIRMWAREVERSION
,
478 hw
->fwrev_str
, strlen(hw
->fwrev_str
));
481 if (!csio_osname(buf
, sizeof(buf
))) {
482 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_OSNAMEVERSION
,
487 csio_append_attrib(&pld
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD
,
488 &maxpayload
, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN
);
489 len
= (uint32_t)(pld
- (uint8_t *)cmd
);
491 attrib_blk
->numattrs
= htonl(numattrs
);
493 /* Submit FDMI RHBA request */
494 spin_lock_irq(&hw
->lock
);
495 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_rhba_cbfn
,
496 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
497 CSIO_INC_STATS(ln
, n_fdmi_err
);
498 csio_ln_dbg(ln
, "Failed to issue fdmi rhba req\n");
500 spin_unlock_irq(&hw
->lock
);
504 * csio_ln_fdmi_dhba_cbfn - DHBA completion
506 * @fdmi_req: fdmi request
509 csio_ln_fdmi_dhba_cbfn(struct csio_hw
*hw
, struct csio_ioreq
*fdmi_req
)
511 struct csio_lnode
*ln
= fdmi_req
->lnode
;
513 struct fc_fdmi_port_name
*port_name
;
516 if (fdmi_req
->wr_status
!= FW_SUCCESS
) {
517 csio_ln_dbg(ln
, "WR error:%x in processing fdmi dhba cmd\n",
518 fdmi_req
->wr_status
);
519 CSIO_INC_STATS(ln
, n_fdmi_err
);
522 if (!csio_is_rnode_ready(fdmi_req
->rnode
)) {
523 CSIO_INC_STATS(ln
, n_fdmi_err
);
526 cmd
= fdmi_req
->dma_buf
.vaddr
;
527 if (ntohs(csio_ct_rsp(cmd
)) != FC_FS_ACC
) {
528 csio_ln_dbg(ln
, "fdmi dhba cmd rejected reason %x expl %x\n",
529 csio_ct_reason(cmd
), csio_ct_expl(cmd
));
532 /* Send FDMI cmd to de-register any Port attributes if registered
536 /* Prepare FDMI DPRT cmd */
537 memset(cmd
, 0, FC_CT_HDR_LEN
);
538 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DPRT
);
540 port_name
= (struct fc_fdmi_port_name
*)csio_ct_get_pld(cmd
);
541 memcpy(&port_name
->portname
, csio_ln_wwpn(ln
), 8);
542 len
+= sizeof(*port_name
);
544 /* Submit FDMI request */
545 spin_lock_irq(&hw
->lock
);
546 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dprt_cbfn
,
547 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
548 CSIO_INC_STATS(ln
, n_fdmi_err
);
549 csio_ln_dbg(ln
, "Failed to issue fdmi dprt req\n");
551 spin_unlock_irq(&hw
->lock
);
555 * csio_ln_fdmi_start - Start an FDMI request.
557 * @context: session context
559 * Issued with lock held.
562 csio_ln_fdmi_start(struct csio_lnode
*ln
, void *context
)
564 struct csio_ioreq
*fdmi_req
;
565 struct csio_rnode
*fdmi_rn
= (struct csio_rnode
*)context
;
567 struct fc_fdmi_hba_identifier
*hbaid
;
570 if (!(ln
->flags
& CSIO_LNF_FDMI_ENABLE
))
571 return -EPROTONOSUPPORT
;
573 if (!csio_is_rnode_ready(fdmi_rn
))
574 CSIO_INC_STATS(ln
, n_fdmi_err
);
576 /* Send FDMI cmd to de-register any HBA attributes if registered
580 fdmi_req
= ln
->mgmt_req
;
581 fdmi_req
->lnode
= ln
;
582 fdmi_req
->rnode
= fdmi_rn
;
584 /* Prepare FDMI DHBA cmd */
585 cmd
= fdmi_req
->dma_buf
.vaddr
;
586 memset(cmd
, 0, FC_CT_HDR_LEN
);
587 csio_fill_ct_iu(cmd
, FC_FST_MGMT
, FC_FDMI_SUBTYPE
, FC_FDMI_DHBA
);
590 hbaid
= (struct fc_fdmi_hba_identifier
*)csio_ct_get_pld(cmd
);
591 memcpy(&hbaid
->id
, csio_ln_wwpn(ln
), 8);
592 len
+= sizeof(*hbaid
);
594 /* Submit FDMI request */
595 if (csio_ln_mgmt_submit_req(fdmi_req
, csio_ln_fdmi_dhba_cbfn
,
596 FCOE_CT
, &fdmi_req
->dma_buf
, len
)) {
597 CSIO_INC_STATS(ln
, n_fdmi_err
);
598 csio_ln_dbg(ln
, "Failed to issue fdmi dhba req\n");
605 * csio_ln_vnp_read_cbfn - vnp read completion handler.
607 * @cbfn: Completion handler.
609 * Reads vnp response and updates ln parameters.
612 csio_ln_vnp_read_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
614 struct csio_lnode
*ln
= ((struct csio_lnode
*)mbp
->priv
);
615 struct fw_fcoe_vnp_cmd
*rsp
= (struct fw_fcoe_vnp_cmd
*)(mbp
->mb
);
616 struct fc_els_csp
*csp
;
617 struct fc_els_cssp
*clsp
;
618 enum fw_retval retval
;
621 retval
= FW_CMD_RETVAL_G(ntohl(rsp
->alloc_to_len16
));
622 if (retval
!= FW_SUCCESS
) {
623 csio_err(hw
, "FCOE VNP read cmd returned error:0x%x\n", retval
);
624 mempool_free(mbp
, hw
->mb_mempool
);
628 spin_lock_irq(&hw
->lock
);
630 memcpy(ln
->mac
, rsp
->vnport_mac
, sizeof(ln
->mac
));
631 memcpy(&nport_id
, &rsp
->vnport_mac
[3], sizeof(uint8_t)*3);
632 ln
->nport_id
= ntohl(nport_id
);
633 ln
->nport_id
= ln
->nport_id
>> 8;
637 * This may look like a duplication of what csio_fcoe_enable_link()
638 * does, but is absolutely necessary if the vnpi changes between
639 * a FCOE LINK UP and FCOE LINK DOWN.
641 memcpy(csio_ln_wwnn(ln
), rsp
->vnport_wwnn
, 8);
642 memcpy(csio_ln_wwpn(ln
), rsp
->vnport_wwpn
, 8);
644 /* Copy common sparam */
645 csp
= (struct fc_els_csp
*)rsp
->cmn_srv_parms
;
646 ln
->ln_sparm
.csp
.sp_hi_ver
= csp
->sp_hi_ver
;
647 ln
->ln_sparm
.csp
.sp_lo_ver
= csp
->sp_lo_ver
;
648 ln
->ln_sparm
.csp
.sp_bb_cred
= csp
->sp_bb_cred
;
649 ln
->ln_sparm
.csp
.sp_features
= csp
->sp_features
;
650 ln
->ln_sparm
.csp
.sp_bb_data
= csp
->sp_bb_data
;
651 ln
->ln_sparm
.csp
.sp_r_a_tov
= csp
->sp_r_a_tov
;
652 ln
->ln_sparm
.csp
.sp_e_d_tov
= csp
->sp_e_d_tov
;
654 /* Copy word 0 & word 1 of class sparam */
655 clsp
= (struct fc_els_cssp
*)rsp
->clsp_word_0_1
;
656 ln
->ln_sparm
.clsp
[2].cp_class
= clsp
->cp_class
;
657 ln
->ln_sparm
.clsp
[2].cp_init
= clsp
->cp_init
;
658 ln
->ln_sparm
.clsp
[2].cp_recip
= clsp
->cp_recip
;
659 ln
->ln_sparm
.clsp
[2].cp_rdfs
= clsp
->cp_rdfs
;
661 spin_unlock_irq(&hw
->lock
);
663 mempool_free(mbp
, hw
->mb_mempool
);
665 /* Send an event to update local attribs */
666 csio_lnode_async_event(ln
, CSIO_LN_FC_ATTRIB_UPDATE
);
670 * csio_ln_vnp_read - Read vnp params.
672 * @cbfn: Completion handler.
674 * Issued with lock held.
677 csio_ln_vnp_read(struct csio_lnode
*ln
,
678 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
680 struct csio_hw
*hw
= ln
->hwp
;
683 /* Allocate Mbox request */
684 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
686 CSIO_INC_STATS(hw
, n_err_nomem
);
690 /* Prepare VNP Command */
691 csio_fcoe_vnp_read_init_mb(ln
, mbp
,
698 if (csio_mb_issue(hw
, mbp
)) {
699 csio_err(hw
, "Failed to issue mbox FCoE VNP command\n");
700 mempool_free(mbp
, hw
->mb_mempool
);
708 * csio_fcoe_enable_link - Enable fcoe link.
710 * @enable: enable/disable
711 * Issued with lock held.
712 * Issues mbox cmd to bring up FCOE link on port associated with given ln.
715 csio_fcoe_enable_link(struct csio_lnode
*ln
, bool enable
)
717 struct csio_hw
*hw
= ln
->hwp
;
719 enum fw_retval retval
;
722 struct fw_fcoe_link_cmd
*lcmd
;
725 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
727 CSIO_INC_STATS(hw
, n_err_nomem
);
732 sub_op
= enable
? FCOE_LINK_UP
: FCOE_LINK_DOWN
;
734 csio_dbg(hw
, "bringing FCOE LINK %s on Port:%d\n",
735 sub_op
? "UP" : "DOWN", portid
);
737 csio_write_fcoe_link_cond_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
738 portid
, sub_op
, 0, 0, 0, NULL
);
740 if (csio_mb_issue(hw
, mbp
)) {
741 csio_err(hw
, "failed to issue FCOE LINK cmd on port[%d]\n",
743 mempool_free(mbp
, hw
->mb_mempool
);
747 retval
= csio_mb_fw_retval(mbp
);
748 if (retval
!= FW_SUCCESS
) {
750 "FCOE LINK %s cmd on port[%d] failed with "
751 "ret:x%x\n", sub_op
? "UP" : "DOWN", portid
, retval
);
752 mempool_free(mbp
, hw
->mb_mempool
);
759 lcmd
= (struct fw_fcoe_link_cmd
*)mbp
->mb
;
761 memcpy(csio_ln_wwnn(ln
), lcmd
->vnport_wwnn
, 8);
762 memcpy(csio_ln_wwpn(ln
), lcmd
->vnport_wwpn
, 8);
764 for (i
= 0; i
< CSIO_MAX_PPORTS
; i
++)
765 if (hw
->pport
[i
].portid
== portid
)
766 memcpy(hw
->pport
[i
].mac
, lcmd
->phy_mac
, 6);
769 mempool_free(mbp
, hw
->mb_mempool
);
774 * csio_ln_read_fcf_cbfn - Read fcf parameters
777 * read fcf response and Update ln fcf information.
780 csio_ln_read_fcf_cbfn(struct csio_hw
*hw
, struct csio_mb
*mbp
)
782 struct csio_lnode
*ln
= (struct csio_lnode
*)mbp
->priv
;
783 struct csio_fcf_info
*fcf_info
;
784 struct fw_fcoe_fcf_cmd
*rsp
=
785 (struct fw_fcoe_fcf_cmd
*)(mbp
->mb
);
786 enum fw_retval retval
;
788 retval
= FW_CMD_RETVAL_G(ntohl(rsp
->retval_len16
));
789 if (retval
!= FW_SUCCESS
) {
790 csio_ln_err(ln
, "FCOE FCF cmd failed with ret x%x\n",
792 mempool_free(mbp
, hw
->mb_mempool
);
796 spin_lock_irq(&hw
->lock
);
797 fcf_info
= ln
->fcfinfo
;
798 fcf_info
->priority
= FW_FCOE_FCF_CMD_PRIORITY_GET(
799 ntohs(rsp
->priority_pkd
));
800 fcf_info
->vf_id
= ntohs(rsp
->vf_id
);
801 fcf_info
->vlan_id
= rsp
->vlan_id
;
802 fcf_info
->max_fcoe_size
= ntohs(rsp
->max_fcoe_size
);
803 fcf_info
->fka_adv
= be32_to_cpu(rsp
->fka_adv
);
804 fcf_info
->fcfi
= FW_FCOE_FCF_CMD_FCFI_GET(ntohl(rsp
->op_to_fcfi
));
805 fcf_info
->fpma
= FW_FCOE_FCF_CMD_FPMA_GET(rsp
->fpma_to_portid
);
806 fcf_info
->spma
= FW_FCOE_FCF_CMD_SPMA_GET(rsp
->fpma_to_portid
);
807 fcf_info
->login
= FW_FCOE_FCF_CMD_LOGIN_GET(rsp
->fpma_to_portid
);
808 fcf_info
->portid
= FW_FCOE_FCF_CMD_PORTID_GET(rsp
->fpma_to_portid
);
809 memcpy(fcf_info
->fc_map
, rsp
->fc_map
, sizeof(fcf_info
->fc_map
));
810 memcpy(fcf_info
->mac
, rsp
->mac
, sizeof(fcf_info
->mac
));
811 memcpy(fcf_info
->name_id
, rsp
->name_id
, sizeof(fcf_info
->name_id
));
812 memcpy(fcf_info
->fabric
, rsp
->fabric
, sizeof(fcf_info
->fabric
));
813 memcpy(fcf_info
->spma_mac
, rsp
->spma_mac
, sizeof(fcf_info
->spma_mac
));
815 spin_unlock_irq(&hw
->lock
);
817 mempool_free(mbp
, hw
->mb_mempool
);
821 * csio_ln_read_fcf_entry - Read fcf entry.
823 * @cbfn: Completion handler.
825 * Issued with lock held.
828 csio_ln_read_fcf_entry(struct csio_lnode
*ln
,
829 void (*cbfn
) (struct csio_hw
*, struct csio_mb
*))
831 struct csio_hw
*hw
= ln
->hwp
;
834 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
836 CSIO_INC_STATS(hw
, n_err_nomem
);
840 /* Get FCoE FCF information */
841 csio_fcoe_read_fcf_init_mb(ln
, mbp
, CSIO_MB_DEFAULT_TMO
,
842 ln
->portid
, ln
->fcf_flowid
, cbfn
);
844 if (csio_mb_issue(hw
, mbp
)) {
845 csio_err(hw
, "failed to issue FCOE FCF cmd\n");
846 mempool_free(mbp
, hw
->mb_mempool
);
854 * csio_handle_link_up - Logical Linkup event.
856 * @portid - Physical port number
861 * This event is received from FW, when virtual link is established between
862 * Physical port[ENode] and FCF. If its new vnpi, then local node object is
863 * created on this FCF and set to [ONLINE] state.
864 * Lnode waits for FW_RDEV_CMD event to be received indicating that
865 * Fabric login is completed and lnode moves to [READY] state.
867 * This called with hw lock held
870 csio_handle_link_up(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
873 struct csio_lnode
*ln
= NULL
;
875 /* Lookup lnode based on vnpi */
876 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
878 /* Pick lnode based on portid */
879 ln
= csio_ln_lookup_by_portid(hw
, portid
);
881 csio_err(hw
, "failed to lookup fcoe lnode on port:%d\n",
887 /* Check if lnode has valid vnp flowid */
888 if (ln
->vnp_flowid
!= CSIO_INVALID_IDX
) {
890 spin_unlock_irq(&hw
->lock
);
891 csio_lnode_alloc(hw
);
892 spin_lock_irq(&hw
->lock
);
895 "failed to allocate fcoe lnode"
896 "for port:%d vnpi:x%x\n",
903 ln
->vnp_flowid
= vnpi
;
904 ln
->dev_num
&= ~0xFFFF;
909 ln
->fcf_flowid
= fcfi
;
911 csio_info(hw
, "Port:%d - FCOE LINK UP\n", portid
);
913 CSIO_INC_STATS(ln
, n_link_up
);
915 /* Send LINKUP event to SM */
916 csio_post_event(&ln
->sm
, CSIO_LNE_LINKUP
);
920 * csio_post_event_rns
922 * @evt - Given rnode event
925 * Posts given rnode event to all FCOE rnodes connected with given Lnode.
926 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
929 * This called with hw lock held
932 csio_post_event_rns(struct csio_lnode
*ln
, enum csio_rn_ev evt
)
934 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
935 struct list_head
*tmp
, *next
;
936 struct csio_rnode
*rn
;
938 list_for_each_safe(tmp
, next
, &rnhead
->sm
.sm_list
) {
939 rn
= (struct csio_rnode
*) tmp
;
940 csio_post_event(&rn
->sm
, evt
);
949 * Frees all FCOE rnodes connected with given Lnode.
951 * This called with hw lock held
954 csio_cleanup_rns(struct csio_lnode
*ln
)
956 struct csio_rnode
*rnhead
= (struct csio_rnode
*) &ln
->rnhead
;
957 struct list_head
*tmp
, *next_rn
;
958 struct csio_rnode
*rn
;
960 list_for_each_safe(tmp
, next_rn
, &rnhead
->sm
.sm_list
) {
961 rn
= (struct csio_rnode
*) tmp
;
962 csio_put_rnode(ln
, rn
);
968 * csio_post_event_lns
970 * @evt - Given lnode event
973 * Posts given lnode event to all FCOE lnodes connected with given Lnode.
974 * This routine is invoked when lnode receives LINK_DOWN/DOWN_LINK/CLOSE
977 * This called with hw lock held
980 csio_post_event_lns(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
982 struct list_head
*tmp
;
983 struct csio_lnode
*cln
, *sln
;
985 /* If NPIV lnode, send evt only to that and return */
986 if (csio_is_npiv_ln(ln
)) {
987 csio_post_event(&ln
->sm
, evt
);
992 /* Traverse children lnodes list and send evt */
993 list_for_each(tmp
, &sln
->cln_head
) {
994 cln
= (struct csio_lnode
*) tmp
;
995 csio_post_event(&cln
->sm
, evt
);
998 /* Send evt to parent lnode */
999 csio_post_event(&ln
->sm
, evt
);
1003 * csio_ln_down - Lcoal nport is down
1007 * Sends LINK_DOWN events to Lnode and its associated NPIVs lnodes.
1009 * This called with hw lock held
1012 csio_ln_down(struct csio_lnode
*ln
)
1014 csio_post_event_lns(ln
, CSIO_LNE_LINK_DOWN
);
1018 * csio_handle_link_down - Logical Linkdown event.
1020 * @portid - Physical port number
1021 * @fcfi - FCF index.
1022 * @vnpi - VNP index.
1025 * This event is received from FW, when virtual link goes down between
1026 * Physical port[ENode] and FCF. Lnode and its associated NPIVs lnode hosted on
1027 * this vnpi[VN-Port] will be de-instantiated.
1029 * This called with hw lock held
1032 csio_handle_link_down(struct csio_hw
*hw
, uint8_t portid
, uint32_t fcfi
,
1035 struct csio_fcf_info
*fp
;
1036 struct csio_lnode
*ln
;
1038 /* Lookup lnode based on vnpi */
1039 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1042 CSIO_INC_STATS(ln
, n_link_down
);
1044 /*Warn if linkdown received if lnode is not in ready state */
1045 if (!csio_is_lnode_ready(ln
)) {
1047 "warn: FCOE link is already in offline "
1048 "Ignoring Fcoe linkdown event on portid %d\n",
1050 CSIO_INC_STATS(ln
, n_evt_drop
);
1055 if (fp
->portid
!= portid
) {
1057 "warn: FCOE linkdown recv with "
1058 "invalid port %d\n", portid
);
1059 CSIO_INC_STATS(ln
, n_evt_drop
);
1064 if (ln
->fcf_flowid
!= fcfi
) {
1066 "warn: FCOE linkdown recv with "
1067 "invalid fcfi x%x\n", fcfi
);
1068 CSIO_INC_STATS(ln
, n_evt_drop
);
1072 csio_info(hw
, "Port:%d - FCOE LINK DOWN\n", portid
);
1074 /* Send LINK_DOWN event to lnode s/m */
1080 "warn: FCOE linkdown recv with invalid vnpi x%x\n",
1082 CSIO_INC_STATS(hw
, n_evt_drop
);
1087 * csio_is_lnode_ready - Checks FCOE lnode is in ready state.
1090 * Returns True if FCOE lnode is in ready state.
1093 csio_is_lnode_ready(struct csio_lnode
*ln
)
1095 return (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
));
1098 /*****************************************************************************/
1099 /* START: Lnode SM */
1100 /*****************************************************************************/
1102 * csio_lns_uninit - The request in uninit state.
1104 * @evt - Event to be processed.
1106 * Process the given lnode event which is currently in "uninit" state.
1107 * Invoked with HW lock held.
1111 csio_lns_uninit(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1113 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1114 struct csio_lnode
*rln
= hw
->rln
;
1117 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1119 case CSIO_LNE_LINKUP
:
1120 csio_set_state(&ln
->sm
, csio_lns_online
);
1121 /* Read FCF only for physical lnode */
1122 if (csio_is_phys_ln(ln
)) {
1123 rv
= csio_ln_read_fcf_entry(ln
,
1124 csio_ln_read_fcf_cbfn
);
1126 /* TODO: Send HW RESET event */
1127 CSIO_INC_STATS(ln
, n_err
);
1131 /* Add FCF record */
1132 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1135 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1137 /* TODO: Send HW RESET event */
1138 CSIO_INC_STATS(ln
, n_err
);
1142 case CSIO_LNE_DOWN_LINK
:
1147 "unexp ln event %d recv from did:x%x in "
1148 "ln state[uninit].\n", evt
, ln
->nport_id
);
1149 CSIO_INC_STATS(ln
, n_evt_unexp
);
1151 } /* switch event */
1155 * csio_lns_online - The request in online state.
1157 * @evt - Event to be processed.
1159 * Process the given lnode event which is currently in "online" state.
1160 * Invoked with HW lock held.
1164 csio_lns_online(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1166 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1168 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1170 case CSIO_LNE_LINKUP
:
1172 "warn: FCOE link is up already "
1173 "Ignoring linkup on port:%d\n", ln
->portid
);
1174 CSIO_INC_STATS(ln
, n_evt_drop
);
1177 case CSIO_LNE_FAB_INIT_DONE
:
1178 csio_set_state(&ln
->sm
, csio_lns_ready
);
1180 spin_unlock_irq(&hw
->lock
);
1181 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKUP
);
1182 spin_lock_irq(&hw
->lock
);
1186 case CSIO_LNE_LINK_DOWN
:
1188 case CSIO_LNE_DOWN_LINK
:
1189 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1190 if (csio_is_phys_ln(ln
)) {
1191 /* Remove FCF entry */
1192 list_del_init(&ln
->fcfinfo
->list
);
1198 "unexp ln event %d recv from did:x%x in "
1199 "ln state[uninit].\n", evt
, ln
->nport_id
);
1200 CSIO_INC_STATS(ln
, n_evt_unexp
);
1203 } /* switch event */
1207 * csio_lns_ready - The request in ready state.
1209 * @evt - Event to be processed.
1211 * Process the given lnode event which is currently in "ready" state.
1212 * Invoked with HW lock held.
1216 csio_lns_ready(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1218 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1220 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1222 case CSIO_LNE_FAB_INIT_DONE
:
1224 "ignoring event %d recv from did x%x"
1225 "in ln state[ready].\n", evt
, ln
->nport_id
);
1226 CSIO_INC_STATS(ln
, n_evt_drop
);
1229 case CSIO_LNE_LINK_DOWN
:
1230 csio_set_state(&ln
->sm
, csio_lns_offline
);
1231 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1233 spin_unlock_irq(&hw
->lock
);
1234 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1235 spin_lock_irq(&hw
->lock
);
1237 if (csio_is_phys_ln(ln
)) {
1238 /* Remove FCF entry */
1239 list_del_init(&ln
->fcfinfo
->list
);
1243 case CSIO_LNE_DOWN_LINK
:
1244 csio_set_state(&ln
->sm
, csio_lns_offline
);
1245 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1247 /* Host need to issue aborts in case if FW has not returned
1248 * WRs with status "ABORTED"
1250 spin_unlock_irq(&hw
->lock
);
1251 csio_lnode_async_event(ln
, CSIO_LN_FC_LINKDOWN
);
1252 spin_lock_irq(&hw
->lock
);
1254 if (csio_is_phys_ln(ln
)) {
1255 /* Remove FCF entry */
1256 list_del_init(&ln
->fcfinfo
->list
);
1260 case CSIO_LNE_CLOSE
:
1261 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1262 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1266 csio_set_state(&ln
->sm
, csio_lns_offline
);
1267 csio_post_event_rns(ln
, CSIO_RNFE_DOWN
);
1272 "unexp ln event %d recv from did:x%x in "
1273 "ln state[uninit].\n", evt
, ln
->nport_id
);
1274 CSIO_INC_STATS(ln
, n_evt_unexp
);
1277 } /* switch event */
1281 * csio_lns_offline - The request in offline state.
1283 * @evt - Event to be processed.
1285 * Process the given lnode event which is currently in "offline" state.
1286 * Invoked with HW lock held.
1290 csio_lns_offline(struct csio_lnode
*ln
, enum csio_ln_ev evt
)
1292 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1293 struct csio_lnode
*rln
= hw
->rln
;
1296 CSIO_INC_STATS(ln
, n_evt_sm
[evt
]);
1298 case CSIO_LNE_LINKUP
:
1299 csio_set_state(&ln
->sm
, csio_lns_online
);
1300 /* Read FCF only for physical lnode */
1301 if (csio_is_phys_ln(ln
)) {
1302 rv
= csio_ln_read_fcf_entry(ln
,
1303 csio_ln_read_fcf_cbfn
);
1305 /* TODO: Send HW RESET event */
1306 CSIO_INC_STATS(ln
, n_err
);
1310 /* Add FCF record */
1311 list_add_tail(&ln
->fcfinfo
->list
, &rln
->fcf_lsthead
);
1314 rv
= csio_ln_vnp_read(ln
, csio_ln_vnp_read_cbfn
);
1316 /* TODO: Send HW RESET event */
1317 CSIO_INC_STATS(ln
, n_err
);
1321 case CSIO_LNE_LINK_DOWN
:
1322 case CSIO_LNE_DOWN_LINK
:
1325 "ignoring event %d recv from did x%x"
1326 "in ln state[offline].\n", evt
, ln
->nport_id
);
1327 CSIO_INC_STATS(ln
, n_evt_drop
);
1330 case CSIO_LNE_CLOSE
:
1331 csio_set_state(&ln
->sm
, csio_lns_uninit
);
1332 csio_post_event_rns(ln
, CSIO_RNFE_CLOSE
);
1337 "unexp ln event %d recv from did:x%x in "
1338 "ln state[offline]\n", evt
, ln
->nport_id
);
1339 CSIO_INC_STATS(ln
, n_evt_unexp
);
1342 } /* switch event */
1345 /*****************************************************************************/
1347 /*****************************************************************************/
1350 csio_free_fcfinfo(struct kref
*kref
)
1352 struct csio_fcf_info
*fcfinfo
= container_of(kref
,
1353 struct csio_fcf_info
, kref
);
1357 /* Helper routines for attributes */
1359 * csio_lnode_state_to_str - Get current state of FCOE lnode.
1361 * @str - state of lnode.
1365 csio_lnode_state_to_str(struct csio_lnode
*ln
, int8_t *str
)
1367 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_uninit
)) {
1368 strcpy(str
, "UNINIT");
1371 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_ready
)) {
1372 strcpy(str
, "READY");
1375 if (csio_get_state(ln
) == ((csio_sm_state_t
)csio_lns_offline
)) {
1376 strcpy(str
, "OFFLINE");
1379 strcpy(str
, "UNKNOWN");
1380 } /* csio_lnode_state_to_str */
1384 csio_get_phy_port_stats(struct csio_hw
*hw
, uint8_t portid
,
1385 struct fw_fcoe_port_stats
*port_stats
)
1387 struct csio_mb
*mbp
;
1388 struct fw_fcoe_port_cmd_params portparams
;
1389 enum fw_retval retval
;
1392 mbp
= mempool_alloc(hw
->mb_mempool
, GFP_ATOMIC
);
1394 csio_err(hw
, "FCoE FCF PARAMS command out of memory!\n");
1397 portparams
.portid
= portid
;
1399 for (idx
= 1; idx
<= 3; idx
++) {
1400 portparams
.idx
= (idx
-1)*6 + 1;
1401 portparams
.nstats
= 6;
1403 portparams
.nstats
= 4;
1404 csio_fcoe_read_portparams_init_mb(hw
, mbp
, CSIO_MB_DEFAULT_TMO
,
1406 if (csio_mb_issue(hw
, mbp
)) {
1407 csio_err(hw
, "Issue of FCoE port params failed!\n");
1408 mempool_free(mbp
, hw
->mb_mempool
);
1411 csio_mb_process_portparams_rsp(hw
, mbp
, &retval
,
1412 &portparams
, port_stats
);
1415 mempool_free(mbp
, hw
->mb_mempool
);
1420 * csio_ln_mgmt_wr_handler -Mgmt Work Request handler.
1423 * This handler is invoked when an outstanding mgmt WR is completed.
1424 * Its invoked in the context of FW event worker thread for every
1425 * mgmt event received.
1430 csio_ln_mgmt_wr_handler(struct csio_hw
*hw
, void *wr
, uint32_t len
)
1432 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1433 struct csio_ioreq
*io_req
= NULL
;
1434 struct fw_fcoe_els_ct_wr
*wr_cmd
;
1437 wr_cmd
= (struct fw_fcoe_els_ct_wr
*) wr
;
1439 if (len
< sizeof(struct fw_fcoe_els_ct_wr
)) {
1441 "Invalid ELS CT WR length recvd, len:%x\n", len
);
1442 mgmtm
->stats
.n_err
++;
1446 io_req
= (struct csio_ioreq
*) ((uintptr_t) wr_cmd
->cookie
);
1447 io_req
->wr_status
= csio_wr_status(wr_cmd
);
1449 /* lookup ioreq exists in our active Q */
1450 spin_lock_irq(&hw
->lock
);
1451 if (csio_mgmt_req_lookup(mgmtm
, io_req
) != 0) {
1453 "Error- Invalid IO handle recv in WR. handle: %p\n",
1455 mgmtm
->stats
.n_err
++;
1456 spin_unlock_irq(&hw
->lock
);
1460 mgmtm
= csio_hw_to_mgmtm(hw
);
1462 /* Dequeue from active queue */
1463 list_del_init(&io_req
->sm
.sm_list
);
1464 mgmtm
->stats
.n_active
--;
1465 spin_unlock_irq(&hw
->lock
);
1467 /* io_req will be freed by completion handler */
1468 if (io_req
->io_cbfn
)
1469 io_req
->io_cbfn(hw
, io_req
);
1473 * csio_fcoe_fwevt_handler - Event handler for Firmware FCoE events.
1475 * @cpl_op: CPL opcode
1478 * Process received FCoE cmd/WR event from FW.
1481 csio_fcoe_fwevt_handler(struct csio_hw
*hw
, __u8 cpl_op
, __be64
*cmd
)
1483 struct csio_lnode
*ln
;
1484 struct csio_rnode
*rn
;
1485 uint8_t portid
, opcode
= *(uint8_t *)cmd
;
1486 struct fw_fcoe_link_cmd
*lcmd
;
1487 struct fw_wr_hdr
*wr
;
1488 struct fw_rdev_wr
*rdev_wr
;
1489 enum fw_fcoe_link_status lstatus
;
1490 uint32_t fcfi
, rdev_flowid
, vnpi
;
1491 enum csio_ln_ev evt
;
1493 if (cpl_op
== CPL_FW6_MSG
&& opcode
== FW_FCOE_LINK_CMD
) {
1495 lcmd
= (struct fw_fcoe_link_cmd
*)cmd
;
1496 lstatus
= lcmd
->lstatus
;
1497 portid
= FW_FCOE_LINK_CMD_PORTID_GET(
1498 ntohl(lcmd
->op_to_portid
));
1499 fcfi
= FW_FCOE_LINK_CMD_FCFI_GET(ntohl(lcmd
->sub_opcode_fcfi
));
1500 vnpi
= FW_FCOE_LINK_CMD_VNPI_GET(ntohl(lcmd
->vnpi_pkd
));
1502 if (lstatus
== FCOE_LINKUP
) {
1505 spin_lock_irq(&hw
->lock
);
1506 csio_handle_link_up(hw
, portid
, fcfi
, vnpi
);
1507 spin_unlock_irq(&hw
->lock
);
1508 /* HW un lock here */
1510 } else if (lstatus
== FCOE_LINKDOWN
) {
1513 spin_lock_irq(&hw
->lock
);
1514 csio_handle_link_down(hw
, portid
, fcfi
, vnpi
);
1515 spin_unlock_irq(&hw
->lock
);
1516 /* HW un lock here */
1518 csio_warn(hw
, "Unexpected FCOE LINK status:0x%x\n",
1520 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1522 } else if (cpl_op
== CPL_FW6_PLD
) {
1523 wr
= (struct fw_wr_hdr
*) (cmd
+ 4);
1524 if (FW_WR_OP_G(be32_to_cpu(wr
->hi
))
1527 rdev_wr
= (struct fw_rdev_wr
*) (cmd
+ 4);
1529 rdev_flowid
= FW_RDEV_WR_FLOWID_GET(
1530 ntohl(rdev_wr
->alloc_to_len16
));
1531 vnpi
= FW_RDEV_WR_ASSOC_FLOWID_GET(
1532 ntohl(rdev_wr
->flags_to_assoc_flowid
));
1535 "FW_RDEV_WR: flowid:x%x ev_cause:x%x "
1536 "vnpi:0x%x\n", rdev_flowid
,
1537 rdev_wr
->event_cause
, vnpi
);
1539 if (rdev_wr
->protocol
!= PROT_FCOE
) {
1541 "FW_RDEV_WR: invalid proto:x%x "
1542 "received with flowid:x%x\n",
1545 CSIO_INC_STATS(hw
, n_evt_drop
);
1550 spin_lock_irq(&hw
->lock
);
1551 ln
= csio_ln_lookup_by_vnpi(hw
, vnpi
);
1554 "FW_DEV_WR: invalid vnpi:x%x received "
1555 "with flowid:x%x\n", vnpi
, rdev_flowid
);
1556 CSIO_INC_STATS(hw
, n_evt_drop
);
1560 rn
= csio_confirm_rnode(ln
, rdev_flowid
,
1561 &rdev_wr
->u
.fcoe_rdev
);
1564 "Failed to confirm rnode "
1565 "for flowid:x%x\n", rdev_flowid
);
1566 CSIO_INC_STATS(hw
, n_evt_drop
);
1570 /* save previous event for debugging */
1571 ln
->prev_evt
= ln
->cur_evt
;
1572 ln
->cur_evt
= rdev_wr
->event_cause
;
1573 CSIO_INC_STATS(ln
, n_evt_fw
[rdev_wr
->event_cause
]);
1575 /* Translate all the fabric events to lnode SM events */
1576 evt
= CSIO_FWE_TO_LNE(rdev_wr
->event_cause
);
1579 "Posting event to lnode event:%d "
1580 "cause:%d flowid:x%x\n", evt
,
1581 rdev_wr
->event_cause
, rdev_flowid
);
1582 csio_post_event(&ln
->sm
, evt
);
1585 /* Handover event to rn SM here. */
1586 csio_rnode_fwevt_handler(rn
, rdev_wr
->event_cause
);
1588 spin_unlock_irq(&hw
->lock
);
1591 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1592 FW_WR_OP_G(be32_to_cpu((wr
->hi
))));
1593 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1595 } else if (cpl_op
== CPL_FW6_MSG
) {
1596 wr
= (struct fw_wr_hdr
*) (cmd
);
1597 if (FW_WR_OP_G(be32_to_cpu(wr
->hi
)) == FW_FCOE_ELS_CT_WR
) {
1598 csio_ln_mgmt_wr_handler(hw
, wr
,
1599 sizeof(struct fw_fcoe_els_ct_wr
));
1601 csio_warn(hw
, "unexpected WR op(0x%x) recv\n",
1602 FW_WR_OP_G(be32_to_cpu((wr
->hi
))));
1603 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1606 csio_warn(hw
, "unexpected CPL op(0x%x) recv\n", opcode
);
1607 CSIO_INC_STATS(hw
, n_cpl_unexp
);
1612 * csio_lnode_start - Kickstart lnode discovery.
1615 * This routine kickstarts the discovery by issuing an FCOE_LINK (up) command.
1618 csio_lnode_start(struct csio_lnode
*ln
)
1621 if (csio_is_phys_ln(ln
) && !(ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1622 rv
= csio_fcoe_enable_link(ln
, 1);
1623 ln
->flags
|= CSIO_LNF_LINK_ENABLE
;
1630 * csio_lnode_stop - Stop the lnode.
1633 * This routine is invoked by HW module to stop lnode and its associated NPIV
1637 csio_lnode_stop(struct csio_lnode
*ln
)
1639 csio_post_event_lns(ln
, CSIO_LNE_DOWN_LINK
);
1640 if (csio_is_phys_ln(ln
) && (ln
->flags
& CSIO_LNF_LINK_ENABLE
)) {
1641 csio_fcoe_enable_link(ln
, 0);
1642 ln
->flags
&= ~CSIO_LNF_LINK_ENABLE
;
1644 csio_ln_dbg(ln
, "stopping ln :%p\n", ln
);
1648 * csio_lnode_close - Close an lnode.
1651 * This routine is invoked by HW module to close an lnode and its
1652 * associated NPIV lnodes. Lnode and its associated NPIV lnodes are
1653 * set to uninitialized state.
1656 csio_lnode_close(struct csio_lnode
*ln
)
1658 csio_post_event_lns(ln
, CSIO_LNE_CLOSE
);
1659 if (csio_is_phys_ln(ln
))
1660 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1662 csio_ln_dbg(ln
, "closed ln :%p\n", ln
);
1666 * csio_ln_prep_ecwr - Prepare ELS/CT WR.
1667 * @io_req - IO request.
1669 * @immd_len - WR immediate data
1670 * @sub_op - Sub opcode
1671 * @sid - source portid.
1672 * @did - destination portid
1674 * @fw_wr - ELS/CT WR to be prepared.
1675 * Returns: 0 - on success
1678 csio_ln_prep_ecwr(struct csio_ioreq
*io_req
, uint32_t wr_len
,
1679 uint32_t immd_len
, uint8_t sub_op
, uint32_t sid
,
1680 uint32_t did
, uint32_t flow_id
, uint8_t *fw_wr
)
1682 struct fw_fcoe_els_ct_wr
*wr
;
1685 wr
= (struct fw_fcoe_els_ct_wr
*)fw_wr
;
1686 wr
->op_immdlen
= cpu_to_be32(FW_WR_OP_V(FW_FCOE_ELS_CT_WR
) |
1687 FW_FCOE_ELS_CT_WR_IMMDLEN(immd_len
));
1689 wr_len
= DIV_ROUND_UP(wr_len
, 16);
1690 wr
->flowid_len16
= cpu_to_be32(FW_WR_FLOWID_V(flow_id
) |
1691 FW_WR_LEN16_V(wr_len
));
1692 wr
->els_ct_type
= sub_op
;
1694 wr
->cp_en_class
= 0;
1695 wr
->cookie
= io_req
->fw_handle
;
1696 wr
->iqid
= cpu_to_be16(csio_q_physiqid(
1697 io_req
->lnode
->hwp
, io_req
->iq_idx
));
1698 wr
->fl_to_sp
= FW_FCOE_ELS_CT_WR_SP(1);
1699 wr
->tmo_val
= (uint8_t) io_req
->tmo
;
1700 port_id
= htonl(sid
);
1701 memcpy(wr
->l_id
, PORT_ID_PTR(port_id
), 3);
1702 port_id
= htonl(did
);
1703 memcpy(wr
->r_id
, PORT_ID_PTR(port_id
), 3);
1705 /* Prepare RSP SGL */
1706 wr
->rsp_dmalen
= cpu_to_be32(io_req
->dma_buf
.len
);
1707 wr
->rsp_dmaaddr
= cpu_to_be64(io_req
->dma_buf
.paddr
);
1712 * csio_ln_mgmt_submit_wr - Post elsct work request.
1714 * @io_req - io request.
1715 * @sub_op - ELS or CT request type
1716 * @pld - Dma Payload buffer
1717 * @pld_len - Payload len
1718 * Prepares ELSCT Work request and sents it to FW.
1719 * Returns: 0 - on success
1722 csio_ln_mgmt_submit_wr(struct csio_mgmtm
*mgmtm
, struct csio_ioreq
*io_req
,
1723 uint8_t sub_op
, struct csio_dma_buf
*pld
,
1726 struct csio_wr_pair wrp
;
1727 struct csio_lnode
*ln
= io_req
->lnode
;
1728 struct csio_rnode
*rn
= io_req
->rnode
;
1729 struct csio_hw
*hw
= mgmtm
->hw
;
1731 struct ulptx_sgl dsgl
;
1732 uint32_t wr_size
= 0;
1734 uint32_t wr_off
= 0;
1738 /* Calculate WR Size for this ELS REQ */
1739 wr_size
= sizeof(struct fw_fcoe_els_ct_wr
);
1741 /* Send as immediate data if pld < 256 */
1742 if (pld_len
< 256) {
1743 wr_size
+= ALIGN(pld_len
, 8);
1744 im_len
= (uint8_t)pld_len
;
1746 wr_size
+= sizeof(struct ulptx_sgl
);
1748 /* Roundup WR size in units of 16 bytes */
1749 wr_size
= ALIGN(wr_size
, 16);
1751 /* Get WR to send ELS REQ */
1752 ret
= csio_wr_get(hw
, mgmtm
->eq_idx
, wr_size
, &wrp
);
1754 csio_err(hw
, "Failed to get WR for ec_req %p ret:%d\n",
1759 /* Prepare Generic WR used by all ELS/CT cmd */
1760 csio_ln_prep_ecwr(io_req
, wr_size
, im_len
, sub_op
,
1761 ln
->nport_id
, rn
->nport_id
,
1765 /* Copy ELS/CT WR CMD */
1766 csio_wr_copy_to_wrp(&fw_wr
[0], &wrp
, wr_off
,
1767 sizeof(struct fw_fcoe_els_ct_wr
));
1768 wr_off
+= sizeof(struct fw_fcoe_els_ct_wr
);
1770 /* Copy payload to Immediate section of WR */
1772 csio_wr_copy_to_wrp(pld
->vaddr
, &wrp
, wr_off
, im_len
);
1774 /* Program DSGL to dma payload */
1775 dsgl
.cmd_nsge
= htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL
) |
1776 ULPTX_MORE_F
| ULPTX_NSGE_V(1));
1777 dsgl
.len0
= cpu_to_be32(pld_len
);
1778 dsgl
.addr0
= cpu_to_be64(pld
->paddr
);
1779 csio_wr_copy_to_wrp(&dsgl
, &wrp
, ALIGN(wr_off
, 8),
1780 sizeof(struct ulptx_sgl
));
1783 /* Issue work request to xmit ELS/CT req to FW */
1784 csio_wr_issue(mgmtm
->hw
, mgmtm
->eq_idx
, false);
1789 * csio_ln_mgmt_submit_req - Submit FCOE Mgmt request.
1790 * @io_req - IO Request
1791 * @io_cbfn - Completion handler.
1792 * @req_type - ELS or CT request type
1793 * @pld - Dma Payload buffer
1794 * @pld_len - Payload len
1797 * This API used submit managment ELS/CT request.
1798 * This called with hw lock held
1799 * Returns: 0 - on success
1800 * -ENOMEM - on error.
1803 csio_ln_mgmt_submit_req(struct csio_ioreq
*io_req
,
1804 void (*io_cbfn
) (struct csio_hw
*, struct csio_ioreq
*),
1805 enum fcoe_cmn_type req_type
, struct csio_dma_buf
*pld
,
1808 struct csio_hw
*hw
= csio_lnode_to_hw(io_req
->lnode
);
1809 struct csio_mgmtm
*mgmtm
= csio_hw_to_mgmtm(hw
);
1812 BUG_ON(pld_len
> pld
->len
);
1814 io_req
->io_cbfn
= io_cbfn
; /* Upper layer callback handler */
1815 io_req
->fw_handle
= (uintptr_t) (io_req
);
1816 io_req
->eq_idx
= mgmtm
->eq_idx
;
1817 io_req
->iq_idx
= mgmtm
->iq_idx
;
1819 rv
= csio_ln_mgmt_submit_wr(mgmtm
, io_req
, req_type
, pld
, pld_len
);
1821 list_add_tail(&io_req
->sm
.sm_list
, &mgmtm
->active_q
);
1822 mgmtm
->stats
.n_active
++;
1828 * csio_ln_fdmi_init - FDMI Init entry point.
1832 csio_ln_fdmi_init(struct csio_lnode
*ln
)
1834 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1835 struct csio_dma_buf
*dma_buf
;
1837 /* Allocate MGMT request required for FDMI */
1838 ln
->mgmt_req
= kzalloc(sizeof(struct csio_ioreq
), GFP_KERNEL
);
1839 if (!ln
->mgmt_req
) {
1840 csio_ln_err(ln
, "Failed to alloc ioreq for FDMI\n");
1841 CSIO_INC_STATS(hw
, n_err_nomem
);
1845 /* Allocate Dma buffers for FDMI response Payload */
1846 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1847 dma_buf
->len
= 2048;
1848 dma_buf
->vaddr
= pci_alloc_consistent(hw
->pdev
, dma_buf
->len
,
1850 if (!dma_buf
->vaddr
) {
1851 csio_err(hw
, "Failed to alloc DMA buffer for FDMI!\n");
1852 kfree(ln
->mgmt_req
);
1853 ln
->mgmt_req
= NULL
;
1857 ln
->flags
|= CSIO_LNF_FDMI_ENABLE
;
1862 * csio_ln_fdmi_exit - FDMI exit entry point.
1866 csio_ln_fdmi_exit(struct csio_lnode
*ln
)
1868 struct csio_dma_buf
*dma_buf
;
1869 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1874 dma_buf
= &ln
->mgmt_req
->dma_buf
;
1876 pci_free_consistent(hw
->pdev
, dma_buf
->len
, dma_buf
->vaddr
,
1879 kfree(ln
->mgmt_req
);
1884 csio_scan_done(struct csio_lnode
*ln
, unsigned long ticks
,
1885 unsigned long time
, unsigned long max_scan_ticks
,
1886 unsigned long delta_scan_ticks
)
1890 if (time
>= max_scan_ticks
)
1893 if (!ln
->tgt_scan_tick
)
1894 ln
->tgt_scan_tick
= ticks
;
1896 if (((ticks
- ln
->tgt_scan_tick
) >= delta_scan_ticks
)) {
1897 if (!ln
->last_scan_ntgts
)
1898 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1900 if (ln
->last_scan_ntgts
== ln
->n_scsi_tgts
)
1903 ln
->last_scan_ntgts
= ln
->n_scsi_tgts
;
1905 ln
->tgt_scan_tick
= ticks
;
1911 * csio_notify_lnodes:
1913 * @note: Notification
1915 * Called from the HW SM to fan out notifications to the
1916 * Lnode SM. Since the HW SM is entered with lock held,
1917 * there is no need to hold locks here.
1921 csio_notify_lnodes(struct csio_hw
*hw
, enum csio_ln_notify note
)
1923 struct list_head
*tmp
;
1924 struct csio_lnode
*ln
;
1926 csio_dbg(hw
, "Notifying all nodes of event %d\n", note
);
1928 /* Traverse children lnodes list and send evt */
1929 list_for_each(tmp
, &hw
->sln_head
) {
1930 ln
= (struct csio_lnode
*) tmp
;
1933 case CSIO_LN_NOTIFY_HWREADY
:
1934 csio_lnode_start(ln
);
1937 case CSIO_LN_NOTIFY_HWRESET
:
1938 case CSIO_LN_NOTIFY_HWREMOVE
:
1939 csio_lnode_close(ln
);
1942 case CSIO_LN_NOTIFY_HWSTOP
:
1943 csio_lnode_stop(ln
);
1954 * csio_disable_lnodes:
1957 * @disable: disable/enable flag.
1958 * If disable=1, disables all lnode hosted on given physical port.
1959 * otherwise enables all the lnodes on given phsysical port.
1960 * This routine need to called with hw lock held.
1963 csio_disable_lnodes(struct csio_hw
*hw
, uint8_t portid
, bool disable
)
1965 struct list_head
*tmp
;
1966 struct csio_lnode
*ln
;
1968 csio_dbg(hw
, "Notifying event to all nodes of port:%d\n", portid
);
1970 /* Traverse sibling lnodes list and send evt */
1971 list_for_each(tmp
, &hw
->sln_head
) {
1972 ln
= (struct csio_lnode
*) tmp
;
1973 if (ln
->portid
!= portid
)
1977 csio_lnode_stop(ln
);
1979 csio_lnode_start(ln
);
1984 * csio_ln_init - Initialize an lnode.
1989 csio_ln_init(struct csio_lnode
*ln
)
1992 struct csio_lnode
*rln
, *pln
;
1993 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
1995 csio_init_state(&ln
->sm
, csio_lns_uninit
);
1996 ln
->vnp_flowid
= CSIO_INVALID_IDX
;
1997 ln
->fcf_flowid
= CSIO_INVALID_IDX
;
1999 if (csio_is_root_ln(ln
)) {
2001 /* This is the lnode used during initialization */
2003 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
), GFP_KERNEL
);
2005 csio_ln_err(ln
, "Failed to alloc FCF record\n");
2006 CSIO_INC_STATS(hw
, n_err_nomem
);
2010 INIT_LIST_HEAD(&ln
->fcf_lsthead
);
2011 kref_init(&ln
->fcfinfo
->kref
);
2013 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2016 } else { /* Either a non-root physical or a virtual lnode */
2019 * THe rest is common for non-root physical and NPIV lnodes.
2020 * Just get references to all other modules
2022 rln
= csio_root_lnode(ln
);
2024 if (csio_is_npiv_ln(ln
)) {
2026 pln
= csio_parent_lnode(ln
);
2027 kref_get(&pln
->fcfinfo
->kref
);
2028 ln
->fcfinfo
= pln
->fcfinfo
;
2030 /* Another non-root physical lnode (FCF) */
2031 ln
->fcfinfo
= kzalloc(sizeof(struct csio_fcf_info
),
2034 csio_ln_err(ln
, "Failed to alloc FCF info\n");
2035 CSIO_INC_STATS(hw
, n_err_nomem
);
2039 kref_init(&ln
->fcfinfo
->kref
);
2041 if (csio_fdmi_enable
&& csio_ln_fdmi_init(ln
))
2045 } /* if (!csio_is_root_ln(ln)) */
2053 csio_ln_exit(struct csio_lnode
*ln
)
2055 struct csio_lnode
*pln
;
2057 csio_cleanup_rns(ln
);
2058 if (csio_is_npiv_ln(ln
)) {
2059 pln
= csio_parent_lnode(ln
);
2060 kref_put(&pln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2062 kref_put(&ln
->fcfinfo
->kref
, csio_free_fcfinfo
);
2063 if (csio_fdmi_enable
)
2064 csio_ln_fdmi_exit(ln
);
2070 * csio_lnode_init - Initialize the members of an lnode.
2075 csio_lnode_init(struct csio_lnode
*ln
, struct csio_hw
*hw
,
2076 struct csio_lnode
*pln
)
2080 /* Link this lnode to hw */
2081 csio_lnode_to_hw(ln
) = hw
;
2083 /* Link child to parent if child lnode */
2089 /* Initialize scsi_tgt and timers to zero */
2090 ln
->n_scsi_tgts
= 0;
2091 ln
->last_scan_ntgts
= 0;
2092 ln
->tgt_scan_tick
= 0;
2094 /* Initialize rnode list */
2095 INIT_LIST_HEAD(&ln
->rnhead
);
2096 INIT_LIST_HEAD(&ln
->cln_head
);
2098 /* Initialize log level for debug */
2099 ln
->params
.log_level
= hw
->params
.log_level
;
2101 if (csio_ln_init(ln
))
2104 /* Add lnode to list of sibling or children lnodes */
2105 spin_lock_irq(&hw
->lock
);
2106 list_add_tail(&ln
->sm
.sm_list
, pln
? &pln
->cln_head
: &hw
->sln_head
);
2109 spin_unlock_irq(&hw
->lock
);
2115 csio_lnode_to_hw(ln
) = NULL
;
2120 * csio_lnode_exit - De-instantiate an lnode.
2125 csio_lnode_exit(struct csio_lnode
*ln
)
2127 struct csio_hw
*hw
= csio_lnode_to_hw(ln
);
2131 /* Remove this lnode from hw->sln_head */
2132 spin_lock_irq(&hw
->lock
);
2134 list_del_init(&ln
->sm
.sm_list
);
2136 /* If it is children lnode, decrement the
2137 * counter in its parent lnode
2140 ln
->pln
->num_vports
--;
2142 /* Update root lnode pointer */
2143 if (list_empty(&hw
->sln_head
))
2146 hw
->rln
= (struct csio_lnode
*)csio_list_next(&hw
->sln_head
);
2148 spin_unlock_irq(&hw
->lock
);
2150 csio_lnode_to_hw(ln
) = NULL
;