aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJames Bottomley <JBottomley@Parallels.com>2013-11-09 23:19:15 -0500
committerJames Bottomley <JBottomley@Parallels.com>2013-11-09 23:19:15 -0500
commit323f6226a816f0b01514d25fba5529e0e68636c3 (patch)
tree964ca28650bc92ce0ed2ba87c1c16ba65f55ebf5 /drivers
parent6fd046f960354250de3fed411eecdb784601bbad (diff)
parent6942df7f775107b504f10de42c81971f514d718d (diff)
Merge tag 'fcoe-3.13' into for-linus
Pull Request for 3.13 for FCOE tree. Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c4
-rw-r--r--drivers/scsi/fcoe/fcoe.c25
-rw-r--r--drivers/scsi/fcoe/fcoe_ctlr.c148
-rw-r--r--drivers/scsi/fcoe/fcoe_sysfs.c14
-rw-r--r--drivers/scsi/fnic/fnic_fcs.c6
-rw-r--r--drivers/scsi/libfc/fc_exch.c251
-rw-r--r--drivers/scsi/libfc/fc_fcp.c10
-rw-r--r--drivers/scsi/libfc/fc_lport.c4
-rw-r--r--drivers/scsi/libfc/fc_rport.c6
9 files changed, 294 insertions, 174 deletions
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 3c204ad1d5b9..9b948505d118 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -542,8 +542,7 @@ static void bnx2fc_recv_frame(struct sk_buff *skb)
542 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id)); 542 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
543 if (vn_port) { 543 if (vn_port) {
544 port = lport_priv(vn_port); 544 port = lport_priv(vn_port);
545 if (compare_ether_addr(port->data_src_addr, dest_mac) 545 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
546 != 0) {
547 BNX2FC_HBA_DBG(lport, "fpma mismatch\n"); 546 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
548 put_cpu(); 547 put_cpu();
549 kfree_skb(skb); 548 kfree_skb(skb);
@@ -1381,6 +1380,7 @@ struct bnx2fc_interface *bnx2fc_interface_create(struct bnx2fc_hba *hba,
1381 return NULL; 1380 return NULL;
1382 } 1381 }
1383 ctlr = fcoe_ctlr_device_priv(ctlr_dev); 1382 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1383 ctlr->cdev = ctlr_dev;
1384 interface = fcoe_ctlr_priv(ctlr); 1384 interface = fcoe_ctlr_priv(ctlr);
1385 dev_hold(netdev); 1385 dev_hold(netdev);
1386 kref_init(&interface->kref); 1386 kref_init(&interface->kref);
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 07453bbf05e7..f3170008ae71 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -408,6 +408,7 @@ static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev,
408 } 408 }
409 409
410 ctlr = fcoe_ctlr_device_priv(ctlr_dev); 410 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
411 ctlr->cdev = ctlr_dev;
411 fcoe = fcoe_ctlr_priv(ctlr); 412 fcoe = fcoe_ctlr_priv(ctlr);
412 413
413 dev_hold(netdev); 414 dev_hold(netdev);
@@ -1440,22 +1441,28 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
1440 ctlr = fcoe_to_ctlr(fcoe); 1441 ctlr = fcoe_to_ctlr(fcoe);
1441 lport = ctlr->lp; 1442 lport = ctlr->lp;
1442 if (unlikely(!lport)) { 1443 if (unlikely(!lport)) {
1443 FCOE_NETDEV_DBG(netdev, "Cannot find hba structure"); 1444 FCOE_NETDEV_DBG(netdev, "Cannot find hba structure\n");
1444 goto err2; 1445 goto err2;
1445 } 1446 }
1446 if (!lport->link_up) 1447 if (!lport->link_up)
1447 goto err2; 1448 goto err2;
1448 1449
1449 FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p " 1450 FCOE_NETDEV_DBG(netdev,
1450 "data:%p tail:%p end:%p sum:%d dev:%s", 1451 "skb_info: len:%d data_len:%d head:%p data:%p tail:%p end:%p sum:%d dev:%s\n",
1451 skb->len, skb->data_len, skb->head, skb->data, 1452 skb->len, skb->data_len, skb->head, skb->data,
1452 skb_tail_pointer(skb), skb_end_pointer(skb), 1453 skb_tail_pointer(skb), skb_end_pointer(skb),
1453 skb->csum, skb->dev ? skb->dev->name : "<NULL>"); 1454 skb->csum, skb->dev ? skb->dev->name : "<NULL>");
1454 1455
1456
1457 skb = skb_share_check(skb, GFP_ATOMIC);
1458
1459 if (skb == NULL)
1460 return NET_RX_DROP;
1461
1455 eh = eth_hdr(skb); 1462 eh = eth_hdr(skb);
1456 1463
1457 if (is_fip_mode(ctlr) && 1464 if (is_fip_mode(ctlr) &&
1458 compare_ether_addr(eh->h_source, ctlr->dest_addr)) { 1465 !ether_addr_equal(eh->h_source, ctlr->dest_addr)) {
1459 FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n", 1466 FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n",
1460 eh->h_source); 1467 eh->h_source);
1461 goto err; 1468 goto err;
@@ -1540,13 +1547,13 @@ static int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev,
1540 wake_up_process(fps->thread); 1547 wake_up_process(fps->thread);
1541 spin_unlock(&fps->fcoe_rx_list.lock); 1548 spin_unlock(&fps->fcoe_rx_list.lock);
1542 1549
1543 return 0; 1550 return NET_RX_SUCCESS;
1544err: 1551err:
1545 per_cpu_ptr(lport->stats, get_cpu())->ErrorFrames++; 1552 per_cpu_ptr(lport->stats, get_cpu())->ErrorFrames++;
1546 put_cpu(); 1553 put_cpu();
1547err2: 1554err2:
1548 kfree_skb(skb); 1555 kfree_skb(skb);
1549 return -1; 1556 return NET_RX_DROP;
1550} 1557}
1551 1558
1552/** 1559/**
@@ -1788,13 +1795,13 @@ static void fcoe_recv_frame(struct sk_buff *skb)
1788 lport = fr->fr_dev; 1795 lport = fr->fr_dev;
1789 if (unlikely(!lport)) { 1796 if (unlikely(!lport)) {
1790 if (skb->destructor != fcoe_percpu_flush_done) 1797 if (skb->destructor != fcoe_percpu_flush_done)
1791 FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb"); 1798 FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb\n");
1792 kfree_skb(skb); 1799 kfree_skb(skb);
1793 return; 1800 return;
1794 } 1801 }
1795 1802
1796 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d " 1803 FCOE_NETDEV_DBG(skb->dev,
1797 "head:%p data:%p tail:%p end:%p sum:%d dev:%s", 1804 "skb_info: len:%d data_len:%d head:%p data:%p tail:%p end:%p sum:%d dev:%s\n",
1798 skb->len, skb->data_len, 1805 skb->len, skb->data_len,
1799 skb->head, skb->data, skb_tail_pointer(skb), 1806 skb->head, skb->data, skb_tail_pointer(skb),
1800 skb_end_pointer(skb), skb->csum, 1807 skb_end_pointer(skb), skb->csum,
diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index 203415e02518..34a1b1f333b4 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -160,74 +160,113 @@ void fcoe_ctlr_init(struct fcoe_ctlr *fip, enum fip_state mode)
160} 160}
161EXPORT_SYMBOL(fcoe_ctlr_init); 161EXPORT_SYMBOL(fcoe_ctlr_init);
162 162
163/**
164 * fcoe_sysfs_fcf_add() - Add a fcoe_fcf{,_device} to a fcoe_ctlr{,_device}
165 * @new: The newly discovered FCF
166 *
167 * Called with fip->ctlr_mutex held
168 */
163static int fcoe_sysfs_fcf_add(struct fcoe_fcf *new) 169static int fcoe_sysfs_fcf_add(struct fcoe_fcf *new)
164{ 170{
165 struct fcoe_ctlr *fip = new->fip; 171 struct fcoe_ctlr *fip = new->fip;
166 struct fcoe_ctlr_device *ctlr_dev = fcoe_ctlr_to_ctlr_dev(fip); 172 struct fcoe_ctlr_device *ctlr_dev;
167 struct fcoe_fcf_device temp, *fcf_dev; 173 struct fcoe_fcf_device *temp, *fcf_dev;
168 int rc = 0; 174 int rc = -ENOMEM;
169 175
170 LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n", 176 LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n",
171 new->fabric_name, new->fcf_mac); 177 new->fabric_name, new->fcf_mac);
172 178
173 mutex_lock(&ctlr_dev->lock); 179 temp = kzalloc(sizeof(*temp), GFP_KERNEL);
174 180 if (!temp)
175 temp.fabric_name = new->fabric_name;
176 temp.switch_name = new->switch_name;
177 temp.fc_map = new->fc_map;
178 temp.vfid = new->vfid;
179 memcpy(temp.mac, new->fcf_mac, ETH_ALEN);
180 temp.priority = new->pri;
181 temp.fka_period = new->fka_period;
182 temp.selected = 0; /* default to unselected */
183
184 fcf_dev = fcoe_fcf_device_add(ctlr_dev, &temp);
185 if (unlikely(!fcf_dev)) {
186 rc = -ENOMEM;
187 goto out; 181 goto out;
188 } 182
183 temp->fabric_name = new->fabric_name;
184 temp->switch_name = new->switch_name;
185 temp->fc_map = new->fc_map;
186 temp->vfid = new->vfid;
187 memcpy(temp->mac, new->fcf_mac, ETH_ALEN);
188 temp->priority = new->pri;
189 temp->fka_period = new->fka_period;
190 temp->selected = 0; /* default to unselected */
189 191
190 /* 192 /*
191 * The fcoe_sysfs layer can return a CONNECTED fcf that 193 * If ctlr_dev doesn't exist then it means we're a libfcoe user
192 * has a priv (fcf was never deleted) or a CONNECTED fcf 194 * who doesn't use fcoe_syfs and didn't allocate a fcoe_ctlr_device.
193 * that doesn't have a priv (fcf was deleted). However, 195 * fnic would be an example of a driver with this behavior. In this
194 * libfcoe will always delete FCFs before trying to add 196 * case we want to add the fcoe_fcf to the fcoe_ctlr list, but we
195 * them. This is ensured because both recv_adv and 197 * don't want to make sysfs changes.
196 * age_fcfs are protected by the the fcoe_ctlr's mutex.
197 * This means that we should never get a FCF with a
198 * non-NULL priv pointer.
199 */ 198 */
200 BUG_ON(fcf_dev->priv);
201 199
202 fcf_dev->priv = new; 200 ctlr_dev = fcoe_ctlr_to_ctlr_dev(fip);
203 new->fcf_dev = fcf_dev; 201 if (ctlr_dev) {
202 mutex_lock(&ctlr_dev->lock);
203 fcf_dev = fcoe_fcf_device_add(ctlr_dev, temp);
204 if (unlikely(!fcf_dev)) {
205 rc = -ENOMEM;
206 mutex_unlock(&ctlr_dev->lock);
207 goto out;
208 }
209
210 /*
211 * The fcoe_sysfs layer can return a CONNECTED fcf that
212 * has a priv (fcf was never deleted) or a CONNECTED fcf
213 * that doesn't have a priv (fcf was deleted). However,
214 * libfcoe will always delete FCFs before trying to add
215 * them. This is ensured because both recv_adv and
216 * age_fcfs are protected by the the fcoe_ctlr's mutex.
217 * This means that we should never get a FCF with a
218 * non-NULL priv pointer.
219 */
220 BUG_ON(fcf_dev->priv);
221
222 fcf_dev->priv = new;
223 new->fcf_dev = fcf_dev;
224 mutex_unlock(&ctlr_dev->lock);
225 }
204 226
205 list_add(&new->list, &fip->fcfs); 227 list_add(&new->list, &fip->fcfs);
206 fip->fcf_count++; 228 fip->fcf_count++;
229 rc = 0;
207 230
208out: 231out:
209 mutex_unlock(&ctlr_dev->lock); 232 kfree(temp);
210 return rc; 233 return rc;
211} 234}
212 235
236/**
237 * fcoe_sysfs_fcf_del() - Remove a fcoe_fcf{,_device} to a fcoe_ctlr{,_device}
238 * @new: The FCF to be removed
239 *
240 * Called with fip->ctlr_mutex held
241 */
213static void fcoe_sysfs_fcf_del(struct fcoe_fcf *new) 242static void fcoe_sysfs_fcf_del(struct fcoe_fcf *new)
214{ 243{
215 struct fcoe_ctlr *fip = new->fip; 244 struct fcoe_ctlr *fip = new->fip;
216 struct fcoe_ctlr_device *ctlr_dev = fcoe_ctlr_to_ctlr_dev(fip); 245 struct fcoe_ctlr_device *cdev;
217 struct fcoe_fcf_device *fcf_dev; 246 struct fcoe_fcf_device *fcf_dev;
218 247
219 list_del(&new->list); 248 list_del(&new->list);
220 fip->fcf_count--; 249 fip->fcf_count--;
221 250
222 mutex_lock(&ctlr_dev->lock); 251 /*
223 252 * If ctlr_dev doesn't exist then it means we're a libfcoe user
224 fcf_dev = fcoe_fcf_to_fcf_dev(new); 253 * who doesn't use fcoe_syfs and didn't allocate a fcoe_ctlr_device
225 WARN_ON(!fcf_dev); 254 * or a fcoe_fcf_device.
226 new->fcf_dev = NULL; 255 *
227 fcoe_fcf_device_delete(fcf_dev); 256 * fnic would be an example of a driver with this behavior. In this
228 kfree(new); 257 * case we want to remove the fcoe_fcf from the fcoe_ctlr list (above),
229 258 * but we don't want to make sysfs changes.
230 mutex_unlock(&ctlr_dev->lock); 259 */
260 cdev = fcoe_ctlr_to_ctlr_dev(fip);
261 if (cdev) {
262 mutex_lock(&cdev->lock);
263 fcf_dev = fcoe_fcf_to_fcf_dev(new);
264 WARN_ON(!fcf_dev);
265 new->fcf_dev = NULL;
266 fcoe_fcf_device_delete(fcf_dev);
267 kfree(new);
268 mutex_unlock(&cdev->lock);
269 }
231} 270}
232 271
233/** 272/**
@@ -300,7 +339,7 @@ static void fcoe_ctlr_announce(struct fcoe_ctlr *fip)
300 spin_unlock_bh(&fip->ctlr_lock); 339 spin_unlock_bh(&fip->ctlr_lock);
301 sel = fip->sel_fcf; 340 sel = fip->sel_fcf;
302 341
303 if (sel && !compare_ether_addr(sel->fcf_mac, fip->dest_addr)) 342 if (sel && ether_addr_equal(sel->fcf_mac, fip->dest_addr))
304 goto unlock; 343 goto unlock;
305 if (!is_zero_ether_addr(fip->dest_addr)) { 344 if (!is_zero_ether_addr(fip->dest_addr)) {
306 printk(KERN_NOTICE "libfcoe: host%d: " 345 printk(KERN_NOTICE "libfcoe: host%d: "
@@ -1000,7 +1039,7 @@ static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1000 if (fcf->switch_name == new.switch_name && 1039 if (fcf->switch_name == new.switch_name &&
1001 fcf->fabric_name == new.fabric_name && 1040 fcf->fabric_name == new.fabric_name &&
1002 fcf->fc_map == new.fc_map && 1041 fcf->fc_map == new.fc_map &&
1003 compare_ether_addr(fcf->fcf_mac, new.fcf_mac) == 0) { 1042 ether_addr_equal(fcf->fcf_mac, new.fcf_mac)) {
1004 found = 1; 1043 found = 1;
1005 break; 1044 break;
1006 } 1045 }
@@ -1340,7 +1379,7 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
1340 mp = (struct fip_mac_desc *)desc; 1379 mp = (struct fip_mac_desc *)desc;
1341 if (dlen < sizeof(*mp)) 1380 if (dlen < sizeof(*mp))
1342 goto err; 1381 goto err;
1343 if (compare_ether_addr(mp->fd_mac, fcf->fcf_mac)) 1382 if (!ether_addr_equal(mp->fd_mac, fcf->fcf_mac))
1344 goto err; 1383 goto err;
1345 desc_mask &= ~BIT(FIP_DT_MAC); 1384 desc_mask &= ~BIT(FIP_DT_MAC);
1346 break; 1385 break;
@@ -1418,8 +1457,8 @@ static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
1418 * 'port_id' is already validated, check MAC address and 1457 * 'port_id' is already validated, check MAC address and
1419 * wwpn 1458 * wwpn
1420 */ 1459 */
1421 if (compare_ether_addr(fip->get_src_addr(vn_port), 1460 if (!ether_addr_equal(fip->get_src_addr(vn_port),
1422 vp->fd_mac) != 0 || 1461 vp->fd_mac) ||
1423 get_unaligned_be64(&vp->fd_wwpn) != 1462 get_unaligned_be64(&vp->fd_wwpn) !=
1424 vn_port->wwpn) 1463 vn_port->wwpn)
1425 continue; 1464 continue;
@@ -1453,6 +1492,9 @@ err:
1453 */ 1492 */
1454void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) 1493void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1455{ 1494{
1495 skb = skb_share_check(skb, GFP_ATOMIC);
1496 if (!skb)
1497 return;
1456 skb_queue_tail(&fip->fip_recv_list, skb); 1498 skb_queue_tail(&fip->fip_recv_list, skb);
1457 schedule_work(&fip->recv_work); 1499 schedule_work(&fip->recv_work);
1458} 1500}
@@ -1479,12 +1521,12 @@ static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
1479 goto drop; 1521 goto drop;
1480 eh = eth_hdr(skb); 1522 eh = eth_hdr(skb);
1481 if (fip->mode == FIP_MODE_VN2VN) { 1523 if (fip->mode == FIP_MODE_VN2VN) {
1482 if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) && 1524 if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) &&
1483 compare_ether_addr(eh->h_dest, fcoe_all_vn2vn) && 1525 !ether_addr_equal(eh->h_dest, fcoe_all_vn2vn) &&
1484 compare_ether_addr(eh->h_dest, fcoe_all_p2p)) 1526 !ether_addr_equal(eh->h_dest, fcoe_all_p2p))
1485 goto drop; 1527 goto drop;
1486 } else if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) && 1528 } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) &&
1487 compare_ether_addr(eh->h_dest, fcoe_all_enode)) 1529 !ether_addr_equal(eh->h_dest, fcoe_all_enode))
1488 goto drop; 1530 goto drop;
1489 fiph = (struct fip_header *)skb->data; 1531 fiph = (struct fip_header *)skb->data;
1490 op = ntohs(fiph->fip_op); 1532 op = ntohs(fiph->fip_op);
@@ -1856,7 +1898,7 @@ int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport,
1856 * address_mode flag to use FC_OUI-based Ethernet DA. 1898 * address_mode flag to use FC_OUI-based Ethernet DA.
1857 * Otherwise we use the FCoE gateway addr 1899 * Otherwise we use the FCoE gateway addr
1858 */ 1900 */
1859 if (!compare_ether_addr(sa, (u8[6])FC_FCOE_FLOGI_MAC)) { 1901 if (ether_addr_equal(sa, (u8[6])FC_FCOE_FLOGI_MAC)) {
1860 fcoe_ctlr_map_dest(fip); 1902 fcoe_ctlr_map_dest(fip);
1861 } else { 1903 } else {
1862 memcpy(fip->dest_addr, sa, ETH_ALEN); 1904 memcpy(fip->dest_addr, sa, ETH_ALEN);
@@ -2825,8 +2867,8 @@ unlock:
2825 * disabled, so that should ensure that this routine is only called 2867 * disabled, so that should ensure that this routine is only called
2826 * when nothing is happening. 2868 * when nothing is happening.
2827 */ 2869 */
2828void fcoe_ctlr_mode_set(struct fc_lport *lport, struct fcoe_ctlr *fip, 2870static void fcoe_ctlr_mode_set(struct fc_lport *lport, struct fcoe_ctlr *fip,
2829 enum fip_state fip_mode) 2871 enum fip_state fip_mode)
2830{ 2872{
2831 void *priv; 2873 void *priv;
2832 2874
diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
index c9382d6eee78..d0d9a2d6120f 100644
--- a/drivers/scsi/fcoe/fcoe_sysfs.c
+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
@@ -300,29 +300,29 @@ static ssize_t store_ctlr_mode(struct device *dev,
300 300
301 switch (ctlr->enabled) { 301 switch (ctlr->enabled) {
302 case FCOE_CTLR_ENABLED: 302 case FCOE_CTLR_ENABLED:
303 LIBFCOE_SYSFS_DBG(ctlr, "Cannot change mode when enabled."); 303 LIBFCOE_SYSFS_DBG(ctlr, "Cannot change mode when enabled.\n");
304 return -EBUSY; 304 return -EBUSY;
305 case FCOE_CTLR_DISABLED: 305 case FCOE_CTLR_DISABLED:
306 if (!ctlr->f->set_fcoe_ctlr_mode) { 306 if (!ctlr->f->set_fcoe_ctlr_mode) {
307 LIBFCOE_SYSFS_DBG(ctlr, 307 LIBFCOE_SYSFS_DBG(ctlr,
308 "Mode change not supported by LLD."); 308 "Mode change not supported by LLD.\n");
309 return -ENOTSUPP; 309 return -ENOTSUPP;
310 } 310 }
311 311
312 ctlr->mode = fcoe_parse_mode(mode); 312 ctlr->mode = fcoe_parse_mode(mode);
313 if (ctlr->mode == FIP_CONN_TYPE_UNKNOWN) { 313 if (ctlr->mode == FIP_CONN_TYPE_UNKNOWN) {
314 LIBFCOE_SYSFS_DBG(ctlr, 314 LIBFCOE_SYSFS_DBG(ctlr, "Unknown mode %s provided.\n",
315 "Unknown mode %s provided.", buf); 315 buf);
316 return -EINVAL; 316 return -EINVAL;
317 } 317 }
318 318
319 ctlr->f->set_fcoe_ctlr_mode(ctlr); 319 ctlr->f->set_fcoe_ctlr_mode(ctlr);
320 LIBFCOE_SYSFS_DBG(ctlr, "Mode changed to %s.", buf); 320 LIBFCOE_SYSFS_DBG(ctlr, "Mode changed to %s.\n", buf);
321 321
322 return count; 322 return count;
323 case FCOE_CTLR_UNUSED: 323 case FCOE_CTLR_UNUSED:
324 default: 324 default:
325 LIBFCOE_SYSFS_DBG(ctlr, "Mode change not supported."); 325 LIBFCOE_SYSFS_DBG(ctlr, "Mode change not supported.\n");
326 return -ENOTSUPP; 326 return -ENOTSUPP;
327 }; 327 };
328} 328}
@@ -653,7 +653,7 @@ static int fcoe_fcf_device_match(struct fcoe_fcf_device *new,
653 if (new->switch_name == old->switch_name && 653 if (new->switch_name == old->switch_name &&
654 new->fabric_name == old->fabric_name && 654 new->fabric_name == old->fabric_name &&
655 new->fc_map == old->fc_map && 655 new->fc_map == old->fc_map &&
656 compare_ether_addr(new->mac, old->mac) == 0) 656 ether_addr_equal(new->mac, old->mac))
657 return 1; 657 return 1;
658 return 0; 658 return 0;
659} 659}
diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
index 60a1c50aa68f..1671325aec7f 100644
--- a/drivers/scsi/fnic/fnic_fcs.c
+++ b/drivers/scsi/fnic/fnic_fcs.c
@@ -658,13 +658,13 @@ void fnic_update_mac_locked(struct fnic *fnic, u8 *new)
658 658
659 if (is_zero_ether_addr(new)) 659 if (is_zero_ether_addr(new))
660 new = ctl; 660 new = ctl;
661 if (!compare_ether_addr(data, new)) 661 if (ether_addr_equal(data, new))
662 return; 662 return;
663 FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "update_mac %pM\n", new); 663 FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host, "update_mac %pM\n", new);
664 if (!is_zero_ether_addr(data) && compare_ether_addr(data, ctl)) 664 if (!is_zero_ether_addr(data) && !ether_addr_equal(data, ctl))
665 vnic_dev_del_addr(fnic->vdev, data); 665 vnic_dev_del_addr(fnic->vdev, data);
666 memcpy(data, new, ETH_ALEN); 666 memcpy(data, new, ETH_ALEN);
667 if (compare_ether_addr(new, ctl)) 667 if (!ether_addr_equal(new, ctl))
668 vnic_dev_add_addr(fnic->vdev, new); 668 vnic_dev_add_addr(fnic->vdev, new);
669} 669}
670 670
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 587992952b3c..1b3a09473452 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/export.h> 29#include <linux/export.h>
30#include <linux/log2.h>
30 31
31#include <scsi/fc/fc_fc2.h> 32#include <scsi/fc/fc_fc2.h>
32 33
@@ -303,10 +304,7 @@ static void fc_exch_setup_hdr(struct fc_exch *ep, struct fc_frame *fp,
303 fr_eof(fp) = FC_EOF_N; 304 fr_eof(fp) = FC_EOF_N;
304 } 305 }
305 306
306 /* 307 /* Initialize remaining fh fields from fc_fill_fc_hdr */
307 * Initialize remainig fh fields
308 * from fc_fill_fc_hdr
309 */
310 fh->fh_ox_id = htons(ep->oxid); 308 fh->fh_ox_id = htons(ep->oxid);
311 fh->fh_rx_id = htons(ep->rxid); 309 fh->fh_rx_id = htons(ep->rxid);
312 fh->fh_seq_id = ep->seq.id; 310 fh->fh_seq_id = ep->seq.id;
@@ -362,9 +360,10 @@ static inline void fc_exch_timer_set_locked(struct fc_exch *ep,
362 360
363 FC_EXCH_DBG(ep, "Exchange timer armed : %d msecs\n", timer_msec); 361 FC_EXCH_DBG(ep, "Exchange timer armed : %d msecs\n", timer_msec);
364 362
365 if (queue_delayed_work(fc_exch_workqueue, &ep->timeout_work, 363 fc_exch_hold(ep); /* hold for timer */
366 msecs_to_jiffies(timer_msec))) 364 if (!queue_delayed_work(fc_exch_workqueue, &ep->timeout_work,
367 fc_exch_hold(ep); /* hold for timer */ 365 msecs_to_jiffies(timer_msec)))
366 fc_exch_release(ep);
368} 367}
369 368
370/** 369/**
@@ -382,6 +381,8 @@ static void fc_exch_timer_set(struct fc_exch *ep, unsigned int timer_msec)
382/** 381/**
383 * fc_exch_done_locked() - Complete an exchange with the exchange lock held 382 * fc_exch_done_locked() - Complete an exchange with the exchange lock held
384 * @ep: The exchange that is complete 383 * @ep: The exchange that is complete
384 *
385 * Note: May sleep if invoked from outside a response handler.
385 */ 386 */
386static int fc_exch_done_locked(struct fc_exch *ep) 387static int fc_exch_done_locked(struct fc_exch *ep)
387{ 388{
@@ -393,7 +394,6 @@ static int fc_exch_done_locked(struct fc_exch *ep)
393 * ep, and in that case we only clear the resp and set it as 394 * ep, and in that case we only clear the resp and set it as
394 * complete, so it can be reused by the timer to send the rrq. 395 * complete, so it can be reused by the timer to send the rrq.
395 */ 396 */
396 ep->resp = NULL;
397 if (ep->state & FC_EX_DONE) 397 if (ep->state & FC_EX_DONE)
398 return rc; 398 return rc;
399 ep->esb_stat |= ESB_ST_COMPLETE; 399 ep->esb_stat |= ESB_ST_COMPLETE;
@@ -464,15 +464,21 @@ static void fc_exch_delete(struct fc_exch *ep)
464} 464}
465 465
466static int fc_seq_send_locked(struct fc_lport *lport, struct fc_seq *sp, 466static int fc_seq_send_locked(struct fc_lport *lport, struct fc_seq *sp,
467 struct fc_frame *fp) 467 struct fc_frame *fp)
468{ 468{
469 struct fc_exch *ep; 469 struct fc_exch *ep;
470 struct fc_frame_header *fh = fc_frame_header_get(fp); 470 struct fc_frame_header *fh = fc_frame_header_get(fp);
471 int error; 471 int error = -ENXIO;
472 u32 f_ctl; 472 u32 f_ctl;
473 u8 fh_type = fh->fh_type; 473 u8 fh_type = fh->fh_type;
474 474
475 ep = fc_seq_exch(sp); 475 ep = fc_seq_exch(sp);
476
477 if (ep->esb_stat & (ESB_ST_COMPLETE | ESB_ST_ABNORMAL)) {
478 fc_frame_free(fp);
479 goto out;
480 }
481
476 WARN_ON(!(ep->esb_stat & ESB_ST_SEQ_INIT)); 482 WARN_ON(!(ep->esb_stat & ESB_ST_SEQ_INIT));
477 483
478 f_ctl = ntoh24(fh->fh_f_ctl); 484 f_ctl = ntoh24(fh->fh_f_ctl);
@@ -515,6 +521,9 @@ out:
515 * @lport: The local port that the exchange will be sent on 521 * @lport: The local port that the exchange will be sent on
516 * @sp: The sequence to be sent 522 * @sp: The sequence to be sent
517 * @fp: The frame to be sent on the exchange 523 * @fp: The frame to be sent on the exchange
524 *
525 * Note: The frame will be freed either by a direct call to fc_frame_free(fp)
526 * or indirectly by calling libfc_function_template.frame_send().
518 */ 527 */
519static int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp, 528static int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp,
520 struct fc_frame *fp) 529 struct fc_frame *fp)
@@ -581,6 +590,8 @@ static struct fc_seq *fc_seq_start_next(struct fc_seq *sp)
581 590
582/* 591/*
583 * Set the response handler for the exchange associated with a sequence. 592 * Set the response handler for the exchange associated with a sequence.
593 *
594 * Note: May sleep if invoked from outside a response handler.
584 */ 595 */
585static void fc_seq_set_resp(struct fc_seq *sp, 596static void fc_seq_set_resp(struct fc_seq *sp,
586 void (*resp)(struct fc_seq *, struct fc_frame *, 597 void (*resp)(struct fc_seq *, struct fc_frame *,
@@ -588,8 +599,18 @@ static void fc_seq_set_resp(struct fc_seq *sp,
588 void *arg) 599 void *arg)
589{ 600{
590 struct fc_exch *ep = fc_seq_exch(sp); 601 struct fc_exch *ep = fc_seq_exch(sp);
602 DEFINE_WAIT(wait);
591 603
592 spin_lock_bh(&ep->ex_lock); 604 spin_lock_bh(&ep->ex_lock);
605 while (ep->resp_active && ep->resp_task != current) {
606 prepare_to_wait(&ep->resp_wq, &wait, TASK_UNINTERRUPTIBLE);
607 spin_unlock_bh(&ep->ex_lock);
608
609 schedule();
610
611 spin_lock_bh(&ep->ex_lock);
612 }
613 finish_wait(&ep->resp_wq, &wait);
593 ep->resp = resp; 614 ep->resp = resp;
594 ep->arg = arg; 615 ep->arg = arg;
595 spin_unlock_bh(&ep->ex_lock); 616 spin_unlock_bh(&ep->ex_lock);
@@ -622,27 +643,31 @@ static int fc_exch_abort_locked(struct fc_exch *ep,
622 if (!sp) 643 if (!sp)
623 return -ENOMEM; 644 return -ENOMEM;
624 645
625 ep->esb_stat |= ESB_ST_SEQ_INIT | ESB_ST_ABNORMAL;
626 if (timer_msec) 646 if (timer_msec)
627 fc_exch_timer_set_locked(ep, timer_msec); 647 fc_exch_timer_set_locked(ep, timer_msec);
628 648
629 /* 649 if (ep->sid) {
630 * If not logged into the fabric, don't send ABTS but leave 650 /*
631 * sequence active until next timeout. 651 * Send an abort for the sequence that timed out.
632 */ 652 */
633 if (!ep->sid) 653 fp = fc_frame_alloc(ep->lp, 0);
634 return 0; 654 if (fp) {
635 655 ep->esb_stat |= ESB_ST_SEQ_INIT;
636 /* 656 fc_fill_fc_hdr(fp, FC_RCTL_BA_ABTS, ep->did, ep->sid,
637 * Send an abort for the sequence that timed out. 657 FC_TYPE_BLS, FC_FC_END_SEQ |
638 */ 658 FC_FC_SEQ_INIT, 0);
639 fp = fc_frame_alloc(ep->lp, 0); 659 error = fc_seq_send_locked(ep->lp, sp, fp);
640 if (fp) { 660 } else {
641 fc_fill_fc_hdr(fp, FC_RCTL_BA_ABTS, ep->did, ep->sid, 661 error = -ENOBUFS;
642 FC_TYPE_BLS, FC_FC_END_SEQ | FC_FC_SEQ_INIT, 0); 662 }
643 error = fc_seq_send_locked(ep->lp, sp, fp); 663 } else {
644 } else 664 /*
645 error = -ENOBUFS; 665 * If not logged into the fabric, don't send ABTS but leave
666 * sequence active until next timeout.
667 */
668 error = 0;
669 }
670 ep->esb_stat |= ESB_ST_ABNORMAL;
646 return error; 671 return error;
647} 672}
648 673
@@ -669,6 +694,61 @@ static int fc_seq_exch_abort(const struct fc_seq *req_sp,
669} 694}
670 695
671/** 696/**
697 * fc_invoke_resp() - invoke ep->resp()
698 *
699 * Notes:
700 * It is assumed that after initialization finished (this means the
701 * first unlock of ex_lock after fc_exch_alloc()) ep->resp and ep->arg are
702 * modified only via fc_seq_set_resp(). This guarantees that none of these
703 * two variables changes if ep->resp_active > 0.
704 *
705 * If an fc_seq_set_resp() call is busy modifying ep->resp and ep->arg when
706 * this function is invoked, the first spin_lock_bh() call in this function
707 * will wait until fc_seq_set_resp() has finished modifying these variables.
708 *
709 * Since fc_exch_done() invokes fc_seq_set_resp() it is guaranteed that that
710 * ep->resp() won't be invoked after fc_exch_done() has returned.
711 *
712 * The response handler itself may invoke fc_exch_done(), which will clear the
713 * ep->resp pointer.
714 *
715 * Return value:
716 * Returns true if and only if ep->resp has been invoked.
717 */
718static bool fc_invoke_resp(struct fc_exch *ep, struct fc_seq *sp,
719 struct fc_frame *fp)
720{
721 void (*resp)(struct fc_seq *, struct fc_frame *fp, void *arg);
722 void *arg;
723 bool res = false;
724
725 spin_lock_bh(&ep->ex_lock);
726 ep->resp_active++;
727 if (ep->resp_task != current)
728 ep->resp_task = !ep->resp_task ? current : NULL;
729 resp = ep->resp;
730 arg = ep->arg;
731 spin_unlock_bh(&ep->ex_lock);
732
733 if (resp) {
734 resp(sp, fp, arg);
735 res = true;
736 } else if (!IS_ERR(fp)) {
737 fc_frame_free(fp);
738 }
739
740 spin_lock_bh(&ep->ex_lock);
741 if (--ep->resp_active == 0)
742 ep->resp_task = NULL;
743 spin_unlock_bh(&ep->ex_lock);
744
745 if (ep->resp_active == 0)
746 wake_up(&ep->resp_wq);
747
748 return res;
749}
750
751/**
672 * fc_exch_timeout() - Handle exchange timer expiration 752 * fc_exch_timeout() - Handle exchange timer expiration
673 * @work: The work_struct identifying the exchange that timed out 753 * @work: The work_struct identifying the exchange that timed out
674 */ 754 */
@@ -677,8 +757,6 @@ static void fc_exch_timeout(struct work_struct *work)
677 struct fc_exch *ep = container_of(work, struct fc_exch, 757 struct fc_exch *ep = container_of(work, struct fc_exch,
678 timeout_work.work); 758 timeout_work.work);
679 struct fc_seq *sp = &ep->seq; 759 struct fc_seq *sp = &ep->seq;
680 void (*resp)(struct fc_seq *, struct fc_frame *fp, void *arg);
681 void *arg;
682 u32 e_stat; 760 u32 e_stat;
683 int rc = 1; 761 int rc = 1;
684 762
@@ -696,16 +774,13 @@ static void fc_exch_timeout(struct work_struct *work)
696 fc_exch_rrq(ep); 774 fc_exch_rrq(ep);
697 goto done; 775 goto done;
698 } else { 776 } else {
699 resp = ep->resp;
700 arg = ep->arg;
701 ep->resp = NULL;
702 if (e_stat & ESB_ST_ABNORMAL) 777 if (e_stat & ESB_ST_ABNORMAL)
703 rc = fc_exch_done_locked(ep); 778 rc = fc_exch_done_locked(ep);
704 spin_unlock_bh(&ep->ex_lock); 779 spin_unlock_bh(&ep->ex_lock);
705 if (!rc) 780 if (!rc)
706 fc_exch_delete(ep); 781 fc_exch_delete(ep);
707 if (resp) 782 fc_invoke_resp(ep, sp, ERR_PTR(-FC_EX_TIMEOUT));
708 resp(sp, ERR_PTR(-FC_EX_TIMEOUT), arg); 783 fc_seq_set_resp(sp, NULL, ep->arg);
709 fc_seq_exch_abort(sp, 2 * ep->r_a_tov); 784 fc_seq_exch_abort(sp, 2 * ep->r_a_tov);
710 goto done; 785 goto done;
711 } 786 }
@@ -792,6 +867,8 @@ hit:
792 ep->f_ctl = FC_FC_FIRST_SEQ; /* next seq is first seq */ 867 ep->f_ctl = FC_FC_FIRST_SEQ; /* next seq is first seq */
793 ep->rxid = FC_XID_UNKNOWN; 868 ep->rxid = FC_XID_UNKNOWN;
794 ep->class = mp->class; 869 ep->class = mp->class;
870 ep->resp_active = 0;
871 init_waitqueue_head(&ep->resp_wq);
795 INIT_DELAYED_WORK(&ep->timeout_work, fc_exch_timeout); 872 INIT_DELAYED_WORK(&ep->timeout_work, fc_exch_timeout);
796out: 873out:
797 return ep; 874 return ep;
@@ -838,8 +915,10 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
838 pool = per_cpu_ptr(mp->pool, xid & fc_cpu_mask); 915 pool = per_cpu_ptr(mp->pool, xid & fc_cpu_mask);
839 spin_lock_bh(&pool->lock); 916 spin_lock_bh(&pool->lock);
840 ep = fc_exch_ptr_get(pool, (xid - mp->min_xid) >> fc_cpu_order); 917 ep = fc_exch_ptr_get(pool, (xid - mp->min_xid) >> fc_cpu_order);
841 if (ep && ep->xid == xid) 918 if (ep) {
919 WARN_ON(ep->xid != xid);
842 fc_exch_hold(ep); 920 fc_exch_hold(ep);
921 }
843 spin_unlock_bh(&pool->lock); 922 spin_unlock_bh(&pool->lock);
844 } 923 }
845 return ep; 924 return ep;
@@ -850,6 +929,8 @@ static struct fc_exch *fc_exch_find(struct fc_exch_mgr *mp, u16 xid)
850 * fc_exch_done() - Indicate that an exchange/sequence tuple is complete and 929 * fc_exch_done() - Indicate that an exchange/sequence tuple is complete and
851 * the memory allocated for the related objects may be freed. 930 * the memory allocated for the related objects may be freed.
852 * @sp: The sequence that has completed 931 * @sp: The sequence that has completed
932 *
933 * Note: May sleep if invoked from outside a response handler.
853 */ 934 */
854static void fc_exch_done(struct fc_seq *sp) 935static void fc_exch_done(struct fc_seq *sp)
855{ 936{
@@ -859,6 +940,8 @@ static void fc_exch_done(struct fc_seq *sp)
859 spin_lock_bh(&ep->ex_lock); 940 spin_lock_bh(&ep->ex_lock);
860 rc = fc_exch_done_locked(ep); 941 rc = fc_exch_done_locked(ep);
861 spin_unlock_bh(&ep->ex_lock); 942 spin_unlock_bh(&ep->ex_lock);
943
944 fc_seq_set_resp(sp, NULL, ep->arg);
862 if (!rc) 945 if (!rc)
863 fc_exch_delete(ep); 946 fc_exch_delete(ep);
864} 947}
@@ -987,6 +1070,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
987 } 1070 }
988 } 1071 }
989 1072
1073 spin_lock_bh(&ep->ex_lock);
990 /* 1074 /*
991 * At this point, we have the exchange held. 1075 * At this point, we have the exchange held.
992 * Find or create the sequence. 1076 * Find or create the sequence.
@@ -1014,11 +1098,11 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
1014 * sending RSP, hence write request on other 1098 * sending RSP, hence write request on other
1015 * end never finishes. 1099 * end never finishes.
1016 */ 1100 */
1017 spin_lock_bh(&ep->ex_lock);
1018 sp->ssb_stat |= SSB_ST_RESP; 1101 sp->ssb_stat |= SSB_ST_RESP;
1019 sp->id = fh->fh_seq_id; 1102 sp->id = fh->fh_seq_id;
1020 spin_unlock_bh(&ep->ex_lock);
1021 } else { 1103 } else {
1104 spin_unlock_bh(&ep->ex_lock);
1105
1022 /* sequence/exch should exist */ 1106 /* sequence/exch should exist */
1023 reject = FC_RJT_SEQ_ID; 1107 reject = FC_RJT_SEQ_ID;
1024 goto rel; 1108 goto rel;
@@ -1029,6 +1113,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
1029 1113
1030 if (f_ctl & FC_FC_SEQ_INIT) 1114 if (f_ctl & FC_FC_SEQ_INIT)
1031 ep->esb_stat |= ESB_ST_SEQ_INIT; 1115 ep->esb_stat |= ESB_ST_SEQ_INIT;
1116 spin_unlock_bh(&ep->ex_lock);
1032 1117
1033 fr_seq(fp) = sp; 1118 fr_seq(fp) = sp;
1034out: 1119out:
@@ -1291,21 +1376,23 @@ static void fc_exch_recv_abts(struct fc_exch *ep, struct fc_frame *rx_fp)
1291 1376
1292 if (!ep) 1377 if (!ep)
1293 goto reject; 1378 goto reject;
1379
1380 fp = fc_frame_alloc(ep->lp, sizeof(*ap));
1381 if (!fp)
1382 goto free;
1383
1294 spin_lock_bh(&ep->ex_lock); 1384 spin_lock_bh(&ep->ex_lock);
1295 if (ep->esb_stat & ESB_ST_COMPLETE) { 1385 if (ep->esb_stat & ESB_ST_COMPLETE) {
1296 spin_unlock_bh(&ep->ex_lock); 1386 spin_unlock_bh(&ep->ex_lock);
1387
1388 fc_frame_free(fp);
1297 goto reject; 1389 goto reject;
1298 } 1390 }
1299 if (!(ep->esb_stat & ESB_ST_REC_QUAL)) 1391 if (!(ep->esb_stat & ESB_ST_REC_QUAL)) {
1392 ep->esb_stat |= ESB_ST_REC_QUAL;
1300 fc_exch_hold(ep); /* hold for REC_QUAL */ 1393 fc_exch_hold(ep); /* hold for REC_QUAL */
1301 ep->esb_stat |= ESB_ST_ABNORMAL | ESB_ST_REC_QUAL;
1302 fc_exch_timer_set_locked(ep, ep->r_a_tov);
1303
1304 fp = fc_frame_alloc(ep->lp, sizeof(*ap));
1305 if (!fp) {
1306 spin_unlock_bh(&ep->ex_lock);
1307 goto free;
1308 } 1394 }
1395 fc_exch_timer_set_locked(ep, ep->r_a_tov);
1309 fh = fc_frame_header_get(fp); 1396 fh = fc_frame_header_get(fp);
1310 ap = fc_frame_payload_get(fp, sizeof(*ap)); 1397 ap = fc_frame_payload_get(fp, sizeof(*ap));
1311 memset(ap, 0, sizeof(*ap)); 1398 memset(ap, 0, sizeof(*ap));
@@ -1319,14 +1406,16 @@ static void fc_exch_recv_abts(struct fc_exch *ep, struct fc_frame *rx_fp)
1319 } 1406 }
1320 sp = fc_seq_start_next_locked(sp); 1407 sp = fc_seq_start_next_locked(sp);
1321 fc_seq_send_last(sp, fp, FC_RCTL_BA_ACC, FC_TYPE_BLS); 1408 fc_seq_send_last(sp, fp, FC_RCTL_BA_ACC, FC_TYPE_BLS);
1409 ep->esb_stat |= ESB_ST_ABNORMAL;
1322 spin_unlock_bh(&ep->ex_lock); 1410 spin_unlock_bh(&ep->ex_lock);
1411
1412free:
1323 fc_frame_free(rx_fp); 1413 fc_frame_free(rx_fp);
1324 return; 1414 return;
1325 1415
1326reject: 1416reject:
1327 fc_exch_send_ba_rjt(rx_fp, FC_BA_RJT_UNABLE, FC_BA_RJT_INV_XID); 1417 fc_exch_send_ba_rjt(rx_fp, FC_BA_RJT_UNABLE, FC_BA_RJT_INV_XID);
1328free: 1418 goto free;
1329 fc_frame_free(rx_fp);
1330} 1419}
1331 1420
1332/** 1421/**
@@ -1416,9 +1505,7 @@ static void fc_exch_recv_req(struct fc_lport *lport, struct fc_exch_mgr *mp,
1416 * If new exch resp handler is valid then call that 1505 * If new exch resp handler is valid then call that
1417 * first. 1506 * first.
1418 */ 1507 */
1419 if (ep->resp) 1508 if (!fc_invoke_resp(ep, sp, fp))
1420 ep->resp(sp, fp, ep->arg);
1421 else
1422 lport->tt.lport_recv(lport, fp); 1509 lport->tt.lport_recv(lport, fp);
1423 fc_exch_release(ep); /* release from lookup */ 1510 fc_exch_release(ep); /* release from lookup */
1424 } else { 1511 } else {
@@ -1442,8 +1529,6 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1442 struct fc_exch *ep; 1529 struct fc_exch *ep;
1443 enum fc_sof sof; 1530 enum fc_sof sof;
1444 u32 f_ctl; 1531 u32 f_ctl;
1445 void (*resp)(struct fc_seq *, struct fc_frame *fp, void *arg);
1446 void *ex_resp_arg;
1447 int rc; 1532 int rc;
1448 1533
1449 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id)); 1534 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
@@ -1478,19 +1563,19 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1478 1563
1479 f_ctl = ntoh24(fh->fh_f_ctl); 1564 f_ctl = ntoh24(fh->fh_f_ctl);
1480 fr_seq(fp) = sp; 1565 fr_seq(fp) = sp;
1566
1567 spin_lock_bh(&ep->ex_lock);
1481 if (f_ctl & FC_FC_SEQ_INIT) 1568 if (f_ctl & FC_FC_SEQ_INIT)
1482 ep->esb_stat |= ESB_ST_SEQ_INIT; 1569 ep->esb_stat |= ESB_ST_SEQ_INIT;
1570 spin_unlock_bh(&ep->ex_lock);
1483 1571
1484 if (fc_sof_needs_ack(sof)) 1572 if (fc_sof_needs_ack(sof))
1485 fc_seq_send_ack(sp, fp); 1573 fc_seq_send_ack(sp, fp);
1486 resp = ep->resp;
1487 ex_resp_arg = ep->arg;
1488 1574
1489 if (fh->fh_type != FC_TYPE_FCP && fr_eof(fp) == FC_EOF_T && 1575 if (fh->fh_type != FC_TYPE_FCP && fr_eof(fp) == FC_EOF_T &&
1490 (f_ctl & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) == 1576 (f_ctl & (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) ==
1491 (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) { 1577 (FC_FC_LAST_SEQ | FC_FC_END_SEQ)) {
1492 spin_lock_bh(&ep->ex_lock); 1578 spin_lock_bh(&ep->ex_lock);
1493 resp = ep->resp;
1494 rc = fc_exch_done_locked(ep); 1579 rc = fc_exch_done_locked(ep);
1495 WARN_ON(fc_seq_exch(sp) != ep); 1580 WARN_ON(fc_seq_exch(sp) != ep);
1496 spin_unlock_bh(&ep->ex_lock); 1581 spin_unlock_bh(&ep->ex_lock);
@@ -1511,10 +1596,8 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1511 * If new exch resp handler is valid then call that 1596 * If new exch resp handler is valid then call that
1512 * first. 1597 * first.
1513 */ 1598 */
1514 if (resp) 1599 fc_invoke_resp(ep, sp, fp);
1515 resp(sp, fp, ex_resp_arg); 1600
1516 else
1517 fc_frame_free(fp);
1518 fc_exch_release(ep); 1601 fc_exch_release(ep);
1519 return; 1602 return;
1520rel: 1603rel:
@@ -1553,8 +1636,6 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
1553 */ 1636 */
1554static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp) 1637static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
1555{ 1638{
1556 void (*resp)(struct fc_seq *, struct fc_frame *fp, void *arg);
1557 void *ex_resp_arg;
1558 struct fc_frame_header *fh; 1639 struct fc_frame_header *fh;
1559 struct fc_ba_acc *ap; 1640 struct fc_ba_acc *ap;
1560 struct fc_seq *sp; 1641 struct fc_seq *sp;
@@ -1599,9 +1680,6 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
1599 break; 1680 break;
1600 } 1681 }
1601 1682
1602 resp = ep->resp;
1603 ex_resp_arg = ep->arg;
1604
1605 /* do we need to do some other checks here. Can we reuse more of 1683 /* do we need to do some other checks here. Can we reuse more of
1606 * fc_exch_recv_seq_resp 1684 * fc_exch_recv_seq_resp
1607 */ 1685 */
@@ -1613,17 +1691,14 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
1613 ntoh24(fh->fh_f_ctl) & FC_FC_LAST_SEQ) 1691 ntoh24(fh->fh_f_ctl) & FC_FC_LAST_SEQ)
1614 rc = fc_exch_done_locked(ep); 1692 rc = fc_exch_done_locked(ep);
1615 spin_unlock_bh(&ep->ex_lock); 1693 spin_unlock_bh(&ep->ex_lock);
1694
1695 fc_exch_hold(ep);
1616 if (!rc) 1696 if (!rc)
1617 fc_exch_delete(ep); 1697 fc_exch_delete(ep);
1618 1698 fc_invoke_resp(ep, sp, fp);
1619 if (resp)
1620 resp(sp, fp, ex_resp_arg);
1621 else
1622 fc_frame_free(fp);
1623
1624 if (has_rec) 1699 if (has_rec)
1625 fc_exch_timer_set(ep, ep->r_a_tov); 1700 fc_exch_timer_set(ep, ep->r_a_tov);
1626 1701 fc_exch_release(ep);
1627} 1702}
1628 1703
1629/** 1704/**
@@ -1662,7 +1737,7 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
1662 break; 1737 break;
1663 default: 1738 default:
1664 if (ep) 1739 if (ep)
1665 FC_EXCH_DBG(ep, "BLS rctl %x - %s received", 1740 FC_EXCH_DBG(ep, "BLS rctl %x - %s received\n",
1666 fh->fh_r_ctl, 1741 fh->fh_r_ctl,
1667 fc_exch_rctl_name(fh->fh_r_ctl)); 1742 fc_exch_rctl_name(fh->fh_r_ctl));
1668 break; 1743 break;
@@ -1745,32 +1820,33 @@ static void fc_seq_ls_rjt(struct fc_frame *rx_fp, enum fc_els_rjt_reason reason,
1745/** 1820/**
1746 * fc_exch_reset() - Reset an exchange 1821 * fc_exch_reset() - Reset an exchange
1747 * @ep: The exchange to be reset 1822 * @ep: The exchange to be reset
1823 *
1824 * Note: May sleep if invoked from outside a response handler.
1748 */ 1825 */
1749static void fc_exch_reset(struct fc_exch *ep) 1826static void fc_exch_reset(struct fc_exch *ep)
1750{ 1827{
1751 struct fc_seq *sp; 1828 struct fc_seq *sp;
1752 void (*resp)(struct fc_seq *, struct fc_frame *, void *);
1753 void *arg;
1754 int rc = 1; 1829 int rc = 1;
1755 1830
1756 spin_lock_bh(&ep->ex_lock); 1831 spin_lock_bh(&ep->ex_lock);
1757 fc_exch_abort_locked(ep, 0); 1832 fc_exch_abort_locked(ep, 0);
1758 ep->state |= FC_EX_RST_CLEANUP; 1833 ep->state |= FC_EX_RST_CLEANUP;
1759 fc_exch_timer_cancel(ep); 1834 fc_exch_timer_cancel(ep);
1760 resp = ep->resp;
1761 ep->resp = NULL;
1762 if (ep->esb_stat & ESB_ST_REC_QUAL) 1835 if (ep->esb_stat & ESB_ST_REC_QUAL)
1763 atomic_dec(&ep->ex_refcnt); /* drop hold for rec_qual */ 1836 atomic_dec(&ep->ex_refcnt); /* drop hold for rec_qual */
1764 ep->esb_stat &= ~ESB_ST_REC_QUAL; 1837 ep->esb_stat &= ~ESB_ST_REC_QUAL;
1765 arg = ep->arg;
1766 sp = &ep->seq; 1838 sp = &ep->seq;
1767 rc = fc_exch_done_locked(ep); 1839 rc = fc_exch_done_locked(ep);
1768 spin_unlock_bh(&ep->ex_lock); 1840 spin_unlock_bh(&ep->ex_lock);
1841
1842 fc_exch_hold(ep);
1843
1769 if (!rc) 1844 if (!rc)
1770 fc_exch_delete(ep); 1845 fc_exch_delete(ep);
1771 1846
1772 if (resp) 1847 fc_invoke_resp(ep, sp, ERR_PTR(-FC_EX_CLOSED));
1773 resp(sp, ERR_PTR(-FC_EX_CLOSED), arg); 1848 fc_seq_set_resp(sp, NULL, ep->arg);
1849 fc_exch_release(ep);
1774} 1850}
1775 1851
1776/** 1852/**
@@ -1956,13 +2032,13 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg)
1956 2032
1957 switch (op) { 2033 switch (op) {
1958 case ELS_LS_RJT: 2034 case ELS_LS_RJT:
1959 FC_EXCH_DBG(aborted_ep, "LS_RJT for RRQ"); 2035 FC_EXCH_DBG(aborted_ep, "LS_RJT for RRQ\n");
1960 /* fall through */ 2036 /* fall through */
1961 case ELS_LS_ACC: 2037 case ELS_LS_ACC:
1962 goto cleanup; 2038 goto cleanup;
1963 default: 2039 default:
1964 FC_EXCH_DBG(aborted_ep, "unexpected response op %x " 2040 FC_EXCH_DBG(aborted_ep, "unexpected response op %x for RRQ\n",
1965 "for RRQ", op); 2041 op);
1966 return; 2042 return;
1967 } 2043 }
1968 2044
@@ -2533,13 +2609,8 @@ int fc_setup_exch_mgr(void)
2533 * cpu on which exchange originated by simple bitwise 2609 * cpu on which exchange originated by simple bitwise
2534 * AND operation between fc_cpu_mask and exchange id. 2610 * AND operation between fc_cpu_mask and exchange id.
2535 */ 2611 */
2536 fc_cpu_mask = 1; 2612 fc_cpu_order = ilog2(roundup_pow_of_two(nr_cpu_ids));
2537 fc_cpu_order = 0; 2613 fc_cpu_mask = (1 << fc_cpu_order) - 1;
2538 while (fc_cpu_mask < nr_cpu_ids) {
2539 fc_cpu_mask <<= 1;
2540 fc_cpu_order++;
2541 }
2542 fc_cpu_mask--;
2543 2614
2544 fc_exch_workqueue = create_singlethread_workqueue("fc_exch_workqueue"); 2615 fc_exch_workqueue = create_singlethread_workqueue("fc_exch_workqueue");
2545 if (!fc_exch_workqueue) 2616 if (!fc_exch_workqueue)
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 5fd0f1fbe586..1d7e76e8b447 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -902,7 +902,8 @@ static void fc_fcp_resp(struct fc_fcp_pkt *fsp, struct fc_frame *fp)
902 /* 902 /*
903 * Check for missing or extra data frames. 903 * Check for missing or extra data frames.
904 */ 904 */
905 if (unlikely(fsp->xfer_len != expected_len)) { 905 if (unlikely(fsp->cdb_status == SAM_STAT_GOOD &&
906 fsp->xfer_len != expected_len)) {
906 if (fsp->xfer_len < expected_len) { 907 if (fsp->xfer_len < expected_len) {
907 /* 908 /*
908 * Some data may be queued locally, 909 * Some data may be queued locally,
@@ -955,12 +956,11 @@ static void fc_fcp_complete_locked(struct fc_fcp_pkt *fsp)
955 * Test for transport underrun, independent of response 956 * Test for transport underrun, independent of response
956 * underrun status. 957 * underrun status.
957 */ 958 */
958 if (fsp->xfer_len < fsp->data_len && !fsp->io_status && 959 if (fsp->cdb_status == SAM_STAT_GOOD &&
960 fsp->xfer_len < fsp->data_len && !fsp->io_status &&
959 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) || 961 (!(fsp->scsi_comp_flags & FCP_RESID_UNDER) ||
960 fsp->xfer_len < fsp->data_len - fsp->scsi_resid)) { 962 fsp->xfer_len < fsp->data_len - fsp->scsi_resid))
961 fsp->status_code = FC_DATA_UNDRUN; 963 fsp->status_code = FC_DATA_UNDRUN;
962 fsp->io_status = 0;
963 }
964 } 964 }
965 965
966 seq = fsp->seq_ptr; 966 seq = fsp->seq_ptr;
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index f04d15c67df3..e01a29863c38 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -516,7 +516,7 @@ static void fc_lport_recv_rnid_req(struct fc_lport *lport,
516 * @lport: The local port receiving the LOGO 516 * @lport: The local port receiving the LOGO
517 * @fp: The LOGO request frame 517 * @fp: The LOGO request frame
518 * 518 *
519 * Locking Note: The lport lock is exected to be held before calling 519 * Locking Note: The lport lock is expected to be held before calling
520 * this function. 520 * this function.
521 */ 521 */
522static void fc_lport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp) 522static void fc_lport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)
@@ -1088,7 +1088,7 @@ static void fc_lport_error(struct fc_lport *lport, struct fc_frame *fp)
1088{ 1088{
1089 unsigned long delay = 0; 1089 unsigned long delay = 0;
1090 FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n", 1090 FC_LPORT_DBG(lport, "Error %ld in state %s, retries %d\n",
1091 PTR_ERR(fp), fc_lport_state(lport), 1091 IS_ERR(fp) ? -PTR_ERR(fp) : 0, fc_lport_state(lport),
1092 lport->retry_count); 1092 lport->retry_count);
1093 1093
1094 if (PTR_ERR(fp) == -FC_EX_CLOSED) 1094 if (PTR_ERR(fp) == -FC_EX_CLOSED)
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index c710d908fda6..589ff9aedd31 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -1705,7 +1705,7 @@ reject:
1705 * @rdata: The remote port that sent the PRLI request 1705 * @rdata: The remote port that sent the PRLI request
1706 * @rx_fp: The PRLI request frame 1706 * @rx_fp: The PRLI request frame
1707 * 1707 *
1708 * Locking Note: The rport lock is exected to be held before calling 1708 * Locking Note: The rport lock is expected to be held before calling
1709 * this function. 1709 * this function.
1710 */ 1710 */
1711static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata, 1711static void fc_rport_recv_prli_req(struct fc_rport_priv *rdata,
@@ -1824,7 +1824,7 @@ drop:
1824 * @rdata: The remote port that sent the PRLO request 1824 * @rdata: The remote port that sent the PRLO request
1825 * @rx_fp: The PRLO request frame 1825 * @rx_fp: The PRLO request frame
1826 * 1826 *
1827 * Locking Note: The rport lock is exected to be held before calling 1827 * Locking Note: The rport lock is expected to be held before calling
1828 * this function. 1828 * this function.
1829 */ 1829 */
1830static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata, 1830static void fc_rport_recv_prlo_req(struct fc_rport_priv *rdata,
@@ -1895,7 +1895,7 @@ drop:
1895 * @lport: The local port that received the LOGO request 1895 * @lport: The local port that received the LOGO request
1896 * @fp: The LOGO request frame 1896 * @fp: The LOGO request frame
1897 * 1897 *
1898 * Locking Note: The rport lock is exected to be held before calling 1898 * Locking Note: The rport lock is expected to be held before calling
1899 * this function. 1899 * this function.
1900 */ 1900 */
1901static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp) 1901static void fc_rport_recv_logo_req(struct fc_lport *lport, struct fc_frame *fp)