aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorBhanu Prakash Gollapudi <bprakash@broadcom.com>2011-07-26 17:51:39 -0400
committerJames Bottomley <JBottomley@Parallels.com>2011-07-27 07:37:31 -0400
commitaea71a024914e8b5b8bed31256dae42195a0a207 (patch)
treed3d155d7323966a56425ad68837b924816719c89 /drivers/scsi
parentf6e76055ba778c56716ba79e106db28297775e87 (diff)
[SCSI] bnx2fc: Introduce interface structure for each vlan interface
Currently, bnx2fc has a hba structure that can work with only a single vlan interface. When there is a change in vlan id, it does not have the capability to switch to different vlan interface. To solve this problem, a new structure called 'interface' has been introduced, and each hba can now have multiple interfaces, one per vlan id. Most of the patch is a moving the interface specific fields from hba to the interface structure, and appropriately modifying the dereferences. A list of interfaces (if_list) is maintained along with adapter list. During a create call, the interface structure is allocated and added to if_list and deleted & freed on a destroy call. Link events are propagated to all interfaces belonging to the hba. Signed-off-by: Bhanu Prakash Gollapudi <bprakash@broadcom.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc.h74
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_els.c9
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c716
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_hwi.c98
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c48
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_tgt.c17
6 files changed, 467 insertions, 495 deletions
diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
index d924236e1b91..6012317c1f2f 100644
--- a/drivers/scsi/bnx2fc/bnx2fc.h
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -153,18 +153,13 @@ struct bnx2fc_percpu_s {
153}; 153};
154 154
155struct bnx2fc_hba { 155struct bnx2fc_hba {
156 struct list_head link; 156 struct list_head list;
157 struct cnic_dev *cnic; 157 struct cnic_dev *cnic;
158 struct pci_dev *pcidev; 158 struct pci_dev *pcidev;
159 struct net_device *netdev;
160 struct net_device *phys_dev; 159 struct net_device *phys_dev;
161 unsigned long reg_with_cnic; 160 unsigned long reg_with_cnic;
162 #define BNX2FC_CNIC_REGISTERED 1 161 #define BNX2FC_CNIC_REGISTERED 1
163 struct packet_type fcoe_packet_type;
164 struct packet_type fip_packet_type;
165 struct bnx2fc_cmd_mgr *cmd_mgr; 162 struct bnx2fc_cmd_mgr *cmd_mgr;
166 struct workqueue_struct *timer_work_queue;
167 struct kref kref;
168 spinlock_t hba_lock; 163 spinlock_t hba_lock;
169 struct mutex hba_mutex; 164 struct mutex hba_mutex;
170 unsigned long adapter_state; 165 unsigned long adapter_state;
@@ -172,15 +167,9 @@ struct bnx2fc_hba {
172 #define ADAPTER_STATE_GOING_DOWN 1 167 #define ADAPTER_STATE_GOING_DOWN 1
173 #define ADAPTER_STATE_LINK_DOWN 2 168 #define ADAPTER_STATE_LINK_DOWN 2
174 #define ADAPTER_STATE_READY 3 169 #define ADAPTER_STATE_READY 3
175 u32 flags; 170 unsigned long flags;
176 unsigned long init_done; 171 #define BNX2FC_FLAG_FW_INIT_DONE 0
177 #define BNX2FC_FW_INIT_DONE 0 172 #define BNX2FC_FLAG_DESTROY_CMPL 1
178 #define BNX2FC_CTLR_INIT_DONE 1
179 #define BNX2FC_CREATE_DONE 2
180 struct fcoe_ctlr ctlr;
181 struct list_head vports;
182 u8 vlan_enabled;
183 int vlan_id;
184 u32 next_conn_id; 173 u32 next_conn_id;
185 struct fcoe_task_ctx_entry **task_ctx; 174 struct fcoe_task_ctx_entry **task_ctx;
186 dma_addr_t *task_ctx_dma; 175 dma_addr_t *task_ctx_dma;
@@ -199,38 +188,41 @@ struct bnx2fc_hba {
199 char *dummy_buffer; 188 char *dummy_buffer;
200 dma_addr_t dummy_buf_dma; 189 dma_addr_t dummy_buf_dma;
201 190
191 /* Active list of offloaded sessions */
192 struct bnx2fc_rport **tgt_ofld_list;
193
194 /* statistics */
202 struct fcoe_statistics_params *stats_buffer; 195 struct fcoe_statistics_params *stats_buffer;
203 dma_addr_t stats_buf_dma; 196 dma_addr_t stats_buf_dma;
204 197 struct completion stat_req_done;
205 /*
206 * PCI related info.
207 */
208 u16 pci_did;
209 u16 pci_vid;
210 u16 pci_sdid;
211 u16 pci_svid;
212 u16 pci_func;
213 u16 pci_devno;
214
215 struct task_struct *l2_thread;
216
217 /* linkdown handling */
218 wait_queue_head_t shutdown_wait;
219 int wait_for_link_down;
220 198
221 /*destroy handling */ 199 /*destroy handling */
222 struct timer_list destroy_timer; 200 struct timer_list destroy_timer;
223 wait_queue_head_t destroy_wait; 201 wait_queue_head_t destroy_wait;
224 202
225 /* Active list of offloaded sessions */ 203 /* linkdown handling */
226 struct bnx2fc_rport *tgt_ofld_list[BNX2FC_NUM_MAX_SESS]; 204 wait_queue_head_t shutdown_wait;
205 int wait_for_link_down;
227 int num_ofld_sess; 206 int num_ofld_sess;
207 struct list_head vports;
208};
228 209
229 /* statistics */ 210struct bnx2fc_interface {
230 struct completion stat_req_done; 211 struct list_head list;
212 unsigned long if_flags;
213 #define BNX2FC_CTLR_INIT_DONE 0
214 struct bnx2fc_hba *hba;
215 struct net_device *netdev;
216 struct packet_type fcoe_packet_type;
217 struct packet_type fip_packet_type;
218 struct workqueue_struct *timer_work_queue;
219 struct kref kref;
220 struct fcoe_ctlr ctlr;
221 u8 vlan_enabled;
222 int vlan_id;
231}; 223};
232 224
233#define bnx2fc_from_ctlr(fip) container_of(fip, struct bnx2fc_hba, ctlr) 225#define bnx2fc_from_ctlr(fip) container_of(fip, struct bnx2fc_interface, ctlr)
234 226
235struct bnx2fc_lport { 227struct bnx2fc_lport {
236 struct list_head list; 228 struct list_head list;
@@ -262,10 +254,9 @@ struct bnx2fc_rport {
262#define BNX2FC_FLAG_DISABLED 0x3 254#define BNX2FC_FLAG_DISABLED 0x3
263#define BNX2FC_FLAG_DESTROYED 0x4 255#define BNX2FC_FLAG_DESTROYED 0x4
264#define BNX2FC_FLAG_OFLD_REQ_CMPL 0x5 256#define BNX2FC_FLAG_OFLD_REQ_CMPL 0x5
265#define BNX2FC_FLAG_DESTROY_CMPL 0x6 257#define BNX2FC_FLAG_CTX_ALLOC_FAILURE 0x6
266#define BNX2FC_FLAG_CTX_ALLOC_FAILURE 0x7 258#define BNX2FC_FLAG_UPLD_REQ_COMPL 0x7
267#define BNX2FC_FLAG_UPLD_REQ_COMPL 0x8 259#define BNX2FC_FLAG_EXPL_LOGO 0x8
268#define BNX2FC_FLAG_EXPL_LOGO 0x9
269 260
270 u8 src_addr[ETH_ALEN]; 261 u8 src_addr[ETH_ALEN];
271 u32 max_sqes; 262 u32 max_sqes;
@@ -327,12 +318,9 @@ struct bnx2fc_rport {
327 spinlock_t cq_lock; 318 spinlock_t cq_lock;
328 atomic_t num_active_ios; 319 atomic_t num_active_ios;
329 u32 flush_in_prog; 320 u32 flush_in_prog;
330 unsigned long work_time_slice;
331 unsigned long timestamp; 321 unsigned long timestamp;
332 struct list_head free_task_list; 322 struct list_head free_task_list;
333 struct bnx2fc_cmd *pending_queue[BNX2FC_SQ_WQES_MAX+1]; 323 struct bnx2fc_cmd *pending_queue[BNX2FC_SQ_WQES_MAX+1];
334 atomic_t pi;
335 atomic_t ci;
336 struct list_head active_cmd_queue; 324 struct list_head active_cmd_queue;
337 struct list_head els_queue; 325 struct list_head els_queue;
338 struct list_head io_retire_queue; 326 struct list_head io_retire_queue;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_els.c b/drivers/scsi/bnx2fc/bnx2fc_els.c
index e3f18736ba37..5d7baa2371f8 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_els.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_els.c
@@ -259,7 +259,7 @@ static int bnx2fc_initiate_els(struct bnx2fc_rport *tgt, unsigned int op,
259 struct bnx2fc_els_cb_arg *cb_arg, u32 timer_msec) 259 struct bnx2fc_els_cb_arg *cb_arg, u32 timer_msec)
260{ 260{
261 struct fcoe_port *port = tgt->port; 261 struct fcoe_port *port = tgt->port;
262 struct bnx2fc_hba *hba = port->priv; 262 struct bnx2fc_interface *interface = port->priv;
263 struct fc_rport *rport = tgt->rport; 263 struct fc_rport *rport = tgt->rport;
264 struct fc_lport *lport = port->lport; 264 struct fc_lport *lport = port->lport;
265 struct bnx2fc_cmd *els_req; 265 struct bnx2fc_cmd *els_req;
@@ -352,7 +352,8 @@ static int bnx2fc_initiate_els(struct bnx2fc_rport *tgt, unsigned int op,
352 index = xid % BNX2FC_TASKS_PER_PAGE; 352 index = xid % BNX2FC_TASKS_PER_PAGE;
353 353
354 /* Initialize task context for this IO request */ 354 /* Initialize task context for this IO request */
355 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx]; 355 task_page = (struct fcoe_task_ctx_entry *)
356 interface->hba->task_ctx[task_idx];
356 task = &(task_page[index]); 357 task = &(task_page[index]);
357 bnx2fc_init_mp_task(els_req, task); 358 bnx2fc_init_mp_task(els_req, task);
358 359
@@ -496,8 +497,8 @@ struct fc_seq *bnx2fc_elsct_send(struct fc_lport *lport, u32 did,
496 void *arg, u32 timeout) 497 void *arg, u32 timeout)
497{ 498{
498 struct fcoe_port *port = lport_priv(lport); 499 struct fcoe_port *port = lport_priv(lport);
499 struct bnx2fc_hba *hba = port->priv; 500 struct bnx2fc_interface *interface = port->priv;
500 struct fcoe_ctlr *fip = &hba->ctlr; 501 struct fcoe_ctlr *fip = &interface->ctlr;
501 struct fc_frame_header *fh = fc_frame_header_get(fp); 502 struct fc_frame_header *fh = fc_frame_header_get(fp);
502 503
503 switch (op) { 504 switch (op) {
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index e70452174f20..65561fcaad03 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -15,6 +15,7 @@
15#include "bnx2fc.h" 15#include "bnx2fc.h"
16 16
17static struct list_head adapter_list; 17static struct list_head adapter_list;
18static struct list_head if_list;
18static u32 adapter_count; 19static u32 adapter_count;
19static DEFINE_MUTEX(bnx2fc_dev_lock); 20static DEFINE_MUTEX(bnx2fc_dev_lock);
20DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu); 21DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
@@ -61,7 +62,7 @@ static int bnx2fc_disable(struct net_device *netdev);
61 62
62static void bnx2fc_recv_frame(struct sk_buff *skb); 63static void bnx2fc_recv_frame(struct sk_buff *skb);
63 64
64static void bnx2fc_start_disc(struct bnx2fc_hba *hba); 65static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
65static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev); 66static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
66static int bnx2fc_net_config(struct fc_lport *lp); 67static int bnx2fc_net_config(struct fc_lport *lp);
67static int bnx2fc_lport_config(struct fc_lport *lport); 68static int bnx2fc_lport_config(struct fc_lport *lport);
@@ -70,18 +71,20 @@ static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
70static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba); 71static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
71static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba); 72static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
72static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba); 73static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
73static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba, 74static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
74 struct device *parent, int npiv); 75 struct device *parent, int npiv);
75static void bnx2fc_destroy_work(struct work_struct *work); 76static void bnx2fc_destroy_work(struct work_struct *work);
76 77
77static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev); 78static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
79static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
80 *phys_dev);
78static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic); 81static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
79 82
80static int bnx2fc_fw_init(struct bnx2fc_hba *hba); 83static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
81static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba); 84static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
82 85
83static void bnx2fc_port_shutdown(struct fc_lport *lport); 86static void bnx2fc_port_shutdown(struct fc_lport *lport);
84static void bnx2fc_stop(struct bnx2fc_hba *hba); 87static void bnx2fc_stop(struct bnx2fc_interface *interface);
85static int __init bnx2fc_mod_init(void); 88static int __init bnx2fc_mod_init(void);
86static void __exit bnx2fc_mod_exit(void); 89static void __exit bnx2fc_mod_exit(void);
87 90
@@ -142,7 +145,8 @@ static void bnx2fc_abort_io(struct fc_lport *lport)
142static void bnx2fc_cleanup(struct fc_lport *lport) 145static void bnx2fc_cleanup(struct fc_lport *lport)
143{ 146{
144 struct fcoe_port *port = lport_priv(lport); 147 struct fcoe_port *port = lport_priv(lport);
145 struct bnx2fc_hba *hba = port->priv; 148 struct bnx2fc_interface *interface = port->priv;
149 struct bnx2fc_hba *hba = interface->hba;
146 struct bnx2fc_rport *tgt; 150 struct bnx2fc_rport *tgt;
147 int i; 151 int i;
148 152
@@ -219,7 +223,8 @@ static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
219 struct fcoe_crc_eof *cp; 223 struct fcoe_crc_eof *cp;
220 struct sk_buff *skb; 224 struct sk_buff *skb;
221 struct fc_frame_header *fh; 225 struct fc_frame_header *fh;
222 struct bnx2fc_hba *hba; 226 struct bnx2fc_interface *interface;
227 struct bnx2fc_hba *hba;
223 struct fcoe_port *port; 228 struct fcoe_port *port;
224 struct fcoe_hdr *hp; 229 struct fcoe_hdr *hp;
225 struct bnx2fc_rport *tgt; 230 struct bnx2fc_rport *tgt;
@@ -230,7 +235,8 @@ static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
230 int wlen, rc = 0; 235 int wlen, rc = 0;
231 236
232 port = (struct fcoe_port *)lport_priv(lport); 237 port = (struct fcoe_port *)lport_priv(lport);
233 hba = port->priv; 238 interface = port->priv;
239 hba = interface->hba;
234 240
235 fh = fc_frame_header_get(fp); 241 fh = fc_frame_header_get(fp);
236 242
@@ -242,12 +248,12 @@ static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
242 } 248 }
243 249
244 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) { 250 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
245 if (!hba->ctlr.sel_fcf) { 251 if (!interface->ctlr.sel_fcf) {
246 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n"); 252 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
247 kfree_skb(skb); 253 kfree_skb(skb);
248 return -EINVAL; 254 return -EINVAL;
249 } 255 }
250 if (fcoe_ctlr_els_send(&hba->ctlr, lport, skb)) 256 if (fcoe_ctlr_els_send(&interface->ctlr, lport, skb))
251 return 0; 257 return 0;
252 } 258 }
253 259
@@ -316,19 +322,19 @@ static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
316 skb_reset_network_header(skb); 322 skb_reset_network_header(skb);
317 skb->mac_len = elen; 323 skb->mac_len = elen;
318 skb->protocol = htons(ETH_P_FCOE); 324 skb->protocol = htons(ETH_P_FCOE);
319 skb->dev = hba->netdev; 325 skb->dev = interface->netdev;
320 326
321 /* fill up mac and fcoe headers */ 327 /* fill up mac and fcoe headers */
322 eh = eth_hdr(skb); 328 eh = eth_hdr(skb);
323 eh->h_proto = htons(ETH_P_FCOE); 329 eh->h_proto = htons(ETH_P_FCOE);
324 if (hba->ctlr.map_dest) 330 if (interface->ctlr.map_dest)
325 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); 331 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
326 else 332 else
327 /* insert GW address */ 333 /* insert GW address */
328 memcpy(eh->h_dest, hba->ctlr.dest_addr, ETH_ALEN); 334 memcpy(eh->h_dest, interface->ctlr.dest_addr, ETH_ALEN);
329 335
330 if (unlikely(hba->ctlr.flogi_oxid != FC_XID_UNKNOWN)) 336 if (unlikely(interface->ctlr.flogi_oxid != FC_XID_UNKNOWN))
331 memcpy(eh->h_source, hba->ctlr.ctl_src_addr, ETH_ALEN); 337 memcpy(eh->h_source, interface->ctlr.ctl_src_addr, ETH_ALEN);
332 else 338 else
333 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); 339 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
334 340
@@ -377,14 +383,15 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
377 struct packet_type *ptype, struct net_device *olddev) 383 struct packet_type *ptype, struct net_device *olddev)
378{ 384{
379 struct fc_lport *lport; 385 struct fc_lport *lport;
380 struct bnx2fc_hba *hba; 386 struct bnx2fc_interface *interface;
381 struct fc_frame_header *fh; 387 struct fc_frame_header *fh;
382 struct fcoe_rcv_info *fr; 388 struct fcoe_rcv_info *fr;
383 struct fcoe_percpu_s *bg; 389 struct fcoe_percpu_s *bg;
384 unsigned short oxid; 390 unsigned short oxid;
385 391
386 hba = container_of(ptype, struct bnx2fc_hba, fcoe_packet_type); 392 interface = container_of(ptype, struct bnx2fc_interface,
387 lport = hba->ctlr.lp; 393 fcoe_packet_type);
394 lport = interface->ctlr.lp;
388 395
389 if (unlikely(lport == NULL)) { 396 if (unlikely(lport == NULL)) {
390 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n"); 397 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
@@ -594,7 +601,8 @@ static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
594 struct fc_host_statistics *bnx2fc_stats; 601 struct fc_host_statistics *bnx2fc_stats;
595 struct fc_lport *lport = shost_priv(shost); 602 struct fc_lport *lport = shost_priv(shost);
596 struct fcoe_port *port = lport_priv(lport); 603 struct fcoe_port *port = lport_priv(lport);
597 struct bnx2fc_hba *hba = port->priv; 604 struct bnx2fc_interface *interface = port->priv;
605 struct bnx2fc_hba *hba = interface->hba;
598 struct fcoe_statistics_params *fw_stats; 606 struct fcoe_statistics_params *fw_stats;
599 int rc = 0; 607 int rc = 0;
600 608
@@ -631,7 +639,7 @@ static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
631static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev) 639static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
632{ 640{
633 struct fcoe_port *port = lport_priv(lport); 641 struct fcoe_port *port = lport_priv(lport);
634 struct bnx2fc_hba *hba = port->priv; 642 struct bnx2fc_interface *interface = port->priv;
635 struct Scsi_Host *shost = lport->host; 643 struct Scsi_Host *shost = lport->host;
636 int rc = 0; 644 int rc = 0;
637 645
@@ -654,7 +662,7 @@ static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
654 fc_host_max_npiv_vports(lport->host) = USHRT_MAX; 662 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
655 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s", 663 sprintf(fc_host_symbolic_name(lport->host), "%s v%s over %s",
656 BNX2FC_NAME, BNX2FC_VERSION, 664 BNX2FC_NAME, BNX2FC_VERSION,
657 hba->netdev->name); 665 interface->netdev->name);
658 666
659 return 0; 667 return 0;
660} 668}
@@ -662,8 +670,8 @@ static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
662static void bnx2fc_link_speed_update(struct fc_lport *lport) 670static void bnx2fc_link_speed_update(struct fc_lport *lport)
663{ 671{
664 struct fcoe_port *port = lport_priv(lport); 672 struct fcoe_port *port = lport_priv(lport);
665 struct bnx2fc_hba *hba = port->priv; 673 struct bnx2fc_interface *interface = port->priv;
666 struct net_device *netdev = hba->netdev; 674 struct net_device *netdev = interface->netdev;
667 struct ethtool_cmd ecmd; 675 struct ethtool_cmd ecmd;
668 676
669 if (!dev_ethtool_get_settings(netdev, &ecmd)) { 677 if (!dev_ethtool_get_settings(netdev, &ecmd)) {
@@ -691,7 +699,8 @@ static void bnx2fc_link_speed_update(struct fc_lport *lport)
691static int bnx2fc_link_ok(struct fc_lport *lport) 699static int bnx2fc_link_ok(struct fc_lport *lport)
692{ 700{
693 struct fcoe_port *port = lport_priv(lport); 701 struct fcoe_port *port = lport_priv(lport);
694 struct bnx2fc_hba *hba = port->priv; 702 struct bnx2fc_interface *interface = port->priv;
703 struct bnx2fc_hba *hba = interface->hba;
695 struct net_device *dev = hba->phys_dev; 704 struct net_device *dev = hba->phys_dev;
696 int rc = 0; 705 int rc = 0;
697 706
@@ -713,7 +722,7 @@ static int bnx2fc_link_ok(struct fc_lport *lport)
713 */ 722 */
714void bnx2fc_get_link_state(struct bnx2fc_hba *hba) 723void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
715{ 724{
716 if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state)) 725 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
717 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); 726 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
718 else 727 else
719 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state); 728 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
@@ -722,11 +731,13 @@ void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
722static int bnx2fc_net_config(struct fc_lport *lport) 731static int bnx2fc_net_config(struct fc_lport *lport)
723{ 732{
724 struct bnx2fc_hba *hba; 733 struct bnx2fc_hba *hba;
734 struct bnx2fc_interface *interface;
725 struct fcoe_port *port; 735 struct fcoe_port *port;
726 u64 wwnn, wwpn; 736 u64 wwnn, wwpn;
727 737
728 port = lport_priv(lport); 738 port = lport_priv(lport);
729 hba = port->priv; 739 interface = port->priv;
740 hba = interface->hba;
730 741
731 /* require support for get_pauseparam ethtool op. */ 742 /* require support for get_pauseparam ethtool op. */
732 if (!hba->phys_dev->ethtool_ops || 743 if (!hba->phys_dev->ethtool_ops ||
@@ -743,11 +754,11 @@ static int bnx2fc_net_config(struct fc_lport *lport)
743 bnx2fc_link_speed_update(lport); 754 bnx2fc_link_speed_update(lport);
744 755
745 if (!lport->vport) { 756 if (!lport->vport) {
746 wwnn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 1, 0); 757 wwnn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 1, 0);
747 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn); 758 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
748 fc_set_wwnn(lport, wwnn); 759 fc_set_wwnn(lport, wwnn);
749 760
750 wwpn = fcoe_wwn_from_mac(hba->ctlr.ctl_src_addr, 2, 0); 761 wwpn = fcoe_wwn_from_mac(interface->ctlr.ctl_src_addr, 2, 0);
751 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn); 762 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
752 fc_set_wwpn(lport, wwpn); 763 fc_set_wwpn(lport, wwpn);
753 } 764 }
@@ -759,9 +770,9 @@ static void bnx2fc_destroy_timer(unsigned long data)
759{ 770{
760 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data; 771 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)data;
761 772
762 BNX2FC_HBA_DBG(hba->ctlr.lp, "ERROR:bnx2fc_destroy_timer - " 773 BNX2FC_MISC_DBG("ERROR:bnx2fc_destroy_timer - "
763 "Destroy compl not received!!\n"); 774 "Destroy compl not received!!\n");
764 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL; 775 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
765 wake_up_interruptible(&hba->destroy_wait); 776 wake_up_interruptible(&hba->destroy_wait);
766} 777}
767 778
@@ -779,54 +790,35 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
779 u16 vlan_id) 790 u16 vlan_id)
780{ 791{
781 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context; 792 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
782 struct fc_lport *lport = hba->ctlr.lp; 793 struct fc_lport *lport;
783 struct fc_lport *vport; 794 struct fc_lport *vport;
795 struct bnx2fc_interface *interface;
796 int wait_for_upload = 0;
784 u32 link_possible = 1; 797 u32 link_possible = 1;
785 798
786 /* Ignore vlans for now */ 799 /* Ignore vlans for now */
787 if (vlan_id != 0) 800 if (vlan_id != 0)
788 return; 801 return;
789 802
790 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
791 BNX2FC_MISC_DBG("driver not ready. event=%s %ld\n",
792 hba->netdev->name, event);
793 return;
794 }
795
796 /*
797 * ASSUMPTION:
798 * indicate_netevent cannot be called from cnic unless bnx2fc
799 * does register_device
800 */
801 BUG_ON(!lport);
802
803 BNX2FC_HBA_DBG(lport, "enter netevent handler - event=%s %ld\n",
804 hba->netdev->name, event);
805
806 switch (event) { 803 switch (event) {
807 case NETDEV_UP: 804 case NETDEV_UP:
808 BNX2FC_HBA_DBG(lport, "Port up, adapter_state = %ld\n",
809 hba->adapter_state);
810 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) 805 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
811 printk(KERN_ERR "indicate_netevent: "\ 806 printk(KERN_ERR "indicate_netevent: "\
812 "adapter is not UP!!\n"); 807 "hba is not UP!!\n");
813 break; 808 break;
814 809
815 case NETDEV_DOWN: 810 case NETDEV_DOWN:
816 BNX2FC_HBA_DBG(lport, "Port down\n");
817 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); 811 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
818 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); 812 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
819 link_possible = 0; 813 link_possible = 0;
820 break; 814 break;
821 815
822 case NETDEV_GOING_DOWN: 816 case NETDEV_GOING_DOWN:
823 BNX2FC_HBA_DBG(lport, "Port going down\n");
824 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); 817 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
825 link_possible = 0; 818 link_possible = 0;
826 break; 819 break;
827 820
828 case NETDEV_CHANGE: 821 case NETDEV_CHANGE:
829 BNX2FC_HBA_DBG(lport, "NETDEV_CHANGE\n");
830 break; 822 break;
831 823
832 default: 824 default:
@@ -834,15 +826,22 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
834 return; 826 return;
835 } 827 }
836 828
837 bnx2fc_link_speed_update(lport); 829 mutex_lock(&bnx2fc_dev_lock);
830 list_for_each_entry(interface, &if_list, list) {
838 831
839 if (link_possible && !bnx2fc_link_ok(lport)) { 832 if (interface->hba != hba)
840 printk(KERN_ERR "indicate_netevent: call ctlr_link_up\n"); 833 continue;
841 fcoe_ctlr_link_up(&hba->ctlr); 834
842 } else { 835 lport = interface->ctlr.lp;
843 printk(KERN_ERR "indicate_netevent: call ctlr_link_down\n"); 836 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
844 if (fcoe_ctlr_link_down(&hba->ctlr)) { 837 interface->netdev->name, event);
845 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); 838
839 bnx2fc_link_speed_update(lport);
840
841 if (link_possible && !bnx2fc_link_ok(lport)) {
842 printk(KERN_ERR "indicate_netevent: ctlr_link_up\n");
843 fcoe_ctlr_link_up(&interface->ctlr);
844 } else if (fcoe_ctlr_link_down(&interface->ctlr)) {
846 mutex_lock(&lport->lp_mutex); 845 mutex_lock(&lport->lp_mutex);
847 list_for_each_entry(vport, &lport->vports, list) 846 list_for_each_entry(vport, &lport->vports, list)
848 fc_host_port_type(vport->host) = 847 fc_host_port_type(vport->host) =
@@ -853,24 +852,26 @@ static void bnx2fc_indicate_netevent(void *context, unsigned long event,
853 get_cpu())->LinkFailureCount++; 852 get_cpu())->LinkFailureCount++;
854 put_cpu(); 853 put_cpu();
855 fcoe_clean_pending_queue(lport); 854 fcoe_clean_pending_queue(lport);
855 wait_for_upload = 1;
856 }
857 }
858 mutex_unlock(&bnx2fc_dev_lock);
856 859
857 init_waitqueue_head(&hba->shutdown_wait); 860 if (wait_for_upload) {
858 BNX2FC_HBA_DBG(lport, "indicate_netevent " 861 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
859 "num_ofld_sess = %d\n", 862 init_waitqueue_head(&hba->shutdown_wait);
860 hba->num_ofld_sess); 863 BNX2FC_MISC_DBG("indicate_netevent "
861 hba->wait_for_link_down = 1; 864 "num_ofld_sess = %d\n",
862 BNX2FC_HBA_DBG(lport, "waiting for uploads to " 865 hba->num_ofld_sess);
863 "compl proc = %s\n", 866 hba->wait_for_link_down = 1;
864 current->comm); 867 wait_event_interruptible(hba->shutdown_wait,
865 wait_event_interruptible(hba->shutdown_wait, 868 (hba->num_ofld_sess == 0));
866 (hba->num_ofld_sess == 0)); 869 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
867 BNX2FC_HBA_DBG(lport, "wakeup - num_ofld_sess = %d\n",
868 hba->num_ofld_sess); 870 hba->num_ofld_sess);
869 hba->wait_for_link_down = 0; 871 hba->wait_for_link_down = 0;
870 872
871 if (signal_pending(current)) 873 if (signal_pending(current))
872 flush_signals(current); 874 flush_signals(current);
873 }
874 } 875 }
875} 876}
876 877
@@ -889,23 +890,12 @@ static int bnx2fc_libfc_config(struct fc_lport *lport)
889 890
890static int bnx2fc_em_config(struct fc_lport *lport) 891static int bnx2fc_em_config(struct fc_lport *lport)
891{ 892{
892 struct fcoe_port *port = lport_priv(lport);
893 struct bnx2fc_hba *hba = port->priv;
894
895 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID, 893 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, FCOE_MIN_XID,
896 FCOE_MAX_XID, NULL)) { 894 FCOE_MAX_XID, NULL)) {
897 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n"); 895 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
898 return -ENOMEM; 896 return -ENOMEM;
899 } 897 }
900 898
901 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
902 BNX2FC_MAX_XID);
903
904 if (!hba->cmd_mgr) {
905 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
906 fc_exch_mgr_free(lport);
907 return -ENOMEM;
908 }
909 return 0; 899 return 0;
910} 900}
911 901
@@ -952,9 +942,10 @@ static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
952 struct packet_type *ptype, 942 struct packet_type *ptype,
953 struct net_device *orig_dev) 943 struct net_device *orig_dev)
954{ 944{
955 struct bnx2fc_hba *hba; 945 struct bnx2fc_interface *interface;
956 hba = container_of(ptype, struct bnx2fc_hba, fip_packet_type); 946 interface = container_of(ptype, struct bnx2fc_interface,
957 fcoe_ctlr_recv(&hba->ctlr, skb); 947 fip_packet_type);
948 fcoe_ctlr_recv(&interface->ctlr, skb);
958 return 0; 949 return 0;
959} 950}
960 951
@@ -1005,17 +996,17 @@ static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1005 struct Scsi_Host *shost = vport_to_shost(vport); 996 struct Scsi_Host *shost = vport_to_shost(vport);
1006 struct fc_lport *n_port = shost_priv(shost); 997 struct fc_lport *n_port = shost_priv(shost);
1007 struct fcoe_port *port = lport_priv(n_port); 998 struct fcoe_port *port = lport_priv(n_port);
1008 struct bnx2fc_hba *hba = port->priv; 999 struct bnx2fc_interface *interface = port->priv;
1009 struct net_device *netdev = hba->netdev; 1000 struct net_device *netdev = interface->netdev;
1010 struct fc_lport *vn_port; 1001 struct fc_lport *vn_port;
1011 1002
1012 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { 1003 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1013 printk(KERN_ERR PFX "vn ports cannot be created on" 1004 printk(KERN_ERR PFX "vn ports cannot be created on"
1014 "this hba\n"); 1005 "this interface\n");
1015 return -EIO; 1006 return -EIO;
1016 } 1007 }
1017 mutex_lock(&bnx2fc_dev_lock); 1008 mutex_lock(&bnx2fc_dev_lock);
1018 vn_port = bnx2fc_if_create(hba, &vport->dev, 1); 1009 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1019 mutex_unlock(&bnx2fc_dev_lock); 1010 mutex_unlock(&bnx2fc_dev_lock);
1020 1011
1021 if (IS_ERR(vn_port)) { 1012 if (IS_ERR(vn_port)) {
@@ -1065,10 +1056,10 @@ static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1065} 1056}
1066 1057
1067 1058
1068static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba) 1059static int bnx2fc_netdev_setup(struct bnx2fc_interface *interface)
1069{ 1060{
1070 struct net_device *netdev = hba->netdev; 1061 struct net_device *netdev = interface->netdev;
1071 struct net_device *physdev = hba->phys_dev; 1062 struct net_device *physdev = interface->hba->phys_dev;
1072 struct netdev_hw_addr *ha; 1063 struct netdev_hw_addr *ha;
1073 int sel_san_mac = 0; 1064 int sel_san_mac = 0;
1074 1065
@@ -1083,7 +1074,8 @@ static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba)
1083 1074
1084 if ((ha->type == NETDEV_HW_ADDR_T_SAN) && 1075 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1085 (is_valid_ether_addr(ha->addr))) { 1076 (is_valid_ether_addr(ha->addr))) {
1086 memcpy(hba->ctlr.ctl_src_addr, ha->addr, ETH_ALEN); 1077 memcpy(interface->ctlr.ctl_src_addr, ha->addr,
1078 ETH_ALEN);
1087 sel_san_mac = 1; 1079 sel_san_mac = 1;
1088 BNX2FC_MISC_DBG("Found SAN MAC\n"); 1080 BNX2FC_MISC_DBG("Found SAN MAC\n");
1089 } 1081 }
@@ -1093,15 +1085,15 @@ static int bnx2fc_netdev_setup(struct bnx2fc_hba *hba)
1093 if (!sel_san_mac) 1085 if (!sel_san_mac)
1094 return -ENODEV; 1086 return -ENODEV;
1095 1087
1096 hba->fip_packet_type.func = bnx2fc_fip_recv; 1088 interface->fip_packet_type.func = bnx2fc_fip_recv;
1097 hba->fip_packet_type.type = htons(ETH_P_FIP); 1089 interface->fip_packet_type.type = htons(ETH_P_FIP);
1098 hba->fip_packet_type.dev = netdev; 1090 interface->fip_packet_type.dev = netdev;
1099 dev_add_pack(&hba->fip_packet_type); 1091 dev_add_pack(&interface->fip_packet_type);
1100 1092
1101 hba->fcoe_packet_type.func = bnx2fc_rcv; 1093 interface->fcoe_packet_type.func = bnx2fc_rcv;
1102 hba->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); 1094 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1103 hba->fcoe_packet_type.dev = netdev; 1095 interface->fcoe_packet_type.dev = netdev;
1104 dev_add_pack(&hba->fcoe_packet_type); 1096 dev_add_pack(&interface->fcoe_packet_type);
1105 1097
1106 return 0; 1098 return 0;
1107} 1099}
@@ -1137,53 +1129,54 @@ static void bnx2fc_release_transport(void)
1137 1129
1138static void bnx2fc_interface_release(struct kref *kref) 1130static void bnx2fc_interface_release(struct kref *kref)
1139{ 1131{
1140 struct bnx2fc_hba *hba; 1132 struct bnx2fc_interface *interface;
1141 struct net_device *netdev; 1133 struct net_device *netdev;
1142 struct net_device *phys_dev;
1143 1134
1144 hba = container_of(kref, struct bnx2fc_hba, kref); 1135 interface = container_of(kref, struct bnx2fc_interface, kref);
1145 BNX2FC_MISC_DBG("Interface is being released\n"); 1136 BNX2FC_MISC_DBG("Interface is being released\n");
1146 1137
1147 netdev = hba->netdev; 1138 netdev = interface->netdev;
1148 phys_dev = hba->phys_dev;
1149 1139
1150 /* tear-down FIP controller */ 1140 /* tear-down FIP controller */
1151 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done)) 1141 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1152 fcoe_ctlr_destroy(&hba->ctlr); 1142 fcoe_ctlr_destroy(&interface->ctlr);
1143
1144 kfree(interface);
1153 1145
1154 /* Free the command manager */
1155 if (hba->cmd_mgr) {
1156 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1157 hba->cmd_mgr = NULL;
1158 }
1159 dev_put(netdev); 1146 dev_put(netdev);
1160 module_put(THIS_MODULE); 1147 module_put(THIS_MODULE);
1161} 1148}
1162 1149
1163static inline void bnx2fc_interface_get(struct bnx2fc_hba *hba) 1150static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1164{ 1151{
1165 kref_get(&hba->kref); 1152 kref_get(&interface->kref);
1166} 1153}
1167 1154
1168static inline void bnx2fc_interface_put(struct bnx2fc_hba *hba) 1155static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1169{ 1156{
1170 kref_put(&hba->kref, bnx2fc_interface_release); 1157 kref_put(&interface->kref, bnx2fc_interface_release);
1171} 1158}
1172static void bnx2fc_interface_destroy(struct bnx2fc_hba *hba) 1159static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1173{ 1160{
1161 /* Free the command manager */
1162 if (hba->cmd_mgr) {
1163 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1164 hba->cmd_mgr = NULL;
1165 }
1166 kfree(hba->tgt_ofld_list);
1174 bnx2fc_unbind_pcidev(hba); 1167 bnx2fc_unbind_pcidev(hba);
1175 kfree(hba); 1168 kfree(hba);
1176} 1169}
1177 1170
1178/** 1171/**
1179 * bnx2fc_interface_create - create a new fcoe instance 1172 * bnx2fc_hba_create - create a new bnx2fc hba
1180 * 1173 *
1181 * @cnic: pointer to cnic device 1174 * @cnic: pointer to cnic device
1182 * 1175 *
1183 * Creates a new FCoE instance on the given device which include allocating 1176 * Creates a new FCoE hba on the given device.
1184 * hba structure, scsi_host and lport structures. 1177 *
1185 */ 1178 */
1186static struct bnx2fc_hba *bnx2fc_interface_create(struct cnic_dev *cnic) 1179static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1187{ 1180{
1188 struct bnx2fc_hba *hba; 1181 struct bnx2fc_hba *hba;
1189 int rc; 1182 int rc;
@@ -1198,65 +1191,83 @@ static struct bnx2fc_hba *bnx2fc_interface_create(struct cnic_dev *cnic)
1198 1191
1199 hba->cnic = cnic; 1192 hba->cnic = cnic;
1200 rc = bnx2fc_bind_pcidev(hba); 1193 rc = bnx2fc_bind_pcidev(hba);
1201 if (rc) 1194 if (rc) {
1195 printk(KERN_ERR PFX "create_adapter: bind error\n");
1202 goto bind_err; 1196 goto bind_err;
1197 }
1203 hba->phys_dev = cnic->netdev; 1198 hba->phys_dev = cnic->netdev;
1204 /* will get overwritten after we do vlan discovery */ 1199 hba->next_conn_id = 0;
1205 hba->netdev = hba->phys_dev; 1200
1201 hba->tgt_ofld_list =
1202 kzalloc(sizeof(struct bnx2fc_rport *) * BNX2FC_NUM_MAX_SESS,
1203 GFP_KERNEL);
1204 if (!hba->tgt_ofld_list) {
1205 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1206 goto tgtofld_err;
1207 }
1208
1209 hba->num_ofld_sess = 0;
1210
1211 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba, BNX2FC_MIN_XID,
1212 BNX2FC_MAX_XID);
1213 if (!hba->cmd_mgr) {
1214 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1215 goto cmgr_err;
1216 }
1206 1217
1207 init_waitqueue_head(&hba->shutdown_wait); 1218 init_waitqueue_head(&hba->shutdown_wait);
1208 init_waitqueue_head(&hba->destroy_wait); 1219 init_waitqueue_head(&hba->destroy_wait);
1220 INIT_LIST_HEAD(&hba->vports);
1209 1221
1210 return hba; 1222 return hba;
1223
1224cmgr_err:
1225 kfree(hba->tgt_ofld_list);
1226tgtofld_err:
1227 bnx2fc_unbind_pcidev(hba);
1211bind_err: 1228bind_err:
1212 printk(KERN_ERR PFX "create_interface: bind error\n");
1213 kfree(hba); 1229 kfree(hba);
1214 return NULL; 1230 return NULL;
1215} 1231}
1216 1232
1217static int bnx2fc_interface_setup(struct bnx2fc_hba *hba, 1233struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1218 enum fip_state fip_mode) 1234 struct net_device *netdev,
1235 enum fip_state fip_mode)
1219{ 1236{
1237 struct bnx2fc_interface *interface;
1220 int rc = 0; 1238 int rc = 0;
1221 struct net_device *netdev = hba->netdev;
1222 struct fcoe_ctlr *fip = &hba->ctlr;
1223 1239
1240 interface = kzalloc(sizeof(*interface), GFP_KERNEL);
1241 if (!interface) {
1242 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1243 return NULL;
1244 }
1224 dev_hold(netdev); 1245 dev_hold(netdev);
1225 kref_init(&hba->kref); 1246 kref_init(&interface->kref);
1226 1247 interface->hba = hba;
1227 hba->flags = 0; 1248 interface->netdev = netdev;
1228 1249
1229 /* Initialize FIP */ 1250 /* Initialize FIP */
1230 memset(fip, 0, sizeof(*fip)); 1251 fcoe_ctlr_init(&interface->ctlr, fip_mode);
1231 fcoe_ctlr_init(fip, fip_mode); 1252 interface->ctlr.send = bnx2fc_fip_send;
1232 hba->ctlr.send = bnx2fc_fip_send; 1253 interface->ctlr.update_mac = bnx2fc_update_src_mac;
1233 hba->ctlr.update_mac = bnx2fc_update_src_mac; 1254 interface->ctlr.get_src_addr = bnx2fc_get_src_mac;
1234 hba->ctlr.get_src_addr = bnx2fc_get_src_mac; 1255 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1235 set_bit(BNX2FC_CTLR_INIT_DONE, &hba->init_done);
1236
1237 INIT_LIST_HEAD(&hba->vports);
1238 rc = bnx2fc_netdev_setup(hba);
1239 if (rc)
1240 goto setup_err;
1241 1256
1242 hba->next_conn_id = 0; 1257 rc = bnx2fc_netdev_setup(interface);
1258 if (!rc)
1259 return interface;
1243 1260
1244 memset(hba->tgt_ofld_list, 0, sizeof(hba->tgt_ofld_list)); 1261 fcoe_ctlr_destroy(&interface->ctlr);
1245 hba->num_ofld_sess = 0;
1246
1247 return 0;
1248
1249setup_err:
1250 fcoe_ctlr_destroy(&hba->ctlr);
1251 dev_put(netdev); 1262 dev_put(netdev);
1252 bnx2fc_interface_put(hba); 1263 kfree(interface);
1253 return rc; 1264 return NULL;
1254} 1265}
1255 1266
1256/** 1267/**
1257 * bnx2fc_if_create - Create FCoE instance on a given interface 1268 * bnx2fc_if_create - Create FCoE instance on a given interface
1258 * 1269 *
1259 * @hba: FCoE interface to create a local port on 1270 * @interface: FCoE interface to create a local port on
1260 * @parent: Device pointer to be the parent in sysfs for the SCSI host 1271 * @parent: Device pointer to be the parent in sysfs for the SCSI host
1261 * @npiv: Indicates if the port is vport or not 1272 * @npiv: Indicates if the port is vport or not
1262 * 1273 *
@@ -1264,7 +1275,7 @@ setup_err:
1264 * 1275 *
1265 * Returns: Allocated fc_lport or an error pointer 1276 * Returns: Allocated fc_lport or an error pointer
1266 */ 1277 */
1267static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba, 1278static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1268 struct device *parent, int npiv) 1279 struct device *parent, int npiv)
1269{ 1280{
1270 struct fc_lport *lport, *n_port; 1281 struct fc_lport *lport, *n_port;
@@ -1272,11 +1283,12 @@ static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1272 struct Scsi_Host *shost; 1283 struct Scsi_Host *shost;
1273 struct fc_vport *vport = dev_to_vport(parent); 1284 struct fc_vport *vport = dev_to_vport(parent);
1274 struct bnx2fc_lport *blport; 1285 struct bnx2fc_lport *blport;
1286 struct bnx2fc_hba *hba;
1275 int rc = 0; 1287 int rc = 0;
1276 1288
1277 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL); 1289 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1278 if (!blport) { 1290 if (!blport) {
1279 BNX2FC_HBA_DBG(hba->ctlr.lp, "Unable to alloc bnx2fc_lport\n"); 1291 BNX2FC_HBA_DBG(interface->ctlr.lp, "Unable to alloc blport\n");
1280 return NULL; 1292 return NULL;
1281 } 1293 }
1282 1294
@@ -1293,7 +1305,7 @@ static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1293 shost = lport->host; 1305 shost = lport->host;
1294 port = lport_priv(lport); 1306 port = lport_priv(lport);
1295 port->lport = lport; 1307 port->lport = lport;
1296 port->priv = hba; 1308 port->priv = interface;
1297 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work); 1309 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1298 1310
1299 /* Configure fcoe_port */ 1311 /* Configure fcoe_port */
@@ -1317,7 +1329,7 @@ static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1317 rc = bnx2fc_shost_config(lport, parent); 1329 rc = bnx2fc_shost_config(lport, parent);
1318 if (rc) { 1330 if (rc) {
1319 printk(KERN_ERR PFX "Couldnt configure shost for %s\n", 1331 printk(KERN_ERR PFX "Couldnt configure shost for %s\n",
1320 hba->netdev->name); 1332 interface->netdev->name);
1321 goto lp_config_err; 1333 goto lp_config_err;
1322 } 1334 }
1323 1335
@@ -1343,8 +1355,9 @@ static struct fc_lport *bnx2fc_if_create(struct bnx2fc_hba *hba,
1343 goto shost_err; 1355 goto shost_err;
1344 } 1356 }
1345 1357
1346 bnx2fc_interface_get(hba); 1358 bnx2fc_interface_get(interface);
1347 1359
1360 hba = interface->hba;
1348 spin_lock_bh(&hba->hba_lock); 1361 spin_lock_bh(&hba->hba_lock);
1349 blport->lport = lport; 1362 blport->lport = lport;
1350 list_add_tail(&blport->list, &hba->vports); 1363 list_add_tail(&blport->list, &hba->vports);
@@ -1361,21 +1374,19 @@ free_blport:
1361 return NULL; 1374 return NULL;
1362} 1375}
1363 1376
1364static void bnx2fc_netdev_cleanup(struct bnx2fc_hba *hba) 1377static void bnx2fc_netdev_cleanup(struct bnx2fc_interface *interface)
1365{ 1378{
1366 /* Dont listen for Ethernet packets anymore */ 1379 /* Dont listen for Ethernet packets anymore */
1367 __dev_remove_pack(&hba->fcoe_packet_type); 1380 __dev_remove_pack(&interface->fcoe_packet_type);
1368 __dev_remove_pack(&hba->fip_packet_type); 1381 __dev_remove_pack(&interface->fip_packet_type);
1369 synchronize_net(); 1382 synchronize_net();
1370} 1383}
1371 1384
1372static void bnx2fc_if_destroy(struct fc_lport *lport) 1385static void bnx2fc_if_destroy(struct fc_lport *lport, struct bnx2fc_hba *hba)
1373{ 1386{
1374 struct fcoe_port *port = lport_priv(lport); 1387 struct fcoe_port *port = lport_priv(lport);
1375 struct bnx2fc_hba *hba = port->priv;
1376 struct bnx2fc_lport *blport, *tmp; 1388 struct bnx2fc_lport *blport, *tmp;
1377 1389
1378 BNX2FC_HBA_DBG(hba->ctlr.lp, "ENTERED bnx2fc_if_destroy\n");
1379 /* Stop the transmit retry timer */ 1390 /* Stop the transmit retry timer */
1380 del_timer_sync(&port->timer); 1391 del_timer_sync(&port->timer);
1381 1392
@@ -1409,8 +1420,6 @@ static void bnx2fc_if_destroy(struct fc_lport *lport)
1409 1420
1410 /* Release Scsi_Host */ 1421 /* Release Scsi_Host */
1411 scsi_host_put(lport->host); 1422 scsi_host_put(lport->host);
1412
1413 bnx2fc_interface_put(hba);
1414} 1423}
1415 1424
1416/** 1425/**
@@ -1425,46 +1434,31 @@ static void bnx2fc_if_destroy(struct fc_lport *lport)
1425 */ 1434 */
1426static int bnx2fc_destroy(struct net_device *netdev) 1435static int bnx2fc_destroy(struct net_device *netdev)
1427{ 1436{
1428 struct bnx2fc_hba *hba = NULL; 1437 struct bnx2fc_interface *interface = NULL;
1429 struct net_device *phys_dev; 1438 struct bnx2fc_hba *hba;
1439 struct fc_lport *lport;
1430 int rc = 0; 1440 int rc = 0;
1431 1441
1432 rtnl_lock(); 1442 rtnl_lock();
1433
1434 mutex_lock(&bnx2fc_dev_lock); 1443 mutex_lock(&bnx2fc_dev_lock);
1435 /* obtain physical netdev */
1436 if (netdev->priv_flags & IFF_802_1Q_VLAN)
1437 phys_dev = vlan_dev_real_dev(netdev);
1438 else {
1439 printk(KERN_ERR PFX "Not a vlan device\n");
1440 rc = -ENODEV;
1441 goto netdev_err;
1442 }
1443 1444
1444 hba = bnx2fc_hba_lookup(phys_dev); 1445 interface = bnx2fc_interface_lookup(netdev);
1445 if (!hba || !hba->ctlr.lp) { 1446 if (!interface || !interface->ctlr.lp) {
1446 rc = -ENODEV; 1447 rc = -ENODEV;
1447 printk(KERN_ERR PFX "bnx2fc_destroy: hba or lport not found\n"); 1448 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1448 goto netdev_err;
1449 }
1450
1451 if (!test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1452 printk(KERN_ERR PFX "bnx2fc_destroy: Create not called\n");
1453 goto netdev_err; 1449 goto netdev_err;
1454 } 1450 }
1455 1451
1456 bnx2fc_netdev_cleanup(hba); 1452 hba = interface->hba;
1457
1458 bnx2fc_stop(hba);
1459
1460 bnx2fc_if_destroy(hba->ctlr.lp);
1461 1453
1462 destroy_workqueue(hba->timer_work_queue); 1454 bnx2fc_netdev_cleanup(interface);
1455 lport = interface->ctlr.lp;
1456 bnx2fc_stop(interface);
1457 list_del(&interface->list);
1458 destroy_workqueue(interface->timer_work_queue);
1459 bnx2fc_interface_put(interface);
1460 bnx2fc_if_destroy(lport, hba);
1463 1461
1464 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done))
1465 bnx2fc_fw_destroy(hba);
1466
1467 clear_bit(BNX2FC_CREATE_DONE, &hba->init_done);
1468netdev_err: 1462netdev_err:
1469 mutex_unlock(&bnx2fc_dev_lock); 1463 mutex_unlock(&bnx2fc_dev_lock);
1470 rtnl_unlock(); 1464 rtnl_unlock();
@@ -1475,16 +1469,20 @@ static void bnx2fc_destroy_work(struct work_struct *work)
1475{ 1469{
1476 struct fcoe_port *port; 1470 struct fcoe_port *port;
1477 struct fc_lport *lport; 1471 struct fc_lport *lport;
1472 struct bnx2fc_interface *interface;
1473 struct bnx2fc_hba *hba;
1478 1474
1479 port = container_of(work, struct fcoe_port, destroy_work); 1475 port = container_of(work, struct fcoe_port, destroy_work);
1480 lport = port->lport; 1476 lport = port->lport;
1477 interface = port->priv;
1478 hba = interface->hba;
1481 1479
1482 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n"); 1480 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1483 1481
1484 bnx2fc_port_shutdown(lport); 1482 bnx2fc_port_shutdown(lport);
1485 rtnl_lock(); 1483 rtnl_lock();
1486 mutex_lock(&bnx2fc_dev_lock); 1484 mutex_lock(&bnx2fc_dev_lock);
1487 bnx2fc_if_destroy(lport); 1485 bnx2fc_if_destroy(lport, hba);
1488 mutex_unlock(&bnx2fc_dev_lock); 1486 mutex_unlock(&bnx2fc_dev_lock);
1489 rtnl_unlock(); 1487 rtnl_unlock();
1490} 1488}
@@ -1556,28 +1554,27 @@ static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1556static void bnx2fc_ulp_start(void *handle) 1554static void bnx2fc_ulp_start(void *handle)
1557{ 1555{
1558 struct bnx2fc_hba *hba = handle; 1556 struct bnx2fc_hba *hba = handle;
1559 struct fc_lport *lport = hba->ctlr.lp; 1557 struct bnx2fc_interface *interface;
1558 struct fc_lport *lport;
1560 1559
1561 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1562 mutex_lock(&bnx2fc_dev_lock); 1560 mutex_lock(&bnx2fc_dev_lock);
1563 1561
1564 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) 1562 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1565 goto start_disc;
1566
1567 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done))
1568 bnx2fc_fw_init(hba); 1563 bnx2fc_fw_init(hba);
1569 1564
1570start_disc:
1571 mutex_unlock(&bnx2fc_dev_lock);
1572
1573 BNX2FC_MISC_DBG("bnx2fc started.\n"); 1565 BNX2FC_MISC_DBG("bnx2fc started.\n");
1574 1566
1575 /* Kick off Fabric discovery*/ 1567 list_for_each_entry(interface, &if_list, list) {
1576 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { 1568 if (interface->hba == hba) {
1577 printk(KERN_ERR PFX "ulp_init: start discovery\n"); 1569 lport = interface->ctlr.lp;
1578 lport->tt.frame_send = bnx2fc_xmit; 1570 /* Kick off Fabric discovery*/
1579 bnx2fc_start_disc(hba); 1571 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1572 lport->tt.frame_send = bnx2fc_xmit;
1573 bnx2fc_start_disc(interface);
1574 }
1580 } 1575 }
1576
1577 mutex_unlock(&bnx2fc_dev_lock);
1581} 1578}
1582 1579
1583static void bnx2fc_port_shutdown(struct fc_lport *lport) 1580static void bnx2fc_port_shutdown(struct fc_lport *lport)
@@ -1587,37 +1584,25 @@ static void bnx2fc_port_shutdown(struct fc_lport *lport)
1587 fc_lport_destroy(lport); 1584 fc_lport_destroy(lport);
1588} 1585}
1589 1586
1590static void bnx2fc_stop(struct bnx2fc_hba *hba) 1587static void bnx2fc_stop(struct bnx2fc_interface *interface)
1591{ 1588{
1592 struct fc_lport *lport; 1589 struct fc_lport *lport;
1593 struct fc_lport *vport; 1590 struct fc_lport *vport;
1594 1591
1595 BNX2FC_MISC_DBG("ENTERED %s - init_done = %ld\n", __func__, 1592 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1596 hba->init_done); 1593 return;
1597 if (test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done) &&
1598 test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1599 lport = hba->ctlr.lp;
1600 bnx2fc_port_shutdown(lport);
1601 BNX2FC_HBA_DBG(lport, "bnx2fc_stop: waiting for %d "
1602 "offloaded sessions\n",
1603 hba->num_ofld_sess);
1604 wait_event_interruptible(hba->shutdown_wait,
1605 (hba->num_ofld_sess == 0));
1606 mutex_lock(&lport->lp_mutex);
1607 list_for_each_entry(vport, &lport->vports, list)
1608 fc_host_port_type(vport->host) = FC_PORTTYPE_UNKNOWN;
1609 mutex_unlock(&lport->lp_mutex);
1610 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1611 fcoe_ctlr_link_down(&hba->ctlr);
1612 fcoe_clean_pending_queue(lport);
1613
1614 mutex_lock(&hba->hba_mutex);
1615 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1616 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
1617 1594
1618 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state); 1595 lport = interface->ctlr.lp;
1619 mutex_unlock(&hba->hba_mutex); 1596 bnx2fc_port_shutdown(lport);
1620 } 1597
1598 mutex_lock(&lport->lp_mutex);
1599 list_for_each_entry(vport, &lport->vports, list)
1600 fc_host_port_type(vport->host) =
1601 FC_PORTTYPE_UNKNOWN;
1602 mutex_unlock(&lport->lp_mutex);
1603 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1604 fcoe_ctlr_link_down(&interface->ctlr);
1605 fcoe_clean_pending_queue(lport);
1621} 1606}
1622 1607
1623static int bnx2fc_fw_init(struct bnx2fc_hba *hba) 1608static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
@@ -1656,8 +1641,7 @@ static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1656 } 1641 }
1657 1642
1658 1643
1659 /* Mark HBA to indicate that the FW INIT is done */ 1644 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1660 set_bit(BNX2FC_FW_INIT_DONE, &hba->init_done);
1661 return 0; 1645 return 0;
1662 1646
1663err_unbind: 1647err_unbind:
@@ -1668,7 +1652,7 @@ err_out:
1668 1652
1669static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba) 1653static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1670{ 1654{
1671 if (test_and_clear_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { 1655 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1672 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) { 1656 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1673 init_timer(&hba->destroy_timer); 1657 init_timer(&hba->destroy_timer);
1674 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT + 1658 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
@@ -1677,8 +1661,8 @@ static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1677 hba->destroy_timer.data = (unsigned long)hba; 1661 hba->destroy_timer.data = (unsigned long)hba;
1678 add_timer(&hba->destroy_timer); 1662 add_timer(&hba->destroy_timer);
1679 wait_event_interruptible(hba->destroy_wait, 1663 wait_event_interruptible(hba->destroy_wait,
1680 (hba->flags & 1664 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1681 BNX2FC_FLAG_DESTROY_CMPL)); 1665 &hba->flags));
1682 /* This should never happen */ 1666 /* This should never happen */
1683 if (signal_pending(current)) 1667 if (signal_pending(current))
1684 flush_signals(current); 1668 flush_signals(current);
@@ -1699,40 +1683,57 @@ static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1699 */ 1683 */
1700static void bnx2fc_ulp_stop(void *handle) 1684static void bnx2fc_ulp_stop(void *handle)
1701{ 1685{
1702 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)handle; 1686 struct bnx2fc_hba *hba = handle;
1687 struct bnx2fc_interface *interface;
1703 1688
1704 printk(KERN_ERR "ULP_STOP\n"); 1689 printk(KERN_ERR "ULP_STOP\n");
1705 1690
1706 mutex_lock(&bnx2fc_dev_lock); 1691 mutex_lock(&bnx2fc_dev_lock);
1707 bnx2fc_stop(hba); 1692 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1693 goto exit;
1694 list_for_each_entry(interface, &if_list, list) {
1695 if (interface->hba == hba)
1696 bnx2fc_stop(interface);
1697 }
1698 BUG_ON(hba->num_ofld_sess != 0);
1699
1700 mutex_lock(&hba->hba_mutex);
1701 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1702 clear_bit(ADAPTER_STATE_GOING_DOWN,
1703 &hba->adapter_state);
1704
1705 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1706 mutex_unlock(&hba->hba_mutex);
1707
1708 bnx2fc_fw_destroy(hba); 1708 bnx2fc_fw_destroy(hba);
1709exit:
1709 mutex_unlock(&bnx2fc_dev_lock); 1710 mutex_unlock(&bnx2fc_dev_lock);
1710} 1711}
1711 1712
1712static void bnx2fc_start_disc(struct bnx2fc_hba *hba) 1713static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
1713{ 1714{
1714 struct fc_lport *lport; 1715 struct fc_lport *lport;
1715 int wait_cnt = 0; 1716 int wait_cnt = 0;
1716 1717
1717 BNX2FC_MISC_DBG("Entered %s\n", __func__); 1718 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1718 /* Kick off FIP/FLOGI */ 1719 /* Kick off FIP/FLOGI */
1719 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { 1720 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1720 printk(KERN_ERR PFX "Init not done yet\n"); 1721 printk(KERN_ERR PFX "Init not done yet\n");
1721 return; 1722 return;
1722 } 1723 }
1723 1724
1724 lport = hba->ctlr.lp; 1725 lport = interface->ctlr.lp;
1725 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n"); 1726 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
1726 1727
1727 if (!bnx2fc_link_ok(lport)) { 1728 if (!bnx2fc_link_ok(lport)) {
1728 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n"); 1729 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
1729 fcoe_ctlr_link_up(&hba->ctlr); 1730 fcoe_ctlr_link_up(&interface->ctlr);
1730 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT; 1731 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
1731 set_bit(ADAPTER_STATE_READY, &hba->adapter_state); 1732 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
1732 } 1733 }
1733 1734
1734 /* wait for the FCF to be selected before issuing FLOGI */ 1735 /* wait for the FCF to be selected before issuing FLOGI */
1735 while (!hba->ctlr.sel_fcf) { 1736 while (!interface->ctlr.sel_fcf) {
1736 msleep(250); 1737 msleep(250);
1737 /* give up after 3 secs */ 1738 /* give up after 3 secs */
1738 if (++wait_cnt > 12) 1739 if (++wait_cnt > 12)
@@ -1758,15 +1759,15 @@ static void bnx2fc_ulp_init(struct cnic_dev *dev)
1758 1759
1759 BNX2FC_MISC_DBG("Entered %s\n", __func__); 1760 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1760 /* bnx2fc works only when bnx2x is loaded */ 1761 /* bnx2fc works only when bnx2x is loaded */
1761 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { 1762 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
1763 (dev->max_fcoe_conn == 0)) {
1762 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s," 1764 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
1763 " flags: %lx\n", 1765 " flags: %lx fcoe_conn: %d\n",
1764 dev->netdev->name, dev->flags); 1766 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
1765 return; 1767 return;
1766 } 1768 }
1767 1769
1768 /* Configure FCoE interface */ 1770 hba = bnx2fc_hba_create(dev);
1769 hba = bnx2fc_interface_create(dev);
1770 if (!hba) { 1771 if (!hba) {
1771 printk(KERN_ERR PFX "hba initialization failed\n"); 1772 printk(KERN_ERR PFX "hba initialization failed\n");
1772 return; 1773 return;
@@ -1774,7 +1775,7 @@ static void bnx2fc_ulp_init(struct cnic_dev *dev)
1774 1775
1775 /* Add HBA to the adapter list */ 1776 /* Add HBA to the adapter list */
1776 mutex_lock(&bnx2fc_dev_lock); 1777 mutex_lock(&bnx2fc_dev_lock);
1777 list_add_tail(&hba->link, &adapter_list); 1778 list_add_tail(&hba->list, &adapter_list);
1778 adapter_count++; 1779 adapter_count++;
1779 mutex_unlock(&bnx2fc_dev_lock); 1780 mutex_unlock(&bnx2fc_dev_lock);
1780 1781
@@ -1790,52 +1791,21 @@ static void bnx2fc_ulp_init(struct cnic_dev *dev)
1790 1791
1791static int bnx2fc_disable(struct net_device *netdev) 1792static int bnx2fc_disable(struct net_device *netdev)
1792{ 1793{
1793 struct bnx2fc_hba *hba; 1794 struct bnx2fc_interface *interface;
1794 struct net_device *phys_dev;
1795 struct ethtool_drvinfo drvinfo;
1796 int rc = 0; 1795 int rc = 0;
1797 1796
1798 rtnl_lock(); 1797 rtnl_lock();
1799
1800 mutex_lock(&bnx2fc_dev_lock); 1798 mutex_lock(&bnx2fc_dev_lock);
1801 1799
1802 /* obtain physical netdev */ 1800 interface = bnx2fc_interface_lookup(netdev);
1803 if (netdev->priv_flags & IFF_802_1Q_VLAN) 1801 if (!interface || !interface->ctlr.lp) {
1804 phys_dev = vlan_dev_real_dev(netdev);
1805 else {
1806 printk(KERN_ERR PFX "Not a vlan device\n");
1807 rc = -ENODEV;
1808 goto nodev;
1809 }
1810
1811 /* verify if the physical device is a netxtreme2 device */
1812 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1813 memset(&drvinfo, 0, sizeof(drvinfo));
1814 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1815 if (strcmp(drvinfo.driver, "bnx2x")) {
1816 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1817 rc = -ENODEV;
1818 goto nodev;
1819 }
1820 } else {
1821 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1822 rc = -ENODEV;
1823 goto nodev;
1824 }
1825
1826 printk(KERN_ERR PFX "phys_dev is netxtreme2 device\n");
1827
1828 /* obtain hba and initialize rest of the structure */
1829 hba = bnx2fc_hba_lookup(phys_dev);
1830 if (!hba || !hba->ctlr.lp) {
1831 rc = -ENODEV; 1802 rc = -ENODEV;
1832 printk(KERN_ERR PFX "bnx2fc_disable: hba or lport not found\n"); 1803 printk(KERN_ERR PFX "bnx2fc_disable: interface or lport not found\n");
1833 } else { 1804 } else {
1834 fcoe_ctlr_link_down(&hba->ctlr); 1805 fcoe_ctlr_link_down(&interface->ctlr);
1835 fcoe_clean_pending_queue(hba->ctlr.lp); 1806 fcoe_clean_pending_queue(interface->ctlr.lp);
1836 } 1807 }
1837 1808
1838nodev:
1839 mutex_unlock(&bnx2fc_dev_lock); 1809 mutex_unlock(&bnx2fc_dev_lock);
1840 rtnl_unlock(); 1810 rtnl_unlock();
1841 return rc; 1811 return rc;
@@ -1844,48 +1814,19 @@ nodev:
1844 1814
1845static int bnx2fc_enable(struct net_device *netdev) 1815static int bnx2fc_enable(struct net_device *netdev)
1846{ 1816{
1847 struct bnx2fc_hba *hba; 1817 struct bnx2fc_interface *interface;
1848 struct net_device *phys_dev;
1849 struct ethtool_drvinfo drvinfo;
1850 int rc = 0; 1818 int rc = 0;
1851 1819
1852 rtnl_lock(); 1820 rtnl_lock();
1853
1854 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1855 mutex_lock(&bnx2fc_dev_lock); 1821 mutex_lock(&bnx2fc_dev_lock);
1856 1822
1857 /* obtain physical netdev */ 1823 interface = bnx2fc_interface_lookup(netdev);
1858 if (netdev->priv_flags & IFF_802_1Q_VLAN) 1824 if (!interface || !interface->ctlr.lp) {
1859 phys_dev = vlan_dev_real_dev(netdev);
1860 else {
1861 printk(KERN_ERR PFX "Not a vlan device\n");
1862 rc = -ENODEV;
1863 goto nodev;
1864 }
1865 /* verify if the physical device is a netxtreme2 device */
1866 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1867 memset(&drvinfo, 0, sizeof(drvinfo));
1868 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1869 if (strcmp(drvinfo.driver, "bnx2x")) {
1870 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1871 rc = -ENODEV;
1872 goto nodev;
1873 }
1874 } else {
1875 printk(KERN_ERR PFX "unable to obtain drv_info\n");
1876 rc = -ENODEV; 1825 rc = -ENODEV;
1877 goto nodev; 1826 printk(KERN_ERR PFX "bnx2fc_enable: interface or lport not found\n");
1878 } 1827 } else if (!bnx2fc_link_ok(interface->ctlr.lp))
1879 1828 fcoe_ctlr_link_up(&interface->ctlr);
1880 /* obtain hba and initialize rest of the structure */
1881 hba = bnx2fc_hba_lookup(phys_dev);
1882 if (!hba || !hba->ctlr.lp) {
1883 rc = -ENODEV;
1884 printk(KERN_ERR PFX "bnx2fc_enable: hba or lport not found\n");
1885 } else if (!bnx2fc_link_ok(hba->ctlr.lp))
1886 fcoe_ctlr_link_up(&hba->ctlr);
1887 1829
1888nodev:
1889 mutex_unlock(&bnx2fc_dev_lock); 1830 mutex_unlock(&bnx2fc_dev_lock);
1890 rtnl_unlock(); 1831 rtnl_unlock();
1891 return rc; 1832 return rc;
@@ -1903,6 +1844,7 @@ nodev:
1903 */ 1844 */
1904static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode) 1845static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1905{ 1846{
1847 struct bnx2fc_interface *interface;
1906 struct bnx2fc_hba *hba; 1848 struct bnx2fc_hba *hba;
1907 struct net_device *phys_dev; 1849 struct net_device *phys_dev;
1908 struct fc_lport *lport; 1850 struct fc_lport *lport;
@@ -1938,7 +1880,7 @@ static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1938 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) { 1880 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
1939 memset(&drvinfo, 0, sizeof(drvinfo)); 1881 memset(&drvinfo, 0, sizeof(drvinfo));
1940 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo); 1882 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
1941 if (strcmp(drvinfo.driver, "bnx2x")) { 1883 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
1942 printk(KERN_ERR PFX "Not a netxtreme2 device\n"); 1884 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
1943 rc = -EINVAL; 1885 rc = -EINVAL;
1944 goto netdev_err; 1886 goto netdev_err;
@@ -1949,7 +1891,7 @@ static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1949 goto netdev_err; 1891 goto netdev_err;
1950 } 1892 }
1951 1893
1952 /* obtain hba and initialize rest of the structure */ 1894 /* obtain interface and initialize rest of the structure */
1953 hba = bnx2fc_hba_lookup(phys_dev); 1895 hba = bnx2fc_hba_lookup(phys_dev);
1954 if (!hba) { 1896 if (!hba) {
1955 rc = -ENODEV; 1897 rc = -ENODEV;
@@ -1957,67 +1899,61 @@ static int bnx2fc_create(struct net_device *netdev, enum fip_state fip_mode)
1957 goto netdev_err; 1899 goto netdev_err;
1958 } 1900 }
1959 1901
1960 if (!test_bit(BNX2FC_FW_INIT_DONE, &hba->init_done)) { 1902 if (bnx2fc_interface_lookup(netdev)) {
1961 rc = bnx2fc_fw_init(hba);
1962 if (rc)
1963 goto netdev_err;
1964 }
1965
1966 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) {
1967 rc = -EEXIST; 1903 rc = -EEXIST;
1968 goto netdev_err; 1904 goto netdev_err;
1969 } 1905 }
1970 1906
1971 /* update netdev with vlan netdev */ 1907 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
1972 hba->netdev = netdev; 1908 if (!interface) {
1973 hba->vlan_id = vlan_id; 1909 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
1974 hba->vlan_enabled = 1;
1975
1976 rc = bnx2fc_interface_setup(hba, fip_mode);
1977 if (rc) {
1978 printk(KERN_ERR PFX "bnx2fc_interface_setup failed\n");
1979 goto ifput_err; 1910 goto ifput_err;
1980 } 1911 }
1981 1912
1982 hba->timer_work_queue = 1913 interface->vlan_id = vlan_id;
1914 interface->vlan_enabled = 1;
1915
1916 interface->timer_work_queue =
1983 create_singlethread_workqueue("bnx2fc_timer_wq"); 1917 create_singlethread_workqueue("bnx2fc_timer_wq");
1984 if (!hba->timer_work_queue) { 1918 if (!interface->timer_work_queue) {
1985 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n"); 1919 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
1986 rc = -EINVAL; 1920 rc = -EINVAL;
1987 goto ifput_err; 1921 goto ifput_err;
1988 } 1922 }
1989 1923
1990 lport = bnx2fc_if_create(hba, &hba->pcidev->dev, 0); 1924 lport = bnx2fc_if_create(interface, &interface->hba->pcidev->dev, 0);
1991 if (!lport) { 1925 if (!lport) {
1992 printk(KERN_ERR PFX "Failed to create interface (%s)\n", 1926 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
1993 netdev->name); 1927 netdev->name);
1994 bnx2fc_netdev_cleanup(hba); 1928 bnx2fc_netdev_cleanup(interface);
1995 rc = -EINVAL; 1929 rc = -EINVAL;
1996 goto if_create_err; 1930 goto if_create_err;
1997 } 1931 }
1998 1932
1933 /* Add interface to if_list */
1934 list_add_tail(&interface->list, &if_list);
1935
1999 lport->boot_time = jiffies; 1936 lport->boot_time = jiffies;
2000 1937
2001 /* Make this master N_port */ 1938 /* Make this master N_port */
2002 hba->ctlr.lp = lport; 1939 interface->ctlr.lp = lport;
2003 1940
2004 set_bit(BNX2FC_CREATE_DONE, &hba->init_done); 1941 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2005 printk(KERN_ERR PFX "create: START DISC\n"); 1942 bnx2fc_start_disc(interface);
2006 bnx2fc_start_disc(hba);
2007 /* 1943 /*
2008 * Release from kref_init in bnx2fc_interface_setup, on success 1944 * Release from kref_init in bnx2fc_interface_setup, on success
2009 * lport should be holding a reference taken in bnx2fc_if_create 1945 * lport should be holding a reference taken in bnx2fc_if_create
2010 */ 1946 */
2011 bnx2fc_interface_put(hba); 1947 bnx2fc_interface_put(interface);
2012 /* put netdev that was held while calling dev_get_by_name */ 1948 /* put netdev that was held while calling dev_get_by_name */
2013 mutex_unlock(&bnx2fc_dev_lock); 1949 mutex_unlock(&bnx2fc_dev_lock);
2014 rtnl_unlock(); 1950 rtnl_unlock();
2015 return 0; 1951 return 0;
2016 1952
2017if_create_err: 1953if_create_err:
2018 destroy_workqueue(hba->timer_work_queue); 1954 destroy_workqueue(interface->timer_work_queue);
2019ifput_err: 1955ifput_err:
2020 bnx2fc_interface_put(hba); 1956 bnx2fc_interface_put(interface);
2021netdev_err: 1957netdev_err:
2022 module_put(THIS_MODULE); 1958 module_put(THIS_MODULE);
2023mod_err: 1959mod_err:
@@ -2027,7 +1963,7 @@ mod_err:
2027} 1963}
2028 1964
2029/** 1965/**
2030 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc adapter instance 1966 * bnx2fc_find_hba_for_cnic - maps cnic instance to bnx2fc hba instance
2031 * 1967 *
2032 * @cnic: Pointer to cnic device instance 1968 * @cnic: Pointer to cnic device instance
2033 * 1969 *
@@ -2047,19 +1983,30 @@ static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2047 return NULL; 1983 return NULL;
2048} 1984}
2049 1985
2050static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev) 1986static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
1987 *netdev)
1988{
1989 struct bnx2fc_interface *interface;
1990
1991 /* Called with bnx2fc_dev_lock held */
1992 list_for_each_entry(interface, &if_list, list) {
1993 if (interface->netdev == netdev)
1994 return interface;
1995 }
1996 return NULL;
1997}
1998
1999static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2000 *phys_dev)
2051{ 2001{
2052 struct list_head *list;
2053 struct list_head *temp;
2054 struct bnx2fc_hba *hba; 2002 struct bnx2fc_hba *hba;
2055 2003
2056 /* Called with bnx2fc_dev_lock held */ 2004 /* Called with bnx2fc_dev_lock held */
2057 list_for_each_safe(list, temp, &adapter_list) { 2005 list_for_each_entry(hba, &adapter_list, list) {
2058 hba = (struct bnx2fc_hba *)list;
2059 if (hba->phys_dev == phys_dev) 2006 if (hba->phys_dev == phys_dev)
2060 return hba; 2007 return hba;
2061 } 2008 }
2062 printk(KERN_ERR PFX "hba_lookup: hba NULL\n"); 2009 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2063 return NULL; 2010 return NULL;
2064} 2011}
2065 2012
@@ -2071,6 +2018,8 @@ static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev)
2071static void bnx2fc_ulp_exit(struct cnic_dev *dev) 2018static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2072{ 2019{
2073 struct bnx2fc_hba *hba; 2020 struct bnx2fc_hba *hba;
2021 struct bnx2fc_interface *interface, *tmp;
2022 struct fc_lport *lport;
2074 2023
2075 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n"); 2024 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2076 2025
@@ -2089,13 +2038,20 @@ static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2089 return; 2038 return;
2090 } 2039 }
2091 2040
2092 list_del_init(&hba->link); 2041 list_del_init(&hba->list);
2093 adapter_count--; 2042 adapter_count--;
2094 2043
2095 if (test_bit(BNX2FC_CREATE_DONE, &hba->init_done)) { 2044 list_for_each_entry_safe(interface, tmp, &if_list, list) {
2096 /* destroy not called yet, move to quiesced list */ 2045 /* destroy not called yet, move to quiesced list */
2097 bnx2fc_netdev_cleanup(hba); 2046 if (interface->hba == hba) {
2098 bnx2fc_if_destroy(hba->ctlr.lp); 2047 bnx2fc_netdev_cleanup(interface);
2048 bnx2fc_stop(interface);
2049
2050 list_del(&interface->list);
2051 lport = interface->ctlr.lp;
2052 bnx2fc_interface_put(interface);
2053 bnx2fc_if_destroy(lport, hba);
2054 }
2099 } 2055 }
2100 mutex_unlock(&bnx2fc_dev_lock); 2056 mutex_unlock(&bnx2fc_dev_lock);
2101 2057
@@ -2103,7 +2059,7 @@ static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2103 /* unregister cnic device */ 2059 /* unregister cnic device */
2104 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic)) 2060 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2105 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); 2061 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2106 bnx2fc_interface_destroy(hba); 2062 bnx2fc_hba_destroy(hba);
2107} 2063}
2108 2064
2109/** 2065/**
@@ -2259,6 +2215,7 @@ static int __init bnx2fc_mod_init(void)
2259 } 2215 }
2260 2216
2261 INIT_LIST_HEAD(&adapter_list); 2217 INIT_LIST_HEAD(&adapter_list);
2218 INIT_LIST_HEAD(&if_list);
2262 mutex_init(&bnx2fc_dev_lock); 2219 mutex_init(&bnx2fc_dev_lock);
2263 adapter_count = 0; 2220 adapter_count = 0;
2264 2221
@@ -2336,16 +2293,17 @@ static void __exit bnx2fc_mod_exit(void)
2336 mutex_unlock(&bnx2fc_dev_lock); 2293 mutex_unlock(&bnx2fc_dev_lock);
2337 2294
2338 /* Unregister with cnic */ 2295 /* Unregister with cnic */
2339 list_for_each_entry_safe(hba, next, &to_be_deleted, link) { 2296 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2340 list_del_init(&hba->link); 2297 list_del_init(&hba->list);
2341 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p, kref = %d\n", 2298 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2342 hba, atomic_read(&hba->kref.refcount)); 2299 hba);
2343 bnx2fc_ulp_stop(hba); 2300 bnx2fc_ulp_stop(hba);
2344 /* unregister cnic device */ 2301 /* unregister cnic device */
2345 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, 2302 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2346 &hba->reg_with_cnic)) 2303 &hba->reg_with_cnic))
2347 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE); 2304 hba->cnic->unregister_device(hba->cnic,
2348 bnx2fc_interface_destroy(hba); 2305 CNIC_ULP_FCOE);
2306 bnx2fc_hba_destroy(hba);
2349 } 2307 }
2350 cnic_unregister_driver(CNIC_ULP_FCOE); 2308 cnic_unregister_driver(CNIC_ULP_FCOE);
2351 2309
diff --git a/drivers/scsi/bnx2fc/bnx2fc_hwi.c b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
index b41deb64aff1..ee1674b794b1 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_hwi.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_hwi.c
@@ -23,7 +23,7 @@ static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
23 struct fcoe_kcqe *ofld_kcqe); 23 struct fcoe_kcqe *ofld_kcqe);
24static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code); 24static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code);
25static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba, 25static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
26 struct fcoe_kcqe *conn_destroy); 26 struct fcoe_kcqe *destroy_kcqe);
27 27
28int bnx2fc_send_stat_req(struct bnx2fc_hba *hba) 28int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
29{ 29{
@@ -67,7 +67,7 @@ int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
67 int rc = 0; 67 int rc = 0;
68 68
69 if (!hba->cnic) { 69 if (!hba->cnic) {
70 printk(KERN_ALERT PFX "hba->cnic NULL during fcoe fw init\n"); 70 printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n");
71 return -ENODEV; 71 return -ENODEV;
72 } 72 }
73 73
@@ -103,6 +103,7 @@ int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
103 fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION; 103 fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION;
104 fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION; 104 fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION;
105 105
106
106 fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma; 107 fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
107 fcoe_init2.hash_tbl_pbl_addr_hi = (u32) 108 fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
108 ((u64) hba->hash_tbl_pbl_dma >> 32); 109 ((u64) hba->hash_tbl_pbl_dma >> 32);
@@ -165,7 +166,8 @@ int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
165 struct bnx2fc_rport *tgt) 166 struct bnx2fc_rport *tgt)
166{ 167{
167 struct fc_lport *lport = port->lport; 168 struct fc_lport *lport = port->lport;
168 struct bnx2fc_hba *hba = port->priv; 169 struct bnx2fc_interface *interface = port->priv;
170 struct bnx2fc_hba *hba = interface->hba;
169 struct kwqe *kwqe_arr[4]; 171 struct kwqe *kwqe_arr[4];
170 struct fcoe_kwqe_conn_offload1 ofld_req1; 172 struct fcoe_kwqe_conn_offload1 ofld_req1;
171 struct fcoe_kwqe_conn_offload2 ofld_req2; 173 struct fcoe_kwqe_conn_offload2 ofld_req2;
@@ -227,7 +229,7 @@ int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
227 ofld_req3.hdr.flags = 229 ofld_req3.hdr.flags =
228 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT); 230 (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
229 231
230 ofld_req3.vlan_tag = hba->vlan_id << 232 ofld_req3.vlan_tag = interface->vlan_id <<
231 FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT; 233 FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
232 ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT; 234 ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
233 235
@@ -278,7 +280,7 @@ int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
278 FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT); 280 FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
279 281
280 /* vlan flag */ 282 /* vlan flag */
281 ofld_req3.flags |= (hba->vlan_enabled << 283 ofld_req3.flags |= (interface->vlan_enabled <<
282 FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT); 284 FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
283 285
284 /* C2_VALID and ACK flags are not set as they are not suppported */ 286 /* C2_VALID and ACK flags are not set as they are not suppported */
@@ -300,12 +302,13 @@ int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
300 ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2]; 302 ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2];
301 ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1]; 303 ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1];
302 ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0]; 304 ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0];
303 ofld_req4.dst_mac_addr_lo[0] = hba->ctlr.dest_addr[5];/* fcf mac */ 305 ofld_req4.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
304 ofld_req4.dst_mac_addr_lo[1] = hba->ctlr.dest_addr[4]; 306 /* fcf mac */
305 ofld_req4.dst_mac_addr_mid[0] = hba->ctlr.dest_addr[3]; 307 ofld_req4.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
306 ofld_req4.dst_mac_addr_mid[1] = hba->ctlr.dest_addr[2]; 308 ofld_req4.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
307 ofld_req4.dst_mac_addr_hi[0] = hba->ctlr.dest_addr[1]; 309 ofld_req4.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
308 ofld_req4.dst_mac_addr_hi[1] = hba->ctlr.dest_addr[0]; 310 ofld_req4.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
311 ofld_req4.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
309 312
310 ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma; 313 ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
311 ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32); 314 ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
@@ -335,7 +338,8 @@ static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
335 struct bnx2fc_rport *tgt) 338 struct bnx2fc_rport *tgt)
336{ 339{
337 struct kwqe *kwqe_arr[2]; 340 struct kwqe *kwqe_arr[2];
338 struct bnx2fc_hba *hba = port->priv; 341 struct bnx2fc_interface *interface = port->priv;
342 struct bnx2fc_hba *hba = interface->hba;
339 struct fcoe_kwqe_conn_enable_disable enbl_req; 343 struct fcoe_kwqe_conn_enable_disable enbl_req;
340 struct fc_lport *lport = port->lport; 344 struct fc_lport *lport = port->lport;
341 struct fc_rport *rport = tgt->rport; 345 struct fc_rport *rport = tgt->rport;
@@ -358,12 +362,12 @@ static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
358 enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0]; 362 enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0];
359 memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN); 363 memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
360 364
361 enbl_req.dst_mac_addr_lo[0] = hba->ctlr.dest_addr[5];/* fcf mac */ 365 enbl_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
362 enbl_req.dst_mac_addr_lo[1] = hba->ctlr.dest_addr[4]; 366 enbl_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
363 enbl_req.dst_mac_addr_mid[0] = hba->ctlr.dest_addr[3]; 367 enbl_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
364 enbl_req.dst_mac_addr_mid[1] = hba->ctlr.dest_addr[2]; 368 enbl_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
365 enbl_req.dst_mac_addr_hi[0] = hba->ctlr.dest_addr[1]; 369 enbl_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
366 enbl_req.dst_mac_addr_hi[1] = hba->ctlr.dest_addr[0]; 370 enbl_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
367 371
368 port_id = fc_host_port_id(lport->host); 372 port_id = fc_host_port_id(lport->host);
369 if (port_id != tgt->sid) { 373 if (port_id != tgt->sid) {
@@ -379,10 +383,10 @@ static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
379 enbl_req.d_id[0] = (port_id & 0x000000FF); 383 enbl_req.d_id[0] = (port_id & 0x000000FF);
380 enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8; 384 enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
381 enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16; 385 enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
382 enbl_req.vlan_tag = hba->vlan_id << 386 enbl_req.vlan_tag = interface->vlan_id <<
383 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT; 387 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
384 enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT; 388 enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
385 enbl_req.vlan_flag = hba->vlan_enabled; 389 enbl_req.vlan_flag = interface->vlan_enabled;
386 enbl_req.context_id = tgt->context_id; 390 enbl_req.context_id = tgt->context_id;
387 enbl_req.conn_id = tgt->fcoe_conn_id; 391 enbl_req.conn_id = tgt->fcoe_conn_id;
388 392
@@ -402,7 +406,8 @@ static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
402int bnx2fc_send_session_disable_req(struct fcoe_port *port, 406int bnx2fc_send_session_disable_req(struct fcoe_port *port,
403 struct bnx2fc_rport *tgt) 407 struct bnx2fc_rport *tgt)
404{ 408{
405 struct bnx2fc_hba *hba = port->priv; 409 struct bnx2fc_interface *interface = port->priv;
410 struct bnx2fc_hba *hba = interface->hba;
406 struct fcoe_kwqe_conn_enable_disable disable_req; 411 struct fcoe_kwqe_conn_enable_disable disable_req;
407 struct kwqe *kwqe_arr[2]; 412 struct kwqe *kwqe_arr[2];
408 struct fc_rport *rport = tgt->rport; 413 struct fc_rport *rport = tgt->rport;
@@ -423,12 +428,12 @@ int bnx2fc_send_session_disable_req(struct fcoe_port *port,
423 disable_req.src_mac_addr_hi[0] = tgt->src_addr[1]; 428 disable_req.src_mac_addr_hi[0] = tgt->src_addr[1];
424 disable_req.src_mac_addr_hi[1] = tgt->src_addr[0]; 429 disable_req.src_mac_addr_hi[1] = tgt->src_addr[0];
425 430
426 disable_req.dst_mac_addr_lo[0] = hba->ctlr.dest_addr[5];/* fcf mac */ 431 disable_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
427 disable_req.dst_mac_addr_lo[1] = hba->ctlr.dest_addr[4]; 432 disable_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
428 disable_req.dst_mac_addr_mid[0] = hba->ctlr.dest_addr[3]; 433 disable_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
429 disable_req.dst_mac_addr_mid[1] = hba->ctlr.dest_addr[2]; 434 disable_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
430 disable_req.dst_mac_addr_hi[0] = hba->ctlr.dest_addr[1]; 435 disable_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
431 disable_req.dst_mac_addr_hi[1] = hba->ctlr.dest_addr[0]; 436 disable_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
432 437
433 port_id = tgt->sid; 438 port_id = tgt->sid;
434 disable_req.s_id[0] = (port_id & 0x000000FF); 439 disable_req.s_id[0] = (port_id & 0x000000FF);
@@ -442,11 +447,11 @@ int bnx2fc_send_session_disable_req(struct fcoe_port *port,
442 disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16; 447 disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
443 disable_req.context_id = tgt->context_id; 448 disable_req.context_id = tgt->context_id;
444 disable_req.conn_id = tgt->fcoe_conn_id; 449 disable_req.conn_id = tgt->fcoe_conn_id;
445 disable_req.vlan_tag = hba->vlan_id << 450 disable_req.vlan_tag = interface->vlan_id <<
446 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT; 451 FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
447 disable_req.vlan_tag |= 452 disable_req.vlan_tag |=
448 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT; 453 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
449 disable_req.vlan_flag = hba->vlan_enabled; 454 disable_req.vlan_flag = interface->vlan_enabled;
450 455
451 kwqe_arr[0] = (struct kwqe *) &disable_req; 456 kwqe_arr[0] = (struct kwqe *) &disable_req;
452 457
@@ -525,7 +530,7 @@ void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
525{ 530{
526 struct fcoe_port *port = tgt->port; 531 struct fcoe_port *port = tgt->port;
527 struct fc_lport *lport = port->lport; 532 struct fc_lport *lport = port->lport;
528 struct bnx2fc_hba *hba = port->priv; 533 struct bnx2fc_interface *interface = port->priv;
529 struct bnx2fc_unsol_els *unsol_els; 534 struct bnx2fc_unsol_els *unsol_els;
530 struct fc_frame_header *fh; 535 struct fc_frame_header *fh;
531 struct fc_frame *fp; 536 struct fc_frame *fp;
@@ -586,7 +591,7 @@ void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
586 fr_eof(fp) = FC_EOF_T; 591 fr_eof(fp) = FC_EOF_T;
587 fr_crc(fp) = cpu_to_le32(~crc); 592 fr_crc(fp) = cpu_to_le32(~crc);
588 unsol_els->lport = lport; 593 unsol_els->lport = lport;
589 unsol_els->hba = hba; 594 unsol_els->hba = interface->hba;
590 unsol_els->fp = fp; 595 unsol_els->fp = fp;
591 INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work); 596 INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
592 queue_work(bnx2fc_wq, &unsol_els->unsol_els_work); 597 queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
@@ -608,7 +613,8 @@ static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
608 u32 frame_len, len; 613 u32 frame_len, len;
609 struct bnx2fc_cmd *io_req = NULL; 614 struct bnx2fc_cmd *io_req = NULL;
610 struct fcoe_task_ctx_entry *task, *task_page; 615 struct fcoe_task_ctx_entry *task, *task_page;
611 struct bnx2fc_hba *hba = tgt->port->priv; 616 struct bnx2fc_interface *interface = tgt->port->priv;
617 struct bnx2fc_hba *hba = interface->hba;
612 int task_idx, index; 618 int task_idx, index;
613 int rc = 0; 619 int rc = 0;
614 620
@@ -685,7 +691,7 @@ static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
685 task_idx = xid / BNX2FC_TASKS_PER_PAGE; 691 task_idx = xid / BNX2FC_TASKS_PER_PAGE;
686 index = xid % BNX2FC_TASKS_PER_PAGE; 692 index = xid % BNX2FC_TASKS_PER_PAGE;
687 task_page = (struct fcoe_task_ctx_entry *) 693 task_page = (struct fcoe_task_ctx_entry *)
688 hba->task_ctx[task_idx]; 694 hba->task_ctx[task_idx];
689 task = &(task_page[index]); 695 task = &(task_page[index]);
690 696
691 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid]; 697 io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
@@ -770,7 +776,8 @@ void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
770 struct fcoe_task_ctx_entry *task; 776 struct fcoe_task_ctx_entry *task;
771 struct fcoe_task_ctx_entry *task_page; 777 struct fcoe_task_ctx_entry *task_page;
772 struct fcoe_port *port = tgt->port; 778 struct fcoe_port *port = tgt->port;
773 struct bnx2fc_hba *hba = port->priv; 779 struct bnx2fc_interface *interface = port->priv;
780 struct bnx2fc_hba *hba = interface->hba;
774 struct bnx2fc_cmd *io_req; 781 struct bnx2fc_cmd *io_req;
775 int task_idx, index; 782 int task_idx, index;
776 u16 xid; 783 u16 xid;
@@ -1004,6 +1011,7 @@ static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
1004{ 1011{
1005 struct bnx2fc_rport *tgt; 1012 struct bnx2fc_rport *tgt;
1006 struct fcoe_port *port; 1013 struct fcoe_port *port;
1014 struct bnx2fc_interface *interface;
1007 u32 conn_id; 1015 u32 conn_id;
1008 u32 context_id; 1016 u32 context_id;
1009 int rc; 1017 int rc;
@@ -1012,14 +1020,15 @@ static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
1012 context_id = ofld_kcqe->fcoe_conn_context_id; 1020 context_id = ofld_kcqe->fcoe_conn_context_id;
1013 tgt = hba->tgt_ofld_list[conn_id]; 1021 tgt = hba->tgt_ofld_list[conn_id];
1014 if (!tgt) { 1022 if (!tgt) {
1015 printk(KERN_ERR PFX "ERROR:ofld_cmpl: No pending ofld req\n"); 1023 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
1016 return; 1024 return;
1017 } 1025 }
1018 BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n", 1026 BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
1019 ofld_kcqe->fcoe_conn_context_id); 1027 ofld_kcqe->fcoe_conn_context_id);
1020 port = tgt->port; 1028 port = tgt->port;
1021 if (hba != tgt->port->priv) { 1029 interface = tgt->port->priv;
1022 printk(KERN_ALERT PFX "ERROR:ofld_cmpl: HBA mis-match\n"); 1030 if (hba != interface->hba) {
1031 printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n");
1023 goto ofld_cmpl_err; 1032 goto ofld_cmpl_err;
1024 } 1033 }
1025 /* 1034 /*
@@ -1063,6 +1072,7 @@ static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1063 struct fcoe_kcqe *ofld_kcqe) 1072 struct fcoe_kcqe *ofld_kcqe)
1064{ 1073{
1065 struct bnx2fc_rport *tgt; 1074 struct bnx2fc_rport *tgt;
1075 struct bnx2fc_interface *interface;
1066 u32 conn_id; 1076 u32 conn_id;
1067 u32 context_id; 1077 u32 context_id;
1068 1078
@@ -1085,13 +1095,14 @@ static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
1085 printk(KERN_ERR PFX "context id mis-match\n"); 1095 printk(KERN_ERR PFX "context id mis-match\n");
1086 return; 1096 return;
1087 } 1097 }
1088 if (hba != tgt->port->priv) { 1098 interface = tgt->port->priv;
1089 printk(KERN_ALERT PFX "bnx2fc-enbl_cmpl: HBA mis-match\n"); 1099 if (hba != interface->hba) {
1100 printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
1090 goto enbl_cmpl_err; 1101 goto enbl_cmpl_err;
1091 } 1102 }
1092 if (ofld_kcqe->completion_status) { 1103 if (ofld_kcqe->completion_status)
1093 goto enbl_cmpl_err; 1104 goto enbl_cmpl_err;
1094 } else { 1105 else {
1095 /* enable successful - rport ready for issuing IOs */ 1106 /* enable successful - rport ready for issuing IOs */
1096 set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags); 1107 set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
1097 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags); 1108 set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
@@ -1241,7 +1252,7 @@ void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
1241 } else { 1252 } else {
1242 printk(KERN_ERR PFX "DESTROY success\n"); 1253 printk(KERN_ERR PFX "DESTROY success\n");
1243 } 1254 }
1244 hba->flags |= BNX2FC_FLAG_DESTROY_CMPL; 1255 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1245 wake_up_interruptible(&hba->destroy_wait); 1256 wake_up_interruptible(&hba->destroy_wait);
1246 break; 1257 break;
1247 1258
@@ -1306,7 +1317,8 @@ int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
1306 struct fcoe_port *port = tgt->port; 1317 struct fcoe_port *port = tgt->port;
1307 u32 reg_off; 1318 u32 reg_off;
1308 resource_size_t reg_base; 1319 resource_size_t reg_base;
1309 struct bnx2fc_hba *hba = port->priv; 1320 struct bnx2fc_interface *interface = port->priv;
1321 struct bnx2fc_hba *hba = interface->hba;
1310 1322
1311 reg_base = pci_resource_start(hba->pcidev, 1323 reg_base = pci_resource_start(hba->pcidev,
1312 BNX2X_DOORBELL_PCI_BAR); 1324 BNX2X_DOORBELL_PCI_BAR);
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 8f988c2e6717..e711ea3dd900 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -29,10 +29,11 @@ static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
29void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req, 29void bnx2fc_cmd_timer_set(struct bnx2fc_cmd *io_req,
30 unsigned int timer_msec) 30 unsigned int timer_msec)
31{ 31{
32 struct bnx2fc_hba *hba = io_req->port->priv; 32 struct bnx2fc_interface *interface = io_req->port->priv;
33 33
34 if (queue_delayed_work(hba->timer_work_queue, &io_req->timeout_work, 34 if (queue_delayed_work(interface->timer_work_queue,
35 msecs_to_jiffies(timer_msec))) 35 &io_req->timeout_work,
36 msecs_to_jiffies(timer_msec)))
36 kref_get(&io_req->refcount); 37 kref_get(&io_req->refcount);
37} 38}
38 39
@@ -419,8 +420,8 @@ free_cmgr:
419struct bnx2fc_cmd *bnx2fc_elstm_alloc(struct bnx2fc_rport *tgt, int type) 420struct bnx2fc_cmd *bnx2fc_elstm_alloc(struct bnx2fc_rport *tgt, int type)
420{ 421{
421 struct fcoe_port *port = tgt->port; 422 struct fcoe_port *port = tgt->port;
422 struct bnx2fc_hba *hba = port->priv; 423 struct bnx2fc_interface *interface = port->priv;
423 struct bnx2fc_cmd_mgr *cmd_mgr = hba->cmd_mgr; 424 struct bnx2fc_cmd_mgr *cmd_mgr = interface->hba->cmd_mgr;
424 struct bnx2fc_cmd *io_req; 425 struct bnx2fc_cmd *io_req;
425 struct list_head *listp; 426 struct list_head *listp;
426 struct io_bdt *bd_tbl; 427 struct io_bdt *bd_tbl;
@@ -485,11 +486,12 @@ struct bnx2fc_cmd *bnx2fc_elstm_alloc(struct bnx2fc_rport *tgt, int type)
485 kref_init(&io_req->refcount); 486 kref_init(&io_req->refcount);
486 return io_req; 487 return io_req;
487} 488}
488static struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt) 489
490struct bnx2fc_cmd *bnx2fc_cmd_alloc(struct bnx2fc_rport *tgt)
489{ 491{
490 struct fcoe_port *port = tgt->port; 492 struct fcoe_port *port = tgt->port;
491 struct bnx2fc_hba *hba = port->priv; 493 struct bnx2fc_interface *interface = port->priv;
492 struct bnx2fc_cmd_mgr *cmd_mgr = hba->cmd_mgr; 494 struct bnx2fc_cmd_mgr *cmd_mgr = interface->hba->cmd_mgr;
493 struct bnx2fc_cmd *io_req; 495 struct bnx2fc_cmd *io_req;
494 struct list_head *listp; 496 struct list_head *listp;
495 struct io_bdt *bd_tbl; 497 struct io_bdt *bd_tbl;
@@ -570,7 +572,8 @@ void bnx2fc_cmd_release(struct kref *ref)
570static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req) 572static void bnx2fc_free_mp_resc(struct bnx2fc_cmd *io_req)
571{ 573{
572 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req); 574 struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
573 struct bnx2fc_hba *hba = io_req->port->priv; 575 struct bnx2fc_interface *interface = io_req->port->priv;
576 struct bnx2fc_hba *hba = interface->hba;
574 size_t sz = sizeof(struct fcoe_bd_ctx); 577 size_t sz = sizeof(struct fcoe_bd_ctx);
575 578
576 /* clear tm flags */ 579 /* clear tm flags */
@@ -606,7 +609,8 @@ int bnx2fc_init_mp_req(struct bnx2fc_cmd *io_req)
606 struct bnx2fc_mp_req *mp_req; 609 struct bnx2fc_mp_req *mp_req;
607 struct fcoe_bd_ctx *mp_req_bd; 610 struct fcoe_bd_ctx *mp_req_bd;
608 struct fcoe_bd_ctx *mp_resp_bd; 611 struct fcoe_bd_ctx *mp_resp_bd;
609 struct bnx2fc_hba *hba = io_req->port->priv; 612 struct bnx2fc_interface *interface = io_req->port->priv;
613 struct bnx2fc_hba *hba = interface->hba;
610 dma_addr_t addr; 614 dma_addr_t addr;
611 size_t sz; 615 size_t sz;
612 616
@@ -682,7 +686,7 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
682 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device)); 686 struct fc_rport *rport = starget_to_rport(scsi_target(sc_cmd->device));
683 struct fc_rport_libfc_priv *rp = rport->dd_data; 687 struct fc_rport_libfc_priv *rp = rport->dd_data;
684 struct fcoe_port *port; 688 struct fcoe_port *port;
685 struct bnx2fc_hba *hba; 689 struct bnx2fc_interface *interface;
686 struct bnx2fc_rport *tgt; 690 struct bnx2fc_rport *tgt;
687 struct bnx2fc_cmd *io_req; 691 struct bnx2fc_cmd *io_req;
688 struct bnx2fc_mp_req *tm_req; 692 struct bnx2fc_mp_req *tm_req;
@@ -699,7 +703,7 @@ static int bnx2fc_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags)
699 703
700 lport = shost_priv(host); 704 lport = shost_priv(host);
701 port = lport_priv(lport); 705 port = lport_priv(lport);
702 hba = port->priv; 706 interface = port->priv;
703 707
704 if (rport == NULL) { 708 if (rport == NULL) {
705 printk(KERN_ERR PFX "device_reset: rport is NULL\n"); 709 printk(KERN_ERR PFX "device_reset: rport is NULL\n");
@@ -774,7 +778,8 @@ retry_tmf:
774 index = xid % BNX2FC_TASKS_PER_PAGE; 778 index = xid % BNX2FC_TASKS_PER_PAGE;
775 779
776 /* Initialize task context for this IO request */ 780 /* Initialize task context for this IO request */
777 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx]; 781 task_page = (struct fcoe_task_ctx_entry *)
782 interface->hba->task_ctx[task_idx];
778 task = &(task_page[index]); 783 task = &(task_page[index]);
779 bnx2fc_init_mp_task(io_req, task); 784 bnx2fc_init_mp_task(io_req, task);
780 785
@@ -822,7 +827,7 @@ int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req)
822 struct bnx2fc_rport *tgt = io_req->tgt; 827 struct bnx2fc_rport *tgt = io_req->tgt;
823 struct fc_rport *rport = tgt->rport; 828 struct fc_rport *rport = tgt->rport;
824 struct fc_rport_priv *rdata = tgt->rdata; 829 struct fc_rport_priv *rdata = tgt->rdata;
825 struct bnx2fc_hba *hba; 830 struct bnx2fc_interface *interface;
826 struct fcoe_port *port; 831 struct fcoe_port *port;
827 struct bnx2fc_cmd *abts_io_req; 832 struct bnx2fc_cmd *abts_io_req;
828 struct fcoe_task_ctx_entry *task; 833 struct fcoe_task_ctx_entry *task;
@@ -839,7 +844,7 @@ int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req)
839 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_abts\n"); 844 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_abts\n");
840 845
841 port = io_req->port; 846 port = io_req->port;
842 hba = port->priv; 847 interface = port->priv;
843 lport = port->lport; 848 lport = port->lport;
844 849
845 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) { 850 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
@@ -896,7 +901,8 @@ int bnx2fc_initiate_abts(struct bnx2fc_cmd *io_req)
896 index = xid % BNX2FC_TASKS_PER_PAGE; 901 index = xid % BNX2FC_TASKS_PER_PAGE;
897 902
898 /* Initialize task context for this IO request */ 903 /* Initialize task context for this IO request */
899 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx]; 904 task_page = (struct fcoe_task_ctx_entry *)
905 interface->hba->task_ctx[task_idx];
900 task = &(task_page[index]); 906 task = &(task_page[index]);
901 bnx2fc_init_mp_task(abts_io_req, task); 907 bnx2fc_init_mp_task(abts_io_req, task);
902 908
@@ -928,7 +934,7 @@ int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
928{ 934{
929 struct fc_lport *lport; 935 struct fc_lport *lport;
930 struct bnx2fc_rport *tgt = io_req->tgt; 936 struct bnx2fc_rport *tgt = io_req->tgt;
931 struct bnx2fc_hba *hba; 937 struct bnx2fc_interface *interface;
932 struct fcoe_port *port; 938 struct fcoe_port *port;
933 struct bnx2fc_cmd *cleanup_io_req; 939 struct bnx2fc_cmd *cleanup_io_req;
934 struct fcoe_task_ctx_entry *task; 940 struct fcoe_task_ctx_entry *task;
@@ -941,7 +947,7 @@ int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
941 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_cleanup\n"); 947 BNX2FC_IO_DBG(io_req, "Entered bnx2fc_initiate_cleanup\n");
942 948
943 port = io_req->port; 949 port = io_req->port;
944 hba = port->priv; 950 interface = port->priv;
945 lport = port->lport; 951 lport = port->lport;
946 952
947 cleanup_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_CLEANUP); 953 cleanup_io_req = bnx2fc_elstm_alloc(tgt, BNX2FC_CLEANUP);
@@ -963,7 +969,8 @@ int bnx2fc_initiate_cleanup(struct bnx2fc_cmd *io_req)
963 index = xid % BNX2FC_TASKS_PER_PAGE; 969 index = xid % BNX2FC_TASKS_PER_PAGE;
964 970
965 /* Initialize task context for this IO request */ 971 /* Initialize task context for this IO request */
966 task_page = (struct fcoe_task_ctx_entry *) hba->task_ctx[task_idx]; 972 task_page = (struct fcoe_task_ctx_entry *)
973 interface->hba->task_ctx[task_idx];
967 task = &(task_page[index]); 974 task = &(task_page[index]);
968 orig_xid = io_req->xid; 975 orig_xid = io_req->xid;
969 976
@@ -1796,7 +1803,8 @@ static int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
1796 struct fcoe_task_ctx_entry *task_page; 1803 struct fcoe_task_ctx_entry *task_page;
1797 struct scsi_cmnd *sc_cmd = io_req->sc_cmd; 1804 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1798 struct fcoe_port *port = tgt->port; 1805 struct fcoe_port *port = tgt->port;
1799 struct bnx2fc_hba *hba = port->priv; 1806 struct bnx2fc_interface *interface = port->priv;
1807 struct bnx2fc_hba *hba = interface->hba;
1800 struct fc_lport *lport = port->lport; 1808 struct fc_lport *lport = port->lport;
1801 struct fcoe_dev_stats *stats; 1809 struct fcoe_dev_stats *stats;
1802 int task_idx, index; 1810 int task_idx, index;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_tgt.c b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
index 4be391edd0c6..263c2678ff62 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_tgt.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_tgt.c
@@ -65,7 +65,8 @@ static void bnx2fc_offload_session(struct fcoe_port *port,
65{ 65{
66 struct fc_lport *lport = rdata->local_port; 66 struct fc_lport *lport = rdata->local_port;
67 struct fc_rport *rport = rdata->rport; 67 struct fc_rport *rport = rdata->rport;
68 struct bnx2fc_hba *hba = port->priv; 68 struct bnx2fc_interface *interface = port->priv;
69 struct bnx2fc_hba *hba = interface->hba;
69 int rval; 70 int rval;
70 int i = 0; 71 int i = 0;
71 72
@@ -237,7 +238,8 @@ void bnx2fc_flush_active_ios(struct bnx2fc_rport *tgt)
237static void bnx2fc_upload_session(struct fcoe_port *port, 238static void bnx2fc_upload_session(struct fcoe_port *port,
238 struct bnx2fc_rport *tgt) 239 struct bnx2fc_rport *tgt)
239{ 240{
240 struct bnx2fc_hba *hba = port->priv; 241 struct bnx2fc_interface *interface = port->priv;
242 struct bnx2fc_hba *hba = interface->hba;
241 243
242 BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n", 244 BNX2FC_TGT_DBG(tgt, "upload_session: active_ios = %d\n",
243 tgt->num_active_ios.counter); 245 tgt->num_active_ios.counter);
@@ -316,7 +318,8 @@ static int bnx2fc_init_tgt(struct bnx2fc_rport *tgt,
316{ 318{
317 319
318 struct fc_rport *rport = rdata->rport; 320 struct fc_rport *rport = rdata->rport;
319 struct bnx2fc_hba *hba = port->priv; 321 struct bnx2fc_interface *interface = port->priv;
322 struct bnx2fc_hba *hba = interface->hba;
320 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db; 323 struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
321 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db; 324 struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
322 325
@@ -392,7 +395,8 @@ void bnx2fc_rport_event_handler(struct fc_lport *lport,
392 enum fc_rport_event event) 395 enum fc_rport_event event)
393{ 396{
394 struct fcoe_port *port = lport_priv(lport); 397 struct fcoe_port *port = lport_priv(lport);
395 struct bnx2fc_hba *hba = port->priv; 398 struct bnx2fc_interface *interface = port->priv;
399 struct bnx2fc_hba *hba = interface->hba;
396 struct fc_rport *rport = rdata->rport; 400 struct fc_rport *rport = rdata->rport;
397 struct fc_rport_libfc_priv *rp; 401 struct fc_rport_libfc_priv *rp;
398 struct bnx2fc_rport *tgt; 402 struct bnx2fc_rport *tgt;
@@ -537,7 +541,8 @@ void bnx2fc_rport_event_handler(struct fc_lport *lport,
537struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port, 541struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
538 u32 port_id) 542 u32 port_id)
539{ 543{
540 struct bnx2fc_hba *hba = port->priv; 544 struct bnx2fc_interface *interface = port->priv;
545 struct bnx2fc_hba *hba = interface->hba;
541 struct bnx2fc_rport *tgt; 546 struct bnx2fc_rport *tgt;
542 struct fc_rport_priv *rdata; 547 struct fc_rport_priv *rdata;
543 int i; 548 int i;
@@ -552,7 +557,7 @@ struct bnx2fc_rport *bnx2fc_tgt_lookup(struct fcoe_port *port,
552 "obtained\n"); 557 "obtained\n");
553 return tgt; 558 return tgt;
554 } else { 559 } else {
555 printk(KERN_ERR PFX "rport 0x%x " 560 BNX2FC_TGT_DBG(tgt, "rport 0x%x "
556 "is in DELETED state\n", 561 "is in DELETED state\n",
557 rdata->ids.port_id); 562 rdata->ids.port_id);
558 return NULL; 563 return NULL;