summaryrefslogtreecommitdiffstats
path: root/net/ncsi
diff options
context:
space:
mode:
authorGavin Shan <gwshan@linux.vnet.ibm.com>2016-10-03 20:25:47 -0400
committerDavid S. Miller <davem@davemloft.net>2016-10-04 02:11:50 -0400
commitd8cedaabe71236d27da1ff03d32ab1da06ed041f (patch)
treee07609143c4bdacb750823c991578551b021d56c /net/ncsi
parent93409033ae653f1c9a949202fb537ab095b2092f (diff)
net/ncsi: Avoid unused-value build warning from ia64-linux-gcc
xchg() is used to set NCSI channel's state in order for consistent access to the state. xchg()'s return value should be used. Otherwise, one build warning will be raised (with -Wunused-value) as below message indicates. It is reported by ia64-linux-gcc (GCC) 4.9.0. net/ncsi/ncsi-manage.c: In function 'ncsi_channel_monitor': arch/ia64/include/uapi/asm/cmpxchg.h:56:2: warning: value computed is \ not used [-Wunused-value] ((__typeof__(*(ptr))) __xchg((unsigned long) (x), (ptr), sizeof(*(ptr)))) ^ net/ncsi/ncsi-manage.c:202:3: note: in expansion of macro 'xchg' xchg(&nc->state, NCSI_CHANNEL_INACTIVE); This removes the atomic access to NCSI channel's state avoid the above build warning. We have to hold the channel's lock when its state is readed or updated. No functional changes introduced. Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com> Reviewed-by: Joel Stanley <joel@jms.id.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ncsi')
-rw-r--r--net/ncsi/ncsi-aen.c37
-rw-r--r--net/ncsi/ncsi-manage.c71
2 files changed, 81 insertions, 27 deletions
diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index d463468442ae..b41a6617d498 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -53,7 +53,9 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
53 struct ncsi_aen_lsc_pkt *lsc; 53 struct ncsi_aen_lsc_pkt *lsc;
54 struct ncsi_channel *nc; 54 struct ncsi_channel *nc;
55 struct ncsi_channel_mode *ncm; 55 struct ncsi_channel_mode *ncm;
56 unsigned long old_data; 56 bool chained;
57 int state;
58 unsigned long old_data, data;
57 unsigned long flags; 59 unsigned long flags;
58 60
59 /* Find the NCSI channel */ 61 /* Find the NCSI channel */
@@ -62,20 +64,27 @@ static int ncsi_aen_handler_lsc(struct ncsi_dev_priv *ndp,
62 return -ENODEV; 64 return -ENODEV;
63 65
64 /* Update the link status */ 66 /* Update the link status */
65 ncm = &nc->modes[NCSI_MODE_LINK];
66 lsc = (struct ncsi_aen_lsc_pkt *)h; 67 lsc = (struct ncsi_aen_lsc_pkt *)h;
68
69 spin_lock_irqsave(&nc->lock, flags);
70 ncm = &nc->modes[NCSI_MODE_LINK];
67 old_data = ncm->data[2]; 71 old_data = ncm->data[2];
68 ncm->data[2] = ntohl(lsc->status); 72 data = ntohl(lsc->status);
73 ncm->data[2] = data;
69 ncm->data[4] = ntohl(lsc->oem_status); 74 ncm->data[4] = ntohl(lsc->oem_status);
70 if (!((old_data ^ ncm->data[2]) & 0x1) || 75
71 !list_empty(&nc->link)) 76 chained = !list_empty(&nc->link);
77 state = nc->state;
78 spin_unlock_irqrestore(&nc->lock, flags);
79
80 if (!((old_data ^ data) & 0x1) || chained)
72 return 0; 81 return 0;
73 if (!(nc->state == NCSI_CHANNEL_INACTIVE && (ncm->data[2] & 0x1)) && 82 if (!(state == NCSI_CHANNEL_INACTIVE && (data & 0x1)) &&
74 !(nc->state == NCSI_CHANNEL_ACTIVE && !(ncm->data[2] & 0x1))) 83 !(state == NCSI_CHANNEL_ACTIVE && !(data & 0x1)))
75 return 0; 84 return 0;
76 85
77 if (!(ndp->flags & NCSI_DEV_HWA) && 86 if (!(ndp->flags & NCSI_DEV_HWA) &&
78 nc->state == NCSI_CHANNEL_ACTIVE) 87 state == NCSI_CHANNEL_ACTIVE)
79 ndp->flags |= NCSI_DEV_RESHUFFLE; 88 ndp->flags |= NCSI_DEV_RESHUFFLE;
80 89
81 ncsi_stop_channel_monitor(nc); 90 ncsi_stop_channel_monitor(nc);
@@ -97,13 +106,21 @@ static int ncsi_aen_handler_cr(struct ncsi_dev_priv *ndp,
97 if (!nc) 106 if (!nc)
98 return -ENODEV; 107 return -ENODEV;
99 108
109 spin_lock_irqsave(&nc->lock, flags);
100 if (!list_empty(&nc->link) || 110 if (!list_empty(&nc->link) ||
101 nc->state != NCSI_CHANNEL_ACTIVE) 111 nc->state != NCSI_CHANNEL_ACTIVE) {
112 spin_unlock_irqrestore(&nc->lock, flags);
102 return 0; 113 return 0;
114 }
115 spin_unlock_irqrestore(&nc->lock, flags);
103 116
104 ncsi_stop_channel_monitor(nc); 117 ncsi_stop_channel_monitor(nc);
118 spin_lock_irqsave(&nc->lock, flags);
119 nc->state = NCSI_CHANNEL_INVISIBLE;
120 spin_unlock_irqrestore(&nc->lock, flags);
121
105 spin_lock_irqsave(&ndp->lock, flags); 122 spin_lock_irqsave(&ndp->lock, flags);
106 xchg(&nc->state, NCSI_CHANNEL_INACTIVE); 123 nc->state = NCSI_CHANNEL_INACTIVE;
107 list_add_tail_rcu(&nc->link, &ndp->channel_queue); 124 list_add_tail_rcu(&nc->link, &ndp->channel_queue);
108 spin_unlock_irqrestore(&ndp->lock, flags); 125 spin_unlock_irqrestore(&ndp->lock, flags);
109 126
diff --git a/net/ncsi/ncsi-manage.c b/net/ncsi/ncsi-manage.c
index ef017b871857..a26ce5132549 100644
--- a/net/ncsi/ncsi-manage.c
+++ b/net/ncsi/ncsi-manage.c
@@ -132,6 +132,7 @@ static void ncsi_report_link(struct ncsi_dev_priv *ndp, bool force_down)
132 struct ncsi_dev *nd = &ndp->ndev; 132 struct ncsi_dev *nd = &ndp->ndev;
133 struct ncsi_package *np; 133 struct ncsi_package *np;
134 struct ncsi_channel *nc; 134 struct ncsi_channel *nc;
135 unsigned long flags;
135 136
136 nd->state = ncsi_dev_state_functional; 137 nd->state = ncsi_dev_state_functional;
137 if (force_down) { 138 if (force_down) {
@@ -142,14 +143,21 @@ static void ncsi_report_link(struct ncsi_dev_priv *ndp, bool force_down)
142 nd->link_up = 0; 143 nd->link_up = 0;
143 NCSI_FOR_EACH_PACKAGE(ndp, np) { 144 NCSI_FOR_EACH_PACKAGE(ndp, np) {
144 NCSI_FOR_EACH_CHANNEL(np, nc) { 145 NCSI_FOR_EACH_CHANNEL(np, nc) {
146 spin_lock_irqsave(&nc->lock, flags);
147
145 if (!list_empty(&nc->link) || 148 if (!list_empty(&nc->link) ||
146 nc->state != NCSI_CHANNEL_ACTIVE) 149 nc->state != NCSI_CHANNEL_ACTIVE) {
150 spin_unlock_irqrestore(&nc->lock, flags);
147 continue; 151 continue;
152 }
148 153
149 if (nc->modes[NCSI_MODE_LINK].data[2] & 0x1) { 154 if (nc->modes[NCSI_MODE_LINK].data[2] & 0x1) {
155 spin_unlock_irqrestore(&nc->lock, flags);
150 nd->link_up = 1; 156 nd->link_up = 1;
151 goto report; 157 goto report;
152 } 158 }
159
160 spin_unlock_irqrestore(&nc->lock, flags);
153 } 161 }
154 } 162 }
155 163
@@ -163,20 +171,22 @@ static void ncsi_channel_monitor(unsigned long data)
163 struct ncsi_package *np = nc->package; 171 struct ncsi_package *np = nc->package;
164 struct ncsi_dev_priv *ndp = np->ndp; 172 struct ncsi_dev_priv *ndp = np->ndp;
165 struct ncsi_cmd_arg nca; 173 struct ncsi_cmd_arg nca;
166 bool enabled; 174 bool enabled, chained;
167 unsigned int timeout; 175 unsigned int timeout;
168 unsigned long flags; 176 unsigned long flags;
169 int ret; 177 int state, ret;
170 178
171 spin_lock_irqsave(&nc->lock, flags); 179 spin_lock_irqsave(&nc->lock, flags);
180 state = nc->state;
181 chained = !list_empty(&nc->link);
172 timeout = nc->timeout; 182 timeout = nc->timeout;
173 enabled = nc->enabled; 183 enabled = nc->enabled;
174 spin_unlock_irqrestore(&nc->lock, flags); 184 spin_unlock_irqrestore(&nc->lock, flags);
175 185
176 if (!enabled || !list_empty(&nc->link)) 186 if (!enabled || chained)
177 return; 187 return;
178 if (nc->state != NCSI_CHANNEL_INACTIVE && 188 if (state != NCSI_CHANNEL_INACTIVE &&
179 nc->state != NCSI_CHANNEL_ACTIVE) 189 state != NCSI_CHANNEL_ACTIVE)
180 return; 190 return;
181 191
182 if (!(timeout % 2)) { 192 if (!(timeout % 2)) {
@@ -195,11 +205,15 @@ static void ncsi_channel_monitor(unsigned long data)
195 205
196 if (timeout + 1 >= 3) { 206 if (timeout + 1 >= 3) {
197 if (!(ndp->flags & NCSI_DEV_HWA) && 207 if (!(ndp->flags & NCSI_DEV_HWA) &&
198 nc->state == NCSI_CHANNEL_ACTIVE) 208 state == NCSI_CHANNEL_ACTIVE)
199 ncsi_report_link(ndp, true); 209 ncsi_report_link(ndp, true);
200 210
211 spin_lock_irqsave(&nc->lock, flags);
212 nc->state = NCSI_CHANNEL_INVISIBLE;
213 spin_unlock_irqrestore(&nc->lock, flags);
214
201 spin_lock_irqsave(&ndp->lock, flags); 215 spin_lock_irqsave(&ndp->lock, flags);
202 xchg(&nc->state, NCSI_CHANNEL_INACTIVE); 216 nc->state = NCSI_CHANNEL_INACTIVE;
203 list_add_tail_rcu(&nc->link, &ndp->channel_queue); 217 list_add_tail_rcu(&nc->link, &ndp->channel_queue);
204 spin_unlock_irqrestore(&ndp->lock, flags); 218 spin_unlock_irqrestore(&ndp->lock, flags);
205 ncsi_process_next_channel(ndp); 219 ncsi_process_next_channel(ndp);
@@ -508,6 +522,7 @@ static void ncsi_suspend_channel(struct ncsi_dev_priv *ndp)
508 struct ncsi_package *np = ndp->active_package; 522 struct ncsi_package *np = ndp->active_package;
509 struct ncsi_channel *nc = ndp->active_channel; 523 struct ncsi_channel *nc = ndp->active_channel;
510 struct ncsi_cmd_arg nca; 524 struct ncsi_cmd_arg nca;
525 unsigned long flags;
511 int ret; 526 int ret;
512 527
513 nca.ndp = ndp; 528 nca.ndp = ndp;
@@ -556,7 +571,9 @@ static void ncsi_suspend_channel(struct ncsi_dev_priv *ndp)
556 571
557 break; 572 break;
558 case ncsi_dev_state_suspend_done: 573 case ncsi_dev_state_suspend_done:
559 xchg(&nc->state, NCSI_CHANNEL_INACTIVE); 574 spin_lock_irqsave(&nc->lock, flags);
575 nc->state = NCSI_CHANNEL_INACTIVE;
576 spin_unlock_irqrestore(&nc->lock, flags);
560 ncsi_process_next_channel(ndp); 577 ncsi_process_next_channel(ndp);
561 578
562 break; 579 break;
@@ -574,6 +591,7 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
574 struct ncsi_channel *nc = ndp->active_channel; 591 struct ncsi_channel *nc = ndp->active_channel;
575 struct ncsi_cmd_arg nca; 592 struct ncsi_cmd_arg nca;
576 unsigned char index; 593 unsigned char index;
594 unsigned long flags;
577 int ret; 595 int ret;
578 596
579 nca.ndp = ndp; 597 nca.ndp = ndp;
@@ -675,10 +693,12 @@ static void ncsi_configure_channel(struct ncsi_dev_priv *ndp)
675 goto error; 693 goto error;
676 break; 694 break;
677 case ncsi_dev_state_config_done: 695 case ncsi_dev_state_config_done:
696 spin_lock_irqsave(&nc->lock, flags);
678 if (nc->modes[NCSI_MODE_LINK].data[2] & 0x1) 697 if (nc->modes[NCSI_MODE_LINK].data[2] & 0x1)
679 xchg(&nc->state, NCSI_CHANNEL_ACTIVE); 698 nc->state = NCSI_CHANNEL_ACTIVE;
680 else 699 else
681 xchg(&nc->state, NCSI_CHANNEL_INACTIVE); 700 nc->state = NCSI_CHANNEL_INACTIVE;
701 spin_unlock_irqrestore(&nc->lock, flags);
682 702
683 ncsi_start_channel_monitor(nc); 703 ncsi_start_channel_monitor(nc);
684 ncsi_process_next_channel(ndp); 704 ncsi_process_next_channel(ndp);
@@ -707,18 +727,25 @@ static int ncsi_choose_active_channel(struct ncsi_dev_priv *ndp)
707 found = NULL; 727 found = NULL;
708 NCSI_FOR_EACH_PACKAGE(ndp, np) { 728 NCSI_FOR_EACH_PACKAGE(ndp, np) {
709 NCSI_FOR_EACH_CHANNEL(np, nc) { 729 NCSI_FOR_EACH_CHANNEL(np, nc) {
730 spin_lock_irqsave(&nc->lock, flags);
731
710 if (!list_empty(&nc->link) || 732 if (!list_empty(&nc->link) ||
711 nc->state != NCSI_CHANNEL_INACTIVE) 733 nc->state != NCSI_CHANNEL_INACTIVE) {
734 spin_unlock_irqrestore(&nc->lock, flags);
712 continue; 735 continue;
736 }
713 737
714 if (!found) 738 if (!found)
715 found = nc; 739 found = nc;
716 740
717 ncm = &nc->modes[NCSI_MODE_LINK]; 741 ncm = &nc->modes[NCSI_MODE_LINK];
718 if (ncm->data[2] & 0x1) { 742 if (ncm->data[2] & 0x1) {
743 spin_unlock_irqrestore(&nc->lock, flags);
719 found = nc; 744 found = nc;
720 goto out; 745 goto out;
721 } 746 }
747
748 spin_unlock_irqrestore(&nc->lock, flags);
722 } 749 }
723 } 750 }
724 751
@@ -987,11 +1014,14 @@ int ncsi_process_next_channel(struct ncsi_dev_priv *ndp)
987 goto out; 1014 goto out;
988 } 1015 }
989 1016
990 old_state = xchg(&nc->state, NCSI_CHANNEL_INVISIBLE);
991 list_del_init(&nc->link); 1017 list_del_init(&nc->link);
992
993 spin_unlock_irqrestore(&ndp->lock, flags); 1018 spin_unlock_irqrestore(&ndp->lock, flags);
994 1019
1020 spin_lock_irqsave(&nc->lock, flags);
1021 old_state = nc->state;
1022 nc->state = NCSI_CHANNEL_INVISIBLE;
1023 spin_unlock_irqrestore(&nc->lock, flags);
1024
995 ndp->active_channel = nc; 1025 ndp->active_channel = nc;
996 ndp->active_package = nc->package; 1026 ndp->active_package = nc->package;
997 1027
@@ -1006,7 +1036,7 @@ int ncsi_process_next_channel(struct ncsi_dev_priv *ndp)
1006 break; 1036 break;
1007 default: 1037 default:
1008 netdev_err(ndp->ndev.dev, "Invalid state 0x%x on %d:%d\n", 1038 netdev_err(ndp->ndev.dev, "Invalid state 0x%x on %d:%d\n",
1009 nc->state, nc->package->id, nc->id); 1039 old_state, nc->package->id, nc->id);
1010 ncsi_report_link(ndp, false); 1040 ncsi_report_link(ndp, false);
1011 return -EINVAL; 1041 return -EINVAL;
1012 } 1042 }
@@ -1151,6 +1181,8 @@ int ncsi_start_dev(struct ncsi_dev *nd)
1151 struct ncsi_dev_priv *ndp = TO_NCSI_DEV_PRIV(nd); 1181 struct ncsi_dev_priv *ndp = TO_NCSI_DEV_PRIV(nd);
1152 struct ncsi_package *np; 1182 struct ncsi_package *np;
1153 struct ncsi_channel *nc; 1183 struct ncsi_channel *nc;
1184 unsigned long flags;
1185 bool chained;
1154 int old_state, ret; 1186 int old_state, ret;
1155 1187
1156 if (nd->state != ncsi_dev_state_registered && 1188 if (nd->state != ncsi_dev_state_registered &&
@@ -1166,8 +1198,13 @@ int ncsi_start_dev(struct ncsi_dev *nd)
1166 /* Reset channel's state and start over */ 1198 /* Reset channel's state and start over */
1167 NCSI_FOR_EACH_PACKAGE(ndp, np) { 1199 NCSI_FOR_EACH_PACKAGE(ndp, np) {
1168 NCSI_FOR_EACH_CHANNEL(np, nc) { 1200 NCSI_FOR_EACH_CHANNEL(np, nc) {
1169 old_state = xchg(&nc->state, NCSI_CHANNEL_INACTIVE); 1201 spin_lock_irqsave(&nc->lock, flags);
1170 WARN_ON_ONCE(!list_empty(&nc->link) || 1202 chained = !list_empty(&nc->link);
1203 old_state = nc->state;
1204 nc->state = NCSI_CHANNEL_INACTIVE;
1205 spin_unlock_irqrestore(&nc->lock, flags);
1206
1207 WARN_ON_ONCE(chained ||
1171 old_state == NCSI_CHANNEL_INVISIBLE); 1208 old_state == NCSI_CHANNEL_INVISIBLE);
1172 } 1209 }
1173 } 1210 }