2 * linux/drivers/message/fusion/mptlan.c
3 * IP Over Fibre Channel device driver.
4 * For use with LSI Fibre Channel PCI chip/adapters
5 * running LSI Fusion MPT (Message Passing Technology) firmware.
7 * Copyright (c) 2000-2008 LSI Corporation
8 * (mailto:DL-MPTFusionLinux@lsi.com)
11 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; version 2 of the License.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
23 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
24 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
25 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
26 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
27 solely responsible for determining the appropriateness of using and
28 distributing the Program and assumes all risks associated with its
29 exercise of rights under this Agreement, including but not limited to
30 the risks and costs of program errors, damage to or loss of data,
31 programs or equipment, and unavailability or interruption of operations.
33 DISCLAIMER OF LIABILITY
34 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
35 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
37 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
38 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
39 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
40 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
42 You should have received a copy of the GNU General Public License
43 along with this program; if not, write to the Free Software
44 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
49 * Define statements used for debugging
51 //#define MPT_LAN_IO_DEBUG
53 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
56 #include <linux/init.h>
57 #include <linux/module.h>
59 #include <linux/sched.h>
61 #define my_VERSION MPT_LINUX_VERSION_COMMON
62 #define MYNAM "mptlan"
64 MODULE_LICENSE("GPL");
65 MODULE_VERSION(my_VERSION
);
67 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
69 * MPT LAN message sizes without variable part.
71 #define MPT_LAN_RECEIVE_POST_REQUEST_SIZE \
72 (sizeof(LANReceivePostRequest_t) - sizeof(SGE_MPI_UNION))
74 #define MPT_LAN_TRANSACTION32_SIZE \
75 (sizeof(SGETransaction32_t) - sizeof(u32))
78 * Fusion MPT LAN private structures
81 struct BufferControl
{
89 u8 pnum
; /* Port number in the IOC. This is not a Unix network port! */
91 atomic_t buckets_out
; /* number of unused buckets on IOC */
92 int bucketthresh
; /* Send more when this many left */
94 int *mpt_txfidx
; /* Free Tx Context list */
96 spinlock_t txfidx_lock
;
98 int *mpt_rxfidx
; /* Free Rx Context list */
100 spinlock_t rxfidx_lock
;
102 struct BufferControl
*RcvCtl
; /* Receive BufferControl structs */
103 struct BufferControl
*SendCtl
; /* Send BufferControl structs */
105 int max_buckets_out
; /* Max buckets to send to IOC */
106 int tx_max_out
; /* IOC's Tx queue len */
111 struct delayed_work post_buckets_task
;
112 struct net_device
*dev
;
113 unsigned long post_buckets_active
;
116 struct mpt_lan_ohdr
{
123 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
128 static int lan_reply (MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
,
129 MPT_FRAME_HDR
*reply
);
130 static int mpt_lan_open(struct net_device
*dev
);
131 static int mpt_lan_reset(struct net_device
*dev
);
132 static int mpt_lan_close(struct net_device
*dev
);
133 static void mpt_lan_post_receive_buckets(struct mpt_lan_priv
*priv
);
134 static void mpt_lan_wake_post_buckets_task(struct net_device
*dev
,
136 static int mpt_lan_receive_post_turbo(struct net_device
*dev
, u32 tmsg
);
137 static int mpt_lan_receive_post_reply(struct net_device
*dev
,
138 LANReceivePostReply_t
*pRecvRep
);
139 static int mpt_lan_send_turbo(struct net_device
*dev
, u32 tmsg
);
140 static int mpt_lan_send_reply(struct net_device
*dev
,
141 LANSendReply_t
*pSendRep
);
142 static int mpt_lan_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
);
143 static int mpt_lan_event_process(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEvReply
);
144 static unsigned short mpt_lan_type_trans(struct sk_buff
*skb
,
145 struct net_device
*dev
);
147 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
149 * Fusion MPT LAN private data
151 static u8 LanCtx
= MPT_MAX_PROTOCOL_DRIVERS
;
153 static u32 max_buckets_out
= 127;
154 static u32 tx_max_out_p
= 127 - 16;
156 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
158 * lan_reply - Handle all data sent from the hardware.
159 * @ioc: Pointer to MPT_ADAPTER structure
160 * @mf: Pointer to original MPT request frame (NULL if TurboReply)
161 * @reply: Pointer to MPT reply frame
163 * Returns 1 indicating original alloc'd request frame ptr
164 * should be freed, or 0 if it shouldn't.
167 lan_reply (MPT_ADAPTER
*ioc
, MPT_FRAME_HDR
*mf
, MPT_FRAME_HDR
*reply
)
169 struct net_device
*dev
= ioc
->netdev
;
170 int FreeReqFrame
= 0;
172 dioprintk((KERN_INFO MYNAM
": %s/%s: Got reply.\n",
173 IOC_AND_NETDEV_NAMES_s_s(dev
)));
175 // dioprintk((KERN_INFO MYNAM "@lan_reply: mf = %p, reply = %p\n",
179 u32 tmsg
= CAST_PTR_TO_U32(reply
);
181 dioprintk((KERN_INFO MYNAM
": %s/%s: @lan_reply, tmsg %08x\n",
182 IOC_AND_NETDEV_NAMES_s_s(dev
),
185 switch (GET_LAN_FORM(tmsg
)) {
187 // NOTE! (Optimization) First case here is now caught in
188 // mptbase.c::mpt_interrupt() routine and callcack here
189 // is now skipped for this case!
191 case LAN_REPLY_FORM_MESSAGE_CONTEXT
:
192 // dioprintk((KERN_INFO MYNAM "/lan_reply: "
193 // "MessageContext turbo reply received\n"));
198 case LAN_REPLY_FORM_SEND_SINGLE
:
199 // dioprintk((MYNAM "/lan_reply: "
200 // "calling mpt_lan_send_reply (turbo)\n"));
202 // Potential BUG here?
203 // FreeReqFrame = mpt_lan_send_turbo(dev, tmsg);
204 // If/when mpt_lan_send_turbo would return 1 here,
205 // calling routine (mptbase.c|mpt_interrupt)
206 // would Oops because mf has already been set
207 // to NULL. So after return from this func,
208 // mpt_interrupt() will attempt to put (NULL) mf ptr
209 // item back onto its adapter FreeQ - Oops!:-(
210 // It's Ok, since mpt_lan_send_turbo() *currently*
211 // always returns 0, but..., just in case:
213 (void) mpt_lan_send_turbo(dev
, tmsg
);
218 case LAN_REPLY_FORM_RECEIVE_SINGLE
:
219 // dioprintk((KERN_INFO MYNAM "@lan_reply: "
220 // "rcv-Turbo = %08x\n", tmsg));
221 mpt_lan_receive_post_turbo(dev
, tmsg
);
225 printk (KERN_ERR MYNAM
"/lan_reply: Got a turbo reply "
226 "that I don't know what to do with\n");
228 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
236 // msg = (u32 *) reply;
237 // dioprintk((KERN_INFO MYNAM "@lan_reply: msg = %08x %08x %08x %08x\n",
238 // le32_to_cpu(msg[0]), le32_to_cpu(msg[1]),
239 // le32_to_cpu(msg[2]), le32_to_cpu(msg[3])));
240 // dioprintk((KERN_INFO MYNAM "@lan_reply: Function = %02xh\n",
241 // reply->u.hdr.Function));
243 switch (reply
->u
.hdr
.Function
) {
245 case MPI_FUNCTION_LAN_SEND
:
247 LANSendReply_t
*pSendRep
;
249 pSendRep
= (LANSendReply_t
*) reply
;
250 FreeReqFrame
= mpt_lan_send_reply(dev
, pSendRep
);
254 case MPI_FUNCTION_LAN_RECEIVE
:
256 LANReceivePostReply_t
*pRecvRep
;
258 pRecvRep
= (LANReceivePostReply_t
*) reply
;
259 if (pRecvRep
->NumberOfContexts
) {
260 mpt_lan_receive_post_reply(dev
, pRecvRep
);
261 if (!(pRecvRep
->MsgFlags
& MPI_MSGFLAGS_CONTINUATION_REPLY
))
264 dioprintk((KERN_INFO MYNAM
"@lan_reply: zero context "
265 "ReceivePostReply received.\n"));
269 case MPI_FUNCTION_LAN_RESET
:
270 /* Just a default reply. Might want to check it to
271 * make sure that everything went ok.
276 case MPI_FUNCTION_EVENT_NOTIFICATION
:
277 case MPI_FUNCTION_EVENT_ACK
:
278 /* _EVENT_NOTIFICATION should NOT come down this path any more.
279 * Should be routed to mpt_lan_event_process(), but just in case...
285 printk (KERN_ERR MYNAM
"/lan_reply: Got a non-turbo "
286 "reply that I don't know what to do with\n");
288 /* CHECKME! Hmmm... FreeReqFrame is 0 here; is that right? */
297 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
299 mpt_lan_ioc_reset(MPT_ADAPTER
*ioc
, int reset_phase
)
301 struct net_device
*dev
= ioc
->netdev
;
302 struct mpt_lan_priv
*priv
;
307 priv
= netdev_priv(dev
);
309 dlprintk((KERN_INFO MYNAM
": IOC %s_reset routed to LAN driver!\n",
310 reset_phase
==MPT_IOC_SETUP_RESET
? "setup" : (
311 reset_phase
==MPT_IOC_PRE_RESET
? "pre" : "post")));
313 if (priv
->mpt_rxfidx
== NULL
)
316 if (reset_phase
== MPT_IOC_SETUP_RESET
) {
318 } else if (reset_phase
== MPT_IOC_PRE_RESET
) {
322 netif_stop_queue(dev
);
324 dlprintk ((KERN_INFO
"mptlan/ioc_reset: called netif_stop_queue for %s.\n", dev
->name
));
326 atomic_set(&priv
->buckets_out
, 0);
328 /* Reset Rx Free Tail index and re-populate the queue. */
329 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
330 priv
->mpt_rxfidx_tail
= -1;
331 for (i
= 0; i
< priv
->max_buckets_out
; i
++)
332 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = i
;
333 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
335 mpt_lan_post_receive_buckets(priv
);
336 netif_wake_queue(dev
);
342 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
344 mpt_lan_event_process(MPT_ADAPTER
*ioc
, EventNotificationReply_t
*pEvReply
)
346 dlprintk((KERN_INFO MYNAM
": MPT event routed to LAN driver!\n"));
348 switch (le32_to_cpu(pEvReply
->Event
)) {
349 case MPI_EVENT_NONE
: /* 00 */
350 case MPI_EVENT_LOG_DATA
: /* 01 */
351 case MPI_EVENT_STATE_CHANGE
: /* 02 */
352 case MPI_EVENT_UNIT_ATTENTION
: /* 03 */
353 case MPI_EVENT_IOC_BUS_RESET
: /* 04 */
354 case MPI_EVENT_EXT_BUS_RESET
: /* 05 */
355 case MPI_EVENT_RESCAN
: /* 06 */
356 /* Ok, do we need to do anything here? As far as
357 I can tell, this is when a new device gets added
359 case MPI_EVENT_LINK_STATUS_CHANGE
: /* 07 */
360 case MPI_EVENT_LOOP_STATE_CHANGE
: /* 08 */
361 case MPI_EVENT_LOGOUT
: /* 09 */
362 case MPI_EVENT_EVENT_CHANGE
: /* 0A */
368 * NOTE: pEvent->AckRequired handling now done in mptbase.c;
369 * Do NOT do it here now!
375 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
377 mpt_lan_open(struct net_device
*dev
)
379 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
382 if (mpt_lan_reset(dev
) != 0) {
383 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
385 printk (KERN_WARNING MYNAM
"/lan_open: lan_reset failed.");
388 printk ("The ioc is active. Perhaps it needs to be"
391 printk ("The ioc in inactive, most likely in the "
392 "process of being reset. Please try again in "
396 priv
->mpt_txfidx
= kmalloc(priv
->tx_max_out
* sizeof(int), GFP_KERNEL
);
397 if (priv
->mpt_txfidx
== NULL
)
399 priv
->mpt_txfidx_tail
= -1;
401 priv
->SendCtl
= kcalloc(priv
->tx_max_out
, sizeof(struct BufferControl
),
403 if (priv
->SendCtl
== NULL
)
405 for (i
= 0; i
< priv
->tx_max_out
; i
++)
406 priv
->mpt_txfidx
[++priv
->mpt_txfidx_tail
] = i
;
408 dlprintk((KERN_INFO MYNAM
"@lo: Finished initializing SendCtl\n"));
410 priv
->mpt_rxfidx
= kmalloc(priv
->max_buckets_out
* sizeof(int),
412 if (priv
->mpt_rxfidx
== NULL
)
414 priv
->mpt_rxfidx_tail
= -1;
416 priv
->RcvCtl
= kcalloc(priv
->max_buckets_out
,
417 sizeof(struct BufferControl
),
419 if (priv
->RcvCtl
== NULL
)
421 for (i
= 0; i
< priv
->max_buckets_out
; i
++)
422 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = i
;
424 /**/ dlprintk((KERN_INFO MYNAM
"/lo: txfidx contains - "));
425 /**/ for (i
= 0; i
< priv
->tx_max_out
; i
++)
426 /**/ dlprintk((" %xh", priv
->mpt_txfidx
[i
]));
427 /**/ dlprintk(("\n"));
429 dlprintk((KERN_INFO MYNAM
"/lo: Finished initializing RcvCtl\n"));
431 mpt_lan_post_receive_buckets(priv
);
432 printk(KERN_INFO MYNAM
": %s/%s: interface up & active\n",
433 IOC_AND_NETDEV_NAMES_s_s(dev
));
435 if (mpt_event_register(LanCtx
, mpt_lan_event_process
) != 0) {
436 printk (KERN_WARNING MYNAM
"/lo: Unable to register for Event"
437 " Notifications. This is a bad thing! We're not going "
438 "to go ahead, but I'd be leery of system stability at "
442 netif_start_queue(dev
);
443 dlprintk((KERN_INFO MYNAM
"/lo: Done.\n"));
447 kfree(priv
->mpt_rxfidx
);
448 priv
->mpt_rxfidx
= NULL
;
450 kfree(priv
->SendCtl
);
451 priv
->SendCtl
= NULL
;
453 kfree(priv
->mpt_txfidx
);
454 priv
->mpt_txfidx
= NULL
;
458 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
459 /* Send a LanReset message to the FW. This should result in the FW returning
460 any buckets it still has. */
462 mpt_lan_reset(struct net_device
*dev
)
465 LANResetRequest_t
*pResetReq
;
466 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
468 mf
= mpt_get_msg_frame(LanCtx
, priv
->mpt_dev
);
471 /* dlprintk((KERN_ERR MYNAM "/reset: Evil funkiness abounds! "
472 "Unable to allocate a request frame.\n"));
477 pResetReq
= (LANResetRequest_t
*) mf
;
479 pResetReq
->Function
= MPI_FUNCTION_LAN_RESET
;
480 pResetReq
->ChainOffset
= 0;
481 pResetReq
->Reserved
= 0;
482 pResetReq
->PortNumber
= priv
->pnum
;
483 pResetReq
->MsgFlags
= 0;
484 pResetReq
->Reserved2
= 0;
486 mpt_put_msg_frame(LanCtx
, priv
->mpt_dev
, mf
);
491 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
493 mpt_lan_close(struct net_device
*dev
)
495 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
496 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
497 unsigned long timeout
;
500 dlprintk((KERN_INFO MYNAM
": mpt_lan_close called\n"));
502 mpt_event_deregister(LanCtx
);
504 dlprintk((KERN_INFO MYNAM
":lan_close: Posted %d buckets "
505 "since driver was loaded, %d still out\n",
506 priv
->total_posted
,atomic_read(&priv
->buckets_out
)));
508 netif_stop_queue(dev
);
512 timeout
= jiffies
+ 2 * HZ
;
513 while (atomic_read(&priv
->buckets_out
) && time_before(jiffies
, timeout
))
514 schedule_timeout_interruptible(1);
516 for (i
= 0; i
< priv
->max_buckets_out
; i
++) {
517 if (priv
->RcvCtl
[i
].skb
!= NULL
) {
518 /**/ dlprintk((KERN_INFO MYNAM
"/lan_close: bucket %05x "
519 /**/ "is still out\n", i
));
520 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[i
].dma
,
523 dev_kfree_skb(priv
->RcvCtl
[i
].skb
);
528 kfree(priv
->mpt_rxfidx
);
530 for (i
= 0; i
< priv
->tx_max_out
; i
++) {
531 if (priv
->SendCtl
[i
].skb
!= NULL
) {
532 pci_unmap_single(mpt_dev
->pcidev
, priv
->SendCtl
[i
].dma
,
533 priv
->SendCtl
[i
].len
,
535 dev_kfree_skb(priv
->SendCtl
[i
].skb
);
539 kfree(priv
->SendCtl
);
540 kfree(priv
->mpt_txfidx
);
542 atomic_set(&priv
->buckets_out
, 0);
544 printk(KERN_INFO MYNAM
": %s/%s: interface down & inactive\n",
545 IOC_AND_NETDEV_NAMES_s_s(dev
));
550 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
552 mpt_lan_change_mtu(struct net_device
*dev
, int new_mtu
)
554 if ((new_mtu
< MPT_LAN_MIN_MTU
) || (new_mtu
> MPT_LAN_MAX_MTU
))
560 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
561 /* Tx timeout handler. */
563 mpt_lan_tx_timeout(struct net_device
*dev
)
565 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
566 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
568 if (mpt_dev
->active
) {
569 dlprintk (("mptlan/tx_timeout: calling netif_wake_queue for %s.\n", dev
->name
));
570 netif_wake_queue(dev
);
574 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
577 mpt_lan_send_turbo(struct net_device
*dev
, u32 tmsg
)
579 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
580 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
581 struct sk_buff
*sent
;
585 ctx
= GET_LAN_BUFFER_CONTEXT(tmsg
);
586 sent
= priv
->SendCtl
[ctx
].skb
;
588 dev
->stats
.tx_packets
++;
589 dev
->stats
.tx_bytes
+= sent
->len
;
591 dioprintk((KERN_INFO MYNAM
": %s/%s: @%s, skb %p sent.\n",
592 IOC_AND_NETDEV_NAMES_s_s(dev
),
595 priv
->SendCtl
[ctx
].skb
= NULL
;
596 pci_unmap_single(mpt_dev
->pcidev
, priv
->SendCtl
[ctx
].dma
,
597 priv
->SendCtl
[ctx
].len
, PCI_DMA_TODEVICE
);
598 dev_kfree_skb_irq(sent
);
600 spin_lock_irqsave(&priv
->txfidx_lock
, flags
);
601 priv
->mpt_txfidx
[++priv
->mpt_txfidx_tail
] = ctx
;
602 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
604 netif_wake_queue(dev
);
608 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
610 mpt_lan_send_reply(struct net_device
*dev
, LANSendReply_t
*pSendRep
)
612 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
613 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
614 struct sk_buff
*sent
;
616 int FreeReqFrame
= 0;
621 count
= pSendRep
->NumberOfContexts
;
623 dioprintk((KERN_INFO MYNAM
": send_reply: IOCStatus: %04x\n",
624 le16_to_cpu(pSendRep
->IOCStatus
)));
626 /* Add check for Loginfo Flag in IOCStatus */
628 switch (le16_to_cpu(pSendRep
->IOCStatus
) & MPI_IOCSTATUS_MASK
) {
629 case MPI_IOCSTATUS_SUCCESS
:
630 dev
->stats
.tx_packets
+= count
;
633 case MPI_IOCSTATUS_LAN_CANCELED
:
634 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED
:
637 case MPI_IOCSTATUS_INVALID_SGL
:
638 dev
->stats
.tx_errors
+= count
;
639 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Invalid SGL sent to IOC!\n",
640 IOC_AND_NETDEV_NAMES_s_s(dev
));
644 dev
->stats
.tx_errors
+= count
;
648 pContext
= &pSendRep
->BufferContext
;
650 spin_lock_irqsave(&priv
->txfidx_lock
, flags
);
652 ctx
= GET_LAN_BUFFER_CONTEXT(le32_to_cpu(*pContext
));
654 sent
= priv
->SendCtl
[ctx
].skb
;
655 dev
->stats
.tx_bytes
+= sent
->len
;
657 dioprintk((KERN_INFO MYNAM
": %s/%s: @%s, skb %p sent.\n",
658 IOC_AND_NETDEV_NAMES_s_s(dev
),
661 priv
->SendCtl
[ctx
].skb
= NULL
;
662 pci_unmap_single(mpt_dev
->pcidev
, priv
->SendCtl
[ctx
].dma
,
663 priv
->SendCtl
[ctx
].len
, PCI_DMA_TODEVICE
);
664 dev_kfree_skb_irq(sent
);
666 priv
->mpt_txfidx
[++priv
->mpt_txfidx_tail
] = ctx
;
671 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
674 if (!(pSendRep
->MsgFlags
& MPI_MSGFLAGS_CONTINUATION_REPLY
))
677 netif_wake_queue(dev
);
681 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
683 mpt_lan_sdu_send (struct sk_buff
*skb
, struct net_device
*dev
)
685 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
686 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
688 LANSendRequest_t
*pSendReq
;
689 SGETransaction32_t
*pTrans
;
690 SGESimple64_t
*pSimple
;
691 const unsigned char *mac
;
695 u16 cur_naa
= 0x1000;
697 dioprintk((KERN_INFO MYNAM
": %s called, skb_addr = %p\n",
700 spin_lock_irqsave(&priv
->txfidx_lock
, flags
);
701 if (priv
->mpt_txfidx_tail
< 0) {
702 netif_stop_queue(dev
);
703 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
705 printk (KERN_ERR
"%s: no tx context available: %u\n",
706 __func__
, priv
->mpt_txfidx_tail
);
707 return NETDEV_TX_BUSY
;
710 mf
= mpt_get_msg_frame(LanCtx
, mpt_dev
);
712 netif_stop_queue(dev
);
713 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
715 printk (KERN_ERR
"%s: Unable to alloc request frame\n",
717 return NETDEV_TX_BUSY
;
720 ctx
= priv
->mpt_txfidx
[priv
->mpt_txfidx_tail
--];
721 spin_unlock_irqrestore(&priv
->txfidx_lock
, flags
);
723 // dioprintk((KERN_INFO MYNAM ": %s/%s: Creating new msg frame (send).\n",
724 // IOC_AND_NETDEV_NAMES_s_s(dev)));
726 pSendReq
= (LANSendRequest_t
*) mf
;
728 /* Set the mac.raw pointer, since this apparently isn't getting
729 * done before we get the skb. Pull the data pointer past the mac data.
731 skb_reset_mac_header(skb
);
734 dma
= pci_map_single(mpt_dev
->pcidev
, skb
->data
, skb
->len
,
737 priv
->SendCtl
[ctx
].skb
= skb
;
738 priv
->SendCtl
[ctx
].dma
= dma
;
739 priv
->SendCtl
[ctx
].len
= skb
->len
;
742 pSendReq
->Reserved
= 0;
743 pSendReq
->Function
= MPI_FUNCTION_LAN_SEND
;
744 pSendReq
->ChainOffset
= 0;
745 pSendReq
->Reserved2
= 0;
746 pSendReq
->MsgFlags
= 0;
747 pSendReq
->PortNumber
= priv
->pnum
;
749 /* Transaction Context Element */
750 pTrans
= (SGETransaction32_t
*) pSendReq
->SG_List
;
752 /* No Flags, 8 bytes of Details, 32bit Context (bloody turbo replies) */
753 pTrans
->ContextSize
= sizeof(u32
);
754 pTrans
->DetailsLength
= 2 * sizeof(u32
);
756 pTrans
->TransactionContext
[0] = cpu_to_le32(ctx
);
758 // dioprintk((KERN_INFO MYNAM ": %s/%s: BC = %08x, skb = %p, buff = %p\n",
759 // IOC_AND_NETDEV_NAMES_s_s(dev),
760 // ctx, skb, skb->data));
762 mac
= skb_mac_header(skb
);
764 pTrans
->TransactionDetails
[0] = cpu_to_le32((cur_naa
<< 16) |
767 pTrans
->TransactionDetails
[1] = cpu_to_le32((mac
[2] << 24) |
772 pSimple
= (SGESimple64_t
*) &pTrans
->TransactionDetails
[2];
774 /* If we ever decide to send more than one Simple SGE per LANSend, then
775 we will need to make sure that LAST_ELEMENT only gets set on the
776 last one. Otherwise, bad voodoo and evil funkiness will commence. */
777 pSimple
->FlagsLength
= cpu_to_le32(
778 ((MPI_SGE_FLAGS_LAST_ELEMENT
|
779 MPI_SGE_FLAGS_END_OF_BUFFER
|
780 MPI_SGE_FLAGS_SIMPLE_ELEMENT
|
781 MPI_SGE_FLAGS_SYSTEM_ADDRESS
|
782 MPI_SGE_FLAGS_HOST_TO_IOC
|
783 MPI_SGE_FLAGS_64_BIT_ADDRESSING
|
784 MPI_SGE_FLAGS_END_OF_LIST
) << MPI_SGE_FLAGS_SHIFT
) |
786 pSimple
->Address
.Low
= cpu_to_le32((u32
) dma
);
787 if (sizeof(dma_addr_t
) > sizeof(u32
))
788 pSimple
->Address
.High
= cpu_to_le32((u32
) ((u64
) dma
>> 32));
790 pSimple
->Address
.High
= 0;
792 mpt_put_msg_frame (LanCtx
, mpt_dev
, mf
);
793 dev
->trans_start
= jiffies
;
795 dioprintk((KERN_INFO MYNAM
": %s/%s: Sending packet. FlagsLength = %08x.\n",
796 IOC_AND_NETDEV_NAMES_s_s(dev
),
797 le32_to_cpu(pSimple
->FlagsLength
)));
802 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
804 mpt_lan_wake_post_buckets_task(struct net_device
*dev
, int priority
)
806 * @priority: 0 = put it on the timer queue, 1 = put it on the immediate queue
809 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
811 if (test_and_set_bit(0, &priv
->post_buckets_active
) == 0) {
813 schedule_delayed_work(&priv
->post_buckets_task
, 0);
815 schedule_delayed_work(&priv
->post_buckets_task
, 1);
816 dioprintk((KERN_INFO MYNAM
": post_buckets queued on "
819 dioprintk((KERN_INFO MYNAM
": %s/%s: Queued post_buckets task.\n",
820 IOC_AND_NETDEV_NAMES_s_s(dev
) ));
824 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
826 mpt_lan_receive_skb(struct net_device
*dev
, struct sk_buff
*skb
)
828 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
830 skb
->protocol
= mpt_lan_type_trans(skb
, dev
);
832 dioprintk((KERN_INFO MYNAM
": %s/%s: Incoming packet (%d bytes) "
833 "delivered to upper level.\n",
834 IOC_AND_NETDEV_NAMES_s_s(dev
), skb
->len
));
836 dev
->stats
.rx_bytes
+= skb
->len
;
837 dev
->stats
.rx_packets
++;
842 dioprintk((MYNAM
"/receive_skb: %d buckets remaining\n",
843 atomic_read(&priv
->buckets_out
)));
845 if (atomic_read(&priv
->buckets_out
) < priv
->bucketthresh
)
846 mpt_lan_wake_post_buckets_task(dev
, 1);
848 dioprintk((KERN_INFO MYNAM
"/receive_post_reply: %d buckets "
849 "remaining, %d received back since sod\n",
850 atomic_read(&priv
->buckets_out
), priv
->total_received
));
855 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
858 mpt_lan_receive_post_turbo(struct net_device
*dev
, u32 tmsg
)
860 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
861 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
862 struct sk_buff
*skb
, *old_skb
;
866 ctx
= GET_LAN_BUCKET_CONTEXT(tmsg
);
867 skb
= priv
->RcvCtl
[ctx
].skb
;
869 len
= GET_LAN_PACKET_LENGTH(tmsg
);
871 if (len
< MPT_LAN_RX_COPYBREAK
) {
874 skb
= (struct sk_buff
*)dev_alloc_skb(len
);
876 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
877 IOC_AND_NETDEV_NAMES_s_s(dev
),
882 pci_dma_sync_single_for_cpu(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
883 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
885 skb_copy_from_linear_data(old_skb
, skb_put(skb
, len
), len
);
887 pci_dma_sync_single_for_device(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
888 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
894 priv
->RcvCtl
[ctx
].skb
= NULL
;
896 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
897 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
900 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
901 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
902 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
904 atomic_dec(&priv
->buckets_out
);
905 priv
->total_received
++;
907 return mpt_lan_receive_skb(dev
, skb
);
910 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
912 mpt_lan_receive_post_free(struct net_device
*dev
,
913 LANReceivePostReply_t
*pRecvRep
)
915 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
916 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
923 count
= pRecvRep
->NumberOfContexts
;
925 /**/ dlprintk((KERN_INFO MYNAM
"/receive_post_reply: "
926 "IOC returned %d buckets, freeing them...\n", count
));
928 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
929 for (i
= 0; i
< count
; i
++) {
930 ctx
= le32_to_cpu(pRecvRep
->BucketContext
[i
]);
932 skb
= priv
->RcvCtl
[ctx
].skb
;
934 // dlprintk((KERN_INFO MYNAM ": %s: dev_name = %s\n",
935 // IOC_AND_NETDEV_NAMES_s_s(dev)));
936 // dlprintk((KERN_INFO MYNAM "@rpr[2], priv = %p, buckets_out addr = %p",
937 // priv, &(priv->buckets_out)));
938 // dlprintk((KERN_INFO MYNAM "@rpr[2] TC + 3\n"));
940 priv
->RcvCtl
[ctx
].skb
= NULL
;
941 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
942 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
943 dev_kfree_skb_any(skb
);
945 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
947 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
949 atomic_sub(count
, &priv
->buckets_out
);
951 // for (i = 0; i < priv->max_buckets_out; i++)
952 // if (priv->RcvCtl[i].skb != NULL)
953 // dlprintk((KERN_INFO MYNAM "@rpr: bucket %03x "
954 // "is still out\n", i));
956 /* dlprintk((KERN_INFO MYNAM "/receive_post_reply: freed %d buckets\n",
959 /**/ dlprintk((KERN_INFO MYNAM
"@receive_post_reply: %d buckets "
960 /**/ "remaining, %d received back since sod.\n",
961 /**/ atomic_read(&priv
->buckets_out
), priv
->total_received
));
965 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
967 mpt_lan_receive_post_reply(struct net_device
*dev
,
968 LANReceivePostReply_t
*pRecvRep
)
970 struct mpt_lan_priv
*priv
= netdev_priv(dev
);
971 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
972 struct sk_buff
*skb
, *old_skb
;
974 u32 len
, ctx
, offset
;
975 u32 remaining
= le32_to_cpu(pRecvRep
->BucketsRemaining
);
979 dioprintk((KERN_INFO MYNAM
": mpt_lan_receive_post_reply called\n"));
980 dioprintk((KERN_INFO MYNAM
": receive_post_reply: IOCStatus: %04x\n",
981 le16_to_cpu(pRecvRep
->IOCStatus
)));
983 if ((le16_to_cpu(pRecvRep
->IOCStatus
) & MPI_IOCSTATUS_MASK
) ==
984 MPI_IOCSTATUS_LAN_CANCELED
)
985 return mpt_lan_receive_post_free(dev
, pRecvRep
);
987 len
= le32_to_cpu(pRecvRep
->PacketLength
);
989 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Got a non-TURBO "
990 "ReceivePostReply w/ PacketLength zero!\n",
991 IOC_AND_NETDEV_NAMES_s_s(dev
));
992 printk (KERN_ERR MYNAM
": MsgFlags = %02x, IOCStatus = %04x\n",
993 pRecvRep
->MsgFlags
, le16_to_cpu(pRecvRep
->IOCStatus
));
997 ctx
= le32_to_cpu(pRecvRep
->BucketContext
[0]);
998 count
= pRecvRep
->NumberOfContexts
;
999 skb
= priv
->RcvCtl
[ctx
].skb
;
1001 offset
= le32_to_cpu(pRecvRep
->PacketOffset
);
1002 // if (offset != 0) {
1003 // printk (KERN_INFO MYNAM ": %s/%s: Got a ReceivePostReply "
1004 // "w/ PacketOffset %u\n",
1005 // IOC_AND_NETDEV_NAMES_s_s(dev),
1009 dioprintk((KERN_INFO MYNAM
": %s/%s: @rpr, offset = %d, len = %d\n",
1010 IOC_AND_NETDEV_NAMES_s_s(dev
),
1016 // dioprintk((KERN_INFO MYNAM ": %s/%s: Multiple buckets returned "
1017 // "for single packet, concatenating...\n",
1018 // IOC_AND_NETDEV_NAMES_s_s(dev)));
1020 skb
= (struct sk_buff
*)dev_alloc_skb(len
);
1022 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1023 IOC_AND_NETDEV_NAMES_s_s(dev
),
1024 __FILE__
, __LINE__
);
1028 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1029 for (i
= 0; i
< count
; i
++) {
1031 ctx
= le32_to_cpu(pRecvRep
->BucketContext
[i
]);
1032 old_skb
= priv
->RcvCtl
[ctx
].skb
;
1034 l
= priv
->RcvCtl
[ctx
].len
;
1038 // dioprintk((KERN_INFO MYNAM ": %s/%s: Buckets = %d, len = %u\n",
1039 // IOC_AND_NETDEV_NAMES_s_s(dev),
1042 pci_dma_sync_single_for_cpu(mpt_dev
->pcidev
,
1043 priv
->RcvCtl
[ctx
].dma
,
1044 priv
->RcvCtl
[ctx
].len
,
1045 PCI_DMA_FROMDEVICE
);
1046 skb_copy_from_linear_data(old_skb
, skb_put(skb
, l
), l
);
1048 pci_dma_sync_single_for_device(mpt_dev
->pcidev
,
1049 priv
->RcvCtl
[ctx
].dma
,
1050 priv
->RcvCtl
[ctx
].len
,
1051 PCI_DMA_FROMDEVICE
);
1053 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1056 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1058 } else if (len
< MPT_LAN_RX_COPYBREAK
) {
1062 skb
= (struct sk_buff
*)dev_alloc_skb(len
);
1064 printk (KERN_ERR MYNAM
": %s/%s: ERROR - Can't allocate skb! (%s@%d)\n",
1065 IOC_AND_NETDEV_NAMES_s_s(dev
),
1066 __FILE__
, __LINE__
);
1070 pci_dma_sync_single_for_cpu(mpt_dev
->pcidev
,
1071 priv
->RcvCtl
[ctx
].dma
,
1072 priv
->RcvCtl
[ctx
].len
,
1073 PCI_DMA_FROMDEVICE
);
1075 skb_copy_from_linear_data(old_skb
, skb_put(skb
, len
), len
);
1077 pci_dma_sync_single_for_device(mpt_dev
->pcidev
,
1078 priv
->RcvCtl
[ctx
].dma
,
1079 priv
->RcvCtl
[ctx
].len
,
1080 PCI_DMA_FROMDEVICE
);
1082 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1083 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1084 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1087 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1089 priv
->RcvCtl
[ctx
].skb
= NULL
;
1091 pci_unmap_single(mpt_dev
->pcidev
, priv
->RcvCtl
[ctx
].dma
,
1092 priv
->RcvCtl
[ctx
].len
, PCI_DMA_FROMDEVICE
);
1093 priv
->RcvCtl
[ctx
].dma
= 0;
1095 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1096 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1101 atomic_sub(count
, &priv
->buckets_out
);
1102 priv
->total_received
+= count
;
1104 if (priv
->mpt_rxfidx_tail
>= MPT_LAN_MAX_BUCKETS_OUT
) {
1105 printk (KERN_ERR MYNAM
": %s/%s: Yoohoo! mpt_rxfidx_tail = %d, "
1106 "MPT_LAN_MAX_BUCKETS_OUT = %d\n",
1107 IOC_AND_NETDEV_NAMES_s_s(dev
),
1108 priv
->mpt_rxfidx_tail
,
1109 MPT_LAN_MAX_BUCKETS_OUT
);
1115 printk (KERN_WARNING MYNAM
": %s/%s: WARNING - IOC out of buckets! "
1116 "(priv->buckets_out = %d)\n",
1117 IOC_AND_NETDEV_NAMES_s_s(dev
),
1118 atomic_read(&priv
->buckets_out
));
1119 else if (remaining
< 10)
1120 printk (KERN_INFO MYNAM
": %s/%s: IOC says %d buckets left. "
1121 "(priv->buckets_out = %d)\n",
1122 IOC_AND_NETDEV_NAMES_s_s(dev
),
1123 remaining
, atomic_read(&priv
->buckets_out
));
1125 if ((remaining
< priv
->bucketthresh
) &&
1126 ((atomic_read(&priv
->buckets_out
) - remaining
) >
1127 MPT_LAN_BUCKETS_REMAIN_MISMATCH_THRESH
)) {
1129 printk (KERN_WARNING MYNAM
" Mismatch between driver's "
1130 "buckets_out count and fw's BucketsRemaining "
1131 "count has crossed the threshold, issuing a "
1132 "LanReset to clear the fw's hashtable. You may "
1133 "want to check your /var/log/messages for \"CRC "
1134 "error\" event notifications.\n");
1137 mpt_lan_wake_post_buckets_task(dev
, 0);
1140 return mpt_lan_receive_skb(dev
, skb
);
1143 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1144 /* Simple SGE's only at the moment */
1147 mpt_lan_post_receive_buckets(struct mpt_lan_priv
*priv
)
1149 struct net_device
*dev
= priv
->dev
;
1150 MPT_ADAPTER
*mpt_dev
= priv
->mpt_dev
;
1152 LANReceivePostRequest_t
*pRecvReq
;
1153 SGETransaction32_t
*pTrans
;
1154 SGESimple64_t
*pSimple
;
1155 struct sk_buff
*skb
;
1157 u32 curr
, buckets
, count
, max
;
1158 u32 len
= (dev
->mtu
+ dev
->hard_header_len
+ 4);
1159 unsigned long flags
;
1162 curr
= atomic_read(&priv
->buckets_out
);
1163 buckets
= (priv
->max_buckets_out
- curr
);
1165 dioprintk((KERN_INFO MYNAM
": %s/%s: @%s, Start_buckets = %u, buckets_out = %u\n",
1166 IOC_AND_NETDEV_NAMES_s_s(dev
),
1167 __func__
, buckets
, curr
));
1169 max
= (mpt_dev
->req_sz
- MPT_LAN_RECEIVE_POST_REQUEST_SIZE
) /
1170 (MPT_LAN_TRANSACTION32_SIZE
+ sizeof(SGESimple64_t
));
1173 mf
= mpt_get_msg_frame(LanCtx
, mpt_dev
);
1175 printk (KERN_ERR
"%s: Unable to alloc request frame\n",
1177 dioprintk((KERN_ERR
"%s: %u buckets remaining\n",
1178 __func__
, buckets
));
1181 pRecvReq
= (LANReceivePostRequest_t
*) mf
;
1183 i
= le16_to_cpu(mf
->u
.frame
.hwhdr
.msgctxu
.fld
.req_idx
);
1184 mpt_dev
->RequestNB
[i
] = 0;
1189 pRecvReq
->Function
= MPI_FUNCTION_LAN_RECEIVE
;
1190 pRecvReq
->ChainOffset
= 0;
1191 pRecvReq
->MsgFlags
= 0;
1192 pRecvReq
->PortNumber
= priv
->pnum
;
1194 pTrans
= (SGETransaction32_t
*) pRecvReq
->SG_List
;
1197 for (i
= 0; i
< count
; i
++) {
1200 spin_lock_irqsave(&priv
->rxfidx_lock
, flags
);
1201 if (priv
->mpt_rxfidx_tail
< 0) {
1202 printk (KERN_ERR
"%s: Can't alloc context\n",
1204 spin_unlock_irqrestore(&priv
->rxfidx_lock
,
1209 ctx
= priv
->mpt_rxfidx
[priv
->mpt_rxfidx_tail
--];
1211 skb
= priv
->RcvCtl
[ctx
].skb
;
1212 if (skb
&& (priv
->RcvCtl
[ctx
].len
!= len
)) {
1213 pci_unmap_single(mpt_dev
->pcidev
,
1214 priv
->RcvCtl
[ctx
].dma
,
1215 priv
->RcvCtl
[ctx
].len
,
1216 PCI_DMA_FROMDEVICE
);
1217 dev_kfree_skb(priv
->RcvCtl
[ctx
].skb
);
1218 skb
= priv
->RcvCtl
[ctx
].skb
= NULL
;
1222 skb
= dev_alloc_skb(len
);
1224 printk (KERN_WARNING
1225 MYNAM
"/%s: Can't alloc skb\n",
1227 priv
->mpt_rxfidx
[++priv
->mpt_rxfidx_tail
] = ctx
;
1228 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1232 dma
= pci_map_single(mpt_dev
->pcidev
, skb
->data
,
1233 len
, PCI_DMA_FROMDEVICE
);
1235 priv
->RcvCtl
[ctx
].skb
= skb
;
1236 priv
->RcvCtl
[ctx
].dma
= dma
;
1237 priv
->RcvCtl
[ctx
].len
= len
;
1240 spin_unlock_irqrestore(&priv
->rxfidx_lock
, flags
);
1242 pTrans
->ContextSize
= sizeof(u32
);
1243 pTrans
->DetailsLength
= 0;
1245 pTrans
->TransactionContext
[0] = cpu_to_le32(ctx
);
1247 pSimple
= (SGESimple64_t
*) pTrans
->TransactionDetails
;
1249 pSimple
->FlagsLength
= cpu_to_le32(
1250 ((MPI_SGE_FLAGS_END_OF_BUFFER
|
1251 MPI_SGE_FLAGS_SIMPLE_ELEMENT
|
1252 MPI_SGE_FLAGS_64_BIT_ADDRESSING
) << MPI_SGE_FLAGS_SHIFT
) | len
);
1253 pSimple
->Address
.Low
= cpu_to_le32((u32
) priv
->RcvCtl
[ctx
].dma
);
1254 if (sizeof(dma_addr_t
) > sizeof(u32
))
1255 pSimple
->Address
.High
= cpu_to_le32((u32
) ((u64
) priv
->RcvCtl
[ctx
].dma
>> 32));
1257 pSimple
->Address
.High
= 0;
1259 pTrans
= (SGETransaction32_t
*) (pSimple
+ 1);
1262 if (pSimple
== NULL
) {
1263 /**/ printk (KERN_WARNING MYNAM
"/%s: No buckets posted\n",
1265 mpt_free_msg_frame(mpt_dev
, mf
);
1269 pSimple
->FlagsLength
|= cpu_to_le32(MPI_SGE_FLAGS_END_OF_LIST
<< MPI_SGE_FLAGS_SHIFT
);
1271 pRecvReq
->BucketCount
= cpu_to_le32(i
);
1273 /* printk(KERN_INFO MYNAM ": posting buckets\n ");
1274 * for (i = 0; i < j + 2; i ++)
1275 * printk (" %08x", le32_to_cpu(msg[i]));
1279 mpt_put_msg_frame(LanCtx
, mpt_dev
, mf
);
1281 priv
->total_posted
+= i
;
1283 atomic_add(i
, &priv
->buckets_out
);
1287 dioprintk((KERN_INFO MYNAM
"/%s: End_buckets = %u, priv->buckets_out = %u\n",
1288 __func__
, buckets
, atomic_read(&priv
->buckets_out
)));
1289 dioprintk((KERN_INFO MYNAM
"/%s: Posted %u buckets and received %u back\n",
1290 __func__
, priv
->total_posted
, priv
->total_received
));
1292 clear_bit(0, &priv
->post_buckets_active
);
1296 mpt_lan_post_receive_buckets_work(struct work_struct
*work
)
1298 mpt_lan_post_receive_buckets(container_of(work
, struct mpt_lan_priv
,
1299 post_buckets_task
.work
));
1302 static const struct net_device_ops mpt_netdev_ops
= {
1303 .ndo_open
= mpt_lan_open
,
1304 .ndo_stop
= mpt_lan_close
,
1305 .ndo_start_xmit
= mpt_lan_sdu_send
,
1306 .ndo_change_mtu
= mpt_lan_change_mtu
,
1307 .ndo_tx_timeout
= mpt_lan_tx_timeout
,
1310 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1311 static struct net_device
*
1312 mpt_register_lan_device (MPT_ADAPTER
*mpt_dev
, int pnum
)
1314 struct net_device
*dev
;
1315 struct mpt_lan_priv
*priv
;
1316 u8 HWaddr
[FC_ALEN
], *a
;
1318 dev
= alloc_fcdev(sizeof(struct mpt_lan_priv
));
1322 dev
->mtu
= MPT_LAN_MTU
;
1324 priv
= netdev_priv(dev
);
1327 priv
->mpt_dev
= mpt_dev
;
1330 INIT_DELAYED_WORK(&priv
->post_buckets_task
,
1331 mpt_lan_post_receive_buckets_work
);
1332 priv
->post_buckets_active
= 0;
1334 dlprintk((KERN_INFO MYNAM
"@%d: bucketlen = %d\n",
1335 __LINE__
, dev
->mtu
+ dev
->hard_header_len
+ 4));
1337 atomic_set(&priv
->buckets_out
, 0);
1338 priv
->total_posted
= 0;
1339 priv
->total_received
= 0;
1340 priv
->max_buckets_out
= max_buckets_out
;
1341 if (mpt_dev
->pfacts
[0].MaxLanBuckets
< max_buckets_out
)
1342 priv
->max_buckets_out
= mpt_dev
->pfacts
[0].MaxLanBuckets
;
1344 dlprintk((KERN_INFO MYNAM
"@%d: MaxLanBuckets=%d, max_buckets_out/priv=%d/%d\n",
1346 mpt_dev
->pfacts
[0].MaxLanBuckets
,
1348 priv
->max_buckets_out
));
1350 priv
->bucketthresh
= priv
->max_buckets_out
* 2 / 3;
1351 spin_lock_init(&priv
->txfidx_lock
);
1352 spin_lock_init(&priv
->rxfidx_lock
);
1354 /* Grab pre-fetched LANPage1 stuff. :-) */
1355 a
= (u8
*) &mpt_dev
->lan_cnfg_page1
.HardwareAddressLow
;
1364 dev
->addr_len
= FC_ALEN
;
1365 memcpy(dev
->dev_addr
, HWaddr
, FC_ALEN
);
1366 memset(dev
->broadcast
, 0xff, FC_ALEN
);
1368 /* The Tx queue is 127 deep on the 909.
1369 * Give ourselves some breathing room.
1371 priv
->tx_max_out
= (tx_max_out_p
<= MPT_TX_MAX_OUT_LIM
) ?
1372 tx_max_out_p
: MPT_TX_MAX_OUT_LIM
;
1374 dev
->netdev_ops
= &mpt_netdev_ops
;
1375 dev
->watchdog_timeo
= MPT_LAN_TX_TIMEOUT
;
1377 dlprintk((KERN_INFO MYNAM
": Finished registering dev "
1378 "and setting initial values\n"));
1380 if (register_netdev(dev
) != 0) {
1388 mptlan_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
1390 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
1391 struct net_device
*dev
;
1394 for (i
= 0; i
< ioc
->facts
.NumberOfPorts
; i
++) {
1395 printk(KERN_INFO MYNAM
": %s: PortNum=%x, "
1396 "ProtocolFlags=%02Xh (%c%c%c%c)\n",
1397 ioc
->name
, ioc
->pfacts
[i
].PortNumber
,
1398 ioc
->pfacts
[i
].ProtocolFlags
,
1399 MPT_PROTOCOL_FLAGS_c_c_c_c(
1400 ioc
->pfacts
[i
].ProtocolFlags
));
1402 if (!(ioc
->pfacts
[i
].ProtocolFlags
&
1403 MPI_PORTFACTS_PROTOCOL_LAN
)) {
1404 printk(KERN_INFO MYNAM
": %s: Hmmm... LAN protocol "
1405 "seems to be disabled on this adapter port!\n",
1410 dev
= mpt_register_lan_device(ioc
, i
);
1412 printk(KERN_ERR MYNAM
": %s: Unable to register "
1413 "port%d as a LAN device\n", ioc
->name
,
1414 ioc
->pfacts
[i
].PortNumber
);
1418 printk(KERN_INFO MYNAM
": %s: Fusion MPT LAN device "
1419 "registered as '%s'\n", ioc
->name
, dev
->name
);
1420 printk(KERN_INFO MYNAM
": %s/%s: "
1422 IOC_AND_NETDEV_NAMES_s_s(dev
),
1434 mptlan_remove(struct pci_dev
*pdev
)
1436 MPT_ADAPTER
*ioc
= pci_get_drvdata(pdev
);
1437 struct net_device
*dev
= ioc
->netdev
;
1440 unregister_netdev(dev
);
1445 static struct mpt_pci_driver mptlan_driver
= {
1446 .probe
= mptlan_probe
,
1447 .remove
= mptlan_remove
,
1450 static int __init
mpt_lan_init (void)
1452 show_mptmod_ver(LANAME
, LANVER
);
1454 if ((LanCtx
= mpt_register(lan_reply
, MPTLAN_DRIVER
)) <= 0) {
1455 printk (KERN_ERR MYNAM
": Failed to register with MPT base driver\n");
1459 dlprintk((KERN_INFO MYNAM
": assigned context of %d\n", LanCtx
));
1461 if (mpt_reset_register(LanCtx
, mpt_lan_ioc_reset
)) {
1462 printk(KERN_ERR MYNAM
": Eieee! unable to register a reset "
1463 "handler with mptbase! The world is at an end! "
1464 "Everything is fading to black! Goodbye.\n");
1468 dlprintk((KERN_INFO MYNAM
": Registered for IOC reset notifications\n"));
1470 mpt_device_driver_register(&mptlan_driver
, MPTLAN_DRIVER
);
1474 static void __exit
mpt_lan_exit(void)
1476 mpt_device_driver_deregister(MPTLAN_DRIVER
);
1477 mpt_reset_deregister(LanCtx
);
1480 mpt_deregister(LanCtx
);
1481 LanCtx
= MPT_MAX_PROTOCOL_DRIVERS
;
1485 module_init(mpt_lan_init
);
1486 module_exit(mpt_lan_exit
);
1488 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1489 static unsigned short
1490 mpt_lan_type_trans(struct sk_buff
*skb
, struct net_device
*dev
)
1492 struct mpt_lan_ohdr
*fch
= (struct mpt_lan_ohdr
*)skb
->data
;
1493 struct fcllc
*fcllc
;
1495 skb_reset_mac_header(skb
);
1496 skb_pull(skb
, sizeof(struct mpt_lan_ohdr
));
1498 if (fch
->dtype
== htons(0xffff)) {
1499 u32
*p
= (u32
*) fch
;
1506 printk (KERN_WARNING MYNAM
": %s: WARNING - Broadcast swap F/W bug detected!\n",
1507 NETDEV_PTR_TO_IOC_NAME_s(dev
));
1508 printk (KERN_WARNING MYNAM
": Please update sender @ MAC_addr = %pM\n",
1512 if (*fch
->daddr
& 1) {
1513 if (!memcmp(fch
->daddr
, dev
->broadcast
, FC_ALEN
)) {
1514 skb
->pkt_type
= PACKET_BROADCAST
;
1516 skb
->pkt_type
= PACKET_MULTICAST
;
1519 if (memcmp(fch
->daddr
, dev
->dev_addr
, FC_ALEN
)) {
1520 skb
->pkt_type
= PACKET_OTHERHOST
;
1522 skb
->pkt_type
= PACKET_HOST
;
1526 fcllc
= (struct fcllc
*)skb
->data
;
1528 /* Strip the SNAP header from ARP packets since we don't
1529 * pass them through to the 802.2/SNAP layers.
1531 if (fcllc
->dsap
== EXTENDED_SAP
&&
1532 (fcllc
->ethertype
== htons(ETH_P_IP
) ||
1533 fcllc
->ethertype
== htons(ETH_P_ARP
))) {
1534 skb_pull(skb
, sizeof(struct fcllc
));
1535 return fcllc
->ethertype
;
1538 return htons(ETH_P_802_2
);
1541 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/