1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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>
46
47#include "csio_hw.h"
48#include "csio_mb.h"
49#include "csio_lnode.h"
50#include "csio_rnode.h"
51
52int csio_fcoe_rnodes = 1024;
53int csio_fdmi_enable = 1;
54
55#define PORT_ID_PTR(_x) ((uint8_t *)(&_x) + 1)
56
57
58static void csio_lns_uninit(struct csio_lnode *, enum csio_ln_ev);
59static void csio_lns_online(struct csio_lnode *, enum csio_ln_ev);
60static void csio_lns_ready(struct csio_lnode *, enum csio_ln_ev);
61static void csio_lns_offline(struct csio_lnode *, enum csio_ln_ev);
62
63static 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);
66
67
68static enum csio_ln_ev fwevt_to_lnevt[] = {
69 CSIO_LNE_NONE,
70 CSIO_LNE_NONE,
71 CSIO_LNE_NONE,
72 CSIO_LNE_NONE,
73 CSIO_LNE_NONE,
74 CSIO_LNE_NONE,
75 CSIO_LNE_NONE,
76 CSIO_LNE_NONE,
77 CSIO_LNE_NONE,
78 CSIO_LNE_NONE,
79 CSIO_LNE_LOGO,
80 CSIO_LNE_LOGO,
81 CSIO_LNE_FAB_INIT_DONE,
82 CSIO_LNE_NONE,
83 CSIO_LNE_FAB_INIT_DONE,
84 CSIO_LNE_NONE,
85 CSIO_LNE_NONE,
86 CSIO_LNE_NONE,
87 CSIO_LNE_NONE,
88 CSIO_LNE_NONE,
89 CSIO_LNE_NONE,
90 CSIO_LNE_NONE,
91 CSIO_LNE_NONE,
92 CSIO_LNE_NONE,
93 CSIO_LNE_NONE,
94 CSIO_LNE_NONE,
95 CSIO_LNE_NONE,
96};
97
98#define CSIO_FWE_TO_LNE(_evt) ((_evt > PROTO_ERR_IMPL_LOGO) ? \
99 CSIO_LNE_NONE : \
100 fwevt_to_lnevt[_evt])
101
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))
106
107
108
109
110
111
112
113
114static struct csio_lnode *
115csio_ln_lookup_by_portid(struct csio_hw *hw, uint8_t portid)
116{
117 struct csio_lnode *ln;
118 struct list_head *tmp;
119
120
121 list_for_each(tmp, &hw->sln_head) {
122 ln = (struct csio_lnode *) tmp;
123 if (ln->portid == portid)
124 return ln;
125 }
126
127 return NULL;
128}
129
130
131
132
133
134
135
136
137static struct csio_lnode *
138csio_ln_lookup_by_vnpi(struct csio_hw *hw, uint32_t vnp_id)
139{
140 struct list_head *tmp1, *tmp2;
141 struct csio_lnode *sln = NULL, *cln = NULL;
142
143 if (list_empty(&hw->sln_head)) {
144 CSIO_INC_STATS(hw, n_lnlkup_miss);
145 return NULL;
146 }
147
148 list_for_each(tmp1, &hw->sln_head) {
149 sln = (struct csio_lnode *) tmp1;
150
151
152 if (sln->vnp_flowid == vnp_id)
153 return sln;
154
155 if (list_empty(&sln->cln_head))
156 continue;
157
158
159 list_for_each(tmp2, &sln->cln_head) {
160 cln = (struct csio_lnode *) tmp2;
161
162 if (cln->vnp_flowid == vnp_id)
163 return cln;
164 }
165 }
166 CSIO_INC_STATS(hw, n_lnlkup_miss);
167 return NULL;
168}
169
170
171
172
173
174
175
176
177struct csio_lnode *
178csio_lnode_lookup_by_wwpn(struct csio_hw *hw, uint8_t *wwpn)
179{
180 struct list_head *tmp1, *tmp2;
181 struct csio_lnode *sln = NULL, *cln = NULL;
182
183 if (list_empty(&hw->sln_head)) {
184 CSIO_INC_STATS(hw, n_lnlkup_miss);
185 return NULL;
186 }
187
188 list_for_each(tmp1, &hw->sln_head) {
189 sln = (struct csio_lnode *) tmp1;
190
191
192 if (!memcmp(csio_ln_wwpn(sln), wwpn, 8))
193 return sln;
194
195 if (list_empty(&sln->cln_head))
196 continue;
197
198
199 list_for_each(tmp2, &sln->cln_head) {
200 cln = (struct csio_lnode *) tmp2;
201
202 if (!memcmp(csio_ln_wwpn(cln), wwpn, 8))
203 return cln;
204 }
205 }
206 return NULL;
207}
208
209
210static void
211csio_fill_ct_iu(void *buf, uint8_t type, uint8_t sub_type, uint16_t op)
212{
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);
218}
219
220static int
221csio_hostname(uint8_t *buf, size_t buf_len)
222{
223 if (snprintf(buf, buf_len, "%s", init_utsname()->nodename) > 0)
224 return 0;
225 return -1;
226}
227
228static int
229csio_osname(uint8_t *buf, size_t buf_len)
230{
231 if (snprintf(buf, buf_len, "%s %s %s",
232 init_utsname()->sysname,
233 init_utsname()->release,
234 init_utsname()->version) > 0)
235 return 0;
236
237 return -1;
238}
239
240static inline void
241csio_append_attrib(uint8_t **ptr, uint16_t type, void *val, size_t val_len)
242{
243 uint16_t len;
244 struct fc_fdmi_attr_entry *ae = (struct fc_fdmi_attr_entry *)*ptr;
245
246 if (WARN_ON(val_len > U16_MAX))
247 return;
248
249 len = val_len;
250
251 ae->type = htons(type);
252 len += 4;
253 len = (len + 3) & ~3;
254 ae->len = htons(len);
255 memcpy(ae->value, val, val_len);
256 if (len > val_len)
257 memset(ae->value + val_len, 0, len - val_len);
258 *ptr += len;
259}
260
261
262
263
264
265
266static void
267csio_ln_fdmi_done(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
268{
269 void *cmd;
270 struct csio_lnode *ln = fdmi_req->lnode;
271
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);
276 }
277
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));
282 }
283}
284
285
286
287
288
289
290static void
291csio_ln_fdmi_rhba_cbfn(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
292{
293 void *cmd;
294 uint8_t *pld;
295 uint32_t len = 0;
296 __be32 val;
297 __be16 mfs;
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;
302 uint8_t buf[64];
303 uint8_t *fc4_type;
304 unsigned long flags;
305
306 if (fdmi_req->wr_status != FW_SUCCESS) {
307 csio_ln_dbg(ln, "WR error:%x in processing fdmi rhba cmd\n",
308 fdmi_req->wr_status);
309 CSIO_INC_STATS(ln, n_fdmi_err);
310 }
311
312 cmd = fdmi_req->dma_buf.vaddr;
313 if (ntohs(csio_ct_rsp(cmd)) != FC_FS_ACC) {
314 csio_ln_dbg(ln, "fdmi rhba cmd rejected reason %x expl %x\n",
315 csio_ct_reason(cmd), csio_ct_expl(cmd));
316 }
317
318 if (!csio_is_rnode_ready(fdmi_req->rnode)) {
319 CSIO_INC_STATS(ln, n_fdmi_err);
320 return;
321 }
322
323
324 memset(cmd, 0, FC_CT_HDR_LEN);
325 csio_fill_ct_iu(cmd, FC_FST_MGMT, FC_FDMI_SUBTYPE, FC_FDMI_RPA);
326
327
328 pld = (uint8_t *)csio_ct_get_pld(cmd);
329 port_name = (struct fc_fdmi_port_name *)pld;
330 memcpy(&port_name->portname, csio_ln_wwpn(ln), 8);
331 pld += sizeof(*port_name);
332
333
334 attrib_blk = (struct fs_fdmi_attrs *)pld;
335 attrib_blk->numattrs = 0;
336 len += sizeof(attrib_blk->numattrs);
337 pld += sizeof(attrib_blk->numattrs);
338
339 fc4_type = &buf[0];
340 memset(fc4_type, 0, FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
341 fc4_type[2] = 1;
342 fc4_type[7] = 1;
343 csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_FC4TYPES,
344 fc4_type, FC_FDMI_PORT_ATTR_FC4TYPES_LEN);
345 numattrs++;
346 val = htonl(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
347 csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_SUPPORTEDSPEED,
348 &val,
349 FC_FDMI_PORT_ATTR_SUPPORTEDSPEED_LEN);
350 numattrs++;
351
352 if (hw->pport[ln->portid].link_speed == FW_PORT_CAP_SPEED_1G)
353 val = htonl(FC_PORTSPEED_1GBIT);
354 else if (hw->pport[ln->portid].link_speed == FW_PORT_CAP_SPEED_10G)
355 val = htonl(FC_PORTSPEED_10GBIT);
356 else if (hw->pport[ln->portid].link_speed == FW_PORT_CAP32_SPEED_25G)
357 val = htonl(FC_PORTSPEED_25GBIT);
358 else if (hw->pport[ln->portid].link_speed == FW_PORT_CAP32_SPEED_40G)
359 val = htonl(FC_PORTSPEED_40GBIT);
360 else if (hw->pport[ln->portid].link_speed == FW_PORT_CAP32_SPEED_50G)
361 val = htonl(FC_PORTSPEED_50GBIT);
362 else if (hw->pport[ln->portid].link_speed == FW_PORT_CAP32_SPEED_100G)
363 val = htonl(FC_PORTSPEED_100GBIT);
364 else
365 val = htonl(CSIO_HBA_PORTSPEED_UNKNOWN);
366 csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED,
367 &val, FC_FDMI_PORT_ATTR_CURRENTPORTSPEED_LEN);
368 numattrs++;
369
370 mfs = ln->ln_sparm.csp.sp_bb_data;
371 csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_MAXFRAMESIZE,
372 &mfs, sizeof(mfs));
373 numattrs++;
374
375 strcpy(buf, "csiostor");
376 csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_OSDEVICENAME, buf,
377 strlen(buf));
378 numattrs++;
379
380 if (!csio_hostname(buf, sizeof(buf))) {
381 csio_append_attrib(&pld, FC_FDMI_PORT_ATTR_HOSTNAME,
382 buf, strlen(buf));
383 numattrs++;
384 }
385 attrib_blk->numattrs = htonl(numattrs);
386 len = (uint32_t)(pld - (uint8_t *)cmd);
387
388
389 spin_lock_irqsave(&hw->lock, flags);
390 if (csio_ln_mgmt_submit_req(fdmi_req, csio_ln_fdmi_done,
391 FCOE_CT, &fdmi_req->dma_buf, len)) {
392 CSIO_INC_STATS(ln, n_fdmi_err);
393 csio_ln_dbg(ln, "Failed to issue fdmi rpa req\n");
394 }
395 spin_unlock_irqrestore(&hw->lock, flags);
396}
397
398
399
400
401
402
403static void
404csio_ln_fdmi_dprt_cbfn(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
405{
406 void *cmd;
407 uint8_t *pld;
408 uint32_t len = 0;
409 uint32_t numattrs = 0;
410 __be32 maxpayload = htonl(65536);
411 struct fc_fdmi_hba_identifier *hbaid;
412 struct csio_lnode *ln = fdmi_req->lnode;
413 struct fc_fdmi_rpl *reg_pl;
414 struct fs_fdmi_attrs *attrib_blk;
415 uint8_t buf[64];
416 unsigned long flags;
417
418 if (fdmi_req->wr_status != FW_SUCCESS) {
419 csio_ln_dbg(ln, "WR error:%x in processing fdmi dprt cmd\n",
420 fdmi_req->wr_status);
421 CSIO_INC_STATS(ln, n_fdmi_err);
422 }
423
424 if (!csio_is_rnode_ready(fdmi_req->rnode)) {
425 CSIO_INC_STATS(ln, n_fdmi_err);
426 return;
427 }
428 cmd = fdmi_req->dma_buf.vaddr;
429 if (ntohs(csio_ct_rsp(cmd)) != FC_FS_ACC) {
430 csio_ln_dbg(ln, "fdmi dprt cmd rejected reason %x expl %x\n",
431 csio_ct_reason(cmd), csio_ct_expl(cmd));
432 }
433
434
435 memset(cmd, 0, FC_CT_HDR_LEN);
436 csio_fill_ct_iu(cmd, FC_FST_MGMT, FC_FDMI_SUBTYPE, FC_FDMI_RHBA);
437 len = FC_CT_HDR_LEN;
438
439
440 pld = (uint8_t *)csio_ct_get_pld(cmd);
441 hbaid = (struct fc_fdmi_hba_identifier *)pld;
442 memcpy(&hbaid->id, csio_ln_wwpn(ln), 8);
443 pld += sizeof(*hbaid);
444
445
446 reg_pl = (struct fc_fdmi_rpl *)pld;
447 reg_pl->numport = htonl(1);
448 memcpy(®_pl->port[0].portname, csio_ln_wwpn(ln), 8);
449 pld += sizeof(*reg_pl);
450
451
452 attrib_blk = (struct fs_fdmi_attrs *)pld;
453 attrib_blk->numattrs = 0;
454 len += sizeof(attrib_blk->numattrs);
455 pld += sizeof(attrib_blk->numattrs);
456
457 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_NODENAME, csio_ln_wwnn(ln),
458 FC_FDMI_HBA_ATTR_NODENAME_LEN);
459 numattrs++;
460
461 memset(buf, 0, sizeof(buf));
462
463 strcpy(buf, "Chelsio Communications");
464 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MANUFACTURER, buf,
465 strlen(buf));
466 numattrs++;
467 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_SERIALNUMBER,
468 hw->vpd.sn, sizeof(hw->vpd.sn));
469 numattrs++;
470 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MODEL, hw->vpd.id,
471 sizeof(hw->vpd.id));
472 numattrs++;
473 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MODELDESCRIPTION,
474 hw->model_desc, strlen(hw->model_desc));
475 numattrs++;
476 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_HARDWAREVERSION,
477 hw->hw_ver, sizeof(hw->hw_ver));
478 numattrs++;
479 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_FIRMWAREVERSION,
480 hw->fwrev_str, strlen(hw->fwrev_str));
481 numattrs++;
482
483 if (!csio_osname(buf, sizeof(buf))) {
484 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_OSNAMEVERSION,
485 buf, strlen(buf));
486 numattrs++;
487 }
488
489 csio_append_attrib(&pld, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD,
490 &maxpayload, FC_FDMI_HBA_ATTR_MAXCTPAYLOAD_LEN);
491 len = (uint32_t)(pld - (uint8_t *)cmd);
492 numattrs++;
493 attrib_blk->numattrs = htonl(numattrs);
494
495
496 spin_lock_irqsave(&hw->lock, flags);
497 if (csio_ln_mgmt_submit_req(fdmi_req, csio_ln_fdmi_rhba_cbfn,
498 FCOE_CT, &fdmi_req->dma_buf, len)) {
499 CSIO_INC_STATS(ln, n_fdmi_err);
500 csio_ln_dbg(ln, "Failed to issue fdmi rhba req\n");
501 }
502 spin_unlock_irqrestore(&hw->lock, flags);
503}
504
505
506
507
508
509
510static void
511csio_ln_fdmi_dhba_cbfn(struct csio_hw *hw, struct csio_ioreq *fdmi_req)
512{
513 struct csio_lnode *ln = fdmi_req->lnode;
514 void *cmd;
515 struct fc_fdmi_port_name *port_name;
516 uint32_t len;
517 unsigned long flags;
518
519 if (fdmi_req->wr_status != FW_SUCCESS) {
520 csio_ln_dbg(ln, "WR error:%x in processing fdmi dhba cmd\n",
521 fdmi_req->wr_status);
522 CSIO_INC_STATS(ln, n_fdmi_err);
523 }
524
525 if (!csio_is_rnode_ready(fdmi_req->rnode)) {
526 CSIO_INC_STATS(ln, n_fdmi_err);
527 return;
528 }
529 cmd = fdmi_req->dma_buf.vaddr;
530 if (ntohs(csio_ct_rsp(cmd)) != FC_FS_ACC) {
531 csio_ln_dbg(ln, "fdmi dhba cmd rejected reason %x expl %x\n",
532 csio_ct_reason(cmd), csio_ct_expl(cmd));
533 }
534
535
536
537
538
539
540 memset(cmd, 0, FC_CT_HDR_LEN);
541 csio_fill_ct_iu(cmd, FC_FST_MGMT, FC_FDMI_SUBTYPE, FC_FDMI_DPRT);
542 len = FC_CT_HDR_LEN;
543 port_name = (struct fc_fdmi_port_name *)csio_ct_get_pld(cmd);
544 memcpy(&port_name->portname, csio_ln_wwpn(ln), 8);
545 len += sizeof(*port_name);
546
547
548 spin_lock_irqsave(&hw->lock, flags);
549 if (csio_ln_mgmt_submit_req(fdmi_req, csio_ln_fdmi_dprt_cbfn,
550 FCOE_CT, &fdmi_req->dma_buf, len)) {
551 CSIO_INC_STATS(ln, n_fdmi_err);
552 csio_ln_dbg(ln, "Failed to issue fdmi dprt req\n");
553 }
554 spin_unlock_irqrestore(&hw->lock, flags);
555}
556
557
558
559
560
561
562
563
564int
565csio_ln_fdmi_start(struct csio_lnode *ln, void *context)
566{
567 struct csio_ioreq *fdmi_req;
568 struct csio_rnode *fdmi_rn = (struct csio_rnode *)context;
569 void *cmd;
570 struct fc_fdmi_hba_identifier *hbaid;
571 uint32_t len;
572
573 if (!(ln->flags & CSIO_LNF_FDMI_ENABLE))
574 return -EPROTONOSUPPORT;
575
576 if (!csio_is_rnode_ready(fdmi_rn))
577 CSIO_INC_STATS(ln, n_fdmi_err);
578
579
580
581
582
583 fdmi_req = ln->mgmt_req;
584 fdmi_req->lnode = ln;
585 fdmi_req->rnode = fdmi_rn;
586
587
588 cmd = fdmi_req->dma_buf.vaddr;
589 memset(cmd, 0, FC_CT_HDR_LEN);
590 csio_fill_ct_iu(cmd, FC_FST_MGMT, FC_FDMI_SUBTYPE, FC_FDMI_DHBA);
591 len = FC_CT_HDR_LEN;
592
593 hbaid = (struct fc_fdmi_hba_identifier *)csio_ct_get_pld(cmd);
594 memcpy(&hbaid->id, csio_ln_wwpn(ln), 8);
595 len += sizeof(*hbaid);
596
597
598 if (csio_ln_mgmt_submit_req(fdmi_req, csio_ln_fdmi_dhba_cbfn,
599 FCOE_CT, &fdmi_req->dma_buf, len)) {
600 CSIO_INC_STATS(ln, n_fdmi_err);
601 csio_ln_dbg(ln, "Failed to issue fdmi dhba req\n");
602 }
603
604 return 0;
605}
606
607
608
609
610
611
612
613
614static void
615csio_ln_vnp_read_cbfn(struct csio_hw *hw, struct csio_mb *mbp)
616{
617 struct csio_lnode *ln = ((struct csio_lnode *)mbp->priv);
618 struct fw_fcoe_vnp_cmd *rsp = (struct fw_fcoe_vnp_cmd *)(mbp->mb);
619 struct fc_els_csp *csp;
620 struct fc_els_cssp *clsp;
621 enum fw_retval retval;
622 __be32 nport_id;
623
624 retval = FW_CMD_RETVAL_G(ntohl(rsp->alloc_to_len16));
625 if (retval != FW_SUCCESS) {
626 csio_err(hw, "FCOE VNP read cmd returned error:0x%x\n", retval);
627 mempool_free(mbp, hw->mb_mempool);
628 return;
629 }
630
631 spin_lock_irq(&hw->lock);
632
633 memcpy(ln->mac, rsp->vnport_mac, sizeof(ln->mac));
634 memcpy(&nport_id, &rsp->vnport_mac[3], sizeof(uint8_t)*3);
635 ln->nport_id = ntohl(nport_id);
636 ln->nport_id = ln->nport_id >> 8;
637
638
639
640
641
642
643
644 memcpy(csio_ln_wwnn(ln), rsp->vnport_wwnn, 8);
645 memcpy(csio_ln_wwpn(ln), rsp->vnport_wwpn, 8);
646
647
648 csp = (struct fc_els_csp *)rsp->cmn_srv_parms;
649 ln->ln_sparm.csp.sp_hi_ver = csp->sp_hi_ver;
650 ln->ln_sparm.csp.sp_lo_ver = csp->sp_lo_ver;
651 ln->ln_sparm.csp.sp_bb_cred = csp->sp_bb_cred;
652 ln->ln_sparm.csp.sp_features = csp->sp_features;
653 ln->ln_sparm.csp.sp_bb_data = csp->sp_bb_data;
654 ln->ln_sparm.csp.sp_r_a_tov = csp->sp_r_a_tov;
655 ln->ln_sparm.csp.sp_e_d_tov = csp->sp_e_d_tov;
656
657
658 clsp = (struct fc_els_cssp *)rsp->clsp_word_0_1;
659 ln->ln_sparm.clsp[2].cp_class = clsp->cp_class;
660 ln->ln_sparm.clsp[2].cp_init = clsp->cp_init;
661 ln->ln_sparm.clsp[2].cp_recip = clsp->cp_recip;
662 ln->ln_sparm.clsp[2].cp_rdfs = clsp->cp_rdfs;
663
664 spin_unlock_irq(&hw->lock);
665
666 mempool_free(mbp, hw->mb_mempool);
667
668
669 csio_lnode_async_event(ln, CSIO_LN_FC_ATTRIB_UPDATE);
670}
671
672
673
674
675
676
677
678
679static int
680csio_ln_vnp_read(struct csio_lnode *ln,
681 void (*cbfn) (struct csio_hw *, struct csio_mb *))
682{
683 struct csio_hw *hw = ln->hwp;
684 struct csio_mb *mbp;
685
686
687 mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
688 if (!mbp) {
689 CSIO_INC_STATS(hw, n_err_nomem);
690 return -ENOMEM;
691 }
692
693
694 csio_fcoe_vnp_read_init_mb(ln, mbp,
695 CSIO_MB_DEFAULT_TMO,
696 ln->fcf_flowid,
697 ln->vnp_flowid,
698 cbfn);
699
700
701 if (csio_mb_issue(hw, mbp)) {
702 csio_err(hw, "Failed to issue mbox FCoE VNP command\n");
703 mempool_free(mbp, hw->mb_mempool);
704 return -EINVAL;
705 }
706
707 return 0;
708}
709
710
711
712
713
714
715
716
717static int
718csio_fcoe_enable_link(struct csio_lnode *ln, bool enable)
719{
720 struct csio_hw *hw = ln->hwp;
721 struct csio_mb *mbp;
722 enum fw_retval retval;
723 uint8_t portid;
724 uint8_t sub_op;
725 struct fw_fcoe_link_cmd *lcmd;
726 int i;
727
728 mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
729 if (!mbp) {
730 CSIO_INC_STATS(hw, n_err_nomem);
731 return -ENOMEM;
732 }
733
734 portid = ln->portid;
735 sub_op = enable ? FCOE_LINK_UP : FCOE_LINK_DOWN;
736
737 csio_dbg(hw, "bringing FCOE LINK %s on Port:%d\n",
738 sub_op ? "UP" : "DOWN", portid);
739
740 csio_write_fcoe_link_cond_init_mb(ln, mbp, CSIO_MB_DEFAULT_TMO,
741 portid, sub_op, 0, 0, 0, NULL);
742
743 if (csio_mb_issue(hw, mbp)) {
744 csio_err(hw, "failed to issue FCOE LINK cmd on port[%d]\n",
745 portid);
746 mempool_free(mbp, hw->mb_mempool);
747 return -EINVAL;
748 }
749
750 retval = csio_mb_fw_retval(mbp);
751 if (retval != FW_SUCCESS) {
752 csio_err(hw,
753 "FCOE LINK %s cmd on port[%d] failed with "
754 "ret:x%x\n", sub_op ? "UP" : "DOWN", portid, retval);
755 mempool_free(mbp, hw->mb_mempool);
756 return -EINVAL;
757 }
758
759 if (!enable)
760 goto out;
761
762 lcmd = (struct fw_fcoe_link_cmd *)mbp->mb;
763
764 memcpy(csio_ln_wwnn(ln), lcmd->vnport_wwnn, 8);
765 memcpy(csio_ln_wwpn(ln), lcmd->vnport_wwpn, 8);
766
767 for (i = 0; i < CSIO_MAX_PPORTS; i++)
768 if (hw->pport[i].portid == portid)
769 memcpy(hw->pport[i].mac, lcmd->phy_mac, 6);
770
771out:
772 mempool_free(mbp, hw->mb_mempool);
773 return 0;
774}
775
776
777
778
779
780
781
782static void
783csio_ln_read_fcf_cbfn(struct csio_hw *hw, struct csio_mb *mbp)
784{
785 struct csio_lnode *ln = (struct csio_lnode *)mbp->priv;
786 struct csio_fcf_info *fcf_info;
787 struct fw_fcoe_fcf_cmd *rsp =
788 (struct fw_fcoe_fcf_cmd *)(mbp->mb);
789 enum fw_retval retval;
790
791 retval = FW_CMD_RETVAL_G(ntohl(rsp->retval_len16));
792 if (retval != FW_SUCCESS) {
793 csio_ln_err(ln, "FCOE FCF cmd failed with ret x%x\n",
794 retval);
795 mempool_free(mbp, hw->mb_mempool);
796 return;
797 }
798
799 spin_lock_irq(&hw->lock);
800 fcf_info = ln->fcfinfo;
801 fcf_info->priority = FW_FCOE_FCF_CMD_PRIORITY_GET(
802 ntohs(rsp->priority_pkd));
803 fcf_info->vf_id = ntohs(rsp->vf_id);
804 fcf_info->vlan_id = rsp->vlan_id;
805 fcf_info->max_fcoe_size = ntohs(rsp->max_fcoe_size);
806 fcf_info->fka_adv = be32_to_cpu(rsp->fka_adv);
807 fcf_info->fcfi = FW_FCOE_FCF_CMD_FCFI_GET(ntohl(rsp->op_to_fcfi));
808 fcf_info->fpma = FW_FCOE_FCF_CMD_FPMA_GET(rsp->fpma_to_portid);
809 fcf_info->spma = FW_FCOE_FCF_CMD_SPMA_GET(rsp->fpma_to_portid);
810 fcf_info->login = FW_FCOE_FCF_CMD_LOGIN_GET(rsp->fpma_to_portid);
811 fcf_info->portid = FW_FCOE_FCF_CMD_PORTID_GET(rsp->fpma_to_portid);
812 memcpy(fcf_info->fc_map, rsp->fc_map, sizeof(fcf_info->fc_map));
813 memcpy(fcf_info->mac, rsp->mac, sizeof(fcf_info->mac));
814 memcpy(fcf_info->name_id, rsp->name_id, sizeof(fcf_info->name_id));
815 memcpy(fcf_info->fabric, rsp->fabric, sizeof(fcf_info->fabric));
816 memcpy(fcf_info->spma_mac, rsp->spma_mac, sizeof(fcf_info->spma_mac));
817
818 spin_unlock_irq(&hw->lock);
819
820 mempool_free(mbp, hw->mb_mempool);
821}
822
823
824
825
826
827
828
829
830static int
831csio_ln_read_fcf_entry(struct csio_lnode *ln,
832 void (*cbfn) (struct csio_hw *, struct csio_mb *))
833{
834 struct csio_hw *hw = ln->hwp;
835 struct csio_mb *mbp;
836
837 mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
838 if (!mbp) {
839 CSIO_INC_STATS(hw, n_err_nomem);
840 return -ENOMEM;
841 }
842
843
844 csio_fcoe_read_fcf_init_mb(ln, mbp, CSIO_MB_DEFAULT_TMO,
845 ln->portid, ln->fcf_flowid, cbfn);
846
847 if (csio_mb_issue(hw, mbp)) {
848 csio_err(hw, "failed to issue FCOE FCF cmd\n");
849 mempool_free(mbp, hw->mb_mempool);
850 return -EINVAL;
851 }
852
853 return 0;
854}
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872static void
873csio_handle_link_up(struct csio_hw *hw, uint8_t portid, uint32_t fcfi,
874 uint32_t vnpi)
875{
876 struct csio_lnode *ln = NULL;
877
878
879 ln = csio_ln_lookup_by_vnpi(hw, vnpi);
880 if (!ln) {
881
882 ln = csio_ln_lookup_by_portid(hw, portid);
883 if (!ln) {
884 csio_err(hw, "failed to lookup fcoe lnode on port:%d\n",
885 portid);
886 CSIO_DB_ASSERT(0);
887 return;
888 }
889
890
891 if (ln->vnp_flowid != CSIO_INVALID_IDX) {
892
893 spin_unlock_irq(&hw->lock);
894 csio_lnode_alloc(hw);
895 spin_lock_irq(&hw->lock);
896 if (!ln) {
897 csio_err(hw,
898 "failed to allocate fcoe lnode"
899 "for port:%d vnpi:x%x\n",
900 portid, vnpi);
901 CSIO_DB_ASSERT(0);
902 return;
903 }
904 ln->portid = portid;
905 }
906 ln->vnp_flowid = vnpi;
907 ln->dev_num &= ~0xFFFF;
908 ln->dev_num |= vnpi;
909 }
910
911
912 ln->fcf_flowid = fcfi;
913
914 csio_info(hw, "Port:%d - FCOE LINK UP\n", portid);
915
916 CSIO_INC_STATS(ln, n_link_up);
917
918
919 csio_post_event(&ln->sm, CSIO_LNE_LINKUP);
920}
921
922
923
924
925
926
927
928
929
930
931
932
933
934static void
935csio_post_event_rns(struct csio_lnode *ln, enum csio_rn_ev evt)
936{
937 struct csio_rnode *rnhead = (struct csio_rnode *) &ln->rnhead;
938 struct list_head *tmp, *next;
939 struct csio_rnode *rn;
940
941 list_for_each_safe(tmp, next, &rnhead->sm.sm_list) {
942 rn = (struct csio_rnode *) tmp;
943 csio_post_event(&rn->sm, evt);
944 }
945}
946
947
948
949
950
951
952
953
954
955
956static void
957csio_cleanup_rns(struct csio_lnode *ln)
958{
959 struct csio_rnode *rnhead = (struct csio_rnode *) &ln->rnhead;
960 struct list_head *tmp, *next_rn;
961 struct csio_rnode *rn;
962
963 list_for_each_safe(tmp, next_rn, &rnhead->sm.sm_list) {
964 rn = (struct csio_rnode *) tmp;
965 csio_put_rnode(ln, rn);
966 }
967
968}
969
970
971
972
973
974
975
976
977
978
979
980
981
982static void
983csio_post_event_lns(struct csio_lnode *ln, enum csio_ln_ev evt)
984{
985 struct list_head *tmp;
986 struct csio_lnode *cln, *sln;
987
988
989 if (csio_is_npiv_ln(ln)) {
990 csio_post_event(&ln->sm, evt);
991 return;
992 }
993
994 sln = ln;
995
996 list_for_each(tmp, &sln->cln_head) {
997 cln = (struct csio_lnode *) tmp;
998 csio_post_event(&cln->sm, evt);
999 }
1000
1001
1002 csio_post_event(&ln->sm, evt);
1003}
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014static void
1015csio_ln_down(struct csio_lnode *ln)
1016{
1017 csio_post_event_lns(ln, CSIO_LNE_LINK_DOWN);
1018}
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034static void
1035csio_handle_link_down(struct csio_hw *hw, uint8_t portid, uint32_t fcfi,
1036 uint32_t vnpi)
1037{
1038 struct csio_fcf_info *fp;
1039 struct csio_lnode *ln;
1040
1041
1042 ln = csio_ln_lookup_by_vnpi(hw, vnpi);
1043 if (ln) {
1044 fp = ln->fcfinfo;
1045 CSIO_INC_STATS(ln, n_link_down);
1046
1047
1048 if (!csio_is_lnode_ready(ln)) {
1049 csio_ln_warn(ln,
1050 "warn: FCOE link is already in offline "
1051 "Ignoring Fcoe linkdown event on portid %d\n",
1052 portid);
1053 CSIO_INC_STATS(ln, n_evt_drop);
1054 return;
1055 }
1056
1057
1058 if (fp->portid != portid) {
1059 csio_ln_warn(ln,
1060 "warn: FCOE linkdown recv with "
1061 "invalid port %d\n", portid);
1062 CSIO_INC_STATS(ln, n_evt_drop);
1063 return;
1064 }
1065
1066
1067 if (ln->fcf_flowid != fcfi) {
1068 csio_ln_warn(ln,
1069 "warn: FCOE linkdown recv with "
1070 "invalid fcfi x%x\n", fcfi);
1071 CSIO_INC_STATS(ln, n_evt_drop);
1072 return;
1073 }
1074
1075 csio_info(hw, "Port:%d - FCOE LINK DOWN\n", portid);
1076
1077
1078 csio_ln_down(ln);
1079
1080 return;
1081 } else {
1082 csio_warn(hw,
1083 "warn: FCOE linkdown recv with invalid vnpi x%x\n",
1084 vnpi);
1085 CSIO_INC_STATS(hw, n_evt_drop);
1086 }
1087}
1088
1089
1090
1091
1092
1093
1094
1095int
1096csio_is_lnode_ready(struct csio_lnode *ln)
1097{
1098 return (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready));
1099}
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113static void
1114csio_lns_uninit(struct csio_lnode *ln, enum csio_ln_ev evt)
1115{
1116 struct csio_hw *hw = csio_lnode_to_hw(ln);
1117 struct csio_lnode *rln = hw->rln;
1118 int rv;
1119
1120 CSIO_INC_STATS(ln, n_evt_sm[evt]);
1121 switch (evt) {
1122 case CSIO_LNE_LINKUP:
1123 csio_set_state(&ln->sm, csio_lns_online);
1124
1125 if (csio_is_phys_ln(ln)) {
1126 rv = csio_ln_read_fcf_entry(ln,
1127 csio_ln_read_fcf_cbfn);
1128 if (rv != 0) {
1129
1130 CSIO_INC_STATS(ln, n_err);
1131 break;
1132 }
1133
1134
1135 list_add_tail(&ln->fcfinfo->list, &rln->fcf_lsthead);
1136 }
1137
1138 rv = csio_ln_vnp_read(ln, csio_ln_vnp_read_cbfn);
1139 if (rv != 0) {
1140
1141 CSIO_INC_STATS(ln, n_err);
1142 }
1143 break;
1144
1145 case CSIO_LNE_DOWN_LINK:
1146 break;
1147
1148 default:
1149 csio_ln_dbg(ln,
1150 "unexp ln event %d recv from did:x%x in "
1151 "ln state[uninit].\n", evt, ln->nport_id);
1152 CSIO_INC_STATS(ln, n_evt_unexp);
1153 break;
1154 }
1155}
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166static void
1167csio_lns_online(struct csio_lnode *ln, enum csio_ln_ev evt)
1168{
1169 struct csio_hw *hw = csio_lnode_to_hw(ln);
1170
1171 CSIO_INC_STATS(ln, n_evt_sm[evt]);
1172 switch (evt) {
1173 case CSIO_LNE_LINKUP:
1174 csio_ln_warn(ln,
1175 "warn: FCOE link is up already "
1176 "Ignoring linkup on port:%d\n", ln->portid);
1177 CSIO_INC_STATS(ln, n_evt_drop);
1178 break;
1179
1180 case CSIO_LNE_FAB_INIT_DONE:
1181 csio_set_state(&ln->sm, csio_lns_ready);
1182
1183 spin_unlock_irq(&hw->lock);
1184 csio_lnode_async_event(ln, CSIO_LN_FC_LINKUP);
1185 spin_lock_irq(&hw->lock);
1186
1187 break;
1188
1189 case CSIO_LNE_LINK_DOWN:
1190
1191 case CSIO_LNE_DOWN_LINK:
1192 csio_set_state(&ln->sm, csio_lns_uninit);
1193 if (csio_is_phys_ln(ln)) {
1194
1195 list_del_init(&ln->fcfinfo->list);
1196 }
1197 break;
1198
1199 default:
1200 csio_ln_dbg(ln,
1201 "unexp ln event %d recv from did:x%x in "
1202 "ln state[uninit].\n", evt, ln->nport_id);
1203 CSIO_INC_STATS(ln, n_evt_unexp);
1204
1205 break;
1206 }
1207}
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218static void
1219csio_lns_ready(struct csio_lnode *ln, enum csio_ln_ev evt)
1220{
1221 struct csio_hw *hw = csio_lnode_to_hw(ln);
1222
1223 CSIO_INC_STATS(ln, n_evt_sm[evt]);
1224 switch (evt) {
1225 case CSIO_LNE_FAB_INIT_DONE:
1226 csio_ln_dbg(ln,
1227 "ignoring event %d recv from did x%x"
1228 "in ln state[ready].\n", evt, ln->nport_id);
1229 CSIO_INC_STATS(ln, n_evt_drop);
1230 break;
1231
1232 case CSIO_LNE_LINK_DOWN:
1233 csio_set_state(&ln->sm, csio_lns_offline);
1234 csio_post_event_rns(ln, CSIO_RNFE_DOWN);
1235
1236 spin_unlock_irq(&hw->lock);
1237 csio_lnode_async_event(ln, CSIO_LN_FC_LINKDOWN);
1238 spin_lock_irq(&hw->lock);
1239
1240 if (csio_is_phys_ln(ln)) {
1241
1242 list_del_init(&ln->fcfinfo->list);
1243 }
1244 break;
1245
1246 case CSIO_LNE_DOWN_LINK:
1247 csio_set_state(&ln->sm, csio_lns_offline);
1248 csio_post_event_rns(ln, CSIO_RNFE_DOWN);
1249
1250
1251
1252
1253 spin_unlock_irq(&hw->lock);
1254 csio_lnode_async_event(ln, CSIO_LN_FC_LINKDOWN);
1255 spin_lock_irq(&hw->lock);
1256
1257 if (csio_is_phys_ln(ln)) {
1258
1259 list_del_init(&ln->fcfinfo->list);
1260 }
1261 break;
1262
1263 case CSIO_LNE_CLOSE:
1264 csio_set_state(&ln->sm, csio_lns_uninit);
1265 csio_post_event_rns(ln, CSIO_RNFE_CLOSE);
1266 break;
1267
1268 case CSIO_LNE_LOGO:
1269 csio_set_state(&ln->sm, csio_lns_offline);
1270 csio_post_event_rns(ln, CSIO_RNFE_DOWN);
1271 break;
1272
1273 default:
1274 csio_ln_dbg(ln,
1275 "unexp ln event %d recv from did:x%x in "
1276 "ln state[uninit].\n", evt, ln->nport_id);
1277 CSIO_INC_STATS(ln, n_evt_unexp);
1278 CSIO_DB_ASSERT(0);
1279 break;
1280 }
1281}
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292static void
1293csio_lns_offline(struct csio_lnode *ln, enum csio_ln_ev evt)
1294{
1295 struct csio_hw *hw = csio_lnode_to_hw(ln);
1296 struct csio_lnode *rln = hw->rln;
1297 int rv;
1298
1299 CSIO_INC_STATS(ln, n_evt_sm[evt]);
1300 switch (evt) {
1301 case CSIO_LNE_LINKUP:
1302 csio_set_state(&ln->sm, csio_lns_online);
1303
1304 if (csio_is_phys_ln(ln)) {
1305 rv = csio_ln_read_fcf_entry(ln,
1306 csio_ln_read_fcf_cbfn);
1307 if (rv != 0) {
1308
1309 CSIO_INC_STATS(ln, n_err);
1310 break;
1311 }
1312
1313
1314 list_add_tail(&ln->fcfinfo->list, &rln->fcf_lsthead);
1315 }
1316
1317 rv = csio_ln_vnp_read(ln, csio_ln_vnp_read_cbfn);
1318 if (rv != 0) {
1319
1320 CSIO_INC_STATS(ln, n_err);
1321 }
1322 break;
1323
1324 case CSIO_LNE_LINK_DOWN:
1325 case CSIO_LNE_DOWN_LINK:
1326 case CSIO_LNE_LOGO:
1327 csio_ln_dbg(ln,
1328 "ignoring event %d recv from did x%x"
1329 "in ln state[offline].\n", evt, ln->nport_id);
1330 CSIO_INC_STATS(ln, n_evt_drop);
1331 break;
1332
1333 case CSIO_LNE_CLOSE:
1334 csio_set_state(&ln->sm, csio_lns_uninit);
1335 csio_post_event_rns(ln, CSIO_RNFE_CLOSE);
1336 break;
1337
1338 default:
1339 csio_ln_dbg(ln,
1340 "unexp ln event %d recv from did:x%x in "
1341 "ln state[offline]\n", evt, ln->nport_id);
1342 CSIO_INC_STATS(ln, n_evt_unexp);
1343 CSIO_DB_ASSERT(0);
1344 break;
1345 }
1346}
1347
1348
1349
1350
1351
1352static void
1353csio_free_fcfinfo(struct kref *kref)
1354{
1355 struct csio_fcf_info *fcfinfo = container_of(kref,
1356 struct csio_fcf_info, kref);
1357 kfree(fcfinfo);
1358}
1359
1360
1361
1362
1363
1364
1365
1366
1367void
1368csio_lnode_state_to_str(struct csio_lnode *ln, int8_t *str)
1369{
1370 if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_uninit)) {
1371 strcpy(str, "UNINIT");
1372 return;
1373 }
1374 if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_ready)) {
1375 strcpy(str, "READY");
1376 return;
1377 }
1378 if (csio_get_state(ln) == ((csio_sm_state_t)csio_lns_offline)) {
1379 strcpy(str, "OFFLINE");
1380 return;
1381 }
1382 strcpy(str, "UNKNOWN");
1383}
1384
1385
1386int
1387csio_get_phy_port_stats(struct csio_hw *hw, uint8_t portid,
1388 struct fw_fcoe_port_stats *port_stats)
1389{
1390 struct csio_mb *mbp;
1391 struct fw_fcoe_port_cmd_params portparams;
1392 enum fw_retval retval;
1393 int idx;
1394
1395 mbp = mempool_alloc(hw->mb_mempool, GFP_ATOMIC);
1396 if (!mbp) {
1397 csio_err(hw, "FCoE FCF PARAMS command out of memory!\n");
1398 return -EINVAL;
1399 }
1400 portparams.portid = portid;
1401
1402 for (idx = 1; idx <= 3; idx++) {
1403 portparams.idx = (idx-1)*6 + 1;
1404 portparams.nstats = 6;
1405 if (idx == 3)
1406 portparams.nstats = 4;
1407 csio_fcoe_read_portparams_init_mb(hw, mbp, CSIO_MB_DEFAULT_TMO,
1408 &portparams, NULL);
1409 if (csio_mb_issue(hw, mbp)) {
1410 csio_err(hw, "Issue of FCoE port params failed!\n");
1411 mempool_free(mbp, hw->mb_mempool);
1412 return -EINVAL;
1413 }
1414 csio_mb_process_portparams_rsp(hw, mbp, &retval,
1415 &portparams, port_stats);
1416 }
1417
1418 mempool_free(mbp, hw->mb_mempool);
1419 return 0;
1420}
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432static void
1433csio_ln_mgmt_wr_handler(struct csio_hw *hw, void *wr, uint32_t len)
1434{
1435 struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
1436 struct csio_ioreq *io_req = NULL;
1437 struct fw_fcoe_els_ct_wr *wr_cmd;
1438
1439
1440 wr_cmd = (struct fw_fcoe_els_ct_wr *) wr;
1441
1442 if (len < sizeof(struct fw_fcoe_els_ct_wr)) {
1443 csio_err(mgmtm->hw,
1444 "Invalid ELS CT WR length recvd, len:%x\n", len);
1445 mgmtm->stats.n_err++;
1446 return;
1447 }
1448
1449 io_req = (struct csio_ioreq *) ((uintptr_t) wr_cmd->cookie);
1450 io_req->wr_status = csio_wr_status(wr_cmd);
1451
1452
1453 spin_lock_irq(&hw->lock);
1454 if (csio_mgmt_req_lookup(mgmtm, io_req) != 0) {
1455 csio_err(mgmtm->hw,
1456 "Error- Invalid IO handle recv in WR. handle: %p\n",
1457 io_req);
1458 mgmtm->stats.n_err++;
1459 spin_unlock_irq(&hw->lock);
1460 return;
1461 }
1462
1463 mgmtm = csio_hw_to_mgmtm(hw);
1464
1465
1466 list_del_init(&io_req->sm.sm_list);
1467 mgmtm->stats.n_active--;
1468 spin_unlock_irq(&hw->lock);
1469
1470
1471 if (io_req->io_cbfn)
1472 io_req->io_cbfn(hw, io_req);
1473}
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483void
1484csio_fcoe_fwevt_handler(struct csio_hw *hw, __u8 cpl_op, __be64 *cmd)
1485{
1486 struct csio_lnode *ln;
1487 struct csio_rnode *rn;
1488 uint8_t portid, opcode = *(uint8_t *)cmd;
1489 struct fw_fcoe_link_cmd *lcmd;
1490 struct fw_wr_hdr *wr;
1491 struct fw_rdev_wr *rdev_wr;
1492 enum fw_fcoe_link_status lstatus;
1493 uint32_t fcfi, rdev_flowid, vnpi;
1494 enum csio_ln_ev evt;
1495
1496 if (cpl_op == CPL_FW6_MSG && opcode == FW_FCOE_LINK_CMD) {
1497
1498 lcmd = (struct fw_fcoe_link_cmd *)cmd;
1499 lstatus = lcmd->lstatus;
1500 portid = FW_FCOE_LINK_CMD_PORTID_GET(
1501 ntohl(lcmd->op_to_portid));
1502 fcfi = FW_FCOE_LINK_CMD_FCFI_GET(ntohl(lcmd->sub_opcode_fcfi));
1503 vnpi = FW_FCOE_LINK_CMD_VNPI_GET(ntohl(lcmd->vnpi_pkd));
1504
1505 if (lstatus == FCOE_LINKUP) {
1506
1507
1508 spin_lock_irq(&hw->lock);
1509 csio_handle_link_up(hw, portid, fcfi, vnpi);
1510 spin_unlock_irq(&hw->lock);
1511
1512
1513 } else if (lstatus == FCOE_LINKDOWN) {
1514
1515
1516 spin_lock_irq(&hw->lock);
1517 csio_handle_link_down(hw, portid, fcfi, vnpi);
1518 spin_unlock_irq(&hw->lock);
1519
1520 } else {
1521 csio_warn(hw, "Unexpected FCOE LINK status:0x%x\n",
1522 lcmd->lstatus);
1523 CSIO_INC_STATS(hw, n_cpl_unexp);
1524 }
1525 } else if (cpl_op == CPL_FW6_PLD) {
1526 wr = (struct fw_wr_hdr *) (cmd + 4);
1527 if (FW_WR_OP_G(be32_to_cpu(wr->hi))
1528 == FW_RDEV_WR) {
1529
1530 rdev_wr = (struct fw_rdev_wr *) (cmd + 4);
1531
1532 rdev_flowid = FW_RDEV_WR_FLOWID_GET(
1533 ntohl(rdev_wr->alloc_to_len16));
1534 vnpi = FW_RDEV_WR_ASSOC_FLOWID_GET(
1535 ntohl(rdev_wr->flags_to_assoc_flowid));
1536
1537 csio_dbg(hw,
1538 "FW_RDEV_WR: flowid:x%x ev_cause:x%x "
1539 "vnpi:0x%x\n", rdev_flowid,
1540 rdev_wr->event_cause, vnpi);
1541
1542 if (rdev_wr->protocol != PROT_FCOE) {
1543 csio_err(hw,
1544 "FW_RDEV_WR: invalid proto:x%x "
1545 "received with flowid:x%x\n",
1546 rdev_wr->protocol,
1547 rdev_flowid);
1548 CSIO_INC_STATS(hw, n_evt_drop);
1549 return;
1550 }
1551
1552
1553 spin_lock_irq(&hw->lock);
1554 ln = csio_ln_lookup_by_vnpi(hw, vnpi);
1555 if (!ln) {
1556 csio_err(hw,
1557 "FW_DEV_WR: invalid vnpi:x%x received "
1558 "with flowid:x%x\n", vnpi, rdev_flowid);
1559 CSIO_INC_STATS(hw, n_evt_drop);
1560 goto out_pld;
1561 }
1562
1563 rn = csio_confirm_rnode(ln, rdev_flowid,
1564 &rdev_wr->u.fcoe_rdev);
1565 if (!rn) {
1566 csio_ln_dbg(ln,
1567 "Failed to confirm rnode "
1568 "for flowid:x%x\n", rdev_flowid);
1569 CSIO_INC_STATS(hw, n_evt_drop);
1570 goto out_pld;
1571 }
1572
1573
1574 ln->prev_evt = ln->cur_evt;
1575 ln->cur_evt = rdev_wr->event_cause;
1576 CSIO_INC_STATS(ln, n_evt_fw[rdev_wr->event_cause]);
1577
1578
1579 evt = CSIO_FWE_TO_LNE(rdev_wr->event_cause);
1580 if (evt) {
1581 csio_ln_dbg(ln,
1582 "Posting event to lnode event:%d "
1583 "cause:%d flowid:x%x\n", evt,
1584 rdev_wr->event_cause, rdev_flowid);
1585 csio_post_event(&ln->sm, evt);
1586 }
1587
1588
1589 csio_rnode_fwevt_handler(rn, rdev_wr->event_cause);
1590out_pld:
1591 spin_unlock_irq(&hw->lock);
1592 return;
1593 } else {
1594 csio_warn(hw, "unexpected WR op(0x%x) recv\n",
1595 FW_WR_OP_G(be32_to_cpu((wr->hi))));
1596 CSIO_INC_STATS(hw, n_cpl_unexp);
1597 }
1598 } else if (cpl_op == CPL_FW6_MSG) {
1599 wr = (struct fw_wr_hdr *) (cmd);
1600 if (FW_WR_OP_G(be32_to_cpu(wr->hi)) == FW_FCOE_ELS_CT_WR) {
1601 csio_ln_mgmt_wr_handler(hw, wr,
1602 sizeof(struct fw_fcoe_els_ct_wr));
1603 } else {
1604 csio_warn(hw, "unexpected WR op(0x%x) recv\n",
1605 FW_WR_OP_G(be32_to_cpu((wr->hi))));
1606 CSIO_INC_STATS(hw, n_cpl_unexp);
1607 }
1608 } else {
1609 csio_warn(hw, "unexpected CPL op(0x%x) recv\n", opcode);
1610 CSIO_INC_STATS(hw, n_cpl_unexp);
1611 }
1612}
1613
1614
1615
1616
1617
1618
1619
1620int
1621csio_lnode_start(struct csio_lnode *ln)
1622{
1623 int rv = 0;
1624 if (csio_is_phys_ln(ln) && !(ln->flags & CSIO_LNF_LINK_ENABLE)) {
1625 rv = csio_fcoe_enable_link(ln, 1);
1626 ln->flags |= CSIO_LNF_LINK_ENABLE;
1627 }
1628
1629 return rv;
1630}
1631
1632
1633
1634
1635
1636
1637
1638
1639void
1640csio_lnode_stop(struct csio_lnode *ln)
1641{
1642 csio_post_event_lns(ln, CSIO_LNE_DOWN_LINK);
1643 if (csio_is_phys_ln(ln) && (ln->flags & CSIO_LNF_LINK_ENABLE)) {
1644 csio_fcoe_enable_link(ln, 0);
1645 ln->flags &= ~CSIO_LNF_LINK_ENABLE;
1646 }
1647 csio_ln_dbg(ln, "stopping ln :%p\n", ln);
1648}
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658void
1659csio_lnode_close(struct csio_lnode *ln)
1660{
1661 csio_post_event_lns(ln, CSIO_LNE_CLOSE);
1662 if (csio_is_phys_ln(ln))
1663 ln->vnp_flowid = CSIO_INVALID_IDX;
1664
1665 csio_ln_dbg(ln, "closed ln :%p\n", ln);
1666}
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680static int
1681csio_ln_prep_ecwr(struct csio_ioreq *io_req, uint32_t wr_len,
1682 uint32_t immd_len, uint8_t sub_op, uint32_t sid,
1683 uint32_t did, uint32_t flow_id, uint8_t *fw_wr)
1684{
1685 struct fw_fcoe_els_ct_wr *wr;
1686 __be32 port_id;
1687
1688 wr = (struct fw_fcoe_els_ct_wr *)fw_wr;
1689 wr->op_immdlen = cpu_to_be32(FW_WR_OP_V(FW_FCOE_ELS_CT_WR) |
1690 FW_FCOE_ELS_CT_WR_IMMDLEN(immd_len));
1691
1692 wr_len = DIV_ROUND_UP(wr_len, 16);
1693 wr->flowid_len16 = cpu_to_be32(FW_WR_FLOWID_V(flow_id) |
1694 FW_WR_LEN16_V(wr_len));
1695 wr->els_ct_type = sub_op;
1696 wr->ctl_pri = 0;
1697 wr->cp_en_class = 0;
1698 wr->cookie = io_req->fw_handle;
1699 wr->iqid = cpu_to_be16(csio_q_physiqid(
1700 io_req->lnode->hwp, io_req->iq_idx));
1701 wr->fl_to_sp = FW_FCOE_ELS_CT_WR_SP(1);
1702 wr->tmo_val = (uint8_t) io_req->tmo;
1703 port_id = htonl(sid);
1704 memcpy(wr->l_id, PORT_ID_PTR(port_id), 3);
1705 port_id = htonl(did);
1706 memcpy(wr->r_id, PORT_ID_PTR(port_id), 3);
1707
1708
1709 wr->rsp_dmalen = cpu_to_be32(io_req->dma_buf.len);
1710 wr->rsp_dmaaddr = cpu_to_be64(io_req->dma_buf.paddr);
1711 return 0;
1712}
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724static int
1725csio_ln_mgmt_submit_wr(struct csio_mgmtm *mgmtm, struct csio_ioreq *io_req,
1726 uint8_t sub_op, struct csio_dma_buf *pld,
1727 uint32_t pld_len)
1728{
1729 struct csio_wr_pair wrp;
1730 struct csio_lnode *ln = io_req->lnode;
1731 struct csio_rnode *rn = io_req->rnode;
1732 struct csio_hw *hw = mgmtm->hw;
1733 uint8_t fw_wr[64];
1734 struct ulptx_sgl dsgl;
1735 uint32_t wr_size = 0;
1736 uint8_t im_len = 0;
1737 uint32_t wr_off = 0;
1738
1739 int ret = 0;
1740
1741
1742 wr_size = sizeof(struct fw_fcoe_els_ct_wr);
1743
1744
1745 if (pld_len < 256) {
1746 wr_size += ALIGN(pld_len, 8);
1747 im_len = (uint8_t)pld_len;
1748 } else
1749 wr_size += sizeof(struct ulptx_sgl);
1750
1751
1752 wr_size = ALIGN(wr_size, 16);
1753
1754
1755 ret = csio_wr_get(hw, mgmtm->eq_idx, wr_size, &wrp);
1756 if (ret != 0) {
1757 csio_err(hw, "Failed to get WR for ec_req %p ret:%d\n",
1758 io_req, ret);
1759 return ret;
1760 }
1761
1762
1763 csio_ln_prep_ecwr(io_req, wr_size, im_len, sub_op,
1764 ln->nport_id, rn->nport_id,
1765 csio_rn_flowid(rn),
1766 &fw_wr[0]);
1767
1768
1769 csio_wr_copy_to_wrp(&fw_wr[0], &wrp, wr_off,
1770 sizeof(struct fw_fcoe_els_ct_wr));
1771 wr_off += sizeof(struct fw_fcoe_els_ct_wr);
1772
1773
1774 if (im_len)
1775 csio_wr_copy_to_wrp(pld->vaddr, &wrp, wr_off, im_len);
1776 else {
1777
1778 dsgl.cmd_nsge = htonl(ULPTX_CMD_V(ULP_TX_SC_DSGL) |
1779 ULPTX_MORE_F | ULPTX_NSGE_V(1));
1780 dsgl.len0 = cpu_to_be32(pld_len);
1781 dsgl.addr0 = cpu_to_be64(pld->paddr);
1782 csio_wr_copy_to_wrp(&dsgl, &wrp, ALIGN(wr_off, 8),
1783 sizeof(struct ulptx_sgl));
1784 }
1785
1786
1787 csio_wr_issue(mgmtm->hw, mgmtm->eq_idx, false);
1788 return ret;
1789}
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805static int
1806csio_ln_mgmt_submit_req(struct csio_ioreq *io_req,
1807 void (*io_cbfn) (struct csio_hw *, struct csio_ioreq *),
1808 enum fcoe_cmn_type req_type, struct csio_dma_buf *pld,
1809 uint32_t pld_len)
1810{
1811 struct csio_hw *hw = csio_lnode_to_hw(io_req->lnode);
1812 struct csio_mgmtm *mgmtm = csio_hw_to_mgmtm(hw);
1813 int rv;
1814
1815 BUG_ON(pld_len > pld->len);
1816
1817 io_req->io_cbfn = io_cbfn;
1818 io_req->fw_handle = (uintptr_t) (io_req);
1819 io_req->eq_idx = mgmtm->eq_idx;
1820 io_req->iq_idx = mgmtm->iq_idx;
1821
1822 rv = csio_ln_mgmt_submit_wr(mgmtm, io_req, req_type, pld, pld_len);
1823 if (rv == 0) {
1824 list_add_tail(&io_req->sm.sm_list, &mgmtm->active_q);
1825 mgmtm->stats.n_active++;
1826 }
1827 return rv;
1828}
1829
1830
1831
1832
1833
1834static int
1835csio_ln_fdmi_init(struct csio_lnode *ln)
1836{
1837 struct csio_hw *hw = csio_lnode_to_hw(ln);
1838 struct csio_dma_buf *dma_buf;
1839
1840
1841 ln->mgmt_req = kzalloc(sizeof(struct csio_ioreq), GFP_KERNEL);
1842 if (!ln->mgmt_req) {
1843 csio_ln_err(ln, "Failed to alloc ioreq for FDMI\n");
1844 CSIO_INC_STATS(hw, n_err_nomem);
1845 return -ENOMEM;
1846 }
1847
1848
1849 dma_buf = &ln->mgmt_req->dma_buf;
1850 dma_buf->len = 2048;
1851 dma_buf->vaddr = dma_alloc_coherent(&hw->pdev->dev, dma_buf->len,
1852 &dma_buf->paddr, GFP_KERNEL);
1853 if (!dma_buf->vaddr) {
1854 csio_err(hw, "Failed to alloc DMA buffer for FDMI!\n");
1855 kfree(ln->mgmt_req);
1856 ln->mgmt_req = NULL;
1857 return -ENOMEM;
1858 }
1859
1860 ln->flags |= CSIO_LNF_FDMI_ENABLE;
1861 return 0;
1862}
1863
1864
1865
1866
1867
1868static int
1869csio_ln_fdmi_exit(struct csio_lnode *ln)
1870{
1871 struct csio_dma_buf *dma_buf;
1872 struct csio_hw *hw = csio_lnode_to_hw(ln);
1873
1874 if (!ln->mgmt_req)
1875 return 0;
1876
1877 dma_buf = &ln->mgmt_req->dma_buf;
1878 if (dma_buf->vaddr)
1879 dma_free_coherent(&hw->pdev->dev, dma_buf->len, dma_buf->vaddr,
1880 dma_buf->paddr);
1881
1882 kfree(ln->mgmt_req);
1883 return 0;
1884}
1885
1886int
1887csio_scan_done(struct csio_lnode *ln, unsigned long ticks,
1888 unsigned long time, unsigned long max_scan_ticks,
1889 unsigned long delta_scan_ticks)
1890{
1891 int rv = 0;
1892
1893 if (time >= max_scan_ticks)
1894 return 1;
1895
1896 if (!ln->tgt_scan_tick)
1897 ln->tgt_scan_tick = ticks;
1898
1899 if (((ticks - ln->tgt_scan_tick) >= delta_scan_ticks)) {
1900 if (!ln->last_scan_ntgts)
1901 ln->last_scan_ntgts = ln->n_scsi_tgts;
1902 else {
1903 if (ln->last_scan_ntgts == ln->n_scsi_tgts)
1904 return 1;
1905
1906 ln->last_scan_ntgts = ln->n_scsi_tgts;
1907 }
1908 ln->tgt_scan_tick = ticks;
1909 }
1910 return rv;
1911}
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923void
1924csio_notify_lnodes(struct csio_hw *hw, enum csio_ln_notify note)
1925{
1926 struct list_head *tmp;
1927 struct csio_lnode *ln;
1928
1929 csio_dbg(hw, "Notifying all nodes of event %d\n", note);
1930
1931
1932 list_for_each(tmp, &hw->sln_head) {
1933 ln = (struct csio_lnode *) tmp;
1934
1935 switch (note) {
1936 case CSIO_LN_NOTIFY_HWREADY:
1937 csio_lnode_start(ln);
1938 break;
1939
1940 case CSIO_LN_NOTIFY_HWRESET:
1941 case CSIO_LN_NOTIFY_HWREMOVE:
1942 csio_lnode_close(ln);
1943 break;
1944
1945 case CSIO_LN_NOTIFY_HWSTOP:
1946 csio_lnode_stop(ln);
1947 break;
1948
1949 default:
1950 break;
1951
1952 }
1953 }
1954}
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965void
1966csio_disable_lnodes(struct csio_hw *hw, uint8_t portid, bool disable)
1967{
1968 struct list_head *tmp;
1969 struct csio_lnode *ln;
1970
1971 csio_dbg(hw, "Notifying event to all nodes of port:%d\n", portid);
1972
1973
1974 list_for_each(tmp, &hw->sln_head) {
1975 ln = (struct csio_lnode *) tmp;
1976 if (ln->portid != portid)
1977 continue;
1978
1979 if (disable)
1980 csio_lnode_stop(ln);
1981 else
1982 csio_lnode_start(ln);
1983 }
1984}
1985
1986
1987
1988
1989
1990
1991static int
1992csio_ln_init(struct csio_lnode *ln)
1993{
1994 int rv = -EINVAL;
1995 struct csio_lnode *pln;
1996 struct csio_hw *hw = csio_lnode_to_hw(ln);
1997
1998 csio_init_state(&ln->sm, csio_lns_uninit);
1999 ln->vnp_flowid = CSIO_INVALID_IDX;
2000 ln->fcf_flowid = CSIO_INVALID_IDX;
2001
2002 if (csio_is_root_ln(ln)) {
2003
2004
2005
2006 ln->fcfinfo = kzalloc(sizeof(struct csio_fcf_info), GFP_KERNEL);
2007 if (!ln->fcfinfo) {
2008 csio_ln_err(ln, "Failed to alloc FCF record\n");
2009 CSIO_INC_STATS(hw, n_err_nomem);
2010 goto err;
2011 }
2012
2013 INIT_LIST_HEAD(&ln->fcf_lsthead);
2014 kref_init(&ln->fcfinfo->kref);
2015
2016 if (csio_fdmi_enable && csio_ln_fdmi_init(ln))
2017 goto err;
2018
2019 } else {
2020
2021
2022
2023
2024
2025
2026 if (csio_is_npiv_ln(ln)) {
2027
2028 pln = csio_parent_lnode(ln);
2029 kref_get(&pln->fcfinfo->kref);
2030 ln->fcfinfo = pln->fcfinfo;
2031 } else {
2032
2033 ln->fcfinfo = kzalloc(sizeof(struct csio_fcf_info),
2034 GFP_KERNEL);
2035 if (!ln->fcfinfo) {
2036 csio_ln_err(ln, "Failed to alloc FCF info\n");
2037 CSIO_INC_STATS(hw, n_err_nomem);
2038 goto err;
2039 }
2040
2041 kref_init(&ln->fcfinfo->kref);
2042
2043 if (csio_fdmi_enable && csio_ln_fdmi_init(ln))
2044 goto err;
2045 }
2046
2047 }
2048
2049 return 0;
2050err:
2051 return rv;
2052}
2053
2054static void
2055csio_ln_exit(struct csio_lnode *ln)
2056{
2057 struct csio_lnode *pln;
2058
2059 csio_cleanup_rns(ln);
2060 if (csio_is_npiv_ln(ln)) {
2061 pln = csio_parent_lnode(ln);
2062 kref_put(&pln->fcfinfo->kref, csio_free_fcfinfo);
2063 } else {
2064 kref_put(&ln->fcfinfo->kref, csio_free_fcfinfo);
2065 if (csio_fdmi_enable)
2066 csio_ln_fdmi_exit(ln);
2067 }
2068 ln->fcfinfo = NULL;
2069}
2070
2071
2072
2073
2074
2075
2076int
2077csio_lnode_init(struct csio_lnode *ln, struct csio_hw *hw,
2078 struct csio_lnode *pln)
2079{
2080 int rv = -EINVAL;
2081
2082
2083 csio_lnode_to_hw(ln) = hw;
2084
2085
2086 if (pln)
2087 ln->pln = pln;
2088 else
2089 ln->pln = NULL;
2090
2091
2092 ln->n_scsi_tgts = 0;
2093 ln->last_scan_ntgts = 0;
2094 ln->tgt_scan_tick = 0;
2095
2096
2097 INIT_LIST_HEAD(&ln->rnhead);
2098 INIT_LIST_HEAD(&ln->cln_head);
2099
2100
2101 ln->params.log_level = hw->params.log_level;
2102
2103 if (csio_ln_init(ln))
2104 goto err;
2105
2106
2107 spin_lock_irq(&hw->lock);
2108 list_add_tail(&ln->sm.sm_list, pln ? &pln->cln_head : &hw->sln_head);
2109 if (pln)
2110 pln->num_vports++;
2111 spin_unlock_irq(&hw->lock);
2112
2113 hw->num_lns++;
2114
2115 return 0;
2116err:
2117 csio_lnode_to_hw(ln) = NULL;
2118 return rv;
2119}
2120
2121
2122
2123
2124
2125
2126void
2127csio_lnode_exit(struct csio_lnode *ln)
2128{
2129 struct csio_hw *hw = csio_lnode_to_hw(ln);
2130
2131 csio_ln_exit(ln);
2132
2133
2134 spin_lock_irq(&hw->lock);
2135
2136 list_del_init(&ln->sm.sm_list);
2137
2138
2139
2140
2141 if (ln->pln)
2142 ln->pln->num_vports--;
2143
2144
2145 if (list_empty(&hw->sln_head))
2146 hw->rln = NULL;
2147 else
2148 hw->rln = (struct csio_lnode *)csio_list_next(&hw->sln_head);
2149
2150 spin_unlock_irq(&hw->lock);
2151
2152 csio_lnode_to_hw(ln) = NULL;
2153 hw->num_lns--;
2154}
2155